diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 33ffaa404..000000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -po/exclude.pot binary diff --git a/.gitignore b/.gitignore index f6a1bd051..18ab8e812 100644 --- a/.gitignore +++ b/.gitignore @@ -1,277 +1,248 @@ -# -# Ignore patterns in this directory and all subdirectories. -# +00_header +10_* +20_linux_xen +30_os-prober +40_custom +41_custom *.1 *.8 -*.a +aclocal.m4 +ahci_test +ascii.bitmaps +ascii.h +autom4te.cache +build-grub-gen-asciih +build-grub-gen-widthspec +build-grub-mkfont +cdboot_test +cmp_test +config.cache +config.guess +config.h +config-util.h +config-util.h.in +config.log +config.status +config.sub +configure +core_compress_test +DISTLIST +docs/*.info +docs/stamp-vti +docs/version.texi +ehci_test +example_grub_script_test +example_scripted_test +example_unit_test *.exec *.exec.exe -*.image -*.image.exe -*.img -*.log -*.lst -*.marker -*.mod -*.o -*.pf2 -*.pp -*.trs -*~ -.deps-core/ -.deps-util/ -.deps/ -.dirstamp -DISTLIST -GPATH -GRTAGS -GSYMS -GTAGS -Makefile -Makefile.in -ascii.bitmaps +fddboot_test genkernsyms.sh gensymlist.sh +gentrigtables +gentrigtables.exe +gettext_strings_test grub-bin2h +/grub-bios-setup +/grub-bios-setup.exe +grub_cmd_date +grub_cmd_echo +grub_cmd_regexp +grub_cmd_set_date +grub_cmd_sleep +/grub-editenv +/grub-editenv.exe grub-emu grub-emu-lite -grub-emu-lite.exe grub-emu.exe -grub-macho2img +grub-emu-lite.exe grub_emu_init.c grub_emu_init.h +/grub-file +/grub-file.exe +grub-fstest +grub-fstest.exe +grub_fstest_init.c +grub_fstest_init.h +grub_func_test +grub-install +grub-install.exe +grub-kbdcomp +/grub-macbless +/grub-macbless.exe +grub-macho2img +/grub-menulst2cfg +/grub-menulst2cfg.exe +/grub-mk* +grub-mount +/grub-ofpathname +/grub-ofpathname.exe +grub-core/build-grub-pe2elf.exe +/grub-probe +/grub-probe.exe grub_probe_init.c grub_probe_init.h +/grub-reboot +grub_script_blanklines +grub_script_blockarg +grub_script_break +grub-script-check +grub-script-check.exe +grub_script_check_init.c +grub_script_check_init.h +grub_script_comments +grub_script_continue +grub_script_dollar +grub_script_echo1 +grub_script_echo_keywords +grub_script_escape_comma +grub_script_eval +grub_script_expansion +grub_script_final_semicolon +grub_script_for1 +grub_script_functions +grub_script_gettext +grub_script_if +grub_script_leading_whitespace +grub_script_no_commands +grub_script_not +grub_script_return +grub_script_setparams +grub_script_shift +grub_script_strcmp +grub_script_test +grub_script_vars1 +grub_script_while1 grub_script.tab.c grub_script.tab.h grub_script.yy.c grub_script.yy.h -grub_script_check_init.c -grub_script_check_init.h +grub-set-default grub_setup_init.c grub_setup_init.h -mdate-sh -mod-*.c -update-grub_lib -widthspec.bin - -# -# Ignore patterns relative to this .gitignore file's directory. -# -/00_header -/10_* -/20_linux_xen -/30_os-prober -/30_uefi-firmware -/40_custom -/41_custom -/ABOUT-NLS -/ChangeLog -/INSTALL.grub -/Makefile.util.am -/Makefile.utilgcry.def -/aclocal.m4 -/ahci_test -/ascii.h -/autom4te.cache/ -/btrfs_test -/build-aux/ -/build-grub-gen-asciih -/build-grub-gen-widthspec -/build-grub-mkfont -/cdboot_test -/cmp_test -/compile -/config-util.h -/config-util.h.in -/config.cache -/config.guess -/config.h -/config.log -/config.status -/config.sub -/configure -/contrib -/core_compress_test -/cpio_test -/date_test -/depcomp -/docs/*.info -/docs/*.info-[0-9]* -/docs/stamp-1 -/docs/stamp-vti -/docs/version-dev.texi -/docs/version.texi -/ehci_test -/example_grub_script_test -/example_scripted_test -/example_unit_test -/exfat_test -/ext234_test -/f2fs_test -/fat_test -/fddboot_test -/file_filter_test -/garbage-gen -/garbage-gen.exe -/gettext_strings_test -/gnulib/ -/grub-2.[0-9]*/ -/grub-2.[0-9]*.tar.gz -/grub-bios-setup -/grub-bios-setup.exe -/grub-core/*.module -/grub-core/*.module.exe -/grub-core/*.pp -/grub-core/Makefile.core.am -/grub-core/Makefile.gcry.def -/grub-core/bootinfo.txt -/grub-core/build-grub-module-verifier -/grub-core/build-grub-pe2elf.exe -/grub-core/contrib -/grub-core/gdb_grub -/grub-core/genmod.sh -/grub-core/gensyminfo.sh -/grub-core/gentrigtables -/grub-core/gentrigtables.exe -/grub-core/gmodule.pl -/grub-core/grub.chrp -/grub-core/kernel.img.bin -/grub-core/lib/gnulib -/grub-core/lib/libgcrypt-grub -/grub-core/modinfo.sh -/grub-core/rs_decoder.h -/grub-core/symlist.c -/grub-core/symlist.h -/grub-core/trigtables.c -/grub-core/unidata.c -/grub-editenv -/grub-editenv.exe -/grub-file -/grub-file.exe -/grub-fs-tester -/grub-fstest -/grub-fstest.exe -/grub-glue-efi -/grub-glue-efi.exe -/grub-install -/grub-install.exe -/grub-kbdcomp -/grub-macbless -/grub-macbless.exe -/grub-menulst2cfg -/grub-menulst2cfg.exe -/grub-mk* -/grub-mount -/grub-ofpathname -/grub-ofpathname.exe -/grub-probe -/grub-probe.exe -/grub-reboot -/grub-render-label -/grub-render-label.exe -/grub-script-check -/grub-script-check.exe -/grub-set-default -/grub-shell -/grub-shell-tester -/grub-sparc64-setup -/grub-sparc64-setup.exe +grub-shell +grub-shell-tester +grub-sparc64-setup +grub-sparc64-setup.exe /grub-syslinux2cfg /grub-syslinux2cfg.exe -/grub_cmd_date -/grub_cmd_echo -/grub_cmd_regexp -/grub_cmd_set_date -/grub_cmd_sleep -/grub_cmd_test -/grub_cmd_tr -/grub_fstest_init.c -/grub_fstest_init.h -/grub_func_test -/grub_script_blanklines -/grub_script_blockarg -/grub_script_break -/grub_script_comments -/grub_script_continue -/grub_script_dollar -/grub_script_echo1 -/grub_script_echo_keywords -/grub_script_escape_comma -/grub_script_eval -/grub_script_expansion -/grub_script_final_semicolon -/grub_script_for1 -/grub_script_functions -/grub_script_gettext -/grub_script_if -/grub_script_leading_whitespace -/grub_script_no_commands -/grub_script_not -/grub_script_return -/grub_script_setparams -/grub_script_shift -/grub_script_strcmp -/grub_script_test -/grub_script_vars1 -/grub_script_while1 -/gzcompress_test -/hddboot_test -/help_test -/hfs_test -/hfsplus_test -/include/grub/cpu -/include/grub/gcrypt/g10lib.h -/include/grub/gcrypt/gcrypt.h -/include/grub/machine -/install-sh -/iso9660_test -/jfs_test -/lib/libgcrypt-grub -/libgrub_a_init.c -/lzocompress_test -/m4/ -/minixfs_test -/missing -/netboot_test -/nilfs2_test -/ntfs_test -/ohci_test -/partmap_test -/pata_test -/po/*.gmo -/po/*.mo -/po/*.po -/po/LINGUAS -/po/Makefile.in.in -/po/Makevars -/po/Makevars.template -/po/POTFILES -/po/POTFILES-shell.in -/po/POTFILES.in -/po/Rules-quot -/po/grub.pot -/po/remove-potcdate.sed -/po/stamp-po -/printf_test -/priority_queue_unit_test -/pseries_test -/reiserfs_test -/romfs_test -/squashfs_test -/stamp-h -/stamp-h.in -/stamp-h1 -/syslinux_test -/tar_test -/test_sha512sum -/test_unset -/tests/syslinux/ubuntu10.04_grub.cfg -/texinfo.tex -/udf_test -/uhci_test -/util/bash-completion.d/grub -/widthspec.h -/xfs_test -/xzcompress_test -/zfs_test +gzcompress_test +hddboot_test +help_test +*.img +*.image +*.image.exe +include/grub/cpu +include/grub/machine +install-sh +lib/libgcrypt-grub +libgrub_a_init.c +*.log +*.lst +lzocompress_test +*.marker +Makefile +*.mod +mod-*.c +missing +netboot_test +*.o +*.a +ohci_test +partmap_test +pata_test +*.pf2 +*.pp +po/*.mo +po/grub.pot +po/POTFILES +po/stamp-po +printf_test +priority_queue_unit_test +pseries_test +stamp-h +stamp-h1 +stamp-h.in +symlist.c +symlist.h +trigtables.c +*.trs +uhci_test +update-grub_lib +unidata.c +xzcompress_test +Makefile.in +GPATH +GRTAGS +GSYMS +GTAGS +compile +depcomp +mdate-sh +texinfo.tex +grub-core/lib/libgcrypt-grub +.deps +.deps-util +.deps-core +.dirstamp +Makefile.util.am +contrib +grub-core/bootinfo.txt +grub-core/Makefile.core.am +grub-core/Makefile.gcry.def +grub-core/contrib +grub-core/gdb_grub +grub-core/genmod.sh +grub-core/gensyminfo.sh +grub-core/gmodule.pl +grub-core/grub.chrp +grub-core/modinfo.sh +grub-core/*.module +grub-core/*.module.exe +grub-core/*.pp +grub-core/kernel.img.bin +util/bash-completion.d/grub +grub-core/gnulib/alloca.h +grub-core/gnulib/arg-nonnull.h +grub-core/gnulib/c++defs.h +grub-core/gnulib/charset.alias +grub-core/gnulib/configmake.h +grub-core/gnulib/float.h +grub-core/gnulib/getopt.h +grub-core/gnulib/langinfo.h +grub-core/gnulib/ref-add.sed +grub-core/gnulib/ref-del.sed +grub-core/gnulib/stdio.h +grub-core/gnulib/stdlib.h +grub-core/gnulib/string.h +grub-core/gnulib/strings.h +grub-core/gnulib/sys +grub-core/gnulib/unistd.h +grub-core/gnulib/warn-on-use.h +grub-core/gnulib/wchar.h +grub-core/gnulib/wctype.h +grub-core/rs_decoder.h +widthspec.bin +widthspec.h +docs/stamp-1 +docs/version-dev.texi +Makefile.utilgcry.def +po/*.po +po/*.gmo +po/LINGUAS +po/remove-potcdate.sed +include/grub/gcrypt/gcrypt.h +include/grub/gcrypt/g10lib.h +po/POTFILES.in +po/POTFILES-shell.in +/grub-glue-efi +/grub-render-label +/grub-glue-efi.exe +/grub-render-label.exe +grub-core/gnulib/locale.h +grub-core/gnulib/unitypes.h +grub-core/gnulib/uniwidth.h +build-aux/test-driver +/garbage-gen +/garbage-gen.exe +/grub-fs-tester diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4bd05a30a..000000000 --- a/.travis.yml +++ /dev/null @@ -1,109 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0+ -# Originally Copyright Roger Meier -# Adapted for GRUB by Alexander Graf -# -# Build GRUB on Travis CI - https://www.travis-ci.org/ -# - -dist: xenial - -language: c - -addons: - apt: - packages: - - autopoint - - libsdl1.2-dev - - lzop - - ovmf - - python - - qemu-system - - unifont - -env: - global: - # Include all cross toolchain paths, so we can just call them later down. - - PATH=/tmp/qemu-install/bin:/tmp/grub/bin:/usr/bin:/bin:/tmp/cross/gcc-8.1.0-nolibc/aarch64-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/arm-linux-gnueabi/bin:/tmp/cross/gcc-8.1.0-nolibc/ia64-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/mips64-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/powerpc64-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/riscv32-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/riscv64-linux/bin:/tmp/cross/gcc-8.1.0-nolibc/sparc64-linux/bin - -before_script: - # Install necessary toolchains based on $CROSS_TARGETS variable. - - mkdir /tmp/cross - # These give us binaries like /tmp/cross/gcc-8.1.0-nolibc/ia64-linux/bin/ia64-linux-gcc - - for i in $CROSS_TARGETS; do - ( cd /tmp/cross; wget -t 3 -O - https://mirrors.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-$i.tar.xz | tar xJ ); - done - -script: - # Comments must be outside the command strings below, or the Travis parser - # will get confused. - - ./bootstrap - - # Build all selected GRUB targets. - - for target in $GRUB_TARGETS; do - plat=${target#*-}; - arch=${target%-*}; - [ "$arch" = "arm64" ] && arch=aarch64-linux; - [ "$arch" = "arm" ] && arch=arm-linux-gnueabi; - [ "$arch" = "ia64" ] && arch=ia64-linux; - [ "$arch" = "mipsel" ] && arch=mips64-linux; - [ "$arch" = "powerpc" ] && arch=powerpc64-linux; - [ "$arch" = "riscv32" ] && arch=riscv32-linux; - [ "$arch" = "riscv64" ] && arch=riscv64-linux; - [ "$arch" = "sparc64" ] && arch=sparc64-linux; - echo "Building $target"; - mkdir obj-$target; - JOBS=`getconf _NPROCESSORS_ONLN 2> /dev/null || echo 1`; - [ "$JOBS" == 1 ] || JOBS=$(($JOBS + 1)); - ( cd obj-$target && ../configure --target=$arch --with-platform=$plat --prefix=/tmp/grub && make -j$JOBS && make -j$JOBS install ) &> log || ( cat log; false ); - done - - # Our test canary. - - echo -e "insmod echo\\ninsmod reboot\\necho hello world\\nreboot" > grub.cfg - - # Assemble images and possibly run them. - - for target in $GRUB_TARGETS; do grub-mkimage -c grub.cfg -p / -O $target -o grub-$target echo reboot normal; done - - # Run images we know how to run. - - if [[ "$GRUB_TARGETS" == *"x86_64-efi"* ]]; then qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -m 512 -no-reboot -nographic -net nic -net user,tftp=.,bootfile=grub-x86_64-efi | tee grub.log && grep "hello world" grub.log; fi - -matrix: - include: - # Each env setting here is a dedicated build. - - name: "x86_64" - env: - - GRUB_TARGETS="x86_64-efi x86_64-xen" - - name: "i386" - env: - - GRUB_TARGETS="i386-coreboot i386-efi i386-ieee1275 i386-multiboot i386-pc i386-qemu i386-xen i386-xen_pvh" - - name: "powerpc" - env: - - GRUB_TARGETS="powerpc-ieee1275" - - CROSS_TARGETS="powerpc64-linux" - - name: "sparc64" - env: - - GRUB_TARGETS="sparc64-ieee1275" - - CROSS_TARGETS="sparc64-linux" - - name: "ia64" - env: - - GRUB_TARGETS="ia64-efi" - - CROSS_TARGETS="ia64-linux" - - name: "mips" - env: - - GRUB_TARGETS="mips-arc mipsel-arc mipsel-qemu_mips mips-qemu_mips" - - CROSS_TARGETS="mips64-linux" - - name: "arm" - env: - - GRUB_TARGETS="arm-coreboot arm-efi arm-uboot" - - CROSS_TARGETS="arm-linux-gnueabi" - - name: "arm64" - env: - - GRUB_TARGETS="arm64-efi" - - CROSS_TARGETS="aarch64-linux" - - name: "riscv32" - env: - - GRUB_TARGETS="riscv32-efi" - - CROSS_TARGETS="riscv32-linux" - - name: "riscv64" - env: - - GRUB_TARGETS="riscv64-efi" - - CROSS_TARGETS="riscv64-linux" diff --git a/ABOUT-NLS b/ABOUT-NLS new file mode 100644 index 000000000..866b904ec --- /dev/null +++ b/ABOUT-NLS @@ -0,0 +1,223 @@ +1 Notes on the Free Translation Project +*************************************** + +Free software is going international! The Free Translation Project is +a way to get maintainers of free software, translators, and users all +together, so that free software will gradually become able to speak many +languages. A few packages already provide translations for their +messages. + + If you found this `ABOUT-NLS' file inside a distribution, you may +assume that the distributed package does use GNU `gettext' internally, +itself available at your nearest GNU archive site. But you do _not_ +need to install GNU `gettext' prior to configuring, installing or using +this package with messages translated. + + Installers will find here some useful hints. These notes also +explain how users should proceed for getting the programs to use the +available translations. They tell how people wanting to contribute and +work on translations can contact the appropriate team. + + When reporting bugs in the `intl/' directory or bugs which may be +related to internationalization, you should tell about the version of +`gettext' which is used. The information can be found in the +`intl/VERSION' file, in internationalized packages. + +1.1 Quick configuration advice +============================== + +If you want to exploit the full power of internationalization, you +should configure it using + + ./configure --with-included-gettext + +to force usage of internationalizing routines provided within this +package, despite the existence of internationalizing capabilities in the +operating system where this package is being installed. So far, only +the `gettext' implementation in the GNU C library version 2 provides as +many features (such as locale alias, message inheritance, automatic +charset conversion or plural form handling) as the implementation here. +It is also not possible to offer this additional functionality on top +of a `catgets' implementation. Future versions of GNU `gettext' will +very likely convey even more functionality. So it might be a good idea +to change to GNU `gettext' as soon as possible. + + So you need _not_ provide this option if you are using GNU libc 2 or +you have installed a recent copy of the GNU gettext package with the +included `libintl'. + +1.2 INSTALL Matters +=================== + +Some packages are "localizable" when properly installed; the programs +they contain can be made to speak your own native language. Most such +packages use GNU `gettext'. Other packages have their own ways to +internationalization, predating GNU `gettext'. + + By default, this package will be installed to allow translation of +messages. It will automatically detect whether the system already +provides the GNU `gettext' functions. If not, the included GNU +`gettext' library will be used. This library is wholly contained +within this package, usually in the `intl/' subdirectory, so prior +installation of the GNU `gettext' package is _not_ required. +Installers may use special options at configuration time for changing +the default behaviour. The commands: + + ./configure --with-included-gettext + ./configure --disable-nls + +will, respectively, bypass any pre-existing `gettext' to use the +internationalizing routines provided within this package, or else, +_totally_ disable translation of messages. + + When you already have GNU `gettext' installed on your system and run +configure without an option for your new package, `configure' will +probably detect the previously built and installed `libintl.a' file and +will decide to use this. This might not be desirable. You should use +the more recent version of the GNU `gettext' library. I.e. if the file +`intl/VERSION' shows that the library which comes with this package is +more recent, you should use + + ./configure --with-included-gettext + +to prevent auto-detection. + + The configuration process will not test for the `catgets' function +and therefore it will not be used. The reason is that even an +emulation of `gettext' on top of `catgets' could not provide all the +extensions of the GNU `gettext' library. + + Internationalized packages usually have many `po/LL.po' files, where +LL gives an ISO 639 two-letter code identifying the language. Unless +translations have been forbidden at `configure' time by using the +`--disable-nls' switch, all available translations are installed +together with the package. However, the environment variable `LINGUAS' +may be set, prior to configuration, to limit the installed set. +`LINGUAS' should then contain a space separated list of two-letter +codes, stating which languages are allowed. + +1.3 Using This Package +====================== + +As a user, if your language has been installed for this package, you +only have to set the `LANG' environment variable to the appropriate +`LL_CC' combination. Here `LL' is an ISO 639 two-letter language code, +and `CC' is an ISO 3166 two-letter country code. For example, let's +suppose that you speak German and live in Germany. At the shell +prompt, merely execute `setenv LANG de_DE' (in `csh'), +`export LANG; LANG=de_DE' (in `sh') or `export LANG=de_DE' (in `bash'). +This can be done from your `.login' or `.profile' file, once and for +all. + + You might think that the country code specification is redundant. +But in fact, some languages have dialects in different countries. For +example, `de_AT' is used for Austria, and `pt_BR' for Brazil. The +country code serves to distinguish the dialects. + + The locale naming convention of `LL_CC', with `LL' denoting the +language and `CC' denoting the country, is the one use on systems based +on GNU libc. On other systems, some variations of this scheme are +used, such as `LL' or `LL_CC.ENCODING'. You can get the list of +locales supported by your system for your language by running the +command `locale -a | grep '^LL''. + + Not all programs have translations for all languages. By default, an +English message is shown in place of a nonexistent translation. If you +understand other languages, you can set up a priority list of languages. +This is done through a different environment variable, called +`LANGUAGE'. GNU `gettext' gives preference to `LANGUAGE' over `LANG' +for the purpose of message handling, but you still need to have `LANG' +set to the primary language; this is required by other parts of the +system libraries. For example, some Swedish users who would rather +read translations in German than English for when Swedish is not +available, set `LANGUAGE' to `sv:de' while leaving `LANG' to `sv_SE'. + + Special advice for Norwegian users: The language code for Norwegian +bokma*l changed from `no' to `nb' recently (in 2003). During the +transition period, while some message catalogs for this language are +installed under `nb' and some older ones under `no', it's recommended +for Norwegian users to set `LANGUAGE' to `nb:no' so that both newer and +older translations are used. + + In the `LANGUAGE' environment variable, but not in the `LANG' +environment variable, `LL_CC' combinations can be abbreviated as `LL' +to denote the language's main dialect. For example, `de' is equivalent +to `de_DE' (German as spoken in Germany), and `pt' to `pt_PT' +(Portuguese as spoken in Portugal) in this context. + +1.4 Translating Teams +===================== + +For the Free Translation Project to be a success, we need interested +people who like their own language and write it well, and who are also +able to synergize with other translators speaking the same language. +Each translation team has its own mailing list. The up-to-date list of +teams can be found at the Free Translation Project's homepage, +`http://www.iro.umontreal.ca/contrib/po/HTML/', in the "National teams" +area. + + If you'd like to volunteer to _work_ at translating messages, you +should become a member of the translating team for your own language. +The subscribing address is _not_ the same as the list itself, it has +`-request' appended. For example, speakers of Swedish can send a +message to `sv-request@li.org', having this message body: + + subscribe + + Keep in mind that team members are expected to participate +_actively_ in translations, or at solving translational difficulties, +rather than merely lurking around. If your team does not exist yet and +you want to start one, or if you are unsure about what to do or how to +get started, please write to `translation@iro.umontreal.ca' to reach the +coordinator for all translator teams. + + The English team is special. It works at improving and uniformizing +the terminology in use. Proven linguistic skills are praised more than +programming skills, here. + +1.5 Available Packages +====================== + +Languages are not equally supported in all packages. The following +matrix shows the current state of internationalization, as of October +2006. The matrix shows, in regard of each package, for which languages +PO files have been submitted to translation coordination, with a +translation percentage of at least 50%. + +# Matrix here is removed! + + Some counters in the preceding matrix are higher than the number of +visible blocks let us expect. This is because a few extra PO files are +used for implementing regional variants of languages, or language +dialects. + + For a PO file in the matrix above to be effective, the package to +which it applies should also have been internationalized and +distributed as such by its maintainer. There might be an observable +lag between the mere existence a PO file and its wide availability in a +distribution. + + If October 2006 seems to be old, you may fetch a more recent copy of +this `ABOUT-NLS' file on most GNU archive sites. The most up-to-date +matrix with full percentage details can be found at +`http://www.iro.umontreal.ca/contrib/po/HTML/matrix.html'. + +1.6 Using `gettext' in new packages +=================================== + +If you are writing a freely available program and want to +internationalize it you are welcome to use GNU `gettext' in your +package. Of course you have to respect the GNU Library General Public +License which covers the use of the GNU `gettext' library. This means +in particular that even non-free programs can use `libintl' as a shared +library, whereas only free software can use `libintl' as a static +library or use modified versions of `libintl'. + + Once the sources are changed appropriately and the setup can handle +the use of `gettext' the only thing missing are the translations. The +Free Translation Project is also available for packages which are not +developed inside the GNU project. Therefore the information given above +applies also for every other Free Software Project. Contact +`translation@iro.umontreal.ca' to make the `.pot' files available to +the translation teams. + diff --git a/ChangeLog-2015 b/ChangeLog similarity index 99% rename from ChangeLog-2015 rename to ChangeLog index 869f6bfb8..2239f72d2 100644 --- a/ChangeLog-2015 +++ b/ChangeLog @@ -1,12 +1,3 @@ -2015-01-23 Vladimir Serbinenko - - * tests/file_filter/file: Really add missing file. - -2015-01-23 Andrei Borzenkov - - * grub-core/disk/xen/xendisk.c: Accept hdX as disk names on Xen to - allow legacy menu.lst processing. - 2015-01-22 Felix Janda Remove direct _llseek code and require long filesystem libc. @@ -177,6 +168,25 @@ 2015-01-19 Kris Moore * grub-core/disk/geli.c: Support GELI v6 and v7. +======= +2015-01-23 Paulo Flabiano Smorigo + + Add Virtual LAN support. + + This patch adds support for virtual LAN (VLAN) tagging. VLAN tagging + allows multiple VLANs in a bridged network to share the same physical + network link but maintain isolation: + + http://en.wikipedia.org/wiki/IEEE_802.1Q + + * grub-core/net/ethernet.c: Add check, get, and set vlan tag id. + * grub-core/net/drivers/ieee1275/ofnet.c: Get vlan tag id from + bootargs. + * grub-core/net/arp.c: Add check. + * grub-core/net/ip.c: Likewise. + * include/grub/net/arp.h: Add vlantag attribute. + * include/grub/net/ip.h: Likewise. +>>>>>>> Add Virtual LAN support 2014-12-09 Andrei Borzenkov diff --git a/INSTALL b/INSTALL index 79a0af7d9..f6f276c44 100644 --- a/INSTALL +++ b/INSTALL @@ -11,15 +11,29 @@ GRUB depends on some software packages installed into your system. If you don't have any of them, please obtain and install them before configuring the GRUB. -* GCC 5.1.0 or later - Experimental support for clang 3.8.0 or later (results in much bigger binaries) - for i386, x86_64, arm (including thumb), arm64, mips(el), powerpc, sparc64 +* GCC 4.1.3 or later + Note: older versions may work but support is limited + Note: clang 3.2 or later works for i386 and x86_64 targets but results in + much bigger binaries. + earlier versions not tested + Note: clang 3.2 or later works for arm + None of tested clang versions generated usable thumb code + earlier versions not tested + Note: clang 3.3 or later works for arm64 + earlier versions have no arm64 support + Note: clang 3.3 or later works for mips(el) + earlier versions fail to generate .reginfo and hence gprel relocations + fail. + Note: clang 3.2 or later works for powerpc + earlier versions not tested + Note: clang doesn't support -mno-app-regs and so can't be used for sparc64 + Note: clang has no support for ia64 and hence you can't compile GRUB + for ia64 with clang * GNU Make * GNU Bison 2.3 or later * GNU gettext 0.17 or later * GNU binutils 2.9.1.0.23 or later * Flex 2.5.35 or later -* pkg-config * Other standard GNU/Unix tools * a libc with large file support (e.g. glibc 2.1 or later) @@ -35,15 +49,15 @@ For optional grub-emu features, you need: To build GRUB's graphical terminal (gfxterm), you need: -* FreeType 2.1.5 or later +* FreeType 2 or later * GNU Unifont If you use a development snapshot or want to hack on GRUB you may need the following. * Python 2.6 or later -* Autoconf 2.63 or later -* Automake 1.11 or later +* Autoconf 2.60 or later +* Automake 1.10.1 or later Prerequisites for make-check: @@ -84,11 +98,7 @@ The simplest way to compile this package is: 2. Skip this and following step if you use release tarball and proceed to step 4. If you want translations type `./linguas.sh'. - 3. Type `./bootstrap'. - - * autogen.sh (called by bootstrap) uses python. By default the - invocation is "python", but it can be overridden by setting the - variable $PYTHON. + 3. Type `./autogen.sh'. 4. Type `./configure' to configure the package for your system. If you're using `csh' on an old version of System V, you might @@ -142,20 +152,12 @@ For this example the configure line might look like (more details below) (some options are optional and included here for completeness but some rarely used options are omitted): - ./configure --host=x86_64-linux-gnu --target=arm-linux-gnueabihf \ - --with-platform=efi BUILD_CC=gcc BUILD_PKG_CONFIG=pkg-config \ - HOST_CC=x86_64-linux-gnu-gcc HOST_CFLAGS='-g -O2' \ - PKG_CONFIG=x86_64-linux-gnu-pkg-config TARGET_CC=arm-linux-gnueabihf-gcc \ - TARGET_CFLAGS='-Os -march=armv8.3-a' TARGET_CCASFLAGS='-march=armv8.3-a' \ - TARGET_OBJCOPY=arm-linux-gnueabihf-objcopy \ - TARGET_STRIP=arm-linux-gnueabihf-strip TARGET_NM=arm-linux-gnueabihf-nm \ - TARGET_RANLIB=arm-linux-gnueabihf-ranlib LEX=flex - -Normally, for building a GRUB on amd64 with tools to run on amd64 to -generate images to run on ARM, using your Linux distribution's -packaged cross compiler, the following would suffice: - - ./configure --target=arm-linux-gnueabihf --with-platform=efi +./configure BUILD_CC=gcc BUILD_FREETYPE=freetype-config --host=amd64-linux-gnu +CC=amd64-linux-gnu-gcc CFLAGS="-g -O2" FREETYPE=amd64-linux-gnu-freetype-config +--target=arm --with-platform=uboot TARGET_CC=arm-elf-gcc +TARGET_CFLAGS="-Os -march=armv6" TARGET_CCASFLAGS="-march=armv6" +TARGET_OBJCOPY="arm-elf-objcopy" TARGET_STRIP="arm-elf-strip" +TARGET_NM=arm-elf-nm TARGET_RANLIB=arm-elf-ranlib LEX=gflex You need to use following options to specify tools and platforms. For minimum version look at prerequisites. All tools not mentioned in this section under @@ -168,27 +170,24 @@ corresponding platform are not needed for the platform in question. 2. BUILD_CFLAGS= for C options for build. 3. BUILD_CPPFLAGS= for C preprocessor options for build. 4. BUILD_LDFLAGS= for linker options for build. - 5. BUILD_PKG_CONFIG= for pkg-config for build (optional). + 5. BUILD_FREETYPE= for freetype-config for build (optional). - For host 1. --host= to autoconf name of host. - 2. CC= for gcc able to compile for host. + 2. CC= for gcc able to compile for host 3. CFLAGS= for C options for host. - 4. HOST_CC= for gcc able to compile for host. - 5. HOST_CFLAGS= for C options for host. - 6. HOST_CPPFLAGS= for C preprocessor options for host. - 7. HOST_LDFLAGS= for linker options for host. - 8. PKG_CONFIG= for pkg-config for host (optional). - 9. Libdevmapper if any must be in standard linker folders (-ldevmapper) (optional). - 10. Libfuse if any must be in standard linker folders (-lfuse) (optional). - 11. Libzfs if any must be in standard linker folders (-lzfs) (optional). - 12. Liblzma if any must be in standard linker folders (-llzma) (optional). - Note: The HOST_* variables override not prefixed variables. + 4. CPPFLAGS= for C preprocessor options for host. + 5. LDFLAGS= for linker options for host. + 6. FREETYPE= for freetype-config for host (optional). + 7. Libdevmapper if any must be in standard linker folders (-ldevmapper) (optional). + 8. Libfuse if any must be in standard linker folders (-lfuse) (optional). + 9. Libzfs if any must be in standard linker folders (-lzfs) (optional). + 10. Liblzma if any must be in standard linker folders (-llzma) (optional). - For target 1. --target= to autoconf cpu name of target. 2. --with-platform to choose firmware. - 3. TARGET_CC= for gcc able to compile for target. + 3. TARGET_CC= for gcc able to compile for target 4. TARGET_CFLAGS= for C options for target. 5. TARGET_CPPFLAGS= for C preprocessor options for target. 6. TARGET_CCASFLAGS= for assembler options for target. @@ -197,10 +196,6 @@ corresponding platform are not needed for the platform in question. 9. TARGET_STRIP= for strip for target. 10. TARGET_NM= for nm for target. 11. TARGET_RANLIB= for ranlib for target. - Note: If the TARGET_* variables are not specified then they will default - to be the same as the host variables. If host variables are not - specified then the TARGET_* variables will default to be the same - as not prefixed variables. - Additionally for emu, for host and target. 1. SDL is looked for in standard linker directories (-lSDL) (optional) diff --git a/Makefile.am b/Makefile.am index bf9c1ba64..cc537a2c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = subdir-objects -Wno-portability DEPDIR = .deps-util -SUBDIRS = grub-core/lib/gnulib . +SUBDIRS = grub-core/gnulib . if COND_real_platform SUBDIRS += grub-core endif @@ -37,7 +37,7 @@ grub_script.yy.c: grub_script.yy.h CLEANFILES += grub_script.yy.c grub_script.yy.h # For libgrub.a -libgrub.pp: config-util.h grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) +libgrub.pp: grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrubmods_a_CPPFLAGS) $(libgrubkern_a_CPPFLAGS) $(CPPFLAGS) \ -D'GRUB_MOD_INIT(x)=@MARKER@x@' $^ > $@ || (rm -f $@; exit 1) CLEANFILES += libgrub.pp @@ -71,7 +71,7 @@ endif starfield_theme_files = $(srcdir)/themes/starfield/blob_w.png $(srcdir)/themes/starfield/boot_menu_c.png $(srcdir)/themes/starfield/boot_menu_e.png $(srcdir)/themes/starfield/boot_menu_ne.png $(srcdir)/themes/starfield/boot_menu_n.png $(srcdir)/themes/starfield/boot_menu_nw.png $(srcdir)/themes/starfield/boot_menu_se.png $(srcdir)/themes/starfield/boot_menu_s.png $(srcdir)/themes/starfield/boot_menu_sw.png $(srcdir)/themes/starfield/boot_menu_w.png $(srcdir)/themes/starfield/slider_c.png $(srcdir)/themes/starfield/slider_n.png $(srcdir)/themes/starfield/slider_s.png $(srcdir)/themes/starfield/starfield.png $(srcdir)/themes/starfield/terminal_box_c.png $(srcdir)/themes/starfield/terminal_box_e.png $(srcdir)/themes/starfield/terminal_box_ne.png $(srcdir)/themes/starfield/terminal_box_n.png $(srcdir)/themes/starfield/terminal_box_nw.png $(srcdir)/themes/starfield/terminal_box_se.png $(srcdir)/themes/starfield/terminal_box_s.png $(srcdir)/themes/starfield/terminal_box_sw.png $(srcdir)/themes/starfield/terminal_box_w.png $(srcdir)/themes/starfield/theme.txt $(srcdir)/themes/starfield/README $(srcdir)/themes/starfield/COPYING.CC-BY-SA-3.0 build-grub-mkfont$(BUILD_EXEEXT): util/grub-mkfont.c grub-core/unidata.c grub-core/kern/emu/misc.c util/misc.c - $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-mkfont\" $^ $(BUILD_FREETYPE_CFLAGS) $(BUILD_FREETYPE_LIBS) + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-mkfont\" $^ $(build_freetype_cflags) $(build_freetype_libs) CLEANFILES += build-grub-mkfont$(BUILD_EXEEXT) garbage-gen$(BUILD_EXEEXT): util/garbage-gen.c @@ -80,30 +80,25 @@ CLEANFILES += garbage-gen$(BUILD_EXEEXT) EXTRA_DIST += util/garbage-gen.c build-grub-gen-asciih$(BUILD_EXEEXT): util/grub-gen-asciih.c - $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(BUILD_FREETYPE_CFLAGS) $(BUILD_FREETYPE_LIBS) -Wall -Werror + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) -Wall -Werror CLEANFILES += build-grub-gen-asciih$(BUILD_EXEEXT) build-grub-gen-widthspec$(BUILD_EXEEXT): util/grub-gen-widthspec.c - $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(BUILD_FREETYPE_CFLAGS) $(BUILD_FREETYPE_LIBS) -Wall -Werror + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_MKFONT=1 -DGRUB_BUILD=1 -DGRUB_UTIL=1 $^ $(build_freetype_cflags) $(build_freetype_libs) -Wall -Werror CLEANFILES += build-grub-gen-widthspec$(BUILD_EXEEXT) if COND_STARFIELD starfield_DATA = dejavu_10.pf2 dejavu_12.pf2 dejavu_bold_14.pf2 dejavu_14.pf2 dejavu_16.pf2 $(starfield_theme_files) -dejavu_10.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -s 10 -o $@ $(DJVU_FONT_SOURCE) -CLEANFILES += dejavu_10.pf2 -dejavu_12.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -s 12 -o $@ $(DJVU_FONT_SOURCE) -CLEANFILES += dejavu_12.pf2 -dejavu_14.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -s 14 -o $@ $(DJVU_FONT_SOURCE) -CLEANFILES += dejavu_14.pf2 -dejavu_bold_14.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -b -s 14 -o $@ $(DJVU_FONT_SOURCE) -CLEANFILES += dejavu_bold_14.pf2 -dejavu_16.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -s 16 -o $@ $(DJVU_FONT_SOURCE) -CLEANFILES += dejavu_16.pf2 +dejavu_10.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -s 10 -o $@ $(DJVU_FONT_SOURCE) +dejavu_12.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -s 12 -o $@ $(DJVU_FONT_SOURCE) +dejavu_14.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -s 14 -o $@ $(DJVU_FONT_SOURCE) +dejavu_bold_14.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -b -s 14 -o $@ $(DJVU_FONT_SOURCE) +dejavu_16.pf2: $(DJVU_FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -s 16 -o $@ $(DJVU_FONT_SOURCE) else starfield_DATA = endif @@ -111,28 +106,28 @@ endif EXTRA_DIST += $(starfield_theme_files) EXTRA_DIST += $(srcdir)/themes/starfield/src/slider_s.xcf $(srcdir)/themes/starfield/src/slider_n.xcf $(srcdir)/themes/starfield/src/slider_c.xcf $(srcdir)/themes/starfield/src/blob_nw.xcf $(srcdir)/themes/starfield/src/bootmenu/center.xcf $(srcdir)/themes/starfield/src/bootmenu/corner.xcf $(srcdir)/themes/starfield/src/bootmenu/side.xcf $(srcdir)/themes/starfield/src/terminalbox/side.xcf $(srcdir)/themes/starfield/src/terminalbox/corner.xcf $(srcdir)/themes/starfield/src/terminalbox/center.xcf -unicode.pf2: $(FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -o $@ $(FONT_SOURCE) || (rm -f $@; exit 1) +unicode.pf2: $(FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -o $@ $(FONT_SOURCE) || (rm -f $@; exit 1) CLEANFILES += unicode.pf2 # Arrows and lines are needed to draw the menu, so always include them UNICODE_ARROWS=0x2190-0x2193 UNICODE_LINES=0x2501-0x251B -ascii.pf2: $(FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES) || (rm -f $@; exit 1) +ascii.pf2: $(FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES) || (rm -f $@; exit 1) CLEANFILES += ascii.pf2 -euro.pf2: $(FONT_SOURCE) build-grub-mkfont$(BUILD_EXEEXT) - ./build-grub-mkfont$(BUILD_EXEEXT) -o $@ $(FONT_SOURCE) -r 0x0-0x4ff,0x1e00-0x1fff,$(UNICODE_ARROWS),$(UNICODE_LINES) || (rm -f $@; exit 1) +euro.pf2: $(FONT_SOURCE) build-grub-mkfont + ./build-grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x4ff,0x1e00-0x1fff,$(UNICODE_ARROWS),$(UNICODE_LINES) || (rm -f $@; exit 1) CLEANFILES += euro.pf2 -ascii.h: $(FONT_SOURCE) build-grub-gen-asciih$(BUILD_EXEEXT) - ./build-grub-gen-asciih$(BUILD_EXEEXT) $(FONT_SOURCE) $@ || (rm -f $@; exit 1) +ascii.h: $(FONT_SOURCE) build-grub-gen-asciih + ./build-grub-gen-asciih $(FONT_SOURCE) $@ || (rm -f $@; exit 1) CLEANFILES += ascii.h -widthspec.h: $(FONT_SOURCE) build-grub-gen-widthspec$(BUILD_EXEEXT) - ./build-grub-gen-widthspec$(BUILD_EXEEXT) $(FONT_SOURCE) $@ || (rm -f $@; exit 1) +widthspec.h: $(FONT_SOURCE) build-grub-gen-widthspec + ./build-grub-gen-widthspec $(FONT_SOURCE) $@ || (rm -f $@; exit 1) CLEANFILES += widthspec.h # Install config.h into platformdir @@ -145,116 +140,109 @@ if COND_real_platform if COND_i386_coreboot QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_i386_multiboot QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_i386_ieee1275 QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_i386_qemu QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_i386_pc QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_i386_efi QEMU32=qemu-system-i386 -MINIMUM_CPU_LINUX=pentium2 endif if COND_x86_64_efi QEMU32=qemu-system-x86_64 -MINIMUM_CPU_LINUX=core2duo endif linux.init.x86_64: $(srcdir)/grub-core/tests/boot/linux.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -static -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux.init.i386: $(srcdir)/grub-core/tests/boot/linux.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -static -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux.init.mips: $(srcdir)/grub-core/tests/boot/linux.init-mips.S - $(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux.init.ppc: $(srcdir)/grub-core/tests/boot/linux.init-ppc.S - $(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux.init.mipsel: $(srcdir)/grub-core/tests/boot/linux.init-mips.S - $(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux.init.loongson: $(srcdir)/grub-core/tests/boot/linux.init-mips.S - $(TARGET_CC) -o $@ $< -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -DREBOOT=1 + $(TARGET_CC) -o $@ $< -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -DREBOOT=1 multiboot.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -DTARGET_MULTIBOOT=1 -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include kfreebsd.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include kfreebsd.aout: kfreebsd.elf - $(TARGET_OBJCOPY) -O a.out-i386-linux $< $@ -j .text + $(TARGET_OBJCOPY) -O a.out-i386-linux $< $@ -R .note.gnu.build-id -R .note.gnu.gold-version pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -static -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32 + $(TARGET_CC) -o $@ $< -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32 pc-chainloader.bin: pc-chainloader.elf $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32 + $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32 ntldr.bin: ntldr.elf - $(TARGET_OBJCOPY) -O binary --strip-unneeded -j .text $< $@; + $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; multiboot2.elf: $(srcdir)/grub-core/tests/boot/kernel-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -static -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1 + $(TARGET_CC) -o $@ $< -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x100000 -m32 -I$(srcdir)/include -DTARGET_MULTIBOOT2=1 kfreebsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kfreebsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m64 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@ + $(TARGET_CC) -o $@ $< -m64 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@ kfreebsd.init.i386: $(srcdir)/grub-core/tests/boot/kfreebsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@ + $(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" && freebsd-brandelf -t FreeBSD $@ knetbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DTARGET_NETBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_NETBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" kopenbsd.init.i386: $(srcdir)/grub-core/tests/boot/kbsd.init-i386.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m32 -static -nostdlib -nostdinc -DTARGET_OPENBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m32 -nostdlib -nostdinc -DTARGET_OPENBSD=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" knetbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m64 -DTARGET_NETBSD=1 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m64 -DTARGET_NETBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" kopenbsd.init.x86_64: $(srcdir)/grub-core/tests/boot/kbsd.init-x86_64.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S - $(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -static -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" + $(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" linux-initramfs.mips: linux.init.mips Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.ppc: linux.init.ppc Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.mipsel: linux.init.mipsel Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.loongson: linux.init.loongson Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.i386: linux.init.i386 Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR linux-initramfs.x86_64: linux.init.x86_64 Makefile - TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio -R 0:0 --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR + TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR kfreebsd-mfsroot.i386.img: kfreebsd.init.i386 Makefile TDIR=`mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR @@ -313,7 +301,7 @@ bootcheck-knetbsd-x86_64: knetbsd.miniroot-image.x86_64.gz $(GRUB_PAYLOADS_DIR)/ ./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=qemu-system-x86_64 --files=/miniroot.gz=knetbsd.miniroot-image.x86_64.gz --files=/knetbsd=$(GRUB_PAYLOADS_DIR)/knetbsd.x86_64 $(srcdir)/grub-core/tests/boot/knetbsd.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null bootcheck-linux-i386: linux-initramfs.i386 $(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg grub-shell - ./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=$(QEMU32) --files=/initrd=linux-initramfs.i386 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg --qemu-opts="-cpu $(MINIMUM_CPU_LINUX)" | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null + ./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=$(QEMU32) --files=/initrd=linux-initramfs.i386 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.i386 $(srcdir)/grub-core/tests/boot/linux.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null bootcheck-linux-x86_64: linux-initramfs.x86_64 $(GRUB_PAYLOADS_DIR)/linux.x86_64 $(srcdir)/grub-core/tests/boot/linux.cfg grub-shell ./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=qemu-system-x86_64 --files=/initrd=linux-initramfs.x86_64 --files=/linux=$(GRUB_PAYLOADS_DIR)/linux.x86_64 $(srcdir)/grub-core/tests/boot/linux.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null @@ -352,41 +340,33 @@ bootcheck-ntldr: ntldr.bin $(srcdir)/grub-core/tests/boot/ntldr.cfg grub-shell ./grub-shell --timeout=$(BOOTCHECK_TIMEOUT) --qemu=$(QEMU32) --files=/ntldr.bin=ntldr.bin $(srcdir)/grub-core/tests/boot/ntldr.cfg | grep $(SUCCESSFUL_BOOT_STRING) > /dev/null if COND_i386_efi -# NetBSD has no support for finding ACPI on EFI -BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386 -endif - -if COND_x86_64_efi -# NetBSD has no support for finding ACPI on EFI -BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386 -endif - -if COND_i386_multiboot -# *BSD requires ACPI -BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 -endif - - -if COND_i386_qemu -# *BSD requires ACPI -BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 -endif - -if COND_i386_coreboot BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386 endif -if COND_i386_ieee1275 -# *BSD requires ACPI -#legacy protocol (linux16) makes early BIOS calls. -BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 +if COND_x86_64_efi +BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386 +endif + +if COND_i386_multiboot +# FreeBSD requires ACPI +BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 +endif + +if COND_i386_coreboot +# Freebsd requires ACPI +BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 +endif + +if COND_i386_qemu +# FreeBSD requires ACPI +BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 endif if COND_i386_pc #pc chainloader by definition is only for i386-pc #ntldr and bootmgr require BIOS. -#legacy protocol (linux16) makes early BIOS calls. -# 32-bit NetBSD crashes early on non-BIOS +#legacy protocol makes early BIOS calls. +# NetBSD crashes early on non-BIOS BOOTCHECKS = bootcheck-kfreebsd-aout bootcheck-kopenbsd-i386 bootcheck-kopenbsd-x86_64 bootcheck-multiboot bootcheck-multiboot2 bootcheck-linux-i386 bootcheck-linux-x86_64 bootcheck-knetbsd-x86_64 bootcheck-kfreebsd-x86_64 bootcheck-kfreebsd-i386 bootcheck-pc-chainloader bootcheck-ntldr bootcheck-linux16-i386 bootcheck-linux16-x86_64 bootcheck-knetbsd-i386 endif @@ -412,7 +392,7 @@ endif .PHONY: bootcheck-linux-i386 bootcheck-linux-x86_64 \ bootcheck-kfreebsd-i386 bootcheck-kfreebsd-x86_64 \ bootcheck-knetbsd-i386 bootcheck-knetbsd-x86_64 \ - bootcheck-linux-mips FORCE + bootcheck-linux-mips # Randomly generated SUCCESSFUL_BOOT_STRING=3e49994fd5d82b7c9298d672d774080d @@ -422,10 +402,8 @@ BOOTCHECK_TIMEOUT=180 bootcheck: $(BOOTCHECKS) if COND_i386_coreboot -FS_PAYLOAD_MODULES ?= $(shell cat grub-core/fs.lst) -default_payload.elf: grub-mkstandalone grub-mkimage FORCE - test -f $@ && rm $@ || true - pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu $(FS_PAYLOAD_MODULES) password_pbkdf2 $(EXTRA_PAYLOAD_MODULES)' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg +default_payload.elf: grub-mkstandalone grub-mkimage + pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o $@ --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos xfs ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=$(srcdir)/coreboot.cfg endif endif @@ -461,27 +439,3 @@ windowszip: windowsdir rm -rf $(windowsdir) EXTRA_DIST += linguas.sh - -changelog_start_date = 2015-01-23 -gitlog_to_changelog = $(top_srcdir)/build-aux/gitlog-to-changelog - -ChangeLog: FORCE - if test -d $(top_srcdir)/.git; then \ - $(gitlog_to_changelog) --srcdir=$(top_srcdir) --since=$(changelog_start_date) > '$@.tmp'; \ - rm -f '$@'; mv '$@.tmp' '$@'; \ - else \ - touch $@; \ - fi - -EXTRA_DIST += ChangeLog ChangeLog-2015 - -syslinux_test: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg - -# Mimic simplify_filename from grub-core/lib/syslinux_parse.c, so that we -# can predict its behaviour in tests. We have to pre-substitute this before -# calling config.status, as config.status offers no reliable way to hook in -# a command between setting ac_abs_top_srcdir and emitting output files. -tests/syslinux/ubuntu10.04_grub.cfg: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg.in - simplified_abs_top_srcdir=`echo "$(abs_top_srcdir)" | sed 's,//,/,g; s,/\./,/,g; :loop; s,/[^/][^/]*/\.\.\(/\|$$\),\1,; t loop'`; \ - sed "s,@simplified_abs_top_srcdir@,$$simplified_abs_top_srcdir,g" $(srcdir)/tests/syslinux/ubuntu10.04_grub.cfg.in | $(top_builddir)/config.status --file=$@:- -CLEANFILES += tests/syslinux/ubuntu10.04_grub.cfg diff --git a/Makefile.util.def b/Makefile.util.def index d9e2bd84d..fed96d864 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -3,7 +3,7 @@ AutoGen definitions Makefile.tpl; library = { name = libgrubkern.a; cflags = '$(CFLAGS_GNULIB)'; - cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json'; + cppflags = '$(CPPFLAGS_GNULIB)'; common = util/misc.c; common = grub-core/kern/command.c; @@ -36,9 +36,7 @@ library = { common = grub-core/kern/misc.c; common = grub-core/kern/partition.c; common = grub-core/lib/crypto.c; - common = grub-core/lib/json/json.c; common = grub-core/disk/luks.c; - common = grub-core/disk/luks2.c; common = grub-core/disk/geli.c; common = grub-core/disk/cryptodisk.c; common = grub-core/disk/AFSplitter.c; @@ -50,13 +48,12 @@ library = { common = grub-core/partmap/gpt.c; common = grub-core/partmap/msdos.c; common = grub-core/fs/proc.c; - common = grub-core/fs/archelp.c; }; library = { name = libgrubmods.a; cflags = '-fno-builtin -Wno-undef'; - cppflags = '-I$(srcdir)/grub-core/lib/minilzo -I$(srcdir)/grub-core/lib/xzembed -I$(srcdir)/grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H'; + cppflags = '-I$(top_srcdir)/grub-core/lib/minilzo -I$(srcdir)/grub-core/lib/xzembed -DMINILZO_HAVE_CONFIG_H'; common_nodist = grub_script.tab.c; common_nodist = grub_script.yy.c; @@ -94,6 +91,7 @@ library = { common = grub-core/fs/bfs.c; common = grub-core/fs/btrfs.c; common = grub-core/fs/cbfs.c; + common = grub-core/fs/archelp.c; common = grub-core/fs/cpio.c; common = grub-core/fs/cpio_be.c; common = grub-core/fs/odc.c; @@ -101,7 +99,6 @@ library = { common = grub-core/fs/ext2.c; common = grub-core/fs/fat.c; common = grub-core/fs/exfat.c; - common = grub-core/fs/f2fs.c; common = grub-core/fs/fshelp.c; common = grub-core/fs/hfs.c; common = grub-core/fs/hfsplus.c; @@ -141,7 +138,7 @@ library = { common = grub-core/lib/crc.c; common = grub-core/lib/adler32.c; common = grub-core/lib/crc64.c; - common = grub-core/lib/datetime.c; + common = grub-core/normal/datetime.c; common = grub-core/normal/misc.c; common = grub-core/partmap/acorn.c; common = grub-core/partmap/amiga.c; @@ -167,15 +164,6 @@ library = { common = grub-core/lib/xzembed/xz_dec_bcj.c; common = grub-core/lib/xzembed/xz_dec_lzma2.c; common = grub-core/lib/xzembed/xz_dec_stream.c; - common = grub-core/lib/zstd/debug.c; - common = grub-core/lib/zstd/entropy_common.c; - common = grub-core/lib/zstd/error_private.c; - common = grub-core/lib/zstd/fse_decompress.c; - common = grub-core/lib/zstd/huf_decompress.c; - common = grub-core/lib/zstd/module.c; - common = grub-core/lib/zstd/xxhash.c; - common = grub-core/lib/zstd/zstd_common.c; - common = grub-core/lib/zstd/zstd_decompress.c; }; program = { @@ -184,8 +172,6 @@ program = { common = util/grub-mkimage.c; common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; common = util/resolve.c; common = grub-core/kern/emu/argp_common.c; common = grub-core/osdep/init.c; @@ -200,7 +186,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBLZMA)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cppflags = '-DGRUB_PKGLIBDIR=\"$(pkglibdir)\"'; @@ -217,7 +203,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -232,7 +218,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -242,23 +228,12 @@ program = { common = util/grub-editenv.c; common = util/editenv.c; - common = util/grub-install-common.c; common = grub-core/osdep/init.c; - common = grub-core/osdep/compress.c; - extra_dist = grub-core/osdep/unix/compress.c; - extra_dist = grub-core/osdep/basic/compress.c; - common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; - common = grub-core/osdep/config.c; - common = util/config.c; - common = util/resolve.c; - ldadd = '$(LIBLZMA)'; ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -274,7 +249,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -297,7 +272,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -313,7 +288,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) -lfuse'; condition = COND_GRUB_MOUNT; }; @@ -325,14 +300,14 @@ program = { common = grub-core/kern/emu/argp_common.c; common = grub-core/osdep/init.c; - cflags = '$(FREETYPE_CFLAGS)'; + cflags = '$(freetype_cflags)'; cppflags = '-DGRUB_MKFONT=1'; ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; - ldadd = '$(FREETYPE_LIBS)'; + ldadd = grub-core/gnulib/libgnu.a; + ldadd = '$(freetype_libs)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; condition = COND_GRUB_MKFONT; }; @@ -350,7 +325,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -372,7 +347,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = libgrubgcry.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cppflags = '-DGRUB_SETUP_FUNC=grub_util_bios_setup'; }; @@ -392,7 +367,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; ldadd = libgrubgcry.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cppflags = '-DGRUB_SETUP_FUNC=grub_util_sparc_setup'; }; @@ -408,7 +383,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -423,7 +398,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -438,8 +413,8 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + ldadd = grub-core/gnulib/libgnu.a; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; data = { @@ -515,12 +490,6 @@ script = { installdir = grubconf; }; -script = { - name = '30_uefi-firmware'; - common = util/grub.d/30_uefi-firmware.in; - installdir = grubconf; -}; - script = { name = '40_custom'; common = util/grub.d/40_custom.in; @@ -541,8 +510,6 @@ program = { common = util/render-label.c; common = util/glue-efi.c; common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; common = util/grub-install-common.c; common = util/setup_bios.c; common = util/setup_sparc.c; @@ -571,7 +538,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; condition = COND_HAVE_EXEC; @@ -585,8 +552,6 @@ program = { common = util/render-label.c; common = util/glue-efi.c; common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; common = util/grub-install-common.c; common = util/setup_bios.c; common = util/setup_sparc.c; @@ -618,7 +583,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -630,8 +595,6 @@ program = { common = util/grub-install.c; common = util/probe.c; common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; common = util/grub-install-common.c; common = util/setup_bios.c; common = util/setup_sparc.c; @@ -650,6 +613,7 @@ program = { common = grub-core/disk/host.c; common = util/resolve.c; + enable = noemu; common = grub-core/kern/emu/argp_common.c; common = grub-core/osdep/init.c; @@ -657,7 +621,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -669,8 +633,6 @@ program = { common = util/grub-mknetdir.c; common = util/mkimage.c; - common = util/grub-mkimage32.c; - common = util/grub-mkimage64.c; common = util/grub-install-common.c; common = util/setup_bios.c; common = util/setup_sparc.c; @@ -693,7 +655,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -803,12 +765,6 @@ script = { common = tests/xfs_test.in; }; -script = { - testcase; - name = f2fs_test; - common = tests/f2fs_test.in; -}; - script = { testcase; name = nilfs2_test; @@ -1200,18 +1156,6 @@ script = { common = tests/file_filter_test.in; }; -script = { - testcase; - name = grub_cmd_test; - common = tests/grub_cmd_test.in; -}; - -script = { - testcase; - name = syslinux_test; - common = tests/syslinux_test.in; -}; - program = { testcase; name = example_unit_test; @@ -1223,7 +1167,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1238,7 +1182,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1253,7 +1197,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1269,7 +1213,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; condition = COND_HAVE_CXX; }; @@ -1285,7 +1229,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1300,7 +1244,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1318,7 +1262,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1334,7 +1278,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1352,7 +1296,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; @@ -1381,6 +1325,6 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; - ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = grub-core/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; diff --git a/NEWS b/NEWS index e7ca7fb3f..a61df942a 100644 --- a/NEWS +++ b/NEWS @@ -1,21 +1,3 @@ -New in 2.04: - -* GCC 8 and 9 support. -* Gnulib integration overhaul. -* RISC-V support. -* Xen PVH support. -* Native UEFI secure boot support. -* UEFI TPM driver. -* New IEEE 1275 obdisk driver. -* Btrfs RAID 5 and RIAD 6 support. -* PARTUUID support. -* VLAN support. -* Native DHCP support. -* Many ARM and ARM64 fixes. -* Many SPARC fixes. -* Many IEEE 1275 fixes. -* ...and tons of other fixes and cleanups... - New in 2.02: * New/improved filesystem and disk support: @@ -35,8 +17,6 @@ New in 2.02: files. * ZFS features support. * ZFS LZ4 support. - * XFS V5 format support. - * LVM RAID1 support. * New/improved terminal and video support: * Monochrome text (matching `hercules' in GRUB Legacy). @@ -68,9 +48,6 @@ New in 2.02: * Improve TFTP robustness. * Parse `nd' disk names in GRUB Legacy configuration files. * Issue separate DNS queries for IPv4 and IPv6. - * Support IPv6 Router Advertisement to configure default router. - * New variable net__next_server containing next server - from BOOTP reply. * Coreboot improvements: * CBFS support both in on-disk images (loopback) and flash. @@ -81,7 +58,6 @@ New in 2.02: * Command for inspecting coreboot tables (`lscoreboot'). * New target default_payload.elf. * Increased maximal core size. - * Prefer pmtimer for TSC calibration. * New/improved platform support: * New `efifwsetup' and `lsefi' commands on EFI platforms. @@ -109,17 +85,6 @@ New in 2.02: * Support for USB debug dongles. * Support for *-emu on all platforms (previously only i386/x86_64 worked). * Support *-emu on Windows. - * New platform `none' which builds only user level utilities. This is now - default if target CPU is not supported. - * Support for booting little-endian Linux kernel on powerpc. - * Support network boot with Oracle sun4v vnet devices. - * Added SAS disks to the IEEE 1275 Open Firmware device list. - * Try multiple methods for TSC (timestamp counter) calibration - PIT, pmtimer, - EFI Stall. If everything fails, use hardcoded frequency 800MHz. - * Support Hyper-V Gen2 platforms which lack PIT for TSC calibration. - * Map UEFI Persistent Memory to E820 persistent memory. - * New Xen loader on ARM64. - * Respect alignment requirement for block device IO buffers on EFI. * Security: * Add optional facility to enforce that all files read by the core image @@ -158,11 +123,6 @@ New in 2.02: menu entry immediately. * New `file' command and grub-file utility to check file types. * New syslinux configuration file parser. - * Set menu entry class to primary OS name returned by os-prober to display - OS specific icon. - * On Linux x86 detect EFI word size in grub-install and automatically select - correct platform (x86_64-efi or i386-efi) to install. Requires Linux kernel - 4.0 or higher. * Build system: * Remove all uses of nested functions; GRUB no longer requires an @@ -183,15 +143,6 @@ New in 2.02: Python 2.6. * modinfo.sh contains build information now. * Added many new tests to improve robustness. - * Target is built without libgcc now. Necessary builtins are reimplemented - directly. This removes requirement for target-specific runtime on build - system. - * emu libusb support removed (was broken and unmaintained). - * powerpc64le compile support. - * Use fixed timestamp when generating GRUB image for reproducible builds. - * Verify at build time that modules contain only supported relocations and their - structure matches what boot-time module loader expects. - * Do not require fonts on powerpc-ieee1275. * Revision control moved to git. diff --git a/README b/README index 685b01657..b30a4b68b 100644 --- a/README +++ b/README @@ -12,6 +12,8 @@ The URL is . More extensive documentation is available in the Info manual, accessible using 'info grub' after building and installing GRUB 2. +Please look at the GRUB Wiki for testing +procedures. There are a number of important user-visible differences from the first version of GRUB, now known as GRUB Legacy. For a summary, please diff --git a/TODO b/TODO index a9b6d3523..6ec1521cd 100644 --- a/TODO +++ b/TODO @@ -7,3 +7,7 @@ glance. So write to first. For bug tracking, refer to: http://savannah.gnu.org/bugs/?group=grub + +Our wiki also lists some areas that need work: + + http://grub.enbug.org/ diff --git a/acinclude.m4 b/acinclude.m4 index 78cdf6e1d..b2bb88d83 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -93,7 +93,7 @@ else fi grub_cv_prog_objcopy_absolute=yes for link_addr in 0x2000 0x8000 0x7C00; do - if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then : + if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then : else AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr]) fi @@ -210,6 +210,80 @@ fi ]) +dnl Mass confusion! +dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit +dnl instructions, but implicitly insert addr32 and data32 bytes so +dnl that the code works in real mode''. +dnl +dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit +dnl instructions,'' which seems right. This requires the programmer +dnl to explicitly insert addr32 and data32 instructions when they want +dnl them. +dnl +dnl We only support the newer versions, because the old versions cause +dnl major pain, by requiring manual assembly to get 16-bit instructions into +dnl asm files. +AC_DEFUN([grub_I386_ASM_ADDR32], +[AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT]) +AC_MSG_CHECKING([for .code16 addr32 assembler support]) +AC_CACHE_VAL(grub_cv_i386_asm_addr32, +[cat > conftest.s.in <<\EOF + .code16 +l1: @ADDR32@ movb %al, l1 +EOF + +if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then + sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s +else + sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s +fi + +if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then + grub_cv_i386_asm_addr32=yes +else + grub_cv_i386_asm_addr32=no +fi + +rm -f conftest*]) + +AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) + +dnl Later versions of GAS requires that addr32 and data32 prefixes +dnl appear in the same lines as the instructions they modify, while +dnl earlier versions requires that they appear in separate lines. +AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT], +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING(dnl +[whether addr32 must be in the same line as the instruction]) +AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement, +[cat > conftest.s <<\EOF + .code16 +l1: addr32 movb %al, l1 +EOF + +if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then + grub_cv_i386_asm_prefix_requirement=yes +else + grub_cv_i386_asm_prefix_requirement=no +fi + +rm -f conftest*]) + +if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then + grub_tmp_addr32="addr32" + grub_tmp_data32="data32" +else + grub_tmp_addr32="addr32;" + grub_tmp_data32="data32;" +fi + +ADDR32=$grub_tmp_addr32 +DATA32=$grub_tmp_data32 + +AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])]) + + dnl Check what symbol is defined as a bss start symbol. dnl Written by Michael Hohmoth and Yoshinori K. Okuji. AC_DEFUN([grub_CHECK_BSS_START_SYMBOL], @@ -390,58 +464,6 @@ else [fi] ]) -AC_DEFUN([grub_CHECK_LINK_PIE],[ -[# Position independent executable. -link_nopie_needed=no] -AC_MSG_CHECKING([whether linker needs disabling of PIE to work]) -AC_LANG_CONFTEST([AC_LANG_SOURCE([[]])]) - -[if eval "$ac_compile -Wl,-r,-d -nostdlib -Werror -o conftest.o" 2> /dev/null; then] - AC_MSG_RESULT([no]) - [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? - rm -f conftest.o -else - link_nopie_needed=yes] - AC_MSG_RESULT([yes]) -[fi] -]) - - -dnl Check if the Linker supports `-no-pie'. -AC_DEFUN([grub_CHECK_NO_PIE], -[AC_MSG_CHECKING([whether linker accepts -no-pie]) -AC_CACHE_VAL(grub_cv_cc_ld_no_pie, -[save_LDFLAGS="$LDFLAGS" -LDFLAGS="$LDFLAGS -no-pie -nostdlib -Werror" -AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_ld_no_pie=yes], - [grub_cv_cc_ld_no_pie=no]) -LDFLAGS="$save_LDFLAGS" -]) -AC_MSG_RESULT([$grub_cv_cc_ld_no_pie]) -nopie_possible=no -if test "x$grub_cv_cc_ld_no_pie" = xyes ; then - nopie_possible=yes -fi -]) - -AC_DEFUN([grub_CHECK_NO_PIE_ONEWORD], -[AC_MSG_CHECKING([whether linker accepts -nopie]) -AC_CACHE_VAL(grub_cv_cc_ld_no_pie_oneword, -[save_LDFLAGS="$LDFLAGS" -LDFLAGS="$LDFLAGS -nopie -nostdlib -Werror" -AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_ld_no_pie_oneword=yes], - [grub_cv_cc_ld_no_pie_oneword=no]) -LDFLAGS="$save_LDFLAGS" -]) -AC_MSG_RESULT([$grub_cv_cc_ld_no_pie_oneword]) -nopie_oneword_possible=no -if test "x$grub_cv_cc_ld_no_pie_oneword" = xyes ; then - nopie_oneword_possible=yes -fi -]) - dnl Check if the C compiler supports `-fPIC'. AC_DEFUN([grub_CHECK_PIC],[ [# Position independent executable. diff --git a/asm-tests/arm.S b/asm-tests/arm.S deleted file mode 100644 index 97c2546bf..000000000 --- a/asm-tests/arm.S +++ /dev/null @@ -1,20 +0,0 @@ -/* on arm clang doesn't support .arch directive */ - - .text - .syntax unified - -#if !defined (__thumb2__) - .arch armv7a - .arm -#else - .arch armv7 - .thumb -#endif - mcr p15, 0, r11, c7, c14, 2 - - /* clang restricts access to dsb/isb despite .arch */ - dsb - isb - - - diff --git a/asm-tests/i386-pc.S b/asm-tests/i386-pc.S deleted file mode 100644 index d037744f9..000000000 --- a/asm-tests/i386-pc.S +++ /dev/null @@ -1,18 +0,0 @@ -/* on x86 old clang doesn't support .code16 - newer clang supports it but creates 6-byte jumps instead of 3-byte ones - which makes us go over boot sector size. - Starting with 3.9 clang emits 3-byte jumps but still creates 8-bytes movl - instead of 5-bytes, so code overflows into data. */ - - .code16 - jmp far - .org 4 - jmp nearer - .org 6 - movl nearer, %ebx - .org 11 - .space 100 -nearer: - .space 200 -far: - .byte 0 diff --git a/asm-tests/i386.S b/asm-tests/i386.S deleted file mode 100644 index 30adc4fe2..000000000 --- a/asm-tests/i386.S +++ /dev/null @@ -1,4 +0,0 @@ -/* on x86 old clang doesn't support .code16 */ - - .code16 - movb %al, %bl diff --git a/asm-tests/mips.S b/asm-tests/mips.S deleted file mode 100644 index 1312d47d5..000000000 --- a/asm-tests/mips.S +++ /dev/null @@ -1,11 +0,0 @@ -/* on mips clang doesn't support privilegied instructions, doubleword store/load - and crashes with hand-written assembly - */ - - .set mips3 - sync - ld $t2, 0($t1) - -a: - addiu $t1, $s0, (b - a) -b: nop diff --git a/asm-tests/powerpc.S b/asm-tests/powerpc.S deleted file mode 100644 index 396a6cce9..000000000 --- a/asm-tests/powerpc.S +++ /dev/null @@ -1,8 +0,0 @@ -/* clang <= 3.3 doesn't handle most of ppc assembly, not even inline assembly - used by gcrypt */ -/* Cache invalidation loop is a fair test. */ - li 5, 0 -1: icbi 5, 3 - addi 5, 5, 32 - cmpw 5, 4 - blt 1b diff --git a/asm-tests/sparc64.S b/asm-tests/sparc64.S deleted file mode 100644 index 03c5fe02a..000000000 --- a/asm-tests/sparc64.S +++ /dev/null @@ -1,9 +0,0 @@ - .text -1: - /* A small list of examples of what clang doesn't support. */ - clr %o0 - lduw [%o4 + 4], %o4 - and %o6, ~0xff, %o6 - stw %o5, [%o3] - bne,pt %icc, 1b - nop diff --git a/autogen.sh b/autogen.sh index 31b0ced7e..7424428d6 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,25 +2,17 @@ set -e -if [ ! -e grub-core/lib/gnulib/stdlib.in.h ]; then - echo "Gnulib not yet bootstrapped; run ./bootstrap instead." >&2 - exit 1 -fi - -# Set ${PYTHON} to plain 'python' if not set already -: ${PYTHON:=python} - export LC_COLLATE=C unset LC_ALL -find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath './gnulib/*' ! -ipath './grub-core/lib/gnulib/*' |sort > po/POTFILES.in +find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' |sort > po/POTFILES.in find util -iname '*.in' ! -name Makefile.in |sort > po/POTFILES-shell.in echo "Importing unicode..." -${PYTHON} util/import_unicode.py unicode/UnicodeData.txt unicode/BidiMirroring.txt unicode/ArabicShaping.txt grub-core/unidata.c +python util/import_unicode.py unicode/UnicodeData.txt unicode/BidiMirroring.txt unicode/ArabicShaping.txt grub-core/unidata.c echo "Importing libgcrypt..." -${PYTHON} util/import_gcry.py grub-core/lib/libgcrypt/ grub-core +python util/import_gcry.py grub-core/lib/libgcrypt/ grub-core sed -n -f util/import_gcrypth.sed < grub-core/lib/libgcrypt/src/gcrypt.h.in > include/grub/gcrypt/gcrypt.h if [ -f include/grub/gcrypt/g10lib.h ]; then rm include/grub/gcrypt/g10lib.h @@ -28,14 +20,14 @@ fi if [ -d grub-core/lib/libgcrypt-grub/mpi/generic ]; then rm -rf grub-core/lib/libgcrypt-grub/mpi/generic fi -cp grub-core/lib/libgcrypt-grub/src/g10lib.h include/grub/gcrypt/g10lib.h +ln -s ../../../grub-core/lib/libgcrypt-grub/src/g10lib.h include/grub/gcrypt/g10lib.h cp -R grub-core/lib/libgcrypt/mpi/generic grub-core/lib/libgcrypt-grub/mpi/generic for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul2.c mpih-mul3.c mpih-lshift.c mpih-rshift.c; do if [ -h grub-core/lib/libgcrypt-grub/mpi/"$x" ] || [ -f grub-core/lib/libgcrypt-grub/mpi/"$x" ]; then rm grub-core/lib/libgcrypt-grub/mpi/"$x" fi - cp grub-core/lib/libgcrypt-grub/mpi/generic/"$x" grub-core/lib/libgcrypt-grub/mpi/"$x" + ln -s generic/"$x" grub-core/lib/libgcrypt-grub/mpi/"$x" done echo "Generating Automake input..." @@ -62,8 +54,8 @@ for extra in contrib/*/Makefile.core.def; do fi done -${PYTHON} gentpl.py $UTIL_DEFS > Makefile.util.am -${PYTHON} gentpl.py $CORE_DEFS > grub-core/Makefile.core.am +python gentpl.py $UTIL_DEFS > Makefile.util.am +python gentpl.py $CORE_DEFS > grub-core/Makefile.core.am for extra in contrib/*/Makefile.common; do if test -e "$extra"; then @@ -87,17 +79,6 @@ done echo "Saving timestamps..." echo timestamp > stamp-h.in -if [ -z "$FROM_BOOTSTRAP" ]; then - # Unaided autoreconf is likely to install older versions of many files - # than the ones provided by Gnulib, but in most cases this won't matter - # very much. This mode is provided so that you can run ./autogen.sh to - # regenerate the GRUB build system in an unpacked release tarball (perhaps - # after patching it), even on systems that don't have access to - # gnulib.git. - echo "Running autoreconf..." - cp -a INSTALL INSTALL.grub - autoreconf -vif - mv INSTALL.grub INSTALL -fi - +echo "Running autoreconf..." +autoreconf -vi exit 0 diff --git a/bootstrap b/bootstrap deleted file mode 100755 index 5b08e7e2d..000000000 --- a/bootstrap +++ /dev/null @@ -1,1073 +0,0 @@ -#! /bin/sh -# Print a version string. -scriptversion=2019-01-04.17; # UTC - -# Bootstrap this package from checked-out sources. - -# Copyright (C) 2003-2019 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# Originally written by Paul Eggert. The canonical version of this -# script is maintained as build-aux/bootstrap in gnulib, however, to -# be useful to your project, you should place a copy of it under -# version control in the top-level directory of your project. The -# intent is that all customization can be done with a bootstrap.conf -# file also maintained in your version control; gnulib comes with a -# template build-aux/bootstrap.conf to get you started. - -# Please report bugs or propose patches to bug-gnulib@gnu.org. - -nl=' -' - -# Ensure file names are sorted consistently across platforms. -LC_ALL=C -export LC_ALL - -# Ensure that CDPATH is not set. Otherwise, the output from cd -# would cause trouble in at least one use below. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - -local_gl_dir=gl - -# Honor $PERL, but work even if there is none. -PERL="${PERL-perl}" - -me=$0 - -default_gnulib_url=git://git.sv.gnu.org/gnulib - -usage() { - cat <&2 -} - -# warn_ WORD1... -warn_ () -{ - # If IFS does not start with ' ', set it and emit the warning in a subshell. - case $IFS in - ' '*) warnf_ '%s\n' "$*";; - *) (IFS=' '; warn_ "$@");; - esac -} - -# die WORD1... -die() { warn_ "$@"; exit 1; } - -# Configuration. - -# Name of the Makefile.am -gnulib_mk=gnulib.mk - -# List of gnulib modules needed. -gnulib_modules= - -# Any gnulib files needed that are not in modules. -gnulib_files= - -: ${AUTOPOINT=autopoint} -: ${AUTORECONF=autoreconf} - -# A function to be called right after gnulib-tool is run. -# Override it via your own definition in bootstrap.conf. -bootstrap_post_import_hook() { :; } - -# A function to be called after everything else in this script. -# Override it via your own definition in bootstrap.conf. -bootstrap_epilogue() { :; } - -# The command to download all .po files for a specified domain into a -# specified directory. Fill in the first %s with the destination -# directory and the second with the domain name. -po_download_command_format=\ -"wget --mirror --level=1 -nd -q -A.po -P '%s' \ - https://translationproject.org/latest/%s/" - -# Prefer a non-empty tarname (4th argument of AC_INIT if given), else -# fall back to the package name (1st argument with munging) -extract_package_name=' - /^AC_INIT(\[*/{ - s/// - /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{ - s//\1/ - s/[],)].*// - p - q - } - s/[],)].*// - s/^GNU // - y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ - s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g - p - } -' -package=$(sed -n "$extract_package_name" configure.ac) \ - || die 'cannot find package name in configure.ac' -gnulib_name=lib$package - -build_aux=build-aux -source_base=lib -m4_base=m4 -doc_base=doc -tests_base=tests -gnulib_extra_files=" - build-aux/install-sh - build-aux/mdate-sh - build-aux/texinfo.tex - build-aux/depcomp - build-aux/config.guess - build-aux/config.sub - doc/INSTALL -" - -# Additional gnulib-tool options to use. Use "\newline" to break lines. -gnulib_tool_option_extras= - -# Other locale categories that need message catalogs. -EXTRA_LOCALE_CATEGORIES= - -# Additional xgettext options to use. Use "\\\newline" to break lines. -XGETTEXT_OPTIONS='\\\ - --flag=_:1:pass-c-format\\\ - --flag=N_:1:pass-c-format\\\ - --flag=error:3:c-format --flag=error_at_line:5:c-format\\\ -' - -# Package bug report address and copyright holder for gettext files -COPYRIGHT_HOLDER='Free Software Foundation, Inc.' -MSGID_BUGS_ADDRESS=bug-$package@gnu.org - -# Files we don't want to import. -excluded_files= - -# File that should exist in the top directory of a checked out hierarchy, -# but not in a distribution tarball. -checkout_only_file=README-hacking - -# Whether to use copies instead of symlinks. -copy=false - -# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want -# those files to be generated in directories like lib/, m4/, and po/. -# Or set it to 'auto' to make this script select which to use based -# on which version control system (if any) is used in the source directory. -vc_ignore=auto - -# Set this to true in bootstrap.conf to enable --bootstrap-sync by -# default. -bootstrap_sync=false - -# Use git to update gnulib sources -use_git=true - -check_exists() { - if test "$1" = "--verbose"; then - ($2 --version /dev/null 2>&1 - if test $? -ge 126; then - # If not found, run with diagnostics as one may be - # presented with env variables to set to find the right version - ($2 --version /dev/null 2>&1 - fi - - test $? -lt 126 -} - -# find_tool ENVVAR NAMES... -# ------------------------- -# Search for a required program. Use the value of ENVVAR, if set, -# otherwise find the first of the NAMES that can be run. -# If found, set ENVVAR to the program name, die otherwise. -# -# FIXME: code duplication, see also gnu-web-doc-update. -find_tool () -{ - find_tool_envvar=$1 - shift - find_tool_names=$@ - eval "find_tool_res=\$$find_tool_envvar" - if test x"$find_tool_res" = x; then - for i; do - if check_exists $i; then - find_tool_res=$i - break - fi - done - fi - if test x"$find_tool_res" = x; then - warn_ "one of these is required: $find_tool_names;" - die "alternatively set $find_tool_envvar to a compatible tool" - fi - eval "$find_tool_envvar=\$find_tool_res" - eval "export $find_tool_envvar" -} - -# Override the default configuration, if necessary. -# Make sure that bootstrap.conf is sourced from the current directory -# if we were invoked as "sh bootstrap". -case "$0" in - */*) test -r "$0.conf" && . "$0.conf" ;; - *) test -r "$0.conf" && . ./"$0.conf" ;; -esac - -if test "$vc_ignore" = auto; then - vc_ignore= - test -d .git && vc_ignore=.gitignore - test -d CVS && vc_ignore="$vc_ignore .cvsignore" -fi - -if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then - use_gnulib=false -else - use_gnulib=true -fi - -# Translate configuration into internal form. - -# Parse options. - -for option -do - case $option in - --help) - usage - exit;; - --gnulib-srcdir=*) - GNULIB_SRCDIR=${option#--gnulib-srcdir=};; - --skip-po) - SKIP_PO=t;; - --force) - checkout_only_file=;; - --copy) - copy=true;; - --bootstrap-sync) - bootstrap_sync=true;; - --no-bootstrap-sync) - bootstrap_sync=false;; - --no-git) - use_git=false;; - *) - die "$option: unknown option";; - esac -done - -$use_git || test -d "$GNULIB_SRCDIR" \ - || die "Error: --no-git requires --gnulib-srcdir" - -if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then - die "Bootstrapping from a non-checked-out distribution is risky." -fi - -# Strip blank and comment lines to leave significant entries. -gitignore_entries() { - sed '/^#/d; /^$/d' "$@" -} - -# If $STR is not already on a line by itself in $FILE, insert it at the start. -# Entries are inserted at the start of the ignore list to ensure existing -# entries starting with ! are not overridden. Such entries support -# whitelisting exceptions after a more generic blacklist pattern. -insert_if_absent() { - file=$1 - str=$2 - test -f $file || touch $file - test -r $file || die "Error: failed to read ignore file: $file" - duplicate_entries=$(gitignore_entries $file | sort | uniq -d) - if [ "$duplicate_entries" ] ; then - die "Error: Duplicate entries in $file: " $duplicate_entries - fi - linesold=$(gitignore_entries $file | wc -l) - linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l) - if [ $linesold != $linesnew ] ; then - { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \ - || die "insert_if_absent $file $str: failed" - fi -} - -# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with -# insert_if_absent. -insert_vc_ignore() { - vc_ignore_file="$1" - pattern="$2" - case $vc_ignore_file in - *.gitignore) - # A .gitignore entry that does not start with '/' applies - # recursively to subdirectories, so prepend '/' to every - # .gitignore entry. - pattern=$(echo "$pattern" | sed s,^,/,);; - esac - insert_if_absent "$vc_ignore_file" "$pattern" -} - -# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac. -found_aux_dir=no -grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \ - >/dev/null && found_aux_dir=yes -grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \ - >/dev/null && found_aux_dir=yes -test $found_aux_dir = yes \ - || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it" - -# If $build_aux doesn't exist, create it now, otherwise some bits -# below will malfunction. If creating it, also mark it as ignored. -if test ! -d $build_aux; then - mkdir $build_aux - for dot_ig in x $vc_ignore; do - test $dot_ig = x && continue - insert_vc_ignore $dot_ig $build_aux - done -fi - -# Note this deviates from the version comparison in automake -# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a -# but this should suffice as we won't be specifying old -# version formats or redundant trailing .0 in bootstrap.conf. -# If we did want full compatibility then we should probably -# use m4_version_compare from autoconf. -sort_ver() { # sort -V is not generally available - ver1="$1" - ver2="$2" - - # split on '.' and compare each component - i=1 - while : ; do - p1=$(echo "$ver1" | cut -d. -f$i) - p2=$(echo "$ver2" | cut -d. -f$i) - if [ ! "$p1" ]; then - echo "$1 $2" - break - elif [ ! "$p2" ]; then - echo "$2 $1" - break - elif [ ! "$p1" = "$p2" ]; then - if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison - echo "$2 $1" - elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison - echo "$1 $2" - else # numeric, then lexicographic comparison - lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1) - if [ "$lp" = "$p2" ]; then - echo "$1 $2" - else - echo "$2 $1" - fi - fi - break - fi - i=$(($i+1)) - done -} - -get_version_sed=' -# Move version to start of line. -s/.*[v ]\([0-9]\)/\1/ - -# Skip lines that do not start with version. -/^[0-9]/!d - -# Remove characters after the version. -s/[^.a-z0-9-].*// - -# The first component must be digits only. -s/^\([0-9]*\)[a-z-].*/\1/ - -#the following essentially does s/5.005/5.5/ -s/\.0*\([1-9]\)/.\1/g -p -q' - -get_version() { - app=$1 - - $app --version >/dev/null 2>&1 || { $app --version; return 1; } - - $app --version 2>&1 | sed -n "$get_version_sed" -} - -check_versions() { - ret=0 - - while read app req_ver; do - # We only need libtoolize from the libtool package. - if test "$app" = libtool; then - app=libtoolize - fi - # Exempt git if --no-git is in effect. - if test "$app" = git; then - $use_git || continue - fi - # Honor $APP variables ($TAR, $AUTOCONF, etc.) - appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_') - test "$appvar" = TAR && appvar=AMTAR - case $appvar in - GZIP) ;; # Do not use $GZIP: it contains gzip options. - PERL::*) ;; # Keep perl modules as-is - *) eval "app=\${$appvar-$app}" ;; - esac - - # Handle the still-experimental Automake-NG programs specially. - # They remain named as the mainstream Automake programs ("automake", - # and "aclocal") to avoid gratuitous incompatibilities with - # pre-existing usages (by, say, autoreconf, or custom autogen.sh - # scripts), but correctly identify themselves (as being part of - # "GNU automake-ng") when asked their version. - case $app in - automake-ng|aclocal-ng) - app=${app%-ng} - ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || { - warn_ "Error: '$app' not found or not from Automake-NG" - ret=1 - continue - } ;; - # Another check is for perl modules. These can be written as - # e.g. perl::XML::XPath in case of XML::XPath module, etc. - perl::*) - # Extract module name - app="${app#perl::}" - if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then - warn_ "Error: perl module '$app' not found" - ret=1 - fi - continue - ;; - esac - if [ "$req_ver" = "-" ]; then - # Merely require app to exist; not all prereq apps are well-behaved - # so we have to rely on $? rather than get_version. - if ! check_exists --verbose $app; then - warn_ "Error: '$app' not found" - ret=1 - fi - else - # Require app to produce a new enough version string. - inst_ver=$(get_version $app) - if [ ! "$inst_ver" ]; then - warn_ "Error: '$app' not found" - ret=1 - else - latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2) - if [ ! "$latest_ver" = "$inst_ver" ]; then - warnf_ '%s\n' \ - "Error: '$app' version == $inst_ver is too old" \ - " '$app' version >= $req_ver is required" - ret=1 - fi - fi - fi - done - - return $ret -} - -print_versions() { - echo "Program Min_version" - echo "----------------------" - printf %s "$buildreq" - echo "----------------------" - # can't depend on column -t -} - -# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6. -# Also find the compatible sha1 utility on the BSDs -if test x"$SKIP_PO" = x; then - find_tool SHA1SUM sha1sum gsha1sum shasum sha1 -fi - -use_libtool=0 -# We'd like to use grep -E, to see if any of LT_INIT, -# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac, -# but that's not portable enough (e.g., for Solaris). -grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \ - && use_libtool=1 -grep '^[ ]*LT_INIT' configure.ac >/dev/null \ - && use_libtool=1 -if test $use_libtool = 1; then - find_tool LIBTOOLIZE glibtoolize libtoolize -fi - -# gnulib-tool requires at least automake and autoconf. -# If either is not listed, add it (with minimum version) as a prerequisite. -case $buildreq in - *automake*) ;; - *) buildreq="automake 1.9 -$buildreq" ;; -esac -case $buildreq in - *autoconf*) ;; - *) buildreq="autoconf 2.59 -$buildreq" ;; -esac - -# When we can deduce that gnulib-tool will require patch, -# and when patch is not already listed as a prerequisite, add it, too. -if test -d "$local_gl_dir" \ - && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then - case $buildreq in - *patch*) ;; - *) buildreq="patch - -$buildreq" ;; - esac -fi - -if ! printf "$buildreq" | check_versions; then - echo >&2 - if test -f README-prereq; then - die "See README-prereq for how to get the prerequisite programs" - else - die "Please install the prerequisite programs" - fi -fi - -# Warn the user if autom4te appears to be broken; this causes known -# issues with at least gettext 0.18.3. -probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -) -if test "x$probe" != xhi; then - warn_ "WARNING: your autom4te wrapper eats stdin;" - warn_ "if bootstrap fails, consider upgrading your autotools" -fi - -echo "$0: Bootstrapping from checked-out $package sources..." - -# See if we can use gnulib's git-merge-changelog merge driver. -if $use_git && test -d .git && check_exists git; then - if git config merge.merge-changelog.driver >/dev/null ; then - : - elif check_exists git-merge-changelog; then - echo "$0: initializing git-merge-changelog driver" - git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver' - git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B' - else - echo "$0: consider installing git-merge-changelog from gnulib" - fi -fi - - -cleanup_gnulib() { - status=$? - rm -fr "$gnulib_path" - exit $status -} - -git_modules_config () { - test -f .gitmodules && git config --file .gitmodules "$@" -} - -if $use_gnulib; then - if $use_git; then - gnulib_path=$(git_modules_config submodule.gnulib.path) - test -z "$gnulib_path" && gnulib_path=gnulib - fi - - # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a - # submodule, for use in the rest of the script. - - case ${GNULIB_SRCDIR--} in - -) - # Note that $use_git is necessarily true in this case. - if git_modules_config submodule.gnulib.url >/dev/null; then - echo "$0: getting gnulib files..." - git submodule init -- "$gnulib_path" || exit $? - git submodule update -- "$gnulib_path" || exit $? - - elif [ ! -d "$gnulib_path" ]; then - echo "$0: getting gnulib files..." - - trap cleanup_gnulib 1 2 13 15 - - shallow= - if test -z "$GNULIB_REVISION"; then - git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2' - fi - git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ - || cleanup_gnulib - - trap - 1 2 13 15 - fi - GNULIB_SRCDIR=$gnulib_path - ;; - *) - # Use GNULIB_SRCDIR directly or as a reference. - if $use_git && test -d "$GNULIB_SRCDIR"/.git && \ - git_modules_config submodule.gnulib.url >/dev/null; then - echo "$0: getting gnulib files..." - if git submodule -h|grep -- --reference > /dev/null; then - # Prefer the one-liner available in git 1.6.4 or newer. - git submodule update --init --reference "$GNULIB_SRCDIR" \ - "$gnulib_path" || exit $? - else - # This fallback allows at least git 1.5.5. - if test -f "$gnulib_path"/gnulib-tool; then - # Since file already exists, assume submodule init already complete. - git submodule update -- "$gnulib_path" || exit $? - else - # Older git can't clone into an empty directory. - rmdir "$gnulib_path" 2>/dev/null - git clone --reference "$GNULIB_SRCDIR" \ - "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \ - && git submodule init -- "$gnulib_path" \ - && git submodule update -- "$gnulib_path" \ - || exit $? - fi - fi - GNULIB_SRCDIR=$gnulib_path - fi - ;; - esac - - if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \ - && ! git_modules_config submodule.gnulib.url >/dev/null; then - (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib - fi - - # $GNULIB_SRCDIR now points to the version of gnulib to use, and - # we no longer need to use git or $gnulib_path below here. - - if $bootstrap_sync; then - cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || { - echo "$0: updating bootstrap and restarting..." - case $(sh -c 'echo "$1"' -- a) in - a) ignored=--;; - *) ignored=ignored;; - esac - exec sh -c \ - 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ - $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \ - "$0" "$@" --no-bootstrap-sync - } - fi - - gnulib_tool=$GNULIB_SRCDIR/gnulib-tool - <$gnulib_tool || exit $? -fi - -# Get translations. - -download_po_files() { - subdir=$1 - domain=$2 - echo "$me: getting translations into $subdir for $domain..." - cmd=$(printf "$po_download_command_format" "$subdir" "$domain") - eval "$cmd" -} - -# Mirror .po files to $po_dir/.reference and copy only the new -# or modified ones into $po_dir. Also update $po_dir/LINGUAS. -# Note po files that exist locally only are left in $po_dir but will -# not be included in LINGUAS and hence will not be distributed. -update_po_files() { - # Directory containing primary .po files. - # Overwrite them only when we're sure a .po file is new. - po_dir=$1 - domain=$2 - - # Mirror *.po files into this dir. - # Usually contains *.s1 checksum files. - ref_po_dir="$po_dir/.reference" - - test -d $ref_po_dir || mkdir $ref_po_dir || return - download_po_files $ref_po_dir $domain \ - && ls "$ref_po_dir"/*.po 2>/dev/null | - sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return - - langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g') - test "$langs" = '*' && langs=x - for po in $langs; do - case $po in x) continue;; esac - new_po="$ref_po_dir/$po.po" - cksum_file="$ref_po_dir/$po.s1" - if ! test -f "$cksum_file" || - ! test -f "$po_dir/$po.po" || - ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then - echo "$me: updated $po_dir/$po.po..." - cp "$new_po" "$po_dir/$po.po" \ - && $SHA1SUM < "$new_po" > "$cksum_file" || return - fi - done -} - -case $SKIP_PO in -'') - if test -d po; then - update_po_files po $package || exit - fi - - if test -d runtime-po; then - update_po_files runtime-po $package-runtime || exit - fi;; -esac - -symlink_to_dir() -{ - src=$1/$2 - dst=${3-$2} - - test -f "$src" && { - - # If the destination directory doesn't exist, create it. - # This is required at least for "lib/uniwidth/cjk.h". - dst_dir=$(dirname "$dst") - if ! test -d "$dst_dir"; then - mkdir -p "$dst_dir" - - # If we've just created a directory like lib/uniwidth, - # tell version control system(s) it's ignorable. - # FIXME: for now, this does only one level - parent=$(dirname "$dst_dir") - for dot_ig in x $vc_ignore; do - test $dot_ig = x && continue - ig=$parent/$dot_ig - insert_vc_ignore $ig "${dst_dir##*/}" - done - fi - - if $copy; then - { - test ! -h "$dst" || { - echo "$me: rm -f $dst" && - rm -f "$dst" - } - } && - test -f "$dst" && - cmp -s "$src" "$dst" || { - echo "$me: cp -fp $src $dst" && - cp -fp "$src" "$dst" - } - else - # Leave any existing symlink alone, if it already points to the source, - # so that broken build tools that care about symlink times - # aren't confused into doing unnecessary builds. Conversely, if the - # existing symlink's timestamp is older than the source, make it afresh, - # so that broken tools aren't confused into skipping needed builds. See - # . - test -h "$dst" && - src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && - dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && - test "$src_i" = "$dst_i" && - both_ls=$(ls -dt "$src" "$dst") && - test "X$both_ls" = "X$dst$nl$src" || { - dot_dots= - case $src in - /*) ;; - *) - case /$dst/ in - *//* | */../* | */./* | /*/*/*/*/*/) - die "invalid symlink calculation: $src -> $dst";; - /*/*/*/*/) dot_dots=../../../;; - /*/*/*/) dot_dots=../../;; - /*/*/) dot_dots=../;; - esac;; - esac - - echo "$me: ln -fs $dot_dots$src $dst" && - ln -fs "$dot_dots$src" "$dst" - } - fi - } -} - -version_controlled_file() { - parent=$1 - file=$2 - if test -d .git; then - git rm -n "$file" > /dev/null 2>&1 - elif test -d .svn; then - svn log -r HEAD "$file" > /dev/null 2>&1 - elif test -d CVS; then - grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null | - grep '^/[^/]*/[0-9]' > /dev/null - else - warn_ "no version control for $file?" - false - fi -} - -# NOTE: we have to be careful to run both autopoint and libtoolize -# before gnulib-tool, since gnulib-tool is likely to provide newer -# versions of files "installed" by these two programs. -# Then, *after* gnulib-tool (see below), we have to be careful to -# run autoreconf in such a way that it does not run either of these -# two just-pre-run programs. - -# Import from gettext. -with_gettext=yes -grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \ - with_gettext=no - -if test $with_gettext = yes || test $use_libtool = 1; then - - tempbase=.bootstrap$$ - trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15 - - > $tempbase.0 > $tempbase.1 && - find . ! -type d -print | sort > $tempbase.0 || exit - - if test $with_gettext = yes; then - # Released autopoint has the tendency to install macros that have been - # obsoleted in current gnulib, so run this before gnulib-tool. - echo "$0: $AUTOPOINT --force" - $AUTOPOINT --force || exit - fi - - # Autoreconf runs aclocal before libtoolize, which causes spurious - # warnings if the initial aclocal is confused by the libtoolized - # (or worse out-of-date) macro directory. - # libtoolize 1.9b added the --install option; but we support back - # to libtoolize 1.5.22, where the install action was default. - if test $use_libtool = 1; then - install= - case $($LIBTOOLIZE --help) in - *--install*) install=--install ;; - esac - echo "running: $LIBTOOLIZE $install --copy" - $LIBTOOLIZE $install --copy - fi - - find . ! -type d -print | sort >$tempbase.1 - old_IFS=$IFS - IFS=$nl - for file in $(comm -13 $tempbase.0 $tempbase.1); do - IFS=$old_IFS - parent=${file%/*} - version_controlled_file "$parent" "$file" || { - for dot_ig in x $vc_ignore; do - test $dot_ig = x && continue - ig=$parent/$dot_ig - insert_vc_ignore "$ig" "${file##*/}" - done - } - done - IFS=$old_IFS - - rm -f $tempbase.0 $tempbase.1 - trap - 1 2 13 15 -fi - -# Import from gnulib. - -if $use_gnulib; then - gnulib_tool_options="\ - --no-changelog\ - --aux-dir=$build_aux\ - --doc-base=$doc_base\ - --lib=$gnulib_name\ - --m4-base=$m4_base/\ - --source-base=$source_base/\ - --tests-base=$tests_base\ - --local-dir=$local_gl_dir\ - $gnulib_tool_option_extras\ - " - if test $use_libtool = 1; then - case "$gnulib_tool_options " in - *' --libtool '*) ;; - *) gnulib_tool_options="$gnulib_tool_options --libtool" ;; - esac - fi - echo "$0: $gnulib_tool $gnulib_tool_options --import ..." - $gnulib_tool $gnulib_tool_options --import $gnulib_modules \ - || die "gnulib-tool failed" - - for file in $gnulib_files; do - symlink_to_dir "$GNULIB_SRCDIR" $file \ - || die "failed to symlink $file" - done -fi - -bootstrap_post_import_hook \ - || die "bootstrap_post_import_hook failed" - -# Don't proceed if there are uninitialized submodules. In particular, -# the next step will remove dangling links, which might be links into -# uninitialized submodules. -# -# Uninitialized submodules are listed with an initial dash. -if $use_git && git submodule | grep '^-' >/dev/null; then - die "some git submodules are not initialized. " \ - "Run 'git submodule init' and bootstrap again." -fi - -# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some -# gnulib-populated directories. Such .m4 files would cause aclocal to fail. -# The following requires GNU find 4.2.3 or newer. Considering the usual -# portability constraints of this script, that may seem a very demanding -# requirement, but it should be ok. Ignore any failure, which is fine, -# since this is only a convenience to help developers avoid the relatively -# unusual case in which a symlinked-to .m4 file is git-removed from gnulib -# between successive runs of this script. -find "$m4_base" "$source_base" \ - -depth \( -name '*.m4' -o -name '*.[ch]' \) \ - -type l -xtype l -delete > /dev/null 2>&1 - -# Invoke autoreconf with --force --install to ensure upgrades of tools -# such as ylwrap. -AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS" - -# Some systems (RHEL 5) are using ancient autotools, for which the -# --no-recursive option had not been invented. Detect that lack and -# omit the option when it's not supported. FIXME in 2017: remove this -# hack when RHEL 5 autotools are updated, or when they become irrelevant. -case $($AUTORECONF --help) in - *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";; -esac - -# Tell autoreconf not to invoke autopoint or libtoolize; they were run above. -echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS" -AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \ - || die "autoreconf failed" - -# Get some extra files from gnulib, overriding existing files. -for file in $gnulib_extra_files; do - case $file in - */INSTALL) dst=INSTALL;; - build-aux/*) dst=$build_aux/${file#build-aux/};; - *) dst=$file;; - esac - symlink_to_dir "$GNULIB_SRCDIR" $file $dst \ - || die "failed to symlink $file" -done - -if test $with_gettext = yes; then - # Create gettext configuration. - echo "$0: Creating po/Makevars from po/Makevars.template ..." - rm -f po/Makevars - sed ' - /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/ - /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/ - /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'| - /^XGETTEXT_OPTIONS *=/{ - s/$/ \\/ - a\ - '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+} - } - ' po/Makevars.template >po/Makevars \ - || die 'cannot generate po/Makevars' - - # If the 'gettext' module is in use, grab the latest Makefile.in.in. - # If only the 'gettext-h' module is in use, assume autopoint already - # put the correct version of this file into place. - case $gnulib_modules in - *gettext-h*) ;; - *gettext*) - cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \ - || die "cannot create po/Makefile.in.in" - ;; - esac - - if test -d runtime-po; then - # Similarly for runtime-po/Makevars, but not quite the same. - rm -f runtime-po/Makevars - sed ' - /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/ - /^subdir *=.*/s/=.*/= runtime-po/ - /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/ - /^XGETTEXT_OPTIONS *=/{ - s/$/ \\/ - a\ - '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+} - } - ' po/Makevars.template >runtime-po/Makevars \ - || die 'cannot generate runtime-po/Makevars' - - # Copy identical files from po to runtime-po. - (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po) - fi -fi - -bootstrap_epilogue - -echo "$0: done. Now you can run './configure'." - -# Local variables: -# eval: (add-hook 'before-save-hook 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC0" -# time-stamp-end: "; # UTC" -# End: diff --git a/bootstrap.conf b/bootstrap.conf deleted file mode 100644 index 6d383240e..000000000 --- a/bootstrap.conf +++ /dev/null @@ -1,100 +0,0 @@ -# Bootstrap configuration. - -# Copyright (C) 2006-2019 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 - -# gnulib modules used by this package. -# mbswidth is used by gnulib-fix-width.diff's changes to argp rather than -# directly. -gnulib_modules=" - argp - base64 - error - fnmatch - getdelim - getline - gettext-h - gitlog-to-changelog - mbswidth - progname - realloc-gnu - regex - save-cwd -" - -gnulib_tool_option_extras="\ - --no-conditional-dependencies \ - --no-vc-files \ -" - -gnulib_name=libgnu -source_base=grub-core/lib/gnulib -gnulib_extra_files=" - build-aux/install-sh - build-aux/mdate-sh - build-aux/texinfo.tex - build-aux/depcomp - build-aux/config.guess - build-aux/config.sub -" - -# Additional xgettext options to use. Use "\\\newline" to break lines. -XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ - --from-code=UTF-8\\\ -' - -checkout_only_file= -copy=true -vc_ignore= - -SKIP_PO=t - -# Build prerequisites -buildreq="\ -autoconf 2.63 -automake 1.11 -gettext 0.18.3 -git 1.5.5 -tar - -" - -# bootstrap doesn't give us a reasonable way to stop Automake from -# overwriting this, so we just copy our version aside and put it back later. -cp -a INSTALL INSTALL.grub - -bootstrap_post_import_hook () { - set -e - for patchname in fix-base64 fix-null-deref fix-width no-abort; do - patch -d grub-core/lib/gnulib -p2 \ - < "grub-core/lib/gnulib-patches/$patchname.patch" - done - for patchname in \ - 0001-Support-POTFILES-shell \ - 0002-Handle-gettext_printf-shell-function \ - 0003-Make-msgfmt-output-in-little-endian \ - 0004-Use-SHELL-rather-than-bin-sh; do - patch -d po -p3 \ - < "po/gettext-patches/$patchname.patch" - done - FROM_BOOTSTRAP=1 ./autogen.sh - set +e # bootstrap expects this -} - -bootstrap_epilogue () { - mv INSTALL.grub INSTALL -} diff --git a/build-aux/config.rpath b/build-aux/config.rpath new file mode 100755 index 000000000..c38b914d6 --- /dev/null +++ b/build-aux/config.rpath @@ -0,0 +1,690 @@ +#! /bin/sh +# Output a system dependent set of variables, describing how to set the +# run time search path of shared libraries in an executable. +# +# Copyright 1996-2013 Free Software Foundation, Inc. +# Taken from GNU libtool, 2001 +# Originally by Gordon Matzigkeit , 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# The first argument passed to this file is the canonical host specification, +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld +# should be set by the caller. +# +# The set of defined variables is at the end of this script. + +# Known limitations: +# - On IRIX 6.5 with CC="cc", the run time search patch must not be longer +# than 256 bytes, otherwise the compiler driver will dump core. The only +# known workaround is to choose shorter directory names for the build +# directory and/or the installation directory. + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a +shrext=.so + +host="$1" +host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` + +# Code taken from libtool.m4's _LT_CC_BASENAME. + +for cc_temp in $CC""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` + +# Code taken from libtool.m4's _LT_COMPILER_PIC. + +wl= +if test "$GCC" = yes; then + wl='-Wl,' +else + case "$host_os" in + aix*) + wl='-Wl,' + ;; + mingw* | cygwin* | pw32* | os2* | cegcc*) + ;; + hpux9* | hpux10* | hpux11*) + wl='-Wl,' + ;; + irix5* | irix6* | nonstopux*) + wl='-Wl,' + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu) + case $cc_basename in + ecc*) + wl='-Wl,' + ;; + icc* | ifort*) + wl='-Wl,' + ;; + lf95*) + wl='-Wl,' + ;; + nagfor*) + wl='-Wl,-Wl,,' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + wl='-Wl,' + ;; + ccc*) + wl='-Wl,' + ;; + xl* | bgxl* | bgf* | mpixl*) + wl='-Wl,' + ;; + como) + wl='-lopt=' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ F* | *Sun*Fortran*) + wl= + ;; + *Sun\ C*) + wl='-Wl,' + ;; + esac + ;; + esac + ;; + newsos6) + ;; + *nto* | *qnx*) + ;; + osf3* | osf4* | osf5*) + wl='-Wl,' + ;; + rdos*) + ;; + solaris*) + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + wl='-Qoption ld ' + ;; + *) + wl='-Wl,' + ;; + esac + ;; + sunos4*) + wl='-Qoption ld ' + ;; + sysv4 | sysv4.2uw2* | sysv4.3*) + wl='-Wl,' + ;; + sysv4*MP*) + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + wl='-Wl,' + ;; + unicos*) + wl='-Wl,' + ;; + uts4*) + ;; + esac +fi + +# Code taken from libtool.m4's _LT_LINKER_SHLIBS. + +hardcode_libdir_flag_spec= +hardcode_libdir_separator= +hardcode_direct=no +hardcode_minus_L=no + +case "$host_os" in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd*) + with_gnu_ld=no + ;; +esac + +ld_shlibs=yes +if test "$with_gnu_ld" = yes; then + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + # Unlike libtool, we use -rpath here, not --rpath, since the documented + # option of GNU ld is called -rpath, not --rpath. + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + case "$host_os" in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + ld_shlibs=no + fi + ;; + amigaos*) + case "$host_cpu" in + powerpc) + ;; + m68k) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + cygwin* | mingw* | pw32* | cegcc*) + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + haiku*) + ;; + interix[3-9]*) + hardcode_direct=no + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + netbsd*) + ;; + solaris*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' + else + ld_shlibs=no + fi + ;; + esac + ;; + sunos4*) + hardcode_direct=yes + ;; + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + : + else + ld_shlibs=no + fi + ;; + esac + if test "$ld_shlibs" = no; then + hardcode_libdir_flag_spec= + fi +else + case "$host_os" in + aix3*) + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test "$GCC" = yes; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + aix[4-9]*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + else + aix_use_runtimelinking=no + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + ;; + esac + fi + hardcode_direct=yes + hardcode_libdir_separator=':' + if test "$GCC" = yes; then + case $host_os in aix4.[012]|aix4.[012].*) + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + fi + # Begin _LT_AC_SYS_LIBPATH_AIX. + echo 'int main () { return 0; }' > conftest.c + ${CC} ${LDFLAGS} conftest.c -o conftest + aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` + if test -z "$aix_libpath"; then + aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` + fi + if test -z "$aix_libpath"; then + aix_libpath="/usr/lib:/lib" + fi + rm -f conftest.c conftest + # End _LT_AC_SYS_LIBPATH_AIX. + if test "$aix_use_runtimelinking" = yes; then + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + else + if test "$host_cpu" = ia64; then + hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' + else + hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" + fi + fi + ;; + amigaos*) + case "$host_cpu" in + powerpc) + ;; + m68k) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + bsdi[45]*) + ;; + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + hardcode_libdir_flag_spec=' ' + libext=lib + ;; + darwin* | rhapsody*) + hardcode_direct=no + if { case $cc_basename in ifort*) true;; *) test "$GCC" = yes;; esac; }; then + : + else + ld_shlibs=no + fi + ;; + dgux*) + hardcode_libdir_flag_spec='-L$libdir' + ;; + freebsd2.2*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + freebsd2*) + hardcode_direct=yes + hardcode_minus_L=yes + ;; + freebsd* | dragonfly*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + hpux9*) + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + hpux10*) + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + hpux11*) + if test "$with_gnu_ld" = no; then + hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' + hardcode_libdir_separator=: + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + ;; + *) + hardcode_direct=yes + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + irix5* | irix6* | nonstopux*) + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + netbsd*) + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + ;; + newsos6) + hardcode_direct=yes + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + *nto* | *qnx*) + ;; + openbsd*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + else + case "$host_os" in + openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) + hardcode_libdir_flag_spec='-R$libdir' + ;; + *) + hardcode_libdir_flag_spec='${wl}-rpath,$libdir' + ;; + esac + fi + else + ld_shlibs=no + fi + ;; + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + osf3*) + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + hardcode_libdir_separator=: + ;; + osf4* | osf5*) + if test "$GCC" = yes; then + hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' + else + # Both cc and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + hardcode_libdir_separator=: + ;; + solaris*) + hardcode_libdir_flag_spec='-R$libdir' + ;; + sunos4*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + ;; + sysv4) + case $host_vendor in + sni) + hardcode_direct=yes # is this really true??? + ;; + siemens) + hardcode_direct=no + ;; + motorola) + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + ;; + sysv4.3*) + ;; + sysv4*MP*) + if test -d /usr/nec; then + ld_shlibs=yes + fi + ;; + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + ;; + sysv5* | sco3.2v5* | sco5v6*) + hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' + hardcode_libdir_separator=':' + ;; + uts4*) + hardcode_libdir_flag_spec='-L$libdir' + ;; + *) + ld_shlibs=no + ;; + esac +fi + +# Check dynamic linker characteristics +# Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER. +# Unlike libtool.m4, here we don't care about _all_ names of the library, but +# only about the one the linker finds when passed -lNAME. This is the last +# element of library_names_spec in libtool.m4, or possibly two of them if the +# linker has special search rules. +library_names_spec= # the last element of library_names_spec in libtool.m4 +libname_spec='lib$name' +case "$host_os" in + aix3*) + library_names_spec='$libname.a' + ;; + aix[4-9]*) + library_names_spec='$libname$shrext' + ;; + amigaos*) + case "$host_cpu" in + powerpc*) + library_names_spec='$libname$shrext' ;; + m68k) + library_names_spec='$libname.a' ;; + esac + ;; + beos*) + library_names_spec='$libname$shrext' + ;; + bsdi[45]*) + library_names_spec='$libname$shrext' + ;; + cygwin* | mingw* | pw32* | cegcc*) + shrext=.dll + library_names_spec='$libname.dll.a $libname.lib' + ;; + darwin* | rhapsody*) + shrext=.dylib + library_names_spec='$libname$shrext' + ;; + dgux*) + library_names_spec='$libname$shrext' + ;; + freebsd* | dragonfly*) + case "$host_os" in + freebsd[123]*) + library_names_spec='$libname$shrext$versuffix' ;; + *) + library_names_spec='$libname$shrext' ;; + esac + ;; + gnu*) + library_names_spec='$libname$shrext' + ;; + haiku*) + library_names_spec='$libname$shrext' + ;; + hpux9* | hpux10* | hpux11*) + case $host_cpu in + ia64*) + shrext=.so + ;; + hppa*64*) + shrext=.sl + ;; + *) + shrext=.sl + ;; + esac + library_names_spec='$libname$shrext' + ;; + interix[3-9]*) + library_names_spec='$libname$shrext' + ;; + irix5* | irix6* | nonstopux*) + library_names_spec='$libname$shrext' + case "$host_os" in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;; + *) libsuff= shlibsuff= ;; + esac + ;; + esac + ;; + linux*oldld* | linux*aout* | linux*coff*) + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu) + library_names_spec='$libname$shrext' + ;; + knetbsd*-gnu) + library_names_spec='$libname$shrext' + ;; + netbsd*) + library_names_spec='$libname$shrext' + ;; + newsos6) + library_names_spec='$libname$shrext' + ;; + *nto* | *qnx*) + library_names_spec='$libname$shrext' + ;; + openbsd*) + library_names_spec='$libname$shrext$versuffix' + ;; + os2*) + libname_spec='$name' + shrext=.dll + library_names_spec='$libname.a' + ;; + osf3* | osf4* | osf5*) + library_names_spec='$libname$shrext' + ;; + rdos*) + ;; + solaris*) + library_names_spec='$libname$shrext' + ;; + sunos4*) + library_names_spec='$libname$shrext$versuffix' + ;; + sysv4 | sysv4.3*) + library_names_spec='$libname$shrext' + ;; + sysv4*MP*) + library_names_spec='$libname$shrext' + ;; + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + library_names_spec='$libname$shrext' + ;; + tpf*) + library_names_spec='$libname$shrext' + ;; + uts4*) + library_names_spec='$libname$shrext' + ;; +esac + +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' +escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` +shlibext=`echo "$shrext" | sed -e 's,^\.,,'` +escaped_libname_spec=`echo "X$libname_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` +escaped_library_names_spec=`echo "X$library_names_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` +escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` + +LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <. */ + +/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools + that the values passed as arguments n, ..., m must be non-NULL pointers. + n = 1 stands for the first argument, n = 2 for the second argument etc. */ +#ifndef _GL_ARG_NONNULL +# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 +# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) +# else +# define _GL_ARG_NONNULL(params) +# endif +#endif diff --git a/build-aux/snippet/c++defs.h b/build-aux/snippet/c++defs.h new file mode 100644 index 000000000..b35b933cd --- /dev/null +++ b/build-aux/snippet/c++defs.h @@ -0,0 +1,271 @@ +/* C++ compatible function declaration macros. + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GL_CXXDEFS_H +#define _GL_CXXDEFS_H + +/* The three most frequent use cases of these macros are: + + * For providing a substitute for a function that is missing on some + platforms, but is declared and works fine on the platforms on which + it exists: + + #if @GNULIB_FOO@ + # if !@HAVE_FOO@ + _GL_FUNCDECL_SYS (foo, ...); + # endif + _GL_CXXALIAS_SYS (foo, ...); + _GL_CXXALIASWARN (foo); + #elif defined GNULIB_POSIXCHECK + ... + #endif + + * For providing a replacement for a function that exists on all platforms, + but is broken/insufficient and needs to be replaced on some platforms: + + #if @GNULIB_FOO@ + # if @REPLACE_FOO@ + # if !(defined __cplusplus && defined GNULIB_NAMESPACE) + # undef foo + # define foo rpl_foo + # endif + _GL_FUNCDECL_RPL (foo, ...); + _GL_CXXALIAS_RPL (foo, ...); + # else + _GL_CXXALIAS_SYS (foo, ...); + # endif + _GL_CXXALIASWARN (foo); + #elif defined GNULIB_POSIXCHECK + ... + #endif + + * For providing a replacement for a function that exists on some platforms + but is broken/insufficient and needs to be replaced on some of them and + is additionally either missing or undeclared on some other platforms: + + #if @GNULIB_FOO@ + # if @REPLACE_FOO@ + # if !(defined __cplusplus && defined GNULIB_NAMESPACE) + # undef foo + # define foo rpl_foo + # endif + _GL_FUNCDECL_RPL (foo, ...); + _GL_CXXALIAS_RPL (foo, ...); + # else + # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@ + _GL_FUNCDECL_SYS (foo, ...); + # endif + _GL_CXXALIAS_SYS (foo, ...); + # endif + _GL_CXXALIASWARN (foo); + #elif defined GNULIB_POSIXCHECK + ... + #endif +*/ + +/* _GL_EXTERN_C declaration; + performs the declaration with C linkage. */ +#if defined __cplusplus +# define _GL_EXTERN_C extern "C" +#else +# define _GL_EXTERN_C extern +#endif + +/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); + declares a replacement function, named rpl_func, with the given prototype, + consisting of return type, parameters, and attributes. + Example: + _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) + _GL_ARG_NONNULL ((1))); + */ +#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ + _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) +#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ + _GL_EXTERN_C rettype rpl_func parameters_and_attributes + +/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); + declares the system function, named func, with the given prototype, + consisting of return type, parameters, and attributes. + Example: + _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) + _GL_ARG_NONNULL ((1))); + */ +#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ + _GL_EXTERN_C rettype func parameters_and_attributes + +/* _GL_CXXALIAS_RPL (func, rettype, parameters); + declares a C++ alias called GNULIB_NAMESPACE::func + that redirects to rpl_func, if GNULIB_NAMESPACE is defined. + Example: + _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); + */ +#define _GL_CXXALIAS_RPL(func,rettype,parameters) \ + _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) +#if defined __cplusplus && defined GNULIB_NAMESPACE +# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ + namespace GNULIB_NAMESPACE \ + { \ + rettype (*const func) parameters = ::rpl_func; \ + } \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#else +# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters); + is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters); + except that the C function rpl_func may have a slightly different + declaration. A cast is used to silence the "invalid conversion" error + that would otherwise occur. */ +#if defined __cplusplus && defined GNULIB_NAMESPACE +# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ + namespace GNULIB_NAMESPACE \ + { \ + rettype (*const func) parameters = \ + reinterpret_cast(::rpl_func); \ + } \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#else +# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIAS_SYS (func, rettype, parameters); + declares a C++ alias called GNULIB_NAMESPACE::func + that redirects to the system provided function func, if GNULIB_NAMESPACE + is defined. + Example: + _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); + */ +#if defined __cplusplus && defined GNULIB_NAMESPACE + /* If we were to write + rettype (*const func) parameters = ::func; + like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls + better (remove an indirection through a 'static' pointer variable), + but then the _GL_CXXALIASWARN macro below would cause a warning not only + for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */ +# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ + namespace GNULIB_NAMESPACE \ + { \ + static rettype (*func) parameters = ::func; \ + } \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#else +# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters); + is like _GL_CXXALIAS_SYS (func, rettype, parameters); + except that the C function func may have a slightly different declaration. + A cast is used to silence the "invalid conversion" error that would + otherwise occur. */ +#if defined __cplusplus && defined GNULIB_NAMESPACE +# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ + namespace GNULIB_NAMESPACE \ + { \ + static rettype (*func) parameters = \ + reinterpret_cast(::func); \ + } \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#else +# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2); + is like _GL_CXXALIAS_SYS (func, rettype, parameters); + except that the C function is picked among a set of overloaded functions, + namely the one with rettype2 and parameters2. Two consecutive casts + are used to silence the "cannot find a match" and "invalid conversion" + errors that would otherwise occur. */ +#if defined __cplusplus && defined GNULIB_NAMESPACE + /* The outer cast must be a reinterpret_cast. + The inner cast: When the function is defined as a set of overloaded + functions, it works as a static_cast<>, choosing the designated variant. + When the function is defined as a single variant, it works as a + reinterpret_cast<>. The parenthesized cast syntax works both ways. */ +# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ + namespace GNULIB_NAMESPACE \ + { \ + static rettype (*func) parameters = \ + reinterpret_cast( \ + (rettype2(*)parameters2)(::func)); \ + } \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#else +# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIASWARN (func); + causes a warning to be emitted when ::func is used but not when + GNULIB_NAMESPACE::func is used. func must be defined without overloaded + variants. */ +#if defined __cplusplus && defined GNULIB_NAMESPACE +# define _GL_CXXALIASWARN(func) \ + _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) +# define _GL_CXXALIASWARN_1(func,namespace) \ + _GL_CXXALIASWARN_2 (func, namespace) +/* To work around GCC bug , + we enable the warning only when not optimizing. */ +# if !__OPTIMIZE__ +# define _GL_CXXALIASWARN_2(func,namespace) \ + _GL_WARN_ON_USE (func, \ + "The symbol ::" #func " refers to the system function. " \ + "Use " #namespace "::" #func " instead.") +# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING +# define _GL_CXXALIASWARN_2(func,namespace) \ + extern __typeof__ (func) func +# else +# define _GL_CXXALIASWARN_2(func,namespace) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +# endif +#else +# define _GL_CXXALIASWARN(func) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes); + causes a warning to be emitted when the given overloaded variant of ::func + is used but not when GNULIB_NAMESPACE::func is used. */ +#if defined __cplusplus && defined GNULIB_NAMESPACE +# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ + _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \ + GNULIB_NAMESPACE) +# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ + _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) +/* To work around GCC bug , + we enable the warning only when not optimizing. */ +# if !__OPTIMIZE__ +# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ + _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ + "The symbol ::" #func " refers to the system function. " \ + "Use " #namespace "::" #func " instead.") +# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING +# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ + extern __typeof__ (func) func +# else +# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +# endif +#else +# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ + _GL_EXTERN_C int _gl_cxxalias_dummy +#endif + +#endif /* _GL_CXXDEFS_H */ diff --git a/build-aux/snippet/warn-on-use.h b/build-aux/snippet/warn-on-use.h new file mode 100644 index 000000000..1736a1bd7 --- /dev/null +++ b/build-aux/snippet/warn-on-use.h @@ -0,0 +1,109 @@ +/* A C macro for emitting warnings if a function is used. + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* _GL_WARN_ON_USE (function, "literal string") issues a declaration + for FUNCTION which will then trigger a compiler warning containing + the text of "literal string" anywhere that function is called, if + supported by the compiler. If the compiler does not support this + feature, the macro expands to an unused extern declaration. + + This macro is useful for marking a function as a potential + portability trap, with the intent that "literal string" include + instructions on the replacement function that should be used + instead. However, one of the reasons that a function is a + portability trap is if it has the wrong signature. Declaring + FUNCTION with a different signature in C is a compilation error, so + this macro must use the same type as any existing declaration so + that programs that avoid the problematic FUNCTION do not fail to + compile merely because they included a header that poisoned the + function. But this implies that _GL_WARN_ON_USE is only safe to + use if FUNCTION is known to already have a declaration. Use of + this macro implies that there must not be any other macro hiding + the declaration of FUNCTION; but undefining FUNCTION first is part + of the poisoning process anyway (although for symbols that are + provided only via a macro, the result is a compilation error rather + than a warning containing "literal string"). Also note that in + C++, it is only safe to use if FUNCTION has no overloads. + + For an example, it is possible to poison 'getline' by: + - adding a call to gl_WARN_ON_USE_PREPARE([[#include ]], + [getline]) in configure.ac, which potentially defines + HAVE_RAW_DECL_GETLINE + - adding this code to a header that wraps the system : + #undef getline + #if HAVE_RAW_DECL_GETLINE + _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but" + "not universally present; use the gnulib module getline"); + #endif + + It is not possible to directly poison global variables. But it is + possible to write a wrapper accessor function, and poison that + (less common usage, like &environ, will cause a compilation error + rather than issue the nice warning, but the end result of informing + the developer about their portability problem is still achieved): + #if HAVE_RAW_DECL_ENVIRON + static char ***rpl_environ (void) { return &environ; } + _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared"); + # undef environ + # define environ (*rpl_environ ()) + #endif + */ +#ifndef _GL_WARN_ON_USE + +# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) +/* A compiler attribute is available in gcc versions 4.3.0 and later. */ +# define _GL_WARN_ON_USE(function, message) \ +extern __typeof__ (function) function __attribute__ ((__warning__ (message))) +# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING +/* Verify the existence of the function. */ +# define _GL_WARN_ON_USE(function, message) \ +extern __typeof__ (function) function +# else /* Unsupported. */ +# define _GL_WARN_ON_USE(function, message) \ +_GL_WARN_EXTERN_C int _gl_warn_on_use +# endif +#endif + +/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string") + is like _GL_WARN_ON_USE (function, "string"), except that the function is + declared with the given prototype, consisting of return type, parameters, + and attributes. + This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does + not work in this case. */ +#ifndef _GL_WARN_ON_USE_CXX +# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) +# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ +extern rettype function parameters_and_attributes \ + __attribute__ ((__warning__ (msg))) +# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING +/* Verify the existence of the function. */ +# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ +extern rettype function parameters_and_attributes +# else /* Unsupported. */ +# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ +_GL_WARN_EXTERN_C int _gl_warn_on_use +# endif +#endif + +/* _GL_WARN_EXTERN_C declaration; + performs the declaration with C linkage. */ +#ifndef _GL_WARN_EXTERN_C +# if defined __cplusplus +# define _GL_WARN_EXTERN_C extern "C" +# else +# define _GL_WARN_EXTERN_C extern +# endif +#endif diff --git a/conf/Makefile.common b/conf/Makefile.common index 6cd71cbb2..51fbaf99d 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -7,7 +7,12 @@ unexport LC_ALL # Platform specific options if COND_sparc64_ieee1275 - LDFLAGS_PLATFORM = -Wl,-melf64_sparc + CFLAGS_PLATFORM += -mno-app-regs + LDFLAGS_PLATFORM = -Wl,-melf64_sparc -mno-relax +endif +if COND_sparc64_emu + CFLAGS_PLATFORM += -mno-app-regs + LDFLAGS_PLATFORM = -Wl,--no-relax endif if COND_arm if !COND_emu @@ -17,9 +22,9 @@ endif if COND_arm64 CFLAGS_PLATFORM += -mcmodel=large endif -if COND_powerpc_ieee1275 - CFLAGS_PLATFORM += -mcpu=powerpc -endif + +#FIXME: discover and check XEN headers +CPPFLAGS_XEN = -I/usr/include # Other options @@ -34,19 +39,21 @@ CPPFLAGS_DEFAULT += -I$(top_srcdir)/grub-core/lib/libgcrypt-grub/src/ CCASFLAGS_DEFAULT = $(CPPFLAGS_DEFAULT) -DASM_FILE=1 BUILD_CPPFLAGS += $(CPPFLAGS_DEFAULT) -CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding -LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) +LDADD_KERNEL = $(TARGET_LIBGCC) + +CFLAGS_KERNEL = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding +LDFLAGS_KERNEL = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) $(TARGET_LDFLAGS_STATIC_LIBGCC) CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) -STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx +STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding -LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +CFLAGS_MODULE = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding +LDFLAGS_MODULE = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) -CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin -LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S +CFLAGS_IMAGE = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -fno-builtin +LDFLAGS_IMAGE = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) @@ -66,7 +73,7 @@ platformdir = $(pkglibdir)/$(target_cpu)-$(platform) starfielddir = $(pkgdatadir)/themes/starfield CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion -CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib +CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/gnulib -I$(top_srcdir)/grub-core/gnulib CFLAGS_POSIX = -fno-builtin CPPFLAGS_POSIX = -I$(top_srcdir)/grub-core/lib/posix_wrap @@ -86,11 +93,9 @@ CPPFLAGS_TERMINAL_LIST += '-Dgrub_term_register_output(...)=OUTPUT_TERMINAL_LIST CPPFLAGS_COMMAND_LIST = '-Dgrub_register_command(...)=COMMAND_LIST_MARKER(__VA_ARGS__)' CPPFLAGS_COMMAND_LIST += '-Dgrub_register_extcmd(...)=EXTCOMMAND_LIST_MARKER(__VA_ARGS__)' CPPFLAGS_COMMAND_LIST += '-Dgrub_register_command_p1(...)=P1COMMAND_LIST_MARKER(__VA_ARGS__)' -CPPFLAGS_FDT_LIST := '-Dgrub_fdtbus_register(...)=FDT_DRIVER_LIST_MARKER(__VA_ARGS__)' CPPFLAGS_MARKER = $(CPPFLAGS_FS_LIST) $(CPPFLAGS_VIDEO_LIST) \ $(CPPFLAGS_PARTTOOL_LIST) $(CPPFLAGS_PARTMAP_LIST) \ - $(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST) \ - $(CPPFLAGS_FDT_LIST) + $(CPPFLAGS_TERMINAL_LIST) $(CPPFLAGS_COMMAND_LIST) # Define these variables to calm down automake @@ -128,11 +133,11 @@ BUILT_SOURCES = .PRECIOUS: $(top_srcdir)/Makefile.util.am $(top_srcdir)/Makefile.util.am: $(top_srcdir)/gentpl.py $(top_srcdir)/Makefile.util.def $(top_srcdir)/Makefile.utilgcry.def - $(PYTHON) $^ > $@.new || (rm -f $@.new; exit 1) + python $^ > $@.new || (rm -f $@.new; exit 1) mv $@.new $@ .PRECIOUS: $(top_srcdir)/grub-core/Makefile.core.am $(top_srcdir)/grub-core/Makefile.core.am: $(top_srcdir)/gentpl.py $(top_srcdir)/grub-core/Makefile.core.def $(top_srcdir)/grub-core/Makefile.gcry.def - if [ "x$$GRUB_CONTRIB" != x ]; then echo "You need to run ./bootstrap manually." >&2; exit 1; fi - $(PYTHON) $^ > $@.new || (rm -f $@.new; exit 1) + if [ "x$$GRUB_CONTRIB" != x ]; then echo "You need to run ./autogen.sh manually." >&2; exit 1; fi + python $^ > $@.new || (rm -f $@.new; exit 1) mv $@.new $@ diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist index 37dc3aa10..1b95ccd3f 100644 --- a/conf/Makefile.extra-dist +++ b/conf/Makefile.extra-dist @@ -5,7 +5,6 @@ EXTRA_DIST += gentpl.py EXTRA_DIST += Makefile.util.def EXTRA_DIST += Makefile.utilgcry.def -EXTRA_DIST += asm-tests EXTRA_DIST += unicode EXTRA_DIST += util/import_gcry.py @@ -28,15 +27,16 @@ EXTRA_DIST += grub-core/gensymlist.sh EXTRA_DIST += grub-core/genemuinit.sh EXTRA_DIST += grub-core/genemuinitheader.sh -EXTRA_DIST += grub-core/lib/gnulib-patches/fix-base64.patch -EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-deref.patch -EXTRA_DIST += grub-core/lib/gnulib-patches/fix-width.patch -EXTRA_DIST += grub-core/lib/gnulib-patches/no-abort.patch +EXTRA_DIST += grub-core/gnulib-fix-null-deref.diff +EXTRA_DIST += grub-core/gnulib-fix-width.diff +EXTRA_DIST += grub-core/gnulib-no-abort.diff +EXTRA_DIST += grub-core/gnulib-no-gets.diff EXTRA_DIST += grub-core/lib/libgcrypt EXTRA_DIST += grub-core/lib/libgcrypt-grub/mpi/generic EXTRA_DIST += $(shell find $(top_srcdir)/include -name '*.h') EXTRA_DIST += $(shell find $(top_srcdir)/grub-core/lib -name '*.h') +EXTRA_DIST += $(shell find $(top_srcdir)/grub-core/gnulib -name '*.h') EXTRA_DIST += grub-core/efiemu/runtime/config.h EXTRA_DIST += grub-core/lib/LzmaDec.c @@ -50,13 +50,8 @@ EXTRA_DIST += util/import_gcrypth.sed EXTRA_DIST += util/bin2h.c EXTRA_DIST += util/grub-gen-asciih.c EXTRA_DIST += util/grub-gen-widthspec.c -EXTRA_DIST += util/grub-module-verifier.c -EXTRA_DIST += util/grub-module-verifier32.c -EXTRA_DIST += util/grub-module-verifier64.c -EXTRA_DIST += util/grub-module-verifierXX.c EXTRA_DIST += util/grub-pe2elf.c - EXTRA_DIST += m4/gnulib-cache.m4 EXTRA_DIST += m4/glibc2.m4 EXTRA_DIST += m4/gnulib-tool.m4 @@ -111,21 +106,6 @@ EXTRA_DIST += grub-core/osdep/windows/password.c EXTRA_DIST += grub-core/osdep/windows/random.c EXTRA_DIST += grub-core/osdep/windows/sleep.c -EXTRA_DIST += po/gettext-patches/0001-Support-POTFILES-shell.patch -EXTRA_DIST += po/gettext-patches/0002-Handle-gettext_printf-shell-function.patch -EXTRA_DIST += po/gettext-patches/0003-Make-msgfmt-output-in-little-endian.patch -EXTRA_DIST += po/gettext-patches/0004-Use-SHELL-rather-than-bin-sh.patch - -EXTRA_DIST += po/POTFILES-shell.in -EXTRA_DIST += po/README -EXTRA_DIST += po/Rules-translit -EXTRA_DIST += po/Rules-windowsdir -EXTRA_DIST += po/arabic.sed -EXTRA_DIST += po/cyrillic.sed -EXTRA_DIST += po/greek.sed -EXTRA_DIST += po/grub.d.sed -EXTRA_DIST += po/hebrew.sed - EXTRA_DIST += tests/dfly-mbr-mbexample.mbr.img.gz EXTRA_DIST += tests/dfly-mbr-mbexample.dfly.img.gz @@ -141,15 +121,3 @@ EXTRA_DIST += tests/file_filter/file.xz.sig EXTRA_DIST += tests/file_filter/keys EXTRA_DIST += tests/file_filter/keys.pub EXTRA_DIST += tests/file_filter/test.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/prompt.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/txt.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/menu.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/po4a.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg -EXTRA_DIST += tests/syslinux/ubuntu10.04_grub.cfg.in diff --git a/config.h.in b/config.h.in index 9e8f9911b..4b6301441 100644 --- a/config.h.in +++ b/config.h.in @@ -7,20 +7,11 @@ #endif #define GCRYPT_NO_DEPRECATED 1 -#define HAVE_MEMMOVE 1 /* Define to 1 to enable disk cache statistics. */ #define DISK_CACHE_STATS @DISK_CACHE_STATS@ #define BOOT_TIME_STATS @BOOT_TIME_STATS@ -/* We don't need those. */ -#define MINILZO_CFG_SKIP_LZO_PTR 1 -#define MINILZO_CFG_SKIP_LZO_UTIL 1 -#define MINILZO_CFG_SKIP_LZO_STRING 1 -#define MINILZO_CFG_SKIP_LZO_INIT 1 -#define MINILZO_CFG_SKIP_LZO1X_1_COMPRESS 1 -#define MINILZO_CFG_SKIP_LZO1X_DECOMPRESS 1 - #if defined (GRUB_BUILD) #undef ENABLE_NLS #define BUILD_SIZEOF_LONG @BUILD_SIZEOF_LONG@ @@ -40,6 +31,10 @@ #define HAVE_FONT_SOURCE @HAVE_FONT_SOURCE@ /* Define if C symbols get an underscore after compilation. */ #define HAVE_ASM_USCORE @HAVE_ASM_USCORE@ +/* Define it to \"addr32\" or \"addr32;\" to make GAS happy. */ +#define ADDR32 @ADDR32@ +/* Define it to \"data32\" or \"data32;\" to make GAS happy. */ +#define DATA32 @DATA32@ /* Define it to one of __bss_start, edata and _edata. */ #define BSS_START_SYMBOL @BSS_START_SYMBOL@ /* Define it to either end or _end. */ diff --git a/configure.ac b/configure.ac index 7c10a4db7..fdddbaddc 100644 --- a/configure.ac +++ b/configure.ac @@ -26,15 +26,12 @@ dnl This is necessary because the target type in autoconf does not dnl describe such a system very well. dnl dnl The current strategy is to use variables with no prefix (such as -dnl CC, CFLAGS, etc.) for the host and target type, variables with -dnl prefix "BUILD_" (such as BUILD_CC, BUILD_CFLAGS, etc.) for the -dnl build type, variables with prefix "HOST_" (such as HOST_CC, -dnl HOST_CFLAGS, etc.) for the host type and variables with the prefix -dnl "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for -dnl the target type. See INSTALL for full list of variables and -dnl description of the relationships between them. +dnl CC, CFLAGS, etc.) for the host type, variables with prefix "BUILD_" +dnl (such as BUILD_CC, BUILD_CFLAGS, etc.) for the build type and variables +dnl with the prefix "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are +dnl used for the target type. See INSTALL for full list of variables. -AC_INIT([GRUB],[2.05],[bug-grub@gnu.org]) +AC_INIT([GRUB],[2.02~beta2],[bug-grub@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) @@ -48,15 +45,11 @@ save_program_prefix="${program_prefix}" AC_CANONICAL_TARGET program_prefix="${save_program_prefix}" -AM_INIT_AUTOMAKE([1.11]) -AC_PREREQ(2.63) +AM_INIT_AUTOMAKE([1.10.1]) +AC_PREREQ(2.60) AC_CONFIG_SRCDIR([include/grub/dl.h]) AC_CONFIG_HEADER([config-util.h]) -# Explicitly check for pkg-config early on, since otherwise conditional -# calls are problematic. -PKG_PROG_PKG_CONFIG - # Program name transformations AC_ARG_PROGRAM grub_TRANSFORM([grub-bios-setup]) @@ -80,20 +73,17 @@ grub_TRANSFORM([grub-file]) # Optimization flag. Allow user to override. if test "x$TARGET_CFLAGS" = x; then - TARGET_CFLAGS=-Os + TARGET_CFLAGS="$TARGET_CFLAGS -Os" fi -# Enable support for "restrict" keyword and other -# features from gnu99 C language standard. -BUILD_CFLAGS="-std=gnu99 $BUILD_CFLAGS" -HOST_CFLAGS="-std=gnu99 $HOST_CFLAGS" -TARGET_CFLAGS="-std=gnu99 $TARGET_CFLAGS" - # Default HOST_CPPFLAGS HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W" +HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W" +TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" +TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" case "$target_cpu" in i[[3456]]86) target_cpu=i386 ;; @@ -113,12 +103,6 @@ case "$target_cpu" in aarch64*) target_cpu=arm64 ;; - riscv32*) - target_cpu=riscv32 - ;; - riscv64*) - target_cpu=riscv64 - ;; esac # Specify the platform (such as firmware). @@ -135,15 +119,12 @@ if test "x$with_platform" = x; then x86_64-*) platform=pc ;; powerpc-*) platform=ieee1275 ;; powerpc64-*) platform=ieee1275 ;; - powerpc64le-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;; mipsel-*) platform=loongson ;; mips-*) platform=arc ;; ia64-*) platform=efi ;; arm-*) platform=uboot ;; arm64-*) platform=efi ;; - riscv32-*) platform=efi ;; - riscv64-*) platform=efi ;; *) AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities]) platform=none @@ -160,7 +141,6 @@ case "$target_cpu"-"$platform" in x86_64-none) ;; x86_64-*) target_cpu=i386 ;; powerpc64-ieee1275) target_cpu=powerpc ;; - powerpc64le-ieee1275) target_cpu=powerpc ;; esac # Check if the platform is supported, make final adjustments. @@ -168,7 +148,6 @@ case "$target_cpu"-"$platform" in i386-efi) ;; x86_64-efi) ;; i386-xen) ;; - i386-xen_pvh) ;; x86_64-xen) ;; i386-pc) ;; i386-multiboot) ;; @@ -189,11 +168,8 @@ case "$target_cpu"-"$platform" in mipsel-fuloong) platform=loongson ;; mipsel-loongson) ;; arm-uboot) ;; - arm-coreboot) ;; arm-efi) ;; arm64-efi) ;; - riscv32-efi) ;; - riscv64-efi) ;; *-emu) ;; *-none) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; @@ -228,8 +204,7 @@ case "$host_os" in esac case "$host_os" in - cygwin) have_exec=y ;; - windows* | mingw32*) have_exec=n ;; + cygwin | windows* | mingw32*) have_exec=n ;; aros*) have_exec=n ;; *) have_exec=y;; esac @@ -239,7 +214,6 @@ case "$platform" in multiboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;; efi) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;; xen) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;; - xen_pvh) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN_PVH=1" ;; ieee1275) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;; uboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;; qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;; @@ -302,7 +276,7 @@ fi AC_SUBST(bootdirname) AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname", - [Default boot directory name]) + [Default boot directory name]") AC_ARG_WITH([grubdir], AS_HELP_STRING([--with-grubdir=DIR], @@ -342,7 +316,7 @@ AC_PROG_LN_S if test "x$LEX" = "x:"; then AC_MSG_ERROR([flex is not found]) else - version=`$LEX --version | $AWK '{ split($2,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'` + version=`$LEX --version | $AWK '{ split($NF,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'` if test -n "$version" -a "$version" -ge 20535; then : else @@ -362,7 +336,6 @@ gl_EARLY AC_PROG_CXX AM_PROG_CC_C_O AM_PROG_AS -AM_PATH_PYTHON([2.6]) # Must be GCC. test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required]) @@ -371,7 +344,6 @@ AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no) AC_GNU_SOURCE AM_GNU_GETTEXT([external]) -AM_GNU_GETTEXT_VERSION([0.18.3]) AC_SYS_LARGEFILE # Identify characteristics of the host architecture. @@ -382,9 +354,6 @@ if test x"$target_cpu-$platform" = xsparc64-emu ; then HOST_CFLAGS="$HOST_CFLAGS -m64" fi -CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64" -HOST_CPPFLAGS="$HOST_CPPFLAGS -D_FILE_OFFSET_BITS=64" - AC_C_BIGENDIAN AC_CHECK_SIZEOF(void *) AC_CHECK_SIZEOF(long) @@ -402,10 +371,7 @@ case "$host_os" in ;; *) AC_CHECK_SIZEOF(off_t) - if test x"$ac_cv_sizeof_off_t" != x8 ; then - AC_CHECK_SIZEOF(off64_t) - test x"$ac_cv_sizeof_off64_t" = x8 || AC_MSG_ERROR([Large file support is required]) - fi;; + test x"$ac_cv_sizeof_off_t" = x8 || AC_MSG_ERROR([Large file support is required]);; esac if test x$USE_NLS = xno; then @@ -420,15 +386,7 @@ fi # Check for functions and headers. AC_CHECK_FUNCS(posix_memalign memalign getextmntent) -AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h limits.h) - -# glibc 2.25 still includes sys/sysmacros.h in sys/types.h but emits deprecation -# warning which causes compilation failure later with -Werror. So use -Werror here -# as well to force proper sys/sysmacros.h detection. -SAVED_CFLAGS="$CFLAGS" -CFLAGS="$HOST_CFLAGS -Werror" -AC_HEADER_MAJOR -CFLAGS="$SAVED_CFLAGS" +AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h limits.h) AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default #include @@ -488,16 +446,6 @@ case "$build_os" in esac AC_SUBST(BUILD_EXEEXT) -# In some build environments like termux /bin/sh is not a valid -# shebang. Use $SHELL instead if it's executable and /bin/sh isn't -BUILD_SHEBANG=/bin/sh -for she in /bin/sh "$SHELL"; do - if test -x "$she" ; then - BUILD_SHEBANG="$she" - fi -done -AC_SUBST(BUILD_SHEBANG) - # For gnulib. gl_INIT @@ -571,24 +519,6 @@ CPPFLAGS="$TARGET_CPPFLAGS" LDFLAGS="$TARGET_LDFLAGS" LIBS="" -if test "x$target_m32" = x1; then - # Force 32-bit mode. - TARGET_CFLAGS="$TARGET_CFLAGS -m32" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32" - TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32" - TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" - TARGET_MODULE_FORMAT="elf32" -fi - -if test "x$target_m64" = x1; then - # Force 64-bit mode. - TARGET_CFLAGS="$TARGET_CFLAGS -m64" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64" - TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64" - TARGET_LDFLAGS="$TARGET_LDFLAGS -m64" - TARGET_MODULE_FORMAT="elf64" -fi - # debug flags. TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations" TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g" @@ -619,7 +549,7 @@ int main (void); TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_w_extra_flags" -AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang], +AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang] [ CFLAGS="$TARGET_CFLAGS" AC_COMPILE_IFELSE( @@ -630,153 +560,58 @@ AC_COMPILE_IFELSE( ]])], [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])]) -if test x$target_cpu = xpowerpc -o x$target_cpu = xmips; then - AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [ - grub_cv_target_cc_big_endian=no - for cand in "-target $target_cpu -Wl,-EB" "-target $target_cpu" \ - "-target $target_cpu-linux-gnu -Wl,-EB" "-target $target_cpu-linux-gnu" \ - "-EB" "-mbig-endian"; do - if test x"$grub_cv_target_cc_big_endian" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $cand -Werror" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__) -#error still little endian -#endif -asm (".globl start; start:"); -asm (".globl _start; _start:"); -asm (".globl __start; __start:"); -void __main (void); -void __main (void) {} -int main (void); -]], [[]])], - [grub_cv_target_cc_big_endian="$cand"], []) - done - ]) - - if test x"$grub_cv_target_cc_big_endian" = xno ; then - AC_MSG_ERROR([could not force big-endian]) - fi - - skip_linkflags="$(echo "$grub_cv_target_cc_big_endian"|sed 's@-Wl,-EB@@')" - - TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags" - TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags" - TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian" -elif test x$target_cpu = xmipsel; then - AC_CACHE_CHECK([for options to get little-endian compilation], grub_cv_target_cc_little_endian, [ - grub_cv_target_cc_little_endian=no - for cand in "-target $target_cpu -Wl,-EL" "-target $target_cpu" \ - "-target $target_cpu-linux-gnu -Wl,-EL" "-target $target_cpu-linux-gnu" \ - "-EL"; do - if test x"$grub_cv_target_cc_little_endian" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $cand -Werror" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ == __BYTE_ORDER__) -#error still big endian -#endif -asm (".globl start; start:"); -asm (".globl _start; _start:"); -asm (".globl __start; __start:"); -void __main (void); -void __main (void) {} -int main (void); -]], [[]])], - [grub_cv_target_cc_little_endian="$cand"], []) - done - ]) - - if test x"$grub_cv_target_cc_little_endian" = xno ; then - AC_MSG_ERROR([could not force little-endian]) - fi - - skip_linkflags="$(echo "$grub_cv_target_cc_little_endian"|sed 's@-Wl,-EL@@')" - - TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags" - TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags" - TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian" +# on x86 clang doesn't support .code16 +# on arm clang doesn't support .arch directive +# on mips clang doesn't support privilegied instructions, doubleword store/load +# and crashes with hand-written assembly +if test "x$grub_cv_cc_target_clang" = xyes && ( test "x$target_cpu" = xi386 \ + || test "x$target_cpu" = xx86_64 || test "x$target_cpu" = xarm \ + || test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ); then + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as" fi -# GRUB code is N32-compliant but it's experimental and we would prefer to -# avoid having too much variety when it doesn't result in any real improvement. -# Moreover N64 isn't supported. -if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then - AC_CACHE_CHECK([for options to force MIPS o32 ABI], grub_cv_target_cc_mips_o32_abi, [ - grub_cv_target_cc_mips_o32_abi=no - for arg in "" "-mabi=32" "-target $target_cpu -mabi=32" ; do - if test x"$grub_cv_target_cc_mips_o32_abi" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $arg -Werror" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#if !defined(_ABIO32) || !defined(_MIPS_SIM) || (_MIPS_SIM != _ABIO32) -#error not o32 ABI -#endif -asm (".globl start; start:"); -asm (".globl _start; _start:"); -asm (".globl __start; __start:"); -void __main (void); -void __main (void) {} -int main (void); -]], [[]])], - [grub_cv_target_cc_mips_o32_abi="$arg"], []) - done - ]) - - if test x"$grub_cv_target_cc_mips_o32_abi" = xno ; then - AC_MSG_ERROR([could not force MIPS o32 ABI]) - fi - - TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mips_o32_abi" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mips_o32_abi" +if test "x$grub_cv_cc_target_clang" = xyes && test "x$target_cpu" = xpowerpc; then +AC_CACHE_CHECK([if clang can handle ame instruction], [grub_cv_cc_target_clang_ame] +[ +CFLAGS="$TARGET_CFLAGS" +AC_COMPILE_IFELSE( +[AC_LANG_PROGRAM([], [[ + unsigned int a = 0, b = 0; + asm volatile ("{ame|addme} %0,%1" : "=r" (a) : "r" (b)); + if (a) + return 1; +]])], +[grub_cv_cc_target_clang_ame=yes], [grub_cv_cc_target_clang_ame=no])]) + # clang <= 3.3 doesn't handle most of ppc assembly, not even inline assembly + # used by gcrypt + if test x$grub_cv_cc_target_clang_ame = xno ; then + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as" + TARGET_CFLAGS="$TARGET_CFLAGS -no-integrated-as" + fi fi -AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [ -test_program= -case "x$target_cpu-$platform" in - xmips-* | xmipsel-*) - test_program=mips - ;; - xi386-pc) - test_program=i386-pc - ;; - xi386-* | xx86_64-*) - test_program=i386 - ;; - xpowerpc-* | xsparc64-* | xarm-*) - test_program=$target_cpu - ;; -esac -if test x"$test_program" = x ; then - grub_cv_cc_target_asm_compile= -else - found=no - for arg in "" "-no-integrated-as"; do - cmdline="$TARGET_CC -c -o /dev/null $TARGET_CCASFLAGS $arg $TARGET_CPPFLAGS $srcdir/asm-tests/$test_program.S" - echo "Running $cmdline" >&AS_MESSAGE_LOG_FD - if $cmdline >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then - grub_cv_cc_target_asm_compile="$arg" - found=yes - break - fi - done - if test x"$found" = xno ; then - AC_MSG_ERROR([could not compile assembly]) - fi -fi -]) - -TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_cc_target_asm_compile" - if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then TARGET_CFLAGS="$TARGET_CFLAGS -march=i386" fi +if test "x$target_m32" = x1; then + # Force 32-bit mode. + TARGET_CFLAGS="$TARGET_CFLAGS -m32" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32" + TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" + TARGET_MODULE_FORMAT="elf32" +fi + +if test "x$target_m64" = x1; then + # Force 64-bit mode. + TARGET_CFLAGS="$TARGET_CFLAGS -m64" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64" + TARGET_LDFLAGS="$TARGET_LDFLAGS -m64" + TARGET_MODULE_FORMAT="elf64" +fi + if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3" fi @@ -833,118 +668,7 @@ fi if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then # Some toolchains enable these features by default, but they need # registers that aren't set up properly in GRUB. - TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" -fi - -# GRUB doesn't use float or doubles at all. Yet some toolchains may decide -# that floats are a good fit to run instead of what's written in the code. -# Given that floating point unit is disabled (if present to begin with) -# when GRUB is running which may result in various hard crashes. -if test x"$platform" != xemu ; then - AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [ - grub_cv_target_cc_soft_float=no - if test "x$target_cpu" = xarm64; then - CFLAGS="$TARGET_CFLAGS -mgeneral-regs-only -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], []) - fi - if test "x$target_cpu" = xriscv32; then - CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], []) - fi - if test "x$target_cpu" = xriscv64; then - CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], []) - fi - if test "x$target_cpu" = xia64; then - CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="-mno-inline-float-divide -mno-inline-sqrt"], []) - fi - if test "x$target_cpu" = xsh4; then - CFLAGS="$TARGET_CFLAGS -m4-nofpu -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="-m4-nofpu"], []) - fi - for cand in "-msoft-float -Xclang -msoft-float -Xclang -no-implicit-float" \ - "-Xclang -msoft-float -Xclang -no-implicit-float" \ - "-Xclang -msoft-float" "-msoft-float"; do - if test x"$grub_cv_target_cc_soft_float" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $cand -Werror" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_soft_float="$cand"], []) - done - ]) - - if test x"$grub_cv_target_cc_soft_float" = xno ; then - AC_MSG_ERROR([could not force soft-float]) - fi - - case x"$grub_cv_target_cc_soft_float" in - x*"-Xclang"*) - # A trick so that clang doesn't see it on link stаge - TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_soft_float" - ;; - *) - TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_soft_float" - ;; - esac - TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_soft_float" - -fi - -if test x"$target_cpu" = xsparc64 ; then - AC_CACHE_CHECK([for options to reserve application registers], grub_cv_target_cc_mno_app_regs, [ - grub_cv_target_cc_mno_app_regs=no - for cand in "-mllvm -sparc-reserve-app-registers" \ - "-mno-app-regs"; do - if test x"$grub_cv_target_cc_mno_app_regs" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $cand -Werror" - CPPFLAGS="$TARGET_CPPFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_mno_app_regs="$cand"], []) - done - ]) - - if test x"$grub_cv_target_cc_mno_app_regs" = xno ; then - AC_MSG_ERROR([could not reserve application registers]) - fi - if test x"$grub_cv_target_cc_mno_app_regs" = x"-mllvm -sparc-reserve-app-registers" ; then - # A trick so that clang doesn't see it on link stаge - TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_app_regs" - else - TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_app_regs" - fi - - AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [ - grub_cv_target_cc_mno_relax=no - for cand in "-mno-relax" "-Wl,--no-relax"; do - if test x"$grub_cv_target_cc_mno_relax" != xno ; then - break - fi - LDFLAGS="$TARGET_LDFLAGS $cand -nostdlib -static" - CFLAGS="$TARGET_CFLAGS -Werror" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - asm (".globl start; start:"); - void __main (void); - void __main (void) {} - int main (void); - ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], []) - done - ]) - LDFLAGS="$TARGET_LDFLAGS" - CFLAGS="$TARGET_CFLAGS" - - if test x"$grub_cv_target_cc_mno_relax" = xno ; then - AC_MSG_ERROR([could not find no-relax options]) - fi - TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_mno_relax" + TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow" fi # By default, GCC 4.4 generates .eh_frame sections containing unwind @@ -975,24 +699,12 @@ if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xy TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions" fi -AC_CACHE_CHECK([whether -mno-stack-arg-probe works], [grub_cv_cc_mno_stack_arg_probe], [ - CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_mno_stack_arg_probe=yes], - [grub_cv_cc_mno_stack_arg_probe=no]) -]) - -if test "x$grub_cv_cc_mno_stack_arg_probe" = xyes; then - TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe" -fi - - # By default, GCC 4.6 generates .eh_frame sections containing unwind # information in some cases where it previously did not. GRUB doesn't need # these and they just use up vital space. Restore the old compiler # behaviour. AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [ - CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables" + CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [grub_cv_cc_fno_asynchronous_unwind_tables=yes], [grub_cv_cc_fno_asynchronous_unwind_tables=no]) @@ -1002,28 +714,66 @@ if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables" fi -AC_CACHE_CHECK([whether -fno-unwind-tables works], [grub_cv_cc_fno_unwind_tables], [ - CFLAGS="$TARGET_CFLAGS -fno-unwind-tables" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_fno_unwind_tables=yes], - [grub_cv_cc_fno_unwind_tables=no]) -]) - -if test "x$grub_cv_cc_fno_unwind_tables" = xyes; then - TARGET_CFLAGS="$TARGET_CFLAGS -fno-unwind-tables" +AC_ARG_ENABLE([efiemu], + [AS_HELP_STRING([--enable-efiemu], + [build and install the efiemu runtimes (default=guessed)])]) +if test x"$enable_efiemu" = xno ; then + efiemu_excuse="explicitly disabled" fi - -# Do not generate .ident sections. -AC_CACHE_CHECK([whether -fno-ident works], [grub_cv_cc_fno_ident], [ - CFLAGS="$TARGET_CFLAGS -fno-ident" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_fno_ident=yes], - [grub_cv_cc_fno_ident=no]) -]) - -if test "x$grub_cv_cc_fno_ident" = xyes; then - TARGET_CFLAGS="$TARGET_CFLAGS -fno-ident" +if test x"$grub_cv_target_cc_link_format" = x-mi386pe || test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then + efiemu_excuse="not available on cygwin" fi +if test x"$target_cpu" != xi386 ; then + efiemu_excuse="only available on i386" +fi +if test x"$platform" = xefi ; then + efiemu_excuse="not available on efi" +fi +if test x"$efiemu_excuse" = x ; then + AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [ + CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], + [grub_cv_cc_efiemu=yes], + [grub_cv_cc_efiemu=no]) + ]) + if test x$grub_cv_cc_efiemu = xno; then + efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib" + fi +fi +if test x"$efiemu_excuse" = x ; then + AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [ + grub_cv_target_cc_efiemu64_link_format=unknown + for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do + CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone" + LDFLAGS="-m64 -Wl,$format -nostdlib -static" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + asm (".globl start; start:"); + asm (".globl _start; _start:"); + asm (".globl __start; __start:"); + void __main (void); + void __main (void) {} + ]], [[]])], [flag=1], [flag=0]) + if test x"$flag" = x1; then + grub_cv_target_cc_efiemu64_link_format="$format" + break + fi + done]) + if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then + efiemu_excuse="no suitable link format for efiemu64 found" + else + EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format" + fi +fi +if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then + AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled ($efiemu_excuse)]) +fi +if test x"$efiemu_excuse" = x ; then +enable_efiemu=yes +else +enable_efiemu=no +fi +AC_SUBST([enable_efiemu]) +AC_SUBST([EFIEMU64_LINK_FORMAT]) CFLAGS="$TARGET_CFLAGS" @@ -1117,79 +867,12 @@ else TARGET_IMG_CFLAGS= fi -CFLAGS="$TARGET_CFLAGS" - -AC_ARG_ENABLE([efiemu], - [AS_HELP_STRING([--enable-efiemu], - [build and install the efiemu runtimes (default=guessed)])]) -if test x"$enable_efiemu" = xno ; then - efiemu_excuse="explicitly disabled" -fi - -if test x"$grub_cv_target_cc_link_format" = x-mi386pe || test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then - efiemu_excuse="not available on cygwin" -fi -if test x"$target_cpu" != xi386 ; then - efiemu_excuse="only available on i386" -fi -if test x"$platform" = xefi ; then - efiemu_excuse="not available on efi" -fi - -if test x"$efiemu_excuse" = x ; then - AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [ - CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_cc_efiemu=yes], - [grub_cv_cc_efiemu=no]) - ]) - if test x$grub_cv_cc_efiemu = xno; then - efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib" - fi -fi -if test x"$efiemu_excuse" = x ; then - AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [ - grub_cv_target_cc_efiemu64_link_format=unknown - for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do - CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone" - LDFLAGS="-m64 -Wl,$format -nostdlib -static" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - asm (".globl start; start:"); - asm (".globl _start; _start:"); - asm (".globl __start; __start:"); - void __main (void); - void __main (void) {} - ]], [[]])], [flag=1], [flag=0]) - if test x"$flag" = x1; then - grub_cv_target_cc_efiemu64_link_format="$format" - break - fi - done]) - if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then - efiemu_excuse="no suitable link format for efiemu64 found" - else - EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format" - fi -fi -if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then - AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled ($efiemu_excuse)]) -fi -if test x"$efiemu_excuse" = x ; then -enable_efiemu=yes -else -enable_efiemu=no -fi -AC_SUBST([enable_efiemu]) -AC_SUBST([EFIEMU64_LINK_FORMAT]) - -CFLAGS="$TARGET_CFLAGS" - AC_SUBST(TARGET_LDFLAGS_OLDMAGIC) LDFLAGS="$TARGET_LDFLAGS" -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then +if test "$target_cpu" = x86_64 || test "$target_cpu-$platform" = sparc64-emu ; then # Use large model to support 4G memory AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [ CFLAGS="$TARGET_CFLAGS -mcmodel=large" @@ -1199,7 +882,7 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_ ]) if test "x$grub_cv_cc_mcmodel" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" - elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then + elif test "$target_cpu-$platform" = sparc64-emu; then TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany" fi fi @@ -1220,24 +903,14 @@ if test "$target_cpu"-"$platform" = x86_64-efi; then fi if test "x$target_cpu" = xarm; then - AC_CACHE_CHECK([for options to disable movt and movw], grub_cv_target_cc_mno_movt, [ - grub_cv_target_cc_mno_movt=no - for cand in "-mno-movt" \ - "-mllvm -arm-use-movt=0" \ - "-mword-relocations"; do - if test x"$grub_cv_target_cc_mno_movt" != xno ; then - break - fi - CFLAGS="$TARGET_CFLAGS $cand -Werror" - CPPFLAGS="$TARGET_CPPFLAGS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [grub_cv_target_cc_mno_movt="$cand"], []) - done + AC_CACHE_CHECK([whether option -mlong-calls works], grub_cv_cc_mlong_calls, [ + CFLAGS="$TARGET_CFLAGS -mlong-calls -Werror" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], + [grub_cv_cc_mlong_calls=yes], + [grub_cv_cc_mlong_calls=no]) ]) - - if test x"$grub_cv_target_cc_mno_movt" != xno ; then - # A trick so that clang doesn't see it on link stage - TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt" + if test "x$grub_cv_cc_mlong_calls" = xyes; then + TARGET_CFLAGS="$TARGET_CFLAGS -mlong-calls" fi AC_CACHE_CHECK([whether option -mthumb-interwork works], grub_cv_cc_mthumb_interwork, [ CFLAGS="$TARGET_CFLAGS -mthumb-interwork -Werror" @@ -1247,19 +920,30 @@ if test "x$target_cpu" = xarm; then ]) if test "x$grub_cv_cc_mthumb_interwork" = xyes; then TARGET_CFLAGS="$TARGET_CFLAGS -mthumb-interwork" - # Clang defaults to thumb interworking elif test "x$grub_cv_cc_target_clang" = xno ; then AC_MSG_ERROR([your compiler doesn't support -mthumb-interwork]) + else + CFLAGS="$TARGET_CFLAGS" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ +#if defined (__thumb__) && !defined (__thumb2__) +#error thumb without interworking +#endif +]])], + [no_interwork_ok=yes], + [no_interwork_ok=no]) + if test x$no_interwork_ok = xno ; then + AC_MSG_ERROR([attempt to compile to thumb with no thumb interwork]) + fi fi fi AC_CACHE_CHECK([whether option -Qn works], grub_cv_target_cc_qn, [ - CFLAGS="$TARGET_CFLAGS -Qn -Qunused-arguments -Werror" + CFLAGS="$TARGET_CFLAGS -Qn -Werror" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [grub_cv_target_cc_qn=yes], [grub_cv_target_cc_qn=no])]) if test "x$grub_cv_target_cc_qn" = xyes; then - TARGET_CFLAGS="$TARGET_CFLAGS -Qn -Qunused-arguments" + TARGET_CFLAGS="$TARGET_CFLAGS -Qn" fi # @@ -1270,27 +954,13 @@ CFLAGS="$TARGET_CFLAGS" # Position independent executable. grub_CHECK_PIE -grub_CHECK_NO_PIE -grub_CHECK_NO_PIE_ONEWORD -grub_CHECK_LINK_PIE [# Need that, because some distributions ship compilers that include -# `-fPIE' or '-fpie' and '-pie' in the default specs. +# `-fPIE' in the default specs. if [ x"$pie_possible" = xyes ]; then - TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie" - TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie" -fi - -if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then - if [ x"$nopie_possible" = xyes ]; then - TARGET_LDFLAGS="$TARGET_LDFLAGS -no-pie" - fi - if [ x"$nopie_oneword_possible" = xyes ]; then - TARGET_LDFLAGS="$TARGET_LDFLAGS -nopie" - fi + TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE" fi] CFLAGS="$TARGET_CFLAGS" -LDFLAGS="$TARGET_LDFLAGS" # Position independent executable. grub_CHECK_PIC @@ -1299,12 +969,9 @@ grub_CHECK_PIC # and reload $gp in every function. # GCC implements it using symbol __gnu_local_gp in non-PIC as well. # However with clang we need PIC for this reloading to happen. -# With arm64 we need relocations that are in some way representable in -# PE as we need to support arm64-efi. Without -fPIC clang generates -# movk's which aren't representable. # Since default varies across dictributions use either -fPIC or -fno-PIC # explicitly. -if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel || test x$target_cpu = xarm64 ) && test "x$grub_cv_cc_target_clang" = xyes ; then +if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then TARGET_CFLAGS="$TARGET_CFLAGS -fPIC" elif [ x"$pic_possible" = xyes ]; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC" @@ -1364,17 +1031,22 @@ fi # Set them to their new values for the tests below. CC="$TARGET_CC" -if test x"$platform" = xemu ; then -CFLAGS="$TARGET_CFLAGS -Wno-error" -elif test "x$TARGET_APPLE_LINKER" = x1 ; then +if test "x$TARGET_APPLE_LINKER" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error" else CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error" fi CPPFLAGS="$TARGET_CPPFLAGS" +if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then +TARGET_LIBGCC= +else +TARGET_LIBGCC=-lgcc +fi + +LIBS="$TARGET_LIBGCC" grub_ASM_USCORE -if test "x$TARGET_APPLE_LINKER" = x0 && test x"$platform" != xemu; then +if test "x$TARGET_APPLE_LINKER" = x0 ; then if test x$grub_cv_asm_uscore = xyes; then DEFSYM="-Wl,--defsym,_abort=_main -Wl,--defsym,__main=_main" else @@ -1384,9 +1056,7 @@ CFLAGS="$TARGET_CFLAGS -nostdlib $DEFSYM" fi # Check for libgcc symbols -if test x"$platform" = xemu; then -AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __clzdi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) -fi +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x) if test "x$TARGET_APPLE_LINKER" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib -static" @@ -1411,6 +1081,8 @@ if test "x$target_cpu" = xi386; then grub_CHECK_END_SYMBOL fi CFLAGS="$TARGET_CFLAGS" + grub_I386_ASM_PREFIX_REQUIREMENT + grub_I386_ASM_ADDR32 fi grub_PROG_NM_WORKS @@ -1422,7 +1094,7 @@ AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY) if test "$platform" != emu; then AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [ SAVED_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$TARGET_CPPFLAGS -nostdlib -nostdinc -isystem `$TARGET_CC -print-file-name=include`" + CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include #include int va_arg_func (int fixed, va_list args);]], [[]])], @@ -1462,11 +1134,9 @@ LIBS="$tmp_LIBS" # Memory manager debugging. AC_ARG_ENABLE([mm-debug], AS_HELP_STRING([--enable-mm-debug], - [include memory manager debugging])) -if test x$enable_mm_debug = xyes; then - AC_DEFINE([MM_DEBUG], [1], - [Define to 1 if you enable memory manager debugging.]) -fi + [include memory manager debugging]), + [AC_DEFINE([MM_DEBUG], [1], + [Define to 1 if you enable memory manager debugging.])]) AC_ARG_ENABLE([cache-stats], AS_HELP_STRING([--enable-cache-stats], @@ -1490,6 +1160,10 @@ else fi AC_SUBST([BOOT_TIME_STATS]) +AC_ARG_ENABLE([grub-emu-usb], + [AS_HELP_STRING([--enable-grub-emu-usb], + [build and install the `grub-emu' debugging utility with USB support (default=guessed)])]) + AC_ARG_ENABLE([grub-emu-sdl], [AS_HELP_STRING([--enable-grub-emu-sdl], [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])]) @@ -1500,6 +1174,34 @@ AC_ARG_ENABLE([grub-emu-pci], if test "$platform" = emu; then +if test x"$enable_grub_emu_usb" != xyes ; then + grub_emu_usb_excuse="not enabled" +fi + +if test x"$enable_grub_emu_pci" = xyes ; then + grub_emu_usb_excuse="conflicts with PCI support" +fi + +[if [ x"$grub_emu_usb_excuse" = x ]; then + # Check for libusb libraries.] +AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"], + [grub_emu_usb_excuse=["need libusb library"]]) + AC_SUBST([LIBUSB]) +[fi] +[if [ x"$grub_emu_usb_excuse" = x ]; then + # Check for headers.] + AC_CHECK_HEADERS([usb.h], [], + [grub_emu_usb_excuse=["need libusb headers"]]) +[fi] +if test x"$enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then + AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled ($grub_emu_usb_excuse)]) +fi +if test x"$grub_emu_usb_excuse" = x ; then +enable_grub_emu_usb=yes +else +enable_grub_emu_usb=no +fi + if test x"$enable_grub_emu_sdl" = xno ; then grub_emu_sdl_excuse="explicitly disabled" fi @@ -1529,6 +1231,10 @@ if test x"$enable_grub_emu_pci" != xyes ; then grub_emu_pci_excuse="not enabled" fi +if test x"$enable_grub_emu_usb" = xyes ; then + grub_emu_pci_excuse="conflicts with USB support" +fi + [if [ x"$grub_emu_pci_excuse" = x ]; then # Check for libpci libraries.] AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"], @@ -1537,7 +1243,7 @@ fi [fi] [if [ x"$grub_emu_pci_excuse" = x ]; then # Check for headers.] - AC_CHECK_HEADERS([pciaccess.h], [], + AC_CHECK_HEADERS([pci/pci.h], [], [grub_emu_pci_excuse=["need libpciaccess headers"]]) [fi] @@ -1549,12 +1255,14 @@ enable_grub_emu_pci=no fi AC_SUBST([enable_grub_emu_sdl]) +AC_SUBST([enable_grub_emu_usb]) AC_SUBST([enable_grub_emu_pci]) else # Ignore --enable-emu-* if platform is not emu enable_grub_emu_sdl=no +enable_grub_emu_usb=no enable_grub_emu_pci=no fi @@ -1565,22 +1273,29 @@ if test x"$enable_grub_mkfont" = xno ; then grub_mkfont_excuse="explicitly disabled" fi +if test x"$grub_mkfont_excuse" = x ; then + # Check for freetype libraries. + AC_CHECK_TOOLS([FREETYPE], [freetype-config]) + if test "x$FREETYPE" = x ; then + grub_mkfont_excuse=["need freetype2 library"] + fi +fi + unset ac_cv_header_ft2build_h if test x"$grub_mkfont_excuse" = x ; then # Check for freetype libraries. - PKG_CHECK_MODULES([FREETYPE], [freetype2], [ - SAVED_CPPFLAGS="$CPPFLAGS" - SAVED_LIBS="$LIBS" - CPPFLAGS="$CPPFLAGS $FREETYPE_CFLAGS" - LIBS="$LIBS $FREETYPE_LIBS" - AC_CHECK_HEADERS([ft2build.h], [], - [grub_mkfont_excuse=["need freetype2 headers"]]) - AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], - [grub_mkfont_excuse=["freetype2 library unusable"]]) - CPPFLAGS="$SAVED_CPPFLAGS" - LIBS="$SAVED_LIBS" - ], [grub_mkfont_excuse=["need freetype2 library"]]) + freetype_cflags=`$FREETYPE --cflags` + freetype_libs=`$FREETYPE --libs` + SAVED_CPPFLAGS="$CPPFLAGS" + SAVED_LIBS="$LIBS" + CPPFLAGS="$CPPFLAGS $freetype_cflags" + LIBS="$LIBS $freetype_libs" + AC_CHECK_HEADERS([ft2build.h], [], + [grub_mkfont_excuse=["need freetype2 headers"]]) + AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_mkfont_excuse=["freetype2 library unusable"]]) + CPPFLAGS="$SAVED_CPPFLAGS" + LIBS="$SAVED_LIBS" fi if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then @@ -1592,6 +1307,8 @@ else enable_grub_mkfont=no fi AC_SUBST([enable_grub_mkfont]) +AC_SUBST([freetype_cflags]) +AC_SUBST([freetype_libs]) SAVED_CC="$CC" SAVED_CPP="$CPP" @@ -1621,21 +1338,25 @@ AC_SUBST([BUILD_WORDS_BIGENDIAN]) if test x"$grub_build_mkfont_excuse" = x ; then # Check for freetype libraries. - SAVED_PKG_CONFIG="$PKG_CONFIG" - test -z "$BUILD_PKG_CONFIG" || PKG_CONFIG="$BUILD_PKG_CONFIG" - PKG_CHECK_MODULES([BUILD_FREETYPE], [freetype2], [ - SAVED_CPPFLAGS_2="$CPPFLAGS" - SAVED_LIBS="$LIBS" - CPPFLAGS="$CPPFLAGS $BUILD_FREETYPE_CFLAGS" - LIBS="$LIBS $BUILD_FREETYPE_LIBS" - AC_CHECK_HEADERS([ft2build.h], [], - [grub_build_mkfont_excuse=["need freetype2 headers"]]) - AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], - [grub_build_mkfont_excuse=["freetype2 library unusable"]]) - LIBS="$SAVED_LIBS" - CPPFLAGS="$SAVED_CPPFLAGS_2" - ], [grub_build_mkfont_excuse=["need freetype2 library"]]) - PKG_CONFIG="$SAVED_PKG_CONFIG" + AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config]) + if test "x$BUILD_FREETYPE" = x ; then + grub_build_mkfont_excuse=["need freetype2 library"] + fi +fi + +if test x"$grub_build_mkfont_excuse" = x ; then + # Check for freetype libraries. + build_freetype_cflags=`$BUILD_FREETYPE --cflags` + build_freetype_libs=`$BUILD_FREETYPE --libs` + SAVED_CPPFLAGS_2="$CPPFLAGS" + SAVED_LIBS="$LIBS" + CPPFLAGS="$CPPFLAGS $build_freetype_cflags" + LIBS="$LIBS $build_freetype_libs" + AC_CHECK_HEADERS([ft2build.h], [], + [grub_build_mkfont_excuse=["need freetype2 headers"]]) + AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_build_mkfont_excuse=["freetype2 library unusable"]]) + LIBS="$SAVED_LIBS" + CPPFLAGS="$SAVED_CPPFLAGS_2" fi if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then @@ -1646,14 +1367,17 @@ if test x"$grub_build_mkfont_excuse" = x ; then else enable_build_grub_mkfont=no fi -if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then +if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$platform" = xcoreboot ); then if test x"$grub_build_mkfont_excuse" = x ; then - AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont]) + AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont]) else - AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont ($grub_build_mkfont_excuse)]) + AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont ($grub_build_mkfont_excuse)]) fi fi +AC_SUBST([build_freetype_cflags]) +AC_SUBST([build_freetype_libs]) + CC="$SAVED_CC" CPP="$SAVED_CPP" CFLAGS="$SAVED_CFLAGS" @@ -1717,11 +1441,11 @@ if test x"$enable_build_grub_mkfont" = xno ; then FONT_SOURCE= fi -if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then +if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 || test "x$platform" = xcoreboot ); then if test x"$grub_build_mkfont_excuse" = x ; then - AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont]) + AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont]) else - AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)]) + AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)]) fi fi @@ -1747,7 +1471,7 @@ fi if test x"$grub_mount_excuse" = x ; then # Check for fuse headers. SAVED_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -DFUSE_USE_VERSION=26" + CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26" AC_CHECK_HEADERS([fuse/fuse.h], [], [grub_mount_excuse=["need FUSE headers"]]) CPPFLAGS="$SAVED_CPPFLAGS" @@ -1882,6 +1606,8 @@ AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu], [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)]) AC_SUBST(HAVE_ASM_USCORE) +AC_SUBST(ADDR32) +AC_SUBST(DATA32) AC_SUBST(BSS_START_SYMBOL) AC_SUBST(END_SYMBOL) AC_SUBST(PACKAGE) @@ -1895,15 +1621,15 @@ if test x"$enable_werror" != xno ; then HOST_CFLAGS="$HOST_CFLAGS -Werror" fi +if test "x$grub_cv_cc_target_clang" = xno; then + TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc" +else + TARGET_LDFLAGS_STATIC_LIBGCC= +fi + TARGET_CPP="$TARGET_CC -E" TARGET_CCAS=$TARGET_CC -# Includes which include make-time substitutions. They must come last -# as to avoid executing top_builddir in shell. -HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" -TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" -TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" - GRUB_TARGET_CPU="${target_cpu}" GRUB_PLATFORM="${platform}" @@ -1911,6 +1637,8 @@ AC_SUBST(GRUB_TARGET_CPU) AC_SUBST(GRUB_PLATFORM) AC_SUBST(TARGET_OBJCONV) +AC_SUBST(TARGET_LIBGCC) +AC_SUBST(TARGET_LDFLAGS_STATIC_LIBGCC) AC_SUBST(TARGET_CPP) AC_SUBST(TARGET_CCAS) AC_SUBST(TARGET_OBJ2ELF) @@ -1940,6 +1668,7 @@ AC_SUBST(BUILD_LIBM) AM_CONDITIONAL([COND_real_platform], [test x$platform != xnone]) AM_CONDITIONAL([COND_emu], [test x$platform = xemu]) +AM_CONDITIONAL([COND_clang], [test x$grub_cv_cc_target_clang = xyes]) AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc]) AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi]) AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi]) @@ -1949,7 +1678,6 @@ AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot]) AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi]) AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen]) -AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh]) AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen]) AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson]) AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips]) @@ -1962,14 +1690,9 @@ AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel]) AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips]) AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ]) AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot]) -AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot]) AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi]) AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ]) AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi]) -AM_CONDITIONAL([COND_riscv32], [test x$target_cpu = xriscv32 ]) -AM_CONDITIONAL([COND_riscv64], [test x$target_cpu = xriscv64 ]) -AM_CONDITIONAL([COND_riscv32_efi], [test x$target_cpu = xriscv32 -a x$platform = xefi]) -AM_CONDITIONAL([COND_riscv64_efi], [test x$target_cpu = xriscv64 -a x$platform = xefi]) AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd]) AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux]) @@ -1980,6 +1703,7 @@ AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu]) AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos]) AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x]) +AM_CONDITIONAL([COND_GRUB_EMU_USB], [test x$enable_grub_emu_usb = xyes]) AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) @@ -2044,7 +1768,7 @@ fi AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([grub-core/Makefile]) -AC_CONFIG_FILES([grub-core/lib/gnulib/Makefile]) +AC_CONFIG_FILES([grub-core/gnulib/Makefile]) AC_CONFIG_FILES([po/Makefile.in]) AC_CONFIG_FILES([docs/Makefile]) AC_CONFIG_FILES([util/bash-completion.d/Makefile]) @@ -2057,6 +1781,11 @@ echo "*******************************************************" echo GRUB2 will be compiled with following components: echo Platform: "$target_cpu"-"$platform" if [ x"$platform" = xemu ]; then +if [ x"$grub_emu_usb_excuse" = x ]; then +echo USB support for grub-emu: Yes +else +echo USB support for grub-emu: No "($grub_emu_usb_excuse)" +fi if [ x"$grub_emu_sdl_excuse" = x ]; then echo SDL support for grub-emu: Yes else diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi index 24d17b8ec..a9f4de631 100644 --- a/docs/grub-dev.texi +++ b/docs/grub-dev.texi @@ -77,7 +77,6 @@ This edition documents version @value{VERSION}. * Coding style:: * Finding your way around:: * Contributing Changes:: -* Updating External Code:: * Porting:: * Error Handling:: * Stack and heap size:: @@ -85,7 +84,6 @@ This edition documents version @value{VERSION}. * Video Subsystem:: * PFF2 Font File Format:: * Graphical Menu Software Design:: -* Verifiers framework:: * Copying This Manual:: Copying This Manual * Index:: @end menu @@ -183,44 +181,38 @@ If a macro is global, its name must be prefixed with GRUB_ and must consist of o @section Comments All comments shall be C-style comments, of the form @samp{/* @dots{} */}. -A comment can be placed immediately preceding the entity it describes or it -can be placed together with code, variable declarations, or other non-comment -entities. However, it is recommended to not mix various forms especially in -types/structs descriptions. + +Comments shall be placed only on a line by themselves. They shall not be placed together with code, variable declarations, or other non-comment entities. A comment should be placed immediately preceding the entity it describes. Acceptable: @example -/* The page # that is the front buffer. */ +/* The page # that is the front buffer. */ int displayed_page; +/* The page # that is the back buffer. */ +int render_page; @end example +Unacceptable: @example -int render_page; /* The page # that is the back buffer. */ +int displayed_page; /* The page # that is the front buffer. */ +int render_page; /* The page # that is the back buffer. */ @end example @node Multi-Line Comments @section Multi-Line Comments -Comments spanning multiple lines shall be formatted with all lines after the -first aligned with the first line. Asterisk characters should be repeated at -the start of each subsequent line. +Comments spanning multiple lines shall be formatted with all lines after the first aligned with the first line. + +Asterisk characters should not be repeated a the start of each subsequent line. Acceptable: @example -/* - * This is a comment - * which spans multiple lines. - * It is long. - */ +/* This is a comment + which spans multiple lines. + It is long. */ @end example Unacceptable: -@example -/* This is a comment - which spans multiple lines. - It is long. */ -@end example - @example /* * This is a comment @@ -228,16 +220,7 @@ Unacceptable: * It is long. */ @end example -@example -/* This is a comment - * which spans multiple lines. - * It is long. - */ -@end example - -In particular first unacceptable form makes comment difficult to distinguish -from the code itself. Especially if it contains the code snippets and/or is -long. So, its usage is disallowed. +The opening @samp{/*} and closing @samp{*/} should be placed together on a line with text. @node Finding your way around @chapter Finding your way around @@ -482,106 +465,6 @@ If your intention is to just get started, please do not submit a inclusion request. Instead, please subscribe to the mailing list, and communicate first (e.g. sending a patch, asking a question, commenting on another message...). -@node Updating External Code -@chapter Updating external code - -GRUB includes some code from other projects, and it is sometimes necessary -to update it. - -@menu -* Gnulib:: -* jsmn:: -* minilzo:: -@end menu - -@node Gnulib -@section Gnulib - -Gnulib is a source code library that provides basic functionality to -programs and libraries. Many software packages make use of Gnulib -to avoid reinventing the portability wheel. - -GRUB imports Gnulib using its @command{bootstrap} utility, identifying a -particular Git commit in @file{bootstrap.conf}. To upgrade to a new Gnulib -commit, set @code{GNULIB_REVISION} in @file{bootstrap.conf} to the new commit -ID, then run @kbd{./bootstrap} and whatever else you need to make sure it -works. Check for changes to Gnulib's @file{NEWS} file between the old and new -commits; in some cases it will be necessary to adjust GRUB to match. You may -also need to update the patches in @file{grub-core/lib/gnulib-patches/}. - -To add a new Gnulib module or remove one that is no longer needed, change -@code{gnulib_modules} in @file{bootstrap.conf}. Again, run @kbd{./bootstrap} -and whatever else you need to make sure it works. - -Bootstrapping from an older distribution containing gettext version < 0.18.3, -will require a patch similar to this to be applied first before running the -@command{./bootstrap} utility: - -@example -diff --git a/bootstrap.conf b/bootstrap.conf -index 988dda0..a3193a9 100644 ---- a/bootstrap.conf -+++ b/bootstrap.conf -@@ -67,7 +67,7 @@ SKIP_PO=t -buildreq="\ -autoconf 2.63 -automake 1.11 --gettext 0.18.3 -+gettext 0.17 -git 1.5.5 -tar - -" -diff --git a/configure.ac b/configure.ac -index 08b518f..99f5b36 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -362,7 +362,7 @@ AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no) - -AC_GNU_SOURCE -AM_GNU_GETTEXT([external]) --AM_GNU_GETTEXT_VERSION([0.18.3]) -+AM_GNU_GETTEXT_VERSION([0.17]) -AC_SYS_LARGEFILE - -# Identify characteristics of the host architecture. - -@end example - -It will also be necessary to adjust the patches in -@file{po/gettext-patches/} to apply to an older version of gettext. - -@node jsmn -@section jsmn - -jsmn is a minimalistic JSON parser which is implemented in a single header file -@file{jsmn.h}. To import a different version of the jsmn parser, you may simply -download the @file{jsmn.h} header from the desired tag or commit to the target -directory: - -@example -curl -L https://raw.githubusercontent.com/zserge/jsmn/v1.1.0/jsmn.h \ - -o grub-core/lib/json/jsmn.h -@end example - -@node minilzo -@section minilzo - -miniLZO is a very lightweight subset of the LZO library intended for easy -inclusion in other projects. It is generated automatically from the LZO -source code and contains the most important LZO functions. - -To upgrade to a new version of the miniLZO library, download the release -tarball and copy the files into the target directory: - -@example -curl -L -O http://www.oberhumer.com/opensource/lzo/download/minilzo-2.08.tar.gz -tar -zxf minilzo-2.08.tar.gz -rm minilzo-2.08/testmini.c -rm -r grub-core/lib/minilzo/* -cp minilzo-2.08/*.[hc] grub-core/lib/minilzo -rm -r minilzo-2.08* -@end example - @node Porting @chapter Porting @@ -788,7 +671,7 @@ is already present and you'll need to make it follow the existant code paths for your platform adding adjustments if necessary. When done compile: @example -./bootstrap +./autogen.sh ./configure --target=$cpu --with-platform=$platform TARGET_CC=.. OBJCOPY=... STRIP=... make > /dev/null @end example @@ -2066,63 +1949,6 @@ the graphics mode that was in use before @code{grub_video_setup()} was called might fix some of the problems. -@node Verifiers framework -@chapter Verifiers framework - -To register your own verifier call @samp{grub_verifier_register} with a structure -pointing to your functions. - -The interface is inspired by the hash interface with @samp{init}/@samp{write}/@samp{fini}. - -There are essentially 2 ways of using it, hashing and whole-file verification. - -With the hashing approach: -During @samp{init} you decide whether you want to check the given file and init context. -In @samp{write} you update your hashing state. -In @samp{fini} you check that the hash matches the expected value/passes some check/... - -With whole-file verification: -During @samp{init} you decide whether you want to check the given file and init context. -In @samp{write} you verify the file and return an error if it fails. -You don't have @samp{fini}. - -Additional @samp{verify_string} receives various strings like kernel parameters -to verify. Returning no error means successful verification and an error stops -the current action. - -Detailed description of the API: - -Every time a file is opened your @samp{init} function is called with file descriptor -and file type. Your function can have the following outcomes: - -@itemize - -@item returning no error and setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_DEFER_AUTH}. -In this case verification is deferred to other active verifiers. Verification -fails if nobody cares or selected verifier fails. - -@item returning no error and setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION}. -In this case your verifier will not be called anymore and it is assumed to have -skipped verification. - -@item returning no error and not setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION} -In this case verification is done as described in the following section. - -@item returning an error. Then opening of the file will fail due to failed verification. - -@end itemize - -In the third case your @samp{write} will be called with chunks of the file. If -you need the whole file in a single chunk then during @samp{init} set the bit -@samp{GRUB_VERIFY_FLAGS_SINGLE_CHUNK} in @samp{*flags}. During @samp{init} you -may set @samp{*context} if you need additional context. At every iteration you -may return an error and the file will be considered as having failed the -verification. If you return no error then verification continues. - -Optionally at the end of the file @samp{fini}, if it exists, is called with just -the context. If you return no error during any of @samp{init}, @samp{write} and -@samp{fini} then the file is considered as having succeded verification. - @node Copying This Manual @appendix Copying This Manual diff --git a/docs/grub.texi b/docs/grub.texi index 37f7ce7da..46b9e7f8e 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -360,9 +360,8 @@ blocklist notation. The currently supported filesystem types are @dfn{Amiga Fast FileSystem (AFFS)}, @dfn{AtheOS fs}, @dfn{BeFS}, @dfn{BtrFS} (including raid0, raid1, raid10, gzip and lzo), @dfn{cpio} (little- and big-endian bin, odc and newc variants), -@dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32}, -@dfn{exFAT}, @dfn{F2FS}, @dfn{HFS}, @dfn{HFS+}, -@dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files), +@dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32}, @dfn{exFAT}, @dfn{HFS}, +@dfn{HFS+}, @dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files), @dfn{JFS}, @dfn{Minix fs} (versions 1, 2 and 3), @dfn{nilfs2}, @dfn{NTFS} (including compression), @dfn{ReiserFS}, @dfn{ROMFS}, @dfn{Amiga Smart FileSystem (SFS)}, @dfn{Squash4}, @dfn{tar}, @dfn{UDF}, @@ -894,7 +893,6 @@ magic. @menu * General boot methods:: How to boot OSes with GRUB generally * Loopback booting:: Notes on booting from loopbacks -* LVM cache booting:: Notes on booting from LVM cache logical volume * OS-specific notes:: Notes on some operating systems @end menu @@ -992,26 +990,6 @@ way. Please consider alternative boot methods like copying all files from the image to actual partition. Consult your OS documentation for more details -@node LVM cache booting -@section Booting from LVM cache logical volume - -The LVM cache logical volume is the logical volume consisting of the original -and the cache pool logical volume. The original is usually on a larger and -slower storage device while the cache pool is on a smaller and faster one. The -performance of the original volume can be improved by storing the frequently -used data on the cache pool to utilize the greater performance of faster -device. - -GRUB boots from LVM cache logical volume merely by reading it's original -logical volume so that dirty data in cache pool volume is disregarded. This is -not a problem for "writethrough" cache mode as it ensures that any data written -will be stored both on the cache and the origin LV. For the other cache mode -"writeback", which delays writing from the cache pool back to the origin LV to -boost performance, GRUB may fail to boot in the wake of accidental power outage -due to it's inability to assemble the cache device for reading the required -dirty data left behind. The situation will be improved after adding full -support to the LVM cache logical volume in the future. - @node OS-specific notes @section Some caveats on OS-specific issues @@ -1114,6 +1092,12 @@ grub> @kbd{initrd16 /initrd} Finally, run the command @command{boot} (@pxref{boot}). @end enumerate +@strong{Caution:} If you use an initrd and specify the @samp{mem=} +option to the kernel to let it use less than actual memory size, you +will also have to specify the same memory size to GRUB. To let GRUB know +the size, run the command @command{uppermem} @emph{before} loading the +kernel. @xref{uppermem}, for more information. + @node NetBSD @subsection NetBSD @@ -1229,11 +1213,10 @@ GRUB is configured using @file{grub.cfg}, usually located under need to write the whole thing by hand. @menu -* Simple configuration:: Recommended for most users -* Root Identifcation Heuristics:: Summary on how the root file system is identified. -* Shell-like scripting:: For power users and developers -* Multi-boot manual config:: For non-standard multi-OS scenarios -* Embedded configuration:: Embedding a configuration file into GRUB +* Simple configuration:: Recommended for most users +* Shell-like scripting:: For power users and developers +* Multi-boot manual config:: For non-standard multi-OS scenarios +* Embedded configuration:: Embedding a configuration file into GRUB @end menu @@ -1324,12 +1307,12 @@ menu and then wait for the timeout set by @samp{GRUB_TIMEOUT} to expire before booting the default entry. Pressing a key interrupts the timeout. If this option is set to @samp{countdown} or @samp{hidden}, then, before -displaying the menu, GRUB will wait for the timeout set by @samp{GRUB_TIMEOUT} -to expire. If @key{ESC} or @key{F4} are pressed, or @key{SHIFT} is held down -during that time, it will display the menu and wait for input. If a hotkey -associated with a menu entry is pressed, it will boot the associated menu entry -immediately. If the timeout expires before either of these happens, it will -boot the default entry. In the @samp{countdown} case, it will show a one-line +displaying the menu, GRUB will wait for the timeout set by +@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during that time, it +will display the menu and wait for input. If a hotkey associated with a +menu entry is pressed, it will boot the associated menu entry immediately. +If the timeout expires before either of these happens, it will boot the +default entry. In the @samp{countdown} case, it will show a one-line indication of the remaining time. @item GRUB_DEFAULT_BUTTON @@ -1415,25 +1398,6 @@ for all respectively normal entries. The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries. -@item GRUB_EARLY_INITRD_LINUX_CUSTOM -@itemx GRUB_EARLY_INITRD_LINUX_STOCK -List of space-separated early initrd images to be loaded from @samp{/boot}. -This is for loading things like CPU microcode, firmware, ACPI tables, crypto -keys, and so on. These early images will be loaded in the order declared, -and all will be loaded before the actual functional initrd image. - -@samp{GRUB_EARLY_INITRD_LINUX_STOCK} is for your distribution to declare -images that are provided by the distribution. It should not be modified -without understanding the consequences. They will be loaded first. - -@samp{GRUB_EARLY_INITRD_LINUX_CUSTOM} is for your custom created images. - -The default stock images are as follows, though they may be overridden by -your distribution: -@example -intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio -@end example - @item GRUB_DISABLE_LINUX_UUID Normally, @command{grub-mkconfig} will generate menu entries that use universally-unique identifiers (UUIDs) to identify the root filesystem to @@ -1441,30 +1405,10 @@ the Linux kernel, using a @samp{root=UUID=...} kernel parameter. This is usually more reliable, but in some cases it may not be appropriate. To disable the use of UUIDs, set this option to @samp{true}. -@item GRUB_DISABLE_LINUX_PARTUUID -If @command{grub-mkconfig} cannot identify the root filesystem via its -universally-unique indentifier (UUID), @command{grub-mkconfig} can use the UUID -of the partition containing the filesystem to identify the root filesystem to -the Linux kernel via a @samp{root=PARTUUID=...} kernel parameter. This is not -as reliable as using the filesystem UUID, but is more reliable than using the -Linux device names. When @samp{GRUB_DISABLE_LINUX_PARTUUID} is set to -@samp{false}, the Linux kernel version must be 2.6.37 (3.10 for systems using -the MSDOS partition scheme) or newer. This option defaults to @samp{true}. To -enable the use of partition UUIDs, set this option to @samp{false}. - @item GRUB_DISABLE_RECOVERY If this option is set to @samp{true}, disable the generation of recovery mode menu entries. -@item GRUB_DISABLE_UUID -Normally, @command{grub-mkconfig} will generate menu entries that use -universally-unique identifiers (UUIDs) to identify various filesystems to -search for files. This is usually more reliable, but in some cases it may -not be appropriate. To disable this use of UUIDs, set this option to -@samp{true}. Setting this option to @samp{true}, will also set the options -@samp{GRUB_DISABLE_LINUX_UUID} and @samp{GRUB_DISABLE_LINUX_PARTUUID} to -@samp{true}, unless they have been explicilty set to @samp{false}. - @item GRUB_VIDEO_BACKEND If graphical video support is required, either because the @samp{gfxterm} graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, @@ -1519,7 +1463,7 @@ Normally, @command{grub-mkconfig} will generate top level menu entry for the kernel with highest version number and put all other found kernels or alternative menu entries for recovery mode in submenu. For entries returned by @command{os-prober} first entry will be put on top level and all others -in submenu. If this option is set to @samp{true}, flat menu with all entries +in submenu. If this option is set to @samp{y}, flat menu with all entries on top level will be generated instead. Changing this option will require changing existing values of @samp{GRUB_DEFAULT}, @samp{fallback} (@pxref{fallback}) and @samp{default} (@pxref{default}) environment variables as well as saved @@ -1553,16 +1497,16 @@ configurations, but have better replacements: @table @samp @item GRUB_HIDDEN_TIMEOUT -Wait this many seconds before displaying the menu. If @key{ESC} or @key{F4} are -pressed, or @key{SHIFT} is held down during that time, display the menu and wait -for input according to @samp{GRUB_TIMEOUT}. If a hotkey associated with a menu -entry is pressed, boot the associated menu entry immediately. If the timeout -expires before either of these happens, display the menu for the number of -seconds specified in @samp{GRUB_TIMEOUT} before booting the default entry. +Wait this many seconds before displaying the menu. If @key{ESC} is pressed +during that time, display the menu and wait for input according to +@samp{GRUB_TIMEOUT}. If a hotkey associated with a menu entry is pressed, +boot the associated menu entry immediately. If the timeout expires before +either of these happens, display the menu for the number of seconds +specified in @samp{GRUB_TIMEOUT} before booting the default entry. If you set @samp{GRUB_HIDDEN_TIMEOUT}, you should also set @samp{GRUB_TIMEOUT=0} so that the menu is not displayed at all unless -@key{ESC} or @key{F4} are pressed, or @key{SHIFT} is held down. +@key{ESC} is pressed. This option is unset by default, and is deprecated in favour of the less confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or @@ -1592,53 +1536,6 @@ edit the scripts in @file{/etc/grub.d} directly. menu entries; simply type the menu entries you want to add at the end of that file, making sure to leave at least the first two lines intact. -@node Root Identifcation Heuristics -@section Root Identifcation Heuristics -If the target operating system uses the Linux kernel, @command{grub-mkconfig} -attempts to identify the root file system via a heuristic algoirthm. This -algorithm selects the identification method of the root file system by -considering three factors. The first is if an initrd for the target operating -system is also present. The second is @samp{GRUB_DISABLE_LINUX_UUID} and if set -to @samp{true}, prevents @command{grub-mkconfig} from identifying the root file -system by its UUID. The third is @samp{GRUB_DISABLE_LINUX_PARTUUID} and if set -to @samp{true}, prevents @command{grub-mkconfig} from identifying the root file -system via the UUID of its enclosing partition. If the variables are assigned -any other value, that value is considered equivalent to @samp{false}. The -variables are also considered to be set to @samp{false} if they are not set. - -When booting, the Linux kernel will delegate the task of mounting the root -filesystem to the initrd. Most initrd images determine the root file system by -checking the Linux kernel's command-line for the @samp{root} key and use its -value as the identification method of the root file system. To improve the -reliability of booting, most initrd images also allow the root file system to be -identified by its UUID. Because of this behavior, the @command{grub-mkconfig} -command will set @samp{root} to @samp{root=UUID=...} to provide the initrd with -the filesystem UUID of the root file system. - -If no initrd is detected or @samp{GRUB_DISABLE_LINUX_UUID} is set to @samp{true} -then @command{grub-command} will identify the root filesystem by setting the -kernel command-line variable @samp{root} to @samp{root=PARTUUID=...} unless -@samp{GRUB_DISABLE_LINUX_PARTUUID} is also set to @samp{true}. If -@samp{GRUB_DISABLE_LINUX_PARTUUID} is also set to @samp{true}, -@command{grub-command} will identify by its Linux device name. - -The following table summarizes the behavior of the @command{grub-mkconfig} -command. - -@multitable {detected} {GRUB_DISABLE_LINUX_PARTUUID} {GRUB_DISABLE_LINUX_UUID} {Linux Root} -@headitem Initrd detected @tab GRUB_DISABLE_LINUX_PARTUUID Set To @tab GRUB_DISABLE_LINUX_UUID Set To @tab Linux Root ID Method -@item false @tab false @tab false @tab part UUID -@item false @tab false @tab true @tab part UUID -@item false @tab true @tab false @tab dev name -@item false @tab true @tab true @tab dev name -@item true @tab false @tab false @tab fs UUID -@item true @tab false @tab true @tab part UUID -@item true @tab true @tab false @tab fs UUID -@item true @tab true @tab true @tab dev name -@end multitable - -Remember, @samp{GRUB_DISABLE_LINUX_PARTUUID} and @samp{GRUB_DISABLE_LINUX_UUID} -are also considered to be set to @samp{false} when they are unset. @node Shell-like scripting @section Writing full configuration files directly @@ -2510,57 +2407,6 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 Then follow instructions printed out by grub-mknetdir on configuring your DHCP server. -The grub.cfg file is placed in the same directory as the path output by -grub-mknetdir hereafter referred to as FWPATH. GRUB will search for its -configuration files in order using the following rules where the appended -value corresponds to a value on the client machine. - -@example -@group -@samp{(FWPATH)}/grub.cfg-@samp{(UUID OF MACHINE)} -@samp{(FWPATH)}/grub.cfg-@samp{(MAC ADDRESS OF NIC)} -@samp{(FWPATH)}/grub.cfg-@samp{(IPv4 OR IPv6 ADDRESS)} -@samp{(FWPATH)}/grub.cfg -@end group -@end example - -The UUID is the Client Machine Identifier Option Definition as specified in -RFC 4578. The client will only attempt to loouk up a UUID config file if it -was provided by the DHCP server. - -The client will only attempt to look up an IPv6 address config once, however, -it will try the IPv4 multiple times. The concrete example below shows what -would happen under the IPv4 case. - -@example -@group -UUID: 7726a678-7fc0-4853-a4f6-c85ac36a120a -MAC: 52:54:00:ec:33:81 -IPV4: 10.0.0.130 (0A000082) -@end group -@end example - -@example -@group -@samp{(FWPATH)}/grub.cfg-7726a678-7fc0-4853-a4f6-c85ac36a120a -@samp{(FWPATH)}/grub.cfg-52-54-00-ec-33-81 -@samp{(FWPATH)}/grub.cfg-0A000082 -@samp{(FWPATH)}/grub.cfg-0A00008 -@samp{(FWPATH)}/grub.cfg-0A0000 -@samp{(FWPATH)}/grub.cfg-0A000 -@samp{(FWPATH)}/grub.cfg-0A00 -@samp{(FWPATH)}/grub.cfg-0A0 -@samp{(FWPATH)}/grub.cfg-0A -@samp{(FWPATH)}/grub.cfg-0 -@samp{(FWPATH)}/grub.cfg -@end group -@end example - -This feature is enabled by default but it can be disabled by setting the -@samp{feature_net_search_cfg} to @samp{n}. Since this happens before the -configuration file is read by GRUB, this option has to be disabled in an -embedded configuration file (@pxref{Embedded configuration}). - After GRUB has started, files on the TFTP server will be accessible via the @samp{(tftp)} device. @@ -2600,10 +2446,6 @@ The boot file name provided by DHCP. Read-only. The name of the DHCP server responsible for these boot parameters. Read-only. -@item net_@var{}_next_server -The IP address of the next (usually, TFTP) server provided by DHCP. -Read-only. - @item net_default_interface Initially set to name of network interface that was used to load grub. Read-write, although setting it affects only interpretation of @@ -2696,8 +2538,6 @@ team are: 85:3 @item Asus EeePC 1005PE 84:1 (unconfirmed) -@item LENOVO ThinkPad T410s (2912W1C) -101:3 @end table To take full advantage of this function, install GRUB into the MBR @@ -3198,8 +3038,6 @@ These variables have special meaning to GRUB. * cmdpath:: * color_highlight:: * color_normal:: -* config_directory:: -* config_file:: * debug:: * default:: * fallback:: @@ -3220,7 +3058,6 @@ These variables have special meaning to GRUB. * net_@var{}_hostname:: * net_@var{}_ip:: * net_@var{}_mac:: -* net_@var{}_next_server:: * net_@var{}_rootpath:: * net_default_interface:: * net_default_ip:: @@ -3343,22 +3180,6 @@ matching colors of first half. to support whole rgb24 palette but currently there is no compelling reason to go beyond the current 16 colors. - -@node config_directory -@subsection config_directory - -This variable is automatically set by GRUB to the directory part of -current configuration file name (@pxref{config_file}). - - -@node config_file -@subsection config_file - -This variable is automatically set by GRUB to the name of configuration file that is being -processed by commands @command{configfile} (@pxref{configfile}) or @command{normal} -(@pxref{normal}). It is restored to the previous value when command completes. - - @node debug @subsection debug @@ -3372,10 +3193,9 @@ source for more details. @node default @subsection default -If this variable is set, it identifies a menu entry that should be -selected by default, possibly after a timeout (@pxref{timeout}). The -entry may be identified by number (starting from 0 at each level of -the hierarchy), by title, or by id. +If this variable is set, it identifies a menu entry that should be selected +by default, possibly after a timeout (@pxref{timeout}). The entry may be +identified by number or by id. For example, if you have: @@ -3391,26 +3211,24 @@ then you can make this the default using: default=example-gnu-linux @end example -If the entry is in a submenu, then it must be identified using the -number, title, or id of each of the submenus starting from the top -level, followed by the number, title, or id of the menu entry itself, -with each element separated by @samp{>}. For example, take the -following menu structure: +If the entry is in a submenu, then it must be identified using the titles of +each of the submenus starting from the top level followed by the number or +title of the menu entry itself, separated by @samp{>}. For example, take +the following menu structure: @example -GNU/Hurd --id gnu-hurd - Standard Boot --id=gnu-hurd-std - Rescue shell --id=gnu-hurd-rescue -Other platforms --id=other - Minix --id=minix - Version 3.4.0 --id=minix-3.4.0 - Version 3.3.0 --id=minix-3.3.0 - GRUB Invaders --id=grub-invaders +Submenu 1 + Menu Entry 1 + Menu Entry 2 +Submenu 2 + Submenu 3 + Menu Entry 3 + Menu Entry 4 + Menu Entry 5 @end example -The more recent release of Minix would then be identified as -@samp{Other platforms>Minix>Version 3.4.0}, or as @samp{1>0>0}, or as -@samp{other>minix>minix-3.4.0}. +``Menu Entry 3'' would then be identified as +@samp{Submenu 2>Submenu 3>Menu Entry 3}. This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple configuration}), @command{grub-set-default}, or @command{grub-reboot}. @@ -3584,12 +3402,6 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}). @xref{Network}. -@node net_@var{}_next_server -@subsection net_@var{}_next_server - -@xref{Network}. - - @node net_@var{}_rootpath @subsection net_@var{}_rootpath @@ -4005,7 +3817,7 @@ you forget a command, you can run the command @command{help} * password_pbkdf2:: Set a hashed password * play:: Play a tune * probe:: Retrieve device info -* rdmsr:: Read values from model-specific registers +* pxe_unload:: Unload the PXE environment * read:: Read user input * reboot:: Reboot your computer * regexp:: Test if regular expression matches string @@ -4018,19 +3830,15 @@ you forget a command, you can run the command @command{help} * sha256sum:: Compute or check SHA256 hash * sha512sum:: Compute or check SHA512 hash * sleep:: Wait for a specified number of seconds -* smbios:: Retrieve SMBIOS information * source:: Read a configuration file in same context * test:: Check file types and compare values * true:: Do nothing, successfully * trust:: Add public key to list of trusted keys * unset:: Unset an environment variable +* uppermem:: Set the upper memory size @comment * vbeinfo:: List available video modes * verify_detached:: Verify detached digital signature * videoinfo:: List available video modes -@comment * xen_*:: Xen boot commands for AArch64 -* wrmsr:: Write values to model-specific registers -* xen_hypervisor:: Load xen hypervisor binary (only on AArch64) -* xen_module:: Load xen modules for xen hypervisor (only on AArch64) @end menu @@ -4242,15 +4050,12 @@ after @command{configfile} returns. @node cpuid @subsection cpuid -@deffn Command cpuid [-l] [-p] +@deffn Command cpuid [-l] Check for CPU features. This command is only available on x86 systems. With the @option{-l} option, return true if the CPU supports long mode (64-bit). -With the @option{-p} option, return true if the CPU supports Physical -Address Extension (PAE). - If invoked without options, this command currently behaves as if it had been invoked with @option{-l}. This may change in the future. @end deffn @@ -4275,9 +4080,8 @@ is requested interactively. Option @var{device} configures specific grub device with specified @var{uuid}; option @option{-a} configures all detected encrypted devices; option @option{-b} configures all geli containers that have boot flag set. -GRUB suports devices encrypted using LUKS, LUKS2 and geli. Note that necessary -modules (@var{luks}, @var{luks2} and @var{geli}) have to be loaded manually -before this command can be used. +GRUB suports devices encrypted using LUKS and geli. Note that necessary modules (@var{luks} and @var{geli}) have to be loaded manually before this command can +be used. @end deffn @@ -4295,12 +4099,13 @@ hour, minute, and second unchanged. @node devicetree -@subsection devicetree +@subsection linux @deffn Command devicetree file Load a device tree blob (.dtb) from a filesystem, for later use by a Linux kernel. Does not perform merging with any device tree supplied by firmware, but rather replaces it completely. +@ref{GNU/Linux}. @end deffn @node distrust @@ -4497,22 +4302,22 @@ about each of the commands whose names begin with those @var{patterns}. @node initrd @subsection initrd -@deffn Command initrd file [file @dots{}] -Load, in order, all initial ramdisks for a Linux kernel image, and set -the appropriate parameters in the Linux setup area in memory. This may only -be used after the @command{linux} command (@pxref{linux}) has been run. See -also @ref{GNU/Linux}. +@deffn Command initrd file +Load an initial ramdisk for a Linux kernel image, and set the appropriate +parameters in the Linux setup area in memory. This may only be used after +the @command{linux} command (@pxref{linux}) has been run. See also +@ref{GNU/Linux}. @end deffn @node initrd16 @subsection initrd16 -@deffn Command initrd16 file [file @dots{}] -Load, in order, all initial ramdisks for a Linux kernel image to be booted in -16-bit mode, and set the appropriate parameters in the Linux setup area in -memory. This may only be used after the @command{linux16} command -(@pxref{linux16}) has been run. See also @ref{GNU/Linux}. +@deffn Command initrd16 file +Load an initial ramdisk for a Linux kernel image to be booted in 16-bit +mode, and set the appropriate parameters in the Linux setup area in memory. +This may only be used after the @command{linux16} command (@pxref{linux16}) +has been run. See also @ref{GNU/Linux}. This command is only available on x86 systems. @end deffn @@ -4720,7 +4525,7 @@ be reloaded after using this command (@pxref{module}). Some kernels have known problems. You need to specify --quirk-* for those. --quirk-bad-kludge is a problem seen in several products that they include loading kludge information with invalid data in ELF file. GRUB prior to 0.97 -and some custom builds preferred ELF information while 0.97 and GRUB 2 +and some custom builds prefered ELF information while 0.97 and GRUB 2 use kludge. Use this option to ignore kludge. Known affected systems: old Solaris, SkyOS. @@ -4798,7 +4603,7 @@ range 0-0xFF (prefix with @samp{0x} to enter it in hexadecimal). When enabled, this hides the selected partition by setting the @dfn{hidden} bit in its partition type code; when disabled, unhides the selected partition by clearing this bit. This is useful only when booting DOS or -Windows and multiple primary FAT partitions exist in one disk. See also +Wwindows and multiple primary FAT partitions exist in one disk. See also @ref{DOS/Windows}. @end table @end deffn @@ -4845,29 +4650,19 @@ a rest. @node probe @subsection probe -@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} device +@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} device Retrieve device information. If option @option{--set} is given, assign result to variable @var{var}, otherwise print information on the screen. - -The option @option{--part-uuid} is currently only implemented for MSDOS and GPT formatted disks. @end deffn -@node rdmsr -@subsection rdmsr +@node pxe_unload +@subsection pxe_unload -@deffn Command: rdmsr 0xADDR [-v VARNAME] -Read a model-specific register at address 0xADDR. If the parameter -@option{-v} is used and an environment variable @var{VARNAME} is -given, set that environment variable to the value that was read. +@deffn Command pxe_unload +Unload the PXE environment (@pxref{Network}). -Please note that on SMP systems, reading from a MSR that has a -scope per hardware thread, implies that the value that is returned -only applies to the particular cpu/core/thread that runs the command. - -Also, if you specify a reserved or unimplemented MSR address, it will -cause a general protection exception (which is not currently being handled) -and the system will reboot. +This command is only available on PC BIOS systems. @end deffn @@ -5143,84 +4938,9 @@ Alias for @code{hashsum --hash sha512 arg @dots{}}. See command @command{hashsum @deffn Command sleep [@option{--verbose}] [@option{--interruptible}] count Sleep for @var{count} seconds. If option @option{--interruptible} is given, -allow pressing @key{ESC}, @key{F4} or holding down @key{SHIFT} to interrupt -sleep. With @option{--verbose} show countdown of remaining seconds. Exit code -is set to 0 if timeout expired and to 1 if timeout was interrupted using any -of the mentioned keys. -@end deffn - - -@node smbios -@subsection smbios - -@deffn Command smbios @ - [@option{--type} @var{type}] @ - [@option{--handle} @var{handle}] @ - [@option{--match} @var{match}] @ - (@option{--get-byte} | @option{--get-word} | @option{--get-dword} | @ - @option{--get-qword} | @option{--get-string} | @option{--get-uuid}) @ - @var{offset} @ - [@option{--set} @var{variable}] -Retrieve SMBIOS information. - -The @command{smbios} command returns the value of a field in an SMBIOS -structure. The following options determine which structure to select. - -@itemize @bullet -@item -Specifying @option{--type} will select structures with a matching -@var{type}. The type can be any integer from 0 to 255. -@item -Specifying @option{--handle} will select structures with a matching -@var{handle}. The handle can be any integer from 0 to 65535. -@item -Specifying @option{--match} will select structure number @var{match} in the -filtered list of structures; e.g. @code{smbios --type 4 --match 2} will select -the second Process Information (Type 4) structure. The list is always ordered -the same as the hardware's SMBIOS table. The match number must be a positive -integer. If unspecified, the first matching structure will be selected. -@end itemize - -The remaining options determine which field in the selected SMBIOS structure to -return. Only one of these options may be specified at a time. - -@itemize @bullet -@item -When given @option{--get-byte}, return the value of the byte -at @var{offset} bytes into the selected SMBIOS structure. -It will be formatted as an unsigned decimal integer. -@item -When given @option{--get-word}, return the value of the word (two bytes) -at @var{offset} bytes into the selected SMBIOS structure. -It will be formatted as an unsigned decimal integer. -@item -When given @option{--get-dword}, return the value of the dword (four bytes) -at @var{offset} bytes into the selected SMBIOS structure. -It will be formatted as an unsigned decimal integer. -@item -When given @option{--get-qword}, return the value of the qword (eight bytes) -at @var{offset} bytes into the selected SMBIOS structure. -It will be formatted as an unsigned decimal integer. -@item -When given @option{--get-string}, return the string with its index found -at @var{offset} bytes into the selected SMBIOS structure. -@item -When given @option{--get-uuid}, return the value of the UUID (sixteen bytes) -at @var{offset} bytes into the selected SMBIOS structure. -It will be formatted as lower-case hyphenated hexadecimal digits, with the -first three fields as little-endian, and the rest printed byte-by-byte. -@end itemize - -The default action is to print the value of the requested field to the console, -but a variable name can be specified with @option{--set} to store the value -instead of printing it. - -For example, this will store and then display the system manufacturer's name. - -@example -smbios --type 1 --get-string 4 --set system_manufacturer -echo $system_manufacturer -@end example +allow @key{ESC} to interrupt sleep. With @option{--verbose} show countdown +of remaining seconds. Exit code is set to 0 if timeout expired and to 1 +if timeout was interrupted by @key{ESC}. @end deffn @@ -5299,8 +5019,6 @@ the length of @var{string} is zero @var{expression} is false @item @var{expression1} @code{-a} @var{expression2} both @var{expression1} and @var{expression2} are true -@item @var{expression1} @var{expression2} -both @var{expression1} and @var{expression2} are true. This syntax is not POSIX-compliant and is not recommended. @item @var{expression1} @code{-o} @var{expression2} either @var{expression1} or @var{expression2} is true @end table @@ -5340,6 +5058,12 @@ Unset the environment variable @var{envvar}. @end deffn +@node uppermem +@subsection uppermem + +This command is not yet implemented for GRUB 2, although it is planned. + + @ignore @node vbeinfo @subsection vbeinfo @@ -5378,44 +5102,6 @@ successfully. If validation fails, it is set to a non-zero value. List available video modes. If resolution is given, show only matching modes. @end deffn -@node wrmsr -@subsection wrmsr - -@deffn Command: wrmsr 0xADDR 0xVALUE -Write a 0xVALUE to a model-specific register at address 0xADDR. - -Please note that on SMP systems, writing to a MSR that has a scope -per hardware thread, implies that the value that is written -only applies to the particular cpu/core/thread that runs the command. - -Also, if you specify a reserved or unimplemented MSR address, it will -cause a general protection exception (which is not currently being handled) -and the system will reboot. -@end deffn - -@node xen_hypervisor -@subsection xen_hypervisor - -@deffn Command xen_hypervisor file [arguments] @dots{} -Load a Xen hypervisor binary from @var{file}. The rest of the line is passed -verbatim as the @dfn{kernel command-line}. Any other binaries must be -reloaded after using this command. -This command is only available on AArch64 systems. -@end deffn - -@node xen_module -@subsection xen_module - -@deffn Command xen_module [--nounzip] file [arguments] -Load a module for xen hypervisor at the booting process of xen. -The rest of the line is passed verbatim as the module command line. -Modules should be loaded in the following order: - - dom0 kernel image - - dom0 ramdisk if present - - XSM policy if present -This command is only available on AArch64 systems. -@end deffn - @node Networking commands @section The list of networking commands @@ -5423,11 +5109,10 @@ This command is only available on AArch64 systems. * net_add_addr:: Add a network address * net_add_dns:: Add a DNS server * net_add_route:: Add routing entry -* net_bootp:: Perform a bootp/DHCP autoconfiguration +* net_bootp:: Perform a bootp autoconfiguration * net_del_addr:: Remove IP address from interface * net_del_dns:: Remove a DNS server * net_del_route:: Remove a route entry -* net_dhcp:: Perform a DHCP autoconfiguration * net_get_dhcp_option:: Retrieve DHCP options * net_ipv6_autoconf:: Perform IPv6 autoconfiguration * net_ls_addr:: List interfaces @@ -5474,9 +5159,33 @@ by @var{shortname} which can be used to remove it (@pxref{net_del_route}). @subsection net_bootp @deffn Command net_bootp [@var{card}] -Alias for net_dhcp, for compatibility with older Grub versions. Will perform -the same DHCP handshake with potential fallback to BOOTP as the net_dhcp -command (@pxref{net_dhcp}). +Perform configuration of @var{card} using DHCP protocol. If no card name +is specified, try to configure all existing cards. If configuration was +successful, interface with name @var{card}@samp{:dhcp} and configured +address is added to @var{card}. If server provided gateway information in +DHCP ACK packet, it is added as route entry with the name @var{card}@samp{:dhcp:gw}. Additionally the following DHCP options are recognized and processed: + +@table @samp +@item 1 (Subnet Mask) +Used to calculate network local routing entry for interface @var{card}@samp{:dhcp}. +@item 3 (Router) +Adds default route entry with the name @var{card}@samp{:dhcp:default} via gateway +from DHCP option. Note that only option with single route is accepted. +@item 6 (Domain Name Server) +Adds all servers from option value to the list of servers used during name resolution. +@item 12 (Host Name) +Sets environment variable @samp{net_}@var{}@samp{_dhcp_hostname} +(@pxref{net_@var{}_hostname}) to the value of option. +@item 15 (Domain Name) +Sets environment variable @samp{net_}@var{}@samp{_dhcp_domain} +(@pxref{net_@var{}_domain}) to the value of option. +@item 17 (Root Path) +Sets environment variable @samp{net_}@var{}@samp{_dhcp_rootpath} +(@pxref{net_@var{}_rootpath}) to the value of option. +@item 18 (Extensions Path) +Sets environment variable @samp{net_}@var{}@samp{_dhcp_extensionspath} +(@pxref{net_@var{}_extensionspath}) to the value of option. +@end table @end deffn @@ -5505,50 +5214,6 @@ Remove route entry identified by @var{shortname}. @end deffn -@node net_dhcp -@subsection net_dhcp - -@deffn Command net_dhcp [@var{card}] -Perform configuration of @var{card} using DHCP protocol. If no card name -is specified, try to configure all existing cards. -Falls back to the BOOTP protocol, if needed. If configuration was -successful, interface with name @var{card}@samp{:dhcp} and configured -address is added to @var{card}. -@comment If server provided gateway information in -@comment DHCP ACK packet, it is added as route entry with the name @var{card}@samp{:dhcp:gw}. -Additionally the following DHCP options are recognized and processed: - -@table @samp -@item 1 (Subnet Mask) -Used to calculate network local routing entry for interface @var{card}@samp{:dhcp}. -@item 3 (Router) -Adds default route entry with the name @var{card}@samp{:dhcp:default} via gateway -from DHCP option. Note that only option with single route is accepted. -@item 6 (Domain Name Server) -Adds all servers from option value to the list of servers used during name resolution. -@item 12 (Host Name) -Sets environment variable @samp{net_}@var{}@samp{_dhcp_hostname} -(@pxref{net_@var{}_hostname}) to the value of option. -@item 15 (Domain Name) -Sets environment variable @samp{net_}@var{}@samp{_dhcp_domain} -(@pxref{net_@var{}_domain}) to the value of option. -@item 17 (Root Path) -Sets environment variable @samp{net_}@var{}@samp{_dhcp_rootpath} -(@pxref{net_@var{}_rootpath}) to the value of option. -@item 18 (Extensions Path) -Sets environment variable @samp{net_}@var{}@samp{_dhcp_extensionspath} -(@pxref{net_@var{}_extensionspath}) to the value of option. -@item 66 (TFTP Server Name) -Sets environment variable @samp{net_}@var{}@samp{_dhcp_server_name} -(@pxref{net_@var{}_dhcp_server_name}) to the value of option. -@item 67 (Filename) -Sets environment variable @samp{net_}@var{}@samp{_boot_file} -(@pxref{net_@var{}_boot_file}) to the value of option. -@end table - -@end deffn - - @node net_get_dhcp_option @subsection net_get_dhcp_option @@ -5624,7 +5289,7 @@ NTFS, JFS, UDF, HFS+, exFAT, long filenames in FAT, Joliet part of ISO9660 are treated as UTF-16 as per specification. AFS and BFS are read as UTF-8, again according to specification. BtrFS, cpio, tar, squash4, minix, minix2, minix3, ROMFS, ReiserFS, XFS, ext2, ext3, ext4, FAT (short names), -F2FS, RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed +RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed to be UTF-8. This might be false on systems configured with legacy charset but as long as the charset used is superset of ASCII you should be able to access ASCII-named files. And it's recommended to configure your system to use @@ -5733,8 +5398,6 @@ environment variables and commands are listed in the same order. @menu * Authentication and authorisation:: Users and access control * Using digital signatures:: Booting digitally signed code -* UEFI secure boot and shim:: Booting digitally signed PE files -* Measured Boot:: Measuring boot components @end menu @node Authentication and authorisation @@ -5763,13 +5426,10 @@ In order to enable authentication support, the @samp{superusers} environment variable must be set to a list of usernames, separated by any of spaces, commas, semicolons, pipes, or ampersands. Superusers are permitted to use the GRUB command line, edit menu entries, and execute any menu entry. If -@samp{superusers} is set, then use of the command line and editing of menu -entries are automatically restricted to superusers. Setting @samp{superusers} -to empty string effectively disables both access to CLI and editing of menu -entries. Note: The environment variable needs to be exported to also affect -the section defined by the @samp{submenu} command (@pxref{submenu}). +@samp{superusers} is set, then use of the command line is automatically +restricted to superusers. -Other users may be allowed to execute specific menu entries by giving a list of +Other users may be given access to specific menu entries by giving a list of usernames (as above) using the @option{--users} option to the @samp{menuentry} command (@pxref{menuentry}). If the @option{--unrestricted} option is used for a menu entry, then that entry is unrestricted. @@ -5898,57 +5558,6 @@ or BIOS) configuration to cause the machine to boot from a different (attacker-controlled) device. GRUB is at best only one link in a secure boot chain. -@node UEFI secure boot and shim -@section UEFI secure boot and shim support - -The GRUB, except the @command{chainloader} command, works with the UEFI secure -boot and the shim. This functionality is provided by the shim_lock module. It -is recommend to build in this and other required modules into the @file{core.img}. -All modules not stored in the @file{core.img} and the ACPI tables for the -@command{acpi} command have to be signed, e.g. using PGP. Additionally, the -@command{iorw}, the @command{memrw} and the @command{wrmsr} commands are -prohibited if the UEFI secure boot is enabled. This is done due to -security reasons. All above mentioned requirements are enforced by the -shim_lock module. And itself it is a persistent module which means that -it cannot be unloaded if it was loaded into the memory. - -@node Measured Boot -@section Measuring boot components - -If the tpm module is loaded and the platform has a Trusted Platform Module -installed, GRUB will log each command executed and each file loaded into the -TPM event log and extend the PCR values in the TPM correspondingly. All events -will be logged into the PCR described below with a type of EV_IPL and an -event description as described below. - -@multitable @columnfractions 0.3 0.1 0.6 -@headitem Event type @tab PCR @tab Description -@item Command -@tab 8 -@tab All executed commands (including those from configuration files) will be -logged and measured as entered with a prefix of ``grub_cmd: `` -@item Kernel command line -@tab 8 -@tab Any command line passed to a kernel will be logged and measured as entered -with a prefix of ``kernel_cmdline: '' -@item Module command line -@tab 8 -@tab Any command line passed to a kernel module will be logged and measured as -entered with a prefix of ``module_cmdline: `` -@item Files -@tab 9 -@tab Any file read by GRUB will be logged and measured with a descriptive text -corresponding to the filename. -@end multitable - -GRUB will not measure its own @file{core.img} - it is expected that firmware -will carry this out. GRUB will also not perform any measurements until the -tpm module is loaded. As such it is recommended that the tpm module be built -into @file{core.img} in order to avoid a potential gap in measurement between -@file{core.img} being loaded and the tpm module being loaded. - -Measured boot is currently only supported on EFI platforms. - @node Platform limitations @chapter Platform limitations @@ -6000,16 +5609,6 @@ BadRAM is the ability to mark some of the RAM as ``bad''. Note: due to protocol limitations mips-loongson (with Linux protocol) and mips-qemu_mips can use only memory up to first hole. -Bootlocation is ability of GRUB to automatically detect where it boots from. -``disk'' means the detection is limited to detecting the disk with partition -being discovered on install time. ``partition'' means that disk and partiton -can be automatically discovered. ``file'' means that boot image file name as -well as disk and partition can be discovered. For consistency default install ignores -partition and relies solely on disk detection. If no bootlocation discovery is available -or boot and grub-root disks are different, UUID is used instead. On ARC if no device -to install to is specified, UUID is used instead as well. - - @multitable @columnfractions .20 .20 .20 .20 .20 @item @tab BIOS @tab Coreboot @tab Multiboot @tab Qemu @item video @tab yes @tab yes @tab yes @tab yes @@ -6021,14 +5620,11 @@ to install to is specified, UUID is used instead as well. @item USB @tab yes @tab yes @tab yes @tab yes @item chainloader @tab local @tab yes @tab yes @tab no @item cpuid @tab partial @tab partial @tab partial @tab partial -@item rdmsr @tab partial @tab partial @tab partial @tab partial -@item wrmsr @tab partial @tab partial @tab partial @tab partial @item hints @tab guess @tab guess @tab guess @tab guess @item PCI @tab yes @tab yes @tab yes @tab yes @item badram @tab yes @tab yes @tab yes @tab yes @item compression @tab always @tab pointless @tab no @tab no @item exit @tab yes @tab no @tab no @tab no -@item bootlocation @tab disk @tab no @tab no @tab no @end multitable @multitable @columnfractions .20 .20 .20 .20 .20 @@ -6042,14 +5638,11 @@ to install to is specified, UUID is used instead as well. @item USB @tab yes @tab yes @tab yes @tab no @item chainloader @tab local @tab local @tab no @tab local @item cpuid @tab partial @tab partial @tab partial @tab no -@item rdmsr @tab partial @tab partial @tab partial @tab no -@item wrmsr @tab partial @tab partial @tab partial @tab no @item hints @tab guess @tab guess @tab good @tab guess @item PCI @tab yes @tab yes @tab yes @tab no @item badram @tab yes @tab yes @tab no @tab yes @item compression @tab no @tab no @tab no @tab no @item exit @tab yes @tab yes @tab yes @tab yes -@item bootlocation @tab file @tab file @tab file, ignored @tab file @end multitable @multitable @columnfractions .20 .20 .20 .20 .20 @@ -6063,35 +5656,29 @@ to install to is specified, UUID is used instead as well. @item USB @tab yes @tab no @tab no @tab no @item chainloader @tab yes @tab no @tab no @tab no @item cpuid @tab no @tab no @tab no @tab no -@item rdmsr @tab no @tab no @tab no @tab no -@item wrmsr @tab no @tab no @tab no @tab no @item hints @tab good @tab good @tab good @tab no @item PCI @tab yes @tab no @tab no @tab no @item badram @tab yes (*) @tab no @tab no @tab no @item compression @tab configurable @tab no @tab no @tab configurable @item exit @tab no @tab yes @tab yes @tab yes -@item bootlocation @tab no @tab partition @tab file @tab file (*) @end multitable @multitable @columnfractions .20 .20 .20 .20 .20 -@item @tab MIPS qemu @tab emu @tab xen -@item video @tab no @tab yes @tab no -@item console charset @tab CP437 @tab Unicode (*) @tab ASCII -@item network @tab no @tab yes @tab no -@item ATA/AHCI @tab yes @tab no @tab no -@item AT keyboard @tab yes @tab no @tab no -@item Speaker @tab no @tab no @tab no -@item USB @tab N/A @tab yes @tab no -@item chainloader @tab yes @tab no @tab yes -@item cpuid @tab no @tab no @tab yes -@item rdmsr @tab no @tab no @tab yes -@item wrmsr @tab no @tab no @tab yes -@item hints @tab guess @tab no @tab no -@item PCI @tab no @tab no @tab no -@item badram @tab yes (*) @tab no @tab no -@item compression @tab configurable @tab no @tab no -@item exit @tab no @tab yes @tab no -@item bootlocation @tab no @tab file @tab no +@item @tab MIPS qemu @tab emu +@item video @tab no @tab yes +@item console charset @tab CP437 @tab Unicode (*) +@item network @tab no @tab yes +@item ATA/AHCI @tab yes @tab no +@item AT keyboard @tab yes @tab no +@item Speaker @tab no @tab no +@item USB @tab N/A @tab yes +@item chainloader @tab yes @tab no +@item cpuid @tab no @tab no +@item hints @tab guess @tab no +@item PCI @tab no @tab no +@item badram @tab yes (*) @tab no +@item compression @tab configurable @tab no +@item exit @tab no @tab yes @end multitable @node Platform-specific operations @@ -6261,7 +5848,7 @@ Following variables must be defined: @multitable @columnfractions .30 .65 @item GRUB_PAYLOADS_DIR @tab directory containing the required kernels -@item GRUB_CBFSTOOL @tab cbfstool from Coreboot package (for coreboot platform only) +@item GRUB_CBFSTOOL @tab cbfstoll from Coreboot package (for coreboot platform only) @item GRUB_COREBOOT_ROM @tab empty Coreboot ROM @item GRUB_QEMU_OPTS @tab additional options to be supplied to QEMU @end multitable @@ -6286,7 +5873,6 @@ Required files are: @menu * GRUB only offers a rescue shell:: -* Firmware stalls instead of booting GRUB:: @end menu @@ -6357,17 +5943,6 @@ support has not yet been added to GRUB. @end itemize -@node Firmware stalls instead of booting GRUB -@section Firmware stalls instead of booting GRUB - -The EFI implementation of some older MacBook laptops stalls when it gets -presented a grub-mkrescue ISO image for x86_64-efi target on an USB stick. -Affected are models of year 2010 or earlier. Workaround is to zeroize the -bytes 446 to 461 of the EFI partition, where mformat has put a partition table -entry which claims partition start at block 0. This change will not hamper -bootability on other machines. - - @node Invoking grub-install @chapter Invoking grub-install diff --git a/gentpl.py b/gentpl.py index c86550d4f..bdcae1a1c 100644 --- a/gentpl.py +++ b/gentpl.py @@ -28,11 +28,10 @@ import re GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275", "x86_64_efi", - "i386_xen", "x86_64_xen", "i386_xen_pvh", + "i386_xen", "x86_64_xen", "mips_loongson", "sparc64_ieee1275", "powerpc_ieee1275", "mips_arc", "ia64_efi", - "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi", - "arm_coreboot", "riscv32_efi", "riscv64_efi" ] + "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi" ] GROUPS = {} @@ -45,18 +44,14 @@ GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"] GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ] GROUPS["sparc64"] = [ "sparc64_ieee1275" ] GROUPS["powerpc"] = [ "powerpc_ieee1275" ] -GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ] +GROUPS["arm"] = [ "arm_uboot", "arm_efi" ] GROUPS["arm64"] = [ "arm64_efi" ] -GROUPS["riscv32"] = [ "riscv32_efi" ] -GROUPS["riscv64"] = [ "riscv64_efi" ] # Groups based on firmware -GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", - "riscv32_efi", "riscv64_efi" ] +GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ] GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] GROUPS["uboot"] = [ "arm_uboot" ] GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ] -GROUPS["coreboot"] = [ "i386_coreboot", "arm_coreboot" ] # emu is a special case so many core functionality isn't needed on this platform GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu") @@ -66,28 +61,22 @@ GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips", "sparc64_ieee1275", "powerpc_ieee1275"] GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi"); GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"] -GROUPS["usb"] = GROUPS["pci"] + ["arm_coreboot"] +GROUPS["usb"] = GROUPS["pci"] # If gfxterm is main output console integrate it into kernel -GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ] +GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot" ] GROUPS["videomodules"] = GRUB_PLATFORMS[:]; for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i) # Similar for terminfo -GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips", "i386_xen_pvh" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"]; +GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"]; GROUPS["terminfomodule"] = GRUB_PLATFORMS[:]; for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i) # Flattened Device Trees (FDT) -GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ] +GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi" ] -# Needs software helpers for division -# Must match GRUB_DIVISION_IN_SOFTWARE in misc.h -GROUPS["softdiv"] = GROUPS["arm"] + ["ia64_efi"] + GROUPS["riscv32"] -GROUPS["no_softdiv"] = GRUB_PLATFORMS[:] -for i in GROUPS["softdiv"]: GROUPS["no_softdiv"].remove(i) - -# Miscellaneous groups scheduled to disappear in future +# Miscelaneous groups schedulded to disappear in future GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"] GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc") @@ -611,7 +600,7 @@ def foreach_enabled_platform(defn, closure): # enable = emu; # enable = i386; # enable = mips_loongson; -# emu_condition = COND_GRUB_EMU_SDL; +# emu_condition = COND_GRUB_EMU_USB; # }; # def under_platform_specific_conditionals(defn, platform, closure): @@ -734,11 +723,9 @@ def kernel(defn, platform): """if test x$(TARGET_APPLE_LINKER) = x1; then \ $(TARGET_STRIP) -S -x $(""" + cname(defn) + """) -o $@.bin $<; \ $(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -ed2016 -wd1106 -nu -nd $@.bin $@; \ - rm -f $@.bin; \ elif test ! -z '$(TARGET_OBJ2ELF)'; then \ """ + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@.bin $< && \ $(TARGET_OBJ2ELF) $@.bin $@ || (rm -f $@; rm -f $@.bin; exit 1); \ - rm -f $@.bin; \ else """ + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@ $<; \ fi""")) @@ -766,7 +753,7 @@ def image(defn, platform): if test x$(TARGET_APPLE_LINKER) = x1; then \ $(MACHO2IMG) $< $@; \ else \ - $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property -R .ARM.exidx $< $@; \ + $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; \ fi """) @@ -841,20 +828,6 @@ def data(defn, platform): var_add("dist_" + installdir(defn) + "_DATA", platform_sources(defn, platform)) gvar_add("dist_noinst_DATA", extra_dist(defn)) -def transform_data(defn, platform): - name = defn['name'] - - var_add(installdir(defn) + "_DATA", name) - - rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """ -(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:- -chmod a+x """ + name + """ -""") - - gvar_add("CLEANFILES", name) - gvar_add("EXTRA_DIST", extra_dist(defn)) - gvar_add("dist_noinst_DATA", platform_sources(defn, platform)) - def script(defn, platform): name = defn['name'] @@ -902,7 +875,6 @@ rules("library", library) rules("program", program) rules("script", script) rules("data", data) -rules("transform_data", transform_data) write_output(section='decl') write_output() diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 3ea8e7ff4..5c087c83b 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -39,10 +39,6 @@ gentrigtables$(BUILD_EXEEXT): gentrigtables.c $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $< $(BUILD_LIBM) CLEANFILES += gentrigtables$(BUILD_EXEEXT) -build-grub-module-verifier$(BUILD_EXEEXT): $(top_srcdir)/util/grub-module-verifier.c $(top_srcdir)/util/grub-module-verifier32.c $(top_srcdir)/util/grub-module-verifier64.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c - $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-module-verifier\" $^ -CLEANFILES += build-grub-module-verifier$(BUILD_EXEEXT) - # trigtables.c trigtables.c: gentrigtables$(BUILD_EXEEXT) gentrigtables.c $(top_srcdir)/configure.ac ./gentrigtables$(BUILD_EXEEXT) > $@ @@ -80,11 +76,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h -if COND_emu -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h -else -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h -endif KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h @@ -92,6 +83,9 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h +if !COND_clang +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h +endif KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h if COND_i386_pc @@ -101,44 +95,25 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h endif -if COND_i386_xen_pvh -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h -endif - if COND_i386_efi -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h endif if COND_i386_coreboot -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/coreboot/lbio.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h endif if COND_i386_multiboot -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h endif if COND_i386_qemu @@ -147,7 +122,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h endif if COND_i386_ieee1275 -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h @@ -156,7 +130,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h endif if COND_i386_xen -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h @@ -175,19 +148,15 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h endif if COND_x86_64_efi -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h endif if COND_ia64_efi KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h endif if COND_mips @@ -257,43 +226,16 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h endif -if COND_arm_coreboot -KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h -endif - if COND_arm_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/efi/loader.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h endif if COND_arm64_efi KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h -endif - -if COND_riscv32_efi -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h -endif - -if COND_riscv64_efi -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h endif if COND_emu @@ -306,6 +248,9 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h if COND_GRUB_EMU_SDL KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h endif +if COND_GRUB_EMU_USB +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libusb.h +endif if COND_GRUB_EMU_PCI KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libpciaccess.h endif @@ -321,7 +266,7 @@ BUILT_SOURCES += symlist.h symlist.c: symlist.h gensymlist.sh $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1) - cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1) + cat symlist.p | /bin/sh $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1) rm -f symlist.p CLEANFILES += symlist.c BUILT_SOURCES += symlist.c @@ -401,16 +346,6 @@ terminal.lst: $(MARKER_FILES) platform_DATA += terminal.lst CLEANFILES += terminal.lst -fdt.lst: $(MARKER_FILES) - (for pp in $^; do \ - b=`basename $$pp .marker`; \ - sed -n \ - -e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \ - -e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \ - done) | sort -u > $@ -platform_DATA += fdt.lst -CLEANFILES += fdt.lst - parttool.lst: $(MARKER_FILES) (for pp in $^; do \ b=`basename $$pp .marker`; \ @@ -449,7 +384,7 @@ moddep.lst: syminfo.lst genmoddep.awk video.lst platform_DATA += moddep.lst CLEANFILES += config.log syminfo.lst moddep.lst -$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT) +$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@ platform_DATA += $(MOD_FILES) platform_DATA += modinfo.sh diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b5f47fc41..42443bc00 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1,43 +1,43 @@ AutoGen definitions Makefile.tpl; -transform_data = { +script = { installdir = noinst; name = gensyminfo.sh; common = gensyminfo.sh.in; }; -transform_data = { +script = { installdir = noinst; name = genmod.sh; common = genmod.sh.in; }; -transform_data = { +script = { installdir = noinst; name = modinfo.sh; common = modinfo.sh.in; }; -transform_data = { +script = { installdir = platform; name = gmodule.pl; common = gmodule.pl.in; }; -transform_data = { +script = { installdir = platform; name = gdb_grub; common = gdb_grub.in; }; -transform_data = { +script = { installdir = platform; name = grub.chrp; common = boot/powerpc/grub.chrp.in; enable = powerpc_ieee1275; }; -transform_data = { +script = { installdir = platform; name = bootinfo.txt; common = boot/powerpc/bootinfo.txt.in; @@ -59,34 +59,31 @@ kernel = { ia64_efi_ldflags = '-Wl,-r,-d'; ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + x86_64_xen_cppflags = '$(CPPFLAGS_XEN)'; + i386_xen_cppflags = '$(CPPFLAGS_XEN)'; + arm_efi_ldflags = '-Wl,-r,-d'; arm_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; arm64_efi_ldflags = '-Wl,-r,-d'; arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; - riscv32_efi_ldflags = '-Wl,-r,-d'; - riscv32_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; - - riscv64_efi_ldflags = '-Wl,-r,-d'; - riscv64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; - i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200'; i386_coreboot_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_coreboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_coreboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200'; i386_multiboot_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_multiboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_multiboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200'; i386_ieee1275_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_ieee1275_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x10000'; i386_xen_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0'; x86_64_xen_ldflags = '$(TARGET_IMG_LDFLAGS)'; x86_64_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0'; - i386_xen_pvh_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000'; + + ldadd = '$(LDADD_KERNEL)'; mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; @@ -98,17 +95,14 @@ kernel = { i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; emu_cflags = '$(CFLAGS_GNULIB)'; emu_cppflags = '$(CPPFLAGS_GNULIB)'; - arm_uboot_ldflags = '-Wl,-r,-d'; + arm_uboot_ldflags = '-Wl,-Ttext=0x08000000'; arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - arm_coreboot_ldflags = '-Wl,-r,-d'; - arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; i386_pc_startup = kern/i386/pc/startup.S; i386_efi_startup = kern/i386/efi/startup.S; x86_64_efi_startup = kern/x86_64/efi/startup.S; i386_xen_startup = kern/i386/xen/startup.S; x86_64_xen_startup = kern/x86_64/xen/startup.S; - i386_xen_pvh_startup = kern/i386/xen/startup_pvh.S; i386_qemu_startup = kern/i386/qemu/startup.S; i386_ieee1275_startup = kern/i386/ieee1275/startup.S; i386_coreboot_startup = kern/i386/coreboot/startup.S; @@ -116,12 +110,9 @@ kernel = { mips_startup = kern/mips/startup.S; sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; - arm_uboot_startup = kern/arm/startup.S; - arm_coreboot_startup = kern/arm/startup.S; + arm_uboot_startup = kern/arm/uboot/startup.S; arm_efi_startup = kern/arm/efi/startup.S; arm64_efi_startup = kern/arm64/efi/startup.S; - riscv32_efi_startup = kern/riscv/efi/startup.S; - riscv64_efi_startup = kern/riscv/efi/startup.S; common = kern/command.c; common = kern/corecmd.c; @@ -141,7 +132,6 @@ kernel = { common = kern/rescue_reader.c; common = kern/term.c; - noemu = kern/compiler-rt.c; noemu = kern/mm.c; noemu = kern/time.c; noemu = kern/generic/millisleep.c; @@ -163,58 +153,28 @@ kernel = { uboot = kern/uboot/init.c; uboot = kern/uboot/hw.c; uboot = term/uboot/console.c; - arm_uboot = kern/arm/uboot/init.c; - arm_uboot = kern/arm/uboot/uboot.S; - - arm_coreboot = kern/arm/coreboot/init.c; - arm_coreboot = kern/arm/coreboot/timer.c; - arm_coreboot = kern/arm/coreboot/coreboot.S; - arm_coreboot = lib/fdt.c; - arm_coreboot = bus/fdt.c; - arm_coreboot = term/ps2.c; - arm_coreboot = term/arm/pl050.c; - arm_coreboot = term/arm/cros.c; - arm_coreboot = term/arm/cros_ec.c; - arm_coreboot = bus/spi/rk3288_spi.c; - arm_coreboot = commands/keylayouts.c; - arm_coreboot = kern/arm/coreboot/dma.c; terminfoinkernel = term/terminfo.c; terminfoinkernel = term/tparm.c; terminfoinkernel = commands/extcmd.c; terminfoinkernel = lib/arg.c; - softdiv = lib/division.c; - i386 = kern/i386/dl.c; i386_xen = kern/i386/dl.c; - i386_xen_pvh = kern/i386/dl.c; i386_coreboot = kern/i386/coreboot/init.c; i386_multiboot = kern/i386/coreboot/init.c; i386_qemu = kern/i386/qemu/init.c; i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; - coreboot = video/coreboot/cbfb.c; + i386_coreboot = video/i386/coreboot/cbfb.c; efi = disk/efi/efidisk.c; efi = kern/efi/efi.c; efi = kern/efi/init.c; efi = kern/efi/mm.c; efi = term/efi/console.c; - efi = kern/acpi.c; - efi = kern/efi/acpi.c; - i386_coreboot = kern/i386/pc/acpi.c; - i386_multiboot = kern/i386/pc/acpi.c; - i386_coreboot = kern/acpi.c; - i386_multiboot = kern/acpi.c; x86 = kern/i386/tsc.c; - x86 = kern/i386/tsc_pit.c; - i386_efi = kern/i386/efi/tsc.c; - x86_64_efi = kern/i386/efi/tsc.c; - i386_efi = kern/i386/tsc_pmtimer.c; - i386_coreboot = kern/i386/tsc_pmtimer.c; - x86_64_efi = kern/i386/tsc_pmtimer.c; i386_efi = kern/i386/efi/init.c; i386_efi = bus/pci.c; @@ -226,7 +186,6 @@ kernel = { x86_64_efi = bus/pci.c; xen = kern/i386/tsc.c; - xen = kern/i386/xen/tsc.c; x86_64_xen = kern/x86_64/xen/hypercall.S; i386_xen = kern/i386/xen/hypercall.S; xen = kern/xen/init.c; @@ -234,14 +193,6 @@ kernel = { xen = disk/xen/xendisk.c; xen = commands/boot.c; - i386_xen_pvh = commands/boot.c; - i386_xen_pvh = disk/xen/xendisk.c; - i386_xen_pvh = kern/i386/tsc.c; - i386_xen_pvh = kern/i386/xen/tsc.c; - i386_xen_pvh = kern/i386/xen/pvh.c; - i386_xen_pvh = kern/xen/init.c; - i386_xen_pvh = term/xen/console.c; - ia64_efi = kern/ia64/efi/startup.S; ia64_efi = kern/ia64/efi/init.c; ia64_efi = kern/ia64/dl.c; @@ -249,16 +200,9 @@ kernel = { ia64_efi = kern/ia64/cache.c; arm_efi = kern/arm/efi/init.c; - arm_efi = kern/efi/fdt.c; + arm_efi = kern/arm/efi/misc.c; - arm64_efi = kern/arm64/efi/init.c; - arm64_efi = kern/efi/fdt.c; - - riscv32_efi = kern/riscv/efi/init.c; - riscv32_efi = kern/efi/fdt.c; - - riscv64_efi = kern/riscv/efi/init.c; - riscv64_efi = kern/efi/fdt.c; + arm64_efi = kern/arm/efi/init.c; i386_pc = kern/i386/pc/init.c; i386_pc = kern/i386/pc/mmap.c; @@ -268,10 +212,8 @@ kernel = { i386_qemu = kern/vga_init.c; i386_qemu = kern/i386/qemu/mmap.c; - coreboot = kern/coreboot/mmap.c; + i386_coreboot = kern/i386/coreboot/mmap.c; i386_coreboot = kern/i386/coreboot/cbtable.c; - coreboot = kern/coreboot/cbtable.c; - arm_coreboot = kern/arm/coreboot/cbtable.c; i386_multiboot = kern/i386/multiboot_mmap.c; @@ -283,7 +225,6 @@ kernel = { mips_qemu_mips = term/ns8250.c; mips_qemu_mips = term/serial.c; mips_qemu_mips = term/at_keyboard.c; - mips_qemu_mips = term/ps2.c; mips_qemu_mips = commands/boot.c; mips_qemu_mips = commands/keylayouts.c; mips_qemu_mips = term/i386/pc/vga_text.c; @@ -299,7 +240,6 @@ kernel = { mips_loongson = bus/pci.c; mips_loongson = kern/mips/loongson/init.c; mips_loongson = term/at_keyboard.c; - mips_loongson = term/ps2.c; mips_loongson = commands/boot.c; mips_loongson = term/serial.c; mips_loongson = video/sm712.c; @@ -312,12 +252,10 @@ kernel = { powerpc_ieee1275 = kern/powerpc/cache.S; powerpc_ieee1275 = kern/powerpc/dl.c; - powerpc_ieee1275 = kern/powerpc/compiler-rt.S; sparc64_ieee1275 = kern/sparc64/cache.S; sparc64_ieee1275 = kern/sparc64/dl.c; sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c; - sparc64_ieee1275 = disk/ieee1275/obdisk.c; arm = kern/arm/dl.c; arm = kern/arm/dl_helper.c; @@ -325,21 +263,13 @@ kernel = { arm = kern/arm/cache_armv7.S; extra_dist = kern/arm/cache.S; arm = kern/arm/cache.c; - arm = kern/arm/compiler-rt.S; + arm = kern/arm/misc.S; arm64 = kern/arm64/cache.c; arm64 = kern/arm64/cache_flush.S; arm64 = kern/arm64/dl.c; arm64 = kern/arm64/dl_helper.c; - riscv32 = kern/riscv/cache.c; - riscv32 = kern/riscv/cache_flush.S; - riscv32 = kern/riscv/dl.c; - - riscv64 = kern/riscv/cache.c; - riscv64 = kern/riscv/cache_flush.S; - riscv64 = kern/riscv/dl.c; - emu = disk/host.c; emu = kern/emu/cache_s.S; emu = kern/emu/hostdisk.c; @@ -395,7 +325,7 @@ program = { ldadd = 'kernel.exec$(EXEEXT)'; ldadd = '$(MODULE_FILES)'; - ldadd = 'lib/gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + ldadd = 'gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; enable = emu; }; @@ -407,7 +337,7 @@ program = { emu_nodist = symlist.c; ldadd = 'kernel.exec$(EXEEXT)'; - ldadd = 'lib/gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + ldadd = 'gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; enable = emu; }; @@ -425,14 +355,8 @@ image = { i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; - /* The entry point for a.out binaries on sparc64 starts - at 0x4000. Since we are writing the 32 bytes long a.out - header in the assembly code ourselves, we need to tell - the linker to adjust the start of the text segment to - 0x4000 - 0x20 = 0x3fe0. - */ - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; - sparc64_ieee1275_objcopyflags = '-O binary'; + sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; objcopyflags = '-O binary'; enable = i386_pc; @@ -461,10 +385,8 @@ image = { i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; - - /* See comment for sparc64_ieee1275_ldflags above. */ - sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; - sparc64_ieee1275_objcopyflags = '-O binary'; + sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big'; + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000'; sparc64_ieee1275_cppflags = '-DCDBOOT=1'; objcopyflags = '-O binary'; @@ -519,13 +441,13 @@ image = { common = lib/xzembed/xz_dec_bcj.c; common = lib/xzembed/xz_dec_lzma2.c; common = lib/xzembed/xz_dec_stream.c; - common = kern/compiler-rt.c; cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1'; objcopyflags = '-O binary'; - mips_ldflags = '-Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; - cflags = '-Wno-unreachable-code'; + mips_ldflags = '$(TARGET_LDFLAGS_STATIC_LIBGCC) -Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + ldadd = '$(TARGET_LIBGCC)'; + cflags = '-Wno-unreachable-code $(TARGET_LDFLAGS_STATIC_LIBGCC)'; enable = mips; }; @@ -537,7 +459,9 @@ image = { cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1'; objcopyflags = '-O binary'; - mips_ldflags = '-Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + mips_ldflags = '$(TARGET_LDFLAGS_STATIC_LIBGCC) -Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + ldadd = '$(TARGET_LIBGCC)'; + cflags = '$(TARGET_LDFLAGS_STATIC_LIBGCC)'; enable = mips; }; @@ -555,7 +479,7 @@ image = { name = fwstart; mips_loongson = boot/mips/loongson/fwstart.S; objcopyflags = '-O binary'; - ldflags = '-Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; + ldflags = '$(TARGET_LDFLAGS_STATIC_LIBGCC) $(TARGET_LIBGCC) -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; enable = mips_loongson; }; @@ -563,7 +487,7 @@ image = { name = fwstart_fuloong2f; mips_loongson = boot/mips/loongson/fuloong2f.S; objcopyflags = '-O binary'; - ldflags = '-Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; + ldflags = '$(TARGET_LDFLAGS_STATIC_LIBGCC) $(TARGET_LIBGCC) -Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; enable = mips_loongson; }; @@ -585,6 +509,13 @@ module = { enable = x86; }; +module = { + name = libusb; + emu = bus/usb/emu/usb.c; + enable = emu; + condition = COND_GRUB_EMU_USB; +}; + module = { name = lsspd; mips_loongson = commands/mips/loongson/lsspd.c; @@ -599,6 +530,13 @@ module = { enable = usb; }; +module = { + name = emuusb; + common = bus/usb/usb.c; + enable = emu; + condition = COND_GRUB_EMU_USB; +}; + module = { name = usbserial_common; common = bus/usb/serial/common.c; @@ -638,10 +576,7 @@ module = { module = { name = ehci; common = bus/usb/ehci.c; - arm_coreboot = bus/usb/ehci-fdt.c; - pci = bus/usb/ehci-pci.c; enable = pci; - enable = arm_coreboot; }; module = { @@ -683,6 +618,7 @@ module = { module = { name = lsxen; common = commands/xen/lsxen.c; + cppflags = '$(CPPFLAGS_XEN)'; enable = xen; }; @@ -708,7 +644,6 @@ module = { module = { name = cbtable; common = kern/i386/coreboot/cbtable.c; - common = kern/coreboot/cbtable.c; enable = i386_pc; enable = i386_efi; enable = i386_qemu; @@ -739,7 +674,7 @@ module = { name = regexp; common = commands/regexp.c; common = commands/wildcard.c; - common = lib/gnulib/regex.c; + common = gnulib/regex.c; cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; }; @@ -748,8 +683,10 @@ module = { name = acpi; common = commands/acpi.c; - i386_pc = kern/acpi.c; - i386_pc = kern/i386/pc/acpi.c; + efi = commands/efi/acpi.c; + i386_pc = commands/i386/pc/acpi.c; + i386_coreboot = commands/i386/pc/acpi.c; + i386_multiboot = commands/i386/pc/acpi.c; enable = efi; enable = i386_pc; @@ -822,9 +759,6 @@ module = { enable = arm_efi; enable = arm64_efi; enable = arm_uboot; - enable = arm_coreboot; - enable = riscv32_efi; - enable = riscv64_efi; }; module = { @@ -846,7 +780,6 @@ module = { name = cpuid; common = commands/i386/cpuid.c; enable = x86; - enable = i386_xen_pvh; enable = i386_xen; enable = x86_64_xen; }; @@ -906,27 +839,29 @@ module = { i386_coreboot = lib/i386/halt.c; i386_qemu = lib/i386/halt.c; xen = lib/xen/halt.c; - i386_xen_pvh = lib/xen/halt.c; + xen_cppflags = '$(CPPFLAGS_XEN)'; efi = lib/efi/halt.c; ieee1275 = lib/ieee1275/halt.c; emu = lib/emu/halt.c; - uboot = lib/dummy/halt.c; - arm_coreboot = lib/dummy/halt.c; + uboot = lib/uboot/halt.c; }; module = { name = reboot; i386 = lib/i386/reboot.c; i386 = lib/i386/reboot_trampoline.S; + ia64_efi = lib/efi/reboot.c; + x86_64_efi = lib/efi/reboot.c; + arm_efi = lib/efi/reboot.c; + arm64_efi = lib/efi/reboot.c; powerpc_ieee1275 = lib/ieee1275/reboot.c; sparc64_ieee1275 = lib/ieee1275/reboot.c; mips_arc = lib/mips/arc/reboot.c; mips_loongson = lib/mips/loongson/reboot.c; mips_qemu_mips = lib/mips/qemu_mips/reboot.c; xen = lib/xen/reboot.c; - i386_xen_pvh = lib/xen/reboot.c; + xen_cppflags = '$(CPPFLAGS_XEN)'; uboot = lib/uboot/reboot.c; - arm_coreboot = lib/dummy/reboot.c; common = commands/reboot.c; }; @@ -936,26 +871,16 @@ module = { }; module = { - name = pgp; - common = commands/pgp.c; + name = verify; + common = commands/verify.c; cflags = '$(CFLAGS_POSIX)'; cppflags = '-I$(srcdir)/lib/posix_wrap'; }; -module = { - name = verifiers; - common = commands/verifiers.c; -}; - -module = { - name = shim_lock; - common = commands/efi/shim_lock.c; - enable = efi; -}; - module = { name = hdparm; common = commands/hdparm.c; + common = lib/hexdump.c; enable = pci; enable = mips_qemu_mips; }; @@ -1097,21 +1022,6 @@ module = { common = commands/sleep.c; }; -module = { - name = smbios; - - common = commands/smbios.c; - efi = commands/efi/smbios.c; - i386_pc = commands/i386/pc/smbios.c; - i386_coreboot = commands/i386/pc/smbios.c; - i386_multiboot = commands/i386/pc/smbios.c; - - enable = efi; - enable = i386_pc; - enable = i386_coreboot; - enable = i386_multiboot; -}; - module = { name = suspend; ieee1275 = commands/ieee1275/suspend.c; @@ -1176,27 +1086,10 @@ module = { common = disk/cryptodisk.c; }; -module = { - name = json; - common = lib/json/json.c; -}; - -module = { - name = afsplitter; - common = disk/AFSplitter.c; -}; - module = { name = luks; common = disk/luks.c; -}; - -module = { - name = luks2; - common = disk/luks2.c; - common = lib/gnulib/base64.c; - cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; - cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json'; + common = disk/AFSplitter.c; }; module = { @@ -1351,27 +1244,12 @@ module = { common = fs/bfs.c; }; -module = { - name = zstd; - common = lib/zstd/debug.c; - common = lib/zstd/entropy_common.c; - common = lib/zstd/error_private.c; - common = lib/zstd/fse_decompress.c; - common = lib/zstd/huf_decompress.c; - common = lib/zstd/module.c; - common = lib/zstd/xxhash.c; - common = lib/zstd/zstd_common.c; - common = lib/zstd/zstd_decompress.c; - cflags = '$(CFLAGS_POSIX) -Wno-undef'; - cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd'; -}; - module = { name = btrfs; common = fs/btrfs.c; common = lib/crc.c; cflags = '$(CFLAGS_POSIX) -Wno-undef'; - cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -I$(srcdir)/lib/zstd -DMINILZO_HAVE_CONFIG_H'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; }; module = { @@ -1419,11 +1297,6 @@ module = { common = fs/exfat.c; }; -module = { - name = f2fs; - common = fs/f2fs.c; -}; - module = { name = fshelp; common = fs/fshelp.c; @@ -1589,6 +1462,7 @@ module = { module = { name = gfxmenu; common = gfxmenu/gfxmenu.c; + common = gfxmenu/model.c; common = gfxmenu/view.c; common = gfxmenu/font.c; common = gfxmenu/icon_manager.c; @@ -1651,18 +1525,12 @@ module = { x86 = lib/i386/relocator16.S; x86 = lib/i386/relocator32.S; x86 = lib/i386/relocator64.S; - i386_xen_pvh = lib/i386/relocator16.S; - i386_xen_pvh = lib/i386/relocator32.S; - i386_xen_pvh = lib/i386/relocator64.S; i386 = lib/i386/relocator_asm.S; - i386_xen_pvh = lib/i386/relocator_asm.S; x86_64 = lib/x86_64/relocator_asm.S; i386_xen = lib/i386/relocator_asm.S; x86_64_xen = lib/x86_64/relocator_asm.S; x86 = lib/i386/relocator.c; x86 = lib/i386/relocator_common_c.c; - i386_xen_pvh = lib/i386/relocator.c; - i386_xen_pvh = lib/i386/relocator_common_c.c; ieee1275 = lib/ieee1275/relocator.c; efi = lib/efi/relocator.c; mips = lib/mips/relocator_asm.S; @@ -1673,7 +1541,7 @@ module = { i386_xen = lib/i386/xen/relocator.S; x86_64_xen = lib/x86_64/xen/relocator.S; xen = lib/i386/relocator_common_c.c; - x86_64_efi = lib/x86_64/efi/relocator.c; + xen_cppflags = '$(CPPFLAGS_XEN)'; extra_dist = lib/i386/relocator_common.S; extra_dist = kern/powerpc/cache_flush.S; @@ -1681,25 +1549,23 @@ module = { enable = mips; enable = powerpc; enable = x86; - enable = i386_xen_pvh; enable = xen; }; module = { name = datetime; - common = lib/datetime.c; cmos = lib/cmos_datetime.c; efi = lib/efi/datetime.c; - uboot = lib/dummy/datetime.c; - arm_coreboot = lib/dummy/datetime.c; + uboot = lib/uboot/datetime.c; sparc64_ieee1275 = lib/ieee1275/datetime.c; powerpc_ieee1275 = lib/ieee1275/datetime.c; sparc64_ieee1275 = lib/ieee1275/cmos.c; powerpc_ieee1275 = lib/ieee1275/cmos.c; xen = lib/xen/datetime.c; - i386_xen_pvh = lib/xen/datetime.c; + xen_cppflags = '$(CPPFLAGS_XEN)'; mips_arc = lib/arc/datetime.c; + enable = noemu; }; module = { @@ -1714,7 +1580,6 @@ module = { extra_dist = lib/ia64/longjmp.S; extra_dist = lib/arm/setjmp.S; extra_dist = lib/arm64/setjmp.S; - extra_dist = lib/riscv/setjmp.S; }; module = { @@ -1745,6 +1610,8 @@ module = { module = { name = linux16; common = loader/i386/pc/linux.c; + common = loader/linux.c; + common = lib/cmdline.c; enable = x86; }; @@ -1779,89 +1646,46 @@ module = { cppflags = "-DGRUB_USE_MULTIBOOT2"; common = loader/multiboot.c; + common = lib/cmdline.c; common = loader/multiboot_mbi2.c; enable = x86; - enable = i386_xen_pvh; enable = mips; }; module = { name = multiboot; common = loader/multiboot.c; + common = lib/cmdline.c; x86 = loader/i386/multiboot_mbi.c; - i386_xen_pvh = loader/i386/multiboot_mbi.c; extra_dist = loader/multiboot_elfxx.c; enable = x86; - enable = i386_xen_pvh; -}; - -module = { - name = xen_boot; - arm64 = loader/arm64/xen_boot.c; - enable = arm64; }; module = { name = linux; x86 = loader/i386/linux.c; - i386_xen_pvh = loader/i386/linux.c; xen = loader/i386/xen.c; + xen_cppflags = '$(CPPFLAGS_XEN)'; i386_pc = lib/i386/pc/vesa_modes_table.c; - i386_xen_pvh = lib/i386/pc/vesa_modes_table.c; mips = loader/mips/linux.c; powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; - arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; - arm_uboot = loader/arm/linux.c; + arm = loader/arm/linux.c; arm64 = loader/arm64/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + fdt = lib/fdt.c; common = loader/linux.c; common = lib/cmdline.c; enable = noemu; }; -module = { - name = fdt; - efi = loader/efi/fdt.c; - common = lib/fdt.c; - enable = fdt; -}; - module = { name = xnu; x86 = loader/xnu_resume.c; x86 = loader/i386/xnu.c; x86 = loader/xnu.c; - /* Code is pretty generic but relies on RNG which - is available only on few platforms. It's not a - big deal as xnu needs ACPI anyway and we have - RNG on all platforms with ACPI. - */ - enable = i386_multiboot; - enable = i386_coreboot; - enable = i386_pc; - enable = i386_efi; - enable = x86_64_efi; -}; - -module = { - name = random; - x86 = lib/i386/random.c; - common = lib/random.c; - - i386_multiboot = kern/i386/tsc_pmtimer.c; - i386_coreboot = kern/i386/tsc_pmtimer.c; - i386_pc = kern/i386/tsc_pmtimer.c; - - enable = i386_multiboot; - enable = i386_coreboot; - enable = i386_pc; - enable = i386_efi; - enable = x86_64_efi; + enable = x86; }; module = { @@ -1897,8 +1721,6 @@ module = { common = mmap/mmap.c; x86 = mmap/i386/uppermem.c; x86 = mmap/i386/mmap.c; - i386_xen_pvh = mmap/i386/uppermem.c; - i386_xen_pvh = mmap/i386/mmap.c; i386_pc = mmap/i386/pc/mmap.c; i386_pc = mmap/i386/pc/mmap_helper.S; @@ -1908,12 +1730,9 @@ module = { mips = mmap/mips/uppermem.c; enable = x86; - enable = i386_xen_pvh; enable = ia64_efi; enable = arm_efi; enable = arm64_efi; - enable = riscv32_efi; - enable = riscv64_efi; enable = mips; }; @@ -1926,6 +1745,7 @@ module = { common = normal/autofs.c; common = normal/color.c; common = normal/completion.c; + common = normal/datetime.c; common = normal/menu.c; common = normal/menu_entry.c; common = normal/menu_text.c; @@ -2021,7 +1841,6 @@ module = { module = { name = at_keyboard; common = term/at_keyboard.c; - common = term/ps2.c; enable = x86; }; @@ -2114,11 +1933,6 @@ module = { common = tests/example_functional_test.c; }; -module = { - name = strtoull_test; - common = tests/strtoull_test.c; -}; - module = { name = setjmp_test; common = tests/setjmp_test.c; @@ -2149,49 +1963,17 @@ module = { name = legacy_password_test; common = tests/legacy_password_test.c; enable = i386_pc; - enable = i386_xen_pvh; enable = i386_efi; enable = x86_64_efi; enable = emu; enable = xen; }; -module = { - name = div; - common = lib/division.c; - enable = no_softdiv; -}; - module = { name = div_test; common = tests/div_test.c; }; -module = { - name = mul_test; - common = tests/mul_test.c; -}; - -module = { - name = shift_test; - common = tests/shift_test.c; -}; - -module = { - name = cmp_test; - common = tests/cmp_test.c; -}; - -module = { - name = ctz_test; - common = tests/ctz_test.c; -}; - -module = { - name = bswap_test; - common = tests/bswap_test.c; -}; - module = { name = videotest_checksum; common = tests/videotest_checksum.c; @@ -2348,7 +2130,6 @@ module = { xen = lib/i386/pc/vesa_modes_table.c; enable = i386_pc; - enable = i386_xen_pvh; enable = i386_efi; enable = x86_64_efi; enable = emu; @@ -2392,12 +2173,10 @@ module = { module = { name = backtrace; x86 = lib/i386/backtrace.c; - i386_xen_pvh = lib/i386/backtrace.c; i386_xen = lib/i386/backtrace.c; x86_64_xen = lib/i386/backtrace.c; common = lib/backtrace.c; enable = x86; - enable = i386_xen_pvh; enable = i386_xen; enable = x86_64_xen; }; @@ -2496,13 +2275,6 @@ module = { common = commands/testspeed.c; }; -module = { - name = tpm; - common = commands/tpm.c; - efi = commands/efi/tpm.c; - enable = efi; -}; - module = { name = tr; common = commands/tr.c; @@ -2524,13 +2296,3 @@ module = { common = loader/i386/xen_file64.c; extra_dist = loader/i386/xen_fileXX.c; }; -module = { - name = rdmsr; - common = commands/i386/rdmsr.c; - enable = x86; -}; -module = { - name = wrmsr; - common = commands/i386/wrmsr.c; - enable = x86; -}; diff --git a/grub-core/boot/decompressor/minilib.c b/grub-core/boot/decompressor/minilib.c index fc46ee07b..94edfd561 100644 --- a/grub-core/boot/decompressor/minilib.c +++ b/grub-core/boot/decompressor/minilib.c @@ -21,7 +21,7 @@ #include void * -grub_memset (void *s, int c, grub_size_t len) +memset (void *s, int c, grub_size_t len) { grub_uint8_t *ptr; for (ptr = s; len; ptr++, len--) @@ -68,6 +68,15 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n) return 0; } +int memcmp (const void *s1, const void *s2, grub_size_t n) + __attribute__ ((alias ("grub_memcmp"))); + +void *memmove (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); + +void *memcpy (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); + void *grub_decompressor_scratch; void diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S index 2bd0b2d28..b4975e2d0 100644 --- a/grub-core/boot/i386/pc/boot.S +++ b/grub-core/boot/i386/pc/boot.S @@ -165,8 +165,8 @@ start: * this area. */ - .org GRUB_BOOT_MACHINE_BPB_START - .org 4 + . = _start + GRUB_BOOT_MACHINE_BPB_START + . = _start + 4 #endif #ifdef HYBRID_BOOT floppy @@ -174,23 +174,23 @@ start: scratch #endif - .org GRUB_BOOT_MACHINE_BPB_END + . = _start + GRUB_BOOT_MACHINE_BPB_END /* * End of BIOS parameter block. */ -LOCAL(kernel_address): +kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR #ifndef HYBRID_BOOT - .org GRUB_BOOT_MACHINE_KERNEL_SECTOR -LOCAL(kernel_sector): + . = _start + GRUB_BOOT_MACHINE_KERNEL_SECTOR +kernel_sector: .long 1 -LOCAL(kernel_sector_high): +kernel_sector_high: .long 0 #endif - .org GRUB_BOOT_MACHINE_BOOT_DRIVE + . = _start + GRUB_BOOT_MACHINE_BOOT_DRIVE boot_drive: .byte 0xff /* the disk to load kernel from */ /* 0xff means use the boot drive */ @@ -208,7 +208,7 @@ LOCAL(after_BPB): * possible boot drive. If GRUB is installed into a floppy, * this does nothing (only jump). */ - .org GRUB_BOOT_MACHINE_DRIVE_CHECK + . = _start + GRUB_BOOT_MACHINE_DRIVE_CHECK boot_drive_check: jmp 3f /* grub-setup may overwrite this jump */ testb $0x80, %dl @@ -275,7 +275,7 @@ real_start: andw $1, %cx jz LOCAL(chs_mode) -LOCAL(lba_mode): +lba_mode: xorw %ax, %ax movw %ax, 4(%si) @@ -290,9 +290,9 @@ LOCAL(lba_mode): movw $0x0010, (%si) /* the absolute address */ - movl LOCAL(kernel_sector), %ebx + movl kernel_sector, %ebx movl %ebx, 8(%si) - movl LOCAL(kernel_sector_high), %ebx + movl kernel_sector_high, %ebx movl %ebx, 12(%si) /* the segment of buffer address */ @@ -361,13 +361,13 @@ LOCAL(final_init): setup_sectors: /* load logical sector start (top half) */ - movl LOCAL(kernel_sector_high), %eax + movl kernel_sector_high, %eax orl %eax, %eax jnz LOCAL(geometry_error) /* load logical sector start (bottom half) */ - movl LOCAL(kernel_sector), %eax + movl kernel_sector, %eax /* zero %edx */ xorl %edx, %edx @@ -452,7 +452,7 @@ LOCAL(copy_buffer): popa /* boot kernel */ - jmp *(LOCAL(kernel_address)) + jmp *(kernel_address) /* END OF MAIN LOOP */ @@ -511,13 +511,13 @@ LOCAL(message): */ #ifdef HYBRID_BOOT - .org 0x1b0 -LOCAL(kernel_sector): + . = _start + 0x1b0 +kernel_sector: .long 1 -LOCAL(kernel_sector_high): +kernel_sector_high: .long 0 #endif - .org GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC + . = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC nt_magic: .long 0 .word 0 @@ -528,7 +528,7 @@ nt_magic: * sneaky, huh? */ - .org GRUB_BOOT_MACHINE_PART_START + . = _start + GRUB_BOOT_MACHINE_PART_START #ifndef HYBRID_BOOT floppy @@ -536,7 +536,7 @@ nt_magic: scratch #endif - .org GRUB_BOOT_MACHINE_PART_END + . = _start + GRUB_BOOT_MACHINE_PART_END /* the last 2 bytes in the sector 0 contain the signature */ .word GRUB_BOOT_MACHINE_SIGNATURE diff --git a/grub-core/boot/i386/pc/cdboot.S b/grub-core/boot/i386/pc/cdboot.S index de4f80929..92df7c76f 100644 --- a/grub-core/boot/i386/pc/cdboot.S +++ b/grub-core/boot/i386/pc/cdboot.S @@ -43,7 +43,7 @@ _start: LOCAL(next): jmp 1f - .org 8 + . = start + 8 bi_pvd: .long 0 /* LBA of primary volume descriptor. */ @@ -168,6 +168,6 @@ err_noboot_msg: err_cdfail_msg: .ascii "cdrom read fails\0" - .org 0x7FF + . = start + 0x7FF .byte 0 diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S index c1addc0df..d030a14c9 100644 --- a/grub-core/boot/i386/pc/diskboot.S +++ b/grub-core/boot/i386/pc/diskboot.S @@ -37,8 +37,8 @@ start: _start: /* - * _start is loaded at 0x8000 and is jumped to with - * CS:IP 0:0x8000 in kernel. + * _start is loaded at 0x2000 and is jumped to with + * CS:IP 0:0x2000 in kernel. */ /* @@ -362,7 +362,7 @@ LOCAL(message): .word 0 .word 0 - .org 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE + . = _start + 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE LOCAL(firstlist): /* this label has to be before the first list entry!!! */ /* fill the first data listing with the default */ blocklist_default_start: diff --git a/grub-core/boot/i386/pc/lnxboot.S b/grub-core/boot/i386/pc/lnxboot.S index 2dda0e06b..87e56a2fd 100644 --- a/grub-core/boot/i386/pc/lnxboot.S +++ b/grub-core/boot/i386/pc/lnxboot.S @@ -41,7 +41,7 @@ data_start: xorl %ebp, %ebp jmp LOCAL(linux_next) - .org 0x1F1 + . = data_start + 0x1F1 setup_sects: .byte CODE_SECTORS @@ -292,4 +292,4 @@ LOCAL(fail): err_int15_msg: .ascii "move memory fails\0" - .org (CODE_SECTORS * 512 + 512) + . = _start + CODE_SECTORS * 512 diff --git a/grub-core/boot/i386/pc/pxeboot.S b/grub-core/boot/i386/pc/pxeboot.S index b695b24d0..446bfc781 100644 --- a/grub-core/boot/i386/pc/pxeboot.S +++ b/grub-core/boot/i386/pc/pxeboot.S @@ -38,5 +38,5 @@ start: /* This region is a junk. Do you say that this is wasteful? But I like that the memory layout of the body is consistent among different kernels rather than scamping just for 1.5KB. */ - .org 0x8200 - 0x7C00 - 0x200 - 1 + . = _start + 0x8200 - 0x7C00 - 0x200 - 1 .byte 0 diff --git a/grub-core/boot/i386/pc/startup_raw.S b/grub-core/boot/i386/pc/startup_raw.S index 28974821e..279674030 100644 --- a/grub-core/boot/i386/pc/startup_raw.S +++ b/grub-core/boot/i386/pc/startup_raw.S @@ -50,23 +50,23 @@ LOCAL (base): * This is a special data area. */ - .org GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE + . = _start + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE LOCAL(compressed_size): .long 0 - .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE + . = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE LOCAL(uncompressed_size): .long 0 - .org GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY + . = _start + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY reed_solomon_redundancy: .long 0 - .org GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH + . = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH .short (LOCAL(reed_solomon_part) - _start) /* * This is the area for all of the special variables. */ - .org GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE + . = _start + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE LOCAL(boot_dev): .byte 0xFF, 0xFF, 0xFF LOCAL(boot_drive): @@ -89,13 +89,13 @@ LOCAL (codestart): sti /* we're safe again */ /* save the boot drive */ - movb %dl, LOCAL(boot_drive) + ADDR32 movb %dl, LOCAL(boot_drive) /* reset disk system (%ah = 0) */ int $0x13 /* transition to protected mode */ - calll real_to_prot + DATA32 call real_to_prot /* The ".code32" directive takes GAS out of 16-bit mode. */ .code32 @@ -118,16 +118,7 @@ LOCAL (codestart): #include "../../../kern/i386/realmode.S" -/* - * - * This is a workaround for clang adding a section containing only .addrsig - * Since clang itself is unable to assemble this pseudo-opcode, just replace - * it with .text - * - */ -#define addrsig text #include -#undef addrsig .text @@ -158,7 +149,7 @@ gate_a20_try_bios: movw $0x2401, %ax int $0x15 - calll real_to_prot + DATA32 call real_to_prot .code32 popl %ebp diff --git a/grub-core/boot/i386/qemu/boot.S b/grub-core/boot/i386/qemu/boot.S index 8c3a1db71..bdd68c704 100644 --- a/grub-core/boot/i386/qemu/boot.S +++ b/grub-core/boot/i386/qemu/boot.S @@ -31,7 +31,7 @@ _start: jmp 1f - .org GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR + . = _start + GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR VARIABLE(grub_core_entry_addr) .long 0 1: @@ -48,9 +48,8 @@ VARIABLE(grub_core_entry_addr) /* Transition to protected mode. We use pushl to force generation of a flat return address. */ pushl $1f - jmp real_to_prot + DATA32 jmp real_to_prot .code32 -1: /* Ensure A20 is enabled. We're in qemu, so control port A works and there is no need to wait since there is no real logic, it's all emulated. */ @@ -58,6 +57,7 @@ VARIABLE(grub_core_entry_addr) andb $(~0x03), %al orb $0x02, %al outb $0x92 +1: movl EXT_C(grub_core_entry_addr), %edx jmp *%edx @@ -66,9 +66,9 @@ VARIABLE(grub_core_entry_addr) /* Intel, in its infinite wisdom, decided to put the i8086 entry point *right here* and this is why we need this kludge. */ - .org GRUB_BOOT_MACHINE_SIZE - 16 + . = GRUB_BOOT_MACHINE_SIZE - 16 .code16 jmp _start - .org GRUB_BOOT_MACHINE_SIZE + . = GRUB_BOOT_MACHINE_SIZE diff --git a/grub-core/boot/mips/loongson/fwstart.S b/grub-core/boot/mips/loongson/fwstart.S index 28c634614..6ae326990 100644 --- a/grub-core/boot/mips/loongson/fwstart.S +++ b/grub-core/boot/mips/loongson/fwstart.S @@ -162,7 +162,7 @@ retry_cs5536: b continue - .org GRUB_CPU_LOONGSON_FLASH_TLB_REFILL - GRUB_CPU_LOONGSON_FLASH_START + . = start + GRUB_CPU_LOONGSON_FLASH_TLB_REFILL - GRUB_CPU_LOONGSON_FLASH_START tlb_refill: mfc0 $s1, GRUB_CPU_LOONGSON_COP0_EPC mfc0 $s2, GRUB_CPU_LOONGSON_COP0_BADVADDR @@ -196,13 +196,13 @@ tlb_refill: b fatal addiu $a0, $a0, %lo(unhandled_tlb_refill) - .org GRUB_CPU_LOONGSON_FLASH_CACHE_ERROR - GRUB_CPU_LOONGSON_FLASH_START + . = start + GRUB_CPU_LOONGSON_FLASH_CACHE_ERROR - GRUB_CPU_LOONGSON_FLASH_START cache_error: lui $a0, %hi(unhandled_cache_error) b fatal addiu $a0, $a0, %lo(unhandled_cache_error) - .org GRUB_CPU_LOONGSON_FLASH_OTHER_EXCEPTION - GRUB_CPU_LOONGSON_FLASH_START + . = start + GRUB_CPU_LOONGSON_FLASH_OTHER_EXCEPTION - GRUB_CPU_LOONGSON_FLASH_START other_exception: mfc0 $s0, GRUB_CPU_LOONGSON_COP0_CAUSE mfc0 $s1, GRUB_CPU_LOONGSON_COP0_EPC @@ -344,7 +344,7 @@ printhex: nop srl $t1, $a0, 28 addiu $t1, $t1, -10 - bltz $t1, 2f + blt $t1, $zero, 2f sll $a0, $a0, 4 addiu $t1, $t1, 'A'-10-'0' 2: addiu $t1, $t1, '0'+10 @@ -398,7 +398,7 @@ read_spd: move $t2, $a0 move $t3, $ra lui $a0, %hi(read_spd_fail) - addiu $a0, $a0, %lo(read_spd_fail) + addiu $a0, $a0, %hi(read_spd_fail) /* Send START. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) @@ -547,7 +547,7 @@ gpio_dump: #endif gpio_dump_end: - .p2align 3 + .p2align write_dumpreg: ld $t2, 0($t6) diff --git a/grub-core/boot/mips/startup_raw.S b/grub-core/boot/mips/startup_raw.S index 6a81b3733..29e93c17e 100644 --- a/grub-core/boot/mips/startup_raw.S +++ b/grub-core/boot/mips/startup_raw.S @@ -22,7 +22,6 @@ #include #include #include -#include #define BASE_ADDR 8 @@ -40,13 +39,13 @@ start: bal codestart nop base: - .org GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE + . = _start + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE compressed_size: .long 0 - .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE + . = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE uncompressed_size: .long 0 - .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR + . = _start + GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR uncompressed_addr: .long 0 codestart: @@ -119,50 +118,50 @@ parsestr: move $v0, $zero move $t3, $t1 3: - lb GRUB_ASM_T4, 0($t2) - lb GRUB_ASM_T5, 0($t3) + lb $t4, 0($t2) + lb $t5, 0($t3) addiu $t2, $t2, 1 addiu $t3, $t3, 1 - beq GRUB_ASM_T5, $zero, 1f + beq $t5, $zero, 1f nop - beq GRUB_ASM_T5, GRUB_ASM_T4, 3b + beq $t5, $t4, 3b nop - bne GRUB_ASM_T4, $zero, 1f + bne $t4, $zero, 1f nop addiu $t3, $t3, 0xffff digcont: - lb GRUB_ASM_T5, 0($t3) + lb $t5, 0($t3) /* Substract '0' from digit. */ - addiu GRUB_ASM_T5, GRUB_ASM_T5, 0xffd0 - bltz GRUB_ASM_T5, 1f + addiu $t5, $t5, 0xffd0 + bltz $t5, 1f nop - addiu GRUB_ASM_T4, GRUB_ASM_T5, 0xfff7 - bgtz GRUB_ASM_T4, 1f + addiu $t4, $t5, 0xfff7 + bgtz $t4, 1f nop /* Multiply $v0 by 10 with bitshifts. */ sll $v0, $v0, 1 - sll GRUB_ASM_T4, $v0, 2 - addu $v0, $v0, GRUB_ASM_T4 - addu $v0, $v0, GRUB_ASM_T5 + sll $t4, $v0, 2 + addu $v0, $v0, $t4 + addu $v0, $v0, $t5 addiu $t3, $t3, 1 b digcont nop 1: jr $ra nop -busclockstr: .asciz "busclock=" -cpuclockstr: .asciz "cpuclock=" -memsizestr: .asciz "memsize=" -highmemsizestr: .asciz "highmemsize=" -machtype_yeeloong_str1: .asciz "machtype=8.9" -machtype_yeeloong_str2: .asciz "machtype=lemote-yeeloong-" -machtype_fuloong2f_str: .asciz "machtype=lemote-fuloong-2f" -machtype_fuloong2e_str: .asciz "machtype=lemote-fuloong-2e" -pmon_yeeloong_str: .asciz "PMON_VER=LM8" -pmon_fuloong2f_str: .asciz "PMON_VER=LM6" -pmon_yeeloong_verstr: .asciz "Version=LM8" -pmon_fuloong2f_verstr: .asciz "Version=LM6" +busclockstr: .asciiz "busclock=" +cpuclockstr: .asciiz "cpuclock=" +memsizestr: .asciiz "memsize=" +highmemsizestr: .asciiz "highmemsize=" +machtype_yeeloong_str1: .asciiz "machtype=8.9" +machtype_yeeloong_str2: .asciiz "machtype=lemote-yeeloong-" +machtype_fuloong2f_str: .asciiz "machtype=lemote-fuloong-2f" +machtype_fuloong2e_str: .asciiz "machtype=lemote-fuloong-2e" +pmon_yeeloong_str: .asciiz "PMON_VER=LM8" +pmon_fuloong2f_str: .asciiz "PMON_VER=LM6" +pmon_yeeloong_verstr: .asciiz "Version=LM8" +pmon_fuloong2f_verstr: .asciiz "Version=LM6" .p2align 2 argdone: @@ -183,10 +182,10 @@ argdone: b argdone addiu $a1, $a1, 4 do_check: - lb GRUB_ASM_T4, 0($t7) - beq GRUB_ASM_T4, $zero, 1f + lb $t4, 0($t7) + beq $t4, $zero, 1f lb $t3, 0($t6) - bne $t3, GRUB_ASM_T4, 2f + bne $t3, $t4, 2f addiu $t6, $t6, 1 b do_check addiu $t7, $t7, 1 @@ -223,8 +222,8 @@ cmdlinedone: 1: beq $t1, $t3, 2f - lb GRUB_ASM_T4, 0($t2) - sb GRUB_ASM_T4, 0($t1) + lb $t4, 0($t2) + sb $t4, 0($t1) addiu $t1, $t1, 1 b 1b addiu $t2, $t2, 1 diff --git a/grub-core/boot/sparc64/ieee1275/boot.S b/grub-core/boot/sparc64/ieee1275/boot.S index ff8a79d3b..507367749 100644 --- a/grub-core/boot/sparc64/ieee1275/boot.S +++ b/grub-core/boot/sparc64/ieee1275/boot.S @@ -21,24 +21,6 @@ .text .align 4 - /* - * We're writing the a.out header ourselves as newer - * upstream versions of binutils no longer support - * the a.out format on sparc64. - * - * The boot loader fits into 512 bytes with 32 bytes - * used for the a.out header, hence the text segment - * size is 512 - 32. There is no data segment and no - * code relocation, thus those fields remain zero. - */ - .word 0x1030107 /* Magic number. */ - .word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* Size of text segment. */ - .word 0 /* Size of initialized data. */ - .word 0 /* Size of uninitialized data. */ - .word 0 /* Size of symbol table || checksum. */ - .word _start /* Entry point. */ - .word 0 /* Size of text relocation. */ - .word 0 /* Size of data relocation. */ .globl _start _start: /* OF CIF entry point arrives in %o4 */ @@ -48,7 +30,7 @@ pic_base: #ifndef CDBOOT /* The offsets to these locations are defined by the - * GRUB_BOOT_MACHINE_foo macros in include/grub/sparc64/ieee1275/boot.h, + * GRUB_BOOT_MACHINE_foo macros in include/grub/sparc/ieee1275/boot.h, * and grub-setup uses this to patch these next three values as needed. * * The boot_path will be the OF device path of the partition where the @@ -58,14 +40,10 @@ pic_base: * * After loading in that block we will execute it by jumping to the * load address plus the size of the prepended A.OUT header (32 bytes). - * - * Since this assembly code includes the 32 bytes long a.out header, - * we need to move the actual code entry point forward by the size - * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE. */ - .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE + . = _start + GRUB_BOOT_MACHINE_BOOT_DEVPATH boot_path: - .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE + . = _start + GRUB_BOOT_MACHINE_KERNEL_BYTE boot_path_end: kernel_byte: .xword (2 << 9) kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR @@ -74,7 +52,7 @@ kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR #define boot_path_end (_start + 1024) #include - .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE + . = _start + 8 kernel_byte: .xword (2 << 9) kernel_size: .word 512 kernel_address: .word GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS @@ -91,10 +69,6 @@ prom_seek_name: .asciz "seek" prom_read_name: .asciz "read" prom_exit_name: .asciz "exit" grub_name: .asciz "GRUB " -#ifdef CDBOOT -prom_close_name: .asciz "close" -#endif - #define GRUB_NAME_LEN 5 .align 4 @@ -239,12 +213,6 @@ bootpath_known: call prom_call_3_1_o1 #ifdef CDBOOT LDUW_ABS(kernel_size, 0x00, %o3) - - GET_ABS(prom_close_name, %o0) - mov 1, %g1 - mov 0, %o5 - call prom_call - mov BOOTDEV_REG, %o1 #else mov 512, %o3 #endif @@ -256,7 +224,7 @@ bootpath_known: #else nop #endif - .org GRUB_BOOT_MACHINE_CODE_END + . = _start + GRUB_BOOT_MACHINE_CODE_END /* the last 4 bytes in the sector 0 contain the signature */ .word GRUB_BOOT_MACHINE_SIGNATURE diff --git a/grub-core/boot/sparc64/ieee1275/diskboot.S b/grub-core/boot/sparc64/ieee1275/diskboot.S index 35e02c1b6..e020f6221 100644 --- a/grub-core/boot/sparc64/ieee1275/diskboot.S +++ b/grub-core/boot/sparc64/ieee1275/diskboot.S @@ -136,7 +136,7 @@ lastlist: .word 0 .word 0 - .org (0x200 - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE) + . = _start + (0x200 - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE) blocklist_default_start: .word 0 .word 2 diff --git a/grub-core/bus/emu/pci.c b/grub-core/bus/emu/pci.c index 267f2622d..9d3296395 100644 --- a/grub-core/bus/emu/pci.c +++ b/grub-core/bus/emu/pci.c @@ -55,8 +55,7 @@ grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base, int err; err = pci_device_map_range (dev, base, size, PCI_DEV_MAP_FLAG_WRITABLE, &addr); if (err) - grub_util_error ("mapping 0x%llx failed (error %d)", - (unsigned long long) base, err); + grub_util_error ("mapping 0x%x failed (error %d)\n", base, err); return addr; } @@ -67,12 +66,12 @@ grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem, pci_device_unmap_range (dev, mem, size); } -GRUB_MOD_INIT (emupci) +GRUB_MOD_INIT (pci) { pci_system_init (); } -GRUB_MOD_FINI (emupci) +GRUB_MOD_FINI (pci) { pci_system_cleanup (); } diff --git a/grub-core/bus/fdt.c b/grub-core/bus/fdt.c deleted file mode 100644 index 135da497b..000000000 --- a/grub-core/bus/fdt.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -static const void *dtb; -static grub_size_t root_address_cells, root_size_cells; -/* Pointer to this symbol signals invalid mapping. */ -char grub_fdtbus_invalid_mapping[1]; - -struct grub_fdtbus_dev *devs; -struct grub_fdtbus_driver *drivers; - -int -grub_fdtbus_is_compatible (const char *compat_string, - const struct grub_fdtbus_dev *dev) -{ - grub_size_t compatible_size; - const char *compatible = grub_fdt_get_prop (dtb, dev->node, "compatible", - &compatible_size); - if (!compatible) - return 0; - const char *compatible_end = compatible + compatible_size; - while (compatible < compatible_end) - { - if (grub_strcmp (compat_string, compatible) == 0) - return 1; - compatible += grub_strlen (compatible) + 1; - } - return 0; -} - -static void -fdtbus_scan (struct grub_fdtbus_dev *parent) -{ - int node; - for (node = grub_fdt_first_node (dtb, parent ? parent->node : 0); node >= 0; - node = grub_fdt_next_node (dtb, node)) - { - struct grub_fdtbus_dev *dev; - struct grub_fdtbus_driver *driver; - dev = grub_zalloc (sizeof (*dev)); - if (!dev) - { - grub_print_error (); - return; - } - dev->node = node; - dev->next = devs; - dev->parent = parent; - devs = dev; - FOR_LIST_ELEMENTS(driver, drivers) - if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev)) - { - grub_dprintf ("fdtbus", "Attaching %s\n", driver->compatible); - if (driver->attach (dev) == GRUB_ERR_NONE) - { - grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible); - dev->driver = driver; - break; - } - grub_print_error (); - } - fdtbus_scan (dev); - } -} - -void -grub_fdtbus_register (struct grub_fdtbus_driver *driver) -{ - struct grub_fdtbus_dev *dev; - grub_dprintf ("fdtbus", "Registering %s\n", driver->compatible); - grub_list_push (GRUB_AS_LIST_P (&drivers), - GRUB_AS_LIST (driver)); - for (dev = devs; dev; dev = dev->next) - if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev)) - { - grub_dprintf ("fdtbus", "Attaching %s (%p)\n", driver->compatible, dev); - if (driver->attach (dev) == GRUB_ERR_NONE) - { - grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible); - dev->driver = driver; - } - grub_print_error (); - } -} - -void -grub_fdtbus_unregister (struct grub_fdtbus_driver *driver) -{ - grub_list_remove (GRUB_AS_LIST (driver)); - struct grub_fdtbus_dev *dev; - for (dev = devs; dev; dev = dev->next) - if (dev->driver == driver) - { - if (driver->detach) - driver->detach(dev); - dev->driver = 0; - } -} - -void -grub_fdtbus_init (const void *dtb_in, grub_size_t size) -{ - if (!dtb_in || grub_fdt_check_header (dtb_in, size) < 0) - grub_fatal ("invalid FDT"); - dtb = dtb_in; - const grub_uint32_t *prop = grub_fdt_get_prop (dtb, 0, "#address-cells", 0); - if (prop) - root_address_cells = grub_be_to_cpu32 (*prop); - else - root_address_cells = 1; - - prop = grub_fdt_get_prop (dtb, 0, "#size-cells", 0); - if (prop) - root_size_cells = grub_be_to_cpu32 (*prop); - else - root_size_cells = 1; - - fdtbus_scan (0); -} - -static int -get_address_cells (const struct grub_fdtbus_dev *dev) -{ - const grub_uint32_t *prop; - if (!dev) - return root_address_cells; - prop = grub_fdt_get_prop (dtb, dev->node, "#address-cells", 0); - if (prop) - return grub_be_to_cpu32 (*prop); - return 1; -} - -static int -get_size_cells (const struct grub_fdtbus_dev *dev) -{ - const grub_uint32_t *prop; - if (!dev) - return root_size_cells; - prop = grub_fdt_get_prop (dtb, dev->node, "#size-cells", 0); - if (prop) - return grub_be_to_cpu32 (*prop); - return 1; -} - -static grub_uint64_t -get64 (const grub_uint32_t *reg, grub_size_t cells) -{ - grub_uint64_t val = 0; - if (cells >= 1) - val = grub_be_to_cpu32 (reg[cells - 1]); - if (cells >= 2) - val |= ((grub_uint64_t) grub_be_to_cpu32 (reg[cells - 2])) << 32; - return val; -} - -static volatile void * -translate (const struct grub_fdtbus_dev *dev, const grub_uint32_t *reg) -{ - volatile void *ret; - const grub_uint32_t *ranges; - grub_size_t ranges_size, cells_per_mapping; - grub_size_t parent_address_cells, child_address_cells, child_size_cells; - grub_size_t nmappings, i; - if (dev == 0) - { - grub_uint64_t val; - val = get64 (reg, root_address_cells); - if (sizeof (void *) == 4 && (val >> 32)) - return grub_fdtbus_invalid_mapping; - return (void *) (grub_addr_t) val; - } - ranges = grub_fdt_get_prop (dtb, dev->node, "ranges", &ranges_size); - if (!ranges) - return grub_fdtbus_invalid_mapping; - if (ranges_size == 0) - return translate (dev->parent, reg); - parent_address_cells = get_address_cells (dev->parent); - child_address_cells = get_address_cells (dev); - child_size_cells = get_size_cells (dev); - cells_per_mapping = parent_address_cells + child_address_cells + child_size_cells; - nmappings = ranges_size / 4 / cells_per_mapping; - for (i = 0; i < nmappings; i++) - { - const grub_uint32_t *child_addr = &ranges[i * cells_per_mapping]; - const grub_uint32_t *parent_addr = child_addr + child_address_cells; - grub_uint64_t child_size = get64 (parent_addr + parent_address_cells, child_size_cells); - - if (child_address_cells > 2 && grub_memcmp (reg, child_addr, (child_address_cells - 2) * 4) != 0) - continue; - if (get64 (reg, child_address_cells) < get64 (child_addr, child_address_cells)) - continue; - - grub_uint64_t offset = get64 (reg, child_address_cells) - get64 (child_addr, child_address_cells); - if (offset >= child_size) - continue; - - ret = translate (dev->parent, parent_addr); - if (grub_fdtbus_is_mapping_valid (ret)) - ret = (volatile char *) ret + offset; - return ret; - } - return grub_fdtbus_invalid_mapping; -} - -volatile void * -grub_fdtbus_map_reg (const struct grub_fdtbus_dev *dev, int regno, grub_size_t *size) -{ - grub_size_t address_cells, size_cells; - address_cells = get_address_cells (dev->parent); - size_cells = get_size_cells (dev->parent); - const grub_uint32_t *reg = grub_fdt_get_prop (dtb, dev->node, "reg", 0); - if (size && size_cells) - *size = reg[(address_cells + size_cells) * regno + address_cells]; - if (size && !size_cells) - *size = 0; - return translate (dev->parent, reg + (address_cells + size_cells) * regno); -} - -const char * -grub_fdtbus_get_name (const struct grub_fdtbus_dev *dev) -{ - return grub_fdt_get_nodename (dtb, dev->node); -} - -const void * -grub_fdtbus_get_prop (const struct grub_fdtbus_dev *dev, - const char *name, - grub_uint32_t *len) -{ - return grub_fdt_get_prop (dtb, dev->node, name, len); -} - -const void * -grub_fdtbus_get_fdt (void) -{ - return dtb; -} diff --git a/grub-core/bus/spi/rk3288_spi.c b/grub-core/bus/spi/rk3288_spi.c deleted file mode 100644 index aacb79ffe..000000000 --- a/grub-core/bus/spi/rk3288_spi.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * - * Copyright (C) 2012 Google Inc. - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * This is based on depthcharge code. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -static grub_err_t -spi_send (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz) -{ - const grub_uint8_t *ptr = data, *end = ptr + sz; - volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0); - spi[2] = 0; - spi[1] = sz - 1; - spi[0] = ((1 << 18) | spi[0]) & ~(1 << 19); - spi[2] = 1; - while (ptr < end) - { - while (spi[9] & 2); - spi[256] = *ptr++; - } - while (spi[9] & 1); - return GRUB_ERR_NONE; -} - -static grub_err_t -spi_receive (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz) -{ - grub_uint8_t *ptr = data, *end = ptr + sz; - volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0); - spi[2] = 0; - spi[1] = sz - 1; - spi[0] = ((1 << 19) | spi[0]) & ~(1 << 18); - spi[2] = 1; - while (ptr < end) - { - while (spi[9] & 8); - *ptr++ = spi[512]; - } - while (spi[9] & 1); - return GRUB_ERR_NONE; -} - -static grub_err_t -spi_start (const struct grub_fdtbus_dev *dev) -{ - volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0); - spi[3] = 1; - return GRUB_ERR_NONE; -} - -static void -spi_stop (const struct grub_fdtbus_dev *dev) -{ - volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0); - spi[3] = 0; -} - -static grub_err_t -spi_attach(const struct grub_fdtbus_dev *dev) -{ - if (!grub_fdtbus_is_mapping_valid (grub_fdtbus_map_reg (dev, 0, 0))) - return GRUB_ERR_IO; - - return GRUB_ERR_NONE; -} - -static struct grub_fdtbus_driver spi = -{ - .compatible = "rockchip,rk3288-spi", - .attach = spi_attach, - .send = spi_send, - .receive = spi_receive, - .start = spi_start, - .stop = spi_stop, -}; - -void -grub_rk3288_spi_init (void) -{ - grub_fdtbus_register (&spi); -} diff --git a/grub-core/bus/usb/ehci-fdt.c b/grub-core/bus/usb/ehci-fdt.c deleted file mode 100644 index 29b50bdd5..000000000 --- a/grub-core/bus/usb/ehci-fdt.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ehci.c - EHCI Support. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2011 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -static grub_err_t -ehci_attach(const struct grub_fdtbus_dev *dev) -{ - grub_dprintf ("ehci", "Found generic-ehci\n"); - - grub_ehci_init_device (grub_fdtbus_map_reg (dev, 0, 0)); - return 0; -} - -struct grub_fdtbus_driver ehci = -{ - .compatible = "generic-ehci", - .attach = ehci_attach -}; - -void -grub_ehci_pci_scan (void) -{ - grub_fdtbus_register (&ehci); -} diff --git a/grub-core/bus/usb/ehci-pci.c b/grub-core/bus/usb/ehci-pci.c deleted file mode 100644 index 65e6cb574..000000000 --- a/grub-core/bus/usb/ehci-pci.c +++ /dev/null @@ -1,208 +0,0 @@ -/* ehci.c - EHCI Support. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2011 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#define GRUB_EHCI_PCI_SBRN_REG 0x60 -#define GRUB_EHCI_ADDR_MEM_MASK (~0xff) - -/* USBLEGSUP bits and related OS OWNED byte offset */ -enum -{ - GRUB_EHCI_BIOS_OWNED = (1 << 16), - GRUB_EHCI_OS_OWNED = (1 << 24) -}; - -/* PCI iteration function... */ -static int -grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid, - void *data __attribute__ ((unused))) -{ - volatile grub_uint32_t *regs; - grub_uint32_t base, base_h; - grub_uint32_t eecp_offset; - grub_uint32_t usblegsup = 0; - grub_uint64_t maxtime; - grub_uint32_t interf; - grub_uint32_t subclass; - grub_uint32_t class; - grub_uint8_t release; - grub_uint32_t class_code; - - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n"); - - if (pciid == GRUB_CS5536_PCIID) - { - grub_uint64_t basereg; - - basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE); - if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE)) - { - /* Shouldn't happen. */ - grub_dprintf ("ehci", "No EHCI address is assigned\n"); - return 0; - } - base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK); - basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER; - basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED; - basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS; - basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE; - grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg); - } - else - { - grub_pci_address_t addr; - addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); - class_code = grub_pci_read (addr) >> 8; - interf = class_code & 0xFF; - subclass = (class_code >> 8) & 0xFF; - class = class_code >> 16; - - /* If this is not an EHCI controller, just return. */ - if (class != 0x0c || subclass != 0x03 || interf != 0x20) - return 0; - - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n"); - - /* Check Serial Bus Release Number */ - addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG); - release = grub_pci_read_byte (addr); - if (release != 0x20) - { - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n", - release); - return 0; - } - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n"); - - /* Determine EHCI EHCC registers base address. */ - addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); - base = grub_pci_read (addr); - addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1); - base_h = grub_pci_read (addr); - /* Stop if registers are mapped above 4G - GRUB does not currently - * work with registers mapped above 4G */ - if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32) - && (base_h != 0)) - { - grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: registers above 4G are not supported\n"); - return 0; - } - base &= GRUB_PCI_ADDR_MEM_MASK; - if (!base) - { - grub_dprintf ("ehci", - "EHCI: EHCI is not mapped\n"); - return 0; - } - - /* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */ - addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); - grub_pci_write_word(addr, - GRUB_PCI_COMMAND_MEM_ENABLED - | GRUB_PCI_COMMAND_BUS_MASTER - | grub_pci_read_word(addr)); - - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n"); - } - - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n", - (base & GRUB_EHCI_ADDR_MEM_MASK)); - - regs = grub_pci_device_map_range (dev, - (base & GRUB_EHCI_ADDR_MEM_MASK), - 0x100); - - /* Is there EECP ? */ - eecp_offset = (grub_le_to_cpu32 (regs[2]) >> 8) & 0xff; - - /* Determine and change ownership. */ - /* EECP offset valid in HCCPARAMS */ - /* Ownership can be changed via EECP only */ - if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40) - { - grub_pci_address_t pciaddr_eecp; - pciaddr_eecp = grub_pci_make_address (dev, eecp_offset); - - usblegsup = grub_pci_read (pciaddr_eecp); - if (usblegsup & GRUB_EHCI_BIOS_OWNED) - { - grub_boot_time ("Taking ownership of EHCI controller"); - grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n"); - /* Ownership change - set OS_OWNED bit */ - grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED); - /* Ensure PCI register is written */ - grub_pci_read (pciaddr_eecp); - - /* Wait for finish of ownership change, EHCI specification - * doesn't say how long it can take... */ - maxtime = grub_get_time_ms () + 1000; - while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED) - && (grub_get_time_ms () < maxtime)); - if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED) - { - grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: EHCI change ownership timeout"); - /* Change ownership in "hard way" - reset BIOS ownership */ - grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED); - /* Ensure PCI register is written */ - grub_pci_read (pciaddr_eecp); - } - } - else if (usblegsup & GRUB_EHCI_OS_OWNED) - /* XXX: What to do in this case - nothing ? Can it happen ? */ - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n"); - else - { - grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n"); - /* XXX: What to do in this case ? Can it happen ? - * Is code below correct ? */ - /* Ownership change - set OS_OWNED bit */ - grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED); - /* Ensure PCI register is written */ - grub_pci_read (pciaddr_eecp); - } - - /* Disable SMI, just to be sure. */ - pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4); - grub_pci_write (pciaddr_eecp, 0); - /* Ensure PCI register is written */ - grub_pci_read (pciaddr_eecp); - } - - grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n"); - - grub_ehci_init_device (regs); - return 0; -} - -void -grub_ehci_pci_scan (void) -{ - grub_pci_iterate (grub_ehci_pci_iter, NULL); -} diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c index d966fc210..8ece40086 100644 --- a/grub-core/bus/usb/ehci.c +++ b/grub-core/bus/usb/ehci.c @@ -22,11 +22,13 @@ #include #include #include +#include +#include +#include #include #include +#include #include -#include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -36,6 +38,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); * - is not supporting interrupt transfers */ +#define GRUB_EHCI_PCI_SBRN_REG 0x60 + /* Capability registers offsets */ enum { @@ -49,6 +53,7 @@ enum #define GRUB_EHCI_EECP_MASK (0xff << 8) #define GRUB_EHCI_EECP_SHIFT 8 +#define GRUB_EHCI_ADDR_MEM_MASK (~0xff) #define GRUB_EHCI_POINTER_MASK (~0x1f) /* Capability register SPARAMS bits */ @@ -79,6 +84,13 @@ enum #define GRUB_EHCI_QH_EMPTY 1 +/* USBLEGSUP bits and related OS OWNED byte offset */ +enum +{ + GRUB_EHCI_BIOS_OWNED = (1 << 16), + GRUB_EHCI_OS_OWNED = (1 << 24) +}; + /* Operational registers offsets */ enum { @@ -325,21 +337,6 @@ struct grub_ehci static struct grub_ehci *ehci; -static void -sync_all_caches (struct grub_ehci *e) -{ - if (!e) - return; - if (e->td_virt) - grub_arch_sync_dma_caches (e->td_virt, sizeof (struct grub_ehci_td) * - GRUB_EHCI_N_TD); - if (e->qh_virt) - grub_arch_sync_dma_caches (e->qh_virt, sizeof (struct grub_ehci_qh) * - GRUB_EHCI_N_QH); - if (e->framelist_virt) - grub_arch_sync_dma_caches (e->framelist_virt, 4096); -} - /* EHCC registers access functions */ static inline grub_uint32_t grub_ehci_ehcc_read32 (struct grub_ehci *e, grub_uint32_t addr) @@ -440,12 +437,9 @@ grub_ehci_reset (struct grub_ehci *e) { grub_uint64_t maxtime; - sync_all_caches (e); - - grub_dprintf ("ehci", "reset\n"); - grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND, - GRUB_EHCI_CMD_HC_RESET); + GRUB_EHCI_CMD_HC_RESET + | grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND)); /* Ensure command is written */ grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND); /* XXX: How long time could take reset of HC ? */ @@ -461,24 +455,116 @@ grub_ehci_reset (struct grub_ehci *e) } /* PCI iteration function... */ -void -grub_ehci_init_device (volatile void *regs) +static int +grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid, + void *data __attribute__ ((unused))) { + grub_uint8_t release; + grub_uint32_t class_code; + grub_uint32_t interf; + grub_uint32_t subclass; + grub_uint32_t class; + grub_uint32_t base, base_h; struct grub_ehci *e; + grub_uint32_t eecp_offset; grub_uint32_t fp; int i; + grub_uint32_t usblegsup = 0; + grub_uint64_t maxtime; grub_uint32_t n_ports; grub_uint8_t caplen; + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: begin\n"); + + if (pciid == GRUB_CS5536_PCIID) + { + grub_uint64_t basereg; + + basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE); + if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE)) + { + /* Shouldn't happen. */ + grub_dprintf ("ehci", "No EHCI address is assigned\n"); + return 0; + } + base = (basereg & GRUB_CS5536_MSR_USB_BASE_ADDR_MASK); + basereg |= GRUB_CS5536_MSR_USB_BASE_BUS_MASTER; + basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_ENABLED; + basereg &= ~GRUB_CS5536_MSR_USB_BASE_PME_STATUS; + basereg &= ~GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE; + grub_cs5536_write_msr (dev, GRUB_CS5536_MSR_USB_EHCI_BASE, basereg); + } + else + { + grub_pci_address_t addr; + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class_code = grub_pci_read (addr) >> 8; + interf = class_code & 0xFF; + subclass = (class_code >> 8) & 0xFF; + class = class_code >> 16; + + /* If this is not an EHCI controller, just return. */ + if (class != 0x0c || subclass != 0x03 || interf != 0x20) + return 0; + + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: class OK\n"); + + /* Check Serial Bus Release Number */ + addr = grub_pci_make_address (dev, GRUB_EHCI_PCI_SBRN_REG); + release = grub_pci_read_byte (addr); + if (release != 0x20) + { + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: Wrong SBRN: %0x\n", + release); + return 0; + } + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: bus rev. num. OK\n"); + + /* Determine EHCI EHCC registers base address. */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0); + base = grub_pci_read (addr); + addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG1); + base_h = grub_pci_read (addr); + /* Stop if registers are mapped above 4G - GRUB does not currently + * work with registers mapped above 4G */ + if (((base & GRUB_PCI_ADDR_MEM_TYPE_MASK) != GRUB_PCI_ADDR_MEM_TYPE_32) + && (base_h != 0)) + { + grub_dprintf ("ehci", + "EHCI grub_ehci_pci_iter: registers above 4G are not supported\n"); + return 0; + } + base &= GRUB_PCI_ADDR_MEM_MASK; + if (!base) + { + grub_dprintf ("ehci", + "EHCI: EHCI is not mapped\n"); + return 0; + } + + /* Set bus master - needed for coreboot, VMware, broken BIOSes etc. */ + addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); + grub_pci_write_word(addr, + GRUB_PCI_COMMAND_MEM_ENABLED + | GRUB_PCI_COMMAND_BUS_MASTER + | grub_pci_read_word(addr)); + + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: 32-bit EHCI OK\n"); + } + /* Allocate memory for the controller and fill basic values. */ e = grub_zalloc (sizeof (*e)); if (!e) - return; + return 1; e->framelist_chunk = NULL; e->td_chunk = NULL; e->qh_chunk = NULL; - e->iobase_ehcc = regs; + e->iobase_ehcc = grub_pci_device_map_range (dev, + (base & GRUB_EHCI_ADDR_MEM_MASK), + 0x100); + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of EHCC: %08x\n", + (base & GRUB_EHCI_ADDR_MEM_MASK)); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CAPLEN: %02x\n", grub_ehci_ehcc_read8 (e, GRUB_EHCI_EHCC_CAPLEN)); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: VERSION: %04x\n", @@ -494,7 +580,7 @@ grub_ehci_init_device (volatile void *regs) if (caplen & (sizeof (grub_uint32_t) - 1)) { grub_dprintf ("ehci", "Unaligned caplen\n"); - return; + return 0; } e->iobase = ((volatile grub_uint32_t *) e->iobase_ehcc + (caplen / sizeof (grub_uint32_t))); @@ -504,8 +590,8 @@ grub_ehci_init_device (volatile void *regs) #endif grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: iobase of oper. regs: %08llxx\n", - (unsigned long long) (grub_addr_t) e->iobase_ehcc + caplen); + "EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n", + (base & GRUB_EHCI_ADDR_MEM_MASK) + caplen); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n", grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND)); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n", @@ -521,6 +607,10 @@ grub_ehci_init_device (volatile void *regs) grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n", grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG)); + /* Is there EECP ? */ + eecp_offset = (grub_ehci_ehcc_read32 (e, GRUB_EHCI_EHCC_CPARAMS) + & GRUB_EHCI_EECP_MASK) >> GRUB_EHCI_EECP_SHIFT; + /* Check format of data structures requested by EHCI */ /* XXX: In fact it is not used at any place, it is prepared for future * This implementation uses 32-bits pointers only */ @@ -624,6 +714,65 @@ grub_ehci_init_device (volatile void *regs) grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: QH/TD init. OK\n"); + /* Determine and change ownership. */ + /* EECP offset valid in HCCPARAMS */ + /* Ownership can be changed via EECP only */ + if (pciid != GRUB_CS5536_PCIID && eecp_offset >= 0x40) + { + grub_pci_address_t pciaddr_eecp; + pciaddr_eecp = grub_pci_make_address (dev, eecp_offset); + + usblegsup = grub_pci_read (pciaddr_eecp); + if (usblegsup & GRUB_EHCI_BIOS_OWNED) + { + grub_boot_time ("Taking ownership of EHCI controller"); + grub_dprintf ("ehci", + "EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n"); + /* Ownership change - set OS_OWNED bit */ + grub_pci_write (pciaddr_eecp, usblegsup | GRUB_EHCI_OS_OWNED); + /* Ensure PCI register is written */ + grub_pci_read (pciaddr_eecp); + + /* Wait for finish of ownership change, EHCI specification + * doesn't say how long it can take... */ + maxtime = grub_get_time_ms () + 1000; + while ((grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED) + && (grub_get_time_ms () < maxtime)); + if (grub_pci_read (pciaddr_eecp) & GRUB_EHCI_BIOS_OWNED) + { + grub_dprintf ("ehci", + "EHCI grub_ehci_pci_iter: EHCI change ownership timeout"); + /* Change ownership in "hard way" - reset BIOS ownership */ + grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED); + /* Ensure PCI register is written */ + grub_pci_read (pciaddr_eecp); + } + } + else if (usblegsup & GRUB_EHCI_OS_OWNED) + /* XXX: What to do in this case - nothing ? Can it happen ? */ + grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: EHCI owned by: OS\n"); + else + { + grub_dprintf ("ehci", + "EHCI grub_ehci_pci_iter: EHCI owned by: NONE\n"); + /* XXX: What to do in this case ? Can it happen ? + * Is code below correct ? */ + /* Ownership change - set OS_OWNED bit */ + grub_pci_write (pciaddr_eecp, GRUB_EHCI_OS_OWNED); + /* Ensure PCI register is written */ + grub_pci_read (pciaddr_eecp); + } + + /* Disable SMI, just to be sure. */ + pciaddr_eecp = grub_pci_make_address (dev, eecp_offset + 4); + grub_pci_write (pciaddr_eecp, 0); + /* Ensure PCI register is written */ + grub_pci_read (pciaddr_eecp); + + } + + grub_dprintf ("ehci", "inithw: EHCI grub_ehci_pci_iter: ownership OK\n"); + /* Now we can setup EHCI (maybe...) */ /* Check if EHCI is halted and halt it if not */ @@ -691,13 +840,11 @@ grub_ehci_init_device (volatile void *regs) e->next = ehci; ehci = e; - sync_all_caches (e); - grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: OK at all\n"); grub_dprintf ("ehci", - "EHCI grub_ehci_pci_iter: iobase of oper. regs: %08llx\n", - (unsigned long long) (grub_addr_t) regs); + "EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n", + (base & GRUB_EHCI_ADDR_MEM_MASK)); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: COMMAND: %08x\n", grub_ehci_oper_read32 (e, GRUB_EHCI_COMMAND)); grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: STATUS: %08x\n", @@ -713,7 +860,7 @@ grub_ehci_init_device (volatile void *regs) grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: CONFIG_FLAG: %08x\n", grub_ehci_oper_read32 (e, GRUB_EHCI_CONFIG_FLAG)); - return; + return 0; fail: if (e) @@ -727,7 +874,7 @@ fail: } grub_free (e); - return; + return 0; } static int @@ -873,7 +1020,6 @@ grub_ehci_find_qh (struct grub_ehci *e, grub_usb_transfer_t transfer) /* Found proper existing (and linked) QH, do setup of QH */ grub_dprintf ("ehci", "find_qh: found, QH=%p\n", qh_iter); grub_ehci_setup_qh (qh_iter, transfer); - sync_all_caches (e); return qh_iter; } @@ -975,7 +1121,7 @@ grub_ehci_free_tds (struct grub_ehci *e, grub_ehci_td_t td, token = grub_le_to_cpu32 (td->token); to_transfer = (token & GRUB_EHCI_TOTAL_MASK) >> GRUB_EHCI_TOTAL_OFF; - /* Check state of TD - if it did not transfer + /* Check state of TD - if it did not transfered * whole data then set last_trans - it should be last executed TD * in case when something went wrong. */ if (transfer && (td->size != to_transfer)) @@ -1143,28 +1289,16 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, grub_ehci_td_t td_prev = NULL; int i; struct grub_ehci_transfer_controller_data *cdata; - grub_uint32_t status; - - sync_all_caches (e); /* Check if EHCI is running and AL is enabled */ - status = grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS); - if ((status & GRUB_EHCI_ST_HC_HALTED) != 0) + if ((grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS) + & GRUB_EHCI_ST_HC_HALTED) != 0) /* XXX: Fix it: Currently we don't do anything to restart EHCI */ - { - grub_dprintf ("ehci", "setup_transfer: halted, status = 0x%x\n", - status); - return GRUB_USB_ERR_INTERNAL; - } - status = grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS); - if ((status + return GRUB_USB_ERR_INTERNAL; + if ((grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS) & (GRUB_EHCI_ST_AS_STATUS | GRUB_EHCI_ST_PS_STATUS)) == 0) /* XXX: Fix it: Currently we don't do anything to restart EHCI */ - { - grub_dprintf ("ehci", "setup_transfer: no AS/PS, status = 0x%x\n", - status); - return GRUB_USB_ERR_INTERNAL; - } + return GRUB_USB_ERR_INTERNAL; /* Allocate memory for controller transfer data. */ cdata = grub_malloc (sizeof (*cdata)); @@ -1176,7 +1310,6 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, cdata->qh_virt = grub_ehci_find_qh (e, transfer); if (!cdata->qh_virt) { - grub_dprintf ("ehci", "setup_transfer: no QH\n"); grub_free (cdata); return GRUB_USB_ERR_INTERNAL; } @@ -1186,7 +1319,6 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, cdata->td_alt_virt = grub_ehci_alloc_td (e); if (!cdata->td_alt_virt) { - grub_dprintf ("ehci", "setup_transfer: no TDs\n"); grub_free (cdata); return GRUB_USB_ERR_INTERNAL; } @@ -1213,7 +1345,6 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, grub_ehci_free_tds (e, cdata->td_first_virt, NULL, &actual); grub_free (cdata); - grub_dprintf ("ehci", "setup_transfer: no TD\n"); return GRUB_USB_ERR_INTERNAL; } @@ -1255,8 +1386,6 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, * i.e. reset token */ cdata->qh_virt->td_overlay.token = grub_cpu_to_le32_compile_time (0); - sync_all_caches (e); - /* Finito */ transfer->controller_data = cdata; @@ -1305,8 +1434,6 @@ grub_ehci_parse_notrun (grub_usb_controller_t dev, grub_ehci_free_td (e, cdata->td_alt_virt); grub_free (cdata); - sync_all_caches (e); - /* Additionally, do something with EHCI to make it running (what?) */ /* Try enable EHCI and AL */ grub_ehci_oper_write32 (e, GRUB_EHCI_COMMAND, @@ -1342,8 +1469,6 @@ grub_ehci_parse_halt (grub_usb_controller_t dev, grub_ehci_free_td (e, cdata->td_alt_virt); grub_free (cdata); - sync_all_caches (e); - /* Evaluation of error code - currently we don't have GRUB USB error * codes for some EHCI states, GRUB_USB_ERR_DATA is used for them. * Order of evaluation is critical, specially bubble/stall. */ @@ -1377,8 +1502,6 @@ grub_ehci_parse_success (grub_usb_controller_t dev, grub_ehci_free_td (e, cdata->td_alt_virt); grub_free (cdata); - sync_all_caches (e); - return GRUB_USB_ERR_NONE; } @@ -1392,8 +1515,6 @@ grub_ehci_check_transfer (grub_usb_controller_t dev, transfer->controller_data; grub_uint32_t token, token_ftd; - sync_all_caches (e); - grub_dprintf ("ehci", "check_transfer: EHCI STATUS=%08x, cdata=%p, qh=%p\n", grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS), @@ -1460,9 +1581,6 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev, int i; grub_uint64_t maxtime; grub_uint32_t qh_phys; - - sync_all_caches (e); - grub_uint32_t interrupt = cdata->qh_virt->ep_cap & GRUB_EHCI_SMASK_MASK; @@ -1482,7 +1600,6 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev, grub_ehci_free_tds (e, cdata->td_first_virt, transfer, &actual); grub_ehci_free_td (e, cdata->td_alt_virt); grub_free (cdata); - sync_all_caches (e); grub_dprintf ("ehci", "cancel_transfer: end - EHCI not running\n"); return GRUB_USB_ERR_NONE; } @@ -1505,8 +1622,6 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev, /* Unlink QH from AL */ e->qh_virt[i].qh_hptr = cdata->qh_virt->qh_hptr; - sync_all_caches (e); - /* If this is an interrupt transfer, we just wait for the periodic * schedule to advance a few times and then assume that the EHCI * controller has read the updated QH. */ @@ -1561,8 +1676,6 @@ grub_ehci_cancel_transfer (grub_usb_controller_t dev, grub_dprintf ("ehci", "cancel_transfer: end\n"); - sync_all_caches (e); - return GRUB_USB_ERR_NONE; } @@ -1664,6 +1777,11 @@ grub_ehci_detect_dev (grub_usb_controller_t dev, int port, int *changed) status = grub_ehci_port_read (e, port); + grub_dprintf ("ehci", "detect_dev: EHCI STATUS: %08x\n", + grub_ehci_oper_read32 (e, GRUB_EHCI_STATUS)); + grub_dprintf ("ehci", "detect_dev: iobase=%p, port=%d, status=0x%02x\n", + e->iobase, port, status); + /* Connect Status Change bit - it detects change of connection */ if (status & GRUB_EHCI_PORT_CONNECT_CH) { @@ -1724,6 +1842,12 @@ grub_ehci_detect_dev (grub_usb_controller_t dev, int port, int *changed) } } +static void +grub_ehci_inithw (void) +{ + grub_pci_iterate (grub_ehci_pci_iter, NULL); +} + static grub_err_t grub_ehci_restore_hw (void) { @@ -1824,7 +1948,7 @@ GRUB_MOD_INIT (ehci) grub_stop_disk_firmware (); grub_boot_time ("Initing EHCI hardware"); - grub_ehci_pci_scan (); + grub_ehci_inithw (); grub_boot_time ("Registering EHCI driver"); grub_usb_controller_dev_register (&usb_controller); grub_boot_time ("EHCI driver registered"); diff --git a/grub-core/bus/usb/emu/usb.c b/grub-core/bus/usb/emu/usb.c new file mode 100644 index 000000000..3ad2fc312 --- /dev/null +++ b/grub-core/bus/usb/emu/usb.c @@ -0,0 +1,203 @@ +/* usb.c -- libusb USB support for GRUB. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + + +static struct grub_usb_controller_dev usb_controller = +{ + .name = "libusb" +}; + +static struct grub_usb_device *grub_usb_devs[128]; + +struct usb_bus *busses; + +static grub_err_t +grub_libusb_devices (void) + +{ + struct usb_bus *bus; + int last = 0; + + busses = usb_get_busses(); + + for (bus = busses; bus; bus = bus->next) + { + struct usb_device *usbdev; + struct grub_usb_device *dev; + + for (usbdev = bus->devices; usbdev; usbdev = usbdev->next) + { + struct usb_device_descriptor *desc = &usbdev->descriptor; + grub_err_t err; + + if (! desc->bcdUSB) + continue; + + dev = grub_malloc (sizeof (*dev)); + if (! dev) + return grub_errno; + + dev->data = usbdev; + + /* Fill in all descriptors. */ + err = grub_usb_device_initialize (dev); + if (err) + { + grub_errno = GRUB_ERR_NONE; + continue; + } + + /* Register the device. */ + grub_usb_devs[last++] = dev; + } + } + + return GRUB_USB_ERR_NONE; +} + +void +grub_usb_poll_devices (void) +{ + /* TODO: recheck grub_usb_devs */ +} + + +int +grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data) +{ + int i; + + for (i = 0; i < 128; i++) + { + if (grub_usb_devs[i]) + { + if (hook (grub_usb_devs[i], hook_data)) + return 1; + } + } + + return 0; +} + +grub_usb_err_t +grub_usb_root_hub (grub_usb_controller_t controller __attribute__((unused))) +{ + return GRUB_USB_ERR_NONE; +} + +grub_usb_err_t +grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype, + grub_uint8_t request, grub_uint16_t value, + grub_uint16_t idx, grub_size_t size, char *data) +{ + usb_dev_handle *devh; + struct usb_device *d = dev->data; + + devh = usb_open (d); + if (usb_control_msg (devh, reqtype, request, + value, idx, data, size, 20) < 0) + { + usb_close (devh); + return GRUB_USB_ERR_STALL; + } + + usb_close (devh); + + return GRUB_USB_ERR_NONE; +} + +grub_usb_err_t +grub_usb_bulk_read (grub_usb_device_t dev, + int endpoint, grub_size_t size, char *data) +{ + usb_dev_handle *devh; + struct usb_device *d = dev->data; + + devh = usb_open (d); + if (usb_claim_interface (devh, 0) < 1) + { + usb_close (devh); + return GRUB_USB_ERR_STALL; + } + + if (usb_bulk_read (devh, endpoint, data, size, 20) < 1) + { + usb_close (devh); + return GRUB_USB_ERR_STALL; + } + + usb_release_interface (devh, 0); + usb_close (devh); + + return GRUB_USB_ERR_NONE; +} + +grub_usb_err_t +grub_usb_bulk_write (grub_usb_device_t dev, + int endpoint, grub_size_t size, char *data) +{ + usb_dev_handle *devh; + struct usb_device *d = dev->data; + + devh = usb_open (d); + if (usb_claim_interface (devh, 0) < 0) + goto fail; + + if (usb_bulk_write (devh, endpoint, data, size, 20) < 0) + goto fail; + + if (usb_release_interface (devh, 0) < 0) + goto fail; + + usb_close (devh); + + return GRUB_USB_ERR_NONE; + + fail: + usb_close (devh); + return GRUB_USB_ERR_STALL; +} + +GRUB_MOD_INIT (libusb) +{ + usb_init(); + usb_find_busses(); + usb_find_devices(); + + if (grub_libusb_devices ()) + return; + + grub_usb_controller_dev_register (&usb_controller); + + return; +} + +GRUB_MOD_FINI (libusb) +{ + return; +} diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c index f0be533d4..d27bfe7fb 100644 --- a/grub-core/bus/usb/ohci.c +++ b/grub-core/bus/usb/ohci.c @@ -750,10 +750,7 @@ grub_ohci_setup_transfer (grub_usb_controller_t dev, { cdata->td_head_virt = grub_ohci_alloc_td (o); if (!cdata->td_head_virt) - { - grub_free (cdata); - return GRUB_USB_ERR_INTERNAL; /* We don't need de-allocate ED */ - } + return GRUB_USB_ERR_INTERNAL; /* We don't need de-allocate ED */ /* We can set td_head only when ED is not active, i.e. * when it is newly allocated. */ cdata->ed_virt->td_head diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c index 7c5811fd6..a95fdfe07 100644 --- a/grub-core/bus/usb/uhci.c +++ b/grub-core/bus/usb/uhci.c @@ -625,7 +625,9 @@ grub_uhci_check_transfer (grub_usb_controller_t dev, return GRUB_USB_ERR_NONE; } - if (errtd && !(errtd->ctrl_status & (1 << 23))) + grub_dprintf ("uhci", "t status=0x%02x\n", errtd->ctrl_status); + + if (!(errtd->ctrl_status & (1 << 23))) { grub_usb_err_t err = GRUB_USB_ERR_NONE; diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index a06cce302..34a7ff1b5 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) grub_usb_set_configuration (dev, 1); dev->nports = hubdesc.portcnt; - dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); - dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); + dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); + dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); if (!dev->children || !dev->ports) { grub_free (dev->children); @@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d /* Query the number of ports the root Hub has. */ hub->nports = controller->dev->hubports (controller); - hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); - hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); + hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); + hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); if (!hub->devices || !hub->ports) { grub_free (hub->devices); diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c index 85f081fff..b614997f2 100644 --- a/grub-core/bus/usb/usbtrans.c +++ b/grub-core/bus/usb/usbtrans.c @@ -18,13 +18,12 @@ */ #include -#include +#include #include #include #include #include #include -#include static inline unsigned int @@ -102,8 +101,6 @@ grub_usb_control_msg (grub_usb_device_t dev, data_addr = grub_dma_get_phys (data_chunk); grub_memcpy ((char *) data, data_in, size); - grub_arch_sync_dma_caches (data, size); - grub_dprintf ("usb", "control: reqtype=0x%02x req=0x%02x val=0x%02x idx=0x%02x size=%lu\n", reqtype, request, value, index, (unsigned long)size); @@ -164,8 +161,6 @@ grub_usb_control_msg (grub_usb_device_t dev, setupdata->value = value; setupdata->index = index; setupdata->length = size; - grub_arch_sync_dma_caches (setupdata, sizeof (*setupdata)); - transfer->transactions[0].size = sizeof (*setupdata); transfer->transactions[0].pid = GRUB_USB_TRANSFER_TYPE_SETUP; transfer->transactions[0].data = setupdata_addr; @@ -207,13 +202,11 @@ grub_usb_control_msg (grub_usb_device_t dev, grub_free (transfer->transactions); grub_free (transfer); + grub_dma_free (data_chunk); grub_dma_free (setupdata_chunk); - grub_arch_sync_dma_caches (data, size0); grub_memcpy (data_in, (char *) data, size0); - grub_dma_free (data_chunk); - return err; } @@ -243,10 +236,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev, data = grub_dma_get_virt (data_chunk); data_addr = grub_dma_get_phys (data_chunk); if (type == GRUB_USB_TRANSFER_TYPE_OUT) - { - grub_memcpy ((char *) data, data_in, size); - grub_arch_sync_dma_caches (data, size); - } + grub_memcpy ((char *) data, data_in, size); /* Create a transfer. */ transfer = grub_malloc (sizeof (struct grub_usb_transfer)); @@ -316,17 +306,13 @@ grub_usb_bulk_finish_readwrite (grub_usb_transfer_t transfer) dev->toggle[transfer->endpoint] = toggle; if (transfer->dir == GRUB_USB_TRANSFER_TYPE_IN) - { - grub_arch_sync_dma_caches (grub_dma_get_virt (transfer->data_chunk), - transfer->size + 1); - grub_memcpy (transfer->data, (void *) - grub_dma_get_virt (transfer->data_chunk), - transfer->size + 1); - } + grub_memcpy (transfer->data, (void *) + grub_dma_get_virt (transfer->data_chunk), + transfer->size + 1); grub_free (transfer->transactions); - grub_dma_free (transfer->data_chunk); grub_free (transfer); + grub_dma_free (transfer->data_chunk); } static grub_usb_err_t diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c index 5a1499aa0..97c2cf282 100644 --- a/grub-core/commands/acpi.c +++ b/grub-core/commands/acpi.c @@ -61,6 +61,18 @@ static const struct grub_arg_option options[] = { {0, 0, 0, 0, 0, 0} }; +/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */ +grub_uint8_t +grub_byte_checksum (void *base, grub_size_t size) +{ + grub_uint8_t *ptr; + grub_uint8_t ret = 0; + for (ptr = (grub_uint8_t *) base; ptr < ((grub_uint8_t *) base) + size; + ptr++) + ret += *ptr; + return ret; +} + /* rev1 is 1 if ACPIv1 is to be generated, 0 otherwise. rev2 contains the revision of ACPIv2+ to generate or 0 if none. */ static int rev1, rev2; @@ -119,8 +131,6 @@ grub_acpi_get_rsdpv1 (void) return grub_machine_acpi_get_rsdpv1 (); } -#if defined (__i386__) || defined (__x86_64__) - static inline int iszero (grub_uint8_t *reg, int size) { @@ -131,6 +141,7 @@ iszero (grub_uint8_t *reg, int size) return 1; } +#if defined (__i386__) || defined (__x86_64__) /* Context for grub_acpi_create_ebda. */ struct grub_acpi_create_ebda_ctx { int ebda_len; @@ -168,10 +179,8 @@ grub_acpi_create_ebda (void) struct grub_acpi_rsdp_v20 *v2; ebda = (grub_uint8_t *) (grub_addr_t) ((*((grub_uint16_t *)0x40e)) << 4); - grub_dprintf ("acpi", "EBDA @%p\n", ebda); if (ebda) ebda_kb_len = *(grub_uint16_t *) ebda; - grub_dprintf ("acpi", "EBDA length 0x%x\n", ebda_kb_len); if (ebda_kb_len > 16) ebda_kb_len = 0; ctx.ebda_len = (ebda_kb_len + 1) << 10; @@ -218,7 +227,7 @@ grub_acpi_create_ebda (void) grub_dprintf ("acpi", "Copying rsdpv2 to %p\n", target); v2inebda = target; target += v2->length; - target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16); + target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1); v2 = 0; break; } @@ -237,7 +246,7 @@ grub_acpi_create_ebda (void) grub_dprintf ("acpi", "Copying rsdpv1 to %p\n", target); v1inebda = target; target += sizeof (struct grub_acpi_rsdp_v10); - target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16); + target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1); v1 = 0; break; } @@ -256,7 +265,7 @@ grub_acpi_create_ebda (void) grub_memcpy (target, v2, v2->length); v2inebda = target; target += v2->length; - target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16); + target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1); v2 = 0; break; } @@ -273,7 +282,7 @@ grub_acpi_create_ebda (void) grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10)); v1inebda = target; target += sizeof (struct grub_acpi_rsdp_v10); - target = (grub_uint8_t *) ALIGN_UP((grub_addr_t) target, 16); + target = (grub_uint8_t *) ((((grub_addr_t) target - 1) | 0xf) + 1); v1 = 0; break; } @@ -485,8 +494,6 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) if (! rsdp) rsdp = grub_machine_acpi_get_rsdpv1 (); - grub_dprintf ("acpi", "RSDP @%p\n", rsdp); - if (rsdp) { grub_uint32_t *entry_ptr; @@ -593,9 +600,6 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) if (! table->addr) { free_tables (); - grub_free (exclude); - grub_free (load_only); - grub_free (table); return grub_errno; } table->next = acpi_tables; @@ -635,7 +639,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) grub_size_t size; char *buf; - file = grub_file_open (args[i], GRUB_FILE_TYPE_ACPI_TABLE); + file = grub_file_open (args[i]); if (! file) { free_tables (); @@ -761,10 +765,10 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID; struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID; - efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table, - &acpi20, grub_acpi_get_rsdpv2 ()); - efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table, - &acpi, grub_acpi_get_rsdpv1 ()); + grub_efi_system_table->boot_services->install_configuration_table + (&acpi20, grub_acpi_get_rsdpv2 ()); + grub_efi_system_table->boot_services->install_configuration_table + (&acpi, grub_acpi_get_rsdpv1 ()); } #endif diff --git a/grub-core/commands/acpihalt.c b/grub-core/commands/acpihalt.c index 9cc7f18e3..da68b5b52 100644 --- a/grub-core/commands/acpihalt.c +++ b/grub-core/commands/acpihalt.c @@ -26,8 +26,6 @@ #define grub_dprintf(cond, args...) printf ( args ) #define grub_printf printf -#define grub_util_fopen fopen -#define grub_memcmp memcmp typedef uint64_t grub_uint64_t; typedef uint32_t grub_uint32_t; typedef uint16_t grub_uint16_t; @@ -248,7 +246,6 @@ get_sleep_type (grub_uint8_t *table, grub_uint8_t *ptr, grub_uint8_t *end, if (!add) return -1; break; - case GRUB_ACPI_OPCODE_CREATE_DWORD_FIELD: case GRUB_ACPI_OPCODE_CREATE_WORD_FIELD: case GRUB_ACPI_OPCODE_CREATE_BYTE_FIELD: { diff --git a/grub-core/commands/blocklist.c b/grub-core/commands/blocklist.c index 944449b77..d1a47b504 100644 --- a/grub-core/commands/blocklist.c +++ b/grub-core/commands/blocklist.c @@ -121,8 +121,8 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)), if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (args[0], GRUB_FILE_TYPE_PRINT_BLOCKLIST - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (args[0]); if (! file) return grub_errno; diff --git a/grub-core/commands/cacheinfo.c b/grub-core/commands/cacheinfo.c index d34a34696..ead6ff82c 100644 --- a/grub-core/commands/cacheinfo.c +++ b/grub-core/commands/cacheinfo.c @@ -23,8 +23,6 @@ #include #include -GRUB_MOD_LICENSE ("GPLv3+"); - static grub_err_t grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/commands/cat.c b/grub-core/commands/cat.c index ba5f0061a..8a7f1af78 100644 --- a/grub-core/commands/cat.c +++ b/grub-core/commands/cat.c @@ -56,7 +56,7 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args) if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (args[0], GRUB_FILE_TYPE_CAT); + file = grub_file_open (args[0]); if (! file) return grub_errno; @@ -140,13 +140,10 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args) grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); } - if (utcount) - { - grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); - for (j = 0; j < utcount; j++) - grub_printf ("<%x>", (unsigned int) utbuf[j]); - grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); - } + grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); + for (j = 0; j < utcount; j++) + grub_printf ("<%x>", (unsigned int) utbuf[j]); + grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); grub_xputs ("\n"); grub_refresh (); diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c index e9c3b25d3..cc23ee67e 100644 --- a/grub-core/commands/cmp.c +++ b/grub-core/commands/cmp.c @@ -45,8 +45,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), grub_printf_ (N_("Compare file `%s' with `%s':\n"), args[0], args[1]); - file1 = grub_file_open (args[0], GRUB_FILE_TYPE_CMP); - file2 = grub_file_open (args[1], GRUB_FILE_TYPE_CMP); + file1 = grub_file_open (args[0]); + file2 = grub_file_open (args[1]); if (! file1 || ! file2) goto cleanup; diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c index 5cb4fafd4..8e1f41f14 100644 --- a/grub-core/commands/date.c +++ b/grub-core/commands/date.c @@ -59,8 +59,7 @@ grub_cmd_date (grub_command_t cmd __attribute__ ((unused)), for (; argc; argc--, args++) { - const char *p; - char c; + char *p, c; int m1, ofs, n, cur_mask; p = args[0]; diff --git a/grub-core/kern/efi/acpi.c b/grub-core/commands/efi/acpi.c similarity index 100% rename from grub-core/kern/efi/acpi.c rename to grub-core/commands/efi/acpi.c diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c index d41d521a4..132cadbc7 100644 --- a/grub-core/commands/efi/loadbios.c +++ b/grub-core/commands/efi/loadbios.c @@ -169,7 +169,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)), if (argc > 1) { - file = grub_file_open (argv[1], GRUB_FILE_TYPE_VBE_DUMP); + file = grub_file_open (argv[1]); if (! file) return grub_errno; @@ -183,7 +183,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_VBE_DUMP); + file = grub_file_open (argv[0]); if (! file) return grub_errno; diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c index d1ce99af4..d901c3892 100644 --- a/grub-core/commands/efi/lsefi.c +++ b/grub-core/commands/efi/lsefi.c @@ -109,10 +109,8 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)), status = efi_call_3 (grub_efi_system_table->boot_services->protocols_per_handle, handle, &protocols, &num_protocols); - if (status != GRUB_EFI_SUCCESS) { + if (status != GRUB_EFI_SUCCESS) grub_printf ("Unable to retrieve protocols\n"); - continue; - } for (j = 0; j < num_protocols; j++) { for (k = 0; k < ARRAY_SIZE (known_protocols); k++) diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c index c85ff7f36..215b45bff 100644 --- a/grub-core/commands/efi/lsefimmap.c +++ b/grub-core/commands/efi/lsefimmap.c @@ -51,7 +51,7 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)), grub_printf ("Type Physical start - end #Pages " - " Size Attributes\n"); + " Size Attributes\n"); memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size); for (desc = memory_map; desc < memory_map_end; @@ -74,8 +74,7 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)), "ACPI-nvs", "MMIO ", "IO-ports", - "PAL-code", - "persist ", + "PAL-code" }; if (desc->type < ARRAY_SIZE (types_str)) grub_printf ("%s ", types_str[desc->type]); @@ -88,29 +87,21 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)), desc->physical_start + (desc->num_pages << 12) - 1, desc->num_pages); - size = desc->num_pages << 12; /* 4 KiB page size */ - /* - * Since size is a multiple of 4 KiB, no need to handle units - * of just Bytes (which would use a mask of 0x3ff). - * - * 14 characters would support the largest possible number of 4 KiB - * pages that are not a multiple of larger units (e.g., MiB): - * 17592186044415 (0xffffff_fffff000), but that uses a lot of - * whitespace for a rare case. 6 characters usually suffices; - * columns will be off if not, but this is preferable to rounding. - */ - if (size & 0xfffff) - grub_printf (" %6" PRIuGRUB_UINT64_T "KiB", size >> 10); - else if (size & 0x3fffffff) - grub_printf (" %6" PRIuGRUB_UINT64_T "MiB", size >> 20); - else if (size & 0xffffffffff) - grub_printf (" %6" PRIuGRUB_UINT64_T "GiB", size >> 30); - else if (size & 0x3ffffffffffff) - grub_printf (" %6" PRIuGRUB_UINT64_T "TiB", size >> 40); - else if (size & 0xfffffffffffffff) - grub_printf (" %6" PRIuGRUB_UINT64_T "PiB", size >> 50); + size = desc->num_pages; + size <<= (12 - 10); + if (size < 1024) + grub_printf (" %4" PRIuGRUB_UINT64_T "KB", size); else - grub_printf (" %6" PRIuGRUB_UINT64_T "EiB", size >> 60); + { + size /= 1024; + if (size < 1024) + grub_printf (" %4" PRIuGRUB_UINT64_T "MB", size); + else + { + size /= 1024; + grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size); + } + } attr = desc->attribute; if (attr & GRUB_EFI_MEMORY_RUNTIME) @@ -131,12 +122,6 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)), grub_printf (" RP"); if (attr & GRUB_EFI_MEMORY_XP) grub_printf (" XP"); - if (attr & GRUB_EFI_MEMORY_NV) - grub_printf (" NV"); - if (attr & GRUB_EFI_MEMORY_MORE_RELIABLE) - grub_printf (" MR"); - if (attr & GRUB_EFI_MEMORY_RO) - grub_printf (" RO"); grub_printf ("\n"); } diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c index d29188efa..8717db91e 100644 --- a/grub-core/commands/efi/lsefisystab.c +++ b/grub-core/commands/efi/lsefisystab.c @@ -37,22 +37,10 @@ static const struct guid_mapping guid_mappings[] = { { GRUB_EFI_ACPI_20_TABLE_GUID, "ACPI-2.0"}, { GRUB_EFI_ACPI_TABLE_GUID, "ACPI-1.0"}, - { GRUB_EFI_CRC32_GUIDED_SECTION_EXTRACTION_GUID, - "CRC32 GUIDED SECTION EXTRACTION"}, - { GRUB_EFI_DEBUG_IMAGE_INFO_TABLE_GUID, "DEBUG IMAGE INFO"}, - { GRUB_EFI_DEVICE_TREE_GUID, "DEVICE TREE"}, - { GRUB_EFI_DXE_SERVICES_TABLE_GUID, "DXE SERVICES"}, - { GRUB_EFI_HCDP_TABLE_GUID, "HCDP"}, - { GRUB_EFI_HOB_LIST_GUID, "HOB LIST"}, - { GRUB_EFI_LZMA_CUSTOM_DECOMPRESS_GUID, "LZMA CUSTOM DECOMPRESS"}, - { GRUB_EFI_MEMORY_TYPE_INFORMATION_GUID, "MEMORY TYPE INFO"}, - { GRUB_EFI_MPS_TABLE_GUID, "MPS"}, { GRUB_EFI_SAL_TABLE_GUID, "SAL"}, { GRUB_EFI_SMBIOS_TABLE_GUID, "SMBIOS"}, - { GRUB_EFI_SMBIOS3_TABLE_GUID, "SMBIOS3"}, - { GRUB_EFI_SYSTEM_RESOURCE_TABLE_GUID, "SYSTEM RESOURCE TABLE"}, - { GRUB_EFI_TIANO_CUSTOM_DECOMPRESS_GUID, "TIANO CUSTOM DECOMPRESS"}, - { GRUB_EFI_TSC_FREQUENCY_GUID, "TSC FREQUENCY"}, + { GRUB_EFI_MPS_TABLE_GUID, "MPS"}, + { GRUB_EFI_HCDP_TABLE_GUID, "HCDP"} }; static grub_err_t @@ -73,8 +61,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), grub_printf ("Vendor: "); for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); - /* Allocate extra 3 bytes to simplify math. */ - vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); + vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); if (!vendor) return grub_errno; *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, diff --git a/grub-core/commands/efi/shim_lock.c b/grub-core/commands/efi/shim_lock.c deleted file mode 100644 index 764098cfc..000000000 --- a/grub-core/commands/efi/shim_lock.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2017 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - * - * EFI shim lock verifier. - */ - -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -#define GRUB_EFI_SHIM_LOCK_GUID \ - { 0x605dab50, 0xe046, 0x4300, \ - { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } \ - } - -struct grub_efi_shim_lock_protocol -{ - grub_efi_status_t - (*verify) (void *buffer, grub_uint32_t size); -}; -typedef struct grub_efi_shim_lock_protocol grub_efi_shim_lock_protocol_t; - -static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID; -static grub_efi_shim_lock_protocol_t *sl; - -/* List of modules which cannot be loaded if UEFI secure boot mode is enabled. */ -static const char * const disabled_mods[] = {"iorw", "memrw", "wrmsr", NULL}; - -static grub_err_t -shim_lock_init (grub_file_t io, enum grub_file_type type, - void **context __attribute__ ((unused)), - enum grub_verify_flags *flags) -{ - const char *b, *e; - int i; - - *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; - - if (!sl) - return GRUB_ERR_NONE; - - switch (type & GRUB_FILE_TYPE_MASK) - { - case GRUB_FILE_TYPE_GRUB_MODULE: - /* Establish GRUB module name. */ - b = grub_strrchr (io->name, '/'); - e = grub_strrchr (io->name, '.'); - - b = b ? (b + 1) : io->name; - e = e ? e : io->name + grub_strlen (io->name); - e = (e > b) ? e : io->name + grub_strlen (io->name); - - for (i = 0; disabled_mods[i]; i++) - if (!grub_strncmp (b, disabled_mods[i], grub_strlen (b) - grub_strlen (e))) - { - grub_error (GRUB_ERR_ACCESS_DENIED, - N_("module cannot be loaded in UEFI secure boot mode: %s"), - io->name); - return GRUB_ERR_ACCESS_DENIED; - } - - /* Fall through. */ - - case GRUB_FILE_TYPE_ACPI_TABLE: - case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE: - *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH; - - return GRUB_ERR_NONE; - - case GRUB_FILE_TYPE_LINUX_KERNEL: - case GRUB_FILE_TYPE_MULTIBOOT_KERNEL: - case GRUB_FILE_TYPE_BSD_KERNEL: - case GRUB_FILE_TYPE_XNU_KERNEL: - case GRUB_FILE_TYPE_PLAN9_KERNEL: - for (i = 0; disabled_mods[i]; i++) - if (grub_dl_get (disabled_mods[i])) - { - grub_error (GRUB_ERR_ACCESS_DENIED, - N_("cannot boot due to dangerous module in memory: %s"), - disabled_mods[i]); - return GRUB_ERR_ACCESS_DENIED; - } - - *flags = GRUB_VERIFY_FLAGS_SINGLE_CHUNK; - - /* Fall through. */ - - default: - return GRUB_ERR_NONE; - } -} - -static grub_err_t -shim_lock_write (void *context __attribute__ ((unused)), void *buf, grub_size_t size) -{ - if (sl->verify (buf, size) != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad shim signature")); - - return GRUB_ERR_NONE; -} - -struct grub_file_verifier shim_lock = - { - .name = "shim_lock", - .init = shim_lock_init, - .write = shim_lock_write - }; - -GRUB_MOD_INIT(shim_lock) -{ - sl = grub_efi_locate_protocol (&shim_lock_guid, 0); - grub_verifier_register (&shim_lock); - - if (!sl) - return; - - grub_dl_set_persistent (mod); -} - -GRUB_MOD_FINI(shim_lock) -{ - grub_verifier_unregister (&shim_lock); -} diff --git a/grub-core/commands/efi/smbios.c b/grub-core/commands/efi/smbios.c deleted file mode 100644 index 75202d5aa..000000000 --- a/grub-core/commands/efi/smbios.c +++ /dev/null @@ -1,61 +0,0 @@ -/* smbios.c - get smbios tables. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include - -struct grub_smbios_eps * -grub_machine_smbios_get_eps (void) -{ - unsigned i; - static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID; - - for (i = 0; i < grub_efi_system_table->num_table_entries; i++) - { - grub_efi_packed_guid_t *guid = - &grub_efi_system_table->configuration_table[i].vendor_guid; - - if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t))) - return (struct grub_smbios_eps *) - grub_efi_system_table->configuration_table[i].vendor_table; - } - - return 0; -} - -struct grub_smbios_eps3 * -grub_machine_smbios_get_eps3 (void) -{ - unsigned i; - static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID; - - for (i = 0; i < grub_efi_system_table->num_table_entries; i++) - { - grub_efi_packed_guid_t *guid = - &grub_efi_system_table->configuration_table[i].vendor_guid; - - if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t))) - return (struct grub_smbios_eps3 *) - grub_efi_system_table->configuration_table[i].vendor_table; - } - - return 0; -} diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c deleted file mode 100644 index b03b6b296..000000000 --- a/grub-core/commands/efi/tpm.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - * - * EFI TPM support code. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -typedef TCG_PCR_EVENT grub_tpm_event_t; - -static grub_efi_guid_t tpm_guid = EFI_TPM_GUID; -static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID; - -static grub_efi_handle_t *grub_tpm_handle; -static grub_uint8_t grub_tpm_version; - -static grub_int8_t tpm1_present = -1; -static grub_int8_t tpm2_present = -1; - -static grub_efi_boolean_t -grub_tpm1_present (grub_efi_tpm_protocol_t *tpm) -{ - grub_efi_status_t status; - TCG_EFI_BOOT_SERVICE_CAPABILITY caps; - grub_uint32_t flags; - grub_efi_physical_address_t eventlog, lastevent; - - if (tpm1_present != -1) - return (grub_efi_boolean_t) tpm1_present; - - caps.Size = (grub_uint8_t) sizeof (caps); - - status = efi_call_5 (tpm->status_check, tpm, &caps, &flags, &eventlog, - &lastevent); - - if (status != GRUB_EFI_SUCCESS || caps.TPMDeactivatedFlag - || !caps.TPMPresentFlag) - return tpm1_present = 0; - - return tpm1_present = 1; -} - -static grub_efi_boolean_t -grub_tpm2_present (grub_efi_tpm2_protocol_t *tpm) -{ - grub_efi_status_t status; - EFI_TCG2_BOOT_SERVICE_CAPABILITY caps; - - caps.Size = (grub_uint8_t) sizeof (caps); - - if (tpm2_present != -1) - return (grub_efi_boolean_t) tpm2_present; - - status = efi_call_2 (tpm->get_capability, tpm, &caps); - - if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag) - return tpm2_present = 0; - - return tpm2_present = 1; -} - -static grub_efi_boolean_t -grub_tpm_handle_find (grub_efi_handle_t *tpm_handle, - grub_efi_uint8_t *protocol_version) -{ - grub_efi_handle_t *handles; - grub_efi_uintn_t num_handles; - - if (grub_tpm_handle != NULL) - { - *tpm_handle = grub_tpm_handle; - *protocol_version = grub_tpm_version; - return 1; - } - - handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm_guid, NULL, - &num_handles); - if (handles && num_handles > 0) - { - grub_tpm_handle = handles[0]; - *tpm_handle = handles[0]; - grub_tpm_version = 1; - *protocol_version = 1; - return 1; - } - - handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm2_guid, NULL, - &num_handles); - if (handles && num_handles > 0) - { - grub_tpm_handle = handles[0]; - *tpm_handle = handles[0]; - grub_tpm_version = 2; - *protocol_version = 2; - return 1; - } - - return 0; -} - -static grub_err_t -grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, - grub_size_t size, grub_uint8_t pcr, - const char *description) -{ - grub_tpm_event_t *event; - grub_efi_status_t status; - grub_efi_tpm_protocol_t *tpm; - grub_efi_physical_address_t lastevent; - grub_uint32_t algorithm; - grub_uint32_t eventnum = 0; - - tpm = grub_efi_open_protocol (tpm_handle, &tpm_guid, - GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - if (!grub_tpm1_present (tpm)) - return 0; - - event = grub_zalloc (sizeof (*event) + grub_strlen (description) + 1); - if (!event) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - N_("cannot allocate TPM event buffer")); - - event->PCRIndex = pcr; - event->EventType = EV_IPL; - event->EventSize = grub_strlen (description) + 1; - grub_memcpy (event->Event, description, event->EventSize); - - algorithm = TCG_ALG_SHA; - status = efi_call_7 (tpm->log_extend_event, tpm, (grub_addr_t) buf, (grub_uint64_t) size, - algorithm, event, &eventnum, &lastevent); - grub_free (event); - - switch (status) - { - case GRUB_EFI_SUCCESS: - return 0; - case GRUB_EFI_DEVICE_ERROR: - return grub_error (GRUB_ERR_IO, N_("Command failed")); - case GRUB_EFI_INVALID_PARAMETER: - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); - case GRUB_EFI_BUFFER_TOO_SMALL: - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("Output buffer too small")); - case GRUB_EFI_NOT_FOUND: - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); - default: - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); - } -} - -static grub_err_t -grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, - grub_size_t size, grub_uint8_t pcr, - const char *description) -{ - EFI_TCG2_EVENT *event; - grub_efi_status_t status; - grub_efi_tpm2_protocol_t *tpm; - - tpm = grub_efi_open_protocol (tpm_handle, &tpm2_guid, - GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - if (!grub_tpm2_present (tpm)) - return 0; - - event = - grub_zalloc (sizeof (EFI_TCG2_EVENT) + grub_strlen (description) + 1); - if (!event) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - N_("cannot allocate TPM event buffer")); - - event->Header.HeaderSize = sizeof (EFI_TCG2_EVENT_HEADER); - event->Header.HeaderVersion = 1; - event->Header.PCRIndex = pcr; - event->Header.EventType = EV_IPL; - event->Size = - sizeof (*event) - sizeof (event->Event) + grub_strlen (description) + 1; - grub_memcpy (event->Event, description, grub_strlen (description) + 1); - - status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (grub_addr_t) buf, - (grub_uint64_t) size, event); - grub_free (event); - - switch (status) - { - case GRUB_EFI_SUCCESS: - return 0; - case GRUB_EFI_DEVICE_ERROR: - return grub_error (GRUB_ERR_IO, N_("Command failed")); - case GRUB_EFI_INVALID_PARAMETER: - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); - case GRUB_EFI_BUFFER_TOO_SMALL: - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("Output buffer too small")); - case GRUB_EFI_NOT_FOUND: - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); - default: - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); - } -} - -grub_err_t -grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, - const char *description) -{ - grub_efi_handle_t tpm_handle; - grub_efi_uint8_t protocol_version; - - if (!grub_tpm_handle_find (&tpm_handle, &protocol_version)) - return 0; - - if (protocol_version == 1) - return grub_tpm1_log_event (tpm_handle, buf, size, pcr, description); - else - return grub_tpm2_log_event (tpm_handle, buf, size, pcr, description); -} diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 2574e6685..42d62d479 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include #include @@ -90,10 +88,6 @@ static const struct grub_arg_option options[] = { N_("Check if FILE is ARM64 EFI file"), 0, 0}, {"is-arm-efi", 0, 0, N_("Check if FILE is ARM EFI file"), 0, 0}, - {"is-riscv32-efi", 0, 0, - N_("Check if FILE is RISC-V 32bit EFI file"), 0, 0}, - {"is-riscv64-efi", 0, 0, - N_("Check if FILE is RISC-V 64bit EFI file"), 0, 0}, {"is-hibernated-hiberfil", 0, 0, N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0}, {"is-x86_64-xnu", 0, 0, @@ -134,7 +128,6 @@ enum IS_IA_EFI, IS_ARM64_EFI, IS_ARM_EFI, - IS_RISCV_EFI, IS_HIBERNATED, IS_XNU64, IS_XNU32, @@ -170,7 +163,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) if (type == -1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no type specified"); - file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL); + file = grub_file_open (args[0]); if (!file) return grub_errno; switch (type) @@ -390,19 +383,21 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) } case IS_ARM_LINUX: { - struct linux_arm_kernel_header lh; - - if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) + grub_uint32_t sig, sig_pi; + if (grub_file_read (file, &sig_pi, 4) != 4) break; - /* Short forward branch in A32 state (for Raspberry pi kernels). */ - if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006)) + /* Raspberry pi. */ + if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006)) { ret = 1; break; } - if (lh.magic == - grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM_MAGIC_SIGNATURE)) + if (grub_file_seek (file, 0x24) == (grub_size_t) -1) + break; + if (grub_file_read (file, &sig, 4) != 4) + break; + if (sig == grub_cpu_to_le32_compile_time (0x016f2818)) { ret = 1; break; @@ -411,13 +406,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) } case IS_ARM64_LINUX: { - struct linux_arm64_kernel_header lh; + grub_uint32_t sig; - if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) + if (grub_file_seek (file, 0x38) == (grub_size_t) -1) break; - - if (lh.magic == - grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM64_MAGIC_SIGNATURE)) + if (grub_file_read (file, &sig, 4) != 4) + break; + if (sig == grub_cpu_to_le32_compile_time (0x644d5241)) { ret = 1; break; @@ -481,8 +476,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) be at least 12 bytes and aligned on a 4-byte boundary. */ for (header = buffer; ((char *) header <= - (char *) buffer + len - (type == IS_MULTIBOOT2 ? 16 : 12)); - header += step) + (char *) buffer + len - (type == IS_MULTIBOOT2 ? 16 : 12)) + || (header = 0); header += step) { if (header[0] == magic && !(grub_le_to_cpu32 (header[0]) @@ -490,19 +485,18 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) + grub_le_to_cpu32 (header[2]) + (type == IS_MULTIBOOT2 ? grub_le_to_cpu32 (header[3]) : 0))) - { - ret = 1; - break; - } + break; } + if (header != 0) + ret = 1; grub_free (buffer); break; } case IS_X86_LINUX32: case IS_X86_LINUX: { - struct linux_i386_kernel_header lh; + struct linux_kernel_header lh; if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) break; if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) @@ -513,7 +507,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) /* FIXME: some really old kernels (< 1.3.73) will fail this. */ if (lh.header != - grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0200) break; @@ -526,7 +520,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) /* FIXME: 2.03 is not always good enough (Linux 2.4 can be 2.03 and still not support 32-bit boot. */ if (lh.header != - grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0203) break; @@ -551,8 +545,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) case IS_XNU64: case IS_XNU32: { - macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, - (type == IS_XNU64)); + macho = grub_macho_open (args[0], (type == IS_XNU64)); if (!macho) break; /* FIXME: more checks? */ @@ -576,7 +569,6 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) case IS_IA_EFI: case IS_ARM64_EFI: case IS_ARM_EFI: - case IS_RISCV_EFI: { char signature[4]; grub_uint32_t pe_offset; @@ -622,13 +614,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) && coff_head.machine != grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED)) break; - if (type == IS_RISCV_EFI - && coff_head.machine != - grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV64)) - /* TODO: Determine bitness dynamically */ - break; - if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI || - type == IS_RISCV_EFI) + if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI) { struct grub_pe64_optional_header o64; if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64)) diff --git a/grub-core/commands/fileXX.c b/grub-core/commands/fileXX.c index c17d26ce6..58e1094c6 100644 --- a/grub-core/commands/fileXX.c +++ b/grub-core/commands/fileXX.c @@ -40,10 +40,10 @@ grub_file_check_netbsdXX (grub_elf_t elf) return 0; if (grub_file_seek (elf->file, elf->ehdr.ehdrXX.e_shoff) == (grub_off_t) -1) - goto fail; + return 0; if (grub_file_read (elf->file, s0, shsize) != (grub_ssize_t) shsize) - goto fail; + return 0; s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; @@ -54,21 +54,18 @@ grub_file_check_netbsdXX (grub_elf_t elf) char name[sizeof(".note.netbsd.ident")]; grub_memset (name, 0, sizeof (name)); if (grub_file_seek (elf->file, stroff + s->sh_name) == (grub_off_t) -1) - goto fail; + return grub_errno; if (grub_file_read (elf->file, name, sizeof (name)) != (grub_ssize_t) sizeof (name)) { if (grub_errno) - goto fail; + return grub_errno; continue; } if (grub_memcmp (name, ".note.netbsd.ident", sizeof(".note.netbsd.ident")) != 0) continue; - grub_free (s0); return 1; } - fail: - grub_free (s0); return 0; } diff --git a/grub-core/commands/gptsync.c b/grub-core/commands/gptsync.c index 444e24874..16592e9bb 100644 --- a/grub-core/commands/gptsync.c +++ b/grub-core/commands/gptsync.c @@ -235,8 +235,6 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)), return grub_errno; } - grub_device_close (dev); - grub_printf_ (N_("New MBR is written to `%s'\n"), args[0]); return GRUB_ERR_NONE; diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c index 456ba908b..d18687351 100644 --- a/grub-core/commands/hashsum.c +++ b/grub-core/commands/hashsum.c @@ -113,7 +113,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN) return grub_error (GRUB_ERR_BUG, "mdlen is too long"); - hashlist = grub_file_open (hashfilename, GRUB_FILE_TYPE_HASHLIST); + hashlist = grub_file_open (hashfilename); if (!hashlist) return grub_errno; @@ -141,15 +141,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, filename = grub_xasprintf ("%s/%s", prefix, p); if (!filename) return grub_errno; - file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH - | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS - : GRUB_FILE_TYPE_NONE)); + if (!uncompress) + grub_file_filter_disable_compression (); + file = grub_file_open (filename); grub_free (filename); } else - file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH - | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS - : GRUB_FILE_TYPE_NONE)); + { + if (!uncompress) + grub_file_filter_disable_compression (); + file = grub_file_open (p); + } if (!file) { grub_file_close (hashlist); @@ -240,9 +242,9 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt, grub_file_t file; grub_err_t err; unsigned j; - file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH - | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS - : GRUB_FILE_TYPE_NONE)); + if (!uncompress) + grub_file_filter_disable_compression (); + file = grub_file_open (args[i]); if (!file) { if (!keep) diff --git a/grub-core/commands/hdparm.c b/grub-core/commands/hdparm.c index d3fa9661e..3fb08912d 100644 --- a/grub-core/commands/hdparm.c +++ b/grub-core/commands/hdparm.c @@ -328,9 +328,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) ata = ((struct grub_scsi *) disk->data)->data; break; } - /* FALLTHROUGH */ default: - grub_disk_close (disk); return grub_error (GRUB_ERR_IO, "not an ATA device"); } diff --git a/grub-core/commands/hexdump.c b/grub-core/commands/hexdump.c index eaa12465b..4c884b3a1 100644 --- a/grub-core/commands/hexdump.c +++ b/grub-core/commands/hexdump.c @@ -90,7 +90,7 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args) { grub_file_t file; - file = grub_file_open (args[0], GRUB_FILE_TYPE_HEXCAT); + file = grub_file_open (args[0]); if (! file) return 0; diff --git a/grub-core/commands/i386/cmostest.c b/grub-core/commands/i386/cmostest.c index 9f6b56a2f..e5dea0769 100644 --- a/grub-core/commands/i386/cmostest.c +++ b/grub-core/commands/i386/cmostest.c @@ -27,7 +27,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_err_t parse_args (int argc, char *argv[], int *byte, int *bit) { - const char *rest; + char *rest; if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, "address required"); @@ -45,7 +45,7 @@ static grub_err_t grub_cmd_cmostest (struct grub_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { - int byte = 0, bit = 0; + int byte, bit; grub_err_t err; grub_uint8_t value; @@ -67,7 +67,7 @@ static grub_err_t grub_cmd_cmosclean (struct grub_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { - int byte = 0, bit = 0; + int byte, bit; grub_err_t err; grub_uint8_t value; @@ -85,7 +85,7 @@ static grub_err_t grub_cmd_cmosset (struct grub_command *cmd __attribute__ ((unused)), int argc, char *argv[]) { - int byte = 0, bit = 0; + int byte, bit; grub_err_t err; grub_uint8_t value; diff --git a/grub-core/commands/i386/coreboot/cb_timestamps.c b/grub-core/commands/i386/coreboot/cb_timestamps.c index e97ea6bed..07fbb0283 100644 --- a/grub-core/commands/i386/coreboot/cb_timestamps.c +++ b/grub-core/commands/i386/coreboot/cb_timestamps.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -39,17 +39,9 @@ static const char *descs[] = { [2] = "before RAM init", [3] = "after RAM init", [4] = "end of romstage", - [5] = "start of verified boot", - [6] = "end of verified boot", [8] = "start of RAM copy", [9] = "end of RAM copy", [10] = "start of ramstage", - [11] = "start of bootblock", - [12] = "end of bootblock", - [13] = "starting to load romstage", - [14] = "finished loading romstage", - [15] = "starting LZMA decompress (ignore for x86)", - [16] = "finished LZMA decompress (ignore for x86)", [30] = "device enumerate", [40] = "device configure", [50] = "device enable", diff --git a/grub-core/commands/i386/coreboot/cbls.c b/grub-core/commands/i386/coreboot/cbls.c index 102291f42..e0a10596f 100644 --- a/grub-core/commands/i386/coreboot/cbls.c +++ b/grub-core/commands/i386/coreboot/cbls.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); diff --git a/grub-core/kern/i386/pc/acpi.c b/grub-core/commands/i386/pc/acpi.c similarity index 94% rename from grub-core/kern/i386/pc/acpi.c rename to grub-core/commands/i386/pc/acpi.c index 297f5d05f..d415d2305 100644 --- a/grub-core/kern/i386/pc/acpi.c +++ b/grub-core/commands/i386/pc/acpi.c @@ -29,15 +29,14 @@ grub_machine_acpi_get_rsdpv1 (void) grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4); ebda_len = * (grub_uint16_t *) ebda; - if (! ebda_len) /* FIXME do we really need this check? */ - goto scan_bios; + if (! ebda_len) + return 0; for (ptr = ebda; ptr < ebda + 0x400; ptr += 16) if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0) return (struct grub_acpi_rsdp_v10 *) ptr; -scan_bios: grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16) @@ -57,8 +56,8 @@ grub_machine_acpi_get_rsdpv2 (void) grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4); ebda_len = * (grub_uint16_t *) ebda; - if (! ebda_len) /* FIXME do we really need this check? */ - goto scan_bios; + if (! ebda_len) + return 0; for (ptr = ebda; ptr < ebda + 0x400; ptr += 16) if (grub_memcmp (ptr, GRUB_RSDP_SIGNATURE, GRUB_RSDP_SIGNATURE_SIZE) == 0 && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0 @@ -68,7 +67,6 @@ grub_machine_acpi_get_rsdpv2 (void) == 0) return (struct grub_acpi_rsdp_v20 *) ptr; -scan_bios: grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16) diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c index a980e4688..7712e2a36 100644 --- a/grub-core/commands/i386/pc/play.c +++ b/grub-core/commands/i386/pc/play.c @@ -93,7 +93,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), grub_uint32_t tempo; grub_file_t file; - file = grub_file_open (args[0], GRUB_FILE_TYPE_AUDIO); + file = grub_file_open (args[0]); if (! file) return grub_errno; @@ -132,7 +132,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), } else { - const char *end; + char *end; unsigned tempo; struct note note; int i; diff --git a/grub-core/commands/i386/pc/smbios.c b/grub-core/commands/i386/pc/smbios.c deleted file mode 100644 index 069d66367..000000000 --- a/grub-core/commands/i386/pc/smbios.c +++ /dev/null @@ -1,52 +0,0 @@ -/* smbios.c - get smbios tables. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -struct grub_smbios_eps * -grub_machine_smbios_get_eps (void) -{ - grub_uint8_t *ptr; - - grub_dprintf ("smbios", "Looking for SMBIOS EPS. Scanning BIOS\n"); - - for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16) - if (grub_memcmp (ptr, "_SM_", 4) == 0 - && grub_byte_checksum (ptr, sizeof (struct grub_smbios_eps)) == 0) - return (struct grub_smbios_eps *) ptr; - - return 0; -} - -struct grub_smbios_eps3 * -grub_machine_smbios_get_eps3 (void) -{ - grub_uint8_t *ptr; - - grub_dprintf ("smbios", "Looking for SMBIOS3 EPS. Scanning BIOS\n"); - - for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16) - if (grub_memcmp (ptr, "_SM3_", 5) == 0 - && grub_byte_checksum (ptr, sizeof (struct grub_smbios_eps3)) == 0) - return (struct grub_smbios_eps3 *) ptr; - - return 0; -} diff --git a/grub-core/commands/i386/rdmsr.c b/grub-core/commands/i386/rdmsr.c deleted file mode 100644 index 46c4346da..000000000 --- a/grub-core/commands/i386/rdmsr.c +++ /dev/null @@ -1,102 +0,0 @@ -/* rdmsr.c - Read CPU model-specific registers. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * Based on gcc/gcc/config/i386/driver-i386.c - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE("GPLv3+"); - -static grub_extcmd_t cmd_read; - -static const struct grub_arg_option options[] = -{ - {0, 'v', 0, N_("Save read value into variable VARNAME."), - N_("VARNAME"), ARG_TYPE_STRING}, - {0, 0, 0, 0, 0, 0} -}; - -static grub_err_t -grub_cmd_msr_read (grub_extcmd_context_t ctxt, int argc, char **argv) -{ - grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; - grub_uint64_t value; - const char *ptr; - char buf[sizeof("1122334455667788")]; - - /* - * The CPUID instruction should be used to determine whether MSRs - * are supported. (CPUID.01H:EDX[5] = 1) - */ - if (! grub_cpu_is_cpuid_supported ()) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - grub_cpuid (0, max_cpuid, manufacturer[0], manufacturer[2], manufacturer[1]); - - if (max_cpuid < 1) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - grub_cpuid (1, a, b, c, features); - - if (!(features & (1 << 5))) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - if (argc != 1) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); - - grub_errno = GRUB_ERR_NONE; - ptr = argv[0]; - addr = grub_strtoul (ptr, &ptr, 0); - - if (grub_errno != GRUB_ERR_NONE) - return grub_errno; - if (*ptr != '\0') - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument")); - - value = grub_msr_read (addr); - - if (ctxt->state[0].set) - { - grub_snprintf (buf, sizeof(buf), "%llx", (unsigned long long) value); - grub_env_set (ctxt->state[0].arg, buf); - } - else - grub_printf ("0x%llx\n", (unsigned long long) value); - - return GRUB_ERR_NONE; -} - -GRUB_MOD_INIT(rdmsr) -{ - cmd_read = grub_register_extcmd ("rdmsr", grub_cmd_msr_read, 0, N_("ADDR"), - N_("Read a CPU model specific register."), - options); -} - -GRUB_MOD_FINI(rdmsr) -{ - grub_unregister_extcmd (cmd_read); -} diff --git a/grub-core/commands/i386/wrmsr.c b/grub-core/commands/i386/wrmsr.c deleted file mode 100644 index fa76f5aed..000000000 --- a/grub-core/commands/i386/wrmsr.c +++ /dev/null @@ -1,93 +0,0 @@ -/* wrmsr.c - Write CPU model-specific registers. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * Based on gcc/gcc/config/i386/driver-i386.c - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE("GPLv3+"); - -static grub_command_t cmd_write; - -static grub_err_t -grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char **argv) -{ - grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; - grub_uint64_t value; - const char *ptr; - - /* - * The CPUID instruction should be used to determine whether MSRs - * are supported. (CPUID.01H:EDX[5] = 1) - */ - if (!grub_cpu_is_cpuid_supported ()) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - grub_cpuid (0, max_cpuid, manufacturer[0], manufacturer[2], manufacturer[1]); - - if (max_cpuid < 1) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - grub_cpuid (1, a, b, c, features); - - if (!(features & (1 << 5))) - return grub_error (GRUB_ERR_BUG, N_("unsupported instruction")); - - if (argc != 2) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected")); - - grub_errno = GRUB_ERR_NONE; - ptr = argv[0]; - addr = grub_strtoul (ptr, &ptr, 0); - - if (grub_errno != GRUB_ERR_NONE) - return grub_errno; - if (*ptr != '\0') - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument")); - - ptr = argv[1]; - value = grub_strtoull (ptr, &ptr, 0); - - if (grub_errno != GRUB_ERR_NONE) - return grub_errno; - if (*ptr != '\0') - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument")); - - grub_msr_write (addr, value); - - return GRUB_ERR_NONE; -} - -GRUB_MOD_INIT(wrmsr) -{ - cmd_write = grub_register_command ("wrmsr", grub_cmd_msr_write, N_("ADDR VALUE"), - N_("Write a value to a CPU model specific register.")); -} - -GRUB_MOD_FINI(wrmsr) -{ - grub_unregister_command (cmd_write); -} diff --git a/grub-core/commands/keylayouts.c b/grub-core/commands/keylayouts.c index c05d6128a..f4b773020 100644 --- a/grub-core/commands/keylayouts.c +++ b/grub-core/commands/keylayouts.c @@ -40,7 +40,7 @@ static struct grub_keyboard_layout layout_us = { /* 0x10 */ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', /* 0x18 */ 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', /* 0x20 */ '3', '4', '5', '6', '7', '8', '9', '0', - /* 0x28 */ '\n', GRUB_TERM_ESC, GRUB_TERM_BACKSPACE, GRUB_TERM_TAB, ' ', '-', '=', '[', + /* 0x28 */ '\n', '\e', '\b', '\t', ' ', '-', '=', '[', /* According to usage table 0x31 should be mapped to '/' but testing with real keyboard shows that 0x32 is remapped to '/'. Map 0x31 to 0. @@ -82,8 +82,8 @@ static struct grub_keyboard_layout layout_us = { /* 0x10 */ 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 0x18 */ 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', /* 0x20 */ '#', '$', '%', '^', '&', '*', '(', ')', - /* 0x28 */ '\n' | GRUB_TERM_SHIFT, GRUB_TERM_ESC | GRUB_TERM_SHIFT, - /* 0x2a */ GRUB_TERM_BACKSPACE | GRUB_TERM_SHIFT, GRUB_TERM_TAB | GRUB_TERM_SHIFT, + /* 0x28 */ '\n' | GRUB_TERM_SHIFT, '\e' | GRUB_TERM_SHIFT, + /* 0x2a */ '\b' | GRUB_TERM_SHIFT, '\t' | GRUB_TERM_SHIFT, /* 0x2c */ ' ' | GRUB_TERM_SHIFT, '_', '+', '{', /* According to usage table 0x31 should be mapped to '/' but testing with real keyboard shows that 0x32 is remapped to '/'. @@ -220,7 +220,7 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)), else filename = argv[0]; - file = grub_file_open (filename, GRUB_FILE_TYPE_KEYBOARD_LAYOUT); + file = grub_file_open (filename); if (! file) goto fail; diff --git a/grub-core/commands/keystatus.c b/grub-core/commands/keystatus.c index ff3f58781..460cf4e7e 100644 --- a/grub-core/commands/keystatus.c +++ b/grub-core/commands/keystatus.c @@ -35,6 +35,24 @@ static const struct grub_arg_option options[] = {0, 0, 0, 0, 0, 0} }; +static int +grub_getkeystatus (void) +{ + int status = 0; + grub_term_input_t term; + + if (grub_term_poll_usb) + grub_term_poll_usb (0); + + FOR_ACTIVE_TERM_INPUTS(term) + { + if (term->getkeystatus) + status |= term->getkeystatus (term); + } + + return status; +} + static grub_err_t grub_cmd_keystatus (grub_extcmd_context_t ctxt, int argc __attribute__ ((unused)), diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c index cc5971f4d..2c09fb7dd 100644 --- a/grub-core/commands/legacycfg.c +++ b/grub-core/commands/legacycfg.c @@ -32,7 +32,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -56,22 +55,16 @@ legacy_file (const char *filename) if (!suffix) return grub_errno; - file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG); + file = grub_file_open (filename); if (! file) - { - grub_free (suffix); - return grub_errno; - } + return grub_errno; menu = grub_env_get_menu (); if (! menu) { menu = grub_zalloc (sizeof (*menu)); if (! menu) - { - grub_free (suffix); - return grub_errno; - } + return grub_errno; grub_env_set_menu (menu); } @@ -84,7 +77,6 @@ legacy_file (const char *filename) if (!buf && grub_errno) { grub_file_close (file); - grub_free (suffix); return grub_errno; } @@ -105,22 +97,13 @@ legacy_file (const char *filename) if (newsuffix) { char *t; - grub_size_t sz; - - if (grub_add (grub_strlen (suffix), grub_strlen (newsuffix), &sz) || - grub_add (sz, 1, &sz)) - { - grub_errno = GRUB_ERR_OUT_OF_RANGE; - goto fail_0; - } - + t = suffix; - suffix = grub_realloc (suffix, sz); + suffix = grub_realloc (suffix, grub_strlen (suffix) + + grub_strlen (newsuffix) + 1); if (!suffix) { grub_free (t); - - fail_0: grub_free (entrysrc); grub_free (parsed); grub_free (newsuffix); @@ -164,22 +147,13 @@ legacy_file (const char *filename) else { char *t; - grub_size_t sz; - - if (grub_add (grub_strlen (entrysrc), grub_strlen (parsed), &sz) || - grub_add (sz, 1, &sz)) - { - grub_errno = GRUB_ERR_OUT_OF_RANGE; - goto fail_1; - } t = entrysrc; - entrysrc = grub_realloc (entrysrc, sz); + entrysrc = grub_realloc (entrysrc, grub_strlen (entrysrc) + + grub_strlen (parsed) + 1); if (!entrysrc) { grub_free (t); - - fail_1: grub_free (parsed); grub_free (suffix); return grub_errno; @@ -199,8 +173,6 @@ legacy_file (const char *filename) if (!args) { grub_file_close (file); - grub_free (suffix); - grub_free (entrysrc); return grub_errno; } args[0] = entryname; @@ -272,7 +244,6 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), struct grub_command *cmd; char **cutargs; int cutargc; - grub_err_t err = GRUB_ERR_NONE; for (i = 0; i < 2; i++) { @@ -333,9 +304,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (argc < 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); - if (!cutargs) - return grub_errno; + cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); cutargc = argc - 1; grub_memcpy (cutargs + 1, args + 2, sizeof (cutargs[0]) * (argc - 2)); cutargs[0] = args[0]; @@ -355,7 +324,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (!(cmd->func) (cmd, cutargc, cutargs)) { kernel_type = LINUX; - goto out; + return GRUB_ERR_NONE; } } grub_errno = GRUB_ERR_NONE; @@ -370,7 +339,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (!(cmd->func) (cmd, argc, args)) { kernel_type = MULTIBOOT; - goto out; + return GRUB_ERR_NONE; } } grub_errno = GRUB_ERR_NONE; @@ -407,8 +376,6 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (part && grub_strcmp (part->partmap->name, "msdos") == 0) bsd_slice = part->number; } - if (dev) - grub_device_close (dev); } /* k*BSD didn't really work well with grub-legacy. */ @@ -435,7 +402,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (!(cmd->func) (cmd, cutargc, cutargs)) { kernel_type = KFREEBSD; - goto out; + return GRUB_ERR_NONE; } } grub_errno = GRUB_ERR_NONE; @@ -444,8 +411,6 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), char **bsdargs; int bsdargc; char bsddevname[sizeof ("wdXXXXXXXXXXXXY")]; - int found = 0; - if (bsd_device == -1) { bsdargs = cutargs; @@ -455,12 +420,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), { char rbuf[3] = "-r"; bsdargc = cutargc + 2; - bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); - if (!bsdargs) - { - err = grub_errno; - goto out; - } + bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); grub_memcpy (bsdargs, args, argc * sizeof (bsdargs[0])); bsdargs[argc] = rbuf; bsdargs[argc + 1] = bsddevname; @@ -476,8 +436,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (!(cmd->func) (cmd, bsdargc, bsdargs)) { kernel_type = KNETBSD; - found = 1; - goto free_bsdargs; + return GRUB_ERR_NONE; } } grub_errno = GRUB_ERR_NONE; @@ -490,28 +449,20 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), if (!(cmd->func) (cmd, bsdargc, bsdargs)) { kernel_type = KOPENBSD; - found = 1; - goto free_bsdargs; + return GRUB_ERR_NONE; } } grub_errno = GRUB_ERR_NONE; } - -free_bsdargs: if (bsdargs != cutargs) grub_free (bsdargs); - if (found) - goto out; } } } while (0); - err = grub_error (GRUB_ERR_BAD_OS, "couldn't load file %s", - args[0]); -out: - grub_free (cutargs); - return err; + return grub_error (GRUB_ERR_BAD_OS, "couldn't load file %s", + args[0]); } static grub_err_t @@ -536,7 +487,7 @@ grub_cmd_legacy_initrd (struct grub_command *mycmd __attribute__ ((unused)), #endif ); - return cmd->func (cmd, argc ? 1 : 0, args); + return cmd->func (cmd, argc, args); } if (kernel_type == MULTIBOOT) { @@ -572,17 +523,15 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused char **newargs; grub_err_t err; char nounzipbuf[10] = "--nounzip"; - - cmd = grub_command_find ("module"); - if (!cmd) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), - "module"); - - newargs = grub_calloc (argc + 1, sizeof (newargs[0])); + newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); if (!newargs) return grub_errno; grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); newargs[0] = nounzipbuf; + cmd = grub_command_find ("module"); + if (!cmd) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), + "module"); err = cmd->func (cmd, argc + 1, newargs); grub_free (newargs); diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c index 3fd664aac..acd93d123 100644 --- a/grub-core/commands/loadenv.c +++ b/grub-core/commands/loadenv.c @@ -44,8 +44,7 @@ static const struct grub_arg_option options[] = PUBKEY filter (that insists upon properly signed files) as well. PUBKEY filter is restored before the function returns. */ static grub_file_t -open_envblk_file (char *filename, - enum grub_file_type type) +open_envblk_file (char *filename, int untrusted) { grub_file_t file; char *buf = 0; @@ -73,7 +72,13 @@ open_envblk_file (char *filename, grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG); } - file = grub_file_open (filename, type); + /* The filters that are disabled will be re-enabled by the call to + grub_file_open() after this particular file is opened. */ + grub_file_filter_disable_compression (); + if (untrusted) + grub_file_filter_disable_pubkey (); + + file = grub_file_open (filename); grub_free (buf); return file; @@ -166,10 +171,7 @@ grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args) whitelist.list = args; /* state[0] is the -f flag; state[1] is the --skip-sig flag */ - file = open_envblk_file ((state[0].set) ? state[0].arg : 0, - GRUB_FILE_TYPE_LOADENV - | (state[1].set - ? GRUB_FILE_TYPE_SKIP_SIGNATURE : GRUB_FILE_TYPE_NONE)); + file = open_envblk_file ((state[0].set) ? state[0].arg : 0, state[1].set); if (! file) return grub_errno; @@ -204,10 +206,7 @@ grub_cmd_list_env (grub_extcmd_context_t ctxt, grub_file_t file; grub_envblk_t envblk; - file = open_envblk_file ((state[0].set) ? state[0].arg : 0, - GRUB_FILE_TYPE_LOADENV - | (state[1].set - ? GRUB_FILE_TYPE_SKIP_SIGNATURE : GRUB_FILE_TYPE_NONE)); + file = open_envblk_file ((state[0].set) ? state[0].arg : 0, 0); if (! file) return grub_errno; @@ -391,8 +390,7 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified"); file = open_envblk_file ((state[0].set) ? state[0].arg : 0, - GRUB_FILE_TYPE_SAVEENV - | GRUB_FILE_TYPE_SKIP_SIGNATURE); + 1 /* allow untrusted */); if (! file) return grub_errno; diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 5b7491aa4..0eaf83652 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -129,8 +129,8 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info, /* XXX: For ext2fs symlinks are detected as files while they should be reported as directories. */ - file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (pathname); if (! file) { grub_errno = 0; @@ -201,15 +201,6 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) if (grub_errno == GRUB_ERR_UNKNOWN_FS) grub_errno = GRUB_ERR_NONE; -#ifdef GRUB_MACHINE_IEEE1275 - /* - * Close device to prevent a double open in grub_normal_print_device_info(). - * Otherwise it may lead to hangs on some IEEE 1275 platforms. - */ - grub_device_close (dev); - dev = NULL; -#endif - grub_normal_print_device_info (device_name); } else if (fs) @@ -221,9 +212,9 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) }; if (longlist) - (fs->fs_dir) (dev, path, print_files_long, &ctx); + (fs->dir) (dev, path, print_files_long, &ctx); else - (fs->fs_dir) (dev, path, print_files, &ctx); + (fs->dir) (dev, path, print_files, &ctx); if (grub_errno == GRUB_ERR_BAD_FILE_TYPE && path[grub_strlen (path) - 1] != '/') @@ -234,8 +225,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) struct grub_dirhook_info info; grub_errno = 0; - file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (dirname); if (! file) goto fail; diff --git a/grub-core/commands/lsmmap.c b/grub-core/commands/lsmmap.c index 816ee47d1..4b504fd28 100644 --- a/grub-core/commands/lsmmap.c +++ b/grub-core/commands/lsmmap.c @@ -37,8 +37,6 @@ static const char *names[] = is required to save accross hibernations. */ [GRUB_MEMORY_NVS] = N_("ACPI non-volatile storage RAM"), [GRUB_MEMORY_BADRAM] = N_("faulty RAM (BadRAM)"), - [GRUB_MEMORY_PERSISTENT] = N_("persistent RAM"), - [GRUB_MEMORY_PERSISTENT_LEGACY] = N_("persistent RAM (legacy)"), [GRUB_MEMORY_COREBOOT_TABLES] = N_("RAM holding coreboot tables"), [GRUB_MEMORY_CODE] = N_("RAM holding firmware code") }; diff --git a/grub-core/commands/macbless.c b/grub-core/commands/macbless.c index 85cefd0f7..4724edd77 100644 --- a/grub-core/commands/macbless.c +++ b/grub-core/commands/macbless.c @@ -106,7 +106,7 @@ grub_mac_bless_inode (grub_device_t dev, grub_uint32_t inode, int is_dir, ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz); ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block); embedded_offset = (ablk_start - + ((grub_uint64_t) extent_start) + + extent_start * (ablk_size >> GRUB_DISK_SECTOR_BITS)); err = @@ -159,12 +159,12 @@ grub_mac_bless_file (grub_device_t dev, const char *path_in, int intel) *tail = 0; ctx.dirname = tail + 1; - (fs->fs_dir) (dev, *path == 0 ? "/" : path, find_inode, &ctx); + (fs->dir) (dev, *path == 0 ? "/" : path, find_inode, &ctx); } else { ctx.dirname = path + 1; - (fs->fs_dir) (dev, "/", find_inode, &ctx); + (fs->dir) (dev, "/", find_inode, &ctx); } if (!ctx.found) { @@ -183,7 +183,7 @@ grub_cmd_macbless (grub_command_t cmd, int argc, char **args) { char *device_name; char *path = 0; - grub_device_t dev = 0; + grub_device_t dev; grub_err_t err; if (argc != 1) @@ -197,12 +197,13 @@ grub_cmd_macbless (grub_command_t cmd, int argc, char **args) else path = path + 1; - if (!path || *path == 0 || !dev) + if (!path || *path == 0 || !device_name) { if (dev) grub_device_close (dev); grub_free (device_name); + grub_free (path); return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument"); } diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c index 9164df744..58d4dadf6 100644 --- a/grub-core/commands/menuentry.c +++ b/grub-core/commands/menuentry.c @@ -52,8 +52,8 @@ static struct int key; } hotkey_aliases[] = { - {"backspace", GRUB_TERM_BACKSPACE}, - {"tab", GRUB_TERM_TAB}, + {"backspace", '\b'}, + {"tab", '\t'}, {"delete", GRUB_TERM_KEY_DC}, {"insert", GRUB_TERM_KEY_INSERT}, {"f1", GRUB_TERM_KEY_F1}, @@ -154,7 +154,7 @@ grub_normal_add_menu_entry (int argc, const char **args, goto fail; /* Save argc, args to pass as parameters to block arg later. */ - menu_args = grub_calloc (argc + 1, sizeof (char *)); + menu_args = grub_malloc (sizeof (char*) * (argc + 1)); if (! menu_args) goto fail; diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index 6bbce3128..a3a118241 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c @@ -43,7 +43,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)), if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_CAT); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -137,9 +137,6 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)), if (! mod) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module"); - if (grub_dl_is_persistent (mod)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module"); - if (grub_dl_unref (mod) <= 0) grub_dl_unload (mod); diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c index 7c8f97f6a..33b6b99ea 100644 --- a/grub-core/commands/nativedisk.c +++ b/grub-core/commands/nativedisk.c @@ -57,7 +57,6 @@ get_uuid (const char *name, char **uuid, int getnative) if (!dev->disk) { grub_dprintf ("nativedisk", "Skipping non-disk\n"); - grub_device_close (dev); return 0; } @@ -66,7 +65,6 @@ get_uuid (const char *name, char **uuid, int getnative) /* Firmware disks. */ case GRUB_DISK_DEVICE_BIOSDISK_ID: case GRUB_DISK_DEVICE_OFDISK_ID: - case GRUB_DISK_DEVICE_OBDISK_ID: case GRUB_DISK_DEVICE_EFIDISK_ID: case GRUB_DISK_DEVICE_NAND_ID: case GRUB_DISK_DEVICE_ARCDISK_ID: @@ -80,7 +78,6 @@ get_uuid (const char *name, char **uuid, int getnative) case GRUB_DISK_DEVICE_XEN: if (getnative) break; - /* FALLTHROUGH */ /* Virtual disks. */ /* GRUB dynamically generated files. */ @@ -93,7 +90,6 @@ get_uuid (const char *name, char **uuid, int getnative) case GRUB_DISK_DEVICE_MEMDISK_ID: grub_dprintf ("nativedisk", "Skipping native disk %s\n", dev->disk->name); - grub_device_close (dev); return 0; /* FIXME: those probably need special handling. */ @@ -109,7 +105,7 @@ get_uuid (const char *name, char **uuid, int getnative) grub_device_close (dev); return grub_errno; } - if (!fs->fs_uuid || fs->fs_uuid (dev, uuid) || !*uuid) + if (!fs->uuid || fs->uuid (dev, uuid) || !*uuid) { grub_device_close (dev); @@ -195,15 +191,12 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), else path_prefix = prefix; - mods = grub_calloc (argc, sizeof (mods[0])); + mods = grub_malloc (argc * sizeof (mods[0])); if (!mods) return grub_errno; if (get_uuid (NULL, &uuid_root, 0)) - { - grub_free (mods); - return grub_errno; - } + return grub_errno; prefdev = grub_file_get_device_name (prefix); if (grub_errno) @@ -215,8 +208,6 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), if (get_uuid (prefdev, &uuid_prefix, 0)) { grub_free (uuid_root); - grub_free (prefdev); - grub_free (mods); return grub_errno; } @@ -243,8 +234,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), if (! filename) goto fail; - file = grub_file_open (filename, - GRUB_FILE_TYPE_GRUB_MODULE); + file = grub_file_open (filename); grub_free (filename); if (! file) goto fail; @@ -297,15 +287,12 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), } grub_free (uuid_root); grub_free (uuid_prefix); - grub_free (prefdev); - grub_free (mods); return GRUB_ERR_NONE; fail: grub_free (uuid_root); grub_free (uuid_prefix); - grub_free (prefdev); for (i = 0; i < mods_loaded; i++) if (mods[i]) @@ -313,8 +300,6 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), mods[i]->fini = 0; grub_dl_unload (mods[i]); } - grub_free (mods); - return grub_errno; } diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c index 051e31320..a47ff0776 100644 --- a/grub-core/commands/parttool.c +++ b/grub-core/commands/parttool.c @@ -59,13 +59,7 @@ grub_parttool_register(const char *part_name, for (nargs = 0; args[nargs].name != 0; nargs++); cur->nargs = nargs; cur->args = (struct grub_parttool_argdesc *) - grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); - if (!cur->args) - { - grub_free (cur); - curhandle--; - return -1; - } + grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); grub_memcpy (cur->args, args, (nargs + 1) * sizeof (struct grub_parttool_argdesc)); @@ -199,7 +193,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file; - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST); + file = grub_file_open (filename); if (file) { char *buf = 0; @@ -249,21 +243,13 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), } if (argc == 1) - { - err = show_help (dev); - grub_device_close (dev); - return err; - } + return show_help (dev); for (i = 1; i < argc; i++) if (grub_strcmp (args[i], "help") == 0) - { - err = show_help (dev); - grub_device_close (dev); - return err; - } + return show_help (dev); - parsed = (int *) grub_calloc (argc, sizeof (int)); + parsed = (int *) grub_zalloc (argc * sizeof (int)); for (i = 1; i < argc; i++) if (! parsed[i]) @@ -288,15 +274,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), break; } if (! cur) - { - grub_free (parsed); - grub_device_close (dev); - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"), + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unknown argument `%s'"), args[i]); - } ptool = cur; pargs = (struct grub_parttool_args *) - grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); + grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); for (j = i; j < argc; j++) if (! parsed[j]) { diff --git a/grub-core/commands/password_pbkdf2.c b/grub-core/commands/password_pbkdf2.c index ab845d25e..0dd1aef3d 100644 --- a/grub-core/commands/password_pbkdf2.c +++ b/grub-core/commands/password_pbkdf2.c @@ -45,7 +45,6 @@ check_password (const char *user, const char *entered, void *pin) grub_uint8_t *buf; struct pbkdf2_password *pass = pin; gcry_err_code_t err; - grub_err_t ret; buf = grub_malloc (pass->buflen); if (!buf) @@ -56,17 +55,17 @@ check_password (const char *user, const char *entered, void *pin) pass->salt, pass->saltlen, pass->c, buf, pass->buflen); if (err) - ret = grub_crypto_gcry_error (err); - else if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0) - ret = GRUB_ACCESS_DENIED; - else { - grub_auth_authenticate (user); - ret = GRUB_ERR_NONE; + grub_free (buf); + return grub_crypto_gcry_error (err); } - grub_free (buf); - return ret; + if (grub_crypto_memcmp (buf, pass->expected, pass->buflen) != 0) + return GRUB_ACCESS_DENIED; + + grub_auth_authenticate (user); + + return GRUB_ERR_NONE; } static inline int @@ -86,7 +85,7 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { grub_err_t err; - const char *ptr, *ptr2; + char *ptr, *ptr2; grub_uint8_t *ptro; struct pbkdf2_password *pass; @@ -105,10 +104,7 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), pass->c = grub_strtoul (ptr, &ptr, 0); if (grub_errno) - { - grub_free (pass); - return grub_errno; - } + return grub_errno; if (*ptr != '.') { grub_free (pass); diff --git a/grub-core/commands/pcidump.c b/grub-core/commands/pcidump.c index f72628fce..f99ad4a21 100644 --- a/grub-core/commands/pcidump.c +++ b/grub-core/commands/pcidump.c @@ -95,7 +95,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, if (ctxt->state[0].set) { ptr = ctxt->state[0].arg; - ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -108,7 +108,8 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, if (*ptr != ':') return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; - ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) + << 16; if (grub_errno == GRUB_ERR_BAD_NUMBER) grub_errno = GRUB_ERR_NONE; else @@ -120,10 +121,10 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, if (ctxt->state[1].set) { const char *optr; - + ptr = ctxt->state[1].arg; optr = ptr; - ctx.bus = grub_strtoul (ptr, &ptr, 16); + ctx.bus = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -137,7 +138,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; optr = ptr; - ctx.device = grub_strtoul (ptr, &ptr, 16); + ctx.device = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -148,7 +149,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, if (*ptr == '.') { ptr++; - ctx.function = grub_strtoul (ptr, &ptr, 16); + ctx.function = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_errno; ctx.check_function = 1; diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 573bdf603..cf2793e1d 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -32,7 +31,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -47,7 +45,6 @@ static const struct grub_arg_option options[] = {"fs", 'f', 0, N_("Determine filesystem type."), 0, 0}, {"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), 0, 0}, {"label", 'l', 0, N_("Determine filesystem label."), 0, 0}, - {"part-uuid", 0, 0, N_("Determine partition UUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -101,52 +98,6 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } - if (state[6].set) - { - /* AAAABBBB-CCCC-DDDD-EEEE-FFFFFFFFFFFF + null terminator */ - char val[37] = "none"; - if (dev->disk && dev->disk->partition) - { - struct grub_partition *p = dev->disk->partition; - grub_disk_t disk = grub_disk_open(dev->disk->name); - - if (!disk) - return grub_errno; - if (grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) - { - struct grub_gpt_partentry entry; - grub_gpt_part_guid_t *guid; - - if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), &entry)) - return grub_errno; - guid = &entry.guid; - grub_snprintf (val, sizeof(val), - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - grub_le_to_cpu32 (guid->data1), - grub_le_to_cpu16 (guid->data2), - grub_le_to_cpu16 (guid->data3), - guid->data4[0], guid->data4[1], guid->data4[2], - guid->data4[3], guid->data4[4], guid->data4[5], - guid->data4[6], guid->data4[7]); - } - else if (grub_strcmp(dev->disk->partition->partmap->name, "msdos") == 0) - { - grub_uint32_t nt_disk_sig; - - if (grub_disk_read(disk, 0, GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - sizeof(nt_disk_sig), &nt_disk_sig) == 0) - grub_snprintf (val, sizeof(val), "%08x-%02x", - grub_le_to_cpu32(nt_disk_sig), 1 + p->number); - } - grub_disk_close(disk); - } - if (state[0].set) - grub_env_set (state[0].arg, val); - else - grub_printf ("%s", val); - grub_device_close (dev); - return GRUB_ERR_NONE; - } fs = grub_fs_probe (dev); if (! fs) return grub_errno; @@ -162,10 +113,10 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) if (state[4].set) { char *uuid; - if (! fs->fs_uuid) + if (! fs->uuid) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("%s does not support UUIDs"), fs->name); - err = fs->fs_uuid (dev, &uuid); + err = fs->uuid (dev, &uuid); if (err) return err; if (! uuid) @@ -183,11 +134,11 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) if (state[5].set) { char *label; - if (! fs->fs_label) + if (! fs->label) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("filesystem `%s' does not support labels"), fs->name); - err = fs->fs_label (dev, &label); + err = fs->label (dev, &label); if (err) return err; if (! label) diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c index 612003f94..f00b184c8 100644 --- a/grub-core/commands/regexp.c +++ b/grub-core/commands/regexp.c @@ -64,7 +64,7 @@ set_matches (char **varnames, char *str, grub_size_t nmatches, { int i; char *p; - const char * q; + char *q; grub_err_t err; unsigned long j; @@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) if (ret) goto fail; - matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); + matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); if (! matches) goto fail; diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index ed090b3af..16143a34c 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -64,7 +64,7 @@ iterate_device (const char *name, void *data) /* Skip floppy drives when requested. */ if (ctx->no_floppy && name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9') - return 1; + return 0; #ifdef DO_SEARCH_FS_UUID #define compare_fn grub_strcasecmp @@ -81,8 +81,8 @@ iterate_device (const char *name, void *data) if (! buf) return 1; - file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (buf); if (file) { found = 1; @@ -103,9 +103,9 @@ iterate_device (const char *name, void *data) fs = grub_fs_probe (dev); #ifdef DO_SEARCH_FS_UUID -#define read_fn fs_uuid +#define read_fn uuid #else -#define read_fn fs_label +#define read_fn label #endif if (fs && fs->read_fn) @@ -210,10 +210,10 @@ try (struct search_ctx *ctx) /* Cache entry was outdated. Remove it. */ if (!ctx->count) { - *prev = cache_ent->next; grub_free (cache_ent->key); grub_free (cache_ent->value); grub_free (cache_ent); + *prev = cache_ent->next; } } diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index 47fc8eb99..3f75fecdf 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) nhints++; - hints = grub_calloc (nhints, sizeof (hints[0])); + hints = grub_malloc (sizeof (hints[0]) * nhints); if (!hints) return grub_errno; j = 0; @@ -175,10 +175,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) var = "root"; } else - { - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); - goto out; - } + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); if (state[SEARCH_LABEL].set) grub_search_label (id, var, state[SEARCH_NO_FLOPPY].set, @@ -190,10 +187,8 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set, hints, nhints); else - grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); + return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); -out: - grub_free (hints); return grub_errno; } diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c index e966af080..d5bc97d60 100644 --- a/grub-core/commands/setpci.c +++ b/grub-core/commands/setpci.c @@ -169,7 +169,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (ctxt->state[0].set) { ptr = ctxt->state[0].arg; - pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -182,7 +182,8 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (*ptr != ':') return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; - pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) + << 16; if (grub_errno == GRUB_ERR_BAD_NUMBER) grub_errno = GRUB_ERR_NONE; else @@ -196,10 +197,10 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (ctxt->state[1].set) { const char *optr; - + ptr = ctxt->state[1].arg; optr = ptr; - bus = grub_strtoul (ptr, &ptr, 16); + bus = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -213,7 +214,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); ptr++; optr = ptr; - device = grub_strtoul (ptr, &ptr, 16); + device = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno == GRUB_ERR_BAD_NUMBER) { grub_errno = GRUB_ERR_NONE; @@ -224,7 +225,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (*ptr == '.') { ptr++; - function = grub_strtoul (ptr, &ptr, 16); + function = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_errno; check_function = 1; @@ -252,7 +253,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (i == ARRAY_SIZE (pci_registers)) { regsize = 0; - regaddr = grub_strtoul (ptr, &ptr, 16); + regaddr = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown register"); } @@ -269,7 +270,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (*ptr == '+') { ptr++; - regaddr += grub_strtoul (ptr, &ptr, 16); + regaddr += grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_errno; } @@ -301,14 +302,14 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) if (*ptr == '=') { ptr++; - regwrite = grub_strtoul (ptr, &ptr, 16); + regwrite = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_errno; write_mask = 0xffffffff; if (*ptr == ':') { ptr++; - write_mask = grub_strtoul (ptr, &ptr, 16); + write_mask = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) return grub_errno; write_mask = 0xffffffff; diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c index a1370b710..e77e7900f 100644 --- a/grub-core/commands/sleep.c +++ b/grub-core/commands/sleep.c @@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) start = grub_get_time_ms (); while (grub_get_time_ms () - start < ms) - if (grub_key_is_interrupt (grub_getkey_noblock ())) + if (grub_getkey_noblock () == GRUB_TERM_ESC) return 1; return 0; diff --git a/grub-core/commands/smbios.c b/grub-core/commands/smbios.c deleted file mode 100644 index 1a9086ddd..000000000 --- a/grub-core/commands/smbios.c +++ /dev/null @@ -1,398 +0,0 @@ -/* smbios.c - retrieve smbios information. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -/* Abstract useful values found in either the SMBIOS3 or SMBIOS EPS. */ -static struct { - grub_addr_t start; - grub_addr_t end; - grub_uint16_t structures; -} table_desc; - -static grub_extcmd_t cmd; - -/* Locate the SMBIOS entry point structure depending on the hardware. */ -struct grub_smbios_eps * -grub_smbios_get_eps (void) -{ - static struct grub_smbios_eps *eps = NULL; - - if (eps != NULL) - return eps; - - eps = grub_machine_smbios_get_eps (); - - return eps; -} - -/* Locate the SMBIOS3 entry point structure depending on the hardware. */ -static struct grub_smbios_eps3 * -grub_smbios_get_eps3 (void) -{ - static struct grub_smbios_eps3 *eps = NULL; - - if (eps != NULL) - return eps; - - eps = grub_machine_smbios_get_eps3 (); - - return eps; -} - -static char * -linux_string (const char *value) -{ - char *out = grub_malloc( grub_strlen (value) + 1); - const char *src = value; - char *dst = out; - - for (; *src; src++) - if (*src > ' ' && *src < 127 && *src != ':') - *dst++ = *src; - - *dst = 0; - return out; -} - -/* - * These functions convert values from the various SMBIOS structure field types - * into a string formatted to be returned to the user. They expect that the - * structure and offset were already validated. When the requested data is - * successfully retrieved and formatted, the pointer to the string is returned; - * otherwise, NULL is returned on failure. Don't free the result. - */ - -static const char * -grub_smbios_format_byte (const grub_uint8_t *structure, grub_uint8_t offset) -{ - static char buffer[sizeof ("255")]; - - grub_snprintf (buffer, sizeof (buffer), "%u", structure[offset]); - - return (const char *)buffer; -} - -static const char * -grub_smbios_format_word (const grub_uint8_t *structure, grub_uint8_t offset) -{ - static char buffer[sizeof ("65535")]; - - grub_uint16_t value = grub_get_unaligned16 (structure + offset); - grub_snprintf (buffer, sizeof (buffer), "%u", value); - - return (const char *)buffer; -} - -static const char * -grub_smbios_format_dword (const grub_uint8_t *structure, grub_uint8_t offset) -{ - static char buffer[sizeof ("4294967295")]; - - grub_uint32_t value = grub_get_unaligned32 (structure + offset); - grub_snprintf (buffer, sizeof (buffer), "%" PRIuGRUB_UINT32_T, value); - - return (const char *)buffer; -} - -static const char * -grub_smbios_format_qword (const grub_uint8_t *structure, grub_uint8_t offset) -{ - static char buffer[sizeof ("18446744073709551615")]; - - grub_uint64_t value = grub_get_unaligned64 (structure + offset); - grub_snprintf (buffer, sizeof (buffer), "%" PRIuGRUB_UINT64_T, value); - - return (const char *)buffer; -} - -static const char * -grub_smbios_get_string (const grub_uint8_t *structure, grub_uint8_t offset) -{ - const grub_uint8_t *ptr = structure + structure[1]; - const grub_uint8_t *table_end = (const grub_uint8_t *)table_desc.end; - const grub_uint8_t referenced_string_number = structure[offset]; - grub_uint8_t i; - - /* A string referenced with zero is interpreted as unset. */ - if (referenced_string_number == 0) - return NULL; - - /* Search the string set. */ - for (i = 1; *ptr != 0 && ptr < table_end; i++) - if (i == referenced_string_number) - { - const char *str = (const char *)ptr; - while (*ptr++ != 0) - if (ptr >= table_end) - return NULL; /* The string isn't terminated. */ - return str; - } - else - while (*ptr++ != 0 && ptr < table_end); - - /* The string number is greater than the number of strings in the set. */ - return NULL; -} - -static const char * -grub_smbios_format_uuid (const grub_uint8_t *structure, grub_uint8_t offset) -{ - static char buffer[sizeof ("ffffffff-ffff-ffff-ffff-ffffffffffff")]; - const grub_uint8_t *f = structure + offset; /* little-endian fields */ - const grub_uint8_t *g = f + 8; /* byte-by-byte fields */ - - grub_snprintf (buffer, sizeof (buffer), - "%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x-%02x%02x%02x%02x%02x%02x", - f[3], f[2], f[1], f[0], f[5], f[4], f[7], f[6], - g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7]); - - return (const char *)buffer; -} - -/* List the field formatting functions and the number of bytes they need. */ -static const struct { - const char *(*format) (const grub_uint8_t *structure, grub_uint8_t offset); - grub_uint8_t field_length; -} field_extractors[] = { - {grub_smbios_format_byte, 1}, - {grub_smbios_format_word, 2}, - {grub_smbios_format_dword, 4}, - {grub_smbios_format_qword, 8}, - {grub_smbios_get_string, 1}, - {grub_smbios_format_uuid, 16} -}; - -/* List command options, with structure field getters ordered as above. */ -#define FIRST_GETTER_OPT (3) -#define SETTER_OPT (FIRST_GETTER_OPT + ARRAY_SIZE(field_extractors)) -#define LINUX_OPT (FIRST_GETTER_OPT + ARRAY_SIZE(field_extractors) + 1) - -static const struct grub_arg_option options[] = { - {"type", 't', 0, N_("Match structures with the given type."), - N_("type"), ARG_TYPE_INT}, - {"handle", 'h', 0, N_("Match structures with the given handle."), - N_("handle"), ARG_TYPE_INT}, - {"match", 'm', 0, N_("Select a structure when several match."), - N_("match"), ARG_TYPE_INT}, - {"get-byte", 'b', 0, N_("Get the byte's value at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"get-word", 'w', 0, N_("Get two bytes' value at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"get-dword", 'd', 0, N_("Get four bytes' value at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"get-qword", 'q', 0, N_("Get eight bytes' value at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"get-string", 's', 0, N_("Get the string specified at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"get-uuid", 'u', 0, N_("Get the UUID's value at the given offset."), - N_("offset"), ARG_TYPE_INT}, - {"set", '\0', 0, N_("Store the value in the given variable name."), - N_("variable"), ARG_TYPE_STRING}, - {"linux", '\0', 0, N_("Filter the result like linux does."), - N_("variable"), ARG_TYPE_NONE}, - {0, 0, 0, 0, 0, 0} -}; - -/* - * Return a matching SMBIOS structure. - * - * This method can use up to three criteria for selecting a structure: - * - The "type" field (use -1 to ignore) - * - The "handle" field (use -1 to ignore) - * - Which to return if several match (use 0 to ignore) - * - * The return value is a pointer to the first matching structure. If no - * structures match the given parameters, NULL is returned. - */ -static const grub_uint8_t * -grub_smbios_match_structure (const grub_int16_t type, - const grub_int32_t handle, - const grub_uint16_t match) -{ - const grub_uint8_t *ptr = (const grub_uint8_t *)table_desc.start; - const grub_uint8_t *table_end = (const grub_uint8_t *)table_desc.end; - grub_uint16_t structures = table_desc.structures; - grub_uint16_t structure_count = 0; - grub_uint16_t matches = 0; - - while (ptr < table_end - && ptr[1] >= 4 /* Valid structures include the 4-byte header. */ - && (structure_count++ < structures || structures == 0)) - { - grub_uint16_t structure_handle = grub_get_unaligned16 (ptr + 2); - grub_uint8_t structure_type = ptr[0]; - - if ((handle < 0 || handle == structure_handle) - && (type < 0 || type == structure_type) - && (match == 0 || match == ++matches)) - return ptr; - else - { - ptr += ptr[1]; - while ((*ptr++ != 0 || *ptr++ != 0) && ptr < table_end); - } - - if (structure_type == GRUB_SMBIOS_TYPE_END_OF_TABLE) - break; - } - - return NULL; -} - -static grub_err_t -grub_cmd_smbios (grub_extcmd_context_t ctxt, - int argc __attribute__ ((unused)), - char **argv __attribute__ ((unused))) -{ - struct grub_arg_list *state = ctxt->state; - - grub_int16_t type = -1; - grub_int32_t handle = -1; - grub_uint16_t match = 0; - grub_uint8_t offset = 0; - - const grub_uint8_t *structure; - const char *value; - char *modified_value = NULL; - grub_int32_t option; - grub_int8_t field_type = -1; - grub_uint8_t i; - - if (table_desc.start == 0) - return grub_error (GRUB_ERR_IO, - N_("the SMBIOS entry point structure was not found")); - - /* Read the given filtering options. */ - if (state[0].set) - { - option = grub_strtol (state[0].arg, NULL, 0); - if (option < 0 || option > 255) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("the type must be between 0 and 255")); - type = (grub_int16_t)option; - } - if (state[1].set) - { - option = grub_strtol (state[1].arg, NULL, 0); - if (option < 0 || option > 65535) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("the handle must be between 0 and 65535")); - handle = (grub_int32_t)option; - } - if (state[2].set) - { - option = grub_strtol (state[2].arg, NULL, 0); - if (option <= 0 || option > 65535) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("the match must be a positive integer")); - match = (grub_uint16_t)option; - } - - /* Determine the data type of the structure field to retrieve. */ - for (i = 0; i < ARRAY_SIZE(field_extractors); i++) - if (state[FIRST_GETTER_OPT + i].set) - { - if (field_type >= 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("only one --get option is usable at a time")); - field_type = i; - } - - /* Require a choice of a structure field to return. */ - if (field_type < 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("one of the --get options is required")); - - /* Locate a matching SMBIOS structure. */ - structure = grub_smbios_match_structure (type, handle, match); - if (structure == NULL) - return grub_error (GRUB_ERR_IO, - N_("no structure matched the given options")); - - /* Ensure the requested byte offset is inside the structure. */ - option = grub_strtol (state[FIRST_GETTER_OPT + field_type].arg, NULL, 0); - if (option < 0 || option >= structure[1]) - return grub_error (GRUB_ERR_OUT_OF_RANGE, - N_("the given offset is outside the structure")); - - /* Ensure the requested data type at the offset is inside the structure. */ - offset = (grub_uint8_t)option; - if (offset + field_extractors[field_type].field_length > structure[1]) - return grub_error (GRUB_ERR_OUT_OF_RANGE, - N_("the field ends outside the structure")); - - /* Format the requested structure field into a readable string. */ - value = field_extractors[field_type].format (structure, offset); - if (value == NULL) - return grub_error (GRUB_ERR_IO, - N_("failed to retrieve the structure field")); - - if (state[LINUX_OPT].set) - value = modified_value = linux_string (value); - - /* Store or print the formatted value. */ - if (state[SETTER_OPT].set) - grub_env_set (state[SETTER_OPT].arg, value); - else - grub_printf ("%s\n", value); - - grub_free(modified_value); - - return GRUB_ERR_NONE; -} - -GRUB_MOD_INIT(smbios) -{ - struct grub_smbios_eps3 *eps3; - struct grub_smbios_eps *eps; - - if ((eps3 = grub_smbios_get_eps3 ())) - { - table_desc.start = (grub_addr_t)eps3->table_address; - table_desc.end = table_desc.start + eps3->maximum_table_length; - table_desc.structures = 0; /* SMBIOS3 drops the structure count. */ - } - else if ((eps = grub_smbios_get_eps ())) - { - table_desc.start = (grub_addr_t)eps->intermediate.table_address; - table_desc.end = table_desc.start + eps->intermediate.table_length; - table_desc.structures = eps->intermediate.structures; - } - - cmd = grub_register_extcmd ("smbios", grub_cmd_smbios, 0, - N_("[-t type] [-h handle] [-m match] " - "(-b|-w|-d|-q|-s|-u) offset " - "[--set variable]"), - N_("Retrieve SMBIOS information."), options); -} - -GRUB_MOD_FINI(smbios) -{ - grub_unregister_extcmd (cmd); -} diff --git a/grub-core/commands/syslinuxcfg.c b/grub-core/commands/syslinuxcfg.c index 7be28fada..00ae113c5 100644 --- a/grub-core/commands/syslinuxcfg.c +++ b/grub-core/commands/syslinuxcfg.c @@ -119,10 +119,7 @@ syslinux_file (grub_extcmd_context_t ctxt, const char *filename) { menu = grub_zalloc (sizeof (*menu)); if (! menu) - { - grub_free (result); - return grub_errno; - } + return grub_errno; grub_env_set_menu (menu); } diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c index 62d3fb398..c98c13d8c 100644 --- a/grub-core/commands/test.c +++ b/grub-core/commands/test.c @@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); /* A simple implementation for signed numbers. */ static int -grub_strtosl (char *arg, const char ** const end, int base) +grub_strtosl (char *arg, char **end, int base) { if (arg[0] == '-') return -grub_strtoul (arg + 1, end, base); @@ -133,15 +133,15 @@ get_fileinfo (char *path, struct test_parse_ctx *ctx) /* Fetch writing time. */ ctx->file_info.mtimeset = 0; - if (fs->fs_mtime) + if (fs->mtime) { - if (! fs->fs_mtime (dev, &ctx->file_info.mtime)) + if (! fs->mtime (dev, &ctx->file_info.mtime)) ctx->file_info.mtimeset = 1; grub_errno = GRUB_ERR_NONE; } } else - (fs->fs_dir) (dev, path, find_file, ctx); + (fs->dir) (dev, path, find_file, ctx); grub_device_close (dev); grub_free (path); @@ -332,7 +332,7 @@ test_parse (char **args, int *argn, int argc) get_fileinfo (args[*argn + 1], &ctx); update_val (ctx.file_exists && ctx.file_info.dir, &ctx); (*argn) += 2; - continue; + return ctx.or || ctx.and; } if (grub_strcmp (args[*argn], "-e") == 0) @@ -340,7 +340,7 @@ test_parse (char **args, int *argn, int argc) get_fileinfo (args[*argn + 1], &ctx); update_val (ctx.file_exists, &ctx); (*argn) += 2; - continue; + return ctx.or || ctx.and; } if (grub_strcmp (args[*argn], "-f") == 0) @@ -349,20 +349,20 @@ test_parse (char **args, int *argn, int argc) /* FIXME: check for other types. */ update_val (ctx.file_exists && ! ctx.file_info.dir, &ctx); (*argn) += 2; - continue; + return ctx.or || ctx.and; } if (grub_strcmp (args[*argn], "-s") == 0) { grub_file_t file; - file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (args[*argn + 1]); update_val (file && (grub_file_size (file) != 0), &ctx); if (file) grub_file_close (file); grub_errno = GRUB_ERR_NONE; (*argn) += 2; - continue; + return ctx.or || ctx.and; } /* String tests. */ diff --git a/grub-core/commands/testload.c b/grub-core/commands/testload.c index ff01a0516..cfab6763d 100644 --- a/grub-core/commands/testload.c +++ b/grub-core/commands/testload.c @@ -57,7 +57,7 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)), if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_TESTLOAD); + file = grub_file_open (argv[0]); if (! file) return grub_errno; diff --git a/grub-core/commands/testspeed.c b/grub-core/commands/testspeed.c index c13a9b8d8..042645f8d 100644 --- a/grub-core/commands/testspeed.c +++ b/grub-core/commands/testspeed.c @@ -61,7 +61,7 @@ grub_cmd_testspeed (grub_extcmd_context_t ctxt, int argc, char **args) if (buffer == NULL) return grub_errno; - file = grub_file_open (args[0], GRUB_FILE_TYPE_TESTLOAD); + file = grub_file_open (args[0]); if (file == NULL) goto quit; diff --git a/grub-core/commands/tpm.c b/grub-core/commands/tpm.c deleted file mode 100644 index 2052c36ea..000000000 --- a/grub-core/commands/tpm.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - * - * Core TPM support code. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_tpm_verify_init (grub_file_t io, - enum grub_file_type type __attribute__ ((unused)), - void **context, enum grub_verify_flags *flags) -{ - *context = io->name; - *flags |= GRUB_VERIFY_FLAGS_SINGLE_CHUNK; - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_tpm_verify_write (void *context, void *buf, grub_size_t size) -{ - return grub_tpm_measure (buf, size, GRUB_BINARY_PCR, context); -} - -static grub_err_t -grub_tpm_verify_string (char *str, enum grub_verify_string_type type) -{ - const char *prefix = NULL; - char *description; - grub_err_t status; - - switch (type) - { - case GRUB_VERIFY_KERNEL_CMDLINE: - prefix = "kernel_cmdline: "; - break; - case GRUB_VERIFY_MODULE_CMDLINE: - prefix = "module_cmdline: "; - break; - case GRUB_VERIFY_COMMAND: - prefix = "grub_cmd: "; - break; - } - description = grub_malloc (grub_strlen (str) + grub_strlen (prefix) + 1); - if (!description) - return grub_errno; - grub_memcpy (description, prefix, grub_strlen (prefix)); - grub_memcpy (description + grub_strlen (prefix), str, - grub_strlen (str) + 1); - status = - grub_tpm_measure ((unsigned char *) str, grub_strlen (str), - GRUB_STRING_PCR, description); - grub_free (description); - return status; -} - -struct grub_file_verifier grub_tpm_verifier = { - .name = "tpm", - .init = grub_tpm_verify_init, - .write = grub_tpm_verify_write, - .verify_string = grub_tpm_verify_string, -}; - -GRUB_MOD_INIT (tpm) -{ - grub_verifier_register (&grub_tpm_verifier); -} - -GRUB_MOD_FINI (tpm) -{ - grub_verifier_unregister (&grub_tpm_verifier); -} diff --git a/grub-core/commands/tr.c b/grub-core/commands/tr.c index ef72841a2..84ad6ff8f 100644 --- a/grub-core/commands/tr.c +++ b/grub-core/commands/tr.c @@ -80,7 +80,7 @@ grub_cmd_tr (grub_extcmd_context_t ctxt, int argc, char **args) } else if (argc > 3) return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters"); - if (!s1 || !s2 || !input) + if (argc <= 0 && (!s1 || !s2 || !input)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing parameters"); if (grub_strlen (s1) != grub_strlen (s2)) diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c index 2c6d93fe6..01cdca934 100644 --- a/grub-core/commands/usbtest.c +++ b/grub-core/commands/usbtest.c @@ -63,11 +63,6 @@ static const char *usb_devspeed[] = "High" }; -#if __GNUC__ >= 9 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif - static grub_usb_err_t grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid, char **string) @@ -113,10 +108,6 @@ grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid, return GRUB_USB_ERR_NONE; } -#if __GNUC__ >= 9 -#pragma GCC diagnostic pop -#endif - static void usb_print_str (const char *description, grub_usb_device_t dev, int idx) { diff --git a/grub-core/commands/verifiers.c b/grub-core/commands/verifiers.c deleted file mode 100644 index aae4d84bb..000000000 --- a/grub-core/commands/verifiers.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2017 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - * - * Verifiers helper. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -struct grub_file_verifier *grub_file_verifiers; - -struct grub_verified -{ - grub_file_t file; - void *buf; -}; -typedef struct grub_verified *grub_verified_t; - -static void -verified_free (grub_verified_t verified) -{ - if (verified) - { - grub_free (verified->buf); - grub_free (verified); - } -} - -static grub_ssize_t -verified_read (struct grub_file *file, char *buf, grub_size_t len) -{ - grub_verified_t verified = file->data; - - grub_memcpy (buf, (char *) verified->buf + file->offset, len); - return len; -} - -static grub_err_t -verified_close (struct grub_file *file) -{ - grub_verified_t verified = file->data; - - grub_file_close (verified->file); - verified_free (verified); - file->data = 0; - - /* Device and name are freed by parent. */ - file->device = 0; - file->name = 0; - - return grub_errno; -} - -struct grub_fs verified_fs = -{ - .name = "verified_read", - .fs_read = verified_read, - .fs_close = verified_close -}; - -static grub_file_t -grub_verifiers_open (grub_file_t io, enum grub_file_type type) -{ - grub_verified_t verified = NULL; - struct grub_file_verifier *ver; - void *context; - grub_file_t ret = 0; - grub_err_t err; - int defer = 0; - - grub_dprintf ("verify", "file: %s type: %d\n", io->name, type); - - if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_SIGNATURE - || (type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_VERIFY_SIGNATURE - || (type & GRUB_FILE_TYPE_SKIP_SIGNATURE)) - return io; - - if (io->device->disk && - (io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID - || io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID)) - return io; - - FOR_LIST_ELEMENTS(ver, grub_file_verifiers) - { - enum grub_verify_flags flags = 0; - err = ver->init (io, type, &context, &flags); - if (err) - goto fail_noclose; - if (flags & GRUB_VERIFY_FLAGS_DEFER_AUTH) - { - defer = 1; - continue; - } - if (!(flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION)) - break; - } - - if (!ver) - { - if (defer) - { - grub_error (GRUB_ERR_ACCESS_DENIED, - N_("verification requested but nobody cares: %s"), io->name); - goto fail_noclose; - } - - /* No verifiers wanted to verify. Just return underlying file. */ - return io; - } - - ret = grub_malloc (sizeof (*ret)); - if (!ret) - { - goto fail; - } - *ret = *io; - - ret->fs = &verified_fs; - ret->not_easily_seekable = 0; - if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1)) - { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - N_("big file signature isn't implemented yet")); - goto fail; - } - verified = grub_malloc (sizeof (*verified)); - if (!verified) - { - goto fail; - } - verified->buf = grub_malloc (ret->size); - if (!verified->buf) - { - goto fail; - } - if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size) - { - if (!grub_errno) - grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), - io->name); - goto fail; - } - - err = ver->write (context, verified->buf, ret->size); - if (err) - goto fail; - - err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE; - if (err) - goto fail; - - if (ver->close) - ver->close (context); - - FOR_LIST_ELEMENTS_NEXT(ver, grub_file_verifiers) - { - enum grub_verify_flags flags = 0; - err = ver->init (io, type, &context, &flags); - if (err) - goto fail_noclose; - if (flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION || - /* Verification done earlier. So, we are happy here. */ - flags & GRUB_VERIFY_FLAGS_DEFER_AUTH) - continue; - err = ver->write (context, verified->buf, ret->size); - if (err) - goto fail; - - err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE; - if (err) - goto fail; - - if (ver->close) - ver->close (context); - } - - verified->file = io; - ret->data = verified; - return ret; - - fail: - if (ver->close) - ver->close (context); - fail_noclose: - verified_free (verified); - grub_free (ret); - return NULL; -} - -grub_err_t -grub_verify_string (char *str, enum grub_verify_string_type type) -{ - struct grub_file_verifier *ver; - - grub_dprintf ("verify", "string: %s, type: %d\n", str, type); - - FOR_LIST_ELEMENTS(ver, grub_file_verifiers) - { - grub_err_t err; - err = ver->verify_string ? ver->verify_string (str, type) : GRUB_ERR_NONE; - if (err) - return err; - } - return GRUB_ERR_NONE; -} - -GRUB_MOD_INIT(verifiers) -{ - grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verifiers_open); -} - -GRUB_MOD_FINI(verifiers) -{ - grub_file_filter_unregister (GRUB_FILE_FILTER_VERIFY); -} diff --git a/grub-core/commands/pgp.c b/grub-core/commands/verify.c similarity index 68% rename from grub-core/commands/pgp.c rename to grub-core/commands/verify.c index bbf6871fe..d5995766b 100644 --- a/grub-core/commands/pgp.c +++ b/grub-core/commands/verify.c @@ -30,10 +30,16 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); +struct grub_verified +{ + grub_file_t file; + void *buf; +}; +typedef struct grub_verified *grub_verified_t; + enum { OPTION_SKIP_SIG = 0 @@ -302,7 +308,7 @@ grub_load_public_key (grub_file_t f) if (!sk) goto fail; - grub_memset (fingerprint_context, 0, GRUB_MD_SHA1->contextsize); + grub_memset (fingerprint_context, 0, sizeof (fingerprint_context)); GRUB_MD_SHA1->init (fingerprint_context); GRUB_MD_SHA1->write (fingerprint_context, "\x99", 1); len_be = grub_cpu_to_be16 (len); @@ -318,19 +324,19 @@ grub_load_public_key (grub_file_t f) if (grub_file_read (f, &l, sizeof (l)) != sizeof (l)) { grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - break; + goto fail; } lb = (grub_be_to_cpu16 (l) + GRUB_CHAR_BIT - 1) / GRUB_CHAR_BIT; if (lb > READBUF_SIZE - sizeof (grub_uint16_t)) { grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - break; + goto fail; } if (grub_file_read (f, buffer + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb) { grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - break; + goto fail; } grub_memcpy (buffer, &l, sizeof (l)); @@ -340,16 +346,10 @@ grub_load_public_key (grub_file_t f) buffer, lb + sizeof (grub_uint16_t), 0)) { grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - break; + goto fail; } } - if (i < pkalgos[pk].nmpipub) - { - grub_free (sk); - goto fail; - } - GRUB_MD_SHA1->final (fingerprint_context); grub_memcpy (sk->fingerprint, GRUB_MD_SHA1->read (fingerprint_context), 20); @@ -439,26 +439,22 @@ rsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval, return ret; } -struct grub_pubkey_context -{ - grub_file_t sig; - struct signature_v4_header v4; - grub_uint8_t v; - const gcry_md_spec_t *hash; - void *hash_context; -}; - static grub_err_t -grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig) +grub_verify_signature_real (char *buf, grub_size_t size, + grub_file_t f, grub_file_t sig, + struct grub_public_key *pkey) { grub_size_t len; + grub_uint8_t v; grub_uint8_t h; grub_uint8_t t; grub_uint8_t pk; + const gcry_md_spec_t *hash; + struct signature_v4_header v4; grub_err_t err; - grub_uint8_t type = 0; - - grub_memset (ctxt, 0, sizeof (*ctxt)); + grub_size_t i; + gcry_mpi_t mpis[10]; + grub_uint8_t type; err = read_packet_header (sig, &type, &len); if (err) @@ -467,18 +463,18 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig) if (type != 0x2) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - if (grub_file_read (sig, &ctxt->v, sizeof (ctxt->v)) != sizeof (ctxt->v)) + if (grub_file_read (sig, &v, sizeof (v)) != sizeof (v)) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - if (ctxt->v != 4) + if (v != 4) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - if (grub_file_read (sig, &ctxt->v4, sizeof (ctxt->v4)) != sizeof (ctxt->v4)) + if (grub_file_read (sig, &v4, sizeof (v4)) != sizeof (v4)) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - h = ctxt->v4.hash; - t = ctxt->v4.type; - pk = ctxt->v4.pkeyalgo; + h = v4.hash; + t = v4.type; + pk = v4.pkeyalgo; if (t != 0) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); @@ -489,242 +485,183 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig) if (pk >= ARRAY_SIZE (pkalgos) || pkalgos[pk].name == NULL) return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - ctxt->hash = grub_crypto_lookup_md_by_name (hashes[h]); - if (!ctxt->hash) + hash = grub_crypto_lookup_md_by_name (hashes[h]); + if (!hash) return grub_error (GRUB_ERR_BAD_SIGNATURE, "hash `%s' not loaded", hashes[h]); grub_dprintf ("crypt", "alive\n"); - ctxt->hash_context = grub_zalloc (ctxt->hash->contextsize); - if (!ctxt->hash_context) - return grub_errno; - - ctxt->hash->init (ctxt->hash_context); - ctxt->sig = sig; - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_pubkey_write (void *ctxt_, void *buf, grub_size_t size) -{ - struct grub_pubkey_context *ctxt = ctxt_; - ctxt->hash->write (ctxt->hash_context, buf, size); - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_verify_signature_real (struct grub_pubkey_context *ctxt, - struct grub_public_key *pkey) -{ - gcry_mpi_t mpis[10]; - grub_uint8_t pk = ctxt->v4.pkeyalgo; - grub_size_t i; - grub_uint8_t *readbuf = NULL; - unsigned char *hval; - grub_ssize_t rem = grub_be_to_cpu16 (ctxt->v4.hashed_sub); - grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6); - grub_uint8_t s; - grub_uint16_t unhashed_sub; - grub_ssize_t r; - grub_uint8_t hash_start[2]; - gcry_mpi_t hmpi; - grub_uint64_t keyid = 0; - struct grub_public_subkey *sk; - - readbuf = grub_malloc (READBUF_SIZE); - if (!readbuf) - goto fail; - - ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v)); - ctxt->hash->write (ctxt->hash_context, &ctxt->v4, sizeof (ctxt->v4)); - while (rem) - { - r = grub_file_read (ctxt->sig, readbuf, - rem < READBUF_SIZE ? rem : READBUF_SIZE); - if (r < 0) - goto fail; - if (r == 0) - break; - ctxt->hash->write (ctxt->hash_context, readbuf, r); - rem -= r; - } - ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v)); - s = 0xff; - ctxt->hash->write (ctxt->hash_context, &s, sizeof (s)); - ctxt->hash->write (ctxt->hash_context, &headlen, sizeof (headlen)); - r = grub_file_read (ctxt->sig, &unhashed_sub, sizeof (unhashed_sub)); - if (r != sizeof (unhashed_sub)) - goto fail; { - grub_uint8_t *ptr; - grub_uint32_t l; - rem = grub_be_to_cpu16 (unhashed_sub); - if (rem > READBUF_SIZE) + void *context = NULL; + unsigned char *hval; + grub_ssize_t rem = grub_be_to_cpu16 (v4.hashed_sub); + grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6); + grub_uint8_t s; + grub_uint16_t unhashed_sub; + grub_ssize_t r; + grub_uint8_t hash_start[2]; + gcry_mpi_t hmpi; + grub_uint64_t keyid = 0; + struct grub_public_subkey *sk; + grub_uint8_t *readbuf = NULL; + + context = grub_zalloc (hash->contextsize); + readbuf = grub_zalloc (READBUF_SIZE); + if (!context || !readbuf) goto fail; - r = grub_file_read (ctxt->sig, readbuf, rem); - if (r != rem) - goto fail; - for (ptr = readbuf; ptr < readbuf + rem; ptr += l) + + hash->init (context); + if (buf) + hash->write (context, buf, size); + else + while (1) + { + r = grub_file_read (f, readbuf, READBUF_SIZE); + if (r < 0) + goto fail; + if (r == 0) + break; + hash->write (context, readbuf, r); + } + + hash->write (context, &v, sizeof (v)); + hash->write (context, &v4, sizeof (v4)); + while (rem) { - if (*ptr < 192) - l = *ptr++; - else if (*ptr < 255) - { - if (ptr + 1 >= readbuf + rem) - break; - l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192; - ptr += 2; - } - else - { - if (ptr + 5 >= readbuf + rem) - break; - l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1)); - ptr += 5; - } - if (*ptr == 0x10 && l >= 8) - keyid = grub_get_unaligned64 (ptr + 1); + r = grub_file_read (sig, readbuf, + rem < READBUF_SIZE ? rem : READBUF_SIZE); + if (r < 0) + goto fail; + if (r == 0) + break; + hash->write (context, readbuf, r); + rem -= r; } + hash->write (context, &v, sizeof (v)); + s = 0xff; + hash->write (context, &s, sizeof (s)); + hash->write (context, &headlen, sizeof (headlen)); + r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub)); + if (r != sizeof (unhashed_sub)) + goto fail; + { + grub_uint8_t *ptr; + grub_uint32_t l; + rem = grub_be_to_cpu16 (unhashed_sub); + if (rem > READBUF_SIZE) + goto fail; + r = grub_file_read (sig, readbuf, rem); + if (r != rem) + goto fail; + for (ptr = readbuf; ptr < readbuf + rem; ptr += l) + { + if (*ptr < 192) + l = *ptr++; + else if (*ptr < 255) + { + if (ptr + 1 >= readbuf + rem) + break; + l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192; + ptr += 2; + } + else + { + if (ptr + 5 >= readbuf + rem) + break; + l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1)); + ptr += 5; + } + if (*ptr == 0x10 && l >= 8) + keyid = grub_get_unaligned64 (ptr + 1); + } + } + + hash->final (context); + + grub_dprintf ("crypt", "alive\n"); + + hval = hash->read (context); + + if (grub_file_read (sig, hash_start, sizeof (hash_start)) != sizeof (hash_start)) + goto fail; + if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0) + goto fail; + + grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (sig)); + + for (i = 0; i < pkalgos[pk].nmpisig; i++) + { + grub_uint16_t l; + grub_size_t lb; + grub_dprintf ("crypt", "alive\n"); + if (grub_file_read (sig, &l, sizeof (l)) != sizeof (l)) + goto fail; + grub_dprintf ("crypt", "alive\n"); + lb = (grub_be_to_cpu16 (l) + 7) / 8; + grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l)); + if (lb > READBUF_SIZE - sizeof (grub_uint16_t)) + goto fail; + grub_dprintf ("crypt", "alive\n"); + if (grub_file_read (sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb) + goto fail; + grub_dprintf ("crypt", "alive\n"); + grub_memcpy (readbuf, &l, sizeof (l)); + grub_dprintf ("crypt", "alive\n"); + + if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP, + readbuf, lb + sizeof (grub_uint16_t), 0)) + goto fail; + grub_dprintf ("crypt", "alive\n"); + } + + if (pkey) + sk = grub_crypto_pk_locate_subkey (keyid, pkey); + else + sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid); + if (!sk) + { + /* TRANSLATORS: %08x is 32-bit key id. */ + grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"), + keyid); + goto fail; + } + + if (pkalgos[pk].pad (&hmpi, hval, hash, sk)) + goto fail; + if (!*pkalgos[pk].algo) + { + grub_dl_load (pkalgos[pk].module); + grub_errno = GRUB_ERR_NONE; + } + + if (!*pkalgos[pk].algo) + { + grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"), + pkalgos[pk].module); + goto fail; + } + if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0)) + goto fail; + + grub_free (context); + grub_free (readbuf); + + return GRUB_ERR_NONE; + + fail: + grub_free (context); + grub_free (readbuf); + if (!grub_errno) + return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); + return grub_errno; } - - ctxt->hash->final (ctxt->hash_context); - - grub_dprintf ("crypt", "alive\n"); - - hval = ctxt->hash->read (ctxt->hash_context); - - if (grub_file_read (ctxt->sig, hash_start, sizeof (hash_start)) != sizeof (hash_start)) - goto fail; - if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0) - goto fail; - - grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (ctxt->sig)); - - for (i = 0; i < pkalgos[pk].nmpisig; i++) - { - grub_uint16_t l; - grub_size_t lb; - grub_dprintf ("crypt", "alive\n"); - if (grub_file_read (ctxt->sig, &l, sizeof (l)) != sizeof (l)) - goto fail; - grub_dprintf ("crypt", "alive\n"); - lb = (grub_be_to_cpu16 (l) + 7) / 8; - grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l)); - if (lb > READBUF_SIZE - sizeof (grub_uint16_t)) - goto fail; - grub_dprintf ("crypt", "alive\n"); - if (grub_file_read (ctxt->sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb) - goto fail; - grub_dprintf ("crypt", "alive\n"); - grub_memcpy (readbuf, &l, sizeof (l)); - grub_dprintf ("crypt", "alive\n"); - - if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP, - readbuf, lb + sizeof (grub_uint16_t), 0)) - goto fail; - grub_dprintf ("crypt", "alive\n"); - } - - if (pkey) - sk = grub_crypto_pk_locate_subkey (keyid, pkey); - else - sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid); - if (!sk) - { - /* TRANSLATORS: %08x is 32-bit key id. */ - grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"), - keyid); - goto fail; - } - - if (pkalgos[pk].pad (&hmpi, hval, ctxt->hash, sk)) - goto fail; - if (!*pkalgos[pk].algo) - { - grub_dl_load (pkalgos[pk].module); - grub_errno = GRUB_ERR_NONE; - } - - if (!*pkalgos[pk].algo) - { - grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"), - pkalgos[pk].module); - goto fail; - } - if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0)) - goto fail; - - grub_free (readbuf); - - return GRUB_ERR_NONE; - - fail: - grub_free (readbuf); - if (!grub_errno) - return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature")); - return grub_errno; -} - -static void -grub_pubkey_close_real (struct grub_pubkey_context *ctxt) -{ - if (ctxt->sig) - grub_file_close (ctxt->sig); - if (ctxt->hash_context) - grub_free (ctxt->hash_context); -} - -static void -grub_pubkey_close (void *ctxt) -{ - grub_pubkey_close_real (ctxt); - grub_free (ctxt); } grub_err_t -grub_verify_signature (grub_file_t f, const char *fsig, +grub_verify_signature (grub_file_t f, grub_file_t sig, struct grub_public_key *pkey) { - grub_file_t sig; - grub_err_t err; - struct grub_pubkey_context ctxt; - grub_uint8_t *readbuf = NULL; - - sig = grub_file_open (fsig, - GRUB_FILE_TYPE_SIGNATURE - | GRUB_FILE_TYPE_NO_DECOMPRESS); - if (!sig) - return grub_errno; - - err = grub_verify_signature_init (&ctxt, sig); - if (err) - { - grub_file_close (sig); - return err; - } - - readbuf = grub_zalloc (READBUF_SIZE); - if (!readbuf) - goto fail; - - while (1) - { - grub_ssize_t r; - r = grub_file_read (f, readbuf, READBUF_SIZE); - if (r < 0) - goto fail; - if (r == 0) - break; - err = grub_pubkey_write (&ctxt, readbuf, r); - if (err) - return err; - } - - grub_verify_signature_real (&ctxt, pkey); - fail: - grub_pubkey_close_real (&ctxt); - return grub_errno; + return grub_verify_signature_real (0, 0, f, sig, pkey); } static grub_err_t @@ -737,12 +674,10 @@ grub_cmd_trust (grub_extcmd_context_t ctxt, if (argc < 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); - pkf = grub_file_open (args[0], - GRUB_FILE_TYPE_PUBLIC_KEY_TRUST - | GRUB_FILE_TYPE_NO_DECOMPRESS - | (ctxt->state[OPTION_SKIP_SIG].set - ? GRUB_FILE_TYPE_SKIP_SIGNATURE - : GRUB_FILE_TYPE_NONE)); + grub_file_filter_disable_compression (); + if (ctxt->state[OPTION_SKIP_SIG].set) + grub_file_filter_disable_pubkey (); + pkf = grub_file_open (args[0]); if (!pkf) return grub_errno; pk = grub_load_public_key (pkf); @@ -816,7 +751,7 @@ static grub_err_t grub_cmd_verify_signature (grub_extcmd_context_t ctxt, int argc, char **args) { - grub_file_t f = NULL; + grub_file_t f = NULL, sig = NULL; grub_err_t err = GRUB_ERR_NONE; struct grub_public_key *pk = NULL; @@ -830,12 +765,10 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt, if (argc > 2) { grub_file_t pkf; - pkf = grub_file_open (args[2], - GRUB_FILE_TYPE_PUBLIC_KEY - | GRUB_FILE_TYPE_NO_DECOMPRESS - | (ctxt->state[OPTION_SKIP_SIG].set - ? GRUB_FILE_TYPE_SKIP_SIGNATURE - : GRUB_FILE_TYPE_NONE)); + grub_file_filter_disable_compression (); + if (ctxt->state[OPTION_SKIP_SIG].set) + grub_file_filter_disable_pubkey (); + pkf = grub_file_open (args[2]); if (!pkf) return grub_errno; pk = grub_load_public_key (pkf); @@ -847,15 +780,26 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt, grub_file_close (pkf); } - f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE); + grub_file_filter_disable_all (); + f = grub_file_open (args[0]); if (!f) { err = grub_errno; goto fail; } - err = grub_verify_signature (f, args[1], pk); + grub_file_filter_disable_all (); + sig = grub_file_open (args[1]); + if (!sig) + { + err = grub_errno; + goto fail; + } + + err = grub_verify_signature (f, sig, pk); fail: + if (sig) + grub_file_close (sig); if (f) grub_file_close (f); if (pk) @@ -865,53 +809,135 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt, static int sec = 0; +static void +verified_free (grub_verified_t verified) +{ + if (verified) + { + grub_free (verified->buf); + grub_free (verified); + } +} + +static grub_ssize_t +verified_read (struct grub_file *file, char *buf, grub_size_t len) +{ + grub_verified_t verified = file->data; + + grub_memcpy (buf, (char *) verified->buf + file->offset, len); + return len; +} + static grub_err_t -grub_pubkey_init (grub_file_t io, enum grub_file_type type __attribute__ ((unused)), - void **context, enum grub_verify_flags *flags) +verified_close (struct grub_file *file) +{ + grub_verified_t verified = file->data; + + grub_file_close (verified->file); + verified_free (verified); + file->data = 0; + + /* device and name are freed by parent */ + file->device = 0; + file->name = 0; + + return grub_errno; +} + +struct grub_fs verified_fs = +{ + .name = "verified_read", + .read = verified_read, + .close = verified_close +}; + +static grub_file_t +grub_pubkey_open (grub_file_t io, const char *filename) { grub_file_t sig; char *fsuf, *ptr; grub_err_t err; - struct grub_pubkey_context *ctxt; + grub_file_filter_t curfilt[GRUB_FILE_FILTER_MAX]; + grub_file_t ret; + grub_verified_t verified; if (!sec) - { - *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; - return GRUB_ERR_NONE; - } - - fsuf = grub_malloc (grub_strlen (io->name) + sizeof (".sig")); + return io; + if (io->device->disk && + (io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID + || io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID)) + return io; + fsuf = grub_malloc (grub_strlen (filename) + sizeof (".sig")); if (!fsuf) - return grub_errno; - ptr = grub_stpcpy (fsuf, io->name); + return NULL; + ptr = grub_stpcpy (fsuf, filename); grub_memcpy (ptr, ".sig", sizeof (".sig")); - sig = grub_file_open (fsuf, GRUB_FILE_TYPE_SIGNATURE); + grub_memcpy (curfilt, grub_file_filters_enabled, + sizeof (curfilt)); + grub_file_filter_disable_all (); + sig = grub_file_open (fsuf); + grub_memcpy (grub_file_filters_enabled, curfilt, + sizeof (curfilt)); grub_free (fsuf); if (!sig) - return grub_errno; + return NULL; - ctxt = grub_malloc (sizeof (*ctxt)); - if (!ctxt) + ret = grub_malloc (sizeof (*ret)); + if (!ret) { grub_file_close (sig); - return grub_errno; + return NULL; } - err = grub_verify_signature_init (ctxt, sig); + *ret = *io; + + ret->fs = &verified_fs; + ret->not_easily_seekable = 0; + if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1)) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "big file signature isn't implemented yet"); + grub_file_close (sig); + grub_free (ret); + return NULL; + } + verified = grub_malloc (sizeof (*verified)); + if (!verified) + { + grub_file_close (sig); + grub_free (ret); + return NULL; + } + verified->buf = grub_malloc (ret->size); + if (!verified->buf) + { + grub_file_close (sig); + grub_free (verified); + grub_free (ret); + return NULL; + } + if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size) + { + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + filename); + grub_file_close (sig); + verified_free (verified); + grub_free (ret); + return NULL; + } + + err = grub_verify_signature_real (verified->buf, ret->size, 0, sig, NULL); + grub_file_close (sig); if (err) { - grub_free (ctxt); - grub_file_close (sig); - return err; + verified_free (verified); + grub_free (ret); + return NULL; } - *context = ctxt; - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_pubkey_fini (void *ctxt) -{ - return grub_verify_signature_real (ctxt, NULL); + verified->file = io; + ret->data = verified; + return ret; } static char * @@ -934,22 +960,14 @@ pseudo_read (struct grub_file *file, char *buf, grub_size_t len) struct grub_fs pseudo_fs = { .name = "pseudo", - .fs_read = pseudo_read - }; + .read = pseudo_read +}; -struct grub_file_verifier grub_pubkey_verifier = - { - .name = "pgp", - .init = grub_pubkey_init, - .fini = grub_pubkey_fini, - .write = grub_pubkey_write, - .close = grub_pubkey_close, - }; static grub_extcmd_t cmd, cmd_trust; static grub_command_t cmd_distrust, cmd_list; -GRUB_MOD_INIT(pgp) +GRUB_MOD_INIT(verify) { const char *val; struct grub_module_header *header; @@ -959,6 +977,8 @@ GRUB_MOD_INIT(pgp) sec = 1; else sec = 0; + + grub_file_filter_register (GRUB_FILE_FILTER_PUBKEY, grub_pubkey_open); grub_register_variable_hook ("check_signatures", 0, grub_env_write_sec); grub_env_export ("check_signatures"); @@ -1004,13 +1024,11 @@ GRUB_MOD_INIT(pgp) cmd_distrust = grub_register_command ("distrust", grub_cmd_distrust, N_("PUBKEY_ID"), N_("Remove PUBKEY_ID from trusted keys.")); - - grub_verifier_register (&grub_pubkey_verifier); } -GRUB_MOD_FINI(pgp) +GRUB_MOD_FINI(verify) { - grub_verifier_unregister (&grub_pubkey_verifier); + grub_file_filter_unregister (GRUB_FILE_FILTER_PUBKEY); grub_unregister_extcmd (cmd); grub_unregister_extcmd (cmd_trust); grub_unregister_command (cmd_list); diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c index 016a4d818..4be8107d5 100644 --- a/grub-core/commands/videoinfo.c +++ b/grub-core/commands/videoinfo.c @@ -136,7 +136,7 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), ctx.height = ctx.width = ctx.depth = 0; if (argc) { - const char *ptr; + char *ptr; ptr = args[0]; ctx.width = grub_strtoul (ptr, &ptr, 0); if (grub_errno) diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c index cc3290311..2807f806b 100644 --- a/grub-core/commands/wildcard.c +++ b/grub-core/commands/wildcard.c @@ -23,7 +23,6 @@ #include #include #include -#include #include @@ -49,7 +48,6 @@ merge (char **dest, char **ps) int i; int j; char **p; - grub_size_t sz; if (! dest) return ps; @@ -62,12 +60,7 @@ merge (char **dest, char **ps) for (j = 0; ps[j]; j++) ; - if (grub_add (i, j, &sz) || - grub_add (sz, 1, &sz) || - grub_mul (sz, sizeof (char *), &sz)) - return dest; - - p = grub_realloc (dest, sz); + p = grub_realloc (dest, sizeof (char*) * (i + j + 1)); if (! p) { grub_free (dest); @@ -122,15 +115,8 @@ make_regex (const char *start, const char *end, regex_t *regexp) char ch; int i = 0; unsigned len = end - start; - char *buffer; - grub_size_t sz; + char *buffer = grub_malloc (len * 2 + 2 + 1); /* worst case size. */ - /* Worst case size is (len * 2 + 2 + 1). */ - if (grub_mul (len, 2, &sz) || - grub_add (sz, 3, &sz)) - return 1; - - buffer = grub_malloc (sz); if (! buffer) return 1; @@ -240,7 +226,6 @@ match_devices_iter (const char *name, void *data) struct match_devices_ctx *ctx = data; char **t; char *buffer; - grub_size_t sz; /* skip partitions if asked to. */ if (ctx->noparts && grub_strchr (name, ',')) @@ -254,21 +239,13 @@ match_devices_iter (const char *name, void *data) if (regexec (ctx->regexp, buffer, 0, 0, 0)) { grub_dprintf ("expand", "not matched\n"); - fail: grub_free (buffer); return 0; } - if (grub_add (ctx->ndev, 2, &sz) || - grub_mul (sz, sizeof (char *), &sz)) - goto fail; - - t = grub_realloc (ctx->devs, sz); + t = grub_realloc (ctx->devs, sizeof (char*) * (ctx->ndev + 2)); if (! t) - { - grub_free (buffer); - return 1; - } + return 1; ctx->devs = t; ctx->devs[ctx->ndev++] = buffer; @@ -313,14 +290,12 @@ struct match_files_ctx /* Helper for match_files. */ static int -match_files_iter (const char *name, - const struct grub_dirhook_info *info __attribute__((unused)), +match_files_iter (const char *name, const struct grub_dirhook_info *info, void *data) { struct match_files_ctx *ctx = data; char **t; char *buffer; - grub_size_t sz; /* skip . and .. names */ if (grub_strcmp(".", name) == 0 || grub_strcmp("..", name) == 0) @@ -336,14 +311,9 @@ match_files_iter (const char *name, if (! buffer) return 1; - if (grub_add (ctx->nfile, 2, &sz) || - grub_mul (sz, sizeof (char *), &sz)) - goto fail; - - t = grub_realloc (ctx->files, sz); - if (!t) + t = grub_realloc (ctx->files, sizeof (char*) * (ctx->nfile + 2)); + if (! t) { - fail: grub_free (buffer); return 1; } @@ -396,7 +366,7 @@ match_files (const char *prefix, const char *suffix, const char *end, else path = ctx.dir; - if (fs->fs_dir (dev, path, match_files_iter, &ctx)) + if (fs->dir (dev, path, match_files_iter, &ctx)) goto fail; grub_free (ctx.dir); @@ -478,7 +448,7 @@ check_file (const char *dir, const char *basename) else path = dir; - fs->fs_dir (dev, path[0] ? path : "/", check_file_iter, &ctx); + fs->dir (dev, path[0] ? path : "/", check_file_iter, &ctx); if (grub_errno == 0 && basename[0] == 0) ctx.found = 1; diff --git a/grub-core/disk/AFSplitter.c b/grub-core/disk/AFSplitter.c index 249163ff0..7e1bd5748 100644 --- a/grub-core/disk/AFSplitter.c +++ b/grub-core/disk/AFSplitter.c @@ -21,12 +21,9 @@ */ #include -#include #include #include -GRUB_MOD_LICENSE ("GPLv2+"); - gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t blocksize, grub_size_t blocknumbers); @@ -75,13 +72,13 @@ AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t i; grub_uint8_t *bufblock; - if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN || hash->mdlen == 0) - return GPG_ERR_INV_ARG; - bufblock = grub_zalloc (blocksize); if (bufblock == NULL) return GPG_ERR_OUT_OF_MEMORY; + if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN || hash->mdlen == 0) + return GPG_ERR_INV_ARG; + grub_memset (bufblock, 0, blocksize); for (i = 0; i < blocknumbers - 1; i++) { diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 0e6d56c24..89365cd09 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -32,7 +32,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); struct grub_ahci_cmd_head { grub_uint32_t config; - grub_uint32_t transferred; + grub_uint32_t transfered; grub_uint64_t command_table_base; grub_uint32_t unused[4]; }; @@ -82,20 +82,6 @@ enum grub_ahci_hba_port_command GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000, }; -enum grub_ahci_hba_port_int_status - { - GRUB_AHCI_HBA_PORT_IS_IFS = (1UL << 27), - GRUB_AHCI_HBA_PORT_IS_HBDS = (1UL << 28), - GRUB_AHCI_HBA_PORT_IS_HBFS = (1UL << 29), - GRUB_AHCI_HBA_PORT_IS_TFES = (1UL << 30), - }; - -#define GRUB_AHCI_HBA_PORT_IS_FATAL_MASK ( \ - GRUB_AHCI_HBA_PORT_IS_IFS | \ - GRUB_AHCI_HBA_PORT_IS_HBDS | \ - GRUB_AHCI_HBA_PORT_IS_HBFS | \ - GRUB_AHCI_HBA_PORT_IS_TFES) - struct grub_ahci_hba { grub_uint32_t cap; @@ -209,10 +195,10 @@ grub_ahci_pciinit (grub_pci_device_t dev, addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); grub_pci_write_word (addr, grub_pci_read_word (addr) - | GRUB_PCI_COMMAND_MEM_ENABLED | GRUB_PCI_COMMAND_BUS_MASTER); + | GRUB_PCI_COMMAND_MEM_ENABLED); hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK, - sizeof (*hba)); + sizeof (hba)); grub_dprintf ("ahci", "dev: %x:%x.%x\n", dev.bus, dev.device, dev.function); grub_dprintf ("ahci", "tfd[0]: %x\n", @@ -369,7 +355,7 @@ grub_ahci_pciinit (grub_pci_device_t dev, if (adevs[i]) { adevs[i]->hba->ports[adevs[i]->port].sata_error = adevs[i]->hba->ports[adevs[i]->port].sata_error; - grub_dprintf ("ahci", "port: %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); adevs[i]->command_list_chunk = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head) * 32); @@ -454,7 +440,7 @@ grub_ahci_pciinit (grub_pci_device_t dev, adevs[i]->hba->ports[adevs[i]->port].intstatus = ~0; // adevs[i]->hba->ports[adevs[i]->port].fbs = 0; - grub_dprintf ("ahci", "port: %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); adevs[i]->rfis = grub_memalign_dma32 (4096, @@ -494,7 +480,7 @@ grub_ahci_pciinit (grub_pci_device_t dev, for (i = 0; i < nports; i++) if (adevs[i]) { - grub_dprintf ("ahci", "port: %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); fr_running |= (1 << i); @@ -502,7 +488,7 @@ grub_ahci_pciinit (grub_pci_device_t dev, adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_POWER_ON; adevs[i]->hba->ports[adevs[i]->port].command |= 1 << 28; - grub_dprintf ("ahci", "port: %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); } @@ -529,26 +515,26 @@ grub_ahci_pciinit (grub_pci_device_t dev, for (i = 0; i < nports; i++) if (adevs[i]) { - grub_dprintf ("ahci", "port %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_POWER_ON; adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_SPIN_UP; - grub_dprintf ("ahci", "port %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); adevs[i]->hba->ports[adevs[i]->port].sata_error = ~0; - grub_dprintf ("ahci", "port %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); - grub_dprintf ("ahci", "port %d, offset: %x, tfd:%x, CMD: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "offset: %x, tfd:%x, CMD: %x\n", (int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data - (char *) adevs[i]->hba), adevs[i]->hba->ports[adevs[i]->port].task_file_data, adevs[i]->hba->ports[adevs[i]->port].command); - grub_dprintf ("ahci", "port %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); } @@ -556,19 +542,17 @@ grub_ahci_pciinit (grub_pci_device_t dev, for (i = 0; i < nports; i++) if (adevs[i]) { - grub_dprintf ("ahci", "port %d, offset: %x, tfd:%x, CMD: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "offset: %x, tfd:%x, CMD: %x\n", (int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data - (char *) adevs[i]->hba), adevs[i]->hba->ports[adevs[i]->port].task_file_data, adevs[i]->hba->ports[adevs[i]->port].command); - grub_dprintf ("ahci", "port: %d, err: %x\n", adevs[i]->port, + grub_dprintf ("ahci", "err: %x\n", adevs[i]->hba->ports[adevs[i]->port].sata_error); adevs[i]->hba->ports[adevs[i]->port].command - = (adevs[i]->hba->ports[adevs[i]->port].command & 0x0fffffff) | (1 << 28) - | GRUB_AHCI_HBA_PORT_CMD_SPIN_UP - | GRUB_AHCI_HBA_PORT_CMD_POWER_ON; + = (adevs[i]->hba->ports[adevs[i]->port].command & 0x0fffffff) | (1 << 28) | 2 | 4; /* struct grub_disk_ata_pass_through_parms parms2; grub_memset (&parms2, 0, sizeof (parms2)); @@ -576,19 +560,19 @@ grub_ahci_pciinit (grub_pci_device_t dev, grub_ahci_readwrite_real (dev, &parms2, 1, 1);*/ } - endtime = grub_get_time_ms () + 32000; + endtime = grub_get_time_ms () + 10000; while (grub_get_time_ms () < endtime) { for (i = 0; i < nports; i++) - if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & (GRUB_ATA_STATUS_BUSY | GRUB_ATA_STATUS_DRQ))) + if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & 0x88)) break; if (i == nports) break; } for (i = 0; i < nports; i++) - if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & (GRUB_ATA_STATUS_BUSY | GRUB_ATA_STATUS_DRQ))) + if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & 0x88)) { grub_dprintf ("ahci", "port %d is busy\n", i); failed_adevs[i] = adevs[i]; @@ -968,7 +952,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, grub_dprintf ("ahci", "AHCI tfd = %x\n", dev->hba->ports[dev->port].task_file_data); - dev->command_list[0].transferred = 0; + dev->command_list[0].transfered = 0; dev->command_list[0].command_table_base = grub_dma_get_phys (dev->command_table_chunk); @@ -1018,7 +1002,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, if (parms->write) grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size); - grub_dprintf ("ahci", "AHCI command scheduled\n"); + grub_dprintf ("ahci", "AHCI command schedulded\n"); grub_dprintf ("ahci", "AHCI tfd = %x\n", dev->hba->ports[dev->port].task_file_data); grub_dprintf ("ahci", "AHCI inten = %x\n", @@ -1040,8 +1024,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, endtime = grub_get_time_ms () + (spinup ? 20000 : 20000); while ((dev->hba->ports[dev->port].command_issue & 1)) - if (grub_get_time_ms () > endtime || - (dev->hba->ports[dev->port].intstatus & GRUB_AHCI_HBA_PORT_IS_FATAL_MASK)) + if (grub_get_time_ms () > endtime) { grub_dprintf ("ahci", "AHCI status <%x %x %x %x>\n", dev->hba->ports[dev->port].command_issue, @@ -1049,10 +1032,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, dev->hba->ports[dev->port].intstatus, dev->hba->ports[dev->port].task_file_data); dev->hba->ports[dev->port].command_issue = 0; - if (dev->hba->ports[dev->port].intstatus & GRUB_AHCI_HBA_PORT_IS_FATAL_MASK) - err = grub_error (GRUB_ERR_IO, "AHCI transfer error"); - else - err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out"); + err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out"); if (!reset) grub_ahci_reset_port (dev, 1); break; @@ -1062,7 +1042,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev, dev->hba->ports[dev->port].command_issue, dev->hba->ports[dev->port].intstatus, dev->hba->ports[dev->port].task_file_data, - dev->command_list[0].transferred, + dev->command_list[0].transfered, dev->hba->ports[dev->port].sata_error, ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x00], ((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x18]); diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index c94039a3d..0cc1993e5 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -296,11 +296,11 @@ static struct grub_disk_dev grub_arcdisk_dev = { .name = "arcdisk", .id = GRUB_DISK_DEVICE_ARCDISK_ID, - .disk_iterate = grub_arcdisk_iterate, - .disk_open = grub_arcdisk_open, - .disk_close = grub_arcdisk_close, - .disk_read = grub_arcdisk_read, - .disk_write = grub_arcdisk_write, + .iterate = grub_arcdisk_iterate, + .open = grub_arcdisk_open, + .close = grub_arcdisk_close, + .read = grub_arcdisk_read, + .write = grub_arcdisk_write, .next = 0 }; diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 685f33a19..8ba4e5c50 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -510,11 +510,11 @@ static struct grub_disk_dev grub_atadisk_dev = { .name = "ATA", .id = GRUB_DISK_DEVICE_ATA_ID, - .disk_iterate = grub_ata_iterate, - .disk_open = grub_ata_open, - .disk_close = grub_ata_close, - .disk_read = grub_ata_read, - .disk_write = grub_ata_write, + .iterate = grub_ata_iterate, + .open = grub_ata_open, + .close = grub_ata_close, + .read = grub_ata_read, + .write = grub_ata_write, .next = 0 }; diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 13af84dd1..f0e3a900a 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007,2010,2011,2019 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include #include #include -#include #ifdef GRUB_UTIL #include @@ -111,23 +110,20 @@ grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, { grub_uint8_t *inptr, *outptr, *end; grub_uint8_t ivt[GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE]; - grub_size_t blocksize; + if (cipher->cipher->blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) + return GPG_ERR_INV_ARG; if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) - return GPG_ERR_INV_ARG; - if (blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) { - grub_memcpy (ivt, inptr, blocksize); + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - grub_crypto_xor (outptr, outptr, iv, blocksize); - grub_crypto_xor (iv, ivt, outptr, blocksize); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize); } return GPG_ERR_NO_ERROR; } @@ -139,23 +135,20 @@ grub_crypto_pcbc_encrypt (grub_crypto_cipher_handle_t cipher, { grub_uint8_t *inptr, *outptr, *end; grub_uint8_t ivt[GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE]; - grub_size_t blocksize; - if (!cipher->cipher->encrypt) - return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) + if (cipher->cipher->blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) return GPG_ERR_INV_ARG; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) + if (!cipher->cipher->decrypt) + return GPG_ERR_NOT_SUPPORTED; + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; end = (grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) { - grub_memcpy (ivt, inptr, blocksize); - grub_crypto_xor (outptr, outptr, iv, blocksize); + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); cipher->cipher->encrypt (cipher->ctx, outptr, inptr); - grub_crypto_xor (iv, ivt, outptr, blocksize); + grub_crypto_xor (iv, ivt, outptr, cipher->cipher->blocksize); } return GPG_ERR_NO_ERROR; } @@ -282,7 +275,6 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, break; case GRUB_CRYPTODISK_MODE_IV_PLAIN64: iv[1] = grub_cpu_to_le32 (sector >> 32); - /* FALLTHROUGH */ case GRUB_CRYPTODISK_MODE_IV_PLAIN: iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); break; @@ -380,13 +372,11 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, break; case GRUB_CRYPTODISK_MODE_ECB: if (do_encrypt) - err = grub_crypto_ecb_encrypt (dev->cipher, data + i, data + i, - (1U << dev->log_sector_size)); + grub_crypto_ecb_encrypt (dev->cipher, data + i, data + i, + (1U << dev->log_sector_size)); else - err = grub_crypto_ecb_decrypt (dev->cipher, data + i, data + i, - (1U << dev->log_sector_size)); - if (err) - return err; + grub_crypto_ecb_decrypt (dev->cipher, data + i, data + i, + (1U << dev->log_sector_size)); break; default: return GPG_ERR_NOT_IMPLEMENTED; @@ -404,167 +394,6 @@ grub_cryptodisk_decrypt (struct grub_cryptodisk *dev, return grub_cryptodisk_endecrypt (dev, data, len, sector, 0); } -grub_err_t -grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, const char *ciphermode) -{ - const char *cipheriv = NULL; - grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; - grub_crypto_cipher_handle_t essiv_cipher = NULL; - const gcry_md_spec_t *essiv_hash = NULL; - const struct gcry_cipher_spec *ciph; - grub_cryptodisk_mode_t mode; - grub_cryptodisk_mode_iv_t mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN64; - int benbi_log = 0; - grub_err_t ret = GRUB_ERR_NONE; - - ciph = grub_crypto_lookup_cipher_by_name (ciphername); - if (!ciph) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", - ciphername); - goto err; - } - - /* Configure the cipher used for the bulk data. */ - cipher = grub_crypto_cipher_open (ciph); - if (!cipher) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s could not be initialized", - ciphername); - goto err; - } - - /* Configure the cipher mode. */ - if (grub_strcmp (ciphermode, "ecb") == 0) - { - mode = GRUB_CRYPTODISK_MODE_ECB; - mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; - cipheriv = NULL; - } - else if (grub_strcmp (ciphermode, "plain") == 0) - { - mode = GRUB_CRYPTODISK_MODE_CBC; - mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; - cipheriv = NULL; - } - else if (grub_memcmp (ciphermode, "cbc-", sizeof ("cbc-") - 1) == 0) - { - mode = GRUB_CRYPTODISK_MODE_CBC; - cipheriv = ciphermode + sizeof ("cbc-") - 1; - } - else if (grub_memcmp (ciphermode, "pcbc-", sizeof ("pcbc-") - 1) == 0) - { - mode = GRUB_CRYPTODISK_MODE_PCBC; - cipheriv = ciphermode + sizeof ("pcbc-") - 1; - } - else if (grub_memcmp (ciphermode, "xts-", sizeof ("xts-") - 1) == 0) - { - mode = GRUB_CRYPTODISK_MODE_XTS; - cipheriv = ciphermode + sizeof ("xts-") - 1; - secondary_cipher = grub_crypto_cipher_open (ciph); - if (!secondary_cipher) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, - "Secondary cipher %s isn't available", ciphername); - goto err; - } - if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", - cipher->cipher->blocksize); - goto err; - } - if (secondary_cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", - secondary_cipher->cipher->blocksize); - goto err; - } - } - else if (grub_memcmp (ciphermode, "lrw-", sizeof ("lrw-") - 1) == 0) - { - mode = GRUB_CRYPTODISK_MODE_LRW; - cipheriv = ciphermode + sizeof ("lrw-") - 1; - if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d", - cipher->cipher->blocksize); - goto err; - } - } - else - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", - ciphermode); - goto err; - } - - if (cipheriv == NULL) - ; - else if (grub_memcmp (cipheriv, "plain", sizeof ("plain") - 1) == 0) - mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; - else if (grub_memcmp (cipheriv, "plain64", sizeof ("plain64") - 1) == 0) - mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN64; - else if (grub_memcmp (cipheriv, "benbi", sizeof ("benbi") - 1) == 0) - { - if (cipher->cipher->blocksize & (cipher->cipher->blocksize - 1) - || cipher->cipher->blocksize == 0) - grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %d", - cipher->cipher->blocksize); - /* FIXME should we return an error here? */ - for (benbi_log = 0; - (cipher->cipher->blocksize << benbi_log) < GRUB_DISK_SECTOR_SIZE; - benbi_log++); - mode_iv = GRUB_CRYPTODISK_MODE_IV_BENBI; - } - else if (grub_memcmp (cipheriv, "null", sizeof ("null") - 1) == 0) - mode_iv = GRUB_CRYPTODISK_MODE_IV_NULL; - else if (grub_memcmp (cipheriv, "essiv:", sizeof ("essiv:") - 1) == 0) - { - const char *hash_str = cipheriv + 6; - - mode_iv = GRUB_CRYPTODISK_MODE_IV_ESSIV; - - /* Configure the hash and cipher used for ESSIV. */ - essiv_hash = grub_crypto_lookup_md_by_name (hash_str); - if (!essiv_hash) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, - "Couldn't load %s hash", hash_str); - goto err; - } - essiv_cipher = grub_crypto_cipher_open (ciph); - if (!essiv_cipher) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, - "Couldn't load %s cipher", ciphername); - goto err; - } - } - else - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown IV mode: %s", - cipheriv); - goto err; - } - - crypt->cipher = cipher; - crypt->benbi_log = benbi_log; - crypt->mode = mode; - crypt->mode_iv = mode_iv; - crypt->secondary_cipher = secondary_cipher; - crypt->essiv_cipher = essiv_cipher; - crypt->essiv_hash = essiv_hash; - -err: - if (ret) - { - grub_crypto_cipher_close (cipher); - grub_crypto_cipher_close (secondary_cipher); - } - return ret; -} - gcry_err_code_t grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize) { @@ -757,8 +586,9 @@ grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector, size, sector, dev->offset); err = grub_disk_read (dev->source_disk, - grub_disk_from_native_sector (disk, sector + dev->offset), - 0, size << disk->log_sector_size, buf); + (sector << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) + dev->offset, 0, + size << disk->log_sector_size, buf); if (err) { grub_dprintf ("cryptodisk", "grub_disk_read failed with error %d\n", err); @@ -815,10 +645,12 @@ grub_cryptodisk_write (grub_disk_t disk, grub_disk_addr_t sector, } /* Since ->write was called so disk.mod is loaded but be paranoid */ - sector = sector + dev->offset; + if (grub_disk_write_weak) err = grub_disk_write_weak (dev->source_disk, - grub_disk_from_native_sector (disk, sector), + (sector << (disk->log_sector_size + - GRUB_DISK_SECTOR_BITS)) + + dev->offset, 0, size << disk->log_sector_size, tmp); else err = grub_error (GRUB_ERR_BUG, "disk.mod not loaded"); @@ -878,7 +710,6 @@ grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name, newdev->id = last_cryptodisk_id++; newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; - newdev->partition_start = grub_partition_get_start (source->partition); newdev->next = cryptodisk_list; cryptodisk_list = newdev; @@ -901,9 +732,7 @@ grub_cryptodisk_get_by_source_disk (grub_disk_t disk) grub_cryptodisk_t dev; for (dev = cryptodisk_list; dev != NULL; dev = dev->next) if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) - if ((disk->partition && grub_partition_get_start (disk->partition) == dev->partition_start) || - (!disk->partition && dev->partition_start == 0)) - return dev; + return dev; return NULL; } @@ -924,7 +753,6 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, newdev->cheat_fd = GRUB_UTIL_FD_INVALID; newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; - newdev->partition_start = grub_partition_get_start (source->partition); newdev->id = last_cryptodisk_id++; newdev->next = cryptodisk_list; cryptodisk_list = newdev; @@ -1128,43 +956,33 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) grub_disk_t disk; grub_cryptodisk_t dev; char *diskname; - char *disklast = NULL; - grub_size_t len; + char *disklast; search_uuid = NULL; check_boot = state[2].set; diskname = args[0]; - len = grub_strlen (diskname); - if (len && diskname[0] == '(' && diskname[len - 1] == ')') + if (diskname[0] == '(' && *(disklast = &diskname[grub_strlen (diskname) - 1]) == ')') { - disklast = &diskname[len - 1]; *disklast = '\0'; - diskname++; + disk = grub_disk_open (diskname + 1); + *disklast = ')'; } - - disk = grub_disk_open (diskname); + else + disk = grub_disk_open (diskname); if (!disk) - { - if (disklast) - *disklast = ')'; - return grub_errno; - } + return grub_errno; dev = grub_cryptodisk_get_by_source_disk (disk); if (dev) { grub_dprintf ("cryptodisk", "already mounted as crypto%lu\n", dev->id); grub_disk_close (disk); - if (disklast) - *disklast = ')'; return GRUB_ERR_NONE; } - err = grub_cryptodisk_scan_device_real (diskname, disk); + err = grub_cryptodisk_scan_device_real (args[0], disk); grub_disk_close (disk); - if (disklast) - *disklast = ')'; return err; } @@ -1173,13 +991,13 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) static struct grub_disk_dev grub_cryptodisk_dev = { .name = "cryptodisk", .id = GRUB_DISK_DEVICE_CRYPTODISK_ID, - .disk_iterate = grub_cryptodisk_iterate, - .disk_open = grub_cryptodisk_open, - .disk_close = grub_cryptodisk_close, - .disk_read = grub_cryptodisk_read, - .disk_write = grub_cryptodisk_write, + .iterate = grub_cryptodisk_iterate, + .open = grub_cryptodisk_open, + .close = grub_cryptodisk_close, + .read = grub_cryptodisk_read, + .write = grub_cryptodisk_write, #ifdef GRUB_UTIL - .disk_memberlist = grub_cryptodisk_memberlist, + .memberlist = grub_cryptodisk_memberlist, #endif .next = 0 }; @@ -1308,6 +1126,5 @@ GRUB_MOD_FINI (cryptodisk) { grub_disk_dev_unregister (&grub_cryptodisk_dev); cryptodisk_cleanup (); - grub_unregister_extcmd (cmd); grub_procfs_unregister (&luks_script); } diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 86557f923..97ca54666 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -71,12 +71,10 @@ is_lv_readable (struct grub_diskfilter_lv *lv, int easily) case GRUB_DISKFILTER_RAID6: if (!easily) need--; - /* Fallthrough. */ case GRUB_DISKFILTER_RAID4: case GRUB_DISKFILTER_RAID5: if (!easily) need--; - /* Fallthrough. */ case GRUB_DISKFILTER_STRIPED: break; @@ -228,9 +226,9 @@ scan_devices (const char *arname) for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) for (p = grub_disk_dev_list; p; p = p->next) if (p->id != GRUB_DISK_DEVICE_DISKFILTER_ID - && p->disk_iterate) + && p->iterate) { - if ((p->disk_iterate) (scan_disk_hook, NULL, pull)) + if ((p->iterate) (scan_disk_hook, NULL, pull)) return; if (arname && is_lv_readable (find_lv (arname), 1)) return; @@ -311,9 +309,9 @@ grub_diskfilter_memberlist (grub_disk_t disk) for (pull = 0; pv && pull < GRUB_DISK_PULL_MAX; pull++) for (p = grub_disk_dev_list; pv && p; p = p->next) if (p->id != GRUB_DISK_DEVICE_DISKFILTER_ID - && p->disk_iterate) + && p->iterate) { - (p->disk_iterate) (scan_disk_hook, NULL, pull); + (p->iterate) (scan_disk_hook, NULL, pull); while (pv && pv->disk) pv = pv->next; } @@ -496,13 +494,13 @@ validate_lv (struct grub_diskfilter_lv *lv) if (!lv) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown volume"); - if (!lv->vg || lv->vg->extent_size == 0) + if (lv->vg->extent_size == 0) return grub_error (GRUB_ERR_READ_ERROR, "invalid volume"); for (i = 0; i < lv->segment_count; i++) { grub_err_t err; - err = validate_segment (&lv->segments[i]); + err = validate_segment (&lv->segments[1]); if (err) return err; } @@ -586,7 +584,6 @@ read_segment (struct grub_diskfilter_segment *seg, grub_disk_addr_t sector, if (seg->node_count == 1) return grub_diskfilter_read_node (&seg->nodes[0], sector, size, buf); - /* Fallthrough. */ case GRUB_DISKFILTER_MIRROR: case GRUB_DISKFILTER_RAID10: { @@ -941,10 +938,8 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) for (lv = vg->lvs; lv; lv = lv->next) { - grub_err_t err; - - /* RAID 1 and single-disk RAID 0 don't use a chunksize but code - assumes one so set one. */ + /* RAID 1 and single-disk RAID 0 don't use a chunksize but code assumes one so set + one. */ for (i = 0; i < lv->segment_count; i++) { if (lv->segments[i].type == 1) @@ -954,6 +949,17 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) && lv->segments[i].stripe_size == 0) lv->segments[i].stripe_size = 64; } + } + + for (lv = vg->lvs; lv; lv = lv->next) + { + grub_err_t err; + + /* RAID 1 doesn't use a chunksize but code assumes one so set + one. */ + for (i = 0; i < lv->segment_count; i++) + if (lv->segments[i].type == 1) + lv->segments[i].stripe_size = 64; err = validate_lv(lv); if (err) @@ -969,8 +975,7 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) for (p = vgp->lvs; p; p = p->next) { int cur_num; - char *num; - const char *end; + char *num, *end; if (!p->fullname) continue; if (grub_strncmp (p->fullname, lv->fullname, len) != 0) @@ -999,6 +1004,7 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) lv->fullname = tmp; } } + lv->vg = vg; } /* Add our new array to the list. */ vg->next = array_list; @@ -1008,7 +1014,7 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) struct grub_diskfilter_vg * grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, - const char *name, grub_uint64_t disk_size, + char *name, grub_uint64_t disk_size, grub_uint64_t stripe_size, int layout, int level) { @@ -1032,10 +1038,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, if (n == 1) n = (layout >> 8) & 0xFF; if (n == 0) - { - grub_free (uuid); - return NULL; - } + return NULL; totsize = grub_divmod64 (nmemb * disk_size, n, 0); } @@ -1049,7 +1052,6 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, break; default: - grub_free (uuid); return NULL; } @@ -1063,7 +1065,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, array->lvs->segments->extent_count = totsize; } - if (array->lvs && array->lvs->segments + if (array->lvs->segments && array->lvs->segments->raid_member_size > disk_size) array->lvs->segments->raid_member_size = disk_size; @@ -1072,10 +1074,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, } array = grub_zalloc (sizeof (*array)); if (!array) - { - grub_free (uuid); - return NULL; - } + return NULL; array->uuid = uuid; array->uuid_len = uuidlen; if (name) @@ -1097,16 +1096,8 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, goto fail; array->lvs->segment_count = 1; array->lvs->visible = 1; - if (array->name) - { - array->lvs->name = grub_strdup (array->name); - if (!array->lvs->name) - goto fail; - array->lvs->fullname = grub_strdup (array->name); - if (!array->lvs->fullname) - goto fail; - } - array->lvs->vg = array; + array->lvs->name = array->name; + array->lvs->fullname = array->name; array->lvs->idname = grub_malloc (sizeof ("mduuid/") + 2 * uuidlen); if (!array->lvs->idname) @@ -1135,7 +1126,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, array->lvs->segments->node_count = nmemb; array->lvs->segments->raid_member_size = disk_size; array->lvs->segments->nodes - = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); + = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); array->lvs->segments->stripe_size = stripe_size; for (i = 0; i < nmemb; i++) { @@ -1156,26 +1147,13 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, return array; fail: - if (array->lvs) - { - grub_free (array->lvs->name); - grub_free (array->lvs->fullname); - grub_free (array->lvs->idname); - if (array->lvs->segments) - { - grub_free (array->lvs->segments->nodes); - grub_free (array->lvs->segments); - } - grub_free (array->lvs); - } + grub_free (array->lvs); while (array->pvs) { pv = array->pvs->next; grub_free (array->pvs); array->pvs = pv; } - grub_free (array->name); - grub_free (array->uuid); grub_free (array); return NULL; } @@ -1227,7 +1205,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, grub_partition_t p; for (p = disk->partition; p; p = p->parent) s++; - pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); + pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); s = 0; for (p = disk->partition; p; p = p->parent) pv->partmaps[s++] = xstrdup (p->partmap->name); @@ -1278,9 +1256,10 @@ free_array (void) { unsigned i; vg->lvs = lv->next; - grub_free (lv->fullname); - grub_free (lv->name); - grub_free (lv->idname); + if (lv->name != lv->fullname) + grub_free (lv->fullname); + if (lv->name != vg->name) + grub_free (lv->name); for (i = 0; i < lv->segment_count; i++) grub_free (lv->segments[i].nodes); grub_free (lv->segments); @@ -1326,14 +1305,14 @@ static struct grub_disk_dev grub_diskfilter_dev = { .name = "diskfilter", .id = GRUB_DISK_DEVICE_DISKFILTER_ID, - .disk_iterate = grub_diskfilter_iterate, - .disk_open = grub_diskfilter_open, - .disk_close = grub_diskfilter_close, - .disk_read = grub_diskfilter_read, - .disk_write = grub_diskfilter_write, + .iterate = grub_diskfilter_iterate, + .open = grub_diskfilter_open, + .close = grub_diskfilter_close, + .read = grub_diskfilter_read, + .write = grub_diskfilter_write, #ifdef GRUB_UTIL - .disk_memberlist = grub_diskfilter_memberlist, - .disk_raidname = grub_diskfilter_getname, + .memberlist = grub_diskfilter_memberlist, + .raidname = grub_diskfilter_getname, #endif .next = 0 }; diff --git a/grub-core/disk/dmraid_nvidia.c b/grub-core/disk/dmraid_nvidia.c index 060279124..fc02f5715 100644 --- a/grub-core/disk/dmraid_nvidia.c +++ b/grub-core/disk/dmraid_nvidia.c @@ -99,8 +99,6 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_nv_super sb; int level; grub_uint64_t disk_size; - grub_uint32_t capacity; - grub_uint8_t total_volumes; char *uuid; if (disk->partition) @@ -126,17 +124,14 @@ grub_dmraid_nv_detect (grub_disk_t disk, return NULL; } - capacity = grub_le_to_cpu32 (sb.capacity); - total_volumes = sb.array.total_volumes; - switch (sb.array.raid_level) { case NV_LEVEL_0: level = 0; - if (total_volumes == 0) + disk_size = sb.capacity / sb.array.total_volumes; + if (sb.array.total_volumes == 0) /* Not RAID. */ return NULL; - disk_size = capacity / total_volumes; break; case NV_LEVEL_1: @@ -146,10 +141,10 @@ grub_dmraid_nv_detect (grub_disk_t disk, case NV_LEVEL_5: level = 5; - if (total_volumes == 0 || total_volumes == 1) + disk_size = sb.capacity / (sb.array.total_volumes - 1); + if (sb.array.total_volumes == 0 || sb.array.total_volumes == 1) /* Not RAID. */ return NULL; - disk_size = capacity / (total_volumes - 1); break; default: @@ -172,7 +167,7 @@ grub_dmraid_nv_detect (grub_disk_t disk, return grub_diskfilter_make_raid (sizeof (sb.array.signature), uuid, sb.array.total_volumes, - "nv", disk_size, + NULL, disk_size, sb.array.stripe_block_size, GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC, level); diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 9e20af70e..3b12c3499 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -43,6 +43,47 @@ static struct grub_efidisk_data *fd_devices; static struct grub_efidisk_data *hd_devices; static struct grub_efidisk_data *cd_devices; +/* Duplicate a device path. */ +static grub_efi_device_path_t * +duplicate_device_path (const grub_efi_device_path_t *dp) +{ + grub_efi_device_path_t *p; + grub_size_t total_size = 0; + + for (p = (grub_efi_device_path_t *) dp; + ; + p = GRUB_EFI_NEXT_DEVICE_PATH (p)) + { + total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p); + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p)) + break; + } + + p = grub_malloc (total_size); + if (! p) + return 0; + + grub_memcpy (p, dp, total_size); + return p; +} + +/* Return the device path node right before the end node. */ +static grub_efi_device_path_t * +find_last_device_path (const grub_efi_device_path_t *dp) +{ + grub_efi_device_path_t *next, *p; + + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) + return 0; + + for (p = (grub_efi_device_path_t *) dp, next = GRUB_EFI_NEXT_DEVICE_PATH (p); + ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (next); + p = next, next = GRUB_EFI_NEXT_DEVICE_PATH (next)) + ; + + return p; +} + static struct grub_efidisk_data * make_devices (void) { @@ -69,7 +110,7 @@ make_devices (void) if (! dp) continue; - ldp = grub_efi_find_last_device_path (dp); + ldp = find_last_device_path (dp); if (! ldp) /* This is empty. Why? */ continue; @@ -80,26 +121,11 @@ make_devices (void) /* This should not happen... Why? */ continue; - /* iPXE adds stub Block IO protocol to loaded image device handle. It is - completely non-functional and simply returns an error for every method. - So attempt to detect and skip it. Magic number is literal "iPXE" and - check block size as well */ - /* FIXME: shoud we close it? We do not do it elsewhere */ - if (bio->media && bio->media->media_id == 0x69505845U && - bio->media->block_size == 1) - continue; - d = grub_malloc (sizeof (*d)); if (! d) { /* Uggh. */ grub_free (handles); - while (devices) - { - d = devices->next; - grub_free (devices); - devices = d; - } return 0; } @@ -124,14 +150,11 @@ find_parent_device (struct grub_efidisk_data *devices, grub_efi_device_path_t *dp, *ldp; struct grub_efidisk_data *parent; - dp = grub_efi_duplicate_device_path (d->device_path); + dp = duplicate_device_path (d->device_path); if (! dp) return 0; - ldp = grub_efi_find_last_device_path (dp); - if (! ldp) - return 0; - + ldp = find_last_device_path (dp); ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ldp->length = sizeof (*ldp); @@ -157,14 +180,11 @@ is_child (struct grub_efidisk_data *child, grub_efi_device_path_t *dp, *ldp; int ret; - dp = grub_efi_duplicate_device_path (child->device_path); + dp = duplicate_device_path (child->device_path); if (! dp) return 0; - ldp = grub_efi_find_last_device_path (dp); - if (! ldp) - return 0; - + ldp = find_last_device_path (dp); ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ldp->length = sizeof (*ldp); @@ -187,8 +207,8 @@ add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d) { int ret; - ret = grub_efi_compare_device_paths (grub_efi_find_last_device_path ((*p)->device_path), - grub_efi_find_last_device_path (d->device_path)); + ret = grub_efi_compare_device_paths (find_last_device_path ((*p)->device_path), + find_last_device_path (d->device_path)); if (ret == 0) ret = grub_efi_compare_device_paths ((*p)->device_path, d->device_path); @@ -230,7 +250,7 @@ name_devices (struct grub_efidisk_data *devices) { case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE: is_hard_drive = 1; - /* Intentionally fall through. */ + /* Fall through by intention. */ case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE: { struct grub_efidisk_data *parent, *parent2; @@ -508,15 +528,8 @@ grub_efidisk_open (const char *name, struct grub_disk *disk) m = d->block_io->media; /* FIXME: Probably it is better to store the block size in the disk, and total sectors should be replaced with total blocks. */ - grub_dprintf ("efidisk", - "m = %p, last block = %llx, block size = %x, io align = %x\n", - m, (unsigned long long) m->last_block, m->block_size, - m->io_align); - - /* Ensure required buffer alignment is a power of two (or is zero). */ - if (m->io_align & (m->io_align - 1)) - return grub_error (GRUB_ERR_IO, "invalid buffer alignment %d", m->io_align); - + grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", + m, (unsigned long long) m->last_block, m->block_size); disk->total_sectors = m->last_block + 1; /* Don't increase this value due to bug in some EFI. */ disk->max_agglomerate = 0xa0000 >> (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS); @@ -546,42 +559,15 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector, { struct grub_efidisk_data *d; grub_efi_block_io_t *bio; - grub_efi_status_t status; - grub_size_t io_align, num_bytes; - char *aligned_buf; d = disk->data; bio = d->block_io; - /* Set alignment to 1 if 0 specified */ - io_align = bio->media->io_align ? bio->media->io_align : 1; - num_bytes = size << disk->log_sector_size; - - if ((grub_addr_t) buf & (io_align - 1)) - { - aligned_buf = grub_memalign (io_align, num_bytes); - if (! aligned_buf) - return GRUB_EFI_OUT_OF_RESOURCES; - if (wr) - grub_memcpy (aligned_buf, buf, num_bytes); - } - else - { - aligned_buf = buf; - } - - status = efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio, - bio->media->media_id, (grub_efi_uint64_t) sector, - (grub_efi_uintn_t) num_bytes, aligned_buf); - - if ((grub_addr_t) buf & (io_align - 1)) - { - if (!wr) - grub_memcpy (buf, aligned_buf, num_bytes); - grub_free (aligned_buf); - } - - return status; + return efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio, + bio->media->media_id, + (grub_efi_uint64_t) sector, + (grub_efi_uintn_t) size << disk->log_sector_size, + buf); } static grub_err_t @@ -596,9 +582,7 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector, status = grub_efidisk_readwrite (disk, sector, size, buf, 0); - if (status == GRUB_EFI_NO_MEDIA) - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name); - else if (status != GRUB_EFI_SUCCESS) + if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx from `%s'"), (unsigned long long) sector, @@ -619,9 +603,7 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector, status = grub_efidisk_readwrite (disk, sector, size, (char *) buf, 1); - if (status == GRUB_EFI_NO_MEDIA) - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'"), disk->name); - else if (status != GRUB_EFI_SUCCESS) + if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_WRITE_ERROR, N_("failure writing sector 0x%llx to `%s'"), (unsigned long long) sector, disk->name); @@ -633,11 +615,11 @@ static struct grub_disk_dev grub_efidisk_dev = { .name = "efidisk", .id = GRUB_DISK_DEVICE_EFIDISK_ID, - .disk_iterate = grub_efidisk_iterate, - .disk_open = grub_efidisk_open, - .disk_close = grub_efidisk_close, - .disk_read = grub_efidisk_read, - .disk_write = grub_efidisk_write, + .iterate = grub_efidisk_iterate, + .open = grub_efidisk_open, + .close = grub_efidisk_close, + .read = grub_efidisk_read, + .write = grub_efidisk_write, .next = 0 }; @@ -813,7 +795,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) if (! dp) return 0; - ldp = grub_efi_find_last_device_path (dp); + ldp = find_last_device_path (dp); if (! ldp) return 0; @@ -821,6 +803,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE || GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)) { + int is_cdrom = 0; struct grub_efidisk_get_device_name_ctx ctx; char *dev_name; grub_efi_device_path_t *dup_dp; @@ -828,22 +811,22 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) /* It is necessary to duplicate the device path so that GRUB can overwrite it. */ - dup_dp = grub_efi_duplicate_device_path (dp); + dup_dp = duplicate_device_path (dp); if (! dup_dp) return 0; while (1) { grub_efi_device_path_t *dup_ldp; - dup_ldp = grub_efi_find_last_device_path (dup_dp); - if (! dup_ldp) - break; - + dup_ldp = find_last_device_path (dup_dp); if (!(GRUB_EFI_DEVICE_PATH_TYPE (dup_ldp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE || GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE))) break; + if (GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE) + is_cdrom = 1; + dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; dup_ldp->length = sizeof (*dup_ldp); @@ -878,13 +861,10 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) if (! ctx.partition_name) { - /* No partition found. In most cases partition is embed in - the root path anyway, so this is not critical. - This happens only if partition is on partmap that GRUB - doesn't need to access root. - */ grub_disk_close (parent); - return grub_strdup (device_name); + if (is_cdrom) + return grub_strdup (device_name); + return 0; } dev_name = grub_xasprintf ("%s,%s", parent->name, diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index e9d23299a..4ed07bb91 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -212,8 +212,7 @@ grub_util_get_geli_uuid (const char *dev) s = grub_util_get_fd_size (fd, dev, &log_secsize); s >>= log_secsize; - if (grub_util_fd_seek (fd, (s << log_secsize) - 512) < 0) - grub_util_error ("%s", _("couldn't read ELI metadata")); + grub_util_fd_seek (fd, (s << log_secsize) - 512); uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1); if (grub_util_fd_read (fd, (void *) &hdr, 512) < 0) @@ -232,10 +231,7 @@ grub_util_get_geli_uuid (const char *dev) err = make_uuid ((void *) &hdr, uuid); if (err) - { - grub_free (uuid); - return NULL; - } + return NULL; return uuid; } diff --git a/grub-core/disk/host.c b/grub-core/disk/host.c index c151d225d..76ef1afb8 100644 --- a/grub-core/disk/host.c +++ b/grub-core/disk/host.c @@ -84,11 +84,11 @@ static struct grub_disk_dev grub_host_dev = /* The only important line in this file :-) */ .name = "host", .id = GRUB_DISK_DEVICE_HOST_ID, - .disk_iterate = grub_host_iterate, - .disk_open = grub_host_open, - .disk_close = grub_host_close, - .disk_read = grub_host_read, - .disk_write = grub_host_write, + .iterate = grub_host_iterate, + .open = grub_host_open, + .close = grub_host_close, + .read = grub_host_read, + .write = grub_host_write, .next = 0 }; diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 8ca250c77..26a4973ad 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -382,8 +382,7 @@ grub_biosdisk_open (const char *name, grub_disk_t disk) /* Some buggy BIOSes doesn't return the total sectors correctly but returns zero. So if it is zero, compute it by C/H/S returned by the LBA BIOS call. */ - total_sectors = ((grub_uint64_t) drp->cylinders) - * drp->heads * drp->sectors; + total_sectors = drp->cylinders * drp->heads * drp->sectors; if (drp->bytes_per_sector && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1)) && drp->bytes_per_sector >= 512 @@ -426,8 +425,7 @@ grub_biosdisk_open (const char *name, grub_disk_t disk) data->heads = 255; if (! total_sectors) - total_sectors = ((grub_uint64_t) data->cylinders) - * data->heads * data->sectors; + total_sectors = data->cylinders * data->heads * data->sectors; } disk->total_sectors = total_sectors; @@ -637,11 +635,11 @@ static struct grub_disk_dev grub_biosdisk_dev = { .name = "biosdisk", .id = GRUB_DISK_DEVICE_BIOSDISK_ID, - .disk_iterate = grub_biosdisk_iterate, - .disk_open = grub_biosdisk_open, - .disk_close = grub_biosdisk_close, - .disk_read = grub_biosdisk_read, - .disk_write = grub_biosdisk_write, + .iterate = grub_biosdisk_iterate, + .open = grub_biosdisk_open, + .close = grub_biosdisk_close, + .read = grub_biosdisk_read, + .write = grub_biosdisk_write, .next = 0 }; diff --git a/grub-core/disk/ieee1275/nand.c b/grub-core/disk/ieee1275/nand.c index bcf3a06f4..feffa8c4c 100644 --- a/grub-core/disk/ieee1275/nand.c +++ b/grub-core/disk/ieee1275/nand.c @@ -223,11 +223,11 @@ static struct grub_disk_dev grub_nand_dev = { .name = "nand", .id = GRUB_DISK_DEVICE_NAND_ID, - .disk_iterate = grub_nand_iterate, - .disk_open = grub_nand_open, - .disk_close = grub_nand_close, - .disk_read = grub_nand_read, - .disk_write = grub_nand_write, + .iterate = grub_nand_iterate, + .open = grub_nand_open, + .close = grub_nand_close, + .read = grub_nand_read, + .write = grub_nand_write, .next = 0 }; diff --git a/grub-core/disk/ieee1275/obdisk.c b/grub-core/disk/ieee1275/obdisk.c deleted file mode 100644 index ec413c3fd..000000000 --- a/grub-core/disk/ieee1275/obdisk.c +++ /dev/null @@ -1,1076 +0,0 @@ -/* obdisk.c - Open Boot disk access. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define IEEE1275_DEV "ieee1275/" -#define IEEE1275_DISK_ALIAS "/disk@" - -struct disk_dev -{ - struct disk_dev *next; - struct disk_dev **prev; - char *name; - char *raw_name; - char *grub_devpath; - char *grub_alias_devpath; - grub_ieee1275_ihandle_t ihandle; - grub_uint32_t block_size; - grub_uint64_t num_blocks; - unsigned int log_sector_size; - grub_uint32_t opened; - grub_uint32_t valid; - grub_uint32_t boot_dev; -}; - -struct parent_dev -{ - struct parent_dev *next; - struct parent_dev **prev; - char *name; - char *type; - grub_ieee1275_ihandle_t ihandle; - grub_uint32_t address_cells; -}; - -static struct grub_scsi_test_unit_ready tur = -{ - .opcode = grub_scsi_cmd_test_unit_ready, - .lun = 0, - .reserved1 = 0, - .reserved2 = 0, - .reserved3 = 0, - .control = 0, -}; - -static int disks_enumerated; -static struct disk_dev *disk_devs; -static struct parent_dev *parent_devs; - -static const char *block_blacklist[] = { - /* Requires additional work in grub before being able to be used. */ - "/iscsi-hba", - /* This block device should never be used by grub. */ - "/reboot-memory@0", - 0 -}; - -#define STRCMP(a, b) ((a) && (b) && (grub_strcmp (a, b) == 0)) - -static char * -strip_ob_partition (char *path) -{ - char *sptr; - - sptr = grub_strstr (path, ":"); - - if (sptr != NULL) - *sptr = '\0'; - - return path; -} - -static void -escape_commas (const char *src, char *dest) -{ - const char *iptr; - - for (iptr = src; *iptr; ) - { - if (*iptr == ',') - *dest++ ='\\'; - - *dest++ = *iptr++; - } - - *dest = '\0'; -} - -static int -count_commas (const char *src) -{ - int count = 0; - - for ( ; *src; src++) - if (*src == ',') - count++; - - return count; -} - - -static char * -decode_grub_devname (const char *name) -{ - char *devpath = grub_malloc (grub_strlen (name) + 1); - char *p, c; - - if (devpath == NULL) - return NULL; - - /* Un-escape commas. */ - p = devpath; - while ((c = *name++) != '\0') - { - if (c == '\\' && *name == ',') - { - *p++ = ','; - name++; - } - else - *p++ = c; - } - - *p++ = '\0'; - - return devpath; -} - -static char * -encode_grub_devname (const char *path) -{ - char *encoding, *optr; - - if (path == NULL) - return NULL; - - encoding = grub_malloc (sizeof (IEEE1275_DEV) + count_commas (path) + - grub_strlen (path) + 1); - - if (encoding == NULL) - { - grub_print_error (); - return NULL; - } - - optr = grub_stpcpy (encoding, IEEE1275_DEV); - escape_commas (path, optr); - return encoding; -} - -static char * -get_parent_devname (const char *devname) -{ - char *parent, *pptr; - - parent = grub_strdup (devname); - - if (parent == NULL) - { - grub_print_error (); - return NULL; - } - - pptr = grub_strstr (parent, IEEE1275_DISK_ALIAS); - - if (pptr != NULL) - *pptr = '\0'; - - return parent; -} - -static void -free_parent_dev (struct parent_dev *parent) -{ - if (parent != NULL) - { - grub_free (parent->name); - grub_free (parent->type); - grub_free (parent); - } -} - -static struct parent_dev * -init_parent (const char *parent) -{ - struct parent_dev *op; - - op = grub_zalloc (sizeof (struct parent_dev)); - - if (op == NULL) - { - grub_print_error (); - return NULL; - } - - op->name = grub_strdup (parent); - op->type = grub_malloc (IEEE1275_MAX_PROP_LEN); - - if ((op->name == NULL) || (op->type == NULL)) - { - grub_print_error (); - free_parent_dev (op); - return NULL; - } - - return op; -} - -static struct parent_dev * -open_new_parent (const char *parent) -{ - struct parent_dev *op = init_parent(parent); - grub_ieee1275_ihandle_t ihandle; - grub_ieee1275_phandle_t phandle; - grub_uint32_t address_cells = 2; - - if (op == NULL) - return NULL; - - grub_ieee1275_open (parent, &ihandle); - - if (ihandle == 0) - { - grub_error (GRUB_ERR_BAD_DEVICE, "unable to open %s", parent); - grub_print_error (); - free_parent_dev (op); - return NULL; - } - - if (grub_ieee1275_instance_to_package (ihandle, &phandle)) - { - grub_error (GRUB_ERR_BAD_DEVICE, "unable to get parent %s", parent); - grub_print_error (); - free_parent_dev (op); - return NULL; - } - - /* - * IEEE Std 1275-1994 page 110: A missing "address-cells" property - * signifies that the number of address cells is two. So ignore on error. - */ - if (grub_ieee1275_get_integer_property (phandle, "#address-cells", - &address_cells, - sizeof (address_cells), 0) != 0) - address_cells = 2; - - grub_ieee1275_get_property (phandle, "device_type", op->type, - IEEE1275_MAX_PROP_LEN, NULL); - - op->ihandle = ihandle; - op->address_cells = address_cells; - return op; -} - -static struct parent_dev * -open_parent (const char *parent) -{ - struct parent_dev *op; - - op = grub_named_list_find (GRUB_AS_NAMED_LIST (parent_devs), parent); - - if (op == NULL) - { - op = open_new_parent (parent); - - if (op != NULL) - grub_list_push (GRUB_AS_LIST_P (&parent_devs), GRUB_AS_LIST (op)); - } - - return op; -} - -static void -display_parents (void) -{ - struct parent_dev *parent; - - grub_printf ("-------------------- PARENTS --------------------\n"); - - FOR_LIST_ELEMENTS (parent, parent_devs) - { - grub_printf ("name: %s\n", parent->name); - grub_printf ("type: %s\n", parent->type); - grub_printf ("address_cells %x\n", parent->address_cells); - } - - grub_printf ("-------------------------------------------------\n"); -} - -static char * -canonicalise_4cell_ua (grub_ieee1275_ihandle_t ihandle, char *unit_address) -{ - grub_uint32_t phy_lo, phy_hi, lun_lo, lun_hi; - int valid_phy = 0; - grub_size_t size; - char *canon = NULL; - - valid_phy = grub_ieee1275_decode_unit4 (ihandle, unit_address, - grub_strlen (unit_address), &phy_lo, - &phy_hi, &lun_lo, &lun_hi); - - if ((valid_phy == 0) && (phy_hi != 0xffffffff)) - canon = grub_ieee1275_encode_uint4 (ihandle, phy_lo, phy_hi, - lun_lo, lun_hi, &size); - - return canon; -} - -static char * -canonicalise_disk (const char *devname) -{ - char *canon, *parent; - struct parent_dev *op; - - canon = grub_ieee1275_canonicalise_devname (devname); - - if (canon == NULL) - { - /* This should not happen. */ - grub_error (GRUB_ERR_BAD_DEVICE, "canonicalise devname failed"); - grub_print_error (); - return NULL; - } - - /* Don't try to open the parent of a virtual device. */ - if (grub_strstr (canon, "virtual-devices")) - return canon; - - parent = get_parent_devname (canon); - - if (parent == NULL) - return NULL; - - op = open_parent (parent); - - /* - * Devices with 4 address cells can have many different types of addressing - * (phy, wwn, and target lun). Use the parents encode-unit / decode-unit - * to find the true canonical name. - */ - if ((op) && (op->address_cells == 4)) - { - char *unit_address, *real_unit_address, *real_canon; - grub_size_t real_unit_str_len; - - unit_address = grub_strstr (canon, IEEE1275_DISK_ALIAS); - unit_address += grub_strlen (IEEE1275_DISK_ALIAS); - - if (unit_address == NULL) - { - /* - * This should not be possible, but return the canonical name for - * the non-disk block device. - */ - grub_free (parent); - return (canon); - } - - real_unit_address = canonicalise_4cell_ua (op->ihandle, unit_address); - - if (real_unit_address == NULL) - { - /* - * This is not an error, since this function could be called with a devalias - * containing a drive that isn't installed in the system. - */ - grub_free (parent); - return NULL; - } - - real_unit_str_len = grub_strlen (op->name) + sizeof (IEEE1275_DISK_ALIAS) - + grub_strlen (real_unit_address); - - real_canon = grub_malloc (real_unit_str_len); - - grub_snprintf (real_canon, real_unit_str_len, "%s/disk@%s", - op->name, real_unit_address); - - grub_free (canon); - canon = real_canon; - } - - grub_free (parent); - return (canon); -} - -static struct disk_dev * -add_canon_disk (const char *cname) -{ - struct disk_dev *dev; - - dev = grub_zalloc (sizeof (struct disk_dev)); - - if (dev == NULL) - goto failed; - - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_RAW_DEVNAMES)) - { - /* - * Append :nolabel to the end of all SPARC disks. - * nolabel is mutually exclusive with all other - * arguments and allows a client program to open - * the entire (raw) disk. Any disk label is ignored. - */ - dev->raw_name = grub_malloc (grub_strlen (cname) + sizeof (":nolabel")); - - if (dev->raw_name == NULL) - goto failed; - - grub_snprintf (dev->raw_name, grub_strlen (cname) + sizeof (":nolabel"), - "%s:nolabel", cname); - } - - /* - * Don't use grub_ieee1275_encode_devname here, the devpath in grub.cfg doesn't - * understand device aliases, which the layer above sometimes sends us. - */ - dev->grub_devpath = encode_grub_devname(cname); - - if (dev->grub_devpath == NULL) - goto failed; - - dev->name = grub_strdup (cname); - - if (dev->name == NULL) - goto failed; - - dev->valid = 1; - grub_list_push (GRUB_AS_LIST_P (&disk_devs), GRUB_AS_LIST (dev)); - return dev; - - failed: - grub_print_error (); - - if (dev != NULL) - { - grub_free (dev->name); - grub_free (dev->grub_devpath); - grub_free (dev->raw_name); - } - - grub_free (dev); - return NULL; -} - -static grub_err_t -add_disk (const char *path) -{ - grub_err_t ret = GRUB_ERR_NONE; - struct disk_dev *dev; - char *canon; - - canon = canonicalise_disk (path); - dev = grub_named_list_find (GRUB_AS_NAMED_LIST (disk_devs), canon); - - if ((canon != NULL) && (dev == NULL)) - { - struct disk_dev *ob_device; - - ob_device = add_canon_disk (canon); - - if (ob_device == NULL) - ret = grub_error (GRUB_ERR_OUT_OF_MEMORY, "failure to add disk"); - } - else if (dev != NULL) - dev->valid = 1; - - grub_free (canon); - return (ret); -} - -static grub_err_t -grub_obdisk_read (grub_disk_t disk, grub_disk_addr_t sector, - grub_size_t size, char *dest) -{ - grub_err_t ret = GRUB_ERR_NONE; - struct disk_dev *dev; - unsigned long long pos; - grub_ssize_t result = 0; - - if (disk->data == NULL) - return grub_error (GRUB_ERR_BAD_DEVICE, "invalid disk data"); - - dev = (struct disk_dev *)disk->data; - pos = sector << disk->log_sector_size; - grub_ieee1275_seek (dev->ihandle, pos, &result); - - if (result < 0) - { - dev->opened = 0; - return grub_error (GRUB_ERR_READ_ERROR, "seek error, can't seek block %llu", - (long long) sector); - } - - grub_ieee1275_read (dev->ihandle, dest, size << disk->log_sector_size, - &result); - - if (result != (grub_ssize_t) (size << disk->log_sector_size)) - { - dev->opened = 0; - return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx " - "from `%s'"), - (unsigned long long) sector, - disk->name); - } - return ret; -} - -static void -grub_obdisk_close (grub_disk_t disk) -{ - grub_memset (disk, 0, sizeof (*disk)); -} - -static void -scan_usb_disk (const char *parent) -{ - struct parent_dev *op; - grub_ssize_t result; - - op = open_parent (parent); - - if (op == NULL) - { - grub_error (GRUB_ERR_BAD_DEVICE, "unable to open %s", parent); - grub_print_error (); - return; - } - - if ((grub_ieee1275_set_address (op->ihandle, 0, 0) == 0) && - (grub_ieee1275_no_data_command (op->ihandle, &tur, &result) == 0) && - (result == 0)) - { - char *buf; - - buf = grub_malloc (IEEE1275_MAX_PATH_LEN); - - if (buf == NULL) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "disk scan failure"); - grub_print_error (); - return; - } - - grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "%s/disk@0", parent); - add_disk (buf); - grub_free (buf); - } -} - -static void -scan_nvme_disk (const char *path) -{ - char *buf; - - buf = grub_malloc (IEEE1275_MAX_PATH_LEN); - - if (buf == NULL) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "disk scan failure"); - grub_print_error (); - return; - } - - grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "%s/disk@1", path); - add_disk (buf); - grub_free (buf); -} - -static void -scan_sparc_sas_2cell (struct parent_dev *op) -{ - grub_ssize_t result; - grub_uint8_t tgt; - char *buf; - - buf = grub_malloc (IEEE1275_MAX_PATH_LEN); - - if (buf == NULL) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "disk scan failure"); - grub_print_error (); - return; - } - - for (tgt = 0; tgt < 0xf; tgt++) - { - - if ((grub_ieee1275_set_address(op->ihandle, tgt, 0) == 0) && - (grub_ieee1275_no_data_command (op->ihandle, &tur, &result) == 0) && - (result == 0)) - { - - grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "%s/disk@%" - PRIxGRUB_UINT32_T, op->name, tgt); - - add_disk (buf); - } - } -} - -static void -scan_sparc_sas_4cell (struct parent_dev *op) -{ - grub_uint16_t exp; - grub_uint8_t phy; - char *buf; - - buf = grub_malloc (IEEE1275_MAX_PATH_LEN); - - if (buf == NULL) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "disk scan failure"); - grub_print_error (); - return; - } - - /* - * Cycle thru the potential for dual ported SAS disks - * behind a SAS expander. - */ - for (exp = 0; exp <= 0x100; exp+=0x100) - - /* The current limit is 32 disks on a phy. */ - for (phy = 0; phy < 0x20; phy++) - { - char *canon = NULL; - - grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "p%" PRIxGRUB_UINT32_T ",0", - exp | phy); - - canon = canonicalise_4cell_ua (op->ihandle, buf); - - if (canon != NULL) - { - grub_snprintf (buf, IEEE1275_MAX_PATH_LEN, "%s/disk@%s", - op->name, canon); - - add_disk (buf); - grub_free (canon); - } - } - - grub_free (buf); -} - -static void -scan_sparc_sas_disk (const char *parent) -{ - struct parent_dev *op; - - op = open_parent (parent); - - if ((op != NULL) && (op->address_cells == 4)) - scan_sparc_sas_4cell (op); - else if ((op != NULL) && (op->address_cells == 2)) - scan_sparc_sas_2cell (op); -} - -static void -iterate_devtree (const struct grub_ieee1275_devalias *alias) -{ - struct grub_ieee1275_devalias child; - - if ((grub_strcmp (alias->type, "scsi-2") == 0) || - (grub_strcmp (alias->type, "scsi-sas") == 0)) - return scan_sparc_sas_disk (alias->path); - - else if (grub_strcmp (alias->type, "nvme") == 0) - return scan_nvme_disk (alias->path); - - else if (grub_strcmp (alias->type, "scsi-usb") == 0) - return scan_usb_disk (alias->path); - - else if (grub_strcmp (alias->type, "block") == 0) - { - const char **bl = block_blacklist; - - while (*bl != NULL) - { - if (grub_strstr (alias->path, *bl)) - return; - bl++; - } - - add_disk (alias->path); - return; - } - - FOR_IEEE1275_DEVCHILDREN (alias->path, child) - iterate_devtree (&child); -} - -static void -enumerate_disks (void) -{ - struct grub_ieee1275_devalias alias; - - FOR_IEEE1275_DEVCHILDREN("/", alias) - iterate_devtree (&alias); -} - -static grub_err_t -add_bootpath (void) -{ - struct disk_dev *ob_device; - grub_err_t ret = GRUB_ERR_NONE; - char *dev, *alias; - char *type; - - dev = grub_ieee1275_get_boot_dev (); - - if (dev == NULL) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failure adding boot device"); - - type = grub_ieee1275_get_device_type (dev); - - if (type == NULL) - { - grub_free (dev); - return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failure adding boot device"); - } - - alias = NULL; - - if (grub_strcmp (type, "network") != 0) - { - dev = strip_ob_partition (dev); - ob_device = add_canon_disk (dev); - - if (ob_device == NULL) - ret = grub_error (GRUB_ERR_OUT_OF_MEMORY, "failure adding boot device"); - - ob_device->valid = 1; - - alias = grub_ieee1275_get_devname (dev); - - if (alias && grub_strcmp (alias, dev) != 0) - ob_device->grub_alias_devpath = grub_ieee1275_encode_devname (dev); - - ob_device->boot_dev = 1; - } - - grub_free (type); - grub_free (dev); - grub_free (alias); - return ret; -} - -static void -enumerate_aliases (void) -{ - struct grub_ieee1275_devalias alias; - - /* - * Some block device aliases are not in canonical form - * - * For example: - * - * disk3 /pci@301/pci@1/scsi@0/disk@p3 - * disk2 /pci@301/pci@1/scsi@0/disk@p2 - * disk1 /pci@301/pci@1/scsi@0/disk@p1 - * disk /pci@301/pci@1/scsi@0/disk@p0 - * disk0 /pci@301/pci@1/scsi@0/disk@p0 - * - * None of these devices are in canonical form. - * - * Also, just because there is a devalias, doesn't mean there is a disk - * at that location. And a valid boot block device doesn't have to have - * a devalias at all. - * - * At this point, all valid disks have been found in the system - * and devaliases that point to canonical names are stored in the - * disk_devs list already. - */ - FOR_IEEE1275_DEVALIASES (alias) - { - struct disk_dev *dev; - char *canon; - - if (grub_strcmp (alias.type, "block") != 0) - continue; - - canon = canonicalise_disk (alias.name); - - if (canon == NULL) - /* This is not an error, a devalias could point to a nonexistent disk. */ - continue; - - dev = grub_named_list_find (GRUB_AS_NAMED_LIST (disk_devs), canon); - - if (dev != NULL) - { - /* - * If more than one alias points to the same device, - * remove the previous one unless it is the boot dev, - * since the upper level will use the first one. The reason - * all the others are redone is in the case of hot-plugging - * a disk. If the boot disk gets hot-plugged, it will come - * thru here with a different name without the boot_dev flag - * set. - */ - if ((dev->boot_dev) && (dev->grub_alias_devpath)) - continue; - - grub_free (dev->grub_alias_devpath); - dev->grub_alias_devpath = grub_ieee1275_encode_devname (alias.path); - } - grub_free (canon); - } -} - -static void -display_disks (void) -{ - struct disk_dev *dev; - - grub_printf ("--------------------- DISKS ---------------------\n"); - - FOR_LIST_ELEMENTS (dev, disk_devs) - { - grub_printf ("name: %s\n", dev->name); - grub_printf ("grub_devpath: %s\n", dev->grub_devpath); - grub_printf ("grub_alias_devpath: %s\n", dev->grub_alias_devpath); - grub_printf ("valid: %s\n", (dev->valid) ? "yes" : "no"); - grub_printf ("boot_dev: %s\n", (dev->boot_dev) ? "yes" : "no"); - grub_printf ("opened: %s\n", (dev->ihandle) ? "yes" : "no"); - grub_printf ("block size: %" PRIuGRUB_UINT32_T "\n", - dev->block_size); - grub_printf ("num blocks: %" PRIuGRUB_UINT64_T "\n", - dev->num_blocks); - grub_printf ("log sector size: %" PRIuGRUB_UINT32_T "\n", - dev->log_sector_size); - grub_printf ("\n"); - } - - grub_printf ("-------------------------------------------------\n"); -} - -static void -display_stats (void) -{ - const char *debug = grub_env_get ("debug"); - - if (debug == NULL) - return; - - if (grub_strword (debug, "all") || grub_strword (debug, "obdisk")) - { - display_parents (); - display_disks (); - } -} - -static void -invalidate_all_disks (void) -{ - struct disk_dev *dev = NULL; - - if (disks_enumerated != 0) - FOR_LIST_ELEMENTS (dev, disk_devs) - dev->valid = 0; -} - -static struct disk_dev * -find_legacy_grub_devpath (const char *name) -{ - struct disk_dev *dev = NULL; - char *canon, *devpath = NULL; - - devpath = decode_grub_devname (name + sizeof ("ieee1275")); - canon = canonicalise_disk (devpath); - - if (canon != NULL) - dev = grub_named_list_find (GRUB_AS_NAMED_LIST (disk_devs), canon); - - grub_free (devpath); - grub_free (canon); - return dev; -} - -static void -enumerate_devices (void) -{ - invalidate_all_disks (); - enumerate_disks (); - enumerate_aliases (); - disks_enumerated = 1; - display_stats (); -} - -static struct disk_dev * -find_grub_devpath_real (const char *name) -{ - struct disk_dev *dev = NULL; - - FOR_LIST_ELEMENTS (dev, disk_devs) - { - if ((STRCMP (dev->grub_devpath, name)) - || (STRCMP (dev->grub_alias_devpath, name))) - break; - } - - return dev; -} - -static struct disk_dev * -find_grub_devpath (const char *name) -{ - struct disk_dev *dev = NULL; - int enumerated; - - do { - enumerated = disks_enumerated; - dev = find_grub_devpath_real (name); - - if (dev != NULL) - break; - - dev = find_legacy_grub_devpath (name); - - if (dev != NULL) - break; - - enumerate_devices (); - } while (enumerated == 0); - - return dev; -} - -static int -grub_obdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, - grub_disk_pull_t pull) -{ - struct disk_dev *dev; - const char *name; - - if (pull != GRUB_DISK_PULL_NONE) - return 0; - - enumerate_devices (); - - FOR_LIST_ELEMENTS (dev, disk_devs) - { - if (dev->valid == 1) - { - if (dev->grub_alias_devpath) - name = dev->grub_alias_devpath; - else - name = dev->grub_devpath; - - if (hook (name, hook_data)) - return 1; - } - } - - return 0; -} - -static grub_err_t -grub_obdisk_open (const char *name, grub_disk_t disk) -{ - grub_ieee1275_ihandle_t ihandle = 0; - struct disk_dev *dev = NULL; - - if (grub_strncmp (name, IEEE1275_DEV, sizeof (IEEE1275_DEV) - 1) != 0) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not IEEE1275 device"); - - dev = find_grub_devpath (name); - - if (dev == NULL) - { - grub_printf ("UNKNOWN DEVICE: %s\n", name); - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "%s", name); - } - - if (dev->opened == 0) - { - if (dev->raw_name != NULL) - grub_ieee1275_open (dev->raw_name, &ihandle); - else - grub_ieee1275_open (dev->name, &ihandle); - - if (ihandle == 0) - { - grub_printf ("Can't open device %s\n", name); - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device %s", name); - } - - dev->block_size = grub_ieee1275_get_block_size (ihandle); - dev->num_blocks = grub_ieee1275_num_blocks (ihandle); - - if (dev->num_blocks == 0) - dev->num_blocks = grub_ieee1275_num_blocks64 (ihandle); - - if (dev->num_blocks == 0) - dev->num_blocks = GRUB_DISK_SIZE_UNKNOWN; - - if (dev->block_size != 0) - { - for (dev->log_sector_size = 0; - (1U << dev->log_sector_size) < dev->block_size; - dev->log_sector_size++); - } - else - dev->log_sector_size = 9; - - dev->ihandle = ihandle; - dev->opened = 1; - } - - disk->total_sectors = dev->num_blocks; - disk->id = dev->ihandle; - disk->data = dev; - disk->log_sector_size = dev->log_sector_size; - return GRUB_ERR_NONE; -} - - -static struct grub_disk_dev grub_obdisk_dev = - { - .name = "obdisk", - .id = GRUB_DISK_DEVICE_OBDISK_ID, - .disk_iterate = grub_obdisk_iterate, - .disk_open = grub_obdisk_open, - .disk_close = grub_obdisk_close, - .disk_read = grub_obdisk_read, - }; - -void -grub_obdisk_init (void) -{ - grub_disk_firmware_fini = grub_obdisk_fini; - add_bootpath (); - grub_disk_dev_register (&grub_obdisk_dev); -} - -void -grub_obdisk_fini (void) -{ - struct disk_dev *dev; - - FOR_LIST_ELEMENTS (dev, disk_devs) - { - if (dev->opened != 0) - grub_ieee1275_close (dev->ihandle); - } - - grub_disk_dev_unregister (&grub_obdisk_dev); -} diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 03674cb47..6870b3958 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -34,8 +34,7 @@ struct ofdisk_hash_ent char *open_path; char *grub_devpath; int is_boot; - int is_removable; - int block_size_fails; + int is_cdrom; /* Pointer to shortest available name on nodes representing canonical names, otherwise NULL. */ const char *shortest; @@ -43,10 +42,6 @@ struct ofdisk_hash_ent struct ofdisk_hash_ent *next; }; -static grub_err_t -grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, - struct ofdisk_hash_ent *op); - #define OFDISK_HASH_SZ 8 static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ]; @@ -128,7 +123,7 @@ ofdisk_hash_add_real (char *devpath) } static int -check_string_removable (const char *str) +check_string_cdrom (const char *str) { const char *ptr = grub_strrchr (str, '/'); @@ -136,7 +131,7 @@ check_string_removable (const char *str) ptr++; else ptr = str; - return (grub_strncmp (ptr, "cdrom", 5) == 0 || grub_strncmp (ptr, "fd", 2) == 0); + return (grub_strncmp (ptr, "cdrom", 5) == 0); } static struct ofdisk_hash_ent * @@ -152,8 +147,8 @@ ofdisk_hash_add (char *devpath, char *curcan) { p->shortest = p->devpath; p->grub_shortest = p->grub_devpath; - if (check_string_removable (devpath)) - p->is_removable = 1; + if (check_string_cdrom (devpath)) + p->is_cdrom = 1; return p; } @@ -163,8 +158,8 @@ ofdisk_hash_add (char *devpath, char *curcan) else grub_free (curcan); - if (check_string_removable (devpath) || check_string_removable (curcan)) - pcan->is_removable = 1; + if (check_string_cdrom (devpath) || check_string_cdrom (curcan)) + pcan->is_cdrom = 1; if (!pcan) grub_errno = GRUB_ERR_NONE; @@ -227,10 +222,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) if (grub_ieee1275_open (alias->path, &ihandle)) return; - - /* This method doesn't need memory allocation for the table. Open - firmware takes care of all memory management and the result table - stays in memory and is never freed. */ + INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3); args.method = (grub_ieee1275_cell_t) "vscsi-report-luns"; args.ihandle = ihandle; @@ -263,82 +255,6 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) grub_free (buf); return; } - else if (grub_strcmp (alias->type, "sas_ioa") == 0) - { - /* The method returns the number of disks and a table where - * each ID is 64-bit long. Example of sas paths: - * /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800 - * /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800 - * /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */ - - struct sas_children - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t max; - grub_ieee1275_cell_t table; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t nentries; - } - args; - char *buf, *bufptr; - unsigned i; - grub_uint64_t *table; - grub_uint16_t table_size; - grub_ieee1275_ihandle_t ihandle; - - buf = grub_malloc (grub_strlen (alias->path) + - sizeof ("/disk@7766554433221100")); - if (!buf) - return; - bufptr = grub_stpcpy (buf, alias->path); - - /* Power machines documentation specify 672 as maximum SAS disks in - one system. Using a slightly larger value to be safe. */ - table_size = 768; - table = grub_calloc (table_size, sizeof (grub_uint64_t)); - - if (!table) - { - grub_free (buf); - return; - } - - if (grub_ieee1275_open (alias->path, &ihandle)) - { - grub_free (buf); - grub_free (table); - return; - } - - INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2); - args.method = (grub_ieee1275_cell_t) "get-sas-children"; - args.ihandle = ihandle; - args.max = table_size; - args.table = (grub_ieee1275_cell_t) table; - args.catch_result = 0; - args.nentries = 0; - - if (IEEE1275_CALL_ENTRY_FN (&args) == -1) - { - grub_ieee1275_close (ihandle); - grub_free (table); - grub_free (buf); - return; - } - - for (i = 0; i < args.nentries; i++) - { - grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"), - "/disk@%" PRIxGRUB_UINT64_T, table[i]); - dev_iterate_real (buf, buf); - } - - grub_ieee1275_close (ihandle); - grub_free (table); - grub_free (buf); - } if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS) && grub_strcmp (alias->type, "block") == 0) @@ -414,7 +330,7 @@ grub_ofdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, } } - if (!ent->is_boot && ent->is_removable) + if (!ent->is_boot && ent->is_cdrom) continue; if (hook (ent->grub_shortest, hook_data)) @@ -459,8 +375,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) /* XXX: This should be large enough for any possible case. */ char prop[64]; grub_ssize_t actual; - grub_uint32_t block_size = 0; - grub_err_t err; if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, @@ -491,6 +405,14 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device"); } + grub_uint32_t block_size = 0; + if (grub_ofdisk_get_block_size (devpath, &block_size) == 0) + { + for (disk->log_sector_size = 0; + (1U << disk->log_sector_size) < block_size; + disk->log_sector_size++); + } + /* XXX: There is no property to read the number of blocks. There should be a property `#blocks', but it is not there. Perhaps it is possible to use seek for this. */ @@ -501,31 +423,14 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) op = ofdisk_hash_find (devpath); if (!op) op = ofdisk_hash_add (devpath, NULL); + else + grub_free (devpath); if (!op) - { - grub_free (devpath); - return grub_errno; - } + return grub_errno; disk->id = (unsigned long) op; disk->data = op->open_path; - - err = grub_ofdisk_get_block_size (devpath, &block_size, op); - if (err) - { - grub_free (devpath); - return err; - } - if (block_size != 0) - { - for (disk->log_sector_size = 0; - (1U << disk->log_sector_size) < block_size; - disk->log_sector_size++); - } - else - disk->log_sector_size = 9; } - grub_free (devpath); return 0; } @@ -615,11 +520,11 @@ static struct grub_disk_dev grub_ofdisk_dev = { .name = "ofdisk", .id = GRUB_DISK_DEVICE_OFDISK_ID, - .disk_iterate = grub_ofdisk_iterate, - .disk_open = grub_ofdisk_open, - .disk_close = grub_ofdisk_close, - .disk_read = grub_ofdisk_read, - .disk_write = grub_ofdisk_write, + .iterate = grub_ofdisk_iterate, + .open = grub_ofdisk_open, + .close = grub_ofdisk_close, + .read = grub_ofdisk_read, + .write = grub_ofdisk_write, .next = 0 }; @@ -684,9 +589,8 @@ grub_ofdisk_init (void) grub_disk_dev_register (&grub_ofdisk_dev); } -static grub_err_t -grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, - struct ofdisk_hash_ent *op) +grub_err_t +grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size) { struct size_args_ieee1275 { @@ -708,34 +612,20 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, if (! last_ihandle) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); - *block_size = 0; - - if (op->block_size_fails >= 2) - return GRUB_ERR_NONE; - INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2); args_ieee1275.method = (grub_ieee1275_cell_t) "block-size"; args_ieee1275.ihandle = last_ihandle; args_ieee1275.result = 1; - if (IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) - { - grub_dprintf ("disk", "can't get block size: failed call-method\n"); - op->block_size_fails++; - } - else if (args_ieee1275.result) - { - grub_dprintf ("disk", "can't get block size: %lld\n", - (long long) args_ieee1275.result); - op->block_size_fails++; - } - else if (args_ieee1275.size1 - && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1)) - && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384) - { - op->block_size_fails = 0; + *block_size = GRUB_DISK_SECTOR_SIZE; + + if ((IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1) || (args_ieee1275.result)) + grub_dprintf ("disk", "can't get block size\n"); + else + if (args_ieee1275.size1 + && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1)) + && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384) *block_size = args_ieee1275.size1; - } return 0; } diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c index 58f8a53e1..8075f2a9e 100644 --- a/grub-core/disk/ldm.c +++ b/grub-core/disk/ldm.c @@ -25,7 +25,6 @@ #include #include #include -#include #ifdef GRUB_UTIL #include @@ -136,7 +135,7 @@ msdos_has_ldm_partition (grub_disk_t dsk) return has_ldm; } -static const grub_gpt_part_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM; +static const grub_gpt_part_type_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM; /* Helper for gpt_ldm_sector. */ static int @@ -290,7 +289,6 @@ make_vg (grub_disk_t disk, struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_ldm_vblk)]; unsigned i; - grub_size_t sz; err = grub_disk_read (disk, cursec, 0, sizeof(vblk), &vblk); if (err) @@ -325,8 +323,8 @@ make_vg (grub_disk_t disk, lv->segments->type = GRUB_DISKFILTER_MIRROR; lv->segments->node_count = 0; lv->segments->node_alloc = 8; - lv->segments->nodes = grub_calloc (lv->segments->node_alloc, - sizeof (*lv->segments->nodes)); + lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) + * lv->segments->node_alloc); if (!lv->segments->nodes) goto fail2; ptr = vblk[i].dynamic; @@ -352,13 +350,7 @@ make_vg (grub_disk_t disk, grub_free (lv); goto fail2; } - if (grub_add (*ptr, 1, &sz)) - { - grub_free (lv->internal_id); - grub_free (lv); - goto fail2; - } - lv->name = grub_malloc (sz); + lv->name = grub_malloc (*ptr + 1); if (!lv->name) { grub_free (lv->internal_id); @@ -551,8 +543,8 @@ make_vg (grub_disk_t disk, { comp->segment_alloc = 8; comp->segment_count = 0; - comp->segments = grub_calloc (comp->segment_alloc, - sizeof (*comp->segments)); + comp->segments = grub_malloc (sizeof (*comp->segments) + * comp->segment_alloc); if (!comp->segments) goto fail2; } @@ -598,8 +590,8 @@ make_vg (grub_disk_t disk, } comp->segments->node_count = read_int (ptr + 1, *ptr); comp->segments->node_alloc = comp->segments->node_count; - comp->segments->nodes = grub_calloc (comp->segments->node_alloc, - sizeof (*comp->segments->nodes)); + comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) + * comp->segments->node_alloc); if (!lv->segments->nodes) goto fail2; } @@ -607,13 +599,10 @@ make_vg (grub_disk_t disk, if (lv->segments->node_alloc == lv->segments->node_count) { void *t; - grub_size_t sz; - - if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || - grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) - goto fail2; - - t = grub_realloc (lv->segments->nodes, sz); + lv->segments->node_alloc *= 2; + t = grub_realloc (lv->segments->nodes, + sizeof (*lv->segments->nodes) + * lv->segments->node_alloc); if (!t) goto fail2; lv->segments->nodes = t; @@ -734,13 +723,10 @@ make_vg (grub_disk_t disk, if (comp->segment_alloc == comp->segment_count) { void *t; - grub_size_t sz; - - if (grub_mul (comp->segment_alloc, 2, &comp->segment_alloc) || - grub_mul (comp->segment_alloc, sizeof (*comp->segments), &sz)) - goto fail2; - - t = grub_realloc (comp->segments, sz); + comp->segment_alloc *= 2; + t = grub_realloc (comp->segments, + comp->segment_alloc + * sizeof (*comp->segments)); if (!t) goto fail2; comp->segments = t; @@ -977,7 +963,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, if (embed_type != GRUB_EMBED_PCBIOS) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "LDM currently supports only PC-BIOS embedding"); + "LDM curently supports only PC-BIOS embedding"); if (disk->partition) return grub_error (GRUB_ERR_BUG, "disk isn't LDM"); pv = grub_diskfilter_get_pv_from_disk (disk, &vg); @@ -1031,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, *nsectors = lv->size; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index cdf9123fa..2d8deaeaf 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -92,8 +92,7 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args) if (argc < 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK - | GRUB_FILE_TYPE_NO_DECOMPRESS); + file = grub_file_open (args[1]); if (! file) return grub_errno; @@ -222,10 +221,10 @@ static struct grub_disk_dev grub_loopback_dev = { .name = "loopback", .id = GRUB_DISK_DEVICE_LOOPBACK_ID, - .disk_iterate = grub_loopback_iterate, - .disk_open = grub_loopback_open, - .disk_read = grub_loopback_read, - .disk_write = grub_loopback_write, + .iterate = grub_loopback_iterate, + .open = grub_loopback_open, + .read = grub_loopback_read, + .write = grub_loopback_write, .next = 0 }; diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c index 59702067a..86c50c612 100644 --- a/grub-core/disk/luks.c +++ b/grub-core/disk/luks.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007,2010,2011,2019 Free Software Foundation, Inc. + * Copyright (C) 2003,2007,2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,7 +75,15 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, char uuid[sizeof (header.uuid) + 1]; char ciphername[sizeof (header.cipherName) + 1]; char ciphermode[sizeof (header.cipherMode) + 1]; + char *cipheriv = NULL; char hashspec[sizeof (header.hashSpec) + 1]; + grub_crypto_cipher_handle_t cipher = NULL, secondary_cipher = NULL; + grub_crypto_cipher_handle_t essiv_cipher = NULL; + const gcry_md_spec_t *hash = NULL, *essiv_hash = NULL; + const struct gcry_cipher_spec *ciph; + grub_cryptodisk_mode_t mode; + grub_cryptodisk_mode_iv_t mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN64; + int benbi_log = 0; grub_err_t err; if (check_boot) @@ -95,7 +103,6 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, || grub_be_to_cpu16 (header.version) != 1) return NULL; - grub_memset (uuid, 0, sizeof (uuid)); optr = uuid; for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)]; iptr++) @@ -119,33 +126,183 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, grub_memcpy (hashspec, header.hashSpec, sizeof (header.hashSpec)); hashspec[sizeof (header.hashSpec)] = 0; - newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); - if (!newdev) + ciph = grub_crypto_lookup_cipher_by_name (ciphername); + if (!ciph) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "Cipher %s isn't available", + ciphername); return NULL; - newdev->offset = grub_be_to_cpu32 (header.payloadOffset); - newdev->source_disk = NULL; - newdev->log_sector_size = 9; - newdev->total_length = grub_disk_get_size (disk) - newdev->offset; - grub_memcpy (newdev->uuid, uuid, sizeof (uuid)); - newdev->modname = "luks"; + } + + /* Configure the cipher used for the bulk data. */ + cipher = grub_crypto_cipher_open (ciph); + if (!cipher) + return NULL; + + if (grub_be_to_cpu32 (header.keyBytes) > 1024) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid keysize %d", + grub_be_to_cpu32 (header.keyBytes)); + grub_crypto_cipher_close (cipher); + return NULL; + } + + /* Configure the cipher mode. */ + if (grub_strcmp (ciphermode, "ecb") == 0) + { + mode = GRUB_CRYPTODISK_MODE_ECB; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; + cipheriv = NULL; + } + else if (grub_strcmp (ciphermode, "plain") == 0) + { + mode = GRUB_CRYPTODISK_MODE_CBC; + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; + cipheriv = NULL; + } + else if (grub_memcmp (ciphermode, "cbc-", sizeof ("cbc-") - 1) == 0) + { + mode = GRUB_CRYPTODISK_MODE_CBC; + cipheriv = ciphermode + sizeof ("cbc-") - 1; + } + else if (grub_memcmp (ciphermode, "pcbc-", sizeof ("pcbc-") - 1) == 0) + { + mode = GRUB_CRYPTODISK_MODE_PCBC; + cipheriv = ciphermode + sizeof ("pcbc-") - 1; + } + else if (grub_memcmp (ciphermode, "xts-", sizeof ("xts-") - 1) == 0) + { + mode = GRUB_CRYPTODISK_MODE_XTS; + cipheriv = ciphermode + sizeof ("xts-") - 1; + secondary_cipher = grub_crypto_cipher_open (ciph); + if (!secondary_cipher) + { + grub_crypto_cipher_close (cipher); + return NULL; + } + if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", + cipher->cipher->blocksize); + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (secondary_cipher); + return NULL; + } + if (secondary_cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d", + secondary_cipher->cipher->blocksize); + grub_crypto_cipher_close (secondary_cipher); + return NULL; + } + } + else if (grub_memcmp (ciphermode, "lrw-", sizeof ("lrw-") - 1) == 0) + { + mode = GRUB_CRYPTODISK_MODE_LRW; + cipheriv = ciphermode + sizeof ("lrw-") - 1; + if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d", + cipher->cipher->blocksize); + grub_crypto_cipher_close (cipher); + return NULL; + } + } + else + { + grub_crypto_cipher_close (cipher); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown cipher mode: %s", + ciphermode); + return NULL; + } + + if (cipheriv == NULL); + else if (grub_memcmp (cipheriv, "plain", sizeof ("plain") - 1) == 0) + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN; + else if (grub_memcmp (cipheriv, "plain64", sizeof ("plain64") - 1) == 0) + mode_iv = GRUB_CRYPTODISK_MODE_IV_PLAIN64; + else if (grub_memcmp (cipheriv, "benbi", sizeof ("benbi") - 1) == 0) + { + if (cipher->cipher->blocksize & (cipher->cipher->blocksize - 1) + || cipher->cipher->blocksize == 0) + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %d", + cipher->cipher->blocksize); + /* FIXME should we return an error here? */ + for (benbi_log = 0; + (cipher->cipher->blocksize << benbi_log) < GRUB_DISK_SECTOR_SIZE; + benbi_log++); + mode_iv = GRUB_CRYPTODISK_MODE_IV_BENBI; + } + else if (grub_memcmp (cipheriv, "null", sizeof ("null") - 1) == 0) + mode_iv = GRUB_CRYPTODISK_MODE_IV_NULL; + else if (grub_memcmp (cipheriv, "essiv:", sizeof ("essiv:") - 1) == 0) + { + char *hash_str = cipheriv + 6; + + mode_iv = GRUB_CRYPTODISK_MODE_IV_ESSIV; + + /* Configure the hash and cipher used for ESSIV. */ + essiv_hash = grub_crypto_lookup_md_by_name (hash_str); + if (!essiv_hash) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (secondary_cipher); + grub_error (GRUB_ERR_FILE_NOT_FOUND, + "Couldn't load %s hash", hash_str); + return NULL; + } + essiv_cipher = grub_crypto_cipher_open (ciph); + if (!essiv_cipher) + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (secondary_cipher); + return NULL; + } + } + else + { + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (secondary_cipher); + grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown IV mode: %s", + cipheriv); + return NULL; + } /* Configure the hash used for the AF splitter and HMAC. */ - newdev->hash = grub_crypto_lookup_md_by_name (hashspec); - if (!newdev->hash) + hash = grub_crypto_lookup_md_by_name (hashspec); + if (!hash) { - grub_free (newdev); + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_crypto_cipher_close (secondary_cipher); grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", hashspec); return NULL; } - err = grub_cryptodisk_setcipher (newdev, ciphername, ciphermode); - if (err) + newdev = grub_zalloc (sizeof (struct grub_cryptodisk)); + if (!newdev) { - grub_free (newdev); + grub_crypto_cipher_close (cipher); + grub_crypto_cipher_close (essiv_cipher); + grub_crypto_cipher_close (secondary_cipher); return NULL; } - + newdev->cipher = cipher; + newdev->offset = grub_be_to_cpu32 (header.payloadOffset); + newdev->source_disk = NULL; + newdev->benbi_log = benbi_log; + newdev->mode = mode; + newdev->mode_iv = mode_iv; + newdev->secondary_cipher = secondary_cipher; + newdev->essiv_cipher = essiv_cipher; + newdev->essiv_hash = essiv_hash; + newdev->hash = hash; + newdev->log_sector_size = 9; + newdev->total_length = grub_disk_get_size (disk) - newdev->offset; + grub_memcpy (newdev->uuid, uuid, sizeof (newdev->uuid)); + newdev->modname = "luks"; COMPILE_TIME_ASSERT (sizeof (newdev->uuid) >= sizeof (uuid)); return newdev; } @@ -179,7 +336,7 @@ luks_recover_key (grub_disk_t source, && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); - split_key = grub_calloc (keysize, max_stripes); + split_key = grub_malloc (keysize * max_stripes); if (!split_key) return grub_errno; diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c deleted file mode 100644 index 31d7166fc..000000000 --- a/grub-core/disk/luks2.c +++ /dev/null @@ -1,687 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -#define LUKS_MAGIC_1ST "LUKS\xBA\xBE" -#define LUKS_MAGIC_2ND "SKUL\xBA\xBE" - -#define MAX_PASSPHRASE 256 - -enum grub_luks2_kdf_type -{ - LUKS2_KDF_TYPE_ARGON2I, - LUKS2_KDF_TYPE_PBKDF2 -}; -typedef enum grub_luks2_kdf_type grub_luks2_kdf_type_t; - -/* On disk LUKS header */ -struct grub_luks2_header -{ - char magic[6]; - grub_uint16_t version; - grub_uint64_t hdr_size; - grub_uint64_t seqid; - char label[48]; - char csum_alg[32]; - grub_uint8_t salt[64]; - char uuid[40]; - char subsystem[48]; - grub_uint64_t hdr_offset; - char _padding[184]; - grub_uint8_t csum[64]; - char _padding4096[7*512]; -} GRUB_PACKED; -typedef struct grub_luks2_header grub_luks2_header_t; - -struct grub_luks2_keyslot -{ - grub_int64_t key_size; - grub_int64_t priority; - struct - { - const char *encryption; - grub_uint64_t offset; - grub_uint64_t size; - grub_int64_t key_size; - } area; - struct - { - const char *hash; - grub_int64_t stripes; - } af; - struct - { - grub_luks2_kdf_type_t type; - const char *salt; - union - { - struct - { - grub_int64_t time; - grub_int64_t memory; - grub_int64_t cpus; - } argon2i; - struct - { - const char *hash; - grub_int64_t iterations; - } pbkdf2; - } u; - } kdf; -}; -typedef struct grub_luks2_keyslot grub_luks2_keyslot_t; - -struct grub_luks2_segment -{ - grub_uint64_t offset; - const char *size; - const char *encryption; - grub_int64_t sector_size; -}; -typedef struct grub_luks2_segment grub_luks2_segment_t; - -struct grub_luks2_digest -{ - /* Both keyslots and segments are interpreted as bitfields here */ - grub_uint64_t keyslots; - grub_uint64_t segments; - const char *salt; - const char *digest; - const char *hash; - grub_int64_t iterations; -}; -typedef struct grub_luks2_digest grub_luks2_digest_t; - -gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, - grub_uint8_t * dst, grub_size_t blocksize, - grub_size_t blocknumbers); - -static grub_err_t -luks2_parse_keyslot (grub_luks2_keyslot_t *out, const grub_json_t *keyslot) -{ - grub_json_t area, af, kdf; - const char *type; - - if (grub_json_getstring (&type, keyslot, "type")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing or invalid keyslot"); - else if (grub_strcmp (type, "luks2")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported keyslot type %s", type); - else if (grub_json_getint64 (&out->key_size, keyslot, "key_size")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing keyslot information"); - if (grub_json_getint64 (&out->priority, keyslot, "priority")) - out->priority = 1; - - if (grub_json_getvalue (&area, keyslot, "area") || - grub_json_getstring (&type, &area, "type")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing or invalid key area"); - else if (grub_strcmp (type, "raw")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported key area type: %s", type); - else if (grub_json_getuint64 (&out->area.offset, &area, "offset") || - grub_json_getuint64 (&out->area.size, &area, "size") || - grub_json_getstring (&out->area.encryption, &area, "encryption") || - grub_json_getint64 (&out->area.key_size, &area, "key_size")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing key area information"); - - if (grub_json_getvalue (&kdf, keyslot, "kdf") || - grub_json_getstring (&type, &kdf, "type") || - grub_json_getstring (&out->kdf.salt, &kdf, "salt")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing or invalid KDF"); - else if (!grub_strcmp (type, "argon2i") || !grub_strcmp (type, "argon2id")) - { - out->kdf.type = LUKS2_KDF_TYPE_ARGON2I; - if (grub_json_getint64 (&out->kdf.u.argon2i.time, &kdf, "time") || - grub_json_getint64 (&out->kdf.u.argon2i.memory, &kdf, "memory") || - grub_json_getint64 (&out->kdf.u.argon2i.cpus, &kdf, "cpus")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing Argon2i parameters"); - } - else if (!grub_strcmp (type, "pbkdf2")) - { - out->kdf.type = LUKS2_KDF_TYPE_PBKDF2; - if (grub_json_getstring (&out->kdf.u.pbkdf2.hash, &kdf, "hash") || - grub_json_getint64 (&out->kdf.u.pbkdf2.iterations, &kdf, "iterations")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing PBKDF2 parameters"); - } - else - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported KDF type %s", type); - - if (grub_json_getvalue (&af, keyslot, "af") || - grub_json_getstring (&type, &af, "type")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing or invalid area"); - if (grub_strcmp (type, "luks1")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported AF type %s", type); - if (grub_json_getint64 (&out->af.stripes, &af, "stripes") || - grub_json_getstring (&out->af.hash, &af, "hash")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing AF parameters"); - - return GRUB_ERR_NONE; -} - -static grub_err_t -luks2_parse_segment (grub_luks2_segment_t *out, const grub_json_t *segment) -{ - const char *type; - - if (grub_json_getstring (&type, segment, "type")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid segment type"); - else if (grub_strcmp (type, "crypt")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported segment type %s", type); - - if (grub_json_getuint64 (&out->offset, segment, "offset") || - grub_json_getstring (&out->size, segment, "size") || - grub_json_getstring (&out->encryption, segment, "encryption") || - grub_json_getint64 (&out->sector_size, segment, "sector_size")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing segment parameters", type); - - return GRUB_ERR_NONE; -} - -static grub_err_t -luks2_parse_digest (grub_luks2_digest_t *out, const grub_json_t *digest) -{ - grub_json_t segments, keyslots, o; - grub_size_t i, size; - grub_uint64_t bit; - const char *type; - - if (grub_json_getstring (&type, digest, "type")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid digest type"); - else if (grub_strcmp (type, "pbkdf2")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported digest type %s", type); - - if (grub_json_getvalue (&segments, digest, "segments") || - grub_json_getvalue (&keyslots, digest, "keyslots") || - grub_json_getstring (&out->salt, digest, "salt") || - grub_json_getstring (&out->digest, digest, "digest") || - grub_json_getstring (&out->hash, digest, "hash") || - grub_json_getint64 (&out->iterations, digest, "iterations")) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing digest parameters"); - - if (grub_json_getsize (&size, &segments)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "Digest references no segments", type); - - for (i = 0; i < size; i++) - { - if (grub_json_getchild (&o, &segments, i) || - grub_json_getuint64 (&bit, &o, NULL)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid segment"); - out->segments |= (1 << bit); - } - - if (grub_json_getsize (&size, &keyslots)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - "Digest references no keyslots", type); - - for (i = 0; i < size; i++) - { - if (grub_json_getchild (&o, &keyslots, i) || - grub_json_getuint64 (&bit, &o, NULL)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid keyslot"); - out->keyslots |= (1 << bit); - } - - return GRUB_ERR_NONE; -} - -static grub_err_t -luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_segment_t *s, - const grub_json_t *root, grub_size_t i) -{ - grub_json_t keyslots, keyslot, digests, digest, segments, segment; - grub_size_t j, size; - grub_uint64_t idx; - - /* Get nth keyslot */ - if (grub_json_getvalue (&keyslots, root, "keyslots") || - grub_json_getchild (&keyslot, &keyslots, i) || - grub_json_getuint64 (&idx, &keyslot, NULL) || - grub_json_getchild (&keyslot, &keyslot, 0) || - luks2_parse_keyslot (k, &keyslot)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse keyslot %"PRIuGRUB_SIZE, i); - - /* Get digest that matches the keyslot. */ - if (grub_json_getvalue (&digests, root, "digests") || - grub_json_getsize (&size, &digests)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not get digests"); - for (j = 0; j < size; j++) - { - if (grub_json_getchild (&digest, &digests, i) || - grub_json_getchild (&digest, &digest, 0) || - luks2_parse_digest (d, &digest)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest %"PRIuGRUB_SIZE, i); - - if ((d->keyslots & (1 << idx))) - break; - } - if (j == size) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot %"PRIuGRUB_SIZE); - - /* Get segment that matches the digest. */ - if (grub_json_getvalue (&segments, root, "segments") || - grub_json_getsize (&size, &segments)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not get segments"); - for (j = 0; j < size; j++) - { - if (grub_json_getchild (&segment, &segments, i) || - grub_json_getuint64 (&idx, &segment, NULL) || - grub_json_getchild (&segment, &segment, 0) || - luks2_parse_segment (s, &segment)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse segment %"PRIuGRUB_SIZE, i); - - if ((d->segments & (1 << idx))) - break; - } - if (j == size) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No segment for digest %"PRIuGRUB_SIZE); - - return GRUB_ERR_NONE; -} - -/* Determine whether to use primary or secondary header */ -static grub_err_t -luks2_read_header (grub_disk_t disk, grub_luks2_header_t *outhdr) -{ - grub_luks2_header_t primary, secondary, *header = &primary; - grub_err_t ret; - - /* Read the primary LUKS header. */ - ret = grub_disk_read (disk, 0, 0, sizeof (primary), &primary); - if (ret) - return ret; - - /* Look for LUKS magic sequence. */ - if (grub_memcmp (primary.magic, LUKS_MAGIC_1ST, sizeof (primary.magic)) || - grub_be_to_cpu16 (primary.version) != 2) - return GRUB_ERR_BAD_SIGNATURE; - - /* Read the secondary header. */ - ret = grub_disk_read (disk, 0, grub_be_to_cpu64 (primary.hdr_size), sizeof (secondary), &secondary); - if (ret) - return ret; - - /* Look for LUKS magic sequence. */ - if (grub_memcmp (secondary.magic, LUKS_MAGIC_2ND, sizeof (secondary.magic)) || - grub_be_to_cpu16 (secondary.version) != 2) - return GRUB_ERR_BAD_SIGNATURE; - - if (grub_be_to_cpu64 (primary.seqid) < grub_be_to_cpu64 (secondary.seqid)) - header = &secondary; - grub_memcpy (outhdr, header, sizeof (*header)); - - return GRUB_ERR_NONE; -} - -static grub_cryptodisk_t -luks2_scan (grub_disk_t disk, const char *check_uuid, int check_boot) -{ - grub_cryptodisk_t cryptodisk; - grub_luks2_header_t header; - char uuid[sizeof (header.uuid) + 1]; - grub_size_t i, j; - - if (check_boot) - return NULL; - - if (luks2_read_header (disk, &header)) - { - grub_errno = GRUB_ERR_NONE; - return NULL; - } - - for (i = 0, j = 0; i < sizeof (header.uuid); i++) - if (header.uuid[i] != '-') - uuid[j++] = header.uuid[i]; - uuid[j] = '\0'; - - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0) - return NULL; - - cryptodisk = grub_zalloc (sizeof (*cryptodisk)); - if (!cryptodisk) - return NULL; - - COMPILE_TIME_ASSERT (sizeof (cryptodisk->uuid) >= sizeof (uuid)); - grub_memcpy (cryptodisk->uuid, uuid, sizeof (uuid)); - - cryptodisk->modname = "luks2"; - return cryptodisk; -} - -static grub_err_t -luks2_verify_key (grub_luks2_digest_t *d, grub_uint8_t *candidate_key, - grub_size_t candidate_key_len) -{ - grub_uint8_t candidate_digest[GRUB_CRYPTODISK_MAX_KEYLEN]; - grub_uint8_t digest[GRUB_CRYPTODISK_MAX_KEYLEN], salt[GRUB_CRYPTODISK_MAX_KEYLEN]; - grub_size_t saltlen = sizeof (salt), digestlen = sizeof (digest); - const gcry_md_spec_t *hash; - gcry_err_code_t gcry_ret; - - /* Decode both digest and salt */ - if (!base64_decode (d->digest, grub_strlen (d->digest), (char *)digest, &digestlen)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid digest"); - if (!base64_decode (d->salt, grub_strlen (d->salt), (char *)salt, &saltlen)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid digest salt"); - - /* Configure the hash used for the digest. */ - hash = grub_crypto_lookup_md_by_name (d->hash); - if (!hash) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", d->hash); - - /* Calculate the candidate key's digest */ - gcry_ret = grub_crypto_pbkdf2 (hash, - candidate_key, candidate_key_len, - salt, saltlen, - d->iterations, - candidate_digest, digestlen); - if (gcry_ret) - return grub_crypto_gcry_error (gcry_ret); - - if (grub_memcmp (candidate_digest, digest, digestlen) != 0) - return grub_error (GRUB_ERR_ACCESS_DENIED, "Mismatching digests"); - - return GRUB_ERR_NONE; -} - -static grub_err_t -luks2_decrypt_key (grub_uint8_t *out_key, - grub_disk_t disk, grub_cryptodisk_t crypt, - grub_luks2_keyslot_t *k, - const grub_uint8_t *passphrase, grub_size_t passphraselen) -{ - grub_uint8_t area_key[GRUB_CRYPTODISK_MAX_KEYLEN]; - grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN]; - grub_uint8_t *split_key = NULL; - grub_size_t saltlen = sizeof (salt); - char cipher[32], *p;; - const gcry_md_spec_t *hash; - gcry_err_code_t gcry_ret; - grub_err_t ret; - - if (!base64_decode (k->kdf.salt, grub_strlen (k->kdf.salt), - (char *)salt, &saltlen)) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid keyslot salt"); - goto err; - } - - /* Calculate the binary area key of the user supplied passphrase. */ - switch (k->kdf.type) - { - case LUKS2_KDF_TYPE_ARGON2I: - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported"); - goto err; - case LUKS2_KDF_TYPE_PBKDF2: - hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash); - if (!hash) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", - k->kdf.u.pbkdf2.hash); - goto err; - } - - gcry_ret = grub_crypto_pbkdf2 (hash, (grub_uint8_t *) passphrase, - passphraselen, - salt, saltlen, - k->kdf.u.pbkdf2.iterations, - area_key, k->area.key_size); - if (gcry_ret) - { - ret = grub_crypto_gcry_error (gcry_ret); - goto err; - } - - break; - } - - /* Set up disk encryption parameters for the key area */ - grub_strncpy (cipher, k->area.encryption, sizeof (cipher)); - p = grub_memchr (cipher, '-', grub_strlen (cipher)); - if (!p) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid encryption"); - *p = '\0'; - - ret = grub_cryptodisk_setcipher (crypt, cipher, p + 1); - if (ret) - return ret; - - gcry_ret = grub_cryptodisk_setkey (crypt, area_key, k->area.key_size); - if (gcry_ret) - { - ret = grub_crypto_gcry_error (gcry_ret); - goto err; - } - - /* Read and decrypt the binary key area with the area key. */ - split_key = grub_malloc (k->area.size); - if (!split_key) - { - ret = grub_errno; - goto err; - } - - grub_errno = GRUB_ERR_NONE; - ret = grub_disk_read (disk, 0, k->area.offset, k->area.size, split_key); - if (ret) - { - grub_error (GRUB_ERR_IO, "Read error: %s\n", grub_errmsg); - goto err; - } - - gcry_ret = grub_cryptodisk_decrypt (crypt, split_key, k->area.size, 0); - if (gcry_ret) - { - ret = grub_crypto_gcry_error (gcry_ret); - goto err; - } - - /* Configure the hash used for anti-forensic merging. */ - hash = grub_crypto_lookup_md_by_name (k->af.hash); - if (!hash) - { - ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash", - k->af.hash); - goto err; - } - - /* Merge the decrypted key material to get the candidate master key. */ - gcry_ret = AF_merge (hash, split_key, out_key, k->key_size, k->af.stripes); - if (gcry_ret) - { - ret = grub_crypto_gcry_error (gcry_ret); - goto err; - } - - grub_dprintf ("luks2", "Candidate key recovered\n"); - - err: - grub_free (split_key); - return ret; -} - -static grub_err_t -luks2_recover_key (grub_disk_t disk, - grub_cryptodisk_t crypt) -{ - grub_uint8_t candidate_key[GRUB_CRYPTODISK_MAX_KEYLEN]; - char passphrase[MAX_PASSPHRASE], cipher[32]; - char *json_header = NULL, *part = NULL, *ptr; - grub_size_t candidate_key_len = 0, i, size; - grub_luks2_header_t header; - grub_luks2_keyslot_t keyslot; - grub_luks2_digest_t digest; - grub_luks2_segment_t segment; - gcry_err_code_t gcry_ret; - grub_json_t *json = NULL, keyslots; - grub_err_t ret; - - ret = luks2_read_header (disk, &header); - if (ret) - return ret; - - json_header = grub_zalloc (grub_be_to_cpu64 (header.hdr_size) - sizeof (header)); - if (!json_header) - return GRUB_ERR_OUT_OF_MEMORY; - - /* Read the JSON area. */ - ret = grub_disk_read (disk, 0, grub_be_to_cpu64 (header.hdr_offset) + sizeof (header), - grub_be_to_cpu64 (header.hdr_size) - sizeof (header), json_header); - if (ret) - goto err; - - ptr = grub_memchr (json_header, 0, grub_be_to_cpu64 (header.hdr_size) - sizeof (header)); - if (!ptr) - goto err; - - ret = grub_json_parse (&json, json_header, grub_be_to_cpu64 (header.hdr_size)); - if (ret) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid LUKS2 JSON header"); - goto err; - } - - /* Get the passphrase from the user. */ - if (disk->partition) - part = grub_partition_get_name (disk->partition); - grub_printf_ (N_("Enter passphrase for %s%s%s (%s): "), disk->name, - disk->partition ? "," : "", part ? : "", - crypt->uuid); - if (!grub_password_get (passphrase, MAX_PASSPHRASE)) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied"); - goto err; - } - - if (grub_json_getvalue (&keyslots, json, "keyslots") || - grub_json_getsize (&size, &keyslots)) - { - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not get keyslots"); - goto err; - } - - /* Try all keyslot */ - for (i = 0; i < size; i++) - { - ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, i); - if (ret) - goto err; - - if (keyslot.priority == 0) - { - grub_dprintf ("luks2", "Ignoring keyslot %"PRIuGRUB_SIZE" due to priority\n", i); - continue; - } - - grub_dprintf ("luks2", "Trying keyslot %"PRIuGRUB_SIZE"\n", i); - - /* Set up disk according to keyslot's segment. */ - crypt->offset = grub_divmod64 (segment.offset, segment.sector_size, NULL); - crypt->log_sector_size = sizeof (unsigned int) * 8 - - __builtin_clz ((unsigned int) segment.sector_size) - 1; - if (grub_strcmp (segment.size, "dynamic") == 0) - crypt->total_length = grub_disk_get_size (disk) - crypt->offset; - else - crypt->total_length = grub_strtoull (segment.size, NULL, 10); - - ret = luks2_decrypt_key (candidate_key, disk, crypt, &keyslot, - (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); - if (ret) - { - grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n", - i, grub_errmsg); - continue; - } - - ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size); - if (ret) - { - grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n", - i, grub_errmsg); - continue; - } - - /* - * TRANSLATORS: It's a cryptographic key slot: one element of an array - * where each element is either empty or holds a key. - */ - grub_printf_ (N_("Slot %"PRIuGRUB_SIZE" opened\n"), i); - - candidate_key_len = keyslot.key_size; - break; - } - if (candidate_key_len == 0) - { - ret = grub_error (GRUB_ERR_ACCESS_DENIED, "Invalid passphrase"); - goto err; - } - - /* Set up disk cipher. */ - grub_strncpy (cipher, segment.encryption, sizeof (cipher)); - ptr = grub_memchr (cipher, '-', grub_strlen (cipher)); - if (!ptr) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid encryption"); - *ptr = '\0'; - - ret = grub_cryptodisk_setcipher (crypt, cipher, ptr + 1); - if (ret) - goto err; - - /* Set the master key. */ - gcry_ret = grub_cryptodisk_setkey (crypt, candidate_key, candidate_key_len); - if (gcry_ret) - { - ret = grub_crypto_gcry_error (gcry_ret); - goto err; - } - - err: - grub_free (part); - grub_free (json_header); - grub_json_free (json); - return ret; -} - -static struct grub_cryptodisk_dev luks2_crypto = { - .scan = luks2_scan, - .recover_key = luks2_recover_key -}; - -GRUB_MOD_INIT (luks2) -{ - grub_cryptodisk_dev_register (&luks2_crypto); -} - -GRUB_MOD_FINI (luks2) -{ - grub_cryptodisk_dev_unregister (&luks2_crypto); -} diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 753545146..862a9664f 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -25,7 +25,6 @@ #include #include #include -#include #ifdef GRUB_UTIL #include @@ -34,20 +33,12 @@ GRUB_MOD_LICENSE ("GPLv3+"); -struct cache_lv -{ - struct grub_diskfilter_lv *lv; - char *cache_pool; - char *origin; - struct cache_lv *next; -}; - /* Go the string STR and return the number after STR. *P will point at the number. In case STR is not found, *P will be NULL and the return value will be 0. */ static grub_uint64_t -grub_lvm_getvalue (const char ** const p, const char *str) +grub_lvm_getvalue (char **p, const char *str) { *p = grub_strstr (*p, str); if (! *p) @@ -72,12 +63,12 @@ grub_lvm_checkvalue (char **p, char *str, char *tmpl) #endif static int -grub_lvm_check_flag (const char *p, const char *str, const char *flag) +grub_lvm_check_flag (char *p, const char *str, const char *flag) { grub_size_t len_str = grub_strlen (str), len_flag = grub_strlen (flag); while (1) { - const char *q; + char *q; p = grub_strstr (p, str); if (! p) return 0; @@ -104,34 +95,6 @@ grub_lvm_check_flag (const char *p, const char *str, const char *flag) } } -static void -grub_lvm_free_cache_lvs (struct cache_lv *cache_lvs) -{ - struct cache_lv *cache; - - while ((cache = cache_lvs)) - { - cache_lvs = cache_lvs->next; - - if (cache->lv) - { - unsigned int i; - - for (i = 0; i < cache->lv->segment_count; ++i) - if (cache->lv->segments) - grub_free (cache->lv->segments[i].nodes); - grub_free (cache->lv->segments); - grub_free (cache->lv->fullname); - grub_free (cache->lv->idname); - grub_free (cache->lv->name); - } - grub_free (cache->lv); - grub_free (cache->origin); - grub_free (cache->cache_pool); - grub_free (cache); - } -} - static struct grub_diskfilter_vg * grub_lvm_detect (grub_disk_t disk, struct grub_diskfilter_pv_id *id, @@ -139,12 +102,10 @@ grub_lvm_detect (grub_disk_t disk, { grub_err_t err; grub_uint64_t mda_offset, mda_size; - grub_size_t ptr; char buf[GRUB_LVM_LABEL_SIZE]; char vg_id[GRUB_LVM_ID_STRLEN+1]; char pv_id[GRUB_LVM_ID_STRLEN+1]; - char *metadatabuf, *mda_end, *vgname; - const char *p, *q; + char *metadatabuf, *p, *q, *vgname; struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; struct grub_lvm_pv_header *pvh; struct grub_lvm_disk_locn *dlocn; @@ -199,7 +160,7 @@ grub_lvm_detect (grub_disk_t disk, "we don't support multiple LVM data areas"); #ifdef GRUB_UTIL - grub_util_info ("we don't support multiple LVM data areas"); + grub_util_info ("we don't support multiple LVM data areas\n"); #endif goto fail; } @@ -212,7 +173,7 @@ grub_lvm_detect (grub_disk_t disk, first one. */ /* Allocate buffer space for the circular worst-case scenario. */ - metadatabuf = grub_calloc (2, mda_size); + metadatabuf = grub_malloc (2 * mda_size); if (! metadatabuf) goto fail; @@ -228,7 +189,7 @@ grub_lvm_detect (grub_disk_t disk, grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "unknown LVM metadata header"); #ifdef GRUB_UTIL - grub_util_info ("unknown LVM metadata header"); + grub_util_info ("unknown LVM metadata header\n"); #endif goto fail2; } @@ -244,31 +205,19 @@ grub_lvm_detect (grub_disk_t disk, grub_le_to_cpu64 (rlocn->size) - grub_le_to_cpu64 (mdah->size)); } + p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); - if (grub_add ((grub_size_t)metadatabuf, - (grub_size_t)grub_le_to_cpu64 (rlocn->offset), - &ptr)) + while (*q != ' ' && q < metadatabuf + mda_size) + q++; + + if (q == metadatabuf + mda_size) { - error_parsing_metadata: #ifdef GRUB_UTIL - grub_util_info ("error parsing metadata"); + grub_util_info ("error parsing metadata\n"); #endif goto fail2; } - p = q = (char *)ptr; - - if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr)) - goto error_parsing_metadata; - - mda_end = (char *)ptr; - - while (*q != ' ' && q < mda_end) - q++; - - if (q == mda_end) - goto error_parsing_metadata; - vgname_len = q - p; vgname = grub_malloc (vgname_len + 1); if (!vgname) @@ -281,7 +230,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("couldn't find ID"); + grub_util_info ("couldn't find ID\n"); #endif goto fail3; } @@ -293,8 +242,6 @@ grub_lvm_detect (grub_disk_t disk, if (! vg) { - struct cache_lv *cache_lvs = NULL; - /* First time we see this volume group. We've to create the whole volume group structure. */ vg = grub_malloc (sizeof (*vg)); @@ -311,7 +258,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown extent size"); + grub_util_info ("unknown extent size\n"); #endif goto fail4; } @@ -359,7 +306,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown pe_start"); + grub_util_info ("unknown pe_start\n"); #endif goto pvs_fail; } @@ -368,7 +315,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("error parsing pe_start"); + grub_util_info ("error parsing pe_start\n"); #endif goto pvs_fail; } @@ -420,26 +367,8 @@ grub_lvm_detect (grub_disk_t disk, { const char *iptr; char *optr; - - /* - * This is kind of hard to read with our safe (but rather - * baroque) math primatives, but it boils down to: - * - * sz0 = vgname_len * 2 + 1 + - * s * 2 + 1 + - * sizeof ("lvm/") - 1; - */ - grub_size_t sz0 = vgname_len, sz1 = s; - - if (grub_mul (sz0, 2, &sz0) || - grub_add (sz0, 1, &sz0) || - grub_mul (sz1, 2, &sz1) || - grub_add (sz1, 1, &sz1) || - grub_add (sz0, sz1, &sz0) || - grub_add (sz0, sizeof ("lvm/") - 1, &sz0)) - goto lvs_fail; - - lv->fullname = grub_malloc (sz0); + lv->fullname = grub_malloc (sizeof ("lvm/") - 1 + 2 * vgname_len + + 1 + 2 * s + 1); if (!lv->fullname) goto lvs_fail; @@ -473,7 +402,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("couldn't find ID"); + grub_util_info ("couldn't find ID\n"); #endif goto lvs_fail; } @@ -493,11 +422,11 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown segment_count"); + grub_util_info ("unknown segment_count\n"); #endif goto lvs_fail; } - lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); + lv->segments = grub_malloc (sizeof (*seg) * lv->segment_count); seg = lv->segments; for (i = 0; i < lv->segment_count; i++) @@ -507,7 +436,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown segment"); + grub_util_info ("unknown segment\n"); #endif goto lvs_segment_fail; } @@ -516,7 +445,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown start_extent"); + grub_util_info ("unknown start_extent\n"); #endif goto lvs_segment_fail; } @@ -524,7 +453,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown extent_count"); + grub_util_info ("unknown extent_count\n"); #endif goto lvs_segment_fail; } @@ -546,7 +475,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown stripe_count"); + grub_util_info ("unknown stripe_count\n"); #endif goto lvs_segment_fail; } @@ -554,15 +483,15 @@ grub_lvm_detect (grub_disk_t disk, if (seg->node_count != 1) seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - seg->nodes = grub_calloc (seg->node_count, - sizeof (*stripe)); + seg->nodes = grub_zalloc (sizeof (*stripe) + * seg->node_count); stripe = seg->nodes; p = grub_strstr (p, "stripes = ["); if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown stripes"); + grub_util_info ("unknown stripes\n"); #endif goto lvs_segment_fail2; } @@ -604,7 +533,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown mirror_count"); + grub_util_info ("unknown mirror_count\n"); #endif goto lvs_segment_fail; } @@ -616,7 +545,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown mirrors"); + grub_util_info ("unknown mirrors\n"); #endif goto lvs_segment_fail2; } @@ -648,17 +577,13 @@ grub_lvm_detect (grub_disk_t disk, if (is_pvmove) seg->node_count = 1; } - else if (grub_memcmp (p, "raid", sizeof ("raid") - 1) == 0 - && ((p[sizeof ("raid") - 1] >= '4' - && p[sizeof ("raid") - 1] <= '6') - || p[sizeof ("raid") - 1] == '1') + else if (grub_memcmp (p, "raid", sizeof ("raid") - 1) + == 0 && (p[sizeof ("raid") - 1] >= '4' + && p[sizeof ("raid") - 1] <= '6') && p[sizeof ("raidX") - 1] == '"') { switch (p[sizeof ("raid") - 1]) { - case '1': - seg->type = GRUB_DISKFILTER_MIRROR; - break; case '4': seg->type = GRUB_DISKFILTER_RAID4; seg->layout = GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC; @@ -678,23 +603,21 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown device_count"); + grub_util_info ("unknown device_count\n"); #endif goto lvs_segment_fail; } - if (seg->type != GRUB_DISKFILTER_MIRROR) + seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + if (p == NULL) { - seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - if (p == NULL) - { #ifdef GRUB_UTIL - grub_util_info ("unknown stripe_size"); + grub_util_info ("unknown stripe_size\n"); #endif - goto lvs_segment_fail; - } + goto lvs_segment_fail; } + seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) * seg->node_count); @@ -702,7 +625,7 @@ grub_lvm_detect (grub_disk_t disk, if (p == NULL) { #ifdef GRUB_UTIL - grub_util_info ("unknown raids"); + grub_util_info ("unknown mirrors\n"); #endif goto lvs_segment_fail2; } @@ -742,106 +665,6 @@ grub_lvm_detect (grub_disk_t disk, seg->nodes[seg->node_count - 1].name = tmp; } } - else if (grub_memcmp (p, "cache\"", - sizeof ("cache\"") - 1) == 0) - { - struct cache_lv *cache = NULL; - - char *p2, *p3; - grub_size_t sz; - - cache = grub_zalloc (sizeof (*cache)); - if (!cache) - goto cache_lv_fail; - cache->lv = grub_zalloc (sizeof (*cache->lv)); - if (!cache->lv) - goto cache_lv_fail; - grub_memcpy (cache->lv, lv, sizeof (*cache->lv)); - - if (lv->fullname) - { - cache->lv->fullname = grub_strdup (lv->fullname); - if (!cache->lv->fullname) - goto cache_lv_fail; - } - if (lv->idname) - { - cache->lv->idname = grub_strdup (lv->idname); - if (!cache->lv->idname) - goto cache_lv_fail; - } - if (lv->name) - { - cache->lv->name = grub_strdup (lv->name); - if (!cache->lv->name) - goto cache_lv_fail; - } - - skip_lv = 1; - - p2 = grub_strstr (p, "cache_pool = \""); - if (!p2) - goto cache_lv_fail; - - p2 = grub_strchr (p2, '"'); - if (!p2) - goto cache_lv_fail; - - p3 = ++p2; - p3 = grub_strchr (p3, '"'); - if (!p3) - goto cache_lv_fail; - - sz = p3 - p2; - - cache->cache_pool = grub_malloc (sz + 1); - if (!cache->cache_pool) - goto cache_lv_fail; - grub_memcpy (cache->cache_pool, p2, sz); - cache->cache_pool[sz] = '\0'; - - p2 = grub_strstr (p, "origin = \""); - if (!p2) - goto cache_lv_fail; - - p2 = grub_strchr (p2, '"'); - if (!p2) - goto cache_lv_fail; - - p3 = ++p2; - p3 = grub_strchr (p3, '"'); - if (!p3) - goto cache_lv_fail; - - sz = p3 - p2; - - cache->origin = grub_malloc (sz + 1); - if (!cache->origin) - goto cache_lv_fail; - grub_memcpy (cache->origin, p2, sz); - cache->origin[sz] = '\0'; - - cache->next = cache_lvs; - cache_lvs = cache; - break; - - cache_lv_fail: - if (cache) - { - grub_free (cache->origin); - grub_free (cache->cache_pool); - if (cache->lv) - { - grub_free (cache->lv->fullname); - grub_free (cache->lv->idname); - grub_free (cache->lv->name); - } - grub_free (cache->lv); - grub_free (cache); - } - grub_lvm_free_cache_lvs (cache_lvs); - goto fail4; - } else { #ifdef GRUB_UTIL @@ -849,7 +672,7 @@ grub_lvm_detect (grub_disk_t disk, p2 = grub_strchr (p, '"'); if (p2) *p2 = 0; - grub_util_info ("unknown LVM type %s", p); + grub_util_info ("unknown LVM type %s\n", p); if (p2) *p2 ='"'; #endif @@ -918,58 +741,6 @@ grub_lvm_detect (grub_disk_t disk, } } - - { - struct cache_lv *cache; - - for (cache = cache_lvs; cache; cache = cache->next) - { - struct grub_diskfilter_lv *lv; - - for (lv = vg->lvs; lv; lv = lv->next) - if (grub_strcmp (lv->name, cache->origin) == 0) - break; - if (lv) - { - cache->lv->segments = grub_calloc (lv->segment_count, sizeof (*lv->segments)); - if (!cache->lv->segments) - { - grub_lvm_free_cache_lvs (cache_lvs); - goto fail4; - } - grub_memcpy (cache->lv->segments, lv->segments, lv->segment_count * sizeof (*lv->segments)); - - for (i = 0; i < lv->segment_count; ++i) - { - struct grub_diskfilter_node *nodes = lv->segments[i].nodes; - grub_size_t node_count = lv->segments[i].node_count; - - cache->lv->segments[i].nodes = grub_calloc (node_count, sizeof (*nodes)); - if (!cache->lv->segments[i].nodes) - { - for (j = 0; j < i; ++j) - grub_free (cache->lv->segments[j].nodes); - grub_free (cache->lv->segments); - cache->lv->segments = NULL; - grub_lvm_free_cache_lvs (cache_lvs); - goto fail4; - } - grub_memcpy (cache->lv->segments[i].nodes, nodes, node_count * sizeof (*nodes)); - } - - if (cache->lv->segments) - { - cache->lv->segment_count = lv->segment_count; - cache->lv->vg = vg; - cache->lv->next = vg->lvs; - vg->lvs = cache->lv; - cache->lv = NULL; - } - } - } - } - - grub_lvm_free_cache_lvs (cache_lvs); if (grub_diskfilter_vg_register (vg)) goto fail4; } diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index c980feba4..7cc80d3df 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -178,7 +178,7 @@ grub_mdraid_detect (grub_disk_t disk, return NULL; if (grub_disk_read (disk, sector, - (char *) (sb.dev_roles + grub_le_to_cpu32 (sb.dev_number)) + (char *) &sb.dev_roles[grub_le_to_cpu32 (sb.dev_number)] - (char *) &sb, sizeof (role), &role)) return NULL; diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index 613779cf3..e5ffc01bf 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -77,11 +77,11 @@ static struct grub_disk_dev grub_memdisk_dev = { .name = "memdisk", .id = GRUB_DISK_DEVICE_MEMDISK_ID, - .disk_iterate = grub_memdisk_iterate, - .disk_open = grub_memdisk_open, - .disk_close = grub_memdisk_close, - .disk_read = grub_memdisk_read, - .disk_write = grub_memdisk_write, + .iterate = grub_memdisk_iterate, + .open = grub_memdisk_open, + .close = grub_memdisk_close, + .read = grub_memdisk_read, + .write = grub_memdisk_write, .next = 0 }; diff --git a/grub-core/disk/raid6_recover.c b/grub-core/disk/raid6_recover.c index 75fe464a4..f9ec632fb 100644 --- a/grub-core/disk/raid6_recover.c +++ b/grub-core/disk/raid6_recover.c @@ -63,37 +63,15 @@ grub_raid6_init_table (void) } } -static unsigned -mod_255 (unsigned x) -{ - while (x > 0xff) - x = (x >> 8) + (x & 0xff); - if (x == 0xff) - return 0; - return x; -} - static grub_err_t -raid6_recover_read_node (void *data, int disknr, - grub_uint64_t sector, - void *buf, grub_size_t size) -{ - struct grub_diskfilter_segment *array = data; - - return grub_diskfilter_read_node (&array->nodes[disknr], - (grub_disk_addr_t)sector, - size >> GRUB_DISK_SECTOR_BITS, buf); -} - -grub_err_t -grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, - char *buf, grub_uint64_t sector, grub_size_t size, - int layout, raid_recover_read_t read_func) +grub_raid6_recover (struct grub_diskfilter_segment *array, int disknr, int p, + char *buf, grub_disk_addr_t sector, grub_size_t size) { int i, q, pos; int bad1 = -1, bad2 = -1; char *pbuf = 0, *qbuf = 0; + size <<= GRUB_DISK_SECTOR_BITS; pbuf = grub_zalloc (size); if (!pbuf) goto quit; @@ -103,17 +81,17 @@ grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, goto quit; q = p + 1; - if (q == (int) nstripes) + if (q == (int) array->node_count) q = 0; pos = q + 1; - if (pos == (int) nstripes) + if (pos == (int) array->node_count) pos = 0; - for (i = 0; i < (int) nstripes - 2; i++) + for (i = 0; i < (int) array->node_count - 2; i++) { int c; - if (layout & GRUB_RAID_LAYOUT_MUL_FROM_POS) + if (array->layout & GRUB_RAID_LAYOUT_MUL_FROM_POS) c = pos; else c = i; @@ -121,7 +99,8 @@ grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, bad1 = c; else { - if (!read_func (data, pos, sector, buf, size)) + if (! grub_diskfilter_read_node (&array->nodes[pos], sector, + size >> GRUB_DISK_SECTOR_BITS, buf)) { grub_crypto_xor (pbuf, pbuf, buf, size); grub_raid_block_mulx (c, buf, size); @@ -139,7 +118,7 @@ grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, } pos++; - if (pos == (int) nstripes) + if (pos == (int) array->node_count) pos = 0; } @@ -150,14 +129,16 @@ grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, if (bad2 < 0) { /* One bad device */ - if (!read_func (data, p, sector, buf, size)) + if ((! grub_diskfilter_read_node (&array->nodes[p], sector, + size >> GRUB_DISK_SECTOR_BITS, buf))) { grub_crypto_xor (buf, buf, pbuf, size); goto quit; } grub_errno = GRUB_ERR_NONE; - if (read_func (data, q, sector, buf, size)) + if (grub_diskfilter_read_node (&array->nodes[q], sector, + size >> GRUB_DISK_SECTOR_BITS, buf)) goto quit; grub_crypto_xor (buf, buf, qbuf, size); @@ -169,21 +150,23 @@ grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, /* Two bad devices */ unsigned c; - if (read_func (data, p, sector, buf, size)) + if (grub_diskfilter_read_node (&array->nodes[p], sector, + size >> GRUB_DISK_SECTOR_BITS, buf)) goto quit; grub_crypto_xor (pbuf, pbuf, buf, size); - if (read_func (data, q, sector, buf, size)) + if (grub_diskfilter_read_node (&array->nodes[q], sector, + size >> GRUB_DISK_SECTOR_BITS, buf)) goto quit; grub_crypto_xor (qbuf, qbuf, buf, size); - c = mod_255((255 ^ bad1) - + (255 ^ powx_inv[(powx[bad2 + (bad1 ^ 255)] ^ 1)])); + c = ((255 ^ bad1) + + (255 ^ powx_inv[(powx[bad2 + (bad1 ^ 255)] ^ 1)])) % 255; grub_raid_block_mulx (c, qbuf, size); - c = mod_255((unsigned) bad2 + c); + c = ((unsigned) bad2 + c) % 255; grub_raid_block_mulx (c, pbuf, size); grub_crypto_xor (pbuf, pbuf, qbuf, size); @@ -197,15 +180,6 @@ quit: return grub_errno; } -static grub_err_t -grub_raid6_recover (struct grub_diskfilter_segment *array, int disknr, int p, - char *buf, grub_disk_addr_t sector, grub_size_t size) -{ - return grub_raid6_recover_gen (array, array->node_count, disknr, p, buf, - sector, size << GRUB_DISK_SECTOR_BITS, - array->layout, raid6_recover_read_node); -} - GRUB_MOD_INIT(raid6rec) { grub_raid6_init_table (); diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 70767cf00..92084d0f8 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -615,10 +615,9 @@ grub_scsi_open (const char *name, grub_disk_t disk) if (scsi->blocksize & (scsi->blocksize - 1) || !scsi->blocksize) { - grub_error (GRUB_ERR_IO, "invalid sector size %d", - scsi->blocksize); grub_free (scsi); - return grub_errno; + return grub_error (GRUB_ERR_IO, "invalid sector size %d", + scsi->blocksize); } for (disk->log_sector_size = 0; (1U << disk->log_sector_size) < scsi->blocksize; @@ -747,11 +746,11 @@ static struct grub_disk_dev grub_scsi_dev = { .name = "scsi", .id = GRUB_DISK_DEVICE_SCSI_ID, - .disk_iterate = grub_scsi_iterate, - .disk_open = grub_scsi_open, - .disk_close = grub_scsi_close, - .disk_read = grub_scsi_read, - .disk_write = grub_scsi_write, + .iterate = grub_scsi_iterate, + .open = grub_scsi_open, + .close = grub_scsi_close, + .read = grub_scsi_read, + .write = grub_scsi_write, .next = 0 }; diff --git a/grub-core/disk/uboot/ubootdisk.c b/grub-core/disk/uboot/ubootdisk.c index 2d115a94d..a5ce07a99 100644 --- a/grub-core/disk/uboot/ubootdisk.c +++ b/grub-core/disk/uboot/ubootdisk.c @@ -264,33 +264,23 @@ uboot_disk_read (struct grub_disk *disk, } static grub_err_t -uboot_disk_write (struct grub_disk *disk, - grub_disk_addr_t offset, grub_size_t numblocks, const char *buf) +uboot_disk_write (struct grub_disk *disk __attribute__ ((unused)), + grub_disk_addr_t sector __attribute__ ((unused)), + grub_size_t size __attribute__ ((unused)), + const char *buf __attribute__ ((unused))) { - struct ubootdisk_data *d; - int retval; - - d = disk->data; - - retval = grub_uboot_dev_write (d->dev, buf, numblocks, offset); - grub_dprintf ("ubootdisk", - "retval=%d, numblocks=%d, sector=%llu\n", - retval, numblocks, (grub_uint64_t) offset); - - if (retval != 0) - return grub_error (GRUB_ERR_IO, "U-Boot disk write error"); - - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "attempt to write (not supported)"); } static struct grub_disk_dev grub_ubootdisk_dev = { .name = "ubootdisk", .id = GRUB_DISK_DEVICE_UBOOTDISK_ID, - .disk_iterate = uboot_disk_iterate, - .disk_open = uboot_disk_open, - .disk_close = uboot_disk_close, - .disk_read = uboot_disk_read, - .disk_write = uboot_disk_write, + .iterate = uboot_disk_iterate, + .open = uboot_disk_open, + .close = uboot_disk_close, + .read = uboot_disk_read, + .write = uboot_disk_write, .next = 0 }; diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c index d6612eebd..2b11c2a2e 100644 --- a/grub-core/disk/xen/xendisk.c +++ b/grub-core/disk/xen/xendisk.c @@ -40,7 +40,6 @@ struct virtdisk grub_xen_evtchn_t evtchn; void *dma_page; grub_xen_grant_t dma_grant; - struct virtdisk *compat_next; }; #define xen_wmb() mb() @@ -48,7 +47,6 @@ struct virtdisk static struct virtdisk *virtdisks; static grub_size_t vdiskcnt; -struct virtdisk *compat_head; static int grub_virtdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, @@ -68,32 +66,20 @@ grub_virtdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, static grub_err_t grub_virtdisk_open (const char *name, grub_disk_t disk) { - int i; + grub_size_t i; grub_uint32_t secsize; char fdir[200]; char *buf; - int num = -1; - struct virtdisk *vd; - /* For compatibility with pv-grub legacy menu.lst accept hdX as disk name */ - if (name[0] == 'h' && name[1] == 'd' && name[2]) - { - num = grub_strtoul (name + 2, 0, 10); - if (grub_errno) - { - grub_errno = 0; - num = -1; - } - } - for (i = 0, vd = compat_head; vd; vd = vd->compat_next, i++) - if (i == num || grub_strcmp (name, vd->fullname) == 0) + for (i = 0; i < vdiskcnt; i++) + if (grub_strcmp (name, virtdisks[i].fullname) == 0) break; - if (!vd) + if (i == vdiskcnt) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a virtdisk"); - disk->data = vd; - disk->id = vd - virtdisks; + disk->data = &virtdisks[i]; + disk->id = i; - grub_snprintf (fdir, sizeof (fdir), "%s/sectors", vd->backend_dir); + grub_snprintf (fdir, sizeof (fdir), "%s/sectors", virtdisks[i].backend_dir); buf = grub_xenstore_get_file (fdir, NULL); if (!buf) return grub_errno; @@ -101,7 +87,8 @@ grub_virtdisk_open (const char *name, grub_disk_t disk) if (grub_errno) return grub_errno; - grub_snprintf (fdir, sizeof (fdir), "%s/sector-size", vd->backend_dir); + grub_snprintf (fdir, sizeof (fdir), "%s/sector-size", + virtdisks[i].backend_dir); buf = grub_xenstore_get_file (fdir, NULL); if (!buf) return grub_errno; @@ -249,11 +236,11 @@ grub_virtdisk_write (grub_disk_t disk, grub_disk_addr_t sector, static struct grub_disk_dev grub_virtdisk_dev = { .name = "xen", .id = GRUB_DISK_DEVICE_XEN, - .disk_iterate = grub_virtdisk_iterate, - .disk_open = grub_virtdisk_open, - .disk_close = grub_virtdisk_close, - .disk_read = grub_virtdisk_read, - .disk_write = grub_virtdisk_write, + .iterate = grub_virtdisk_iterate, + .open = grub_virtdisk_open, + .close = grub_virtdisk_close, + .read = grub_virtdisk_read, + .write = grub_virtdisk_write, .next = 0 }; @@ -277,7 +264,6 @@ fill (const char *dir, void *data) grub_err_t err; void *buf; struct evtchn_alloc_unbound alloc_unbound; - struct virtdisk **prev = &compat_head, *vd = compat_head; /* Shouldn't happen unles some hotplug happened. */ if (vdiskcnt >= *ctr) @@ -388,19 +374,6 @@ fill (const char *dir, void *data) virtdisks[vdiskcnt].frontend_dir = grub_strdup (fdir); - /* For compatibility with pv-grub maintain linked list sorted by handle - value in increasing order. This allows mapping of (hdX) disk names - from legacy menu.lst */ - while (vd) - { - if (vd->handle > virtdisks[vdiskcnt].handle) - break; - prev = &vd->compat_next; - vd = vd->compat_next; - } - virtdisks[vdiskcnt].compat_next = vd; - *prev = &virtdisks[vdiskcnt]; - vdiskcnt++; return 0; @@ -426,7 +399,7 @@ grub_xendisk_init (void) if (!ctr) return; - virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); + virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); if (!virtdisks) return; if (grub_xenstore_dir ("device/vbd", fill, &ctr)) diff --git a/grub-core/efiemu/i386/loadcore64.c b/grub-core/efiemu/i386/loadcore64.c index 18facf47f..e49d0b6ff 100644 --- a/grub-core/efiemu/i386/loadcore64.c +++ b/grub-core/efiemu/i386/loadcore64.c @@ -98,7 +98,6 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs, break; case R_X86_64_PC32: - case R_X86_64_PLT32: err = grub_efiemu_write_value (addr, *addr32 + rel->r_addend + sym.off diff --git a/grub-core/efiemu/i386/pc/cfgtables.c b/grub-core/efiemu/i386/pc/cfgtables.c index e5fffb7d4..492c07c46 100644 --- a/grub-core/efiemu/i386/pc/cfgtables.c +++ b/grub-core/efiemu/i386/pc/cfgtables.c @@ -22,11 +22,11 @@ #include #include #include -#include grub_err_t grub_machine_efiemu_init_tables (void) { + grub_uint8_t *ptr; void *table; grub_err_t err; grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID; @@ -57,10 +57,17 @@ grub_machine_efiemu_init_tables (void) if (err) return err; } - table = grub_smbios_get_eps (); - if (table) + + for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; + ptr += 16) + if (grub_memcmp (ptr, "_SM_", 4) == 0 + && grub_byte_checksum (ptr, *(ptr + 5)) == 0) + break; + + if (ptr < (grub_uint8_t *) 0x100000) { - err = grub_efiemu_register_configuration_table (smbios, 0, 0, table); + grub_dprintf ("efiemu", "Registering SMBIOS\n"); + err = grub_efiemu_register_configuration_table (smbios, 0, 0, ptr); if (err) return err; } diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c index 2b924623f..6968b3719 100644 --- a/grub-core/efiemu/loadcore.c +++ b/grub-core/efiemu/loadcore.c @@ -154,10 +154,7 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e) s->sh_flags & SHF_EXECINSTR ? GRUB_EFI_RUNTIME_SERVICES_CODE : GRUB_EFI_RUNTIME_SERVICES_DATA); if (seg->handle < 0) - { - grub_free (seg); - return grub_errno; - } + return grub_errno; seg->off = 0; } @@ -201,7 +198,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) - grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); + grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); /* Relocators */ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); @@ -346,7 +343,7 @@ SUFFIX (grub_efiemu_loadcore_init) (void *core, const char *filename, return grub_error (GRUB_ERR_BAD_MODULE, N_("this ELF file is not of the right type")); /* Make sure that every section is within the core. */ - if ((grub_size_t) core_size < e->e_shoff + (grub_uint32_t) e->e_shentsize * e->e_shnum) + if ((grub_size_t) core_size < e->e_shoff + e->e_shentsize * e->e_shnum) return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), filename); diff --git a/grub-core/efiemu/main.c b/grub-core/efiemu/main.c index a81934725..f2140ad29 100644 --- a/grub-core/efiemu/main.c +++ b/grub-core/efiemu/main.c @@ -187,7 +187,7 @@ grub_efiemu_load_file (const char *filename) grub_file_t file; grub_err_t err; - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); + file = grub_file_open (filename); if (! file) return grub_errno; @@ -196,7 +196,7 @@ grub_efiemu_load_file (const char *filename) { grub_file_close (file); grub_efiemu_unload (); - return err; + return grub_errno; } grub_dprintf ("efiemu", "mm initialized\n"); diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c index 9b8e0d0ad..d4a4f3aad 100644 --- a/grub-core/efiemu/mm.c +++ b/grub-core/efiemu/mm.c @@ -99,8 +99,7 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size, grub_size_t align_overhead; struct grub_efiemu_memrequest *ret, *cur, *prev; /* Check that the request is correct */ - if (type <= GRUB_EFI_LOADER_CODE || type == GRUB_EFI_PERSISTENT_MEMORY || - type >= GRUB_EFI_MAX_MEMORY_TYPE) + if (type >= GRUB_EFI_MAX_MEMORY_TYPE || type <= GRUB_EFI_LOADER_CODE) return -2; /* Add new size to requested size */ @@ -167,13 +166,6 @@ efiemu_alloc_requests (void) GRUB_EFI_MEMORY_MAPPED_IO, GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE, GRUB_EFI_PAL_CODE - - /* - * These are not allocatable: - * GRUB_EFI_RESERVED_MEMORY_TYPE - * GRUB_EFI_PERSISTENT_MEMORY - * >= GRUB_EFI_MAX_MEMORY_TYPE - */ }; /* Compute total memory needed */ @@ -410,14 +402,9 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, return grub_efiemu_add_to_mmap (addr, size, GRUB_EFI_ACPI_MEMORY_NVS); - case GRUB_MEMORY_PERSISTENT: - case GRUB_MEMORY_PERSISTENT_LEGACY: - return grub_efiemu_add_to_mmap (addr, size, - GRUB_EFI_PERSISTENT_MEMORY); default: grub_dprintf ("efiemu", "Unknown memory type %d. Assuming unusable\n", type); - /* FALLTHROUGH */ case GRUB_MEMORY_RESERVED: return grub_efiemu_add_to_mmap (addr, size, GRUB_EFI_UNUSABLE_MEMORY); @@ -458,7 +445,7 @@ grub_efiemu_mmap_iterate (grub_memory_hook_t hook, void *hook_data) case GRUB_EFI_MEMORY_MAPPED_IO: case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE: case GRUB_EFI_PAL_CODE: - default: + case GRUB_EFI_MAX_MEMORY_TYPE: hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, GRUB_MEMORY_RESERVED, hook_data); break; @@ -481,12 +468,6 @@ grub_efiemu_mmap_iterate (grub_memory_hook_t hook, void *hook_data) hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, GRUB_MEMORY_NVS, hook_data); break; - - case GRUB_EFI_PERSISTENT_MEMORY: - hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, - GRUB_MEMORY_PERSISTENT, hook_data); - break; - } return 0; @@ -522,8 +503,7 @@ grub_efiemu_mmap_sort_and_uniq (void) [GRUB_EFI_ACPI_MEMORY_NVS] = 3, [GRUB_EFI_MEMORY_MAPPED_IO] = 4, [GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE] = 4, - [GRUB_EFI_PAL_CODE] = 4, - [GRUB_EFI_PERSISTENT_MEMORY] = 4 + [GRUB_EFI_PAL_CODE] = 4 }; int i, j, k, done; @@ -554,11 +534,11 @@ grub_efiemu_mmap_sort_and_uniq (void) /* Initialize variables*/ grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); scanline_events = (struct grub_efiemu_mmap_scan *) - grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); + grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); /* Number of chunks can't increase more than by factor of 2 */ result = (grub_efi_memory_descriptor_t *) - grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); + grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); if (!result || !scanline_events) { grub_free (result); @@ -660,7 +640,7 @@ grub_efiemu_mm_do_alloc (void) /* Preallocate mmap */ efiemu_mmap = (grub_efi_memory_descriptor_t *) - grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); + grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); if (!efiemu_mmap) { grub_efiemu_unload (); diff --git a/grub-core/efiemu/pnvram.c b/grub-core/efiemu/pnvram.c index dd42bc691..c5c3d4bd3 100644 --- a/grub-core/efiemu/pnvram.c +++ b/grub-core/efiemu/pnvram.c @@ -39,7 +39,7 @@ static grub_size_t nvramsize; /* Parse signed value */ static int -grub_strtosl (const char *arg, const char ** const end, int base) +grub_strtosl (const char *arg, char **end, int base) { if (arg[0] == '-') return -grub_strtoul (arg + 1, end, base); @@ -120,8 +120,7 @@ nvram_set (void * data __attribute__ ((unused))) grub_memset (nvram, 0, nvramsize); FOR_SORTED_ENV (var) { - const char *guid; - char *attr, *name, *varname; + char *guid, *attr, *name, *varname; struct efi_variable *efivar; int len = 0; int i; diff --git a/grub-core/efiemu/prepare.c b/grub-core/efiemu/prepare.c index 99ddb5abb..84c3368a8 100644 --- a/grub-core/efiemu/prepare.c +++ b/grub-core/efiemu/prepare.c @@ -83,16 +83,10 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks, ((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off); /* Put pointer to the list of configuration tables in system table */ - err = grub_efiemu_write_value - (&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0, - conftable_handle, 0, 1, - sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table)); - if (err) - { - grub_efiemu_unload (); - return err; - } - + grub_efiemu_write_value + (&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0, + conftable_handle, 0, 1, + sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table)); SUFFIX(grub_efiemu_system_table)->num_table_entries = cntconftables; /* Fill the list of configuration tables */ diff --git a/grub-core/efiemu/runtime/efiemu.c b/grub-core/efiemu/runtime/efiemu.c index 5db1f347b..d923e409f 100644 --- a/grub-core/efiemu/runtime/efiemu.c +++ b/grub-core/efiemu/runtime/efiemu.c @@ -174,17 +174,17 @@ efiemu_memset (grub_uint8_t *a, grub_uint8_t b, grub_size_t n) static inline void write_cmos (grub_uint8_t addr, grub_uint8_t val) { - asm volatile ("outb %%al,$0x70\n" - "mov %%cl, %%al\n" - "outb %%al,$0x71": :"a" (addr), "c" (val)); + __asm__ __volatile__ ("outb %%al,$0x70\n" + "mov %%cl, %%al\n" + "outb %%al,$0x71": :"a" (addr), "c" (val)); } static inline grub_uint8_t read_cmos (grub_uint8_t addr) { grub_uint8_t ret; - asm volatile ("outb %%al, $0x70\n" - "inb $0x71, %%al": "=a"(ret) :"a" (addr)); + __asm__ __volatile__ ("outb %%al, $0x70\n" + "inb $0x71, %%al": "=a"(ret) :"a" (addr)); return ret; } diff --git a/grub-core/font/font.c b/grub-core/font/font.c index d09bb38d8..14b93e172 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -30,7 +30,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -294,7 +293,8 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; /* Allocate the character index array. */ - font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); + font->char_index = grub_malloc (font->num_chars + * sizeof (struct char_index_entry)); if (!font->char_index) return 1; font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); @@ -361,13 +361,9 @@ static char * read_section_as_string (struct font_file_section *section) { char *str; - grub_size_t sz; grub_ssize_t ret; - if (grub_add (section->length, 1, &sz)) - return NULL; - - str = grub_malloc (sz); + str = grub_malloc (section->length + 1); if (!str) return 0; @@ -422,7 +418,7 @@ grub_font_load (const char *filename) #endif if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+') - file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024); + file = grub_buffile_open (filename, 1024); else { const char *prefix = grub_env_get ("prefix"); @@ -442,7 +438,7 @@ grub_font_load (const char *filename) ptr = grub_stpcpy (ptr, filename); ptr = grub_stpcpy (ptr, ".pf2"); *ptr = 0; - file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024); + file = grub_buffile_open (fullname, 1024); grub_free (fullname); } if (!file) @@ -532,12 +528,6 @@ grub_font_load (const char *filename) if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) { - if (font->name != NULL) - { - grub_error (GRUB_ERR_BAD_FONT, "invalid font file: too many NAME sections"); - goto fail; - } - font->name = read_section_as_string (§ion); if (!font->name) goto fail; @@ -787,7 +777,6 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code) if (grub_file_read (font->file, glyph->bitmap, len) != len) { remove_font (font); - grub_free (glyph); return 0; } } @@ -1296,7 +1285,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id, - grub_font_get_xheight (combining_glyphs[i]->font) - 1; if (space <= 0) space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8; - /* Fallthrough. */ + case GRUB_UNICODE_STACK_ATTACHED_ABOVE: do_blit (combining_glyphs[i], targetx, -(ctx.bounds.height + ctx.bounds.y + space @@ -1337,7 +1326,6 @@ blit_comb (const struct grub_unicode_glyph *glyph_id, + combining_glyphs[i]->height); if (space <= 0) space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8; - /* Fallthrough. */ case GRUB_UNICODE_STACK_ATTACHED_BELOW: do_blit (combining_glyphs[i], targetx, -(ctx.bounds.y - space), diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c index 220b3712f..f673897e0 100644 --- a/grub-core/fs/affs.c +++ b/grub-core/fs/affs.c @@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) return 0; } latin1[symlink_size] = 0; - utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); + utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); if (!utf8) { grub_free (latin1); @@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, return 1; } - hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); + hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); if (!hashtable) return 1; @@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) len = file.namelen; if (len > sizeof (file.name)) len = sizeof (file.name); - *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); + *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); if (*label) *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; } @@ -685,12 +685,12 @@ grub_affs_mtime (grub_device_t device, grub_int32_t *t) static struct grub_fs grub_affs_fs = { .name = "affs", - .fs_dir = grub_affs_dir, - .fs_open = grub_affs_open, - .fs_read = grub_affs_read, - .fs_close = grub_affs_close, - .fs_label = grub_affs_label, - .fs_mtime = grub_affs_mtime, + .dir = grub_affs_dir, + .open = grub_affs_open, + .read = grub_affs_read, + .close = grub_affs_close, + .label = grub_affs_label, + .mtime = grub_affs_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 0, diff --git a/grub-core/fs/archelp.c b/grub-core/fs/archelp.c index 0cf544f6f..c85cbfac2 100644 --- a/grub-core/fs/archelp.c +++ b/grub-core/fs/archelp.c @@ -34,12 +34,12 @@ canonicalize (char *name) iptr++; if (iptr[0] == '.' && (iptr[1] == '/' || iptr[1] == 0)) { - iptr++; + iptr += 2; continue; } if (iptr[0] == '.' && iptr[1] == '.' && (iptr[2] == '/' || iptr[2] == 0)) { - iptr += 2; + iptr += 3; if (optr == name) continue; for (optr -= 2; optr >= name && *optr != '/'; optr--); @@ -249,10 +249,9 @@ grub_archelp_open (struct grub_archelp_data *data, while (1) { grub_uint32_t mode; - grub_int32_t mtime; int restart; - if (arcops->find_file (data, &fn, &mtime, &mode)) + if (arcops->find_file (data, &fn, NULL, &mode)) goto fail; if (mode == GRUB_ARCHELP_ATTR_END) diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c index 47dbe2011..145e77186 100644 --- a/grub-core/fs/bfs.c +++ b/grub-core/fs/bfs.c @@ -29,7 +29,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -562,10 +561,10 @@ iterate_in_b_tree (grub_disk_t disk, } static int -bfs_strcmp (const char *a, const char *b, grub_size_t alen) +bfs_strcmp (const char *a, const char *b, grub_size_t alen, grub_size_t blen) { char ac, bc; - while (*b && alen) + while (blen && alen) { if (*a != *b) break; @@ -573,10 +572,11 @@ bfs_strcmp (const char *a, const char *b, grub_size_t alen) a++; b++; alen--; + blen--; } ac = alen ? *a : 0; - bc = *b; + bc = blen ? *b : 0; #ifdef MODE_AFS return (int) (grub_int8_t) ac - (int) (grub_int8_t) bc; @@ -589,6 +589,7 @@ static grub_err_t find_in_b_tree (grub_disk_t disk, const struct grub_bfs_superblock *sb, const struct grub_bfs_inode *ino, const char *name, + grub_size_t name_len, grub_uint64_t * res) { struct grub_bfs_btree_header head; @@ -636,7 +637,7 @@ find_in_b_tree (grub_disk_t disk, end = grub_bfs_to_cpu16 (keylen_idx[(i | (1 << j))]); if (grub_bfs_to_cpu_treehead (node->total_key_len) <= end) end = grub_bfs_to_cpu_treehead (node->total_key_len); - cmp = bfs_strcmp (key_data + start, name, end - start); + cmp = bfs_strcmp (key_data + start, name, end - start, name_len); if (cmp == 0 && level == 0) { *res = grub_bfs_to_cpu64 (key_values[i | (1 << j)].val); @@ -657,7 +658,7 @@ find_in_b_tree (grub_disk_t disk, end = grub_bfs_to_cpu16 (keylen_idx[0]); if (grub_bfs_to_cpu_treehead (node->total_key_len) <= end) end = grub_bfs_to_cpu_treehead (node->total_key_len); - cmp = bfs_strcmp (key_data, name, end); + cmp = bfs_strcmp (key_data, name, end, name_len); if (cmp == 0 && level == 0) { *res = grub_bfs_to_cpu64 (key_values[0].val); @@ -706,119 +707,127 @@ find_in_b_tree (grub_disk_t disk, } } -struct grub_fshelp_node -{ - grub_disk_t disk; - const struct grub_bfs_superblock *sb; - struct grub_bfs_inode ino; -}; - static grub_err_t -lookup_file (grub_fshelp_node_t dir, - const char *name, - grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype) +hop_level (grub_disk_t disk, + const struct grub_bfs_superblock *sb, + struct grub_bfs_inode *ino, const char *name, + const char *name_end) { grub_err_t err; - struct grub_bfs_inode *new_ino; grub_uint64_t res = 0; - err = find_in_b_tree (dir->disk, dir->sb, &dir->ino, name, &res); + if (((grub_bfs_to_cpu32 (ino->mode) & ATTR_TYPE) != ATTR_DIR)) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + + err = find_in_b_tree (disk, sb, ino, name, name_end - name, &res); if (err) return err; - *foundnode = grub_malloc (sizeof (struct grub_fshelp_node)); - if (!*foundnode) - return grub_errno; - - (*foundnode)->disk = dir->disk; - (*foundnode)->sb = dir->sb; - new_ino = &(*foundnode)->ino; - - if (grub_disk_read (dir->disk, res - << (grub_bfs_to_cpu32 (dir->sb->log2_bsize) - - GRUB_DISK_SECTOR_BITS), 0, - sizeof (*new_ino), (char *) new_ino)) - { - grub_free (*foundnode); - return grub_errno; - } - switch (grub_bfs_to_cpu32 (new_ino->mode) & ATTR_TYPE) - { - default: - case ATTR_REG: - *foundtype = GRUB_FSHELP_REG; - break; - case ATTR_DIR: - *foundtype = GRUB_FSHELP_DIR; - break; - case ATTR_LNK: - *foundtype = GRUB_FSHELP_SYMLINK; - break; - } - return GRUB_ERR_NONE; -} - -static char * -read_symlink (grub_fshelp_node_t node) -{ - char *alloc = NULL; - grub_err_t err; - -#ifndef MODE_AFS - if (!(grub_bfs_to_cpu32 (node->ino.flags) & LONG_SYMLINK)) - { - alloc = grub_malloc (sizeof (node->ino.inplace_link) + 1); - if (!alloc) - { - return NULL; - } - grub_memcpy (alloc, node->ino.inplace_link, - sizeof (node->ino.inplace_link)); - alloc[sizeof (node->ino.inplace_link)] = 0; - } - else -#endif - { - grub_size_t symsize = grub_bfs_to_cpu64 (node->ino.size); - alloc = grub_malloc (symsize + 1); - if (!alloc) - return NULL; - err = read_bfs_file (node->disk, node->sb, &node->ino, 0, alloc, symsize, 0, 0); - if (err) - { - grub_free (alloc); - return NULL; - } - alloc[symsize] = 0; - } - - return alloc; + return grub_disk_read (disk, res + << (grub_bfs_to_cpu32 (sb->log2_bsize) + - GRUB_DISK_SECTOR_BITS), 0, + sizeof (*ino), (char *) ino); } static grub_err_t find_file (const char *path, grub_disk_t disk, - const struct grub_bfs_superblock *sb, struct grub_bfs_inode *ino, - enum grub_fshelp_filetype exptype) + const struct grub_bfs_superblock *sb, struct grub_bfs_inode *ino) { + const char *ptr, *next = path; + char *alloc = NULL; + char *wptr; grub_err_t err; - struct grub_fshelp_node root = { - .disk = disk, - .sb = sb, - }; - struct grub_fshelp_node *found; + struct grub_bfs_inode old_ino; + unsigned symlinks_max = 32; - err = read_extent (disk, sb, &sb->root_dir, 0, 0, &root.ino, - sizeof (root.ino)); + err = read_extent (disk, sb, &sb->root_dir, 0, 0, ino, + sizeof (*ino)); if (err) return err; - err = grub_fshelp_find_file_lookup (path, &root, &found, lookup_file, read_symlink, exptype); - if (!err) - grub_memcpy (ino, &found->ino, sizeof (*ino)); - if (&root != found) - grub_free (found); - return err; + while (1) + { + ptr = next; + while (*ptr == '/') + ptr++; + if (*ptr == 0) + { + grub_free (alloc); + return GRUB_ERR_NONE; + } + for (next = ptr; *next && *next != '/'; next++); + grub_memcpy (&old_ino, ino, sizeof (old_ino)); + err = hop_level (disk, sb, ino, ptr, next); + if (err) + return err; + + if (((grub_bfs_to_cpu32 (ino->mode) & ATTR_TYPE) == ATTR_LNK)) + { + char *old_alloc = alloc; + if (--symlinks_max == 0) + { + grub_free (alloc); + return grub_error (GRUB_ERR_SYMLINK_LOOP, + N_("too deep nesting of symlinks")); + } + +#ifndef MODE_AFS + if (grub_bfs_to_cpu32 (ino->flags) & LONG_SYMLINK) +#endif + { + grub_size_t symsize = grub_bfs_to_cpu64 (ino->size); + alloc = grub_malloc (grub_strlen (next) + + symsize + 1); + if (!alloc) + { + grub_free (alloc); + return grub_errno; + } + grub_free (old_alloc); + err = read_bfs_file (disk, sb, ino, 0, alloc, symsize, 0, 0); + if (err) + { + grub_free (alloc); + return err; + } + alloc[symsize] = 0; + } +#ifndef MODE_AFS + else + { + alloc = grub_malloc (grub_strlen (next) + + sizeof (ino->inplace_link) + 1); + if (!alloc) + { + grub_free (alloc); + return grub_errno; + } + grub_free (old_alloc); + grub_memcpy (alloc, ino->inplace_link, + sizeof (ino->inplace_link)); + alloc[sizeof (ino->inplace_link)] = 0; + } +#endif + if (alloc[0] == '/') + { + err = read_extent (disk, sb, &sb->root_dir, 0, 0, ino, + sizeof (*ino)); + if (err) + { + grub_free (alloc); + return err; + } + } + else + grub_memcpy (ino, &old_ino, sizeof (old_ino)); + wptr = alloc + grub_strlen (alloc); + if (next) + wptr = grub_stpcpy (wptr, next); + *wptr = 0; + next = alloc; + continue; + } + } } static grub_err_t @@ -900,9 +909,11 @@ grub_bfs_dir (grub_device_t device, const char *path, { struct grub_bfs_inode ino; - err = find_file (path, device->disk, &ctx.sb, &ino, GRUB_FSHELP_DIR); + err = find_file (path, device->disk, &ctx.sb, &ino); if (err) return err; + if (((grub_bfs_to_cpu32 (ino.mode) & ATTR_TYPE) != ATTR_DIR)) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); iterate_in_b_tree (device->disk, &ctx.sb, &ino, grub_bfs_dir_iter, &ctx); } @@ -923,9 +934,11 @@ grub_bfs_open (struct grub_file *file, const char *name) { struct grub_bfs_inode ino; struct grub_bfs_data *data; - err = find_file (name, file->device->disk, &sb, &ino, GRUB_FSHELP_REG); + err = find_file (name, file->device->disk, &sb, &ino); if (err) return err; + if (((grub_bfs_to_cpu32 (ino.mode) & ATTR_TYPE) != ATTR_REG)) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file")); data = grub_zalloc (sizeof (struct grub_bfs_data)); if (!data) @@ -1021,7 +1034,7 @@ read_bfs_attr (grub_disk_t disk, if (err) return -1; - err = find_in_b_tree (disk, sb, ino, name, &res); + err = find_in_b_tree (disk, sb, ino, name, grub_strlen (name), &res); if (err) return -1; grub_disk_read (disk, res @@ -1082,13 +1095,13 @@ static struct grub_fs grub_bfs_fs = { #else .name = "bfs", #endif - .fs_dir = grub_bfs_dir, - .fs_open = grub_bfs_open, - .fs_read = grub_bfs_read, - .fs_close = grub_bfs_close, - .fs_label = grub_bfs_label, + .dir = grub_bfs_dir, + .open = grub_bfs_open, + .read = grub_bfs_read, + .close = grub_bfs_close, + .label = grub_bfs_label, #ifndef MODE_AFS - .fs_uuid = grub_bfs_uuid, + .uuid = grub_bfs_uuid, #endif #ifdef GRUB_UTIL .reserved_first_sector = 1, diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 27339bdb3..9cffa91fa 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -17,14 +17,6 @@ * along with GRUB. If not, see . */ -/* - * Tell zstd to expose functions that aren't part of the stable API, which - * aren't safe to use when linking against a dynamic library. We vendor in a - * specific zstd version, so we know what we're getting. We need these unstable - * functions to provide our own allocator, which uses grub_malloc(), to zstd. - */ -#define ZSTD_STATIC_LINKING_ONLY - #include #include #include @@ -35,12 +27,8 @@ #include #include #include -#include #include #include -#include -#include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -57,9 +45,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE (GRUB_BTRFS_LZO_BLOCK_SIZE + \ (GRUB_BTRFS_LZO_BLOCK_SIZE / 16) + 64 + 3) -#define ZSTD_BTRFS_MAX_WINDOWLOG 17 -#define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG) - typedef grub_uint8_t grub_btrfs_checksum_t[0x20]; typedef grub_uint16_t grub_btrfs_uuid_t[8]; @@ -92,8 +77,7 @@ struct btrfs_header { grub_btrfs_checksum_t checksum; grub_btrfs_uuid_t uuid; - grub_uint64_t bytenr; - grub_uint8_t dummy[0x28]; + grub_uint8_t dummy[0x30]; grub_uint32_t nitems; grub_uint8_t level; } GRUB_PACKED; @@ -135,10 +119,6 @@ struct grub_btrfs_chunk_item #define GRUB_BTRFS_CHUNK_TYPE_RAID1 0x10 #define GRUB_BTRFS_CHUNK_TYPE_DUPLICATED 0x20 #define GRUB_BTRFS_CHUNK_TYPE_RAID10 0x40 -#define GRUB_BTRFS_CHUNK_TYPE_RAID5 0x80 -#define GRUB_BTRFS_CHUNK_TYPE_RAID6 0x100 -#define GRUB_BTRFS_CHUNK_TYPE_RAID1C3 0x200 -#define GRUB_BTRFS_CHUNK_TYPE_RAID1C4 0x400 grub_uint8_t dummy2[0xc]; grub_uint16_t nstripes; grub_uint16_t nsubstripes; @@ -195,7 +175,7 @@ struct grub_btrfs_time { grub_int64_t sec; grub_uint32_t nanosec; -} GRUB_PACKED; +} __attribute__ ((aligned (4))); struct grub_btrfs_inode { @@ -232,7 +212,6 @@ struct grub_btrfs_extent_data #define GRUB_BTRFS_COMPRESSION_NONE 0 #define GRUB_BTRFS_COMPRESSION_ZLIB 1 #define GRUB_BTRFS_COMPRESSION_LZO 2 -#define GRUB_BTRFS_COMPRESSION_ZSTD 3 #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 @@ -248,11 +227,11 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, static grub_err_t read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) { - struct grub_btrfs_superblock sblock; unsigned i; grub_err_t err = GRUB_ERR_NONE; for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++) { + struct grub_btrfs_superblock sblock; /* Don't try additional superblocks beyond device size. */ if (i && (grub_le_to_cpu64 (sblock.this_device.size) >> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i]) @@ -305,25 +284,6 @@ free_iterator (struct grub_btrfs_leaf_descriptor *desc) grub_free (desc->data); } -static grub_err_t -check_btrfs_header (struct grub_btrfs_data *data, struct btrfs_header *header, - grub_disk_addr_t addr) -{ - if (grub_le_to_cpu64 (header->bytenr) != addr) - { - grub_dprintf ("btrfs", "btrfs_header.bytenr is not equal node addr\n"); - return grub_error (GRUB_ERR_BAD_FS, - "header bytenr is not equal node addr"); - } - if (grub_memcmp (data->sblock.uuid, header->uuid, sizeof(grub_btrfs_uuid_t))) - { - grub_dprintf ("btrfs", "btrfs_header.uuid doesn't match sblock uuid\n"); - return grub_error (GRUB_ERR_BAD_FS, - "header uuid doesn't match sblock uuid"); - } - return GRUB_ERR_NONE; -} - static grub_err_t save_ref (struct grub_btrfs_leaf_descriptor *desc, grub_disk_addr_t addr, unsigned i, unsigned m, int l) @@ -332,13 +292,9 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc, if (desc->allocated < desc->depth) { void *newdata; - grub_size_t sz; - - if (grub_mul (desc->allocated, 2, &desc->allocated) || - grub_mul (desc->allocated, sizeof (desc->data[0]), &sz)) - return GRUB_ERR_OUT_OF_RANGE; - - newdata = grub_realloc (desc->data, sz); + desc->allocated *= 2; + newdata = grub_realloc (desc->data, sizeof (desc->data[0]) + * desc->allocated); if (!newdata) return grub_errno; desc->data = newdata; @@ -383,7 +339,6 @@ next (struct grub_btrfs_data *data, err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head, sizeof (head), 0); - check_btrfs_header (data, &head, grub_le_to_cpu64 (node.addr)); if (err) return -err; @@ -420,7 +375,7 @@ lower_bound (struct grub_btrfs_data *data, { desc->allocated = 16; desc->depth = 0; - desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); + desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); if (!desc->data) return grub_errno; } @@ -445,7 +400,6 @@ lower_bound (struct grub_btrfs_data *data, /* FIXME: preread few nodes into buffer. */ err = grub_btrfs_read_logical (data, addr, &head, sizeof (head), recursion_depth + 1); - check_btrfs_header (data, &head, addr); if (err) return err; addr += sizeof (head); @@ -610,7 +564,7 @@ find_device_iter (const char *name, void *data) } static grub_device_t -find_device (struct grub_btrfs_data *data, grub_uint64_t id) +find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) { struct find_device_ctx ctx = { .data = data, @@ -622,28 +576,28 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) for (i = 0; i < data->n_devices_attached; i++) if (id == data->devices_attached[i].id) return data->devices_attached[i].dev; - - grub_device_iterate (find_device_iter, &ctx); - + if (do_rescan) + grub_device_iterate (find_device_iter, &ctx); + if (!ctx.dev_found) + { + grub_error (GRUB_ERR_BAD_FS, + N_("couldn't find a necessary member device " + "of multi-device filesystem")); + return NULL; + } data->n_devices_attached++; if (data->n_devices_attached > data->n_devices_allocated) { void *tmp; - grub_size_t sz; - - if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || - grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || - grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) - goto fail; - - data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + data->n_devices_allocated = 2 * data->n_devices_attached + 1; + data->devices_attached + = grub_realloc (tmp = data->devices_attached, + data->n_devices_allocated + * sizeof (data->devices_attached[0])); if (!data->devices_attached) { + grub_device_close (ctx.dev_found); data->devices_attached = tmp; - - fail: - if (ctx.dev_found) - grub_device_close (ctx.dev_found); return NULL; } } @@ -652,211 +606,6 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) return ctx.dev_found; } -static grub_err_t -btrfs_read_from_chunk (struct grub_btrfs_data *data, - struct grub_btrfs_chunk_item *chunk, - grub_uint64_t stripen, grub_uint64_t stripe_offset, - int redundancy, grub_uint64_t csize, - void *buf) -{ - struct grub_btrfs_chunk_stripe *stripe; - grub_disk_addr_t paddr; - grub_device_t dev; - grub_err_t err; - - stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1); - /* Right now the redundancy handling is easy. - With RAID5-like it will be more difficult. */ - stripe += stripen + redundancy; - - paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset; - - grub_dprintf ("btrfs", "stripe %" PRIxGRUB_UINT64_T - " maps to 0x%" PRIxGRUB_UINT64_T "\n" - "reading paddr 0x%" PRIxGRUB_UINT64_T "\n", - stripen, stripe->offset, paddr); - - dev = find_device (data, stripe->device_id); - if (!dev) - { - grub_dprintf ("btrfs", - "couldn't find a necessary member device " - "of multi-device filesystem\n"); - grub_errno = GRUB_ERR_NONE; - return GRUB_ERR_READ_ERROR; - } - - err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS, - paddr & (GRUB_DISK_SECTOR_SIZE - 1), - csize, buf); - return err; -} - -struct raid56_buffer { - void *buf; - int data_is_valid; -}; - -static void -rebuild_raid5 (char *dest, struct raid56_buffer *buffers, - grub_uint64_t nstripes, grub_uint64_t csize) -{ - grub_uint64_t i; - int first; - - for(i = 0; buffers[i].data_is_valid && i < nstripes; i++); - - if (i == nstripes) - { - grub_dprintf ("btrfs", "called rebuild_raid5(), but all disks are OK\n"); - return; - } - - grub_dprintf ("btrfs", "rebuilding RAID 5 stripe #%" PRIuGRUB_UINT64_T "\n", i); - - for (i = 0, first = 1; i < nstripes; i++) - { - if (!buffers[i].data_is_valid) - continue; - - if (first) { - grub_memcpy(dest, buffers[i].buf, csize); - first = 0; - } else - grub_crypto_xor (dest, dest, buffers[i].buf, csize); - } -} - -static grub_err_t -raid6_recover_read_buffer (void *data, int disk_nr, - grub_uint64_t addr __attribute__ ((unused)), - void *dest, grub_size_t size) -{ - struct raid56_buffer *buffers = data; - - if (!buffers[disk_nr].data_is_valid) - return grub_errno = GRUB_ERR_READ_ERROR; - - grub_memcpy(dest, buffers[disk_nr].buf, size); - - return grub_errno = GRUB_ERR_NONE; -} - -static void -rebuild_raid6 (struct raid56_buffer *buffers, grub_uint64_t nstripes, - grub_uint64_t csize, grub_uint64_t parities_pos, void *dest, - grub_uint64_t stripen) - -{ - grub_raid6_recover_gen (buffers, nstripes, stripen, parities_pos, - dest, 0, csize, 0, raid6_recover_read_buffer); -} - -static grub_err_t -raid56_read_retry (struct grub_btrfs_data *data, - struct grub_btrfs_chunk_item *chunk, - grub_uint64_t stripe_offset, grub_uint64_t stripen, - grub_uint64_t csize, void *buf, grub_uint64_t parities_pos) -{ - struct raid56_buffer *buffers; - grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); - grub_uint64_t chunk_type = grub_le_to_cpu64 (chunk->type); - grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; - grub_uint64_t i, failed_devices; - - buffers = grub_calloc (nstripes, sizeof (*buffers)); - if (!buffers) - goto cleanup; - - for (i = 0; i < nstripes; i++) - { - buffers[i].buf = grub_zalloc (csize); - if (!buffers[i].buf) - goto cleanup; - } - - for (failed_devices = 0, i = 0; i < nstripes; i++) - { - struct grub_btrfs_chunk_stripe *stripe; - grub_disk_addr_t paddr; - grub_device_t dev; - grub_err_t err; - - /* - * The struct grub_btrfs_chunk_stripe array lives - * behind struct grub_btrfs_chunk_item. - */ - stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1) + i; - - paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset; - grub_dprintf ("btrfs", "reading paddr %" PRIxGRUB_UINT64_T - " from stripe ID %" PRIxGRUB_UINT64_T "\n", - paddr, stripe->device_id); - - dev = find_device (data, stripe->device_id); - if (!dev) - { - grub_dprintf ("btrfs", "stripe %" PRIuGRUB_UINT64_T " FAILED (dev ID %" - PRIxGRUB_UINT64_T ")\n", i, stripe->device_id); - failed_devices++; - continue; - } - - err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS, - paddr & (GRUB_DISK_SECTOR_SIZE - 1), - csize, buffers[i].buf); - if (err == GRUB_ERR_NONE) - { - buffers[i].data_is_valid = 1; - grub_dprintf ("btrfs", "stripe %" PRIuGRUB_UINT64_T " OK (dev ID %" - PRIxGRUB_UINT64_T ")\n", i, stripe->device_id); - } - else - { - grub_dprintf ("btrfs", "stripe %" PRIuGRUB_UINT64_T - " READ FAILED (dev ID %" PRIxGRUB_UINT64_T ")\n", - i, stripe->device_id); - failed_devices++; - } - } - - if (failed_devices > 1 && (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID5)) - { - grub_dprintf ("btrfs", "not enough disks for RAID 5: total %" PRIuGRUB_UINT64_T - ", missing %" PRIuGRUB_UINT64_T "\n", - nstripes, failed_devices); - ret = GRUB_ERR_READ_ERROR; - goto cleanup; - } - else if (failed_devices > 2 && (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID6)) - { - grub_dprintf ("btrfs", "not enough disks for RAID 6: total %" PRIuGRUB_UINT64_T - ", missing %" PRIuGRUB_UINT64_T "\n", - nstripes, failed_devices); - ret = GRUB_ERR_READ_ERROR; - goto cleanup; - } - else - grub_dprintf ("btrfs", "enough disks for RAID 5: total %" - PRIuGRUB_UINT64_T ", missing %" PRIuGRUB_UINT64_T "\n", - nstripes, failed_devices); - - /* We have enough disks. So, rebuild the data. */ - if (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID5) - rebuild_raid5 (buf, buffers, nstripes, csize); - else - rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen); - - ret = GRUB_ERR_NONE; - cleanup: - if (buffers) - for (i = 0; i < nstripes; i++) - grub_free (buffers[i].buf); - grub_free (buffers); - - return ret; -} - static grub_err_t grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, void *buf, grub_size_t size, int recursion_depth) @@ -870,6 +619,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_err_t err = 0; struct grub_btrfs_key key_out; int challoc = 0; + grub_device_t dev; struct grub_btrfs_key key_in; grub_size_t chsize; grub_disk_addr_t chaddr; @@ -934,12 +684,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_uint16_t nstripes; unsigned redundancy = 1; unsigned i, j; - int is_raid56; - grub_uint64_t parities_pos = 0; - - is_raid56 = !!(grub_le_to_cpu64 (chunk->type) & - (GRUB_BTRFS_CHUNK_TYPE_RAID5 | - GRUB_BTRFS_CHUNK_TYPE_RAID6)); if (grub_le_to_cpu64 (chunk->size) <= off) { @@ -976,19 +720,14 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, csize = (stripen + 1) * stripe_length - off; break; } - case GRUB_BTRFS_CHUNK_TYPE_RAID1C4: - redundancy++; - /* fall through */ - case GRUB_BTRFS_CHUNK_TYPE_RAID1C3: - redundancy++; - /* fall through */ case GRUB_BTRFS_CHUNK_TYPE_DUPLICATED: case GRUB_BTRFS_CHUNK_TYPE_RAID1: { - grub_dprintf ("btrfs", "RAID1 (copies: %d)\n", ++redundancy); + grub_dprintf ("btrfs", "RAID1\n"); stripen = 0; stripe_offset = off; csize = grub_le_to_cpu64 (chunk->size) - off; + redundancy = 2; break; } case GRUB_BTRFS_CHUNK_TYPE_RAID0: @@ -1025,86 +764,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; - break; - } - case GRUB_BTRFS_CHUNK_TYPE_RAID5: - case GRUB_BTRFS_CHUNK_TYPE_RAID6: - { - grub_uint64_t nparities, stripe_nr, high, low; - - redundancy = 1; /* no redundancy for now */ - - if (grub_le_to_cpu64 (chunk->type) & GRUB_BTRFS_CHUNK_TYPE_RAID5) - { - grub_dprintf ("btrfs", "RAID5\n"); - nparities = 1; - } - else - { - grub_dprintf ("btrfs", "RAID6\n"); - nparities = 2; - } - - /* - * RAID 6 layout consists of several stripes spread over - * the disks, e.g.: - * - * Disk_0 Disk_1 Disk_2 Disk_3 - * A0 B0 P0 Q0 - * Q1 A1 B1 P1 - * P2 Q2 A2 B2 - * - * Note: placement of the parities depend on row number. - * - * Pay attention that the btrfs terminology may differ from - * terminology used in other RAID implementations, e.g. LVM, - * dm or md. The main difference is that btrfs calls contiguous - * block of data on a given disk, e.g. A0, stripe instead of chunk. - * - * The variables listed below have following meaning: - * - stripe_nr is the stripe number excluding the parities - * (A0 = 0, B0 = 1, A1 = 2, B1 = 3, etc.), - * - high is the row number (0 for A0...Q0, 1 for Q1...P1, etc.), - * - stripen is the disk number in a row (0 for A0, Q1, P2, - * 1 for B0, A1, Q2, etc.), - * - off is the logical address to read, - * - chunk_stripe_length is the size of a stripe (typically 64 KiB), - * - nstripes is the number of disks in a row, - * - low is the offset of the data inside a stripe, - * - stripe_offset is the data offset in an array, - * - csize is the "potential" data to read; it will be reduced - * to size if the latter is smaller, - * - nparities is the number of parities (1 for RAID 5, 2 for - * RAID 6); used only in RAID 5/6 code. - */ - stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); - - /* - * stripen is computed without the parities - * (0 for A0, A1, A2, 1 for B0, B1, B2, etc.). - */ - high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen); - - /* - * The stripes are spread over the disks. Every each row their - * positions are shifted by 1 place. So, the real disks number - * change. Hence, we have to take into account current row number - * modulo nstripes (0 for A0, 1 for A1, 2 for A2, etc.). - */ - grub_divmod64 (high + stripen, nstripes, &stripen); - - /* - * parities_pos is equal to ((high - nparities) % nstripes) - * (see the diagram above). However, (high - nparities) can - * be negative, e.g. when high == 0, leading to an incorrect - * results. (high + nstripes - nparities) is always positive and - * modulo nstripes is equal to ((high - nparities) % nstripes). - */ - grub_divmod64 (high + nstripes - nparities, nstripes, &parities_pos); - - stripe_offset = chunk_stripe_length * high + low; - csize = chunk_stripe_length - low; - break; } default: @@ -1121,41 +780,49 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, for (j = 0; j < 2; j++) { - grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T - "+0x%" PRIxGRUB_UINT64_T - " (%d stripes (%d substripes) of %" - PRIxGRUB_UINT64_T ")\n", - grub_le_to_cpu64 (key->offset), - grub_le_to_cpu64 (chunk->size), - grub_le_to_cpu16 (chunk->nstripes), - grub_le_to_cpu16 (chunk->nsubstripes), - grub_le_to_cpu64 (chunk->stripe_length)); - grub_dprintf ("btrfs", "reading laddr 0x%" PRIxGRUB_UINT64_T "\n", - addr); - - if (is_raid56) + for (i = 0; i < redundancy; i++) { - err = btrfs_read_from_chunk (data, chunk, stripen, - stripe_offset, - 0, /* no mirror */ - csize, buf); + struct grub_btrfs_chunk_stripe *stripe; + grub_disk_addr_t paddr; + + stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1); + /* Right now the redundancy handling is easy. + With RAID5-like it will be more difficult. */ + stripe += stripen + i; + + paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset; + + grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T + "+0x%" PRIxGRUB_UINT64_T + " (%d stripes (%d substripes) of %" + PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T + " maps to 0x%" PRIxGRUB_UINT64_T "\n", + grub_le_to_cpu64 (key->offset), + grub_le_to_cpu64 (chunk->size), + grub_le_to_cpu16 (chunk->nstripes), + grub_le_to_cpu16 (chunk->nsubstripes), + grub_le_to_cpu64 (chunk->stripe_length), + stripen, stripe->offset); + grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T + " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr, + addr); + + dev = find_device (data, stripe->device_id, j); + if (!dev) + { + err = grub_errno; + grub_errno = GRUB_ERR_NONE; + continue; + } + + err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS, + paddr & (GRUB_DISK_SECTOR_SIZE - 1), + csize, buf); + if (!err) + break; grub_errno = GRUB_ERR_NONE; - if (err) - err = raid56_read_retry (data, chunk, stripe_offset, - stripen, csize, buf, parities_pos); } - else - for (i = 0; i < redundancy; i++) - { - err = btrfs_read_from_chunk (data, chunk, stripen, - stripe_offset, - i, /* redundancy */ - csize, buf); - if (!err) - break; - grub_errno = GRUB_ERR_NONE; - } - if (!err) + if (i != redundancy) break; } if (err) @@ -1214,8 +881,7 @@ grub_btrfs_unmount (struct grub_btrfs_data *data) unsigned i; /* The device 0 is closed one layer upper. */ for (i = 1; i < data->n_devices_attached; i++) - if (data->devices_attached[i].dev) - grub_device_close (data->devices_attached[i].dev); + grub_device_close (data->devices_attached[i].dev); grub_free (data->devices_attached); grub_free (data->extent); grub_free (data); @@ -1246,96 +912,6 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data, return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode), 0); } -static void *grub_zstd_malloc (void *state __attribute__((unused)), size_t size) -{ - return grub_malloc (size); -} - -static void grub_zstd_free (void *state __attribute__((unused)), void *address) -{ - return grub_free (address); -} - -static ZSTD_customMem grub_zstd_allocator (void) -{ - ZSTD_customMem allocator; - - allocator.customAlloc = &grub_zstd_malloc; - allocator.customFree = &grub_zstd_free; - allocator.opaque = NULL; - - return allocator; -} - -static grub_ssize_t -grub_btrfs_zstd_decompress (char *ibuf, grub_size_t isize, grub_off_t off, - char *obuf, grub_size_t osize) -{ - void *allocated = NULL; - char *otmpbuf = obuf; - grub_size_t otmpsize = osize; - ZSTD_DCtx *dctx = NULL; - grub_size_t zstd_ret; - grub_ssize_t ret = -1; - - /* - * Zstd will fail if it can't fit the entire output in the destination - * buffer, so if osize isn't large enough, allocate a temporary buffer. - */ - if (otmpsize < ZSTD_BTRFS_MAX_INPUT) - { - allocated = grub_malloc (ZSTD_BTRFS_MAX_INPUT); - if (!allocated) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed allocate a zstd buffer"); - goto err; - } - otmpbuf = (char *) allocated; - otmpsize = ZSTD_BTRFS_MAX_INPUT; - } - - /* Create the ZSTD_DCtx. */ - dctx = ZSTD_createDCtx_advanced (grub_zstd_allocator ()); - if (!dctx) - { - /* ZSTD_createDCtx_advanced() only fails if it is out of memory. */ - grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to create a zstd context"); - goto err; - } - - /* - * Get the real input size, there may be junk at the - * end of the frame. - */ - isize = ZSTD_findFrameCompressedSize (ibuf, isize); - if (ZSTD_isError (isize)) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted"); - goto err; - } - - /* Decompress and check for errors. */ - zstd_ret = ZSTD_decompressDCtx (dctx, otmpbuf, otmpsize, ibuf, isize); - if (ZSTD_isError (zstd_ret)) - { - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted"); - goto err; - } - - /* - * Move the requested data into the obuf. obuf may be equal - * to otmpbuf, which is why grub_memmove() is required. - */ - grub_memmove (obuf, otmpbuf + off, osize); - ret = osize; - -err: - grub_free (allocated); - ZSTD_freeDCtx (dctx); - - return ret; -} - static grub_ssize_t grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off, char *obuf, grub_size_t osize) @@ -1511,8 +1087,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE && data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB - && data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO - && data->extent->compression != GRUB_BTRFS_COMPRESSION_ZSTD) + && data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO) { grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "compression type 0x%x not supported", @@ -1552,15 +1127,6 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, != (grub_ssize_t) csize) return -1; } - else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZSTD) - { - if (grub_btrfs_zstd_decompress (data->extent->inl, data->extsize - - ((grub_uint8_t *) data->extent->inl - - (grub_uint8_t *) data->extent), - extoff, buf, csize) - != (grub_ssize_t) csize) - return -1; - } else grub_memcpy (buf, data->extent->inl + extoff, csize); break; @@ -1598,10 +1164,6 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data, ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff + grub_le_to_cpu64 (data->extent->offset), buf, csize); - else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZSTD) - ret = grub_btrfs_zstd_decompress (tmp, zsize, extoff - + grub_le_to_cpu64 (data->extent->offset), - buf, csize); else ret = -1; @@ -2177,7 +1739,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), *nsectors = 64 * 2 - 1; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) @@ -2189,14 +1751,14 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), static struct grub_fs grub_btrfs_fs = { .name = "btrfs", - .fs_dir = grub_btrfs_dir, - .fs_open = grub_btrfs_open, - .fs_read = grub_btrfs_read, - .fs_close = grub_btrfs_close, - .fs_uuid = grub_btrfs_uuid, - .fs_label = grub_btrfs_label, + .dir = grub_btrfs_dir, + .open = grub_btrfs_open, + .read = grub_btrfs_read, + .close = grub_btrfs_close, + .uuid = grub_btrfs_uuid, + .label = grub_btrfs_label, #ifdef GRUB_UTIL - .fs_embed = grub_btrfs_embed, + .embed = grub_btrfs_embed, .reserved_first_sector = 1, .blocklist_install = 0, #endif diff --git a/grub-core/fs/cbfs.c b/grub-core/fs/cbfs.c index 857bea991..35750a0e4 100644 --- a/grub-core/fs/cbfs.c +++ b/grub-core/fs/cbfs.c @@ -74,7 +74,8 @@ grub_cbfs_find_file (struct grub_archelp_data *data, char **name, (void) mtime; offset = grub_be_to_cpu32 (hd.offset); - *mode = GRUB_ARCHELP_ATTR_FILE | GRUB_ARCHELP_ATTR_NOTIME; + if (mode) + *mode = GRUB_ARCHELP_ATTR_FILE | GRUB_ARCHELP_ATTR_NOTIME; namesize = offset; if (namesize >= sizeof (hd)) @@ -143,7 +144,7 @@ static struct grub_archelp_data * grub_cbfs_mount (grub_disk_t disk) { struct cbfs_file hd; - struct grub_archelp_data *data = NULL; + struct grub_archelp_data *data; grub_uint32_t ptr; grub_off_t header_off; struct cbfs_header head; @@ -195,7 +196,6 @@ grub_cbfs_mount (grub_disk_t disk) return data; fail: - grub_free (data); grub_error (GRUB_ERR_BAD_FS, "not a cbfs filesystem"); return 0; } @@ -328,11 +328,11 @@ static struct grub_disk_dev grub_cbfsdisk_dev = { .name = "cbfsdisk", .id = GRUB_DISK_DEVICE_CBFSDISK_ID, - .disk_iterate = grub_cbfsdisk_iterate, - .disk_open = grub_cbfsdisk_open, - .disk_close = grub_cbfsdisk_close, - .disk_read = grub_cbfsdisk_read, - .disk_write = grub_cbfsdisk_write, + .iterate = grub_cbfsdisk_iterate, + .open = grub_cbfsdisk_open, + .close = grub_cbfsdisk_close, + .read = grub_cbfsdisk_read, + .write = grub_cbfsdisk_write, .next = 0 }; @@ -344,16 +344,8 @@ init_cbfsdisk (void) ptr = *(grub_uint32_t *) 0xfffffffc; head = (struct cbfs_header *) (grub_addr_t) ptr; - grub_dprintf ("cbfs", "head=%p\n", head); - /* coreboot current supports only ROMs <= 16 MiB. Bigger ROMs will - have problems as RCBA is 18 MiB below end of 32-bit typically, - so either memory map would have to be rearranged or we'd need to support - reading ROMs through controller directly. - */ - if (ptr < 0xff000000 - || 0xffffffff - ptr < (grub_uint32_t) sizeof (*head) + 0xf - || !validate_head (head)) + if (!validate_head (head)) return; cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize), @@ -375,10 +367,10 @@ fini_cbfsdisk (void) static struct grub_fs grub_cbfs_fs = { .name = "cbfs", - .fs_dir = grub_cbfs_dir, - .fs_open = grub_cbfs_open, - .fs_read = grub_cbfs_read, - .fs_close = grub_cbfs_close, + .dir = grub_cbfs_dir, + .open = grub_cbfs_open, + .read = grub_cbfs_read, + .close = grub_cbfs_close, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 0, diff --git a/grub-core/fs/cpio_common.c b/grub-core/fs/cpio_common.c index 4e885d623..b0ae9f445 100644 --- a/grub-core/fs/cpio_common.c +++ b/grub-core/fs/cpio_common.c @@ -36,11 +36,6 @@ struct grub_archelp_data grub_off_t size; }; -#if __GNUC__ >= 9 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif - static grub_err_t grub_cpio_find_file (struct grub_archelp_data *data, char **name, grub_int32_t *mtime, grub_uint32_t *mode) @@ -66,15 +61,8 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode)); namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize)); - /* Don't allow negative numbers. */ - if (namesize >= 0x80000000) - { - /* Probably a corruption, don't attempt to recover. */ - *mode = GRUB_ARCHELP_ATTR_END; - return GRUB_ERR_NONE; - } - - *mode = modeval; + if (mode) + *mode = modeval; *name = grub_malloc (namesize + 1); if (*name == NULL) @@ -101,10 +89,6 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, return GRUB_ERR_NONE; } -#if __GNUC__ >= 9 -#pragma GCC diagnostic pop -#endif - static char * grub_cpio_get_link_target (struct grub_archelp_data *data) { @@ -242,10 +226,10 @@ grub_cpio_close (grub_file_t file) static struct grub_fs grub_cpio_fs = { .name = FSNAME, - .fs_dir = grub_cpio_dir, - .fs_open = grub_cpio_open, - .fs_read = grub_cpio_read, - .fs_close = grub_cpio_close, + .dir = grub_cpio_dir, + .open = grub_cpio_open, + .read = grub_cpio_read, + .close = grub_cpio_close, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 0, diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c index ac33bcd68..44c7974e3 100644 --- a/grub-core/fs/ext2.c +++ b/grub-core/fs/ext2.c @@ -46,7 +46,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -101,31 +100,22 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* Extents used */ #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 -#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 -#define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 /* The set of back-incompatible features this driver DOES support. Add (OR) * flags here as the related features are implemented into the driver. */ #define EXT2_DRIVER_SUPPORTED_INCOMPAT ( EXT2_FEATURE_INCOMPAT_FILETYPE \ | EXT4_FEATURE_INCOMPAT_EXTENTS \ | EXT4_FEATURE_INCOMPAT_FLEX_BG \ - | EXT2_FEATURE_INCOMPAT_META_BG \ - | EXT4_FEATURE_INCOMPAT_64BIT \ - | EXT4_FEATURE_INCOMPAT_ENCRYPT) + | EXT4_FEATURE_INCOMPAT_64BIT) /* List of rationales for the ignored "incompatible" features: * needs_recovery: Not really back-incompatible - was added as such to forbid * ext2 drivers from mounting an ext3 volume with a dirty * journal because they will ignore the journal, but the next * ext3 driver to mount the volume will find the journal and * replay it, potentially corrupting the metadata written by - * the ext2 drivers. Safe to ignore for this RO driver. - * mmp: Not really back-incompatible - was added as such to - * avoid multiple read-write mounts. Safe to ignore for this - * RO driver. - */ -#define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER \ - | EXT4_FEATURE_INCOMPAT_MMP) + * the ext2 drivers. Safe to ignore for this RO driver. */ +#define EXT2_DRIVER_IGNORED_INCOMPAT ( EXT3_FEATURE_INCOMPAT_RECOVER ) #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U @@ -141,7 +131,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define EXT3_JOURNAL_FLAG_DELETED 4 #define EXT3_JOURNAL_FLAG_LAST_TAG 8 -#define EXT4_ENCRYPT_FLAG 0x800 #define EXT4_EXTENTS_FLAG 0x80000 /* The ext2 superblock. */ @@ -342,68 +331,16 @@ static grub_dl_t my_mod; -/* Check is a = b^x for some x. */ -static inline int -is_power_of (grub_uint64_t a, grub_uint32_t b) -{ - grub_uint64_t c; - /* Prevent overflow assuming b < 8. */ - if (a >= (1LL << 60)) - return 0; - for (c = 1; c <= a; c *= b); - return (c == a); -} - - -static inline int -group_has_super_block (struct grub_ext2_data *data, grub_uint64_t group) -{ - if (!(data->sblock.feature_ro_compat - & grub_cpu_to_le32_compile_time(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))) - return 1; - /* Algorithm looked up in Linux source. */ - if (group <= 1) - return 1; - /* Even number is never a power of odd number. */ - if (!(group & 1)) - return 0; - return (is_power_of(group, 7) || is_power_of(group, 5) || - is_power_of(group, 3)); -} - /* Read into BLKGRP the blockgroup descriptor of blockgroup GROUP of the mounted filesystem DATA. */ inline static grub_err_t -grub_ext2_blockgroup (struct grub_ext2_data *data, grub_uint64_t group, +grub_ext2_blockgroup (struct grub_ext2_data *data, int group, struct grub_ext2_block_group *blkgrp) { - grub_uint64_t full_offset = (group << data->log_group_desc_size); - grub_uint64_t block, offset; - block = (full_offset >> LOG2_BLOCK_SIZE (data)); - offset = (full_offset & ((1 << LOG2_BLOCK_SIZE (data)) - 1)); - if ((data->sblock.feature_incompat - & grub_cpu_to_le32_compile_time (EXT2_FEATURE_INCOMPAT_META_BG)) - && block >= grub_le_to_cpu32(data->sblock.first_meta_bg)) - { - grub_uint64_t first_block_group; - /* Find the first block group for which a descriptor - is stored in given block. */ - first_block_group = (block << (LOG2_BLOCK_SIZE (data) - - data->log_group_desc_size)); - - block = (first_block_group - * grub_le_to_cpu32(data->sblock.blocks_per_group)); - - if (group_has_super_block (data, first_block_group)) - block++; - } - else - /* Superblock. */ - block++; return grub_disk_read (data->disk, - ((grub_le_to_cpu32 (data->sblock.first_data_block) - + block) - << LOG2_EXT2_BLOCK_SIZE (data)), offset, + ((grub_le_to_cpu32 (data->sblock.first_data_block) + 1) + << LOG2_EXT2_BLOCK_SIZE (data)), + group << data->log_group_desc_size, sizeof (struct grub_ext2_block_group), blkgrp); } @@ -542,9 +479,8 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) shift = 2; goto indirect; } - grub_error (GRUB_ERR_BAD_FS, - "ext2fs doesn't support quadruple indirect blocks"); - return -1; + return grub_error (GRUB_ERR_BAD_FS, + "ext2fs doesn't support quadruple indirect blocks"); indirect: do { @@ -559,7 +495,7 @@ indirect: & ((1 << log_perblock) - 1)) * sizeof (indir), sizeof (indir), &indir)) - return -1; + return grub_errno; } while (shift--); return grub_le_to_cpu32 (indir); @@ -704,28 +640,15 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) { char *symlink; struct grub_fshelp_node *diro = node; - grub_size_t sz; if (! diro->inode_read) { grub_ext2_read_inode (diro->data, diro->ino, &diro->inode); if (grub_errno) return 0; - - if (diro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) - { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "symlink is encrypted"); - return 0; - } } - if (grub_add (grub_le_to_cpu32 (diro->inode.size), 1, &sz)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - return NULL; - } - - symlink = grub_malloc (sz); + symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); if (! symlink) return 0; @@ -766,12 +689,6 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir, return 0; } - if (diro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) - { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "directory is encrypted"); - return 0; - } - /* Search the file. */ while (fpos < grub_le_to_cpu32 (diro->inode.size)) { @@ -882,12 +799,6 @@ grub_ext2_open (struct grub_file *file, const char *name) goto fail; } - if (fdiro->inode.flags & grub_cpu_to_le32_compile_time (EXT4_ENCRYPT_FLAG)) - { - err = grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "file is encrypted"); - goto fail; - } - grub_memcpy (data->inode, &fdiro->inode, sizeof (struct grub_ext2_inode)); grub_free (fdiro); @@ -1080,13 +991,13 @@ grub_ext2_mtime (grub_device_t device, grub_int32_t *tm) static struct grub_fs grub_ext2_fs = { .name = "ext2", - .fs_dir = grub_ext2_dir, - .fs_open = grub_ext2_open, - .fs_read = grub_ext2_read, - .fs_close = grub_ext2_close, - .fs_label = grub_ext2_label, - .fs_uuid = grub_ext2_uuid, - .fs_mtime = grub_ext2_mtime, + .dir = grub_ext2_dir, + .open = grub_ext2_open, + .read = grub_ext2_read, + .close = grub_ext2_close, + .label = grub_ext2_label, + .uuid = grub_ext2_uuid, + .mtime = grub_ext2_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c deleted file mode 100644 index 8a9992ca9..000000000 --- a/grub-core/fs/f2fs.c +++ /dev/null @@ -1,1328 +0,0 @@ -/* - * f2fs.c - Flash-Friendly File System - * - * Written by Jaegeuk Kim - * - * Copyright (C) 2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -/* F2FS Magic Number. */ -#define F2FS_SUPER_MAGIC 0xf2f52010 - -#define CHECKSUM_OFFSET 4092 /* Must be aligned 4 bytes. */ -#define U32_CHECKSUM_OFFSET (CHECKSUM_OFFSET >> 2) -#define CRCPOLY_LE 0xedb88320 - -/* Byte-size offset. */ -#define F2FS_SUPER_OFFSET ((grub_disk_addr_t)1024) -#define F2FS_SUPER_OFFSET0 (F2FS_SUPER_OFFSET >> GRUB_DISK_SECTOR_BITS) -#define F2FS_SUPER_OFFSET1 ((F2FS_SUPER_OFFSET + F2FS_BLKSIZE) >> \ - GRUB_DISK_SECTOR_BITS) - -/* 9 bits for 512 bytes. */ -#define F2FS_MIN_LOG_SECTOR_SIZE 9 - -/* Support only 4KB block. */ -#define F2FS_BLK_BITS 12 -#define F2FS_BLKSIZE (1 << F2FS_BLK_BITS) -#define F2FS_BLK_SEC_BITS (F2FS_BLK_BITS - GRUB_DISK_SECTOR_BITS) - -#define VERSION_LEN 256 -#define F2FS_MAX_EXTENSION 64 - -#define CP_COMPACT_SUM_FLAG 0x00000004 -#define CP_UMOUNT_FLAG 0x00000001 - -#define MAX_ACTIVE_LOGS 16 -#define MAX_ACTIVE_NODE_LOGS 8 -#define MAX_ACTIVE_DATA_LOGS 8 -#define NR_CURSEG_DATA_TYPE 3 -#define NR_CURSEG_NODE_TYPE 3 -#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) - -#define ENTRIES_IN_SUM 512 -#define SUMMARY_SIZE 7 -#define SUM_FOOTER_SIZE 5 -#define JENTRY_SIZE (sizeof(struct grub_f2fs_nat_jent)) -#define SUM_ENTRIES_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM) -#define SUM_JOURNAL_SIZE (F2FS_BLKSIZE - SUM_FOOTER_SIZE - SUM_ENTRIES_SIZE) -#define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) / JENTRY_SIZE) -#define NAT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) % JENTRY_SIZE) - -#define NAT_ENTRY_SIZE (sizeof(struct grub_f2fs_nat_entry)) -#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / NAT_ENTRY_SIZE) - -#define F2FS_NAME_LEN 255 -#define F2FS_SLOT_LEN 8 -#define NR_DENTRY_IN_BLOCK 214 -#define SIZE_OF_DIR_ENTRY 11 /* By byte. */ -#define BITS_PER_BYTE 8 -#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define SIZE_OF_RESERVED (F2FS_BLKSIZE - \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ - NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) - -#define F2FS_INLINE_XATTR_ADDRS 50 /* 200 bytes for inline xattrs. */ -#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode. */ - -#define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block. */ -#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block. */ -#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) -#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) -#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3) -#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4) -#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5) - -#define MAX_INLINE_DATA (4 * (DEF_ADDRS_PER_INODE - \ - F2FS_INLINE_XATTR_ADDRS - 1)) -#define NR_INLINE_DENTRY (MAX_INLINE_DATA * BITS_PER_BYTE / \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ - BITS_PER_BYTE + 1)) -#define INLINE_DENTRY_BITMAP_SIZE ((NR_INLINE_DENTRY + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define INLINE_RESERVED_SIZE (MAX_INLINE_DATA - \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ - NR_INLINE_DENTRY + \ - INLINE_DENTRY_BITMAP_SIZE)) -#define CURSEG_HOT_DATA 0 - -#define CKPT_FLAG_SET(ckpt, f) (ckpt)->ckpt_flags & \ - grub_cpu_to_le32_compile_time (f) - -#define F2FS_INLINE_XATTR 0x01 /* File inline xattr flag. */ -#define F2FS_INLINE_DATA 0x02 /* File inline data flag. */ -#define F2FS_INLINE_DENTRY 0x04 /* File inline dentry flag. */ -#define F2FS_DATA_EXIST 0x08 /* File inline data exist flag. */ -#define F2FS_INLINE_DOTS 0x10 /* File having implicit dot dentries. */ - -#define MAX_VOLUME_NAME 512 - -enum FILE_TYPE -{ - F2FS_FT_UNKNOWN, - F2FS_FT_REG_FILE = 1, - F2FS_FT_DIR = 2, - F2FS_FT_SYMLINK = 7 -}; - -struct grub_f2fs_superblock -{ - grub_uint32_t magic; - grub_uint16_t dummy1[2]; - grub_uint32_t log_sectorsize; - grub_uint32_t log_sectors_per_block; - grub_uint32_t log_blocksize; - grub_uint32_t log_blocks_per_seg; - grub_uint32_t segs_per_sec; - grub_uint32_t secs_per_zone; - grub_uint32_t checksum_offset; - grub_uint8_t dummy2[40]; - grub_uint32_t cp_blkaddr; - grub_uint32_t sit_blkaddr; - grub_uint32_t nat_blkaddr; - grub_uint32_t ssa_blkaddr; - grub_uint32_t main_blkaddr; - grub_uint32_t root_ino; - grub_uint32_t node_ino; - grub_uint32_t meta_ino; - grub_uint8_t uuid[16]; - grub_uint16_t volume_name[MAX_VOLUME_NAME]; - grub_uint32_t extension_count; - grub_uint8_t extension_list[F2FS_MAX_EXTENSION][8]; - grub_uint32_t cp_payload; - grub_uint8_t version[VERSION_LEN]; - grub_uint8_t init_version[VERSION_LEN]; -} GRUB_PACKED; - -struct grub_f2fs_checkpoint -{ - grub_uint64_t checkpoint_ver; - grub_uint64_t user_block_count; - grub_uint64_t valid_block_count; - grub_uint32_t rsvd_segment_count; - grub_uint32_t overprov_segment_count; - grub_uint32_t free_segment_count; - grub_uint32_t cur_node_segno[MAX_ACTIVE_NODE_LOGS]; - grub_uint16_t cur_node_blkoff[MAX_ACTIVE_NODE_LOGS]; - grub_uint32_t cur_data_segno[MAX_ACTIVE_DATA_LOGS]; - grub_uint16_t cur_data_blkoff[MAX_ACTIVE_DATA_LOGS]; - grub_uint32_t ckpt_flags; - grub_uint32_t cp_pack_total_block_count; - grub_uint32_t cp_pack_start_sum; - grub_uint32_t valid_node_count; - grub_uint32_t valid_inode_count; - grub_uint32_t next_free_nid; - grub_uint32_t sit_ver_bitmap_bytesize; - grub_uint32_t nat_ver_bitmap_bytesize; - grub_uint32_t checksum_offset; - grub_uint64_t elapsed_time; - grub_uint8_t alloc_type[MAX_ACTIVE_LOGS]; - grub_uint8_t sit_nat_version_bitmap[3900]; - grub_uint32_t checksum; -} GRUB_PACKED; - -struct grub_f2fs_nat_entry { - grub_uint8_t version; - grub_uint32_t ino; - grub_uint32_t block_addr; -} GRUB_PACKED; - -struct grub_f2fs_nat_jent -{ - grub_uint32_t nid; - struct grub_f2fs_nat_entry ne; -} GRUB_PACKED; - -struct grub_f2fs_nat_journal { - grub_uint16_t n_nats; - struct grub_f2fs_nat_jent entries[NAT_JOURNAL_ENTRIES]; - grub_uint8_t reserved[NAT_JOURNAL_RESERVED]; -} GRUB_PACKED; - -struct grub_f2fs_nat_block { - struct grub_f2fs_nat_entry ne[NAT_ENTRY_PER_BLOCK]; -} GRUB_PACKED; - -struct grub_f2fs_dir_entry -{ - grub_uint32_t hash_code; - grub_uint32_t ino; - grub_uint16_t name_len; - grub_uint8_t file_type; -} GRUB_PACKED; - -struct grub_f2fs_inline_dentry -{ - grub_uint8_t dentry_bitmap[INLINE_DENTRY_BITMAP_SIZE]; - grub_uint8_t reserved[INLINE_RESERVED_SIZE]; - struct grub_f2fs_dir_entry dentry[NR_INLINE_DENTRY]; - grub_uint8_t filename[NR_INLINE_DENTRY][F2FS_SLOT_LEN]; -} GRUB_PACKED; - -struct grub_f2fs_dentry_block { - grub_uint8_t dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; - grub_uint8_t reserved[SIZE_OF_RESERVED]; - struct grub_f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; - grub_uint8_t filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; -} GRUB_PACKED; - -struct grub_f2fs_inode -{ - grub_uint16_t i_mode; - grub_uint8_t i_advise; - grub_uint8_t i_inline; - grub_uint32_t i_uid; - grub_uint32_t i_gid; - grub_uint32_t i_links; - grub_uint64_t i_size; - grub_uint64_t i_blocks; - grub_uint64_t i_atime; - grub_uint64_t i_ctime; - grub_uint64_t i_mtime; - grub_uint32_t i_atime_nsec; - grub_uint32_t i_ctime_nsec; - grub_uint32_t i_mtime_nsec; - grub_uint32_t i_generation; - grub_uint32_t i_current_depth; - grub_uint32_t i_xattr_nid; - grub_uint32_t i_flags; - grub_uint32_t i_pino; - grub_uint32_t i_namelen; - grub_uint8_t i_name[F2FS_NAME_LEN]; - grub_uint8_t i_dir_level; - grub_uint8_t i_ext[12]; - grub_uint32_t i_addr[DEF_ADDRS_PER_INODE]; - grub_uint32_t i_nid[5]; -} GRUB_PACKED; - -struct grub_direct_node { - grub_uint32_t addr[ADDRS_PER_BLOCK]; -} GRUB_PACKED; - -struct grub_indirect_node { - grub_uint32_t nid[NIDS_PER_BLOCK]; -} GRUB_PACKED; - -struct grub_f2fs_node -{ - union - { - struct grub_f2fs_inode i; - struct grub_direct_node dn; - struct grub_indirect_node in; - /* Should occupy F2FS_BLKSIZE totally. */ - char buf[F2FS_BLKSIZE - 40]; - }; - grub_uint8_t dummy[40]; -} GRUB_PACKED; - -struct grub_fshelp_node -{ - struct grub_f2fs_data *data; - struct grub_f2fs_node inode; - grub_uint32_t ino; - int inode_read; -}; - -struct grub_f2fs_data -{ - struct grub_f2fs_superblock sblock; - struct grub_f2fs_checkpoint ckpt; - - grub_uint32_t root_ino; - grub_uint32_t blocks_per_seg; - grub_uint32_t cp_blkaddr; - grub_uint32_t nat_blkaddr; - - struct grub_f2fs_nat_journal nat_j; - char *nat_bitmap; - - grub_disk_t disk; - struct grub_f2fs_node *inode; - struct grub_fshelp_node diropen; -}; - -struct grub_f2fs_dir_iter_ctx -{ - struct grub_f2fs_data *data; - grub_fshelp_iterate_dir_hook_t hook; - void *hook_data; - grub_uint8_t *bitmap; - grub_uint8_t (*filename)[F2FS_SLOT_LEN]; - struct grub_f2fs_dir_entry *dentry; - int max; -}; - -struct grub_f2fs_dir_ctx -{ - grub_fs_dir_hook_t hook; - void *hook_data; - struct grub_f2fs_data *data; -}; - -static grub_dl_t my_mod; - -static int -grub_f2fs_test_bit_le (int nr, const grub_uint8_t *addr) -{ - return addr[nr >> 3] & (1 << (nr & 7)); -} - -static char * -get_inline_addr (struct grub_f2fs_inode *inode) -{ - return (char *) &inode->i_addr[1]; -} - -static grub_uint64_t -grub_f2fs_file_size (struct grub_f2fs_inode *inode) -{ - return grub_le_to_cpu64 (inode->i_size); -} - -static grub_uint32_t -start_cp_addr (struct grub_f2fs_data *data) -{ - struct grub_f2fs_checkpoint *ckpt = &data->ckpt; - grub_uint32_t start_addr = data->cp_blkaddr; - - if (!(ckpt->checkpoint_ver & grub_cpu_to_le64_compile_time(1))) - return start_addr + data->blocks_per_seg; - - return start_addr; -} - -static grub_uint32_t -start_sum_block (struct grub_f2fs_data *data) -{ - struct grub_f2fs_checkpoint *ckpt = &data->ckpt; - - return start_cp_addr (data) + grub_le_to_cpu32 (ckpt->cp_pack_start_sum); -} - -static grub_uint32_t -sum_blk_addr (struct grub_f2fs_data *data, int base, int type) -{ - struct grub_f2fs_checkpoint *ckpt = &data->ckpt; - - return start_cp_addr (data) + - grub_le_to_cpu32 (ckpt->cp_pack_total_block_count) - - (base + 1) + type; -} - -static void * -nat_bitmap_ptr (struct grub_f2fs_data *data) -{ - struct grub_f2fs_checkpoint *ckpt = &data->ckpt; - grub_uint32_t offset; - - if (grub_le_to_cpu32 (data->sblock.cp_payload) > 0) - return ckpt->sit_nat_version_bitmap; - - offset = grub_le_to_cpu32 (ckpt->sit_ver_bitmap_bytesize); - - return ckpt->sit_nat_version_bitmap + offset; -} - -static grub_uint32_t -get_node_id (struct grub_f2fs_node *rn, int off, int inode_block) -{ - if (inode_block) - return grub_le_to_cpu32 (rn->i.i_nid[off - NODE_DIR1_BLOCK]); - - return grub_le_to_cpu32 (rn->in.nid[off]); -} - -static grub_err_t -grub_f2fs_block_read (struct grub_f2fs_data *data, grub_uint32_t blkaddr, - void *buf) -{ - return grub_disk_read (data->disk, - ((grub_disk_addr_t)blkaddr) << F2FS_BLK_SEC_BITS, - 0, F2FS_BLKSIZE, buf); -} - -/* CRC32 */ -static grub_uint32_t -grub_f2fs_cal_crc32 (const void *buf, const grub_uint32_t len) -{ - grub_uint32_t crc = F2FS_SUPER_MAGIC; - unsigned char *p = (unsigned char *)buf; - grub_uint32_t tmp = len; - int i; - - while (tmp--) - { - crc ^= *p++; - for (i = 0; i < 8; i++) - crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); - } - - return crc; -} - -static int -grub_f2fs_crc_valid (grub_uint32_t blk_crc, void *buf, const grub_uint32_t len) -{ - grub_uint32_t cal_crc = 0; - - cal_crc = grub_f2fs_cal_crc32 (buf, len); - - return (cal_crc == blk_crc) ? 1 : 0; -} - -static int -grub_f2fs_test_bit (grub_uint32_t nr, const char *p) -{ - int mask; - - p += (nr >> 3); - mask = 1 << (7 - (nr & 0x07)); - - return mask & *p; -} - -static int -grub_f2fs_sanity_check_sb (struct grub_f2fs_superblock *sb) -{ - grub_uint32_t log_sectorsize, log_sectors_per_block; - - if (sb->magic != grub_cpu_to_le32_compile_time (F2FS_SUPER_MAGIC)) - return -1; - - if (sb->log_blocksize != grub_cpu_to_le32_compile_time (F2FS_BLK_BITS)) - return -1; - - log_sectorsize = grub_le_to_cpu32 (sb->log_sectorsize); - log_sectors_per_block = grub_le_to_cpu32 (sb->log_sectors_per_block); - - if (log_sectorsize > F2FS_BLK_BITS) - return -1; - - if (log_sectorsize < F2FS_MIN_LOG_SECTOR_SIZE) - return -1; - - if (log_sectors_per_block + log_sectorsize != F2FS_BLK_BITS) - return -1; - - return 0; -} - -static int -grub_f2fs_read_sb (struct grub_f2fs_data *data, grub_disk_addr_t offset) -{ - grub_disk_t disk = data->disk; - grub_err_t err; - - /* Read first super block. */ - err = grub_disk_read (disk, offset, 0, sizeof (data->sblock), &data->sblock); - if (err) - return -1; - - return grub_f2fs_sanity_check_sb (&data->sblock); -} - -static void * -validate_checkpoint (struct grub_f2fs_data *data, grub_uint32_t cp_addr, - grub_uint64_t *version) -{ - grub_uint32_t *cp_page_1, *cp_page_2; - struct grub_f2fs_checkpoint *cp_block; - grub_uint64_t cur_version = 0, pre_version = 0; - grub_uint32_t crc = 0; - grub_uint32_t crc_offset; - grub_err_t err; - - /* Read the 1st cp block in this CP pack. */ - cp_page_1 = grub_malloc (F2FS_BLKSIZE); - if (!cp_page_1) - return NULL; - - err = grub_f2fs_block_read (data, cp_addr, cp_page_1); - if (err) - goto invalid_cp1; - - cp_block = (struct grub_f2fs_checkpoint *)cp_page_1; - crc_offset = grub_le_to_cpu32 (cp_block->checksum_offset); - if (crc_offset != CHECKSUM_OFFSET) - goto invalid_cp1; - - crc = grub_le_to_cpu32 (*(cp_page_1 + U32_CHECKSUM_OFFSET)); - if (!grub_f2fs_crc_valid (crc, cp_block, crc_offset)) - goto invalid_cp1; - - pre_version = grub_le_to_cpu64 (cp_block->checkpoint_ver); - - /* Read the 2nd cp block in this CP pack. */ - cp_page_2 = grub_malloc (F2FS_BLKSIZE); - if (!cp_page_2) - goto invalid_cp1; - - cp_addr += grub_le_to_cpu32 (cp_block->cp_pack_total_block_count) - 1; - - err = grub_f2fs_block_read (data, cp_addr, cp_page_2); - if (err) - goto invalid_cp2; - - cp_block = (struct grub_f2fs_checkpoint *)cp_page_2; - crc_offset = grub_le_to_cpu32 (cp_block->checksum_offset); - if (crc_offset != CHECKSUM_OFFSET) - goto invalid_cp2; - - crc = grub_le_to_cpu32 (*(cp_page_2 + U32_CHECKSUM_OFFSET)); - if (!grub_f2fs_crc_valid (crc, cp_block, crc_offset)) - goto invalid_cp2; - - cur_version = grub_le_to_cpu64 (cp_block->checkpoint_ver); - if (cur_version == pre_version) - { - *version = cur_version; - grub_free (cp_page_2); - - return cp_page_1; - } - - invalid_cp2: - grub_free (cp_page_2); - - invalid_cp1: - grub_free (cp_page_1); - - return NULL; -} - -static grub_err_t -grub_f2fs_read_cp (struct grub_f2fs_data *data) -{ - void *cp1, *cp2, *cur_page; - grub_uint64_t cp1_version = 0, cp2_version = 0; - grub_uint64_t cp_start_blk_no; - - /* - * Finding out valid cp block involves read both - * sets (cp pack1 and cp pack 2). - */ - cp_start_blk_no = data->cp_blkaddr; - cp1 = validate_checkpoint (data, cp_start_blk_no, &cp1_version); - if (!cp1 && grub_errno) - return grub_errno; - - /* The second checkpoint pack should start at the next segment. */ - cp_start_blk_no += data->blocks_per_seg; - cp2 = validate_checkpoint (data, cp_start_blk_no, &cp2_version); - if (!cp2 && grub_errno) - { - grub_free (cp1); - return grub_errno; - } - - if (cp1 && cp2) - cur_page = (cp2_version > cp1_version) ? cp2 : cp1; - else if (cp1) - cur_page = cp1; - else if (cp2) - cur_page = cp2; - else - return grub_error (GRUB_ERR_BAD_FS, "no checkpoints"); - - grub_memcpy (&data->ckpt, cur_page, F2FS_BLKSIZE); - - grub_free (cp1); - grub_free (cp2); - - return 0; -} - -static grub_err_t -get_nat_journal (struct grub_f2fs_data *data) -{ - grub_uint32_t block; - char *buf; - grub_err_t err; - - buf = grub_malloc (F2FS_BLKSIZE); - if (!buf) - return grub_errno; - - if (CKPT_FLAG_SET(&data->ckpt, CP_COMPACT_SUM_FLAG)) - block = start_sum_block (data); - else if (CKPT_FLAG_SET (&data->ckpt, CP_UMOUNT_FLAG)) - block = sum_blk_addr (data, NR_CURSEG_TYPE, CURSEG_HOT_DATA); - else - block = sum_blk_addr (data, NR_CURSEG_DATA_TYPE, CURSEG_HOT_DATA); - - err = grub_f2fs_block_read (data, block, buf); - if (err) - goto fail; - - if (CKPT_FLAG_SET (&data->ckpt, CP_COMPACT_SUM_FLAG)) - grub_memcpy (&data->nat_j, buf, SUM_JOURNAL_SIZE); - else - grub_memcpy (&data->nat_j, buf + SUM_ENTRIES_SIZE, SUM_JOURNAL_SIZE); - - fail: - grub_free (buf); - - return err; -} - -static grub_uint32_t -get_blkaddr_from_nat_journal (struct grub_f2fs_data *data, grub_uint32_t nid) -{ - grub_uint16_t n = grub_le_to_cpu16 (data->nat_j.n_nats); - grub_uint32_t blkaddr = 0; - grub_uint16_t i; - - for (i = 0; i < n; i++) - { - if (grub_le_to_cpu32 (data->nat_j.entries[i].nid) == nid) - { - blkaddr = grub_le_to_cpu32 (data->nat_j.entries[i].ne.block_addr); - break; - } - } - - return blkaddr; -} - -static grub_uint32_t -get_node_blkaddr (struct grub_f2fs_data *data, grub_uint32_t nid) -{ - struct grub_f2fs_nat_block *nat_block; - grub_uint32_t seg_off, block_off, entry_off, block_addr; - grub_uint32_t blkaddr; - grub_err_t err; - - blkaddr = get_blkaddr_from_nat_journal (data, nid); - if (blkaddr) - return blkaddr; - - nat_block = grub_malloc (F2FS_BLKSIZE); - if (!nat_block) - return 0; - - block_off = nid / NAT_ENTRY_PER_BLOCK; - entry_off = nid % NAT_ENTRY_PER_BLOCK; - - seg_off = block_off / data->blocks_per_seg; - block_addr = data->nat_blkaddr + - ((seg_off * data->blocks_per_seg) << 1) + - (block_off & (data->blocks_per_seg - 1)); - - if (grub_f2fs_test_bit (block_off, data->nat_bitmap)) - block_addr += data->blocks_per_seg; - - err = grub_f2fs_block_read (data, block_addr, nat_block); - if (err) - { - grub_free (nat_block); - return 0; - } - - blkaddr = grub_le_to_cpu32 (nat_block->ne[entry_off].block_addr); - - grub_free (nat_block); - - return blkaddr; -} - -static int -grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block, - grub_uint32_t offset[4], grub_uint32_t noffset[4]) -{ - grub_uint32_t direct_blks = ADDRS_PER_BLOCK; - grub_uint32_t dptrs_per_blk = NIDS_PER_BLOCK; - grub_uint32_t indirect_blks = ADDRS_PER_BLOCK * NIDS_PER_BLOCK; - grub_uint32_t dindirect_blks = indirect_blks * NIDS_PER_BLOCK; - grub_uint32_t direct_index = DEF_ADDRS_PER_INODE; - int n = 0; - int level = -1; - - if (inode->i_inline & F2FS_INLINE_XATTR) - direct_index -= F2FS_INLINE_XATTR_ADDRS; - - noffset[0] = 0; - - if (block < direct_index) - { - offset[n] = block; - level = 0; - goto got; - } - - block -= direct_index; - if (block < direct_blks) - { - offset[n++] = NODE_DIR1_BLOCK; - noffset[n] = 1; - offset[n] = block; - level = 1; - goto got; - } - - block -= direct_blks; - if (block < direct_blks) - { - offset[n++] = NODE_DIR2_BLOCK; - noffset[n] = 2; - offset[n] = block; - level = 1; - goto got; - } - - block -= direct_blks; - if (block < indirect_blks) - { - offset[n++] = NODE_IND1_BLOCK; - noffset[n] = 3; - offset[n++] = block / direct_blks; - noffset[n] = 4 + offset[n - 1]; - offset[n] = block % direct_blks; - level = 2; - goto got; - } - - block -= indirect_blks; - if (block < indirect_blks) - { - offset[n++] = NODE_IND2_BLOCK; - noffset[n] = 4 + dptrs_per_blk; - offset[n++] = block / direct_blks; - noffset[n] = 5 + dptrs_per_blk + offset[n - 1]; - offset[n] = block % direct_blks; - level = 2; - goto got; - } - - block -= indirect_blks; - if (block < dindirect_blks) - { - offset[n++] = NODE_DIND_BLOCK; - noffset[n] = 5 + (dptrs_per_blk * 2); - offset[n++] = block / indirect_blks; - noffset[n] = 6 + (dptrs_per_blk * 2) + - offset[n - 1] * (dptrs_per_blk + 1); - offset[n++] = (block / direct_blks) % dptrs_per_blk; - noffset[n] = 7 + (dptrs_per_blk * 2) + - offset[n - 2] * (dptrs_per_blk + 1) + offset[n - 1]; - offset[n] = block % direct_blks; - level = 3; - goto got; - } - - got: - return level; -} - -static grub_err_t -grub_f2fs_read_node (struct grub_f2fs_data *data, - grub_uint32_t nid, struct grub_f2fs_node *np) -{ - grub_uint32_t blkaddr; - - blkaddr = get_node_blkaddr (data, nid); - if (!blkaddr) - return grub_errno; - - return grub_f2fs_block_read (data, blkaddr, np); -} - -static struct grub_f2fs_data * -grub_f2fs_mount (grub_disk_t disk) -{ - struct grub_f2fs_data *data; - grub_err_t err; - - data = grub_malloc (sizeof (*data)); - if (!data) - return NULL; - - data->disk = disk; - - if (grub_f2fs_read_sb (data, F2FS_SUPER_OFFSET0)) - { - if (grub_f2fs_read_sb (data, F2FS_SUPER_OFFSET1)) - { - if (grub_errno == GRUB_ERR_NONE) - grub_error (GRUB_ERR_BAD_FS, - "not a F2FS filesystem (no superblock)"); - goto fail; - } - } - - data->root_ino = grub_le_to_cpu32 (data->sblock.root_ino); - data->cp_blkaddr = grub_le_to_cpu32 (data->sblock.cp_blkaddr); - data->nat_blkaddr = grub_le_to_cpu32 (data->sblock.nat_blkaddr); - data->blocks_per_seg = 1 << - grub_le_to_cpu32 (data->sblock.log_blocks_per_seg); - - err = grub_f2fs_read_cp (data); - if (err) - goto fail; - - data->nat_bitmap = nat_bitmap_ptr (data); - - err = get_nat_journal (data); - if (err) - goto fail; - - data->diropen.data = data; - data->diropen.ino = data->root_ino; - data->diropen.inode_read = 1; - data->inode = &data->diropen.inode; - - err = grub_f2fs_read_node (data, data->root_ino, data->inode); - if (err) - goto fail; - - return data; - - fail: - grub_free (data); - - return NULL; -} - -/* Guarantee inline_data was handled by caller. */ -static grub_disk_addr_t -grub_f2fs_get_block (grub_fshelp_node_t node, grub_disk_addr_t block_ofs) -{ - struct grub_f2fs_data *data = node->data; - struct grub_f2fs_inode *inode = &node->inode.i; - grub_uint32_t offset[4], noffset[4], nids[4]; - struct grub_f2fs_node *node_block; - grub_uint32_t block_addr = -1; - int level, i; - - level = grub_get_node_path (inode, block_ofs, offset, noffset); - - if (level < 0) - return -1; - - if (level == 0) - return grub_le_to_cpu32 (inode->i_addr[offset[0]]); - - node_block = grub_malloc (F2FS_BLKSIZE); - if (!node_block) - return -1; - - nids[1] = get_node_id (&node->inode, offset[0], 1); - - /* Get indirect or direct nodes. */ - for (i = 1; i <= level; i++) - { - grub_f2fs_read_node (data, nids[i], node_block); - if (grub_errno) - goto fail; - - if (i < level) - nids[i + 1] = get_node_id (node_block, offset[i], 0); - } - - block_addr = grub_le_to_cpu32 (node_block->dn.addr[offset[level]]); - - fail: - grub_free (node_block); - - return block_addr; -} - -static grub_ssize_t -grub_f2fs_read_file (grub_fshelp_node_t node, - grub_disk_read_hook_t read_hook, void *read_hook_data, - grub_off_t pos, grub_size_t len, char *buf) -{ - struct grub_f2fs_inode *inode = &node->inode.i; - grub_off_t filesize = grub_f2fs_file_size (inode); - char *inline_addr = get_inline_addr (inode); - - if (inode->i_inline & F2FS_INLINE_DATA) - { - if (filesize > MAX_INLINE_DATA) - return -1; - - if (len > filesize - pos) - len = filesize - pos; - - grub_memcpy (buf, inline_addr + pos, len); - return len; - } - - return grub_fshelp_read_file (node->data->disk, node, - read_hook, read_hook_data, - pos, len, buf, grub_f2fs_get_block, - filesize, - F2FS_BLK_SEC_BITS, 0); -} - -static char * -grub_f2fs_read_symlink (grub_fshelp_node_t node) -{ - char *symlink; - struct grub_fshelp_node *diro = node; - grub_uint64_t filesize; - - if (!diro->inode_read) - { - grub_f2fs_read_node (diro->data, diro->ino, &diro->inode); - if (grub_errno) - return 0; - } - - filesize = grub_f2fs_file_size(&diro->inode.i); - - symlink = grub_malloc (filesize + 1); - if (!symlink) - return 0; - - grub_f2fs_read_file (diro, 0, 0, 0, filesize, symlink); - if (grub_errno) - { - grub_free (symlink); - return 0; - } - - symlink[filesize] = '\0'; - - return symlink; -} - -static int -grub_f2fs_check_dentries (struct grub_f2fs_dir_iter_ctx *ctx) -{ - struct grub_fshelp_node *fdiro; - int i; - - for (i = 0; i < ctx->max;) - { - char *filename; - enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN; - enum FILE_TYPE ftype; - int name_len; - int ret; - - if (grub_f2fs_test_bit_le (i, ctx->bitmap) == 0) - { - i++; - continue; - } - - ftype = ctx->dentry[i].file_type; - name_len = grub_le_to_cpu16 (ctx->dentry[i].name_len); - filename = grub_malloc (name_len + 1); - if (!filename) - return 0; - - grub_memcpy (filename, ctx->filename[i], name_len); - filename[name_len] = 0; - - fdiro = grub_malloc (sizeof (struct grub_fshelp_node)); - if (!fdiro) - { - grub_free(filename); - return 0; - } - - if (ftype == F2FS_FT_DIR) - type = GRUB_FSHELP_DIR; - else if (ftype == F2FS_FT_SYMLINK) - type = GRUB_FSHELP_SYMLINK; - else if (ftype == F2FS_FT_REG_FILE) - type = GRUB_FSHELP_REG; - - fdiro->data = ctx->data; - fdiro->ino = grub_le_to_cpu32 (ctx->dentry[i].ino); - fdiro->inode_read = 0; - - ret = ctx->hook (filename, type, fdiro, ctx->hook_data); - grub_free(filename); - if (ret) - return 1; - - i += (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN; - } - - return 0; -} - -static int -grub_f2fs_iterate_inline_dir (struct grub_f2fs_inode *dir, - struct grub_f2fs_dir_iter_ctx *ctx) -{ - struct grub_f2fs_inline_dentry *de_blk; - - de_blk = (struct grub_f2fs_inline_dentry *) get_inline_addr (dir); - - ctx->bitmap = de_blk->dentry_bitmap; - ctx->dentry = de_blk->dentry; - ctx->filename = de_blk->filename; - ctx->max = NR_INLINE_DENTRY; - - return grub_f2fs_check_dentries (ctx); -} - -static int -grub_f2fs_iterate_dir (grub_fshelp_node_t dir, - grub_fshelp_iterate_dir_hook_t hook, void *hook_data) -{ - struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir; - struct grub_f2fs_inode *inode; - struct grub_f2fs_dir_iter_ctx ctx = { - .data = diro->data, - .hook = hook, - .hook_data = hook_data - }; - grub_off_t fpos = 0; - - if (!diro->inode_read) - { - grub_f2fs_read_node (diro->data, diro->ino, &diro->inode); - if (grub_errno) - return 0; - } - - inode = &diro->inode.i; - - if (inode->i_inline & F2FS_INLINE_DENTRY) - return grub_f2fs_iterate_inline_dir (inode, &ctx); - - while (fpos < grub_f2fs_file_size (inode)) - { - struct grub_f2fs_dentry_block *de_blk; - char *buf; - int ret; - - buf = grub_zalloc (F2FS_BLKSIZE); - if (!buf) - return 0; - - grub_f2fs_read_file (diro, 0, 0, fpos, F2FS_BLKSIZE, buf); - if (grub_errno) - { - grub_free (buf); - return 0; - } - - de_blk = (struct grub_f2fs_dentry_block *) buf; - - ctx.bitmap = de_blk->dentry_bitmap; - ctx.dentry = de_blk->dentry; - ctx.filename = de_blk->filename; - ctx.max = NR_DENTRY_IN_BLOCK; - - ret = grub_f2fs_check_dentries (&ctx); - grub_free (buf); - if (ret) - return 1; - - fpos += F2FS_BLKSIZE; - } - - return 0; -} - -static int -grub_f2fs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype, - grub_fshelp_node_t node, void *data) -{ - struct grub_f2fs_dir_ctx *ctx = data; - struct grub_dirhook_info info; - - grub_memset (&info, 0, sizeof (info)); - if (!node->inode_read) - { - grub_f2fs_read_node (ctx->data, node->ino, &node->inode); - if (!grub_errno) - node->inode_read = 1; - grub_errno = GRUB_ERR_NONE; - } - if (node->inode_read) - { - info.mtimeset = 1; - info.mtime = grub_le_to_cpu64 (node->inode.i.i_mtime); - } - - info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); - grub_free (node); - - return ctx->hook (filename, &info, ctx->hook_data); -} - -static grub_err_t -grub_f2fs_dir (grub_device_t device, const char *path, - grub_fs_dir_hook_t hook, void *hook_data) -{ - struct grub_f2fs_dir_ctx ctx = { - .hook = hook, - .hook_data = hook_data - }; - struct grub_fshelp_node *fdiro = 0; - - grub_dl_ref (my_mod); - - ctx.data = grub_f2fs_mount (device->disk); - if (!ctx.data) - goto fail; - - grub_fshelp_find_file (path, &ctx.data->diropen, &fdiro, - grub_f2fs_iterate_dir, grub_f2fs_read_symlink, - GRUB_FSHELP_DIR); - if (grub_errno) - goto fail; - - grub_f2fs_iterate_dir (fdiro, grub_f2fs_dir_iter, &ctx); - - fail: - if (fdiro != &ctx.data->diropen) - grub_free (fdiro); - grub_free (ctx.data); - grub_dl_unref (my_mod); - - return grub_errno; -} - -/* Open a file named NAME and initialize FILE. */ -static grub_err_t -grub_f2fs_open (struct grub_file *file, const char *name) -{ - struct grub_f2fs_data *data = NULL; - struct grub_fshelp_node *fdiro = 0; - struct grub_f2fs_inode *inode; - - grub_dl_ref (my_mod); - - data = grub_f2fs_mount (file->device->disk); - if (!data) - goto fail; - - grub_fshelp_find_file (name, &data->diropen, &fdiro, - grub_f2fs_iterate_dir, grub_f2fs_read_symlink, - GRUB_FSHELP_REG); - if (grub_errno) - goto fail; - - if (!fdiro->inode_read) - { - grub_f2fs_read_node (data, fdiro->ino, &fdiro->inode); - if (grub_errno) - goto fail; - } - - grub_memcpy (data->inode, &fdiro->inode, sizeof (*data->inode)); - grub_free (fdiro); - - inode = &(data->inode->i); - file->size = grub_f2fs_file_size (inode); - file->data = data; - file->offset = 0; - - if (inode->i_inline & F2FS_INLINE_DATA && file->size > MAX_INLINE_DATA) - grub_error (GRUB_ERR_BAD_FS, "corrupted inline_data: need fsck"); - - return 0; - - fail: - if (fdiro != &data->diropen) - grub_free (fdiro); - grub_free (data); - - grub_dl_unref (my_mod); - - return grub_errno; -} - -static grub_ssize_t -grub_f2fs_read (grub_file_t file, char *buf, grub_size_t len) -{ - struct grub_f2fs_data *data = (struct grub_f2fs_data *) file->data; - - return grub_f2fs_read_file (&data->diropen, - file->read_hook, file->read_hook_data, - file->offset, len, buf); -} - -static grub_err_t -grub_f2fs_close (grub_file_t file) -{ - struct grub_f2fs_data *data = (struct grub_f2fs_data *) file->data; - - grub_free (data); - - grub_dl_unref (my_mod); - - return GRUB_ERR_NONE; -} - -static grub_uint8_t * -grub_f2fs_utf16_to_utf8 (grub_uint16_t *in_buf_le) -{ - grub_uint16_t in_buf[MAX_VOLUME_NAME]; - grub_uint8_t *out_buf; - int len = 0; - - out_buf = grub_malloc (MAX_VOLUME_NAME * GRUB_MAX_UTF8_PER_UTF16 + 1); - if (!out_buf) - return NULL; - - while (*in_buf_le != 0 && len < MAX_VOLUME_NAME) { - in_buf[len] = grub_le_to_cpu16 (in_buf_le[len]); - len++; - } - - *grub_utf16_to_utf8 (out_buf, in_buf, len) = '\0'; - - return out_buf; -} - -#if __GNUC__ >= 9 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif - -static grub_err_t -grub_f2fs_label (grub_device_t device, char **label) -{ - struct grub_f2fs_data *data; - grub_disk_t disk = device->disk; - - grub_dl_ref (my_mod); - - data = grub_f2fs_mount (disk); - if (data) - *label = (char *) grub_f2fs_utf16_to_utf8 (data->sblock.volume_name); - else - *label = NULL; - - grub_free (data); - grub_dl_unref (my_mod); - - return grub_errno; -} - -#if __GNUC__ >= 9 -#pragma GCC diagnostic pop -#endif - -static grub_err_t -grub_f2fs_uuid (grub_device_t device, char **uuid) -{ - struct grub_f2fs_data *data; - grub_disk_t disk = device->disk; - - grub_dl_ref (my_mod); - - data = grub_f2fs_mount (disk); - if (data) - { - *uuid = - grub_xasprintf - ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - data->sblock.uuid[0], data->sblock.uuid[1], - data->sblock.uuid[2], data->sblock.uuid[3], - data->sblock.uuid[4], data->sblock.uuid[5], - data->sblock.uuid[6], data->sblock.uuid[7], - data->sblock.uuid[8], data->sblock.uuid[9], - data->sblock.uuid[10], data->sblock.uuid[11], - data->sblock.uuid[12], data->sblock.uuid[13], - data->sblock.uuid[14], data->sblock.uuid[15]); - } - else - *uuid = NULL; - - grub_free (data); - grub_dl_unref (my_mod); - - return grub_errno; -} - -static struct grub_fs grub_f2fs_fs = { - .name = "f2fs", - .fs_dir = grub_f2fs_dir, - .fs_open = grub_f2fs_open, - .fs_read = grub_f2fs_read, - .fs_close = grub_f2fs_close, - .fs_label = grub_f2fs_label, - .fs_uuid = grub_f2fs_uuid, -#ifdef GRUB_UTIL - .reserved_first_sector = 1, - .blocklist_install = 0, -#endif - .next = 0 -}; - -GRUB_MOD_INIT (f2fs) -{ - grub_fs_register (&grub_f2fs_fs); - my_mod = mod; -} - -GRUB_MOD_FINI (f2fs) -{ - grub_fs_unregister (&grub_f2fs_fs); -} diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c index 7f775a170..79fe864d7 100644 --- a/grub-core/fs/fat.c +++ b/grub-core/fs/fat.c @@ -26,13 +26,11 @@ #include #include #include -#include #ifndef MODE_EXFAT #include #else #include #endif -#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -175,6 +173,8 @@ struct grub_fat_data #ifndef MODE_EXFAT grub_uint32_t root_sector; grub_uint32_t num_root_sectors; +#else + int is_contiguous; #endif int cluster_bits; @@ -182,26 +182,13 @@ struct grub_fat_data grub_uint32_t cluster_sector; grub_uint32_t num_clusters; - grub_uint32_t uuid; -}; - -struct grub_fshelp_node { - grub_disk_t disk; - struct grub_fat_data *data; - grub_uint8_t attr; -#ifndef MODE_EXFAT - grub_uint32_t file_size; -#else - grub_uint64_t file_size; -#endif + grub_ssize_t file_size; grub_uint32_t file_cluster; grub_uint32_t cur_cluster_num; grub_uint32_t cur_cluster; -#ifdef MODE_EXFAT - int is_contiguous; -#endif + grub_uint32_t uuid; }; static grub_dl_t my_mod; @@ -440,6 +427,13 @@ grub_fat_mount (grub_disk_t disk) (void) magic; #endif + /* Start from the root directory. */ + data->file_cluster = data->root_cluster; + data->cur_cluster_num = ~0U; + data->attr = GRUB_FAT_ATTR_DIRECTORY; +#ifdef MODE_EXFAT + data->is_contiguous = 0; +#endif return data; fail: @@ -450,7 +444,7 @@ grub_fat_mount (grub_disk_t disk) } static grub_ssize_t -grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node, +grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data, grub_disk_read_hook_t read_hook, void *read_hook_data, grub_off_t offset, grub_size_t len, char *buf) { @@ -463,13 +457,13 @@ grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node, #ifndef MODE_EXFAT /* This is a special case. FAT12 and FAT16 doesn't have the root directory in clusters. */ - if (node->file_cluster == ~0U) + if (data->file_cluster == ~0U) { - size = (node->data->num_root_sectors << GRUB_DISK_SECTOR_BITS) - offset; + size = (data->num_root_sectors << GRUB_DISK_SECTOR_BITS) - offset; if (size > len) size = len; - if (grub_disk_read (disk, node->data->root_sector, offset, size, buf)) + if (grub_disk_read (disk, data->root_sector, offset, size, buf)) return -1; return size; @@ -477,12 +471,12 @@ grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node, #endif #ifdef MODE_EXFAT - if (node->is_contiguous) + if (data->is_contiguous) { /* Read the data here. */ - sector = (node->data->cluster_sector - + ((node->file_cluster - 2) - << node->data->cluster_bits)); + sector = (data->cluster_sector + + ((data->file_cluster - 2) + << data->cluster_bits)); disk->read_hook = read_hook; disk->read_hook_data = read_hook_data; @@ -497,53 +491,53 @@ grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node, #endif /* Calculate the logical cluster number and offset. */ - logical_cluster_bits = (node->data->cluster_bits + logical_cluster_bits = (data->cluster_bits + GRUB_DISK_SECTOR_BITS); logical_cluster = offset >> logical_cluster_bits; offset &= (1ULL << logical_cluster_bits) - 1; - if (logical_cluster < node->cur_cluster_num) + if (logical_cluster < data->cur_cluster_num) { - node->cur_cluster_num = 0; - node->cur_cluster = node->file_cluster; + data->cur_cluster_num = 0; + data->cur_cluster = data->file_cluster; } while (len) { - while (logical_cluster > node->cur_cluster_num) + while (logical_cluster > data->cur_cluster_num) { /* Find next cluster. */ grub_uint32_t next_cluster; grub_uint32_t fat_offset; - switch (node->data->fat_size) + switch (data->fat_size) { case 32: - fat_offset = node->cur_cluster << 2; + fat_offset = data->cur_cluster << 2; break; case 16: - fat_offset = node->cur_cluster << 1; + fat_offset = data->cur_cluster << 1; break; default: /* case 12: */ - fat_offset = node->cur_cluster + (node->cur_cluster >> 1); + fat_offset = data->cur_cluster + (data->cur_cluster >> 1); break; } /* Read the FAT. */ - if (grub_disk_read (disk, node->data->fat_sector, fat_offset, - (node->data->fat_size + 7) >> 3, + if (grub_disk_read (disk, data->fat_sector, fat_offset, + (data->fat_size + 7) >> 3, (char *) &next_cluster)) return -1; next_cluster = grub_le_to_cpu32 (next_cluster); - switch (node->data->fat_size) + switch (data->fat_size) { case 16: next_cluster &= 0xFFFF; break; case 12: - if (node->cur_cluster & 1) + if (data->cur_cluster & 1) next_cluster >>= 4; next_cluster &= 0x0FFF; @@ -551,27 +545,27 @@ grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node, } grub_dprintf ("fat", "fat_size=%d, next_cluster=%u\n", - node->data->fat_size, next_cluster); + data->fat_size, next_cluster); /* Check the end. */ - if (next_cluster >= node->data->cluster_eof_mark) + if (next_cluster >= data->cluster_eof_mark) return ret; - if (next_cluster < 2 || next_cluster >= node->data->num_clusters) + if (next_cluster < 2 || next_cluster >= data->num_clusters) { grub_error (GRUB_ERR_BAD_FS, "invalid cluster %u", next_cluster); return -1; } - node->cur_cluster = next_cluster; - node->cur_cluster_num++; + data->cur_cluster = next_cluster; + data->cur_cluster_num++; } /* Read the data here. */ - sector = (node->data->cluster_sector - + ((node->cur_cluster - 2) - << node->data->cluster_bits)); + sector = (data->cluster_sector + + ((data->cur_cluster - 2) + << data->cluster_bits)); size = (1 << logical_cluster_bits) - offset; if (size > len) size = len; @@ -597,7 +591,6 @@ struct grub_fat_iterate_context { #ifdef MODE_EXFAT struct grub_fat_dir_node dir; - struct grub_fat_dir_entry entry; #else struct grub_fat_dir_entry dir; #endif @@ -638,39 +631,39 @@ grub_fat_iterate_fini (struct grub_fat_iterate_context *ctxt) #ifdef MODE_EXFAT static grub_err_t -grub_fat_iterate_dir_next (grub_fshelp_node_t node, +grub_fat_iterate_dir_next (grub_disk_t disk, struct grub_fat_data *data, struct grub_fat_iterate_context *ctxt) { grub_memset (&ctxt->dir, 0, sizeof (ctxt->dir)); while (1) { - struct grub_fat_dir_entry *dir = &ctxt->entry; + struct grub_fat_dir_entry dir; - ctxt->offset += sizeof (*dir); + ctxt->offset += sizeof (dir); - if (grub_fat_read_data (node->disk, node, 0, 0, ctxt->offset, sizeof (*dir), - (char *) dir) - != sizeof (*dir)) + if (grub_fat_read_data (disk, data, 0, 0, ctxt->offset, sizeof (dir), + (char *) &dir) + != sizeof (dir)) break; - if (dir->entry_type == 0) + if (dir.entry_type == 0) break; - if (!(dir->entry_type & 0x80)) + if (!(dir.entry_type & 0x80)) continue; - if (dir->entry_type == 0x85) + if (dir.entry_type == 0x85) { unsigned i, nsec, slots = 0; - nsec = dir->type_specific.file.secondary_count; + nsec = dir.type_specific.file.secondary_count; - ctxt->dir.attr = grub_cpu_to_le16 (dir->type_specific.file.attr); + ctxt->dir.attr = grub_cpu_to_le16 (dir.type_specific.file.attr); ctxt->dir.have_stream = 0; for (i = 0; i < nsec; i++) { struct grub_fat_dir_entry sec; ctxt->offset += sizeof (sec); - if (grub_fat_read_data (node->disk, node, 0, 0, + if (grub_fat_read_data (disk, data, 0, 0, ctxt->offset, sizeof (sec), (char *) &sec) != sizeof (sec)) break; @@ -687,7 +680,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, ctxt->dir.file_size = grub_cpu_to_le64 (sec.type_specific.stream_extension.file_size); ctxt->dir.have_stream = 1; - ctxt->dir.is_contiguous = !!(sec.type_specific.stream_extension.flags + ctxt->dir.is_contiguous = !!(dir.type_specific.stream_extension.flags & grub_cpu_to_le16_compile_time (FLAG_CONTIGUOUS)); break; case 0xc1: @@ -707,7 +700,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, if (i != nsec) { - ctxt->offset -= sizeof (*dir); + ctxt->offset -= sizeof (dir); continue; } @@ -717,51 +710,24 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, return 0; } /* Allocation bitmap. */ - if (dir->entry_type == 0x81) + if (dir.entry_type == 0x81) continue; /* Upcase table. */ - if (dir->entry_type == 0x82) + if (dir.entry_type == 0x82) continue; /* Volume label. */ - if (dir->entry_type == 0x83) + if (dir.entry_type == 0x83) continue; grub_dprintf ("exfat", "unknown primary type 0x%02x\n", - dir->entry_type); + dir.entry_type); } return grub_errno ? : GRUB_ERR_EOF; } -/* - * Convert a timestamp in exFAT format to seconds since the UNIX epoch - * according to sections 7.4.8 and 7.4.9 in the exFAT specification. - * https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification - */ -static int -grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int32_t *nix) { - struct grub_datetime datetime = { - .year = (field >> 25) + 1980, - .month = (field & 0x01E00000) >> 21, - .day = (field & 0x001F0000) >> 16, - .hour = (field & 0x0000F800) >> 11, - .minute = (field & 0x000007E0) >> 5, - .second = (field & 0x0000001F) * 2 + (msec >= 100 ? 1 : 0), - }; - - /* The conversion below allows seconds=60, so don't trust its validation. */ - if ((field & 0x1F) > 29) - return 0; - - /* Validate the 10-msec field even though it is rounded down to seconds. */ - if (msec > 199) - return 0; - - return grub_datetime2unixtime (&datetime, nix); -} - #else static grub_err_t -grub_fat_iterate_dir_next (grub_fshelp_node_t node, +grub_fat_iterate_dir_next (grub_disk_t disk, struct grub_fat_data *data, struct grub_fat_iterate_context *ctxt) { char *filep = 0; @@ -776,7 +742,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, ctxt->offset += sizeof (ctxt->dir); /* Read a directory entry. */ - if (grub_fat_read_data (node->disk, node, 0, 0, + if (grub_fat_read_data (disk, data, 0, 0, ctxt->offset, sizeof (ctxt->dir), (char *) &ctxt->dir) != sizeof (ctxt->dir) || ctxt->dir.name[0] == 0) @@ -863,9 +829,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, i--; } - /* XXX should we check that dir position is 0 or 1? */ - if (i > 2 || filep[0] != '.' || (i == 2 && filep[1] != '.')) - *filep++ = '.'; + *filep++ = '.'; for (i = 8; i < 11 && ctxt->dir.name[i]; i++) *filep++ = grub_tolower (ctxt->dir.name[i]); @@ -885,45 +849,64 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node, return grub_errno ? : GRUB_ERR_EOF; } -/* - * Convert a date and time in FAT format to seconds since the UNIX epoch - * according to sections 11.3.5 and 11.3.6 in ECMA-107. - * https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-107.pdf - */ -static int -grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int32_t *nix) { - struct grub_datetime datetime = { - .year = (date >> 9) + 1980, - .month = (date & 0x01E0) >> 5, - .day = (date & 0x001F), - .hour = (time >> 11), - .minute = (time & 0x07E0) >> 5, - .second = (time & 0x001F) * 2, - }; - - /* The conversion below allows seconds=60, so don't trust its validation. */ - if ((time & 0x1F) > 29) - return 0; - - return grub_datetime2unixtime (&datetime, nix); -} - #endif -static grub_err_t lookup_file (grub_fshelp_node_t node, - const char *name, - grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype) +/* Find the underlying directory or file in PATH and return the + next path. If there is no next path or an error occurs, return NULL. + If HOOK is specified, call it with each file name. */ +static char * +grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, + const char *path, const char *origpath, + grub_fs_dir_hook_t hook, void *hook_data) { - grub_err_t err; + char *dirname, *dirp; + int call_hook; + int found = 0; struct grub_fat_iterate_context ctxt; + grub_err_t err; + + if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY)) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + return 0; + } + + /* Extract a directory name. */ + while (*path == '/') + path++; + + dirp = grub_strchr (path, '/'); + if (dirp) + { + unsigned len = dirp - path; + + dirname = grub_malloc (len + 1); + if (! dirname) + goto fail; + + grub_memcpy (dirname, path, len); + dirname[len] = '\0'; + } + else + /* This is actually a file. */ + dirname = grub_strdup (path); + + call_hook = (! dirp && hook); err = grub_fat_iterate_init (&ctxt); if (err) - return err; - - while (!(err = grub_fat_iterate_dir_next (node, &ctxt))) { + grub_free (dirname); + return 0; + } + + while (!(err = grub_fat_iterate_dir_next (disk, data, &ctxt))) + { + struct grub_dirhook_info info; + grub_memset (&info, 0, sizeof (info)); + + info.dir = !! (ctxt.dir.attr & GRUB_FAT_ATTR_DIRECTORY); + info.case_insensitive = 1; #ifdef MODE_EXFAT if (!ctxt.dir.have_stream) @@ -932,33 +915,33 @@ static grub_err_t lookup_file (grub_fshelp_node_t node, if (ctxt.dir.attr & GRUB_FAT_ATTR_VOLUME_ID) continue; #endif - - if (grub_strcasecmp (name, ctxt.filename) == 0) + if (*dirname == '\0' && call_hook) { - *foundnode = grub_malloc (sizeof (struct grub_fshelp_node)); - if (!*foundnode) - return grub_errno; - (*foundnode)->attr = ctxt.dir.attr; + if (hook (ctxt.filename, &info, hook_data)) + break; + else + continue; + } + + if (grub_strcasecmp (dirname, ctxt.filename) == 0) + { + found = 1; + data->attr = ctxt.dir.attr; #ifdef MODE_EXFAT - (*foundnode)->file_size = ctxt.dir.file_size; - (*foundnode)->file_cluster = ctxt.dir.first_cluster; - (*foundnode)->is_contiguous = ctxt.dir.is_contiguous; + data->file_size = ctxt.dir.file_size; + data->file_cluster = ctxt.dir.first_cluster; + data->is_contiguous = ctxt.dir.is_contiguous; #else - (*foundnode)->file_size = grub_le_to_cpu32 (ctxt.dir.file_size); - (*foundnode)->file_cluster = ((grub_le_to_cpu16 (ctxt.dir.first_cluster_high) << 16) + data->file_size = grub_le_to_cpu32 (ctxt.dir.file_size); + data->file_cluster = ((grub_le_to_cpu16 (ctxt.dir.first_cluster_high) << 16) | grub_le_to_cpu16 (ctxt.dir.first_cluster_low)); - /* If directory points to root, starting cluster is 0 */ - if (!(*foundnode)->file_cluster) - (*foundnode)->file_cluster = node->data->root_cluster; #endif - (*foundnode)->cur_cluster_num = ~0U; - (*foundnode)->data = node->data; - (*foundnode)->disk = node->disk; + data->cur_cluster_num = ~0U; - *foundtype = ((*foundnode)->attr & GRUB_FAT_ATTR_DIRECTORY) ? GRUB_FSHELP_DIR : GRUB_FSHELP_REG; + if (call_hook) + hook (ctxt.filename, &info, hook_data); - grub_fat_iterate_fini (&ctxt); - return GRUB_ERR_NONE; + break; } } @@ -966,8 +949,13 @@ static grub_err_t lookup_file (grub_fshelp_node_t node, if (err == GRUB_ERR_EOF) err = 0; - return err; + if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook) + grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), origpath); + fail: + grub_free (dirname); + + return found ? dirp : 0; } static grub_err_t @@ -976,9 +964,9 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, { struct grub_fat_data *data = 0; grub_disk_t disk = device->disk; - grub_fshelp_node_t found = NULL; - grub_err_t err; - struct grub_fat_iterate_context ctxt; + grub_size_t len; + char *dirname = 0; + char *p; grub_dl_ref (my_mod); @@ -986,62 +974,27 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, if (! data) goto fail; - struct grub_fshelp_node root = { - .data = data, - .disk = disk, - .attr = GRUB_FAT_ATTR_DIRECTORY, - .file_size = 0, - .file_cluster = data->root_cluster, - .cur_cluster_num = ~0U, - .cur_cluster = 0, -#ifdef MODE_EXFAT - .is_contiguous = 0, -#endif - }; - - err = grub_fshelp_find_file_lookup (path, &root, &found, lookup_file, NULL, GRUB_FSHELP_DIR); - if (err) + /* Make sure that DIRNAME terminates with '/'. */ + len = grub_strlen (path); + dirname = grub_malloc (len + 1 + 1); + if (! dirname) goto fail; + grub_memcpy (dirname, path, len); + p = dirname + len; + if (path[len - 1] != '/') + *p++ = '/'; + *p = '\0'; + p = dirname; - err = grub_fat_iterate_init (&ctxt); - if (err) - goto fail; - - while (!(err = grub_fat_iterate_dir_next (found, &ctxt))) + do { - struct grub_dirhook_info info; - grub_memset (&info, 0, sizeof (info)); - - info.dir = !! (ctxt.dir.attr & GRUB_FAT_ATTR_DIRECTORY); - info.case_insensitive = 1; -#ifdef MODE_EXFAT - if (!ctxt.dir.have_stream) - continue; - info.mtimeset = grub_exfat_timestamp (grub_le_to_cpu32 (ctxt.entry.type_specific.file.m_time), - ctxt.entry.type_specific.file.m_time_tenth, - &info.mtime); -#else - if (ctxt.dir.attr & GRUB_FAT_ATTR_VOLUME_ID) - continue; - info.mtimeset = grub_fat_timestamp (grub_le_to_cpu16 (ctxt.dir.w_time), - grub_le_to_cpu16 (ctxt.dir.w_date), - &info.mtime); -#endif - if (info.mtimeset == 0) - grub_error (GRUB_ERR_OUT_OF_RANGE, - "invalid modification timestamp for %s", path); - - if (hook (ctxt.filename, &info, hook_data)) - break; + p = grub_fat_find_dir (disk, data, p, path, hook, hook_data); } - grub_fat_iterate_fini (&ctxt); - if (err == GRUB_ERR_EOF) - err = 0; + while (p && grub_errno == GRUB_ERR_NONE); fail: - if (found != &root) - grub_free (found); + grub_free (dirname); grub_free (data); grub_dl_unref (my_mod); @@ -1053,43 +1006,35 @@ static grub_err_t grub_fat_open (grub_file_t file, const char *name) { struct grub_fat_data *data = 0; - grub_fshelp_node_t found = NULL; - grub_err_t err; - grub_disk_t disk = file->device->disk; + char *p = (char *) name; grub_dl_ref (my_mod); - data = grub_fat_mount (disk); + data = grub_fat_mount (file->device->disk); if (! data) goto fail; - struct grub_fshelp_node root = { - .data = data, - .disk = disk, - .attr = GRUB_FAT_ATTR_DIRECTORY, - .file_size = 0, - .file_cluster = data->root_cluster, - .cur_cluster_num = ~0U, - .cur_cluster = 0, -#ifdef MODE_EXFAT - .is_contiguous = 0, -#endif - }; + do + { + p = grub_fat_find_dir (file->device->disk, data, p, name, 0, 0); + if (grub_errno != GRUB_ERR_NONE) + goto fail; + } + while (p); - err = grub_fshelp_find_file_lookup (name, &root, &found, lookup_file, NULL, GRUB_FSHELP_REG); - if (err) - goto fail; + if (data->attr & GRUB_FAT_ATTR_DIRECTORY) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file")); + goto fail; + } - file->data = found; - file->size = found->file_size; + file->data = data; + file->size = data->file_size; return GRUB_ERR_NONE; fail: - if (found != &root) - grub_free (found); - grub_free (data); grub_dl_unref (my_mod); @@ -1108,10 +1053,7 @@ grub_fat_read (grub_file_t file, char *buf, grub_size_t len) static grub_err_t grub_fat_close (grub_file_t file) { - grub_fshelp_node_t node = file->data; - - grub_free (node->data); - grub_free (node); + grub_free (file->data); grub_dl_unref (my_mod); @@ -1124,29 +1066,20 @@ grub_fat_label (grub_device_t device, char **label) { struct grub_fat_dir_entry dir; grub_ssize_t offset = -sizeof(dir); + struct grub_fat_data *data; grub_disk_t disk = device->disk; - struct grub_fshelp_node root = { - .disk = disk, - .attr = GRUB_FAT_ATTR_DIRECTORY, - .file_size = 0, - .cur_cluster_num = ~0U, - .cur_cluster = 0, - .is_contiguous = 0, - }; - root.data = grub_fat_mount (disk); - if (! root.data) + data = grub_fat_mount (disk); + if (! data) return grub_errno; - root.file_cluster = root.data->root_cluster; - *label = NULL; while (1) { offset += sizeof (dir); - if (grub_fat_read_data (disk, &root, 0, 0, + if (grub_fat_read_data (disk, data, 0, 0, offset, sizeof (dir), (char *) &dir) != sizeof (dir)) break; @@ -1166,7 +1099,7 @@ grub_fat_label (grub_device_t device, char **label) * GRUB_MAX_UTF8_PER_UTF16 + 1); if (!*label) { - grub_free (root.data); + grub_free (data); return grub_errno; } chc = dir.type_specific.volume_label.character_count; @@ -1178,7 +1111,7 @@ grub_fat_label (grub_device_t device, char **label) } } - grub_free (root.data); + grub_free (data); return grub_errno; } @@ -1187,32 +1120,30 @@ grub_fat_label (grub_device_t device, char **label) static grub_err_t grub_fat_label (grub_device_t device, char **label) { + struct grub_fat_data *data; grub_disk_t disk = device->disk; grub_err_t err; struct grub_fat_iterate_context ctxt; - struct grub_fshelp_node root = { - .disk = disk, - .attr = GRUB_FAT_ATTR_DIRECTORY, - .file_size = 0, - .cur_cluster_num = ~0U, - .cur_cluster = 0, - }; *label = 0; grub_dl_ref (my_mod); - root.data = grub_fat_mount (disk); - if (! root.data) + data = grub_fat_mount (disk); + if (! data) goto fail; - root.file_cluster = root.data->root_cluster; + if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY)) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + return 0; + } err = grub_fat_iterate_init (&ctxt); if (err) goto fail; - while (!(err = grub_fat_iterate_dir_next (&root, &ctxt))) + while (!(err = grub_fat_iterate_dir_next (disk, data, &ctxt))) if ((ctxt.dir.attr & ~GRUB_FAT_ATTR_ARCHIVE) == GRUB_FAT_ATTR_VOLUME_ID) { *label = grub_strdup (ctxt.filename); @@ -1225,7 +1156,7 @@ grub_fat_label (grub_device_t device, char **label) grub_dl_unref (my_mod); - grub_free (root.data); + grub_free (data); return grub_errno; } @@ -1290,12 +1221,12 @@ static struct grub_fs grub_fat_fs = #else .name = "fat", #endif - .fs_dir = grub_fat_dir, - .fs_open = grub_fat_open, - .fs_read = grub_fat_read, - .fs_close = grub_fat_close, - .fs_label = grub_fat_label, - .fs_uuid = grub_fat_uuid, + .dir = grub_fat_dir, + .open = grub_fat_open, + .read = grub_fat_read, + .close = grub_fat_close, + .label = grub_fat_label, + .uuid = grub_fat_uuid, #ifdef GRUB_UTIL #ifdef MODE_EXFAT /* ExFAT BPB is 30 larger than FAT32 one. */ diff --git a/grub-core/fs/fshelp.c b/grub-core/fs/fshelp.c index 4c902adf3..b899bed04 100644 --- a/grub-core/fs/fshelp.c +++ b/grub-core/fs/fshelp.c @@ -30,287 +30,169 @@ GRUB_MOD_LICENSE ("GPLv3+"); typedef int (*iterate_dir_func) (grub_fshelp_node_t dir, grub_fshelp_iterate_dir_hook_t hook, void *data); -typedef grub_err_t (*lookup_file_func) (grub_fshelp_node_t dir, - const char *name, - grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype); typedef char *(*read_symlink_func) (grub_fshelp_node_t node); -struct stack_element { - struct stack_element *parent; - grub_fshelp_node_t node; - enum grub_fshelp_filetype type; -}; - /* Context for grub_fshelp_find_file. */ struct grub_fshelp_find_file_ctx { - /* Inputs. */ const char *path; - grub_fshelp_node_t rootnode; - - /* Global options. */ + grub_fshelp_node_t rootnode, currroot, currnode, oldnode; + enum grub_fshelp_filetype foundtype; int symlinknest; - - /* Current file being traversed and its parents. */ - struct stack_element *currnode; + const char *name; + const char *next; + enum grub_fshelp_filetype type; }; /* Helper for find_file_iter. */ static void free_node (grub_fshelp_node_t node, struct grub_fshelp_find_file_ctx *ctx) { - if (node != ctx->rootnode) + if (node != ctx->rootnode && node != ctx->currroot) grub_free (node); } -static void -pop_element (struct grub_fshelp_find_file_ctx *ctx) -{ - struct stack_element *el; - el = ctx->currnode; - ctx->currnode = el->parent; - free_node (el->node, ctx); - grub_free (el); -} - -static void -free_stack (struct grub_fshelp_find_file_ctx *ctx) -{ - while (ctx->currnode) - pop_element (ctx); -} - -static void -go_up_a_level (struct grub_fshelp_find_file_ctx *ctx) -{ - if (!ctx->currnode->parent) - return; - pop_element (ctx); -} - -static grub_err_t -push_node (struct grub_fshelp_find_file_ctx *ctx, grub_fshelp_node_t node, enum grub_fshelp_filetype filetype) -{ - struct stack_element *nst; - nst = grub_malloc (sizeof (*nst)); - if (!nst) - return grub_errno; - nst->node = node; - nst->type = filetype & ~GRUB_FSHELP_CASE_INSENSITIVE; - nst->parent = ctx->currnode; - ctx->currnode = nst; - return GRUB_ERR_NONE; -} - -static grub_err_t -go_to_root (struct grub_fshelp_find_file_ctx *ctx) -{ - free_stack (ctx); - return push_node (ctx, ctx->rootnode, GRUB_FSHELP_DIR); -} - -struct grub_fshelp_find_file_iter_ctx -{ - const char *name; - grub_fshelp_node_t *foundnode; - enum grub_fshelp_filetype *foundtype; -}; - /* Helper for grub_fshelp_find_file. */ static int find_file_iter (const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node, void *data) { - struct grub_fshelp_find_file_iter_ctx *ctx = data; + struct grub_fshelp_find_file_ctx *ctx = data; if (filetype == GRUB_FSHELP_UNKNOWN || ((filetype & GRUB_FSHELP_CASE_INSENSITIVE) - ? grub_strcasecmp (ctx->name, filename) - : grub_strcmp (ctx->name, filename))) + ? grub_strncasecmp (ctx->name, filename, ctx->next - ctx->name) + : grub_strncmp (ctx->name, filename, ctx->next - ctx->name)) + || filename[ctx->next - ctx->name]) { grub_free (node); return 0; } /* The node is found, stop iterating over the nodes. */ - *ctx->foundnode = node; - *ctx->foundtype = filetype; + ctx->type = filetype & ~GRUB_FSHELP_CASE_INSENSITIVE; + ctx->oldnode = ctx->currnode; + ctx->currnode = node; + return 1; } static grub_err_t -directory_find_file (grub_fshelp_node_t node, const char *name, grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype, iterate_dir_func iterate_dir) -{ - int found; - struct grub_fshelp_find_file_iter_ctx ctx = { - .foundnode = foundnode, - .foundtype = foundtype, - .name = name - }; - found = iterate_dir (node, find_file_iter, &ctx); - if (! found) - { - if (grub_errno) - return grub_errno; - } - return GRUB_ERR_NONE; -} - -static grub_err_t -find_file (char *currpath, - iterate_dir_func iterate_dir, lookup_file_func lookup_file, - read_symlink_func read_symlink, +find_file (const char *currpath, grub_fshelp_node_t currroot, + grub_fshelp_node_t *currfound, + iterate_dir_func iterate_dir, read_symlink_func read_symlink, struct grub_fshelp_find_file_ctx *ctx) { - char *name, *next; - grub_err_t err; - for (name = currpath; ; name = next) + ctx->currroot = currroot; + ctx->name = currpath; + ctx->type = GRUB_FSHELP_DIR; + ctx->currnode = currroot; + ctx->oldnode = currroot; + + for (;;) { - char c; - grub_fshelp_node_t foundnode = NULL; - enum grub_fshelp_filetype foundtype = 0; + int found; /* Remove all leading slashes. */ - while (*name == '/') - name++; + while (*ctx->name == '/') + ctx->name++; /* Found the node! */ - if (! *name) - return 0; + if (! *ctx->name) + { + *currfound = ctx->currnode; + ctx->foundtype = ctx->type; + return 0; + } /* Extract the actual part from the pathname. */ - for (next = name; *next && *next != '/'; next++); + for (ctx->next = ctx->name; *ctx->next && *ctx->next != '/'; ctx->next++); /* At this point it is expected that the current node is a directory, check if this is true. */ - if (ctx->currnode->type != GRUB_FSHELP_DIR) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); - - /* Don't rely on fs providing actual . in the listing. */ - if (next - name == 1 && name[0] == '.') - continue; - - /* Don't rely on fs providing actual .. in the listing. */ - if (next - name == 2 && name[0] == '.' && name[1] == '.') + if (ctx->type != GRUB_FSHELP_DIR) { - go_up_a_level (ctx); - continue; + free_node (ctx->currnode, ctx); + ctx->currnode = 0; + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); } /* Iterate over the directory. */ - c = *next; - *next = '\0'; - if (lookup_file) - err = lookup_file (ctx->currnode->node, name, &foundnode, &foundtype); - else - err = directory_find_file (ctx->currnode->node, name, &foundnode, &foundtype, iterate_dir); - *next = c; + found = iterate_dir (ctx->currnode, find_file_iter, ctx); + if (! found) + { + free_node (ctx->currnode, ctx); + ctx->currnode = 0; + if (grub_errno) + return grub_errno; - if (err) - return err; + break; + } - if (!foundnode) - break; - - push_node (ctx, foundnode, foundtype); - /* Read in the symlink and follow it. */ - if (ctx->currnode->type == GRUB_FSHELP_SYMLINK) + if (ctx->type == GRUB_FSHELP_SYMLINK) { char *symlink; + const char *next; /* Test if the symlink does not loop. */ if (++ctx->symlinknest == 8) - return grub_error (GRUB_ERR_SYMLINK_LOOP, - N_("too deep nesting of symlinks")); + { + free_node (ctx->currnode, ctx); + free_node (ctx->oldnode, ctx); + ctx->currnode = 0; + ctx->oldnode = 0; + return grub_error (GRUB_ERR_SYMLINK_LOOP, + N_("too deep nesting of symlinks")); + } - symlink = read_symlink (ctx->currnode->node); + symlink = read_symlink (ctx->currnode); + free_node (ctx->currnode, ctx); + ctx->currnode = 0; if (!symlink) - return grub_errno; + { + free_node (ctx->oldnode, ctx); + ctx->oldnode = 0; + return grub_errno; + } /* The symlink is an absolute path, go back to the root inode. */ if (symlink[0] == '/') { - err = go_to_root (ctx); - if (err) - return err; + free_node (ctx->oldnode, ctx); + ctx->oldnode = ctx->rootnode; } - else - { - /* Get from symlink to containing directory. */ - go_up_a_level (ctx); - } - /* Lookup the node the symlink points to. */ - find_file (symlink, iterate_dir, lookup_file, read_symlink, ctx); + next = ctx->next; + find_file (symlink, ctx->oldnode, &ctx->currnode, + iterate_dir, read_symlink, ctx); + ctx->next = next; + ctx->type = ctx->foundtype; grub_free (symlink); if (grub_errno) - return grub_errno; + { + free_node (ctx->oldnode, ctx); + ctx->oldnode = 0; + return grub_errno; + } } + + if (ctx->oldnode != ctx->currnode) + { + free_node (ctx->oldnode, ctx); + ctx->oldnode = 0; + } + + ctx->name = ctx->next; } return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), ctx->path); } -static grub_err_t -grub_fshelp_find_file_real (const char *path, grub_fshelp_node_t rootnode, - grub_fshelp_node_t *foundnode, - iterate_dir_func iterate_dir, - lookup_file_func lookup_file, - read_symlink_func read_symlink, - enum grub_fshelp_filetype expecttype) -{ - struct grub_fshelp_find_file_ctx ctx = { - .path = path, - .rootnode = rootnode, - .symlinknest = 0, - .currnode = 0 - }; - grub_err_t err; - enum grub_fshelp_filetype foundtype; - char *duppath; - - if (!path || path[0] != '/') - { - return grub_error (GRUB_ERR_BAD_FILENAME, N_("invalid file name `%s'"), path); - } - - err = go_to_root (&ctx); - if (err) - return err; - - duppath = grub_strdup (path); - if (!duppath) - return grub_errno; - err = find_file (duppath, iterate_dir, lookup_file, read_symlink, &ctx); - grub_free (duppath); - if (err) - { - free_stack (&ctx); - return err; - } - - *foundnode = ctx.currnode->node; - foundtype = ctx.currnode->type; - /* Avoid the node being freed. */ - ctx.currnode->node = 0; - free_stack (&ctx); - - /* Check if the node that was found was of the expected type. */ - if (expecttype == GRUB_FSHELP_REG && foundtype != expecttype) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file")); - else if (expecttype == GRUB_FSHELP_DIR && foundtype != expecttype) - return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); - - return 0; -} - /* Lookup the node PATH. The node ROOTNODE describes the root of the directory tree. The node found is returned in FOUNDNODE, which is either a ROOTNODE or a new malloc'ed node. ITERATE_DIR is used to @@ -325,23 +207,31 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, read_symlink_func read_symlink, enum grub_fshelp_filetype expecttype) { - return grub_fshelp_find_file_real (path, rootnode, foundnode, - iterate_dir, NULL, - read_symlink, expecttype); + struct grub_fshelp_find_file_ctx ctx = { + .path = path, + .rootnode = rootnode, + .foundtype = GRUB_FSHELP_DIR, + .symlinknest = 0 + }; + grub_err_t err; -} + if (!path || path[0] != '/') + { + grub_error (GRUB_ERR_BAD_FILENAME, N_("invalid file name `%s'"), path); + return grub_errno; + } -grub_err_t -grub_fshelp_find_file_lookup (const char *path, grub_fshelp_node_t rootnode, - grub_fshelp_node_t *foundnode, - lookup_file_func lookup_file, - read_symlink_func read_symlink, - enum grub_fshelp_filetype expecttype) -{ - return grub_fshelp_find_file_real (path, rootnode, foundnode, - NULL, lookup_file, - read_symlink, expecttype); + err = find_file (path, rootnode, foundnode, iterate_dir, read_symlink, &ctx); + if (err) + return err; + /* Check if the node that was found was of the expected type. */ + if (expecttype == GRUB_FSHELP_REG && ctx.foundtype != expecttype) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file")); + else if (expecttype == GRUB_FSHELP_DIR && ctx.foundtype != expecttype) + return grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + + return 0; } /* Read LEN bytes from the file NODE on disk DISK into the buffer BUF, diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c index 3fe842b4d..f46f77a94 100644 --- a/grub-core/fs/hfs.c +++ b/grub-core/fs/hfs.c @@ -29,7 +29,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -693,7 +692,6 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx, int i; struct grub_hfs_extent *dat; int blk; - grub_uint16_t reccnt; dat = (struct grub_hfs_extent *) (type == 0 ? (&data->sblock.catalog_recs) @@ -712,12 +710,8 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx, return grub_errno; } - reccnt = grub_be_to_cpu16 (node->node.reccnt); - if (reccnt > (nodesize >> 1)) - reccnt = (nodesize >> 1); - /* Iterate over all records in this node. */ - for (i = 0; i < reccnt; i++) + for (i = 0; i < grub_be_to_cpu16 (node->node.reccnt); i++) { int pos = (nodesize >> 1) - 1 - i; struct pointer @@ -725,19 +719,16 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx, grub_uint8_t keylen; grub_uint8_t key; } GRUB_PACKED *pnt; - grub_uint16_t off = grub_be_to_cpu16 (node->offsets[pos]); - if (off > nodesize - sizeof(*pnt)) - continue; - pnt = (struct pointer *) (off + node->rawnode); - if (nodesize < (grub_size_t) off + pnt->keylen + 1) - continue; + pnt = (struct pointer *) (grub_be_to_cpu16 (node->offsets[pos]) + + node->rawnode); struct grub_hfs_record rec = { &pnt->key, pnt->keylen, &pnt->key + pnt->keylen +(pnt->keylen + 1) % 2, - nodesize - off - pnt->keylen - 1 + nodesize - grub_be_to_cpu16 (node->offsets[pos]) + - pnt->keylen - 1 }; if (node_hook (&node->node, &rec, hook_arg)) @@ -1126,81 +1117,90 @@ utf8_to_macroman (grub_uint8_t *to, const char *from) return optr - to; } -union grub_hfs_anyrec { - struct grub_hfs_filerec frec; - struct grub_hfs_dirrec dir; -}; - -struct grub_fshelp_node -{ - struct grub_hfs_data *data; - union grub_hfs_anyrec fdrec; - grub_uint32_t inode; -}; - -static grub_err_t -lookup_file (grub_fshelp_node_t dir, - const char *name, - grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype) -{ - struct grub_hfs_catalog_key key; - grub_ssize_t slen; - union grub_hfs_anyrec fdrec; - - key.parent_dir = grub_cpu_to_be32 (dir->inode); - slen = utf8_to_macroman (key.str, name); - if (slen < 0) - /* Not found */ - return GRUB_ERR_NONE; - key.strlen = slen; - - /* Lookup this node. */ - if (! grub_hfs_find_node (dir->data, (char *) &key, dir->data->cat_root, - 0, (char *) &fdrec.frec, sizeof (fdrec.frec))) - /* Not found */ - return GRUB_ERR_NONE; - - *foundnode = grub_malloc (sizeof (struct grub_fshelp_node)); - if (!*foundnode) - return grub_errno; - - (*foundnode)->inode = grub_be_to_cpu32 (fdrec.dir.dirid); - (*foundnode)->fdrec = fdrec; - (*foundnode)->data = dir->data; - *foundtype = (fdrec.frec.type == GRUB_HFS_FILETYPE_DIR) ? GRUB_FSHELP_DIR : GRUB_FSHELP_REG; - return GRUB_ERR_NONE; -} /* Find a file or directory with the pathname PATH in the filesystem DATA. Return the file record in RETDATA when it is non-zero. Return the directory number in RETINODE when it is non-zero. */ static grub_err_t grub_hfs_find_dir (struct grub_hfs_data *data, const char *path, - grub_fshelp_node_t *found, - enum grub_fshelp_filetype exptype) + struct grub_hfs_filerec *retdata, int *retinode) { - struct grub_fshelp_node root = { - .data = data, - .inode = data->rootdir, - .fdrec = { - .frec = { - .type = GRUB_HFS_FILETYPE_DIR - } - } - }; - grub_err_t err; + int inode = data->rootdir; + char *next; + char *origpath; + union { + struct grub_hfs_filerec frec; + struct grub_hfs_dirrec dir; + } fdrec; - err = grub_fshelp_find_file_lookup (path, &root, found, lookup_file, NULL, exptype); + fdrec.frec.type = GRUB_HFS_FILETYPE_DIR; - if (&root == *found) + if (path[0] != '/') { - *found = grub_malloc (sizeof (root)); - if (!*found) - return grub_errno; - grub_memcpy (*found, &root, sizeof (root)); + grub_error (GRUB_ERR_BAD_FILENAME, N_("invalid file name `%s'"), path); + return 0; } - return err; + + origpath = grub_strdup (path); + if (!origpath) + return grub_errno; + + path = origpath; + while (*path == '/') + path++; + + while (path && grub_strlen (path)) + { + grub_ssize_t slen; + if (fdrec.frec.type != GRUB_HFS_FILETYPE_DIR) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + goto fail; + } + + /* Isolate a part of the path. */ + next = grub_strchr (path, '/'); + if (next) + { + while (*next == '/') + *(next++) = '\0'; + } + + struct grub_hfs_catalog_key key; + + key.parent_dir = grub_cpu_to_be32 (inode); + slen = utf8_to_macroman (key.str, path); + if (slen < 0) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path); + goto fail; + } + key.strlen = slen; + + /* Lookup this node. */ + if (! grub_hfs_find_node (data, (char *) &key, data->cat_root, + 0, (char *) &fdrec.frec, sizeof (fdrec.frec))) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), origpath); + goto fail; + } + + if (grub_errno) + goto fail; + + inode = grub_be_to_cpu32 (fdrec.dir.dirid); + path = next; + } + + if (retdata) + grub_memcpy (retdata, &fdrec.frec, sizeof (fdrec.frec)); + + if (retinode) + *retinode = inode; + + fail: + grub_free (origpath); + return grub_errno; } struct grub_hfs_dir_hook_ctx @@ -1258,14 +1258,16 @@ static grub_err_t grub_hfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, void *hook_data) { + int inode; + struct grub_hfs_data *data; + struct grub_hfs_filerec frec; struct grub_hfs_dir_hook_ctx ctx = { .hook = hook, .hook_data = hook_data }; - grub_fshelp_node_t found = NULL; - + grub_dl_ref (my_mod); data = grub_hfs_mount (device->disk); @@ -1273,13 +1275,18 @@ grub_hfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, goto fail; /* First the directory ID for the directory. */ - if (grub_hfs_find_dir (data, path, &found, GRUB_FSHELP_DIR)) + if (grub_hfs_find_dir (data, path, &frec, &inode)) goto fail; - grub_hfs_iterate_dir (data, data->cat_root, found->inode, grub_hfs_dir_hook, &ctx); + if (frec.type != GRUB_HFS_FILETYPE_DIR) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); + goto fail; + } + + grub_hfs_iterate_dir (data, data->cat_root, inode, grub_hfs_dir_hook, &ctx); fail: - grub_free (found); grub_free (data); grub_dl_unref (my_mod); @@ -1293,36 +1300,35 @@ static grub_err_t grub_hfs_open (struct grub_file *file, const char *name) { struct grub_hfs_data *data; - grub_fshelp_node_t found = NULL; - + struct grub_hfs_filerec frec; + grub_dl_ref (my_mod); data = grub_hfs_mount (file->device->disk); - if (!data) - { - grub_dl_unref (my_mod); - return grub_errno; - } - - if (grub_hfs_find_dir (data, name, &found, GRUB_FSHELP_REG)) + if (grub_hfs_find_dir (data, name, &frec, 0)) { grub_free (data); - grub_free (found); grub_dl_unref (my_mod); return grub_errno; } - grub_memcpy (data->extents, found->fdrec.frec.extents, sizeof (grub_hfs_datarecord_t)); - file->size = grub_be_to_cpu32 (found->fdrec.frec.size); - data->size = grub_be_to_cpu32 (found->fdrec.frec.size); - data->fileid = grub_be_to_cpu32 (found->fdrec.frec.fileid); + if (frec.type != GRUB_HFS_FILETYPE_FILE) + { + grub_free (data); + grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a regular file")); + grub_dl_unref (my_mod); + return grub_errno; + } + + grub_memcpy (data->extents, frec.extents, sizeof (grub_hfs_datarecord_t)); + file->size = grub_be_to_cpu32 (frec.size); + data->size = grub_be_to_cpu32 (frec.size); + data->fileid = grub_be_to_cpu32 (frec.fileid); file->offset = 0; file->data = data; - grub_free (found); - return 0; } @@ -1360,7 +1366,7 @@ grub_hfs_label (grub_device_t device, char **label) grub_size_t len = data->sblock.volname[0]; if (len > sizeof (data->sblock.volname) - 1) len = sizeof (data->sblock.volname) - 1; - *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); + *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); if (*label) macroman_to_utf8 (*label, data->sblock.volname + 1, len + 1, 0); @@ -1417,13 +1423,13 @@ grub_hfs_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_hfs_fs = { .name = "hfs", - .fs_dir = grub_hfs_dir, - .fs_open = grub_hfs_open, - .fs_read = grub_hfs_read, - .fs_close = grub_hfs_close, - .fs_label = grub_hfs_label, - .fs_uuid = grub_hfs_uuid, - .fs_mtime = grub_hfs_mtime, + .dir = grub_hfs_dir, + .open = grub_hfs_open, + .read = grub_hfs_read, + .close = grub_hfs_close, + .label = grub_hfs_label, + .uuid = grub_hfs_uuid, + .mtime = grub_hfs_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 9c4e4c88c..950d8a1e1 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -31,7 +31,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -337,9 +336,6 @@ grub_hfsplus_mount (grub_disk_t disk) data->case_sensitive = ((magic == GRUB_HFSPLUSX_MAGIC) && (header.key_compare == GRUB_HFSPLUSX_BINARYCOMPARE)); - if (data->catalog_tree.nodesize < 2) - goto fail; - if (grub_hfsplus_read_file (&data->extoverflow_tree.file, 0, 0, sizeof (struct grub_hfsplus_btnode), sizeof (header), (char *) &header) <= 0) @@ -354,9 +350,6 @@ grub_hfsplus_mount (grub_disk_t disk) data->extoverflow_tree.root = grub_be_to_cpu32 (header.root); data->extoverflow_tree.nodesize = grub_be_to_cpu16 (header.nodesize); - if (data->extoverflow_tree.nodesize < 2) - goto fail; - if (grub_hfsplus_read_file (&data->attr_tree.file, 0, 0, sizeof (struct grub_hfsplus_btnode), sizeof (header), (char *) &header) <= 0) @@ -476,12 +469,8 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node) { char *symlink; grub_ssize_t numread; - grub_size_t sz = node->size; - if (grub_add (sz, 1, &sz)) - return NULL; - - symlink = grub_malloc (sz); + symlink = grub_malloc (node->size + 1); if (!symlink) return 0; @@ -666,7 +655,6 @@ list_nodes (void *record, void *hook_arg) char *filename; int i; struct grub_fshelp_node *node; - grub_uint16_t *keyname; struct grub_hfsplus_catfile *fileinfo; enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN; struct list_nodes_ctx *ctx = hook_arg; @@ -720,39 +708,34 @@ list_nodes (void *record, void *hook_arg) if (type == GRUB_FSHELP_UNKNOWN) return 0; - filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen), - GRUB_MAX_UTF8_PER_UTF16 + 1); + filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen) + * GRUB_MAX_UTF8_PER_UTF16 + 1); if (! filename) return 0; - keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); - if (!keyname) - { - grub_free (filename); - return 0; - } - /* Make sure the byte order of the UTF16 string is correct. */ for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++) { - keyname[i] = grub_be_to_cpu16 (catkey->name[i]); + catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]); - if (keyname[i] == '/') - keyname[i] = ':'; + if (catkey->name[i] == '/') + catkey->name[i] = ':'; /* If the name is obviously invalid, skip this node. */ - if (keyname[i] == 0) - { - grub_free (keyname); - grub_free (filename); - return 0; - } + if (catkey->name[i] == 0) + return 0; } - *grub_utf16_to_utf8 ((grub_uint8_t *) filename, keyname, + *grub_utf16_to_utf8 ((grub_uint8_t *) filename, catkey->name, grub_be_to_cpu16 (catkey->namelen)) = '\0'; - grub_free (keyname); + /* Restore the byte order to what it was previously. */ + for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++) + { + if (catkey->name[i] == ':') + catkey->name[i] = '/'; + catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]); + } /* hfs+ is case insensitive. */ if (! ctx->dir->data->case_sensitive) @@ -762,10 +745,7 @@ list_nodes (void *record, void *hook_arg) callback function. */ node = grub_malloc (sizeof (*node)); if (!node) - { - grub_free (filename); - return 1; - } + return 1; node->data = ctx->dir->data; node->compressed = 0; node->cbuf = 0; @@ -800,8 +780,8 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir, }; struct grub_hfsplus_key_internal intern; - struct grub_hfsplus_btnode *node = NULL; - grub_disk_addr_t ptr = 0; + struct grub_hfsplus_btnode *node; + grub_disk_addr_t ptr; { struct grub_fshelp_node *fsnode; @@ -983,10 +963,9 @@ grub_hfsplus_label (grub_device_t device, char **label) grub_disk_t disk = device->disk; struct grub_hfsplus_catkey *catkey; int i, label_len; - grub_uint16_t *label_name; struct grub_hfsplus_key_internal intern; - struct grub_hfsplus_btnode *node = NULL; - grub_disk_addr_t ptr = 0; + struct grub_hfsplus_btnode *node; + grub_disk_addr_t ptr; *label = 0; @@ -1012,41 +991,22 @@ grub_hfsplus_label (grub_device_t device, char **label) grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); label_len = grub_be_to_cpu16 (catkey->namelen); - label_name = grub_calloc (label_len, sizeof (*label_name)); - if (!label_name) - { - grub_free (node); - grub_free (data); - return grub_errno; - } - for (i = 0; i < label_len; i++) { - label_name[i] = grub_be_to_cpu16 (catkey->name[i]); + catkey->name[i] = grub_be_to_cpu16 (catkey->name[i]); /* If the name is obviously invalid, skip this node. */ - if (label_name[i] == 0) - { - grub_free (label_name); - grub_free (node); - grub_free (data); - return 0; - } + if (catkey->name[i] == 0) + return 0; } - *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); + *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); if (! *label) - { - grub_free (label_name); - grub_free (node); - grub_free (data); - return grub_errno; - } + return grub_errno; - *grub_utf16_to_utf8 ((grub_uint8_t *) (*label), label_name, + *grub_utf16_to_utf8 ((grub_uint8_t *) (*label), catkey->name, label_len) = '\0'; - grub_free (label_name); grub_free (node); grub_free (data); @@ -1106,13 +1066,13 @@ grub_hfsplus_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_hfsplus_fs = { .name = "hfsplus", - .fs_dir = grub_hfsplus_dir, - .fs_open = grub_hfsplus_open, - .fs_read = grub_hfsplus_read, - .fs_close = grub_hfsplus_close, - .fs_label = grub_hfsplus_label, - .fs_mtime = grub_hfsplus_mtime, - .fs_uuid = grub_hfsplus_uuid, + .dir = grub_hfsplus_dir, + .open = grub_hfsplus_open, + .read = grub_hfsplus_read, + .close = grub_hfsplus_close, + .label = grub_hfsplus_label, + .mtime = grub_hfsplus_mtime, + .uuid = grub_hfsplus_uuid, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c index 5ec4433b8..6a6677337 100644 --- a/grub-core/fs/iso9660.c +++ b/grub-core/fs/iso9660.c @@ -28,7 +28,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -332,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) int i; grub_uint16_t t[MAX_NAMELEN / 2 + 1]; - p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); + p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); if (! p) return NULL; @@ -532,22 +531,11 @@ add_part (struct iterate_dir_ctx *ctx, int len2) { int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; - grub_size_t sz; - char *new; - if (grub_add (size, len2, &sz) || - grub_add (sz, 1, &sz)) + ctx->symlink = grub_realloc (ctx->symlink, size + len2 + 1); + if (! ctx->symlink) return; - new = grub_realloc (ctx->symlink, sz); - if (!new) - { - grub_free (ctx->symlink); - ctx->symlink = NULL; - return; - } - ctx->symlink = new; - grub_memcpy (ctx->symlink + size, part, len2); ctx->symlink[size + len2] = 0; } @@ -572,24 +560,17 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, { grub_size_t off = 0, csize = 1; char *old; - grub_size_t sz; - csize = entry->len - 5; old = ctx->filename; if (ctx->filename_alloc) { off = grub_strlen (ctx->filename); - if (grub_add (csize, off, &sz) || - grub_add (sz, 1, &sz)) - return GRUB_ERR_OUT_OF_RANGE; - ctx->filename = grub_realloc (ctx->filename, sz); + ctx->filename = grub_realloc (ctx->filename, csize + off + 1); } else { off = 0; - if (grub_add (csize, 1, &sz)) - return GRUB_ERR_OUT_OF_RANGE; - ctx->filename = grub_zalloc (sz); + ctx->filename = grub_zalloc (csize + 1); } if (!ctx->filename) { @@ -640,12 +621,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, is the length. Both are part of the `Component Record'. */ if (ctx->symlink && !ctx->was_continue) - { - add_part (ctx, "/", 1); - if (grub_errno) - return grub_errno; - } - + add_part (ctx, "/", 1); add_part (ctx, (char *) &entry->data[pos + 2], entry->data[pos + 1]); ctx->was_continue = (entry->data[pos] & 1); @@ -664,11 +640,6 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, add_part (ctx, "/", 1); break; } - - /* Check if grub_realloc() failed in add_part(). */ - if (grub_errno) - return grub_errno; - /* In pos + 1 the length of the `Component Record' is stored. */ pos += entry->data[pos + 1] + 2; @@ -779,15 +750,19 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, if (dir->data->joliet && !ctx.filename) { - char *semicolon; + char *oldname, *semicolon; + oldname = name; ctx.filename = grub_iso9660_convert_string - ((grub_uint8_t *) name, dirent.namelen >> 1); + ((grub_uint8_t *) oldname, dirent.namelen >> 1); semicolon = grub_strrchr (ctx.filename, ';'); if (semicolon) *semicolon = '\0'; + if (ctx.filename_alloc) + grub_free (oldname); + ctx.filename_alloc = 1; } @@ -805,18 +780,14 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, if (node->have_dirents >= node->alloc_dirents) { struct grub_fshelp_node *new_node; - grub_size_t sz; - - if (grub_mul (node->alloc_dirents, 2, &node->alloc_dirents) || - grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || - grub_mul (sz, sizeof (node->dirents[0]), &sz) || - grub_add (sz, sizeof (struct grub_fshelp_node), &sz)) - goto fail_0; - - new_node = grub_realloc (node, sz); + node->alloc_dirents *= 2; + new_node = grub_realloc (node, + sizeof (struct grub_fshelp_node) + + ((node->alloc_dirents + - ARRAY_SIZE (node->dirents)) + * sizeof (node->dirents[0]))); if (!new_node) { - fail_0: if (ctx.filename_alloc) grub_free (ctx.filename); grub_free (node); @@ -832,18 +803,14 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, * sizeof (node->dirents[0]) < grub_strlen (ctx.symlink) + 1) { struct grub_fshelp_node *new_node; - grub_size_t sz; - - if (grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || - grub_mul (sz, sizeof (node->dirents[0]), &sz) || - grub_add (sz, sizeof (struct grub_fshelp_node) + 1, &sz) || - grub_add (sz, grub_strlen (ctx.symlink), &sz)) - goto fail_1; - - new_node = grub_realloc (node, sz); + new_node = grub_realloc (node, + sizeof (struct grub_fshelp_node) + + ((node->alloc_dirents + - ARRAY_SIZE (node->dirents)) + * sizeof (node->dirents[0])) + + grub_strlen (ctx.symlink) + 1); if (!new_node) { - fail_1: if (ctx.filename_alloc) grub_free (ctx.filename); grub_free (node); @@ -992,15 +959,14 @@ grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len) { struct grub_iso9660_data *data = (struct grub_iso9660_data *) file->data; - grub_err_t err; /* XXX: The file is stored in as a single extent. */ data->disk->read_hook = file->read_hook; data->disk->read_hook_data = file->read_hook_data; - err = read_node (data->node, file->offset, len, buf); + read_node (data->node, file->offset, len, buf); data->disk->read_hook = NULL; - if (err || grub_errno) + if (grub_errno) return -1; return len; @@ -1136,13 +1102,13 @@ grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf) static struct grub_fs grub_iso9660_fs = { .name = "iso9660", - .fs_dir = grub_iso9660_dir, - .fs_open = grub_iso9660_open, - .fs_read = grub_iso9660_read, - .fs_close = grub_iso9660_close, - .fs_label = grub_iso9660_label, - .fs_uuid = grub_iso9660_uuid, - .fs_mtime = grub_iso9660_mtime, + .dir = grub_iso9660_dir, + .open = grub_iso9660_open, + .read = grub_iso9660_read, + .close = grub_iso9660_close, + .label = grub_iso9660_label, + .uuid = grub_iso9660_uuid, + .mtime = grub_iso9660_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c index d5a6d6527..aab3e8c7b 100644 --- a/grub-core/fs/jfs.c +++ b/grub-core/fs/jfs.c @@ -505,10 +505,6 @@ le_to_cpu16_copy (grub_uint16_t *out, grub_uint16_t *in, grub_size_t len) *out++ = grub_le_to_cpu16 (*in++); } -#if __GNUC__ >= 9 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Waddress-of-packed-member" -#endif /* Read in the next dirent from the directory described by DIRO. */ static grub_err_t @@ -586,9 +582,6 @@ grub_jfs_getent (struct grub_jfs_diropen *diro) return 0; } -#if __GNUC__ >= 9 -#pragma GCC diagnostic pop -#endif /* Read LEN bytes from the file described by DATA starting with byte POS. Return the amount of read bytes in READ. */ @@ -937,12 +930,12 @@ grub_jfs_label (grub_device_t device, char **label) static struct grub_fs grub_jfs_fs = { .name = "jfs", - .fs_dir = grub_jfs_dir, - .fs_open = grub_jfs_open, - .fs_read = grub_jfs_read, - .fs_close = grub_jfs_close, - .fs_label = grub_jfs_label, - .fs_uuid = grub_jfs_uuid, + .dir = grub_jfs_dir, + .open = grub_jfs_open, + .read = grub_jfs_read, + .close = grub_jfs_close, + .label = grub_jfs_label, + .uuid = grub_jfs_uuid, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/minix.c b/grub-core/fs/minix.c index d0d08363c..90ddd34f1 100644 --- a/grub-core/fs/minix.c +++ b/grub-core/fs/minix.c @@ -82,6 +82,17 @@ typedef grub_uint16_t grub_minix_ino_t; #define GRUB_MINIX_INODE_DINDIR_ZONE(data) (grub_minix_to_cpu_n \ (data->inode.double_indir_zone)) +#ifndef MODE_MINIX3 +#define GRUB_MINIX_LOG2_ZONESZ (GRUB_MINIX_LOG2_BSIZE \ + + grub_minix_to_cpu16 (data->sblock.log2_zone_size)) +#endif + +#ifdef MODE_MINIX3 +#define GRUB_MINIX_ZONE2SECT(zone) ((zone) * data->block_size) +#else +#define GRUB_MINIX_ZONE2SECT(zone) ((zone) << GRUB_MINIX_LOG2_ZONESZ) +#endif + #ifdef MODE_MINIX3 struct grub_minix_sblock @@ -171,32 +182,15 @@ static grub_dl_t my_mod; static grub_err_t grub_minix_find_file (struct grub_minix_data *data, const char *path); -#ifdef MODE_MINIX3 -static inline grub_disk_addr_t -grub_minix_zone2sect (struct grub_minix_data *data, grub_minix_uintn_t zone) -{ - return ((grub_disk_addr_t) zone) * data->block_size; -} -#else -static inline grub_disk_addr_t -grub_minix_zone2sect (struct grub_minix_data *data, grub_minix_uintn_t zone) -{ - int log2_zonesz = (GRUB_MINIX_LOG2_BSIZE - + grub_minix_to_cpu16 (data->sblock.log2_zone_size)); - return (((grub_disk_addr_t) zone) << log2_zonesz); -} -#endif - - /* Read the block pointer in ZONE, on the offset NUM. */ static grub_minix_uintn_t -grub_get_indir (struct grub_minix_data *data, +grub_get_indir (struct grub_minix_data *data, grub_minix_uintn_t zone, grub_minix_uintn_t num) { grub_minix_uintn_t indirn; grub_disk_read (data->disk, - grub_minix_zone2sect(data, zone), + GRUB_MINIX_ZONE2SECT(zone), sizeof (grub_minix_uintn_t) * num, sizeof (grub_minix_uintn_t), (char *) &indirn); return grub_minix_to_cpu_n (indirn); @@ -287,7 +281,7 @@ grub_minix_read_file (struct grub_minix_data *data, for (i = posblock; i < blockcnt; i++) { - grub_minix_uintn_t blknr; + grub_disk_addr_t blknr; grub_uint64_t blockend = data->block_size << GRUB_DISK_SECTOR_BITS; grub_off_t skipfirst = 0; @@ -316,7 +310,7 @@ grub_minix_read_file (struct grub_minix_data *data, data->disk->read_hook = read_hook; data->disk->read_hook_data = read_hook_data; grub_disk_read (data->disk, - grub_minix_zone2sect(data, blknr), + GRUB_MINIX_ZONE2SECT(blknr), skipfirst, blockend, buf); data->disk->read_hook = 0; if (grub_errno) @@ -342,8 +336,7 @@ grub_minix_read_inode (struct grub_minix_data *data, grub_minix_ino_t ino) /* The first inode in minix is inode 1. */ ino--; - block = grub_minix_zone2sect (data, - 2 + grub_minix_to_cpu16 (sblock->inode_bmap_size) + block = GRUB_MINIX_ZONE2SECT (2 + grub_minix_to_cpu16 (sblock->inode_bmap_size) + grub_minix_to_cpu16 (sblock->zone_bmap_size)); block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)); int offs = (ino % (GRUB_DISK_SECTOR_SIZE @@ -687,10 +680,10 @@ static struct grub_fs grub_minix_fs = .name = "minix", #endif #endif - .fs_dir = grub_minix_dir, - .fs_open = grub_minix_open, - .fs_read = grub_minix_read, - .fs_close = grub_minix_close, + .dir = grub_minix_dir, + .open = grub_minix_open, + .read = grub_minix_read, + .close = grub_minix_close, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c index 7ed148d3b..598a2a55b 100644 --- a/grub-core/fs/nilfs2.c +++ b/grub-core/fs/nilfs2.c @@ -1192,13 +1192,13 @@ grub_nilfs2_mtime (grub_device_t device, grub_int32_t * tm) static struct grub_fs grub_nilfs2_fs = { .name = "nilfs2", - .fs_dir = grub_nilfs2_dir, - .fs_open = grub_nilfs2_open, - .fs_read = grub_nilfs2_read, - .fs_close = grub_nilfs2_close, - .fs_label = grub_nilfs2_label, - .fs_uuid = grub_nilfs2_uuid, - .fs_mtime = grub_nilfs2_mtime, + .dir = grub_nilfs2_dir, + .open = grub_nilfs2_open, + .read = grub_nilfs2_read, + .close = grub_nilfs2_close, + .label = grub_nilfs2_label, + .uuid = grub_nilfs2_uuid, + .mtime = grub_nilfs2_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 0, diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c index 2f34f76da..d3a91f5d7 100644 --- a/grub-core/fs/ntfs.c +++ b/grub-core/fs/ntfs.c @@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) grub_uint16_t *tmp; grub_size_t i; - buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); - tmp = grub_calloc (len, sizeof (tmp[0])); + buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); + tmp = grub_malloc (len * sizeof (tmp[0])); if (!buf || !tmp) { grub_free (buf); @@ -618,10 +618,7 @@ list_file (struct grub_ntfs_file *diro, grub_uint8_t *pos, ustr = get_utf8 (np, ns); if (ustr == NULL) - { - grub_free (fdiro); - return 0; - } + return 0; if (namespace) type |= GRUB_FSHELP_CASE_INSENSITIVE; @@ -920,16 +917,12 @@ grub_ntfs_mount (grub_disk_t disk) if (bpb.clusters_per_mft > 0) data->mft_size = ((grub_disk_addr_t) bpb.clusters_per_mft) << data->log_spc; - else if (-bpb.clusters_per_mft < GRUB_NTFS_BLK_SHR || -bpb.clusters_per_mft >= 31) - goto fail; else data->mft_size = 1ULL << (-bpb.clusters_per_mft - GRUB_NTFS_BLK_SHR); if (bpb.clusters_per_index > 0) data->idx_size = (((grub_disk_addr_t) bpb.clusters_per_index) << data->log_spc); - else if (-bpb.clusters_per_index < GRUB_NTFS_BLK_SHR || -bpb.clusters_per_index >= 31) - goto fail; else data->idx_size = 1ULL << (-bpb.clusters_per_index - GRUB_NTFS_BLK_SHR); @@ -1212,12 +1205,12 @@ grub_ntfs_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_ntfs_fs = { .name = "ntfs", - .fs_dir = grub_ntfs_dir, - .fs_open = grub_ntfs_open, - .fs_read = grub_ntfs_read, - .fs_close = grub_ntfs_close, - .fs_label = grub_ntfs_label, - .fs_uuid = grub_ntfs_uuid, + .dir = grub_ntfs_dir, + .open = grub_ntfs_open, + .read = grub_ntfs_read, + .close = grub_ntfs_close, + .label = grub_ntfs_label, + .uuid = grub_ntfs_uuid, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/ntfscomp.c b/grub-core/fs/ntfscomp.c index 3cd97d337..2e1ce51a8 100644 --- a/grub-core/fs/ntfscomp.c +++ b/grub-core/fs/ntfscomp.c @@ -104,7 +104,7 @@ decomp_block (struct grub_ntfs_comp *cc, grub_uint8_t *dest) if (tag & 1) { grub_uint32_t i, len, delta, code, lmask, dshift; - grub_uint16_t word = 0; + grub_uint16_t word; if (decomp_get16 (cc, &word)) return grub_errno; diff --git a/grub-core/fs/proc.c b/grub-core/fs/proc.c index 5f516502d..a03469ec6 100644 --- a/grub-core/fs/proc.c +++ b/grub-core/fs/proc.c @@ -22,7 +22,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -75,44 +74,6 @@ grub_procdev_write (grub_disk_t disk __attribute ((unused)), return GRUB_ERR_OUT_OF_RANGE; } -struct grub_archelp_data -{ - struct grub_procfs_entry *entry, *next_entry; -}; - -static void -grub_procfs_rewind (struct grub_archelp_data *data) -{ - data->entry = NULL; - data->next_entry = grub_procfs_entries; -} - -static grub_err_t -grub_procfs_find_file (struct grub_archelp_data *data, char **name, - grub_int32_t *mtime, - grub_uint32_t *mode) -{ - data->entry = data->next_entry; - if (!data->entry) - { - *mode = GRUB_ARCHELP_ATTR_END; - return GRUB_ERR_NONE; - } - data->next_entry = data->entry->next; - *mode = GRUB_ARCHELP_ATTR_FILE | GRUB_ARCHELP_ATTR_NOTIME; - *name = grub_strdup (data->entry->name); - *mtime = 0; - if (!*name) - return grub_errno; - return GRUB_ERR_NONE; -} - -static struct grub_archelp_ops arcops = - { - .find_file = grub_procfs_find_file, - .rewind = grub_procfs_rewind - }; - static grub_ssize_t grub_procfs_read (grub_file_t file, char *buf, grub_size_t len) { @@ -138,55 +99,64 @@ static grub_err_t grub_procfs_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, void *hook_data) { - struct grub_archelp_data data; + const char *ptr; + struct grub_dirhook_info info; + struct grub_procfs_entry *entry; + + grub_memset (&info, 0, sizeof (info)); /* Check if the disk is our dummy disk. */ if (grub_strcmp (device->disk->name, "proc")) return grub_error (GRUB_ERR_BAD_FS, "not a procfs"); - - grub_procfs_rewind (&data); - - return grub_archelp_dir (&data, &arcops, - path, hook, hook_data); + for (ptr = path; *ptr == '/'; ptr++); + if (*ptr) + return 0; + FOR_LIST_ELEMENTS((entry), (grub_procfs_entries)) + if (hook (entry->name, &info, hook_data)) + return 0; + return 0; } static grub_err_t grub_procfs_open (struct grub_file *file, const char *path) { - grub_err_t err; - struct grub_archelp_data data; - grub_size_t sz; + const char *pathptr; + struct grub_procfs_entry *entry; - grub_procfs_rewind (&data); + for (pathptr = path; *pathptr == '/'; pathptr++); - err = grub_archelp_open (&data, &arcops, path); - if (err) - return err; - file->data = data.entry->get_contents (&sz); - if (!file->data) - return grub_errno; - file->size = sz; - return GRUB_ERR_NONE; + FOR_LIST_ELEMENTS((entry), (grub_procfs_entries)) + if (grub_strcmp (pathptr, entry->name) == 0) + { + grub_size_t sz; + file->data = entry->get_contents (&sz); + if (!file->data) + return grub_errno; + file->size = sz; + return GRUB_ERR_NONE; + } + + return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), path); } static struct grub_disk_dev grub_procfs_dev = { .name = "proc", .id = GRUB_DISK_DEVICE_PROCFS_ID, - .disk_iterate = grub_procdev_iterate, - .disk_open = grub_procdev_open, - .disk_close = grub_procdev_close, - .disk_read = grub_procdev_read, - .disk_write = grub_procdev_write, + .iterate = grub_procdev_iterate, + .open = grub_procdev_open, + .close = grub_procdev_close, + .read = grub_procdev_read, + .write = grub_procdev_write, .next = 0 }; static struct grub_fs grub_procfs_fs = { .name = "procfs", - .fs_dir = grub_procfs_dir, - .fs_open = grub_procfs_open, - .fs_read = grub_procfs_read, - .fs_close = grub_procfs_close, + .dir = grub_procfs_dir, + .open = grub_procfs_open, + .read = grub_procfs_read, + .close = grub_procfs_close, .next = 0 }; diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c index af6a226a7..de3d4fa3c 100644 --- a/grub-core/fs/reiserfs.c +++ b/grub-core/fs/reiserfs.c @@ -783,30 +783,12 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, struct grub_reiserfs_key entry_key; enum grub_fshelp_filetype entry_type; char *entry_name; - char *entry_name_end = 0; - char c; if (!(entry_state & GRUB_REISERFS_VISIBLE_MASK)) continue; entry_name = (((char *) directory_headers) + grub_le_to_cpu16 (directory_header->location)); - if (entry_number == 0) - { - entry_name_end = (char *) block_header - + grub_le_to_cpu16 (item_headers[block_position].item_location) - + grub_le_to_cpu16 (item_headers[block_position].item_size); - } - else - { - entry_name_end = (((char *) directory_headers) - + grub_le_to_cpu16 (directory_headers[entry_number - 1].location)); - } - if (entry_name_end < entry_name || entry_name_end > (char *) block_header + block_size) - { - entry_name_end = (char *) block_header + block_size; - } - entry_key.directory_id = directory_header->directory_id; entry_key.object_id = directory_header->object_id; entry_key.u.v2.offset_type = 0; @@ -953,7 +935,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, else { /* Pseudo file ".." never has stat block. */ - if (entry_name_end == entry_name + 2 && grub_memcmp (entry_name, "..", 2) != 0) + if (grub_strcmp (entry_name, "..")) grub_dprintf ("reiserfs", "Warning : %s has no stat block !\n", entry_name); @@ -961,21 +943,18 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, goto next; } } - - c = *entry_name_end; - *entry_name_end = 0; if (hook (entry_name, entry_type, entry_item, hook_data)) { - *entry_name_end = c; grub_dprintf ("reiserfs", "Found : %s, type=%d\n", entry_name, entry_type); ret = 1; goto found; } - *entry_name_end = c; next: - ; + *entry_name = 0; /* Make sure next entry name (which is just + before this one in disk order) stops before + the current one. */ } if (next_offset == 0) @@ -1111,7 +1090,7 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node, switch (found.type) { case GRUB_REISERFS_DIRECT: - block = ((grub_disk_addr_t) found.block_number) * (block_size >> GRUB_DISK_SECTOR_BITS); + block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS); grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block); if (initial_position < current_position + item_size) { @@ -1402,12 +1381,12 @@ grub_reiserfs_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_reiserfs_fs = { .name = "reiserfs", - .fs_dir = grub_reiserfs_dir, - .fs_open = grub_reiserfs_open, - .fs_read = grub_reiserfs_read, - .fs_close = grub_reiserfs_close, - .fs_label = grub_reiserfs_label, - .fs_uuid = grub_reiserfs_uuid, + .dir = grub_reiserfs_dir, + .open = grub_reiserfs_open, + .read = grub_reiserfs_read, + .close = grub_reiserfs_close, + .label = grub_reiserfs_label, + .uuid = grub_reiserfs_uuid, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/romfs.c b/grub-core/fs/romfs.c index d97b8fbb8..2e3544408 100644 --- a/grub-core/fs/romfs.c +++ b/grub-core/fs/romfs.c @@ -461,11 +461,11 @@ grub_romfs_label (grub_device_t device, char **label) static struct grub_fs grub_romfs_fs = { .name = "romfs", - .fs_dir = grub_romfs_dir, - .fs_open = grub_romfs_open, - .fs_read = grub_romfs_read, - .fs_close = grub_romfs_close, - .fs_label = grub_romfs_label, + .dir = grub_romfs_dir, + .open = grub_romfs_open, + .read = grub_romfs_read, + .close = grub_romfs_close, + .label = grub_romfs_label, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 0, diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c index de2b107a4..6c8215048 100644 --- a/grub-core/fs/sfs.c +++ b/grub-core/fs/sfs.c @@ -26,7 +26,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -174,11 +173,10 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block, struct grub_sfs_btree *tree; int i; grub_uint32_t next; - grub_size_t blocksize = GRUB_DISK_SECTOR_SIZE << data->log_blocksize; - treeblock = grub_malloc (blocksize); - if (!treeblock) - return grub_errno; + treeblock = grub_malloc (GRUB_DISK_SECTOR_SIZE << data->log_blocksize); + if (!block) + return 0; next = grub_be_to_cpu32 (data->rblock.btree); tree = (struct grub_sfs_btree *) treeblock; @@ -186,21 +184,17 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block, /* Handle this level in the btree. */ do { - grub_uint16_t nnodes; grub_disk_read (data->disk, ((grub_disk_addr_t) next) << data->log_blocksize, - 0, blocksize, treeblock); + 0, GRUB_DISK_SECTOR_SIZE << data->log_blocksize, + treeblock); if (grub_errno) { grub_free (treeblock); return grub_errno; } - nnodes = grub_be_to_cpu16 (tree->nodes); - if (nnodes * (grub_uint32_t) (tree)->nodesize > blocksize) - break; - - for (i = (int) nnodes - 1; i >= 0; i--) + for (i = grub_be_to_cpu16 (tree->nodes) - 1; i >= 0; i--) { #define EXTNODE(tree, index) \ @@ -267,7 +261,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) node->next_extent = node->block; node->cache_size = 0; - node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); + node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); if (!node->cache) { grub_errno = 0; @@ -308,15 +302,10 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) if (node->cache && node->cache_size >= node->cache_allocated) { struct cache_entry *e = node->cache; - grub_size_t sz; - - if (grub_mul (node->cache_allocated, 2 * sizeof (e[0]), &sz)) - goto fail; - - e = grub_realloc (node->cache, sz); + e = grub_realloc (node->cache,node->cache_allocated * 2 + * sizeof (e[0])); if (!e) { - fail: grub_errno = 0; grub_free (node->cache); node->cache = 0; @@ -483,16 +472,10 @@ grub_sfs_create_node (struct grub_fshelp_node **node, grub_size_t len = grub_strlen (name); grub_uint8_t *name_u8; int ret; - grub_size_t sz; - - if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || - grub_add (sz, 1, &sz)) - return 1; - *node = grub_malloc (sizeof (**node)); if (!*node) return 1; - name_u8 = grub_malloc (sz); + name_u8 = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); if (!name_u8) { grub_free (*node); @@ -736,13 +719,8 @@ grub_sfs_label (grub_device_t device, char **label) data = grub_sfs_mount (disk); if (data) { - grub_size_t sz, len = grub_strlen (data->label); - - if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || - grub_add (sz, 1, &sz)) - return GRUB_ERR_OUT_OF_RANGE; - - *label = grub_malloc (sz); + grub_size_t len = grub_strlen (data->label); + *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); if (*label) *grub_latin1_to_utf8 ((grub_uint8_t *) *label, (const grub_uint8_t *) data->label, @@ -758,11 +736,11 @@ grub_sfs_label (grub_device_t device, char **label) static struct grub_fs grub_sfs_fs = { .name = "sfs", - .fs_dir = grub_sfs_dir, - .fs_open = grub_sfs_open, - .fs_read = grub_sfs_read, - .fs_close = grub_sfs_close, - .fs_label = grub_sfs_label, + .dir = grub_sfs_dir, + .open = grub_sfs_open, + .read = grub_sfs_read, + .close = grub_sfs_close, + .label = grub_sfs_label, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 1, diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index a5f35c10e..b97b34440 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "xz.h" @@ -460,17 +459,7 @@ grub_squash_read_symlink (grub_fshelp_node_t node) { char *ret; grub_err_t err; - grub_size_t sz; - - if (grub_add (grub_le_to_cpu32 (node->ino.symlink.namelen), 1, &sz)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - return NULL; - } - - ret = grub_malloc (sz); - if (!ret) - return NULL; + ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); err = read_chunk (node->data, ret, grub_le_to_cpu32 (node->ino.symlink.namelen), @@ -517,16 +506,11 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, { grub_fshelp_node_t node; - grub_size_t sz; - - if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || - grub_add (sz, sizeof (*node), &sz)) - return 0; - - node = grub_malloc (sz); + node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); if (!node) return 0; - grub_memcpy (node, dir, sz); + grub_memcpy (node, dir, + sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); if (hook (".", GRUB_FSHELP_DIR, node, hook_data)) return 1; @@ -534,15 +518,12 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, { grub_err_t err; - if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || - grub_add (sz, sizeof (*node), &sz)) - return 0; - - node = grub_malloc (sz); + node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); if (!node) return 0; - grub_memcpy (node, dir, sz); + grub_memcpy (node, dir, + sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); node->stsize--; err = read_chunk (dir->data, &node->ino, sizeof (node->ino), @@ -576,7 +557,6 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; struct grub_squash_dirent di; struct grub_squash_inode ino; - grub_size_t sz; err = read_chunk (dir->data, &di, sizeof (di), grub_le_to_cpu64 (dir->data->sb.diroffset) @@ -609,16 +589,13 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) filetype = GRUB_FSHELP_SYMLINK; - if (grub_add (dir->stsize, 1, &sz) || - grub_mul (sz, sizeof (dir->stack[0]), &sz) || - grub_add (sz, sizeof (*node), &sz)) - return 0; - - node = grub_malloc (sz); + node = grub_malloc (sizeof (*node) + + (dir->stsize + 1) * sizeof (dir->stack[0])); if (! node) return 0; - grub_memcpy (node, dir, sz - sizeof(dir->stack[0])); + grub_memcpy (node, dir, + sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); node->ino = ino; node->stack[node->stsize].ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); @@ -769,7 +746,7 @@ direct_read (struct grub_squash_data *data, struct grub_squash_cache_inode *ino, grub_off_t off, char *buf, grub_size_t len) { - grub_err_t err = GRUB_ERR_NONE; + grub_err_t err; grub_off_t cumulated_uncompressed_size = 0; grub_uint64_t a = 0; grub_size_t i; @@ -846,12 +823,7 @@ direct_read (struct grub_squash_data *data, curread = data->blksz - boff; if (curread > len) curread = len; - if (!ino->block_sizes[i]) - { - /* Sparse block */ - grub_memset (buf, '\0', curread); - } - else if (!(ino->block_sizes[i] + if (!(ino->block_sizes[i] & grub_cpu_to_le32_compile_time (SQUASH_BLOCK_UNCOMPRESSED))) { char *block; @@ -901,57 +873,36 @@ direct_read (struct grub_squash_data *data, static grub_ssize_t -grub_squash_read (grub_file_t file, char *buf, grub_size_t len) +grub_squash_read_data (struct grub_squash_data *data, + struct grub_squash_cache_inode *ino, + grub_off_t off, char *buf, grub_size_t len) { - struct grub_squash_data *data = file->data; - struct grub_squash_cache_inode *ino = &data->ino; - grub_off_t off = file->offset; grub_err_t err; - grub_uint64_t a, b; + grub_uint64_t a = 0, b; grub_uint32_t fragment = 0; int compressed = 0; struct grub_squash_frag_desc frag; - grub_off_t direct_len; - grub_uint64_t mask = grub_le_to_cpu32 (data->sb.block_size) - 1; - grub_size_t orig_len = len; switch (ino->ino.type) { case grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR): + a = grub_le_to_cpu64 (ino->ino.long_file.chunk); fragment = grub_le_to_cpu32 (ino->ino.long_file.fragment); break; case grub_cpu_to_le16_compile_time (SQUASH_TYPE_REGULAR): + a = grub_le_to_cpu32 (ino->ino.file.chunk); fragment = grub_le_to_cpu32 (ino->ino.file.fragment); break; } - /* Squash may pack file tail as fragment. So read initial part directly and - get tail from fragments */ - direct_len = fragment == 0xffffffff ? file->size : file->size & ~mask; - if (off < direct_len) - { - grub_size_t read_len = direct_len - off; - grub_ssize_t res; - - if (read_len > len) - read_len = len; - res = direct_read (data, ino, off, buf, read_len); - if ((grub_size_t) res != read_len) - return -1; /* FIXME: is short read possible here? */ - len -= read_len; - if (!len) - return read_len; - buf += read_len; - off = 0; - } - else - off -= direct_len; + if (fragment == 0xffffffff) + return direct_read (data, ino, off, buf, len); err = read_chunk (data, &frag, sizeof (frag), data->fragments, sizeof (frag) * fragment); if (err) return -1; - a = grub_le_to_cpu64 (frag.offset); + a += grub_le_to_cpu64 (frag.offset); compressed = !(frag.size & grub_cpu_to_le32_compile_time (SQUASH_BLOCK_UNCOMPRESSED)); if (ino->ino.type == grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR)) b = grub_le_to_cpu32 (ino->ino.long_file.offset) + off; @@ -992,7 +943,16 @@ grub_squash_read (grub_file_t file, char *buf, grub_size_t len) if (err) return -1; } - return orig_len; + return len; +} + +static grub_ssize_t +grub_squash_read (grub_file_t file, char *buf, grub_size_t len) +{ + struct grub_squash_data *data = file->data; + + return grub_squash_read_data (data, &data->ino, + file->offset, buf, len); } static grub_err_t @@ -1018,11 +978,11 @@ grub_squash_mtime (grub_device_t dev, grub_int32_t *tm) static struct grub_fs grub_squash_fs = { .name = "squash4", - .fs_dir = grub_squash_dir, - .fs_open = grub_squash_open, - .fs_read = grub_squash_read, - .fs_close = grub_squash_close, - .fs_mtime = grub_squash_mtime, + .dir = grub_squash_dir, + .open = grub_squash_open, + .read = grub_squash_read, + .close = grub_squash_close, + .mtime = grub_squash_mtime, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 0, diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c index c551ed6b5..39bf197aa 100644 --- a/grub-core/fs/tar.c +++ b/grub-core/fs/tar.c @@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, if (data->linkname_alloc < linksize + 1) { char *n; - n = grub_calloc (2, linksize + 1); + n = grub_malloc (2 * (linksize + 1)); if (!n) return grub_errno; grub_free (data->linkname); @@ -324,10 +324,10 @@ grub_cpio_close (grub_file_t file) static struct grub_fs grub_cpio_fs = { .name = "tarfs", - .fs_dir = grub_cpio_dir, - .fs_open = grub_cpio_open, - .fs_read = grub_cpio_read, - .fs_close = grub_cpio_close, + .dir = grub_cpio_dir, + .open = grub_cpio_open, + .read = grub_cpio_read, + .close = grub_cpio_close, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 0, diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 2ac5c1d00..fd412830c 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -28,7 +28,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -322,32 +321,6 @@ struct grub_udf_partmap }; } GRUB_PACKED; -struct grub_udf_pvd -{ - struct grub_udf_tag tag; - grub_uint32_t seq_num; - grub_uint32_t pvd_num; - grub_uint8_t ident[32]; - grub_uint16_t vol_seq_num; - grub_uint16_t max_vol_seq_num; - grub_uint16_t interchange_level; - grub_uint16_t max_interchange_level; - grub_uint32_t charset_list; - grub_uint32_t max_charset_list; - grub_uint8_t volset_ident[128]; - struct grub_udf_charspec desc_charset; - struct grub_udf_charspec expl_charset; - struct grub_udf_extent_ad vol_abstract; - struct grub_udf_extent_ad vol_copyright; - struct grub_udf_regid app_ident; - struct grub_udf_timestamp recording_time; - struct grub_udf_regid imp_ident; - grub_uint8_t imp_use[64]; - grub_uint32_t pred_vds_loc; - grub_uint16_t flags; - grub_uint8_t reserved[22]; -} GRUB_PACKED; - struct grub_udf_lvd { struct grub_udf_tag tag; @@ -375,7 +348,6 @@ struct grub_udf_aed struct grub_udf_data { grub_disk_t disk; - struct grub_udf_pvd pvd; struct grub_udf_lvd lvd; struct grub_udf_pd pds[GRUB_UDF_MAX_PDS]; struct grub_udf_partmap *pms[GRUB_UDF_MAX_PMS]; @@ -720,17 +692,7 @@ grub_udf_mount (grub_disk_t disk) } tag.tag_ident = U16 (tag.tag_ident); - if (tag.tag_ident == GRUB_UDF_TAG_IDENT_PVD) - { - if (grub_disk_read (disk, block << lbshift, 0, - sizeof (struct grub_udf_pvd), - &data->pvd)) - { - grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem"); - goto fail; - } - } - else if (tag.tag_ident == GRUB_UDF_TAG_IDENT_PD) + if (tag.tag_ident == GRUB_UDF_TAG_IDENT_PD) { if (data->npd >= GRUB_UDF_MAX_PDS) { @@ -874,7 +836,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) { unsigned i; utf16len = sz - 1; - utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); if (!utf16) return NULL; for (i = 0; i < utf16len; i++) @@ -884,49 +846,20 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) { unsigned i; utf16len = (sz - 1) / 2; - utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + utf16 = grub_malloc (utf16len * sizeof (utf16[0])); if (!utf16) return NULL; for (i = 0; i < utf16len; i++) utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; } if (!outbuf) - { - grub_size_t size; - - if (grub_mul (utf16len, GRUB_MAX_UTF8_PER_UTF16, &size) || - grub_add (size, 1, &size)) - goto fail; - - outbuf = grub_malloc (size); - } + outbuf = grub_malloc (utf16len * GRUB_MAX_UTF8_PER_UTF16 + 1); if (outbuf) *grub_utf16_to_utf8 ((grub_uint8_t *) outbuf, utf16, utf16len) = '\0'; - - fail: grub_free (utf16); return outbuf; } -static char * -read_dstring (const grub_uint8_t *raw, grub_size_t sz) -{ - grub_size_t len; - - if (raw[0] == 0) { - char *outbuf = grub_malloc (1); - if (!outbuf) - return NULL; - outbuf[0] = 0; - return outbuf; - } - - len = raw[sz - 1]; - if (len > sz - 1) - len = sz - 1; - return read_string (raw, len, NULL); -} - static int grub_udf_iterate_dir (grub_fshelp_node_t dir, grub_fshelp_iterate_dir_hook_t hook, void *hook_data) @@ -965,10 +898,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, return 0; if (grub_udf_read_icb (dir->data, &dirent.icb, child)) - { - grub_free (child); - return 0; - } + return 0; + if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) { /* This is the parent directory. */ @@ -990,18 +921,11 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, dirent.file_ident_length, (char *) raw)) != dirent.file_ident_length) - { - grub_free (child); - return 0; - } + return 0; filename = read_string (raw, dirent.file_ident_length, 0); if (!filename) - { - /* As the hook won't get called. */ - grub_free (child); - grub_print_error (); - } + grub_print_error (); if (filename && hook (filename, type, child, hook_data)) { @@ -1025,7 +949,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) grub_size_t sz = U64 (node->block.fe.file_size); grub_uint8_t *raw; const grub_uint8_t *ptr; - char *out = NULL, *optr; + char *out, *optr; if (sz < 4) return NULL; @@ -1033,16 +957,14 @@ grub_udf_read_symlink (grub_fshelp_node_t node) if (!raw) return NULL; if (grub_udf_read_file (node, NULL, NULL, 0, sz, (char *) raw) < 0) - goto fail_1; + { + grub_free (raw); + return NULL; + } - if (grub_mul (sz, 2, &sz) || - grub_add (sz, 1, &sz)) - goto fail_0; - - out = grub_malloc (sz); + out = grub_malloc (sz * 2 + 1); if (!out) { - fail_0: grub_free (raw); return NULL; } @@ -1053,18 +975,17 @@ grub_udf_read_symlink (grub_fshelp_node_t node) { grub_size_t s; if ((grub_size_t) (ptr - raw + 4) > sz) - goto fail_1; + goto fail; if (!(ptr[2] == 0 && ptr[3] == 0)) - goto fail_1; + goto fail; s = 4 + ptr[1]; if ((grub_size_t) (ptr - raw + s) > sz) - goto fail_1; + goto fail; switch (*ptr) { case 1: if (ptr[1]) - goto fail_1; - /* Fallthrough. */ + goto fail; case 2: /* in 4 bytes. out: 1 byte. */ optr = out; @@ -1088,11 +1009,11 @@ grub_udf_read_symlink (grub_fshelp_node_t node) if (optr != out) *optr++ = '/'; if (!read_string (ptr + 4, s - 4, optr)) - goto fail_1; + goto fail; optr += grub_strlen (optr); break; default: - goto fail_1; + goto fail; } ptr += s; } @@ -1100,7 +1021,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) grub_free (raw); return out; - fail_1: + fail: grub_free (raw); grub_free (out); grub_error (GRUB_ERR_BAD_FS, "invalid symlink"); @@ -1275,7 +1196,7 @@ grub_udf_label (grub_device_t device, char **label) if (data) { - *label = read_dstring (data->lvd.ident, sizeof (data->lvd.ident)); + *label = read_string (data->lvd.ident, sizeof (data->lvd.ident), 0); grub_free (data); } else @@ -1284,95 +1205,13 @@ grub_udf_label (grub_device_t device, char **label) return grub_errno; } -static char * -gen_uuid_from_volset (char *volset_ident) -{ - grub_size_t i; - grub_size_t len; - grub_size_t nonhexpos; - grub_uint8_t buf[17]; - char *uuid; - - len = grub_strlen (volset_ident); - if (len < 8) - return NULL; - - uuid = grub_malloc (17); - if (!uuid) - return NULL; - - if (len > 16) - len = 16; - - grub_memset (buf, 0, sizeof (buf)); - grub_memcpy (buf, volset_ident, len); - - nonhexpos = 16; - for (i = 0; i < 16; ++i) - { - if (!grub_isxdigit (buf[i])) - { - nonhexpos = i; - break; - } - } - - if (nonhexpos < 8) - { - grub_snprintf (uuid, 17, "%02x%02x%02x%02x%02x%02x%02x%02x", - buf[0], buf[1], buf[2], buf[3], - buf[4], buf[5], buf[6], buf[7]); - } - else if (nonhexpos < 16) - { - for (i = 0; i < 8; ++i) - uuid[i] = grub_tolower (buf[i]); - grub_snprintf (uuid+8, 9, "%02x%02x%02x%02x", - buf[8], buf[9], buf[10], buf[11]); - } - else - { - for (i = 0; i < 16; ++i) - uuid[i] = grub_tolower (buf[i]); - uuid[16] = 0; - } - - return uuid; -} - -static grub_err_t -grub_udf_uuid (grub_device_t device, char **uuid) -{ - char *volset_ident; - struct grub_udf_data *data; - data = grub_udf_mount (device->disk); - - if (data) - { - volset_ident = read_dstring (data->pvd.volset_ident, sizeof (data->pvd.volset_ident)); - if (volset_ident) - { - *uuid = gen_uuid_from_volset (volset_ident); - grub_free (volset_ident); - } - else - *uuid = 0; - grub_free (data); - } - else - *uuid = 0; - - return grub_errno; -} - static struct grub_fs grub_udf_fs = { .name = "udf", - .fs_dir = grub_udf_dir, - .fs_open = grub_udf_open, - .fs_read = grub_udf_read, - .fs_close = grub_udf_close, - .fs_label = grub_udf_label, - .fs_uuid = grub_udf_uuid, + .dir = grub_udf_dir, + .open = grub_udf_open, + .read = grub_udf_read, + .close = grub_udf_close, + .label = grub_udf_label, #ifdef GRUB_UTIL .reserved_first_sector = 1, .blocklist_install = 1, diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c index fca46baa1..f560ad380 100644 --- a/grub-core/fs/ufs.c +++ b/grub-core/fs/ufs.c @@ -394,7 +394,7 @@ grub_ufs_read_file (struct grub_ufs_data *data, return -1; } else - grub_memset (buf, 0, blockend); + grub_memset (buf, UFS_BLKSZ (sblock) - skipfirst, 0); buf += UFS_BLKSZ (sblock) - skipfirst; } @@ -465,13 +465,7 @@ grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino) && INODE_SIZE (data) <= sizeof (data->inode.symlink)) grub_strcpy (symlink, (char *) data->inode.symlink); else - { - if (grub_ufs_read_file (data, 0, 0, 0, sz, symlink) < 0) - { - grub_free(symlink); - return grub_errno; - } - } + grub_ufs_read_file (data, 0, 0, 0, sz, symlink); symlink[sz] = '\0'; /* The symlink is an absolute path, go back to the root inode. */ @@ -875,13 +869,13 @@ static struct grub_fs grub_ufs_fs = .name = "ufs1", #endif #endif - .fs_dir = grub_ufs_dir, - .fs_open = grub_ufs_open, - .fs_read = grub_ufs_read, - .fs_close = grub_ufs_close, - .fs_label = grub_ufs_label, - .fs_uuid = grub_ufs_uuid, - .fs_mtime = grub_ufs_mtime, + .dir = grub_ufs_dir, + .open = grub_ufs_open, + .read = grub_ufs_read, + .close = grub_ufs_close, + .label = grub_ufs_label, + .uuid = grub_ufs_uuid, + .mtime = grub_ufs_mtime, /* FIXME: set reserved_first_sector. */ #ifdef GRUB_UTIL .blocklist_install = 1, diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c index ea6590290..16ffd3f1e 100644 --- a/grub-core/fs/xfs.c +++ b/grub-core/fs/xfs.c @@ -25,7 +25,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -35,64 +34,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define XFS_INODE_FORMAT_EXT 2 #define XFS_INODE_FORMAT_BTREE 3 -/* Superblock version field flags */ -#define XFS_SB_VERSION_NUMBITS 0x000f -#define XFS_SB_VERSION_ATTRBIT 0x0010 -#define XFS_SB_VERSION_NLINKBIT 0x0020 -#define XFS_SB_VERSION_QUOTABIT 0x0040 -#define XFS_SB_VERSION_ALIGNBIT 0x0080 -#define XFS_SB_VERSION_DALIGNBIT 0x0100 -#define XFS_SB_VERSION_LOGV2BIT 0x0400 -#define XFS_SB_VERSION_SECTORBIT 0x0800 -#define XFS_SB_VERSION_EXTFLGBIT 0x1000 -#define XFS_SB_VERSION_DIRV2BIT 0x2000 -#define XFS_SB_VERSION_MOREBITSBIT 0x8000 -#define XFS_SB_VERSION_BITS_SUPPORTED \ - (XFS_SB_VERSION_NUMBITS | \ - XFS_SB_VERSION_ATTRBIT | \ - XFS_SB_VERSION_NLINKBIT | \ - XFS_SB_VERSION_QUOTABIT | \ - XFS_SB_VERSION_ALIGNBIT | \ - XFS_SB_VERSION_DALIGNBIT | \ - XFS_SB_VERSION_LOGV2BIT | \ - XFS_SB_VERSION_SECTORBIT | \ - XFS_SB_VERSION_EXTFLGBIT | \ - XFS_SB_VERSION_DIRV2BIT | \ - XFS_SB_VERSION_MOREBITSBIT) - -/* Recognized xfs format versions */ -#define XFS_SB_VERSION_4 4 /* Good old XFS filesystem */ -#define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */ - -/* features2 field flags */ -#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */ -#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */ -#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32-bit project ids */ -#define XFS_SB_VERSION2_FTYPE 0x00000200 /* inode type in dir */ -#define XFS_SB_VERSION2_BITS_SUPPORTED \ - (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ - XFS_SB_VERSION2_ATTR2BIT | \ - XFS_SB_VERSION2_PROJID32BIT | \ - XFS_SB_VERSION2_FTYPE) - -/* incompat feature flags */ -#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ -#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ -#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ - -/* - * Directory entries with ftype are explicitly handled by GRUB code. - * - * We do not currently read the inode btrees, so it is safe to read filesystems - * with the XFS_SB_FEAT_INCOMPAT_SPINODES feature. - * - * We do not currently verify metadata UUID, so it is safe to read filesystems - * with the XFS_SB_FEAT_INCOMPAT_META_UUID feature. - */ -#define XFS_SB_FEAT_INCOMPAT_SUPPORTED \ - (XFS_SB_FEAT_INCOMPAT_FTYPE | \ - XFS_SB_FEAT_INCOMPAT_SPINODES | \ - XFS_SB_FEAT_INCOMPAT_META_UUID) struct grub_xfs_sblock { @@ -104,9 +45,7 @@ struct grub_xfs_sblock grub_uint64_t rootino; grub_uint8_t unused3[20]; grub_uint32_t agsize; - grub_uint8_t unused4[12]; - grub_uint16_t version; - grub_uint8_t unused5[6]; + grub_uint8_t unused4[20]; grub_uint8_t label[12]; grub_uint8_t log2_bsize; grub_uint8_t log2_sect; @@ -115,19 +54,12 @@ struct grub_xfs_sblock grub_uint8_t log2_agblk; grub_uint8_t unused6[67]; grub_uint8_t log2_dirblk; - grub_uint8_t unused7[7]; - grub_uint32_t features2; - grub_uint8_t unused8[4]; - grub_uint32_t sb_features_compat; - grub_uint32_t sb_features_ro_compat; - grub_uint32_t sb_features_incompat; - grub_uint32_t sb_features_log_incompat; } GRUB_PACKED; struct grub_xfs_dir_header { grub_uint8_t count; - grub_uint8_t largeino; + grub_uint8_t smallino; union { grub_uint32_t i4; @@ -135,29 +67,21 @@ struct grub_xfs_dir_header } GRUB_PACKED parent; } GRUB_PACKED; -/* Structure for directory entry inlined in the inode */ struct grub_xfs_dir_entry { grub_uint8_t len; grub_uint16_t offset; char name[1]; - /* Inode number follows, 32 / 64 bits. */ + /* Inode number follows, 32 bits. */ } GRUB_PACKED; -/* Structure for directory entry in a block */ struct grub_xfs_dir2_entry { grub_uint64_t inode; grub_uint8_t len; } GRUB_PACKED; -struct grub_xfs_extent -{ - /* This should be a bitfield but bietfields are unportable, so just have - a raw array and functions extracting useful info from it. - */ - grub_uint32_t raw[4]; -} GRUB_PACKED; +typedef grub_uint32_t grub_xfs_extent[4]; struct grub_xfs_btree_node { @@ -166,22 +90,21 @@ struct grub_xfs_btree_node grub_uint16_t numrecs; grub_uint64_t left; grub_uint64_t right; - /* In V5 here follow crc, uuid, etc. */ - /* Then follow keys and block pointers */ -} GRUB_PACKED; + grub_uint64_t keys[1]; +} GRUB_PACKED; struct grub_xfs_btree_root { grub_uint16_t level; grub_uint16_t numrecs; grub_uint64_t keys[1]; -} GRUB_PACKED; +} GRUB_PACKED; struct grub_xfs_time { grub_uint32_t sec; grub_uint32_t nanosec; -} GRUB_PACKED; +} GRUB_PACKED; struct grub_xfs_inode { @@ -200,11 +123,19 @@ struct grub_xfs_inode grub_uint16_t unused3; grub_uint8_t fork_offset; grub_uint8_t unused4[17]; + union + { + char raw[156]; + struct dir + { + struct grub_xfs_dir_header dirhead; + struct grub_xfs_dir_entry direntry[1]; + } dir; + grub_xfs_extent extents[XFS_INODE_EXTENTS]; + struct grub_xfs_btree_root btree; + } GRUB_PACKED data; } GRUB_PACKED; -#define XFS_V2_INODE_SIZE sizeof(struct grub_xfs_inode) -#define XFS_V3_INODE_SIZE (XFS_V2_INODE_SIZE + 76) - struct grub_xfs_dirblock_tail { grub_uint32_t leaf_count; @@ -226,8 +157,6 @@ struct grub_xfs_data int pos; int bsize; grub_uint32_t agsize; - unsigned int hasftype:1; - unsigned int hascrc:1; struct grub_fshelp_node diropen; }; @@ -235,71 +164,6 @@ static grub_dl_t my_mod; -static int grub_xfs_sb_hascrc(struct grub_xfs_data *data) -{ - return (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) == - grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5); -} - -static int grub_xfs_sb_hasftype(struct grub_xfs_data *data) -{ - if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) == - grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) && - data->sblock.sb_features_incompat & grub_cpu_to_be32_compile_time(XFS_SB_FEAT_INCOMPAT_FTYPE)) - return 1; - if (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_MOREBITSBIT) && - data->sblock.features2 & grub_cpu_to_be32_compile_time(XFS_SB_VERSION2_FTYPE)) - return 1; - return 0; -} - -static int grub_xfs_sb_valid(struct grub_xfs_data *data) -{ - grub_dprintf("xfs", "Validating superblock\n"); - if (grub_strncmp ((char *) (data->sblock.magic), "XFSB", 4) - || data->sblock.log2_bsize < GRUB_DISK_SECTOR_BITS - || ((int) data->sblock.log2_bsize - + (int) data->sblock.log2_dirblk) >= 27) - { - grub_error (GRUB_ERR_BAD_FS, "not a XFS filesystem"); - return 0; - } - if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) == - grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5)) - { - grub_dprintf("xfs", "XFS v5 superblock detected\n"); - if (data->sblock.sb_features_incompat & - grub_cpu_to_be32_compile_time(~XFS_SB_FEAT_INCOMPAT_SUPPORTED)) - { - grub_error (GRUB_ERR_BAD_FS, "XFS filesystem has unsupported " - "incompatible features"); - return 0; - } - return 1; - } - else if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) == - grub_cpu_to_be16_compile_time(XFS_SB_VERSION_4)) - { - grub_dprintf("xfs", "XFS v4 superblock detected\n"); - if (!(data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_DIRV2BIT))) - { - grub_error (GRUB_ERR_BAD_FS, "XFS filesystem without V2 directories " - "is unsupported"); - return 0; - } - if (data->sblock.version & grub_cpu_to_be16_compile_time(~XFS_SB_VERSION_BITS_SUPPORTED) || - (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_MOREBITSBIT) && - data->sblock.features2 & grub_cpu_to_be16_compile_time(~XFS_SB_VERSION2_BITS_SUPPORTED))) - { - grub_error (GRUB_ERR_BAD_FS, "XFS filesystem has unsupported version " - "bits"); - return 0; - } - return 1; - } - return 0; -} - /* Filetype information as used in inodes. */ #define FILETYPE_INO_MASK 0170000 #define FILETYPE_INO_REG 0100000 @@ -316,14 +180,14 @@ static inline grub_uint64_t GRUB_XFS_INO_INOINAG (struct grub_xfs_data *data, grub_uint64_t ino) { - return (ino & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)); + return (grub_be_to_cpu64 (ino) & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)); } static inline grub_uint64_t GRUB_XFS_INO_AG (struct grub_xfs_data *data, grub_uint64_t ino) { - return (ino >> GRUB_XFS_INO_AGBITS (data)); + return (grub_be_to_cpu64 (ino) >> GRUB_XFS_INO_AGBITS (data)); } static inline grub_disk_addr_t @@ -334,25 +198,37 @@ GRUB_XFS_FSB_TO_BLOCK (struct grub_xfs_data *data, grub_disk_addr_t fsb) } static inline grub_uint64_t -GRUB_XFS_EXTENT_OFFSET (struct grub_xfs_extent *exts, int ex) +GRUB_XFS_EXTENT_OFFSET (grub_xfs_extent *exts, int ex) { - return ((grub_be_to_cpu32 (exts[ex].raw[0]) & ~(1 << 31)) << 23 - | grub_be_to_cpu32 (exts[ex].raw[1]) >> 9); + return ((grub_be_to_cpu32 (exts[ex][0]) & ~(1 << 31)) << 23 + | grub_be_to_cpu32 (exts[ex][1]) >> 9); } static inline grub_uint64_t -GRUB_XFS_EXTENT_BLOCK (struct grub_xfs_extent *exts, int ex) +GRUB_XFS_EXTENT_BLOCK (grub_xfs_extent *exts, int ex) { - return ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex].raw[1]) + return ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex][1]) & (0x1ff)) << 43 - | (grub_uint64_t) grub_be_to_cpu32 (exts[ex].raw[2]) << 11 - | grub_be_to_cpu32 (exts[ex].raw[3]) >> 21); + | (grub_uint64_t) grub_be_to_cpu32 (exts[ex][2]) << 11 + | grub_be_to_cpu32 (exts[ex][3]) >> 21); } static inline grub_uint64_t -GRUB_XFS_EXTENT_SIZE (struct grub_xfs_extent *exts, int ex) +GRUB_XFS_EXTENT_SIZE (grub_xfs_extent *exts, int ex) { - return (grub_be_to_cpu32 (exts[ex].raw[3]) & ((1 << 21) - 1)); + return (grub_be_to_cpu32 (exts[ex][3]) & ((1 << 21) - 1)); +} + +static inline int +GRUB_XFS_ROUND_TO_DIRENT (int pos) +{ + return ((((pos) + 8 - 1) / 8) * 8); +} + +static inline int +GRUB_XFS_NEXT_DIRENT (int pos, int len) +{ + return (pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2); } @@ -379,109 +255,6 @@ grub_xfs_inode_offset (struct grub_xfs_data *data, data->sblock.log2_inode); } -static inline grub_size_t -grub_xfs_inode_size(struct grub_xfs_data *data) -{ - return (grub_size_t)1 << data->sblock.log2_inode; -} - -/* - * Returns size occupied by XFS inode stored in memory - we store struct - * grub_fshelp_node there but on disk inode size may be actually larger than - * struct grub_xfs_inode so we need to account for that so that we can read - * from disk directly into in-memory structure. - */ -static inline grub_size_t -grub_xfs_fshelp_size(struct grub_xfs_data *data) -{ - return sizeof (struct grub_fshelp_node) - sizeof (struct grub_xfs_inode) - + grub_xfs_inode_size(data); -} - -/* This should return void * but XFS code is error-prone with alignment, so - return char to retain cast-align. - */ -static char * -grub_xfs_inode_data(struct grub_xfs_inode *inode) -{ - if (inode->version <= 2) - return ((char *)inode) + XFS_V2_INODE_SIZE; - return ((char *)inode) + XFS_V3_INODE_SIZE; -} - -static struct grub_xfs_dir_entry * -grub_xfs_inline_de(struct grub_xfs_dir_header *head) -{ - /* - With small inode numbers the header is 4 bytes smaller because of - smaller parent pointer - */ - return (struct grub_xfs_dir_entry *) - (((char *) head) + sizeof(struct grub_xfs_dir_header) - - (head->largeino ? 0 : sizeof(grub_uint32_t))); -} - -static grub_uint8_t * -grub_xfs_inline_de_inopos(struct grub_xfs_data *data, - struct grub_xfs_dir_entry *de) -{ - return ((grub_uint8_t *)(de + 1)) + de->len - 1 + (data->hasftype ? 1 : 0); -} - -static struct grub_xfs_dir_entry * -grub_xfs_inline_next_de(struct grub_xfs_data *data, - struct grub_xfs_dir_header *head, - struct grub_xfs_dir_entry *de) -{ - char *p = (char *)de + sizeof(struct grub_xfs_dir_entry) - 1 + de->len; - - p += head->largeino ? sizeof(grub_uint64_t) : sizeof(grub_uint32_t); - if (data->hasftype) - p++; - - return (struct grub_xfs_dir_entry *)p; -} - -static struct grub_xfs_dirblock_tail * -grub_xfs_dir_tail(struct grub_xfs_data *data, void *dirblock) -{ - int dirblksize = 1 << (data->sblock.log2_bsize + data->sblock.log2_dirblk); - - return (struct grub_xfs_dirblock_tail *) - ((char *)dirblock + dirblksize - sizeof (struct grub_xfs_dirblock_tail)); -} - -static struct grub_xfs_dir2_entry * -grub_xfs_first_de(struct grub_xfs_data *data, void *dirblock) -{ - if (data->hascrc) - return (struct grub_xfs_dir2_entry *)((char *)dirblock + 64); - return (struct grub_xfs_dir2_entry *)((char *)dirblock + 16); -} - -static struct grub_xfs_dir2_entry * -grub_xfs_next_de(struct grub_xfs_data *data, struct grub_xfs_dir2_entry *de) -{ - int size = sizeof (struct grub_xfs_dir2_entry) + de->len + 2 /* Tag */; - - if (data->hasftype) - size++; /* File type */ - return (struct grub_xfs_dir2_entry *)(((char *)de) + ALIGN_UP(size, 8)); -} - -/* This should return void * but XFS code is error-prone with alignment, so - return char to retain cast-align. - */ -static char * -grub_xfs_btree_keys(struct grub_xfs_data *data, - struct grub_xfs_btree_node *leaf) -{ - char *keys = (char *)(leaf + 1); - - if (data->hascrc) - keys += 48; /* skip crc, uuid, ... */ - return keys; -} static grub_err_t grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino, @@ -490,11 +263,9 @@ grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino, grub_uint64_t block = grub_xfs_inode_block (data, ino); int offset = grub_xfs_inode_offset (data, ino); - grub_dprintf("xfs", "Reading inode (%"PRIuGRUB_UINT64_T") - %"PRIuGRUB_UINT64_T", %d\n", - ino, block, offset); /* Read the inode. */ - if (grub_disk_read (data->disk, block, offset, grub_xfs_inode_size(data), - inode)) + if (grub_disk_read (data->disk, block, offset, + 1 << data->sblock.log2_inode, inode)) return grub_errno; if (grub_strncmp ((char *) inode->magic, "IN", 2)) @@ -503,47 +274,40 @@ grub_xfs_read_inode (struct grub_xfs_data *data, grub_uint64_t ino, return 0; } -static grub_uint64_t -get_fsb (const void *keys, int idx) -{ - const char *p = (const char *) keys + sizeof(grub_uint64_t) * idx; - return grub_be_to_cpu64 (grub_get_unaligned64 (p)); -} static grub_disk_addr_t grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) { struct grub_xfs_btree_node *leaf = 0; int ex, nrec; - struct grub_xfs_extent *exts; + grub_xfs_extent *exts; grub_uint64_t ret = 0; if (node->inode.format == XFS_INODE_FORMAT_BTREE) { - struct grub_xfs_btree_root *root; - const char *keys; + const grub_uint64_t *keys; int recoffset; leaf = grub_malloc (node->data->bsize); if (leaf == 0) return 0; - root = (struct grub_xfs_btree_root *) grub_xfs_inode_data(&node->inode); - nrec = grub_be_to_cpu16 (root->numrecs); - keys = (char *) &root->keys[0]; + nrec = grub_be_to_cpu16 (node->inode.data.btree.numrecs); + keys = &node->inode.data.btree.keys[0]; if (node->inode.fork_offset) recoffset = (node->inode.fork_offset - 1) / 2; else - recoffset = (grub_xfs_inode_size(node->data) - - ((char *) keys - (char *) &node->inode)) - / (2 * sizeof (grub_uint64_t)); + recoffset = ((1 << node->data->sblock.log2_inode) + - ((char *) &node->inode.data.btree.keys + - (char *) &node->inode)) + / (2 * sizeof (grub_uint64_t)); do { int i; for (i = 0; i < nrec; i++) { - if (fileblock < get_fsb(keys, i)) + if (fileblock < grub_be_to_cpu64 (keys[i])) break; } @@ -553,16 +317,12 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) grub_free (leaf); return 0; } - if (grub_disk_read (node->data->disk, - GRUB_XFS_FSB_TO_BLOCK (node->data, get_fsb (keys, i - 1 + recoffset)) << (node->data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS), + GRUB_XFS_FSB_TO_BLOCK (node->data, grub_be_to_cpu64 (keys[i - 1 + recoffset])) << (node->data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS), 0, node->data->bsize, leaf)) return 0; - if ((!node->data->hascrc && - grub_strncmp ((char *) leaf->magic, "BMAP", 4)) || - (node->data->hascrc && - grub_strncmp ((char *) leaf->magic, "BMA3", 4))) + if (grub_strncmp ((char *) leaf->magic, "BMAP", 4)) { grub_free (leaf); grub_error (GRUB_ERR_BAD_FS, "not a correct XFS BMAP node"); @@ -570,18 +330,18 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) } nrec = grub_be_to_cpu16 (leaf->numrecs); - keys = grub_xfs_btree_keys(node->data, leaf); - recoffset = ((node->data->bsize - ((char *) keys + keys = &leaf->keys[0]; + recoffset = ((node->data->bsize - ((char *) &leaf->keys - (char *) leaf)) / (2 * sizeof (grub_uint64_t))); } while (leaf->level); - exts = (struct grub_xfs_extent *) keys; + exts = (grub_xfs_extent *) keys; } else if (node->inode.format == XFS_INODE_FORMAT_EXT) { nrec = grub_be_to_cpu32 (node->inode.nextents); - exts = (struct grub_xfs_extent *) grub_xfs_inode_data(&node->inode); + exts = &node->inode.data.extents[0]; } else { @@ -619,13 +379,13 @@ grub_xfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) POS. Return the amount of read bytes in READ. */ static grub_ssize_t grub_xfs_read_file (grub_fshelp_node_t node, - grub_disk_read_hook_t read_hook, void *read_hook_data, - grub_off_t pos, grub_size_t len, char *buf, grub_uint32_t header_size) + grub_disk_read_hook_t read_hook, void *read_hook_data, + grub_off_t pos, grub_size_t len, char *buf) { return grub_fshelp_read_file (node->data->disk, node, read_hook, read_hook_data, pos, len, buf, grub_xfs_read_block, - grub_be_to_cpu64 (node->inode.size) + header_size, + grub_be_to_cpu64 (node->inode.size), node->data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS, 0); } @@ -634,34 +394,23 @@ grub_xfs_read_file (grub_fshelp_node_t node, static char * grub_xfs_read_symlink (grub_fshelp_node_t node) { - grub_ssize_t size = grub_be_to_cpu64 (node->inode.size); - - if (size < 0) - { - grub_error (GRUB_ERR_BAD_FS, "invalid symlink"); - return 0; - } + int size = grub_be_to_cpu64 (node->inode.size); switch (node->inode.format) { case XFS_INODE_FORMAT_INO: - return grub_strndup (grub_xfs_inode_data(&node->inode), size); + return grub_strndup (node->inode.data.raw, size); case XFS_INODE_FORMAT_EXT: { char *symlink; grub_ssize_t numread; - int off = 0; - - if (node->data->hascrc) - off = 56; symlink = grub_malloc (size + 1); if (!symlink) return 0; - node->inode.size = grub_be_to_cpu64 (size + off); - numread = grub_xfs_read_file (node, 0, 0, off, size, symlink, off); + numread = grub_xfs_read_file (node, 0, 0, 0, size, symlink); if (numread != size) { grub_free (symlink); @@ -707,7 +456,9 @@ static int iterate_dir_call_hook (grub_uint64_t ino, const char *filename, struct grub_fshelp_node *fdiro; grub_err_t err; - fdiro = grub_malloc (grub_xfs_fshelp_size(ctx->diro->data) + 1); + fdiro = grub_malloc (sizeof (struct grub_fshelp_node) + - sizeof (struct grub_xfs_inode) + + (1 << ctx->diro->data->sblock.log2_inode) + 1); if (!fdiro) { grub_print_error (); @@ -745,18 +496,24 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, { case XFS_INODE_FORMAT_INO: { - struct grub_xfs_dir_header *head = (struct grub_xfs_dir_header *) grub_xfs_inode_data(&diro->inode); - struct grub_xfs_dir_entry *de = grub_xfs_inline_de(head); - int smallino = !head->largeino; + struct grub_xfs_dir_entry *de = &diro->inode.data.dir.direntry[0]; + int smallino = !diro->inode.data.dir.dirhead.smallino; int i; grub_uint64_t parent; /* If small inode numbers are used to pack the direntry, the parent inode number is small too. */ if (smallino) - parent = grub_be_to_cpu32 (head->parent.i4); + { + parent = grub_be_to_cpu32 (diro->inode.data.dir.dirhead.parent.i4); + parent = grub_cpu_to_be64 (parent); + /* The header is a bit smaller than usual. */ + de = (struct grub_xfs_dir_entry *) ((char *) de - 4); + } else - parent = grub_be_to_cpu64 (head->parent.i8); + { + parent = diro->inode.data.dir.dirhead.parent.i8; + } /* Synthesize the direntries for `.' and `..'. */ if (iterate_dir_call_hook (diro->ino, ".", &ctx)) @@ -765,10 +522,12 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, if (iterate_dir_call_hook (parent, "..", &ctx)) return 1; - for (i = 0; i < head->count; i++) + for (i = 0; i < diro->inode.data.dir.dirhead.count; i++) { grub_uint64_t ino; - grub_uint8_t *inopos = grub_xfs_inline_de_inopos(dir->data, de); + grub_uint8_t *inopos = (((grub_uint8_t *) de) + + sizeof (struct grub_xfs_dir_entry) + + de->len - 1); grub_uint8_t c; /* inopos might be unaligned. */ @@ -786,17 +545,18 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, | (((grub_uint64_t) inopos[5]) << 16) | (((grub_uint64_t) inopos[6]) << 8) | (((grub_uint64_t) inopos[7]) << 0); + ino = grub_cpu_to_be64 (ino); c = de->name[de->len]; de->name[de->len] = '\0'; if (iterate_dir_call_hook (ino, de->name, &ctx)) - { - de->name[de->len] = c; - return 1; - } + return 1; de->name[de->len] = c; - de = grub_xfs_inline_next_de(dir->data, head, de); + de = ((struct grub_xfs_dir_entry *) + (((char *) de)+ sizeof (struct grub_xfs_dir_entry) + de->len + + ((smallino ? sizeof (grub_uint32_t) + : sizeof (grub_uint64_t))) - 1)); } break; } @@ -823,30 +583,34 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, >> dirblk_log2); blk++) { - struct grub_xfs_dir2_entry *direntry = - grub_xfs_first_de(dir->data, dirblock); + /* The header is skipped, the first direntry is stored + from byte 16. */ + int pos = 16; int entries; - struct grub_xfs_dirblock_tail *tail = - grub_xfs_dir_tail(dir->data, dirblock); + int tail_start = (dirblk_size + - sizeof (struct grub_xfs_dirblock_tail)); + + struct grub_xfs_dirblock_tail *tail; + tail = (struct grub_xfs_dirblock_tail *) &dirblock[tail_start]; numread = grub_xfs_read_file (dir, 0, 0, blk << dirblk_log2, - dirblk_size, dirblock, 0); + dirblk_size, dirblock); if (numread != dirblk_size) return 0; entries = (grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale)); - if (!entries) - continue; - /* Iterate over all entries within this block. */ - while ((char *)direntry < (char *)tail) + while (pos < (dirblk_size + - (int) sizeof (struct grub_xfs_dir2_entry))) { + struct grub_xfs_dir2_entry *direntry; grub_uint8_t *freetag; char *filename; + direntry = (struct grub_xfs_dir2_entry *) &dirblock[pos]; freetag = (grub_uint8_t *) direntry; if (grub_get_unaligned16 (freetag) == 0XFFFF) @@ -854,20 +618,17 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, grub_uint8_t *skip = (freetag + sizeof (grub_uint16_t)); /* This entry is not used, go to the next one. */ - direntry = (struct grub_xfs_dir2_entry *) - (((char *)direntry) + - grub_be_to_cpu16 (grub_get_unaligned16 (skip))); + pos += grub_be_to_cpu16 (grub_get_unaligned16 (skip)); continue; } - filename = (char *)(direntry + 1); - /* The byte after the filename is for the filetype, padding, or - tag, which is not used by GRUB. So it can be overwritten. */ + filename = &dirblock[pos + sizeof (*direntry)]; + /* The byte after the filename is for the tag, which + is not used by GRUB. So it can be overwritten. */ filename[direntry->len] = '\0'; - if (iterate_dir_call_hook (grub_be_to_cpu64(direntry->inode), - filename, &ctx)) + if (iterate_dir_call_hook (direntry->inode, filename, &ctx)) { grub_free (dirblock); return 1; @@ -880,7 +641,8 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir, break; /* Select the next directory entry. */ - direntry = grub_xfs_next_de(dir->data, direntry); + pos = GRUB_XFS_NEXT_DIRENT (pos, direntry->len); + pos = GRUB_XFS_ROUND_TO_DIRENT (pos); } } grub_free (dirblock); @@ -900,42 +662,41 @@ static struct grub_xfs_data * grub_xfs_mount (grub_disk_t disk) { struct grub_xfs_data *data = 0; - grub_size_t sz; data = grub_zalloc (sizeof (struct grub_xfs_data)); if (!data) return 0; - grub_dprintf("xfs", "Reading sb\n"); /* Read the superblock. */ if (grub_disk_read (disk, 0, 0, sizeof (struct grub_xfs_sblock), &data->sblock)) goto fail; - if (!grub_xfs_sb_valid(data)) - goto fail; + if (grub_strncmp ((char *) (data->sblock.magic), "XFSB", 4) + || data->sblock.log2_bsize < GRUB_DISK_SECTOR_BITS + || ((int) data->sblock.log2_bsize + + (int) data->sblock.log2_dirblk) >= 27) + { + grub_error (GRUB_ERR_BAD_FS, "not a XFS filesystem"); + goto fail; + } - if (grub_add (grub_xfs_inode_size (data), - sizeof (struct grub_xfs_data) - sizeof (struct grub_xfs_inode) + 1, &sz)) - goto fail; - - data = grub_realloc (data, sz); + data = grub_realloc (data, + sizeof (struct grub_xfs_data) + - sizeof (struct grub_xfs_inode) + + (1 << data->sblock.log2_inode) + 1); if (! data) goto fail; data->diropen.data = data; - data->diropen.ino = grub_be_to_cpu64(data->sblock.rootino); + data->diropen.ino = data->sblock.rootino; data->diropen.inode_read = 1; data->bsize = grub_be_to_cpu32 (data->sblock.bsize); data->agsize = grub_be_to_cpu32 (data->sblock.agsize); - data->hasftype = grub_xfs_sb_hasftype(data); - data->hascrc = grub_xfs_sb_hascrc(data); data->disk = disk; data->pos = 0; - grub_dprintf("xfs", "Reading root ino %"PRIuGRUB_UINT64_T"\n", - grub_cpu_to_be64(data->sblock.rootino)); grub_xfs_read_inode (data, data->diropen.ino, &data->diropen.inode); @@ -1038,7 +799,10 @@ grub_xfs_open (struct grub_file *file, const char *name) if (fdiro != &data->diropen) { - grub_memcpy (&data->diropen, fdiro, grub_xfs_fshelp_size(data)); + grub_memcpy (&data->diropen, fdiro, + sizeof (struct grub_fshelp_node) + - sizeof (struct grub_xfs_inode) + + (1 << data->sblock.log2_inode)); grub_free (fdiro); } @@ -1068,7 +832,7 @@ grub_xfs_read (grub_file_t file, char *buf, grub_size_t len) return grub_xfs_read_file (&data->diropen, file->read_hook, file->read_hook_data, - file->offset, len, buf, 0); + file->offset, len, buf); } @@ -1140,12 +904,12 @@ grub_xfs_uuid (grub_device_t device, char **uuid) static struct grub_fs grub_xfs_fs = { .name = "xfs", - .fs_dir = grub_xfs_dir, - .fs_open = grub_xfs_open, - .fs_read = grub_xfs_read, - .fs_close = grub_xfs_close, - .fs_label = grub_xfs_label, - .fs_uuid = grub_xfs_uuid, + .dir = grub_xfs_dir, + .open = grub_xfs_open, + .read = grub_xfs_read, + .close = grub_xfs_close, + .label = grub_xfs_label, + .uuid = grub_xfs_uuid, #ifdef GRUB_UTIL .reserved_first_sector = 0, .blocklist_install = 1, diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index 41ef0ff57..c943b5299 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -55,7 +55,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -142,10 +141,7 @@ ZAP_LEAF_NUMCHUNKS (int bs) static inline zap_leaf_chunk_t * ZAP_LEAF_CHUNK (zap_leaf_phys_t *l, int bs, int idx) { - grub_properly_aligned_t *l_entries; - - l_entries = (grub_properly_aligned_t *) ALIGN_UP((grub_addr_t)l->l_hash, sizeof (grub_properly_aligned_t)); - return &((zap_leaf_chunk_t *) (l_entries + return &((zap_leaf_chunk_t *) (l->l_entries + (ZAP_LEAF_HASH_NUMENTRIES(bs) * 2) / sizeof (grub_properly_aligned_t)))[idx]; } @@ -256,6 +252,7 @@ struct grub_zfs_data uberblock_t current_uberblock; + int mounted; grub_uint64_t guid; }; @@ -284,17 +281,12 @@ grub_crypto_cipher_handle_t (*grub_zfs_load_key) (const struct grub_zfs_key *key */ #define MAX_SUPPORTED_FEATURE_STRLEN 50 static const char *spa_feature_names[] = { - "org.illumos:lz4_compress", - "com.delphix:hole_birth", - "com.delphix:embedded_data", - "com.delphix:extensible_dataset", - "org.open-zfs:large_blocks", - NULL + "org.illumos:lz4_compress",NULL }; static int check_feature(const char *name, grub_uint64_t val, struct grub_zfs_dir_ctx *ctx); -static grub_err_t +static int check_mos_features(dnode_phys_t *mosmdn_phys,grub_zfs_endian_t endian,struct grub_zfs_data* data ); static grub_err_t @@ -777,14 +769,11 @@ fill_vdev_info (struct grub_zfs_data *data, if (data->n_devices_attached > data->n_devices_allocated) { void *tmp; - grub_size_t sz; - - if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || - grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || - grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) - return GRUB_ERR_OUT_OF_RANGE; - - data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + data->n_devices_allocated = 2 * data->n_devices_attached + 1; + data->devices_attached + = grub_realloc (tmp = data->devices_attached, + data->n_devices_allocated + * sizeof (data->devices_attached[0])); if (!data->devices_attached) { data->devices_attached = tmp; @@ -968,7 +957,7 @@ nvpair_value (const char *nvp,char **val, static grub_err_t check_pool_label (struct grub_zfs_data *data, struct grub_zfs_device_desc *diskdesc, - int *inserted, int original) + int *inserted) { grub_uint64_t pool_state, txg = 0; char *nvlist,*features; @@ -1092,11 +1081,10 @@ check_pool_label (struct grub_zfs_data *data, grub_dprintf ("zfs", "check 11 passed\n"); - if (original) - data->guid = poolguid; - - if (data->guid != poolguid) + if (data->mounted && data->guid != poolguid) return grub_error (GRUB_ERR_BAD_FS, "another zpool"); + else + data->guid = poolguid; { char *nv; @@ -1198,7 +1186,7 @@ scan_disk (grub_device_t dev, struct grub_zfs_data *data, } grub_dprintf ("zfs", "label ok %d\n", label); - err = check_pool_label (data, &desc, inserted, original); + err = check_pool_label (data, &desc, inserted); if (err || !*inserted) { grub_errno = GRUB_ERR_NONE; @@ -1763,7 +1751,7 @@ zio_read_gang (blkptr_t * bp, grub_zfs_endian_t endian, dva_t * dva, void *buf, for (i = 0; i < SPA_GBH_NBLKPTRS; i++) { - if (BP_IS_HOLE(&zio_gb->zg_blkptr[i])) + if (zio_gb->zg_blkptr[i].blk_birth == 0) continue; err = zio_read_data (&zio_gb->zg_blkptr[i], endian, buf, data); @@ -1812,39 +1800,6 @@ zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian, void *buf, return err; } -/* - * buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be - * more than BPE_PAYLOAD_SIZE bytes). - */ -static grub_err_t -decode_embedded_bp_compressed(const blkptr_t *bp, void *buf) -{ - grub_size_t psize, i; - grub_uint8_t *buf8 = buf; - grub_uint64_t w = 0; - const grub_uint64_t *bp64 = (const grub_uint64_t *)bp; - - psize = BPE_GET_PSIZE(bp); - - /* - * Decode the words of the block pointer into the byte array. - * Low bits of first word are the first byte (little endian). - */ - for (i = 0; i < psize; i++) - { - if (i % sizeof (w) == 0) - { - /* beginning of a word */ - w = *bp64; - bp64++; - if (!BPE_IS_PAYLOADWORD(bp, bp64)) - bp64++; - } - buf8[i] = BF64_GET(w, (i % sizeof (w)) * 8, 8); - } - return GRUB_ERR_NONE; -} - /* * Read in a block of data, verify its checksum, decompress if needed, * and put the uncompressed data in buf. @@ -1863,26 +1818,12 @@ zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf, *buf = NULL; checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff; - comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7f; + comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff; encrypted = ((grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 60) & 3); - if (BP_IS_EMBEDDED(bp)) - { - if (BPE_GET_ETYPE(bp) != BP_EMBEDDED_TYPE_DATA) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported embedded BP (type=%u)\n", - BPE_GET_ETYPE(bp)); - lsize = BPE_GET_LSIZE(bp); - psize = BF64_GET_SB(grub_zfs_to_cpu64 ((bp)->blk_prop, endian), 25, 7, 0, 1); - } - else - { - lsize = (BP_IS_HOLE(bp) ? 0 : - (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1) - << SPA_MINBLOCKSHIFT)); - psize = get_psize (bp, endian); - } - grub_dprintf("zfs", "zio_read: E %d: size %" PRIdGRUB_SSIZE "/%" - PRIdGRUB_SSIZE "\n", (int)BP_IS_EMBEDDED(bp), lsize, psize); + lsize = (BP_IS_HOLE(bp) ? 0 : + (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1) + << SPA_MINBLOCKSHIFT)); + psize = get_psize (bp, endian); if (size) *size = lsize; @@ -1896,41 +1837,33 @@ zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf, "compression algorithm %s not supported\n", decomp_table[comp].name); if (comp != ZIO_COMPRESS_OFF) - /* It's not really necessary to align to 16, just for safety. */ - compbuf = grub_malloc (ALIGN_UP (psize, 16)); + { + /* It's not really necessary to align to 16, just for safety. */ + compbuf = grub_malloc (ALIGN_UP (psize, 16)); + if (! compbuf) + return grub_errno; + } else compbuf = *buf = grub_malloc (lsize); - if (! compbuf) - return grub_errno; grub_dprintf ("zfs", "endian = %d\n", endian); - if (BP_IS_EMBEDDED(bp)) - err = decode_embedded_bp_compressed(bp, compbuf); - else - { - err = zio_read_data (bp, endian, compbuf, data); - /* FIXME is it really necessary? */ - if (comp != ZIO_COMPRESS_OFF) - grub_memset (compbuf + psize, 0, ALIGN_UP (psize, 16) - psize); - } + err = zio_read_data (bp, endian, compbuf, data); if (err) { grub_free (compbuf); *buf = NULL; return err; } + grub_memset (compbuf, 0, ALIGN_UP (psize, 16) - psize); - if (!BP_IS_EMBEDDED(bp)) + err = zio_checksum_verify (zc, checksum, endian, + compbuf, psize); + if (err) { - err = zio_checksum_verify (zc, checksum, endian, - compbuf, psize); - if (err) - { - grub_dprintf ("zfs", "incorrect checksum\n"); - grub_free (compbuf); - *buf = NULL; - return err; - } + grub_dprintf ("zfs", "incorrect checksum\n"); + grub_free (compbuf); + *buf = NULL; + return err; } if (encrypted) @@ -2042,7 +1975,7 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, dn->endian) << SPA_MINBLOCKSHIFT; *buf = grub_malloc (size); - if (!*buf) + if (*buf) { err = grub_errno; break; @@ -2080,14 +2013,12 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, */ static grub_err_t mzap_lookup (mzap_phys_t * zapobj, grub_zfs_endian_t endian, - grub_uint32_t objsize, const char *name, grub_uint64_t * value, + int objsize, const char *name, grub_uint64_t * value, int case_insensitive) { - grub_uint32_t i, chunks; + int i, chunks; mzap_ent_phys_t *mzap_ent = zapobj->mz_chunk; - if (objsize < MZAP_ENT_LEN) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), name); chunks = objsize / MZAP_ENT_LEN - 1; for (i = 0; i < chunks; i++) { @@ -2495,7 +2426,7 @@ zap_lookup (dnode_end_t * zap_dnode, const char *name, grub_uint64_t *val, struct grub_zfs_data *data, int case_insensitive) { grub_uint64_t block_type; - grub_uint32_t size; + int size; void *zapbuf; grub_err_t err; grub_zfs_endian_t endian; @@ -2503,7 +2434,7 @@ zap_lookup (dnode_end_t * zap_dnode, const char *name, grub_uint64_t *val, grub_dprintf ("zfs", "looking for '%s'\n", name); /* Read in the first block of the zap object data. */ - size = (grub_uint32_t) grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, + size = grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, zap_dnode->endian) << SPA_MINBLOCKSHIFT; err = dmu_read (zap_dnode, 0, &zapbuf, &endian, data); if (err) @@ -2889,10 +2820,7 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, err = dmu_read (&(dnode_path->dn), block, &t, 0, data); if (err) - { - grub_free (sym_value); - return err; - } + return err; movesize = sym_sz - block * blksz; if (movesize > blksz) @@ -2907,8 +2835,6 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn, if (!path_buf) { grub_free (oldpathbuf); - if (free_symval) - grub_free (sym_value); return grub_errno; } grub_memcpy (path, sym_value, sym_sz); @@ -3092,7 +3018,7 @@ get_filesystem_dnode (dnode_end_t * mosmdn, char *fsname, grub_dprintf ("zfs", "alive\n"); - err = dnode_get (mosmdn, objnum, 0, mdn, data); + err = dnode_get (mosmdn, objnum, DMU_OT_DSL_DIR, mdn, data); if (err) return err; @@ -3125,7 +3051,7 @@ get_filesystem_dnode (dnode_end_t * mosmdn, char *fsname, if (err) return err; - err = dnode_get (mosmdn, objnum, 0, mdn, data); + err = dnode_get (mosmdn, objnum, DMU_OT_DSL_DIR, mdn, data); if (err) return err; @@ -3139,7 +3065,7 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data) { void *osp; blkptr_t *bp; - grub_size_t ospsize = 0; + grub_size_t ospsize; grub_err_t err; grub_dprintf ("zfs", "endian = %d\n", mdn->endian); @@ -3280,7 +3206,8 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, grub_dprintf ("zfs", "endian = %d\n", subvol->mdn.endian); - err = dnode_get (&(data->mos), headobj, 0, &subvol->mdn, data); + err = dnode_get (&(data->mos), headobj, DMU_OT_DSL_DATASET, &subvol->mdn, + data); if (err) { grub_free (fsname); @@ -3332,7 +3259,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, } subvol->nkeys = 0; zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); - subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); + subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); if (!subvol->keyring) { grub_free (fsname); @@ -3475,18 +3402,14 @@ grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name) { char *nvpair; char *ret; - grub_size_t size, sz; + grub_size_t size; int found; found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, &size, 0); if (!found) return 0; - - if (grub_add (size, 3 * sizeof (grub_uint32_t), &sz)) - return 0; - - ret = grub_zalloc (sz); + ret = grub_zalloc (size + 3 * sizeof (grub_uint32_t)); if (!ret) return 0; grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); @@ -3680,13 +3603,8 @@ zfs_mount (grub_device_t dev) if (ub->ub_version >= SPA_VERSION_FEATURES && check_mos_features(&((objset_phys_t *) osp)->os_meta_dnode,ub_endian, data) != 0) - { - grub_error (GRUB_ERR_BAD_FS, "Unsupported features in pool"); - grub_free (osp); - zfs_unmount (data); - return NULL; - } - + return NULL; + /* Got the MOS. Save it at the memory addr MOS. */ grub_memmove (&(data->mos.dn), &((objset_phys_t *) osp)->os_meta_dnode, DNODE_SIZE); @@ -3694,6 +3612,8 @@ zfs_mount (grub_device_t dev) ub_endian) >> 63) & 1; grub_free (osp); + data->mounted = 1; + return data; } @@ -3983,7 +3903,7 @@ fill_fs_info (struct grub_dirhook_info *info, { headobj = grub_zfs_to_cpu64 (((dsl_dir_phys_t *) DN_BONUS (&mdn.dn))->dd_head_dataset_obj, mdn.endian); - err = dnode_get (&(data->mos), headobj, 0, &mdn, data); + err = dnode_get (&(data->mos), headobj, DMU_OT_DSL_DATASET, &mdn, data); if (err) { grub_dprintf ("zfs", "failed here\n"); @@ -4061,12 +3981,7 @@ iterate_zap (const char *name, grub_uint64_t val, struct grub_zfs_dir_ctx *ctx) dnode_end_t dn; grub_memset (&info, 0, sizeof (info)); - err = dnode_get (&(ctx->data->subvol.mdn), val, 0, &dn, ctx->data); - if (err) - { - grub_print_error (); - return 0; - } + dnode_get (&(ctx->data->subvol.mdn), val, 0, &dn, ctx->data); if (dn.dn.dn_bonustype == DMU_OT_SA) { @@ -4287,11 +4202,11 @@ check_feature (const char *name, grub_uint64_t val, * errnum: Failure. */ -static grub_err_t +static int check_mos_features(dnode_phys_t *mosmdn_phys,grub_zfs_endian_t endian,struct grub_zfs_data* data ) { grub_uint64_t objnum; - grub_err_t errnum = 0; + grub_uint8_t errnum = 0; dnode_end_t dn,mosmdn; mzap_phys_t* mzp; grub_zfs_endian_t endianzap; @@ -4347,7 +4262,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) @@ -4359,15 +4274,15 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), static struct grub_fs grub_zfs_fs = { .name = "zfs", - .fs_dir = grub_zfs_dir, - .fs_open = grub_zfs_open, - .fs_read = grub_zfs_read, - .fs_close = grub_zfs_close, - .fs_label = zfs_label, - .fs_uuid = zfs_uuid, - .fs_mtime = zfs_mtime, + .dir = grub_zfs_dir, + .open = grub_zfs_open, + .read = grub_zfs_read, + .close = grub_zfs_close, + .label = zfs_label, + .uuid = zfs_uuid, + .mtime = zfs_mtime, #ifdef GRUB_UTIL - .fs_embed = grub_zfs_embed, + .embed = grub_zfs_embed, .reserved_first_sector = 1, .blocklist_install = 0, #endif diff --git a/grub-core/fs/zfs/zfs_lz4.c b/grub-core/fs/zfs/zfs_lz4.c index 5453822d0..1212a8986 100644 --- a/grub-core/fs/zfs/zfs_lz4.c +++ b/grub-core/fs/zfs/zfs_lz4.c @@ -73,6 +73,7 @@ static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, #define U32 grub_uint32_t #define S32 grub_int32_t #define U64 grub_uint64_t +typedef grub_size_t size_t; typedef struct _U16_S { U16 v; @@ -132,10 +133,10 @@ typedef struct _U64_S { /* Decompression functions */ grub_err_t -lz4_decompress(void *s_start, void *d_start, grub_size_t s_len, grub_size_t d_len); +lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len); grub_err_t -lz4_decompress(void *s_start, void *d_start, grub_size_t s_len, grub_size_t d_len) +lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len) { const BYTE *src = s_start; U32 bufsiz = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | @@ -166,7 +167,7 @@ LZ4_uncompress_unknownOutputSize(const char *source, BYTE *const oend = op + maxOutputSize; BYTE *cpy; - grub_size_t dec[] = { 0, 3, 2, 3, 0, 0, 0, 0 }; + size_t dec[] = { 0, 3, 2, 3, 0, 0, 0, 0 }; /* Main Loop */ while (ip < iend) { @@ -183,8 +184,6 @@ LZ4_uncompress_unknownOutputSize(const char *source, } } /* copy literals */ - if ((grub_addr_t) length > ~(grub_addr_t)op) - goto _output_error; cpy = op + length; if ((cpy > oend - COPYLENGTH) || (ip + length > iend - COPYLENGTH)) { @@ -236,8 +235,8 @@ LZ4_uncompress_unknownOutputSize(const char *source, /* copy repeated sequence */ if unlikely(op - ref < STEPSIZE) { #if LZ4_ARCH64 - grub_size_t dec2table[] = { 0, 0, 0, -1, 0, 1, 2, 3 }; - grub_size_t dec2 = dec2table[op - ref]; + size_t dec2table[] = { 0, 0, 0, -1, 0, 1, 2, 3 }; + size_t dec2 = dec2table[op - ref]; #else const int dec2 = 0; #endif diff --git a/grub-core/fs/zfs/zfscrypt.c b/grub-core/fs/zfs/zfscrypt.c index de3b015f5..88dae72ef 100644 --- a/grub-core/fs/zfs/zfscrypt.c +++ b/grub-core/fs/zfs/zfscrypt.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -83,13 +82,9 @@ grub_zfs_add_key (grub_uint8_t *key_in, int passphrase) { struct grub_zfs_wrap_key *key; - grub_size_t sz; - if (!passphrase && keylen > 32) keylen = 32; - if (grub_add (sizeof (*key), keylen, &sz)) - return GRUB_ERR_OUT_OF_RANGE; - key = grub_malloc (sz); + key = grub_malloc (sizeof (*key) + keylen); if (!key) return grub_errno; key->is_passphrase = passphrase; @@ -243,7 +238,7 @@ grub_gcm_decrypt (grub_crypto_cipher_handle_t cipher, grub_crypto_xor (out + 16 * i, in + 16 * i, mul, csize); } for (j = 0; j < 8; j++) - mac[15 - j] ^= ((((grub_uint64_t) psize) * 8) >> (8 * j)); + mac[15 - j] ^= ((psize * 8) >> (8 * j)); grub_gcm_mul (mac, h); if (mac_out) @@ -359,7 +354,6 @@ grub_zfs_load_key_real (const struct grub_zfs_key *key, if (err) { grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (cipher); continue; } @@ -368,7 +362,6 @@ grub_zfs_load_key_real (const struct grub_zfs_key *key, if (err) { grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (cipher); continue; } @@ -379,7 +372,6 @@ grub_zfs_load_key_real (const struct grub_zfs_key *key, { grub_dprintf ("zfs", "key loading failed\n"); grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (cipher); continue; } @@ -389,25 +381,21 @@ grub_zfs_load_key_real (const struct grub_zfs_key *key, { grub_dprintf ("zfs", "key loading failed\n"); grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (cipher); continue; } ret = grub_crypto_cipher_open (GRUB_CIPHER_AES); if (!ret) { grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (cipher); continue; } err = grub_crypto_cipher_set_key (ret, decrypted, keylen); if (err) { - grub_errno = GRUB_ERR_NONE; - grub_crypto_cipher_close (ret); - grub_crypto_cipher_close (cipher); - continue; - } - grub_crypto_cipher_close (cipher); + grub_errno = GRUB_ERR_NONE; + grub_crypto_cipher_close (ret); + continue; + } return ret; } return NULL; @@ -430,7 +418,7 @@ grub_cmd_zfs_key (grub_extcmd_context_t ctxt, int argc, char **args) if (argc > 0) { grub_file_t file; - file = grub_file_open (args[0], GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY); + file = grub_file_open (args[0]); if (!file) return grub_errno; real_size = grub_file_read (file, buf, 1024); diff --git a/grub-core/gdb/cstub.c b/grub-core/gdb/cstub.c index b64acd70f..c94411b10 100644 --- a/grub-core/gdb/cstub.c +++ b/grub-core/gdb/cstub.c @@ -336,7 +336,6 @@ grub_gdb_trap (int trap_no) /* sAA..AA: Step one instruction from AA..AA(optional). */ case 's': stepping = 1; - /* FALLTHROUGH */ /* cAA..AA: Continue at address AA..AA(optional). */ case 'c': diff --git a/grub-core/genmod.sh.in b/grub-core/genmod.sh.in index 1250589b3..789732b10 100644 --- a/grub-core/genmod.sh.in +++ b/grub-core/genmod.sh.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e # Copyright (C) 2010 Free Software Foundation, Inc. @@ -15,12 +15,12 @@ set -e # # Example: # -# genmod.sh moddep.lst normal.module build-grub-module-verifier normal.mod +# genmod.sh moddep.lst normal.module normal.mod # moddep=$1 infile=$2 -outfile=$4 +outfile=$3 tmpfile=${outfile}.tmp modname=`echo $infile | sed -e 's@\.module.*$@@'` @@ -58,11 +58,7 @@ if test x@TARGET_APPLE_LINKER@ != x1; then -K grub_mod_init -K grub_mod_fini \ -K _grub_mod_init -K _grub_mod_fini \ -R .note.gnu.gold-version -R .note.GNU-stack \ - -R .gnu.build.attributes \ - -R .rel.gnu.build.attributes \ - -R .rela.gnu.build.attributes \ - -R .eh_frame -R .rela.eh_frame -R .rel.eh_frame \ - -R .note -R .comment -R .ARM.exidx $tmpfile || exit 1 + -R .note -R .comment $tmpfile || exit 1 fi if ! test -z "${TARGET_OBJ2ELF}"; then "${TARGET_OBJ2ELF}" $tmpfile || exit 1 @@ -95,9 +91,6 @@ else -nr:_grub_mod_init:grub_mod_init \ -nr:_grub_mod_fini:grub_mod_fini \ -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1 - rm -f $tmpfile.bin -fi -if test x@platform@ != xemu; then - ./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@ + rm -f $name.bin fi mv $tmpfile $outfile diff --git a/grub-core/genmoddep.awk b/grub-core/genmoddep.awk index 04c2863e5..2f32465c4 100644 --- a/grub-core/genmoddep.awk +++ b/grub-core/genmoddep.awk @@ -18,10 +18,6 @@ BEGIN { { if ($1 == "defined") { - if ($3 !~ /^\.refptr\./ && $3 in symtab) { - printf "%s in %s is duplicated in %s\n", $3, $2, symtab[$3] >"/dev/stderr"; - error++; - } symtab[$3] = $2; modtab[$2] = "" modtab[$2] } else if ($1 == "undefined") { @@ -33,7 +29,7 @@ BEGIN { } } else { - printf "error: %u: unrecognized input format\n", NR >"/dev/stderr"; + printf "error: %u: unrecognized input format\n", NR; error++; } } @@ -43,8 +39,6 @@ END { if (error >= 1) exit 1; - total_depcount = 0 - for (mod in modtab) { # Remove duplications. split(modtab[mod], depmods, " "); @@ -58,42 +52,14 @@ END { uniqmods[depmod] = 1; } modlist = "" - depcount[mod] = 0 for (depmod in uniqmods) { modlist = modlist " " depmod; - inverse_dependencies[depmod] = inverse_dependencies[depmod] " " mod - depcount[mod]++ - total_depcount++ } if (mod == "all_video") { continue; } printf "%s:%s\n", mod, modlist; } - - # Check that we have no dependency circles - while (total_depcount != 0) { - something_done = 0 - for (mod in depcount) { - if (depcount[mod] == 0) { - delete depcount[mod] - split(inverse_dependencies[mod], inv_depmods, " "); - for (ctr in inv_depmods) { - depcount[inv_depmods[ctr]]-- - total_depcount-- - } - delete inverse_dependencies[mod] - something_done = 1 - } - } - if (something_done == 0) { - for (mod in depcount) { - circle = circle " " mod - } - printf "error: modules %s form a dependency circle\n", circle >"/dev/stderr"; - exit 1 - } - } modlist = "" while (getline <"video.lst") { modlist = modlist " " $1; diff --git a/grub-core/gensyminfo.sh.in b/grub-core/gensyminfo.sh.in index 9bc767532..2e8716b42 100644 --- a/grub-core/gensyminfo.sh.in +++ b/grub-core/gensyminfo.sh.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e # Copyright (C) 2010 Free Software Foundation, Inc. diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 4d02e62c1..4880cefe3 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -291,7 +291,7 @@ grub_mofile_open (struct grub_gettext_context *ctx, /* Using fd_mo and not another variable because it's needed for grub_gettext_get_info. */ - fd = grub_file_open (filename, GRUB_FILE_TYPE_GETTEXT_CATALOG); + fd = grub_file_open (filename); if (!fd) return grub_errno; diff --git a/grub-core/gfxmenu/font.c b/grub-core/gfxmenu/font.c index 756c24f20..64d52670b 100644 --- a/grub-core/gfxmenu/font.c +++ b/grub-core/gfxmenu/font.c @@ -45,7 +45,6 @@ grub_font_draw_string (const char *str, grub_font_t font, grub_uint32_t *logical; grub_ssize_t logical_len, visual_len; struct grub_unicode_glyph *visual, *ptr; - grub_err_t err; logical_len = grub_utf8_to_ucs4_alloc (str, &logical, 0); if (logical_len < 0) @@ -57,28 +56,24 @@ grub_font_draw_string (const char *str, grub_font_t font, if (visual_len < 0) return grub_errno; - err = GRUB_ERR_NONE; for (ptr = visual, x = left_x; ptr < visual + visual_len; ptr++) { + grub_err_t err; struct grub_font_glyph *glyph; glyph = grub_font_construct_glyph (font, ptr); if (!glyph) - { - err = grub_errno; - goto out; - } + return grub_errno; err = grub_font_draw_glyph (glyph, color, x, baseline_y); - if (err) - goto out; x += glyph->device_width; + if (err) + return err; } -out: for (ptr = visual; ptr < visual + visual_len; ptr++) grub_unicode_destroy_glyph (ptr); grub_free (visual); - return err; + return GRUB_ERR_NONE; } /* Get the width in pixels of the specified UTF-8 string, when rendered in diff --git a/grub-core/gfxmenu/gfxmenu.c b/grub-core/gfxmenu/gfxmenu.c index 8a17dda2c..f49fce802 100644 --- a/grub-core/gfxmenu/gfxmenu.c +++ b/grub-core/gfxmenu/gfxmenu.c @@ -63,14 +63,14 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested) return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "theme"); - err = grub_video_get_info (&mode_info); - if (err) - return err; - instance = grub_zalloc (sizeof (*instance)); if (!instance) return grub_errno; + err = grub_video_get_info (&mode_info); + if (err) + return err; + if (theme_path[0] != '/' && theme_path[0] != '(') { const char *prefix; diff --git a/grub-core/gfxmenu/gui_circular_progress.c b/grub-core/gfxmenu/gui_circular_progress.c index 7578bfbec..354dd7b73 100644 --- a/grub-core/gfxmenu/gui_circular_progress.c +++ b/grub-core/gfxmenu/gui_circular_progress.c @@ -230,7 +230,7 @@ circprog_set_state (void *vself, int visible, int start, static int parse_angle (const char *value) { - const char *ptr; + char *ptr; int angle; angle = grub_strtol (value, &ptr, 10); diff --git a/grub-core/gfxmenu/gui_image.c b/grub-core/gfxmenu/gui_image.c index 6b2e976f1..29784ed2d 100644 --- a/grub-core/gfxmenu/gui_image.c +++ b/grub-core/gfxmenu/gui_image.c @@ -195,10 +195,7 @@ load_image (grub_gui_image_t self, const char *path) return grub_errno; if (self->bitmap && (self->bitmap != self->raw_bitmap)) - { - grub_video_bitmap_destroy (self->bitmap); - self->bitmap = 0; - } + grub_video_bitmap_destroy (self->bitmap); if (self->raw_bitmap) grub_video_bitmap_destroy (self->raw_bitmap); diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c index ba1e1eab3..a9a415e31 100644 --- a/grub-core/gfxmenu/gui_string_util.c +++ b/grub-core/gfxmenu/gui_string_util.c @@ -55,7 +55,7 @@ canonicalize_path (const char *path) if (*p == '/') components++; - char **path_array = grub_calloc (components, sizeof (*path_array)); + char **path_array = grub_malloc (components * sizeof (*path_array)); if (! path_array) return 0; diff --git a/grub-core/gfxmenu/icon_manager.c b/grub-core/gfxmenu/icon_manager.c index 1894682ef..ff49ab0e0 100644 --- a/grub-core/gfxmenu/icon_manager.c +++ b/grub-core/gfxmenu/icon_manager.c @@ -106,10 +106,8 @@ grub_gfxmenu_icon_manager_set_theme_path (grub_gfxmenu_icon_manager_t mgr, const char *path) { /* Clear the cache if the theme path has changed. */ - if (mgr->theme_path == 0 && path == 0) - return; - if (mgr->theme_path == 0 || path == 0 - || grub_strcmp (mgr->theme_path, path) != 0) + if (((mgr->theme_path == 0) != (path == 0)) + || (grub_strcmp (mgr->theme_path, path) != 0)) grub_gfxmenu_icon_manager_clear_cache (mgr); grub_free (mgr->theme_path); diff --git a/include/grub/i386/coreboot/kernel.h b/grub-core/gfxmenu/model.c similarity index 100% rename from include/grub/i386/coreboot/kernel.h rename to grub-core/gfxmenu/model.c diff --git a/grub-core/gfxmenu/theme_loader.c b/grub-core/gfxmenu/theme_loader.c index eae83086b..8a7945816 100644 --- a/grub-core/gfxmenu/theme_loader.c +++ b/grub-core/gfxmenu/theme_loader.c @@ -255,7 +255,7 @@ theme_set_string (grub_gfxmenu_view_t view, { unsigned int tmp; int err = theme_get_unsigned_int_from_proportional (value, - view->screen.height, + view->screen.width, &tmp); if (err != GRUB_ERR_NONE) return err; @@ -275,7 +275,7 @@ theme_set_string (grub_gfxmenu_view_t view, { unsigned int tmp; int err = theme_get_unsigned_int_from_proportional (value, - view->screen.height, + view->screen.width, &tmp); if (err != GRUB_ERR_NONE) return err; @@ -484,7 +484,7 @@ parse_proportional_spec (const char *value, signed *abs, grub_fixed_signed_t *pr ptr++; } - num = grub_strtoul (ptr, &ptr, 0); + num = grub_strtoul (ptr, (char **) &ptr, 0); if (grub_errno) return grub_errno; if (sig) @@ -743,7 +743,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) p.view = view; p.theme_dir = grub_get_dirname (theme_path); - file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME); + file = grub_file_open (theme_path); if (! file) { grub_free (p.theme_dir); @@ -774,8 +774,6 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) view->canvas->component.ops->destroy (view->canvas); view->canvas = grub_gui_canvas_new (); - if (!view->canvas) - goto fail; ((grub_gui_component_t) view->canvas) ->ops->set_bounds ((grub_gui_component_t) view->canvas, &view->screen); diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c index 470597ded..b60602889 100644 --- a/grub-core/gfxmenu/widget-box.c +++ b/grub-core/gfxmenu/widget-box.c @@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, box->content_height = 0; box->raw_pixmaps = (struct grub_video_bitmap **) - grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); box->scaled_pixmaps = (struct grub_video_bitmap **) - grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); /* Initialize all pixmap pointers to NULL so that proper destruction can be performed if an error is encountered partway through construction. */ diff --git a/grub-core/lib/gnulib-patches/fix-null-deref.patch b/grub-core/gnulib-fix-null-deref.diff similarity index 52% rename from grub-core/lib/gnulib-patches/fix-null-deref.patch rename to grub-core/gnulib-fix-null-deref.diff index 8fafa153a..a2fba8c3b 100644 --- a/grub-core/lib/gnulib-patches/fix-null-deref.patch +++ b/grub-core/gnulib-fix-null-deref.diff @@ -1,8 +1,7 @@ -diff --git a/lib/argp-parse.c b/lib/argp-parse.c -index 6dec57310..900adad54 100644 ---- a/lib/argp-parse.c -+++ b/lib/argp-parse.c -@@ -940,7 +940,7 @@ weak_alias (__argp_parse, argp_parse) +=== modified file 'grub-core/gnulib/argp-parse.c' +--- grub-core/gnulib/argp-parse.c 2010-04-02 22:45:01 +0000 ++++ grub-core/gnulib/argp-parse.c 2011-04-10 13:25:52 +0000 +@@ -935,7 +935,7 @@ void * __argp_input (const struct argp *argp, const struct argp_state *state) { @@ -11,3 +10,4 @@ index 6dec57310..900adad54 100644 { struct group *group; struct parser *parser = state->pstate; + diff --git a/grub-core/lib/gnulib-patches/fix-width.patch b/grub-core/gnulib-fix-width.diff similarity index 75% rename from grub-core/lib/gnulib-patches/fix-width.patch rename to grub-core/gnulib-fix-width.diff index 0a208ad08..ae77af6c9 100644 --- a/grub-core/lib/gnulib-patches/fix-width.patch +++ b/grub-core/gnulib-fix-width.diff @@ -1,8 +1,8 @@ diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c -index ba6a407f7..d0685b3d4 100644 +index 7aa317c..02406ff 100644 --- a/lib/argp-fmtstream.c +++ b/lib/argp-fmtstream.c -@@ -28,9 +28,11 @@ +@@ -29,9 +29,11 @@ #include #include #include @@ -14,7 +14,7 @@ index ba6a407f7..d0685b3d4 100644 #ifndef ARGP_FMTSTREAM_USE_LINEWRAP -@@ -115,6 +117,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free) +@@ -116,6 +118,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free) #endif #endif @@ -66,12 +66,12 @@ index ba6a407f7..d0685b3d4 100644 /* Process FS's buffer so that line wrapping is done from POINT_OFFS to the end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ void -@@ -168,13 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +@@ -168,14 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) + if (!nl) { ++ size_t display_width = mbsnwidth (buf, fs->p - buf, MBSW_STOP_AT_NUL); /* The buffer ends in a partial line. */ -+ size_t display_width = mbsnwidth (buf, fs->p - buf, -+ MBSW_STOP_AT_NUL); - if (fs->point_col + len < fs->rmargin) + if (fs->point_col + display_width < fs->rmargin) @@ -84,7 +84,7 @@ index ba6a407f7..d0685b3d4 100644 break; } else -@@ -182,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +@@ -183,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs) the end of the buffer. */ nl = fs->p; } @@ -111,16 +111,16 @@ index ba6a407f7..d0685b3d4 100644 /* This line is too long. */ r = fs->rmargin - 1; -@@ -225,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +@@ -226,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) char *p, *nextline; int i; - p = buf + (r + 1 - fs->point_col); -+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); ++ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); while (p >= buf && !isblank ((unsigned char) *p)) --p; nextline = p + 1; /* This will begin the next line. */ -@@ -243,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +@@ -244,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) { /* A single word that is greater than the maximum line width. Oh well. Put it on an overlong line by itself. */ @@ -129,21 +129,21 @@ index ba6a407f7..d0685b3d4 100644 /* Find the end of the long word. */ if (p < nl) do -@@ -277,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +@@ -278,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) && fs->p > nextline) { /* The margin needs more blanks than we removed. */ - if (fs->end - fs->p > fs->wmargin + 1) + if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL) -+ > fs->wmargin + 1) ++ > fs->wmargin + 1) /* Make some space for them. */ { size_t mv = fs->p - nextline; diff --git a/lib/argp-help.c b/lib/argp-help.c -index e5375a0f0..5d8f451ec 100644 +index 354f1e2..2914f47 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c -@@ -51,6 +51,7 @@ +@@ -50,6 +50,7 @@ #include "argp.h" #include "argp-fmtstream.h" #include "argp-namefrob.h" @@ -151,7 +151,7 @@ index e5375a0f0..5d8f451ec 100644 #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) -@@ -1432,7 +1433,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, +@@ -1452,7 +1453,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, /* Manually do line wrapping so that it (probably) won't get wrapped at any embedded spaces. */ @@ -161,57 +161,71 @@ index e5375a0f0..5d8f451ec 100644 __argp_fmtstream_write (stream, cp, nl - cp); } diff --git a/lib/mbswidth.c b/lib/mbswidth.c -index 408a15e34..b3fb7f83a 100644 +index 7c2dfce..baa4f27 100644 --- a/lib/mbswidth.c +++ b/lib/mbswidth.c -@@ -38,6 +38,14 @@ - /* Get INT_MAX. */ - #include - -+#ifndef FALLTHROUGH -+# if __GNUC__ < 7 -+# define FALLTHROUGH ((void) 0) -+# else -+# define FALLTHROUGH __attribute__ ((__fallthrough__)) -+# endif -+#endif -+ - /* Returns the number of columns needed to represent the multibyte - character string pointed to by STRING. If a non-printable character - occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. -@@ -90,6 +98,10 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +@@ -90,6 +90,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) p++; width++; break; -+ case '\0': -+ if (flags & MBSW_STOP_AT_NUL) -+ return width; -+ FALLTHROUGH; ++ case '\0': ++ if (flags & MBSW_STOP_AT_NUL) ++ return width; default: /* If we have a multibyte sequence, scan it up to its end. */ { -@@ -168,6 +180,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +@@ -168,6 +171,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) { unsigned char c = (unsigned char) *p++; + if (c == 0 && (flags & MBSW_STOP_AT_NUL)) -+ return width; ++ return width; + if (isprint (c)) { if (width == INT_MAX) diff --git a/lib/mbswidth.h b/lib/mbswidth.h -index 2b5c53c37..45a123e63 100644 +index e9c0b03..d7207c5 100644 --- a/lib/mbswidth.h +++ b/lib/mbswidth.h -@@ -45,6 +45,10 @@ extern "C" { +@@ -45,6 +45,9 @@ extern "C" { control characters and 1 otherwise. */ #define MBSW_REJECT_UNPRINTABLE 2 +/* If this bit is set \0 is treated as the end of string. + Otherwise it's treated as a normal one column width character. */ +#define MBSW_STOP_AT_NUL 4 -+ /* Returns the number of screen columns needed for STRING. */ #define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ +diff --git a/modules/argp b/modules/argp +index 125046a..6f14d10 100644 +--- a/modules/argp ++++ b/modules/argp +@@ -40,6 +40,7 @@ stdalign + strerror + memchr + memmove ++mbswidth + + configure.ac: + gl_ARGP +diff --git a/modules/argp-tests b/modules/argp-tests +index 8f92a4d..0463927 100644 +--- a/modules/argp-tests ++++ b/modules/argp-tests +@@ -1,11 +1,13 @@ + Files: + tests/test-argp.c + tests/test-argp-2.sh ++tests/test-argp-2-utf.sh + + Depends-on: + progname + + Makefile.am: + TESTS += test-argp test-argp-2.sh +-check_PROGRAMS += test-argp ++TESTS += test-argp test-argp-2.sh test-argp-2-utf.sh ++check_PROGRAMS += test-argp test-argp-utf8 + test_argp_LDADD = $(LDADD) @LIBINTL@ diff --git a/grub-core/gnulib-no-abort.diff b/grub-core/gnulib-no-abort.diff new file mode 100644 index 000000000..8377338f7 --- /dev/null +++ b/grub-core/gnulib-no-abort.diff @@ -0,0 +1,30 @@ +=== modified file 'grub-core/gnulib/regcomp.c' +--- grub-core/gnulib/regcomp.c 2010-09-20 10:35:33 +0000 ++++ grub-core/gnulib/regcomp.c 2012-03-10 11:31:42 +0000 +@@ -549,13 +549,9 @@ regerror (int errcode, const regex_t *_R + if (BE (errcode < 0 + || errcode >= (int) (sizeof (__re_error_msgid_idx) + / sizeof (__re_error_msgid_idx[0])), 0)) +- /* Only error codes returned by the rest of the code should be passed +- to this routine. If we are given anything else, or if other regex +- code generates an invalid error code, then the program has a bug. +- Dump core so we can fix it. */ +- abort (); +- +- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); ++ msg = gettext ("unknown regexp error"); ++ else ++ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); + + msg_size = strlen (msg) + 1; /* Includes the null. */ + +@@ -1119,7 +1119,7 @@ + } + break; + default: +- abort (); ++ break; + } + + if (mb_chars || has_period) + diff --git a/grub-core/gnulib-no-gets.diff b/grub-core/gnulib-no-gets.diff new file mode 100644 index 000000000..1a9487e84 --- /dev/null +++ b/grub-core/gnulib-no-gets.diff @@ -0,0 +1,10 @@ +--- /tmp/x.diff 2013-04-11 16:51:42.777873536 +0200 ++++ grub-core/gnulib/stdio.in.h 2013-04-11 16:51:49.917873298 +0200 +@@ -700,7 +700,6 @@ + removed it. */ + #undef gets + #if HAVE_RAW_DECL_GETS +-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); + #endif + + diff --git a/grub-core/gnulib/Makefile.am b/grub-core/gnulib/Makefile.am new file mode 100644 index 000000000..3444397fe --- /dev/null +++ b/grub-core/gnulib/Makefile.am @@ -0,0 +1,1747 @@ +## DO NOT EDIT! GENERATED AUTOMATICALLY! +## Process this file with automake to produce Makefile.in. +# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this file. If not, see . +# +# As a special exception to the GNU General Public License, +# this file may be distributed as part of a program that +# contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex + +AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects + +SUBDIRS = +noinst_HEADERS = +noinst_LIBRARIES = +noinst_LTLIBRARIES = +EXTRA_DIST = +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = core *.stackdump +MOSTLYCLEANDIRS = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +AM_CPPFLAGS = +AM_CFLAGS = + +noinst_LIBRARIES += libgnu.a + +libgnu_a_SOURCES = +libgnu_a_LIBADD = $(gl_LIBOBJS) +libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) +EXTRA_libgnu_a_SOURCES = + +## begin gnulib module alloca + + +libgnu_a_LIBADD += @ALLOCA@ +libgnu_a_DEPENDENCIES += @ALLOCA@ +EXTRA_DIST += alloca.c + +EXTRA_libgnu_a_SOURCES += alloca.c + +## end gnulib module alloca + +## begin gnulib module alloca-opt + +BUILT_SOURCES += $(ALLOCA_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_ALLOCA_H +alloca.h: alloca.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/alloca.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +else +alloca.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += alloca.h alloca.h-t + +EXTRA_DIST += alloca.in.h + +## end gnulib module alloca-opt + +## begin gnulib module argp + +libgnu_a_SOURCES += argp.h argp-ba.c argp-eexst.c \ + argp-fmtstream.c argp-fmtstream.h argp-fs-xinl.c argp-help.c \ + argp-namefrob.h argp-parse.c argp-pin.c argp-pv.c argp-pvh.c \ + argp-xinl.c + +## end gnulib module argp + +## begin gnulib module btowc + + +EXTRA_DIST += btowc.c + +EXTRA_libgnu_a_SOURCES += btowc.c + +## end gnulib module btowc + +## begin gnulib module configmake + +# Listed in the same order as the GNU makefile conventions, and +# provided by autoconf 2.59c+. +# The Automake-defined pkg* macros are appended, in the order +# listed in the Automake 1.10a+ documentation. +configmake.h: Makefile + $(AM_V_GEN)rm -f $@-t && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#define PREFIX "$(prefix)"'; \ + echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ + echo '#define BINDIR "$(bindir)"'; \ + echo '#define SBINDIR "$(sbindir)"'; \ + echo '#define LIBEXECDIR "$(libexecdir)"'; \ + echo '#define DATAROOTDIR "$(datarootdir)"'; \ + echo '#define DATADIR "$(datadir)"'; \ + echo '#define SYSCONFDIR "$(sysconfdir)"'; \ + echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \ + echo '#define LOCALSTATEDIR "$(localstatedir)"'; \ + echo '#define INCLUDEDIR "$(includedir)"'; \ + echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \ + echo '#define DOCDIR "$(docdir)"'; \ + echo '#define INFODIR "$(infodir)"'; \ + echo '#define HTMLDIR "$(htmldir)"'; \ + echo '#define DVIDIR "$(dvidir)"'; \ + echo '#define PDFDIR "$(pdfdir)"'; \ + echo '#define PSDIR "$(psdir)"'; \ + echo '#define LIBDIR "$(libdir)"'; \ + echo '#define LISPDIR "$(lispdir)"'; \ + echo '#define LOCALEDIR "$(localedir)"'; \ + echo '#define MANDIR "$(mandir)"'; \ + echo '#define MANEXT "$(manext)"'; \ + echo '#define PKGDATADIR "$(pkgdatadir)"'; \ + echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ + echo '#define PKGLIBDIR "$(pkglibdir)"'; \ + echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ + } | sed '/""/d' > $@-t && \ + mv -f $@-t $@ + +BUILT_SOURCES += configmake.h +CLEANFILES += configmake.h configmake.h-t + +## end gnulib module configmake + +## begin gnulib module dirname-lgpl + +libgnu_a_SOURCES += dirname-lgpl.c basename-lgpl.c stripslash.c + +EXTRA_DIST += dirname.h + +## end gnulib module dirname-lgpl + +## begin gnulib module dosname + + +EXTRA_DIST += dosname.h + +## end gnulib module dosname + +## begin gnulib module errno + +BUILT_SOURCES += $(ERRNO_H) + +# We need the following in order to create when the system +# doesn't have one that is POSIX compliant. +if GL_GENERATE_ERRNO_H +errno.h: errno.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_ERRNO_H''@|$(NEXT_ERRNO_H)|g' \ + -e 's|@''EMULTIHOP_HIDDEN''@|$(EMULTIHOP_HIDDEN)|g' \ + -e 's|@''EMULTIHOP_VALUE''@|$(EMULTIHOP_VALUE)|g' \ + -e 's|@''ENOLINK_HIDDEN''@|$(ENOLINK_HIDDEN)|g' \ + -e 's|@''ENOLINK_VALUE''@|$(ENOLINK_VALUE)|g' \ + -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ + -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ + < $(srcdir)/errno.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +errno.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += errno.h errno.h-t + +EXTRA_DIST += errno.in.h + +## end gnulib module errno + +## begin gnulib module error + + +EXTRA_DIST += error.c error.h + +EXTRA_libgnu_a_SOURCES += error.c + +## end gnulib module error + +## begin gnulib module float + +BUILT_SOURCES += $(FLOAT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_FLOAT_H +float.h: float.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ + -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ + < $(srcdir)/float.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +float.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += float.h float.h-t + +EXTRA_DIST += float.c float.in.h itold.c + +EXTRA_libgnu_a_SOURCES += float.c itold.c + +## end gnulib module float + +## begin gnulib module fnmatch + +BUILT_SOURCES += $(FNMATCH_H) + +# We need the following in order to create when the system +# doesn't have one that supports the required API. +if GL_GENERATE_FNMATCH_H +fnmatch.h: fnmatch.in.h $(top_builddir)/config.status $(ARG_NONNULL_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + < $(srcdir)/fnmatch.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +else +fnmatch.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += fnmatch.h fnmatch.h-t + +EXTRA_DIST += fnmatch.c fnmatch.in.h fnmatch_loop.c + +EXTRA_libgnu_a_SOURCES += fnmatch.c fnmatch_loop.c + +## end gnulib module fnmatch + +## begin gnulib module getdelim + + +EXTRA_DIST += getdelim.c + +EXTRA_libgnu_a_SOURCES += getdelim.c + +## end gnulib module getdelim + +## begin gnulib module getline + + +EXTRA_DIST += getline.c + +EXTRA_libgnu_a_SOURCES += getline.c + +## end gnulib module getline + +## begin gnulib module getopt-posix + +BUILT_SOURCES += $(GETOPT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + < $(srcdir)/getopt.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +MOSTLYCLEANFILES += getopt.h getopt.h-t + +EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h + +EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c + +## end gnulib module getopt-posix + +## begin gnulib module gettext + +# This is for those projects which use "gettextize --intl" to put a source-code +# copy of libintl into their package. In such projects, every Makefile.am needs +# -I$(top_builddir)/intl, so that can be found in this directory. +# For the Makefile.ams in other directories it is the maintainer's +# responsibility; for the one from gnulib we do it here. +# This option has no effect when the user disables NLS (because then the intl +# directory contains no libintl.h file) or when the project does not use +# "gettextize --intl". +AM_CPPFLAGS += -I$(top_builddir)/intl + +EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath + +## end gnulib module gettext + +## begin gnulib module gettext-h + +libgnu_a_SOURCES += gettext.h + +## end gnulib module gettext-h + +## begin gnulib module havelib + + +EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath + +## end gnulib module havelib + +## begin gnulib module intprops + + +EXTRA_DIST += intprops.h + +## end gnulib module intprops + +## begin gnulib module langinfo + +BUILT_SOURCES += langinfo.h + +# We need the following in order to create an empty placeholder for +# when the system doesn't have one. +langinfo.h: langinfo.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_LANGINFO_H''@|$(HAVE_LANGINFO_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \ + -e 's/@''GNULIB_NL_LANGINFO''@/$(GNULIB_NL_LANGINFO)/g' \ + -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \ + -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \ + -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \ + -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \ + -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \ + -e 's|@''REPLACE_NL_LANGINFO''@|$(REPLACE_NL_LANGINFO)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/langinfo.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += langinfo.h langinfo.h-t + +EXTRA_DIST += langinfo.in.h + +## end gnulib module langinfo + +## begin gnulib module localcharset + +libgnu_a_SOURCES += localcharset.h localcharset.c + +# We need the following in order to install a simple file in $(libdir) +# which is shared with other installed packages. We use a list of referencing +# packages so that "make uninstall" will remove the file if and only if it +# is not used by another installed package. +# On systems with glibc-2.1 or newer, the file is redundant, therefore we +# avoid installing it. + +all-local: charset.alias ref-add.sed ref-del.sed + +charset_alias = $(DESTDIR)$(libdir)/charset.alias +charset_tmp = $(DESTDIR)$(libdir)/charset.tmp +install-exec-local: install-exec-localcharset +install-exec-localcharset: all-local + if test $(GLIBC21) = no; then \ + case '$(host_os)' in \ + darwin[56]*) \ + need_charset_alias=true ;; \ + darwin* | cygwin* | mingw* | pw32* | cegcc*) \ + need_charset_alias=false ;; \ + *) \ + need_charset_alias=true ;; \ + esac ; \ + else \ + need_charset_alias=false ; \ + fi ; \ + if $$need_charset_alias; then \ + $(mkinstalldirs) $(DESTDIR)$(libdir) ; \ + fi ; \ + if test -f $(charset_alias); then \ + sed -f ref-add.sed $(charset_alias) > $(charset_tmp) ; \ + $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \ + rm -f $(charset_tmp) ; \ + else \ + if $$need_charset_alias; then \ + sed -f ref-add.sed charset.alias > $(charset_tmp) ; \ + $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \ + rm -f $(charset_tmp) ; \ + fi ; \ + fi + +uninstall-local: uninstall-localcharset +uninstall-localcharset: all-local + if test -f $(charset_alias); then \ + sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \ + if grep '^# Packages using this file: $$' $(charset_tmp) \ + > /dev/null; then \ + rm -f $(charset_alias); \ + else \ + $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \ + fi; \ + rm -f $(charset_tmp); \ + fi + +charset.alias: config.charset + $(AM_V_GEN)rm -f t-$@ $@ && \ + $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \ + mv t-$@ $@ + +SUFFIXES += .sed .sin +.sin.sed: + $(AM_V_GEN)rm -f t-$@ $@ && \ + sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \ + mv t-$@ $@ + +CLEANFILES += charset.alias ref-add.sed ref-del.sed + +EXTRA_DIST += config.charset ref-add.sin ref-del.sin + +## end gnulib module localcharset + +## begin gnulib module locale + +BUILT_SOURCES += locale.h + +# We need the following in order to create when the system +# doesn't have one that provides all definitions. +locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \ + -e 's/@''GNULIB_LOCALECONV''@/$(GNULIB_LOCALECONV)/g' \ + -e 's/@''GNULIB_SETLOCALE''@/$(GNULIB_SETLOCALE)/g' \ + -e 's/@''GNULIB_DUPLOCALE''@/$(GNULIB_DUPLOCALE)/g' \ + -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \ + -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \ + -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \ + -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \ + -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \ + -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/locale.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += locale.h locale.h-t + +EXTRA_DIST += locale.in.h + +## end gnulib module locale + +## begin gnulib module localeconv + + +EXTRA_DIST += localeconv.c + +EXTRA_libgnu_a_SOURCES += localeconv.c + +## end gnulib module localeconv + +## begin gnulib module malloc-gnu + + +EXTRA_DIST += malloc.c + +EXTRA_libgnu_a_SOURCES += malloc.c + +## end gnulib module malloc-gnu + +## begin gnulib module malloc-posix + + +EXTRA_DIST += malloc.c + +EXTRA_libgnu_a_SOURCES += malloc.c + +## end gnulib module malloc-posix + +## begin gnulib module mbrtowc + + +EXTRA_DIST += mbrtowc.c + +EXTRA_libgnu_a_SOURCES += mbrtowc.c + +## end gnulib module mbrtowc + +## begin gnulib module mbsinit + + +EXTRA_DIST += mbsinit.c + +EXTRA_libgnu_a_SOURCES += mbsinit.c + +## end gnulib module mbsinit + +## begin gnulib module mbsrtowcs + + +EXTRA_DIST += mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c + +EXTRA_libgnu_a_SOURCES += mbsrtowcs-state.c mbsrtowcs.c + +## end gnulib module mbsrtowcs + +## begin gnulib module mbswidth + +libgnu_a_SOURCES += mbswidth.h mbswidth.c + +## end gnulib module mbswidth + +## begin gnulib module mbtowc + + +EXTRA_DIST += mbtowc-impl.h mbtowc.c + +EXTRA_libgnu_a_SOURCES += mbtowc.c + +## end gnulib module mbtowc + +## begin gnulib module memchr + + +EXTRA_DIST += memchr.c memchr.valgrind + +EXTRA_libgnu_a_SOURCES += memchr.c + +## end gnulib module memchr + +## begin gnulib module mempcpy + + +EXTRA_DIST += mempcpy.c + +EXTRA_libgnu_a_SOURCES += mempcpy.c + +## end gnulib module mempcpy + +## begin gnulib module msvc-inval + + +EXTRA_DIST += msvc-inval.c msvc-inval.h + +EXTRA_libgnu_a_SOURCES += msvc-inval.c + +## end gnulib module msvc-inval + +## begin gnulib module msvc-nothrow + + +EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h + +EXTRA_libgnu_a_SOURCES += msvc-nothrow.c + +## end gnulib module msvc-nothrow + +## begin gnulib module nl_langinfo + + +EXTRA_DIST += nl_langinfo.c + +EXTRA_libgnu_a_SOURCES += nl_langinfo.c + +## end gnulib module nl_langinfo + +## begin gnulib module progname + +libgnu_a_SOURCES += progname.h progname.c + +## end gnulib module progname + +## begin gnulib module rawmemchr + + +EXTRA_DIST += rawmemchr.c rawmemchr.valgrind + +EXTRA_libgnu_a_SOURCES += rawmemchr.c + +## end gnulib module rawmemchr + +## begin gnulib module realloc-posix + + +EXTRA_DIST += realloc.c + +EXTRA_libgnu_a_SOURCES += realloc.c + +## end gnulib module realloc-posix + +## begin gnulib module regex + + +EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c + +EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c + +## end gnulib module regex + +## begin gnulib module size_max + +libgnu_a_SOURCES += size_max.h + +## end gnulib module size_max + +## begin gnulib module sleep + + +EXTRA_DIST += sleep.c + +EXTRA_libgnu_a_SOURCES += sleep.c + +## end gnulib module sleep + +## begin gnulib module snippet/_Noreturn + +# Because this Makefile snippet defines a variable used by other +# gnulib Makefile snippets, it must be present in all Makefile.am that +# need it. This is ensured by the applicability 'all' defined above. + +_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h + +EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h + +## end gnulib module snippet/_Noreturn + +## begin gnulib module snippet/arg-nonnull + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +BUILT_SOURCES += arg-nonnull.h +# The arg-nonnull.h that gets inserted into generated .h files is the same as +# build-aux/snippet/arg-nonnull.h, except that it has the copyright header cut +# off. +arg-nonnull.h: $(top_srcdir)/build-aux/snippet/arg-nonnull.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_ARG_NONNULL/,$$p' \ + < $(top_srcdir)/build-aux/snippet/arg-nonnull.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t + +ARG_NONNULL_H=arg-nonnull.h + +EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h + +## end gnulib module snippet/arg-nonnull + +## begin gnulib module snippet/c++defs + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +BUILT_SOURCES += c++defs.h +# The c++defs.h that gets inserted into generated .h files is the same as +# build-aux/snippet/c++defs.h, except that it has the copyright header cut off. +c++defs.h: $(top_srcdir)/build-aux/snippet/c++defs.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/_GL_CXXDEFS/,$$p' \ + < $(top_srcdir)/build-aux/snippet/c++defs.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += c++defs.h c++defs.h-t + +CXXDEFS_H=c++defs.h + +EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h + +## end gnulib module snippet/c++defs + +## begin gnulib module snippet/warn-on-use + +BUILT_SOURCES += warn-on-use.h +# The warn-on-use.h that gets inserted into generated .h files is the same as +# build-aux/snippet/warn-on-use.h, except that it has the copyright header cut +# off. +warn-on-use.h: $(top_srcdir)/build-aux/snippet/warn-on-use.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/^.ifndef/,$$p' \ + < $(top_srcdir)/build-aux/snippet/warn-on-use.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t + +WARN_ON_USE_H=warn-on-use.h + +EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h + +## end gnulib module snippet/warn-on-use + +## begin gnulib module stdalign + +BUILT_SOURCES += $(STDALIGN_H) + +# We need the following in order to create when the system +# doesn't have one that works. +if GL_GENERATE_STDALIGN_H +stdalign.h: stdalign.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/stdalign.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +stdalign.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stdalign.h stdalign.h-t + +EXTRA_DIST += stdalign.in.h + +## end gnulib module stdalign + +## begin gnulib module stdbool + +BUILT_SOURCES += $(STDBOOL_H) + +# We need the following in order to create when the system +# doesn't have one that works. +if GL_GENERATE_STDBOOL_H +stdbool.h: stdbool.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +stdbool.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stdbool.h stdbool.h-t + +EXTRA_DIST += stdbool.in.h + +## end gnulib module stdbool + +## begin gnulib module stddef + +BUILT_SOURCES += $(STDDEF_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_STDDEF_H +stddef.h: stddef.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ + -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ + -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ + < $(srcdir)/stddef.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +stddef.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stddef.h stddef.h-t + +EXTRA_DIST += stddef.in.h + +## end gnulib module stddef + +## begin gnulib module stdint + +BUILT_SOURCES += $(STDINT_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_STDINT_H +stdint.h: stdint.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \ + -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ + -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ + -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ + -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \ + -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \ + -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \ + -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ + -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \ + -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \ + -e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \ + -e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \ + -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \ + -e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ + -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ + -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ + < $(srcdir)/stdint.in.h; \ + } > $@-t && \ + mv $@-t $@ +else +stdint.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += stdint.h stdint.h-t + +EXTRA_DIST += stdint.in.h + +## end gnulib module stdint + +## begin gnulib module stdio + +BUILT_SOURCES += stdio.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \ + -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \ + -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \ + -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \ + -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \ + -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \ + -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \ + -e 's/@''GNULIB_FOPEN''@/$(GNULIB_FOPEN)/g' \ + -e 's/@''GNULIB_FPRINTF''@/$(GNULIB_FPRINTF)/g' \ + -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GNULIB_FPRINTF_POSIX)/g' \ + -e 's/@''GNULIB_FPURGE''@/$(GNULIB_FPURGE)/g' \ + -e 's/@''GNULIB_FPUTC''@/$(GNULIB_FPUTC)/g' \ + -e 's/@''GNULIB_FPUTS''@/$(GNULIB_FPUTS)/g' \ + -e 's/@''GNULIB_FREAD''@/$(GNULIB_FREAD)/g' \ + -e 's/@''GNULIB_FREOPEN''@/$(GNULIB_FREOPEN)/g' \ + -e 's/@''GNULIB_FSCANF''@/$(GNULIB_FSCANF)/g' \ + -e 's/@''GNULIB_FSEEK''@/$(GNULIB_FSEEK)/g' \ + -e 's/@''GNULIB_FSEEKO''@/$(GNULIB_FSEEKO)/g' \ + -e 's/@''GNULIB_FTELL''@/$(GNULIB_FTELL)/g' \ + -e 's/@''GNULIB_FTELLO''@/$(GNULIB_FTELLO)/g' \ + -e 's/@''GNULIB_FWRITE''@/$(GNULIB_FWRITE)/g' \ + -e 's/@''GNULIB_GETC''@/$(GNULIB_GETC)/g' \ + -e 's/@''GNULIB_GETCHAR''@/$(GNULIB_GETCHAR)/g' \ + -e 's/@''GNULIB_GETDELIM''@/$(GNULIB_GETDELIM)/g' \ + -e 's/@''GNULIB_GETLINE''@/$(GNULIB_GETLINE)/g' \ + -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \ + -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \ + -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \ + -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \ + -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \ + -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \ + -e 's/@''GNULIB_PRINTF_POSIX''@/$(GNULIB_PRINTF_POSIX)/g' \ + -e 's/@''GNULIB_PUTC''@/$(GNULIB_PUTC)/g' \ + -e 's/@''GNULIB_PUTCHAR''@/$(GNULIB_PUTCHAR)/g' \ + -e 's/@''GNULIB_PUTS''@/$(GNULIB_PUTS)/g' \ + -e 's/@''GNULIB_REMOVE''@/$(GNULIB_REMOVE)/g' \ + -e 's/@''GNULIB_RENAME''@/$(GNULIB_RENAME)/g' \ + -e 's/@''GNULIB_RENAMEAT''@/$(GNULIB_RENAMEAT)/g' \ + -e 's/@''GNULIB_SCANF''@/$(GNULIB_SCANF)/g' \ + -e 's/@''GNULIB_SNPRINTF''@/$(GNULIB_SNPRINTF)/g' \ + -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GNULIB_SPRINTF_POSIX)/g' \ + -e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GNULIB_STDIO_H_NONBLOCKING)/g' \ + -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \ + -e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \ + -e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \ + -e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \ + -e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \ + -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \ + -e 's/@''GNULIB_VFSCANF''@/$(GNULIB_VFSCANF)/g' \ + -e 's/@''GNULIB_VSCANF''@/$(GNULIB_VSCANF)/g' \ + -e 's/@''GNULIB_VPRINTF''@/$(GNULIB_VPRINTF)/g' \ + -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \ + -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ + -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ + < $(srcdir)/stdio.in.h | \ + sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ + -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \ + -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \ + -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ + -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \ + -e 's|@''HAVE_DECL_OBSTACK_PRINTF''@|$(HAVE_DECL_OBSTACK_PRINTF)|g' \ + -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \ + -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \ + -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \ + -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \ + -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|g' \ + -e 's|@''HAVE_PCLOSE''@|$(HAVE_PCLOSE)|g' \ + -e 's|@''HAVE_POPEN''@|$(HAVE_POPEN)|g' \ + -e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \ + -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \ + -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \ + -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \ + -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \ + -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \ + -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ + -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \ + -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ + -e 's|@''REPLACE_FPURGE''@|$(REPLACE_FPURGE)|g' \ + -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \ + -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \ + -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \ + -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ + -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ + -e 's|@''REPLACE_GETDELIM''@|$(REPLACE_GETDELIM)|g' \ + -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ + -e 's|@''REPLACE_OBSTACK_PRINTF''@|$(REPLACE_OBSTACK_PRINTF)|g' \ + -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \ + -e 's|@''REPLACE_POPEN''@|$(REPLACE_POPEN)|g' \ + -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ + -e 's|@''REPLACE_REMOVE''@|$(REPLACE_REMOVE)|g' \ + -e 's|@''REPLACE_RENAME''@|$(REPLACE_RENAME)|g' \ + -e 's|@''REPLACE_RENAMEAT''@|$(REPLACE_RENAMEAT)|g' \ + -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \ + -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \ + -e 's|@''REPLACE_STDIO_READ_FUNCS''@|$(REPLACE_STDIO_READ_FUNCS)|g' \ + -e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \ + -e 's|@''REPLACE_TMPFILE''@|$(REPLACE_TMPFILE)|g' \ + -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \ + -e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \ + -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ + -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \ + -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \ + -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ + -e 's|@''ASM_SYMBOL_PREFIX''@|$(ASM_SYMBOL_PREFIX)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += stdio.h stdio.h-t + +EXTRA_DIST += stdio.in.h + +## end gnulib module stdio + +## begin gnulib module stdlib + +BUILT_SOURCES += stdlib.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ + $(_NORETURN_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ + -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \ + -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \ + -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \ + -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \ + -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ + -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ + -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ + -e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \ + -e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \ + -e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \ + -e 's/@''GNULIB_MKOSTEMP''@/$(GNULIB_MKOSTEMP)/g' \ + -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \ + -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \ + -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ + -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ + -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ + -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ + -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \ + -e 's/@''GNULIB_RANDOM''@/$(GNULIB_RANDOM)/g' \ + -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \ + -e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \ + -e 's/@''GNULIB_REALPATH''@/$(GNULIB_REALPATH)/g' \ + -e 's/@''GNULIB_RPMATCH''@/$(GNULIB_RPMATCH)/g' \ + -e 's/@''GNULIB_SECURE_GETENV''@/$(GNULIB_SECURE_GETENV)/g' \ + -e 's/@''GNULIB_SETENV''@/$(GNULIB_SETENV)/g' \ + -e 's/@''GNULIB_STRTOD''@/$(GNULIB_STRTOD)/g' \ + -e 's/@''GNULIB_STRTOLL''@/$(GNULIB_STRTOLL)/g' \ + -e 's/@''GNULIB_STRTOULL''@/$(GNULIB_STRTOULL)/g' \ + -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GNULIB_SYSTEM_POSIX)/g' \ + -e 's/@''GNULIB_UNLOCKPT''@/$(GNULIB_UNLOCKPT)/g' \ + -e 's/@''GNULIB_UNSETENV''@/$(GNULIB_UNSETENV)/g' \ + -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \ + < $(srcdir)/stdlib.in.h | \ + sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ + -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ + -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ + -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ + -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ + -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ + -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ + -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ + -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ + -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ + -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ + -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ + -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ + -e 's|@''HAVE_RANDOM''@|$(HAVE_RANDOM)|g' \ + -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ + -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ + -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ + -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ + -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \ + -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \ + -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ + -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \ + -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ + -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ + -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ + -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ + -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \ + -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ + -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ + -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ + -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ + -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \ + -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ + -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \ + -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ + -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ + -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ + -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ + -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ + -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _Noreturn/r $(_NORETURN_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += stdlib.h stdlib.h-t + +EXTRA_DIST += stdlib.in.h + +## end gnulib module stdlib + +## begin gnulib module strcase + + +EXTRA_DIST += strcasecmp.c strncasecmp.c + +EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c + +## end gnulib module strcase + +## begin gnulib module strchrnul + + +EXTRA_DIST += strchrnul.c strchrnul.valgrind + +EXTRA_libgnu_a_SOURCES += strchrnul.c + +## end gnulib module strchrnul + +## begin gnulib module streq + + +EXTRA_DIST += streq.h + +## end gnulib module streq + +## begin gnulib module strerror + + +EXTRA_DIST += strerror.c + +EXTRA_libgnu_a_SOURCES += strerror.c + +## end gnulib module strerror + +## begin gnulib module strerror-override + + +EXTRA_DIST += strerror-override.c strerror-override.h + +EXTRA_libgnu_a_SOURCES += strerror-override.c + +## end gnulib module strerror-override + +## begin gnulib module string + +BUILT_SOURCES += string.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \ + -e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \ + -e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \ + -e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \ + -e 's/@''GNULIB_MBSNLEN''@/$(GNULIB_MBSNLEN)/g' \ + -e 's/@''GNULIB_MBSCHR''@/$(GNULIB_MBSCHR)/g' \ + -e 's/@''GNULIB_MBSRCHR''@/$(GNULIB_MBSRCHR)/g' \ + -e 's/@''GNULIB_MBSSTR''@/$(GNULIB_MBSSTR)/g' \ + -e 's/@''GNULIB_MBSCASECMP''@/$(GNULIB_MBSCASECMP)/g' \ + -e 's/@''GNULIB_MBSNCASECMP''@/$(GNULIB_MBSNCASECMP)/g' \ + -e 's/@''GNULIB_MBSPCASECMP''@/$(GNULIB_MBSPCASECMP)/g' \ + -e 's/@''GNULIB_MBSCASESTR''@/$(GNULIB_MBSCASESTR)/g' \ + -e 's/@''GNULIB_MBSCSPN''@/$(GNULIB_MBSCSPN)/g' \ + -e 's/@''GNULIB_MBSPBRK''@/$(GNULIB_MBSPBRK)/g' \ + -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \ + -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \ + -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \ + -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \ + -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \ + -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \ + -e 's/@''GNULIB_MEMRCHR''@/$(GNULIB_MEMRCHR)/g' \ + -e 's/@''GNULIB_RAWMEMCHR''@/$(GNULIB_RAWMEMCHR)/g' \ + -e 's/@''GNULIB_STPCPY''@/$(GNULIB_STPCPY)/g' \ + -e 's/@''GNULIB_STPNCPY''@/$(GNULIB_STPNCPY)/g' \ + -e 's/@''GNULIB_STRCHRNUL''@/$(GNULIB_STRCHRNUL)/g' \ + -e 's/@''GNULIB_STRDUP''@/$(GNULIB_STRDUP)/g' \ + -e 's/@''GNULIB_STRNCAT''@/$(GNULIB_STRNCAT)/g' \ + -e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \ + -e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \ + -e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \ + -e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \ + -e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \ + -e 's/@''GNULIB_STRCASESTR''@/$(GNULIB_STRCASESTR)/g' \ + -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \ + -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ + -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ + -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ + -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ + < $(srcdir)/string.in.h | \ + sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \ + -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \ + -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ + -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \ + -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ + -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ + -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ + -e 's|@''HAVE_RAWMEMCHR''@|$(HAVE_RAWMEMCHR)|g' \ + -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \ + -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ + -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ + -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ + -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ + -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ + -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ + -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ + -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ + -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ + -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ + -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ + -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ + -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ + -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ + -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ + -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ + -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \ + -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ + -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ + -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ + -e 's|@''REPLACE_STRERROR_R''@|$(REPLACE_STRERROR_R)|g' \ + -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ + -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ + -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ + -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ + -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ + -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + < $(srcdir)/string.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += string.h string.h-t + +EXTRA_DIST += string.in.h + +## end gnulib module string + +## begin gnulib module strings + +BUILT_SOURCES += strings.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \ + -e 's|@''GNULIB_FFS''@|$(GNULIB_FFS)|g' \ + -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \ + -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ + -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/strings.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += strings.h strings.h-t + +EXTRA_DIST += strings.in.h + +## end gnulib module strings + +## begin gnulib module strndup + + +EXTRA_DIST += strndup.c + +EXTRA_libgnu_a_SOURCES += strndup.c + +## end gnulib module strndup + +## begin gnulib module strnlen + + +EXTRA_DIST += strnlen.c + +EXTRA_libgnu_a_SOURCES += strnlen.c + +## end gnulib module strnlen + +## begin gnulib module strnlen1 + +libgnu_a_SOURCES += strnlen1.h strnlen1.c + +## end gnulib module strnlen1 + +## begin gnulib module sys_types + +BUILT_SOURCES += sys/types.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +sys/types.h: sys_types.in.h $(top_builddir)/config.status + $(AM_V_at)$(MKDIR_P) sys + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \ + -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ + < $(srcdir)/sys_types.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sys/types.h sys/types.h-t + +EXTRA_DIST += sys_types.in.h + +## end gnulib module sys_types + +## begin gnulib module sysexits + +BUILT_SOURCES += $(SYSEXITS_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_SYSEXITS_H +sysexits.h: sysexits.in.h $(top_builddir)/config.status + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_SYSEXITS_H''@|$(HAVE_SYSEXITS_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SYSEXITS_H''@|$(NEXT_SYSEXITS_H)|g' \ + < $(srcdir)/sysexits.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +else +sysexits.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += sysexits.h sysexits.h-t + +EXTRA_DIST += sysexits.in.h + +## end gnulib module sysexits + +## begin gnulib module unistd + +BUILT_SOURCES += unistd.h +libgnu_a_SOURCES += unistd.c + +# We need the following in order to create an empty placeholder for +# when the system doesn't have one. +unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ + -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ + -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \ + -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \ + -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ + -e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \ + -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \ + -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \ + -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \ + -e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \ + -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \ + -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \ + -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \ + -e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \ + -e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \ + -e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \ + -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \ + -e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \ + -e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \ + -e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \ + -e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \ + -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \ + -e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \ + -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \ + -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \ + -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \ + -e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \ + -e 's/@''GNULIB_LCHOWN''@/$(GNULIB_LCHOWN)/g' \ + -e 's/@''GNULIB_LINK''@/$(GNULIB_LINK)/g' \ + -e 's/@''GNULIB_LINKAT''@/$(GNULIB_LINKAT)/g' \ + -e 's/@''GNULIB_LSEEK''@/$(GNULIB_LSEEK)/g' \ + -e 's/@''GNULIB_PIPE''@/$(GNULIB_PIPE)/g' \ + -e 's/@''GNULIB_PIPE2''@/$(GNULIB_PIPE2)/g' \ + -e 's/@''GNULIB_PREAD''@/$(GNULIB_PREAD)/g' \ + -e 's/@''GNULIB_PWRITE''@/$(GNULIB_PWRITE)/g' \ + -e 's/@''GNULIB_READ''@/$(GNULIB_READ)/g' \ + -e 's/@''GNULIB_READLINK''@/$(GNULIB_READLINK)/g' \ + -e 's/@''GNULIB_READLINKAT''@/$(GNULIB_READLINKAT)/g' \ + -e 's/@''GNULIB_RMDIR''@/$(GNULIB_RMDIR)/g' \ + -e 's/@''GNULIB_SETHOSTNAME''@/$(GNULIB_SETHOSTNAME)/g' \ + -e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \ + -e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \ + -e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/g' \ + -e 's/@''GNULIB_TTYNAME_R''@/$(GNULIB_TTYNAME_R)/g' \ + -e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GNULIB_GL_UNISTD_H_GETOPT)/g' \ + -e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GNULIB_UNISTD_H_NONBLOCKING)/g' \ + -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GNULIB_UNISTD_H_SIGPIPE)/g' \ + -e 's/@''GNULIB_UNLINK''@/$(GNULIB_UNLINK)/g' \ + -e 's/@''GNULIB_UNLINKAT''@/$(GNULIB_UNLINKAT)/g' \ + -e 's/@''GNULIB_USLEEP''@/$(GNULIB_USLEEP)/g' \ + -e 's/@''GNULIB_WRITE''@/$(GNULIB_WRITE)/g' \ + < $(srcdir)/unistd.in.h | \ + sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \ + -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ + -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ + -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ + -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ + -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ + -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ + -e 's|@''HAVE_FDATASYNC''@|$(HAVE_FDATASYNC)|g' \ + -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ + -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ + -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ + -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ + -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ + -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \ + -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ + -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \ + -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ + -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ + -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ + -e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \ + -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ + -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \ + -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \ + -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ + -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \ + -e 's|@''HAVE_SETHOSTNAME''@|$(HAVE_SETHOSTNAME)|g' \ + -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ + -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \ + -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \ + -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ + -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ + -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ + -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \ + -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \ + -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \ + -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ + -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \ + -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \ + -e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \ + -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \ + -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ + -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ + | \ + sed -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ + -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ + -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ + -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ + -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ + -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ + -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ + -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ + -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ + -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ + -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ + -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \ + -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ + -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ + -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \ + -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ + -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \ + -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \ + -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \ + -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ + -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ + -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ + -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ + -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ + -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ + -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ + -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ + -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ + -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ + -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += unistd.h unistd.h-t + +EXTRA_DIST += unistd.in.h + +## end gnulib module unistd + +## begin gnulib module unitypes + +BUILT_SOURCES += $(LIBUNISTRING_UNITYPES_H) + +unitypes.h: unitypes.in.h + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/unitypes.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +MOSTLYCLEANFILES += unitypes.h unitypes.h-t + +EXTRA_DIST += unitypes.in.h + +## end gnulib module unitypes + +## begin gnulib module uniwidth/base + +BUILT_SOURCES += $(LIBUNISTRING_UNIWIDTH_H) + +uniwidth.h: uniwidth.in.h + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/uniwidth.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +MOSTLYCLEANFILES += uniwidth.h uniwidth.h-t + +EXTRA_DIST += localcharset.h uniwidth.in.h + +## end gnulib module uniwidth/base + +## begin gnulib module uniwidth/width + +if LIBUNISTRING_COMPILE_UNIWIDTH_WIDTH +libgnu_a_SOURCES += uniwidth/width.c +endif + +EXTRA_DIST += uniwidth/cjk.h + +## end gnulib module uniwidth/width + +## begin gnulib module vasnprintf + + +EXTRA_DIST += asnprintf.c float+.h printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h + +EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c + +## end gnulib module vasnprintf + +## begin gnulib module verify + + +EXTRA_DIST += verify.h + +## end gnulib module verify + +## begin gnulib module vsnprintf + + +EXTRA_DIST += vsnprintf.c + +EXTRA_libgnu_a_SOURCES += vsnprintf.c + +## end gnulib module vsnprintf + +## begin gnulib module wchar + +BUILT_SOURCES += wchar.h + +# We need the following in order to create when the system +# version does not work standalone. +wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ + -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \ + -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \ + -e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \ + -e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \ + -e 's/@''GNULIB_MBSINIT''@/$(GNULIB_MBSINIT)/g' \ + -e 's/@''GNULIB_MBRTOWC''@/$(GNULIB_MBRTOWC)/g' \ + -e 's/@''GNULIB_MBRLEN''@/$(GNULIB_MBRLEN)/g' \ + -e 's/@''GNULIB_MBSRTOWCS''@/$(GNULIB_MBSRTOWCS)/g' \ + -e 's/@''GNULIB_MBSNRTOWCS''@/$(GNULIB_MBSNRTOWCS)/g' \ + -e 's/@''GNULIB_WCRTOMB''@/$(GNULIB_WCRTOMB)/g' \ + -e 's/@''GNULIB_WCSRTOMBS''@/$(GNULIB_WCSRTOMBS)/g' \ + -e 's/@''GNULIB_WCSNRTOMBS''@/$(GNULIB_WCSNRTOMBS)/g' \ + -e 's/@''GNULIB_WCWIDTH''@/$(GNULIB_WCWIDTH)/g' \ + -e 's/@''GNULIB_WMEMCHR''@/$(GNULIB_WMEMCHR)/g' \ + -e 's/@''GNULIB_WMEMCMP''@/$(GNULIB_WMEMCMP)/g' \ + -e 's/@''GNULIB_WMEMCPY''@/$(GNULIB_WMEMCPY)/g' \ + -e 's/@''GNULIB_WMEMMOVE''@/$(GNULIB_WMEMMOVE)/g' \ + -e 's/@''GNULIB_WMEMSET''@/$(GNULIB_WMEMSET)/g' \ + -e 's/@''GNULIB_WCSLEN''@/$(GNULIB_WCSLEN)/g' \ + -e 's/@''GNULIB_WCSNLEN''@/$(GNULIB_WCSNLEN)/g' \ + -e 's/@''GNULIB_WCSCPY''@/$(GNULIB_WCSCPY)/g' \ + -e 's/@''GNULIB_WCPCPY''@/$(GNULIB_WCPCPY)/g' \ + -e 's/@''GNULIB_WCSNCPY''@/$(GNULIB_WCSNCPY)/g' \ + -e 's/@''GNULIB_WCPNCPY''@/$(GNULIB_WCPNCPY)/g' \ + -e 's/@''GNULIB_WCSCAT''@/$(GNULIB_WCSCAT)/g' \ + -e 's/@''GNULIB_WCSNCAT''@/$(GNULIB_WCSNCAT)/g' \ + -e 's/@''GNULIB_WCSCMP''@/$(GNULIB_WCSCMP)/g' \ + -e 's/@''GNULIB_WCSNCMP''@/$(GNULIB_WCSNCMP)/g' \ + -e 's/@''GNULIB_WCSCASECMP''@/$(GNULIB_WCSCASECMP)/g' \ + -e 's/@''GNULIB_WCSNCASECMP''@/$(GNULIB_WCSNCASECMP)/g' \ + -e 's/@''GNULIB_WCSCOLL''@/$(GNULIB_WCSCOLL)/g' \ + -e 's/@''GNULIB_WCSXFRM''@/$(GNULIB_WCSXFRM)/g' \ + -e 's/@''GNULIB_WCSDUP''@/$(GNULIB_WCSDUP)/g' \ + -e 's/@''GNULIB_WCSCHR''@/$(GNULIB_WCSCHR)/g' \ + -e 's/@''GNULIB_WCSRCHR''@/$(GNULIB_WCSRCHR)/g' \ + -e 's/@''GNULIB_WCSCSPN''@/$(GNULIB_WCSCSPN)/g' \ + -e 's/@''GNULIB_WCSSPN''@/$(GNULIB_WCSSPN)/g' \ + -e 's/@''GNULIB_WCSPBRK''@/$(GNULIB_WCSPBRK)/g' \ + -e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \ + -e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \ + -e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \ + < $(srcdir)/wchar.in.h | \ + sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ + -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ + -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ + -e 's|@''HAVE_MBRTOWC''@|$(HAVE_MBRTOWC)|g' \ + -e 's|@''HAVE_MBRLEN''@|$(HAVE_MBRLEN)|g' \ + -e 's|@''HAVE_MBSRTOWCS''@|$(HAVE_MBSRTOWCS)|g' \ + -e 's|@''HAVE_MBSNRTOWCS''@|$(HAVE_MBSNRTOWCS)|g' \ + -e 's|@''HAVE_WCRTOMB''@|$(HAVE_WCRTOMB)|g' \ + -e 's|@''HAVE_WCSRTOMBS''@|$(HAVE_WCSRTOMBS)|g' \ + -e 's|@''HAVE_WCSNRTOMBS''@|$(HAVE_WCSNRTOMBS)|g' \ + -e 's|@''HAVE_WMEMCHR''@|$(HAVE_WMEMCHR)|g' \ + -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \ + -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \ + -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \ + -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \ + -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \ + -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \ + -e 's|@''HAVE_WCSCPY''@|$(HAVE_WCSCPY)|g' \ + -e 's|@''HAVE_WCPCPY''@|$(HAVE_WCPCPY)|g' \ + -e 's|@''HAVE_WCSNCPY''@|$(HAVE_WCSNCPY)|g' \ + -e 's|@''HAVE_WCPNCPY''@|$(HAVE_WCPNCPY)|g' \ + -e 's|@''HAVE_WCSCAT''@|$(HAVE_WCSCAT)|g' \ + -e 's|@''HAVE_WCSNCAT''@|$(HAVE_WCSNCAT)|g' \ + -e 's|@''HAVE_WCSCMP''@|$(HAVE_WCSCMP)|g' \ + -e 's|@''HAVE_WCSNCMP''@|$(HAVE_WCSNCMP)|g' \ + -e 's|@''HAVE_WCSCASECMP''@|$(HAVE_WCSCASECMP)|g' \ + -e 's|@''HAVE_WCSNCASECMP''@|$(HAVE_WCSNCASECMP)|g' \ + -e 's|@''HAVE_WCSCOLL''@|$(HAVE_WCSCOLL)|g' \ + -e 's|@''HAVE_WCSXFRM''@|$(HAVE_WCSXFRM)|g' \ + -e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|g' \ + -e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|g' \ + -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|g' \ + -e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|g' \ + -e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|g' \ + -e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|g' \ + -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \ + -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \ + -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \ + -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ + -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ + | \ + sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ + -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \ + -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \ + -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \ + -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \ + -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \ + -e 's|@''REPLACE_MBSRTOWCS''@|$(REPLACE_MBSRTOWCS)|g' \ + -e 's|@''REPLACE_MBSNRTOWCS''@|$(REPLACE_MBSNRTOWCS)|g' \ + -e 's|@''REPLACE_WCRTOMB''@|$(REPLACE_WCRTOMB)|g' \ + -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \ + -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ + -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ + -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += wchar.h wchar.h-t + +EXTRA_DIST += wchar.in.h + +## end gnulib module wchar + +## begin gnulib module wcrtomb + + +EXTRA_DIST += wcrtomb.c + +EXTRA_libgnu_a_SOURCES += wcrtomb.c + +## end gnulib module wcrtomb + +## begin gnulib module wctype-h + +BUILT_SOURCES += wctype.h +libgnu_a_SOURCES += wctype-h.c + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ + -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ + -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ + -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \ + -e 's/@''GNULIB_WCTRANS''@/$(GNULIB_WCTRANS)/g' \ + -e 's/@''GNULIB_TOWCTRANS''@/$(GNULIB_TOWCTRANS)/g' \ + -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ + -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ + -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \ + -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \ + -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ + -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \ + -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ + -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/wctype.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += wctype.h wctype.h-t + +EXTRA_DIST += wctype.in.h + +## end gnulib module wctype-h + +## begin gnulib module wcwidth + + +EXTRA_DIST += wcwidth.c + +EXTRA_libgnu_a_SOURCES += wcwidth.c + +## end gnulib module wcwidth + +## begin gnulib module xsize + +libgnu_a_SOURCES += xsize.h xsize.c + +## end gnulib module xsize + + +mostlyclean-local: mostlyclean-generic + @for dir in '' $(MOSTLYCLEANDIRS); do \ + if test -n "$$dir" && test -d $$dir; then \ + echo "rmdir $$dir"; rmdir $$dir; \ + fi; \ + done; \ + : diff --git a/grub-core/gnulib/alloca.c b/grub-core/gnulib/alloca.c new file mode 100644 index 000000000..ee0f01886 --- /dev/null +++ b/grub-core/gnulib/alloca.c @@ -0,0 +1,478 @@ +/* alloca.c -- allocate automatically reclaimed memory + (Mostly) portable public-domain implementation -- D A Gwyn + + This implementation of the PWB library alloca function, + which is used to allocate space off the run-time stack so + that it is automatically reclaimed upon procedure exit, + was inspired by discussions with J. Q. Johnson of Cornell. + J.Otto Tennant contributed the Cray support. + + There are some preprocessor constants that can + be defined when compiling for your specific system, for + improved efficiency; however, the defaults should be okay. + + The general concept of this implementation is to keep + track of all alloca-allocated blocks, and reclaim any + that are found to be deeper in the stack than the current + invocation. This heuristic does not reclaim storage as + soon as it becomes invalid, but it will do so eventually. + + As a special case, alloca(0) reclaims storage without + allocating any. It is a good idea to use alloca(0) in + your main control loop, etc. to force garbage collection. */ + +#include + +#include + +#include +#include + +#ifdef emacs +# include "lisp.h" +# include "blockinput.h" +# ifdef EMACS_FREE +# undef free +# define free EMACS_FREE +# endif +#else +# define memory_full() abort () +#endif + +/* If compiling with GCC 2, this file's not needed. */ +#if !defined (__GNUC__) || __GNUC__ < 2 + +/* If someone has defined alloca as a macro, + there must be some other way alloca is supposed to work. */ +# ifndef alloca + +# ifdef emacs +# ifdef static +/* actually, only want this if static is defined as "" + -- this is for usg, in which emacs must undefine static + in order to make unexec workable + */ +# ifndef STACK_DIRECTION +you +lose +-- must know STACK_DIRECTION at compile-time +/* Using #error here is not wise since this file should work for + old and obscure compilers. */ +# endif /* STACK_DIRECTION undefined */ +# endif /* static */ +# endif /* emacs */ + +/* If your stack is a linked list of frames, you have to + provide an "address metric" ADDRESS_FUNCTION macro. */ + +# if defined (CRAY) && defined (CRAY_STACKSEG_END) +long i00afunc (); +# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) +# else +# define ADDRESS_FUNCTION(arg) &(arg) +# endif + +/* Define STACK_DIRECTION if you know the direction of stack + growth for your system; otherwise it will be automatically + deduced at run-time. + + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ + +# ifndef STACK_DIRECTION +# define STACK_DIRECTION 0 /* Direction unknown. */ +# endif + +# if STACK_DIRECTION != 0 + +# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ + +# else /* STACK_DIRECTION == 0; need run-time code. */ + +static int stack_dir; /* 1 or -1 once known. */ +# define STACK_DIR stack_dir + +static int +find_stack_direction (int *addr, int depth) +{ + int dir, dummy = 0; + if (! addr) + addr = &dummy; + *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; + dir = depth ? find_stack_direction (addr, depth - 1) : 0; + return dir + dummy; +} + +# endif /* STACK_DIRECTION == 0 */ + +/* An "alloca header" is used to: + (a) chain together all alloca'ed blocks; + (b) keep track of stack depth. + + It is very important that sizeof(header) agree with malloc + alignment chunk size. The following default should work okay. */ + +# ifndef ALIGN_SIZE +# define ALIGN_SIZE sizeof(double) +# endif + +typedef union hdr +{ + char align[ALIGN_SIZE]; /* To force sizeof(header). */ + struct + { + union hdr *next; /* For chaining headers. */ + char *deep; /* For stack depth measure. */ + } h; +} header; + +static header *last_alloca_header = NULL; /* -> last alloca header. */ + +/* Return a pointer to at least SIZE bytes of storage, + which will be automatically reclaimed upon exit from + the procedure that called alloca. Originally, this space + was supposed to be taken from the current stack frame of the + caller, but that method cannot be made to work for some + implementations of C, for example under Gould's UTX/32. */ + +void * +alloca (size_t size) +{ + auto char probe; /* Probes stack depth: */ + register char *depth = ADDRESS_FUNCTION (probe); + +# if STACK_DIRECTION == 0 + if (STACK_DIR == 0) /* Unknown growth direction. */ + STACK_DIR = find_stack_direction (NULL, (size & 1) + 20); +# endif + + /* Reclaim garbage, defined as all alloca'd storage that + was allocated from deeper in the stack than currently. */ + + { + register header *hp; /* Traverses linked list. */ + +# ifdef emacs + BLOCK_INPUT; +# endif + + for (hp = last_alloca_header; hp != NULL;) + if ((STACK_DIR > 0 && hp->h.deep > depth) + || (STACK_DIR < 0 && hp->h.deep < depth)) + { + register header *np = hp->h.next; + + free (hp); /* Collect garbage. */ + + hp = np; /* -> next header. */ + } + else + break; /* Rest are not deeper. */ + + last_alloca_header = hp; /* -> last valid storage. */ + +# ifdef emacs + UNBLOCK_INPUT; +# endif + } + + if (size == 0) + return NULL; /* No allocation required. */ + + /* Allocate combined header + user data storage. */ + + { + /* Address of header. */ + register header *new; + + size_t combined_size = sizeof (header) + size; + if (combined_size < sizeof (header)) + memory_full (); + + new = malloc (combined_size); + + if (! new) + memory_full (); + + new->h.next = last_alloca_header; + new->h.deep = depth; + + last_alloca_header = new; + + /* User storage begins just after header. */ + + return (void *) (new + 1); + } +} + +# if defined (CRAY) && defined (CRAY_STACKSEG_END) + +# ifdef DEBUG_I00AFUNC +# include +# endif + +# ifndef CRAY_STACK +# define CRAY_STACK +# ifndef CRAY2 +/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ +struct stack_control_header + { + long shgrow:32; /* Number of times stack has grown. */ + long shaseg:32; /* Size of increments to stack. */ + long shhwm:32; /* High water mark of stack. */ + long shsize:32; /* Current size of stack (all segments). */ + }; + +/* The stack segment linkage control information occurs at + the high-address end of a stack segment. (The stack + grows from low addresses to high addresses.) The initial + part of the stack segment linkage control information is + 0200 (octal) words. This provides for register storage + for the routine which overflows the stack. */ + +struct stack_segment_linkage + { + long ss[0200]; /* 0200 overflow words. */ + long sssize:32; /* Number of words in this segment. */ + long ssbase:32; /* Offset to stack base. */ + long:32; + long sspseg:32; /* Offset to linkage control of previous + segment of stack. */ + long:32; + long sstcpt:32; /* Pointer to task common address block. */ + long sscsnm; /* Private control structure number for + microtasking. */ + long ssusr1; /* Reserved for user. */ + long ssusr2; /* Reserved for user. */ + long sstpid; /* Process ID for pid based multi-tasking. */ + long ssgvup; /* Pointer to multitasking thread giveup. */ + long sscray[7]; /* Reserved for Cray Research. */ + long ssa0; + long ssa1; + long ssa2; + long ssa3; + long ssa4; + long ssa5; + long ssa6; + long ssa7; + long sss0; + long sss1; + long sss2; + long sss3; + long sss4; + long sss5; + long sss6; + long sss7; + }; + +# else /* CRAY2 */ +/* The following structure defines the vector of words + returned by the STKSTAT library routine. */ +struct stk_stat + { + long now; /* Current total stack size. */ + long maxc; /* Amount of contiguous space which would + be required to satisfy the maximum + stack demand to date. */ + long high_water; /* Stack high-water mark. */ + long overflows; /* Number of stack overflow ($STKOFEN) calls. */ + long hits; /* Number of internal buffer hits. */ + long extends; /* Number of block extensions. */ + long stko_mallocs; /* Block allocations by $STKOFEN. */ + long underflows; /* Number of stack underflow calls ($STKRETN). */ + long stko_free; /* Number of deallocations by $STKRETN. */ + long stkm_free; /* Number of deallocations by $STKMRET. */ + long segments; /* Current number of stack segments. */ + long maxs; /* Maximum number of stack segments so far. */ + long pad_size; /* Stack pad size. */ + long current_address; /* Current stack segment address. */ + long current_size; /* Current stack segment size. This + number is actually corrupted by STKSTAT to + include the fifteen word trailer area. */ + long initial_address; /* Address of initial segment. */ + long initial_size; /* Size of initial segment. */ + }; + +/* The following structure describes the data structure which trails + any stack segment. I think that the description in 'asdef' is + out of date. I only describe the parts that I am sure about. */ + +struct stk_trailer + { + long this_address; /* Address of this block. */ + long this_size; /* Size of this block (does not include + this trailer). */ + long unknown2; + long unknown3; + long link; /* Address of trailer block of previous + segment. */ + long unknown5; + long unknown6; + long unknown7; + long unknown8; + long unknown9; + long unknown10; + long unknown11; + long unknown12; + long unknown13; + long unknown14; + }; + +# endif /* CRAY2 */ +# endif /* not CRAY_STACK */ + +# ifdef CRAY2 +/* Determine a "stack measure" for an arbitrary ADDRESS. + I doubt that "lint" will like this much. */ + +static long +i00afunc (long *address) +{ + struct stk_stat status; + struct stk_trailer *trailer; + long *block, size; + long result = 0; + + /* We want to iterate through all of the segments. The first + step is to get the stack status structure. We could do this + more quickly and more directly, perhaps, by referencing the + $LM00 common block, but I know that this works. */ + + STKSTAT (&status); + + /* Set up the iteration. */ + + trailer = (struct stk_trailer *) (status.current_address + + status.current_size + - 15); + + /* There must be at least one stack segment. Therefore it is + a fatal error if "trailer" is null. */ + + if (trailer == 0) + abort (); + + /* Discard segments that do not contain our argument address. */ + + while (trailer != 0) + { + block = (long *) trailer->this_address; + size = trailer->this_size; + if (block == 0 || size == 0) + abort (); + trailer = (struct stk_trailer *) trailer->link; + if ((block <= address) && (address < (block + size))) + break; + } + + /* Set the result to the offset in this segment and add the sizes + of all predecessor segments. */ + + result = address - block; + + if (trailer == 0) + { + return result; + } + + do + { + if (trailer->this_size <= 0) + abort (); + result += trailer->this_size; + trailer = (struct stk_trailer *) trailer->link; + } + while (trailer != 0); + + /* We are done. Note that if you present a bogus address (one + not in any segment), you will get a different number back, formed + from subtracting the address of the first block. This is probably + not what you want. */ + + return (result); +} + +# else /* not CRAY2 */ +/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. + Determine the number of the cell within the stack, + given the address of the cell. The purpose of this + routine is to linearize, in some sense, stack addresses + for alloca. */ + +static long +i00afunc (long address) +{ + long stkl = 0; + + long size, pseg, this_segment, stack; + long result = 0; + + struct stack_segment_linkage *ssptr; + + /* Register B67 contains the address of the end of the + current stack segment. If you (as a subprogram) store + your registers on the stack and find that you are past + the contents of B67, you have overflowed the segment. + + B67 also points to the stack segment linkage control + area, which is what we are really interested in. */ + + stkl = CRAY_STACKSEG_END (); + ssptr = (struct stack_segment_linkage *) stkl; + + /* If one subtracts 'size' from the end of the segment, + one has the address of the first word of the segment. + + If this is not the first segment, 'pseg' will be + nonzero. */ + + pseg = ssptr->sspseg; + size = ssptr->sssize; + + this_segment = stkl - size; + + /* It is possible that calling this routine itself caused + a stack overflow. Discard stack segments which do not + contain the target address. */ + + while (!(this_segment <= address && address <= stkl)) + { +# ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); +# endif + if (pseg == 0) + break; + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + this_segment = stkl - size; + } + + result = address - this_segment; + + /* If you subtract pseg from the current end of the stack, + you get the address of the previous stack segment's end. + This seems a little convoluted to me, but I'll bet you save + a cycle somewhere. */ + + while (pseg != 0) + { +# ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o\n", pseg, size); +# endif + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + result += size; + } + return (result); +} + +# endif /* not CRAY2 */ +# endif /* CRAY */ + +# endif /* no alloca */ +#endif /* not GCC 2 */ diff --git a/grub-core/gnulib/alloca.in.h b/grub-core/gnulib/alloca.in.h new file mode 100644 index 000000000..72d28ee30 --- /dev/null +++ b/grub-core/gnulib/alloca.in.h @@ -0,0 +1,63 @@ +/* Memory allocation on the stack. + + Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation, + Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program; if not, see + . + */ + +/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H + means there is a real alloca function. */ +#ifndef _GL_ALLOCA_H +#define _GL_ALLOCA_H + +/* alloca (N) returns a pointer to N bytes of memory + allocated on the stack, which will last until the function returns. + Use of alloca should be avoided: + - inside arguments of function calls - undefined behaviour, + - in inline functions - the allocation may actually last until the + calling function returns, + - for huge N (say, N >= 65536) - you never know how large (or small) + the stack is, and when the stack cannot fulfill the memory allocation + request, the program just crashes. + */ + +#ifndef alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _AIX +# define alloca __alloca +# elif defined _MSC_VER +# include +# define alloca _alloca +# elif defined __DECC && defined __VMS +# define alloca __ALLOCA +# elif defined __TANDEM && defined _TNS_E_TARGET +# ifdef __cplusplus +extern "C" +# endif +void *_alloca (unsigned short); +# pragma intrinsic (_alloca) +# define alloca _alloca +# else +# include +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +# endif +#endif + +#endif /* _GL_ALLOCA_H */ diff --git a/grub-core/gnulib/argp-ba.c b/grub-core/gnulib/argp-ba.c new file mode 100644 index 000000000..5abc9d00a --- /dev/null +++ b/grub-core/gnulib/argp-ba.c @@ -0,0 +1,34 @@ +/* Default definition for ARGP_PROGRAM_BUG_ADDRESS. + Copyright (C) 1996-1997, 1999, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* If set by the user program, it should point to string that is the + bug-reporting address for the program. It will be printed by argp_help if + the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help + messages), embedded in a sentence that says something like "Report bugs to + ADDR." */ +const char *argp_program_bug_address +/* This variable should be zero-initialized. On most systems, putting it into + BSS is sufficient. Not so on Mac OS X 10.3 and 10.4, see + + . */ +#if defined __ELF__ + /* On ELF systems, variables in BSS behave well. */ +#else + = (const char *) 0 +#endif + ; diff --git a/grub-core/gnulib/argp-eexst.c b/grub-core/gnulib/argp-eexst.c new file mode 100644 index 000000000..a8bb77fcf --- /dev/null +++ b/grub-core/gnulib/argp-eexst.c @@ -0,0 +1,30 @@ +/* Default definition for ARGP_ERR_EXIT_STATUS + Copyright (C) 1997, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "argp.h" + +/* The exit status that argp will use when exiting due to a parsing error. + If not defined or set by the user program, this defaults to EX_USAGE from + . */ +error_t argp_err_exit_status = EX_USAGE; diff --git a/grub-core/gnulib/argp-fmtstream.c b/grub-core/gnulib/argp-fmtstream.c new file mode 100644 index 000000000..02406ff2a --- /dev/null +++ b/grub-core/gnulib/argp-fmtstream.c @@ -0,0 +1,488 @@ +/* Word-wrapping and line-truncating streams + Copyright (C) 1997-1999, 2001-2003, 2005, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This package emulates glibc 'line_wrap_stream' semantics for systems that + don't have that. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include + +#include "argp-fmtstream.h" +#include "argp-namefrob.h" +#include "mbswidth.h" + +#ifndef ARGP_FMTSTREAM_USE_LINEWRAP + +#ifndef isblank +#define isblank(ch) ((ch)==' ' || (ch)=='\t') +#endif + +#if defined _LIBC && defined USE_IN_LIBIO +# include +# include +# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a) +#endif + +#define INIT_BUF_SIZE 200 +#define PRINTF_SIZE_GUESS 150 + +/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines + written on it with LMARGIN spaces and limits them to RMARGIN columns + total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by + replacing the whitespace before them with a newline and WMARGIN spaces. + Otherwise, chars beyond RMARGIN are simply dropped until a newline. + Returns NULL if there was an error. */ +argp_fmtstream_t +__argp_make_fmtstream (FILE *stream, + size_t lmargin, size_t rmargin, ssize_t wmargin) +{ + argp_fmtstream_t fs; + + fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream)); + if (fs != NULL) + { + fs->stream = stream; + + fs->lmargin = lmargin; + fs->rmargin = rmargin; + fs->wmargin = wmargin; + fs->point_col = 0; + fs->point_offs = 0; + + fs->buf = (char *) malloc (INIT_BUF_SIZE); + if (! fs->buf) + { + free (fs); + fs = 0; + } + else + { + fs->p = fs->buf; + fs->end = fs->buf + INIT_BUF_SIZE; + } + } + + return fs; +} +#if 0 +/* Not exported. */ +#ifdef weak_alias +weak_alias (__argp_make_fmtstream, argp_make_fmtstream) +#endif +#endif + +/* Flush FS to its stream, and free it (but don't close the stream). */ +void +__argp_fmtstream_free (argp_fmtstream_t fs) +{ + __argp_fmtstream_update (fs); + if (fs->p > fs->buf) + { +#ifdef USE_IN_LIBIO + __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); +#else + fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); +#endif + } + free (fs->buf); + free (fs); +} +#if 0 +/* Not exported. */ +#ifdef weak_alias +weak_alias (__argp_fmtstream_free, argp_fmtstream_free) +#endif +#endif + + +/* Return the pointer to the first character that doesn't fit in l columns. */ +static inline const ptrdiff_t +add_width (const char *ptr, const char *end, size_t l) +{ + mbstate_t ps; + const char *ptr0 = ptr; + + memset (&ps, 0, sizeof (ps)); + + while (ptr < end) + { + wchar_t wc; + size_t s, k; + + s = mbrtowc (&wc, ptr, end - ptr, &ps); + if (s == (size_t) -1) + break; + if (s == (size_t) -2) + { + if (1 >= l) + break; + l--; + ptr++; + continue; + } + + if (wc == '\e' && ptr + 3 < end + && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1') + && ptr[3] == 'm') + { + ptr += 4; + continue; + } + + k = wcwidth (wc); + + if (k >= l) + break; + l -= k; + ptr += s; + } + return ptr - ptr0; +} + +/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the + end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ +void +__argp_fmtstream_update (argp_fmtstream_t fs) +{ + char *buf, *nl; + size_t len; + + /* Scan the buffer for newlines. */ + buf = fs->buf + fs->point_offs; + while (buf < fs->p) + { + size_t r; + + if (fs->point_col == 0 && fs->lmargin != 0) + { + /* We are starting a new line. Print spaces to the left margin. */ + const size_t pad = fs->lmargin; + if (fs->p + pad < fs->end) + { + /* We can fit in them in the buffer by moving the + buffer text up and filling in the beginning. */ + memmove (buf + pad, buf, fs->p - buf); + fs->p += pad; /* Compensate for bigger buffer. */ + memset (buf, ' ', pad); /* Fill in the spaces. */ + buf += pad; /* Don't bother searching them. */ + } + else + { + /* No buffer space for spaces. Must flush. */ + size_t i; + for (i = 0; i < pad; i++) + { +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else +#endif + putc_unlocked (' ', fs->stream); + } + } + fs->point_col = pad; + } + + len = fs->p - buf; + nl = memchr (buf, '\n', len); + + if (fs->point_col < 0) + fs->point_col = 0; + + if (!nl) + { + size_t display_width = mbsnwidth (buf, fs->p - buf, MBSW_STOP_AT_NUL); + /* The buffer ends in a partial line. */ + + if (fs->point_col + display_width < fs->rmargin) + { + /* The remaining buffer text is a partial line and fits + within the maximum line width. Advance point for the + characters to be written and stop scanning. */ + fs->point_col += display_width; + break; + } + else + /* Set the end-of-line pointer for the code below to + the end of the buffer. */ + nl = fs->p; + } + else + { + size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL); + if (display_width < (ssize_t) fs->rmargin) + { + /* The buffer contains a full line that fits within the maximum + line width. Reset point and scan the next line. */ + fs->point_col = 0; + buf = nl + 1; + continue; + } + } + + /* This line is too long. */ + r = fs->rmargin - 1; + + if (fs->wmargin < 0) + { + /* Truncate the line by overwriting the excess with the + newline and anything after it in the buffer. */ + if (nl < fs->p) + { + memmove (buf + (r - fs->point_col), nl, fs->p - nl); + fs->p -= buf + (r - fs->point_col) - nl; + /* Reset point for the next line and start scanning it. */ + fs->point_col = 0; + buf += r + 1; /* Skip full line plus \n. */ + } + else + { + /* The buffer ends with a partial line that is beyond the + maximum line width. Advance point for the characters + written, and discard those past the max from the buffer. */ + fs->point_col += len; + fs->p -= fs->point_col - r; + break; + } + } + else + { + /* Do word wrap. Go to the column just past the maximum line + width and scan back for the beginning of the word there. + Then insert a line break. */ + + char *p, *nextline; + int i; + + p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); + while (p >= buf && !isblank ((unsigned char) *p)) + --p; + nextline = p + 1; /* This will begin the next line. */ + + if (nextline > buf) + { + /* Swallow separating blanks. */ + if (p >= buf) + do + --p; + while (p >= buf && isblank ((unsigned char) *p)); + nl = p + 1; /* The newline will replace the first blank. */ + } + else + { + /* A single word that is greater than the maximum line width. + Oh well. Put it on an overlong line by itself. */ + p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); + /* Find the end of the long word. */ + if (p < nl) + do + ++p; + while (p < nl && !isblank ((unsigned char) *p)); + if (p == nl) + { + /* It already ends a line. No fussing required. */ + fs->point_col = 0; + buf = nl + 1; + continue; + } + /* We will move the newline to replace the first blank. */ + nl = p; + /* Swallow separating blanks. */ + do + ++p; + while (isblank ((unsigned char) *p)); + /* The next line will start here. */ + nextline = p; + } + + /* Note: There are a bunch of tests below for + NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall + at the end of the buffer, and NEXTLINE is in fact empty (and so + we need not be careful to maintain its contents). */ + + if ((nextline == buf + len + 1 + ? fs->end - nl < fs->wmargin + 1 + : nextline - (nl + 1) < fs->wmargin) + && fs->p > nextline) + { + /* The margin needs more blanks than we removed. */ + if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL) + > fs->wmargin + 1) + /* Make some space for them. */ + { + size_t mv = fs->p - nextline; + memmove (nl + 1 + fs->wmargin, nextline, mv); + nextline = nl + 1 + fs->wmargin; + len = nextline + mv - buf; + *nl++ = '\n'; + } + else + /* Output the first line so we can use the space. */ + { +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s\n", + (int) (nl - fs->buf), fs->buf); +#else + if (nl > fs->buf) + fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); + putc_unlocked ('\n', fs->stream); +#endif + + len += buf - fs->buf; + nl = buf = fs->buf; + } + } + else + /* We can fit the newline and blanks in before + the next word. */ + *nl++ = '\n'; + + if (nextline - nl >= fs->wmargin + || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) + /* Add blanks up to the wrap margin column. */ + for (i = 0; i < fs->wmargin; ++i) + *nl++ = ' '; + else + for (i = 0; i < fs->wmargin; ++i) +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else +#endif + putc_unlocked (' ', fs->stream); + + /* Copy the tail of the original buffer into the current buffer + position. */ + if (nl < nextline) + memmove (nl, nextline, buf + len - nextline); + len -= nextline - buf; + + /* Continue the scan on the remaining lines in the buffer. */ + buf = nl; + + /* Restore bufp to include all the remaining text. */ + fs->p = nl + len; + + /* Reset the counter of what has been output this line. If wmargin + is 0, we want to avoid the lmargin getting added, so we set + point_col to a magic value of -1 in that case. */ + fs->point_col = fs->wmargin ? fs->wmargin : -1; + } + } + + /* Remember that we've scanned as far as the end of the buffer. */ + fs->point_offs = fs->p - fs->buf; +} + +/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by + growing the buffer, or by flushing it. True is returned iff we succeed. */ +int +__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) +{ + if ((size_t) (fs->end - fs->p) < amount) + { + ssize_t wrote; + + /* Flush FS's buffer. */ + __argp_fmtstream_update (fs); + +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); + wrote = fs->p - fs->buf; +#else + wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); +#endif + if (wrote == fs->p - fs->buf) + { + fs->p = fs->buf; + fs->point_offs = 0; + } + else + { + fs->p -= wrote; + fs->point_offs -= wrote; + memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); + return 0; + } + + if ((size_t) (fs->end - fs->buf) < amount) + /* Gotta grow the buffer. */ + { + size_t old_size = fs->end - fs->buf; + size_t new_size = old_size + amount; + char *new_buf; + + if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size))) + { + __set_errno (ENOMEM); + return 0; + } + + fs->buf = new_buf; + fs->end = new_buf + new_size; + fs->p = fs->buf; + } + } + + return 1; +} + +ssize_t +__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...) +{ + int out; + size_t avail; + size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */ + + do + { + va_list args; + + if (! __argp_fmtstream_ensure (fs, size_guess)) + return -1; + + va_start (args, fmt); + avail = fs->end - fs->p; + out = __vsnprintf (fs->p, avail, fmt, args); + va_end (args); + if ((size_t) out >= avail) + size_guess = out + 1; + } + while ((size_t) out >= avail); + + fs->p += out; + + return out; +} +#if 0 +/* Not exported. */ +#ifdef weak_alias +weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf) +#endif +#endif + +#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */ diff --git a/grub-core/gnulib/argp-fmtstream.h b/grub-core/gnulib/argp-fmtstream.h new file mode 100644 index 000000000..000090ea6 --- /dev/null +++ b/grub-core/gnulib/argp-fmtstream.h @@ -0,0 +1,359 @@ +/* Word-wrapping and line-truncating streams. + Copyright (C) 1997, 2006-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This package emulates glibc 'line_wrap_stream' semantics for systems that + don't have that. If the system does have it, it is just a wrapper for + that. This header file is only used internally while compiling argp, and + shouldn't be installed. */ + +#ifndef _ARGP_FMTSTREAM_H +#define _ARGP_FMTSTREAM_H + +#include +#include +#include + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \ + || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)) +/* line_wrap_stream is available, so use that. */ +#define ARGP_FMTSTREAM_USE_LINEWRAP +#endif + +#ifdef ARGP_FMTSTREAM_USE_LINEWRAP +/* Just be a simple wrapper for line_wrap_stream; the semantics are + *slightly* different, as line_wrap_stream doesn't actually make a new + object, it just modifies the given stream (reversibly) to do + line-wrapping. Since we control who uses this code, it doesn't matter. */ + +#include + +typedef FILE *argp_fmtstream_t; + +#define argp_make_fmtstream line_wrap_stream +#define __argp_make_fmtstream line_wrap_stream +#define argp_fmtstream_free line_unwrap_stream +#define __argp_fmtstream_free line_unwrap_stream + +#define __argp_fmtstream_putc(fs,ch) putc(ch,fs) +#define argp_fmtstream_putc(fs,ch) putc(ch,fs) +#define __argp_fmtstream_puts(fs,str) fputs(str,fs) +#define argp_fmtstream_puts(fs,str) fputs(str,fs) +#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) +#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) +#define __argp_fmtstream_printf fprintf +#define argp_fmtstream_printf fprintf + +#define __argp_fmtstream_lmargin line_wrap_lmargin +#define argp_fmtstream_lmargin line_wrap_lmargin +#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin +#define argp_fmtstream_set_lmargin line_wrap_set_lmargin +#define __argp_fmtstream_rmargin line_wrap_rmargin +#define argp_fmtstream_rmargin line_wrap_rmargin +#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin +#define argp_fmtstream_set_rmargin line_wrap_set_rmargin +#define __argp_fmtstream_wmargin line_wrap_wmargin +#define argp_fmtstream_wmargin line_wrap_wmargin +#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin +#define argp_fmtstream_set_wmargin line_wrap_set_wmargin +#define __argp_fmtstream_point line_wrap_point +#define argp_fmtstream_point line_wrap_point + +#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ +/* Guess we have to define our own version. */ + +struct argp_fmtstream +{ + FILE *stream; /* The stream we're outputting to. */ + + size_t lmargin, rmargin; /* Left and right margins. */ + ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ + + /* Point in buffer to which we've processed for wrapping, but not output. */ + size_t point_offs; + /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ + ssize_t point_col; + + char *buf; /* Output buffer. */ + char *p; /* Current end of text in BUF. */ + char *end; /* Absolute end of BUF. */ +}; + +typedef struct argp_fmtstream *argp_fmtstream_t; + +/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines + written on it with LMARGIN spaces and limits them to RMARGIN columns + total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by + replacing the whitespace before them with a newline and WMARGIN spaces. + Otherwise, chars beyond RMARGIN are simply dropped until a newline. + Returns NULL if there was an error. */ +extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); +extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); + +/* Flush __FS to its stream, and free it (but don't close the stream). */ +extern void __argp_fmtstream_free (argp_fmtstream_t __fs); +extern void argp_fmtstream_free (argp_fmtstream_t __fs); + +extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, + const char *__fmt, ...) + _GL_ATTRIBUTE_FORMAT ((printf, 2, 3)); +extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, + const char *__fmt, ...) + _GL_ATTRIBUTE_FORMAT ((printf, 2, 3)); + +#if _LIBC +extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); +extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); + +extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); +extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); + +extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, + const char *__str, size_t __len); +extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, + const char *__str, size_t __len); +#endif + +/* Access macros for various bits of state. */ +#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin) +#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin) +#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin) +#define __argp_fmtstream_lmargin argp_fmtstream_lmargin +#define __argp_fmtstream_rmargin argp_fmtstream_rmargin +#define __argp_fmtstream_wmargin argp_fmtstream_wmargin + +#if _LIBC +/* Set __FS's left margin to LMARGIN and return the old value. */ +extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, + size_t __lmargin); +extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, + size_t __lmargin); + +/* Set __FS's right margin to __RMARGIN and return the old value. */ +extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, + size_t __rmargin); +extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, + size_t __rmargin); + +/* Set __FS's wrap margin to __WMARGIN and return the old value. */ +extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, + size_t __wmargin); +extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, + size_t __wmargin); + +/* Return the column number of the current output point in __FS. */ +extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); +extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs); +#endif + +/* Internal routines. */ +extern void _argp_fmtstream_update (argp_fmtstream_t __fs); +extern void __argp_fmtstream_update (argp_fmtstream_t __fs); +extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); +extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); + +#if !_LIBC || defined __OPTIMIZE__ +/* Inline versions of above routines. */ + +#if !_LIBC +#define __argp_fmtstream_putc argp_fmtstream_putc +#define __argp_fmtstream_puts argp_fmtstream_puts +#define __argp_fmtstream_write argp_fmtstream_write +#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin +#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin +#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin +#define __argp_fmtstream_point argp_fmtstream_point +#define __argp_fmtstream_update _argp_fmtstream_update +#define __argp_fmtstream_ensure _argp_fmtstream_ensure +_GL_INLINE_HEADER_BEGIN +#ifndef ARGP_FS_EI +# define ARGP_FS_EI _GL_INLINE +#endif +#endif + +#ifndef ARGP_FS_EI +# ifdef __GNUC__ + /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. It defines a macro + __GNUC_STDC_INLINE__ to indicate this situation or a macro + __GNUC_GNU_INLINE__ to indicate the opposite situation. + + GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline + semantics but warns, unless -fgnu89-inline is used: + warning: C99 inline functions are not supported; using GNU89 + warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute + It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. + + Whereas Apple GCC 4.0.1 build 5479 without -std=c99 or -std=gnu99 + implements the GNU C inline semantics and defines the macro + __GNUC_GNU_INLINE__, but it does not warn and does not support + __attribute__ ((__gnu_inline__)). + + All in all, these are the possible combinations. For every compiler, + we need to choose ARGP_FS_EI so that the corresponding table cell + contains an "ok". + + \ ARGP_FS_EI inline extern extern + \ inline inline + CC \ __attribute__ + ((gnu_inline)) + + gcc 4.3.0 error ok ok + gcc 4.3.0 -std=gnu99 -fgnu89-inline error ok ok + gcc 4.3.0 -std=gnu99 ok error ok + + gcc 4.2.2 error ok ok + gcc 4.2.2 -std=gnu99 -fgnu89-inline error ok ok + gcc 4.2.2 -std=gnu99 error warning ok + + gcc 4.1.2 error ok warning + gcc 4.1.2 -std=gnu99 error ok warning + + Apple gcc 4.0.1 error ok warning + Apple gcc 4.0.1 -std=gnu99 ok error warning + */ +# if defined __GNUC_STDC_INLINE__ +# define ARGP_FS_EI inline +# elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) +# define ARGP_FS_EI extern inline __attribute__ ((__gnu_inline__)) +# else +# define ARGP_FS_EI extern inline +# endif +# else + /* With other compilers, assume the ISO C99 meaning of 'inline', if + the compiler supports 'inline' at all. */ +# define ARGP_FS_EI inline +# endif +#endif + +ARGP_FS_EI size_t +__argp_fmtstream_write (argp_fmtstream_t __fs, + const char *__str, size_t __len) +{ + if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) + { + memcpy (__fs->p, __str, __len); + __fs->p += __len; + return __len; + } + else + return 0; +} + +ARGP_FS_EI int +__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str) +{ + size_t __len = strlen (__str); + if (__len) + { + size_t __wrote = __argp_fmtstream_write (__fs, __str, __len); + return __wrote == __len ? 0 : -1; + } + else + return 0; +} + +ARGP_FS_EI int +__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch) +{ + if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1)) + return *__fs->p++ = __ch; + else + return EOF; +} + +/* Set __FS's left margin to __LMARGIN and return the old value. */ +ARGP_FS_EI size_t +__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin) +{ + size_t __old; + if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) + __argp_fmtstream_update (__fs); + __old = __fs->lmargin; + __fs->lmargin = __lmargin; + return __old; +} + +/* Set __FS's right margin to __RMARGIN and return the old value. */ +ARGP_FS_EI size_t +__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin) +{ + size_t __old; + if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) + __argp_fmtstream_update (__fs); + __old = __fs->rmargin; + __fs->rmargin = __rmargin; + return __old; +} + +/* Set FS's wrap margin to __WMARGIN and return the old value. */ +ARGP_FS_EI size_t +__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin) +{ + size_t __old; + if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) + __argp_fmtstream_update (__fs); + __old = __fs->wmargin; + __fs->wmargin = __wmargin; + return __old; +} + +/* Return the column number of the current output point in __FS. */ +ARGP_FS_EI size_t +__argp_fmtstream_point (argp_fmtstream_t __fs) +{ + if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) + __argp_fmtstream_update (__fs); + return __fs->point_col >= 0 ? __fs->point_col : 0; +} + +#if !_LIBC +#undef __argp_fmtstream_putc +#undef __argp_fmtstream_puts +#undef __argp_fmtstream_write +#undef __argp_fmtstream_set_lmargin +#undef __argp_fmtstream_set_rmargin +#undef __argp_fmtstream_set_wmargin +#undef __argp_fmtstream_point +#undef __argp_fmtstream_update +#undef __argp_fmtstream_ensure +_GL_INLINE_HEADER_END +#endif + +#endif /* !_LIBC || __OPTIMIZE__ */ + +#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */ + +#endif /* argp-fmtstream.h */ diff --git a/grub-core/gnulib/argp-fs-xinl.c b/grub-core/gnulib/argp-fs-xinl.c new file mode 100644 index 000000000..35547d93d --- /dev/null +++ b/grub-core/gnulib/argp-fs-xinl.c @@ -0,0 +1,46 @@ +/* Real definitions for extern inline functions in argp-fmtstream.h + Copyright (C) 1997, 2003-2004, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef _LIBC +# define ARGP_FS_EI +#else +# define ARGP_FS_EI _GL_EXTERN_INLINE +#endif +#undef __OPTIMIZE__ +#define __OPTIMIZE__ 1 +#include "argp-fmtstream.h" + +#if 0 +/* Not exported. */ +/* Add weak aliases. */ +#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias) + +weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc) +weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts) +weak_alias (__argp_fmtstream_write, argp_fmtstream_write) +weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin) +weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin) +weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin) +weak_alias (__argp_fmtstream_point, argp_fmtstream_point) + +#endif +#endif diff --git a/grub-core/gnulib/argp-help.c b/grub-core/gnulib/argp-help.c new file mode 100644 index 000000000..2914f4723 --- /dev/null +++ b/grub-core/gnulib/argp-help.c @@ -0,0 +1,1956 @@ +/* Hierarchical argument parsing help output + Copyright (C) 1995-2005, 2007, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_IN_LIBIO +# include +#endif + +#ifdef _LIBC +# include +# undef dgettext +# define dgettext(domain, msgid) \ + INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) +#else +# include "gettext.h" +#endif + +#include "argp.h" +#include "argp-fmtstream.h" +#include "argp-namefrob.h" +#include "mbswidth.h" + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +/* User-selectable (using an environment variable) formatting parameters. + + These may be specified in an environment variable called 'ARGP_HELP_FMT', + with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2 + Where VALn must be a positive integer. The list of variables is in the + UPARAM_NAMES vector, below. */ + +/* Default parameters. */ +#define DUP_ARGS 0 /* True if option argument can be duplicated. */ +#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ +#define SHORT_OPT_COL 2 /* column in which short options start */ +#define LONG_OPT_COL 6 /* column in which long options start */ +#define DOC_OPT_COL 2 /* column in which doc options start */ +#define OPT_DOC_COL 29 /* column in which option text starts */ +#define HEADER_COL 1 /* column in which group headers are printed */ +#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ +#define RMARGIN 79 /* right margin used for wrapping */ + +/* User-selectable (using an environment variable) formatting parameters. + They must all be of type 'int' for the parsing code to work. */ +struct uparams +{ + /* If true, arguments for an option are shown with both short and long + options, even when a given option has both, e.g. '-x ARG, --longx=ARG'. + If false, then if an option has both, the argument is only shown with + the long one, e.g., '-x, --longx=ARG', and a message indicating that + this really means both is printed below the options. */ + int dup_args; + + /* This is true if when DUP_ARGS is false, and some duplicate arguments have + been suppressed, an explanatory message should be printed. */ + int dup_args_note; + + /* Various output columns. */ + int short_opt_col; /* column in which short options start */ + int long_opt_col; /* column in which long options start */ + int doc_opt_col; /* column in which doc options start */ + int opt_doc_col; /* column in which option text starts */ + int header_col; /* column in which group headers are printed */ + int usage_indent; /* indentation of wrapped usage lines */ + int rmargin; /* right margin used for wrapping */ + + int valid; /* True when the values in here are valid. */ +}; + +/* This is a global variable, as user options are only ever read once. */ +static struct uparams uparams = { + DUP_ARGS, DUP_ARGS_NOTE, + SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL, + USAGE_INDENT, RMARGIN, + 0 +}; + +/* A particular uparam, and what the user name is. */ +struct uparam_name +{ + const char *name; /* User name. */ + int is_bool; /* Whether it's 'boolean'. */ + size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ +}; + +/* The name-field mappings we know about. */ +static const struct uparam_name uparam_names[] = +{ + { "dup-args", 1, offsetof (struct uparams, dup_args) }, + { "dup-args-note", 1, offsetof (struct uparams, dup_args_note) }, + { "short-opt-col", 0, offsetof (struct uparams, short_opt_col) }, + { "long-opt-col", 0, offsetof (struct uparams, long_opt_col) }, + { "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) }, + { "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) }, + { "header-col", 0, offsetof (struct uparams, header_col) }, + { "usage-indent", 0, offsetof (struct uparams, usage_indent) }, + { "rmargin", 0, offsetof (struct uparams, rmargin) }, + { 0 } +}; + +static void +validate_uparams (const struct argp_state *state, struct uparams *upptr) +{ + const struct uparam_name *up; + + for (up = uparam_names; up->name; up++) + { + if (up->is_bool + || up->uparams_offs == offsetof (struct uparams, rmargin)) + continue; + if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin) + { + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ +ARGP_HELP_FMT: %s value is less than or equal to %s"), + "rmargin", up->name); + return; + } + } + uparams = *upptr; + uparams.valid = 1; +} + +/* Read user options from the environment, and fill in UPARAMS appropriately. */ +static void +fill_in_uparams (const struct argp_state *state) +{ + const char *var = getenv ("ARGP_HELP_FMT"); + struct uparams new_params = uparams; + +#define SKIPWS(p) do { while (isspace ((unsigned char) *p)) p++; } while (0); + + if (var) + { + /* Parse var. */ + while (*var) + { + SKIPWS (var); + + if (isalpha ((unsigned char) *var)) + { + size_t var_len; + const struct uparam_name *un; + int unspec = 0, val = 0; + const char *arg = var; + + while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_') + arg++; + var_len = arg - var; + + SKIPWS (arg); + + if (*arg == '\0' || *arg == ',') + unspec = 1; + else if (*arg == '=') + { + arg++; + SKIPWS (arg); + } + + if (unspec) + { + if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') + { + val = 0; + var += 3; + var_len -= 3; + } + else + val = 1; + } + else if (isdigit ((unsigned char) *arg)) + { + val = atoi (arg); + while (isdigit ((unsigned char) *arg)) + arg++; + SKIPWS (arg); + } + + for (un = uparam_names; un->name; un++) + if (strlen (un->name) == var_len + && strncmp (var, un->name, var_len) == 0) + { + if (unspec && !un->is_bool) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ +%.*s: ARGP_HELP_FMT parameter requires a value"), + (int) var_len, var); + else if (val < 0) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ +%.*s: ARGP_HELP_FMT parameter must be positive"), + (int) var_len, var); + else + *(int *)((char *)&new_params + un->uparams_offs) = val; + break; + } + if (! un->name) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, "\ +%.*s: Unknown ARGP_HELP_FMT parameter"), + (int) var_len, var); + + var = arg; + if (*var == ',') + var++; + } + else if (*var) + { + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "Garbage in ARGP_HELP_FMT: %s"), var); + break; + } + } + validate_uparams (state, &new_params); + } +} + +/* Returns true if OPT hasn't been marked invisible. Visibility only affects + whether OPT is displayed or used in sorting, not option shadowing. */ +#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN)) + +/* Returns true if OPT is an alias for an earlier option. */ +#define oalias(opt) ((opt)->flags & OPTION_ALIAS) + +/* Returns true if OPT is a documentation-only entry. */ +#define odoc(opt) ((opt)->flags & OPTION_DOC) + +/* Returns true if OPT should not be translated */ +#define onotrans(opt) ((opt)->flags & OPTION_NO_TRANS) + +/* Returns true if OPT is the end-of-list marker for a list of options. */ +#define oend(opt) __option_is_end (opt) + +/* Returns true if OPT has a short option. */ +#define oshort(opt) __option_is_short (opt) + +/* + The help format for a particular option is like: + + -xARG, -yARG, --long1=ARG, --long2=ARG Documentation... + + Where ARG will be omitted if there's no argument, for this option, or + will be surrounded by "[" and "]" appropriately if the argument is + optional. The documentation string is word-wrapped appropriately, and if + the list of options is long enough, it will be started on a separate line. + If there are no short options for a given option, the first long option is + indented slightly in a way that's supposed to make most long options appear + to be in a separate column. + + For example, the following output (from ps): + + -p PID, --pid=PID List the process PID + --pgrp=PGRP List processes in the process group PGRP + -P, -x, --no-parent Include processes without parents + -Q, --all-fields Don't elide unusable fields (normally if there's + some reason ps can't print a field for any + process, it's removed from the output entirely) + -r, --reverse, --gratuitously-long-reverse-option + Reverse the order of any sort + --session[=SID] Add the processes from the session SID (which + defaults to the sid of the current process) + + Here are some more options: + -f ZOT, --foonly=ZOT Glork a foonly + -z, --zaza Snit a zar + + -?, --help Give this help list + --usage Give a short usage message + -V, --version Print program version + + The struct argp_option array for the above could look like: + + { + {"pid", 'p', "PID", 0, "List the process PID"}, + {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"}, + {"no-parent", 'P', 0, 0, "Include processes without parents"}, + {0, 'x', 0, OPTION_ALIAS}, + {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" + " if there's some reason ps can't" + " print a field for any process, it's" + " removed from the output entirely)" }, + {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, + {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, + {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL, + "Add the processes from the session" + " SID (which defaults to the sid of" + " the current process)" }, + + {0,0,0,0, "Here are some more options:"}, + {"foonly", 'f', "ZOT", 0, "Glork a foonly"}, + {"zaza", 'z', 0, 0, "Snit a zar"}, + + {0} + } + + Note that the last three options are automatically supplied by argp_parse, + unless you tell it not to with ARGP_NO_HELP. + +*/ + +/* Returns true if CH occurs between BEG and END. */ +static int +find_char (char ch, char *beg, char *end) +{ + while (beg < end) + if (*beg == ch) + return 1; + else + beg++; + return 0; +} + +struct hol_cluster; /* fwd decl */ + +struct hol_entry +{ + /* First option. */ + const struct argp_option *opt; + /* Number of options (including aliases). */ + unsigned num; + + /* A pointers into the HOL's short_options field, to the first short option + letter for this entry. The order of the characters following this point + corresponds to the order of options pointed to by OPT, and there are at + most NUM. A short option recorded in an option following OPT is only + valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's + probably been shadowed by some other entry). */ + char *short_options; + + /* Entries are sorted by their group first, in the order: + 1, 2, ..., n, 0, -m, ..., -2, -1 + and then alphabetically within each group. The default is 0. */ + int group; + + /* The cluster of options this entry belongs to, or 0 if none. */ + struct hol_cluster *cluster; + + /* The argp from which this option came. */ + const struct argp *argp; + + /* Position in the array */ + unsigned ord; +}; + +/* A cluster of entries to reflect the argp tree structure. */ +struct hol_cluster +{ + /* A descriptive header printed before options in this cluster. */ + const char *header; + + /* Used to order clusters within the same group with the same parent, + according to the order in which they occurred in the parent argp's child + list. */ + int index; + + /* How to sort this cluster with respect to options and other clusters at the + same depth (clusters always follow options in the same group). */ + int group; + + /* The cluster to which this cluster belongs, or 0 if it's at the base + level. */ + struct hol_cluster *parent; + + /* The argp from which this cluster is (eventually) derived. */ + const struct argp *argp; + + /* The distance this cluster is from the root. */ + int depth; + + /* Clusters in a given hol are kept in a linked list, to make freeing them + possible. */ + struct hol_cluster *next; +}; + +/* A list of options for help. */ +struct hol +{ + /* An array of hol_entry's. */ + struct hol_entry *entries; + /* The number of entries in this hol. If this field is zero, the others + are undefined. */ + unsigned num_entries; + + /* A string containing all short options in this HOL. Each entry contains + pointers into this string, so the order can't be messed with blindly. */ + char *short_options; + + /* Clusters of entries in this hol. */ + struct hol_cluster *clusters; +}; + +/* Create a struct hol from the options in ARGP. CLUSTER is the + hol_cluster in which these entries occur, or 0, if at the root. */ +static struct hol * +make_hol (const struct argp *argp, struct hol_cluster *cluster) +{ + char *so; + const struct argp_option *o; + const struct argp_option *opts = argp->options; + struct hol_entry *entry; + unsigned num_short_options = 0; + struct hol *hol = malloc (sizeof (struct hol)); + + assert (hol); + + hol->num_entries = 0; + hol->clusters = 0; + + if (opts) + { + int cur_group = 0; + + /* The first option must not be an alias. */ + assert (! oalias (opts)); + + /* Calculate the space needed. */ + for (o = opts; ! oend (o); o++) + { + if (! oalias (o)) + hol->num_entries++; + if (oshort (o)) + num_short_options++; /* This is an upper bound. */ + } + + hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries); + hol->short_options = malloc (num_short_options + 1); + + assert (hol->entries && hol->short_options); + if (SIZE_MAX <= UINT_MAX) + assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); + + /* Fill in the entries. */ + so = hol->short_options; + for (o = opts, entry = hol->entries; ! oend (o); entry++) + { + entry->opt = o; + entry->num = 0; + entry->short_options = so; + entry->group = cur_group = + o->group + ? o->group + : ((!o->name && !o->key) + ? cur_group + 1 + : cur_group); + entry->cluster = cluster; + entry->argp = argp; + + do + { + entry->num++; + if (oshort (o) && ! find_char (o->key, hol->short_options, so)) + /* O has a valid short option which hasn't already been used.*/ + *so++ = o->key; + o++; + } + while (! oend (o) && oalias (o)); + } + *so = '\0'; /* null terminated so we can find the length */ + } + + return hol; +} + +/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the + associated argp child list entry), INDEX, and PARENT, and return a pointer + to it. ARGP is the argp that this cluster results from. */ +static struct hol_cluster * +hol_add_cluster (struct hol *hol, int group, const char *header, int index, + struct hol_cluster *parent, const struct argp *argp) +{ + struct hol_cluster *cl = malloc (sizeof (struct hol_cluster)); + if (cl) + { + cl->group = group; + cl->header = header; + + cl->index = index; + cl->parent = parent; + cl->argp = argp; + cl->depth = parent ? parent->depth + 1 : 0; + + cl->next = hol->clusters; + hol->clusters = cl; + } + return cl; +} + +/* Free HOL and any resources it uses. */ +static void +hol_free (struct hol *hol) +{ + struct hol_cluster *cl = hol->clusters; + + while (cl) + { + struct hol_cluster *next = cl->next; + free (cl); + cl = next; + } + + if (hol->num_entries > 0) + { + free (hol->entries); + free (hol->short_options); + } + + free (hol); +} + +static int +hol_entry_short_iterate (const struct hol_entry *entry, + int (*func)(const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie), + const char *domain, void *cookie) +{ + unsigned nopts; + int val = 0; + const struct argp_option *opt, *real = entry->opt; + char *so = entry->short_options; + + for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) + if (oshort (opt) && *so == opt->key) + { + if (!oalias (opt)) + real = opt; + if (ovisible (opt)) + val = (*func)(opt, real, domain, cookie); + so++; + } + + return val; +} + +static inline int +#if __GNUC__ >= 3 +__attribute__ ((always_inline)) +#endif +hol_entry_long_iterate (const struct hol_entry *entry, + int (*func)(const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie), + const char *domain, void *cookie) +{ + unsigned nopts; + int val = 0; + const struct argp_option *opt, *real = entry->opt; + + for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) + if (opt->name) + { + if (!oalias (opt)) + real = opt; + if (ovisible (opt)) + val = (*func)(opt, real, domain, cookie); + } + + return val; +} + +/* Iterator that returns true for the first short option. */ +static int +until_short (const struct argp_option *opt, const struct argp_option *real, + const char *domain, void *cookie) +{ + return oshort (opt) ? opt->key : 0; +} + +/* Returns the first valid short option in ENTRY, or 0 if there is none. */ +static char +hol_entry_first_short (const struct hol_entry *entry) +{ + return hol_entry_short_iterate (entry, until_short, + entry->argp->argp_domain, 0); +} + +/* Returns the first valid long option in ENTRY, or 0 if there is none. */ +static const char * +hol_entry_first_long (const struct hol_entry *entry) +{ + const struct argp_option *opt; + unsigned num; + for (opt = entry->opt, num = entry->num; num > 0; opt++, num--) + if (opt->name && ovisible (opt)) + return opt->name; + return 0; +} + +/* Returns the entry in HOL with the long option name NAME, or 0 if there is + none. */ +static struct hol_entry * +hol_find_entry (struct hol *hol, const char *name) +{ + struct hol_entry *entry = hol->entries; + unsigned num_entries = hol->num_entries; + + while (num_entries-- > 0) + { + const struct argp_option *opt = entry->opt; + unsigned num_opts = entry->num; + + while (num_opts-- > 0) + if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) + return entry; + else + opt++; + + entry++; + } + + return 0; +} + +/* If an entry with the long option NAME occurs in HOL, set it's special + sort position to GROUP. */ +static void +hol_set_group (struct hol *hol, const char *name, int group) +{ + struct hol_entry *entry = hol_find_entry (hol, name); + if (entry) + entry->group = group; +} + +/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1. + EQ is what to return if GROUP1 and GROUP2 are the same. */ +static int +group_cmp (int group1, int group2, int eq) +{ + if (group1 == group2) + return eq; + else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0)) + return group1 - group2; + else + return group2 - group1; +} + +/* Compare clusters CL1 & CL2 by the order that they should appear in + output. */ +static int +hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2) +{ + /* If one cluster is deeper than the other, use its ancestor at the same + level, so that finding the common ancestor is straightforward. + + clN->depth > 0 means that clN->parent != NULL (see hol_add_cluster) */ + while (cl1->depth > cl2->depth) + cl1 = cl1->parent; + while (cl2->depth > cl1->depth) + cl2 = cl2->parent; + + /* Now reduce both clusters to their ancestors at the point where both have + a common parent; these can be directly compared. */ + while (cl1->parent != cl2->parent) + cl1 = cl1->parent, cl2 = cl2->parent; + + return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index); +} + +/* Return the ancestor of CL that's just below the root (i.e., has a parent + of 0). */ +static struct hol_cluster * +hol_cluster_base (struct hol_cluster *cl) +{ + while (cl->parent) + cl = cl->parent; + return cl; +} + +/* Return true if CL1 is a child of CL2. */ +static int +hol_cluster_is_child (const struct hol_cluster *cl1, + const struct hol_cluster *cl2) +{ + while (cl1 && cl1 != cl2) + cl1 = cl1->parent; + return cl1 == cl2; +} + +/* Given the name of an OPTION_DOC option, modifies NAME to start at the tail + that should be used for comparisons, and returns true iff it should be + treated as a non-option. */ +static int +canon_doc_option (const char **name) +{ + int non_opt; + + if (!*name) + non_opt = 1; + else + { + /* Skip initial whitespace. */ + while (isspace ((unsigned char) **name)) + (*name)++; + /* Decide whether this looks like an option (leading '-') or not. */ + non_opt = (**name != '-'); + /* Skip until part of name used for sorting. */ + while (**name && !isalnum ((unsigned char) **name)) + (*name)++; + } + return non_opt; +} + +#define HOL_ENTRY_PTRCMP(a,b) ((a)->ord < (b)->ord ? -1 : 1) + +/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help + listing. */ +static int +hol_entry_cmp (const struct hol_entry *entry1, + const struct hol_entry *entry2) +{ + /* The group numbers by which the entries should be ordered; if either is + in a cluster, then this is just the group within the cluster. */ + int group1 = entry1->group, group2 = entry2->group; + int rc; + + if (entry1->cluster != entry2->cluster) + { + /* The entries are not within the same cluster, so we can't compare them + directly, we have to use the appropriate clustering level too. */ + if (! entry1->cluster) + /* ENTRY1 is at the "base level", not in a cluster, so we have to + compare it's group number with that of the base cluster in which + ENTRY2 resides. Note that if they're in the same group, the + clustered option always comes laster. */ + return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); + else if (! entry2->cluster) + /* Likewise, but ENTRY2's not in a cluster. */ + return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); + else + /* Both entries are in clusters, we can just compare the clusters. */ + return (rc = hol_cluster_cmp (entry1->cluster, entry2->cluster)) ? + rc : HOL_ENTRY_PTRCMP (entry1, entry2); + } + else if (group1 == group2) + /* The entries are both in the same cluster and group, so compare them + alphabetically. */ + { + int short1 = hol_entry_first_short (entry1); + int short2 = hol_entry_first_short (entry2); + int doc1 = odoc (entry1->opt); + int doc2 = odoc (entry2->opt); + const char *long1 = hol_entry_first_long (entry1); + const char *long2 = hol_entry_first_long (entry2); + + if (doc1) + doc1 = canon_doc_option (&long1); + if (doc2) + doc2 = canon_doc_option (&long2); + + if (doc1 != doc2) + /* "documentation" options always follow normal options (or + documentation options that *look* like normal options). */ + return doc1 - doc2; + else if (!short1 && !short2 && long1 && long2) + /* Only long options. */ + return (rc = __strcasecmp (long1, long2)) ? + rc : HOL_ENTRY_PTRCMP (entry1, entry2); + else + /* Compare short/short, long/short, short/long, using the first + character of long options. Entries without *any* valid + options (such as options with OPTION_HIDDEN set) will be put + first, but as they're not displayed, it doesn't matter where + they are. */ + { + unsigned char first1 = short1 ? short1 : long1 ? *long1 : 0; + unsigned char first2 = short2 ? short2 : long2 ? *long2 : 0; + /* Use tolower, not _tolower, since only the former is + guaranteed to work on something already lower case. */ + int lower_cmp = tolower (first1) - tolower (first2); + /* Compare ignoring case, except when the options are both the + same letter, in which case lower-case always comes first. */ + return lower_cmp ? lower_cmp : + (rc = first2 - first1) ? + rc : HOL_ENTRY_PTRCMP (entry1, entry2); + } + } + else + /* Within the same cluster, but not the same group, so just compare + groups. */ + return group_cmp (group1, group2, HOL_ENTRY_PTRCMP (entry1, entry2)); +} + +/* Version of hol_entry_cmp with correct signature for qsort. */ +static int +hol_entry_qcmp (const void *entry1_v, const void *entry2_v) +{ + return hol_entry_cmp (entry1_v, entry2_v); +} + +/* Sort HOL by group and alphabetically by option name (with short options + taking precedence over long). Since the sorting is for display purposes + only, the shadowing of options isn't effected. */ +static void +hol_sort (struct hol *hol) +{ + if (hol->num_entries > 0) + { + unsigned i; + struct hol_entry *e; + for (i = 0, e = hol->entries; i < hol->num_entries; i++, e++) + e->ord = i; + qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), + hol_entry_qcmp); + } +} + +/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow + any in MORE with the same name. */ +static void +hol_append (struct hol *hol, struct hol *more) +{ + struct hol_cluster **cl_end = &hol->clusters; + + /* Steal MORE's cluster list, and add it to the end of HOL's. */ + while (*cl_end) + cl_end = &(*cl_end)->next; + *cl_end = more->clusters; + more->clusters = 0; + + /* Merge entries. */ + if (more->num_entries > 0) + { + if (hol->num_entries == 0) + { + hol->num_entries = more->num_entries; + hol->entries = more->entries; + hol->short_options = more->short_options; + more->num_entries = 0; /* Mark MORE's fields as invalid. */ + } + else + /* Append the entries in MORE to those in HOL, taking care to only add + non-shadowed SHORT_OPTIONS values. */ + { + unsigned left; + char *so, *more_so; + struct hol_entry *e; + unsigned num_entries = hol->num_entries + more->num_entries; + struct hol_entry *entries = + malloc (num_entries * sizeof (struct hol_entry)); + unsigned hol_so_len = strlen (hol->short_options); + char *short_options = + malloc (hol_so_len + strlen (more->short_options) + 1); + + assert (entries && short_options); + if (SIZE_MAX <= UINT_MAX) + assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); + + __mempcpy (__mempcpy (entries, hol->entries, + hol->num_entries * sizeof (struct hol_entry)), + more->entries, + more->num_entries * sizeof (struct hol_entry)); + + __mempcpy (short_options, hol->short_options, hol_so_len); + + /* Fix up the short options pointers from HOL. */ + for (e = entries, left = hol->num_entries; left > 0; e++, left--) + e->short_options = + short_options + (e->short_options - hol->short_options); + + /* Now add the short options from MORE, fixing up its entries + too. */ + so = short_options + hol_so_len; + more_so = more->short_options; + for (left = more->num_entries; left > 0; e++, left--) + { + int opts_left; + const struct argp_option *opt; + + e->short_options = so; + + for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) + { + int ch = *more_so; + if (oshort (opt) && ch == opt->key) + /* The next short option in MORE_SO, CH, is from OPT. */ + { + if (! find_char (ch, short_options, + short_options + hol_so_len)) + /* The short option CH isn't shadowed by HOL's options, + so add it to the sum. */ + *so++ = ch; + more_so++; + } + } + } + + *so = '\0'; + + free (hol->entries); + free (hol->short_options); + + hol->entries = entries; + hol->num_entries = num_entries; + hol->short_options = short_options; + } + } + + hol_free (more); +} + +/* Inserts enough spaces to make sure STREAM is at column COL. */ +static void +indent_to (argp_fmtstream_t stream, unsigned col) +{ + int needed = col - __argp_fmtstream_point (stream); + while (needed-- > 0) + __argp_fmtstream_putc (stream, ' '); +} + +/* Output to STREAM either a space, or a newline if there isn't room for at + least ENSURE characters before the right margin. */ +static void +space (argp_fmtstream_t stream, size_t ensure) +{ + if (__argp_fmtstream_point (stream) + ensure + >= __argp_fmtstream_rmargin (stream)) + __argp_fmtstream_putc (stream, '\n'); + else + __argp_fmtstream_putc (stream, ' '); +} + +/* If the option REAL has an argument, we print it in using the printf + format REQ_FMT or OPT_FMT depending on whether it's a required or + optional argument. */ +static void +arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, + const char *domain, argp_fmtstream_t stream) +{ + if (real->arg) + { + if (real->flags & OPTION_ARG_OPTIONAL) + __argp_fmtstream_printf (stream, opt_fmt, + dgettext (domain, real->arg)); + else + __argp_fmtstream_printf (stream, req_fmt, + dgettext (domain, real->arg)); + } +} + +/* Helper functions for hol_entry_help. */ + +/* State used during the execution of hol_help. */ +struct hol_help_state +{ + /* PREV_ENTRY should contain the previous entry printed, or 0. */ + struct hol_entry *prev_entry; + + /* If an entry is in a different group from the previous one, and SEP_GROUPS + is true, then a blank line will be printed before any output. */ + int sep_groups; + + /* True if a duplicate option argument was suppressed (only ever set if + UPARAMS.dup_args is false). */ + int suppressed_dup_arg; +}; + +/* Some state used while printing a help entry (used to communicate with + helper functions). See the doc for hol_entry_help for more info, as most + of the fields are copied from its arguments. */ +struct pentry_state +{ + const struct hol_entry *entry; + argp_fmtstream_t stream; + struct hol_help_state *hhstate; + + /* True if nothing's been printed so far. */ + int first; + + /* If non-zero, the state that was used to print this help. */ + const struct argp_state *state; +}; + +/* If a user doc filter should be applied to DOC, do so. */ +static const char * +filter_doc (const char *doc, int key, const struct argp *argp, + const struct argp_state *state) +{ + if (argp->help_filter) + /* We must apply a user filter to this output. */ + { + void *input = __argp_input (argp, state); + return (*argp->help_filter) (key, doc, input); + } + else + /* No filter. */ + return doc; +} + +/* Prints STR as a header line, with the margin lines set appropriately, and + notes the fact that groups should be separated with a blank line. ARGP is + the argp that should dictate any user doc filtering to take place. Note + that the previous wrap margin isn't restored, but the left margin is reset + to 0. */ +static void +print_header (const char *str, const struct argp *argp, + struct pentry_state *pest) +{ + const char *tstr = dgettext (argp->argp_domain, str); + const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); + + if (fstr) + { + if (*fstr) + { + if (pest->hhstate->prev_entry) + /* Precede with a blank line. */ + __argp_fmtstream_putc (pest->stream, '\n'); + indent_to (pest->stream, uparams.header_col); + __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); + __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); + __argp_fmtstream_puts (pest->stream, fstr); + __argp_fmtstream_set_lmargin (pest->stream, 0); + __argp_fmtstream_putc (pest->stream, '\n'); + } + + pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */ + } + + if (fstr != tstr) + free ((char *) fstr); +} + +/* Inserts a comma if this isn't the first item on the line, and then makes + sure we're at least to column COL. If this *is* the first item on a line, + prints any pending whitespace/headers that should precede this line. Also + clears FIRST. */ +static void +comma (unsigned col, struct pentry_state *pest) +{ + if (pest->first) + { + const struct hol_entry *pe = pest->hhstate->prev_entry; + const struct hol_cluster *cl = pest->entry->cluster; + + if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group) + __argp_fmtstream_putc (pest->stream, '\n'); + + if (cl && cl->header && *cl->header + && (!pe + || (pe->cluster != cl + && !hol_cluster_is_child (pe->cluster, cl)))) + /* If we're changing clusters, then this must be the start of the + ENTRY's cluster unless that is an ancestor of the previous one + (in which case we had just popped into a sub-cluster for a bit). + If so, then print the cluster's header line. */ + { + int old_wm = __argp_fmtstream_wmargin (pest->stream); + print_header (cl->header, cl->argp, pest); + __argp_fmtstream_set_wmargin (pest->stream, old_wm); + } + + pest->first = 0; + } + else + __argp_fmtstream_puts (pest->stream, ", "); + + indent_to (pest->stream, col); +} + +/* Print help for ENTRY to STREAM. */ +static void +hol_entry_help (struct hol_entry *entry, const struct argp_state *state, + argp_fmtstream_t stream, struct hol_help_state *hhstate) +{ + unsigned num; + const struct argp_option *real = entry->opt, *opt; + char *so = entry->short_options; + int have_long_opt = 0; /* We have any long options. */ + /* Saved margins. */ + int old_lm = __argp_fmtstream_set_lmargin (stream, 0); + int old_wm = __argp_fmtstream_wmargin (stream); + /* PEST is a state block holding some of our variables that we'd like to + share with helper functions. */ + struct pentry_state pest; + + pest.entry = entry; + pest.stream = stream; + pest.hhstate = hhstate; + pest.first = 1; + pest.state = state; + + if (! odoc (real)) + for (opt = real, num = entry->num; num > 0; opt++, num--) + if (opt->name && ovisible (opt)) + { + have_long_opt = 1; + break; + } + + /* First emit short options. */ + __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */ + for (opt = real, num = entry->num; num > 0; opt++, num--) + if (oshort (opt) && opt->key == *so) + /* OPT has a valid (non shadowed) short option. */ + { + if (ovisible (opt)) + { + comma (uparams.short_opt_col, &pest); + __argp_fmtstream_putc (stream, '-'); + __argp_fmtstream_putc (stream, *so); + if (!have_long_opt || uparams.dup_args) + arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); + else if (real->arg) + hhstate->suppressed_dup_arg = 1; + } + so++; + } + + /* Now, long options. */ + if (odoc (real)) + /* A "documentation" option. */ + { + __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); + for (opt = real, num = entry->num; num > 0; opt++, num--) + if (opt->name && *opt->name && ovisible (opt)) + { + comma (uparams.doc_opt_col, &pest); + /* Calling dgettext here isn't quite right, since sorting will + have been done on the original; but documentation options + should be pretty rare anyway... */ + __argp_fmtstream_puts (stream, + onotrans (opt) ? + opt->name : + dgettext (state->root_argp->argp_domain, + opt->name)); + } + } + else + /* A real long option. */ + { + int first_long_opt = 1; + + __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col); + for (opt = real, num = entry->num; num > 0; opt++, num--) + if (opt->name && ovisible (opt)) + { + comma (uparams.long_opt_col, &pest); + __argp_fmtstream_printf (stream, "--%s", opt->name); + if (first_long_opt || uparams.dup_args) + arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, + stream); + else if (real->arg) + hhstate->suppressed_dup_arg = 1; + } + } + + /* Next, documentation strings. */ + __argp_fmtstream_set_lmargin (stream, 0); + + if (pest.first) + { + /* Didn't print any switches, what's up? */ + if (!oshort (real) && !real->name) + /* This is a group header, print it nicely. */ + print_header (real->doc, entry->argp, &pest); + else + /* Just a totally shadowed option or null header; print nothing. */ + goto cleanup; /* Just return, after cleaning up. */ + } + else + { + const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain, + real->doc) : 0; + const char *fstr = filter_doc (tstr, real->key, entry->argp, state); + if (fstr && *fstr) + { + unsigned int col = __argp_fmtstream_point (stream); + + __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); + __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); + + if (col > (unsigned int) (uparams.opt_doc_col + 3)) + __argp_fmtstream_putc (stream, '\n'); + else if (col >= (unsigned int) uparams.opt_doc_col) + __argp_fmtstream_puts (stream, " "); + else + indent_to (stream, uparams.opt_doc_col); + + __argp_fmtstream_puts (stream, fstr); + } + if (fstr && fstr != tstr) + free ((char *) fstr); + + /* Reset the left margin. */ + __argp_fmtstream_set_lmargin (stream, 0); + __argp_fmtstream_putc (stream, '\n'); + } + + hhstate->prev_entry = entry; + +cleanup: + __argp_fmtstream_set_lmargin (stream, old_lm); + __argp_fmtstream_set_wmargin (stream, old_wm); +} + +/* Output a long help message about the options in HOL to STREAM. */ +static void +hol_help (struct hol *hol, const struct argp_state *state, + argp_fmtstream_t stream) +{ + unsigned num; + struct hol_entry *entry; + struct hol_help_state hhstate = { 0, 0, 0 }; + + for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--) + hol_entry_help (entry, state, stream, &hhstate); + + if (hhstate.suppressed_dup_arg && uparams.dup_args_note) + { + const char *tstr = dgettext (state->root_argp->argp_domain, "\ +Mandatory or optional arguments to long options are also mandatory or \ +optional for any corresponding short options."); + const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, + state ? state->root_argp : 0, state); + if (fstr && *fstr) + { + __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_puts (stream, fstr); + __argp_fmtstream_putc (stream, '\n'); + } + if (fstr && fstr != tstr) + free ((char *) fstr); + } +} + +/* Helper functions for hol_usage. */ + +/* If OPT is a short option without an arg, append its key to the string + pointer pointer to by COOKIE, and advance the pointer. */ +static int +add_argless_short_opt (const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie) +{ + char **snao_end = cookie; + if (!(opt->arg || real->arg) + && !((opt->flags | real->flags) & OPTION_NO_USAGE)) + *(*snao_end)++ = opt->key; + return 0; +} + +/* If OPT is a short option with an arg, output a usage entry for it to the + stream pointed at by COOKIE. */ +static int +usage_argful_short_opt (const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie) +{ + argp_fmtstream_t stream = cookie; + const char *arg = opt->arg; + int flags = opt->flags | real->flags; + + if (! arg) + arg = real->arg; + + if (arg && !(flags & OPTION_NO_USAGE)) + { + arg = dgettext (domain, arg); + + if (flags & OPTION_ARG_OPTIONAL) + __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); + else + { + /* Manually do line wrapping so that it (probably) won't + get wrapped at the embedded space. */ + space (stream, 6 + strlen (arg)); + __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); + } + } + + return 0; +} + +/* Output a usage entry for the long option opt to the stream pointed at by + COOKIE. */ +static int +usage_long_opt (const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie) +{ + argp_fmtstream_t stream = cookie; + const char *arg = opt->arg; + int flags = opt->flags | real->flags; + + if (! arg) + arg = real->arg; + + if (! (flags & OPTION_NO_USAGE) && !odoc (opt)) + { + if (arg) + { + arg = dgettext (domain, arg); + if (flags & OPTION_ARG_OPTIONAL) + __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); + else + __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); + } + else + __argp_fmtstream_printf (stream, " [--%s]", opt->name); + } + + return 0; +} + +/* Print a short usage description for the arguments in HOL to STREAM. */ +static void +hol_usage (struct hol *hol, argp_fmtstream_t stream) +{ + if (hol->num_entries > 0) + { + unsigned nentries; + struct hol_entry *entry; + char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1); + char *snao_end = short_no_arg_opts; + + /* First we put a list of short options without arguments. */ + for (entry = hol->entries, nentries = hol->num_entries + ; nentries > 0 + ; entry++, nentries--) + hol_entry_short_iterate (entry, add_argless_short_opt, + entry->argp->argp_domain, &snao_end); + if (snao_end > short_no_arg_opts) + { + *snao_end++ = 0; + __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); + } + + /* Now a list of short options *with* arguments. */ + for (entry = hol->entries, nentries = hol->num_entries + ; nentries > 0 + ; entry++, nentries--) + hol_entry_short_iterate (entry, usage_argful_short_opt, + entry->argp->argp_domain, stream); + + /* Finally, a list of long options (whew!). */ + for (entry = hol->entries, nentries = hol->num_entries + ; nentries > 0 + ; entry++, nentries--) + hol_entry_long_iterate (entry, usage_long_opt, + entry->argp->argp_domain, stream); + } +} + +/* Make a HOL containing all levels of options in ARGP. CLUSTER is the + cluster in which ARGP's entries should be clustered, or 0. */ +static struct hol * +argp_hol (const struct argp *argp, struct hol_cluster *cluster) +{ + const struct argp_child *child = argp->children; + struct hol *hol = make_hol (argp, cluster); + if (child) + while (child->argp) + { + struct hol_cluster *child_cluster = + ((child->group || child->header) + /* Put CHILD->argp within its own cluster. */ + ? hol_add_cluster (hol, child->group, child->header, + child - argp->children, cluster, argp) + /* Just merge it into the parent's cluster. */ + : cluster); + hol_append (hol, argp_hol (child->argp, child_cluster)) ; + child++; + } + return hol; +} + +/* Calculate how many different levels with alternative args strings exist in + ARGP. */ +static size_t +argp_args_levels (const struct argp *argp) +{ + size_t levels = 0; + const struct argp_child *child = argp->children; + + if (argp->args_doc && strchr (argp->args_doc, '\n')) + levels++; + + if (child) + while (child->argp) + levels += argp_args_levels ((child++)->argp); + + return levels; +} + +/* Print all the non-option args documented in ARGP to STREAM. Any output is + preceded by a space. LEVELS is a pointer to a byte vector the length + returned by argp_args_levels; it should be initialized to zero, and + updated by this routine for the next call if ADVANCE is true. True is + returned as long as there are more patterns to output. */ +static int +argp_args_usage (const struct argp *argp, const struct argp_state *state, + char **levels, int advance, argp_fmtstream_t stream) +{ + char *our_level = *levels; + int multiple = 0; + const struct argp_child *child = argp->children; + const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0; + const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); + + if (fdoc) + { + const char *cp = fdoc; + nl = __strchrnul (cp, '\n'); + if (*nl != '\0') + /* This is a "multi-level" args doc; advance to the correct position + as determined by our state in LEVELS, and update LEVELS. */ + { + int i; + multiple = 1; + for (i = 0; i < *our_level; i++) + cp = nl + 1, nl = __strchrnul (cp, '\n'); + (*levels)++; + } + + /* Manually do line wrapping so that it (probably) won't get wrapped at + any embedded spaces. */ + space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL)); + + __argp_fmtstream_write (stream, cp, nl - cp); + } + if (fdoc && fdoc != tdoc) + free ((char *)fdoc); /* Free user's modified doc string. */ + + if (child) + while (child->argp) + advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream); + + if (advance && multiple) + { + /* Need to increment our level. */ + if (*nl) + /* There's more we can do here. */ + { + (*our_level)++; + advance = 0; /* Our parent shouldn't advance also. */ + } + else if (*our_level > 0) + /* We had multiple levels, but used them up; reset to zero. */ + *our_level = 0; + } + + return !advance; +} + +/* Print the documentation for ARGP to STREAM; if POST is false, then + everything preceding a '\v' character in the documentation strings (or + the whole string, for those with none) is printed, otherwise, everything + following the '\v' character (nothing for strings without). Each separate + bit of documentation is separated a blank line, and if PRE_BLANK is true, + then the first is as well. If FIRST_ONLY is true, only the first + occurrence is output. Returns true if anything was output. */ +static int +argp_doc (const struct argp *argp, const struct argp_state *state, + int post, int pre_blank, int first_only, + argp_fmtstream_t stream) +{ + const char *text; + const char *inp_text; + size_t inp_text_len = 0; + const char *trans_text; + void *input = 0; + int anything = 0; + const struct argp_child *child = argp->children; + + if (argp->doc) + { + char *vt = strchr (argp->doc, '\v'); + if (vt) + { + if (post) + inp_text = vt + 1; + else + { + inp_text_len = vt - argp->doc; + inp_text = __strndup (argp->doc, inp_text_len); + } + } + else + inp_text = post ? 0 : argp->doc; + trans_text = inp_text ? dgettext (argp->argp_domain, inp_text) : NULL; + } + else + trans_text = inp_text = 0; + + if (argp->help_filter) + /* We have to filter the doc strings. */ + { + input = __argp_input (argp, state); + text = + (*argp->help_filter) (post + ? ARGP_KEY_HELP_POST_DOC + : ARGP_KEY_HELP_PRE_DOC, + trans_text, input); + } + else + text = (const char *) trans_text; + + if (text) + { + if (pre_blank) + __argp_fmtstream_putc (stream, '\n'); + + __argp_fmtstream_puts (stream, text); + + if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) + __argp_fmtstream_putc (stream, '\n'); + + anything = 1; + } + + if (text && text != trans_text) + free ((char *) text); /* Free TEXT returned from the help filter. */ + + if (inp_text && inp_text_len) + free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ + + if (post && argp->help_filter) + /* Now see if we have to output an ARGP_KEY_HELP_EXTRA text. */ + { + text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input); + if (text) + { + if (anything || pre_blank) + __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_puts (stream, text); + free ((char *) text); + if (__argp_fmtstream_point (stream) + > __argp_fmtstream_lmargin (stream)) + __argp_fmtstream_putc (stream, '\n'); + anything = 1; + } + } + + if (child) + while (child->argp && !(first_only && anything)) + anything |= + argp_doc ((child++)->argp, state, + post, anything || pre_blank, first_only, + stream); + + return anything; +} + +/* Output a usage message for ARGP to STREAM. If called from + argp_state_help, STATE is the relevant parsing state. FLAGS are from the + set ARGP_HELP_*. NAME is what to use wherever a "program name" is + needed. */ +static void +_help (const struct argp *argp, const struct argp_state *state, FILE *stream, + unsigned flags, char *name) +{ + int anything = 0; /* Whether we've output anything. */ + struct hol *hol = 0; + argp_fmtstream_t fs; + + if (! stream) + return; + +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __flockfile (stream); +#endif + + if (! uparams.valid) + fill_in_uparams (state); + + fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0); + if (! fs) + { +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __funlockfile (stream); +#endif + return; + } + + if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG)) + { + hol = argp_hol (argp, 0); + + /* If present, these options always come last. */ + hol_set_group (hol, "help", -1); + hol_set_group (hol, "version", -1); + + hol_sort (hol); + } + + if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE)) + /* Print a short "Usage:" message. */ + { + int first_pattern = 1, more_patterns; + size_t num_pattern_levels = argp_args_levels (argp); + char *pattern_levels = alloca (num_pattern_levels); + + memset (pattern_levels, 0, num_pattern_levels); + + do + { + int old_lm; + int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); + char *levels = pattern_levels; + + if (first_pattern) + __argp_fmtstream_printf (fs, "%s %s", + dgettext (argp->argp_domain, "Usage:"), + name); + else + __argp_fmtstream_printf (fs, "%s %s", + dgettext (argp->argp_domain, " or: "), + name); + + /* We set the lmargin as well as the wmargin, because hol_usage + manually wraps options with newline to avoid annoying breaks. */ + old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); + + if (flags & ARGP_HELP_SHORT_USAGE) + /* Just show where the options go. */ + { + if (hol->num_entries > 0) + __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, + " [OPTION...]")); + } + else + /* Actually print the options. */ + { + hol_usage (hol, fs); + flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ + } + + more_patterns = argp_args_usage (argp, state, &levels, 1, fs); + + __argp_fmtstream_set_wmargin (fs, old_wm); + __argp_fmtstream_set_lmargin (fs, old_lm); + + __argp_fmtstream_putc (fs, '\n'); + anything = 1; + + first_pattern = 0; + } + while (more_patterns); + } + + if (flags & ARGP_HELP_PRE_DOC) + anything |= argp_doc (argp, state, 0, 0, 1, fs); + + if (flags & ARGP_HELP_SEE) + { + __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\ +Try '%s --help' or '%s --usage' for more information.\n"), + name, name); + anything = 1; + } + + if (flags & ARGP_HELP_LONG) + /* Print a long, detailed help message. */ + { + /* Print info about all the options. */ + if (hol->num_entries > 0) + { + if (anything) + __argp_fmtstream_putc (fs, '\n'); + hol_help (hol, state, fs); + anything = 1; + } + } + + if (flags & ARGP_HELP_POST_DOC) + /* Print any documentation strings at the end. */ + anything |= argp_doc (argp, state, 1, anything, 0, fs); + + if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address) + { + if (anything) + __argp_fmtstream_putc (fs, '\n'); + __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, + "Report bugs to %s.\n"), + argp_program_bug_address); + anything = 1; + } + +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __funlockfile (stream); +#endif + + if (hol) + hol_free (hol); + + __argp_fmtstream_free (fs); +} + +/* Output a usage message for ARGP to STREAM. FLAGS are from the set + ARGP_HELP_*. NAME is what to use wherever a "program name" is needed. */ +void __argp_help (const struct argp *argp, FILE *stream, + unsigned flags, char *name) +{ + struct argp_state state; + memset (&state, 0, sizeof state); + state.root_argp = argp; + _help (argp, &state, stream, flags, name); +} +#ifdef weak_alias +weak_alias (__argp_help, argp_help) +#endif + +#if ! (defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) +char * +__argp_short_program_name (void) +{ +# if HAVE_DECL_PROGRAM_INVOCATION_NAME + return __argp_base_name (program_invocation_name); +# else + /* FIXME: What now? Miles suggests that it is better to use NULL, + but currently the value is passed on directly to fputs_unlocked, + so that requires more changes. */ +# if __GNUC__ +# warning No reasonable value to return +# endif /* __GNUC__ */ + return ""; +# endif +} +#endif + +/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are + from the set ARGP_HELP_*. */ +void +__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags) +{ + if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) + { + if (state && (state->flags & ARGP_LONG_ONLY)) + flags |= ARGP_HELP_LONG_ONLY; + + _help (state ? state->root_argp : 0, state, stream, flags, + state ? state->name : __argp_short_program_name ()); + + if (!state || ! (state->flags & ARGP_NO_EXIT)) + { + if (flags & ARGP_HELP_EXIT_ERR) + exit (argp_err_exit_status); + if (flags & ARGP_HELP_EXIT_OK) + exit (0); + } + } +} +#ifdef weak_alias +weak_alias (__argp_state_help, argp_state_help) +#endif + +/* If appropriate, print the printf string FMT and following args, preceded + by the program name and ':', to stderr, and followed by a "Try ... --help" + message, then exit (1). */ +void +__argp_error (const struct argp_state *state, const char *fmt, ...) +{ + if (!state || !(state->flags & ARGP_NO_ERRS)) + { + FILE *stream = state ? state->err_stream : stderr; + + if (stream) + { + va_list ap; + +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __flockfile (stream); +#endif + + va_start (ap, fmt); + +#ifdef USE_IN_LIBIO + if (_IO_fwide (stream, 0) > 0) + { + char *buf; + + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; + + __fwprintf (stream, L"%s: %s\n", + state ? state->name : __argp_short_program_name (), + buf); + + free (buf); + } + else +#endif + { + fputs_unlocked (state + ? state->name : __argp_short_program_name (), + stream); + putc_unlocked (':', stream); + putc_unlocked (' ', stream); + + vfprintf (stream, fmt, ap); + + putc_unlocked ('\n', stream); + } + + __argp_state_help (state, stream, ARGP_HELP_STD_ERR); + + va_end (ap); + +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __funlockfile (stream); +#endif + } + } +} +#ifdef weak_alias +weak_alias (__argp_error, argp_error) +#endif + +/* Similar to the standard gnu error-reporting function error(), but will + respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print + to STATE->err_stream. This is useful for argument parsing code that is + shared between program startup (when exiting is desired) and runtime + option parsing (when typically an error code is returned instead). The + difference between this function and argp_error is that the latter is for + *parsing errors*, and the former is for other problems that occur during + parsing but don't reflect a (syntactic) problem with the input. */ +void +__argp_failure (const struct argp_state *state, int status, int errnum, + const char *fmt, ...) +{ + if (!state || !(state->flags & ARGP_NO_ERRS)) + { + FILE *stream = state ? state->err_stream : stderr; + + if (stream) + { +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __flockfile (stream); +#endif + +#ifdef USE_IN_LIBIO + if (_IO_fwide (stream, 0) > 0) + __fwprintf (stream, L"%s", + state ? state->name : __argp_short_program_name ()); + else +#endif + fputs_unlocked (state + ? state->name : __argp_short_program_name (), + stream); + + if (fmt) + { + va_list ap; + + va_start (ap, fmt); +#ifdef USE_IN_LIBIO + if (_IO_fwide (stream, 0) > 0) + { + char *buf; + + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; + + __fwprintf (stream, L": %s", buf); + + free (buf); + } + else +#endif + { + putc_unlocked (':', stream); + putc_unlocked (' ', stream); + + vfprintf (stream, fmt, ap); + } + + va_end (ap); + } + + if (errnum) + { + char buf[200]; + +#ifdef USE_IN_LIBIO + if (_IO_fwide (stream, 0) > 0) + __fwprintf (stream, L": %s", + __strerror_r (errnum, buf, sizeof (buf))); + else +#endif + { + char const *s = NULL; + putc_unlocked (':', stream); + putc_unlocked (' ', stream); +#if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P && !defined strerror_r) + s = __strerror_r (errnum, buf, sizeof buf); +#elif HAVE_DECL_STRERROR_R + if (__strerror_r (errnum, buf, sizeof buf) == 0) + s = buf; +#endif +#if !_LIBC + if (! s && ! (s = strerror (errnum))) + s = dgettext (state->root_argp->argp_domain, + "Unknown system error"); +#endif + fputs (s, stream); + } + } + +#ifdef USE_IN_LIBIO + if (_IO_fwide (stream, 0) > 0) + putwc_unlocked (L'\n', stream); + else +#endif + putc_unlocked ('\n', stream); + +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) + __funlockfile (stream); +#endif + + if (status && (!state || !(state->flags & ARGP_NO_EXIT))) + exit (status); + } + } +} +#ifdef weak_alias +weak_alias (__argp_failure, argp_failure) +#endif diff --git a/grub-core/gnulib/argp-namefrob.h b/grub-core/gnulib/argp-namefrob.h new file mode 100644 index 000000000..6333958c6 --- /dev/null +++ b/grub-core/gnulib/argp-namefrob.h @@ -0,0 +1,157 @@ +/* Name frobnication for compiling argp outside of glibc + Copyright (C) 1997, 2003, 2007, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#if !_LIBC +/* This code is written for inclusion in gnu-libc, and uses names in the + namespace reserved for libc. If we're not compiling in libc, define those + names to be the normal ones instead. */ + +/* argp-parse functions */ +#undef __argp_parse +#define __argp_parse argp_parse +#undef __option_is_end +#define __option_is_end _option_is_end +#undef __option_is_short +#define __option_is_short _option_is_short +#undef __argp_input +#define __argp_input _argp_input + +/* argp-help functions */ +#undef __argp_help +#define __argp_help argp_help +#undef __argp_error +#define __argp_error argp_error +#undef __argp_failure +#define __argp_failure argp_failure +#undef __argp_state_help +#define __argp_state_help argp_state_help +#undef __argp_usage +#define __argp_usage argp_usage + +/* argp-fmtstream functions */ +#undef __argp_make_fmtstream +#define __argp_make_fmtstream argp_make_fmtstream +#undef __argp_fmtstream_free +#define __argp_fmtstream_free argp_fmtstream_free +#undef __argp_fmtstream_putc +#define __argp_fmtstream_putc argp_fmtstream_putc +#undef __argp_fmtstream_puts +#define __argp_fmtstream_puts argp_fmtstream_puts +#undef __argp_fmtstream_write +#define __argp_fmtstream_write argp_fmtstream_write +#undef __argp_fmtstream_printf +#define __argp_fmtstream_printf argp_fmtstream_printf +#undef __argp_fmtstream_set_lmargin +#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin +#undef __argp_fmtstream_set_rmargin +#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin +#undef __argp_fmtstream_set_wmargin +#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin +#undef __argp_fmtstream_point +#define __argp_fmtstream_point argp_fmtstream_point +#undef __argp_fmtstream_update +#define __argp_fmtstream_update _argp_fmtstream_update +#undef __argp_fmtstream_ensure +#define __argp_fmtstream_ensure _argp_fmtstream_ensure +#undef __argp_fmtstream_lmargin +#define __argp_fmtstream_lmargin argp_fmtstream_lmargin +#undef __argp_fmtstream_rmargin +#define __argp_fmtstream_rmargin argp_fmtstream_rmargin +#undef __argp_fmtstream_wmargin +#define __argp_fmtstream_wmargin argp_fmtstream_wmargin + +/* normal libc functions we call */ +#undef __flockfile +#define __flockfile flockfile +#undef __funlockfile +#define __funlockfile funlockfile +#undef __mempcpy +#define __mempcpy mempcpy +#undef __sleep +#define __sleep sleep +#undef __strcasecmp +#define __strcasecmp strcasecmp +#undef __strchrnul +#define __strchrnul strchrnul +#undef __strerror_r +#define __strerror_r strerror_r +#undef __strndup +#define __strndup strndup +#undef __vsnprintf +#define __vsnprintf vsnprintf + +#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED +# define clearerr_unlocked(x) clearerr (x) +#endif +#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED +# define feof_unlocked(x) feof (x) +#endif +#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED +# define ferror_unlocked(x) ferror (x) +#endif +#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED +# define fflush_unlocked(x) fflush (x) +#endif +#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED +# define fgets_unlocked(x,y,z) fgets (x,y,z) +#endif +#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED +# define fputc_unlocked(x,y) fputc (x,y) +#endif +#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED +# define fputs_unlocked(x,y) fputs (x,y) +#endif +#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED +# define fread_unlocked(w,x,y,z) fread (w,x,y,z) +#endif +#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED +# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) +#endif +#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED +# define getc_unlocked(x) getc (x) +#endif +#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED +# define getchar_unlocked() getchar () +#endif +#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED +# define putc_unlocked(x,y) putc (x,y) +#endif +#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED +# define putchar_unlocked(x) putchar (x) +#endif + +#endif /* !_LIBC */ + +#ifndef __set_errno +# define __set_errno(e) (errno = (e)) +#endif + +#if defined GNULIB_ARGP_DISABLE_DIRNAME +# define __argp_base_name(arg) arg +#elif defined GNULIB_ARGP_EXTERN_BASENAME +extern char *__argp_base_name (const char *arg); +#else +# include "dirname.h" +# define __argp_base_name last_component +#endif + +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME +# define __argp_short_program_name() (program_invocation_short_name) +#else +extern char *__argp_short_program_name (void); +#endif diff --git a/grub-core/gnulib/argp-parse.c b/grub-core/gnulib/argp-parse.c new file mode 100644 index 000000000..67ea32c54 --- /dev/null +++ b/grub-core/gnulib/argp-parse.c @@ -0,0 +1,953 @@ +/* Hierarchical argument parsing, layered over getopt + Copyright (C) 1995-2000, 2002-2004, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _LIBC +# include +# undef dgettext +# define dgettext(domain, msgid) \ + INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) +#else +# include "gettext.h" +#endif +#define N_(msgid) msgid + +#include "argp.h" +#include "argp-namefrob.h" + +#define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d)) + +/* Getopt return values. */ +#define KEY_END (-1) /* The end of the options. */ +#define KEY_ARG 1 /* A non-option argument. */ +#define KEY_ERR '?' /* An error parsing the options. */ + +/* The meta-argument used to prevent any further arguments being interpreted + as options. */ +#define QUOTE "--" + +/* The number of bits we steal in a long-option value for our own use. */ +#define GROUP_BITS CHAR_BIT + +/* The number of bits available for the user value. */ +#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS) +#define USER_MASK ((1 << USER_BITS) - 1) + +/* EZ alias for ARGP_ERR_UNKNOWN. */ +#define EBADKEY ARGP_ERR_UNKNOWN + +/* Default options. */ + +/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep + for one second intervals, decrementing _ARGP_HANG until it's zero. Thus + you can force the program to continue by attaching a debugger and setting + it to 0 yourself. */ +static volatile int _argp_hang; + +#define OPT_PROGNAME -2 +#define OPT_USAGE -3 +#define OPT_HANG -4 + +static const struct argp_option argp_default_options[] = +{ + {"help", '?', 0, 0, N_("give this help list"), -1}, + {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0}, + {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0}, + {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN, + N_("hang for SECS seconds (default 3600)"), 0}, + {NULL, 0, 0, 0, NULL, 0} +}; + +static error_t +argp_default_parser (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case '?': + __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP); + break; + case OPT_USAGE: + __argp_state_help (state, state->out_stream, + ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); + break; + + case OPT_PROGNAME: /* Set the program name. */ +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME + program_invocation_name = arg; +#endif + /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka + __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined + to be that, so we have to be a bit careful here.] */ + + /* Update what we use for messages. */ + state->name = __argp_base_name (arg); + +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + program_invocation_short_name = state->name; +#endif + + if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) + == ARGP_PARSE_ARGV0) + /* Update what getopt uses too. */ + state->argv[0] = arg; + + break; + + case OPT_HANG: + _argp_hang = atoi (arg ? arg : "3600"); + while (_argp_hang-- > 0) + __sleep (1); + break; + + default: + return EBADKEY; + } + return 0; +} + +static const struct argp argp_default_argp = + {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"}; + + +static const struct argp_option argp_version_options[] = +{ + {"version", 'V', 0, 0, N_("print program version"), -1}, + {NULL, 0, 0, 0, NULL, 0} +}; + +static error_t +argp_version_parser (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case 'V': + if (argp_program_version_hook) + (*argp_program_version_hook) (state->out_stream, state); + else if (argp_program_version) + fprintf (state->out_stream, "%s\n", argp_program_version); + else + __argp_error (state, "%s", + dgettext (state->root_argp->argp_domain, + "(PROGRAM ERROR) No version known!?")); + if (! (state->flags & ARGP_NO_EXIT)) + exit (0); + break; + default: + return EBADKEY; + } + return 0; +} + +static const struct argp argp_version_argp = + {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"}; + +/* Returns the offset into the getopt long options array LONG_OPTIONS of a + long option with called NAME, or -1 if none is found. Passing NULL as + NAME will return the number of options. */ +static int +find_long_option (struct option *long_options, const char *name) +{ + struct option *l = long_options; + while (l->name != NULL) + if (name != NULL && strcmp (l->name, name) == 0) + return l - long_options; + else + l++; + if (name == NULL) + return l - long_options; + else + return -1; +} + + +/* The state of a "group" during parsing. Each group corresponds to a + particular argp structure from the tree of such descending from the top + level argp passed to argp_parse. */ +struct group +{ + /* This group's parsing function. */ + argp_parser_t parser; + + /* Which argp this group is from. */ + const struct argp *argp; + + /* Points to the point in SHORT_OPTS corresponding to the end of the short + options for this group. We use it to determine from which group a + particular short options is from. */ + char *short_end; + + /* The number of non-option args successfully handled by this parser. */ + unsigned args_processed; + + /* This group's parser's parent's group. */ + struct group *parent; + unsigned parent_index; /* And the our position in the parent. */ + + /* These fields are swapped into and out of the state structure when + calling this group's parser. */ + void *input, **child_inputs; + void *hook; +}; + +/* Call GROUP's parser with KEY and ARG, swapping any group-specific info + from STATE before calling, and back into state afterwards. If GROUP has + no parser, EBADKEY is returned. */ +static error_t +group_parse (struct group *group, struct argp_state *state, int key, char *arg) +{ + if (group->parser) + { + error_t err; + state->hook = group->hook; + state->input = group->input; + state->child_inputs = group->child_inputs; + state->arg_num = group->args_processed; + err = (*group->parser)(key, arg, state); + group->hook = state->hook; + return err; + } + else + return EBADKEY; +} + +struct parser +{ + const struct argp *argp; + + /* SHORT_OPTS is the getopt short options string for the union of all the + groups of options. */ + char *short_opts; + /* LONG_OPTS is the array of getop long option structures for the union of + all the groups of options. */ + struct option *long_opts; + /* OPT_DATA is the getopt data used for the re-entrant getopt. */ + struct _getopt_data opt_data; + + /* States of the various parsing groups. */ + struct group *groups; + /* The end of the GROUPS array. */ + struct group *egroup; + /* A vector containing storage for the CHILD_INPUTS field in all groups. */ + void **child_inputs; + + /* True if we think using getopt is still useful; if false, then + remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is + cleared whenever getopt returns KEY_END, but may be set again if the user + moves the next argument pointer backwards. */ + int try_getopt; + + /* State block supplied to parsing routines. */ + struct argp_state state; + + /* Memory used by this parser. */ + void *storage; +}; + +/* The next usable entries in the various parser tables being filled in by + convert_options. */ +struct parser_convert_state +{ + struct parser *parser; + char *short_end; + struct option *long_end; + void **child_inputs_end; +}; + +/* Converts all options in ARGP (which is put in GROUP) and ancestors + into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and + CVT->LONG_END are the points at which new options are added. Returns the + next unused group entry. CVT holds state used during the conversion. */ +static struct group * +convert_options (const struct argp *argp, + struct group *parent, unsigned parent_index, + struct group *group, struct parser_convert_state *cvt) +{ + /* REAL is the most recent non-alias value of OPT. */ + const struct argp_option *real = argp->options; + const struct argp_child *children = argp->children; + + if (real || argp->parser) + { + const struct argp_option *opt; + + if (real) + for (opt = real; !__option_is_end (opt); opt++) + { + if (! (opt->flags & OPTION_ALIAS)) + /* OPT isn't an alias, so we can use values from it. */ + real = opt; + + if (! (real->flags & OPTION_DOC)) + /* A real option (not just documentation). */ + { + if (__option_is_short (opt)) + /* OPT can be used as a short option. */ + { + *cvt->short_end++ = opt->key; + if (real->arg) + { + *cvt->short_end++ = ':'; + if (real->flags & OPTION_ARG_OPTIONAL) + *cvt->short_end++ = ':'; + } + *cvt->short_end = '\0'; /* keep 0 terminated */ + } + + if (opt->name + && find_long_option (cvt->parser->long_opts, opt->name) < 0) + /* OPT can be used as a long option. */ + { + cvt->long_end->name = opt->name; + cvt->long_end->has_arg = + (real->arg + ? (real->flags & OPTION_ARG_OPTIONAL + ? optional_argument + : required_argument) + : no_argument); + cvt->long_end->flag = 0; + /* we add a disambiguating code to all the user's + values (which is removed before we actually call + the function to parse the value); this means that + the user loses use of the high 8 bits in all his + values (the sign of the lower bits is preserved + however)... */ + cvt->long_end->val = + ((opt->key ? opt->key : real->key) & USER_MASK) + + (((group - cvt->parser->groups) + 1) << USER_BITS); + + /* Keep the LONG_OPTS list terminated. */ + (++cvt->long_end)->name = NULL; + } + } + } + + group->parser = argp->parser; + group->argp = argp; + group->short_end = cvt->short_end; + group->args_processed = 0; + group->parent = parent; + group->parent_index = parent_index; + group->input = 0; + group->hook = 0; + group->child_inputs = 0; + + if (children) + /* Assign GROUP's CHILD_INPUTS field some space from + CVT->child_inputs_end.*/ + { + unsigned num_children = 0; + while (children[num_children].argp) + num_children++; + group->child_inputs = cvt->child_inputs_end; + cvt->child_inputs_end += num_children; + } + + parent = group++; + } + else + parent = 0; + + if (children) + { + unsigned index = 0; + while (children->argp) + group = + convert_options (children++->argp, parent, index++, group, cvt); + } + + return group; +} + +/* Find the merged set of getopt options, with keys appropriately prefixed. */ +static void +parser_convert (struct parser *parser, const struct argp *argp, int flags) +{ + struct parser_convert_state cvt; + + cvt.parser = parser; + cvt.short_end = parser->short_opts; + cvt.long_end = parser->long_opts; + cvt.child_inputs_end = parser->child_inputs; + + if (flags & ARGP_IN_ORDER) + *cvt.short_end++ = '-'; + else if (flags & ARGP_NO_ARGS) + *cvt.short_end++ = '+'; + *cvt.short_end = '\0'; + + cvt.long_end->name = NULL; + + parser->argp = argp; + + if (argp) + parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt); + else + parser->egroup = parser->groups; /* No parsers at all! */ +} + +/* Lengths of various parser fields which we will allocated. */ +struct parser_sizes +{ + size_t short_len; /* Getopt short options string. */ + size_t long_len; /* Getopt long options vector. */ + size_t num_groups; /* Group structures we allocate. */ + size_t num_child_inputs; /* Child input slots. */ +}; + +/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of + argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by + the maximum lengths of the resulting merged getopt short options string and + long-options array, respectively. */ +static void +calc_sizes (const struct argp *argp, struct parser_sizes *szs) +{ + const struct argp_child *child = argp->children; + const struct argp_option *opt = argp->options; + + if (opt || argp->parser) + { + szs->num_groups++; + if (opt) + { + int num_opts = 0; + while (!__option_is_end (opt++)) + num_opts++; + szs->short_len += num_opts * 3; /* opt + up to 2 ':'s */ + szs->long_len += num_opts; + } + } + + if (child) + while (child->argp) + { + calc_sizes ((child++)->argp, szs); + szs->num_child_inputs++; + } +} + +/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */ +static error_t +parser_init (struct parser *parser, const struct argp *argp, + int argc, char **argv, int flags, void *input) +{ + error_t err = 0; + struct group *group; + struct parser_sizes szs; + struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER; + char *storage; + size_t glen, gsum; + size_t clen, csum; + size_t llen, lsum; + size_t slen, ssum; + + szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1; + szs.long_len = 0; + szs.num_groups = 0; + szs.num_child_inputs = 0; + + if (argp) + calc_sizes (argp, &szs); + + /* Lengths of the various bits of storage used by PARSER. */ + glen = (szs.num_groups + 1) * sizeof (struct group); + clen = szs.num_child_inputs * sizeof (void *); + llen = (szs.long_len + 1) * sizeof (struct option); + slen = szs.short_len + 1; + + /* Sums of previous lengths, properly aligned. There's no need to + align gsum, since struct group is aligned at least as strictly as + void * (since it contains a void * member). And there's no need + to align lsum, since struct option is aligned at least as + strictly as char. */ + gsum = glen; + csum = alignto (gsum + clen, alignof (struct option)); + lsum = csum + llen; + ssum = lsum + slen; + + parser->storage = malloc (ssum); + if (! parser->storage) + return ENOMEM; + + storage = parser->storage; + parser->groups = parser->storage; + parser->child_inputs = (void **) (storage + gsum); + parser->long_opts = (struct option *) (storage + csum); + parser->short_opts = storage + lsum; + parser->opt_data = opt_data; + + memset (parser->child_inputs, 0, clen); + parser_convert (parser, argp, flags); + + memset (&parser->state, 0, sizeof (struct argp_state)); + parser->state.root_argp = parser->argp; + parser->state.argc = argc; + parser->state.argv = argv; + parser->state.flags = flags; + parser->state.err_stream = stderr; + parser->state.out_stream = stdout; + parser->state.next = 0; /* Tell getopt to initialize. */ + parser->state.pstate = parser; + + parser->try_getopt = 1; + + /* Call each parser for the first time, giving it a chance to propagate + values to child parsers. */ + if (parser->groups < parser->egroup) + parser->groups->input = input; + for (group = parser->groups; + group < parser->egroup && (!err || err == EBADKEY); + group++) + { + if (group->parent) + /* If a child parser, get the initial input value from the parent. */ + group->input = group->parent->child_inputs[group->parent_index]; + + if (!group->parser + && group->argp->children && group->argp->children->argp) + /* For the special case where no parsing function is supplied for an + argp, propagate its input to its first child, if any (this just + makes very simple wrapper argps more convenient). */ + group->child_inputs[0] = group->input; + + err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0); + } + if (err == EBADKEY) + err = 0; /* Some parser didn't understand. */ + + if (err) + return err; + + if (parser->state.flags & ARGP_NO_ERRS) + { + parser->opt_data.opterr = 0; + if (parser->state.flags & ARGP_PARSE_ARGV0) + /* getopt always skips ARGV[0], so we have to fake it out. As long + as OPTERR is 0, then it shouldn't actually try to access it. */ + parser->state.argv--, parser->state.argc++; + } + else + parser->opt_data.opterr = 1; /* Print error messages. */ + + if (parser->state.argv == argv && argv[0]) + /* There's an argv[0]; use it for messages. */ + parser->state.name = __argp_base_name (argv[0]); + else + parser->state.name = __argp_short_program_name (); + + return 0; +} + +/* Free any storage consumed by PARSER (but not PARSER itself). */ +static error_t +parser_finalize (struct parser *parser, + error_t err, int arg_ebadkey, int *end_index) +{ + struct group *group; + + if (err == EBADKEY && arg_ebadkey) + /* Suppress errors generated by unparsed arguments. */ + err = 0; + + if (! err) + { + if (parser->state.next == parser->state.argc) + /* We successfully parsed all arguments! Call all the parsers again, + just a few more times... */ + { + for (group = parser->groups; + group < parser->egroup && (!err || err==EBADKEY); + group++) + if (group->args_processed == 0) + err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); + for (group = parser->egroup - 1; + group >= parser->groups && (!err || err==EBADKEY); + group--) + err = group_parse (group, &parser->state, ARGP_KEY_END, 0); + + if (err == EBADKEY) + err = 0; /* Some parser didn't understand. */ + + /* Tell the user that all arguments are parsed. */ + if (end_index) + *end_index = parser->state.next; + } + else if (end_index) + /* Return any remaining arguments to the user. */ + *end_index = parser->state.next; + else + /* No way to return the remaining arguments, they must be bogus. */ + { + if (!(parser->state.flags & ARGP_NO_ERRS) + && parser->state.err_stream) + fprintf (parser->state.err_stream, + dgettext (parser->argp->argp_domain, + "%s: Too many arguments\n"), + parser->state.name); + err = EBADKEY; + } + } + + /* Okay, we're all done, with either an error or success; call the parsers + to indicate which one. */ + + if (err) + { + /* Maybe print an error message. */ + if (err == EBADKEY) + /* An appropriate message describing what the error was should have + been printed earlier. */ + __argp_state_help (&parser->state, parser->state.err_stream, + ARGP_HELP_STD_ERR); + + /* Since we didn't exit, give each parser an error indication. */ + for (group = parser->groups; group < parser->egroup; group++) + group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); + } + else + /* Notify parsers of success, and propagate back values from parsers. */ + { + /* We pass over the groups in reverse order so that child groups are + given a chance to do there processing before passing back a value to + the parent. */ + for (group = parser->egroup - 1 + ; group >= parser->groups && (!err || err == EBADKEY) + ; group--) + err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); + if (err == EBADKEY) + err = 0; /* Some parser didn't understand. */ + } + + /* Call parsers once more, to do any final cleanup. Errors are ignored. */ + for (group = parser->egroup - 1; group >= parser->groups; group--) + group_parse (group, &parser->state, ARGP_KEY_FINI, 0); + + if (err == EBADKEY) + err = EINVAL; + + free (parser->storage); + + return err; +} + +/* Call the user parsers to parse the non-option argument VAL, at the current + position, returning any error. The state NEXT pointer is assumed to have + been adjusted (by getopt) to point after this argument; this function will + adjust it correctly to reflect however many args actually end up being + consumed. */ +static error_t +parser_parse_arg (struct parser *parser, char *val) +{ + /* Save the starting value of NEXT, first adjusting it so that the arg + we're parsing is again the front of the arg vector. */ + int index = --parser->state.next; + error_t err = EBADKEY; + struct group *group; + int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ + + /* Try to parse the argument in each parser. */ + for (group = parser->groups + ; group < parser->egroup && err == EBADKEY + ; group++) + { + parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ + key = ARGP_KEY_ARG; + err = group_parse (group, &parser->state, key, val); + + if (err == EBADKEY) + /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ + { + parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ + key = ARGP_KEY_ARGS; + err = group_parse (group, &parser->state, key, 0); + } + } + + if (! err) + { + if (key == ARGP_KEY_ARGS) + /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't + changed by the user, *all* arguments should be considered + consumed. */ + parser->state.next = parser->state.argc; + + if (parser->state.next > index) + /* Remember that we successfully processed a non-option + argument -- but only if the user hasn't gotten tricky and set + the clock back. */ + (--group)->args_processed += (parser->state.next - index); + else + /* The user wants to reparse some args, give getopt another try. */ + parser->try_getopt = 1; + } + + return err; +} + +/* Call the user parsers to parse the option OPT, with argument VAL, at the + current position, returning any error. */ +static error_t +parser_parse_opt (struct parser *parser, int opt, char *val) +{ + /* The group key encoded in the high bits; 0 for short opts or + group_number + 1 for long opts. */ + int group_key = opt >> USER_BITS; + error_t err = EBADKEY; + + if (group_key == 0) + /* A short option. By comparing OPT's position in SHORT_OPTS to the + various starting positions in each group's SHORT_END field, we can + determine which group OPT came from. */ + { + struct group *group; + char *short_index = strchr (parser->short_opts, opt); + + if (short_index) + for (group = parser->groups; group < parser->egroup; group++) + if (group->short_end > short_index) + { + err = group_parse (group, &parser->state, opt, + parser->opt_data.optarg); + break; + } + } + else + /* A long option. We use shifts instead of masking for extracting + the user value in order to preserve the sign. */ + err = + group_parse (&parser->groups[group_key - 1], &parser->state, + (opt << GROUP_BITS) >> GROUP_BITS, + parser->opt_data.optarg); + + if (err == EBADKEY) + /* At least currently, an option not recognized is an error in the + parser, because we pre-compute which parser is supposed to deal + with each option. */ + { + static const char bad_key_err[] = + N_("(PROGRAM ERROR) Option should have been recognized!?"); + if (group_key == 0) + __argp_error (&parser->state, "-%c: %s", opt, + dgettext (parser->argp->argp_domain, bad_key_err)); + else + { + struct option *long_opt = parser->long_opts; + while (long_opt->val != opt && long_opt->name) + long_opt++; + __argp_error (&parser->state, "--%s: %s", + long_opt->name ? long_opt->name : "???", + dgettext (parser->argp->argp_domain, bad_key_err)); + } + } + + return err; +} + +/* Parse the next argument in PARSER (as indicated by PARSER->state.next). + Any error from the parsers is returned, and *ARGP_EBADKEY indicates + whether a value of EBADKEY is due to an unrecognized argument (which is + generally not fatal). */ +static error_t +parser_parse_next (struct parser *parser, int *arg_ebadkey) +{ + int opt; + error_t err = 0; + + if (parser->state.quoted && parser->state.next < parser->state.quoted) + /* The next argument pointer has been moved to before the quoted + region, so pretend we never saw the quoting "--", and give getopt + another chance. If the user hasn't removed it, getopt will just + process it again. */ + parser->state.quoted = 0; + + if (parser->try_getopt && !parser->state.quoted) + /* Give getopt a chance to parse this. */ + { + /* Put it back in OPTIND for getopt. */ + parser->opt_data.optind = parser->state.next; + /* Distinguish KEY_ERR from a real option. */ + parser->opt_data.optopt = KEY_END; + if (parser->state.flags & ARGP_LONG_ONLY) + opt = _getopt_long_only_r (parser->state.argc, parser->state.argv, + parser->short_opts, parser->long_opts, 0, + &parser->opt_data); + else + opt = _getopt_long_r (parser->state.argc, parser->state.argv, + parser->short_opts, parser->long_opts, 0, + &parser->opt_data); + /* And see what getopt did. */ + parser->state.next = parser->opt_data.optind; + + if (opt == KEY_END) + /* Getopt says there are no more options, so stop using + getopt; we'll continue if necessary on our own. */ + { + parser->try_getopt = 0; + if (parser->state.next > 1 + && strcmp (parser->state.argv[parser->state.next - 1], QUOTE) + == 0) + /* Not only is this the end of the options, but it's a + "quoted" region, which may have args that *look* like + options, so we definitely shouldn't try to use getopt past + here, whatever happens. */ + parser->state.quoted = parser->state.next; + } + else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END) + /* KEY_ERR can have the same value as a valid user short + option, but in the case of a real error, getopt sets OPTOPT + to the offending character, which can never be KEY_END. */ + { + *arg_ebadkey = 0; + return EBADKEY; + } + } + else + opt = KEY_END; + + if (opt == KEY_END) + { + /* We're past what getopt considers the options. */ + if (parser->state.next >= parser->state.argc + || (parser->state.flags & ARGP_NO_ARGS)) + /* Indicate that we're done. */ + { + *arg_ebadkey = 1; + return EBADKEY; + } + else + /* A non-option arg; simulate what getopt might have done. */ + { + opt = KEY_ARG; + parser->opt_data.optarg = parser->state.argv[parser->state.next++]; + } + } + + if (opt == KEY_ARG) + /* A non-option argument; try each parser in turn. */ + err = parser_parse_arg (parser, parser->opt_data.optarg); + else + err = parser_parse_opt (parser, opt, parser->opt_data.optarg); + + if (err == EBADKEY) + *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG); + + return err; +} + +/* Parse the options strings in ARGC & ARGV according to the argp in ARGP. + FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the + index in ARGV of the first unparsed option is returned in it. If an + unknown option is present, EINVAL is returned; if some parser routine + returned a non-zero value, it is returned; otherwise 0 is returned. */ +error_t +__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, + int *end_index, void *input) +{ + error_t err; + struct parser parser; + + /* If true, then err == EBADKEY is a result of a non-option argument failing + to be parsed (which in some cases isn't actually an error). */ + int arg_ebadkey = 0; + +#ifndef _LIBC + if (!(flags & ARGP_PARSE_ARGV0)) + { +#if HAVE_DECL_PROGRAM_INVOCATION_NAME + if (!program_invocation_name) + program_invocation_name = argv[0]; +#endif +#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + if (!program_invocation_short_name) + program_invocation_short_name = __argp_base_name (argv[0]); +#endif + } +#endif + + if (! (flags & ARGP_NO_HELP)) + /* Add our own options. */ + { + struct argp_child *child = alloca (4 * sizeof (struct argp_child)); + struct argp *top_argp = alloca (sizeof (struct argp)); + + /* TOP_ARGP has no options, it just serves to group the user & default + argps. */ + memset (top_argp, 0, sizeof (*top_argp)); + top_argp->children = child; + + memset (child, 0, 4 * sizeof (struct argp_child)); + + if (argp) + (child++)->argp = argp; + (child++)->argp = &argp_default_argp; + if (argp_program_version || argp_program_version_hook) + (child++)->argp = &argp_version_argp; + child->argp = 0; + + argp = top_argp; + } + + /* Construct a parser for these arguments. */ + err = parser_init (&parser, argp, argc, argv, flags, input); + + if (! err) + /* Parse! */ + { + while (! err) + err = parser_parse_next (&parser, &arg_ebadkey); + err = parser_finalize (&parser, err, arg_ebadkey, end_index); + } + + return err; +} +#ifdef weak_alias +weak_alias (__argp_parse, argp_parse) +#endif + +/* Return the input field for ARGP in the parser corresponding to STATE; used + by the help routines. */ +void * +__argp_input (const struct argp *argp, const struct argp_state *state) +{ + if (state && state->pstate) + { + struct group *group; + struct parser *parser = state->pstate; + + for (group = parser->groups; group < parser->egroup; group++) + if (group->argp == argp) + return group->input; + } + + return 0; +} +#ifdef weak_alias +weak_alias (__argp_input, _argp_input) +#endif diff --git a/grub-core/gnulib/argp-pin.c b/grub-core/gnulib/argp-pin.c new file mode 100644 index 000000000..78cbb355b --- /dev/null +++ b/grub-core/gnulib/argp-pin.c @@ -0,0 +1,26 @@ +/* Full and short program names for argp module + Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME +char *program_invocation_short_name = 0; +#endif +#ifndef HAVE_PROGRAM_INVOCATION_NAME +char *program_invocation_name = 0; +#endif diff --git a/grub-core/gnulib/argp-pv.c b/grub-core/gnulib/argp-pv.c new file mode 100644 index 000000000..c74070d12 --- /dev/null +++ b/grub-core/gnulib/argp-pv.c @@ -0,0 +1,34 @@ +/* Default definition for ARGP_PROGRAM_VERSION. + Copyright (C) 1996-1997, 1999, 2006, 2009-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* If set by the user program to a non-zero value, then a default option + --version is added (unless the ARGP_NO_HELP flag is used), which will + print this string followed by a newline and exit (unless the + ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ +const char *argp_program_version +/* This variable should be zero-initialized. On most systems, putting it into + BSS is sufficient. Not so on Mac OS X 10.3 and 10.4, see + + . */ +#if defined __ELF__ + /* On ELF systems, variables in BSS behave well. */ +#else + = (const char *) 0 +#endif + ; diff --git a/grub-core/gnulib/argp-pvh.c b/grub-core/gnulib/argp-pvh.c new file mode 100644 index 000000000..885ff4b75 --- /dev/null +++ b/grub-core/gnulib/argp-pvh.c @@ -0,0 +1,31 @@ +/* Default definition for ARGP_PROGRAM_VERSION_HOOK. + Copyright (C) 1996-1997, 1999, 2004, 2009-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "argp.h" + +/* If set by the user program to a non-zero value, then a default option + --version is added (unless the ARGP_NO_HELP flag is used), which calls + this function with a stream to print the version to and a pointer to the + current parsing state, and then exits (unless the ARGP_NO_EXIT flag is + used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ +void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = NULL; diff --git a/grub-core/gnulib/argp-xinl.c b/grub-core/gnulib/argp-xinl.c new file mode 100644 index 000000000..04d8cf703 --- /dev/null +++ b/grub-core/gnulib/argp-xinl.c @@ -0,0 +1,46 @@ +/* Real definitions for extern inline functions in argp.h + Copyright (C) 1997-1998, 2004, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if defined _LIBC || defined HAVE_FEATURES_H +# include +#endif + +#ifndef __USE_EXTERN_INLINES +# define __USE_EXTERN_INLINES 1 +#endif +#ifdef _LIBC +# define ARGP_EI +#else +# define ARGP_EI _GL_EXTERN_INLINE +#endif +#undef __OPTIMIZE__ +#define __OPTIMIZE__ 1 +#include "argp.h" + +/* Add weak aliases. */ +#if _LIBC - 0 && defined (weak_alias) + +weak_alias (__argp_usage, argp_usage) +weak_alias (__option_is_short, _option_is_short) +weak_alias (__option_is_end, _option_is_end) + +#endif diff --git a/grub-core/gnulib/argp.h b/grub-core/gnulib/argp.h new file mode 100644 index 000000000..c4094a40c --- /dev/null +++ b/grub-core/gnulib/argp.h @@ -0,0 +1,650 @@ +/* Hierarchical argument parsing, layered over getopt. + Copyright (C) 1995-1999, 2003-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Miles Bader . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _ARGP_H +#define _ARGP_H + +#include +#include +#include +#include + +#define __need_error_t +#include + +#ifndef __THROW +# define __THROW +#endif +#ifndef __NTH +# define __NTH(fct) fct __THROW +#endif + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +/* GCC 2.95 and later have "__restrict"; C99 compilers have + "restrict", and "configure" may have defined "restrict". + Other compilers use __restrict, __restrict__, and _Restrict, and + 'configure' might #define 'restrict' to those words. */ +#ifndef __restrict +# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) +# if 199901L <= __STDC_VERSION__ +# define __restrict restrict +# else +# define __restrict +# endif +# endif +#endif + +#ifndef __error_t_defined +typedef int error_t; +# define __error_t_defined +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* A description of a particular option. A pointer to an array of + these is passed in the OPTIONS field of an argp structure. Each option + entry can correspond to one long option and/or one short option; more + names for the same option can be added by following an entry in an option + array with options having the OPTION_ALIAS flag set. */ +struct argp_option +{ + /* The long option name. For more than one name for the same option, you + can use following options with the OPTION_ALIAS flag set. */ + const char *name; + + /* What key is returned for this option. If > 0 and printable, then it's + also accepted as a short option. */ + int key; + + /* If non-NULL, this is the name of the argument associated with this + option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */ + const char *arg; + + /* OPTION_ flags. */ + int flags; + + /* The doc string for this option. If both NAME and KEY are 0, This string + will be printed outdented from the normal option column, making it + useful as a group header (it will be the first thing printed in its + group); in this usage, it's conventional to end the string with a ':'. + + Write the initial value as N_("TEXT") if you want xgettext to collect + it into a POT file. */ + const char *doc; + + /* The group this option is in. In a long help message, options are sorted + alphabetically within each group, and the groups presented in the order + 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with + if this field 0 will inherit the group number of the previous entry, or + zero if it's the first one, unless its a group header (NAME and KEY both + 0), in which case, the previous entry + 1 is the default. Automagic + options such as --help are put into group -1. */ + int group; +}; + +/* The argument associated with this option is optional. */ +#define OPTION_ARG_OPTIONAL 0x1 + +/* This option isn't displayed in any help messages. */ +#define OPTION_HIDDEN 0x2 + +/* This option is an alias for the closest previous non-alias option. This + means that it will be displayed in the same help entry, and will inherit + fields other than NAME and KEY from the aliased option. */ +#define OPTION_ALIAS 0x4 + +/* This option isn't actually an option (and so should be ignored by the + actual option parser), but rather an arbitrary piece of documentation that + should be displayed in much the same manner as the options. If this flag + is set, then the option NAME field is displayed unmodified (e.g., no '--' + prefix is added) at the left-margin (where a *short* option would normally + be displayed), and the documentation string in the normal place. The NAME + field will be translated using gettext, unless OPTION_NO_TRANS is set (see + below). For purposes of sorting, any leading whitespace and punctuation is + ignored, except that if the first non-whitespace character is not '-', this + entry is displayed after all options (and OPTION_DOC entries with a leading + '-') in the same group. */ +#define OPTION_DOC 0x8 + +/* This option shouldn't be included in "long" usage messages (but is still + included in help messages). This is mainly intended for options that are + completely documented in an argp's ARGS_DOC field, in which case including + the option in the generic usage list would be redundant. For instance, + if ARGS_DOC is "FOO BAR\n-x BLAH", and the '-x' option's purpose is to + distinguish these two cases, -x should probably be marked + OPTION_NO_USAGE. */ +#define OPTION_NO_USAGE 0x10 + +/* Valid only in conjunction with OPTION_DOC. This option disables translation + of option name. */ +#define OPTION_NO_TRANS 0x20 + + +struct argp; /* fwd declare this type */ +struct argp_state; /* " */ +struct argp_child; /* " */ + +/* The type of a pointer to an argp parsing function. */ +typedef error_t (*argp_parser_t) (int key, char *arg, + struct argp_state *state); + +/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such + returns will simply be ignored. For user keys, this error will be turned + into EINVAL (if the call to argp_parse is such that errors are propagated + back to the user instead of exiting); returning EINVAL itself would result + in an immediate stop to parsing in *all* cases. */ +#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ + +/* Special values for the KEY argument to an argument parsing function. + ARGP_ERR_UNKNOWN should be returned if they aren't understood. + + The sequence of keys to a parsing function is either (where each + uppercased word should be prefixed by 'ARGP_KEY_' and opt is a user key): + + INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all + or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed + or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized + + The third case is where every parser returned ARGP_KEY_UNKNOWN for an + argument, in which case parsing stops at that argument (returning the + unparsed arguments to the caller of argp_parse if requested, or stopping + with an error message if not). + + If an error occurs (either detected by argp, or because the parsing + function returned an error value), then the parser is called with + ARGP_KEY_ERROR, and no further calls are made. */ + +/* This is not an option at all, but rather a command line argument. If a + parser receiving this key returns success, the fact is recorded, and the + ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the + argument, a parser function decrements the NEXT field of the state it's + passed, the option won't be considered processed; this is to allow you to + actually modify the argument (perhaps into an option), and have it + processed again. */ +#define ARGP_KEY_ARG 0 +/* There are remaining arguments not parsed by any parser, which may be found + starting at (STATE->argv + STATE->next). If success is returned, but + STATE->next left untouched, it's assumed that all arguments were consume, + otherwise, the parser should adjust STATE->next to reflect any arguments + consumed. */ +#define ARGP_KEY_ARGS 0x1000006 +/* There are no more command line arguments at all. */ +#define ARGP_KEY_END 0x1000001 +/* Because it's common to want to do some special processing if there aren't + any non-option args, user parsers are called with this key if they didn't + successfully process any non-option arguments. Called just before + ARGP_KEY_END (where more general validity checks on previously parsed + arguments can take place). */ +#define ARGP_KEY_NO_ARGS 0x1000002 +/* Passed in before any parsing is done. Afterwards, the values of each + element of the CHILD_INPUT field, if any, in the state structure is + copied to each child's state to be the initial value of the INPUT field. */ +#define ARGP_KEY_INIT 0x1000003 +/* Use after all other keys, including SUCCESS & END. */ +#define ARGP_KEY_FINI 0x1000007 +/* Passed in when parsing has successfully been completed (even if there are + still arguments remaining). */ +#define ARGP_KEY_SUCCESS 0x1000004 +/* Passed in if an error occurs. */ +#define ARGP_KEY_ERROR 0x1000005 + +/* An argp structure contains a set of options declarations, a function to + deal with parsing one, documentation string, a possible vector of child + argp's, and perhaps a function to filter help output. When actually + parsing options, getopt is called with the union of all the argp + structures chained together through their CHILD pointers, with conflicts + being resolved in favor of the first occurrence in the chain. */ +struct argp +{ + /* An array of argp_option structures, terminated by an entry with both + NAME and KEY having a value of 0. */ + const struct argp_option *options; + + /* What to do with an option from this structure. KEY is the key + associated with the option, and ARG is any associated argument (NULL if + none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be + returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then + parsing is stopped immediately, and that value is returned from + argp_parse(). For special (non-user-supplied) values of KEY, see the + ARGP_KEY_ definitions below. */ + argp_parser_t parser; + + /* A string describing what other arguments are wanted by this program. It + is only used by argp_usage to print the "Usage:" message. If it + contains newlines, the strings separated by them are considered + alternative usage patterns, and printed on separate lines (lines after + the first are prefix by " or: " instead of "Usage:"). */ + const char *args_doc; + + /* If non-NULL, a string containing extra text to be printed before and + after the options in a long help message (separated by a vertical tab + '\v' character). + Write the initial value as N_("BEFORE-TEXT") "\v" N_("AFTER-TEXT") if + you want xgettext to collect the two pieces of text into a POT file. */ + const char *doc; + + /* A vector of argp_children structures, terminated by a member with a 0 + argp field, pointing to child argps should be parsed with this one. Any + conflicts are resolved in favor of this argp, or early argps in the + CHILDREN list. This field is useful if you use libraries that supply + their own argp structure, which you want to use in conjunction with your + own. */ + const struct argp_child *children; + + /* If non-zero, this should be a function to filter the output of help + messages. KEY is either a key from an option, in which case TEXT is + that option's help text, or a special key from the ARGP_KEY_HELP_ + defines, below, describing which other help text TEXT is. The function + should return either TEXT, if it should be used as-is, a replacement + string, which should be malloced, and will be freed by argp, or NULL, + meaning "print nothing". The value for TEXT is *after* any translation + has been done, so if any of the replacement text also needs translation, + that should be done by the filter function. INPUT is either the input + supplied to argp_parse, or NULL, if argp_help was called directly. */ + char *(*help_filter) (int __key, const char *__text, void *__input); + + /* If non-zero the strings used in the argp library are translated using + the domain described by this string. Otherwise the currently installed + default domain is used. */ + const char *argp_domain; +}; + +/* Possible KEY arguments to a help filter function. */ +#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceding options. */ +#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ +#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ +#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; + TEXT is NULL for this key. */ +/* Explanatory note emitted when duplicate option arguments have been + suppressed. */ +#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 +#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ + +/* When an argp has a non-zero CHILDREN field, it should point to a vector of + argp_child structures, each of which describes a subsidiary argp. */ +struct argp_child +{ + /* The child parser. */ + const struct argp *argp; + + /* Flags for this child. */ + int flags; + + /* If non-zero, an optional header to be printed in help output before the + child options. As a side-effect, a non-zero value forces the child + options to be grouped together; to achieve this effect without actually + printing a header string, use a value of "". */ + const char *header; + + /* Where to group the child options relative to the other ("consolidated") + options in the parent argp; the values are the same as the GROUP field + in argp_option structs, but all child-groupings follow parent options at + a particular group level. If both this field and HEADER are zero, then + they aren't grouped at all, but rather merged with the parent options + (merging the child's grouping levels with the parents). */ + int group; +}; + +/* Parsing state. This is provided to parsing functions called by argp, + which may examine and, as noted, modify fields. */ +struct argp_state +{ + /* The top level ARGP being parsed. */ + const struct argp *root_argp; + + /* The argument vector being parsed. May be modified. */ + int argc; + char **argv; + + /* The index in ARGV of the next arg that to be parsed. May be modified. */ + int next; + + /* The flags supplied to argp_parse. May be modified. */ + unsigned flags; + + /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the + number of the current arg, starting at zero, and incremented after each + such call returns. At all other times, this is the number of such + arguments that have been processed. */ + unsigned arg_num; + + /* If non-zero, the index in ARGV of the first argument following a special + '--' argument (which prevents anything following being interpreted as an + option). Only set once argument parsing has proceeded past this point. */ + int quoted; + + /* An arbitrary pointer passed in from the user. */ + void *input; + /* Values to pass to child parsers. This vector will be the same length as + the number of children for the current parser. */ + void **child_inputs; + + /* For the parser's use. Initialized to 0. */ + void *hook; + + /* The name used when printing messages. This is initialized to ARGV[0], + or PROGRAM_INVOCATION_NAME if that is unavailable. */ + char *name; + + /* Streams used when argp prints something. */ + FILE *err_stream; /* For errors; initialized to stderr. */ + FILE *out_stream; /* For information; initialized to stdout. */ + + void *pstate; /* Private, for use by argp. */ +}; + +/* Flags for argp_parse (note that the defaults are those that are + convenient for program command line parsing): */ + +/* Don't ignore the first element of ARGV. Normally (and always unless + ARGP_NO_ERRS is set) the first element of the argument vector is + skipped for option parsing purposes, as it corresponds to the program name + in a command line. */ +#define ARGP_PARSE_ARGV0 0x01 + +/* Don't print error messages for unknown options to stderr; unless this flag + is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program + name in the error messages. This flag implies ARGP_NO_EXIT (on the + assumption that silent exiting upon errors is bad behaviour). */ +#define ARGP_NO_ERRS 0x02 + +/* Don't parse any non-option args. Normally non-option args are parsed by + calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg + as the value. Since it's impossible to know which parse function wants to + handle it, each one is called in turn, until one returns 0 or an error + other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the + argp_parse returns prematurely (but with a return value of 0). If all + args have been parsed without error, all parsing functions are called one + last time with a key of ARGP_KEY_END. This flag needn't normally be set, + as the normal behavior is to stop parsing as soon as some argument can't + be handled. */ +#define ARGP_NO_ARGS 0x04 + +/* Parse options and arguments in the same order they occur on the command + line -- normally they're rearranged so that all options come first. */ +#define ARGP_IN_ORDER 0x08 + +/* Don't provide the standard long option --help, which causes usage and + option help information to be output to stdout, and exit (0) called. */ +#define ARGP_NO_HELP 0x10 + +/* Don't exit on errors (they may still result in error messages). */ +#define ARGP_NO_EXIT 0x20 + +/* Use the gnu getopt "long-only" rules for parsing arguments. */ +#define ARGP_LONG_ONLY 0x40 + +/* Turns off any message-printing/exiting options. */ +#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) + +/* Parse the options strings in ARGC & ARGV according to the options in ARGP. + FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the + index in ARGV of the first unparsed option is returned in it. If an + unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser + routine returned a non-zero value, it is returned; otherwise 0 is + returned. This function may also call exit unless the ARGP_NO_HELP flag + is set. INPUT is a pointer to a value to be passed in to the parser. */ +extern error_t argp_parse (const struct argp *__restrict __argp, + int /*argc*/, char **__restrict /*argv*/, + unsigned __flags, int *__restrict __arg_index, + void *__restrict __input); +extern error_t __argp_parse (const struct argp *__restrict __argp, + int /*argc*/, char **__restrict /*argv*/, + unsigned __flags, int *__restrict __arg_index, + void *__restrict __input); + +/* Global variables. */ + +/* GNULIB makes sure both program_invocation_name and + program_invocation_short_name are available */ +#ifdef GNULIB_PROGRAM_INVOCATION_NAME +extern char *program_invocation_name; +# undef HAVE_DECL_PROGRAM_INVOCATION_NAME +# define HAVE_DECL_PROGRAM_INVOCATION_NAME 1 +#endif + +#ifdef GNULIB_PROGRAM_INVOCATION_SHORT_NAME +extern char *program_invocation_short_name; +# undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME +# define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1 +#endif + +/* If defined or set by the user program to a non-zero value, then a default + option --version is added (unless the ARGP_NO_HELP flag is used), which + will print this string followed by a newline and exit (unless the + ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ +extern const char *argp_program_version; + +/* If defined or set by the user program to a non-zero value, then a default + option --version is added (unless the ARGP_NO_HELP flag is used), which + calls this function with a stream to print the version to and a pointer to + the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is + used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ +extern void (*argp_program_version_hook) (FILE *__restrict __stream, + struct argp_state *__restrict + __state); + +/* If defined or set by the user program, it should point to string that is + the bug-reporting address for the program. It will be printed by + argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various + standard help messages), embedded in a sentence that says something like + "Report bugs to ADDR." */ +extern const char *argp_program_bug_address; + +/* The exit status that argp will use when exiting due to a parsing error. + If not defined or set by the user program, this defaults to EX_USAGE from + . */ +extern error_t argp_err_exit_status; + +/* Flags for argp_help. */ +#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ +#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ +#define ARGP_HELP_SEE 0x04 /* a "Try ... for more help" message. */ +#define ARGP_HELP_LONG 0x08 /* a long help message. */ +#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ +#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ +#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) +#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ +#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to + reflect ARGP_LONG_ONLY mode. */ + +/* These ARGP_HELP flags are only understood by argp_state_help. */ +#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ +#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ + +/* The standard thing to do after a program command line parsing error, if an + error message has already been printed. */ +#define ARGP_HELP_STD_ERR \ + (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) +/* The standard thing to do after a program command line parsing error, if no + more specific error message has been printed. */ +#define ARGP_HELP_STD_USAGE \ + (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) +/* The standard thing to do in response to a --help option. */ +#define ARGP_HELP_STD_HELP \ + (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ + | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR) + +/* Output a usage message for ARGP to STREAM. FLAGS are from the set + ARGP_HELP_*. */ +extern void argp_help (const struct argp *__restrict __argp, + FILE *__restrict __stream, + unsigned __flags, char *__restrict __name); +extern void __argp_help (const struct argp *__restrict __argp, + FILE *__restrict __stream, unsigned __flags, + char *__name); + +/* The following routines are intended to be called from within an argp + parsing routine (thus taking an argp_state structure as the first + argument). They may or may not print an error message and exit, depending + on the flags in STATE -- in any case, the caller should be prepared for + them *not* to exit, and should return an appropriate error after calling + them. [argp_usage & argp_error should probably be called argp_state_..., + but they're used often enough that they should be short] */ + +/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are + from the set ARGP_HELP_*. */ +extern void argp_state_help (const struct argp_state *__restrict __state, + FILE *__restrict __stream, + unsigned int __flags); +extern void __argp_state_help (const struct argp_state *__restrict __state, + FILE *__restrict __stream, + unsigned int __flags); + +#if _LIBC +/* Possibly output the standard usage message for ARGP to stderr and exit. */ +extern void argp_usage (const struct argp_state *__state); +extern void __argp_usage (const struct argp_state *__state); +#endif + +/* If appropriate, print the printf string FMT and following args, preceded + by the program name and ':', to stderr, and followed by a "Try ... --help" + message, then exit (1). */ +extern void argp_error (const struct argp_state *__restrict __state, + const char *__restrict __fmt, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); +extern void __argp_error (const struct argp_state *__restrict __state, + const char *__restrict __fmt, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); + +/* Similar to the standard gnu error-reporting function error(), but will + respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print + to STATE->err_stream. This is useful for argument parsing code that is + shared between program startup (when exiting is desired) and runtime + option parsing (when typically an error code is returned instead). The + difference between this function and argp_error is that the latter is for + *parsing errors*, and the former is for other problems that occur during + parsing but don't reflect a (syntactic) problem with the input. */ +extern void argp_failure (const struct argp_state *__restrict __state, + int __status, int __errnum, + const char *__restrict __fmt, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); +extern void __argp_failure (const struct argp_state *__restrict __state, + int __status, int __errnum, + const char *__restrict __fmt, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); + +#if _LIBC +/* Returns true if the option OPT is a valid short option. */ +extern int _option_is_short (const struct argp_option *__opt) __THROW; +extern int __option_is_short (const struct argp_option *__opt) __THROW; + +/* Returns true if the option OPT is in fact the last (unused) entry in an + options array. */ +extern int _option_is_end (const struct argp_option *__opt) __THROW; +extern int __option_is_end (const struct argp_option *__opt) __THROW; +#endif + +/* Return the input field for ARGP in the parser corresponding to STATE; used + by the help routines. */ +extern void *_argp_input (const struct argp *__restrict __argp, + const struct argp_state *__restrict __state) + __THROW; +extern void *__argp_input (const struct argp *__restrict __argp, + const struct argp_state *__restrict __state) + __THROW; + +#if !_LIBC || defined __USE_EXTERN_INLINES + +# if !_LIBC +# define __argp_usage argp_usage +# define __argp_state_help argp_state_help +# define __option_is_short _option_is_short +# define __option_is_end _option_is_end +_GL_INLINE_HEADER_BEGIN +# ifndef ARGP_EI +# define ARGP_EI _GL_INLINE +# endif +# endif + +# ifndef ARGP_EI +# ifdef __GNUC__ + /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. It defines a macro + __GNUC_STDC_INLINE__ to indicate this situation or a macro + __GNUC_GNU_INLINE__ to indicate the opposite situation. + GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline + semantics but warns, unless -fgnu89-inline is used: + warning: C99 inline functions are not supported; using GNU89 + warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute + It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. */ +# if defined __GNUC_STDC_INLINE__ +# define ARGP_EI __inline__ +# elif defined __GNUC_GNU_INLINE__ +# define ARGP_EI extern __inline__ __attribute__ ((__gnu_inline__)) +# else +# define ARGP_EI extern __inline__ +# endif +# else + /* With other compilers, assume the ISO C99 meaning of 'inline', if + the compiler supports 'inline' at all. */ +# define ARGP_EI inline +# endif +# endif + +ARGP_EI void +__argp_usage (const struct argp_state *__state) +{ + __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); +} + +ARGP_EI int +__NTH (__option_is_short (const struct argp_option *__opt)) +{ + if (__opt->flags & OPTION_DOC) + return 0; + else + { + int __key = __opt->key; + return __key > 0 && __key <= UCHAR_MAX && isprint (__key); + } +} + +ARGP_EI int +__NTH (__option_is_end (const struct argp_option *__opt)) +{ + return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; +} + +# if !_LIBC +# undef __argp_usage +# undef __argp_state_help +# undef __option_is_short +# undef __option_is_end +_GL_INLINE_HEADER_END +# endif +#endif /* Use extern inlines. */ + +#ifdef __cplusplus +} +#endif + +#endif /* argp.h */ diff --git a/grub-core/gnulib/asnprintf.c b/grub-core/gnulib/asnprintf.c new file mode 100644 index 000000000..76e228d86 --- /dev/null +++ b/grub-core/gnulib/asnprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#include + +/* Specification. */ +#include "vasnprintf.h" + +#include + +char * +asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +{ + va_list args; + char *result; + + va_start (args, format); + result = vasnprintf (resultbuf, lengthp, format, args); + va_end (args); + return result; +} diff --git a/grub-core/gnulib/basename-lgpl.c b/grub-core/gnulib/basename-lgpl.c new file mode 100644 index 000000000..9307e8314 --- /dev/null +++ b/grub-core/gnulib/basename-lgpl.c @@ -0,0 +1,75 @@ +/* basename.c -- return the last element in a file name + + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include "dirname.h" + +#include + +/* Return the address of the last file name component of NAME. If + NAME has no relative file name components because it is a file + system root, return the empty string. */ + +char * +last_component (char const *name) +{ + char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); + char const *p; + bool saw_slash = false; + + while (ISSLASH (*base)) + base++; + + for (p = base; *p; p++) + { + if (ISSLASH (*p)) + saw_slash = true; + else if (saw_slash) + { + base = p; + saw_slash = false; + } + } + + return (char *) base; +} + +/* Return the length of the basename NAME. Typically NAME is the + value returned by base_name or last_component. Act like strlen + (NAME), except omit all trailing slashes. */ + +size_t +base_len (char const *name) +{ + size_t len; + size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); + + for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) + continue; + + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1 + && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2]) + return 2; + + if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len + && len == prefix_len && ISSLASH (name[prefix_len])) + return prefix_len + 1; + + return len; +} diff --git a/grub-core/gnulib/btowc.c b/grub-core/gnulib/btowc.c new file mode 100644 index 000000000..6c7cbec9d --- /dev/null +++ b/grub-core/gnulib/btowc.c @@ -0,0 +1,39 @@ +/* Convert unibyte character to wide character. + Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include + +wint_t +btowc (int c) +{ + if (c != EOF) + { + char buf[1]; + wchar_t wc; + + buf[0] = c; + if (mbtowc (&wc, buf, 1) >= 0) + return wc; + } + return WEOF; +} diff --git a/grub-core/gnulib/config.charset b/grub-core/gnulib/config.charset new file mode 100644 index 000000000..a991419cd --- /dev/null +++ b/grub-core/gnulib/config.charset @@ -0,0 +1,684 @@ +#! /bin/sh +# Output a system dependent table of character encoding aliases. +# +# Copyright (C) 2000-2004, 2006-2013 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see . +# +# The table consists of lines of the form +# ALIAS CANONICAL +# +# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)". +# ALIAS is compared in a case sensitive way. +# +# CANONICAL is the GNU canonical name for this character encoding. +# It must be an encoding supported by libiconv. Support by GNU libc is +# also desirable. CANONICAL is case insensitive. Usually an upper case +# MIME charset name is preferred. +# The current list of GNU canonical charset names is as follows. +# +# name MIME? used by which systems +# (darwin = Mac OS X, woe32 = native Windows) +# +# ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin cygwin +# ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin +# ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin +# ISO-8859-3 Y glibc solaris cygwin +# ISO-8859-4 Y osf solaris freebsd netbsd openbsd darwin +# ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin +# ISO-8859-6 Y glibc aix hpux solaris cygwin +# ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd openbsd darwin cygwin +# ISO-8859-8 Y glibc aix hpux osf solaris cygwin +# ISO-8859-9 Y glibc aix hpux irix osf solaris darwin cygwin +# ISO-8859-13 glibc netbsd openbsd darwin cygwin +# ISO-8859-14 glibc cygwin +# ISO-8859-15 glibc aix osf solaris freebsd netbsd openbsd darwin cygwin +# KOI8-R Y glibc solaris freebsd netbsd openbsd darwin +# KOI8-U Y glibc freebsd netbsd openbsd darwin cygwin +# KOI8-T glibc +# CP437 dos +# CP775 dos +# CP850 aix osf dos +# CP852 dos +# CP855 dos +# CP856 aix +# CP857 dos +# CP861 dos +# CP862 dos +# CP864 dos +# CP865 dos +# CP866 freebsd netbsd openbsd darwin dos +# CP869 dos +# CP874 woe32 dos +# CP922 aix +# CP932 aix cygwin woe32 dos +# CP943 aix +# CP949 osf darwin woe32 dos +# CP950 woe32 dos +# CP1046 aix +# CP1124 aix +# CP1125 dos +# CP1129 aix +# CP1131 darwin +# CP1250 woe32 +# CP1251 glibc solaris netbsd openbsd darwin cygwin woe32 +# CP1252 aix woe32 +# CP1253 woe32 +# CP1254 woe32 +# CP1255 glibc woe32 +# CP1256 woe32 +# CP1257 woe32 +# GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin +# EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin +# EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin +# EUC-TW glibc aix hpux irix osf solaris netbsd +# BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin +# BIG5-HKSCS glibc solaris darwin +# GBK glibc aix osf solaris darwin cygwin woe32 dos +# GB18030 glibc solaris netbsd darwin +# SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin +# JOHAB glibc solaris woe32 +# TIS-620 glibc aix hpux osf solaris cygwin +# VISCII Y glibc +# TCVN5712-1 glibc +# ARMSCII-8 glibc darwin +# GEORGIAN-PS glibc cygwin +# PT154 glibc +# HP-ROMAN8 hpux +# HP-ARABIC8 hpux +# HP-GREEK8 hpux +# HP-HEBREW8 hpux +# HP-TURKISH8 hpux +# HP-KANA8 hpux +# DEC-KANJI osf +# DEC-HANYU osf +# UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin +# +# Note: Names which are not marked as being a MIME name should not be used in +# Internet protocols for information interchange (mail, news, etc.). +# +# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications +# must understand both names and treat them as equivalent. +# +# The first argument passed to this file is the canonical host specification, +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM + +host="$1" +os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'` +echo "# This file contains a table of character encoding aliases," +echo "# suitable for operating system '${os}'." +echo "# It was automatically generated from config.charset." +# List of references, updated during installation: +echo "# Packages using this file: " +case "$os" in + linux-gnulibc1*) + # Linux libc5 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "C ASCII" + echo "POSIX ASCII" + for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ + en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ + en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ + es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ + et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ + fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ + it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ + sv_FI sv_SE; do + echo "$l ISO-8859-1" + echo "$l.iso-8859-1 ISO-8859-1" + echo "$l.iso-8859-15 ISO-8859-15" + echo "$l.iso-8859-15@euro ISO-8859-15" + echo "$l@euro ISO-8859-15" + echo "$l.cp-437 CP437" + echo "$l.cp-850 CP850" + echo "$l.cp-1252 CP1252" + echo "$l.cp-1252@euro CP1252" + #echo "$l.atari-st ATARI-ST" # not a commonly used encoding + echo "$l.utf-8 UTF-8" + echo "$l.utf-8@euro UTF-8" + done + for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ + sl_SI sr sr_CS sr_YU; do + echo "$l ISO-8859-2" + echo "$l.iso-8859-2 ISO-8859-2" + echo "$l.cp-852 CP852" + echo "$l.cp-1250 CP1250" + echo "$l.utf-8 UTF-8" + done + for l in mk mk_MK ru ru_RU; do + echo "$l ISO-8859-5" + echo "$l.iso-8859-5 ISO-8859-5" + echo "$l.koi8-r KOI8-R" + echo "$l.cp-866 CP866" + echo "$l.cp-1251 CP1251" + echo "$l.utf-8 UTF-8" + done + for l in ar ar_SA; do + echo "$l ISO-8859-6" + echo "$l.iso-8859-6 ISO-8859-6" + echo "$l.cp-864 CP864" + #echo "$l.cp-868 CP868" # not a commonly used encoding + echo "$l.cp-1256 CP1256" + echo "$l.utf-8 UTF-8" + done + for l in el el_GR gr gr_GR; do + echo "$l ISO-8859-7" + echo "$l.iso-8859-7 ISO-8859-7" + echo "$l.cp-869 CP869" + echo "$l.cp-1253 CP1253" + echo "$l.cp-1253@euro CP1253" + echo "$l.utf-8 UTF-8" + echo "$l.utf-8@euro UTF-8" + done + for l in he he_IL iw iw_IL; do + echo "$l ISO-8859-8" + echo "$l.iso-8859-8 ISO-8859-8" + echo "$l.cp-862 CP862" + echo "$l.cp-1255 CP1255" + echo "$l.utf-8 UTF-8" + done + for l in tr tr_TR; do + echo "$l ISO-8859-9" + echo "$l.iso-8859-9 ISO-8859-9" + echo "$l.cp-857 CP857" + echo "$l.cp-1254 CP1254" + echo "$l.utf-8 UTF-8" + done + for l in lt lt_LT lv lv_LV; do + #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name + echo "$l ISO-8859-13" + done + for l in ru_UA uk uk_UA; do + echo "$l KOI8-U" + done + for l in zh zh_CN; do + #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name + echo "$l GB2312" + done + for l in ja ja_JP ja_JP.EUC; do + echo "$l EUC-JP" + done + for l in ko ko_KR; do + echo "$l EUC-KR" + done + for l in th th_TH; do + echo "$l TIS-620" + done + for l in fa fa_IR; do + #echo "$l ISIRI-3342" # a broken encoding + echo "$l.utf-8 UTF-8" + done + ;; + linux* | *-gnu*) + # With glibc-2.1 or newer, we don't need any canonicalization, + # because glibc has iconv and both glibc and libiconv support all + # GNU canonical names directly. Therefore, the Makefile does not + # need to install the alias file at all. + # The following applies only to glibc-2.0.x and older libcs. + echo "ISO_646.IRV:1983 ASCII" + ;; + aix*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-6 ISO-8859-6" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "IBM-850 CP850" + echo "IBM-856 CP856" + echo "IBM-921 ISO-8859-13" + echo "IBM-922 CP922" + echo "IBM-932 CP932" + echo "IBM-943 CP943" + echo "IBM-1046 CP1046" + echo "IBM-1124 CP1124" + echo "IBM-1129 CP1129" + echo "IBM-1252 CP1252" + echo "IBM-eucCN GB2312" + echo "IBM-eucJP EUC-JP" + echo "IBM-eucKR EUC-KR" + echo "IBM-eucTW EUC-TW" + echo "big5 BIG5" + echo "GBK GBK" + echo "TIS-620 TIS-620" + echo "UTF-8 UTF-8" + ;; + hpux*) + echo "iso88591 ISO-8859-1" + echo "iso88592 ISO-8859-2" + echo "iso88595 ISO-8859-5" + echo "iso88596 ISO-8859-6" + echo "iso88597 ISO-8859-7" + echo "iso88598 ISO-8859-8" + echo "iso88599 ISO-8859-9" + echo "iso885915 ISO-8859-15" + echo "roman8 HP-ROMAN8" + echo "arabic8 HP-ARABIC8" + echo "greek8 HP-GREEK8" + echo "hebrew8 HP-HEBREW8" + echo "turkish8 HP-TURKISH8" + echo "kana8 HP-KANA8" + echo "tis620 TIS-620" + echo "big5 BIG5" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "hp15CN GB2312" + #echo "ccdc ?" # what is this? + echo "SJIS SHIFT_JIS" + echo "utf8 UTF-8" + ;; + irix*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-9 ISO-8859-9" + echo "eucCN GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + ;; + osf*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "cp850 CP850" + echo "big5 BIG5" + echo "dechanyu DEC-HANYU" + echo "dechanzi GB2312" + echo "deckanji DEC-KANJI" + echo "deckorean EUC-KR" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "GBK GBK" + echo "KSC5601 CP949" + echo "sdeckanji EUC-JP" + echo "SJIS SHIFT_JIS" + echo "TACTIS TIS-620" + echo "UTF-8 UTF-8" + ;; + solaris*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-3 ISO-8859-3" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-6 ISO-8859-6" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "koi8-r KOI8-R" + echo "ansi-1251 CP1251" + echo "BIG5 BIG5" + echo "Big5-HKSCS BIG5-HKSCS" + echo "gb2312 GB2312" + echo "GBK GBK" + echo "GB18030 GB18030" + echo "cns11643 EUC-TW" + echo "5601 EUC-KR" + echo "ko_KR.johap92 JOHAB" + echo "eucJP EUC-JP" + echo "PCK SHIFT_JIS" + echo "TIS620.2533 TIS-620" + #echo "sun_eu_greek ?" # what is this? + echo "UTF-8 UTF-8" + ;; + freebsd* | os2*) + # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just + # reuse FreeBSD's locale data for OS/2. + echo "C ASCII" + echo "US-ASCII ASCII" + for l in la_LN lt_LN; do + echo "$l.ASCII ASCII" + done + for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ + fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ + lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do + echo "$l.ISO_8859-1 ISO-8859-1" + echo "$l.DIS_8859-15 ISO-8859-15" + done + for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do + echo "$l.ISO_8859-2 ISO-8859-2" + done + for l in la_LN lt_LT; do + echo "$l.ISO_8859-4 ISO-8859-4" + done + for l in ru_RU ru_SU; do + echo "$l.KOI8-R KOI8-R" + echo "$l.ISO_8859-5 ISO-8859-5" + echo "$l.CP866 CP866" + done + echo "uk_UA.KOI8-U KOI8-U" + echo "zh_TW.BIG5 BIG5" + echo "zh_TW.Big5 BIG5" + echo "zh_CN.EUC GB2312" + echo "ja_JP.EUC EUC-JP" + echo "ja_JP.SJIS SHIFT_JIS" + echo "ja_JP.Shift_JIS SHIFT_JIS" + echo "ko_KR.EUC EUC-KR" + ;; + netbsd*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + echo "eucCN GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "BIG5 BIG5" + echo "SJIS SHIFT_JIS" + ;; + openbsd*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + ;; + darwin[56]*) + # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "C ASCII" + for l in en_AU en_CA en_GB en_US la_LN; do + echo "$l.US-ASCII ASCII" + done + for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ + fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ + nl_NL no_NO pt_PT sv_SE; do + echo "$l ISO-8859-1" + echo "$l.ISO8859-1 ISO-8859-1" + echo "$l.ISO8859-15 ISO-8859-15" + done + for l in la_LN; do + echo "$l.ISO8859-1 ISO-8859-1" + echo "$l.ISO8859-15 ISO-8859-15" + done + for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do + echo "$l.ISO8859-2 ISO-8859-2" + done + for l in la_LN lt_LT; do + echo "$l.ISO8859-4 ISO-8859-4" + done + for l in ru_RU; do + echo "$l.KOI8-R KOI8-R" + echo "$l.ISO8859-5 ISO-8859-5" + echo "$l.CP866 CP866" + done + for l in bg_BG; do + echo "$l.CP1251 CP1251" + done + echo "uk_UA.KOI8-U KOI8-U" + echo "zh_TW.BIG5 BIG5" + echo "zh_TW.Big5 BIG5" + echo "zh_CN.EUC GB2312" + echo "ja_JP.EUC EUC-JP" + echo "ja_JP.SJIS SHIFT_JIS" + echo "ko_KR.EUC EUC-KR" + ;; + darwin*) + # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is + # useless: + # - It returns the empty string when LANG is set to a locale of the + # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 + # LC_CTYPE file. + # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by + # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. + # - The documentation says: + # "... all code that calls BSD system routines should ensure + # that the const *char parameters of these routines are in UTF-8 + # encoding. All BSD system functions expect their string + # parameters to be in UTF-8 encoding and nothing else." + # It also says + # "An additional caveat is that string parameters for files, + # paths, and other file-system entities must be in canonical + # UTF-8. In a canonical UTF-8 Unicode string, all decomposable + # characters are decomposed ..." + # but this is not true: You can pass non-decomposed UTF-8 strings + # to file system functions, and it is the OS which will convert + # them to decomposed UTF-8 before accessing the file system. + # - The Apple Terminal application displays UTF-8 by default. + # - However, other applications are free to use different encodings: + # - xterm uses ISO-8859-1 by default. + # - TextEdit uses MacRoman by default. + # We prefer UTF-8 over decomposed UTF-8-MAC because one should + # minimize the use of decomposed Unicode. Unfortunately, through the + # Darwin file system, decomposed UTF-8 strings are leaked into user + # space nevertheless. + # Then there are also the locales with encodings other than US-ASCII + # and UTF-8. These locales can be occasionally useful to users (e.g. + # when grepping through ISO-8859-1 encoded text files), when all their + # file names are in US-ASCII. + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + echo "KOI8-R KOI8-R" + echo "KOI8-U KOI8-U" + echo "CP866 CP866" + echo "CP949 CP949" + echo "CP1131 CP1131" + echo "CP1251 CP1251" + echo "eucCN GB2312" + echo "GB2312 GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "Big5 BIG5" + echo "Big5HKSCS BIG5-HKSCS" + echo "GBK GBK" + echo "GB18030 GB18030" + echo "SJIS SHIFT_JIS" + echo "ARMSCII-8 ARMSCII-8" + echo "PT154 PT154" + #echo "ISCII-DEV ?" + echo "* UTF-8" + ;; + beos* | haiku*) + # BeOS and Haiku have a single locale, and it has UTF-8 encoding. + echo "* UTF-8" + ;; + msdosdjgpp*) + # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "#" + echo "# The encodings given here may not all be correct." + echo "# If you find that the encoding given for your language and" + echo "# country is not the one your DOS machine actually uses, just" + echo "# correct it in this file, and send a mail to" + echo "# Juan Manuel Guerrero " + echo "# and Bruno Haible ." + echo "#" + echo "C ASCII" + # ISO-8859-1 languages + echo "ca CP850" + echo "ca_ES CP850" + echo "da CP865" # not CP850 ?? + echo "da_DK CP865" # not CP850 ?? + echo "de CP850" + echo "de_AT CP850" + echo "de_CH CP850" + echo "de_DE CP850" + echo "en CP850" + echo "en_AU CP850" # not CP437 ?? + echo "en_CA CP850" + echo "en_GB CP850" + echo "en_NZ CP437" + echo "en_US CP437" + echo "en_ZA CP850" # not CP437 ?? + echo "es CP850" + echo "es_AR CP850" + echo "es_BO CP850" + echo "es_CL CP850" + echo "es_CO CP850" + echo "es_CR CP850" + echo "es_CU CP850" + echo "es_DO CP850" + echo "es_EC CP850" + echo "es_ES CP850" + echo "es_GT CP850" + echo "es_HN CP850" + echo "es_MX CP850" + echo "es_NI CP850" + echo "es_PA CP850" + echo "es_PY CP850" + echo "es_PE CP850" + echo "es_SV CP850" + echo "es_UY CP850" + echo "es_VE CP850" + echo "et CP850" + echo "et_EE CP850" + echo "eu CP850" + echo "eu_ES CP850" + echo "fi CP850" + echo "fi_FI CP850" + echo "fr CP850" + echo "fr_BE CP850" + echo "fr_CA CP850" + echo "fr_CH CP850" + echo "fr_FR CP850" + echo "ga CP850" + echo "ga_IE CP850" + echo "gd CP850" + echo "gd_GB CP850" + echo "gl CP850" + echo "gl_ES CP850" + echo "id CP850" # not CP437 ?? + echo "id_ID CP850" # not CP437 ?? + echo "is CP861" # not CP850 ?? + echo "is_IS CP861" # not CP850 ?? + echo "it CP850" + echo "it_CH CP850" + echo "it_IT CP850" + echo "lt CP775" + echo "lt_LT CP775" + echo "lv CP775" + echo "lv_LV CP775" + echo "nb CP865" # not CP850 ?? + echo "nb_NO CP865" # not CP850 ?? + echo "nl CP850" + echo "nl_BE CP850" + echo "nl_NL CP850" + echo "nn CP865" # not CP850 ?? + echo "nn_NO CP865" # not CP850 ?? + echo "no CP865" # not CP850 ?? + echo "no_NO CP865" # not CP850 ?? + echo "pt CP850" + echo "pt_BR CP850" + echo "pt_PT CP850" + echo "sv CP850" + echo "sv_SE CP850" + # ISO-8859-2 languages + echo "cs CP852" + echo "cs_CZ CP852" + echo "hr CP852" + echo "hr_HR CP852" + echo "hu CP852" + echo "hu_HU CP852" + echo "pl CP852" + echo "pl_PL CP852" + echo "ro CP852" + echo "ro_RO CP852" + echo "sk CP852" + echo "sk_SK CP852" + echo "sl CP852" + echo "sl_SI CP852" + echo "sq CP852" + echo "sq_AL CP852" + echo "sr CP852" # CP852 or CP866 or CP855 ?? + echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? + echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? + # ISO-8859-3 languages + echo "mt CP850" + echo "mt_MT CP850" + # ISO-8859-5 languages + echo "be CP866" + echo "be_BE CP866" + echo "bg CP866" # not CP855 ?? + echo "bg_BG CP866" # not CP855 ?? + echo "mk CP866" # not CP855 ?? + echo "mk_MK CP866" # not CP855 ?? + echo "ru CP866" + echo "ru_RU CP866" + echo "uk CP1125" + echo "uk_UA CP1125" + # ISO-8859-6 languages + echo "ar CP864" + echo "ar_AE CP864" + echo "ar_DZ CP864" + echo "ar_EG CP864" + echo "ar_IQ CP864" + echo "ar_IR CP864" + echo "ar_JO CP864" + echo "ar_KW CP864" + echo "ar_MA CP864" + echo "ar_OM CP864" + echo "ar_QA CP864" + echo "ar_SA CP864" + echo "ar_SY CP864" + # ISO-8859-7 languages + echo "el CP869" + echo "el_GR CP869" + # ISO-8859-8 languages + echo "he CP862" + echo "he_IL CP862" + # ISO-8859-9 languages + echo "tr CP857" + echo "tr_TR CP857" + # Japanese + echo "ja CP932" + echo "ja_JP CP932" + # Chinese + echo "zh_CN GBK" + echo "zh_TW CP950" # not CP938 ?? + # Korean + echo "kr CP949" # not CP934 ?? + echo "kr_KR CP949" # not CP934 ?? + # Thai + echo "th CP874" + echo "th_TH CP874" + # Other + echo "eo CP850" + echo "eo_EO CP850" + ;; +esac diff --git a/grub-core/gnulib/dirname-lgpl.c b/grub-core/gnulib/dirname-lgpl.c new file mode 100644 index 000000000..82f66301f --- /dev/null +++ b/grub-core/gnulib/dirname-lgpl.c @@ -0,0 +1,86 @@ +/* dirname.c -- return all but the last element in a file name + + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include "dirname.h" + +#include +#include + +/* Return the length of the prefix of FILE that will be used by + dir_name. If FILE is in the working directory, this returns zero + even though 'dir_name (FILE)' will return ".". Works properly even + if there are trailing slashes (by effectively ignoring them). */ + +size_t +dir_len (char const *file) +{ + size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file); + size_t length; + + /* Advance prefix_length beyond important leading slashes. */ + prefix_length += (prefix_length != 0 + ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE + && ISSLASH (file[prefix_length])) + : (ISSLASH (file[0]) + ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT + && ISSLASH (file[1]) && ! ISSLASH (file[2]) + ? 2 : 1)) + : 0)); + + /* Strip the basename and any redundant slashes before it. */ + for (length = last_component (file) - file; + prefix_length < length; length--) + if (! ISSLASH (file[length - 1])) + break; + return length; +} + + +/* In general, we can't use the builtin 'dirname' function if available, + since it has different meanings in different environments. + In some environments the builtin 'dirname' modifies its argument. + + Return the leading directories part of FILE, allocated with malloc. + Works properly even if there are trailing slashes (by effectively + ignoring them). Return NULL on failure. + + If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); + lstat (base_name (FILE)); } will access the same file. Likewise, + if the sequence { chdir (dir_name (FILE)); + rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE + to "foo" in the same directory FILE was in. */ + +char * +mdir_name (char const *file) +{ + size_t length = dir_len (file); + bool append_dot = (length == 0 + || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE + && length == FILE_SYSTEM_PREFIX_LEN (file) + && file[2] != '\0' && ! ISSLASH (file[2]))); + char *dir = malloc (length + append_dot + 1); + if (!dir) + return NULL; + memcpy (dir, file, length); + if (append_dot) + dir[length++] = '.'; + dir[length] = '\0'; + return dir; +} diff --git a/grub-core/gnulib/dirname.h b/grub-core/gnulib/dirname.h new file mode 100644 index 000000000..4ad031200 --- /dev/null +++ b/grub-core/gnulib/dirname.h @@ -0,0 +1,46 @@ +/* Take file names apart into directory and base names. + + Copyright (C) 1998, 2001, 2003-2006, 2009-2013 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef DIRNAME_H_ +# define DIRNAME_H_ 1 + +# include +# include +# include "dosname.h" + +# ifndef DIRECTORY_SEPARATOR +# define DIRECTORY_SEPARATOR '/' +# endif + +# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT +# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 +# endif + +# if GNULIB_DIRNAME +char *base_name (char const *file); +char *dir_name (char const *file); +# endif + +char *mdir_name (char const *file); +size_t base_len (char const *file) _GL_ATTRIBUTE_PURE; +size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE; +char *last_component (char const *file) _GL_ATTRIBUTE_PURE; + +bool strip_trailing_slashes (char *file); + +#endif /* not DIRNAME_H_ */ diff --git a/grub-core/gnulib/dosname.h b/grub-core/gnulib/dosname.h new file mode 100644 index 000000000..ba63ce4bd --- /dev/null +++ b/grub-core/gnulib/dosname.h @@ -0,0 +1,53 @@ +/* File names on MS-DOS/Windows systems. + + Copyright (C) 2000-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + From Paul Eggert and Jim Meyering. */ + +#ifndef _DOSNAME_H +#define _DOSNAME_H + +#if (defined _WIN32 || defined __WIN32__ || \ + defined __MSDOS__ || defined __CYGWIN__ || \ + defined __EMX__ || defined __DJGPP__) + /* This internal macro assumes ASCII, but all hosts that support drive + letters use ASCII. */ +# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \ + <= 'z' - 'a') +# define FILE_SYSTEM_PREFIX_LEN(Filename) \ + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) +# ifndef __CYGWIN__ +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 +# endif +# define ISSLASH(C) ((C) == '/' || (C) == '\\') +#else +# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 +# define ISSLASH(C) ((C) == '/') +#endif + +#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 +#endif + +#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) +# else +# define IS_ABSOLUTE_FILE_NAME(F) \ + (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0) +#endif +#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) + +#endif /* DOSNAME_H_ */ diff --git a/grub-core/gnulib/errno.in.h b/grub-core/gnulib/errno.in.h new file mode 100644 index 000000000..49b35464b --- /dev/null +++ b/grub-core/gnulib/errno.in.h @@ -0,0 +1,279 @@ +/* A POSIX-like . + + Copyright (C) 2008-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _@GUARD_PREFIX@_ERRNO_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_ERRNO_H@ + +#ifndef _@GUARD_PREFIX@_ERRNO_H +#define _@GUARD_PREFIX@_ERRNO_H + + +/* On native Windows platforms, many macros are not defined. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +/* These are the same values as defined by MSVC 10, for interoperability. */ + +# ifndef ENOMSG +# define ENOMSG 122 +# define GNULIB_defined_ENOMSG 1 +# endif + +# ifndef EIDRM +# define EIDRM 111 +# define GNULIB_defined_EIDRM 1 +# endif + +# ifndef ENOLINK +# define ENOLINK 121 +# define GNULIB_defined_ENOLINK 1 +# endif + +# ifndef EPROTO +# define EPROTO 134 +# define GNULIB_defined_EPROTO 1 +# endif + +# ifndef EBADMSG +# define EBADMSG 104 +# define GNULIB_defined_EBADMSG 1 +# endif + +# ifndef EOVERFLOW +# define EOVERFLOW 132 +# define GNULIB_defined_EOVERFLOW 1 +# endif + +# ifndef ENOTSUP +# define ENOTSUP 129 +# define GNULIB_defined_ENOTSUP 1 +# endif + +# ifndef ENETRESET +# define ENETRESET 117 +# define GNULIB_defined_ENETRESET 1 +# endif + +# ifndef ECONNABORTED +# define ECONNABORTED 106 +# define GNULIB_defined_ECONNABORTED 1 +# endif + +# ifndef ECANCELED +# define ECANCELED 105 +# define GNULIB_defined_ECANCELED 1 +# endif + +# ifndef EOWNERDEAD +# define EOWNERDEAD 133 +# define GNULIB_defined_EOWNERDEAD 1 +# endif + +# ifndef ENOTRECOVERABLE +# define ENOTRECOVERABLE 127 +# define GNULIB_defined_ENOTRECOVERABLE 1 +# endif + +# ifndef EINPROGRESS +# define EINPROGRESS 112 +# define EALREADY 103 +# define ENOTSOCK 128 +# define EDESTADDRREQ 109 +# define EMSGSIZE 115 +# define EPROTOTYPE 136 +# define ENOPROTOOPT 123 +# define EPROTONOSUPPORT 135 +# define EOPNOTSUPP 130 +# define EAFNOSUPPORT 102 +# define EADDRINUSE 100 +# define EADDRNOTAVAIL 101 +# define ENETDOWN 116 +# define ENETUNREACH 118 +# define ECONNRESET 108 +# define ENOBUFS 119 +# define EISCONN 113 +# define ENOTCONN 126 +# define ETIMEDOUT 138 +# define ECONNREFUSED 107 +# define ELOOP 114 +# define EHOSTUNREACH 110 +# define EWOULDBLOCK 140 +# define GNULIB_defined_ESOCK 1 +# endif + +# ifndef ETXTBSY +# define ETXTBSY 139 +# define ENODATA 120 /* not required by POSIX */ +# define ENOSR 124 /* not required by POSIX */ +# define ENOSTR 125 /* not required by POSIX */ +# define ETIME 137 /* not required by POSIX */ +# define EOTHER 131 /* not required by POSIX */ +# define GNULIB_defined_ESTREAMS 1 +# endif + +/* These are intentionally the same values as the WSA* error numbers, defined + in . */ +# define ESOCKTNOSUPPORT 10044 /* not required by POSIX */ +# define EPFNOSUPPORT 10046 /* not required by POSIX */ +# define ESHUTDOWN 10058 /* not required by POSIX */ +# define ETOOMANYREFS 10059 /* not required by POSIX */ +# define EHOSTDOWN 10064 /* not required by POSIX */ +# define EPROCLIM 10067 /* not required by POSIX */ +# define EUSERS 10068 /* not required by POSIX */ +# define EDQUOT 10069 +# define ESTALE 10070 +# define EREMOTE 10071 /* not required by POSIX */ +# define GNULIB_defined_EWINSOCK 1 + +# endif + + +/* On OSF/1 5.1, when _XOPEN_SOURCE_EXTENDED is not defined, the macros + EMULTIHOP, ENOLINK, EOVERFLOW are not defined. */ +# if @EMULTIHOP_HIDDEN@ +# define EMULTIHOP @EMULTIHOP_VALUE@ +# define GNULIB_defined_EMULTIHOP 1 +# endif +# if @ENOLINK_HIDDEN@ +# define ENOLINK @ENOLINK_VALUE@ +# define GNULIB_defined_ENOLINK 1 +# endif +# if @EOVERFLOW_HIDDEN@ +# define EOVERFLOW @EOVERFLOW_VALUE@ +# define GNULIB_defined_EOVERFLOW 1 +# endif + + +/* On OpenBSD 4.0 and on native Windows, the macros ENOMSG, EIDRM, ENOLINK, + EPROTO, EMULTIHOP, EBADMSG, EOVERFLOW, ENOTSUP, ECANCELED are not defined. + Likewise, on NonStop Kernel, EDQUOT is not defined. + Define them here. Values >= 2000 seem safe to use: Solaris ESTALE = 151, + HP-UX EWOULDBLOCK = 246, IRIX EDQUOT = 1133. + + Note: When one of these systems defines some of these macros some day, + binaries will have to be recompiled so that they recognizes the new + errno values from the system. */ + +# ifndef ENOMSG +# define ENOMSG 2000 +# define GNULIB_defined_ENOMSG 1 +# endif + +# ifndef EIDRM +# define EIDRM 2001 +# define GNULIB_defined_EIDRM 1 +# endif + +# ifndef ENOLINK +# define ENOLINK 2002 +# define GNULIB_defined_ENOLINK 1 +# endif + +# ifndef EPROTO +# define EPROTO 2003 +# define GNULIB_defined_EPROTO 1 +# endif + +# ifndef EMULTIHOP +# define EMULTIHOP 2004 +# define GNULIB_defined_EMULTIHOP 1 +# endif + +# ifndef EBADMSG +# define EBADMSG 2005 +# define GNULIB_defined_EBADMSG 1 +# endif + +# ifndef EOVERFLOW +# define EOVERFLOW 2006 +# define GNULIB_defined_EOVERFLOW 1 +# endif + +# ifndef ENOTSUP +# define ENOTSUP 2007 +# define GNULIB_defined_ENOTSUP 1 +# endif + +# ifndef ENETRESET +# define ENETRESET 2011 +# define GNULIB_defined_ENETRESET 1 +# endif + +# ifndef ECONNABORTED +# define ECONNABORTED 2012 +# define GNULIB_defined_ECONNABORTED 1 +# endif + +# ifndef ESTALE +# define ESTALE 2009 +# define GNULIB_defined_ESTALE 1 +# endif + +# ifndef EDQUOT +# define EDQUOT 2010 +# define GNULIB_defined_EDQUOT 1 +# endif + +# ifndef ECANCELED +# define ECANCELED 2008 +# define GNULIB_defined_ECANCELED 1 +# endif + +/* On many platforms, the macros EOWNERDEAD and ENOTRECOVERABLE are not + defined. */ + +# ifndef EOWNERDEAD +# if defined __sun + /* Use the same values as defined for Solaris >= 8, for + interoperability. */ +# define EOWNERDEAD 58 +# define ENOTRECOVERABLE 59 +# elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* We have a conflict here: pthreads-win32 defines these values + differently than MSVC 10. It's hairy to decide which one to use. */ +# if defined __MINGW32__ && !defined USE_WINDOWS_THREADS + /* Use the same values as defined by pthreads-win32, for + interoperability. */ +# define EOWNERDEAD 43 +# define ENOTRECOVERABLE 44 +# else + /* Use the same values as defined by MSVC 10, for + interoperability. */ +# define EOWNERDEAD 133 +# define ENOTRECOVERABLE 127 +# endif +# else +# define EOWNERDEAD 2013 +# define ENOTRECOVERABLE 2014 +# endif +# define GNULIB_defined_EOWNERDEAD 1 +# define GNULIB_defined_ENOTRECOVERABLE 1 +# endif + +# ifndef EILSEQ +# define EILSEQ 2015 +# define GNULIB_defined_EILSEQ 1 +# endif + +#endif /* _@GUARD_PREFIX@_ERRNO_H */ +#endif /* _@GUARD_PREFIX@_ERRNO_H */ diff --git a/grub-core/gnulib/error.c b/grub-core/gnulib/error.c new file mode 100644 index 000000000..865b29340 --- /dev/null +++ b/grub-core/gnulib/error.c @@ -0,0 +1,401 @@ +/* Error handler for noninteractive utilities + Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by David MacKenzie . */ + +#if !_LIBC +# include +#endif + +#include "error.h" + +#include +#include +#include +#include + +#if !_LIBC && ENABLE_NLS +# include "gettext.h" +# define _(msgid) gettext (msgid) +#endif + +#ifdef _LIBC +# include +# include +# include +# include +# define mbsrtowcs __mbsrtowcs +#endif + +#if USE_UNLOCKED_IO +# include "unlocked-io.h" +#endif + +#ifndef _ +# define _(String) String +#endif + +/* If NULL, error will flush stdout, then print on stderr the program + name, a colon and a space. Otherwise, error will call this + function without parameters instead. */ +void (*error_print_progname) (void); + +/* This variable is incremented each time 'error' is called. */ +unsigned int error_message_count; + +#ifdef _LIBC +/* In the GNU C library, there is a predefined variable for this. */ + +# define program_name program_invocation_name +# include +# include +# include + +/* In GNU libc we want do not want to use the common name 'error' directly. + Instead make it a weak alias. */ +extern void __error (int status, int errnum, const char *message, ...) + __attribute__ ((__format__ (__printf__, 3, 4))); +extern void __error_at_line (int status, int errnum, const char *file_name, + unsigned int line_number, const char *message, + ...) + __attribute__ ((__format__ (__printf__, 5, 6)));; +# define error __error +# define error_at_line __error_at_line + +# include +# define fflush(s) INTUSE(_IO_fflush) (s) +# undef putc +# define putc(c, fp) INTUSE(_IO_putc) (c, fp) + +# include + +#else /* not _LIBC */ + +# include +# include + +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Get declarations of the native Windows API functions. */ +# define WIN32_LEAN_AND_MEAN +# include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" +# endif + +/* The gnulib override of fcntl is not needed in this file. */ +# undef fcntl + +# if !HAVE_DECL_STRERROR_R +# ifndef HAVE_DECL_STRERROR_R +"this configure-time declaration test was not run" +# endif +# if STRERROR_R_CHAR_P +char *strerror_r (); +# else +int strerror_r (); +# endif +# endif + +/* The calling program should define program_name and set it to the + name of the executing program. */ +extern char *program_name; + +# if HAVE_STRERROR_R || defined strerror_r +# define __strerror_r strerror_r +# endif /* HAVE_STRERROR_R || defined strerror_r */ +#endif /* not _LIBC */ + +#if !_LIBC +/* Return non-zero if FD is open. */ +static int +is_open (int fd) +{ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* On native Windows: The initial state of unassigned standard file + descriptors is that they are open but point to an INVALID_HANDLE_VALUE. + There is no fcntl, and the gnulib replacement fcntl does not support + F_GETFL. */ + return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; +# else +# ifndef F_GETFL +# error Please port fcntl to your platform +# endif + return 0 <= fcntl (fd, F_GETFL); +# endif +} +#endif + +static void +flush_stdout (void) +{ +#if !_LIBC + int stdout_fd; + +# if GNULIB_FREOPEN_SAFER + /* Use of gnulib's freopen-safer module normally ensures that + fileno (stdout) == 1 + whenever stdout is open. */ + stdout_fd = STDOUT_FILENO; +# else + /* POSIX states that fileno (stdout) after fclose is unspecified. But in + practice it is not a problem, because stdout is statically allocated and + the fd of a FILE stream is stored as a field in its allocated memory. */ + stdout_fd = fileno (stdout); +# endif + /* POSIX states that fflush (stdout) after fclose is unspecified; it + is safe in glibc, but not on all other platforms. fflush (NULL) + is always defined, but too draconian. */ + if (0 <= stdout_fd && is_open (stdout_fd)) +#endif + fflush (stdout); +} + +static void +print_errno_message (int errnum) +{ + char const *s; + +#if defined HAVE_STRERROR_R || _LIBC + char errbuf[1024]; +# if STRERROR_R_CHAR_P || _LIBC + s = __strerror_r (errnum, errbuf, sizeof errbuf); +# else + if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) + s = errbuf; + else + s = 0; +# endif +#else + s = strerror (errnum); +#endif + +#if !_LIBC + if (! s) + s = _("Unknown system error"); +#endif + +#if _LIBC + __fxprintf (NULL, ": %s", s); +#else + fprintf (stderr, ": %s", s); +#endif +} + +static void +error_tail (int status, int errnum, const char *message, va_list args) +{ +#if _LIBC + if (_IO_fwide (stderr, 0) > 0) + { +# define ALLOCA_LIMIT 2000 + size_t len = strlen (message) + 1; + wchar_t *wmessage = NULL; + mbstate_t st; + size_t res; + const char *tmp; + bool use_malloc = false; + + while (1) + { + if (__libc_use_alloca (len * sizeof (wchar_t))) + wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); + else + { + if (!use_malloc) + wmessage = NULL; + + wchar_t *p = (wchar_t *) realloc (wmessage, + len * sizeof (wchar_t)); + if (p == NULL) + { + free (wmessage); + fputws_unlocked (L"out of memory\n", stderr); + return; + } + wmessage = p; + use_malloc = true; + } + + memset (&st, '\0', sizeof (st)); + tmp = message; + + res = mbsrtowcs (wmessage, &tmp, len, &st); + if (res != len) + break; + + if (__builtin_expect (len >= SIZE_MAX / 2, 0)) + { + /* This really should not happen if everything is fine. */ + res = (size_t) -1; + break; + } + + len *= 2; + } + + if (res == (size_t) -1) + { + /* The string cannot be converted. */ + if (use_malloc) + { + free (wmessage); + use_malloc = false; + } + wmessage = (wchar_t *) L"???"; + } + + __vfwprintf (stderr, wmessage, args); + + if (use_malloc) + free (wmessage); + } + else +#endif + vfprintf (stderr, message, args); + va_end (args); + + ++error_message_count; + if (errnum) + print_errno_message (errnum); +#if _LIBC + __fxprintf (NULL, "\n"); +#else + putc ('\n', stderr); +#endif + fflush (stderr); + if (status) + exit (status); +} + + +/* Print the program name and error message MESSAGE, which is a printf-style + format string with optional args. + If ERRNUM is nonzero, print its corresponding system error message. + Exit with status STATUS if it is nonzero. */ +void +error (int status, int errnum, const char *message, ...) +{ + va_list args; + +#if defined _LIBC && defined __libc_ptf_call + /* We do not want this call to be cut short by a thread + cancellation. Therefore disable cancellation for now. */ + int state = PTHREAD_CANCEL_ENABLE; + __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), + 0); +#endif + + flush_stdout (); +#ifdef _LIBC + _IO_flockfile (stderr); +#endif + if (error_print_progname) + (*error_print_progname) (); + else + { +#if _LIBC + __fxprintf (NULL, "%s: ", program_name); +#else + fprintf (stderr, "%s: ", program_name); +#endif + } + + va_start (args, message); + error_tail (status, errnum, message, args); + +#ifdef _LIBC + _IO_funlockfile (stderr); +# ifdef __libc_ptf_call + __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); +# endif +#endif +} + +/* Sometimes we want to have at most one error per line. This + variable controls whether this mode is selected or not. */ +int error_one_per_line; + +void +error_at_line (int status, int errnum, const char *file_name, + unsigned int line_number, const char *message, ...) +{ + va_list args; + + if (error_one_per_line) + { + static const char *old_file_name; + static unsigned int old_line_number; + + if (old_line_number == line_number + && (file_name == old_file_name + || strcmp (old_file_name, file_name) == 0)) + /* Simply return and print nothing. */ + return; + + old_file_name = file_name; + old_line_number = line_number; + } + +#if defined _LIBC && defined __libc_ptf_call + /* We do not want this call to be cut short by a thread + cancellation. Therefore disable cancellation for now. */ + int state = PTHREAD_CANCEL_ENABLE; + __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), + 0); +#endif + + flush_stdout (); +#ifdef _LIBC + _IO_flockfile (stderr); +#endif + if (error_print_progname) + (*error_print_progname) (); + else + { +#if _LIBC + __fxprintf (NULL, "%s:", program_name); +#else + fprintf (stderr, "%s:", program_name); +#endif + } + +#if _LIBC + __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", + file_name, line_number); +#else + fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", + file_name, line_number); +#endif + + va_start (args, message); + error_tail (status, errnum, message, args); + +#ifdef _LIBC + _IO_funlockfile (stderr); +# ifdef __libc_ptf_call + __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); +# endif +#endif +} + +#ifdef _LIBC +/* Make the weak alias. */ +# undef error +# undef error_at_line +weak_alias (__error, error) +weak_alias (__error_at_line, error_at_line) +#endif diff --git a/grub-core/gnulib/error.h b/grub-core/gnulib/error.h new file mode 100644 index 000000000..afcb0e10c --- /dev/null +++ b/grub-core/gnulib/error.h @@ -0,0 +1,65 @@ +/* Declaration for error-reporting function + Copyright (C) 1995-1997, 2003, 2006, 2008-2013 Free Software Foundation, + Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _ERROR_H +#define _ERROR_H 1 + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Print a message with 'fprintf (stderr, FORMAT, ...)'; + if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). + If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */ + +extern void error (int __status, int __errnum, const char *__format, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); + +extern void error_at_line (int __status, int __errnum, const char *__fname, + unsigned int __lineno, const char *__format, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6)); + +/* If NULL, error will flush stdout, then print on stderr the program + name, a colon and a space. Otherwise, error will call this + function without parameters instead. */ +extern void (*error_print_progname) (void); + +/* This variable is incremented each time 'error' is called. */ +extern unsigned int error_message_count; + +/* Sometimes we want to have at most one error per line. This + variable controls whether this mode is selected or not. */ +extern int error_one_per_line; + +#ifdef __cplusplus +} +#endif + +#endif /* error.h */ diff --git a/grub-core/gnulib/float+.h b/grub-core/gnulib/float+.h new file mode 100644 index 000000000..32fb790bb --- /dev/null +++ b/grub-core/gnulib/float+.h @@ -0,0 +1,147 @@ +/* Supplemental information about the floating-point formats. + Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2007. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _FLOATPLUS_H +#define _FLOATPLUS_H + +#include +#include + +/* Number of bits in the mantissa of a floating-point number, including the + "hidden bit". */ +#if FLT_RADIX == 2 +# define FLT_MANT_BIT FLT_MANT_DIG +# define DBL_MANT_BIT DBL_MANT_DIG +# define LDBL_MANT_BIT LDBL_MANT_DIG +#elif FLT_RADIX == 4 +# define FLT_MANT_BIT (FLT_MANT_DIG * 2) +# define DBL_MANT_BIT (DBL_MANT_DIG * 2) +# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2) +#elif FLT_RADIX == 16 +# define FLT_MANT_BIT (FLT_MANT_DIG * 4) +# define DBL_MANT_BIT (DBL_MANT_DIG * 4) +# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4) +#endif + +/* Bit mask that can be used to mask the exponent, as an unsigned number. */ +#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7) +#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7) +#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7) + +/* Number of bits used for the exponent of a floating-point number, including + the exponent's sign. */ +#define FLT_EXP_BIT \ + (FLT_EXP_MASK < 0x100 ? 8 : \ + FLT_EXP_MASK < 0x200 ? 9 : \ + FLT_EXP_MASK < 0x400 ? 10 : \ + FLT_EXP_MASK < 0x800 ? 11 : \ + FLT_EXP_MASK < 0x1000 ? 12 : \ + FLT_EXP_MASK < 0x2000 ? 13 : \ + FLT_EXP_MASK < 0x4000 ? 14 : \ + FLT_EXP_MASK < 0x8000 ? 15 : \ + FLT_EXP_MASK < 0x10000 ? 16 : \ + FLT_EXP_MASK < 0x20000 ? 17 : \ + FLT_EXP_MASK < 0x40000 ? 18 : \ + FLT_EXP_MASK < 0x80000 ? 19 : \ + FLT_EXP_MASK < 0x100000 ? 20 : \ + FLT_EXP_MASK < 0x200000 ? 21 : \ + FLT_EXP_MASK < 0x400000 ? 22 : \ + FLT_EXP_MASK < 0x800000 ? 23 : \ + FLT_EXP_MASK < 0x1000000 ? 24 : \ + FLT_EXP_MASK < 0x2000000 ? 25 : \ + FLT_EXP_MASK < 0x4000000 ? 26 : \ + FLT_EXP_MASK < 0x8000000 ? 27 : \ + FLT_EXP_MASK < 0x10000000 ? 28 : \ + FLT_EXP_MASK < 0x20000000 ? 29 : \ + FLT_EXP_MASK < 0x40000000 ? 30 : \ + FLT_EXP_MASK <= 0x7fffffff ? 31 : \ + 32) +#define DBL_EXP_BIT \ + (DBL_EXP_MASK < 0x100 ? 8 : \ + DBL_EXP_MASK < 0x200 ? 9 : \ + DBL_EXP_MASK < 0x400 ? 10 : \ + DBL_EXP_MASK < 0x800 ? 11 : \ + DBL_EXP_MASK < 0x1000 ? 12 : \ + DBL_EXP_MASK < 0x2000 ? 13 : \ + DBL_EXP_MASK < 0x4000 ? 14 : \ + DBL_EXP_MASK < 0x8000 ? 15 : \ + DBL_EXP_MASK < 0x10000 ? 16 : \ + DBL_EXP_MASK < 0x20000 ? 17 : \ + DBL_EXP_MASK < 0x40000 ? 18 : \ + DBL_EXP_MASK < 0x80000 ? 19 : \ + DBL_EXP_MASK < 0x100000 ? 20 : \ + DBL_EXP_MASK < 0x200000 ? 21 : \ + DBL_EXP_MASK < 0x400000 ? 22 : \ + DBL_EXP_MASK < 0x800000 ? 23 : \ + DBL_EXP_MASK < 0x1000000 ? 24 : \ + DBL_EXP_MASK < 0x2000000 ? 25 : \ + DBL_EXP_MASK < 0x4000000 ? 26 : \ + DBL_EXP_MASK < 0x8000000 ? 27 : \ + DBL_EXP_MASK < 0x10000000 ? 28 : \ + DBL_EXP_MASK < 0x20000000 ? 29 : \ + DBL_EXP_MASK < 0x40000000 ? 30 : \ + DBL_EXP_MASK <= 0x7fffffff ? 31 : \ + 32) +#define LDBL_EXP_BIT \ + (LDBL_EXP_MASK < 0x100 ? 8 : \ + LDBL_EXP_MASK < 0x200 ? 9 : \ + LDBL_EXP_MASK < 0x400 ? 10 : \ + LDBL_EXP_MASK < 0x800 ? 11 : \ + LDBL_EXP_MASK < 0x1000 ? 12 : \ + LDBL_EXP_MASK < 0x2000 ? 13 : \ + LDBL_EXP_MASK < 0x4000 ? 14 : \ + LDBL_EXP_MASK < 0x8000 ? 15 : \ + LDBL_EXP_MASK < 0x10000 ? 16 : \ + LDBL_EXP_MASK < 0x20000 ? 17 : \ + LDBL_EXP_MASK < 0x40000 ? 18 : \ + LDBL_EXP_MASK < 0x80000 ? 19 : \ + LDBL_EXP_MASK < 0x100000 ? 20 : \ + LDBL_EXP_MASK < 0x200000 ? 21 : \ + LDBL_EXP_MASK < 0x400000 ? 22 : \ + LDBL_EXP_MASK < 0x800000 ? 23 : \ + LDBL_EXP_MASK < 0x1000000 ? 24 : \ + LDBL_EXP_MASK < 0x2000000 ? 25 : \ + LDBL_EXP_MASK < 0x4000000 ? 26 : \ + LDBL_EXP_MASK < 0x8000000 ? 27 : \ + LDBL_EXP_MASK < 0x10000000 ? 28 : \ + LDBL_EXP_MASK < 0x20000000 ? 29 : \ + LDBL_EXP_MASK < 0x40000000 ? 30 : \ + LDBL_EXP_MASK <= 0x7fffffff ? 31 : \ + 32) + +/* Number of bits used for a floating-point number: the mantissa (not + counting the "hidden bit", since it may or may not be explicit), the + exponent, and the sign. */ +#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1) +#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1) +#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1) + +/* Number of bytes used for a floating-point number. + This can be smaller than the 'sizeof'. For example, on i386 systems, + 'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence + LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but + sizeof (long double) = 12 or = 16. */ +#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) +#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) +#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) + +/* Verify that SIZEOF_FLT <= sizeof (float) etc. */ +typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1]; +typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1]; +typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1]; + +#endif /* _FLOATPLUS_H */ diff --git a/grub-core/gnulib/float.c b/grub-core/gnulib/float.c new file mode 100644 index 000000000..366945fa3 --- /dev/null +++ b/grub-core/gnulib/float.c @@ -0,0 +1,33 @@ +/* Auxiliary definitions for . + Copyright (C) 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ +const union gl_long_double_union gl_LDBL_MAX = + { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } }; +#elif defined __i386__ +const union gl_long_double_union gl_LDBL_MAX = + { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; +#else +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; +#endif diff --git a/grub-core/gnulib/float.in.h b/grub-core/gnulib/float.in.h new file mode 100644 index 000000000..84e1950f9 --- /dev/null +++ b/grub-core/gnulib/float.in.h @@ -0,0 +1,188 @@ +/* A correct . + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _@GUARD_PREFIX@_FLOAT_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_FLOAT_H@ + +#ifndef _@GUARD_PREFIX@_FLOAT_H +#define _@GUARD_PREFIX@_FLOAT_H + +/* 'long double' properties. */ + +#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) +/* Number of mantissa units, in base FLT_RADIX. */ +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +/* Number of decimal digits that is sufficient for representing a number. */ +# undef LDBL_DIG +# define LDBL_DIG 18 +/* x-1 where x is the smallest representable number > 1. */ +# undef LDBL_EPSILON +# define LDBL_EPSILON 1.0842021724855044340E-19L +/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */ +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +/* Minimum positive normalized number. */ +# undef LDBL_MIN +# define LDBL_MIN 3.3621031431120935063E-4932L +/* Maximum representable finite number. */ +# undef LDBL_MAX +# define LDBL_MAX 1.1897314953572317650E+4932L +/* Minimum e such that 10^e is in the range of normalized numbers. */ +# undef LDBL_MIN_10_EXP +# define LDBL_MIN_10_EXP (-4931) +/* Maximum e such that 10^e is in the range of representable finite numbers. */ +# undef LDBL_MAX_10_EXP +# define LDBL_MAX_10_EXP 4932 +#endif + +/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of + precision in the compiler but 64 bits of precision at runtime. See + . */ +#if defined __i386__ && defined __FreeBSD__ +/* Number of mantissa units, in base FLT_RADIX. */ +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +/* Number of decimal digits that is sufficient for representing a number. */ +# undef LDBL_DIG +# define LDBL_DIG 18 +/* x-1 where x is the smallest representable number > 1. */ +# undef LDBL_EPSILON +# define LDBL_EPSILON 1.084202172485504434007452800869941711426e-19L /* 2^-63 */ +/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */ +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +/* Minimum positive normalized number. */ +# undef LDBL_MIN +# define LDBL_MIN 3.3621031431120935E-4932L /* = 0x1p-16382L */ +/* Maximum representable finite number. */ +# undef LDBL_MAX +/* LDBL_MAX is represented as { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }. + But the largest literal that GCC allows us to write is + 0x0.fffffffffffff8p16384L = { 0xFFFFF800, 0xFFFFFFFF, 32766 }. + So, define it like this through a reference to an external variable + + const unsigned int LDBL_MAX[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 32766 }; + extern const long double LDBL_MAX; + + Unfortunately, this is not a constant expression. */ +union gl_long_double_union + { + struct { unsigned int lo; unsigned int hi; unsigned int exponent; } xd; + long double ld; + }; +extern const union gl_long_double_union gl_LDBL_MAX; +# define LDBL_MAX (gl_LDBL_MAX.ld) +/* Minimum e such that 10^e is in the range of normalized numbers. */ +# undef LDBL_MIN_10_EXP +# define LDBL_MIN_10_EXP (-4931) +/* Maximum e such that 10^e is in the range of representable finite numbers. */ +# undef LDBL_MAX_10_EXP +# define LDBL_MAX_10_EXP 4932 +#endif + +/* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are + wrong. + On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */ +#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# undef LDBL_MIN_10_EXP +# define LDBL_MIN_10_EXP DBL_MIN_10_EXP +# undef LDBL_MIN +# define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */ +#endif +#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ +# undef LDBL_MAX +/* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }. + It is not easy to define: + #define LDBL_MAX 1.79769313486231580793728971405302307166e308L + is too small, whereas + #define LDBL_MAX 1.79769313486231580793728971405302307167e308L + is too large. Apparently a bug in GCC decimal-to-binary conversion. + Also, I can't get values larger than + #define LDBL63 ((long double) (1ULL << 63)) + #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) + #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) + #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) + #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL) + which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }. + So, define it like this through a reference to an external variable + + const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }; + extern const long double LDBL_MAX; + + or through a pointer cast + + #define LDBL_MAX \ + (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }) + + Unfortunately, this is not a constant expression, and the latter expression + does not work well when GCC is optimizing.. */ +union gl_long_double_union + { + struct { double hi; double lo; } dd; + long double ld; + }; +extern const union gl_long_double_union gl_LDBL_MAX; +# define LDBL_MAX (gl_LDBL_MAX.ld) +#endif + +/* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong. + On IRIX 6.5, with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_EPSILON + are wrong. */ +#if defined __sgi && (LDBL_MANT_DIG >= 106) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 106 +# if defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# undef LDBL_MIN_10_EXP +# define LDBL_MIN_10_EXP DBL_MIN_10_EXP +# undef LDBL_MIN +# define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */ +# undef LDBL_EPSILON +# define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */ +# endif +#endif + +#if @REPLACE_ITOLD@ +/* Pull in a function that fixes the 'int' to 'long double' conversion + of glibc 2.7. */ +extern +# ifdef __cplusplus +"C" +# endif +void _Qp_itoq (long double *, int); +static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq; +#endif + +#endif /* _@GUARD_PREFIX@_FLOAT_H */ +#endif /* _@GUARD_PREFIX@_FLOAT_H */ diff --git a/grub-core/gnulib/fnmatch.c b/grub-core/gnulib/fnmatch.c new file mode 100644 index 000000000..6a09e1a9b --- /dev/null +++ b/grub-core/gnulib/fnmatch.c @@ -0,0 +1,350 @@ +/* Copyright (C) 1991-1993, 1996-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _LIBC +# include +#endif + +/* Enable GNU extensions in fnmatch.h. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#if ! defined __builtin_expect && __GNUC__ < 3 +# define __builtin_expect(expr, expected) (expr) +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define WIDE_CHAR_SUPPORT \ + (HAVE_WCTYPE_H && HAVE_BTOWC && HAVE_ISWCTYPE \ + && HAVE_WMEMCHR && (HAVE_WMEMCPY || HAVE_WMEMPCPY)) + +/* For platform which support the ISO C amendment 1 functionality we + support user defined character classes. */ +#if defined _LIBC || WIDE_CHAR_SUPPORT +# include +# include +#endif + +/* We need some of the locale data (the collation sequence information) + but there is no interface to get this information in general. Therefore + we support a correct implementation only in glibc. */ +#ifdef _LIBC +# include "../locale/localeinfo.h" +# include "../locale/elem-hash.h" +# include "../locale/coll-lookup.h" +# include + +# define CONCAT(a,b) __CONCAT(a,b) +# define mbsrtowcs __mbsrtowcs +# define fnmatch __fnmatch +extern int fnmatch (const char *pattern, const char *string, int flags); +#endif + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +/* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set. */ +#define NO_LEADING_PERIOD(flags) \ + ((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD)) + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself, and have not detected a bug + in the library. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand 'configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined _LIBC || !defined __GNU_LIBRARY__ || !HAVE_FNMATCH_GNU + + +# if ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK)) +# define isblank(c) ((c) == ' ' || (c) == '\t') +# endif + +# define STREQ(s1, s2) (strcmp (s1, s2) == 0) + +# if defined _LIBC || WIDE_CHAR_SUPPORT +/* The GNU C library provides support for user-defined character classes + and the functions from ISO C amendment 1. */ +# ifdef CHARCLASS_NAME_MAX +# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX +# else +/* This shouldn't happen but some implementation might still have this + problem. Use a reasonable default value. */ +# define CHAR_CLASS_MAX_LENGTH 256 +# endif + +# ifdef _LIBC +# define IS_CHAR_CLASS(string) __wctype (string) +# else +# define IS_CHAR_CLASS(string) wctype (string) +# endif + +# ifdef _LIBC +# define ISWCTYPE(WC, WT) __iswctype (WC, WT) +# else +# define ISWCTYPE(WC, WT) iswctype (WC, WT) +# endif + +# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC +/* In this case we are implementing the multibyte character handling. */ +# define HANDLE_MULTIBYTE 1 +# endif + +# else +# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, 'xdigit'. */ + +# define IS_CHAR_CLASS(string) \ + (STREQ (string, "alpha") || STREQ (string, "upper") \ + || STREQ (string, "lower") || STREQ (string, "digit") \ + || STREQ (string, "alnum") || STREQ (string, "xdigit") \ + || STREQ (string, "space") || STREQ (string, "print") \ + || STREQ (string, "punct") || STREQ (string, "graph") \ + || STREQ (string, "cntrl") || STREQ (string, "blank")) +# endif + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +/* Global variable. */ +static int posixly_correct; + +# ifndef internal_function +/* Inside GNU libc we mark some function in a special way. In other + environments simply ignore the marking. */ +# define internal_function +# endif + +/* Note that this evaluates C many times. */ +# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c)) +# define CHAR char +# define UCHAR unsigned char +# define INT int +# define FCT internal_fnmatch +# define EXT ext_match +# define END end_pattern +# define L_(CS) CS +# ifdef _LIBC +# define BTOWC(C) __btowc (C) +# else +# define BTOWC(C) btowc (C) +# endif +# define STRLEN(S) strlen (S) +# define STRCAT(D, S) strcat (D, S) +# ifdef _LIBC +# define MEMPCPY(D, S, N) __mempcpy (D, S, N) +# else +# if HAVE_MEMPCPY +# define MEMPCPY(D, S, N) mempcpy (D, S, N) +# else +# define MEMPCPY(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) +# endif +# endif +# define MEMCHR(S, C, N) memchr (S, C, N) +# include "fnmatch_loop.c" + + +# if HANDLE_MULTIBYTE +# define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c)) +# define CHAR wchar_t +# define UCHAR wint_t +# define INT wint_t +# define FCT internal_fnwmatch +# define EXT ext_wmatch +# define END end_wpattern +# define L_(CS) L##CS +# define BTOWC(C) (C) +# ifdef _LIBC +# define STRLEN(S) __wcslen (S) +# define STRCAT(D, S) __wcscat (D, S) +# define MEMPCPY(D, S, N) __wmempcpy (D, S, N) +# else +# define STRLEN(S) wcslen (S) +# define STRCAT(D, S) wcscat (D, S) +# if HAVE_WMEMPCPY +# define MEMPCPY(D, S, N) wmempcpy (D, S, N) +# else +# define MEMPCPY(D, S, N) (wmemcpy (D, S, N) + (N)) +# endif +# endif +# define MEMCHR(S, C, N) wmemchr (S, C, N) +# define WIDE_CHAR_VERSION 1 + +# undef IS_CHAR_CLASS +/* We have to convert the wide character string in a multibyte string. But + we know that the character class names consist of alphanumeric characters + from the portable character set, and since the wide character encoding + for a member of the portable character set is the same code point as + its single-byte encoding, we can use a simplified method to convert the + string to a multibyte character string. */ +static wctype_t +is_char_class (const wchar_t *wcs) +{ + char s[CHAR_CLASS_MAX_LENGTH + 1]; + char *cp = s; + + do + { + /* Test for a printable character from the portable character set. */ +# ifdef _LIBC + if (*wcs < 0x20 || *wcs > 0x7e + || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60) + return (wctype_t) 0; +# else + switch (*wcs) + { + case L' ': case L'!': case L'"': case L'#': case L'%': + case L'&': case L'\'': case L'(': case L')': case L'*': + case L'+': case L',': case L'-': case L'.': case L'/': + case L'0': case L'1': case L'2': case L'3': case L'4': + case L'5': case L'6': case L'7': case L'8': case L'9': + case L':': case L';': case L'<': case L'=': case L'>': + case L'?': + case L'A': case L'B': case L'C': case L'D': case L'E': + case L'F': case L'G': case L'H': case L'I': case L'J': + case L'K': case L'L': case L'M': case L'N': case L'O': + case L'P': case L'Q': case L'R': case L'S': case L'T': + case L'U': case L'V': case L'W': case L'X': case L'Y': + case L'Z': + case L'[': case L'\\': case L']': case L'^': case L'_': + case L'a': case L'b': case L'c': case L'd': case L'e': + case L'f': case L'g': case L'h': case L'i': case L'j': + case L'k': case L'l': case L'm': case L'n': case L'o': + case L'p': case L'q': case L'r': case L's': case L't': + case L'u': case L'v': case L'w': case L'x': case L'y': + case L'z': case L'{': case L'|': case L'}': case L'~': + break; + default: + return (wctype_t) 0; + } +# endif + + /* Avoid overrunning the buffer. */ + if (cp == s + CHAR_CLASS_MAX_LENGTH) + return (wctype_t) 0; + + *cp++ = (char) *wcs++; + } + while (*wcs != L'\0'); + + *cp = '\0'; + +# ifdef _LIBC + return __wctype (s); +# else + return wctype (s); +# endif +} +# define IS_CHAR_CLASS(string) is_char_class (string) + +# include "fnmatch_loop.c" +# endif + + +int +fnmatch (const char *pattern, const char *string, int flags) +{ +# if HANDLE_MULTIBYTE +# define ALLOCA_LIMIT 2000 + if (__builtin_expect (MB_CUR_MAX, 1) != 1) + { + mbstate_t ps; + size_t patsize; + size_t strsize; + size_t totsize; + wchar_t *wpattern; + wchar_t *wstring; + int res; + + /* Calculate the size needed to convert the strings to + wide characters. */ + memset (&ps, '\0', sizeof (ps)); + patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; + if (__builtin_expect (patsize != 0, 1)) + { + assert (mbsinit (&ps)); + strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; + if (__builtin_expect (strsize != 0, 1)) + { + assert (mbsinit (&ps)); + totsize = patsize + strsize; + if (__builtin_expect (! (patsize <= totsize + && totsize <= SIZE_MAX / sizeof (wchar_t)), + 0)) + { + errno = ENOMEM; + return -1; + } + + /* Allocate room for the wide characters. */ + if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) + wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); + else + { + wpattern = malloc (totsize * sizeof (wchar_t)); + if (__builtin_expect (! wpattern, 0)) + { + errno = ENOMEM; + return -1; + } + } + wstring = wpattern + patsize; + + /* Convert the strings into wide characters. */ + mbsrtowcs (wpattern, &pattern, patsize, &ps); + assert (mbsinit (&ps)); + mbsrtowcs (wstring, &string, strsize, &ps); + + res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, + flags & FNM_PERIOD, flags); + + if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) + free (wpattern); + return res; + } + } + } + +# endif /* HANDLE_MULTIBYTE */ + + return internal_fnmatch (pattern, string, string + strlen (string), + flags & FNM_PERIOD, flags); +} + +# ifdef _LIBC +# undef fnmatch +versioned_symbol (libc, __fnmatch, fnmatch, GLIBC_2_2_3); +# if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2_3) +strong_alias (__fnmatch, __fnmatch_old) +compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0); +# endif +libc_hidden_ver (__fnmatch, fnmatch) +# endif + +#endif /* _LIBC or not __GNU_LIBRARY__. */ diff --git a/grub-core/gnulib/fnmatch.in.h b/grub-core/gnulib/fnmatch.in.h new file mode 100644 index 000000000..d39ce2f1c --- /dev/null +++ b/grub-core/gnulib/fnmatch.in.h @@ -0,0 +1,67 @@ +/* Copyright (C) 1991-1993, 1996-1999, 2001-2003, 2005, 2007, 2009-2013 Free + Software Foundation, Inc. + + This file is part of the GNU C Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _FNMATCH_H +#define _FNMATCH_H 1 + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* We #undef these before defining them because some losing systems + (HP-UX A.08.07 for example) define these in . */ +#undef FNM_PATHNAME +#undef FNM_NOESCAPE +#undef FNM_PERIOD + +/* Bits set in the FLAGS argument to 'fnmatch'. */ +#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match '/'. */ +#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ +#define FNM_PERIOD (1 << 2) /* Leading '.' is matched only explicitly. */ + +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE +# define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */ +# define FNM_LEADING_DIR (1 << 3) /* Ignore '/...' after a match. */ +# define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ +# define FNM_EXTMATCH (1 << 5) /* Use ksh-like extended matching. */ +#endif + +/* Value returned by 'fnmatch' if STRING does not match PATTERN. */ +#define FNM_NOMATCH 1 + +/* This value is returned if the implementation does not support + 'fnmatch'. Since this is not the case here it will never be + returned but the conformance test suites still require the symbol + to be defined. */ +#ifdef _XOPEN_SOURCE +# define FNM_NOSYS (-1) +#endif + +/* Match NAME against the file name pattern PATTERN, + returning zero if it matches, FNM_NOMATCH if not. */ +extern int fnmatch (const char *__pattern, const char *__name, + int __flags) + _GL_ARG_NONNULL ((1, 2)); + +#ifdef __cplusplus +} +#endif + +#endif /* fnmatch.h */ diff --git a/grub-core/gnulib/fnmatch_loop.c b/grub-core/gnulib/fnmatch_loop.c new file mode 100644 index 000000000..f57cd63f9 --- /dev/null +++ b/grub-core/gnulib/fnmatch_loop.c @@ -0,0 +1,1219 @@ +/* Copyright (C) 1991-1993, 1996-2006, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Match STRING against the file name pattern PATTERN, returning zero if + it matches, nonzero if not. */ +static int EXT (INT opt, const CHAR *pattern, const CHAR *string, + const CHAR *string_end, bool no_leading_period, int flags) + internal_function; +static const CHAR *END (const CHAR *patternp) internal_function; + +static int +internal_function +FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, + bool no_leading_period, int flags) +{ + register const CHAR *p = pattern, *n = string; + register UCHAR c; +#ifdef _LIBC +# if WIDE_CHAR_VERSION + const char *collseq = (const char *) + _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQWC); +# else + const UCHAR *collseq = (const UCHAR *) + _NL_CURRENT(LC_COLLATE, _NL_COLLATE_COLLSEQMB); +# endif +#endif + + while ((c = *p++) != L_('\0')) + { + bool new_no_leading_period = false; + c = FOLD (c); + + switch (c) + { + case L_('?'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, + flags); + if (res != -1) + return res; + } + + if (n == string_end) + return FNM_NOMATCH; + else if (*n == L_('/') && (flags & FNM_FILE_NAME)) + return FNM_NOMATCH; + else if (*n == L_('.') && no_leading_period) + return FNM_NOMATCH; + break; + + case L_('\\'): + if (!(flags & FNM_NOESCAPE)) + { + c = *p++; + if (c == L_('\0')) + /* Trailing \ loses. */ + return FNM_NOMATCH; + c = FOLD (c); + } + if (n == string_end || FOLD ((UCHAR) *n) != c) + return FNM_NOMATCH; + break; + + case L_('*'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, + flags); + if (res != -1) + return res; + } + + if (n != string_end && *n == L_('.') && no_leading_period) + return FNM_NOMATCH; + + for (c = *p++; c == L_('?') || c == L_('*'); c = *p++) + { + if (*p == L_('(') && (flags & FNM_EXTMATCH) != 0) + { + const CHAR *endp = END (p); + if (endp != p) + { + /* This is a pattern. Skip over it. */ + p = endp; + continue; + } + } + + if (c == L_('?')) + { + /* A ? needs to match one character. */ + if (n == string_end) + /* There isn't another character; no match. */ + return FNM_NOMATCH; + else if (*n == L_('/') + && __builtin_expect (flags & FNM_FILE_NAME, 0)) + /* A slash does not match a wildcard under + FNM_FILE_NAME. */ + return FNM_NOMATCH; + else + /* One character of the string is consumed in matching + this ? wildcard, so *??? won't match if there are + less than three characters. */ + ++n; + } + } + + if (c == L_('\0')) + /* The wildcard(s) is/are the last element of the pattern. + If the name is a file name and contains another slash + this means it cannot match, unless the FNM_LEADING_DIR + flag is set. */ + { + int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH; + + if (flags & FNM_FILE_NAME) + { + if (flags & FNM_LEADING_DIR) + result = 0; + else + { + if (MEMCHR (n, L_('/'), string_end - n) == NULL) + result = 0; + } + } + + return result; + } + else + { + const CHAR *endp; + + endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L_('/') : L_('\0'), + string_end - n); + if (endp == NULL) + endp = string_end; + + if (c == L_('[') + || (__builtin_expect (flags & FNM_EXTMATCH, 0) != 0 + && (c == L_('@') || c == L_('+') || c == L_('!')) + && *p == L_('('))) + { + int flags2 = ((flags & FNM_FILE_NAME) + ? flags : (flags & ~FNM_PERIOD)); + bool no_leading_period2 = no_leading_period; + + for (--p; n < endp; ++n, no_leading_period2 = false) + if (FCT (p, n, string_end, no_leading_period2, flags2) + == 0) + return 0; + } + else if (c == L_('/') && (flags & FNM_FILE_NAME)) + { + while (n < string_end && *n != L_('/')) + ++n; + if (n < string_end && *n == L_('/') + && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags) + == 0)) + return 0; + } + else + { + int flags2 = ((flags & FNM_FILE_NAME) + ? flags : (flags & ~FNM_PERIOD)); + int no_leading_period2 = no_leading_period; + + if (c == L_('\\') && !(flags & FNM_NOESCAPE)) + c = *p; + c = FOLD (c); + for (--p; n < endp; ++n, no_leading_period2 = false) + if (FOLD ((UCHAR) *n) == c + && (FCT (p, n, string_end, no_leading_period2, flags2) + == 0)) + return 0; + } + } + + /* If we come here no match is possible with the wildcard. */ + return FNM_NOMATCH; + + case L_('['): + { + /* Nonzero if the sense of the character class is inverted. */ + const CHAR *p_init = p; + const CHAR *n_init = n; + register bool not; + CHAR cold; + UCHAR fn; + + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + if (n == string_end) + return FNM_NOMATCH; + + if (*n == L_('.') && no_leading_period) + return FNM_NOMATCH; + + if (*n == L_('/') && (flags & FNM_FILE_NAME)) + /* '/' cannot be matched. */ + return FNM_NOMATCH; + + not = (*p == L_('!') || (posixly_correct < 0 && *p == L_('^'))); + if (not) + ++p; + + fn = FOLD ((UCHAR) *n); + + c = *p++; + for (;;) + { + if (!(flags & FNM_NOESCAPE) && c == L_('\\')) + { + if (*p == L_('\0')) + return FNM_NOMATCH; + c = FOLD ((UCHAR) *p); + ++p; + + goto normal_bracket; + } + else if (c == L_('[') && *p == L_(':')) + { + /* Leave room for the null. */ + CHAR str[CHAR_CLASS_MAX_LENGTH + 1]; + size_t c1 = 0; +#if defined _LIBC || WIDE_CHAR_SUPPORT + wctype_t wt; +#endif + const CHAR *startp = p; + + for (;;) + { + if (c1 == CHAR_CLASS_MAX_LENGTH) + /* The name is too long and therefore the pattern + is ill-formed. */ + return FNM_NOMATCH; + + c = *++p; + if (c == L_(':') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c < L_('a') || c >= L_('z')) + { + /* This cannot possibly be a character class name. + Match it as a normal range. */ + p = startp; + c = L_('['); + goto normal_bracket; + } + str[c1++] = c; + } + str[c1] = L_('\0'); + +#if defined _LIBC || WIDE_CHAR_SUPPORT + wt = IS_CHAR_CLASS (str); + if (wt == 0) + /* Invalid character class name. */ + return FNM_NOMATCH; + +# if defined _LIBC && ! WIDE_CHAR_VERSION + /* The following code is glibc specific but does + there a good job in speeding up the code since + we can avoid the btowc() call. */ + if (_ISCTYPE ((UCHAR) *n, wt)) + goto matched; +# else + if (ISWCTYPE (BTOWC ((UCHAR) *n), wt)) + goto matched; +# endif +#else + if ((STREQ (str, L_("alnum")) && isalnum ((UCHAR) *n)) + || (STREQ (str, L_("alpha")) && isalpha ((UCHAR) *n)) + || (STREQ (str, L_("blank")) && isblank ((UCHAR) *n)) + || (STREQ (str, L_("cntrl")) && iscntrl ((UCHAR) *n)) + || (STREQ (str, L_("digit")) && isdigit ((UCHAR) *n)) + || (STREQ (str, L_("graph")) && isgraph ((UCHAR) *n)) + || (STREQ (str, L_("lower")) && islower ((UCHAR) *n)) + || (STREQ (str, L_("print")) && isprint ((UCHAR) *n)) + || (STREQ (str, L_("punct")) && ispunct ((UCHAR) *n)) + || (STREQ (str, L_("space")) && isspace ((UCHAR) *n)) + || (STREQ (str, L_("upper")) && isupper ((UCHAR) *n)) + || (STREQ (str, L_("xdigit")) && isxdigit ((UCHAR) *n))) + goto matched; +#endif + c = *p++; + } +#ifdef _LIBC + else if (c == L_('[') && *p == L_('=')) + { + UCHAR str[1]; + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + const CHAR *startp = p; + + c = *++p; + if (c == L_('\0')) + { + p = startp; + c = L_('['); + goto normal_bracket; + } + str[0] = c; + + c = *++p; + if (c != L_('=') || p[1] != L_(']')) + { + p = startp; + c = L_('['); + goto normal_bracket; + } + p += 2; + + if (nrules == 0) + { + if ((UCHAR) *n == str[0]) + goto matched; + } + else + { + const int32_t *table; +# if WIDE_CHAR_VERSION + const int32_t *weights; + const int32_t *extra; +# else + const unsigned char *weights; + const unsigned char *extra; +# endif + const int32_t *indirect; + int32_t idx; + const UCHAR *cp = (const UCHAR *) str; + + /* This #include defines a local function! */ +# if WIDE_CHAR_VERSION +# include +# else +# include +# endif + +# if WIDE_CHAR_VERSION + table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC); + weights = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC); + extra = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC); + indirect = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC); +# else + table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); + weights = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB); + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); + indirect = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB); +# endif + + idx = findidx (&cp); + if (idx != 0) + { + /* We found a table entry. Now see whether the + character we are currently at has the same + equivalence class value. */ + int len = weights[idx & 0xffffff]; + int32_t idx2; + const UCHAR *np = (const UCHAR *) n; + + idx2 = findidx (&np); + if (idx2 != 0 + && (idx >> 24) == (idx2 >> 24) + && len == weights[idx2 & 0xffffff]) + { + int cnt = 0; + + idx &= 0xffffff; + idx2 &= 0xffffff; + + while (cnt < len + && (weights[idx + 1 + cnt] + == weights[idx2 + 1 + cnt])) + ++cnt; + + if (cnt == len) + goto matched; + } + } + } + + c = *p++; + } +#endif + else if (c == L_('\0')) + { + /* [ unterminated, treat as normal character. */ + p = p_init; + n = n_init; + c = L_('['); + goto normal_match; + } + else + { + bool is_range = false; + +#ifdef _LIBC + bool is_seqval = false; + + if (c == L_('[') && *p == L_('.')) + { + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + const CHAR *startp = p; + size_t c1 = 0; + + while (1) + { + c = *++p; + if (c == L_('.') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c == '\0') + return FNM_NOMATCH; + ++c1; + } + + /* We have to handling the symbols differently in + ranges since then the collation sequence is + important. */ + is_range = *p == L_('-') && p[1] != L_('\0'); + + if (nrules == 0) + { + /* There are no names defined in the collation + data. Therefore we only accept the trivial + names consisting of the character itself. */ + if (c1 != 1) + return FNM_NOMATCH; + + if (!is_range && *n == startp[1]) + goto matched; + + cold = startp[1]; + c = *p++; + } + else + { + int32_t table_size; + const int32_t *symb_table; +# ifdef WIDE_CHAR_VERSION + char str[c1]; + size_t strcnt; +# else +# define str (startp + 1) +# endif + const unsigned char *extra; + int32_t idx; + int32_t elem; + int32_t second; + int32_t hash; + +# ifdef WIDE_CHAR_VERSION + /* We have to convert the name to a single-byte + string. This is possible since the names + consist of ASCII characters and the internal + representation is UCS4. */ + for (strcnt = 0; strcnt < c1; ++strcnt) + str[strcnt] = startp[1 + strcnt]; +# endif + + table_size = + _NL_CURRENT_WORD (LC_COLLATE, + _NL_COLLATE_SYMB_HASH_SIZEMB); + symb_table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_TABLEMB); + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_EXTRAMB); + + /* Locate the character in the hashing table. */ + hash = elem_hash (str, c1); + + idx = 0; + elem = hash % table_size; + if (symb_table[2 * elem] != 0) + { + second = hash % (table_size - 2) + 1; + + do + { + /* First compare the hashing value. */ + if (symb_table[2 * elem] == hash + && (c1 + == extra[symb_table[2 * elem + 1]]) + && memcmp (str, + &extra[symb_table[2 * elem + + 1] + + 1], c1) == 0) + { + /* Yep, this is the entry. */ + idx = symb_table[2 * elem + 1]; + idx += 1 + extra[idx]; + break; + } + + /* Next entry. */ + elem += second; + } + while (symb_table[2 * elem] != 0); + } + + if (symb_table[2 * elem] != 0) + { + /* Compare the byte sequence but only if + this is not part of a range. */ +# ifdef WIDE_CHAR_VERSION + int32_t *wextra; + + idx += 1 + extra[idx]; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~3; + + wextra = (int32_t *) &extra[idx + 4]; +# endif + + if (! is_range) + { +# ifdef WIDE_CHAR_VERSION + for (c1 = 0; + (int32_t) c1 < wextra[idx]; + ++c1) + if (n[c1] != wextra[1 + c1]) + break; + + if ((int32_t) c1 == wextra[idx]) + goto matched; +# else + for (c1 = 0; c1 < extra[idx]; ++c1) + if (n[c1] != extra[1 + c1]) + break; + + if (c1 == extra[idx]) + goto matched; +# endif + } + + /* Get the collation sequence value. */ + is_seqval = true; +# ifdef WIDE_CHAR_VERSION + cold = wextra[1 + wextra[idx]]; +# else + /* Adjust for the alignment. */ + idx += 1 + extra[idx]; + idx = (idx + 3) & ~4; + cold = *((int32_t *) &extra[idx]); +# endif + + c = *p++; + } + else if (c1 == 1) + { + /* No valid character. Match it as a + single byte. */ + if (!is_range && *n == str[0]) + goto matched; + + cold = str[0]; + c = *p++; + } + else + return FNM_NOMATCH; + } + } + else +# undef str +#endif + { + c = FOLD (c); + normal_bracket: + + /* We have to handling the symbols differently in + ranges since then the collation sequence is + important. */ + is_range = (*p == L_('-') && p[1] != L_('\0') + && p[1] != L_(']')); + + if (!is_range && c == fn) + goto matched; + +#if _LIBC + /* This is needed if we goto normal_bracket; from + outside of is_seqval's scope. */ + is_seqval = false; +#endif + + cold = c; + c = *p++; + } + + if (c == L_('-') && *p != L_(']')) + { +#if _LIBC + /* We have to find the collation sequence + value for C. Collation sequence is nothing + we can regularly access. The sequence + value is defined by the order in which the + definitions of the collation values for the + various characters appear in the source + file. A strange concept, nowhere + documented. */ + uint32_t fcollseq; + uint32_t lcollseq; + UCHAR cend = *p++; + +# ifdef WIDE_CHAR_VERSION + /* Search in the 'names' array for the characters. */ + fcollseq = __collseq_table_lookup (collseq, fn); + if (fcollseq == ~((uint32_t) 0)) + /* XXX We don't know anything about the character + we are supposed to match. This means we are + failing. */ + goto range_not_matched; + + if (is_seqval) + lcollseq = cold; + else + lcollseq = __collseq_table_lookup (collseq, cold); +# else + fcollseq = collseq[fn]; + lcollseq = is_seqval ? cold : collseq[(UCHAR) cold]; +# endif + + is_seqval = false; + if (cend == L_('[') && *p == L_('.')) + { + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, + _NL_COLLATE_NRULES); + const CHAR *startp = p; + size_t c1 = 0; + + while (1) + { + c = *++p; + if (c == L_('.') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c == '\0') + return FNM_NOMATCH; + ++c1; + } + + if (nrules == 0) + { + /* There are no names defined in the + collation data. Therefore we only + accept the trivial names consisting + of the character itself. */ + if (c1 != 1) + return FNM_NOMATCH; + + cend = startp[1]; + } + else + { + int32_t table_size; + const int32_t *symb_table; +# ifdef WIDE_CHAR_VERSION + char str[c1]; + size_t strcnt; +# else +# define str (startp + 1) +# endif + const unsigned char *extra; + int32_t idx; + int32_t elem; + int32_t second; + int32_t hash; + +# ifdef WIDE_CHAR_VERSION + /* We have to convert the name to a single-byte + string. This is possible since the names + consist of ASCII characters and the internal + representation is UCS4. */ + for (strcnt = 0; strcnt < c1; ++strcnt) + str[strcnt] = startp[1 + strcnt]; +# endif + + table_size = + _NL_CURRENT_WORD (LC_COLLATE, + _NL_COLLATE_SYMB_HASH_SIZEMB); + symb_table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_TABLEMB); + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_EXTRAMB); + + /* Locate the character in the hashing + table. */ + hash = elem_hash (str, c1); + + idx = 0; + elem = hash % table_size; + if (symb_table[2 * elem] != 0) + { + second = hash % (table_size - 2) + 1; + + do + { + /* First compare the hashing value. */ + if (symb_table[2 * elem] == hash + && (c1 + == extra[symb_table[2 * elem + 1]]) + && memcmp (str, + &extra[symb_table[2 * elem + 1] + + 1], c1) == 0) + { + /* Yep, this is the entry. */ + idx = symb_table[2 * elem + 1]; + idx += 1 + extra[idx]; + break; + } + + /* Next entry. */ + elem += second; + } + while (symb_table[2 * elem] != 0); + } + + if (symb_table[2 * elem] != 0) + { + /* Compare the byte sequence but only if + this is not part of a range. */ +# ifdef WIDE_CHAR_VERSION + int32_t *wextra; + + idx += 1 + extra[idx]; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~4; + + wextra = (int32_t *) &extra[idx + 4]; +# endif + /* Get the collation sequence value. */ + is_seqval = true; +# ifdef WIDE_CHAR_VERSION + cend = wextra[1 + wextra[idx]]; +# else + /* Adjust for the alignment. */ + idx += 1 + extra[idx]; + idx = (idx + 3) & ~4; + cend = *((int32_t *) &extra[idx]); +# endif + } + else if (symb_table[2 * elem] != 0 && c1 == 1) + { + cend = str[0]; + c = *p++; + } + else + return FNM_NOMATCH; + } +# undef str + } + else + { + if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) + cend = *p++; + if (cend == L_('\0')) + return FNM_NOMATCH; + cend = FOLD (cend); + } + + /* XXX It is not entirely clear to me how to handle + characters which are not mentioned in the + collation specification. */ + if ( +# ifdef WIDE_CHAR_VERSION + lcollseq == 0xffffffff || +# endif + lcollseq <= fcollseq) + { + /* We have to look at the upper bound. */ + uint32_t hcollseq; + + if (is_seqval) + hcollseq = cend; + else + { +# ifdef WIDE_CHAR_VERSION + hcollseq = + __collseq_table_lookup (collseq, cend); + if (hcollseq == ~((uint32_t) 0)) + { + /* Hum, no information about the upper + bound. The matching succeeds if the + lower bound is matched exactly. */ + if (lcollseq != fcollseq) + goto range_not_matched; + + goto matched; + } +# else + hcollseq = collseq[cend]; +# endif + } + + if (lcollseq <= hcollseq && fcollseq <= hcollseq) + goto matched; + } +# ifdef WIDE_CHAR_VERSION + range_not_matched: +# endif +#else + /* We use a boring value comparison of the character + values. This is better than comparing using + 'strcoll' since the latter would have surprising + and sometimes fatal consequences. */ + UCHAR cend = *p++; + + if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) + cend = *p++; + if (cend == L_('\0')) + return FNM_NOMATCH; + + /* It is a range. */ + if (cold <= fn && fn <= cend) + goto matched; +#endif + + c = *p++; + } + } + + if (c == L_(']')) + break; + } + + if (!not) + return FNM_NOMATCH; + break; + + matched: + /* Skip the rest of the [...] that already matched. */ + do + { + ignore_next: + c = *p++; + + if (c == L_('\0')) + /* [... (unterminated) loses. */ + return FNM_NOMATCH; + + if (!(flags & FNM_NOESCAPE) && c == L_('\\')) + { + if (*p == L_('\0')) + return FNM_NOMATCH; + /* XXX 1003.2d11 is unclear if this is right. */ + ++p; + } + else if (c == L_('[') && *p == L_(':')) + { + int c1 = 0; + const CHAR *startp = p; + + while (1) + { + c = *++p; + if (++c1 == CHAR_CLASS_MAX_LENGTH) + return FNM_NOMATCH; + + if (*p == L_(':') && p[1] == L_(']')) + break; + + if (c < L_('a') || c >= L_('z')) + { + p = startp; + goto ignore_next; + } + } + p += 2; + c = *p++; + } + else if (c == L_('[') && *p == L_('=')) + { + c = *++p; + if (c == L_('\0')) + return FNM_NOMATCH; + c = *++p; + if (c != L_('=') || p[1] != L_(']')) + return FNM_NOMATCH; + p += 2; + c = *p++; + } + else if (c == L_('[') && *p == L_('.')) + { + ++p; + while (1) + { + c = *++p; + if (c == '\0') + return FNM_NOMATCH; + + if (*p == L_('.') && p[1] == L_(']')) + break; + } + p += 2; + c = *p++; + } + } + while (c != L_(']')); + if (not) + return FNM_NOMATCH; + } + break; + + case L_('+'): + case L_('@'): + case L_('!'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, flags); + if (res != -1) + return res; + } + goto normal_match; + + case L_('/'): + if (NO_LEADING_PERIOD (flags)) + { + if (n == string_end || c != (UCHAR) *n) + return FNM_NOMATCH; + + new_no_leading_period = true; + break; + } + /* FALLTHROUGH */ + default: + normal_match: + if (n == string_end || c != FOLD ((UCHAR) *n)) + return FNM_NOMATCH; + } + + no_leading_period = new_no_leading_period; + ++n; + } + + if (n == string_end) + return 0; + + if ((flags & FNM_LEADING_DIR) && n != string_end && *n == L_('/')) + /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */ + return 0; + + return FNM_NOMATCH; +} + + +static const CHAR * +internal_function +END (const CHAR *pattern) +{ + const CHAR *p = pattern; + + while (1) + if (*++p == L_('\0')) + /* This is an invalid pattern. */ + return pattern; + else if (*p == L_('[')) + { + /* Handle brackets special. */ + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + /* Skip the not sign. We have to recognize it because of a possibly + following ']'. */ + if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) + ++p; + /* A leading ']' is recognized as such. */ + if (*p == L_(']')) + ++p; + /* Skip over all characters of the list. */ + while (*p != L_(']')) + if (*p++ == L_('\0')) + /* This is no valid pattern. */ + return pattern; + } + else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@') + || *p == L_('!')) && p[1] == L_('(')) + p = END (p + 1); + else if (*p == L_(')')) + break; + + return p + 1; +} + + +static int +internal_function +EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, + bool no_leading_period, int flags) +{ + const CHAR *startp; + size_t level; + struct patternlist + { + struct patternlist *next; + CHAR str[1]; + } *list = NULL; + struct patternlist **lastp = &list; + size_t pattern_len = STRLEN (pattern); + const CHAR *p; + const CHAR *rs; + enum { ALLOCA_LIMIT = 8000 }; + + /* Parse the pattern. Store the individual parts in the list. */ + level = 0; + for (startp = p = pattern + 1; ; ++p) + if (*p == L_('\0')) + /* This is an invalid pattern. */ + return -1; + else if (*p == L_('[')) + { + /* Handle brackets special. */ + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + /* Skip the not sign. We have to recognize it because of a possibly + following ']'. */ + if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) + ++p; + /* A leading ']' is recognized as such. */ + if (*p == L_(']')) + ++p; + /* Skip over all characters of the list. */ + while (*p != L_(']')) + if (*p++ == L_('\0')) + /* This is no valid pattern. */ + return -1; + } + else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@') + || *p == L_('!')) && p[1] == L_('(')) + /* Remember the nesting level. */ + ++level; + else if (*p == L_(')')) + { + if (level-- == 0) + { + /* This means we found the end of the pattern. */ +#define NEW_PATTERN \ + struct patternlist *newp; \ + size_t plen; \ + size_t plensize; \ + size_t newpsize; \ + \ + plen = (opt == L_('?') || opt == L_('@') \ + ? pattern_len \ + : p - startp + 1UL); \ + plensize = plen * sizeof (CHAR); \ + newpsize = offsetof (struct patternlist, str) + plensize; \ + if ((size_t) -1 / sizeof (CHAR) < plen \ + || newpsize < offsetof (struct patternlist, str) \ + || ALLOCA_LIMIT <= newpsize) \ + return -1; \ + newp = (struct patternlist *) alloca (newpsize); \ + *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \ + newp->next = NULL; \ + *lastp = newp; \ + lastp = &newp->next + NEW_PATTERN; + break; + } + } + else if (*p == L_('|')) + { + if (level == 0) + { + NEW_PATTERN; + startp = p + 1; + } + } + assert (list != NULL); + assert (p[-1] == L_(')')); +#undef NEW_PATTERN + + switch (opt) + { + case L_('*'): + if (FCT (p, string, string_end, no_leading_period, flags) == 0) + return 0; + /* FALLTHROUGH */ + + case L_('+'): + do + { + for (rs = string; rs <= string_end; ++rs) + /* First match the prefix with the current pattern with the + current pattern. */ + if (FCT (list->str, string, rs, no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0 + /* This was successful. Now match the rest with the rest + of the pattern. */ + && (FCT (p, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME + ? flags : flags & ~FNM_PERIOD) == 0 + /* This didn't work. Try the whole pattern. */ + || (rs != string + && FCT (pattern - 1, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME + ? flags : flags & ~FNM_PERIOD) == 0))) + /* It worked. Signal success. */ + return 0; + } + while ((list = list->next) != NULL); + + /* None of the patterns lead to a match. */ + return FNM_NOMATCH; + + case L_('?'): + if (FCT (p, string, string_end, no_leading_period, flags) == 0) + return 0; + /* FALLTHROUGH */ + + case L_('@'): + do + /* I cannot believe it but 'strcat' is actually acceptable + here. Match the entire string with the prefix from the + pattern list and the rest of the pattern following the + pattern list. */ + if (FCT (STRCAT (list->str, p), string, string_end, + no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) + /* It worked. Signal success. */ + return 0; + while ((list = list->next) != NULL); + + /* None of the patterns lead to a match. */ + return FNM_NOMATCH; + + case L_('!'): + for (rs = string; rs <= string_end; ++rs) + { + struct patternlist *runp; + + for (runp = list; runp != NULL; runp = runp->next) + if (FCT (runp->str, string, rs, no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) + break; + + /* If none of the patterns matched see whether the rest does. */ + if (runp == NULL + && (FCT (p, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) + == 0)) + /* This is successful. */ + return 0; + } + + /* None of the patterns together with the rest of the pattern + lead to a match. */ + return FNM_NOMATCH; + + default: + assert (! "Invalid extended matching operator"); + break; + } + + return -1; +} + + +#undef FOLD +#undef CHAR +#undef UCHAR +#undef INT +#undef FCT +#undef EXT +#undef END +#undef MEMPCPY +#undef MEMCHR +#undef STRLEN +#undef STRCAT +#undef L_ +#undef BTOWC diff --git a/grub-core/gnulib/getdelim.c b/grub-core/gnulib/getdelim.c new file mode 100644 index 000000000..fdbcde2a2 --- /dev/null +++ b/grub-core/gnulib/getdelim.c @@ -0,0 +1,135 @@ +/* getdelim.c --- Implementation of replacement getdelim function. + Copyright (C) 1994, 1996-1998, 2001, 2003, 2005-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Ported from glibc by Simon Josefsson. */ + +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc + optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below. */ +#define _GL_ARG_NONNULL(params) + +#include + +#include + +#include +#include +#include +#include + +#ifndef SSIZE_MAX +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) +#endif + +#if USE_UNLOCKED_IO +# include "unlocked-io.h" +# define getc_maybe_unlocked(fp) getc(fp) +#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED +# undef flockfile +# undef funlockfile +# define flockfile(x) ((void) 0) +# define funlockfile(x) ((void) 0) +# define getc_maybe_unlocked(fp) getc(fp) +#else +# define getc_maybe_unlocked(fp) getc_unlocked(fp) +#endif + +/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + +ssize_t +getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) +{ + ssize_t result; + size_t cur_len = 0; + + if (lineptr == NULL || n == NULL || fp == NULL) + { + errno = EINVAL; + return -1; + } + + flockfile (fp); + + if (*lineptr == NULL || *n == 0) + { + char *new_lineptr; + *n = 120; + new_lineptr = (char *) realloc (*lineptr, *n); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + *lineptr = new_lineptr; + } + + for (;;) + { + int i; + + i = getc_maybe_unlocked (fp); + if (i == EOF) + { + result = -1; + break; + } + + /* Make enough space for len+1 (for final NUL) bytes. */ + if (cur_len + 1 >= *n) + { + size_t needed_max = + SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; + size_t needed = 2 * *n + 1; /* Be generous. */ + char *new_lineptr; + + if (needed_max < needed) + needed = needed_max; + if (cur_len + 1 >= needed) + { + result = -1; + errno = EOVERFLOW; + goto unlock_return; + } + + new_lineptr = (char *) realloc (*lineptr, needed); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + + *lineptr = new_lineptr; + *n = needed; + } + + (*lineptr)[cur_len] = i; + cur_len++; + + if (i == delimiter) + break; + } + (*lineptr)[cur_len] = '\0'; + result = cur_len ? cur_len : result; + + unlock_return: + funlockfile (fp); /* doesn't set errno */ + + return result; +} diff --git a/grub-core/gnulib/getline.c b/grub-core/gnulib/getline.c new file mode 100644 index 000000000..1aa07b9c7 --- /dev/null +++ b/grub-core/gnulib/getline.c @@ -0,0 +1,27 @@ +/* getline.c --- Implementation of replacement getline function. + Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Simon Josefsson. */ + +#include + +#include + +ssize_t +getline (char **lineptr, size_t *n, FILE *stream) +{ + return getdelim (lineptr, n, '\n', stream); +} diff --git a/grub-core/gnulib/getopt.c b/grub-core/gnulib/getopt.c new file mode 100644 index 000000000..ef0f4ceec --- /dev/null +++ b/grub-core/gnulib/getopt.c @@ -0,0 +1,1245 @@ +/* Getopt for GNU. + NOTE: getopt is part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to drepper@gnu.org + before changing it! + Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _LIBC +# include +#endif + +#include "getopt.h" + +#include +#include +#include +#include + +#ifdef _LIBC +# include +#else +# include "gettext.h" +# define _(msgid) gettext (msgid) +#endif + +#if defined _LIBC && defined USE_IN_LIBIO +# include +#endif + +/* This version of 'getopt' appears to the caller like standard Unix 'getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As 'getopt_long' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Using 'getopt' or setting the environment variable POSIXLY_CORRECT + disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "getopt_int.h" + +/* For communication from 'getopt' to the caller. + When 'getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when 'ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to 'getopt'. + + On entry to 'getopt', zero means this is the first call; initialize. + + When 'getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, 'optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Keep a global copy of all internal members of getopt_data. */ + +static struct _getopt_data getopt_data; + + +#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV +extern char *getenv (); +#endif + +#ifdef _LIBC +/* Stored original parameters. + XXX This is no good solution. We should rather copy the args so + that we can compare them later. But we must not use malloc(3). */ +extern int __libc_argc; +extern char **__libc_argv; + +/* Bash 2.0 gives us an environment variable containing flags + indicating ARGV elements that should not be considered arguments. */ + +# ifdef USE_NONOPTION_FLAGS +/* Defined in getopt_init.c */ +extern char *__getopt_nonoption_flags; +# endif + +# ifdef USE_NONOPTION_FLAGS +# define SWAP_FLAGS(ch1, ch2) \ + if (d->__nonoption_flags_len > 0) \ + { \ + char __tmp = __getopt_nonoption_flags[ch1]; \ + __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ + __getopt_nonoption_flags[ch2] = __tmp; \ + } +# else +# define SWAP_FLAGS(ch1, ch2) +# endif +#else /* !_LIBC */ +# define SWAP_FLAGS(ch1, ch2) +#endif /* _LIBC */ + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + 'first_nonopt' and 'last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (char **argv, struct _getopt_data *d) +{ + int bottom = d->__first_nonopt; + int middle = d->__last_nonopt; + int top = d->optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + /* First make sure the handling of the '__getopt_nonoption_flags' + string can work normally. Our top argument must be in the range + of the string. */ + if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len) + { + /* We must extend the array. The user plays games with us and + presents new arguments. */ + char *new_str = malloc (top + 1); + if (new_str == NULL) + d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0; + else + { + memset (__mempcpy (new_str, __getopt_nonoption_flags, + d->__nonoption_flags_max_len), + '\0', top + 1 - d->__nonoption_flags_max_len); + d->__nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; + } + } +#endif + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + SWAP_FLAGS (bottom + i, middle + i); + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + d->__first_nonopt += (d->optind - d->__last_nonopt); + d->__last_nonopt = d->optind; +} + +/* Initialize the internal data when the first call is made. */ + +static const char * +_getopt_initialize (int argc _GL_UNUSED, + char **argv _GL_UNUSED, const char *optstring, + struct _getopt_data *d, int posixly_correct) +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + d->__first_nonopt = d->__last_nonopt = d->optind; + + d->__nextchar = NULL; + + d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + d->__ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + d->__ordering = REQUIRE_ORDER; + ++optstring; + } + else if (d->__posixly_correct) + d->__ordering = REQUIRE_ORDER; + else + d->__ordering = PERMUTE; + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + if (!d->__posixly_correct + && argc == __libc_argc && argv == __libc_argv) + { + if (d->__nonoption_flags_max_len == 0) + { + if (__getopt_nonoption_flags == NULL + || __getopt_nonoption_flags[0] == '\0') + d->__nonoption_flags_max_len = -1; + else + { + const char *orig_str = __getopt_nonoption_flags; + int len = d->__nonoption_flags_max_len = strlen (orig_str); + if (d->__nonoption_flags_max_len < argc) + d->__nonoption_flags_max_len = argc; + __getopt_nonoption_flags = + (char *) malloc (d->__nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + d->__nonoption_flags_max_len = -1; + else + memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), + '\0', d->__nonoption_flags_max_len - len); + } + } + d->__nonoption_flags_len = d->__nonoption_flags_max_len; + } + else + d->__nonoption_flags_len = 0; +#endif + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If 'getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If 'getopt' finds another option character, it returns that character, + updating 'optind' and 'nextchar' so that the next call to 'getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, 'getopt' returns -1. + Then 'optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set 'opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in 'optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in 'optarg', otherwise 'optarg' is set to zero. + + If OPTSTRING starts with '-' or '+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with '--' instead of '-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a '=', or else the in next ARGV-element. + When 'getopt' finds a long-named option, it returns 0 if that option's + 'flag' field is nonzero, the value of the option's 'val' field + if the 'flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of 'struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal_r (int argc, char **argv, const char *optstring, + const struct option *longopts, int *longind, + int long_only, struct _getopt_data *d, int posixly_correct) +{ + int print_errors = d->opterr; + + if (argc < 1) + return -1; + + d->optarg = NULL; + + if (d->optind == 0 || !d->__initialized) + { + if (d->optind == 0) + d->optind = 1; /* Don't scan ARGV[0], the program name. */ + optstring = _getopt_initialize (argc, argv, optstring, d, + posixly_correct); + d->__initialized = 1; + } + else if (optstring[0] == '-' || optstring[0] == '+') + optstring++; + if (optstring[0] == ':') + print_errors = 0; + + /* Test whether ARGV[optind] points to a non-option argument. + Either it does not have option syntax, or there is an environment flag + from the shell indicating it is not an option. The later information + is only used when the used in the GNU libc. */ +#if defined _LIBC && defined USE_NONOPTION_FLAGS +# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \ + || (d->optind < d->__nonoption_flags_len \ + && __getopt_nonoption_flags[d->optind] == '1')) +#else +# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0') +#endif + + if (d->__nextchar == NULL || *d->__nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been + moved back by the user (who may also have changed the arguments). */ + if (d->__last_nonopt > d->optind) + d->__last_nonopt = d->optind; + if (d->__first_nonopt > d->optind) + d->__first_nonopt = d->optind; + + if (d->__ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (d->__first_nonopt != d->__last_nonopt + && d->__last_nonopt != d->optind) + exchange ((char **) argv, d); + else if (d->__last_nonopt != d->optind) + d->__first_nonopt = d->optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (d->optind < argc && NONOPTION_P) + d->optind++; + d->__last_nonopt = d->optind; + } + + /* The special ARGV-element '--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (d->optind != argc && !strcmp (argv[d->optind], "--")) + { + d->optind++; + + if (d->__first_nonopt != d->__last_nonopt + && d->__last_nonopt != d->optind) + exchange ((char **) argv, d); + else if (d->__first_nonopt == d->__last_nonopt) + d->__first_nonopt = d->optind; + d->__last_nonopt = argc; + + d->optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (d->optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (d->__first_nonopt != d->__last_nonopt) + d->optind = d->__first_nonopt; + return -1; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if (NONOPTION_P) + { + if (d->__ordering == REQUIRE_ORDER) + return -1; + d->optarg = argv[d->optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + d->__nextchar = (argv[d->optind] + 1 + + (longopts != NULL && argv[d->optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[d->optind][1] == '-' + || (long_only && (argv[d->optind][2] + || !strchr (optstring, argv[d->optind][1]))))) + { + char *nameend; + unsigned int namelen; + const struct option *p; + const struct option *pfound = NULL; + struct option_list + { + const struct option *p; + struct option_list *next; + } *ambig_list = NULL; + int exact = 0; + int indfound = -1; + int option_index; + + for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + namelen = nameend - d->__nextchar; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, d->__nextchar, namelen)) + { + if (namelen == (unsigned int) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else if (long_only + || pfound->has_arg != p->has_arg + || pfound->flag != p->flag + || pfound->val != p->val) + { + /* Second or later nonexact match found. */ + struct option_list *newp = malloc (sizeof (*newp)); + newp->p = p; + newp->next = ambig_list; + ambig_list = newp; + } + } + + if (ambig_list != NULL && !exact) + { + if (print_errors) + { + struct option_list first; + first.p = pfound; + first.next = ambig_list; + ambig_list = &first; + +#if defined _LIBC && defined USE_IN_LIBIO + char *buf = NULL; + size_t buflen = 0; + + FILE *fp = open_memstream (&buf, &buflen); + if (fp != NULL) + { + fprintf (fp, + _("%s: option '%s' is ambiguous; possibilities:"), + argv[0], argv[d->optind]); + + do + { + fprintf (fp, " '--%s'", ambig_list->p->name); + ambig_list = ambig_list->next; + } + while (ambig_list != NULL); + + fputc_unlocked ('\n', fp); + + if (__builtin_expect (fclose (fp) != EOF, 1)) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } + } +#else + fprintf (stderr, + _("%s: option '%s' is ambiguous; possibilities:"), + argv[0], argv[d->optind]); + do + { + fprintf (stderr, " '--%s'", ambig_list->p->name); + ambig_list = ambig_list->next; + } + while (ambig_list != NULL); + + fputc ('\n', stderr); +#endif + } + d->__nextchar += strlen (d->__nextchar); + d->optind++; + d->optopt = 0; + return '?'; + } + + while (ambig_list != NULL) + { + struct option_list *pn = ambig_list->next; + free (ambig_list); + ambig_list = pn; + } + + if (pfound != NULL) + { + option_index = indfound; + d->optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + d->optarg = nameend + 1; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + int n; +#endif + + if (argv[d->optind - 1][1] == '-') + { + /* --option */ +#if defined _LIBC && defined USE_IN_LIBIO + n = __asprintf (&buf, _("\ +%s: option '--%s' doesn't allow an argument\n"), + argv[0], pfound->name); +#else + fprintf (stderr, _("\ +%s: option '--%s' doesn't allow an argument\n"), + argv[0], pfound->name); +#endif + } + else + { + /* +option or -option */ +#if defined _LIBC && defined USE_IN_LIBIO + n = __asprintf (&buf, _("\ +%s: option '%c%s' doesn't allow an argument\n"), + argv[0], argv[d->optind - 1][0], + pfound->name); +#else + fprintf (stderr, _("\ +%s: option '%c%s' doesn't allow an argument\n"), + argv[0], argv[d->optind - 1][0], + pfound->name); +#endif + } + +#if defined _LIBC && defined USE_IN_LIBIO + if (n >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#endif + } + + d->__nextchar += strlen (d->__nextchar); + + d->optopt = pfound->val; + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (d->optind < argc) + d->optarg = argv[d->optind++]; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, _("\ +%s: option '--%s' requires an argument\n"), + argv[0], pfound->name) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, + _("%s: option '--%s' requires an argument\n"), + argv[0], pfound->name); +#endif + } + d->__nextchar += strlen (d->__nextchar); + d->optopt = pfound->val; + return optstring[0] == ':' ? ':' : '?'; + } + } + d->__nextchar += strlen (d->__nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[d->optind][1] == '-' + || strchr (optstring, *d->__nextchar) == NULL) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + int n; +#endif + + if (argv[d->optind][1] == '-') + { + /* --option */ +#if defined _LIBC && defined USE_IN_LIBIO + n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"), + argv[0], d->__nextchar); +#else + fprintf (stderr, _("%s: unrecognized option '--%s'\n"), + argv[0], d->__nextchar); +#endif + } + else + { + /* +option or -option */ +#if defined _LIBC && defined USE_IN_LIBIO + n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"), + argv[0], argv[d->optind][0], d->__nextchar); +#else + fprintf (stderr, _("%s: unrecognized option '%c%s'\n"), + argv[0], argv[d->optind][0], d->__nextchar); +#endif + } + +#if defined _LIBC && defined USE_IN_LIBIO + if (n >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#endif + } + d->__nextchar = (char *) ""; + d->optind++; + d->optopt = 0; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *d->__nextchar++; + const char *temp = strchr (optstring, c); + + /* Increment 'optind' when we start to process its last character. */ + if (*d->__nextchar == '\0') + ++d->optind; + + if (temp == NULL || c == ':' || c == ';') + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + int n; +#endif + +#if defined _LIBC && defined USE_IN_LIBIO + n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"), + argv[0], c); +#else + fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c); +#endif + +#if defined _LIBC && defined USE_IN_LIBIO + if (n >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#endif + } + d->optopt = c; + return '?'; + } + /* Convenience. Treat POSIX -W foo same as long option --foo */ + if (temp[0] == 'W' && temp[1] == ';') + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + if (longopts == NULL) + goto no_longs; + + /* This is an option that requires an argument. */ + if (*d->__nextchar != '\0') + { + d->optarg = d->__nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + d->optind++; + } + else if (d->optind == argc) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, + _("%s: option requires an argument -- '%c'\n"), + argv[0], c) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, + _("%s: option requires an argument -- '%c'\n"), + argv[0], c); +#endif + } + d->optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } + else + /* We already incremented 'd->optind' once; + increment it again when taking next ARGV-elt as argument. */ + d->optarg = argv[d->optind++]; + + /* optarg is now the argument, see if it's in the + table of longopts. */ + + for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '='; + nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) + { + if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else if (long_only + || pfound->has_arg != p->has_arg + || pfound->flag != p->flag + || pfound->val != p->val) + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"), + argv[0], d->optarg) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"), + argv[0], d->optarg); +#endif + } + d->__nextchar += strlen (d->__nextchar); + d->optind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + d->optarg = nameend + 1; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, _("\ +%s: option '-W %s' doesn't allow an argument\n"), + argv[0], pfound->name) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, _("\ +%s: option '-W %s' doesn't allow an argument\n"), + argv[0], pfound->name); +#endif + } + + d->__nextchar += strlen (d->__nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (d->optind < argc) + d->optarg = argv[d->optind++]; + else + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, _("\ +%s: option '-W %s' requires an argument\n"), + argv[0], pfound->name) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, _("\ +%s: option '-W %s' requires an argument\n"), + argv[0], pfound->name); +#endif + } + d->__nextchar += strlen (d->__nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + else + d->optarg = NULL; + d->__nextchar += strlen (d->__nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + no_longs: + d->__nextchar = NULL; + return 'W'; /* Let the application handle it. */ + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*d->__nextchar != '\0') + { + d->optarg = d->__nextchar; + d->optind++; + } + else + d->optarg = NULL; + d->__nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*d->__nextchar != '\0') + { + d->optarg = d->__nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + d->optind++; + } + else if (d->optind == argc) + { + if (print_errors) + { +#if defined _LIBC && defined USE_IN_LIBIO + char *buf; + + if (__asprintf (&buf, _("\ +%s: option requires an argument -- '%c'\n"), + argv[0], c) >= 0) + { + _IO_flockfile (stderr); + + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + + __fxprintf (NULL, "%s", buf); + + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); + + free (buf); + } +#else + fprintf (stderr, + _("%s: option requires an argument -- '%c'\n"), + argv[0], c); +#endif + } + d->optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented 'optind' once; + increment it again when taking next ARGV-elt as argument. */ + d->optarg = argv[d->optind++]; + d->__nextchar = NULL; + } + } + return c; + } +} + +int +_getopt_internal (int argc, char **argv, const char *optstring, + const struct option *longopts, int *longind, int long_only, + int posixly_correct) +{ + int result; + + getopt_data.optind = optind; + getopt_data.opterr = opterr; + + result = _getopt_internal_r (argc, argv, optstring, longopts, + longind, long_only, &getopt_data, + posixly_correct); + + optind = getopt_data.optind; + optarg = getopt_data.optarg; + optopt = getopt_data.optopt; + + return result; +} + +/* glibc gets a LSB-compliant getopt. + Standalone applications get a POSIX-compliant getopt. */ +#if _LIBC +enum { POSIXLY_CORRECT = 0 }; +#else +enum { POSIXLY_CORRECT = 1 }; +#endif + +int +getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, (char **) argv, optstring, + (const struct option *) 0, + (int *) 0, + 0, POSIXLY_CORRECT); +} + +#ifdef _LIBC +int +__posix_getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0, 1); +} +#endif + + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of 'getopt'. */ + +int +main (int argc, char **argv) +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == -1) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value '%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/grub-core/gnulib/getopt.in.h b/grub-core/gnulib/getopt.in.h new file mode 100644 index 000000000..d9c7d8144 --- /dev/null +++ b/grub-core/gnulib/getopt.in.h @@ -0,0 +1,255 @@ +/* Declarations for getopt. + Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _@GUARD_PREFIX@_GETOPT_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. We must + also inform the replacement unistd.h to not recursively use + ; our definitions will be present soon enough. */ +#if @HAVE_GETOPT_H@ +# define _GL_SYSTEM_GETOPT +# @INCLUDE_NEXT@ @NEXT_GETOPT_H@ +# undef _GL_SYSTEM_GETOPT +#endif + +#ifndef _@GUARD_PREFIX@_GETOPT_H + +#ifndef __need_getopt +# define _@GUARD_PREFIX@_GETOPT_H 1 +#endif + +/* Standalone applications should #define __GETOPT_PREFIX to an + identifier that prefixes the external functions and variables + defined in this header. When this happens, include the + headers that might declare getopt so that they will not cause + confusion if included after this file (if the system had , + we have already included it). Then systematically rename + identifiers so that they do not collide with the system functions + and variables. Renaming avoids problems with some compilers and + linkers. */ +#if defined __GETOPT_PREFIX && !defined __need_getopt +# if !@HAVE_GETOPT_H@ +# define __need_system_stdlib_h +# include +# undef __need_system_stdlib_h +# include +# include +# endif +# undef __need_getopt +# undef getopt +# undef getopt_long +# undef getopt_long_only +# undef optarg +# undef opterr +# undef optind +# undef optopt +# undef option +# define __GETOPT_CONCAT(x, y) x ## y +# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) +# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) +# define getopt __GETOPT_ID (getopt) +# define getopt_long __GETOPT_ID (getopt_long) +# define getopt_long_only __GETOPT_ID (getopt_long_only) +# define optarg __GETOPT_ID (optarg) +# define opterr __GETOPT_ID (opterr) +# define optind __GETOPT_ID (optind) +# define optopt __GETOPT_ID (optopt) +# define option __GETOPT_ID (option) +# define _getopt_internal __GETOPT_ID (getopt_internal) +#endif + +/* Standalone applications get correct prototypes for getopt_long and + getopt_long_only; they declare "char **argv". libc uses prototypes + with "char *const *argv" that are incorrect because getopt_long and + getopt_long_only can permute argv; this is required for backward + compatibility (e.g., for LSB 2.0.1). + + This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt', + but it caused redefinition warnings if both unistd.h and getopt.h were + included, since unistd.h includes getopt.h having previously defined + __need_getopt. + + The only place where __getopt_argv_const is used is in definitions + of getopt_long and getopt_long_only below, but these are visible + only if __need_getopt is not defined, so it is quite safe to rewrite + the conditional as follows: +*/ +#if !defined __need_getopt +# if defined __GETOPT_PREFIX +# define __getopt_argv_const /* empty */ +# else +# define __getopt_argv_const const +# endif +#endif + +/* If __GNU_LIBRARY__ is not already defined, either we are being used + standalone, or this is the first header included in the source file. + If we are being used with glibc, we need to include , but + that does not exist if we are standalone. So: if __GNU_LIBRARY__ is + not defined, include , which will pull in for us + if it's from glibc. (Why ctype.h? It's guaranteed to exist and it + doesn't flood the namespace with stuff the way some other headers do.) */ +#if !defined __GNU_LIBRARY__ +# include +#endif + +#ifndef __THROW +# ifndef __GNUC_PREREQ +# define __GNUC_PREREQ(maj, min) (0) +# endif +# if defined __cplusplus && __GNUC_PREREQ (2,8) +# define __THROW throw () +# else +# define __THROW +# endif +#endif + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from 'getopt' to the caller. + When 'getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when 'ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to 'getopt'. + + On entry to 'getopt', zero means this is the first call; initialize. + + When 'getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, 'optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message 'getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +#ifndef __need_getopt +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of 'struct option' terminated by an element containing a name which is + zero. + + The field 'has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field 'flag' is not NULL, it points to a variable that is set + to the value given in the field 'val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an 'int' to + a compiled-in constant, such as set a value from 'optarg', set the + option's 'flag' field to zero and its 'val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero 'flag' field, 'getopt' + returns the contents of the 'val' field. */ + +# if !GNULIB_defined_struct_option +struct option +{ + const char *name; + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; +# define GNULIB_defined_struct_option 1 +# endif + +/* Names for the values of the 'has_arg' field of 'struct option'. */ + +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 +#endif /* need getopt */ + + +/* Get definitions and prototypes for functions to process the + arguments in ARGV (ARGC of them, minus the program name) for + options given in OPTS. + + Return the option character from OPTS just read. Return -1 when + there are no more options. For unrecognized options, or options + missing arguments, 'optopt' is set to the option letter, and '?' is + returned. + + The OPTS string is a list of characters which are recognized option + letters, optionally followed by colons, specifying that that letter + takes an argument, to be placed in 'optarg'. + + If a letter in OPTS is followed by two colons, its argument is + optional. This behavior is specific to the GNU 'getopt'. + + The argument '--' causes premature termination of argument + scanning, explicitly telling 'getopt' that there are no more + options. + + If OPTS begins with '-', then non-option arguments are treated as + arguments to the option '\1'. This behavior is specific to the GNU + 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in + the environment, then do not permute arguments. */ + +extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) + __THROW _GL_ARG_NONNULL ((2, 3)); + +#ifndef __need_getopt +extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind) + __THROW _GL_ARG_NONNULL ((2, 3)); +extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind) + __THROW _GL_ARG_NONNULL ((2, 3)); + +#endif + +#ifdef __cplusplus +} +#endif + +/* Make sure we later can get all the definitions and declarations. */ +#undef __need_getopt + +#endif /* _@GUARD_PREFIX@_GETOPT_H */ +#endif /* _@GUARD_PREFIX@_GETOPT_H */ diff --git a/grub-core/gnulib/getopt1.c b/grub-core/gnulib/getopt1.c new file mode 100644 index 000000000..55a6b4eae --- /dev/null +++ b/grub-core/gnulib/getopt1.c @@ -0,0 +1,170 @@ +/* getopt_long and getopt_long_only entry points for GNU getopt. + Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef _LIBC +# include +#else +# include +# include "getopt.h" +#endif +#include "getopt_int.h" + +#include + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +#include +#endif + +#ifndef NULL +#define NULL 0 +#endif + +int +getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, + const struct option *long_options, int *opt_index) +{ + return _getopt_internal (argc, (char **) argv, options, long_options, + opt_index, 0, 0); +} + +int +_getopt_long_r (int argc, char **argv, const char *options, + const struct option *long_options, int *opt_index, + struct _getopt_data *d) +{ + return _getopt_internal_r (argc, argv, options, long_options, opt_index, + 0, d, 0); +} + +/* Like getopt_long, but '-' as well as '--' can indicate a long option. + If an option that starts with '-' (not '--') doesn't match a long option, + but does match a short option, it is parsed as a short option + instead. */ + +int +getopt_long_only (int argc, char *__getopt_argv_const *argv, + const char *options, + const struct option *long_options, int *opt_index) +{ + return _getopt_internal (argc, (char **) argv, options, long_options, + opt_index, 1, 0); +} + +int +_getopt_long_only_r (int argc, char **argv, const char *options, + const struct option *long_options, int *opt_index, + struct _getopt_data *d) +{ + return _getopt_internal_r (argc, argv, options, long_options, opt_index, + 1, d, 0); +} + + +#ifdef TEST + +#include + +int +main (int argc, char **argv) +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static const struct option long_options[] = + { + {"add", 1, 0, 0}, + {"append", 0, 0, 0}, + {"delete", 1, 0, 0}, + {"verbose", 0, 0, 0}, + {"create", 0, 0, 0}, + {"file", 1, 0, 0}, + {0, 0, 0, 0} + }; + + c = getopt_long (argc, argv, "abc:d:0123456789", + long_options, &option_index); + if (c == -1) + break; + + switch (c) + { + case 0: + printf ("option %s", long_options[option_index].name); + if (optarg) + printf (" with arg %s", optarg); + printf ("\n"); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value '%s'\n", optarg); + break; + + case 'd': + printf ("option d with value '%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/grub-core/gnulib/getopt_int.h b/grub-core/gnulib/getopt_int.h new file mode 100644 index 000000000..a6e4b9ea7 --- /dev/null +++ b/grub-core/gnulib/getopt_int.h @@ -0,0 +1,135 @@ +/* Internal declarations for getopt. + Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GETOPT_INT_H +#define _GETOPT_INT_H 1 + +#include + +extern int _getopt_internal (int ___argc, char **___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only, int __posixly_correct); + + +/* Reentrant versions which can handle parsing multiple argument + vectors at the same time. */ + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using '+' as the first character + of the list of option characters, or by calling getopt. + + PERMUTE is the default. We permute the contents of ARGV as we + scan, so that eventually all the non-options are at the end. + This allows options to be given in any order, even with programs + that were not written to expect this. + + RETURN_IN_ORDER is an option available to programs that were + written to expect options and other ARGV-elements in any order + and that care about the ordering of the two. We describe each + non-option ARGV-element as if it were the argument of an option + with character code 1. Using '-' as the first character of the + list of option characters selects this mode of operation. + + The special argument '--' forces an end of option-scanning regardless + of the value of 'ordering'. In the case of RETURN_IN_ORDER, only + '--' can cause 'getopt' to return -1 with 'optind' != ARGC. */ + +enum __ord + { + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER + }; + +/* Data type for reentrant functions. */ +struct _getopt_data +{ + /* These have exactly the same meaning as the corresponding global + variables, except that they are used for the reentrant + versions of getopt. */ + int optind; + int opterr; + int optopt; + char *optarg; + + /* Internal members. */ + + /* True if the internal members have been initialized. */ + int __initialized; + + /* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + char *__nextchar; + + /* See __ord above. */ + enum __ord __ordering; + + /* If the POSIXLY_CORRECT environment variable is set + or getopt was called. */ + int __posixly_correct; + + + /* Handle permutation of arguments. */ + + /* Describe the part of ARGV that contains non-options that have + been skipped. 'first_nonopt' is the index in ARGV of the first + of them; 'last_nonopt' is the index after the last of them. */ + + int __first_nonopt; + int __last_nonopt; + +#if defined _LIBC && defined USE_NONOPTION_FLAGS + int __nonoption_flags_max_len; + int __nonoption_flags_len; +#endif +}; + +/* The initializer is necessary to set OPTIND and OPTERR to their + default values and to clear the initialization flag. */ +#define _GETOPT_DATA_INITIALIZER { 1, 1 } + +extern int _getopt_internal_r (int ___argc, char **___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only, struct _getopt_data *__data, + int __posixly_correct); + +extern int _getopt_long_r (int ___argc, char **___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + struct _getopt_data *__data); + +extern int _getopt_long_only_r (int ___argc, char **___argv, + const char *__shortopts, + const struct option *__longopts, + int *__longind, + struct _getopt_data *__data); + +#endif /* getopt_int.h */ diff --git a/grub-core/gnulib/gettext.h b/grub-core/gnulib/gettext.h new file mode 100644 index 000000000..d0215715a --- /dev/null +++ b/grub-core/gnulib/gettext.h @@ -0,0 +1,288 @@ +/* Convenience header for conditional use of GNU . + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include + +/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by + the gettext() and ngettext() macros. This is an alternative to calling + textdomain(), and is useful for libraries. */ +# ifdef DEFAULT_TEXT_DOMAIN +# undef gettext +# define gettext(Msgid) \ + dgettext (DEFAULT_TEXT_DOMAIN, Msgid) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) +# endif + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of a NOP. We don't include + as well because people using "gettext.h" will not include , + and also including would fail on SunOS 4, whereas + is OK. */ +#if defined(__sun) +# include +#endif + +/* Many header files from the libstdc++ coming with g++ 3.3 or newer include + , which chokes if dcgettext is defined as a macro. So include + it now, to make later inclusions of a NOP. */ +#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) +# include +# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H +# include +# endif +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# undef gettext +# define gettext(Msgid) ((const char *) (Msgid)) +# undef dgettext +# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) +# undef dcgettext +# define dcgettext(Domainname, Msgid, Category) \ + ((void) (Category), dgettext (Domainname, Msgid)) +# undef ngettext +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 \ + ? ((void) (Msgid2), (const char *) (Msgid1)) \ + : ((void) (Msgid1), (const char *) (Msgid2))) +# undef dngettext +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) +# undef dcngettext +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N)) +# undef textdomain +# define textdomain(Domainname) ((const char *) (Domainname)) +# undef bindtextdomain +# define bindtextdomain(Domainname, Dirname) \ + ((void) (Domainname), (const char *) (Dirname)) +# undef bind_textdomain_codeset +# define bind_textdomain_codeset(Domainname, Codeset) \ + ((void) (Domainname), (const char *) (Codeset)) + +#endif + +/* Prefer gnulib's setlocale override over libintl's setlocale override. */ +#ifdef GNULIB_defined_setlocale +# undef setlocale +# define setlocale rpl_setlocale +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +/* The separator between msgctxt and msgid in a .mo file. */ +#define GETTEXT_CONTEXT_GLUE "\004" + +/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a + MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be + short and rarely need to change. + The letter 'p' stands for 'particular' or 'special'. */ +#ifdef DEFAULT_TEXT_DOMAIN +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#else +# define pgettext(Msgctxt, Msgid) \ + pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#endif +#define dpgettext(Domainname, Msgctxt, Msgid) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) +#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) +#ifdef DEFAULT_TEXT_DOMAIN +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#else +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#endif +#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +pgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + int category) +{ + const char *translation = dcgettext (domain, msg_ctxt_id, category); + if (translation == msg_ctxt_id) + return msgid; + else + return translation; +} + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +npgettext_aux (const char *domain, + const char *msg_ctxt_id, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + const char *translation = + dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); + if (translation == msg_ctxt_id || translation == msgid_plural) + return (n == 1 ? msgid : msgid_plural); + else + return translation; +} + +/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID + can be arbitrary expressions. But for string literals these macros are + less efficient than those above. */ + +#include + +#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \ + /* || __STDC_VERSION__ >= 199901L */ ) +# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 +#else +# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 +#endif + +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +#include +#endif + +#define pgettext_expr(Msgctxt, Msgid) \ + dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ + dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcgettext (domain, msg_ctxt_id, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (translation != msg_ctxt_id) + return translation; + } + return msgid; +} + +#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ + dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static const char * +dcnpgettext_expr (const char *domain, + const char *msgctxt, const char *msgid, + const char *msgid_plural, unsigned long int n, + int category) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + char msg_ctxt_id[msgctxt_len + msgid_len]; +#else + char buf[1024]; + char *msg_ctxt_id = + (msgctxt_len + msgid_len <= sizeof (buf) + ? buf + : (char *) malloc (msgctxt_len + msgid_len)); + if (msg_ctxt_id != NULL) +#endif + { + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS + if (msg_ctxt_id != buf) + free (msg_ctxt_id); +#endif + if (!(translation == msg_ctxt_id || translation == msgid_plural)) + return translation; + } + return (n == 1 ? msgid : msgid_plural); +} + +#endif /* _LIBGETTEXT_H */ diff --git a/grub-core/gnulib/intprops.h b/grub-core/gnulib/intprops.h new file mode 100644 index 000000000..b473052d1 --- /dev/null +++ b/grub-core/gnulib/intprops.h @@ -0,0 +1,319 @@ +/* intprops.h -- properties of integer types + + Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_INTPROPS_H +#define _GL_INTPROPS_H + +#include + +/* Return an integer value, converted to the same type as the integer + expression E after integer type promotion. V is the unconverted value. */ +#define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) + +/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see + . */ +#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if negative values of the signed integer type T use two's + complement, ones' complement, or signed magnitude representation, + respectively. Much GNU code assumes two's complement, but some + people like to be portable to all possible C hosts. */ +#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) +#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) +#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) + +/* True if the signed integer expression E uses two's complement. */ +#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1) + +/* True if the arithmetic type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Return 1 if the integer expression E, after integer promotion, has + a signed type. */ +#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) + + +/* Minimum and maximum values for integer types and expressions. These + macros have undefined behavior if T is signed and has padding bits. + If this is a problem for you, please let us know how to fix it for + your host. */ + +/* The maximum and minimum values for the integer type T. */ +#define TYPE_MINIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ TYPE_MAXIMUM (t))) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) + +/* The maximum and minimum values for the type of the expression E, + after integer promotion. E should not have side effects. */ +#define _GL_INT_MINIMUM(e) \ + (_GL_INT_SIGNED (e) \ + ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_CONVERT (e, 0)) +#define _GL_INT_MAXIMUM(e) \ + (_GL_INT_SIGNED (e) \ + ? _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_NEGATE_CONVERT (e, 1)) +#define _GL_SIGNED_INT_MAXIMUM(e) \ + (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) + + +/* Return 1 if the __typeof__ keyword works. This could be done by + 'configure', but for now it's easier to do it by hand. */ +#if 2 <= __GNUC__ || 0x5110 <= __SUNPRO_C +# define _GL_HAVE___TYPEOF__ 1 +#else +# define _GL_HAVE___TYPEOF__ 0 +#endif + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argument, + and expands to an integer constant expression. */ +#if _GL_HAVE___TYPEOF__ +# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define _GL_SIGNED_TYPE_OR_EXPR(t) 1 +#endif + +/* Bound on length of the string representing an unsigned integer + value representable in B bits. log10 (2.0) < 146/485. The + smallest value of B where this bound is not tight is 2621. */ +#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) + +/* Bound on length of the string representing an integer type or expression T. + Subtract 1 for the sign bit if T is signed, and then add 1 more for + a minus sign if needed. + + Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is + signed, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ +#define INT_STRLEN_BOUND(t) \ + (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ + - _GL_SIGNED_TYPE_OR_EXPR (t)) \ + + _GL_SIGNED_TYPE_OR_EXPR (t)) + +/* Bound on buffer size needed to represent an integer type or expression T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) + + +/* Range overflow checks. + + The INT__RANGE_OVERFLOW macros return 1 if the corresponding C + operators might not yield numerically correct answers due to + arithmetic overflow. They do not rely on undefined or + implementation-defined behavior. Their implementations are simple + and straightforward, but they are a bit harder to use than the + INT__OVERFLOW macros described below. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + Restrictions on *_RANGE_OVERFLOW macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, + so the arguments should not have side effects. The arithmetic + arguments (including the MIN and MAX arguments) must be of the same + integer type after the usual arithmetic conversions, and the type + must have minimum value MIN and maximum MAX. Unsigned types should + use a zero MIN of the proper type. + + These macros are tuned for constant MIN and MAX. For commutative + operations such as A + B, they are also tuned for constant B. */ + +/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (a) < (min) - (b) \ + : (max) - (b) < (a)) + +/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (max) + (b) < (a) \ + : (a) < (min) + (b)) + +/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ + ((min) < 0 \ + ? (a) < - (max) \ + : 0 < (a)) + +/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Avoid && and || as they tickle + bugs in Sun C 5.11 2010/08/13 and other compilers; see + . */ +#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (a) < (max) / (b) \ + : (b) == -1 \ + ? 0 \ + : (min) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (a) < (min) / (b) \ + : (max) / (b) < (a))) + +/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. */ +#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ + ((min) < 0 && (b) == -1 && (a) < - (max)) + +/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. + Mathematically, % should never overflow, but on x86-like hosts + INT_MIN % -1 traps, and the C standard permits this, so treat this + as an overflow too. */ +#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ + INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max) + +/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Here, MIN and MAX are for A only, and B need + not be of the same type as the other arguments. The C standard says that + behavior is undefined for shifts unless 0 <= B < wordwidth, and that when + A is negative then A << B has undefined behavior and A >> B has + implementation-defined behavior, but do not check these other + restrictions. */ +#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ + ((a) < 0 \ + ? (a) < (min) >> (b) \ + : (max) >> (b) < (a)) + + +/* The _GL*_OVERFLOW macros have the same restrictions as the + *_RANGE_OVERFLOW macros, except that they do not assume that operands + (e.g., A and B) have the same type as MIN and MAX. Instead, they assume + that the result (e.g., A + B) has that type. */ +#define _GL_ADD_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? (b) <= (a) + (b) \ + : (b) < 0 ? (a) <= (a) + (b) \ + : (a) + (b) < (b)) +#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? 1 \ + : (b) < 0 ? (a) - (b) <= (a) \ + : (a) < (b)) +#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ + || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) +#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (b) <= (a) + (b) - 1 \ + : (b) < 0 && (a) + (b) <= (a)) +#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ + : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) + +/* Return a nonzero value if A is a mathematical multiple of B, where + A is unsigned, B is negative, and MAX is the maximum value of A's + type. A's type must be the same as (A % B)'s type. Normally (A % + -B == 0) suffices, but things get tricky if -B would overflow. */ +#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \ + (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \ + ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \ + ? (a) \ + : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \ + : (a) % - (b)) \ + == 0) + + +/* Integer overflow checks. + + The INT__OVERFLOW macros return 1 if the corresponding C operators + might not yield numerically correct answers due to arithmetic overflow. + They work correctly on all known practical hosts, and do not rely + on undefined behavior due to signed arithmetic overflow. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_OVERFLOW (i, j)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + These macros are tuned for their last argument being a constant. + + Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, + A % B, and A << B would overflow, respectively. */ + +#define INT_ADD_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) +#define INT_SUBTRACT_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) +#define INT_NEGATE_OVERFLOW(a) \ + INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) +#define INT_MULTIPLY_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) +#define INT_DIVIDE_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW) +#define INT_REMAINDER_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW) +#define INT_LEFT_SHIFT_OVERFLOW(a, b) \ + INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \ + _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) + +/* Return 1 if the expression A B would overflow, + where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, + assuming MIN and MAX are the minimum and maximum for the result type. + Arguments should be free of side effects. */ +#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ + op_result_overflow (a, b, \ + _GL_INT_MINIMUM (0 * (b) + (a)), \ + _GL_INT_MAXIMUM (0 * (b) + (a))) + +#endif /* _GL_INTPROPS_H */ diff --git a/grub-core/gnulib/itold.c b/grub-core/gnulib/itold.c new file mode 100644 index 000000000..9aabc7e46 --- /dev/null +++ b/grub-core/gnulib/itold.c @@ -0,0 +1,28 @@ +/* Replacement for 'int' to 'long double' conversion routine. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +void +_Qp_itoq (long double *result, int a) +{ + /* Convert from 'int' to 'double', then from 'double' to 'long double'. */ + *result = (double) a; +} diff --git a/grub-core/gnulib/langinfo.in.h b/grub-core/gnulib/langinfo.in.h new file mode 100644 index 000000000..5388ce624 --- /dev/null +++ b/grub-core/gnulib/langinfo.in.h @@ -0,0 +1,176 @@ +/* Substitute for and wrapper around . + Copyright (C) 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* + * POSIX for platforms that lack it or have an incomplete one. + * + */ + +#ifndef _@GUARD_PREFIX@_LANGINFO_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_LANGINFO_H@ +# @INCLUDE_NEXT@ @NEXT_LANGINFO_H@ +#endif + +#ifndef _@GUARD_PREFIX@_LANGINFO_H +#define _@GUARD_PREFIX@_LANGINFO_H + + +#if !@HAVE_LANGINFO_H@ + +/* A platform that lacks . */ + +/* Assume that it also lacks and the nl_item type. */ +# if !GNULIB_defined_nl_item +typedef int nl_item; +# define GNULIB_defined_nl_item 1 +# endif + +/* nl_langinfo items of the LC_CTYPE category */ +# define CODESET 10000 +/* nl_langinfo items of the LC_NUMERIC category */ +# define RADIXCHAR 10001 +# define THOUSEP 10002 +/* nl_langinfo items of the LC_TIME category */ +# define D_T_FMT 10003 +# define D_FMT 10004 +# define T_FMT 10005 +# define T_FMT_AMPM 10006 +# define AM_STR 10007 +# define PM_STR 10008 +# define DAY_1 10009 +# define DAY_2 (DAY_1 + 1) +# define DAY_3 (DAY_1 + 2) +# define DAY_4 (DAY_1 + 3) +# define DAY_5 (DAY_1 + 4) +# define DAY_6 (DAY_1 + 5) +# define DAY_7 (DAY_1 + 6) +# define ABDAY_1 10016 +# define ABDAY_2 (ABDAY_1 + 1) +# define ABDAY_3 (ABDAY_1 + 2) +# define ABDAY_4 (ABDAY_1 + 3) +# define ABDAY_5 (ABDAY_1 + 4) +# define ABDAY_6 (ABDAY_1 + 5) +# define ABDAY_7 (ABDAY_1 + 6) +# define MON_1 10023 +# define MON_2 (MON_1 + 1) +# define MON_3 (MON_1 + 2) +# define MON_4 (MON_1 + 3) +# define MON_5 (MON_1 + 4) +# define MON_6 (MON_1 + 5) +# define MON_7 (MON_1 + 6) +# define MON_8 (MON_1 + 7) +# define MON_9 (MON_1 + 8) +# define MON_10 (MON_1 + 9) +# define MON_11 (MON_1 + 10) +# define MON_12 (MON_1 + 11) +# define ABMON_1 10035 +# define ABMON_2 (ABMON_1 + 1) +# define ABMON_3 (ABMON_1 + 2) +# define ABMON_4 (ABMON_1 + 3) +# define ABMON_5 (ABMON_1 + 4) +# define ABMON_6 (ABMON_1 + 5) +# define ABMON_7 (ABMON_1 + 6) +# define ABMON_8 (ABMON_1 + 7) +# define ABMON_9 (ABMON_1 + 8) +# define ABMON_10 (ABMON_1 + 9) +# define ABMON_11 (ABMON_1 + 10) +# define ABMON_12 (ABMON_1 + 11) +# define ERA 10047 +# define ERA_D_FMT 10048 +# define ERA_D_T_FMT 10049 +# define ERA_T_FMT 10050 +# define ALT_DIGITS 10051 +/* nl_langinfo items of the LC_MONETARY category */ +# define CRNCYSTR 10052 +/* nl_langinfo items of the LC_MESSAGES category */ +# define YESEXPR 10053 +# define NOEXPR 10054 + +#else + +/* A platform that has . */ + +# if !@HAVE_LANGINFO_CODESET@ +# define CODESET 10000 +# define GNULIB_defined_CODESET 1 +# endif + +# if !@HAVE_LANGINFO_T_FMT_AMPM@ +# define T_FMT_AMPM 10006 +# define GNULIB_defined_T_FMT_AMPM 1 +# endif + +# if !@HAVE_LANGINFO_ERA@ +# define ERA 10047 +# define ERA_D_FMT 10048 +# define ERA_D_T_FMT 10049 +# define ERA_T_FMT 10050 +# define ALT_DIGITS 10051 +# define GNULIB_defined_ERA 1 +# endif + +# if !@HAVE_LANGINFO_YESEXPR@ +# define YESEXPR 10053 +# define NOEXPR 10054 +# define GNULIB_defined_YESEXPR 1 +# endif + +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* Declare overridden functions. */ + + +/* Return a piece of locale dependent information. + Note: The difference between nl_langinfo (CODESET) and locale_charset () + is that the latter normalizes the encoding names to GNU conventions. */ + +#if @GNULIB_NL_LANGINFO@ +# if @REPLACE_NL_LANGINFO@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef nl_langinfo +# define nl_langinfo rpl_nl_langinfo +# endif +_GL_FUNCDECL_RPL (nl_langinfo, char *, (nl_item item)); +_GL_CXXALIAS_RPL (nl_langinfo, char *, (nl_item item)); +# else +# if !@HAVE_NL_LANGINFO@ +_GL_FUNCDECL_SYS (nl_langinfo, char *, (nl_item item)); +# endif +_GL_CXXALIAS_SYS (nl_langinfo, char *, (nl_item item)); +# endif +_GL_CXXALIASWARN (nl_langinfo); +#elif defined GNULIB_POSIXCHECK +# undef nl_langinfo +# if HAVE_RAW_DECL_NL_LANGINFO +_GL_WARN_ON_USE (nl_langinfo, "nl_langinfo is not portable - " + "use gnulib module nl_langinfo for portability"); +# endif +#endif + + +#endif /* _@GUARD_PREFIX@_LANGINFO_H */ +#endif /* _@GUARD_PREFIX@_LANGINFO_H */ diff --git a/grub-core/gnulib/localcharset.c b/grub-core/gnulib/localcharset.c new file mode 100644 index 000000000..953cc1e70 --- /dev/null +++ b/grub-core/gnulib/localcharset.c @@ -0,0 +1,553 @@ +/* Determine a canonical name for the current locale's character encoding. + + Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +/* Written by Bruno Haible . */ + +#include + +/* Specification. */ +#include "localcharset.h" + +#include +#include +#include +#include +#include + +#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET +# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */ +#endif + +#if defined _WIN32 || defined __WIN32__ +# define WINDOWS_NATIVE +#endif + +#if defined __EMX__ +/* Assume EMX program runs on OS/2, even if compiled under DOS. */ +# ifndef OS2 +# define OS2 +# endif +#endif + +#if !defined WINDOWS_NATIVE +# include +# if HAVE_LANGINFO_CODESET +# include +# else +# if 0 /* see comment below */ +# include +# endif +# endif +# ifdef __CYGWIN__ +# define WIN32_LEAN_AND_MEAN +# include +# endif +#elif defined WINDOWS_NATIVE +# define WIN32_LEAN_AND_MEAN +# include +#endif +#if defined OS2 +# define INCL_DOS +# include +#endif + +#if ENABLE_RELOCATABLE +# include "relocatable.h" +#else +# define relocate(pathname) (pathname) +#endif + +/* Get LIBDIR. */ +#ifndef LIBDIR +# include "configmake.h" +#endif + +/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */ +#ifndef O_NOFOLLOW +# define O_NOFOLLOW 0 +#endif + +#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ + /* Native Windows, Cygwin, OS/2, DOS */ +# define ISSLASH(C) ((C) == '/' || (C) == '\\') +#endif + +#ifndef DIRECTORY_SEPARATOR +# define DIRECTORY_SEPARATOR '/' +#endif + +#ifndef ISSLASH +# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) +#endif + +#if HAVE_DECL_GETC_UNLOCKED +# undef getc +# define getc getc_unlocked +#endif + +/* The following static variable is declared 'volatile' to avoid a + possible multithread problem in the function get_charset_aliases. If we + are running in a threaded environment, and if two threads initialize + 'charset_aliases' simultaneously, both will produce the same value, + and everything will be ok if the two assignments to 'charset_aliases' + are atomic. But I don't know what will happen if the two assignments mix. */ +#if __STDC__ != 1 +# define volatile /* empty */ +#endif +/* Pointer to the contents of the charset.alias file, if it has already been + read, else NULL. Its format is: + ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */ +static const char * volatile charset_aliases; + +/* Return a pointer to the contents of the charset.alias file. */ +static const char * +get_charset_aliases (void) +{ + const char *cp; + + cp = charset_aliases; + if (cp == NULL) + { +#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__) + const char *dir; + const char *base = "charset.alias"; + char *file_name; + + /* Make it possible to override the charset.alias location. This is + necessary for running the testsuite before "make install". */ + dir = getenv ("CHARSETALIASDIR"); + if (dir == NULL || dir[0] == '\0') + dir = relocate (LIBDIR); + + /* Concatenate dir and base into freshly allocated file_name. */ + { + size_t dir_len = strlen (dir); + size_t base_len = strlen (base); + int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); + file_name = (char *) malloc (dir_len + add_slash + base_len + 1); + if (file_name != NULL) + { + memcpy (file_name, dir, dir_len); + if (add_slash) + file_name[dir_len] = DIRECTORY_SEPARATOR; + memcpy (file_name + dir_len + add_slash, base, base_len + 1); + } + } + + if (file_name == NULL) + /* Out of memory. Treat the file as empty. */ + cp = ""; + else + { + int fd; + + /* Open the file. Reject symbolic links on platforms that support + O_NOFOLLOW. This is a security feature. Without it, an attacker + could retrieve parts of the contents (namely, the tail of the + first line that starts with "* ") of an arbitrary file by placing + a symbolic link to that file under the name "charset.alias" in + some writable directory and defining the environment variable + CHARSETALIASDIR to point to that directory. */ + fd = open (file_name, + O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + /* File not found. Treat it as empty. */ + cp = ""; + else + { + FILE *fp; + + fp = fdopen (fd, "r"); + if (fp == NULL) + { + /* Out of memory. Treat the file as empty. */ + close (fd); + cp = ""; + } + else + { + /* Parse the file's contents. */ + char *res_ptr = NULL; + size_t res_size = 0; + + for (;;) + { + int c; + char buf1[50+1]; + char buf2[50+1]; + size_t l1, l2; + char *old_res_ptr; + + c = getc (fp); + if (c == EOF) + break; + if (c == '\n' || c == ' ' || c == '\t') + continue; + if (c == '#') + { + /* Skip comment, to end of line. */ + do + c = getc (fp); + while (!(c == EOF || c == '\n')); + if (c == EOF) + break; + continue; + } + ungetc (c, fp); + if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) + break; + l1 = strlen (buf1); + l2 = strlen (buf2); + old_res_ptr = res_ptr; + if (res_size == 0) + { + res_size = l1 + 1 + l2 + 1; + res_ptr = (char *) malloc (res_size + 1); + } + else + { + res_size += l1 + 1 + l2 + 1; + res_ptr = (char *) realloc (res_ptr, res_size + 1); + } + if (res_ptr == NULL) + { + /* Out of memory. */ + res_size = 0; + free (old_res_ptr); + break; + } + strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); + strcpy (res_ptr + res_size - (l2 + 1), buf2); + } + fclose (fp); + if (res_size == 0) + cp = ""; + else + { + *(res_ptr + res_size) = '\0'; + cp = res_ptr; + } + } + } + + free (file_name); + } + +#else + +# if defined DARWIN7 + /* To avoid the trouble of installing a file that is shared by many + GNU packages -- many packaging systems have problems with this --, + simply inline the aliases here. */ + cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-4" "\0" "ISO-8859-4" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + "ISO8859-13" "\0" "ISO-8859-13" "\0" + "ISO8859-15" "\0" "ISO-8859-15" "\0" + "KOI8-R" "\0" "KOI8-R" "\0" + "KOI8-U" "\0" "KOI8-U" "\0" + "CP866" "\0" "CP866" "\0" + "CP949" "\0" "CP949" "\0" + "CP1131" "\0" "CP1131" "\0" + "CP1251" "\0" "CP1251" "\0" + "eucCN" "\0" "GB2312" "\0" + "GB2312" "\0" "GB2312" "\0" + "eucJP" "\0" "EUC-JP" "\0" + "eucKR" "\0" "EUC-KR" "\0" + "Big5" "\0" "BIG5" "\0" + "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" + "GBK" "\0" "GBK" "\0" + "GB18030" "\0" "GB18030" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "ARMSCII-8" "\0" "ARMSCII-8" "\0" + "PT154" "\0" "PT154" "\0" + /*"ISCII-DEV" "\0" "?" "\0"*/ + "*" "\0" "UTF-8" "\0"; +# endif + +# if defined VMS + /* To avoid the troubles of an extra file charset.alias_vms in the + sources of many GNU packages, simply inline the aliases here. */ + /* The list of encodings is taken from the OpenVMS 7.3-1 documentation + "Compaq C Run-Time Library Reference Manual for OpenVMS systems" + section 10.7 "Handling Different Character Sets". */ + cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-8" "\0" "ISO-8859-8" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + /* Japanese */ + "eucJP" "\0" "EUC-JP" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "DECKANJI" "\0" "DEC-KANJI" "\0" + "SDECKANJI" "\0" "EUC-JP" "\0" + /* Chinese */ + "eucTW" "\0" "EUC-TW" "\0" + "DECHANYU" "\0" "DEC-HANYU" "\0" + "DECHANZI" "\0" "GB2312" "\0" + /* Korean */ + "DECKOREAN" "\0" "EUC-KR" "\0"; +# endif + +# if defined WINDOWS_NATIVE || defined __CYGWIN__ + /* To avoid the troubles of installing a separate file in the same + directory as the DLL and of retrieving the DLL's directory at + runtime, simply inline the aliases here. */ + + cp = "CP936" "\0" "GBK" "\0" + "CP1361" "\0" "JOHAB" "\0" + "CP20127" "\0" "ASCII" "\0" + "CP20866" "\0" "KOI8-R" "\0" + "CP20936" "\0" "GB2312" "\0" + "CP21866" "\0" "KOI8-RU" "\0" + "CP28591" "\0" "ISO-8859-1" "\0" + "CP28592" "\0" "ISO-8859-2" "\0" + "CP28593" "\0" "ISO-8859-3" "\0" + "CP28594" "\0" "ISO-8859-4" "\0" + "CP28595" "\0" "ISO-8859-5" "\0" + "CP28596" "\0" "ISO-8859-6" "\0" + "CP28597" "\0" "ISO-8859-7" "\0" + "CP28598" "\0" "ISO-8859-8" "\0" + "CP28599" "\0" "ISO-8859-9" "\0" + "CP28605" "\0" "ISO-8859-15" "\0" + "CP38598" "\0" "ISO-8859-8" "\0" + "CP51932" "\0" "EUC-JP" "\0" + "CP51936" "\0" "GB2312" "\0" + "CP51949" "\0" "EUC-KR" "\0" + "CP51950" "\0" "EUC-TW" "\0" + "CP54936" "\0" "GB18030" "\0" + "CP65001" "\0" "UTF-8" "\0"; +# endif +#endif + + charset_aliases = cp; + } + + return cp; +} + +/* Determine the current locale's character encoding, and canonicalize it + into one of the canonical names listed in config.charset. + The result must not be freed; it is statically allocated. + If the canonical name cannot be determined, the result is a non-canonical + name. */ + +#ifdef STATIC +STATIC +#endif +const char * +locale_charset (void) +{ + const char *codeset; + const char *aliases; + +#if !(defined WINDOWS_NATIVE || defined OS2) + +# if HAVE_LANGINFO_CODESET + + /* Most systems support nl_langinfo (CODESET) nowadays. */ + codeset = nl_langinfo (CODESET); + +# ifdef __CYGWIN__ + /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always + returns "US-ASCII". Return the suffix of the locale name from the + environment variables (if present) or the codepage as a number. */ + if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) + { + const char *locale; + static char buf[2 + 10 + 1]; + + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } + if (locale != NULL && locale[0] != '\0') + { + /* If the locale name contains an encoding after the dot, return + it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + } + + /* The Windows API has a function returning the locale's codepage as a + number: GetACP(). This encoding is used by Cygwin, unless the user + has set the environment variable CYGWIN=codepage:oem (which very few + people do). + Output directed to console windows needs to be converted (to + GetOEMCP() if the console is using a raster font, or to + GetConsoleOutputCP() if it is using a TrueType font). Cygwin does + this conversion transparently (see winsup/cygwin/fhandler_console.cc), + converting to GetConsoleOutputCP(). This leads to correct results, + except when SetConsoleOutputCP has been called and a raster font is + in use. */ + sprintf (buf, "CP%u", GetACP ()); + codeset = buf; + } +# endif + +# else + + /* On old systems which lack it, use setlocale or getenv. */ + const char *locale = NULL; + + /* But most old systems don't have a complete set of locales. Some + (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't + use setlocale here; it would return "C" when it doesn't support the + locale name the user has set. */ +# if 0 + locale = setlocale (LC_CTYPE, NULL); +# endif + if (locale == NULL || locale[0] == '\0') + { + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } + } + + /* On some old systems, one used to set locale = "iso8859_1". On others, + you set it to "language_COUNTRY.charset". In any case, we resolve it + through the charset.alias file. */ + codeset = locale; + +# endif + +#elif defined WINDOWS_NATIVE + + static char buf[2 + 10 + 1]; + + /* The Windows API has a function returning the locale's codepage as a + number: GetACP(). + When the output goes to a console window, it needs to be provided in + GetOEMCP() encoding if the console is using a raster font, or in + GetConsoleOutputCP() encoding if it is using a TrueType font. + But in GUI programs and for output sent to files and pipes, GetACP() + encoding is the best bet. */ + sprintf (buf, "CP%u", GetACP ()); + codeset = buf; + +#elif defined OS2 + + const char *locale; + static char buf[2 + 10 + 1]; + ULONG cp[3]; + ULONG cplen; + + /* Allow user to override the codeset, as set in the operating system, + with standard language environment variables. */ + locale = getenv ("LC_ALL"); + if (locale == NULL || locale[0] == '\0') + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } + if (locale != NULL && locale[0] != '\0') + { + /* If the locale name contains an encoding after the dot, return it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + + /* Resolve through the charset.alias file. */ + codeset = locale; + } + else + { + /* OS/2 has a function returning the locale's codepage as a number. */ + if (DosQueryCp (sizeof (cp), cp, &cplen)) + codeset = ""; + else + { + sprintf (buf, "CP%u", cp[0]); + codeset = buf; + } + } + +#endif + + if (codeset == NULL) + /* The canonical name cannot be determined. */ + codeset = ""; + + /* Resolve alias. */ + for (aliases = get_charset_aliases (); + *aliases != '\0'; + aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) + if (strcmp (codeset, aliases) == 0 + || (aliases[0] == '*' && aliases[1] == '\0')) + { + codeset = aliases + strlen (aliases) + 1; + break; + } + + /* Don't return an empty string. GNU libc and GNU libiconv interpret + the empty string as denoting "the locale's character encoding", + thus GNU libiconv would call this function a second time. */ + if (codeset[0] == '\0') + codeset = "ASCII"; + +#ifdef DARWIN7 + /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8" + (the default codeset) does not work when MB_CUR_MAX is 1. */ + if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX <= 1) + codeset = "ASCII"; +#endif + + return codeset; +} diff --git a/grub-core/gnulib/localcharset.h b/grub-core/gnulib/localcharset.h new file mode 100644 index 000000000..c20982986 --- /dev/null +++ b/grub-core/gnulib/localcharset.h @@ -0,0 +1,40 @@ +/* Determine a canonical name for the current locale's character encoding. + Copyright (C) 2000-2003, 2009-2013 Free Software Foundation, Inc. + This file is part of the GNU CHARSET Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _LOCALCHARSET_H +#define _LOCALCHARSET_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Determine the current locale's character encoding, and canonicalize it + into one of the canonical names listed in config.charset. + The result must not be freed; it is statically allocated. + If the canonical name cannot be determined, the result is a non-canonical + name. */ +extern const char * locale_charset (void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _LOCALCHARSET_H */ diff --git a/grub-core/gnulib/locale.in.h b/grub-core/gnulib/locale.in.h new file mode 100644 index 000000000..264161a6c --- /dev/null +++ b/grub-core/gnulib/locale.in.h @@ -0,0 +1,216 @@ +/* A POSIX . + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#ifdef _GL_ALREADY_INCLUDING_LOCALE_H + +/* Special invocation conventions to handle Solaris header files + (through Solaris 10) when combined with gettext's libintl.h. */ + +#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_LOCALE_H + +#define _GL_ALREADY_INCLUDING_LOCALE_H + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ + +#undef _GL_ALREADY_INCLUDING_LOCALE_H + +#ifndef _@GUARD_PREFIX@_LOCALE_H +#define _@GUARD_PREFIX@_LOCALE_H + +/* NetBSD 5.0 mis-defines NULL. */ +#include + +/* Mac OS X 10.5 defines the locale_t type in . */ +#if @HAVE_XLOCALE_H@ +# include +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C. + On systems that don't define it, use the same value as GNU libintl. */ +#if !defined LC_MESSAGES +# define LC_MESSAGES 1729 +#endif + +/* Bionic libc's 'struct lconv' is just a dummy. */ +#if @REPLACE_STRUCT_LCONV@ +# define lconv rpl_lconv +struct lconv +{ + /* All 'char *' are actually 'const char *'. */ + + /* Members that depend on the LC_NUMERIC category of the locale. See + */ + + /* Symbol used as decimal point. */ + char *decimal_point; + /* Symbol used to separate groups of digits to the left of the decimal + point. */ + char *thousands_sep; + /* Definition of the size of groups of digits to the left of the decimal + point. */ + char *grouping; + + /* Members that depend on the LC_MONETARY category of the locale. See + */ + + /* Symbol used as decimal point. */ + char *mon_decimal_point; + /* Symbol used to separate groups of digits to the left of the decimal + point. */ + char *mon_thousands_sep; + /* Definition of the size of groups of digits to the left of the decimal + point. */ + char *mon_grouping; + /* Sign used to indicate a value >= 0. */ + char *positive_sign; + /* Sign used to indicate a value < 0. */ + char *negative_sign; + + /* For formatting local currency. */ + /* Currency symbol (3 characters) followed by separator (1 character). */ + char *currency_symbol; + /* Number of digits after the decimal point. */ + char frac_digits; + /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it + comes after the number. */ + char p_cs_precedes; + /* For values >= 0: Position of the sign. */ + char p_sign_posn; + /* For values >= 0: Placement of spaces between currency symbol, sign, and + number. */ + char p_sep_by_space; + /* For values < 0: 1 if the currency symbol precedes the number, 0 if it + comes after the number. */ + char n_cs_precedes; + /* For values < 0: Position of the sign. */ + char n_sign_posn; + /* For values < 0: Placement of spaces between currency symbol, sign, and + number. */ + char n_sep_by_space; + + /* For formatting international currency. */ + /* Currency symbol (3 characters) followed by separator (1 character). */ + char *int_curr_symbol; + /* Number of digits after the decimal point. */ + char int_frac_digits; + /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it + comes after the number. */ + char int_p_cs_precedes; + /* For values >= 0: Position of the sign. */ + char int_p_sign_posn; + /* For values >= 0: Placement of spaces between currency symbol, sign, and + number. */ + char int_p_sep_by_space; + /* For values < 0: 1 if the currency symbol precedes the number, 0 if it + comes after the number. */ + char int_n_cs_precedes; + /* For values < 0: Position of the sign. */ + char int_n_sign_posn; + /* For values < 0: Placement of spaces between currency symbol, sign, and + number. */ + char int_n_sep_by_space; +}; +#endif + +#if @GNULIB_LOCALECONV@ +# if @REPLACE_LOCALECONV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef localeconv +# define localeconv rpl_localeconv +# endif +_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void)); +_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void)); +# else +_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void)); +# endif +_GL_CXXALIASWARN (localeconv); +#elif @REPLACE_STRUCT_LCONV@ +# undef localeconv +# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv +#elif defined GNULIB_POSIXCHECK +# undef localeconv +# if HAVE_RAW_DECL_LOCALECONV +_GL_WARN_ON_USE (localeconv, + "localeconv returns too few information on some platforms - " + "use gnulib module localeconv for portability"); +# endif +#endif + +#if @GNULIB_SETLOCALE@ +# if @REPLACE_SETLOCALE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef setlocale +# define setlocale rpl_setlocale +# define GNULIB_defined_setlocale 1 +# endif +_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale)); +_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale)); +# else +_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale)); +# endif +_GL_CXXALIASWARN (setlocale); +#elif defined GNULIB_POSIXCHECK +# undef setlocale +# if HAVE_RAW_DECL_SETLOCALE +_GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - " + "use gnulib module setlocale for portability"); +# endif +#endif + +#if @GNULIB_DUPLOCALE@ +# if @REPLACE_DUPLOCALE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef duplocale +# define duplocale rpl_duplocale +# endif +_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale)); +# else +# if @HAVE_DUPLOCALE@ +_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale)); +# endif +# endif +# if @HAVE_DUPLOCALE@ +_GL_CXXALIASWARN (duplocale); +# endif +#elif defined GNULIB_POSIXCHECK +# undef duplocale +# if HAVE_RAW_DECL_DUPLOCALE +_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - " + "use gnulib module duplocale for portability"); +# endif +#endif + +#endif /* _@GUARD_PREFIX@_LOCALE_H */ +#endif /* ! _GL_ALREADY_INCLUDING_LOCALE_H */ +#endif /* _@GUARD_PREFIX@_LOCALE_H */ diff --git a/grub-core/gnulib/localeconv.c b/grub-core/gnulib/localeconv.c new file mode 100644 index 000000000..7c7c77cfd --- /dev/null +++ b/grub-core/gnulib/localeconv.c @@ -0,0 +1,103 @@ +/* Query locale dependent information for formatting numbers. + Copyright (C) 2012-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#if HAVE_STRUCT_LCONV_DECIMAL_POINT + +/* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_* + members. */ + +struct lconv * +localeconv (void) +{ + static struct lconv result; +# undef lconv +# undef localeconv + struct lconv *sys_result = localeconv (); + + result.decimal_point = sys_result->decimal_point; + result.thousands_sep = sys_result->thousands_sep; + result.grouping = sys_result->grouping; + result.mon_decimal_point = sys_result->mon_decimal_point; + result.mon_thousands_sep = sys_result->mon_thousands_sep; + result.mon_grouping = sys_result->mon_grouping; + result.positive_sign = sys_result->positive_sign; + result.negative_sign = sys_result->negative_sign; + result.currency_symbol = sys_result->currency_symbol; + result.frac_digits = sys_result->frac_digits; + result.p_cs_precedes = sys_result->p_cs_precedes; + result.p_sign_posn = sys_result->p_sign_posn; + result.p_sep_by_space = sys_result->p_sep_by_space; + result.n_cs_precedes = sys_result->n_cs_precedes; + result.n_sign_posn = sys_result->n_sign_posn; + result.n_sep_by_space = sys_result->n_sep_by_space; + result.int_curr_symbol = sys_result->int_curr_symbol; + result.int_frac_digits = sys_result->int_frac_digits; + result.int_p_cs_precedes = sys_result->p_cs_precedes; + result.int_p_sign_posn = sys_result->p_sign_posn; + result.int_p_sep_by_space = sys_result->p_sep_by_space; + result.int_n_cs_precedes = sys_result->n_cs_precedes; + result.int_n_sign_posn = sys_result->n_sign_posn; + result.int_n_sep_by_space = sys_result->n_sep_by_space; + + return &result; +} + +#else + +/* Override for platforms where 'struct lconv' is a dummy. */ + +# include + +struct lconv * +localeconv (void) +{ + static /*const*/ struct lconv result = + { + /* decimal_point */ ".", + /* thousands_sep */ "", + /* grouping */ "", + /* mon_decimal_point */ "", + /* mon_thousands_sep */ "", + /* mon_grouping */ "", + /* positive_sign */ "", + /* negative_sign */ "", + /* currency_symbol */ "", + /* frac_digits */ CHAR_MAX, + /* p_cs_precedes */ CHAR_MAX, + /* p_sign_posn */ CHAR_MAX, + /* p_sep_by_space */ CHAR_MAX, + /* n_cs_precedes */ CHAR_MAX, + /* n_sign_posn */ CHAR_MAX, + /* n_sep_by_space */ CHAR_MAX, + /* int_curr_symbol */ "", + /* int_frac_digits */ CHAR_MAX, + /* int_p_cs_precedes */ CHAR_MAX, + /* int_p_sign_posn */ CHAR_MAX, + /* int_p_sep_by_space */ CHAR_MAX, + /* int_n_cs_precedes */ CHAR_MAX, + /* int_n_sign_posn */ CHAR_MAX, + /* int_n_sep_by_space */ CHAR_MAX + }; + + return &result; +} + +#endif diff --git a/grub-core/gnulib/malloc.c b/grub-core/gnulib/malloc.c new file mode 100644 index 000000000..908735d27 --- /dev/null +++ b/grub-core/gnulib/malloc.c @@ -0,0 +1,56 @@ +/* malloc() function that is glibc compatible. + + Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* written by Jim Meyering and Bruno Haible */ + +#define _GL_USE_STDLIB_ALLOC 1 +#include +/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */ +#ifdef malloc +# define NEED_MALLOC_GNU 1 +# undef malloc +/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */ +#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU +# define NEED_MALLOC_GNU 1 +#endif + +#include + +#include + +/* Allocate an N-byte block of memory from the heap. + If N is zero, allocate a 1-byte block. */ + +void * +rpl_malloc (size_t n) +{ + void *result; + +#if NEED_MALLOC_GNU + if (n == 0) + n = 1; +#endif + + result = malloc (n); + +#if !HAVE_MALLOC_POSIX + if (result == NULL) + errno = ENOMEM; +#endif + + return result; +} diff --git a/grub-core/gnulib/mbrtowc.c b/grub-core/gnulib/mbrtowc.c new file mode 100644 index 000000000..5ee44aea4 --- /dev/null +++ b/grub-core/gnulib/mbrtowc.c @@ -0,0 +1,402 @@ +/* Convert multibyte character to wide character. + Copyright (C) 1999-2002, 2005-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#if GNULIB_defined_mbstate_t +/* Implement mbrtowc() on top of mbtowc(). */ + +# include +# include + +# include "localcharset.h" +# include "streq.h" +# include "verify.h" + + +verify (sizeof (mbstate_t) >= 4); + +static char internal_state[4]; + +size_t +mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ + char *pstate = (char *)ps; + + if (s == NULL) + { + pwc = NULL; + s = ""; + n = 1; + } + + if (n == 0) + return (size_t)(-2); + + /* Here n > 0. */ + + if (pstate == NULL) + pstate = internal_state; + + { + size_t nstate = pstate[0]; + char buf[4]; + const char *p; + size_t m; + + switch (nstate) + { + case 0: + p = s; + m = n; + break; + case 3: + buf[2] = pstate[3]; + /*FALLTHROUGH*/ + case 2: + buf[1] = pstate[2]; + /*FALLTHROUGH*/ + case 1: + buf[0] = pstate[1]; + p = buf; + m = nstate; + buf[m++] = s[0]; + if (n >= 2 && m < 4) + { + buf[m++] = s[1]; + if (n >= 3 && m < 4) + buf[m++] = s[2]; + } + break; + default: + errno = EINVAL; + return (size_t)(-1); + } + + /* Here m > 0. */ + +# if __GLIBC__ || defined __UCLIBC__ + /* Work around bug */ + mbtowc (NULL, NULL, 0); +# endif + { + int res = mbtowc (pwc, p, m); + + if (res >= 0) + { + if (pwc != NULL && ((*pwc == 0) != (res == 0))) + abort (); + if (nstate >= (res > 0 ? res : 1)) + abort (); + res -= nstate; + pstate[0] = 0; + return res; + } + + /* mbtowc does not distinguish between invalid and incomplete multibyte + sequences. But mbrtowc needs to make this distinction. + There are two possible approaches: + - Use iconv() and its return value. + - Use built-in knowledge about the possible encodings. + Given the low quality of implementation of iconv() on the systems that + lack mbrtowc(), we use the second approach. + The possible encodings are: + - 8-bit encodings, + - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, + - UTF-8. + Use specialized code for each. */ + if (m >= 4 || m >= MB_CUR_MAX) + goto invalid; + /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ + { + const char *encoding = locale_charset (); + + if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) + { + /* Cf. unistr/u8-mblen.c. */ + unsigned char c = (unsigned char) p[0]; + + if (c >= 0xc2) + { + if (c < 0xe0) + { + if (m == 1) + goto incomplete; + } + else if (c < 0xf0) + { + if (m == 1) + goto incomplete; + if (m == 2) + { + unsigned char c2 = (unsigned char) p[1]; + + if ((c2 ^ 0x80) < 0x40 + && (c >= 0xe1 || c2 >= 0xa0) + && (c != 0xed || c2 < 0xa0)) + goto incomplete; + } + } + else if (c <= 0xf4) + { + if (m == 1) + goto incomplete; + else /* m == 2 || m == 3 */ + { + unsigned char c2 = (unsigned char) p[1]; + + if ((c2 ^ 0x80) < 0x40 + && (c >= 0xf1 || c2 >= 0x90) + && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) + { + if (m == 2) + goto incomplete; + else /* m == 3 */ + { + unsigned char c3 = (unsigned char) p[2]; + + if ((c3 ^ 0x80) < 0x40) + goto incomplete; + } + } + } + } + } + goto invalid; + } + + /* As a reference for this code, you can use the GNU libiconv + implementation. Look for uses of the RET_TOOFEW macro. */ + + if (STREQ_OPT (encoding, + "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) + goto incomplete; + } + if (m == 2) + { + unsigned char c = (unsigned char) p[0]; + + if (c == 0x8f) + { + unsigned char c2 = (unsigned char) p[1]; + + if (c2 >= 0xa1 && c2 < 0xff) + goto incomplete; + } + } + goto invalid; + } + if (STREQ_OPT (encoding, + "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) + || STREQ_OPT (encoding, + "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) + || STREQ_OPT (encoding, + "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if (c >= 0xa1 && c < 0xff) + goto incomplete; + } + goto invalid; + } + if (STREQ_OPT (encoding, + "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0xa1 && c < 0xff) || c == 0x8e) + goto incomplete; + } + else /* m == 2 || m == 3 */ + { + unsigned char c = (unsigned char) p[0]; + + if (c == 0x8e) + goto incomplete; + } + goto invalid; + } + if (STREQ_OPT (encoding, + "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) + goto incomplete; + } + else /* m == 2 || m == 3 */ + { + unsigned char c = (unsigned char) p[0]; + + if (c >= 0x90 && c <= 0xe3) + { + unsigned char c2 = (unsigned char) p[1]; + + if (c2 >= 0x30 && c2 <= 0x39) + { + if (m == 2) + goto incomplete; + else /* m == 3 */ + { + unsigned char c3 = (unsigned char) p[2]; + + if (c3 >= 0x81 && c3 <= 0xfe) + goto incomplete; + } + } + } + } + goto invalid; + } + if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) + || (c >= 0xf0 && c <= 0xf9)) + goto incomplete; + } + goto invalid; + } + + /* An unknown multibyte encoding. */ + goto incomplete; + } + + incomplete: + { + size_t k = nstate; + /* Here 0 <= k < m < 4. */ + pstate[++k] = s[0]; + if (k < m) + { + pstate[++k] = s[1]; + if (k < m) + pstate[++k] = s[2]; + } + if (k != m) + abort (); + } + pstate[0] = m; + return (size_t)(-2); + + invalid: + errno = EILSEQ; + /* The conversion state is undefined, says POSIX. */ + return (size_t)(-1); + } + } +} + +#else +/* Override the system's mbrtowc() function. */ + +# undef mbrtowc + +size_t +rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ +# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG + if (s == NULL) + { + pwc = NULL; + s = ""; + n = 1; + } +# endif + +# if MBRTOWC_RETVAL_BUG + { + static mbstate_t internal_state; + + /* Override mbrtowc's internal state. We cannot call mbsinit() on the + hidden internal state, but we can call it on our variable. */ + if (ps == NULL) + ps = &internal_state; + + if (!mbsinit (ps)) + { + /* Parse the rest of the multibyte character byte for byte. */ + size_t count = 0; + for (; n > 0; s++, n--) + { + wchar_t wc; + size_t ret = mbrtowc (&wc, s, 1, ps); + + if (ret == (size_t)(-1)) + return (size_t)(-1); + count++; + if (ret != (size_t)(-2)) + { + /* The multibyte character has been completed. */ + if (pwc != NULL) + *pwc = wc; + return (wc == 0 ? 0 : count); + } + } + return (size_t)(-2); + } + } +# endif + +# if MBRTOWC_NUL_RETVAL_BUG + { + wchar_t wc; + size_t ret = mbrtowc (&wc, s, n, ps); + + if (ret != (size_t)(-1) && ret != (size_t)(-2)) + { + if (pwc != NULL) + *pwc = wc; + if (wc == 0) + ret = 0; + } + return ret; + } +# else + { +# if MBRTOWC_NULL_ARG1_BUG + wchar_t dummy; + + if (pwc == NULL) + pwc = &dummy; +# endif + + return mbrtowc (pwc, s, n, ps); + } +# endif +} + +#endif diff --git a/grub-core/gnulib/mbsinit.c b/grub-core/gnulib/mbsinit.c new file mode 100644 index 000000000..26fbb7fa2 --- /dev/null +++ b/grub-core/gnulib/mbsinit.c @@ -0,0 +1,61 @@ +/* Test for initial conversion state. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "verify.h" + +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + +/* On native Windows, 'mbstate_t' is defined as 'int'. */ + +int +mbsinit (const mbstate_t *ps) +{ + return ps == NULL || *ps == 0; +} + +#else + +/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() + and wcrtomb(), wcsrtombs(). + We assume that + - sizeof (mbstate_t) >= 4, + - only stateless encodings are supported (such as UTF-8 and EUC-JP, but + not ISO-2022 variants), + - for each encoding, the number of bytes for a wide character is <= 4. + (This maximum is attained for UTF-8, GB18030, EUC-TW.) + We define the meaning of mbstate_t as follows: + - In mb -> wc direction, mbstate_t's first byte contains the number of + buffered bytes (in the range 0..3), followed by up to 3 buffered bytes. + - In wc -> mb direction, mbstate_t contains no information. In other + words, it is always in the initial state. */ + +verify (sizeof (mbstate_t) >= 4); + +int +mbsinit (const mbstate_t *ps) +{ + const char *pstate = (const char *)ps; + + return pstate == NULL || pstate[0] == 0; +} + +#endif diff --git a/grub-core/gnulib/mbsrtowcs-impl.h b/grub-core/gnulib/mbsrtowcs-impl.h new file mode 100644 index 000000000..b50e9739b --- /dev/null +++ b/grub-core/gnulib/mbsrtowcs-impl.h @@ -0,0 +1,122 @@ +/* Convert string to wide string. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +size_t +mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) +{ + if (ps == NULL) + ps = &_gl_mbsrtowcs_state; + { + const char *src = *srcp; + + if (dest != NULL) + { + wchar_t *destptr = dest; + + for (; len > 0; destptr++, len--) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MB_LEN_MAX); */ + if (src[0] == '\0') + src_avail = 1; + else if (src[1] == '\0') + src_avail = 2; + else if (src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (destptr, src, src_avail, ps); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input; + if (ret == 0) + { + src = NULL; + /* Here mbsinit (ps). */ + break; + } + src += ret; + } + + *srcp = src; + return destptr - dest; + } + else + { + /* Ignore dest and len, don't store *srcp at the end, and + don't clobber *ps. */ + mbstate_t state = *ps; + size_t totalcount = 0; + + for (;; totalcount++) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MB_LEN_MAX); */ + if (src[0] == '\0') + src_avail = 1; + else if (src[1] == '\0') + src_avail = 2; + else if (src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (NULL, src, src_avail, &state); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input2; + if (ret == 0) + { + /* Here mbsinit (&state). */ + break; + } + src += ret; + } + + return totalcount; + } + + bad_input: + *srcp = src; + bad_input2: + errno = EILSEQ; + return (size_t)(-1); + } +} diff --git a/grub-core/gnulib/mbsrtowcs-state.c b/grub-core/gnulib/mbsrtowcs-state.c new file mode 100644 index 000000000..5a0b8882b --- /dev/null +++ b/grub-core/gnulib/mbsrtowcs-state.c @@ -0,0 +1,37 @@ +/* Convert string to wide string. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +/* Internal state used by the functions mbsrtowcs() and mbsnrtowcs(). */ +mbstate_t _gl_mbsrtowcs_state +/* The state must initially be in the "initial state"; so, zero-initialize it. + On most systems, putting it into BSS is sufficient. Not so on Mac OS X 10.3, + see . + When it needs an initializer, use 0 or {0} as initializer? 0 only works + when mbstate_t is a scalar type (such as when gnulib defines it, or on + AIX, IRIX, mingw). {0} works as an initializer in all cases: for a struct + or union type, but also for a scalar type (ISO C 99, 6.7.8.(11)). */ +#if defined __ELF__ + /* On ELF systems, variables in BSS behave well. */ +#else + /* Use braces, to be on the safe side. */ + = { 0 } +#endif + ; diff --git a/grub-core/gnulib/mbsrtowcs.c b/grub-core/gnulib/mbsrtowcs.c new file mode 100644 index 000000000..116ff493b --- /dev/null +++ b/grub-core/gnulib/mbsrtowcs.c @@ -0,0 +1,32 @@ +/* Convert string to wide string. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include + +#include "strnlen1.h" + + +extern mbstate_t _gl_mbsrtowcs_state; + +#include "mbsrtowcs-impl.h" diff --git a/grub-core/gnulib/mbswidth.c b/grub-core/gnulib/mbswidth.c new file mode 100644 index 000000000..baa4f2757 --- /dev/null +++ b/grub-core/gnulib/mbswidth.c @@ -0,0 +1,199 @@ +/* Determine the number of screen columns needed for a string. + Copyright (C) 2000-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible . */ + +#include + +/* Specification. */ +#include "mbswidth.h" + +/* Get MB_CUR_MAX. */ +#include + +#include + +/* Get isprint(). */ +#include + +/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */ +#include + +/* Get iswcntrl(). */ +#include + +/* Get INT_MAX. */ +#include + +/* Returns the number of columns needed to represent the multibyte + character string pointed to by STRING. If a non-printable character + occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. + With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is + the multibyte analogue of the wcswidth function. */ +int +mbswidth (const char *string, int flags) +{ + return mbsnwidth (string, strlen (string), flags); +} + +/* Returns the number of columns needed to represent the multibyte + character string pointed to by STRING of length NBYTES. If a + non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is + specified, -1 is returned. */ +int +mbsnwidth (const char *string, size_t nbytes, int flags) +{ + const char *p = string; + const char *plimit = p + nbytes; + int width; + + width = 0; + if (MB_CUR_MAX > 1) + { + while (p < plimit) + switch (*p) + { + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + /* These characters are printable ASCII characters. */ + p++; + width++; + break; + case '\0': + if (flags & MBSW_STOP_AT_NUL) + return width; + default: + /* If we have a multibyte sequence, scan it up to its end. */ + { + mbstate_t mbstate; + memset (&mbstate, 0, sizeof mbstate); + do + { + wchar_t wc; + size_t bytes; + int w; + + bytes = mbrtowc (&wc, p, plimit - p, &mbstate); + + if (bytes == (size_t) -1) + /* An invalid multibyte sequence was encountered. */ + { + if (!(flags & MBSW_REJECT_INVALID)) + { + p++; + width++; + break; + } + else + return -1; + } + + if (bytes == (size_t) -2) + /* An incomplete multibyte character at the end. */ + { + if (!(flags & MBSW_REJECT_INVALID)) + { + p = plimit; + width++; + break; + } + else + return -1; + } + + if (bytes == 0) + /* A null wide character was encountered. */ + bytes = 1; + + w = wcwidth (wc); + if (w >= 0) + /* A printable multibyte character. */ + { + if (w > INT_MAX - width) + goto overflow; + width += w; + } + else + /* An unprintable multibyte character. */ + if (!(flags & MBSW_REJECT_UNPRINTABLE)) + { + if (!iswcntrl (wc)) + { + if (width == INT_MAX) + goto overflow; + width++; + } + } + else + return -1; + + p += bytes; + } + while (! mbsinit (&mbstate)); + } + break; + } + return width; + } + + while (p < plimit) + { + unsigned char c = (unsigned char) *p++; + + if (c == 0 && (flags & MBSW_STOP_AT_NUL)) + return width; + + if (isprint (c)) + { + if (width == INT_MAX) + goto overflow; + width++; + } + else if (!(flags & MBSW_REJECT_UNPRINTABLE)) + { + if (!iscntrl (c)) + { + if (width == INT_MAX) + goto overflow; + width++; + } + } + else + return -1; + } + return width; + + overflow: + return INT_MAX; +} diff --git a/grub-core/gnulib/mbswidth.h b/grub-core/gnulib/mbswidth.h new file mode 100644 index 000000000..d7207c58f --- /dev/null +++ b/grub-core/gnulib/mbswidth.h @@ -0,0 +1,63 @@ +/* Determine the number of screen columns needed for a string. + Copyright (C) 2000-2004, 2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Avoid a clash of our mbswidth() with a function of the same name defined + in UnixWare 7.1.1 . We need this #include before the #define + below. + However, we don't want to #include on all platforms because + - Tru64 with Desktop Toolkit C has a bug: must be included before + . + - BSD/OS 4.1 has a bug: and must be included before + . */ +#if HAVE_DECL_MBSWIDTH_IN_WCHAR_H +# include +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Optional flags to influence mbswidth/mbsnwidth behavior. */ + +/* If this bit is set, return -1 upon finding an invalid or incomplete + character. Otherwise, assume invalid characters have width 1. */ +#define MBSW_REJECT_INVALID 1 + +/* If this bit is set, return -1 upon finding a non-printable character. + Otherwise, assume unprintable characters have width 0 if they are + control characters and 1 otherwise. */ +#define MBSW_REJECT_UNPRINTABLE 2 + +/* If this bit is set \0 is treated as the end of string. + Otherwise it's treated as a normal one column width character. */ +#define MBSW_STOP_AT_NUL 4 + +/* Returns the number of screen columns needed for STRING. */ +#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ +extern int mbswidth (const char *string, int flags); + +/* Returns the number of screen columns needed for the NBYTES bytes + starting at BUF. */ +extern int mbsnwidth (const char *buf, size_t nbytes, int flags); + + +#ifdef __cplusplus +} +#endif diff --git a/grub-core/gnulib/mbtowc-impl.h b/grub-core/gnulib/mbtowc-impl.h new file mode 100644 index 000000000..767ab397c --- /dev/null +++ b/grub-core/gnulib/mbtowc-impl.h @@ -0,0 +1,44 @@ +/* Convert multibyte character to wide character. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* We don't need a static internal state, because the encoding is not state + dependent, and when mbrtowc returns (size_t)(-2). we throw the result + away. */ + +int +mbtowc (wchar_t *pwc, const char *s, size_t n) +{ + if (s == NULL) + return 0; + else + { + mbstate_t state; + wchar_t wc; + size_t result; + + memset (&state, 0, sizeof (mbstate_t)); + result = mbrtowc (&wc, s, n, &state); + if (result == (size_t)-1 || result == (size_t)-2) + { + errno = EILSEQ; + return -1; + } + if (pwc != NULL) + *pwc = wc; + return (wc == 0 ? 0 : result); + } +} diff --git a/grub-core/gnulib/mbtowc.c b/grub-core/gnulib/mbtowc.c new file mode 100644 index 000000000..632f2e1db --- /dev/null +++ b/grub-core/gnulib/mbtowc.c @@ -0,0 +1,26 @@ +/* Convert multibyte character to wide character. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +#include +#include +#include + +#include "mbtowc-impl.h" diff --git a/grub-core/gnulib/memchr.c b/grub-core/gnulib/memchr.c new file mode 100644 index 000000000..3db38a94c --- /dev/null +++ b/grub-core/gnulib/memchr.c @@ -0,0 +1,172 @@ +/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013 + Free Software Foundation, Inc. + + Based on strlen implementation by Torbjorn Granlund (tege@sics.se), + with help from Dan Sahlin (dan@sics.se) and + commentary by Jim Blandy (jimb@ai.mit.edu); + adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), + and implemented by Roland McGrath (roland@ai.mit.edu). + +NOTE: The canonical source of this file is maintained with the GNU C Library. +Bugs can be reported to bug-glibc@prep.ai.mit.edu. + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ + +#ifndef _LIBC +# include +#endif + +#include + +#include + +#if defined _LIBC +# include +#else +# define reg_char char +#endif + +#include + +#if HAVE_BP_SYM_H || defined _LIBC +# include +#else +# define BP_SYM(sym) sym +#endif + +#undef __memchr +#ifdef _LIBC +# undef memchr +#endif + +#ifndef weak_alias +# define __memchr memchr +#endif + +/* Search no more than N bytes of S for C. */ +void * +__memchr (void const *s, int c_in, size_t n) +{ + /* On 32-bit hardware, choosing longword to be a 32-bit unsigned + long instead of a 64-bit uintmax_t tends to give better + performance. On 64-bit hardware, unsigned long is generally 64 + bits already. Change this typedef to experiment with + performance. */ + typedef unsigned long int longword; + + const unsigned char *char_ptr; + const longword *longword_ptr; + longword repeated_one; + longword repeated_c; + unsigned reg_char c; + + c = (unsigned char) c_in; + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + n > 0 && (size_t) char_ptr % sizeof (longword) != 0; + --n, ++char_ptr) + if (*char_ptr == c) + return (void *) char_ptr; + + longword_ptr = (const longword *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + repeated_one = 0x01010101; + repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + } + + /* Instead of the traditional loop which tests each byte, we will test a + longword at a time. The tricky part is testing if *any of the four* + bytes in the longword in question are equal to c. We first use an xor + with repeated_c. This reduces the task to testing whether *any of the + four* bytes in longword1 is zero. + + We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + So, the test whether any byte in longword1 is zero is equivalent to + testing whether tmp is nonzero. */ + + while (n >= sizeof (longword)) + { + longword longword1 = *longword_ptr ^ repeated_c; + + if ((((longword1 - repeated_one) & ~longword1) + & (repeated_one << 7)) != 0) + break; + longword_ptr++; + n -= sizeof (longword); + } + + char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that either n < sizeof (longword), or one of the + sizeof (longword) bytes starting at char_ptr is == c. On little-endian + machines, we could determine the first such byte without any further + memory accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. Choose code + that works in both cases. */ + + for (; n > 0; --n, ++char_ptr) + { + if (*char_ptr == c) + return (void *) char_ptr; + } + + return NULL; +} +#ifdef weak_alias +weak_alias (__memchr, BP_SYM (memchr)) +#endif diff --git a/grub-core/gnulib/memchr.valgrind b/grub-core/gnulib/memchr.valgrind new file mode 100644 index 000000000..60f247e10 --- /dev/null +++ b/grub-core/gnulib/memchr.valgrind @@ -0,0 +1,14 @@ +# Suppress a valgrind message about use of uninitialized memory in memchr(). +# POSIX states that when the character is found, memchr must not read extra +# bytes in an overestimated length (for example, where memchr is used to +# implement strnlen). However, we use a safe word read to provide a speedup. +{ + memchr-value4 + Memcheck:Value4 + fun:rpl_memchr +} +{ + memchr-value8 + Memcheck:Value8 + fun:rpl_memchr +} diff --git a/grub-core/gnulib/mempcpy.c b/grub-core/gnulib/mempcpy.c new file mode 100644 index 000000000..5582368ed --- /dev/null +++ b/grub-core/gnulib/mempcpy.c @@ -0,0 +1,28 @@ +/* Copy memory area and return pointer after last written byte. + Copyright (C) 2003, 2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#include + +/* Specification. */ +#include + +/* Copy N bytes of SRC to DEST, return pointer to bytes after the + last written byte. */ +void * +mempcpy (void *dest, const void *src, size_t n) +{ + return (char *) memcpy (dest, src, n) + n; +} diff --git a/grub-core/gnulib/msvc-inval.c b/grub-core/gnulib/msvc-inval.c new file mode 100644 index 000000000..7e57731eb --- /dev/null +++ b/grub-core/gnulib/msvc-inval.c @@ -0,0 +1,129 @@ +/* Invalid parameter handler for MSVC runtime libraries. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#include + +/* Specification. */ +#include "msvc-inval.h" + +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \ + && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING) + +/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler + declaration. */ +# include + +# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING + +static void __cdecl +gl_msvc_invalid_parameter_handler (const wchar_t *expression, + const wchar_t *function, + const wchar_t *file, + unsigned int line, + uintptr_t dummy) +{ +} + +# else + +/* Get declarations of the native Windows API functions. */ +# define WIN32_LEAN_AND_MEAN +# include + +# if defined _MSC_VER + +static void cdecl +gl_msvc_invalid_parameter_handler (const wchar_t *expression, + const wchar_t *function, + const wchar_t *file, + unsigned int line, + uintptr_t dummy) +{ + RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL); +} + +# else + +/* An index to thread-local storage. */ +static DWORD tls_index; +static int tls_initialized /* = 0 */; + +/* Used as a fallback only. */ +static struct gl_msvc_inval_per_thread not_per_thread; + +struct gl_msvc_inval_per_thread * +gl_msvc_inval_current (void) +{ + if (!tls_initialized) + { + tls_index = TlsAlloc (); + tls_initialized = 1; + } + if (tls_index == TLS_OUT_OF_INDEXES) + /* TlsAlloc had failed. */ + return ¬_per_thread; + else + { + struct gl_msvc_inval_per_thread *pointer = + (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index); + if (pointer == NULL) + { + /* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */ + pointer = + (struct gl_msvc_inval_per_thread *) + malloc (sizeof (struct gl_msvc_inval_per_thread)); + if (pointer == NULL) + /* Could not allocate memory. Use the global storage. */ + pointer = ¬_per_thread; + TlsSetValue (tls_index, pointer); + } + return pointer; + } +} + +static void cdecl +gl_msvc_invalid_parameter_handler (const wchar_t *expression, + const wchar_t *function, + const wchar_t *file, + unsigned int line, + uintptr_t dummy) +{ + struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current (); + if (current->restart_valid) + longjmp (current->restart, 1); + else + /* An invalid parameter notification from outside the gnulib code. + Give the caller a chance to intervene. */ + RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL); +} + +# endif + +# endif + +static int gl_msvc_inval_initialized /* = 0 */; + +void +gl_msvc_inval_ensure_handler (void) +{ + if (gl_msvc_inval_initialized == 0) + { + _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler); + gl_msvc_inval_initialized = 1; + } +} + +#endif diff --git a/grub-core/gnulib/msvc-inval.h b/grub-core/gnulib/msvc-inval.h new file mode 100644 index 000000000..dcb0353dc --- /dev/null +++ b/grub-core/gnulib/msvc-inval.h @@ -0,0 +1,222 @@ +/* Invalid parameter handler for MSVC runtime libraries. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _MSVC_INVAL_H +#define _MSVC_INVAL_H + +/* With MSVC runtime libraries with the "invalid parameter handler" concept, + functions like fprintf(), dup2(), or close() crash when the caller passes + an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF) + instead. + This file defines macros that turn such an invalid parameter notification + into a non-local exit. An error code can then be produced at the target + of this exit. You can thus write code like + + TRY_MSVC_INVAL + { + + } + CATCH_MSVC_INVAL + { + + } + DONE_MSVC_INVAL; + + This entire block expands to a single statement. + + The handling of invalid parameters can be done in three ways: + + * The default way, which is reasonable for programs (not libraries): + AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING]) + + * The way for libraries that make "hairy" calls (like close(-1), or + fclose(fp) where fileno(fp) is closed, or simply getdtablesize()): + AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING]) + + * The way for libraries that make no "hairy" calls: + AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING]) + */ + +#define DEFAULT_HANDLING 0 +#define HAIRY_LIBRARY_HANDLING 1 +#define SANE_LIBRARY_HANDLING 2 + +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \ + && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING) +/* A native Windows platform with the "invalid parameter handler" concept, + and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */ + +# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING +/* Default handling. */ + +# ifdef __cplusplus +extern "C" { +# endif + +/* Ensure that the invalid parameter handler in installed that just returns. + Because we assume no other part of the program installs a different + invalid parameter handler, this solution is multithread-safe. */ +extern void gl_msvc_inval_ensure_handler (void); + +# ifdef __cplusplus +} +# endif + +# define TRY_MSVC_INVAL \ + do \ + { \ + gl_msvc_inval_ensure_handler (); \ + if (1) +# define CATCH_MSVC_INVAL \ + else +# define DONE_MSVC_INVAL \ + } \ + while (0) + +# else +/* Handling for hairy libraries. */ + +# include + +/* Gnulib can define its own status codes, as described in the page + "Raising Software Exceptions" on microsoft.com + . + Our status codes are composed of + - 0xE0000000, mandatory for all user-defined status codes, + - 0x474E550, a API identifier ("GNU"), + - 0, 1, 2, ..., used to distinguish different status codes from the + same API. */ +# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0) + +# if defined _MSC_VER +/* A compiler that supports __try/__except, as described in the page + "try-except statement" on microsoft.com + . + With __try/__except, we can use the multithread-safe exception handling. */ + +# ifdef __cplusplus +extern "C" { +# endif + +/* Ensure that the invalid parameter handler in installed that raises a + software exception with code STATUS_GNULIB_INVALID_PARAMETER. + Because we assume no other part of the program installs a different + invalid parameter handler, this solution is multithread-safe. */ +extern void gl_msvc_inval_ensure_handler (void); + +# ifdef __cplusplus +} +# endif + +# define TRY_MSVC_INVAL \ + do \ + { \ + gl_msvc_inval_ensure_handler (); \ + __try +# define CATCH_MSVC_INVAL \ + __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \ + ? EXCEPTION_EXECUTE_HANDLER \ + : EXCEPTION_CONTINUE_SEARCH) +# define DONE_MSVC_INVAL \ + } \ + while (0) + +# else +/* Any compiler. + We can only use setjmp/longjmp. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +struct gl_msvc_inval_per_thread +{ + /* The restart that will resume execution at the code between + CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between + TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */ + jmp_buf restart; + + /* Tells whether the contents of restart is valid. */ + int restart_valid; +}; + +/* Ensure that the invalid parameter handler in installed that passes + control to the gl_msvc_inval_restart if it is valid, or raises a + software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise. + Because we assume no other part of the program installs a different + invalid parameter handler, this solution is multithread-safe. */ +extern void gl_msvc_inval_ensure_handler (void); + +/* Return a pointer to the per-thread data for the current thread. */ +extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void); + +# ifdef __cplusplus +} +# endif + +# define TRY_MSVC_INVAL \ + do \ + { \ + struct gl_msvc_inval_per_thread *msvc_inval_current; \ + gl_msvc_inval_ensure_handler (); \ + msvc_inval_current = gl_msvc_inval_current (); \ + /* First, initialize gl_msvc_inval_restart. */ \ + if (setjmp (msvc_inval_current->restart) == 0) \ + { \ + /* Then, mark it as valid. */ \ + msvc_inval_current->restart_valid = 1; +# define CATCH_MSVC_INVAL \ + /* Execution completed. \ + Mark gl_msvc_inval_restart as invalid. */ \ + msvc_inval_current->restart_valid = 0; \ + } \ + else \ + { \ + /* Execution triggered an invalid parameter notification. \ + Mark gl_msvc_inval_restart as invalid. */ \ + msvc_inval_current->restart_valid = 0; +# define DONE_MSVC_INVAL \ + } \ + } \ + while (0) + +# endif + +# endif + +#else +/* A platform that does not need to the invalid parameter handler, + or when SANE_LIBRARY_HANDLING is desired. */ + +/* The braces here avoid GCC warnings like + "warning: suggest explicit braces to avoid ambiguous 'else'". */ +# define TRY_MSVC_INVAL \ + do \ + { \ + if (1) +# define CATCH_MSVC_INVAL \ + else +# define DONE_MSVC_INVAL \ + } \ + while (0) + +#endif + +#endif /* _MSVC_INVAL_H */ diff --git a/grub-core/gnulib/msvc-nothrow.c b/grub-core/gnulib/msvc-nothrow.c new file mode 100644 index 000000000..8d65472a8 --- /dev/null +++ b/grub-core/gnulib/msvc-nothrow.c @@ -0,0 +1,49 @@ +/* Wrappers that don't throw invalid parameter notifications + with MSVC runtime libraries. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#include + +/* Specification. */ +#include "msvc-nothrow.h" + +/* Get declarations of the native Windows API functions. */ +#define WIN32_LEAN_AND_MEAN +#include + +#include "msvc-inval.h" + +#undef _get_osfhandle + +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +intptr_t +_gl_nothrow_get_osfhandle (int fd) +{ + intptr_t result; + + TRY_MSVC_INVAL + { + result = _get_osfhandle (fd); + } + CATCH_MSVC_INVAL + { + result = (intptr_t) INVALID_HANDLE_VALUE; + } + DONE_MSVC_INVAL; + + return result; +} +#endif diff --git a/grub-core/gnulib/msvc-nothrow.h b/grub-core/gnulib/msvc-nothrow.h new file mode 100644 index 000000000..5f521813d --- /dev/null +++ b/grub-core/gnulib/msvc-nothrow.h @@ -0,0 +1,43 @@ +/* Wrappers that don't throw invalid parameter notifications + with MSVC runtime libraries. + Copyright (C) 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _MSVC_NOTHROW_H +#define _MSVC_NOTHROW_H + +/* With MSVC runtime libraries with the "invalid parameter handler" concept, + functions like fprintf(), dup2(), or close() crash when the caller passes + an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF) + instead. + This file defines wrappers that turn such an invalid parameter notification + into an error code. */ + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +/* Get original declaration of _get_osfhandle. */ +# include + +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER + +/* Override _get_osfhandle. */ +extern intptr_t _gl_nothrow_get_osfhandle (int fd); +# define _get_osfhandle _gl_nothrow_get_osfhandle + +# endif + +#endif + +#endif /* _MSVC_NOTHROW_H */ diff --git a/grub-core/gnulib/nl_langinfo.c b/grub-core/gnulib/nl_langinfo.c new file mode 100644 index 000000000..771c9533a --- /dev/null +++ b/grub-core/gnulib/nl_langinfo.c @@ -0,0 +1,271 @@ +/* nl_langinfo() replacement: query locale dependent information. + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#if REPLACE_NL_LANGINFO + +/* Override nl_langinfo with support for added nl_item values. */ + +# include +# include + +# undef nl_langinfo + +char * +rpl_nl_langinfo (nl_item item) +{ + switch (item) + { +# if GNULIB_defined_CODESET + case CODESET: + { + const char *locale; + static char buf[2 + 10 + 1]; + + locale = setlocale (LC_CTYPE, NULL); + if (locale != NULL && locale[0] != '\0') + { + /* If the locale name contains an encoding after the dot, return + it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + } + return ""; + } +# endif +# if GNULIB_defined_T_FMT_AMPM + case T_FMT_AMPM: + return "%I:%M:%S %p"; +# endif +# if GNULIB_defined_ERA + case ERA: + /* The format is not standardized. In glibc it is a sequence of strings + of the form "direction:offset:start_date:end_date:era_name:era_format" + with an empty string at the end. */ + return ""; + case ERA_D_FMT: + /* The %Ex conversion in strftime behaves like %x if the locale does not + have an alternative time format. */ + item = D_FMT; + break; + case ERA_D_T_FMT: + /* The %Ec conversion in strftime behaves like %c if the locale does not + have an alternative time format. */ + item = D_T_FMT; + break; + case ERA_T_FMT: + /* The %EX conversion in strftime behaves like %X if the locale does not + have an alternative time format. */ + item = T_FMT; + break; + case ALT_DIGITS: + /* The format is not standardized. In glibc it is a sequence of 10 + strings, appended in memory. */ + return "\0\0\0\0\0\0\0\0\0\0"; +# endif +# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS + case YESEXPR: + return "^[yY]"; + case NOEXPR: + return "^[nN]"; +# endif + default: + break; + } + return nl_langinfo (item); +} + +#else + +/* Provide nl_langinfo from scratch. */ + +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +/* Native Windows platforms. */ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# include + +# else + +/* An old Unix platform without locales, such as Linux libc5 or BeOS. */ + +# endif + +# include + +char * +nl_langinfo (nl_item item) +{ + switch (item) + { + /* nl_langinfo items of the LC_CTYPE category */ + case CODESET: +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + { + static char buf[2 + 10 + 1]; + + /* The Windows API has a function returning the locale's codepage as + a number. */ + sprintf (buf, "CP%u", GetACP ()); + return buf; + } +# elif defined __BEOS__ + return "UTF-8"; +# else + return "ISO-8859-1"; +# endif + /* nl_langinfo items of the LC_NUMERIC category */ + case RADIXCHAR: + return localeconv () ->decimal_point; + case THOUSEP: + return localeconv () ->thousands_sep; + /* nl_langinfo items of the LC_TIME category. + TODO: Really use the locale. */ + case D_T_FMT: + case ERA_D_T_FMT: + return "%a %b %e %H:%M:%S %Y"; + case D_FMT: + case ERA_D_FMT: + return "%m/%d/%y"; + case T_FMT: + case ERA_T_FMT: + return "%H:%M:%S"; + case T_FMT_AMPM: + return "%I:%M:%S %p"; + case AM_STR: + return "AM"; + case PM_STR: + return "PM"; + case DAY_1: + return "Sunday"; + case DAY_2: + return "Monday"; + case DAY_3: + return "Tuesday"; + case DAY_4: + return "Wednesday"; + case DAY_5: + return "Thursday"; + case DAY_6: + return "Friday"; + case DAY_7: + return "Saturday"; + case ABDAY_1: + return "Sun"; + case ABDAY_2: + return "Mon"; + case ABDAY_3: + return "Tue"; + case ABDAY_4: + return "Wed"; + case ABDAY_5: + return "Thu"; + case ABDAY_6: + return "Fri"; + case ABDAY_7: + return "Sat"; + case MON_1: + return "January"; + case MON_2: + return "February"; + case MON_3: + return "March"; + case MON_4: + return "April"; + case MON_5: + return "May"; + case MON_6: + return "June"; + case MON_7: + return "July"; + case MON_8: + return "August"; + case MON_9: + return "September"; + case MON_10: + return "October"; + case MON_11: + return "November"; + case MON_12: + return "December"; + case ABMON_1: + return "Jan"; + case ABMON_2: + return "Feb"; + case ABMON_3: + return "Mar"; + case ABMON_4: + return "Apr"; + case ABMON_5: + return "May"; + case ABMON_6: + return "Jun"; + case ABMON_7: + return "Jul"; + case ABMON_8: + return "Aug"; + case ABMON_9: + return "Sep"; + case ABMON_10: + return "Oct"; + case ABMON_11: + return "Nov"; + case ABMON_12: + return "Dec"; + case ERA: + return ""; + case ALT_DIGITS: + return "\0\0\0\0\0\0\0\0\0\0"; + /* nl_langinfo items of the LC_MONETARY category + TODO: Really use the locale. */ + case CRNCYSTR: + return "-"; + /* nl_langinfo items of the LC_MESSAGES category + TODO: Really use the locale. */ + case YESEXPR: + return "^[yY]"; + case NOEXPR: + return "^[nN]"; + default: + return ""; + } +} + +#endif diff --git a/grub-core/gnulib/printf-args.c b/grub-core/gnulib/printf-args.c new file mode 100644 index 000000000..c27e6bc6b --- /dev/null +++ b/grub-core/gnulib/printf-args.c @@ -0,0 +1,187 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +/* This file can be parametrized with the following macros: + ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. + PRINTF_FETCHARGS Name of the function to be defined. + STATIC Set to 'static' to declare the function static. */ + +#ifndef PRINTF_FETCHARGS +# include +#endif + +/* Specification. */ +#ifndef PRINTF_FETCHARGS +# include "printf-args.h" +#endif + +#ifdef STATIC +STATIC +#endif +int +PRINTF_FETCHARGS (va_list args, arguments *a) +{ + size_t i; + argument *ap; + + for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) + switch (ap->type) + { + case TYPE_SCHAR: + ap->a.a_schar = va_arg (args, /*signed char*/ int); + break; + case TYPE_UCHAR: + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; + case TYPE_SHORT: + ap->a.a_short = va_arg (args, /*short*/ int); + break; + case TYPE_USHORT: + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; + case TYPE_INT: + ap->a.a_int = va_arg (args, int); + break; + case TYPE_UINT: + ap->a.a_uint = va_arg (args, unsigned int); + break; + case TYPE_LONGINT: + ap->a.a_longint = va_arg (args, long int); + break; + case TYPE_ULONGINT: + ap->a.a_ulongint = va_arg (args, unsigned long int); + break; +#if HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + ap->a.a_longlongint = va_arg (args, long long int); + break; + case TYPE_ULONGLONGINT: + ap->a.a_ulonglongint = va_arg (args, unsigned long long int); + break; +#endif + case TYPE_DOUBLE: + ap->a.a_double = va_arg (args, double); + break; + case TYPE_LONGDOUBLE: + ap->a.a_longdouble = va_arg (args, long double); + break; + case TYPE_CHAR: + ap->a.a_char = va_arg (args, int); + break; +#if HAVE_WINT_T + case TYPE_WIDE_CHAR: + /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by + default argument promotions", this is not the case in mingw32, + where wint_t is 'unsigned short'. */ + ap->a.a_wide_char = + (sizeof (wint_t) < sizeof (int) + ? (wint_t) va_arg (args, int) + : va_arg (args, wint_t)); + break; +#endif + case TYPE_STRING: + ap->a.a_string = va_arg (args, const char *); + /* A null pointer is an invalid argument for "%s", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_string == NULL) + ap->a.a_string = "(NULL)"; + break; +#if HAVE_WCHAR_T + case TYPE_WIDE_STRING: + ap->a.a_wide_string = va_arg (args, const wchar_t *); + /* A null pointer is an invalid argument for "%ls", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_wide_string == NULL) + { + static const wchar_t wide_null_string[] = + { + (wchar_t)'(', + (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', + (wchar_t)')', + (wchar_t)0 + }; + ap->a.a_wide_string = wide_null_string; + } + break; +#endif + case TYPE_POINTER: + ap->a.a_pointer = va_arg (args, void *); + break; + case TYPE_COUNT_SCHAR_POINTER: + ap->a.a_count_schar_pointer = va_arg (args, signed char *); + break; + case TYPE_COUNT_SHORT_POINTER: + ap->a.a_count_short_pointer = va_arg (args, short *); + break; + case TYPE_COUNT_INT_POINTER: + ap->a.a_count_int_pointer = va_arg (args, int *); + break; + case TYPE_COUNT_LONGINT_POINTER: + ap->a.a_count_longint_pointer = va_arg (args, long int *); + break; +#if HAVE_LONG_LONG_INT + case TYPE_COUNT_LONGLONGINT_POINTER: + ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); + break; +#endif +#if ENABLE_UNISTDIO + /* The unistdio extensions. */ + case TYPE_U8_STRING: + ap->a.a_u8_string = va_arg (args, const uint8_t *); + /* A null pointer is an invalid argument for "%U", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u8_string == NULL) + { + static const uint8_t u8_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u8_string = u8_null_string; + } + break; + case TYPE_U16_STRING: + ap->a.a_u16_string = va_arg (args, const uint16_t *); + /* A null pointer is an invalid argument for "%lU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u16_string == NULL) + { + static const uint16_t u16_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u16_string = u16_null_string; + } + break; + case TYPE_U32_STRING: + ap->a.a_u32_string = va_arg (args, const uint32_t *); + /* A null pointer is an invalid argument for "%llU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u32_string == NULL) + { + static const uint32_t u32_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u32_string = u32_null_string; + } + break; +#endif + default: + /* Unknown type. */ + return -1; + } + return 0; +} diff --git a/grub-core/gnulib/printf-args.h b/grub-core/gnulib/printf-args.h new file mode 100644 index 000000000..2a9c2a3f8 --- /dev/null +++ b/grub-core/gnulib/printf-args.h @@ -0,0 +1,158 @@ +/* Decomposed printf argument list. + Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _PRINTF_ARGS_H +#define _PRINTF_ARGS_H + +/* This file can be parametrized with the following macros: + ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. + PRINTF_FETCHARGS Name of the function to be declared. + STATIC Set to 'static' to declare the function static. */ + +/* Default parameters. */ +#ifndef PRINTF_FETCHARGS +# define PRINTF_FETCHARGS printf_fetchargs +#endif + +/* Get size_t. */ +#include + +/* Get wchar_t. */ +#if HAVE_WCHAR_T +# include +#endif + +/* Get wint_t. */ +#if HAVE_WINT_T +# include +#endif + +/* Get va_list. */ +#include + + +/* Argument types */ +typedef enum +{ + TYPE_NONE, + TYPE_SCHAR, + TYPE_UCHAR, + TYPE_SHORT, + TYPE_USHORT, + TYPE_INT, + TYPE_UINT, + TYPE_LONGINT, + TYPE_ULONGINT, +#if HAVE_LONG_LONG_INT + TYPE_LONGLONGINT, + TYPE_ULONGLONGINT, +#endif + TYPE_DOUBLE, + TYPE_LONGDOUBLE, + TYPE_CHAR, +#if HAVE_WINT_T + TYPE_WIDE_CHAR, +#endif + TYPE_STRING, +#if HAVE_WCHAR_T + TYPE_WIDE_STRING, +#endif + TYPE_POINTER, + TYPE_COUNT_SCHAR_POINTER, + TYPE_COUNT_SHORT_POINTER, + TYPE_COUNT_INT_POINTER, + TYPE_COUNT_LONGINT_POINTER +#if HAVE_LONG_LONG_INT +, TYPE_COUNT_LONGLONGINT_POINTER +#endif +#if ENABLE_UNISTDIO + /* The unistdio extensions. */ +, TYPE_U8_STRING +, TYPE_U16_STRING +, TYPE_U32_STRING +#endif +} arg_type; + +/* Polymorphic argument */ +typedef struct +{ + arg_type type; + union + { + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_longint; + unsigned long int a_ulongint; +#if HAVE_LONG_LONG_INT + long long int a_longlongint; + unsigned long long int a_ulonglongint; +#endif + float a_float; + double a_double; + long double a_longdouble; + int a_char; +#if HAVE_WINT_T + wint_t a_wide_char; +#endif + const char* a_string; +#if HAVE_WCHAR_T + const wchar_t* a_wide_string; +#endif + void* a_pointer; + signed char * a_count_schar_pointer; + short * a_count_short_pointer; + int * a_count_int_pointer; + long int * a_count_longint_pointer; +#if HAVE_LONG_LONG_INT + long long int * a_count_longlongint_pointer; +#endif +#if ENABLE_UNISTDIO + /* The unistdio extensions. */ + const uint8_t * a_u8_string; + const uint16_t * a_u16_string; + const uint32_t * a_u32_string; +#endif + } + a; +} +argument; + +/* Number of directly allocated arguments (no malloc() needed). */ +#define N_DIRECT_ALLOC_ARGUMENTS 7 + +typedef struct +{ + size_t count; + argument *arg; + argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS]; +} +arguments; + + +/* Fetch the arguments, putting them into a. */ +#ifdef STATIC +STATIC +#else +extern +#endif +int PRINTF_FETCHARGS (va_list args, arguments *a); + +#endif /* _PRINTF_ARGS_H */ diff --git a/grub-core/gnulib/printf-parse.c b/grub-core/gnulib/printf-parse.c new file mode 100644 index 000000000..23cacc1da --- /dev/null +++ b/grub-core/gnulib/printf-parse.c @@ -0,0 +1,638 @@ +/* Formatted output to strings. + Copyright (C) 1999-2000, 2002-2003, 2006-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +/* This file can be parametrized with the following macros: + CHAR_T The element type of the format string. + CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters + in the format string are ASCII. + DIRECTIVE Structure denoting a format directive. + Depends on CHAR_T. + DIRECTIVES Structure denoting the set of format directives of a + format string. Depends on CHAR_T. + PRINTF_PARSE Function that parses a format string. + Depends on CHAR_T. + STATIC Set to 'static' to declare the function static. + ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */ + +#ifndef PRINTF_PARSE +# include +#endif + +/* Specification. */ +#ifndef PRINTF_PARSE +# include "printf-parse.h" +#endif + +/* Default parameters. */ +#ifndef PRINTF_PARSE +# define PRINTF_PARSE printf_parse +# define CHAR_T char +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +#endif + +/* Get size_t, NULL. */ +#include + +/* Get intmax_t. */ +#if defined IN_LIBINTL || defined IN_LIBASPRINTF +# if HAVE_STDINT_H_WITH_UINTMAX +# include +# endif +# if HAVE_INTTYPES_H_WITH_UINTMAX +# include +# endif +#else +# include +#endif + +/* malloc(), realloc(), free(). */ +#include + +/* memcpy(). */ +#include + +/* errno. */ +#include + +/* Checked size_t computations. */ +#include "xsize.h" + +#if CHAR_T_ONLY_ASCII +/* c_isascii(). */ +# include "c-ctype.h" +#endif + +#ifdef STATIC +STATIC +#endif +int +PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) +{ + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ + size_t max_width_length = 0; + size_t max_precision_length = 0; + + d->count = 0; + d_allocated = N_DIRECT_ALLOC_DIRECTIVES; + d->dir = d->direct_alloc_dir; + + a->count = 0; + a_allocated = N_DIRECT_ALLOC_ARGUMENTS; + a->arg = a->direct_alloc_arg; + +#define REGISTER_ARG(_index_,_type_) \ + { \ + size_t n = (_index_); \ + if (n >= a_allocated) \ + { \ + size_t memory_size; \ + argument *memory; \ + \ + a_allocated = xtimes (a_allocated, 2); \ + if (a_allocated <= n) \ + a_allocated = xsum (n, 1); \ + memory_size = xtimes (a_allocated, sizeof (argument)); \ + if (size_overflow_p (memory_size)) \ + /* Overflow, would lead to out of memory. */ \ + goto out_of_memory; \ + memory = (argument *) (a->arg != a->direct_alloc_arg \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto out_of_memory; \ + if (a->arg == a->direct_alloc_arg) \ + memcpy (memory, a->arg, a->count * sizeof (argument)); \ + a->arg = memory; \ + } \ + while (a->count <= n) \ + a->arg[a->count++].type = TYPE_NONE; \ + if (a->arg[n].type == TYPE_NONE) \ + a->arg[n].type = (_type_); \ + else if (a->arg[n].type != (_type_)) \ + /* Ambiguous type for positional argument. */ \ + goto error; \ + } + + while (*cp != '\0') + { + CHAR_T c = *cp++; + if (c == '%') + { + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ + + /* Initialize the next directive. */ + dp->dir_start = cp - 1; + dp->flags = 0; + dp->width_start = NULL; + dp->width_end = NULL; + dp->width_arg_index = ARG_NONE; + dp->precision_start = NULL; + dp->precision_end = NULL; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + arg_index = n - 1; + cp = np + 1; + } + } + + /* Read the flags. */ + for (;;) + { + if (*cp == '\'') + { + dp->flags |= FLAG_GROUP; + cp++; + } + else if (*cp == '-') + { + dp->flags |= FLAG_LEFT; + cp++; + } + else if (*cp == '+') + { + dp->flags |= FLAG_SHOWSIGN; + cp++; + } + else if (*cp == ' ') + { + dp->flags |= FLAG_SPACE; + cp++; + } + else if (*cp == '#') + { + dp->flags |= FLAG_ALT; + cp++; + } + else if (*cp == '0') + { + dp->flags |= FLAG_ZERO; + cp++; + } +#if __GLIBC__ >= 2 && !defined __UCLIBC__ + else if (*cp == 'I') + { + dp->flags |= FLAG_LOCALIZED; + cp++; + } +#endif + else + break; + } + + /* Parse the field width. */ + if (*cp == '*') + { + dp->width_start = cp; + cp++; + dp->width_end = cp; + if (max_width_length < 1) + max_width_length = 1; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + dp->width_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->width_arg_index, TYPE_INT); + } + else if (*cp >= '0' && *cp <= '9') + { + size_t width_length; + + dp->width_start = cp; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->width_end = cp; + width_length = dp->width_end - dp->width_start; + if (max_width_length < width_length) + max_width_length = width_length; + } + + /* Parse the precision. */ + if (*cp == '.') + { + cp++; + if (*cp == '*') + { + dp->precision_start = cp - 1; + cp++; + dp->precision_end = cp; + if (max_precision_length < 2) + max_precision_length = 2; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory + later. */ + goto error; + dp->precision_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->precision_arg_index, TYPE_INT); + } + else + { + size_t precision_length; + + dp->precision_start = cp - 1; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->precision_end = cp; + precision_length = dp->precision_end - dp->precision_start; + if (max_precision_length < precision_length) + max_precision_length = precision_length; + } + } + + { + arg_type type; + + /* Parse argument type/size specifiers. */ + { + int flags = 0; + + for (;;) + { + if (*cp == 'h') + { + flags |= (1 << (flags & 1)); + cp++; + } + else if (*cp == 'L') + { + flags |= 4; + cp++; + } + else if (*cp == 'l') + { + flags += 8; + cp++; + } + else if (*cp == 'j') + { + if (sizeof (intmax_t) > sizeof (long)) + { + /* intmax_t = long long */ + flags += 16; + } + else if (sizeof (intmax_t) > sizeof (int)) + { + /* intmax_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 'z' || *cp == 'Z') + { + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + if (sizeof (size_t) > sizeof (long)) + { + /* size_t = long long */ + flags += 16; + } + else if (sizeof (size_t) > sizeof (int)) + { + /* size_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 't') + { + if (sizeof (ptrdiff_t) > sizeof (long)) + { + /* ptrdiff_t = long long */ + flags += 16; + } + else if (sizeof (ptrdiff_t) > sizeof (int)) + { + /* ptrdiff_t = long */ + flags += 8; + } + cp++; + } +#if defined __APPLE__ && defined __MACH__ + /* On Mac OS X 10.3, PRIdMAX is defined as "qd". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'q') + { + if (64 / 8 > sizeof (long)) + { + /* int64_t = long long */ + flags += 16; + } + else + { + /* int64_t = long */ + flags += 8; + } + cp++; + } +#endif +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* On native Windows, PRIdMAX is defined as "I64d". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') + { + if (64 / 8 > sizeof (long)) + { + /* __int64 = long long */ + flags += 16; + } + else + { + /* __int64 = long */ + flags += 8; + } + cp += 3; + } +#endif + else + break; + } + + /* Read the conversion character. */ + c = *cp++; + switch (c) + { + case 'd': case 'i': +#if HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGLONGINT; + else +#endif + /* If 'long long' exists and is the same as 'long', we parse + "lld" into TYPE_LONGINT. */ + if (flags >= 8) + type = TYPE_LONGINT; + else if (flags & 2) + type = TYPE_SCHAR; + else if (flags & 1) + type = TYPE_SHORT; + else + type = TYPE_INT; + break; + case 'o': case 'u': case 'x': case 'X': +#if HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_ULONGLONGINT; + else +#endif + /* If 'unsigned long long' exists and is the same as + 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + if (flags >= 8) + type = TYPE_ULONGINT; + else if (flags & 2) + type = TYPE_UCHAR; + else if (flags & 1) + type = TYPE_USHORT; + else + type = TYPE_UINT; + break; + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGDOUBLE; + else + type = TYPE_DOUBLE; + break; + case 'c': + if (flags >= 8) +#if HAVE_WINT_T + type = TYPE_WIDE_CHAR; +#else + goto error; +#endif + else + type = TYPE_CHAR; + break; +#if HAVE_WINT_T + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; +#endif + case 's': + if (flags >= 8) +#if HAVE_WCHAR_T + type = TYPE_WIDE_STRING; +#else + goto error; +#endif + else + type = TYPE_STRING; + break; +#if HAVE_WCHAR_T + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; +#endif + case 'p': + type = TYPE_POINTER; + break; + case 'n': +#if HAVE_LONG_LONG_INT + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_COUNT_LONGLONGINT_POINTER; + else +#endif + /* If 'long long' exists and is the same as 'long', we parse + "lln" into TYPE_COUNT_LONGINT_POINTER. */ + if (flags >= 8) + type = TYPE_COUNT_LONGINT_POINTER; + else if (flags & 2) + type = TYPE_COUNT_SCHAR_POINTER; + else if (flags & 1) + type = TYPE_COUNT_SHORT_POINTER; + else + type = TYPE_COUNT_INT_POINTER; + break; +#if ENABLE_UNISTDIO + /* The unistdio extensions. */ + case 'U': + if (flags >= 16) + type = TYPE_U32_STRING; + else if (flags >= 8) + type = TYPE_U16_STRING; + else + type = TYPE_U8_STRING; + break; +#endif + case '%': + type = TYPE_NONE; + break; + default: + /* Unknown conversion character. */ + goto error; + } + } + + if (type != TYPE_NONE) + { + dp->arg_index = arg_index; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->arg_index, type); + } + dp->conversion = c; + dp->dir_end = cp; + } + + d->count++; + if (d->count >= d_allocated) + { + size_t memory_size; + DIRECTIVE *memory; + + d_allocated = xtimes (d_allocated, 2); + memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); + if (size_overflow_p (memory_size)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir + ? realloc (d->dir, memory_size) + : malloc (memory_size)); + if (memory == NULL) + /* Out of memory. */ + goto out_of_memory; + if (d->dir == d->direct_alloc_dir) + memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE)); + d->dir = memory; + } + } +#if CHAR_T_ONLY_ASCII + else if (!c_isascii (c)) + { + /* Non-ASCII character. Not supported. */ + goto error; + } +#endif + } + d->dir[d->count].dir_start = cp; + + d->max_width_length = max_width_length; + d->max_precision_length = max_precision_length; + return 0; + +error: + if (a->arg != a->direct_alloc_arg) + free (a->arg); + if (d->dir != d->direct_alloc_dir) + free (d->dir); + errno = EINVAL; + return -1; + +out_of_memory: + if (a->arg != a->direct_alloc_arg) + free (a->arg); + if (d->dir != d->direct_alloc_dir) + free (d->dir); + errno = ENOMEM; + return -1; +} + +#undef PRINTF_PARSE +#undef DIRECTIVES +#undef DIRECTIVE +#undef CHAR_T_ONLY_ASCII +#undef CHAR_T diff --git a/grub-core/gnulib/printf-parse.h b/grub-core/gnulib/printf-parse.h new file mode 100644 index 000000000..d8474bee1 --- /dev/null +++ b/grub-core/gnulib/printf-parse.h @@ -0,0 +1,193 @@ +/* Parse printf format string. + Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _PRINTF_PARSE_H +#define _PRINTF_PARSE_H + +/* This file can be parametrized with the following macros: + ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. + STATIC Set to 'static' to declare the function static. */ + +#if HAVE_FEATURES_H +# include /* for __GLIBC__, __UCLIBC__ */ +#endif + +#include "printf-args.h" + + +/* Flags */ +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 +#if __GLIBC__ >= 2 && !defined __UCLIBC__ +# define FLAG_LOCALIZED 64 /* I flag, uses localized digits */ +#endif + +/* arg_index value indicating that no argument is consumed. */ +#define ARG_NONE (~(size_t)0) + +/* xxx_directive: A parsed directive. + xxx_directives: A parsed format string. */ + +/* Number of directly allocated directives (no malloc() needed). */ +#define N_DIRECT_ALLOC_DIRECTIVES 7 + +/* A parsed directive. */ +typedef struct +{ + const char* dir_start; + const char* dir_end; + int flags; + const char* width_start; + const char* width_end; + size_t width_arg_index; + const char* precision_start; + const char* precision_end; + size_t precision_arg_index; + char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ + size_t arg_index; +} +char_directive; + +/* A parsed format string. */ +typedef struct +{ + size_t count; + char_directive *dir; + size_t max_width_length; + size_t max_precision_length; + char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES]; +} +char_directives; + +#if ENABLE_UNISTDIO + +/* A parsed directive. */ +typedef struct +{ + const uint8_t* dir_start; + const uint8_t* dir_end; + int flags; + const uint8_t* width_start; + const uint8_t* width_end; + size_t width_arg_index; + const uint8_t* precision_start; + const uint8_t* precision_end; + size_t precision_arg_index; + uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ + size_t arg_index; +} +u8_directive; + +/* A parsed format string. */ +typedef struct +{ + size_t count; + u8_directive *dir; + size_t max_width_length; + size_t max_precision_length; + u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES]; +} +u8_directives; + +/* A parsed directive. */ +typedef struct +{ + const uint16_t* dir_start; + const uint16_t* dir_end; + int flags; + const uint16_t* width_start; + const uint16_t* width_end; + size_t width_arg_index; + const uint16_t* precision_start; + const uint16_t* precision_end; + size_t precision_arg_index; + uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ + size_t arg_index; +} +u16_directive; + +/* A parsed format string. */ +typedef struct +{ + size_t count; + u16_directive *dir; + size_t max_width_length; + size_t max_precision_length; + u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES]; +} +u16_directives; + +/* A parsed directive. */ +typedef struct +{ + const uint32_t* dir_start; + const uint32_t* dir_end; + int flags; + const uint32_t* width_start; + const uint32_t* width_end; + size_t width_arg_index; + const uint32_t* precision_start; + const uint32_t* precision_end; + size_t precision_arg_index; + uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ + size_t arg_index; +} +u32_directive; + +/* A parsed format string. */ +typedef struct +{ + size_t count; + u32_directive *dir; + size_t max_width_length; + size_t max_precision_length; + u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES]; +} +u32_directives; + +#endif + + +/* Parses the format string. Fills in the number N of directives, and fills + in directives[0], ..., directives[N-1], and sets directives[N].dir_start + to the end of the format string. Also fills in the arg_type fields of the + arguments and the needed count of arguments. */ +#if ENABLE_UNISTDIO +extern int + ulc_printf_parse (const char *format, char_directives *d, arguments *a); +extern int + u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a); +extern int + u16_printf_parse (const uint16_t *format, u16_directives *d, + arguments *a); +extern int + u32_printf_parse (const uint32_t *format, u32_directives *d, + arguments *a); +#else +# ifdef STATIC +STATIC +# else +extern +# endif +int printf_parse (const char *format, char_directives *d, arguments *a); +#endif + +#endif /* _PRINTF_PARSE_H */ diff --git a/grub-core/gnulib/progname.c b/grub-core/gnulib/progname.c new file mode 100644 index 000000000..0c195e521 --- /dev/null +++ b/grub-core/gnulib/progname.c @@ -0,0 +1,92 @@ +/* Program name management. + Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +/* Specification. */ +#undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */ +#include "progname.h" + +#include /* get program_invocation_name declaration */ +#include +#include +#include + + +/* String containing name the program is called with. + To be initialized by main(). */ +const char *program_name = NULL; + +/* Set program_name, based on argv[0]. + argv0 must be a string allocated with indefinite extent, and must not be + modified after this call. */ +void +set_program_name (const char *argv0) +{ + /* libtool creates a temporary executable whose name is sometimes prefixed + with "lt-" (depends on the platform). It also makes argv[0] absolute. + But the name of the temporary executable is a detail that should not be + visible to the end user and to the test suite. + Remove this "/.libs/" or "/.libs/lt-" prefix here. */ + const char *slash; + const char *base; + + /* Sanity check. POSIX requires the invoking process to pass a non-NULL + argv[0]. */ + if (argv0 == NULL) + { + /* It's a bug in the invoking program. Help diagnosing it. */ + fputs ("A NULL argv[0] was passed through an exec system call.\n", + stderr); + abort (); + } + + slash = strrchr (argv0, '/'); + base = (slash != NULL ? slash + 1 : argv0); + if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0) + { + argv0 = base; + if (strncmp (base, "lt-", 3) == 0) + { + argv0 = base + 3; + /* On glibc systems, remove the "lt-" prefix from the variable + program_invocation_short_name. */ +#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + program_invocation_short_name = (char *) argv0; +#endif + } + } + + /* But don't strip off a leading / in general, because when the user + runs + /some/hidden/place/bin/cp foo foo + he should get the error message + /some/hidden/place/bin/cp: `foo' and `foo' are the same file + not + cp: `foo' and `foo' are the same file + */ + + program_name = argv0; + + /* On glibc systems, the error() function comes from libc and uses the + variable program_invocation_name, not program_name. So set this variable + as well. */ +#if HAVE_DECL_PROGRAM_INVOCATION_NAME + program_invocation_name = (char *) argv0; +#endif +} diff --git a/grub-core/gnulib/progname.h b/grub-core/gnulib/progname.h new file mode 100644 index 000000000..b4f3c2778 --- /dev/null +++ b/grub-core/gnulib/progname.h @@ -0,0 +1,62 @@ +/* Program name management. + Copyright (C) 2001-2004, 2006, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _PROGNAME_H +#define _PROGNAME_H + +/* Programs using this file should do the following in main(): + set_program_name (argv[0]); + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* String containing name the program is called with. */ +extern const char *program_name; + +/* Set program_name, based on argv[0]. + argv0 must be a string allocated with indefinite extent, and must not be + modified after this call. */ +extern void set_program_name (const char *argv0); + +#if ENABLE_RELOCATABLE + +/* Set program_name, based on argv[0], and original installation prefix and + directory, for relocatability. */ +extern void set_program_name_and_installdir (const char *argv0, + const char *orig_installprefix, + const char *orig_installdir); +#undef set_program_name +#define set_program_name(ARG0) \ + set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR) + +/* Return the full pathname of the current executable, based on the earlier + call to set_program_name_and_installdir. Return NULL if unknown. */ +extern char *get_full_program_name (void); + +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif /* _PROGNAME_H */ diff --git a/grub-core/gnulib/rawmemchr.c b/grub-core/gnulib/rawmemchr.c new file mode 100644 index 000000000..a0298ce64 --- /dev/null +++ b/grub-core/gnulib/rawmemchr.c @@ -0,0 +1,136 @@ +/* Searching in a string. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +/* Find the first occurrence of C in S. */ +void * +rawmemchr (const void *s, int c_in) +{ + /* On 32-bit hardware, choosing longword to be a 32-bit unsigned + long instead of a 64-bit uintmax_t tends to give better + performance. On 64-bit hardware, unsigned long is generally 64 + bits already. Change this typedef to experiment with + performance. */ + typedef unsigned long int longword; + + const unsigned char *char_ptr; + const longword *longword_ptr; + longword repeated_one; + longword repeated_c; + unsigned char c; + + c = (unsigned char) c_in; + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + (size_t) char_ptr % sizeof (longword) != 0; + ++char_ptr) + if (*char_ptr == c) + return (void *) char_ptr; + + longword_ptr = (const longword *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + repeated_one = 0x01010101; + repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + } + + /* Instead of the traditional loop which tests each byte, we will + test a longword at a time. The tricky part is testing if *any of + the four* bytes in the longword in question are equal to NUL or + c. We first use an xor with repeated_c. This reduces the task + to testing whether *any of the four* bytes in longword1 is zero. + + We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + The test whether any byte in longword1 is zero is equivalent + to testing whether tmp is nonzero. + + This test can read beyond the end of a string, depending on where + C_IN is encountered. However, this is considered safe since the + initialization phase ensured that the read will be aligned, + therefore, the read will not cross page boundaries and will not + cause a fault. */ + + while (1) + { + longword longword1 = *longword_ptr ^ repeated_c; + + if ((((longword1 - repeated_one) & ~longword1) + & (repeated_one << 7)) != 0) + break; + longword_ptr++; + } + + char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that one of the sizeof (longword) bytes + starting at char_ptr is == c. On little-endian machines, we + could determine the first such byte without any further memory + accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. + Choose code that works in both cases. */ + + char_ptr = (unsigned char *) longword_ptr; + while (*char_ptr != c) + char_ptr++; + return (void *) char_ptr; +} diff --git a/grub-core/gnulib/rawmemchr.valgrind b/grub-core/gnulib/rawmemchr.valgrind new file mode 100644 index 000000000..636392368 --- /dev/null +++ b/grub-core/gnulib/rawmemchr.valgrind @@ -0,0 +1,12 @@ +# Suppress a valgrind message about use of uninitialized memory in rawmemchr(). +# This use is OK because it provides only a speedup. +{ + rawmemchr-value4 + Memcheck:Value4 + fun:rawmemchr +} +{ + rawmemchr-value8 + Memcheck:Value8 + fun:rawmemchr +} diff --git a/grub-core/gnulib/realloc.c b/grub-core/gnulib/realloc.c new file mode 100644 index 000000000..b51010a62 --- /dev/null +++ b/grub-core/gnulib/realloc.c @@ -0,0 +1,79 @@ +/* realloc() function that is glibc compatible. + + Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2013 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Jim Meyering and Bruno Haible */ + +#define _GL_USE_STDLIB_ALLOC 1 +#include + +/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */ +#ifdef realloc +# define NEED_REALLOC_GNU 1 +/* Whereas the gnulib module 'realloc-gnu' defines HAVE_REALLOC_GNU. */ +#elif GNULIB_REALLOC_GNU && !HAVE_REALLOC_GNU +# define NEED_REALLOC_GNU 1 +#endif + +/* Infer the properties of the system's malloc function. + The gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */ +#if GNULIB_MALLOC_GNU && HAVE_MALLOC_GNU +# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1 +#endif + +#include + +#include + +/* Change the size of an allocated block of memory P to N bytes, + with error checking. If N is zero, change it to 1. If P is NULL, + use malloc. */ + +void * +rpl_realloc (void *p, size_t n) +{ + void *result; + +#if NEED_REALLOC_GNU + if (n == 0) + { + n = 1; + + /* In theory realloc might fail, so don't rely on it to free. */ + free (p); + p = NULL; + } +#endif + + if (p == NULL) + { +#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE + if (n == 0) + n = 1; +#endif + result = malloc (n); + } + else + result = realloc (p, n); + +#if !HAVE_REALLOC_POSIX + if (result == NULL) + errno = ENOMEM; +#endif + + return result; +} diff --git a/grub-core/gnulib/ref-add.sin b/grub-core/gnulib/ref-add.sin new file mode 100644 index 000000000..112bcdc64 --- /dev/null +++ b/grub-core/gnulib/ref-add.sin @@ -0,0 +1,29 @@ +# Add this package to a list of references stored in a text file. +# +# Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see . +# +# Written by Bruno Haible . +# +/^# Packages using this file: / { + s/# Packages using this file:// + ta + :a + s/ @PACKAGE@ / @PACKAGE@ / + tb + s/ $/ @PACKAGE@ / + :b + s/^/# Packages using this file:/ +} diff --git a/grub-core/gnulib/ref-del.sin b/grub-core/gnulib/ref-del.sin new file mode 100644 index 000000000..6f7386847 --- /dev/null +++ b/grub-core/gnulib/ref-del.sin @@ -0,0 +1,24 @@ +# Remove this package from a list of references stored in a text file. +# +# Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see . +# +# Written by Bruno Haible . +# +/^# Packages using this file: / { + s/# Packages using this file:// + s/ @PACKAGE@ / / + s/^/# Packages using this file:/ +} diff --git a/grub-core/gnulib/regcomp.c b/grub-core/gnulib/regcomp.c new file mode 100644 index 000000000..596e0cf3e --- /dev/null +++ b/grub-core/gnulib/regcomp.c @@ -0,0 +1,3913 @@ +/* Extended regular expression matching and search library. + Copyright (C) 2002-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Isamu Hasegawa . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, + size_t length, reg_syntax_t syntax); +static void re_compile_fastmap_iter (regex_t *bufp, + const re_dfastate_t *init_state, + char *fastmap); +static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len); +#ifdef RE_ENABLE_I18N +static void free_charset (re_charset_t *cset); +#endif /* RE_ENABLE_I18N */ +static void free_workarea_compile (regex_t *preg); +static reg_errcode_t create_initial_state (re_dfa_t *dfa); +#ifdef RE_ENABLE_I18N +static void optimize_utf8 (re_dfa_t *dfa); +#endif +static reg_errcode_t analyze (regex_t *preg); +static reg_errcode_t preorder (bin_tree_t *root, + reg_errcode_t (fn (void *, bin_tree_t *)), + void *extra); +static reg_errcode_t postorder (bin_tree_t *root, + reg_errcode_t (fn (void *, bin_tree_t *)), + void *extra); +static reg_errcode_t optimize_subexps (void *extra, bin_tree_t *node); +static reg_errcode_t lower_subexps (void *extra, bin_tree_t *node); +static bin_tree_t *lower_subexp (reg_errcode_t *err, regex_t *preg, + bin_tree_t *node); +static reg_errcode_t calc_first (void *extra, bin_tree_t *node); +static reg_errcode_t calc_next (void *extra, bin_tree_t *node); +static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node); +static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint); +static Idx search_duplicated_node (const re_dfa_t *dfa, Idx org_node, + unsigned int constraint); +static reg_errcode_t calc_eclosure (re_dfa_t *dfa); +static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, + Idx node, bool root); +static reg_errcode_t calc_inveclosure (re_dfa_t *dfa); +static Idx fetch_number (re_string_t *input, re_token_t *token, + reg_syntax_t syntax); +static int peek_token (re_token_t *token, re_string_t *input, + reg_syntax_t syntax) internal_function; +static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, + reg_syntax_t syntax, reg_errcode_t *err); +static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg, + re_token_t *token, reg_syntax_t syntax, + Idx nest, reg_errcode_t *err); +static bin_tree_t *parse_branch (re_string_t *regexp, regex_t *preg, + re_token_t *token, reg_syntax_t syntax, + Idx nest, reg_errcode_t *err); +static bin_tree_t *parse_expression (re_string_t *regexp, regex_t *preg, + re_token_t *token, reg_syntax_t syntax, + Idx nest, reg_errcode_t *err); +static bin_tree_t *parse_sub_exp (re_string_t *regexp, regex_t *preg, + re_token_t *token, reg_syntax_t syntax, + Idx nest, reg_errcode_t *err); +static bin_tree_t *parse_dup_op (bin_tree_t *dup_elem, re_string_t *regexp, + re_dfa_t *dfa, re_token_t *token, + reg_syntax_t syntax, reg_errcode_t *err); +static bin_tree_t *parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, + re_token_t *token, reg_syntax_t syntax, + reg_errcode_t *err); +static reg_errcode_t parse_bracket_element (bracket_elem_t *elem, + re_string_t *regexp, + re_token_t *token, int token_len, + re_dfa_t *dfa, + reg_syntax_t syntax, + bool accept_hyphen); +static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem, + re_string_t *regexp, + re_token_t *token); +#ifdef RE_ENABLE_I18N +static reg_errcode_t build_equiv_class (bitset_t sbcset, + re_charset_t *mbcset, + Idx *equiv_class_alloc, + const unsigned char *name); +static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, + bitset_t sbcset, + re_charset_t *mbcset, + Idx *char_class_alloc, + const char *class_name, + reg_syntax_t syntax); +#else /* not RE_ENABLE_I18N */ +static reg_errcode_t build_equiv_class (bitset_t sbcset, + const unsigned char *name); +static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans, + bitset_t sbcset, + const char *class_name, + reg_syntax_t syntax); +#endif /* not RE_ENABLE_I18N */ +static bin_tree_t *build_charclass_op (re_dfa_t *dfa, + RE_TRANSLATE_TYPE trans, + const char *class_name, + const char *extra, + bool non_match, reg_errcode_t *err); +static bin_tree_t *create_tree (re_dfa_t *dfa, + bin_tree_t *left, bin_tree_t *right, + re_token_type_t type); +static bin_tree_t *create_token_tree (re_dfa_t *dfa, + bin_tree_t *left, bin_tree_t *right, + const re_token_t *token); +static bin_tree_t *duplicate_tree (const bin_tree_t *src, re_dfa_t *dfa); +static void free_token (re_token_t *node); +static reg_errcode_t free_tree (void *extra, bin_tree_t *node); +static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node); + +/* This table gives an error message for each of the error codes listed + in regex.h. Obviously the order here has to be same as there. + POSIX doesn't require that we do anything for REG_NOERROR, + but why not be nice? */ + +static const char __re_error_msgid[] = + { +#define REG_NOERROR_IDX 0 + gettext_noop ("Success") /* REG_NOERROR */ + "\0" +#define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success") + gettext_noop ("No match") /* REG_NOMATCH */ + "\0" +#define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match") + gettext_noop ("Invalid regular expression") /* REG_BADPAT */ + "\0" +#define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression") + gettext_noop ("Invalid collation character") /* REG_ECOLLATE */ + "\0" +#define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character") + gettext_noop ("Invalid character class name") /* REG_ECTYPE */ + "\0" +#define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name") + gettext_noop ("Trailing backslash") /* REG_EESCAPE */ + "\0" +#define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash") + gettext_noop ("Invalid back reference") /* REG_ESUBREG */ + "\0" +#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference") + gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */ + "\0" +#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^") + gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */ + "\0" +#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(") + gettext_noop ("Unmatched \\{") /* REG_EBRACE */ + "\0" +#define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{") + gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */ + "\0" +#define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}") + gettext_noop ("Invalid range end") /* REG_ERANGE */ + "\0" +#define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end") + gettext_noop ("Memory exhausted") /* REG_ESPACE */ + "\0" +#define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted") + gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */ + "\0" +#define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression") + gettext_noop ("Premature end of regular expression") /* REG_EEND */ + "\0" +#define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression") + gettext_noop ("Regular expression too big") /* REG_ESIZE */ + "\0" +#define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big") + gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ + }; + +static const size_t __re_error_msgid_idx[] = + { + REG_NOERROR_IDX, + REG_NOMATCH_IDX, + REG_BADPAT_IDX, + REG_ECOLLATE_IDX, + REG_ECTYPE_IDX, + REG_EESCAPE_IDX, + REG_ESUBREG_IDX, + REG_EBRACK_IDX, + REG_EPAREN_IDX, + REG_EBRACE_IDX, + REG_BADBR_IDX, + REG_ERANGE_IDX, + REG_ESPACE_IDX, + REG_BADRPT_IDX, + REG_EEND_IDX, + REG_ESIZE_IDX, + REG_ERPAREN_IDX + }; + +/* Entry points for GNU code. */ + +/* re_compile_pattern is the GNU regular expression compiler: it + compiles PATTERN (of length LENGTH) and puts the result in BUFP. + Returns 0 if the pattern was valid, otherwise an error string. + + Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields + are set in BUFP on entry. */ + +#ifdef _LIBC +const char * +re_compile_pattern (pattern, length, bufp) + const char *pattern; + size_t length; + struct re_pattern_buffer *bufp; +#else /* size_t might promote */ +const char * +re_compile_pattern (const char *pattern, size_t length, + struct re_pattern_buffer *bufp) +#endif +{ + reg_errcode_t ret; + + /* And GNU code determines whether or not to get register information + by passing null for the REGS argument to re_match, etc., not by + setting no_sub, unless RE_NO_SUB is set. */ + bufp->no_sub = !!(re_syntax_options & RE_NO_SUB); + + /* Match anchors at newline. */ + bufp->newline_anchor = 1; + + ret = re_compile_internal (bufp, pattern, length, re_syntax_options); + + if (!ret) + return NULL; + return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]); +} +#ifdef _LIBC +weak_alias (__re_compile_pattern, re_compile_pattern) +#endif + +/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can + also be assigned to arbitrarily: each pattern buffer stores its own + syntax, so it can be changed between regex compilations. */ +/* This has no initializer because initialized variables in Emacs + become read-only after dumping. */ +reg_syntax_t re_syntax_options; + + +/* Specify the precise syntax of regexps for compilation. This provides + for compatibility for various utilities which historically have + different, incompatible syntaxes. + + The argument SYNTAX is a bit mask comprised of the various bits + defined in regex.h. We return the old syntax. */ + +reg_syntax_t +re_set_syntax (syntax) + reg_syntax_t syntax; +{ + reg_syntax_t ret = re_syntax_options; + + re_syntax_options = syntax; + return ret; +} +#ifdef _LIBC +weak_alias (__re_set_syntax, re_set_syntax) +#endif + +int +re_compile_fastmap (bufp) + struct re_pattern_buffer *bufp; +{ + re_dfa_t *dfa = bufp->buffer; + char *fastmap = bufp->fastmap; + + memset (fastmap, '\0', sizeof (char) * SBC_MAX); + re_compile_fastmap_iter (bufp, dfa->init_state, fastmap); + if (dfa->init_state != dfa->init_state_word) + re_compile_fastmap_iter (bufp, dfa->init_state_word, fastmap); + if (dfa->init_state != dfa->init_state_nl) + re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap); + if (dfa->init_state != dfa->init_state_begbuf) + re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap); + bufp->fastmap_accurate = 1; + return 0; +} +#ifdef _LIBC +weak_alias (__re_compile_fastmap, re_compile_fastmap) +#endif + +static inline void +__attribute__ ((always_inline)) +re_set_fastmap (char *fastmap, bool icase, int ch) +{ + fastmap[ch] = 1; + if (icase) + fastmap[tolower (ch)] = 1; +} + +/* Helper function for re_compile_fastmap. + Compile fastmap for the initial_state INIT_STATE. */ + +static void +re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, + char *fastmap) +{ + re_dfa_t *dfa = bufp->buffer; + Idx node_cnt; + bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE)); + for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) + { + Idx node = init_state->nodes.elems[node_cnt]; + re_token_type_t type = dfa->nodes[node].type; + + if (type == CHARACTER) + { + re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c); +#ifdef RE_ENABLE_I18N + if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) + { + unsigned char buf[MB_LEN_MAX]; + unsigned char *p; + wchar_t wc; + mbstate_t state; + + p = buf; + *p++ = dfa->nodes[node].opr.c; + while (++node < dfa->nodes_len + && dfa->nodes[node].type == CHARACTER + && dfa->nodes[node].mb_partial) + *p++ = dfa->nodes[node].opr.c; + memset (&state, '\0', sizeof (state)); + if (__mbrtowc (&wc, (const char *) buf, p - buf, + &state) == p - buf + && (__wcrtomb ((char *) buf, towlower (wc), &state) + != (size_t) -1)) + re_set_fastmap (fastmap, false, buf[0]); + } +#endif + } + else if (type == SIMPLE_BRACKET) + { + int i, ch; + for (i = 0, ch = 0; i < BITSET_WORDS; ++i) + { + int j; + bitset_word_t w = dfa->nodes[node].opr.sbcset[i]; + for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) + if (w & ((bitset_word_t) 1 << j)) + re_set_fastmap (fastmap, icase, ch); + } + } +#ifdef RE_ENABLE_I18N + else if (type == COMPLEX_BRACKET) + { + re_charset_t *cset = dfa->nodes[node].opr.mbcset; + Idx i; + +# ifdef _LIBC + /* See if we have to try all bytes which start multiple collation + elements. + e.g. In da_DK, we want to catch 'a' since "aa" is a valid + collation element, and don't catch 'b' since 'b' is + the only collation element which starts from 'b' (and + it is caught by SIMPLE_BRACKET). */ + if (_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES) != 0 + && (cset->ncoll_syms || cset->nranges)) + { + const int32_t *table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); + for (i = 0; i < SBC_MAX; ++i) + if (table[i] < 0) + re_set_fastmap (fastmap, icase, i); + } +# endif /* _LIBC */ + + /* See if we have to start the match at all multibyte characters, + i.e. where we would not find an invalid sequence. This only + applies to multibyte character sets; for single byte character + sets, the SIMPLE_BRACKET again suffices. */ + if (dfa->mb_cur_max > 1 + && (cset->nchar_classes || cset->non_match || cset->nranges +# ifdef _LIBC + || cset->nequiv_classes +# endif /* _LIBC */ + )) + { + unsigned char c = 0; + do + { + mbstate_t mbs; + memset (&mbs, 0, sizeof (mbs)); + if (__mbrtowc (NULL, (char *) &c, 1, &mbs) == (size_t) -2) + re_set_fastmap (fastmap, false, (int) c); + } + while (++c != 0); + } + + else + { + /* ... Else catch all bytes which can start the mbchars. */ + for (i = 0; i < cset->nmbchars; ++i) + { + char buf[256]; + mbstate_t state; + memset (&state, '\0', sizeof (state)); + if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1) + re_set_fastmap (fastmap, icase, *(unsigned char *) buf); + if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) + { + if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) + != (size_t) -1) + re_set_fastmap (fastmap, false, *(unsigned char *) buf); + } + } + } + } +#endif /* RE_ENABLE_I18N */ + else if (type == OP_PERIOD +#ifdef RE_ENABLE_I18N + || type == OP_UTF8_PERIOD +#endif /* RE_ENABLE_I18N */ + || type == END_OF_RE) + { + memset (fastmap, '\1', sizeof (char) * SBC_MAX); + if (type == END_OF_RE) + bufp->can_be_null = 1; + return; + } + } +} + +/* Entry point for POSIX code. */ +/* regcomp takes a regular expression as a string and compiles it. + + PREG is a regex_t *. We do not expect any fields to be initialized, + since POSIX says we shouldn't. Thus, we set + + 'buffer' to the compiled pattern; + 'used' to the length of the compiled pattern; + 'syntax' to RE_SYNTAX_POSIX_EXTENDED if the + REG_EXTENDED bit in CFLAGS is set; otherwise, to + RE_SYNTAX_POSIX_BASIC; + 'newline_anchor' to REG_NEWLINE being set in CFLAGS; + 'fastmap' to an allocated space for the fastmap; + 'fastmap_accurate' to zero; + 're_nsub' to the number of subexpressions in PATTERN. + + PATTERN is the address of the pattern string. + + CFLAGS is a series of bits which affect compilation. + + If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we + use POSIX basic syntax. + + If REG_NEWLINE is set, then . and [^...] don't match newline. + Also, regexec will try a match beginning after every newline. + + If REG_ICASE is set, then we considers upper- and lowercase + versions of letters to be equivalent when matching. + + If REG_NOSUB is set, then when PREG is passed to regexec, that + routine will report only success or failure, and nothing about the + registers. + + It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for + the return codes and their meanings.) */ + +int +regcomp (preg, pattern, cflags) + regex_t *_Restrict_ preg; + const char *_Restrict_ pattern; + int cflags; +{ + reg_errcode_t ret; + reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED + : RE_SYNTAX_POSIX_BASIC); + + preg->buffer = NULL; + preg->allocated = 0; + preg->used = 0; + + /* Try to allocate space for the fastmap. */ + preg->fastmap = re_malloc (char, SBC_MAX); + if (BE (preg->fastmap == NULL, 0)) + return REG_ESPACE; + + syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0; + + /* If REG_NEWLINE is set, newlines are treated differently. */ + if (cflags & REG_NEWLINE) + { /* REG_NEWLINE implies neither . nor [^...] match newline. */ + syntax &= ~RE_DOT_NEWLINE; + syntax |= RE_HAT_LISTS_NOT_NEWLINE; + /* It also changes the matching behavior. */ + preg->newline_anchor = 1; + } + else + preg->newline_anchor = 0; + preg->no_sub = !!(cflags & REG_NOSUB); + preg->translate = NULL; + + ret = re_compile_internal (preg, pattern, strlen (pattern), syntax); + + /* POSIX doesn't distinguish between an unmatched open-group and an + unmatched close-group: both are REG_EPAREN. */ + if (ret == REG_ERPAREN) + ret = REG_EPAREN; + + /* We have already checked preg->fastmap != NULL. */ + if (BE (ret == REG_NOERROR, 1)) + /* Compute the fastmap now, since regexec cannot modify the pattern + buffer. This function never fails in this implementation. */ + (void) re_compile_fastmap (preg); + else + { + /* Some error occurred while compiling the expression. */ + re_free (preg->fastmap); + preg->fastmap = NULL; + } + + return (int) ret; +} +#ifdef _LIBC +weak_alias (__regcomp, regcomp) +#endif + +/* Returns a message corresponding to an error code, ERRCODE, returned + from either regcomp or regexec. We don't use PREG here. */ + +#ifdef _LIBC +size_t +regerror (errcode, preg, errbuf, errbuf_size) + int errcode; + const regex_t *_Restrict_ preg; + char *_Restrict_ errbuf; + size_t errbuf_size; +#else /* size_t might promote */ +size_t +regerror (int errcode, const regex_t *_Restrict_ preg, + char *_Restrict_ errbuf, size_t errbuf_size) +#endif +{ + const char *msg; + size_t msg_size; + + if (BE (errcode < 0 + || errcode >= (int) (sizeof (__re_error_msgid_idx) + / sizeof (__re_error_msgid_idx[0])), 0)) + msg = gettext ("unknown regexp error"); + else + msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); + + msg_size = strlen (msg) + 1; /* Includes the null. */ + + if (BE (errbuf_size != 0, 1)) + { + size_t cpy_size = msg_size; + if (BE (msg_size > errbuf_size, 0)) + { + cpy_size = errbuf_size - 1; + errbuf[cpy_size] = '\0'; + } + memcpy (errbuf, msg, cpy_size); + } + + return msg_size; +} +#ifdef _LIBC +weak_alias (__regerror, regerror) +#endif + + +#ifdef RE_ENABLE_I18N +/* This static array is used for the map to single-byte characters when + UTF-8 is used. Otherwise we would allocate memory just to initialize + it the same all the time. UTF-8 is the preferred encoding so this is + a worthwhile optimization. */ +static const bitset_t utf8_sb_map = +{ + /* Set the first 128 bits. */ +# ifdef __GNUC__ + [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX +# else +# if 4 * BITSET_WORD_BITS < ASCII_CHARS +# error "bitset_word_t is narrower than 32 bits" +# elif 3 * BITSET_WORD_BITS < ASCII_CHARS + BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX, +# elif 2 * BITSET_WORD_BITS < ASCII_CHARS + BITSET_WORD_MAX, BITSET_WORD_MAX, +# elif 1 * BITSET_WORD_BITS < ASCII_CHARS + BITSET_WORD_MAX, +# endif + (BITSET_WORD_MAX + >> (SBC_MAX % BITSET_WORD_BITS == 0 + ? 0 + : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS)) +# endif +}; +#endif + + +static void +free_dfa_content (re_dfa_t *dfa) +{ + Idx i, j; + + if (dfa->nodes) + for (i = 0; i < dfa->nodes_len; ++i) + free_token (dfa->nodes + i); + re_free (dfa->nexts); + for (i = 0; i < dfa->nodes_len; ++i) + { + if (dfa->eclosures != NULL) + re_node_set_free (dfa->eclosures + i); + if (dfa->inveclosures != NULL) + re_node_set_free (dfa->inveclosures + i); + if (dfa->edests != NULL) + re_node_set_free (dfa->edests + i); + } + re_free (dfa->edests); + re_free (dfa->eclosures); + re_free (dfa->inveclosures); + re_free (dfa->nodes); + + if (dfa->state_table) + for (i = 0; i <= dfa->state_hash_mask; ++i) + { + struct re_state_table_entry *entry = dfa->state_table + i; + for (j = 0; j < entry->num; ++j) + { + re_dfastate_t *state = entry->array[j]; + free_state (state); + } + re_free (entry->array); + } + re_free (dfa->state_table); +#ifdef RE_ENABLE_I18N + if (dfa->sb_char != utf8_sb_map) + re_free (dfa->sb_char); +#endif + re_free (dfa->subexp_map); +#ifdef DEBUG + re_free (dfa->re_str); +#endif + + re_free (dfa); +} + + +/* Free dynamically allocated space used by PREG. */ + +void +regfree (preg) + regex_t *preg; +{ + re_dfa_t *dfa = preg->buffer; + if (BE (dfa != NULL, 1)) + free_dfa_content (dfa); + preg->buffer = NULL; + preg->allocated = 0; + + re_free (preg->fastmap); + preg->fastmap = NULL; + + re_free (preg->translate); + preg->translate = NULL; +} +#ifdef _LIBC +weak_alias (__regfree, regfree) +#endif + +/* Entry points compatible with 4.2 BSD regex library. We don't define + them unless specifically requested. */ + +#if defined _REGEX_RE_COMP || defined _LIBC + +/* BSD has one and only one pattern buffer. */ +static struct re_pattern_buffer re_comp_buf; + +char * +# ifdef _LIBC +/* Make these definitions weak in libc, so POSIX programs can redefine + these names if they don't use our functions, and still use + regcomp/regexec above without link errors. */ +weak_function +# endif +re_comp (s) + const char *s; +{ + reg_errcode_t ret; + char *fastmap; + + if (!s) + { + if (!re_comp_buf.buffer) + return gettext ("No previous regular expression"); + return 0; + } + + if (re_comp_buf.buffer) + { + fastmap = re_comp_buf.fastmap; + re_comp_buf.fastmap = NULL; + __regfree (&re_comp_buf); + memset (&re_comp_buf, '\0', sizeof (re_comp_buf)); + re_comp_buf.fastmap = fastmap; + } + + if (re_comp_buf.fastmap == NULL) + { + re_comp_buf.fastmap = (char *) malloc (SBC_MAX); + if (re_comp_buf.fastmap == NULL) + return (char *) gettext (__re_error_msgid + + __re_error_msgid_idx[(int) REG_ESPACE]); + } + + /* Since 're_exec' always passes NULL for the 'regs' argument, we + don't need to initialize the pattern buffer fields which affect it. */ + + /* Match anchors at newlines. */ + re_comp_buf.newline_anchor = 1; + + ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options); + + if (!ret) + return NULL; + + /* Yes, we're discarding 'const' here if !HAVE_LIBINTL. */ + return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]); +} + +#ifdef _LIBC +libc_freeres_fn (free_mem) +{ + __regfree (&re_comp_buf); +} +#endif + +#endif /* _REGEX_RE_COMP */ + +/* Internal entry point. + Compile the regular expression PATTERN, whose length is LENGTH. + SYNTAX indicate regular expression's syntax. */ + +static reg_errcode_t +re_compile_internal (regex_t *preg, const char * pattern, size_t length, + reg_syntax_t syntax) +{ + reg_errcode_t err = REG_NOERROR; + re_dfa_t *dfa; + re_string_t regexp; + + /* Initialize the pattern buffer. */ + preg->fastmap_accurate = 0; + preg->syntax = syntax; + preg->not_bol = preg->not_eol = 0; + preg->used = 0; + preg->re_nsub = 0; + preg->can_be_null = 0; + preg->regs_allocated = REGS_UNALLOCATED; + + /* Initialize the dfa. */ + dfa = preg->buffer; + if (BE (preg->allocated < sizeof (re_dfa_t), 0)) + { + /* If zero allocated, but buffer is non-null, try to realloc + enough space. This loses if buffer's address is bogus, but + that is the user's responsibility. If ->buffer is NULL this + is a simple allocation. */ + dfa = re_realloc (preg->buffer, re_dfa_t, 1); + if (dfa == NULL) + return REG_ESPACE; + preg->allocated = sizeof (re_dfa_t); + preg->buffer = dfa; + } + preg->used = sizeof (re_dfa_t); + + err = init_dfa (dfa, length); + if (BE (err != REG_NOERROR, 0)) + { + free_dfa_content (dfa); + preg->buffer = NULL; + preg->allocated = 0; + return err; + } +#ifdef DEBUG + /* Note: length+1 will not overflow since it is checked in init_dfa. */ + dfa->re_str = re_malloc (char, length + 1); + strncpy (dfa->re_str, pattern, length + 1); +#endif + + __libc_lock_init (dfa->lock); + + err = re_string_construct (®exp, pattern, length, preg->translate, + (syntax & RE_ICASE) != 0, dfa); + if (BE (err != REG_NOERROR, 0)) + { + re_compile_internal_free_return: + free_workarea_compile (preg); + re_string_destruct (®exp); + free_dfa_content (dfa); + preg->buffer = NULL; + preg->allocated = 0; + return err; + } + + /* Parse the regular expression, and build a structure tree. */ + preg->re_nsub = 0; + dfa->str_tree = parse (®exp, preg, syntax, &err); + if (BE (dfa->str_tree == NULL, 0)) + goto re_compile_internal_free_return; + + /* Analyze the tree and create the nfa. */ + err = analyze (preg); + if (BE (err != REG_NOERROR, 0)) + goto re_compile_internal_free_return; + +#ifdef RE_ENABLE_I18N + /* If possible, do searching in single byte encoding to speed things up. */ + if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL) + optimize_utf8 (dfa); +#endif + + /* Then create the initial state of the dfa. */ + err = create_initial_state (dfa); + + /* Release work areas. */ + free_workarea_compile (preg); + re_string_destruct (®exp); + + if (BE (err != REG_NOERROR, 0)) + { + free_dfa_content (dfa); + preg->buffer = NULL; + preg->allocated = 0; + } + + return err; +} + +/* Initialize DFA. We use the length of the regular expression PAT_LEN + as the initial length of some arrays. */ + +static reg_errcode_t +init_dfa (re_dfa_t *dfa, size_t pat_len) +{ + __re_size_t table_size; +#ifndef _LIBC + const char *codeset_name; +#endif +#ifdef RE_ENABLE_I18N + size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t)); +#else + size_t max_i18n_object_size = 0; +#endif + size_t max_object_size = + MAX (sizeof (struct re_state_table_entry), + MAX (sizeof (re_token_t), + MAX (sizeof (re_node_set), + MAX (sizeof (regmatch_t), + max_i18n_object_size)))); + + memset (dfa, '\0', sizeof (re_dfa_t)); + + /* Force allocation of str_tree_storage the first time. */ + dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; + + /* Avoid overflows. The extra "/ 2" is for the table_size doubling + calculation below, and for similar doubling calculations + elsewhere. And it's <= rather than <, because some of the + doubling calculations add 1 afterwards. */ + if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0)) + return REG_ESPACE; + + dfa->nodes_alloc = pat_len + 1; + dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc); + + /* table_size = 2 ^ ceil(log pat_len) */ + for (table_size = 1; ; table_size <<= 1) + if (table_size > pat_len) + break; + + dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size); + dfa->state_hash_mask = table_size - 1; + + dfa->mb_cur_max = MB_CUR_MAX; +#ifdef _LIBC + if (dfa->mb_cur_max == 6 + && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0) + dfa->is_utf8 = 1; + dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII) + != 0); +#else + codeset_name = nl_langinfo (CODESET); + if ((codeset_name[0] == 'U' || codeset_name[0] == 'u') + && (codeset_name[1] == 'T' || codeset_name[1] == 't') + && (codeset_name[2] == 'F' || codeset_name[2] == 'f') + && strcmp (codeset_name + 3 + (codeset_name[3] == '-'), "8") == 0) + dfa->is_utf8 = 1; + + /* We check exhaustively in the loop below if this charset is a + superset of ASCII. */ + dfa->map_notascii = 0; +#endif + +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + { + if (dfa->is_utf8) + dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map; + else + { + int i, j, ch; + + dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); + if (BE (dfa->sb_char == NULL, 0)) + return REG_ESPACE; + + /* Set the bits corresponding to single byte chars. */ + for (i = 0, ch = 0; i < BITSET_WORDS; ++i) + for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) + { + wint_t wch = __btowc (ch); + if (wch != WEOF) + dfa->sb_char[i] |= (bitset_word_t) 1 << j; +# ifndef _LIBC + if (isascii (ch) && wch != ch) + dfa->map_notascii = 1; +# endif + } + } + } +#endif + + if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0)) + return REG_ESPACE; + return REG_NOERROR; +} + +/* Initialize WORD_CHAR table, which indicate which character is + "word". In this case "word" means that it is the word construction + character used by some operators like "\<", "\>", etc. */ + +static void +internal_function +init_word_char (re_dfa_t *dfa) +{ + int i = 0; + int j; + int ch = 0; + dfa->word_ops_used = 1; + if (BE (dfa->map_notascii == 0, 1)) + { + bitset_word_t bits0 = 0x00000000; + bitset_word_t bits1 = 0x03ff0000; + bitset_word_t bits2 = 0x87fffffe; + bitset_word_t bits3 = 0x07fffffe; + if (BITSET_WORD_BITS == 64) + { + dfa->word_char[0] = bits1 << 31 << 1 | bits0; + dfa->word_char[1] = bits3 << 31 << 1 | bits2; + i = 2; + } + else if (BITSET_WORD_BITS == 32) + { + dfa->word_char[0] = bits0; + dfa->word_char[1] = bits1; + dfa->word_char[2] = bits2; + dfa->word_char[3] = bits3; + i = 4; + } + else + goto general_case; + ch = 128; + + if (BE (dfa->is_utf8, 1)) + { + memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8); + return; + } + } + + general_case: + for (; i < BITSET_WORDS; ++i) + for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch) + if (isalnum (ch) || ch == '_') + dfa->word_char[i] |= (bitset_word_t) 1 << j; +} + +/* Free the work area which are only used while compiling. */ + +static void +free_workarea_compile (regex_t *preg) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_storage_t *storage, *next; + for (storage = dfa->str_tree_storage; storage; storage = next) + { + next = storage->next; + re_free (storage); + } + dfa->str_tree_storage = NULL; + dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE; + dfa->str_tree = NULL; + re_free (dfa->org_indices); + dfa->org_indices = NULL; +} + +/* Create initial states for all contexts. */ + +static reg_errcode_t +create_initial_state (re_dfa_t *dfa) +{ + Idx first, i; + reg_errcode_t err; + re_node_set init_nodes; + + /* Initial states have the epsilon closure of the node which is + the first node of the regular expression. */ + first = dfa->str_tree->first->node_idx; + dfa->init_node = first; + err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first); + if (BE (err != REG_NOERROR, 0)) + return err; + + /* The back-references which are in initial states can epsilon transit, + since in this case all of the subexpressions can be null. + Then we add epsilon closures of the nodes which are the next nodes of + the back-references. */ + if (dfa->nbackref > 0) + for (i = 0; i < init_nodes.nelem; ++i) + { + Idx node_idx = init_nodes.elems[i]; + re_token_type_t type = dfa->nodes[node_idx].type; + + Idx clexp_idx; + if (type != OP_BACK_REF) + continue; + for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx) + { + re_token_t *clexp_node; + clexp_node = dfa->nodes + init_nodes.elems[clexp_idx]; + if (clexp_node->type == OP_CLOSE_SUBEXP + && clexp_node->opr.idx == dfa->nodes[node_idx].opr.idx) + break; + } + if (clexp_idx == init_nodes.nelem) + continue; + + if (type == OP_BACK_REF) + { + Idx dest_idx = dfa->edests[node_idx].elems[0]; + if (!re_node_set_contains (&init_nodes, dest_idx)) + { + reg_errcode_t merge_err + = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx); + if (merge_err != REG_NOERROR) + return merge_err; + i = 0; + } + } + } + + /* It must be the first time to invoke acquire_state. */ + dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0); + /* We don't check ERR here, since the initial state must not be NULL. */ + if (BE (dfa->init_state == NULL, 0)) + return err; + if (dfa->init_state->has_constraint) + { + dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes, + CONTEXT_WORD); + dfa->init_state_nl = re_acquire_state_context (&err, dfa, &init_nodes, + CONTEXT_NEWLINE); + dfa->init_state_begbuf = re_acquire_state_context (&err, dfa, + &init_nodes, + CONTEXT_NEWLINE + | CONTEXT_BEGBUF); + if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL + || dfa->init_state_begbuf == NULL, 0)) + return err; + } + else + dfa->init_state_word = dfa->init_state_nl + = dfa->init_state_begbuf = dfa->init_state; + + re_node_set_free (&init_nodes); + return REG_NOERROR; +} + +#ifdef RE_ENABLE_I18N +/* If it is possible to do searching in single byte encoding instead of UTF-8 + to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change + DFA nodes where needed. */ + +static void +optimize_utf8 (re_dfa_t *dfa) +{ + Idx node; + int i; + bool mb_chars = false; + bool has_period = false; + + for (node = 0; node < dfa->nodes_len; ++node) + switch (dfa->nodes[node].type) + { + case CHARACTER: + if (dfa->nodes[node].opr.c >= ASCII_CHARS) + mb_chars = true; + break; + case ANCHOR: + switch (dfa->nodes[node].opr.ctx_type) + { + case LINE_FIRST: + case LINE_LAST: + case BUF_FIRST: + case BUF_LAST: + break; + default: + /* Word anchors etc. cannot be handled. It's okay to test + opr.ctx_type since constraints (for all DFA nodes) are + created by ORing one or more opr.ctx_type values. */ + return; + } + break; + case OP_PERIOD: + has_period = true; + break; + case OP_BACK_REF: + case OP_ALT: + case END_OF_RE: + case OP_DUP_ASTERISK: + case OP_OPEN_SUBEXP: + case OP_CLOSE_SUBEXP: + break; + case COMPLEX_BRACKET: + return; + case SIMPLE_BRACKET: + /* Just double check. */ + { + int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0 + ? 0 + : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS); + for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i) + { + if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0) + return; + rshift = 0; + } + } + break; + default: + break; + } + + if (mb_chars || has_period) + for (node = 0; node < dfa->nodes_len; ++node) + { + if (dfa->nodes[node].type == CHARACTER + && dfa->nodes[node].opr.c >= ASCII_CHARS) + dfa->nodes[node].mb_partial = 0; + else if (dfa->nodes[node].type == OP_PERIOD) + dfa->nodes[node].type = OP_UTF8_PERIOD; + } + + /* The search can be in single byte locale. */ + dfa->mb_cur_max = 1; + dfa->is_utf8 = 0; + dfa->has_mb_node = dfa->nbackref > 0 || has_period; +} +#endif + +/* Analyze the structure tree, and calculate "first", "next", "edest", + "eclosure", and "inveclosure". */ + +static reg_errcode_t +analyze (regex_t *preg) +{ + re_dfa_t *dfa = preg->buffer; + reg_errcode_t ret; + + /* Allocate arrays. */ + dfa->nexts = re_malloc (Idx, dfa->nodes_alloc); + dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); + dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc); + dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); + if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL + || dfa->eclosures == NULL, 0)) + return REG_ESPACE; + + dfa->subexp_map = re_malloc (Idx, preg->re_nsub); + if (dfa->subexp_map != NULL) + { + Idx i; + for (i = 0; i < preg->re_nsub; i++) + dfa->subexp_map[i] = i; + preorder (dfa->str_tree, optimize_subexps, dfa); + for (i = 0; i < preg->re_nsub; i++) + if (dfa->subexp_map[i] != i) + break; + if (i == preg->re_nsub) + { + free (dfa->subexp_map); + dfa->subexp_map = NULL; + } + } + + ret = postorder (dfa->str_tree, lower_subexps, preg); + if (BE (ret != REG_NOERROR, 0)) + return ret; + ret = postorder (dfa->str_tree, calc_first, dfa); + if (BE (ret != REG_NOERROR, 0)) + return ret; + preorder (dfa->str_tree, calc_next, dfa); + ret = preorder (dfa->str_tree, link_nfa_nodes, dfa); + if (BE (ret != REG_NOERROR, 0)) + return ret; + ret = calc_eclosure (dfa); + if (BE (ret != REG_NOERROR, 0)) + return ret; + + /* We only need this during the prune_impossible_nodes pass in regexec.c; + skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */ + if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match) + || dfa->nbackref) + { + dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); + if (BE (dfa->inveclosures == NULL, 0)) + return REG_ESPACE; + ret = calc_inveclosure (dfa); + } + + return ret; +} + +/* Our parse trees are very unbalanced, so we cannot use a stack to + implement parse tree visits. Instead, we use parent pointers and + some hairy code in these two functions. */ +static reg_errcode_t +postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)), + void *extra) +{ + bin_tree_t *node, *prev; + + for (node = root; ; ) + { + /* Descend down the tree, preferably to the left (or to the right + if that's the only child). */ + while (node->left || node->right) + if (node->left) + node = node->left; + else + node = node->right; + + do + { + reg_errcode_t err = fn (extra, node); + if (BE (err != REG_NOERROR, 0)) + return err; + if (node->parent == NULL) + return REG_NOERROR; + prev = node; + node = node->parent; + } + /* Go up while we have a node that is reached from the right. */ + while (node->right == prev || node->right == NULL); + node = node->right; + } +} + +static reg_errcode_t +preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)), + void *extra) +{ + bin_tree_t *node; + + for (node = root; ; ) + { + reg_errcode_t err = fn (extra, node); + if (BE (err != REG_NOERROR, 0)) + return err; + + /* Go to the left node, or up and to the right. */ + if (node->left) + node = node->left; + else + { + bin_tree_t *prev = NULL; + while (node->right == prev || node->right == NULL) + { + prev = node; + node = node->parent; + if (!node) + return REG_NOERROR; + } + node = node->right; + } + } +} + +/* Optimization pass: if a SUBEXP is entirely contained, strip it and tell + re_search_internal to map the inner one's opr.idx to this one's. Adjust + backreferences as well. Requires a preorder visit. */ +static reg_errcode_t +optimize_subexps (void *extra, bin_tree_t *node) +{ + re_dfa_t *dfa = (re_dfa_t *) extra; + + if (node->token.type == OP_BACK_REF && dfa->subexp_map) + { + int idx = node->token.opr.idx; + node->token.opr.idx = dfa->subexp_map[idx]; + dfa->used_bkref_map |= 1 << node->token.opr.idx; + } + + else if (node->token.type == SUBEXP + && node->left && node->left->token.type == SUBEXP) + { + Idx other_idx = node->left->token.opr.idx; + + node->left = node->left->left; + if (node->left) + node->left->parent = node; + + dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx]; + if (other_idx < BITSET_WORD_BITS) + dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx); + } + + return REG_NOERROR; +} + +/* Lowering pass: Turn each SUBEXP node into the appropriate concatenation + of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */ +static reg_errcode_t +lower_subexps (void *extra, bin_tree_t *node) +{ + regex_t *preg = (regex_t *) extra; + reg_errcode_t err = REG_NOERROR; + + if (node->left && node->left->token.type == SUBEXP) + { + node->left = lower_subexp (&err, preg, node->left); + if (node->left) + node->left->parent = node; + } + if (node->right && node->right->token.type == SUBEXP) + { + node->right = lower_subexp (&err, preg, node->right); + if (node->right) + node->right->parent = node; + } + + return err; +} + +static bin_tree_t * +lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_t *body = node->left; + bin_tree_t *op, *cls, *tree1, *tree; + + if (preg->no_sub + /* We do not optimize empty subexpressions, because otherwise we may + have bad CONCAT nodes with NULL children. This is obviously not + very common, so we do not lose much. An example that triggers + this case is the sed "script" /\(\)/x. */ + && node->left != NULL + && (node->token.opr.idx >= BITSET_WORD_BITS + || !(dfa->used_bkref_map + & ((bitset_word_t) 1 << node->token.opr.idx)))) + return node->left; + + /* Convert the SUBEXP node to the concatenation of an + OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */ + op = create_tree (dfa, NULL, NULL, OP_OPEN_SUBEXP); + cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP); + tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls; + tree = create_tree (dfa, op, tree1, CONCAT); + if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + + op->token.opr.idx = cls->token.opr.idx = node->token.opr.idx; + op->token.opt_subexp = cls->token.opt_subexp = node->token.opt_subexp; + return tree; +} + +/* Pass 1 in building the NFA: compute FIRST and create unlinked automaton + nodes. Requires a postorder visit. */ +static reg_errcode_t +calc_first (void *extra, bin_tree_t *node) +{ + re_dfa_t *dfa = (re_dfa_t *) extra; + if (node->token.type == CONCAT) + { + node->first = node->left->first; + node->node_idx = node->left->node_idx; + } + else + { + node->first = node; + node->node_idx = re_dfa_add_node (dfa, node->token); + if (BE (node->node_idx == REG_MISSING, 0)) + return REG_ESPACE; + if (node->token.type == ANCHOR) + dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type; + } + return REG_NOERROR; +} + +/* Pass 2: compute NEXT on the tree. Preorder visit. */ +static reg_errcode_t +calc_next (void *extra, bin_tree_t *node) +{ + switch (node->token.type) + { + case OP_DUP_ASTERISK: + node->left->next = node; + break; + case CONCAT: + node->left->next = node->right->first; + node->right->next = node->next; + break; + default: + if (node->left) + node->left->next = node->next; + if (node->right) + node->right->next = node->next; + break; + } + return REG_NOERROR; +} + +/* Pass 3: link all DFA nodes to their NEXT node (any order will do). */ +static reg_errcode_t +link_nfa_nodes (void *extra, bin_tree_t *node) +{ + re_dfa_t *dfa = (re_dfa_t *) extra; + Idx idx = node->node_idx; + reg_errcode_t err = REG_NOERROR; + + switch (node->token.type) + { + case CONCAT: + break; + + case END_OF_RE: + assert (node->next == NULL); + break; + + case OP_DUP_ASTERISK: + case OP_ALT: + { + Idx left, right; + dfa->has_plural_match = 1; + if (node->left != NULL) + left = node->left->first->node_idx; + else + left = node->next->node_idx; + if (node->right != NULL) + right = node->right->first->node_idx; + else + right = node->next->node_idx; + assert (REG_VALID_INDEX (left)); + assert (REG_VALID_INDEX (right)); + err = re_node_set_init_2 (dfa->edests + idx, left, right); + } + break; + + case ANCHOR: + case OP_OPEN_SUBEXP: + case OP_CLOSE_SUBEXP: + err = re_node_set_init_1 (dfa->edests + idx, node->next->node_idx); + break; + + case OP_BACK_REF: + dfa->nexts[idx] = node->next->node_idx; + if (node->token.type == OP_BACK_REF) + err = re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]); + break; + + default: + assert (!IS_EPSILON_NODE (node->token.type)); + dfa->nexts[idx] = node->next->node_idx; + break; + } + + return err; +} + +/* Duplicate the epsilon closure of the node ROOT_NODE. + Note that duplicated nodes have constraint INIT_CONSTRAINT in addition + to their own constraint. */ + +static reg_errcode_t +internal_function +duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node, + Idx root_node, unsigned int init_constraint) +{ + Idx org_node, clone_node; + bool ok; + unsigned int constraint = init_constraint; + for (org_node = top_org_node, clone_node = top_clone_node;;) + { + Idx org_dest, clone_dest; + if (dfa->nodes[org_node].type == OP_BACK_REF) + { + /* If the back reference epsilon-transit, its destination must + also have the constraint. Then duplicate the epsilon closure + of the destination of the back reference, and store it in + edests of the back reference. */ + org_dest = dfa->nexts[org_node]; + re_node_set_empty (dfa->edests + clone_node); + clone_dest = duplicate_node (dfa, org_dest, constraint); + if (BE (clone_dest == REG_MISSING, 0)) + return REG_ESPACE; + dfa->nexts[clone_node] = dfa->nexts[org_node]; + ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + } + else if (dfa->edests[org_node].nelem == 0) + { + /* In case of the node can't epsilon-transit, don't duplicate the + destination and store the original destination as the + destination of the node. */ + dfa->nexts[clone_node] = dfa->nexts[org_node]; + break; + } + else if (dfa->edests[org_node].nelem == 1) + { + /* In case of the node can epsilon-transit, and it has only one + destination. */ + org_dest = dfa->edests[org_node].elems[0]; + re_node_set_empty (dfa->edests + clone_node); + /* If the node is root_node itself, it means the epsilon closure + has a loop. Then tie it to the destination of the root_node. */ + if (org_node == root_node && clone_node != org_node) + { + ok = re_node_set_insert (dfa->edests + clone_node, org_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + break; + } + /* In case the node has another constraint, append it. */ + constraint |= dfa->nodes[org_node].constraint; + clone_dest = duplicate_node (dfa, org_dest, constraint); + if (BE (clone_dest == REG_MISSING, 0)) + return REG_ESPACE; + ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + } + else /* dfa->edests[org_node].nelem == 2 */ + { + /* In case of the node can epsilon-transit, and it has two + destinations. In the bin_tree_t and DFA, that's '|' and '*'. */ + org_dest = dfa->edests[org_node].elems[0]; + re_node_set_empty (dfa->edests + clone_node); + /* Search for a duplicated node which satisfies the constraint. */ + clone_dest = search_duplicated_node (dfa, org_dest, constraint); + if (clone_dest == REG_MISSING) + { + /* There is no such duplicated node, create a new one. */ + reg_errcode_t err; + clone_dest = duplicate_node (dfa, org_dest, constraint); + if (BE (clone_dest == REG_MISSING, 0)) + return REG_ESPACE; + ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + err = duplicate_node_closure (dfa, org_dest, clone_dest, + root_node, constraint); + if (BE (err != REG_NOERROR, 0)) + return err; + } + else + { + /* There is a duplicated node which satisfies the constraint, + use it to avoid infinite loop. */ + ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + } + + org_dest = dfa->edests[org_node].elems[1]; + clone_dest = duplicate_node (dfa, org_dest, constraint); + if (BE (clone_dest == REG_MISSING, 0)) + return REG_ESPACE; + ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); + if (BE (! ok, 0)) + return REG_ESPACE; + } + org_node = org_dest; + clone_node = clone_dest; + } + return REG_NOERROR; +} + +/* Search for a node which is duplicated from the node ORG_NODE, and + satisfies the constraint CONSTRAINT. */ + +static Idx +search_duplicated_node (const re_dfa_t *dfa, Idx org_node, + unsigned int constraint) +{ + Idx idx; + for (idx = dfa->nodes_len - 1; dfa->nodes[idx].duplicated && idx > 0; --idx) + { + if (org_node == dfa->org_indices[idx] + && constraint == dfa->nodes[idx].constraint) + return idx; /* Found. */ + } + return REG_MISSING; /* Not found. */ +} + +/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT. + Return the index of the new node, or REG_MISSING if insufficient storage is + available. */ + +static Idx +duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint) +{ + Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]); + if (BE (dup_idx != REG_MISSING, 1)) + { + dfa->nodes[dup_idx].constraint = constraint; + dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint; + dfa->nodes[dup_idx].duplicated = 1; + + /* Store the index of the original node. */ + dfa->org_indices[dup_idx] = org_idx; + } + return dup_idx; +} + +static reg_errcode_t +calc_inveclosure (re_dfa_t *dfa) +{ + Idx src, idx; + bool ok; + for (idx = 0; idx < dfa->nodes_len; ++idx) + re_node_set_init_empty (dfa->inveclosures + idx); + + for (src = 0; src < dfa->nodes_len; ++src) + { + Idx *elems = dfa->eclosures[src].elems; + for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx) + { + ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src); + if (BE (! ok, 0)) + return REG_ESPACE; + } + } + + return REG_NOERROR; +} + +/* Calculate "eclosure" for all the node in DFA. */ + +static reg_errcode_t +calc_eclosure (re_dfa_t *dfa) +{ + Idx node_idx; + bool incomplete; +#ifdef DEBUG + assert (dfa->nodes_len > 0); +#endif + incomplete = false; + /* For each nodes, calculate epsilon closure. */ + for (node_idx = 0; ; ++node_idx) + { + reg_errcode_t err; + re_node_set eclosure_elem; + if (node_idx == dfa->nodes_len) + { + if (!incomplete) + break; + incomplete = false; + node_idx = 0; + } + +#ifdef DEBUG + assert (dfa->eclosures[node_idx].nelem != REG_MISSING); +#endif + + /* If we have already calculated, skip it. */ + if (dfa->eclosures[node_idx].nelem != 0) + continue; + /* Calculate epsilon closure of 'node_idx'. */ + err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true); + if (BE (err != REG_NOERROR, 0)) + return err; + + if (dfa->eclosures[node_idx].nelem == 0) + { + incomplete = true; + re_node_set_free (&eclosure_elem); + } + } + return REG_NOERROR; +} + +/* Calculate epsilon closure of NODE. */ + +static reg_errcode_t +calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) +{ + reg_errcode_t err; + Idx i; + re_node_set eclosure; + bool ok; + bool incomplete = false; + err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1); + if (BE (err != REG_NOERROR, 0)) + return err; + + /* This indicates that we are calculating this node now. + We reference this value to avoid infinite loop. */ + dfa->eclosures[node].nelem = REG_MISSING; + + /* If the current node has constraints, duplicate all nodes + since they must inherit the constraints. */ + if (dfa->nodes[node].constraint + && dfa->edests[node].nelem + && !dfa->nodes[dfa->edests[node].elems[0]].duplicated) + { + err = duplicate_node_closure (dfa, node, node, node, + dfa->nodes[node].constraint); + if (BE (err != REG_NOERROR, 0)) + return err; + } + + /* Expand each epsilon destination nodes. */ + if (IS_EPSILON_NODE(dfa->nodes[node].type)) + for (i = 0; i < dfa->edests[node].nelem; ++i) + { + re_node_set eclosure_elem; + Idx edest = dfa->edests[node].elems[i]; + /* If calculating the epsilon closure of 'edest' is in progress, + return intermediate result. */ + if (dfa->eclosures[edest].nelem == REG_MISSING) + { + incomplete = true; + continue; + } + /* If we haven't calculated the epsilon closure of 'edest' yet, + calculate now. Otherwise use calculated epsilon closure. */ + if (dfa->eclosures[edest].nelem == 0) + { + err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false); + if (BE (err != REG_NOERROR, 0)) + return err; + } + else + eclosure_elem = dfa->eclosures[edest]; + /* Merge the epsilon closure of 'edest'. */ + err = re_node_set_merge (&eclosure, &eclosure_elem); + if (BE (err != REG_NOERROR, 0)) + return err; + /* If the epsilon closure of 'edest' is incomplete, + the epsilon closure of this node is also incomplete. */ + if (dfa->eclosures[edest].nelem == 0) + { + incomplete = true; + re_node_set_free (&eclosure_elem); + } + } + + /* An epsilon closure includes itself. */ + ok = re_node_set_insert (&eclosure, node); + if (BE (! ok, 0)) + return REG_ESPACE; + if (incomplete && !root) + dfa->eclosures[node].nelem = 0; + else + dfa->eclosures[node] = eclosure; + *new_set = eclosure; + return REG_NOERROR; +} + +/* Functions for token which are used in the parser. */ + +/* Fetch a token from INPUT. + We must not use this function inside bracket expressions. */ + +static void +internal_function +fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) +{ + re_string_skip_bytes (input, peek_token (result, input, syntax)); +} + +/* Peek a token from INPUT, and return the length of the token. + We must not use this function inside bracket expressions. */ + +static int +internal_function +peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) +{ + unsigned char c; + + if (re_string_eoi (input)) + { + token->type = END_OF_RE; + return 0; + } + + c = re_string_peek_byte (input, 0); + token->opr.c = c; + + token->word_char = 0; +#ifdef RE_ENABLE_I18N + token->mb_partial = 0; + if (input->mb_cur_max > 1 && + !re_string_first_byte (input, re_string_cur_idx (input))) + { + token->type = CHARACTER; + token->mb_partial = 1; + return 1; + } +#endif + if (c == '\\') + { + unsigned char c2; + if (re_string_cur_idx (input) + 1 >= re_string_length (input)) + { + token->type = BACK_SLASH; + return 1; + } + + c2 = re_string_peek_byte_case (input, 1); + token->opr.c = c2; + token->type = CHARACTER; +#ifdef RE_ENABLE_I18N + if (input->mb_cur_max > 1) + { + wint_t wc = re_string_wchar_at (input, + re_string_cur_idx (input) + 1); + token->word_char = IS_WIDE_WORD_CHAR (wc) != 0; + } + else +#endif + token->word_char = IS_WORD_CHAR (c2) != 0; + + switch (c2) + { + case '|': + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR)) + token->type = OP_ALT; + break; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + if (!(syntax & RE_NO_BK_REFS)) + { + token->type = OP_BACK_REF; + token->opr.idx = c2 - '1'; + } + break; + case '<': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = WORD_FIRST; + } + break; + case '>': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = WORD_LAST; + } + break; + case 'b': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = WORD_DELIM; + } + break; + case 'B': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = NOT_WORD_DELIM; + } + break; + case 'w': + if (!(syntax & RE_NO_GNU_OPS)) + token->type = OP_WORD; + break; + case 'W': + if (!(syntax & RE_NO_GNU_OPS)) + token->type = OP_NOTWORD; + break; + case 's': + if (!(syntax & RE_NO_GNU_OPS)) + token->type = OP_SPACE; + break; + case 'S': + if (!(syntax & RE_NO_GNU_OPS)) + token->type = OP_NOTSPACE; + break; + case '`': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = BUF_FIRST; + } + break; + case '\'': + if (!(syntax & RE_NO_GNU_OPS)) + { + token->type = ANCHOR; + token->opr.ctx_type = BUF_LAST; + } + break; + case '(': + if (!(syntax & RE_NO_BK_PARENS)) + token->type = OP_OPEN_SUBEXP; + break; + case ')': + if (!(syntax & RE_NO_BK_PARENS)) + token->type = OP_CLOSE_SUBEXP; + break; + case '+': + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) + token->type = OP_DUP_PLUS; + break; + case '?': + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM)) + token->type = OP_DUP_QUESTION; + break; + case '{': + if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) + token->type = OP_OPEN_DUP_NUM; + break; + case '}': + if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES))) + token->type = OP_CLOSE_DUP_NUM; + break; + default: + break; + } + return 2; + } + + token->type = CHARACTER; +#ifdef RE_ENABLE_I18N + if (input->mb_cur_max > 1) + { + wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input)); + token->word_char = IS_WIDE_WORD_CHAR (wc) != 0; + } + else +#endif + token->word_char = IS_WORD_CHAR (token->opr.c); + + switch (c) + { + case '\n': + if (syntax & RE_NEWLINE_ALT) + token->type = OP_ALT; + break; + case '|': + if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR)) + token->type = OP_ALT; + break; + case '*': + token->type = OP_DUP_ASTERISK; + break; + case '+': + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) + token->type = OP_DUP_PLUS; + break; + case '?': + if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM)) + token->type = OP_DUP_QUESTION; + break; + case '{': + if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) + token->type = OP_OPEN_DUP_NUM; + break; + case '}': + if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) + token->type = OP_CLOSE_DUP_NUM; + break; + case '(': + if (syntax & RE_NO_BK_PARENS) + token->type = OP_OPEN_SUBEXP; + break; + case ')': + if (syntax & RE_NO_BK_PARENS) + token->type = OP_CLOSE_SUBEXP; + break; + case '[': + token->type = OP_OPEN_BRACKET; + break; + case '.': + token->type = OP_PERIOD; + break; + case '^': + if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && + re_string_cur_idx (input) != 0) + { + char prev = re_string_peek_byte (input, -1); + if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') + break; + } + token->type = ANCHOR; + token->opr.ctx_type = LINE_FIRST; + break; + case '$': + if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && + re_string_cur_idx (input) + 1 != re_string_length (input)) + { + re_token_t next; + re_string_skip_bytes (input, 1); + peek_token (&next, input, syntax); + re_string_skip_bytes (input, -1); + if (next.type != OP_ALT && next.type != OP_CLOSE_SUBEXP) + break; + } + token->type = ANCHOR; + token->opr.ctx_type = LINE_LAST; + break; + default: + break; + } + return 1; +} + +/* Peek a token from INPUT, and return the length of the token. + We must not use this function out of bracket expressions. */ + +static int +internal_function +peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) +{ + unsigned char c; + if (re_string_eoi (input)) + { + token->type = END_OF_RE; + return 0; + } + c = re_string_peek_byte (input, 0); + token->opr.c = c; + +#ifdef RE_ENABLE_I18N + if (input->mb_cur_max > 1 && + !re_string_first_byte (input, re_string_cur_idx (input))) + { + token->type = CHARACTER; + return 1; + } +#endif /* RE_ENABLE_I18N */ + + if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) + && re_string_cur_idx (input) + 1 < re_string_length (input)) + { + /* In this case, '\' escape a character. */ + unsigned char c2; + re_string_skip_bytes (input, 1); + c2 = re_string_peek_byte (input, 0); + token->opr.c = c2; + token->type = CHARACTER; + return 1; + } + if (c == '[') /* '[' is a special char in a bracket exps. */ + { + unsigned char c2; + int token_len; + if (re_string_cur_idx (input) + 1 < re_string_length (input)) + c2 = re_string_peek_byte (input, 1); + else + c2 = 0; + token->opr.c = c2; + token_len = 2; + switch (c2) + { + case '.': + token->type = OP_OPEN_COLL_ELEM; + break; + case '=': + token->type = OP_OPEN_EQUIV_CLASS; + break; + case ':': + if (syntax & RE_CHAR_CLASSES) + { + token->type = OP_OPEN_CHAR_CLASS; + break; + } + /* else fall through. */ + default: + token->type = CHARACTER; + token->opr.c = c; + token_len = 1; + break; + } + return token_len; + } + switch (c) + { + case '-': + token->type = OP_CHARSET_RANGE; + break; + case ']': + token->type = OP_CLOSE_BRACKET; + break; + case '^': + token->type = OP_NON_MATCH_LIST; + break; + default: + token->type = CHARACTER; + } + return 1; +} + +/* Functions for parser. */ + +/* Entry point of the parser. + Parse the regular expression REGEXP and return the structure tree. + If an error occurs, ERR is set by error code, and return NULL. + This function build the following tree, from regular expression : + CAT + / \ + / \ + EOR + + CAT means concatenation. + EOR means end of regular expression. */ + +static bin_tree_t * +parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax, + reg_errcode_t *err) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_t *tree, *eor, *root; + re_token_t current_token; + dfa->syntax = syntax; + fetch_token (¤t_token, regexp, syntax | RE_CARET_ANCHORS_HERE); + tree = parse_reg_exp (regexp, preg, ¤t_token, syntax, 0, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + eor = create_tree (dfa, NULL, NULL, END_OF_RE); + if (tree != NULL) + root = create_tree (dfa, tree, eor, CONCAT); + else + root = eor; + if (BE (eor == NULL || root == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + return root; +} + +/* This function build the following tree, from regular expression + |: + ALT + / \ + / \ + + + ALT means alternative, which represents the operator '|'. */ + +static bin_tree_t * +parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, + reg_syntax_t syntax, Idx nest, reg_errcode_t *err) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_t *tree, *branch = NULL; + tree = parse_branch (regexp, preg, token, syntax, nest, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + + while (token->type == OP_ALT) + { + fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); + if (token->type != OP_ALT && token->type != END_OF_RE + && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) + { + branch = parse_branch (regexp, preg, token, syntax, nest, err); + if (BE (*err != REG_NOERROR && branch == NULL, 0)) + return NULL; + } + else + branch = NULL; + tree = create_tree (dfa, tree, branch, OP_ALT); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + } + return tree; +} + +/* This function build the following tree, from regular expression + : + CAT + / \ + / \ + + + CAT means concatenation. */ + +static bin_tree_t * +parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token, + reg_syntax_t syntax, Idx nest, reg_errcode_t *err) +{ + bin_tree_t *tree, *expr; + re_dfa_t *dfa = preg->buffer; + tree = parse_expression (regexp, preg, token, syntax, nest, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + + while (token->type != OP_ALT && token->type != END_OF_RE + && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) + { + expr = parse_expression (regexp, preg, token, syntax, nest, err); + if (BE (*err != REG_NOERROR && expr == NULL, 0)) + { + if (tree != NULL) + postorder (tree, free_tree, NULL); + return NULL; + } + if (tree != NULL && expr != NULL) + { + bin_tree_t *newtree = create_tree (dfa, tree, expr, CONCAT); + if (newtree == NULL) + { + postorder (expr, free_tree, NULL); + postorder (tree, free_tree, NULL); + *err = REG_ESPACE; + return NULL; + } + tree = newtree; + } + else if (tree == NULL) + tree = expr; + /* Otherwise expr == NULL, we don't need to create new tree. */ + } + return tree; +} + +/* This function build the following tree, from regular expression a*: + * + | + a +*/ + +static bin_tree_t * +parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, + reg_syntax_t syntax, Idx nest, reg_errcode_t *err) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_t *tree; + switch (token->type) + { + case CHARACTER: + tree = create_token_tree (dfa, NULL, NULL, token); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + { + while (!re_string_eoi (regexp) + && !re_string_first_byte (regexp, re_string_cur_idx (regexp))) + { + bin_tree_t *mbc_remain; + fetch_token (token, regexp, syntax); + mbc_remain = create_token_tree (dfa, NULL, NULL, token); + tree = create_tree (dfa, tree, mbc_remain, CONCAT); + if (BE (mbc_remain == NULL || tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + } + } +#endif + break; + case OP_OPEN_SUBEXP: + tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + break; + case OP_OPEN_BRACKET: + tree = parse_bracket_exp (regexp, dfa, token, syntax, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + break; + case OP_BACK_REF: + if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1)) + { + *err = REG_ESUBREG; + return NULL; + } + dfa->used_bkref_map |= 1 << token->opr.idx; + tree = create_token_tree (dfa, NULL, NULL, token); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + ++dfa->nbackref; + dfa->has_mb_node = 1; + break; + case OP_OPEN_DUP_NUM: + if (syntax & RE_CONTEXT_INVALID_DUP) + { + *err = REG_BADRPT; + return NULL; + } + /* FALLTHROUGH */ + case OP_DUP_ASTERISK: + case OP_DUP_PLUS: + case OP_DUP_QUESTION: + if (syntax & RE_CONTEXT_INVALID_OPS) + { + *err = REG_BADRPT; + return NULL; + } + else if (syntax & RE_CONTEXT_INDEP_OPS) + { + fetch_token (token, regexp, syntax); + return parse_expression (regexp, preg, token, syntax, nest, err); + } + /* else fall through */ + case OP_CLOSE_SUBEXP: + if ((token->type == OP_CLOSE_SUBEXP) && + !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) + { + *err = REG_ERPAREN; + return NULL; + } + /* else fall through */ + case OP_CLOSE_DUP_NUM: + /* We treat it as a normal character. */ + + /* Then we can these characters as normal characters. */ + token->type = CHARACTER; + /* mb_partial and word_char bits should be initialized already + by peek_token. */ + tree = create_token_tree (dfa, NULL, NULL, token); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + break; + case ANCHOR: + if ((token->opr.ctx_type + & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST)) + && dfa->word_ops_used == 0) + init_word_char (dfa); + if (token->opr.ctx_type == WORD_DELIM + || token->opr.ctx_type == NOT_WORD_DELIM) + { + bin_tree_t *tree_first, *tree_last; + if (token->opr.ctx_type == WORD_DELIM) + { + token->opr.ctx_type = WORD_FIRST; + tree_first = create_token_tree (dfa, NULL, NULL, token); + token->opr.ctx_type = WORD_LAST; + } + else + { + token->opr.ctx_type = INSIDE_WORD; + tree_first = create_token_tree (dfa, NULL, NULL, token); + token->opr.ctx_type = INSIDE_NOTWORD; + } + tree_last = create_token_tree (dfa, NULL, NULL, token); + tree = create_tree (dfa, tree_first, tree_last, OP_ALT); + if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + } + else + { + tree = create_token_tree (dfa, NULL, NULL, token); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + } + /* We must return here, since ANCHORs can't be followed + by repetition operators. + eg. RE"^*" is invalid or "", + it must not be "". */ + fetch_token (token, regexp, syntax); + return tree; + case OP_PERIOD: + tree = create_token_tree (dfa, NULL, NULL, token); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + if (dfa->mb_cur_max > 1) + dfa->has_mb_node = 1; + break; + case OP_WORD: + case OP_NOTWORD: + tree = build_charclass_op (dfa, regexp->trans, + "alnum", + "_", + token->type == OP_NOTWORD, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + break; + case OP_SPACE: + case OP_NOTSPACE: + tree = build_charclass_op (dfa, regexp->trans, + "space", + "", + token->type == OP_NOTSPACE, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + break; + case OP_ALT: + case END_OF_RE: + return NULL; + case BACK_SLASH: + *err = REG_EESCAPE; + return NULL; + default: + /* Must not happen? */ +#ifdef DEBUG + assert (0); +#endif + return NULL; + } + fetch_token (token, regexp, syntax); + + while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS + || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM) + { + tree = parse_dup_op (tree, regexp, dfa, token, syntax, err); + if (BE (*err != REG_NOERROR && tree == NULL, 0)) + return NULL; + /* In BRE consecutive duplications are not allowed. */ + if ((syntax & RE_CONTEXT_INVALID_DUP) + && (token->type == OP_DUP_ASTERISK + || token->type == OP_OPEN_DUP_NUM)) + { + *err = REG_BADRPT; + return NULL; + } + } + + return tree; +} + +/* This function build the following tree, from regular expression + (): + SUBEXP + | + +*/ + +static bin_tree_t * +parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, + reg_syntax_t syntax, Idx nest, reg_errcode_t *err) +{ + re_dfa_t *dfa = preg->buffer; + bin_tree_t *tree; + size_t cur_nsub; + cur_nsub = preg->re_nsub++; + + fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE); + + /* The subexpression may be a null string. */ + if (token->type == OP_CLOSE_SUBEXP) + tree = NULL; + else + { + tree = parse_reg_exp (regexp, preg, token, syntax, nest, err); + if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0)) + { + if (tree != NULL) + postorder (tree, free_tree, NULL); + *err = REG_EPAREN; + } + if (BE (*err != REG_NOERROR, 0)) + return NULL; + } + + if (cur_nsub <= '9' - '1') + dfa->completed_bkref_map |= 1 << cur_nsub; + + tree = create_tree (dfa, tree, NULL, SUBEXP); + if (BE (tree == NULL, 0)) + { + *err = REG_ESPACE; + return NULL; + } + tree->token.opr.idx = cur_nsub; + return tree; +} + +/* This function parse repetition operators like "*", "+", "{1,3}" etc. */ + +static bin_tree_t * +parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, + re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err) +{ + bin_tree_t *tree = NULL, *old_tree = NULL; + Idx i, start, end, start_idx = re_string_cur_idx (regexp); + re_token_t start_token = *token; + + if (token->type == OP_OPEN_DUP_NUM) + { + end = 0; + start = fetch_number (regexp, token, syntax); + if (start == REG_MISSING) + { + if (token->type == CHARACTER && token->opr.c == ',') + start = 0; /* We treat "{,m}" as "{0,m}". */ + else + { + *err = REG_BADBR; /* {} is invalid. */ + return NULL; + } + } + if (BE (start != REG_ERROR, 1)) + { + /* We treat "{n}" as "{n,n}". */ + end = ((token->type == OP_CLOSE_DUP_NUM) ? start + : ((token->type == CHARACTER && token->opr.c == ',') + ? fetch_number (regexp, token, syntax) : REG_ERROR)); + } + if (BE (start == REG_ERROR || end == REG_ERROR, 0)) + { + /* Invalid sequence. */ + if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0)) + { + if (token->type == END_OF_RE) + *err = REG_EBRACE; + else + *err = REG_BADBR; + + return NULL; + } + + /* If the syntax bit is set, rollback. */ + re_string_set_index (regexp, start_idx); + *token = start_token; + token->type = CHARACTER; + /* mb_partial and word_char bits should be already initialized by + peek_token. */ + return elem; + } + + if (BE ((end != REG_MISSING && start > end) + || token->type != OP_CLOSE_DUP_NUM, 0)) + { + /* First number greater than second. */ + *err = REG_BADBR; + return NULL; + } + + if (BE (RE_DUP_MAX < (end == REG_MISSING ? start : end), 0)) + { + *err = REG_ESIZE; + return NULL; + } + } + else + { + start = (token->type == OP_DUP_PLUS) ? 1 : 0; + end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING; + } + + fetch_token (token, regexp, syntax); + + if (BE (elem == NULL, 0)) + return NULL; + if (BE (start == 0 && end == 0, 0)) + { + postorder (elem, free_tree, NULL); + return NULL; + } + + /* Extract "{n,m}" to "...{0,}". */ + if (BE (start > 0, 0)) + { + tree = elem; + for (i = 2; i <= start; ++i) + { + elem = duplicate_tree (elem, dfa); + tree = create_tree (dfa, tree, elem, CONCAT); + if (BE (elem == NULL || tree == NULL, 0)) + goto parse_dup_op_espace; + } + + if (start == end) + return tree; + + /* Duplicate ELEM before it is marked optional. */ + elem = duplicate_tree (elem, dfa); + old_tree = tree; + } + else + old_tree = NULL; + + if (elem->token.type == SUBEXP) + { + uintptr_t subidx = elem->token.opr.idx; + postorder (elem, mark_opt_subexp, (void *) subidx); + } + + tree = create_tree (dfa, elem, NULL, + (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT)); + if (BE (tree == NULL, 0)) + goto parse_dup_op_espace; + +/* From gnulib's "intprops.h": + True if the arithmetic type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + + /* This loop is actually executed only when end != REG_MISSING, + to rewrite {0,n} as ((...?)?)?... We have + already created the start+1-th copy. */ + if (TYPE_SIGNED (Idx) || end != REG_MISSING) + for (i = start + 2; i <= end; ++i) + { + elem = duplicate_tree (elem, dfa); + tree = create_tree (dfa, tree, elem, CONCAT); + if (BE (elem == NULL || tree == NULL, 0)) + goto parse_dup_op_espace; + + tree = create_tree (dfa, tree, NULL, OP_ALT); + if (BE (tree == NULL, 0)) + goto parse_dup_op_espace; + } + + if (old_tree) + tree = create_tree (dfa, old_tree, tree, CONCAT); + + return tree; + + parse_dup_op_espace: + *err = REG_ESPACE; + return NULL; +} + +/* Size of the names for collating symbol/equivalence_class/character_class. + I'm not sure, but maybe enough. */ +#define BRACKET_NAME_BUF_SIZE 32 + +#ifndef _LIBC + /* Local function for parse_bracket_exp only used in case of NOT _LIBC. + Build the range expression which starts from START_ELEM, and ends + at END_ELEM. The result are written to MBCSET and SBCSET. + RANGE_ALLOC is the allocated size of mbcset->range_starts, and + mbcset->range_ends, is a pointer argument since we may + update it. */ + +static reg_errcode_t +internal_function +# ifdef RE_ENABLE_I18N +build_range_exp (const reg_syntax_t syntax, + bitset_t sbcset, + re_charset_t *mbcset, + Idx *range_alloc, + const bracket_elem_t *start_elem, + const bracket_elem_t *end_elem) +# else /* not RE_ENABLE_I18N */ +build_range_exp (const reg_syntax_t syntax, + bitset_t sbcset, + const bracket_elem_t *start_elem, + const bracket_elem_t *end_elem) +# endif /* not RE_ENABLE_I18N */ +{ + unsigned int start_ch, end_ch; + /* Equivalence Classes and Character Classes can't be a range start/end. */ + if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS + || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, + 0)) + return REG_ERANGE; + + /* We can handle no multi character collating elements without libc + support. */ + if (BE ((start_elem->type == COLL_SYM + && strlen ((char *) start_elem->opr.name) > 1) + || (end_elem->type == COLL_SYM + && strlen ((char *) end_elem->opr.name) > 1), 0)) + return REG_ECOLLATE; + +# ifdef RE_ENABLE_I18N + { + wchar_t wc; + wint_t start_wc; + wint_t end_wc; + + start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch + : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] + : 0)); + end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch + : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0] + : 0)); + start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM) + ? __btowc (start_ch) : start_elem->opr.wch); + end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM) + ? __btowc (end_ch) : end_elem->opr.wch); + if (start_wc == WEOF || end_wc == WEOF) + return REG_ECOLLATE; + else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0)) + return REG_ERANGE; + + /* Got valid collation sequence values, add them as a new entry. + However, for !_LIBC we have no collation elements: if the + character set is single byte, the single byte character set + that we build below suffices. parse_bracket_exp passes + no MBCSET if dfa->mb_cur_max == 1. */ + if (mbcset) + { + /* Check the space of the arrays. */ + if (BE (*range_alloc == mbcset->nranges, 0)) + { + /* There is not enough space, need realloc. */ + wchar_t *new_array_start, *new_array_end; + Idx new_nranges; + + /* +1 in case of mbcset->nranges is 0. */ + new_nranges = 2 * mbcset->nranges + 1; + /* Use realloc since mbcset->range_starts and mbcset->range_ends + are NULL if *range_alloc == 0. */ + new_array_start = re_realloc (mbcset->range_starts, wchar_t, + new_nranges); + new_array_end = re_realloc (mbcset->range_ends, wchar_t, + new_nranges); + + if (BE (new_array_start == NULL || new_array_end == NULL, 0)) + return REG_ESPACE; + + mbcset->range_starts = new_array_start; + mbcset->range_ends = new_array_end; + *range_alloc = new_nranges; + } + + mbcset->range_starts[mbcset->nranges] = start_wc; + mbcset->range_ends[mbcset->nranges++] = end_wc; + } + + /* Build the table for single byte characters. */ + for (wc = 0; wc < SBC_MAX; ++wc) + { + if (start_wc <= wc && wc <= end_wc) + bitset_set (sbcset, wc); + } + } +# else /* not RE_ENABLE_I18N */ + { + unsigned int ch; + start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch + : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] + : 0)); + end_ch = ((end_elem->type == SB_CHAR ) ? end_elem->opr.ch + : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0] + : 0)); + if (start_ch > end_ch) + return REG_ERANGE; + /* Build the table for single byte characters. */ + for (ch = 0; ch < SBC_MAX; ++ch) + if (start_ch <= ch && ch <= end_ch) + bitset_set (sbcset, ch); + } +# endif /* not RE_ENABLE_I18N */ + return REG_NOERROR; +} +#endif /* not _LIBC */ + +#ifndef _LIBC +/* Helper function for parse_bracket_exp only used in case of NOT _LIBC.. + Build the collating element which is represented by NAME. + The result are written to MBCSET and SBCSET. + COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a + pointer argument since we may update it. */ + +static reg_errcode_t +internal_function +# ifdef RE_ENABLE_I18N +build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, + Idx *coll_sym_alloc, const unsigned char *name) +# else /* not RE_ENABLE_I18N */ +build_collating_symbol (bitset_t sbcset, const unsigned char *name) +# endif /* not RE_ENABLE_I18N */ +{ + size_t name_len = strlen ((const char *) name); + if (BE (name_len != 1, 0)) + return REG_ECOLLATE; + else + { + bitset_set (sbcset, name[0]); + return REG_NOERROR; + } +} +#endif /* not _LIBC */ + +/* This function parse bracket expression like "[abc]", "[a-c]", + "[[.a-a.]]" etc. */ + +static bin_tree_t * +parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, + reg_syntax_t syntax, reg_errcode_t *err) +{ +#ifdef _LIBC + const unsigned char *collseqmb; + const char *collseqwc; + uint32_t nrules; + int32_t table_size; + const int32_t *symb_table; + const unsigned char *extra; + + /* Local function for parse_bracket_exp used in _LIBC environment. + Seek the collating symbol entry corresponding to NAME. + Return the index of the symbol in the SYMB_TABLE, + or -1 if not found. */ + + auto inline int32_t + __attribute__ ((always_inline)) + seek_collating_symbol_entry (const unsigned char *name, size_t name_len) + { + int32_t elem; + + for (elem = 0; elem < table_size; elem++) + if (symb_table[2 * elem] != 0) + { + int32_t idx = symb_table[2 * elem + 1]; + /* Skip the name of collating element name. */ + idx += 1 + extra[idx]; + if (/* Compare the length of the name. */ + name_len == extra[idx] + /* Compare the name. */ + && memcmp (name, &extra[idx + 1], name_len) == 0) + /* Yep, this is the entry. */ + return elem; + } + return -1; + } + + /* Local function for parse_bracket_exp used in _LIBC environment. + Look up the collation sequence value of BR_ELEM. + Return the value if succeeded, UINT_MAX otherwise. */ + + auto inline unsigned int + __attribute__ ((always_inline)) + lookup_collation_sequence_value (bracket_elem_t *br_elem) + { + if (br_elem->type == SB_CHAR) + { + /* + if (MB_CUR_MAX == 1) + */ + if (nrules == 0) + return collseqmb[br_elem->opr.ch]; + else + { + wint_t wc = __btowc (br_elem->opr.ch); + return __collseq_table_lookup (collseqwc, wc); + } + } + else if (br_elem->type == MB_CHAR) + { + if (nrules != 0) + return __collseq_table_lookup (collseqwc, br_elem->opr.wch); + } + else if (br_elem->type == COLL_SYM) + { + size_t sym_name_len = strlen ((char *) br_elem->opr.name); + if (nrules != 0) + { + int32_t elem, idx; + elem = seek_collating_symbol_entry (br_elem->opr.name, + sym_name_len); + if (elem != -1) + { + /* We found the entry. */ + idx = symb_table[2 * elem + 1]; + /* Skip the name of collating element name. */ + idx += 1 + extra[idx]; + /* Skip the byte sequence of the collating element. */ + idx += 1 + extra[idx]; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~3; + /* Skip the multibyte collation sequence value. */ + idx += sizeof (unsigned int); + /* Skip the wide char sequence of the collating element. */ + idx += sizeof (unsigned int) * + (1 + *(unsigned int *) (extra + idx)); + /* Return the collation sequence value. */ + return *(unsigned int *) (extra + idx); + } + else if (sym_name_len == 1) + { + /* No valid character. Match it as a single byte + character. */ + return collseqmb[br_elem->opr.name[0]]; + } + } + else if (sym_name_len == 1) + return collseqmb[br_elem->opr.name[0]]; + } + return UINT_MAX; + } + + /* Local function for parse_bracket_exp used in _LIBC environment. + Build the range expression which starts from START_ELEM, and ends + at END_ELEM. The result are written to MBCSET and SBCSET. + RANGE_ALLOC is the allocated size of mbcset->range_starts, and + mbcset->range_ends, is a pointer argument since we may + update it. */ + + auto inline reg_errcode_t + __attribute__ ((always_inline)) + build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc, + bracket_elem_t *start_elem, bracket_elem_t *end_elem) + { + unsigned int ch; + uint32_t start_collseq; + uint32_t end_collseq; + + /* Equivalence Classes and Character Classes can't be a range + start/end. */ + if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS + || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, + 0)) + return REG_ERANGE; + + /* FIXME: Implement rational ranges here, too. */ + start_collseq = lookup_collation_sequence_value (start_elem); + end_collseq = lookup_collation_sequence_value (end_elem); + /* Check start/end collation sequence values. */ + if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) + return REG_ECOLLATE; + if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) + return REG_ERANGE; + + /* Got valid collation sequence values, add them as a new entry. + However, if we have no collation elements, and the character set + is single byte, the single byte character set that we + build below suffices. */ + if (nrules > 0 || dfa->mb_cur_max > 1) + { + /* Check the space of the arrays. */ + if (BE (*range_alloc == mbcset->nranges, 0)) + { + /* There is not enough space, need realloc. */ + uint32_t *new_array_start; + uint32_t *new_array_end; + Idx new_nranges; + + /* +1 in case of mbcset->nranges is 0. */ + new_nranges = 2 * mbcset->nranges + 1; + new_array_start = re_realloc (mbcset->range_starts, uint32_t, + new_nranges); + new_array_end = re_realloc (mbcset->range_ends, uint32_t, + new_nranges); + + if (BE (new_array_start == NULL || new_array_end == NULL, 0)) + return REG_ESPACE; + + mbcset->range_starts = new_array_start; + mbcset->range_ends = new_array_end; + *range_alloc = new_nranges; + } + + mbcset->range_starts[mbcset->nranges] = start_collseq; + mbcset->range_ends[mbcset->nranges++] = end_collseq; + } + + /* Build the table for single byte characters. */ + for (ch = 0; ch < SBC_MAX; ch++) + { + uint32_t ch_collseq; + /* + if (MB_CUR_MAX == 1) + */ + if (nrules == 0) + ch_collseq = collseqmb[ch]; + else + ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch)); + if (start_collseq <= ch_collseq && ch_collseq <= end_collseq) + bitset_set (sbcset, ch); + } + return REG_NOERROR; + } + + /* Local function for parse_bracket_exp used in _LIBC environment. + Build the collating element which is represented by NAME. + The result are written to MBCSET and SBCSET. + COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a + pointer argument since we may update it. */ + + auto inline reg_errcode_t + __attribute__ ((always_inline)) + build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, + Idx *coll_sym_alloc, const unsigned char *name) + { + int32_t elem, idx; + size_t name_len = strlen ((const char *) name); + if (nrules != 0) + { + elem = seek_collating_symbol_entry (name, name_len); + if (elem != -1) + { + /* We found the entry. */ + idx = symb_table[2 * elem + 1]; + /* Skip the name of collating element name. */ + idx += 1 + extra[idx]; + } + else if (name_len == 1) + { + /* No valid character, treat it as a normal + character. */ + bitset_set (sbcset, name[0]); + return REG_NOERROR; + } + else + return REG_ECOLLATE; + + /* Got valid collation sequence, add it as a new entry. */ + /* Check the space of the arrays. */ + if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0)) + { + /* Not enough, realloc it. */ + /* +1 in case of mbcset->ncoll_syms is 0. */ + Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1; + /* Use realloc since mbcset->coll_syms is NULL + if *alloc == 0. */ + int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t, + new_coll_sym_alloc); + if (BE (new_coll_syms == NULL, 0)) + return REG_ESPACE; + mbcset->coll_syms = new_coll_syms; + *coll_sym_alloc = new_coll_sym_alloc; + } + mbcset->coll_syms[mbcset->ncoll_syms++] = idx; + return REG_NOERROR; + } + else + { + if (BE (name_len != 1, 0)) + return REG_ECOLLATE; + else + { + bitset_set (sbcset, name[0]); + return REG_NOERROR; + } + } + } +#endif + + re_token_t br_token; + re_bitset_ptr_t sbcset; +#ifdef RE_ENABLE_I18N + re_charset_t *mbcset; + Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0; + Idx equiv_class_alloc = 0, char_class_alloc = 0; +#endif /* not RE_ENABLE_I18N */ + bool non_match = false; + bin_tree_t *work_tree; + int token_len; + bool first_round = true; +#ifdef _LIBC + collseqmb = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB); + nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + if (nrules) + { + /* + if (MB_CUR_MAX > 1) + */ + collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); + table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB); + symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_TABLEMB); + extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_SYMB_EXTRAMB); + } +#endif + sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); +#ifdef RE_ENABLE_I18N + mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); +#endif /* RE_ENABLE_I18N */ +#ifdef RE_ENABLE_I18N + if (BE (sbcset == NULL || mbcset == NULL, 0)) +#else + if (BE (sbcset == NULL, 0)) +#endif /* RE_ENABLE_I18N */ + { + re_free (sbcset); +#ifdef RE_ENABLE_I18N + re_free (mbcset); +#endif + *err = REG_ESPACE; + return NULL; + } + + token_len = peek_token_bracket (token, regexp, syntax); + if (BE (token->type == END_OF_RE, 0)) + { + *err = REG_BADPAT; + goto parse_bracket_exp_free_return; + } + if (token->type == OP_NON_MATCH_LIST) + { +#ifdef RE_ENABLE_I18N + mbcset->non_match = 1; +#endif /* not RE_ENABLE_I18N */ + non_match = true; + if (syntax & RE_HAT_LISTS_NOT_NEWLINE) + bitset_set (sbcset, '\n'); + re_string_skip_bytes (regexp, token_len); /* Skip a token. */ + token_len = peek_token_bracket (token, regexp, syntax); + if (BE (token->type == END_OF_RE, 0)) + { + *err = REG_BADPAT; + goto parse_bracket_exp_free_return; + } + } + + /* We treat the first ']' as a normal character. */ + if (token->type == OP_CLOSE_BRACKET) + token->type = CHARACTER; + + while (1) + { + bracket_elem_t start_elem, end_elem; + unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE]; + unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE]; + reg_errcode_t ret; + int token_len2 = 0; + bool is_range_exp = false; + re_token_t token2; + + start_elem.opr.name = start_name_buf; + ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa, + syntax, first_round); + if (BE (ret != REG_NOERROR, 0)) + { + *err = ret; + goto parse_bracket_exp_free_return; + } + first_round = false; + + /* Get information about the next token. We need it in any case. */ + token_len = peek_token_bracket (token, regexp, syntax); + + /* Do not check for ranges if we know they are not allowed. */ + if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS) + { + if (BE (token->type == END_OF_RE, 0)) + { + *err = REG_EBRACK; + goto parse_bracket_exp_free_return; + } + if (token->type == OP_CHARSET_RANGE) + { + re_string_skip_bytes (regexp, token_len); /* Skip '-'. */ + token_len2 = peek_token_bracket (&token2, regexp, syntax); + if (BE (token2.type == END_OF_RE, 0)) + { + *err = REG_EBRACK; + goto parse_bracket_exp_free_return; + } + if (token2.type == OP_CLOSE_BRACKET) + { + /* We treat the last '-' as a normal character. */ + re_string_skip_bytes (regexp, -token_len); + token->type = CHARACTER; + } + else + is_range_exp = true; + } + } + + if (is_range_exp == true) + { + end_elem.opr.name = end_name_buf; + ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2, + dfa, syntax, true); + if (BE (ret != REG_NOERROR, 0)) + { + *err = ret; + goto parse_bracket_exp_free_return; + } + + token_len = peek_token_bracket (token, regexp, syntax); + +#ifdef _LIBC + *err = build_range_exp (sbcset, mbcset, &range_alloc, + &start_elem, &end_elem); +#else +# ifdef RE_ENABLE_I18N + *err = build_range_exp (syntax, sbcset, + dfa->mb_cur_max > 1 ? mbcset : NULL, + &range_alloc, &start_elem, &end_elem); +# else + *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem); +# endif +#endif /* RE_ENABLE_I18N */ + if (BE (*err != REG_NOERROR, 0)) + goto parse_bracket_exp_free_return; + } + else + { + switch (start_elem.type) + { + case SB_CHAR: + bitset_set (sbcset, start_elem.opr.ch); + break; +#ifdef RE_ENABLE_I18N + case MB_CHAR: + /* Check whether the array has enough space. */ + if (BE (mbchar_alloc == mbcset->nmbchars, 0)) + { + wchar_t *new_mbchars; + /* Not enough, realloc it. */ + /* +1 in case of mbcset->nmbchars is 0. */ + mbchar_alloc = 2 * mbcset->nmbchars + 1; + /* Use realloc since array is NULL if *alloc == 0. */ + new_mbchars = re_realloc (mbcset->mbchars, wchar_t, + mbchar_alloc); + if (BE (new_mbchars == NULL, 0)) + goto parse_bracket_exp_espace; + mbcset->mbchars = new_mbchars; + } + mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch; + break; +#endif /* RE_ENABLE_I18N */ + case EQUIV_CLASS: + *err = build_equiv_class (sbcset, +#ifdef RE_ENABLE_I18N + mbcset, &equiv_class_alloc, +#endif /* RE_ENABLE_I18N */ + start_elem.opr.name); + if (BE (*err != REG_NOERROR, 0)) + goto parse_bracket_exp_free_return; + break; + case COLL_SYM: + *err = build_collating_symbol (sbcset, +#ifdef RE_ENABLE_I18N + mbcset, &coll_sym_alloc, +#endif /* RE_ENABLE_I18N */ + start_elem.opr.name); + if (BE (*err != REG_NOERROR, 0)) + goto parse_bracket_exp_free_return; + break; + case CHAR_CLASS: + *err = build_charclass (regexp->trans, sbcset, +#ifdef RE_ENABLE_I18N + mbcset, &char_class_alloc, +#endif /* RE_ENABLE_I18N */ + (const char *) start_elem.opr.name, + syntax); + if (BE (*err != REG_NOERROR, 0)) + goto parse_bracket_exp_free_return; + break; + default: + assert (0); + break; + } + } + if (BE (token->type == END_OF_RE, 0)) + { + *err = REG_EBRACK; + goto parse_bracket_exp_free_return; + } + if (token->type == OP_CLOSE_BRACKET) + break; + } + + re_string_skip_bytes (regexp, token_len); /* Skip a token. */ + + /* If it is non-matching list. */ + if (non_match) + bitset_not (sbcset); + +#ifdef RE_ENABLE_I18N + /* Ensure only single byte characters are set. */ + if (dfa->mb_cur_max > 1) + bitset_mask (sbcset, dfa->sb_char); + + if (mbcset->nmbchars || mbcset->ncoll_syms || mbcset->nequiv_classes + || mbcset->nranges || (dfa->mb_cur_max > 1 && (mbcset->nchar_classes + || mbcset->non_match))) + { + bin_tree_t *mbc_tree; + int sbc_idx; + /* Build a tree for complex bracket. */ + dfa->has_mb_node = 1; + br_token.type = COMPLEX_BRACKET; + br_token.opr.mbcset = mbcset; + mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); + if (BE (mbc_tree == NULL, 0)) + goto parse_bracket_exp_espace; + for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx) + if (sbcset[sbc_idx]) + break; + /* If there are no bits set in sbcset, there is no point + of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */ + if (sbc_idx < BITSET_WORDS) + { + /* Build a tree for simple bracket. */ + br_token.type = SIMPLE_BRACKET; + br_token.opr.sbcset = sbcset; + work_tree = create_token_tree (dfa, NULL, NULL, &br_token); + if (BE (work_tree == NULL, 0)) + goto parse_bracket_exp_espace; + + /* Then join them by ALT node. */ + work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT); + if (BE (work_tree == NULL, 0)) + goto parse_bracket_exp_espace; + } + else + { + re_free (sbcset); + work_tree = mbc_tree; + } + } + else +#endif /* not RE_ENABLE_I18N */ + { +#ifdef RE_ENABLE_I18N + free_charset (mbcset); +#endif + /* Build a tree for simple bracket. */ + br_token.type = SIMPLE_BRACKET; + br_token.opr.sbcset = sbcset; + work_tree = create_token_tree (dfa, NULL, NULL, &br_token); + if (BE (work_tree == NULL, 0)) + goto parse_bracket_exp_espace; + } + return work_tree; + + parse_bracket_exp_espace: + *err = REG_ESPACE; + parse_bracket_exp_free_return: + re_free (sbcset); +#ifdef RE_ENABLE_I18N + free_charset (mbcset); +#endif /* RE_ENABLE_I18N */ + return NULL; +} + +/* Parse an element in the bracket expression. */ + +static reg_errcode_t +parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp, + re_token_t *token, int token_len, re_dfa_t *dfa, + reg_syntax_t syntax, bool accept_hyphen) +{ +#ifdef RE_ENABLE_I18N + int cur_char_size; + cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp)); + if (cur_char_size > 1) + { + elem->type = MB_CHAR; + elem->opr.wch = re_string_wchar_at (regexp, re_string_cur_idx (regexp)); + re_string_skip_bytes (regexp, cur_char_size); + return REG_NOERROR; + } +#endif /* RE_ENABLE_I18N */ + re_string_skip_bytes (regexp, token_len); /* Skip a token. */ + if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS + || token->type == OP_OPEN_EQUIV_CLASS) + return parse_bracket_symbol (elem, regexp, token); + if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen) + { + /* A '-' must only appear as anything but a range indicator before + the closing bracket. Everything else is an error. */ + re_token_t token2; + (void) peek_token_bracket (&token2, regexp, syntax); + if (token2.type != OP_CLOSE_BRACKET) + /* The actual error value is not standardized since this whole + case is undefined. But ERANGE makes good sense. */ + return REG_ERANGE; + } + elem->type = SB_CHAR; + elem->opr.ch = token->opr.c; + return REG_NOERROR; +} + +/* Parse a bracket symbol in the bracket expression. Bracket symbols are + such as [::], [..], and + [==]. */ + +static reg_errcode_t +parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp, + re_token_t *token) +{ + unsigned char ch, delim = token->opr.c; + int i = 0; + if (re_string_eoi(regexp)) + return REG_EBRACK; + for (;; ++i) + { + if (i >= BRACKET_NAME_BUF_SIZE) + return REG_EBRACK; + if (token->type == OP_OPEN_CHAR_CLASS) + ch = re_string_fetch_byte_case (regexp); + else + ch = re_string_fetch_byte (regexp); + if (re_string_eoi(regexp)) + return REG_EBRACK; + if (ch == delim && re_string_peek_byte (regexp, 0) == ']') + break; + elem->opr.name[i] = ch; + } + re_string_skip_bytes (regexp, 1); + elem->opr.name[i] = '\0'; + switch (token->type) + { + case OP_OPEN_COLL_ELEM: + elem->type = COLL_SYM; + break; + case OP_OPEN_EQUIV_CLASS: + elem->type = EQUIV_CLASS; + break; + case OP_OPEN_CHAR_CLASS: + elem->type = CHAR_CLASS; + break; + default: + break; + } + return REG_NOERROR; +} + + /* Helper function for parse_bracket_exp. + Build the equivalence class which is represented by NAME. + The result are written to MBCSET and SBCSET. + EQUIV_CLASS_ALLOC is the allocated size of mbcset->equiv_classes, + is a pointer argument since we may update it. */ + +static reg_errcode_t +#ifdef RE_ENABLE_I18N +build_equiv_class (bitset_t sbcset, re_charset_t *mbcset, + Idx *equiv_class_alloc, const unsigned char *name) +#else /* not RE_ENABLE_I18N */ +build_equiv_class (bitset_t sbcset, const unsigned char *name) +#endif /* not RE_ENABLE_I18N */ +{ +#ifdef _LIBC + uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + if (nrules != 0) + { + const int32_t *table, *indirect; + const unsigned char *weights, *extra, *cp; + unsigned char char_buf[2]; + int32_t idx1, idx2; + unsigned int ch; + size_t len; + /* This #include defines a local function! */ +# include + /* Calculate the index for equivalence class. */ + cp = name; + table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); + weights = (const unsigned char *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_WEIGHTMB); + extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_EXTRAMB); + indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_INDIRECTMB); + idx1 = findidx (&cp, -1); + if (BE (idx1 == 0 || *cp != '\0', 0)) + /* This isn't a valid character. */ + return REG_ECOLLATE; + + /* Build single byte matching table for this equivalence class. */ + len = weights[idx1 & 0xffffff]; + for (ch = 0; ch < SBC_MAX; ++ch) + { + char_buf[0] = ch; + cp = char_buf; + idx2 = findidx (&cp, 1); +/* + idx2 = table[ch]; +*/ + if (idx2 == 0) + /* This isn't a valid character. */ + continue; + /* Compare only if the length matches and the collation rule + index is the same. */ + if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24)) + { + int cnt = 0; + + while (cnt <= len && + weights[(idx1 & 0xffffff) + 1 + cnt] + == weights[(idx2 & 0xffffff) + 1 + cnt]) + ++cnt; + + if (cnt > len) + bitset_set (sbcset, ch); + } + } + /* Check whether the array has enough space. */ + if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) + { + /* Not enough, realloc it. */ + /* +1 in case of mbcset->nequiv_classes is 0. */ + Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1; + /* Use realloc since the array is NULL if *alloc == 0. */ + int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes, + int32_t, + new_equiv_class_alloc); + if (BE (new_equiv_classes == NULL, 0)) + return REG_ESPACE; + mbcset->equiv_classes = new_equiv_classes; + *equiv_class_alloc = new_equiv_class_alloc; + } + mbcset->equiv_classes[mbcset->nequiv_classes++] = idx1; + } + else +#endif /* _LIBC */ + { + if (BE (strlen ((const char *) name) != 1, 0)) + return REG_ECOLLATE; + bitset_set (sbcset, *name); + } + return REG_NOERROR; +} + + /* Helper function for parse_bracket_exp. + Build the character class which is represented by NAME. + The result are written to MBCSET and SBCSET. + CHAR_CLASS_ALLOC is the allocated size of mbcset->char_classes, + is a pointer argument since we may update it. */ + +static reg_errcode_t +#ifdef RE_ENABLE_I18N +build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, + re_charset_t *mbcset, Idx *char_class_alloc, + const char *class_name, reg_syntax_t syntax) +#else /* not RE_ENABLE_I18N */ +build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset, + const char *class_name, reg_syntax_t syntax) +#endif /* not RE_ENABLE_I18N */ +{ + int i; + const char *name = class_name; + + /* In case of REG_ICASE "upper" and "lower" match the both of + upper and lower cases. */ + if ((syntax & RE_ICASE) + && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0)) + name = "alpha"; + +#ifdef RE_ENABLE_I18N + /* Check the space of the arrays. */ + if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) + { + /* Not enough, realloc it. */ + /* +1 in case of mbcset->nchar_classes is 0. */ + Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1; + /* Use realloc since array is NULL if *alloc == 0. */ + wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t, + new_char_class_alloc); + if (BE (new_char_classes == NULL, 0)) + return REG_ESPACE; + mbcset->char_classes = new_char_classes; + *char_class_alloc = new_char_class_alloc; + } + mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name); +#endif /* RE_ENABLE_I18N */ + +#define BUILD_CHARCLASS_LOOP(ctype_func) \ + do { \ + if (BE (trans != NULL, 0)) \ + { \ + for (i = 0; i < SBC_MAX; ++i) \ + if (ctype_func (i)) \ + bitset_set (sbcset, trans[i]); \ + } \ + else \ + { \ + for (i = 0; i < SBC_MAX; ++i) \ + if (ctype_func (i)) \ + bitset_set (sbcset, i); \ + } \ + } while (0) + + if (strcmp (name, "alnum") == 0) + BUILD_CHARCLASS_LOOP (isalnum); + else if (strcmp (name, "cntrl") == 0) + BUILD_CHARCLASS_LOOP (iscntrl); + else if (strcmp (name, "lower") == 0) + BUILD_CHARCLASS_LOOP (islower); + else if (strcmp (name, "space") == 0) + BUILD_CHARCLASS_LOOP (isspace); + else if (strcmp (name, "alpha") == 0) + BUILD_CHARCLASS_LOOP (isalpha); + else if (strcmp (name, "digit") == 0) + BUILD_CHARCLASS_LOOP (isdigit); + else if (strcmp (name, "print") == 0) + BUILD_CHARCLASS_LOOP (isprint); + else if (strcmp (name, "upper") == 0) + BUILD_CHARCLASS_LOOP (isupper); + else if (strcmp (name, "blank") == 0) + BUILD_CHARCLASS_LOOP (isblank); + else if (strcmp (name, "graph") == 0) + BUILD_CHARCLASS_LOOP (isgraph); + else if (strcmp (name, "punct") == 0) + BUILD_CHARCLASS_LOOP (ispunct); + else if (strcmp (name, "xdigit") == 0) + BUILD_CHARCLASS_LOOP (isxdigit); + else + return REG_ECTYPE; + + return REG_NOERROR; +} + +static bin_tree_t * +build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans, + const char *class_name, + const char *extra, bool non_match, + reg_errcode_t *err) +{ + re_bitset_ptr_t sbcset; +#ifdef RE_ENABLE_I18N + re_charset_t *mbcset; + Idx alloc = 0; +#endif /* not RE_ENABLE_I18N */ + reg_errcode_t ret; + re_token_t br_token; + bin_tree_t *tree; + + sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); +#ifdef RE_ENABLE_I18N + mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); +#endif /* RE_ENABLE_I18N */ + +#ifdef RE_ENABLE_I18N + if (BE (sbcset == NULL || mbcset == NULL, 0)) +#else /* not RE_ENABLE_I18N */ + if (BE (sbcset == NULL, 0)) +#endif /* not RE_ENABLE_I18N */ + { + *err = REG_ESPACE; + return NULL; + } + + if (non_match) + { +#ifdef RE_ENABLE_I18N + mbcset->non_match = 1; +#endif /* not RE_ENABLE_I18N */ + } + + /* We don't care the syntax in this case. */ + ret = build_charclass (trans, sbcset, +#ifdef RE_ENABLE_I18N + mbcset, &alloc, +#endif /* RE_ENABLE_I18N */ + class_name, 0); + + if (BE (ret != REG_NOERROR, 0)) + { + re_free (sbcset); +#ifdef RE_ENABLE_I18N + free_charset (mbcset); +#endif /* RE_ENABLE_I18N */ + *err = ret; + return NULL; + } + /* \w match '_' also. */ + for (; *extra; extra++) + bitset_set (sbcset, *extra); + + /* If it is non-matching list. */ + if (non_match) + bitset_not (sbcset); + +#ifdef RE_ENABLE_I18N + /* Ensure only single byte characters are set. */ + if (dfa->mb_cur_max > 1) + bitset_mask (sbcset, dfa->sb_char); +#endif + + /* Build a tree for simple bracket. */ + br_token.type = SIMPLE_BRACKET; + br_token.opr.sbcset = sbcset; + tree = create_token_tree (dfa, NULL, NULL, &br_token); + if (BE (tree == NULL, 0)) + goto build_word_op_espace; + +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + { + bin_tree_t *mbc_tree; + /* Build a tree for complex bracket. */ + br_token.type = COMPLEX_BRACKET; + br_token.opr.mbcset = mbcset; + dfa->has_mb_node = 1; + mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); + if (BE (mbc_tree == NULL, 0)) + goto build_word_op_espace; + /* Then join them by ALT node. */ + tree = create_tree (dfa, tree, mbc_tree, OP_ALT); + if (BE (mbc_tree != NULL, 1)) + return tree; + } + else + { + free_charset (mbcset); + return tree; + } +#else /* not RE_ENABLE_I18N */ + return tree; +#endif /* not RE_ENABLE_I18N */ + + build_word_op_espace: + re_free (sbcset); +#ifdef RE_ENABLE_I18N + free_charset (mbcset); +#endif /* RE_ENABLE_I18N */ + *err = REG_ESPACE; + return NULL; +} + +/* This is intended for the expressions like "a{1,3}". + Fetch a number from 'input', and return the number. + Return REG_MISSING if the number field is empty like "{,1}". + Return RE_DUP_MAX + 1 if the number field is too large. + Return REG_ERROR if an error occurred. */ + +static Idx +fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) +{ + Idx num = REG_MISSING; + unsigned char c; + while (1) + { + fetch_token (token, input, syntax); + c = token->opr.c; + if (BE (token->type == END_OF_RE, 0)) + return REG_ERROR; + if (token->type == OP_CLOSE_DUP_NUM || c == ',') + break; + num = ((token->type != CHARACTER || c < '0' || '9' < c + || num == REG_ERROR) + ? REG_ERROR + : num == REG_MISSING + ? c - '0' + : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); + } + return num; +} + +#ifdef RE_ENABLE_I18N +static void +free_charset (re_charset_t *cset) +{ + re_free (cset->mbchars); +# ifdef _LIBC + re_free (cset->coll_syms); + re_free (cset->equiv_classes); + re_free (cset->range_starts); + re_free (cset->range_ends); +# endif + re_free (cset->char_classes); + re_free (cset); +} +#endif /* RE_ENABLE_I18N */ + +/* Functions for binary tree operation. */ + +/* Create a tree node. */ + +static bin_tree_t * +create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, + re_token_type_t type) +{ + re_token_t t; + t.type = type; + return create_token_tree (dfa, left, right, &t); +} + +static bin_tree_t * +create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, + const re_token_t *token) +{ + bin_tree_t *tree; + if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0)) + { + bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1); + + if (storage == NULL) + return NULL; + storage->next = dfa->str_tree_storage; + dfa->str_tree_storage = storage; + dfa->str_tree_storage_idx = 0; + } + tree = &dfa->str_tree_storage->data[dfa->str_tree_storage_idx++]; + + tree->parent = NULL; + tree->left = left; + tree->right = right; + tree->token = *token; + tree->token.duplicated = 0; + tree->token.opt_subexp = 0; + tree->first = NULL; + tree->next = NULL; + tree->node_idx = REG_MISSING; + + if (left != NULL) + left->parent = tree; + if (right != NULL) + right->parent = tree; + return tree; +} + +/* Mark the tree SRC as an optional subexpression. + To be called from preorder or postorder. */ + +static reg_errcode_t +mark_opt_subexp (void *extra, bin_tree_t *node) +{ + Idx idx = (uintptr_t) extra; + if (node->token.type == SUBEXP && node->token.opr.idx == idx) + node->token.opt_subexp = 1; + + return REG_NOERROR; +} + +/* Free the allocated memory inside NODE. */ + +static void +free_token (re_token_t *node) +{ +#ifdef RE_ENABLE_I18N + if (node->type == COMPLEX_BRACKET && node->duplicated == 0) + free_charset (node->opr.mbcset); + else +#endif /* RE_ENABLE_I18N */ + if (node->type == SIMPLE_BRACKET && node->duplicated == 0) + re_free (node->opr.sbcset); +} + +/* Worker function for tree walking. Free the allocated memory inside NODE + and its children. */ + +static reg_errcode_t +free_tree (void *extra, bin_tree_t *node) +{ + free_token (&node->token); + return REG_NOERROR; +} + + +/* Duplicate the node SRC, and return new node. This is a preorder + visit similar to the one implemented by the generic visitor, but + we need more infrastructure to maintain two parallel trees --- so, + it's easier to duplicate. */ + +static bin_tree_t * +duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa) +{ + const bin_tree_t *node; + bin_tree_t *dup_root; + bin_tree_t **p_new = &dup_root, *dup_node = root->parent; + + for (node = root; ; ) + { + /* Create a new tree and link it back to the current parent. */ + *p_new = create_token_tree (dfa, NULL, NULL, &node->token); + if (*p_new == NULL) + return NULL; + (*p_new)->parent = dup_node; + (*p_new)->token.duplicated = 1; + dup_node = *p_new; + + /* Go to the left node, or up and to the right. */ + if (node->left) + { + node = node->left; + p_new = &dup_node->left; + } + else + { + const bin_tree_t *prev = NULL; + while (node->right == prev || node->right == NULL) + { + prev = node; + node = node->parent; + dup_node = dup_node->parent; + if (!node) + return dup_root; + } + node = node->right; + p_new = &dup_node->right; + } + } +} diff --git a/grub-core/gnulib/regex.c b/grub-core/gnulib/regex.c new file mode 100644 index 000000000..5a0332e00 --- /dev/null +++ b/grub-core/gnulib/regex.c @@ -0,0 +1,81 @@ +/* Extended regular expression matching and search library. + Copyright (C) 2002-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Isamu Hasegawa . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _LIBC +# include + +# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +# endif +# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wold-style-definition" +# pragma GCC diagnostic ignored "-Wtype-limits" +# endif +#endif + +/* Make sure no one compiles this code with a C++ compiler. */ +#if defined __cplusplus && defined _LIBC +# error "This is C code, use a C compiler" +#endif + +#ifdef _LIBC +/* We have to keep the namespace clean. */ +# define regfree(preg) __regfree (preg) +# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef) +# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags) +# define regerror(errcode, preg, errbuf, errbuf_size) \ + __regerror(errcode, preg, errbuf, errbuf_size) +# define re_set_registers(bu, re, nu, st, en) \ + __re_set_registers (bu, re, nu, st, en) +# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \ + __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) +# define re_match(bufp, string, size, pos, regs) \ + __re_match (bufp, string, size, pos, regs) +# define re_search(bufp, string, size, startpos, range, regs) \ + __re_search (bufp, string, size, startpos, range, regs) +# define re_compile_pattern(pattern, length, bufp) \ + __re_compile_pattern (pattern, length, bufp) +# define re_set_syntax(syntax) __re_set_syntax (syntax) +# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \ + __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop) +# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp) + +# include "../locale/localeinfo.h" +#endif + +/* On some systems, limits.h sets RE_DUP_MAX to a lower value than + GNU regex allows. Include it before , which correctly + #undefs RE_DUP_MAX and sets it to the right value. */ +#include + +#include +#include "regex_internal.h" + +#include "regex_internal.c" +#include "regcomp.c" +#include "regexec.c" + +/* Binary backward compatibility. */ +#if _LIBC +# include +# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3) +link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.") +int re_max_failures = 2000; +# endif +#endif diff --git a/grub-core/gnulib/regex.h b/grub-core/gnulib/regex.h new file mode 100644 index 000000000..854c6edaf --- /dev/null +++ b/grub-core/gnulib/regex.h @@ -0,0 +1,667 @@ +/* Definitions for data structures and routines for the regular + expression library. + Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2013 Free Software + Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _REGEX_H +#define _REGEX_H 1 + +#include + +/* Allow the use in C++ code. */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Define __USE_GNU to declare GNU extensions that violate the + POSIX name space rules. */ +#ifdef _GNU_SOURCE +# define __USE_GNU 1 +#endif + +#ifdef _REGEX_LARGE_OFFSETS + +/* Use types and values that are wide enough to represent signed and + unsigned byte offsets in memory. This currently works only when + the regex code is used outside of the GNU C library; it is not yet + supported within glibc itself, and glibc users should not define + _REGEX_LARGE_OFFSETS. */ + +/* The type of nonnegative object indexes. Traditionally, GNU regex + uses 'int' for these. Code that uses __re_idx_t should work + regardless of whether the type is signed. */ +typedef size_t __re_idx_t; + +/* The type of object sizes. */ +typedef size_t __re_size_t; + +/* The type of object sizes, in places where the traditional code + uses unsigned long int. */ +typedef size_t __re_long_size_t; + +#else + +/* The traditional GNU regex implementation mishandles strings longer + than INT_MAX. */ +typedef int __re_idx_t; +typedef unsigned int __re_size_t; +typedef unsigned long int __re_long_size_t; + +#endif + +/* The following two types have to be signed and unsigned integer type + wide enough to hold a value of a pointer. For most ANSI compilers + ptrdiff_t and size_t should be likely OK. Still size of these two + types is 2 for Microsoft C. Ugh... */ +typedef long int s_reg_t; +typedef unsigned long int active_reg_t; + +/* The following bits are used to determine the regexp syntax we + recognize. The set/not-set meanings are chosen so that Emacs syntax + remains the value 0. The bits are given in alphabetical order, and + the definitions shifted by one from the previous bit; thus, when we + add or remove a bit, only one other definition need change. */ +typedef unsigned long int reg_syntax_t; + +#ifdef __USE_GNU +/* If this bit is not set, then \ inside a bracket expression is literal. + If set, then such a \ quotes the following character. */ +# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) + +/* If this bit is not set, then + and ? are operators, and \+ and \? are + literals. + If set, then \+ and \? are operators and + and ? are literals. */ +# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) + +/* If this bit is set, then character classes are supported. They are: + [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], + [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. + If not set, then character classes are not supported. */ +# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) + +/* If this bit is set, then ^ and $ are always anchors (outside bracket + expressions, of course). + If this bit is not set, then it depends: + ^ is an anchor if it is at the beginning of a regular + expression or after an open-group or an alternation operator; + $ is an anchor if it is at the end of a regular expression, or + before a close-group or an alternation operator. + + This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because + POSIX draft 11.2 says that * etc. in leading positions is undefined. + We already implemented a previous draft which made those constructs + invalid, though, so we haven't changed the code back. */ +# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) + +/* If this bit is set, then special characters are always special + regardless of where they are in the pattern. + If this bit is not set, then special characters are special only in + some contexts; otherwise they are ordinary. Specifically, + * + ? and intervals are only special when not after the beginning, + open-group, or alternation operator. */ +# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) + +/* If this bit is set, then *, +, ?, and { cannot be first in an re or + immediately after an alternation or begin-group operator. */ +# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) + +/* If this bit is set, then . matches newline. + If not set, then it doesn't. */ +# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) + +/* If this bit is set, then . doesn't match NUL. + If not set, then it does. */ +# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) + +/* If this bit is set, nonmatching lists [^...] do not match newline. + If not set, they do. */ +# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) + +/* If this bit is set, either \{...\} or {...} defines an + interval, depending on RE_NO_BK_BRACES. + If not set, \{, \}, {, and } are literals. */ +# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) + +/* If this bit is set, +, ? and | aren't recognized as operators. + If not set, they are. */ +# define RE_LIMITED_OPS (RE_INTERVALS << 1) + +/* If this bit is set, newline is an alternation operator. + If not set, newline is literal. */ +# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) + +/* If this bit is set, then '{...}' defines an interval, and \{ and \} + are literals. + If not set, then '\{...\}' defines an interval. */ +# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) + +/* If this bit is set, (...) defines a group, and \( and \) are literals. + If not set, \(...\) defines a group, and ( and ) are literals. */ +# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) + +/* If this bit is set, then \ matches . + If not set, then \ is a back-reference. */ +# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) + +/* If this bit is set, then | is an alternation operator, and \| is literal. + If not set, then \| is an alternation operator, and | is literal. */ +# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) + +/* If this bit is set, then an ending range point collating higher + than the starting range point, as in [z-a], is invalid. + If not set, then when ending range point collates higher than the + starting range point, the range is ignored. */ +# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) + +/* If this bit is set, then an unmatched ) is ordinary. + If not set, then an unmatched ) is invalid. */ +# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) + +/* If this bit is set, succeed as soon as we match the whole pattern, + without further backtracking. */ +# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) + +/* If this bit is set, do not process the GNU regex operators. + If not set, then the GNU regex operators are recognized. */ +# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) + +/* If this bit is set, turn on internal regex debugging. + If not set, and debugging was on, turn it off. + This only works if regex.c is compiled -DDEBUG. + We define this bit always, so that all that's needed to turn on + debugging is to recompile regex.c; the calling code can always have + this bit set, and it won't affect anything in the normal case. */ +# define RE_DEBUG (RE_NO_GNU_OPS << 1) + +/* If this bit is set, a syntactically invalid interval is treated as + a string of ordinary characters. For example, the ERE 'a{1' is + treated as 'a\{1'. */ +# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) + +/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only + for ^, because it is difficult to scan the regex backwards to find + whether ^ should be special. */ +# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) + +/* If this bit is set, then \{ cannot be first in a regex or + immediately after an alternation, open-group or \} operator. */ +# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) + +/* If this bit is set, then no_sub will be set to 1 during + re_compile_pattern. */ +# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) +#endif + +/* This global variable defines the particular regexp syntax to use (for + some interfaces). When a regexp is compiled, the syntax used is + stored in the pattern buffer, so changing this does not affect + already-compiled regexps. */ +extern reg_syntax_t re_syntax_options; + +#ifdef __USE_GNU +/* Define combinations of the above bits for the standard possibilities. + (The [[[ comments delimit what gets put into the Texinfo file, so + don't delete them!) */ +/* [[[begin syntaxes]]] */ +# define RE_SYNTAX_EMACS 0 + +# define RE_SYNTAX_AWK \ + (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ + | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CHAR_CLASSES \ + | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) + +# define RE_SYNTAX_GNU_AWK \ + ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INVALID_INTERVAL_ORD) \ + & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \ + | RE_CONTEXT_INVALID_OPS )) + +# define RE_SYNTAX_POSIX_AWK \ + (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INTERVALS | RE_NO_GNU_OPS \ + | RE_INVALID_INTERVAL_ORD) + +# define RE_SYNTAX_GREP \ + (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ + | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ + | RE_NEWLINE_ALT) + +# define RE_SYNTAX_EGREP \ + (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ + | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ + | RE_NO_BK_VBAR) + +# define RE_SYNTAX_POSIX_EGREP \ + (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ + | RE_INVALID_INTERVAL_ORD) + +/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ +# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC + +# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC + +/* Syntax bits common to both basic and extended POSIX regex syntax. */ +# define _RE_SYNTAX_POSIX_COMMON \ + (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ + | RE_INTERVALS | RE_NO_EMPTY_RANGES) + +# define RE_SYNTAX_POSIX_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) + +/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes + RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this + isn't minimal, since other operators, such as \`, aren't disabled. */ +# define RE_SYNTAX_POSIX_MINIMAL_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) + +# define RE_SYNTAX_POSIX_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ + | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) + +/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is + removed and RE_NO_BK_REFS is added. */ +# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) +/* [[[end syntaxes]]] */ + +/* Maximum number of duplicates an interval can allow. POSIX-conforming + systems might define this in , but we want our + value, so remove any previous define. */ +# ifdef _REGEX_INCLUDE_LIMITS_H +# include +# endif +# ifdef RE_DUP_MAX +# undef RE_DUP_MAX +# endif + +/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored + the counter as a 2-byte signed integer. This is no longer true, so + RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to + ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined. + However, there would be a huge performance problem if someone + actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains + its historical value. */ +# define RE_DUP_MAX (0x7fff) +#endif + + +/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */ + +/* If this bit is set, then use extended regular expression syntax. + If not set, then use basic regular expression syntax. */ +#define REG_EXTENDED 1 + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +#define REG_ICASE (1 << 1) + +/* If this bit is set, then anchors do not match at newline + characters in the string. + If not set, then anchors do match at newlines. */ +#define REG_NEWLINE (1 << 2) + +/* If this bit is set, then report only success or fail in regexec. + If not set, then returns differ between not matching and errors. */ +#define REG_NOSUB (1 << 3) + + +/* POSIX 'eflags' bits (i.e., information for regexec). */ + +/* If this bit is set, then the beginning-of-line operator doesn't match + the beginning of the string (presumably because it's not the + beginning of a line). + If not set, then the beginning-of-line operator does match the + beginning of the string. */ +#define REG_NOTBOL 1 + +/* Like REG_NOTBOL, except for the end-of-line. */ +#define REG_NOTEOL (1 << 1) + +/* Use PMATCH[0] to delimit the start and end of the search in the + buffer. */ +#define REG_STARTEND (1 << 2) + + +/* If any error codes are removed, changed, or added, update the + '__re_error_msgid' table in regcomp.c. */ + +typedef enum +{ + _REG_ENOSYS = -1, /* This will never happen for this implementation. */ + _REG_NOERROR = 0, /* Success. */ + _REG_NOMATCH, /* Didn't find a match (for regexec). */ + + /* POSIX regcomp return error codes. (In the order listed in the + standard.) */ + _REG_BADPAT, /* Invalid pattern. */ + _REG_ECOLLATE, /* Invalid collating element. */ + _REG_ECTYPE, /* Invalid character class name. */ + _REG_EESCAPE, /* Trailing backslash. */ + _REG_ESUBREG, /* Invalid back reference. */ + _REG_EBRACK, /* Unmatched left bracket. */ + _REG_EPAREN, /* Parenthesis imbalance. */ + _REG_EBRACE, /* Unmatched \{. */ + _REG_BADBR, /* Invalid contents of \{\}. */ + _REG_ERANGE, /* Invalid range end. */ + _REG_ESPACE, /* Ran out of memory. */ + _REG_BADRPT, /* No preceding re for repetition op. */ + + /* Error codes we've added. */ + _REG_EEND, /* Premature end. */ + _REG_ESIZE, /* Too large (e.g., repeat count too large). */ + _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ +} reg_errcode_t; + +#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K +# define REG_ENOSYS _REG_ENOSYS +#endif +#define REG_NOERROR _REG_NOERROR +#define REG_NOMATCH _REG_NOMATCH +#define REG_BADPAT _REG_BADPAT +#define REG_ECOLLATE _REG_ECOLLATE +#define REG_ECTYPE _REG_ECTYPE +#define REG_EESCAPE _REG_EESCAPE +#define REG_ESUBREG _REG_ESUBREG +#define REG_EBRACK _REG_EBRACK +#define REG_EPAREN _REG_EPAREN +#define REG_EBRACE _REG_EBRACE +#define REG_BADBR _REG_BADBR +#define REG_ERANGE _REG_ERANGE +#define REG_ESPACE _REG_ESPACE +#define REG_BADRPT _REG_BADRPT +#define REG_EEND _REG_EEND +#define REG_ESIZE _REG_ESIZE +#define REG_ERPAREN _REG_ERPAREN + +/* This data structure represents a compiled pattern. Before calling + the pattern compiler, the fields 'buffer', 'allocated', 'fastmap', + and 'translate' can be set. After the pattern has been compiled, + the fields 're_nsub', 'not_bol' and 'not_eol' are available. All + other fields are private to the regex routines. */ + +#ifndef RE_TRANSLATE_TYPE +# define __RE_TRANSLATE_TYPE unsigned char * +# ifdef __USE_GNU +# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE +# endif +#endif + +#ifdef __USE_GNU +# define __REPB_PREFIX(name) name +#else +# define __REPB_PREFIX(name) __##name +#endif + +struct re_pattern_buffer +{ + /* Space that holds the compiled pattern. The type + 'struct re_dfa_t' is private and is not declared here. */ + struct re_dfa_t *__REPB_PREFIX(buffer); + + /* Number of bytes to which 'buffer' points. */ + __re_long_size_t __REPB_PREFIX(allocated); + + /* Number of bytes actually used in 'buffer'. */ + __re_long_size_t __REPB_PREFIX(used); + + /* Syntax setting with which the pattern was compiled. */ + reg_syntax_t __REPB_PREFIX(syntax); + + /* Pointer to a fastmap, if any, otherwise zero. re_search uses the + fastmap, if there is one, to skip over impossible starting points + for matches. */ + char *__REPB_PREFIX(fastmap); + + /* Either a translate table to apply to all characters before + comparing them, or zero for no translation. The translation is + applied to a pattern when it is compiled and to a string when it + is matched. */ + __RE_TRANSLATE_TYPE __REPB_PREFIX(translate); + + /* Number of subexpressions found by the compiler. */ + size_t re_nsub; + + /* Zero if this pattern cannot match the empty string, one else. + Well, in truth it's used only in 're_search_2', to see whether or + not we should use the fastmap, so we don't set this absolutely + perfectly; see 're_compile_fastmap' (the "duplicate" case). */ + unsigned __REPB_PREFIX(can_be_null) : 1; + + /* If REGS_UNALLOCATED, allocate space in the 'regs' structure + for 'max (RE_NREGS, re_nsub + 1)' groups. + If REGS_REALLOCATE, reallocate space if necessary. + If REGS_FIXED, use what's there. */ +#ifdef __USE_GNU +# define REGS_UNALLOCATED 0 +# define REGS_REALLOCATE 1 +# define REGS_FIXED 2 +#endif + unsigned __REPB_PREFIX(regs_allocated) : 2; + + /* Set to zero when 're_compile_pattern' compiles a pattern; set to + one by 're_compile_fastmap' if it updates the fastmap. */ + unsigned __REPB_PREFIX(fastmap_accurate) : 1; + + /* If set, 're_match_2' does not return information about + subexpressions. */ + unsigned __REPB_PREFIX(no_sub) : 1; + + /* If set, a beginning-of-line anchor doesn't match at the beginning + of the string. */ + unsigned __REPB_PREFIX(not_bol) : 1; + + /* Similarly for an end-of-line anchor. */ + unsigned __REPB_PREFIX(not_eol) : 1; + + /* If true, an anchor at a newline matches. */ + unsigned __REPB_PREFIX(newline_anchor) : 1; +}; + +typedef struct re_pattern_buffer regex_t; + +/* Type for byte offsets within the string. POSIX mandates this. */ +#ifdef _REGEX_LARGE_OFFSETS +/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as + ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t + is wider than ssize_t, so ssize_t is safe. */ +typedef ssize_t regoff_t; +#else +/* The traditional GNU regex implementation mishandles strings longer + than INT_MAX. */ +typedef int regoff_t; +#endif + + +#ifdef __USE_GNU +/* This is the structure we store register match data in. See + regex.texinfo for a full description of what registers match. */ +struct re_registers +{ + __re_size_t num_regs; + regoff_t *start; + regoff_t *end; +}; + + +/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer, + 're_match_2' returns information about at least this many registers + the first time a 'regs' structure is passed. */ +# ifndef RE_NREGS +# define RE_NREGS 30 +# endif +#endif + + +/* POSIX specification for registers. Aside from the different names than + 're_registers', POSIX uses an array of structures, instead of a + structure of arrays. */ +typedef struct +{ + regoff_t rm_so; /* Byte offset from string's start to substring's start. */ + regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ +} regmatch_t; + +/* Declarations for routines. */ + +#ifdef __USE_GNU +/* Sets the current default syntax to SYNTAX, and return the old syntax. + You can also simply assign to the 're_syntax_options' variable. */ +extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); + +/* Compile the regular expression PATTERN, with length LENGTH + and syntax given by the global 're_syntax_options', into the buffer + BUFFER. Return NULL if successful, and an error string if not. + + To free the allocated storage, you must call 'regfree' on BUFFER. + Note that the translate table must either have been initialised by + 'regcomp', with a malloc'ed value, or set to NULL before calling + 'regfree'. */ +extern const char *re_compile_pattern (const char *__pattern, size_t __length, + struct re_pattern_buffer *__buffer); + + +/* Compile a fastmap for the compiled pattern in BUFFER; used to + accelerate searches. Return 0 if successful and -2 if was an + internal error. */ +extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); + + +/* Search in the string STRING (with length LENGTH) for the pattern + compiled into BUFFER. Start searching at position START, for RANGE + characters. Return the starting position of the match, -1 for no + match, or -2 for an internal error. Also return register + information in REGS (if REGS and BUFFER->no_sub are nonzero). */ +extern regoff_t re_search (struct re_pattern_buffer *__buffer, + const char *__string, __re_idx_t __length, + __re_idx_t __start, regoff_t __range, + struct re_registers *__regs); + + +/* Like 're_search', but search in the concatenation of STRING1 and + STRING2. Also, stop searching at index START + STOP. */ +extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, + const char *__string1, __re_idx_t __length1, + const char *__string2, __re_idx_t __length2, + __re_idx_t __start, regoff_t __range, + struct re_registers *__regs, + __re_idx_t __stop); + + +/* Like 're_search', but return how many characters in STRING the regexp + in BUFFER matched, starting at position START. */ +extern regoff_t re_match (struct re_pattern_buffer *__buffer, + const char *__string, __re_idx_t __length, + __re_idx_t __start, struct re_registers *__regs); + + +/* Relates to 're_match' as 're_search_2' relates to 're_search'. */ +extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, + const char *__string1, __re_idx_t __length1, + const char *__string2, __re_idx_t __length2, + __re_idx_t __start, struct re_registers *__regs, + __re_idx_t __stop); + + +/* Set REGS to hold NUM_REGS registers, storing them in STARTS and + ENDS. Subsequent matches using BUFFER and REGS will use this memory + for recording register information. STARTS and ENDS must be + allocated with malloc, and must each be at least 'NUM_REGS * sizeof + (regoff_t)' bytes long. + + If NUM_REGS == 0, then subsequent matches should allocate their own + register data. + + Unless this function is called, the first search or match using + BUFFER will allocate its own register data, without + freeing the old data. */ +extern void re_set_registers (struct re_pattern_buffer *__buffer, + struct re_registers *__regs, + __re_size_t __num_regs, + regoff_t *__starts, regoff_t *__ends); +#endif /* Use GNU */ + +#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD) +# ifndef _CRAY +/* 4.2 bsd compatibility. */ +extern char *re_comp (const char *); +extern int re_exec (const char *); +# endif +#endif + +/* GCC 2.95 and later have "__restrict"; C99 compilers have + "restrict", and "configure" may have defined "restrict". + Other compilers use __restrict, __restrict__, and _Restrict, and + 'configure' might #define 'restrict' to those words, so pick a + different name. */ +#ifndef _Restrict_ +# if 199901L <= __STDC_VERSION__ +# define _Restrict_ restrict +# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) +# define _Restrict_ __restrict +# else +# define _Restrict_ +# endif +#endif +/* gcc 3.1 and up support the [restrict] syntax. Don't trust + sys/cdefs.h's definition of __restrict_arr, though, as it + mishandles gcc -ansi -pedantic. */ +#ifndef _Restrict_arr_ +# if ((199901L <= __STDC_VERSION__ \ + || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ + && !defined __STRICT_ANSI__)) \ + && !defined __GNUG__) +# define _Restrict_arr_ _Restrict_ +# else +# define _Restrict_arr_ +# endif +#endif + +/* POSIX compatibility. */ +extern int regcomp (regex_t *_Restrict_ __preg, + const char *_Restrict_ __pattern, + int __cflags); + +extern int regexec (const regex_t *_Restrict_ __preg, + const char *_Restrict_ __string, size_t __nmatch, + regmatch_t __pmatch[_Restrict_arr_], + int __eflags); + +extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, + char *_Restrict_ __errbuf, size_t __errbuf_size); + +extern void regfree (regex_t *__preg); + + +#ifdef __cplusplus +} +#endif /* C++ */ + +#endif /* regex.h */ diff --git a/grub-core/gnulib/regex_internal.c b/grub-core/gnulib/regex_internal.c new file mode 100644 index 000000000..899b0ae67 --- /dev/null +++ b/grub-core/gnulib/regex_internal.c @@ -0,0 +1,1741 @@ +/* Extended regular expression matching and search library. + Copyright (C) 2002-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Isamu Hasegawa . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +static void re_string_construct_common (const char *str, Idx len, + re_string_t *pstr, + RE_TRANSLATE_TYPE trans, bool icase, + const re_dfa_t *dfa) internal_function; +static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa, + const re_node_set *nodes, + re_hashval_t hash) internal_function; +static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa, + const re_node_set *nodes, + unsigned int context, + re_hashval_t hash) internal_function; + +/* Functions for string operation. */ + +/* This function allocate the buffers. It is necessary to call + re_string_reconstruct before using the object. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) +{ + reg_errcode_t ret; + Idx init_buf_len; + + /* Ensure at least one character fits into the buffers. */ + if (init_len < dfa->mb_cur_max) + init_len = dfa->mb_cur_max; + init_buf_len = (len + 1 < init_len) ? len + 1: init_len; + re_string_construct_common (str, len, pstr, trans, icase, dfa); + + ret = re_string_realloc_buffers (pstr, init_buf_len); + if (BE (ret != REG_NOERROR, 0)) + return ret; + + pstr->word_char = dfa->word_char; + pstr->word_ops_used = dfa->word_ops_used; + pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str; + pstr->valid_len = (pstr->mbs_allocated || dfa->mb_cur_max > 1) ? 0 : len; + pstr->valid_raw_len = pstr->valid_len; + return REG_NOERROR; +} + +/* This function allocate the buffers, and initialize them. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_string_construct (re_string_t *pstr, const char *str, Idx len, + RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) +{ + reg_errcode_t ret; + memset (pstr, '\0', sizeof (re_string_t)); + re_string_construct_common (str, len, pstr, trans, icase, dfa); + + if (len > 0) + { + ret = re_string_realloc_buffers (pstr, len + 1); + if (BE (ret != REG_NOERROR, 0)) + return ret; + } + pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str; + + if (icase) + { +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + { + while (1) + { + ret = build_wcs_upper_buffer (pstr); + if (BE (ret != REG_NOERROR, 0)) + return ret; + if (pstr->valid_raw_len >= len) + break; + if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max) + break; + ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); + if (BE (ret != REG_NOERROR, 0)) + return ret; + } + } + else +#endif /* RE_ENABLE_I18N */ + build_upper_buffer (pstr); + } + else + { +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + build_wcs_buffer (pstr); + else +#endif /* RE_ENABLE_I18N */ + { + if (trans != NULL) + re_string_translate_buffer (pstr); + else + { + pstr->valid_len = pstr->bufs_len; + pstr->valid_raw_len = pstr->bufs_len; + } + } + } + + return REG_NOERROR; +} + +/* Helper functions for re_string_allocate, and re_string_construct. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) +{ +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + { + wint_t *new_wcs; + + /* Avoid overflow in realloc. */ + const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx)); + if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0)) + return REG_ESPACE; + + new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); + if (BE (new_wcs == NULL, 0)) + return REG_ESPACE; + pstr->wcs = new_wcs; + if (pstr->offsets != NULL) + { + Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len); + if (BE (new_offsets == NULL, 0)) + return REG_ESPACE; + pstr->offsets = new_offsets; + } + } +#endif /* RE_ENABLE_I18N */ + if (pstr->mbs_allocated) + { + unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char, + new_buf_len); + if (BE (new_mbs == NULL, 0)) + return REG_ESPACE; + pstr->mbs = new_mbs; + } + pstr->bufs_len = new_buf_len; + return REG_NOERROR; +} + + +static void +internal_function +re_string_construct_common (const char *str, Idx len, re_string_t *pstr, + RE_TRANSLATE_TYPE trans, bool icase, + const re_dfa_t *dfa) +{ + pstr->raw_mbs = (const unsigned char *) str; + pstr->len = len; + pstr->raw_len = len; + pstr->trans = trans; + pstr->icase = icase; + pstr->mbs_allocated = (trans != NULL || icase); + pstr->mb_cur_max = dfa->mb_cur_max; + pstr->is_utf8 = dfa->is_utf8; + pstr->map_notascii = dfa->map_notascii; + pstr->stop = pstr->len; + pstr->raw_stop = pstr->stop; +} + +#ifdef RE_ENABLE_I18N + +/* Build wide character buffer PSTR->WCS. + If the byte sequence of the string are: + (0), (1), (0), (1), + Then wide character buffer will be: + , WEOF , , WEOF , + We use WEOF for padding, they indicate that the position isn't + a first byte of a multibyte character. + + Note that this function assumes PSTR->VALID_LEN elements are already + built and starts from PSTR->VALID_LEN. */ + +static void +internal_function +build_wcs_buffer (re_string_t *pstr) +{ +#ifdef _LIBC + unsigned char buf[MB_LEN_MAX]; + assert (MB_LEN_MAX >= pstr->mb_cur_max); +#else + unsigned char buf[64]; +#endif + mbstate_t prev_st; + Idx byte_idx, end_idx, remain_len; + size_t mbclen; + + /* Build the buffers from pstr->valid_len to either pstr->len or + pstr->bufs_len. */ + end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len; + for (byte_idx = pstr->valid_len; byte_idx < end_idx;) + { + wchar_t wc; + const char *p; + + remain_len = end_idx - byte_idx; + prev_st = pstr->cur_state; + /* Apply the translation if we need. */ + if (BE (pstr->trans != NULL, 0)) + { + int i, ch; + + for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) + { + ch = pstr->raw_mbs [pstr->raw_mbs_idx + byte_idx + i]; + buf[i] = pstr->mbs[byte_idx + i] = pstr->trans[ch]; + } + p = (const char *) buf; + } + else + p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx; + mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); + if (BE (mbclen == (size_t) -1 || mbclen == 0 + || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0)) + { + /* We treat these cases as a singlebyte character. */ + mbclen = 1; + wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; + if (BE (pstr->trans != NULL, 0)) + wc = pstr->trans[wc]; + pstr->cur_state = prev_st; + } + else if (BE (mbclen == (size_t) -2, 0)) + { + /* The buffer doesn't have enough space, finish to build. */ + pstr->cur_state = prev_st; + break; + } + + /* Write wide character and padding. */ + pstr->wcs[byte_idx++] = wc; + /* Write paddings. */ + for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;) + pstr->wcs[byte_idx++] = WEOF; + } + pstr->valid_len = byte_idx; + pstr->valid_raw_len = byte_idx; +} + +/* Build wide character buffer PSTR->WCS like build_wcs_buffer, + but for REG_ICASE. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +build_wcs_upper_buffer (re_string_t *pstr) +{ + mbstate_t prev_st; + Idx src_idx, byte_idx, end_idx, remain_len; + size_t mbclen; +#ifdef _LIBC + char buf[MB_LEN_MAX]; + assert (MB_LEN_MAX >= pstr->mb_cur_max); +#else + char buf[64]; +#endif + + byte_idx = pstr->valid_len; + end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len; + + /* The following optimization assumes that ASCII characters can be + mapped to wide characters with a simple cast. */ + if (! pstr->map_notascii && pstr->trans == NULL && !pstr->offsets_needed) + { + while (byte_idx < end_idx) + { + wchar_t wc; + + if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]) + && mbsinit (&pstr->cur_state)) + { + /* In case of a singlebyte character. */ + pstr->mbs[byte_idx] + = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]); + /* The next step uses the assumption that wchar_t is encoded + ASCII-safe: all ASCII values can be converted like this. */ + pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; + ++byte_idx; + continue; + } + + remain_len = end_idx - byte_idx; + prev_st = pstr->cur_state; + mbclen = __mbrtowc (&wc, + ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx + + byte_idx), remain_len, &pstr->cur_state); + if (BE (mbclen < (size_t) -2, 1)) + { + wchar_t wcu = wc; + if (iswlower (wc)) + { + size_t mbcdlen; + + wcu = towupper (wc); + mbcdlen = wcrtomb (buf, wcu, &prev_st); + if (BE (mbclen == mbcdlen, 1)) + memcpy (pstr->mbs + byte_idx, buf, mbclen); + else + { + src_idx = byte_idx; + goto offsets_needed; + } + } + else + memcpy (pstr->mbs + byte_idx, + pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx, mbclen); + pstr->wcs[byte_idx++] = wcu; + /* Write paddings. */ + for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;) + pstr->wcs[byte_idx++] = WEOF; + } + else if (mbclen == (size_t) -1 || mbclen == 0 + || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len)) + { + /* It is an invalid character, an incomplete character + at the end of the string, or '\0'. Just use the byte. */ + int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; + pstr->mbs[byte_idx] = ch; + /* And also cast it to wide char. */ + pstr->wcs[byte_idx++] = (wchar_t) ch; + if (BE (mbclen == (size_t) -1, 0)) + pstr->cur_state = prev_st; + } + else + { + /* The buffer doesn't have enough space, finish to build. */ + pstr->cur_state = prev_st; + break; + } + } + pstr->valid_len = byte_idx; + pstr->valid_raw_len = byte_idx; + return REG_NOERROR; + } + else + for (src_idx = pstr->valid_raw_len; byte_idx < end_idx;) + { + wchar_t wc; + const char *p; + offsets_needed: + remain_len = end_idx - byte_idx; + prev_st = pstr->cur_state; + if (BE (pstr->trans != NULL, 0)) + { + int i, ch; + + for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) + { + ch = pstr->raw_mbs [pstr->raw_mbs_idx + src_idx + i]; + buf[i] = pstr->trans[ch]; + } + p = (const char *) buf; + } + else + p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; + mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); + if (BE (mbclen < (size_t) -2, 1)) + { + wchar_t wcu = wc; + if (iswlower (wc)) + { + size_t mbcdlen; + + wcu = towupper (wc); + mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st); + if (BE (mbclen == mbcdlen, 1)) + memcpy (pstr->mbs + byte_idx, buf, mbclen); + else if (mbcdlen != (size_t) -1) + { + size_t i; + + if (byte_idx + mbcdlen > pstr->bufs_len) + { + pstr->cur_state = prev_st; + break; + } + + if (pstr->offsets == NULL) + { + pstr->offsets = re_malloc (Idx, pstr->bufs_len); + + if (pstr->offsets == NULL) + return REG_ESPACE; + } + if (!pstr->offsets_needed) + { + for (i = 0; i < (size_t) byte_idx; ++i) + pstr->offsets[i] = i; + pstr->offsets_needed = 1; + } + + memcpy (pstr->mbs + byte_idx, buf, mbcdlen); + pstr->wcs[byte_idx] = wcu; + pstr->offsets[byte_idx] = src_idx; + for (i = 1; i < mbcdlen; ++i) + { + pstr->offsets[byte_idx + i] + = src_idx + (i < mbclen ? i : mbclen - 1); + pstr->wcs[byte_idx + i] = WEOF; + } + pstr->len += mbcdlen - mbclen; + if (pstr->raw_stop > src_idx) + pstr->stop += mbcdlen - mbclen; + end_idx = (pstr->bufs_len > pstr->len) + ? pstr->len : pstr->bufs_len; + byte_idx += mbcdlen; + src_idx += mbclen; + continue; + } + else + memcpy (pstr->mbs + byte_idx, p, mbclen); + } + else + memcpy (pstr->mbs + byte_idx, p, mbclen); + + if (BE (pstr->offsets_needed != 0, 0)) + { + size_t i; + for (i = 0; i < mbclen; ++i) + pstr->offsets[byte_idx + i] = src_idx + i; + } + src_idx += mbclen; + + pstr->wcs[byte_idx++] = wcu; + /* Write paddings. */ + for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;) + pstr->wcs[byte_idx++] = WEOF; + } + else if (mbclen == (size_t) -1 || mbclen == 0 + || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len)) + { + /* It is an invalid character or '\0'. Just use the byte. */ + int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx]; + + if (BE (pstr->trans != NULL, 0)) + ch = pstr->trans [ch]; + pstr->mbs[byte_idx] = ch; + + if (BE (pstr->offsets_needed != 0, 0)) + pstr->offsets[byte_idx] = src_idx; + ++src_idx; + + /* And also cast it to wide char. */ + pstr->wcs[byte_idx++] = (wchar_t) ch; + if (BE (mbclen == (size_t) -1, 0)) + pstr->cur_state = prev_st; + } + else + { + /* The buffer doesn't have enough space, finish to build. */ + pstr->cur_state = prev_st; + break; + } + } + pstr->valid_len = byte_idx; + pstr->valid_raw_len = src_idx; + return REG_NOERROR; +} + +/* Skip characters until the index becomes greater than NEW_RAW_IDX. + Return the index. */ + +static Idx +internal_function +re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc) +{ + mbstate_t prev_st; + Idx rawbuf_idx; + size_t mbclen; + wint_t wc = WEOF; + + /* Skip the characters which are not necessary to check. */ + for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len; + rawbuf_idx < new_raw_idx;) + { + wchar_t wc2; + Idx remain_len = pstr->raw_len - rawbuf_idx; + prev_st = pstr->cur_state; + mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx, + remain_len, &pstr->cur_state); + if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) + { + /* We treat these cases as a single byte character. */ + if (mbclen == 0 || remain_len == 0) + wc = L'\0'; + else + wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx); + mbclen = 1; + pstr->cur_state = prev_st; + } + else + wc = wc2; + /* Then proceed the next character. */ + rawbuf_idx += mbclen; + } + *last_wc = wc; + return rawbuf_idx; +} +#endif /* RE_ENABLE_I18N */ + +/* Build the buffer PSTR->MBS, and apply the translation if we need. + This function is used in case of REG_ICASE. */ + +static void +internal_function +build_upper_buffer (re_string_t *pstr) +{ + Idx char_idx, end_idx; + end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len; + + for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx) + { + int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx]; + if (BE (pstr->trans != NULL, 0)) + ch = pstr->trans[ch]; + if (islower (ch)) + pstr->mbs[char_idx] = toupper (ch); + else + pstr->mbs[char_idx] = ch; + } + pstr->valid_len = char_idx; + pstr->valid_raw_len = char_idx; +} + +/* Apply TRANS to the buffer in PSTR. */ + +static void +internal_function +re_string_translate_buffer (re_string_t *pstr) +{ + Idx buf_idx, end_idx; + end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len; + + for (buf_idx = pstr->valid_len; buf_idx < end_idx; ++buf_idx) + { + int ch = pstr->raw_mbs[pstr->raw_mbs_idx + buf_idx]; + pstr->mbs[buf_idx] = pstr->trans[ch]; + } + + pstr->valid_len = buf_idx; + pstr->valid_raw_len = buf_idx; +} + +/* This function re-construct the buffers. + Concretely, convert to wide character in case of pstr->mb_cur_max > 1, + convert to upper case in case of REG_ICASE, apply translation. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) +{ + Idx offset; + + if (BE (pstr->raw_mbs_idx <= idx, 0)) + offset = idx - pstr->raw_mbs_idx; + else + { + /* Reset buffer. */ +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); +#endif /* RE_ENABLE_I18N */ + pstr->len = pstr->raw_len; + pstr->stop = pstr->raw_stop; + pstr->valid_len = 0; + pstr->raw_mbs_idx = 0; + pstr->valid_raw_len = 0; + pstr->offsets_needed = 0; + pstr->tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF + : CONTEXT_NEWLINE | CONTEXT_BEGBUF); + if (!pstr->mbs_allocated) + pstr->mbs = (unsigned char *) pstr->raw_mbs; + offset = idx; + } + + if (BE (offset != 0, 1)) + { + /* Should the already checked characters be kept? */ + if (BE (offset < pstr->valid_raw_len, 1)) + { + /* Yes, move them to the front of the buffer. */ +#ifdef RE_ENABLE_I18N + if (BE (pstr->offsets_needed, 0)) + { + Idx low = 0, high = pstr->valid_len, mid; + do + { + mid = (high + low) / 2; + if (pstr->offsets[mid] > offset) + high = mid; + else if (pstr->offsets[mid] < offset) + low = mid + 1; + else + break; + } + while (low < high); + if (pstr->offsets[mid] < offset) + ++mid; + pstr->tip_context = re_string_context_at (pstr, mid - 1, + eflags); + /* This can be quite complicated, so handle specially + only the common and easy case where the character with + different length representation of lower and upper + case is present at or after offset. */ + if (pstr->valid_len > offset + && mid == offset && pstr->offsets[mid] == offset) + { + memmove (pstr->wcs, pstr->wcs + offset, + (pstr->valid_len - offset) * sizeof (wint_t)); + memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); + pstr->valid_len -= offset; + pstr->valid_raw_len -= offset; + for (low = 0; low < pstr->valid_len; low++) + pstr->offsets[low] = pstr->offsets[low + offset] - offset; + } + else + { + /* Otherwise, just find out how long the partial multibyte + character at offset is and fill it with WEOF/255. */ + pstr->len = pstr->raw_len - idx + offset; + pstr->stop = pstr->raw_stop - idx + offset; + pstr->offsets_needed = 0; + while (mid > 0 && pstr->offsets[mid - 1] == offset) + --mid; + while (mid < pstr->valid_len) + if (pstr->wcs[mid] != WEOF) + break; + else + ++mid; + if (mid == pstr->valid_len) + pstr->valid_len = 0; + else + { + pstr->valid_len = pstr->offsets[mid] - offset; + if (pstr->valid_len) + { + for (low = 0; low < pstr->valid_len; ++low) + pstr->wcs[low] = WEOF; + memset (pstr->mbs, 255, pstr->valid_len); + } + } + pstr->valid_raw_len = pstr->valid_len; + } + } + else +#endif + { + pstr->tip_context = re_string_context_at (pstr, offset - 1, + eflags); +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + memmove (pstr->wcs, pstr->wcs + offset, + (pstr->valid_len - offset) * sizeof (wint_t)); +#endif /* RE_ENABLE_I18N */ + if (BE (pstr->mbs_allocated, 0)) + memmove (pstr->mbs, pstr->mbs + offset, + pstr->valid_len - offset); + pstr->valid_len -= offset; + pstr->valid_raw_len -= offset; +#if DEBUG + assert (pstr->valid_len > 0); +#endif + } + } + else + { +#ifdef RE_ENABLE_I18N + /* No, skip all characters until IDX. */ + Idx prev_valid_len = pstr->valid_len; + + if (BE (pstr->offsets_needed, 0)) + { + pstr->len = pstr->raw_len - idx + offset; + pstr->stop = pstr->raw_stop - idx + offset; + pstr->offsets_needed = 0; + } +#endif + pstr->valid_len = 0; +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + { + Idx wcs_idx; + wint_t wc = WEOF; + + if (pstr->is_utf8) + { + const unsigned char *raw, *p, *end; + + /* Special case UTF-8. Multi-byte chars start with any + byte other than 0x80 - 0xbf. */ + raw = pstr->raw_mbs + pstr->raw_mbs_idx; + end = raw + (offset - pstr->mb_cur_max); + if (end < pstr->raw_mbs) + end = pstr->raw_mbs; + p = raw + offset - 1; +#ifdef _LIBC + /* We know the wchar_t encoding is UCS4, so for the simple + case, ASCII characters, skip the conversion step. */ + if (isascii (*p) && BE (pstr->trans == NULL, 1)) + { + memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); + /* pstr->valid_len = 0; */ + wc = (wchar_t) *p; + } + else +#endif + for (; p >= end; --p) + if ((*p & 0xc0) != 0x80) + { + mbstate_t cur_state; + wchar_t wc2; + Idx mlen = raw + pstr->len - p; + unsigned char buf[6]; + size_t mbclen; + + const unsigned char *pp = p; + if (BE (pstr->trans != NULL, 0)) + { + int i = mlen < 6 ? mlen : 6; + while (--i >= 0) + buf[i] = pstr->trans[p[i]]; + pp = buf; + } + /* XXX Don't use mbrtowc, we know which conversion + to use (UTF-8 -> UCS4). */ + memset (&cur_state, 0, sizeof (cur_state)); + mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, + &cur_state); + if (raw + offset - p <= mbclen + && mbclen < (size_t) -2) + { + memset (&pstr->cur_state, '\0', + sizeof (mbstate_t)); + pstr->valid_len = mbclen - (raw + offset - p); + wc = wc2; + } + break; + } + } + + if (wc == WEOF) + pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx; + if (wc == WEOF) + pstr->tip_context + = re_string_context_at (pstr, prev_valid_len - 1, eflags); + else + pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) + && IS_WIDE_WORD_CHAR (wc)) + ? CONTEXT_WORD + : ((IS_WIDE_NEWLINE (wc) + && pstr->newline_anchor) + ? CONTEXT_NEWLINE : 0)); + if (BE (pstr->valid_len, 0)) + { + for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) + pstr->wcs[wcs_idx] = WEOF; + if (pstr->mbs_allocated) + memset (pstr->mbs, 255, pstr->valid_len); + } + pstr->valid_raw_len = pstr->valid_len; + } + else +#endif /* RE_ENABLE_I18N */ + { + int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1]; + pstr->valid_raw_len = 0; + if (pstr->trans) + c = pstr->trans[c]; + pstr->tip_context = (bitset_contain (pstr->word_char, c) + ? CONTEXT_WORD + : ((IS_NEWLINE (c) && pstr->newline_anchor) + ? CONTEXT_NEWLINE : 0)); + } + } + if (!BE (pstr->mbs_allocated, 0)) + pstr->mbs += offset; + } + pstr->raw_mbs_idx = idx; + pstr->len -= offset; + pstr->stop -= offset; + + /* Then build the buffers. */ +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + { + if (pstr->icase) + { + reg_errcode_t ret = build_wcs_upper_buffer (pstr); + if (BE (ret != REG_NOERROR, 0)) + return ret; + } + else + build_wcs_buffer (pstr); + } + else +#endif /* RE_ENABLE_I18N */ + if (BE (pstr->mbs_allocated, 0)) + { + if (pstr->icase) + build_upper_buffer (pstr); + else if (pstr->trans != NULL) + re_string_translate_buffer (pstr); + } + else + pstr->valid_len = pstr->len; + + pstr->cur_idx = 0; + return REG_NOERROR; +} + +static unsigned char +internal_function __attribute__ ((pure)) +re_string_peek_byte_case (const re_string_t *pstr, Idx idx) +{ + int ch; + Idx off; + + /* Handle the common (easiest) cases first. */ + if (BE (!pstr->mbs_allocated, 1)) + return re_string_peek_byte (pstr, idx); + +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1 + && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx)) + return re_string_peek_byte (pstr, idx); +#endif + + off = pstr->cur_idx + idx; +#ifdef RE_ENABLE_I18N + if (pstr->offsets_needed) + off = pstr->offsets[off]; +#endif + + ch = pstr->raw_mbs[pstr->raw_mbs_idx + off]; + +#ifdef RE_ENABLE_I18N + /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I + this function returns CAPITAL LETTER I instead of first byte of + DOTLESS SMALL LETTER I. The latter would confuse the parser, + since peek_byte_case doesn't advance cur_idx in any way. */ + if (pstr->offsets_needed && !isascii (ch)) + return re_string_peek_byte (pstr, idx); +#endif + + return ch; +} + +static unsigned char +internal_function +re_string_fetch_byte_case (re_string_t *pstr) +{ + if (BE (!pstr->mbs_allocated, 1)) + return re_string_fetch_byte (pstr); + +#ifdef RE_ENABLE_I18N + if (pstr->offsets_needed) + { + Idx off; + int ch; + + /* For tr_TR.UTF-8 [[:islower:]] there is + [[: CAPITAL LETTER I WITH DOT lower:]] in mbs. Skip + in that case the whole multi-byte character and return + the original letter. On the other side, with + [[: DOTLESS SMALL LETTER I return [[:I, as doing + anything else would complicate things too much. */ + + if (!re_string_first_byte (pstr, pstr->cur_idx)) + return re_string_fetch_byte (pstr); + + off = pstr->offsets[pstr->cur_idx]; + ch = pstr->raw_mbs[pstr->raw_mbs_idx + off]; + + if (! isascii (ch)) + return re_string_fetch_byte (pstr); + + re_string_skip_bytes (pstr, + re_string_char_size_at (pstr, pstr->cur_idx)); + return ch; + } +#endif + + return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++]; +} + +static void +internal_function +re_string_destruct (re_string_t *pstr) +{ +#ifdef RE_ENABLE_I18N + re_free (pstr->wcs); + re_free (pstr->offsets); +#endif /* RE_ENABLE_I18N */ + if (pstr->mbs_allocated) + re_free (pstr->mbs); +} + +/* Return the context at IDX in INPUT. */ + +static unsigned int +internal_function +re_string_context_at (const re_string_t *input, Idx idx, int eflags) +{ + int c; + if (BE (! REG_VALID_INDEX (idx), 0)) + /* In this case, we use the value stored in input->tip_context, + since we can't know the character in input->mbs[-1] here. */ + return input->tip_context; + if (BE (idx == input->len, 0)) + return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF + : CONTEXT_NEWLINE | CONTEXT_ENDBUF); +#ifdef RE_ENABLE_I18N + if (input->mb_cur_max > 1) + { + wint_t wc; + Idx wc_idx = idx; + while(input->wcs[wc_idx] == WEOF) + { +#ifdef DEBUG + /* It must not happen. */ + assert (REG_VALID_INDEX (wc_idx)); +#endif + --wc_idx; + if (! REG_VALID_INDEX (wc_idx)) + return input->tip_context; + } + wc = input->wcs[wc_idx]; + if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc)) + return CONTEXT_WORD; + return (IS_WIDE_NEWLINE (wc) && input->newline_anchor + ? CONTEXT_NEWLINE : 0); + } + else +#endif + { + c = re_string_byte_at (input, idx); + if (bitset_contain (input->word_char, c)) + return CONTEXT_WORD; + return IS_NEWLINE (c) && input->newline_anchor ? CONTEXT_NEWLINE : 0; + } +} + +/* Functions for set operation. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_alloc (re_node_set *set, Idx size) +{ + set->alloc = size; + set->nelem = 0; + set->elems = re_malloc (Idx, size); + if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0)) + return REG_ESPACE; + return REG_NOERROR; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_init_1 (re_node_set *set, Idx elem) +{ + set->alloc = 1; + set->nelem = 1; + set->elems = re_malloc (Idx, 1); + if (BE (set->elems == NULL, 0)) + { + set->alloc = set->nelem = 0; + return REG_ESPACE; + } + set->elems[0] = elem; + return REG_NOERROR; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2) +{ + set->alloc = 2; + set->elems = re_malloc (Idx, 2); + if (BE (set->elems == NULL, 0)) + return REG_ESPACE; + if (elem1 == elem2) + { + set->nelem = 1; + set->elems[0] = elem1; + } + else + { + set->nelem = 2; + if (elem1 < elem2) + { + set->elems[0] = elem1; + set->elems[1] = elem2; + } + else + { + set->elems[0] = elem2; + set->elems[1] = elem1; + } + } + return REG_NOERROR; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_init_copy (re_node_set *dest, const re_node_set *src) +{ + dest->nelem = src->nelem; + if (src->nelem > 0) + { + dest->alloc = dest->nelem; + dest->elems = re_malloc (Idx, dest->alloc); + if (BE (dest->elems == NULL, 0)) + { + dest->alloc = dest->nelem = 0; + return REG_ESPACE; + } + memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); + } + else + re_node_set_init_empty (dest); + return REG_NOERROR; +} + +/* Calculate the intersection of the sets SRC1 and SRC2. And merge it to + DEST. Return value indicate the error code or REG_NOERROR if succeeded. + Note: We assume dest->elems is NULL, when dest->alloc is 0. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, + const re_node_set *src2) +{ + Idx i1, i2, is, id, delta, sbase; + if (src1->nelem == 0 || src2->nelem == 0) + return REG_NOERROR; + + /* We need dest->nelem + 2 * elems_in_intersection; this is a + conservative estimate. */ + if (src1->nelem + src2->nelem + dest->nelem > dest->alloc) + { + Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; + Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); + if (BE (new_elems == NULL, 0)) + return REG_ESPACE; + dest->elems = new_elems; + dest->alloc = new_alloc; + } + + /* Find the items in the intersection of SRC1 and SRC2, and copy + into the top of DEST those that are not already in DEST itself. */ + sbase = dest->nelem + src1->nelem + src2->nelem; + i1 = src1->nelem - 1; + i2 = src2->nelem - 1; + id = dest->nelem - 1; + for (;;) + { + if (src1->elems[i1] == src2->elems[i2]) + { + /* Try to find the item in DEST. Maybe we could binary search? */ + while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1]) + --id; + + if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1]) + dest->elems[--sbase] = src1->elems[i1]; + + if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2)) + break; + } + + /* Lower the highest of the two items. */ + else if (src1->elems[i1] < src2->elems[i2]) + { + if (! REG_VALID_INDEX (--i2)) + break; + } + else + { + if (! REG_VALID_INDEX (--i1)) + break; + } + } + + id = dest->nelem - 1; + is = dest->nelem + src1->nelem + src2->nelem - 1; + delta = is - sbase + 1; + + /* Now copy. When DELTA becomes zero, the remaining + DEST elements are already in place; this is more or + less the same loop that is in re_node_set_merge. */ + dest->nelem += delta; + if (delta > 0 && REG_VALID_INDEX (id)) + for (;;) + { + if (dest->elems[is] > dest->elems[id]) + { + /* Copy from the top. */ + dest->elems[id + delta--] = dest->elems[is--]; + if (delta == 0) + break; + } + else + { + /* Slide from the bottom. */ + dest->elems[id + delta] = dest->elems[id]; + if (! REG_VALID_INDEX (--id)) + break; + } + } + + /* Copy remaining SRC elements. */ + memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx)); + + return REG_NOERROR; +} + +/* Calculate the union set of the sets SRC1 and SRC2. And store it to + DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_init_union (re_node_set *dest, const re_node_set *src1, + const re_node_set *src2) +{ + Idx i1, i2, id; + if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0) + { + dest->alloc = src1->nelem + src2->nelem; + dest->elems = re_malloc (Idx, dest->alloc); + if (BE (dest->elems == NULL, 0)) + return REG_ESPACE; + } + else + { + if (src1 != NULL && src1->nelem > 0) + return re_node_set_init_copy (dest, src1); + else if (src2 != NULL && src2->nelem > 0) + return re_node_set_init_copy (dest, src2); + else + re_node_set_init_empty (dest); + return REG_NOERROR; + } + for (i1 = i2 = id = 0 ; i1 < src1->nelem && i2 < src2->nelem ;) + { + if (src1->elems[i1] > src2->elems[i2]) + { + dest->elems[id++] = src2->elems[i2++]; + continue; + } + if (src1->elems[i1] == src2->elems[i2]) + ++i2; + dest->elems[id++] = src1->elems[i1++]; + } + if (i1 < src1->nelem) + { + memcpy (dest->elems + id, src1->elems + i1, + (src1->nelem - i1) * sizeof (Idx)); + id += src1->nelem - i1; + } + else if (i2 < src2->nelem) + { + memcpy (dest->elems + id, src2->elems + i2, + (src2->nelem - i2) * sizeof (Idx)); + id += src2->nelem - i2; + } + dest->nelem = id; + return REG_NOERROR; +} + +/* Calculate the union set of the sets DEST and SRC. And store it to + DEST. Return value indicate the error code or REG_NOERROR if succeeded. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +re_node_set_merge (re_node_set *dest, const re_node_set *src) +{ + Idx is, id, sbase, delta; + if (src == NULL || src->nelem == 0) + return REG_NOERROR; + if (dest->alloc < 2 * src->nelem + dest->nelem) + { + Idx new_alloc = 2 * (src->nelem + dest->alloc); + Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc); + if (BE (new_buffer == NULL, 0)) + return REG_ESPACE; + dest->elems = new_buffer; + dest->alloc = new_alloc; + } + + if (BE (dest->nelem == 0, 0)) + { + dest->nelem = src->nelem; + memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); + return REG_NOERROR; + } + + /* Copy into the top of DEST the items of SRC that are not + found in DEST. Maybe we could binary search in DEST? */ + for (sbase = dest->nelem + 2 * src->nelem, + is = src->nelem - 1, id = dest->nelem - 1; + REG_VALID_INDEX (is) && REG_VALID_INDEX (id); ) + { + if (dest->elems[id] == src->elems[is]) + is--, id--; + else if (dest->elems[id] < src->elems[is]) + dest->elems[--sbase] = src->elems[is--]; + else /* if (dest->elems[id] > src->elems[is]) */ + --id; + } + + if (REG_VALID_INDEX (is)) + { + /* If DEST is exhausted, the remaining items of SRC must be unique. */ + sbase -= is + 1; + memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx)); + } + + id = dest->nelem - 1; + is = dest->nelem + 2 * src->nelem - 1; + delta = is - sbase + 1; + if (delta == 0) + return REG_NOERROR; + + /* Now copy. When DELTA becomes zero, the remaining + DEST elements are already in place. */ + dest->nelem += delta; + for (;;) + { + if (dest->elems[is] > dest->elems[id]) + { + /* Copy from the top. */ + dest->elems[id + delta--] = dest->elems[is--]; + if (delta == 0) + break; + } + else + { + /* Slide from the bottom. */ + dest->elems[id + delta] = dest->elems[id]; + if (! REG_VALID_INDEX (--id)) + { + /* Copy remaining SRC elements. */ + memcpy (dest->elems, dest->elems + sbase, + delta * sizeof (Idx)); + break; + } + } + } + + return REG_NOERROR; +} + +/* Insert the new element ELEM to the re_node_set* SET. + SET should not already have ELEM. + Return true if successful. */ + +static bool +internal_function __attribute_warn_unused_result__ +re_node_set_insert (re_node_set *set, Idx elem) +{ + Idx idx; + /* In case the set is empty. */ + if (set->alloc == 0) + return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1); + + if (BE (set->nelem, 0) == 0) + { + /* We already guaranteed above that set->alloc != 0. */ + set->elems[0] = elem; + ++set->nelem; + return true; + } + + /* Realloc if we need. */ + if (set->alloc == set->nelem) + { + Idx *new_elems; + set->alloc = set->alloc * 2; + new_elems = re_realloc (set->elems, Idx, set->alloc); + if (BE (new_elems == NULL, 0)) + return false; + set->elems = new_elems; + } + + /* Move the elements which follows the new element. Test the + first element separately to skip a check in the inner loop. */ + if (elem < set->elems[0]) + { + idx = 0; + for (idx = set->nelem; idx > 0; idx--) + set->elems[idx] = set->elems[idx - 1]; + } + else + { + for (idx = set->nelem; set->elems[idx - 1] > elem; idx--) + set->elems[idx] = set->elems[idx - 1]; + } + + /* Insert the new element. */ + set->elems[idx] = elem; + ++set->nelem; + return true; +} + +/* Insert the new element ELEM to the re_node_set* SET. + SET should not already have any element greater than or equal to ELEM. + Return true if successful. */ + +static bool +internal_function __attribute_warn_unused_result__ +re_node_set_insert_last (re_node_set *set, Idx elem) +{ + /* Realloc if we need. */ + if (set->alloc == set->nelem) + { + Idx *new_elems; + set->alloc = (set->alloc + 1) * 2; + new_elems = re_realloc (set->elems, Idx, set->alloc); + if (BE (new_elems == NULL, 0)) + return false; + set->elems = new_elems; + } + + /* Insert the new element. */ + set->elems[set->nelem++] = elem; + return true; +} + +/* Compare two node sets SET1 and SET2. + Return true if SET1 and SET2 are equivalent. */ + +static bool +internal_function __attribute__ ((pure)) +re_node_set_compare (const re_node_set *set1, const re_node_set *set2) +{ + Idx i; + if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem) + return false; + for (i = set1->nelem ; REG_VALID_INDEX (--i) ; ) + if (set1->elems[i] != set2->elems[i]) + return false; + return true; +} + +/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */ + +static Idx +internal_function __attribute__ ((pure)) +re_node_set_contains (const re_node_set *set, Idx elem) +{ + __re_size_t idx, right, mid; + if (! REG_VALID_NONZERO_INDEX (set->nelem)) + return 0; + + /* Binary search the element. */ + idx = 0; + right = set->nelem - 1; + while (idx < right) + { + mid = (idx + right) / 2; + if (set->elems[mid] < elem) + idx = mid + 1; + else + right = mid; + } + return set->elems[idx] == elem ? idx + 1 : 0; +} + +static void +internal_function +re_node_set_remove_at (re_node_set *set, Idx idx) +{ + if (idx < 0 || idx >= set->nelem) + return; + --set->nelem; + for (; idx < set->nelem; idx++) + set->elems[idx] = set->elems[idx + 1]; +} + + +/* Add the token TOKEN to dfa->nodes, and return the index of the token. + Or return REG_MISSING if an error occurred. */ + +static Idx +internal_function +re_dfa_add_node (re_dfa_t *dfa, re_token_t token) +{ + if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) + { + size_t new_nodes_alloc = dfa->nodes_alloc * 2; + Idx *new_nexts, *new_indices; + re_node_set *new_edests, *new_eclosures; + re_token_t *new_nodes; + + /* Avoid overflows in realloc. */ + const size_t max_object_size = MAX (sizeof (re_token_t), + MAX (sizeof (re_node_set), + sizeof (Idx))); + if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0)) + return REG_MISSING; + + new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); + if (BE (new_nodes == NULL, 0)) + return REG_MISSING; + dfa->nodes = new_nodes; + new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); + new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); + new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); + new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); + if (BE (new_nexts == NULL || new_indices == NULL + || new_edests == NULL || new_eclosures == NULL, 0)) + return REG_MISSING; + dfa->nexts = new_nexts; + dfa->org_indices = new_indices; + dfa->edests = new_edests; + dfa->eclosures = new_eclosures; + dfa->nodes_alloc = new_nodes_alloc; + } + dfa->nodes[dfa->nodes_len] = token; + dfa->nodes[dfa->nodes_len].constraint = 0; +#ifdef RE_ENABLE_I18N + dfa->nodes[dfa->nodes_len].accept_mb = + ((token.type == OP_PERIOD && dfa->mb_cur_max > 1) + || token.type == COMPLEX_BRACKET); +#endif + dfa->nexts[dfa->nodes_len] = REG_MISSING; + re_node_set_init_empty (dfa->edests + dfa->nodes_len); + re_node_set_init_empty (dfa->eclosures + dfa->nodes_len); + return dfa->nodes_len++; +} + +static re_hashval_t +internal_function +calc_state_hash (const re_node_set *nodes, unsigned int context) +{ + re_hashval_t hash = nodes->nelem + context; + Idx i; + for (i = 0 ; i < nodes->nelem ; i++) + hash += nodes->elems[i]; + return hash; +} + +/* Search for the state whose node_set is equivalent to NODES. + Return the pointer to the state, if we found it in the DFA. + Otherwise create the new one and return it. In case of an error + return NULL and set the error code in ERR. + Note: - We assume NULL as the invalid state, then it is possible that + return value is NULL and ERR is REG_NOERROR. + - We never return non-NULL value in case of any errors, it is for + optimization. */ + +static re_dfastate_t * +internal_function __attribute_warn_unused_result__ +re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, + const re_node_set *nodes) +{ + re_hashval_t hash; + re_dfastate_t *new_state; + struct re_state_table_entry *spot; + Idx i; +#ifdef lint + /* Suppress bogus uninitialized-variable warnings. */ + *err = REG_NOERROR; +#endif + if (BE (nodes->nelem == 0, 0)) + { + *err = REG_NOERROR; + return NULL; + } + hash = calc_state_hash (nodes, 0); + spot = dfa->state_table + (hash & dfa->state_hash_mask); + + for (i = 0 ; i < spot->num ; i++) + { + re_dfastate_t *state = spot->array[i]; + if (hash != state->hash) + continue; + if (re_node_set_compare (&state->nodes, nodes)) + return state; + } + + /* There are no appropriate state in the dfa, create the new one. */ + new_state = create_ci_newstate (dfa, nodes, hash); + if (BE (new_state == NULL, 0)) + *err = REG_ESPACE; + + return new_state; +} + +/* Search for the state whose node_set is equivalent to NODES and + whose context is equivalent to CONTEXT. + Return the pointer to the state, if we found it in the DFA. + Otherwise create the new one and return it. In case of an error + return NULL and set the error code in ERR. + Note: - We assume NULL as the invalid state, then it is possible that + return value is NULL and ERR is REG_NOERROR. + - We never return non-NULL value in case of any errors, it is for + optimization. */ + +static re_dfastate_t * +internal_function __attribute_warn_unused_result__ +re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, + const re_node_set *nodes, unsigned int context) +{ + re_hashval_t hash; + re_dfastate_t *new_state; + struct re_state_table_entry *spot; + Idx i; +#ifdef lint + /* Suppress bogus uninitialized-variable warnings. */ + *err = REG_NOERROR; +#endif + if (nodes->nelem == 0) + { + *err = REG_NOERROR; + return NULL; + } + hash = calc_state_hash (nodes, context); + spot = dfa->state_table + (hash & dfa->state_hash_mask); + + for (i = 0 ; i < spot->num ; i++) + { + re_dfastate_t *state = spot->array[i]; + if (state->hash == hash + && state->context == context + && re_node_set_compare (state->entrance_nodes, nodes)) + return state; + } + /* There are no appropriate state in 'dfa', create the new one. */ + new_state = create_cd_newstate (dfa, nodes, context, hash); + if (BE (new_state == NULL, 0)) + *err = REG_ESPACE; + + return new_state; +} + +/* Finish initialization of the new state NEWSTATE, and using its hash value + HASH put in the appropriate bucket of DFA's state table. Return value + indicates the error code if failed. */ + +static reg_errcode_t +__attribute_warn_unused_result__ +register_state (const re_dfa_t *dfa, re_dfastate_t *newstate, + re_hashval_t hash) +{ + struct re_state_table_entry *spot; + reg_errcode_t err; + Idx i; + + newstate->hash = hash; + err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem); + if (BE (err != REG_NOERROR, 0)) + return REG_ESPACE; + for (i = 0; i < newstate->nodes.nelem; i++) + { + Idx elem = newstate->nodes.elems[i]; + if (!IS_EPSILON_NODE (dfa->nodes[elem].type)) + if (! re_node_set_insert_last (&newstate->non_eps_nodes, elem)) + return REG_ESPACE; + } + + spot = dfa->state_table + (hash & dfa->state_hash_mask); + if (BE (spot->alloc <= spot->num, 0)) + { + Idx new_alloc = 2 * spot->num + 2; + re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *, + new_alloc); + if (BE (new_array == NULL, 0)) + return REG_ESPACE; + spot->array = new_array; + spot->alloc = new_alloc; + } + spot->array[spot->num++] = newstate; + return REG_NOERROR; +} + +static void +free_state (re_dfastate_t *state) +{ + re_node_set_free (&state->non_eps_nodes); + re_node_set_free (&state->inveclosure); + if (state->entrance_nodes != &state->nodes) + { + re_node_set_free (state->entrance_nodes); + re_free (state->entrance_nodes); + } + re_node_set_free (&state->nodes); + re_free (state->word_trtable); + re_free (state->trtable); + re_free (state); +} + +/* Create the new state which is independent of contexts. + Return the new state if succeeded, otherwise return NULL. */ + +static re_dfastate_t * +internal_function __attribute_warn_unused_result__ +create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, + re_hashval_t hash) +{ + Idx i; + reg_errcode_t err; + re_dfastate_t *newstate; + + newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); + if (BE (newstate == NULL, 0)) + return NULL; + err = re_node_set_init_copy (&newstate->nodes, nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_free (newstate); + return NULL; + } + + newstate->entrance_nodes = &newstate->nodes; + for (i = 0 ; i < nodes->nelem ; i++) + { + re_token_t *node = dfa->nodes + nodes->elems[i]; + re_token_type_t type = node->type; + if (type == CHARACTER && !node->constraint) + continue; +#ifdef RE_ENABLE_I18N + newstate->accept_mb |= node->accept_mb; +#endif /* RE_ENABLE_I18N */ + + /* If the state has the halt node, the state is a halt state. */ + if (type == END_OF_RE) + newstate->halt = 1; + else if (type == OP_BACK_REF) + newstate->has_backref = 1; + else if (type == ANCHOR || node->constraint) + newstate->has_constraint = 1; + } + err = register_state (dfa, newstate, hash); + if (BE (err != REG_NOERROR, 0)) + { + free_state (newstate); + newstate = NULL; + } + return newstate; +} + +/* Create the new state which is depend on the context CONTEXT. + Return the new state if succeeded, otherwise return NULL. */ + +static re_dfastate_t * +internal_function __attribute_warn_unused_result__ +create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, + unsigned int context, re_hashval_t hash) +{ + Idx i, nctx_nodes = 0; + reg_errcode_t err; + re_dfastate_t *newstate; + + newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); + if (BE (newstate == NULL, 0)) + return NULL; + err = re_node_set_init_copy (&newstate->nodes, nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_free (newstate); + return NULL; + } + + newstate->context = context; + newstate->entrance_nodes = &newstate->nodes; + + for (i = 0 ; i < nodes->nelem ; i++) + { + re_token_t *node = dfa->nodes + nodes->elems[i]; + re_token_type_t type = node->type; + unsigned int constraint = node->constraint; + + if (type == CHARACTER && !constraint) + continue; +#ifdef RE_ENABLE_I18N + newstate->accept_mb |= node->accept_mb; +#endif /* RE_ENABLE_I18N */ + + /* If the state has the halt node, the state is a halt state. */ + if (type == END_OF_RE) + newstate->halt = 1; + else if (type == OP_BACK_REF) + newstate->has_backref = 1; + + if (constraint) + { + if (newstate->entrance_nodes == &newstate->nodes) + { + newstate->entrance_nodes = re_malloc (re_node_set, 1); + if (BE (newstate->entrance_nodes == NULL, 0)) + { + free_state (newstate); + return NULL; + } + if (re_node_set_init_copy (newstate->entrance_nodes, nodes) + != REG_NOERROR) + return NULL; + nctx_nodes = 0; + newstate->has_constraint = 1; + } + + if (NOT_SATISFY_PREV_CONSTRAINT (constraint,context)) + { + re_node_set_remove_at (&newstate->nodes, i - nctx_nodes); + ++nctx_nodes; + } + } + } + err = register_state (dfa, newstate, hash); + if (BE (err != REG_NOERROR, 0)) + { + free_state (newstate); + newstate = NULL; + } + return newstate; +} diff --git a/grub-core/gnulib/regex_internal.h b/grub-core/gnulib/regex_internal.h new file mode 100644 index 000000000..c467b2907 --- /dev/null +++ b/grub-core/gnulib/regex_internal.h @@ -0,0 +1,873 @@ +/* Extended regular expression matching and search library. + Copyright (C) 2002-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Isamu Hasegawa . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _REGEX_INTERNAL_H +#define _REGEX_INTERNAL_H 1 + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#if defined _LIBC +# include +#else +# define __libc_lock_init(NAME) do { } while (0) +# define __libc_lock_lock(NAME) do { } while (0) +# define __libc_lock_unlock(NAME) do { } while (0) +#endif + +/* In case that the system doesn't have isblank(). */ +#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK)) +# define isblank(ch) ((ch) == ' ' || (ch) == '\t') +#endif + +#ifdef _LIBC +# ifndef _RE_DEFINE_LOCALE_FUNCTIONS +# define _RE_DEFINE_LOCALE_FUNCTIONS 1 +# include +# include +# include +# endif +#endif + +/* This is for other GNU distributions with internationalized messages. */ +#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC +# include +# ifdef _LIBC +# undef gettext +# define gettext(msgid) \ + __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) +# endif +#else +# define gettext(msgid) (msgid) +#endif + +#ifndef gettext_noop +/* This define is so xgettext can find the internationalizable + strings. */ +# define gettext_noop(String) String +#endif + +#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC +# define RE_ENABLE_I18N +#endif + +#if __GNUC__ >= 3 +# define BE(expr, val) __builtin_expect (expr, val) +#else +# define BE(expr, val) (expr) +#endif + +/* Number of ASCII characters. */ +#define ASCII_CHARS 0x80 + +/* Number of single byte characters. */ +#define SBC_MAX (UCHAR_MAX + 1) + +#define COLL_ELEM_LEN_MAX 8 + +/* The character which represents newline. */ +#define NEWLINE_CHAR '\n' +#define WIDE_NEWLINE_CHAR L'\n' + +/* Rename to standard API for using out of glibc. */ +#ifndef _LIBC +# undef __wctype +# undef __iswctype +# define __wctype wctype +# define __iswctype iswctype +# define __btowc btowc +# define __mbrtowc mbrtowc +# define __wcrtomb wcrtomb +# define __regfree regfree +# define attribute_hidden +#endif /* not _LIBC */ + +#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) +# define __attribute__(arg) +#endif + +typedef __re_idx_t Idx; +#ifdef _REGEX_LARGE_OFFSETS +# define IDX_MAX (SIZE_MAX - 2) +#else +# define IDX_MAX INT_MAX +#endif + +/* Special return value for failure to match. */ +#define REG_MISSING ((Idx) -1) + +/* Special return value for internal error. */ +#define REG_ERROR ((Idx) -2) + +/* Test whether N is a valid index, and is not one of the above. */ +#ifdef _REGEX_LARGE_OFFSETS +# define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR) +#else +# define REG_VALID_INDEX(n) (0 <= (n)) +#endif + +/* Test whether N is a valid nonzero index. */ +#ifdef _REGEX_LARGE_OFFSETS +# define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1)) +#else +# define REG_VALID_NONZERO_INDEX(n) (0 < (n)) +#endif + +/* A hash value, suitable for computing hash tables. */ +typedef __re_size_t re_hashval_t; + +/* An integer used to represent a set of bits. It must be unsigned, + and must be at least as wide as unsigned int. */ +typedef unsigned long int bitset_word_t; +/* All bits set in a bitset_word_t. */ +#define BITSET_WORD_MAX ULONG_MAX + +/* Number of bits in a bitset_word_t. For portability to hosts with + padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)'; + instead, deduce it directly from BITSET_WORD_MAX. Avoid + greater-than-32-bit integers and unconditional shifts by more than + 31 bits, as they're not portable. */ +#if BITSET_WORD_MAX == 0xffffffffUL +# define BITSET_WORD_BITS 32 +#elif BITSET_WORD_MAX >> 31 >> 4 == 1 +# define BITSET_WORD_BITS 36 +#elif BITSET_WORD_MAX >> 31 >> 16 == 1 +# define BITSET_WORD_BITS 48 +#elif BITSET_WORD_MAX >> 31 >> 28 == 1 +# define BITSET_WORD_BITS 60 +#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1 +# define BITSET_WORD_BITS 64 +#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1 +# define BITSET_WORD_BITS 72 +#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1 +# define BITSET_WORD_BITS 128 +#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1 +# define BITSET_WORD_BITS 256 +#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1 +# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */ +# if BITSET_WORD_BITS <= SBC_MAX +# error "Invalid SBC_MAX" +# endif +#else +# error "Add case for new bitset_word_t size" +#endif + +/* Number of bitset_word_t values in a bitset_t. */ +#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) + +typedef bitset_word_t bitset_t[BITSET_WORDS]; +typedef bitset_word_t *re_bitset_ptr_t; +typedef const bitset_word_t *re_const_bitset_ptr_t; + +#define PREV_WORD_CONSTRAINT 0x0001 +#define PREV_NOTWORD_CONSTRAINT 0x0002 +#define NEXT_WORD_CONSTRAINT 0x0004 +#define NEXT_NOTWORD_CONSTRAINT 0x0008 +#define PREV_NEWLINE_CONSTRAINT 0x0010 +#define NEXT_NEWLINE_CONSTRAINT 0x0020 +#define PREV_BEGBUF_CONSTRAINT 0x0040 +#define NEXT_ENDBUF_CONSTRAINT 0x0080 +#define WORD_DELIM_CONSTRAINT 0x0100 +#define NOT_WORD_DELIM_CONSTRAINT 0x0200 + +typedef enum +{ + INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT, + WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT, + WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT, + INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT, + LINE_FIRST = PREV_NEWLINE_CONSTRAINT, + LINE_LAST = NEXT_NEWLINE_CONSTRAINT, + BUF_FIRST = PREV_BEGBUF_CONSTRAINT, + BUF_LAST = NEXT_ENDBUF_CONSTRAINT, + WORD_DELIM = WORD_DELIM_CONSTRAINT, + NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT +} re_context_type; + +typedef struct +{ + Idx alloc; + Idx nelem; + Idx *elems; +} re_node_set; + +typedef enum +{ + NON_TYPE = 0, + + /* Node type, These are used by token, node, tree. */ + CHARACTER = 1, + END_OF_RE = 2, + SIMPLE_BRACKET = 3, + OP_BACK_REF = 4, + OP_PERIOD = 5, +#ifdef RE_ENABLE_I18N + COMPLEX_BRACKET = 6, + OP_UTF8_PERIOD = 7, +#endif /* RE_ENABLE_I18N */ + + /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used + when the debugger shows values of this enum type. */ +#define EPSILON_BIT 8 + OP_OPEN_SUBEXP = EPSILON_BIT | 0, + OP_CLOSE_SUBEXP = EPSILON_BIT | 1, + OP_ALT = EPSILON_BIT | 2, + OP_DUP_ASTERISK = EPSILON_BIT | 3, + ANCHOR = EPSILON_BIT | 4, + + /* Tree type, these are used only by tree. */ + CONCAT = 16, + SUBEXP = 17, + + /* Token type, these are used only by token. */ + OP_DUP_PLUS = 18, + OP_DUP_QUESTION, + OP_OPEN_BRACKET, + OP_CLOSE_BRACKET, + OP_CHARSET_RANGE, + OP_OPEN_DUP_NUM, + OP_CLOSE_DUP_NUM, + OP_NON_MATCH_LIST, + OP_OPEN_COLL_ELEM, + OP_CLOSE_COLL_ELEM, + OP_OPEN_EQUIV_CLASS, + OP_CLOSE_EQUIV_CLASS, + OP_OPEN_CHAR_CLASS, + OP_CLOSE_CHAR_CLASS, + OP_WORD, + OP_NOTWORD, + OP_SPACE, + OP_NOTSPACE, + BACK_SLASH + +} re_token_type_t; + +#ifdef RE_ENABLE_I18N +typedef struct +{ + /* Multibyte characters. */ + wchar_t *mbchars; + + /* Collating symbols. */ +# ifdef _LIBC + int32_t *coll_syms; +# endif + + /* Equivalence classes. */ +# ifdef _LIBC + int32_t *equiv_classes; +# endif + + /* Range expressions. */ +# ifdef _LIBC + uint32_t *range_starts; + uint32_t *range_ends; +# else /* not _LIBC */ + wchar_t *range_starts; + wchar_t *range_ends; +# endif /* not _LIBC */ + + /* Character classes. */ + wctype_t *char_classes; + + /* If this character set is the non-matching list. */ + unsigned int non_match : 1; + + /* # of multibyte characters. */ + Idx nmbchars; + + /* # of collating symbols. */ + Idx ncoll_syms; + + /* # of equivalence classes. */ + Idx nequiv_classes; + + /* # of range expressions. */ + Idx nranges; + + /* # of character classes. */ + Idx nchar_classes; +} re_charset_t; +#endif /* RE_ENABLE_I18N */ + +typedef struct +{ + union + { + unsigned char c; /* for CHARACTER */ + re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ +#ifdef RE_ENABLE_I18N + re_charset_t *mbcset; /* for COMPLEX_BRACKET */ +#endif /* RE_ENABLE_I18N */ + Idx idx; /* for BACK_REF */ + re_context_type ctx_type; /* for ANCHOR */ + } opr; +#if __GNUC__ >= 2 && !defined __STRICT_ANSI__ + re_token_type_t type : 8; +#else + re_token_type_t type; +#endif + unsigned int constraint : 10; /* context constraint */ + unsigned int duplicated : 1; + unsigned int opt_subexp : 1; +#ifdef RE_ENABLE_I18N + unsigned int accept_mb : 1; + /* These 2 bits can be moved into the union if needed (e.g. if running out + of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */ + unsigned int mb_partial : 1; +#endif + unsigned int word_char : 1; +} re_token_t; + +#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT) + +struct re_string_t +{ + /* Indicate the raw buffer which is the original string passed as an + argument of regexec(), re_search(), etc.. */ + const unsigned char *raw_mbs; + /* Store the multibyte string. In case of "case insensitive mode" like + REG_ICASE, upper cases of the string are stored, otherwise MBS points + the same address that RAW_MBS points. */ + unsigned char *mbs; +#ifdef RE_ENABLE_I18N + /* Store the wide character string which is corresponding to MBS. */ + wint_t *wcs; + Idx *offsets; + mbstate_t cur_state; +#endif + /* Index in RAW_MBS. Each character mbs[i] corresponds to + raw_mbs[raw_mbs_idx + i]. */ + Idx raw_mbs_idx; + /* The length of the valid characters in the buffers. */ + Idx valid_len; + /* The corresponding number of bytes in raw_mbs array. */ + Idx valid_raw_len; + /* The length of the buffers MBS and WCS. */ + Idx bufs_len; + /* The index in MBS, which is updated by re_string_fetch_byte. */ + Idx cur_idx; + /* length of RAW_MBS array. */ + Idx raw_len; + /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */ + Idx len; + /* End of the buffer may be shorter than its length in the cases such + as re_match_2, re_search_2. Then, we use STOP for end of the buffer + instead of LEN. */ + Idx raw_stop; + /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */ + Idx stop; + + /* The context of mbs[0]. We store the context independently, since + the context of mbs[0] may be different from raw_mbs[0], which is + the beginning of the input string. */ + unsigned int tip_context; + /* The translation passed as a part of an argument of re_compile_pattern. */ + RE_TRANSLATE_TYPE trans; + /* Copy of re_dfa_t's word_char. */ + re_const_bitset_ptr_t word_char; + /* true if REG_ICASE. */ + unsigned char icase; + unsigned char is_utf8; + unsigned char map_notascii; + unsigned char mbs_allocated; + unsigned char offsets_needed; + unsigned char newline_anchor; + unsigned char word_ops_used; + int mb_cur_max; +}; +typedef struct re_string_t re_string_t; + + +struct re_dfa_t; +typedef struct re_dfa_t re_dfa_t; + +#ifndef _LIBC +# define internal_function +#endif + +#ifndef NOT_IN_libc +static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr, + Idx new_buf_len) + internal_function; +# ifdef RE_ENABLE_I18N +static void build_wcs_buffer (re_string_t *pstr) internal_function; +static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) + internal_function; +# endif /* RE_ENABLE_I18N */ +static void build_upper_buffer (re_string_t *pstr) internal_function; +static void re_string_translate_buffer (re_string_t *pstr) internal_function; +static unsigned int re_string_context_at (const re_string_t *input, Idx idx, + int eflags) + internal_function __attribute__ ((pure)); +#endif +#define re_string_peek_byte(pstr, offset) \ + ((pstr)->mbs[(pstr)->cur_idx + offset]) +#define re_string_fetch_byte(pstr) \ + ((pstr)->mbs[(pstr)->cur_idx++]) +#define re_string_first_byte(pstr, idx) \ + ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF) +#define re_string_is_single_byte_char(pstr, idx) \ + ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \ + || (pstr)->wcs[(idx) + 1] != WEOF)) +#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx) +#define re_string_cur_idx(pstr) ((pstr)->cur_idx) +#define re_string_get_buffer(pstr) ((pstr)->mbs) +#define re_string_length(pstr) ((pstr)->len) +#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx]) +#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) +#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) + +#if defined _LIBC || HAVE_ALLOCA +# include +#endif + +#ifndef _LIBC +# if HAVE_ALLOCA +/* The OS usually guarantees only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + allocate anything larger than 4096 bytes. Also care for the possibility + of a few compiler-allocated temporary stack slots. */ +# define __libc_use_alloca(n) ((n) < 4032) +# else +/* alloca is implemented with malloc, so just use malloc. */ +# define __libc_use_alloca(n) 0 +# undef alloca +# define alloca(n) malloc (n) +# endif +#endif + +#ifdef _LIBC +# define MALLOC_0_IS_NONNULL 1 +#elif !defined MALLOC_0_IS_NONNULL +# define MALLOC_0_IS_NONNULL 0 +#endif + +#ifndef MAX +# define MAX(a,b) ((a) < (b) ? (b) : (a)) +#endif +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t))) +#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t))) +#define re_free(p) free (p) + +struct bin_tree_t +{ + struct bin_tree_t *parent; + struct bin_tree_t *left; + struct bin_tree_t *right; + struct bin_tree_t *first; + struct bin_tree_t *next; + + re_token_t token; + + /* 'node_idx' is the index in dfa->nodes, if 'type' == 0. + Otherwise 'type' indicate the type of this node. */ + Idx node_idx; +}; +typedef struct bin_tree_t bin_tree_t; + +#define BIN_TREE_STORAGE_SIZE \ + ((1024 - sizeof (void *)) / sizeof (bin_tree_t)) + +struct bin_tree_storage_t +{ + struct bin_tree_storage_t *next; + bin_tree_t data[BIN_TREE_STORAGE_SIZE]; +}; +typedef struct bin_tree_storage_t bin_tree_storage_t; + +#define CONTEXT_WORD 1 +#define CONTEXT_NEWLINE (CONTEXT_WORD << 1) +#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1) +#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1) + +#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD) +#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE) +#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF) +#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF) +#define IS_ORDINARY_CONTEXT(c) ((c) == 0) + +#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') +#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) +#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') +#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) + +#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ + ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \ + || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \ + || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\ + || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context))) + +#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \ + ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \ + || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \ + || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \ + || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context))) + +struct re_dfastate_t +{ + re_hashval_t hash; + re_node_set nodes; + re_node_set non_eps_nodes; + re_node_set inveclosure; + re_node_set *entrance_nodes; + struct re_dfastate_t **trtable, **word_trtable; + unsigned int context : 4; + unsigned int halt : 1; + /* If this state can accept "multi byte". + Note that we refer to multibyte characters, and multi character + collating elements as "multi byte". */ + unsigned int accept_mb : 1; + /* If this state has backreference node(s). */ + unsigned int has_backref : 1; + unsigned int has_constraint : 1; +}; +typedef struct re_dfastate_t re_dfastate_t; + +struct re_state_table_entry +{ + Idx num; + Idx alloc; + re_dfastate_t **array; +}; + +/* Array type used in re_sub_match_last_t and re_sub_match_top_t. */ + +typedef struct +{ + Idx next_idx; + Idx alloc; + re_dfastate_t **array; +} state_array_t; + +/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */ + +typedef struct +{ + Idx node; + Idx str_idx; /* The position NODE match at. */ + state_array_t path; +} re_sub_match_last_t; + +/* Store information about the node NODE whose type is OP_OPEN_SUBEXP. + And information about the node, whose type is OP_CLOSE_SUBEXP, + corresponding to NODE is stored in LASTS. */ + +typedef struct +{ + Idx str_idx; + Idx node; + state_array_t *path; + Idx alasts; /* Allocation size of LASTS. */ + Idx nlasts; /* The number of LASTS. */ + re_sub_match_last_t **lasts; +} re_sub_match_top_t; + +struct re_backref_cache_entry +{ + Idx node; + Idx str_idx; + Idx subexp_from; + Idx subexp_to; + char more; + char unused; + unsigned short int eps_reachable_subexps_map; +}; + +typedef struct +{ + /* The string object corresponding to the input string. */ + re_string_t input; +#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) + const re_dfa_t *const dfa; +#else + const re_dfa_t *dfa; +#endif + /* EFLAGS of the argument of regexec. */ + int eflags; + /* Where the matching ends. */ + Idx match_last; + Idx last_node; + /* The state log used by the matcher. */ + re_dfastate_t **state_log; + Idx state_log_top; + /* Back reference cache. */ + Idx nbkref_ents; + Idx abkref_ents; + struct re_backref_cache_entry *bkref_ents; + int max_mb_elem_len; + Idx nsub_tops; + Idx asub_tops; + re_sub_match_top_t **sub_tops; +} re_match_context_t; + +typedef struct +{ + re_dfastate_t **sifted_states; + re_dfastate_t **limited_states; + Idx last_node; + Idx last_str_idx; + re_node_set limits; +} re_sift_context_t; + +struct re_fail_stack_ent_t +{ + Idx idx; + Idx node; + regmatch_t *regs; + re_node_set eps_via_nodes; +}; + +struct re_fail_stack_t +{ + Idx num; + Idx alloc; + struct re_fail_stack_ent_t *stack; +}; + +struct re_dfa_t +{ + re_token_t *nodes; + size_t nodes_alloc; + size_t nodes_len; + Idx *nexts; + Idx *org_indices; + re_node_set *edests; + re_node_set *eclosures; + re_node_set *inveclosures; + struct re_state_table_entry *state_table; + re_dfastate_t *init_state; + re_dfastate_t *init_state_word; + re_dfastate_t *init_state_nl; + re_dfastate_t *init_state_begbuf; + bin_tree_t *str_tree; + bin_tree_storage_t *str_tree_storage; + re_bitset_ptr_t sb_char; + int str_tree_storage_idx; + + /* number of subexpressions 're_nsub' is in regex_t. */ + re_hashval_t state_hash_mask; + Idx init_node; + Idx nbackref; /* The number of backreference in this dfa. */ + + /* Bitmap expressing which backreference is used. */ + bitset_word_t used_bkref_map; + bitset_word_t completed_bkref_map; + + unsigned int has_plural_match : 1; + /* If this dfa has "multibyte node", which is a backreference or + a node which can accept multibyte character or multi character + collating element. */ + unsigned int has_mb_node : 1; + unsigned int is_utf8 : 1; + unsigned int map_notascii : 1; + unsigned int word_ops_used : 1; + int mb_cur_max; + bitset_t word_char; + reg_syntax_t syntax; + Idx *subexp_map; +#ifdef DEBUG + char* re_str; +#endif +#ifdef _LIBC + __libc_lock_define (, lock) +#endif +}; + +#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set)) +#define re_node_set_remove(set,id) \ + (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1)) +#define re_node_set_empty(p) ((p)->nelem = 0) +#define re_node_set_free(set) re_free ((set)->elems) + + +typedef enum +{ + SB_CHAR, + MB_CHAR, + EQUIV_CLASS, + COLL_SYM, + CHAR_CLASS +} bracket_elem_type; + +typedef struct +{ + bracket_elem_type type; + union + { + unsigned char ch; + unsigned char *name; + wchar_t wch; + } opr; +} bracket_elem_t; + + +/* Functions for bitset_t operation. */ + +static void +bitset_set (bitset_t set, Idx i) +{ + set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; +} + +static void +bitset_clear (bitset_t set, Idx i) +{ + set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); +} + +static bool +bitset_contain (const bitset_t set, Idx i) +{ + return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; +} + +static void +bitset_empty (bitset_t set) +{ + memset (set, '\0', sizeof (bitset_t)); +} + +static void +bitset_set_all (bitset_t set) +{ + memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); + if (SBC_MAX % BITSET_WORD_BITS != 0) + set[BITSET_WORDS - 1] = + ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; +} + +static void +bitset_copy (bitset_t dest, const bitset_t src) +{ + memcpy (dest, src, sizeof (bitset_t)); +} + +static void __attribute__ ((unused)) +bitset_not (bitset_t set) +{ + int bitset_i; + for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i) + set[bitset_i] = ~set[bitset_i]; + if (SBC_MAX % BITSET_WORD_BITS != 0) + set[BITSET_WORDS - 1] = + ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1) + & ~set[BITSET_WORDS - 1]); +} + +static void __attribute__ ((unused)) +bitset_merge (bitset_t dest, const bitset_t src) +{ + int bitset_i; + for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) + dest[bitset_i] |= src[bitset_i]; +} + +static void __attribute__ ((unused)) +bitset_mask (bitset_t dest, const bitset_t src) +{ + int bitset_i; + for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i) + dest[bitset_i] &= src[bitset_i]; +} + +#ifdef RE_ENABLE_I18N +/* Functions for re_string. */ +static int +internal_function __attribute__ ((pure, unused)) +re_string_char_size_at (const re_string_t *pstr, Idx idx) +{ + int byte_idx; + if (pstr->mb_cur_max == 1) + return 1; + for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx) + if (pstr->wcs[idx + byte_idx] != WEOF) + break; + return byte_idx; +} + +static wint_t +internal_function __attribute__ ((pure, unused)) +re_string_wchar_at (const re_string_t *pstr, Idx idx) +{ + if (pstr->mb_cur_max == 1) + return (wint_t) pstr->mbs[idx]; + return (wint_t) pstr->wcs[idx]; +} + +# ifndef NOT_IN_libc +static int +internal_function __attribute__ ((pure, unused)) +re_string_elem_size_at (const re_string_t *pstr, Idx idx) +{ +# ifdef _LIBC + const unsigned char *p, *extra; + const int32_t *table, *indirect; +# include + uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + + if (nrules != 0) + { + table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); + indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, + _NL_COLLATE_INDIRECTMB); + p = pstr->mbs + idx; + findidx (&p, pstr->len - idx); + return p - pstr->mbs - idx; + } + else +# endif /* _LIBC */ + return 1; +} +# endif +#endif /* RE_ENABLE_I18N */ + +#ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif + +#if __GNUC_PREREQ (3,4) +# undef __attribute_warn_unused_result__ +# define __attribute_warn_unused_result__ \ + __attribute__ ((__warn_unused_result__)) +#else +# define __attribute_warn_unused_result__ /* empty */ +#endif + +#endif /* _REGEX_INTERNAL_H */ diff --git a/grub-core/gnulib/regexec.c b/grub-core/gnulib/regexec.c new file mode 100644 index 000000000..f632cd47b --- /dev/null +++ b/grub-core/gnulib/regexec.c @@ -0,0 +1,4414 @@ +/* Extended regular expression matching and search library. + Copyright (C) 2002-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Isamu Hasegawa . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the GNU C Library; if not, see + . */ + +static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags, + Idx n) internal_function; +static void match_ctx_clean (re_match_context_t *mctx) internal_function; +static void match_ctx_free (re_match_context_t *cache) internal_function; +static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node, + Idx str_idx, Idx from, Idx to) + internal_function; +static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx) + internal_function; +static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node, + Idx str_idx) internal_function; +static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop, + Idx node, Idx str_idx) + internal_function; +static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, + re_dfastate_t **limited_sts, Idx last_node, + Idx last_str_idx) + internal_function; +static reg_errcode_t re_search_internal (const regex_t *preg, + const char *string, Idx length, + Idx start, Idx last_start, Idx stop, + size_t nmatch, regmatch_t pmatch[], + int eflags) internal_function; +static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp, + const char *string1, Idx length1, + const char *string2, Idx length2, + Idx start, regoff_t range, + struct re_registers *regs, + Idx stop, bool ret_len) internal_function; +static regoff_t re_search_stub (struct re_pattern_buffer *bufp, + const char *string, Idx length, Idx start, + regoff_t range, Idx stop, + struct re_registers *regs, + bool ret_len) internal_function; +static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, + Idx nregs, int regs_allocated) internal_function; +static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx) + internal_function; +static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match, + Idx *p_match_first) internal_function; +static Idx check_halt_state_context (const re_match_context_t *mctx, + const re_dfastate_t *state, Idx idx) + internal_function; +static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, + regmatch_t *prev_idx_match, Idx cur_node, + Idx cur_idx, Idx nmatch) internal_function; +static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, + Idx str_idx, Idx dest_node, Idx nregs, + regmatch_t *regs, + re_node_set *eps_via_nodes) + internal_function; +static reg_errcode_t set_regs (const regex_t *preg, + const re_match_context_t *mctx, + size_t nmatch, regmatch_t *pmatch, + bool fl_backtrack) internal_function; +static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) + internal_function; + +#ifdef RE_ENABLE_I18N +static int sift_states_iter_mb (const re_match_context_t *mctx, + re_sift_context_t *sctx, + Idx node_idx, Idx str_idx, Idx max_str_idx) + internal_function; +#endif /* RE_ENABLE_I18N */ +static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, + re_sift_context_t *sctx) + internal_function; +static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, + re_sift_context_t *sctx, Idx str_idx, + re_node_set *cur_dest) + internal_function; +static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, + re_sift_context_t *sctx, + Idx str_idx, + re_node_set *dest_nodes) + internal_function; +static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, + re_node_set *dest_nodes, + const re_node_set *candidates) + internal_function; +static bool check_dst_limits (const re_match_context_t *mctx, + const re_node_set *limits, + Idx dst_node, Idx dst_idx, Idx src_node, + Idx src_idx) internal_function; +static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, + int boundaries, Idx subexp_idx, + Idx from_node, Idx bkref_idx) + internal_function; +static int check_dst_limits_calc_pos (const re_match_context_t *mctx, + Idx limit, Idx subexp_idx, + Idx node, Idx str_idx, + Idx bkref_idx) internal_function; +static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, + re_node_set *dest_nodes, + const re_node_set *candidates, + re_node_set *limits, + struct re_backref_cache_entry *bkref_ents, + Idx str_idx) internal_function; +static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, + re_sift_context_t *sctx, + Idx str_idx, const re_node_set *candidates) + internal_function; +static reg_errcode_t merge_state_array (const re_dfa_t *dfa, + re_dfastate_t **dst, + re_dfastate_t **src, Idx num) + internal_function; +static re_dfastate_t *find_recover_state (reg_errcode_t *err, + re_match_context_t *mctx) internal_function; +static re_dfastate_t *transit_state (reg_errcode_t *err, + re_match_context_t *mctx, + re_dfastate_t *state) internal_function; +static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, + re_match_context_t *mctx, + re_dfastate_t *next_state) + internal_function; +static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, + re_node_set *cur_nodes, + Idx str_idx) internal_function; +#if 0 +static re_dfastate_t *transit_state_sb (reg_errcode_t *err, + re_match_context_t *mctx, + re_dfastate_t *pstate) + internal_function; +#endif +#ifdef RE_ENABLE_I18N +static reg_errcode_t transit_state_mb (re_match_context_t *mctx, + re_dfastate_t *pstate) + internal_function; +#endif /* RE_ENABLE_I18N */ +static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, + const re_node_set *nodes) + internal_function; +static reg_errcode_t get_subexp (re_match_context_t *mctx, + Idx bkref_node, Idx bkref_str_idx) + internal_function; +static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, + const re_sub_match_top_t *sub_top, + re_sub_match_last_t *sub_last, + Idx bkref_node, Idx bkref_str) + internal_function; +static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, + Idx subexp_idx, int type) internal_function; +static reg_errcode_t check_arrival (re_match_context_t *mctx, + state_array_t *path, Idx top_node, + Idx top_str, Idx last_node, Idx last_str, + int type) internal_function; +static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, + Idx str_idx, + re_node_set *cur_nodes, + re_node_set *next_nodes) + internal_function; +static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, + re_node_set *cur_nodes, + Idx ex_subexp, int type) + internal_function; +static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, + re_node_set *dst_nodes, + Idx target, Idx ex_subexp, + int type) internal_function; +static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, + re_node_set *cur_nodes, Idx cur_str, + Idx subexp_num, int type) + internal_function; +static bool build_trtable (const re_dfa_t *dfa, + re_dfastate_t *state) internal_function; +#ifdef RE_ENABLE_I18N +static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, + const re_string_t *input, Idx idx) + internal_function; +# ifdef _LIBC +static unsigned int find_collation_sequence_value (const unsigned char *mbs, + size_t name_len) + internal_function; +# endif /* _LIBC */ +#endif /* RE_ENABLE_I18N */ +static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, + const re_dfastate_t *state, + re_node_set *states_node, + bitset_t *states_ch) internal_function; +static bool check_node_accept (const re_match_context_t *mctx, + const re_token_t *node, Idx idx) + internal_function; +static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len) + internal_function; + +/* Entry point for POSIX code. */ + +/* regexec searches for a given pattern, specified by PREG, in the + string STRING. + + If NMATCH is zero or REG_NOSUB was set in the cflags argument to + 'regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at + least NMATCH elements, and we set them to the offsets of the + corresponding matched substrings. + + EFLAGS specifies "execution flags" which affect matching: if + REG_NOTBOL is set, then ^ does not match at the beginning of the + string; if REG_NOTEOL is set, then $ does not match at the end. + + We return 0 if we find a match and REG_NOMATCH if not. */ + +int +regexec (preg, string, nmatch, pmatch, eflags) + const regex_t *_Restrict_ preg; + const char *_Restrict_ string; + size_t nmatch; + regmatch_t pmatch[_Restrict_arr_]; + int eflags; +{ + reg_errcode_t err; + Idx start, length; +#ifdef _LIBC + re_dfa_t *dfa = preg->buffer; +#endif + + if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) + return REG_BADPAT; + + if (eflags & REG_STARTEND) + { + start = pmatch[0].rm_so; + length = pmatch[0].rm_eo; + } + else + { + start = 0; + length = strlen (string); + } + + __libc_lock_lock (dfa->lock); + if (preg->no_sub) + err = re_search_internal (preg, string, length, start, length, + length, 0, NULL, eflags); + else + err = re_search_internal (preg, string, length, start, length, + length, nmatch, pmatch, eflags); + __libc_lock_unlock (dfa->lock); + return err != REG_NOERROR; +} + +#ifdef _LIBC +# include +versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4); + +# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4) +__typeof__ (__regexec) __compat_regexec; + +int +attribute_compat_text_section +__compat_regexec (const regex_t *_Restrict_ preg, + const char *_Restrict_ string, size_t nmatch, + regmatch_t pmatch[], int eflags) +{ + return regexec (preg, string, nmatch, pmatch, + eflags & (REG_NOTBOL | REG_NOTEOL)); +} +compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); +# endif +#endif + +/* Entry points for GNU code. */ + +/* re_match, re_search, re_match_2, re_search_2 + + The former two functions operate on STRING with length LENGTH, + while the later two operate on concatenation of STRING1 and STRING2 + with lengths LENGTH1 and LENGTH2, respectively. + + re_match() matches the compiled pattern in BUFP against the string, + starting at index START. + + re_search() first tries matching at index START, then it tries to match + starting from index START + 1, and so on. The last start position tried + is START + RANGE. (Thus RANGE = 0 forces re_search to operate the same + way as re_match().) + + The parameter STOP of re_{match,search}_2 specifies that no match exceeding + the first STOP characters of the concatenation of the strings should be + concerned. + + If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match + and all groups is stored in REGS. (For the "_2" variants, the offsets are + computed relative to the concatenation, not relative to the individual + strings.) + + On success, re_match* functions return the length of the match, re_search* + return the position of the start of the match. Return value -1 means no + match was found and -2 indicates an internal error. */ + +regoff_t +re_match (bufp, string, length, start, regs) + struct re_pattern_buffer *bufp; + const char *string; + Idx length, start; + struct re_registers *regs; +{ + return re_search_stub (bufp, string, length, start, 0, length, regs, true); +} +#ifdef _LIBC +weak_alias (__re_match, re_match) +#endif + +regoff_t +re_search (bufp, string, length, start, range, regs) + struct re_pattern_buffer *bufp; + const char *string; + Idx length, start; + regoff_t range; + struct re_registers *regs; +{ + return re_search_stub (bufp, string, length, start, range, length, regs, + false); +} +#ifdef _LIBC +weak_alias (__re_search, re_search) +#endif + +regoff_t +re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) + struct re_pattern_buffer *bufp; + const char *string1, *string2; + Idx length1, length2, start, stop; + struct re_registers *regs; +{ + return re_search_2_stub (bufp, string1, length1, string2, length2, + start, 0, regs, stop, true); +} +#ifdef _LIBC +weak_alias (__re_match_2, re_match_2) +#endif + +regoff_t +re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) + struct re_pattern_buffer *bufp; + const char *string1, *string2; + Idx length1, length2, start, stop; + regoff_t range; + struct re_registers *regs; +{ + return re_search_2_stub (bufp, string1, length1, string2, length2, + start, range, regs, stop, false); +} +#ifdef _LIBC +weak_alias (__re_search_2, re_search_2) +#endif + +static regoff_t +re_search_2_stub (struct re_pattern_buffer *bufp, + const char *string1, Idx length1, + const char *string2, Idx length2, + Idx start, regoff_t range, struct re_registers *regs, + Idx stop, bool ret_len) +{ + const char *str; + regoff_t rval; + Idx len = length1 + length2; + char *s = NULL; + + if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0)) + return -2; + + /* Concatenate the strings. */ + if (length2 > 0) + if (length1 > 0) + { + s = re_malloc (char, len); + + if (BE (s == NULL, 0)) + return -2; +#ifdef _LIBC + memcpy (__mempcpy (s, string1, length1), string2, length2); +#else + memcpy (s, string1, length1); + memcpy (s + length1, string2, length2); +#endif + str = s; + } + else + str = string2; + else + str = string1; + + rval = re_search_stub (bufp, str, len, start, range, stop, regs, + ret_len); + re_free (s); + return rval; +} + +/* The parameters have the same meaning as those of re_search. + Additional parameters: + If RET_LEN is true the length of the match is returned (re_match style); + otherwise the position of the match is returned. */ + +static regoff_t +re_search_stub (struct re_pattern_buffer *bufp, + const char *string, Idx length, + Idx start, regoff_t range, Idx stop, struct re_registers *regs, + bool ret_len) +{ + reg_errcode_t result; + regmatch_t *pmatch; + Idx nregs; + regoff_t rval; + int eflags = 0; +#ifdef _LIBC + re_dfa_t *dfa = bufp->buffer; +#endif + Idx last_start = start + range; + + /* Check for out-of-range. */ + if (BE (start < 0 || start > length, 0)) + return -1; + if (BE (length < last_start || (0 <= range && last_start < start), 0)) + last_start = length; + else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) + last_start = 0; + + __libc_lock_lock (dfa->lock); + + eflags |= (bufp->not_bol) ? REG_NOTBOL : 0; + eflags |= (bufp->not_eol) ? REG_NOTEOL : 0; + + /* Compile fastmap if we haven't yet. */ + if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) + re_compile_fastmap (bufp); + + if (BE (bufp->no_sub, 0)) + regs = NULL; + + /* We need at least 1 register. */ + if (regs == NULL) + nregs = 1; + else if (BE (bufp->regs_allocated == REGS_FIXED + && regs->num_regs <= bufp->re_nsub, 0)) + { + nregs = regs->num_regs; + if (BE (nregs < 1, 0)) + { + /* Nothing can be copied to regs. */ + regs = NULL; + nregs = 1; + } + } + else + nregs = bufp->re_nsub + 1; + pmatch = re_malloc (regmatch_t, nregs); + if (BE (pmatch == NULL, 0)) + { + rval = -2; + goto out; + } + + result = re_search_internal (bufp, string, length, start, last_start, stop, + nregs, pmatch, eflags); + + rval = 0; + + /* I hope we needn't fill their regs with -1's when no match was found. */ + if (result != REG_NOERROR) + rval = result == REG_NOMATCH ? -1 : -2; + else if (regs != NULL) + { + /* If caller wants register contents data back, copy them. */ + bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, + bufp->regs_allocated); + if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) + rval = -2; + } + + if (BE (rval == 0, 1)) + { + if (ret_len) + { + assert (pmatch[0].rm_so == start); + rval = pmatch[0].rm_eo - start; + } + else + rval = pmatch[0].rm_so; + } + re_free (pmatch); + out: + __libc_lock_unlock (dfa->lock); + return rval; +} + +static unsigned +re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, + int regs_allocated) +{ + int rval = REGS_REALLOCATE; + Idx i; + Idx need_regs = nregs + 1; + /* We need one extra element beyond 'num_regs' for the '-1' marker GNU code + uses. */ + + /* Have the register data arrays been allocated? */ + if (regs_allocated == REGS_UNALLOCATED) + { /* No. So allocate them with malloc. */ + regs->start = re_malloc (regoff_t, need_regs); + if (BE (regs->start == NULL, 0)) + return REGS_UNALLOCATED; + regs->end = re_malloc (regoff_t, need_regs); + if (BE (regs->end == NULL, 0)) + { + re_free (regs->start); + return REGS_UNALLOCATED; + } + regs->num_regs = need_regs; + } + else if (regs_allocated == REGS_REALLOCATE) + { /* Yes. If we need more elements than were already + allocated, reallocate them. If we need fewer, just + leave it alone. */ + if (BE (need_regs > regs->num_regs, 0)) + { + regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); + regoff_t *new_end; + if (BE (new_start == NULL, 0)) + return REGS_UNALLOCATED; + new_end = re_realloc (regs->end, regoff_t, need_regs); + if (BE (new_end == NULL, 0)) + { + re_free (new_start); + return REGS_UNALLOCATED; + } + regs->start = new_start; + regs->end = new_end; + regs->num_regs = need_regs; + } + } + else + { + assert (regs_allocated == REGS_FIXED); + /* This function may not be called with REGS_FIXED and nregs too big. */ + assert (regs->num_regs >= nregs); + rval = REGS_FIXED; + } + + /* Copy the regs. */ + for (i = 0; i < nregs; ++i) + { + regs->start[i] = pmatch[i].rm_so; + regs->end[i] = pmatch[i].rm_eo; + } + for ( ; i < regs->num_regs; ++i) + regs->start[i] = regs->end[i] = -1; + + return rval; +} + +/* Set REGS to hold NUM_REGS registers, storing them in STARTS and + ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use + this memory for recording register information. STARTS and ENDS + must be allocated using the malloc library routine, and must each + be at least NUM_REGS * sizeof (regoff_t) bytes long. + + If NUM_REGS == 0, then subsequent matches should allocate their own + register data. + + Unless this function is called, the first search or match using + PATTERN_BUFFER will allocate its own register data, without + freeing the old data. */ + +void +re_set_registers (bufp, regs, num_regs, starts, ends) + struct re_pattern_buffer *bufp; + struct re_registers *regs; + __re_size_t num_regs; + regoff_t *starts, *ends; +{ + if (num_regs) + { + bufp->regs_allocated = REGS_REALLOCATE; + regs->num_regs = num_regs; + regs->start = starts; + regs->end = ends; + } + else + { + bufp->regs_allocated = REGS_UNALLOCATED; + regs->num_regs = 0; + regs->start = regs->end = NULL; + } +} +#ifdef _LIBC +weak_alias (__re_set_registers, re_set_registers) +#endif + +/* Entry points compatible with 4.2 BSD regex library. We don't define + them unless specifically requested. */ + +#if defined _REGEX_RE_COMP || defined _LIBC +int +# ifdef _LIBC +weak_function +# endif +re_exec (s) + const char *s; +{ + return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); +} +#endif /* _REGEX_RE_COMP */ + +/* Internal entry point. */ + +/* Searches for a compiled pattern PREG in the string STRING, whose + length is LENGTH. NMATCH, PMATCH, and EFLAGS have the same + meaning as with regexec. LAST_START is START + RANGE, where + START and RANGE have the same meaning as with re_search. + Return REG_NOERROR if we find a match, and REG_NOMATCH if not, + otherwise return the error code. + Note: We assume front end functions already check ranges. + (0 <= LAST_START && LAST_START <= LENGTH) */ + +static reg_errcode_t +__attribute_warn_unused_result__ +re_search_internal (const regex_t *preg, + const char *string, Idx length, + Idx start, Idx last_start, Idx stop, + size_t nmatch, regmatch_t pmatch[], + int eflags) +{ + reg_errcode_t err; + const re_dfa_t *dfa = preg->buffer; + Idx left_lim, right_lim; + int incr; + bool fl_longest_match; + int match_kind; + Idx match_first; + Idx match_last = REG_MISSING; + Idx extra_nmatch; + bool sb; + int ch; +#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) + re_match_context_t mctx = { .dfa = dfa }; +#else + re_match_context_t mctx; +#endif + char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate + && start != last_start && !preg->can_be_null) + ? preg->fastmap : NULL); + RE_TRANSLATE_TYPE t = preg->translate; + +#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) + memset (&mctx, '\0', sizeof (re_match_context_t)); + mctx.dfa = dfa; +#endif + + extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0; + nmatch -= extra_nmatch; + + /* Check if the DFA haven't been compiled. */ + if (BE (preg->used == 0 || dfa->init_state == NULL + || dfa->init_state_word == NULL || dfa->init_state_nl == NULL + || dfa->init_state_begbuf == NULL, 0)) + return REG_NOMATCH; + +#ifdef DEBUG + /* We assume front-end functions already check them. */ + assert (0 <= last_start && last_start <= length); +#endif + + /* If initial states with non-begbuf contexts have no elements, + the regex must be anchored. If preg->newline_anchor is set, + we'll never use init_state_nl, so do not check it. */ + if (dfa->init_state->nodes.nelem == 0 + && dfa->init_state_word->nodes.nelem == 0 + && (dfa->init_state_nl->nodes.nelem == 0 + || !preg->newline_anchor)) + { + if (start != 0 && last_start != 0) + return REG_NOMATCH; + start = last_start = 0; + } + + /* We must check the longest matching, if nmatch > 0. */ + fl_longest_match = (nmatch != 0 || dfa->nbackref); + + err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, + preg->translate, (preg->syntax & RE_ICASE) != 0, + dfa); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + mctx.input.stop = stop; + mctx.input.raw_stop = stop; + mctx.input.newline_anchor = preg->newline_anchor; + + err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + + /* We will log all the DFA states through which the dfa pass, + if nmatch > 1, or this dfa has "multibyte node", which is a + back-reference or a node which can accept multibyte character or + multi character collating element. */ + if (nmatch > 1 || dfa->has_mb_node) + { + /* Avoid overflow. */ + if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) + <= mctx.input.bufs_len), 0)) + { + err = REG_ESPACE; + goto free_return; + } + + mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); + if (BE (mctx.state_log == NULL, 0)) + { + err = REG_ESPACE; + goto free_return; + } + } + else + mctx.state_log = NULL; + + match_first = start; + mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF + : CONTEXT_NEWLINE | CONTEXT_BEGBUF; + + /* Check incrementally whether the input string matches. */ + incr = (last_start < start) ? -1 : 1; + left_lim = (last_start < start) ? last_start : start; + right_lim = (last_start < start) ? start : last_start; + sb = dfa->mb_cur_max == 1; + match_kind = + (fastmap + ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0) + | (start <= last_start ? 2 : 0) + | (t != NULL ? 1 : 0)) + : 8); + + for (;; match_first += incr) + { + err = REG_NOMATCH; + if (match_first < left_lim || right_lim < match_first) + goto free_return; + + /* Advance as rapidly as possible through the string, until we + find a plausible place to start matching. This may be done + with varying efficiency, so there are various possibilities: + only the most common of them are specialized, in order to + save on code size. We use a switch statement for speed. */ + switch (match_kind) + { + case 8: + /* No fastmap. */ + break; + + case 7: + /* Fastmap with single-byte translation, match forward. */ + while (BE (match_first < right_lim, 1) + && !fastmap[t[(unsigned char) string[match_first]]]) + ++match_first; + goto forward_match_found_start_or_reached_end; + + case 6: + /* Fastmap without translation, match forward. */ + while (BE (match_first < right_lim, 1) + && !fastmap[(unsigned char) string[match_first]]) + ++match_first; + + forward_match_found_start_or_reached_end: + if (BE (match_first == right_lim, 0)) + { + ch = match_first >= length + ? 0 : (unsigned char) string[match_first]; + if (!fastmap[t ? t[ch] : ch]) + goto free_return; + } + break; + + case 4: + case 5: + /* Fastmap without multi-byte translation, match backwards. */ + while (match_first >= left_lim) + { + ch = match_first >= length + ? 0 : (unsigned char) string[match_first]; + if (fastmap[t ? t[ch] : ch]) + break; + --match_first; + } + if (match_first < left_lim) + goto free_return; + break; + + default: + /* In this case, we can't determine easily the current byte, + since it might be a component byte of a multibyte + character. Then we use the constructed buffer instead. */ + for (;;) + { + /* If MATCH_FIRST is out of the valid range, reconstruct the + buffers. */ + __re_size_t offset = match_first - mctx.input.raw_mbs_idx; + if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0)) + { + err = re_string_reconstruct (&mctx.input, match_first, + eflags); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + + offset = match_first - mctx.input.raw_mbs_idx; + } + /* If MATCH_FIRST is out of the buffer, leave it as '\0'. + Note that MATCH_FIRST must not be smaller than 0. */ + ch = (match_first >= length + ? 0 : re_string_byte_at (&mctx.input, offset)); + if (fastmap[ch]) + break; + match_first += incr; + if (match_first < left_lim || match_first > right_lim) + { + err = REG_NOMATCH; + goto free_return; + } + } + break; + } + + /* Reconstruct the buffers so that the matcher can assume that + the matching starts from the beginning of the buffer. */ + err = re_string_reconstruct (&mctx.input, match_first, eflags); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + +#ifdef RE_ENABLE_I18N + /* Don't consider this char as a possible match start if it part, + yet isn't the head, of a multibyte character. */ + if (!sb && !re_string_first_byte (&mctx.input, 0)) + continue; +#endif + + /* It seems to be appropriate one, then use the matcher. */ + /* We assume that the matching starts from 0. */ + mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0; + match_last = check_matching (&mctx, fl_longest_match, + start <= last_start ? &match_first : NULL); + if (match_last != REG_MISSING) + { + if (BE (match_last == REG_ERROR, 0)) + { + err = REG_ESPACE; + goto free_return; + } + else + { + mctx.match_last = match_last; + if ((!preg->no_sub && nmatch > 1) || dfa->nbackref) + { + re_dfastate_t *pstate = mctx.state_log[match_last]; + mctx.last_node = check_halt_state_context (&mctx, pstate, + match_last); + } + if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match) + || dfa->nbackref) + { + err = prune_impossible_nodes (&mctx); + if (err == REG_NOERROR) + break; + if (BE (err != REG_NOMATCH, 0)) + goto free_return; + match_last = REG_MISSING; + } + else + break; /* We found a match. */ + } + } + + match_ctx_clean (&mctx); + } + +#ifdef DEBUG + assert (match_last != REG_MISSING); + assert (err == REG_NOERROR); +#endif + + /* Set pmatch[] if we need. */ + if (nmatch > 0) + { + Idx reg_idx; + + /* Initialize registers. */ + for (reg_idx = 1; reg_idx < nmatch; ++reg_idx) + pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1; + + /* Set the points where matching start/end. */ + pmatch[0].rm_so = 0; + pmatch[0].rm_eo = mctx.match_last; + /* FIXME: This function should fail if mctx.match_last exceeds + the maximum possible regoff_t value. We need a new error + code REG_OVERFLOW. */ + + if (!preg->no_sub && nmatch > 1) + { + err = set_regs (preg, &mctx, nmatch, pmatch, + dfa->has_plural_match && dfa->nbackref > 0); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + + /* At last, add the offset to each register, since we slid + the buffers so that we could assume that the matching starts + from 0. */ + for (reg_idx = 0; reg_idx < nmatch; ++reg_idx) + if (pmatch[reg_idx].rm_so != -1) + { +#ifdef RE_ENABLE_I18N + if (BE (mctx.input.offsets_needed != 0, 0)) + { + pmatch[reg_idx].rm_so = + (pmatch[reg_idx].rm_so == mctx.input.valid_len + ? mctx.input.valid_raw_len + : mctx.input.offsets[pmatch[reg_idx].rm_so]); + pmatch[reg_idx].rm_eo = + (pmatch[reg_idx].rm_eo == mctx.input.valid_len + ? mctx.input.valid_raw_len + : mctx.input.offsets[pmatch[reg_idx].rm_eo]); + } +#else + assert (mctx.input.offsets_needed == 0); +#endif + pmatch[reg_idx].rm_so += match_first; + pmatch[reg_idx].rm_eo += match_first; + } + for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx) + { + pmatch[nmatch + reg_idx].rm_so = -1; + pmatch[nmatch + reg_idx].rm_eo = -1; + } + + if (dfa->subexp_map) + for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++) + if (dfa->subexp_map[reg_idx] != reg_idx) + { + pmatch[reg_idx + 1].rm_so + = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so; + pmatch[reg_idx + 1].rm_eo + = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo; + } + } + + free_return: + re_free (mctx.state_log); + if (dfa->nbackref) + match_ctx_free (&mctx); + re_string_destruct (&mctx.input); + return err; +} + +static reg_errcode_t +__attribute_warn_unused_result__ +prune_impossible_nodes (re_match_context_t *mctx) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx halt_node, match_last; + reg_errcode_t ret; + re_dfastate_t **sifted_states; + re_dfastate_t **lim_states = NULL; + re_sift_context_t sctx; +#ifdef DEBUG + assert (mctx->state_log != NULL); +#endif + match_last = mctx->match_last; + halt_node = mctx->last_node; + + /* Avoid overflow. */ + if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0)) + return REG_ESPACE; + + sifted_states = re_malloc (re_dfastate_t *, match_last + 1); + if (BE (sifted_states == NULL, 0)) + { + ret = REG_ESPACE; + goto free_return; + } + if (dfa->nbackref) + { + lim_states = re_malloc (re_dfastate_t *, match_last + 1); + if (BE (lim_states == NULL, 0)) + { + ret = REG_ESPACE; + goto free_return; + } + while (1) + { + memset (lim_states, '\0', + sizeof (re_dfastate_t *) * (match_last + 1)); + sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, + match_last); + ret = sift_states_backward (mctx, &sctx); + re_node_set_free (&sctx.limits); + if (BE (ret != REG_NOERROR, 0)) + goto free_return; + if (sifted_states[0] != NULL || lim_states[0] != NULL) + break; + do + { + --match_last; + if (! REG_VALID_INDEX (match_last)) + { + ret = REG_NOMATCH; + goto free_return; + } + } while (mctx->state_log[match_last] == NULL + || !mctx->state_log[match_last]->halt); + halt_node = check_halt_state_context (mctx, + mctx->state_log[match_last], + match_last); + } + ret = merge_state_array (dfa, sifted_states, lim_states, + match_last + 1); + re_free (lim_states); + lim_states = NULL; + if (BE (ret != REG_NOERROR, 0)) + goto free_return; + } + else + { + sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last); + ret = sift_states_backward (mctx, &sctx); + re_node_set_free (&sctx.limits); + if (BE (ret != REG_NOERROR, 0)) + goto free_return; + if (sifted_states[0] == NULL) + { + ret = REG_NOMATCH; + goto free_return; + } + } + re_free (mctx->state_log); + mctx->state_log = sifted_states; + sifted_states = NULL; + mctx->last_node = halt_node; + mctx->match_last = match_last; + ret = REG_NOERROR; + free_return: + re_free (sifted_states); + re_free (lim_states); + return ret; +} + +/* Acquire an initial state and return it. + We must select appropriate initial state depending on the context, + since initial states may have constraints like "\<", "^", etc.. */ + +static inline re_dfastate_t * +__attribute__ ((always_inline)) internal_function +acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, + Idx idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + if (dfa->init_state->has_constraint) + { + unsigned int context; + context = re_string_context_at (&mctx->input, idx - 1, mctx->eflags); + if (IS_WORD_CONTEXT (context)) + return dfa->init_state_word; + else if (IS_ORDINARY_CONTEXT (context)) + return dfa->init_state; + else if (IS_BEGBUF_CONTEXT (context) && IS_NEWLINE_CONTEXT (context)) + return dfa->init_state_begbuf; + else if (IS_NEWLINE_CONTEXT (context)) + return dfa->init_state_nl; + else if (IS_BEGBUF_CONTEXT (context)) + { + /* It is relatively rare case, then calculate on demand. */ + return re_acquire_state_context (err, dfa, + dfa->init_state->entrance_nodes, + context); + } + else + /* Must not happen? */ + return dfa->init_state; + } + else + return dfa->init_state; +} + +/* Check whether the regular expression match input string INPUT or not, + and return the index where the matching end. Return REG_MISSING if + there is no match, and return REG_ERROR in case of an error. + FL_LONGEST_MATCH means we want the POSIX longest matching. + If P_MATCH_FIRST is not NULL, and the match fails, it is set to the + next place where we may want to try matching. + Note that the matcher assumes that the matching starts from the current + index of the buffer. */ + +static Idx +internal_function __attribute_warn_unused_result__ +check_matching (re_match_context_t *mctx, bool fl_longest_match, + Idx *p_match_first) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err; + Idx match = 0; + Idx match_last = REG_MISSING; + Idx cur_str_idx = re_string_cur_idx (&mctx->input); + re_dfastate_t *cur_state; + bool at_init_state = p_match_first != NULL; + Idx next_start_idx = cur_str_idx; + + err = REG_NOERROR; + cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); + /* An initial state must not be NULL (invalid). */ + if (BE (cur_state == NULL, 0)) + { + assert (err == REG_ESPACE); + return REG_ERROR; + } + + if (mctx->state_log != NULL) + { + mctx->state_log[cur_str_idx] = cur_state; + + /* Check OP_OPEN_SUBEXP in the initial state in case that we use them + later. E.g. Processing back references. */ + if (BE (dfa->nbackref, 0)) + { + at_init_state = false; + err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); + if (BE (err != REG_NOERROR, 0)) + return err; + + if (cur_state->has_backref) + { + err = transit_state_bkref (mctx, &cur_state->nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + } + } + } + + /* If the RE accepts NULL string. */ + if (BE (cur_state->halt, 0)) + { + if (!cur_state->has_constraint + || check_halt_state_context (mctx, cur_state, cur_str_idx)) + { + if (!fl_longest_match) + return cur_str_idx; + else + { + match_last = cur_str_idx; + match = 1; + } + } + } + + while (!re_string_eoi (&mctx->input)) + { + re_dfastate_t *old_state = cur_state; + Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; + + if ((BE (next_char_idx >= mctx->input.bufs_len, 0) + && mctx->input.bufs_len < mctx->input.len) + || (BE (next_char_idx >= mctx->input.valid_len, 0) + && mctx->input.valid_len < mctx->input.len)) + { + err = extend_buffers (mctx, next_char_idx + 1); + if (BE (err != REG_NOERROR, 0)) + { + assert (err == REG_ESPACE); + return REG_ERROR; + } + } + + cur_state = transit_state (&err, mctx, cur_state); + if (mctx->state_log != NULL) + cur_state = merge_state_with_log (&err, mctx, cur_state); + + if (cur_state == NULL) + { + /* Reached the invalid state or an error. Try to recover a valid + state using the state log, if available and if we have not + already found a valid (even if not the longest) match. */ + if (BE (err != REG_NOERROR, 0)) + return REG_ERROR; + + if (mctx->state_log == NULL + || (match && !fl_longest_match) + || (cur_state = find_recover_state (&err, mctx)) == NULL) + break; + } + + if (BE (at_init_state, 0)) + { + if (old_state == cur_state) + next_start_idx = next_char_idx; + else + at_init_state = false; + } + + if (cur_state->halt) + { + /* Reached a halt state. + Check the halt state can satisfy the current context. */ + if (!cur_state->has_constraint + || check_halt_state_context (mctx, cur_state, + re_string_cur_idx (&mctx->input))) + { + /* We found an appropriate halt state. */ + match_last = re_string_cur_idx (&mctx->input); + match = 1; + + /* We found a match, do not modify match_first below. */ + p_match_first = NULL; + if (!fl_longest_match) + break; + } + } + } + + if (p_match_first) + *p_match_first += next_start_idx; + + return match_last; +} + +/* Check NODE match the current context. */ + +static bool +internal_function +check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context) +{ + re_token_type_t type = dfa->nodes[node].type; + unsigned int constraint = dfa->nodes[node].constraint; + if (type != END_OF_RE) + return false; + if (!constraint) + return true; + if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context)) + return false; + return true; +} + +/* Check the halt state STATE match the current context. + Return 0 if not match, if the node, STATE has, is a halt node and + match the context, return the node. */ + +static Idx +internal_function +check_halt_state_context (const re_match_context_t *mctx, + const re_dfastate_t *state, Idx idx) +{ + Idx i; + unsigned int context; +#ifdef DEBUG + assert (state->halt); +#endif + context = re_string_context_at (&mctx->input, idx, mctx->eflags); + for (i = 0; i < state->nodes.nelem; ++i) + if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context)) + return state->nodes.elems[i]; + return 0; +} + +/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA + corresponding to the DFA). + Return the destination node, and update EPS_VIA_NODES; + return REG_MISSING in case of errors. */ + +static Idx +internal_function +proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, + Idx *pidx, Idx node, re_node_set *eps_via_nodes, + struct re_fail_stack_t *fs) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx i; + bool ok; + if (IS_EPSILON_NODE (dfa->nodes[node].type)) + { + re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes; + re_node_set *edests = &dfa->edests[node]; + Idx dest_node; + ok = re_node_set_insert (eps_via_nodes, node); + if (BE (! ok, 0)) + return REG_ERROR; + /* Pick up a valid destination, or return REG_MISSING if none + is found. */ + for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i) + { + Idx candidate = edests->elems[i]; + if (!re_node_set_contains (cur_nodes, candidate)) + continue; + if (dest_node == REG_MISSING) + dest_node = candidate; + + else + { + /* In order to avoid infinite loop like "(a*)*", return the second + epsilon-transition if the first was already considered. */ + if (re_node_set_contains (eps_via_nodes, dest_node)) + return candidate; + + /* Otherwise, push the second epsilon-transition on the fail stack. */ + else if (fs != NULL + && push_fail_stack (fs, *pidx, candidate, nregs, regs, + eps_via_nodes)) + return REG_ERROR; + + /* We know we are going to exit. */ + break; + } + } + return dest_node; + } + else + { + Idx naccepted = 0; + re_token_type_t type = dfa->nodes[node].type; + +#ifdef RE_ENABLE_I18N + if (dfa->nodes[node].accept_mb) + naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx); + else +#endif /* RE_ENABLE_I18N */ + if (type == OP_BACK_REF) + { + Idx subexp_idx = dfa->nodes[node].opr.idx + 1; + naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so; + if (fs != NULL) + { + if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1) + return REG_MISSING; + else if (naccepted) + { + char *buf = (char *) re_string_get_buffer (&mctx->input); + if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx, + naccepted) != 0) + return REG_MISSING; + } + } + + if (naccepted == 0) + { + Idx dest_node; + ok = re_node_set_insert (eps_via_nodes, node); + if (BE (! ok, 0)) + return REG_ERROR; + dest_node = dfa->edests[node].elems[0]; + if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, + dest_node)) + return dest_node; + } + } + + if (naccepted != 0 + || check_node_accept (mctx, dfa->nodes + node, *pidx)) + { + Idx dest_node = dfa->nexts[node]; + *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted; + if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL + || !re_node_set_contains (&mctx->state_log[*pidx]->nodes, + dest_node))) + return REG_MISSING; + re_node_set_empty (eps_via_nodes); + return dest_node; + } + } + return REG_MISSING; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, + Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes) +{ + reg_errcode_t err; + Idx num = fs->num++; + if (fs->num == fs->alloc) + { + struct re_fail_stack_ent_t *new_array; + new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) + * fs->alloc * 2)); + if (new_array == NULL) + return REG_ESPACE; + fs->alloc *= 2; + fs->stack = new_array; + } + fs->stack[num].idx = str_idx; + fs->stack[num].node = dest_node; + fs->stack[num].regs = re_malloc (regmatch_t, nregs); + if (fs->stack[num].regs == NULL) + return REG_ESPACE; + memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); + err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes); + return err; +} + +static Idx +internal_function +pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, + regmatch_t *regs, re_node_set *eps_via_nodes) +{ + Idx num = --fs->num; + assert (REG_VALID_INDEX (num)); + *pidx = fs->stack[num].idx; + memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); + re_node_set_free (eps_via_nodes); + re_free (fs->stack[num].regs); + *eps_via_nodes = fs->stack[num].eps_via_nodes; + return fs->stack[num].node; +} + +/* Set the positions where the subexpressions are starts/ends to registers + PMATCH. + Note: We assume that pmatch[0] is already set, and + pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, + regmatch_t *pmatch, bool fl_backtrack) +{ + const re_dfa_t *dfa = preg->buffer; + Idx idx, cur_node; + re_node_set eps_via_nodes; + struct re_fail_stack_t *fs; + struct re_fail_stack_t fs_body = { 0, 2, NULL }; + regmatch_t *prev_idx_match; + bool prev_idx_match_malloced = false; + +#ifdef DEBUG + assert (nmatch > 1); + assert (mctx->state_log != NULL); +#endif + if (fl_backtrack) + { + fs = &fs_body; + fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc); + if (fs->stack == NULL) + return REG_ESPACE; + } + else + fs = NULL; + + cur_node = dfa->init_node; + re_node_set_init_empty (&eps_via_nodes); + + if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) + prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t)); + else + { + prev_idx_match = re_malloc (regmatch_t, nmatch); + if (prev_idx_match == NULL) + { + free_fail_stack_return (fs); + return REG_ESPACE; + } + prev_idx_match_malloced = true; + } + memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); + + for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) + { + update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); + + if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) + { + Idx reg_idx; + if (fs) + { + for (reg_idx = 0; reg_idx < nmatch; ++reg_idx) + if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1) + break; + if (reg_idx == nmatch) + { + re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); + return free_fail_stack_return (fs); + } + cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch, + &eps_via_nodes); + } + else + { + re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); + return REG_NOERROR; + } + } + + /* Proceed to next node. */ + cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node, + &eps_via_nodes, fs); + + if (BE (! REG_VALID_INDEX (cur_node), 0)) + { + if (BE (cur_node == REG_ERROR, 0)) + { + re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); + free_fail_stack_return (fs); + return REG_ESPACE; + } + if (fs) + cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch, + &eps_via_nodes); + else + { + re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); + return REG_NOMATCH; + } + } + } + re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); + return free_fail_stack_return (fs); +} + +static reg_errcode_t +internal_function +free_fail_stack_return (struct re_fail_stack_t *fs) +{ + if (fs) + { + Idx fs_idx; + for (fs_idx = 0; fs_idx < fs->num; ++fs_idx) + { + re_node_set_free (&fs->stack[fs_idx].eps_via_nodes); + re_free (fs->stack[fs_idx].regs); + } + re_free (fs->stack); + } + return REG_NOERROR; +} + +static void +internal_function +update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, + regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) +{ + int type = dfa->nodes[cur_node].type; + if (type == OP_OPEN_SUBEXP) + { + Idx reg_num = dfa->nodes[cur_node].opr.idx + 1; + + /* We are at the first node of this sub expression. */ + if (reg_num < nmatch) + { + pmatch[reg_num].rm_so = cur_idx; + pmatch[reg_num].rm_eo = -1; + } + } + else if (type == OP_CLOSE_SUBEXP) + { + Idx reg_num = dfa->nodes[cur_node].opr.idx + 1; + if (reg_num < nmatch) + { + /* We are at the last node of this sub expression. */ + if (pmatch[reg_num].rm_so < cur_idx) + { + pmatch[reg_num].rm_eo = cur_idx; + /* This is a non-empty match or we are not inside an optional + subexpression. Accept this right away. */ + memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); + } + else + { + if (dfa->nodes[cur_node].opt_subexp + && prev_idx_match[reg_num].rm_so != -1) + /* We transited through an empty match for an optional + subexpression, like (a?)*, and this is not the subexp's + first match. Copy back the old content of the registers + so that matches of an inner subexpression are undone as + well, like in ((a?))*. */ + memcpy (pmatch, prev_idx_match, sizeof (regmatch_t) * nmatch); + else + /* We completed a subexpression, but it may be part of + an optional one, so do not update PREV_IDX_MATCH. */ + pmatch[reg_num].rm_eo = cur_idx; + } + } + } +} + +/* This function checks the STATE_LOG from the SCTX->last_str_idx to 0 + and sift the nodes in each states according to the following rules. + Updated state_log will be wrote to STATE_LOG. + + Rules: We throw away the Node 'a' in the STATE_LOG[STR_IDX] if... + 1. When STR_IDX == MATCH_LAST(the last index in the state_log): + If 'a' isn't the LAST_NODE and 'a' can't epsilon transit to + the LAST_NODE, we throw away the node 'a'. + 2. When 0 <= STR_IDX < MATCH_LAST and 'a' accepts + string 's' and transit to 'b': + i. If 'b' isn't in the STATE_LOG[STR_IDX+strlen('s')], we throw + away the node 'a'. + ii. If 'b' is in the STATE_LOG[STR_IDX+strlen('s')] but 'b' is + thrown away, we throw away the node 'a'. + 3. When 0 <= STR_IDX < MATCH_LAST and 'a' epsilon transit to 'b': + i. If 'b' isn't in the STATE_LOG[STR_IDX], we throw away the + node 'a'. + ii. If 'b' is in the STATE_LOG[STR_IDX] but 'b' is thrown away, + we throw away the node 'a'. */ + +#define STATE_NODE_CONTAINS(state,node) \ + ((state) != NULL && re_node_set_contains (&(state)->nodes, node)) + +static reg_errcode_t +internal_function +sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) +{ + reg_errcode_t err; + int null_cnt = 0; + Idx str_idx = sctx->last_str_idx; + re_node_set cur_dest; + +#ifdef DEBUG + assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL); +#endif + + /* Build sifted state_log[str_idx]. It has the nodes which can epsilon + transit to the last_node and the last_node itself. */ + err = re_node_set_init_1 (&cur_dest, sctx->last_node); + if (BE (err != REG_NOERROR, 0)) + return err; + err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + + /* Then check each states in the state_log. */ + while (str_idx > 0) + { + /* Update counters. */ + null_cnt = (sctx->sifted_states[str_idx] == NULL) ? null_cnt + 1 : 0; + if (null_cnt > mctx->max_mb_elem_len) + { + memset (sctx->sifted_states, '\0', + sizeof (re_dfastate_t *) * str_idx); + re_node_set_free (&cur_dest); + return REG_NOERROR; + } + re_node_set_empty (&cur_dest); + --str_idx; + + if (mctx->state_log[str_idx]) + { + err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + + /* Add all the nodes which satisfy the following conditions: + - It can epsilon transit to a node in CUR_DEST. + - It is in CUR_SRC. + And update state_log. */ + err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + err = REG_NOERROR; + free_return: + re_node_set_free (&cur_dest); + return err; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, + Idx str_idx, re_node_set *cur_dest) +{ + const re_dfa_t *const dfa = mctx->dfa; + const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; + Idx i; + + /* Then build the next sifted state. + We build the next sifted state on 'cur_dest', and update + 'sifted_states[str_idx]' with 'cur_dest'. + Note: + 'cur_dest' is the sifted state from 'state_log[str_idx + 1]'. + 'cur_src' points the node_set of the old 'state_log[str_idx]' + (with the epsilon nodes pre-filtered out). */ + for (i = 0; i < cur_src->nelem; i++) + { + Idx prev_node = cur_src->elems[i]; + int naccepted = 0; + bool ok; + +#ifdef DEBUG + re_token_type_t type = dfa->nodes[prev_node].type; + assert (!IS_EPSILON_NODE (type)); +#endif +#ifdef RE_ENABLE_I18N + /* If the node may accept "multi byte". */ + if (dfa->nodes[prev_node].accept_mb) + naccepted = sift_states_iter_mb (mctx, sctx, prev_node, + str_idx, sctx->last_str_idx); +#endif /* RE_ENABLE_I18N */ + + /* We don't check backreferences here. + See update_cur_sifted_state(). */ + if (!naccepted + && check_node_accept (mctx, dfa->nodes + prev_node, str_idx) + && STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + 1], + dfa->nexts[prev_node])) + naccepted = 1; + + if (naccepted == 0) + continue; + + if (sctx->limits.nelem) + { + Idx to_idx = str_idx + naccepted; + if (check_dst_limits (mctx, &sctx->limits, + dfa->nexts[prev_node], to_idx, + prev_node, str_idx)) + continue; + } + ok = re_node_set_insert (cur_dest, prev_node); + if (BE (! ok, 0)) + return REG_ESPACE; + } + + return REG_NOERROR; +} + +/* Helper functions. */ + +static reg_errcode_t +internal_function +clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) +{ + Idx top = mctx->state_log_top; + + if ((next_state_log_idx >= mctx->input.bufs_len + && mctx->input.bufs_len < mctx->input.len) + || (next_state_log_idx >= mctx->input.valid_len + && mctx->input.valid_len < mctx->input.len)) + { + reg_errcode_t err; + err = extend_buffers (mctx, next_state_log_idx + 1); + if (BE (err != REG_NOERROR, 0)) + return err; + } + + if (top < next_state_log_idx) + { + memset (mctx->state_log + top + 1, '\0', + sizeof (re_dfastate_t *) * (next_state_log_idx - top)); + mctx->state_log_top = next_state_log_idx; + } + return REG_NOERROR; +} + +static reg_errcode_t +internal_function +merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, + re_dfastate_t **src, Idx num) +{ + Idx st_idx; + reg_errcode_t err; + for (st_idx = 0; st_idx < num; ++st_idx) + { + if (dst[st_idx] == NULL) + dst[st_idx] = src[st_idx]; + else if (src[st_idx] != NULL) + { + re_node_set merged_set; + err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes, + &src[st_idx]->nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + dst[st_idx] = re_acquire_state (&err, dfa, &merged_set); + re_node_set_free (&merged_set); + if (BE (err != REG_NOERROR, 0)) + return err; + } + } + return REG_NOERROR; +} + +static reg_errcode_t +internal_function +update_cur_sifted_state (const re_match_context_t *mctx, + re_sift_context_t *sctx, Idx str_idx, + re_node_set *dest_nodes) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err = REG_NOERROR; + const re_node_set *candidates; + candidates = ((mctx->state_log[str_idx] == NULL) ? NULL + : &mctx->state_log[str_idx]->nodes); + + if (dest_nodes->nelem == 0) + sctx->sifted_states[str_idx] = NULL; + else + { + if (candidates) + { + /* At first, add the nodes which can epsilon transit to a node in + DEST_NODE. */ + err = add_epsilon_src_nodes (dfa, dest_nodes, candidates); + if (BE (err != REG_NOERROR, 0)) + return err; + + /* Then, check the limitations in the current sift_context. */ + if (sctx->limits.nelem) + { + err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits, + mctx->bkref_ents, str_idx); + if (BE (err != REG_NOERROR, 0)) + return err; + } + } + + sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + } + + if (candidates && mctx->state_log[str_idx]->has_backref) + { + err = sift_states_bkref (mctx, sctx, str_idx, candidates); + if (BE (err != REG_NOERROR, 0)) + return err; + } + return REG_NOERROR; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, + const re_node_set *candidates) +{ + reg_errcode_t err = REG_NOERROR; + Idx i; + + re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + + if (!state->inveclosure.alloc) + { + err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); + if (BE (err != REG_NOERROR, 0)) + return REG_ESPACE; + for (i = 0; i < dest_nodes->nelem; i++) + { + err = re_node_set_merge (&state->inveclosure, + dfa->inveclosures + dest_nodes->elems[i]); + if (BE (err != REG_NOERROR, 0)) + return REG_ESPACE; + } + } + return re_node_set_add_intersect (dest_nodes, candidates, + &state->inveclosure); +} + +static reg_errcode_t +internal_function +sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, + const re_node_set *candidates) +{ + Idx ecl_idx; + reg_errcode_t err; + re_node_set *inv_eclosure = dfa->inveclosures + node; + re_node_set except_nodes; + re_node_set_init_empty (&except_nodes); + for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx) + { + Idx cur_node = inv_eclosure->elems[ecl_idx]; + if (cur_node == node) + continue; + if (IS_EPSILON_NODE (dfa->nodes[cur_node].type)) + { + Idx edst1 = dfa->edests[cur_node].elems[0]; + Idx edst2 = ((dfa->edests[cur_node].nelem > 1) + ? dfa->edests[cur_node].elems[1] : REG_MISSING); + if ((!re_node_set_contains (inv_eclosure, edst1) + && re_node_set_contains (dest_nodes, edst1)) + || (REG_VALID_NONZERO_INDEX (edst2) + && !re_node_set_contains (inv_eclosure, edst2) + && re_node_set_contains (dest_nodes, edst2))) + { + err = re_node_set_add_intersect (&except_nodes, candidates, + dfa->inveclosures + cur_node); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&except_nodes); + return err; + } + } + } + } + for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx) + { + Idx cur_node = inv_eclosure->elems[ecl_idx]; + if (!re_node_set_contains (&except_nodes, cur_node)) + { + Idx idx = re_node_set_contains (dest_nodes, cur_node) - 1; + re_node_set_remove_at (dest_nodes, idx); + } + } + re_node_set_free (&except_nodes); + return REG_NOERROR; +} + +static bool +internal_function +check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, + Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx lim_idx, src_pos, dst_pos; + + Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx); + Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx); + for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx) + { + Idx subexp_idx; + struct re_backref_cache_entry *ent; + ent = mctx->bkref_ents + limits->elems[lim_idx]; + subexp_idx = dfa->nodes[ent->node].opr.idx; + + dst_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx], + subexp_idx, dst_node, dst_idx, + dst_bkref_idx); + src_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx], + subexp_idx, src_node, src_idx, + src_bkref_idx); + + /* In case of: + ( ) + ( ) + ( ) */ + if (src_pos == dst_pos) + continue; /* This is unrelated limitation. */ + else + return true; + } + return false; +} + +static int +internal_function +check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, + Idx subexp_idx, Idx from_node, Idx bkref_idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + const re_node_set *eclosures = dfa->eclosures + from_node; + Idx node_idx; + + /* Else, we are on the boundary: examine the nodes on the epsilon + closure. */ + for (node_idx = 0; node_idx < eclosures->nelem; ++node_idx) + { + Idx node = eclosures->elems[node_idx]; + switch (dfa->nodes[node].type) + { + case OP_BACK_REF: + if (bkref_idx != REG_MISSING) + { + struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx; + do + { + Idx dst; + int cpos; + + if (ent->node != node) + continue; + + if (subexp_idx < BITSET_WORD_BITS + && !(ent->eps_reachable_subexps_map + & ((bitset_word_t) 1 << subexp_idx))) + continue; + + /* Recurse trying to reach the OP_OPEN_SUBEXP and + OP_CLOSE_SUBEXP cases below. But, if the + destination node is the same node as the source + node, don't recurse because it would cause an + infinite loop: a regex that exhibits this behavior + is ()\1*\1* */ + dst = dfa->edests[node].elems[0]; + if (dst == from_node) + { + if (boundaries & 1) + return -1; + else /* if (boundaries & 2) */ + return 0; + } + + cpos = + check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, + dst, bkref_idx); + if (cpos == -1 /* && (boundaries & 1) */) + return -1; + if (cpos == 0 && (boundaries & 2)) + return 0; + + if (subexp_idx < BITSET_WORD_BITS) + ent->eps_reachable_subexps_map + &= ~((bitset_word_t) 1 << subexp_idx); + } + while (ent++->more); + } + break; + + case OP_OPEN_SUBEXP: + if ((boundaries & 1) && subexp_idx == dfa->nodes[node].opr.idx) + return -1; + break; + + case OP_CLOSE_SUBEXP: + if ((boundaries & 2) && subexp_idx == dfa->nodes[node].opr.idx) + return 0; + break; + + default: + break; + } + } + + return (boundaries & 2) ? 1 : 0; +} + +static int +internal_function +check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, + Idx subexp_idx, Idx from_node, Idx str_idx, + Idx bkref_idx) +{ + struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; + int boundaries; + + /* If we are outside the range of the subexpression, return -1 or 1. */ + if (str_idx < lim->subexp_from) + return -1; + + if (lim->subexp_to < str_idx) + return 1; + + /* If we are within the subexpression, return 0. */ + boundaries = (str_idx == lim->subexp_from); + boundaries |= (str_idx == lim->subexp_to) << 1; + if (boundaries == 0) + return 0; + + /* Else, examine epsilon closure. */ + return check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, + from_node, bkref_idx); +} + +/* Check the limitations of sub expressions LIMITS, and remove the nodes + which are against limitations from DEST_NODES. */ + +static reg_errcode_t +internal_function +check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, + const re_node_set *candidates, re_node_set *limits, + struct re_backref_cache_entry *bkref_ents, Idx str_idx) +{ + reg_errcode_t err; + Idx node_idx, lim_idx; + + for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx) + { + Idx subexp_idx; + struct re_backref_cache_entry *ent; + ent = bkref_ents + limits->elems[lim_idx]; + + if (str_idx <= ent->subexp_from || ent->str_idx < str_idx) + continue; /* This is unrelated limitation. */ + + subexp_idx = dfa->nodes[ent->node].opr.idx; + if (ent->subexp_to == str_idx) + { + Idx ops_node = REG_MISSING; + Idx cls_node = REG_MISSING; + for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) + { + Idx node = dest_nodes->elems[node_idx]; + re_token_type_t type = dfa->nodes[node].type; + if (type == OP_OPEN_SUBEXP + && subexp_idx == dfa->nodes[node].opr.idx) + ops_node = node; + else if (type == OP_CLOSE_SUBEXP + && subexp_idx == dfa->nodes[node].opr.idx) + cls_node = node; + } + + /* Check the limitation of the open subexpression. */ + /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */ + if (REG_VALID_INDEX (ops_node)) + { + err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes, + candidates); + if (BE (err != REG_NOERROR, 0)) + return err; + } + + /* Check the limitation of the close subexpression. */ + if (REG_VALID_INDEX (cls_node)) + for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) + { + Idx node = dest_nodes->elems[node_idx]; + if (!re_node_set_contains (dfa->inveclosures + node, + cls_node) + && !re_node_set_contains (dfa->eclosures + node, + cls_node)) + { + /* It is against this limitation. + Remove it form the current sifted state. */ + err = sub_epsilon_src_nodes (dfa, node, dest_nodes, + candidates); + if (BE (err != REG_NOERROR, 0)) + return err; + --node_idx; + } + } + } + else /* (ent->subexp_to != str_idx) */ + { + for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) + { + Idx node = dest_nodes->elems[node_idx]; + re_token_type_t type = dfa->nodes[node].type; + if (type == OP_CLOSE_SUBEXP || type == OP_OPEN_SUBEXP) + { + if (subexp_idx != dfa->nodes[node].opr.idx) + continue; + /* It is against this limitation. + Remove it form the current sifted state. */ + err = sub_epsilon_src_nodes (dfa, node, dest_nodes, + candidates); + if (BE (err != REG_NOERROR, 0)) + return err; + } + } + } + } + return REG_NOERROR; +} + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, + Idx str_idx, const re_node_set *candidates) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err; + Idx node_idx, node; + re_sift_context_t local_sctx; + Idx first_idx = search_cur_bkref_entry (mctx, str_idx); + + if (first_idx == REG_MISSING) + return REG_NOERROR; + + local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */ + + for (node_idx = 0; node_idx < candidates->nelem; ++node_idx) + { + Idx enabled_idx; + re_token_type_t type; + struct re_backref_cache_entry *entry; + node = candidates->elems[node_idx]; + type = dfa->nodes[node].type; + /* Avoid infinite loop for the REs like "()\1+". */ + if (node == sctx->last_node && str_idx == sctx->last_str_idx) + continue; + if (type != OP_BACK_REF) + continue; + + entry = mctx->bkref_ents + first_idx; + enabled_idx = first_idx; + do + { + Idx subexp_len; + Idx to_idx; + Idx dst_node; + bool ok; + re_dfastate_t *cur_state; + + if (entry->node != node) + continue; + subexp_len = entry->subexp_to - entry->subexp_from; + to_idx = str_idx + subexp_len; + dst_node = (subexp_len ? dfa->nexts[node] + : dfa->edests[node].elems[0]); + + if (to_idx > sctx->last_str_idx + || sctx->sifted_states[to_idx] == NULL + || !STATE_NODE_CONTAINS (sctx->sifted_states[to_idx], dst_node) + || check_dst_limits (mctx, &sctx->limits, node, + str_idx, dst_node, to_idx)) + continue; + + if (local_sctx.sifted_states == NULL) + { + local_sctx = *sctx; + err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + local_sctx.last_node = node; + local_sctx.last_str_idx = str_idx; + ok = re_node_set_insert (&local_sctx.limits, enabled_idx); + if (BE (! ok, 0)) + { + err = REG_ESPACE; + goto free_return; + } + cur_state = local_sctx.sifted_states[str_idx]; + err = sift_states_backward (mctx, &local_sctx); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + if (sctx->limited_states != NULL) + { + err = merge_state_array (dfa, sctx->limited_states, + local_sctx.sifted_states, + str_idx + 1); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + local_sctx.sifted_states[str_idx] = cur_state; + re_node_set_remove (&local_sctx.limits, enabled_idx); + + /* mctx->bkref_ents may have changed, reload the pointer. */ + entry = mctx->bkref_ents + enabled_idx; + } + while (enabled_idx++, entry++->more); + } + err = REG_NOERROR; + free_return: + if (local_sctx.sifted_states != NULL) + { + re_node_set_free (&local_sctx.limits); + } + + return err; +} + + +#ifdef RE_ENABLE_I18N +static int +internal_function +sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, + Idx node_idx, Idx str_idx, Idx max_str_idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + int naccepted; + /* Check the node can accept "multi byte". */ + naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); + if (naccepted > 0 && str_idx + naccepted <= max_str_idx && + !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted], + dfa->nexts[node_idx])) + /* The node can't accept the "multi byte", or the + destination was already thrown away, then the node + could't accept the current input "multi byte". */ + naccepted = 0; + /* Otherwise, it is sure that the node could accept + 'naccepted' bytes input. */ + return naccepted; +} +#endif /* RE_ENABLE_I18N */ + + +/* Functions for state transition. */ + +/* Return the next state to which the current state STATE will transit by + accepting the current input byte, and update STATE_LOG if necessary. + If STATE can accept a multibyte char/collating element/back reference + update the destination of STATE_LOG. */ + +static re_dfastate_t * +internal_function __attribute_warn_unused_result__ +transit_state (reg_errcode_t *err, re_match_context_t *mctx, + re_dfastate_t *state) +{ + re_dfastate_t **trtable; + unsigned char ch; + +#ifdef RE_ENABLE_I18N + /* If the current state can accept multibyte. */ + if (BE (state->accept_mb, 0)) + { + *err = transit_state_mb (mctx, state); + if (BE (*err != REG_NOERROR, 0)) + return NULL; + } +#endif /* RE_ENABLE_I18N */ + + /* Then decide the next state with the single byte. */ +#if 0 + if (0) + /* don't use transition table */ + return transit_state_sb (err, mctx, state); +#endif + + /* Use transition table */ + ch = re_string_fetch_byte (&mctx->input); + for (;;) + { + trtable = state->trtable; + if (BE (trtable != NULL, 1)) + return trtable[ch]; + + trtable = state->word_trtable; + if (BE (trtable != NULL, 1)) + { + unsigned int context; + context + = re_string_context_at (&mctx->input, + re_string_cur_idx (&mctx->input) - 1, + mctx->eflags); + if (IS_WORD_CONTEXT (context)) + return trtable[ch + SBC_MAX]; + else + return trtable[ch]; + } + + if (!build_trtable (mctx->dfa, state)) + { + *err = REG_ESPACE; + return NULL; + } + + /* Retry, we now have a transition table. */ + } +} + +/* Update the state_log if we need */ +static re_dfastate_t * +internal_function +merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, + re_dfastate_t *next_state) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx cur_idx = re_string_cur_idx (&mctx->input); + + if (cur_idx > mctx->state_log_top) + { + mctx->state_log[cur_idx] = next_state; + mctx->state_log_top = cur_idx; + } + else if (mctx->state_log[cur_idx] == 0) + { + mctx->state_log[cur_idx] = next_state; + } + else + { + re_dfastate_t *pstate; + unsigned int context; + re_node_set next_nodes, *log_nodes, *table_nodes = NULL; + /* If (state_log[cur_idx] != 0), it implies that cur_idx is + the destination of a multibyte char/collating element/ + back reference. Then the next state is the union set of + these destinations and the results of the transition table. */ + pstate = mctx->state_log[cur_idx]; + log_nodes = pstate->entrance_nodes; + if (next_state != NULL) + { + table_nodes = next_state->entrance_nodes; + *err = re_node_set_init_union (&next_nodes, table_nodes, + log_nodes); + if (BE (*err != REG_NOERROR, 0)) + return NULL; + } + else + next_nodes = *log_nodes; + /* Note: We already add the nodes of the initial state, + then we don't need to add them here. */ + + context = re_string_context_at (&mctx->input, + re_string_cur_idx (&mctx->input) - 1, + mctx->eflags); + next_state = mctx->state_log[cur_idx] + = re_acquire_state_context (err, dfa, &next_nodes, context); + /* We don't need to check errors here, since the return value of + this function is next_state and ERR is already set. */ + + if (table_nodes != NULL) + re_node_set_free (&next_nodes); + } + + if (BE (dfa->nbackref, 0) && next_state != NULL) + { + /* Check OP_OPEN_SUBEXP in the current state in case that we use them + later. We must check them here, since the back references in the + next state might use them. */ + *err = check_subexp_matching_top (mctx, &next_state->nodes, + cur_idx); + if (BE (*err != REG_NOERROR, 0)) + return NULL; + + /* If the next state has back references. */ + if (next_state->has_backref) + { + *err = transit_state_bkref (mctx, &next_state->nodes); + if (BE (*err != REG_NOERROR, 0)) + return NULL; + next_state = mctx->state_log[cur_idx]; + } + } + + return next_state; +} + +/* Skip bytes in the input that correspond to part of a + multi-byte match, then look in the log for a state + from which to restart matching. */ +static re_dfastate_t * +internal_function +find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) +{ + re_dfastate_t *cur_state; + do + { + Idx max = mctx->state_log_top; + Idx cur_str_idx = re_string_cur_idx (&mctx->input); + + do + { + if (++cur_str_idx > max) + return NULL; + re_string_skip_bytes (&mctx->input, 1); + } + while (mctx->state_log[cur_str_idx] == NULL); + + cur_state = merge_state_with_log (err, mctx, NULL); + } + while (*err == REG_NOERROR && cur_state == NULL); + return cur_state; +} + +/* Helper functions for transit_state. */ + +/* From the node set CUR_NODES, pick up the nodes whose types are + OP_OPEN_SUBEXP and which have corresponding back references in the regular + expression. And register them to use them later for evaluating the + corresponding back references. */ + +static reg_errcode_t +internal_function +check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, + Idx str_idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx node_idx; + reg_errcode_t err; + + /* TODO: This isn't efficient. + Because there might be more than one nodes whose types are + OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all + nodes. + E.g. RE: (a){2} */ + for (node_idx = 0; node_idx < cur_nodes->nelem; ++node_idx) + { + Idx node = cur_nodes->elems[node_idx]; + if (dfa->nodes[node].type == OP_OPEN_SUBEXP + && dfa->nodes[node].opr.idx < BITSET_WORD_BITS + && (dfa->used_bkref_map + & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) + { + err = match_ctx_add_subtop (mctx, node, str_idx); + if (BE (err != REG_NOERROR, 0)) + return err; + } + } + return REG_NOERROR; +} + +#if 0 +/* Return the next state to which the current state STATE will transit by + accepting the current input byte. */ + +static re_dfastate_t * +transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, + re_dfastate_t *state) +{ + const re_dfa_t *const dfa = mctx->dfa; + re_node_set next_nodes; + re_dfastate_t *next_state; + Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input); + unsigned int context; + + *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1); + if (BE (*err != REG_NOERROR, 0)) + return NULL; + for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt) + { + Idx cur_node = state->nodes.elems[node_cnt]; + if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx)) + { + *err = re_node_set_merge (&next_nodes, + dfa->eclosures + dfa->nexts[cur_node]); + if (BE (*err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return NULL; + } + } + } + context = re_string_context_at (&mctx->input, cur_str_idx, mctx->eflags); + next_state = re_acquire_state_context (err, dfa, &next_nodes, context); + /* We don't need to check errors here, since the return value of + this function is next_state and ERR is already set. */ + + re_node_set_free (&next_nodes); + re_string_skip_bytes (&mctx->input, 1); + return next_state; +} +#endif + +#ifdef RE_ENABLE_I18N +static reg_errcode_t +internal_function +transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err; + Idx i; + + for (i = 0; i < pstate->nodes.nelem; ++i) + { + re_node_set dest_nodes, *new_nodes; + Idx cur_node_idx = pstate->nodes.elems[i]; + int naccepted; + Idx dest_idx; + unsigned int context; + re_dfastate_t *dest_state; + + if (!dfa->nodes[cur_node_idx].accept_mb) + continue; + + if (dfa->nodes[cur_node_idx].constraint) + { + context = re_string_context_at (&mctx->input, + re_string_cur_idx (&mctx->input), + mctx->eflags); + if (NOT_SATISFY_NEXT_CONSTRAINT (dfa->nodes[cur_node_idx].constraint, + context)) + continue; + } + + /* How many bytes the node can accept? */ + naccepted = check_node_accept_bytes (dfa, cur_node_idx, &mctx->input, + re_string_cur_idx (&mctx->input)); + if (naccepted == 0) + continue; + + /* The node can accepts 'naccepted' bytes. */ + dest_idx = re_string_cur_idx (&mctx->input) + naccepted; + mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted + : mctx->max_mb_elem_len); + err = clean_state_log_if_needed (mctx, dest_idx); + if (BE (err != REG_NOERROR, 0)) + return err; +#ifdef DEBUG + assert (dfa->nexts[cur_node_idx] != REG_MISSING); +#endif + new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx]; + + dest_state = mctx->state_log[dest_idx]; + if (dest_state == NULL) + dest_nodes = *new_nodes; + else + { + err = re_node_set_init_union (&dest_nodes, + dest_state->entrance_nodes, new_nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + } + context = re_string_context_at (&mctx->input, dest_idx - 1, + mctx->eflags); + mctx->state_log[dest_idx] + = re_acquire_state_context (&err, dfa, &dest_nodes, context); + if (dest_state != NULL) + re_node_set_free (&dest_nodes); + if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0)) + return err; + } + return REG_NOERROR; +} +#endif /* RE_ENABLE_I18N */ + +static reg_errcode_t +internal_function +transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err; + Idx i; + Idx cur_str_idx = re_string_cur_idx (&mctx->input); + + for (i = 0; i < nodes->nelem; ++i) + { + Idx dest_str_idx, prev_nelem, bkc_idx; + Idx node_idx = nodes->elems[i]; + unsigned int context; + const re_token_t *node = dfa->nodes + node_idx; + re_node_set *new_dest_nodes; + + /* Check whether 'node' is a backreference or not. */ + if (node->type != OP_BACK_REF) + continue; + + if (node->constraint) + { + context = re_string_context_at (&mctx->input, cur_str_idx, + mctx->eflags); + if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context)) + continue; + } + + /* 'node' is a backreference. + Check the substring which the substring matched. */ + bkc_idx = mctx->nbkref_ents; + err = get_subexp (mctx, node_idx, cur_str_idx); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + + /* And add the epsilon closures (which is 'new_dest_nodes') of + the backreference to appropriate state_log. */ +#ifdef DEBUG + assert (dfa->nexts[node_idx] != REG_MISSING); +#endif + for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx) + { + Idx subexp_len; + re_dfastate_t *dest_state; + struct re_backref_cache_entry *bkref_ent; + bkref_ent = mctx->bkref_ents + bkc_idx; + if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx) + continue; + subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from; + new_dest_nodes = (subexp_len == 0 + ? dfa->eclosures + dfa->edests[node_idx].elems[0] + : dfa->eclosures + dfa->nexts[node_idx]); + dest_str_idx = (cur_str_idx + bkref_ent->subexp_to + - bkref_ent->subexp_from); + context = re_string_context_at (&mctx->input, dest_str_idx - 1, + mctx->eflags); + dest_state = mctx->state_log[dest_str_idx]; + prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0 + : mctx->state_log[cur_str_idx]->nodes.nelem); + /* Add 'new_dest_node' to state_log. */ + if (dest_state == NULL) + { + mctx->state_log[dest_str_idx] + = re_acquire_state_context (&err, dfa, new_dest_nodes, + context); + if (BE (mctx->state_log[dest_str_idx] == NULL + && err != REG_NOERROR, 0)) + goto free_return; + } + else + { + re_node_set dest_nodes; + err = re_node_set_init_union (&dest_nodes, + dest_state->entrance_nodes, + new_dest_nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&dest_nodes); + goto free_return; + } + mctx->state_log[dest_str_idx] + = re_acquire_state_context (&err, dfa, &dest_nodes, context); + re_node_set_free (&dest_nodes); + if (BE (mctx->state_log[dest_str_idx] == NULL + && err != REG_NOERROR, 0)) + goto free_return; + } + /* We need to check recursively if the backreference can epsilon + transit. */ + if (subexp_len == 0 + && mctx->state_log[cur_str_idx]->nodes.nelem > prev_nelem) + { + err = check_subexp_matching_top (mctx, new_dest_nodes, + cur_str_idx); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + err = transit_state_bkref (mctx, new_dest_nodes); + if (BE (err != REG_NOERROR, 0)) + goto free_return; + } + } + } + err = REG_NOERROR; + free_return: + return err; +} + +/* Enumerate all the candidates which the backreference BKREF_NODE can match + at BKREF_STR_IDX, and register them by match_ctx_add_entry(). + Note that we might collect inappropriate candidates here. + However, the cost of checking them strictly here is too high, then we + delay these checking for prune_impossible_nodes(). */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) +{ + const re_dfa_t *const dfa = mctx->dfa; + Idx subexp_num, sub_top_idx; + const char *buf = (const char *) re_string_get_buffer (&mctx->input); + /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ + Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); + if (cache_idx != REG_MISSING) + { + const struct re_backref_cache_entry *entry + = mctx->bkref_ents + cache_idx; + do + if (entry->node == bkref_node) + return REG_NOERROR; /* We already checked it. */ + while (entry++->more); + } + + subexp_num = dfa->nodes[bkref_node].opr.idx; + + /* For each sub expression */ + for (sub_top_idx = 0; sub_top_idx < mctx->nsub_tops; ++sub_top_idx) + { + reg_errcode_t err; + re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx]; + re_sub_match_last_t *sub_last; + Idx sub_last_idx, sl_str, bkref_str_off; + + if (dfa->nodes[sub_top->node].opr.idx != subexp_num) + continue; /* It isn't related. */ + + sl_str = sub_top->str_idx; + bkref_str_off = bkref_str_idx; + /* At first, check the last node of sub expressions we already + evaluated. */ + for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx) + { + regoff_t sl_str_diff; + sub_last = sub_top->lasts[sub_last_idx]; + sl_str_diff = sub_last->str_idx - sl_str; + /* The matched string by the sub expression match with the substring + at the back reference? */ + if (sl_str_diff > 0) + { + if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0)) + { + /* Not enough chars for a successful match. */ + if (bkref_str_off + sl_str_diff > mctx->input.len) + break; + + err = clean_state_log_if_needed (mctx, + bkref_str_off + + sl_str_diff); + if (BE (err != REG_NOERROR, 0)) + return err; + buf = (const char *) re_string_get_buffer (&mctx->input); + } + if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0) + /* We don't need to search this sub expression any more. */ + break; + } + bkref_str_off += sl_str_diff; + sl_str += sl_str_diff; + err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, + bkref_str_idx); + + /* Reload buf, since the preceding call might have reallocated + the buffer. */ + buf = (const char *) re_string_get_buffer (&mctx->input); + + if (err == REG_NOMATCH) + continue; + if (BE (err != REG_NOERROR, 0)) + return err; + } + + if (sub_last_idx < sub_top->nlasts) + continue; + if (sub_last_idx > 0) + ++sl_str; + /* Then, search for the other last nodes of the sub expression. */ + for (; sl_str <= bkref_str_idx; ++sl_str) + { + Idx cls_node; + regoff_t sl_str_off; + const re_node_set *nodes; + sl_str_off = sl_str - sub_top->str_idx; + /* The matched string by the sub expression match with the substring + at the back reference? */ + if (sl_str_off > 0) + { + if (BE (bkref_str_off >= mctx->input.valid_len, 0)) + { + /* If we are at the end of the input, we cannot match. */ + if (bkref_str_off >= mctx->input.len) + break; + + err = extend_buffers (mctx, bkref_str_off + 1); + if (BE (err != REG_NOERROR, 0)) + return err; + + buf = (const char *) re_string_get_buffer (&mctx->input); + } + if (buf [bkref_str_off++] != buf[sl_str - 1]) + break; /* We don't need to search this sub expression + any more. */ + } + if (mctx->state_log[sl_str] == NULL) + continue; + /* Does this state have a ')' of the sub expression? */ + nodes = &mctx->state_log[sl_str]->nodes; + cls_node = find_subexp_node (dfa, nodes, subexp_num, + OP_CLOSE_SUBEXP); + if (cls_node == REG_MISSING) + continue; /* No. */ + if (sub_top->path == NULL) + { + sub_top->path = calloc (sizeof (state_array_t), + sl_str - sub_top->str_idx + 1); + if (sub_top->path == NULL) + return REG_ESPACE; + } + /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node + in the current context? */ + err = check_arrival (mctx, sub_top->path, sub_top->node, + sub_top->str_idx, cls_node, sl_str, + OP_CLOSE_SUBEXP); + if (err == REG_NOMATCH) + continue; + if (BE (err != REG_NOERROR, 0)) + return err; + sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str); + if (BE (sub_last == NULL, 0)) + return REG_ESPACE; + err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, + bkref_str_idx); + if (err == REG_NOMATCH) + continue; + } + } + return REG_NOERROR; +} + +/* Helper functions for get_subexp(). */ + +/* Check SUB_LAST can arrive to the back reference BKREF_NODE at BKREF_STR. + If it can arrive, register the sub expression expressed with SUB_TOP + and SUB_LAST. */ + +static reg_errcode_t +internal_function +get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, + re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str) +{ + reg_errcode_t err; + Idx to_idx; + /* Can the subexpression arrive the back reference? */ + err = check_arrival (mctx, &sub_last->path, sub_last->node, + sub_last->str_idx, bkref_node, bkref_str, + OP_OPEN_SUBEXP); + if (err != REG_NOERROR) + return err; + err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, + sub_last->str_idx); + if (BE (err != REG_NOERROR, 0)) + return err; + to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx; + return clean_state_log_if_needed (mctx, to_idx); +} + +/* Find the first node which is '(' or ')' and whose index is SUBEXP_IDX. + Search '(' if FL_OPEN, or search ')' otherwise. + TODO: This function isn't efficient... + Because there might be more than one nodes whose types are + OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all + nodes. + E.g. RE: (a){2} */ + +static Idx +internal_function +find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, + Idx subexp_idx, int type) +{ + Idx cls_idx; + for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx) + { + Idx cls_node = nodes->elems[cls_idx]; + const re_token_t *node = dfa->nodes + cls_node; + if (node->type == type + && node->opr.idx == subexp_idx) + return cls_node; + } + return REG_MISSING; +} + +/* Check whether the node TOP_NODE at TOP_STR can arrive to the node + LAST_NODE at LAST_STR. We record the path onto PATH since it will be + heavily reused. + Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, + Idx top_str, Idx last_node, Idx last_str, int type) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err = REG_NOERROR; + Idx subexp_num, backup_cur_idx, str_idx, null_cnt; + re_dfastate_t *cur_state = NULL; + re_node_set *cur_nodes, next_nodes; + re_dfastate_t **backup_state_log; + unsigned int context; + + subexp_num = dfa->nodes[top_node].opr.idx; + /* Extend the buffer if we need. */ + if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0)) + { + re_dfastate_t **new_array; + Idx old_alloc = path->alloc; + Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; + Idx new_alloc; + if (BE (IDX_MAX - old_alloc < incr_alloc, 0)) + return REG_ESPACE; + new_alloc = old_alloc + incr_alloc; + if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) + return REG_ESPACE; + new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); + if (BE (new_array == NULL, 0)) + return REG_ESPACE; + path->array = new_array; + path->alloc = new_alloc; + memset (new_array + old_alloc, '\0', + sizeof (re_dfastate_t *) * (path->alloc - old_alloc)); + } + + str_idx = path->next_idx ? path->next_idx : top_str; + + /* Temporary modify MCTX. */ + backup_state_log = mctx->state_log; + backup_cur_idx = mctx->input.cur_idx; + mctx->state_log = path->array; + mctx->input.cur_idx = str_idx; + + /* Setup initial node set. */ + context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); + if (str_idx == top_str) + { + err = re_node_set_init_1 (&next_nodes, top_node); + if (BE (err != REG_NOERROR, 0)) + return err; + err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + } + else + { + cur_state = mctx->state_log[str_idx]; + if (cur_state && cur_state->has_backref) + { + err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); + if (BE (err != REG_NOERROR, 0)) + return err; + } + else + re_node_set_init_empty (&next_nodes); + } + if (str_idx == top_str || (cur_state && cur_state->has_backref)) + { + if (next_nodes.nelem) + { + err = expand_bkref_cache (mctx, &next_nodes, str_idx, + subexp_num, type); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + } + cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); + if (BE (cur_state == NULL && err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + mctx->state_log[str_idx] = cur_state; + } + + for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) + { + re_node_set_empty (&next_nodes); + if (mctx->state_log[str_idx + 1]) + { + err = re_node_set_merge (&next_nodes, + &mctx->state_log[str_idx + 1]->nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + } + if (cur_state) + { + err = check_arrival_add_next_nodes (mctx, str_idx, + &cur_state->non_eps_nodes, + &next_nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + } + ++str_idx; + if (next_nodes.nelem) + { + err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + err = expand_bkref_cache (mctx, &next_nodes, str_idx, + subexp_num, type); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + } + context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); + cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); + if (BE (cur_state == NULL && err != REG_NOERROR, 0)) + { + re_node_set_free (&next_nodes); + return err; + } + mctx->state_log[str_idx] = cur_state; + null_cnt = cur_state == NULL ? null_cnt + 1 : 0; + } + re_node_set_free (&next_nodes); + cur_nodes = (mctx->state_log[last_str] == NULL ? NULL + : &mctx->state_log[last_str]->nodes); + path->next_idx = str_idx; + + /* Fix MCTX. */ + mctx->state_log = backup_state_log; + mctx->input.cur_idx = backup_cur_idx; + + /* Then check the current node set has the node LAST_NODE. */ + if (cur_nodes != NULL && re_node_set_contains (cur_nodes, last_node)) + return REG_NOERROR; + + return REG_NOMATCH; +} + +/* Helper functions for check_arrival. */ + +/* Calculate the destination nodes of CUR_NODES at STR_IDX, and append them + to NEXT_NODES. + TODO: This function is similar to the functions transit_state*(), + however this function has many additional works. + Can't we unify them? */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, + re_node_set *cur_nodes, re_node_set *next_nodes) +{ + const re_dfa_t *const dfa = mctx->dfa; + bool ok; + Idx cur_idx; +#ifdef RE_ENABLE_I18N + reg_errcode_t err = REG_NOERROR; +#endif + re_node_set union_set; + re_node_set_init_empty (&union_set); + for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx) + { + int naccepted = 0; + Idx cur_node = cur_nodes->elems[cur_idx]; +#ifdef DEBUG + re_token_type_t type = dfa->nodes[cur_node].type; + assert (!IS_EPSILON_NODE (type)); +#endif +#ifdef RE_ENABLE_I18N + /* If the node may accept "multi byte". */ + if (dfa->nodes[cur_node].accept_mb) + { + naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input, + str_idx); + if (naccepted > 1) + { + re_dfastate_t *dest_state; + Idx next_node = dfa->nexts[cur_node]; + Idx next_idx = str_idx + naccepted; + dest_state = mctx->state_log[next_idx]; + re_node_set_empty (&union_set); + if (dest_state) + { + err = re_node_set_merge (&union_set, &dest_state->nodes); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&union_set); + return err; + } + } + ok = re_node_set_insert (&union_set, next_node); + if (BE (! ok, 0)) + { + re_node_set_free (&union_set); + return REG_ESPACE; + } + mctx->state_log[next_idx] = re_acquire_state (&err, dfa, + &union_set); + if (BE (mctx->state_log[next_idx] == NULL + && err != REG_NOERROR, 0)) + { + re_node_set_free (&union_set); + return err; + } + } + } +#endif /* RE_ENABLE_I18N */ + if (naccepted + || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) + { + ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]); + if (BE (! ok, 0)) + { + re_node_set_free (&union_set); + return REG_ESPACE; + } + } + } + re_node_set_free (&union_set); + return REG_NOERROR; +} + +/* For all the nodes in CUR_NODES, add the epsilon closures of them to + CUR_NODES, however exclude the nodes which are: + - inside the sub expression whose number is EX_SUBEXP, if FL_OPEN. + - out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN. +*/ + +static reg_errcode_t +internal_function +check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, + Idx ex_subexp, int type) +{ + reg_errcode_t err; + Idx idx, outside_node; + re_node_set new_nodes; +#ifdef DEBUG + assert (cur_nodes->nelem); +#endif + err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); + if (BE (err != REG_NOERROR, 0)) + return err; + /* Create a new node set NEW_NODES with the nodes which are epsilon + closures of the node in CUR_NODES. */ + + for (idx = 0; idx < cur_nodes->nelem; ++idx) + { + Idx cur_node = cur_nodes->elems[idx]; + const re_node_set *eclosure = dfa->eclosures + cur_node; + outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); + if (outside_node == REG_MISSING) + { + /* There are no problematic nodes, just merge them. */ + err = re_node_set_merge (&new_nodes, eclosure); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&new_nodes); + return err; + } + } + else + { + /* There are problematic nodes, re-calculate incrementally. */ + err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node, + ex_subexp, type); + if (BE (err != REG_NOERROR, 0)) + { + re_node_set_free (&new_nodes); + return err; + } + } + } + re_node_set_free (cur_nodes); + *cur_nodes = new_nodes; + return REG_NOERROR; +} + +/* Helper function for check_arrival_expand_ecl. + Check incrementally the epsilon closure of TARGET, and if it isn't + problematic append it to DST_NODES. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, + Idx target, Idx ex_subexp, int type) +{ + Idx cur_node; + for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);) + { + bool ok; + + if (dfa->nodes[cur_node].type == type + && dfa->nodes[cur_node].opr.idx == ex_subexp) + { + if (type == OP_CLOSE_SUBEXP) + { + ok = re_node_set_insert (dst_nodes, cur_node); + if (BE (! ok, 0)) + return REG_ESPACE; + } + break; + } + ok = re_node_set_insert (dst_nodes, cur_node); + if (BE (! ok, 0)) + return REG_ESPACE; + if (dfa->edests[cur_node].nelem == 0) + break; + if (dfa->edests[cur_node].nelem == 2) + { + reg_errcode_t err; + err = check_arrival_expand_ecl_sub (dfa, dst_nodes, + dfa->edests[cur_node].elems[1], + ex_subexp, type); + if (BE (err != REG_NOERROR, 0)) + return err; + } + cur_node = dfa->edests[cur_node].elems[0]; + } + return REG_NOERROR; +} + + +/* For all the back references in the current state, calculate the + destination of the back references by the appropriate entry + in MCTX->BKREF_ENTS. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, + Idx cur_str, Idx subexp_num, int type) +{ + const re_dfa_t *const dfa = mctx->dfa; + reg_errcode_t err; + Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); + struct re_backref_cache_entry *ent; + + if (cache_idx_start == REG_MISSING) + return REG_NOERROR; + + restart: + ent = mctx->bkref_ents + cache_idx_start; + do + { + Idx to_idx, next_node; + + /* Is this entry ENT is appropriate? */ + if (!re_node_set_contains (cur_nodes, ent->node)) + continue; /* No. */ + + to_idx = cur_str + ent->subexp_to - ent->subexp_from; + /* Calculate the destination of the back reference, and append it + to MCTX->STATE_LOG. */ + if (to_idx == cur_str) + { + /* The backreference did epsilon transit, we must re-check all the + node in the current state. */ + re_node_set new_dests; + reg_errcode_t err2, err3; + next_node = dfa->edests[ent->node].elems[0]; + if (re_node_set_contains (cur_nodes, next_node)) + continue; + err = re_node_set_init_1 (&new_dests, next_node); + err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type); + err3 = re_node_set_merge (cur_nodes, &new_dests); + re_node_set_free (&new_dests); + if (BE (err != REG_NOERROR || err2 != REG_NOERROR + || err3 != REG_NOERROR, 0)) + { + err = (err != REG_NOERROR ? err + : (err2 != REG_NOERROR ? err2 : err3)); + return err; + } + /* TODO: It is still inefficient... */ + goto restart; + } + else + { + re_node_set union_set; + next_node = dfa->nexts[ent->node]; + if (mctx->state_log[to_idx]) + { + bool ok; + if (re_node_set_contains (&mctx->state_log[to_idx]->nodes, + next_node)) + continue; + err = re_node_set_init_copy (&union_set, + &mctx->state_log[to_idx]->nodes); + ok = re_node_set_insert (&union_set, next_node); + if (BE (err != REG_NOERROR || ! ok, 0)) + { + re_node_set_free (&union_set); + err = err != REG_NOERROR ? err : REG_ESPACE; + return err; + } + } + else + { + err = re_node_set_init_1 (&union_set, next_node); + if (BE (err != REG_NOERROR, 0)) + return err; + } + mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); + re_node_set_free (&union_set); + if (BE (mctx->state_log[to_idx] == NULL + && err != REG_NOERROR, 0)) + return err; + } + } + while (ent++->more); + return REG_NOERROR; +} + +/* Build transition table for the state. + Return true if successful. */ + +static bool +internal_function +build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) +{ + reg_errcode_t err; + Idx i, j; + int ch; + bool need_word_trtable = false; + bitset_word_t elem, mask; + bool dests_node_malloced = false; + bool dest_states_malloced = false; + Idx ndests; /* Number of the destination states from 'state'. */ + re_dfastate_t **trtable; + re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; + re_node_set follows, *dests_node; + bitset_t *dests_ch; + bitset_t acceptable; + + struct dests_alloc + { + re_node_set dests_node[SBC_MAX]; + bitset_t dests_ch[SBC_MAX]; + } *dests_alloc; + + /* We build DFA states which corresponds to the destination nodes + from 'state'. 'dests_node[i]' represents the nodes which i-th + destination state contains, and 'dests_ch[i]' represents the + characters which i-th destination state accepts. */ + if (__libc_use_alloca (sizeof (struct dests_alloc))) + dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); + else + { + dests_alloc = re_malloc (struct dests_alloc, 1); + if (BE (dests_alloc == NULL, 0)) + return false; + dests_node_malloced = true; + } + dests_node = dests_alloc->dests_node; + dests_ch = dests_alloc->dests_ch; + + /* Initialize transition table. */ + state->word_trtable = state->trtable = NULL; + + /* At first, group all nodes belonging to 'state' into several + destinations. */ + ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); + if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0)) + { + if (dests_node_malloced) + free (dests_alloc); + /* Return false in case of an error, true otherwise. */ + if (ndests == 0) + { + state->trtable = (re_dfastate_t **) + calloc (sizeof (re_dfastate_t *), SBC_MAX); + if (BE (state->trtable == NULL, 0)) + return false; + return true; + } + return false; + } + + err = re_node_set_alloc (&follows, ndests + 1); + if (BE (err != REG_NOERROR, 0)) + goto out_free; + + /* Avoid arithmetic overflow in size calculation. */ + if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) + / (3 * sizeof (re_dfastate_t *))) + < ndests), + 0)) + goto out_free; + + if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX + + ndests * 3 * sizeof (re_dfastate_t *))) + dest_states = (re_dfastate_t **) + alloca (ndests * 3 * sizeof (re_dfastate_t *)); + else + { + dest_states = (re_dfastate_t **) + malloc (ndests * 3 * sizeof (re_dfastate_t *)); + if (BE (dest_states == NULL, 0)) + { +out_free: + if (dest_states_malloced) + free (dest_states); + re_node_set_free (&follows); + for (i = 0; i < ndests; ++i) + re_node_set_free (dests_node + i); + if (dests_node_malloced) + free (dests_alloc); + return false; + } + dest_states_malloced = true; + } + dest_states_word = dest_states + ndests; + dest_states_nl = dest_states_word + ndests; + bitset_empty (acceptable); + + /* Then build the states for all destinations. */ + for (i = 0; i < ndests; ++i) + { + Idx next_node; + re_node_set_empty (&follows); + /* Merge the follows of this destination states. */ + for (j = 0; j < dests_node[i].nelem; ++j) + { + next_node = dfa->nexts[dests_node[i].elems[j]]; + if (next_node != REG_MISSING) + { + err = re_node_set_merge (&follows, dfa->eclosures + next_node); + if (BE (err != REG_NOERROR, 0)) + goto out_free; + } + } + dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0); + if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0)) + goto out_free; + /* If the new state has context constraint, + build appropriate states for these contexts. */ + if (dest_states[i]->has_constraint) + { + dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows, + CONTEXT_WORD); + if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0)) + goto out_free; + + if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1) + need_word_trtable = true; + + dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows, + CONTEXT_NEWLINE); + if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0)) + goto out_free; + } + else + { + dest_states_word[i] = dest_states[i]; + dest_states_nl[i] = dest_states[i]; + } + bitset_merge (acceptable, dests_ch[i]); + } + + if (!BE (need_word_trtable, 0)) + { + /* We don't care about whether the following character is a word + character, or we are in a single-byte character set so we can + discern by looking at the character code: allocate a + 256-entry transition table. */ + trtable = state->trtable = + (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); + if (BE (trtable == NULL, 0)) + goto out_free; + + /* For all characters ch...: */ + for (i = 0; i < BITSET_WORDS; ++i) + for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; + elem; + mask <<= 1, elem >>= 1, ++ch) + if (BE (elem & 1, 0)) + { + /* There must be exactly one destination which accepts + character ch. See group_nodes_into_DFAstates. */ + for (j = 0; (dests_ch[j][i] & mask) == 0; ++j) + ; + + /* j-th destination accepts the word character ch. */ + if (dfa->word_char[i] & mask) + trtable[ch] = dest_states_word[j]; + else + trtable[ch] = dest_states[j]; + } + } + else + { + /* We care about whether the following character is a word + character, and we are in a multi-byte character set: discern + by looking at the character code: build two 256-entry + transition tables, one starting at trtable[0] and one + starting at trtable[SBC_MAX]. */ + trtable = state->word_trtable = + (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); + if (BE (trtable == NULL, 0)) + goto out_free; + + /* For all characters ch...: */ + for (i = 0; i < BITSET_WORDS; ++i) + for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; + elem; + mask <<= 1, elem >>= 1, ++ch) + if (BE (elem & 1, 0)) + { + /* There must be exactly one destination which accepts + character ch. See group_nodes_into_DFAstates. */ + for (j = 0; (dests_ch[j][i] & mask) == 0; ++j) + ; + + /* j-th destination accepts the word character ch. */ + trtable[ch] = dest_states[j]; + trtable[ch + SBC_MAX] = dest_states_word[j]; + } + } + + /* new line */ + if (bitset_contain (acceptable, NEWLINE_CHAR)) + { + /* The current state accepts newline character. */ + for (j = 0; j < ndests; ++j) + if (bitset_contain (dests_ch[j], NEWLINE_CHAR)) + { + /* k-th destination accepts newline character. */ + trtable[NEWLINE_CHAR] = dest_states_nl[j]; + if (need_word_trtable) + trtable[NEWLINE_CHAR + SBC_MAX] = dest_states_nl[j]; + /* There must be only one destination which accepts + newline. See group_nodes_into_DFAstates. */ + break; + } + } + + if (dest_states_malloced) + free (dest_states); + + re_node_set_free (&follows); + for (i = 0; i < ndests; ++i) + re_node_set_free (dests_node + i); + + if (dests_node_malloced) + free (dests_alloc); + + return true; +} + +/* Group all nodes belonging to STATE into several destinations. + Then for all destinations, set the nodes belonging to the destination + to DESTS_NODE[i] and set the characters accepted by the destination + to DEST_CH[i]. This function return the number of destinations. */ + +static Idx +internal_function +group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, + re_node_set *dests_node, bitset_t *dests_ch) +{ + reg_errcode_t err; + bool ok; + Idx i, j, k; + Idx ndests; /* Number of the destinations from 'state'. */ + bitset_t accepts; /* Characters a node can accept. */ + const re_node_set *cur_nodes = &state->nodes; + bitset_empty (accepts); + ndests = 0; + + /* For all the nodes belonging to 'state', */ + for (i = 0; i < cur_nodes->nelem; ++i) + { + re_token_t *node = &dfa->nodes[cur_nodes->elems[i]]; + re_token_type_t type = node->type; + unsigned int constraint = node->constraint; + + /* Enumerate all single byte character this node can accept. */ + if (type == CHARACTER) + bitset_set (accepts, node->opr.c); + else if (type == SIMPLE_BRACKET) + { + bitset_merge (accepts, node->opr.sbcset); + } + else if (type == OP_PERIOD) + { +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + bitset_merge (accepts, dfa->sb_char); + else +#endif + bitset_set_all (accepts); + if (!(dfa->syntax & RE_DOT_NEWLINE)) + bitset_clear (accepts, '\n'); + if (dfa->syntax & RE_DOT_NOT_NULL) + bitset_clear (accepts, '\0'); + } +#ifdef RE_ENABLE_I18N + else if (type == OP_UTF8_PERIOD) + { + if (ASCII_CHARS % BITSET_WORD_BITS == 0) + memset (accepts, -1, ASCII_CHARS / CHAR_BIT); + else + bitset_merge (accepts, utf8_sb_map); + if (!(dfa->syntax & RE_DOT_NEWLINE)) + bitset_clear (accepts, '\n'); + if (dfa->syntax & RE_DOT_NOT_NULL) + bitset_clear (accepts, '\0'); + } +#endif + else + continue; + + /* Check the 'accepts' and sift the characters which are not + match it the context. */ + if (constraint) + { + if (constraint & NEXT_NEWLINE_CONSTRAINT) + { + bool accepts_newline = bitset_contain (accepts, NEWLINE_CHAR); + bitset_empty (accepts); + if (accepts_newline) + bitset_set (accepts, NEWLINE_CHAR); + else + continue; + } + if (constraint & NEXT_ENDBUF_CONSTRAINT) + { + bitset_empty (accepts); + continue; + } + + if (constraint & NEXT_WORD_CONSTRAINT) + { + bitset_word_t any_set = 0; + if (type == CHARACTER && !node->word_char) + { + bitset_empty (accepts); + continue; + } +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + for (j = 0; j < BITSET_WORDS; ++j) + any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j])); + else +#endif + for (j = 0; j < BITSET_WORDS; ++j) + any_set |= (accepts[j] &= dfa->word_char[j]); + if (!any_set) + continue; + } + if (constraint & NEXT_NOTWORD_CONSTRAINT) + { + bitset_word_t any_set = 0; + if (type == CHARACTER && node->word_char) + { + bitset_empty (accepts); + continue; + } +#ifdef RE_ENABLE_I18N + if (dfa->mb_cur_max > 1) + for (j = 0; j < BITSET_WORDS; ++j) + any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j])); + else +#endif + for (j = 0; j < BITSET_WORDS; ++j) + any_set |= (accepts[j] &= ~dfa->word_char[j]); + if (!any_set) + continue; + } + } + + /* Then divide 'accepts' into DFA states, or create a new + state. Above, we make sure that accepts is not empty. */ + for (j = 0; j < ndests; ++j) + { + bitset_t intersec; /* Intersection sets, see below. */ + bitset_t remains; + /* Flags, see below. */ + bitset_word_t has_intersec, not_subset, not_consumed; + + /* Optimization, skip if this state doesn't accept the character. */ + if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c)) + continue; + + /* Enumerate the intersection set of this state and 'accepts'. */ + has_intersec = 0; + for (k = 0; k < BITSET_WORDS; ++k) + has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k]; + /* And skip if the intersection set is empty. */ + if (!has_intersec) + continue; + + /* Then check if this state is a subset of 'accepts'. */ + not_subset = not_consumed = 0; + for (k = 0; k < BITSET_WORDS; ++k) + { + not_subset |= remains[k] = ~accepts[k] & dests_ch[j][k]; + not_consumed |= accepts[k] = accepts[k] & ~dests_ch[j][k]; + } + + /* If this state isn't a subset of 'accepts', create a + new group state, which has the 'remains'. */ + if (not_subset) + { + bitset_copy (dests_ch[ndests], remains); + bitset_copy (dests_ch[j], intersec); + err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]); + if (BE (err != REG_NOERROR, 0)) + goto error_return; + ++ndests; + } + + /* Put the position in the current group. */ + ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]); + if (BE (! ok, 0)) + goto error_return; + + /* If all characters are consumed, go to next node. */ + if (!not_consumed) + break; + } + /* Some characters remain, create a new group. */ + if (j == ndests) + { + bitset_copy (dests_ch[ndests], accepts); + err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); + if (BE (err != REG_NOERROR, 0)) + goto error_return; + ++ndests; + bitset_empty (accepts); + } + } + return ndests; + error_return: + for (j = 0; j < ndests; ++j) + re_node_set_free (dests_node + j); + return REG_MISSING; +} + +#ifdef RE_ENABLE_I18N +/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts. + Return the number of the bytes the node accepts. + STR_IDX is the current index of the input string. + + This function handles the nodes which can accept one character, or + one collating element like '.', '[a-z]', opposite to the other nodes + can only accept one byte. */ + +static int +internal_function +check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, + const re_string_t *input, Idx str_idx) +{ + const re_token_t *node = dfa->nodes + node_idx; + int char_len, elem_len; + Idx i; + + if (BE (node->type == OP_UTF8_PERIOD, 0)) + { + unsigned char c = re_string_byte_at (input, str_idx), d; + if (BE (c < 0xc2, 1)) + return 0; + + if (str_idx + 2 > input->len) + return 0; + + d = re_string_byte_at (input, str_idx + 1); + if (c < 0xe0) + return (d < 0x80 || d > 0xbf) ? 0 : 2; + else if (c < 0xf0) + { + char_len = 3; + if (c == 0xe0 && d < 0xa0) + return 0; + } + else if (c < 0xf8) + { + char_len = 4; + if (c == 0xf0 && d < 0x90) + return 0; + } + else if (c < 0xfc) + { + char_len = 5; + if (c == 0xf8 && d < 0x88) + return 0; + } + else if (c < 0xfe) + { + char_len = 6; + if (c == 0xfc && d < 0x84) + return 0; + } + else + return 0; + + if (str_idx + char_len > input->len) + return 0; + + for (i = 1; i < char_len; ++i) + { + d = re_string_byte_at (input, str_idx + i); + if (d < 0x80 || d > 0xbf) + return 0; + } + return char_len; + } + + char_len = re_string_char_size_at (input, str_idx); + if (node->type == OP_PERIOD) + { + if (char_len <= 1) + return 0; + /* FIXME: I don't think this if is needed, as both '\n' + and '\0' are char_len == 1. */ + /* '.' accepts any one character except the following two cases. */ + if ((!(dfa->syntax & RE_DOT_NEWLINE) && + re_string_byte_at (input, str_idx) == '\n') || + ((dfa->syntax & RE_DOT_NOT_NULL) && + re_string_byte_at (input, str_idx) == '\0')) + return 0; + return char_len; + } + + elem_len = re_string_elem_size_at (input, str_idx); + if ((elem_len <= 1 && char_len <= 1) || char_len == 0) + return 0; + + if (node->type == COMPLEX_BRACKET) + { + const re_charset_t *cset = node->opr.mbcset; +# ifdef _LIBC + const unsigned char *pin + = ((const unsigned char *) re_string_get_buffer (input) + str_idx); + Idx j; + uint32_t nrules; +# endif /* _LIBC */ + int match_len = 0; + wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars) + ? re_string_wchar_at (input, str_idx) : 0); + + /* match with multibyte character? */ + for (i = 0; i < cset->nmbchars; ++i) + if (wc == cset->mbchars[i]) + { + match_len = char_len; + goto check_node_accept_bytes_match; + } + /* match with character_class? */ + for (i = 0; i < cset->nchar_classes; ++i) + { + wctype_t wt = cset->char_classes[i]; + if (__iswctype (wc, wt)) + { + match_len = char_len; + goto check_node_accept_bytes_match; + } + } + +# ifdef _LIBC + nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + if (nrules != 0) + { + unsigned int in_collseq = 0; + const int32_t *table, *indirect; + const unsigned char *weights, *extra; + const char *collseqwc; + /* This #include defines a local function! */ +# include + + /* match with collating_symbol? */ + if (cset->ncoll_syms) + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB); + for (i = 0; i < cset->ncoll_syms; ++i) + { + const unsigned char *coll_sym = extra + cset->coll_syms[i]; + /* Compare the length of input collating element and + the length of current collating element. */ + if (*coll_sym != elem_len) + continue; + /* Compare each bytes. */ + for (j = 0; j < *coll_sym; j++) + if (pin[j] != coll_sym[1 + j]) + break; + if (j == *coll_sym) + { + /* Match if every bytes is equal. */ + match_len = j; + goto check_node_accept_bytes_match; + } + } + + if (cset->nranges) + { + if (elem_len <= char_len) + { + collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC); + in_collseq = __collseq_table_lookup (collseqwc, wc); + } + else + in_collseq = find_collation_sequence_value (pin, elem_len); + } + /* match with range expression? */ + /* FIXME: Implement rational ranges here, too. */ + for (i = 0; i < cset->nranges; ++i) + if (cset->range_starts[i] <= in_collseq + && in_collseq <= cset->range_ends[i]) + { + match_len = elem_len; + goto check_node_accept_bytes_match; + } + + /* match with equivalence_class? */ + if (cset->nequiv_classes) + { + const unsigned char *cp = pin; + table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); + weights = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB); + extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); + indirect = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB); + int32_t idx = findidx (&cp, elem_len); + if (idx > 0) + for (i = 0; i < cset->nequiv_classes; ++i) + { + int32_t equiv_class_idx = cset->equiv_classes[i]; + size_t weight_len = weights[idx & 0xffffff]; + if (weight_len == weights[equiv_class_idx & 0xffffff] + && (idx >> 24) == (equiv_class_idx >> 24)) + { + Idx cnt = 0; + + idx &= 0xffffff; + equiv_class_idx &= 0xffffff; + + while (cnt <= weight_len + && (weights[equiv_class_idx + 1 + cnt] + == weights[idx + 1 + cnt])) + ++cnt; + if (cnt > weight_len) + { + match_len = elem_len; + goto check_node_accept_bytes_match; + } + } + } + } + } + else +# endif /* _LIBC */ + { + /* match with range expression? */ + for (i = 0; i < cset->nranges; ++i) + { + if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i]) + { + match_len = char_len; + goto check_node_accept_bytes_match; + } + } + } + check_node_accept_bytes_match: + if (!cset->non_match) + return match_len; + else + { + if (match_len > 0) + return 0; + else + return (elem_len > char_len) ? elem_len : char_len; + } + } + return 0; +} + +# ifdef _LIBC +static unsigned int +internal_function +find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) +{ + uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + if (nrules == 0) + { + if (mbs_len == 1) + { + /* No valid character. Match it as a single byte character. */ + const unsigned char *collseq = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB); + return collseq[mbs[0]]; + } + return UINT_MAX; + } + else + { + int32_t idx; + const unsigned char *extra = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB); + int32_t extrasize = (const unsigned char *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB + 1) - extra; + + for (idx = 0; idx < extrasize;) + { + int mbs_cnt; + bool found = false; + int32_t elem_mbs_len; + /* Skip the name of collating element name. */ + idx = idx + extra[idx] + 1; + elem_mbs_len = extra[idx++]; + if (mbs_len == elem_mbs_len) + { + for (mbs_cnt = 0; mbs_cnt < elem_mbs_len; ++mbs_cnt) + if (extra[idx + mbs_cnt] != mbs[mbs_cnt]) + break; + if (mbs_cnt == elem_mbs_len) + /* Found the entry. */ + found = true; + } + /* Skip the byte sequence of the collating element. */ + idx += elem_mbs_len; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~3; + /* Skip the collation sequence value. */ + idx += sizeof (uint32_t); + /* Skip the wide char sequence of the collating element. */ + idx = idx + sizeof (uint32_t) * (*(int32_t *) (extra + idx) + 1); + /* If we found the entry, return the sequence value. */ + if (found) + return *(uint32_t *) (extra + idx); + /* Skip the collation sequence value. */ + idx += sizeof (uint32_t); + } + return UINT_MAX; + } +} +# endif /* _LIBC */ +#endif /* RE_ENABLE_I18N */ + +/* Check whether the node accepts the byte which is IDX-th + byte of the INPUT. */ + +static bool +internal_function +check_node_accept (const re_match_context_t *mctx, const re_token_t *node, + Idx idx) +{ + unsigned char ch; + ch = re_string_byte_at (&mctx->input, idx); + switch (node->type) + { + case CHARACTER: + if (node->opr.c != ch) + return false; + break; + + case SIMPLE_BRACKET: + if (!bitset_contain (node->opr.sbcset, ch)) + return false; + break; + +#ifdef RE_ENABLE_I18N + case OP_UTF8_PERIOD: + if (ch >= ASCII_CHARS) + return false; + /* FALLTHROUGH */ +#endif + case OP_PERIOD: + if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) + || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) + return false; + break; + + default: + return false; + } + + if (node->constraint) + { + /* The node has constraints. Check whether the current context + satisfies the constraints. */ + unsigned int context = re_string_context_at (&mctx->input, idx, + mctx->eflags); + if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context)) + return false; + } + + return true; +} + +/* Extend the buffers, if the buffers have run out. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +extend_buffers (re_match_context_t *mctx, int min_len) +{ + reg_errcode_t ret; + re_string_t *pstr = &mctx->input; + + /* Avoid overflow. */ + if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2 + <= pstr->bufs_len, 0)) + return REG_ESPACE; + + /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ + ret = re_string_realloc_buffers (pstr, + MAX (min_len, + MIN (pstr->len, pstr->bufs_len * 2))); + if (BE (ret != REG_NOERROR, 0)) + return ret; + + if (mctx->state_log != NULL) + { + /* And double the length of state_log. */ + /* XXX We have no indication of the size of this buffer. If this + allocation fail we have no indication that the state_log array + does not have the right size. */ + re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, + pstr->bufs_len + 1); + if (BE (new_array == NULL, 0)) + return REG_ESPACE; + mctx->state_log = new_array; + } + + /* Then reconstruct the buffers. */ + if (pstr->icase) + { +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + { + ret = build_wcs_upper_buffer (pstr); + if (BE (ret != REG_NOERROR, 0)) + return ret; + } + else +#endif /* RE_ENABLE_I18N */ + build_upper_buffer (pstr); + } + else + { +#ifdef RE_ENABLE_I18N + if (pstr->mb_cur_max > 1) + build_wcs_buffer (pstr); + else +#endif /* RE_ENABLE_I18N */ + { + if (pstr->trans != NULL) + re_string_translate_buffer (pstr); + } + } + return REG_NOERROR; +} + + +/* Functions for matching context. */ + +/* Initialize MCTX. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) +{ + mctx->eflags = eflags; + mctx->match_last = REG_MISSING; + if (n > 0) + { + /* Avoid overflow. */ + size_t max_object_size = + MAX (sizeof (struct re_backref_cache_entry), + sizeof (re_sub_match_top_t *)); + if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0)) + return REG_ESPACE; + + mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); + mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); + if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) + return REG_ESPACE; + } + /* Already zero-ed by the caller. + else + mctx->bkref_ents = NULL; + mctx->nbkref_ents = 0; + mctx->nsub_tops = 0; */ + mctx->abkref_ents = n; + mctx->max_mb_elem_len = 1; + mctx->asub_tops = n; + return REG_NOERROR; +} + +/* Clean the entries which depend on the current input in MCTX. + This function must be invoked when the matcher changes the start index + of the input, or changes the input string. */ + +static void +internal_function +match_ctx_clean (re_match_context_t *mctx) +{ + Idx st_idx; + for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx) + { + Idx sl_idx; + re_sub_match_top_t *top = mctx->sub_tops[st_idx]; + for (sl_idx = 0; sl_idx < top->nlasts; ++sl_idx) + { + re_sub_match_last_t *last = top->lasts[sl_idx]; + re_free (last->path.array); + re_free (last); + } + re_free (top->lasts); + if (top->path) + { + re_free (top->path->array); + re_free (top->path); + } + free (top); + } + + mctx->nsub_tops = 0; + mctx->nbkref_ents = 0; +} + +/* Free all the memory associated with MCTX. */ + +static void +internal_function +match_ctx_free (re_match_context_t *mctx) +{ + /* First, free all the memory associated with MCTX->SUB_TOPS. */ + match_ctx_clean (mctx); + re_free (mctx->sub_tops); + re_free (mctx->bkref_ents); +} + +/* Add a new backreference entry to MCTX. + Note that we assume that caller never call this function with duplicate + entry, and call with STR_IDX which isn't smaller than any existing entry. +*/ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, + Idx to) +{ + if (mctx->nbkref_ents >= mctx->abkref_ents) + { + struct re_backref_cache_entry* new_entry; + new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, + mctx->abkref_ents * 2); + if (BE (new_entry == NULL, 0)) + { + re_free (mctx->bkref_ents); + return REG_ESPACE; + } + mctx->bkref_ents = new_entry; + memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', + sizeof (struct re_backref_cache_entry) * mctx->abkref_ents); + mctx->abkref_ents *= 2; + } + if (mctx->nbkref_ents > 0 + && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx) + mctx->bkref_ents[mctx->nbkref_ents - 1].more = 1; + + mctx->bkref_ents[mctx->nbkref_ents].node = node; + mctx->bkref_ents[mctx->nbkref_ents].str_idx = str_idx; + mctx->bkref_ents[mctx->nbkref_ents].subexp_from = from; + mctx->bkref_ents[mctx->nbkref_ents].subexp_to = to; + + /* This is a cache that saves negative results of check_dst_limits_calc_pos. + If bit N is clear, means that this entry won't epsilon-transition to + an OP_OPEN_SUBEXP or OP_CLOSE_SUBEXP for the N+1-th subexpression. If + it is set, check_dst_limits_calc_pos_1 will recurse and try to find one + such node. + + A backreference does not epsilon-transition unless it is empty, so set + to all zeros if FROM != TO. */ + mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map + = (from == to ? -1 : 0); + + mctx->bkref_ents[mctx->nbkref_ents++].more = 0; + if (mctx->max_mb_elem_len < to - from) + mctx->max_mb_elem_len = to - from; + return REG_NOERROR; +} + +/* Return the first entry with the same str_idx, or REG_MISSING if none is + found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */ + +static Idx +internal_function +search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx) +{ + Idx left, right, mid, last; + last = right = mctx->nbkref_ents; + for (left = 0; left < right;) + { + mid = (left + right) / 2; + if (mctx->bkref_ents[mid].str_idx < str_idx) + left = mid + 1; + else + right = mid; + } + if (left < last && mctx->bkref_ents[left].str_idx == str_idx) + return left; + else + return REG_MISSING; +} + +/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches + at STR_IDX. */ + +static reg_errcode_t +internal_function __attribute_warn_unused_result__ +match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) +{ +#ifdef DEBUG + assert (mctx->sub_tops != NULL); + assert (mctx->asub_tops > 0); +#endif + if (BE (mctx->nsub_tops == mctx->asub_tops, 0)) + { + Idx new_asub_tops = mctx->asub_tops * 2; + re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, + re_sub_match_top_t *, + new_asub_tops); + if (BE (new_array == NULL, 0)) + return REG_ESPACE; + mctx->sub_tops = new_array; + mctx->asub_tops = new_asub_tops; + } + mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); + if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) + return REG_ESPACE; + mctx->sub_tops[mctx->nsub_tops]->node = node; + mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; + return REG_NOERROR; +} + +/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches + at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */ + +static re_sub_match_last_t * +internal_function +match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) +{ + re_sub_match_last_t *new_entry; + if (BE (subtop->nlasts == subtop->alasts, 0)) + { + Idx new_alasts = 2 * subtop->alasts + 1; + re_sub_match_last_t **new_array = re_realloc (subtop->lasts, + re_sub_match_last_t *, + new_alasts); + if (BE (new_array == NULL, 0)) + return NULL; + subtop->lasts = new_array; + subtop->alasts = new_alasts; + } + new_entry = calloc (1, sizeof (re_sub_match_last_t)); + if (BE (new_entry != NULL, 1)) + { + subtop->lasts[subtop->nlasts] = new_entry; + new_entry->node = node; + new_entry->str_idx = str_idx; + ++subtop->nlasts; + } + return new_entry; +} + +static void +internal_function +sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, + re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx) +{ + sctx->sifted_states = sifted_sts; + sctx->limited_states = limited_sts; + sctx->last_node = last_node; + sctx->last_str_idx = last_str_idx; + re_node_set_init_empty (&sctx->limits); +} diff --git a/grub-core/gnulib/size_max.h b/grub-core/gnulib/size_max.h new file mode 100644 index 000000000..5f3312404 --- /dev/null +++ b/grub-core/gnulib/size_max.h @@ -0,0 +1,30 @@ +/* size_max.h -- declare SIZE_MAX through system headers + Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef GNULIB_SIZE_MAX_H +#define GNULIB_SIZE_MAX_H + +/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */ +# include +/* Get SIZE_MAX declaration on systems like glibc 2. */ +# if HAVE_STDINT_H +# include +# endif +/* On systems where these include files don't define it, SIZE_MAX is defined + in config.h. */ + +#endif /* GNULIB_SIZE_MAX_H */ diff --git a/grub-core/gnulib/sleep.c b/grub-core/gnulib/sleep.c new file mode 100644 index 000000000..4c97d7dfa --- /dev/null +++ b/grub-core/gnulib/sleep.c @@ -0,0 +1,76 @@ +/* Pausing execution of the current thread. + Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2007. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include + +#include "verify.h" + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +unsigned int +sleep (unsigned int seconds) +{ + unsigned int remaining; + + /* Sleep for 1 second many times, because + 1. Sleep is not interruptible by Ctrl-C, + 2. we want to avoid arithmetic overflow while multiplying with 1000. */ + for (remaining = seconds; remaining > 0; remaining--) + Sleep (1000); + + return remaining; +} + +#elif HAVE_SLEEP + +# undef sleep + +/* Guarantee unlimited sleep and a reasonable return value. Cygwin + 1.5.x rejects attempts to sleep more than 49.7 days (2**32 + milliseconds), but uses uninitialized memory which results in a + garbage answer. Similarly, Linux 2.6.9 with glibc 2.3.4 has a too + small return value when asked to sleep more than 24.85 days. */ +unsigned int +rpl_sleep (unsigned int seconds) +{ + /* This requires int larger than 16 bits. */ + verify (UINT_MAX / 24 / 24 / 60 / 60); + const unsigned int limit = 24 * 24 * 60 * 60; + while (limit < seconds) + { + unsigned int result; + seconds -= limit; + result = sleep (limit); + if (result) + return seconds + result; + } + return sleep (seconds); +} + +#else /* !HAVE_SLEEP */ + + #error "Please port gnulib sleep.c to your platform, possibly using usleep() or select(), then report this to bug-gnulib." + +#endif diff --git a/grub-core/gnulib/stdalign.in.h b/grub-core/gnulib/stdalign.in.h new file mode 100644 index 000000000..c3a67321b --- /dev/null +++ b/grub-core/gnulib/stdalign.in.h @@ -0,0 +1,90 @@ +/* A substitute for ISO C11 . + + Copyright 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Paul Eggert and Bruno Haible. */ + +#ifndef _GL_STDALIGN_H +#define _GL_STDALIGN_H + +/* ISO C11 for platforms that lack it. + + References: + ISO C11 (latest free draft + ) + sections 6.5.3.4, 6.7.5, 7.15. + C++11 (latest free draft + ) + section 18.10. */ + +/* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment + requirement of a structure member (i.e., slot or field) that is of + type TYPE, as an integer constant expression. + + This differs from GCC's __alignof__ operator, which can yield a + better-performing alignment for an object of that type. For + example, on x86 with GCC, __alignof__ (double) and __alignof__ + (long long) are 8, whereas alignof (double) and alignof (long long) + are 4 unless the option '-malign-double' is used. + + The result cannot be used as a value for an 'enum' constant, if you + want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */ +#include +#if defined __cplusplus + template struct __alignof_helper { char __a; __t __b; }; +# define _Alignof(type) offsetof (__alignof_helper, __b) +#else +# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) +#endif +#define alignof _Alignof +#define __alignof_is_defined 1 + +/* alignas (A), also known as _Alignas (A), aligns a variable or type + to the alignment A, where A is an integer constant expression. For + example: + + int alignas (8) foo; + struct s { int a; int alignas (8) bar; }; + + aligns the address of FOO and the offset of BAR to be multiples of 8. + + A should be a power of two that is at least the type's alignment + and at most the implementation's alignment limit. This limit is + 2**28 on typical GNUish hosts, and 2**13 on MSVC. To be portable + to MSVC through at least version 10.0, A should be an integer + constant, as MSVC does not support expressions such as 1 << 3. + To be portable to Sun C 5.11, do not align auto variables to + anything stricter than their default alignment. + + The following C11 requirements are not supported here: + + - If A is zero, alignas has no effect. + - alignas can be used multiple times; the strictest one wins. + - alignas (TYPE) is equivalent to alignas (alignof (TYPE)). + + */ + +#if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C +# define _Alignas(a) __attribute__ ((__aligned__ (a))) +#elif 1300 <= _MSC_VER +# define _Alignas(a) __declspec (align (a)) +#endif +#ifdef _Alignas +# define alignas _Alignas +# define __alignas_is_defined 1 +#endif + +#endif /* _GL_STDALIGN_H */ diff --git a/grub-core/gnulib/stdbool.in.h b/grub-core/gnulib/stdbool.in.h new file mode 100644 index 000000000..7c1577277 --- /dev/null +++ b/grub-core/gnulib/stdbool.in.h @@ -0,0 +1,132 @@ +/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _GL_STDBOOL_H +#define _GL_STDBOOL_H + +/* ISO C 99 for platforms that lack it. */ + +/* Usage suggestions: + + Programs that use should be aware of some limitations + and standards compliance issues. + + Standards compliance: + + - must be #included before 'bool', 'false', 'true' + can be used. + + - You cannot assume that sizeof (bool) == 1. + + - Programs should not undefine the macros bool, true, and false, + as C99 lists that as an "obsolescent feature". + + Limitations of this substitute, when used in a C89 environment: + + - must be #included before the '_Bool' type can be used. + + - You cannot assume that _Bool is a typedef; it might be a macro. + + - Bit-fields of type 'bool' are not supported. Portable code + should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'. + + - In C99, casts and automatic conversions to '_Bool' or 'bool' are + performed in such a way that every nonzero value gets converted + to 'true', and zero gets converted to 'false'. This doesn't work + with this substitute. With this substitute, only the values 0 and 1 + give the expected result when converted to _Bool' or 'bool'. + + - C99 allows the use of (_Bool)0.0 in constant expressions, but + this substitute cannot always provide this property. + + Also, it is suggested that programs use 'bool' rather than '_Bool'; + this isn't required, but 'bool' is more common. */ + + +/* 7.16. Boolean type and values */ + +/* BeOS already #defines false 0, true 1. We use the same + definitions below, but temporarily we have to #undef them. */ +#if defined __BEOS__ && !defined __HAIKU__ +# include /* defines bool but not _Bool */ +# undef false +# undef true +#endif + +#ifdef __cplusplus +# define _Bool bool +# define bool bool +#else +# if defined __BEOS__ && !defined __HAIKU__ + /* A compiler known to have 'bool'. */ + /* If the compiler already has both 'bool' and '_Bool', we can assume they + are the same types. */ +# if !@HAVE__BOOL@ +typedef bool _Bool; +# endif +# else +# if !defined __GNUC__ + /* If @HAVE__BOOL@: + Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when + the built-in _Bool type is used. See + http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html + Similar bugs are likely with other compilers as well; this file + wouldn't be used if was working. + So we override the _Bool type. + If !@HAVE__BOOL@: + Need to define _Bool ourselves. As 'signed char' or as an enum type? + Use of a typedef, with SunPRO C, leads to a stupid + "warning: _Bool is a keyword in ISO C99". + Use of an enum type, with IRIX cc, leads to a stupid + "warning(1185): enumerated type mixed with another type". + Even the existence of an enum type, without a typedef, + "Invalid enumerator. (badenum)" with HP-UX cc on Tru64. + The only benefit of the enum, debuggability, is not important + with these compilers. So use 'signed char' and no enum. */ +# define _Bool signed char +# else + /* With this compiler, trust the _Bool type if the compiler has it. */ +# if !@HAVE__BOOL@ + /* For the sake of symbolic names in gdb, define true and false as + enum constants, not only as macros. + It is tempting to write + typedef enum { false = 0, true = 1 } _Bool; + so that gdb prints values of type 'bool' symbolically. But then + values of type '_Bool' might promote to 'int' or 'unsigned int' + (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' + (see ISO C 99 6.3.1.1.(2)). So add a negative value to the + enum; this ensures that '_Bool' promotes to 'int'. */ +typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; +# endif +# endif +# endif +# define bool _Bool +#endif + +/* The other macros must be usable in preprocessor directives. */ +#ifdef __cplusplus +# define false false +# define true true +#else +# define false 0 +# define true 1 +#endif + +#define __bool_true_false_are_defined 1 + +#endif /* _GL_STDBOOL_H */ diff --git a/grub-core/gnulib/stddef.in.h b/grub-core/gnulib/stddef.in.h new file mode 100644 index 000000000..40f0536aa --- /dev/null +++ b/grub-core/gnulib/stddef.in.h @@ -0,0 +1,86 @@ +/* A substitute for POSIX 2008 , for platforms that have issues. + + Copyright (C) 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Eric Blake. */ + +/* + * POSIX 2008 for platforms that have issues. + * + */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if defined __need_wchar_t || defined __need_size_t \ + || defined __need_ptrdiff_t || defined __need_NULL \ + || defined __need_wint_t +/* Special invocation convention inside gcc header files. In + particular, gcc provides a version of that blindly + redefines NULL even when __need_wint_t was defined, even though + wint_t is not normally provided by . Hence, we must + remember if special invocation has ever been used to obtain wint_t, + in which case we need to clean up NULL yet again. */ + +# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) +# ifdef __need_wint_t +# undef _@GUARD_PREFIX@_STDDEF_H +# define _GL_STDDEF_WINT_T +# endif +# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ +# endif + +#else +/* Normal invocation convention. */ + +# ifndef _@GUARD_PREFIX@_STDDEF_H + +/* The include_next requires a split double-inclusion guard. */ + +# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ + +# ifndef _@GUARD_PREFIX@_STDDEF_H +# define _@GUARD_PREFIX@_STDDEF_H + +/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ +#if @REPLACE_NULL@ +# undef NULL +# ifdef __cplusplus + /* ISO C++ says that the macro NULL must expand to an integer constant + expression, hence '((void *) 0)' is not allowed in C++. */ +# if __GNUG__ >= 3 + /* GNU C++ has a __null macro that behaves like an integer ('int' or + 'long') but has the same size as a pointer. Use that, to avoid + warnings. */ +# define NULL __null +# else +# define NULL 0L +# endif +# else +# define NULL ((void *) 0) +# endif +#endif + +/* Some platforms lack wchar_t. */ +#if !@HAVE_WCHAR_T@ +# define wchar_t int +#endif + +# endif /* _@GUARD_PREFIX@_STDDEF_H */ +# endif /* _@GUARD_PREFIX@_STDDEF_H */ +#endif /* __need_XXX */ diff --git a/grub-core/gnulib/stdint.in.h b/grub-core/gnulib/stdint.in.h new file mode 100644 index 000000000..2db8b2e37 --- /dev/null +++ b/grub-core/gnulib/stdint.in.h @@ -0,0 +1,636 @@ +/* Copyright (C) 2001-2002, 2004-2013 Free Software Foundation, Inc. + Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. + This file is part of gnulib. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* + * ISO C 99 for platforms that lack it. + * + */ + +#ifndef _@GUARD_PREFIX@_STDINT_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* When including a system file that in turn includes , + use the system , not our substitute. This avoids + problems with (for example) VMS, whose includes + . */ +#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H + +/* On Android (Bionic libc), includes this file before + having defined 'time_t'. Therefore in this case avoid including + other system header files; just include the system's . + Ideally we should test __BIONIC__ here, but it is only defined after + has been included; hence test __ANDROID__ instead. */ +#if defined __ANDROID__ \ + && defined _SYS_TYPES_H_ && !defined __need_size_t +# @INCLUDE_NEXT@ @NEXT_STDINT_H@ +#else + +/* Get those types that are already defined in other system include + files, so that we can "#define int8_t signed char" below without + worrying about a later system include file containing a "typedef + signed char int8_t;" that will get messed up by our macro. Our + macros should all be consistent with the system versions, except + for the "fast" types and macros, which we recommend against using + in public interfaces due to compiler differences. */ + +#if @HAVE_STDINT_H@ +# if defined __sgi && ! defined __c99 + /* Bypass IRIX's if in C89 mode, since it merely annoys users + with "This header file is to be used only for c99 mode compilations" + diagnostics. */ +# define __STDINT_H__ +# endif + + /* Some pre-C++11 implementations need this. */ +# ifdef __cplusplus +# ifndef __STDC_CONSTANT_MACROS +# define __STDC_CONSTANT_MACROS 1 +# endif +# ifndef __STDC_LIMIT_MACROS +# define __STDC_LIMIT_MACROS 1 +# endif +# endif + + /* Other systems may have an incomplete or buggy . + Include it before , since any "#include " + in would reinclude us, skipping our contents because + _@GUARD_PREFIX@_STDINT_H is defined. + The include_next requires a split double-inclusion guard. */ +# @INCLUDE_NEXT@ @NEXT_STDINT_H@ +#endif + +#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H +#define _@GUARD_PREFIX@_STDINT_H + +/* defines some of the stdint.h types as well, on glibc, + IRIX 6.5, and OpenBSD 3.8 (via ). + AIX 5.2 isn't needed and causes troubles. + Mac OS X 10.4.6 includes (which is us), but + relies on the system definitions, so include + after @NEXT_STDINT_H@. */ +#if @HAVE_SYS_TYPES_H@ && ! defined _AIX +# include +#endif + +/* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX, + LONG_MIN, LONG_MAX, ULONG_MAX. */ +#include + +#if @HAVE_INTTYPES_H@ + /* In OpenBSD 3.8, includes , which defines + int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. + also defines intptr_t and uintptr_t. */ +# include +#elif @HAVE_SYS_INTTYPES_H@ + /* Solaris 7 has the types except the *_fast*_t types, and + the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ +# include +#endif + +#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ + /* Linux libc4 >= 4.6.7 and libc5 have a that defines + int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is + included by . */ +# include +#endif + +#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H + +/* Minimum and maximum values for an integer type under the usual assumption. + Return an unspecified value if BITS == 0, adding a check to pacify + picky compilers. */ + +#define _STDINT_MIN(signed, bits, zero) \ + ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) + +#define _STDINT_MAX(signed, bits, zero) \ + ((signed) \ + ? ~ _STDINT_MIN (signed, bits, zero) \ + : /* The expression for the unsigned case. The subtraction of (signed) \ + is a nop in the unsigned case and avoids "signed integer overflow" \ + warnings in the signed case. */ \ + ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1) + +#if !GNULIB_defined_stdint_types + +/* 7.18.1.1. Exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef int8_t +#undef uint8_t +typedef signed char gl_int8_t; +typedef unsigned char gl_uint8_t; +#define int8_t gl_int8_t +#define uint8_t gl_uint8_t + +#undef int16_t +#undef uint16_t +typedef short int gl_int16_t; +typedef unsigned short int gl_uint16_t; +#define int16_t gl_int16_t +#define uint16_t gl_uint16_t + +#undef int32_t +#undef uint32_t +typedef int gl_int32_t; +typedef unsigned int gl_uint32_t; +#define int32_t gl_int32_t +#define uint32_t gl_uint32_t + +/* If the system defines INT64_MAX, assume int64_t works. That way, + if the underlying platform defines int64_t to be a 64-bit long long + int, the code below won't mistakenly define it to be a 64-bit long + int, which would mess up C++ name mangling. We must use #ifdef + rather than #if, to avoid an error with HP-UX 10.20 cc. */ + +#ifdef INT64_MAX +# define GL_INT64_T +#else +/* Do not undefine int64_t if gnulib is not being used with 64-bit + types, since otherwise it breaks platforms like Tandem/NSK. */ +# if LONG_MAX >> 31 >> 31 == 1 +# undef int64_t +typedef long int gl_int64_t; +# define int64_t gl_int64_t +# define GL_INT64_T +# elif defined _MSC_VER +# undef int64_t +typedef __int64 gl_int64_t; +# define int64_t gl_int64_t +# define GL_INT64_T +# elif @HAVE_LONG_LONG_INT@ +# undef int64_t +typedef long long int gl_int64_t; +# define int64_t gl_int64_t +# define GL_INT64_T +# endif +#endif + +#ifdef UINT64_MAX +# define GL_UINT64_T +#else +# if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# undef uint64_t +typedef unsigned long int gl_uint64_t; +# define uint64_t gl_uint64_t +# define GL_UINT64_T +# elif defined _MSC_VER +# undef uint64_t +typedef unsigned __int64 gl_uint64_t; +# define uint64_t gl_uint64_t +# define GL_UINT64_T +# elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# undef uint64_t +typedef unsigned long long int gl_uint64_t; +# define uint64_t gl_uint64_t +# define GL_UINT64_T +# endif +#endif + +/* Avoid collision with Solaris 2.5.1 etc. */ +#define _UINT8_T +#define _UINT32_T +#define _UINT64_T + + +/* 7.18.1.2. Minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef int_least8_t +#undef uint_least8_t +#undef int_least16_t +#undef uint_least16_t +#undef int_least32_t +#undef uint_least32_t +#undef int_least64_t +#undef uint_least64_t +#define int_least8_t int8_t +#define uint_least8_t uint8_t +#define int_least16_t int16_t +#define uint_least16_t uint16_t +#define int_least32_t int32_t +#define uint_least32_t uint32_t +#ifdef GL_INT64_T +# define int_least64_t int64_t +#endif +#ifdef GL_UINT64_T +# define uint_least64_t uint64_t +#endif + +/* 7.18.1.3. Fastest minimum-width integer types */ + +/* Note: Other substitutes may define these types differently. + It is not recommended to use these types in public header files. */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. The following code normally + uses types consistent with glibc, as that lessens the chance of + incompatibility with older GNU hosts. */ + +#undef int_fast8_t +#undef uint_fast8_t +#undef int_fast16_t +#undef uint_fast16_t +#undef int_fast32_t +#undef uint_fast32_t +#undef int_fast64_t +#undef uint_fast64_t +typedef signed char gl_int_fast8_t; +typedef unsigned char gl_uint_fast8_t; + +#ifdef __sun +/* Define types compatible with SunOS 5.10, so that code compiled under + earlier SunOS versions works with code compiled under SunOS 5.10. */ +typedef int gl_int_fast32_t; +typedef unsigned int gl_uint_fast32_t; +#else +typedef long int gl_int_fast32_t; +typedef unsigned long int gl_uint_fast32_t; +#endif +typedef gl_int_fast32_t gl_int_fast16_t; +typedef gl_uint_fast32_t gl_uint_fast16_t; + +#define int_fast8_t gl_int_fast8_t +#define uint_fast8_t gl_uint_fast8_t +#define int_fast16_t gl_int_fast16_t +#define uint_fast16_t gl_uint_fast16_t +#define int_fast32_t gl_int_fast32_t +#define uint_fast32_t gl_uint_fast32_t +#ifdef GL_INT64_T +# define int_fast64_t int64_t +#endif +#ifdef GL_UINT64_T +# define uint_fast64_t uint64_t +#endif + +/* 7.18.1.4. Integer types capable of holding object pointers */ + +#undef intptr_t +#undef uintptr_t +typedef long int gl_intptr_t; +typedef unsigned long int gl_uintptr_t; +#define intptr_t gl_intptr_t +#define uintptr_t gl_uintptr_t + +/* 7.18.1.5. Greatest-width integer types */ + +/* Note: These types are compiler dependent. It may be unwise to use them in + public header files. */ + +/* If the system defines INTMAX_MAX, assume that intmax_t works, and + similarly for UINTMAX_MAX and uintmax_t. This avoids problems with + assuming one type where another is used by the system. */ + +#ifndef INTMAX_MAX +# undef INTMAX_C +# undef intmax_t +# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +typedef long long int gl_intmax_t; +# define intmax_t gl_intmax_t +# elif defined GL_INT64_T +# define intmax_t int64_t +# else +typedef long int gl_intmax_t; +# define intmax_t gl_intmax_t +# endif +#endif + +#ifndef UINTMAX_MAX +# undef UINTMAX_C +# undef uintmax_t +# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +typedef unsigned long long int gl_uintmax_t; +# define uintmax_t gl_uintmax_t +# elif defined GL_UINT64_T +# define uintmax_t uint64_t +# else +typedef unsigned long int gl_uintmax_t; +# define uintmax_t gl_uintmax_t +# endif +#endif + +/* Verify that intmax_t and uintmax_t have the same size. Too much code + breaks if this is not the case. If this check fails, the reason is likely + to be found in the autoconf macros. */ +typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) + ? 1 : -1]; + +#define GNULIB_defined_stdint_types 1 +#endif /* !GNULIB_defined_stdint_types */ + +/* 7.18.2. Limits of specified-width integer types */ + +/* 7.18.2.1. Limits of exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef INT8_MIN +#undef INT8_MAX +#undef UINT8_MAX +#define INT8_MIN (~ INT8_MAX) +#define INT8_MAX 127 +#define UINT8_MAX 255 + +#undef INT16_MIN +#undef INT16_MAX +#undef UINT16_MAX +#define INT16_MIN (~ INT16_MAX) +#define INT16_MAX 32767 +#define UINT16_MAX 65535 + +#undef INT32_MIN +#undef INT32_MAX +#undef UINT32_MAX +#define INT32_MIN (~ INT32_MAX) +#define INT32_MAX 2147483647 +#define UINT32_MAX 4294967295U + +#if defined GL_INT64_T && ! defined INT64_MAX +/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0 + evaluates the latter incorrectly in preprocessor expressions. */ +# define INT64_MIN (- INTMAX_C (1) << 63) +# define INT64_MAX INTMAX_C (9223372036854775807) +#endif + +#if defined GL_UINT64_T && ! defined UINT64_MAX +# define UINT64_MAX UINTMAX_C (18446744073709551615) +#endif + +/* 7.18.2.2. Limits of minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef INT_LEAST8_MIN +#undef INT_LEAST8_MAX +#undef UINT_LEAST8_MAX +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#undef INT_LEAST16_MIN +#undef INT_LEAST16_MAX +#undef UINT_LEAST16_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#undef INT_LEAST32_MIN +#undef INT_LEAST32_MAX +#undef UINT_LEAST32_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#undef INT_LEAST64_MIN +#undef INT_LEAST64_MAX +#ifdef GL_INT64_T +# define INT_LEAST64_MIN INT64_MIN +# define INT_LEAST64_MAX INT64_MAX +#endif + +#undef UINT_LEAST64_MAX +#ifdef GL_UINT64_T +# define UINT_LEAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.3. Limits of fastest minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. */ + +#undef INT_FAST8_MIN +#undef INT_FAST8_MAX +#undef UINT_FAST8_MAX +#define INT_FAST8_MIN SCHAR_MIN +#define INT_FAST8_MAX SCHAR_MAX +#define UINT_FAST8_MAX UCHAR_MAX + +#undef INT_FAST16_MIN +#undef INT_FAST16_MAX +#undef UINT_FAST16_MAX +#define INT_FAST16_MIN INT_FAST32_MIN +#define INT_FAST16_MAX INT_FAST32_MAX +#define UINT_FAST16_MAX UINT_FAST32_MAX + +#undef INT_FAST32_MIN +#undef INT_FAST32_MAX +#undef UINT_FAST32_MAX +#ifdef __sun +# define INT_FAST32_MIN INT_MIN +# define INT_FAST32_MAX INT_MAX +# define UINT_FAST32_MAX UINT_MAX +#else +# define INT_FAST32_MIN LONG_MIN +# define INT_FAST32_MAX LONG_MAX +# define UINT_FAST32_MAX ULONG_MAX +#endif + +#undef INT_FAST64_MIN +#undef INT_FAST64_MAX +#ifdef GL_INT64_T +# define INT_FAST64_MIN INT64_MIN +# define INT_FAST64_MAX INT64_MAX +#endif + +#undef UINT_FAST64_MAX +#ifdef GL_UINT64_T +# define UINT_FAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.4. Limits of integer types capable of holding object pointers */ + +#undef INTPTR_MIN +#undef INTPTR_MAX +#undef UINTPTR_MAX +#define INTPTR_MIN LONG_MIN +#define INTPTR_MAX LONG_MAX +#define UINTPTR_MAX ULONG_MAX + +/* 7.18.2.5. Limits of greatest-width integer types */ + +#ifndef INTMAX_MAX +# undef INTMAX_MIN +# ifdef INT64_MAX +# define INTMAX_MIN INT64_MIN +# define INTMAX_MAX INT64_MAX +# else +# define INTMAX_MIN INT32_MIN +# define INTMAX_MAX INT32_MAX +# endif +#endif + +#ifndef UINTMAX_MAX +# ifdef UINT64_MAX +# define UINTMAX_MAX UINT64_MAX +# else +# define UINTMAX_MAX UINT32_MAX +# endif +#endif + +/* 7.18.3. Limits of other integer types */ + +/* ptrdiff_t limits */ +#undef PTRDIFF_MIN +#undef PTRDIFF_MAX +#if @APPLE_UNIVERSAL_BUILD@ +# ifdef _LP64 +# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l) +# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l) +# else +# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0) +# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0) +# endif +#else +# define PTRDIFF_MIN \ + _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) +# define PTRDIFF_MAX \ + _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) +#endif + +/* sig_atomic_t limits */ +#undef SIG_ATOMIC_MIN +#undef SIG_ATOMIC_MAX +#define SIG_ATOMIC_MIN \ + _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) +#define SIG_ATOMIC_MAX \ + _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) + + +/* size_t limit */ +#undef SIZE_MAX +#if @APPLE_UNIVERSAL_BUILD@ +# ifdef _LP64 +# define SIZE_MAX _STDINT_MAX (0, 64, 0ul) +# else +# define SIZE_MAX _STDINT_MAX (0, 32, 0ul) +# endif +#else +# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) +#endif + +/* wchar_t limits */ +/* Get WCHAR_MIN, WCHAR_MAX. + This include is not on the top, above, because on OSF/1 4.0 we have a + sequence of nested includes + -> -> -> , and the latter includes + and assumes its types are already defined. */ +#if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX) + /* BSD/OS 4.0.1 has a bug: , and must be + included before . */ +# include +# include +# include +# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H +# include +# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H +#endif +#undef WCHAR_MIN +#undef WCHAR_MAX +#define WCHAR_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) +#define WCHAR_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) + +/* wint_t limits */ +#undef WINT_MIN +#undef WINT_MAX +#define WINT_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) +#define WINT_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) + +/* 7.18.4. Macros for integer constants */ + +/* 7.18.4.1. Macros for minimum-width integer constants */ +/* According to ISO C 99 Technical Corrigendum 1 */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ + +#undef INT8_C +#undef UINT8_C +#define INT8_C(x) x +#define UINT8_C(x) x + +#undef INT16_C +#undef UINT16_C +#define INT16_C(x) x +#define UINT16_C(x) x + +#undef INT32_C +#undef UINT32_C +#define INT32_C(x) x +#define UINT32_C(x) x ## U + +#undef INT64_C +#undef UINT64_C +#if LONG_MAX >> 31 >> 31 == 1 +# define INT64_C(x) x##L +#elif defined _MSC_VER +# define INT64_C(x) x##i64 +#elif @HAVE_LONG_LONG_INT@ +# define INT64_C(x) x##LL +#endif +#if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# define UINT64_C(x) x##UL +#elif defined _MSC_VER +# define UINT64_C(x) x##ui64 +#elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# define UINT64_C(x) x##ULL +#endif + +/* 7.18.4.2. Macros for greatest-width integer constants */ + +#ifndef INTMAX_C +# if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +# define INTMAX_C(x) x##LL +# elif defined GL_INT64_T +# define INTMAX_C(x) INT64_C(x) +# else +# define INTMAX_C(x) x##L +# endif +#endif + +#ifndef UINTMAX_C +# if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +# define UINTMAX_C(x) x##ULL +# elif defined GL_UINT64_T +# define UINTMAX_C(x) UINT64_C(x) +# else +# define UINTMAX_C(x) x##UL +# endif +#endif + +#endif /* _@GUARD_PREFIX@_STDINT_H */ +#endif /* !(defined __ANDROID__ && ...) */ +#endif /* !defined _@GUARD_PREFIX@_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */ diff --git a/grub-core/gnulib/stdio.in.h b/grub-core/gnulib/stdio.in.h new file mode 100644 index 000000000..e1d28cebf --- /dev/null +++ b/grub-core/gnulib/stdio.in.h @@ -0,0 +1,1333 @@ +/* A GNU-like . + + Copyright (C) 2004, 2007-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if defined __need_FILE || defined __need___FILE || defined _GL_ALREADY_INCLUDING_STDIO_H +/* Special invocation convention: + - Inside glibc header files. + - On OSF/1 5.1 we have a sequence of nested includes + -> -> -> -> + -> -> -> . + In this situation, the functions are not yet declared, therefore we cannot + provide the C++ aliases. */ + +#@INCLUDE_NEXT@ @NEXT_STDIO_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_STDIO_H + +#define _GL_ALREADY_INCLUDING_STDIO_H + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_STDIO_H@ + +#undef _GL_ALREADY_INCLUDING_STDIO_H + +#ifndef _@GUARD_PREFIX@_STDIO_H +#define _@GUARD_PREFIX@_STDIO_H + +/* Get va_list. Needed on many systems, including glibc 2.8. */ +#include + +#include + +/* Get off_t and ssize_t. Needed on many systems, including glibc 2.8 + and eglibc 2.11.2. + May also define off_t to a 64-bit type on native Windows. */ +#include + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +/* _GL_ATTRIBUTE_FORMAT_PRINTF + indicates to GCC that the function takes a format string and arguments, + where the format string directives are the ones standardized by ISO C99 + and POSIX. */ +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) +#else +# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +#endif + +/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, + except that it indicates to GCC that the supported format string directives + are the ones of the system printf(), rather than the ones standardized by + ISO C99 and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) + +/* _GL_ATTRIBUTE_FORMAT_SCANF + indicates to GCC that the function takes a format string and arguments, + where the format string directives are the ones standardized by ISO C99 + and POSIX. */ +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, first_argument)) +#else +# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) +#endif + +/* _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_SCANF, + except that it indicates to GCC that the supported format string directives + are the ones of the system scanf(), rather than the ones standardized by + ISO C99 and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) + +/* Solaris 10 declares renameat in , not in . */ +/* But in any case avoid namespace pollution on glibc systems. */ +#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __sun \ + && ! defined __GLIBC__ +# include +#endif + + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* Macros for stringification. */ +#define _GL_STDIO_STRINGIZE(token) #token +#define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) + + +#if @GNULIB_DPRINTF@ +# if @REPLACE_DPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dprintf rpl_dprintf +# endif +_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...)); +# else +# if !@HAVE_DPRINTF@ +_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...)); +# endif +_GL_CXXALIASWARN (dprintf); +#elif defined GNULIB_POSIXCHECK +# undef dprintf +# if HAVE_RAW_DECL_DPRINTF +_GL_WARN_ON_USE (dprintf, "dprintf is unportable - " + "use gnulib module dprintf for portability"); +# endif +#endif + +#if @GNULIB_FCLOSE@ +/* Close STREAM and its underlying file descriptor. */ +# if @REPLACE_FCLOSE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define fclose rpl_fclose +# endif +_GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (fclose, int, (FILE *stream)); +# else +_GL_CXXALIAS_SYS (fclose, int, (FILE *stream)); +# endif +_GL_CXXALIASWARN (fclose); +#elif defined GNULIB_POSIXCHECK +# undef fclose +/* Assume fclose is always declared. */ +_GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - " + "use gnulib module fclose for portable POSIX compliance"); +#endif + +#if @GNULIB_FDOPEN@ +# if @REPLACE_FDOPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fdopen +# define fdopen rpl_fdopen +# endif +_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode)); +# else +_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); +# endif +_GL_CXXALIASWARN (fdopen); +#elif defined GNULIB_POSIXCHECK +# undef fdopen +/* Assume fdopen is always declared. */ +_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - " + "use gnulib module fdopen for portability"); +#endif + +#if @GNULIB_FFLUSH@ +/* Flush all pending data on STREAM according to POSIX rules. Both + output and seekable input streams are supported. + Note! LOSS OF DATA can occur if fflush is applied on an input stream + that is _not_seekable_ or on an update stream that is _not_seekable_ + and in which the most recent operation was input. Seekability can + be tested with lseek(fileno(fp),0,SEEK_CUR). */ +# if @REPLACE_FFLUSH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define fflush rpl_fflush +# endif +_GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream)); +_GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream)); +# else +_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream)); +# endif +_GL_CXXALIASWARN (fflush); +#elif defined GNULIB_POSIXCHECK +# undef fflush +/* Assume fflush is always declared. */ +_GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - " + "use gnulib module fflush for portable POSIX compliance"); +#endif + +#if @GNULIB_FGETC@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fgetc +# define fgetc rpl_fgetc +# endif +_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (fgetc, int, (FILE *stream)); +# else +_GL_CXXALIAS_SYS (fgetc, int, (FILE *stream)); +# endif +_GL_CXXALIASWARN (fgetc); +#endif + +#if @GNULIB_FGETS@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fgets +# define fgets rpl_fgets +# endif +_GL_FUNCDECL_RPL (fgets, char *, (char *s, int n, FILE *stream) + _GL_ARG_NONNULL ((1, 3))); +_GL_CXXALIAS_RPL (fgets, char *, (char *s, int n, FILE *stream)); +# else +_GL_CXXALIAS_SYS (fgets, char *, (char *s, int n, FILE *stream)); +# endif +_GL_CXXALIASWARN (fgets); +#endif + +#if @GNULIB_FOPEN@ +# if @REPLACE_FOPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fopen +# define fopen rpl_fopen +# endif +_GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode)); +# else +_GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode)); +# endif +_GL_CXXALIASWARN (fopen); +#elif defined GNULIB_POSIXCHECK +# undef fopen +/* Assume fopen is always declared. */ +_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - " + "use gnulib module fopen for portability"); +#endif + +#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@ +# if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \ + || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define fprintf rpl_fprintf +# endif +# define GNULIB_overrides_fprintf 1 +# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ +_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +# else +_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...)); +# else +_GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...)); +# endif +_GL_CXXALIASWARN (fprintf); +#endif +#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK +# if !GNULIB_overrides_fprintf +# undef fprintf +# endif +/* Assume fprintf is always declared. */ +_GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - " + "use gnulib module fprintf-posix for portable " + "POSIX compliance"); +#endif + +#if @GNULIB_FPURGE@ +/* Discard all pending buffered I/O data on STREAM. + STREAM must not be wide-character oriented. + When discarding pending output, the file position is set back to where it + was before the write calls. When discarding pending input, the file + position is advanced to match the end of the previously read input. + Return 0 if successful. Upon error, return -1 and set errno. */ +# if @REPLACE_FPURGE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define fpurge rpl_fpurge +# endif +_GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream)); +# else +# if !@HAVE_DECL_FPURGE@ +_GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream)); +# endif +_GL_CXXALIASWARN (fpurge); +#elif defined GNULIB_POSIXCHECK +# undef fpurge +# if HAVE_RAW_DECL_FPURGE +_GL_WARN_ON_USE (fpurge, "fpurge is not always present - " + "use gnulib module fpurge for portability"); +# endif +#endif + +#if @GNULIB_FPUTC@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fputc +# define fputc rpl_fputc +# endif +_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream)); +# else +_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream)); +# endif +_GL_CXXALIASWARN (fputc); +#endif + +#if @GNULIB_FPUTS@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fputs +# define fputs rpl_fputs +# endif +_GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream)); +# else +_GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream)); +# endif +_GL_CXXALIASWARN (fputs); +#endif + +#if @GNULIB_FREAD@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fread +# define fread rpl_fread +# endif +_GL_FUNCDECL_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream) + _GL_ARG_NONNULL ((4))); +_GL_CXXALIAS_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)); +# else +_GL_CXXALIAS_SYS (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)); +# endif +_GL_CXXALIASWARN (fread); +#endif + +#if @GNULIB_FREOPEN@ +# if @REPLACE_FREOPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef freopen +# define freopen rpl_freopen +# endif +_GL_FUNCDECL_RPL (freopen, FILE *, + (const char *filename, const char *mode, FILE *stream) + _GL_ARG_NONNULL ((2, 3))); +_GL_CXXALIAS_RPL (freopen, FILE *, + (const char *filename, const char *mode, FILE *stream)); +# else +_GL_CXXALIAS_SYS (freopen, FILE *, + (const char *filename, const char *mode, FILE *stream)); +# endif +_GL_CXXALIASWARN (freopen); +#elif defined GNULIB_POSIXCHECK +# undef freopen +/* Assume freopen is always declared. */ +_GL_WARN_ON_USE (freopen, + "freopen on native Windows platforms is not POSIX compliant - " + "use gnulib module freopen for portability"); +#endif + +#if @GNULIB_FSCANF@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fscanf +# define fscanf rpl_fscanf +# endif +_GL_FUNCDECL_RPL (fscanf, int, (FILE *stream, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (fscanf, int, (FILE *stream, const char *format, ...)); +# else +_GL_CXXALIAS_SYS (fscanf, int, (FILE *stream, const char *format, ...)); +# endif +_GL_CXXALIASWARN (fscanf); +#endif + + +/* Set up the following warnings, based on which modules are in use. + GNU Coding Standards discourage the use of fseek, since it imposes + an arbitrary limitation on some 32-bit hosts. Remember that the + fseek module depends on the fseeko module, so we only have three + cases to consider: + + 1. The developer is not using either module. Issue a warning under + GNULIB_POSIXCHECK for both functions, to remind them that both + functions have bugs on some systems. _GL_NO_LARGE_FILES has no + impact on this warning. + + 2. The developer is using both modules. They may be unaware of the + arbitrary limitations of fseek, so issue a warning under + GNULIB_POSIXCHECK. On the other hand, they may be using both + modules intentionally, so the developer can define + _GL_NO_LARGE_FILES in the compilation units where the use of fseek + is safe, to silence the warning. + + 3. The developer is using the fseeko module, but not fseek. Gnulib + guarantees that fseek will still work around platform bugs in that + case, but we presume that the developer is aware of the pitfalls of + fseek and was trying to avoid it, so issue a warning even when + GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be + defined to silence the warning in particular compilation units. + In C++ compilations with GNULIB_NAMESPACE, in order to avoid that + fseek gets defined as a macro, it is recommended that the developer + uses the fseek module, even if he is not calling the fseek function. + + Most gnulib clients that perform stream operations should fall into + category 3. */ + +#if @GNULIB_FSEEK@ +# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES +# define _GL_FSEEK_WARN /* Category 2, above. */ +# undef fseek +# endif +# if @REPLACE_FSEEK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fseek +# define fseek rpl_fseek +# endif +_GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence)); +# else +_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence)); +# endif +_GL_CXXALIASWARN (fseek); +#endif + +#if @GNULIB_FSEEKO@ +# if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES +# define _GL_FSEEK_WARN /* Category 3, above. */ +# undef fseek +# endif +# if @REPLACE_FSEEKO@ +/* Provide an fseeko function that is aware of a preceding fflush(), and which + detects pipes. */ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fseeko +# define fseeko rpl_fseeko +# endif +_GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)); +# else +# if ! @HAVE_DECL_FSEEKO@ +_GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)); +# endif +_GL_CXXALIASWARN (fseeko); +#elif defined GNULIB_POSIXCHECK +# define _GL_FSEEK_WARN /* Category 1, above. */ +# undef fseek +# undef fseeko +# if HAVE_RAW_DECL_FSEEKO +_GL_WARN_ON_USE (fseeko, "fseeko is unportable - " + "use gnulib module fseeko for portability"); +# endif +#endif + +#ifdef _GL_FSEEK_WARN +# undef _GL_FSEEK_WARN +/* Here, either fseek is undefined (but C89 guarantees that it is + declared), or it is defined as rpl_fseek (declared above). */ +_GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB " + "on 32-bit platforms - " + "use fseeko function for handling of large files"); +#endif + + +/* ftell, ftello. See the comments on fseek/fseeko. */ + +#if @GNULIB_FTELL@ +# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES +# define _GL_FTELL_WARN /* Category 2, above. */ +# undef ftell +# endif +# if @REPLACE_FTELL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ftell +# define ftell rpl_ftell +# endif +_GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (ftell, long, (FILE *fp)); +# else +_GL_CXXALIAS_SYS (ftell, long, (FILE *fp)); +# endif +_GL_CXXALIASWARN (ftell); +#endif + +#if @GNULIB_FTELLO@ +# if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES +# define _GL_FTELL_WARN /* Category 3, above. */ +# undef ftell +# endif +# if @REPLACE_FTELLO@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ftello +# define ftello rpl_ftello +# endif +_GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp)); +# else +# if ! @HAVE_DECL_FTELLO@ +_GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp)); +# endif +_GL_CXXALIASWARN (ftello); +#elif defined GNULIB_POSIXCHECK +# define _GL_FTELL_WARN /* Category 1, above. */ +# undef ftell +# undef ftello +# if HAVE_RAW_DECL_FTELLO +_GL_WARN_ON_USE (ftello, "ftello is unportable - " + "use gnulib module ftello for portability"); +# endif +#endif + +#ifdef _GL_FTELL_WARN +# undef _GL_FTELL_WARN +/* Here, either ftell is undefined (but C89 guarantees that it is + declared), or it is defined as rpl_ftell (declared above). */ +_GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB " + "on 32-bit platforms - " + "use ftello function for handling of large files"); +#endif + + +#if @GNULIB_FWRITE@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fwrite +# define fwrite rpl_fwrite +# endif +_GL_FUNCDECL_RPL (fwrite, size_t, + (const void *ptr, size_t s, size_t n, FILE *stream) + _GL_ARG_NONNULL ((1, 4))); +_GL_CXXALIAS_RPL (fwrite, size_t, + (const void *ptr, size_t s, size_t n, FILE *stream)); +# else +_GL_CXXALIAS_SYS (fwrite, size_t, + (const void *ptr, size_t s, size_t n, FILE *stream)); + +/* Work around bug 11959 when fortifying glibc 2.4 through 2.15 + , + which sometimes causes an unwanted diagnostic for fwrite calls. + This affects only function declaration attributes under certain + versions of gcc, and is not needed for C++. */ +# if (0 < __USE_FORTIFY_LEVEL \ + && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \ + && 3 < __GNUC__ + (4 <= __GNUC_MINOR__) \ + && !defined __cplusplus) +# undef fwrite +# define fwrite(a, b, c, d) ({size_t __r = fwrite (a, b, c, d); __r; }) +# endif +# endif +_GL_CXXALIASWARN (fwrite); +#endif + +#if @GNULIB_GETC@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getc +# define getc rpl_fgetc +# endif +_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL_1 (getc, rpl_fgetc, int, (FILE *stream)); +# else +_GL_CXXALIAS_SYS (getc, int, (FILE *stream)); +# endif +_GL_CXXALIASWARN (getc); +#endif + +#if @GNULIB_GETCHAR@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getchar +# define getchar rpl_getchar +# endif +_GL_FUNCDECL_RPL (getchar, int, (void)); +_GL_CXXALIAS_RPL (getchar, int, (void)); +# else +_GL_CXXALIAS_SYS (getchar, int, (void)); +# endif +_GL_CXXALIASWARN (getchar); +#endif + +#if @GNULIB_GETDELIM@ +/* Read input, up to (and including) the next occurrence of DELIMITER, from + STREAM, store it in *LINEPTR (and NUL-terminate it). + *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE + bytes of space. It is realloc'd as necessary. + Return the number of bytes read and stored at *LINEPTR (not including the + NUL terminator), or -1 on error or EOF. */ +# if @REPLACE_GETDELIM@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getdelim +# define getdelim rpl_getdelim +# endif +_GL_FUNCDECL_RPL (getdelim, ssize_t, + (char **lineptr, size_t *linesize, int delimiter, + FILE *stream) + _GL_ARG_NONNULL ((1, 2, 4))); +_GL_CXXALIAS_RPL (getdelim, ssize_t, + (char **lineptr, size_t *linesize, int delimiter, + FILE *stream)); +# else +# if !@HAVE_DECL_GETDELIM@ +_GL_FUNCDECL_SYS (getdelim, ssize_t, + (char **lineptr, size_t *linesize, int delimiter, + FILE *stream) + _GL_ARG_NONNULL ((1, 2, 4))); +# endif +_GL_CXXALIAS_SYS (getdelim, ssize_t, + (char **lineptr, size_t *linesize, int delimiter, + FILE *stream)); +# endif +_GL_CXXALIASWARN (getdelim); +#elif defined GNULIB_POSIXCHECK +# undef getdelim +# if HAVE_RAW_DECL_GETDELIM +_GL_WARN_ON_USE (getdelim, "getdelim is unportable - " + "use gnulib module getdelim for portability"); +# endif +#endif + +#if @GNULIB_GETLINE@ +/* Read a line, up to (and including) the next newline, from STREAM, store it + in *LINEPTR (and NUL-terminate it). + *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE + bytes of space. It is realloc'd as necessary. + Return the number of bytes read and stored at *LINEPTR (not including the + NUL terminator), or -1 on error or EOF. */ +# if @REPLACE_GETLINE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getline +# define getline rpl_getline +# endif +_GL_FUNCDECL_RPL (getline, ssize_t, + (char **lineptr, size_t *linesize, FILE *stream) + _GL_ARG_NONNULL ((1, 2, 3))); +_GL_CXXALIAS_RPL (getline, ssize_t, + (char **lineptr, size_t *linesize, FILE *stream)); +# else +# if !@HAVE_DECL_GETLINE@ +_GL_FUNCDECL_SYS (getline, ssize_t, + (char **lineptr, size_t *linesize, FILE *stream) + _GL_ARG_NONNULL ((1, 2, 3))); +# endif +_GL_CXXALIAS_SYS (getline, ssize_t, + (char **lineptr, size_t *linesize, FILE *stream)); +# endif +# if @HAVE_DECL_GETLINE@ +_GL_CXXALIASWARN (getline); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getline +# if HAVE_RAW_DECL_GETLINE +_GL_WARN_ON_USE (getline, "getline is unportable - " + "use gnulib module getline for portability"); +# endif +#endif + +/* It is very rare that the developer ever has full control of stdin, + so any use of gets warrants an unconditional warning; besides, C11 + removed it. */ +#undef gets +#if HAVE_RAW_DECL_GETS +#endif + + +#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ +struct obstack; +/* Grow an obstack with formatted output. Return the number of + bytes added to OBS. No trailing nul byte is added, and the + object should be closed with obstack_finish before use. Upon + memory allocation error, call obstack_alloc_failed_handler. Upon + other error, return -1. */ +# if @REPLACE_OBSTACK_PRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define obstack_printf rpl_obstack_printf +# endif +_GL_FUNCDECL_RPL (obstack_printf, int, + (struct obstack *obs, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (obstack_printf, int, + (struct obstack *obs, const char *format, ...)); +# else +# if !@HAVE_DECL_OBSTACK_PRINTF@ +_GL_FUNCDECL_SYS (obstack_printf, int, + (struct obstack *obs, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (obstack_printf, int, + (struct obstack *obs, const char *format, ...)); +# endif +_GL_CXXALIASWARN (obstack_printf); +# if @REPLACE_OBSTACK_PRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define obstack_vprintf rpl_obstack_vprintf +# endif +_GL_FUNCDECL_RPL (obstack_vprintf, int, + (struct obstack *obs, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (obstack_vprintf, int, + (struct obstack *obs, const char *format, va_list args)); +# else +# if !@HAVE_DECL_OBSTACK_PRINTF@ +_GL_FUNCDECL_SYS (obstack_vprintf, int, + (struct obstack *obs, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (obstack_vprintf, int, + (struct obstack *obs, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (obstack_vprintf); +#endif + +#if @GNULIB_PCLOSE@ +# if !@HAVE_PCLOSE@ +_GL_FUNCDECL_SYS (pclose, int, (FILE *stream) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (pclose, int, (FILE *stream)); +_GL_CXXALIASWARN (pclose); +#elif defined GNULIB_POSIXCHECK +# undef pclose +# if HAVE_RAW_DECL_PCLOSE +_GL_WARN_ON_USE (pclose, "pclose is unportable - " + "use gnulib module pclose for more portability"); +# endif +#endif + +#if @GNULIB_PERROR@ +/* Print a message to standard error, describing the value of ERRNO, + (if STRING is not NULL and not empty) prefixed with STRING and ": ", + and terminated with a newline. */ +# if @REPLACE_PERROR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define perror rpl_perror +# endif +_GL_FUNCDECL_RPL (perror, void, (const char *string)); +_GL_CXXALIAS_RPL (perror, void, (const char *string)); +# else +_GL_CXXALIAS_SYS (perror, void, (const char *string)); +# endif +_GL_CXXALIASWARN (perror); +#elif defined GNULIB_POSIXCHECK +# undef perror +/* Assume perror is always declared. */ +_GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - " + "use gnulib module perror for portability"); +#endif + +#if @GNULIB_POPEN@ +# if @REPLACE_POPEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef popen +# define popen rpl_popen +# endif +_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); +# else +# if !@HAVE_POPEN@ +_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); +# endif +_GL_CXXALIASWARN (popen); +#elif defined GNULIB_POSIXCHECK +# undef popen +# if HAVE_RAW_DECL_POPEN +_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " + "use gnulib module popen or pipe for more portability"); +# endif +#endif + +#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ +# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ + || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) +# if defined __GNUC__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +/* Don't break __attribute__((format(printf,M,N))). */ +# define printf __printf__ +# endif +# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ +_GL_FUNCDECL_RPL_1 (__printf__, int, + (const char *format, ...) + __asm__ (@ASM_SYMBOL_PREFIX@ + _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) + _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ARG_NONNULL ((1))); +# else +_GL_FUNCDECL_RPL_1 (__printf__, int, + (const char *format, ...) + __asm__ (@ASM_SYMBOL_PREFIX@ + _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) + _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); +# else +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define printf rpl_printf +# endif +_GL_FUNCDECL_RPL (printf, int, + (const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (printf, int, (const char *format, ...)); +# endif +# define GNULIB_overrides_printf 1 +# else +_GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); +# endif +_GL_CXXALIASWARN (printf); +#endif +#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK +# if !GNULIB_overrides_printf +# undef printf +# endif +/* Assume printf is always declared. */ +_GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - " + "use gnulib module printf-posix for portable " + "POSIX compliance"); +#endif + +#if @GNULIB_PUTC@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putc +# define putc rpl_fputc +# endif +_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream)); +# else +_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream)); +# endif +_GL_CXXALIASWARN (putc); +#endif + +#if @GNULIB_PUTCHAR@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putchar +# define putchar rpl_putchar +# endif +_GL_FUNCDECL_RPL (putchar, int, (int c)); +_GL_CXXALIAS_RPL (putchar, int, (int c)); +# else +_GL_CXXALIAS_SYS (putchar, int, (int c)); +# endif +_GL_CXXALIASWARN (putchar); +#endif + +#if @GNULIB_PUTS@ +# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef puts +# define puts rpl_puts +# endif +_GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (puts, int, (const char *string)); +# else +_GL_CXXALIAS_SYS (puts, int, (const char *string)); +# endif +_GL_CXXALIASWARN (puts); +#endif + +#if @GNULIB_REMOVE@ +# if @REPLACE_REMOVE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef remove +# define remove rpl_remove +# endif +_GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (remove, int, (const char *name)); +# else +_GL_CXXALIAS_SYS (remove, int, (const char *name)); +# endif +_GL_CXXALIASWARN (remove); +#elif defined GNULIB_POSIXCHECK +# undef remove +/* Assume remove is always declared. */ +_GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - " + "use gnulib module remove for more portability"); +#endif + +#if @GNULIB_RENAME@ +# if @REPLACE_RENAME@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef rename +# define rename rpl_rename +# endif +_GL_FUNCDECL_RPL (rename, int, + (const char *old_filename, const char *new_filename) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (rename, int, + (const char *old_filename, const char *new_filename)); +# else +_GL_CXXALIAS_SYS (rename, int, + (const char *old_filename, const char *new_filename)); +# endif +_GL_CXXALIASWARN (rename); +#elif defined GNULIB_POSIXCHECK +# undef rename +/* Assume rename is always declared. */ +_GL_WARN_ON_USE (rename, "rename is buggy on some platforms - " + "use gnulib module rename for more portability"); +#endif + +#if @GNULIB_RENAMEAT@ +# if @REPLACE_RENAMEAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef renameat +# define renameat rpl_renameat +# endif +_GL_FUNCDECL_RPL (renameat, int, + (int fd1, char const *file1, int fd2, char const *file2) + _GL_ARG_NONNULL ((2, 4))); +_GL_CXXALIAS_RPL (renameat, int, + (int fd1, char const *file1, int fd2, char const *file2)); +# else +# if !@HAVE_RENAMEAT@ +_GL_FUNCDECL_SYS (renameat, int, + (int fd1, char const *file1, int fd2, char const *file2) + _GL_ARG_NONNULL ((2, 4))); +# endif +_GL_CXXALIAS_SYS (renameat, int, + (int fd1, char const *file1, int fd2, char const *file2)); +# endif +_GL_CXXALIASWARN (renameat); +#elif defined GNULIB_POSIXCHECK +# undef renameat +# if HAVE_RAW_DECL_RENAMEAT +_GL_WARN_ON_USE (renameat, "renameat is not portable - " + "use gnulib module renameat for portability"); +# endif +#endif + +#if @GNULIB_SCANF@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if defined __GNUC__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef scanf +/* Don't break __attribute__((format(scanf,M,N))). */ +# define scanf __scanf__ +# endif +_GL_FUNCDECL_RPL_1 (__scanf__, int, + (const char *format, ...) + __asm__ (@ASM_SYMBOL_PREFIX@ + _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf)) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *format, ...)); +# else +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef scanf +# define scanf rpl_scanf +# endif +_GL_FUNCDECL_RPL (scanf, int, (const char *format, ...) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (scanf, int, (const char *format, ...)); +# endif +# else +_GL_CXXALIAS_SYS (scanf, int, (const char *format, ...)); +# endif +_GL_CXXALIASWARN (scanf); +#endif + +#if @GNULIB_SNPRINTF@ +# if @REPLACE_SNPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define snprintf rpl_snprintf +# endif +_GL_FUNCDECL_RPL (snprintf, int, + (char *str, size_t size, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ARG_NONNULL ((3))); +_GL_CXXALIAS_RPL (snprintf, int, + (char *str, size_t size, const char *format, ...)); +# else +# if !@HAVE_DECL_SNPRINTF@ +_GL_FUNCDECL_SYS (snprintf, int, + (char *str, size_t size, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ARG_NONNULL ((3))); +# endif +_GL_CXXALIAS_SYS (snprintf, int, + (char *str, size_t size, const char *format, ...)); +# endif +_GL_CXXALIASWARN (snprintf); +#elif defined GNULIB_POSIXCHECK +# undef snprintf +# if HAVE_RAW_DECL_SNPRINTF +_GL_WARN_ON_USE (snprintf, "snprintf is unportable - " + "use gnulib module snprintf for portability"); +# endif +#endif + +/* Some people would argue that all sprintf uses should be warned about + (for example, OpenBSD issues a link warning for it), + since it can cause security holes due to buffer overruns. + However, we believe that sprintf can be used safely, and is more + efficient than snprintf in those safe cases; and as proof of our + belief, we use sprintf in several gnulib modules. So this header + intentionally avoids adding a warning to sprintf except when + GNULIB_POSIXCHECK is defined. */ + +#if @GNULIB_SPRINTF_POSIX@ +# if @REPLACE_SPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define sprintf rpl_sprintf +# endif +_GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...)); +# else +_GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...)); +# endif +_GL_CXXALIASWARN (sprintf); +#elif defined GNULIB_POSIXCHECK +# undef sprintf +/* Assume sprintf is always declared. */ +_GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - " + "use gnulib module sprintf-posix for portable " + "POSIX compliance"); +#endif + +#if @GNULIB_TMPFILE@ +# if @REPLACE_TMPFILE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define tmpfile rpl_tmpfile +# endif +_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)); +_GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); +# else +_GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); +# endif +_GL_CXXALIASWARN (tmpfile); +#elif defined GNULIB_POSIXCHECK +# undef tmpfile +# if HAVE_RAW_DECL_TMPFILE +_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " + "use gnulib module tmpfile for portability"); +# endif +#endif + +#if @GNULIB_VASPRINTF@ +/* Write formatted output to a string dynamically allocated with malloc(). + If the memory allocation succeeds, store the address of the string in + *RESULT and return the number of resulting bytes, excluding the trailing + NUL. Upon memory allocation error, or some other error, return -1. */ +# if @REPLACE_VASPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define asprintf rpl_asprintf +# endif +_GL_FUNCDECL_RPL (asprintf, int, + (char **result, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (asprintf, int, + (char **result, const char *format, ...)); +# else +# if !@HAVE_VASPRINTF@ +_GL_FUNCDECL_SYS (asprintf, int, + (char **result, const char *format, ...) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (asprintf, int, + (char **result, const char *format, ...)); +# endif +_GL_CXXALIASWARN (asprintf); +# if @REPLACE_VASPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vasprintf rpl_vasprintf +# endif +_GL_FUNCDECL_RPL (vasprintf, int, + (char **result, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (vasprintf, int, + (char **result, const char *format, va_list args)); +# else +# if !@HAVE_VASPRINTF@ +_GL_FUNCDECL_SYS (vasprintf, int, + (char **result, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (vasprintf, int, + (char **result, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vasprintf); +#endif + +#if @GNULIB_VDPRINTF@ +# if @REPLACE_VDPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vdprintf rpl_vdprintf +# endif +_GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args)); +# else +# if !@HAVE_VDPRINTF@ +_GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((2))); +# endif +/* Need to cast, because on Solaris, the third parameter will likely be + __va_list args. */ +_GL_CXXALIAS_SYS_CAST (vdprintf, int, + (int fd, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vdprintf); +#elif defined GNULIB_POSIXCHECK +# undef vdprintf +# if HAVE_RAW_DECL_VDPRINTF +_GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - " + "use gnulib module vdprintf for portability"); +# endif +#endif + +#if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@ +# if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \ + || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vfprintf rpl_vfprintf +# endif +# define GNULIB_overrides_vfprintf 1 +# if @GNULIB_VFPRINTF_POSIX@ +_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +# else +_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)); +# else +/* Need to cast, because on Solaris, the third parameter is + __va_list args + and GCC's fixincludes did not change this to __gnuc_va_list. */ +_GL_CXXALIAS_SYS_CAST (vfprintf, int, + (FILE *fp, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vfprintf); +#endif +#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK +# if !GNULIB_overrides_vfprintf +# undef vfprintf +# endif +/* Assume vfprintf is always declared. */ +_GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - " + "use gnulib module vfprintf-posix for portable " + "POSIX compliance"); +#endif + +#if @GNULIB_VFSCANF@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef vfscanf +# define vfscanf rpl_vfscanf +# endif +_GL_FUNCDECL_RPL (vfscanf, int, + (FILE *stream, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (vfscanf, int, + (FILE *stream, const char *format, va_list args)); +# else +_GL_CXXALIAS_SYS (vfscanf, int, + (FILE *stream, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vfscanf); +#endif + +#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ +# if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \ + || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vprintf rpl_vprintf +# endif +# define GNULIB_overrides_vprintf 1 +# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ +_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) + _GL_ARG_NONNULL ((1))); +# else +_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args)); +# else +/* Need to cast, because on Solaris, the second parameter is + __va_list args + and GCC's fixincludes did not change this to __gnuc_va_list. */ +_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vprintf); +#endif +#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK +# if !GNULIB_overrides_vprintf +# undef vprintf +# endif +/* Assume vprintf is always declared. */ +_GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - " + "use gnulib module vprintf-posix for portable " + "POSIX compliance"); +#endif + +#if @GNULIB_VSCANF@ +# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef vscanf +# define vscanf rpl_vscanf +# endif +_GL_FUNCDECL_RPL (vscanf, int, (const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (vscanf, int, (const char *format, va_list args)); +# else +_GL_CXXALIAS_SYS (vscanf, int, (const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vscanf); +#endif + +#if @GNULIB_VSNPRINTF@ +# if @REPLACE_VSNPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vsnprintf rpl_vsnprintf +# endif +_GL_FUNCDECL_RPL (vsnprintf, int, + (char *str, size_t size, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ARG_NONNULL ((3))); +_GL_CXXALIAS_RPL (vsnprintf, int, + (char *str, size_t size, const char *format, va_list args)); +# else +# if !@HAVE_DECL_VSNPRINTF@ +_GL_FUNCDECL_SYS (vsnprintf, int, + (char *str, size_t size, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ARG_NONNULL ((3))); +# endif +_GL_CXXALIAS_SYS (vsnprintf, int, + (char *str, size_t size, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vsnprintf); +#elif defined GNULIB_POSIXCHECK +# undef vsnprintf +# if HAVE_RAW_DECL_VSNPRINTF +_GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " + "use gnulib module vsnprintf for portability"); +# endif +#endif + +#if @GNULIB_VSPRINTF_POSIX@ +# if @REPLACE_VSPRINTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define vsprintf rpl_vsprintf +# endif +_GL_FUNCDECL_RPL (vsprintf, int, + (char *str, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (vsprintf, int, + (char *str, const char *format, va_list args)); +# else +/* Need to cast, because on Solaris, the third parameter is + __va_list args + and GCC's fixincludes did not change this to __gnuc_va_list. */ +_GL_CXXALIAS_SYS_CAST (vsprintf, int, + (char *str, const char *format, va_list args)); +# endif +_GL_CXXALIASWARN (vsprintf); +#elif defined GNULIB_POSIXCHECK +# undef vsprintf +/* Assume vsprintf is always declared. */ +_GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - " + "use gnulib module vsprintf-posix for portable " + "POSIX compliance"); +#endif + +#endif /* _@GUARD_PREFIX@_STDIO_H */ +#endif /* _@GUARD_PREFIX@_STDIO_H */ +#endif diff --git a/grub-core/gnulib/stdlib.in.h b/grub-core/gnulib/stdlib.in.h new file mode 100644 index 000000000..c9552480e --- /dev/null +++ b/grub-core/gnulib/stdlib.in.h @@ -0,0 +1,954 @@ +/* A GNU-like . + + Copyright (C) 1995, 2001-2004, 2006-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if defined __need_system_stdlib_h || defined __need_malloc_and_calloc +/* Special invocation conventions inside some gnulib header files, + and inside some glibc header files, respectively. */ + +#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_STDLIB_H + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ + +#ifndef _@GUARD_PREFIX@_STDLIB_H +#define _@GUARD_PREFIX@_STDLIB_H + +/* NetBSD 5.0 mis-defines NULL. */ +#include + +/* MirBSD 10 defines WEXITSTATUS in , not in . */ +#if @GNULIB_SYSTEM_POSIX@ && !defined WEXITSTATUS +# include +#endif + +/* Solaris declares getloadavg() in . */ +#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ +# include +#endif + +/* Native Windows platforms declare mktemp() in . */ +#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include +#endif + +#if @GNULIB_RANDOM_R@ + +/* OSF/1 5.1 declares 'struct random_data' in , which is included + from if _REENTRANT is defined. Include it whenever we need + 'struct random_data'. */ +# if @HAVE_RANDOM_H@ +# include +# endif + +# if !@HAVE_STRUCT_RANDOM_DATA@ || @REPLACE_RANDOM_R@ || !@HAVE_RANDOM_R@ +# include +# endif + +# if !@HAVE_STRUCT_RANDOM_DATA@ +/* Define 'struct random_data'. + But allow multiple gnulib generated replacements to coexist. */ +# if !GNULIB_defined_struct_random_data +struct random_data +{ + int32_t *fptr; /* Front pointer. */ + int32_t *rptr; /* Rear pointer. */ + int32_t *state; /* Array of state values. */ + int rand_type; /* Type of random number generator. */ + int rand_deg; /* Degree of random number generator. */ + int rand_sep; /* Distance between front and rear. */ + int32_t *end_ptr; /* Pointer behind state table. */ +}; +# define GNULIB_defined_struct_random_data 1 +# endif +# endif +#endif + +#if (@GNULIB_MKSTEMP@ || @GNULIB_MKSTEMPS@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +/* On Mac OS X 10.3, only declares mkstemp. */ +/* On Mac OS X 10.5, only declares mkstemps. */ +/* On Cygwin 1.7.1, only declares getsubopt. */ +/* But avoid namespace pollution on glibc systems and native Windows. */ +# include +#endif + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The attribute __pure__ was added in gcc 2.96. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define _GL_ATTRIBUTE_PURE /* empty */ +#endif + +/* The definition of _Noreturn is copied here. */ + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Some systems do not define EXIT_*, despite otherwise supporting C89. */ +#ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +#endif +/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere + with proper operation of xargs. */ +#ifndef EXIT_FAILURE +# define EXIT_FAILURE 1 +#elif EXIT_FAILURE != 1 +# undef EXIT_FAILURE +# define EXIT_FAILURE 1 +#endif + + +#if @GNULIB__EXIT@ +/* Terminate the current process with the given return code, without running + the 'atexit' handlers. */ +# if !@HAVE__EXIT@ +_GL_FUNCDECL_SYS (_Exit, _Noreturn void, (int status)); +# endif +_GL_CXXALIAS_SYS (_Exit, void, (int status)); +_GL_CXXALIASWARN (_Exit); +#elif defined GNULIB_POSIXCHECK +# undef _Exit +# if HAVE_RAW_DECL__EXIT +_GL_WARN_ON_USE (_Exit, "_Exit is unportable - " + "use gnulib module _Exit for portability"); +# endif +#endif + + +#if @GNULIB_ATOLL@ +/* Parse a signed decimal integer. + Returns the value of the integer. Errors are not detected. */ +# if !@HAVE_ATOLL@ +_GL_FUNCDECL_SYS (atoll, long long, (const char *string) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (atoll, long long, (const char *string)); +_GL_CXXALIASWARN (atoll); +#elif defined GNULIB_POSIXCHECK +# undef atoll +# if HAVE_RAW_DECL_ATOLL +_GL_WARN_ON_USE (atoll, "atoll is unportable - " + "use gnulib module atoll for portability"); +# endif +#endif + +#if @GNULIB_CALLOC_POSIX@ +# if @REPLACE_CALLOC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef calloc +# define calloc rpl_calloc +# endif +_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size)); +_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); +# else +_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); +# endif +_GL_CXXALIASWARN (calloc); +#elif defined GNULIB_POSIXCHECK +# undef calloc +/* Assume calloc is always declared. */ +_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - " + "use gnulib module calloc-posix for portability"); +#endif + +#if @GNULIB_CANONICALIZE_FILE_NAME@ +# if @REPLACE_CANONICALIZE_FILE_NAME@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define canonicalize_file_name rpl_canonicalize_file_name +# endif +_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); +# else +# if !@HAVE_CANONICALIZE_FILE_NAME@ +_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name)); +# endif +_GL_CXXALIASWARN (canonicalize_file_name); +#elif defined GNULIB_POSIXCHECK +# undef canonicalize_file_name +# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME +_GL_WARN_ON_USE (canonicalize_file_name, + "canonicalize_file_name is unportable - " + "use gnulib module canonicalize-lgpl for portability"); +# endif +#endif + +#if @GNULIB_GETLOADAVG@ +/* Store max(NELEM,3) load average numbers in LOADAVG[]. + The three numbers are the load average of the last 1 minute, the last 5 + minutes, and the last 15 minutes, respectively. + LOADAVG is an array of NELEM numbers. */ +# if !@HAVE_DECL_GETLOADAVG@ +_GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem)); +_GL_CXXALIASWARN (getloadavg); +#elif defined GNULIB_POSIXCHECK +# undef getloadavg +# if HAVE_RAW_DECL_GETLOADAVG +_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - " + "use gnulib module getloadavg for portability"); +# endif +#endif + +#if @GNULIB_GETSUBOPT@ +/* Assuming *OPTIONP is a comma separated list of elements of the form + "token" or "token=value", getsubopt parses the first of these elements. + If the first element refers to a "token" that is member of the given + NULL-terminated array of tokens: + - It replaces the comma with a NUL byte, updates *OPTIONP to point past + the first option and the comma, sets *VALUEP to the value of the + element (or NULL if it doesn't contain an "=" sign), + - It returns the index of the "token" in the given array of tokens. + Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. + For more details see the POSIX:2001 specification. + http://www.opengroup.org/susv3xsh/getsubopt.html */ +# if !@HAVE_GETSUBOPT@ +_GL_FUNCDECL_SYS (getsubopt, int, + (char **optionp, char *const *tokens, char **valuep) + _GL_ARG_NONNULL ((1, 2, 3))); +# endif +_GL_CXXALIAS_SYS (getsubopt, int, + (char **optionp, char *const *tokens, char **valuep)); +_GL_CXXALIASWARN (getsubopt); +#elif defined GNULIB_POSIXCHECK +# undef getsubopt +# if HAVE_RAW_DECL_GETSUBOPT +_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - " + "use gnulib module getsubopt for portability"); +# endif +#endif + +#if @GNULIB_GRANTPT@ +/* Change the ownership and access permission of the slave side of the + pseudo-terminal whose master side is specified by FD. */ +# if !@HAVE_GRANTPT@ +_GL_FUNCDECL_SYS (grantpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (grantpt, int, (int fd)); +_GL_CXXALIASWARN (grantpt); +#elif defined GNULIB_POSIXCHECK +# undef grantpt +# if HAVE_RAW_DECL_GRANTPT +_GL_WARN_ON_USE (grantpt, "grantpt is not portable - " + "use gnulib module grantpt for portability"); +# endif +#endif + +/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not + rely on GNU or POSIX semantics for malloc and realloc (for example, + by never specifying a zero size), so it does not need malloc or + realloc to be redefined. */ +#if @GNULIB_MALLOC_POSIX@ +# if @REPLACE_MALLOC@ +# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \ + || _GL_USE_STDLIB_ALLOC) +# undef malloc +# define malloc rpl_malloc +# endif +_GL_FUNCDECL_RPL (malloc, void *, (size_t size)); +_GL_CXXALIAS_RPL (malloc, void *, (size_t size)); +# else +_GL_CXXALIAS_SYS (malloc, void *, (size_t size)); +# endif +_GL_CXXALIASWARN (malloc); +#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC +# undef malloc +/* Assume malloc is always declared. */ +_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " + "use gnulib module malloc-posix for portability"); +#endif + +/* Convert a multibyte character to a wide character. */ +#if @GNULIB_MBTOWC@ +# if @REPLACE_MBTOWC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbtowc +# define mbtowc rpl_mbtowc +# endif +_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); +_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); +# else +_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); +# endif +_GL_CXXALIASWARN (mbtowc); +#endif + +#if @GNULIB_MKDTEMP@ +/* Create a unique temporary directory from TEMPLATE. + The last six characters of TEMPLATE must be "XXXXXX"; + they are replaced with a string that makes the directory name unique. + Returns TEMPLATE, or a null pointer if it cannot get a unique name. + The directory is created mode 700. */ +# if !@HAVE_MKDTEMP@ +_GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/)); +_GL_CXXALIASWARN (mkdtemp); +#elif defined GNULIB_POSIXCHECK +# undef mkdtemp +# if HAVE_RAW_DECL_MKDTEMP +_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - " + "use gnulib module mkdtemp for portability"); +# endif +#endif + +#if @GNULIB_MKOSTEMP@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + The file is then created, with the specified flags, ensuring it didn't exist + before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKOSTEMP@ +_GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)); +_GL_CXXALIASWARN (mkostemp); +#elif defined GNULIB_POSIXCHECK +# undef mkostemp +# if HAVE_RAW_DECL_MKOSTEMP +_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - " + "use gnulib module mkostemp for portability"); +# endif +#endif + +#if @GNULIB_MKOSTEMPS@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE before a suffix of length + SUFFIXLEN must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + The file is then created, with the specified flags, ensuring it didn't exist + before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKOSTEMPS@ +_GL_FUNCDECL_SYS (mkostemps, int, + (char * /*template*/, int /*suffixlen*/, int /*flags*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkostemps, int, + (char * /*template*/, int /*suffixlen*/, int /*flags*/)); +_GL_CXXALIASWARN (mkostemps); +#elif defined GNULIB_POSIXCHECK +# undef mkostemps +# if HAVE_RAW_DECL_MKOSTEMPS +_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - " + "use gnulib module mkostemps for portability"); +# endif +#endif + +#if @GNULIB_MKSTEMP@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The file is then created, ensuring it didn't exist before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if @REPLACE_MKSTEMP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mkstemp rpl_mkstemp +# endif +_GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/)); +# else +# if ! @HAVE_MKSTEMP@ +_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/)); +# endif +_GL_CXXALIASWARN (mkstemp); +#elif defined GNULIB_POSIXCHECK +# undef mkstemp +# if HAVE_RAW_DECL_MKSTEMP +_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - " + "use gnulib module mkstemp for portability"); +# endif +#endif + +#if @GNULIB_MKSTEMPS@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE prior to a suffix of length + SUFFIXLEN must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The file is then created, ensuring it didn't exist before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKSTEMPS@ +_GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)); +_GL_CXXALIASWARN (mkstemps); +#elif defined GNULIB_POSIXCHECK +# undef mkstemps +# if HAVE_RAW_DECL_MKSTEMPS +_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - " + "use gnulib module mkstemps for portability"); +# endif +#endif + +#if @GNULIB_POSIX_OPENPT@ +/* Return an FD open to the master side of a pseudo-terminal. Flags should + include O_RDWR, and may also include O_NOCTTY. */ +# if !@HAVE_POSIX_OPENPT@ +_GL_FUNCDECL_SYS (posix_openpt, int, (int flags)); +# endif +_GL_CXXALIAS_SYS (posix_openpt, int, (int flags)); +_GL_CXXALIASWARN (posix_openpt); +#elif defined GNULIB_POSIXCHECK +# undef posix_openpt +# if HAVE_RAW_DECL_POSIX_OPENPT +_GL_WARN_ON_USE (posix_openpt, "posix_openpt is not portable - " + "use gnulib module posix_openpt for portability"); +# endif +#endif + +#if @GNULIB_PTSNAME@ +/* Return the pathname of the pseudo-terminal slave associated with + the master FD is open on, or NULL on errors. */ +# if @REPLACE_PTSNAME@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ptsname +# define ptsname rpl_ptsname +# endif +_GL_FUNCDECL_RPL (ptsname, char *, (int fd)); +_GL_CXXALIAS_RPL (ptsname, char *, (int fd)); +# else +# if !@HAVE_PTSNAME@ +_GL_FUNCDECL_SYS (ptsname, char *, (int fd)); +# endif +_GL_CXXALIAS_SYS (ptsname, char *, (int fd)); +# endif +_GL_CXXALIASWARN (ptsname); +#elif defined GNULIB_POSIXCHECK +# undef ptsname +# if HAVE_RAW_DECL_PTSNAME +_GL_WARN_ON_USE (ptsname, "ptsname is not portable - " + "use gnulib module ptsname for portability"); +# endif +#endif + +#if @GNULIB_PTSNAME_R@ +/* Set the pathname of the pseudo-terminal slave associated with + the master FD is open on and return 0, or set errno and return + non-zero on errors. */ +# if @REPLACE_PTSNAME_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ptsname_r +# define ptsname_r rpl_ptsname_r +# endif +_GL_FUNCDECL_RPL (ptsname_r, int, (int fd, char *buf, size_t len)); +_GL_CXXALIAS_RPL (ptsname_r, int, (int fd, char *buf, size_t len)); +# else +# if !@HAVE_PTSNAME_R@ +_GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); +# endif +_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); +# endif +_GL_CXXALIASWARN (ptsname_r); +#elif defined GNULIB_POSIXCHECK +# undef ptsname_r +# if HAVE_RAW_DECL_PTSNAME_R +_GL_WARN_ON_USE (ptsname_r, "ptsname_r is not portable - " + "use gnulib module ptsname_r for portability"); +# endif +#endif + +#if @GNULIB_PUTENV@ +# if @REPLACE_PUTENV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putenv +# define putenv rpl_putenv +# endif +_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (putenv, int, (char *string)); +# else +_GL_CXXALIAS_SYS (putenv, int, (char *string)); +# endif +_GL_CXXALIASWARN (putenv); +#endif + + +#if @GNULIB_RANDOM_R@ +# if !@HAVE_RANDOM_R@ +# ifndef RAND_MAX +# define RAND_MAX 2147483647 +# endif +# endif +#endif + + +#if @GNULIB_RANDOM@ +# if !@HAVE_RANDOM@ +_GL_FUNCDECL_SYS (random, long, (void)); +# endif +_GL_CXXALIAS_SYS (random, long, (void)); +_GL_CXXALIASWARN (random); +#elif defined GNULIB_POSIXCHECK +# undef random +# if HAVE_RAW_DECL_RANDOM +_GL_WARN_ON_USE (random, "random is unportable - " + "use gnulib module random for portability"); +# endif +#endif + +#if @GNULIB_RANDOM@ +# if !@HAVE_RANDOM@ +_GL_FUNCDECL_SYS (srandom, void, (unsigned int seed)); +# endif +_GL_CXXALIAS_SYS (srandom, void, (unsigned int seed)); +_GL_CXXALIASWARN (srandom); +#elif defined GNULIB_POSIXCHECK +# undef srandom +# if HAVE_RAW_DECL_SRANDOM +_GL_WARN_ON_USE (srandom, "srandom is unportable - " + "use gnulib module random for portability"); +# endif +#endif + +#if @GNULIB_RANDOM@ +# if !@HAVE_RANDOM@ +_GL_FUNCDECL_SYS (initstate, char *, + (unsigned int seed, char *buf, size_t buf_size) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (initstate, char *, + (unsigned int seed, char *buf, size_t buf_size)); +_GL_CXXALIASWARN (initstate); +#elif defined GNULIB_POSIXCHECK +# undef initstate +# if HAVE_RAW_DECL_INITSTATE_R +_GL_WARN_ON_USE (initstate, "initstate is unportable - " + "use gnulib module random for portability"); +# endif +#endif + +#if @GNULIB_RANDOM@ +# if !@HAVE_RANDOM@ +_GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (setstate, char *, (char *arg_state)); +_GL_CXXALIASWARN (setstate); +#elif defined GNULIB_POSIXCHECK +# undef setstate +# if HAVE_RAW_DECL_SETSTATE_R +_GL_WARN_ON_USE (setstate, "setstate is unportable - " + "use gnulib module random for portability"); +# endif +#endif + + +#if @GNULIB_RANDOM_R@ +# if @REPLACE_RANDOM_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef random_r +# define random_r rpl_random_r +# endif +_GL_FUNCDECL_RPL (random_r, int, (struct random_data *buf, int32_t *result) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (random_r, int, (struct random_data *buf, int32_t *result)); +# else +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result)); +# endif +_GL_CXXALIASWARN (random_r); +#elif defined GNULIB_POSIXCHECK +# undef random_r +# if HAVE_RAW_DECL_RANDOM_R +_GL_WARN_ON_USE (random_r, "random_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if @REPLACE_RANDOM_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef srandom_r +# define srandom_r rpl_srandom_r +# endif +_GL_FUNCDECL_RPL (srandom_r, int, + (unsigned int seed, struct random_data *rand_state) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (srandom_r, int, + (unsigned int seed, struct random_data *rand_state)); +# else +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (srandom_r, int, + (unsigned int seed, struct random_data *rand_state) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (srandom_r, int, + (unsigned int seed, struct random_data *rand_state)); +# endif +_GL_CXXALIASWARN (srandom_r); +#elif defined GNULIB_POSIXCHECK +# undef srandom_r +# if HAVE_RAW_DECL_SRANDOM_R +_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if @REPLACE_RANDOM_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef initstate_r +# define initstate_r rpl_initstate_r +# endif +_GL_FUNCDECL_RPL (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state) + _GL_ARG_NONNULL ((2, 4))); +_GL_CXXALIAS_RPL (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state)); +# else +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state) + _GL_ARG_NONNULL ((2, 4))); +# endif +_GL_CXXALIAS_SYS (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state)); +# endif +_GL_CXXALIASWARN (initstate_r); +#elif defined GNULIB_POSIXCHECK +# undef initstate_r +# if HAVE_RAW_DECL_INITSTATE_R +_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if @REPLACE_RANDOM_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef setstate_r +# define setstate_r rpl_setstate_r +# endif +_GL_FUNCDECL_RPL (setstate_r, int, + (char *arg_state, struct random_data *rand_state) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (setstate_r, int, + (char *arg_state, struct random_data *rand_state)); +# else +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (setstate_r, int, + (char *arg_state, struct random_data *rand_state) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (setstate_r, int, + (char *arg_state, struct random_data *rand_state)); +# endif +_GL_CXXALIASWARN (setstate_r); +#elif defined GNULIB_POSIXCHECK +# undef setstate_r +# if HAVE_RAW_DECL_SETSTATE_R +_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + + +#if @GNULIB_REALLOC_POSIX@ +# if @REPLACE_REALLOC@ +# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \ + || _GL_USE_STDLIB_ALLOC) +# undef realloc +# define realloc rpl_realloc +# endif +_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); +_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); +# else +_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); +# endif +_GL_CXXALIASWARN (realloc); +#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC +# undef realloc +/* Assume realloc is always declared. */ +_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " + "use gnulib module realloc-posix for portability"); +#endif + +#if @GNULIB_REALPATH@ +# if @REPLACE_REALPATH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define realpath rpl_realpath +# endif +_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved)); +# else +# if !@HAVE_REALPATH@ +_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved)); +# endif +_GL_CXXALIASWARN (realpath); +#elif defined GNULIB_POSIXCHECK +# undef realpath +# if HAVE_RAW_DECL_REALPATH +_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module " + "canonicalize or canonicalize-lgpl for portability"); +# endif +#endif + +#if @GNULIB_RPMATCH@ +/* Test a user response to a question. + Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ +# if !@HAVE_RPMATCH@ +_GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (rpmatch, int, (const char *response)); +_GL_CXXALIASWARN (rpmatch); +#elif defined GNULIB_POSIXCHECK +# undef rpmatch +# if HAVE_RAW_DECL_RPMATCH +_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - " + "use gnulib module rpmatch for portability"); +# endif +#endif + +#if @GNULIB_SECURE_GETENV@ +/* Look up NAME in the environment, returning 0 in insecure situations. */ +# if !@HAVE_SECURE_GETENV@ +_GL_FUNCDECL_SYS (secure_getenv, char *, + (char const *name) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (secure_getenv, char *, (char const *name)); +_GL_CXXALIASWARN (secure_getenv); +#elif defined GNULIB_POSIXCHECK +# undef secure_getenv +# if HAVE_RAW_DECL_SECURE_GETENV +_GL_WARN_ON_USE (secure_getenv, "secure_getenv is unportable - " + "use gnulib module secure_getenv for portability"); +# endif +#endif + +#if @GNULIB_SETENV@ +/* Set NAME to VALUE in the environment. + If REPLACE is nonzero, overwrite an existing value. */ +# if @REPLACE_SETENV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef setenv +# define setenv rpl_setenv +# endif +_GL_FUNCDECL_RPL (setenv, int, + (const char *name, const char *value, int replace) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (setenv, int, + (const char *name, const char *value, int replace)); +# else +# if !@HAVE_DECL_SETENV@ +_GL_FUNCDECL_SYS (setenv, int, + (const char *name, const char *value, int replace) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (setenv, int, + (const char *name, const char *value, int replace)); +# endif +# if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@) +_GL_CXXALIASWARN (setenv); +# endif +#elif defined GNULIB_POSIXCHECK +# undef setenv +# if HAVE_RAW_DECL_SETENV +_GL_WARN_ON_USE (setenv, "setenv is unportable - " + "use gnulib module setenv for portability"); +# endif +#endif + +#if @GNULIB_STRTOD@ + /* Parse a double from STRING, updating ENDP if appropriate. */ +# if @REPLACE_STRTOD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strtod rpl_strtod +# endif +_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp)); +# else +# if !@HAVE_STRTOD@ +_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp)); +# endif +_GL_CXXALIASWARN (strtod); +#elif defined GNULIB_POSIXCHECK +# undef strtod +# if HAVE_RAW_DECL_STRTOD +_GL_WARN_ON_USE (strtod, "strtod is unportable - " + "use gnulib module strtod for portability"); +# endif +#endif + +#if @GNULIB_STRTOLL@ +/* Parse a signed integer whose textual representation starts at STRING. + The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, + it may be decimal or octal (with prefix "0") or hexadecimal (with prefix + "0x"). + If ENDPTR is not NULL, the address of the first byte after the integer is + stored in *ENDPTR. + Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set + to ERANGE. */ +# if !@HAVE_STRTOLL@ +_GL_FUNCDECL_SYS (strtoll, long long, + (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strtoll, long long, + (const char *string, char **endptr, int base)); +_GL_CXXALIASWARN (strtoll); +#elif defined GNULIB_POSIXCHECK +# undef strtoll +# if HAVE_RAW_DECL_STRTOLL +_GL_WARN_ON_USE (strtoll, "strtoll is unportable - " + "use gnulib module strtoll for portability"); +# endif +#endif + +#if @GNULIB_STRTOULL@ +/* Parse an unsigned integer whose textual representation starts at STRING. + The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, + it may be decimal or octal (with prefix "0") or hexadecimal (with prefix + "0x"). + If ENDPTR is not NULL, the address of the first byte after the integer is + stored in *ENDPTR. + Upon overflow, the return value is ULLONG_MAX, and errno is set to + ERANGE. */ +# if !@HAVE_STRTOULL@ +_GL_FUNCDECL_SYS (strtoull, unsigned long long, + (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strtoull, unsigned long long, + (const char *string, char **endptr, int base)); +_GL_CXXALIASWARN (strtoull); +#elif defined GNULIB_POSIXCHECK +# undef strtoull +# if HAVE_RAW_DECL_STRTOULL +_GL_WARN_ON_USE (strtoull, "strtoull is unportable - " + "use gnulib module strtoull for portability"); +# endif +#endif + +#if @GNULIB_UNLOCKPT@ +/* Unlock the slave side of the pseudo-terminal whose master side is specified + by FD, so that it can be opened. */ +# if !@HAVE_UNLOCKPT@ +_GL_FUNCDECL_SYS (unlockpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (unlockpt, int, (int fd)); +_GL_CXXALIASWARN (unlockpt); +#elif defined GNULIB_POSIXCHECK +# undef unlockpt +# if HAVE_RAW_DECL_UNLOCKPT +_GL_WARN_ON_USE (unlockpt, "unlockpt is not portable - " + "use gnulib module unlockpt for portability"); +# endif +#endif + +#if @GNULIB_UNSETENV@ +/* Remove the variable NAME from the environment. */ +# if @REPLACE_UNSETENV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unsetenv +# define unsetenv rpl_unsetenv +# endif +_GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (unsetenv, int, (const char *name)); +# else +# if !@HAVE_DECL_UNSETENV@ +_GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (unsetenv, int, (const char *name)); +# endif +# if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@) +_GL_CXXALIASWARN (unsetenv); +# endif +#elif defined GNULIB_POSIXCHECK +# undef unsetenv +# if HAVE_RAW_DECL_UNSETENV +_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - " + "use gnulib module unsetenv for portability"); +# endif +#endif + +/* Convert a wide character to a multibyte character. */ +#if @GNULIB_WCTOMB@ +# if @REPLACE_WCTOMB@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wctomb +# define wctomb rpl_wctomb +# endif +_GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc)); +_GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc)); +# else +_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc)); +# endif +_GL_CXXALIASWARN (wctomb); +#endif + + +#endif /* _@GUARD_PREFIX@_STDLIB_H */ +#endif /* _@GUARD_PREFIX@_STDLIB_H */ +#endif diff --git a/grub-core/gnulib/strcasecmp.c b/grub-core/gnulib/strcasecmp.c new file mode 100644 index 000000000..0f0a742ff --- /dev/null +++ b/grub-core/gnulib/strcasecmp.c @@ -0,0 +1,62 @@ +/* Case-insensitive string comparison function. + Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include + +#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) + +/* Compare strings S1 and S2, ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less than, equal to or greater + than S2. + Note: This function does not work with multibyte strings! */ + +int +strcasecmp (const char *s1, const char *s2) +{ + const unsigned char *p1 = (const unsigned char *) s1; + const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2) + return 0; + + do + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); + + if (c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); +} diff --git a/grub-core/gnulib/strchrnul.c b/grub-core/gnulib/strchrnul.c new file mode 100644 index 000000000..f6b072274 --- /dev/null +++ b/grub-core/gnulib/strchrnul.c @@ -0,0 +1,142 @@ +/* Searching in a string. + Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +/* Find the first occurrence of C in S or the final NUL byte. */ +char * +strchrnul (const char *s, int c_in) +{ + /* On 32-bit hardware, choosing longword to be a 32-bit unsigned + long instead of a 64-bit uintmax_t tends to give better + performance. On 64-bit hardware, unsigned long is generally 64 + bits already. Change this typedef to experiment with + performance. */ + typedef unsigned long int longword; + + const unsigned char *char_ptr; + const longword *longword_ptr; + longword repeated_one; + longword repeated_c; + unsigned char c; + + c = (unsigned char) c_in; + if (!c) + return rawmemchr (s, 0); + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s; + (size_t) char_ptr % sizeof (longword) != 0; + ++char_ptr) + if (!*char_ptr || *char_ptr == c) + return (char *) char_ptr; + + longword_ptr = (const longword *) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to any size longwords. */ + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + repeated_one = 0x01010101; + repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + } + + /* Instead of the traditional loop which tests each byte, we will + test a longword at a time. The tricky part is testing if *any of + the four* bytes in the longword in question are equal to NUL or + c. We first use an xor with repeated_c. This reduces the task + to testing whether *any of the four* bytes in longword1 or + longword2 is zero. + + Let's consider longword1. We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + The test whether any byte in longword1 or longword2 is zero is equivalent + to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine + this into a single test, whether (tmp1 | tmp2) is nonzero. + + This test can read more than one byte beyond the end of a string, + depending on where the terminating NUL is encountered. However, + this is considered safe since the initialization phase ensured + that the read will be aligned, therefore, the read will not cross + page boundaries and will not cause a fault. */ + + while (1) + { + longword longword1 = *longword_ptr ^ repeated_c; + longword longword2 = *longword_ptr; + + if (((((longword1 - repeated_one) & ~longword1) + | ((longword2 - repeated_one) & ~longword2)) + & (repeated_one << 7)) != 0) + break; + longword_ptr++; + } + + char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that one of the sizeof (longword) bytes + starting at char_ptr is == 0 or == c. On little-endian machines, + we could determine the first such byte without any further memory + accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. + Choose code that works in both cases. */ + + char_ptr = (unsigned char *) longword_ptr; + while (*char_ptr && (*char_ptr != c)) + char_ptr++; + return (char *) char_ptr; +} diff --git a/grub-core/gnulib/strchrnul.valgrind b/grub-core/gnulib/strchrnul.valgrind new file mode 100644 index 000000000..b14fa1304 --- /dev/null +++ b/grub-core/gnulib/strchrnul.valgrind @@ -0,0 +1,12 @@ +# Suppress a valgrind message about use of uninitialized memory in strchrnul(). +# This use is OK because it provides only a speedup. +{ + strchrnul-value4 + Memcheck:Value4 + fun:strchrnul +} +{ + strchrnul-value8 + Memcheck:Value8 + fun:strchrnul +} diff --git a/grub-core/gnulib/streq.h b/grub-core/gnulib/streq.h new file mode 100644 index 000000000..12c1867c8 --- /dev/null +++ b/grub-core/gnulib/streq.h @@ -0,0 +1,176 @@ +/* Optimized string comparison. + Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible . */ + +#ifndef _GL_STREQ_H +#define _GL_STREQ_H + +#include + +/* STREQ_OPT allows to optimize string comparison with a small literal string. + STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) + is semantically equivalent to + strcmp (s, "EUC-KR") == 0 + just faster. */ + +/* Help GCC to generate good code for string comparisons with + immediate strings. */ +#if defined (__GNUC__) && defined (__OPTIMIZE__) + +static inline int +streq9 (const char *s1, const char *s2) +{ + return strcmp (s1 + 9, s2 + 9) == 0; +} + +static inline int +streq8 (const char *s1, const char *s2, char s28) +{ + if (s1[8] == s28) + { + if (s28 == 0) + return 1; + else + return streq9 (s1, s2); + } + else + return 0; +} + +static inline int +streq7 (const char *s1, const char *s2, char s27, char s28) +{ + if (s1[7] == s27) + { + if (s27 == 0) + return 1; + else + return streq8 (s1, s2, s28); + } + else + return 0; +} + +static inline int +streq6 (const char *s1, const char *s2, char s26, char s27, char s28) +{ + if (s1[6] == s26) + { + if (s26 == 0) + return 1; + else + return streq7 (s1, s2, s27, s28); + } + else + return 0; +} + +static inline int +streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28) +{ + if (s1[5] == s25) + { + if (s25 == 0) + return 1; + else + return streq6 (s1, s2, s26, s27, s28); + } + else + return 0; +} + +static inline int +streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28) +{ + if (s1[4] == s24) + { + if (s24 == 0) + return 1; + else + return streq5 (s1, s2, s25, s26, s27, s28); + } + else + return 0; +} + +static inline int +streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28) +{ + if (s1[3] == s23) + { + if (s23 == 0) + return 1; + else + return streq4 (s1, s2, s24, s25, s26, s27, s28); + } + else + return 0; +} + +static inline int +streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28) +{ + if (s1[2] == s22) + { + if (s22 == 0) + return 1; + else + return streq3 (s1, s2, s23, s24, s25, s26, s27, s28); + } + else + return 0; +} + +static inline int +streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28) +{ + if (s1[1] == s21) + { + if (s21 == 0) + return 1; + else + return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28); + } + else + return 0; +} + +static inline int +streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28) +{ + if (s1[0] == s20) + { + if (s20 == 0) + return 1; + else + return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28); + } + else + return 0; +} + +#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \ + streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28) + +#else + +#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \ + (strcmp (s1, s2) == 0) + +#endif + +#endif /* _GL_STREQ_H */ diff --git a/grub-core/gnulib/strerror-override.c b/grub-core/gnulib/strerror-override.c new file mode 100644 index 000000000..d0ed2fb86 --- /dev/null +++ b/grub-core/gnulib/strerror-override.c @@ -0,0 +1,302 @@ +/* strerror-override.c --- POSIX compatible system error routine + + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2010. */ + +#include + +#include "strerror-override.h" + +#include + +#if GNULIB_defined_EWINSOCK /* native Windows platforms */ +# if HAVE_WINSOCK2_H +# include +# endif +#endif + +/* If ERRNUM maps to an errno value defined by gnulib, return a string + describing the error. Otherwise return NULL. */ +const char * +strerror_override (int errnum) +{ + /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */ + switch (errnum) + { +#if REPLACE_STRERROR_0 + case 0: + return "Success"; +#endif + +#if GNULIB_defined_ESOCK /* native Windows platforms with older */ + case EINPROGRESS: + return "Operation now in progress"; + case EALREADY: + return "Operation already in progress"; + case ENOTSOCK: + return "Socket operation on non-socket"; + case EDESTADDRREQ: + return "Destination address required"; + case EMSGSIZE: + return "Message too long"; + case EPROTOTYPE: + return "Protocol wrong type for socket"; + case ENOPROTOOPT: + return "Protocol not available"; + case EPROTONOSUPPORT: + return "Protocol not supported"; + case EOPNOTSUPP: + return "Operation not supported"; + case EAFNOSUPPORT: + return "Address family not supported by protocol"; + case EADDRINUSE: + return "Address already in use"; + case EADDRNOTAVAIL: + return "Cannot assign requested address"; + case ENETDOWN: + return "Network is down"; + case ENETUNREACH: + return "Network is unreachable"; + case ECONNRESET: + return "Connection reset by peer"; + case ENOBUFS: + return "No buffer space available"; + case EISCONN: + return "Transport endpoint is already connected"; + case ENOTCONN: + return "Transport endpoint is not connected"; + case ETIMEDOUT: + return "Connection timed out"; + case ECONNREFUSED: + return "Connection refused"; + case ELOOP: + return "Too many levels of symbolic links"; + case EHOSTUNREACH: + return "No route to host"; + case EWOULDBLOCK: + return "Operation would block"; +#endif +#if GNULIB_defined_ESTREAMS /* native Windows platforms with older */ + case ETXTBSY: + return "Text file busy"; + case ENODATA: + return "No data available"; + case ENOSR: + return "Out of streams resources"; + case ENOSTR: + return "Device not a stream"; + case ETIME: + return "Timer expired"; + case EOTHER: + return "Other error"; +#endif +#if GNULIB_defined_EWINSOCK /* native Windows platforms */ + case ESOCKTNOSUPPORT: + return "Socket type not supported"; + case EPFNOSUPPORT: + return "Protocol family not supported"; + case ESHUTDOWN: + return "Cannot send after transport endpoint shutdown"; + case ETOOMANYREFS: + return "Too many references: cannot splice"; + case EHOSTDOWN: + return "Host is down"; + case EPROCLIM: + return "Too many processes"; + case EUSERS: + return "Too many users"; + case EDQUOT: + return "Disk quota exceeded"; + case ESTALE: + return "Stale NFS file handle"; + case EREMOTE: + return "Object is remote"; +# if HAVE_WINSOCK2_H + /* WSA_INVALID_HANDLE maps to EBADF */ + /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */ + /* WSA_INVALID_PARAMETER maps to EINVAL */ + case WSA_OPERATION_ABORTED: + return "Overlapped operation aborted"; + case WSA_IO_INCOMPLETE: + return "Overlapped I/O event object not in signaled state"; + case WSA_IO_PENDING: + return "Overlapped operations will complete later"; + /* WSAEINTR maps to EINTR */ + /* WSAEBADF maps to EBADF */ + /* WSAEACCES maps to EACCES */ + /* WSAEFAULT maps to EFAULT */ + /* WSAEINVAL maps to EINVAL */ + /* WSAEMFILE maps to EMFILE */ + /* WSAEWOULDBLOCK maps to EWOULDBLOCK */ + /* WSAEINPROGRESS maps to EINPROGRESS */ + /* WSAEALREADY maps to EALREADY */ + /* WSAENOTSOCK maps to ENOTSOCK */ + /* WSAEDESTADDRREQ maps to EDESTADDRREQ */ + /* WSAEMSGSIZE maps to EMSGSIZE */ + /* WSAEPROTOTYPE maps to EPROTOTYPE */ + /* WSAENOPROTOOPT maps to ENOPROTOOPT */ + /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */ + /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */ + /* WSAEOPNOTSUPP maps to EOPNOTSUPP */ + /* WSAEPFNOSUPPORT is EPFNOSUPPORT */ + /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */ + /* WSAEADDRINUSE maps to EADDRINUSE */ + /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */ + /* WSAENETDOWN maps to ENETDOWN */ + /* WSAENETUNREACH maps to ENETUNREACH */ + /* WSAENETRESET maps to ENETRESET */ + /* WSAECONNABORTED maps to ECONNABORTED */ + /* WSAECONNRESET maps to ECONNRESET */ + /* WSAENOBUFS maps to ENOBUFS */ + /* WSAEISCONN maps to EISCONN */ + /* WSAENOTCONN maps to ENOTCONN */ + /* WSAESHUTDOWN is ESHUTDOWN */ + /* WSAETOOMANYREFS is ETOOMANYREFS */ + /* WSAETIMEDOUT maps to ETIMEDOUT */ + /* WSAECONNREFUSED maps to ECONNREFUSED */ + /* WSAELOOP maps to ELOOP */ + /* WSAENAMETOOLONG maps to ENAMETOOLONG */ + /* WSAEHOSTDOWN is EHOSTDOWN */ + /* WSAEHOSTUNREACH maps to EHOSTUNREACH */ + /* WSAENOTEMPTY maps to ENOTEMPTY */ + /* WSAEPROCLIM is EPROCLIM */ + /* WSAEUSERS is EUSERS */ + /* WSAEDQUOT is EDQUOT */ + /* WSAESTALE is ESTALE */ + /* WSAEREMOTE is EREMOTE */ + case WSASYSNOTREADY: + return "Network subsystem is unavailable"; + case WSAVERNOTSUPPORTED: + return "Winsock.dll version out of range"; + case WSANOTINITIALISED: + return "Successful WSAStartup not yet performed"; + case WSAEDISCON: + return "Graceful shutdown in progress"; + case WSAENOMORE: case WSA_E_NO_MORE: + return "No more results"; + case WSAECANCELLED: case WSA_E_CANCELLED: + return "Call was canceled"; + case WSAEINVALIDPROCTABLE: + return "Procedure call table is invalid"; + case WSAEINVALIDPROVIDER: + return "Service provider is invalid"; + case WSAEPROVIDERFAILEDINIT: + return "Service provider failed to initialize"; + case WSASYSCALLFAILURE: + return "System call failure"; + case WSASERVICE_NOT_FOUND: + return "Service not found"; + case WSATYPE_NOT_FOUND: + return "Class type not found"; + case WSAEREFUSED: + return "Database query was refused"; + case WSAHOST_NOT_FOUND: + return "Host not found"; + case WSATRY_AGAIN: + return "Nonauthoritative host not found"; + case WSANO_RECOVERY: + return "Nonrecoverable error"; + case WSANO_DATA: + return "Valid name, no data record of requested type"; + /* WSA_QOS_* omitted */ +# endif +#endif + +#if GNULIB_defined_ENOMSG + case ENOMSG: + return "No message of desired type"; +#endif + +#if GNULIB_defined_EIDRM + case EIDRM: + return "Identifier removed"; +#endif + +#if GNULIB_defined_ENOLINK + case ENOLINK: + return "Link has been severed"; +#endif + +#if GNULIB_defined_EPROTO + case EPROTO: + return "Protocol error"; +#endif + +#if GNULIB_defined_EMULTIHOP + case EMULTIHOP: + return "Multihop attempted"; +#endif + +#if GNULIB_defined_EBADMSG + case EBADMSG: + return "Bad message"; +#endif + +#if GNULIB_defined_EOVERFLOW + case EOVERFLOW: + return "Value too large for defined data type"; +#endif + +#if GNULIB_defined_ENOTSUP + case ENOTSUP: + return "Not supported"; +#endif + +#if GNULIB_defined_ENETRESET + case ENETRESET: + return "Network dropped connection on reset"; +#endif + +#if GNULIB_defined_ECONNABORTED + case ECONNABORTED: + return "Software caused connection abort"; +#endif + +#if GNULIB_defined_ESTALE + case ESTALE: + return "Stale NFS file handle"; +#endif + +#if GNULIB_defined_EDQUOT + case EDQUOT: + return "Disk quota exceeded"; +#endif + +#if GNULIB_defined_ECANCELED + case ECANCELED: + return "Operation canceled"; +#endif + +#if GNULIB_defined_EOWNERDEAD + case EOWNERDEAD: + return "Owner died"; +#endif + +#if GNULIB_defined_ENOTRECOVERABLE + case ENOTRECOVERABLE: + return "State not recoverable"; +#endif + +#if GNULIB_defined_EILSEQ + case EILSEQ: + return "Invalid or incomplete multibyte or wide character"; +#endif + + default: + return NULL; + } +} diff --git a/grub-core/gnulib/strerror-override.h b/grub-core/gnulib/strerror-override.h new file mode 100644 index 000000000..3b8f24b99 --- /dev/null +++ b/grub-core/gnulib/strerror-override.h @@ -0,0 +1,56 @@ +/* strerror-override.h --- POSIX compatible system error routine + + Copyright (C) 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _GL_STRERROR_OVERRIDE_H +# define _GL_STRERROR_OVERRIDE_H + +# include +# include + +/* Reasonable buffer size that should never trigger ERANGE; if this + proves too small, we intentionally abort(), to remind us to fix + this value. */ +# define STACKBUF_LEN 256 + +/* If ERRNUM maps to an errno value defined by gnulib, return a string + describing the error. Otherwise return NULL. */ +# if REPLACE_STRERROR_0 \ + || GNULIB_defined_ESOCK \ + || GNULIB_defined_ESTREAMS \ + || GNULIB_defined_EWINSOCK \ + || GNULIB_defined_ENOMSG \ + || GNULIB_defined_EIDRM \ + || GNULIB_defined_ENOLINK \ + || GNULIB_defined_EPROTO \ + || GNULIB_defined_EMULTIHOP \ + || GNULIB_defined_EBADMSG \ + || GNULIB_defined_EOVERFLOW \ + || GNULIB_defined_ENOTSUP \ + || GNULIB_defined_ENETRESET \ + || GNULIB_defined_ECONNABORTED \ + || GNULIB_defined_ESTALE \ + || GNULIB_defined_EDQUOT \ + || GNULIB_defined_ECANCELED \ + || GNULIB_defined_EOWNERDEAD \ + || GNULIB_defined_ENOTRECOVERABLE \ + || GNULIB_defined_EILSEQ +extern const char *strerror_override (int errnum); +# else +# define strerror_override(ignored) NULL +# endif + +#endif /* _GL_STRERROR_OVERRIDE_H */ diff --git a/grub-core/gnulib/strerror.c b/grub-core/gnulib/strerror.c new file mode 100644 index 000000000..80a2f2eea --- /dev/null +++ b/grub-core/gnulib/strerror.c @@ -0,0 +1,70 @@ +/* strerror.c --- POSIX compatible system error routine + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include +#include +#include + +#include "intprops.h" +#include "strerror-override.h" +#include "verify.h" + +/* Use the system functions, not the gnulib overrides in this file. */ +#undef sprintf + +char * +strerror (int n) +#undef strerror +{ + static char buf[STACKBUF_LEN]; + size_t len; + + /* Cast away const, due to the historical signature of strerror; + callers should not be modifying the string. */ + const char *msg = strerror_override (n); + if (msg) + return (char *) msg; + + msg = strerror (n); + + /* Our strerror_r implementation might use the system's strerror + buffer, so all other clients of strerror have to see the error + copied into a buffer that we manage. This is not thread-safe, + even if the system strerror is, but portable programs shouldn't + be using strerror if they care about thread-safety. */ + if (!msg || !*msg) + { + static char const fmt[] = "Unknown error %d"; + verify (sizeof buf >= sizeof (fmt) + INT_STRLEN_BOUND (n)); + sprintf (buf, fmt, n); + errno = EINVAL; + return buf; + } + + /* Fix STACKBUF_LEN if this ever aborts. */ + len = strlen (msg); + if (sizeof buf <= len) + abort (); + + return memcpy (buf, msg, len + 1); +} diff --git a/grub-core/gnulib/string.in.h b/grub-core/gnulib/string.in.h new file mode 100644 index 000000000..d7a6c9c92 --- /dev/null +++ b/grub-core/gnulib/string.in.h @@ -0,0 +1,1029 @@ +/* A GNU-like . + + Copyright (C) 1995-1996, 2001-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _@GUARD_PREFIX@_STRING_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_STRING_H@ + +#ifndef _@GUARD_PREFIX@_STRING_H +#define _@GUARD_PREFIX@_STRING_H + +/* NetBSD 5.0 mis-defines NULL. */ +#include + +/* MirBSD defines mbslen as a macro. */ +#if @GNULIB_MBSLEN@ && defined __MirBSD__ +# include +#endif + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The attribute __pure__ was added in gcc 2.96. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define _GL_ATTRIBUTE_PURE /* empty */ +#endif + +/* NetBSD 5.0 declares strsignal in , not in . */ +/* But in any case avoid namespace pollution on glibc systems. */ +#if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \ + && ! defined __GLIBC__ +# include +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Find the index of the least-significant set bit. */ +#if @GNULIB_FFSL@ +# if !@HAVE_FFSL@ +_GL_FUNCDECL_SYS (ffsl, int, (long int i)); +# endif +_GL_CXXALIAS_SYS (ffsl, int, (long int i)); +_GL_CXXALIASWARN (ffsl); +#elif defined GNULIB_POSIXCHECK +# undef ffsl +# if HAVE_RAW_DECL_FFSL +_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module"); +# endif +#endif + + +/* Find the index of the least-significant set bit. */ +#if @GNULIB_FFSLL@ +# if !@HAVE_FFSLL@ +_GL_FUNCDECL_SYS (ffsll, int, (long long int i)); +# endif +_GL_CXXALIAS_SYS (ffsll, int, (long long int i)); +_GL_CXXALIASWARN (ffsll); +#elif defined GNULIB_POSIXCHECK +# undef ffsll +# if HAVE_RAW_DECL_FFSLL +_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module"); +# endif +#endif + + +/* Return the first instance of C within N bytes of S, or NULL. */ +#if @GNULIB_MEMCHR@ +# if @REPLACE_MEMCHR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define memchr rpl_memchr +# endif +_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); +# else +# if ! @HAVE_MEMCHR@ +_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C" { const void * std::memchr (const void *, int, size_t); } + extern "C++" { void * std::memchr (void *, int, size_t); } */ +_GL_CXXALIAS_SYS_CAST2 (memchr, + void *, (void const *__s, int __c, size_t __n), + void const *, (void const *__s, int __c, size_t __n)); +# endif +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); +_GL_CXXALIASWARN1 (memchr, void const *, + (void const *__s, int __c, size_t __n)); +# else +_GL_CXXALIASWARN (memchr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef memchr +/* Assume memchr is always declared. */ +_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - " + "use gnulib module memchr for portability" ); +#endif + +/* Return the first occurrence of NEEDLE in HAYSTACK. */ +#if @GNULIB_MEMMEM@ +# if @REPLACE_MEMMEM@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define memmem rpl_memmem +# endif +_GL_FUNCDECL_RPL (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 3))); +_GL_CXXALIAS_RPL (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len)); +# else +# if ! @HAVE_DECL_MEMMEM@ +_GL_FUNCDECL_SYS (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 3))); +# endif +_GL_CXXALIAS_SYS (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len)); +# endif +_GL_CXXALIASWARN (memmem); +#elif defined GNULIB_POSIXCHECK +# undef memmem +# if HAVE_RAW_DECL_MEMMEM +_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " + "use gnulib module memmem-simple for portability, " + "and module memmem for speed" ); +# endif +#endif + +/* Copy N bytes of SRC to DEST, return pointer to bytes after the + last written byte. */ +#if @GNULIB_MEMPCPY@ +# if ! @HAVE_MEMPCPY@ +_GL_FUNCDECL_SYS (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n)); +_GL_CXXALIASWARN (mempcpy); +#elif defined GNULIB_POSIXCHECK +# undef mempcpy +# if HAVE_RAW_DECL_MEMPCPY +_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - " + "use gnulib module mempcpy for portability"); +# endif +#endif + +/* Search backwards through a block for a byte (specified as an int). */ +#if @GNULIB_MEMRCHR@ +# if ! @HAVE_DECL_MEMRCHR@ +_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const void * std::memrchr (const void *, int, size_t); } + extern "C++" { void * std::memrchr (void *, int, size_t); } */ +_GL_CXXALIAS_SYS_CAST2 (memrchr, + void *, (void const *, int, size_t), + void const *, (void const *, int, size_t)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t)); +_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t)); +# else +_GL_CXXALIASWARN (memrchr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef memrchr +# if HAVE_RAW_DECL_MEMRCHR +_GL_WARN_ON_USE (memrchr, "memrchr is unportable - " + "use gnulib module memrchr for portability"); +# endif +#endif + +/* Find the first occurrence of C in S. More efficient than + memchr(S,C,N), at the expense of undefined behavior if C does not + occur within N bytes. */ +#if @GNULIB_RAWMEMCHR@ +# if ! @HAVE_RAWMEMCHR@ +_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const void * std::rawmemchr (const void *, int); } + extern "C++" { void * std::rawmemchr (void *, int); } */ +_GL_CXXALIAS_SYS_CAST2 (rawmemchr, + void *, (void const *__s, int __c_in), + void const *, (void const *__s, int __c_in)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in)); +_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in)); +# else +_GL_CXXALIASWARN (rawmemchr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef rawmemchr +# if HAVE_RAW_DECL_RAWMEMCHR +_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " + "use gnulib module rawmemchr for portability"); +# endif +#endif + +/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ +#if @GNULIB_STPCPY@ +# if ! @HAVE_STPCPY@ +_GL_FUNCDECL_SYS (stpcpy, char *, + (char *restrict __dst, char const *restrict __src) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (stpcpy, char *, + (char *restrict __dst, char const *restrict __src)); +_GL_CXXALIASWARN (stpcpy); +#elif defined GNULIB_POSIXCHECK +# undef stpcpy +# if HAVE_RAW_DECL_STPCPY +_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - " + "use gnulib module stpcpy for portability"); +# endif +#endif + +/* Copy no more than N bytes of SRC to DST, returning a pointer past the + last non-NUL byte written into DST. */ +#if @GNULIB_STPNCPY@ +# if @REPLACE_STPNCPY@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef stpncpy +# define stpncpy rpl_stpncpy +# endif +_GL_FUNCDECL_RPL (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n)); +# else +# if ! @HAVE_STPNCPY@ +_GL_FUNCDECL_SYS (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n)); +# endif +_GL_CXXALIASWARN (stpncpy); +#elif defined GNULIB_POSIXCHECK +# undef stpncpy +# if HAVE_RAW_DECL_STPNCPY +_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - " + "use gnulib module stpncpy for portability"); +# endif +#endif + +#if defined GNULIB_POSIXCHECK +/* strchr() does not work with multibyte strings if the locale encoding is + GB18030 and the character to be searched is a digit. */ +# undef strchr +/* Assume strchr is always declared. */ +_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " + "in some multibyte locales - " + "use mbschr if you care about internationalization"); +#endif + +/* Find the first occurrence of C in S or the final NUL byte. */ +#if @GNULIB_STRCHRNUL@ +# if @REPLACE_STRCHRNUL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strchrnul rpl_strchrnul +# endif +_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strchrnul, char *, + (const char *str, int ch)); +# else +# if ! @HAVE_STRCHRNUL@ +_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * std::strchrnul (const char *, int); } + extern "C++" { char * std::strchrnul (char *, int); } */ +_GL_CXXALIAS_SYS_CAST2 (strchrnul, + char *, (char const *__s, int __c_in), + char const *, (char const *__s, int __c_in)); +# endif +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in)); +_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in)); +# else +_GL_CXXALIASWARN (strchrnul); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strchrnul +# if HAVE_RAW_DECL_STRCHRNUL +_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - " + "use gnulib module strchrnul for portability"); +# endif +#endif + +/* Duplicate S, returning an identical malloc'd string. */ +#if @GNULIB_STRDUP@ +# if @REPLACE_STRDUP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strdup +# define strdup rpl_strdup +# endif +_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); +# else +# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup + /* strdup exists as a function and as a macro. Get rid of the macro. */ +# undef strdup +# endif +# if !(@HAVE_DECL_STRDUP@ || defined strdup) +_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); +# endif +_GL_CXXALIASWARN (strdup); +#elif defined GNULIB_POSIXCHECK +# undef strdup +# if HAVE_RAW_DECL_STRDUP +_GL_WARN_ON_USE (strdup, "strdup is unportable - " + "use gnulib module strdup for portability"); +# endif +#endif + +/* Append no more than N characters from SRC onto DEST. */ +#if @GNULIB_STRNCAT@ +# if @REPLACE_STRNCAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strncat +# define strncat rpl_strncat +# endif +_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); +# else +_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); +# endif +_GL_CXXALIASWARN (strncat); +#elif defined GNULIB_POSIXCHECK +# undef strncat +# if HAVE_RAW_DECL_STRNCAT +_GL_WARN_ON_USE (strncat, "strncat is unportable - " + "use gnulib module strncat for portability"); +# endif +#endif + +/* Return a newly allocated copy of at most N bytes of STRING. */ +#if @GNULIB_STRNDUP@ +# if @REPLACE_STRNDUP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strndup +# define strndup rpl_strndup +# endif +_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n)); +# else +# if ! @HAVE_DECL_STRNDUP@ +_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n)); +# endif +_GL_CXXALIASWARN (strndup); +#elif defined GNULIB_POSIXCHECK +# undef strndup +# if HAVE_RAW_DECL_STRNDUP +_GL_WARN_ON_USE (strndup, "strndup is unportable - " + "use gnulib module strndup for portability"); +# endif +#endif + +/* Find the length (number of bytes) of STRING, but scan at most + MAXLEN bytes. If no '\0' terminator is found in that many bytes, + return MAXLEN. */ +#if @GNULIB_STRNLEN@ +# if @REPLACE_STRNLEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strnlen +# define strnlen rpl_strnlen +# endif +_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); +# else +# if ! @HAVE_DECL_STRNLEN@ +_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); +# endif +_GL_CXXALIASWARN (strnlen); +#elif defined GNULIB_POSIXCHECK +# undef strnlen +# if HAVE_RAW_DECL_STRNLEN +_GL_WARN_ON_USE (strnlen, "strnlen is unportable - " + "use gnulib module strnlen for portability"); +# endif +#endif + +#if defined GNULIB_POSIXCHECK +/* strcspn() assumes the second argument is a list of single-byte characters. + Even in this simple case, it does not work with multibyte strings if the + locale encoding is GB18030 and one of the characters to be searched is a + digit. */ +# undef strcspn +/* Assume strcspn is always declared. */ +_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings " + "in multibyte locales - " + "use mbscspn if you care about internationalization"); +#endif + +/* Find the first occurrence in S of any character in ACCEPT. */ +#if @GNULIB_STRPBRK@ +# if ! @HAVE_STRPBRK@ +_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C" { const char * strpbrk (const char *, const char *); } + extern "C++" { char * strpbrk (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strpbrk, + char *, (char const *__s, char const *__accept), + const char *, (char const *__s, char const *__accept)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); +_GL_CXXALIASWARN1 (strpbrk, char const *, + (char const *__s, char const *__accept)); +# else +_GL_CXXALIASWARN (strpbrk); +# endif +# if defined GNULIB_POSIXCHECK +/* strpbrk() assumes the second argument is a list of single-byte characters. + Even in this simple case, it does not work with multibyte strings if the + locale encoding is GB18030 and one of the characters to be searched is a + digit. */ +# undef strpbrk +_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " + "in multibyte locales - " + "use mbspbrk if you care about internationalization"); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strpbrk +# if HAVE_RAW_DECL_STRPBRK +_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " + "use gnulib module strpbrk for portability"); +# endif +#endif + +#if defined GNULIB_POSIXCHECK +/* strspn() assumes the second argument is a list of single-byte characters. + Even in this simple case, it cannot work with multibyte strings. */ +# undef strspn +/* Assume strspn is always declared. */ +_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings " + "in multibyte locales - " + "use mbsspn if you care about internationalization"); +#endif + +#if defined GNULIB_POSIXCHECK +/* strrchr() does not work with multibyte strings if the locale encoding is + GB18030 and the character to be searched is a digit. */ +# undef strrchr +/* Assume strrchr is always declared. */ +_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " + "in some multibyte locales - " + "use mbsrchr if you care about internationalization"); +#endif + +/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. + If one is found, overwrite it with a NUL, and advance *STRINGP + to point to the next char after it. Otherwise, set *STRINGP to NULL. + If *STRINGP was already NULL, nothing happens. + Return the old value of *STRINGP. + + This is a variant of strtok() that is multithread-safe and supports + empty fields. + + Caveat: It modifies the original string. + Caveat: These functions cannot be used on constant strings. + Caveat: The identity of the delimiting character is lost. + Caveat: It doesn't work with multibyte strings unless all of the delimiter + characters are ASCII characters < 0x30. + + See also strtok_r(). */ +#if @GNULIB_STRSEP@ +# if ! @HAVE_STRSEP@ +_GL_FUNCDECL_SYS (strsep, char *, + (char **restrict __stringp, char const *restrict __delim) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (strsep, char *, + (char **restrict __stringp, char const *restrict __delim)); +_GL_CXXALIASWARN (strsep); +# if defined GNULIB_POSIXCHECK +# undef strsep +_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings " + "in multibyte locales - " + "use mbssep if you care about internationalization"); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strsep +# if HAVE_RAW_DECL_STRSEP +_GL_WARN_ON_USE (strsep, "strsep is unportable - " + "use gnulib module strsep for portability"); +# endif +#endif + +#if @GNULIB_STRSTR@ +# if @REPLACE_STRSTR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strstr rpl_strstr +# endif +_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); +# else + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * strstr (const char *, const char *); } + extern "C++" { char * strstr (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strstr, + char *, (const char *haystack, const char *needle), + const char *, (const char *haystack, const char *needle)); +# endif +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); +_GL_CXXALIASWARN1 (strstr, const char *, + (const char *haystack, const char *needle)); +# else +_GL_CXXALIASWARN (strstr); +# endif +#elif defined GNULIB_POSIXCHECK +/* strstr() does not work with multibyte strings if the locale encoding is + different from UTF-8: + POSIX says that it operates on "strings", and "string" in POSIX is defined + as a sequence of bytes, not of characters. */ +# undef strstr +/* Assume strstr is always declared. */ +_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot " + "work correctly on character strings in most " + "multibyte locales - " + "use mbsstr if you care about internationalization, " + "or use strstr if you care about speed"); +#endif + +/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive + comparison. */ +#if @GNULIB_STRCASESTR@ +# if @REPLACE_STRCASESTR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strcasestr rpl_strcasestr +# endif +_GL_FUNCDECL_RPL (strcasestr, char *, + (const char *haystack, const char *needle) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strcasestr, char *, + (const char *haystack, const char *needle)); +# else +# if ! @HAVE_STRCASESTR@ +_GL_FUNCDECL_SYS (strcasestr, char *, + (const char *haystack, const char *needle) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * strcasestr (const char *, const char *); } + extern "C++" { char * strcasestr (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strcasestr, + char *, (const char *haystack, const char *needle), + const char *, (const char *haystack, const char *needle)); +# endif +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle)); +_GL_CXXALIASWARN1 (strcasestr, const char *, + (const char *haystack, const char *needle)); +# else +_GL_CXXALIASWARN (strcasestr); +# endif +#elif defined GNULIB_POSIXCHECK +/* strcasestr() does not work with multibyte strings: + It is a glibc extension, and glibc implements it only for unibyte + locales. */ +# undef strcasestr +# if HAVE_RAW_DECL_STRCASESTR +_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character " + "strings in multibyte locales - " + "use mbscasestr if you care about " + "internationalization, or use c-strcasestr if you want " + "a locale independent function"); +# endif +#endif + +/* Parse S into tokens separated by characters in DELIM. + If S is NULL, the saved pointer in SAVE_PTR is used as + the next starting point. For example: + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" + + This is a variant of strtok() that is multithread-safe. + + For the POSIX documentation for this function, see: + http://www.opengroup.org/susv3xsh/strtok.html + + Caveat: It modifies the original string. + Caveat: These functions cannot be used on constant strings. + Caveat: The identity of the delimiting character is lost. + Caveat: It doesn't work with multibyte strings unless all of the delimiter + characters are ASCII characters < 0x30. + + See also strsep(). */ +#if @GNULIB_STRTOK_R@ +# if @REPLACE_STRTOK_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strtok_r +# define strtok_r rpl_strtok_r +# endif +_GL_FUNCDECL_RPL (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr) + _GL_ARG_NONNULL ((2, 3))); +_GL_CXXALIAS_RPL (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr)); +# else +# if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK +# undef strtok_r +# endif +# if ! @HAVE_DECL_STRTOK_R@ +_GL_FUNCDECL_SYS (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr) + _GL_ARG_NONNULL ((2, 3))); +# endif +_GL_CXXALIAS_SYS (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr)); +# endif +_GL_CXXALIASWARN (strtok_r); +# if defined GNULIB_POSIXCHECK +_GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character " + "strings in multibyte locales - " + "use mbstok_r if you care about internationalization"); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strtok_r +# if HAVE_RAW_DECL_STRTOK_R +_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " + "use gnulib module strtok_r for portability"); +# endif +#endif + + +/* The following functions are not specified by POSIX. They are gnulib + extensions. */ + +#if @GNULIB_MBSLEN@ +/* Return the number of multibyte characters in the character string STRING. + This considers multibyte characters, unlike strlen, which counts bytes. */ +# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ +# undef mbslen +# endif +# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbslen rpl_mbslen +# endif +_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string)); +# else +_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); +# endif +_GL_CXXALIASWARN (mbslen); +#endif + +#if @GNULIB_MBSNLEN@ +/* Return the number of multibyte characters in the character string starting + at STRING and ending at STRING + LEN. */ +_GL_EXTERN_C size_t mbsnlen (const char *string, size_t len) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1)); +#endif + +#if @GNULIB_MBSCHR@ +/* Locate the first single-byte character C in the character string STRING, + and return a pointer to it. Return NULL if C is not found in STRING. + Unlike strchr(), this function works correctly in multibyte locales with + encodings such as GB18030. */ +# if defined __hpux +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ +# endif +_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c)); +# else +_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c)); +# endif +_GL_CXXALIASWARN (mbschr); +#endif + +#if @GNULIB_MBSRCHR@ +/* Locate the last single-byte character C in the character string STRING, + and return a pointer to it. Return NULL if C is not found in STRING. + Unlike strrchr(), this function works correctly in multibyte locales with + encodings such as GB18030. */ +# if defined __hpux || defined __INTERIX +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbsrchr rpl_mbsrchr /* avoid collision with system function */ +# endif +_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c)); +# else +_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c)); +# endif +_GL_CXXALIASWARN (mbsrchr); +#endif + +#if @GNULIB_MBSSTR@ +/* Find the first occurrence of the character string NEEDLE in the character + string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. + Unlike strstr(), this function works correctly in multibyte locales with + encodings different from UTF-8. */ +_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSCASECMP@ +/* Compare the character strings S1 and S2, ignoring case, returning less than, + equal to or greater than zero if S1 is lexicographically less than, equal to + or greater than S2. + Note: This function may, in multibyte locales, return 0 for strings of + different lengths! + Unlike strcasecmp(), this function works correctly in multibyte locales. */ +_GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSNCASECMP@ +/* Compare the initial segment of the character string S1 consisting of at most + N characters with the initial segment of the character string S2 consisting + of at most N characters, ignoring case, returning less than, equal to or + greater than zero if the initial segment of S1 is lexicographically less + than, equal to or greater than the initial segment of S2. + Note: This function may, in multibyte locales, return 0 for initial segments + of different lengths! + Unlike strncasecmp(), this function works correctly in multibyte locales. + But beware that N is not a byte count but a character count! */ +_GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSPCASECMP@ +/* Compare the initial segment of the character string STRING consisting of + at most mbslen (PREFIX) characters with the character string PREFIX, + ignoring case. If the two match, return a pointer to the first byte + after this prefix in STRING. Otherwise, return NULL. + Note: This function may, in multibyte locales, return non-NULL if STRING + is of smaller length than PREFIX! + Unlike strncasecmp(), this function works correctly in multibyte + locales. */ +_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSCASESTR@ +/* Find the first occurrence of the character string NEEDLE in the character + string HAYSTACK, using case-insensitive comparison. + Note: This function may, in multibyte locales, return success even if + strlen (haystack) < strlen (needle) ! + Unlike strcasestr(), this function works correctly in multibyte locales. */ +_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSCSPN@ +/* Find the first occurrence in the character string STRING of any character + in the character string ACCEPT. Return the number of bytes from the + beginning of the string to this occurrence, or to the end of the string + if none exists. + Unlike strcspn(), this function works correctly in multibyte locales. */ +_GL_EXTERN_C size_t mbscspn (const char *string, const char *accept) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSPBRK@ +/* Find the first occurrence in the character string STRING of any character + in the character string ACCEPT. Return the pointer to it, or NULL if none + exists. + Unlike strpbrk(), this function works correctly in multibyte locales. */ +# if defined __hpux +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ +# endif +_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept)); +# else +_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept)); +# endif +_GL_CXXALIASWARN (mbspbrk); +#endif + +#if @GNULIB_MBSSPN@ +/* Find the first occurrence in the character string STRING of any character + not in the character string REJECT. Return the number of bytes from the + beginning of the string to this occurrence, or to the end of the string + if none exists. + Unlike strspn(), this function works correctly in multibyte locales. */ +_GL_EXTERN_C size_t mbsspn (const char *string, const char *reject) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSSEP@ +/* Search the next delimiter (multibyte character listed in the character + string DELIM) starting at the character string *STRINGP. + If one is found, overwrite it with a NUL, and advance *STRINGP to point + to the next multibyte character after it. Otherwise, set *STRINGP to NULL. + If *STRINGP was already NULL, nothing happens. + Return the old value of *STRINGP. + + This is a variant of mbstok_r() that supports empty fields. + + Caveat: It modifies the original string. + Caveat: These functions cannot be used on constant strings. + Caveat: The identity of the delimiting character is lost. + + See also mbstok_r(). */ +_GL_EXTERN_C char * mbssep (char **stringp, const char *delim) + _GL_ARG_NONNULL ((1, 2)); +#endif + +#if @GNULIB_MBSTOK_R@ +/* Parse the character string STRING into tokens separated by characters in + the character string DELIM. + If STRING is NULL, the saved pointer in SAVE_PTR is used as + the next starting point. For example: + char s[] = "-abc-=-def"; + char *sp; + x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = mbstok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" + + Caveat: It modifies the original string. + Caveat: These functions cannot be used on constant strings. + Caveat: The identity of the delimiting character is lost. + + See also mbssep(). */ +_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) + _GL_ARG_NONNULL ((2, 3)); +#endif + +/* Map any int, typically from errno, into an error message. */ +#if @GNULIB_STRERROR@ +# if @REPLACE_STRERROR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strerror +# define strerror rpl_strerror +# endif +_GL_FUNCDECL_RPL (strerror, char *, (int)); +_GL_CXXALIAS_RPL (strerror, char *, (int)); +# else +_GL_CXXALIAS_SYS (strerror, char *, (int)); +# endif +_GL_CXXALIASWARN (strerror); +#elif defined GNULIB_POSIXCHECK +# undef strerror +/* Assume strerror is always declared. */ +_GL_WARN_ON_USE (strerror, "strerror is unportable - " + "use gnulib module strerror to guarantee non-NULL result"); +#endif + +/* Map any int, typically from errno, into an error message. Multithread-safe. + Uses the POSIX declaration, not the glibc declaration. */ +#if @GNULIB_STRERROR_R@ +# if @REPLACE_STRERROR_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strerror_r +# define strerror_r rpl_strerror_r +# endif +_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)); +# else +# if !@HAVE_DECL_STRERROR_R@ +_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)); +# endif +# if @HAVE_DECL_STRERROR_R@ +_GL_CXXALIASWARN (strerror_r); +# endif +#elif defined GNULIB_POSIXCHECK +# undef strerror_r +# if HAVE_RAW_DECL_STRERROR_R +_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - " + "use gnulib module strerror_r-posix for portability"); +# endif +#endif + +#if @GNULIB_STRSIGNAL@ +# if @REPLACE_STRSIGNAL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strsignal rpl_strsignal +# endif +_GL_FUNCDECL_RPL (strsignal, char *, (int __sig)); +_GL_CXXALIAS_RPL (strsignal, char *, (int __sig)); +# else +# if ! @HAVE_DECL_STRSIGNAL@ +_GL_FUNCDECL_SYS (strsignal, char *, (int __sig)); +# endif +/* Need to cast, because on Cygwin 1.5.x systems, the return type is + 'const char *'. */ +_GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig)); +# endif +_GL_CXXALIASWARN (strsignal); +#elif defined GNULIB_POSIXCHECK +# undef strsignal +# if HAVE_RAW_DECL_STRSIGNAL +_GL_WARN_ON_USE (strsignal, "strsignal is unportable - " + "use gnulib module strsignal for portability"); +# endif +#endif + +#if @GNULIB_STRVERSCMP@ +# if !@HAVE_STRVERSCMP@ +_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *)); +_GL_CXXALIASWARN (strverscmp); +#elif defined GNULIB_POSIXCHECK +# undef strverscmp +# if HAVE_RAW_DECL_STRVERSCMP +_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - " + "use gnulib module strverscmp for portability"); +# endif +#endif + + +#endif /* _@GUARD_PREFIX@_STRING_H */ +#endif /* _@GUARD_PREFIX@_STRING_H */ diff --git a/grub-core/gnulib/strings.in.h b/grub-core/gnulib/strings.in.h new file mode 100644 index 000000000..4469f86ca --- /dev/null +++ b/grub-core/gnulib/strings.in.h @@ -0,0 +1,122 @@ +/* A substitute . + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _@GUARD_PREFIX@_STRINGS_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* Minix 3.1.8 has a bug: must be included before . + But avoid namespace pollution on glibc systems. */ +#if defined __minix && !defined __GLIBC__ +# include +#endif + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_STRINGS_H@ +# @INCLUDE_NEXT@ @NEXT_STRINGS_H@ +#endif + +#ifndef _@GUARD_PREFIX@_STRINGS_H +#define _@GUARD_PREFIX@_STRINGS_H + +#if ! @HAVE_DECL_STRNCASECMP@ +/* Get size_t. */ +# include +#endif + + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +#ifdef __cplusplus +extern "C" { +#endif + + + /* Find the index of the least-significant set bit. */ +#if @GNULIB_FFS@ +# if !@HAVE_FFS@ +_GL_FUNCDECL_SYS (ffs, int, (int i)); +# endif +_GL_CXXALIAS_SYS (ffs, int, (int i)); +_GL_CXXALIASWARN (ffs); +#elif defined GNULIB_POSIXCHECK +# undef ffs +# if HAVE_RAW_DECL_FFS +_GL_WARN_ON_USE (ffs, "ffs is not portable - use the ffs module"); +# endif +#endif + +/* Compare strings S1 and S2, ignoring case, returning less than, equal to or + greater than zero if S1 is lexicographically less than, equal to or greater + than S2. + Note: This function does not work in multibyte locales. */ +#if ! @HAVE_STRCASECMP@ +extern int strcasecmp (char const *s1, char const *s2) + _GL_ARG_NONNULL ((1, 2)); +#endif +#if defined GNULIB_POSIXCHECK +/* strcasecmp() does not work with multibyte strings: + POSIX says that it operates on "strings", and "string" in POSIX is defined + as a sequence of bytes, not of characters. */ +# undef strcasecmp +# if HAVE_RAW_DECL_STRCASECMP +_GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character " + "strings in multibyte locales - " + "use mbscasecmp if you care about " + "internationalization, or use c_strcasecmp , " + "gnulib module c-strcase) if you want a locale " + "independent function"); +# endif +#endif + +/* Compare no more than N bytes of strings S1 and S2, ignoring case, + returning less than, equal to or greater than zero if S1 is + lexicographically less than, equal to or greater than S2. + Note: This function cannot work correctly in multibyte locales. */ +#if ! @HAVE_DECL_STRNCASECMP@ +extern int strncasecmp (char const *s1, char const *s2, size_t n) + _GL_ARG_NONNULL ((1, 2)); +#endif +#if defined GNULIB_POSIXCHECK +/* strncasecmp() does not work with multibyte strings: + POSIX says that it operates on "strings", and "string" in POSIX is defined + as a sequence of bytes, not of characters. */ +# undef strncasecmp +# if HAVE_RAW_DECL_STRNCASECMP +_GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character " + "strings in multibyte locales - " + "use mbsncasecmp or mbspcasecmp if you care about " + "internationalization, or use c_strncasecmp , " + "gnulib module c-strcase) if you want a locale " + "independent function"); +# endif +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* _@GUARD_PREFIX@_STRING_H */ +#endif /* _@GUARD_PREFIX@_STRING_H */ diff --git a/grub-core/gnulib/stripslash.c b/grub-core/gnulib/stripslash.c new file mode 100644 index 000000000..0e452a95e --- /dev/null +++ b/grub-core/gnulib/stripslash.c @@ -0,0 +1,45 @@ +/* stripslash.c -- remove redundant trailing slashes from a file name + + Copyright (C) 1990, 2001, 2003-2006, 2009-2013 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include "dirname.h" + +/* Remove trailing slashes from FILE. Return true if a trailing slash + was removed. This is useful when using file name completion from a + shell that adds a "/" after directory names (such as tcsh and + bash), because on symlinks to directories, several system calls + have different semantics according to whether a trailing slash is + present. */ + +bool +strip_trailing_slashes (char *file) +{ + char *base = last_component (file); + char *base_lim; + bool had_slash; + + /* last_component returns "" for file system roots, but we need to turn + "///" into "/". */ + if (! *base) + base = file; + base_lim = base + base_len (base); + had_slash = (*base_lim != '\0'); + *base_lim = '\0'; + return had_slash; +} diff --git a/grub-core/gnulib/strncasecmp.c b/grub-core/gnulib/strncasecmp.c new file mode 100644 index 000000000..35840bc01 --- /dev/null +++ b/grub-core/gnulib/strncasecmp.c @@ -0,0 +1,62 @@ +/* strncasecmp.c -- case insensitive string comparator + Copyright (C) 1998-1999, 2005-2007, 2009-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include + +#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) + +/* Compare no more than N bytes of strings S1 and S2, ignoring case, + returning less than, equal to or greater than zero if S1 is + lexicographically less than, equal to or greater than S2. + Note: This function cannot work correctly in multibyte locales. */ + +int +strncasecmp (const char *s1, const char *s2, size_t n) +{ + register const unsigned char *p1 = (const unsigned char *) s1; + register const unsigned char *p2 = (const unsigned char *) s2; + unsigned char c1, c2; + + if (p1 == p2 || n == 0) + return 0; + + do + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); + + if (--n == 0 || c1 == '\0') + break; + + ++p1; + ++p2; + } + while (c1 == c2); + + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, the + difference of two 'unsigned char' values - including the sign bit - + doesn't fit in an 'int'. */ + return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); +} diff --git a/grub-core/gnulib/strndup.c b/grub-core/gnulib/strndup.c new file mode 100644 index 000000000..e60268b86 --- /dev/null +++ b/grub-core/gnulib/strndup.c @@ -0,0 +1,36 @@ +/* A replacement function, for systems that lack strndup. + + Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#include + +#include + +#include + +char * +strndup (char const *s, size_t n) +{ + size_t len = strnlen (s, n); + char *new = malloc (len + 1); + + if (new == NULL) + return NULL; + + new[len] = '\0'; + return memcpy (new, s, len); +} diff --git a/grub-core/gnulib/strnlen.c b/grub-core/gnulib/strnlen.c new file mode 100644 index 000000000..57fdfe770 --- /dev/null +++ b/grub-core/gnulib/strnlen.c @@ -0,0 +1,30 @@ +/* Find the length of STRING, but scan at most MAXLEN characters. + Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#include + +#include + +/* Find the length of STRING, but scan at most MAXLEN characters. + If no '\0' terminator is found in that many characters, return MAXLEN. */ + +size_t +strnlen (const char *string, size_t maxlen) +{ + const char *end = memchr (string, '\0', maxlen); + return end ? (size_t) (end - string) : maxlen; +} diff --git a/grub-core/gnulib/strnlen1.c b/grub-core/gnulib/strnlen1.c new file mode 100644 index 000000000..0c22d21ed --- /dev/null +++ b/grub-core/gnulib/strnlen1.c @@ -0,0 +1,35 @@ +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "strnlen1.h" + +#include + +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +/* This is the same as strnlen (string, maxlen - 1) + 1. */ +size_t +strnlen1 (const char *string, size_t maxlen) +{ + const char *end = (const char *) memchr (string, '\0', maxlen); + if (end != NULL) + return end - string + 1; + else + return maxlen; +} diff --git a/grub-core/gnulib/strnlen1.h b/grub-core/gnulib/strnlen1.h new file mode 100644 index 000000000..7c65e3161 --- /dev/null +++ b/grub-core/gnulib/strnlen1.h @@ -0,0 +1,40 @@ +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _STRNLEN1_H +#define _STRNLEN1_H + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Find the length of STRING + 1, but scan at most MAXLEN bytes. + If no '\0' terminator is found in that many characters, return MAXLEN. */ +/* This is the same as strnlen (string, maxlen - 1) + 1. */ +extern size_t strnlen1 (const char *string, size_t maxlen) + _GL_ATTRIBUTE_PURE; + + +#ifdef __cplusplus +} +#endif + + +#endif /* _STRNLEN1_H */ diff --git a/grub-core/gnulib/sys_types.in.h b/grub-core/gnulib/sys_types.in.h new file mode 100644 index 000000000..d7da35623 --- /dev/null +++ b/grub-core/gnulib/sys_types.in.h @@ -0,0 +1,51 @@ +/* Provide a more complete sys/types.h. + + Copyright (C) 2011-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#ifndef _@GUARD_PREFIX@_SYS_TYPES_H + +/* The include_next requires a split double-inclusion guard. */ +#@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@ + +#ifndef _@GUARD_PREFIX@_SYS_TYPES_H +#define _@GUARD_PREFIX@_SYS_TYPES_H + +/* Override off_t if Large File Support is requested on native Windows. */ +#if @WINDOWS_64_BIT_OFF_T@ +/* Same as int64_t in . */ +# if defined _MSC_VER +# define off_t __int64 +# else +# define off_t long long int +# endif +/* Indicator, for gnulib internal purposes. */ +# define _GL_WINDOWS_64_BIT_OFF_T 1 +#endif + +/* MSVC 9 defines size_t in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) \ + && ! defined __GLIBC__ +# include +#endif + +#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ +#endif /* _@GUARD_PREFIX@_SYS_TYPES_H */ diff --git a/grub-core/gnulib/sysexits.in.h b/grub-core/gnulib/sysexits.in.h new file mode 100644 index 000000000..fa8db8386 --- /dev/null +++ b/grub-core/gnulib/sysexits.in.h @@ -0,0 +1,72 @@ +/* exit() exit codes for some BSD system programs. + Copyright (C) 2003, 2006-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Simon Josefsson based on sysexits(3) man page */ + +#ifndef _@GUARD_PREFIX@_SYSEXITS_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if @HAVE_SYSEXITS_H@ + +/* IRIX 6.5 has an that defines a macro EX_OK with a nonzero + value. Override it. See + */ +# ifdef __sgi +# include +# undef EX_OK +# endif + +/* The include_next requires a split double-inclusion guard. */ +# @INCLUDE_NEXT@ @NEXT_SYSEXITS_H@ + +/* HP-UX 11 ends at EX_NOPERM. */ +# ifndef EX_CONFIG +# define EX_CONFIG 78 +# endif + +#endif + +#ifndef _@GUARD_PREFIX@_SYSEXITS_H +#define _@GUARD_PREFIX@_SYSEXITS_H + +#if !@HAVE_SYSEXITS_H@ + +# define EX_OK 0 /* same value as EXIT_SUCCESS */ + +# define EX_USAGE 64 +# define EX_DATAERR 65 +# define EX_NOINPUT 66 +# define EX_NOUSER 67 +# define EX_NOHOST 68 +# define EX_UNAVAILABLE 69 +# define EX_SOFTWARE 70 +# define EX_OSERR 71 +# define EX_OSFILE 72 +# define EX_CANTCREAT 73 +# define EX_IOERR 74 +# define EX_TEMPFAIL 75 +# define EX_PROTOCOL 76 +# define EX_NOPERM 77 +# define EX_CONFIG 78 + +#endif + +#endif /* _@GUARD_PREFIX@_SYSEXITS_H */ +#endif /* _@GUARD_PREFIX@_SYSEXITS_H */ diff --git a/grub-core/gnulib/unistd.c b/grub-core/gnulib/unistd.c new file mode 100644 index 000000000..6c6a8e268 --- /dev/null +++ b/grub-core/gnulib/unistd.c @@ -0,0 +1,3 @@ +#include +#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE +#include "unistd.h" diff --git a/grub-core/gnulib/unistd.in.h b/grub-core/gnulib/unistd.in.h new file mode 100644 index 000000000..2ea9af436 --- /dev/null +++ b/grub-core/gnulib/unistd.in.h @@ -0,0 +1,1530 @@ +/* Substitute for and wrapper around . + Copyright (C) 2003-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _@GUARD_PREFIX@_UNISTD_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_UNISTD_H@ +# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ +#endif + +/* Get all possible declarations of gethostname(). */ +#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \ + && !defined _GL_INCLUDING_WINSOCK2_H +# define _GL_INCLUDING_WINSOCK2_H +# include +# undef _GL_INCLUDING_WINSOCK2_H +#endif + +#if !defined _@GUARD_PREFIX@_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H +#define _@GUARD_PREFIX@_UNISTD_H + +/* NetBSD 5.0 mis-defines NULL. Also get size_t. */ +#include + +/* mingw doesn't define the SEEK_* or *_FILENO macros in . */ +/* Cygwin 1.7.1 declares symlinkat in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \ + || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \ + && defined __CYGWIN__)) \ + && ! defined __GLIBC__ +# include +#endif + +/* Cygwin 1.7.1 declares unlinkat in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \ + && ! defined __GLIBC__ +# include +#endif + +/* mingw fails to declare _exit in . */ +/* mingw, MSVC, BeOS, Haiku declare environ in , not in + . */ +/* Solaris declares getcwd not only in but also in . */ +/* OSF Tru64 Unix cannot see gnulib rpl_strtod when system is + included here. */ +/* But avoid namespace pollution on glibc systems. */ +#if !defined __GLIBC__ && !defined __osf__ +# define __need_system_stdlib_h +# include +# undef __need_system_stdlib_h +#endif + +/* Native Windows platforms declare chdir, getcwd, rmdir in + and/or , not in . + They also declare access(), chmod(), close(), dup(), dup2(), isatty(), + lseek(), read(), unlink(), write() in . */ +#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ + || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) +# include /* mingw32, mingw64 */ +# include /* mingw64, MSVC 9 */ +#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \ + || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \ + || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include +#endif + +/* AIX and OSF/1 5.1 declare getdomainname in , not in . + NonStop Kernel declares gethostname in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if ((@GNULIB_GETDOMAINNAME@ && (defined _AIX || defined __osf__)) \ + || (@GNULIB_GETHOSTNAME@ && defined __TANDEM)) \ + && !defined __GLIBC__ +# include +#endif + +/* MSVC defines off_t in . + May also define off_t to a 64-bit type on native Windows. */ +#if !@HAVE_UNISTD_H@ || @WINDOWS_64_BIT_OFF_T@ +/* Get off_t. */ +# include +#endif + +#if (@GNULIB_READ@ || @GNULIB_WRITE@ \ + || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \ + || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK) +/* Get ssize_t. */ +# include +#endif + +/* Get getopt(), optarg, optind, opterr, optopt. + But avoid namespace pollution on glibc systems. */ +#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT +# define __need_getopt +# include +#endif + +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_UNISTD_INLINE +# define _GL_UNISTD_INLINE _GL_INLINE +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Hide some function declarations from . */ + +#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ +# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef socket +# define socket socket_used_without_including_sys_socket_h +# undef connect +# define connect connect_used_without_including_sys_socket_h +# undef accept +# define accept accept_used_without_including_sys_socket_h +# undef bind +# define bind bind_used_without_including_sys_socket_h +# undef getpeername +# define getpeername getpeername_used_without_including_sys_socket_h +# undef getsockname +# define getsockname getsockname_used_without_including_sys_socket_h +# undef getsockopt +# define getsockopt getsockopt_used_without_including_sys_socket_h +# undef listen +# define listen listen_used_without_including_sys_socket_h +# undef recv +# define recv recv_used_without_including_sys_socket_h +# undef send +# define send send_used_without_including_sys_socket_h +# undef recvfrom +# define recvfrom recvfrom_used_without_including_sys_socket_h +# undef sendto +# define sendto sendto_used_without_including_sys_socket_h +# undef setsockopt +# define setsockopt setsockopt_used_without_including_sys_socket_h +# undef shutdown +# define shutdown shutdown_used_without_including_sys_socket_h +# else + _GL_WARN_ON_USE (socket, + "socket() used without including "); + _GL_WARN_ON_USE (connect, + "connect() used without including "); + _GL_WARN_ON_USE (accept, + "accept() used without including "); + _GL_WARN_ON_USE (bind, + "bind() used without including "); + _GL_WARN_ON_USE (getpeername, + "getpeername() used without including "); + _GL_WARN_ON_USE (getsockname, + "getsockname() used without including "); + _GL_WARN_ON_USE (getsockopt, + "getsockopt() used without including "); + _GL_WARN_ON_USE (listen, + "listen() used without including "); + _GL_WARN_ON_USE (recv, + "recv() used without including "); + _GL_WARN_ON_USE (send, + "send() used without including "); + _GL_WARN_ON_USE (recvfrom, + "recvfrom() used without including "); + _GL_WARN_ON_USE (sendto, + "sendto() used without including "); + _GL_WARN_ON_USE (setsockopt, + "setsockopt() used without including "); + _GL_WARN_ON_USE (shutdown, + "shutdown() used without including "); +# endif +# endif +# if !defined _@GUARD_PREFIX@_SYS_SELECT_H +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef select +# define select select_used_without_including_sys_select_h +# else + _GL_WARN_ON_USE (select, + "select() used without including "); +# endif +# endif +#endif + + +/* OS/2 EMX lacks these macros. */ +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +/* Ensure *_OK macros exist. */ +#ifndef F_OK +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 +#endif + + +/* Declare overridden functions. */ + + +#if defined GNULIB_POSIXCHECK +/* The access() function is a security risk. */ +_GL_WARN_ON_USE (access, "the access function is a security risk - " + "use the gnulib module faccessat instead"); +#endif + + +#if @GNULIB_CHDIR@ +_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1))); +_GL_CXXALIASWARN (chdir); +#elif defined GNULIB_POSIXCHECK +# undef chdir +# if HAVE_RAW_DECL_CHDIR +_GL_WARN_ON_USE (chown, "chdir is not always in - " + "use gnulib module chdir for portability"); +# endif +#endif + + +#if @GNULIB_CHOWN@ +/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE + to GID (if GID is not -1). Follow symbolic links. + Return 0 if successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if @REPLACE_DUP2@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dup2 rpl_dup2 +# endif +_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd)); +_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd)); +# else +# if !@HAVE_DUP2@ +_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd)); +# endif +_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd)); +# endif +_GL_CXXALIASWARN (dup2); +#elif defined GNULIB_POSIXCHECK +# undef dup2 +# if HAVE_RAW_DECL_DUP2 +_GL_WARN_ON_USE (dup2, "dup2 is unportable - " + "use gnulib module dup2 for portability"); +# endif +#endif + + +#if @GNULIB_DUP3@ +/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the + specified flags. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + Close NEWFD first if it is open. + Return newfd if successful, otherwise -1 and errno set. + See the Linux man page at + . */ +# if @HAVE_DUP3@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dup3 rpl_dup3 +# endif +_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags)); +_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags)); +# else +_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags)); +_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags)); +# endif +_GL_CXXALIASWARN (dup3); +#elif defined GNULIB_POSIXCHECK +# undef dup3 +# if HAVE_RAW_DECL_DUP3 +_GL_WARN_ON_USE (dup3, "dup3 is unportable - " + "use gnulib module dup3 for portability"); +# endif +#endif + + +#if @GNULIB_ENVIRON@ +# if !@HAVE_DECL_ENVIRON@ +/* Set of environment variables and values. An array of strings of the form + "VARIABLE=VALUE", terminated with a NULL. */ +# if defined __APPLE__ && defined __MACH__ +# include +# define environ (*_NSGetEnviron ()) +# else +# ifdef __cplusplus +extern "C" { +# endif +extern char **environ; +# ifdef __cplusplus +} +# endif +# endif +# endif +#elif defined GNULIB_POSIXCHECK +# if HAVE_RAW_DECL_ENVIRON +_GL_UNISTD_INLINE char *** +rpl_environ (void) +{ + return &environ; +} +_GL_WARN_ON_USE (rpl_environ, "environ is unportable - " + "use gnulib module environ for portability"); +# undef environ +# define environ (*rpl_environ ()) +# endif +#endif + + +#if @GNULIB_EUIDACCESS@ +/* Like access(), except that it uses the effective user id and group id of + the current process. */ +# if !@HAVE_EUIDACCESS@ +_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode)); +_GL_CXXALIASWARN (euidaccess); +# if defined GNULIB_POSIXCHECK +/* Like access(), this function is a security risk. */ +_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - " + "use the gnulib module faccessat instead"); +# endif +#elif defined GNULIB_POSIXCHECK +# undef euidaccess +# if HAVE_RAW_DECL_EUIDACCESS +_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - " + "use gnulib module euidaccess for portability"); +# endif +#endif + + +#if @GNULIB_FACCESSAT@ +# if !@HAVE_FACCESSAT@ +_GL_FUNCDECL_SYS (faccessat, int, + (int fd, char const *file, int mode, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (faccessat, int, + (int fd, char const *file, int mode, int flag)); +_GL_CXXALIASWARN (faccessat); +#elif defined GNULIB_POSIXCHECK +# undef faccessat +# if HAVE_RAW_DECL_FACCESSAT +_GL_WARN_ON_USE (faccessat, "faccessat is not portable - " + "use gnulib module faccessat for portability"); +# endif +#endif + + +#if @GNULIB_FCHDIR@ +/* Change the process' current working directory to the directory on which + the given file descriptor is open. + Return 0 if successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if ! @HAVE_FCHDIR@ +_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); + +/* Gnulib internal hooks needed to maintain the fchdir metadata. */ +_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename) + _GL_ARG_NONNULL ((2)); +_GL_EXTERN_C void _gl_unregister_fd (int fd); +_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd); +_GL_EXTERN_C const char *_gl_directory_name (int fd); + +# else +# if !@HAVE_DECL_FCHDIR@ +_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); +# endif +# endif +_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/)); +_GL_CXXALIASWARN (fchdir); +#elif defined GNULIB_POSIXCHECK +# undef fchdir +# if HAVE_RAW_DECL_FCHDIR +_GL_WARN_ON_USE (fchdir, "fchdir is unportable - " + "use gnulib module fchdir for portability"); +# endif +#endif + + +#if @GNULIB_FCHOWNAT@ +# if @REPLACE_FCHOWNAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fchownat +# define fchownat rpl_fchownat +# endif +_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag)); +# else +# if !@HAVE_FCHOWNAT@ +_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag)); +# endif +_GL_CXXALIASWARN (fchownat); +#elif defined GNULIB_POSIXCHECK +# undef fchownat +# if HAVE_RAW_DECL_FCHOWNAT +_GL_WARN_ON_USE (fchownat, "fchownat is not portable - " + "use gnulib module openat for portability"); +# endif +#endif + + +#if @GNULIB_FDATASYNC@ +/* Synchronize changes to a file. + Return 0 if successful, otherwise -1 and errno set. + See POSIX:2008 specification + . */ +# if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@ +_GL_FUNCDECL_SYS (fdatasync, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (fdatasync, int, (int fd)); +_GL_CXXALIASWARN (fdatasync); +#elif defined GNULIB_POSIXCHECK +# undef fdatasync +# if HAVE_RAW_DECL_FDATASYNC +_GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - " + "use gnulib module fdatasync for portability"); +# endif +#endif + + +#if @GNULIB_FSYNC@ +/* Synchronize changes, including metadata, to a file. + Return 0 if successful, otherwise -1 and errno set. + See POSIX:2008 specification + . */ +# if !@HAVE_FSYNC@ +_GL_FUNCDECL_SYS (fsync, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (fsync, int, (int fd)); +_GL_CXXALIASWARN (fsync); +#elif defined GNULIB_POSIXCHECK +# undef fsync +# if HAVE_RAW_DECL_FSYNC +_GL_WARN_ON_USE (fsync, "fsync is unportable - " + "use gnulib module fsync for portability"); +# endif +#endif + + +#if @GNULIB_FTRUNCATE@ +/* Change the size of the file to which FD is opened to become equal to LENGTH. + Return 0 if successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if @REPLACE_FTRUNCATE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ftruncate +# define ftruncate rpl_ftruncate +# endif +_GL_FUNCDECL_RPL (ftruncate, int, (int fd, off_t length)); +_GL_CXXALIAS_RPL (ftruncate, int, (int fd, off_t length)); +# else +# if !@HAVE_FTRUNCATE@ +_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length)); +# endif +_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length)); +# endif +_GL_CXXALIASWARN (ftruncate); +#elif defined GNULIB_POSIXCHECK +# undef ftruncate +# if HAVE_RAW_DECL_FTRUNCATE +_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - " + "use gnulib module ftruncate for portability"); +# endif +#endif + + +#if @GNULIB_GETCWD@ +/* Get the name of the current working directory, and put it in SIZE bytes + of BUF. + Return BUF if successful, or NULL if the directory couldn't be determined + or SIZE was too small. + See the POSIX:2008 specification + . + Additionally, the gnulib module 'getcwd' guarantees the following GNU + extension: If BUF is NULL, an array is allocated with 'malloc'; the array + is SIZE bytes long, unless SIZE == 0, in which case it is as big as + necessary. */ +# if @REPLACE_GETCWD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getcwd rpl_getcwd +# endif +_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size)); +_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size)); +# else +/* Need to cast, because on mingw, the second parameter is + int size. */ +_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size)); +# endif +_GL_CXXALIASWARN (getcwd); +#elif defined GNULIB_POSIXCHECK +# undef getcwd +# if HAVE_RAW_DECL_GETCWD +_GL_WARN_ON_USE (getcwd, "getcwd is unportable - " + "use gnulib module getcwd for portability"); +# endif +#endif + + +#if @GNULIB_GETDOMAINNAME@ +/* Return the NIS domain name of the machine. + WARNING! The NIS domain name is unrelated to the fully qualified host name + of the machine. It is also unrelated to email addresses. + WARNING! The NIS domain name is usually the empty string or "(none)" when + not using NIS. + + Put up to LEN bytes of the NIS domain name into NAME. + Null terminate it if the name is shorter than LEN. + If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. + Return 0 if successful, otherwise set errno and return -1. */ +# if @REPLACE_GETDOMAINNAME@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getdomainname +# define getdomainname rpl_getdomainname +# endif +_GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len)); +# else +# if !@HAVE_DECL_GETDOMAINNAME@ +_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len)); +# endif +_GL_CXXALIASWARN (getdomainname); +#elif defined GNULIB_POSIXCHECK +# undef getdomainname +# if HAVE_RAW_DECL_GETDOMAINNAME +_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - " + "use gnulib module getdomainname for portability"); +# endif +#endif + + +#if @GNULIB_GETDTABLESIZE@ +/* Return the maximum number of file descriptors in the current process. + In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ +# if !@HAVE_GETDTABLESIZE@ +_GL_FUNCDECL_SYS (getdtablesize, int, (void)); +# endif +_GL_CXXALIAS_SYS (getdtablesize, int, (void)); +_GL_CXXALIASWARN (getdtablesize); +#elif defined GNULIB_POSIXCHECK +# undef getdtablesize +# if HAVE_RAW_DECL_GETDTABLESIZE +_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - " + "use gnulib module getdtablesize for portability"); +# endif +#endif + + +#if @GNULIB_GETGROUPS@ +/* Return the supplemental groups that the current process belongs to. + It is unspecified whether the effective group id is in the list. + If N is 0, return the group count; otherwise, N describes how many + entries are available in GROUPS. Return -1 and set errno if N is + not 0 and not large enough. Fails with ENOSYS on some systems. */ +# if @REPLACE_GETGROUPS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getgroups +# define getgroups rpl_getgroups +# endif +_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups)); +_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups)); +# else +# if !@HAVE_GETGROUPS@ +_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups)); +# endif +_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups)); +# endif +_GL_CXXALIASWARN (getgroups); +#elif defined GNULIB_POSIXCHECK +# undef getgroups +# if HAVE_RAW_DECL_GETGROUPS +_GL_WARN_ON_USE (getgroups, "getgroups is unportable - " + "use gnulib module getgroups for portability"); +# endif +#endif + + +#if @GNULIB_GETHOSTNAME@ +/* Return the standard host name of the machine. + WARNING! The host name may or may not be fully qualified. + + Put up to LEN bytes of the host name into NAME. + Null terminate it if the name is shorter than LEN. + If the host name is longer than LEN, set errno = EINVAL and return -1. + Return 0 if successful, otherwise set errno and return -1. */ +# if @UNISTD_H_HAVE_WINSOCK2_H@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gethostname +# define gethostname rpl_gethostname +# endif +_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len)); +# else +# if !@HAVE_GETHOSTNAME@ +_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +# endif +/* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second + parameter is + int len. */ +_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len)); +# endif +_GL_CXXALIASWARN (gethostname); +#elif @UNISTD_H_HAVE_WINSOCK2_H@ +# undef gethostname +# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname +#elif defined GNULIB_POSIXCHECK +# undef gethostname +# if HAVE_RAW_DECL_GETHOSTNAME +_GL_WARN_ON_USE (gethostname, "gethostname is unportable - " + "use gnulib module gethostname for portability"); +# endif +#endif + + +#if @GNULIB_GETLOGIN@ +/* Returns the user's login name, or NULL if it cannot be found. Upon error, + returns NULL with errno set. + + See . + + Most programs don't need to use this function, because the information is + available through environment variables: + ${LOGNAME-$USER} on Unix platforms, + $USERNAME on native Windows platforms. + */ +# if !@HAVE_GETLOGIN@ +_GL_FUNCDECL_SYS (getlogin, char *, (void)); +# endif +_GL_CXXALIAS_SYS (getlogin, char *, (void)); +_GL_CXXALIASWARN (getlogin); +#elif defined GNULIB_POSIXCHECK +# undef getlogin +# if HAVE_RAW_DECL_GETLOGIN +_GL_WARN_ON_USE (getlogin, "getlogin is unportable - " + "use gnulib module getlogin for portability"); +# endif +#endif + + +#if @GNULIB_GETLOGIN_R@ +/* Copies the user's login name to NAME. + The array pointed to by NAME has room for SIZE bytes. + + Returns 0 if successful. Upon error, an error number is returned, or -1 in + the case that the login name cannot be found but no specific error is + provided (this case is hopefully rare but is left open by the POSIX spec). + + See . + + Most programs don't need to use this function, because the information is + available through environment variables: + ${LOGNAME-$USER} on Unix platforms, + $USERNAME on native Windows platforms. + */ +# if @REPLACE_GETLOGIN_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getlogin_r rpl_getlogin_r +# endif +_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size)); +# else +# if !@HAVE_DECL_GETLOGIN_R@ +_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size) + _GL_ARG_NONNULL ((1))); +# endif +/* Need to cast, because on Solaris 10 systems, the second argument is + int size. */ +_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size)); +# endif +_GL_CXXALIASWARN (getlogin_r); +#elif defined GNULIB_POSIXCHECK +# undef getlogin_r +# if HAVE_RAW_DECL_GETLOGIN_R +_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - " + "use gnulib module getlogin_r for portability"); +# endif +#endif + + +#if @GNULIB_GETPAGESIZE@ +# if @REPLACE_GETPAGESIZE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getpagesize rpl_getpagesize +# endif +_GL_FUNCDECL_RPL (getpagesize, int, (void)); +_GL_CXXALIAS_RPL (getpagesize, int, (void)); +# else +# if !@HAVE_GETPAGESIZE@ +# if !defined getpagesize +/* This is for POSIX systems. */ +# if !defined _gl_getpagesize && defined _SC_PAGESIZE +# if ! (defined __VMS && __VMS_VER < 70000000) +# define _gl_getpagesize() sysconf (_SC_PAGESIZE) +# endif +# endif +/* This is for older VMS. */ +# if !defined _gl_getpagesize && defined __VMS +# ifdef __ALPHA +# define _gl_getpagesize() 8192 +# else +# define _gl_getpagesize() 512 +# endif +# endif +/* This is for BeOS. */ +# if !defined _gl_getpagesize && @HAVE_OS_H@ +# include +# if defined B_PAGE_SIZE +# define _gl_getpagesize() B_PAGE_SIZE +# endif +# endif +/* This is for AmigaOS4.0. */ +# if !defined _gl_getpagesize && defined __amigaos4__ +# define _gl_getpagesize() 2048 +# endif +/* This is for older Unix systems. */ +# if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@ +# include +# ifdef EXEC_PAGESIZE +# define _gl_getpagesize() EXEC_PAGESIZE +# else +# ifdef NBPG +# ifndef CLSIZE +# define CLSIZE 1 +# endif +# define _gl_getpagesize() (NBPG * CLSIZE) +# else +# ifdef NBPC +# define _gl_getpagesize() NBPC +# endif +# endif +# endif +# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getpagesize() _gl_getpagesize () +# else +# if !GNULIB_defined_getpagesize_function +_GL_UNISTD_INLINE int +getpagesize () +{ + return _gl_getpagesize (); +} +# define GNULIB_defined_getpagesize_function 1 +# endif +# endif +# endif +# endif +/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */ +_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void)); +# endif +# if @HAVE_DECL_GETPAGESIZE@ +_GL_CXXALIASWARN (getpagesize); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getpagesize +# if HAVE_RAW_DECL_GETPAGESIZE +_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - " + "use gnulib module getpagesize for portability"); +# endif +#endif + + +#if @GNULIB_GETUSERSHELL@ +/* Return the next valid login shell on the system, or NULL when the end of + the list has been reached. */ +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (getusershell, char *, (void)); +# endif +_GL_CXXALIAS_SYS (getusershell, char *, (void)); +_GL_CXXALIASWARN (getusershell); +#elif defined GNULIB_POSIXCHECK +# undef getusershell +# if HAVE_RAW_DECL_GETUSERSHELL +_GL_WARN_ON_USE (getusershell, "getusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif +#endif + +#if @GNULIB_GETUSERSHELL@ +/* Rewind to pointer that is advanced at each getusershell() call. */ +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (setusershell, void, (void)); +# endif +_GL_CXXALIAS_SYS (setusershell, void, (void)); +_GL_CXXALIASWARN (setusershell); +#elif defined GNULIB_POSIXCHECK +# undef setusershell +# if HAVE_RAW_DECL_SETUSERSHELL +_GL_WARN_ON_USE (setusershell, "setusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif +#endif + +#if @GNULIB_GETUSERSHELL@ +/* Free the pointer that is advanced at each getusershell() call and + associated resources. */ +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (endusershell, void, (void)); +# endif +_GL_CXXALIAS_SYS (endusershell, void, (void)); +_GL_CXXALIASWARN (endusershell); +#elif defined GNULIB_POSIXCHECK +# undef endusershell +# if HAVE_RAW_DECL_ENDUSERSHELL +_GL_WARN_ON_USE (endusershell, "endusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif +#endif + + +#if @GNULIB_GROUP_MEMBER@ +/* Determine whether group id is in calling user's group list. */ +# if !@HAVE_GROUP_MEMBER@ +_GL_FUNCDECL_SYS (group_member, int, (gid_t gid)); +# endif +_GL_CXXALIAS_SYS (group_member, int, (gid_t gid)); +_GL_CXXALIASWARN (group_member); +#elif defined GNULIB_POSIXCHECK +# undef group_member +# if HAVE_RAW_DECL_GROUP_MEMBER +_GL_WARN_ON_USE (group_member, "group_member is unportable - " + "use gnulib module group-member for portability"); +# endif +#endif + + +#if @GNULIB_ISATTY@ +# if @REPLACE_ISATTY@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef isatty +# define isatty rpl_isatty +# endif +_GL_FUNCDECL_RPL (isatty, int, (int fd)); +_GL_CXXALIAS_RPL (isatty, int, (int fd)); +# else +_GL_CXXALIAS_SYS (isatty, int, (int fd)); +# endif +_GL_CXXALIASWARN (isatty); +#elif defined GNULIB_POSIXCHECK +# undef isatty +# if HAVE_RAW_DECL_ISATTY +_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - " + "use gnulib module isatty for portability"); +# endif +#endif + + +#if @GNULIB_LCHOWN@ +/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE + to GID (if GID is not -1). Do not follow symbolic links. + Return 0 if successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if @REPLACE_LCHOWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef lchown +# define lchown rpl_lchown +# endif +_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)); +# else +# if !@HAVE_LCHOWN@ +_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)); +# endif +_GL_CXXALIASWARN (lchown); +#elif defined GNULIB_POSIXCHECK +# undef lchown +# if HAVE_RAW_DECL_LCHOWN +_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - " + "use gnulib module lchown for portability"); +# endif +#endif + + +#if @GNULIB_LINK@ +/* Create a new hard link for an existing file. + Return 0 if successful, otherwise -1 and errno set. + See POSIX:2008 specification + . */ +# if @REPLACE_LINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define link rpl_link +# endif +_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2)); +# else +# if !@HAVE_LINK@ +_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2)); +# endif +_GL_CXXALIASWARN (link); +#elif defined GNULIB_POSIXCHECK +# undef link +# if HAVE_RAW_DECL_LINK +_GL_WARN_ON_USE (link, "link is unportable - " + "use gnulib module link for portability"); +# endif +#endif + + +#if @GNULIB_LINKAT@ +/* Create a new hard link for an existing file, relative to two + directories. FLAG controls whether symlinks are followed. + Return 0 if successful, otherwise -1 and errno set. */ +# if @REPLACE_LINKAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef linkat +# define linkat rpl_linkat +# endif +_GL_FUNCDECL_RPL (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag) + _GL_ARG_NONNULL ((2, 4))); +_GL_CXXALIAS_RPL (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag)); +# else +# if !@HAVE_LINKAT@ +_GL_FUNCDECL_SYS (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag) + _GL_ARG_NONNULL ((2, 4))); +# endif +_GL_CXXALIAS_SYS (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag)); +# endif +_GL_CXXALIASWARN (linkat); +#elif defined GNULIB_POSIXCHECK +# undef linkat +# if HAVE_RAW_DECL_LINKAT +_GL_WARN_ON_USE (linkat, "linkat is unportable - " + "use gnulib module linkat for portability"); +# endif +#endif + + +#if @GNULIB_LSEEK@ +/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. + Return the new offset if successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if @REPLACE_LSEEK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define lseek rpl_lseek +# endif +_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence)); +_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence)); +# else +_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence)); +# endif +_GL_CXXALIASWARN (lseek); +#elif defined GNULIB_POSIXCHECK +# undef lseek +# if HAVE_RAW_DECL_LSEEK +_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " + "systems - use gnulib module lseek for portability"); +# endif +#endif + + +#if @GNULIB_PIPE@ +/* Create a pipe, defaulting to O_BINARY mode. + Store the read-end as fd[0] and the write-end as fd[1]. + Return 0 upon success, or -1 with errno set upon failure. */ +# if !@HAVE_PIPE@ +_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (pipe, int, (int fd[2])); +_GL_CXXALIASWARN (pipe); +#elif defined GNULIB_POSIXCHECK +# undef pipe +# if HAVE_RAW_DECL_PIPE +_GL_WARN_ON_USE (pipe, "pipe is unportable - " + "use gnulib module pipe-posix for portability"); +# endif +#endif + + +#if @GNULIB_PIPE2@ +/* Create a pipe, applying the given flags when opening the read-end of the + pipe and the write-end of the pipe. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + Store the read-end as fd[0] and the write-end as fd[1]. + Return 0 upon success, or -1 with errno set upon failure. + See also the Linux man page at + . */ +# if @HAVE_PIPE2@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define pipe2 rpl_pipe2 +# endif +_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags)); +# else +_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags)); +# endif +_GL_CXXALIASWARN (pipe2); +#elif defined GNULIB_POSIXCHECK +# undef pipe2 +# if HAVE_RAW_DECL_PIPE2 +_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - " + "use gnulib module pipe2 for portability"); +# endif +#endif + + +#if @GNULIB_PREAD@ +/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET. + Return the number of bytes placed into BUF if successful, otherwise + set errno and return -1. 0 indicates EOF. + See the POSIX:2008 specification + . */ +# if @REPLACE_PREAD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef pread +# define pread rpl_pread +# endif +_GL_FUNCDECL_RPL (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset)); +# else +# if !@HAVE_PREAD@ +_GL_FUNCDECL_SYS (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset)); +# endif +_GL_CXXALIASWARN (pread); +#elif defined GNULIB_POSIXCHECK +# undef pread +# if HAVE_RAW_DECL_PREAD +_GL_WARN_ON_USE (pread, "pread is unportable - " + "use gnulib module pread for portability"); +# endif +#endif + + +#if @GNULIB_PWRITE@ +/* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET. + Return the number of bytes written if successful, otherwise + set errno and return -1. 0 indicates nothing written. See the + POSIX:2008 specification + . */ +# if @REPLACE_PWRITE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef pwrite +# define pwrite rpl_pwrite +# endif +_GL_FUNCDECL_RPL (pwrite, ssize_t, + (int fd, const void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (pwrite, ssize_t, + (int fd, const void *buf, size_t bufsize, off_t offset)); +# else +# if !@HAVE_PWRITE@ +_GL_FUNCDECL_SYS (pwrite, ssize_t, + (int fd, const void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (pwrite, ssize_t, + (int fd, const void *buf, size_t bufsize, off_t offset)); +# endif +_GL_CXXALIASWARN (pwrite); +#elif defined GNULIB_POSIXCHECK +# undef pwrite +# if HAVE_RAW_DECL_PWRITE +_GL_WARN_ON_USE (pwrite, "pwrite is unportable - " + "use gnulib module pwrite for portability"); +# endif +#endif + + +#if @GNULIB_READ@ +/* Read up to COUNT bytes from file descriptor FD into the buffer starting + at BUF. See the POSIX:2008 specification + . */ +# if @REPLACE_READ@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef read +# define read rpl_read +# endif +_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count)); +# else +/* Need to cast, because on mingw, the third parameter is + unsigned int count + and the return type is 'int'. */ +_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count)); +# endif +_GL_CXXALIASWARN (read); +#endif + + +#if @GNULIB_READLINK@ +/* Read the contents of the symbolic link FILE and place the first BUFSIZE + bytes of it into BUF. Return the number of bytes placed into BUF if + successful, otherwise -1 and errno set. + See the POSIX:2008 specification + . */ +# if @REPLACE_READLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define readlink rpl_readlink +# endif +_GL_FUNCDECL_RPL (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize)); +# else +# if !@HAVE_READLINK@ +_GL_FUNCDECL_SYS (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize)); +# endif +_GL_CXXALIASWARN (readlink); +#elif defined GNULIB_POSIXCHECK +# undef readlink +# if HAVE_RAW_DECL_READLINK +_GL_WARN_ON_USE (readlink, "readlink is unportable - " + "use gnulib module readlink for portability"); +# endif +#endif + + +#if @GNULIB_READLINKAT@ +# if !@HAVE_READLINKAT@ +_GL_FUNCDECL_SYS (readlinkat, ssize_t, + (int fd, char const *file, char *buf, size_t len) + _GL_ARG_NONNULL ((2, 3))); +# endif +_GL_CXXALIAS_SYS (readlinkat, ssize_t, + (int fd, char const *file, char *buf, size_t len)); +_GL_CXXALIASWARN (readlinkat); +#elif defined GNULIB_POSIXCHECK +# undef readlinkat +# if HAVE_RAW_DECL_READLINKAT +_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - " + "use gnulib module readlinkat for portability"); +# endif +#endif + + +#if @GNULIB_RMDIR@ +/* Remove the directory DIR. */ +# if @REPLACE_RMDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define rmdir rpl_rmdir +# endif +_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (rmdir, int, (char const *name)); +# else +_GL_CXXALIAS_SYS (rmdir, int, (char const *name)); +# endif +_GL_CXXALIASWARN (rmdir); +#elif defined GNULIB_POSIXCHECK +# undef rmdir +# if HAVE_RAW_DECL_RMDIR +_GL_WARN_ON_USE (rmdir, "rmdir is unportable - " + "use gnulib module rmdir for portability"); +# endif +#endif + + +#if @GNULIB_SETHOSTNAME@ +/* Set the host name of the machine. + The host name may or may not be fully qualified. + + Put LEN bytes of NAME into the host name. + Return 0 if successful, otherwise, set errno and return -1. + + Platforms with no ability to set the hostname return -1 and set + errno = ENOSYS. */ +# if !@HAVE_SETHOSTNAME@ || !@HAVE_DECL_SETHOSTNAME@ +_GL_FUNCDECL_SYS (sethostname, int, (const char *name, size_t len) + _GL_ARG_NONNULL ((1))); +# endif +/* Need to cast, because on Solaris 11 2011-10, Mac OS X 10.5, IRIX 6.5 + and FreeBSD 6.4 the second parameter is int. On Solaris 11 + 2011-10, the first parameter is not const. */ +_GL_CXXALIAS_SYS_CAST (sethostname, int, (const char *name, size_t len)); +_GL_CXXALIASWARN (sethostname); +#elif defined GNULIB_POSIXCHECK +# undef sethostname +# if HAVE_RAW_DECL_SETHOSTNAME +_GL_WARN_ON_USE (sethostname, "sethostname is unportable - " + "use gnulib module sethostname for portability"); +# endif +#endif + + +#if @GNULIB_SLEEP@ +/* Pause the execution of the current thread for N seconds. + Returns the number of seconds left to sleep. + See the POSIX:2008 specification + . */ +# if @REPLACE_SLEEP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef sleep +# define sleep rpl_sleep +# endif +_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n)); +_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n)); +# else +# if !@HAVE_SLEEP@ +_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n)); +# endif +_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n)); +# endif +_GL_CXXALIASWARN (sleep); +#elif defined GNULIB_POSIXCHECK +# undef sleep +# if HAVE_RAW_DECL_SLEEP +_GL_WARN_ON_USE (sleep, "sleep is unportable - " + "use gnulib module sleep for portability"); +# endif +#endif + + +#if @GNULIB_SYMLINK@ +# if @REPLACE_SYMLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef symlink +# define symlink rpl_symlink +# endif +_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file)); +# else +# if !@HAVE_SYMLINK@ +_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file)); +# endif +_GL_CXXALIASWARN (symlink); +#elif defined GNULIB_POSIXCHECK +# undef symlink +# if HAVE_RAW_DECL_SYMLINK +_GL_WARN_ON_USE (symlink, "symlink is not portable - " + "use gnulib module symlink for portability"); +# endif +#endif + + +#if @GNULIB_SYMLINKAT@ +# if !@HAVE_SYMLINKAT@ +_GL_FUNCDECL_SYS (symlinkat, int, + (char const *contents, int fd, char const *file) + _GL_ARG_NONNULL ((1, 3))); +# endif +_GL_CXXALIAS_SYS (symlinkat, int, + (char const *contents, int fd, char const *file)); +_GL_CXXALIASWARN (symlinkat); +#elif defined GNULIB_POSIXCHECK +# undef symlinkat +# if HAVE_RAW_DECL_SYMLINKAT +_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - " + "use gnulib module symlinkat for portability"); +# endif +#endif + + +#if @GNULIB_TTYNAME_R@ +/* Store at most BUFLEN characters of the pathname of the terminal FD is + open on in BUF. Return 0 on success, otherwise an error number. */ +# if @REPLACE_TTYNAME_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ttyname_r +# define ttyname_r rpl_ttyname_r +# endif +_GL_FUNCDECL_RPL (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +# else +# if !@HAVE_DECL_TTYNAME_R@ +_GL_FUNCDECL_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +# endif +_GL_CXXALIASWARN (ttyname_r); +#elif defined GNULIB_POSIXCHECK +# undef ttyname_r +# if HAVE_RAW_DECL_TTYNAME_R +_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - " + "use gnulib module ttyname_r for portability"); +# endif +#endif + + +#if @GNULIB_UNLINK@ +# if @REPLACE_UNLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unlink +# define unlink rpl_unlink +# endif +_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (unlink, int, (char const *file)); +# else +_GL_CXXALIAS_SYS (unlink, int, (char const *file)); +# endif +_GL_CXXALIASWARN (unlink); +#elif defined GNULIB_POSIXCHECK +# undef unlink +# if HAVE_RAW_DECL_UNLINK +_GL_WARN_ON_USE (unlink, "unlink is not portable - " + "use gnulib module unlink for portability"); +# endif +#endif + + +#if @GNULIB_UNLINKAT@ +# if @REPLACE_UNLINKAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unlinkat +# define unlinkat rpl_unlinkat +# endif +_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag)); +# else +# if !@HAVE_UNLINKAT@ +_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag)); +# endif +_GL_CXXALIASWARN (unlinkat); +#elif defined GNULIB_POSIXCHECK +# undef unlinkat +# if HAVE_RAW_DECL_UNLINKAT +_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - " + "use gnulib module openat for portability"); +# endif +#endif + + +#if @GNULIB_USLEEP@ +/* Pause the execution of the current thread for N microseconds. + Returns 0 on completion, or -1 on range error. + See the POSIX:2001 specification + . */ +# if @REPLACE_USLEEP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef usleep +# define usleep rpl_usleep +# endif +_GL_FUNCDECL_RPL (usleep, int, (useconds_t n)); +_GL_CXXALIAS_RPL (usleep, int, (useconds_t n)); +# else +# if !@HAVE_USLEEP@ +_GL_FUNCDECL_SYS (usleep, int, (useconds_t n)); +# endif +_GL_CXXALIAS_SYS (usleep, int, (useconds_t n)); +# endif +_GL_CXXALIASWARN (usleep); +#elif defined GNULIB_POSIXCHECK +# undef usleep +# if HAVE_RAW_DECL_USLEEP +_GL_WARN_ON_USE (usleep, "usleep is unportable - " + "use gnulib module usleep for portability"); +# endif +#endif + + +#if @GNULIB_WRITE@ +/* Write up to COUNT bytes starting at BUF to file descriptor FD. + See the POSIX:2008 specification + . */ +# if @REPLACE_WRITE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef write +# define write rpl_write +# endif +_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); +# else +/* Need to cast, because on mingw, the third parameter is + unsigned int count + and the return type is 'int'. */ +_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count)); +# endif +_GL_CXXALIASWARN (write); +#endif + +_GL_INLINE_HEADER_END + +#endif /* _@GUARD_PREFIX@_UNISTD_H */ +#endif /* _@GUARD_PREFIX@_UNISTD_H */ diff --git a/grub-core/gnulib/unitypes.in.h b/grub-core/gnulib/unitypes.in.h new file mode 100644 index 000000000..06eef05ce --- /dev/null +++ b/grub-core/gnulib/unitypes.in.h @@ -0,0 +1,46 @@ +/* Elementary types and macros for the GNU UniString library. + Copyright (C) 2002, 2005-2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _UNITYPES_H +#define _UNITYPES_H + +/* Get uint8_t, uint16_t, uint32_t. */ +#include + +/* Type representing a Unicode character. */ +typedef uint32_t ucs4_t; + +/* Attribute of a function whose result depends only on the arguments + (not pointers!) and which has no side effects. */ +#ifndef _UC_ATTRIBUTE_CONST +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) +# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__)) +# else +# define _UC_ATTRIBUTE_CONST +# endif +#endif + +/* Attribute of a function whose result depends only on the arguments + (possibly pointers) and global memory, and which has no side effects. */ +#ifndef _UC_ATTRIBUTE_PURE +# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define _UC_ATTRIBUTE_PURE +# endif +#endif + +#endif /* _UNITYPES_H */ diff --git a/grub-core/gnulib/uniwidth.in.h b/grub-core/gnulib/uniwidth.in.h new file mode 100644 index 000000000..8931cc9b0 --- /dev/null +++ b/grub-core/gnulib/uniwidth.in.h @@ -0,0 +1,72 @@ +/* Display width functions. + Copyright (C) 2001-2002, 2005, 2007, 2009-2013 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _UNIWIDTH_H +#define _UNIWIDTH_H + +#include "unitypes.h" + +/* Get size_t. */ +#include + +/* Get locale_charset() declaration. */ +#include "localcharset.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Display width. */ + +/* These functions are locale dependent. The encoding argument identifies + the encoding (e.g. "ISO-8859-2" for Polish). */ + +/* Determine number of column positions required for UC. */ +extern int + uc_width (ucs4_t uc, const char *encoding) + _UC_ATTRIBUTE_PURE; + +/* Determine number of column positions required for first N units + (or fewer if S ends before this) in S. */ +extern int + u8_width (const uint8_t *s, size_t n, const char *encoding) + _UC_ATTRIBUTE_PURE; +extern int + u16_width (const uint16_t *s, size_t n, const char *encoding) + _UC_ATTRIBUTE_PURE; +extern int + u32_width (const uint32_t *s, size_t n, const char *encoding) + _UC_ATTRIBUTE_PURE; + +/* Determine number of column positions required for S. */ +extern int + u8_strwidth (const uint8_t *s, const char *encoding) + _UC_ATTRIBUTE_PURE; +extern int + u16_strwidth (const uint16_t *s, const char *encoding) + _UC_ATTRIBUTE_PURE; +extern int + u32_strwidth (const uint32_t *s, const char *encoding) + _UC_ATTRIBUTE_PURE; + + +#ifdef __cplusplus +} +#endif + +#endif /* _UNIWIDTH_H */ diff --git a/grub-core/gnulib/uniwidth/cjk.h b/grub-core/gnulib/uniwidth/cjk.h new file mode 100644 index 000000000..11b14dfec --- /dev/null +++ b/grub-core/gnulib/uniwidth/cjk.h @@ -0,0 +1,37 @@ +/* Test for CJK encoding. + Copyright (C) 2001-2002, 2005-2007, 2009-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2002. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "streq.h" + +static int +is_cjk_encoding (const char *encoding) +{ + if (0 + /* Legacy Japanese encodings */ + || STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0) + /* Legacy Chinese encodings */ + || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) + || STREQ_OPT (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0) + || STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0) + || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0) + /* Legacy Korean encodings */ + || STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) + || STREQ_OPT (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0) + || STREQ_OPT (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0)) + return 1; + return 0; +} diff --git a/grub-core/gnulib/uniwidth/width.c b/grub-core/gnulib/uniwidth/width.c new file mode 100644 index 000000000..173d0872c --- /dev/null +++ b/grub-core/gnulib/uniwidth/width.c @@ -0,0 +1,368 @@ +/* Determine display width of Unicode character. + Copyright (C) 2001-2002, 2006-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2002. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "uniwidth.h" + +#include "cjk.h" + +/* + * Non-spacing attribute table. + * Consists of: + * - Non-spacing characters; generated from PropList.txt or + * "grep '^[^;]*;[^;]*;[^;]*;[^;]*;NSM;' UnicodeData.txt" + * - Format control characters; generated from + * "grep '^[^;]*;[^;]*;Cf;' UnicodeData.txt" + * - Zero width characters; generated from + * "grep '^[^;]*;ZERO WIDTH ' UnicodeData.txt" + */ +static const unsigned char nonspacing_table_data[27*64] = { + /* 0x0000-0x01ff */ + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0000-0x003f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x0040-0x007f */ + 0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x00, 0x00, /* 0x0080-0x00bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x013f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0140-0x017f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x01bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01c0-0x01ff */ + /* 0x0200-0x03ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0200-0x023f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0240-0x027f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0280-0x02bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c0-0x02ff */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x0300-0x033f */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* 0x0340-0x037f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0380-0x03bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x03c0-0x03ff */ + /* 0x0400-0x05ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0400-0x043f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0440-0x047f */ + 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0480-0x04bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x04c0-0x04ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0500-0x053f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0540-0x057f */ + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xbf, /* 0x0580-0x05bf */ + 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05ff */ + /* 0x0600-0x07ff */ + 0x0f, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, /* 0x0600-0x063f */ + 0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, /* 0x0640-0x067f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0680-0x06bf */ + 0x00, 0x00, 0xc0, 0xbf, 0x9f, 0x3d, 0x00, 0x00, /* 0x06c0-0x06ff */ + 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x0700-0x073f */ + 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0740-0x077f */ + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, /* 0x0780-0x07bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x07c0-0x07ff */ + /* 0x0800-0x09ff */ + 0x00, 0x00, 0xc0, 0xfb, 0xef, 0x3e, 0x00, 0x00, /* 0x0800-0x083f */ + 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, /* 0x0840-0x087f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0880-0x08bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08c0-0x08ff */ + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, /* 0x0900-0x093f */ + 0xfe, 0x21, 0xfe, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0940-0x097f */ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0980-0x09bf */ + 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x09c0-0x09ff */ + /* 0x0a00-0x0bff */ + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a00-0x0a3f */ + 0x86, 0x39, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, /* 0x0a40-0x0a7f */ + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a80-0x0abf */ + 0xbe, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0ac0-0x0aff */ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, /* 0x0b00-0x0b3f */ + 0x1e, 0x20, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0b40-0x0b7f */ + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b80-0x0bbf */ + 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0bc0-0x0bff */ + /* 0x0c00-0x0dff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, /* 0x0c00-0x0c3f */ + 0xc1, 0x3d, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0c40-0x0c7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0c80-0x0cbf */ + 0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0cc0-0x0cff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d00-0x0d3f */ + 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0d40-0x0d7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d80-0x0dbf */ + 0x00, 0x04, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0dc0-0x0dff */ + /* 0x0e00-0x0fff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x07, /* 0x0e00-0x0e3f */ + 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e40-0x0e7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1b, /* 0x0e80-0x0ebf */ + 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0ec0-0x0eff */ + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x02, /* 0x0f00-0x0f3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, /* 0x0f40-0x0f7f */ + 0xdf, 0xe0, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1f, /* 0x0f80-0x0fbf */ + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0fc0-0x0fff */ + /* 0x1000-0x11ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x66, /* 0x1000-0x103f */ + 0x00, 0x00, 0x00, 0xc3, 0x01, 0x00, 0x1e, 0x00, /* 0x1040-0x107f */ + 0x64, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x1080-0x10bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c0-0x10ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1100-0x113f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1140-0x117f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1180-0x11bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11c0-0x11ff */ + /* 0x1200-0x13ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1200-0x123f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1240-0x127f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1280-0x12bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12c0-0x12ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1300-0x133f */ + 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 0x1340-0x137f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1380-0x13bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13c0-0x13ff */ + /* 0x1600-0x17ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1600-0x163f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1640-0x167f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1680-0x16bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16c0-0x16ff */ + 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, /* 0x1700-0x173f */ + 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1740-0x177f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f, /* 0x1780-0x17bf */ + 0x40, 0xfe, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x17c0-0x17ff */ + /* 0x1800-0x19ff */ + 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1800-0x183f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1840-0x187f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x1880-0x18bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18c0-0x18ff */ + 0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x04, 0x0e, /* 0x1900-0x193f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1940-0x197f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1980-0x19bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x19c0-0x19ff */ + /* 0x1a00-0x1bff */ + 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, /* 0x1a00-0x1a3f */ + 0x00, 0x00, 0x40, 0x7f, 0xe5, 0x1f, 0xf8, 0x9f, /* 0x1a40-0x1a7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1a80-0x1abf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ac0-0x1aff */ + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x17, /* 0x1b00-0x1b3f */ + 0x04, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x1b40-0x1b7f */ + 0x03, 0x00, 0x00, 0x00, 0x3c, 0x03, 0x00, 0x00, /* 0x1b80-0x1bbf */ + 0x00, 0x00, 0x00, 0x00, 0x40, 0xa3, 0x03, 0x00, /* 0x1bc0-0x1bff */ + /* 0x1c00-0x1dff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xcf, 0x00, /* 0x1c00-0x1c3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c40-0x1c7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c80-0x1cbf */ + 0x00, 0x00, 0xf7, 0xff, 0xfd, 0x21, 0x00, 0x00, /* 0x1cc0-0x1cff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d00-0x1d3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d40-0x1d7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d80-0x1dbf */ + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, /* 0x1dc0-0x1dff */ + /* 0x2000-0x21ff */ + 0x00, 0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, /* 0x2000-0x203f */ + 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, /* 0x2040-0x207f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2080-0x20bf */ + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, /* 0x20c0-0x20ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2100-0x213f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2140-0x217f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2180-0x21bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21c0-0x21ff */ + /* 0x2c00-0x2dff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c00-0x2c3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c40-0x2c7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c80-0x2cbf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, /* 0x2cc0-0x2cff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d00-0x2d3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x2d40-0x2d7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d80-0x2dbf */ + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x2dc0-0x2dff */ + /* 0x3000-0x31ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, /* 0x3000-0x303f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3040-0x307f */ + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, /* 0x3080-0x30bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30c0-0x30ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3100-0x313f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3140-0x317f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3180-0x31bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x31c0-0x31ff */ + /* 0xa600-0xa7ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa600-0xa63f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x30, /* 0xa640-0xa67f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa680-0xa6bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, /* 0xa6c0-0xa6ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa700-0xa73f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa740-0xa77f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa780-0xa7bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa7c0-0xa7ff */ + /* 0xa800-0xa9ff */ + 0x44, 0x08, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* 0xa800-0xa83f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa840-0xa87f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa880-0xa8bf */ + 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, /* 0xa8c0-0xa8ff */ + 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, /* 0xa900-0xa93f */ + 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa940-0xa97f */ + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x13, /* 0xa980-0xa9bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa9c0-0xa9ff */ + /* 0xaa00-0xabff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x66, 0x00, /* 0xaa00-0xaa3f */ + 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaa40-0xaa7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xc1, /* 0xaa80-0xaabf */ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaac0-0xaaff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab00-0xab3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab40-0xab7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab80-0xabbf */ + 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x00, /* 0xabc0-0xabff */ + /* 0xfa00-0xfbff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa00-0xfa3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa40-0xfa7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa80-0xfabf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfac0-0xfaff */ + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0xfb00-0xfb3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb40-0xfb7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb80-0xfbbf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfbc0-0xfbff */ + /* 0xfe00-0xffff */ + 0xff, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, /* 0xfe00-0xfe3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe40-0xfe7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe80-0xfebf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0xfec0-0xfeff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff00-0xff3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff40-0xff7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff80-0xffbf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, /* 0xffc0-0xffff */ + /* 0x10000-0x101ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10000-0x1003f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10040-0x1007f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10080-0x100bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x100c0-0x100ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10100-0x1013f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10140-0x1017f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10180-0x101bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, /* 0x101c0-0x101ff */ + /* 0x10a00-0x10bff */ + 0x6e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, /* 0x10a00-0x10a3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a40-0x10a7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a80-0x10abf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10ac0-0x10aff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b00-0x10b3f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b40-0x10b7f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b80-0x10bbf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10bc0-0x10bff */ + /* 0x11000-0x111ff */ + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0x11000-0x1103f */ + 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11040-0x1107f */ + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x26, /* 0x11080-0x110bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x110c0-0x110ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11100-0x1113f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11140-0x1117f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11180-0x111bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x111c0-0x111ff */ + /* 0x1d000-0x1d1ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d000-0x1d03f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d040-0x1d07f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d080-0x1d0bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d0c0-0x1d0ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d100-0x1d13f */ + 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xf8, 0xff, /* 0x1d140-0x1d17f */ + 0xe7, 0x0f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x1d180-0x1d1bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d1c0-0x1d1ff */ + /* 0x1d200-0x1d3ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d200-0x1d23f */ + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d240-0x1d27f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d280-0x1d2bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d2c0-0x1d2ff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d300-0x1d33f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d340-0x1d37f */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d380-0x1d3bf */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0x1d3c0-0x1d3ff */ +}; +static const signed char nonspacing_table_ind[240] = { + 0, 1, 2, 3, 4, 5, 6, 7, /* 0x0000-0x0fff */ + 8, 9, -1, 10, 11, 12, 13, -1, /* 0x1000-0x1fff */ + 14, -1, -1, -1, -1, -1, 15, -1, /* 0x2000-0x2fff */ + 16, -1, -1, -1, -1, -1, -1, -1, /* 0x3000-0x3fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x4000-0x4fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x5000-0x5fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x6000-0x6fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x7000-0x7fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x8000-0x8fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x9000-0x9fff */ + -1, -1, -1, 17, 18, 19, -1, -1, /* 0xa000-0xafff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb000-0xbfff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc000-0xcfff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd000-0xdfff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe000-0xefff */ + -1, -1, -1, -1, -1, 20, -1, 21, /* 0xf000-0xffff */ + 22, -1, -1, -1, -1, 23, -1, -1, /* 0x10000-0x10fff */ + 24, -1, -1, -1, -1, -1, -1, -1, /* 0x11000-0x11fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x12000-0x12fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x13000-0x13fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x14000-0x14fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x15000-0x15fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x16000-0x16fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x17000-0x17fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x18000-0x18fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x19000-0x19fff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1a000-0x1afff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1b000-0x1bfff */ + -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1c000-0x1cfff */ + 25, 26, -1, -1, -1, -1, -1, -1 /* 0x1d000-0x1dfff */ +}; + +/* Determine number of column positions required for UC. */ +int +uc_width (ucs4_t uc, const char *encoding) +{ + /* Test for non-spacing or control character. */ + if ((uc >> 9) < 240) + { + int ind = nonspacing_table_ind[uc >> 9]; + if (ind >= 0) + if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1) + { + if (uc > 0 && uc < 0xa0) + return -1; + else + return 0; + } + } + else if ((uc >> 9) == (0xe0000 >> 9)) + { + if (uc >= 0xe0100) + { + if (uc <= 0xe01ef) + return 0; + } + else + { + if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001) + return 0; + } + } + /* Test for double-width character. + * Generated from "grep '^[^;]\{4,5\};[WF]' EastAsianWidth.txt" + * and "grep '^[^;]\{4,5\};[^WF]' EastAsianWidth.txt" + */ + if (uc >= 0x1100 + && ((uc < 0x1160) /* Hangul Jamo */ + || (uc >= 0x2329 && uc < 0x232b) /* Angle Brackets */ + || (uc >= 0x2e80 && uc < 0xa4d0 /* CJK ... Yi */ + && !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00)) + || (uc >= 0xac00 && uc < 0xd7a4) /* Hangul Syllables */ + || (uc >= 0xf900 && uc < 0xfb00) /* CJK Compatibility Ideographs */ + || (uc >= 0xfe10 && uc < 0xfe20) /* Presentation Forms for Vertical */ + || (uc >= 0xfe30 && uc < 0xfe70) /* CJK Compatibility Forms */ + || (uc >= 0xff00 && uc < 0xff61) /* Fullwidth Forms */ + || (uc >= 0xffe0 && uc < 0xffe7) /* Fullwidth Signs */ + || (uc >= 0x20000 && uc <= 0x2ffff) /* Supplementary Ideographic Plane */ + || (uc >= 0x30000 && uc <= 0x3ffff) /* Tertiary Ideographic Plane */ + ) ) + return 2; + /* In ancient CJK encodings, Cyrillic and most other characters are + double-width as well. */ + if (uc >= 0x00A1 && uc < 0xFF61 && uc != 0x20A9 + && is_cjk_encoding (encoding)) + return 2; + return 1; +} diff --git a/grub-core/gnulib/vasnprintf.c b/grub-core/gnulib/vasnprintf.c new file mode 100644 index 000000000..8fdab32ea --- /dev/null +++ b/grub-core/gnulib/vasnprintf.c @@ -0,0 +1,5606 @@ +/* vsprintf with automatic memory allocation. + Copyright (C) 1999, 2002-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +/* This file can be parametrized with the following macros: + VASNPRINTF The name of the function being defined. + FCHAR_T The element type of the format string. + DCHAR_T The element type of the destination (result) string. + FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters + in the format string are ASCII. MUST be set if + FCHAR_T and DCHAR_T are not the same type. + DIRECTIVE Structure denoting a format directive. + Depends on FCHAR_T. + DIRECTIVES Structure denoting the set of format directives of a + format string. Depends on FCHAR_T. + PRINTF_PARSE Function that parses a format string. + Depends on FCHAR_T. + DCHAR_CPY memcpy like function for DCHAR_T[] arrays. + DCHAR_SET memset like function for DCHAR_T[] arrays. + DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays. + SNPRINTF The system's snprintf (or similar) function. + This may be either snprintf or swprintf. + TCHAR_T The element type of the argument and result string + of the said SNPRINTF function. This may be either + char or wchar_t. The code exploits that + sizeof (TCHAR_T) | sizeof (DCHAR_T) and + alignof (TCHAR_T) <= alignof (DCHAR_T). + DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type. + DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[]. + DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t. + DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t. + DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */ + +/* Tell glibc's to provide a prototype for snprintf(). + This must come before because may include + , and once has been included, it's too late. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#ifndef VASNPRINTF +# include +#endif +#ifndef IN_LIBINTL +# include +#endif + +/* Specification. */ +#ifndef VASNPRINTF +# if WIDE_CHAR_VERSION +# include "vasnwprintf.h" +# else +# include "vasnprintf.h" +# endif +#endif + +#include /* localeconv() */ +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#if HAVE_NL_LANGINFO +# include +#endif +#ifndef VASNPRINTF +# if WIDE_CHAR_VERSION +# include "wprintf-parse.h" +# else +# include "printf-parse.h" +# endif +#endif + +/* Checked size_t computations. */ +#include "xsize.h" + +#include "verify.h" + +#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL +# include +# include "float+.h" +#endif + +#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL +# include +# include "isnand-nolibm.h" +#endif + +#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL +# include +# include "isnanl-nolibm.h" +# include "fpucw.h" +#endif + +#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL +# include +# include "isnand-nolibm.h" +# include "printf-frexp.h" +#endif + +#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL +# include +# include "isnanl-nolibm.h" +# include "printf-frexpl.h" +# include "fpucw.h" +#endif + +/* Default parameters. */ +#ifndef VASNPRINTF +# if WIDE_CHAR_VERSION +# define VASNPRINTF vasnwprintf +# define FCHAR_T wchar_t +# define DCHAR_T wchar_t +# define TCHAR_T wchar_t +# define DCHAR_IS_TCHAR 1 +# define DIRECTIVE wchar_t_directive +# define DIRECTIVES wchar_t_directives +# define PRINTF_PARSE wprintf_parse +# define DCHAR_CPY wmemcpy +# define DCHAR_SET wmemset +# else +# define VASNPRINTF vasnprintf +# define FCHAR_T char +# define DCHAR_T char +# define TCHAR_T char +# define DCHAR_IS_TCHAR 1 +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +# define PRINTF_PARSE printf_parse +# define DCHAR_CPY memcpy +# define DCHAR_SET memset +# endif +#endif +#if WIDE_CHAR_VERSION + /* TCHAR_T is wchar_t. */ +# define USE_SNPRINTF 1 +# if HAVE_DECL__SNWPRINTF + /* On Windows, the function swprintf() has a different signature than + on Unix; we use the function _snwprintf() or - on mingw - snwprintf() + instead. The mingw function snwprintf() has fewer bugs than the + MSVCRT function _snwprintf(), so prefer that. */ +# if defined __MINGW32__ +# define SNPRINTF snwprintf +# else +# define SNPRINTF _snwprintf +# endif +# else + /* Unix. */ +# define SNPRINTF swprintf +# endif +#else + /* TCHAR_T is char. */ + /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'. + But don't use it on BeOS, since BeOS snprintf produces no output if the + size argument is >= 0x3000000. + Also don't use it on Linux libc5, since there snprintf with size = 1 + writes any output without bounds, like sprintf. */ +# if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__ && !(__GNU_LIBRARY__ == 1) +# define USE_SNPRINTF 1 +# else +# define USE_SNPRINTF 0 +# endif +# if HAVE_DECL__SNPRINTF + /* Windows. The mingw function snprintf() has fewer bugs than the MSVCRT + function _snprintf(), so prefer that. */ +# if defined __MINGW32__ +# define SNPRINTF snprintf + /* Here we need to call the native snprintf, not rpl_snprintf. */ +# undef snprintf +# else +# define SNPRINTF _snprintf +# endif +# else + /* Unix. */ +# define SNPRINTF snprintf + /* Here we need to call the native snprintf, not rpl_snprintf. */ +# undef snprintf +# endif +#endif +/* Here we need to call the native sprintf, not rpl_sprintf. */ +#undef sprintf + +/* GCC >= 4.0 with -Wall emits unjustified "... may be used uninitialized" + warnings in this file. Use -Dlint to suppress them. */ +#ifdef lint +# define IF_LINT(Code) Code +#else +# define IF_LINT(Code) /* empty */ +#endif + +/* Avoid some warnings from "gcc -Wshadow". + This file doesn't use the exp() and remainder() functions. */ +#undef exp +#define exp expo +#undef remainder +#define remainder rem + +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION +# if (HAVE_STRNLEN && !defined _AIX) +# define local_strnlen strnlen +# else +# ifndef local_strnlen_defined +# define local_strnlen_defined 1 +static size_t +local_strnlen (const char *string, size_t maxlen) +{ + const char *end = memchr (string, '\0', maxlen); + return end ? (size_t) (end - string) : maxlen; +} +# endif +# endif +#endif + +#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T +# if HAVE_WCSLEN +# define local_wcslen wcslen +# else + /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid + a dependency towards this library, here is a local substitute. + Define this substitute only once, even if this file is included + twice in the same compilation unit. */ +# ifndef local_wcslen_defined +# define local_wcslen_defined 1 +static size_t +local_wcslen (const wchar_t *s) +{ + const wchar_t *ptr; + + for (ptr = s; *ptr != (wchar_t) 0; ptr++) + ; + return ptr - s; +} +# endif +# endif +#endif + +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION +# if HAVE_WCSNLEN +# define local_wcsnlen wcsnlen +# else +# ifndef local_wcsnlen_defined +# define local_wcsnlen_defined 1 +static size_t +local_wcsnlen (const wchar_t *s, size_t maxlen) +{ + const wchar_t *ptr; + + for (ptr = s; maxlen > 0 && *ptr != (wchar_t) 0; ptr++, maxlen--) + ; + return ptr - s; +} +# endif +# endif +#endif + +#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL +/* Determine the decimal-point character according to the current locale. */ +# ifndef decimal_point_char_defined +# define decimal_point_char_defined 1 +static char +decimal_point_char (void) +{ + const char *point; + /* Determine it in a multithread-safe way. We know nl_langinfo is + multithread-safe on glibc systems and Mac OS X systems, but is not required + to be multithread-safe by POSIX. sprintf(), however, is multithread-safe. + localeconv() is rarely multithread-safe. */ +# if HAVE_NL_LANGINFO && (__GLIBC__ || defined __UCLIBC__ || (defined __APPLE__ && defined __MACH__)) + point = nl_langinfo (RADIXCHAR); +# elif 1 + char pointbuf[5]; + sprintf (pointbuf, "%#.0f", 1.0); + point = &pointbuf[1]; +# else + point = localeconv () -> decimal_point; +# endif + /* The decimal point is always a single byte: either '.' or ','. */ + return (point[0] != '\0' ? point[0] : '.'); +} +# endif +#endif + +#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL + +/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */ +static int +is_infinite_or_zero (double x) +{ + return isnand (x) || x + x == x; +} + +#endif + +#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL + +/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */ +static int +is_infinite_or_zerol (long double x) +{ + return isnanl (x) || x + x == x; +} + +#endif + +#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL + +/* Converting 'long double' to decimal without rare rounding bugs requires + real bignums. We use the naming conventions of GNU gmp, but vastly simpler + (and slower) algorithms. */ + +typedef unsigned int mp_limb_t; +# define GMP_LIMB_BITS 32 +verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS); + +typedef unsigned long long mp_twolimb_t; +# define GMP_TWOLIMB_BITS 64 +verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS); + +/* Representation of a bignum >= 0. */ +typedef struct +{ + size_t nlimbs; + mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */ +} mpn_t; + +/* Compute the product of two bignums >= 0. + Return the allocated memory in case of success, NULL in case of memory + allocation failure. */ +static void * +multiply (mpn_t src1, mpn_t src2, mpn_t *dest) +{ + const mp_limb_t *p1; + const mp_limb_t *p2; + size_t len1; + size_t len2; + + if (src1.nlimbs <= src2.nlimbs) + { + len1 = src1.nlimbs; + p1 = src1.limbs; + len2 = src2.nlimbs; + p2 = src2.limbs; + } + else + { + len1 = src2.nlimbs; + p1 = src2.limbs; + len2 = src1.nlimbs; + p2 = src1.limbs; + } + /* Now 0 <= len1 <= len2. */ + if (len1 == 0) + { + /* src1 or src2 is zero. */ + dest->nlimbs = 0; + dest->limbs = (mp_limb_t *) malloc (1); + } + else + { + /* Here 1 <= len1 <= len2. */ + size_t dlen; + mp_limb_t *dp; + size_t k, i, j; + + dlen = len1 + len2; + dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); + if (dp == NULL) + return NULL; + for (k = len2; k > 0; ) + dp[--k] = 0; + for (i = 0; i < len1; i++) + { + mp_limb_t digit1 = p1[i]; + mp_twolimb_t carry = 0; + for (j = 0; j < len2; j++) + { + mp_limb_t digit2 = p2[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + carry += dp[i + j]; + dp[i + j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + dp[i + len2] = (mp_limb_t) carry; + } + /* Normalise. */ + while (dlen > 0 && dp[dlen - 1] == 0) + dlen--; + dest->nlimbs = dlen; + dest->limbs = dp; + } + return dest->limbs; +} + +/* Compute the quotient of a bignum a >= 0 and a bignum b > 0. + a is written as a = q * b + r with 0 <= r < b. q is the quotient, r + the remainder. + Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd, + q is incremented. + Return the allocated memory in case of success, NULL in case of memory + allocation failure. */ +static void * +divide (mpn_t a, mpn_t b, mpn_t *q) +{ + /* Algorithm: + First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]] + with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS). + If m=n=1, perform a single-precision division: + r:=0, j:=m, + while j>0 do + {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j = + = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r=n>1, perform a multiple-precision division: + We have a/b < beta^(m-n+1). + s:=intDsize-1-(highest bit in b[n-1]), 0<=s=beta/2. + For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).} + Compute q* : + q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]). + In case of overflow (q* >= beta) set q* := beta-1. + Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2] + and c3 := b[n-2] * q*. + {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow + occurred. Furthermore 0 <= c3 < beta^2. + If there was overflow and + r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2, + the next test can be skipped.} + While c3 > c2, {Here 0 <= c2 < c3 < beta^2} + Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2]. + If q* > 0: + Put r := r - b * q* * beta^j. In detail: + [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]]. + hence: u:=0, for i:=0 to n-1 do + u := u + q* * b[i], + r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry), + u:=u div beta (+ 1, if carry in subtraction) + r[n+j]:=r[n+j]-u. + {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1 + < q* + 1 <= beta, + the carry u does not overflow.} + If a negative carry occurs, put q* := q* - 1 + and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]]. + Set q[j] := q*. + Normalise [q[m-n],..,q[0]]; this yields the quotient q. + Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the + rest r. + The room for q[j] can be allocated at the memory location of r[n+j]. + Finally, round-to-even: + Shift r left by 1 bit. + If r > b or if r = b and q[0] is odd, q := q+1. + */ + const mp_limb_t *a_ptr = a.limbs; + size_t a_len = a.nlimbs; + const mp_limb_t *b_ptr = b.limbs; + size_t b_len = b.nlimbs; + mp_limb_t *roomptr; + mp_limb_t *tmp_roomptr = NULL; + mp_limb_t *q_ptr; + size_t q_len; + mp_limb_t *r_ptr; + size_t r_len; + + /* Allocate room for a_len+2 digits. + (Need a_len+1 digits for the real division and 1 more digit for the + final rounding of q.) */ + roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t)); + if (roomptr == NULL) + return NULL; + + /* Normalise a. */ + while (a_len > 0 && a_ptr[a_len - 1] == 0) + a_len--; + + /* Normalise b. */ + for (;;) + { + if (b_len == 0) + /* Division by zero. */ + abort (); + if (b_ptr[b_len - 1] == 0) + b_len--; + else + break; + } + + /* Here m = a_len >= 0 and n = b_len > 0. */ + + if (a_len < b_len) + { + /* m beta^(m-2) <= a/b < beta^m */ + r_ptr = roomptr; + q_ptr = roomptr + 1; + { + mp_limb_t den = b_ptr[0]; + mp_limb_t remainder = 0; + const mp_limb_t *sourceptr = a_ptr + a_len; + mp_limb_t *destptr = q_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; + *--destptr = num / den; + remainder = num % den; + } + /* Normalise and store r. */ + if (remainder > 0) + { + r_ptr[0] = remainder; + r_len = 1; + } + else + r_len = 0; + /* Normalise q. */ + q_len = a_len; + if (q_ptr[q_len - 1] == 0) + q_len--; + } + } + else + { + /* n>1: multiple precision division. + beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> + beta^(m-n-1) <= a/b < beta^(m-n+1). */ + /* Determine s. */ + size_t s; + { + mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ + /* Determine s = GMP_LIMB_BITS - integer_length (msd). + Code copied from gnulib's integer_length.c. */ +# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + s = __builtin_clz (msd); +# else +# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT + if (GMP_LIMB_BITS <= DBL_MANT_BIT) + { + /* Use 'double' operations. + Assumes an IEEE 754 'double' implementation. */ +# define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7) +# define DBL_EXP_BIAS (DBL_EXP_MASK / 2 - 1) +# define NWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + union { double value; unsigned int word[NWORDS]; } m; + + /* Use a single integer to floating-point conversion. */ + m.value = msd; + + s = GMP_LIMB_BITS + - (((m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & DBL_EXP_MASK) + - DBL_EXP_BIAS); + } + else +# undef NWORDS +# endif + { + s = 31; + if (msd >= 0x10000) + { + msd = msd >> 16; + s -= 16; + } + if (msd >= 0x100) + { + msd = msd >> 8; + s -= 8; + } + if (msd >= 0x10) + { + msd = msd >> 4; + s -= 4; + } + if (msd >= 0x4) + { + msd = msd >> 2; + s -= 2; + } + if (msd >= 0x2) + { + msd = msd >> 1; + s -= 1; + } + } +# endif + } + /* 0 <= s < GMP_LIMB_BITS. + Copy b, shifting it left by s bits. */ + if (s > 0) + { + tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); + if (tmp_roomptr == NULL) + { + free (roomptr); + return NULL; + } + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = tmp_roomptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + /* accu must be zero, since that was how s was determined. */ + if (accu != 0) + abort (); + } + b_ptr = tmp_roomptr; + } + /* Copy a, shifting it left by s bits, yields r. + Memory layout: + At the beginning: r = roomptr[0..a_len], + at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ + r_ptr = roomptr; + if (s == 0) + { + memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); + r_ptr[a_len] = 0; + } + else + { + const mp_limb_t *sourceptr = a_ptr; + mp_limb_t *destptr = r_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = a_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + *destptr++ = (mp_limb_t) accu; + } + q_ptr = roomptr + b_len; + q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ + { + size_t j = a_len - b_len; /* m-n */ + mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ + mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ + mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ + ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; + /* Division loop, traversed m-n+1 times. + j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ + for (;;) + { + mp_limb_t q_star; + mp_limb_t c1; + if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ + { + /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ + mp_twolimb_t num = + ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) + | r_ptr[j + b_len - 1]; + q_star = num / b_msd; + c1 = num % b_msd; + } + else + { + /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ + q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ + /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta + <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta + <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) + {<= beta !}. + If yes, jump directly to the subtraction loop. + (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta + <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ + if (r_ptr[j + b_len] > b_msd + || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) + /* r[j+n] >= b[n-1]+1 or + r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a + carry. */ + goto subtract; + } + /* q_star = q*, + c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by + b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 + this can happen only twice. */ + if (c3 > c2) + { + q_star = q_star - 1; /* q* := q* - 1 */ + if (c3 - c2 > b_msdd) + q_star = q_star - 1; /* q* := q* - 1 */ + } + } + if (q_star > 0) + subtract: + { + /* Subtract r := r - b * q* * beta^j. */ + mp_limb_t cr; + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_twolimb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + /* Here 0 <= carry <= q*. */ + carry = + carry + + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ + + (mp_limb_t) ~(*destptr); + /* Here 0 <= carry <= beta*q* + beta-1. */ + *destptr++ = ~(mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; /* <= q* */ + } + cr = (mp_limb_t) carry; + } + /* Subtract cr from r_ptr[j + b_len], then forget about + r_ptr[j + b_len]. */ + if (cr > r_ptr[j + b_len]) + { + /* Subtraction gave a carry. */ + q_star = q_star - 1; /* q* := q* - 1 */ + /* Add b back. */ + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_limb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + mp_limb_t source1 = *sourceptr++; + mp_limb_t source2 = *destptr; + *destptr++ = source1 + source2 + carry; + carry = + (carry + ? source1 >= (mp_limb_t) ~source2 + : source1 > (mp_limb_t) ~source2); + } + } + /* Forget about the carry and about r[j+n]. */ + } + } + /* q* is determined. Store it as q[j]. */ + q_ptr[j] = q_star; + if (j == 0) + break; + j--; + } + } + r_len = b_len; + /* Normalise q. */ + if (q_ptr[q_len - 1] == 0) + q_len--; +# if 0 /* Not needed here, since we need r only to compare it with b/2, and + b is shifted left by s bits. */ + /* Shift r right by s bits. */ + if (s > 0) + { + mp_limb_t ptr = r_ptr + r_len; + mp_twolimb_t accu = 0; + size_t count; + for (count = r_len; count > 0; count--) + { + accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; + accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); + *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); + } + } +# endif + /* Normalise r. */ + while (r_len > 0 && r_ptr[r_len - 1] == 0) + r_len--; + } + /* Compare r << 1 with b. */ + if (r_len > b_len) + goto increment_q; + { + size_t i; + for (i = b_len;;) + { + mp_limb_t r_i = + (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) + | (i < r_len ? r_ptr[i] << 1 : 0); + mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); + if (r_i > b_i) + goto increment_q; + if (r_i < b_i) + goto keep_q; + if (i == 0) + break; + i--; + } + } + if (q_len > 0 && ((q_ptr[0] & 1) != 0)) + /* q is odd. */ + increment_q: + { + size_t i; + for (i = 0; i < q_len; i++) + if (++(q_ptr[i]) != 0) + goto keep_q; + q_ptr[q_len++] = 1; + } + keep_q: + if (tmp_roomptr != NULL) + free (tmp_roomptr); + q->limbs = q_ptr; + q->nlimbs = q_len; + return roomptr; +} + +/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal + representation. + Destroys the contents of a. + Return the allocated memory - containing the decimal digits in low-to-high + order, terminated with a NUL character - in case of success, NULL in case + of memory allocation failure. */ +static char * +convert_to_decimal (mpn_t a, size_t extra_zeroes) +{ + mp_limb_t *a_ptr = a.limbs; + size_t a_len = a.nlimbs; + /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ + size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); + char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); + if (c_ptr != NULL) + { + char *d_ptr = c_ptr; + for (; extra_zeroes > 0; extra_zeroes--) + *d_ptr++ = '0'; + while (a_len > 0) + { + /* Divide a by 10^9, in-place. */ + mp_limb_t remainder = 0; + mp_limb_t *ptr = a_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; + *ptr = num / 1000000000; + remainder = num % 1000000000; + } + /* Store the remainder as 9 decimal digits. */ + for (count = 9; count > 0; count--) + { + *d_ptr++ = '0' + (remainder % 10); + remainder = remainder / 10; + } + /* Normalize a. */ + if (a_ptr[a_len - 1] == 0) + a_len--; + } + /* Remove leading zeroes. */ + while (d_ptr > c_ptr && d_ptr[-1] == '0') + d_ptr--; + /* But keep at least one zero. */ + if (d_ptr == c_ptr) + *d_ptr++ = '0'; + /* Terminate the string. */ + *d_ptr = '\0'; + } + return c_ptr; +} + +# if NEED_PRINTF_LONG_DOUBLE + +/* Assuming x is finite and >= 0: + write x as x = 2^e * m, where m is a bignum. + Return the allocated memory in case of success, NULL in case of memory + allocation failure. */ +static void * +decode_long_double (long double x, int *ep, mpn_t *mp) +{ + mpn_t m; + int exp; + long double y; + size_t i; + + /* Allocate memory for result. */ + m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS; + m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t)); + if (m.limbs == NULL) + return NULL; + /* Split into exponential part and mantissa. */ + y = frexpl (x, &exp); + if (!(y >= 0.0L && y < 1.0L)) + abort (); + /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the + latter is an integer. */ + /* Convert the mantissa (y * 2^LDBL_MANT_BIT) to a sequence of limbs. + I'm not sure whether it's safe to cast a 'long double' value between + 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only + 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int', + doesn't matter). */ +# if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0 +# if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2 + { + mp_limb_t hi, lo; + y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2)); + hi = (int) y; + y -= hi; + if (!(y >= 0.0L && y < 1.0L)) + abort (); + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + lo = (int) y; + y -= lo; + if (!(y >= 0.0L && y < 1.0L)) + abort (); + m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; + } +# else + { + mp_limb_t d; + y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS); + d = (int) y; + y -= d; + if (!(y >= 0.0L && y < 1.0L)) + abort (); + m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; + } +# endif +# endif + for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; ) + { + mp_limb_t hi, lo; + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + hi = (int) y; + y -= hi; + if (!(y >= 0.0L && y < 1.0L)) + abort (); + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + lo = (int) y; + y -= lo; + if (!(y >= 0.0L && y < 1.0L)) + abort (); + m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; + } +# if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess + precision. */ + if (!(y == 0.0L)) + abort (); +# endif + /* Normalise. */ + while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0) + m.nlimbs--; + *mp = m; + *ep = exp - LDBL_MANT_BIT; + return m.limbs; +} + +# endif + +# if NEED_PRINTF_DOUBLE + +/* Assuming x is finite and >= 0: + write x as x = 2^e * m, where m is a bignum. + Return the allocated memory in case of success, NULL in case of memory + allocation failure. */ +static void * +decode_double (double x, int *ep, mpn_t *mp) +{ + mpn_t m; + int exp; + double y; + size_t i; + + /* Allocate memory for result. */ + m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS; + m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t)); + if (m.limbs == NULL) + return NULL; + /* Split into exponential part and mantissa. */ + y = frexp (x, &exp); + if (!(y >= 0.0 && y < 1.0)) + abort (); + /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * 2^DBL_MANT_BIT), and the + latter is an integer. */ + /* Convert the mantissa (y * 2^DBL_MANT_BIT) to a sequence of limbs. + I'm not sure whether it's safe to cast a 'double' value between + 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only + 'double' values between 0 and 2^16 (to 'unsigned int' or 'int', + doesn't matter). */ +# if (DBL_MANT_BIT % GMP_LIMB_BITS) != 0 +# if (DBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2 + { + mp_limb_t hi, lo; + y *= (mp_limb_t) 1 << (DBL_MANT_BIT % (GMP_LIMB_BITS / 2)); + hi = (int) y; + y -= hi; + if (!(y >= 0.0 && y < 1.0)) + abort (); + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + lo = (int) y; + y -= lo; + if (!(y >= 0.0 && y < 1.0)) + abort (); + m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; + } +# else + { + mp_limb_t d; + y *= (mp_limb_t) 1 << (DBL_MANT_BIT % GMP_LIMB_BITS); + d = (int) y; + y -= d; + if (!(y >= 0.0 && y < 1.0)) + abort (); + m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; + } +# endif +# endif + for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; ) + { + mp_limb_t hi, lo; + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + hi = (int) y; + y -= hi; + if (!(y >= 0.0 && y < 1.0)) + abort (); + y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); + lo = (int) y; + y -= lo; + if (!(y >= 0.0 && y < 1.0)) + abort (); + m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; + } + if (!(y == 0.0)) + abort (); + /* Normalise. */ + while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0) + m.nlimbs--; + *mp = m; + *ep = exp - DBL_MANT_BIT; + return m.limbs; +} + +# endif + +/* Assuming x = 2^e * m is finite and >= 0, and n is an integer: + Returns the decimal representation of round (x * 10^n). + Return the allocated memory - containing the decimal digits in low-to-high + order, terminated with a NUL character - in case of success, NULL in case + of memory allocation failure. */ +static char * +scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) +{ + int s; + size_t extra_zeroes; + unsigned int abs_n; + unsigned int abs_s; + mp_limb_t *pow5_ptr; + size_t pow5_len; + unsigned int s_limbs; + unsigned int s_bits; + mpn_t pow5; + mpn_t z; + void *z_memory; + char *digits; + + if (memory == NULL) + return NULL; + /* x = 2^e * m, hence + y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m) + = round (2^s * 5^n * m). */ + s = e + n; + extra_zeroes = 0; + /* Factor out a common power of 10 if possible. */ + if (s > 0 && n > 0) + { + extra_zeroes = (s < n ? s : n); + s -= extra_zeroes; + n -= extra_zeroes; + } + /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes. + Before converting to decimal, we need to compute + z = round (2^s * 5^n * m). */ + /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same + sign. 2.322 is slightly larger than log(5)/log(2). */ + abs_n = (n >= 0 ? n : -n); + abs_s = (s >= 0 ? s : -s); + pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 + + abs_s / GMP_LIMB_BITS + 1) + * sizeof (mp_limb_t)); + if (pow5_ptr == NULL) + { + free (memory); + return NULL; + } + /* Initialize with 1. */ + pow5_ptr[0] = 1; + pow5_len = 1; + /* Multiply with 5^|n|. */ + if (abs_n > 0) + { + static mp_limb_t const small_pow5[13 + 1] = + { + 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, + 48828125, 244140625, 1220703125 + }; + unsigned int n13; + for (n13 = 0; n13 <= abs_n; n13 += 13) + { + mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; + size_t j; + mp_twolimb_t carry = 0; + for (j = 0; j < pow5_len; j++) + { + mp_limb_t digit2 = pow5_ptr[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + pow5_ptr[j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + if (carry > 0) + pow5_ptr[pow5_len++] = (mp_limb_t) carry; + } + } + s_limbs = abs_s / GMP_LIMB_BITS; + s_bits = abs_s % GMP_LIMB_BITS; + if (n >= 0 ? s >= 0 : s <= 0) + { + /* Multiply with 2^|s|. */ + if (s_bits > 0) + { + mp_limb_t *ptr = pow5_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = pow5_len; count > 0; count--) + { + accu += (mp_twolimb_t) *ptr << s_bits; + *ptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + { + *ptr = (mp_limb_t) accu; + pow5_len++; + } + } + if (s_limbs > 0) + { + size_t count; + for (count = pow5_len; count > 0;) + { + count--; + pow5_ptr[s_limbs + count] = pow5_ptr[count]; + } + for (count = s_limbs; count > 0;) + { + count--; + pow5_ptr[count] = 0; + } + pow5_len += s_limbs; + } + pow5.limbs = pow5_ptr; + pow5.nlimbs = pow5_len; + if (n >= 0) + { + /* Multiply m with pow5. No division needed. */ + z_memory = multiply (m, pow5, &z); + } + else + { + /* Divide m by pow5 and round. */ + z_memory = divide (m, pow5, &z); + } + } + else + { + pow5.limbs = pow5_ptr; + pow5.nlimbs = pow5_len; + if (n >= 0) + { + /* n >= 0, s < 0. + Multiply m with pow5, then divide by 2^|s|. */ + mpn_t numerator; + mpn_t denominator; + void *tmp_memory; + tmp_memory = multiply (m, pow5, &numerator); + if (tmp_memory == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + /* Construct 2^|s|. */ + { + mp_limb_t *ptr = pow5_ptr + pow5_len; + size_t i; + for (i = 0; i < s_limbs; i++) + ptr[i] = 0; + ptr[s_limbs] = (mp_limb_t) 1 << s_bits; + denominator.limbs = ptr; + denominator.nlimbs = s_limbs + 1; + } + z_memory = divide (numerator, denominator, &z); + free (tmp_memory); + } + else + { + /* n < 0, s > 0. + Multiply m with 2^s, then divide by pow5. */ + mpn_t numerator; + mp_limb_t *num_ptr; + num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) + * sizeof (mp_limb_t)); + if (num_ptr == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + { + mp_limb_t *destptr = num_ptr; + { + size_t i; + for (i = 0; i < s_limbs; i++) + *destptr++ = 0; + } + if (s_bits > 0) + { + const mp_limb_t *sourceptr = m.limbs; + mp_twolimb_t accu = 0; + size_t count; + for (count = m.nlimbs; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s_bits; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + *destptr++ = (mp_limb_t) accu; + } + else + { + const mp_limb_t *sourceptr = m.limbs; + size_t count; + for (count = m.nlimbs; count > 0; count--) + *destptr++ = *sourceptr++; + } + numerator.limbs = num_ptr; + numerator.nlimbs = destptr - num_ptr; + } + z_memory = divide (numerator, pow5, &z); + free (num_ptr); + } + } + free (pow5_ptr); + free (memory); + + /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */ + + if (z_memory == NULL) + return NULL; + digits = convert_to_decimal (z, extra_zeroes); + free (z_memory); + return digits; +} + +# if NEED_PRINTF_LONG_DOUBLE + +/* Assuming x is finite and >= 0, and n is an integer: + Returns the decimal representation of round (x * 10^n). + Return the allocated memory - containing the decimal digits in low-to-high + order, terminated with a NUL character - in case of success, NULL in case + of memory allocation failure. */ +static char * +scale10_round_decimal_long_double (long double x, int n) +{ + int e IF_LINT(= 0); + mpn_t m; + void *memory = decode_long_double (x, &e, &m); + return scale10_round_decimal_decoded (e, m, memory, n); +} + +# endif + +# if NEED_PRINTF_DOUBLE + +/* Assuming x is finite and >= 0, and n is an integer: + Returns the decimal representation of round (x * 10^n). + Return the allocated memory - containing the decimal digits in low-to-high + order, terminated with a NUL character - in case of success, NULL in case + of memory allocation failure. */ +static char * +scale10_round_decimal_double (double x, int n) +{ + int e IF_LINT(= 0); + mpn_t m; + void *memory = decode_double (x, &e, &m); + return scale10_round_decimal_decoded (e, m, memory, n); +} + +# endif + +# if NEED_PRINTF_LONG_DOUBLE + +/* Assuming x is finite and > 0: + Return an approximation for n with 10^n <= x < 10^(n+1). + The approximation is usually the right n, but may be off by 1 sometimes. */ +static int +floorlog10l (long double x) +{ + int exp; + long double y; + double z; + double l; + + /* Split into exponential part and mantissa. */ + y = frexpl (x, &exp); + if (!(y >= 0.0L && y < 1.0L)) + abort (); + if (y == 0.0L) + return INT_MIN; + if (y < 0.5L) + { + while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) + { + y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } + if (y < (1.0L / (1 << 16))) + { + y *= 1.0L * (1 << 16); + exp -= 16; + } + if (y < (1.0L / (1 << 8))) + { + y *= 1.0L * (1 << 8); + exp -= 8; + } + if (y < (1.0L / (1 << 4))) + { + y *= 1.0L * (1 << 4); + exp -= 4; + } + if (y < (1.0L / (1 << 2))) + { + y *= 1.0L * (1 << 2); + exp -= 2; + } + if (y < (1.0L / (1 << 1))) + { + y *= 1.0L * (1 << 1); + exp -= 1; + } + } + if (!(y >= 0.5L && y < 1.0L)) + abort (); + /* Compute an approximation for l = log2(x) = exp + log2(y). */ + l = exp; + z = y; + if (z < 0.70710678118654752444) + { + z *= 1.4142135623730950488; + l -= 0.5; + } + if (z < 0.8408964152537145431) + { + z *= 1.1892071150027210667; + l -= 0.25; + } + if (z < 0.91700404320467123175) + { + z *= 1.0905077326652576592; + l -= 0.125; + } + if (z < 0.9576032806985736469) + { + z *= 1.0442737824274138403; + l -= 0.0625; + } + /* Now 0.95 <= z <= 1.01. */ + z = 1 - z; + /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...) + Four terms are enough to get an approximation with error < 10^-7. */ + l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25))); + /* Finally multiply with log(2)/log(10), yields an approximation for + log10(x). */ + l *= 0.30102999566398119523; + /* Round down to the next integer. */ + return (int) l + (l < 0 ? -1 : 0); +} + +# endif + +# if NEED_PRINTF_DOUBLE + +/* Assuming x is finite and > 0: + Return an approximation for n with 10^n <= x < 10^(n+1). + The approximation is usually the right n, but may be off by 1 sometimes. */ +static int +floorlog10 (double x) +{ + int exp; + double y; + double z; + double l; + + /* Split into exponential part and mantissa. */ + y = frexp (x, &exp); + if (!(y >= 0.0 && y < 1.0)) + abort (); + if (y == 0.0) + return INT_MIN; + if (y < 0.5) + { + while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) + { + y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } + if (y < (1.0 / (1 << 16))) + { + y *= 1.0 * (1 << 16); + exp -= 16; + } + if (y < (1.0 / (1 << 8))) + { + y *= 1.0 * (1 << 8); + exp -= 8; + } + if (y < (1.0 / (1 << 4))) + { + y *= 1.0 * (1 << 4); + exp -= 4; + } + if (y < (1.0 / (1 << 2))) + { + y *= 1.0 * (1 << 2); + exp -= 2; + } + if (y < (1.0 / (1 << 1))) + { + y *= 1.0 * (1 << 1); + exp -= 1; + } + } + if (!(y >= 0.5 && y < 1.0)) + abort (); + /* Compute an approximation for l = log2(x) = exp + log2(y). */ + l = exp; + z = y; + if (z < 0.70710678118654752444) + { + z *= 1.4142135623730950488; + l -= 0.5; + } + if (z < 0.8408964152537145431) + { + z *= 1.1892071150027210667; + l -= 0.25; + } + if (z < 0.91700404320467123175) + { + z *= 1.0905077326652576592; + l -= 0.125; + } + if (z < 0.9576032806985736469) + { + z *= 1.0442737824274138403; + l -= 0.0625; + } + /* Now 0.95 <= z <= 1.01. */ + z = 1 - z; + /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...) + Four terms are enough to get an approximation with error < 10^-7. */ + l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25))); + /* Finally multiply with log(2)/log(10), yields an approximation for + log10(x). */ + l *= 0.30102999566398119523; + /* Round down to the next integer. */ + return (int) l + (l < 0 ? -1 : 0); +} + +# endif + +/* Tests whether a string of digits consists of exactly PRECISION zeroes and + a single '1' digit. */ +static int +is_borderline (const char *digits, size_t precision) +{ + for (; precision > 0; precision--, digits++) + if (*digits != '0') + return 0; + if (*digits != '1') + return 0; + digits++; + return *digits == '\0'; +} + +#endif + +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 + +/* Use a different function name, to make it possible that the 'wchar_t' + parametrization and the 'char' parametrization get compiled in the same + translation unit. */ +# if WIDE_CHAR_VERSION +# define MAX_ROOM_NEEDED wmax_room_needed +# else +# define MAX_ROOM_NEEDED max_room_needed +# endif + +/* Returns the number of TCHAR_T units needed as temporary space for the result + of sprintf or SNPRINTF of a single conversion directive. */ +static size_t +MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, + arg_type type, int flags, size_t width, int has_precision, + size_t precision, int pad_ourselves) +{ + size_t tmp_length; + + switch (conversion) + { + case 'd': case 'i': case 'u': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Multiply by 2, as an estimate for FLAG_GROUP. */ + tmp_length = xsum (tmp_length, tmp_length); + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'o': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'x': case 'X': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 2, to account for a leading sign or alternate form. */ + tmp_length = xsum (tmp_length, 2); + break; + + case 'f': case 'F': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + else + tmp_length = + (unsigned int) (DBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'e': case 'E': case 'g': case 'G': + tmp_length = + 12; /* sign, decimal point, exponent etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'a': case 'A': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (DBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + break; + + case 'c': +# if HAVE_WINT_T && !WIDE_CHAR_VERSION + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else +# endif + tmp_length = 1; + break; + + case 's': +# if HAVE_WCHAR_T + if (type == TYPE_WIDE_STRING) + { +# if WIDE_CHAR_VERSION + /* ISO C says about %ls in fwprintf: + "If the precision is not specified or is greater than the size + of the array, the array shall contain a null wide character." + So if there is a precision, we must not use wcslen. */ + const wchar_t *arg = ap->arg[arg_index].a.a_wide_string; + + if (has_precision) + tmp_length = local_wcsnlen (arg, precision); + else + tmp_length = local_wcslen (arg); +# else + /* ISO C says about %ls in fprintf: + "If a precision is specified, no more than that many bytes are + written (including shift sequences, if any), and the array + shall contain a null wide character if, to equal the multibyte + character sequence length given by the precision, the function + would need to access a wide character one past the end of the + array." + So if there is a precision, we must not use wcslen. */ + /* This case has already been handled separately in VASNPRINTF. */ + abort (); +# endif + } + else +# endif + { +# if WIDE_CHAR_VERSION + /* ISO C says about %s in fwprintf: + "If the precision is not specified or is greater than the size + of the converted array, the converted array shall contain a + null wide character." + So if there is a precision, we must not use strlen. */ + /* This case has already been handled separately in VASNPRINTF. */ + abort (); +# else + /* ISO C says about %s in fprintf: + "If the precision is not specified or greater than the size of + the array, the array shall contain a null character." + So if there is a precision, we must not use strlen. */ + const char *arg = ap->arg[arg_index].a.a_string; + + if (has_precision) + tmp_length = local_strnlen (arg, precision); + else + tmp_length = strlen (arg); +# endif + } + break; + + case 'p': + tmp_length = + (unsigned int) (sizeof (void *) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1 /* turn floor into ceil */ + + 2; /* account for leading 0x */ + break; + + default: + abort (); + } + + if (!pad_ourselves) + { +# if ENABLE_UNISTDIO + /* Padding considers the number of characters, therefore the number of + elements after padding may be + > max (tmp_length, width) + but is certainly + <= tmp_length + width. */ + tmp_length = xsum (tmp_length, width); +# else + /* Padding considers the number of elements, says POSIX. */ + if (tmp_length < width) + tmp_length = width; +# endif + } + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + return tmp_length; +} + +#endif + +DCHAR_T * +VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, + const FCHAR_T *format, va_list args) +{ + DIRECTIVES d; + arguments a; + + if (PRINTF_PARSE (format, &d, &a) < 0) + /* errno is already set. */ + return NULL; + +#define CLEANUP() \ + if (d.dir != d.direct_alloc_dir) \ + free (d.dir); \ + if (a.arg != a.direct_alloc_arg) \ + free (a.arg); + + if (PRINTF_FETCHARGS (args, &a) < 0) + { + CLEANUP (); + errno = EINVAL; + return NULL; + } + + { + size_t buf_neededlength; + TCHAR_T *buf; + TCHAR_T *buf_malloced; + const FCHAR_T *cp; + size_t i; + DIRECTIVE *dp; + /* Output string accumulator. */ + DCHAR_T *result; + size_t allocated; + size_t length; + + /* Allocate a small buffer that will hold a directive passed to + sprintf or snprintf. */ + buf_neededlength = + xsum4 (7, d.max_width_length, d.max_precision_length, 6); +#if HAVE_ALLOCA + if (buf_neededlength < 4000 / sizeof (TCHAR_T)) + { + buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); + buf_malloced = NULL; + } + else +#endif + { + size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); + if (size_overflow_p (buf_memsize)) + goto out_of_memory_1; + buf = (TCHAR_T *) malloc (buf_memsize); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; + } + + if (resultbuf != NULL) + { + result = resultbuf; + allocated = *lengthp; + } + else + { + result = NULL; + allocated = 0; + } + length = 0; + /* Invariants: + result is either == resultbuf or == NULL or malloc-allocated. + If length > 0, then result != NULL. */ + + /* Ensures that allocated >= needed. Aborts through a jump to + out_of_memory if needed is SIZE_MAX or otherwise too big. */ +#define ENSURE_ALLOCATION(needed) \ + if ((needed) > allocated) \ + { \ + size_t memory_size; \ + DCHAR_T *memory; \ + \ + allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ + if ((needed) > allocated) \ + allocated = (needed); \ + memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ + if (size_overflow_p (memory_size)) \ + goto out_of_memory; \ + if (result == resultbuf || result == NULL) \ + memory = (DCHAR_T *) malloc (memory_size); \ + else \ + memory = (DCHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + DCHAR_CPY (memory, result, length); \ + result = memory; \ + } + + for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) + { + if (cp != dp->dir_start) + { + size_t n = dp->dir_start - cp; + size_t augmented_length = xsum (length, n); + + ENSURE_ALLOCATION (augmented_length); + /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we + need that the format string contains only ASCII characters + if FCHAR_T and DCHAR_T are not the same type. */ + if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) + { + DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); + length = augmented_length; + } + else + { + do + result[length++] = (unsigned char) *cp++; + while (--n > 0); + } + } + if (i == d.count) + break; + + /* Execute a single directive. */ + if (dp->conversion == '%') + { + size_t augmented_length; + + if (!(dp->arg_index == ARG_NONE)) + abort (); + augmented_length = xsum (length, 1); + ENSURE_ALLOCATION (augmented_length); + result[length] = '%'; + length = augmented_length; + } + else + { + if (!(dp->arg_index != ARG_NONE)) + abort (); + + if (dp->conversion == 'n') + { + switch (a.arg[dp->arg_index].type) + { + case TYPE_COUNT_SCHAR_POINTER: + *a.arg[dp->arg_index].a.a_count_schar_pointer = length; + break; + case TYPE_COUNT_SHORT_POINTER: + *a.arg[dp->arg_index].a.a_count_short_pointer = length; + break; + case TYPE_COUNT_INT_POINTER: + *a.arg[dp->arg_index].a.a_count_int_pointer = length; + break; + case TYPE_COUNT_LONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longint_pointer = length; + break; +#if HAVE_LONG_LONG_INT + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; +#endif + default: + abort (); + } + } +#if ENABLE_UNISTDIO + /* The unistdio extensions. */ + else if (dp->conversion == 'U') + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + switch (type) + { + case TYPE_U8_STRING: + { + const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; + const uint8_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u8_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + +# if DCHAR_IS_UINT8_T + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } +# else + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; +# if DCHAR_IS_TCHAR + /* Convert from UTF-8 to locale encoding. */ + converted = + u8_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); +# else + /* Convert from UTF-8 to UTF-16/UTF-32. */ + converted = + U8_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); +# endif + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } +# endif + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U16_STRING: + { + const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; + const uint16_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u16_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + +# if DCHAR_IS_UINT16_T + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } +# else + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; +# if DCHAR_IS_TCHAR + /* Convert from UTF-16 to locale encoding. */ + converted = + u16_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); +# else + /* Convert from UTF-16 to UTF-8/UTF-32. */ + converted = + U16_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); +# endif + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } +# endif + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U32_STRING: + { + const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; + const uint32_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u32_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + +# if DCHAR_IS_UINT32_T + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } +# else + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; +# if DCHAR_IS_TCHAR + /* Convert from UTF-32 to locale encoding. */ + converted = + u32_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); +# else + /* Convert from UTF-32 to UTF-8/UTF-16. */ + converted = + U32_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); +# endif + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } +# endif + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + default: + abort (); + } + } +#endif +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T + else if (dp->conversion == 's' +# if WIDE_CHAR_VERSION + && a.arg[dp->arg_index].type != TYPE_WIDE_STRING +# else + && a.arg[dp->arg_index].type == TYPE_WIDE_STRING +# endif + ) + { + /* The normal handling of the 's' directive below requires + allocating a temporary buffer. The determination of its + length (tmp_length), in the case when a precision is + specified, below requires a conversion between a char[] + string and a wchar_t[] wide string. It could be done, but + we have no guarantee that the implementation of sprintf will + use the exactly same algorithm. Without this guarantee, it + is possible to have buffer overrun bugs. In order to avoid + such bugs, we implement the entire processing of the 's' + directive ourselves. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + +# if WIDE_CHAR_VERSION + /* %s in vasnwprintf. See the specification of fwprintf. */ + { + const char *arg = a.arg[dp->arg_index].a.a_string; + const char *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only as many bytes as needed to produce PRECISION + wide characters, from the left. */ +# if HAVE_MBRTOWC + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count; +# if HAVE_MBRTOWC + count = mbrlen (arg_end, MB_CUR_MAX, &state); +# else + count = mblen (arg_end, MB_CUR_MAX); +# endif + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of wide + characters. */ +# if HAVE_MBRTOWC + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + arg_end = arg; + characters = 0; + for (;;) + { + int count; +# if HAVE_MBRTOWC + count = mbrlen (arg_end, MB_CUR_MAX, &state); +# else + count = mblen (arg_end, MB_CUR_MAX); +# endif + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + + if (has_precision || has_width) + { + /* We know the number of wide characters in advance. */ + size_t remaining; +# if HAVE_MBRTOWC + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; remaining--) + { + wchar_t wc; + int count; +# if HAVE_MBRTOWC + count = mbrtowc (&wc, arg, arg_end - arg, &state); +# else + count = mbtowc (&wc, arg, arg_end - arg); +# endif + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + result[length++] = wc; + arg += count; + } + if (!(arg == arg_end)) + abort (); + } + else + { +# if HAVE_MBRTOWC + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + while (arg < arg_end) + { + wchar_t wc; + int count; +# if HAVE_MBRTOWC + count = mbrtowc (&wc, arg, arg_end - arg, &state); +# else + count = mbtowc (&wc, arg, arg_end - arg); +# endif + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + ENSURE_ALLOCATION (xsum (length, 1)); + result[length++] = wc; + arg += count; + } + } + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } +# else + /* %ls in vasnprintf. See the specification of fprintf. */ + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + const wchar_t *arg_end; + size_t characters; +# if !DCHAR_IS_TCHAR + /* This code assumes that TCHAR_T is 'char'. */ + verify (sizeof (TCHAR_T) == 1); + TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; +# endif + size_t w; + + if (has_precision) + { + /* Use only as many wide characters as needed to produce + at most PRECISION bytes, from the left. */ +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + arg_end = arg; + characters = 0; + while (precision > 0) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg_end, &state); +# else + count = wctomb (cbuf, *arg_end); +# endif + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + if (precision < count) + break; + arg_end++; + characters += count; + precision -= count; + } + } +# if DCHAR_IS_TCHAR + else if (has_width) +# else + else +# endif + { + /* Use the entire string, and count the number of + bytes. */ +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + arg_end = arg; + characters = 0; + for (;;) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg_end, &state); +# else + count = wctomb (cbuf, *arg_end); +# endif + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end++; + characters += count; + } + } +# if DCHAR_IS_TCHAR + else + { + /* Use the entire string. */ + arg_end = arg + local_wcslen (arg); + /* The number of bytes doesn't matter. */ + characters = 0; + } +# endif + +# if !DCHAR_IS_TCHAR + /* Convert the string into a piece of temporary memory. */ + tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); + if (tmpsrc == NULL) + goto out_of_memory; + { + TCHAR_T *tmpptr = tmpsrc; + size_t remaining; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); +# else + count = wctomb (cbuf, *arg); +# endif + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (tmpptr, cbuf, count); + tmpptr += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, characters, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + free (tmpsrc); + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + free (tmpsrc); +# endif + + if (has_width) + { +# if ENABLE_UNISTDIO + /* Outside POSIX, it's preferable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, characters); +# else + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = characters; +# endif + } + else + /* w doesn't matter. */ + w = 0; + + if (has_width && width > w + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + +# if DCHAR_IS_TCHAR + if (has_precision || has_width) + { + /* We know the number of bytes in advance. */ + size_t remaining; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); +# else + count = wctomb (cbuf, *arg); +# endif + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (result + length, cbuf, count); + length += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + else + { +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); +# endif + while (arg < arg_end) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); +# else + count = wctomb (cbuf, *arg); +# endif + if (count <= 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, count)); + memcpy (result + length, cbuf, count); + length += count; + arg++; + } + } +# else + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + length += tmpdst_len; +# endif + + if (has_width && width > w + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } +# endif + } +#endif +#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL + else if ((dp->conversion == 'a' || dp->conversion == 'A') +# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) + && (0 +# if NEED_PRINTF_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE +# endif +# if NEED_PRINTF_LONG_DOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE +# endif + ) +# endif + ) + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* Allocate a temporary buffer of sufficient size. */ + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) ((LDBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) ((DBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } + + pad_ptr = NULL; + p = tmp; + if (type == TYPE_LONGDOUBLE) + { +# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + long double mantissa; + + if (arg > 0.0L) + mantissa = printf_frexpl (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0L; + } + + if (has_precision + && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + long double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5L : tail > 0.5L) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0L; + } + if (tail != 0.0L) + for (q = precision; q > 0; q--) + tail *= 0.0625L; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0L || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0L) + { + mantissa *= 16.0L; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } +# endif + } + + END_LONG_DOUBLE_ROUNDING (); + } +# else + abort (); +# endif + } + else + { +# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + double mantissa; + + if (arg > 0.0) + mantissa = printf_frexp (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0; + } + + if (has_precision + && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5 : tail > 0.5) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0; + } + if (tail != 0.0) + for (q = precision; q > 0; q--) + tail *= 0.0625; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0 || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0) + { + mantissa *= 16.0; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } +# endif + } + } +# else + abort (); +# endif + } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } +#endif +#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL + else if ((dp->conversion == 'f' || dp->conversion == 'F' + || dp->conversion == 'e' || dp->conversion == 'E' + || dp->conversion == 'g' || dp->conversion == 'G' + || dp->conversion == 'a' || dp->conversion == 'A') + && (0 +# if NEED_PRINTF_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE +# elif NEED_PRINTF_INFINITE_DOUBLE + || (a.arg[dp->arg_index].type == TYPE_DOUBLE + /* The systems (mingw) which produce wrong output + for Inf, -Inf, and NaN also do so for -0.0. + Therefore we treat this case here as well. */ + && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) +# endif +# if NEED_PRINTF_LONG_DOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE +# elif NEED_PRINTF_INFINITE_LONG_DOUBLE + || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + /* Some systems produce wrong output for Inf, + -Inf, and NaN. Some systems in this category + (IRIX 5.3) also do so for -0.0. Therefore we + treat this case here as well. */ + && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) +# endif + )) + { +# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) + arg_type type = a.arg[dp->arg_index].type; +# endif + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* POSIX specifies the default precision to be 6 for %f, %F, + %e, %E, but not for %g, %G. Implementations appear to use + the same default precision also for %g, %G. But for %a, %A, + the default precision is 0. */ + if (!has_precision) + if (!(dp->conversion == 'a' || dp->conversion == 'A')) + precision = 6; + + /* Allocate a temporary buffer of sufficient size. */ +# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); +# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); +# elif NEED_PRINTF_LONG_DOUBLE + tmp_length = LDBL_DIG + 1; +# elif NEED_PRINTF_DOUBLE + tmp_length = DBL_DIG + 1; +# else + tmp_length = 0; +# endif + if (tmp_length < precision) + tmp_length = precision; +# if NEED_PRINTF_LONG_DOUBLE +# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE + if (type == TYPE_LONGDOUBLE) +# endif + if (dp->conversion == 'f' || dp->conversion == 'F') + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + if (!(isnanl (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10l (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } +# endif +# if NEED_PRINTF_DOUBLE +# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE + if (type == TYPE_DOUBLE) +# endif + if (dp->conversion == 'f' || dp->conversion == 'F') + { + double arg = a.arg[dp->arg_index].a.a_double; + if (!(isnand (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10 (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } +# endif + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } + + pad_ptr = NULL; + p = tmp; + +# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE +# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE + if (type == TYPE_LONGDOUBLE) +# endif + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { +# if NEED_PRINTF_LONG_DOUBLE + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_long_double (arg, precision); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0L) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0L. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)precision - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } +# endif + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0L) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0L. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } +# endif + } + + free (digits); + } + } + else + abort (); +# else + /* arg is finite. */ + if (!(arg == 0.0L)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else if (dp->conversion == 'a' || dp->conversion == 'A') + { + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion - 'A' + 'P'; + *p++ = '+'; + *p++ = '0'; + } + else + abort (); +# endif + } + + END_LONG_DOUBLE_ROUNDING (); + } + } +# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE + else +# endif +# endif +# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE + { + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { +# if NEED_PRINTF_DOUBLE + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_double (arg, precision); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)precision - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + { '%', '+', '.', '3', 'd', '\0' }; +# else + { '%', '+', '.', '2', 'd', '\0' }; +# endif + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + "%+.3d"; +# else + "%+.2d"; +# endif + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } +# endif + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ +# if WIDE_CHAR_VERSION + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + { '%', '+', '.', '3', 'd', '\0' }; +# else + { '%', '+', '.', '2', 'd', '\0' }; +# endif + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; +# else + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + "%+.3d"; +# else + "%+.2d"; +# endif + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } +# endif + } + + free (digits); + } + } + else + abort (); +# else + /* arg is finite. */ + if (!(arg == 0.0)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + /* Produce the same number of exponent digits as + the native printf implementation. */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + *p++ = '0'; +# endif + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else + abort (); +# endif + } + } + } +# endif + + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } +#endif + else + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + int has_width; + size_t width; +#endif +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION + int has_precision; + size_t precision; +#endif +#if NEED_PRINTF_UNBOUNDED_PRECISION + int prec_ourselves; +#else +# define prec_ourselves 0 +#endif +#if NEED_PRINTF_FLAG_LEFTADJUST +# define pad_ourselves 1 +#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + int pad_ourselves; +#else +# define pad_ourselves 0 +#endif + TCHAR_T *fbp; + unsigned int prefix_count; + int prefixes[2] IF_LINT (= { 0 }); + int orig_errno; +#if !USE_SNPRINTF + size_t tmp_length; + TCHAR_T tmpbuf[700]; + TCHAR_T *tmp; +#endif + +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } +#endif + +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } +#endif + + /* Decide whether to handle the precision ourselves. */ +#if NEED_PRINTF_UNBOUNDED_PRECISION + switch (dp->conversion) + { + case 'd': case 'i': case 'u': + case 'o': + case 'x': case 'X': case 'p': + prec_ourselves = has_precision && (precision > 0); + break; + default: + prec_ourselves = 0; + break; + } +#endif + + /* Decide whether to perform the padding ourselves. */ +#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION) + switch (dp->conversion) + { +# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO + /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need + to perform the padding after this conversion. Functions + with unistdio extensions perform the padding based on + character count rather than element count. */ + case 'c': case 's': +# endif +# if NEED_PRINTF_FLAG_ZERO + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': +# endif + pad_ourselves = 1; + break; + default: + pad_ourselves = prec_ourselves; + break; + } +#endif + +#if !USE_SNPRINTF + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + tmp_length = + MAX_ROOM_NEEDED (&a, dp->arg_index, dp->conversion, type, + flags, width, has_precision, precision, + pad_ourselves); + + if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (TCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } +#endif + + /* Construct the format string for calling snprintf or + sprintf. */ + fbp = buf; + *fbp++ = '%'; +#if NEED_PRINTF_FLAG_GROUPING + /* The underlying implementation doesn't support the ' flag. + Produce no grouping characters in this case; this is + acceptable because the grouping is locale dependent. */ +#else + if (flags & FLAG_GROUP) + *fbp++ = '\''; +#endif + if (flags & FLAG_LEFT) + *fbp++ = '-'; + if (flags & FLAG_SHOWSIGN) + *fbp++ = '+'; + if (flags & FLAG_SPACE) + *fbp++ = ' '; + if (flags & FLAG_ALT) + *fbp++ = '#'; +#if __GLIBC__ >= 2 && !defined __UCLIBC__ + if (flags & FLAG_LOCALIZED) + *fbp++ = 'I'; +#endif + if (!pad_ourselves) + { + if (flags & FLAG_ZERO) + *fbp++ = '0'; + if (dp->width_start != dp->width_end) + { + size_t n = dp->width_end - dp->width_start; + /* The width specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->width_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + if (!prec_ourselves) + { + if (dp->precision_start != dp->precision_end) + { + size_t n = dp->precision_end - dp->precision_start; + /* The precision specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->precision_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + + switch (type) + { +#if HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + *fbp++ = 'I'; + *fbp++ = '6'; + *fbp++ = '4'; + break; +# else + *fbp++ = 'l'; + /*FALLTHROUGH*/ +# endif +#endif + case TYPE_LONGINT: + case TYPE_ULONGINT: +#if HAVE_WINT_T + case TYPE_WIDE_CHAR: +#endif +#if HAVE_WCHAR_T + case TYPE_WIDE_STRING: +#endif + *fbp++ = 'l'; + break; + case TYPE_LONGDOUBLE: + *fbp++ = 'L'; + break; + default: + break; + } +#if NEED_PRINTF_DIRECTIVE_F + if (dp->conversion == 'F') + *fbp = 'f'; + else +#endif + *fbp = dp->conversion; +#if USE_SNPRINTF +# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) + fbp[1] = '%'; + fbp[2] = 'n'; + fbp[3] = '\0'; +# else + /* On glibc2 systems from glibc >= 2.3 - probably also older + ones - we know that snprintf's return value conforms to + ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and + gl_SNPRINTF_TRUNCATION_C99 pass. + Therefore we can avoid using %n in this situation. + On glibc2 systems from 2004-10-18 or newer, the use of %n + in format strings in writable memory may crash the program + (if compiled with _FORTIFY_SOURCE=2), so we should avoid it + in this situation. */ + /* On native Windows systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Windows systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ + fbp[1] = '\0'; +# endif +#else + fbp[1] = '\0'; +#endif + + /* Construct the arguments for calling snprintf or sprintf. */ + prefix_count = 0; + if (!pad_ourselves && dp->width_arg_index != ARG_NONE) + { + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; + } + if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) + { + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; + } + +#if USE_SNPRINTF + /* The SNPRINTF result is appended after result[0..length]. + The latter is an array of DCHAR_T; SNPRINTF appends an + array of TCHAR_T to it. This is possible because + sizeof (TCHAR_T) divides sizeof (DCHAR_T) and + alignof (TCHAR_T) <= alignof (DCHAR_T). */ +# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) + /* Ensure that maxlen below will be >= 2. Needed on BeOS, + where an snprintf() with maxlen==1 acts like sprintf(). */ + ENSURE_ALLOCATION (xsum (length, + (2 + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR)); + /* Prepare checking whether snprintf returns the count + via %n. */ + *(TCHAR_T *) (result + length) = '\0'; +#endif + + orig_errno = errno; + + for (;;) + { + int count = -1; + +#if USE_SNPRINTF + int retcount = 0; + size_t maxlen = allocated - length; + /* SNPRINTF can fail if its second argument is + > INT_MAX. */ + if (maxlen > INT_MAX / TCHARS_PER_DCHAR) + maxlen = INT_MAX / TCHARS_PER_DCHAR; + maxlen = maxlen * TCHARS_PER_DCHAR; +# define SNPRINTF_BUF(arg) \ + switch (prefix_count) \ + { \ + case 0: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + arg, &count); \ + break; \ + case 1: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], arg, &count); \ + break; \ + case 2: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], prefixes[1], arg, \ + &count); \ + break; \ + default: \ + abort (); \ + } +#else +# define SNPRINTF_BUF(arg) \ + switch (prefix_count) \ + { \ + case 0: \ + count = sprintf (tmp, buf, arg); \ + break; \ + case 1: \ + count = sprintf (tmp, buf, prefixes[0], arg); \ + break; \ + case 2: \ + count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ + arg); \ + break; \ + default: \ + abort (); \ + } +#endif + + errno = 0; + switch (type) + { + case TYPE_SCHAR: + { + int arg = a.arg[dp->arg_index].a.a_schar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UCHAR: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uchar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_SHORT: + { + int arg = a.arg[dp->arg_index].a.a_short; + SNPRINTF_BUF (arg); + } + break; + case TYPE_USHORT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_ushort; + SNPRINTF_BUF (arg); + } + break; + case TYPE_INT: + { + int arg = a.arg[dp->arg_index].a.a_int; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UINT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGINT: + { + long int arg = a.arg[dp->arg_index].a.a_longint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGINT: + { + unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; + SNPRINTF_BUF (arg); + } + break; +#if HAVE_LONG_LONG_INT + case TYPE_LONGLONGINT: + { + long long int arg = a.arg[dp->arg_index].a.a_longlongint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGLONGINT: + { + unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_DOUBLE: + { + double arg = a.arg[dp->arg_index].a.a_double; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGDOUBLE: + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + SNPRINTF_BUF (arg); + } + break; + case TYPE_CHAR: + { + int arg = a.arg[dp->arg_index].a.a_char; + SNPRINTF_BUF (arg); + } + break; +#if HAVE_WINT_T + case TYPE_WIDE_CHAR: + { + wint_t arg = a.arg[dp->arg_index].a.a_wide_char; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_STRING: + { + const char *arg = a.arg[dp->arg_index].a.a_string; + SNPRINTF_BUF (arg); + } + break; +#if HAVE_WCHAR_T + case TYPE_WIDE_STRING: + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + SNPRINTF_BUF (arg); + } + break; +#endif + case TYPE_POINTER: + { + void *arg = a.arg[dp->arg_index].a.a_pointer; + SNPRINTF_BUF (arg); + } + break; + default: + abort (); + } + +#if USE_SNPRINTF + /* Portability: Not all implementations of snprintf() + are ISO C 99 compliant. Determine the number of + bytes that snprintf() has produced or would have + produced. */ + if (count >= 0) + { + /* Verify that snprintf() has NUL-terminated its + result. */ + if (count < maxlen + && ((TCHAR_T *) (result + length)) [count] != '\0') + abort (); + /* Portability hack. */ + if (retcount > count) + count = retcount; + } + else + { + /* snprintf() doesn't understand the '%n' + directive. */ + if (fbp[1] != '\0') + { + /* Don't use the '%n' directive; instead, look + at the snprintf() return value. */ + fbp[1] = '\0'; + continue; + } + else + { + /* Look at the snprintf() return value. */ + if (retcount < 0) + { +# if !HAVE_SNPRINTF_RETVAL_C99 + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. + But a failure at this point can also come + from other reasons than a too small buffer, + such as an invalid wide string argument to + the %ls directive, or possibly an invalid + floating-point argument. */ + size_t tmp_length = + MAX_ROOM_NEEDED (&a, dp->arg_index, + dp->conversion, type, flags, + width, has_precision, + precision, pad_ourselves); + + if (maxlen < tmp_length) + { + /* Make more room. But try to do through + this reallocation only once. */ + size_t bigger_need = + xsum (length, + xsum (tmp_length, + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + /* And always grow proportionally. + (There may be several arguments, each + needing a little more room than the + previous one.) */ + size_t bigger_need2 = + xsum (xtimes (allocated, 2), 12); + if (bigger_need < bigger_need2) + bigger_need = bigger_need2; + ENSURE_ALLOCATION (bigger_need); + continue; + } +# endif + } + else + count = retcount; + } + } +#endif + + /* Attempt to handle failure. */ + if (count < 0) + { + /* SNPRINTF or sprintf failed. Save and use the errno + that it has set, if any. */ + int saved_errno = errno; + + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = + (saved_errno != 0 + ? saved_errno + : (dp->conversion == 'c' || dp->conversion == 's' + ? EILSEQ + : EINVAL)); + return NULL; + } + +#if USE_SNPRINTF + /* Handle overflow of the allocated buffer. + If such an overflow occurs, a C99 compliant snprintf() + returns a count >= maxlen. However, a non-compliant + snprintf() function returns only count = maxlen - 1. To + cover both cases, test whether count >= maxlen - 1. */ + if ((unsigned int) count + 1 >= maxlen) + { + /* If maxlen already has attained its allowed maximum, + allocating more memory will not increase maxlen. + Instead of looping, bail out. */ + if (maxlen == INT_MAX / TCHARS_PER_DCHAR) + goto overflow; + else + { + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping + eternally if snprintf() reports a too small + count. */ + size_t n = + xmax (xsum (length, + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR), + xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + continue; + } + } +#endif + +#if NEED_PRINTF_UNBOUNDED_PRECISION + if (prec_ourselves) + { + /* Handle the precision. */ + TCHAR_T *prec_ptr = +# if USE_SNPRINTF + (TCHAR_T *) (result + length); +# else + tmp; +# endif + size_t prefix_count; + size_t move; + + prefix_count = 0; + /* Put the additional zeroes after the sign. */ + if (count >= 1 + && (*prec_ptr == '-' || *prec_ptr == '+' + || *prec_ptr == ' ')) + prefix_count = 1; + /* Put the additional zeroes after the 0x prefix if + (flags & FLAG_ALT) || (dp->conversion == 'p'). */ + else if (count >= 2 + && prec_ptr[0] == '0' + && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) + prefix_count = 2; + + move = count - prefix_count; + if (precision > move) + { + /* Insert zeroes. */ + size_t insert = precision - move; + TCHAR_T *prec_end; + +# if USE_SNPRINTF + size_t n = + xsum (length, + (count + insert + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + ENSURE_ALLOCATION (n); + length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + prec_ptr = (TCHAR_T *) (result + length); +# endif + + prec_end = prec_ptr + count; + prec_ptr += prefix_count; + + while (prec_end > prec_ptr) + { + prec_end--; + prec_end[insert] = prec_end[0]; + } + + prec_end += insert; + do + *--prec_end = '0'; + while (prec_end > prec_ptr); + + count += insert; + } + } +#endif + +#if !USE_SNPRINTF + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); +#endif + +#if !DCHAR_IS_TCHAR + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + if (dp->conversion == 'c' || dp->conversion == 's') + { + /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING + TYPE_WIDE_STRING. + The result string is not certainly ASCII. */ + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + verify (sizeof (TCHAR_T) == 1); +# if USE_SNPRINTF + tmpsrc = (TCHAR_T *) (result + length); +# else + tmpsrc = tmp; +# endif + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, count, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + count = tmpdst_len; + } + else + { + /* The result string is ASCII. + Simple 1:1 conversion. */ +# if USE_SNPRINTF + /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a + no-op conversion, in-place on the array starting + at (result + length). */ + if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) +# endif + { + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t n; + +# if USE_SNPRINTF + if (result == resultbuf) + { + tmpsrc = (TCHAR_T *) (result + length); + /* ENSURE_ALLOCATION will not move tmpsrc + (because it's part of resultbuf). */ + ENSURE_ALLOCATION (xsum (length, count)); + } + else + { + /* ENSURE_ALLOCATION will move the array + (because it uses realloc(). */ + ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = (TCHAR_T *) (result + length); + } +# else + tmpsrc = tmp; + ENSURE_ALLOCATION (xsum (length, count)); +# endif + tmpdst = result + length; + /* Copy backwards, because of overlapping. */ + tmpsrc += count; + tmpdst += count; + for (n = count; n > 0; n--) + *--tmpdst = (unsigned char) *--tmpsrc; + } + } +#endif + +#if DCHAR_IS_TCHAR && !USE_SNPRINTF + /* Make room for the result. */ + if (count > allocated - length) + { + /* Need at least count elements. But allocate + proportionally. */ + size_t n = + xmax (xsum (length, count), xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + } +#endif + + /* Here count <= allocated - length. */ + + /* Perform padding. */ +#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + if (pad_ourselves && has_width) + { + size_t w; +# if ENABLE_UNISTDIO + /* Outside POSIX, it's preferable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, count); +# else + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = count; +# endif + if (w < width) + { + size_t pad = width - w; + + /* Make room for the result. */ + if (xsum (count, pad) > allocated - length) + { + /* Need at least count + pad elements. But + allocate proportionally. */ + size_t n = + xmax (xsum3 (length, count, pad), + xtimes (allocated, 2)); + +# if USE_SNPRINTF + length += count; + ENSURE_ALLOCATION (n); + length -= count; +# else + ENSURE_ALLOCATION (n); +# endif + } + /* Here count + pad <= allocated - length. */ + + { +# if !DCHAR_IS_TCHAR || USE_SNPRINTF + DCHAR_T * const rp = result + length; +# else + DCHAR_T * const rp = tmp; +# endif + DCHAR_T *p = rp + count; + DCHAR_T *end = p + pad; + DCHAR_T *pad_ptr; +# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO + if (dp->conversion == 'c' + || dp->conversion == 's') + /* No zero-padding for string directives. */ + pad_ptr = NULL; + else +# endif + { + pad_ptr = (*rp == '-' ? rp + 1 : rp); + /* No zero-padding of "inf" and "nan". */ + if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') + || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) + pad_ptr = NULL; + } + /* The generated string now extends from rp to p, + with the zero padding insertion point being at + pad_ptr. */ + + count = count + pad; /* = end - rp */ + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > rp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + } + } + } +#endif + + /* Here still count <= allocated - length. */ + +#if !DCHAR_IS_TCHAR || USE_SNPRINTF + /* The snprintf() result did fit. */ +#else + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); +#endif +#if !USE_SNPRINTF + if (tmp != tmpbuf) + free (tmp); +#endif + +#if NEED_PRINTF_DIRECTIVE_F + if (dp->conversion == 'F') + { + /* Convert the %f result to upper case for %F. */ + DCHAR_T *rp = result + length; + size_t rc; + for (rc = count; rc > 0; rc--, rp++) + if (*rp >= 'a' && *rp <= 'z') + *rp = *rp - 'a' + 'A'; + } +#endif + + length += count; + break; + } + errno = orig_errno; +#undef pad_ourselves +#undef prec_ourselves + } + } + } + + /* Add the final NUL. */ + ENSURE_ALLOCATION (xsum (length, 1)); + result[length] = '\0'; + + if (result != resultbuf && length + 1 < allocated) + { + /* Shrink the allocated memory if possible. */ + DCHAR_T *memory; + + memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); + if (memory != NULL) + result = memory; + } + + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + *lengthp = length; + /* Note that we can produce a big string of a length > INT_MAX. POSIX + says that snprintf() fails with errno = EOVERFLOW in this case, but + that's only because snprintf() returns an 'int'. This function does + not have this limitation. */ + return result; + +#if USE_SNPRINTF + overflow: + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EOVERFLOW; + return NULL; +#endif + + out_of_memory: + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + out_of_memory_1: + CLEANUP (); + errno = ENOMEM; + return NULL; + } +} + +#undef MAX_ROOM_NEEDED +#undef TCHARS_PER_DCHAR +#undef SNPRINTF +#undef USE_SNPRINTF +#undef DCHAR_SET +#undef DCHAR_CPY +#undef PRINTF_PARSE +#undef DIRECTIVES +#undef DIRECTIVE +#undef DCHAR_IS_TCHAR +#undef TCHAR_T +#undef DCHAR_T +#undef FCHAR_T +#undef VASNPRINTF diff --git a/grub-core/gnulib/vasnprintf.h b/grub-core/gnulib/vasnprintf.h new file mode 100644 index 000000000..7658f505e --- /dev/null +++ b/grub-core/gnulib/vasnprintf.h @@ -0,0 +1,79 @@ +/* vsprintf with automatic memory allocation. + Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifndef _VASNPRINTF_H +#define _VASNPRINTF_H + +/* Get va_list. */ +#include + +/* Get size_t. */ +#include + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Write formatted output to a string dynamically allocated with malloc(). + You can pass a preallocated buffer for the result in RESULTBUF and its + size in *LENGTHP; otherwise you pass RESULTBUF = NULL. + If successful, return the address of the string (this may be = RESULTBUF + if no dynamic memory allocation was necessary) and set *LENGTHP to the + number of resulting bytes, excluding the trailing NUL. Upon error, set + errno and return NULL. + + When dynamic memory allocation occurs, the preallocated buffer is left + alone (with possibly modified contents). This makes it possible to use + a statically allocated or stack-allocated buffer, like this: + + char buf[100]; + size_t len = sizeof (buf); + char *output = vasnprintf (buf, &len, format, args); + if (output == NULL) + ... error handling ...; + else + { + ... use the output string ...; + if (output != buf) + free (output); + } + */ +#if REPLACE_VASNPRINTF +# define asnprintf rpl_asnprintf +# define vasnprintf rpl_vasnprintf +#endif +extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) + _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); +extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) + _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); + +#ifdef __cplusplus +} +#endif + +#endif /* _VASNPRINTF_H */ diff --git a/grub-core/gnulib/verify.h b/grub-core/gnulib/verify.h new file mode 100644 index 000000000..cb8e90b54 --- /dev/null +++ b/grub-core/gnulib/verify.h @@ -0,0 +1,245 @@ +/* Compile-time assert-like macros. + + Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ + +#ifndef _GL_VERIFY_H +# define _GL_VERIFY_H + + +/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. + This is supported by GCC 4.6.0 and later, in C mode, and its use + here generates easier-to-read diagnostics when verify (R) fails. + + Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11. + This will likely be supported by future GCC versions, in C++ mode. + + Use this only with GCC. If we were willing to slow 'configure' + down we could also use it with other compilers, but since this + affects only the quality of diagnostics, why bother? */ +# if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined __cplusplus +# define _GL_HAVE__STATIC_ASSERT 1 +# endif +/* The condition (99 < __GNUC__) is temporary, until we know about the + first G++ release that supports static_assert. */ +# if (99 < __GNUC__) && defined __cplusplus +# define _GL_HAVE_STATIC_ASSERT 1 +# endif + +/* Each of these macros verifies that its argument R is nonzero. To + be portable, R should be an integer constant expression. Unlike + assert (R), there is no run-time overhead. + + If _Static_assert works, verify (R) uses it directly. Similarly, + _GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct + that is an operand of sizeof. + + The code below uses several ideas for C++ compilers, and for C + compilers that do not support _Static_assert: + + * The first step is ((R) ? 1 : -1). Given an expression R, of + integral or boolean or floating-point type, this yields an + expression of integral type, whose value is later verified to be + constant and nonnegative. + + * Next this expression W is wrapped in a type + struct _gl_verify_type { + unsigned int _gl_verify_error_if_negative: W; + }. + If W is negative, this yields a compile-time error. No compiler can + deal with a bit-field of negative size. + + One might think that an array size check would have the same + effect, that is, that the type struct { unsigned int dummy[W]; } + would work as well. However, inside a function, some compilers + (such as C++ compilers and GNU C) allow local parameters and + variables inside array size expressions. With these compilers, + an array size check would not properly diagnose this misuse of + the verify macro: + + void function (int n) { verify (n < 0); } + + * For the verify macro, the struct _gl_verify_type will need to + somehow be embedded into a declaration. To be portable, this + declaration must declare an object, a constant, a function, or a + typedef name. If the declared entity uses the type directly, + such as in + + struct dummy {...}; + typedef struct {...} dummy; + extern struct {...} *dummy; + extern void dummy (struct {...} *); + extern struct {...} *dummy (void); + + two uses of the verify macro would yield colliding declarations + if the entity names are not disambiguated. A workaround is to + attach the current line number to the entity name: + + #define _GL_CONCAT0(x, y) x##y + #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) + extern struct {...} * _GL_CONCAT (dummy, __LINE__); + + But this has the problem that two invocations of verify from + within the same macro would collide, since the __LINE__ value + would be the same for both invocations. (The GCC __COUNTER__ + macro solves this problem, but is not portable.) + + A solution is to use the sizeof operator. It yields a number, + getting rid of the identity of the type. Declarations like + + extern int dummy [sizeof (struct {...})]; + extern void dummy (int [sizeof (struct {...})]); + extern int (*dummy (void)) [sizeof (struct {...})]; + + can be repeated. + + * Should the implementation use a named struct or an unnamed struct? + Which of the following alternatives can be used? + + extern int dummy [sizeof (struct {...})]; + extern int dummy [sizeof (struct _gl_verify_type {...})]; + extern void dummy (int [sizeof (struct {...})]); + extern void dummy (int [sizeof (struct _gl_verify_type {...})]); + extern int (*dummy (void)) [sizeof (struct {...})]; + extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})]; + + In the second and sixth case, the struct type is exported to the + outer scope; two such declarations therefore collide. GCC warns + about the first, third, and fourth cases. So the only remaining + possibility is the fifth case: + + extern int (*dummy (void)) [sizeof (struct {...})]; + + * GCC warns about duplicate declarations of the dummy function if + -Wredundant-decls is used. GCC 4.3 and later have a builtin + __COUNTER__ macro that can let us generate unique identifiers for + each dummy function, to suppress this warning. + + * This implementation exploits the fact that older versions of GCC, + which do not support _Static_assert, also do not warn about the + last declaration mentioned above. + + * GCC warns if -Wnested-externs is enabled and verify() is used + within a function body; but inside a function, you can always + arrange to use verify_expr() instead. + + * In C++, any struct definition inside sizeof is invalid. + Use a template type to work around the problem. */ + +/* Concatenate two preprocessor tokens. */ +# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) +# define _GL_CONCAT0(x, y) x##y + +/* _GL_COUNTER is an integer, preferably one that changes each time we + use it. Use __COUNTER__ if it works, falling back on __LINE__ + otherwise. __LINE__ isn't perfect, but it's better than a + constant. */ +# if defined __COUNTER__ && __COUNTER__ != __COUNTER__ +# define _GL_COUNTER __COUNTER__ +# else +# define _GL_COUNTER __LINE__ +# endif + +/* Generate a symbol with the given prefix, making it unique if + possible. */ +# define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) + +/* Verify requirement R at compile-time, as an integer constant expression + that returns 1. If R is false, fail at compile-time, preferably + with a diagnostic that includes the string-literal DIAGNOSTIC. */ + +# define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ + (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) + +# ifdef __cplusplus +# if !GNULIB_defined_struct__gl_verify_type +template + struct _gl_verify_type { + unsigned int _gl_verify_error_if_negative: w; + }; +# define GNULIB_defined_struct__gl_verify_type 1 +# endif +# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ + _gl_verify_type<(R) ? 1 : -1> +# elif defined _GL_HAVE__STATIC_ASSERT +# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ + struct { \ + _Static_assert (R, DIAGNOSTIC); \ + int _gl_dummy; \ + } +# else +# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ + struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } +# endif + +/* Verify requirement R at compile-time, as a declaration without a + trailing ';'. If R is false, fail at compile-time, preferably + with a diagnostic that includes the string-literal DIAGNOSTIC. + + Unfortunately, unlike C11, this implementation must appear as an + ordinary declaration, and cannot appear inside struct { ... }. */ + +# ifdef _GL_HAVE__STATIC_ASSERT +# define _GL_VERIFY _Static_assert +# else +# define _GL_VERIFY(R, DIAGNOSTIC) \ + extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ + [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] +# endif + +/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ +# ifdef _GL_STATIC_ASSERT_H +# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert +# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) +# endif +# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert +# define static_assert _Static_assert /* C11 requires this #define. */ +# endif +# endif + +/* @assert.h omit start@ */ + +/* Each of these macros verifies that its argument R is nonzero. To + be portable, R should be an integer constant expression. Unlike + assert (R), there is no run-time overhead. + + There are two macros, since no single macro can be used in all + contexts in C. verify_true (R) is for scalar contexts, including + integer constant expression contexts. verify (R) is for declaration + contexts, e.g., the top level. */ + +/* Verify requirement R at compile-time, as an integer constant expression. + Return 1. This is equivalent to verify_expr (R, 1). + + verify_true is obsolescent; please use verify_expr instead. */ + +# define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") + +/* Verify requirement R at compile-time. Return the value of the + expression E. */ + +# define verify_expr(R, E) \ + (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) + +/* Verify requirement R at compile-time, as a declaration without a + trailing ';'. */ + +# define verify(R) _GL_VERIFY (R, "verify (" #R ")") + +/* @assert.h omit end@ */ + +#endif diff --git a/grub-core/gnulib/vsnprintf.c b/grub-core/gnulib/vsnprintf.c new file mode 100644 index 000000000..7d4dfbed9 --- /dev/null +++ b/grub-core/gnulib/vsnprintf.c @@ -0,0 +1,70 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc. + Written by Simon Josefsson and Yoann Vandoorselaere . + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include + +#include +#include +#include +#include +#include + +#include "vasnprintf.h" + +/* Print formatted output to string STR. Similar to vsprintf, but + additional length SIZE limit how much is written into STR. Returns + string length of formatted string (which may be larger than SIZE). + STR may be NULL, in which case nothing will be written. On error, + return a negative value. */ +int +vsnprintf (char *str, size_t size, const char *format, va_list args) +{ + char *output; + size_t len; + size_t lenbuf = size; + + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > INT_MAX) + { + errno = EOVERFLOW; + return -1; + } + + return len; +} diff --git a/grub-core/gnulib/wchar.in.h b/grub-core/gnulib/wchar.in.h new file mode 100644 index 000000000..b6e436279 --- /dev/null +++ b/grub-core/gnulib/wchar.in.h @@ -0,0 +1,1028 @@ +/* A substitute for ISO C99 , for platforms that have issues. + + Copyright (C) 2007-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Eric Blake. */ + +/* + * ISO C 99 for platforms that have issues. + * + * + * For now, this just ensures proper prerequisite inclusion order and + * the declaration of wcwidth(). + */ + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H +/* Special invocation convention: + - Inside glibc and uClibc header files. + - On HP-UX 11.00 we have a sequence of nested includes + -> -> , and the latter includes , + once indirectly -> -> -> + and once directly. In both situations 'wint_t' is not yet defined, + therefore we cannot provide the function overrides; instead include only + the system's . + - On IRIX 6.5, similarly, we have an include -> , and + the latter includes . But here, we have no way to detect whether + is completely included or is still being included. */ + +#@INCLUDE_NEXT@ @NEXT_WCHAR_H@ + +#else +/* Normal invocation convention. */ + +#ifndef _@GUARD_PREFIX@_WCHAR_H + +#define _GL_ALREADY_INCLUDING_WCHAR_H + +#if @HAVE_FEATURES_H@ +# include /* for __GLIBC__ */ +#endif + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . + In some builds of uClibc, is nonexistent and wchar_t is defined + by . + But avoid namespace pollution on glibc systems. */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +#endif +#ifndef __GLIBC__ +# include +# include +#endif + +/* Include the original if it exists. + Some builds of uClibc lack it. */ +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_WCHAR_H@ +# @INCLUDE_NEXT@ @NEXT_WCHAR_H@ +#endif + +#undef _GL_ALREADY_INCLUDING_WCHAR_H + +#ifndef _@GUARD_PREFIX@_WCHAR_H +#define _@GUARD_PREFIX@_WCHAR_H + +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The attribute __pure__ was added in gcc 2.96. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define _GL_ATTRIBUTE_PURE /* empty */ +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + +/* Define wint_t and WEOF. (Also done in wctype.in.h.) */ +#if !@HAVE_WINT_T@ && !defined wint_t +# define wint_t int +# ifndef WEOF +# define WEOF -1 +# endif +#else +/* MSVC defines wint_t as 'unsigned short' in . + This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be + "unchanged by default argument promotions". Override it. */ +# if defined _MSC_VER +# if !GNULIB_defined_wint_t +# include +typedef unsigned int rpl_wint_t; +# undef wint_t +# define wint_t rpl_wint_t +# define GNULIB_defined_wint_t 1 +# endif +# endif +# ifndef WEOF +# define WEOF ((wint_t) -1) +# endif +#endif + + +/* Override mbstate_t if it is too small. + On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for + implementing mbrtowc for encodings like UTF-8. */ +#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@ +# if !GNULIB_defined_mbstate_t +typedef int rpl_mbstate_t; +# undef mbstate_t +# define mbstate_t rpl_mbstate_t +# define GNULIB_defined_mbstate_t 1 +# endif +#endif + + +/* Convert a single-byte character to a wide character. */ +#if @GNULIB_BTOWC@ +# if @REPLACE_BTOWC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef btowc +# define btowc rpl_btowc +# endif +_GL_FUNCDECL_RPL (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE); +_GL_CXXALIAS_RPL (btowc, wint_t, (int c)); +# else +# if !@HAVE_BTOWC@ +_GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (btowc, wint_t, (int c)); +# endif +_GL_CXXALIASWARN (btowc); +#elif defined GNULIB_POSIXCHECK +# undef btowc +# if HAVE_RAW_DECL_BTOWC +_GL_WARN_ON_USE (btowc, "btowc is unportable - " + "use gnulib module btowc for portability"); +# endif +#endif + + +/* Convert a wide character to a single-byte character. */ +#if @GNULIB_WCTOB@ +# if @REPLACE_WCTOB@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wctob +# define wctob rpl_wctob +# endif +_GL_FUNCDECL_RPL (wctob, int, (wint_t wc) _GL_ATTRIBUTE_PURE); +_GL_CXXALIAS_RPL (wctob, int, (wint_t wc)); +# else +# if !defined wctob && !@HAVE_DECL_WCTOB@ +/* wctob is provided by gnulib, or wctob exists but is not declared. */ +_GL_FUNCDECL_SYS (wctob, int, (wint_t wc) _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wctob, int, (wint_t wc)); +# endif +_GL_CXXALIASWARN (wctob); +#elif defined GNULIB_POSIXCHECK +# undef wctob +# if HAVE_RAW_DECL_WCTOB +_GL_WARN_ON_USE (wctob, "wctob is unportable - " + "use gnulib module wctob for portability"); +# endif +#endif + + +/* Test whether *PS is in the initial state. */ +#if @GNULIB_MBSINIT@ +# if @REPLACE_MBSINIT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsinit +# define mbsinit rpl_mbsinit +# endif +_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps)); +# else +# if !@HAVE_MBSINIT@ +_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (mbsinit); +#elif defined GNULIB_POSIXCHECK +# undef mbsinit +# if HAVE_RAW_DECL_MBSINIT +_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - " + "use gnulib module mbsinit for portability"); +# endif +#endif + + +/* Convert a multibyte character to a wide character. */ +#if @GNULIB_MBRTOWC@ +# if @REPLACE_MBRTOWC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbrtowc +# define mbrtowc rpl_mbrtowc +# endif +_GL_FUNCDECL_RPL (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +# else +# if !@HAVE_MBRTOWC@ +_GL_FUNCDECL_SYS (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (mbrtowc); +#elif defined GNULIB_POSIXCHECK +# undef mbrtowc +# if HAVE_RAW_DECL_MBRTOWC +_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - " + "use gnulib module mbrtowc for portability"); +# endif +#endif + + +/* Recognize a multibyte character. */ +#if @GNULIB_MBRLEN@ +# if @REPLACE_MBRLEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbrlen +# define mbrlen rpl_mbrlen +# endif +_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +# else +# if !@HAVE_MBRLEN@ +_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (mbrlen); +#elif defined GNULIB_POSIXCHECK +# undef mbrlen +# if HAVE_RAW_DECL_MBRLEN +_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - " + "use gnulib module mbrlen for portability"); +# endif +#endif + + +/* Convert a string to a wide string. */ +#if @GNULIB_MBSRTOWCS@ +# if @REPLACE_MBSRTOWCS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsrtowcs +# define mbsrtowcs rpl_mbsrtowcs +# endif +_GL_FUNCDECL_RPL (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_MBSRTOWCS@ +_GL_FUNCDECL_SYS (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, + mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (mbsrtowcs); +#elif defined GNULIB_POSIXCHECK +# undef mbsrtowcs +# if HAVE_RAW_DECL_MBSRTOWCS +_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - " + "use gnulib module mbsrtowcs for portability"); +# endif +#endif + + +/* Convert a string to a wide string. */ +#if @GNULIB_MBSNRTOWCS@ +# if @REPLACE_MBSNRTOWCS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsnrtowcs +# define mbsnrtowcs rpl_mbsnrtowcs +# endif +_GL_FUNCDECL_RPL (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_MBSNRTOWCS@ +_GL_FUNCDECL_SYS (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (mbsnrtowcs); +#elif defined GNULIB_POSIXCHECK +# undef mbsnrtowcs +# if HAVE_RAW_DECL_MBSNRTOWCS +_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - " + "use gnulib module mbsnrtowcs for portability"); +# endif +#endif + + +/* Convert a wide character to a multibyte character. */ +#if @GNULIB_WCRTOMB@ +# if @REPLACE_WCRTOMB@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcrtomb +# define wcrtomb rpl_wcrtomb +# endif +_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +# else +# if !@HAVE_WCRTOMB@ +_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (wcrtomb); +#elif defined GNULIB_POSIXCHECK +# undef wcrtomb +# if HAVE_RAW_DECL_WCRTOMB +_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - " + "use gnulib module wcrtomb for portability"); +# endif +#endif + + +/* Convert a wide string to a string. */ +#if @GNULIB_WCSRTOMBS@ +# if @REPLACE_WCSRTOMBS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsrtombs +# define wcsrtombs rpl_wcsrtombs +# endif +_GL_FUNCDECL_RPL (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_WCSRTOMBS@ +_GL_FUNCDECL_SYS (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, + mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (wcsrtombs); +#elif defined GNULIB_POSIXCHECK +# undef wcsrtombs +# if HAVE_RAW_DECL_WCSRTOMBS +_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - " + "use gnulib module wcsrtombs for portability"); +# endif +#endif + + +/* Convert a wide string to a string. */ +#if @GNULIB_WCSNRTOMBS@ +# if @REPLACE_WCSNRTOMBS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsnrtombs +# define wcsnrtombs rpl_wcsnrtombs +# endif +_GL_FUNCDECL_RPL (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_WCSNRTOMBS@ +_GL_FUNCDECL_SYS (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# endif +_GL_CXXALIASWARN (wcsnrtombs); +#elif defined GNULIB_POSIXCHECK +# undef wcsnrtombs +# if HAVE_RAW_DECL_WCSNRTOMBS +_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - " + "use gnulib module wcsnrtombs for portability"); +# endif +#endif + + +/* Return the number of screen columns needed for WC. */ +#if @GNULIB_WCWIDTH@ +# if @REPLACE_WCWIDTH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcwidth +# define wcwidth rpl_wcwidth +# endif +_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t) _GL_ATTRIBUTE_PURE); +_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t)); +# else +# if !@HAVE_DECL_WCWIDTH@ +/* wcwidth exists but is not declared. */ +_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t) _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t)); +# endif +_GL_CXXALIASWARN (wcwidth); +#elif defined GNULIB_POSIXCHECK +# undef wcwidth +# if HAVE_RAW_DECL_WCWIDTH +_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - " + "use gnulib module wcwidth for portability"); +# endif +#endif + + +/* Search N wide characters of S for C. */ +#if @GNULIB_WMEMCHR@ +# if !@HAVE_WMEMCHR@ +_GL_FUNCDECL_SYS (wmemchr, wchar_t *, (const wchar_t *s, wchar_t c, size_t n) + _GL_ATTRIBUTE_PURE); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { + const wchar_t * std::wmemchr (const wchar_t *, wchar_t, size_t); + wchar_t * std::wmemchr (wchar_t *, wchar_t, size_t); + } */ +_GL_CXXALIAS_SYS_CAST2 (wmemchr, + wchar_t *, (const wchar_t *, wchar_t, size_t), + const wchar_t *, (const wchar_t *, wchar_t, size_t)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); +_GL_CXXALIASWARN1 (wmemchr, const wchar_t *, + (const wchar_t *s, wchar_t c, size_t n)); +# else +_GL_CXXALIASWARN (wmemchr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef wmemchr +# if HAVE_RAW_DECL_WMEMCHR +_GL_WARN_ON_USE (wmemchr, "wmemchr is unportable - " + "use gnulib module wmemchr for portability"); +# endif +#endif + + +/* Compare N wide characters of S1 and S2. */ +#if @GNULIB_WMEMCMP@ +# if !@HAVE_WMEMCMP@ +_GL_FUNCDECL_SYS (wmemcmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wmemcmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n)); +_GL_CXXALIASWARN (wmemcmp); +#elif defined GNULIB_POSIXCHECK +# undef wmemcmp +# if HAVE_RAW_DECL_WMEMCMP +_GL_WARN_ON_USE (wmemcmp, "wmemcmp is unportable - " + "use gnulib module wmemcmp for portability"); +# endif +#endif + + +/* Copy N wide characters of SRC to DEST. */ +#if @GNULIB_WMEMCPY@ +# if !@HAVE_WMEMCPY@ +_GL_FUNCDECL_SYS (wmemcpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wmemcpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wmemcpy); +#elif defined GNULIB_POSIXCHECK +# undef wmemcpy +# if HAVE_RAW_DECL_WMEMCPY +_GL_WARN_ON_USE (wmemcpy, "wmemcpy is unportable - " + "use gnulib module wmemcpy for portability"); +# endif +#endif + + +/* Copy N wide characters of SRC to DEST, guaranteeing correct behavior for + overlapping memory areas. */ +#if @GNULIB_WMEMMOVE@ +# if !@HAVE_WMEMMOVE@ +_GL_FUNCDECL_SYS (wmemmove, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wmemmove, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wmemmove); +#elif defined GNULIB_POSIXCHECK +# undef wmemmove +# if HAVE_RAW_DECL_WMEMMOVE +_GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - " + "use gnulib module wmemmove for portability"); +# endif +#endif + + +/* Set N wide characters of S to C. */ +#if @GNULIB_WMEMSET@ +# if !@HAVE_WMEMSET@ +_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); +# endif +_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); +_GL_CXXALIASWARN (wmemset); +#elif defined GNULIB_POSIXCHECK +# undef wmemset +# if HAVE_RAW_DECL_WMEMSET +_GL_WARN_ON_USE (wmemset, "wmemset is unportable - " + "use gnulib module wmemset for portability"); +# endif +#endif + + +/* Return the number of wide characters in S. */ +#if @GNULIB_WCSLEN@ +# if !@HAVE_WCSLEN@ +_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s) _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s)); +_GL_CXXALIASWARN (wcslen); +#elif defined GNULIB_POSIXCHECK +# undef wcslen +# if HAVE_RAW_DECL_WCSLEN +_GL_WARN_ON_USE (wcslen, "wcslen is unportable - " + "use gnulib module wcslen for portability"); +# endif +#endif + + +/* Return the number of wide characters in S, but at most MAXLEN. */ +#if @GNULIB_WCSNLEN@ +# if !@HAVE_WCSNLEN@ +_GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen)); +_GL_CXXALIASWARN (wcsnlen); +#elif defined GNULIB_POSIXCHECK +# undef wcsnlen +# if HAVE_RAW_DECL_WCSNLEN +_GL_WARN_ON_USE (wcsnlen, "wcsnlen is unportable - " + "use gnulib module wcsnlen for portability"); +# endif +#endif + + +/* Copy SRC to DEST. */ +#if @GNULIB_WCSCPY@ +# if !@HAVE_WCSCPY@ +_GL_FUNCDECL_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); +# endif +_GL_CXXALIAS_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); +_GL_CXXALIASWARN (wcscpy); +#elif defined GNULIB_POSIXCHECK +# undef wcscpy +# if HAVE_RAW_DECL_WCSCPY +_GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - " + "use gnulib module wcscpy for portability"); +# endif +#endif + + +/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */ +#if @GNULIB_WCPCPY@ +# if !@HAVE_WCPCPY@ +_GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); +# endif +_GL_CXXALIAS_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); +_GL_CXXALIASWARN (wcpcpy); +#elif defined GNULIB_POSIXCHECK +# undef wcpcpy +# if HAVE_RAW_DECL_WCPCPY +_GL_WARN_ON_USE (wcpcpy, "wcpcpy is unportable - " + "use gnulib module wcpcpy for portability"); +# endif +#endif + + +/* Copy no more than N wide characters of SRC to DEST. */ +#if @GNULIB_WCSNCPY@ +# if !@HAVE_WCSNCPY@ +_GL_FUNCDECL_SYS (wcsncpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wcsncpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wcsncpy); +#elif defined GNULIB_POSIXCHECK +# undef wcsncpy +# if HAVE_RAW_DECL_WCSNCPY +_GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - " + "use gnulib module wcsncpy for portability"); +# endif +#endif + + +/* Copy no more than N characters of SRC to DEST, returning the address of + the last character written into DEST. */ +#if @GNULIB_WCPNCPY@ +# if !@HAVE_WCPNCPY@ +_GL_FUNCDECL_SYS (wcpncpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wcpncpy, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wcpncpy); +#elif defined GNULIB_POSIXCHECK +# undef wcpncpy +# if HAVE_RAW_DECL_WCPNCPY +_GL_WARN_ON_USE (wcpncpy, "wcpncpy is unportable - " + "use gnulib module wcpncpy for portability"); +# endif +#endif + + +/* Append SRC onto DEST. */ +#if @GNULIB_WCSCAT@ +# if !@HAVE_WCSCAT@ +_GL_FUNCDECL_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); +# endif +_GL_CXXALIAS_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); +_GL_CXXALIASWARN (wcscat); +#elif defined GNULIB_POSIXCHECK +# undef wcscat +# if HAVE_RAW_DECL_WCSCAT +_GL_WARN_ON_USE (wcscat, "wcscat is unportable - " + "use gnulib module wcscat for portability"); +# endif +#endif + + +/* Append no more than N wide characters of SRC onto DEST. */ +#if @GNULIB_WCSNCAT@ +# if !@HAVE_WCSNCAT@ +_GL_FUNCDECL_SYS (wcsncat, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +# endif +_GL_CXXALIAS_SYS (wcsncat, wchar_t *, + (wchar_t *dest, const wchar_t *src, size_t n)); +_GL_CXXALIASWARN (wcsncat); +#elif defined GNULIB_POSIXCHECK +# undef wcsncat +# if HAVE_RAW_DECL_WCSNCAT +_GL_WARN_ON_USE (wcsncat, "wcsncat is unportable - " + "use gnulib module wcsncat for portability"); +# endif +#endif + + +/* Compare S1 and S2. */ +#if @GNULIB_WCSCMP@ +# if !@HAVE_WCSCMP@ +_GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)); +_GL_CXXALIASWARN (wcscmp); +#elif defined GNULIB_POSIXCHECK +# undef wcscmp +# if HAVE_RAW_DECL_WCSCMP +_GL_WARN_ON_USE (wcscmp, "wcscmp is unportable - " + "use gnulib module wcscmp for portability"); +# endif +#endif + + +/* Compare no more than N wide characters of S1 and S2. */ +#if @GNULIB_WCSNCMP@ +# if !@HAVE_WCSNCMP@ +_GL_FUNCDECL_SYS (wcsncmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcsncmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n)); +_GL_CXXALIASWARN (wcsncmp); +#elif defined GNULIB_POSIXCHECK +# undef wcsncmp +# if HAVE_RAW_DECL_WCSNCMP +_GL_WARN_ON_USE (wcsncmp, "wcsncmp is unportable - " + "use gnulib module wcsncmp for portability"); +# endif +#endif + + +/* Compare S1 and S2, ignoring case. */ +#if @GNULIB_WCSCASECMP@ +# if !@HAVE_WCSCASECMP@ +_GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2)); +_GL_CXXALIASWARN (wcscasecmp); +#elif defined GNULIB_POSIXCHECK +# undef wcscasecmp +# if HAVE_RAW_DECL_WCSCASECMP +_GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - " + "use gnulib module wcscasecmp for portability"); +# endif +#endif + + +/* Compare no more than N chars of S1 and S2, ignoring case. */ +#if @GNULIB_WCSNCASECMP@ +# if !@HAVE_WCSNCASECMP@ +_GL_FUNCDECL_SYS (wcsncasecmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcsncasecmp, int, + (const wchar_t *s1, const wchar_t *s2, size_t n)); +_GL_CXXALIASWARN (wcsncasecmp); +#elif defined GNULIB_POSIXCHECK +# undef wcsncasecmp +# if HAVE_RAW_DECL_WCSNCASECMP +_GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - " + "use gnulib module wcsncasecmp for portability"); +# endif +#endif + + +/* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE + category of the current locale. */ +#if @GNULIB_WCSCOLL@ +# if !@HAVE_WCSCOLL@ +_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); +# endif +_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); +_GL_CXXALIASWARN (wcscoll); +#elif defined GNULIB_POSIXCHECK +# undef wcscoll +# if HAVE_RAW_DECL_WCSCOLL +_GL_WARN_ON_USE (wcscoll, "wcscoll is unportable - " + "use gnulib module wcscoll for portability"); +# endif +#endif + + +/* Transform S2 into array pointed to by S1 such that if wcscmp is applied + to two transformed strings the result is the as applying 'wcscoll' to the + original strings. */ +#if @GNULIB_WCSXFRM@ +# if !@HAVE_WCSXFRM@ +_GL_FUNCDECL_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); +# endif +_GL_CXXALIAS_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); +_GL_CXXALIASWARN (wcsxfrm); +#elif defined GNULIB_POSIXCHECK +# undef wcsxfrm +# if HAVE_RAW_DECL_WCSXFRM +_GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - " + "use gnulib module wcsxfrm for portability"); +# endif +#endif + + +/* Duplicate S, returning an identical malloc'd string. */ +#if @GNULIB_WCSDUP@ +# if !@HAVE_WCSDUP@ +_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s)); +# endif +_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); +_GL_CXXALIASWARN (wcsdup); +#elif defined GNULIB_POSIXCHECK +# undef wcsdup +# if HAVE_RAW_DECL_WCSDUP +_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " + "use gnulib module wcsdup for portability"); +# endif +#endif + + +/* Find the first occurrence of WC in WCS. */ +#if @GNULIB_WCSCHR@ +# if !@HAVE_WCSCHR@ +_GL_FUNCDECL_SYS (wcschr, wchar_t *, (const wchar_t *wcs, wchar_t wc) + _GL_ATTRIBUTE_PURE); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { + const wchar_t * std::wcschr (const wchar_t *, wchar_t); + wchar_t * std::wcschr (wchar_t *, wchar_t); + } */ +_GL_CXXALIAS_SYS_CAST2 (wcschr, + wchar_t *, (const wchar_t *, wchar_t), + const wchar_t *, (const wchar_t *, wchar_t)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc)); +_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc)); +# else +_GL_CXXALIASWARN (wcschr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef wcschr +# if HAVE_RAW_DECL_WCSCHR +_GL_WARN_ON_USE (wcschr, "wcschr is unportable - " + "use gnulib module wcschr for portability"); +# endif +#endif + + +/* Find the last occurrence of WC in WCS. */ +#if @GNULIB_WCSRCHR@ +# if !@HAVE_WCSRCHR@ +_GL_FUNCDECL_SYS (wcsrchr, wchar_t *, (const wchar_t *wcs, wchar_t wc) + _GL_ATTRIBUTE_PURE); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { + const wchar_t * std::wcsrchr (const wchar_t *, wchar_t); + wchar_t * std::wcsrchr (wchar_t *, wchar_t); + } */ +_GL_CXXALIAS_SYS_CAST2 (wcsrchr, + wchar_t *, (const wchar_t *, wchar_t), + const wchar_t *, (const wchar_t *, wchar_t)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc)); +_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc)); +# else +_GL_CXXALIASWARN (wcsrchr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef wcsrchr +# if HAVE_RAW_DECL_WCSRCHR +_GL_WARN_ON_USE (wcsrchr, "wcsrchr is unportable - " + "use gnulib module wcsrchr for portability"); +# endif +#endif + + +/* Return the length of the initial segmet of WCS which consists entirely + of wide characters not in REJECT. */ +#if @GNULIB_WCSCSPN@ +# if !@HAVE_WCSCSPN@ +_GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject)); +_GL_CXXALIASWARN (wcscspn); +#elif defined GNULIB_POSIXCHECK +# undef wcscspn +# if HAVE_RAW_DECL_WCSCSPN +_GL_WARN_ON_USE (wcscspn, "wcscspn is unportable - " + "use gnulib module wcscspn for portability"); +# endif +#endif + + +/* Return the length of the initial segmet of WCS which consists entirely + of wide characters in ACCEPT. */ +#if @GNULIB_WCSSPN@ +# if !@HAVE_WCSSPN@ +_GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)); +_GL_CXXALIASWARN (wcsspn); +#elif defined GNULIB_POSIXCHECK +# undef wcsspn +# if HAVE_RAW_DECL_WCSSPN +_GL_WARN_ON_USE (wcsspn, "wcsspn is unportable - " + "use gnulib module wcsspn for portability"); +# endif +#endif + + +/* Find the first occurrence in WCS of any character in ACCEPT. */ +#if @GNULIB_WCSPBRK@ +# if !@HAVE_WCSPBRK@ +_GL_FUNCDECL_SYS (wcspbrk, wchar_t *, + (const wchar_t *wcs, const wchar_t *accept) + _GL_ATTRIBUTE_PURE); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { + const wchar_t * std::wcspbrk (const wchar_t *, const wchar_t *); + wchar_t * std::wcspbrk (wchar_t *, const wchar_t *); + } */ +_GL_CXXALIAS_SYS_CAST2 (wcspbrk, + wchar_t *, (const wchar_t *, const wchar_t *), + const wchar_t *, (const wchar_t *, const wchar_t *)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (wcspbrk, wchar_t *, + (wchar_t *wcs, const wchar_t *accept)); +_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *, + (const wchar_t *wcs, const wchar_t *accept)); +# else +_GL_CXXALIASWARN (wcspbrk); +# endif +#elif defined GNULIB_POSIXCHECK +# undef wcspbrk +# if HAVE_RAW_DECL_WCSPBRK +_GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - " + "use gnulib module wcspbrk for portability"); +# endif +#endif + + +/* Find the first occurrence of NEEDLE in HAYSTACK. */ +#if @GNULIB_WCSSTR@ +# if !@HAVE_WCSSTR@ +_GL_FUNCDECL_SYS (wcsstr, wchar_t *, + (const wchar_t *haystack, const wchar_t *needle) + _GL_ATTRIBUTE_PURE); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { + const wchar_t * std::wcsstr (const wchar_t *, const wchar_t *); + wchar_t * std::wcsstr (wchar_t *, const wchar_t *); + } */ +_GL_CXXALIAS_SYS_CAST2 (wcsstr, + wchar_t *, (const wchar_t *, const wchar_t *), + const wchar_t *, (const wchar_t *, const wchar_t *)); +# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (wcsstr, wchar_t *, + (wchar_t *haystack, const wchar_t *needle)); +_GL_CXXALIASWARN1 (wcsstr, const wchar_t *, + (const wchar_t *haystack, const wchar_t *needle)); +# else +_GL_CXXALIASWARN (wcsstr); +# endif +#elif defined GNULIB_POSIXCHECK +# undef wcsstr +# if HAVE_RAW_DECL_WCSSTR +_GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - " + "use gnulib module wcsstr for portability"); +# endif +#endif + + +/* Divide WCS into tokens separated by characters in DELIM. */ +#if @GNULIB_WCSTOK@ +# if !@HAVE_WCSTOK@ +_GL_FUNCDECL_SYS (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +# endif +_GL_CXXALIAS_SYS (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +_GL_CXXALIASWARN (wcstok); +#elif defined GNULIB_POSIXCHECK +# undef wcstok +# if HAVE_RAW_DECL_WCSTOK +_GL_WARN_ON_USE (wcstok, "wcstok is unportable - " + "use gnulib module wcstok for portability"); +# endif +#endif + + +/* Determine number of column positions required for first N wide + characters (or fewer if S ends before this) in S. */ +#if @GNULIB_WCSWIDTH@ +# if @REPLACE_WCSWIDTH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcswidth +# define wcswidth rpl_wcswidth +# endif +_GL_FUNCDECL_RPL (wcswidth, int, (const wchar_t *s, size_t n) + _GL_ATTRIBUTE_PURE); +_GL_CXXALIAS_RPL (wcswidth, int, (const wchar_t *s, size_t n)); +# else +# if !@HAVE_WCSWIDTH@ +_GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n) + _GL_ATTRIBUTE_PURE); +# endif +_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n)); +# endif +_GL_CXXALIASWARN (wcswidth); +#elif defined GNULIB_POSIXCHECK +# undef wcswidth +# if HAVE_RAW_DECL_WCSWIDTH +_GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - " + "use gnulib module wcswidth for portability"); +# endif +#endif + + +#endif /* _@GUARD_PREFIX@_WCHAR_H */ +#endif /* _@GUARD_PREFIX@_WCHAR_H */ +#endif diff --git a/grub-core/gnulib/wcrtomb.c b/grub-core/gnulib/wcrtomb.c new file mode 100644 index 000000000..da42809bc --- /dev/null +++ b/grub-core/gnulib/wcrtomb.c @@ -0,0 +1,53 @@ +/* Convert wide character to multibyte character. + Copyright (C) 2008-2013 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include +#include + + +size_t +wcrtomb (char *s, wchar_t wc, mbstate_t *ps) +{ + /* This implementation of wcrtomb on top of wctomb() supports only + stateless encodings. ps must be in the initial state. */ + if (ps != NULL && !mbsinit (ps)) + { + errno = EINVAL; + return (size_t)(-1); + } + + if (s == NULL) + /* We know the NUL wide character corresponds to the NUL character. */ + return 1; + else + { + int ret = wctomb (s, wc); + + if (ret >= 0) + return ret; + else + { + errno = EILSEQ; + return (size_t)(-1); + } + } +} diff --git a/grub-core/gnulib/wctype-h.c b/grub-core/gnulib/wctype-h.c new file mode 100644 index 000000000..bb5f847e3 --- /dev/null +++ b/grub-core/gnulib/wctype-h.c @@ -0,0 +1,4 @@ +/* Normally this would be wctype.c, but that name's already taken. */ +#include +#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE +#include "wctype.h" diff --git a/grub-core/gnulib/wctype.in.h b/grub-core/gnulib/wctype.in.h new file mode 100644 index 000000000..0cd02d5a3 --- /dev/null +++ b/grub-core/gnulib/wctype.in.h @@ -0,0 +1,504 @@ +/* A substitute for ISO C99 , for platforms that lack it. + + Copyright (C) 2006-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible and Paul Eggert. */ + +/* + * ISO C 99 for platforms that lack it. + * + * + * iswctype, towctrans, towlower, towupper, wctrans, wctype, + * wctrans_t, and wctype_t are not yet implemented. + */ + +#ifndef _@GUARD_PREFIX@_WCTYPE_H + +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ + +#if @HAVE_WINT_T@ +/* Solaris 2.5 has a bug: must be included before . + Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +# include +# include +# include +# include +#endif + +/* Include the original if it exists. + BeOS 5 has the functions but no . */ +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_WCTYPE_H@ +# @INCLUDE_NEXT@ @NEXT_WCTYPE_H@ +#endif + +#ifndef _@GUARD_PREFIX@_WCTYPE_H +#define _@GUARD_PREFIX@_WCTYPE_H + +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_WCTYPE_INLINE +# define _GL_WCTYPE_INLINE _GL_INLINE +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* Solaris 2.6 includes which includes which + #defines a number of identifiers in the application namespace. Revert + these #defines. */ +#ifdef __sun +# undef multibyte +# undef eucw1 +# undef eucw2 +# undef eucw3 +# undef scrw1 +# undef scrw2 +# undef scrw3 +#endif + +/* Define wint_t and WEOF. (Also done in wchar.in.h.) */ +#if !@HAVE_WINT_T@ && !defined wint_t +# define wint_t int +# ifndef WEOF +# define WEOF -1 +# endif +#else +/* MSVC defines wint_t as 'unsigned short' in . + This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be + "unchanged by default argument promotions". Override it. */ +# if defined _MSC_VER +# if !GNULIB_defined_wint_t +# include +typedef unsigned int rpl_wint_t; +# undef wint_t +# define wint_t rpl_wint_t +# define GNULIB_defined_wint_t 1 +# endif +# endif +# ifndef WEOF +# define WEOF ((wint_t) -1) +# endif +#endif + + +#if !GNULIB_defined_wctype_functions + +/* FreeBSD 4.4 to 4.11 has but lacks the functions. + Linux libc5 has and the functions but they are broken. + Assume all 11 functions (all isw* except iswblank) are implemented the + same way, or not at all. */ +# if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ + +/* IRIX 5.3 has macros but no functions, its isw* macros refer to an + undefined variable _ctmp_ and to macros like _P, and they + refer to system functions like _iswctype that are not in the + standard C library. Rather than try to get ancient buggy + implementations like this to work, just disable them. */ +# undef iswalnum +# undef iswalpha +# undef iswblank +# undef iswcntrl +# undef iswdigit +# undef iswgraph +# undef iswlower +# undef iswprint +# undef iswpunct +# undef iswspace +# undef iswupper +# undef iswxdigit +# undef towlower +# undef towupper + +/* Linux libc5 has and the functions but they are broken. */ +# if @REPLACE_ISWCNTRL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define iswalnum rpl_iswalnum +# define iswalpha rpl_iswalpha +# define iswblank rpl_iswblank +# define iswcntrl rpl_iswcntrl +# define iswdigit rpl_iswdigit +# define iswgraph rpl_iswgraph +# define iswlower rpl_iswlower +# define iswprint rpl_iswprint +# define iswpunct rpl_iswpunct +# define iswspace rpl_iswspace +# define iswupper rpl_iswupper +# define iswxdigit rpl_iswxdigit +# endif +# endif +# if @REPLACE_TOWLOWER@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define towlower rpl_towlower +# define towupper rpl_towupper +# endif +# endif + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswalnum +# else +iswalnum +# endif + (wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswalpha +# else +iswalpha +# endif + (wint_t wc) +{ + return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswblank +# else +iswblank +# endif + (wint_t wc) +{ + return wc == ' ' || wc == '\t'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswcntrl +# else +iswcntrl +# endif + (wint_t wc) +{ + return (wc & ~0x1f) == 0 || wc == 0x7f; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswdigit +# else +iswdigit +# endif + (wint_t wc) +{ + return wc >= '0' && wc <= '9'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswgraph +# else +iswgraph +# endif + (wint_t wc) +{ + return wc >= '!' && wc <= '~'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswlower +# else +iswlower +# endif + (wint_t wc) +{ + return wc >= 'a' && wc <= 'z'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswprint +# else +iswprint +# endif + (wint_t wc) +{ + return wc >= ' ' && wc <= '~'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswpunct +# else +iswpunct +# endif + (wint_t wc) +{ + return (wc >= '!' && wc <= '~' + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswspace +# else +iswspace +# endif + (wint_t wc) +{ + return (wc == ' ' || wc == '\t' + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswupper +# else +iswupper +# endif + (wint_t wc) +{ + return wc >= 'A' && wc <= 'Z'; +} + +_GL_WCTYPE_INLINE int +# if @REPLACE_ISWCNTRL@ +rpl_iswxdigit +# else +iswxdigit +# endif + (wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); +} + +_GL_WCTYPE_INLINE wint_t +# if @REPLACE_TOWLOWER@ +rpl_towlower +# else +towlower +# endif + (wint_t wc) +{ + return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc); +} + +_GL_WCTYPE_INLINE wint_t +# if @REPLACE_TOWLOWER@ +rpl_towupper +# else +towupper +# endif + (wint_t wc) +{ + return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc); +} + +# elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@) +/* Only the iswblank function is missing. */ + +# if @REPLACE_ISWBLANK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define iswblank rpl_iswblank +# endif +_GL_FUNCDECL_RPL (iswblank, int, (wint_t wc)); +# else +_GL_FUNCDECL_SYS (iswblank, int, (wint_t wc)); +# endif + +# endif + +# if defined __MINGW32__ + +/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t. + The functions towlower and towupper are implemented in the MSVCRT library + to take a wchar_t argument and return a wchar_t result. mingw declares + these functions to take a wint_t argument and return a wint_t result. + This means that: + 1. When the user passes an argument outside the range 0x0000..0xFFFF, the + function will look only at the lower 16 bits. This is allowed according + to POSIX. + 2. The return value is returned in the lower 16 bits of the result register. + The upper 16 bits are random: whatever happened to be in that part of the + result register. We need to fix this by adding a zero-extend from + wchar_t to wint_t after the call. */ + +_GL_WCTYPE_INLINE wint_t +rpl_towlower (wint_t wc) +{ + return (wint_t) (wchar_t) towlower (wc); +} +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define towlower rpl_towlower +# endif + +_GL_WCTYPE_INLINE wint_t +rpl_towupper (wint_t wc) +{ + return (wint_t) (wchar_t) towupper (wc); +} +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define towupper rpl_towupper +# endif + +# endif /* __MINGW32__ */ + +# define GNULIB_defined_wctype_functions 1 +#endif + +#if @REPLACE_ISWCNTRL@ +_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc)); +#else +_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc)); +#endif +_GL_CXXALIASWARN (iswalnum); +_GL_CXXALIASWARN (iswalpha); +_GL_CXXALIASWARN (iswcntrl); +_GL_CXXALIASWARN (iswdigit); +_GL_CXXALIASWARN (iswgraph); +_GL_CXXALIASWARN (iswlower); +_GL_CXXALIASWARN (iswprint); +_GL_CXXALIASWARN (iswpunct); +_GL_CXXALIASWARN (iswspace); +_GL_CXXALIASWARN (iswupper); +_GL_CXXALIASWARN (iswxdigit); + +#if @GNULIB_ISWBLANK@ +# if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@ +_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc)); +# else +_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc)); +# endif +_GL_CXXALIASWARN (iswblank); +#endif + +#if !@HAVE_WCTYPE_T@ +# if !GNULIB_defined_wctype_t +typedef void * wctype_t; +# define GNULIB_defined_wctype_t 1 +# endif +#endif + +/* Get a descriptor for a wide character property. */ +#if @GNULIB_WCTYPE@ +# if !@HAVE_WCTYPE_T@ +_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name)); +# endif +_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name)); +_GL_CXXALIASWARN (wctype); +#elif defined GNULIB_POSIXCHECK +# undef wctype +# if HAVE_RAW_DECL_WCTYPE +_GL_WARN_ON_USE (wctype, "wctype is unportable - " + "use gnulib module wctype for portability"); +# endif +#endif + +/* Test whether a wide character has a given property. + The argument WC must be either a wchar_t value or WEOF. + The argument DESC must have been returned by the wctype() function. */ +#if @GNULIB_ISWCTYPE@ +# if !@HAVE_WCTYPE_T@ +_GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc)); +# endif +_GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc)); +_GL_CXXALIASWARN (iswctype); +#elif defined GNULIB_POSIXCHECK +# undef iswctype +# if HAVE_RAW_DECL_ISWCTYPE +_GL_WARN_ON_USE (iswctype, "iswctype is unportable - " + "use gnulib module iswctype for portability"); +# endif +#endif + +#if @REPLACE_TOWLOWER@ || defined __MINGW32__ +_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc)); +_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc)); +#else +_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc)); +_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc)); +#endif +_GL_CXXALIASWARN (towlower); +_GL_CXXALIASWARN (towupper); + +#if !@HAVE_WCTRANS_T@ +# if !GNULIB_defined_wctrans_t +typedef void * wctrans_t; +# define GNULIB_defined_wctrans_t 1 +# endif +#endif + +/* Get a descriptor for a wide character case conversion. */ +#if @GNULIB_WCTRANS@ +# if !@HAVE_WCTRANS_T@ +_GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name)); +# endif +_GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name)); +_GL_CXXALIASWARN (wctrans); +#elif defined GNULIB_POSIXCHECK +# undef wctrans +# if HAVE_RAW_DECL_WCTRANS +_GL_WARN_ON_USE (wctrans, "wctrans is unportable - " + "use gnulib module wctrans for portability"); +# endif +#endif + +/* Perform a given case conversion on a wide character. + The argument WC must be either a wchar_t value or WEOF. + The argument DESC must have been returned by the wctrans() function. */ +#if @GNULIB_TOWCTRANS@ +# if !@HAVE_WCTRANS_T@ +_GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc)); +# endif +_GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc)); +_GL_CXXALIASWARN (towctrans); +#elif defined GNULIB_POSIXCHECK +# undef towctrans +# if HAVE_RAW_DECL_TOWCTRANS +_GL_WARN_ON_USE (towctrans, "towctrans is unportable - " + "use gnulib module towctrans for portability"); +# endif +#endif + +_GL_INLINE_HEADER_END + +#endif /* _@GUARD_PREFIX@_WCTYPE_H */ +#endif /* _@GUARD_PREFIX@_WCTYPE_H */ diff --git a/grub-core/gnulib/wcwidth.c b/grub-core/gnulib/wcwidth.c new file mode 100644 index 000000000..253fcaa65 --- /dev/null +++ b/grub-core/gnulib/wcwidth.c @@ -0,0 +1,50 @@ +/* Determine the number of screen columns needed for a character. + Copyright (C) 2006-2007, 2010-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +/* Get iswprint. */ +#include + +#include "localcharset.h" +#include "streq.h" +#include "uniwidth.h" + +int +wcwidth (wchar_t wc) +#undef wcwidth +{ + /* In UTF-8 locales, use a Unicode aware width function. */ + const char *encoding = locale_charset (); + if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0)) + { + /* We assume that in a UTF-8 locale, a wide character is the same as a + Unicode character. */ + return uc_width (wc, encoding); + } + else + { + /* Otherwise, fall back to the system's wcwidth function. */ +#if HAVE_WCWIDTH + return wcwidth (wc); +#else + return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; +#endif + } +} diff --git a/grub-core/gnulib/xsize.c b/grub-core/gnulib/xsize.c new file mode 100644 index 000000000..4b4914c2c --- /dev/null +++ b/grub-core/gnulib/xsize.c @@ -0,0 +1,3 @@ +#include +#define XSIZE_INLINE _GL_EXTERN_INLINE +#include "xsize.h" diff --git a/grub-core/gnulib/xsize.h b/grub-core/gnulib/xsize.h new file mode 100644 index 000000000..2922f3530 --- /dev/null +++ b/grub-core/gnulib/xsize.h @@ -0,0 +1,114 @@ +/* xsize.h -- Checked size_t computations. + + Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef _XSIZE_H +#define _XSIZE_H + +/* Get size_t. */ +#include + +/* Get SIZE_MAX. */ +#include +#if HAVE_STDINT_H +# include +#endif + +_GL_INLINE_HEADER_BEGIN +#ifndef XSIZE_INLINE +# define XSIZE_INLINE _GL_INLINE +#endif + +/* The size of memory objects is often computed through expressions of + type size_t. Example: + void* p = malloc (header_size + n * element_size). + These computations can lead to overflow. When this happens, malloc() + returns a piece of memory that is way too small, and the program then + crashes while attempting to fill the memory. + To avoid this, the functions and macros in this file check for overflow. + The convention is that SIZE_MAX represents overflow. + malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc + implementation that uses mmap --, it's recommended to use size_overflow_p() + or size_in_bounds_p() before invoking malloc(). + The example thus becomes: + size_t size = xsum (header_size, xtimes (n, element_size)); + void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); +*/ + +/* Convert an arbitrary value >= 0 to type size_t. */ +#define xcast_size_t(N) \ + ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) + +/* Sum of two sizes, with overflow check. */ +XSIZE_INLINE size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum (size_t size1, size_t size2) +{ + size_t sum = size1 + size2; + return (sum >= size1 ? sum : SIZE_MAX); +} + +/* Sum of three sizes, with overflow check. */ +XSIZE_INLINE size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum3 (size_t size1, size_t size2, size_t size3) +{ + return xsum (xsum (size1, size2), size3); +} + +/* Sum of four sizes, with overflow check. */ +XSIZE_INLINE size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) +{ + return xsum (xsum (xsum (size1, size2), size3), size4); +} + +/* Maximum of two sizes, with overflow check. */ +XSIZE_INLINE size_t +#if __GNUC__ >= 3 +__attribute__ ((__pure__)) +#endif +xmax (size_t size1, size_t size2) +{ + /* No explicit check is needed here, because for any n: + max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ + return (size1 >= size2 ? size1 : size2); +} + +/* Multiplication of a count with an element size, with overflow check. + The count must be >= 0 and the element size must be > 0. + This is a macro, not a function, so that it works correctly even + when N is of a wider type and N > SIZE_MAX. */ +#define xtimes(N, ELSIZE) \ + ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) + +/* Check for overflow. */ +#define size_overflow_p(SIZE) \ + ((SIZE) == SIZE_MAX) +/* Check against overflow. */ +#define size_in_bounds_p(SIZE) \ + ((SIZE) != SIZE_MAX) + +_GL_INLINE_HEADER_END + +#endif /* _XSIZE_H */ diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index a458c3aca..22438277d 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -43,7 +43,7 @@ typedef struct grub_bufio *grub_bufio_t; static struct grub_fs grub_bufio_fs; grub_file_t -grub_bufio_open (grub_file_t io, grub_size_t size) +grub_bufio_open (grub_file_t io, int size) { grub_file_t file; grub_bufio_t bufio = 0; @@ -57,17 +57,10 @@ grub_bufio_open (grub_file_t io, grub_size_t size) else if (size > GRUB_BUFIO_MAX_SIZE) size = GRUB_BUFIO_MAX_SIZE; - if (size > io->size) + if ((size < 0) || ((unsigned) size > io->size)) size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE : io->size); - /* - * Round up size to power of 2 which the binary math to - * calculate next_buf in grub_bufio_read() requires. - */ - while (size & (size - 1)) - size = (size | (size - 1)) + 1; - bufio = grub_zalloc (sizeof (struct grub_bufio) + size); if (! bufio) { @@ -88,11 +81,11 @@ grub_bufio_open (grub_file_t io, grub_size_t size) } grub_file_t -grub_buffile_open (const char *name, enum grub_file_type type, grub_size_t size) +grub_buffile_open (const char *name, int size) { grub_file_t io, file; - io = grub_file_open (name, type); + io = grub_file_open (name); if (! io) return 0; @@ -205,10 +198,10 @@ grub_bufio_close (grub_file_t file) static struct grub_fs grub_bufio_fs = { .name = "bufio", - .fs_dir = 0, - .fs_open = 0, - .fs_read = grub_bufio_read, - .fs_close = grub_bufio_close, - .fs_label = 0, + .dir = 0, + .open = 0, + .read = grub_bufio_read, + .close = grub_bufio_close, + .label = 0, .next = 0 }; diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 43d98a7bd..129209e37 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -43,7 +43,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -95,14 +94,6 @@ struct grub_gzio struct huft *tl; /* The distance code table. */ struct huft *td; - /* The checksum algorithm */ - const gcry_md_spec_t *hdesc; - /* The wanted checksum */ - grub_uint32_t orig_checksum; - /* The uncompressed length */ - grub_size_t orig_len; - /* Context for checksum calculation */ - grub_uint8_t *hcontext; /* The lookup bits for the literal/length code table. */ int bl; /* The lookup bits for the distance code table. */ @@ -149,24 +140,24 @@ eat_field (grub_file_t file, int len) #define OLD_GZIP_MAGIC grub_le_to_cpu16 (0x9E1F) /* Compression methods (see algorithm.doc) */ -#define GRUB_GZ_STORED 0 -#define GRUB_GZ_COMPRESSED 1 -#define GRUB_GZ_PACKED 2 -#define GRUB_GZ_LZHED 3 +#define STORED 0 +#define COMPRESSED 1 +#define PACKED 2 +#define LZHED 3 /* methods 4 to 7 reserved */ -#define GRUB_GZ_DEFLATED 8 -#define GRUB_GZ_MAX_METHODS 9 +#define DEFLATED 8 +#define MAX_METHODS 9 /* gzip flag byte */ -#define GRUB_GZ_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define GRUB_GZ_CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ -#define GRUB_GZ_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define GRUB_GZ_ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define GRUB_GZ_COMMENT 0x10 /* bit 4 set: file comment present */ -#define GRUB_GZ_ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ -#define GRUB_GZ_RESERVED 0xC0 /* bit 6,7: reserved */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ +#define RESERVED 0xC0 /* bit 6,7: reserved */ -#define GRUB_GZ_UNSUPPORTED_FLAGS (GRUB_GZ_CONTINUATION | GRUB_GZ_ENCRYPTED | GRUB_GZ_RESERVED) +#define UNSUPPORTED_FLAGS (CONTINUATION | ENCRYPTED | RESERVED) /* inflate block codes */ #define INFLATE_STORED 0 @@ -189,7 +180,7 @@ test_gzip_header (grub_file_t file) grub_uint8_t os_type; } hdr; grub_uint16_t extra_len; - grub_uint32_t crc32; + grub_uint32_t orig_len; grub_gzio_t gzio = file->data; if (grub_file_tell (gzio->file) != 0) @@ -210,29 +201,26 @@ test_gzip_header (grub_file_t file) * problem occurs from here on, then we have corrupt or otherwise * bad data, and the error should be reported to the user. */ - if (hdr.method != GRUB_GZ_DEFLATED - || (hdr.flags & GRUB_GZ_UNSUPPORTED_FLAGS) - || ((hdr.flags & GRUB_GZ_EXTRA_FIELD) + if (hdr.method != DEFLATED + || (hdr.flags & UNSUPPORTED_FLAGS) + || ((hdr.flags & EXTRA_FIELD) && (grub_file_read (gzio->file, &extra_len, 2) != 2 || eat_field (gzio->file, grub_le_to_cpu16 (extra_len)))) - || ((hdr.flags & GRUB_GZ_ORIG_NAME) && eat_field (gzio->file, -1)) - || ((hdr.flags & GRUB_GZ_COMMENT) && eat_field (gzio->file, -1))) + || ((hdr.flags & ORIG_NAME) && eat_field (gzio->file, -1)) + || ((hdr.flags & COMMENT) && eat_field (gzio->file, -1))) return 0; gzio->data_offset = grub_file_tell (gzio->file); /* FIXME: don't do this on not easily seekable files. */ { - grub_file_seek (gzio->file, grub_file_size (gzio->file) - 8); - if (grub_file_read (gzio->file, &crc32, 4) != 4) - return 0; - gzio->orig_checksum = grub_le_to_cpu32 (crc32); - if (grub_file_read (gzio->file, &gzio->orig_len, 4) != 4) + grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4); + if (grub_file_read (gzio->file, &orig_len, 4) != 4) return 0; /* FIXME: this does not handle files whose original size is over 4GB. But how can we know the real original size? */ - file->size = grub_le_to_cpu32 (gzio->orig_len); + file->size = grub_le_to_cpu32 (orig_len); } initialize_tables (gzio); @@ -554,7 +542,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ z = 1 << j; /* table entries for j-bit table */ /* allocate and link in new table */ - q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); + q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); if (! q) { if (h) @@ -1107,23 +1095,7 @@ inflate_window (grub_gzio_t gzio) gzio->saved_offset += gzio->wp; - if (gzio->hcontext) - { - gzio->hdesc->write (gzio->hcontext, gzio->slide, gzio->wp); - - if (gzio->saved_offset == gzio->orig_len) - { - grub_uint32_t csum; - - gzio->hdesc->final (gzio->hcontext); - csum = grub_get_unaligned32 (gzio->hdesc->read (gzio->hcontext)); - csum = grub_be_to_cpu32 (csum); - if (csum != gzio->orig_checksum) - grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, - "checksum mismatch %08x/%08x", - gzio->orig_checksum, csum); - } - } + /* XXX do CRC calculation here! */ } @@ -1146,9 +1118,6 @@ initialize_tables (grub_gzio_t gzio) huft_free (gzio->td); gzio->tl = NULL; gzio->td = NULL; - - if (gzio->hcontext) - gzio->hdesc->init(gzio->hcontext); } @@ -1156,14 +1125,11 @@ initialize_tables (grub_gzio_t gzio) even if IO does not contain data compressed by gzip, return a valid file object. Note that this function won't close IO, even if an error occurs. */ static grub_file_t -grub_gzio_open (grub_file_t io, enum grub_file_type type) +grub_gzio_open (grub_file_t io, const char *name __attribute__ ((unused))) { grub_file_t file; grub_gzio_t gzio = 0; - if (type & GRUB_FILE_TYPE_NO_DECOMPRESS) - return io; - file = (grub_file_t) grub_zalloc (sizeof (*file)); if (! file) return 0; @@ -1177,9 +1143,6 @@ grub_gzio_open (grub_file_t io, enum grub_file_type type) gzio->file = io; - gzio->hdesc = GRUB_MD_CRC32; - gzio->hcontext = grub_malloc(gzio->hdesc->contextsize); - file->device = io->device; file->data = gzio; file->fs = &grub_gzio_fs; @@ -1188,7 +1151,6 @@ grub_gzio_open (grub_file_t io, enum grub_file_type type) if (! test_gzip_header (file)) { grub_errno = GRUB_ERR_NONE; - grub_free (gzio->hcontext); grub_free (gzio); grub_free (file); grub_file_seek (io, 0); @@ -1199,19 +1161,6 @@ grub_gzio_open (grub_file_t io, enum grub_file_type type) return file; } -static grub_uint8_t -mod_31 (grub_uint16_t v) -{ - /* At most 2 iterations for any number that - we can get here. - In any case faster than real division. */ - while (v > 0x1f) - v = (v & 0x1f) + (v >> 5); - if (v == 0x1f) - return 0; - return v; -} - static int test_zlib_header (grub_gzio_t gzio) { @@ -1221,7 +1170,7 @@ test_zlib_header (grub_gzio_t gzio) flg = get_byte (gzio); /* Check that compression method is DEFLATE. */ - if ((cmf & 0xf) != GRUB_GZ_DEFLATED) + if ((cmf & 0xf) != DEFLATED) { /* TRANSLATORS: It's about given file having some strange format, not complete lack of gzip support. */ @@ -1229,10 +1178,7 @@ test_zlib_header (grub_gzio_t gzio) return 0; } - /* Usually it would be: (cmf * 256 + flg) % 31 != 0. */ - /* But 256 == 8 (31). */ - /* By multiplying by 4 and using 32 == 1 (31). We get our formula. */ - if (mod_31 (cmf + flg * 4) != 0) + if ((cmf * 256U + flg) % 31U) { grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, N_("unsupported gzip format")); return 0; @@ -1325,7 +1271,6 @@ grub_gzio_close (grub_file_t file) grub_file_close (gzio->file); huft_free (gzio->tl); huft_free (gzio->td); - grub_free (gzio->hcontext); grub_free (gzio); /* No need to close the same device twice. */ @@ -1389,11 +1334,11 @@ grub_deflate_decompress (char *inbuf, grub_size_t insize, grub_off_t off, static struct grub_fs grub_gzio_fs = { .name = "gzio", - .fs_dir = 0, - .fs_open = 0, - .fs_read = grub_gzio_read, - .fs_close = grub_gzio_close, - .fs_label = 0, + .dir = 0, + .open = 0, + .read = grub_gzio_read, + .close = grub_gzio_close, + .label = 0, .next = 0 }; diff --git a/grub-core/io/lzopio.c b/grub-core/io/lzopio.c index 30144857d..7559c6c9c 100644 --- a/grub-core/io/lzopio.c +++ b/grub-core/io/lzopio.c @@ -407,14 +407,12 @@ CORRUPTED: } static grub_file_t -grub_lzopio_open (grub_file_t io, enum grub_file_type type) +grub_lzopio_open (grub_file_t io, + const char *name __attribute__ ((unused))) { grub_file_t file; grub_lzopio_t lzopio; - if (type & GRUB_FILE_TYPE_NO_DECOMPRESS) - return io; - file = (grub_file_t) grub_zalloc (sizeof (*file)); if (!file) return 0; @@ -531,11 +529,11 @@ grub_lzopio_close (grub_file_t file) static struct grub_fs grub_lzopio_fs = { .name = "lzopio", - .fs_dir = 0, - .fs_open = 0, - .fs_read = grub_lzopio_read, - .fs_close = grub_lzopio_close, - .fs_label = 0, + .dir = 0, + .open = 0, + .read = grub_lzopio_read, + .close = grub_lzopio_close, + .label = 0, .next = 0 }; diff --git a/grub-core/io/offset.c b/grub-core/io/offset.c index 7e2db4a3a..ebed0ebe6 100644 --- a/grub-core/io/offset.c +++ b/grub-core/io/offset.c @@ -52,11 +52,11 @@ grub_offset_close (grub_file_t file) static struct grub_fs grub_offset_fs = { .name = "offset", - .fs_dir = 0, - .fs_open = 0, - .fs_read = grub_offset_read, - .fs_close = grub_offset_close, - .fs_label = 0, + .dir = 0, + .open = 0, + .read = grub_offset_read, + .close = grub_offset_close, + .label = 0, .next = 0 }; @@ -69,8 +69,7 @@ grub_file_offset_close (grub_file_t file) } grub_file_t -grub_file_offset_open (grub_file_t parent, enum grub_file_type type, - grub_off_t start, grub_off_t size) +grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size) { struct grub_offset_file *off_data; grub_file_t off_file, last_off_file; @@ -96,10 +95,10 @@ grub_file_offset_open (grub_file_t parent, enum grub_file_type type, last_off_file = NULL; for (filter = GRUB_FILE_FILTER_COMPRESSION_FIRST; off_file && filter <= GRUB_FILE_FILTER_COMPRESSION_LAST; filter++) - if (grub_file_filters[filter]) + if (grub_file_filters_enabled[filter]) { last_off_file = off_file; - off_file = grub_file_filters[filter] (off_file, type); + off_file = grub_file_filters_enabled[filter] (off_file, parent->name); } if (!off_file) diff --git a/grub-core/io/xzio.c b/grub-core/io/xzio.c index 516c4dfca..a3536ad73 100644 --- a/grub-core/io/xzio.c +++ b/grub-core/io/xzio.c @@ -169,14 +169,12 @@ ERROR: } static grub_file_t -grub_xzio_open (grub_file_t io, enum grub_file_type type) +grub_xzio_open (grub_file_t io, + const char *name __attribute__ ((unused))) { grub_file_t file; grub_xzio_t xzio; - if (type & GRUB_FILE_TYPE_NO_DECOMPRESS) - return io; - file = (grub_file_t) grub_zalloc (sizeof (*file)); if (!file) return 0; @@ -327,11 +325,11 @@ grub_xzio_close (grub_file_t file) static struct grub_fs grub_xzio_fs = { .name = "xzio", - .fs_dir = 0, - .fs_open = 0, - .fs_read = grub_xzio_read, - .fs_close = grub_xzio_close, - .fs_label = 0, + .dir = 0, + .open = 0, + .read = grub_xzio_read, + .close = grub_xzio_close, + .label = 0, .next = 0 }; diff --git a/grub-core/kern/acpi.c b/grub-core/kern/acpi.c deleted file mode 100644 index 5746ac00c..000000000 --- a/grub-core/kern/acpi.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2012 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include - -/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */ -grub_uint8_t -grub_byte_checksum (void *base, grub_size_t size) -{ - grub_uint8_t *ptr; - grub_uint8_t ret = 0; - for (ptr = (grub_uint8_t *) base; ptr < ((grub_uint8_t *) base) + size; - ptr++) - ret += *ptr; - return ret; -} - -static void * -grub_acpi_rsdt_find_table (struct grub_acpi_table_header *rsdt, const char *sig) -{ - grub_size_t s; - grub_unaligned_uint32_t *ptr; - - if (!rsdt) - return 0; - - if (grub_memcmp (rsdt->signature, "RSDT", 4) != 0) - return 0; - - ptr = (grub_unaligned_uint32_t *) (rsdt + 1); - s = (rsdt->length - sizeof (*rsdt)) / sizeof (grub_uint32_t); - for (; s; s--, ptr++) - { - struct grub_acpi_table_header *tbl; - tbl = (struct grub_acpi_table_header *) (grub_addr_t) ptr->val; - if (grub_memcmp (tbl->signature, sig, 4) == 0) - return tbl; - } - return 0; -} - -static void * -grub_acpi_xsdt_find_table (struct grub_acpi_table_header *xsdt, const char *sig) -{ - grub_size_t s; - grub_unaligned_uint64_t *ptr; - - if (!xsdt) - return 0; - - if (grub_memcmp (xsdt->signature, "XSDT", 4) != 0) - return 0; - - ptr = (grub_unaligned_uint64_t *) (xsdt + 1); - s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t); - for (; s; s--, ptr++) - { - struct grub_acpi_table_header *tbl; -#if GRUB_CPU_SIZEOF_VOID_P != 8 - if (ptr->val >> 32) - continue; -#endif - tbl = (struct grub_acpi_table_header *) (grub_addr_t) ptr->val; - if (grub_memcmp (tbl->signature, sig, 4) == 0) - return tbl; - } - return 0; -} - -struct grub_acpi_fadt * -grub_acpi_find_fadt (void) -{ - struct grub_acpi_fadt *fadt = 0; - struct grub_acpi_rsdp_v10 *rsdpv1; - struct grub_acpi_rsdp_v20 *rsdpv2; - rsdpv1 = grub_machine_acpi_get_rsdpv1 (); - if (rsdpv1) - fadt = grub_acpi_rsdt_find_table ((struct grub_acpi_table_header *) - (grub_addr_t) rsdpv1->rsdt_addr, - GRUB_ACPI_FADT_SIGNATURE); - if (fadt) - return fadt; - rsdpv2 = grub_machine_acpi_get_rsdpv2 (); - if (rsdpv2) - fadt = grub_acpi_rsdt_find_table ((struct grub_acpi_table_header *) - (grub_addr_t) rsdpv2->rsdpv1.rsdt_addr, - GRUB_ACPI_FADT_SIGNATURE); - if (fadt) - return fadt; - if (rsdpv2 -#if GRUB_CPU_SIZEOF_VOID_P != 8 - && !(rsdpv2->xsdt_addr >> 32) -#endif - ) - fadt = grub_acpi_xsdt_find_table ((struct grub_acpi_table_header *) - (grub_addr_t) rsdpv2->xsdt_addr, - GRUB_ACPI_FADT_SIGNATURE); - if (fadt) - return fadt; - return 0; -} diff --git a/grub-core/kern/arm/cache.c b/grub-core/kern/arm/cache.c index 6c75193e4..34154ccdb 100644 --- a/grub-core/kern/arm/cache.c +++ b/grub-core/kern/arm/cache.c @@ -29,8 +29,6 @@ void grub_arm_clean_dcache_range_armv6 (grub_addr_t start, grub_addr_t end, grub_addr_t dlinesz); void grub_arm_clean_dcache_range_armv7 (grub_addr_t start, grub_addr_t end, grub_addr_t dlinesz); -void grub_arm_clean_dcache_range_poc_armv7 (grub_addr_t start, grub_addr_t end, - grub_addr_t dlinesz); void grub_arm_invalidate_icache_range_armv6 (grub_addr_t start, grub_addr_t end, grub_addr_t dlinesz); void grub_arm_invalidate_icache_range_armv7 (grub_addr_t start, grub_addr_t end, @@ -93,16 +91,13 @@ probe_caches (void) grub_arch_cache_ilinesz = 8 << (cache_type & 3); type = ARCH_ARMV6; break; - default: - /* - * The CTR register is pretty much unchanged from v7 onwards, - * and is guaranteed to be backward compatible (the IDC/DIC bits - * allow certain CMOs to be elided, but performing them is never - * wrong), hence handling it like its AArch64 equivalent. - */ + case 0x80 ... 0x8f: grub_arch_cache_dlinesz = 4 << ((cache_type >> 16) & 0xf); grub_arch_cache_ilinesz = 4 << (cache_type & 0xf); type = ARCH_ARMV7; + break; + default: + grub_fatal ("Unsupported cache type 0x%x", cache_type); } if (grub_arch_cache_dlinesz > grub_arch_cache_ilinesz) grub_arch_cache_max_linesz = grub_arch_cache_dlinesz; @@ -257,38 +252,6 @@ grub_arch_sync_caches (void *address, grub_size_t len) } } -void -grub_arch_sync_dma_caches (volatile void *address, grub_size_t len) -{ - grub_addr_t start = (grub_addr_t) address; - grub_addr_t end = start + len; - - if (type == ARCH_UNKNOWN) - probe_caches (); - start = ALIGN_DOWN (start, grub_arch_cache_max_linesz); - end = ALIGN_UP (end, grub_arch_cache_max_linesz); - switch (type) - { - case ARCH_ARMV6: - grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz); - grub_arm_invalidate_icache_range_armv6 (start, end, - grub_arch_cache_ilinesz); - break; - case ARCH_ARMV5_WRITE_THROUGH: - case ARCH_ARMV6_UNIFIED: - grub_arm_clean_dcache_range_armv6 (start, end, grub_arch_cache_dlinesz); - break; - case ARCH_ARMV7: - grub_arm_clean_dcache_range_poc_armv7 (start, end, grub_arch_cache_dlinesz); - grub_arm_invalidate_icache_range_armv7 (start, end, - grub_arch_cache_ilinesz); - break; - /* Pacify GCC. */ - case ARCH_UNKNOWN: - break; - } -} - void grub_arm_disable_caches_mmu (void) { diff --git a/grub-core/kern/arm/cache_armv7.S b/grub-core/kern/arm/cache_armv7.S index 5ae76a3d8..1ef2754af 100644 --- a/grub-core/kern/arm/cache_armv7.S +++ b/grub-core/kern/arm/cache_armv7.S @@ -33,18 +33,6 @@ # define ISB isb #define ARMV7 1 -FUNCTION(grub_arm_clean_dcache_range_poc_armv7) - DSB - @ Clean data cache for range to point-of-coherence -1: cmp r0, r1 - bge 2f - mcr p15, 0, r0, c7, c14, 1 @ DCCMVAC - add r0, r0, r2 @ Next line - b 1b -2: DSB - bx lr - - @ r0 - CLIDR @ r1 - LoC @ r2 - current level diff --git a/grub-core/kern/arm/coreboot/cbtable.c b/grub-core/kern/arm/coreboot/cbtable.c deleted file mode 100644 index 8a655bb5c..000000000 --- a/grub-core/kern/arm/coreboot/cbtable.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -#pragma GCC diagnostic ignored "-Wcast-align" - -grub_linuxbios_table_header_t -grub_linuxbios_get_tables (void) -{ - grub_linuxbios_table_header_t table_header - = (grub_linuxbios_table_header_t) grub_arm_saved_registers.r[0]; - - if (!grub_linuxbios_check_signature (table_header)) - return 0; - - return table_header; -} diff --git a/grub-core/kern/arm/coreboot/coreboot.S b/grub-core/kern/arm/coreboot/coreboot.S deleted file mode 100644 index a1104526c..000000000 --- a/grub-core/kern/arm/coreboot/coreboot.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include - - .file "coreboot.S" - .text - .syntax unified -#if !defined (__thumb2__) - .arch armv7a - .arm -#else - .arch armv7 - .thumb -#endif - -FUNCTION(grub_arm_pfr1) - mrc p15, 0, r0, c0, c1, 1 - bx lr - -FUNCTION(grub_armv7_get_timer_value) - isb - mrrc p15, 1, r0, r1, c14 - bx lr - -FUNCTION(grub_armv7_get_timer_frequency) - mrc p15, 0, r0, c14, c0, 0 - bx lr - diff --git a/grub-core/kern/arm/coreboot/dma.c b/grub-core/kern/arm/coreboot/dma.c deleted file mode 100644 index 2c2a62789..000000000 --- a/grub-core/kern/arm/coreboot/dma.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -struct grub_pci_dma_chunk * -grub_memalign_dma32 (grub_size_t align, grub_size_t size) -{ - void *ret; - if (align < 64) - align = 64; - size = ALIGN_UP (size, align); - ret = grub_memalign (align, size); - if (!ret) - return 0; - grub_arch_sync_dma_caches (ret, size); - return ret; -} - -void -grub_dma_free (struct grub_pci_dma_chunk *ch) -{ - grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN; - grub_arch_sync_dma_caches (ch, size); - grub_free (ch); -} - -volatile void * -grub_dma_get_virt (struct grub_pci_dma_chunk *ch) -{ - return (void *) ch; -} - -grub_uint32_t -grub_dma_get_phys (struct grub_pci_dma_chunk *ch) -{ - return (grub_uint32_t) (grub_addr_t) ch; -} - diff --git a/grub-core/kern/arm/coreboot/init.c b/grub-core/kern/arm/coreboot/init.c deleted file mode 100644 index 8d8c5b829..000000000 --- a/grub-core/kern/arm/coreboot/init.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern grub_uint8_t _start[]; -extern grub_uint8_t _end[]; -extern grub_uint8_t _edata[]; -grub_addr_t start_of_ram = ~(grub_addr_t)0; - -void __attribute__ ((noreturn)) -grub_exit (void) -{ - /* We can't use grub_fatal() in this function. This would create an infinite - loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ - while (1) - grub_cpu_idle (); -} - -static grub_uint64_t modend; -static int have_memory = 0; - -/* Helper for grub_machine_init. */ -static int -heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, - void *data __attribute__ ((unused))) -{ - grub_uint64_t begin = addr, end = addr + size; - -#if GRUB_CPU_SIZEOF_VOID_P == 4 - /* Restrict ourselves to 32-bit memory space. */ - if (begin > GRUB_ULONG_MAX) - return 0; - if (end > GRUB_ULONG_MAX) - end = GRUB_ULONG_MAX; -#endif - - if (start_of_ram > begin) - start_of_ram = begin; - - if (type != GRUB_MEMORY_AVAILABLE) - return 0; - - if (modend && begin < modend) - { - if (begin < (grub_addr_t)_start) - { - grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) ((grub_addr_t)_start - begin)); - have_memory = 1; - } - begin = modend; - } - - /* Avoid DMA problems. */ - if (end >= 0xfe000000) - end = 0xfe000000; - - if (end <= begin) - return 0; - - grub_mm_init_region ((void *) (grub_addr_t) begin, (grub_size_t) (end - begin)); - - have_memory = 1; - - return 0; -} - -void -grub_machine_init (void) -{ - struct grub_module_header *header; - void *dtb = 0; - grub_size_t dtb_size = 0; - - modend = grub_modules_get_end (); - - grub_video_coreboot_fb_early_init (); - - grub_machine_mmap_iterate (heap_init, NULL); - if (!have_memory) - grub_fatal ("No memory found"); - - grub_video_coreboot_fb_late_init (); - - grub_font_init (); - grub_gfxterm_init (); - - FOR_MODULES (header) - if (header->type == OBJ_TYPE_DTB) - { - char *dtb_orig_addr, *dtb_copy; - dtb_orig_addr = (char *) header + sizeof (struct grub_module_header); - - dtb_size = header->size - sizeof (struct grub_module_header); - dtb = dtb_copy = grub_malloc (dtb_size); - grub_memmove (dtb_copy, dtb_orig_addr, dtb_size); - break; - } - if (!dtb) - grub_fatal ("No DTB found"); - grub_fdtbus_init (dtb, dtb_size); - - grub_rk3288_spi_init (); - - grub_machine_timer_init (); - grub_cros_init (); - grub_pl050_init (); -} - -void -grub_machine_get_bootlocation (char **device __attribute__ ((unused)), - char **path __attribute__ ((unused))) -{ -} - -void -grub_machine_fini (int flags __attribute__ ((unused))) -{ -} diff --git a/grub-core/kern/arm/coreboot/timer.c b/grub-core/kern/arm/coreboot/timer.c deleted file mode 100644 index d97b844f8..000000000 --- a/grub-core/kern/arm/coreboot/timer.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -grub_uint64_t -grub_armv7_get_timer_value(void); - -grub_uint32_t -grub_armv7_get_timer_frequency(void); - -grub_uint32_t -grub_arm_pfr1(void); - -static int have_timer = 0; -static volatile grub_uint32_t *sp804_regs; - -static grub_uint64_t -sp804_get_time_ms (void) -{ - static grub_uint32_t high, last_low; - grub_uint32_t low = ~sp804_regs[1]; - if (last_low > low) - high++; - last_low = low; - return grub_divmod64 ((((grub_uint64_t) high) << 32) | low, - 1000, 0); -} - -static grub_err_t -sp804_attach(const struct grub_fdtbus_dev *dev) -{ - if (have_timer) - return GRUB_ERR_NONE; - sp804_regs = grub_fdtbus_map_reg (dev, 0, 0); - if (!grub_fdtbus_is_mapping_valid (sp804_regs)) - return grub_error (GRUB_ERR_IO, "could not map sp804: %p", sp804_regs); - grub_install_get_time_ms (sp804_get_time_ms); - have_timer = 1; - return GRUB_ERR_NONE; -} - -struct grub_fdtbus_driver sp804 = -{ - .compatible = "arm,sp804", - .attach = sp804_attach -}; - -static grub_uint32_t timer_frequency_in_khz; - -static grub_uint64_t -generic_get_time_ms (void) -{ - return grub_divmod64 (grub_armv7_get_timer_value(), timer_frequency_in_khz, 0); -} - -static int -try_generic_timer (void) -{ - if (((grub_arm_pfr1 () >> 16) & 0xf) != 1) - return 0; - grub_printf ("freq = %x\n", grub_armv7_get_timer_frequency()); - timer_frequency_in_khz = 0x016e3600 / 1000; //grub_armv7_get_timer_frequency() / 1000; - if (timer_frequency_in_khz == 0) - return 0; - grub_install_get_time_ms (generic_get_time_ms); - have_timer = 1; - return 1; -} - -void -grub_machine_timer_init (void) -{ - grub_fdtbus_register (&sp804); - - if (!have_timer) - try_generic_timer (); - if (!have_timer) - grub_fatal ("No timer found"); -} diff --git a/grub-core/kern/arm/dl.c b/grub-core/kern/arm/dl.c index eab9d17ff..57cac2e75 100644 --- a/grub-core/kern/arm/dl.c +++ b/grub-core/kern/arm/dl.c @@ -78,9 +78,9 @@ grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, const Elf_Rel *rel, *max; for (rel = (const Elf_Rel *) ((grub_addr_t) e + s->sh_offset), - max = (const Elf_Rel *) ((grub_addr_t) rel + s->sh_size); - rel + 1 <= max; - rel = (const Elf_Rel *) ((grub_addr_t) rel + s->sh_entsize)) + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) switch (ELF_R_TYPE (rel->r_info)) { case R_ARM_CALL: @@ -173,8 +173,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, sym_addr += grub_arm_thm_call_get_offset ((grub_uint16_t *) target); grub_dprintf ("dl", " sym_addr = 0x%08x\n", sym_addr); - if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) - sym_addr |= 1; offset = sym_addr - (grub_uint32_t) target; @@ -207,21 +205,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, */ case R_ARM_V4BX: break; - case R_ARM_THM_MOVW_ABS_NC: - case R_ARM_THM_MOVT_ABS: - { - grub_uint32_t offset; - offset = grub_arm_thm_movw_movt_get_value((grub_uint16_t *) target); - offset += sym_addr; - - if (ELF_R_TYPE (rel->r_info) == R_ARM_THM_MOVT_ABS) - offset >>= 16; - else - offset &= 0xffff; - - grub_arm_thm_movw_movt_set_value((grub_uint16_t *) target, offset); - } - break; case R_ARM_THM_JUMP19: { /* Thumb instructions can be 16-bit aligned */ @@ -229,16 +212,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, sym_addr += grub_arm_thm_jump19_get_offset ((grub_uint16_t *) target); - if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) - sym_addr |= 1; - offset = sym_addr - (grub_uint32_t) target; if (!grub_arm_thm_jump19_check_offset (offset) || !(sym_addr & 1)) { - struct trampoline_thumb *tp = mod->trampptr; - mod->trampptr = tp + 1; + struct trampoline_thumb *tp = mod->gotptr; + mod->gotptr = tp + 1; grub_memcpy (tp->template, thumb_template, sizeof (tp->template)); tp->neg_addr = -sym_addr - 4; offset = ((grub_uint8_t *) tp - (grub_uint8_t *) target - 4) | 1; diff --git a/grub-core/kern/arm/dl_helper.c b/grub-core/kern/arm/dl_helper.c index 21d77f763..5721939c1 100644 --- a/grub-core/kern/arm/dl_helper.c +++ b/grub-core/kern/arm/dl_helper.c @@ -25,20 +25,6 @@ #include #include -static inline grub_uint32_t -thumb_get_instruction_word (grub_uint16_t *target) -{ - /* Extract instruction word in alignment-safe manner */ - return grub_le_to_cpu16 ((*target)) << 16 | grub_le_to_cpu16 (*(target + 1)); -} - -static inline void -thumb_set_instruction_word (grub_uint16_t *target, grub_uint32_t insword) -{ - *target = grub_cpu_to_le16 (insword >> 16); - *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); -} - /* * R_ARM_ABS32 * @@ -70,7 +56,9 @@ grub_arm_thm_call_get_offset (grub_uint16_t *target) grub_uint32_t insword; grub_int32_t offset; - insword = thumb_get_instruction_word (target); + /* Extract instruction word in alignment-safe manner */ + insword = (grub_le_to_cpu16 (*target) << 16) + | (grub_le_to_cpu16(*(target + 1))); /* Extract bitfields from instruction words */ sign = (insword >> 26) & 1; @@ -95,7 +83,9 @@ grub_arm_thm_call_set_offset (grub_uint16_t *target, grub_int32_t offset) grub_uint32_t insword; int is_blx; - insword = thumb_get_instruction_word (target); + /* Extract instruction word in alignment-safe manner */ + insword = (grub_le_to_cpu16 (*target) << 16) + | (grub_le_to_cpu16(*(target + 1))); if (((insword >> 12) & 0xd) == 0xc) is_blx = 1; @@ -118,7 +108,9 @@ grub_arm_thm_call_set_offset (grub_uint16_t *target, grub_int32_t offset) (((offset >> 12) & 0x03ff) << 16) | (j1 << 13) | (j2 << 11) | ((offset >> 1) & 0x07ff); - thumb_set_instruction_word (target, insword); + /* Write instruction word back in alignment-safe manner */ + *target = grub_cpu_to_le16 ((insword >> 16) & 0xffff); + *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); grub_dprintf ("dl", " *insword = 0x%08x", insword); @@ -131,7 +123,9 @@ grub_arm_thm_jump19_get_offset (grub_uint16_t *target) grub_int32_t offset; grub_uint32_t insword; - insword = thumb_get_instruction_word (target); + /* Extract instruction word in alignment-safe manner */ + insword = (grub_le_to_cpu16 (*target) << 16) + | (grub_le_to_cpu16(*(target + 1))); /* Extract and sign extend offset */ offset = ((insword >> 26) & 1) << 19 @@ -155,7 +149,9 @@ grub_arm_thm_jump19_set_offset (grub_uint16_t *target, grub_int32_t offset) offset >>= 1; offset &= 0xfffff; - insword = thumb_get_instruction_word (target); + /* Extract instruction word in alignment-safe manner */ + insword = grub_le_to_cpu16 ((*target)) << 16 + | grub_le_to_cpu16 (*(target + 1)); /* Reassemble instruction word and write back */ insword &= insmask; @@ -164,7 +160,8 @@ grub_arm_thm_jump19_set_offset (grub_uint16_t *target, grub_int32_t offset) | ((offset >> 17) & 1) << 13 | ((offset >> 11) & 0x3f) << 16 | (offset & 0x7ff); - thumb_set_instruction_word (target, insword); + *target = grub_cpu_to_le16 (insword >> 16); + *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); } int @@ -175,32 +172,6 @@ grub_arm_thm_jump19_check_offset (grub_int32_t offset) return 1; } -grub_uint16_t -grub_arm_thm_movw_movt_get_value (grub_uint16_t *target) -{ - grub_uint32_t insword; - - insword = thumb_get_instruction_word (target); - - return ((insword & 0xf0000) >> 4) | ((insword & 0x04000000) >> 15) | \ - ((insword & 0x7000) >> 4) | (insword & 0xff); -} - -void -grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value) -{ - grub_uint32_t insword; - const grub_uint32_t insmask = 0xfbf08f00; - - insword = thumb_get_instruction_word (target); - insword &= insmask; - - insword |= ((value & 0xf000) << 4) | ((value & 0x0800) << 15) | \ - ((value & 0x0700) << 4) | (value & 0xff); - - thumb_set_instruction_word (target, insword); -} - /*********************************************************** * ARM (A32) relocations: * diff --git a/grub-core/kern/arm/efi/init.c b/grub-core/kern/arm/efi/init.c index 40c3b467f..a6ae03475 100644 --- a/grub-core/kern/arm/efi/init.c +++ b/grub-core/kern/arm/efi/init.c @@ -38,7 +38,7 @@ static void increment_timer (grub_efi_event_t event __attribute__ ((unused)), void *context __attribute__ ((unused))) { - tmr += 10; + tmr++; } void @@ -52,7 +52,7 @@ grub_machine_init (void) efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL, GRUB_EFI_TPL_CALLBACK, increment_timer, NULL, &tmr_evt); - efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000); + efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 10000); grub_install_get_time_ms (grub_efi_get_time_ms); } @@ -67,11 +67,8 @@ grub_machine_fini (int flags) b = grub_efi_system_table->boot_services; - efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0); + efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 0); efi_call_1 (b->close_event, tmr_evt); grub_efi_fini (); - - if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) - grub_efi_memory_fini (); } diff --git a/grub-core/kern/arm/efi/misc.c b/grub-core/kern/arm/efi/misc.c new file mode 100644 index 000000000..7cd41842a --- /dev/null +++ b/grub-core/kern/arm/efi/misc.c @@ -0,0 +1,202 @@ +/* misc.c - various system functions for an arm-based EFI system */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +static inline grub_size_t +page_align (grub_size_t size) +{ + return (size + (1 << 12) - 1) & (~((1 << 12) - 1)); +} + +/* Find the optimal number of pages for the memory map. Is it better to + move this code to efi/mm.c? */ +static grub_efi_uintn_t +find_mmap_size (void) +{ + static grub_efi_uintn_t mmap_size = 0; + + if (mmap_size != 0) + return mmap_size; + + mmap_size = (1 << 12); + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + + mmap = grub_malloc (mmap_size); + if (! mmap) + return 0; + + ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + { + grub_error (GRUB_ERR_IO, "cannot get memory map"); + return 0; + } + else if (ret > 0) + break; + + mmap_size += (1 << 12); + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + mmap_size += (1 << 12); + + return page_align (mmap_size); +} + +#define NEXT_MEMORY_DESCRIPTOR(desc, size) \ + ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) +#define PAGE_SHIFT 12 + +void * +grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size) +{ + grub_efi_uintn_t desc_size; + grub_efi_memory_descriptor_t *mmap, *mmap_end; + grub_efi_uintn_t mmap_size, tmp_mmap_size; + grub_efi_memory_descriptor_t *desc; + void *mem = NULL; + grub_addr_t min_start = 0; + + mmap_size = find_mmap_size(); + if (!mmap_size) + return NULL; + + mmap = grub_malloc(mmap_size); + if (!mmap) + return NULL; + + tmp_mmap_size = mmap_size; + if (grub_efi_get_memory_map (&tmp_mmap_size, mmap, 0, &desc_size, 0) <= 0) + { + grub_error (GRUB_ERR_IO, "cannot get memory map"); + goto fail; + } + + mmap_end = NEXT_MEMORY_DESCRIPTOR (mmap, tmp_mmap_size); + /* Find lowest accessible RAM location */ + { + int found = 0; + for (desc = mmap ; !found && (desc < mmap_end) ; + desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size)) + { + switch (desc->type) + { + case GRUB_EFI_CONVENTIONAL_MEMORY: + case GRUB_EFI_LOADER_CODE: + case GRUB_EFI_LOADER_DATA: + min_start = desc->physical_start + min_offset; + found = 1; + break; + default: + break; + } + } + } + + /* First, find free pages for the real mode code + and the memory map buffer. */ + for (desc = mmap ; desc < mmap_end ; + desc = NEXT_MEMORY_DESCRIPTOR(desc, desc_size)) + { + grub_uint64_t start, end; + + grub_dprintf("mm", "%s: 0x%08x bytes @ 0x%08x\n", + __FUNCTION__, + (grub_uint32_t) (desc->num_pages << PAGE_SHIFT), + (grub_uint32_t) (desc->physical_start)); + + if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY) + continue; + + start = desc->physical_start; + end = start + (desc->num_pages << PAGE_SHIFT); + grub_dprintf("mm", "%s: start=0x%016llx, end=0x%016llx\n", + __FUNCTION__, start, end); + start = start < min_start ? min_start : start; + if (start + size > end) + continue; + grub_dprintf("mm", "%s: let's allocate some (0x%x) pages @ 0x%08x...\n", + __FUNCTION__, (size >> PAGE_SHIFT), (grub_addr_t) start); + mem = grub_efi_allocate_pages (start, (size >> PAGE_SHIFT) + 1); + grub_dprintf("mm", "%s: retval=0x%08x\n", + __FUNCTION__, (grub_addr_t) mem); + if (! mem) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); + goto fail; + } + break; + } + + if (! mem) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); + goto fail; + } + + grub_free (mmap); + return mem; + + fail: + grub_free (mmap); + return NULL; +} + +grub_err_t +grub_efi_prepare_platform (void) +{ + grub_efi_uintn_t mmap_size; + grub_efi_uintn_t map_key; + grub_efi_uintn_t desc_size; + grub_efi_uint32_t desc_version; + grub_efi_memory_descriptor_t *mmap_buf; + grub_err_t err; + + /* + * Cloned from IA64 + * Must be done after grub_machine_fini because map_key is used by + *exit_boot_services. + */ + mmap_size = find_mmap_size (); + if (! mmap_size) + return GRUB_ERR_OUT_OF_MEMORY; + mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12); + if (! mmap_buf) + return GRUB_ERR_OUT_OF_MEMORY; + + err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key, + &desc_size, &desc_version); + if (err != GRUB_ERR_NONE) + return err; + + return GRUB_ERR_NONE; +} diff --git a/grub-core/kern/arm/compiler-rt.S b/grub-core/kern/arm/misc.S similarity index 89% rename from grub-core/kern/arm/compiler-rt.S rename to grub-core/kern/arm/misc.S index 645b42f50..16b6f8e60 100644 --- a/grub-core/kern/arm/compiler-rt.S +++ b/grub-core/kern/arm/misc.S @@ -58,11 +58,15 @@ FUNCTION(__aeabi_lmul) ldmfd sp!, {r4, fp} bx lr - .macro division32 parent + .macro division parent sub sp, sp, #8 @ Allocate naturally aligned 64-bit space stmfd sp!, {r3,lr} @ Dummy r3 to maintain stack alignment - add r2, sp, #8 @ Set r2 to address of 64-bit space + add r3, sp, #8 @ Set r3 to address of 64-bit space + str r3, [sp] @ Stack parameter, pointer to 64-bit space + mov r2, r1 + mov r1, #0 + mov r3, #0 bl \parent ldr r1, [sp, #8] @ Extract remainder ldmfd sp!, {r3,lr} @ Pop into an unused arg/scratch register @@ -71,9 +75,8 @@ FUNCTION(__aeabi_lmul) .endm FUNCTION(__aeabi_uidivmod) - division32 grub_divmod32 -FUNCTION(__aeabi_idivmod) - division32 grub_divmod32s + division grub_divmod64 + /* * Null divide-by-zero handler diff --git a/grub-core/kern/arm/uboot/init.c b/grub-core/kern/arm/uboot/init.c deleted file mode 100644 index 2a6aa3fdd..000000000 --- a/grub-core/kern/arm/uboot/init.c +++ /dev/null @@ -1,70 +0,0 @@ -/* init.c - generic U-Boot initialization and finalization */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -extern int (*grub_uboot_syscall_ptr) (int, int *, ...); - -grub_uint32_t -grub_uboot_get_machine_type (void) -{ - return grub_arm_saved_registers.r[1]; -} - -grub_addr_t -grub_uboot_get_boot_data (void) -{ - return grub_arm_saved_registers.r[2]; -} - -int -grub_uboot_api_init (void) -{ - struct api_signature *start, *end; - struct api_signature *p; - grub_addr_t grub_uboot_search_hint = grub_arm_saved_registers.sp; - if (grub_uboot_search_hint) - { - /* Extended search range to work around Trim Slice U-Boot issue */ - start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff) - - 0x00500000); - end = - (struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN - - API_SIG_MAGLEN + 0x00500000); - } - else - { - start = 0; - end = (struct api_signature *) (256 * 1024 * 1024); - } - - /* Structure alignment is (at least) 8 bytes */ - for (p = start; p < end; p = (void *) ((grub_addr_t) p + 8)) - { - if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0) - { - grub_uboot_syscall_ptr = p->syscall; - return p->version; - } - } - - return 0; -} diff --git a/grub-core/kern/arm/startup.S b/grub-core/kern/arm/uboot/startup.S similarity index 68% rename from grub-core/kern/arm/startup.S rename to grub-core/kern/arm/uboot/startup.S index 3946fe8e1..0c4a5f670 100644 --- a/grub-core/kern/arm/startup.S +++ b/grub-core/kern/arm/uboot/startup.S @@ -24,7 +24,6 @@ * GRUB is called from U-Boot as a Linux Kernel type image, which * means among other things that it always enters in ARM state. * - * coreboot starts in ARM mode as well. * * Overview of GRUB image layout: * @@ -56,6 +55,10 @@ FUNCTION(_start) VARIABLE(grub_total_module_size) .long 0 +VARIABLE(grub_uboot_machine_type) + .long 0 +VARIABLE(grub_uboot_boot_data) + .long 0 VARIABLE(grub_modbase) .long 0 bss_start_ptr: @@ -63,73 +66,34 @@ bss_start_ptr: end_ptr: .long EXT_C(_end) - @ Memory map at start: - @ * text+data - @ * list relocations - @ * modules - @ Before we enter C, we need to apply the relocations - @ and get following map: - @ * text+data - @ * BSS (cleared) - @ * stack - @ * modules - @ - @ To make things easier we ensure - @ that BSS+stack is larger than list of relocations - @ by increasing stack if necessarry. - @ This allows us to always unconditionally copy backwards - @ Currently list of relocations is ~5K and stack is set - @ to be at least 256K - FUNCTION(codestart) @ Store context: Machine ID, atags/dtb, ... @ U-Boot API signature is stored on the U-Boot heap @ Stack pointer used as start address for signature probing mov r12, sp adr sp, entry_state - push {r0-r12,lr} @ store U-Boot context (sp in r12) + push {r4-r12,lr} @ store U-Boot context (sp in r12) - adr r1, _start - ldr r0, bss_start_ptr @ src - add r0, r0, r1 + str r1, EXT_C(grub_uboot_machine_type) + str r2, EXT_C(grub_uboot_boot_data) - add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) - mvn r2, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) - and r0, r0, r2 -1: - ldr r3, [r0], #4 @load next offset - @ both -2 and -1 are treated the same as we have only one type of relocs - @ -2 means "end of this type of relocs" and -1 means "end of all relocs" - add r2, r3, #2 - cmp r2, #1 - bls reloc_done - @ Adjust next offset - ldr r2, [r3, r1] - add r2, r2, r1 - str r2, [r3, r1] - b 1b - -reloc_done: - - @ Modules have been stored as a blob + @ Modules have been stored as a blob in BSS, @ they need to be manually relocated to _end + ldr r0, bss_start_ptr @ src add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) mvn r1, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) - and r0, r0, r1 @ src = aligned end of relocations + and r0, r0, r1 ldr r1, end_ptr @ dst = End of BSS ldr r2, grub_total_module_size @ blob size add r1, r1, #GRUB_KERNEL_MACHINE_STACK_SIZE and r1, r1, #~0x7 @ Ensure 8-byte alignment - sub sp, r1, #8 add r1, r1, #1024 str r1, EXT_C(grub_modbase) - /* Coreboot already places modules at right place. */ -#ifndef GRUB_MACHINE_COREBOOT add r1, r1, r2 add r0, r0, r2 sub r1, r1, #4 @@ -139,7 +103,6 @@ reloc_done: str r3, [r1], #-4 @ *dst-- = r3 subs r2, #4 @ remaining -= 4 bne 1b @ while remaining != 0 -#endif @ Since we _are_ the C run-time, we need to manually zero the BSS @ region before continuing @@ -157,21 +120,64 @@ reloc_done: b EXT_C(grub_main) + /* + * uboot_syscall(): + * This function is effectively a veneer, so it cannot + * modify the stack or corrupt any registers other than + * r12 (ip). Furthermore it needs to restore r8 for + * U-Boot (Global Data Pointer) and preserve it for Grub. + */ +FUNCTION(grub_uboot_syscall) + str r8, transition_space + str lr, transition_space + 4 + str r9, transition_space + 8 + + ldr r8, gd_backup + ldr r9, gd_backup + 4 + + bl do_syscall + + ldr r8, transition_space + ldr lr, transition_space + 4 + ldr r9, transition_space + 8 + + bx lr +do_syscall: + + ldr ip, grub_uboot_syscall_ptr + bx ip + +FUNCTION(grub_uboot_return) + adr sp, entry_state_end + pop {r4-r12, lr} + mov sp, r12 + bx lr + + .align 3 -@ U-boot/coreboot context stack space -VARIABLE(grub_arm_saved_registers) - .long 0 @ r0 - .long 0 @ r1 - .long 0 @ r2 - .long 0 @ r3 +@ U-boot context stack space +entry_state_end: .long 0 @ r4 .long 0 @ r5 .long 0 @ r6 .long 0 @ r7 - .long 0 @ r8 - .long 0 @ r9 +gd_backup: + .long 0 @ r8 - U-Boot global data pointer up to 2013-09-21 + .long 0 @ r9 - U-Boot global data pointer 2013-09-21 onwards .long 0 @ r10 .long 0 @ r11 - .long 0 @ sp +VARIABLE(grub_uboot_search_hint)@ U-Boot stack pointer - + .long 0 @ also API signature address hint. .long 0 @ lr -entry_state: +entry_state: @ backup for U-Boot context + +@ GRUB context stack space +transition_space: + .long 0 @ r8 + .long 0 @ lr + .long 0 @ r9 + +VARIABLE(grub_uboot_syscall_ptr) + .long 0 @ + + END diff --git a/grub-core/kern/arm/uboot/uboot.S b/grub-core/kern/arm/uboot/uboot.S deleted file mode 100644 index d128775f1..000000000 --- a/grub-core/kern/arm/uboot/uboot.S +++ /dev/null @@ -1,73 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - - /* - * uboot_syscall(): - * This function is effectively a veneer, so it cannot - * modify the stack or corrupt any registers other than - * r12 (ip). Furthermore it needs to restore r8 for - * U-Boot (Global Data Pointer) and preserve it for Grub. - */ -FUNCTION(grub_uboot_syscall) - str r8, transition_space - str lr, transition_space + 4 - str r9, transition_space + 8 - - ldr ip, saved_registers_ptr - ldr r8, [ip, #4 * 8] - ldr r9, [ip, #4 * 9] - - bl do_syscall - - ldr r8, transition_space - ldr lr, transition_space + 4 - ldr r9, transition_space + 8 - - bx lr -do_syscall: - - ldr ip, grub_uboot_syscall_ptr - bx ip - -FUNCTION(grub_uboot_return) - ldr ip, saved_registers_ptr - ldr sp, [ip, #4 * 4] - pop {r4-r12, lr} - mov sp, r12 - bx lr - - - .align 3 - -@ GRUB context stack space -transition_space: - .long 0 @ r8 - .long 0 @ lr - .long 0 @ r9 - -saved_registers_ptr: - .long EXT_C(grub_arm_saved_registers) - -VARIABLE(grub_uboot_syscall_ptr) - .long 0 @ - - END diff --git a/grub-core/kern/arm64/dl.c b/grub-core/kern/arm64/dl.c index fb0337319..e19ba6a0d 100644 --- a/grub-core/kern/arm64/dl.c +++ b/grub-core/kern/arm64/dl.c @@ -25,9 +25,14 @@ #include #include +struct trampoline +{ #define LDR 0x58000050 #define BR 0xd61f0200 - + grub_uint32_t ldr; /* ldr x16, 8 */ + grub_uint32_t br; /* br x16 */ + grub_uint64_t addr; +}; /* * Check if EHDR is a valid ELF header. @@ -48,6 +53,42 @@ grub_arch_dl_check_header (void *ehdr) #pragma GCC diagnostic ignored "-Wcast-align" +grub_err_t +grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, + grub_size_t *got) +{ + const Elf_Ehdr *e = ehdr; + const Elf_Shdr *s; + unsigned i; + + *tramp = 0; + *got = 0; + + for (i = 0, s = (const Elf_Shdr *) ((grub_addr_t) e + e->e_shoff); + i < e->e_shnum; + i++, s = (const Elf_Shdr *) ((grub_addr_t) s + e->e_shentsize)) + if (s->sh_type == SHT_REL || s->sh_type == SHT_RELA) + { + const Elf_Rel *rel, *max; + + for (rel = (const Elf_Rel *) ((grub_addr_t) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel = (const Elf_Rel *) ((grub_addr_t) rel + s->sh_entsize)) + switch (ELF_R_TYPE (rel->r_info)) + { + case R_AARCH64_CALL26: + case R_AARCH64_JUMP26: + { + *tramp += sizeof (struct trampoline); + break; + } + } + } + + return GRUB_ERR_NONE; +} + /* * Unified function for both REL and RELA */ @@ -56,7 +97,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, Elf_Shdr *s, grub_dl_segment_t seg) { Elf_Rel *rel, *max; - unsigned unmatched_adr_got_page = 0; for (rel = (Elf_Rel *) ((char *) ehdr + s->sh_offset), max = (Elf_Rel *) ((char *) rel + s->sh_size); @@ -92,12 +132,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, *abs_place = (grub_uint64_t) sym_addr; } break; - case R_AARCH64_ADD_ABS_LO12_NC: - grub_arm64_set_abs_lo12 (place, sym_addr); - break; - case R_AARCH64_LDST64_ABS_LO12_NC: - grub_arm64_set_abs_lo12_ldst64 (place, sym_addr); - break; case R_AARCH64_CALL26: case R_AARCH64_JUMP26: { @@ -105,7 +139,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, if (!grub_arm_64_check_xxxx26_offset (offset)) { - struct grub_arm64_trampoline *tp = mod->trampptr; + struct trampoline *tp = mod->trampptr; mod->trampptr = tp + 1; tp->ldr = LDR; tp->br = BR; @@ -120,68 +154,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, grub_arm64_set_xxxx26_offset (place, offset); } break; - case R_AARCH64_PREL32: - { - grub_int64_t value; - Elf64_Word *addr32 = place; - value = ((grub_int32_t) *addr32) + sym_addr - - (Elf64_Xword) (grub_addr_t) seg->addr - rel->r_offset; - if (value != (grub_int32_t) value) - return grub_error (GRUB_ERR_BAD_MODULE, "relocation out of range"); - grub_dprintf("dl", " reloc_prel32 %p => 0x%016llx\n", - place, (unsigned long long) sym_addr); - *addr32 = value; - } - break; - case R_AARCH64_ADR_GOT_PAGE: - { - grub_uint64_t *gp = mod->gotptr; - Elf_Rela *rel2; - grub_int64_t gpoffset = ((grub_uint64_t) gp & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL); - *gp = (grub_uint64_t) sym_addr; - mod->gotptr = gp + 1; - unmatched_adr_got_page++; - grub_dprintf("dl", " reloc_got %p => 0x%016llx (0x%016llx)\n", - place, (unsigned long long) sym_addr, (unsigned long long) gp); - if (!grub_arm64_check_hi21_signed (gpoffset)) - return grub_error (GRUB_ERR_BAD_MODULE, - "HI21 out of range"); - grub_arm64_set_hi21(place, gpoffset); - for (rel2 = (Elf_Rela *) ((char *) rel + s->sh_entsize); - rel2 < (Elf_Rela *) max; - rel2 = (Elf_Rela *) ((char *) rel2 + s->sh_entsize)) - if (ELF_R_SYM (rel2->r_info) - == ELF_R_SYM (rel->r_info) - && ((Elf_Rela *) rel)->r_addend == rel2->r_addend - && ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC) - { - grub_arm64_set_abs_lo12_ldst64 ((void *) ((grub_addr_t) seg->addr + rel2->r_offset), - (grub_uint64_t)gp); - break; - } - if (rel2 >= (Elf_Rela *) max) - return grub_error (GRUB_ERR_BAD_MODULE, - "ADR_GOT_PAGE without matching LD64_GOT_LO12_NC"); - } - break; - case R_AARCH64_LD64_GOT_LO12_NC: - if (unmatched_adr_got_page == 0) - return grub_error (GRUB_ERR_BAD_MODULE, - "LD64_GOT_LO12_NC without matching ADR_GOT_PAGE"); - unmatched_adr_got_page--; - break; - case R_AARCH64_ADR_PREL_PG_HI21: - { - grub_int64_t offset = (sym_addr & ~0xfffULL) - (((grub_uint64_t) place) & ~0xfffULL); - - if (!grub_arm64_check_hi21_signed (offset)) - return grub_error (GRUB_ERR_BAD_MODULE, - "HI21 out of range"); - - grub_arm64_set_hi21 (place, offset); - } - break; - default: return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("relocation 0x%x is not implemented yet"), diff --git a/grub-core/kern/arm64/dl_helper.c b/grub-core/kern/arm64/dl_helper.c index e00c198db..d213ab93e 100644 --- a/grub-core/kern/arm64/dl_helper.c +++ b/grub-core/kern/arm64/dl_helper.c @@ -53,82 +53,3 @@ grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset) *place &= insmask; *place |= grub_cpu_to_le32 (offset >> 2) & ~insmask; } - -int -grub_arm64_check_hi21_signed (grub_int64_t offset) -{ - if (offset != (grub_int64_t)(grub_int32_t)offset) - return 0; - return 1; -} - -void -grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset) -{ - const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0x9f00001f); - grub_uint32_t val; - - offset >>= 12; - - val = ((offset & 3) << 29) | (((offset >> 2) & 0x7ffff) << 5); - - *place &= insmask; - *place |= grub_cpu_to_le32 (val) & ~insmask; -} - -void -grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target) -{ - const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xffc003ff); - - *place &= insmask; - *place |= grub_cpu_to_le32 (target << 10) & ~insmask; -} - -void -grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target) -{ - const grub_uint32_t insmask = grub_cpu_to_le32_compile_time (0xfff803ff); - - *place &= insmask; - *place |= grub_cpu_to_le32 (target << 7) & ~insmask; -} - -#pragma GCC diagnostic ignored "-Wcast-align" - -grub_err_t -grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, - grub_size_t *got) -{ - const Elf64_Ehdr *e = ehdr; - const Elf64_Shdr *s; - unsigned i; - - *tramp = 0; - *got = 0; - - for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu64 (e->e_shoff)); - i < grub_le_to_cpu16 (e->e_shnum); - i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize))) - if (s->sh_type == grub_cpu_to_le32_compile_time (SHT_REL) - || s->sh_type == grub_cpu_to_le32_compile_time (SHT_RELA)) - { - const Elf64_Rela *rel, *max; - - for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu64 (s->sh_offset)), - max = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_size)); - rel < max; rel = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_entsize))) - switch (ELF64_R_TYPE (rel->r_info)) - { - case R_AARCH64_CALL26: - case R_AARCH64_JUMP26: - *tramp += sizeof (struct grub_arm64_trampoline); - break; - case R_AARCH64_ADR_GOT_PAGE: - *got += 8; - break; - } - } - - return GRUB_ERR_NONE; -} diff --git a/grub-core/kern/arm64/efi/init.c b/grub-core/kern/arm64/efi/init.c deleted file mode 100644 index 5010caefd..000000000 --- a/grub-core/kern/arm64/efi/init.c +++ /dev/null @@ -1,63 +0,0 @@ -/* init.c - initialize an arm-based EFI system */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -static grub_uint64_t timer_frequency_in_khz; - -static grub_uint64_t -grub_efi_get_time_ms (void) -{ - grub_uint64_t tmr; - asm volatile("mrs %0, cntvct_el0" : "=r" (tmr)); - - return tmr / timer_frequency_in_khz; -} - - -void -grub_machine_init (void) -{ - grub_uint64_t timer_frequency; - - grub_efi_init (); - - asm volatile("mrs %0, cntfrq_el0" : "=r" (timer_frequency)); - timer_frequency_in_khz = timer_frequency / 1000; - - grub_install_get_time_ms (grub_efi_get_time_ms); -} - -void -grub_machine_fini (int flags) -{ - if (!(flags & GRUB_LOADER_FLAG_NORETURN)) - return; - - grub_efi_fini (); - - if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) - grub_efi_memory_fini (); -} diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c deleted file mode 100644 index a464200c6..000000000 --- a/grub-core/kern/compiler-rt.c +++ /dev/null @@ -1,464 +0,0 @@ -/* compiler-rt.c - compiler helpers. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010-2014 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -#ifndef GRUB_EMBED_DECOMPRESSOR -void * GRUB_BUILTIN_ATTR -memcpy (void *dest, const void *src, grub_size_t n) -{ - return grub_memmove (dest, src, n); -} -void * GRUB_BUILTIN_ATTR -memmove (void *dest, const void *src, grub_size_t n) -{ - return grub_memmove (dest, src, n); -} -int GRUB_BUILTIN_ATTR -memcmp (const void *s1, const void *s2, grub_size_t n) -{ - return grub_memcmp (s1, s2, n); -} -void * GRUB_BUILTIN_ATTR -memset (void *s, int c, grub_size_t n) -{ - return grub_memset (s, c, n); -} - -#ifdef __APPLE__ - -void GRUB_BUILTIN_ATTR -__bzero (void *s, grub_size_t n) -{ - grub_memset (s, 0, n); -} - -#endif - -#if GRUB_DIVISION_IN_SOFTWARE - -grub_uint32_t -__udivsi3 (grub_uint32_t a, grub_uint32_t b) -{ - return grub_divmod64 (a, b, 0); -} - -grub_int32_t -__divsi3 (grub_int32_t a, grub_int32_t b) -{ - return grub_divmod64s (a, b, 0); -} - -grub_uint32_t -__umodsi3 (grub_uint32_t a, grub_uint32_t b) -{ - grub_uint64_t ret; - grub_divmod64 (a, b, &ret); - return ret; -} - -grub_int32_t -__modsi3 (grub_int32_t a, grub_int32_t b) -{ - grub_int64_t ret; - grub_divmod64s (a, b, &ret); - return ret; -} - -grub_uint64_t -__udivdi3 (grub_uint64_t a, grub_uint64_t b) -{ - return grub_divmod64 (a, b, 0); -} - -grub_uint64_t -__umoddi3 (grub_uint64_t a, grub_uint64_t b) -{ - grub_uint64_t ret; - grub_divmod64 (a, b, &ret); - return ret; -} - -grub_int64_t -__divdi3 (grub_int64_t a, grub_int64_t b) -{ - return grub_divmod64s (a, b, 0); -} - -grub_int64_t -__moddi3 (grub_int64_t a, grub_int64_t b) -{ - grub_int64_t ret; - grub_divmod64s (a, b, &ret); - return ret; -} - -#endif - -#endif - -#ifdef NEED_CTZDI2 - -unsigned -__ctzdi2 (grub_uint64_t x) -{ - unsigned ret = 0; - if (!x) - return 64; - if (!(x & 0xffffffff)) - { - x >>= 32; - ret |= 32; - } - if (!(x & 0xffff)) - { - x >>= 16; - ret |= 16; - } - if (!(x & 0xff)) - { - x >>= 8; - ret |= 8; - } - if (!(x & 0xf)) - { - x >>= 4; - ret |= 4; - } - if (!(x & 0x3)) - { - x >>= 2; - ret |= 2; - } - if (!(x & 0x1)) - { - x >>= 1; - ret |= 1; - } - return ret; -} -#endif - -#ifdef NEED_CTZSI2 -unsigned -__ctzsi2 (grub_uint32_t x) -{ - unsigned ret = 0; - if (!x) - return 32; - - if (!(x & 0xffff)) - { - x >>= 16; - ret |= 16; - } - if (!(x & 0xff)) - { - x >>= 8; - ret |= 8; - } - if (!(x & 0xf)) - { - x >>= 4; - ret |= 4; - } - if (!(x & 0x3)) - { - x >>= 2; - ret |= 2; - } - if (!(x & 0x1)) - { - x >>= 1; - ret |= 1; - } - return ret; -} - -#endif - - -#if defined (__clang__) && !defined(GRUB_EMBED_DECOMPRESSOR) -/* clang emits references to abort(). */ -void __attribute__ ((noreturn)) -abort (void) -{ - grub_fatal ("compiler abort"); -} -#endif - -#if (defined (__MINGW32__) || defined (__CYGWIN__)) -void __register_frame_info (void) -{ -} - -void __deregister_frame_info (void) -{ -} - -void ___chkstk_ms (void) -{ -} - -void __chkstk_ms (void) -{ -} -#endif - -union component64 -{ - grub_uint64_t full; - struct - { -#ifdef GRUB_CPU_WORDS_BIGENDIAN - grub_uint32_t high; - grub_uint32_t low; -#else - grub_uint32_t low; - grub_uint32_t high; -#endif - }; -}; - -#if defined (__powerpc__) || defined (__arm__) || defined(__mips__) || \ - (defined(__riscv) && (__riscv_xlen == 32)) - -/* Based on libgcc2.c from gcc suite. */ -grub_uint64_t -__lshrdi3 (grub_uint64_t u, int b) -{ - if (b == 0) - return u; - - const union component64 uu = {.full = u}; - const int bm = 32 - b; - union component64 w; - - if (bm <= 0) - { - w.high = 0; - w.low = (grub_uint32_t) uu.high >> -bm; - } - else - { - const grub_uint32_t carries = (grub_uint32_t) uu.high << bm; - - w.high = (grub_uint32_t) uu.high >> b; - w.low = ((grub_uint32_t) uu.low >> b) | carries; - } - - return w.full; -} - -/* Based on libgcc2.c from gcc suite. */ -grub_uint64_t -__ashrdi3 (grub_uint64_t u, int b) -{ - if (b == 0) - return u; - - const union component64 uu = {.full = u}; - const int bm = 32 - b; - union component64 w; - - if (bm <= 0) - { - /* w.high = 1..1 or 0..0 */ - w.high = ((grub_int32_t) uu.high) >> (32 - 1); - w.low = ((grub_int32_t) uu.high) >> -bm; - } - else - { - const grub_uint32_t carries = ((grub_uint32_t) uu.high) << bm; - - w.high = ((grub_int32_t) uu.high) >> b; - w.low = ((grub_uint32_t) uu.low >> b) | carries; - } - - return w.full; -} - -/* Based on libgcc2.c from gcc suite. */ -grub_uint64_t -__ashldi3 (grub_uint64_t u, int b) -{ - if (b == 0) - return u; - - const union component64 uu = {.full = u}; - const int bm = 32 - b; - union component64 w; - - if (bm <= 0) - { - w.low = 0; - w.high = (grub_uint32_t) uu.low << -bm; - } - else - { - const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm; - - w.low = (grub_uint32_t) uu.low << b; - w.high = ((grub_uint32_t) uu.high << b) | carries; - } - - return w.full; -} - -/* Based on libgcc2.c from gcc suite. */ -int -__ucmpdi2 (grub_uint64_t a, grub_uint64_t b) -{ - union component64 ac, bc; - ac.full = a; - bc.full = b; - - if (ac.high < bc.high) - return 0; - else if (ac.high > bc.high) - return 2; - - if (ac.low < bc.low) - return 0; - else if (ac.low > bc.low) - return 2; - return 1; -} - -#endif - -#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \ - defined(__arm__) || defined(__riscv) - -/* Based on libgcc2.c from gcc suite. */ -grub_uint32_t -__bswapsi2 (grub_uint32_t u) -{ - return ((((u) & 0xff000000) >> 24) - | (((u) & 0x00ff0000) >> 8) - | (((u) & 0x0000ff00) << 8) - | (((u) & 0x000000ff) << 24)); -} - -/* Based on libgcc2.c from gcc suite. */ -grub_uint64_t -__bswapdi2 (grub_uint64_t u) -{ - return ((((u) & 0xff00000000000000ull) >> 56) - | (((u) & 0x00ff000000000000ull) >> 40) - | (((u) & 0x0000ff0000000000ull) >> 24) - | (((u) & 0x000000ff00000000ull) >> 8) - | (((u) & 0x00000000ff000000ull) << 8) - | (((u) & 0x0000000000ff0000ull) << 24) - | (((u) & 0x000000000000ff00ull) << 40) - | (((u) & 0x00000000000000ffull) << 56)); -} - - -#endif - -#ifdef __arm__ -grub_uint32_t -__aeabi_uidiv (grub_uint32_t a, grub_uint32_t b) - __attribute__ ((alias ("__udivsi3"))); -grub_int32_t -__aeabi_idiv (grub_int32_t a, grub_int32_t b) - __attribute__ ((alias ("__divsi3"))); -void *__aeabi_memcpy (void *dest, const void *src, grub_size_t n) - __attribute__ ((alias ("grub_memcpy"))); -void *__aeabi_memcpy4 (void *dest, const void *src, grub_size_t n) - __attribute__ ((alias ("grub_memcpy"))); -void *__aeabi_memcpy8 (void *dest, const void *src, grub_size_t n) - __attribute__ ((alias ("grub_memcpy"))); -void *__aeabi_memset (void *s, int c, grub_size_t n) - __attribute__ ((alias ("memset"))); - -void -__aeabi_memclr (void *s, grub_size_t n) -{ - grub_memset (s, 0, n); -} - -void __aeabi_memclr4 (void *s, grub_size_t n) - __attribute__ ((alias ("__aeabi_memclr"))); -void __aeabi_memclr8 (void *s, grub_size_t n) - __attribute__ ((alias ("__aeabi_memclr"))); - -int -__aeabi_ulcmp (grub_uint64_t a, grub_uint64_t b) -{ - return __ucmpdi2 (a, b) - 1; -} - -grub_uint64_t -__aeabi_lasr (grub_uint64_t u, int b) - __attribute__ ((alias ("__ashrdi3"))); -grub_uint64_t -__aeabi_llsr (grub_uint64_t u, int b) - __attribute__ ((alias ("__lshrdi3"))); - -grub_uint64_t -__aeabi_llsl (grub_uint64_t u, int b) - __attribute__ ((alias ("__ashldi3"))); - -#endif - -#if defined(__mips__) || defined(__riscv) || defined(__sparc__) -/* Based on libgcc from gcc suite. */ -int -__clzsi2 (grub_uint32_t val) -{ - int i = 32; - int j = 16; - int temp; - - for (; j; j >>= 1) - { - if ((temp = val) >> j) - { - if (j == 1) - { - return (i - 2); - } - else - { - i -= j; - val = temp; - } - } - } - return (i - val); -} -#endif - -#if defined(__riscv) || defined(__sparc__) -int -__clzdi2 (grub_uint64_t val) -{ - if (val >> 32) - { - return __clzsi2 (val >> 32); - } - else - { - return __clzsi2 (val) + 32; - } -} -#endif diff --git a/grub-core/kern/coreboot/cbtable.c b/grub-core/kern/coreboot/cbtable.c deleted file mode 100644 index aec63dbd1..000000000 --- a/grub-core/kern/coreboot/cbtable.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -#pragma GCC diagnostic ignored "-Wcast-align" - -/* Helper for grub_linuxbios_table_iterate. */ -int -grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header) -{ - if (! grub_memcmp (tbl_header->signature, "LBIO", 4)) - return 1; - - return 0; -} - -grub_err_t -grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t, - void *), - void *hook_data) -{ - grub_linuxbios_table_header_t table_header = grub_linuxbios_get_tables (); - grub_linuxbios_table_item_t table_item; - - if (!table_header) - return 0; - -signature_found: - - table_item = - (grub_linuxbios_table_item_t) ((char *) table_header + - table_header->header_size); - for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header - + table_header->header_size - + table_header->table_size); - table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size)) - { - if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK - && grub_linuxbios_check_signature ((grub_linuxbios_table_header_t) (grub_addr_t) - *(grub_uint64_t *) (table_item + 1))) - { - table_header = (grub_linuxbios_table_header_t) (grub_addr_t) - *(grub_uint64_t *) (table_item + 1); - goto signature_found; - } - if (hook (table_item, hook_data)) - return 1; - } - - return 0; -} diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c index fc54f43f2..d9412a316 100644 --- a/grub-core/kern/corecmd.c +++ b/grub-core/kern/corecmd.c @@ -155,7 +155,7 @@ grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)), } else if (fs) { - (fs->fs_dir) (dev, path, grub_mini_print_files, NULL); + (fs->dir) (dev, path, grub_mini_print_files, NULL); grub_xputs ("\n"); grub_refresh (); } diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index ffb09c8ee..789f8c052 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -223,7 +223,7 @@ grub_disk_open (const char *name) for (dev = grub_disk_dev_list; dev; dev = dev->next) { - if ((dev->disk_open) (raw, disk) == GRUB_ERR_NONE) + if ((dev->open) (raw, disk) == GRUB_ERR_NONE) break; else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) grub_errno = GRUB_ERR_NONE; @@ -294,8 +294,8 @@ grub_disk_close (grub_disk_t disk) grub_partition_t part; grub_dprintf ("disk", "Closing `%s'.\n", disk->name); - if (disk->dev && disk->dev->disk_close) - (disk->dev->disk_close) (disk); + if (disk->dev && disk->dev->close) + (disk->dev->close) (disk); /* Reset the timer. */ grub_last_time = grub_get_time_ms (); @@ -341,10 +341,10 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector, < (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) { grub_err_t err; - err = (disk->dev->disk_read) (disk, transform_sector (disk, sector), - 1U << (GRUB_DISK_CACHE_BITS - + GRUB_DISK_SECTOR_BITS - - disk->log_sector_size), tmp_buf); + err = (disk->dev->read) (disk, transform_sector (disk, sector), + 1U << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS + - disk->log_sector_size), tmp_buf); if (!err) { /* Copy it and store it in the disk cache. */ @@ -377,8 +377,8 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector, if (!tmp_buf) return grub_errno; - if ((disk->dev->disk_read) (disk, transform_sector (disk, aligned_sector), - num, tmp_buf)) + if ((disk->dev->read) (disk, transform_sector (disk, aligned_sector), + num, tmp_buf)) { grub_error_push (); grub_dprintf ("disk", "%s read failed\n", disk->name); @@ -483,11 +483,11 @@ grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, { grub_disk_addr_t i; - err = (disk->dev->disk_read) (disk, transform_sector (disk, sector), - agglomerate << (GRUB_DISK_CACHE_BITS - + GRUB_DISK_SECTOR_BITS - - disk->log_sector_size), - buf); + err = (disk->dev->read) (disk, transform_sector (disk, sector), + agglomerate << (GRUB_DISK_CACHE_BITS + + GRUB_DISK_SECTOR_BITS + - disk->log_sector_size), + buf); if (err) return err; diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c index 48eb5e7b6..6850e0497 100644 --- a/grub-core/kern/dl.c +++ b/grub-core/kern/dl.c @@ -225,7 +225,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) unsigned i; const Elf_Shdr *s; grub_size_t tsize = 0, talign = 1; -#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) +#if !defined (__i386__) && !defined (__x86_64__) grub_size_t tramp; grub_size_t got; grub_err_t err; @@ -241,7 +241,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) talign = s->sh_addralign; } -#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) +#if !defined (__i386__) && !defined (__x86_64__) err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got); if (err) return err; @@ -304,7 +304,7 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e) mod->segment = seg; } } -#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) +#if !defined (__i386__) && !defined (__x86_64__) ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN); mod->tramp = ptr; mod->trampptr = ptr; @@ -333,17 +333,14 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) if (s->sh_type == SHT_SYMTAB) break; - /* Module without symbol table may still be used to pull in dependencies. - We verify at build time that such modules do not contain any relocations - that may reference symbol table. */ if (i == e->e_shnum) - return GRUB_ERR_NONE; + return grub_error (GRUB_ERR_BAD_MODULE, N_("no symbol table")); #ifdef GRUB_MODULES_MACHINE_READONLY mod->symtab = grub_malloc (s->sh_size); if (!mod->symtab) return grub_errno; - grub_memcpy (mod->symtab, (char *) e + s->sh_offset, s->sh_size); + memcpy (mod->symtab, (char *) e + s->sh_offset, s->sh_size); #else mod->symtab = (Elf_Sym *) ((char *) e + s->sh_offset); #endif @@ -579,9 +576,6 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) if (seg) { - if (!mod->symtab) - return grub_error (GRUB_ERR_BAD_MODULE, "relocation without symbol table"); - err = grub_arch_dl_relocate_symbols (mod, ehdr, s, seg); if (err) return err; @@ -611,7 +605,7 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) } /* Make sure that every section is within the core. */ - if (size < e->e_shoff + (grub_uint32_t) e->e_shentsize * e->e_shnum) + if (size < e->e_shoff + e->e_shentsize * e->e_shnum) { grub_error (GRUB_ERR_BAD_OS, "ELF sections outside core"); return 0; @@ -688,7 +682,7 @@ grub_dl_load_file (const char *filename) grub_boot_time ("Loading module %s", filename); - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); + file = grub_file_open (filename); if (! file) return 0; diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index e0165e74c..b9eb1ab1e 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -27,7 +27,6 @@ #include #include #include -#include /* The handle of GRUB itself. Filled in by the startup code. */ grub_efi_handle_t grub_efi_image_handle; @@ -154,20 +153,10 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle) GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); } -void -grub_reboot (void) -{ - grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | - GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); - efi_call_4 (grub_efi_system_table->runtime_services->reset_system, - GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); - for (;;) ; -} - void grub_exit (void) { - grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); + grub_efi_fini (); efi_call_4 (grub_efi_system_table->boot_services->exit, grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0); for (;;) ; @@ -203,7 +192,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, len = grub_strlen (var); len16 = len * GRUB_MAX_UTF16_PER_UTF8; - var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); if (!var16) return grub_errno; len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); @@ -216,7 +205,6 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS | GRUB_EFI_VARIABLE_RUNTIME_ACCESS), datasize, data); - grub_free (var16); if (status == GRUB_EFI_SUCCESS) return GRUB_ERR_NONE; @@ -238,7 +226,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, len = grub_strlen (var); len16 = len * GRUB_MAX_UTF16_PER_UTF8; - var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); if (!var16) return NULL; len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); @@ -248,11 +236,8 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, NULL); - if (status != GRUB_EFI_BUFFER_TOO_SMALL || !datasize) - { - grub_free (var16); - return NULL; - } + if (!datasize) + return NULL; data = grub_malloc (datasize); if (!data) @@ -309,23 +294,13 @@ grub_efi_modules_addr (void) } if (i == coff_header->num_sections) - { - grub_dprintf("sections", "section %d is last section; invalid.\n", i); - return 0; - } + return 0; info = (struct grub_module_info *) ((char *) image->image_base + section->virtual_address); - if (section->name[0] != '.' && info->magic != GRUB_MODULE_MAGIC) - { - grub_dprintf("sections", - "section %d has bad magic %08x, should be %08x\n", - i, info->magic, GRUB_MODULE_MAGIC); - return 0; - } + if (info->magic != GRUB_MODULE_MAGIC) + return 0; - grub_dprintf("sections", "returning section info for section %d: \"%s\"\n", - i, section->name); return (grub_addr_t) info; } @@ -338,12 +313,9 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) grub_size_t filesize = 0; grub_efi_device_path_t *dp; - if (!dp0) - return NULL; - dp = dp0; - while (dp) + while (1) { grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); @@ -353,15 +325,9 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE) { - grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); - - if (len < 4) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "malformed EFI Device Path node has length=%d", len); - return NULL; - } - len = (len - 4) / sizeof (grub_efi_char16_t); + grub_efi_uint16_t len; + len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) + / sizeof (grub_efi_char16_t)); filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2; } @@ -377,7 +343,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) if (!name) return NULL; - while (dp) + while (1) { grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); @@ -389,34 +355,14 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) { grub_efi_file_path_device_path_t *fp; grub_efi_uint16_t len; - grub_efi_char16_t *dup_name; *p++ = '/'; - len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); - if (len < 4) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "malformed EFI Device Path node has length=%d", len); - return NULL; - } - - len = (len - 4) / sizeof (grub_efi_char16_t); + len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) + / sizeof (grub_efi_char16_t)); fp = (grub_efi_file_path_device_path_t *) dp; - /* According to EFI spec Path Name is NULL terminated */ - while (len > 0 && fp->path_name[len - 1] == 0) - len--; - dup_name = grub_calloc (len, sizeof (*dup_name)); - if (!dup_name) - { - grub_free (name); - return NULL; - } - p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, - grub_memcpy (dup_name, fp->path_name, len * sizeof (*dup_name)), - len); - grub_free (dup_name); + p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); } dp = GRUB_EFI_NEXT_DEVICE_PATH (dp); @@ -448,66 +394,6 @@ grub_efi_get_device_path (grub_efi_handle_t handle) GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); } -/* Return the device path node right before the end node. */ -grub_efi_device_path_t * -grub_efi_find_last_device_path (const grub_efi_device_path_t *dp) -{ - grub_efi_device_path_t *next, *p; - - if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) - return 0; - - for (p = (grub_efi_device_path_t *) dp, next = GRUB_EFI_NEXT_DEVICE_PATH (p); - ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (next); - p = next, next = GRUB_EFI_NEXT_DEVICE_PATH (next)) - ; - - return p; -} - -/* Duplicate a device path. */ -grub_efi_device_path_t * -grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp) -{ - grub_efi_device_path_t *p; - grub_size_t total_size = 0; - - for (p = (grub_efi_device_path_t *) dp; - ; - p = GRUB_EFI_NEXT_DEVICE_PATH (p)) - { - grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (p); - - /* - * In the event that we find a node that's completely garbage, for - * example if we get to 0x7f 0x01 0x02 0x00 ... (EndInstance with a size - * of 2), GRUB_EFI_END_ENTIRE_DEVICE_PATH() will be true and - * GRUB_EFI_NEXT_DEVICE_PATH() will return NULL, so we won't continue, - * and neither should our consumers, but there won't be any error raised - * even though the device path is junk. - * - * This keeps us from passing junk down back to our caller. - */ - if (len < 4) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "malformed EFI Device Path node has length=%d", len); - return NULL; - } - - total_size += len; - if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p)) - break; - } - - p = grub_malloc (total_size); - if (! p) - return 0; - - grub_memcpy (p, dp, total_size); - return p; -} - static void dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) { @@ -540,7 +426,7 @@ dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) void grub_efi_print_device_path (grub_efi_device_path_t *dp) { - while (GRUB_EFI_DEVICE_PATH_VALID (dp)) + while (1) { grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); @@ -865,20 +751,9 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) fp = (grub_efi_file_path_device_path_t *) dp; buf = grub_malloc ((len - 4) * 2 + 1); if (buf) - { - grub_efi_char16_t *dup_name = grub_malloc (len - 4); - if (!dup_name) - { - grub_errno = GRUB_ERR_NONE; - grub_printf ("/File((null))"); - grub_free (buf); - break; - } - *grub_utf16_to_utf8 (buf, grub_memcpy (dup_name, fp->path_name, len - 4), + *grub_utf16_to_utf8 (buf, fp->path_name, (len - 4) / sizeof (grub_efi_char16_t)) - = '\0'; - grub_free (dup_name); - } + = '\0'; else grub_errno = GRUB_ERR_NONE; grub_printf ("/File(%s)", buf); @@ -952,10 +827,7 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, /* Return non-zero. */ return 1; - if (dp1 == dp2) - return 0; - - while (GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) + while (1) { grub_efi_uint8_t type1, type2; grub_efi_uint8_t subtype1, subtype2; @@ -991,14 +863,5 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); } - /* - * There's no "right" answer here, but we probably don't want to call a valid - * dp and an invalid dp equal, so pick one way or the other. - */ - if (GRUB_EFI_DEVICE_PATH_VALID (dp1) && !GRUB_EFI_DEVICE_PATH_VALID (dp2)) - return 1; - else if (!GRUB_EFI_DEVICE_PATH_VALID (dp1) && GRUB_EFI_DEVICE_PATH_VALID (dp2)) - return -1; - return 0; } diff --git a/grub-core/kern/efi/fdt.c b/grub-core/kern/efi/fdt.c deleted file mode 100644 index 30100c61c..000000000 --- a/grub-core/kern/efi/fdt.c +++ /dev/null @@ -1,43 +0,0 @@ -/* fdt.c - EFI Flattened Device Tree interaction */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -void * -grub_efi_get_firmware_fdt (void) -{ - grub_efi_configuration_table_t *tables; - grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; - void *firmware_fdt = NULL; - unsigned int i; - - /* Look for FDT in UEFI config tables. */ - tables = grub_efi_system_table->configuration_table; - - for (i = 0; i < grub_efi_system_table->num_table_entries; i++) - if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) - { - firmware_fdt = tables[i].vendor_table; - grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); - break; - } - - return firmware_fdt; -} diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 2c31847bf..e9c85de12 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -59,13 +59,10 @@ grub_machine_get_bootlocation (char **device, char **path) if (!image) return; *device = grub_efidisk_get_device_name (image->device_handle); - if (!*device && grub_efi_net_config) - { - grub_efi_net_config (image->device_handle, device, path); - return; - } - *path = grub_efi_get_filename (image->file_path); + if (!*device && grub_efi_net_config) + grub_efi_net_config (image->device_handle, device, path); + if (*path) { /* Get the directory. */ diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 457772d57..20a47aaf5 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -49,133 +49,55 @@ static grub_efi_uintn_t finish_desc_size; static grub_efi_uint32_t finish_desc_version; int grub_efi_is_finished = 0; -/* - * We need to roll back EFI allocations on exit. Remember allocations that - * we'll free on exit. - */ -struct efi_allocation; -struct efi_allocation { - grub_efi_physical_address_t address; - grub_efi_uint64_t pages; - struct efi_allocation *next; -}; -static struct efi_allocation *efi_allocated_memory; - -static void -grub_efi_store_alloc (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) -{ - grub_efi_boot_services_t *b; - struct efi_allocation *alloc; - grub_efi_status_t status; - - b = grub_efi_system_table->boot_services; - status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, - sizeof(*alloc), (void**)&alloc); - - if (status == GRUB_EFI_SUCCESS) - { - alloc->next = efi_allocated_memory; - alloc->address = address; - alloc->pages = pages; - efi_allocated_memory = alloc; - } - else - grub_printf ("Could not malloc memory to remember EFI allocation. " - "Exiting GRUB won't free all memory.\n"); -} - -static void -grub_efi_drop_alloc (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) -{ - struct efi_allocation *ea, *eap; - grub_efi_boot_services_t *b; - - b = grub_efi_system_table->boot_services; - - for (eap = NULL, ea = efi_allocated_memory; ea; eap = ea, ea = ea->next) - { - if (ea->address != address || ea->pages != pages) - continue; - - /* Remove the current entry from the list. */ - if (eap) - eap->next = ea->next; - else - efi_allocated_memory = ea->next; - - /* Then free the memory backing it. */ - efi_call_1 (b->free_pool, ea); - - /* And leave, we're done. */ - break; - } -} - /* Allocate pages. Return the pointer to the first of allocated pages. */ void * -grub_efi_allocate_pages_real (grub_efi_physical_address_t address, - grub_efi_uintn_t pages, - grub_efi_allocate_type_t alloctype, - grub_efi_memory_type_t memtype) +grub_efi_allocate_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) { + grub_efi_allocate_type_t type; grub_efi_status_t status; grub_efi_boot_services_t *b; +#if 1 /* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > GRUB_EFI_MAX_USABLE_ADDRESS) + return 0; +#endif + +#if 1 + if (address == 0) { - grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("invalid memory address (0x%llx > 0x%llx)"), - address, GRUB_EFI_MAX_USABLE_ADDRESS); - return NULL; + type = GRUB_EFI_ALLOCATE_MAX_ADDRESS; + address = GRUB_EFI_MAX_USABLE_ADDRESS; } + else + type = GRUB_EFI_ALLOCATE_ADDRESS; +#else + if (address == 0) + type = GRUB_EFI_ALLOCATE_ANY_PAGES; + else + type = GRUB_EFI_ALLOCATE_ADDRESS; +#endif b = grub_efi_system_table->boot_services; - status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); + status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); if (status != GRUB_EFI_SUCCESS) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - return NULL; - } + return 0; if (address == 0) { /* Uggh, the address 0 was allocated... This is too annoying, so reallocate another one. */ address = GRUB_EFI_MAX_USABLE_ADDRESS; - status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); + status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); grub_efi_free_pages (0, pages); if (status != GRUB_EFI_SUCCESS) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - return NULL; - } + return 0; } - grub_efi_store_alloc (address, pages); - return (void *) ((grub_addr_t) address); } -void * -grub_efi_allocate_any_pages (grub_efi_uintn_t pages) -{ - return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS, - pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, - GRUB_EFI_LOADER_DATA); -} - -void * -grub_efi_allocate_fixed (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) -{ - return grub_efi_allocate_pages_real (address, pages, - GRUB_EFI_ALLOCATE_ADDRESS, - GRUB_EFI_LOADER_DATA); -} - /* Free pages starting from ADDRESS. */ void grub_efi_free_pages (grub_efi_physical_address_t address, @@ -185,8 +107,6 @@ grub_efi_free_pages (grub_efi_physical_address_t address, b = grub_efi_system_table->boot_services; efi_call_2 (b->free_pages, address, pages); - - grub_efi_drop_alloc (address, pages); } #if defined (__i386__) || defined (__x86_64__) @@ -297,30 +217,6 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf, return GRUB_ERR_NONE; } -/* - * To obtain the UEFI memory map, we must pass a buffer of sufficient size - * to hold the entire map. This function returns a sane start value for - * buffer size. - */ -grub_efi_uintn_t -grub_efi_find_mmap_size (void) -{ - grub_efi_uintn_t mmap_size = 0; - grub_efi_uintn_t desc_size; - - if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0) - { - grub_error (GRUB_ERR_IO, "cannot get EFI memory map size"); - return 0; - } - - /* - * Add an extra page, since UEFI can alter the memory map itself on - * callbacks or explicit calls, including console output. - */ - return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_SIZE); -} - /* Get the memory map as defined in the EFI spec. Return 1 if successful, return 0 if partial, or return -1 if an error occurs. */ int @@ -506,9 +402,7 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, pages = required_pages; } - addr = grub_efi_allocate_pages_real (start, pages, - GRUB_EFI_ALLOCATE_ADDRESS, - GRUB_EFI_LOADER_CODE); + addr = grub_efi_allocate_pages (start, pages); if (! addr) grub_fatal ("cannot allocate conventional memory %p with %u pages", (void *) ((grub_addr_t) start), @@ -525,20 +419,6 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map, grub_fatal ("too little memory"); } -void -grub_efi_memory_fini (void) -{ - /* - * Free all stale allocations. grub_efi_free_pages() will remove - * the found entry from the list and it will always find the first - * list entry (efi_allocated_memory is the list start). Hence we - * remove all entries from the list until none is left altogether. - */ - while (efi_allocated_memory) - grub_efi_free_pages (efi_allocated_memory->address, - efi_allocated_memory->pages); -} - #if 0 /* Print the memory map. */ static void @@ -574,7 +454,8 @@ grub_efi_mm_init (void) int mm_status; /* Prepare a memory region to store two memory maps. */ - memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + memory_map = grub_efi_allocate_pages (0, + 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); if (! memory_map) grub_fatal ("cannot allocate memory"); @@ -592,7 +473,7 @@ grub_efi_mm_init (void) /* Freeing/allocating operations may increase memory map size. */ map_size += desc_size * 32; - memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (map_size)); + memory_map = grub_efi_allocate_pages (0, 2 * BYTES_TO_PAGES (map_size)); if (! memory_map) grub_fatal ("cannot allocate memory"); @@ -644,34 +525,3 @@ grub_efi_mm_init (void) grub_efi_free_pages ((grub_addr_t) memory_map, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } - -#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) -grub_err_t -grub_efi_get_ram_base(grub_addr_t *base_addr) -{ - grub_efi_memory_descriptor_t *memory_map, *desc; - grub_efi_uintn_t memory_map_size, desc_size; - int ret; - - memory_map_size = grub_efi_find_mmap_size(); - - memory_map = grub_malloc (memory_map_size); - if (! memory_map) - return GRUB_ERR_OUT_OF_MEMORY; - ret = grub_efi_get_memory_map (&memory_map_size, memory_map, NULL, - &desc_size, NULL); - - if (ret < 1) - return GRUB_ERR_BUG; - - for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS; - (grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size); - desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) - if (desc->attribute & GRUB_EFI_MEMORY_WB) - *base_addr = grub_min (*base_addr, desc->physical_start); - - grub_free(memory_map); - - return GRUB_ERR_NONE; -} -#endif diff --git a/grub-core/kern/elf.c b/grub-core/kern/elf.c index 9d7149b38..5f99c43cc 100644 --- a/grub-core/kern/elf.c +++ b/grub-core/kern/elf.c @@ -28,25 +28,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); -#pragma GCC diagnostic ignored "-Wcast-align" - -#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) -#define GRUB_ELF_ENABLE_BI_ENDIAN 1 -#else -#define GRUB_ELF_ENABLE_BI_ENDIAN 0 -#endif - -#if defined(GRUB_CPU_WORDS_BIGENDIAN) -#define GRUB_ELF_NATIVE_ENDIANNESS ELFDATA2MSB -#define GRUB_ELF_OPPOSITE_ENDIANNESS ELFDATA2LSB -#else -#define GRUB_ELF_NATIVE_ENDIANNESS ELFDATA2LSB -#define GRUB_ELF_OPPOSITE_ENDIANNESS ELFDATA2MSB -#endif - -static int grub_elf32_check_endianess_and_bswap_ehdr (grub_elf_t elf); -static int grub_elf64_check_endianess_and_bswap_ehdr (grub_elf_t elf); - /* Check if EHDR is a valid ELF header. */ static grub_err_t grub_elf_check_header (grub_elf_t elf) @@ -57,25 +38,8 @@ grub_elf_check_header (grub_elf_t elf) || e->e_ident[EI_MAG1] != ELFMAG1 || e->e_ident[EI_MAG2] != ELFMAG2 || e->e_ident[EI_MAG3] != ELFMAG3 - || e->e_ident[EI_VERSION] != EV_CURRENT) - return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic")); - - if (grub_elf_is_elf32 (elf)) - { - if (!grub_elf32_check_endianess_and_bswap_ehdr (elf)) { - return grub_error (GRUB_ERR_BAD_OS, "invalid ELF endianness magic"); - } - } - else if (grub_elf_is_elf64 (elf)) - { - if (!grub_elf64_check_endianess_and_bswap_ehdr (elf)) { - return grub_error (GRUB_ERR_BAD_OS, "invalid ELF endianness magic"); - } - } - else - return grub_error (GRUB_ERR_BAD_OS, "unknown ELF class"); - - if (e->e_version != EV_CURRENT) + || e->e_ident[EI_VERSION] != EV_CURRENT + || e->e_version != EV_CURRENT) return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-independent ELF magic")); return GRUB_ERR_NONE; @@ -136,12 +100,12 @@ fail: } grub_elf_t -grub_elf_open (const char *name, enum grub_file_type type) +grub_elf_open (const char *name) { grub_file_t file; grub_elf_t elf; - file = grub_file_open (name, type); + file = grub_file_open (name); if (! file) return 0; @@ -153,9 +117,6 @@ grub_elf_open (const char *name, enum grub_file_type type) } -#define grub_swap_bytes_halfXX grub_swap_bytes16 -#define grub_swap_bytes_wordXX grub_swap_bytes32 - /* 32-bit */ #define ehdrXX ehdr32 #define ELFCLASSXX ELFCLASS32 @@ -166,12 +127,7 @@ grub_elf_open (const char *name, enum grub_file_type type) #define grub_elf_is_elfXX grub_elf_is_elf32 #define grub_elfXX_load_phdrs grub_elf32_load_phdrs #define ElfXX_Phdr Elf32_Phdr -#define ElfXX_Ehdr Elf32_Ehdr #define grub_uintXX_t grub_uint32_t -#define grub_swap_bytes_addrXX grub_swap_bytes32 -#define grub_swap_bytes_offXX grub_swap_bytes32 -#define grub_swap_bytes_XwordXX grub_swap_bytes32 -#define grub_elfXX_check_endianess_and_bswap_ehdr grub_elf32_check_endianess_and_bswap_ehdr #include "elfXX.c" @@ -184,12 +140,7 @@ grub_elf_open (const char *name, enum grub_file_type type) #undef grub_elf_is_elfXX #undef grub_elfXX_load_phdrs #undef ElfXX_Phdr -#undef ElfXX_Ehdr #undef grub_uintXX_t -#undef grub_swap_bytes_addrXX -#undef grub_swap_bytes_offXX -#undef grub_swap_bytes_XwordXX -#undef grub_elfXX_check_endianess_and_bswap_ehdr /* 64-bit */ @@ -202,11 +153,6 @@ grub_elf_open (const char *name, enum grub_file_type type) #define grub_elf_is_elfXX grub_elf_is_elf64 #define grub_elfXX_load_phdrs grub_elf64_load_phdrs #define ElfXX_Phdr Elf64_Phdr -#define ElfXX_Ehdr Elf64_Ehdr #define grub_uintXX_t grub_uint64_t -#define grub_swap_bytes_addrXX grub_swap_bytes64 -#define grub_swap_bytes_offXX grub_swap_bytes64 -#define grub_swap_bytes_XwordXX grub_swap_bytes64 -#define grub_elfXX_check_endianess_and_bswap_ehdr grub_elf64_check_endianess_and_bswap_ehdr #include "elfXX.c" diff --git a/grub-core/kern/elfXX.c b/grub-core/kern/elfXX.c index 1859d1880..1d0997186 100644 --- a/grub-core/kern/elfXX.c +++ b/grub-core/kern/elfXX.c @@ -12,7 +12,7 @@ grub_elfXX_load_phdrs (grub_elf_t elf) if (elf->phdrs) return GRUB_ERR_NONE; - phdrs_size = (grub_uint32_t) elf->ehdr.ehdrXX.e_phnum * elf->ehdr.ehdrXX.e_phentsize; + phdrs_size = elf->ehdr.ehdrXX.e_phnum * elf->ehdr.ehdrXX.e_phentsize; grub_dprintf ("elf", "Loading program headers at 0x%llx, size 0x%lx.\n", (unsigned long long) elf->ehdr.ehdrXX.e_phoff, @@ -31,25 +31,6 @@ grub_elfXX_load_phdrs (grub_elf_t elf) return grub_errno; } -#if GRUB_ELF_ENABLE_BI_ENDIAN - if (elf->ehdr.ehdrXX.e_ident[EI_DATA] == GRUB_ELF_OPPOSITE_ENDIANNESS) - { - ElfXX_Phdr *phdr; - for (phdr = elf->phdrs; (char *) phdr < (char *) elf->phdrs + phdrs_size; - phdr = (ElfXX_Phdr *) ((char *) phdr + elf->ehdr.ehdrXX.e_phentsize)) - { - phdr->p_type = grub_swap_bytes_wordXX (phdr->p_type); - phdr->p_flags = grub_swap_bytes_wordXX (phdr->p_flags); - phdr->p_offset = grub_swap_bytes_offXX (phdr->p_offset); - phdr->p_vaddr = grub_swap_bytes_addrXX (phdr->p_vaddr); - phdr->p_paddr = grub_swap_bytes_addrXX (phdr->p_paddr); - phdr->p_filesz = grub_swap_bytes_XwordXX (phdr->p_filesz); - phdr->p_memsz = grub_swap_bytes_XwordXX (phdr->p_memsz); - phdr->p_align = grub_swap_bytes_XwordXX (phdr->p_align); - } - } -#endif /* GRUB_ELF_ENABLE_BI_ENDIAN */ - return GRUB_ERR_NONE; } @@ -173,35 +154,3 @@ grub_elfXX_load (grub_elf_t elf, const char *filename, return grub_errno; } - -static int -grub_elfXX_check_endianess_and_bswap_ehdr (grub_elf_t elf) -{ - ElfXX_Ehdr *e = &(elf->ehdr.ehdrXX); - if (e->e_ident[EI_DATA] == GRUB_ELF_NATIVE_ENDIANNESS) - { - return 1; - } - -#if GRUB_ELF_ENABLE_BI_ENDIAN - if (e->e_ident[EI_DATA] == GRUB_ELF_OPPOSITE_ENDIANNESS) - { - e->e_type = grub_swap_bytes_halfXX (e->e_type); - e->e_machine = grub_swap_bytes_halfXX (e->e_machine); - e->e_version = grub_swap_bytes_wordXX (e->e_version); - e->e_entry = grub_swap_bytes_addrXX (e->e_entry); - e->e_phoff = grub_swap_bytes_offXX (e->e_phoff); - e->e_shoff = grub_swap_bytes_offXX (e->e_shoff); - e->e_flags = grub_swap_bytes_wordXX (e->e_flags); - e->e_ehsize = grub_swap_bytes_halfXX (e->e_ehsize); - e->e_phentsize = grub_swap_bytes_halfXX (e->e_phentsize); - e->e_phnum = grub_swap_bytes_halfXX (e->e_phnum); - e->e_shentsize = grub_swap_bytes_halfXX (e->e_shentsize); - e->e_shnum = grub_swap_bytes_halfXX (e->e_shnum); - e->e_shstrndx = grub_swap_bytes_halfXX (e->e_shstrndx); - return 1; - } -#endif /* GRUB_ELF_ENABLE_BI_ENDIAN */ - - return 0; -} diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c index 113682cc4..07be6756f 100644 --- a/grub-core/kern/emu/cache.c +++ b/grub-core/kern/emu/cache.c @@ -8,7 +8,7 @@ #include "../ia64/cache.c" #elif defined (__arm__) || defined (__aarch64__) -void __clear_cache (void *beg, void *end); +void __clear_cache (char *beg, char *end); void grub_arch_sync_caches (void *address, grub_size_t len) @@ -25,11 +25,5 @@ grub_arch_sync_caches (void *address, grub_size_t len) return _flush_cache (address, len, 0); } -#elif defined(__riscv) -void -grub_arch_sync_caches (void *address, grub_size_t len) -{ -} - #endif diff --git a/grub-core/kern/emu/cache_s.S b/grub-core/kern/emu/cache_s.S index 2245cddc3..76cf7560d 100644 --- a/grub-core/kern/emu/cache_s.S +++ b/grub-core/kern/emu/cache_s.S @@ -8,8 +8,7 @@ #include "../sparc64/cache.S" #elif defined(__powerpc__) #include "../powerpc/cache.S" -#elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \ - defined(__mips__) || defined(__riscv) +#elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || defined(__mips__) #else #error "No target cpu type is defined" #endif diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index d975265b2..a4ebf78a9 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -161,9 +161,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) { struct stat st; # if GRUB_DISK_DEVS_ARE_CHAR - if (fstat (fd, &st) >= 0 && S_ISCHR (st.st_mode)) + if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode)) # else - if (fstat (fd, &st) >= 0 && S_ISBLK (st.st_mode)) + if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode)) # endif data->is_disk = 1; } @@ -184,7 +184,7 @@ grub_hostdisk_os_dev_to_grub_drive (const char *os_disk, int add) unsigned int i; char *canon; - canon = grub_canonicalize_file_name (os_disk); + canon = canonicalize_file_name (os_disk); if (!canon) canon = xstrdup (os_disk); @@ -388,11 +388,11 @@ static struct grub_disk_dev grub_util_biosdisk_dev = { .name = "hostdisk", .id = GRUB_DISK_DEVICE_HOSTDISK_ID, - .disk_iterate = grub_util_biosdisk_iterate, - .disk_open = grub_util_biosdisk_open, - .disk_close = grub_util_biosdisk_close, - .disk_read = grub_util_biosdisk_read, - .disk_write = grub_util_biosdisk_write, + .iterate = grub_util_biosdisk_iterate, + .open = grub_util_biosdisk_open, + .close = grub_util_biosdisk_close, + .read = grub_util_biosdisk_read, + .write = grub_util_biosdisk_write, .next = 0 }; @@ -422,7 +422,7 @@ read_device_map (const char *dev_map) char buf[1024]; /* XXX */ int lineno = 0; - if (!dev_map || dev_map[0] == '\0') + if (dev_map[0] == '\0') { grub_util_info ("no device.map"); return; @@ -535,7 +535,7 @@ read_device_map (const char *dev_map) /* On Linux, the devfs uses symbolic links horribly, and that confuses the interface very much, so use realpath to expand symbolic links. */ - map[drive].device = grub_canonicalize_file_name (p); + map[drive].device = canonicalize_file_name (p); if (! map[drive].device) map[drive].device = xstrdup (p); @@ -615,7 +615,7 @@ static char * grub_util_path_concat_real (size_t n, int ext, va_list ap) { size_t totlen = 0; - char **l = xcalloc (n + ext, sizeof (l[0])); + char **l = xmalloc ((n + ext) * sizeof (l[0])); char *r, *p, *pi; size_t i; int first = 1; diff --git a/grub-core/kern/emu/hostfs.c b/grub-core/kern/emu/hostfs.c index cb532105e..823116da6 100644 --- a/grub-core/kern/emu/hostfs.c +++ b/grub-core/kern/emu/hostfs.c @@ -19,6 +19,11 @@ #include +/* Legacy feature macro.*/ +#define _BSD_SOURCE +/* New feature macro that provides everything _BSD_SOURCE and + * _SVID_SOURCE provided and possibly more. */ +#define _DEFAULT_SOURCE #include #include #include @@ -173,17 +178,14 @@ grub_hostfs_label (grub_device_t device __attribute ((unused)), return GRUB_ERR_NONE; } -#undef open -#undef close - static struct grub_fs grub_hostfs_fs = { .name = "hostfs", - .fs_dir = grub_hostfs_dir, - .fs_open = grub_hostfs_open, - .fs_read = grub_hostfs_read, - .fs_close = grub_hostfs_close, - .fs_label = grub_hostfs_label, + .dir = grub_hostfs_dir, + .open = grub_hostfs_open, + .read = grub_hostfs_read, + .close = grub_hostfs_close, + .label = grub_hostfs_label, .next = 0 }; diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c index b327d4e41..b2fc93d7f 100644 --- a/grub-core/kern/emu/lite.c +++ b/grub-core/kern/emu/lite.c @@ -24,8 +24,6 @@ #elif defined(__aarch64__) #include "../arm64/dl_helper.c" #include "../arm64/dl.c" -#elif defined(__riscv) -#include "../riscv/dl.c" #else #error "No target cpu type is defined" #endif diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c index 425bb9603..4b509139c 100644 --- a/grub-core/kern/emu/main.c +++ b/grub-core/kern/emu/main.c @@ -63,13 +63,6 @@ void grub_reboot (void) { longjmp (main_env, 1); - grub_fatal ("longjmp failed"); -} - -void -grub_exit (void) -{ - grub_reboot (); } void @@ -93,16 +86,11 @@ grub_machine_fini (int flags) -#define OPT_MEMDISK 257 - static struct argp_option options[] = { {"root", 'r', N_("DEVICE_NAME"), 0, N_("Set root device."), 2}, {"device-map", 'm', N_("FILE"), 0, /* TRANSLATORS: There are many devices in device map. */ N_("use FILE as the device map [default=%s]"), 0}, - {"memdisk", OPT_MEMDISK, N_("FILE"), 0, - /* TRANSLATORS: There are many devices in device map. */ - N_("use FILE as memdisk"), 0}, {"directory", 'd', N_("DIR"), 0, N_("use GRUB files in the directory DIR [default=%s]"), 0}, {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, @@ -131,7 +119,6 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused))) struct arguments { const char *dev_map; - const char *mem_disk; int hold; }; @@ -144,9 +131,6 @@ argp_parser (int key, char *arg, struct argp_state *state) switch (key) { - case OPT_MEMDISK: - arguments->mem_disk = arg; - break; case 'r': free (root_dev); root_dev = xstrdup (arg); @@ -196,13 +180,9 @@ main (int argc, char *argv[]) struct arguments arguments = { .dev_map = DEFAULT_DEVICE_MAP, - .hold = 0, - .mem_disk = 0, + .hold = 0 }; volatile int hold = 0; - size_t total_module_size = sizeof (struct grub_module_info), memdisk_size = 0; - struct grub_module_info *modinfo; - void *mods; grub_util_host_init (&argc, &argv); @@ -214,33 +194,6 @@ main (int argc, char *argv[]) exit(1); } - if (arguments.mem_disk) - { - memdisk_size = ALIGN_UP(grub_util_get_image_size (arguments.mem_disk), 512); - total_module_size += memdisk_size + sizeof (struct grub_module_header); - } - - mods = xmalloc (total_module_size); - modinfo = grub_memset (mods, 0, total_module_size); - mods = (char *) (modinfo + 1); - - modinfo->magic = GRUB_MODULE_MAGIC; - modinfo->offset = sizeof (struct grub_module_info); - modinfo->size = total_module_size; - - if (arguments.mem_disk) - { - struct grub_module_header *header = (struct grub_module_header *) mods; - header->type = OBJ_TYPE_MEMDISK; - header->size = memdisk_size + sizeof (*header); - mods = header + 1; - - grub_util_load_image (arguments.mem_disk, mods); - mods = (char *) mods + memdisk_size; - } - - grub_modbase = (grub_addr_t) modinfo; - hold = arguments.hold; /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */ if (hold && verbosity > 0) diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c index dfd8a8ec4..bb606da28 100644 --- a/grub-core/kern/emu/misc.c +++ b/grub-core/kern/emu/misc.c @@ -16,9 +16,7 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_BUILD #include -#endif #include #include @@ -85,18 +83,6 @@ grub_util_error (const char *fmt, ...) exit (1); } -void * -xcalloc (grub_size_t nmemb, grub_size_t size) -{ - void *p; - - p = calloc (nmemb, size); - if (!p) - grub_util_error ("%s", _("out of memory")); - - return p; -} - void * xmalloc (grub_size_t size) { @@ -141,7 +127,6 @@ xasprintf (const char *fmt, ...) va_start (ap, fmt); result = grub_xvasprintf (fmt, ap); - va_end (ap); if (!result) grub_util_error ("%s", _("out of memory")); @@ -149,13 +134,11 @@ xasprintf (const char *fmt, ...) } #endif -#if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) void grub_exit (void) { exit (1); } -#endif grub_uint64_t grub_get_time_ms (void) @@ -166,51 +149,3 @@ grub_get_time_ms (void) return (tv.tv_sec * 1000 + tv.tv_usec / 1000); } - -size_t -grub_util_get_image_size (const char *path) -{ - FILE *f; - size_t ret; - off_t sz; - - f = grub_util_fopen (path, "rb"); - - if (!f) - grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); - - fseeko (f, 0, SEEK_END); - - sz = ftello (f); - if (sz < 0) - grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); - if (sz != (size_t) sz) - grub_util_error (_("file `%s' is too big"), path); - ret = (size_t) sz; - - fclose (f); - - return ret; -} - -void -grub_util_load_image (const char *path, char *buf) -{ - FILE *fp; - size_t size; - - grub_util_info ("reading %s", path); - - size = grub_util_get_image_size (path); - - fp = grub_util_fopen (path, "rb"); - if (! fp) - grub_util_error (_("cannot open `%s': %s"), path, - strerror (errno)); - - if (fread (buf, 1, size, fp) != size) - grub_util_error (_("cannot read `%s': %s"), path, - strerror (errno)); - - fclose (fp); -} diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c index 4d1046a21..f262e95e3 100644 --- a/grub-core/kern/emu/mm.c +++ b/grub-core/kern/emu/mm.c @@ -25,16 +25,6 @@ #include #include -void * -grub_calloc (grub_size_t nmemb, grub_size_t size) -{ - void *ret; - ret = calloc (nmemb, size); - if (!ret) - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - return ret; -} - void * grub_malloc (grub_size_t size) { @@ -60,8 +50,7 @@ grub_zalloc (grub_size_t size) void grub_free (void *ptr) { - if (ptr) - free (ptr); + free (ptr); } void * diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 58454458c..24da12bb9 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -28,7 +28,8 @@ void (*EXPORT_VAR (grub_grubnet_fini)) (void); -grub_file_filter_t grub_file_filters[GRUB_FILE_FILTER_MAX]; +grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX]; +grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX]; /* Get the device part of the filename NAME. It is enclosed by parentheses. */ char * @@ -58,7 +59,7 @@ grub_file_get_device_name (const char *name) } grub_file_t -grub_file_open (const char *name, enum grub_file_type type) +grub_file_open (const char *name) { grub_device_t device = 0; grub_file_t file = 0, last_file = 0; @@ -88,16 +89,7 @@ grub_file_open (const char *name, enum grub_file_type type) file->device = device; - /* In case of relative pathnames and non-Unix systems (like Windows) - * name of host files may not start with `/'. Blocklists for host files - * are meaningless as well (for a start, host disk does not allow any direct - * access - it is just a marker). So skip host disk in this case. - */ - if (device->disk && file_name[0] != '/' -#if defined(GRUB_UTIL) || defined(GRUB_MACHINE_EMU) - && grub_strcmp (device->disk->name, "host") -#endif - ) + if (device->disk && file_name[0] != '/') /* This is a block list. */ file->fs = &grub_fs_blocklist; else @@ -107,26 +99,24 @@ grub_file_open (const char *name, enum grub_file_type type) goto fail; } - if ((file->fs->fs_open) (file, file_name) != GRUB_ERR_NONE) + if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE) goto fail; file->name = grub_strdup (name); grub_errno = GRUB_ERR_NONE; - for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters); + for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled); filter++) - if (grub_file_filters[filter]) + if (grub_file_filters_enabled[filter]) { last_file = file; - file = grub_file_filters[filter] (file, type); - if (file && file != last_file) - { - file->name = grub_strdup (name); - grub_errno = GRUB_ERR_NONE; - } + file = grub_file_filters_enabled[filter] (file, name); } if (!file) grub_file_close (last_file); + + grub_memcpy (grub_file_filters_enabled, grub_file_filters_all, + sizeof (grub_file_filters_enabled)); return file; @@ -138,6 +128,9 @@ grub_file_open (const char *name, enum grub_file_type type) grub_free (file); + grub_memcpy (grub_file_filters_enabled, grub_file_filters_all, + sizeof (grub_file_filters_enabled)); + return 0; } @@ -177,7 +170,7 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) file->read_hook_data = file; file->progress_offset = file->offset; } - res = (file->fs->fs_read) (file, buf, len); + res = (file->fs->read) (file, buf, len); file->read_hook = read_hook; file->read_hook_data = read_hook_data; if (res > 0) @@ -189,8 +182,8 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len) grub_err_t grub_file_close (grub_file_t file) { - if (file->fs->fs_close) - (file->fs->fs_close) (file); + if (file->fs->close) + (file->fs->close) (file); if (file->device) grub_device_close (file->device); diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c index fb30da9f4..9085895b6 100644 --- a/grub-core/kern/fs.c +++ b/grub-core/kern/fs.c @@ -64,13 +64,13 @@ grub_fs_probe (grub_device_t device) if (grub_strcmp (p->name, "btrfs") == 0) { char *label = 0; - p->fs_uuid (device, &label); + p->uuid (device, &label); if (label) grub_free (label); } else #endif - (p->fs_dir) (device, "/", probe_dummy_iter, NULL); + (p->dir) (device, "/", probe_dummy_iter, NULL); if (grub_errno == GRUB_ERR_NONE) return p; @@ -94,7 +94,7 @@ grub_fs_probe (grub_device_t device) { p = grub_fs_list; - (p->fs_dir) (device, "/", probe_dummy_iter, NULL); + (p->dir) (device, "/", probe_dummy_iter, NULL); if (grub_errno == GRUB_ERR_NONE) { count--; @@ -134,7 +134,7 @@ struct grub_fs_block static grub_err_t grub_fs_blocklist_open (grub_file_t file, const char *name) { - const char *p = name; + char *p = (char *) name; unsigned num = 0; unsigned i; grub_disk_t disk = file->device->disk; @@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) while (p); /* Allocate a block list. */ - blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); + blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); if (! blocks) return 0; @@ -243,9 +243,9 @@ grub_fs_blocklist_read (grub_file_t file, char *buf, grub_size_t len) struct grub_fs grub_fs_blocklist = { .name = "blocklist", - .fs_dir = 0, - .fs_open = grub_fs_blocklist_open, - .fs_read = grub_fs_blocklist_read, - .fs_close = 0, + .dir = 0, + .open = grub_fs_blocklist_open, + .read = grub_fs_blocklist_read, + .close = 0, .next = 0 }; diff --git a/grub-core/kern/i386/coreboot/cbtable.c b/grub-core/kern/i386/coreboot/cbtable.c index 34a2b59be..1669bc0ca 100644 --- a/grub-core/kern/i386/coreboot/cbtable.c +++ b/grub-core/kern/i386/coreboot/cbtable.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include @@ -25,20 +25,59 @@ GRUB_MOD_LICENSE ("GPLv3+"); -grub_linuxbios_table_header_t -grub_linuxbios_get_tables (void) +/* Helper for grub_linuxbios_table_iterate. */ +static int +check_signature (grub_linuxbios_table_header_t tbl_header) { - grub_linuxbios_table_header_t table_header; - /* Assuming table_header is aligned to its size (8 bytes). */ - for (table_header = (grub_linuxbios_table_header_t) 0x500; - table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++) - if (grub_linuxbios_check_signature (table_header)) - return table_header; - - for (table_header = (grub_linuxbios_table_header_t) 0xf0000; - table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++) - if (grub_linuxbios_check_signature (table_header)) - return table_header; + if (! grub_memcmp (tbl_header->signature, "LBIO", 4)) + return 1; + + return 0; +} + +grub_err_t +grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t, + void *), + void *hook_data) +{ + grub_linuxbios_table_header_t table_header; + grub_linuxbios_table_item_t table_item; + + /* Assuming table_header is aligned to its size (8 bytes). */ + + for (table_header = (grub_linuxbios_table_header_t) 0x500; + table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++) + if (check_signature (table_header)) + goto signature_found; + + for (table_header = (grub_linuxbios_table_header_t) 0xf0000; + table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++) + if (check_signature (table_header)) + goto signature_found; + + return 0; + +signature_found: + + table_item = + (grub_linuxbios_table_item_t) ((char *) table_header + + table_header->header_size); + for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header + + table_header->header_size + + table_header->table_size); + table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size)) + { + if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK + && check_signature ((grub_linuxbios_table_header_t) (grub_addr_t) + *(grub_uint64_t *) (table_item + 1))) + { + table_header = (grub_linuxbios_table_header_t) (grub_addr_t) + *(grub_uint64_t *) (table_item + 1); + goto signature_found; + } + if (hook (table_item, hook_data)) + return 1; + } return 0; } diff --git a/grub-core/kern/coreboot/mmap.c b/grub-core/kern/i386/coreboot/mmap.c similarity index 97% rename from grub-core/kern/coreboot/mmap.c rename to grub-core/kern/i386/coreboot/mmap.c index caf8f7cef..4d29f6b7d 100644 --- a/grub-core/kern/coreboot/mmap.c +++ b/grub-core/kern/i386/coreboot/mmap.c @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#include -#include +#include +#include #include #include #include @@ -49,7 +49,6 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data) { grub_uint64_t start = mem_region->addr; grub_uint64_t end = mem_region->addr + mem_region->size; -#ifdef __i386__ /* Mark region 0xa0000 - 0x100000 as reserved. */ if (start < 0x100000 && end >= 0xa0000 && mem_region->type == GRUB_MACHINE_MEMORY_AVAILABLE) @@ -76,7 +75,6 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data) if (end <= start) continue; } -#endif if (ctx->hook (start, end - start, /* Multiboot mmaps match with the coreboot mmap definition. Therefore, we can just pass type diff --git a/grub-core/kern/i386/coreboot/startup.S b/grub-core/kern/i386/coreboot/startup.S index c8486548d..8c3283846 100644 --- a/grub-core/kern/i386/coreboot/startup.S +++ b/grub-core/kern/i386/coreboot/startup.S @@ -61,3 +61,8 @@ multiboot_header: /* checksum */ .long -0x1BADB002 - MULTIBOOT_MEMORY_INFO +/* + * prot_to_real and associated structures (but NOT real_to_prot, that is + * only needed for BIOS gates). + */ +#include "../realmode.S" diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c index 46476e27e..a28316cc6 100644 --- a/grub-core/kern/i386/efi/init.c +++ b/grub-core/kern/i386/efi/init.c @@ -38,11 +38,6 @@ grub_machine_init (void) void grub_machine_fini (int flags) { - if (!(flags & GRUB_LOADER_FLAG_NORETURN)) - return; - - grub_efi_fini (); - - if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) - grub_efi_memory_fini (); + if (flags & GRUB_LOADER_FLAG_NORETURN) + grub_efi_fini (); } diff --git a/grub-core/kern/i386/efi/tsc.c b/grub-core/kern/i386/efi/tsc.c deleted file mode 100644 index 4b93ba8e1..000000000 --- a/grub-core/kern/i386/efi/tsc.c +++ /dev/null @@ -1,40 +0,0 @@ -/* kern/i386/tsc.c - x86 TSC time source implementation - * Requires Pentium or better x86 CPU that supports the RDTSC instruction. - * This module uses the PIT to calibrate the TSC to - * real time. - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -int -grub_tsc_calibrate_from_efi (void) -{ - grub_uint64_t start_tsc, end_tsc; - /* Use EFI Time Service to calibrate TSC */ - start_tsc = grub_get_tsc (); - efi_call_1 (grub_efi_system_table->boot_services->stall, 1000); - end_tsc = grub_get_tsc (); - grub_tsc_rate = grub_divmod64 ((1ULL << 32), end_tsc - start_tsc, 0); - return 1; -} diff --git a/grub-core/kern/i386/int.S b/grub-core/kern/i386/int.S index 862a54202..7edace404 100644 --- a/grub-core/kern/i386/int.S +++ b/grub-core/kern/i386/int.S @@ -44,13 +44,6 @@ FUNCTION(grub_bios_interrupt) movl 24(%edx), %esi movl 28(%edx), %edx - /* - Via C3 CPUs have cache coherence problems, so we need to call - wbinvd at these 2 points. As wbinvd slows down boot, don't do - it on non-VIA. 9090 is nop nop. */ -VARIABLE(grub_bios_via_workaround1) - .byte 0x90, 0x90 - PROT_TO_REAL .code16 pushf @@ -99,10 +92,6 @@ intno: movw %ax, LOCAL(bios_register_es) popf - -VARIABLE(grub_bios_via_workaround2) - .byte 0x90, 0x90 - REAL_TO_PROT .code32 diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c index 27bc68b8a..3c8160aab 100644 --- a/grub-core/kern/i386/pc/init.c +++ b/grub-core/kern/i386/pc/init.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -185,26 +184,6 @@ mmap_iterate_hook (grub_uint64_t addr, grub_uint64_t size, return 0; } -extern grub_uint16_t grub_bios_via_workaround1, grub_bios_via_workaround2; - -/* Via needs additional wbinvd. */ -static void -grub_via_workaround_init (void) -{ - grub_uint32_t manufacturer[3], max_cpuid; - if (! grub_cpu_is_cpuid_supported ()) - return; - - grub_cpuid (0, max_cpuid, manufacturer[0], manufacturer[2], manufacturer[1]); - - if (grub_memcmp (manufacturer, "CentaurHauls", 12) != 0) - return; - - grub_bios_via_workaround1 = 0x090f; - grub_bios_via_workaround2 = 0x090f; - asm volatile ("wbinvd"); -} - void grub_machine_init (void) { @@ -214,9 +193,6 @@ grub_machine_init (void) #endif grub_addr_t modend; - /* This has to happen before any BIOS calls. */ - grub_via_workaround_init (); - grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + (_edata - _start); /* Initialize the console as early as possible. */ diff --git a/grub-core/kern/i386/pc/mmap.c b/grub-core/kern/i386/pc/mmap.c index c0c3c3585..f1375f3e1 100644 --- a/grub-core/kern/i386/pc/mmap.c +++ b/grub-core/kern/i386/pc/mmap.c @@ -148,7 +148,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) while (1) { - grub_memset (entry, 0, sizeof (*entry)); + grub_memset (entry, 0, sizeof (entry)); cont = grub_get_mmap_entry (entry, cont); diff --git a/grub-core/kern/i386/pc/startup.S b/grub-core/kern/i386/pc/startup.S index b8a9b33b4..6bb36c603 100644 --- a/grub-core/kern/i386/pc/startup.S +++ b/grub-core/kern/i386/pc/startup.S @@ -135,7 +135,7 @@ LOCAL(prot_to_real_addr): .macro REAL_TO_PROT movl LOCAL(real_to_prot_addr), %eax - calll *%eax + DATA32 call *%ax .endm /* diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S index 0d89858d9..3d47d1e4f 100644 --- a/grub-core/kern/i386/qemu/startup.S +++ b/grub-core/kern/i386/qemu/startup.S @@ -28,7 +28,7 @@ _start: jmp codestart - .org GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR + . = _start + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR VARIABLE(grub_core_entry_addr) .long 0 @@ -73,3 +73,5 @@ codestart: 1: hlt jmp 1b + +#include "../realmode.S" diff --git a/grub-core/kern/i386/realmode.S b/grub-core/kern/i386/realmode.S index 998fdc756..541cedc87 100644 --- a/grub-core/kern/i386/realmode.S +++ b/grub-core/kern/i386/realmode.S @@ -54,7 +54,7 @@ protstack: .endm .macro REAL_TO_PROT - calll real_to_prot + DATA32 call real_to_prot .endm /* @@ -137,22 +137,7 @@ real_to_prot: /* load the GDT register */ xorw %ax, %ax movw %ax, %ds -#ifdef GRUB_MACHINE_QEMU - /* - qemu is special: gdtdesc is in ROM. - %cs = 0xf000 - _start + GRUB_BOOT_MACHINE_SIZE = 0x100000 - So - _start + GRUB_BOOT_MACHINE_SIZE - 0x10000 points to the same point - as %cs. - gdtdesc - (_start + GRUB_BOOT_MACHINE_SIZE - 0x10000) - = gdtdesc - _start - GRUB_BOOT_MACHINE_SIZE + 0x10000 - but the later can be computed by assembly. - */ - lgdtl %cs:(gdtdesc - _start - GRUB_BOOT_MACHINE_SIZE + 0x10000) -#else - lgdtl gdtdesc -#endif + DATA32 ADDR32 lgdt gdtdesc /* turn on protected mode */ movl %cr0, %eax @@ -160,7 +145,7 @@ real_to_prot: movl %eax, %cr0 /* jump to relocation, flush prefetch queue, and reload %cs */ - ljmpl $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg + DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg .code32 protcseg: @@ -193,9 +178,6 @@ protcseg: /* return on the old (or initialized) stack! */ ret - /* prot_to_real assumes that this code is under 64K which is not - true for qemu. */ -#ifndef GRUB_MACHINE_QEMU /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2009,2010 Free Software Foundation, Inc. @@ -255,7 +237,7 @@ tmpcseg: movl %eax, %cr0 /* flush prefetch queue, reload %cs */ - ljmpl $0, $realcseg + DATA32 ljmp $0, $realcseg realcseg: /* we are in real mode now @@ -276,6 +258,6 @@ realcseg: #endif /* return on new stack! */ - retl -#endif + DATA32 ret + .code32 diff --git a/grub-core/kern/i386/tsc.c b/grub-core/kern/i386/tsc.c index 9293b161d..d7d1783e4 100644 --- a/grub-core/kern/i386/tsc.c +++ b/grub-core/kern/i386/tsc.c @@ -1,6 +1,7 @@ /* kern/i386/tsc.c - x86 TSC time source implementation * Requires Pentium or better x86 CPU that supports the RDTSC instruction. - * This module calibrates the TSC to real time. + * This module uses the RTC (via grub_get_rtc()) to calibrate the TSC to + * real time. * * GRUB -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. @@ -24,6 +25,12 @@ #include #include #include +#ifdef GRUB_MACHINE_XEN +#include +#else +#include +#endif +#include /* This defines the value TSC had at the epoch (that is, when we calibrated it). */ static grub_uint64_t tsc_boot_time; @@ -33,6 +40,66 @@ static grub_uint64_t tsc_boot_time; in 32-bit. */ grub_uint32_t grub_tsc_rate; +/* Read the TSC value, which increments with each CPU clock cycle. */ +static __inline grub_uint64_t +grub_get_tsc (void) +{ + grub_uint32_t lo, hi; + grub_uint32_t a,b,c,d; + + /* The CPUID instruction is a 'serializing' instruction, and + avoids out-of-order execution of the RDTSC instruction. */ + grub_cpuid (0,a,b,c,d); + /* Read TSC value. We cannot use "=A", since this would use + %rax on x86_64. */ + __asm__ __volatile__ ("rdtsc":"=a" (lo), "=d" (hi)); + + return (((grub_uint64_t) hi) << 32) | lo; +} + +static __inline int +grub_cpu_is_tsc_supported (void) +{ + grub_uint32_t a,b,c,d; + if (! grub_cpu_is_cpuid_supported ()) + return 0; + + grub_cpuid(1,a,b,c,d); + + return (d & (1 << 4)) != 0; +} + +#ifndef GRUB_MACHINE_XEN + +static void +grub_pit_wait (grub_uint16_t tics) +{ + /* Disable timer2 gate and speaker. */ + grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) + & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), + GRUB_PIT_SPEAKER_PORT); + + /* Set tics. */ + grub_outb (GRUB_PIT_CTRL_SELECT_2 | GRUB_PIT_CTRL_READLOAD_WORD, + GRUB_PIT_CTRL); + grub_outb (tics & 0xff, GRUB_PIT_COUNTER_2); + grub_outb (tics >> 8, GRUB_PIT_COUNTER_2); + + /* Enable timer2 gate, keep speaker disabled. */ + grub_outb ((grub_inb (GRUB_PIT_SPEAKER_PORT) & ~ GRUB_PIT_SPK_DATA) + | GRUB_PIT_SPK_TMR2, + GRUB_PIT_SPEAKER_PORT); + + /* Wait. */ + while ((grub_inb (GRUB_PIT_SPEAKER_PORT) & GRUB_PIT_SPK_TMR2_LATCH) == 0x00); + + /* Disable timer2 gate and speaker. */ + grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) + & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), + GRUB_PIT_SPEAKER_PORT); +} +#endif + static grub_uint64_t grub_tsc_get_time_ms (void) { @@ -43,36 +110,52 @@ grub_tsc_get_time_ms (void) return ((al * grub_tsc_rate) >> 32) + ah * grub_tsc_rate; } -static int -calibrate_tsc_hardcode (void) +#ifndef GRUB_MACHINE_XEN +/* Calibrate the TSC based on the RTC. */ +static void +calibrate_tsc (void) { - grub_tsc_rate = 5368;/* 800 MHz */ - return 1; + /* First calibrate the TSC rate (relative, not absolute time). */ + grub_uint64_t end_tsc; + + tsc_boot_time = grub_get_tsc (); + grub_pit_wait (0xffff); + end_tsc = grub_get_tsc (); + + grub_tsc_rate = 0; + if (end_tsc > tsc_boot_time) + grub_tsc_rate = grub_divmod64 ((55ULL << 32), end_tsc - tsc_boot_time, 0); + if (grub_tsc_rate == 0) + grub_tsc_rate = 5368;/* 800 MHz */ } +#endif void grub_tsc_init (void) { - if (!grub_cpu_is_tsc_supported ()) +#ifdef GRUB_MACHINE_XEN + grub_uint64_t t; + tsc_boot_time = grub_get_tsc (); + t = grub_xen_shared_info->vcpu_info[0].time.tsc_to_system_mul; + if (grub_xen_shared_info->vcpu_info[0].time.tsc_shift > 0) + t <<= grub_xen_shared_info->vcpu_info[0].time.tsc_shift; + else + t >>= -grub_xen_shared_info->vcpu_info[0].time.tsc_shift; + grub_tsc_rate = grub_divmod64 (t, 1000000, 0); + grub_install_get_time_ms (grub_tsc_get_time_ms); +#else + if (grub_cpu_is_tsc_supported ()) + { + calibrate_tsc (); + grub_install_get_time_ms (grub_tsc_get_time_ms); + } + else { #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_IEEE1275) grub_install_get_time_ms (grub_rtc_get_time_ms); #else grub_fatal ("no TSC found"); #endif - return; } - - tsc_boot_time = grub_get_tsc (); - -#if defined (GRUB_MACHINE_XEN) || defined (GRUB_MACHINE_XEN_PVH) - (void) (grub_tsc_calibrate_from_xen () || calibrate_tsc_hardcode()); -#elif defined (GRUB_MACHINE_EFI) - (void) (grub_tsc_calibrate_from_pmtimer () || grub_tsc_calibrate_from_pit () || grub_tsc_calibrate_from_efi() || calibrate_tsc_hardcode()); -#elif defined (GRUB_MACHINE_COREBOOT) - (void) (grub_tsc_calibrate_from_pmtimer () || grub_tsc_calibrate_from_pit () || calibrate_tsc_hardcode()); -#else - (void) (grub_tsc_calibrate_from_pit () || calibrate_tsc_hardcode()); #endif - grub_install_get_time_ms (grub_tsc_get_time_ms); } diff --git a/grub-core/kern/i386/tsc_pit.c b/grub-core/kern/i386/tsc_pit.c deleted file mode 100644 index 67990bfa6..000000000 --- a/grub-core/kern/i386/tsc_pit.c +++ /dev/null @@ -1,84 +0,0 @@ -/* kern/i386/tsc.c - x86 TSC time source implementation - * Requires Pentium or better x86 CPU that supports the RDTSC instruction. - * This module uses the PIT to calibrate the TSC to - * real time. - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -static int -grub_pit_wait (void) -{ - int ret = 0; - - /* Disable timer2 gate and speaker. */ - grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) - & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), - GRUB_PIT_SPEAKER_PORT); - - /* Set tics. */ - grub_outb (GRUB_PIT_CTRL_SELECT_2 | GRUB_PIT_CTRL_READLOAD_WORD, - GRUB_PIT_CTRL); - /* 0xffff ticks: 55ms. */ - grub_outb (0xff, GRUB_PIT_COUNTER_2); - grub_outb (0xff, GRUB_PIT_COUNTER_2); - - /* Enable timer2 gate, keep speaker disabled. */ - grub_outb ((grub_inb (GRUB_PIT_SPEAKER_PORT) & ~ GRUB_PIT_SPK_DATA) - | GRUB_PIT_SPK_TMR2, - GRUB_PIT_SPEAKER_PORT); - - if ((grub_inb (GRUB_PIT_SPEAKER_PORT) & GRUB_PIT_SPK_TMR2_LATCH) == 0x00) { - ret = 1; - /* Wait. */ - while ((grub_inb (GRUB_PIT_SPEAKER_PORT) & GRUB_PIT_SPK_TMR2_LATCH) == 0x00); - } - - /* Disable timer2 gate and speaker. */ - grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) - & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), - GRUB_PIT_SPEAKER_PORT); - - return ret; -} - -/* Calibrate the TSC based on the RTC. */ -int -grub_tsc_calibrate_from_pit (void) -{ - /* First calibrate the TSC rate (relative, not absolute time). */ - grub_uint64_t start_tsc, end_tsc; - - start_tsc = grub_get_tsc (); - if (!grub_pit_wait ()) - return 0; - end_tsc = grub_get_tsc (); - - grub_tsc_rate = 0; - if (end_tsc > start_tsc) - grub_tsc_rate = grub_divmod64 ((55ULL << 32), end_tsc - start_tsc, 0); - if (grub_tsc_rate == 0) - return 0; - return 1; -} diff --git a/grub-core/kern/i386/tsc_pmtimer.c b/grub-core/kern/i386/tsc_pmtimer.c deleted file mode 100644 index c9c361699..000000000 --- a/grub-core/kern/i386/tsc_pmtimer.c +++ /dev/null @@ -1,88 +0,0 @@ -/* kern/i386/tsc.c - x86 TSC time source implementation - * Requires Pentium or better x86 CPU that supports the RDTSC instruction. - * This module uses the PIT to calibrate the TSC to - * real time. - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -grub_uint64_t -grub_pmtimer_wait_count_tsc (grub_port_t pmtimer, - grub_uint16_t num_pm_ticks) -{ - grub_uint32_t start; - grub_uint32_t last; - grub_uint32_t cur, end; - grub_uint64_t start_tsc; - grub_uint64_t end_tsc; - int num_iter = 0; - - start = grub_inl (pmtimer) & 0xffffff; - last = start; - end = start + num_pm_ticks; - start_tsc = grub_get_tsc (); - while (1) - { - cur = grub_inl (pmtimer) & 0xffffff; - if (cur < last) - cur |= 0x1000000; - num_iter++; - if (cur >= end) - { - end_tsc = grub_get_tsc (); - return end_tsc - start_tsc; - } - /* Check for broken PM timer. - 50000000 TSCs is between 5 ms (10GHz) and 200 ms (250 MHz) - if after this time we still don't have 1 ms on pmtimer, then - pmtimer is broken. - */ - if ((num_iter & 0xffffff) == 0 && grub_get_tsc () - start_tsc > 5000000) { - return 0; - } - } -} - -int -grub_tsc_calibrate_from_pmtimer (void) -{ - struct grub_acpi_fadt *fadt; - grub_port_t pmtimer; - grub_uint64_t tsc_diff; - - fadt = grub_acpi_find_fadt (); - if (!fadt) - return 0; - pmtimer = fadt->pmtimer; - if (!pmtimer) - return 0; - - /* It's 3.579545 MHz clock. Wait 1 ms. */ - tsc_diff = grub_pmtimer_wait_count_tsc (pmtimer, 3580); - if (tsc_diff == 0) - return 0; - grub_tsc_rate = grub_divmod64 ((1ULL << 32), tsc_diff, 0); - return 1; -} diff --git a/grub-core/kern/i386/xen/pvh.c b/grub-core/kern/i386/xen/pvh.c deleted file mode 100644 index 91fbca859..000000000 --- a/grub-core/kern/i386/xen/pvh.c +++ /dev/null @@ -1,369 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define XEN_MEMORY_MAP_SIZE 128 - -grub_uint64_t grub_rsdp_addr; - -static char hypercall_page[GRUB_XEN_PAGE_SIZE] - __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE))); - -static grub_uint32_t xen_cpuid_base; -static struct start_info grub_xen_start_page; -static struct grub_e820_mmap_entry map[XEN_MEMORY_MAP_SIZE]; -static unsigned int nr_map_entries; - -static void -grub_xen_cons_msg (const char *msg) -{ - const char *c; - - for (c = msg; *c; c++) - grub_outb (*c, XEN_HVM_DEBUGCONS_IOPORT); -} - -static void -grub_xen_panic (const char *msg) -{ - grub_xen_cons_msg (msg); - grub_xen_cons_msg ("System halted!\n"); - - asm volatile ("cli"); - - while (1) - { - asm volatile ("hlt"); - } -} - -static void -grub_xen_cpuid_base (void) -{ - grub_uint32_t base, eax, signature[3]; - - for (base = 0x40000000; base < 0x40010000; base += 0x100) - { - grub_cpuid (base, eax, signature[0], signature[1], signature[2]); - if (!grub_memcmp ("XenVMMXenVMM", signature, 12) && (eax - base) >= 2) - { - xen_cpuid_base = base; - return; - } - } - - grub_xen_panic ("Found no Xen signature!\n"); -} - -static void -grub_xen_setup_hypercall_page (void) -{ - grub_uint32_t msr, addr, eax, ebx, ecx, edx; - - /* Get base address of Xen-specific MSRs. */ - grub_cpuid (xen_cpuid_base + 2, eax, ebx, ecx, edx); - msr = ebx; - addr = (grub_uint32_t) (&hypercall_page); - - /* Specify hypercall page address for Xen. */ - asm volatile ("wrmsr" : : "c" (msr), "a" (addr), "d" (0) : "memory"); -} - -int -grub_xen_hypercall (grub_uint32_t callno, grub_uint32_t a0, - grub_uint32_t a1, grub_uint32_t a2, - grub_uint32_t a3, grub_uint32_t a4, - grub_uint32_t a5 __attribute__ ((unused))) -{ - grub_uint32_t res; - - asm volatile ("call *%[callno]" - : "=a" (res), "+b" (a0), "+c" (a1), "+d" (a2), - "+S" (a3), "+D" (a4) - : [callno] "a" (&hypercall_page[callno * 32]) - : "memory"); - return res; -} - -static grub_uint32_t -grub_xen_get_param (int idx) -{ - struct xen_hvm_param xhv; - int r; - - xhv.domid = DOMID_SELF; - xhv.index = idx; - r = grub_xen_hypercall (__HYPERVISOR_hvm_op, HVMOP_get_param, - (grub_uint32_t) (&xhv), 0, 0, 0, 0); - if (r < 0) - grub_xen_panic ("Could not get parameter from Xen!\n"); - return xhv.value; -} - -static void * -grub_xen_add_physmap (unsigned int space, void *addr) -{ - struct xen_add_to_physmap xatp; - - xatp.domid = DOMID_SELF; - xatp.idx = 0; - xatp.space = space; - xatp.gpfn = (grub_addr_t) addr >> GRUB_XEN_LOG_PAGE_SIZE; - if (grub_xen_hypercall (__HYPERVISOR_memory_op, XENMEM_add_to_physmap, - (grub_uint32_t) (&xatp), 0, 0, 0, 0)) - grub_xen_panic ("Memory_op hypercall failed!\n"); - return addr; -} - -static void -grub_xen_sort_mmap (void) -{ - grub_uint64_t from, to; - unsigned int i; - struct grub_e820_mmap_entry tmp; - - /* Align map entries to page boundaries. */ - for (i = 0; i < nr_map_entries; i++) - { - from = map[i].addr; - to = from + map[i].len; - if (map[i].type == GRUB_MEMORY_AVAILABLE) - { - from = ALIGN_UP (from, GRUB_XEN_PAGE_SIZE); - to = ALIGN_DOWN (to, GRUB_XEN_PAGE_SIZE); - } - else - { - from = ALIGN_DOWN (from, GRUB_XEN_PAGE_SIZE); - to = ALIGN_UP (to, GRUB_XEN_PAGE_SIZE); - } - map[i].addr = from; - map[i].len = to - from; - } - - again: - /* Sort entries by start address. */ - for (i = 1; i < nr_map_entries; i++) - { - if (map[i].addr >= map[i - 1].addr) - continue; - tmp = map[i]; - map[i] = map[i - 1]; - map[i - 1] = tmp; - i = 0; - } - - /* Detect overlapping areas. */ - for (i = 1; i < nr_map_entries; i++) - { - if (map[i].addr >= map[i - 1].addr + map[i - 1].len) - continue; - tmp = map[i - 1]; - map[i - 1].len = map[i].addr - map[i - 1].addr; - if (map[i].addr + map[i].len >= tmp.addr + tmp.len) - continue; - if (nr_map_entries < ARRAY_SIZE (map)) - { - map[nr_map_entries].addr = map[i].addr + map[i].len; - map[nr_map_entries].len = tmp.addr + tmp.len - map[nr_map_entries].addr; - map[nr_map_entries].type = tmp.type; - nr_map_entries++; - goto again; - } - } - - /* Merge adjacent entries. */ - for (i = 1; i < nr_map_entries; i++) - { - if (map[i].type == map[i - 1].type && - map[i].addr == map[i - 1].addr + map[i - 1].len) - { - map[i - 1].len += map[i].len; - map[i] = map[nr_map_entries - 1]; - nr_map_entries--; - goto again; - } - } -} - -static void -grub_xen_get_mmap (void) -{ - struct xen_memory_map memmap; - - memmap.nr_entries = ARRAY_SIZE (map); - set_xen_guest_handle (memmap.buffer, map); - if (grub_xen_hypercall (__HYPERVISOR_memory_op, XENMEM_memory_map, - (grub_uint32_t) (&memmap), 0, 0, 0, 0)) - grub_xen_panic ("Could not get memory map from Xen!\n"); - nr_map_entries = memmap.nr_entries; - - grub_xen_sort_mmap (); -} - -static void -grub_xen_set_mmap (void) -{ - struct xen_foreign_memory_map memmap; - - memmap.domid = DOMID_SELF; - memmap.map.nr_entries = nr_map_entries; - set_xen_guest_handle (memmap.map.buffer, map); - grub_xen_hypercall (__HYPERVISOR_memory_op, XENMEM_set_memory_map, - (grub_uint32_t) (&memmap), 0, 0, 0, 0); -} - -static void -grub_xen_mm_init_regions (void) -{ - grub_uint64_t modend, from, to; - unsigned int i; - - modend = grub_modules_get_end (); - - for (i = 0; i < nr_map_entries; i++) - { - if (map[i].type != GRUB_MEMORY_AVAILABLE) - continue; - from = map[i].addr; - to = from + map[i].len; - if (from < modend) - from = modend; - if (from >= to || from >= (1ULL << 32)) - continue; - if (to > (1ULL << 32)) - to = 1ULL << 32; - grub_mm_init_region ((void *) (grub_addr_t) from, to - from); - } -} - -static grub_uint64_t -grub_xen_find_page (grub_uint64_t start) -{ - unsigned int i, j; - grub_uint64_t last = start; - - /* - * Try to find a e820 map hole below 4G. - * Relies on page-aligned entries (addr and len) and input (start). - */ - - for (i = 0; i < nr_map_entries; i++) - { - if (last > map[i].addr + map[i].len) - continue; - if (last < map[i].addr) - return last; - if ((map[i].addr >> 32) || ((map[i].addr + map[i].len) >> 32)) - break; - last = map[i].addr + map[i].len; - } - if (i == nr_map_entries) - return last; - - /* No hole found, use the highest RAM page below 4G and reserve it. */ - if (nr_map_entries == ARRAY_SIZE (map)) - grub_xen_panic ("Memory map size limit reached!\n"); - for (i = 0, j = 0; i < nr_map_entries; i++) - { - if (map[i].type != GRUB_MEMORY_AVAILABLE) - continue; - if (map[i].addr >> 32) - break; - j = i; - if ((map[i].addr + map[i].len) >> 32) - break; - } - if (map[j].type != GRUB_MEMORY_AVAILABLE) - grub_xen_panic ("No free memory page found!\n"); - if ((map[j].addr + map[j].len) >> 32) - last = (1ULL << 32) - GRUB_XEN_PAGE_SIZE; - else - last = map[j].addr + map[j].len - GRUB_XEN_PAGE_SIZE; - map[nr_map_entries].addr = last; - map[nr_map_entries].len = GRUB_XEN_PAGE_SIZE; - map[nr_map_entries].type = GRUB_MEMORY_RESERVED; - nr_map_entries++; - grub_xen_sort_mmap (); - - return last; -} - -void -grub_xen_setup_pvh (void) -{ - grub_addr_t par; - - grub_xen_cpuid_base (); - grub_xen_setup_hypercall_page (); - grub_xen_get_mmap (); - - /* Setup Xen data. */ - grub_xen_start_page_addr = &grub_xen_start_page; - - par = grub_xen_get_param (HVM_PARAM_CONSOLE_PFN); - grub_xen_start_page_addr->console.domU.mfn = par; - grub_xen_xcons = (void *) (grub_addr_t) (par << GRUB_XEN_LOG_PAGE_SIZE); - par = grub_xen_get_param (HVM_PARAM_CONSOLE_EVTCHN); - grub_xen_start_page_addr->console.domU.evtchn = par; - - par = grub_xen_get_param (HVM_PARAM_STORE_PFN); - grub_xen_start_page_addr->store_mfn = par; - grub_xen_xenstore = (void *) (grub_addr_t) (par << GRUB_XEN_LOG_PAGE_SIZE); - par = grub_xen_get_param (HVM_PARAM_STORE_EVTCHN); - grub_xen_start_page_addr->store_evtchn = par; - - par = grub_xen_find_page (0); - grub_xen_grant_table = grub_xen_add_physmap (XENMAPSPACE_grant_table, - (void *) par); - par = grub_xen_find_page (par + GRUB_XEN_PAGE_SIZE); - grub_xen_shared_info = grub_xen_add_physmap (XENMAPSPACE_shared_info, - (void *) par); - grub_xen_set_mmap (); - - grub_xen_mm_init_regions (); - - grub_rsdp_addr = pvh_start_info->rsdp_paddr; -} - -grub_err_t -grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) -{ - unsigned int i; - - for (i = 0; i < nr_map_entries; i++) - { - if (map[i].len && hook (map[i].addr, map[i].len, map[i].type, hook_data)) - break; - } - - return GRUB_ERR_NONE; -} diff --git a/grub-core/kern/i386/xen/startup_pvh.S b/grub-core/kern/i386/xen/startup_pvh.S deleted file mode 100644 index 363c31858..000000000 --- a/grub-core/kern/i386/xen/startup_pvh.S +++ /dev/null @@ -1,81 +0,0 @@ -/* startup.S - bootstrap GRUB itself */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - - .file "startup_pvh.S" - .text - .globl start, _start - .code32 - -start: -_start: - cld - lgdt gdtdesc - ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f -1: - movl $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %eax - mov %eax, %ds - mov %eax, %es - mov %eax, %fs - mov %eax, %gs - mov %eax, %ss - leal LOCAL(stack_end), %esp - - /* Save address of start info structure. */ - mov %ebx, pvh_start_info - call EXT_C(grub_main) - /* Doesn't return. */ - - .p2align 3 -gdt: - .word 0, 0 - .byte 0, 0, 0, 0 - - /* -- code segment -- - * base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present - * type = 32bit code execute/read, DPL = 0 - */ - .word 0xFFFF, 0 - .byte 0, 0x9A, 0xCF, 0 - - /* -- data segment -- - * base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present - * type = 32 bit data read/write, DPL = 0 - */ - .word 0xFFFF, 0 - .byte 0, 0x92, 0xCF, 0 - - .p2align 3 -/* this is the GDT descriptor */ -gdtdesc: - .word 0x17 /* limit */ - .long gdt /* addr */ - - .p2align 2 -/* Saved pointer to start info structure. */ - .globl pvh_start_info -pvh_start_info: - .long 0 - - .bss - .space GRUB_MEMORY_MACHINE_PROT_STACK_SIZE -LOCAL(stack_end): diff --git a/grub-core/kern/i386/xen/tsc.c b/grub-core/kern/i386/xen/tsc.c deleted file mode 100644 index 8792b308d..000000000 --- a/grub-core/kern/i386/xen/tsc.c +++ /dev/null @@ -1,40 +0,0 @@ -/* kern/i386/tsc.c - x86 TSC time source implementation - * Requires Pentium or better x86 CPU that supports the RDTSC instruction. - * This module uses the PIT to calibrate the TSC to - * real time. - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -int -grub_tsc_calibrate_from_xen (void) -{ - grub_uint64_t t; - t = grub_xen_shared_info->vcpu_info[0].time.tsc_to_system_mul; - if (grub_xen_shared_info->vcpu_info[0].time.tsc_shift > 0) - t <<= grub_xen_shared_info->vcpu_info[0].time.tsc_shift; - else - t >>= -grub_xen_shared_info->vcpu_info[0].time.tsc_shift; - grub_tsc_rate = grub_divmod64 (t, 1000000, 0); - return 1; -} diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c index ebcf31629..ad79eb525 100644 --- a/grub-core/kern/ia64/dl.c +++ b/grub-core/kern/ia64/dl.c @@ -104,9 +104,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, case R_IA64_PCREL64LSB: *(grub_uint64_t *) addr += value - addr; break; - case R_IA64_GPREL64I: - grub_ia64_set_immu64 (addr, value - (grub_addr_t) mod->base); - break; case R_IA64_GPREL22: if ((value - (grub_addr_t) mod->base) & ~MASK20) return grub_error (GRUB_ERR_BAD_MODULE, @@ -119,7 +116,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, case R_IA64_LTOFF22: if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) value = *(grub_uint64_t *) sym->st_value + rel->r_addend; - /* Fallthrough. */ case R_IA64_LTOFF_FPTR22: { grub_uint64_t *gpptr = mod->gotptr; diff --git a/grub-core/kern/ia64/dl_helper.c b/grub-core/kern/ia64/dl_helper.c index c60159573..c7e53a679 100644 --- a/grub-core/kern/ia64/dl_helper.c +++ b/grub-core/kern/ia64/dl_helper.c @@ -30,40 +30,6 @@ #define MASK20 ((1 << 20) - 1) #define MASK3 (~(grub_addr_t) 3) -void -grub_ia64_set_immu64 (grub_addr_t addr, grub_uint64_t val) -{ - /* Copied from binutils. */ - grub_uint64_t *ptr = ((grub_uint64_t *) (addr & MASK3)); - grub_uint64_t t0, t1; - - t0 = grub_le_to_cpu64 (ptr[0]); - t1 = grub_le_to_cpu64 (ptr[1]); - - /* tmpl/s: bits 0.. 5 in t0 - slot 0: bits 5..45 in t0 - slot 1: bits 46..63 in t0, bits 0..22 in t1 - slot 2: bits 23..63 in t1 */ - - /* First, clear the bits that form the 64 bit constant. */ - t0 &= ~(0x3ffffLL << 46); - t1 &= ~(0x7fffffLL - | (( (0x07fLL << 13) | (0x1ffLL << 27) - | (0x01fLL << 22) | (0x001LL << 21) - | (0x001LL << 36)) << 23)); - - t0 |= ((val >> 22) & 0x03ffffLL) << 46; /* 18 lsbs of imm41 */ - t1 |= ((val >> 40) & 0x7fffffLL) << 0; /* 23 msbs of imm41 */ - t1 |= ( (((val >> 0) & 0x07f) << 13) /* imm7b */ - | (((val >> 7) & 0x1ff) << 27) /* imm9d */ - | (((val >> 16) & 0x01f) << 22) /* imm5c */ - | (((val >> 21) & 0x001) << 21) /* ic */ - | (((val >> 63) & 0x001) << 36)) << 23; /* i */ - - ptr[0] = t0; - ptr[1] = t1; -} - void grub_ia64_add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value) { @@ -216,11 +182,11 @@ grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize))) if (s->sh_type == grub_cpu_to_le32_compile_time (SHT_RELA)) { - const Elf64_Rela *rel, *max; + Elf64_Rela *rel, *max; for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu64 (s->sh_offset)), - max = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_size)); - rel < max; rel = (const Elf64_Rela *) ((char *) rel + grub_le_to_cpu64 (s->sh_entsize))) + max = rel + grub_le_to_cpu64 (s->sh_size) / grub_le_to_cpu64 (s->sh_entsize); + rel < max; rel++) switch (ELF64_R_TYPE (grub_le_to_cpu64 (rel->r_info))) { case R_IA64_PCREL21B: diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c index f1965571b..b5ecbd091 100644 --- a/grub-core/kern/ia64/efi/init.c +++ b/grub-core/kern/ia64/efi/init.c @@ -70,11 +70,6 @@ grub_machine_init (void) void grub_machine_fini (int flags) { - if (!(flags & GRUB_LOADER_FLAG_NORETURN)) - return; - - grub_efi_fini (); - - if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) - grub_efi_memory_fini (); + if (flags & GRUB_LOADER_FLAG_NORETURN) + grub_efi_fini (); } diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c index 20cbbd761..3e12e6b24 100644 --- a/grub-core/kern/ieee1275/cmain.c +++ b/grub-core/kern/ieee1275/cmain.c @@ -108,9 +108,6 @@ grub_ieee1275_find_options (void) if (rc >= 0) { char *ptr; - - if (grub_strncmp (tmp, "sun4v", 5) == 0) - grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_RAW_DEVNAMES); for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1) { if (grub_memcmp (ptr, "MacRISC", sizeof ("MacRISC") - 1) == 0 diff --git a/grub-core/kern/ieee1275/ieee1275.c b/grub-core/kern/ieee1275/ieee1275.c index 86f81a3c4..98217029f 100644 --- a/grub-core/kern/ieee1275/ieee1275.c +++ b/grub-core/kern/ieee1275/ieee1275.c @@ -19,7 +19,6 @@ #include #include -#include #define IEEE1275_PHANDLE_INVALID ((grub_ieee1275_cell_t) -1) #define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_cell_t) 0) @@ -483,91 +482,6 @@ grub_ieee1275_close (grub_ieee1275_ihandle_t ihandle) return 0; } -int -grub_ieee1275_decode_unit4 (grub_ieee1275_ihandle_t ihandle, - void *addr, grub_size_t size, - grub_uint32_t *phy_lo, grub_uint32_t *phy_hi, - grub_uint32_t *lun_lo, grub_uint32_t *lun_hi) -{ - struct decode_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t size; - grub_ieee1275_cell_t addr; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t tgt_h; - grub_ieee1275_cell_t tgt_l; - grub_ieee1275_cell_t lun_h; - grub_ieee1275_cell_t lun_l; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 5); - args.method = (grub_ieee1275_cell_t) "decode-unit"; - args.ihandle = ihandle; - args.size = size; - args.addr = (grub_ieee1275_cell_t) addr; - args.catch_result = 1; - - if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, "decode-unit failed\n"); - return -1; - } - - *phy_lo = args.tgt_l; - *phy_hi = args.tgt_h; - *lun_lo = args.lun_l; - *lun_hi = args.lun_h; - return 0; -} - -char * -grub_ieee1275_encode_uint4 (grub_ieee1275_ihandle_t ihandle, - grub_uint32_t phy_lo, grub_uint32_t phy_hi, - grub_uint32_t lun_lo, grub_uint32_t lun_hi, - grub_size_t *size) -{ - char *addr; - struct encode_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t tgt_h; - grub_ieee1275_cell_t tgt_l; - grub_ieee1275_cell_t lun_h; - grub_ieee1275_cell_t lun_l; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t size; - grub_ieee1275_cell_t addr; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 3); - args.method = (grub_ieee1275_cell_t) "encode-unit"; - args.ihandle = ihandle; - - args.tgt_l = phy_lo; - args.tgt_h = phy_hi; - args.lun_l = lun_lo; - args.lun_h = lun_hi; - args.catch_result = 1; - - if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, "encode-unit failed\n"); - return 0; - } - - addr = (void *)args.addr; - *size = args.size; - addr = grub_strdup ((char *)args.addr); - return addr; -} - int grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align, grub_addr_t *result) @@ -693,117 +607,3 @@ grub_ieee1275_milliseconds (grub_uint32_t *msecs) *msecs = args.msecs; return 0; } - -int -grub_ieee1275_set_address (grub_ieee1275_ihandle_t ihandle, - grub_uint32_t target, grub_uint32_t lun) -{ - struct set_address - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t tgt; - grub_ieee1275_cell_t lun; - grub_ieee1275_cell_t catch_result; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 1); - - /* - * IEEE 1275-1994 Standard for Boot (Initialization Configuration) - * Firmware: Core Requirements and Practices - * E.3.2.2 Bus-specific methods for bus nodes - * - * A package implementing the scsi-2 device type shall implement the - * following bus-specific method: - * - * set-address ( unit# target# -- ) - * Sets the SCSI target number (0x0..0xf) and unit number (0..7) to which - * subsequent commands apply. - */ - args.method = (grub_ieee1275_cell_t) "set-address"; - args.ihandle = ihandle; - args.tgt = target; - args.lun = lun; - - if (IEEE1275_CALL_ENTRY_FN (&args) == -1) - return -1; - - return args.catch_result; -} - -int -grub_ieee1275_no_data_command (grub_ieee1275_ihandle_t ihandle, - const void *cmd_addr, grub_ssize_t *result) -{ - struct set_address - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t cmd_addr; - grub_ieee1275_cell_t error; - grub_ieee1275_cell_t catch_result; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 3, 2); - - /* - * IEEE 1275-1994 Standard for Boot (Initialization Configuration) - * Firmware: Core Requirements and Practices - * - * E.3.2.2 Bus-specific methods for bus nodes - * - * A package implementing the scsi-2 device type shall implement the - * following bus-specific method: - * - * no-data-command ( cmd-addr -- error? ) - * Executes a simple SCSI command, automatically retrying under - * certain conditions. cmd-addr is the address of a 6-byte command buffer - * containing an SCSI command that does not have a data transfer phase. - * Executes the command, retrying indefinitely with the same retry criteria - * as retry-command. - * - * error? is nonzero if an error occurred, zero otherwise. - * NOTE no-data-command is a convenience function. It provides - * no capabilities that are not present in retry-command, but for - * those commands that meet its restrictions, it is easier to use. - */ - args.method = (grub_ieee1275_cell_t) "no-data-command"; - args.ihandle = ihandle; - args.cmd_addr = (grub_ieee1275_cell_t) cmd_addr; - - if (IEEE1275_CALL_ENTRY_FN (&args) == -1) - return -1; - - if (result) - *result = args.error; - - return args.catch_result; -} - -int -grub_ieee1275_get_block_size (grub_ieee1275_ihandle_t ihandle) -{ - struct size_args_ieee1275 - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t result; - grub_ieee1275_cell_t size; - } args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2); - args.method = (grub_ieee1275_cell_t) "block-size"; - args.ihandle = ihandle; - args.result = 1; - - if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result)) - return 0; - - return args.size; -} diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index d483e35ee..d5bd74d35 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -30,9 +30,6 @@ #include #include #include -#ifdef __sparc__ -#include -#endif #include #include #include @@ -49,19 +46,11 @@ #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) /* The maximum heap size we're going to claim */ -#ifdef __i386__ -#define HEAP_MAX_SIZE (unsigned long) (64 * 1024 * 1024) -#else #define HEAP_MAX_SIZE (unsigned long) (32 * 1024 * 1024) -#endif /* If possible, we will avoid claiming heap above this address, because it seems to cause relocation problems with OSes that link at 4 MiB */ -#ifdef __i386__ -#define HEAP_MAX_ADDR (unsigned long) (64 * 1024 * 1024) -#else #define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) -#endif extern char _start[]; extern char _end[]; @@ -97,12 +86,28 @@ void grub_machine_get_bootlocation (char **device, char **path) { char *bootpath; + grub_ssize_t bootpath_size; char *filename; char *type; - bootpath = grub_ieee1275_get_boot_dev (); + if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath", + &bootpath_size) + || bootpath_size <= 0) + { + /* Should never happen. */ + grub_printf ("/chosen/bootpath property missing!\n"); + return; + } + + bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64); if (! bootpath) - return; + { + grub_print_error (); + return; + } + grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath, + (grub_size_t) bootpath_size + 1, 0); + bootpath[bootpath_size] = '\0'; /* Transform an OF device path to a GRUB path. */ @@ -113,8 +118,6 @@ grub_machine_get_bootlocation (char **device, char **path) char *ptr; dev = grub_ieee1275_get_aliasdevname (bootpath); canon = grub_ieee1275_canonicalise_devname (dev); - if (! canon) - return; ptr = canon + grub_strlen (canon) - 1; while (ptr > canon && (*ptr == ',' || *ptr == ':')) ptr--; @@ -163,7 +166,7 @@ heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, { unsigned long *total = data; - if (type != GRUB_MEMORY_AVAILABLE) + if (type != 1) return 0; if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM)) @@ -283,11 +286,8 @@ grub_machine_init (void) grub_console_init_early (); grub_claim_heap (); grub_console_init_lately (); -#ifdef __sparc__ - grub_obdisk_init (); -#else grub_ofdisk_init (); -#endif + grub_parse_cmdline (); #ifdef __i386__ @@ -302,11 +302,7 @@ grub_machine_fini (int flags) { if (flags & GRUB_LOADER_FLAG_NORETURN) { -#ifdef __sparc__ - grub_obdisk_fini (); -#else grub_ofdisk_fini (); -#endif grub_console_fini (); } } diff --git a/grub-core/kern/ieee1275/mmap.c b/grub-core/kern/ieee1275/mmap.c index bf325eadf..911bb0011 100644 --- a/grub-core/kern/ieee1275/mmap.c +++ b/grub-core/kern/ieee1275/mmap.c @@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) { grub_ieee1275_phandle_t root; grub_ieee1275_phandle_t memory; - grub_uint32_t available[128]; + grub_uint32_t available[32]; grub_ssize_t available_size; grub_uint32_t address_cells = 1; grub_uint32_t size_cells = 1; @@ -49,9 +49,6 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size)) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "couldn't examine /memory/available property"); - if (available_size < 0 || (grub_size_t) available_size > sizeof (available)) - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "/memory response buffer exceeded"); if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) { diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c index 4d493ab76..ddb778340 100644 --- a/grub-core/kern/ieee1275/openfw.c +++ b/grub-core/kern/ieee1275/openfw.c @@ -479,9 +479,6 @@ grub_ieee1275_encode_devname (const char *path) char *optr; const char *iptr; - if (! device) - return 0; - encoding = grub_malloc (sizeof ("ieee1275/") + 2 * grub_strlen (device) + sizeof (",XXXXXXXXXXXX")); if (!encoding) @@ -564,30 +561,3 @@ grub_ieee1275_canonicalise_devname (const char *path) return NULL; } -char * -grub_ieee1275_get_boot_dev (void) -{ - char *bootpath; - grub_ssize_t bootpath_size; - - if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath", - &bootpath_size) - || bootpath_size <= 0) - { - /* Should never happen. */ - grub_printf ("/chosen/bootpath property missing!\n"); - return NULL; - } - - bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64); - if (! bootpath) - { - grub_print_error (); - return NULL; - } - grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath, - (grub_size_t) bootpath_size + 1, 0); - bootpath[bootpath_size] = '\0'; - - return bootpath; -} diff --git a/grub-core/kern/mips/cache.S b/grub-core/kern/mips/cache.S index fa331eca1..78e40bcea 100644 --- a/grub-core/kern/mips/cache.S +++ b/grub-core/kern/mips/cache.S @@ -7,7 +7,6 @@ FUNCTION (grub_arch_sync_caches) #include "cache_flush.S" j $ra - nop FUNCTION (grub_arch_sync_dma_caches) move $t2, $a0 @@ -66,5 +65,4 @@ FUNCTION (grub_arch_sync_dma_caches) #endif sync_op - jr $ra - nop + jr $ra \ No newline at end of file diff --git a/grub-core/kern/mips/dl.c b/grub-core/kern/mips/dl.c index 5d7d299c7..8c057e01d 100644 --- a/grub-core/kern/mips/dl.c +++ b/grub-core/kern/mips/dl.c @@ -138,10 +138,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, sym = (Elf_Sym *) ((char *) mod->symtab + mod->symsize * ELF_R_SYM (rel->r_info)); sym_value = sym->st_value; - if (s->sh_type == SHT_RELA) - { - sym_value += ((Elf_Rela *) rel)->r_addend; - } if (sym_value == (grub_addr_t) &__gnu_local_gp_dummy) sym_value = (grub_addr_t) mod->got; else if (sym_value == (grub_addr_t) &_gp_disp_dummy) @@ -236,7 +232,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, sym_value &= 0xffff0000; *(grub_uint16_t *) addr = 0; } - /* Fallthrough. */ case R_MIPS_CALL16: { grub_uint32_t *gpptr = mod->gotptr; diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index 1fdb58aca..709a91afa 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -22,7 +22,6 @@ #include #include #include -#include #define BASE_ADDR 8 @@ -37,7 +36,7 @@ start: bal cont nop - .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE + . = _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE VARIABLE(grub_total_modules_size) .long 0 @@ -96,8 +95,8 @@ cont: modulesmovcont: beq $t3, $0, modulesmovdone nop - lb GRUB_ASM_T4, 0($t2) - sb GRUB_ASM_T4, 0($t1) + lb $t4, 0($t2) + sb $t4, 0($t1) addiu $t2, $t2, -1 addiu $t1, $t1, -1 b modulesmovcont diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index a278e069b..c5c815d8d 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -95,6 +95,25 @@ grub_memmove (void *dest, const void *src, grub_size_t n) return dest; } +#ifndef __APPLE__ +void *memmove (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); +/* GCC emits references to memcpy() for struct copies etc. */ +void *memcpy (void *dest, const void *src, grub_size_t n) + __attribute__ ((alias ("grub_memmove"))); +#else +void * GRUB_BUILTIN_ATTR +memcpy (void *dest, const void *src, grub_size_t n) +{ + return grub_memmove (dest, src, n); +} +void * GRUB_BUILTIN_ATTR +memmove (void *dest, const void *src, grub_size_t n) +{ + return grub_memmove (dest, src, n); +} +#endif + char * grub_strcpy (char *dest, const char *src) { @@ -158,28 +177,17 @@ int grub_err_printf (const char *fmt, ...) __attribute__ ((alias("grub_printf"))); #endif -int -grub_debug_enabled (const char * condition) -{ - const char *debug; - - debug = grub_env_get ("debug"); - if (!debug) - return 0; - - if (grub_strword (debug, "all") || grub_strword (debug, condition)) - return 1; - - return 0; -} - void grub_real_dprintf (const char *file, const int line, const char *condition, const char *fmt, ...) { va_list args; + const char *debug = grub_env_get ("debug"); - if (grub_debug_enabled (condition)) + if (! debug) + return; + + if (grub_strword (debug, "all") || grub_strword (debug, condition)) { grub_printf ("%s:%d: ", file, line); va_start (args, fmt); @@ -245,6 +253,16 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n) return 0; } +#ifndef __APPLE__ +int memcmp (const void *s1, const void *s2, grub_size_t n) + __attribute__ ((alias ("grub_memcmp"))); +#else +int GRUB_BUILTIN_ATTR +memcmp (const void *s1, const void *s2, grub_size_t n) +{ + return grub_memcmp (s1, s2, n); +} +#endif int grub_strcmp (const char *s1, const char *s2) @@ -351,8 +369,7 @@ grub_isspace (int c) } unsigned long -grub_strtoul (const char * restrict str, const char ** const restrict end, - int base) +grub_strtoul (const char *str, char **end, int base) { unsigned long long num; @@ -369,8 +386,7 @@ grub_strtoul (const char * restrict str, const char ** const restrict end, } unsigned long long -grub_strtoull (const char * restrict str, const char ** const restrict end, - int base) +grub_strtoull (const char *str, char **end, int base) { unsigned long long num = 0; int found = 0; @@ -404,13 +420,12 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, unsigned long digit; digit = grub_tolower (*str) - '0'; - if (digit >= 'a' - '0') - digit += '0' - 'a' + 10; - else if (digit > 9) - break; - - if (digit >= (unsigned long) base) - break; + if (digit > 9) + { + digit += '0' - 'a' + 10; + if (digit >= (unsigned long) base) + break; + } found = 1; @@ -517,6 +532,26 @@ grub_memset (void *s, int c, grub_size_t len) return s; } +#ifndef __APPLE__ +void *memset (void *s, int c, grub_size_t n) + __attribute__ ((alias ("grub_memset"))); +#else +void * GRUB_BUILTIN_ATTR +memset (void *s, int c, grub_size_t n) +{ + return grub_memset (s, c, n); +} + +#endif + +#if !defined(GRUB_UTIL) && defined(__APPLE__) +void GRUB_BUILTIN_ATTR +__bzero (void *s, grub_size_t n) +{ + grub_memset (s, 0, n); +} + +#endif grub_size_t grub_strlen (const char *s) @@ -559,10 +594,10 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) grub_uint64_t m = 0; /* ARM and IA64 don't have a fast 32-bit division. - Using that code would just make us use software division routines, calling - ourselves indirectly and hence getting infinite recursion. + Using that code would just make us use libgcc routines, calling + them twice (once for modulo and once for quotient. */ -#if !GRUB_DIVISION_IN_SOFTWARE +#if !defined (__arm__) && !defined (__ia64__) /* Skip the slow computation if 32-bit arithmetic is possible. */ if (n < 0xffffffff && d < 0xffffffff) { @@ -596,12 +631,138 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) return q; } +#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) + +#if defined (__arm__) + +grub_uint32_t +__udivsi3 (grub_uint32_t a, grub_uint32_t b) +{ + return grub_divmod64 (a, b, 0); +} + +grub_uint32_t +__umodsi3 (grub_uint32_t a, grub_uint32_t b) +{ + grub_uint64_t ret; + grub_divmod64 (a, b, &ret); + return ret; +} + +#endif + +#ifdef NEED_CTZDI2 + +unsigned +__ctzdi2 (grub_uint64_t x) +{ + unsigned ret = 0; + if (!x) + return 64; + if (!(x & 0xffffffff)) + { + x >>= 32; + ret |= 32; + } + if (!(x & 0xffff)) + { + x >>= 16; + ret |= 16; + } + if (!(x & 0xff)) + { + x >>= 8; + ret |= 8; + } + if (!(x & 0xf)) + { + x >>= 4; + ret |= 4; + } + if (!(x & 0x3)) + { + x >>= 2; + ret |= 2; + } + if (!(x & 0x1)) + { + x >>= 1; + ret |= 1; + } + return ret; +} +#endif + +#ifdef NEED_CTZSI2 +unsigned +__ctzsi2 (grub_uint32_t x) +{ + unsigned ret = 0; + if (!x) + return 32; + + if (!(x & 0xffff)) + { + x >>= 16; + ret |= 16; + } + if (!(x & 0xff)) + { + x >>= 8; + ret |= 8; + } + if (!(x & 0xf)) + { + x >>= 4; + ret |= 4; + } + if (!(x & 0x3)) + { + x >>= 2; + ret |= 2; + } + if (!(x & 0x1)) + { + x >>= 1; + ret |= 1; + } + return ret; +} + +#endif + +#ifdef __arm__ +grub_uint32_t +__aeabi_uidiv (grub_uint32_t a, grub_uint32_t b) + __attribute__ ((alias ("__udivsi3"))); +#endif + +#if defined (__ia64__) + +grub_uint64_t +__udivdi3 (grub_uint64_t a, grub_uint64_t b) +{ + return grub_divmod64 (a, b, 0); +} + +grub_uint64_t +__umoddi3 (grub_uint64_t a, grub_uint64_t b) +{ + grub_uint64_t ret; + grub_divmod64 (a, b, &ret); + return ret; +} + +#endif + +#endif /* GRUB_UTIL */ + /* Convert a long long value to a string. This function avoids 64-bit modular arithmetic or divisions. */ static inline char * grub_lltoa (char *str, int c, unsigned long long n) { - unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10; + unsigned base = (c == 'x') ? 16 : 10; char *p; if ((long long) n < 0 && c == 'd') @@ -616,7 +777,7 @@ grub_lltoa (char *str, int c, unsigned long long n) do { unsigned d = (unsigned) (n & 0xf); - *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0'; + *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; } while (n >>= 4); else @@ -689,7 +850,6 @@ parse_printf_args (const char *fmt0, struct printf_args *args, { case 'p': case 'x': - case 'X': case 'u': case 'd': case 'c': @@ -704,7 +864,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, args->ptr = args->prealloc; else { - args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); + args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); if (!args->ptr) { grub_errno = GRUB_ERR_NONE; @@ -755,12 +915,6 @@ parse_printf_args (const char *fmt0, struct printf_args *args, fmt++; c = *fmt++; - if (c == '%') - { - n--; - continue; - } - if (c == 'l') { c = *fmt++; @@ -776,7 +930,6 @@ parse_printf_args (const char *fmt0, struct printf_args *args, switch (c) { case 'x': - case 'X': case 'u': args->ptr[curn].type = UNSIGNED_INT + longfmt; break; @@ -868,14 +1021,14 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, { if (fmt[0] == '0') zerofill = '0'; - format1 = grub_strtoul (fmt, &fmt, 10); + format1 = grub_strtoul (fmt, (char **) &fmt, 10); } if (*fmt == '.') fmt++; if (grub_isdigit (*fmt)) - format2 = grub_strtoul (fmt, &fmt, 10); + format2 = grub_strtoul (fmt, (char **) &fmt, 10); if (*fmt == '$') { @@ -898,7 +1051,6 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, if (c == '%') { write_char (str, &count, max_len,c); - n--; continue; } @@ -915,7 +1067,6 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, c = 'x'; /* Fall through. */ case 'x': - case 'X': case 'u': case 'd': { @@ -1114,6 +1265,15 @@ grub_abort (void) grub_exit (); } +#if defined (__clang__) && !defined (GRUB_UTIL) +/* clang emits references to abort(). */ +void __attribute__ ((noreturn)) +abort (void) +{ + grub_abort (); +} +#endif + void grub_fatal (const char *fmt, ...) { @@ -1123,11 +1283,26 @@ grub_fatal (const char *fmt, ...) grub_vprintf (_(fmt), ap); va_end (ap); - grub_refresh (); - grub_abort (); } +#if (defined (__MINGW32__) || defined (__CYGWIN__)) && !defined(GRUB_UTIL) +void __register_frame_info (void) +{ +} + +void __deregister_frame_info (void) +{ +} +void ___chkstk_ms (void) +{ +} + +void __chkstk_ms (void) +{ +} +#endif + #if BOOT_TIME_STATS #include diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index f2822a836..1c3d02388 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -67,10 +67,8 @@ #include #include #include -#include #ifdef MM_DEBUG -# undef grub_calloc # undef grub_malloc # undef grub_zalloc # undef grub_realloc @@ -327,15 +325,6 @@ grub_memalign (grub_size_t align, grub_size_t size) if (!grub_mm_base) goto fail; - if (size > ~(grub_size_t) align) - goto fail; - - /* We currently assume at least a 32-bit grub_size_t, - so limiting allocations to - 1MiB - in name of sanity is beneficial. */ - if ((size + align) > ~(grub_size_t) 0x100000) - goto fail; - align = (align >> GRUB_MM_ALIGN_LOG2); if (align == 0) align = 1; @@ -377,30 +366,6 @@ grub_memalign (grub_size_t align, grub_size_t size) return 0; } -/* - * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on - * integer overflow. - */ -void * -grub_calloc (grub_size_t nmemb, grub_size_t size) -{ - void *ret; - grub_size_t sz = 0; - - if (grub_mul (nmemb, size, &sz)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - return NULL; - } - - ret = grub_memalign (0, sz); - if (!ret) - return NULL; - - grub_memset (ret, 0, sz); - return ret; -} - /* Allocate SIZE bytes and return the pointer. */ void * grub_malloc (grub_size_t size) @@ -587,20 +552,6 @@ grub_mm_dump (unsigned lineno) grub_printf ("\n"); } -void * -grub_debug_calloc (const char *file, int line, grub_size_t nmemb, grub_size_t size) -{ - void *ptr; - - if (grub_mm_debug) - grub_printf ("%s:%d: calloc (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE ") = ", - file, line, size); - ptr = grub_calloc (nmemb, size); - if (grub_mm_debug) - grub_printf ("%p\n", ptr); - return ptr; -} - void * grub_debug_malloc (const char *file, int line, grub_size_t size) { diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c index 619db3122..b9bd12352 100644 --- a/grub-core/kern/parser.c +++ b/grub-core/kern/parser.c @@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, return grub_errno; grub_memcpy (args, buffer, bp - buffer); - *argv = grub_calloc (*argc + 1, sizeof (char *)); + *argv = grub_malloc (sizeof (char *) * (*argc + 1)); if (!*argv) { grub_free (args); @@ -268,7 +268,6 @@ grub_parser_execute (char *source) grub_parser_execute_getline (&line, 0, &source); grub_rescue_parse_line (line, grub_parser_execute_getline, &source); grub_free (line); - grub_print_error (); } return grub_errno; diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c index 2c401b866..e499147cb 100644 --- a/grub-core/kern/partition.c +++ b/grub-core/kern/partition.c @@ -126,7 +126,7 @@ grub_partition_probe (struct grub_disk *disk, const char *str) while (*ptr && grub_isalpha (*ptr)) ptr++; partname_end = ptr; - num = grub_strtoul (ptr, &ptr, 0) - 1; + num = grub_strtoul (ptr, (char **) &ptr, 0) - 1; curpart = 0; /* Use the first partition map type found. */ diff --git a/grub-core/kern/powerpc/compiler-rt.S b/grub-core/kern/powerpc/compiler-rt.S deleted file mode 100644 index b3b912db6..000000000 --- a/grub-core/kern/powerpc/compiler-rt.S +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Special support for eabi and SVR4 - * - * Copyright (C) 1995-2014 Free Software Foundation, Inc. - * Written By Michael Meissner - * 64-bit support written by David Edelsohn - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3, or (at your option) any - * later version. - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * Under Section 7 of GPL version 3, you are granted additional - * permissions described in the GCC Runtime Library Exception, version - * 3.1, as published by the Free Software Foundation. - * - * You should have received a copy of the GNU General Public License and - * a copy of the GCC Runtime Library Exception along with this program; - * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - * . - */ - -/* Do any initializations needed for the eabi environment */ - -#include -#include - - .section ".text" - -#define CFI_RESTORE(reg) .cfi_restore reg -#define CFI_OFFSET(reg, off) .cfi_offset reg, off -#define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg -#define CFI_STARTPROC .cfi_startproc -#define CFI_ENDPROC .cfi_endproc - -/* Routines for restoring integer registers, called by the compiler. */ -/* Called with r11 pointing to the stack header word of the caller of the */ -/* function, just beyond the end of the integer restore area. */ - -CFI_STARTPROC -CFI_DEF_CFA_REGISTER (11) -CFI_OFFSET (65, 4) -CFI_OFFSET (14, -72) -CFI_OFFSET (15, -68) -CFI_OFFSET (16, -64) -CFI_OFFSET (17, -60) -CFI_OFFSET (18, -56) -CFI_OFFSET (19, -52) -CFI_OFFSET (20, -48) -CFI_OFFSET (21, -44) -CFI_OFFSET (22, -40) -CFI_OFFSET (23, -36) -CFI_OFFSET (24, -32) -CFI_OFFSET (25, -28) -CFI_OFFSET (26, -24) -CFI_OFFSET (27, -20) -CFI_OFFSET (28, -16) -CFI_OFFSET (29, -12) -CFI_OFFSET (30, -8) -CFI_OFFSET (31, -4) -FUNCTION(_restgpr_14_x) lwz 14,-72(11) /* restore gp registers */ -CFI_RESTORE (14) -FUNCTION(_restgpr_15_x) lwz 15,-68(11) -CFI_RESTORE (15) -FUNCTION(_restgpr_16_x) lwz 16,-64(11) -CFI_RESTORE (16) -FUNCTION(_restgpr_17_x) lwz 17,-60(11) -CFI_RESTORE (17) -FUNCTION(_restgpr_18_x) lwz 18,-56(11) -CFI_RESTORE (18) -FUNCTION(_restgpr_19_x) lwz 19,-52(11) -CFI_RESTORE (19) -FUNCTION(_restgpr_20_x) lwz 20,-48(11) -CFI_RESTORE (20) -FUNCTION(_restgpr_21_x) lwz 21,-44(11) -CFI_RESTORE (21) -FUNCTION(_restgpr_22_x) lwz 22,-40(11) -CFI_RESTORE (22) -FUNCTION(_restgpr_23_x) lwz 23,-36(11) -CFI_RESTORE (23) -FUNCTION(_restgpr_24_x) lwz 24,-32(11) -CFI_RESTORE (24) -FUNCTION(_restgpr_25_x) lwz 25,-28(11) -CFI_RESTORE (25) -FUNCTION(_restgpr_26_x) lwz 26,-24(11) -CFI_RESTORE (26) -FUNCTION(_restgpr_27_x) lwz 27,-20(11) -CFI_RESTORE (27) -FUNCTION(_restgpr_28_x) lwz 28,-16(11) -CFI_RESTORE (28) -FUNCTION(_restgpr_29_x) lwz 29,-12(11) -CFI_RESTORE (29) -FUNCTION(_restgpr_30_x) lwz 30,-8(11) -CFI_RESTORE (30) -FUNCTION(_restgpr_31_x) lwz 0,4(11) - lwz 31,-4(11) -CFI_RESTORE (31) - mtlr 0 -CFI_RESTORE (65) - mr 1,11 -CFI_DEF_CFA_REGISTER (1) - blr -CFI_ENDPROC - -CFI_STARTPROC -FUNCTION(_savegpr_14) stw 14,-72(11) /* save gp registers */ -FUNCTION(_savegpr_15) stw 15,-68(11) -FUNCTION(_savegpr_16) stw 16,-64(11) -FUNCTION(_savegpr_17) stw 17,-60(11) -FUNCTION(_savegpr_18) stw 18,-56(11) -FUNCTION(_savegpr_19) stw 19,-52(11) -FUNCTION(_savegpr_20) stw 20,-48(11) -FUNCTION(_savegpr_21) stw 21,-44(11) -FUNCTION(_savegpr_22) stw 22,-40(11) -FUNCTION(_savegpr_23) stw 23,-36(11) -FUNCTION(_savegpr_24) stw 24,-32(11) -FUNCTION(_savegpr_25) stw 25,-28(11) -FUNCTION(_savegpr_26) stw 26,-24(11) -FUNCTION(_savegpr_27) stw 27,-20(11) -FUNCTION(_savegpr_28) stw 28,-16(11) -FUNCTION(_savegpr_29) stw 29,-12(11) -FUNCTION(_savegpr_30) stw 30,-8(11) -FUNCTION(_savegpr_31) stw 31,-4(11) - blr -CFI_ENDPROC diff --git a/grub-core/kern/powerpc/dl.c b/grub-core/kern/powerpc/dl.c index cdd61b305..3a7fa3ed3 100644 --- a/grub-core/kern/powerpc/dl.c +++ b/grub-core/kern/powerpc/dl.c @@ -79,8 +79,7 @@ grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, max = rel + s->sh_size / s->sh_entsize; rel < max; rel++) - if (ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_REL24 - || ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_PLTREL24) + if (ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_REL24) (*tramp)++; } @@ -123,7 +122,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, *(Elf_Half *) addr = value; break; - case GRUB_ELF_R_PPC_PLTREL24: case GRUB_ELF_R_PPC_REL24: { Elf_Sword delta = value - (Elf_Word) addr; diff --git a/grub-core/kern/rescue_parser.c b/grub-core/kern/rescue_parser.c index 633836699..ab3d04160 100644 --- a/grub-core/kern/rescue_parser.c +++ b/grub-core/kern/rescue_parser.c @@ -43,17 +43,13 @@ grub_rescue_parse_line (char *line, /* In case of an assignment set the environment accordingly instead of calling a function. */ - if (n == 1) + if (n == 1 && grub_strchr (line, '=')) { char *val = grub_strchr (args[0], '='); - - if (val) - { - val[0] = 0; - grub_env_set (args[0], val + 1); - val[0] = '='; - goto quit; - } + val[0] = 0; + grub_env_set (args[0], val + 1); + val[0] = '='; + goto quit; } /* Get the command name. */ @@ -76,7 +72,6 @@ grub_rescue_parse_line (char *line, } quit: - /* Arguments are returned in single memory chunk separated by zeroes */ grub_free (args[0]); grub_free (args); diff --git a/grub-core/kern/riscv/cache.c b/grub-core/kern/riscv/cache.c deleted file mode 100644 index 47777a033..000000000 --- a/grub-core/kern/riscv/cache.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -static grub_int64_t dlinesz; -static grub_int64_t ilinesz; - -/* Prototypes for asm functions. */ -void grub_arch_clean_dcache_range (grub_addr_t beg, grub_addr_t end, - grub_size_t line_size); -void grub_arch_invalidate_icache_range (grub_addr_t beg, grub_addr_t end, - grub_size_t line_size); - -static void -probe_caches (void) -{ - /* TODO */ - dlinesz = 32; - ilinesz = 32; -} - -void -grub_arch_sync_caches (void *address, grub_size_t len) -{ - grub_size_t start, end, max_align; - - if (dlinesz == 0) - probe_caches(); - if (dlinesz == 0) - grub_fatal ("Unknown cache line size!"); - - max_align = dlinesz > ilinesz ? dlinesz : ilinesz; - - start = ALIGN_DOWN ((grub_size_t) address, max_align); - end = ALIGN_UP ((grub_size_t) address + len, max_align); - - grub_arch_clean_dcache_range (start, end, dlinesz); - grub_arch_invalidate_icache_range (start, end, ilinesz); -} - -void -grub_arch_sync_dma_caches (volatile void *address __attribute__((unused)), - grub_size_t len __attribute__((unused))) -{ - /* DMA incoherent devices not supported yet */ -} diff --git a/grub-core/kern/riscv/cache_flush.S b/grub-core/kern/riscv/cache_flush.S deleted file mode 100644 index 41de6e411..000000000 --- a/grub-core/kern/riscv/cache_flush.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include - - .file "cache_flush.S" - .text - -/* - * Simple cache maintenance functions - */ - -/* - * a0 - *beg (inclusive) - * a1 - *end (exclusive) - * a2 - line size -*/ -FUNCTION(grub_arch_clean_dcache_range) - /* TODO */ - ret - -/* - * a0 - *beg (inclusive) - * a1 - *end (exclusive) - * a2 - line size - */ -FUNCTION(grub_arch_invalidate_icache_range) - fence.i - ret diff --git a/grub-core/kern/riscv/dl.c b/grub-core/kern/riscv/dl.c deleted file mode 100644 index 6fb8385ef..000000000 --- a/grub-core/kern/riscv/dl.c +++ /dev/null @@ -1,340 +0,0 @@ -/* dl.c - arch-dependent part of loadable module support */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -/* - * Instructions and instruction encoding are documented in the RISC-V - * specification. This file is based on version 2.2: - * - * https://github.com/riscv/riscv-isa-manual/blob/master/release/riscv-spec-v2.2.pdf - */ -#define LDR 0x58000050 -#define BR 0xd61f0200 - -/* - * Check if EHDR is a valid ELF header. - */ -grub_err_t -grub_arch_dl_check_header (void *ehdr) -{ - Elf_Ehdr *e = ehdr; - - /* Check the magic numbers. */ - if (e->e_ident[EI_DATA] != ELFDATA2LSB || e->e_machine != EM_RISCV) - return grub_error (GRUB_ERR_BAD_OS, - N_("invalid arch-dependent ELF magic")); - - return GRUB_ERR_NONE; -} - -#pragma GCC diagnostic ignored "-Wcast-align" - -/* Relocate symbols. */ -grub_err_t -grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, - Elf_Shdr *s, grub_dl_segment_t seg) -{ - Elf_Rel *rel, *max; - - for (rel = (Elf_Rel *) ((char *) ehdr + s->sh_offset), - max = (Elf_Rel *) ((char *) rel + s->sh_size); - rel < max; - rel = (Elf_Rel *) ((char *) rel + s->sh_entsize)) - { - Elf_Sym *sym; - void *place; - grub_size_t sym_addr; - - if (rel->r_offset >= seg->size) - return grub_error (GRUB_ERR_BAD_MODULE, - "reloc offset is out of the segment"); - - sym = (Elf_Sym *) ((char *) mod->symtab - + mod->symsize * ELF_R_SYM (rel->r_info)); - - sym_addr = sym->st_value; - if (s->sh_type == SHT_RELA) - sym_addr += ((Elf_Rela *) rel)->r_addend; - - place = (void *) ((grub_addr_t) seg->addr + rel->r_offset); - - switch (ELF_R_TYPE (rel->r_info)) - { - case R_RISCV_32: - { - grub_uint32_t *abs_place = place; - - grub_dprintf ("dl", " reloc_abs32 %p => 0x%016llx\n", - place, (unsigned long long) sym_addr); - - *abs_place = (grub_uint32_t) sym_addr; - } - break; - case R_RISCV_64: - { - grub_size_t *abs_place = place; - - grub_dprintf ("dl", " reloc_abs64 %p => 0x%016llx\n", - place, (unsigned long long) sym_addr); - - *abs_place = (grub_size_t) sym_addr; - } - break; - - case R_RISCV_ADD8: - { - grub_uint8_t *abs_place = place; - - *abs_place += (grub_uint8_t) sym_addr; - } - break; - case R_RISCV_ADD16: - { - grub_uint16_t *abs_place = place; - - *abs_place += (grub_uint16_t) sym_addr; - } - break; - case R_RISCV_ADD32: - { - grub_uint32_t *abs_place = place; - - *abs_place += (grub_uint32_t) sym_addr; - } - break; - case R_RISCV_ADD64: - { - grub_size_t *abs_place = place; - - *abs_place += (grub_size_t) sym_addr; - } - break; - - case R_RISCV_SUB8: - { - grub_uint8_t *abs_place = place; - - *abs_place -= (grub_uint8_t) sym_addr; - } - break; - case R_RISCV_SUB16: - { - grub_uint16_t *abs_place = place; - - *abs_place -= (grub_uint16_t) sym_addr; - } - break; - case R_RISCV_SUB32: - { - grub_uint32_t *abs_place = place; - - *abs_place -= (grub_uint32_t) sym_addr; - } - break; - case R_RISCV_SUB64: - { - grub_size_t *abs_place = place; - - *abs_place -= (grub_size_t) sym_addr; - } - break; - - case R_RISCV_BRANCH: - { - grub_uint32_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_uint32_t imm12 = (off & 0x1000) << (31 - 12); - grub_uint32_t imm11 = (off & 0x800) >> (11 - 7); - grub_uint32_t imm10_5 = (off & 0x7e0) << (30 - 10); - grub_uint32_t imm4_1 = (off & 0x1e) << (11 - 4); - *abs_place = (*abs_place & 0x1fff07f) - | imm12 | imm11 | imm10_5 | imm4_1; - } - break; - - case R_RISCV_JAL: - { - grub_uint32_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_uint32_t imm20 = (off & 0x100000) << (31 - 20); - grub_uint32_t imm19_12 = (off & 0xff000); - grub_uint32_t imm11 = (off & 0x800) << (20 - 11); - grub_uint32_t imm10_1 = (off & 0x7fe) << (30 - 10); - *abs_place = (*abs_place & 0xfff) - | imm20 | imm19_12 | imm11 | imm10_1; - } - break; - - case R_RISCV_CALL: - { - grub_uint32_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_uint32_t hi20, lo12; - - if (off != (grub_int32_t) off) - return grub_error (GRUB_ERR_BAD_MODULE, "relocation overflow"); - - hi20 = (off + 0x800) & 0xfffff000; - lo12 = (off - hi20) & 0xfff; - abs_place[0] = (abs_place[0] & 0xfff) | hi20; - abs_place[1] = (abs_place[1] & 0xfffff) | (lo12 << 20); - } - break; - - case R_RISCV_RVC_BRANCH: - { - grub_uint16_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_uint16_t imm8 = (off & 0x100) << (12 - 8); - grub_uint16_t imm7_6 = (off & 0xc0) >> (6 - 5); - grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); - grub_uint16_t imm4_3 = (off & 0x18) << (12 - 5); - grub_uint16_t imm2_1 = (off & 0x6) << (12 - 10); - *abs_place = (*abs_place & 0xe383) - | imm8 | imm7_6 | imm5 | imm4_3 | imm2_1; - } - break; - - case R_RISCV_RVC_JUMP: - { - grub_uint16_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_uint16_t imm11 = (off & 0x800) << (12 - 11); - grub_uint16_t imm10 = (off & 0x400) >> (10 - 8); - grub_uint16_t imm9_8 = (off & 0x300) << (12 - 11); - grub_uint16_t imm7 = (off & 0x80) >> (7 - 6); - grub_uint16_t imm6 = (off & 0x40) << (12 - 11); - grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); - grub_uint16_t imm4 = (off & 0x10) << (12 - 5); - grub_uint16_t imm3_1 = (off & 0xe) << (12 - 10); - *abs_place = ((*abs_place & 0xe003) - | imm11 | imm10 | imm9_8 | imm7 | imm6 - | imm5 | imm4 | imm3_1); - } - break; - - case R_RISCV_PCREL_HI20: - { - grub_uint32_t *abs_place = place; - grub_ssize_t off = sym_addr - (grub_addr_t) place; - grub_int32_t hi20; - - if (off != (grub_int32_t)off) - return grub_error (GRUB_ERR_BAD_MODULE, "relocation overflow"); - - hi20 = (off + 0x800) & 0xfffff000; - *abs_place = (*abs_place & 0xfff) | hi20; - } - break; - - case R_RISCV_PCREL_LO12_I: - case R_RISCV_PCREL_LO12_S: - { - grub_uint32_t *t32 = place; - Elf_Rela *rel2; - /* Search backwards for matching HI20 reloc. */ - for (rel2 = (Elf_Rela *) ((char *) rel - s->sh_entsize); - (unsigned long)rel2 >= ((unsigned long)ehdr + s->sh_offset); - rel2 = (Elf_Rela *) ((char *) rel2 - s->sh_entsize)) - { - Elf_Addr rel2_info; - Elf_Addr rel2_offset; - Elf_Addr rel2_sym_addr; - Elf_Addr rel2_loc; - grub_ssize_t rel2_off; - grub_ssize_t off; - Elf_Sym *sym2; - - rel2_offset = rel2->r_offset; - rel2_info = rel2->r_info; - rel2_loc = (grub_addr_t) seg->addr + rel2_offset; - - if (ELF_R_TYPE (rel2_info) == R_RISCV_PCREL_HI20 - && rel2_loc == sym_addr) - { - sym2 = (Elf_Sym *) ((char *) mod->symtab - + mod->symsize * ELF_R_SYM (rel2->r_info)); - rel2_sym_addr = sym2->st_value; - if (s->sh_type == SHT_RELA) - rel2_sym_addr += ((Elf_Rela *) rel2)->r_addend; - - rel2_off = rel2_sym_addr - rel2_loc; - off = rel2_off - ((rel2_off + 0x800) & 0xfffff000); - - if (ELF_R_TYPE (rel->r_info) == R_RISCV_PCREL_LO12_I) - *t32 = (*t32 & 0xfffff) | (off & 0xfff) << 20; - else - { - grub_uint32_t imm11_5 = (off & 0xfe0) << (31 - 11); - grub_uint32_t imm4_0 = (off & 0x1f) << (11 - 4); - *t32 = (*t32 & 0x1fff07f) | imm11_5 | imm4_0; - } - break; - } - } - if ((unsigned long)rel2 < ((unsigned long)ehdr + s->sh_offset)) - return grub_error (GRUB_ERR_BAD_MODULE, "cannot find matching HI20 relocation"); - } - break; - - case R_RISCV_HI20: - { - grub_uint32_t *abs_place = place; - *abs_place = (*abs_place & 0xfff) | - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); - } - break; - - case R_RISCV_LO12_I: - { - grub_uint32_t *abs_place = place; - grub_int32_t lo12 = (grub_int32_t) sym_addr - - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); - *abs_place = (*abs_place & 0xfffff) | ((lo12 & 0xfff) << 20); - } - break; - - case R_RISCV_LO12_S: - { - grub_uint32_t *abs_place = place; - grub_int32_t lo12 = (grub_int32_t) sym_addr - - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); - grub_uint32_t imm11_5 = (lo12 & 0xfe0) << (31 - 11); - grub_uint32_t imm4_0 = (lo12 & 0x1f) << (11 - 4); - *abs_place = (*abs_place & 0x1fff07f) | imm11_5 | imm4_0; - } - break; - - case R_RISCV_RELAX: - break; - default: - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - N_("relocation 0x%x is not implemented yet"), - ELF_R_TYPE (rel->r_info)); - } - } - - return GRUB_ERR_NONE; -} diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c deleted file mode 100644 index 38795fe67..000000000 --- a/grub-core/kern/riscv/efi/init.c +++ /dev/null @@ -1,79 +0,0 @@ -/* init.c - initialize a riscv-based EFI system */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -static grub_uint64_t timer_frequency_in_khz; - -static grub_uint64_t -grub_efi_get_time_ms (void) -{ - grub_uint64_t tmr; - -#if __riscv_xlen == 64 - asm volatile ("rdcycle %0" : "=r" (tmr)); -#else - grub_uint32_t lo, hi, tmp; - asm volatile ( - "1:\n" - "rdcycleh %0\n" - "rdcycle %1\n" - "rdcycleh %2\n" - "bne %0, %2, 1b" - : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); - tmr = ((grub_uint64_t)hi << 32) | lo; -#endif - - return tmr / timer_frequency_in_khz; -} - -void -grub_machine_init (void) -{ - grub_uint64_t time_before, time_after; - - grub_efi_init (); - - /* Calculate timer frequency */ - timer_frequency_in_khz = 1; - time_before = grub_efi_get_time_ms(); - grub_efi_stall(1000); - time_after = grub_efi_get_time_ms(); - timer_frequency_in_khz = time_after - time_before; - - grub_install_get_time_ms (grub_efi_get_time_ms); -} - -void -grub_machine_fini (int flags) -{ - if (!(flags & GRUB_LOADER_FLAG_NORETURN)) - return; - - grub_efi_fini (); - - if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) - grub_efi_memory_fini (); -} diff --git a/grub-core/kern/riscv/efi/startup.S b/grub-core/kern/riscv/efi/startup.S deleted file mode 100644 index f2a7b2b1e..000000000 --- a/grub-core/kern/riscv/efi/startup.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include - -#if __riscv_xlen == 64 -#define sl sd -#define ll ld -#else -#define sl sw -#define ll lw -#endif - - - .file "startup.S" - .text -FUNCTION(_start) - /* - * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0. - */ - - ll a2, efi_image_handle_val - sl a0, 0(a2) - ll a2, efi_system_table_val - sl a1, 0(a2) - ll a2, grub_main_val - jr a2 -grub_main_val: - .quad EXT_C(grub_main) -efi_system_table_val: - .quad EXT_C(grub_efi_system_table) -efi_image_handle_val: - .quad EXT_C(grub_efi_image_handle) diff --git a/grub-core/kern/sparc64/dl.c b/grub-core/kern/sparc64/dl.c index 739be4717..d25c15e10 100644 --- a/grub-core/kern/sparc64/dl.c +++ b/grub-core/kern/sparc64/dl.c @@ -159,7 +159,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, if (value >> 32) return grub_error (GRUB_ERR_BAD_MODULE, "address out of 32 bits range"); - /* Fallthrough. */ case R_SPARC_LM22: *addr = (*addr & 0xFFC00000) | ((value >> 10) & 0x3FFFFF); break; diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S index 03b916f05..79b6bb325 100644 --- a/grub-core/kern/sparc64/ieee1275/crt0.S +++ b/grub-core/kern/sparc64/ieee1275/crt0.S @@ -27,7 +27,7 @@ _start: ba codestart mov %o4, %o0 - .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE + . = EXT_C(_start) + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE VARIABLE(grub_total_module_size) .word 0 diff --git a/grub-core/kern/sparc64/ieee1275/ieee1275.c b/grub-core/kern/sparc64/ieee1275/ieee1275.c index 5a59aaf06..53be692c3 100644 --- a/grub-core/kern/sparc64/ieee1275/ieee1275.c +++ b/grub-core/kern/sparc64/ieee1275/ieee1275.c @@ -89,59 +89,3 @@ grub_ieee1275_alloc_physmem (grub_addr_t *paddr, grub_size_t size, return args.catch_result; } - -grub_uint64_t -grub_ieee1275_num_blocks (grub_ieee1275_ihandle_t ihandle) -{ - struct nblocks_args_ieee1275 - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t blocks; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2); - args.method = (grub_ieee1275_cell_t) "#blocks"; - args.ihandle = ihandle; - args.catch_result = 1; - - if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result != 0)) - return -1; - - /* - * If the number of blocks exceeds the range of an unsigned number, - * return 0 to alert the caller to try the #blocks64 command. - */ - if (args.blocks >= 0xffffffffULL) - return 0; - - return args.blocks; -} - -grub_uint64_t -grub_ieee1275_num_blocks64 (grub_ieee1275_ihandle_t ihandle) -{ - struct nblocks_args_ieee1275 - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t ihandle; - grub_ieee1275_cell_t catch_result; - grub_ieee1275_cell_t hi_blocks; - grub_ieee1275_cell_t lo_blocks; - } - args; - - INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3); - args.method = (grub_ieee1275_cell_t) "#blocks64"; - args.ihandle = ihandle; - args.catch_result = 1; - - if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result != 0)) - return -1; - - return ((args.hi_blocks << 32) | (args.lo_blocks)); -} diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c index 14d596498..07720ee67 100644 --- a/grub-core/kern/term.c +++ b/grub-core/kern/term.c @@ -120,45 +120,6 @@ grub_getkey (void) } } -int -grub_getkeystatus (void) -{ - int status = 0; - grub_term_input_t term; - - if (grub_term_poll_usb) - grub_term_poll_usb (0); - - FOR_ACTIVE_TERM_INPUTS(term) - { - if (term->getkeystatus) - status |= term->getkeystatus (term); - } - - return status; -} - -int -grub_key_is_interrupt (int key) -{ - /* - * ESC sometimes is the BIOS setup hotkey and may be hard to discover, also - * check F4, which was chosen because is not used as a hotkey to enter the - * BIOS setup by any vendor. - */ - if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F4) - return 1; - - /* - * Pressing keys at the right time during boot is hard to time, also allow - * interrupting sleeps / the menu countdown by keeping shift pressed. - */ - if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT | GRUB_TERM_STATUS_RSHIFT)) - return 1; - - return 0; -} - void grub_refresh (void) { diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c index 3e338645c..5dcc106ed 100644 --- a/grub-core/kern/uboot/init.c +++ b/grub-core/kern/uboot/init.c @@ -36,14 +36,30 @@ extern char __bss_start[]; extern char _end[]; extern grub_size_t grub_total_module_size; +extern int (*grub_uboot_syscall_ptr) (int, int *, ...); static unsigned long timer_start; +extern grub_uint32_t grub_uboot_machine_type; +extern grub_addr_t grub_uboot_boot_data; + void grub_exit (void) { grub_uboot_return (0); } +grub_uint32_t +grub_uboot_get_machine_type (void) +{ + return grub_uboot_machine_type; +} + +grub_addr_t +grub_uboot_get_boot_data (void) +{ + return grub_uboot_boot_data; +} + static grub_uint64_t uboot_timer_ms (void) { diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c index aac8f9ae1..6800a4beb 100644 --- a/grub-core/kern/uboot/uboot.c +++ b/grub-core/kern/uboot/uboot.c @@ -39,13 +39,48 @@ * returns: 0 if the call not found, 1 if serviced */ +extern int (*grub_uboot_syscall_ptr) (int, int *, ...); extern int grub_uboot_syscall (int, int *, ...); +extern grub_addr_t grub_uboot_search_hint; static struct sys_info uboot_sys_info; static struct mem_region uboot_mem_info[5]; static struct device_info * devices; static int num_devices; +int +grub_uboot_api_init (void) +{ + struct api_signature *start, *end; + struct api_signature *p; + + if (grub_uboot_search_hint) + { + /* Extended search range to work around Trim Slice U-Boot issue */ + start = (struct api_signature *) ((grub_uboot_search_hint & ~0x000fffff) + - 0x00500000); + end = + (struct api_signature *) ((grub_addr_t) start + UBOOT_API_SEARCH_LEN - + API_SIG_MAGLEN + 0x00500000); + } + else + { + start = 0; + end = (struct api_signature *) (256 * 1024 * 1024); + } + + /* Structure alignment is (at least) 8 bytes */ + for (p = start; p < end; p = (void *) ((grub_addr_t) p + 8)) + { + if (grub_memcmp (&(p->magic), API_SIG_MAGIC, API_SIG_MAGLEN) == 0) + { + grub_uboot_syscall_ptr = p->syscall; + return p->version; + } + } + + return 0; +} /* * All functions below are wrappers around the grub_uboot_syscall() function @@ -133,7 +168,7 @@ grub_uboot_dev_enum (void) return num_devices; max_devices = 2; - enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); + enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); if (!enum_devices) return 0; @@ -243,22 +278,6 @@ grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks, return retval; } -int -grub_uboot_dev_write (struct device_info *dev, const void *buf, - grub_size_t blocks, grub_uint32_t start) -{ - int retval; - - if (!OPEN_DEV (dev)) - return -1; - - if (!grub_uboot_syscall (API_DEV_WRITE, &retval, dev, buf, - &blocks, &start)) - return -1; - - return retval; -} - int grub_uboot_dev_recv (struct device_info *dev, void *buf, int size, int *real_size) diff --git a/grub-core/kern/x86_64/dl.c b/grub-core/kern/x86_64/dl.c index 3a73e6e6c..440690673 100644 --- a/grub-core/kern/x86_64/dl.c +++ b/grub-core/kern/x86_64/dl.c @@ -70,7 +70,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr, break; case R_X86_64_PC32: - case R_X86_64_PLT32: { grub_int64_t value; value = ((grub_int32_t) *addr32) + rel->r_addend + sym->st_value - diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c index 782ca7295..0559c033c 100644 --- a/grub-core/kern/xen/init.c +++ b/grub-core/kern/xen/init.c @@ -41,13 +41,9 @@ grub_size_t grub_xen_n_allocated_shared_pages; static grub_xen_mfn_t grub_xen_ptr2mfn (void *ptr) { -#ifdef GRUB_MACHINE_XEN grub_xen_mfn_t *mfn_list = (grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list; return mfn_list[(grub_addr_t) ptr >> GRUB_XEN_LOG_PAGE_SIZE]; -#else - return (grub_addr_t) ptr >> GRUB_XEN_LOG_PAGE_SIZE; -#endif } void * @@ -108,6 +104,18 @@ grub_machine_get_bootlocation (char **device __attribute__ ((unused)), { } +static grub_uint8_t window[GRUB_XEN_PAGE_SIZE] + __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE))); + +#ifdef __x86_64__ +#define NUMBER_OF_LEVELS 4 +#else +#define NUMBER_OF_LEVELS 3 +#endif + +#define LOG_POINTERS_PER_PAGE 9 +#define POINTERS_PER_PAGE (1 << LOG_POINTERS_PER_PAGE) + void grub_xen_store_send (const void *buf_, grub_size_t len) { @@ -310,38 +318,6 @@ grub_xenstore_dir (const char *dir, unsigned long gntframe = 0; -static void -grub_xen_setup_gnttab (void) -{ - struct gnttab_set_version gnttab_setver; - struct gnttab_setup_table gnttab_setup; - - grub_memset (&gnttab_setver, 0, sizeof (gnttab_setver)); - - gnttab_setver.version = 1; - grub_xen_grant_table_op (GNTTABOP_set_version, &gnttab_setver, 1); - - grub_memset (&gnttab_setup, 0, sizeof (gnttab_setup)); - gnttab_setup.dom = DOMID_SELF; - gnttab_setup.nr_frames = 1; - gnttab_setup.frame_list.p = &gntframe; - - grub_xen_grant_table_op (GNTTABOP_setup_table, &gnttab_setup, 1); -} - -#ifdef GRUB_MACHINE_XEN -static grub_uint8_t window[GRUB_XEN_PAGE_SIZE] - __attribute__ ((aligned (GRUB_XEN_PAGE_SIZE))); - -#ifdef __x86_64__ -#define NUMBER_OF_LEVELS 4 -#else -#define NUMBER_OF_LEVELS 3 -#endif - -#define LOG_POINTERS_PER_PAGE 9 -#define POINTERS_PER_PAGE (1 << LOG_POINTERS_PER_PAGE) - #define MAX_N_UNUSABLE_PAGES 4 static int @@ -381,12 +357,26 @@ map_all_pages (void) (grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list; grub_uint64_t *pg = (grub_uint64_t *) window; grub_uint64_t oldpgstart, oldpgend; + struct gnttab_setup_table gnttab_setup; + struct gnttab_set_version gnttab_setver; grub_size_t n_unusable_pages = 0; struct mmu_update m2p_updates[2 * MAX_N_UNUSABLE_PAGES]; if (total_pages > MAX_TOTAL_PAGES - 4) total_pages = MAX_TOTAL_PAGES - 4; + grub_memset (&gnttab_setver, 0, sizeof (gnttab_setver)); + + gnttab_setver.version = 1; + grub_xen_grant_table_op (GNTTABOP_set_version, &gnttab_setver, 1); + + grub_memset (&gnttab_setup, 0, sizeof (gnttab_setup)); + gnttab_setup.dom = DOMID_SELF; + gnttab_setup.nr_frames = 1; + gnttab_setup.frame_list.p = &gntframe; + + grub_xen_grant_table_op (GNTTABOP_setup_table, &gnttab_setup, 1); + for (j = 0; j < total_pages - n_unusable_pages; j++) while (!grub_xen_is_page_usable (mfn_list[j])) { @@ -534,45 +524,20 @@ map_all_pages (void) grub_mm_init_region ((void *) heap_start, heap_end - heap_start); } -grub_err_t -grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) -{ - grub_uint64_t total_pages = grub_xen_start_page_addr->nr_pages; - grub_uint64_t usable_pages = grub_xen_start_page_addr->pt_base >> 12; - if (hook (0, page2offset (usable_pages), GRUB_MEMORY_AVAILABLE, hook_data)) - return GRUB_ERR_NONE; - - hook (page2offset (usable_pages), page2offset (total_pages - usable_pages), - GRUB_MEMORY_RESERVED, hook_data); - - return GRUB_ERR_NONE; -} -#endif - extern char _end[]; void grub_machine_init (void) { -#ifdef GRUB_MACHINE_XEN #ifdef __i386__ grub_xen_vm_assist (VMASST_CMD_enable, VMASST_TYPE_pae_extended_cr3); -#endif #endif grub_modbase = ALIGN_UP ((grub_addr_t) _end + GRUB_KERNEL_MACHINE_MOD_GAP, GRUB_KERNEL_MACHINE_MOD_ALIGN); -#ifdef GRUB_MACHINE_XEN_PVH - grub_xen_setup_pvh (); -#endif - - grub_xen_setup_gnttab (); - -#ifdef GRUB_MACHINE_XEN map_all_pages (); -#endif grub_console_init (); @@ -599,3 +564,17 @@ grub_machine_fini (int flags __attribute__ ((unused))) grub_xendisk_fini (); grub_boot_fini (); } + +grub_err_t +grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) +{ + grub_uint64_t total_pages = grub_xen_start_page_addr->nr_pages; + grub_uint64_t usable_pages = grub_xen_start_page_addr->pt_base >> 12; + if (hook (0, page2offset (usable_pages), GRUB_MEMORY_AVAILABLE, hook_data)) + return GRUB_ERR_NONE; + + hook (page2offset (usable_pages), page2offset (total_pages - usable_pages), + GRUB_MEMORY_RESERVED, hook_data); + + return GRUB_ERR_NONE; +} diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c index 753e56a95..f2ec04a8c 100644 --- a/grub-core/lib/LzmaEnc.c +++ b/grub-core/lib/LzmaEnc.c @@ -1877,19 +1877,13 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize } else { - UInt32 posSlot, lenToPosState; + UInt32 posSlot; RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); p->state = kMatchNextStates[p->state]; LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); pos -= LZMA_NUM_REPS; GetPosSlot(pos, posSlot); - lenToPosState = GetLenToPosState(len); - if (lenToPosState >= kNumLenToPosStates) - { - p->result = SZ_ERROR_DATA; - return CheckErrors(p); - } - RcTree_Encode(&p->rc, p->posSlotEncoder[lenToPosState], kNumPosSlotBits, posSlot); + RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); if (posSlot >= kStartPosModelIndex) { diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c index 8439a0062..fd7744a6f 100644 --- a/grub-core/lib/arg.c +++ b/grub-core/lib/arg.c @@ -23,7 +23,6 @@ #include #include #include -#include /* Built-in parser for default options. */ static const struct grub_arg_option help_options[] = @@ -217,13 +216,7 @@ static inline grub_err_t add_arg (char ***argl, int *num, char *s) { char **p = *argl; - grub_size_t sz; - - if (grub_add (++(*num), 1, &sz) || - grub_mul (sz, sizeof (char *), &sz)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - - *argl = grub_realloc (*argl, sz); + *argl = grub_realloc (*argl, (++(*num) + 1) * sizeof (char *)); if (! *argl) { grub_free (p); @@ -382,7 +375,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, case ARG_TYPE_INT: { - const char * tail; + char *tail; grub_strtoull (option, &tail, 0); if (tail == 0 || tail == option || *tail != '\0' || grub_errno) @@ -438,7 +431,6 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, grub_size_t argcnt; struct grub_arg_list *list; const struct grub_arg_option *options; - grub_size_t sz0, sz1; options = extcmd->options; if (! options) @@ -451,15 +443,7 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, argcnt += ((grub_size_t) argc + 1) / 2 + 1; /* max possible for any option */ } - if (grub_mul (sizeof (*list), i, &sz0) || - grub_mul (sizeof (char *), argcnt, &sz1) || - grub_add (sz0, sz1, &sz0)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - return 0; - } - - list = grub_zalloc (sz0); + list = grub_zalloc (sizeof (*list) * i + sizeof (char*) * argcnt); if (! list) return 0; diff --git a/grub-core/lib/arm64/setjmp.S b/grub-core/lib/arm64/setjmp.S index ffcabf6e4..adaafe40f 100644 --- a/grub-core/lib/arm64/setjmp.S +++ b/grub-core/lib/arm64/setjmp.S @@ -17,10 +17,8 @@ */ #include -#include .file "setjmp.S" -GRUB_MOD_LICENSE "GPLv3+" .text /* @@ -50,7 +48,6 @@ FUNCTION(grub_longjmp) ldp x29, x30, [x0], #16 ldr x2, [x0] mov sp, x2 - mov x0, #1 cmp x1, #0 csel x0, x1, x0, ne ret diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c index ed0b149dc..d5e10ee87 100644 --- a/grub-core/lib/cmdline.c +++ b/grub-core/lib/cmdline.c @@ -62,13 +62,12 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[]) return size; } -grub_err_t -grub_create_loader_cmdline (int argc, char *argv[], char *buf, - grub_size_t size, enum grub_verify_string_type type) +int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + grub_size_t size) { int i, space; unsigned int arg_size; - char *c, *orig_buf = buf; + char *c; for (i = 0; i < argc; i++) { @@ -105,5 +104,5 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, *buf = 0; - return grub_verify_string (orig_buf, type); + return i; } diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index ca334d5a4..8e8426c4a 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -205,16 +205,13 @@ grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher, { const grub_uint8_t *inptr, *end; grub_uint8_t *outptr; - grub_size_t blocksize; if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; end = (const grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) cipher->cipher->decrypt (cipher->ctx, outptr, inptr); return GPG_ERR_NO_ERROR; } @@ -225,16 +222,13 @@ grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher, { const grub_uint8_t *inptr, *end; grub_uint8_t *outptr; - grub_size_t blocksize; if (!cipher->cipher->encrypt) return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; end = (const grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) cipher->cipher->encrypt (cipher->ctx, outptr, inptr); return GPG_ERR_NO_ERROR; } @@ -247,23 +241,20 @@ grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher, grub_uint8_t *outptr; const grub_uint8_t *inptr, *end; void *iv; - grub_size_t blocksize; - if (!cipher->cipher->encrypt) + if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; end = (const grub_uint8_t *) in + size; iv = iv_in; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) { - grub_crypto_xor (outptr, inptr, iv, blocksize); + grub_crypto_xor (outptr, inptr, iv, cipher->cipher->blocksize); cipher->cipher->encrypt (cipher->ctx, outptr, outptr); iv = outptr; } - grub_memcpy (iv_in, iv, blocksize); + grub_memcpy (iv_in, iv, cipher->cipher->blocksize); return GPG_ERR_NO_ERROR; } @@ -275,23 +266,20 @@ grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher, const grub_uint8_t *inptr, *end; grub_uint8_t *outptr; grub_uint8_t ivt[GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE]; - grub_size_t blocksize; if (!cipher->cipher->decrypt) return GPG_ERR_NOT_SUPPORTED; - blocksize = cipher->cipher->blocksize; - if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0) - || ((size & (blocksize - 1)) != 0)) + if (size % cipher->cipher->blocksize != 0) return GPG_ERR_INV_ARG; - if (blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) + if (cipher->cipher->blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE) return GPG_ERR_INV_ARG; end = (const grub_uint8_t *) in + size; for (inptr = in, outptr = out; inptr < end; - inptr += blocksize, outptr += blocksize) + inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize) { - grub_memcpy (ivt, inptr, blocksize); + grub_memcpy (ivt, inptr, cipher->cipher->blocksize); cipher->cipher->decrypt (cipher->ctx, outptr, inptr); - grub_crypto_xor (outptr, outptr, iv, blocksize); - grub_memcpy (iv, ivt, blocksize); + grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize); + grub_memcpy (iv, ivt, cipher->cipher->blocksize); } return GPG_ERR_NO_ERROR; } @@ -462,7 +450,7 @@ grub_password_get (char buf[], unsigned buf_size) if (key == '\n' || key == '\r') break; - if (key == GRUB_TERM_ESC) + if (key == '\e') { cur_len = 0; break; @@ -470,8 +458,7 @@ grub_password_get (char buf[], unsigned buf_size) if (key == '\b') { - if (cur_len) - cur_len--; + cur_len--; continue; } @@ -487,7 +474,7 @@ grub_password_get (char buf[], unsigned buf_size) grub_xputs ("\n"); grub_refresh (); - return (key != GRUB_TERM_ESC); + return (key != '\e'); } #endif diff --git a/grub-core/lib/disk.c b/grub-core/lib/disk.c index b4eb064a8..0f186883a 100644 --- a/grub-core/lib/disk.c +++ b/grub-core/lib/disk.c @@ -101,8 +101,8 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_disk_cache_invalidate (disk->dev->id, disk->id, sector); - if ((disk->dev->disk_write) (disk, transform_sector (disk, sector), - 1, tmp_buf) != GRUB_ERR_NONE) + if ((disk->dev->write) (disk, transform_sector (disk, sector), + 1, tmp_buf) != GRUB_ERR_NONE) { grub_free (tmp_buf); goto finish; @@ -130,8 +130,8 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector, << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS - disk->log_sector_size)); - if ((disk->dev->disk_write) (disk, transform_sector (disk, sector), - n, buf) != GRUB_ERR_NONE) + if ((disk->dev->write) (disk, transform_sector (disk, sector), + n, buf) != GRUB_ERR_NONE) goto finish; while (n--) diff --git a/grub-core/lib/division.c b/grub-core/lib/division.c deleted file mode 100644 index 35606fea7..000000000 --- a/grub-core/lib/division.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_uint64_t -abs64(grub_int64_t a) -{ - return a > 0 ? a : -a; -} - -grub_int64_t -grub_divmod64s (grub_int64_t n, - grub_int64_t d, - grub_int64_t *ro) -{ - grub_uint64_t ru; - grub_int64_t q, r; - q = grub_divmod64 (abs64(n), abs64(d), &ru); - r = ru; - /* Now: |n| = |d| * q + r */ - if (n < 0) - { - /* -|n| = |d| * (-q) + (-r) */ - q = -q; - r = -r; - } - /* Now: n = |d| * q + r */ - if (d < 0) - { - /* n = (-|d|) * (-q) + r */ - q = -q; - } - /* Now: n = d * q + r */ - if (ro) - *ro = r; - return q; -} - -grub_uint32_t -grub_divmod32 (grub_uint32_t n, grub_uint32_t d, grub_uint32_t *ro) -{ - grub_uint64_t q, r; - q = grub_divmod64 (n, d, &r); - *ro = r; - return q; -} - -grub_int32_t -grub_divmod32s (grub_int32_t n, grub_int32_t d, grub_int32_t *ro) -{ - grub_int64_t q, r; - q = grub_divmod64s (n, d, &r); - *ro = r; - return q; -} diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c index 29d413641..e9441c844 100644 --- a/grub-core/lib/efi/halt.c +++ b/grub-core/lib/efi/halt.c @@ -28,10 +28,8 @@ void grub_halt (void) { - grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | - GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); -#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \ - !defined(__riscv) + grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); +#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) grub_acpi_halt (); #endif efi_call_4 (grub_efi_system_table->runtime_services->reset_system, diff --git a/grub-core/lib/dummy/reboot.c b/grub-core/lib/efi/reboot.c similarity index 77% rename from grub-core/lib/dummy/reboot.c rename to grub-core/lib/efi/reboot.c index b8cbed8f8..7de8bcb5d 100644 --- a/grub-core/lib/dummy/reboot.c +++ b/grub-core/lib/efi/reboot.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. + * Copyright (C) 2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,8 +16,10 @@ * along with GRUB. If not, see . */ -#include +#include +#include #include +#include #include #include @@ -25,8 +27,7 @@ void grub_reboot (void) { grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); - - /* Just stop here */ - - while (1); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); + for (;;) ; } diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c index 2e4e78b13..230e0e9d9 100644 --- a/grub-core/lib/envblk.c +++ b/grub-core/lib/envblk.c @@ -143,7 +143,7 @@ grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value) /* Move the following characters backward, and fill the new space with harmless characters. */ grub_memmove (p + vl, p + len, pend - (p + len)); - grub_memset (space - (len - vl), '#', len - vl); + grub_memset (space + len - vl, '#', len - vl); } else /* Move the following characters forward. */ diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c index 0d371c563..7e76dc06b 100644 --- a/grub-core/lib/fdt.c +++ b/grub-core/lib/fdt.c @@ -19,9 +19,6 @@ #include #include #include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); #define FDT_SUPPORTED_VERSION 17 @@ -41,6 +38,11 @@ GRUB_MOD_LICENSE ("GPLv3+"); (2 * sizeof(grub_uint32_t) \ + ALIGN_UP (grub_strlen (name) + 1, sizeof(grub_uint32_t))) +/* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff + fields, plus the property value, plus padding if needed. */ +#define prop_entry_size(prop_len) \ + (3 * sizeof(grub_uint32_t) + ALIGN_UP(prop_len, sizeof(grub_uint32_t))) + #define SKIP_NODE_NAME(name, token, end) \ name = (char *) ((token) + 1); \ while (name < (char *) end) \ @@ -81,7 +83,7 @@ static grub_uint32_t *get_next_node (const void *fdt, char *node_name) case FDT_PROP: /* Skip property token and following data (len, nameoff and property value). */ - token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) + token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_NOP: @@ -97,13 +99,13 @@ static grub_uint32_t *get_next_node (const void *fdt, char *node_name) static int get_mem_rsvmap_size (const void *fdt) { int size = 0; - grub_unaligned_uint64_t *ptr = (void *) ((grub_addr_t) fdt - + grub_fdt_get_off_mem_rsvmap (fdt)); + grub_uint64_t *ptr = (void *) ((grub_addr_t) fdt + + grub_fdt_get_off_mem_rsvmap (fdt)); do { size += 2 * sizeof(*ptr); - if (!ptr[0].val && !ptr[1].val) + if (!*ptr && !*(ptr + 1)) return size; ptr += 2; } while ((grub_addr_t) ptr <= (grub_addr_t) fdt + grub_fdt_get_totalsize (fdt) @@ -145,7 +147,7 @@ static int add_subnode (void *fdt, int parentoffset, const char *name) { case FDT_PROP: /* Skip len, nameoff and property value. */ - token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) + token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_BEGIN_NODE: @@ -224,7 +226,7 @@ static int rearrange_blocks (void *fdt, unsigned int clearance) return 0; } -static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset, +static grub_uint32_t *find_prop (void *fdt, unsigned int nodeoffset, const char *name) { grub_uint32_t *prop = (void *) ((grub_addr_t) fdt @@ -244,12 +246,12 @@ static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset, && !grub_strcmp (name, (char *) fdt + grub_fdt_get_off_dt_strings (fdt) + nameoff)) { - if (prop + grub_fdt_prop_entry_size(grub_be_to_cpu32(*(prop + 1))) + if (prop + prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop) >= end) return NULL; return prop; } - prop += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop); + prop += prop_entry_size(grub_be_to_cpu32(*(prop + 1))) / sizeof (*prop); } else if (grub_be_to_cpu32(*prop) == FDT_NOP) prop++; @@ -263,9 +265,9 @@ static grub_uint32_t *find_prop (const void *fdt, unsigned int nodeoffset, the size allocated for the FDT; if this function is called before the other functions in this file and returns success, the other functions are guaranteed not to access memory locations outside the allocated memory. */ -int grub_fdt_check_header_nosize (const void *fdt) +int grub_fdt_check_header_nosize (void *fdt) { - if (((grub_addr_t) fdt & 0x3) || (grub_fdt_get_magic (fdt) != FDT_MAGIC) + if (((grub_addr_t) fdt & 0x7) || (grub_fdt_get_magic (fdt) != FDT_MAGIC) || (grub_fdt_get_version (fdt) < FDT_SUPPORTED_VERSION) || (grub_fdt_get_last_comp_version (fdt) > FDT_SUPPORTED_VERSION) || (grub_fdt_get_off_dt_struct (fdt) & 0x00000003) @@ -281,7 +283,7 @@ int grub_fdt_check_header_nosize (const void *fdt) return 0; } -int grub_fdt_check_header (const void *fdt, unsigned int size) +int grub_fdt_check_header (void *fdt, unsigned int size) { if (size < sizeof (grub_fdt_header_t) || (grub_fdt_get_totalsize (fdt) > size) @@ -290,105 +292,52 @@ int grub_fdt_check_header (const void *fdt, unsigned int size) return 0; } -static const grub_uint32_t * -advance_token (const void *fdt, const grub_uint32_t *token, const grub_uint32_t *end, int skip_current) +/* Find a direct sub-node of a given parent node. */ +int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset, + const char *name) { - for (; token < end; skip_current = 0) + grub_uint32_t *token, *end; + char *node_name; + + if (parentoffset & 0x3) + return -1; + token = (void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt) + + parentoffset); + end = (void *) struct_end (fdt); + if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE)) + return -1; + SKIP_NODE_NAME(node_name, token, end); + while (token < end) { - switch (grub_be_to_cpu32 (*token)) + switch (grub_be_to_cpu32(*token)) { case FDT_BEGIN_NODE: - if (skip_current) - { - token = get_next_node (fdt, (char *) (token + 1)); - continue; - } - char *ptr; - for (ptr = (char *) (token + 1); *ptr && ptr < (char *) end; ptr++) - ; - if (ptr >= (char *) end) - return 0; - return token; + node_name = (char *) (token + 1); + if (node_name + grub_strlen (name) >= (char *) end) + return -1; + if (!grub_strcmp (node_name, name)) + return (int) ((grub_addr_t) token - (grub_addr_t) fdt + - grub_fdt_get_off_dt_struct (fdt)); + token = get_next_node (fdt, node_name); + if (!token) + return -1; + break; case FDT_PROP: /* Skip property token and following data (len, nameoff and property value). */ if (token >= end - 1) - return 0; - token += grub_fdt_prop_entry_size(grub_be_to_cpu32(*(token + 1))) + return -1; + token += prop_entry_size(grub_be_to_cpu32(*(token + 1))) / sizeof(*token); break; case FDT_NOP: token++; break; default: - return 0; + return -1; } } - return 0; -} - -int grub_fdt_next_node (const void *fdt, unsigned int currentoffset) -{ - const grub_uint32_t *token = (const grub_uint32_t *) fdt + (currentoffset + grub_fdt_get_off_dt_struct (fdt)) / 4; - token = advance_token (fdt, token, (const void *) struct_end (fdt), 1); - if (!token) - return -1; - return (int) ((grub_addr_t) token - (grub_addr_t) fdt - - grub_fdt_get_off_dt_struct (fdt)); -} - -int grub_fdt_first_node (const void *fdt, unsigned int parentoffset) -{ - const grub_uint32_t *token, *end; - char *node_name; - - if (parentoffset & 0x3) - return -1; - token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt) - + parentoffset); - end = (const void *) struct_end (fdt); - if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE)) - return -1; - SKIP_NODE_NAME(node_name, token, end); - token = advance_token (fdt, token, end, 0); - if (!token) - return -1; - return (int) ((grub_addr_t) token - (grub_addr_t) fdt - - grub_fdt_get_off_dt_struct (fdt)); -} - -/* Find a direct sub-node of a given parent node. */ -int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset, - const char *name) -{ - const grub_uint32_t *token, *end; - const char *node_name; - int skip_current = 0; - - if (parentoffset & 0x3) - return -1; - token = (const void *) ((grub_addr_t) fdt + grub_fdt_get_off_dt_struct(fdt) - + parentoffset); - end = (const void *) struct_end (fdt); - if ((token >= end) || (grub_be_to_cpu32(*token) != FDT_BEGIN_NODE)) - return -1; - SKIP_NODE_NAME(node_name, token, end); - while (1) { - token = advance_token (fdt, token, end, skip_current); - if (!token) - return -1; - skip_current = 1; - node_name = (const char *) token + 4; - if (grub_strcmp (node_name, name) == 0) - return (int) ((grub_addr_t) token - (grub_addr_t) fdt - - grub_fdt_get_off_dt_struct (fdt)); - } -} - -const char * -grub_fdt_get_nodename (const void *fdt, unsigned int nodeoffset) -{ - return (const char *) fdt + grub_fdt_get_off_dt_struct(fdt) + nodeoffset + 4; + return -1; } int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset, @@ -407,24 +356,6 @@ int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset, return add_subnode (fdt, parentoffset, name); } -const void * -grub_fdt_get_prop (const void *fdt, unsigned int nodeoffset, const char *name, - grub_uint32_t *len) -{ - grub_uint32_t *prop; - if ((nodeoffset >= grub_fdt_get_size_dt_struct (fdt)) || (nodeoffset & 0x3) - || (grub_be_to_cpu32(*(grub_uint32_t *) ((grub_addr_t) fdt - + grub_fdt_get_off_dt_struct (fdt) + nodeoffset)) - != FDT_BEGIN_NODE)) - return 0; - prop = find_prop (fdt, nodeoffset, name); - if (!prop) - return 0; - if (len) - *len = grub_be_to_cpu32 (*(prop + 1)); - return prop + 3; -} - int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, const void *val, grub_uint32_t len) { @@ -462,12 +393,12 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, unsigned int needed_space = 0; if (!prop) - needed_space = grub_fdt_prop_entry_size(len); + needed_space = prop_entry_size(len); if (!prop_name_present) needed_space += grub_strlen (name) + 1; if (needed_space > get_free_space (fdt)) return -1; - if (rearrange_blocks (fdt, !prop ? grub_fdt_prop_entry_size(len) : 0) < 0) + if (rearrange_blocks (fdt, !prop ? prop_entry_size(len) : 0) < 0) return -1; } if (!prop_name_present) { @@ -484,10 +415,10 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, + sizeof(grub_uint32_t)); prop = (void *) (node_name + ALIGN_UP(grub_strlen(node_name) + 1, 4)); - grub_memmove (prop + grub_fdt_prop_entry_size(len) / sizeof(*prop), prop, + grub_memmove (prop + prop_entry_size(len) / sizeof(*prop), prop, struct_end(fdt) - (grub_addr_t) prop); grub_fdt_set_size_dt_struct (fdt, grub_fdt_get_size_dt_struct (fdt) - + grub_fdt_prop_entry_size(len)); + + prop_entry_size(len)); *prop = grub_cpu_to_be32_compile_time (FDT_PROP); *(prop + 2) = grub_cpu_to_be32 (nameoff); } @@ -495,7 +426,7 @@ int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, /* Insert padding bytes at the end of the value; if they are not needed, they will be overwritten by the following memcpy. */ - *(prop + grub_fdt_prop_entry_size(len) / sizeof(grub_uint32_t) - 1) = 0; + *(prop + prop_entry_size(len) / sizeof(grub_uint32_t) - 1) = 0; grub_memcpy (prop + 3, val, len); return 0; diff --git a/grub-core/lib/gnulib-patches/fix-base64.patch b/grub-core/lib/gnulib-patches/fix-base64.patch deleted file mode 100644 index 985db1279..000000000 --- a/grub-core/lib/gnulib-patches/fix-base64.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/lib/base64.h b/lib/base64.h -index 9cd0183b8..185a2afa1 100644 ---- a/lib/base64.h -+++ b/lib/base64.h -@@ -21,8 +21,14 @@ - /* Get size_t. */ - # include - --/* Get bool. */ --# include -+#ifndef GRUB_POSIX_BOOL_DEFINED -+typedef enum { false = 0, true = 1 } bool; -+#define GRUB_POSIX_BOOL_DEFINED 1 -+#endif -+ -+#ifndef _GL_ATTRIBUTE_CONST -+# define _GL_ATTRIBUTE_CONST /* empty */ -+#endif - - # ifdef __cplusplus - extern "C" { diff --git a/grub-core/lib/gnulib-patches/no-abort.patch b/grub-core/lib/gnulib-patches/no-abort.patch deleted file mode 100644 index e469c4762..000000000 --- a/grub-core/lib/gnulib-patches/no-abort.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/lib/regcomp.c b/lib/regcomp.c -index cc85f35ac..de45ebb5c 100644 ---- a/lib/regcomp.c -+++ b/lib/regcomp.c -@@ -528,9 +528,9 @@ regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, - to this routine. If we are given anything else, or if other regex - code generates an invalid error code, then the program has a bug. - Dump core so we can fix it. */ -- abort (); -- -- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); -+ msg = gettext ("unknown regexp error"); -+ else -+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); - - msg_size = strlen (msg) + 1; /* Includes the null. */ - -@@ -1136,7 +1136,7 @@ optimize_utf8 (re_dfa_t *dfa) - } - break; - default: -- abort (); -+ break; - } - - if (mb_chars || has_period) diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c index c3e03c727..7a7796a12 100644 --- a/grub-core/lib/i386/backtrace.c +++ b/grub-core/lib/i386/backtrace.c @@ -56,11 +56,11 @@ void grub_backtrace (void) { #ifdef __x86_64__ - asm volatile ("movq %%rbp, %%rdi\n" - "callq *%%rax": :"a"(grub_backtrace_pointer)); + asm volatile ("movq %rbp, %rdi\n" + "call " EXT_C("grub_backtrace_pointer")); #else - asm volatile ("movl %%ebp, %%eax\n" - "calll *%%ecx": :"c"(grub_backtrace_pointer)); + asm volatile ("movl %ebp, %eax\n" + "call " EXT_C("grub_backtrace_pointer")); #endif } diff --git a/grub-core/lib/i386/halt.c b/grub-core/lib/i386/halt.c index 2364fe4d7..9f8405494 100644 --- a/grub-core/lib/i386/halt.c +++ b/grub-core/lib/i386/halt.c @@ -66,7 +66,7 @@ grub_halt (void) #endif /* Disable interrupts. */ - asm volatile ("cli"); + __asm__ __volatile__ ("cli"); /* Bochs, QEMU, etc. Removed in newer QEMU releases. */ for (i = 0; i < sizeof (bochs_shutdown) - 1; i++) diff --git a/grub-core/lib/i386/random.c b/grub-core/lib/i386/random.c deleted file mode 100644 index cd83d2f8f..000000000 --- a/grub-core/lib/i386/random.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -static int have_tsc = -1, have_pmtimer = -1; -static grub_port_t pmtimer_port; - -static int -detect_pmtimer (void) -{ - struct grub_acpi_fadt *fadt; - fadt = grub_acpi_find_fadt (); - if (!fadt) - return 0; - pmtimer_port = fadt->pmtimer; - if (!pmtimer_port) - return 0; - return 1; -} - -static int -pmtimer_tsc_get_random_bit (void) -{ - /* It's hard to come up with figures about pmtimer and tsc jitter but - 50 ppm seems to be typical. So we need 10^6/50 tsc cycles to get drift - of one tsc cycle. With TSC at least of 800 MHz it means 1/(50*800) - = 1/40000 s or about 3579545 / 40000 = 90 pmtimer ticks. - This gives us rate of 40000 bit/s or 5 kB/s. - */ - grub_uint64_t tsc_diff; - tsc_diff = grub_pmtimer_wait_count_tsc (pmtimer_port, 90); - if (tsc_diff == 0) - { - have_pmtimer = 0; - return -1; - } - return tsc_diff & 1; -} - -static int -pmtimer_tsc_get_random_byte (void) -{ - grub_uint8_t ret = 0; - int i, c; - for (i = 0; i < 8; i++) - { - c = pmtimer_tsc_get_random_bit (); - if (c < 0) - return -1; - ret |= c << i; - } - return ret; -} - -static int -pmtimer_fill_buffer (void *buffer, grub_size_t sz) -{ - grub_uint8_t *p = buffer; - int c; - while (sz) - { - c = pmtimer_tsc_get_random_byte (); - if (c < 0) - return 0; - *p++ = c; - sz--; - } - return 1; -} - -int -grub_crypto_arch_get_random (void *buffer, grub_size_t sz) -{ - if (have_tsc == -1) - have_tsc = grub_cpu_is_tsc_supported (); - if (!have_tsc) - return 0; - if (have_pmtimer == -1) - have_pmtimer = detect_pmtimer (); - if (!have_pmtimer) - return 0; - return pmtimer_fill_buffer (buffer, sz); -} diff --git a/grub-core/lib/i386/reboot.c b/grub-core/lib/i386/reboot.c index dce0b563d..a234244dc 100644 --- a/grub-core/lib/i386/reboot.c +++ b/grub-core/lib/i386/reboot.c @@ -16,8 +16,6 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_MACHINE_EFI - #include #include #include @@ -60,5 +58,3 @@ grub_reboot (void) while (1); } - -#endif /* GRUB_MACHINE_EFI */ diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c index 34cbe834f..ffaf25f08 100644 --- a/grub-core/lib/i386/relocator.c +++ b/grub-core/lib/i386/relocator.c @@ -64,6 +64,7 @@ extern grub_uint64_t grub_relocator64_rbx; extern grub_uint64_t grub_relocator64_rcx; extern grub_uint64_t grub_relocator64_rdx; extern grub_uint64_t grub_relocator64_rip; +extern grub_uint64_t grub_relocator64_rip_addr; extern grub_uint64_t grub_relocator64_rsp; extern grub_uint64_t grub_relocator64_rsi; extern grub_addr_t grub_relocator64_cr3; @@ -83,10 +84,11 @@ grub_relocator32_boot (struct grub_relocator *rel, /* Specific memory range due to Global Descriptor Table for use by payload that we will store in returned chunk. The address range and preference are based on "THE LINUX/x86 BOOT PROTOCOL" specification. */ - err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x1000, 0x9a000, - RELOCATOR_SIZEOF (32), 16, - GRUB_RELOCATOR_PREFERENCE_LOW, - avoid_efi_bootservices); + err = grub_relocator_alloc_chunk_align (rel, &ch, 0x1000, + 0x9a000 - RELOCATOR_SIZEOF (32), + RELOCATOR_SIZEOF (32), 16, + GRUB_RELOCATOR_PREFERENCE_LOW, + avoid_efi_bootservices); if (err) return err; @@ -124,10 +126,13 @@ grub_relocator16_boot (struct grub_relocator *rel, grub_relocator_chunk_t ch; /* Put it higher than the byte it checks for A20 check. */ - err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x8010, 0xa0000, - RELOCATOR_SIZEOF (16) + - GRUB_RELOCATOR16_STACK_SIZE, 16, - GRUB_RELOCATOR_PREFERENCE_NONE, 0); + err = grub_relocator_alloc_chunk_align (rel, &ch, 0x8010, + 0xa0000 - RELOCATOR_SIZEOF (16) + - GRUB_RELOCATOR16_STACK_SIZE, + RELOCATOR_SIZEOF (16) + + GRUB_RELOCATOR16_STACK_SIZE, 16, + GRUB_RELOCATOR_PREFERENCE_NONE, + 0); if (err) return err; @@ -179,9 +184,11 @@ grub_relocator64_boot (struct grub_relocator *rel, void *relst; grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align_safe (rel, &ch, min_addr, max_addr, - RELOCATOR_SIZEOF (64), 16, - GRUB_RELOCATOR_PREFERENCE_NONE, 0); + err = grub_relocator_alloc_chunk_align (rel, &ch, min_addr, + max_addr - RELOCATOR_SIZEOF (64), + RELOCATOR_SIZEOF (64), 16, + GRUB_RELOCATOR_PREFERENCE_NONE, + 0); if (err) return err; diff --git a/grub-core/lib/i386/relocator16.S b/grub-core/lib/i386/relocator16.S index e9238119b..c8d6f86d8 100644 --- a/grub-core/lib/i386/relocator16.S +++ b/grub-core/lib/i386/relocator16.S @@ -38,21 +38,15 @@ VARIABLE(grub_relocator16_start) #ifdef __APPLE__ LOCAL(cs_base_bytes12_offset) = LOCAL (cs_base_bytes12) - LOCAL (base) LOCAL(cs_base_byte3_offset) = LOCAL (cs_base_byte3) - LOCAL (base) - LOCAL(ds_base_bytes12_offset) = LOCAL (ds_base_bytes12) - LOCAL (base) - LOCAL(ds_base_byte3_offset) = LOCAL (ds_base_byte3) - LOCAL (base) movl %esi, %eax movw %ax, (LOCAL(cs_base_bytes12_offset)) (RSI, 1) - movw %ax, (LOCAL(ds_base_bytes12_offset)) (RSI, 1) shrl $16, %eax movb %al, (LOCAL (cs_base_byte3_offset)) (RSI, 1) - movb %al, (LOCAL (ds_base_byte3_offset)) (RSI, 1) #else movl %esi, %eax movw %ax, (LOCAL (cs_base_bytes12) - LOCAL (base)) (RSI, 1) - movw %ax, (LOCAL (ds_base_bytes12) - LOCAL (base)) (RSI, 1) shrl $16, %eax movb %al, (LOCAL (cs_base_byte3) - LOCAL (base)) (RSI, 1) - movb %al, (LOCAL (ds_base_byte3) - LOCAL (base)) (RSI, 1) #endif RELOAD_GDT @@ -94,15 +88,15 @@ VARIABLE(grub_relocator16_start) LOCAL(segment_offset) = LOCAL (segment) - LOCAL (base) LOCAL(idt_offset) = LOCAL(relocator16_idt) - LOCAL (base) LOCAL(cont2_offset) = LOCAL (cont2) - LOCAL(base) - movw %ax, (LOCAL(segment_offset)) - lidt (LOCAL(idt_offset)) + movw %ax, LOCAL(segment_offset) (%esi, 1) + lidt LOCAL(idt_offset) (%esi, 1) /* jump to a 16 bit segment */ ljmp $PSEUDO_REAL_CSEG, $(LOCAL(cont2_offset)) #else - movw %ax, (LOCAL (segment) - LOCAL (base)) + movw %ax, (LOCAL (segment) - LOCAL (base)) (%esi, 1) - lidt (EXT_C(grub_relocator16_idt) - LOCAL (base)) + lidt (EXT_C(grub_relocator16_idt) - LOCAL (base)) (%esi, 1) /* jump to a 16 bit segment */ ljmp $PSEUDO_REAL_CSEG, $(LOCAL (cont2) - LOCAL(base)) @@ -210,9 +204,8 @@ LOCAL(gate_a20_check_state): ret LOCAL(gate_a20_done): - /* - * We are in real mode now. Set up the real mode segment registers and - * all the other general purpose registers. cs is updated with ljmp. + /* we are in real mode now + * set up the real mode segment registers : DS, SS, ES */ /* movw imm16, %ax. */ .byte 0xb8 @@ -305,7 +298,7 @@ LOCAL(gdt): .byte 0, 0x92, 0xCF, 0 /* -- 16 bit real mode CS -- - * base = filled by code, limit 0x0FFFF (1 B Granularity), present + * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present * type = 16 bit code execute/read only/conforming, DPL = 0 */ .word 0xFFFF @@ -317,17 +310,11 @@ LOCAL(cs_base_byte3): .byte 0x9E, 0, 0 /* -- 16 bit real mode DS -- - * base = filled by code, limit 0x0FFFF (1 B Granularity), present + * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present * type = 16 bit data read/write, DPL = 0 */ - .word 0xFFFF -LOCAL(ds_base_bytes12): - .word 0 -LOCAL(ds_base_byte3): - .byte 0 - - .byte 0x92, 0, 0 - + .word 0xFFFF, 0 + .byte 0, 0x92, 0, 0 LOCAL(gdt_end): #ifdef __APPLE__ diff --git a/grub-core/lib/i386/relocator64.S b/grub-core/lib/i386/relocator64.S index 148f38adb..e4648d818 100644 --- a/grub-core/lib/i386/relocator64.S +++ b/grub-core/lib/i386/relocator64.S @@ -73,22 +73,6 @@ VARIABLE(grub_relocator64_rsp) movq %rax, %rsp -#ifdef GRUB_MACHINE_EFI - jmp LOCAL(skip_efi_stack_align) - - /* - * Here is grub_relocator64_efi_start() entry point. Most of the - * code below is shared between grub_relocator64_efi_start() - * and grub_relocator64_start(). - * - * Think twice before changing anything there!!! - */ -VARIABLE(grub_relocator64_efi_start) - /* Align the stack as UEFI spec requires. */ - andq $~15, %rsp - -LOCAL(skip_efi_stack_align): -#endif /* mov imm64, %rax */ .byte 0x48 .byte 0xb8 @@ -136,11 +120,6 @@ LOCAL(jump_addr): VARIABLE(grub_relocator64_rip) .quad 0 -#ifdef GRUB_MACHINE_EFI - /* Here grub_relocator64_efi_start() ends. Ufff... */ -VARIABLE(grub_relocator64_efi_end) -#endif - #ifndef __x86_64__ .p2align 4 LOCAL(gdt): diff --git a/grub-core/lib/i386/relocator_common.S b/grub-core/lib/i386/relocator_common.S index 1b5210dd3..03f427a03 100644 --- a/grub-core/lib/i386/relocator_common.S +++ b/grub-core/lib/i386/relocator_common.S @@ -29,6 +29,8 @@ #endif .macro DISABLE_PAGING +#ifdef GRUB_MACHINE_IEEE1275 +#endif movl %cr0, %eax andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax diff --git a/grub-core/lib/i386/xen/relocator.S b/grub-core/lib/i386/xen/relocator.S index 96e51b59a..694a54c85 100644 --- a/grub-core/lib/i386/xen/relocator.S +++ b/grub-core/lib/i386/xen/relocator.S @@ -16,8 +16,6 @@ * along with GRUB. If not, see . */ -#include -#include #include #include @@ -25,86 +23,78 @@ VARIABLE(grub_relocator_xen_remap_start) LOCAL(base): - /* Remap the remapper to it's new address. */ - /* mov imm32, %ebx - %ebx: new virtual address of remapper */ + /* mov imm32, %ebx */ .byte 0xbb VARIABLE(grub_relocator_xen_remapper_virt) .long 0 - /* mov imm32, %ecx - %ecx: low part of page table entry */ + /* mov imm32, %ecx */ .byte 0xb9 VARIABLE(grub_relocator_xen_remapper_map) .long 0 - /* mov imm32, %edx - %edx: high part of page table entry */ + /* mov imm32, %edx */ .byte 0xba VARIABLE(grub_relocator_xen_remapper_map_high) .long 0 - movl %ebx, %ebp /* %ebx is clobbered by hypercall */ + movl %ebx, %ebp - movl $UVMF_INVLPG, %esi /* esi: flags (inv. single entry) */ + movl $2, %esi movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 movl %ebp, %ebx addl $(LOCAL(cont) - LOCAL(base)), %ebx - jmp *%ebx /* Continue with new virtual address */ + jmp *%ebx LOCAL(cont): - /* Modify mappings of new page tables to be read-only. */ - /* mov imm32, %eax */ - .byte 0xb8 -VARIABLE(grub_relocator_xen_paging_areas_addr) - .long 0 - movl %eax, %ebx + xorl %eax, %eax + movl %eax, %ebp 1: - movl 0(%ebx), %ebp /* Get start pfn of the current area */ - movl GRUB_TARGET_SIZEOF_LONG(%ebx), %ecx /* Get # of pg tables */ - testl %ecx, %ecx /* 0 -> last area reached */ - jz 3f - addl $(2 * GRUB_TARGET_SIZEOF_LONG), %ebx - movl %ebx, %esp /* Save current area pointer */ -2: - movl %ecx, %edi /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_mfn_list) .long 0 - movl 0(%eax, %ebp, 4), %ecx /* mfn */ - movl %ebp, %ebx - shll $PAGE_SHIFT, %ebx /* virtual address (1:1 mapping) */ + movl %eax, %edi + movl %ebp, %eax + movl 0(%edi, %eax, 4), %ecx + + /* mov imm32, %ebx */ + .byte 0xbb +VARIABLE(grub_relocator_xen_paging_start) + .long 0 + shll $12, %eax + addl %eax, %ebx movl %ecx, %edx - shll $PAGE_SHIFT, %ecx /* prepare pte low part */ - shrl $(32 - PAGE_SHIFT), %edx /* pte high part */ - orl $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %ecx /* pte low */ - movl $UVMF_INVLPG, %esi + shll $12, %ecx + shrl $20, %edx + orl $5, %ecx + movl $2, %esi movl $__HYPERVISOR_update_va_mapping, %eax - int $0x82 /* parameters: eax, ebx, ecx, edx, esi */ + int $0x82 - incl %ebp /* next pfn */ - movl %edi, %ecx + incl %ebp + /* mov imm32, %ecx */ + .byte 0xb9 +VARIABLE(grub_relocator_xen_paging_size) + .long 0 + cmpl %ebp, %ecx - loop 2b + ja 1b - mov %esp, %ebx /* restore area poniter */ - jmp 1b - -3: - /* Switch page tables: pin new L3 pt, load cr3, unpin old L3. */ /* mov imm32, %ebx */ .byte 0xbb VARIABLE(grub_relocator_xen_mmu_op_addr) .long 0 - movl $3, %ecx /* 3 mmu ops */ - movl $0, %edx /* pdone (not used) */ - movl $DOMID_SELF, %esi + movl $3, %ecx + movl $0, %edx + movl $0x7FF0, %esi movl $__HYPERVISOR_mmuext_op, %eax int $0x82 - /* Continue in virtual kernel mapping. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remap_continue) @@ -112,9 +102,6 @@ VARIABLE(grub_relocator_xen_remap_continue) jmp *%eax -VARIABLE(grub_relocator_xen_paging_areas) - .long 0, 0, 0, 0, 0, 0, 0, 0 - VARIABLE(grub_relocator_xen_mmu_op) .space 256 @@ -122,22 +109,21 @@ VARIABLE(grub_relocator_xen_remap_end) VARIABLE(grub_relocator_xen_start) - /* Unmap old remapper area. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remapper_virt2) .long 0 - movl %eax, %ebx + movl %eax, %edi - xorl %ecx, %ecx /* Invalid pte */ + xorl %ecx, %ecx xorl %edx, %edx - movl $UVMF_INVLPG, %esi + movl $2, %esi movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 - /* Prepare registers for starting kernel. */ + /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_stack) @@ -159,7 +145,6 @@ VARIABLE(grub_relocator_xen_start_info) VARIABLE(grub_relocator_xen_entry_point) .long 0 - /* Now start the new kernel. */ jmp *%eax VARIABLE(grub_relocator_xen_end) diff --git a/grub-core/lib/ieee1275/datetime.c b/grub-core/lib/ieee1275/datetime.c index b81fba2ed..74578f15a 100644 --- a/grub-core/lib/ieee1275/datetime.c +++ b/grub-core/lib/ieee1275/datetime.c @@ -95,7 +95,7 @@ grub_get_datetime (struct grub_datetime *datetime) datetime->year = args.year; datetime->month = args.month; - datetime->day = args.day + 1; + datetime->day = args.day; datetime->hour = args.hour; datetime->minute = args.minute; datetime->second = args.second; @@ -140,7 +140,7 @@ grub_set_datetime (struct grub_datetime *datetime) args.year = datetime->year; args.month = datetime->month; - args.day = datetime->day - 1; + args.day = datetime->day; args.hour = datetime->hour; args.minute = datetime->minute; args.second = datetime->second; diff --git a/grub-core/lib/json/jsmn.h b/grub-core/lib/json/jsmn.h deleted file mode 100644 index 3178dcc97..000000000 --- a/grub-core/lib/json/jsmn.h +++ /dev/null @@ -1,471 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2010 Serge Zaitsev - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef JSMN_H -#define JSMN_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef JSMN_STATIC -#define JSMN_API static -#else -#define JSMN_API extern -#endif - -/** - * JSON type identifier. Basic types are: - * o Object - * o Array - * o String - * o Other primitive: number, boolean (true/false) or null - */ -typedef enum { - JSMN_UNDEFINED = 0, - JSMN_OBJECT = 1, - JSMN_ARRAY = 2, - JSMN_STRING = 3, - JSMN_PRIMITIVE = 4 -} jsmntype_t; - -enum jsmnerr { - /* Not enough tokens were provided */ - JSMN_ERROR_NOMEM = -1, - /* Invalid character inside JSON string */ - JSMN_ERROR_INVAL = -2, - /* The string is not a full JSON packet, more bytes expected */ - JSMN_ERROR_PART = -3 -}; - -/** - * JSON token description. - * type type (object, array, string etc.) - * start start position in JSON data string - * end end position in JSON data string - */ -typedef struct jsmntok { - jsmntype_t type; - int start; - int end; - int size; -#ifdef JSMN_PARENT_LINKS - int parent; -#endif -} jsmntok_t; - -/** - * JSON parser. Contains an array of token blocks available. Also stores - * the string being parsed now and current position in that string. - */ -typedef struct jsmn_parser { - unsigned int pos; /* offset in the JSON string */ - unsigned int toknext; /* next token to allocate */ - int toksuper; /* superior token node, e.g. parent object or array */ -} jsmn_parser; - -/** - * Create JSON parser over an array of tokens - */ -JSMN_API void jsmn_init(jsmn_parser *parser); - -/** - * Run JSON parser. It parses a JSON data string into and array of tokens, each - * describing - * a single JSON object. - */ -JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, - jsmntok_t *tokens, const unsigned int num_tokens); - -#ifndef JSMN_HEADER -/** - * Allocates a fresh unused token from the token pool. - */ -static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens, - const size_t num_tokens) { - jsmntok_t *tok; - if (parser->toknext >= num_tokens) { - return NULL; - } - tok = &tokens[parser->toknext++]; - tok->start = tok->end = -1; - tok->size = 0; -#ifdef JSMN_PARENT_LINKS - tok->parent = -1; -#endif - return tok; -} - -/** - * Fills token type and boundaries. - */ -static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type, - const int start, const int end) { - token->type = type; - token->start = start; - token->end = end; - token->size = 0; -} - -/** - * Fills next available token with JSON primitive. - */ -static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, - const size_t len, jsmntok_t *tokens, - const size_t num_tokens) { - jsmntok_t *token; - int start; - - start = parser->pos; - - for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { - switch (js[parser->pos]) { -#ifndef JSMN_STRICT - /* In strict mode primitive must be followed by "," or "}" or "]" */ - case ':': -#endif - case '\t': - case '\r': - case '\n': - case ' ': - case ',': - case ']': - case '}': - goto found; - default: - /* to quiet a warning from gcc*/ - break; - } - if (js[parser->pos] < 32 || js[parser->pos] >= 127) { - parser->pos = start; - return JSMN_ERROR_INVAL; - } - } -#ifdef JSMN_STRICT - /* In strict mode primitive must be followed by a comma/object/array */ - parser->pos = start; - return JSMN_ERROR_PART; -#endif - -found: - if (tokens == NULL) { - parser->pos--; - return 0; - } - token = jsmn_alloc_token(parser, tokens, num_tokens); - if (token == NULL) { - parser->pos = start; - return JSMN_ERROR_NOMEM; - } - jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); -#ifdef JSMN_PARENT_LINKS - token->parent = parser->toksuper; -#endif - parser->pos--; - return 0; -} - -/** - * Fills next token with JSON string. - */ -static int jsmn_parse_string(jsmn_parser *parser, const char *js, - const size_t len, jsmntok_t *tokens, - const size_t num_tokens) { - jsmntok_t *token; - - int start = parser->pos; - - parser->pos++; - - /* Skip starting quote */ - for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { - char c = js[parser->pos]; - - /* Quote: end of string */ - if (c == '\"') { - if (tokens == NULL) { - return 0; - } - token = jsmn_alloc_token(parser, tokens, num_tokens); - if (token == NULL) { - parser->pos = start; - return JSMN_ERROR_NOMEM; - } - jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos); -#ifdef JSMN_PARENT_LINKS - token->parent = parser->toksuper; -#endif - return 0; - } - - /* Backslash: Quoted symbol expected */ - if (c == '\\' && parser->pos + 1 < len) { - int i; - parser->pos++; - switch (js[parser->pos]) { - /* Allowed escaped symbols */ - case '\"': - case '/': - case '\\': - case 'b': - case 'f': - case 'r': - case 'n': - case 't': - break; - /* Allows escaped symbol \uXXXX */ - case 'u': - parser->pos++; - for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; - i++) { - /* If it isn't a hex character we have an error */ - if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ - (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ - (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ - parser->pos = start; - return JSMN_ERROR_INVAL; - } - parser->pos++; - } - parser->pos--; - break; - /* Unexpected symbol */ - default: - parser->pos = start; - return JSMN_ERROR_INVAL; - } - } - } - parser->pos = start; - return JSMN_ERROR_PART; -} - -/** - * Parse JSON string and fill tokens. - */ -JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, - jsmntok_t *tokens, const unsigned int num_tokens) { - int r; - int i; - jsmntok_t *token; - int count = parser->toknext; - - for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { - char c; - jsmntype_t type; - - c = js[parser->pos]; - switch (c) { - case '{': - case '[': - count++; - if (tokens == NULL) { - break; - } - token = jsmn_alloc_token(parser, tokens, num_tokens); - if (token == NULL) { - return JSMN_ERROR_NOMEM; - } - if (parser->toksuper != -1) { - jsmntok_t *t = &tokens[parser->toksuper]; -#ifdef JSMN_STRICT - /* In strict mode an object or array can't become a key */ - if (t->type == JSMN_OBJECT) { - return JSMN_ERROR_INVAL; - } -#endif - t->size++; -#ifdef JSMN_PARENT_LINKS - token->parent = parser->toksuper; -#endif - } - token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); - token->start = parser->pos; - parser->toksuper = parser->toknext - 1; - break; - case '}': - case ']': - if (tokens == NULL) { - break; - } - type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); -#ifdef JSMN_PARENT_LINKS - if (parser->toknext < 1) { - return JSMN_ERROR_INVAL; - } - token = &tokens[parser->toknext - 1]; - for (;;) { - if (token->start != -1 && token->end == -1) { - if (token->type != type) { - return JSMN_ERROR_INVAL; - } - token->end = parser->pos + 1; - parser->toksuper = token->parent; - break; - } - if (token->parent == -1) { - if (token->type != type || parser->toksuper == -1) { - return JSMN_ERROR_INVAL; - } - break; - } - token = &tokens[token->parent]; - } -#else - for (i = parser->toknext - 1; i >= 0; i--) { - token = &tokens[i]; - if (token->start != -1 && token->end == -1) { - if (token->type != type) { - return JSMN_ERROR_INVAL; - } - parser->toksuper = -1; - token->end = parser->pos + 1; - break; - } - } - /* Error if unmatched closing bracket */ - if (i == -1) { - return JSMN_ERROR_INVAL; - } - for (; i >= 0; i--) { - token = &tokens[i]; - if (token->start != -1 && token->end == -1) { - parser->toksuper = i; - break; - } - } -#endif - break; - case '\"': - r = jsmn_parse_string(parser, js, len, tokens, num_tokens); - if (r < 0) { - return r; - } - count++; - if (parser->toksuper != -1 && tokens != NULL) { - tokens[parser->toksuper].size++; - } - break; - case '\t': - case '\r': - case '\n': - case ' ': - break; - case ':': - parser->toksuper = parser->toknext - 1; - break; - case ',': - if (tokens != NULL && parser->toksuper != -1 && - tokens[parser->toksuper].type != JSMN_ARRAY && - tokens[parser->toksuper].type != JSMN_OBJECT) { -#ifdef JSMN_PARENT_LINKS - parser->toksuper = tokens[parser->toksuper].parent; -#else - for (i = parser->toknext - 1; i >= 0; i--) { - if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { - if (tokens[i].start != -1 && tokens[i].end == -1) { - parser->toksuper = i; - break; - } - } - } -#endif - } - break; -#ifdef JSMN_STRICT - /* In strict mode primitives are: numbers and booleans */ - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 't': - case 'f': - case 'n': - /* And they must not be keys of the object */ - if (tokens != NULL && parser->toksuper != -1) { - const jsmntok_t *t = &tokens[parser->toksuper]; - if (t->type == JSMN_OBJECT || - (t->type == JSMN_STRING && t->size != 0)) { - return JSMN_ERROR_INVAL; - } - } -#else - /* In non-strict mode every unquoted value is a primitive */ - default: -#endif - r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); - if (r < 0) { - return r; - } - count++; - if (parser->toksuper != -1 && tokens != NULL) { - tokens[parser->toksuper].size++; - } - break; - -#ifdef JSMN_STRICT - /* Unexpected char in strict mode */ - default: - return JSMN_ERROR_INVAL; -#endif - } - } - - if (tokens != NULL) { - for (i = parser->toknext - 1; i >= 0; i--) { - /* Unmatched opened object or array */ - if (tokens[i].start != -1 && tokens[i].end == -1) { - return JSMN_ERROR_PART; - } - } - } - - return count; -} - -/** - * Creates a new parser based over a given buffer with an array of tokens - * available. - */ -JSMN_API void jsmn_init(jsmn_parser *parser) { - parser->pos = 0; - parser->toknext = 0; - parser->toksuper = -1; -} - -#endif /* JSMN_HEADER */ - -#ifdef __cplusplus -} -#endif - -#endif /* JSMN_H */ diff --git a/grub-core/lib/json/json.c b/grub-core/lib/json/json.c deleted file mode 100644 index 1c20c75ea..000000000 --- a/grub-core/lib/json/json.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -#define JSMN_STATIC -#include "jsmn.h" -#include "json.h" - -GRUB_MOD_LICENSE ("GPLv3"); - -grub_err_t -grub_json_parse (grub_json_t **out, char *string, grub_size_t string_len) -{ - grub_json_t *json = NULL; - jsmn_parser parser; - grub_err_t ret = GRUB_ERR_NONE; - int jsmn_ret; - - if (!string) - return GRUB_ERR_BAD_ARGUMENT; - - json = grub_zalloc (sizeof (*json)); - if (!json) - return GRUB_ERR_OUT_OF_MEMORY; - json->string = string; - - /* - * Parse the string twice: first to determine how many tokens - * we need to allocate, second to fill allocated tokens. - */ - jsmn_init (&parser); - jsmn_ret = jsmn_parse (&parser, string, string_len, NULL, 0); - if (jsmn_ret <= 0) - { - ret = GRUB_ERR_BAD_ARGUMENT; - goto err; - } - - json->tokens = grub_calloc (jsmn_ret, sizeof (jsmntok_t)); - if (!json->tokens) - { - ret = GRUB_ERR_OUT_OF_MEMORY; - goto err; - } - - jsmn_init (&parser); - jsmn_ret = jsmn_parse (&parser, string, string_len, json->tokens, jsmn_ret); - if (jsmn_ret <= 0) - { - ret = GRUB_ERR_BAD_ARGUMENT; - goto err; - } - - *out = json; - - err: - if (ret) - grub_json_free (json); - - return ret; -} - -void -grub_json_free (grub_json_t *json) -{ - if (json) - { - grub_free (json->tokens); - grub_free (json); - } -} - -grub_err_t -grub_json_getsize (grub_size_t *out, const grub_json_t *json) -{ - int size; - - size = json->tokens[json->idx].size; - if (size < 0) - return GRUB_ERR_OUT_OF_RANGE; - - *out = (grub_size_t) size; - return GRUB_ERR_NONE; -} - -grub_err_t -grub_json_gettype (grub_json_type_t *out, const grub_json_t *json) -{ - switch (json->tokens[json->idx].type) - { - case JSMN_OBJECT: - *out = GRUB_JSON_OBJECT; - break; - case JSMN_ARRAY: - *out = GRUB_JSON_ARRAY; - break; - case JSMN_STRING: - *out = GRUB_JSON_STRING; - break; - case JSMN_PRIMITIVE: - *out = GRUB_JSON_PRIMITIVE; - break; - default: - return GRUB_ERR_BAD_ARGUMENT; - } - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_json_getchild (grub_json_t *out, const grub_json_t *parent, grub_size_t n) -{ - grub_size_t offset = 1, size; - jsmntok_t *p; - - if (grub_json_getsize (&size, parent) || n >= size) - return GRUB_ERR_OUT_OF_RANGE; - - /* - * Skip the first n children. For each of the children, we need - * to skip their own potential children (e.g. if it's an - * array), as well. We thus add the children's size to n on - * each iteration. - */ - p = &parent->tokens[parent->idx]; - while (n--) - n += p[offset++].size; - - out->string = parent->string; - out->tokens = parent->tokens; - out->idx = parent->idx + offset; - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_json_getvalue (grub_json_t *out, const grub_json_t *parent, const char *key) -{ - grub_json_type_t type; - grub_size_t i, size; - - if (grub_json_gettype (&type, parent) || type != GRUB_JSON_OBJECT) - return GRUB_ERR_BAD_ARGUMENT; - - if (grub_json_getsize (&size, parent)) - return GRUB_ERR_BAD_ARGUMENT; - - for (i = 0; i < size; i++) - { - grub_json_t child; - const char *s; - - if (grub_json_getchild (&child, parent, i) || - grub_json_getstring (&s, &child, NULL) || - grub_strcmp (s, key) != 0) - continue; - - return grub_json_getchild (out, &child, 0); - } - - return GRUB_ERR_FILE_NOT_FOUND; -} - -static grub_err_t -get_value (grub_json_type_t *out_type, const char **out_string, const grub_json_t *parent, const char *key) -{ - const grub_json_t *p = parent; - grub_json_t child; - grub_err_t ret; - jsmntok_t *tok; - - if (key) - { - ret = grub_json_getvalue (&child, parent, key); - if (ret) - return ret; - p = &child; - } - - tok = &p->tokens[p->idx]; - p->string[tok->end] = '\0'; - - *out_string = p->string + tok->start; - - return grub_json_gettype (out_type, p); -} - -grub_err_t -grub_json_getstring (const char **out, const grub_json_t *parent, const char *key) -{ - grub_json_type_t type; - const char *value; - grub_err_t ret; - - ret = get_value (&type, &value, parent, key); - if (ret) - return ret; - if (type != GRUB_JSON_STRING) - return GRUB_ERR_BAD_ARGUMENT; - - *out = value; - return GRUB_ERR_NONE; -} - -grub_err_t -grub_json_getuint64 (grub_uint64_t *out, const grub_json_t *parent, const char *key) -{ - grub_json_type_t type; - const char *value; - const char *end; - grub_err_t ret; - - ret = get_value (&type, &value, parent, key); - if (ret) - return ret; - if (type != GRUB_JSON_STRING && type != GRUB_JSON_PRIMITIVE) - return GRUB_ERR_BAD_ARGUMENT; - - grub_errno = GRUB_ERR_NONE; - *out = grub_strtoul (value, &end, 10); - if (grub_errno != GRUB_ERR_NONE || *end) - return GRUB_ERR_BAD_NUMBER; - - return GRUB_ERR_NONE; -} - -grub_err_t -grub_json_getint64 (grub_int64_t *out, const grub_json_t *parent, const char *key) -{ - grub_json_type_t type; - const char *value; - const char *end; - grub_err_t ret; - - ret = get_value (&type, &value, parent, key); - if (ret) - return ret; - if (type != GRUB_JSON_STRING && type != GRUB_JSON_PRIMITIVE) - return GRUB_ERR_BAD_ARGUMENT; - - grub_errno = GRUB_ERR_NONE; - *out = grub_strtol (value, &end, 10); - if (grub_errno != GRUB_ERR_NONE || *end) - return GRUB_ERR_BAD_NUMBER; - - return GRUB_ERR_NONE; -} diff --git a/grub-core/lib/json/json.h b/grub-core/lib/json/json.h deleted file mode 100644 index 4ea2a22d8..000000000 --- a/grub-core/lib/json/json.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_JSON_JSON_H -#define GRUB_JSON_JSON_H 1 - -#include - -enum grub_json_type -{ - /* Unordered collection of key-value pairs. */ - GRUB_JSON_OBJECT, - /* Ordered list of zero or more values. */ - GRUB_JSON_ARRAY, - /* Zero or more Unicode characters. */ - GRUB_JSON_STRING, - /* Number, boolean or empty value. */ - GRUB_JSON_PRIMITIVE, - /* Invalid token. */ - GRUB_JSON_UNDEFINED, -}; -typedef enum grub_json_type grub_json_type_t; - -/* Forward-declaration to avoid including jsmn.h. */ -struct jsmntok; - -struct grub_json -{ - struct jsmntok *tokens; - char *string; - grub_size_t idx; -}; -typedef struct grub_json grub_json_t; - -/* - * Parse a JSON-encoded string. Note that the string passed to - * this function will get modified on subsequent calls to - * grub_json_get*(). Returns the root object of the parsed JSON - * object, which needs to be free'd via grub_json_free(). Callers - * must ensure that the string outlives the returned root object, - * and that child objects must not be used after the root object - * has been free'd. - */ -extern grub_err_t EXPORT_FUNC(grub_json_parse) (grub_json_t **out, - char *string, - grub_size_t string_len); - -/* - * Free the structure and its contents. The string passed to - * grub_json_parse() will not be free'd. - */ -extern void EXPORT_FUNC(grub_json_free) (grub_json_t *json); - -/* - * Get the child count of a valid grub_json_t instance. Children - * are present for arrays, objects (dicts) and keys of a dict. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getsize) (grub_size_t *out, - const grub_json_t *json); - -/* Get the type of a valid grub_json_t instance. */ -extern grub_err_t EXPORT_FUNC(grub_json_gettype) (grub_json_type_t *out, - const grub_json_t *json); - -/* - * Get n'th child of a valid object, array or key. Will return an - * error if no such child exists. The result does not need to be - * free'd. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getchild) (grub_json_t *out, - const grub_json_t *parent, - grub_size_t n); - -/* - * Get value of key from a valid grub_json_t instance. The result - * does not need to be free'd. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getvalue) (grub_json_t *out, - const grub_json_t *parent, - const char *key); - -/* - * Get the string representation of a valid grub_json_t instance. - * If a key is given and parent is a JSON object, this function - * will return the string value of a child mapping to the key. - * If no key is given, it will return the string value of the - * parent itself. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getstring) (const char **out, - const grub_json_t *parent, - const char *key); - -/* - * Get the uint64 representation of a valid grub_json_t instance. - * Returns an error if the value pointed to by `parent` cannot be - * converted to an uint64. See grub_json_getstring() for details - * on the key parameter. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getuint64) (grub_uint64_t *out, - const grub_json_t *parent, - const char *key); - -/* - * Get the int64 representation of a valid grub_json_t instance. - * Returns an error if the value pointed to by `parent` cannot be - * converted to an int64. See grub_json_getstring() for - * details on the key parameter. - */ -extern grub_err_t EXPORT_FUNC(grub_json_getint64) (grub_int64_t *out, - const grub_json_t *parent, - const char *key); - -#endif diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index 05719ab2c..61266d95a 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -418,7 +418,7 @@ adjust_file (const char *in, grub_size_t len) } if (*comma != ',') return grub_legacy_escape (in, len); - part = grub_strtoull (comma + 1, &rest, 0); + part = grub_strtoull (comma + 1, (char **) &rest, 0); if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z') { subpart = rest[1] - 'a'; @@ -664,7 +664,6 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) { case TYPE_FILE_NO_CONSUME: hold_arg = 1; - /* Fallthrough. */ case TYPE_PARTITION: case TYPE_FILE: args[i] = adjust_file (curarg, curarglen); diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c index 63f6fcd11..f5e946a2d 100644 --- a/grub-core/lib/libgcrypt/cipher/ac.c +++ b/grub-core/lib/libgcrypt/cipher/ac.c @@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, gcry_mpi_t mpi; char *label; - data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); + data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); if (! data_mpis_new) { err = gcry_error_from_errno (errno); @@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, } /* Add MPI list. */ - arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); + arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); if (! arg_list) { err = gcry_error_from_errno (errno); @@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, /* We build a list of arguments to pass to gcry_sexp_build_array(). */ data_length = _gcry_ac_data_length (data); - arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); + arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); if (! arg_list) { err = gcry_error_from_errno (errno); @@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, arg_list_n += 2; /* Allocate list. */ - arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); + arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); if (! arg_list) { err = gcry_error_from_errno (errno); diff --git a/grub-core/lib/libgcrypt/cipher/bufhelp.h b/grub-core/lib/libgcrypt/cipher/bufhelp.h deleted file mode 100644 index df3559472..000000000 --- a/grub-core/lib/libgcrypt/cipher/bufhelp.h +++ /dev/null @@ -1,432 +0,0 @@ -/* bufhelp.h - Some buffer manipulation helpers - * Copyright (C) 2012 Jussi Kivilinna - * - * This file is part of Libgcrypt. - * - * Libgcrypt is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * Libgcrypt is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, see . - */ -#ifndef GCRYPT_BUFHELP_H -#define GCRYPT_BUFHELP_H - - -#include "bithelp.h" - - -#undef BUFHELP_FAST_UNALIGNED_ACCESS -#if defined(HAVE_GCC_ATTRIBUTE_PACKED) && \ - defined(HAVE_GCC_ATTRIBUTE_ALIGNED) && \ - (defined(__i386__) || defined(__x86_64__) || \ - (defined(__arm__) && defined(__ARM_FEATURE_UNALIGNED)) || \ - defined(__aarch64__)) -/* These architectures are able of unaligned memory accesses and can - handle those fast. - */ -# define BUFHELP_FAST_UNALIGNED_ACCESS 1 -#endif - - -#ifdef BUFHELP_FAST_UNALIGNED_ACCESS -/* Define type with one-byte alignment on architectures with fast unaligned - memory accesses. - */ -typedef struct bufhelp_int_s -{ - uintptr_t a; -} __attribute__((packed, aligned(1))) bufhelp_int_t; -#else -/* Define type with default alignment for other architectures (unaligned - accessed handled in per byte loops). - */ -typedef struct bufhelp_int_s -{ - uintptr_t a; -} bufhelp_int_t; -#endif - - -/* Optimized function for small buffer copying */ -static inline void -buf_cpy(void *_dst, const void *_src, size_t len) -{ -#if __GNUC__ >= 4 && (defined(__x86_64__) || defined(__i386__)) - /* For AMD64 and i386, memcpy is faster. */ - memcpy(_dst, _src, len); -#else - byte *dst = _dst; - const byte *src = _src; - bufhelp_int_t *ldst; - const bufhelp_int_t *lsrc; -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - const unsigned int longmask = sizeof(bufhelp_int_t) - 1; - - /* Skip fast processing if buffers are unaligned. */ - if (((uintptr_t)dst | (uintptr_t)src) & longmask) - goto do_bytes; -#endif - - ldst = (bufhelp_int_t *)(void *)dst; - lsrc = (const bufhelp_int_t *)(const void *)src; - - for (; len >= sizeof(bufhelp_int_t); len -= sizeof(bufhelp_int_t)) - (ldst++)->a = (lsrc++)->a; - - dst = (byte *)ldst; - src = (const byte *)lsrc; - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS -do_bytes: -#endif - /* Handle tail. */ - for (; len; len--) - *dst++ = *src++; -#endif /*__GNUC__ >= 4 && (__x86_64__ || __i386__)*/ -} - - -/* Optimized function for buffer xoring */ -static inline void -buf_xor(void *_dst, const void *_src1, const void *_src2, size_t len) -{ - byte *dst = _dst; - const byte *src1 = _src1; - const byte *src2 = _src2; - bufhelp_int_t *ldst; - const bufhelp_int_t *lsrc1, *lsrc2; -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - const unsigned int longmask = sizeof(bufhelp_int_t) - 1; - - /* Skip fast processing if buffers are unaligned. */ - if (((uintptr_t)dst | (uintptr_t)src1 | (uintptr_t)src2) & longmask) - goto do_bytes; -#endif - - ldst = (bufhelp_int_t *)(void *)dst; - lsrc1 = (const bufhelp_int_t *)(const void *)src1; - lsrc2 = (const bufhelp_int_t *)(const void *)src2; - - for (; len >= sizeof(bufhelp_int_t); len -= sizeof(bufhelp_int_t)) - (ldst++)->a = (lsrc1++)->a ^ (lsrc2++)->a; - - dst = (byte *)ldst; - src1 = (const byte *)lsrc1; - src2 = (const byte *)lsrc2; - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS -do_bytes: -#endif - /* Handle tail. */ - for (; len; len--) - *dst++ = *src1++ ^ *src2++; -} - - -/* Optimized function for in-place buffer xoring. */ -static inline void -buf_xor_1(void *_dst, const void *_src, size_t len) -{ - byte *dst = _dst; - const byte *src = _src; - bufhelp_int_t *ldst; - const bufhelp_int_t *lsrc; -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - const unsigned int longmask = sizeof(bufhelp_int_t) - 1; - - /* Skip fast processing if buffers are unaligned. */ - if (((uintptr_t)dst | (uintptr_t)src) & longmask) - goto do_bytes; -#endif - - ldst = (bufhelp_int_t *)(void *)dst; - lsrc = (const bufhelp_int_t *)(const void *)src; - - for (; len >= sizeof(bufhelp_int_t); len -= sizeof(bufhelp_int_t)) - (ldst++)->a ^= (lsrc++)->a; - - dst = (byte *)ldst; - src = (const byte *)lsrc; - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS -do_bytes: -#endif - /* Handle tail. */ - for (; len; len--) - *dst++ ^= *src++; -} - - -/* Optimized function for buffer xoring with two destination buffers. Used - mainly by CFB mode encryption. */ -static inline void -buf_xor_2dst(void *_dst1, void *_dst2, const void *_src, size_t len) -{ - byte *dst1 = _dst1; - byte *dst2 = _dst2; - const byte *src = _src; - bufhelp_int_t *ldst1, *ldst2; - const bufhelp_int_t *lsrc; -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - const unsigned int longmask = sizeof(bufhelp_int_t) - 1; - - /* Skip fast processing if buffers are unaligned. */ - if (((uintptr_t)src | (uintptr_t)dst1 | (uintptr_t)dst2) & longmask) - goto do_bytes; -#endif - - ldst1 = (bufhelp_int_t *)(void *)dst1; - ldst2 = (bufhelp_int_t *)(void *)dst2; - lsrc = (const bufhelp_int_t *)(const void *)src; - - for (; len >= sizeof(bufhelp_int_t); len -= sizeof(bufhelp_int_t)) - (ldst1++)->a = ((ldst2++)->a ^= (lsrc++)->a); - - dst1 = (byte *)ldst1; - dst2 = (byte *)ldst2; - src = (const byte *)lsrc; - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS -do_bytes: -#endif - /* Handle tail. */ - for (; len; len--) - *dst1++ = (*dst2++ ^= *src++); -} - - -/* Optimized function for combined buffer xoring and copying. Used by mainly - CBC mode decryption. */ -static inline void -buf_xor_n_copy_2(void *_dst_xor, const void *_src_xor, void *_srcdst_cpy, - const void *_src_cpy, size_t len) -{ - byte *dst_xor = _dst_xor; - byte *srcdst_cpy = _srcdst_cpy; - const byte *src_xor = _src_xor; - const byte *src_cpy = _src_cpy; - byte temp; - bufhelp_int_t *ldst_xor, *lsrcdst_cpy; - const bufhelp_int_t *lsrc_cpy, *lsrc_xor; - uintptr_t ltemp; -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - const unsigned int longmask = sizeof(bufhelp_int_t) - 1; - - /* Skip fast processing if buffers are unaligned. */ - if (((uintptr_t)src_cpy | (uintptr_t)src_xor | (uintptr_t)dst_xor | - (uintptr_t)srcdst_cpy) & longmask) - goto do_bytes; -#endif - - ldst_xor = (bufhelp_int_t *)(void *)dst_xor; - lsrc_xor = (const bufhelp_int_t *)(void *)src_xor; - lsrcdst_cpy = (bufhelp_int_t *)(void *)srcdst_cpy; - lsrc_cpy = (const bufhelp_int_t *)(const void *)src_cpy; - - for (; len >= sizeof(bufhelp_int_t); len -= sizeof(bufhelp_int_t)) - { - ltemp = (lsrc_cpy++)->a; - (ldst_xor++)->a = (lsrcdst_cpy)->a ^ (lsrc_xor++)->a; - (lsrcdst_cpy++)->a = ltemp; - } - - dst_xor = (byte *)ldst_xor; - src_xor = (const byte *)lsrc_xor; - srcdst_cpy = (byte *)lsrcdst_cpy; - src_cpy = (const byte *)lsrc_cpy; - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS -do_bytes: -#endif - /* Handle tail. */ - for (; len; len--) - { - temp = *src_cpy++; - *dst_xor++ = *srcdst_cpy ^ *src_xor++; - *srcdst_cpy++ = temp; - } -} - - -/* Optimized function for combined buffer xoring and copying. Used by mainly - CFB mode decryption. */ -static inline void -buf_xor_n_copy(void *_dst_xor, void *_srcdst_cpy, const void *_src, size_t len) -{ - buf_xor_n_copy_2(_dst_xor, _src, _srcdst_cpy, _src, len); -} - - -/* Constant-time compare of two buffers. Returns 1 if buffers are equal, - and 0 if buffers differ. */ -static inline int -buf_eq_const(const void *_a, const void *_b, size_t len) -{ - const byte *a = _a; - const byte *b = _b; - size_t diff, i; - - /* Constant-time compare. */ - for (i = 0, diff = 0; i < len; i++) - diff -= !!(a[i] - b[i]); - - return !diff; -} - - -#ifndef BUFHELP_FAST_UNALIGNED_ACCESS - -/* Functions for loading and storing unaligned u32 values of different - endianness. */ -static inline u32 buf_get_be32(const void *_buf) -{ - const byte *in = _buf; - return ((u32)in[0] << 24) | ((u32)in[1] << 16) | \ - ((u32)in[2] << 8) | (u32)in[3]; -} - -static inline u32 buf_get_le32(const void *_buf) -{ - const byte *in = _buf; - return ((u32)in[3] << 24) | ((u32)in[2] << 16) | \ - ((u32)in[1] << 8) | (u32)in[0]; -} - -static inline void buf_put_be32(void *_buf, u32 val) -{ - byte *out = _buf; - out[0] = val >> 24; - out[1] = val >> 16; - out[2] = val >> 8; - out[3] = val; -} - -static inline void buf_put_le32(void *_buf, u32 val) -{ - byte *out = _buf; - out[3] = val >> 24; - out[2] = val >> 16; - out[1] = val >> 8; - out[0] = val; -} - - -/* Functions for loading and storing unaligned u64 values of different - endianness. */ -static inline u64 buf_get_be64(const void *_buf) -{ - const byte *in = _buf; - return ((u64)in[0] << 56) | ((u64)in[1] << 48) | \ - ((u64)in[2] << 40) | ((u64)in[3] << 32) | \ - ((u64)in[4] << 24) | ((u64)in[5] << 16) | \ - ((u64)in[6] << 8) | (u64)in[7]; -} - -static inline u64 buf_get_le64(const void *_buf) -{ - const byte *in = _buf; - return ((u64)in[7] << 56) | ((u64)in[6] << 48) | \ - ((u64)in[5] << 40) | ((u64)in[4] << 32) | \ - ((u64)in[3] << 24) | ((u64)in[2] << 16) | \ - ((u64)in[1] << 8) | (u64)in[0]; -} - -static inline void buf_put_be64(void *_buf, u64 val) -{ - byte *out = _buf; - out[0] = val >> 56; - out[1] = val >> 48; - out[2] = val >> 40; - out[3] = val >> 32; - out[4] = val >> 24; - out[5] = val >> 16; - out[6] = val >> 8; - out[7] = val; -} - -static inline void buf_put_le64(void *_buf, u64 val) -{ - byte *out = _buf; - out[7] = val >> 56; - out[6] = val >> 48; - out[5] = val >> 40; - out[4] = val >> 32; - out[3] = val >> 24; - out[2] = val >> 16; - out[1] = val >> 8; - out[0] = val; -} - -#else /*BUFHELP_FAST_UNALIGNED_ACCESS*/ - -typedef struct bufhelp_u32_s -{ - u32 a; -} __attribute__((packed, aligned(1))) bufhelp_u32_t; - -/* Functions for loading and storing unaligned u32 values of different - endianness. */ -static inline u32 buf_get_be32(const void *_buf) -{ - return be_bswap32(((const bufhelp_u32_t *)_buf)->a); -} - -static inline u32 buf_get_le32(const void *_buf) -{ - return le_bswap32(((const bufhelp_u32_t *)_buf)->a); -} - -static inline void buf_put_be32(void *_buf, u32 val) -{ - bufhelp_u32_t *out = _buf; - out->a = be_bswap32(val); -} - -static inline void buf_put_le32(void *_buf, u32 val) -{ - bufhelp_u32_t *out = _buf; - out->a = le_bswap32(val); -} - - -typedef struct bufhelp_u64_s -{ - u64 a; -} __attribute__((packed, aligned(1))) bufhelp_u64_t; - -/* Functions for loading and storing unaligned u64 values of different - endianness. */ -static inline u64 buf_get_be64(const void *_buf) -{ - return be_bswap64(((const bufhelp_u64_t *)_buf)->a); -} - -static inline u64 buf_get_le64(const void *_buf) -{ - return le_bswap64(((const bufhelp_u64_t *)_buf)->a); -} - -static inline void buf_put_be64(void *_buf, u64 val) -{ - bufhelp_u64_t *out = _buf; - out->a = be_bswap64(val); -} - -static inline void buf_put_le64(void *_buf, u64 val) -{ - bufhelp_u64_t *out = _buf; - out->a = le_bswap64(val); -} - - -#endif /*BUFHELP_FAST_UNALIGNED_ACCESS*/ - -#endif /*GCRYPT_BUFHELP_H*/ diff --git a/grub-core/lib/libgcrypt/cipher/crc.c b/grub-core/lib/libgcrypt/cipher/crc.c index 28454f8ab..9e406f1b1 100644 --- a/grub-core/lib/libgcrypt/cipher/crc.c +++ b/grub-core/lib/libgcrypt/cipher/crc.c @@ -28,8 +28,116 @@ #include "cipher.h" #include "bithelp.h" -#include "bufhelp.h" +/* Table of CRCs of all 8-bit messages. Generated by running code + from RFC 1952 modified to print out the table. */ +static u32 crc32_table[256] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +/* + * The following function was extracted from RFC 1952 by Simon + * Josefsson, for the Shishi project, and modified to be compatible + * with the modified CRC-32 used by RFC 1510, and subsequently + * modified for GNU Libgcrypt to allow it to be used for calculating + * both unmodified CRC-32 and modified CRC-32 values. Original + * copyright and notice from the document follows: + * + * Copyright (c) 1996 L. Peter Deutsch + * + * Permission is granted to copy and distribute this document for + * any purpose and without charge, including translations into + * other languages and incorporation into compilations, provided + * that the copyright notice and this notice are preserved, and + * that any substantive changes or deletions from the original are + * clearly marked. + * + * The copyright on RFCs, and consequently the function below, are + * supposedly also retroactively claimed by the Internet Society + * (according to rfc-editor@rfc-editor.org), with the following + * copyright notice: + * + * Copyright (C) The Internet Society. All Rights Reserved. + * + * This document and translations of it may be copied and furnished + * to others, and derivative works that comment on or otherwise + * explain it or assist in its implementation may be prepared, + * copied, published and distributed, in whole or in part, without + * restriction of any kind, provided that the above copyright + * notice and this paragraph are included on all such copies and + * derivative works. However, this document itself may not be + * modified in any way, such as by removing the copyright notice or + * references to the Internet Society or other Internet + * organizations, except as needed for the purpose of developing + * Internet standards in which case the procedures for copyrights + * defined in the Internet Standards process must be followed, or + * as required to translate it into languages other than English. + * + * The limited permissions granted above are perpetual and will not be + * revoked by the Internet Society or its successors or assigns. + * + * This document and the information contained herein is provided + * on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET + * ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE + * OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A + * PARTICULAR PURPOSE. + * + */ +static u32 +update_crc32 (u32 crc, const void *buf_arg, size_t len) +{ + const char *buf = buf_arg; + size_t n; + + for (n = 0; n < len; n++) + crc = crc32_table[(crc ^ buf[n]) & 0xff] ^ (crc >> 8); + + return crc; +} typedef struct { @@ -38,302 +146,8 @@ typedef struct } CRC_CONTEXT; - -/* - * Code generated by universal_crc by Danjel McGougan - * - * CRC parameters used: - * bits: 32 - * poly: 0x04c11db7 - * init: 0xffffffff - * xor: 0xffffffff - * reverse: true - * non-direct: false - * - * CRC of the string "123456789" is 0xcbf43926 - */ - -static const u32 crc32_table[1024] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, - 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, - 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, - 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, - 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, - 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, - 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, - 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, - 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, - 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, - 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, - 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, - 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, - 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, - 0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, - 0x646cc504, 0x7d77f445, 0x565aa786, 0x4f4196c7, - 0xc8d98a08, 0xd1c2bb49, 0xfaefe88a, 0xe3f4d9cb, - 0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, 0x87981ccf, - 0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, - 0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496, - 0x821b9859, 0x9b00a918, 0xb02dfadb, 0xa936cb9a, - 0xe6775d5d, 0xff6c6c1c, 0xd4413fdf, 0xcd5a0e9e, - 0x958424a2, 0x8c9f15e3, 0xa7b24620, 0xbea97761, - 0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265, - 0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, - 0x39316bae, 0x202a5aef, 0x0b07092c, 0x121c386d, - 0xdf4636f3, 0xc65d07b2, 0xed705471, 0xf46b6530, - 0xbb2af3f7, 0xa231c2b6, 0x891c9175, 0x9007a034, - 0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, - 0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c, - 0xf0794f05, 0xe9627e44, 0xc24f2d87, 0xdb541cc6, - 0x94158a01, 0x8d0ebb40, 0xa623e883, 0xbf38d9c2, - 0x38a0c50d, 0x21bbf44c, 0x0a96a78f, 0x138d96ce, - 0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca, - 0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, - 0xded79850, 0xc7cca911, 0xece1fad2, 0xf5facb93, - 0x7262d75c, 0x6b79e61d, 0x4054b5de, 0x594f849f, - 0x160e1258, 0x0f152319, 0x243870da, 0x3d23419b, - 0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, - 0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60, - 0xad24e1af, 0xb43fd0ee, 0x9f12832d, 0x8609b26c, - 0xc94824ab, 0xd05315ea, 0xfb7e4629, 0xe2657768, - 0x2f3f79f6, 0x362448b7, 0x1d091b74, 0x04122a35, - 0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31, - 0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, - 0x838a36fa, 0x9a9107bb, 0xb1bc5478, 0xa8a76539, - 0x3b83984b, 0x2298a90a, 0x09b5fac9, 0x10aecb88, - 0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, 0x74c20e8c, - 0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, - 0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484, - 0x71418a1a, 0x685abb5b, 0x4377e898, 0x5a6cd9d9, - 0x152d4f1e, 0x0c367e5f, 0x271b2d9c, 0x3e001cdd, - 0xb9980012, 0xa0833153, 0x8bae6290, 0x92b553d1, - 0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5, - 0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, - 0xca6b79ed, 0xd37048ac, 0xf85d1b6f, 0xe1462a2e, - 0x66de36e1, 0x7fc507a0, 0x54e85463, 0x4df36522, - 0x02b2f3e5, 0x1ba9c2a4, 0x30849167, 0x299fa026, - 0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, - 0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f, - 0x2c1c24b0, 0x350715f1, 0x1e2a4632, 0x07317773, - 0x4870e1b4, 0x516bd0f5, 0x7a468336, 0x635db277, - 0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, 0xe0d7848d, - 0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189, - 0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, - 0x674f9842, 0x7e54a903, 0x5579fac0, 0x4c62cb81, - 0x8138c51f, 0x9823f45e, 0xb30ea79d, 0xaa1596dc, - 0xe554001b, 0xfc4f315a, 0xd7626299, 0xce7953d8, - 0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, - 0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0, - 0x5e7ef3ec, 0x4765c2ad, 0x6c48916e, 0x7553a02f, - 0x3a1236e8, 0x230907a9, 0x0824546a, 0x113f652b, - 0x96a779e4, 0x8fbc48a5, 0xa4911b66, 0xbd8a2a27, - 0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23, - 0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, - 0x70d024b9, 0x69cb15f8, 0x42e6463b, 0x5bfd777a, - 0xdc656bb5, 0xc57e5af4, 0xee530937, 0xf7483876, - 0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, 0x9324fd72, - 0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, - 0x0709a8dc, 0x06cbc2eb, 0x048d7cb2, 0x054f1685, - 0x0e1351b8, 0x0fd13b8f, 0x0d9785d6, 0x0c55efe1, - 0x091af964, 0x08d89353, 0x0a9e2d0a, 0x0b5c473d, - 0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, - 0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5, - 0x1235f2c8, 0x13f798ff, 0x11b126a6, 0x10734c91, - 0x153c5a14, 0x14fe3023, 0x16b88e7a, 0x177ae44d, - 0x384d46e0, 0x398f2cd7, 0x3bc9928e, 0x3a0bf8b9, - 0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065, - 0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, - 0x3157bf84, 0x3095d5b3, 0x32d36bea, 0x331101dd, - 0x246be590, 0x25a98fa7, 0x27ef31fe, 0x262d5bc9, - 0x23624d4c, 0x22a0277b, 0x20e69922, 0x2124f315, - 0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, - 0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad, - 0x709a8dc0, 0x7158e7f7, 0x731e59ae, 0x72dc3399, - 0x7793251c, 0x76514f2b, 0x7417f172, 0x75d59b45, - 0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, 0x7ccf6221, - 0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd, - 0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, - 0x6bb5866c, 0x6a77ec5b, 0x68315202, 0x69f33835, - 0x62af7f08, 0x636d153f, 0x612bab66, 0x60e9c151, - 0x65a6d7d4, 0x6464bde3, 0x662203ba, 0x67e0698d, - 0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, - 0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5, - 0x46c49a98, 0x4706f0af, 0x45404ef6, 0x448224c1, - 0x41cd3244, 0x400f5873, 0x4249e62a, 0x438b8c1d, - 0x54f16850, 0x55330267, 0x5775bc3e, 0x56b7d609, - 0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5, - 0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, - 0x5deb9134, 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d, - 0xe1351b80, 0xe0f771b7, 0xe2b1cfee, 0xe373a5d9, - 0xe63cb35c, 0xe7fed96b, 0xe5b86732, 0xe47a0d05, - 0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, - 0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd, - 0xfd13b8f0, 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, - 0xfa1a102c, 0xfbd87a1b, 0xf99ec442, 0xf85cae75, - 0xf300e948, 0xf2c2837f, 0xf0843d26, 0xf1465711, - 0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd, - 0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, - 0xde71f5bc, 0xdfb39f8b, 0xddf521d2, 0xdc374be5, - 0xd76b0cd8, 0xd6a966ef, 0xd4efd8b6, 0xd52db281, - 0xd062a404, 0xd1a0ce33, 0xd3e6706a, 0xd2241a5d, - 0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, - 0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895, - 0xcb4dafa8, 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, - 0xcc440774, 0xcd866d43, 0xcfc0d31a, 0xce02b92d, - 0x91af9640, 0x906dfc77, 0x922b422e, 0x93e92819, - 0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5, - 0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, - 0x98b56f24, 0x99770513, 0x9b31bb4a, 0x9af3d17d, - 0x8d893530, 0x8c4b5f07, 0x8e0de15e, 0x8fcf8b69, - 0x8a809dec, 0x8b42f7db, 0x89044982, 0x88c623b5, - 0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, - 0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d, - 0xa9e2d0a0, 0xa820ba97, 0xaa6604ce, 0xaba46ef9, - 0xaeeb787c, 0xaf29124b, 0xad6fac12, 0xacadc625, - 0xa7f18118, 0xa633eb2f, 0xa4755576, 0xa5b73f41, - 0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d, - 0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, - 0xb2cddb0c, 0xb30fb13b, 0xb1490f62, 0xb08b6555, - 0xbbd72268, 0xba15485f, 0xb853f606, 0xb9919c31, - 0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, 0xbe9834ed, - 0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, - 0x8f629757, 0x37def032, 0x256b5fdc, 0x9dd738b9, - 0xc5b428ef, 0x7d084f8a, 0x6fbde064, 0xd7018701, - 0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, 0x58631056, - 0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, - 0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26, - 0x95ad7f70, 0x2d111815, 0x3fa4b7fb, 0x8718d09e, - 0x1acfe827, 0xa2738f42, 0xb0c620ac, 0x087a47c9, - 0xa032af3e, 0x188ec85b, 0x0a3b67b5, 0xb28700d0, - 0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787, - 0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, - 0xeae41086, 0x525877e3, 0x40edd80d, 0xf851bf68, - 0xf02bf8a1, 0x48979fc4, 0x5a22302a, 0xe29e574f, - 0x7f496ff6, 0xc7f50893, 0xd540a77d, 0x6dfcc018, - 0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, - 0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7, - 0x9b14583d, 0x23a83f58, 0x311d90b6, 0x89a1f7d3, - 0x1476cf6a, 0xaccaa80f, 0xbe7f07e1, 0x06c36084, - 0x5ea070d2, 0xe61c17b7, 0xf4a9b859, 0x4c15df3c, - 0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b, - 0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, - 0x446f98f5, 0xfcd3ff90, 0xee66507e, 0x56da371b, - 0x0eb9274d, 0xb6054028, 0xa4b0efc6, 0x1c0c88a3, - 0x81dbb01a, 0x3967d77f, 0x2bd27891, 0x936e1ff4, - 0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, - 0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba, - 0xfe92dfec, 0x462eb889, 0x549b1767, 0xec277002, - 0x71f048bb, 0xc94c2fde, 0xdbf98030, 0x6345e755, - 0x6b3fa09c, 0xd383c7f9, 0xc1366817, 0x798a0f72, - 0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825, - 0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, - 0x21e91f24, 0x99557841, 0x8be0d7af, 0x335cb0ca, - 0xed59b63b, 0x55e5d15e, 0x47507eb0, 0xffec19d5, - 0x623b216c, 0xda874609, 0xc832e9e7, 0x708e8e82, - 0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, - 0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d, - 0xbd40e1a4, 0x05fc86c1, 0x1749292f, 0xaff54e4a, - 0x322276f3, 0x8a9e1196, 0x982bbe78, 0x2097d91d, - 0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, 0x6a4166a5, - 0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2, - 0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, - 0xc2098e52, 0x7ab5e937, 0x680046d9, 0xd0bc21bc, - 0x88df31ea, 0x3063568f, 0x22d6f961, 0x9a6a9e04, - 0x07bda6bd, 0xbf01c1d8, 0xadb46e36, 0x15080953, - 0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, - 0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623, - 0xd8c66675, 0x607a0110, 0x72cfaefe, 0xca73c99b, - 0x57a4f122, 0xef189647, 0xfdad39a9, 0x45115ecc, - 0x764dee06, 0xcef18963, 0xdc44268d, 0x64f841e8, - 0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf, - 0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, - 0x3c9b51be, 0x842736db, 0x96929935, 0x2e2efe50, - 0x2654b999, 0x9ee8defc, 0x8c5d7112, 0x34e11677, - 0xa9362ece, 0x118a49ab, 0x033fe645, 0xbb838120, - 0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, - 0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf, - 0xd67f4138, 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, - 0x591dd66f, 0xe1a1b10a, 0xf3141ee4, 0x4ba87981, - 0x13cb69d7, 0xab770eb2, 0xb9c2a15c, 0x017ec639, - 0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e, - 0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, - 0x090481f0, 0xb1b8e695, 0xa30d497b, 0x1bb12e1e, - 0x43d23e48, 0xfb6e592d, 0xe9dbf6c3, 0x516791a6, - 0xccb0a91f, 0x740cce7a, 0x66b96194, 0xde0506f1 -}; - /* CRC32 */ -static inline u32 -crc32_next (u32 crc, byte data) -{ - return (crc >> 8) ^ crc32_table[(crc & 0xff) ^ data]; -} - -/* - * Process 4 bytes in one go - */ -static inline u32 -crc32_next4 (u32 crc, u32 data) -{ - crc ^= data; - crc = crc32_table[(crc & 0xff) + 0x300] ^ - crc32_table[((crc >> 8) & 0xff) + 0x200] ^ - crc32_table[((crc >> 16) & 0xff) + 0x100] ^ - crc32_table[(crc >> 24) & 0xff]; - return crc; -} - static void crc32_init (void *context) { @@ -342,40 +156,12 @@ crc32_init (void *context) } static void -crc32_write (void *context, const void *inbuf_arg, size_t inlen) +crc32_write (void *context, const void *inbuf, size_t inlen) { CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; - const byte *inbuf = inbuf_arg; - u32 crc; - - if (!inbuf || !inlen) + if (!inbuf) return; - - crc = ctx->CRC; - - while (inlen >= 16) - { - inlen -= 16; - crc = crc32_next4(crc, buf_get_le32(&inbuf[0])); - crc = crc32_next4(crc, buf_get_le32(&inbuf[4])); - crc = crc32_next4(crc, buf_get_le32(&inbuf[8])); - crc = crc32_next4(crc, buf_get_le32(&inbuf[12])); - inbuf += 16; - } - - while (inlen >= 4) - { - inlen -= 4; - crc = crc32_next4(crc, buf_get_le32(inbuf)); - inbuf += 4; - } - - while (inlen--) - { - crc = crc32_next(crc, *inbuf++); - } - - ctx->CRC = crc; + ctx->CRC = update_crc32 (ctx->CRC, inbuf, inlen); } static byte * @@ -390,12 +176,13 @@ crc32_final (void *context) { CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; ctx->CRC ^= 0xffffffffL; - buf_put_be32 (ctx->buf, ctx->CRC); + ctx->buf[0] = (ctx->CRC >> 24) & 0xFF; + ctx->buf[1] = (ctx->CRC >> 16) & 0xFF; + ctx->buf[2] = (ctx->CRC >> 8) & 0xFF; + ctx->buf[3] = (ctx->CRC ) & 0xFF; } /* CRC32 a'la RFC 1510 */ -/* CRC of the string "123456789" is 0x2dfd2d88 */ - static void crc32rfc1510_init (void *context) { @@ -407,366 +194,82 @@ static void crc32rfc1510_final (void *context) { CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; - buf_put_be32(ctx->buf, ctx->CRC); + ctx->buf[0] = (ctx->CRC >> 24) & 0xFF; + ctx->buf[1] = (ctx->CRC >> 16) & 0xFF; + ctx->buf[2] = (ctx->CRC >> 8) & 0xFF; + ctx->buf[3] = (ctx->CRC ) & 0xFF; } /* CRC24 a'la RFC 2440 */ /* - * Code generated by universal_crc by Danjel McGougan + * The following CRC 24 routines are adapted from RFC 2440, which has + * the following copyright notice: * - * CRC parameters used: - * bits: 24 - * poly: 0x864cfb - * init: 0xb704ce - * xor: 0x000000 - * reverse: false - * non-direct: false + * Copyright (C) The Internet Society (1998). All Rights Reserved. * - * CRC of the string "123456789" is 0x21cf02 + * This document and translations of it may be copied and furnished + * to others, and derivative works that comment on or otherwise + * explain it or assist in its implementation may be prepared, + * copied, published and distributed, in whole or in part, without + * restriction of any kind, provided that the above copyright notice + * and this paragraph are included on all such copies and derivative + * works. However, this document itself may not be modified in any + * way, such as by removing the copyright notice or references to + * the Internet Society or other Internet organizations, except as + * needed for the purpose of developing Internet standards in which + * case the procedures for copyrights defined in the Internet + * Standards process must be followed, or as required to translate + * it into languages other than English. + * + * The limited permissions granted above are perpetual and will not be + * revoked by the Internet Society or its successors or assigns. + * + * This document and the information contained herein is provided on + * an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET + * ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE + * OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. */ -static const u32 crc24_table[1024] = -{ - 0x00000000, 0x00fb4c86, 0x000dd58a, 0x00f6990c, - 0x00e1e693, 0x001aaa15, 0x00ec3319, 0x00177f9f, - 0x003981a1, 0x00c2cd27, 0x0034542b, 0x00cf18ad, - 0x00d86732, 0x00232bb4, 0x00d5b2b8, 0x002efe3e, - 0x00894ec5, 0x00720243, 0x00849b4f, 0x007fd7c9, - 0x0068a856, 0x0093e4d0, 0x00657ddc, 0x009e315a, - 0x00b0cf64, 0x004b83e2, 0x00bd1aee, 0x00465668, - 0x005129f7, 0x00aa6571, 0x005cfc7d, 0x00a7b0fb, - 0x00e9d10c, 0x00129d8a, 0x00e40486, 0x001f4800, - 0x0008379f, 0x00f37b19, 0x0005e215, 0x00feae93, - 0x00d050ad, 0x002b1c2b, 0x00dd8527, 0x0026c9a1, - 0x0031b63e, 0x00cafab8, 0x003c63b4, 0x00c72f32, - 0x00609fc9, 0x009bd34f, 0x006d4a43, 0x009606c5, - 0x0081795a, 0x007a35dc, 0x008cacd0, 0x0077e056, - 0x00591e68, 0x00a252ee, 0x0054cbe2, 0x00af8764, - 0x00b8f8fb, 0x0043b47d, 0x00b52d71, 0x004e61f7, - 0x00d2a319, 0x0029ef9f, 0x00df7693, 0x00243a15, - 0x0033458a, 0x00c8090c, 0x003e9000, 0x00c5dc86, - 0x00eb22b8, 0x00106e3e, 0x00e6f732, 0x001dbbb4, - 0x000ac42b, 0x00f188ad, 0x000711a1, 0x00fc5d27, - 0x005beddc, 0x00a0a15a, 0x00563856, 0x00ad74d0, - 0x00ba0b4f, 0x004147c9, 0x00b7dec5, 0x004c9243, - 0x00626c7d, 0x009920fb, 0x006fb9f7, 0x0094f571, - 0x00838aee, 0x0078c668, 0x008e5f64, 0x007513e2, - 0x003b7215, 0x00c03e93, 0x0036a79f, 0x00cdeb19, - 0x00da9486, 0x0021d800, 0x00d7410c, 0x002c0d8a, - 0x0002f3b4, 0x00f9bf32, 0x000f263e, 0x00f46ab8, - 0x00e31527, 0x001859a1, 0x00eec0ad, 0x00158c2b, - 0x00b23cd0, 0x00497056, 0x00bfe95a, 0x0044a5dc, - 0x0053da43, 0x00a896c5, 0x005e0fc9, 0x00a5434f, - 0x008bbd71, 0x0070f1f7, 0x008668fb, 0x007d247d, - 0x006a5be2, 0x00911764, 0x00678e68, 0x009cc2ee, - 0x00a44733, 0x005f0bb5, 0x00a992b9, 0x0052de3f, - 0x0045a1a0, 0x00beed26, 0x0048742a, 0x00b338ac, - 0x009dc692, 0x00668a14, 0x00901318, 0x006b5f9e, - 0x007c2001, 0x00876c87, 0x0071f58b, 0x008ab90d, - 0x002d09f6, 0x00d64570, 0x0020dc7c, 0x00db90fa, - 0x00ccef65, 0x0037a3e3, 0x00c13aef, 0x003a7669, - 0x00148857, 0x00efc4d1, 0x00195ddd, 0x00e2115b, - 0x00f56ec4, 0x000e2242, 0x00f8bb4e, 0x0003f7c8, - 0x004d963f, 0x00b6dab9, 0x004043b5, 0x00bb0f33, - 0x00ac70ac, 0x00573c2a, 0x00a1a526, 0x005ae9a0, - 0x0074179e, 0x008f5b18, 0x0079c214, 0x00828e92, - 0x0095f10d, 0x006ebd8b, 0x00982487, 0x00636801, - 0x00c4d8fa, 0x003f947c, 0x00c90d70, 0x003241f6, - 0x00253e69, 0x00de72ef, 0x0028ebe3, 0x00d3a765, - 0x00fd595b, 0x000615dd, 0x00f08cd1, 0x000bc057, - 0x001cbfc8, 0x00e7f34e, 0x00116a42, 0x00ea26c4, - 0x0076e42a, 0x008da8ac, 0x007b31a0, 0x00807d26, - 0x009702b9, 0x006c4e3f, 0x009ad733, 0x00619bb5, - 0x004f658b, 0x00b4290d, 0x0042b001, 0x00b9fc87, - 0x00ae8318, 0x0055cf9e, 0x00a35692, 0x00581a14, - 0x00ffaaef, 0x0004e669, 0x00f27f65, 0x000933e3, - 0x001e4c7c, 0x00e500fa, 0x001399f6, 0x00e8d570, - 0x00c62b4e, 0x003d67c8, 0x00cbfec4, 0x0030b242, - 0x0027cddd, 0x00dc815b, 0x002a1857, 0x00d154d1, - 0x009f3526, 0x006479a0, 0x0092e0ac, 0x0069ac2a, - 0x007ed3b5, 0x00859f33, 0x0073063f, 0x00884ab9, - 0x00a6b487, 0x005df801, 0x00ab610d, 0x00502d8b, - 0x00475214, 0x00bc1e92, 0x004a879e, 0x00b1cb18, - 0x00167be3, 0x00ed3765, 0x001bae69, 0x00e0e2ef, - 0x00f79d70, 0x000cd1f6, 0x00fa48fa, 0x0001047c, - 0x002ffa42, 0x00d4b6c4, 0x00222fc8, 0x00d9634e, - 0x00ce1cd1, 0x00355057, 0x00c3c95b, 0x003885dd, - 0x00000000, 0x00488f66, 0x00901ecd, 0x00d891ab, - 0x00db711c, 0x0093fe7a, 0x004b6fd1, 0x0003e0b7, - 0x00b6e338, 0x00fe6c5e, 0x0026fdf5, 0x006e7293, - 0x006d9224, 0x00251d42, 0x00fd8ce9, 0x00b5038f, - 0x006cc771, 0x00244817, 0x00fcd9bc, 0x00b456da, - 0x00b7b66d, 0x00ff390b, 0x0027a8a0, 0x006f27c6, - 0x00da2449, 0x0092ab2f, 0x004a3a84, 0x0002b5e2, - 0x00015555, 0x0049da33, 0x00914b98, 0x00d9c4fe, - 0x00d88ee3, 0x00900185, 0x0048902e, 0x00001f48, - 0x0003ffff, 0x004b7099, 0x0093e132, 0x00db6e54, - 0x006e6ddb, 0x0026e2bd, 0x00fe7316, 0x00b6fc70, - 0x00b51cc7, 0x00fd93a1, 0x0025020a, 0x006d8d6c, - 0x00b44992, 0x00fcc6f4, 0x0024575f, 0x006cd839, - 0x006f388e, 0x0027b7e8, 0x00ff2643, 0x00b7a925, - 0x0002aaaa, 0x004a25cc, 0x0092b467, 0x00da3b01, - 0x00d9dbb6, 0x009154d0, 0x0049c57b, 0x00014a1d, - 0x004b5141, 0x0003de27, 0x00db4f8c, 0x0093c0ea, - 0x0090205d, 0x00d8af3b, 0x00003e90, 0x0048b1f6, - 0x00fdb279, 0x00b53d1f, 0x006dacb4, 0x002523d2, - 0x0026c365, 0x006e4c03, 0x00b6dda8, 0x00fe52ce, - 0x00279630, 0x006f1956, 0x00b788fd, 0x00ff079b, - 0x00fce72c, 0x00b4684a, 0x006cf9e1, 0x00247687, - 0x00917508, 0x00d9fa6e, 0x00016bc5, 0x0049e4a3, - 0x004a0414, 0x00028b72, 0x00da1ad9, 0x009295bf, - 0x0093dfa2, 0x00db50c4, 0x0003c16f, 0x004b4e09, - 0x0048aebe, 0x000021d8, 0x00d8b073, 0x00903f15, - 0x00253c9a, 0x006db3fc, 0x00b52257, 0x00fdad31, - 0x00fe4d86, 0x00b6c2e0, 0x006e534b, 0x0026dc2d, - 0x00ff18d3, 0x00b797b5, 0x006f061e, 0x00278978, - 0x002469cf, 0x006ce6a9, 0x00b47702, 0x00fcf864, - 0x0049fbeb, 0x0001748d, 0x00d9e526, 0x00916a40, - 0x00928af7, 0x00da0591, 0x0002943a, 0x004a1b5c, - 0x0096a282, 0x00de2de4, 0x0006bc4f, 0x004e3329, - 0x004dd39e, 0x00055cf8, 0x00ddcd53, 0x00954235, - 0x002041ba, 0x0068cedc, 0x00b05f77, 0x00f8d011, - 0x00fb30a6, 0x00b3bfc0, 0x006b2e6b, 0x0023a10d, - 0x00fa65f3, 0x00b2ea95, 0x006a7b3e, 0x0022f458, - 0x002114ef, 0x00699b89, 0x00b10a22, 0x00f98544, - 0x004c86cb, 0x000409ad, 0x00dc9806, 0x00941760, - 0x0097f7d7, 0x00df78b1, 0x0007e91a, 0x004f667c, - 0x004e2c61, 0x0006a307, 0x00de32ac, 0x0096bdca, - 0x00955d7d, 0x00ddd21b, 0x000543b0, 0x004dccd6, - 0x00f8cf59, 0x00b0403f, 0x0068d194, 0x00205ef2, - 0x0023be45, 0x006b3123, 0x00b3a088, 0x00fb2fee, - 0x0022eb10, 0x006a6476, 0x00b2f5dd, 0x00fa7abb, - 0x00f99a0c, 0x00b1156a, 0x006984c1, 0x00210ba7, - 0x00940828, 0x00dc874e, 0x000416e5, 0x004c9983, - 0x004f7934, 0x0007f652, 0x00df67f9, 0x0097e89f, - 0x00ddf3c3, 0x00957ca5, 0x004ded0e, 0x00056268, - 0x000682df, 0x004e0db9, 0x00969c12, 0x00de1374, - 0x006b10fb, 0x00239f9d, 0x00fb0e36, 0x00b38150, - 0x00b061e7, 0x00f8ee81, 0x00207f2a, 0x0068f04c, - 0x00b134b2, 0x00f9bbd4, 0x00212a7f, 0x0069a519, - 0x006a45ae, 0x0022cac8, 0x00fa5b63, 0x00b2d405, - 0x0007d78a, 0x004f58ec, 0x0097c947, 0x00df4621, - 0x00dca696, 0x009429f0, 0x004cb85b, 0x0004373d, - 0x00057d20, 0x004df246, 0x009563ed, 0x00ddec8b, - 0x00de0c3c, 0x0096835a, 0x004e12f1, 0x00069d97, - 0x00b39e18, 0x00fb117e, 0x002380d5, 0x006b0fb3, - 0x0068ef04, 0x00206062, 0x00f8f1c9, 0x00b07eaf, - 0x0069ba51, 0x00213537, 0x00f9a49c, 0x00b12bfa, - 0x00b2cb4d, 0x00fa442b, 0x0022d580, 0x006a5ae6, - 0x00df5969, 0x0097d60f, 0x004f47a4, 0x0007c8c2, - 0x00042875, 0x004ca713, 0x009436b8, 0x00dcb9de, - 0x00000000, 0x00d70983, 0x00555f80, 0x00825603, - 0x0051f286, 0x0086fb05, 0x0004ad06, 0x00d3a485, - 0x0059a88b, 0x008ea108, 0x000cf70b, 0x00dbfe88, - 0x00085a0d, 0x00df538e, 0x005d058d, 0x008a0c0e, - 0x00491c91, 0x009e1512, 0x001c4311, 0x00cb4a92, - 0x0018ee17, 0x00cfe794, 0x004db197, 0x009ab814, - 0x0010b41a, 0x00c7bd99, 0x0045eb9a, 0x0092e219, - 0x0041469c, 0x00964f1f, 0x0014191c, 0x00c3109f, - 0x006974a4, 0x00be7d27, 0x003c2b24, 0x00eb22a7, - 0x00388622, 0x00ef8fa1, 0x006dd9a2, 0x00bad021, - 0x0030dc2f, 0x00e7d5ac, 0x006583af, 0x00b28a2c, - 0x00612ea9, 0x00b6272a, 0x00347129, 0x00e378aa, - 0x00206835, 0x00f761b6, 0x007537b5, 0x00a23e36, - 0x00719ab3, 0x00a69330, 0x0024c533, 0x00f3ccb0, - 0x0079c0be, 0x00aec93d, 0x002c9f3e, 0x00fb96bd, - 0x00283238, 0x00ff3bbb, 0x007d6db8, 0x00aa643b, - 0x0029a4ce, 0x00fead4d, 0x007cfb4e, 0x00abf2cd, - 0x00785648, 0x00af5fcb, 0x002d09c8, 0x00fa004b, - 0x00700c45, 0x00a705c6, 0x002553c5, 0x00f25a46, - 0x0021fec3, 0x00f6f740, 0x0074a143, 0x00a3a8c0, - 0x0060b85f, 0x00b7b1dc, 0x0035e7df, 0x00e2ee5c, - 0x00314ad9, 0x00e6435a, 0x00641559, 0x00b31cda, - 0x003910d4, 0x00ee1957, 0x006c4f54, 0x00bb46d7, - 0x0068e252, 0x00bfebd1, 0x003dbdd2, 0x00eab451, - 0x0040d06a, 0x0097d9e9, 0x00158fea, 0x00c28669, - 0x001122ec, 0x00c62b6f, 0x00447d6c, 0x009374ef, - 0x001978e1, 0x00ce7162, 0x004c2761, 0x009b2ee2, - 0x00488a67, 0x009f83e4, 0x001dd5e7, 0x00cadc64, - 0x0009ccfb, 0x00dec578, 0x005c937b, 0x008b9af8, - 0x00583e7d, 0x008f37fe, 0x000d61fd, 0x00da687e, - 0x00506470, 0x00876df3, 0x00053bf0, 0x00d23273, - 0x000196f6, 0x00d69f75, 0x0054c976, 0x0083c0f5, - 0x00a9041b, 0x007e0d98, 0x00fc5b9b, 0x002b5218, - 0x00f8f69d, 0x002fff1e, 0x00ada91d, 0x007aa09e, - 0x00f0ac90, 0x0027a513, 0x00a5f310, 0x0072fa93, - 0x00a15e16, 0x00765795, 0x00f40196, 0x00230815, - 0x00e0188a, 0x00371109, 0x00b5470a, 0x00624e89, - 0x00b1ea0c, 0x0066e38f, 0x00e4b58c, 0x0033bc0f, - 0x00b9b001, 0x006eb982, 0x00ecef81, 0x003be602, - 0x00e84287, 0x003f4b04, 0x00bd1d07, 0x006a1484, - 0x00c070bf, 0x0017793c, 0x00952f3f, 0x004226bc, - 0x00918239, 0x00468bba, 0x00c4ddb9, 0x0013d43a, - 0x0099d834, 0x004ed1b7, 0x00cc87b4, 0x001b8e37, - 0x00c82ab2, 0x001f2331, 0x009d7532, 0x004a7cb1, - 0x00896c2e, 0x005e65ad, 0x00dc33ae, 0x000b3a2d, - 0x00d89ea8, 0x000f972b, 0x008dc128, 0x005ac8ab, - 0x00d0c4a5, 0x0007cd26, 0x00859b25, 0x005292a6, - 0x00813623, 0x00563fa0, 0x00d469a3, 0x00036020, - 0x0080a0d5, 0x0057a956, 0x00d5ff55, 0x0002f6d6, - 0x00d15253, 0x00065bd0, 0x00840dd3, 0x00530450, - 0x00d9085e, 0x000e01dd, 0x008c57de, 0x005b5e5d, - 0x0088fad8, 0x005ff35b, 0x00dda558, 0x000aacdb, - 0x00c9bc44, 0x001eb5c7, 0x009ce3c4, 0x004bea47, - 0x00984ec2, 0x004f4741, 0x00cd1142, 0x001a18c1, - 0x009014cf, 0x00471d4c, 0x00c54b4f, 0x001242cc, - 0x00c1e649, 0x0016efca, 0x0094b9c9, 0x0043b04a, - 0x00e9d471, 0x003eddf2, 0x00bc8bf1, 0x006b8272, - 0x00b826f7, 0x006f2f74, 0x00ed7977, 0x003a70f4, - 0x00b07cfa, 0x00677579, 0x00e5237a, 0x00322af9, - 0x00e18e7c, 0x003687ff, 0x00b4d1fc, 0x0063d87f, - 0x00a0c8e0, 0x0077c163, 0x00f59760, 0x00229ee3, - 0x00f13a66, 0x002633e5, 0x00a465e6, 0x00736c65, - 0x00f9606b, 0x002e69e8, 0x00ac3feb, 0x007b3668, - 0x00a892ed, 0x007f9b6e, 0x00fdcd6d, 0x002ac4ee, - 0x00000000, 0x00520936, 0x00a4126c, 0x00f61b5a, - 0x004825d8, 0x001a2cee, 0x00ec37b4, 0x00be3e82, - 0x006b0636, 0x00390f00, 0x00cf145a, 0x009d1d6c, - 0x002323ee, 0x00712ad8, 0x00873182, 0x00d538b4, - 0x00d60c6c, 0x0084055a, 0x00721e00, 0x00201736, - 0x009e29b4, 0x00cc2082, 0x003a3bd8, 0x006832ee, - 0x00bd0a5a, 0x00ef036c, 0x00191836, 0x004b1100, - 0x00f52f82, 0x00a726b4, 0x00513dee, 0x000334d8, - 0x00ac19d8, 0x00fe10ee, 0x00080bb4, 0x005a0282, - 0x00e43c00, 0x00b63536, 0x00402e6c, 0x0012275a, - 0x00c71fee, 0x009516d8, 0x00630d82, 0x003104b4, - 0x008f3a36, 0x00dd3300, 0x002b285a, 0x0079216c, - 0x007a15b4, 0x00281c82, 0x00de07d8, 0x008c0eee, - 0x0032306c, 0x0060395a, 0x00962200, 0x00c42b36, - 0x00111382, 0x00431ab4, 0x00b501ee, 0x00e708d8, - 0x0059365a, 0x000b3f6c, 0x00fd2436, 0x00af2d00, - 0x00a37f36, 0x00f17600, 0x00076d5a, 0x0055646c, - 0x00eb5aee, 0x00b953d8, 0x004f4882, 0x001d41b4, - 0x00c87900, 0x009a7036, 0x006c6b6c, 0x003e625a, - 0x00805cd8, 0x00d255ee, 0x00244eb4, 0x00764782, - 0x0075735a, 0x00277a6c, 0x00d16136, 0x00836800, - 0x003d5682, 0x006f5fb4, 0x009944ee, 0x00cb4dd8, - 0x001e756c, 0x004c7c5a, 0x00ba6700, 0x00e86e36, - 0x005650b4, 0x00045982, 0x00f242d8, 0x00a04bee, - 0x000f66ee, 0x005d6fd8, 0x00ab7482, 0x00f97db4, - 0x00474336, 0x00154a00, 0x00e3515a, 0x00b1586c, - 0x006460d8, 0x003669ee, 0x00c072b4, 0x00927b82, - 0x002c4500, 0x007e4c36, 0x0088576c, 0x00da5e5a, - 0x00d96a82, 0x008b63b4, 0x007d78ee, 0x002f71d8, - 0x00914f5a, 0x00c3466c, 0x00355d36, 0x00675400, - 0x00b26cb4, 0x00e06582, 0x00167ed8, 0x004477ee, - 0x00fa496c, 0x00a8405a, 0x005e5b00, 0x000c5236, - 0x0046ff6c, 0x0014f65a, 0x00e2ed00, 0x00b0e436, - 0x000edab4, 0x005cd382, 0x00aac8d8, 0x00f8c1ee, - 0x002df95a, 0x007ff06c, 0x0089eb36, 0x00dbe200, - 0x0065dc82, 0x0037d5b4, 0x00c1ceee, 0x0093c7d8, - 0x0090f300, 0x00c2fa36, 0x0034e16c, 0x0066e85a, - 0x00d8d6d8, 0x008adfee, 0x007cc4b4, 0x002ecd82, - 0x00fbf536, 0x00a9fc00, 0x005fe75a, 0x000dee6c, - 0x00b3d0ee, 0x00e1d9d8, 0x0017c282, 0x0045cbb4, - 0x00eae6b4, 0x00b8ef82, 0x004ef4d8, 0x001cfdee, - 0x00a2c36c, 0x00f0ca5a, 0x0006d100, 0x0054d836, - 0x0081e082, 0x00d3e9b4, 0x0025f2ee, 0x0077fbd8, - 0x00c9c55a, 0x009bcc6c, 0x006dd736, 0x003fde00, - 0x003cead8, 0x006ee3ee, 0x0098f8b4, 0x00caf182, - 0x0074cf00, 0x0026c636, 0x00d0dd6c, 0x0082d45a, - 0x0057ecee, 0x0005e5d8, 0x00f3fe82, 0x00a1f7b4, - 0x001fc936, 0x004dc000, 0x00bbdb5a, 0x00e9d26c, - 0x00e5805a, 0x00b7896c, 0x00419236, 0x00139b00, - 0x00ada582, 0x00ffacb4, 0x0009b7ee, 0x005bbed8, - 0x008e866c, 0x00dc8f5a, 0x002a9400, 0x00789d36, - 0x00c6a3b4, 0x0094aa82, 0x0062b1d8, 0x0030b8ee, - 0x00338c36, 0x00618500, 0x00979e5a, 0x00c5976c, - 0x007ba9ee, 0x0029a0d8, 0x00dfbb82, 0x008db2b4, - 0x00588a00, 0x000a8336, 0x00fc986c, 0x00ae915a, - 0x0010afd8, 0x0042a6ee, 0x00b4bdb4, 0x00e6b482, - 0x00499982, 0x001b90b4, 0x00ed8bee, 0x00bf82d8, - 0x0001bc5a, 0x0053b56c, 0x00a5ae36, 0x00f7a700, - 0x00229fb4, 0x00709682, 0x00868dd8, 0x00d484ee, - 0x006aba6c, 0x0038b35a, 0x00cea800, 0x009ca136, - 0x009f95ee, 0x00cd9cd8, 0x003b8782, 0x00698eb4, - 0x00d7b036, 0x0085b900, 0x0073a25a, 0x0021ab6c, - 0x00f493d8, 0x00a69aee, 0x005081b4, 0x00028882, - 0x00bcb600, 0x00eebf36, 0x0018a46c, 0x004aad5a -}; - -static inline -u32 crc24_init (void) -{ - return 0xce04b7; -} - -static inline -u32 crc24_next (u32 crc, byte data) -{ - return (crc >> 8) ^ crc24_table[(crc & 0xff) ^ data]; -} - -/* - * Process 4 bytes in one go - */ -static inline -u32 crc24_next4 (u32 crc, u32 data) -{ - crc ^= data; - crc = crc24_table[(crc & 0xff) + 0x300] ^ - crc24_table[((crc >> 8) & 0xff) + 0x200] ^ - crc24_table[((crc >> 16) & 0xff) + 0x100] ^ - crc24_table[(crc >> 24) & 0xff]; - return crc; -} - -static inline -u32 crc24_final (u32 crc) -{ - return crc & 0xffffff; -} +#define CRC24_INIT 0xb704ceL +#define CRC24_POLY 0x1864cfbL static void crc24rfc2440_init (void *context) { CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; - ctx->CRC = crc24_init(); + ctx->CRC = CRC24_INIT; } static void crc24rfc2440_write (void *context, const void *inbuf_arg, size_t inlen) { const unsigned char *inbuf = inbuf_arg; + int i; CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; - u32 crc; - if (!inbuf || !inlen) + if (!inbuf) return; - crc = ctx->CRC; - - while (inlen >= 16) - { - inlen -= 16; - crc = crc24_next4(crc, buf_get_le32(&inbuf[0])); - crc = crc24_next4(crc, buf_get_le32(&inbuf[4])); - crc = crc24_next4(crc, buf_get_le32(&inbuf[8])); - crc = crc24_next4(crc, buf_get_le32(&inbuf[12])); - inbuf += 16; + while (inlen--) { + ctx->CRC ^= (*inbuf++) << 16; + for (i = 0; i < 8; i++) { + ctx->CRC <<= 1; + if (ctx->CRC & 0x1000000) + ctx->CRC ^= CRC24_POLY; } - - while (inlen >= 4) - { - inlen -= 4; - crc = crc24_next4(crc, buf_get_le32(inbuf)); - inbuf += 4; - } - - while (inlen--) - { - crc = crc24_next(crc, *inbuf++); - } - - ctx->CRC = crc; + } } static void crc24rfc2440_final (void *context) { CRC_CONTEXT *ctx = (CRC_CONTEXT *) context; - ctx->CRC = crc24_final(ctx->CRC); - buf_put_le32 (ctx->buf, ctx->CRC); + ctx->buf[0] = (ctx->CRC >> 16) & 0xFF; + ctx->buf[1] = (ctx->CRC >> 8) & 0xFF; + ctx->buf[2] = (ctx->CRC ) & 0xFF; } gcry_md_spec_t _gcry_digest_spec_crc32 = diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c index b12e79b19..2788e349f 100644 --- a/grub-core/lib/libgcrypt/cipher/primegen.c +++ b/grub-core/lib/libgcrypt/cipher/primegen.c @@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, } /* Allocate an array to track pool usage. */ - pool_in_use = gcry_calloc (n, sizeof *pool_in_use); + pool_in_use = gcry_malloc (n * sizeof *pool_in_use); if (!pool_in_use) { err = gpg_err_code_from_errno (errno); @@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, if (nbits < 16) log_fatal ("can't generate a prime with less than %d bits\n", 16); - mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); + mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); /* Make nbits fit into gcry_mpi_t implementation. */ val_2 = mpi_alloc_set_ui( 2 ); val_3 = mpi_alloc_set_ui( 3); diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c index ca087ad75..910982141 100644 --- a/grub-core/lib/libgcrypt/cipher/pubkey.c +++ b/grub-core/lib/libgcrypt/cipher/pubkey.c @@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) * array to a format string, so we have to do it this way :-(. */ /* FIXME: There is now such a format specifier, so we can change the code to be more clear. */ - arg_list = calloc (nelem, sizeof *arg_list); + arg_list = malloc (nelem * sizeof *arg_list); if (!arg_list) { rc = gpg_err_code_from_syserror (); @@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) } strcpy (p, "))"); - arg_list = calloc (nelem, sizeof *arg_list); + arg_list = malloc (nelem * sizeof *arg_list); if (!arg_list) { rc = gpg_err_code_from_syserror (); diff --git a/grub-core/lib/libgcrypt_wrap/mem.c b/grub-core/lib/libgcrypt_wrap/mem.c index 74c6eafe5..beeb661a3 100644 --- a/grub-core/lib/libgcrypt_wrap/mem.c +++ b/grub-core/lib/libgcrypt_wrap/mem.c @@ -4,7 +4,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -37,10 +36,7 @@ void * gcry_xcalloc (size_t n, size_t m) { void *ret; - size_t sz; - if (grub_mul (n, m, &sz)) - grub_fatal ("gcry_xcalloc would overflow"); - ret = grub_zalloc (sz); + ret = grub_zalloc (n * m); if (!ret) grub_fatal ("gcry_xcalloc failed"); return ret; @@ -60,10 +56,7 @@ void * gcry_xcalloc_secure (size_t n, size_t m) { void *ret; - size_t sz; - if (grub_mul (n, m, &sz)) - grub_fatal ("gcry_xcalloc would overflow"); - ret = grub_zalloc (sz); + ret = grub_zalloc (n * m); if (!ret) grub_fatal ("gcry_xcalloc failed"); return ret; diff --git a/grub-core/lib/minilzo/lzoconf.h b/grub-core/lib/minilzo/lzoconf.h index 61be29c5d..1d0fe14fc 100644 --- a/grub-core/lib/minilzo/lzoconf.h +++ b/grub-core/lib/minilzo/lzoconf.h @@ -2,7 +2,22 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -29,9 +44,9 @@ #ifndef __LZOCONF_H_INCLUDED #define __LZOCONF_H_INCLUDED 1 -#define LZO_VERSION 0x2080 -#define LZO_VERSION_STRING "2.08" -#define LZO_VERSION_DATE "Jun 29 2014" +#define LZO_VERSION 0x2050 +#define LZO_VERSION_STRING "2.05" +#define LZO_VERSION_DATE "Apr 23 2011" /* internal Autoconf configuration file - only used when building LZO */ #if defined(LZO_HAVE_CONFIG_H) @@ -48,7 +63,7 @@ #if !defined(CHAR_BIT) || (CHAR_BIT != 8) # error "invalid CHAR_BIT" #endif -#if !defined(UCHAR_MAX) || !defined(USHRT_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) +#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) # error "check your compiler installation" #endif #if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) @@ -70,6 +85,14 @@ extern "C" { // some core defines ************************************************************************/ +#if !defined(LZO_UINT32_C) +# if (UINT_MAX < LZO_0xffffffffL) +# define LZO_UINT32_C(c) c ## UL +# else +# define LZO_UINT32_C(c) ((c) + 0U) +# endif +#endif + /* memory checkers */ #if !defined(__LZO_CHECKER) # if defined(__BOUNDS_CHECKING_ON) @@ -88,31 +111,28 @@ extern "C" { // integral and pointer types ************************************************************************/ -/* lzo_uint must match size_t */ +/* lzo_uint should match size_t */ #if !defined(LZO_UINT_MAX) -# if (LZO_ABI_LLP64) -# if (LZO_OS_WIN64) +# if defined(LZO_ABI_LLP64) /* WIN64 */ +# if defined(LZO_OS_WIN64) typedef unsigned __int64 lzo_uint; typedef __int64 lzo_int; # else - typedef lzo_ullong_t lzo_uint; - typedef lzo_llong_t lzo_int; + typedef unsigned long long lzo_uint; + typedef long long lzo_int; # endif -# define LZO_SIZEOF_LZO_UINT 8 # define LZO_UINT_MAX 0xffffffffffffffffull # define LZO_INT_MAX 9223372036854775807LL # define LZO_INT_MIN (-1LL - LZO_INT_MAX) -# elif (LZO_ABI_IP32L64) /* MIPS R5900 */ +# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ typedef unsigned int lzo_uint; typedef int lzo_int; -# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_INT # define LZO_UINT_MAX UINT_MAX # define LZO_INT_MAX INT_MAX # define LZO_INT_MIN INT_MIN # elif (ULONG_MAX >= LZO_0xffffffffL) typedef unsigned long lzo_uint; typedef long lzo_int; -# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_LONG # define LZO_UINT_MAX ULONG_MAX # define LZO_INT_MAX LONG_MAX # define LZO_INT_MIN LONG_MIN @@ -121,22 +141,63 @@ extern "C" { # endif #endif -/* The larger type of lzo_uint and lzo_uint32_t. */ -#if (LZO_SIZEOF_LZO_UINT >= 4) -# define lzo_xint lzo_uint -#else -# define lzo_xint lzo_uint32_t +/* Integral types with 32 bits or more. */ +#if !defined(LZO_UINT32_MAX) +# if (UINT_MAX >= LZO_0xffffffffL) + typedef unsigned int lzo_uint32; + typedef int lzo_int32; +# define LZO_UINT32_MAX UINT_MAX +# define LZO_INT32_MAX INT_MAX +# define LZO_INT32_MIN INT_MIN +# elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint32; + typedef long lzo_int32; +# define LZO_UINT32_MAX ULONG_MAX +# define LZO_INT32_MAX LONG_MAX +# define LZO_INT32_MIN LONG_MIN +# else +# error "lzo_uint32" +# endif #endif -typedef int lzo_bool; +/* Integral types with exactly 64 bits. */ +#if !defined(LZO_UINT64_MAX) +# if (LZO_UINT_MAX >= LZO_0xffffffffL) +# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3) +# define lzo_uint64 lzo_uint +# define lzo_int64 lzo_int +# define LZO_UINT64_MAX LZO_UINT_MAX +# define LZO_INT64_MAX LZO_INT_MAX +# define LZO_INT64_MIN LZO_INT_MIN +# endif +# elif (ULONG_MAX >= LZO_0xffffffffL) +# if ((((ULONG_MAX) >> 31) >> 31) == 3) + typedef unsigned long lzo_uint64; + typedef long lzo_int64; +# define LZO_UINT64_MAX ULONG_MAX +# define LZO_INT64_MAX LONG_MAX +# define LZO_INT64_MIN LONG_MIN +# endif +# endif +#endif -/* sanity checks */ -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == LZO_SIZEOF_LZO_UINT) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t)) +/* The larger type of lzo_uint and lzo_uint32. */ +#if (LZO_UINT_MAX >= LZO_UINT32_MAX) +# define lzo_xint lzo_uint +#else +# define lzo_xint lzo_uint32 +#endif -#ifndef __LZO_MMODEL -#define __LZO_MMODEL /*empty*/ +/* Memory model that allows to access memory at offsets of lzo_uint. */ +#if !defined(__LZO_MMODEL) +# if (LZO_UINT_MAX <= UINT_MAX) +# define __LZO_MMODEL /*empty*/ +# elif defined(LZO_HAVE_MM_HUGE_PTR) +# define __LZO_MMODEL_HUGE 1 +# define __LZO_MMODEL __huge +# else +# define __LZO_MMODEL /*empty*/ +# endif #endif /* no typedef here because of const-pointer issues */ @@ -145,52 +206,21 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t)) #define lzo_voidp void __LZO_MMODEL * #define lzo_shortp short __LZO_MMODEL * #define lzo_ushortp unsigned short __LZO_MMODEL * -#define lzo_intp lzo_int __LZO_MMODEL * +#define lzo_uint32p lzo_uint32 __LZO_MMODEL * +#define lzo_int32p lzo_int32 __LZO_MMODEL * +#if defined(LZO_UINT64_MAX) +#define lzo_uint64p lzo_uint64 __LZO_MMODEL * +#define lzo_int64p lzo_int64 __LZO_MMODEL * +#endif #define lzo_uintp lzo_uint __LZO_MMODEL * +#define lzo_intp lzo_int __LZO_MMODEL * #define lzo_xintp lzo_xint __LZO_MMODEL * #define lzo_voidpp lzo_voidp __LZO_MMODEL * #define lzo_bytepp lzo_bytep __LZO_MMODEL * +/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ +#define lzo_byte unsigned char __LZO_MMODEL -#define lzo_int8_tp lzo_int8_t __LZO_MMODEL * -#define lzo_uint8_tp lzo_uint8_t __LZO_MMODEL * -#define lzo_int16_tp lzo_int16_t __LZO_MMODEL * -#define lzo_uint16_tp lzo_uint16_t __LZO_MMODEL * -#define lzo_int32_tp lzo_int32_t __LZO_MMODEL * -#define lzo_uint32_tp lzo_uint32_t __LZO_MMODEL * -#if defined(lzo_int64_t) -#define lzo_int64_tp lzo_int64_t __LZO_MMODEL * -#define lzo_uint64_tp lzo_uint64_t __LZO_MMODEL * -#endif - -/* Older LZO versions used to support ancient systems and memory models - * like 16-bit MSDOS with __huge pointers and Cray PVP, but these - * obsolete configurations are not supported any longer. - */ -#if defined(__LZO_MMODEL_HUGE) -#error "__LZO_MMODEL_HUGE is unsupported" -#endif -#if (LZO_MM_PVP) -#error "LZO_MM_PVP is unsupported" -#endif -#if (LZO_SIZEOF_INT < 4) -#error "LZO_SIZEOF_INT < 4 is unsupported" -#endif -#if (__LZO_UINTPTR_T_IS_POINTER) -#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) >= 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) >= 4) -/* Strange configurations where sizeof(lzo_uint) != sizeof(size_t) should - * work but have not received much testing lately, so be strict here. - */ -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(size_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(ptrdiff_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(lzo_uintptr_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_uintptr_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_uintptr_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long *) == sizeof(lzo_uintptr_t)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_voidp)) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_bytep)) +typedef int lzo_bool; /*********************************************************************** @@ -285,7 +315,7 @@ struct lzo_callback_t /* a progress indicator callback function (set to 0 to disable) */ lzo_progress_func_t nprogress; - /* INFO: the first parameter "self" of the nalloc/nfree/nprogress + /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress * callbacks points back to this struct, so you are free to store * some extra info in the following variables. */ lzo_voidp user1; @@ -313,9 +343,6 @@ struct lzo_callback_t #define LZO_E_INPUT_NOT_CONSUMED (-8) #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ #define LZO_E_INVALID_ARGUMENT (-10) -#define LZO_E_INVALID_ALIGNMENT (-11) /* pointer argument is not properly aligned */ -#define LZO_E_OUTPUT_NOT_CONSUMED (-12) -#define LZO_E_INTERNAL_ERROR (-99) #ifndef lzo_sizeof_dict_t @@ -329,7 +356,7 @@ struct lzo_callback_t * compiler's view of various types are consistent. */ #define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ - (int)sizeof(long),(int)sizeof(lzo_uint32_t),(int)sizeof(lzo_uint),\ + (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ (int)sizeof(lzo_callback_t)) LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); @@ -352,22 +379,18 @@ LZO_EXTERN(lzo_voidp) lzo_memset(lzo_voidp buf, int c, lzo_uint len); /* checksum functions */ -LZO_EXTERN(lzo_uint32_t) - lzo_adler32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); -LZO_EXTERN(lzo_uint32_t) - lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); -LZO_EXTERN(const lzo_uint32_tp) +LZO_EXTERN(lzo_uint32) + lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(lzo_uint32) + lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(const lzo_uint32p) lzo_get_crc32_table(void); /* misc. */ LZO_EXTERN(int) _lzo_config_check(void); -typedef union { - lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04; - void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09; -#if defined(lzo_int64_t) - lzo_uint64_t a10; -#endif -} lzo_align_t; +typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u; +typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u; +typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t; /* align a char pointer on a boundary that is a multiple of 'size' */ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); @@ -376,30 +399,9 @@ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); /*********************************************************************** -// deprecated macros - only for backward compatibility +// deprecated macros - only for backward compatibility with LZO v1.xx ************************************************************************/ -/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ -#define lzo_byte unsigned char -/* deprecated type names */ -#define lzo_int32 lzo_int32_t -#define lzo_uint32 lzo_uint32_t -#define lzo_int32p lzo_int32_t __LZO_MMODEL * -#define lzo_uint32p lzo_uint32_t __LZO_MMODEL * -#define LZO_INT32_MAX LZO_INT32_C(2147483647) -#define LZO_UINT32_MAX LZO_UINT32_C(4294967295) -#if defined(lzo_int64_t) -#define lzo_int64 lzo_int64_t -#define lzo_uint64 lzo_uint64_t -#define lzo_int64p lzo_int64_t __LZO_MMODEL * -#define lzo_uint64p lzo_uint64_t __LZO_MMODEL * -#define LZO_INT64_MAX LZO_INT64_C(9223372036854775807) -#define LZO_UINT64_MAX LZO_UINT64_C(18446744073709551615) -#endif -/* deprecated types */ -typedef union { lzo_bytep a; lzo_uint b; } __lzo_pu_u; -typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u; - #if defined(LZO_CFG_COMPAT) #define __LZOCONF_H 1 @@ -441,4 +443,4 @@ typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u; #endif /* already included */ -/* vim:set ts=4 sw=4 et: */ +/* vim:set ts=4 et: */ diff --git a/grub-core/lib/minilzo/lzodefs.h b/grub-core/lib/minilzo/lzodefs.h index f4ae9487e..0e40e332a 100644 --- a/grub-core/lib/minilzo/lzodefs.h +++ b/grub-core/lib/minilzo/lzodefs.h @@ -2,7 +2,22 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -32,6 +47,12 @@ #if defined(__CYGWIN32__) && !defined(__CYGWIN__) # define __CYGWIN__ __CYGWIN32__ #endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) # define _ALL_SOURCE 1 #endif @@ -40,30 +61,19 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif -#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) -#if defined(__ARMCC_VERSION) -# pragma diag_suppress 193 -#elif defined(__clang__) && defined(__clang_minor__) -# pragma clang diagnostic ignored "-Wundef" -#elif defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) && defined(__linux__) # pragma warning(disable: 193) -#elif defined(__KEIL__) && defined(__C166__) +#endif +#if defined(__KEIL__) && defined(__C166__) # pragma warning disable = 322 -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) -# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) -# pragma GCC diagnostic ignored "-Wundef" -# endif -#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -# if ((_MSC_VER-0) >= 1300) +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) # pragma warning(disable: 4668) # endif #endif -#endif -#if 0 && defined(__POCC__) && defined(_WIN32) -# if (__POCC__ >= 400) -# pragma warn(disable: 2216) -# endif -#endif #if 0 && defined(__WATCOMC__) # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) # pragma warning 203 9 @@ -72,29 +82,13 @@ #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) # pragma option -h #endif -#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE 1 -#endif -#ifndef _CRT_NONSTDC_NO_WARNINGS -#define _CRT_NONSTDC_NO_WARNINGS 1 -#endif -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS 1 -#endif -#endif #if 0 -#define LZO_0xffffUL 0xfffful -#define LZO_0xffffffffUL 0xfffffffful +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful #else -#define LZO_0xffffUL 65535ul -#define LZO_0xffffffffUL 4294967295ul +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul #endif -#define LZO_0xffffL LZO_0xffffUL -#define LZO_0xffffffffL LZO_0xffffffffUL #if (LZO_0xffffL == LZO_0xffffffffL) # error "your preprocessor is broken 1" #endif @@ -109,13 +103,6 @@ # error "your preprocessor is broken 4" #endif #endif -#if defined(__COUNTER__) -# ifndef LZO_CFG_USE_COUNTER -# define LZO_CFG_USE_COUNTER 1 -# endif -#else -# undef LZO_CFG_USE_COUNTER -#endif #if (UINT_MAX == LZO_0xffffL) #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) # if !defined(MSDOS) @@ -246,31 +233,14 @@ #endif #define LZO_PP_STRINGIZE(x) #x #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) -#define LZO_PP_CONCAT0() /*empty*/ -#define LZO_PP_CONCAT1(a) a #define LZO_PP_CONCAT2(a,b) a ## b #define LZO_PP_CONCAT3(a,b,c) a ## b ## c #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g -#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() -#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) -#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) -#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) -#define LZO_PP_EMPTY /*empty*/ -#define LZO_PP_EMPTY0() /*empty*/ -#define LZO_PP_EMPTY1(a) /*empty*/ -#define LZO_PP_EMPTY2(a,b) /*empty*/ -#define LZO_PP_EMPTY3(a,b,c) /*empty*/ -#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ -#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ -#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ -#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ #if 1 #define LZO_CPP_STRINGIZE(x) #x #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) @@ -278,16 +248,12 @@ #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) -#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) -#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -297,13 +263,9 @@ # endif #endif #if defined(__cplusplus) -# define LZO_EXTERN_C extern "C" -# define LZO_EXTERN_C_BEGIN extern "C" { -# define LZO_EXTERN_C_END } +# define LZO_EXTERN_C extern "C" #else -# define LZO_EXTERN_C extern -# define LZO_EXTERN_C_BEGIN /*empty*/ -# define LZO_EXTERN_C_END /*empty*/ +# define LZO_EXTERN_C extern #endif #if !defined(__LZO_OS_OVERRIDE) #if (LZO_OS_FREESTANDING) @@ -404,12 +366,12 @@ #elif defined(__VMS) # define LZO_OS_VMS 1 # define LZO_INFO_OS "vms" -#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PS2 1 # define LZO_INFO_OS "console" # define LZO_INFO_OS_CONSOLE "ps2" -#elif defined(__mips__) && defined(__psp__) +#elif (defined(__mips__) && defined(__psp__)) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PSP 1 # define LZO_INFO_OS "console" @@ -437,18 +399,9 @@ # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) # define LZO_OS_POSIX_LINUX 1 # define LZO_INFO_OS_POSIX "linux" -# elif defined(__APPLE__) && defined(__MACH__) -# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) -# define LZO_OS_POSIX_DARWIN 1040 -# define LZO_INFO_OS_POSIX "darwin_iphone" -# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) -# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -# define LZO_INFO_OS_POSIX "darwin" -# else -# define LZO_OS_POSIX_DARWIN 1 -# define LZO_INFO_OS_POSIX "darwin" -# endif -# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" # elif defined(__minix__) || defined(__minix) # define LZO_OS_POSIX_MINIX 1 # define LZO_INFO_OS_POSIX "minix" @@ -483,18 +436,18 @@ #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (UINT_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) @@ -510,65 +463,59 @@ # define LZO_INFO_CC "sdcc" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) -# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) # define LZO_INFO_CC "Pathscale C" # define LZO_INFO_CCVER __PATHSCALE__ -# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# endif -#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) -# define LZO_CC_INTELC __INTEL_COMPILER +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 # define LZO_INFO_CC "Intel C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_INTELC_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 # endif #elif defined(__POCC__) && defined(_WIN32) # define LZO_CC_PELLESC 1 # define LZO_INFO_CC "Pelles C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) -#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) # else -# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) # endif -# define LZO_CC_ARMCC __ARMCC_VERSION -# define LZO_INFO_CC "ARM C Compiler" -# define LZO_INFO_CCVER __VERSION__ -#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) -# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) +# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) # else -# define LZO_CC_CLANG 0x010000L -# endif -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_CLANG_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_CLANG_CLANG 0x010000L # endif +# define LZO_CC_CLANG LZO_CC_CLANG_GNUC # define LZO_INFO_CC "clang" # define LZO_INFO_CCVER __VERSION__ #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) # else -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) # endif # define LZO_CC_LLVM LZO_CC_LLVM_GNUC # define LZO_INFO_CC "llvm-gcc" # define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ #elif defined(__ACK__) && defined(_ACK) # define LZO_CC_ACK 1 # define LZO_INFO_CC "Amsterdam Compiler Kit C" # define LZO_INFO_CCVER "unknown" -#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) -# define LZO_CC_ARMCC __ARMCC_VERSION -# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION -# define LZO_INFO_CC "ARM C Compiler" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) #elif defined(__AZTEC_C__) # define LZO_CC_AZTECC 1 # define LZO_INFO_CC "Aztec C" @@ -593,23 +540,10 @@ # define LZO_CC_DECC 1 # define LZO_INFO_CC "DEC C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) -#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) -# define LZO_CC_GHS 1 -# define LZO_INFO_CC "Green Hills C" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_GHS_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# endif #elif defined(__HIGHC__) # define LZO_CC_HIGHC 1 # define LZO_INFO_CC "MetaWare High C" # define LZO_INFO_CCVER "unknown" -#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) -# define LZO_CC_HPACC __HP_aCC -# define LZO_INFO_CC "HP aCC" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) #elif defined(__IAR_SYSTEMS_ICC__) # define LZO_CC_IARC 1 # define LZO_INFO_CC "IAR C" @@ -618,14 +552,10 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__IBMC__) && ((__IBMC__-0) > 0) -# define LZO_CC_IBMC __IBMC__ +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 # define LZO_INFO_CC "IBM C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) -#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) -# define LZO_CC_IBMC __IBMCPP__ -# define LZO_INFO_CC "IBM C" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) #elif defined(__KEIL__) && defined(__C166__) # define LZO_CC_KEILC 1 # define LZO_INFO_CC "Keil C" @@ -642,8 +572,16 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) -# define LZO_CC_MWERKS __MWERKS__ +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 # define LZO_INFO_CC "Metrowerks C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) @@ -654,15 +592,6 @@ # define LZO_CC_PACIFICC 1 # define LZO_INFO_CC "Pacific C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) -#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) -# else -# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" -# endif -# define LZO_INFO_CC "Portland Group PGI C" #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) # define LZO_CC_PGI 1 # define LZO_INFO_CC "Portland Group PGI C" @@ -677,7 +606,7 @@ # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) #elif defined(__SUNPRO_C) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_C-0) > 0) +# if ((__SUNPRO_C)+0 > 0) # define LZO_CC_SUNPROC __SUNPRO_C # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) # else @@ -686,7 +615,7 @@ # endif #elif defined(__SUNPRO_CC) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_CC-0) > 0) +# if ((__SUNPRO_CC)+0 > 0) # define LZO_CC_SUNPROC __SUNPRO_CC # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) # else @@ -712,46 +641,16 @@ #elif defined(__ZTC__) # define LZO_CC_ZORTECHC 1 # define LZO_INFO_CC "Zortech C" -# if ((__ZTC__-0) == 0x310) +# if (__ZTC__ == 0x310) # define LZO_INFO_CCVER "0x310" # else # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) # endif -#elif defined(__GNUC__) && defined(__VERSION__) -# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# elif defined(__GNUC_MINOR__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) -# else -# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -# endif -# define LZO_INFO_CC "gcc" -# define LZO_INFO_CCVER __VERSION__ -#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_MSC _MSC_VER -# define LZO_INFO_CC "Microsoft C" -# if defined(_MSC_FULL_VER) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -# else -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -# endif #else # define LZO_CC_UNKNOWN 1 # define LZO_INFO_CC "unknown" # define LZO_INFO_CCVER "unknown" #endif -#if (LZO_CC_GNUC) && defined(__OPEN64__) -# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) -# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) -# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC -# endif -#endif -#if (LZO_CC_GNUC) && defined(__PCC__) -# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) -# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) -# define LZO_CC_PCC_GNUC LZO_CC_GNUC -# endif -#endif #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" #endif @@ -769,10 +668,8 @@ # define LZO_INFO_ARCH "generic" #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) -# define LZO_ARCH_ARM64 1 -# define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) # define LZO_ARCH_ALPHA 1 # define LZO_INFO_ARCH "alpha" @@ -788,10 +685,10 @@ # define LZO_INFO_ARCH "arm_thumb" #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) # define LZO_ARCH_ARM 1 -# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) # define LZO_ARCH_ARM_THUMB 1 # define LZO_INFO_ARCH "arm_thumb" -# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) # define LZO_INFO_ARCH "arm" # else # define LZO_INFO_ARCH "arm" @@ -909,147 +806,53 @@ # error "FIXME - missing define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) -# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" +# error "FIXME - missing WIN32 define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) -# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" +# error "FIXME - missing WIN64 define for CPU architecture" #endif #if (LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #endif -#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) -# define LZO_ARCH_X64 1 -#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_AMD64 1 +#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +# error "this should not happen" #endif -#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) -# define LZO_ARCH_AARCH64 1 -#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_ARM64 1 -#endif -#if (LZO_ARCH_I386 && !LZO_ARCH_X86) -# define LZO_ARCH_X86 1 -#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_I386 1 -#endif -#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) -# error "unexpected configuration - check your compiler defines" +#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +# error "this should not happen" #endif #if (LZO_ARCH_I086) # if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if (LZO_ARCH_I386) # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif -#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) -# if !defined(LZO_TARGET_FEATURE_SSE2) -# if defined(__SSE2__) -# define LZO_TARGET_FEATURE_SSE2 1 -# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) -# define LZO_TARGET_FEATURE_SSE2 1 -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_SSSE3) -# if (LZO_TARGET_FEATURE_SSE2) -# if defined(__SSSE3__) -# define LZO_TARGET_FEATURE_SSSE3 1 -# elif defined(_MSC_VER) && defined(__AVX__) -# define LZO_TARGET_FEATURE_SSSE3 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_SSE4_2) -# if (LZO_TARGET_FEATURE_SSSE3) -# if defined(__SSE4_2__) -# define LZO_TARGET_FEATURE_SSE4_2 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_AVX) -# if (LZO_TARGET_FEATURE_SSSE3) -# if defined(__AVX__) -# define LZO_TARGET_FEATURE_AVX 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_AVX2) -# if (LZO_TARGET_FEATURE_AVX) -# if defined(__AVX2__) -# define LZO_TARGET_FEATURE_AVX2 1 -# endif -# endif -# endif -#endif -#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM) -# if !defined(LZO_TARGET_FEATURE_NEON) -# if defined(__ARM_NEON__) -# define LZO_TARGET_FEATURE_NEON 1 -# endif -# endif -#elif (LZO_ARCH_ARM64) -# if !defined(LZO_TARGET_FEATURE_NEON) -# if 1 -# define LZO_TARGET_FEATURE_NEON 1 -# endif -# endif -#endif -#if 0 -#elif !defined(__LZO_MM_OVERRIDE) +#if !defined(__LZO_MM_OVERRIDE) #if (LZO_ARCH_I086) #if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" #endif #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) # define LZO_MM_TINY 1 @@ -1076,7 +879,7 @@ #elif (LZO_CC_ZORTECHC && defined(__VCM__)) # define LZO_MM_LARGE 1 #else -# error "unknown LZO_ARCH_I086 memory model" +# error "unknown memory model" #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) #define LZO_HAVE_MM_HUGE_PTR 1 @@ -1099,10 +902,10 @@ #endif #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) # if (LZO_OS_DOS16) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # elif (LZO_CC_ZORTECHC) # else -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #ifdef __cplusplus @@ -1134,7 +937,7 @@ extern "C" { #endif #elif (LZO_ARCH_C166) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_C166 __MODEL__" +# error "FIXME - C166 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 1) @@ -1148,11 +951,11 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_C166 __MODEL__" +# error "FIXME - C166 __MODEL__" #endif #elif (LZO_ARCH_MCS251) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_MCS251 __MODEL__" +# error "FIXME - MCS251 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -1164,11 +967,11 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_MCS251 __MODEL__" +# error "FIXME - MCS251 __MODEL__" #endif #elif (LZO_ARCH_MCS51) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_MCS51 __MODEL__" +# error "FIXME - MCS51 __MODEL__" #elif ((__MODEL__) == 1) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -1180,7 +983,7 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_MCS51 __MODEL__" +# error "FIXME - MCS51 __MODEL__" #endif #elif (LZO_ARCH_CRAY_PVP) # define LZO_MM_PVP 1 @@ -1207,156 +1010,567 @@ extern "C" { # error "unknown memory model" #endif #endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif #if !defined(__lzo_gnuc_extension__) #if (LZO_CC_GNUC >= 0x020800ul) # define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_IBMC >= 600) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_gnuc_extension__ __extension__ #else -#endif -#endif -#if !defined(__lzo_gnuc_extension__) # define __lzo_gnuc_extension__ /*empty*/ #endif -#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_inline __inline__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) # else -# define LZO_CFG_USE_NEW_STYLE_CASTS 1 +# define __lzo_noinline __declspec(noinline) # endif +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_noinline __attribute__((__noinline__)) #endif -#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 #endif -#if !defined(__cplusplus) -# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) -# undef LZO_CFG_USE_NEW_STYLE_CASTS -# endif -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline /*empty*/ #endif -#if !defined(LZO_REINTERPRET_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) -# endif +#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +# error "this should not happen" #endif -#if !defined(LZO_REINTERPRET_CAST) -# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) #endif -#if !defined(LZO_STATIC_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_STATIC_CAST(t,e) (static_cast (e)) -# endif #endif -#if !defined(LZO_STATIC_CAST) -# define LZO_STATIC_CAST(t,e) ((t) (e)) +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn /*empty*/ #endif -#if !defined(LZO_STATIC_CAST2) -# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) #endif -#if !defined(LZO_UNCONST_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNCONST_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) -# endif #endif -#if !defined(LZO_UNCONST_CAST) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow /*empty*/ #endif -#if !defined(LZO_UNCONST_VOLATILE_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -# endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict #endif -#if !defined(LZO_UNCONST_VOLATILE_CAST) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_UNVOLATILE_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) -# endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict /*empty*/ #endif -#if !defined(LZO_UNVOLATILE_CAST) -# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #endif -#if !defined(LZO_UNVOLATILE_CONST_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -# endif #endif -#if !defined(LZO_UNVOLATILE_CONST_CAST) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) #endif -#if !defined(LZO_PCAST) -# if (LZO_HAVE_MM_HUGE_PTR) -# define LZO_PCAST(t,e) ((t) (e)) -# endif -#endif -#if !defined(LZO_PCAST) -# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) -#endif -#if !defined(LZO_CCAST) -# if (LZO_HAVE_MM_HUGE_PTR) -# define LZO_CCAST(t,e) ((t) (e)) -# endif -#endif -#if !defined(LZO_CCAST) -# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) -#endif -#if !defined(LZO_ICONV) -# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(LZO_ICAST) -# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(LZO_ITRUNC) -# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(__lzo_cte) -# if (LZO_CC_MSC || LZO_CC_WATCOMC) -# define __lzo_cte(e) ((void)0,(e)) -# elif 1 -# define __lzo_cte(e) ((void)0,(e)) -# endif -#endif -#if !defined(__lzo_cte) -# define __lzo_cte(e) (e) -#endif -#if !defined(LZO_BLOCK_BEGIN) -# define LZO_BLOCK_BEGIN do { -# define LZO_BLOCK_END } while __lzo_cte(0) +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) #endif #if !defined(LZO_UNUSED) # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) # define LZO_UNUSED(var) ((void) &var) # elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) # define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) -# define LZO_UNUSED(var) ((void) &var) # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define LZO_UNUSED(var) ((void) var) # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_UNUSED(var) if (&var) ; else # elif (LZO_CC_KEILC) -# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} # elif (LZO_CC_PACIFICC) # define LZO_UNUSED(var) ((void) sizeof(var)) # elif (LZO_CC_WATCOMC) && defined(__cplusplus) @@ -1377,18 +1591,18 @@ extern "C" { # elif (LZO_CC_MSC) # define LZO_UNUSED_FUNC(func) ((void) &func) # elif (LZO_CC_KEILC || LZO_CC_PELLESC) -# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} # else # define LZO_UNUSED_FUNC(func) ((void) func) # endif #endif #if !defined(LZO_UNUSED_LABEL) -# if (LZO_CC_CLANG >= 0x020800ul) -# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) -# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l # else -# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l # endif #endif #if !defined(LZO_DEFINE_UNINITIALIZED_VAR) @@ -1400,488 +1614,39 @@ extern "C" { # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init # endif #endif -#if !defined(__lzo_inline) -#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) -#elif defined(__cplusplus) -# define __lzo_inline inline -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -# define __lzo_inline inline -#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) -# define __lzo_inline __inline -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_inline __inline__ -#elif (LZO_CC_DMC) -# define __lzo_inline __inline -#elif (LZO_CC_GHS) -# define __lzo_inline __inline__ -#elif (LZO_CC_IBMC >= 600) -# define __lzo_inline __inline__ -#elif (LZO_CC_INTELC) -# define __lzo_inline __inline -#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) -# define __lzo_inline __inline -#elif (LZO_CC_MSC && (_MSC_VER >= 900)) -# define __lzo_inline __inline -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_inline __inline__ -#endif -#endif -#if defined(__lzo_inline) -# ifndef __lzo_HAVE_inline -# define __lzo_HAVE_inline 1 -# endif -#else -# define __lzo_inline /*empty*/ -#endif -#if !defined(__lzo_forceinline) -#if (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -# define __lzo_forceinline __forceinline -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_forceinline __forceinline -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#endif -#endif -#if defined(__lzo_forceinline) -# ifndef __lzo_HAVE_forceinline -# define __lzo_HAVE_forceinline 1 -# endif -#else -# define __lzo_forceinline __lzo_inline -#endif -#if !defined(__lzo_noinline) -#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) -# define __lzo_noinline __attribute__((__noinline__,__used__)) -#elif (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -# define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) -# if defined(__cplusplus) +#if !defined(LZO_UNCONST_CAST) +# if 0 && defined(__cplusplus) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) # else -# define __lzo_noinline __declspec(noinline) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) # endif -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_noinline __attribute__((__noinline__)) -#endif -#endif -#if defined(__lzo_noinline) -# ifndef __lzo_HAVE_noinline -# define __lzo_HAVE_noinline 1 -# endif -#else -# define __lzo_noinline /*empty*/ -#endif -#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) -# error "unexpected configuration - check your compiler defines" -#endif -#if !defined(__lzo_static_inline) -#if (LZO_CC_IBMC) -# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline -#endif -#endif -#if !defined(__lzo_static_inline) -# define __lzo_static_inline static __lzo_inline -#endif -#if !defined(__lzo_static_forceinline) -#if (LZO_CC_IBMC) -# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline -#endif -#endif -#if !defined(__lzo_static_forceinline) -# define __lzo_static_forceinline static __lzo_forceinline -#endif -#if !defined(__lzo_static_noinline) -#if (LZO_CC_IBMC) -# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline -#endif -#endif -#if !defined(__lzo_static_noinline) -# define __lzo_static_noinline static __lzo_noinline -#endif -#if !defined(__lzo_c99_extern_inline) -#if defined(__GNUC_GNU_INLINE__) -# define __lzo_c99_extern_inline __lzo_inline -#elif defined(__GNUC_STDC_INLINE__) -# define __lzo_c99_extern_inline extern __lzo_inline -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -# define __lzo_c99_extern_inline extern __lzo_inline -#endif -#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) -# define __lzo_c99_extern_inline __lzo_inline -#endif -#endif -#if defined(__lzo_c99_extern_inline) -# ifndef __lzo_HAVE_c99_extern_inline -# define __lzo_HAVE_c99_extern_inline 1 -# endif -#else -# define __lzo_c99_extern_inline /*empty*/ -#endif -#if !defined(__lzo_may_alias) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_CLANG >= 0x020900ul) -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 -# define __lzo_may_alias __attribute__((__may_alias__)) -#endif -#endif -#if defined(__lzo_may_alias) -# ifndef __lzo_HAVE_may_alias -# define __lzo_HAVE_may_alias 1 -# endif -#else -# define __lzo_may_alias /*empty*/ -#endif -#if !defined(__lzo_noreturn) -#if (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#endif -#endif -#if defined(__lzo_noreturn) -# ifndef __lzo_HAVE_noreturn -# define __lzo_HAVE_noreturn 1 -# endif -#else -# define __lzo_noreturn /*empty*/ -#endif -#if !defined(__lzo_nothrow) -#if (LZO_CC_GNUC >= 0x030300ul) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) -# define __lzo_nothrow __declspec(nothrow) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) -# define __lzo_nothrow __declspec(nothrow) -#endif -#endif -#if defined(__lzo_nothrow) -# ifndef __lzo_HAVE_nothrow -# define __lzo_HAVE_nothrow 1 -# endif -#else -# define __lzo_nothrow /*empty*/ -#endif -#if !defined(__lzo_restrict) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_IBMC >= 1210) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) -# define __lzo_restrict __restrict -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_restrict __restrict__ -#endif -#endif -#if defined(__lzo_restrict) -# ifndef __lzo_HAVE_restrict -# define __lzo_HAVE_restrict 1 -# endif -#else -# define __lzo_restrict /*empty*/ -#endif -#if !defined(__lzo_alignof) -#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_GHS) && !defined(__cplusplus) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_IBMC >= 600) -# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_alignof(e) __alignof(e) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_alignof(e) __alignof__(e) -#endif -#endif -#if defined(__lzo_alignof) -# ifndef __lzo_HAVE_alignof -# define __lzo_HAVE_alignof 1 -# endif -#endif -#if !defined(__lzo_struct_packed) -#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -# define __lzo_struct_packed(s) struct s { -# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_struct_packed(s) struct s { -# define __lzo_struct_packed_end() } __attribute__((__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_IBMC >= 700) -# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { -# define __lzo_struct_packed_end() } __attribute__((__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { -# define __lzo_struct_packed_end() } __pragma(pack(pop)); -#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -# define __lzo_struct_packed(s) _Packed struct s { -# define __lzo_struct_packed_end() }; -#endif -#endif -#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) -# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) -#endif -#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) -# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() -#endif -#if !defined(__lzo_byte_struct) -#if defined(__lzo_struct_packed) -# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() -# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() -#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); -# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); -#endif -#endif -#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) -# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) -#endif -#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) -#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) -#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_CILLY || LZO_CC_PCC) -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_struct_align16(s) struct __declspec(align(16)) s { -# define __lzo_struct_align16_end() }; -# define __lzo_struct_align32(s) struct __declspec(align(32)) s { -# define __lzo_struct_align32_end() }; -# define __lzo_struct_align64(s) struct __declspec(align(64)) s { -# define __lzo_struct_align64_end() }; -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_struct_align16(s) struct s { -# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); -# define __lzo_struct_align32(s) struct s { -# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); -# define __lzo_struct_align64(s) struct s { -# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); -#endif -#endif -#if !defined(__lzo_union_um) -#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) -#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_union_am(s) union s { -# define __lzo_union_am_end() } __lzo_may_alias; -# define __lzo_union_um(s) union s { -# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_IBMC >= 700) -# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { -# define __lzo_union_am_end() } __lzo_may_alias; -# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { -# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_union_um(s) __pragma(pack(push,1)) union s { -# define __lzo_union_um_end() } __pragma(pack(pop)); -#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -# define __lzo_union_um(s) _Packed union s { -# define __lzo_union_um_end() }; -#endif -#endif -#if !defined(__lzo_union_am) -# define __lzo_union_am(s) union s { -# define __lzo_union_am_end() }; -#endif -#if !defined(__lzo_constructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_constructor __attribute__((__constructor__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_constructor __attribute__((__constructor__)) -#endif -#endif -#if defined(__lzo_constructor) -# ifndef __lzo_HAVE_constructor -# define __lzo_HAVE_constructor 1 -# endif -#endif -#if !defined(__lzo_destructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_destructor __attribute__((__destructor__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_destructor __attribute__((__destructor__)) -#endif -#endif -#if defined(__lzo_destructor) -# ifndef __lzo_HAVE_destructor -# define __lzo_HAVE_destructor 1 -# endif -#endif -#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -# error "unexpected configuration - check your compiler defines" -#endif -#if !defined(__lzo_likely) && !defined(__lzo_unlikely) -#if (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_IBMC >= 1010) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#endif -#endif -#if defined(__lzo_likely) -# ifndef __lzo_HAVE_likely -# define __lzo_HAVE_likely 1 -# endif -#else -# define __lzo_likely(e) (e) -#endif -#if defined(__lzo_unlikely) -# ifndef __lzo_HAVE_unlikely -# define __lzo_HAVE_unlikely 1 -# endif -#else -# define __lzo_unlikely(e) (e) -#endif -#if !defined(__lzo_static_unused_void_func) -# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) -# else -# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) -# endif -#endif -#if !defined(__lzo_loop_forever) -# if (LZO_CC_IBMC) -# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END -# else -# define __lzo_loop_forever() do { ; } while __lzo_cte(1) -# endif -#endif -#if !defined(__lzo_unreachable) -#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) -# define __lzo_unreachable() __builtin_unreachable(); -#elif (LZO_CC_GNUC >= 0x040500ul) -# define __lzo_unreachable() __builtin_unreachable(); -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 -# define __lzo_unreachable() __builtin_unreachable(); -#endif -#endif -#if defined(__lzo_unreachable) -# ifndef __lzo_HAVE_unreachable -# define __lzo_HAVE_unreachable 1 -# endif -#else -# if 0 -# define __lzo_unreachable() ((void)0); -# else -# define __lzo_unreachable() __lzo_loop_forever(); -# endif -#endif -#ifndef __LZO_CTA_NAME -#if (LZO_CFG_USE_COUNTER) -# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) -#else -# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) -#endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END -# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END -# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; # else -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; # endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT) # if (LZO_CC_AZTECC) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; -# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} -# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) -# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} -# elif (LZO_CC_GNUC >= 0x040700ul) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # else -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} # endif #endif -LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) -#if defined(__cplusplus) -extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) @@ -1945,7 +1710,6 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) # define __lzo_cdecl_va __lzo_cdecl #endif #if !(LZO_CFG_NO_WINDOWS_H) -#if !defined(LZO_HAVE_WINDOWS_H) #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) # elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) @@ -1955,615 +1719,61 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) # endif #endif #endif -#endif -#ifndef LZO_SIZEOF_SHORT -#if defined(SIZEOF_SHORT) -# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -#elif defined(__SIZEOF_SHORT__) -# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) -#endif -#endif -#ifndef LZO_SIZEOF_INT -#if defined(SIZEOF_INT) -# define LZO_SIZEOF_INT (SIZEOF_INT) -#elif defined(__SIZEOF_INT__) -# define LZO_SIZEOF_INT (__SIZEOF_INT__) -#endif -#endif -#ifndef LZO_SIZEOF_LONG -#if defined(SIZEOF_LONG) -# define LZO_SIZEOF_LONG (SIZEOF_LONG) -#elif defined(__SIZEOF_LONG__) -# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) -#endif -#endif -#ifndef LZO_SIZEOF_LONG_LONG -#if defined(SIZEOF_LONG_LONG) -# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -#elif defined(__SIZEOF_LONG_LONG__) -# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) -#endif -#endif -#ifndef LZO_SIZEOF___INT16 -#if defined(SIZEOF___INT16) -# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -#endif -#endif -#ifndef LZO_SIZEOF___INT32 -#if defined(SIZEOF___INT32) -# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -#endif -#endif -#ifndef LZO_SIZEOF___INT64 -#if defined(SIZEOF___INT64) -# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -#endif -#endif -#ifndef LZO_SIZEOF_VOID_P -#if defined(SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -#elif defined(__SIZEOF_POINTER__) -# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) -#endif -#endif -#ifndef LZO_SIZEOF_SIZE_T -#if defined(SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -#elif defined(__SIZEOF_SIZE_T__) -# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) -#endif -#endif -#ifndef LZO_SIZEOF_PTRDIFF_T -#if defined(SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -#elif defined(__SIZEOF_PTRDIFF_T__) -# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) -#endif -#endif -#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -#if !defined(LZO_SIZEOF_SHORT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_SHORT 8 -# elif (USHRT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,7) == 1) -# define LZO_SIZEOF_SHORT 1 -# elif (__LZO_LSR(USHRT_MAX,15) == 1) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,31) == 1) -# define LZO_SIZEOF_SHORT 4 -# elif (__LZO_LSR(USHRT_MAX,63) == 1) -# define LZO_SIZEOF_SHORT 8 -# elif (__LZO_LSR(USHRT_MAX,127) == 1) -# define LZO_SIZEOF_SHORT 16 -# else -# error "LZO_SIZEOF_SHORT" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) -#if !defined(LZO_SIZEOF_INT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_INT 8 -# elif (UINT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_INT 2 -# elif (UINT_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,7) == 1) -# define LZO_SIZEOF_INT 1 -# elif (__LZO_LSR(UINT_MAX,15) == 1) -# define LZO_SIZEOF_INT 2 -# elif (__LZO_LSR(UINT_MAX,31) == 1) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,63) == 1) -# define LZO_SIZEOF_INT 8 -# elif (__LZO_LSR(UINT_MAX,127) == 1) -# define LZO_SIZEOF_INT 16 -# else -# error "LZO_SIZEOF_INT" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) -#if !defined(LZO_SIZEOF_LONG) -# if (ULONG_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,7) == 1) -# define LZO_SIZEOF_LONG 1 -# elif (__LZO_LSR(ULONG_MAX,15) == 1) -# define LZO_SIZEOF_LONG 2 -# elif (__LZO_LSR(ULONG_MAX,31) == 1) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,39) == 1) -# define LZO_SIZEOF_LONG 5 -# elif (__LZO_LSR(ULONG_MAX,63) == 1) -# define LZO_SIZEOF_LONG 8 -# elif (__LZO_LSR(ULONG_MAX,127) == 1) -# define LZO_SIZEOF_LONG 16 -# else -# error "LZO_SIZEOF_LONG" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -# if (LZO_CC_GNUC >= 0x030300ul) -# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) -# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -# define LZO_SIZEOF_LONG_LONG 4 -# endif -# endif -# endif -#endif -#endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -#if (LZO_ARCH_I086 && LZO_CC_DMC) -#elif (LZO_CC_CILLY) && defined(__GNUC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_SIZEOF_LONG_LONG 8 -#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_OS_WIN64 || defined(_WIN64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define LZO_SIZEOF_LONG_LONG 8 -#endif -#endif -#endif -#if defined(__cplusplus) && (LZO_CC_GNUC) -# if (LZO_CC_GNUC < 0x020800ul) -# undef LZO_SIZEOF_LONG_LONG -# endif -#endif -#if (LZO_CFG_NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG -#elif defined(__NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG -#elif defined(_NO_LONGLONG) -# undef LZO_SIZEOF_LONG_LONG -#endif -#if !defined(LZO_WORDSIZE) #if (LZO_ARCH_ALPHA) -# define LZO_WORDSIZE 8 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 #elif (LZO_ARCH_AMD64) -# define LZO_WORDSIZE 8 -#elif (LZO_ARCH_AVR) -# define LZO_WORDSIZE 1 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_WORDSIZE 4 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_WORDSIZE 4 -# else -# define LZO_WORDSIZE 2 -# endif -#elif (LZO_ARCH_I086) -# define LZO_WORDSIZE 2 -#elif (LZO_ARCH_IA64) -# define LZO_WORDSIZE 8 -#elif (LZO_ARCH_M16C) -# define LZO_WORDSIZE 2 -#elif (LZO_ARCH_SPU) -# define LZO_WORDSIZE 4 -#elif (LZO_ARCH_Z80) -# define LZO_WORDSIZE 1 -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define LZO_WORDSIZE 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) -# define LZO_WORDSIZE 8 -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_WORDSIZE 8 -#endif -#endif -#if !defined(LZO_SIZEOF_VOID_P) -#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -# define LZO_SIZEOF_VOID_P 4 -#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -# define LZO_SIZEOF_VOID_P 8 -#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -# define LZO_SIZEOF_VOID_P 8 -#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -# define LZO_SIZEOF_VOID_P 8 -#elif (LZO_ARCH_AVR) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -# endif -#elif (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -# define LZO_SIZEOF_VOID_P 2 -# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -# define LZO_SIZEOF_VOID_P 4 -# else -# error "invalid LZO_ARCH_I086 memory model" -# endif -#elif (LZO_ARCH_M16C) -# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -#elif (LZO_ARCH_SPU) -# define LZO_SIZEOF_VOID_P 4 -#elif (LZO_ARCH_Z80) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define LZO_SIZEOF_VOID_P 4 -#elif (LZO_OS_OS400 || defined(__OS400__)) -# if defined(__LLP64_IFC__) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -# else -# define LZO_SIZEOF_VOID_P 16 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -# endif -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#endif -#endif -#if !defined(LZO_SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) -#if !defined(LZO_SIZEOF_SIZE_T) -#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -# define LZO_SIZEOF_SIZE_T 2 -#endif -#endif -#if !defined(LZO_SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -#endif -#if defined(offsetof) -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) -#endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -#if (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -# define LZO_SIZEOF_PTRDIFF_T 4 -# else -# define LZO_SIZEOF_PTRDIFF_T 2 -# endif -# else -# error "invalid LZO_ARCH_I086 memory model" -# endif -#endif -#endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T -#endif -#if defined(offsetof) -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) -#endif -#if !defined(LZO_WORDSIZE) -# define LZO_WORDSIZE LZO_SIZEOF_VOID_P -#endif -#if (LZO_ABI_NEUTRAL_ENDIAN) -# undef LZO_ABI_BIG_ENDIAN -# undef LZO_ABI_LITTLE_ENDIAN -#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -# define LZO_ABI_BIG_ENDIAN 1 -#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -# if (__LITTLE_ENDIAN__ == 1) -# define LZO_ABI_LITTLE_ENDIAN 1 -# else -# define LZO_ABI_BIG_ENDIAN 1 -# endif -#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) -# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) -# error "unexpected configuration - check your compiler defines" -# elif defined(__BIG_ENDIAN) -# define LZO_ABI_BIG_ENDIAN 1 -# else -# define LZO_ABI_LITTLE_ENDIAN 1 -# endif -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#endif -#endif -#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ABI_BIG_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "be" -#elif (LZO_ABI_LITTLE_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "le" -#elif (LZO_ABI_NEUTRAL_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "neutral" -#endif -#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_I8LP16 1 -# define LZO_INFO_ABI_PM "i8lp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_ILP16 1 -# define LZO_INFO_ABI_PM "ilp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_LP32 1 -# define LZO_INFO_ABI_PM "lp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_ILP32 1 -# define LZO_INFO_ABI_PM "ilp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -# define LZO_ABI_LLP64 1 -# define LZO_INFO_ABI_PM "llp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_LP64 1 -# define LZO_INFO_ABI_PM "lp64" -#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_ILP64 1 -# define LZO_INFO_ABI_PM "ilp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_IP32L64 1 -# define LZO_INFO_ABI_PM "ip32l64" -#endif -#if 0 -#elif !defined(__LZO_LIBC_OVERRIDE) -#if (LZO_LIBC_NAKED) -# define LZO_INFO_LIBC "naked" -#elif (LZO_LIBC_FREESTANDING) -# define LZO_INFO_LIBC "freestanding" -#elif (LZO_LIBC_MOSTLY_FREESTANDING) -# define LZO_INFO_LIBC "mfreestanding" -#elif (LZO_LIBC_ISOC90) -# define LZO_INFO_LIBC "isoc90" -#elif (LZO_LIBC_ISOC99) -# define LZO_INFO_LIBC "isoc99" -#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#elif defined(__dietlibc__) -# define LZO_LIBC_DIETLIBC 1 -# define LZO_INFO_LIBC "dietlibc" -#elif defined(_NEWLIB_VERSION) -# define LZO_LIBC_NEWLIB 1 -# define LZO_INFO_LIBC "newlib" -#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -# if defined(__UCLIBC_SUBLEVEL__) -# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) -# else -# define LZO_LIBC_UCLIBC 0x00090bL -# endif -# define LZO_INFO_LIBC "uc" "libc" -#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) -# define LZO_INFO_LIBC "glibc" -#elif (LZO_CC_MWERKS) && defined(__MSL__) -# define LZO_LIBC_MSL __MSL__ -# define LZO_INFO_LIBC "msl" -#elif 1 && defined(__IAR_SYSTEMS_ICC__) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#else -# define LZO_LIBC_DEFAULT 1 -# define LZO_INFO_LIBC "default" -#endif -#endif -#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -# define LZO_ASM_SYNTAX_MSC 1 -#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_CC_GNUC) -# define LZO_ASM_SYNTAX_GNUC 1 -#endif -#if (LZO_ASM_SYNTAX_GNUC) -#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -# define __LZO_ASM_CLOBBER "ax" -# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) -# define __LZO_ASM_CLOBBER "memory" -# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#else -# define __LZO_ASM_CLOBBER "cc", "memory" -# define __LZO_ASM_CLOBBER_LIST_CC : "cc" -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#endif -#endif -#if (LZO_ARCH_ALPHA) -# define LZO_OPT_AVOID_UINT_INDEX 1 -#elif (LZO_ARCH_AMD64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) #elif (LZO_ARCH_ARM) -# if defined(__ARM_FEATURE_UNALIGNED) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# endif -#elif (LZO_ARCH_ARM64) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 #elif (LZO_ARCH_CRIS) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 #elif (LZO_ARCH_I386) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 #elif (LZO_ARCH_IA64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 #elif (LZO_ARCH_M68K) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if defined(__mc68020__) && !defined(__mcoldfire__) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 # endif #elif (LZO_ARCH_MIPS) -# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 #elif (LZO_ARCH_POWERPC) -# define LZO_OPT_PREFER_PREINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if (LZO_ABI_BIG_ENDIAN) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# if (LZO_WORDSIZE == 8) -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 # endif #elif (LZO_ARCH_S390) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# if (LZO_WORDSIZE == 8) -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 # endif #elif (LZO_ARCH_SH) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 #endif #ifndef LZO_CFG_NO_INLINE_ASM -#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) -# define LZO_CFG_NO_INLINE_ASM 1 -#elif (LZO_CC_LLVM) +#if (LZO_CC_LLVM) # define LZO_CFG_NO_INLINE_ASM 1 #endif #endif -#if (LZO_CFG_NO_INLINE_ASM) -# undef LZO_ASM_SYNTAX_MSC -# undef LZO_ASM_SYNTAX_GNUC -# undef __LZO_ASM_CLOBBER -# undef __LZO_ASM_CLOBBER_LIST_CC -# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY -# undef __LZO_ASM_CLOBBER_LIST_EMPTY -#endif #ifndef LZO_CFG_NO_UNALIGNED #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) # define LZO_CFG_NO_UNALIGNED 1 @@ -2574,6 +1784,25 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # undef LZO_OPT_UNALIGNED32 # undef LZO_OPT_UNALIGNED64 #endif +#if (LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif #if defined(__LZO_INFOSTR_MM) #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) # define __LZO_INFOSTR_MM "" @@ -2617,382 +1846,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #define LZO_INFO_STRING \ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER -#if !(LZO_CFG_SKIP_LZO_TYPES) -#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) -# error "missing defines for sizes" -#endif -#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) -# error "missing defines for sizes" -#endif -#if !defined(lzo_llong_t) -#if (LZO_SIZEOF_LONG_LONG+0 > 0) -__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; -# define lzo_llong_t lzo_llong_t__ -# define lzo_ullong_t lzo_ullong_t__ -#endif -#endif -#if !defined(lzo_int16e_t) -#if (LZO_SIZEOF_LONG == 2) -# define lzo_int16e_t long -# define lzo_uint16e_t unsigned long -#elif (LZO_SIZEOF_INT == 2) -# define lzo_int16e_t int -# define lzo_uint16e_t unsigned int -#elif (LZO_SIZEOF_SHORT == 2) -# define lzo_int16e_t short int -# define lzo_uint16e_t unsigned short int -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) - typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); - typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); -# define lzo_int16e_t lzo_int16e_hi_t__ -# define lzo_uint16e_t lzo_uint16e_hi_t__ -#elif (LZO_SIZEOF___INT16 == 2) -# define lzo_int16e_t __int16 -# define lzo_uint16e_t unsigned __int16 -#else -#endif -#endif -#if defined(lzo_int16e_t) -# define LZO_SIZEOF_LZO_INT16E_T 2 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) -#endif -#if !defined(lzo_int32e_t) -#if (LZO_SIZEOF_LONG == 4) -# define lzo_int32e_t long int -# define lzo_uint32e_t unsigned long int -#elif (LZO_SIZEOF_INT == 4) -# define lzo_int32e_t int -# define lzo_uint32e_t unsigned int -#elif (LZO_SIZEOF_SHORT == 4) -# define lzo_int32e_t short int -# define lzo_uint32e_t unsigned short int -#elif (LZO_SIZEOF_LONG_LONG == 4) -# define lzo_int32e_t lzo_llong_t -# define lzo_uint32e_t lzo_ullong_t -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) - typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); - typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -# define lzo_int32e_t lzo_int32e_si_t__ -# define lzo_uint32e_t lzo_uint32e_si_t__ -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) - typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); - typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -# define lzo_int32e_t lzo_int32e_si_t__ -# define lzo_uint32e_t lzo_uint32e_si_t__ -# define LZO_INT32_C(c) (c##LL) -# define LZO_UINT32_C(c) (c##ULL) -#elif (LZO_SIZEOF___INT32 == 4) -# define lzo_int32e_t __int32 -# define lzo_uint32e_t unsigned __int32 -#else -#endif -#endif -#if defined(lzo_int32e_t) -# define LZO_SIZEOF_LZO_INT32E_T 4 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) -#endif -#if !defined(lzo_int64e_t) -#if (LZO_SIZEOF___INT64 == 8) -# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -# define LZO_CFG_TYPE_PREFER___INT64 1 -# endif -#endif -#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_int64e_t int -# define lzo_uint64e_t unsigned int -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG == 8) -# define lzo_int64e_t long int -# define lzo_uint64e_t unsigned long int -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG -#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) -# define lzo_int64e_t lzo_llong_t -# define lzo_uint64e_t lzo_ullong_t -# if (LZO_CC_BORLANDC) -# define LZO_INT64_C(c) ((c) + 0ll) -# define LZO_UINT64_C(c) ((c) + 0ull) -# elif 0 -# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) -# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) -# else -# define LZO_INT64_C(c) (c##LL) -# define LZO_UINT64_C(c) (c##ULL) -# endif -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG -#elif (LZO_SIZEOF___INT64 == 8) -# define lzo_int64e_t __int64 -# define lzo_uint64e_t unsigned __int64 -# if (LZO_CC_BORLANDC) -# define LZO_INT64_C(c) ((c) + 0i64) -# define LZO_UINT64_C(c) ((c) + 0ui64) -# else -# define LZO_INT64_C(c) (c##i64) -# define LZO_UINT64_C(c) (c##ui64) -# endif -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 -#else -#endif -#endif -#if defined(lzo_int64e_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) -#endif -#if !defined(lzo_int32l_t) -#if defined(lzo_int32e_t) -# define lzo_int32l_t lzo_int32e_t -# define lzo_uint32l_t lzo_uint32e_t -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T -#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_int32l_t int -# define lzo_uint32l_t unsigned int -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG >= 4) -# define lzo_int32l_t long int -# define lzo_uint32l_t unsigned long int -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG -#else -# error "lzo_int32l_t" -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) -#endif -#if !defined(lzo_int64l_t) -#if defined(lzo_int64e_t) -# define lzo_int64l_t lzo_int64e_t -# define lzo_uint64l_t lzo_uint64e_t -# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T -#else -#endif -#endif -#if defined(lzo_int64l_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) -#endif -#if !defined(lzo_int32f_t) -#if (LZO_SIZEOF_SIZE_T >= 8) -# define lzo_int32f_t lzo_int64l_t -# define lzo_uint32f_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T -#else -# define lzo_int32f_t lzo_int32l_t -# define lzo_uint32f_t lzo_uint32l_t -# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) -#endif -#if !defined(lzo_int64f_t) -#if defined(lzo_int64l_t) -# define lzo_int64f_t lzo_int64l_t -# define lzo_uint64f_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T -#else -#endif -#endif -#if defined(lzo_int64f_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) -#endif -#if !defined(lzo_intptr_t) -#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) -# define __LZO_INTPTR_T_IS_POINTER 1 - typedef char* lzo_intptr_t; - typedef char* lzo_uintptr_t; -# define lzo_intptr_t lzo_intptr_t -# define lzo_uintptr_t lzo_uintptr_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P -#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) - typedef __w64 int lzo_intptr_t; - typedef __w64 unsigned int lzo_uintptr_t; -# define lzo_intptr_t lzo_intptr_t -# define lzo_uintptr_t lzo_uintptr_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) -# define lzo_intptr_t short -# define lzo_uintptr_t unsigned short -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT -#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_intptr_t int -# define lzo_uintptr_t unsigned int -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) -# define lzo_intptr_t long -# define lzo_uintptr_t unsigned long -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG -#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) -# define lzo_intptr_t lzo_int64l_t -# define lzo_uintptr_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T -#else -# error "lzo_intptr_t" -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) -#endif -#if !defined(lzo_word_t) -#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) -#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) -# define lzo_word_t lzo_uintptr_t -# define lzo_sword_t lzo_intptr_t -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T -#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) -# define lzo_word_t unsigned long -# define lzo_sword_t long -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG -#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) -# define lzo_word_t unsigned int -# define lzo_sword_t int -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT -#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) -# define lzo_word_t unsigned short -# define lzo_sword_t short -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT -#elif (LZO_WORDSIZE == 1) -# define lzo_word_t unsigned char -# define lzo_sword_t signed char -# define LZO_SIZEOF_LZO_WORD_T 1 -#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) -# define lzo_word_t lzo_uint64l_t -# define lzo_sword_t lzo_int64l_t -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T -#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) -#if 0 - typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); - typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); -# define lzo_word_t lzo_word_t -# define lzo_sword_t lzo_sword_t -# define LZO_SIZEOF_LZO_WORD_T 16 -#endif -#else -# error "lzo_word_t" -#endif -#endif -#endif -#if 1 && defined(lzo_word_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) -#endif -#if 1 -#define lzo_int8_t signed char -#define lzo_uint8_t unsigned char -#define LZO_SIZEOF_LZO_INT8_T 1 -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) -#endif -#if defined(lzo_int16e_t) -#define lzo_int16_t lzo_int16e_t -#define lzo_uint16_t lzo_uint16e_t -#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) -#endif -#if defined(lzo_int32e_t) -#define lzo_int32_t lzo_int32e_t -#define lzo_uint32_t lzo_uint32e_t -#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) -#endif -#if defined(lzo_int64e_t) -#define lzo_int64_t lzo_int64e_t -#define lzo_uint64_t lzo_uint64e_t -#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) -#endif -#if 1 -#define lzo_int_least32_t lzo_int32l_t -#define lzo_uint_least32_t lzo_uint32l_t -#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) -#endif -#if defined(lzo_int64l_t) -#define lzo_int_least64_t lzo_int64l_t -#define lzo_uint_least64_t lzo_uint64l_t -#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) -#endif -#if 1 -#define lzo_int_fast32_t lzo_int32f_t -#define lzo_uint_fast32_t lzo_uint32f_t -#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) -#endif -#if defined(lzo_int64f_t) -#define lzo_int_fast64_t lzo_int64f_t -#define lzo_uint_fast64_t lzo_uint64f_t -#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) -#endif -#if !defined(LZO_INT16_C) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) -# define LZO_INT16_C(c) ((c) + 0) -# define LZO_UINT16_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) -# define LZO_INT16_C(c) ((c) + 0L) -# define LZO_UINT16_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 2) -# define LZO_INT16_C(c) (c) -# define LZO_UINT16_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 2) -# define LZO_INT16_C(c) (c##L) -# define LZO_UINT16_C(c) (c##UL) -# else -# error "LZO_INT16_C" -# endif -#endif -#if !defined(LZO_INT32_C) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) -# define LZO_INT32_C(c) ((c) + 0) -# define LZO_UINT32_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) -# define LZO_INT32_C(c) ((c) + 0L) -# define LZO_UINT32_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 4) -# define LZO_INT32_C(c) (c) -# define LZO_UINT32_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 4) -# define LZO_INT32_C(c) (c##L) -# define LZO_UINT32_C(c) (c##UL) -# elif (LZO_SIZEOF_LONG_LONG >= 4) -# define LZO_INT32_C(c) (c##LL) -# define LZO_UINT32_C(c) (c##ULL) -# else -# error "LZO_INT32_C" -# endif -#endif -#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) -# define LZO_INT64_C(c) ((c) + 0) -# define LZO_UINT64_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) -# define LZO_INT64_C(c) ((c) + 0L) -# define LZO_UINT64_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 8) -# define LZO_INT64_C(c) (c) -# define LZO_UINT64_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 8) -# define LZO_INT64_C(c) (c##L) -# define LZO_UINT64_C(c) (c##UL) -# else -# error "LZO_INT64_C" -# endif -#endif -#endif #endif /* already included */ -/* vim:set ts=4 sw=4 et: */ +/* vim:set ts=4 et: */ diff --git a/grub-core/lib/minilzo/minilzo.c b/grub-core/lib/minilzo/minilzo.c index ab2be5f4f..25a1f68b3 100644 --- a/grub-core/lib/minilzo/minilzo.c +++ b/grub-core/lib/minilzo/minilzo.c @@ -2,7 +2,22 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -52,6 +67,12 @@ #if defined(__CYGWIN32__) && !defined(__CYGWIN__) # define __CYGWIN__ __CYGWIN32__ #endif +#if defined(__IBMCPP__) && !defined(__IBMC__) +# define __IBMC__ __IBMCPP__ +#endif +#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +# define __INTEL_COMPILER __ICL +#endif #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) # define _ALL_SOURCE 1 #endif @@ -60,30 +81,19 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif -#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) -#if defined(__ARMCC_VERSION) -# pragma diag_suppress 193 -#elif defined(__clang__) && defined(__clang_minor__) -# pragma clang diagnostic ignored "-Wundef" -#elif defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) && defined(__linux__) # pragma warning(disable: 193) -#elif defined(__KEIL__) && defined(__C166__) +#endif +#if defined(__KEIL__) && defined(__C166__) # pragma warning disable = 322 -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) -# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) -# pragma GCC diagnostic ignored "-Wundef" -# endif -#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -# if ((_MSC_VER-0) >= 1300) +#elif 0 && defined(__C251__) +# pragma warning disable = 322 +#endif +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if (_MSC_VER >= 1300) # pragma warning(disable: 4668) # endif #endif -#endif -#if 0 && defined(__POCC__) && defined(_WIN32) -# if (__POCC__ >= 400) -# pragma warn(disable: 2216) -# endif -#endif #if 0 && defined(__WATCOMC__) # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) # pragma warning 203 9 @@ -92,29 +102,13 @@ #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) # pragma option -h #endif -#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE 1 -#endif -#ifndef _CRT_NONSTDC_NO_WARNINGS -#define _CRT_NONSTDC_NO_WARNINGS 1 -#endif -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS 1 -#endif -#endif #if 0 -#define LZO_0xffffUL 0xfffful -#define LZO_0xffffffffUL 0xfffffffful +#define LZO_0xffffL 0xfffful +#define LZO_0xffffffffL 0xfffffffful #else -#define LZO_0xffffUL 65535ul -#define LZO_0xffffffffUL 4294967295ul +#define LZO_0xffffL 65535ul +#define LZO_0xffffffffL 4294967295ul #endif -#define LZO_0xffffL LZO_0xffffUL -#define LZO_0xffffffffL LZO_0xffffffffUL #if (LZO_0xffffL == LZO_0xffffffffL) # error "your preprocessor is broken 1" #endif @@ -129,13 +123,6 @@ # error "your preprocessor is broken 4" #endif #endif -#if defined(__COUNTER__) -# ifndef LZO_CFG_USE_COUNTER -# define LZO_CFG_USE_COUNTER 1 -# endif -#else -# undef LZO_CFG_USE_COUNTER -#endif #if (UINT_MAX == LZO_0xffffL) #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) # if !defined(MSDOS) @@ -266,31 +253,14 @@ #endif #define LZO_PP_STRINGIZE(x) #x #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) -#define LZO_PP_CONCAT0() /*empty*/ -#define LZO_PP_CONCAT1(a) a #define LZO_PP_CONCAT2(a,b) a ## b #define LZO_PP_CONCAT3(a,b,c) a ## b ## c #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g -#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() -#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) -#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) -#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) -#define LZO_PP_EMPTY /*empty*/ -#define LZO_PP_EMPTY0() /*empty*/ -#define LZO_PP_EMPTY1(a) /*empty*/ -#define LZO_PP_EMPTY2(a,b) /*empty*/ -#define LZO_PP_EMPTY3(a,b,c) /*empty*/ -#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ -#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ -#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ -#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ #if 1 #define LZO_CPP_STRINGIZE(x) #x #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) @@ -298,16 +268,12 @@ #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e -#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f -#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) -#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) -#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -317,13 +283,9 @@ # endif #endif #if defined(__cplusplus) -# define LZO_EXTERN_C extern "C" -# define LZO_EXTERN_C_BEGIN extern "C" { -# define LZO_EXTERN_C_END } +# define LZO_EXTERN_C extern "C" #else -# define LZO_EXTERN_C extern -# define LZO_EXTERN_C_BEGIN /*empty*/ -# define LZO_EXTERN_C_END /*empty*/ +# define LZO_EXTERN_C extern #endif #if !defined(__LZO_OS_OVERRIDE) #if (LZO_OS_FREESTANDING) @@ -424,12 +386,12 @@ #elif defined(__VMS) # define LZO_OS_VMS 1 # define LZO_INFO_OS "vms" -#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) +#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PS2 1 # define LZO_INFO_OS "console" # define LZO_INFO_OS_CONSOLE "ps2" -#elif defined(__mips__) && defined(__psp__) +#elif (defined(__mips__) && defined(__psp__)) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PSP 1 # define LZO_INFO_OS "console" @@ -457,18 +419,9 @@ # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) # define LZO_OS_POSIX_LINUX 1 # define LZO_INFO_OS_POSIX "linux" -# elif defined(__APPLE__) && defined(__MACH__) -# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) -# define LZO_OS_POSIX_DARWIN 1040 -# define LZO_INFO_OS_POSIX "darwin_iphone" -# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) -# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -# define LZO_INFO_OS_POSIX "darwin" -# else -# define LZO_OS_POSIX_DARWIN 1 -# define LZO_INFO_OS_POSIX "darwin" -# endif -# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN +# elif defined(__APPLE__) || defined(__MACOS__) +# define LZO_OS_POSIX_MACOSX 1 +# define LZO_INFO_OS_POSIX "macosx" # elif defined(__minix__) || defined(__minix) # define LZO_OS_POSIX_MINIX 1 # define LZO_INFO_OS_POSIX "minix" @@ -503,18 +456,18 @@ #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (UINT_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) @@ -530,65 +483,59 @@ # define LZO_INFO_CC "sdcc" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) -# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) # define LZO_INFO_CC "Pathscale C" # define LZO_INFO_CCVER __PATHSCALE__ -# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# endif -#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) -# define LZO_CC_INTELC __INTEL_COMPILER +#elif defined(__INTEL_COMPILER) +# define LZO_CC_INTELC 1 # define LZO_INFO_CC "Intel C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_INTELC_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# if defined(_WIN32) || defined(_WIN64) +# define LZO_CC_SYNTAX_MSC 1 +# else +# define LZO_CC_SYNTAX_GNUC 1 # endif #elif defined(__POCC__) && defined(_WIN32) # define LZO_CC_PELLESC 1 # define LZO_INFO_CC "Pelles C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) -#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) # else -# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) # endif -# define LZO_CC_ARMCC __ARMCC_VERSION -# define LZO_INFO_CC "ARM C Compiler" -# define LZO_INFO_CCVER __VERSION__ -#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) -# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) +# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) # else -# define LZO_CC_CLANG 0x010000L -# endif -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_CLANG_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_CLANG_CLANG 0x010000L # endif +# define LZO_CC_CLANG LZO_CC_CLANG_GNUC # define LZO_INFO_CC "clang" # define LZO_INFO_CCVER __VERSION__ #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) # else -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) # endif # define LZO_CC_LLVM LZO_CC_LLVM_GNUC # define LZO_INFO_CC "llvm-gcc" # define LZO_INFO_CCVER __VERSION__ +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ #elif defined(__ACK__) && defined(_ACK) # define LZO_CC_ACK 1 # define LZO_INFO_CC "Amsterdam Compiler Kit C" # define LZO_INFO_CCVER "unknown" -#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) -# define LZO_CC_ARMCC __ARMCC_VERSION -# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION -# define LZO_INFO_CC "ARM C Compiler" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) #elif defined(__AZTEC_C__) # define LZO_CC_AZTECC 1 # define LZO_INFO_CC "Aztec C" @@ -613,23 +560,10 @@ # define LZO_CC_DECC 1 # define LZO_INFO_CC "DEC C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) -#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) -# define LZO_CC_GHS 1 -# define LZO_INFO_CC "Green Hills C" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) -# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_GHS_MSC _MSC_VER -# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) -# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# endif #elif defined(__HIGHC__) # define LZO_CC_HIGHC 1 # define LZO_INFO_CC "MetaWare High C" # define LZO_INFO_CCVER "unknown" -#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) -# define LZO_CC_HPACC __HP_aCC -# define LZO_INFO_CC "HP aCC" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) #elif defined(__IAR_SYSTEMS_ICC__) # define LZO_CC_IARC 1 # define LZO_INFO_CC "IAR C" @@ -638,14 +572,10 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__IBMC__) && ((__IBMC__-0) > 0) -# define LZO_CC_IBMC __IBMC__ +#elif defined(__IBMC__) +# define LZO_CC_IBMC 1 # define LZO_INFO_CC "IBM C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) -#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) -# define LZO_CC_IBMC __IBMCPP__ -# define LZO_INFO_CC "IBM C" -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) #elif defined(__KEIL__) && defined(__C166__) # define LZO_CC_KEILC 1 # define LZO_INFO_CC "Keil C" @@ -662,8 +592,16 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) -# define LZO_CC_MWERKS __MWERKS__ +#elif defined(_MSC_VER) +# define LZO_CC_MSC 1 +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif +#elif defined(__MWERKS__) +# define LZO_CC_MWERKS 1 # define LZO_INFO_CC "Metrowerks C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) @@ -674,15 +612,6 @@ # define LZO_CC_PACIFICC 1 # define LZO_INFO_CC "Pacific C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) -#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) -# else -# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" -# endif -# define LZO_INFO_CC "Portland Group PGI C" #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) # define LZO_CC_PGI 1 # define LZO_INFO_CC "Portland Group PGI C" @@ -697,7 +626,7 @@ # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) #elif defined(__SUNPRO_C) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_C-0) > 0) +# if ((__SUNPRO_C)+0 > 0) # define LZO_CC_SUNPROC __SUNPRO_C # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) # else @@ -706,7 +635,7 @@ # endif #elif defined(__SUNPRO_CC) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_CC-0) > 0) +# if ((__SUNPRO_CC)+0 > 0) # define LZO_CC_SUNPROC __SUNPRO_CC # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) # else @@ -732,46 +661,16 @@ #elif defined(__ZTC__) # define LZO_CC_ZORTECHC 1 # define LZO_INFO_CC "Zortech C" -# if ((__ZTC__-0) == 0x310) +# if (__ZTC__ == 0x310) # define LZO_INFO_CCVER "0x310" # else # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) # endif -#elif defined(__GNUC__) && defined(__VERSION__) -# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) -# elif defined(__GNUC_MINOR__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) -# else -# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -# endif -# define LZO_INFO_CC "gcc" -# define LZO_INFO_CCVER __VERSION__ -#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) -# define LZO_CC_MSC _MSC_VER -# define LZO_INFO_CC "Microsoft C" -# if defined(_MSC_FULL_VER) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -# else -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -# endif #else # define LZO_CC_UNKNOWN 1 # define LZO_INFO_CC "unknown" # define LZO_INFO_CCVER "unknown" #endif -#if (LZO_CC_GNUC) && defined(__OPEN64__) -# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) -# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) -# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC -# endif -#endif -#if (LZO_CC_GNUC) && defined(__PCC__) -# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) -# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) -# define LZO_CC_PCC_GNUC LZO_CC_GNUC -# endif -#endif #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" #endif @@ -789,10 +688,8 @@ # define LZO_INFO_ARCH "generic" #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 +# define LZO_ARCH_IA16 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) -# define LZO_ARCH_ARM64 1 -# define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) # define LZO_ARCH_ALPHA 1 # define LZO_INFO_ARCH "alpha" @@ -808,10 +705,10 @@ # define LZO_INFO_ARCH "arm_thumb" #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) # define LZO_ARCH_ARM 1 -# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) +# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) # define LZO_ARCH_ARM_THUMB 1 # define LZO_INFO_ARCH "arm_thumb" -# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) +# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) # define LZO_INFO_ARCH "arm" # else # define LZO_INFO_ARCH "arm" @@ -929,147 +826,53 @@ # error "FIXME - missing define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) -# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" +# error "FIXME - missing WIN32 define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) -# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" +# error "FIXME - missing WIN64 define for CPU architecture" #endif #if (LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) # define LZO_ARCH_I086PM 1 +# define LZO_ARCH_IA16PM 1 #endif -#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) -# define LZO_ARCH_X64 1 -#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_AMD64 1 +#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +# error "this should not happen" #endif -#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) -# define LZO_ARCH_AARCH64 1 -#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_ARM64 1 -#endif -#if (LZO_ARCH_I386 && !LZO_ARCH_X86) -# define LZO_ARCH_X86 1 -#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) -# define LZO_ARCH_I386 1 -#endif -#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) -# error "unexpected configuration - check your compiler defines" +#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +# error "this should not happen" #endif #if (LZO_ARCH_I086) # if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #if (LZO_ARCH_I386) # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif -#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) -# if !defined(LZO_TARGET_FEATURE_SSE2) -# if defined(__SSE2__) -# define LZO_TARGET_FEATURE_SSE2 1 -# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) -# define LZO_TARGET_FEATURE_SSE2 1 -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_SSSE3) -# if (LZO_TARGET_FEATURE_SSE2) -# if defined(__SSSE3__) -# define LZO_TARGET_FEATURE_SSSE3 1 -# elif defined(_MSC_VER) && defined(__AVX__) -# define LZO_TARGET_FEATURE_SSSE3 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_SSE4_2) -# if (LZO_TARGET_FEATURE_SSSE3) -# if defined(__SSE4_2__) -# define LZO_TARGET_FEATURE_SSE4_2 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_AVX) -# if (LZO_TARGET_FEATURE_SSSE3) -# if defined(__AVX__) -# define LZO_TARGET_FEATURE_AVX 1 -# endif -# endif -# endif -# if !defined(LZO_TARGET_FEATURE_AVX2) -# if (LZO_TARGET_FEATURE_AVX) -# if defined(__AVX2__) -# define LZO_TARGET_FEATURE_AVX2 1 -# endif -# endif -# endif -#endif -#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ARCH_ARM) -# if !defined(LZO_TARGET_FEATURE_NEON) -# if defined(__ARM_NEON__) -# define LZO_TARGET_FEATURE_NEON 1 -# endif -# endif -#elif (LZO_ARCH_ARM64) -# if !defined(LZO_TARGET_FEATURE_NEON) -# if 1 -# define LZO_TARGET_FEATURE_NEON 1 -# endif -# endif -#endif -#if 0 -#elif !defined(__LZO_MM_OVERRIDE) +#if !defined(__LZO_MM_OVERRIDE) #if (LZO_ARCH_I086) #if (UINT_MAX != LZO_0xffffL) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" #endif #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) # define LZO_MM_TINY 1 @@ -1096,7 +899,7 @@ #elif (LZO_CC_ZORTECHC && defined(__VCM__)) # define LZO_MM_LARGE 1 #else -# error "unknown LZO_ARCH_I086 memory model" +# error "unknown memory model" #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) #define LZO_HAVE_MM_HUGE_PTR 1 @@ -1119,10 +922,10 @@ #endif #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) # if (LZO_OS_DOS16) -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # elif (LZO_CC_ZORTECHC) # else -# error "unexpected configuration - check your compiler defines" +# error "this should not happen" # endif #endif #ifdef __cplusplus @@ -1154,7 +957,7 @@ extern "C" { #endif #elif (LZO_ARCH_C166) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_C166 __MODEL__" +# error "FIXME - C166 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 1) @@ -1168,11 +971,11 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_C166 __MODEL__" +# error "FIXME - C166 __MODEL__" #endif #elif (LZO_ARCH_MCS251) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_MCS251 __MODEL__" +# error "FIXME - MCS251 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -1184,11 +987,11 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_MCS251 __MODEL__" +# error "FIXME - MCS251 __MODEL__" #endif #elif (LZO_ARCH_MCS51) #if !defined(__MODEL__) -# error "FIXME - LZO_ARCH_MCS51 __MODEL__" +# error "FIXME - MCS51 __MODEL__" #elif ((__MODEL__) == 1) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -1200,7 +1003,7 @@ extern "C" { #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - LZO_ARCH_MCS51 __MODEL__" +# error "FIXME - MCS51 __MODEL__" #endif #elif (LZO_ARCH_CRAY_PVP) # define LZO_MM_PVP 1 @@ -1227,156 +1030,567 @@ extern "C" { # error "unknown memory model" #endif #endif +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#endif +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#endif +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#endif +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#endif +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#endif +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#endif +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if (LZO_ARCH_I086) +# define __LZO_WORDSIZE 2 +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "LZO_MM" +# endif +#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +# define __LZO_WORDSIZE 1 +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define __LZO_WORDSIZE 4 +# define LZO_SIZEOF_VOID_P 4 +# else +# define __LZO_WORDSIZE 2 +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_M16C) +# define __LZO_WORDSIZE 2 +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +# define __LZO_WORDSIZE 8 +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define __LZO_WORDSIZE LZO_SIZEOF_LONG +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#elif (LZO_ARCH_SPU) +# if 0 +# define __LZO_WORDSIZE 16 +# endif +# define LZO_SIZEOF_VOID_P 4 +#else +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_WORDSIZE) +# if defined(__LZO_WORDSIZE) +# define LZO_WORDSIZE __LZO_WORDSIZE +# else +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +# endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#else +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "LZO_MM" +# endif +#else +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "this should not happen" +#endif +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uclibc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif #if !defined(__lzo_gnuc_extension__) #if (LZO_CC_GNUC >= 0x020800ul) # define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_IBMC >= 600) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_gnuc_extension__ __extension__ #else -#endif -#endif -#if !defined(__lzo_gnuc_extension__) # define __lzo_gnuc_extension__ /*empty*/ #endif -#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 -# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#endif +#if !defined(__lzo_ua_volatile) +# define __lzo_ua_volatile volatile +#endif +#if !defined(__lzo_alignof) +#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# define __lzo_HAVE_alignof 1 +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# define __lzo_HAVE_constructor 1 +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# define __lzo_HAVE_destructor 1 +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "this should not happen" +#endif +#if !defined(__lzo_inline) +#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +#elif defined(__cplusplus) +# define __lzo_inline inline +#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +# define __lzo_inline __inline +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_inline __inline__ +#elif (LZO_CC_DMC) +# define __lzo_inline __inline +#elif (LZO_CC_INTELC) +# define __lzo_inline __inline +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +# define __lzo_inline __inline +#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +# define __lzo_inline __inline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_inline __inline__ +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define __lzo_inline inline +#endif +#endif +#if defined(__lzo_inline) +# define __lzo_HAVE_inline 1 +#else +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_forceinline __forceinline +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#endif +#endif +#if defined(__lzo_forceinline) +# define __lzo_HAVE_forceinline 1 +#else +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +# define __lzo_noinline __attribute__((__noinline__,__used__)) +#elif (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_noinline __declspec(noinline) +#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +# if defined(__cplusplus) # else -# define LZO_CFG_USE_NEW_STYLE_CASTS 1 +# define __lzo_noinline __declspec(noinline) # endif +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_noinline __attribute__((__noinline__)) #endif -#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 #endif -#if !defined(__cplusplus) -# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) -# undef LZO_CFG_USE_NEW_STYLE_CASTS -# endif -# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#if defined(__lzo_noinline) +# define __lzo_HAVE_noinline 1 +#else +# define __lzo_noinline /*empty*/ #endif -#if !defined(LZO_REINTERPRET_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) -# endif +#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +# error "this should not happen" #endif -#if !defined(LZO_REINTERPRET_CAST) -# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) #endif -#if !defined(LZO_STATIC_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_STATIC_CAST(t,e) (static_cast (e)) -# endif #endif -#if !defined(LZO_STATIC_CAST) -# define LZO_STATIC_CAST(t,e) ((t) (e)) +#if defined(__lzo_noreturn) +# define __lzo_HAVE_noreturn 1 +#else +# define __lzo_noreturn /*empty*/ #endif -#if !defined(LZO_STATIC_CAST2) -# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +# define __lzo_nothrow __declspec(nothrow) #endif -#if !defined(LZO_UNCONST_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNCONST_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) -# endif #endif -#if !defined(LZO_UNCONST_CAST) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) +#if defined(__lzo_nothrow) +# define __lzo_HAVE_nothrow 1 +#else +# define __lzo_nothrow /*empty*/ #endif -#if !defined(LZO_UNCONST_VOLATILE_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -# endif +#if !defined(__lzo_restrict) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +# define __lzo_restrict __restrict #endif -#if !defined(LZO_UNCONST_VOLATILE_CAST) -# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_UNVOLATILE_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) -# endif +#if defined(__lzo_restrict) +# define __lzo_HAVE_restrict 1 +#else +# define __lzo_restrict /*empty*/ #endif -#if !defined(LZO_UNVOLATILE_CAST) -# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) +#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +#if (LZO_CC_GNUC >= 0x030200ul) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #endif -#if !defined(LZO_UNVOLATILE_CONST_CAST) -# if (LZO_CFG_USE_NEW_STYLE_CASTS) -# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) -# elif (LZO_HAVE_MM_HUGE_PTR) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) -# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) -# endif #endif -#if !defined(LZO_UNVOLATILE_CONST_CAST) -# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) +#if defined(__lzo_likely) +# define __lzo_HAVE_likely 1 +#else +# define __lzo_likely(e) (e) #endif -#if !defined(LZO_PCAST) -# if (LZO_HAVE_MM_HUGE_PTR) -# define LZO_PCAST(t,e) ((t) (e)) -# endif -#endif -#if !defined(LZO_PCAST) -# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) -#endif -#if !defined(LZO_CCAST) -# if (LZO_HAVE_MM_HUGE_PTR) -# define LZO_CCAST(t,e) ((t) (e)) -# endif -#endif -#if !defined(LZO_CCAST) -# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) -#endif -#if !defined(LZO_ICONV) -# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(LZO_ICAST) -# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(LZO_ITRUNC) -# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) -#endif -#if !defined(__lzo_cte) -# if (LZO_CC_MSC || LZO_CC_WATCOMC) -# define __lzo_cte(e) ((void)0,(e)) -# elif 1 -# define __lzo_cte(e) ((void)0,(e)) -# endif -#endif -#if !defined(__lzo_cte) -# define __lzo_cte(e) (e) -#endif -#if !defined(LZO_BLOCK_BEGIN) -# define LZO_BLOCK_BEGIN do { -# define LZO_BLOCK_END } while __lzo_cte(0) +#if defined(__lzo_unlikely) +# define __lzo_HAVE_unlikely 1 +#else +# define __lzo_unlikely(e) (e) #endif #if !defined(LZO_UNUSED) # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) # define LZO_UNUSED(var) ((void) &var) # elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) # define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) -# define LZO_UNUSED(var) ((void) &var) # elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define LZO_UNUSED(var) ((void) var) # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_UNUSED(var) if (&var) ; else # elif (LZO_CC_KEILC) -# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} +# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} # elif (LZO_CC_PACIFICC) # define LZO_UNUSED(var) ((void) sizeof(var)) # elif (LZO_CC_WATCOMC) && defined(__cplusplus) @@ -1397,18 +1611,18 @@ extern "C" { # elif (LZO_CC_MSC) # define LZO_UNUSED_FUNC(func) ((void) &func) # elif (LZO_CC_KEILC || LZO_CC_PELLESC) -# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} +# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} # else # define LZO_UNUSED_FUNC(func) ((void) func) # endif #endif #if !defined(LZO_UNUSED_LABEL) -# if (LZO_CC_CLANG >= 0x020800ul) -# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) -# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l +# if (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if (0) goto l # else -# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l +# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l # endif #endif #if !defined(LZO_DEFINE_UNINITIALIZED_VAR) @@ -1420,488 +1634,39 @@ extern "C" { # define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init # endif #endif -#if !defined(__lzo_inline) -#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) -#elif defined(__cplusplus) -# define __lzo_inline inline -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -# define __lzo_inline inline -#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) -# define __lzo_inline __inline -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_inline __inline__ -#elif (LZO_CC_DMC) -# define __lzo_inline __inline -#elif (LZO_CC_GHS) -# define __lzo_inline __inline__ -#elif (LZO_CC_IBMC >= 600) -# define __lzo_inline __inline__ -#elif (LZO_CC_INTELC) -# define __lzo_inline __inline -#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) -# define __lzo_inline __inline -#elif (LZO_CC_MSC && (_MSC_VER >= 900)) -# define __lzo_inline __inline -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_inline __inline__ -#endif -#endif -#if defined(__lzo_inline) -# ifndef __lzo_HAVE_inline -# define __lzo_HAVE_inline 1 -# endif -#else -# define __lzo_inline /*empty*/ -#endif -#if !defined(__lzo_forceinline) -#if (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -# define __lzo_forceinline __forceinline -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_forceinline __forceinline -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#endif -#endif -#if defined(__lzo_forceinline) -# ifndef __lzo_HAVE_forceinline -# define __lzo_HAVE_forceinline 1 -# endif -#else -# define __lzo_forceinline __lzo_inline -#endif -#if !defined(__lzo_noinline) -#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) -# define __lzo_noinline __attribute__((__noinline__,__used__)) -#elif (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -# define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) -# if defined(__cplusplus) +#if !defined(LZO_UNCONST_CAST) +# if 0 && defined(__cplusplus) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) # else -# define __lzo_noinline __declspec(noinline) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) # endif -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_noinline __attribute__((__noinline__)) -#endif -#endif -#if defined(__lzo_noinline) -# ifndef __lzo_HAVE_noinline -# define __lzo_HAVE_noinline 1 -# endif -#else -# define __lzo_noinline /*empty*/ -#endif -#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) -# error "unexpected configuration - check your compiler defines" -#endif -#if !defined(__lzo_static_inline) -#if (LZO_CC_IBMC) -# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline -#endif -#endif -#if !defined(__lzo_static_inline) -# define __lzo_static_inline static __lzo_inline -#endif -#if !defined(__lzo_static_forceinline) -#if (LZO_CC_IBMC) -# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline -#endif -#endif -#if !defined(__lzo_static_forceinline) -# define __lzo_static_forceinline static __lzo_forceinline -#endif -#if !defined(__lzo_static_noinline) -#if (LZO_CC_IBMC) -# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline -#endif -#endif -#if !defined(__lzo_static_noinline) -# define __lzo_static_noinline static __lzo_noinline -#endif -#if !defined(__lzo_c99_extern_inline) -#if defined(__GNUC_GNU_INLINE__) -# define __lzo_c99_extern_inline __lzo_inline -#elif defined(__GNUC_STDC_INLINE__) -# define __lzo_c99_extern_inline extern __lzo_inline -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) -# define __lzo_c99_extern_inline extern __lzo_inline -#endif -#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) -# define __lzo_c99_extern_inline __lzo_inline -#endif -#endif -#if defined(__lzo_c99_extern_inline) -# ifndef __lzo_HAVE_c99_extern_inline -# define __lzo_HAVE_c99_extern_inline 1 -# endif -#else -# define __lzo_c99_extern_inline /*empty*/ -#endif -#if !defined(__lzo_may_alias) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_CLANG >= 0x020900ul) -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 -# define __lzo_may_alias __attribute__((__may_alias__)) -#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 -# define __lzo_may_alias __attribute__((__may_alias__)) -#endif -#endif -#if defined(__lzo_may_alias) -# ifndef __lzo_HAVE_may_alias -# define __lzo_HAVE_may_alias 1 -# endif -#else -# define __lzo_may_alias /*empty*/ -#endif -#if !defined(__lzo_noreturn) -#if (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_IBMC >= 700) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#endif -#endif -#if defined(__lzo_noreturn) -# ifndef __lzo_HAVE_noreturn -# define __lzo_HAVE_noreturn 1 -# endif -#else -# define __lzo_noreturn /*empty*/ -#endif -#if !defined(__lzo_nothrow) -#if (LZO_CC_GNUC >= 0x030300ul) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) -# define __lzo_nothrow __declspec(nothrow) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) -# define __lzo_nothrow __declspec(nothrow) -#endif -#endif -#if defined(__lzo_nothrow) -# ifndef __lzo_HAVE_nothrow -# define __lzo_HAVE_nothrow 1 -# endif -#else -# define __lzo_nothrow /*empty*/ -#endif -#if !defined(__lzo_restrict) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_IBMC >= 1210) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) -# define __lzo_restrict __restrict__ -#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) -# define __lzo_restrict __restrict -#elif (LZO_CC_PGI >= 0x0d0a00ul) -# define __lzo_restrict __restrict__ -#endif -#endif -#if defined(__lzo_restrict) -# ifndef __lzo_HAVE_restrict -# define __lzo_HAVE_restrict 1 -# endif -#else -# define __lzo_restrict /*empty*/ -#endif -#if !defined(__lzo_alignof) -#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_GHS) && !defined(__cplusplus) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_IBMC >= 600) -# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_alignof(e) __alignof(e) -#elif (LZO_CC_SUNPROC >= 0x5100) -# define __lzo_alignof(e) __alignof__(e) -#endif -#endif -#if defined(__lzo_alignof) -# ifndef __lzo_HAVE_alignof -# define __lzo_HAVE_alignof 1 -# endif -#endif -#if !defined(__lzo_struct_packed) -#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -# define __lzo_struct_packed(s) struct s { -# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_struct_packed(s) struct s { -# define __lzo_struct_packed_end() } __attribute__((__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_IBMC >= 700) -# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { -# define __lzo_struct_packed_end() } __attribute__((__packed__)); -# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { -# define __lzo_struct_packed_end() } __pragma(pack(pop)); -#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -# define __lzo_struct_packed(s) _Packed struct s { -# define __lzo_struct_packed_end() }; -#endif -#endif -#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) -# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) -#endif -#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) -# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() -#endif -#if !defined(__lzo_byte_struct) -#if defined(__lzo_struct_packed) -# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() -# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() -#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); -# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); -#endif -#endif -#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) -# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) -#endif -#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) -#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) -#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_CILLY || LZO_CC_PCC) -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_struct_align16(s) struct __declspec(align(16)) s { -# define __lzo_struct_align16_end() }; -# define __lzo_struct_align32(s) struct __declspec(align(32)) s { -# define __lzo_struct_align32_end() }; -# define __lzo_struct_align64(s) struct __declspec(align(64)) s { -# define __lzo_struct_align64_end() }; -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_struct_align16(s) struct s { -# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); -# define __lzo_struct_align32(s) struct s { -# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); -# define __lzo_struct_align64(s) struct s { -# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); -#endif -#endif -#if !defined(__lzo_union_um) -#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) -#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) -#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) -#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_union_am(s) union s { -# define __lzo_union_am_end() } __lzo_may_alias; -# define __lzo_union_um(s) union s { -# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_IBMC >= 700) -# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { -# define __lzo_union_am_end() } __lzo_may_alias; -# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { -# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); -#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_union_um(s) __pragma(pack(push,1)) union s { -# define __lzo_union_um_end() } __pragma(pack(pop)); -#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) -# define __lzo_union_um(s) _Packed union s { -# define __lzo_union_um_end() }; -#endif -#endif -#if !defined(__lzo_union_am) -# define __lzo_union_am(s) union s { -# define __lzo_union_am_end() }; -#endif -#if !defined(__lzo_constructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_constructor __attribute__((__constructor__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_constructor __attribute__((__constructor__)) -#endif -#endif -#if defined(__lzo_constructor) -# ifndef __lzo_HAVE_constructor -# define __lzo_HAVE_constructor 1 -# endif -#endif -#if !defined(__lzo_destructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_destructor __attribute__((__destructor__)) -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_destructor __attribute__((__destructor__)) -#endif -#endif -#if defined(__lzo_destructor) -# ifndef __lzo_HAVE_destructor -# define __lzo_HAVE_destructor 1 -# endif -#endif -#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -# error "unexpected configuration - check your compiler defines" -#endif -#if !defined(__lzo_likely) && !defined(__lzo_unlikely) -#if (LZO_CC_GNUC >= 0x030200ul) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_IBMC >= 1010) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_likely(e) (__builtin_expect(!!(e),1)) -# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#endif -#endif -#if defined(__lzo_likely) -# ifndef __lzo_HAVE_likely -# define __lzo_HAVE_likely 1 -# endif -#else -# define __lzo_likely(e) (e) -#endif -#if defined(__lzo_unlikely) -# ifndef __lzo_HAVE_unlikely -# define __lzo_HAVE_unlikely 1 -# endif -#else -# define __lzo_unlikely(e) (e) -#endif -#if !defined(__lzo_static_unused_void_func) -# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) -# else -# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) -# endif -#endif -#if !defined(__lzo_loop_forever) -# if (LZO_CC_IBMC) -# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END -# else -# define __lzo_loop_forever() do { ; } while __lzo_cte(1) -# endif -#endif -#if !defined(__lzo_unreachable) -#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) -# define __lzo_unreachable() __builtin_unreachable(); -#elif (LZO_CC_GNUC >= 0x040500ul) -# define __lzo_unreachable() __builtin_unreachable(); -#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 -# define __lzo_unreachable() __builtin_unreachable(); -#endif -#endif -#if defined(__lzo_unreachable) -# ifndef __lzo_HAVE_unreachable -# define __lzo_HAVE_unreachable 1 -# endif -#else -# if 0 -# define __lzo_unreachable() ((void)0); -# else -# define __lzo_unreachable() __lzo_loop_forever(); -# endif -#endif -#ifndef __LZO_CTA_NAME -#if (LZO_CFG_USE_COUNTER) -# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) -#else -# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) -#endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END -# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END -# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; # else -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; # endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT) # if (LZO_CC_AZTECC) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; -# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) -# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} -# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) -# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} -# elif (LZO_CC_GNUC >= 0x040700ul) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # else -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} # endif #endif -LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) -#if defined(__cplusplus) -extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) @@ -1965,7 +1730,6 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) # define __lzo_cdecl_va __lzo_cdecl #endif #if !(LZO_CFG_NO_WINDOWS_H) -#if !defined(LZO_HAVE_WINDOWS_H) #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) # elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) @@ -1975,615 +1739,61 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) # endif #endif #endif -#endif -#ifndef LZO_SIZEOF_SHORT -#if defined(SIZEOF_SHORT) -# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) -#elif defined(__SIZEOF_SHORT__) -# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) -#endif -#endif -#ifndef LZO_SIZEOF_INT -#if defined(SIZEOF_INT) -# define LZO_SIZEOF_INT (SIZEOF_INT) -#elif defined(__SIZEOF_INT__) -# define LZO_SIZEOF_INT (__SIZEOF_INT__) -#endif -#endif -#ifndef LZO_SIZEOF_LONG -#if defined(SIZEOF_LONG) -# define LZO_SIZEOF_LONG (SIZEOF_LONG) -#elif defined(__SIZEOF_LONG__) -# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) -#endif -#endif -#ifndef LZO_SIZEOF_LONG_LONG -#if defined(SIZEOF_LONG_LONG) -# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) -#elif defined(__SIZEOF_LONG_LONG__) -# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) -#endif -#endif -#ifndef LZO_SIZEOF___INT16 -#if defined(SIZEOF___INT16) -# define LZO_SIZEOF___INT16 (SIZEOF___INT16) -#endif -#endif -#ifndef LZO_SIZEOF___INT32 -#if defined(SIZEOF___INT32) -# define LZO_SIZEOF___INT32 (SIZEOF___INT32) -#endif -#endif -#ifndef LZO_SIZEOF___INT64 -#if defined(SIZEOF___INT64) -# define LZO_SIZEOF___INT64 (SIZEOF___INT64) -#endif -#endif -#ifndef LZO_SIZEOF_VOID_P -#if defined(SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) -#elif defined(__SIZEOF_POINTER__) -# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) -#endif -#endif -#ifndef LZO_SIZEOF_SIZE_T -#if defined(SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) -#elif defined(__SIZEOF_SIZE_T__) -# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) -#endif -#endif -#ifndef LZO_SIZEOF_PTRDIFF_T -#if defined(SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) -#elif defined(__SIZEOF_PTRDIFF_T__) -# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) -#endif -#endif -#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -#if !defined(LZO_SIZEOF_SHORT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_SHORT 8 -# elif (USHRT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,7) == 1) -# define LZO_SIZEOF_SHORT 1 -# elif (__LZO_LSR(USHRT_MAX,15) == 1) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,31) == 1) -# define LZO_SIZEOF_SHORT 4 -# elif (__LZO_LSR(USHRT_MAX,63) == 1) -# define LZO_SIZEOF_SHORT 8 -# elif (__LZO_LSR(USHRT_MAX,127) == 1) -# define LZO_SIZEOF_SHORT 16 -# else -# error "LZO_SIZEOF_SHORT" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) -#if !defined(LZO_SIZEOF_INT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_INT 8 -# elif (UINT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_INT 2 -# elif (UINT_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,7) == 1) -# define LZO_SIZEOF_INT 1 -# elif (__LZO_LSR(UINT_MAX,15) == 1) -# define LZO_SIZEOF_INT 2 -# elif (__LZO_LSR(UINT_MAX,31) == 1) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,63) == 1) -# define LZO_SIZEOF_INT 8 -# elif (__LZO_LSR(UINT_MAX,127) == 1) -# define LZO_SIZEOF_INT 16 -# else -# error "LZO_SIZEOF_INT" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) -#if !defined(LZO_SIZEOF_LONG) -# if (ULONG_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,7) == 1) -# define LZO_SIZEOF_LONG 1 -# elif (__LZO_LSR(ULONG_MAX,15) == 1) -# define LZO_SIZEOF_LONG 2 -# elif (__LZO_LSR(ULONG_MAX,31) == 1) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,39) == 1) -# define LZO_SIZEOF_LONG 5 -# elif (__LZO_LSR(ULONG_MAX,63) == 1) -# define LZO_SIZEOF_LONG 8 -# elif (__LZO_LSR(ULONG_MAX,127) == 1) -# define LZO_SIZEOF_LONG 16 -# else -# error "LZO_SIZEOF_LONG" -# endif -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -# if (LZO_CC_GNUC >= 0x030300ul) -# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) -# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -# define LZO_SIZEOF_LONG_LONG 4 -# endif -# endif -# endif -#endif -#endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -#if (LZO_ARCH_I086 && LZO_CC_DMC) -#elif (LZO_CC_CILLY) && defined(__GNUC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_SIZEOF_LONG_LONG 8 -#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_OS_WIN64 || defined(_WIN64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define LZO_SIZEOF_LONG_LONG 8 -#endif -#endif -#endif -#if defined(__cplusplus) && (LZO_CC_GNUC) -# if (LZO_CC_GNUC < 0x020800ul) -# undef LZO_SIZEOF_LONG_LONG -# endif -#endif -#if (LZO_CFG_NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG -#elif defined(__NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG -#elif defined(_NO_LONGLONG) -# undef LZO_SIZEOF_LONG_LONG -#endif -#if !defined(LZO_WORDSIZE) #if (LZO_ARCH_ALPHA) -# define LZO_WORDSIZE 8 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 #elif (LZO_ARCH_AMD64) -# define LZO_WORDSIZE 8 -#elif (LZO_ARCH_AVR) -# define LZO_WORDSIZE 1 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_WORDSIZE 4 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_WORDSIZE 4 -# else -# define LZO_WORDSIZE 2 -# endif -#elif (LZO_ARCH_I086) -# define LZO_WORDSIZE 2 -#elif (LZO_ARCH_IA64) -# define LZO_WORDSIZE 8 -#elif (LZO_ARCH_M16C) -# define LZO_WORDSIZE 2 -#elif (LZO_ARCH_SPU) -# define LZO_WORDSIZE 4 -#elif (LZO_ARCH_Z80) -# define LZO_WORDSIZE 1 -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define LZO_WORDSIZE 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) -# define LZO_WORDSIZE 8 -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_WORDSIZE 8 -#endif -#endif -#if !defined(LZO_SIZEOF_VOID_P) -#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -# define LZO_SIZEOF_VOID_P 4 -#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -# define LZO_SIZEOF_VOID_P 8 -#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) -# define LZO_SIZEOF_VOID_P 8 -#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) -# define LZO_SIZEOF_VOID_P 8 -#elif (LZO_ARCH_AVR) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -# endif -#elif (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -# define LZO_SIZEOF_VOID_P 2 -# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -# define LZO_SIZEOF_VOID_P 4 -# else -# error "invalid LZO_ARCH_I086 memory model" -# endif -#elif (LZO_ARCH_M16C) -# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -#elif (LZO_ARCH_SPU) -# define LZO_SIZEOF_VOID_P 4 -#elif (LZO_ARCH_Z80) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define LZO_SIZEOF_VOID_P 4 -#elif (LZO_OS_OS400 || defined(__OS400__)) -# if defined(__LLP64_IFC__) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -# else -# define LZO_SIZEOF_VOID_P 16 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -# endif -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#endif -#endif -#if !defined(LZO_SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -#endif -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) -#if !defined(LZO_SIZEOF_SIZE_T) -#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -# define LZO_SIZEOF_SIZE_T 2 -#endif -#endif -#if !defined(LZO_SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -#endif -#if defined(offsetof) -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) -#endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -#if (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -# define LZO_SIZEOF_PTRDIFF_T 4 -# else -# define LZO_SIZEOF_PTRDIFF_T 2 -# endif -# else -# error "invalid LZO_ARCH_I086 memory model" -# endif -#endif -#endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T -#endif -#if defined(offsetof) -LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) -#endif -#if !defined(LZO_WORDSIZE) -# define LZO_WORDSIZE LZO_SIZEOF_VOID_P -#endif -#if (LZO_ABI_NEUTRAL_ENDIAN) -# undef LZO_ABI_BIG_ENDIAN -# undef LZO_ABI_LITTLE_ENDIAN -#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -# define LZO_ABI_BIG_ENDIAN 1 -#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -# if (__LITTLE_ENDIAN__ == 1) -# define LZO_ABI_LITTLE_ENDIAN 1 -# else -# define LZO_ABI_BIG_ENDIAN 1 -# endif -#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) -# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) -# error "unexpected configuration - check your compiler defines" -# elif defined(__BIG_ENDIAN) -# define LZO_ABI_BIG_ENDIAN 1 -# else -# define LZO_ABI_LITTLE_ENDIAN 1 -# endif -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#endif -#endif -#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -# error "unexpected configuration - check your compiler defines" -#endif -#if (LZO_ABI_BIG_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "be" -#elif (LZO_ABI_LITTLE_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "le" -#elif (LZO_ABI_NEUTRAL_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "neutral" -#endif -#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_I8LP16 1 -# define LZO_INFO_ABI_PM "i8lp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_ILP16 1 -# define LZO_INFO_ABI_PM "ilp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_LP32 1 -# define LZO_INFO_ABI_PM "lp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_ILP32 1 -# define LZO_INFO_ABI_PM "ilp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -# define LZO_ABI_LLP64 1 -# define LZO_INFO_ABI_PM "llp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_LP64 1 -# define LZO_INFO_ABI_PM "lp64" -#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_ILP64 1 -# define LZO_INFO_ABI_PM "ilp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_IP32L64 1 -# define LZO_INFO_ABI_PM "ip32l64" -#endif -#if 0 -#elif !defined(__LZO_LIBC_OVERRIDE) -#if (LZO_LIBC_NAKED) -# define LZO_INFO_LIBC "naked" -#elif (LZO_LIBC_FREESTANDING) -# define LZO_INFO_LIBC "freestanding" -#elif (LZO_LIBC_MOSTLY_FREESTANDING) -# define LZO_INFO_LIBC "mfreestanding" -#elif (LZO_LIBC_ISOC90) -# define LZO_INFO_LIBC "isoc90" -#elif (LZO_LIBC_ISOC99) -# define LZO_INFO_LIBC "isoc99" -#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#elif defined(__dietlibc__) -# define LZO_LIBC_DIETLIBC 1 -# define LZO_INFO_LIBC "dietlibc" -#elif defined(_NEWLIB_VERSION) -# define LZO_LIBC_NEWLIB 1 -# define LZO_INFO_LIBC "newlib" -#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -# if defined(__UCLIBC_SUBLEVEL__) -# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) -# else -# define LZO_LIBC_UCLIBC 0x00090bL -# endif -# define LZO_INFO_LIBC "uc" "libc" -#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) -# define LZO_INFO_LIBC "glibc" -#elif (LZO_CC_MWERKS) && defined(__MSL__) -# define LZO_LIBC_MSL __MSL__ -# define LZO_INFO_LIBC "msl" -#elif 1 && defined(__IAR_SYSTEMS_ICC__) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#else -# define LZO_LIBC_DEFAULT 1 -# define LZO_INFO_LIBC "default" -#endif -#endif -#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -# define LZO_ASM_SYNTAX_MSC 1 -#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_CC_GNUC) -# define LZO_ASM_SYNTAX_GNUC 1 -#endif -#if (LZO_ASM_SYNTAX_GNUC) -#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -# define __LZO_ASM_CLOBBER "ax" -# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) -# define __LZO_ASM_CLOBBER "memory" -# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#else -# define __LZO_ASM_CLOBBER "cc", "memory" -# define __LZO_ASM_CLOBBER_LIST_CC : "cc" -# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" -# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ -#endif -#endif -#if (LZO_ARCH_ALPHA) -# define LZO_OPT_AVOID_UINT_INDEX 1 -#elif (LZO_ARCH_AMD64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# define LZO_OPT_UNALIGNED64 1 +#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) #elif (LZO_ARCH_ARM) -# if defined(__ARM_FEATURE_UNALIGNED) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# endif -#elif (LZO_ARCH_ARM64) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_AVOID_SHORT 1 +# define LZO_OPT_AVOID_USHORT 1 #elif (LZO_ARCH_CRIS) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 #elif (LZO_ARCH_I386) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 #elif (LZO_ARCH_IA64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 #elif (LZO_ARCH_M68K) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if defined(__mc68020__) && !defined(__mcoldfire__) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 # endif #elif (LZO_ARCH_MIPS) -# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 #elif (LZO_ARCH_POWERPC) -# define LZO_OPT_PREFER_PREINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if (LZO_ABI_BIG_ENDIAN) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# if (LZO_WORDSIZE == 8) -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 # endif #elif (LZO_ARCH_S390) -# ifndef LZO_OPT_UNALIGNED16 -# define LZO_OPT_UNALIGNED16 1 -# endif -# ifndef LZO_OPT_UNALIGNED32 -# define LZO_OPT_UNALIGNED32 1 -# endif -# if (LZO_WORDSIZE == 8) -# ifndef LZO_OPT_UNALIGNED64 -# define LZO_OPT_UNALIGNED64 1 -# endif +# define LZO_OPT_UNALIGNED16 1 +# define LZO_OPT_UNALIGNED32 1 +# if (LZO_SIZEOF_SIZE_T == 8) +# define LZO_OPT_UNALIGNED64 1 # endif #elif (LZO_ARCH_SH) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 #endif #ifndef LZO_CFG_NO_INLINE_ASM -#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) -# define LZO_CFG_NO_INLINE_ASM 1 -#elif (LZO_CC_LLVM) +#if (LZO_CC_LLVM) # define LZO_CFG_NO_INLINE_ASM 1 #endif #endif -#if (LZO_CFG_NO_INLINE_ASM) -# undef LZO_ASM_SYNTAX_MSC -# undef LZO_ASM_SYNTAX_GNUC -# undef __LZO_ASM_CLOBBER -# undef __LZO_ASM_CLOBBER_LIST_CC -# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY -# undef __LZO_ASM_CLOBBER_LIST_EMPTY -#endif #ifndef LZO_CFG_NO_UNALIGNED #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) # define LZO_CFG_NO_UNALIGNED 1 @@ -2594,6 +1804,25 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # undef LZO_OPT_UNALIGNED32 # undef LZO_OPT_UNALIGNED64 #endif +#if (LZO_CFG_NO_INLINE_ASM) +#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +#elif (LZO_CC_INTELC) +# define __LZO_ASM_CLOBBER "memory" +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +#endif +#endif #if defined(__LZO_INFOSTR_MM) #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) # define __LZO_INFOSTR_MM "" @@ -2637,381 +1866,6 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #define LZO_INFO_STRING \ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER -#if !(LZO_CFG_SKIP_LZO_TYPES) -#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) -# error "missing defines for sizes" -#endif -#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) -# error "missing defines for sizes" -#endif -#if !defined(lzo_llong_t) -#if (LZO_SIZEOF_LONG_LONG+0 > 0) -__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; -# define lzo_llong_t lzo_llong_t__ -# define lzo_ullong_t lzo_ullong_t__ -#endif -#endif -#if !defined(lzo_int16e_t) -#if (LZO_SIZEOF_LONG == 2) -# define lzo_int16e_t long -# define lzo_uint16e_t unsigned long -#elif (LZO_SIZEOF_INT == 2) -# define lzo_int16e_t int -# define lzo_uint16e_t unsigned int -#elif (LZO_SIZEOF_SHORT == 2) -# define lzo_int16e_t short int -# define lzo_uint16e_t unsigned short int -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) - typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); - typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); -# define lzo_int16e_t lzo_int16e_hi_t__ -# define lzo_uint16e_t lzo_uint16e_hi_t__ -#elif (LZO_SIZEOF___INT16 == 2) -# define lzo_int16e_t __int16 -# define lzo_uint16e_t unsigned __int16 -#else -#endif -#endif -#if defined(lzo_int16e_t) -# define LZO_SIZEOF_LZO_INT16E_T 2 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) -#endif -#if !defined(lzo_int32e_t) -#if (LZO_SIZEOF_LONG == 4) -# define lzo_int32e_t long int -# define lzo_uint32e_t unsigned long int -#elif (LZO_SIZEOF_INT == 4) -# define lzo_int32e_t int -# define lzo_uint32e_t unsigned int -#elif (LZO_SIZEOF_SHORT == 4) -# define lzo_int32e_t short int -# define lzo_uint32e_t unsigned short int -#elif (LZO_SIZEOF_LONG_LONG == 4) -# define lzo_int32e_t lzo_llong_t -# define lzo_uint32e_t lzo_ullong_t -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) - typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); - typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -# define lzo_int32e_t lzo_int32e_si_t__ -# define lzo_uint32e_t lzo_uint32e_si_t__ -#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) - typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); - typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); -# define lzo_int32e_t lzo_int32e_si_t__ -# define lzo_uint32e_t lzo_uint32e_si_t__ -# define LZO_INT32_C(c) (c##LL) -# define LZO_UINT32_C(c) (c##ULL) -#elif (LZO_SIZEOF___INT32 == 4) -# define lzo_int32e_t __int32 -# define lzo_uint32e_t unsigned __int32 -#else -#endif -#endif -#if defined(lzo_int32e_t) -# define LZO_SIZEOF_LZO_INT32E_T 4 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) -#endif -#if !defined(lzo_int64e_t) -#if (LZO_SIZEOF___INT64 == 8) -# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -# define LZO_CFG_TYPE_PREFER___INT64 1 -# endif -#endif -#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_int64e_t int -# define lzo_uint64e_t unsigned int -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG == 8) -# define lzo_int64e_t long int -# define lzo_uint64e_t unsigned long int -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG -#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) -# define lzo_int64e_t lzo_llong_t -# define lzo_uint64e_t lzo_ullong_t -# if (LZO_CC_BORLANDC) -# define LZO_INT64_C(c) ((c) + 0ll) -# define LZO_UINT64_C(c) ((c) + 0ull) -# elif 0 -# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) -# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) -# else -# define LZO_INT64_C(c) (c##LL) -# define LZO_UINT64_C(c) (c##ULL) -# endif -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG -#elif (LZO_SIZEOF___INT64 == 8) -# define lzo_int64e_t __int64 -# define lzo_uint64e_t unsigned __int64 -# if (LZO_CC_BORLANDC) -# define LZO_INT64_C(c) ((c) + 0i64) -# define LZO_UINT64_C(c) ((c) + 0ui64) -# else -# define LZO_INT64_C(c) (c##i64) -# define LZO_UINT64_C(c) (c##ui64) -# endif -# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 -#else -#endif -#endif -#if defined(lzo_int64e_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) -#endif -#if !defined(lzo_int32l_t) -#if defined(lzo_int32e_t) -# define lzo_int32l_t lzo_int32e_t -# define lzo_uint32l_t lzo_uint32e_t -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T -#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_int32l_t int -# define lzo_uint32l_t unsigned int -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG >= 4) -# define lzo_int32l_t long int -# define lzo_uint32l_t unsigned long int -# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG -#else -# error "lzo_int32l_t" -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) -#endif -#if !defined(lzo_int64l_t) -#if defined(lzo_int64e_t) -# define lzo_int64l_t lzo_int64e_t -# define lzo_uint64l_t lzo_uint64e_t -# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T -#else -#endif -#endif -#if defined(lzo_int64l_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) -#endif -#if !defined(lzo_int32f_t) -#if (LZO_SIZEOF_SIZE_T >= 8) -# define lzo_int32f_t lzo_int64l_t -# define lzo_uint32f_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T -#else -# define lzo_int32f_t lzo_int32l_t -# define lzo_uint32f_t lzo_uint32l_t -# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) -#endif -#if !defined(lzo_int64f_t) -#if defined(lzo_int64l_t) -# define lzo_int64f_t lzo_int64l_t -# define lzo_uint64f_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T -#else -#endif -#endif -#if defined(lzo_int64f_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) -#endif -#if !defined(lzo_intptr_t) -#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) -# define __LZO_INTPTR_T_IS_POINTER 1 - typedef char* lzo_intptr_t; - typedef char* lzo_uintptr_t; -# define lzo_intptr_t lzo_intptr_t -# define lzo_uintptr_t lzo_uintptr_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P -#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) - typedef __w64 int lzo_intptr_t; - typedef __w64 unsigned int lzo_uintptr_t; -# define lzo_intptr_t lzo_intptr_t -# define lzo_uintptr_t lzo_uintptr_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) -# define lzo_intptr_t short -# define lzo_uintptr_t unsigned short -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT -#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) -# define lzo_intptr_t int -# define lzo_uintptr_t unsigned int -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT -#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) -# define lzo_intptr_t long -# define lzo_uintptr_t unsigned long -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG -#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) -# define lzo_intptr_t lzo_int64l_t -# define lzo_uintptr_t lzo_uint64l_t -# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T -#else -# error "lzo_intptr_t" -#endif -#endif -#if 1 - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) -#endif -#if !defined(lzo_word_t) -#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) -#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) -# define lzo_word_t lzo_uintptr_t -# define lzo_sword_t lzo_intptr_t -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T -#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) -# define lzo_word_t unsigned long -# define lzo_sword_t long -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG -#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) -# define lzo_word_t unsigned int -# define lzo_sword_t int -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT -#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) -# define lzo_word_t unsigned short -# define lzo_sword_t short -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT -#elif (LZO_WORDSIZE == 1) -# define lzo_word_t unsigned char -# define lzo_sword_t signed char -# define LZO_SIZEOF_LZO_WORD_T 1 -#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) -# define lzo_word_t lzo_uint64l_t -# define lzo_sword_t lzo_int64l_t -# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T -#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) -#if 0 - typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); - typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); -# define lzo_word_t lzo_word_t -# define lzo_sword_t lzo_sword_t -# define LZO_SIZEOF_LZO_WORD_T 16 -#endif -#else -# error "lzo_word_t" -#endif -#endif -#endif -#if 1 && defined(lzo_word_t) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) - LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) -#endif -#if 1 -#define lzo_int8_t signed char -#define lzo_uint8_t unsigned char -#define LZO_SIZEOF_LZO_INT8_T 1 -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) -#endif -#if defined(lzo_int16e_t) -#define lzo_int16_t lzo_int16e_t -#define lzo_uint16_t lzo_uint16e_t -#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) -#endif -#if defined(lzo_int32e_t) -#define lzo_int32_t lzo_int32e_t -#define lzo_uint32_t lzo_uint32e_t -#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) -#endif -#if defined(lzo_int64e_t) -#define lzo_int64_t lzo_int64e_t -#define lzo_uint64_t lzo_uint64e_t -#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) -#endif -#if 1 -#define lzo_int_least32_t lzo_int32l_t -#define lzo_uint_least32_t lzo_uint32l_t -#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) -#endif -#if defined(lzo_int64l_t) -#define lzo_int_least64_t lzo_int64l_t -#define lzo_uint_least64_t lzo_uint64l_t -#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) -#endif -#if 1 -#define lzo_int_fast32_t lzo_int32f_t -#define lzo_uint_fast32_t lzo_uint32f_t -#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) -#endif -#if defined(lzo_int64f_t) -#define lzo_int_fast64_t lzo_int64f_t -#define lzo_uint_fast64_t lzo_uint64f_t -#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) -#endif -#if !defined(LZO_INT16_C) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) -# define LZO_INT16_C(c) ((c) + 0) -# define LZO_UINT16_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) -# define LZO_INT16_C(c) ((c) + 0L) -# define LZO_UINT16_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 2) -# define LZO_INT16_C(c) (c) -# define LZO_UINT16_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 2) -# define LZO_INT16_C(c) (c##L) -# define LZO_UINT16_C(c) (c##UL) -# else -# error "LZO_INT16_C" -# endif -#endif -#if !defined(LZO_INT32_C) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) -# define LZO_INT32_C(c) ((c) + 0) -# define LZO_UINT32_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) -# define LZO_INT32_C(c) ((c) + 0L) -# define LZO_UINT32_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 4) -# define LZO_INT32_C(c) (c) -# define LZO_UINT32_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 4) -# define LZO_INT32_C(c) (c##L) -# define LZO_UINT32_C(c) (c##UL) -# elif (LZO_SIZEOF_LONG_LONG >= 4) -# define LZO_INT32_C(c) (c##LL) -# define LZO_UINT32_C(c) (c##ULL) -# else -# error "LZO_INT32_C" -# endif -#endif -#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) -# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) -# define LZO_INT64_C(c) ((c) + 0) -# define LZO_UINT64_C(c) ((c) + 0U) -# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) -# define LZO_INT64_C(c) ((c) + 0L) -# define LZO_UINT64_C(c) ((c) + 0UL) -# elif (LZO_SIZEOF_INT >= 8) -# define LZO_INT64_C(c) (c) -# define LZO_UINT64_C(c) (c##U) -# elif (LZO_SIZEOF_LONG >= 8) -# define LZO_INT64_C(c) (c##L) -# define LZO_UINT64_C(c) (c##UL) -# else -# error "LZO_INT64_C" -# endif -#endif -#endif #endif @@ -3020,7 +1874,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #undef LZO_HAVE_CONFIG_H #include "minilzo.h" -#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2080) +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050) # error "version mismatch in miniLZO source files" #endif @@ -3032,9 +1886,23 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #define __LZO_CONF_H 1 #if !defined(__LZO_IN_MINILZO) -#if defined(LZO_CFG_FREESTANDING) && (LZO_CFG_FREESTANDING) +#if (LZO_CFG_FREESTANDING) # define LZO_LIBC_FREESTANDING 1 # define LZO_OS_FREESTANDING 1 +# define ACC_LIBC_FREESTANDING 1 +# define ACC_OS_FREESTANDING 1 +#endif +#if (LZO_CFG_NO_UNALIGNED) +# define ACC_CFG_NO_UNALIGNED 1 +#endif +#if (LZO_ARCH_GENERIC) +# define ACC_ARCH_GENERIC 1 +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# define ACC_ABI_NEUTRAL_ENDIAN 1 +#endif +#if (LZO_HAVE_CONFIG_H) +# define ACC_CONFIG_NO_HEADER 1 #endif #if defined(LZO_CFG_EXTRA_CONFIG_HEADER) # include LZO_CFG_EXTRA_CONFIG_HEADER @@ -3043,27 +1911,22 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 # error "include this file first" #endif #include "lzo/lzoconf.h" -#if defined(LZO_CFG_EXTRA_CONFIG_HEADER2) -# include LZO_CFG_EXTRA_CONFIG_HEADER2 -#endif #endif -#if (LZO_VERSION < 0x2080) || !defined(__LZOCONF_H_INCLUDED) +#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) # error "version mismatch" #endif -#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1100)) -# pragma warning(disable: 4702) +#if (LZO_CC_BORLANDC && LZO_ARCH_I086) +# pragma option -h #endif + #if (LZO_CC_MSC && (_MSC_VER >= 1000)) # pragma warning(disable: 4127 4701) -# pragma warning(disable: 4514 4710 4711) #endif #if (LZO_CC_MSC && (_MSC_VER >= 1300)) # pragma warning(disable: 4820) -#endif -#if (LZO_CC_MSC && (_MSC_VER >= 1800)) -# pragma warning(disable: 4746) +# pragma warning(disable: 4514 4710 4711) #endif #if (LZO_CC_SUNPROC) @@ -3074,16 +1937,49 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #endif #endif -#if defined(__LZO_IN_MINILZO) || (LZO_CFG_FREESTANDING) +#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) +# error "this should not happen - check defines for __huge" +#endif + +#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) +#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +# define ACC_WANT_ACC_INCD_H 1 +# define ACC_WANT_ACC_INCE_H 1 +# define ACC_WANT_ACC_INCI_H 1 #elif 1 # include #else -# define LZO_WANT_ACC_INCD_H 1 +# define ACC_WANT_ACC_INCD_H 1 #endif -#if defined(LZO_HAVE_CONFIG_H) -# define LZO_CFG_NO_CONFIG_HEADER 1 + +#if (LZO_ARCH_I086) +# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT +# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) +# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) +# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) #endif +#if !defined(lzo_uintptr_t) +# if defined(__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) +# define __LZO_UINTPTR_T_IS_POINTER 1 + typedef char* lzo_uintptr_t; +# define lzo_uintptr_t lzo_uintptr_t +# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t size_t +# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long +# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned int +# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) +# define lzo_uintptr_t unsigned long long +# else +# define lzo_uintptr_t size_t +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + #if 1 && !defined(LZO_CFG_FREESTANDING) #if 1 && !defined(HAVE_STRING_H) #define HAVE_STRING_H 1 @@ -3106,23 +2002,6 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #include #endif -#if 1 || defined(lzo_int8_t) || defined(lzo_uint8_t) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint8_t) == 1) -#endif -#if 1 || defined(lzo_int16_t) || defined(lzo_uint16_t) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint16_t) == 2) -#endif -#if 1 || defined(lzo_int32_t) || defined(lzo_uint32_t) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32_t) == 4) -#endif -#if defined(lzo_int64_t) || defined(lzo_uint64_t) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) -#endif - #if (LZO_CFG_FREESTANDING) # undef HAVE_MEMCMP # undef HAVE_MEMCPY @@ -3133,28 +2012,28 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) #if !(HAVE_MEMCMP) # undef memcmp # define memcmp(a,b,c) lzo_memcmp(a,b,c) -#else +#elif !(__LZO_MMODEL_HUGE) # undef lzo_memcmp # define lzo_memcmp(a,b,c) memcmp(a,b,c) #endif #if !(HAVE_MEMCPY) # undef memcpy # define memcpy(a,b,c) lzo_memcpy(a,b,c) -#else +#elif !(__LZO_MMODEL_HUGE) # undef lzo_memcpy # define lzo_memcpy(a,b,c) memcpy(a,b,c) #endif #if !(HAVE_MEMMOVE) # undef memmove # define memmove(a,b,c) lzo_memmove(a,b,c) -#else +#elif !(__LZO_MMODEL_HUGE) # undef lzo_memmove # define lzo_memmove(a,b,c) memmove(a,b,c) #endif #if !(HAVE_MEMSET) # undef memset # define memset(a,b,c) lzo_memset(a,b,c) -#else +#elif !(__LZO_MMODEL_HUGE) # undef lzo_memset # define lzo_memset(a,b,c) memset(a,b,c) #endif @@ -3179,29 +2058,27 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) #endif +#if !defined(__lzo_inline) +# define __lzo_inline /*empty*/ +#endif +#if !defined(__lzo_forceinline) +# define __lzo_forceinline /*empty*/ +#endif +#if !defined(__lzo_noinline) +# define __lzo_noinline /*empty*/ +#endif + #if (LZO_CFG_PGO) +# undef __acc_likely +# undef __acc_unlikely # undef __lzo_likely # undef __lzo_unlikely +# define __acc_likely(e) (e) +# define __acc_unlikely(e) (e) # define __lzo_likely(e) (e) # define __lzo_unlikely(e) (e) #endif -#undef _ -#undef __ -#undef ___ -#undef ____ -#undef _p0 -#undef _p1 -#undef _p2 -#undef _p3 -#undef _p4 -#undef _s0 -#undef _s1 -#undef _s2 -#undef _s3 -#undef _s4 -#undef _ww - #if 1 # define LZO_BYTE(x) ((unsigned char) (x)) #else @@ -3220,548 +2097,84 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) #define LZO_SIZE(bits) (1u << (bits)) #define LZO_MASK(bits) (LZO_SIZE(bits) - 1) +#define LZO_LSIZE(bits) (1ul << (bits)) +#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) + #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) #if !defined(DMUL) #if 0 -# define DMUL(a,b) ((lzo_xint) ((lzo_uint32_t)(a) * (lzo_uint32_t)(b))) +# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) #else # define DMUL(a,b) ((lzo_xint) ((a) * (b))) #endif #endif -#ifndef __LZO_FUNC_H -#define __LZO_FUNC_H 1 - -#if !defined(LZO_BITOPS_USE_ASM_BITSCAN) && !defined(LZO_BITOPS_USE_GNUC_BITSCAN) && !defined(LZO_BITOPS_USE_MSC_BITSCAN) -#if 1 && (LZO_ARCH_AMD64) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_ASM_SYNTAX_GNUC) -#define LZO_BITOPS_USE_ASM_BITSCAN 1 -#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) -#define LZO_BITOPS_USE_GNUC_BITSCAN 1 -#elif (LZO_OS_WIN32 || LZO_OS_WIN64) && ((LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1010)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) -#define LZO_BITOPS_USE_MSC_BITSCAN 1 -#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -#include -#endif -#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) -#pragma intrinsic(_BitScanReverse) -#pragma intrinsic(_BitScanForward) -#endif -#if (LZO_CC_MSC) && (LZO_ARCH_AMD64) -#pragma intrinsic(_BitScanReverse64) -#pragma intrinsic(_BitScanForward64) +#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) +# if (LZO_SIZEOF_SHORT == 2) +# define LZO_UNALIGNED_OK_2 1 +# endif +# if (LZO_SIZEOF_INT == 4) +# define LZO_UNALIGNED_OK_4 1 +# endif #endif +#if 1 && (LZO_ARCH_AMD64) +# if defined(LZO_UINT64_MAX) +# define LZO_UNALIGNED_OK_8 1 +# endif #endif +#if (LZO_CFG_NO_UNALIGNED) +# undef LZO_UNALIGNED_OK_2 +# undef LZO_UNALIGNED_OK_4 +# undef LZO_UNALIGNED_OK_8 #endif -__lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v) -{ -#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) - unsigned long r; (void) _BitScanReverse(&r, v); return (unsigned) r ^ 31; -#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) -#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) - lzo_uint32_t r; - __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); - return (unsigned) r ^ 31; -#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4) - unsigned r; r = (unsigned) __builtin_clz(v); return r; -#define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v)) -#else - LZO_UNUSED(v); return 0; -#endif -} - -#if defined(lzo_uint64_t) -__lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v) -{ -#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) - unsigned long r; (void) _BitScanReverse64(&r, v); return (unsigned) r ^ 63; -#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) -#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) - lzo_uint64_t r; - __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); - return (unsigned) r ^ 63; -#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) - unsigned r; r = (unsigned) __builtin_clzl(v); return r; -#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v)) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8) - unsigned r; r = (unsigned) __builtin_clzll(v); return r; -#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v)) -#else - LZO_UNUSED(v); return 0; -#endif -} -#endif - -__lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v) -{ -#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) - unsigned long r; (void) _BitScanForward(&r, v); return (unsigned) r; -#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) -#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) - lzo_uint32_t r; - __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); - return (unsigned) r; -#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4) - unsigned r; r = (unsigned) __builtin_ctz(v); return r; -#define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v)) -#else - LZO_UNUSED(v); return 0; -#endif -} - -#if defined(lzo_uint64_t) -__lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v) -{ -#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) - unsigned long r; (void) _BitScanForward64(&r, v); return (unsigned) r; -#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) -#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) - lzo_uint64_t r; - __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); - return (unsigned) r; -#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8) - unsigned r; r = (unsigned) __builtin_ctzl(v); return r; -#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v)) -#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8) - unsigned r; r = (unsigned) __builtin_ctzll(v); return r; -#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v)) -#else - LZO_UNUSED(v); return 0; -#endif -} -#endif - -#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -static void __attribute__((__unused__)) -#else -__lzo_static_forceinline void -#endif -lzo_bitops_unused_funcs(void) -{ - LZO_UNUSED_FUNC(lzo_bitops_ctlz32_func); - LZO_UNUSED_FUNC(lzo_bitops_cttz32_func); -#if defined(lzo_uint64_t) - LZO_UNUSED_FUNC(lzo_bitops_ctlz64_func); - LZO_UNUSED_FUNC(lzo_bitops_cttz64_func); -#endif - LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); -} - -#if defined(__lzo_alignof) && !(LZO_CFG_NO_UNALIGNED) -#ifndef __lzo_memops_tcheck -#define __lzo_memops_tcheck(t,a,b) ((void)0, sizeof(t) == (a) && __lzo_alignof(t) == (b)) -#endif -#endif -#ifndef lzo_memops_TU0p -#define lzo_memops_TU0p void __LZO_MMODEL * -#endif -#ifndef lzo_memops_TU1p -#define lzo_memops_TU1p unsigned char __LZO_MMODEL * -#endif -#ifndef lzo_memops_TU2p -#if (LZO_OPT_UNALIGNED16) -typedef lzo_uint16_t __lzo_may_alias lzo_memops_TU2; -#define lzo_memops_TU2p volatile lzo_memops_TU2 * -#elif defined(__lzo_byte_struct) -__lzo_byte_struct(lzo_memops_TU2_struct,2) -typedef struct lzo_memops_TU2_struct lzo_memops_TU2; -#else -struct lzo_memops_TU2_struct { unsigned char a[2]; } __lzo_may_alias; -typedef struct lzo_memops_TU2_struct lzo_memops_TU2; -#endif -#ifndef lzo_memops_TU2p -#define lzo_memops_TU2p lzo_memops_TU2 * -#endif -#endif -#ifndef lzo_memops_TU4p -#if (LZO_OPT_UNALIGNED32) -typedef lzo_uint32_t __lzo_may_alias lzo_memops_TU4; -#define lzo_memops_TU4p volatile lzo_memops_TU4 __LZO_MMODEL * -#elif defined(__lzo_byte_struct) -__lzo_byte_struct(lzo_memops_TU4_struct,4) -typedef struct lzo_memops_TU4_struct lzo_memops_TU4; -#else -struct lzo_memops_TU4_struct { unsigned char a[4]; } __lzo_may_alias; -typedef struct lzo_memops_TU4_struct lzo_memops_TU4; -#endif -#ifndef lzo_memops_TU4p -#define lzo_memops_TU4p lzo_memops_TU4 __LZO_MMODEL * -#endif -#endif -#ifndef lzo_memops_TU8p -#if (LZO_OPT_UNALIGNED64) -typedef lzo_uint64_t __lzo_may_alias lzo_memops_TU8; -#define lzo_memops_TU8p volatile lzo_memops_TU8 __LZO_MMODEL * -#elif defined(__lzo_byte_struct) -__lzo_byte_struct(lzo_memops_TU8_struct,8) -typedef struct lzo_memops_TU8_struct lzo_memops_TU8; -#else -struct lzo_memops_TU8_struct { unsigned char a[8]; } __lzo_may_alias; -typedef struct lzo_memops_TU8_struct lzo_memops_TU8; -#endif -#ifndef lzo_memops_TU8p -#define lzo_memops_TU8p lzo_memops_TU8 __LZO_MMODEL * -#endif -#endif -#ifndef lzo_memops_set_TU1p -#define lzo_memops_set_TU1p volatile lzo_memops_TU1p -#endif -#ifndef lzo_memops_move_TU1p -#define lzo_memops_move_TU1p lzo_memops_TU1p -#endif -#define LZO_MEMOPS_SET1(dd,cc) \ - LZO_BLOCK_BEGIN \ - lzo_memops_set_TU1p d__1 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ - d__1[0] = LZO_BYTE(cc); \ - LZO_BLOCK_END -#define LZO_MEMOPS_SET2(dd,cc) \ - LZO_BLOCK_BEGIN \ - lzo_memops_set_TU1p d__2 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ - d__2[0] = LZO_BYTE(cc); d__2[1] = LZO_BYTE(cc); \ - LZO_BLOCK_END -#define LZO_MEMOPS_SET3(dd,cc) \ - LZO_BLOCK_BEGIN \ - lzo_memops_set_TU1p d__3 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ - d__3[0] = LZO_BYTE(cc); d__3[1] = LZO_BYTE(cc); d__3[2] = LZO_BYTE(cc); \ - LZO_BLOCK_END -#define LZO_MEMOPS_SET4(dd,cc) \ - LZO_BLOCK_BEGIN \ - lzo_memops_set_TU1p d__4 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ - d__4[0] = LZO_BYTE(cc); d__4[1] = LZO_BYTE(cc); d__4[2] = LZO_BYTE(cc); d__4[3] = LZO_BYTE(cc); \ - LZO_BLOCK_END -#define LZO_MEMOPS_MOVE1(dd,ss) \ - LZO_BLOCK_BEGIN \ - lzo_memops_move_TU1p d__1 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_move_TU1p s__1 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ - d__1[0] = s__1[0]; \ - LZO_BLOCK_END -#define LZO_MEMOPS_MOVE2(dd,ss) \ - LZO_BLOCK_BEGIN \ - lzo_memops_move_TU1p d__2 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_move_TU1p s__2 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ - d__2[0] = s__2[0]; d__2[1] = s__2[1]; \ - LZO_BLOCK_END -#define LZO_MEMOPS_MOVE3(dd,ss) \ - LZO_BLOCK_BEGIN \ - lzo_memops_move_TU1p d__3 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_move_TU1p s__3 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ - d__3[0] = s__3[0]; d__3[1] = s__3[1]; d__3[2] = s__3[2]; \ - LZO_BLOCK_END -#define LZO_MEMOPS_MOVE4(dd,ss) \ - LZO_BLOCK_BEGIN \ - lzo_memops_move_TU1p d__4 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_move_TU1p s__4 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ - d__4[0] = s__4[0]; d__4[1] = s__4[1]; d__4[2] = s__4[2]; d__4[3] = s__4[3]; \ - LZO_BLOCK_END -#define LZO_MEMOPS_MOVE8(dd,ss) \ - LZO_BLOCK_BEGIN \ - lzo_memops_move_TU1p d__8 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_move_TU1p s__8 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ - d__8[0] = s__8[0]; d__8[1] = s__8[1]; d__8[2] = s__8[2]; d__8[3] = s__8[3]; \ - d__8[4] = s__8[4]; d__8[5] = s__8[5]; d__8[6] = s__8[6]; d__8[7] = s__8[7]; \ - LZO_BLOCK_END -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU1p)0)==1) -#define LZO_MEMOPS_COPY1(dd,ss) LZO_MEMOPS_MOVE1(dd,ss) -#if (LZO_OPT_UNALIGNED16) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU2p)0)==2) -#define LZO_MEMOPS_COPY2(dd,ss) \ - * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) -#elif defined(__lzo_memops_tcheck) -#define LZO_MEMOPS_COPY2(dd,ss) \ - LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU2,2,1)) { \ - * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss); \ - } else { LZO_MEMOPS_MOVE2(dd,ss); } LZO_BLOCK_END -#else -#define LZO_MEMOPS_COPY2(dd,ss) LZO_MEMOPS_MOVE2(dd,ss) -#endif -#if (LZO_OPT_UNALIGNED32) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU4p)0)==4) -#define LZO_MEMOPS_COPY4(dd,ss) \ - * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -#elif defined(__lzo_memops_tcheck) -#define LZO_MEMOPS_COPY4(dd,ss) \ - LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU4,4,1)) { \ - * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss); \ - } else { LZO_MEMOPS_MOVE4(dd,ss); } LZO_BLOCK_END -#else -#define LZO_MEMOPS_COPY4(dd,ss) LZO_MEMOPS_MOVE4(dd,ss) -#endif -#if (LZO_WORDSIZE != 8) -#define LZO_MEMOPS_COPY8(dd,ss) \ - LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END -#else -#if (LZO_OPT_UNALIGNED64) -LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU8p)0)==8) -#define LZO_MEMOPS_COPY8(dd,ss) \ - * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) -#elif (LZO_OPT_UNALIGNED32) -#define LZO_MEMOPS_COPY8(dd,ss) \ - LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END -#elif defined(__lzo_memops_tcheck) -#define LZO_MEMOPS_COPY8(dd,ss) \ - LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU8,8,1)) { \ - * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss); \ - } else { LZO_MEMOPS_MOVE8(dd,ss); } LZO_BLOCK_END -#else -#define LZO_MEMOPS_COPY8(dd,ss) LZO_MEMOPS_MOVE8(dd,ss) -#endif -#endif -#define LZO_MEMOPS_COPYN(dd,ss,nn) \ - LZO_BLOCK_BEGIN \ - lzo_memops_TU1p d__n = (lzo_memops_TU1p) (lzo_memops_TU0p) (dd); \ - const lzo_memops_TU1p s__n = (const lzo_memops_TU1p) (const lzo_memops_TU0p) (ss); \ - lzo_uint n__n = (nn); \ - while ((void)0, n__n >= 8) { LZO_MEMOPS_COPY8(d__n, s__n); d__n += 8; s__n += 8; n__n -= 8; } \ - if ((void)0, n__n >= 4) { LZO_MEMOPS_COPY4(d__n, s__n); d__n += 4; s__n += 4; n__n -= 4; } \ - if ((void)0, n__n > 0) do { *d__n++ = *s__n++; } while (--n__n > 0); \ - LZO_BLOCK_END - -__lzo_static_forceinline lzo_uint16_t lzo_memops_get_le16(const lzo_voidp ss) -{ - lzo_uint16_t v; -#if (LZO_ABI_LITTLE_ENDIAN) - LZO_MEMOPS_COPY2(&v, ss); -#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) - const lzo_memops_TU2p s = (const lzo_memops_TU2p) ss; - unsigned long vv; - __asm__("lhbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); - v = (lzo_uint16_t) vv; -#else - const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; - v = (lzo_uint16_t) (((lzo_uint16_t)s[0]) | ((lzo_uint16_t)s[1] << 8)); -#endif - return v; -} -#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -#define LZO_MEMOPS_GET_LE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) -#else -#define LZO_MEMOPS_GET_LE16(ss) lzo_memops_get_le16(ss) -#endif - -__lzo_static_forceinline lzo_uint32_t lzo_memops_get_le32(const lzo_voidp ss) -{ - lzo_uint32_t v; -#if (LZO_ABI_LITTLE_ENDIAN) - LZO_MEMOPS_COPY4(&v, ss); -#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) - const lzo_memops_TU4p s = (const lzo_memops_TU4p) ss; - unsigned long vv; - __asm__("lwbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); - v = (lzo_uint32_t) vv; -#else - const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; - v = (lzo_uint32_t) (((lzo_uint32_t)s[0]) | ((lzo_uint32_t)s[1] << 8) | ((lzo_uint32_t)s[2] << 16) | ((lzo_uint32_t)s[3] << 24)); -#endif - return v; -} -#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) -#define LZO_MEMOPS_GET_LE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -#else -#define LZO_MEMOPS_GET_LE32(ss) lzo_memops_get_le32(ss) -#endif - -#if (LZO_OPT_UNALIGNED64) && (LZO_ABI_LITTLE_ENDIAN) -#define LZO_MEMOPS_GET_LE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) -#endif - -__lzo_static_forceinline lzo_uint16_t lzo_memops_get_ne16(const lzo_voidp ss) -{ - lzo_uint16_t v; - LZO_MEMOPS_COPY2(&v, ss); - return v; -} -#if (LZO_OPT_UNALIGNED16) -#define LZO_MEMOPS_GET_NE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) -#else -#define LZO_MEMOPS_GET_NE16(ss) lzo_memops_get_ne16(ss) -#endif - -__lzo_static_forceinline lzo_uint32_t lzo_memops_get_ne32(const lzo_voidp ss) -{ - lzo_uint32_t v; - LZO_MEMOPS_COPY4(&v, ss); - return v; -} -#if (LZO_OPT_UNALIGNED32) -#define LZO_MEMOPS_GET_NE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) -#else -#define LZO_MEMOPS_GET_NE32(ss) lzo_memops_get_ne32(ss) -#endif - -#if (LZO_OPT_UNALIGNED64) -#define LZO_MEMOPS_GET_NE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) -#endif - -__lzo_static_forceinline void lzo_memops_put_le16(lzo_voidp dd, lzo_uint16_t vv) -{ -#if (LZO_ABI_LITTLE_ENDIAN) - LZO_MEMOPS_COPY2(dd, &vv); -#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) - lzo_memops_TU2p d = (lzo_memops_TU2p) dd; - unsigned long v = vv; - __asm__("sthbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); -#else - lzo_memops_TU1p d = (lzo_memops_TU1p) dd; - d[0] = LZO_BYTE((vv ) & 0xff); - d[1] = LZO_BYTE((vv >> 8) & 0xff); -#endif -} -#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) -#define LZO_MEMOPS_PUT_LE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) -#else -#define LZO_MEMOPS_PUT_LE16(dd,vv) lzo_memops_put_le16(dd,vv) -#endif - -__lzo_static_forceinline void lzo_memops_put_le32(lzo_voidp dd, lzo_uint32_t vv) -{ -#if (LZO_ABI_LITTLE_ENDIAN) - LZO_MEMOPS_COPY4(dd, &vv); -#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) - lzo_memops_TU4p d = (lzo_memops_TU4p) dd; - unsigned long v = vv; - __asm__("stwbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); -#else - lzo_memops_TU1p d = (lzo_memops_TU1p) dd; - d[0] = LZO_BYTE((vv ) & 0xff); - d[1] = LZO_BYTE((vv >> 8) & 0xff); - d[2] = LZO_BYTE((vv >> 16) & 0xff); - d[3] = LZO_BYTE((vv >> 24) & 0xff); -#endif -} -#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) -#define LZO_MEMOPS_PUT_LE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) -#else -#define LZO_MEMOPS_PUT_LE32(dd,vv) lzo_memops_put_le32(dd,vv) -#endif - -__lzo_static_forceinline void lzo_memops_put_ne16(lzo_voidp dd, lzo_uint16_t vv) -{ - LZO_MEMOPS_COPY2(dd, &vv); -} -#if (LZO_OPT_UNALIGNED16) -#define LZO_MEMOPS_PUT_NE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) -#else -#define LZO_MEMOPS_PUT_NE16(dd,vv) lzo_memops_put_ne16(dd,vv) -#endif - -__lzo_static_forceinline void lzo_memops_put_ne32(lzo_voidp dd, lzo_uint32_t vv) -{ - LZO_MEMOPS_COPY4(dd, &vv); -} -#if (LZO_OPT_UNALIGNED32) -#define LZO_MEMOPS_PUT_NE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) -#else -#define LZO_MEMOPS_PUT_NE32(dd,vv) lzo_memops_put_ne32(dd,vv) -#endif - -#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -static void __attribute__((__unused__)) -#else -__lzo_static_forceinline void -#endif -lzo_memops_unused_funcs(void) -{ - LZO_UNUSED_FUNC(lzo_memops_get_le16); - LZO_UNUSED_FUNC(lzo_memops_get_le32); - LZO_UNUSED_FUNC(lzo_memops_get_ne16); - LZO_UNUSED_FUNC(lzo_memops_get_ne32); - LZO_UNUSED_FUNC(lzo_memops_put_le16); - LZO_UNUSED_FUNC(lzo_memops_put_le32); - LZO_UNUSED_FUNC(lzo_memops_put_ne16); - LZO_UNUSED_FUNC(lzo_memops_put_ne32); - LZO_UNUSED_FUNC(lzo_memops_unused_funcs); -} - -#endif - -#ifndef UA_SET1 -#define UA_SET1 LZO_MEMOPS_SET1 -#endif -#ifndef UA_SET2 -#define UA_SET2 LZO_MEMOPS_SET2 -#endif -#ifndef UA_SET3 -#define UA_SET3 LZO_MEMOPS_SET3 -#endif -#ifndef UA_SET4 -#define UA_SET4 LZO_MEMOPS_SET4 -#endif -#ifndef UA_MOVE1 -#define UA_MOVE1 LZO_MEMOPS_MOVE1 -#endif -#ifndef UA_MOVE2 -#define UA_MOVE2 LZO_MEMOPS_MOVE2 -#endif -#ifndef UA_MOVE3 -#define UA_MOVE3 LZO_MEMOPS_MOVE3 -#endif -#ifndef UA_MOVE4 -#define UA_MOVE4 LZO_MEMOPS_MOVE4 -#endif -#ifndef UA_MOVE8 -#define UA_MOVE8 LZO_MEMOPS_MOVE8 -#endif -#ifndef UA_COPY1 -#define UA_COPY1 LZO_MEMOPS_COPY1 -#endif -#ifndef UA_COPY2 -#define UA_COPY2 LZO_MEMOPS_COPY2 -#endif -#ifndef UA_COPY3 -#define UA_COPY3 LZO_MEMOPS_COPY3 -#endif -#ifndef UA_COPY4 -#define UA_COPY4 LZO_MEMOPS_COPY4 -#endif -#ifndef UA_COPY8 -#define UA_COPY8 LZO_MEMOPS_COPY8 -#endif -#ifndef UA_COPYN -#define UA_COPYN LZO_MEMOPS_COPYN -#endif -#ifndef UA_COPYN_X -#define UA_COPYN_X LZO_MEMOPS_COPYN -#endif -#ifndef UA_GET_LE16 -#define UA_GET_LE16 LZO_MEMOPS_GET_LE16 -#endif -#ifndef UA_GET_LE32 -#define UA_GET_LE32 LZO_MEMOPS_GET_LE32 -#endif -#ifdef LZO_MEMOPS_GET_LE64 -#ifndef UA_GET_LE64 -#define UA_GET_LE64 LZO_MEMOPS_GET_LE64 -#endif -#endif -#ifndef UA_GET_NE16 -#define UA_GET_NE16 LZO_MEMOPS_GET_NE16 -#endif -#ifndef UA_GET_NE32 -#define UA_GET_NE32 LZO_MEMOPS_GET_NE32 -#endif -#ifdef LZO_MEMOPS_GET_NE64 -#ifndef UA_GET_NE64 -#define UA_GET_NE64 LZO_MEMOPS_GET_NE64 -#endif -#endif -#ifndef UA_PUT_LE16 -#define UA_PUT_LE16 LZO_MEMOPS_PUT_LE16 -#endif -#ifndef UA_PUT_LE32 -#define UA_PUT_LE32 LZO_MEMOPS_PUT_LE32 -#endif -#ifndef UA_PUT_NE16 -#define UA_PUT_NE16 LZO_MEMOPS_PUT_NE16 -#endif -#ifndef UA_PUT_NE32 -#define UA_PUT_NE32 LZO_MEMOPS_PUT_NE32 +#undef UA_GET16 +#undef UA_SET16 +#undef UA_COPY16 +#undef UA_GET32 +#undef UA_SET32 +#undef UA_COPY32 +#undef UA_GET64 +#undef UA_SET64 +#undef UA_COPY64 +#if defined(LZO_UNALIGNED_OK_2) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2) +# if 1 && defined(ACC_UA_COPY16) +# define UA_GET16 ACC_UA_GET16 +# define UA_SET16 ACC_UA_SET16 +# define UA_COPY16 ACC_UA_COPY16 +# else +# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) +# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) +# endif +#endif +#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) +# if 1 && defined(ACC_UA_COPY32) +# define UA_GET32 ACC_UA_GET32 +# define UA_SET32 ACC_UA_SET32 +# define UA_COPY32 ACC_UA_COPY32 +# else +# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) +# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) +# endif +#endif +#if defined(LZO_UNALIGNED_OK_8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8) +# if 1 && defined(ACC_UA_COPY64) +# define UA_GET64 ACC_UA_GET64 +# define UA_SET64 ACC_UA_SET64 +# define UA_COPY64 ACC_UA_COPY64 +# else +# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) +# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) +# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) +# endif #endif #define MEMCPY8_DS(dest,src,len) \ @@ -3782,10 +2195,25 @@ LZO_EXTERN(const lzo_bytep) lzo_copyright(void); extern "C" { #endif +#if !defined(lzo_uintptr_t) +# if (__LZO_MMODEL_HUGE) +# define lzo_uintptr_t unsigned long +# else +# define lzo_uintptr_t acc_uintptr_t +# ifdef __ACC_INTPTR_T_IS_POINTER +# define __LZO_UINTPTR_T_IS_POINTER 1 +# endif +# endif +#endif + #if (LZO_ARCH_I086) -#error "LZO_ARCH_I086 is unsupported" +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) +#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) #elif (LZO_MM_PVP) -#error "LZO_MM_PVP is unsupported" +#define PTR(a) ((lzo_bytep) (a)) +#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) +#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) #else #define PTR(a) ((lzo_uintptr_t) (a)) #define PTR_LINEAR(a) PTR(a) @@ -3815,28 +2243,24 @@ typedef union unsigned long a_ulong; lzo_int a_lzo_int; lzo_uint a_lzo_uint; - lzo_xint a_lzo_xint; - lzo_int16_t a_lzo_int16_t; - lzo_uint16_t a_lzo_uint16_t; - lzo_int32_t a_lzo_int32_t; - lzo_uint32_t a_lzo_uint32_t; -#if defined(lzo_uint64_t) - lzo_int64_t a_lzo_int64_t; - lzo_uint64_t a_lzo_uint64_t; + lzo_int32 a_lzo_int32; + lzo_uint32 a_lzo_uint32; +#if defined(LZO_UINT64_MAX) + lzo_int64 a_lzo_int64; + lzo_uint64 a_lzo_uint64; #endif - size_t a_size_t; ptrdiff_t a_ptrdiff_t; lzo_uintptr_t a_lzo_uintptr_t; - void * a_void_p; - char * a_char_p; - unsigned char * a_uchar_p; - const void * a_c_void_p; - const char * a_c_char_p; - const unsigned char * a_c_uchar_p; lzo_voidp a_lzo_voidp; + void * a_void_p; lzo_bytep a_lzo_bytep; - const lzo_voidp a_c_lzo_voidp; - const lzo_bytep a_c_lzo_bytep; + lzo_bytepp a_lzo_bytepp; + lzo_uintp a_lzo_uintp; + lzo_uint * a_lzo_uint_p; + lzo_uint32p a_lzo_uint32p; + lzo_uint32 * a_lzo_uint32_p; + unsigned char * a_uchar_p; + char * a_char_p; } lzo_full_align_t; @@ -3852,14 +2276,18 @@ lzo_full_align_t; #ifndef LZO_DICT_USE_PTR #define LZO_DICT_USE_PTR 1 +#if 0 && (LZO_ARCH_I086) +# undef LZO_DICT_USE_PTR +# define LZO_DICT_USE_PTR 0 +#endif #endif #if (LZO_DICT_USE_PTR) # define lzo_dict_t const lzo_bytep -# define lzo_dict_p lzo_dict_t * +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * #else # define lzo_dict_t lzo_uint -# define lzo_dict_p lzo_dict_t * +# define lzo_dict_p lzo_dict_t __LZO_MMODEL * #endif #endif @@ -3872,9 +2300,10 @@ __lzo_ptr_linear(const lzo_voidp ptr) lzo_uintptr_t p; #if (LZO_ARCH_I086) -#error "LZO_ARCH_I086 is unsupported" + p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); #elif (LZO_MM_PVP) -#error "LZO_MM_PVP is unsupported" + p = (lzo_uintptr_t) (ptr); + p = (p << 3) | (p >> 61); #else p = (lzo_uintptr_t) PTR_LINEAR(ptr); #endif @@ -3885,8 +2314,9 @@ __lzo_ptr_linear(const lzo_voidp ptr) LZO_PUBLIC(unsigned) __lzo_align_gap(const lzo_voidp ptr, lzo_uint size) { -#if (__LZO_UINTPTR_T_IS_POINTER) -#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" +#if defined(__LZO_UINTPTR_T_IS_POINTER) + size_t n = (size_t) ptr; + n = (((n + size - 1) / size) * size) - n; #else lzo_uintptr_t p, n; p = __lzo_ptr_linear(ptr); @@ -3912,7 +2342,7 @@ static const char __lzo_copyright[] = #else "\r\n\n" "LZO data compression library.\n" - "$Copyright: LZO Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer\n" + "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" "\n" "http://www.oberhumer.com $\n\n" "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" @@ -3922,7 +2352,11 @@ static const char __lzo_copyright[] = LZO_PUBLIC(const lzo_bytep) lzo_copyright(void) { +#if (LZO_OS_DOS16 && LZO_CC_TURBOC) + return (lzo_voidp) __lzo_copyright; +#else return (const lzo_bytep) __lzo_copyright; +#endif } LZO_PUBLIC(unsigned) @@ -3959,16 +2393,16 @@ _lzo_version_date(void) #define LZO_NMAX 5552 #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 -#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1) -#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2) -#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4) -#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8) +#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); +#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); +#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); +#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); -LZO_PUBLIC(lzo_uint32_t) -lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) +LZO_PUBLIC(lzo_uint32) +lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) { - lzo_uint32_t s1 = adler & 0xffff; - lzo_uint32_t s2 = (adler >> 16) & 0xffff; + lzo_uint32 s1 = adler & 0xffff; + lzo_uint32 s2 = (adler >> 16) & 0xffff; unsigned k; if (buf == NULL) @@ -4025,8 +2459,8 @@ lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) - const lzo_hbyte_p p1 = LZO_STATIC_CAST(const lzo_hbyte_p, s1); - const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, s2); + const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; if __lzo_likely(len > 0) do { int d = *p1 - *p2; @@ -4042,8 +2476,8 @@ LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) - lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); - const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; if (!(len > 0) || p1 == p2) return dest; do @@ -4057,8 +2491,8 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) - lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); - const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); + lzo_hbyte_p p1 = (lzo_hbyte_p) dest; + const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; if (!(len > 0) || p1 == p2) return dest; if (p1 < p2) @@ -4080,17 +2514,16 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p sr return memmove(dest, src, len); #endif } -LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int cc, lzo_hsize_t len) +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) - lzo_hbyte_p p = LZO_STATIC_CAST(lzo_hbyte_p, s); - unsigned char c = LZO_ITRUNC(unsigned char, cc); + lzo_hbyte_p p = (lzo_hbyte_p) s; if __lzo_likely(len > 0) do - *p++ = c; + *p++ = (unsigned char) c; while __lzo_likely(--len > 0); return s; #else - return memset(s, cc, len); + return memset(s, c, len); #endif } #undef LZOLIB_PUBLIC @@ -4099,28 +2532,105 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int cc, lzo_hsize_t len) #if !defined(__LZO_IN_MINILZO) -#define LZO_WANT_ACC_CHK_CH 1 -#undef LZOCHK_ASSERT +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT - LZOCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) - LZOCHK_ASSERT_IS_SIGNED_T(lzo_int) - LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) -#if !(__LZO_UINTPTR_T_IS_POINTER) - LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) + + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) + ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) + ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) +#if defined(LZO_UINT64_MAX) + ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) + ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) #endif - LZOCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) - LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) + +#if !defined(__LZO_UINTPTR_T_IS_POINTER) + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) +#endif + ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + + ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) + ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) + ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) #endif -#undef LZOCHK_ASSERT +#undef ACCCHK_ASSERT -union lzo_config_check_union { - lzo_uint a[2]; - unsigned char b[2*LZO_MAX(8,sizeof(lzo_uint))]; -#if defined(lzo_uint64_t) - lzo_uint64_t c[2]; +#if 0 +#define WANT_lzo_bitops_clz32 1 +#define WANT_lzo_bitops_clz64 1 +#endif +#define WANT_lzo_bitops_ctz32 1 +#define WANT_lzo_bitops_ctz64 1 + +#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +#include +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +#pragma intrinsic(_BitScanReverse) +static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanReverse(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz32 lzo_bitops_clz32 +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +#pragma intrinsic(_BitScanReverse64) +static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanReverse64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz64 lzo_bitops_clz64 +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#pragma intrinsic(_BitScanForward) +static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanForward(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz32 lzo_bitops_ctz32 +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#pragma intrinsic(_BitScanForward64) +static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanForward64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz64 lzo_bitops_ctz64 +#endif + +#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +#endif #endif -}; #if 0 #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) @@ -4134,101 +2644,73 @@ static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off) LZO_PUBLIC(int) _lzo_config_check(void) { -#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030100ul && LZO_CC_CLANG < 0x030300ul)) -# if 0 - volatile -# endif + lzo_bool r = 1; + union { + lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))]; +#if defined(LZO_UNALIGNED_OK_8) + lzo_uint64 c[2]; #endif - union lzo_config_check_union u; + unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; + } u; lzo_voidp p; - unsigned r = 1; u.a[0] = u.a[1] = 0; p = u2p(&u, 0); r &= ((* (lzo_bytep) p) == 0); -#if !(LZO_CFG_NO_CONFIG_CHECK) -#if (LZO_ABI_BIG_ENDIAN) +#if !defined(LZO_CFG_NO_CONFIG_CHECK) +#if defined(LZO_ABI_BIG_ENDIAN) u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; p = u2p(&u, 0); r &= ((* (lzo_uintp) p) == 128); #endif -#if (LZO_ABI_LITTLE_ENDIAN) +#if defined(LZO_ABI_LITTLE_ENDIAN) u.a[0] = u.a[1] = 0; u.b[0] = 128; p = u2p(&u, 0); r &= ((* (lzo_uintp) p) == 128); #endif +#if defined(LZO_UNALIGNED_OK_2) u.a[0] = u.a[1] = 0; - u.b[0] = 1; u.b[3] = 2; + u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; p = u2p(&u, 1); - r &= UA_GET_NE16(p) == 0; - r &= UA_GET_LE16(p) == 0; - u.b[1] = 128; - r &= UA_GET_LE16(p) == 128; - u.b[2] = 129; - r &= UA_GET_LE16(p) == LZO_UINT16_C(0x8180); -#if (LZO_ABI_BIG_ENDIAN) - r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8081); -#endif -#if (LZO_ABI_LITTLE_ENDIAN) - r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180); + r &= ((* (lzo_ushortp) p) == 0); #endif +#if defined(LZO_UNALIGNED_OK_4) u.a[0] = u.a[1] = 0; - u.b[0] = 3; u.b[5] = 4; + u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; p = u2p(&u, 1); - r &= UA_GET_NE32(p) == 0; - r &= UA_GET_LE32(p) == 0; - u.b[1] = 128; - r &= UA_GET_LE32(p) == 128; - u.b[2] = 129; u.b[3] = 130; u.b[4] = 131; - r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180); -#if (LZO_ABI_BIG_ENDIAN) - r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283); + r &= ((* (lzo_uint32p) p) == 0); #endif -#if (LZO_ABI_LITTLE_ENDIAN) - r &= UA_GET_NE32(p) == LZO_UINT32_C(0x83828180); -#endif -#if defined(UA_GET_NE64) +#if defined(LZO_UNALIGNED_OK_8) u.c[0] = u.c[1] = 0; - u.b[0] = 5; u.b[9] = 6; + u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; p = u2p(&u, 1); - u.c[0] = u.c[1] = 0; - r &= UA_GET_NE64(p) == 0; -#if defined(UA_GET_LE64) - r &= UA_GET_LE64(p) == 0; - u.b[1] = 128; - r &= UA_GET_LE64(p) == 128; + r &= ((* (lzo_uint64p) p) == 0); +#endif +#if defined(lzo_bitops_clz32) + { unsigned i; lzo_uint32 v = 1; + for (i = 0; i < 31; i++, v <<= 1) + r &= lzo_bitops_clz32(v) == 31 - i; + } +#endif +#if defined(lzo_bitops_clz64) + { unsigned i; lzo_uint64 v = 1; + for (i = 0; i < 63; i++, v <<= 1) + r &= lzo_bitops_clz64(v) == 63 - i; + } +#endif +#if defined(lzo_bitops_ctz32) + { unsigned i; lzo_uint32 v = 1; + for (i = 0; i < 31; i++, v <<= 1) + r &= lzo_bitops_ctz32(v) == i; + } +#endif +#if defined(lzo_bitops_ctz64) + { unsigned i; lzo_uint64 v = 1; + for (i = 0; i < 63; i++, v <<= 1) + r &= lzo_bitops_ctz64(v) == i; + } #endif #endif -#if defined(lzo_bitops_ctlz32) - { unsigned i = 0; lzo_uint32_t v; - for (v = 1; v != 0 && r == 1; v <<= 1, i++) { - r &= lzo_bitops_ctlz32(v) == 31 - i; - r &= lzo_bitops_ctlz32_func(v) == 31 - i; - }} -#endif -#if defined(lzo_bitops_ctlz64) - { unsigned i = 0; lzo_uint64_t v; - for (v = 1; v != 0 && r == 1; v <<= 1, i++) { - r &= lzo_bitops_ctlz64(v) == 63 - i; - r &= lzo_bitops_ctlz64_func(v) == 63 - i; - }} -#endif -#if defined(lzo_bitops_cttz32) - { unsigned i = 0; lzo_uint32_t v; - for (v = 1; v != 0 && r == 1; v <<= 1, i++) { - r &= lzo_bitops_cttz32(v) == i; - r &= lzo_bitops_cttz32_func(v) == i; - }} -#endif -#if defined(lzo_bitops_cttz64) - { unsigned i = 0; lzo_uint64_t v; - for (v = 1; v != 0 && r == 1; v <<= 1, i++) { - r &= lzo_bitops_cttz64(v) == i; - r &= lzo_bitops_cttz64_func(v) == i; - }} -#endif -#endif - LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); return r == 1 ? LZO_E_OK : LZO_E_ERROR; } @@ -4242,11 +2724,11 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, #if defined(__LZO_IN_MINILZO) #elif (LZO_CC_MSC && ((_MSC_VER) < 700)) #else -#define LZO_WANT_ACC_CHK_CH 1 -#undef LZOCHK_ASSERT -#define LZOCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) +#define ACC_WANT_ACC_CHK_CH 1 +#undef ACCCHK_ASSERT +#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) #endif -#undef LZOCHK_ASSERT +#undef ACCCHK_ASSERT if (v == 0) return LZO_E_ERROR; @@ -4254,7 +2736,7 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, r = (s1 == -1 || s1 == (int) sizeof(short)) && (s2 == -1 || s2 == (int) sizeof(int)) && (s3 == -1 || s3 == (int) sizeof(long)) && - (s4 == -1 || s4 == (int) sizeof(lzo_uint32_t)) && + (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && (s7 == -1 || s7 == (int) sizeof(char *)) && @@ -4297,11 +2779,11 @@ int __far __pascal LibMain ( int a, short b, short c, long d ) #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) -#if 1 && defined(UA_GET_LE32) +#if 1 && defined(UA_GET32) #undef LZO_DICT_USE_PTR #define LZO_DICT_USE_PTR 0 #undef lzo_dict_t -#define lzo_dict_t lzo_uint16_t +#define lzo_dict_t unsigned short #endif #define LZO_NEED_DICT_H 1 @@ -4606,7 +3088,77 @@ DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) #endif #if 1 && defined(DO_COMPRESS) && !defined(do_compress) -# define do_compress LZO_PP_ECONCAT2(DO_COMPRESS,_core) +# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) +#endif + +#if defined(UA_GET64) +# define WANT_lzo_bitops_ctz64 1 +#elif defined(UA_GET32) +# define WANT_lzo_bitops_ctz32 1 +#endif + +#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +#include +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +#pragma intrinsic(_BitScanReverse) +static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanReverse(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz32 lzo_bitops_clz32 +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +#pragma intrinsic(_BitScanReverse64) +static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanReverse64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_clz64 lzo_bitops_clz64 +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#pragma intrinsic(_BitScanForward) +static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +{ + unsigned long r; + (void) _BitScanForward(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz32 lzo_bitops_ctz32 +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#pragma intrinsic(_BitScanForward64) +static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +{ + unsigned long r; + (void) _BitScanForward64(&r, v); + return (unsigned) r; +} +#define lzo_bitops_ctz64 lzo_bitops_ctz64 +#endif + +#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +#endif +#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +#endif +#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +#endif +#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +#endif +#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +#endif #endif static __lzo_noinline lzo_uint @@ -4614,7 +3166,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, lzo_bytep out, lzo_uintp out_len, lzo_uint ti, lzo_voidp wrkmem) { - const lzo_bytep ip; + register const lzo_bytep ip; lzo_bytep op; const lzo_bytep const in_end = in + in_len; const lzo_bytep const ip_end = in + in_len - 20; @@ -4623,7 +3175,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, op = out; ip = in; - ii = ip; + ii = ip - ti; ip += ti < 4 ? 4 - ti : 0; for (;;) @@ -4653,8 +3205,8 @@ next: goto literal; try_match: -#if (LZO_OPT_UNALIGNED32) - if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip)) +#if defined(UA_GET32) + if (UA_GET32(m_pos) != UA_GET32(ip)) #else if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) #endif @@ -4669,43 +3221,49 @@ literal: lzo_uint m_off; lzo_uint m_len; { - lzo_uint32_t dv; + lzo_uint32 dv; lzo_uint dindex; literal: ip += 1 + ((ip - ii) >> 5); next: if __lzo_unlikely(ip >= ip_end) break; - dv = UA_GET_LE32(ip); + dv = UA_GET32(ip); dindex = DINDEX(dv,ip); GINDEX(m_off,m_pos,in+dict,dindex,in); UPDATE_I(dict,0,dindex,ip,in); - if __lzo_unlikely(dv != UA_GET_LE32(m_pos)) + if __lzo_unlikely(dv != UA_GET32(m_pos)) goto literal; } #endif - ii -= ti; ti = 0; { - lzo_uint t = pd(ip,ii); + register lzo_uint t = pd(ip,ii); if (t != 0) { if (t <= 3) { - op[-2] = LZO_BYTE(op[-2] | t); -#if (LZO_OPT_UNALIGNED32) - UA_COPY4(op, ii); + op[-2] |= LZO_BYTE(t); +#if defined(UA_COPY32) + UA_COPY32(op, ii); op += t; #else { do *op++ = *ii++; while (--t > 0); } #endif } -#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) +#if defined(UA_COPY32) || defined(UA_COPY64) else if (t <= 16) { *op++ = LZO_BYTE(t - 3); - UA_COPY8(op, ii); - UA_COPY8(op+8, ii+8); +#if defined(UA_COPY64) + UA_COPY64(op, ii); + UA_COPY64(op+8, ii+8); +#else + UA_COPY32(op, ii); + UA_COPY32(op+4, ii+4); + UA_COPY32(op+8, ii+8); + UA_COPY32(op+12, ii+12); +#endif op += t; } #endif @@ -4715,21 +3273,31 @@ next: *op++ = LZO_BYTE(t - 3); else { - lzo_uint tt = t - 18; + register lzo_uint tt = t - 18; *op++ = 0; while __lzo_unlikely(tt > 255) { tt -= 255; - UA_SET1(op, 0); - op++; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif } assert(tt > 0); *op++ = LZO_BYTE(tt); } -#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) +#if defined(UA_COPY32) || defined(UA_COPY64) do { - UA_COPY8(op, ii); - UA_COPY8(op+8, ii+8); +#if defined(UA_COPY64) + UA_COPY64(op, ii); + UA_COPY64(op+8, ii+8); +#else + UA_COPY32(op, ii); + UA_COPY32(op+4, ii+4); + UA_COPY32(op+8, ii+8); + UA_COPY32(op+12, ii+12); +#endif op += 16; ii += 16; t -= 16; } while (t >= 16); if (t > 0) #endif @@ -4739,26 +3307,19 @@ next: } m_len = 4; { -#if (LZO_OPT_UNALIGNED64) - lzo_uint64_t v; - v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); +#if defined(UA_GET64) + lzo_uint64 v; + v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); if __lzo_unlikely(v == 0) { do { m_len += 8; - v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); + v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); if __lzo_unlikely(ip + m_len >= ip_end) goto m_len_done; } while (v == 0); } -#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64) - m_len += lzo_bitops_ctlz64(v) / CHAR_BIT; -#elif (LZO_ABI_BIG_ENDIAN) - if ((v >> (64 - CHAR_BIT)) == 0) do { - v <<= CHAR_BIT; - m_len += 1; - } while ((v >> (64 - CHAR_BIT)) == 0); -#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64) - m_len += lzo_bitops_cttz64(v) / CHAR_BIT; +#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) + m_len += lzo_bitops_ctz64(v) / CHAR_BIT; #elif (LZO_ABI_LITTLE_ENDIAN) if ((v & UCHAR_MAX) == 0) do { v >>= CHAR_BIT; @@ -4769,30 +3330,19 @@ next: m_len += 1; } while (ip[m_len] == m_pos[m_len]); #endif -#elif (LZO_OPT_UNALIGNED32) - lzo_uint32_t v; - v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); +#elif defined(UA_GET32) + lzo_uint32 v; + v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); if __lzo_unlikely(v == 0) { do { m_len += 4; - v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); - if (v != 0) - break; - m_len += 4; - v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); if __lzo_unlikely(ip + m_len >= ip_end) goto m_len_done; } while (v == 0); } -#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32) - m_len += lzo_bitops_ctlz32(v) / CHAR_BIT; -#elif (LZO_ABI_BIG_ENDIAN) - if ((v >> (32 - CHAR_BIT)) == 0) do { - v <<= CHAR_BIT; - m_len += 1; - } while ((v >> (32 - CHAR_BIT)) == 0); -#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32) - m_len += lzo_bitops_cttz32(v) / CHAR_BIT; +#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) + m_len += lzo_bitops_ctz32(v) / CHAR_BIT; #elif (LZO_ABI_LITTLE_ENDIAN) if ((v & UCHAR_MAX) == 0) do { v >>= CHAR_BIT; @@ -4807,27 +3357,6 @@ next: if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { do { m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; - if (ip[m_len] != m_pos[m_len]) - break; - m_len += 1; if __lzo_unlikely(ip + m_len >= ip_end) goto m_len_done; } while (ip[m_len] == m_pos[m_len]); @@ -4861,8 +3390,11 @@ m_len_done: while __lzo_unlikely(m_len > 255) { m_len -= 255; - UA_SET1(op, 0); - op++; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif } *op++ = LZO_BYTE(m_len); } @@ -4881,8 +3413,11 @@ m_len_done: while __lzo_unlikely(m_len > 255) { m_len -= 255; - UA_SET1(op, 0); - op++; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif } *op++ = LZO_BYTE(m_len); } @@ -4893,7 +3428,7 @@ m_len_done: } *out_len = pd(op, out); - return pd(in_end,ii-ti); + return pd(in_end,ii); } LZO_PUBLIC(int) @@ -4933,7 +3468,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, if (op == out && t <= 238) *op++ = LZO_BYTE(17 + t); else if (t <= 3) - op[-2] = LZO_BYTE(op[-2] | t); + op[-2] |= LZO_BYTE(t); else if (t <= 18) *op++ = LZO_BYTE(t - 3); else @@ -4944,14 +3479,17 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, while (tt > 255) { tt -= 255; - UA_SET1(op, 0); - op++; +#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) + + * (volatile unsigned char *) op++ = 0; +#else + *op++ = 0; +#endif } assert(tt > 0); *op++ = LZO_BYTE(tt); } - UA_COPYN(op, ii, t); - op += t; + do *op++ = *ii++; while (--t > 0); } *op++ = M4_MARKER | 1; @@ -4988,13 +3526,10 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, #undef TEST_IP #undef TEST_OP -#undef TEST_IP_AND_TEST_OP #undef TEST_LB #undef TEST_LBO #undef NEED_IP #undef NEED_OP -#undef TEST_IV -#undef TEST_OV #undef HAVE_TEST_IP #undef HAVE_TEST_OP #undef HAVE_NEED_IP @@ -5009,7 +3544,6 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, # if (LZO_TEST_OVERRUN_INPUT >= 2) # define NEED_IP(x) \ if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun -# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun # endif #endif @@ -5021,13 +3555,12 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, # undef TEST_OP # define NEED_OP(x) \ if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun -# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun # endif #endif #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) -# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun -# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun #else # define TEST_LB(m_pos) ((void) 0) # define TEST_LBO(m_pos,o) ((void) 0) @@ -5048,27 +3581,15 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, # define TEST_OP 1 #endif -#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) -# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) -#elif defined(HAVE_TEST_IP) -# define TEST_IP_AND_TEST_OP TEST_IP -#elif defined(HAVE_TEST_OP) -# define TEST_IP_AND_TEST_OP TEST_OP -#else -# define TEST_IP_AND_TEST_OP 1 -#endif - #if defined(NEED_IP) # define HAVE_NEED_IP 1 #else # define NEED_IP(x) ((void) 0) -# define TEST_IV(x) ((void) 0) #endif #if defined(NEED_OP) # define HAVE_NEED_OP 1 #else # define NEED_OP(x) ((void) 0) -# define TEST_OV(x) ((void) 0) #endif #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) @@ -5085,14 +3606,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, lzo_voidp wrkmem ) #endif { - lzo_bytep op; - const lzo_bytep ip; - lzo_uint t; + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; #if defined(COPY_DICT) lzo_uint m_off; const lzo_bytep dict_end; #else - const lzo_bytep m_pos; + register const lzo_bytep m_pos; #endif const lzo_bytep const ip_end = in + in_len; @@ -5127,45 +3648,43 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, op = out; ip = in; - NEED_IP(1); if (*ip > 17) { t = *ip++ - 17; if (t < 4) goto match_next; - assert(t > 0); NEED_OP(t); NEED_IP(t+3); + assert(t > 0); NEED_OP(t); NEED_IP(t+1); do *op++ = *ip++; while (--t > 0); goto first_literal_run; } - for (;;) + while (TEST_IP && TEST_OP) { - NEED_IP(3); t = *ip++; if (t >= 16) goto match; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_IV(t); NEED_IP(1); } t += 15 + *ip++; } - assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); -#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) t += 3; if (t >= 8) do { - UA_COPY8(op,ip); + UA_COPY64(op,ip); op += 8; ip += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; t -= 4; } if (t > 0) @@ -5173,19 +3692,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, *op++ = *ip++; if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } } -#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -#if !(LZO_OPT_UNALIGNED32) +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) if (PTR_ALIGNED2_4(op,ip)) { #endif - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; if (--t > 0) { if (t >= 4) { do { - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *ip++; while (--t > 0); @@ -5193,12 +3712,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, else do *op++ = *ip++; while (--t > 0); } -#if !(LZO_OPT_UNALIGNED32) +#if !defined(LZO_UNALIGNED_OK_4) } else #endif #endif -#if !(LZO_OPT_UNALIGNED32) +#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) { *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; do *op++ = *ip++; while (--t > 0); @@ -5234,7 +3753,7 @@ first_literal_run: #endif goto match_done; - for (;;) { + do { match: if (t >= 64) { @@ -5294,15 +3813,14 @@ match: t &= 31; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_OV(t); NEED_IP(1); } t += 31 + *ip++; - NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -5318,9 +3836,9 @@ match: m_pos = op - off; last_m_off = off; } -#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) m_pos = op - 1; - m_pos -= UA_GET_LE16(ip) >> 2; + m_pos -= UA_GET16(ip) >> 2; #else m_pos = op - 1; m_pos -= (ip[0] >> 2) + (ip[1] << 6); @@ -5339,15 +3857,14 @@ match: t &= 7; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_OV(t); NEED_IP(1); } t += 7 + *ip++; - NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -5365,8 +3882,8 @@ match: #else #if defined(LZO1Z) m_pos -= (ip[0] << 6) + (ip[1] >> 2); -#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) - m_pos -= UA_GET_LE16(ip) >> 2; +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET16(ip) >> 2; #else m_pos -= (ip[0] >> 2) + (ip[1] << 6); #endif @@ -5414,18 +3931,18 @@ match: #else TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); -#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) if (op - m_pos >= 8) { t += (3 - 1); if (t >= 8) do { - UA_COPY8(op,m_pos); + UA_COPY64(op,m_pos); op += 8; m_pos += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4; } if (t > 0) @@ -5435,8 +3952,8 @@ match: } } else -#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -#if !(LZO_OPT_UNALIGNED32) +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) { assert((op - m_pos) >= 4); @@ -5444,10 +3961,10 @@ match: if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) { #endif - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4 - (3 - 1); do { - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *m_pos++; while (--t > 0); @@ -5472,7 +3989,7 @@ match_done: break; match_next: - assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); #if 0 do *op++ = *ip++; while (--t > 0); #else @@ -5480,10 +3997,16 @@ match_next: if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } #endif t = *ip++; - } + } while (TEST_IP && TEST_OP); } +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + eof_found: + assert(t == 1); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); @@ -5529,13 +4052,10 @@ lookbehind_overrun: #undef TEST_IP #undef TEST_OP -#undef TEST_IP_AND_TEST_OP #undef TEST_LB #undef TEST_LBO #undef NEED_IP #undef NEED_OP -#undef TEST_IV -#undef TEST_OV #undef HAVE_TEST_IP #undef HAVE_TEST_OP #undef HAVE_NEED_IP @@ -5550,7 +4070,6 @@ lookbehind_overrun: # if (LZO_TEST_OVERRUN_INPUT >= 2) # define NEED_IP(x) \ if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun -# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun # endif #endif @@ -5562,13 +4081,12 @@ lookbehind_overrun: # undef TEST_OP # define NEED_OP(x) \ if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun -# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun # endif #endif #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) -# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun -# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun +# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun #else # define TEST_LB(m_pos) ((void) 0) # define TEST_LBO(m_pos,o) ((void) 0) @@ -5589,27 +4107,15 @@ lookbehind_overrun: # define TEST_OP 1 #endif -#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) -# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) -#elif defined(HAVE_TEST_IP) -# define TEST_IP_AND_TEST_OP TEST_IP -#elif defined(HAVE_TEST_OP) -# define TEST_IP_AND_TEST_OP TEST_OP -#else -# define TEST_IP_AND_TEST_OP 1 -#endif - #if defined(NEED_IP) # define HAVE_NEED_IP 1 #else # define NEED_IP(x) ((void) 0) -# define TEST_IV(x) ((void) 0) #endif #if defined(NEED_OP) # define HAVE_NEED_OP 1 #else # define NEED_OP(x) ((void) 0) -# define TEST_OV(x) ((void) 0) #endif #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) @@ -5626,14 +4132,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, lzo_voidp wrkmem ) #endif { - lzo_bytep op; - const lzo_bytep ip; - lzo_uint t; + register lzo_bytep op; + register const lzo_bytep ip; + register lzo_uint t; #if defined(COPY_DICT) lzo_uint m_off; const lzo_bytep dict_end; #else - const lzo_bytep m_pos; + register const lzo_bytep m_pos; #endif const lzo_bytep const ip_end = in + in_len; @@ -5668,45 +4174,43 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, op = out; ip = in; - NEED_IP(1); if (*ip > 17) { t = *ip++ - 17; if (t < 4) goto match_next; - assert(t > 0); NEED_OP(t); NEED_IP(t+3); + assert(t > 0); NEED_OP(t); NEED_IP(t+1); do *op++ = *ip++; while (--t > 0); goto first_literal_run; } - for (;;) + while (TEST_IP && TEST_OP) { - NEED_IP(3); t = *ip++; if (t >= 16) goto match; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_IV(t); NEED_IP(1); } t += 15 + *ip++; } - assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); -#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) t += 3; if (t >= 8) do { - UA_COPY8(op,ip); + UA_COPY64(op,ip); op += 8; ip += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; t -= 4; } if (t > 0) @@ -5714,19 +4218,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, *op++ = *ip++; if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } } -#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -#if !(LZO_OPT_UNALIGNED32) +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) if (PTR_ALIGNED2_4(op,ip)) { #endif - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; if (--t > 0) { if (t >= 4) { do { - UA_COPY4(op,ip); + UA_COPY32(op,ip); op += 4; ip += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *ip++; while (--t > 0); @@ -5734,12 +4238,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, else do *op++ = *ip++; while (--t > 0); } -#if !(LZO_OPT_UNALIGNED32) +#if !defined(LZO_UNALIGNED_OK_4) } else #endif #endif -#if !(LZO_OPT_UNALIGNED32) +#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) { *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; do *op++ = *ip++; while (--t > 0); @@ -5775,7 +4279,7 @@ first_literal_run: #endif goto match_done; - for (;;) { + do { match: if (t >= 64) { @@ -5835,15 +4339,14 @@ match: t &= 31; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_OV(t); NEED_IP(1); } t += 31 + *ip++; - NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -5859,9 +4362,9 @@ match: m_pos = op - off; last_m_off = off; } -#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) m_pos = op - 1; - m_pos -= UA_GET_LE16(ip) >> 2; + m_pos -= UA_GET16(ip) >> 2; #else m_pos = op - 1; m_pos -= (ip[0] >> 2) + (ip[1] << 6); @@ -5880,15 +4383,14 @@ match: t &= 7; if (t == 0) { + NEED_IP(1); while (*ip == 0) { t += 255; ip++; - TEST_OV(t); NEED_IP(1); } t += 7 + *ip++; - NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -5906,8 +4408,8 @@ match: #else #if defined(LZO1Z) m_pos -= (ip[0] << 6) + (ip[1] >> 2); -#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) - m_pos -= UA_GET_LE16(ip) >> 2; +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET16(ip) >> 2; #else m_pos -= (ip[0] >> 2) + (ip[1] << 6); #endif @@ -5955,18 +4457,18 @@ match: #else TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); -#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) if (op - m_pos >= 8) { t += (3 - 1); if (t >= 8) do { - UA_COPY8(op,m_pos); + UA_COPY64(op,m_pos); op += 8; m_pos += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4; } if (t > 0) @@ -5976,8 +4478,8 @@ match: } } else -#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) -#if !(LZO_OPT_UNALIGNED32) +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) { assert((op - m_pos) >= 4); @@ -5985,10 +4487,10 @@ match: if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) { #endif - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4 - (3 - 1); do { - UA_COPY4(op,m_pos); + UA_COPY32(op,m_pos); op += 4; m_pos += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *m_pos++; while (--t > 0); @@ -6013,7 +4515,7 @@ match_done: break; match_next: - assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); #if 0 do *op++ = *ip++; while (--t > 0); #else @@ -6021,10 +4523,16 @@ match_next: if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } #endif t = *ip++; - } + } while (TEST_IP && TEST_OP); } +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + eof_found: + assert(t == 1); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); @@ -6051,3 +4559,4 @@ lookbehind_overrun: #endif /***** End of minilzo.c *****/ + diff --git a/grub-core/lib/minilzo/minilzo.h b/grub-core/lib/minilzo/minilzo.h index 793745467..74fefa9fe 100644 --- a/grub-core/lib/minilzo/minilzo.h +++ b/grub-core/lib/minilzo/minilzo.h @@ -2,7 +2,22 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -35,7 +50,7 @@ #ifndef __MINILZO_H #define __MINILZO_H 1 -#define MINILZO_VERSION 0x2080 +#define MINILZO_VERSION 0x2050 #ifdef __LZOCONF_H # error "you cannot use both LZO and miniLZO" @@ -63,7 +78,7 @@ extern "C" { */ #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS -#define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t)) +#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) #define LZO1X_MEM_DECOMPRESS (0) diff --git a/grub-core/lib/mips/relocator.c b/grub-core/lib/mips/relocator.c index 743b213e6..9d5f49cb9 100644 --- a/grub-core/lib/mips/relocator.c +++ b/grub-core/lib/mips/relocator.c @@ -120,8 +120,10 @@ grub_relocator32_boot (struct grub_relocator *rel, unsigned i; grub_addr_t vtarget; - err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), - stateset_size, sizeof (grub_uint32_t), + err = grub_relocator_alloc_chunk_align (rel, &ch, 0, + (0xffffffff - stateset_size) + + 1, stateset_size, + sizeof (grub_uint32_t), GRUB_RELOCATOR_PREFERENCE_NONE, 0); if (err) return err; diff --git a/grub-core/lib/mips/setjmp.S b/grub-core/lib/mips/setjmp.S index 895235b78..f01294518 100644 --- a/grub-core/lib/mips/setjmp.S +++ b/grub-core/lib/mips/setjmp.S @@ -18,7 +18,6 @@ #include #include -#include .file "setjmp.S" @@ -30,42 +29,40 @@ GRUB_MOD_LICENSE "GPLv3+" * int grub_setjmp (grub_jmp_buf env) */ FUNCTION(grub_setjmp) - GRUB_ASM_REG_S $s0, 0($a0) - GRUB_ASM_REG_S $s1, 8($a0) - GRUB_ASM_REG_S $s2, 16($a0) - GRUB_ASM_REG_S $s3, 24($a0) - GRUB_ASM_REG_S $s4, 32($a0) - GRUB_ASM_REG_S $s5, 40($a0) - GRUB_ASM_REG_S $s6, 48($a0) - GRUB_ASM_REG_S $s7, 56($a0) - GRUB_ASM_REG_S $s8, 64($a0) - GRUB_ASM_REG_S $gp, 72($a0) - GRUB_ASM_REG_S $sp, 80($a0) - GRUB_ASM_REG_S $ra, 88($a0) + sw $s0, 0($a0) + sw $s1, 4($a0) + sw $s2, 8($a0) + sw $s3, 12($a0) + sw $s4, 16($a0) + sw $s5, 20($a0) + sw $s6, 24($a0) + sw $s7, 28($a0) + sw $s8, 32($a0) + sw $gp, 36($a0) + sw $sp, 40($a0) + sw $ra, 44($a0) move $v0, $zero move $v1, $zero jr $ra - nop /* * int grub_longjmp (grub_jmp_buf env, int val) */ FUNCTION(grub_longjmp) - GRUB_ASM_REG_L $s0, 0($a0) - GRUB_ASM_REG_L $s1, 8($a0) - GRUB_ASM_REG_L $s2, 16($a0) - GRUB_ASM_REG_L $s3, 24($a0) - GRUB_ASM_REG_L $s4, 32($a0) - GRUB_ASM_REG_L $s5, 40($a0) - GRUB_ASM_REG_L $s6, 48($a0) - GRUB_ASM_REG_L $s7, 56($a0) - GRUB_ASM_REG_L $s8, 64($a0) - GRUB_ASM_REG_L $gp, 72($a0) - GRUB_ASM_REG_L $sp, 80($a0) - GRUB_ASM_REG_L $ra, 88($a0) + lw $s0, 0($a0) + lw $s1, 4($a0) + lw $s2, 8($a0) + lw $s3, 12($a0) + lw $s4, 16($a0) + lw $s5, 20($a0) + lw $s6, 24($a0) + lw $s7, 28($a0) + lw $s8, 32($a0) + lw $gp, 36($a0) + lw $sp, 40($a0) + lw $ra, 44($a0) move $v0, $a1 bne $v0, $zero, 1f addiu $v0, $v0, 1 1: move $v1, $zero jr $ra - nop diff --git a/grub-core/lib/pbkdf2.c b/grub-core/lib/pbkdf2.c index 28aa96c46..01cee3951 100644 --- a/grub-core/lib/pbkdf2.c +++ b/grub-core/lib/pbkdf2.c @@ -31,6 +31,7 @@ GRUB_MOD_LICENSE ("GPLv2+"); desired derived output length DKLEN. Output buffer is DK which must have room for at least DKLEN octets. The output buffer will be filled with the derived data. */ +#pragma GCC diagnostic ignored "-Wunreachable-code" gcry_err_code_t grub_crypto_pbkdf2 (const struct gcry_md_spec *md, diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h index 7217138ff..955295403 100644 --- a/grub-core/lib/posix_wrap/limits.h +++ b/grub-core/lib/posix_wrap/limits.h @@ -27,14 +27,8 @@ #define ULONG_MAX GRUB_ULONG_MAX #define SIZE_MAX GRUB_SIZE_MAX -#define SCHAR_MIN GRUB_SCHAR_MIN -#define SCHAR_MAX GRUB_SCHAR_MAX -#define SHRT_MIN GRUB_SHRT_MIN #define SHRT_MAX GRUB_SHRT_MAX -#define INT_MIN GRUB_INT_MIN #define INT_MAX GRUB_INT_MAX -#define LONG_MIN GRUB_LONG_MIN -#define LONG_MAX GRUB_LONG_MAX #define CHAR_BIT 8 diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h index 7a8d385e9..3b46f47ff 100644 --- a/grub-core/lib/posix_wrap/stdlib.h +++ b/grub-core/lib/posix_wrap/stdlib.h @@ -21,7 +21,6 @@ #include #include -#include static inline void free (void *ptr) @@ -38,12 +37,7 @@ malloc (grub_size_t size) static inline void * calloc (grub_size_t size, grub_size_t nelem) { - grub_size_t sz; - - if (grub_mul (size, nelem, &sz)) - return NULL; - - return grub_zalloc (sz); + return grub_zalloc (size * nelem); } static inline void * diff --git a/grub-core/lib/posix_wrap/string.h b/grub-core/lib/posix_wrap/string.h index 7ae6eee97..c4b9bf089 100644 --- a/grub-core/lib/posix_wrap/string.h +++ b/grub-core/lib/posix_wrap/string.h @@ -42,6 +42,21 @@ strcasecmp (const char *s1, const char *s2) return grub_strcasecmp (s1, s2); } +#ifdef GRUB_UTIL +static inline void * +memcpy (void *dest, const void *src, grub_size_t n) +{ + return grub_memcpy (dest, src, n); +} + +static inline int +memcmp (const void *s1, const void *s2, grub_size_t n) +{ + return grub_memcmp (s1, s2, n); +} + +#endif + static inline void bcopy (const void *src, void *dest, grub_size_t n) { @@ -84,9 +99,4 @@ memchr (const void *s, int c, grub_size_t n) return grub_memchr (s, c, n); } -#define memcmp grub_memcmp -#define memcpy grub_memcpy -#define memmove grub_memmove -#define memset grub_memset - #endif diff --git a/grub-core/lib/powerpc/relocator.c b/grub-core/lib/powerpc/relocator.c index 8ffb8b686..bdf2b111b 100644 --- a/grub-core/lib/powerpc/relocator.c +++ b/grub-core/lib/powerpc/relocator.c @@ -115,8 +115,10 @@ grub_relocator32_boot (struct grub_relocator *rel, unsigned i; grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), - stateset_size, sizeof (grub_uint32_t), + err = grub_relocator_alloc_chunk_align (rel, &ch, 0, + (0xffffffff - stateset_size) + + 1, stateset_size, + sizeof (grub_uint32_t), GRUB_RELOCATOR_PREFERENCE_NONE, 0); if (err) return err; diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c index 7d5e7c05a..659be0b7f 100644 --- a/grub-core/lib/priority_queue.c +++ b/grub-core/lib/priority_queue.c @@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, { struct grub_priority_queue *ret; void *els; - els = grub_calloc (8, elsize); + els = grub_malloc (elsize * 8); if (!els) return 0; ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); diff --git a/grub-core/lib/progress.c b/grub-core/lib/progress.c index 4b7cbbca6..63a0767d6 100644 --- a/grub-core/lib/progress.c +++ b/grub-core/lib/progress.c @@ -23,7 +23,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -38,17 +37,11 @@ grub_file_progress_hook_real (grub_disk_addr_t sector __attribute__ ((unused)), grub_uint64_t now; static grub_uint64_t last_progress_update_time; grub_file_t file = data; - const char *e; file->progress_offset += length; if (call_depth) return; - e = grub_env_get ("enable_progress_indicator"); - if (e && e[0] == '0') { - return; - } - call_depth = 1; now = grub_get_time_ms (); @@ -77,15 +70,7 @@ grub_file_progress_hook_real (grub_disk_addr_t sector __attribute__ ((unused)), percent = grub_divmod64 (100 * file->progress_offset, file->size, 0); - /* grub_net_fs_open() saves off partial file structure before name is initialized. - It already saves passed file name in net structure so just use it in this case. - */ - if (file->device->net) - partial_file_name = grub_strrchr (file->device->net->name, '/'); - else if (file->name) /* grub_file_open() may leave it as NULL */ - partial_file_name = grub_strrchr (file->name, '/'); - else - partial_file_name = NULL; + partial_file_name = grub_strrchr (file->name, '/'); if (partial_file_name) partial_file_name++; else diff --git a/grub-core/lib/random.c b/grub-core/lib/random.c deleted file mode 100644 index 43b966438..000000000 --- a/grub-core/lib/random.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -grub_err_t -grub_crypto_get_random (void *buffer, grub_size_t sz) -{ - /* This is an arbitrer between different methods. - TODO: Add more methods in the future. */ - /* TODO: Add some PRNG smartness to reduce damage from bad entropy. */ - if (grub_crypto_arch_get_random (buffer, sz)) - return GRUB_ERR_NONE; - return grub_error (GRUB_ERR_IO, "no random sources found"); -} - -static int -get_num_digits (int val) -{ - int ret = 0; - while (val != 0) - { - ret++; - val /= 10; - } - if (ret == 0) - return 1; - return ret; -} - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" - -static grub_err_t -grub_cmd_hexdump_random (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) -{ - grub_size_t length = 64; - grub_err_t err; - void *buffer; - grub_uint8_t *ptr; - int stats[256]; - int i, digits = 2; - char template[10]; - - if (argc >= 1) - length = grub_strtoull (args[0], 0, 0); - - if (length == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "length pust be positive"); - - buffer = grub_malloc (length); - if (!buffer) - return grub_errno; - - err = grub_crypto_get_random (buffer, length); - if (err) - { - grub_free (buffer); - return err; - } - - hexdump (0, buffer, length); - grub_memset(stats, 0, sizeof(stats)); - for (ptr = buffer; ptr < (grub_uint8_t *) buffer + length; ptr++) - stats[*ptr]++; - grub_printf ("Statistics:\n"); - for (i = 0; i < 256; i++) - { - int z = get_num_digits (stats[i]); - if (z > digits) - digits = z; - } - - grub_snprintf (template, sizeof (template), "%%0%dd ", digits); - - for (i = 0; i < 256; i++) - { - grub_printf ("%s", template);//, stats[i]); - if ((i & 0xf) == 0xf) - grub_printf ("\n"); - } - - grub_free (buffer); - - return 0; -} - -static grub_command_t cmd; - -GRUB_MOD_INIT (random) -{ - cmd = grub_register_command ("hexdump_random", grub_cmd_hexdump_random, - N_("[LENGTH]"), - N_("Hexdump random data.")); -} - -GRUB_MOD_FINI (random) -{ - grub_unregister_command (cmd); -} diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c index 467305b46..7263cbc04 100644 --- a/grub-core/lib/reed_solomon.c +++ b/grub-core/lib/reed_solomon.c @@ -20,7 +20,6 @@ #include #include #include -#define xcalloc calloc #define xmalloc malloc #define grub_memset memset #define grub_memcpy memcpy @@ -159,9 +158,11 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) gf_single_t *rs_polynomial; int i, j; gf_single_t *m; - m = xcalloc (s + rs, sizeof (gf_single_t)); + m = xmalloc ((s + rs) * sizeof (gf_single_t)); grub_memcpy (m, data, s * sizeof (gf_single_t)); - rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); + grub_memset (m + s, 0, rs * sizeof (gf_single_t)); + rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); + grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); rs_polynomial[rs] = 1; /* Multiply with X - a^r */ for (j = 0; j < rs; j++) @@ -361,7 +362,7 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, /* Nothing to do. */ if (!rs) - goto exit; + return; init_powx (); @@ -387,7 +388,6 @@ grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size, #ifndef TEST assert (grub_memcmp (tmp, buffer, data_size) == 0); #endif -exit: free (tmp); } #endif diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c index f2c1944c2..f759c7f41 100644 --- a/grub-core/lib/relocator.c +++ b/grub-core/lib/relocator.c @@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, } #endif - eventt = grub_calloc (maxevents, sizeof (events[0])); + eventt = grub_malloc (maxevents * sizeof (events[0])); counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); - events = grub_calloc (maxevents, sizeof (events[0])); + events = grub_malloc (maxevents * sizeof (events[0])); if (!events || !eventt || !counter) { grub_dprintf ("relocator", "events or counter allocation failed %d\n", @@ -736,36 +736,26 @@ malloc_in_range (struct grub_relocator *rel, } isinsideafter = (!ncollisions && (nstarted || ((nlefto || nstartedfw) && !nblockfw))); - if (from_low_priv) { - if (!isinsidebefore && isinsideafter) - starta = ALIGN_UP (events[j].pos, align); - - if (isinsidebefore && !isinsideafter) - { - target = starta; - if (target < start) - target = start; - if (target + size <= end && target + size <= events[j].pos) - /* Found an usable address. */ - goto found; - } - } else { - if (!isinsidebefore && isinsideafter) - { - if (events[j].pos >= size) - starta = ALIGN_DOWN (events[j].pos - size, align) + size; - else - starta = 0; - } - if (isinsidebefore && !isinsideafter && starta >= size) - { - target = starta - size; - if (target > end - size) - target = end - size; - if (target >= start && target >= events[j].pos) - goto found; - } - } + if (!isinsidebefore && isinsideafter) + starta = from_low_priv ? ALIGN_UP (events[j].pos, align) + : ALIGN_DOWN (events[j].pos - size, align) + size; + if (isinsidebefore && !isinsideafter && from_low_priv) + { + target = starta; + if (target < start) + target = start; + if (target + size <= end && target + size <= events[j].pos) + /* Found an usable address. */ + goto found; + } + if (isinsidebefore && !isinsideafter && !from_low_priv) + { + target = starta - size; + if (target > end - size) + target = end - size; + if (target >= start && target >= events[j].pos) + goto found; + } } } @@ -963,7 +953,7 @@ malloc_in_range (struct grub_relocator *rel, #endif unsigned cural = 0; int oom = 0; - res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); + res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); if (!res->subchunks) oom = 1; res->nsubchunks = nallocs; @@ -1386,8 +1376,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, }; grub_addr_t min_addr2 = 0, max_addr2; - if (size && (max_addr > ~size)) - max_addr = ~size + 1; + if (max_addr > ~size) + max_addr = ~size; #ifdef GRUB_MACHINE_PCBIOS if (min_addr < 0x1000) @@ -1562,8 +1552,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, count[(chunk->src & 0xff) + 1]++; } } - from = grub_calloc (nchunks, sizeof (sorted[0])); - to = grub_calloc (nchunks, sizeof (sorted[0])); + from = grub_malloc (nchunks * sizeof (sorted[0])); + to = grub_malloc (nchunks * sizeof (sorted[0])); if (!from || !to) { grub_free (from); diff --git a/grub-core/lib/riscv/setjmp.S b/grub-core/lib/riscv/setjmp.S deleted file mode 100644 index b48ef29ea..000000000 --- a/grub-core/lib/riscv/setjmp.S +++ /dev/null @@ -1,84 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - - .file "setjmp.S" - -GRUB_MOD_LICENSE "GPLv3+" - - .text - -#if __riscv_xlen == 64 -#define STORE_IDX(reg, idx) sd reg, (idx*8)(a0) -#define LOAD_IDX(reg, idx) ld reg, (idx*8)(a0) -#else -#define STORE_IDX(reg, idx) sw reg, (idx*4)(a0) -#define LOAD_IDX(reg, idx) lw reg, (idx*4)(a0) -#endif - -/* - * int grub_setjmp (grub_jmp_buf env) - */ -FUNCTION(grub_setjmp) - /* Preserve all callee-saved registers and the SP */ - STORE_IDX(s0, 0) - STORE_IDX(s1, 1) - STORE_IDX(s2, 2) - STORE_IDX(s3, 3) - STORE_IDX(s4, 4) - STORE_IDX(s5, 5) - STORE_IDX(s6, 6) - STORE_IDX(s7, 7) - STORE_IDX(s8, 8) - STORE_IDX(s9, 9) - STORE_IDX(s10, 10) - STORE_IDX(s11, 11) - STORE_IDX(ra, 12) - STORE_IDX(sp, 13) - li a0, 0 - ret - -/* - * int grub_longjmp (grub_jmp_buf env, int val) - */ -FUNCTION(grub_longjmp) - LOAD_IDX(s0, 0) - LOAD_IDX(s1, 1) - LOAD_IDX(s2, 2) - LOAD_IDX(s3, 3) - LOAD_IDX(s4, 4) - LOAD_IDX(s5, 5) - LOAD_IDX(s6, 6) - LOAD_IDX(s7, 7) - LOAD_IDX(s8, 8) - LOAD_IDX(s9, 9) - LOAD_IDX(s10, 10) - LOAD_IDX(s11, 11) - LOAD_IDX(ra, 12) - LOAD_IDX(sp, 13) - - /* Move the return value in place, but return 1 if passed 0. */ - beq a1, zero, longjmp_1 - mv a0, a1 - ret - - longjmp_1: - li a0, 1 - ret diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index aa297ab0a..f6e4905e2 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -15,8 +15,6 @@ #include "./arm/setjmp.S" #elif defined(__aarch64__) #include "./arm64/setjmp.S" -#elif defined(__riscv) -#include "./riscv/setjmp.S" #else #error "Unknown target cpu type" #endif diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c index de9fda06f..241cefe69 100644 --- a/grub-core/lib/syslinux_parse.c +++ b/grub-core/lib/syslinux_parse.c @@ -649,8 +649,6 @@ helptext (const char *line, grub_file_t file, struct syslinux_menu *menu) grub_size_t helplen, alloclen = 0; help = grub_strdup (line); - if (!help) - return grub_errno; helplen = grub_strlen (line); while ((grub_free (buf), buf = grub_file_getline (file))) { @@ -684,7 +682,6 @@ helptext (const char *line, grub_file_t file, struct syslinux_menu *menu) } grub_free (buf); - grub_free (help); return grub_errno; } @@ -696,7 +693,7 @@ syslinux_parse_real (struct syslinux_menu *menu) char *buf = NULL; grub_err_t err = GRUB_ERR_NONE; - file = grub_file_open (menu->filename, GRUB_FILE_TYPE_CONFIG); + file = grub_file_open (menu->filename); if (!file) return grub_errno; while ((grub_free (buf), buf = grub_file_getline (file))) @@ -772,7 +769,7 @@ print_escaped (struct output_buffer *outbuf, if (err) return err; outbuf->buf[outbuf->ptr++] = '\''; - for (ptr = from; *ptr && ptr < to; ptr++) + for (ptr = from; *ptr; ptr++) { if (*ptr == '\'') { @@ -807,10 +804,6 @@ print_file (struct output_buffer *outbuf, return print_escaped (outbuf, from, to); } -/* - * Makefile.am mimics this when generating tests/syslinux/ubuntu10.04_grub.cfg, - * so changes here may need to be reflected there too. - */ static void simplify_filename (char *str) { @@ -843,84 +836,6 @@ simplify_filename (char *str) *optr = '\0'; } -static grub_err_t -print_config (struct output_buffer *outbuf, - struct syslinux_menu *menu, - const char *filename, const char *basedir) -{ - struct syslinux_menu *menuptr; - grub_err_t err = GRUB_ERR_NONE; - char *new_cwd = NULL; - char *new_target_cwd = NULL; - char *newname = NULL; - int depth = 0; - - new_cwd = get_read_filename (menu, basedir); - if (!new_cwd) - { - err = grub_errno; - goto out; - } - new_target_cwd = get_target_filename (menu, basedir); - if (!new_target_cwd) - { - err = grub_errno; - goto out; - } - newname = get_read_filename (menu, filename); - if (!newname) - { - err = grub_errno; - goto out; - } - simplify_filename (newname); - - print_string ("#"); - print_file (outbuf, menu, filename, NULL); - print_string (" "); - err = print (outbuf, newname, grub_strlen (newname)); - if (err) - return err; - print_string (":\n"); - - for (menuptr = menu; menuptr; menuptr = menuptr->parent, depth++) - if (grub_strcmp (menuptr->filename, newname) == 0 - || depth > 20) - break; - if (menuptr) - { - print_string (" syslinux_configfile -r "); - print_file (outbuf, menu, "/", NULL); - print_string (" -c "); - print_file (outbuf, menu, basedir, NULL); - print_string (" "); - print_file (outbuf, menu, filename, NULL); - print_string ("\n"); - } - else - { - err = config_file (outbuf, menu->root_read_directory, - menu->root_target_directory, new_cwd, new_target_cwd, - newname, menu, menu->flavour); - if (err == GRUB_ERR_FILE_NOT_FOUND - || err == GRUB_ERR_BAD_FILENAME) - { - grub_errno = err = GRUB_ERR_NONE; - print_string ("# File "); - err = print (outbuf, newname, grub_strlen (newname)); - if (err) - goto out; - print_string (" not found\n"); - } - } - - out: - grub_free (newname); - grub_free (new_cwd); - grub_free (new_target_cwd); - return err; -} - static grub_err_t write_entry (struct output_buffer *outbuf, struct syslinux_menu *menu, @@ -928,12 +843,7 @@ write_entry (struct output_buffer *outbuf, { grub_err_t err; if (curentry->comments) - { - err = print (outbuf, curentry->comments, - grub_strlen (curentry->comments)); - if (err) - return err; - } + print (outbuf, curentry->comments, grub_strlen (curentry->comments)); { struct syslinux_say *say; for (say = curentry->say; say && say->next; say = say->next); @@ -950,8 +860,9 @@ write_entry (struct output_buffer *outbuf, { case KERNEL_LINUX: { - const char *ptr; - const char *initrd = NULL, *initrde= NULL; + char *ptr; + char *cmdline; + char *initrd = NULL; for (ptr = curentry->append; ptr && *ptr; ptr++) if ((ptr == curentry->append || grub_isspace (ptr[-1])) && grub_strncasecmp (ptr, "initrd=", sizeof ("initrd=") - 1) @@ -959,20 +870,32 @@ write_entry (struct output_buffer *outbuf, break; if (ptr && *ptr) { + char *ptr2; + grub_size_t totlen = grub_strlen (curentry->append); initrd = ptr + sizeof ("initrd=") - 1; - for (initrde = initrd; *initrde && !grub_isspace (*initrde); initrde++); + for (ptr2 = ptr; *ptr2 && !grub_isspace (*ptr2); ptr2++); + if (*ptr2) + { + *ptr2 = 0; + ptr2++; + } + cmdline = grub_malloc (totlen + 1 - (ptr2 - ptr)); + if (!cmdline) + return grub_errno; + grub_memcpy (cmdline, curentry->append, ptr - curentry->append); + grub_memcpy (cmdline + (ptr - curentry->append), + ptr2, totlen - (ptr2 - curentry->append)); + *(cmdline + totlen - (ptr2 - ptr)) = 0; } + else + cmdline = curentry->append; print_string (" if test x$grub_platform = xpc; then " "linux_suffix=16; else linux_suffix= ; fi\n"); print_string (" linux$linux_suffix "); print_file (outbuf, menu, curentry->kernel_file, NULL); print_string (" "); - if (curentry->append) - { - err = print (outbuf, curentry->append, grub_strlen (curentry->append)); - if (err) - return err; - } + if (cmdline) + print (outbuf, cmdline, grub_strlen (cmdline)); print_string ("\n"); if (initrd || curentry->initrds) { @@ -980,7 +903,7 @@ write_entry (struct output_buffer *outbuf, print_string (" initrd$linux_suffix "); if (initrd) { - print_file (outbuf, menu, initrd, initrde); + print_file (outbuf, menu, initrd, NULL); print_string (" "); } for (lst = curentry->initrds; lst; lst = lst->next) @@ -1026,7 +949,6 @@ write_entry (struct output_buffer *outbuf, break; } print_string (" # UNSUPPORTED localboot type "); - print_string ("\ntrue;\n"); if (print_num (outbuf, n)) return grub_errno; print_string ("\n"); @@ -1062,7 +984,7 @@ write_entry (struct output_buffer *outbuf, if (ptr[0] == 'h' && ptr[1] == 'd') { is_fd = 0; - devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + devn = grub_strtoul (ptr + 2, &ptr, 0); continue; } if (grub_strncasecmp (ptr, "file=", 5) == 0) @@ -1086,12 +1008,12 @@ write_entry (struct output_buffer *outbuf, if (ptr[0] == 'f' && ptr[1] == 'd') { is_fd = 1; - devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + devn = grub_strtoul (ptr + 2, &ptr, 0); continue; } if (grub_isdigit (ptr[0])) { - part = grub_strtoul (ptr, (const char **)&ptr, 0); + part = grub_strtoul (ptr, &ptr, 0); continue; } /* FIXME: isolinux, ntldr, cmldr, *dos, seg, hide @@ -1202,7 +1124,8 @@ write_entry (struct output_buffer *outbuf, ptr++; i386e = ptr; } - *lme = '\0'; + if (lme) + *lme = '\0'; if (paee) *paee = '\0'; if (i386e) @@ -1307,36 +1230,6 @@ write_entry (struct output_buffer *outbuf, break; } - if (grub_strcasecmp (basename, "menu.c32") == 0 || - grub_strcasecmp (basename, "vesamenu.c32") == 0) - { - char *ptr; - char *end; - - ptr = curentry->append; - if (!ptr) - return grub_errno; - - while (*ptr) - { - end = ptr; - for (end = ptr; *end && !grub_isspace (*end); end++); - if (*end) - *end++ = '\0'; - - /* "~" is supposed to be current file, so let's skip it */ - if (grub_strcmp (ptr, "~") != 0) - { - err = print_config (outbuf, menu, ptr, ""); - if (err != GRUB_ERR_NONE) - break; - } - for (ptr = end; *ptr && grub_isspace (*ptr); ptr++); - } - err = GRUB_ERR_NONE; - break; - } - /* FIXME: gdb, GFXBoot, Hdt, Ifcpu, Ifplop, Kbdmap, FIXME: Linux, Lua, Meminfo, rosh, Sanbboot */ @@ -1349,13 +1242,70 @@ write_entry (struct output_buffer *outbuf, } case KERNEL_CONFIG: { + char *new_cwd, *new_target_cwd; const char *ap; ap = curentry->append; if (!ap) ap = curentry->argument; if (!ap) ap = ""; - print_config (outbuf, menu, curentry->kernel_file, ap); + new_cwd = get_read_filename (menu, ap); + if (!new_cwd) + return grub_errno; + new_target_cwd = get_target_filename (menu, ap); + if (!new_target_cwd) + return grub_errno; + + struct syslinux_menu *menuptr; + char *newname; + int depth = 0; + + newname = get_read_filename (menu, curentry->kernel_file); + if (!newname) + return grub_errno; + simplify_filename (newname); + + print_string ("#"); + print_file (outbuf, menu, curentry->kernel_file, NULL); + print_string (" "); + print (outbuf, newname, grub_strlen (newname)); + print_string (":\n"); + + for (menuptr = menu; menuptr; menuptr = menuptr->parent, depth++) + if (grub_strcmp (menuptr->filename, newname) == 0 + || depth > 20) + break; + if (menuptr) + { + print_string (" syslinux_configfile -r "); + print_file (outbuf, menu, "/", NULL); + print_string (" -c "); + print_file (outbuf, menu, ap, NULL); + print_string (" "); + print_file (outbuf, menu, curentry->kernel_file, NULL); + print_string ("\n"); + } + else + { + err = config_file (outbuf, menu->root_read_directory, + menu->root_target_directory, new_cwd, new_target_cwd, + newname, menu, menu->flavour); + if (err == GRUB_ERR_FILE_NOT_FOUND + || err == GRUB_ERR_BAD_FILENAME) + { + grub_errno = err = GRUB_ERR_NONE; + print_string ("# File "); + err = print (outbuf, newname, grub_strlen (newname)); + if (err) + return err; + print_string (" not found\n"); + } + if (err) + return err; + } + grub_free (newname); + grub_free (new_cwd); + grub_free (new_target_cwd); } break; case KERNEL_NO_KERNEL: @@ -1470,13 +1420,6 @@ config_file (struct output_buffer *outbuf, print_string ("\n"); } - if (menu.comments) - { - err = print (outbuf, menu.comments, grub_strlen (menu.comments)); - if (err) - return err; - } - if (menu.timeout == 0 && menu.entries && menu.def) { err = print_entry (outbuf, &menu, menu.def); @@ -1493,6 +1436,12 @@ config_file (struct output_buffer *outbuf, if (err) return err; print_string ("\n"); + if (menu.comments) + { + err = print (outbuf, menu.comments, grub_strlen (menu.comments)); + if (err) + return err; + } if (menu.def) { diff --git a/grub-core/lib/dummy/datetime.c b/grub-core/lib/uboot/datetime.c similarity index 91% rename from grub-core/lib/dummy/datetime.c rename to grub-core/lib/uboot/datetime.c index cf693fc6b..4be716928 100644 --- a/grub-core/lib/dummy/datetime.c +++ b/grub-core/lib/uboot/datetime.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -29,12 +30,12 @@ grub_err_t grub_get_datetime (struct grub_datetime *datetime __attribute__ ((unused))) { return grub_error (GRUB_ERR_INVALID_COMMAND, - "can\'t get datetime on this machine"); + "can\'t get datetime using U-Boot"); } grub_err_t grub_set_datetime (struct grub_datetime * datetime __attribute__ ((unused))) { return grub_error (GRUB_ERR_INVALID_COMMAND, - "can\'t set datetime on this machine"); + "can\'t set datetime using U-Boot"); } diff --git a/grub-core/lib/dummy/halt.c b/grub-core/lib/uboot/halt.c similarity index 100% rename from grub-core/lib/dummy/halt.c rename to grub-core/lib/uboot/halt.c diff --git a/grub-core/lib/x86_64/efi/relocator.c b/grub-core/lib/x86_64/efi/relocator.c deleted file mode 100644 index 7d200a125..000000000 --- a/grub-core/lib/x86_64/efi/relocator.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * Copyright (C) 2016 Oracle and/or its affiliates. All rights reserved. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -#include -#include - -#include -#include - -extern grub_uint64_t grub_relocator64_rax; -extern grub_uint64_t grub_relocator64_rbx; -extern grub_uint64_t grub_relocator64_rcx; -extern grub_uint64_t grub_relocator64_rdx; -extern grub_uint64_t grub_relocator64_rip; -extern grub_uint64_t grub_relocator64_rsi; - -extern grub_uint8_t grub_relocator64_efi_start; -extern grub_uint8_t grub_relocator64_efi_end; - -#define RELOCATOR_SIZEOF(x) (&grub_relocator##x##_end - &grub_relocator##x##_start) - -grub_err_t -grub_relocator64_efi_boot (struct grub_relocator *rel, - struct grub_relocator64_efi_state state) -{ - grub_err_t err; - void *relst; - grub_relocator_chunk_t ch; - - /* - * 64-bit relocator code may live above 4 GiB quite well. - * However, I do not want ask for problems. Just in case. - */ - err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0x100000000, - RELOCATOR_SIZEOF (64_efi), 16, - GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) - return err; - - /* Do not touch %rsp! It points to EFI created stack. */ - grub_relocator64_rax = state.rax; - grub_relocator64_rbx = state.rbx; - grub_relocator64_rcx = state.rcx; - grub_relocator64_rdx = state.rdx; - grub_relocator64_rip = state.rip; - grub_relocator64_rsi = state.rsi; - - grub_memmove (get_virtual_current_address (ch), &grub_relocator64_efi_start, - RELOCATOR_SIZEOF (64_efi)); - - err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch), - &relst, NULL); - if (err) - return err; - - ((void (*) (void)) relst) (); - - /* Not reached. */ - return GRUB_ERR_NONE; -} diff --git a/grub-core/lib/x86_64/xen/relocator.S b/grub-core/lib/x86_64/xen/relocator.S index f5364ed0f..78c123350 100644 --- a/grub-core/lib/x86_64/xen/relocator.S +++ b/grub-core/lib/x86_64/xen/relocator.S @@ -16,85 +16,94 @@ * along with GRUB. If not, see . */ -#include -#include #include #include -/* Macro to load an imm64 value stored by the C-part into %rax: */ -#define MOV_IMM64_RAX(var) .byte 0x48, 0xb8; VARIABLE(var); .quad 0 - .p2align 4 /* force 16-byte alignment */ VARIABLE(grub_relocator_xen_remap_start) LOCAL(base): - /* Remap the remapper to it's new address. */ - MOV_IMM64_RAX(grub_relocator_xen_remapper_virt) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_remapper_virt) + .quad 0 - movq %rax, %rdi /* %rdi: new virtual address of remapper */ - movq %rax, %rbx /* Remember new virtual address */ + movq %rax, %rdi + movq %rax, %rbx - MOV_IMM64_RAX(grub_relocator_xen_remapper_map) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_remapper_map) + .quad 0 - movq %rax, %rsi /* %rsi: page table entry */ + movq %rax, %rsi - movq $UVMF_INVLPG, %rdx /* %rdx: flags (inv. single entry) */ + movq $2, %rdx movq $__HYPERVISOR_update_va_mapping, %rax - syscall /* Do the remap operation */ + syscall addq $(LOCAL(cont) - LOCAL(base)), %rbx - jmp *%rbx /* Continue with new virtual address */ + jmp *%rbx LOCAL(cont): - /* Modify mappings of new page tables to be read-only. */ - MOV_IMM64_RAX(grub_relocator_xen_mfn_list) + + /* mov imm64, %rcx */ + .byte 0x48 + .byte 0xb9 +VARIABLE(grub_relocator_xen_paging_size) + .quad 0 - movq %rax, %rbx /* %rbx is the base of the p2m list */ - leaq EXT_C(grub_relocator_xen_paging_areas) (%rip), %r8 + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_paging_start) + .quad 0 + movq %rax, %r12 + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_mfn_list) + .quad 0 + + movq %rax, %rsi 1: - movq 0(%r8), %r12 /* Get start pfn of the current area */ - movq GRUB_TARGET_SIZEOF_LONG(%r8), %rcx /* Get # of pg tables */ - testq %rcx, %rcx /* 0 -> last area reached */ - jz 3f -2: movq %r12, %rdi - shlq $PAGE_SHIFT, %rdi /* virtual address (1:1 mapping) */ - movq (%rbx, %r12, 8), %rsi /* mfn */ - shlq $PAGE_SHIFT, %rsi - orq $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %rsi /* Build pte */ - movq $UVMF_INVLPG, %rdx - movq %rcx, %r9 /* %rcx clobbered by hypercall */ + movq %rsi, %rbx + movq 0(%rsi), %rsi + shlq $12, %rsi + orq $5, %rsi + movq $2, %rdx + movq %rcx, %r9 movq $__HYPERVISOR_update_va_mapping, %rax syscall movq %r9, %rcx - incq %r12 /* next pfn */ + addq $8, %rbx + addq $4096, %r12 + movq %rbx, %rsi - loop 2b + loop 1b - addq $(2 * GRUB_TARGET_SIZEOF_LONG), %r8 /* next pg table area */ - jmp 1b - -3: - /* Switch page tables: pin new L4 pt, load cr3, unpin old L4. */ leaq EXT_C(grub_relocator_xen_mmu_op) (%rip), %rdi - movq $3, %rsi /* 3 mmu ops */ - movq $0, %rdx /* pdone (not used) */ - movq $DOMID_SELF, %r10 + movq $3, %rsi + movq $0, %rdx + movq $0x7FF0, %r10 movq $__HYPERVISOR_mmuext_op, %rax syscall - /* Continue in virtual kernel mapping. */ - MOV_IMM64_RAX(grub_relocator_xen_remap_continue) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_remap_continue) + .quad 0 jmp *%rax -VARIABLE(grub_relocator_xen_paging_areas) - /* array of start, size pairs, size 0 is end marker */ - .quad 0, 0, 0, 0, 0, 0, 0, 0 - VARIABLE(grub_relocator_xen_mmu_op) .space 256 @@ -102,32 +111,46 @@ VARIABLE(grub_relocator_xen_remap_end) VARIABLE(grub_relocator_xen_start) - /* Unmap old remapper area. */ - MOV_IMM64_RAX(grub_relocator_xen_remapper_virt2) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_remapper_virt2) + .quad 0 movq %rax, %rdi - xorq %rax, %rax /* Invalid pte */ + xorq %rax, %rax movq %rax, %rsi - movq $UVMF_INVLPG, %rdx + movq $2, %rdx movq $__HYPERVISOR_update_va_mapping, %rax syscall - /* Prepare registers for starting kernel. */ - MOV_IMM64_RAX(grub_relocator_xen_stack) + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_stack) + .quad 0 movq %rax, %rsp - MOV_IMM64_RAX(grub_relocator_xen_start_info) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_start_info) + .quad 0 movq %rax, %rsi cld - MOV_IMM64_RAX(grub_relocator_xen_entry_point) + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator_xen_entry_point) + .quad 0 - /* Now start the new kernel. */ jmp *%rax VARIABLE(grub_relocator_xen_end) diff --git a/grub-core/lib/xen/relocator.c b/grub-core/lib/xen/relocator.c index 4d0cbcadb..8f427d341 100644 --- a/grub-core/lib/xen/relocator.c +++ b/grub-core/lib/xen/relocator.c @@ -29,11 +29,6 @@ typedef grub_addr_t grub_xen_reg_t; -struct grub_relocator_xen_paging_area { - grub_xen_reg_t start; - grub_xen_reg_t size; -} GRUB_PACKED; - extern grub_uint8_t grub_relocator_xen_start; extern grub_uint8_t grub_relocator_xen_end; extern grub_uint8_t grub_relocator_xen_remap_start; @@ -41,16 +36,15 @@ extern grub_uint8_t grub_relocator_xen_remap_end; extern grub_xen_reg_t grub_relocator_xen_stack; extern grub_xen_reg_t grub_relocator_xen_start_info; extern grub_xen_reg_t grub_relocator_xen_entry_point; +extern grub_xen_reg_t grub_relocator_xen_paging_start; +extern grub_xen_reg_t grub_relocator_xen_paging_size; extern grub_xen_reg_t grub_relocator_xen_remapper_virt; extern grub_xen_reg_t grub_relocator_xen_remapper_virt2; extern grub_xen_reg_t grub_relocator_xen_remapper_map; extern grub_xen_reg_t grub_relocator_xen_mfn_list; -extern struct grub_relocator_xen_paging_area - grub_relocator_xen_paging_areas[XEN_MAX_MAPPINGS]; extern grub_xen_reg_t grub_relocator_xen_remap_continue; #ifdef __i386__ extern grub_xen_reg_t grub_relocator_xen_mmu_op_addr; -extern grub_xen_reg_t grub_relocator_xen_paging_areas_addr; extern grub_xen_reg_t grub_relocator_xen_remapper_map_high; #endif extern mmuext_op_t grub_relocator_xen_mmu_op[3]; @@ -67,7 +61,6 @@ grub_relocator_xen_boot (struct grub_relocator *rel, { grub_err_t err; void *relst; - int i; grub_relocator_chunk_t ch, ch_tramp; grub_xen_mfn_t *mfn_list = (grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list; @@ -84,11 +77,8 @@ grub_relocator_xen_boot (struct grub_relocator *rel, grub_relocator_xen_stack = state.stack; grub_relocator_xen_start_info = state.start_info; grub_relocator_xen_entry_point = state.entry_point; - for (i = 0; i < XEN_MAX_MAPPINGS; i++) - { - grub_relocator_xen_paging_areas[i].start = state.paging_start[i]; - grub_relocator_xen_paging_areas[i].size = state.paging_size[i]; - } + grub_relocator_xen_paging_start = state.paging_start << 12; + grub_relocator_xen_paging_size = state.paging_size; grub_relocator_xen_remapper_virt = remapper_virt; grub_relocator_xen_remapper_virt2 = remapper_virt; grub_relocator_xen_remap_continue = trampoline_virt; @@ -98,12 +88,10 @@ grub_relocator_xen_boot (struct grub_relocator *rel, grub_relocator_xen_remapper_map_high = (mfn_list[remapper_pfn] >> 20); grub_relocator_xen_mmu_op_addr = (char *) &grub_relocator_xen_mmu_op - (char *) &grub_relocator_xen_remap_start + remapper_virt; - grub_relocator_xen_paging_areas_addr = - (char *) &grub_relocator_xen_paging_areas - - (char *) &grub_relocator_xen_remap_start + remapper_virt; #endif - grub_relocator_xen_mfn_list = state.mfn_list; + grub_relocator_xen_mfn_list = state.mfn_list + + state.paging_start * sizeof (grub_addr_t); grub_memset (grub_relocator_xen_mmu_op, 0, sizeof (grub_relocator_xen_mmu_op)); @@ -112,9 +100,9 @@ grub_relocator_xen_boot (struct grub_relocator *rel, #else grub_relocator_xen_mmu_op[0].cmd = MMUEXT_PIN_L4_TABLE; #endif - grub_relocator_xen_mmu_op[0].arg1.mfn = mfn_list[state.paging_start[0]]; + grub_relocator_xen_mmu_op[0].arg1.mfn = mfn_list[state.paging_start]; grub_relocator_xen_mmu_op[1].cmd = MMUEXT_NEW_BASEPTR; - grub_relocator_xen_mmu_op[1].arg1.mfn = mfn_list[state.paging_start[0]]; + grub_relocator_xen_mmu_op[1].arg1.mfn = mfn_list[state.paging_start]; grub_relocator_xen_mmu_op[2].cmd = MMUEXT_UNPIN_TABLE; grub_relocator_xen_mmu_op[2].arg1.mfn = mfn_list[grub_xen_start_page_addr->pt_base >> 12]; diff --git a/grub-core/lib/xzembed/xz.h b/grub-core/lib/xzembed/xz.h index f7b32d800..fe7158bb2 100644 --- a/grub-core/lib/xzembed/xz.h +++ b/grub-core/lib/xzembed/xz.h @@ -24,7 +24,6 @@ #ifndef XZ_H #define XZ_H -#include #include #include #include diff --git a/grub-core/lib/xzembed/xz_dec_lzma2.c b/grub-core/lib/xzembed/xz_dec_lzma2.c index af7b77079..8a2a1183d 100644 --- a/grub-core/lib/xzembed/xz_dec_lzma2.c +++ b/grub-core/lib/xzembed/xz_dec_lzma2.c @@ -1044,8 +1044,6 @@ enum xz_ret xz_dec_lzma2_run( s->lzma2.sequence = SEQ_LZMA_PREPARE; - /* Fall through */ - case SEQ_LZMA_PREPARE: if (s->lzma2.compressed < RC_INIT_BYTES) return XZ_DATA_ERROR; @@ -1056,8 +1054,6 @@ enum xz_ret xz_dec_lzma2_run( s->lzma2.compressed -= RC_INIT_BYTES; s->lzma2.sequence = SEQ_LZMA_RUN; - /* Fall through */ - case SEQ_LZMA_RUN: /* * Set dictionary limit to indicate how much we want diff --git a/grub-core/lib/xzembed/xz_dec_stream.c b/grub-core/lib/xzembed/xz_dec_stream.c index a29751e14..c16b13060 100644 --- a/grub-core/lib/xzembed/xz_dec_stream.c +++ b/grub-core/lib/xzembed/xz_dec_stream.c @@ -750,7 +750,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->sequence = SEQ_BLOCK_START; - /* FALLTHROUGH */ case SEQ_BLOCK_START: /* We need one byte of input to continue. */ if (b->in_pos == b->in_size) @@ -774,7 +773,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->temp.pos = 0; s->sequence = SEQ_BLOCK_HEADER; - /* FALLTHROUGH */ case SEQ_BLOCK_HEADER: if (!fill_temp(s, b)) return XZ_OK; @@ -785,7 +783,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->sequence = SEQ_BLOCK_UNCOMPRESS; - /* FALLTHROUGH */ case SEQ_BLOCK_UNCOMPRESS: ret = dec_block(s, b); if (ret != XZ_STREAM_END) @@ -813,7 +810,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->sequence = SEQ_BLOCK_CHECK; - /* FALLTHROUGH */ case SEQ_BLOCK_CHECK: ret = hash_validate(s, b, 0); if (ret != XZ_STREAM_END) @@ -862,7 +858,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->sequence = SEQ_INDEX_CRC32; - /* FALLTHROUGH */ case SEQ_INDEX_CRC32: ret = hash_validate(s, b, 1); if (ret != XZ_STREAM_END) @@ -871,7 +866,6 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->temp.size = STREAM_HEADER_SIZE; s->sequence = SEQ_STREAM_FOOTER; - /* FALLTHROUGH */ case SEQ_STREAM_FOOTER: if (!fill_temp(s, b)) return XZ_OK; diff --git a/grub-core/lib/zstd/bitstream.h b/grub-core/lib/zstd/bitstream.h deleted file mode 100644 index 2f91460c5..000000000 --- a/grub-core/lib/zstd/bitstream.h +++ /dev/null @@ -1,458 +0,0 @@ -/* ****************************************************************** - bitstream - Part of FSE library - Copyright (C) 2013-present, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - Source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ -#ifndef BITSTREAM_H_MODULE -#define BITSTREAM_H_MODULE - -#if defined (__cplusplus) -extern "C" { -#endif - -/* -* This API consists of small unitary functions, which must be inlined for best performance. -* Since link-time-optimization is not available for all compilers, -* these functions are defined into a .h to be included. -*/ - -/*-**************************************** -* Dependencies -******************************************/ -#include "mem.h" /* unaligned access routines */ -#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */ -#include "error_private.h" /* error codes and messages */ - - -/*========================================= -* Target specific -=========================================*/ -#if defined(__BMI__) && defined(__GNUC__) -# include /* support for bextr (experimental) */ -#endif - -#define STREAM_ACCUMULATOR_MIN_32 25 -#define STREAM_ACCUMULATOR_MIN_64 57 -#define STREAM_ACCUMULATOR_MIN ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64)) - - -/*-****************************************** -* bitStream encoding API (write forward) -********************************************/ -/* bitStream can mix input from multiple sources. - * A critical property of these streams is that they encode and decode in **reverse** direction. - * So the first bit sequence you add will be the last to be read, like a LIFO stack. - */ -typedef struct { - size_t bitContainer; - unsigned bitPos; - char* startPtr; - char* ptr; - char* endPtr; -} BIT_CStream_t; - -MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity); -MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits); -MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC); -MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC); - -/* Start with initCStream, providing the size of buffer to write into. -* bitStream will never write outside of this buffer. -* `dstCapacity` must be >= sizeof(bitD->bitContainer), otherwise @return will be an error code. -* -* bits are first added to a local register. -* Local register is size_t, hence 64-bits on 64-bits systems, or 32-bits on 32-bits systems. -* Writing data into memory is an explicit operation, performed by the flushBits function. -* Hence keep track how many bits are potentially stored into local register to avoid register overflow. -* After a flushBits, a maximum of 7 bits might still be stored into local register. -* -* Avoid storing elements of more than 24 bits if you want compatibility with 32-bits bitstream readers. -* -* Last operation is to close the bitStream. -* The function returns the final size of CStream in bytes. -* If data couldn't fit into `dstBuffer`, it will return a 0 ( == not storable) -*/ - - -/*-******************************************** -* bitStream decoding API (read backward) -**********************************************/ -typedef struct { - size_t bitContainer; - unsigned bitsConsumed; - const char* ptr; - const char* start; - const char* limitPtr; -} BIT_DStream_t; - -typedef enum { BIT_DStream_unfinished = 0, - BIT_DStream_endOfBuffer = 1, - BIT_DStream_completed = 2, - BIT_DStream_overflow = 3 } BIT_DStream_status; /* result of BIT_reloadDStream() */ - /* 1,2,4,8 would be better for bitmap combinations, but slows down performance a bit ... :( */ - -MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize); -MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits); -MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD); -MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD); - - -/* Start by invoking BIT_initDStream(). -* A chunk of the bitStream is then stored into a local register. -* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t). -* You can then retrieve bitFields stored into the local register, **in reverse order**. -* Local register is explicitly reloaded from memory by the BIT_reloadDStream() method. -* A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished. -* Otherwise, it can be less than that, so proceed accordingly. -* Checking if DStream has reached its end can be performed with BIT_endOfDStream(). -*/ - - -/*-**************************************** -* unsafe API -******************************************/ -MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, size_t value, unsigned nbBits); -/* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */ - -MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC); -/* unsafe version; does not check buffer overflow */ - -MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits); -/* faster, but works only if nbBits >= 1 */ - - - -/*-************************************************************** -* Internal functions -****************************************************************/ -MEM_STATIC unsigned BIT_highbit32 (U32 val) -{ - assert(val != 0); - { -# if defined(_MSC_VER) /* Visual */ - unsigned long r=0; - _BitScanReverse ( &r, val ); - return (unsigned) r; -# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ - return 31 - __builtin_clz (val); -# else /* Software version */ - static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, - 11, 14, 16, 18, 22, 25, 3, 30, - 8, 12, 20, 28, 15, 17, 24, 7, - 19, 27, 23, 6, 26, 5, 4, 31 }; - U32 v = val; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27]; -# endif - } -} - -/*===== Local Constants =====*/ -static const unsigned BIT_mask[] = { - 0, 1, 3, 7, 0xF, 0x1F, - 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, - 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, - 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, - 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF, - 0x3FFFFFFF, 0x7FFFFFFF}; /* up to 31 bits */ -#define BIT_MASK_SIZE (sizeof(BIT_mask) / sizeof(BIT_mask[0])) - -/*-************************************************************** -* bitStream encoding -****************************************************************/ -/*! BIT_initCStream() : - * `dstCapacity` must be > sizeof(size_t) - * @return : 0 if success, - * otherwise an error code (can be tested using ERR_isError()) */ -MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, - void* startPtr, size_t dstCapacity) -{ - bitC->bitContainer = 0; - bitC->bitPos = 0; - bitC->startPtr = (char*)startPtr; - bitC->ptr = bitC->startPtr; - bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); - if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); - return 0; -} - -/*! BIT_addBits() : - * can add up to 31 bits into `bitC`. - * Note : does not check for register overflow ! */ -MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, - size_t value, unsigned nbBits) -{ - MEM_STATIC_ASSERT(BIT_MASK_SIZE == 32); - assert(nbBits < BIT_MASK_SIZE); - assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); - bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos; - bitC->bitPos += nbBits; -} - -/*! BIT_addBitsFast() : - * works only if `value` is _clean_, - * meaning all high bits above nbBits are 0 */ -MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, - size_t value, unsigned nbBits) -{ - assert((value>>nbBits) == 0); - assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); - bitC->bitContainer |= value << bitC->bitPos; - bitC->bitPos += nbBits; -} - -/*! BIT_flushBitsFast() : - * assumption : bitContainer has not overflowed - * unsafe version; does not check buffer overflow */ -MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC) -{ - size_t const nbBytes = bitC->bitPos >> 3; - assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); - MEM_writeLEST(bitC->ptr, bitC->bitContainer); - bitC->ptr += nbBytes; - assert(bitC->ptr <= bitC->endPtr); - bitC->bitPos &= 7; - bitC->bitContainer >>= nbBytes*8; -} - -/*! BIT_flushBits() : - * assumption : bitContainer has not overflowed - * safe version; check for buffer overflow, and prevents it. - * note : does not signal buffer overflow. - * overflow will be revealed later on using BIT_closeCStream() */ -MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC) -{ - size_t const nbBytes = bitC->bitPos >> 3; - assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); - MEM_writeLEST(bitC->ptr, bitC->bitContainer); - bitC->ptr += nbBytes; - if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; - bitC->bitPos &= 7; - bitC->bitContainer >>= nbBytes*8; -} - -/*! BIT_closeCStream() : - * @return : size of CStream, in bytes, - * or 0 if it could not fit into dstBuffer */ -MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC) -{ - BIT_addBitsFast(bitC, 1, 1); /* endMark */ - BIT_flushBits(bitC); - if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ - return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); -} - - -/*-******************************************************** -* bitStream decoding -**********************************************************/ -/*! BIT_initDStream() : - * Initialize a BIT_DStream_t. - * `bitD` : a pointer to an already allocated BIT_DStream_t structure. - * `srcSize` must be the *exact* size of the bitStream, in bytes. - * @return : size of stream (== srcSize), or an errorCode if a problem is detected - */ -MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize) -{ - if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } - - bitD->start = (const char*)srcBuffer; - bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); - - if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ - bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); - bitD->bitContainer = MEM_readLEST(bitD->ptr); - { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; - bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ - if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } - } else { - bitD->ptr = bitD->start; - bitD->bitContainer = *(const BYTE*)(bitD->start); - switch(srcSize) - { - case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); - /* fall-through */ - - case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); - /* fall-through */ - - case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); - /* fall-through */ - - case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24; - /* fall-through */ - - case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16; - /* fall-through */ - - case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8; - /* fall-through */ - - default: break; - } - { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; - bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; - if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ - } - bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; - } - - return srcSize; -} - -MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start) -{ - return bitContainer >> start; -} - -MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits) -{ -#if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008 /* experimental */ -# if defined(__x86_64__) - if (sizeof(bitContainer)==8) - return _bextr_u64(bitContainer, start, nbBits); - else -# endif - return _bextr_u32(bitContainer, start, nbBits); -#else - assert(nbBits < BIT_MASK_SIZE); - return (bitContainer >> start) & BIT_mask[nbBits]; -#endif -} - -MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits) -{ - assert(nbBits < BIT_MASK_SIZE); - return bitContainer & BIT_mask[nbBits]; -} - -/*! BIT_lookBits() : - * Provides next n bits from local register. - * local register is not modified. - * On 32-bits, maxNbBits==24. - * On 64-bits, maxNbBits==56. - * @return : value extracted */ -MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits) -{ -#if defined(__BMI__) && defined(__GNUC__) /* experimental; fails if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8 */ - return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits); -#else - U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; - return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask); -#endif -} - -/*! BIT_lookBitsFast() : - * unsafe version; only works if nbBits >= 1 */ -MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits) -{ - U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; - assert(nbBits >= 1); - return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); -} - -MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits) -{ - bitD->bitsConsumed += nbBits; -} - -/*! BIT_readBits() : - * Read (consume) next n bits from local register and update. - * Pay attention to not read more than nbBits contained into local register. - * @return : extracted value. */ -MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits) -{ - size_t const value = BIT_lookBits(bitD, nbBits); - BIT_skipBits(bitD, nbBits); - return value; -} - -/*! BIT_readBitsFast() : - * unsafe version; only works only if nbBits >= 1 */ -MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits) -{ - size_t const value = BIT_lookBitsFast(bitD, nbBits); - assert(nbBits >= 1); - BIT_skipBits(bitD, nbBits); - return value; -} - -/*! BIT_reloadDStream() : - * Refill `bitD` from buffer previously set in BIT_initDStream() . - * This function is safe, it guarantees it will not read beyond src buffer. - * @return : status of `BIT_DStream_t` internal register. - * when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */ -MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD) -{ - if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */ - return BIT_DStream_overflow; - - if (bitD->ptr >= bitD->limitPtr) { - bitD->ptr -= bitD->bitsConsumed >> 3; - bitD->bitsConsumed &= 7; - bitD->bitContainer = MEM_readLEST(bitD->ptr); - return BIT_DStream_unfinished; - } - if (bitD->ptr == bitD->start) { - if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; - return BIT_DStream_completed; - } - /* start < ptr < limitPtr */ - { U32 nbBytes = bitD->bitsConsumed >> 3; - BIT_DStream_status result = BIT_DStream_unfinished; - if (bitD->ptr - nbBytes < bitD->start) { - nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ - result = BIT_DStream_endOfBuffer; - } - bitD->ptr -= nbBytes; - bitD->bitsConsumed -= nbBytes*8; - bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ - return result; - } -} - -/*! BIT_endOfDStream() : - * @return : 1 if DStream has _exactly_ reached its end (all bits consumed). - */ -MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream) -{ - return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); -} - -#if defined (__cplusplus) -} -#endif - -#endif /* BITSTREAM_H_MODULE */ diff --git a/grub-core/lib/zstd/compiler.h b/grub-core/lib/zstd/compiler.h deleted file mode 100644 index 07f875e4d..000000000 --- a/grub-core/lib/zstd/compiler.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -#ifndef ZSTD_COMPILER_H -#define ZSTD_COMPILER_H - -/*-******************************************************* -* Compiler specifics -*********************************************************/ -/* force inlining */ -#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ -# define INLINE_KEYWORD inline -#else -# define INLINE_KEYWORD -#endif - -#if defined(__GNUC__) -# define FORCE_INLINE_ATTR __attribute__((always_inline)) -#elif defined(_MSC_VER) -# define FORCE_INLINE_ATTR __forceinline -#else -# define FORCE_INLINE_ATTR -#endif - -/** - * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant - * parameters. They must be inlined for the compiler to elimininate the constant - * branches. - */ -#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR -/** - * HINT_INLINE is used to help the compiler generate better code. It is *not* - * used for "templates", so it can be tweaked based on the compilers - * performance. - * - * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the - * always_inline attribute. - * - * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline - * attribute. - */ -#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5 -# define HINT_INLINE static INLINE_KEYWORD -#else -# define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR -#endif - -/* force no inlining */ -#ifdef _MSC_VER -# define FORCE_NOINLINE static __declspec(noinline) -#else -# ifdef __GNUC__ -# define FORCE_NOINLINE static __attribute__((__noinline__)) -# else -# define FORCE_NOINLINE static -# endif -#endif - -/* target attribute */ -#ifndef __has_attribute - #define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ -#endif -#if defined(__GNUC__) -# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target))) -#else -# define TARGET_ATTRIBUTE(target) -#endif - -/* Enable runtime BMI2 dispatch based on the CPU. - * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default. - */ -#ifndef DYNAMIC_BMI2 - #if ((defined(__clang__) && __has_attribute(__target__)) \ - || (defined(__GNUC__) \ - && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \ - && (defined(__x86_64__) || defined(_M_X86)) \ - && !defined(__BMI2__) - # define DYNAMIC_BMI2 1 - #else - # define DYNAMIC_BMI2 0 - #endif -#endif - -/* prefetch - * can be disabled, by declaring NO_PREFETCH macro - * All prefetch invocations use a single default locality 2, - * generating instruction prefetcht1, - * which, according to Intel, means "load data into L2 cache". - * This is a good enough "middle ground" for the time being, - * though in theory, it would be better to specialize locality depending on data being prefetched. - * Tests could not determine any sensible difference based on locality value. */ -#if defined(NO_PREFETCH) -# define PREFETCH(ptr) (void)(ptr) /* disabled */ -#else -# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */ -# include /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ -# define PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1) -# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) ) -# define PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */) -# else -# define PREFETCH(ptr) (void)(ptr) /* disabled */ -# endif -#endif /* NO_PREFETCH */ - -#define CACHELINE_SIZE 64 - -#define PREFETCH_AREA(p, s) { \ - const char* const _ptr = (const char*)(p); \ - size_t const _size = (size_t)(s); \ - size_t _pos; \ - for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \ - PREFETCH(_ptr + _pos); \ - } \ -} - -/* disable warnings */ -#ifdef _MSC_VER /* Visual Studio */ -# include /* For Visual 2005 */ -# pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */ -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -# pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */ -# pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */ -# pragma warning(disable : 4324) /* disable: C4324: padded structure */ -#endif - -#endif /* ZSTD_COMPILER_H */ diff --git a/grub-core/lib/zstd/cpu.h b/grub-core/lib/zstd/cpu.h deleted file mode 100644 index eeb428ad5..000000000 --- a/grub-core/lib/zstd/cpu.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2018-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -#ifndef ZSTD_COMMON_CPU_H -#define ZSTD_COMMON_CPU_H - -/** - * Implementation taken from folly/CpuId.h - * https://github.com/facebook/folly/blob/master/folly/CpuId.h - */ - -#include - -#include "mem.h" - -#ifdef _MSC_VER -#include -#endif - -typedef struct { - U32 f1c; - U32 f1d; - U32 f7b; - U32 f7c; -} ZSTD_cpuid_t; - -MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) { - U32 f1c = 0; - U32 f1d = 0; - U32 f7b = 0; - U32 f7c = 0; -#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) - int reg[4]; - __cpuid((int*)reg, 0); - { - int const n = reg[0]; - if (n >= 1) { - __cpuid((int*)reg, 1); - f1c = (U32)reg[2]; - f1d = (U32)reg[3]; - } - if (n >= 7) { - __cpuidex((int*)reg, 7, 0); - f7b = (U32)reg[1]; - f7c = (U32)reg[2]; - } - } -#elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__) - /* The following block like the normal cpuid branch below, but gcc - * reserves ebx for use of its pic register so we must specially - * handle the save and restore to avoid clobbering the register - */ - U32 n; - __asm__( - "pushl %%ebx\n\t" - "cpuid\n\t" - "popl %%ebx\n\t" - : "=a"(n) - : "a"(0) - : "ecx", "edx"); - if (n >= 1) { - U32 f1a; - __asm__( - "pushl %%ebx\n\t" - "cpuid\n\t" - "popl %%ebx\n\t" - : "=a"(f1a), "=c"(f1c), "=d"(f1d) - : "a"(1)); - } - if (n >= 7) { - __asm__( - "pushl %%ebx\n\t" - "cpuid\n\t" - "movl %%ebx, %%eax\n\r" - "popl %%ebx" - : "=a"(f7b), "=c"(f7c) - : "a"(7), "c"(0) - : "edx"); - } -#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__) - U32 n; - __asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx"); - if (n >= 1) { - U32 f1a; - __asm__("cpuid" : "=a"(f1a), "=c"(f1c), "=d"(f1d) : "a"(1) : "ebx"); - } - if (n >= 7) { - U32 f7a; - __asm__("cpuid" - : "=a"(f7a), "=b"(f7b), "=c"(f7c) - : "a"(7), "c"(0) - : "edx"); - } -#endif - { - ZSTD_cpuid_t cpuid; - cpuid.f1c = f1c; - cpuid.f1d = f1d; - cpuid.f7b = f7b; - cpuid.f7c = f7c; - return cpuid; - } -} - -#define X(name, r, bit) \ - MEM_STATIC int ZSTD_cpuid_##name(ZSTD_cpuid_t const cpuid) { \ - return ((cpuid.r) & (1U << bit)) != 0; \ - } - -/* cpuid(1): Processor Info and Feature Bits. */ -#define C(name, bit) X(name, f1c, bit) - C(sse3, 0) - C(pclmuldq, 1) - C(dtes64, 2) - C(monitor, 3) - C(dscpl, 4) - C(vmx, 5) - C(smx, 6) - C(eist, 7) - C(tm2, 8) - C(ssse3, 9) - C(cnxtid, 10) - C(fma, 12) - C(cx16, 13) - C(xtpr, 14) - C(pdcm, 15) - C(pcid, 17) - C(dca, 18) - C(sse41, 19) - C(sse42, 20) - C(x2apic, 21) - C(movbe, 22) - C(popcnt, 23) - C(tscdeadline, 24) - C(aes, 25) - C(xsave, 26) - C(osxsave, 27) - C(avx, 28) - C(f16c, 29) - C(rdrand, 30) -#undef C -#define D(name, bit) X(name, f1d, bit) - D(fpu, 0) - D(vme, 1) - D(de, 2) - D(pse, 3) - D(tsc, 4) - D(msr, 5) - D(pae, 6) - D(mce, 7) - D(cx8, 8) - D(apic, 9) - D(sep, 11) - D(mtrr, 12) - D(pge, 13) - D(mca, 14) - D(cmov, 15) - D(pat, 16) - D(pse36, 17) - D(psn, 18) - D(clfsh, 19) - D(ds, 21) - D(acpi, 22) - D(mmx, 23) - D(fxsr, 24) - D(sse, 25) - D(sse2, 26) - D(ss, 27) - D(htt, 28) - D(tm, 29) - D(pbe, 31) -#undef D - -/* cpuid(7): Extended Features. */ -#define B(name, bit) X(name, f7b, bit) - B(bmi1, 3) - B(hle, 4) - B(avx2, 5) - B(smep, 7) - B(bmi2, 8) - B(erms, 9) - B(invpcid, 10) - B(rtm, 11) - B(mpx, 14) - B(avx512f, 16) - B(avx512dq, 17) - B(rdseed, 18) - B(adx, 19) - B(smap, 20) - B(avx512ifma, 21) - B(pcommit, 22) - B(clflushopt, 23) - B(clwb, 24) - B(avx512pf, 26) - B(avx512er, 27) - B(avx512cd, 28) - B(sha, 29) - B(avx512bw, 30) - B(avx512vl, 31) -#undef B -#define C(name, bit) X(name, f7c, bit) - C(prefetchwt1, 0) - C(avx512vbmi, 1) -#undef C - -#undef X - -#endif /* ZSTD_COMMON_CPU_H */ diff --git a/grub-core/lib/zstd/debug.c b/grub-core/lib/zstd/debug.c deleted file mode 100644 index 3ebdd1cb1..000000000 --- a/grub-core/lib/zstd/debug.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ****************************************************************** - debug - Part of FSE library - Copyright (C) 2013-present, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - Source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ - - -/* - * This module only hosts one global variable - * which can be used to dynamically influence the verbosity of traces, - * such as DEBUGLOG and RAWLOG - */ - -#include "debug.h" - -int g_debuglevel = DEBUGLEVEL; diff --git a/grub-core/lib/zstd/debug.h b/grub-core/lib/zstd/debug.h deleted file mode 100644 index 0c04ad2cc..000000000 --- a/grub-core/lib/zstd/debug.h +++ /dev/null @@ -1,123 +0,0 @@ -/* ****************************************************************** - debug - Part of FSE library - Copyright (C) 2013-present, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - Source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ - - -/* - * The purpose of this header is to enable debug functions. - * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time, - * and DEBUG_STATIC_ASSERT() for compile-time. - * - * By default, DEBUGLEVEL==0, which means run-time debug is disabled. - * - * Level 1 enables assert() only. - * Starting level 2, traces can be generated and pushed to stderr. - * The higher the level, the more verbose the traces. - * - * It's possible to dynamically adjust level using variable g_debug_level, - * which is only declared if DEBUGLEVEL>=2, - * and is a global variable, not multi-thread protected (use with care) - */ - -#ifndef DEBUG_H_12987983217 -#define DEBUG_H_12987983217 - -#if defined (__cplusplus) -extern "C" { -#endif - - -/* static assert is triggered at compile time, leaving no runtime artefact, - * but can only work with compile-time constants. - * This variant can only be used inside a function. */ -#define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1]) - - -/* DEBUGLEVEL is expected to be defined externally, - * typically through compiler command line. - * Value must be a number. */ -#ifndef DEBUGLEVEL -# define DEBUGLEVEL 0 -#endif - -/* recommended values for DEBUGLEVEL : - * 0 : no debug, all run-time functions disabled - * 1 : no display, enables assert() only - * 2 : reserved, for currently active debug path - * 3 : events once per object lifetime (CCtx, CDict, etc.) - * 4 : events once per frame - * 5 : events once per block - * 6 : events once per sequence (verbose) - * 7+: events at every position (*very* verbose) - * - * It's generally inconvenient to output traces > 5. - * In which case, it's possible to selectively enable higher verbosity levels - * by modifying g_debug_level. - */ - -#if (DEBUGLEVEL>=1) -# include -#else -# ifndef assert /* assert may be already defined, due to prior #include */ -# define assert(condition) ((void)0) /* disable assert (default) */ -# endif -#endif - -#if (DEBUGLEVEL>=2) -# include -extern int g_debuglevel; /* here, this variable is only declared, - it actually lives in debug.c, - and is shared by the whole process. - It's typically used to enable very verbose levels - on selective conditions (such as position in src) */ - -# define RAWLOG(l, ...) { \ - if (l<=g_debuglevel) { \ - fprintf(stderr, __VA_ARGS__); \ - } } -# define DEBUGLOG(l, ...) { \ - if (l<=g_debuglevel) { \ - fprintf(stderr, __FILE__ ": " __VA_ARGS__); \ - fprintf(stderr, " \n"); \ - } } -#else -# define RAWLOG(l, ...) {} /* disabled */ -# define DEBUGLOG(l, ...) {} /* disabled */ -#endif - - -#if defined (__cplusplus) -} -#endif - -#endif /* DEBUG_H_12987983217 */ diff --git a/grub-core/lib/zstd/entropy_common.c b/grub-core/lib/zstd/entropy_common.c deleted file mode 100644 index b12944e1d..000000000 --- a/grub-core/lib/zstd/entropy_common.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - Common functions of New Generation Entropy library - Copyright (C) 2016, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy - - Public forum : https://groups.google.com/forum/#!forum/lz4c -*************************************************************************** */ - -/* ************************************* -* Dependencies -***************************************/ -#include "mem.h" -#include "error_private.h" /* ERR_*, ERROR */ -#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */ -#include "fse.h" -#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */ -#include "huf.h" - - -/*=== Version ===*/ -unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; } - - -/*=== Error Management ===*/ -unsigned FSE_isError(size_t code) { return ERR_isError(code); } -const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); } - -unsigned HUF_isError(size_t code) { return ERR_isError(code); } -const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); } - - -/*-************************************************************** -* FSE NCount encoding-decoding -****************************************************************/ -size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr, - const void* headerBuffer, size_t hbSize) -{ - const BYTE* const istart = (const BYTE*) headerBuffer; - const BYTE* const iend = istart + hbSize; - const BYTE* ip = istart; - int nbBits; - int remaining; - int threshold; - U32 bitStream; - int bitCount; - unsigned charnum = 0; - int previous0 = 0; - - if (hbSize < 4) { - /* This function only works when hbSize >= 4 */ - char buffer[4]; - memset(buffer, 0, sizeof(buffer)); - memcpy(buffer, headerBuffer, hbSize); - { size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr, - buffer, sizeof(buffer)); - if (FSE_isError(countSize)) return countSize; - if (countSize > hbSize) return ERROR(corruption_detected); - return countSize; - } } - assert(hbSize >= 4); - - /* init */ - memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */ - bitStream = MEM_readLE32(ip); - nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */ - if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge); - bitStream >>= 4; - bitCount = 4; - *tableLogPtr = nbBits; - remaining = (1<1) & (charnum<=*maxSVPtr)) { - if (previous0) { - unsigned n0 = charnum; - while ((bitStream & 0xFFFF) == 0xFFFF) { - n0 += 24; - if (ip < iend-5) { - ip += 2; - bitStream = MEM_readLE32(ip) >> bitCount; - } else { - bitStream >>= 16; - bitCount += 16; - } } - while ((bitStream & 3) == 3) { - n0 += 3; - bitStream >>= 2; - bitCount += 2; - } - n0 += bitStream & 3; - bitCount += 2; - if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall); - while (charnum < n0) normalizedCounter[charnum++] = 0; - if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { - assert((bitCount >> 3) <= 3); /* For first condition to work */ - ip += bitCount>>3; - bitCount &= 7; - bitStream = MEM_readLE32(ip) >> bitCount; - } else { - bitStream >>= 2; - } } - { int const max = (2*threshold-1) - remaining; - int count; - - if ((bitStream & (threshold-1)) < (U32)max) { - count = bitStream & (threshold-1); - bitCount += nbBits-1; - } else { - count = bitStream & (2*threshold-1); - if (count >= threshold) count -= max; - bitCount += nbBits; - } - - count--; /* extra accuracy */ - remaining -= count < 0 ? -count : count; /* -1 means +1 */ - normalizedCounter[charnum++] = (short)count; - previous0 = !count; - while (remaining < threshold) { - nbBits--; - threshold >>= 1; - } - - if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { - ip += bitCount>>3; - bitCount &= 7; - } else { - bitCount -= (int)(8 * (iend - 4 - ip)); - ip = iend - 4; - } - bitStream = MEM_readLE32(ip) >> (bitCount & 31); - } } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */ - if (remaining != 1) return ERROR(corruption_detected); - if (bitCount > 32) return ERROR(corruption_detected); - *maxSVPtr = charnum-1; - - ip += (bitCount+7)>>3; - return ip-istart; -} - - -/*! HUF_readStats() : - Read compact Huffman tree, saved by HUF_writeCTable(). - `huffWeight` is destination buffer. - `rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32. - @return : size read from `src` , or an error Code . - Note : Needed by HUF_readCTable() and HUF_readDTableX?() . -*/ -size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats, - U32* nbSymbolsPtr, U32* tableLogPtr, - const void* src, size_t srcSize) -{ - U32 weightTotal; - const BYTE* ip = (const BYTE*) src; - size_t iSize; - size_t oSize; - - if (!srcSize) return ERROR(srcSize_wrong); - iSize = ip[0]; - /* memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */ - - if (iSize >= 128) { /* special header */ - oSize = iSize - 127; - iSize = ((oSize+1)/2); - if (iSize+1 > srcSize) return ERROR(srcSize_wrong); - if (oSize >= hwSize) return ERROR(corruption_detected); - ip += 1; - { U32 n; - for (n=0; n> 4; - huffWeight[n+1] = ip[n/2] & 15; - } } } - else { /* header compressed with FSE (normal case) */ - FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */ - if (iSize+1 > srcSize) return ERROR(srcSize_wrong); - oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */ - if (FSE_isError(oSize)) return oSize; - } - - /* collect weight stats */ - memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32)); - weightTotal = 0; - { U32 n; for (n=0; n= HUF_TABLELOG_MAX) return ERROR(corruption_detected); - rankStats[huffWeight[n]]++; - weightTotal += (1 << huffWeight[n]) >> 1; - } } - if (weightTotal == 0) return ERROR(corruption_detected); - - /* get last non-null symbol weight (implied, total must be 2^n) */ - { U32 const tableLog = BIT_highbit32(weightTotal) + 1; - if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected); - *tableLogPtr = tableLog; - /* determine last weight */ - { U32 const total = 1 << tableLog; - U32 const rest = total - weightTotal; - U32 const verif = 1 << BIT_highbit32(rest); - U32 const lastWeight = BIT_highbit32(rest) + 1; - if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */ - huffWeight[oSize] = (BYTE)lastWeight; - rankStats[lastWeight]++; - } } - - /* check tree construction validity */ - if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */ - - /* results */ - *nbSymbolsPtr = (U32)(oSize+1); - return iSize+1; -} diff --git a/grub-core/lib/zstd/error_private.c b/grub-core/lib/zstd/error_private.c deleted file mode 100644 index d004ee636..000000000 --- a/grub-core/lib/zstd/error_private.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -/* The purpose of this file is to have a single list of error strings embedded in binary */ - -#include "error_private.h" - -const char* ERR_getErrorString(ERR_enum code) -{ - static const char* const notErrorCode = "Unspecified error code"; - switch( code ) - { - case PREFIX(no_error): return "No error detected"; - case PREFIX(GENERIC): return "Error (generic)"; - case PREFIX(prefix_unknown): return "Unknown frame descriptor"; - case PREFIX(version_unsupported): return "Version not supported"; - case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter"; - case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding"; - case PREFIX(corruption_detected): return "Corrupted block detected"; - case PREFIX(checksum_wrong): return "Restored data doesn't match checksum"; - case PREFIX(parameter_unsupported): return "Unsupported parameter"; - case PREFIX(parameter_outOfBound): return "Parameter is out of bound"; - case PREFIX(init_missing): return "Context should be init first"; - case PREFIX(memory_allocation): return "Allocation error : not enough memory"; - case PREFIX(workSpace_tooSmall): return "workSpace buffer is not large enough"; - case PREFIX(stage_wrong): return "Operation not authorized at current processing stage"; - case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported"; - case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large"; - case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; - case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; - case PREFIX(dictionary_wrong): return "Dictionary mismatch"; - case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples"; - case PREFIX(dstSize_tooSmall): return "Destination buffer is too small"; - case PREFIX(srcSize_wrong): return "Src size is incorrect"; - /* following error codes are not stable and may be removed or changed in a future version */ - case PREFIX(frameIndex_tooLarge): return "Frame index is too large"; - case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking"; - case PREFIX(maxCode): - default: return notErrorCode; - } -} diff --git a/grub-core/lib/zstd/error_private.h b/grub-core/lib/zstd/error_private.h deleted file mode 100644 index 0d2fa7e34..000000000 --- a/grub-core/lib/zstd/error_private.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -/* Note : this module is expected to remain private, do not expose it */ - -#ifndef ERROR_H_MODULE -#define ERROR_H_MODULE - -#if defined (__cplusplus) -extern "C" { -#endif - - -/* **************************************** -* Dependencies -******************************************/ -#include /* size_t */ -#include "zstd_errors.h" /* enum list */ - - -/* **************************************** -* Compiler-specific -******************************************/ -#if defined(__GNUC__) -# define ERR_STATIC static __attribute__((unused)) -#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) -# define ERR_STATIC static inline -#elif defined(_MSC_VER) -# define ERR_STATIC static __inline -#else -# define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ -#endif - - -/*-**************************************** -* Customization (error_public.h) -******************************************/ -typedef ZSTD_ErrorCode ERR_enum; -#define PREFIX(name) ZSTD_error_##name - - -/*-**************************************** -* Error codes handling -******************************************/ -#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ -#define ERROR(name) ZSTD_ERROR(name) -#define ZSTD_ERROR(name) ((size_t)-PREFIX(name)) - -ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } - -ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } - - -/*-**************************************** -* Error Strings -******************************************/ - -const char* ERR_getErrorString(ERR_enum code); /* error_private.c */ - -ERR_STATIC const char* ERR_getErrorName(size_t code) -{ - return ERR_getErrorString(ERR_getErrorCode(code)); -} - -#if defined (__cplusplus) -} -#endif - -#endif /* ERROR_H_MODULE */ diff --git a/grub-core/lib/zstd/fse.h b/grub-core/lib/zstd/fse.h deleted file mode 100644 index a5a6b6d4d..000000000 --- a/grub-core/lib/zstd/fse.h +++ /dev/null @@ -1,708 +0,0 @@ -/* ****************************************************************** - FSE : Finite State Entropy codec - Public Prototypes declaration - Copyright (C) 2013-2016, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - Source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ - -#if defined (__cplusplus) -extern "C" { -#endif - -#ifndef FSE_H -#define FSE_H - - -/*-***************************************** -* Dependencies -******************************************/ -#include /* size_t, ptrdiff_t */ - - -/*-***************************************** -* FSE_PUBLIC_API : control library symbols visibility -******************************************/ -#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) -# define FSE_PUBLIC_API __attribute__ ((visibility ("default"))) -#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ -# define FSE_PUBLIC_API __declspec(dllexport) -#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) -# define FSE_PUBLIC_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ -#else -# define FSE_PUBLIC_API -#endif - -/*------ Version ------*/ -#define FSE_VERSION_MAJOR 0 -#define FSE_VERSION_MINOR 9 -#define FSE_VERSION_RELEASE 0 - -#define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE -#define FSE_QUOTE(str) #str -#define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str) -#define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION) - -#define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE) -FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */ - - -/*-**************************************** -* FSE simple functions -******************************************/ -/*! FSE_compress() : - Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'. - 'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize). - @return : size of compressed data (<= dstCapacity). - Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! - if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead. - if FSE_isError(return), compression failed (more details using FSE_getErrorName()) -*/ -FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity, - const void* src, size_t srcSize); - -/*! FSE_decompress(): - Decompress FSE data from buffer 'cSrc', of size 'cSrcSize', - into already allocated destination buffer 'dst', of size 'dstCapacity'. - @return : size of regenerated data (<= maxDstSize), - or an error code, which can be tested using FSE_isError() . - - ** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!! - Why ? : making this distinction requires a header. - Header management is intentionally delegated to the user layer, which can better manage special cases. -*/ -FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity, - const void* cSrc, size_t cSrcSize); - - -/*-***************************************** -* Tool functions -******************************************/ -FSE_PUBLIC_API size_t FSE_compressBound(size_t size); /* maximum compressed size */ - -/* Error Management */ -FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return value is an error code */ -FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */ - - -/*-***************************************** -* FSE advanced functions -******************************************/ -/*! FSE_compress2() : - Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog' - Both parameters can be defined as '0' to mean : use default value - @return : size of compressed data - Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!! - if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression. - if FSE_isError(return), it's an error code. -*/ -FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); - - -/*-***************************************** -* FSE detailed API -******************************************/ -/*! -FSE_compress() does the following: -1. count symbol occurrence from source[] into table count[] (see hist.h) -2. normalize counters so that sum(count[]) == Power_of_2 (2^tableLog) -3. save normalized counters to memory buffer using writeNCount() -4. build encoding table 'CTable' from normalized counters -5. encode the data stream using encoding table 'CTable' - -FSE_decompress() does the following: -1. read normalized counters with readNCount() -2. build decoding table 'DTable' from normalized counters -3. decode the data stream using decoding table 'DTable' - -The following API allows targeting specific sub-functions for advanced tasks. -For example, it's possible to compress several blocks using the same 'CTable', -or to save and provide normalized distribution using external method. -*/ - -/* *** COMPRESSION *** */ - -/*! FSE_optimalTableLog(): - dynamically downsize 'tableLog' when conditions are met. - It saves CPU time, by using smaller tables, while preserving or even improving compression ratio. - @return : recommended tableLog (necessarily <= 'maxTableLog') */ -FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); - -/*! FSE_normalizeCount(): - normalize counts so that sum(count[]) == Power_of_2 (2^tableLog) - 'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1). - @return : tableLog, - or an errorCode, which can be tested using FSE_isError() */ -FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, - const unsigned* count, size_t srcSize, unsigned maxSymbolValue); - -/*! FSE_NCountWriteBound(): - Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'. - Typically useful for allocation purpose. */ -FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog); - -/*! FSE_writeNCount(): - Compactly save 'normalizedCounter' into 'buffer'. - @return : size of the compressed table, - or an errorCode, which can be tested using FSE_isError(). */ -FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, - const short* normalizedCounter, - unsigned maxSymbolValue, unsigned tableLog); - -/*! Constructor and Destructor of FSE_CTable. - Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */ -typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */ -FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog); -FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct); - -/*! FSE_buildCTable(): - Builds `ct`, which must be already allocated, using FSE_createCTable(). - @return : 0, or an errorCode, which can be tested using FSE_isError() */ -FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); - -/*! FSE_compress_usingCTable(): - Compress `src` using `ct` into `dst` which must be already allocated. - @return : size of compressed data (<= `dstCapacity`), - or 0 if compressed data could not fit into `dst`, - or an errorCode, which can be tested using FSE_isError() */ -FSE_PUBLIC_API size_t FSE_compress_usingCTable (void* dst, size_t dstCapacity, const void* src, size_t srcSize, const FSE_CTable* ct); - -/*! -Tutorial : ----------- -The first step is to count all symbols. FSE_count() does this job very fast. -Result will be saved into 'count', a table of unsigned int, which must be already allocated, and have 'maxSymbolValuePtr[0]+1' cells. -'src' is a table of bytes of size 'srcSize'. All values within 'src' MUST be <= maxSymbolValuePtr[0] -maxSymbolValuePtr[0] will be updated, with its real value (necessarily <= original value) -FSE_count() will return the number of occurrence of the most frequent symbol. -This can be used to know if there is a single symbol within 'src', and to quickly evaluate its compressibility. -If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). - -The next step is to normalize the frequencies. -FSE_normalizeCount() will ensure that sum of frequencies is == 2 ^'tableLog'. -It also guarantees a minimum of 1 to any Symbol with frequency >= 1. -You can use 'tableLog'==0 to mean "use default tableLog value". -If you are unsure of which tableLog value to use, you can ask FSE_optimalTableLog(), -which will provide the optimal valid tableLog given sourceSize, maxSymbolValue, and a user-defined maximum (0 means "default"). - -The result of FSE_normalizeCount() will be saved into a table, -called 'normalizedCounter', which is a table of signed short. -'normalizedCounter' must be already allocated, and have at least 'maxSymbolValue+1' cells. -The return value is tableLog if everything proceeded as expected. -It is 0 if there is a single symbol within distribution. -If there is an error (ex: invalid tableLog value), the function will return an ErrorCode (which can be tested using FSE_isError()). - -'normalizedCounter' can be saved in a compact manner to a memory area using FSE_writeNCount(). -'buffer' must be already allocated. -For guaranteed success, buffer size must be at least FSE_headerBound(). -The result of the function is the number of bytes written into 'buffer'. -If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError(); ex : buffer size too small). - -'normalizedCounter' can then be used to create the compression table 'CTable'. -The space required by 'CTable' must be already allocated, using FSE_createCTable(). -You can then use FSE_buildCTable() to fill 'CTable'. -If there is an error, both functions will return an ErrorCode (which can be tested using FSE_isError()). - -'CTable' can then be used to compress 'src', with FSE_compress_usingCTable(). -Similar to FSE_count(), the convention is that 'src' is assumed to be a table of char of size 'srcSize' -The function returns the size of compressed data (without header), necessarily <= `dstCapacity`. -If it returns '0', compressed data could not fit into 'dst'. -If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). -*/ - - -/* *** DECOMPRESSION *** */ - -/*! FSE_readNCount(): - Read compactly saved 'normalizedCounter' from 'rBuffer'. - @return : size read from 'rBuffer', - or an errorCode, which can be tested using FSE_isError(). - maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */ -FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter, - unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, - const void* rBuffer, size_t rBuffSize); - -/*! Constructor and Destructor of FSE_DTable. - Note that its size depends on 'tableLog' */ -typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */ -FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog); -FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt); - -/*! FSE_buildDTable(): - Builds 'dt', which must be already allocated, using FSE_createDTable(). - return : 0, or an errorCode, which can be tested using FSE_isError() */ -FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); - -/*! FSE_decompress_usingDTable(): - Decompress compressed source `cSrc` of size `cSrcSize` using `dt` - into `dst` which must be already allocated. - @return : size of regenerated data (necessarily <= `dstCapacity`), - or an errorCode, which can be tested using FSE_isError() */ -FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt); - -/*! -Tutorial : ----------- -(Note : these functions only decompress FSE-compressed blocks. - If block is uncompressed, use memcpy() instead - If block is a single repeated byte, use memset() instead ) - -The first step is to obtain the normalized frequencies of symbols. -This can be performed by FSE_readNCount() if it was saved using FSE_writeNCount(). -'normalizedCounter' must be already allocated, and have at least 'maxSymbolValuePtr[0]+1' cells of signed short. -In practice, that means it's necessary to know 'maxSymbolValue' beforehand, -or size the table to handle worst case situations (typically 256). -FSE_readNCount() will provide 'tableLog' and 'maxSymbolValue'. -The result of FSE_readNCount() is the number of bytes read from 'rBuffer'. -Note that 'rBufferSize' must be at least 4 bytes, even if useful information is less than that. -If there is an error, the function will return an error code, which can be tested using FSE_isError(). - -The next step is to build the decompression tables 'FSE_DTable' from 'normalizedCounter'. -This is performed by the function FSE_buildDTable(). -The space required by 'FSE_DTable' must be already allocated using FSE_createDTable(). -If there is an error, the function will return an error code, which can be tested using FSE_isError(). - -`FSE_DTable` can then be used to decompress `cSrc`, with FSE_decompress_usingDTable(). -`cSrcSize` must be strictly correct, otherwise decompression will fail. -FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<=`dstCapacity`). -If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small) -*/ - -#endif /* FSE_H */ - -#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY) -#define FSE_H_FSE_STATIC_LINKING_ONLY - -/* *** Dependency *** */ -#include "bitstream.h" - - -/* ***************************************** -* Static allocation -*******************************************/ -/* FSE buffer bounds */ -#define FSE_NCOUNTBOUND 512 -#define FSE_BLOCKBOUND(size) (size + (size>>7)) -#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ - -/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */ -#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2)) -#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1< 12) ? (1 << (maxTableLog - 2)) : 1024) ) -size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); - -size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits); -/**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */ - -size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue); -/**< build a fake FSE_CTable, designed to compress always the same symbolValue */ - -/* FSE_buildCTable_wksp() : - * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`). - * `wkspSize` must be >= `(1<= BIT_DStream_completed - -When it's done, verify decompression is fully completed, by checking both DStream and the relevant states. -Checking if DStream has reached its end is performed by : - BIT_endOfDStream(&DStream); -Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible. - FSE_endOfDState(&DState); -*/ - - -/* ***************************************** -* FSE unsafe API -*******************************************/ -static unsigned char FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD); -/* faster, but works only if nbBits is always >= 1 (otherwise, result will be corrupted) */ - - -/* ***************************************** -* Implementation of inlined functions -*******************************************/ -typedef struct { - int deltaFindState; - U32 deltaNbBits; -} FSE_symbolCompressionTransform; /* total 8 bytes */ - -MEM_STATIC void FSE_initCState(FSE_CState_t* statePtr, const FSE_CTable* ct) -{ - const void* ptr = ct; - const U16* u16ptr = (const U16*) ptr; - const U32 tableLog = MEM_read16(ptr); - statePtr->value = (ptrdiff_t)1<stateTable = u16ptr+2; - statePtr->symbolTT = ((const U32*)ct + 1 + (tableLog ? (1<<(tableLog-1)) : 1)); - statePtr->stateLog = tableLog; -} - - -/*! FSE_initCState2() : -* Same as FSE_initCState(), but the first symbol to include (which will be the last to be read) -* uses the smallest state value possible, saving the cost of this symbol */ -MEM_STATIC void FSE_initCState2(FSE_CState_t* statePtr, const FSE_CTable* ct, U32 symbol) -{ - FSE_initCState(statePtr, ct); - { const FSE_symbolCompressionTransform symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; - const U16* stateTable = (const U16*)(statePtr->stateTable); - U32 nbBitsOut = (U32)((symbolTT.deltaNbBits + (1<<15)) >> 16); - statePtr->value = (nbBitsOut << 16) - symbolTT.deltaNbBits; - statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; - } -} - -MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, U32 symbol) -{ - FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; - const U16* const stateTable = (const U16*)(statePtr->stateTable); - U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16); - BIT_addBits(bitC, statePtr->value, nbBitsOut); - statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; -} - -MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePtr) -{ - BIT_addBits(bitC, statePtr->value, statePtr->stateLog); - BIT_flushBits(bitC); -} - - -/* FSE_getMaxNbBits() : - * Approximate maximum cost of a symbol, in bits. - * Fractional get rounded up (i.e : a symbol with a normalized frequency of 3 gives the same result as a frequency of 2) - * note 1 : assume symbolValue is valid (<= maxSymbolValue) - * note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */ -MEM_STATIC U32 FSE_getMaxNbBits(const void* symbolTTPtr, U32 symbolValue) -{ - const FSE_symbolCompressionTransform* symbolTT = (const FSE_symbolCompressionTransform*) symbolTTPtr; - return (symbolTT[symbolValue].deltaNbBits + ((1<<16)-1)) >> 16; -} - -/* FSE_bitCost() : - * Approximate symbol cost, as fractional value, using fixed-point format (accuracyLog fractional bits) - * note 1 : assume symbolValue is valid (<= maxSymbolValue) - * note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */ -MEM_STATIC U32 FSE_bitCost(const void* symbolTTPtr, U32 tableLog, U32 symbolValue, U32 accuracyLog) -{ - const FSE_symbolCompressionTransform* symbolTT = (const FSE_symbolCompressionTransform*) symbolTTPtr; - U32 const minNbBits = symbolTT[symbolValue].deltaNbBits >> 16; - U32 const threshold = (minNbBits+1) << 16; - assert(tableLog < 16); - assert(accuracyLog < 31-tableLog); /* ensure enough room for renormalization double shift */ - { U32 const tableSize = 1 << tableLog; - U32 const deltaFromThreshold = threshold - (symbolTT[symbolValue].deltaNbBits + tableSize); - U32 const normalizedDeltaFromThreshold = (deltaFromThreshold << accuracyLog) >> tableLog; /* linear interpolation (very approximate) */ - U32 const bitMultiplier = 1 << accuracyLog; - assert(symbolTT[symbolValue].deltaNbBits + tableSize <= threshold); - assert(normalizedDeltaFromThreshold <= bitMultiplier); - return (minNbBits+1)*bitMultiplier - normalizedDeltaFromThreshold; - } -} - - -/* ====== Decompression ====== */ - -typedef struct { - U16 tableLog; - U16 fastMode; -} FSE_DTableHeader; /* sizeof U32 */ - -typedef struct -{ - unsigned short newState; - unsigned char symbol; - unsigned char nbBits; -} FSE_decode_t; /* size == U32 */ - -MEM_STATIC void FSE_initDState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD, const FSE_DTable* dt) -{ - const void* ptr = dt; - const FSE_DTableHeader* const DTableH = (const FSE_DTableHeader*)ptr; - DStatePtr->state = BIT_readBits(bitD, DTableH->tableLog); - BIT_reloadDStream(bitD); - DStatePtr->table = dt + 1; -} - -MEM_STATIC BYTE FSE_peekSymbol(const FSE_DState_t* DStatePtr) -{ - FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; - return DInfo.symbol; -} - -MEM_STATIC void FSE_updateState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) -{ - FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; - U32 const nbBits = DInfo.nbBits; - size_t const lowBits = BIT_readBits(bitD, nbBits); - DStatePtr->state = DInfo.newState + lowBits; -} - -MEM_STATIC BYTE FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) -{ - FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; - U32 const nbBits = DInfo.nbBits; - BYTE const symbol = DInfo.symbol; - size_t const lowBits = BIT_readBits(bitD, nbBits); - - DStatePtr->state = DInfo.newState + lowBits; - return symbol; -} - -/*! FSE_decodeSymbolFast() : - unsafe, only works if no symbol has a probability > 50% */ -MEM_STATIC BYTE FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) -{ - FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; - U32 const nbBits = DInfo.nbBits; - BYTE const symbol = DInfo.symbol; - size_t const lowBits = BIT_readBitsFast(bitD, nbBits); - - DStatePtr->state = DInfo.newState + lowBits; - return symbol; -} - -MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr) -{ - return DStatePtr->state == 0; -} - - - -#ifndef FSE_COMMONDEFS_ONLY - -/* ************************************************************** -* Tuning parameters -****************************************************************/ -/*!MEMORY_USAGE : -* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) -* Increasing memory usage improves compression ratio -* Reduced memory usage can improve speed, due to cache effect -* Recommended max value is 14, for 16KB, which nicely fits into Intel x86 L1 cache */ -#ifndef FSE_MAX_MEMORY_USAGE -# define FSE_MAX_MEMORY_USAGE 14 -#endif -#ifndef FSE_DEFAULT_MEMORY_USAGE -# define FSE_DEFAULT_MEMORY_USAGE 13 -#endif - -/*!FSE_MAX_SYMBOL_VALUE : -* Maximum symbol value authorized. -* Required for proper stack allocation */ -#ifndef FSE_MAX_SYMBOL_VALUE -# define FSE_MAX_SYMBOL_VALUE 255 -#endif - -/* ************************************************************** -* template functions type & suffix -****************************************************************/ -#define FSE_FUNCTION_TYPE BYTE -#define FSE_FUNCTION_EXTENSION -#define FSE_DECODE_TYPE FSE_decode_t - - -#endif /* !FSE_COMMONDEFS_ONLY */ - - -/* *************************************************************** -* Constants -*****************************************************************/ -#define FSE_MAX_TABLELOG (FSE_MAX_MEMORY_USAGE-2) -#define FSE_MAX_TABLESIZE (1U< FSE_TABLELOG_ABSOLUTE_MAX -# error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported" -#endif - -#define FSE_TABLESTEP(tableSize) ((tableSize>>1) + (tableSize>>3) + 3) - - -#endif /* FSE_STATIC_LINKING_ONLY */ - - -#if defined (__cplusplus) -} -#endif diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c deleted file mode 100644 index 2227b84bc..000000000 --- a/grub-core/lib/zstd/fse_decompress.c +++ /dev/null @@ -1,309 +0,0 @@ -/* ****************************************************************** - FSE : Finite State Entropy decoder - Copyright (C) 2013-2015, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy - - Public forum : https://groups.google.com/forum/#!forum/lz4c -****************************************************************** */ - - -/* ************************************************************** -* Includes -****************************************************************/ -#include /* malloc, free, qsort */ -#include /* memcpy, memset */ -#include "bitstream.h" -#include "compiler.h" -#define FSE_STATIC_LINKING_ONLY -#include "fse.h" -#include "error_private.h" - - -/* ************************************************************** -* Error Management -****************************************************************/ -#define FSE_isError ERR_isError -#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */ - -/* check and forward error code */ -#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; } - - -/* ************************************************************** -* Templates -****************************************************************/ -/* - designed to be included - for type-specific functions (template emulation in C) - Objective is to write these functions only once, for improved maintenance -*/ - -/* safety checks */ -#ifndef FSE_FUNCTION_EXTENSION -# error "FSE_FUNCTION_EXTENSION must be defined" -#endif -#ifndef FSE_FUNCTION_TYPE -# error "FSE_FUNCTION_TYPE must be defined" -#endif - -/* Function names */ -#define FSE_CAT(X,Y) X##Y -#define FSE_FUNCTION_NAME(X,Y) FSE_CAT(X,Y) -#define FSE_TYPE_NAME(X,Y) FSE_CAT(X,Y) - - -/* Function templates */ -FSE_DTable* FSE_createDTable (unsigned tableLog) -{ - if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; - return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); -} - -void FSE_freeDTable (FSE_DTable* dt) -{ - free(dt); -} - -size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog) -{ - void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */ - FSE_DECODE_TYPE* const tableDecode = (FSE_DECODE_TYPE*) (tdPtr); - U16 symbolNext[FSE_MAX_SYMBOL_VALUE+1]; - - U32 const maxSV1 = maxSymbolValue + 1; - U32 const tableSize = 1 << tableLog; - U32 highThreshold = tableSize-1; - - /* Sanity Checks */ - if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge); - if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); - - /* Init, lay down lowprob symbols */ - { FSE_DTableHeader DTableH; - DTableH.tableLog = (U16)tableLog; - DTableH.fastMode = 1; - { S16 const largeLimit= (S16)(1 << (tableLog-1)); - U32 s; - for (s=0; s= largeLimit) DTableH.fastMode=0; - symbolNext[s] = normalizedCounter[s]; - } } } - memcpy(dt, &DTableH, sizeof(DTableH)); - } - - /* Spread symbols */ - { U32 const tableMask = tableSize-1; - U32 const step = FSE_TABLESTEP(tableSize); - U32 s, position = 0; - for (s=0; s highThreshold) position = (position + step) & tableMask; /* lowprob area */ - } } - if (position!=0) return ERROR(GENERIC); /* position must reach all cells once, otherwise normalizedCounter is incorrect */ - } - - /* Build Decoding table */ - { U32 u; - for (u=0; utableLog = 0; - DTableH->fastMode = 0; - - cell->newState = 0; - cell->symbol = symbolValue; - cell->nbBits = 0; - - return 0; -} - - -size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits) -{ - void* ptr = dt; - FSE_DTableHeader* const DTableH = (FSE_DTableHeader*)ptr; - void* dPtr = dt + 1; - FSE_decode_t* const dinfo = (FSE_decode_t*)dPtr; - const unsigned tableSize = 1 << nbBits; - const unsigned tableMask = tableSize - 1; - const unsigned maxSV1 = tableMask+1; - unsigned s; - - /* Sanity checks */ - if (nbBits < 1) return ERROR(GENERIC); /* min size */ - - /* Build Decoding Table */ - DTableH->tableLog = (U16)nbBits; - DTableH->fastMode = 1; - for (s=0; s sizeof(bitD.bitContainer)*8) /* This test must be static */ - BIT_reloadDStream(&bitD); - - op[1] = FSE_GETSYMBOL(&state2); - - if (FSE_MAX_TABLELOG*4+7 > sizeof(bitD.bitContainer)*8) /* This test must be static */ - { if (BIT_reloadDStream(&bitD) > BIT_DStream_unfinished) { op+=2; break; } } - - op[2] = FSE_GETSYMBOL(&state1); - - if (FSE_MAX_TABLELOG*2+7 > sizeof(bitD.bitContainer)*8) /* This test must be static */ - BIT_reloadDStream(&bitD); - - op[3] = FSE_GETSYMBOL(&state2); - } - - /* tail */ - /* note : BIT_reloadDStream(&bitD) >= FSE_DStream_partiallyFilled; Ends at exactly BIT_DStream_completed */ - while (1) { - if (op>(omax-2)) return ERROR(dstSize_tooSmall); - *op++ = FSE_GETSYMBOL(&state1); - if (BIT_reloadDStream(&bitD)==BIT_DStream_overflow) { - *op++ = FSE_GETSYMBOL(&state2); - break; - } - - if (op>(omax-2)) return ERROR(dstSize_tooSmall); - *op++ = FSE_GETSYMBOL(&state2); - if (BIT_reloadDStream(&bitD)==BIT_DStream_overflow) { - *op++ = FSE_GETSYMBOL(&state1); - break; - } } - - return op-ostart; -} - - -size_t FSE_decompress_usingDTable(void* dst, size_t originalSize, - const void* cSrc, size_t cSrcSize, - const FSE_DTable* dt) -{ - const void* ptr = dt; - const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr; - const U32 fastMode = DTableH->fastMode; - - /* select fast mode (static) */ - if (fastMode) return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 1); - return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 0); -} - - -size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog) -{ - const BYTE* const istart = (const BYTE*)cSrc; - const BYTE* ip = istart; - short counting[FSE_MAX_SYMBOL_VALUE+1]; - unsigned tableLog; - unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE; - - /* normal FSE decoding mode */ - size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize); - if (FSE_isError(NCountLength)) return NCountLength; - //if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */ - if (tableLog > maxLog) return ERROR(tableLog_tooLarge); - ip += NCountLength; - cSrcSize -= NCountLength; - - CHECK_F( FSE_buildDTable (workSpace, counting, maxSymbolValue, tableLog) ); - - return FSE_decompress_usingDTable (dst, dstCapacity, ip, cSrcSize, workSpace); /* always return, even if it is an error code */ -} - - -typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)]; - -size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize) -{ - DTable_max_t dt; /* Static analyzer seems unable to understand this table will be properly initialized later */ - return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, dt, FSE_MAX_TABLELOG); -} - - - -#endif /* FSE_COMMONDEFS_ONLY */ diff --git a/grub-core/lib/zstd/huf.h b/grub-core/lib/zstd/huf.h deleted file mode 100644 index de9464111..000000000 --- a/grub-core/lib/zstd/huf.h +++ /dev/null @@ -1,334 +0,0 @@ -/* ****************************************************************** - huff0 huffman codec, - part of Finite State Entropy library - Copyright (C) 2013-present, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - Source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ - -#if defined (__cplusplus) -extern "C" { -#endif - -#ifndef HUF_H_298734234 -#define HUF_H_298734234 - -/* *** Dependencies *** */ -#include /* size_t */ - - -/* *** library symbols visibility *** */ -/* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual, - * HUF symbols remain "private" (internal symbols for library only). - * Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */ -#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) -# define HUF_PUBLIC_API __attribute__ ((visibility ("default"))) -#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ -# define HUF_PUBLIC_API __declspec(dllexport) -#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) -# define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */ -#else -# define HUF_PUBLIC_API -#endif - - -/* ========================== */ -/* *** simple functions *** */ -/* ========================== */ - -/** HUF_compress() : - * Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'. - * 'dst' buffer must be already allocated. - * Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize). - * `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB. - * @return : size of compressed data (<= `dstCapacity`). - * Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! - * if HUF_isError(return), compression failed (more details using HUF_getErrorName()) - */ -HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity, - const void* src, size_t srcSize); - -/** HUF_decompress() : - * Decompress HUF data from buffer 'cSrc', of size 'cSrcSize', - * into already allocated buffer 'dst', of minimum size 'dstSize'. - * `originalSize` : **must** be the ***exact*** size of original (uncompressed) data. - * Note : in contrast with FSE, HUF_decompress can regenerate - * RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data, - * because it knows size to regenerate (originalSize). - * @return : size of regenerated data (== originalSize), - * or an error code, which can be tested using HUF_isError() - */ -HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize, - const void* cSrc, size_t cSrcSize); - - -/* *** Tool functions *** */ -#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */ -HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */ - -/* Error Management */ -HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */ -HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */ - - -/* *** Advanced function *** */ - -/** HUF_compress2() : - * Same as HUF_compress(), but offers control over `maxSymbolValue` and `tableLog`. - * `maxSymbolValue` must be <= HUF_SYMBOLVALUE_MAX . - * `tableLog` must be `<= HUF_TABLELOG_MAX` . */ -HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - unsigned maxSymbolValue, unsigned tableLog); - -/** HUF_compress4X_wksp() : - * Same as HUF_compress2(), but uses externally allocated `workSpace`. - * `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */ -#define HUF_WORKSPACE_SIZE (6 << 10) -#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32)) -HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - unsigned maxSymbolValue, unsigned tableLog, - void* workSpace, size_t wkspSize); - -#endif /* HUF_H_298734234 */ - -/* ****************************************************************** - * WARNING !! - * The following section contains advanced and experimental definitions - * which shall never be used in the context of a dynamic library, - * because they are not guaranteed to remain stable in the future. - * Only consider them in association with static linking. - * *****************************************************************/ -#if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY) -#define HUF_H_HUF_STATIC_LINKING_ONLY - -/* *** Dependencies *** */ -#include "mem.h" /* U32 */ - - -/* *** Constants *** */ -#define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */ -#define HUF_TABLELOG_DEFAULT 11 /* default tableLog value when none specified */ -#define HUF_SYMBOLVALUE_MAX 255 - -#define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */ -#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX) -# error "HUF_TABLELOG_MAX is too large !" -#endif - - -/* **************************************** -* Static allocation -******************************************/ -/* HUF buffer bounds */ -#define HUF_CTABLEBOUND 129 -#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */ -#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ - -/* static allocation of HUF's Compression Table */ -#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */ -#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32)) -#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \ - U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \ - void* name##hv = &(name##hb); \ - HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */ - -/* static allocation of HUF's DTable */ -typedef U32 HUF_DTable; -#define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog))) -#define HUF_CREATE_STATIC_DTABLEX1(DTable, maxTableLog) \ - HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1) * 0x01000001) } -#define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \ - HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) } - - -/* **************************************** -* Advanced decompression functions -******************************************/ -size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ -size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ - -size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */ -size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */ -size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */ -size_t HUF_decompress4X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ -size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ -size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ -size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ - - -/* **************************************** - * HUF detailed API - * ****************************************/ - -/*! HUF_compress() does the following: - * 1. count symbol occurrence from source[] into table count[] using FSE_count() (exposed within "fse.h") - * 2. (optional) refine tableLog using HUF_optimalTableLog() - * 3. build Huffman table from count using HUF_buildCTable() - * 4. save Huffman table to memory buffer using HUF_writeCTable() - * 5. encode the data stream using HUF_compress4X_usingCTable() - * - * The following API allows targeting specific sub-functions for advanced tasks. - * For example, it's possible to compress several blocks using the same 'CTable', - * or to save and regenerate 'CTable' using external methods. - */ -unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); -typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */ -size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */ -size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog); -size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); - -typedef enum { - HUF_repeat_none, /**< Cannot use the previous table */ - HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */ - HUF_repeat_valid /**< Can use the previous table and it is assumed to be valid */ - } HUF_repeat; -/** HUF_compress4X_repeat() : - * Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. - * If it uses hufTable it does not modify hufTable or repeat. - * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. - * If preferRepeat then the old table will always be used if valid. */ -size_t HUF_compress4X_repeat(void* dst, size_t dstSize, - const void* src, size_t srcSize, - unsigned maxSymbolValue, unsigned tableLog, - void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */ - HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2); - -/** HUF_buildCTable_wksp() : - * Same as HUF_buildCTable(), but using externally allocated scratch buffer. - * `workSpace` must be aligned on 4-bytes boundaries, and its size must be >= HUF_CTABLE_WORKSPACE_SIZE. - */ -#define HUF_CTABLE_WORKSPACE_SIZE_U32 (2*HUF_SYMBOLVALUE_MAX +1 +1) -#define HUF_CTABLE_WORKSPACE_SIZE (HUF_CTABLE_WORKSPACE_SIZE_U32 * sizeof(unsigned)) -size_t HUF_buildCTable_wksp (HUF_CElt* tree, - const U32* count, U32 maxSymbolValue, U32 maxNbBits, - void* workSpace, size_t wkspSize); - -/*! HUF_readStats() : - * Read compact Huffman tree, saved by HUF_writeCTable(). - * `huffWeight` is destination buffer. - * @return : size read from `src` , or an error Code . - * Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */ -size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, - U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr, - const void* src, size_t srcSize); - -/** HUF_readCTable() : - * Loading a CTable saved with HUF_writeCTable() */ -size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); - -/** HUF_getNbBits() : - * Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX - * Note 1 : is not inlined, as HUF_CElt definition is private - * Note 2 : const void* used, so that it can provide a statically allocated table as argument (which uses type U32) */ -U32 HUF_getNbBits(const void* symbolTable, U32 symbolValue); - -/* - * HUF_decompress() does the following: - * 1. select the decompression algorithm (X1, X2) based on pre-computed heuristics - * 2. build Huffman table from save, using HUF_readDTableX?() - * 3. decode 1 or 4 segments in parallel using HUF_decompress?X?_usingDTable() - */ - -/** HUF_selectDecoder() : - * Tells which decoder is likely to decode faster, - * based on a set of pre-computed metrics. - * @return : 0==HUF_decompress4X1, 1==HUF_decompress4X2 . - * Assumption : 0 < dstSize <= 128 KB */ -U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize); - -/** - * The minimum workspace size for the `workSpace` used in - * HUF_readDTableX1_wksp() and HUF_readDTableX2_wksp(). - * - * The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when - * HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15. - * Buffer overflow errors may potentially occur if code modifications result in - * a required workspace size greater than that specified in the following - * macro. - */ -#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10) -#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32)) - -size_t HUF_readDTableX1 (HUF_DTable* DTable, const void* src, size_t srcSize); -size_t HUF_readDTableX1_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); -size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize); -size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); - -size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); -size_t HUF_decompress4X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); -size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); - - -/* ====================== */ -/* single stream variants */ -/* ====================== */ - -size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); -size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ -size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); -/** HUF_compress1X_repeat() : - * Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. - * If it uses hufTable it does not modify hufTable or repeat. - * If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. - * If preferRepeat then the old table will always be used if valid. */ -size_t HUF_compress1X_repeat(void* dst, size_t dstSize, - const void* src, size_t srcSize, - unsigned maxSymbolValue, unsigned tableLog, - void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */ - HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2); - -size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */ -size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */ - -size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); -size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); -size_t HUF_decompress1X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ -size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ -size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ -size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ - -size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */ -size_t HUF_decompress1X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); -size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); - -/* BMI2 variants. - * If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0. - */ -size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2); -size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2); -size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2); -size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2); - -#endif /* HUF_STATIC_LINKING_ONLY */ - -#if defined (__cplusplus) -} -#endif diff --git a/grub-core/lib/zstd/huf_decompress.c b/grub-core/lib/zstd/huf_decompress.c deleted file mode 100644 index 83ecaff01..000000000 --- a/grub-core/lib/zstd/huf_decompress.c +++ /dev/null @@ -1,1096 +0,0 @@ -/* ****************************************************************** - huff0 huffman decoder, - part of Finite State Entropy library - Copyright (C) 2013-present, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy -****************************************************************** */ - -/* ************************************************************** -* Dependencies -****************************************************************/ -#include /* memcpy, memset */ -#include "compiler.h" -#include "bitstream.h" /* BIT_* */ -#include "fse.h" /* to compress headers */ -#define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "error_private.h" - - -/* ************************************************************** -* Error Management -****************************************************************/ -#define HUF_isError ERR_isError -#define CHECK_F(f) { size_t const err_ = (f); if (HUF_isError(err_)) return err_; } - - -/* ************************************************************** -* Byte alignment for workSpace management -****************************************************************/ -#define HUF_ALIGN(x, a) HUF_ALIGN_MASK((x), (a) - 1) -#define HUF_ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) - - -/*-***************************/ -/* generic DTableDesc */ -/*-***************************/ -typedef struct { BYTE maxTableLog; BYTE tableType; BYTE tableLog; BYTE reserved; } DTableDesc; - -static DTableDesc HUF_getDTableDesc(const HUF_DTable* table) -{ - DTableDesc dtd; - memcpy(&dtd, table, sizeof(dtd)); - return dtd; -} - - -/*-***************************/ -/* single-symbol decoding */ -/*-***************************/ -typedef struct { BYTE byte; BYTE nbBits; } HUF_DEltX1; /* single-symbol decoding */ - -size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize) -{ - U32 tableLog = 0; - U32 nbSymbols = 0; - size_t iSize; - void* const dtPtr = DTable + 1; - HUF_DEltX1* const dt = (HUF_DEltX1*)dtPtr; - - U32* rankVal; - BYTE* huffWeight; - size_t spaceUsed32 = 0; - - rankVal = (U32 *)workSpace + spaceUsed32; - spaceUsed32 += HUF_TABLELOG_ABSOLUTEMAX + 1; - huffWeight = (BYTE *)((U32 *)workSpace + spaceUsed32); - spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2; - - if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge); - - DEBUG_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUF_DTable)); - /* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */ - - iSize = HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX + 1, rankVal, &nbSymbols, &tableLog, src, srcSize); - if (HUF_isError(iSize)) return iSize; - - /* Table header */ - { DTableDesc dtd = HUF_getDTableDesc(DTable); - if (tableLog > (U32)(dtd.maxTableLog+1)) return ERROR(tableLog_tooLarge); /* DTable too small, Huffman tree cannot fit in */ - dtd.tableType = 0; - dtd.tableLog = (BYTE)tableLog; - memcpy(DTable, &dtd, sizeof(dtd)); - } - - /* Calculate starting value for each rank */ - { U32 n, nextRankStart = 0; - for (n=1; n> 1; - U32 u; - HUF_DEltX1 D; - D.byte = (BYTE)n; D.nbBits = (BYTE)(tableLog + 1 - w); - for (u = rankVal[w]; u < rankVal[w] + length; u++) - dt[u] = D; - rankVal[w] += length; - } } - - return iSize; -} - -size_t HUF_readDTableX1(HUF_DTable* DTable, const void* src, size_t srcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_readDTableX1_wksp(DTable, src, srcSize, - workSpace, sizeof(workSpace)); -} - -FORCE_INLINE_TEMPLATE BYTE -HUF_decodeSymbolX1(BIT_DStream_t* Dstream, const HUF_DEltX1* dt, const U32 dtLog) -{ - size_t const val = BIT_lookBitsFast(Dstream, dtLog); /* note : dtLog >= 1 */ - BYTE const c = dt[val].byte; - BIT_skipBits(Dstream, dt[val].nbBits); - return c; -} - -#define HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr) \ - *ptr++ = HUF_decodeSymbolX1(DStreamPtr, dt, dtLog) - -#define HUF_DECODE_SYMBOLX1_1(ptr, DStreamPtr) \ - if (MEM_64bits() || (HUF_TABLELOG_MAX<=12)) \ - HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr) - -#define HUF_DECODE_SYMBOLX1_2(ptr, DStreamPtr) \ - if (MEM_64bits()) \ - HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr) - -HINT_INLINE size_t -HUF_decodeStreamX1(BYTE* p, BIT_DStream_t* const bitDPtr, BYTE* const pEnd, const HUF_DEltX1* const dt, const U32 dtLog) -{ - BYTE* const pStart = p; - - /* up to 4 symbols at a time */ - while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd-3)) { - HUF_DECODE_SYMBOLX1_2(p, bitDPtr); - HUF_DECODE_SYMBOLX1_1(p, bitDPtr); - HUF_DECODE_SYMBOLX1_2(p, bitDPtr); - HUF_DECODE_SYMBOLX1_0(p, bitDPtr); - } - - /* [0-3] symbols remaining */ - if (MEM_32bits()) - while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd)) - HUF_DECODE_SYMBOLX1_0(p, bitDPtr); - - /* no more data to retrieve from bitstream, no need to reload */ - while (p < pEnd) - HUF_DECODE_SYMBOLX1_0(p, bitDPtr); - - return pEnd-pStart; -} - -FORCE_INLINE_TEMPLATE size_t -HUF_decompress1X1_usingDTable_internal_body( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - BYTE* op = (BYTE*)dst; - BYTE* const oend = op + dstSize; - const void* dtPtr = DTable + 1; - const HUF_DEltX1* const dt = (const HUF_DEltX1*)dtPtr; - BIT_DStream_t bitD; - DTableDesc const dtd = HUF_getDTableDesc(DTable); - U32 const dtLog = dtd.tableLog; - - CHECK_F( BIT_initDStream(&bitD, cSrc, cSrcSize) ); - - HUF_decodeStreamX1(op, &bitD, oend, dt, dtLog); - - if (!BIT_endOfDStream(&bitD)) return ERROR(corruption_detected); - - return dstSize; -} - -FORCE_INLINE_TEMPLATE size_t -HUF_decompress4X1_usingDTable_internal_body( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - /* Check */ - if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ - - { const BYTE* const istart = (const BYTE*) cSrc; - BYTE* const ostart = (BYTE*) dst; - BYTE* const oend = ostart + dstSize; - const void* const dtPtr = DTable + 1; - const HUF_DEltX1* const dt = (const HUF_DEltX1*)dtPtr; - - /* Init */ - BIT_DStream_t bitD1; - BIT_DStream_t bitD2; - BIT_DStream_t bitD3; - BIT_DStream_t bitD4; - size_t const length1 = MEM_readLE16(istart); - size_t const length2 = MEM_readLE16(istart+2); - size_t const length3 = MEM_readLE16(istart+4); - size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6); - const BYTE* const istart1 = istart + 6; /* jumpTable */ - const BYTE* const istart2 = istart1 + length1; - const BYTE* const istart3 = istart2 + length2; - const BYTE* const istart4 = istart3 + length3; - const size_t segmentSize = (dstSize+3) / 4; - BYTE* const opStart2 = ostart + segmentSize; - BYTE* const opStart3 = opStart2 + segmentSize; - BYTE* const opStart4 = opStart3 + segmentSize; - BYTE* op1 = ostart; - BYTE* op2 = opStart2; - BYTE* op3 = opStart3; - BYTE* op4 = opStart4; - U32 endSignal = BIT_DStream_unfinished; - DTableDesc const dtd = HUF_getDTableDesc(DTable); - U32 const dtLog = dtd.tableLog; - - if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */ - CHECK_F( BIT_initDStream(&bitD1, istart1, length1) ); - CHECK_F( BIT_initDStream(&bitD2, istart2, length2) ); - CHECK_F( BIT_initDStream(&bitD3, istart3, length3) ); - CHECK_F( BIT_initDStream(&bitD4, istart4, length4) ); - - /* up to 16 symbols per loop (4 symbols per stream) in 64-bit mode */ - endSignal = BIT_reloadDStream(&bitD1) | BIT_reloadDStream(&bitD2) | BIT_reloadDStream(&bitD3) | BIT_reloadDStream(&bitD4); - while ( (endSignal==BIT_DStream_unfinished) && (op4<(oend-3)) ) { - HUF_DECODE_SYMBOLX1_2(op1, &bitD1); - HUF_DECODE_SYMBOLX1_2(op2, &bitD2); - HUF_DECODE_SYMBOLX1_2(op3, &bitD3); - HUF_DECODE_SYMBOLX1_2(op4, &bitD4); - HUF_DECODE_SYMBOLX1_1(op1, &bitD1); - HUF_DECODE_SYMBOLX1_1(op2, &bitD2); - HUF_DECODE_SYMBOLX1_1(op3, &bitD3); - HUF_DECODE_SYMBOLX1_1(op4, &bitD4); - HUF_DECODE_SYMBOLX1_2(op1, &bitD1); - HUF_DECODE_SYMBOLX1_2(op2, &bitD2); - HUF_DECODE_SYMBOLX1_2(op3, &bitD3); - HUF_DECODE_SYMBOLX1_2(op4, &bitD4); - HUF_DECODE_SYMBOLX1_0(op1, &bitD1); - HUF_DECODE_SYMBOLX1_0(op2, &bitD2); - HUF_DECODE_SYMBOLX1_0(op3, &bitD3); - HUF_DECODE_SYMBOLX1_0(op4, &bitD4); - BIT_reloadDStream(&bitD1); - BIT_reloadDStream(&bitD2); - BIT_reloadDStream(&bitD3); - BIT_reloadDStream(&bitD4); - } - - /* check corruption */ - /* note : should not be necessary : op# advance in lock step, and we control op4. - * but curiously, binary generated by gcc 7.2 & 7.3 with -mbmi2 runs faster when >=1 test is present */ - if (op1 > opStart2) return ERROR(corruption_detected); - if (op2 > opStart3) return ERROR(corruption_detected); - if (op3 > opStart4) return ERROR(corruption_detected); - /* note : op4 supposed already verified within main loop */ - - /* finish bitStreams one by one */ - HUF_decodeStreamX1(op1, &bitD1, opStart2, dt, dtLog); - HUF_decodeStreamX1(op2, &bitD2, opStart3, dt, dtLog); - HUF_decodeStreamX1(op3, &bitD3, opStart4, dt, dtLog); - HUF_decodeStreamX1(op4, &bitD4, oend, dt, dtLog); - - /* check */ - { U32 const endCheck = BIT_endOfDStream(&bitD1) & BIT_endOfDStream(&bitD2) & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4); - if (!endCheck) return ERROR(corruption_detected); } - - /* decoded size */ - return dstSize; - } -} - - -typedef size_t (*HUF_decompress_usingDTable_t)(void *dst, size_t dstSize, - const void *cSrc, - size_t cSrcSize, - const HUF_DTable *DTable); -#if DYNAMIC_BMI2 - -#define HUF_DGEN(fn) \ - \ - static size_t fn##_default( \ - void* dst, size_t dstSize, \ - const void* cSrc, size_t cSrcSize, \ - const HUF_DTable* DTable) \ - { \ - return fn##_body(dst, dstSize, cSrc, cSrcSize, DTable); \ - } \ - \ - static TARGET_ATTRIBUTE("bmi2") size_t fn##_bmi2( \ - void* dst, size_t dstSize, \ - const void* cSrc, size_t cSrcSize, \ - const HUF_DTable* DTable) \ - { \ - return fn##_body(dst, dstSize, cSrc, cSrcSize, DTable); \ - } \ - \ - static size_t fn(void* dst, size_t dstSize, void const* cSrc, \ - size_t cSrcSize, HUF_DTable const* DTable, int bmi2) \ - { \ - if (bmi2) { \ - return fn##_bmi2(dst, dstSize, cSrc, cSrcSize, DTable); \ - } \ - return fn##_default(dst, dstSize, cSrc, cSrcSize, DTable); \ - } - -#else - -#define HUF_DGEN(fn) \ - static size_t fn(void* dst, size_t dstSize, void const* cSrc, \ - size_t cSrcSize, HUF_DTable const* DTable, int bmi2) \ - { \ - (void)bmi2; \ - return fn##_body(dst, dstSize, cSrc, cSrcSize, DTable); \ - } - -#endif - -HUF_DGEN(HUF_decompress1X1_usingDTable_internal) -HUF_DGEN(HUF_decompress4X1_usingDTable_internal) - - - -size_t HUF_decompress1X1_usingDTable( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc dtd = HUF_getDTableDesc(DTable); - if (dtd.tableType != 0) return ERROR(GENERIC); - return HUF_decompress1X1_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - -size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* DCtx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize) -{ - const BYTE* ip = (const BYTE*) cSrc; - - size_t const hSize = HUF_readDTableX1_wksp(DCtx, cSrc, cSrcSize, workSpace, wkspSize); - if (HUF_isError(hSize)) return hSize; - if (hSize >= cSrcSize) return ERROR(srcSize_wrong); - ip += hSize; cSrcSize -= hSize; - - return HUF_decompress1X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, DCtx, /* bmi2 */ 0); -} - - -size_t HUF_decompress1X1_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress1X1_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} - -size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX); - return HUF_decompress1X1_DCtx (DTable, dst, dstSize, cSrc, cSrcSize); -} - -size_t HUF_decompress4X1_usingDTable( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc dtd = HUF_getDTableDesc(DTable); - if (dtd.tableType != 0) return ERROR(GENERIC); - return HUF_decompress4X1_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - -static size_t HUF_decompress4X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize, int bmi2) -{ - const BYTE* ip = (const BYTE*) cSrc; - - size_t const hSize = HUF_readDTableX1_wksp (dctx, cSrc, cSrcSize, - workSpace, wkspSize); - if (HUF_isError(hSize)) return hSize; - if (hSize >= cSrcSize) return ERROR(srcSize_wrong); - ip += hSize; cSrcSize -= hSize; - - return HUF_decompress4X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2); -} - -size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize) -{ - return HUF_decompress4X1_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, 0); -} - - -size_t HUF_decompress4X1_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} -size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX); - return HUF_decompress4X1_DCtx(DTable, dst, dstSize, cSrc, cSrcSize); -} - - -/* *************************/ -/* double-symbols decoding */ -/* *************************/ - -typedef struct { U16 sequence; BYTE nbBits; BYTE length; } HUF_DEltX2; /* double-symbols decoding */ -typedef struct { BYTE symbol; BYTE weight; } sortedSymbol_t; -typedef U32 rankValCol_t[HUF_TABLELOG_MAX + 1]; -typedef rankValCol_t rankVal_t[HUF_TABLELOG_MAX]; - - -/* HUF_fillDTableX2Level2() : - * `rankValOrigin` must be a table of at least (HUF_TABLELOG_MAX + 1) U32 */ -static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 sizeLog, const U32 consumed, - const U32* rankValOrigin, const int minWeight, - const sortedSymbol_t* sortedSymbols, const U32 sortedListSize, - U32 nbBitsBaseline, U16 baseSeq) -{ - HUF_DEltX2 DElt; - U32 rankVal[HUF_TABLELOG_MAX + 1]; - - /* get pre-calculated rankVal */ - memcpy(rankVal, rankValOrigin, sizeof(rankVal)); - - /* fill skipped values */ - if (minWeight>1) { - U32 i, skipSize = rankVal[minWeight]; - MEM_writeLE16(&(DElt.sequence), baseSeq); - DElt.nbBits = (BYTE)(consumed); - DElt.length = 1; - for (i = 0; i < skipSize; i++) - DTable[i] = DElt; - } - - /* fill DTable */ - { U32 s; for (s=0; s= 1 */ - - rankVal[weight] += length; - } } -} - - -static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, - const sortedSymbol_t* sortedList, const U32 sortedListSize, - const U32* rankStart, rankVal_t rankValOrigin, const U32 maxWeight, - const U32 nbBitsBaseline) -{ - U32 rankVal[HUF_TABLELOG_MAX + 1]; - const int scaleLog = nbBitsBaseline - targetLog; /* note : targetLog >= srcLog, hence scaleLog <= 1 */ - const U32 minBits = nbBitsBaseline - maxWeight; - U32 s; - - memcpy(rankVal, rankValOrigin, sizeof(rankVal)); - - /* fill DTable */ - for (s=0; s= minBits) { /* enough room for a second symbol */ - U32 sortedRank; - int minWeight = nbBits + scaleLog; - if (minWeight < 1) minWeight = 1; - sortedRank = rankStart[minWeight]; - HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits, - rankValOrigin[nbBits], minWeight, - sortedList+sortedRank, sortedListSize-sortedRank, - nbBitsBaseline, symbol); - } else { - HUF_DEltX2 DElt; - MEM_writeLE16(&(DElt.sequence), symbol); - DElt.nbBits = (BYTE)(nbBits); - DElt.length = 1; - { U32 const end = start + length; - U32 u; - for (u = start; u < end; u++) DTable[u] = DElt; - } } - rankVal[weight] += length; - } -} - -size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, - const void* src, size_t srcSize, - void* workSpace, size_t wkspSize) -{ - U32 tableLog, maxW, sizeOfSort, nbSymbols; - DTableDesc dtd = HUF_getDTableDesc(DTable); - U32 const maxTableLog = dtd.maxTableLog; - size_t iSize; - void* dtPtr = DTable+1; /* force compiler to avoid strict-aliasing */ - HUF_DEltX2* const dt = (HUF_DEltX2*)dtPtr; - U32 *rankStart; - - rankValCol_t* rankVal; - U32* rankStats; - U32* rankStart0; - sortedSymbol_t* sortedSymbol; - BYTE* weightList; - size_t spaceUsed32 = 0; - - rankVal = (rankValCol_t *)((U32 *)workSpace + spaceUsed32); - spaceUsed32 += (sizeof(rankValCol_t) * HUF_TABLELOG_MAX) >> 2; - rankStats = (U32 *)workSpace + spaceUsed32; - spaceUsed32 += HUF_TABLELOG_MAX + 1; - rankStart0 = (U32 *)workSpace + spaceUsed32; - spaceUsed32 += HUF_TABLELOG_MAX + 2; - sortedSymbol = (sortedSymbol_t *)workSpace + (spaceUsed32 * sizeof(U32)) / sizeof(sortedSymbol_t); - spaceUsed32 += HUF_ALIGN(sizeof(sortedSymbol_t) * (HUF_SYMBOLVALUE_MAX + 1), sizeof(U32)) >> 2; - weightList = (BYTE *)((U32 *)workSpace + spaceUsed32); - spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2; - - if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge); - - rankStart = rankStart0 + 1; - memset(rankStats, 0, sizeof(U32) * (2 * HUF_TABLELOG_MAX + 2 + 1)); - - DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable)); /* if compiler fails here, assertion is wrong */ - if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge); - /* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */ - - iSize = HUF_readStats(weightList, HUF_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize); - if (HUF_isError(iSize)) return iSize; - - /* check result */ - if (tableLog > maxTableLog) return ERROR(tableLog_tooLarge); /* DTable can't fit code depth */ - - /* find maxWeight */ - for (maxW = tableLog; rankStats[maxW]==0; maxW--) {} /* necessarily finds a solution before 0 */ - - /* Get start index of each weight */ - { U32 w, nextRankStart = 0; - for (w=1; w> consumed; - } } } } - - HUF_fillDTableX2(dt, maxTableLog, - sortedSymbol, sizeOfSort, - rankStart0, rankVal, maxW, - tableLog+1); - - dtd.tableLog = (BYTE)maxTableLog; - dtd.tableType = 1; - memcpy(DTable, &dtd, sizeof(dtd)); - return iSize; -} - -size_t HUF_readDTableX2(HUF_DTable* DTable, const void* src, size_t srcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_readDTableX2_wksp(DTable, src, srcSize, - workSpace, sizeof(workSpace)); -} - - -FORCE_INLINE_TEMPLATE U32 -HUF_decodeSymbolX2(void* op, BIT_DStream_t* DStream, const HUF_DEltX2* dt, const U32 dtLog) -{ - size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */ - memcpy(op, dt+val, 2); - BIT_skipBits(DStream, dt[val].nbBits); - return dt[val].length; -} - -FORCE_INLINE_TEMPLATE U32 -HUF_decodeLastSymbolX2(void* op, BIT_DStream_t* DStream, const HUF_DEltX2* dt, const U32 dtLog) -{ - size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */ - memcpy(op, dt+val, 1); - if (dt[val].length==1) BIT_skipBits(DStream, dt[val].nbBits); - else { - if (DStream->bitsConsumed < (sizeof(DStream->bitContainer)*8)) { - BIT_skipBits(DStream, dt[val].nbBits); - if (DStream->bitsConsumed > (sizeof(DStream->bitContainer)*8)) - /* ugly hack; works only because it's the last symbol. Note : can't easily extract nbBits from just this symbol */ - DStream->bitsConsumed = (sizeof(DStream->bitContainer)*8); - } } - return 1; -} - -#define HUF_DECODE_SYMBOLX2_0(ptr, DStreamPtr) \ - ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog) - -#define HUF_DECODE_SYMBOLX2_1(ptr, DStreamPtr) \ - if (MEM_64bits() || (HUF_TABLELOG_MAX<=12)) \ - ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog) - -#define HUF_DECODE_SYMBOLX2_2(ptr, DStreamPtr) \ - if (MEM_64bits()) \ - ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog) - -HINT_INLINE size_t -HUF_decodeStreamX2(BYTE* p, BIT_DStream_t* bitDPtr, BYTE* const pEnd, - const HUF_DEltX2* const dt, const U32 dtLog) -{ - BYTE* const pStart = p; - - /* up to 8 symbols at a time */ - while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd-(sizeof(bitDPtr->bitContainer)-1))) { - HUF_DECODE_SYMBOLX2_2(p, bitDPtr); - HUF_DECODE_SYMBOLX2_1(p, bitDPtr); - HUF_DECODE_SYMBOLX2_2(p, bitDPtr); - HUF_DECODE_SYMBOLX2_0(p, bitDPtr); - } - - /* closer to end : up to 2 symbols at a time */ - while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p <= pEnd-2)) - HUF_DECODE_SYMBOLX2_0(p, bitDPtr); - - while (p <= pEnd-2) - HUF_DECODE_SYMBOLX2_0(p, bitDPtr); /* no need to reload : reached the end of DStream */ - - if (p < pEnd) - p += HUF_decodeLastSymbolX2(p, bitDPtr, dt, dtLog); - - return p-pStart; -} - -FORCE_INLINE_TEMPLATE size_t -HUF_decompress1X2_usingDTable_internal_body( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - BIT_DStream_t bitD; - - /* Init */ - CHECK_F( BIT_initDStream(&bitD, cSrc, cSrcSize) ); - - /* decode */ - { BYTE* const ostart = (BYTE*) dst; - BYTE* const oend = ostart + dstSize; - const void* const dtPtr = DTable+1; /* force compiler to not use strict-aliasing */ - const HUF_DEltX2* const dt = (const HUF_DEltX2*)dtPtr; - DTableDesc const dtd = HUF_getDTableDesc(DTable); - HUF_decodeStreamX2(ostart, &bitD, oend, dt, dtd.tableLog); - } - - /* check */ - if (!BIT_endOfDStream(&bitD)) return ERROR(corruption_detected); - - /* decoded size */ - return dstSize; -} - - -FORCE_INLINE_TEMPLATE size_t -HUF_decompress4X2_usingDTable_internal_body( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ - - { const BYTE* const istart = (const BYTE*) cSrc; - BYTE* const ostart = (BYTE*) dst; - BYTE* const oend = ostart + dstSize; - const void* const dtPtr = DTable+1; - const HUF_DEltX2* const dt = (const HUF_DEltX2*)dtPtr; - - /* Init */ - BIT_DStream_t bitD1; - BIT_DStream_t bitD2; - BIT_DStream_t bitD3; - BIT_DStream_t bitD4; - size_t const length1 = MEM_readLE16(istart); - size_t const length2 = MEM_readLE16(istart+2); - size_t const length3 = MEM_readLE16(istart+4); - size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6); - const BYTE* const istart1 = istart + 6; /* jumpTable */ - const BYTE* const istart2 = istart1 + length1; - const BYTE* const istart3 = istart2 + length2; - const BYTE* const istart4 = istart3 + length3; - size_t const segmentSize = (dstSize+3) / 4; - BYTE* const opStart2 = ostart + segmentSize; - BYTE* const opStart3 = opStart2 + segmentSize; - BYTE* const opStart4 = opStart3 + segmentSize; - BYTE* op1 = ostart; - BYTE* op2 = opStart2; - BYTE* op3 = opStart3; - BYTE* op4 = opStart4; - U32 endSignal; - DTableDesc const dtd = HUF_getDTableDesc(DTable); - U32 const dtLog = dtd.tableLog; - - if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */ - CHECK_F( BIT_initDStream(&bitD1, istart1, length1) ); - CHECK_F( BIT_initDStream(&bitD2, istart2, length2) ); - CHECK_F( BIT_initDStream(&bitD3, istart3, length3) ); - CHECK_F( BIT_initDStream(&bitD4, istart4, length4) ); - - /* 16-32 symbols per loop (4-8 symbols per stream) */ - endSignal = BIT_reloadDStream(&bitD1) | BIT_reloadDStream(&bitD2) | BIT_reloadDStream(&bitD3) | BIT_reloadDStream(&bitD4); - for ( ; (endSignal==BIT_DStream_unfinished) & (op4<(oend-(sizeof(bitD4.bitContainer)-1))) ; ) { - HUF_DECODE_SYMBOLX2_2(op1, &bitD1); - HUF_DECODE_SYMBOLX2_2(op2, &bitD2); - HUF_DECODE_SYMBOLX2_2(op3, &bitD3); - HUF_DECODE_SYMBOLX2_2(op4, &bitD4); - HUF_DECODE_SYMBOLX2_1(op1, &bitD1); - HUF_DECODE_SYMBOLX2_1(op2, &bitD2); - HUF_DECODE_SYMBOLX2_1(op3, &bitD3); - HUF_DECODE_SYMBOLX2_1(op4, &bitD4); - HUF_DECODE_SYMBOLX2_2(op1, &bitD1); - HUF_DECODE_SYMBOLX2_2(op2, &bitD2); - HUF_DECODE_SYMBOLX2_2(op3, &bitD3); - HUF_DECODE_SYMBOLX2_2(op4, &bitD4); - HUF_DECODE_SYMBOLX2_0(op1, &bitD1); - HUF_DECODE_SYMBOLX2_0(op2, &bitD2); - HUF_DECODE_SYMBOLX2_0(op3, &bitD3); - HUF_DECODE_SYMBOLX2_0(op4, &bitD4); - - endSignal = BIT_reloadDStream(&bitD1) | BIT_reloadDStream(&bitD2) | BIT_reloadDStream(&bitD3) | BIT_reloadDStream(&bitD4); - } - - /* check corruption */ - if (op1 > opStart2) return ERROR(corruption_detected); - if (op2 > opStart3) return ERROR(corruption_detected); - if (op3 > opStart4) return ERROR(corruption_detected); - /* note : op4 already verified within main loop */ - - /* finish bitStreams one by one */ - HUF_decodeStreamX2(op1, &bitD1, opStart2, dt, dtLog); - HUF_decodeStreamX2(op2, &bitD2, opStart3, dt, dtLog); - HUF_decodeStreamX2(op3, &bitD3, opStart4, dt, dtLog); - HUF_decodeStreamX2(op4, &bitD4, oend, dt, dtLog); - - /* check */ - { U32 const endCheck = BIT_endOfDStream(&bitD1) & BIT_endOfDStream(&bitD2) & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4); - if (!endCheck) return ERROR(corruption_detected); } - - /* decoded size */ - return dstSize; - } -} - -HUF_DGEN(HUF_decompress1X2_usingDTable_internal) -HUF_DGEN(HUF_decompress4X2_usingDTable_internal) - -size_t HUF_decompress1X2_usingDTable( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc dtd = HUF_getDTableDesc(DTable); - if (dtd.tableType != 1) return ERROR(GENERIC); - return HUF_decompress1X2_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - -size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* DCtx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize) -{ - const BYTE* ip = (const BYTE*) cSrc; - - size_t const hSize = HUF_readDTableX2_wksp(DCtx, cSrc, cSrcSize, - workSpace, wkspSize); - if (HUF_isError(hSize)) return hSize; - if (hSize >= cSrcSize) return ERROR(srcSize_wrong); - ip += hSize; cSrcSize -= hSize; - - return HUF_decompress1X2_usingDTable_internal(dst, dstSize, ip, cSrcSize, DCtx, /* bmi2 */ 0); -} - - -size_t HUF_decompress1X2_DCtx(HUF_DTable* DCtx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress1X2_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} - -size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX); - return HUF_decompress1X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize); -} - -size_t HUF_decompress4X2_usingDTable( - void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc dtd = HUF_getDTableDesc(DTable); - if (dtd.tableType != 1) return ERROR(GENERIC); - return HUF_decompress4X2_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - -static size_t HUF_decompress4X2_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize, int bmi2) -{ - const BYTE* ip = (const BYTE*) cSrc; - - size_t hSize = HUF_readDTableX2_wksp(dctx, cSrc, cSrcSize, - workSpace, wkspSize); - if (HUF_isError(hSize)) return hSize; - if (hSize >= cSrcSize) return ERROR(srcSize_wrong); - ip += hSize; cSrcSize -= hSize; - - return HUF_decompress4X2_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2); -} - -size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize) -{ - return HUF_decompress4X2_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, /* bmi2 */ 0); -} - - -size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} - -size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX); - return HUF_decompress4X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize); -} - - -/* ***********************************/ -/* Universal decompression selectors */ -/* ***********************************/ - -size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc const dtd = HUF_getDTableDesc(DTable); - return dtd.tableType ? HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0) : - HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - -size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, - const void* cSrc, size_t cSrcSize, - const HUF_DTable* DTable) -{ - DTableDesc const dtd = HUF_getDTableDesc(DTable); - return dtd.tableType ? HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0) : - HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0); -} - - -typedef struct { U32 tableTime; U32 decode256Time; } algo_time_t; -static const algo_time_t algoTime[16 /* Quantization */][3 /* single, double, quad */] = -{ - /* single, double, quad */ - {{0,0}, {1,1}, {2,2}}, /* Q==0 : impossible */ - {{0,0}, {1,1}, {2,2}}, /* Q==1 : impossible */ - {{ 38,130}, {1313, 74}, {2151, 38}}, /* Q == 2 : 12-18% */ - {{ 448,128}, {1353, 74}, {2238, 41}}, /* Q == 3 : 18-25% */ - {{ 556,128}, {1353, 74}, {2238, 47}}, /* Q == 4 : 25-32% */ - {{ 714,128}, {1418, 74}, {2436, 53}}, /* Q == 5 : 32-38% */ - {{ 883,128}, {1437, 74}, {2464, 61}}, /* Q == 6 : 38-44% */ - {{ 897,128}, {1515, 75}, {2622, 68}}, /* Q == 7 : 44-50% */ - {{ 926,128}, {1613, 75}, {2730, 75}}, /* Q == 8 : 50-56% */ - {{ 947,128}, {1729, 77}, {3359, 77}}, /* Q == 9 : 56-62% */ - {{1107,128}, {2083, 81}, {4006, 84}}, /* Q ==10 : 62-69% */ - {{1177,128}, {2379, 87}, {4785, 88}}, /* Q ==11 : 69-75% */ - {{1242,128}, {2415, 93}, {5155, 84}}, /* Q ==12 : 75-81% */ - {{1349,128}, {2644,106}, {5260,106}}, /* Q ==13 : 81-87% */ - {{1455,128}, {2422,124}, {4174,124}}, /* Q ==14 : 87-93% */ - {{ 722,128}, {1891,145}, {1936,146}}, /* Q ==15 : 93-99% */ -}; - -/** HUF_selectDecoder() : - * Tells which decoder is likely to decode faster, - * based on a set of pre-computed metrics. - * @return : 0==HUF_decompress4X1, 1==HUF_decompress4X2 . - * Assumption : 0 < dstSize <= 128 KB */ -U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize) -{ - assert(dstSize > 0); - assert(dstSize <= 128*1024); - /* decoder timing evaluation */ - { U32 const Q = (cSrcSize >= dstSize) ? 15 : (U32)(cSrcSize * 16 / dstSize); /* Q < 16 */ - U32 const D256 = (U32)(dstSize >> 8); - U32 const DTime0 = algoTime[Q][0].tableTime + (algoTime[Q][0].decode256Time * D256); - U32 DTime1 = algoTime[Q][1].tableTime + (algoTime[Q][1].decode256Time * D256); - DTime1 += DTime1 >> 3; /* advantage to algorithm using less memory, to reduce cache eviction */ - return DTime1 < DTime0; -} } - - -typedef size_t (*decompressionAlgo)(void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); - -size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - static const decompressionAlgo decompress[2] = { HUF_decompress4X1, HUF_decompress4X2 }; - - /* validation checks */ - if (dstSize == 0) return ERROR(dstSize_tooSmall); - if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */ - if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */ - if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */ - - { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize); - return decompress[algoNb](dst, dstSize, cSrc, cSrcSize); - } -} - -size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - /* validation checks */ - if (dstSize == 0) return ERROR(dstSize_tooSmall); - if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */ - if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */ - if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */ - - { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize); - return algoNb ? HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) : - HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) ; - } -} - -size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress4X_hufOnly_wksp(dctx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} - - -size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, - size_t dstSize, const void* cSrc, - size_t cSrcSize, void* workSpace, - size_t wkspSize) -{ - /* validation checks */ - if (dstSize == 0) return ERROR(dstSize_tooSmall); - if (cSrcSize == 0) return ERROR(corruption_detected); - - { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize); - return algoNb ? HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize): - HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize); - } -} - -size_t HUF_decompress1X_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize, - void* workSpace, size_t wkspSize) -{ - /* validation checks */ - if (dstSize == 0) return ERROR(dstSize_tooSmall); - if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */ - if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */ - if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */ - - { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize); - return algoNb ? HUF_decompress1X2_DCtx_wksp(dctx, dst, dstSize, cSrc, - cSrcSize, workSpace, wkspSize): - HUF_decompress1X1_DCtx_wksp(dctx, dst, dstSize, cSrc, - cSrcSize, workSpace, wkspSize); - } -} - -size_t HUF_decompress1X_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, - const void* cSrc, size_t cSrcSize) -{ - U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; - return HUF_decompress1X_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, - workSpace, sizeof(workSpace)); -} - - -size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2) -{ - DTableDesc const dtd = HUF_getDTableDesc(DTable); - return dtd.tableType ? HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2) : - HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2); -} - -size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2) -{ - const BYTE* ip = (const BYTE*) cSrc; - - size_t const hSize = HUF_readDTableX1_wksp(dctx, cSrc, cSrcSize, workSpace, wkspSize); - if (HUF_isError(hSize)) return hSize; - if (hSize >= cSrcSize) return ERROR(srcSize_wrong); - ip += hSize; cSrcSize -= hSize; - - return HUF_decompress1X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2); -} - -size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2) -{ - DTableDesc const dtd = HUF_getDTableDesc(DTable); - return dtd.tableType ? HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2) : - HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2); -} - -size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2) -{ - /* validation checks */ - if (dstSize == 0) return ERROR(dstSize_tooSmall); - if (cSrcSize == 0) return ERROR(corruption_detected); - - { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize); - return algoNb ? HUF_decompress4X2_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2) : - HUF_decompress4X1_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2); - } -} diff --git a/grub-core/lib/zstd/mem.h b/grub-core/lib/zstd/mem.h deleted file mode 100644 index 2051bcad1..000000000 --- a/grub-core/lib/zstd/mem.h +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -#ifndef MEM_H_MODULE -#define MEM_H_MODULE - -#if defined (__cplusplus) -extern "C" { -#endif - -/*-**************************************** -* Dependencies -******************************************/ -#include /* size_t, ptrdiff_t */ -#include /* memcpy */ - - -/*-**************************************** -* Compiler specifics -******************************************/ -#if defined(_MSC_VER) /* Visual Studio */ -# include /* _byteswap_ulong */ -# include /* _byteswap_* */ -#endif -#if defined(__GNUC__) -# define MEM_STATIC static __inline __attribute__((unused)) -#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) -# define MEM_STATIC static inline -#elif defined(_MSC_VER) -# define MEM_STATIC static __inline -#else -# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ -#endif - -/* code only tested on 32 and 64 bits systems */ -#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; } -MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); } - - -/*-************************************************************** -* Basic Types -*****************************************************************/ -#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) -# include - typedef uint8_t BYTE; - typedef uint16_t U16; - typedef int16_t S16; - typedef uint32_t U32; - typedef int32_t S32; - typedef uint64_t U64; - typedef int64_t S64; -#else -# include -#if CHAR_BIT != 8 -# error "this implementation requires char to be exactly 8-bit type" -#endif - typedef unsigned char BYTE; -#if USHRT_MAX != 65535 -# error "this implementation requires short to be exactly 16-bit type" -#endif - typedef unsigned short U16; - typedef signed short S16; -#if UINT_MAX != 4294967295 -# error "this implementation requires int to be exactly 32-bit type" -#endif - typedef unsigned int U32; - typedef signed int S32; -/* note : there are no limits defined for long long type in C90. - * limits exist in C99, however, in such case, is preferred */ - typedef unsigned long long U64; - typedef signed long long S64; -#endif - - -/*-************************************************************** -* Memory I/O -*****************************************************************/ -/* MEM_FORCE_MEMORY_ACCESS : - * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. - * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. - * The below switch allow to select different access method for improved performance. - * Method 0 (default) : use `memcpy()`. Safe and portable. - * Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable). - * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. - * Method 2 : direct access. This method is portable but violate C standard. - * It can generate buggy code on targets depending on alignment. - * In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6) - * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. - * Prefer these methods in priority order (0 > 1 > 2) - */ -#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ -# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) -# define MEM_FORCE_MEMORY_ACCESS 2 -# elif defined(__INTEL_COMPILER) || defined(__GNUC__) -# define MEM_FORCE_MEMORY_ACCESS 1 -# endif -#endif - -MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; } -MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; } - -MEM_STATIC unsigned MEM_isLittleEndian(void) -{ - const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ - return one.c[0]; -} - -#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2) - -/* violates C standard, by lying on structure alignment. -Only use if no other choice to achieve best performance on target platform */ -MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; } -MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; } -MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; } -MEM_STATIC size_t MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; } - -MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } -MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } -MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; } - -#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1) - -/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ -/* currently only defined for gcc and icc */ -#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32)) - __pragma( pack(push, 1) ) - typedef struct { U16 v; } unalign16; - typedef struct { U32 v; } unalign32; - typedef struct { U64 v; } unalign64; - typedef struct { size_t v; } unalignArch; - __pragma( pack(pop) ) -#else - typedef struct { U16 v; } __attribute__((packed)) unalign16; - typedef struct { U32 v; } __attribute__((packed)) unalign32; - typedef struct { U64 v; } __attribute__((packed)) unalign64; - typedef struct { size_t v; } __attribute__((packed)) unalignArch; -#endif - -MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign16*)ptr)->v; } -MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign32*)ptr)->v; } -MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign64*)ptr)->v; } -MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalignArch*)ptr)->v; } - -MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign16*)memPtr)->v = value; } -MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign32*)memPtr)->v = value; } -MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v = value; } - -#else - -/* default method, safe and standard. - can sometimes prove slower */ - -MEM_STATIC U16 MEM_read16(const void* memPtr) -{ - U16 val; memcpy(&val, memPtr, sizeof(val)); return val; -} - -MEM_STATIC U32 MEM_read32(const void* memPtr) -{ - U32 val; memcpy(&val, memPtr, sizeof(val)); return val; -} - -MEM_STATIC U64 MEM_read64(const void* memPtr) -{ - U64 val; memcpy(&val, memPtr, sizeof(val)); return val; -} - -MEM_STATIC size_t MEM_readST(const void* memPtr) -{ - size_t val; memcpy(&val, memPtr, sizeof(val)); return val; -} - -MEM_STATIC void MEM_write16(void* memPtr, U16 value) -{ - memcpy(memPtr, &value, sizeof(value)); -} - -MEM_STATIC void MEM_write32(void* memPtr, U32 value) -{ - memcpy(memPtr, &value, sizeof(value)); -} - -MEM_STATIC void MEM_write64(void* memPtr, U64 value) -{ - memcpy(memPtr, &value, sizeof(value)); -} - -#endif /* MEM_FORCE_MEMORY_ACCESS */ - -MEM_STATIC U32 MEM_swap32(U32 in) -{ -#if defined(_MSC_VER) /* Visual Studio */ - return _byteswap_ulong(in); -#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) - return __builtin_bswap32(in); -#else - return ((in << 24) & 0xff000000 ) | - ((in << 8) & 0x00ff0000 ) | - ((in >> 8) & 0x0000ff00 ) | - ((in >> 24) & 0x000000ff ); -#endif -} - -MEM_STATIC U64 MEM_swap64(U64 in) -{ -#if defined(_MSC_VER) /* Visual Studio */ - return _byteswap_uint64(in); -#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) - return __builtin_bswap64(in); -#else - return ((in << 56) & 0xff00000000000000ULL) | - ((in << 40) & 0x00ff000000000000ULL) | - ((in << 24) & 0x0000ff0000000000ULL) | - ((in << 8) & 0x000000ff00000000ULL) | - ((in >> 8) & 0x00000000ff000000ULL) | - ((in >> 24) & 0x0000000000ff0000ULL) | - ((in >> 40) & 0x000000000000ff00ULL) | - ((in >> 56) & 0x00000000000000ffULL); -#endif -} - -MEM_STATIC size_t MEM_swapST(size_t in) -{ - if (MEM_32bits()) - return (size_t)MEM_swap32((U32)in); - else - return (size_t)MEM_swap64((U64)in); -} - -/*=== Little endian r/w ===*/ - -MEM_STATIC U16 MEM_readLE16(const void* memPtr) -{ - if (MEM_isLittleEndian()) - return MEM_read16(memPtr); - else { - const BYTE* p = (const BYTE*)memPtr; - return (U16)(p[0] + (p[1]<<8)); - } -} - -MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val) -{ - if (MEM_isLittleEndian()) { - MEM_write16(memPtr, val); - } else { - BYTE* p = (BYTE*)memPtr; - p[0] = (BYTE)val; - p[1] = (BYTE)(val>>8); - } -} - -MEM_STATIC U32 MEM_readLE24(const void* memPtr) -{ - return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16); -} - -MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val) -{ - MEM_writeLE16(memPtr, (U16)val); - ((BYTE*)memPtr)[2] = (BYTE)(val>>16); -} - -MEM_STATIC U32 MEM_readLE32(const void* memPtr) -{ - if (MEM_isLittleEndian()) - return MEM_read32(memPtr); - else - return MEM_swap32(MEM_read32(memPtr)); -} - -MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32) -{ - if (MEM_isLittleEndian()) - MEM_write32(memPtr, val32); - else - MEM_write32(memPtr, MEM_swap32(val32)); -} - -MEM_STATIC U64 MEM_readLE64(const void* memPtr) -{ - if (MEM_isLittleEndian()) - return MEM_read64(memPtr); - else - return MEM_swap64(MEM_read64(memPtr)); -} - -MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64) -{ - if (MEM_isLittleEndian()) - MEM_write64(memPtr, val64); - else - MEM_write64(memPtr, MEM_swap64(val64)); -} - -MEM_STATIC size_t MEM_readLEST(const void* memPtr) -{ - if (MEM_32bits()) - return (size_t)MEM_readLE32(memPtr); - else - return (size_t)MEM_readLE64(memPtr); -} - -MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val) -{ - if (MEM_32bits()) - MEM_writeLE32(memPtr, (U32)val); - else - MEM_writeLE64(memPtr, (U64)val); -} - -/*=== Big endian r/w ===*/ - -MEM_STATIC U32 MEM_readBE32(const void* memPtr) -{ - if (MEM_isLittleEndian()) - return MEM_swap32(MEM_read32(memPtr)); - else - return MEM_read32(memPtr); -} - -MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32) -{ - if (MEM_isLittleEndian()) - MEM_write32(memPtr, MEM_swap32(val32)); - else - MEM_write32(memPtr, val32); -} - -MEM_STATIC U64 MEM_readBE64(const void* memPtr) -{ - if (MEM_isLittleEndian()) - return MEM_swap64(MEM_read64(memPtr)); - else - return MEM_read64(memPtr); -} - -MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64) -{ - if (MEM_isLittleEndian()) - MEM_write64(memPtr, MEM_swap64(val64)); - else - MEM_write64(memPtr, val64); -} - -MEM_STATIC size_t MEM_readBEST(const void* memPtr) -{ - if (MEM_32bits()) - return (size_t)MEM_readBE32(memPtr); - else - return (size_t)MEM_readBE64(memPtr); -} - -MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val) -{ - if (MEM_32bits()) - MEM_writeBE32(memPtr, (U32)val); - else - MEM_writeBE64(memPtr, (U64)val); -} - - -#if defined (__cplusplus) -} -#endif - -#endif /* MEM_H_MODULE */ diff --git a/grub-core/lib/zstd/module.c b/grub-core/lib/zstd/module.c deleted file mode 100644 index e64d068f4..000000000 --- a/grub-core/lib/zstd/module.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include - -GRUB_MOD_LICENSE ("GPLv3"); diff --git a/grub-core/lib/zstd/xxhash.c b/grub-core/lib/zstd/xxhash.c deleted file mode 100644 index 532b81619..000000000 --- a/grub-core/lib/zstd/xxhash.c +++ /dev/null @@ -1,876 +0,0 @@ -/* -* xxHash - Fast Hash algorithm -* Copyright (C) 2012-2016, Yann Collet -* -* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following disclaimer -* in the documentation and/or other materials provided with the -* distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* You can contact the author at : -* - xxHash homepage: http://www.xxhash.com -* - xxHash source repository : https://github.com/Cyan4973/xxHash -*/ - - -/* ************************************* -* Tuning parameters -***************************************/ -/*!XXH_FORCE_MEMORY_ACCESS : - * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. - * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. - * The below switch allow to select different access method for improved performance. - * Method 0 (default) : use `memcpy()`. Safe and portable. - * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable). - * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. - * Method 2 : direct access. This method doesn't depend on compiler but violate C standard. - * It can generate buggy code on targets which do not support unaligned memory accesses. - * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) - * See http://stackoverflow.com/a/32095106/646947 for details. - * Prefer these methods in priority order (0 > 1 > 2) - */ -#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ -# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) -# define XXH_FORCE_MEMORY_ACCESS 2 -# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \ - (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) -# define XXH_FORCE_MEMORY_ACCESS 1 -# endif -#endif - -/*!XXH_ACCEPT_NULL_INPUT_POINTER : - * If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer. - * When this option is enabled, xxHash output for null input pointers will be the same as a null-length input. - * By default, this option is disabled. To enable it, uncomment below define : - */ -/* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */ - -/*!XXH_FORCE_NATIVE_FORMAT : - * By default, xxHash library provides endian-independant Hash values, based on little-endian convention. - * Results are therefore identical for little-endian and big-endian CPU. - * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format. - * Should endian-independance be of no importance for your application, you may set the #define below to 1, - * to improve speed for Big-endian CPU. - * This option has no impact on Little_Endian CPU. - */ -#ifndef XXH_FORCE_NATIVE_FORMAT /* can be defined externally */ -# define XXH_FORCE_NATIVE_FORMAT 0 -#endif - -/*!XXH_FORCE_ALIGN_CHECK : - * This is a minor performance trick, only useful with lots of very small keys. - * It means : check for aligned/unaligned input. - * The check costs one initial branch per hash; set to 0 when the input data - * is guaranteed to be aligned. - */ -#ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */ -# if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) -# define XXH_FORCE_ALIGN_CHECK 0 -# else -# define XXH_FORCE_ALIGN_CHECK 1 -# endif -#endif - - -/* ************************************* -* Includes & Memory related functions -***************************************/ -/* Modify the local functions below should you wish to use some other memory routines */ -/* for malloc(), free() */ -#include -#include /* size_t */ -static void* XXH_malloc(size_t s) { return malloc(s); } -static void XXH_free (void* p) { free(p); } -/* for memcpy() */ -#include -static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); } - -#ifndef XXH_STATIC_LINKING_ONLY -# define XXH_STATIC_LINKING_ONLY -#endif -#include "xxhash.h" - - -/* ************************************* -* Compiler Specific Options -***************************************/ -#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ -# define INLINE_KEYWORD inline -#else -# define INLINE_KEYWORD -#endif - -#if defined(__GNUC__) -# define FORCE_INLINE_ATTR __attribute__((always_inline)) -#elif defined(_MSC_VER) -# define FORCE_INLINE_ATTR __forceinline -#else -# define FORCE_INLINE_ATTR -#endif - -#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR - - -#ifdef _MSC_VER -# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ -#endif - - -/* ************************************* -* Basic Types -***************************************/ -#ifndef MEM_MODULE -# define MEM_MODULE -# if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) -# include - typedef uint8_t BYTE; - typedef uint16_t U16; - typedef uint32_t U32; - typedef int32_t S32; - typedef uint64_t U64; -# else - typedef unsigned char BYTE; - typedef unsigned short U16; - typedef unsigned int U32; - typedef signed int S32; - typedef unsigned long long U64; /* if your compiler doesn't support unsigned long long, replace by another 64-bit type here. Note that xxhash.h will also need to be updated. */ -# endif -#endif - - -#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) - -/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */ -static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; } -static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; } - -#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) - -/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ -/* currently only defined for gcc and icc */ -typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign; - -static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } -static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; } - -#else - -/* portable and safe solution. Generally efficient. - * see : http://stackoverflow.com/a/32095106/646947 - */ - -static U32 XXH_read32(const void* memPtr) -{ - U32 val; - memcpy(&val, memPtr, sizeof(val)); - return val; -} - -static U64 XXH_read64(const void* memPtr) -{ - U64 val; - memcpy(&val, memPtr, sizeof(val)); - return val; -} - -#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */ - - -/* **************************************** -* Compiler-specific Functions and Macros -******************************************/ -#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) - -/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */ -#if defined(_MSC_VER) -# define XXH_rotl32(x,r) _rotl(x,r) -# define XXH_rotl64(x,r) _rotl64(x,r) -#else -# define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r))) -# define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r))) -#endif - -#if defined(_MSC_VER) /* Visual Studio */ -# define XXH_swap32 _byteswap_ulong -# define XXH_swap64 _byteswap_uint64 -#elif GCC_VERSION >= 403 -# define XXH_swap32 __builtin_bswap32 -# define XXH_swap64 __builtin_bswap64 -#else -static U32 XXH_swap32 (U32 x) -{ - return ((x << 24) & 0xff000000 ) | - ((x << 8) & 0x00ff0000 ) | - ((x >> 8) & 0x0000ff00 ) | - ((x >> 24) & 0x000000ff ); -} -static U64 XXH_swap64 (U64 x) -{ - return ((x << 56) & 0xff00000000000000ULL) | - ((x << 40) & 0x00ff000000000000ULL) | - ((x << 24) & 0x0000ff0000000000ULL) | - ((x << 8) & 0x000000ff00000000ULL) | - ((x >> 8) & 0x00000000ff000000ULL) | - ((x >> 24) & 0x0000000000ff0000ULL) | - ((x >> 40) & 0x000000000000ff00ULL) | - ((x >> 56) & 0x00000000000000ffULL); -} -#endif - - -/* ************************************* -* Architecture Macros -***************************************/ -typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; - -/* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example on the compiler command line */ -#ifndef XXH_CPU_LITTLE_ENDIAN - static const int g_one = 1; -# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&g_one)) -#endif - - -/* *************************** -* Memory reads -*****************************/ -typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment; - -FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align) -{ - if (align==XXH_unaligned) - return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); - else - return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr); -} - -FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian) -{ - return XXH_readLE32_align(ptr, endian, XXH_unaligned); -} - -static U32 XXH_readBE32(const void* ptr) -{ - return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr); -} - -FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align) -{ - if (align==XXH_unaligned) - return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); - else - return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr); -} - -FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian) -{ - return XXH_readLE64_align(ptr, endian, XXH_unaligned); -} - -static U64 XXH_readBE64(const void* ptr) -{ - return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr); -} - - -/* ************************************* -* Macros -***************************************/ -#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */ - - -/* ************************************* -* Constants -***************************************/ -static const U32 PRIME32_1 = 2654435761U; -static const U32 PRIME32_2 = 2246822519U; -static const U32 PRIME32_3 = 3266489917U; -static const U32 PRIME32_4 = 668265263U; -static const U32 PRIME32_5 = 374761393U; - -static const U64 PRIME64_1 = 11400714785074694791ULL; -static const U64 PRIME64_2 = 14029467366897019727ULL; -static const U64 PRIME64_3 = 1609587929392839161ULL; -static const U64 PRIME64_4 = 9650029242287828579ULL; -static const U64 PRIME64_5 = 2870177450012600261ULL; - -XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; } - - -/* ************************** -* Utils -****************************/ -XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState) -{ - memcpy(dstState, srcState, sizeof(*dstState)); -} - -XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState) -{ - memcpy(dstState, srcState, sizeof(*dstState)); -} - - -/* *************************** -* Simple Hash Functions -*****************************/ - -static U32 XXH32_round(U32 seed, U32 input) -{ - seed += input * PRIME32_2; - seed = XXH_rotl32(seed, 13); - seed *= PRIME32_1; - return seed; -} - -FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align) -{ - const BYTE* p = (const BYTE*)input; - const BYTE* bEnd = p + len; - U32 h32; -#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align) - -#ifdef XXH_ACCEPT_NULL_INPUT_POINTER - if (p==NULL) { - len=0; - bEnd=p=(const BYTE*)(size_t)16; - } -#endif - - if (len>=16) { - const BYTE* const limit = bEnd - 16; - U32 v1 = seed + PRIME32_1 + PRIME32_2; - U32 v2 = seed + PRIME32_2; - U32 v3 = seed + 0; - U32 v4 = seed - PRIME32_1; - - do { - v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4; - v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4; - v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4; - v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4; - } while (p<=limit); - - h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); - } else { - h32 = seed + PRIME32_5; - } - - h32 += (U32) len; - - while (p+4<=bEnd) { - h32 += XXH_get32bits(p) * PRIME32_3; - h32 = XXH_rotl32(h32, 17) * PRIME32_4 ; - p+=4; - } - - while (p> 15; - h32 *= PRIME32_2; - h32 ^= h32 >> 13; - h32 *= PRIME32_3; - h32 ^= h32 >> 16; - - return h32; -} - - -XXH_PUBLIC_API unsigned int XXH32 (const void* input, size_t len, unsigned int seed) -{ -#if 0 - /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ - XXH32_CREATESTATE_STATIC(state); - XXH32_reset(state, seed); - XXH32_update(state, input, len); - return XXH32_digest(state); -#else - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if (XXH_FORCE_ALIGN_CHECK) { - if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */ - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); - else - return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned); - } } - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned); - else - return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned); -#endif -} - - -static U64 XXH64_round(U64 acc, U64 input) -{ - acc += input * PRIME64_2; - acc = XXH_rotl64(acc, 31); - acc *= PRIME64_1; - return acc; -} - -static U64 XXH64_mergeRound(U64 acc, U64 val) -{ - val = XXH64_round(0, val); - acc ^= val; - acc = acc * PRIME64_1 + PRIME64_4; - return acc; -} - -FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align) -{ - const BYTE* p = (const BYTE*)input; - const BYTE* const bEnd = p + len; - U64 h64; -#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align) - -#ifdef XXH_ACCEPT_NULL_INPUT_POINTER - if (p==NULL) { - len=0; - bEnd=p=(const BYTE*)(size_t)32; - } -#endif - - if (len>=32) { - const BYTE* const limit = bEnd - 32; - U64 v1 = seed + PRIME64_1 + PRIME64_2; - U64 v2 = seed + PRIME64_2; - U64 v3 = seed + 0; - U64 v4 = seed - PRIME64_1; - - do { - v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8; - v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8; - v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8; - v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8; - } while (p<=limit); - - h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); - h64 = XXH64_mergeRound(h64, v1); - h64 = XXH64_mergeRound(h64, v2); - h64 = XXH64_mergeRound(h64, v3); - h64 = XXH64_mergeRound(h64, v4); - - } else { - h64 = seed + PRIME64_5; - } - - h64 += (U64) len; - - while (p+8<=bEnd) { - U64 const k1 = XXH64_round(0, XXH_get64bits(p)); - h64 ^= k1; - h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; - p+=8; - } - - if (p+4<=bEnd) { - h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; - h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; - p+=4; - } - - while (p> 33; - h64 *= PRIME64_2; - h64 ^= h64 >> 29; - h64 *= PRIME64_3; - h64 ^= h64 >> 32; - - return h64; -} - - -XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed) -{ -#if 0 - /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ - XXH64_CREATESTATE_STATIC(state); - XXH64_reset(state, seed); - XXH64_update(state, input, len); - return XXH64_digest(state); -#else - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if (XXH_FORCE_ALIGN_CHECK) { - if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */ - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); - else - return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned); - } } - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned); - else - return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned); -#endif -} - - -/* ************************************************** -* Advanced Hash Functions -****************************************************/ - -XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void) -{ - return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t)); -} -XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr) -{ - XXH_free(statePtr); - return XXH_OK; -} - -XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void) -{ - return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t)); -} -XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr) -{ - XXH_free(statePtr); - return XXH_OK; -} - - -/*** Hash feed ***/ - -XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed) -{ - XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */ - memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */ - state.v1 = seed + PRIME32_1 + PRIME32_2; - state.v2 = seed + PRIME32_2; - state.v3 = seed + 0; - state.v4 = seed - PRIME32_1; - memcpy(statePtr, &state, sizeof(state)); - return XXH_OK; -} - - -XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed) -{ - XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */ - memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */ - state.v1 = seed + PRIME64_1 + PRIME64_2; - state.v2 = seed + PRIME64_2; - state.v3 = seed + 0; - state.v4 = seed - PRIME64_1; - memcpy(statePtr, &state, sizeof(state)); - return XXH_OK; -} - - -FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian) -{ - const BYTE* p = (const BYTE*)input; - const BYTE* const bEnd = p + len; - -#ifdef XXH_ACCEPT_NULL_INPUT_POINTER - if (input==NULL) return XXH_ERROR; -#endif - - state->total_len_32 += (unsigned)len; - state->large_len |= (len>=16) | (state->total_len_32>=16); - - if (state->memsize + len < 16) { /* fill in tmp buffer */ - XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len); - state->memsize += (unsigned)len; - return XXH_OK; - } - - if (state->memsize) { /* some data left from previous update */ - XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize); - { const U32* p32 = state->mem32; - state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++; - state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++; - state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++; - state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian)); p32++; - } - p += 16-state->memsize; - state->memsize = 0; - } - - if (p <= bEnd-16) { - const BYTE* const limit = bEnd - 16; - U32 v1 = state->v1; - U32 v2 = state->v2; - U32 v3 = state->v3; - U32 v4 = state->v4; - - do { - v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4; - v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4; - v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4; - v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4; - } while (p<=limit); - - state->v1 = v1; - state->v2 = v2; - state->v3 = v3; - state->v4 = v4; - } - - if (p < bEnd) { - XXH_memcpy(state->mem32, p, (size_t)(bEnd-p)); - state->memsize = (unsigned)(bEnd-p); - } - - return XXH_OK; -} - -XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len) -{ - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH32_update_endian(state_in, input, len, XXH_littleEndian); - else - return XXH32_update_endian(state_in, input, len, XXH_bigEndian); -} - - - -FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian) -{ - const BYTE * p = (const BYTE*)state->mem32; - const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize; - U32 h32; - - if (state->large_len) { - h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18); - } else { - h32 = state->v3 /* == seed */ + PRIME32_5; - } - - h32 += state->total_len_32; - - while (p+4<=bEnd) { - h32 += XXH_readLE32(p, endian) * PRIME32_3; - h32 = XXH_rotl32(h32, 17) * PRIME32_4; - p+=4; - } - - while (p> 15; - h32 *= PRIME32_2; - h32 ^= h32 >> 13; - h32 *= PRIME32_3; - h32 ^= h32 >> 16; - - return h32; -} - - -XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in) -{ - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH32_digest_endian(state_in, XXH_littleEndian); - else - return XXH32_digest_endian(state_in, XXH_bigEndian); -} - - - -/* **** XXH64 **** */ - -FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian) -{ - const BYTE* p = (const BYTE*)input; - const BYTE* const bEnd = p + len; - -#ifdef XXH_ACCEPT_NULL_INPUT_POINTER - if (input==NULL) return XXH_ERROR; -#endif - - state->total_len += len; - - if (state->memsize + len < 32) { /* fill in tmp buffer */ - XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len); - state->memsize += (U32)len; - return XXH_OK; - } - - if (state->memsize) { /* tmp buffer is full */ - XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize); - state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian)); - state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian)); - state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian)); - state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian)); - p += 32-state->memsize; - state->memsize = 0; - } - - if (p+32 <= bEnd) { - const BYTE* const limit = bEnd - 32; - U64 v1 = state->v1; - U64 v2 = state->v2; - U64 v3 = state->v3; - U64 v4 = state->v4; - - do { - v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8; - v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8; - v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8; - v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8; - } while (p<=limit); - - state->v1 = v1; - state->v2 = v2; - state->v3 = v3; - state->v4 = v4; - } - - if (p < bEnd) { - XXH_memcpy(state->mem64, p, (size_t)(bEnd-p)); - state->memsize = (unsigned)(bEnd-p); - } - - return XXH_OK; -} - -XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len) -{ - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH64_update_endian(state_in, input, len, XXH_littleEndian); - else - return XXH64_update_endian(state_in, input, len, XXH_bigEndian); -} - - - -FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian) -{ - const BYTE * p = (const BYTE*)state->mem64; - const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize; - U64 h64; - - if (state->total_len >= 32) { - U64 const v1 = state->v1; - U64 const v2 = state->v2; - U64 const v3 = state->v3; - U64 const v4 = state->v4; - - h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); - h64 = XXH64_mergeRound(h64, v1); - h64 = XXH64_mergeRound(h64, v2); - h64 = XXH64_mergeRound(h64, v3); - h64 = XXH64_mergeRound(h64, v4); - } else { - h64 = state->v3 + PRIME64_5; - } - - h64 += (U64) state->total_len; - - while (p+8<=bEnd) { - U64 const k1 = XXH64_round(0, XXH_readLE64(p, endian)); - h64 ^= k1; - h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; - p+=8; - } - - if (p+4<=bEnd) { - h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1; - h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; - p+=4; - } - - while (p> 33; - h64 *= PRIME64_2; - h64 ^= h64 >> 29; - h64 *= PRIME64_3; - h64 ^= h64 >> 32; - - return h64; -} - - -XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t* state_in) -{ - XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; - - if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) - return XXH64_digest_endian(state_in, XXH_littleEndian); - else - return XXH64_digest_endian(state_in, XXH_bigEndian); -} - - -/* ************************** -* Canonical representation -****************************/ - -/*! Default XXH result types are basic unsigned 32 and 64 bits. -* The canonical representation follows human-readable write convention, aka big-endian (large digits first). -* These functions allow transformation of hash result into and from its canonical format. -* This way, hash values can be written into a file or buffer, and remain comparable across different systems and programs. -*/ - -XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash) -{ - XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t)); - if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash); - memcpy(dst, &hash, sizeof(*dst)); -} - -XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash) -{ - XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t)); - if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash); - memcpy(dst, &hash, sizeof(*dst)); -} - -XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src) -{ - return XXH_readBE32(src); -} - -XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src) -{ - return XXH_readBE64(src); -} diff --git a/grub-core/lib/zstd/xxhash.h b/grub-core/lib/zstd/xxhash.h deleted file mode 100644 index 9bad1f59f..000000000 --- a/grub-core/lib/zstd/xxhash.h +++ /dev/null @@ -1,305 +0,0 @@ -/* - xxHash - Extremely Fast Hash algorithm - Header File - Copyright (C) 2012-2016, Yann Collet. - - BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - You can contact the author at : - - xxHash source repository : https://github.com/Cyan4973/xxHash -*/ - -/* Notice extracted from xxHash homepage : - -xxHash is an extremely fast Hash algorithm, running at RAM speed limits. -It also successfully passes all tests from the SMHasher suite. - -Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) - -Name Speed Q.Score Author -xxHash 5.4 GB/s 10 -CrapWow 3.2 GB/s 2 Andrew -MumurHash 3a 2.7 GB/s 10 Austin Appleby -SpookyHash 2.0 GB/s 10 Bob Jenkins -SBox 1.4 GB/s 9 Bret Mulvey -Lookup3 1.2 GB/s 9 Bob Jenkins -SuperFastHash 1.2 GB/s 1 Paul Hsieh -CityHash64 1.05 GB/s 10 Pike & Alakuijala -FNV 0.55 GB/s 5 Fowler, Noll, Vo -CRC32 0.43 GB/s 9 -MD5-32 0.33 GB/s 10 Ronald L. Rivest -SHA1-32 0.28 GB/s 10 - -Q.Score is a measure of quality of the hash function. -It depends on successfully passing SMHasher test set. -10 is a perfect score. - -A 64-bits version, named XXH64, is available since r35. -It offers much better speed, but for 64-bits applications only. -Name Speed on 64 bits Speed on 32 bits -XXH64 13.8 GB/s 1.9 GB/s -XXH32 6.8 GB/s 6.0 GB/s -*/ - -#if defined (__cplusplus) -extern "C" { -#endif - -#ifndef XXHASH_H_5627135585666179 -#define XXHASH_H_5627135585666179 1 - - -/* **************************** -* Definitions -******************************/ -#include /* size_t */ -typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; - - -/* **************************** -* API modifier -******************************/ -/** XXH_PRIVATE_API -* This is useful if you want to include xxhash functions in `static` mode -* in order to inline them, and remove their symbol from the public list. -* Methodology : -* #define XXH_PRIVATE_API -* #include "xxhash.h" -* `xxhash.c` is automatically included. -* It's not useful to compile and link it as a separate module anymore. -*/ -#ifdef XXH_PRIVATE_API -# ifndef XXH_STATIC_LINKING_ONLY -# define XXH_STATIC_LINKING_ONLY -# endif -# if defined(__GNUC__) -# define XXH_PUBLIC_API static __inline __attribute__((unused)) -# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) -# define XXH_PUBLIC_API static inline -# elif defined(_MSC_VER) -# define XXH_PUBLIC_API static __inline -# else -# define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */ -# endif -#else -# define XXH_PUBLIC_API /* do nothing */ -#endif /* XXH_PRIVATE_API */ - -/*!XXH_NAMESPACE, aka Namespace Emulation : - -If you want to include _and expose_ xxHash functions from within your own library, -but also want to avoid symbol collisions with another library which also includes xxHash, - -you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library -with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values). - -Note that no change is required within the calling program as long as it includes `xxhash.h` : -regular symbol name will be automatically translated by this header. -*/ -#ifdef XXH_NAMESPACE -# define XXH_CAT(A,B) A##B -# define XXH_NAME2(A,B) XXH_CAT(A,B) -# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) -# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) -# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber) -# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) -# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) -# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) -# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) -# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) -# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) -# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) -# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) -# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) -# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) -# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState) -# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState) -# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash) -# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash) -# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical) -# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical) -#endif - - -/* ************************************* -* Version -***************************************/ -#define XXH_VERSION_MAJOR 0 -#define XXH_VERSION_MINOR 6 -#define XXH_VERSION_RELEASE 2 -#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) -XXH_PUBLIC_API unsigned XXH_versionNumber (void); - - -/* **************************** -* Simple Hash Functions -******************************/ -typedef unsigned int XXH32_hash_t; -typedef unsigned long long XXH64_hash_t; - -XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed); -XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); - -/*! -XXH32() : - Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". - The memory between input & input+length must be valid (allocated and read-accessible). - "seed" can be used to alter the result predictably. - Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s -XXH64() : - Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". - "seed" can be used to alter the result predictably. - This function runs 2x faster on 64-bits systems, but slower on 32-bits systems (see benchmark). -*/ - - -/* **************************** -* Streaming Hash Functions -******************************/ -typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ -typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ - -/*! State allocation, compatible with dynamic libraries */ - -XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void); -XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); - -XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void); -XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); - - -/* hash streaming */ - -XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed); -XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); -XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); - -XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed); -XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); -XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); - -/* -These functions generate the xxHash of an input provided in multiple segments. -Note that, for small input, they are slower than single-call functions, due to state management. -For small input, prefer `XXH32()` and `XXH64()` . - -XXH state must first be allocated, using XXH*_createState() . - -Start a new hash by initializing state with a seed, using XXH*_reset(). - -Then, feed the hash state by calling XXH*_update() as many times as necessary. -Obviously, input must be allocated and read accessible. -The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. - -Finally, a hash value can be produced anytime, by using XXH*_digest(). -This function returns the nn-bits hash as an int or long long. - -It's still possible to continue inserting input into the hash state after a digest, -and generate some new hashes later on, by calling again XXH*_digest(). - -When done, free XXH state space if it was allocated dynamically. -*/ - - -/* ************************** -* Utils -****************************/ -#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* ! C99 */ -# define restrict /* disable restrict */ -#endif - -XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state); -XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state); - - -/* ************************** -* Canonical representation -****************************/ -/* Default result type for XXH functions are primitive unsigned 32 and 64 bits. -* The canonical representation uses human-readable write convention, aka big-endian (large digits first). -* These functions allow transformation of hash result into and from its canonical format. -* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs. -*/ -typedef struct { unsigned char digest[4]; } XXH32_canonical_t; -typedef struct { unsigned char digest[8]; } XXH64_canonical_t; - -XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); -XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); - -XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); -XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src); - -#endif /* XXHASH_H_5627135585666179 */ - - - -/* ================================================================================================ - This section contains definitions which are not guaranteed to remain stable. - They may change in future versions, becoming incompatible with a different version of the library. - They shall only be used with static linking. - Never use these definitions in association with dynamic linking ! -=================================================================================================== */ -#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345) -#define XXH_STATIC_H_3543687687345 - -/* These definitions are only meant to allow allocation of XXH state - statically, on stack, or in a struct for example. - Do not use members directly. */ - - struct XXH32_state_s { - unsigned total_len_32; - unsigned large_len; - unsigned v1; - unsigned v2; - unsigned v3; - unsigned v4; - unsigned mem32[4]; /* buffer defined as U32 for alignment */ - unsigned memsize; - unsigned reserved; /* never read nor write, will be removed in a future version */ - }; /* typedef'd to XXH32_state_t */ - - struct XXH64_state_s { - unsigned long long total_len; - unsigned long long v1; - unsigned long long v2; - unsigned long long v3; - unsigned long long v4; - unsigned long long mem64[4]; /* buffer defined as U64 for alignment */ - unsigned memsize; - unsigned reserved[2]; /* never read nor write, will be removed in a future version */ - }; /* typedef'd to XXH64_state_t */ - - -# ifdef XXH_PRIVATE_API -# include "xxhash.c" /* include xxhash functions as `static`, for inlining */ -# endif - -#endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */ - - -#if defined (__cplusplus) -} -#endif diff --git a/grub-core/lib/zstd/zstd.h b/grub-core/lib/zstd/zstd.h deleted file mode 100644 index 7b6964be3..000000000 --- a/grub-core/lib/zstd/zstd.h +++ /dev/null @@ -1,1516 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ -#if defined (__cplusplus) -extern "C" { -#endif - -#ifndef ZSTD_H_235446 -#define ZSTD_H_235446 - -/* ====== Dependency ======*/ -#include /* size_t */ - - -/* ===== ZSTDLIB_API : control library symbols visibility ===== */ -#ifndef ZSTDLIB_VISIBILITY -# if defined(__GNUC__) && (__GNUC__ >= 4) -# define ZSTDLIB_VISIBILITY __attribute__ ((visibility ("default"))) -# else -# define ZSTDLIB_VISIBILITY -# endif -#endif -#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) -# define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBILITY -#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) -# define ZSTDLIB_API __declspec(dllimport) ZSTDLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ -#else -# define ZSTDLIB_API ZSTDLIB_VISIBILITY -#endif - - -/******************************************************************************* - Introduction - - zstd, short for Zstandard, is a fast lossless compression algorithm, targeting - real-time compression scenarios at zlib-level and better compression ratios. - The zstd compression library provides in-memory compression and decompression - functions. - - The library supports regular compression levels from 1 up to ZSTD_maxCLevel(), - which is currently 22. Levels >= 20, labeled `--ultra`, should be used with - caution, as they require more memory. The library also offers negative - compression levels, which extend the range of speed vs. ratio preferences. - The lower the level, the faster the speed (at the cost of compression). - - Compression can be done in: - - a single step (described as Simple API) - - a single step, reusing a context (described as Explicit context) - - unbounded multiple steps (described as Streaming compression) - - The compression ratio achievable on small data can be highly improved using - a dictionary. Dictionary compression can be performed in: - - a single step (described as Simple dictionary API) - - a single step, reusing a dictionary (described as Bulk-processing - dictionary API) - - Advanced experimental functions can be accessed using - `#define ZSTD_STATIC_LINKING_ONLY` before including zstd.h. - - Advanced experimental APIs should never be used with a dynamically-linked - library. They are not "stable"; their definitions or signatures may change in - the future. Only static linking is allowed. -*******************************************************************************/ - -/*------ Version ------*/ -#define ZSTD_VERSION_MAJOR 1 -#define ZSTD_VERSION_MINOR 3 -#define ZSTD_VERSION_RELEASE 6 - -#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) -ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll version */ - -#define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE -#define ZSTD_QUOTE(str) #str -#define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) -#define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) -ZSTDLIB_API const char* ZSTD_versionString(void); /* v1.3.0+ */ - -/*************************************** -* Default constant -***************************************/ -#ifndef ZSTD_CLEVEL_DEFAULT -# define ZSTD_CLEVEL_DEFAULT 3 -#endif - -/*************************************** -* Simple API -***************************************/ -/*! ZSTD_compress() : - * Compresses `src` content as a single zstd compressed frame into already allocated `dst`. - * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. - * @return : compressed size written into `dst` (<= `dstCapacity), - * or an error code if it fails (which can be tested using ZSTD_isError()). */ -ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - int compressionLevel); - -/*! ZSTD_decompress() : - * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. - * `dstCapacity` is an upper bound of originalSize to regenerate. - * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. - * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), - * or an errorCode if it fails (which can be tested using ZSTD_isError()). */ -ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, - const void* src, size_t compressedSize); - -/*! ZSTD_getFrameContentSize() : added in v1.3.0 - * `src` should point to the start of a ZSTD encoded frame. - * `srcSize` must be at least as large as the frame header. - * hint : any size >= `ZSTD_frameHeaderSize_max` is large enough. - * @return : - decompressed size of `src` frame content, if known - * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined - * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) - * note 1 : a 0 return value means the frame is valid but "empty". - * note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode. - * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. - * In which case, it's necessary to use streaming mode to decompress data. - * Optionally, application can rely on some implicit limit, - * as ZSTD_decompress() only needs an upper bound of decompressed size. - * (For example, data could be necessarily cut into blocks <= 16 KB). - * note 3 : decompressed size is always present when compression is completed using single-pass functions, - * such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict(). - * note 4 : decompressed size can be very large (64-bits value), - * potentially larger than what local system can handle as a single memory segment. - * In which case, it's necessary to use streaming mode to decompress data. - * note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. - * Always ensure return value fits within application's authorized limits. - * Each application can set its own limits. - * note 6 : This function replaces ZSTD_getDecompressedSize() */ -#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1) -#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) -ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize); - -/*! ZSTD_getDecompressedSize() : - * NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). - * Both functions work the same way, but ZSTD_getDecompressedSize() blends - * "empty", "unknown" and "error" results to the same return value (0), - * while ZSTD_getFrameContentSize() gives them separate return values. - * @return : decompressed size of `src` frame content _if known and not empty_, 0 otherwise. */ -ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); - - -/*====== Helper functions ======*/ -#define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */ -ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */ -ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ -ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ -ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ - - -/*************************************** -* Explicit context -***************************************/ -/*= Compression context - * When compressing many times, - * it is recommended to allocate a context just once, and re-use it for each successive compression operation. - * This will make workload friendlier for system's memory. - * Use one context per thread for parallel execution in multi-threaded environments. */ -typedef struct ZSTD_CCtx_s ZSTD_CCtx; -ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); -ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); - -/*! ZSTD_compressCCtx() : - * Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ -ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - int compressionLevel); - -/*= Decompression context - * When decompressing many times, - * it is recommended to allocate a context only once, - * and re-use it for each successive compression operation. - * This will make workload friendlier for system's memory. - * Use one context per thread for parallel execution. */ -typedef struct ZSTD_DCtx_s ZSTD_DCtx; -ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); -ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); - -/*! ZSTD_decompressDCtx() : - * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */ -ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize); - - -/************************** -* Simple dictionary API -***************************/ -/*! ZSTD_compress_usingDict() : - * Compression using a predefined Dictionary (see dictBuilder/zdict.h). - * Note : This function loads the dictionary, resulting in significant startup delay. - * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ -ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const void* dict,size_t dictSize, - int compressionLevel); - -/*! ZSTD_decompress_usingDict() : - * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). - * Dictionary must be identical to the one used during compression. - * Note : This function loads the dictionary, resulting in significant startup delay. - * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ -ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const void* dict,size_t dictSize); - - -/********************************** - * Bulk processing dictionary API - *********************************/ -typedef struct ZSTD_CDict_s ZSTD_CDict; - -/*! ZSTD_createCDict() : - * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. - * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. - * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. - * `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict - * Note : A ZSTD_CDict can be created with an empty dictionary, but it is inefficient for small data. */ -ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize, - int compressionLevel); - -/*! ZSTD_freeCDict() : - * Function frees memory allocated by ZSTD_createCDict(). */ -ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); - -/*! ZSTD_compress_usingCDict() : - * Compression using a digested Dictionary. - * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. - * Note that compression level is decided during dictionary creation. - * Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) - * Note : ZSTD_compress_usingCDict() can be used with a ZSTD_CDict created from an empty dictionary. - * But it is inefficient for small data, and it is recommended to use ZSTD_compressCCtx(). */ -ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const ZSTD_CDict* cdict); - - -typedef struct ZSTD_DDict_s ZSTD_DDict; - -/*! ZSTD_createDDict() : - * Create a digested dictionary, ready to start decompression operation without startup delay. - * dictBuffer can be released after DDict creation, as its content is copied inside DDict */ -ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize); - -/*! ZSTD_freeDDict() : - * Function frees memory allocated with ZSTD_createDDict() */ -ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); - -/*! ZSTD_decompress_usingDDict() : - * Decompression using a digested Dictionary. - * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ -ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const ZSTD_DDict* ddict); - - -/**************************** -* Streaming -****************************/ - -typedef struct ZSTD_inBuffer_s { - const void* src; /**< start of input buffer */ - size_t size; /**< size of input buffer */ - size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ -} ZSTD_inBuffer; - -typedef struct ZSTD_outBuffer_s { - void* dst; /**< start of output buffer */ - size_t size; /**< size of output buffer */ - size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ -} ZSTD_outBuffer; - - - -/*-*********************************************************************** -* Streaming compression - HowTo -* -* A ZSTD_CStream object is required to track streaming operation. -* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources. -* ZSTD_CStream objects can be reused multiple times on consecutive compression operations. -* It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively, -* since it will play nicer with system's memory, by re-using already allocated memory. -* Use one separate ZSTD_CStream per thread for parallel execution. -* -* Start a new compression by initializing ZSTD_CStream context. -* Use ZSTD_initCStream() to start a new compression operation. -* Use variants ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for streaming with dictionary (experimental section) -* -* Use ZSTD_compressStream() as many times as necessary to consume input stream. -* The function will automatically update both `pos` fields within `input` and `output`. -* Note that the function may not consume the entire input, -* for example, because the output buffer is already full, -* in which case `input.pos < input.size`. -* The caller must check if input has been entirely consumed. -* If not, the caller must make some room to receive more compressed data, -* typically by emptying output buffer, or allocating a new output buffer, -* and then present again remaining input data. -* @return : a size hint, preferred nb of bytes to use as input for next function call -* or an error code, which can be tested using ZSTD_isError(). -* Note 1 : it's just a hint, to help latency a little, any other value will work fine. -* Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize() -* -* At any moment, it's possible to flush whatever data might remain stuck within internal buffer, -* using ZSTD_flushStream(). `output->pos` will be updated. -* Note that, if `output->size` is too small, a single invocation of ZSTD_flushStream() might not be enough (return code > 0). -* In which case, make some room to receive more compressed data, and call again ZSTD_flushStream(). -* @return : 0 if internal buffers are entirely flushed, -* >0 if some data still present within internal buffer (the value is minimal estimation of remaining size), -* or an error code, which can be tested using ZSTD_isError(). -* -* ZSTD_endStream() instructs to finish a frame. -* It will perform a flush and write frame epilogue. -* The epilogue is required for decoders to consider a frame completed. -* flush() operation is the same, and follows same rules as ZSTD_flushStream(). -* @return : 0 if frame fully completed and fully flushed, -* >0 if some data still present within internal buffer (the value is minimal estimation of remaining size), -* or an error code, which can be tested using ZSTD_isError(). -* -* *******************************************************************/ - -typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same object (>= v1.3.0) */ - /* Continue to distinguish them for compatibility with older versions <= v1.2.0 */ -/*===== ZSTD_CStream management functions =====*/ -ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); -ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); - -/*===== Streaming compression functions =====*/ -ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); -ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); -ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); -ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); - -ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */ -ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */ - - - -/*-*************************************************************************** -* Streaming decompression - HowTo -* -* A ZSTD_DStream object is required to track streaming operations. -* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources. -* ZSTD_DStream objects can be re-used multiple times. -* -* Use ZSTD_initDStream() to start a new decompression operation, -* or ZSTD_initDStream_usingDict() if decompression requires a dictionary. -* @return : recommended first input size -* -* Use ZSTD_decompressStream() repetitively to consume your input. -* The function will update both `pos` fields. -* If `input.pos < input.size`, some input has not been consumed. -* It's up to the caller to present again remaining data. -* If `output.pos < output.size`, decoder has flushed everything it could. -* @return : 0 when a frame is completely decoded and fully flushed, -* an error code, which can be tested using ZSTD_isError(), -* any other value > 0, which means there is still some decoding to do to complete current frame. -* The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame. -* *******************************************************************************/ - -typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */ - /* For compatibility with versions <= v1.2.0, continue to consider them separated. */ -/*===== ZSTD_DStream management functions =====*/ -ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); -ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); - -/*===== Streaming decompression functions =====*/ -ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); -ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); - -ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ -ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ - -#endif /* ZSTD_H_235446 */ - - - - -#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) -#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY - -/**************************************************************************************** - * ADVANCED AND EXPERIMENTAL FUNCTIONS - **************************************************************************************** - * The definitions in this section are considered experimental. - * They should never be used with a dynamic library, as prototypes may change in the future. - * They are provided for advanced scenarios. - * Use them only in association with static linking. - * ***************************************************************************************/ - -ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */ - -/* --- Constants ---*/ -#define ZSTD_MAGICNUMBER 0xFD2FB528 /* v0.8+ */ -#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* v0.7+ */ -#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U - -#define ZSTD_BLOCKSIZELOG_MAX 17 -#define ZSTD_BLOCKSIZE_MAX (1<= first frame size - * @return : the compressed size of the first frame starting at `src`, - * suitable to pass to `ZSTD_decompress` or similar, - * or an error code if input is invalid */ -ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize); - -/*! ZSTD_findDecompressedSize() : - * `src` should point the start of a series of ZSTD encoded and/or skippable frames - * `srcSize` must be the _exact_ size of this series - * (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`) - * @return : - decompressed size of all data in all successive frames - * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN - * - if an error occurred: ZSTD_CONTENTSIZE_ERROR - * - * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. - * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. - * In which case, it's necessary to use streaming mode to decompress data. - * note 2 : decompressed size is always present when compression is done with ZSTD_compress() - * note 3 : decompressed size can be very large (64-bits value), - * potentially larger than what local system can handle as a single memory segment. - * In which case, it's necessary to use streaming mode to decompress data. - * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. - * Always ensure result fits within application's authorized limits. - * Each application can set its own limits. - * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to - * read each contained frame header. This is fast as most of the data is skipped, - * however it does mean that all frame data must be present and valid. */ -ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize); - -/*! ZSTD_frameHeaderSize() : - * srcSize must be >= ZSTD_frameHeaderSize_prefix. - * @return : size of the Frame Header, - * or an error code (if srcSize is too small) */ -ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize); - - -/*************************************** -* Memory management -***************************************/ - -/*! ZSTD_sizeof_*() : - * These functions give the current memory usage of selected object. - * Object memory usage can evolve when re-used. */ -ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); -ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); -ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); -ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); -ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); -ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); - -/*! ZSTD_estimate*() : - * These functions make it possible to estimate memory usage - * of a future {D,C}Ctx, before its creation. - * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. - * It will also consider src size to be arbitrarily "large", which is worst case. - * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation. - * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. - * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1. - * Note : CCtx size estimation is only correct for single-threaded compression. */ -ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel); -ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams); -ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params); -ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void); - -/*! ZSTD_estimateCStreamSize() : - * ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one. - * It will also consider src size to be arbitrarily "large", which is worst case. - * If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation. - * ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. - * ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbWorkers is >= 1. - * Note : CStream size estimation is only correct for single-threaded compression. - * ZSTD_DStream memory budget depends on window Size. - * This information can be passed manually, using ZSTD_estimateDStreamSize, - * or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame(); - * Note : if streaming is init with function ZSTD_init?Stream_usingDict(), - * an internal ?Dict will be created, which additional size is not estimated here. - * In this case, get total size by adding ZSTD_estimate?DictSize */ -ZSTDLIB_API size_t ZSTD_estimateCStreamSize(int compressionLevel); -ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams); -ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params); -ZSTDLIB_API size_t ZSTD_estimateDStreamSize(size_t windowSize); -ZSTDLIB_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize); - -/*! ZSTD_estimate?DictSize() : - * ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict(). - * ZSTD_estimateCDictSize_advanced() makes it possible to control compression parameters precisely, like ZSTD_createCDict_advanced(). - * Note : dictionaries created by reference (`ZSTD_dlm_byRef`) are logically smaller. - */ -ZSTDLIB_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel); -ZSTDLIB_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod); -ZSTDLIB_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod); - -/*! ZSTD_initStatic*() : - * Initialize an object using a pre-allocated fixed-size buffer. - * workspace: The memory area to emplace the object into. - * Provided pointer *must be 8-bytes aligned*. - * Buffer must outlive object. - * workspaceSize: Use ZSTD_estimate*Size() to determine - * how large workspace must be to support target scenario. - * @return : pointer to object (same address as workspace, just different type), - * or NULL if error (size too small, incorrect alignment, etc.) - * Note : zstd will never resize nor malloc() when using a static buffer. - * If the object requires more memory than available, - * zstd will just error out (typically ZSTD_error_memory_allocation). - * Note 2 : there is no corresponding "free" function. - * Since workspace is allocated externally, it must be freed externally too. - * Note 3 : cParams : use ZSTD_getCParams() to convert a compression level - * into its associated cParams. - * Limitation 1 : currently not compatible with internal dictionary creation, triggered by - * ZSTD_CCtx_loadDictionary(), ZSTD_initCStream_usingDict() or ZSTD_initDStream_usingDict(). - * Limitation 2 : static cctx currently not compatible with multi-threading. - * Limitation 3 : static dctx is incompatible with legacy support. - */ -ZSTDLIB_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize); -ZSTDLIB_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticCCtx() */ - -ZSTDLIB_API ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize); -ZSTDLIB_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticDCtx() */ - -ZSTDLIB_API const ZSTD_CDict* ZSTD_initStaticCDict( - void* workspace, size_t workspaceSize, - const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_compressionParameters cParams); - -ZSTDLIB_API const ZSTD_DDict* ZSTD_initStaticDDict( - void* workspace, size_t workspaceSize, - const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType); - -/*! Custom memory allocation : - * These prototypes make it possible to pass your own allocation/free functions. - * ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below. - * All allocation/free operations will be completed using these custom variants instead of regular ones. - */ -typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size); -typedef void (*ZSTD_freeFunction) (void* opaque, void* address); -typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem; -static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */ - -ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); -ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); -ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem); -ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem); - -ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_compressionParameters cParams, - ZSTD_customMem customMem); - -ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_customMem customMem); - - - -/*************************************** -* Advanced compression functions -***************************************/ - -/*! ZSTD_createCDict_byReference() : - * Create a digested dictionary for compression - * Dictionary content is simply referenced, and therefore stays in dictBuffer. - * It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */ -ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel); - -/*! ZSTD_getCParams() : -* @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. -* `estimatedSrcSize` value is optional, select 0 if not known */ -ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); - -/*! ZSTD_getParams() : -* same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. -* All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0 */ -ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); - -/*! ZSTD_checkCParams() : -* Ensure param values remain within authorized range */ -ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); - -/*! ZSTD_adjustCParams() : - * optimize params for a given `srcSize` and `dictSize`. - * both values are optional, select `0` if unknown. */ -ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize); - -/*! ZSTD_compress_advanced() : -* Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter */ -ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const void* dict,size_t dictSize, - ZSTD_parameters params); - -/*! ZSTD_compress_usingCDict_advanced() : -* Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ -ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const ZSTD_CDict* cdict, ZSTD_frameParameters fParams); - - -/*--- Advanced decompression functions ---*/ - -/*! ZSTD_isFrame() : - * Tells if the content of `buffer` starts with a valid Frame Identifier. - * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. - * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. - * Note 3 : Skippable Frame Identifiers are considered valid. */ -ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size); - -/*! ZSTD_createDDict_byReference() : - * Create a digested dictionary, ready to start decompression operation without startup delay. - * Dictionary content is referenced, and therefore stays in dictBuffer. - * It is important that dictBuffer outlives DDict, - * it must remain read accessible throughout the lifetime of DDict */ -ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize); - - -/*! ZSTD_getDictID_fromDict() : - * Provides the dictID stored within dictionary. - * if @return == 0, the dictionary is not conformant with Zstandard specification. - * It can still be loaded, but as a content-only dictionary. */ -ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize); - -/*! ZSTD_getDictID_fromDDict() : - * Provides the dictID of the dictionary loaded into `ddict`. - * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. - * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ -ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict); - -/*! ZSTD_getDictID_fromFrame() : - * Provides the dictID required to decompressed the frame stored within `src`. - * If @return == 0, the dictID could not be decoded. - * This could for one of the following reasons : - * - The frame does not require a dictionary to be decoded (most common case). - * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. - * Note : this use case also happens when using a non-conformant dictionary. - * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). - * - This is not a Zstandard frame. - * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */ -ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize); - - -/******************************************************************** -* Advanced streaming functions -********************************************************************/ - -/*===== Advanced Streaming compression functions =====*/ -ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct. If it is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, "0" also disables frame content size field. It may be enabled in the future. */ -ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/ -ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, - ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */ -ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); /**< note : cdict will just be referenced, and must outlive compression session */ -ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize); /**< same as ZSTD_initCStream_usingCDict(), with control over frame parameters. pledgedSrcSize must be correct. If srcSize is not known at init time, use value ZSTD_CONTENTSIZE_UNKNOWN. */ - -/*! ZSTD_resetCStream() : - * start a new compression job, using same parameters from previous job. - * This is typically useful to skip dictionary loading stage, since it will re-use it in-place. - * Note that zcs must be init at least once before using ZSTD_resetCStream(). - * If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN. - * If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. - * For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs, - * but it will change to mean "empty" in future version, so use macro ZSTD_CONTENTSIZE_UNKNOWN instead. - * @return : 0, or an error code (which can be tested using ZSTD_isError()) - */ -ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); - - -typedef struct { - unsigned long long ingested; /* nb input bytes read and buffered */ - unsigned long long consumed; /* nb input bytes actually compressed */ - unsigned long long produced; /* nb of compressed bytes generated and buffered */ - unsigned long long flushed; /* nb of compressed bytes flushed : not provided; can be tracked from caller side */ - unsigned currentJobID; /* MT only : latest started job nb */ - unsigned nbActiveWorkers; /* MT only : nb of workers actively compressing at probe time */ -} ZSTD_frameProgression; - -/* ZSTD_getFrameProgression() : - * tells how much data has been ingested (read from input) - * consumed (input actually compressed) and produced (output) for current frame. - * Note : (ingested - consumed) is amount of input data buffered internally, not yet compressed. - * Aggregates progression inside active worker threads. - */ -ZSTDLIB_API ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx); - -/*! ZSTD_toFlushNow() : - * Tell how many bytes are ready to be flushed immediately. - * Useful for multithreading scenarios (nbWorkers >= 1). - * Probe the oldest active job, defined as oldest job not yet entirely flushed, - * and check its output buffer. - * @return : amount of data stored in oldest job and ready to be flushed immediately. - * if @return == 0, it means either : - * + there is no active job (could be checked with ZSTD_frameProgression()), or - * + oldest job is still actively compressing data, - * but everything it has produced has also been flushed so far, - * therefore flushing speed is currently limited by production speed of oldest job - * irrespective of the speed of concurrent newer jobs. - */ -ZSTDLIB_API size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx); - - - -/*===== Advanced Streaming decompression functions =====*/ -typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e; -ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); /* obsolete : this API will be removed in a future version */ -ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */ -ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */ -ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */ - - -/********************************************************************* -* Buffer-less and synchronous inner streaming functions -* -* This is an advanced API, giving full control over buffer management, for users which need direct control over memory. -* But it's also a complex one, with several restrictions, documented below. -* Prefer normal streaming API for an easier experience. -********************************************************************* */ - -/** - Buffer-less streaming compression (synchronous mode) - - A ZSTD_CCtx object is required to track streaming operations. - Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource. - ZSTD_CCtx object can be re-used multiple times within successive compression operations. - - Start by initializing a context. - Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression, - or ZSTD_compressBegin_advanced(), for finer parameter control. - It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx() - - Then, consume your input using ZSTD_compressContinue(). - There are some important considerations to keep in mind when using this advanced function : - - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only. - - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks. - - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario. - Worst case evaluation is provided by ZSTD_compressBound(). - ZSTD_compressContinue() doesn't guarantee recover after a failed compression. - - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog). - It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks) - - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps. - In which case, it will "discard" the relevant memory section from its history. - - Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum. - It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame. - Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders. - - `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again. -*/ - -/*===== Buffer-less streaming compression functions =====*/ -ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel); -ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel); -ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */ -ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */ -ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */ -ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */ - -ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); -ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); - - -/*- - Buffer-less streaming decompression (synchronous mode) - - A ZSTD_DCtx object is required to track streaming operations. - Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. - A ZSTD_DCtx object can be re-used multiple times. - - First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader(). - Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough. - Data fragment must be large enough to ensure successful decoding. - `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough. - @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled. - >0 : `srcSize` is too small, please provide at least @result bytes on next attempt. - errorCode, which can be tested using ZSTD_isError(). - - It fills a ZSTD_frameHeader structure with important information to correctly decode the frame, - such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`). - Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information. - As a consequence, check that values remain within valid application range. - For example, do not allocate memory blindly, check that `windowSize` is within expectation. - Each application can set its own limits, depending on local restrictions. - For extended interoperability, it is recommended to support `windowSize` of at least 8 MB. - - ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes. - ZSTD_decompressContinue() is very sensitive to contiguity, - if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place, - or that previous contiguous segment is large enough to properly handle maximum back-reference distance. - There are multiple ways to guarantee this condition. - - The most memory efficient way is to use a round buffer of sufficient size. - Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(), - which can @return an error code if required value is too large for current system (in 32-bits mode). - In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one, - up to the moment there is not enough room left in the buffer to guarantee decoding another full block, - which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`. - At which point, decoding can resume from the beginning of the buffer. - Note that already decoded data stored in the buffer should be flushed before being overwritten. - - There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory. - - Finally, if you control the compression process, you can also ignore all buffer size rules, - as long as the encoder and decoder progress in "lock-step", - aka use exactly the same buffer sizes, break contiguity at the same place, etc. - - Once buffers are setup, start decompression, with ZSTD_decompressBegin(). - If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict(). - - Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively. - ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue(). - ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail. - - @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity). - It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item. - It can also be an error code, which can be tested with ZSTD_isError(). - - A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero. - Context can then be reset to start a new decompression. - - Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType(). - This information is not required to properly decode a frame. - - == Special case : skippable frames == - - Skippable frames allow integration of user-defined data into a flow of concatenated frames. - Skippable frames will be ignored (skipped) by decompressor. - The format of skippable frames is as follows : - a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F - b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits - c) Frame Content - any content (User Data) of length equal to Frame Size - For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame. - For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content. -*/ - -/*===== Buffer-less streaming decompression functions =====*/ -typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e; -typedef struct { - unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */ - unsigned long long windowSize; /* can be very large, up to <= frameContentSize */ - unsigned blockSizeMax; - ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */ - unsigned headerSize; - unsigned dictID; - unsigned checksumFlag; -} ZSTD_frameHeader; -/** ZSTD_getFrameHeader() : - * decode Frame Header, or requires larger `srcSize`. - * @return : 0, `zfhPtr` is correctly filled, - * >0, `srcSize` is too small, value is wanted `srcSize` amount, - * or an error code, which can be tested using ZSTD_isError() */ -ZSTDLIB_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */ -ZSTDLIB_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */ - -ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); -ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); -ZSTDLIB_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); - -ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); -ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); - -/* misc */ -ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx); -typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e; -ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); - - - -/* ============================================ */ -/** New advanced API (experimental) */ -/* ============================================ */ - -/* API design : - * In this advanced API, parameters are pushed one by one into an existing context, - * using ZSTD_CCtx_set*() functions. - * Pushed parameters are sticky : they are applied to next job, and any subsequent job. - * It's possible to reset parameters to "default" using ZSTD_CCtx_reset(). - * Important : "sticky" parameters only work with `ZSTD_compress_generic()` ! - * For any other entry point, "sticky" parameters are ignored ! - * - * This API is intended to replace all others advanced / experimental API entry points. - */ - -/* note on enum design : - * All enum will be pinned to explicit values before reaching "stable API" status */ - -typedef enum { - /* Opened question : should we have a format ZSTD_f_auto ? - * Today, it would mean exactly the same as ZSTD_f_zstd1. - * But, in the future, should several formats become supported, - * on the compression side, it would mean "default format". - * On the decompression side, it would mean "automatic format detection", - * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames". - * Since meaning is a little different, another option could be to define different enums for compression and decompression. - * This question could be kept for later, when there are actually multiple formats to support, - * but there is also the question of pinning enum values, and pinning value `0` is especially important */ - ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */ - ZSTD_f_zstd1_magicless, /* Variant of zstd frame format, without initial 4-bytes magic number. - * Useful to save 4 bytes per generated frame. - * Decoder cannot recognise automatically this format, requiring instructions. */ -} ZSTD_format_e; - -typedef enum { - /* compression format */ - ZSTD_p_format = 10, /* See ZSTD_format_e enum definition. - * Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */ - - /* compression parameters */ - ZSTD_p_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table - * Default level is ZSTD_CLEVEL_DEFAULT==3. - * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT. - * Note 1 : it's possible to pass a negative compression level by casting it to unsigned type. - * Note 2 : setting a level sets all default values of other compression parameters. - * Note 3 : setting compressionLevel automatically updates ZSTD_p_compressLiterals. */ - ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2. - * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX. - * Special: value 0 means "use default windowLog". - * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27) - * requires explicitly allowing such window size during decompression stage. */ - ZSTD_p_hashLog, /* Size of the initial probe table, as a power of 2. - * Resulting table size is (1 << (hashLog+2)). - * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX. - * Larger tables improve compression ratio of strategies <= dFast, - * and improve speed of strategies > dFast. - * Special: value 0 means "use default hashLog". */ - ZSTD_p_chainLog, /* Size of the multi-probe search table, as a power of 2. - * Resulting table size is (1 << (chainLog+2)). - * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX. - * Larger tables result in better and slower compression. - * This parameter is useless when using "fast" strategy. - * Note it's still useful when using "dfast" strategy, - * in which case it defines a secondary probe table. - * Special: value 0 means "use default chainLog". */ - ZSTD_p_searchLog, /* Number of search attempts, as a power of 2. - * More attempts result in better and slower compression. - * This parameter is useless when using "fast" and "dFast" strategies. - * Special: value 0 means "use default searchLog". */ - ZSTD_p_minMatch, /* Minimum size of searched matches (note : repCode matches can be smaller). - * Larger values make faster compression and decompression, but decrease ratio. - * Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX. - * Note that currently, for all strategies < btopt, effective minimum is 4. - * , for all strategies > fast, effective maximum is 6. - * Special: value 0 means "use default minMatchLength". */ - ZSTD_p_targetLength, /* Impact of this field depends on strategy. - * For strategies btopt & btultra: - * Length of Match considered "good enough" to stop search. - * Larger values make compression stronger, and slower. - * For strategy fast: - * Distance between match sampling. - * Larger values make compression faster, and weaker. - * Special: value 0 means "use default targetLength". */ - ZSTD_p_compressionStrategy, /* See ZSTD_strategy enum definition. - * Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility. - * The higher the value of selected strategy, the more complex it is, - * resulting in stronger and slower compression. - * Special: value 0 means "use default strategy". */ - - ZSTD_p_enableLongDistanceMatching=160, /* Enable long distance matching. - * This parameter is designed to improve compression ratio - * for large inputs, by finding large matches at long distance. - * It increases memory usage and window size. - * Note: enabling this parameter increases ZSTD_p_windowLog to 128 MB - * except when expressly set to a different value. */ - ZSTD_p_ldmHashLog, /* Size of the table for long distance matching, as a power of 2. - * Larger values increase memory usage and compression ratio, - * but decrease compression speed. - * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX - * default: windowlog - 7. - * Special: value 0 means "automatically determine hashlog". */ - ZSTD_p_ldmMinMatch, /* Minimum match size for long distance matcher. - * Larger/too small values usually decrease compression ratio. - * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX. - * Special: value 0 means "use default value" (default: 64). */ - ZSTD_p_ldmBucketSizeLog, /* Log size of each bucket in the LDM hash table for collision resolution. - * Larger values improve collision resolution but decrease compression speed. - * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX . - * Special: value 0 means "use default value" (default: 3). */ - ZSTD_p_ldmHashEveryLog, /* Frequency of inserting/looking up entries in the LDM hash table. - * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN). - * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage. - * Larger values improve compression speed. - * Deviating far from default value will likely result in a compression ratio decrease. - * Special: value 0 means "automatically determine hashEveryLog". */ - - /* frame parameters */ - ZSTD_p_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1) - * Content size must be known at the beginning of compression, - * it is provided using ZSTD_CCtx_setPledgedSrcSize() */ - ZSTD_p_checksumFlag, /* A 32-bits checksum of content is written at end of frame (default:0) */ - ZSTD_p_dictIDFlag, /* When applicable, dictionary's ID is written into frame header (default:1) */ - - /* multi-threading parameters */ - /* These parameters are only useful if multi-threading is enabled (ZSTD_MULTITHREAD). - * They return an error otherwise. */ - ZSTD_p_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel. - * When nbWorkers >= 1, triggers asynchronous mode : - * ZSTD_compress_generic() consumes some input, flush some output if possible, and immediately gives back control to caller, - * while compression work is performed in parallel, within worker threads. - * (note : a strong exception to this rule is when first invocation sets ZSTD_e_end : it becomes a blocking call). - * More workers improve speed, but also increase memory usage. - * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */ - ZSTD_p_jobSize, /* Size of a compression job. This value is enforced only in non-blocking mode. - * Each compression job is completed in parallel, so this value indirectly controls the nb of active threads. - * 0 means default, which is dynamically determined based on compression parameters. - * Job size must be a minimum of overlapSize, or 1 MB, whichever is largest. - * The minimum size is automatically and transparently enforced */ - ZSTD_p_overlapSizeLog, /* Size of previous input reloaded at the beginning of each job. - * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */ - - /* =================================================================== */ - /* experimental parameters - no stability guaranteed */ - /* =================================================================== */ - - ZSTD_p_forceMaxWindow=1100, /* Force back-reference distances to remain < windowSize, - * even when referencing into Dictionary content (default:0) */ - ZSTD_p_forceAttachDict, /* ZSTD supports usage of a CDict in-place - * (avoiding having to copy the compression tables - * from the CDict into the working context). Using - * a CDict in this way saves an initial setup step, - * but comes at the cost of more work per byte of - * input. ZSTD has a simple internal heuristic that - * guesses which strategy will be faster. You can - * use this flag to override that guess. - * - * Note that the by-reference, in-place strategy is - * only used when reusing a compression context - * with compatible compression parameters. (If - * incompatible / uninitialized, the working - * context needs to be cleared anyways, which is - * about as expensive as overwriting it with the - * dictionary context, so there's no savings in - * using the CDict by-ref.) - * - * Values greater than 0 force attaching the dict. - * Values less than 0 force copying the dict. - * 0 selects the default heuristic-guided behavior. - */ - -} ZSTD_cParameter; - - -/*! ZSTD_CCtx_setParameter() : - * Set one compression parameter, selected by enum ZSTD_cParameter. - * Setting a parameter is generally only possible during frame initialization (before starting compression). - * Exception : when using multi-threading mode (nbThreads >= 1), - * following parameters can be updated _during_ compression (within same frame): - * => compressionLevel, hashLog, chainLog, searchLog, minMatch, targetLength and strategy. - * new parameters will be active on next job, or after a flush(). - * Note : when `value` type is not unsigned (int, or enum), cast it to unsigned for proper type checking. - * @result : informational value (typically, value being set, correctly clamped), - * or an error code (which can be tested with ZSTD_isError()). */ -ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value); - -/*! ZSTD_CCtx_getParameter() : - * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned* value); - -/*! ZSTD_CCtx_setPledgedSrcSize() : - * Total input data size to be compressed as a single frame. - * This value will be controlled at the end, and result in error if not respected. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Note 1 : 0 means zero, empty. - * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN. - * ZSTD_CONTENTSIZE_UNKNOWN is default value for any new compression job. - * Note 2 : If all data is provided and consumed in a single round, - * this value is overriden by srcSize instead. */ -ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize); - -/*! ZSTD_CCtx_loadDictionary() : - * Create an internal CDict from `dict` buffer. - * Decompression will have to use same dictionary. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Special: Adding a NULL (or 0-size) dictionary invalidates previous dictionary, - * meaning "return to no-dictionary mode". - * Note 1 : Dictionary will be used for all future compression jobs. - * To return to "no-dictionary" situation, load a NULL dictionary - * Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters. - * For this reason, compression parameters cannot be changed anymore after loading a dictionary. - * It's also a CPU consuming operation, with non-negligible impact on latency. - * Note 3 :`dict` content will be copied internally. - * Use ZSTD_CCtx_loadDictionary_byReference() to reference dictionary content instead. - * In such a case, dictionary buffer must outlive its users. - * Note 4 : Use ZSTD_CCtx_loadDictionary_advanced() - * to precisely select how dictionary content must be interpreted. */ -ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); -ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); -ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType); - - -/*! ZSTD_CCtx_refCDict() : - * Reference a prepared dictionary, to be used for all next compression jobs. - * Note that compression parameters are enforced from within CDict, - * and supercede any compression parameter previously set within CCtx. - * The dictionary will remain valid for future compression jobs using same CCtx. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Special : adding a NULL CDict means "return to no-dictionary mode". - * Note 1 : Currently, only one dictionary can be managed. - * Adding a new dictionary effectively "discards" any previous one. - * Note 2 : CDict is just referenced, its lifetime must outlive CCtx. */ -ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); - -/*! ZSTD_CCtx_refPrefix() : - * Reference a prefix (single-usage dictionary) for next compression job. - * Decompression will need same prefix to properly regenerate data. - * Compressing with a prefix is similar in outcome as performing a diff and compressing it, - * but performs much faster, especially during decompression (compression speed is tunable with compression level). - * Note that prefix is **only used once**. Tables are discarded at end of compression job (ZSTD_e_end). - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Special: Adding any prefix (including NULL) invalidates any previous prefix or dictionary - * Note 1 : Prefix buffer is referenced. It **must** outlive compression job. - * Its contain must remain unmodified up to end of compression (ZSTD_e_end). - * Note 2 : If the intention is to diff some large src data blob with some prior version of itself, - * ensure that the window size is large enough to contain the entire source. - * See ZSTD_p_windowLog. - * Note 3 : Referencing a prefix involves building tables, which are dependent on compression parameters. - * It's a CPU consuming operation, with non-negligible impact on latency. - * If there is a need to use same prefix multiple times, consider loadDictionary instead. - * Note 4 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent). - * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode. */ -ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, - const void* prefix, size_t prefixSize); -ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, - const void* prefix, size_t prefixSize, - ZSTD_dictContentType_e dictContentType); - -/*! ZSTD_CCtx_reset() : - * Return a CCtx to clean state. - * Useful after an error, or to interrupt an ongoing compression job and start a new one. - * Any internal data not yet flushed is cancelled. - * The parameters and dictionary are kept unchanged, to reset them use ZSTD_CCtx_resetParameters(). - */ -ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); - -/*! ZSTD_CCtx_resetParameters() : - * All parameters are back to default values (compression level is ZSTD_CLEVEL_DEFAULT). - * Dictionary (if any) is dropped. - * Resetting parameters is only possible during frame initialization (before starting compression). - * To reset the context use ZSTD_CCtx_reset(). - * @return 0 or an error code (which can be checked with ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_CCtx_resetParameters(ZSTD_CCtx* cctx); - - - -typedef enum { - ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal conditions */ - ZSTD_e_flush, /* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */ - ZSTD_e_end /* flush any remaining data and close current frame. Any additional data starts a new frame. */ -} ZSTD_EndDirective; - -/*! ZSTD_compress_generic() : - * Behave about the same as ZSTD_compressStream. To note : - * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter() - * - Compression parameters cannot be changed once compression is started. - * - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize - * - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit. - * - In single-thread mode (default), function is blocking : it completed its job before returning to caller. - * - In multi-thread mode, function is non-blocking : it just acquires a copy of input, and distribute job to internal worker threads, - * and then immediately returns, just indicating that there is some data remaining to be flushed. - * The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte. - * - Exception : in multi-threading mode, if the first call requests a ZSTD_e_end directive, it is blocking : it will complete compression before giving back control to caller. - * - @return provides a minimum amount of data remaining to be flushed from internal buffers - * or an error code, which can be tested using ZSTD_isError(). - * if @return != 0, flush is not fully completed, there is still some data left within internal buffers. - * This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers. - * For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed. - * - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0), - * only ZSTD_e_end or ZSTD_e_flush operations are allowed. - * Before starting a new compression job, or changing compression parameters, - * it is required to fully flush internal buffers. - */ -ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, - ZSTD_outBuffer* output, - ZSTD_inBuffer* input, - ZSTD_EndDirective endOp); - - -/*! ZSTD_compress_generic_simpleArgs() : - * Same as ZSTD_compress_generic(), - * but using only integral types as arguments. - * Argument list is larger than ZSTD_{in,out}Buffer, - * but can be helpful for binders from dynamic languages - * which have troubles handling structures containing memory pointers. - */ -ZSTDLIB_API size_t ZSTD_compress_generic_simpleArgs ( - ZSTD_CCtx* cctx, - void* dst, size_t dstCapacity, size_t* dstPos, - const void* src, size_t srcSize, size_t* srcPos, - ZSTD_EndDirective endOp); - - -/*! ZSTD_CCtx_params : - * Quick howto : - * - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure - * - ZSTD_CCtxParam_setParameter() : Push parameters one by one into - * an existing ZSTD_CCtx_params structure. - * This is similar to - * ZSTD_CCtx_setParameter(). - * - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to - * an existing CCtx. - * These parameters will be applied to - * all subsequent compression jobs. - * - ZSTD_compress_generic() : Do compression using the CCtx. - * - ZSTD_freeCCtxParams() : Free the memory. - * - * This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams() - * for static allocation for single-threaded compression. - */ -ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); -ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); - - -/*! ZSTD_CCtxParams_reset() : - * Reset params to default values. - */ -ZSTDLIB_API size_t ZSTD_CCtxParams_reset(ZSTD_CCtx_params* params); - -/*! ZSTD_CCtxParams_init() : - * Initializes the compression parameters of cctxParams according to - * compression level. All other parameters are reset to their default values. - */ -ZSTDLIB_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compressionLevel); - -/*! ZSTD_CCtxParams_init_advanced() : - * Initializes the compression and frame parameters of cctxParams according to - * params. All other parameters are reset to their default values. - */ -ZSTDLIB_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params); - - -/*! ZSTD_CCtxParam_setParameter() : - * Similar to ZSTD_CCtx_setParameter. - * Set one compression parameter, selected by enum ZSTD_cParameter. - * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams(). - * Note : when `value` is an enum, cast it to unsigned for proper type checking. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value); - -/*! ZSTD_CCtxParam_getParameter() : - * Similar to ZSTD_CCtx_getParameter. - * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_CCtxParam_getParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned* value); - -/*! ZSTD_CCtx_setParametersUsingCCtxParams() : - * Apply a set of ZSTD_CCtx_params to the compression context. - * This can be done even after compression is started, - * if nbWorkers==0, this will have no impact until a new compression is started. - * if nbWorkers>=1, new parameters will be picked up at next job, - * with a few restrictions (windowLog, pledgedSrcSize, nbWorkers, jobSize, and overlapLog are not updated). - */ -ZSTDLIB_API size_t ZSTD_CCtx_setParametersUsingCCtxParams( - ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params); - - -/* ==================================== */ -/*=== Advanced decompression API ===*/ -/* ==================================== */ - -/* The following API works the same way as the advanced compression API : - * a context is created, parameters are pushed into it one by one, - * then the context can be used to decompress data using an interface similar to the straming API. - */ - -/*! ZSTD_DCtx_loadDictionary() : - * Create an internal DDict from dict buffer, - * to be used to decompress next frames. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, - * meaning "return to no-dictionary mode". - * Note 1 : `dict` content will be copied internally. - * Use ZSTD_DCtx_loadDictionary_byReference() - * to reference dictionary content instead. - * In which case, the dictionary buffer must outlive its users. - * Note 2 : Loading a dictionary involves building tables, - * which has a non-negligible impact on CPU usage and latency. - * Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select - * how dictionary content will be interpreted and loaded. - */ -ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); -ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); -ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType); - - -/*! ZSTD_DCtx_refDDict() : - * Reference a prepared dictionary, to be used to decompress next frames. - * The dictionary remains active for decompression of future frames using same DCtx. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Note 1 : Currently, only one dictionary can be managed. - * Referencing a new dictionary effectively "discards" any previous one. - * Special : adding a NULL DDict means "return to no-dictionary mode". - * Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx. - */ -ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); - - -/*! ZSTD_DCtx_refPrefix() : - * Reference a prefix (single-usage dictionary) for next compression job. - * This is the reverse operation of ZSTD_CCtx_refPrefix(), - * and must use the same prefix as the one used during compression. - * Prefix is **only used once**. Reference is discarded at end of frame. - * End of frame is reached when ZSTD_DCtx_decompress_generic() returns 0. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - * Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary - * Note 2 : Prefix buffer is referenced. It **must** outlive decompression job. - * Prefix buffer must remain unmodified up to the end of frame, - * reached when ZSTD_DCtx_decompress_generic() returns 0. - * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent). - * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode. - * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost. - * A fulldict prefix is more costly though. - */ -ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, - const void* prefix, size_t prefixSize); -ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, - const void* prefix, size_t prefixSize, - ZSTD_dictContentType_e dictContentType); - - -/*! ZSTD_DCtx_setMaxWindowSize() : - * Refuses allocating internal buffers for frames requiring a window size larger than provided limit. - * This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario). - * This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode. - * By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX) - * @return : 0, or an error code (which can be tested using ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize); - - -/*! ZSTD_DCtx_setFormat() : - * Instruct the decoder context about what kind of data to decode next. - * This instruction is mandatory to decode data without a fully-formed header, - * such ZSTD_f_zstd1_magicless for example. - * @return : 0, or an error code (which can be tested using ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format); - - -/*! ZSTD_getFrameHeader_advanced() : - * same as ZSTD_getFrameHeader(), - * with added capability to select a format (like ZSTD_f_zstd1_magicless) */ -ZSTDLIB_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, - const void* src, size_t srcSize, ZSTD_format_e format); - - -/*! ZSTD_decompress_generic() : - * Behave the same as ZSTD_decompressStream. - * Decompression parameters cannot be changed once decompression is started. - * @return : an error code, which can be tested using ZSTD_isError() - * if >0, a hint, nb of expected input bytes for next invocation. - * `0` means : a frame has just been fully decoded and flushed. - */ -ZSTDLIB_API size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx, - ZSTD_outBuffer* output, - ZSTD_inBuffer* input); - - -/*! ZSTD_decompress_generic_simpleArgs() : - * Same as ZSTD_decompress_generic(), - * but using only integral types as arguments. - * Argument list is larger than ZSTD_{in,out}Buffer, - * but can be helpful for binders from dynamic languages - * which have troubles handling structures containing memory pointers. - */ -ZSTDLIB_API size_t ZSTD_decompress_generic_simpleArgs ( - ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, size_t* dstPos, - const void* src, size_t srcSize, size_t* srcPos); - - -/*! ZSTD_DCtx_reset() : - * Return a DCtx to clean state. - * If a decompression was ongoing, any internal data not yet flushed is cancelled. - * All parameters are back to default values, including sticky ones. - * Dictionary (if any) is dropped. - * Parameters can be modified again after a reset. - */ -ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx); - - - -/* ============================ */ -/** Block level API */ -/* ============================ */ - -/*! - Block functions produce and decode raw zstd blocks, without frame metadata. - Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). - User will have to take in charge required information to regenerate data, such as compressed and content sizes. - - A few rules to respect : - - Compressing and decompressing require a context structure - + Use ZSTD_createCCtx() and ZSTD_createDCtx() - - It is necessary to init context before starting - + compression : any ZSTD_compressBegin*() variant, including with dictionary - + decompression : any ZSTD_decompressBegin*() variant, including with dictionary - + copyCCtx() and copyDCtx() can be used too - - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB - + If input is larger than a block size, it's necessary to split input data into multiple blocks - + For inputs larger than a single block size, consider using the regular ZSTD_compress() instead. - Frame metadata is not that costly, and quickly becomes negligible as source size grows larger. - - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero. - In which case, nothing is produced into `dst`. - + User must test for such outcome and deal directly with uncompressed data - + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!! - + In case of multiple successive blocks, should some of them be uncompressed, - decoder must be informed of their existence in order to follow proper history. - Use ZSTD_insertBlock() for such a case. -*/ - -/*===== Raw zstd block functions =====*/ -ZSTDLIB_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx); -ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); -ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); -ZSTDLIB_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */ - - -#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */ - -#if defined (__cplusplus) -} -#endif diff --git a/grub-core/lib/zstd/zstd_common.c b/grub-core/lib/zstd/zstd_common.c deleted file mode 100644 index 6f05d240e..000000000 --- a/grub-core/lib/zstd/zstd_common.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - - - -/*-************************************* -* Dependencies -***************************************/ -#include /* malloc, calloc, free */ -#include /* memset */ -#include "error_private.h" -#include "zstd_internal.h" - - -/*-**************************************** -* Version -******************************************/ -unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; } - -const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; } - - -/*-**************************************** -* ZSTD Error Management -******************************************/ -/*! ZSTD_isError() : - * tells if a return value is an error code */ -unsigned ZSTD_isError(size_t code) { return ERR_isError(code); } - -/*! ZSTD_getErrorName() : - * provides error code string from function result (useful for debugging) */ -const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); } - -/*! ZSTD_getError() : - * convert a `size_t` function result into a proper ZSTD_errorCode enum */ -ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); } - -/*! ZSTD_getErrorString() : - * provides error code string from enum */ -const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); } - - - -/*=************************************************************** -* Custom allocator -****************************************************************/ -void* ZSTD_malloc(size_t size, ZSTD_customMem customMem) -{ - if (customMem.customAlloc) - return customMem.customAlloc(customMem.opaque, size); - return malloc(size); -} - -void* ZSTD_calloc(size_t size, ZSTD_customMem customMem) -{ - if (customMem.customAlloc) { - /* calloc implemented as malloc+memset; - * not as efficient as calloc, but next best guess for custom malloc */ - void* const ptr = customMem.customAlloc(customMem.opaque, size); - memset(ptr, 0, size); - return ptr; - } - return calloc(1, size); -} - -void ZSTD_free(void* ptr, ZSTD_customMem customMem) -{ - if (ptr!=NULL) { - if (customMem.customFree) - customMem.customFree(customMem.opaque, ptr); - else - free(ptr); - } -} diff --git a/grub-core/lib/zstd/zstd_decompress.c b/grub-core/lib/zstd/zstd_decompress.c deleted file mode 100644 index 711b5b6d7..000000000 --- a/grub-core/lib/zstd/zstd_decompress.c +++ /dev/null @@ -1,3108 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - - -/* *************************************************************** -* Tuning parameters -*****************************************************************/ -/*! - * HEAPMODE : - * Select how default decompression function ZSTD_decompress() allocates its context, - * on stack (0), or into heap (1, default; requires malloc()). - * Note that functions with explicit context such as ZSTD_decompressDCtx() are unaffected. - */ -#ifndef ZSTD_HEAPMODE -# define ZSTD_HEAPMODE 1 -#endif - -/*! -* LEGACY_SUPPORT : -* if set to 1+, ZSTD_decompress() can decode older formats (v0.1+) -*/ -#ifndef ZSTD_LEGACY_SUPPORT -# define ZSTD_LEGACY_SUPPORT 0 -#endif - -/*! - * MAXWINDOWSIZE_DEFAULT : - * maximum window size accepted by DStream __by default__. - * Frames requiring more memory will be rejected. - * It's possible to set a different limit using ZSTD_DCtx_setMaxWindowSize(). - */ -#ifndef ZSTD_MAXWINDOWSIZE_DEFAULT -# define ZSTD_MAXWINDOWSIZE_DEFAULT (((U32)1 << ZSTD_WINDOWLOG_DEFAULTMAX) + 1) -#endif - -/*! - * NO_FORWARD_PROGRESS_MAX : - * maximum allowed nb of calls to ZSTD_decompressStream() and ZSTD_decompress_generic() - * without any forward progress - * (defined as: no byte read from input, and no byte flushed to output) - * before triggering an error. - */ -#ifndef ZSTD_NO_FORWARD_PROGRESS_MAX -# define ZSTD_NO_FORWARD_PROGRESS_MAX 16 -#endif - - -/*-******************************************************* -* Dependencies -*********************************************************/ -#include /* memcpy, memmove, memset */ -#include "compiler.h" /* prefetch */ -#include "cpu.h" /* bmi2 */ -#include "mem.h" /* low level memory routines */ -#define FSE_STATIC_LINKING_ONLY -#include "fse.h" -#define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "zstd_internal.h" - -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) -# include "zstd_legacy.h" -#endif - -static const void* ZSTD_DDictDictContent(const ZSTD_DDict* ddict); -static size_t ZSTD_DDictDictSize(const ZSTD_DDict* ddict); - - -/*-************************************* -* Errors -***************************************/ -#define ZSTD_isError ERR_isError /* for inlining */ -#define FSE_isError ERR_isError -#define HUF_isError ERR_isError - - -/*_******************************************************* -* Memory operations -**********************************************************/ -static void ZSTD_copy4(void* dst, const void* src) { memcpy(dst, src, 4); } - - -/*-************************************************************* -* Context management -***************************************************************/ -typedef enum { ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader, - ZSTDds_decodeBlockHeader, ZSTDds_decompressBlock, - ZSTDds_decompressLastBlock, ZSTDds_checkChecksum, - ZSTDds_decodeSkippableHeader, ZSTDds_skipFrame } ZSTD_dStage; - -typedef enum { zdss_init=0, zdss_loadHeader, - zdss_read, zdss_load, zdss_flush } ZSTD_dStreamStage; - - -typedef struct { - U32 fastMode; - U32 tableLog; -} ZSTD_seqSymbol_header; - -typedef struct { - U16 nextState; - BYTE nbAdditionalBits; - BYTE nbBits; - U32 baseValue; -} ZSTD_seqSymbol; - -#define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log))) - -typedef struct { - ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]; /* Note : Space reserved for FSE Tables */ - ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]; /* is also used as temporary workspace while building hufTable during DDict creation */ - ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]; /* and therefore must be at least HUF_DECOMPRESS_WORKSPACE_SIZE large */ - HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]; /* can accommodate HUF_decompress4X */ - U32 rep[ZSTD_REP_NUM]; -} ZSTD_entropyDTables_t; - -struct ZSTD_DCtx_s -{ - const ZSTD_seqSymbol* LLTptr; - const ZSTD_seqSymbol* MLTptr; - const ZSTD_seqSymbol* OFTptr; - const HUF_DTable* HUFptr; - ZSTD_entropyDTables_t entropy; - U32 workspace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; /* space needed when building huffman tables */ - const void* previousDstEnd; /* detect continuity */ - const void* prefixStart; /* start of current segment */ - const void* virtualStart; /* virtual start of previous segment if it was just before current one */ - const void* dictEnd; /* end of previous segment */ - size_t expected; - ZSTD_frameHeader fParams; - U64 decodedSize; - blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */ - ZSTD_dStage stage; - U32 litEntropy; - U32 fseEntropy; - XXH64_state_t xxhState; - size_t headerSize; - ZSTD_format_e format; - const BYTE* litPtr; - ZSTD_customMem customMem; - size_t litSize; - size_t rleSize; - size_t staticSize; - int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */ - - /* dictionary */ - ZSTD_DDict* ddictLocal; - const ZSTD_DDict* ddict; /* set by ZSTD_initDStream_usingDDict(), or ZSTD_DCtx_refDDict() */ - U32 dictID; - int ddictIsCold; /* if == 1 : dictionary is "new" for working context, and presumed "cold" (not in cpu cache) */ - - /* streaming */ - ZSTD_dStreamStage streamStage; - char* inBuff; - size_t inBuffSize; - size_t inPos; - size_t maxWindowSize; - char* outBuff; - size_t outBuffSize; - size_t outStart; - size_t outEnd; - size_t lhSize; - void* legacyContext; - U32 previousLegacyVersion; - U32 legacyVersion; - U32 hostageByte; - int noForwardProgress; - - /* workspace */ - BYTE litBuffer[ZSTD_BLOCKSIZE_MAX + WILDCOPY_OVERLENGTH]; - BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]; -}; /* typedef'd to ZSTD_DCtx within "zstd.h" */ - -size_t ZSTD_sizeof_DCtx (const ZSTD_DCtx* dctx) -{ - if (dctx==NULL) return 0; /* support sizeof NULL */ - return sizeof(*dctx) - + ZSTD_sizeof_DDict(dctx->ddictLocal) - + dctx->inBuffSize + dctx->outBuffSize; -} - -size_t ZSTD_estimateDCtxSize(void) { return sizeof(ZSTD_DCtx); } - - -static size_t ZSTD_startingInputLength(ZSTD_format_e format) -{ - size_t const startingInputLength = (format==ZSTD_f_zstd1_magicless) ? - ZSTD_frameHeaderSize_prefix - ZSTD_FRAMEIDSIZE : - ZSTD_frameHeaderSize_prefix; - ZSTD_STATIC_ASSERT(ZSTD_FRAMEHEADERSIZE_PREFIX >= ZSTD_FRAMEIDSIZE); - /* only supports formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless */ - assert( (format == ZSTD_f_zstd1) || (format == ZSTD_f_zstd1_magicless) ); - return startingInputLength; -} - -static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx) -{ - dctx->format = ZSTD_f_zstd1; /* ZSTD_decompressBegin() invokes ZSTD_startingInputLength() with argument dctx->format */ - dctx->staticSize = 0; - dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT; - dctx->ddict = NULL; - dctx->ddictLocal = NULL; - dctx->dictEnd = NULL; - dctx->ddictIsCold = 0; - dctx->inBuff = NULL; - dctx->inBuffSize = 0; - dctx->outBuffSize = 0; - dctx->streamStage = zdss_init; - dctx->legacyContext = NULL; - dctx->previousLegacyVersion = 0; - dctx->noForwardProgress = 0; - dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); -} - -ZSTD_DCtx* ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize) -{ - ZSTD_DCtx* const dctx = (ZSTD_DCtx*) workspace; - - if ((size_t)workspace & 7) return NULL; /* 8-aligned */ - if (workspaceSize < sizeof(ZSTD_DCtx)) return NULL; /* minimum size */ - - ZSTD_initDCtx_internal(dctx); - dctx->staticSize = workspaceSize; - dctx->inBuff = (char*)(dctx+1); - return dctx; -} - -ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem) -{ - if (!customMem.customAlloc ^ !customMem.customFree) return NULL; - - { ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(*dctx), customMem); - if (!dctx) return NULL; - dctx->customMem = customMem; - ZSTD_initDCtx_internal(dctx); - return dctx; - } -} - -ZSTD_DCtx* ZSTD_createDCtx(void) -{ - DEBUGLOG(3, "ZSTD_createDCtx"); - return ZSTD_createDCtx_advanced(ZSTD_defaultCMem); -} - -size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx) -{ - if (dctx==NULL) return 0; /* support free on NULL */ - if (dctx->staticSize) return ERROR(memory_allocation); /* not compatible with static DCtx */ - { ZSTD_customMem const cMem = dctx->customMem; - ZSTD_freeDDict(dctx->ddictLocal); - dctx->ddictLocal = NULL; - ZSTD_free(dctx->inBuff, cMem); - dctx->inBuff = NULL; -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) - if (dctx->legacyContext) - ZSTD_freeLegacyStreamContext(dctx->legacyContext, dctx->previousLegacyVersion); -#endif - ZSTD_free(dctx, cMem); - return 0; - } -} - -/* no longer useful */ -void ZSTD_copyDCtx(ZSTD_DCtx* dstDCtx, const ZSTD_DCtx* srcDCtx) -{ - size_t const toCopy = (size_t)((char*)(&dstDCtx->inBuff) - (char*)dstDCtx); - memcpy(dstDCtx, srcDCtx, toCopy); /* no need to copy workspace */ -} - - -/*-************************************************************* - * Frame header decoding - ***************************************************************/ - -/*! ZSTD_isFrame() : - * Tells if the content of `buffer` starts with a valid Frame Identifier. - * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. - * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. - * Note 3 : Skippable Frame Identifiers are considered valid. */ -unsigned ZSTD_isFrame(const void* buffer, size_t size) -{ - if (size < ZSTD_FRAMEIDSIZE) return 0; - { U32 const magic = MEM_readLE32(buffer); - if (magic == ZSTD_MAGICNUMBER) return 1; - if ((magic & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) return 1; - } -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) - if (ZSTD_isLegacy(buffer, size)) return 1; -#endif - return 0; -} - -/** ZSTD_frameHeaderSize_internal() : - * srcSize must be large enough to reach header size fields. - * note : only works for formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless. - * @return : size of the Frame Header - * or an error code, which can be tested with ZSTD_isError() */ -static size_t ZSTD_frameHeaderSize_internal(const void* src, size_t srcSize, ZSTD_format_e format) -{ - size_t const minInputSize = ZSTD_startingInputLength(format); - if (srcSize < minInputSize) return ERROR(srcSize_wrong); - - { BYTE const fhd = ((const BYTE*)src)[minInputSize-1]; - U32 const dictID= fhd & 3; - U32 const singleSegment = (fhd >> 5) & 1; - U32 const fcsId = fhd >> 6; - return minInputSize + !singleSegment - + ZSTD_did_fieldSize[dictID] + ZSTD_fcs_fieldSize[fcsId] - + (singleSegment && !fcsId); - } -} - -/** ZSTD_frameHeaderSize() : - * srcSize must be >= ZSTD_frameHeaderSize_prefix. - * @return : size of the Frame Header, - * or an error code (if srcSize is too small) */ -size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize) -{ - return ZSTD_frameHeaderSize_internal(src, srcSize, ZSTD_f_zstd1); -} - - -/** ZSTD_getFrameHeader_advanced() : - * decode Frame Header, or require larger `srcSize`. - * note : only works for formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless - * @return : 0, `zfhPtr` is correctly filled, - * >0, `srcSize` is too small, value is wanted `srcSize` amount, - * or an error code, which can be tested using ZSTD_isError() */ -size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format) -{ - const BYTE* ip = (const BYTE*)src; - size_t const minInputSize = ZSTD_startingInputLength(format); - - memset(zfhPtr, 0, sizeof(*zfhPtr)); /* not strictly necessary, but static analyzer do not understand that zfhPtr is only going to be read only if return value is zero, since they are 2 different signals */ - if (srcSize < minInputSize) return minInputSize; - if (src==NULL) return ERROR(GENERIC); /* invalid parameter */ - - if ( (format != ZSTD_f_zstd1_magicless) - && (MEM_readLE32(src) != ZSTD_MAGICNUMBER) ) { - if ((MEM_readLE32(src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { - /* skippable frame */ - if (srcSize < ZSTD_skippableHeaderSize) - return ZSTD_skippableHeaderSize; /* magic number + frame length */ - memset(zfhPtr, 0, sizeof(*zfhPtr)); - zfhPtr->frameContentSize = MEM_readLE32((const char *)src + ZSTD_FRAMEIDSIZE); - zfhPtr->frameType = ZSTD_skippableFrame; - return 0; - } - return ERROR(prefix_unknown); - } - - /* ensure there is enough `srcSize` to fully read/decode frame header */ - { size_t const fhsize = ZSTD_frameHeaderSize_internal(src, srcSize, format); - if (srcSize < fhsize) return fhsize; - zfhPtr->headerSize = (U32)fhsize; - } - - { BYTE const fhdByte = ip[minInputSize-1]; - size_t pos = minInputSize; - U32 const dictIDSizeCode = fhdByte&3; - U32 const checksumFlag = (fhdByte>>2)&1; - U32 const singleSegment = (fhdByte>>5)&1; - U32 const fcsID = fhdByte>>6; - U64 windowSize = 0; - U32 dictID = 0; - U64 frameContentSize = ZSTD_CONTENTSIZE_UNKNOWN; - if ((fhdByte & 0x08) != 0) - return ERROR(frameParameter_unsupported); /* reserved bits, must be zero */ - - if (!singleSegment) { - BYTE const wlByte = ip[pos++]; - U32 const windowLog = (wlByte >> 3) + ZSTD_WINDOWLOG_ABSOLUTEMIN; - if (windowLog > ZSTD_WINDOWLOG_MAX) - return ERROR(frameParameter_windowTooLarge); - windowSize = (1ULL << windowLog); - windowSize += (windowSize >> 3) * (wlByte&7); - } - switch(dictIDSizeCode) - { - default: assert(0); /* impossible */ - case 0 : break; - case 1 : dictID = ip[pos]; pos++; break; - case 2 : dictID = MEM_readLE16(ip+pos); pos+=2; break; - case 3 : dictID = MEM_readLE32(ip+pos); pos+=4; break; - } - switch(fcsID) - { - default: assert(0); /* impossible */ - case 0 : if (singleSegment) frameContentSize = ip[pos]; break; - case 1 : frameContentSize = MEM_readLE16(ip+pos)+256; break; - case 2 : frameContentSize = MEM_readLE32(ip+pos); break; - case 3 : frameContentSize = MEM_readLE64(ip+pos); break; - } - if (singleSegment) windowSize = frameContentSize; - - zfhPtr->frameType = ZSTD_frame; - zfhPtr->frameContentSize = frameContentSize; - zfhPtr->windowSize = windowSize; - zfhPtr->blockSizeMax = (unsigned) MIN(windowSize, ZSTD_BLOCKSIZE_MAX); - zfhPtr->dictID = dictID; - zfhPtr->checksumFlag = checksumFlag; - } - return 0; -} - -/** ZSTD_getFrameHeader() : - * decode Frame Header, or require larger `srcSize`. - * note : this function does not consume input, it only reads it. - * @return : 0, `zfhPtr` is correctly filled, - * >0, `srcSize` is too small, value is wanted `srcSize` amount, - * or an error code, which can be tested using ZSTD_isError() */ -size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize) -{ - return ZSTD_getFrameHeader_advanced(zfhPtr, src, srcSize, ZSTD_f_zstd1); -} - - -/** ZSTD_getFrameContentSize() : - * compatible with legacy mode - * @return : decompressed size of the single frame pointed to be `src` if known, otherwise - * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined - * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) */ -unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize) -{ -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) - if (ZSTD_isLegacy(src, srcSize)) { - unsigned long long const ret = ZSTD_getDecompressedSize_legacy(src, srcSize); - return ret == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : ret; - } -#endif - { ZSTD_frameHeader zfh; - if (ZSTD_getFrameHeader(&zfh, src, srcSize) != 0) - return ZSTD_CONTENTSIZE_ERROR; - if (zfh.frameType == ZSTD_skippableFrame) { - return 0; - } else { - return zfh.frameContentSize; - } } -} - -/** ZSTD_findDecompressedSize() : - * compatible with legacy mode - * `srcSize` must be the exact length of some number of ZSTD compressed and/or - * skippable frames - * @return : decompressed size of the frames contained */ -unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize) -{ - unsigned long long totalDstSize = 0; - - while (srcSize >= ZSTD_frameHeaderSize_prefix) { - U32 const magicNumber = MEM_readLE32(src); - - if ((magicNumber & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { - size_t skippableSize; - if (srcSize < ZSTD_skippableHeaderSize) - return ERROR(srcSize_wrong); - skippableSize = MEM_readLE32((const BYTE *)src + ZSTD_FRAMEIDSIZE) - + ZSTD_skippableHeaderSize; - if (srcSize < skippableSize) { - return ZSTD_CONTENTSIZE_ERROR; - } - - src = (const BYTE *)src + skippableSize; - srcSize -= skippableSize; - continue; - } - - { unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize); - if (ret >= ZSTD_CONTENTSIZE_ERROR) return ret; - - /* check for overflow */ - if (totalDstSize + ret < totalDstSize) return ZSTD_CONTENTSIZE_ERROR; - totalDstSize += ret; - } - { size_t const frameSrcSize = ZSTD_findFrameCompressedSize(src, srcSize); - if (ZSTD_isError(frameSrcSize)) { - return ZSTD_CONTENTSIZE_ERROR; - } - - src = (const BYTE *)src + frameSrcSize; - srcSize -= frameSrcSize; - } - } /* while (srcSize >= ZSTD_frameHeaderSize_prefix) */ - - if (srcSize) return ZSTD_CONTENTSIZE_ERROR; - - return totalDstSize; -} - -/** ZSTD_getDecompressedSize() : -* compatible with legacy mode -* @return : decompressed size if known, 0 otherwise - note : 0 can mean any of the following : - - frame content is empty - - decompressed size field is not present in frame header - - frame header unknown / not supported - - frame header not complete (`srcSize` too small) */ -unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize) -{ - unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize); - ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_ERROR < ZSTD_CONTENTSIZE_UNKNOWN); - return (ret >= ZSTD_CONTENTSIZE_ERROR) ? 0 : ret; -} - - -/** ZSTD_decodeFrameHeader() : -* `headerSize` must be the size provided by ZSTD_frameHeaderSize(). -* @return : 0 if success, or an error code, which can be tested using ZSTD_isError() */ -static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx* dctx, const void* src, size_t headerSize) -{ - size_t const result = ZSTD_getFrameHeader_advanced(&(dctx->fParams), src, headerSize, dctx->format); - if (ZSTD_isError(result)) return result; /* invalid header */ - if (result>0) return ERROR(srcSize_wrong); /* headerSize too small */ - if (dctx->fParams.dictID && (dctx->dictID != dctx->fParams.dictID)) - return ERROR(dictionary_wrong); - if (dctx->fParams.checksumFlag) XXH64_reset(&dctx->xxhState, 0); - return 0; -} - - -/*-************************************************************* - * Block decoding - ***************************************************************/ - -/*! ZSTD_getcBlockSize() : -* Provides the size of compressed block from block header `src` */ -size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, - blockProperties_t* bpPtr) -{ - if (srcSize < ZSTD_blockHeaderSize) return ERROR(srcSize_wrong); - { U32 const cBlockHeader = MEM_readLE24(src); - U32 const cSize = cBlockHeader >> 3; - bpPtr->lastBlock = cBlockHeader & 1; - bpPtr->blockType = (blockType_e)((cBlockHeader >> 1) & 3); - bpPtr->origSize = cSize; /* only useful for RLE */ - if (bpPtr->blockType == bt_rle) return 1; - if (bpPtr->blockType == bt_reserved) return ERROR(corruption_detected); - return cSize; - } -} - - -static size_t ZSTD_copyRawBlock(void* dst, size_t dstCapacity, - const void* src, size_t srcSize) -{ - if (dst==NULL) return ERROR(dstSize_tooSmall); - if (srcSize > dstCapacity) return ERROR(dstSize_tooSmall); - memcpy(dst, src, srcSize); - return srcSize; -} - - -static size_t ZSTD_setRleBlock(void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - size_t regenSize) -{ - if (srcSize != 1) return ERROR(srcSize_wrong); - if (regenSize > dstCapacity) return ERROR(dstSize_tooSmall); - memset(dst, *(const BYTE*)src, regenSize); - return regenSize; -} - -/* Hidden declaration for fullbench */ -size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, - const void* src, size_t srcSize); -/*! ZSTD_decodeLiteralsBlock() : - * @return : nb of bytes read from src (< srcSize ) - * note : symbol not declared but exposed for fullbench */ -size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, - const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ -{ - if (srcSize < MIN_CBLOCK_SIZE) return ERROR(corruption_detected); - - { const BYTE* const istart = (const BYTE*) src; - symbolEncodingType_e const litEncType = (symbolEncodingType_e)(istart[0] & 3); - - switch(litEncType) - { - case set_repeat: - if (dctx->litEntropy==0) return ERROR(dictionary_corrupted); - /* fall-through */ - - case set_compressed: - if (srcSize < 5) return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3 */ - { size_t lhSize, litSize, litCSize; - U32 singleStream=0; - U32 const lhlCode = (istart[0] >> 2) & 3; - U32 const lhc = MEM_readLE32(istart); - switch(lhlCode) - { - case 0: case 1: default: /* note : default is impossible, since lhlCode into [0..3] */ - /* 2 - 2 - 10 - 10 */ - singleStream = !lhlCode; - lhSize = 3; - litSize = (lhc >> 4) & 0x3FF; - litCSize = (lhc >> 14) & 0x3FF; - break; - case 2: - /* 2 - 2 - 14 - 14 */ - lhSize = 4; - litSize = (lhc >> 4) & 0x3FFF; - litCSize = lhc >> 18; - break; - case 3: - /* 2 - 2 - 18 - 18 */ - lhSize = 5; - litSize = (lhc >> 4) & 0x3FFFF; - litCSize = (lhc >> 22) + (istart[4] << 10); - break; - } - if (litSize > ZSTD_BLOCKSIZE_MAX) return ERROR(corruption_detected); - if (litCSize + lhSize > srcSize) return ERROR(corruption_detected); - - /* prefetch huffman table if cold */ - if (dctx->ddictIsCold && (litSize > 768 /* heuristic */)) { - PREFETCH_AREA(dctx->HUFptr, sizeof(dctx->entropy.hufTable)); - } - - if (HUF_isError((litEncType==set_repeat) ? - ( singleStream ? - HUF_decompress1X_usingDTable_bmi2(dctx->litBuffer, litSize, istart+lhSize, litCSize, dctx->HUFptr, dctx->bmi2) : - HUF_decompress4X_usingDTable_bmi2(dctx->litBuffer, litSize, istart+lhSize, litCSize, dctx->HUFptr, dctx->bmi2) ) : - ( singleStream ? - HUF_decompress1X1_DCtx_wksp_bmi2(dctx->entropy.hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize, - dctx->workspace, sizeof(dctx->workspace), dctx->bmi2) : - HUF_decompress4X_hufOnly_wksp_bmi2(dctx->entropy.hufTable, dctx->litBuffer, litSize, istart+lhSize, litCSize, - dctx->workspace, sizeof(dctx->workspace), dctx->bmi2)))) - return ERROR(corruption_detected); - - dctx->litPtr = dctx->litBuffer; - dctx->litSize = litSize; - dctx->litEntropy = 1; - if (litEncType==set_compressed) dctx->HUFptr = dctx->entropy.hufTable; - memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH); - return litCSize + lhSize; - } - - case set_basic: - { size_t litSize, lhSize; - U32 const lhlCode = ((istart[0]) >> 2) & 3; - switch(lhlCode) - { - case 0: case 2: default: /* note : default is impossible, since lhlCode into [0..3] */ - lhSize = 1; - litSize = istart[0] >> 3; - break; - case 1: - lhSize = 2; - litSize = MEM_readLE16(istart) >> 4; - break; - case 3: - lhSize = 3; - litSize = MEM_readLE24(istart) >> 4; - break; - } - - if (lhSize+litSize+WILDCOPY_OVERLENGTH > srcSize) { /* risk reading beyond src buffer with wildcopy */ - if (litSize+lhSize > srcSize) return ERROR(corruption_detected); - memcpy(dctx->litBuffer, istart+lhSize, litSize); - dctx->litPtr = dctx->litBuffer; - dctx->litSize = litSize; - memset(dctx->litBuffer + dctx->litSize, 0, WILDCOPY_OVERLENGTH); - return lhSize+litSize; - } - /* direct reference into compressed stream */ - dctx->litPtr = istart+lhSize; - dctx->litSize = litSize; - return lhSize+litSize; - } - - case set_rle: - { U32 const lhlCode = ((istart[0]) >> 2) & 3; - size_t litSize, lhSize; - switch(lhlCode) - { - case 0: case 2: default: /* note : default is impossible, since lhlCode into [0..3] */ - lhSize = 1; - litSize = istart[0] >> 3; - break; - case 1: - lhSize = 2; - litSize = MEM_readLE16(istart) >> 4; - break; - case 3: - lhSize = 3; - litSize = MEM_readLE24(istart) >> 4; - if (srcSize<4) return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need lhSize+1 = 4 */ - break; - } - if (litSize > ZSTD_BLOCKSIZE_MAX) return ERROR(corruption_detected); - memset(dctx->litBuffer, istart[lhSize], litSize + WILDCOPY_OVERLENGTH); - dctx->litPtr = dctx->litBuffer; - dctx->litSize = litSize; - return lhSize+1; - } - default: - return ERROR(corruption_detected); /* impossible */ - } - } -} - -/* Default FSE distribution tables. - * These are pre-calculated FSE decoding tables using default distributions as defined in specification : - * https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#default-distributions - * They were generated programmatically with following method : - * - start from default distributions, present in /lib/common/zstd_internal.h - * - generate tables normally, using ZSTD_buildFSETable() - * - printout the content of tables - * - pretify output, report below, test with fuzzer to ensure it's correct */ - -/* Default FSE distribution table for Literal Lengths */ -static const ZSTD_seqSymbol LL_defaultDTable[(1<tableLog = 0; - DTableH->fastMode = 0; - - cell->nbBits = 0; - cell->nextState = 0; - assert(nbAddBits < 255); - cell->nbAdditionalBits = (BYTE)nbAddBits; - cell->baseValue = baseValue; -} - - -/* ZSTD_buildFSETable() : - * generate FSE decoding table for one symbol (ll, ml or off) */ -static void -ZSTD_buildFSETable(ZSTD_seqSymbol* dt, - const short* normalizedCounter, unsigned maxSymbolValue, - const U32* baseValue, const U32* nbAdditionalBits, - unsigned tableLog) -{ - ZSTD_seqSymbol* const tableDecode = dt+1; - U16 symbolNext[MaxSeq+1]; - - U32 const maxSV1 = maxSymbolValue + 1; - U32 const tableSize = 1 << tableLog; - U32 highThreshold = tableSize-1; - - /* Sanity Checks */ - assert(maxSymbolValue <= MaxSeq); - assert(tableLog <= MaxFSELog); - - /* Init, lay down lowprob symbols */ - { ZSTD_seqSymbol_header DTableH; - DTableH.tableLog = tableLog; - DTableH.fastMode = 1; - { S16 const largeLimit= (S16)(1 << (tableLog-1)); - U32 s; - for (s=0; s= largeLimit) DTableH.fastMode=0; - symbolNext[s] = normalizedCounter[s]; - } } } - memcpy(dt, &DTableH, sizeof(DTableH)); - } - - /* Spread symbols */ - { U32 const tableMask = tableSize-1; - U32 const step = FSE_TABLESTEP(tableSize); - U32 s, position = 0; - for (s=0; s highThreshold) position = (position + step) & tableMask; /* lowprob area */ - } } - assert(position == 0); /* position must reach all cells once, otherwise normalizedCounter is incorrect */ - } - - /* Build Decoding table */ - { U32 u; - for (u=0; u max) return ERROR(corruption_detected); - { U32 const symbol = *(const BYTE*)src; - U32 const baseline = baseValue[symbol]; - U32 const nbBits = nbAdditionalBits[symbol]; - ZSTD_buildSeqTable_rle(DTableSpace, baseline, nbBits); - } - *DTablePtr = DTableSpace; - return 1; - case set_basic : - *DTablePtr = defaultTable; - return 0; - case set_repeat: - if (!flagRepeatTable) return ERROR(corruption_detected); - /* prefetch FSE table if used */ - if (ddictIsCold && (nbSeq > 24 /* heuristic */)) { - const void* const pStart = *DTablePtr; - size_t const pSize = sizeof(ZSTD_seqSymbol) * (SEQSYMBOL_TABLE_SIZE(maxLog)); - PREFETCH_AREA(pStart, pSize); - } - return 0; - case set_compressed : - { U32 tableLog; - S16 norm[MaxSeq+1]; - size_t const headerSize = FSE_readNCount(norm, &max, &tableLog, src, srcSize); - if (FSE_isError(headerSize)) return ERROR(corruption_detected); - if (tableLog > maxLog) return ERROR(corruption_detected); - ZSTD_buildFSETable(DTableSpace, norm, max, baseValue, nbAdditionalBits, tableLog); - *DTablePtr = DTableSpace; - return headerSize; - } - default : /* impossible */ - assert(0); - return ERROR(GENERIC); - } -} - -static const U32 LL_base[MaxLL+1] = { - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 18, 20, 22, 24, 28, 32, 40, - 48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, - 0x2000, 0x4000, 0x8000, 0x10000 }; - -static const U32 OF_base[MaxOff+1] = { - 0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D, - 0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD, - 0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD, - 0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD }; - -static const U32 OF_bits[MaxOff+1] = { - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31 }; - -static const U32 ML_base[MaxML+1] = { - 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, - 35, 37, 39, 41, 43, 47, 51, 59, - 67, 83, 99, 0x83, 0x103, 0x203, 0x403, 0x803, - 0x1003, 0x2003, 0x4003, 0x8003, 0x10003 }; - -/* Hidden delcaration for fullbench */ -size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr, - const void* src, size_t srcSize); - -size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr, - const void* src, size_t srcSize) -{ - const BYTE* const istart = (const BYTE* const)src; - const BYTE* const iend = istart + srcSize; - const BYTE* ip = istart; - int nbSeq; - DEBUGLOG(5, "ZSTD_decodeSeqHeaders"); - - /* check */ - if (srcSize < MIN_SEQUENCES_SIZE) return ERROR(srcSize_wrong); - - /* SeqHead */ - nbSeq = *ip++; - if (!nbSeq) { *nbSeqPtr=0; return 1; } - if (nbSeq > 0x7F) { - if (nbSeq == 0xFF) { - if (ip+2 > iend) return ERROR(srcSize_wrong); - nbSeq = MEM_readLE16(ip) + LONGNBSEQ, ip+=2; - } else { - if (ip >= iend) return ERROR(srcSize_wrong); - nbSeq = ((nbSeq-0x80)<<8) + *ip++; - } - } - *nbSeqPtr = nbSeq; - - /* FSE table descriptors */ - if (ip+4 > iend) return ERROR(srcSize_wrong); /* minimum possible size */ - { symbolEncodingType_e const LLtype = (symbolEncodingType_e)(*ip >> 6); - symbolEncodingType_e const OFtype = (symbolEncodingType_e)((*ip >> 4) & 3); - symbolEncodingType_e const MLtype = (symbolEncodingType_e)((*ip >> 2) & 3); - ip++; - - /* Build DTables */ - { size_t const llhSize = ZSTD_buildSeqTable(dctx->entropy.LLTable, &dctx->LLTptr, - LLtype, MaxLL, LLFSELog, - ip, iend-ip, - LL_base, LL_bits, - LL_defaultDTable, dctx->fseEntropy, - dctx->ddictIsCold, nbSeq); - if (ZSTD_isError(llhSize)) return ERROR(corruption_detected); - ip += llhSize; - } - - { size_t const ofhSize = ZSTD_buildSeqTable(dctx->entropy.OFTable, &dctx->OFTptr, - OFtype, MaxOff, OffFSELog, - ip, iend-ip, - OF_base, OF_bits, - OF_defaultDTable, dctx->fseEntropy, - dctx->ddictIsCold, nbSeq); - if (ZSTD_isError(ofhSize)) return ERROR(corruption_detected); - ip += ofhSize; - } - - { size_t const mlhSize = ZSTD_buildSeqTable(dctx->entropy.MLTable, &dctx->MLTptr, - MLtype, MaxML, MLFSELog, - ip, iend-ip, - ML_base, ML_bits, - ML_defaultDTable, dctx->fseEntropy, - dctx->ddictIsCold, nbSeq); - if (ZSTD_isError(mlhSize)) return ERROR(corruption_detected); - ip += mlhSize; - } - } - - /* prefetch dictionary content */ - if (dctx->ddictIsCold) { - size_t const dictSize = (const char*)dctx->prefixStart - (const char*)dctx->virtualStart; - size_t const psmin = MIN(dictSize, (size_t)(64*nbSeq) /* heuristic */ ); - size_t const pSize = MIN(psmin, 128 KB /* protection */ ); - const void* const pStart = (const char*)dctx->dictEnd - pSize; - PREFETCH_AREA(pStart, pSize); - dctx->ddictIsCold = 0; - } - - return ip-istart; -} - - -typedef struct { - size_t litLength; - size_t matchLength; - size_t offset; - const BYTE* match; -} seq_t; - -typedef struct { - size_t state; - const ZSTD_seqSymbol* table; -} ZSTD_fseState; - -typedef struct { - BIT_DStream_t DStream; - ZSTD_fseState stateLL; - ZSTD_fseState stateOffb; - ZSTD_fseState stateML; - size_t prevOffset[ZSTD_REP_NUM]; - const BYTE* prefixStart; - const BYTE* dictEnd; - size_t pos; -} seqState_t; - - -FORCE_NOINLINE -size_t ZSTD_execSequenceLast7(BYTE* op, - BYTE* const oend, seq_t sequence, - const BYTE** litPtr, const BYTE* const litLimit, - const BYTE* const base, const BYTE* const vBase, const BYTE* const dictEnd) -{ - BYTE* const oLitEnd = op + sequence.litLength; - size_t const sequenceLength = sequence.litLength + sequence.matchLength; - BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */ - BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH; - const BYTE* const iLitEnd = *litPtr + sequence.litLength; - const BYTE* match = oLitEnd - sequence.offset; - - /* check */ - if (oMatchEnd>oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */ - if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */ - if (oLitEnd <= oend_w) return ERROR(GENERIC); /* Precondition */ - - /* copy literals */ - if (op < oend_w) { - ZSTD_wildcopy(op, *litPtr, oend_w - op); - *litPtr += oend_w - op; - op = oend_w; - } - while (op < oLitEnd) *op++ = *(*litPtr)++; - - /* copy Match */ - if (sequence.offset > (size_t)(oLitEnd - base)) { - /* offset beyond prefix */ - if (sequence.offset > (size_t)(oLitEnd - vBase)) return ERROR(corruption_detected); - match = dictEnd - (base-match); - if (match + sequence.matchLength <= dictEnd) { - memmove(oLitEnd, match, sequence.matchLength); - return sequenceLength; - } - /* span extDict & currentPrefixSegment */ - { size_t const length1 = dictEnd - match; - memmove(oLitEnd, match, length1); - op = oLitEnd + length1; - sequence.matchLength -= length1; - match = base; - } } - while (op < oMatchEnd) *op++ = *match++; - return sequenceLength; -} - - -HINT_INLINE -size_t ZSTD_execSequence(BYTE* op, - BYTE* const oend, seq_t sequence, - const BYTE** litPtr, const BYTE* const litLimit, - const BYTE* const prefixStart, const BYTE* const virtualStart, const BYTE* const dictEnd) -{ - BYTE* const oLitEnd = op + sequence.litLength; - size_t const sequenceLength = sequence.litLength + sequence.matchLength; - BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */ - BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH; - const BYTE* const iLitEnd = *litPtr + sequence.litLength; - const BYTE* match = oLitEnd - sequence.offset; - - /* check */ - if (oMatchEnd>oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */ - if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */ - if (oLitEnd>oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, virtualStart, dictEnd); - - /* copy Literals */ - ZSTD_copy8(op, *litPtr); - if (sequence.litLength > 8) - ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */ - op = oLitEnd; - *litPtr = iLitEnd; /* update for next sequence */ - - /* copy Match */ - if (sequence.offset > (size_t)(oLitEnd - prefixStart)) { - /* offset beyond prefix -> go into extDict */ - if (sequence.offset > (size_t)(oLitEnd - virtualStart)) - return ERROR(corruption_detected); - match = dictEnd + (match - prefixStart); - if (match + sequence.matchLength <= dictEnd) { - memmove(oLitEnd, match, sequence.matchLength); - return sequenceLength; - } - /* span extDict & currentPrefixSegment */ - { size_t const length1 = dictEnd - match; - memmove(oLitEnd, match, length1); - op = oLitEnd + length1; - sequence.matchLength -= length1; - match = prefixStart; - if (op > oend_w || sequence.matchLength < MINMATCH) { - U32 i; - for (i = 0; i < sequence.matchLength; ++i) op[i] = match[i]; - return sequenceLength; - } - } } - /* Requirement: op <= oend_w && sequence.matchLength >= MINMATCH */ - - /* match within prefix */ - if (sequence.offset < 8) { - /* close range match, overlap */ - static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */ - static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */ - int const sub2 = dec64table[sequence.offset]; - op[0] = match[0]; - op[1] = match[1]; - op[2] = match[2]; - op[3] = match[3]; - match += dec32table[sequence.offset]; - ZSTD_copy4(op+4, match); - match -= sub2; - } else { - ZSTD_copy8(op, match); - } - op += 8; match += 8; - - if (oMatchEnd > oend-(16-MINMATCH)) { - if (op < oend_w) { - ZSTD_wildcopy(op, match, oend_w - op); - match += oend_w - op; - op = oend_w; - } - while (op < oMatchEnd) *op++ = *match++; - } else { - ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8 */ - } - return sequenceLength; -} - - -HINT_INLINE -size_t ZSTD_execSequenceLong(BYTE* op, - BYTE* const oend, seq_t sequence, - const BYTE** litPtr, const BYTE* const litLimit, - const BYTE* const prefixStart, const BYTE* const dictStart, const BYTE* const dictEnd) -{ - BYTE* const oLitEnd = op + sequence.litLength; - size_t const sequenceLength = sequence.litLength + sequence.matchLength; - BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */ - BYTE* const oend_w = oend - WILDCOPY_OVERLENGTH; - const BYTE* const iLitEnd = *litPtr + sequence.litLength; - const BYTE* match = sequence.match; - - /* check */ - if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of WILDCOPY_OVERLENGTH from oend */ - if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */ - if (oLitEnd > oend_w) return ZSTD_execSequenceLast7(op, oend, sequence, litPtr, litLimit, prefixStart, dictStart, dictEnd); - - /* copy Literals */ - ZSTD_copy8(op, *litPtr); /* note : op <= oLitEnd <= oend_w == oend - 8 */ - if (sequence.litLength > 8) - ZSTD_wildcopy(op+8, (*litPtr)+8, sequence.litLength - 8); /* note : since oLitEnd <= oend-WILDCOPY_OVERLENGTH, no risk of overwrite beyond oend */ - op = oLitEnd; - *litPtr = iLitEnd; /* update for next sequence */ - - /* copy Match */ - if (sequence.offset > (size_t)(oLitEnd - prefixStart)) { - /* offset beyond prefix */ - if (sequence.offset > (size_t)(oLitEnd - dictStart)) return ERROR(corruption_detected); - if (match + sequence.matchLength <= dictEnd) { - memmove(oLitEnd, match, sequence.matchLength); - return sequenceLength; - } - /* span extDict & currentPrefixSegment */ - { size_t const length1 = dictEnd - match; - memmove(oLitEnd, match, length1); - op = oLitEnd + length1; - sequence.matchLength -= length1; - match = prefixStart; - if (op > oend_w || sequence.matchLength < MINMATCH) { - U32 i; - for (i = 0; i < sequence.matchLength; ++i) op[i] = match[i]; - return sequenceLength; - } - } } - assert(op <= oend_w); - assert(sequence.matchLength >= MINMATCH); - - /* match within prefix */ - if (sequence.offset < 8) { - /* close range match, overlap */ - static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */ - static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */ - int const sub2 = dec64table[sequence.offset]; - op[0] = match[0]; - op[1] = match[1]; - op[2] = match[2]; - op[3] = match[3]; - match += dec32table[sequence.offset]; - ZSTD_copy4(op+4, match); - match -= sub2; - } else { - ZSTD_copy8(op, match); - } - op += 8; match += 8; - - if (oMatchEnd > oend-(16-MINMATCH)) { - if (op < oend_w) { - ZSTD_wildcopy(op, match, oend_w - op); - match += oend_w - op; - op = oend_w; - } - while (op < oMatchEnd) *op++ = *match++; - } else { - ZSTD_wildcopy(op, match, (ptrdiff_t)sequence.matchLength-8); /* works even if matchLength < 8 */ - } - return sequenceLength; -} - -static void -ZSTD_initFseState(ZSTD_fseState* DStatePtr, BIT_DStream_t* bitD, const ZSTD_seqSymbol* dt) -{ - const void* ptr = dt; - const ZSTD_seqSymbol_header* const DTableH = (const ZSTD_seqSymbol_header*)ptr; - DStatePtr->state = BIT_readBits(bitD, DTableH->tableLog); - DEBUGLOG(6, "ZSTD_initFseState : val=%u using %u bits", - (U32)DStatePtr->state, DTableH->tableLog); - BIT_reloadDStream(bitD); - DStatePtr->table = dt + 1; -} - -FORCE_INLINE_TEMPLATE void -ZSTD_updateFseState(ZSTD_fseState* DStatePtr, BIT_DStream_t* bitD) -{ - ZSTD_seqSymbol const DInfo = DStatePtr->table[DStatePtr->state]; - U32 const nbBits = DInfo.nbBits; - size_t const lowBits = BIT_readBits(bitD, nbBits); - DStatePtr->state = DInfo.nextState + lowBits; -} - -/* We need to add at most (ZSTD_WINDOWLOG_MAX_32 - 1) bits to read the maximum - * offset bits. But we can only read at most (STREAM_ACCUMULATOR_MIN_32 - 1) - * bits before reloading. This value is the maximum number of bytes we read - * after reloading when we are decoding long offets. - */ -#define LONG_OFFSETS_MAX_EXTRA_BITS_32 \ - (ZSTD_WINDOWLOG_MAX_32 > STREAM_ACCUMULATOR_MIN_32 \ - ? ZSTD_WINDOWLOG_MAX_32 - STREAM_ACCUMULATOR_MIN_32 \ - : 0) - -typedef enum { ZSTD_lo_isRegularOffset, ZSTD_lo_isLongOffset=1 } ZSTD_longOffset_e; - -FORCE_INLINE_TEMPLATE seq_t -ZSTD_decodeSequence(seqState_t* seqState, const ZSTD_longOffset_e longOffsets) -{ - seq_t seq; - U32 const llBits = seqState->stateLL.table[seqState->stateLL.state].nbAdditionalBits; - U32 const mlBits = seqState->stateML.table[seqState->stateML.state].nbAdditionalBits; - U32 const ofBits = seqState->stateOffb.table[seqState->stateOffb.state].nbAdditionalBits; - U32 const totalBits = llBits+mlBits+ofBits; - U32 const llBase = seqState->stateLL.table[seqState->stateLL.state].baseValue; - U32 const mlBase = seqState->stateML.table[seqState->stateML.state].baseValue; - U32 const ofBase = seqState->stateOffb.table[seqState->stateOffb.state].baseValue; - - /* sequence */ - { size_t offset; - if (!ofBits) - offset = 0; - else { - ZSTD_STATIC_ASSERT(ZSTD_lo_isLongOffset == 1); - ZSTD_STATIC_ASSERT(LONG_OFFSETS_MAX_EXTRA_BITS_32 == 5); - assert(ofBits <= MaxOff); - if (MEM_32bits() && longOffsets && (ofBits >= STREAM_ACCUMULATOR_MIN_32)) { - U32 const extraBits = ofBits - MIN(ofBits, 32 - seqState->DStream.bitsConsumed); - offset = ofBase + (BIT_readBitsFast(&seqState->DStream, ofBits - extraBits) << extraBits); - BIT_reloadDStream(&seqState->DStream); - if (extraBits) offset += BIT_readBitsFast(&seqState->DStream, extraBits); - assert(extraBits <= LONG_OFFSETS_MAX_EXTRA_BITS_32); /* to avoid another reload */ - } else { - offset = ofBase + BIT_readBitsFast(&seqState->DStream, ofBits/*>0*/); /* <= (ZSTD_WINDOWLOG_MAX-1) bits */ - if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); - } - } - - if (ofBits <= 1) { - offset += (llBase==0); - if (offset) { - size_t temp = (offset==3) ? seqState->prevOffset[0] - 1 : seqState->prevOffset[offset]; - temp += !temp; /* 0 is not valid; input is corrupted; force offset to 1 */ - if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1]; - seqState->prevOffset[1] = seqState->prevOffset[0]; - seqState->prevOffset[0] = offset = temp; - } else { /* offset == 0 */ - offset = seqState->prevOffset[0]; - } - } else { - seqState->prevOffset[2] = seqState->prevOffset[1]; - seqState->prevOffset[1] = seqState->prevOffset[0]; - seqState->prevOffset[0] = offset; - } - seq.offset = offset; - } - - seq.matchLength = mlBase - + ((mlBits>0) ? BIT_readBitsFast(&seqState->DStream, mlBits/*>0*/) : 0); /* <= 16 bits */ - if (MEM_32bits() && (mlBits+llBits >= STREAM_ACCUMULATOR_MIN_32-LONG_OFFSETS_MAX_EXTRA_BITS_32)) - BIT_reloadDStream(&seqState->DStream); - if (MEM_64bits() && (totalBits >= STREAM_ACCUMULATOR_MIN_64-(LLFSELog+MLFSELog+OffFSELog))) - BIT_reloadDStream(&seqState->DStream); - /* Ensure there are enough bits to read the rest of data in 64-bit mode. */ - ZSTD_STATIC_ASSERT(16+LLFSELog+MLFSELog+OffFSELog < STREAM_ACCUMULATOR_MIN_64); - - seq.litLength = llBase - + ((llBits>0) ? BIT_readBitsFast(&seqState->DStream, llBits/*>0*/) : 0); /* <= 16 bits */ - if (MEM_32bits()) - BIT_reloadDStream(&seqState->DStream); - - DEBUGLOG(6, "seq: litL=%u, matchL=%u, offset=%u", - (U32)seq.litLength, (U32)seq.matchLength, (U32)seq.offset); - - /* ANS state update */ - ZSTD_updateFseState(&seqState->stateLL, &seqState->DStream); /* <= 9 bits */ - ZSTD_updateFseState(&seqState->stateML, &seqState->DStream); /* <= 9 bits */ - if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); /* <= 18 bits */ - ZSTD_updateFseState(&seqState->stateOffb, &seqState->DStream); /* <= 8 bits */ - - return seq; -} - -FORCE_INLINE_TEMPLATE size_t -ZSTD_decompressSequences_body( ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - const BYTE* ip = (const BYTE*)seqStart; - const BYTE* const iend = ip + seqSize; - BYTE* const ostart = (BYTE* const)dst; - BYTE* const oend = ostart + maxDstSize; - BYTE* op = ostart; - const BYTE* litPtr = dctx->litPtr; - const BYTE* const litEnd = litPtr + dctx->litSize; - const BYTE* const prefixStart = (const BYTE*) (dctx->prefixStart); - const BYTE* const vBase = (const BYTE*) (dctx->virtualStart); - const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd); - DEBUGLOG(5, "ZSTD_decompressSequences_body"); - - /* Regen sequences */ - if (nbSeq) { - seqState_t seqState; - dctx->fseEntropy = 1; - { U32 i; for (i=0; ientropy.rep[i]; } - CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected); - ZSTD_initFseState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr); - ZSTD_initFseState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr); - ZSTD_initFseState(&seqState.stateML, &seqState.DStream, dctx->MLTptr); - - for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) { - nbSeq--; - { seq_t const sequence = ZSTD_decodeSequence(&seqState, isLongOffset); - size_t const oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litEnd, prefixStart, vBase, dictEnd); - DEBUGLOG(6, "regenerated sequence size : %u", (U32)oneSeqSize); - if (ZSTD_isError(oneSeqSize)) return oneSeqSize; - op += oneSeqSize; - } } - - /* check if reached exact end */ - DEBUGLOG(5, "ZSTD_decompressSequences_body: after decode loop, remaining nbSeq : %i", nbSeq); - if (nbSeq) return ERROR(corruption_detected); - /* save reps for next block */ - { U32 i; for (i=0; ientropy.rep[i] = (U32)(seqState.prevOffset[i]); } - } - - /* last literal segment */ - { size_t const lastLLSize = litEnd - litPtr; - if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall); - memcpy(op, litPtr, lastLLSize); - op += lastLLSize; - } - - return op-ostart; -} - -static size_t -ZSTD_decompressSequences_default(ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - return ZSTD_decompressSequences_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - - - -FORCE_INLINE_TEMPLATE seq_t -ZSTD_decodeSequenceLong(seqState_t* seqState, ZSTD_longOffset_e const longOffsets) -{ - seq_t seq; - U32 const llBits = seqState->stateLL.table[seqState->stateLL.state].nbAdditionalBits; - U32 const mlBits = seqState->stateML.table[seqState->stateML.state].nbAdditionalBits; - U32 const ofBits = seqState->stateOffb.table[seqState->stateOffb.state].nbAdditionalBits; - U32 const totalBits = llBits+mlBits+ofBits; - U32 const llBase = seqState->stateLL.table[seqState->stateLL.state].baseValue; - U32 const mlBase = seqState->stateML.table[seqState->stateML.state].baseValue; - U32 const ofBase = seqState->stateOffb.table[seqState->stateOffb.state].baseValue; - - /* sequence */ - { size_t offset; - if (!ofBits) - offset = 0; - else { - ZSTD_STATIC_ASSERT(ZSTD_lo_isLongOffset == 1); - ZSTD_STATIC_ASSERT(LONG_OFFSETS_MAX_EXTRA_BITS_32 == 5); - assert(ofBits <= MaxOff); - if (MEM_32bits() && longOffsets) { - U32 const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN_32-1); - offset = ofBase + (BIT_readBitsFast(&seqState->DStream, ofBits - extraBits) << extraBits); - if (MEM_32bits() || extraBits) BIT_reloadDStream(&seqState->DStream); - if (extraBits) offset += BIT_readBitsFast(&seqState->DStream, extraBits); - } else { - offset = ofBase + BIT_readBitsFast(&seqState->DStream, ofBits); /* <= (ZSTD_WINDOWLOG_MAX-1) bits */ - if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); - } - } - - if (ofBits <= 1) { - offset += (llBase==0); - if (offset) { - size_t temp = (offset==3) ? seqState->prevOffset[0] - 1 : seqState->prevOffset[offset]; - temp += !temp; /* 0 is not valid; input is corrupted; force offset to 1 */ - if (offset != 1) seqState->prevOffset[2] = seqState->prevOffset[1]; - seqState->prevOffset[1] = seqState->prevOffset[0]; - seqState->prevOffset[0] = offset = temp; - } else { - offset = seqState->prevOffset[0]; - } - } else { - seqState->prevOffset[2] = seqState->prevOffset[1]; - seqState->prevOffset[1] = seqState->prevOffset[0]; - seqState->prevOffset[0] = offset; - } - seq.offset = offset; - } - - seq.matchLength = mlBase + ((mlBits>0) ? BIT_readBitsFast(&seqState->DStream, mlBits) : 0); /* <= 16 bits */ - if (MEM_32bits() && (mlBits+llBits >= STREAM_ACCUMULATOR_MIN_32-LONG_OFFSETS_MAX_EXTRA_BITS_32)) - BIT_reloadDStream(&seqState->DStream); - if (MEM_64bits() && (totalBits >= STREAM_ACCUMULATOR_MIN_64-(LLFSELog+MLFSELog+OffFSELog))) - BIT_reloadDStream(&seqState->DStream); - /* Verify that there is enough bits to read the rest of the data in 64-bit mode. */ - ZSTD_STATIC_ASSERT(16+LLFSELog+MLFSELog+OffFSELog < STREAM_ACCUMULATOR_MIN_64); - - seq.litLength = llBase + ((llBits>0) ? BIT_readBitsFast(&seqState->DStream, llBits) : 0); /* <= 16 bits */ - if (MEM_32bits()) - BIT_reloadDStream(&seqState->DStream); - - { size_t const pos = seqState->pos + seq.litLength; - const BYTE* const matchBase = (seq.offset > pos) ? seqState->dictEnd : seqState->prefixStart; - seq.match = matchBase + pos - seq.offset; /* note : this operation can overflow when seq.offset is really too large, which can only happen when input is corrupted. - * No consequence though : no memory access will occur, overly large offset will be detected in ZSTD_execSequenceLong() */ - seqState->pos = pos + seq.matchLength; - } - - /* ANS state update */ - ZSTD_updateFseState(&seqState->stateLL, &seqState->DStream); /* <= 9 bits */ - ZSTD_updateFseState(&seqState->stateML, &seqState->DStream); /* <= 9 bits */ - if (MEM_32bits()) BIT_reloadDStream(&seqState->DStream); /* <= 18 bits */ - ZSTD_updateFseState(&seqState->stateOffb, &seqState->DStream); /* <= 8 bits */ - - return seq; -} - -FORCE_INLINE_TEMPLATE size_t -ZSTD_decompressSequencesLong_body( - ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - const BYTE* ip = (const BYTE*)seqStart; - const BYTE* const iend = ip + seqSize; - BYTE* const ostart = (BYTE* const)dst; - BYTE* const oend = ostart + maxDstSize; - BYTE* op = ostart; - const BYTE* litPtr = dctx->litPtr; - const BYTE* const litEnd = litPtr + dctx->litSize; - const BYTE* const prefixStart = (const BYTE*) (dctx->prefixStart); - const BYTE* const dictStart = (const BYTE*) (dctx->virtualStart); - const BYTE* const dictEnd = (const BYTE*) (dctx->dictEnd); - - /* Regen sequences */ - if (nbSeq) { -#define STORED_SEQS 4 -#define STOSEQ_MASK (STORED_SEQS-1) -#define ADVANCED_SEQS 4 - seq_t sequences[STORED_SEQS]; - int const seqAdvance = MIN(nbSeq, ADVANCED_SEQS); - seqState_t seqState; - int seqNb; - dctx->fseEntropy = 1; - { U32 i; for (i=0; ientropy.rep[i]; } - seqState.prefixStart = prefixStart; - seqState.pos = (size_t)(op-prefixStart); - seqState.dictEnd = dictEnd; - CHECK_E(BIT_initDStream(&seqState.DStream, ip, iend-ip), corruption_detected); - ZSTD_initFseState(&seqState.stateLL, &seqState.DStream, dctx->LLTptr); - ZSTD_initFseState(&seqState.stateOffb, &seqState.DStream, dctx->OFTptr); - ZSTD_initFseState(&seqState.stateML, &seqState.DStream, dctx->MLTptr); - - /* prepare in advance */ - for (seqNb=0; (BIT_reloadDStream(&seqState.DStream) <= BIT_DStream_completed) && (seqNbentropy.rep[i] = (U32)(seqState.prevOffset[i]); } -#undef STORED_SEQS -#undef STOSEQ_MASK -#undef ADVANCED_SEQS - } - - /* last literal segment */ - { size_t const lastLLSize = litEnd - litPtr; - if (lastLLSize > (size_t)(oend-op)) return ERROR(dstSize_tooSmall); - memcpy(op, litPtr, lastLLSize); - op += lastLLSize; - } - - return op-ostart; -} - -static size_t -ZSTD_decompressSequencesLong_default(ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - return ZSTD_decompressSequencesLong_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - - - -#if DYNAMIC_BMI2 - -static TARGET_ATTRIBUTE("bmi2") size_t -ZSTD_decompressSequences_bmi2(ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - return ZSTD_decompressSequences_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - -static TARGET_ATTRIBUTE("bmi2") size_t -ZSTD_decompressSequencesLong_bmi2(ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - return ZSTD_decompressSequencesLong_body(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - -#endif - -typedef size_t (*ZSTD_decompressSequences_t)( - ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, - const void *seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset); - -static size_t ZSTD_decompressSequences(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - DEBUGLOG(5, "ZSTD_decompressSequences"); -#if DYNAMIC_BMI2 - if (dctx->bmi2) { - return ZSTD_decompressSequences_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); - } -#endif - return ZSTD_decompressSequences_default(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - -static size_t ZSTD_decompressSequencesLong(ZSTD_DCtx* dctx, - void* dst, size_t maxDstSize, - const void* seqStart, size_t seqSize, int nbSeq, - const ZSTD_longOffset_e isLongOffset) -{ - DEBUGLOG(5, "ZSTD_decompressSequencesLong"); -#if DYNAMIC_BMI2 - if (dctx->bmi2) { - return ZSTD_decompressSequencesLong_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); - } -#endif - return ZSTD_decompressSequencesLong_default(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset); -} - -/* ZSTD_getLongOffsetsShare() : - * condition : offTable must be valid - * @return : "share" of long offsets (arbitrarily defined as > (1<<23)) - * compared to maximum possible of (1< 22) total += 1; - } - - assert(tableLog <= OffFSELog); - total <<= (OffFSELog - tableLog); /* scale to OffFSELog */ - - return total; -} - - -static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, const int frame) -{ /* blockType == blockCompressed */ - const BYTE* ip = (const BYTE*)src; - /* isLongOffset must be true if there are long offsets. - * Offsets are long if they are larger than 2^STREAM_ACCUMULATOR_MIN. - * We don't expect that to be the case in 64-bit mode. - * In block mode, window size is not known, so we have to be conservative. - * (note: but it could be evaluated from current-lowLimit) - */ - ZSTD_longOffset_e const isLongOffset = (ZSTD_longOffset_e)(MEM_32bits() && (!frame || dctx->fParams.windowSize > (1ULL << STREAM_ACCUMULATOR_MIN))); - DEBUGLOG(5, "ZSTD_decompressBlock_internal (size : %u)", (U32)srcSize); - - if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong); - - /* Decode literals section */ - { size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize); - DEBUGLOG(5, "ZSTD_decodeLiteralsBlock : %u", (U32)litCSize); - if (ZSTD_isError(litCSize)) return litCSize; - ip += litCSize; - srcSize -= litCSize; - } - - /* Build Decoding Tables */ - { int nbSeq; - size_t const seqHSize = ZSTD_decodeSeqHeaders(dctx, &nbSeq, ip, srcSize); - if (ZSTD_isError(seqHSize)) return seqHSize; - ip += seqHSize; - srcSize -= seqHSize; - - if ( (!frame || dctx->fParams.windowSize > (1<<24)) - && (nbSeq>0) ) { /* could probably use a larger nbSeq limit */ - U32 const shareLongOffsets = ZSTD_getLongOffsetsShare(dctx->OFTptr); - U32 const minShare = MEM_64bits() ? 7 : 20; /* heuristic values, correspond to 2.73% and 7.81% */ - if (shareLongOffsets >= minShare) - return ZSTD_decompressSequencesLong(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset); - } - - return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize, nbSeq, isLongOffset); - } -} - - -static void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst) -{ - if (dst != dctx->previousDstEnd) { /* not contiguous */ - dctx->dictEnd = dctx->previousDstEnd; - dctx->virtualStart = (const char*)dst - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart)); - dctx->prefixStart = dst; - dctx->previousDstEnd = dst; - } -} - -size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize) -{ - size_t dSize; - ZSTD_checkContinuity(dctx, dst); - dSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 0); - dctx->previousDstEnd = (char*)dst + dSize; - return dSize; -} - - -/** ZSTD_insertBlock() : - insert `src` block into `dctx` history. Useful to track uncompressed blocks. */ -ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize) -{ - ZSTD_checkContinuity(dctx, blockStart); - dctx->previousDstEnd = (const char*)blockStart + blockSize; - return blockSize; -} - - -static size_t ZSTD_generateNxBytes(void* dst, size_t dstCapacity, BYTE value, size_t length) -{ - if (length > dstCapacity) return ERROR(dstSize_tooSmall); - memset(dst, value, length); - return length; -} - -/** ZSTD_findFrameCompressedSize() : - * compatible with legacy mode - * `src` must point to the start of a ZSTD frame, ZSTD legacy frame, or skippable frame - * `srcSize` must be at least as large as the frame contained - * @return : the compressed size of the frame starting at `src` */ -size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize) -{ -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) - if (ZSTD_isLegacy(src, srcSize)) - return ZSTD_findFrameCompressedSizeLegacy(src, srcSize); -#endif - if ( (srcSize >= ZSTD_skippableHeaderSize) - && (MEM_readLE32(src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START ) { - return ZSTD_skippableHeaderSize + MEM_readLE32((const BYTE*)src + ZSTD_FRAMEIDSIZE); - } else { - const BYTE* ip = (const BYTE*)src; - const BYTE* const ipstart = ip; - size_t remainingSize = srcSize; - ZSTD_frameHeader zfh; - - /* Extract Frame Header */ - { size_t const ret = ZSTD_getFrameHeader(&zfh, src, srcSize); - if (ZSTD_isError(ret)) return ret; - if (ret > 0) return ERROR(srcSize_wrong); - } - - ip += zfh.headerSize; - remainingSize -= zfh.headerSize; - - /* Loop on each block */ - while (1) { - blockProperties_t blockProperties; - size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties); - if (ZSTD_isError(cBlockSize)) return cBlockSize; - - if (ZSTD_blockHeaderSize + cBlockSize > remainingSize) - return ERROR(srcSize_wrong); - - ip += ZSTD_blockHeaderSize + cBlockSize; - remainingSize -= ZSTD_blockHeaderSize + cBlockSize; - - if (blockProperties.lastBlock) break; - } - - if (zfh.checksumFlag) { /* Final frame content checksum */ - if (remainingSize < 4) return ERROR(srcSize_wrong); - ip += 4; - } - - return ip - ipstart; - } -} - -/*! ZSTD_decompressFrame() : -* @dctx must be properly initialized */ -static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void** srcPtr, size_t *srcSizePtr) -{ - const BYTE* ip = (const BYTE*)(*srcPtr); - BYTE* const ostart = (BYTE* const)dst; - BYTE* const oend = ostart + dstCapacity; - BYTE* op = ostart; - size_t remainingSize = *srcSizePtr; - - /* check */ - if (remainingSize < ZSTD_frameHeaderSize_min+ZSTD_blockHeaderSize) - return ERROR(srcSize_wrong); - - /* Frame Header */ - { size_t const frameHeaderSize = ZSTD_frameHeaderSize(ip, ZSTD_frameHeaderSize_prefix); - if (ZSTD_isError(frameHeaderSize)) return frameHeaderSize; - if (remainingSize < frameHeaderSize+ZSTD_blockHeaderSize) - return ERROR(srcSize_wrong); - CHECK_F( ZSTD_decodeFrameHeader(dctx, ip, frameHeaderSize) ); - ip += frameHeaderSize; remainingSize -= frameHeaderSize; - } - - /* Loop on each block */ - while (1) { - size_t decodedSize; - blockProperties_t blockProperties; - size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties); - if (ZSTD_isError(cBlockSize)) return cBlockSize; - - ip += ZSTD_blockHeaderSize; - remainingSize -= ZSTD_blockHeaderSize; - if (cBlockSize > remainingSize) return ERROR(srcSize_wrong); - - switch(blockProperties.blockType) - { - case bt_compressed: - decodedSize = ZSTD_decompressBlock_internal(dctx, op, oend-op, ip, cBlockSize, /* frame */ 1); - break; - case bt_raw : - decodedSize = ZSTD_copyRawBlock(op, oend-op, ip, cBlockSize); - break; - case bt_rle : - decodedSize = ZSTD_generateNxBytes(op, oend-op, *ip, blockProperties.origSize); - break; - case bt_reserved : - default: - return ERROR(corruption_detected); - } - - if (ZSTD_isError(decodedSize)) return decodedSize; - if (dctx->fParams.checksumFlag) - XXH64_update(&dctx->xxhState, op, decodedSize); - op += decodedSize; - ip += cBlockSize; - remainingSize -= cBlockSize; - if (blockProperties.lastBlock) break; - } - - if (dctx->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) { - if ((U64)(op-ostart) != dctx->fParams.frameContentSize) { - return ERROR(corruption_detected); - } } - if (dctx->fParams.checksumFlag) { /* Frame content checksum verification */ - U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState); - U32 checkRead; - if (remainingSize<4) return ERROR(checksum_wrong); - checkRead = MEM_readLE32(ip); - if (checkRead != checkCalc) return ERROR(checksum_wrong); - ip += 4; - remainingSize -= 4; - } - - /* Allow caller to get size read */ - *srcPtr = ip; - *srcSizePtr = remainingSize; - return op-ostart; -} - -static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const void* dict, size_t dictSize, - const ZSTD_DDict* ddict) -{ - void* const dststart = dst; - int moreThan1Frame = 0; - - DEBUGLOG(5, "ZSTD_decompressMultiFrame"); - assert(dict==NULL || ddict==NULL); /* either dict or ddict set, not both */ - - if (ddict) { - dict = ZSTD_DDictDictContent(ddict); - dictSize = ZSTD_DDictDictSize(ddict); - } - - while (srcSize >= ZSTD_frameHeaderSize_prefix) { - -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) - if (ZSTD_isLegacy(src, srcSize)) { - size_t decodedSize; - size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize); - if (ZSTD_isError(frameSize)) return frameSize; - /* legacy support is not compatible with static dctx */ - if (dctx->staticSize) return ERROR(memory_allocation); - - decodedSize = ZSTD_decompressLegacy(dst, dstCapacity, src, frameSize, dict, dictSize); - - dst = (BYTE*)dst + decodedSize; - dstCapacity -= decodedSize; - - src = (const BYTE*)src + frameSize; - srcSize -= frameSize; - - continue; - } -#endif - - { U32 const magicNumber = MEM_readLE32(src); - DEBUGLOG(4, "reading magic number %08X (expecting %08X)", - (U32)magicNumber, (U32)ZSTD_MAGICNUMBER); - if ((magicNumber & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { - size_t skippableSize; - if (srcSize < ZSTD_skippableHeaderSize) - return ERROR(srcSize_wrong); - skippableSize = MEM_readLE32((const BYTE*)src + ZSTD_FRAMEIDSIZE) - + ZSTD_skippableHeaderSize; - if (srcSize < skippableSize) return ERROR(srcSize_wrong); - - src = (const BYTE *)src + skippableSize; - srcSize -= skippableSize; - continue; - } } - - if (ddict) { - /* we were called from ZSTD_decompress_usingDDict */ - CHECK_F(ZSTD_decompressBegin_usingDDict(dctx, ddict)); - } else { - /* this will initialize correctly with no dict if dict == NULL, so - * use this in all cases but ddict */ - CHECK_F(ZSTD_decompressBegin_usingDict(dctx, dict, dictSize)); - } - ZSTD_checkContinuity(dctx, dst); - - { const size_t res = ZSTD_decompressFrame(dctx, dst, dstCapacity, - &src, &srcSize); - if ( (ZSTD_getErrorCode(res) == ZSTD_error_prefix_unknown) - && (moreThan1Frame==1) ) { - /* at least one frame successfully completed, - * but following bytes are garbage : - * it's more likely to be a srcSize error, - * specifying more bytes than compressed size of frame(s). - * This error message replaces ERROR(prefix_unknown), - * which would be confusing, as the first header is actually correct. - * Note that one could be unlucky, it might be a corruption error instead, - * happening right at the place where we expect zstd magic bytes. - * But this is _much_ less likely than a srcSize field error. */ - return ERROR(srcSize_wrong); - } - if (ZSTD_isError(res)) return res; - /* no need to bound check, ZSTD_decompressFrame already has */ - dst = (BYTE*)dst + res; - dstCapacity -= res; - } - moreThan1Frame = 1; - } /* while (srcSize >= ZSTD_frameHeaderSize_prefix) */ - - if (srcSize) return ERROR(srcSize_wrong); /* input not entirely consumed */ - - return (BYTE*)dst - (BYTE*)dststart; -} - -size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const void* dict, size_t dictSize) -{ - return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL); -} - - -size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) -{ - return ZSTD_decompress_usingDict(dctx, dst, dstCapacity, src, srcSize, NULL, 0); -} - - -size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t srcSize) -{ -#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1) - size_t regenSize; - ZSTD_DCtx* const dctx = ZSTD_createDCtx(); - if (dctx==NULL) return ERROR(memory_allocation); - regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize); - ZSTD_freeDCtx(dctx); - return regenSize; -#else /* stack mode */ - ZSTD_DCtx dctx; - ZSTD_initDCtx_internal(&dctx); - return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize); -#endif -} - - -/*-************************************** -* Advanced Streaming Decompression API -* Bufferless and synchronous -****************************************/ -size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx) { return dctx->expected; } - -ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) { - switch(dctx->stage) - { - default: /* should not happen */ - assert(0); - case ZSTDds_getFrameHeaderSize: - case ZSTDds_decodeFrameHeader: - return ZSTDnit_frameHeader; - case ZSTDds_decodeBlockHeader: - return ZSTDnit_blockHeader; - case ZSTDds_decompressBlock: - return ZSTDnit_block; - case ZSTDds_decompressLastBlock: - return ZSTDnit_lastBlock; - case ZSTDds_checkChecksum: - return ZSTDnit_checksum; - case ZSTDds_decodeSkippableHeader: - case ZSTDds_skipFrame: - return ZSTDnit_skippableFrame; - } -} - -static int ZSTD_isSkipFrame(ZSTD_DCtx* dctx) { return dctx->stage == ZSTDds_skipFrame; } - -/** ZSTD_decompressContinue() : - * srcSize : must be the exact nb of bytes expected (see ZSTD_nextSrcSizeToDecompress()) - * @return : nb of bytes generated into `dst` (necessarily <= `dstCapacity) - * or an error code, which can be tested using ZSTD_isError() */ -size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) -{ - DEBUGLOG(5, "ZSTD_decompressContinue (srcSize:%u)", (U32)srcSize); - /* Sanity check */ - if (srcSize != dctx->expected) return ERROR(srcSize_wrong); /* not allowed */ - if (dstCapacity) ZSTD_checkContinuity(dctx, dst); - - switch (dctx->stage) - { - case ZSTDds_getFrameHeaderSize : - assert(src != NULL); - if (dctx->format == ZSTD_f_zstd1) { /* allows header */ - assert(srcSize >= ZSTD_FRAMEIDSIZE); /* to read skippable magic number */ - if ((MEM_readLE32(src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */ - memcpy(dctx->headerBuffer, src, srcSize); - dctx->expected = ZSTD_skippableHeaderSize - srcSize; /* remaining to load to get full skippable frame header */ - dctx->stage = ZSTDds_decodeSkippableHeader; - return 0; - } } - dctx->headerSize = ZSTD_frameHeaderSize_internal(src, srcSize, dctx->format); - if (ZSTD_isError(dctx->headerSize)) return dctx->headerSize; - memcpy(dctx->headerBuffer, src, srcSize); - dctx->expected = dctx->headerSize - srcSize; - dctx->stage = ZSTDds_decodeFrameHeader; - return 0; - - case ZSTDds_decodeFrameHeader: - assert(src != NULL); - memcpy(dctx->headerBuffer + (dctx->headerSize - srcSize), src, srcSize); - CHECK_F(ZSTD_decodeFrameHeader(dctx, dctx->headerBuffer, dctx->headerSize)); - dctx->expected = ZSTD_blockHeaderSize; - dctx->stage = ZSTDds_decodeBlockHeader; - return 0; - - case ZSTDds_decodeBlockHeader: - { blockProperties_t bp; - size_t const cBlockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp); - if (ZSTD_isError(cBlockSize)) return cBlockSize; - dctx->expected = cBlockSize; - dctx->bType = bp.blockType; - dctx->rleSize = bp.origSize; - if (cBlockSize) { - dctx->stage = bp.lastBlock ? ZSTDds_decompressLastBlock : ZSTDds_decompressBlock; - return 0; - } - /* empty block */ - if (bp.lastBlock) { - if (dctx->fParams.checksumFlag) { - dctx->expected = 4; - dctx->stage = ZSTDds_checkChecksum; - } else { - dctx->expected = 0; /* end of frame */ - dctx->stage = ZSTDds_getFrameHeaderSize; - } - } else { - dctx->expected = ZSTD_blockHeaderSize; /* jump to next header */ - dctx->stage = ZSTDds_decodeBlockHeader; - } - return 0; - } - - case ZSTDds_decompressLastBlock: - case ZSTDds_decompressBlock: - DEBUGLOG(5, "ZSTD_decompressContinue: case ZSTDds_decompressBlock"); - { size_t rSize; - switch(dctx->bType) - { - case bt_compressed: - DEBUGLOG(5, "ZSTD_decompressContinue: case bt_compressed"); - rSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 1); - break; - case bt_raw : - rSize = ZSTD_copyRawBlock(dst, dstCapacity, src, srcSize); - break; - case bt_rle : - rSize = ZSTD_setRleBlock(dst, dstCapacity, src, srcSize, dctx->rleSize); - break; - case bt_reserved : /* should never happen */ - default: - return ERROR(corruption_detected); - } - if (ZSTD_isError(rSize)) return rSize; - DEBUGLOG(5, "ZSTD_decompressContinue: decoded size from block : %u", (U32)rSize); - dctx->decodedSize += rSize; - if (dctx->fParams.checksumFlag) XXH64_update(&dctx->xxhState, dst, rSize); - - if (dctx->stage == ZSTDds_decompressLastBlock) { /* end of frame */ - DEBUGLOG(4, "ZSTD_decompressContinue: decoded size from frame : %u", (U32)dctx->decodedSize); - if (dctx->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) { - if (dctx->decodedSize != dctx->fParams.frameContentSize) { - return ERROR(corruption_detected); - } } - if (dctx->fParams.checksumFlag) { /* another round for frame checksum */ - dctx->expected = 4; - dctx->stage = ZSTDds_checkChecksum; - } else { - dctx->expected = 0; /* ends here */ - dctx->stage = ZSTDds_getFrameHeaderSize; - } - } else { - dctx->stage = ZSTDds_decodeBlockHeader; - dctx->expected = ZSTD_blockHeaderSize; - dctx->previousDstEnd = (char*)dst + rSize; - } - return rSize; - } - - case ZSTDds_checkChecksum: - assert(srcSize == 4); /* guaranteed by dctx->expected */ - { U32 const h32 = (U32)XXH64_digest(&dctx->xxhState); - U32 const check32 = MEM_readLE32(src); - DEBUGLOG(4, "ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", h32, check32); - if (check32 != h32) return ERROR(checksum_wrong); - dctx->expected = 0; - dctx->stage = ZSTDds_getFrameHeaderSize; - return 0; - } - - case ZSTDds_decodeSkippableHeader: - assert(src != NULL); - assert(srcSize <= ZSTD_skippableHeaderSize); - memcpy(dctx->headerBuffer + (ZSTD_skippableHeaderSize - srcSize), src, srcSize); /* complete skippable header */ - dctx->expected = MEM_readLE32(dctx->headerBuffer + ZSTD_FRAMEIDSIZE); /* note : dctx->expected can grow seriously large, beyond local buffer size */ - dctx->stage = ZSTDds_skipFrame; - return 0; - - case ZSTDds_skipFrame: - dctx->expected = 0; - dctx->stage = ZSTDds_getFrameHeaderSize; - return 0; - - default: - return ERROR(GENERIC); /* impossible */ - } -} - - -static size_t ZSTD_refDictContent(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) -{ - dctx->dictEnd = dctx->previousDstEnd; - dctx->virtualStart = (const char*)dict - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart)); - dctx->prefixStart = dict; - dctx->previousDstEnd = (const char*)dict + dictSize; - return 0; -} - -/*! ZSTD_loadEntropy() : - * dict : must point at beginning of a valid zstd dictionary. - * @return : size of entropy tables read */ -static size_t ZSTD_loadEntropy(ZSTD_entropyDTables_t* entropy, - const void* const dict, size_t const dictSize) -{ - const BYTE* dictPtr = (const BYTE*)dict; - const BYTE* const dictEnd = dictPtr + dictSize; - - if (dictSize <= 8) return ERROR(dictionary_corrupted); - assert(MEM_readLE32(dict) == ZSTD_MAGIC_DICTIONARY); /* dict must be valid */ - dictPtr += 8; /* skip header = magic + dictID */ - - ZSTD_STATIC_ASSERT(offsetof(ZSTD_entropyDTables_t, OFTable) == offsetof(ZSTD_entropyDTables_t, LLTable) + sizeof(entropy->LLTable)); - ZSTD_STATIC_ASSERT(offsetof(ZSTD_entropyDTables_t, MLTable) == offsetof(ZSTD_entropyDTables_t, OFTable) + sizeof(entropy->OFTable)); - ZSTD_STATIC_ASSERT(sizeof(entropy->LLTable) + sizeof(entropy->OFTable) + sizeof(entropy->MLTable) >= HUF_DECOMPRESS_WORKSPACE_SIZE); - { void* const workspace = &entropy->LLTable; /* use fse tables as temporary workspace; implies fse tables are grouped together */ - size_t const workspaceSize = sizeof(entropy->LLTable) + sizeof(entropy->OFTable) + sizeof(entropy->MLTable); - size_t const hSize = HUF_readDTableX2_wksp(entropy->hufTable, - dictPtr, dictEnd - dictPtr, - workspace, workspaceSize); - if (HUF_isError(hSize)) return ERROR(dictionary_corrupted); - dictPtr += hSize; - } - - { short offcodeNCount[MaxOff+1]; - U32 offcodeMaxValue = MaxOff, offcodeLog; - size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); - if (FSE_isError(offcodeHeaderSize)) return ERROR(dictionary_corrupted); - if (offcodeMaxValue > MaxOff) return ERROR(dictionary_corrupted); - if (offcodeLog > OffFSELog) return ERROR(dictionary_corrupted); - ZSTD_buildFSETable( entropy->OFTable, - offcodeNCount, offcodeMaxValue, - OF_base, OF_bits, - offcodeLog); - dictPtr += offcodeHeaderSize; - } - - { short matchlengthNCount[MaxML+1]; - unsigned matchlengthMaxValue = MaxML, matchlengthLog; - size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); - if (FSE_isError(matchlengthHeaderSize)) return ERROR(dictionary_corrupted); - if (matchlengthMaxValue > MaxML) return ERROR(dictionary_corrupted); - if (matchlengthLog > MLFSELog) return ERROR(dictionary_corrupted); - ZSTD_buildFSETable( entropy->MLTable, - matchlengthNCount, matchlengthMaxValue, - ML_base, ML_bits, - matchlengthLog); - dictPtr += matchlengthHeaderSize; - } - - { short litlengthNCount[MaxLL+1]; - unsigned litlengthMaxValue = MaxLL, litlengthLog; - size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); - if (FSE_isError(litlengthHeaderSize)) return ERROR(dictionary_corrupted); - if (litlengthMaxValue > MaxLL) return ERROR(dictionary_corrupted); - if (litlengthLog > LLFSELog) return ERROR(dictionary_corrupted); - ZSTD_buildFSETable( entropy->LLTable, - litlengthNCount, litlengthMaxValue, - LL_base, LL_bits, - litlengthLog); - dictPtr += litlengthHeaderSize; - } - - if (dictPtr+12 > dictEnd) return ERROR(dictionary_corrupted); - { int i; - size_t const dictContentSize = (size_t)(dictEnd - (dictPtr+12)); - for (i=0; i<3; i++) { - U32 const rep = MEM_readLE32(dictPtr); dictPtr += 4; - if (rep==0 || rep >= dictContentSize) return ERROR(dictionary_corrupted); - entropy->rep[i] = rep; - } } - - return dictPtr - (const BYTE*)dict; -} - -static size_t ZSTD_decompress_insertDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) -{ - if (dictSize < 8) return ZSTD_refDictContent(dctx, dict, dictSize); - { U32 const magic = MEM_readLE32(dict); - if (magic != ZSTD_MAGIC_DICTIONARY) { - return ZSTD_refDictContent(dctx, dict, dictSize); /* pure content mode */ - } } - dctx->dictID = MEM_readLE32((const char*)dict + ZSTD_FRAMEIDSIZE); - - /* load entropy tables */ - { size_t const eSize = ZSTD_loadEntropy(&dctx->entropy, dict, dictSize); - if (ZSTD_isError(eSize)) return ERROR(dictionary_corrupted); - dict = (const char*)dict + eSize; - dictSize -= eSize; - } - dctx->litEntropy = dctx->fseEntropy = 1; - - /* reference dictionary content */ - return ZSTD_refDictContent(dctx, dict, dictSize); -} - -size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx) -{ - assert(dctx != NULL); - dctx->expected = ZSTD_startingInputLength(dctx->format); /* dctx->format must be properly set */ - dctx->stage = ZSTDds_getFrameHeaderSize; - dctx->decodedSize = 0; - dctx->previousDstEnd = NULL; - dctx->prefixStart = NULL; - dctx->virtualStart = NULL; - dctx->dictEnd = NULL; - dctx->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */ - dctx->litEntropy = dctx->fseEntropy = 0; - dctx->dictID = 0; - ZSTD_STATIC_ASSERT(sizeof(dctx->entropy.rep) == sizeof(repStartValue)); - memcpy(dctx->entropy.rep, repStartValue, sizeof(repStartValue)); /* initial repcodes */ - dctx->LLTptr = dctx->entropy.LLTable; - dctx->MLTptr = dctx->entropy.MLTable; - dctx->OFTptr = dctx->entropy.OFTable; - dctx->HUFptr = dctx->entropy.hufTable; - return 0; -} - -size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) -{ - CHECK_F( ZSTD_decompressBegin(dctx) ); - if (dict && dictSize) - CHECK_E(ZSTD_decompress_insertDictionary(dctx, dict, dictSize), dictionary_corrupted); - return 0; -} - - -/* ====== ZSTD_DDict ====== */ - -struct ZSTD_DDict_s { - void* dictBuffer; - const void* dictContent; - size_t dictSize; - ZSTD_entropyDTables_t entropy; - U32 dictID; - U32 entropyPresent; - ZSTD_customMem cMem; -}; /* typedef'd to ZSTD_DDict within "zstd.h" */ - -static const void* ZSTD_DDictDictContent(const ZSTD_DDict* ddict) -{ - assert(ddict != NULL); - return ddict->dictContent; -} - -static size_t ZSTD_DDictDictSize(const ZSTD_DDict* ddict) -{ - assert(ddict != NULL); - return ddict->dictSize; -} - -size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict) -{ - DEBUGLOG(4, "ZSTD_decompressBegin_usingDDict"); - assert(dctx != NULL); - if (ddict) { - dctx->ddictIsCold = (dctx->dictEnd != (const char*)ddict->dictContent + ddict->dictSize); - DEBUGLOG(4, "DDict is %s", - dctx->ddictIsCold ? "~cold~" : "hot!"); - } - CHECK_F( ZSTD_decompressBegin(dctx) ); - if (ddict) { /* NULL ddict is equivalent to no dictionary */ - dctx->dictID = ddict->dictID; - dctx->prefixStart = ddict->dictContent; - dctx->virtualStart = ddict->dictContent; - dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize; - dctx->previousDstEnd = dctx->dictEnd; - if (ddict->entropyPresent) { - dctx->litEntropy = 1; - dctx->fseEntropy = 1; - dctx->LLTptr = ddict->entropy.LLTable; - dctx->MLTptr = ddict->entropy.MLTable; - dctx->OFTptr = ddict->entropy.OFTable; - dctx->HUFptr = ddict->entropy.hufTable; - dctx->entropy.rep[0] = ddict->entropy.rep[0]; - dctx->entropy.rep[1] = ddict->entropy.rep[1]; - dctx->entropy.rep[2] = ddict->entropy.rep[2]; - } else { - dctx->litEntropy = 0; - dctx->fseEntropy = 0; - } - } - return 0; -} - -static size_t -ZSTD_loadEntropy_inDDict(ZSTD_DDict* ddict, - ZSTD_dictContentType_e dictContentType) -{ - ddict->dictID = 0; - ddict->entropyPresent = 0; - if (dictContentType == ZSTD_dct_rawContent) return 0; - - if (ddict->dictSize < 8) { - if (dictContentType == ZSTD_dct_fullDict) - return ERROR(dictionary_corrupted); /* only accept specified dictionaries */ - return 0; /* pure content mode */ - } - { U32 const magic = MEM_readLE32(ddict->dictContent); - if (magic != ZSTD_MAGIC_DICTIONARY) { - if (dictContentType == ZSTD_dct_fullDict) - return ERROR(dictionary_corrupted); /* only accept specified dictionaries */ - return 0; /* pure content mode */ - } - } - ddict->dictID = MEM_readLE32((const char*)ddict->dictContent + ZSTD_FRAMEIDSIZE); - - /* load entropy tables */ - CHECK_E( ZSTD_loadEntropy(&ddict->entropy, - ddict->dictContent, ddict->dictSize), - dictionary_corrupted ); - ddict->entropyPresent = 1; - return 0; -} - - -static size_t ZSTD_initDDict_internal(ZSTD_DDict* ddict, - const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType) -{ - if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) { - ddict->dictBuffer = NULL; - ddict->dictContent = dict; - if (!dict) dictSize = 0; - } else { - void* const internalBuffer = ZSTD_malloc(dictSize, ddict->cMem); - ddict->dictBuffer = internalBuffer; - ddict->dictContent = internalBuffer; - if (!internalBuffer) return ERROR(memory_allocation); - memcpy(internalBuffer, dict, dictSize); - } - ddict->dictSize = dictSize; - ddict->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */ - - /* parse dictionary content */ - CHECK_F( ZSTD_loadEntropy_inDDict(ddict, dictContentType) ); - - return 0; -} - -ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType, - ZSTD_customMem customMem) -{ - if (!customMem.customAlloc ^ !customMem.customFree) return NULL; - - { ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_malloc(sizeof(ZSTD_DDict), customMem); - if (ddict == NULL) return NULL; - ddict->cMem = customMem; - { size_t const initResult = ZSTD_initDDict_internal(ddict, - dict, dictSize, - dictLoadMethod, dictContentType); - if (ZSTD_isError(initResult)) { - ZSTD_freeDDict(ddict); - return NULL; - } } - return ddict; - } -} - -/*! ZSTD_createDDict() : -* Create a digested dictionary, to start decompression without startup delay. -* `dict` content is copied inside DDict. -* Consequently, `dict` can be released after `ZSTD_DDict` creation */ -ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize) -{ - ZSTD_customMem const allocator = { NULL, NULL, NULL }; - return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator); -} - -/*! ZSTD_createDDict_byReference() : - * Create a digested dictionary, to start decompression without startup delay. - * Dictionary content is simply referenced, it will be accessed during decompression. - * Warning : dictBuffer must outlive DDict (DDict must be freed before dictBuffer) */ -ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize) -{ - ZSTD_customMem const allocator = { NULL, NULL, NULL }; - return ZSTD_createDDict_advanced(dictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, allocator); -} - - -const ZSTD_DDict* ZSTD_initStaticDDict( - void* sBuffer, size_t sBufferSize, - const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType) -{ - size_t const neededSpace = sizeof(ZSTD_DDict) - + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize); - ZSTD_DDict* const ddict = (ZSTD_DDict*)sBuffer; - assert(sBuffer != NULL); - assert(dict != NULL); - if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */ - if (sBufferSize < neededSpace) return NULL; - if (dictLoadMethod == ZSTD_dlm_byCopy) { - memcpy(ddict+1, dict, dictSize); /* local copy */ - dict = ddict+1; - } - if (ZSTD_isError( ZSTD_initDDict_internal(ddict, - dict, dictSize, - ZSTD_dlm_byRef, dictContentType) )) - return NULL; - return ddict; -} - - -size_t ZSTD_freeDDict(ZSTD_DDict* ddict) -{ - if (ddict==NULL) return 0; /* support free on NULL */ - { ZSTD_customMem const cMem = ddict->cMem; - ZSTD_free(ddict->dictBuffer, cMem); - ZSTD_free(ddict, cMem); - return 0; - } -} - -/*! ZSTD_estimateDDictSize() : - * Estimate amount of memory that will be needed to create a dictionary for decompression. - * Note : dictionary created by reference using ZSTD_dlm_byRef are smaller */ -size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod) -{ - return sizeof(ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize); -} - -size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict) -{ - if (ddict==NULL) return 0; /* support sizeof on NULL */ - return sizeof(*ddict) + (ddict->dictBuffer ? ddict->dictSize : 0) ; -} - -/*! ZSTD_getDictID_fromDict() : - * Provides the dictID stored within dictionary. - * if @return == 0, the dictionary is not conformant with Zstandard specification. - * It can still be loaded, but as a content-only dictionary. */ -unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize) -{ - if (dictSize < 8) return 0; - if (MEM_readLE32(dict) != ZSTD_MAGIC_DICTIONARY) return 0; - return MEM_readLE32((const char*)dict + ZSTD_FRAMEIDSIZE); -} - -/*! ZSTD_getDictID_fromDDict() : - * Provides the dictID of the dictionary loaded into `ddict`. - * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. - * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ -unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict) -{ - if (ddict==NULL) return 0; - return ZSTD_getDictID_fromDict(ddict->dictContent, ddict->dictSize); -} - -/*! ZSTD_getDictID_fromFrame() : - * Provides the dictID required to decompresse frame stored within `src`. - * If @return == 0, the dictID could not be decoded. - * This could for one of the following reasons : - * - The frame does not require a dictionary (most common case). - * - The frame was built with dictID intentionally removed. - * Needed dictionary is a hidden information. - * Note : this use case also happens when using a non-conformant dictionary. - * - `srcSize` is too small, and as a result, frame header could not be decoded. - * Note : possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`. - * - This is not a Zstandard frame. - * When identifying the exact failure cause, it's possible to use - * ZSTD_getFrameHeader(), which will provide a more precise error code. */ -unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize) -{ - ZSTD_frameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0 }; - size_t const hError = ZSTD_getFrameHeader(&zfp, src, srcSize); - if (ZSTD_isError(hError)) return 0; - return zfp.dictID; -} - - -/*! ZSTD_decompress_usingDDict() : -* Decompression using a pre-digested Dictionary -* Use dictionary without significant overhead. */ -size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, - const void* src, size_t srcSize, - const ZSTD_DDict* ddict) -{ - /* pass content and size in case legacy frames are encountered */ - return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, - NULL, 0, - ddict); -} - - -/*===================================== -* Streaming decompression -*====================================*/ - -ZSTD_DStream* ZSTD_createDStream(void) -{ - DEBUGLOG(3, "ZSTD_createDStream"); - return ZSTD_createDStream_advanced(ZSTD_defaultCMem); -} - -ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize) -{ - return ZSTD_initStaticDCtx(workspace, workspaceSize); -} - -ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem) -{ - return ZSTD_createDCtx_advanced(customMem); -} - -size_t ZSTD_freeDStream(ZSTD_DStream* zds) -{ - return ZSTD_freeDCtx(zds); -} - - -/* *** Initialization *** */ - -size_t ZSTD_DStreamInSize(void) { return ZSTD_BLOCKSIZE_MAX + ZSTD_blockHeaderSize; } -size_t ZSTD_DStreamOutSize(void) { return ZSTD_BLOCKSIZE_MAX; } - -size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, - const void* dict, size_t dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod, - ZSTD_dictContentType_e dictContentType) -{ - if (dctx->streamStage != zdss_init) return ERROR(stage_wrong); - ZSTD_freeDDict(dctx->ddictLocal); - if (dict && dictSize >= 8) { - dctx->ddictLocal = ZSTD_createDDict_advanced(dict, dictSize, dictLoadMethod, dictContentType, dctx->customMem); - if (dctx->ddictLocal == NULL) return ERROR(memory_allocation); - } else { - dctx->ddictLocal = NULL; - } - dctx->ddict = dctx->ddictLocal; - return 0; -} - -size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) -{ - return ZSTD_DCtx_loadDictionary_advanced(dctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto); -} - -size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize) -{ - return ZSTD_DCtx_loadDictionary_advanced(dctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto); -} - -size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType) -{ - return ZSTD_DCtx_loadDictionary_advanced(dctx, prefix, prefixSize, ZSTD_dlm_byRef, dictContentType); -} - -size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize) -{ - return ZSTD_DCtx_refPrefix_advanced(dctx, prefix, prefixSize, ZSTD_dct_rawContent); -} - - -/* ZSTD_initDStream_usingDict() : - * return : expected size, aka ZSTD_frameHeaderSize_prefix. - * this function cannot fail */ -size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize) -{ - DEBUGLOG(4, "ZSTD_initDStream_usingDict"); - zds->streamStage = zdss_init; - zds->noForwardProgress = 0; - CHECK_F( ZSTD_DCtx_loadDictionary(zds, dict, dictSize) ); - return ZSTD_frameHeaderSize_prefix; -} - -/* note : this variant can't fail */ -size_t ZSTD_initDStream(ZSTD_DStream* zds) -{ - DEBUGLOG(4, "ZSTD_initDStream"); - return ZSTD_initDStream_usingDict(zds, NULL, 0); -} - -/* ZSTD_initDStream_usingDDict() : - * ddict will just be referenced, and must outlive decompression session - * this function cannot fail */ -size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* dctx, const ZSTD_DDict* ddict) -{ - size_t const initResult = ZSTD_initDStream(dctx); - dctx->ddict = ddict; - return initResult; -} - -/* ZSTD_resetDStream() : - * return : expected size, aka ZSTD_frameHeaderSize_prefix. - * this function cannot fail */ -size_t ZSTD_resetDStream(ZSTD_DStream* dctx) -{ - DEBUGLOG(4, "ZSTD_resetDStream"); - dctx->streamStage = zdss_loadHeader; - dctx->lhSize = dctx->inPos = dctx->outStart = dctx->outEnd = 0; - dctx->legacyVersion = 0; - dctx->hostageByte = 0; - return ZSTD_frameHeaderSize_prefix; -} - -size_t ZSTD_setDStreamParameter(ZSTD_DStream* dctx, - ZSTD_DStreamParameter_e paramType, unsigned paramValue) -{ - if (dctx->streamStage != zdss_init) return ERROR(stage_wrong); - switch(paramType) - { - default : return ERROR(parameter_unsupported); - case DStream_p_maxWindowSize : - DEBUGLOG(4, "setting maxWindowSize = %u KB", paramValue >> 10); - dctx->maxWindowSize = paramValue ? paramValue : (U32)(-1); - break; - } - return 0; -} - -size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict) -{ - if (dctx->streamStage != zdss_init) return ERROR(stage_wrong); - dctx->ddict = ddict; - return 0; -} - -size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize) -{ - if (dctx->streamStage != zdss_init) return ERROR(stage_wrong); - dctx->maxWindowSize = maxWindowSize; - return 0; -} - -size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format) -{ - DEBUGLOG(4, "ZSTD_DCtx_setFormat : %u", (unsigned)format); - if (dctx->streamStage != zdss_init) return ERROR(stage_wrong); - dctx->format = format; - return 0; -} - - -size_t ZSTD_sizeof_DStream(const ZSTD_DStream* dctx) -{ - return ZSTD_sizeof_DCtx(dctx); -} - -size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize) -{ - size_t const blockSize = (size_t) MIN(windowSize, ZSTD_BLOCKSIZE_MAX); - unsigned long long const neededRBSize = windowSize + blockSize + (WILDCOPY_OVERLENGTH * 2); - unsigned long long const neededSize = MIN(frameContentSize, neededRBSize); - size_t const minRBSize = (size_t) neededSize; - if ((unsigned long long)minRBSize != neededSize) return ERROR(frameParameter_windowTooLarge); - return minRBSize; -} - -size_t ZSTD_estimateDStreamSize(size_t windowSize) -{ - size_t const blockSize = MIN(windowSize, ZSTD_BLOCKSIZE_MAX); - size_t const inBuffSize = blockSize; /* no block can be larger */ - size_t const outBuffSize = ZSTD_decodingBufferSize_min(windowSize, ZSTD_CONTENTSIZE_UNKNOWN); - return ZSTD_estimateDCtxSize() + inBuffSize + outBuffSize; -} - -size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize) -{ - U32 const windowSizeMax = 1U << ZSTD_WINDOWLOG_MAX; /* note : should be user-selectable */ - ZSTD_frameHeader zfh; - size_t const err = ZSTD_getFrameHeader(&zfh, src, srcSize); - if (ZSTD_isError(err)) return err; - if (err>0) return ERROR(srcSize_wrong); - if (zfh.windowSize > windowSizeMax) - return ERROR(frameParameter_windowTooLarge); - return ZSTD_estimateDStreamSize((size_t)zfh.windowSize); -} - - -/* ***** Decompression ***** */ - -MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize) -{ - size_t const length = MIN(dstCapacity, srcSize); - memcpy(dst, src, length); - return length; -} - - -size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input) -{ - const char* const istart = (const char*)(input->src) + input->pos; - const char* const iend = (const char*)(input->src) + input->size; - const char* ip = istart; - char* const ostart = (char*)(output->dst) + output->pos; - char* const oend = (char*)(output->dst) + output->size; - char* op = ostart; - U32 someMoreWork = 1; - - DEBUGLOG(5, "ZSTD_decompressStream"); - if (input->pos > input->size) { /* forbidden */ - DEBUGLOG(5, "in: pos: %u vs size: %u", - (U32)input->pos, (U32)input->size); - return ERROR(srcSize_wrong); - } - if (output->pos > output->size) { /* forbidden */ - DEBUGLOG(5, "out: pos: %u vs size: %u", - (U32)output->pos, (U32)output->size); - return ERROR(dstSize_tooSmall); - } - DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos)); - - while (someMoreWork) { - switch(zds->streamStage) - { - case zdss_init : - DEBUGLOG(5, "stage zdss_init => transparent reset "); - ZSTD_resetDStream(zds); /* transparent reset on starting decoding a new frame */ - /* fall-through */ - - case zdss_loadHeader : - DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip)); -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) - if (zds->legacyVersion) { - /* legacy support is incompatible with static dctx */ - if (zds->staticSize) return ERROR(memory_allocation); - { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input); - if (hint==0) zds->streamStage = zdss_init; - return hint; - } } -#endif - { size_t const hSize = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format); - DEBUGLOG(5, "header size : %u", (U32)hSize); - if (ZSTD_isError(hSize)) { -#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) - U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart); - if (legacyVersion) { - const void* const dict = zds->ddict ? zds->ddict->dictContent : NULL; - size_t const dictSize = zds->ddict ? zds->ddict->dictSize : 0; - DEBUGLOG(5, "ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion); - /* legacy support is incompatible with static dctx */ - if (zds->staticSize) return ERROR(memory_allocation); - CHECK_F(ZSTD_initLegacyStream(&zds->legacyContext, - zds->previousLegacyVersion, legacyVersion, - dict, dictSize)); - zds->legacyVersion = zds->previousLegacyVersion = legacyVersion; - { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion, output, input); - if (hint==0) zds->streamStage = zdss_init; /* or stay in stage zdss_loadHeader */ - return hint; - } } -#endif - return hSize; /* error */ - } - if (hSize != 0) { /* need more input */ - size_t const toLoad = hSize - zds->lhSize; /* if hSize!=0, hSize > zds->lhSize */ - size_t const remainingInput = (size_t)(iend-ip); - assert(iend >= ip); - if (toLoad > remainingInput) { /* not enough input to load full header */ - if (remainingInput > 0) { - memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput); - zds->lhSize += remainingInput; - } - input->pos = input->size; - return (MAX(ZSTD_frameHeaderSize_min, hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */ - } - assert(ip != NULL); - memcpy(zds->headerBuffer + zds->lhSize, ip, toLoad); zds->lhSize = hSize; ip += toLoad; - break; - } } - - /* check for single-pass mode opportunity */ - if (zds->fParams.frameContentSize && zds->fParams.windowSize /* skippable frame if == 0 */ - && (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) { - size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart); - if (cSize <= (size_t)(iend-istart)) { - /* shortcut : using single-pass mode */ - size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, zds->ddict); - if (ZSTD_isError(decompressedSize)) return decompressedSize; - DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()") - ip = istart + cSize; - op += decompressedSize; - zds->expected = 0; - zds->streamStage = zdss_init; - someMoreWork = 0; - break; - } } - - /* Consume header (see ZSTDds_decodeFrameHeader) */ - DEBUGLOG(4, "Consume header"); - CHECK_F(ZSTD_decompressBegin_usingDDict(zds, zds->ddict)); - - if ((MEM_readLE32(zds->headerBuffer) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */ - zds->expected = MEM_readLE32(zds->headerBuffer + ZSTD_FRAMEIDSIZE); - zds->stage = ZSTDds_skipFrame; - } else { - CHECK_F(ZSTD_decodeFrameHeader(zds, zds->headerBuffer, zds->lhSize)); - zds->expected = ZSTD_blockHeaderSize; - zds->stage = ZSTDds_decodeBlockHeader; - } - - /* control buffer memory usage */ - DEBUGLOG(4, "Control max memory usage (%u KB <= max %u KB)", - (U32)(zds->fParams.windowSize >>10), - (U32)(zds->maxWindowSize >> 10) ); - zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN); - if (zds->fParams.windowSize > zds->maxWindowSize) return ERROR(frameParameter_windowTooLarge); - - /* Adapt buffer sizes to frame header instructions */ - { size_t const neededInBuffSize = MAX(zds->fParams.blockSizeMax, 4 /* frame checksum */); - size_t const neededOutBuffSize = ZSTD_decodingBufferSize_min(zds->fParams.windowSize, zds->fParams.frameContentSize); - if ((zds->inBuffSize < neededInBuffSize) || (zds->outBuffSize < neededOutBuffSize)) { - size_t const bufferSize = neededInBuffSize + neededOutBuffSize; - DEBUGLOG(4, "inBuff : from %u to %u", - (U32)zds->inBuffSize, (U32)neededInBuffSize); - DEBUGLOG(4, "outBuff : from %u to %u", - (U32)zds->outBuffSize, (U32)neededOutBuffSize); - if (zds->staticSize) { /* static DCtx */ - DEBUGLOG(4, "staticSize : %u", (U32)zds->staticSize); - assert(zds->staticSize >= sizeof(ZSTD_DCtx)); /* controlled at init */ - if (bufferSize > zds->staticSize - sizeof(ZSTD_DCtx)) - return ERROR(memory_allocation); - } else { - ZSTD_free(zds->inBuff, zds->customMem); - zds->inBuffSize = 0; - zds->outBuffSize = 0; - zds->inBuff = (char*)ZSTD_malloc(bufferSize, zds->customMem); - if (zds->inBuff == NULL) return ERROR(memory_allocation); - } - zds->inBuffSize = neededInBuffSize; - zds->outBuff = zds->inBuff + zds->inBuffSize; - zds->outBuffSize = neededOutBuffSize; - } } - zds->streamStage = zdss_read; - /* fall-through */ - - case zdss_read: - DEBUGLOG(5, "stage zdss_read"); - { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds); - DEBUGLOG(5, "neededInSize = %u", (U32)neededInSize); - if (neededInSize==0) { /* end of frame */ - zds->streamStage = zdss_init; - someMoreWork = 0; - break; - } - if ((size_t)(iend-ip) >= neededInSize) { /* decode directly from src */ - int const isSkipFrame = ZSTD_isSkipFrame(zds); - size_t const decodedSize = ZSTD_decompressContinue(zds, - zds->outBuff + zds->outStart, (isSkipFrame ? 0 : zds->outBuffSize - zds->outStart), - ip, neededInSize); - if (ZSTD_isError(decodedSize)) return decodedSize; - ip += neededInSize; - if (!decodedSize && !isSkipFrame) break; /* this was just a header */ - zds->outEnd = zds->outStart + decodedSize; - zds->streamStage = zdss_flush; - break; - } } - if (ip==iend) { someMoreWork = 0; break; } /* no more input */ - zds->streamStage = zdss_load; - /* fall-through */ - - case zdss_load: - { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds); - size_t const toLoad = neededInSize - zds->inPos; - int const isSkipFrame = ZSTD_isSkipFrame(zds); - size_t loadedSize; - if (isSkipFrame) { - loadedSize = MIN(toLoad, (size_t)(iend-ip)); - } else { - if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */ - loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip); - } - ip += loadedSize; - zds->inPos += loadedSize; - if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */ - - /* decode loaded input */ - { size_t const decodedSize = ZSTD_decompressContinue(zds, - zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart, - zds->inBuff, neededInSize); - if (ZSTD_isError(decodedSize)) return decodedSize; - zds->inPos = 0; /* input is consumed */ - if (!decodedSize && !isSkipFrame) { zds->streamStage = zdss_read; break; } /* this was just a header */ - zds->outEnd = zds->outStart + decodedSize; - } } - zds->streamStage = zdss_flush; - /* fall-through */ - - case zdss_flush: - { size_t const toFlushSize = zds->outEnd - zds->outStart; - size_t const flushedSize = ZSTD_limitCopy(op, oend-op, zds->outBuff + zds->outStart, toFlushSize); - op += flushedSize; - zds->outStart += flushedSize; - if (flushedSize == toFlushSize) { /* flush completed */ - zds->streamStage = zdss_read; - if ( (zds->outBuffSize < zds->fParams.frameContentSize) - && (zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize) ) { - DEBUGLOG(5, "restart filling outBuff from beginning (left:%i, needed:%u)", - (int)(zds->outBuffSize - zds->outStart), - (U32)zds->fParams.blockSizeMax); - zds->outStart = zds->outEnd = 0; - } - break; - } } - /* cannot complete flush */ - someMoreWork = 0; - break; - - default: return ERROR(GENERIC); /* impossible */ - } } - - /* result */ - input->pos = (size_t)(ip - (const char*)(input->src)); - output->pos = (size_t)(op - (char*)(output->dst)); - if ((ip==istart) && (op==ostart)) { /* no forward progress */ - zds->noForwardProgress ++; - if (zds->noForwardProgress >= ZSTD_NO_FORWARD_PROGRESS_MAX) { - if (op==oend) return ERROR(dstSize_tooSmall); - if (ip==iend) return ERROR(srcSize_wrong); - assert(0); - } - } else { - zds->noForwardProgress = 0; - } - { size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zds); - if (!nextSrcSizeHint) { /* frame fully decoded */ - if (zds->outEnd == zds->outStart) { /* output fully flushed */ - if (zds->hostageByte) { - if (input->pos >= input->size) { - /* can't release hostage (not present) */ - zds->streamStage = zdss_read; - return 1; - } - input->pos++; /* release hostage */ - } /* zds->hostageByte */ - return 0; - } /* zds->outEnd == zds->outStart */ - if (!zds->hostageByte) { /* output not fully flushed; keep last byte as hostage; will be released when all output is flushed */ - input->pos--; /* note : pos > 0, otherwise, impossible to finish reading last block */ - zds->hostageByte=1; - } - return 1; - } /* nextSrcSizeHint==0 */ - nextSrcSizeHint += ZSTD_blockHeaderSize * (ZSTD_nextInputType(zds) == ZSTDnit_block); /* preload header of next block */ - assert(zds->inPos <= nextSrcSizeHint); - nextSrcSizeHint -= zds->inPos; /* part already loaded*/ - return nextSrcSizeHint; - } -} - - -size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input) -{ - return ZSTD_decompressStream(dctx, output, input); -} - -size_t ZSTD_decompress_generic_simpleArgs ( - ZSTD_DCtx* dctx, - void* dst, size_t dstCapacity, size_t* dstPos, - const void* src, size_t srcSize, size_t* srcPos) -{ - ZSTD_outBuffer output = { dst, dstCapacity, *dstPos }; - ZSTD_inBuffer input = { src, srcSize, *srcPos }; - /* ZSTD_compress_generic() will check validity of dstPos and srcPos */ - size_t const cErr = ZSTD_decompress_generic(dctx, &output, &input); - *dstPos = output.pos; - *srcPos = input.pos; - return cErr; -} - -void ZSTD_DCtx_reset(ZSTD_DCtx* dctx) -{ - (void)ZSTD_initDStream(dctx); - dctx->format = ZSTD_f_zstd1; - dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT; -} diff --git a/grub-core/lib/zstd/zstd_errors.h b/grub-core/lib/zstd/zstd_errors.h deleted file mode 100644 index 57533f286..000000000 --- a/grub-core/lib/zstd/zstd_errors.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -#ifndef ZSTD_ERRORS_H_398273423 -#define ZSTD_ERRORS_H_398273423 - -#if defined (__cplusplus) -extern "C" { -#endif - -/*===== dependency =====*/ -#include /* size_t */ - - -/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */ -#ifndef ZSTDERRORLIB_VISIBILITY -# if defined(__GNUC__) && (__GNUC__ >= 4) -# define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default"))) -# else -# define ZSTDERRORLIB_VISIBILITY -# endif -#endif -#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) -# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY -#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) -# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ -#else -# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY -#endif - -/*-********************************************* - * Error codes list - *-********************************************* - * Error codes _values_ are pinned down since v1.3.1 only. - * Therefore, don't rely on values if you may link to any version < v1.3.1. - * - * Only values < 100 are considered stable. - * - * note 1 : this API shall be used with static linking only. - * dynamic linking is not yet officially supported. - * note 2 : Prefer relying on the enum than on its value whenever possible - * This is the only supported way to use the error list < v1.3.1 - * note 3 : ZSTD_isError() is always correct, whatever the library version. - **********************************************/ -typedef enum { - ZSTD_error_no_error = 0, - ZSTD_error_GENERIC = 1, - ZSTD_error_prefix_unknown = 10, - ZSTD_error_version_unsupported = 12, - ZSTD_error_frameParameter_unsupported = 14, - ZSTD_error_frameParameter_windowTooLarge = 16, - ZSTD_error_corruption_detected = 20, - ZSTD_error_checksum_wrong = 22, - ZSTD_error_dictionary_corrupted = 30, - ZSTD_error_dictionary_wrong = 32, - ZSTD_error_dictionaryCreation_failed = 34, - ZSTD_error_parameter_unsupported = 40, - ZSTD_error_parameter_outOfBound = 42, - ZSTD_error_tableLog_tooLarge = 44, - ZSTD_error_maxSymbolValue_tooLarge = 46, - ZSTD_error_maxSymbolValue_tooSmall = 48, - ZSTD_error_stage_wrong = 60, - ZSTD_error_init_missing = 62, - ZSTD_error_memory_allocation = 64, - ZSTD_error_workSpace_tooSmall= 66, - ZSTD_error_dstSize_tooSmall = 70, - ZSTD_error_srcSize_wrong = 72, - /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */ - ZSTD_error_frameIndex_tooLarge = 100, - ZSTD_error_seekableIO = 102, - ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */ -} ZSTD_ErrorCode; - -/*! ZSTD_getErrorCode() : - convert a `size_t` function result into a `ZSTD_ErrorCode` enum type, - which can be used to compare with enum list published above */ -ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); -ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */ - - -#if defined (__cplusplus) -} -#endif - -#endif /* ZSTD_ERRORS_H_398273423 */ diff --git a/grub-core/lib/zstd/zstd_internal.h b/grub-core/lib/zstd/zstd_internal.h deleted file mode 100644 index e75adfa61..000000000 --- a/grub-core/lib/zstd/zstd_internal.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -#ifndef ZSTD_CCOMMON_H_MODULE -#define ZSTD_CCOMMON_H_MODULE - -/* this module contains definitions which must be identical - * across compression, decompression and dictBuilder. - * It also contains a few functions useful to at least 2 of them - * and which benefit from being inlined */ - -/*-************************************* -* Dependencies -***************************************/ -#include "compiler.h" -#include "mem.h" -#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */ -#include "error_private.h" -#define ZSTD_STATIC_LINKING_ONLY -#include "zstd.h" -#define FSE_STATIC_LINKING_ONLY -#include "fse.h" -#define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#ifndef XXH_STATIC_LINKING_ONLY -# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ -#endif -#include "xxhash.h" /* XXH_reset, update, digest */ - - -#if defined (__cplusplus) -extern "C" { -#endif - -/* ---- static assert (debug) --- */ -#define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) - - -/*-************************************* -* shared macros -***************************************/ -#undef MIN -#undef MAX -#define MIN(a,b) ((a)<(b) ? (a) : (b)) -#define MAX(a,b) ((a)>(b) ? (a) : (b)) -#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */ -#define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */ - - -/*-************************************* -* Common constants -***************************************/ -#define ZSTD_OPT_NUM (1<<12) - -#define ZSTD_REP_NUM 3 /* number of repcodes */ -#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1) -static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 }; - -#define KB *(1 <<10) -#define MB *(1 <<20) -#define GB *(1U<<30) - -#define BIT7 128 -#define BIT6 64 -#define BIT5 32 -#define BIT4 16 -#define BIT1 2 -#define BIT0 1 - -#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10 -#define ZSTD_WINDOWLOG_DEFAULTMAX 27 /* Default maximum allowed window log */ -static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 }; -static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 }; - -#define ZSTD_FRAMEIDSIZE 4 /* magic number size */ - -#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */ -static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE; -typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e; - -#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */ -#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */ - -#define HufLog 12 -typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e; - -#define LONGNBSEQ 0x7F00 - -#define MINMATCH 3 - -#define Litbits 8 -#define MaxLit ((1<= 3) /* GCC Intrinsic */ - return 31 - __builtin_clz(val); -# else /* Software version */ - static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; - U32 v = val; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return DeBruijnClz[(v * 0x07C4ACDDU) >> 27]; -# endif - } -} - - -/* ZSTD_invalidateRepCodes() : - * ensures next compression will not use repcodes from previous block. - * Note : only works with regular variant; - * do not use with extDict variant ! */ -void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); /* zstdmt, adaptive_compression (shouldn't get this definition from here) */ - - -typedef struct { - blockType_e blockType; - U32 lastBlock; - U32 origSize; -} blockProperties_t; - -/*! ZSTD_getcBlockSize() : - * Provides the size of compressed block from block header `src` */ -/* Used by: decompress, fullbench (does not get its definition from here) */ -size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, - blockProperties_t* bpPtr); - -#if defined (__cplusplus) -} -#endif - -#endif /* ZSTD_CCOMMON_H_MODULE */ diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c index d70c17486..5b39f02bb 100644 --- a/grub-core/loader/arm/linux.c +++ b/grub-core/loader/arm/linux.c @@ -28,7 +28,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -43,18 +42,21 @@ static grub_size_t linux_size; static char *linux_args; static grub_uint32_t machine_type; -static const void *current_fdt; +static void *fdt_addr; typedef void (*kernel_entry_t) (int, unsigned long, void *); +#define LINUX_ZIMAGE_OFFSET 0x24 +#define LINUX_ZIMAGE_MAGIC 0x016f2818 + #define LINUX_PHYS_OFFSET (0x00008000) -#define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x03000000) +#define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000) #define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000) static grub_size_t -get_atag_size (const grub_uint32_t *atag) +get_atag_size (grub_uint32_t *atag) { - const grub_uint32_t *atag0 = atag; + grub_uint32_t *atag0 = atag; while (atag[0] && atag[1]) atag += atag[0]; return atag - atag0; @@ -66,11 +68,10 @@ get_atag_size (const grub_uint32_t *atag) * Merges in command line parameters and sets up initrd addresses. */ static grub_err_t -linux_prepare_atag (void *target_atag) +linux_prepare_atag (void) { - const grub_uint32_t *atag_orig = (const grub_uint32_t *) current_fdt; - grub_uint32_t *tmp_atag, *to; - const grub_uint32_t *from; + grub_uint32_t *atag_orig = (grub_uint32_t *) fdt_addr; + grub_uint32_t *tmp_atag, *from, *to; grub_size_t tmp_size; grub_size_t arg_size = grub_strlen (linux_args); char *cmdline_orig = NULL; @@ -78,7 +79,7 @@ linux_prepare_atag (void *target_atag) /* some place for cmdline, initrd and terminator. */ tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; - tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); + tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); if (!tmp_atag) return grub_errno; @@ -141,7 +142,7 @@ linux_prepare_atag (void *target_atag) to += 2; /* Copy updated FDT to its launch location */ - grub_memcpy (target_atag, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag)); + grub_memcpy (atag_orig, tmp_atag, sizeof (grub_uint32_t) * (to - tmp_atag)); grub_free (tmp_atag); grub_dprintf ("loader", "ATAG updated for Linux boot\n"); @@ -155,19 +156,19 @@ linux_prepare_atag (void *target_atag) * Merges in command line parameters and sets up initrd addresses. */ static grub_err_t -linux_prepare_fdt (void *target_fdt) +linux_prepare_fdt (void) { int node; int retval; int tmp_size; void *tmp_fdt; - tmp_size = grub_fdt_get_totalsize (current_fdt) + 0x100 + grub_strlen (linux_args); + tmp_size = grub_fdt_get_totalsize (fdt_addr) + 0x100 + grub_strlen (linux_args); tmp_fdt = grub_malloc (tmp_size); if (!tmp_fdt) return grub_errno; - grub_memcpy (tmp_fdt, current_fdt, grub_fdt_get_totalsize (current_fdt)); + grub_memcpy (tmp_fdt, fdt_addr, grub_fdt_get_totalsize (fdt_addr)); grub_fdt_set_totalsize (tmp_fdt, tmp_size); /* Find or create '/chosen' node */ @@ -208,7 +209,7 @@ linux_prepare_fdt (void *target_fdt) } /* Copy updated FDT to its launch location */ - grub_memcpy (target_fdt, tmp_fdt, tmp_size); + grub_memcpy (fdt_addr, tmp_fdt, tmp_size); grub_free (tmp_fdt); grub_dprintf ("loader", "FDT updated for Linux boot\n"); @@ -225,17 +226,16 @@ linux_boot (void) { kernel_entry_t linuxmain; int fdt_valid, atag_valid; - void *target_fdt = 0; - fdt_valid = (current_fdt && grub_fdt_check_header_nosize (current_fdt) == 0); - atag_valid = ((((const grub_uint16_t *) current_fdt)[3] & ~3) == 0x5440 - && *((const grub_uint32_t *) current_fdt)); + fdt_valid = (fdt_addr && grub_fdt_check_header_nosize (fdt_addr) == 0); + atag_valid = ((((grub_uint16_t *) fdt_addr)[3] & ~3) == 0x5440 + && *((grub_uint32_t *) fdt_addr)); grub_dprintf ("loader", "atag: %p, %x, %x, %s, %s\n", - current_fdt, - ((const grub_uint16_t *) current_fdt)[3], - *((const grub_uint32_t *) current_fdt), - (const char *) current_fdt, - (const char *) current_fdt + 1); + fdt_addr, + ((grub_uint16_t *) fdt_addr)[3], + *((grub_uint32_t *) fdt_addr), + (char *) fdt_addr, + (char *) fdt_addr + 1); if (!fdt_valid && machine_type == GRUB_ARM_MACHINE_TYPE_FDT) return grub_error (GRUB_ERR_FILE_NOT_FOUND, @@ -245,40 +245,23 @@ linux_boot (void) grub_dprintf ("loader", "Kernel at: 0x%x\n", linux_addr); - if (fdt_valid || atag_valid) - { -#ifdef GRUB_MACHINE_EFI - grub_size_t size; - if (fdt_valid) - size = grub_fdt_get_totalsize (current_fdt); - else - size = 4 * get_atag_size (current_fdt); - size += grub_strlen (linux_args) + 256; - target_fdt = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size); - if (!target_fdt) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); -#else - target_fdt = (void *) LINUX_FDT_ADDRESS; -#endif - } - if (fdt_valid) { grub_err_t err; - err = linux_prepare_fdt (target_fdt); + err = linux_prepare_fdt (); if (err) return err; - grub_dprintf ("loader", "FDT @ %p\n", target_fdt); + grub_dprintf ("loader", "FDT @ 0x%p\n", fdt_addr); } else if (atag_valid) { grub_err_t err; - err = linux_prepare_atag (target_fdt); + err = linux_prepare_atag (); if (err) return err; - grub_dprintf ("loader", "ATAG @ %p\n", target_fdt); + grub_dprintf ("loader", "ATAG @ 0x%p\n", fdt_addr); } grub_dprintf ("loader", "Jumping to Linux...\n"); @@ -291,9 +274,18 @@ linux_boot (void) */ linuxmain = (kernel_entry_t) linux_addr; +#ifdef GRUB_MACHINE_EFI + { + grub_err_t err; + err = grub_efi_prepare_platform(); + if (err != GRUB_ERR_NONE) + return err; + } +#endif + grub_arm_disable_caches_mmu (); - linuxmain (0, machine_type, target_fdt); + linuxmain (0, machine_type, fdt_addr); return grub_error (GRUB_ERR_BAD_OS, "Linux call returned"); } @@ -304,12 +296,17 @@ linux_boot (void) static grub_err_t linux_load (const char *filename, grub_file_t file) { - struct linux_arm_kernel_header *lh; int size; size = grub_file_size (file); +#ifdef GRUB_MACHINE_EFI + linux_addr = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_PHYS_OFFSET, size); + if (!linux_addr) + return grub_errno; +#else linux_addr = LINUX_ADDRESS; +#endif grub_dprintf ("loader", "Loading Linux to 0x%08x\n", (grub_addr_t) linux_addr); @@ -321,10 +318,9 @@ linux_load (const char *filename, grub_file_t file) return grub_errno; } - lh = (void *) linux_addr; - - if ((grub_size_t) size > sizeof (*lh) && - lh->magic == GRUB_LINUX_ARM_MAGIC_SIGNATURE) + if (size > LINUX_ZIMAGE_OFFSET + 4 + && *(grub_uint32_t *) (linux_addr + LINUX_ZIMAGE_OFFSET) + == LINUX_ZIMAGE_MAGIC) ; else if (size > 0x8000 && *(grub_uint32_t *) (linux_addr) == 0xea000006 && machine_type == GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI) @@ -363,7 +359,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (!file) goto fail; @@ -384,11 +380,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Create kernel command line. */ grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - err = grub_create_loader_cmdline (argc, argv, - linux_args + sizeof (LINUX_IMAGE) - 1, size, - GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - goto fail; + grub_create_loader_cmdline (argc, argv, + linux_args + sizeof (LINUX_IMAGE) - 1, size); return GRUB_ERR_NONE; @@ -408,7 +401,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD); + file = grub_file_open (argv[0]); if (!file) return grub_errno; @@ -417,7 +410,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), size = grub_get_initrd_size (&initrd_ctx); +#ifdef GRUB_MACHINE_EFI + if (initrd_start) + grub_efi_free_pages (initrd_start, + (initrd_end - initrd_start + 0xfff) >> 12); + initrd_start = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_INITRD_PHYS_OFFSET, size); + + if (!initrd_start) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); + goto fail; + } +#else initrd_start = LINUX_INITRD_ADDRESS; +#endif grub_dprintf ("loader", "Loading initrd to 0x%08x\n", (grub_addr_t) initrd_start); @@ -438,26 +444,11 @@ fail: static grub_err_t load_dtb (grub_file_t dtb, int size) { - void *new_fdt = grub_zalloc (size); - if (!new_fdt) - return grub_errno; - grub_dprintf ("loader", "Loading device tree to %p\n", - new_fdt); - if ((grub_file_read (dtb, new_fdt, size) != size) - || (grub_fdt_check_header (new_fdt, size) != 0)) - { - grub_free (new_fdt); - return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree")); - } - - grub_fdt_set_totalsize (new_fdt, size); - current_fdt = new_fdt; - /* - * We've successfully loaded an FDT, so any machine type passed - * from firmware is now obsolete. - */ - machine_type = GRUB_ARM_MACHINE_TYPE_FDT; + if ((grub_file_read (dtb, fdt_addr, size) != size) + || (grub_fdt_check_header (fdt_addr, size) != 0)) + return grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree")); + grub_fdt_set_totalsize (fdt_addr, size); return GRUB_ERR_NONE; } @@ -471,15 +462,44 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)), if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - dtb = grub_file_open (argv[0], GRUB_FILE_TYPE_DEVICE_TREE_IMAGE); + dtb = grub_file_open (argv[0]); if (!dtb) - return grub_errno; + goto out; size = grub_file_size (dtb); if (size == 0) - grub_error (GRUB_ERR_BAD_OS, "empty file"); - else - load_dtb (dtb, size); + { + grub_error (GRUB_ERR_BAD_OS, "empty file"); + goto out; + } + +#ifdef GRUB_MACHINE_EFI + fdt_addr = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size); + if (!fdt_addr) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); + goto out; + } +#else + fdt_addr = (void *) LINUX_FDT_ADDRESS; +#endif + + grub_dprintf ("loader", "Loading device tree to 0x%08x\n", + (grub_addr_t) fdt_addr); + load_dtb (dtb, size); + if (grub_errno != GRUB_ERR_NONE) + { + fdt_addr = NULL; + goto out; + } + + /* + * We've successfully loaded an FDT, so any machine type passed + * from firmware is now obsolete. + */ + machine_type = GRUB_ARM_MACHINE_TYPE_FDT; + + out: grub_file_close (dtb); return grub_errno; @@ -497,7 +517,7 @@ GRUB_MOD_INIT (linux) /* TRANSLATORS: DTB stands for device tree blob. */ 0, N_("Load DTB file.")); my_mod = mod; - current_fdt = (const void *) grub_arm_firmware_get_boot_data (); + fdt_addr = (void *) grub_arm_firmware_get_boot_data (); machine_type = grub_arm_firmware_get_machine_type (); } diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index ef3e9f944..564a75a80 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -27,15 +27,18 @@ #include #include #include -#include -#include #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); +#define GRUB_EFI_PAGE_SHIFT 12 +#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) +#define GRUB_EFI_PE_MAGIC 0x5A4D + +static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; + static grub_dl_t my_mod; static int loaded; @@ -48,31 +51,93 @@ static grub_uint32_t cmdline_size; static grub_addr_t initrd_start; static grub_addr_t initrd_end; -grub_err_t -grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) +static void *loaded_fdt; +static void *fdt; + +static void * +get_firmware_fdt (void) { - if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE) + grub_efi_configuration_table_t *tables; + void *firmware_fdt = NULL; + unsigned int i; + + /* Look for FDT in UEFI config tables. */ + tables = grub_efi_system_table->configuration_table; + + for (i = 0; i < grub_efi_system_table->num_table_entries; i++) + if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) + { + firmware_fdt = tables[i].vendor_table; + grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); + break; + } + + return firmware_fdt; +} + +static void +get_fdt (void) +{ + void *raw_fdt; + grub_size_t size; + + if (fdt) + { + size = BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)); + grub_efi_free_pages ((grub_efi_physical_address_t) fdt, size); + } + + if (loaded_fdt) + raw_fdt = loaded_fdt; + else + raw_fdt = get_firmware_fdt(); + + size = + raw_fdt ? grub_fdt_get_totalsize (raw_fdt) : GRUB_FDT_EMPTY_TREE_SZ; + size += 0x400; + + grub_dprintf ("linux", "allocating %ld bytes for fdt\n", size); + fdt = grub_efi_allocate_pages (0, BYTES_TO_PAGES (size)); + if (!fdt) + return; + + if (raw_fdt) + { + grub_memmove (fdt, raw_fdt, size); + grub_fdt_set_totalsize (fdt, size); + } + else + { + grub_fdt_create_empty_tree (fdt, size); + } +} + +static grub_err_t +check_kernel (struct grub_arm64_linux_kernel_header *lh) +{ + if (lh->magic != GRUB_ARM64_LINUX_MAGIC) return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); - if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC) + if ((lh->code0 & 0xffff) != GRUB_EFI_PE_MAGIC) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled")); grub_dprintf ("linux", "UEFI stub kernel:\n"); + grub_dprintf ("linux", "text_offset = 0x%012llx\n", + (long long unsigned) lh->text_offset); grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset); return GRUB_ERR_NONE; } static grub_err_t -finalize_params_linux (void) +finalize_params (void) { + grub_efi_boot_services_t *b; + grub_efi_status_t status; int node, retval; - void *fdt; - - fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); - + get_fdt (); if (!fdt) goto failure; @@ -86,8 +151,8 @@ finalize_params_linux (void) /* Set initrd info */ if (initrd_start && initrd_end > initrd_start) { - grub_dprintf ("linux", "Initrd @ %p-%p\n", - (void *) initrd_start, (void *) initrd_end); + grub_dprintf ("linux", "Initrd @ 0x%012lx-0x%012lx\n", + initrd_start, initrd_end); retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", initrd_start); @@ -99,26 +164,97 @@ finalize_params_linux (void) goto failure; } - if (grub_fdt_install() != GRUB_ERR_NONE) + b = grub_efi_system_table->boot_services; + status = b->install_configuration_table (&fdt_guid, fdt); + if (status != GRUB_EFI_SUCCESS) goto failure; + grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", + fdt); + return GRUB_ERR_NONE; failure: - grub_fdt_unload(); + grub_efi_free_pages ((grub_efi_physical_address_t) fdt, + BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt))); + fdt = NULL; return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); } -grub_err_t -grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) +static grub_err_t +grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_file_t dtb; + void *blob = NULL; + int size; + + if (!loaded) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("you need to load the kernel first")); + return GRUB_ERR_BAD_OS; + } + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); + + if (loaded_fdt) + grub_free (loaded_fdt); + loaded_fdt = NULL; + + dtb = grub_file_open (argv[0]); + if (!dtb) + goto out; + + size = grub_file_size (dtb); + blob = grub_malloc (size); + if (!blob) + goto out; + + if (grub_file_read (dtb, blob, size) < size) + { + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); + goto out; + } + + if (grub_fdt_check_header (blob, size) != 0) + { + grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree")); + goto out; + } + +out: + if (dtb) + grub_file_close (dtb); + + if (blob) + { + if (grub_errno == GRUB_ERR_NONE) + loaded_fdt = blob; + else + grub_free (blob); + } + + return grub_errno; +} + +static grub_err_t +grub_linux_boot (void) { grub_efi_memory_mapped_device_path_t *mempath; grub_efi_handle_t image_handle; grub_efi_boot_services_t *b; grub_efi_status_t status; + grub_err_t retval; grub_efi_loaded_image_t *loaded_image; int len; + retval = finalize_params(); + if (retval != GRUB_ERR_NONE) + return retval; + mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); if (!mempath) return grub_errno; @@ -127,8 +263,8 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); mempath[0].memory_type = GRUB_EFI_LOADER_DATA; - mempath[0].start_address = addr; - mempath[0].end_address = addr + size; + mempath[0].start_address = (grub_addr_t) kernel_addr; + mempath[0].end_address = (grub_addr_t) kernel_addr + kernel_size; mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; @@ -137,46 +273,37 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) b = grub_efi_system_table->boot_services; status = b->load_image (0, grub_efi_image_handle, (grub_efi_device_path_t *) mempath, - (void *) addr, size, &image_handle); + kernel_addr, kernel_size, &image_handle); if (status != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); - grub_dprintf ("linux", "linux command line: '%s'\n", args); + grub_dprintf ("linux", "linux command line: '%s'\n", linux_args); /* Convert command line to UCS-2 */ loaded_image = grub_efi_get_loaded_image (image_handle); loaded_image->load_options_size = len = - (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); + (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); loaded_image->load_options = - grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + grub_efi_allocate_pages (0, + BYTES_TO_PAGES (loaded_image->load_options_size)); if (!loaded_image->load_options) return grub_errno; loaded_image->load_options_size = 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, - (grub_uint8_t *) args, len, NULL); + (grub_uint8_t *) linux_args, len, NULL); - grub_dprintf ("linux", "starting image %p\n", image_handle); + grub_dprintf("linux", "starting image %p\n", image_handle); status = b->start_image (image_handle, 0, NULL); /* When successful, not reached */ b->unload_image (image_handle); - grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, - GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + grub_efi_free_pages ((grub_efi_physical_address_t) loaded_image->load_options, + BYTES_TO_PAGES (loaded_image->load_options_size)); return grub_errno; } -static grub_err_t -grub_linux_boot (void) -{ - if (finalize_params_linux () != GRUB_ERR_NONE) - return grub_errno; - - return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, - kernel_size, linux_args)); -} - static grub_err_t grub_linux_unload (void) { @@ -184,52 +311,19 @@ grub_linux_unload (void) loaded = 0; if (initrd_start) grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start, - GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start)); + BYTES_TO_PAGES (initrd_end - initrd_start)); initrd_start = initrd_end = 0; grub_free (linux_args); if (kernel_addr) - grub_efi_free_pages ((grub_addr_t) kernel_addr, - GRUB_EFI_BYTES_TO_PAGES (kernel_size)); - grub_fdt_unload (); + grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr, + BYTES_TO_PAGES (kernel_size)); + if (fdt) + grub_efi_free_pages ((grub_efi_physical_address_t) fdt, + BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt))); + return GRUB_ERR_NONE; } -/* - * As per linux/Documentation/arm/Booting - * ARM initrd needs to be covered by kernel linear mapping, - * so place it in the first 512MB of DRAM. - * - * As per linux/Documentation/arm64/booting.txt - * ARM64 initrd needs to be contained entirely within a 1GB aligned window - * of up to 32GB of size that covers the kernel image as well. - * Since the EFI stub loader will attempt to load the kernel near start of - * RAM, place the buffer in the first 32GB of RAM. - */ -#ifdef __arm__ -#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024) -#else /* __aarch64__ */ -#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024) -#endif - -/* - * This function returns a pointer to a legally allocated initrd buffer, - * or NULL if unsuccessful - */ -static void * -allocate_initrd_mem (int initrd_pages) -{ - grub_addr_t max_addr; - - if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) - return NULL; - - max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; - - return grub_efi_allocate_pages_real (max_addr, initrd_pages, - GRUB_EFI_ALLOCATE_MAX_ADDRESS, - GRUB_EFI_LOADER_DATA); -} - static grub_err_t grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) @@ -257,9 +351,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), initrd_size = grub_get_initrd_size (&initrd_ctx); grub_dprintf ("linux", "Loading initrd\n"); - initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size)); - initrd_mem = allocate_initrd_mem (initrd_pages); - + initrd_pages = (BYTES_TO_PAGES (initrd_size)); + initrd_mem = grub_efi_allocate_pages (0, initrd_pages); if (!initrd_mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); @@ -277,7 +370,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), fail: grub_initrd_close (&initrd_ctx); if (initrd_mem && !initrd_start) - grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages); + grub_efi_free_pages ((grub_efi_physical_address_t) initrd_mem, + initrd_pages); return grub_errno; } @@ -287,8 +381,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_file_t file = 0; - struct linux_arch_kernel_header lh; - grub_err_t err; + struct grub_arm64_linux_kernel_header lh; grub_dl_ref (my_mod); @@ -298,7 +391,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (!file) goto fail; @@ -307,15 +400,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) return grub_errno; - if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE) + if (check_kernel (&lh) != GRUB_ERR_NONE) goto fail; grub_loader_unset(); grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); - kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); + kernel_addr = grub_efi_allocate_pages (0, BYTES_TO_PAGES (kernel_size)); grub_dprintf ("linux", "kernel numpages: %lld\n", - (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); + (long long) BYTES_TO_PAGES (kernel_size)); if (!kernel_addr) { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); @@ -341,12 +434,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - err = grub_create_loader_cmdline (argc, argv, - linux_args + sizeof (LINUX_IMAGE) - 1, - cmdline_size, - GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - goto fail; + grub_create_loader_cmdline (argc, argv, + linux_args + sizeof (LINUX_IMAGE) - 1, + cmdline_size); if (grub_errno == GRUB_ERR_NONE) { @@ -368,14 +458,14 @@ fail: grub_free (linux_args); if (kernel_addr && !loaded) - grub_efi_free_pages ((grub_addr_t) kernel_addr, - GRUB_EFI_BYTES_TO_PAGES (kernel_size)); + grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr, + BYTES_TO_PAGES (kernel_size)); return grub_errno; } -static grub_command_t cmd_linux, cmd_initrd; +static grub_command_t cmd_linux, cmd_initrd, cmd_devicetree; GRUB_MOD_INIT (linux) { @@ -383,6 +473,9 @@ GRUB_MOD_INIT (linux) N_("Load Linux.")); cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, N_("Load initrd.")); + cmd_devicetree = + grub_register_command ("devicetree", grub_cmd_devicetree, 0, + N_("Load DTB file.")); my_mod = mod; } @@ -390,4 +483,5 @@ GRUB_MOD_FINI (linux) { grub_unregister_command (cmd_linux); grub_unregister_command (cmd_initrd); + grub_unregister_command (cmd_devicetree); } diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c deleted file mode 100644 index 22cc25ecc..000000000 --- a/grub-core/loader/arm64/xen_boot.c +++ /dev/null @@ -1,527 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2014 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* required by struct xen_hypervisor_header */ -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -#define XEN_HYPERVISOR_NAME "xen_hypervisor" -#define MODULE_CUSTOM_COMPATIBLE "multiboot,module" - -/* This maximum size is defined in Power.org ePAPR V1.1 - * https://www.power.org/documentation/epapr-version-1-1/ - * 2.2.1.1 Node Name Requirements - * node-name@unit-address - * 31 + 1(@) + 16(64bit address in hex format) + 1(\0) = 49 - */ -#define FDT_NODE_NAME_MAX_SIZE (49) - -struct compat_string_struct -{ - grub_size_t size; - const char *compat_string; -}; -typedef struct compat_string_struct compat_string_struct_t; -#define FDT_COMPATIBLE(x) {.size = sizeof(x), .compat_string = (x)} - -enum module_type -{ - MODULE_IMAGE, - MODULE_INITRD, - MODULE_XSM, - MODULE_CUSTOM -}; -typedef enum module_type module_type_t; - -struct xen_hypervisor_header -{ - struct linux_arm64_kernel_header efi_head; - - /* This is always PE\0\0. */ - grub_uint8_t signature[GRUB_PE32_SIGNATURE_SIZE]; - /* The COFF file header. */ - struct grub_pe32_coff_header coff_header; - /* The Optional header. */ - struct grub_pe64_optional_header optional_header; -}; - -struct xen_boot_binary -{ - struct xen_boot_binary *next; - struct xen_boot_binary **prev; - int is_hypervisor; - - grub_addr_t start; - grub_size_t size; - grub_size_t align; - - char *cmdline; - int cmdline_size; -}; - -static grub_dl_t my_mod; - -static int loaded; - -static struct xen_boot_binary *xen_hypervisor; -static struct xen_boot_binary *module_head; - -static __inline grub_addr_t -xen_boot_address_align (grub_addr_t start, grub_size_t align) -{ - return (align ? (ALIGN_UP (start, align)) : start); -} - -static grub_err_t -prepare_xen_hypervisor_params (void *xen_boot_fdt) -{ - int chosen_node = 0; - int retval; - - chosen_node = grub_fdt_find_subnode (xen_boot_fdt, 0, "chosen"); - if (chosen_node < 0) - chosen_node = grub_fdt_add_subnode (xen_boot_fdt, 0, "chosen"); - if (chosen_node < 1) - return grub_error (GRUB_ERR_IO, "failed to get chosen node in FDT"); - - /* - * The address and size are always written using 64-bits value. Set - * #address-cells and #size-cells accordingly. - */ - retval = grub_fdt_set_prop32 (xen_boot_fdt, chosen_node, "#address-cells", 2); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to set #address-cells"); - retval = grub_fdt_set_prop32 (xen_boot_fdt, chosen_node, "#size-cells", 2); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to set #size-cells"); - - grub_dprintf ("xen_loader", - "Xen Hypervisor cmdline : %s @ %p size:%d\n", - xen_hypervisor->cmdline, xen_hypervisor->cmdline, - xen_hypervisor->cmdline_size); - - retval = grub_fdt_set_prop (xen_boot_fdt, chosen_node, "bootargs", - xen_hypervisor->cmdline, - xen_hypervisor->cmdline_size); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to install/update FDT"); - - return GRUB_ERR_NONE; -} - -static grub_err_t -prepare_xen_module_params (struct xen_boot_binary *module, void *xen_boot_fdt) -{ - int retval, chosen_node = 0, module_node = 0; - char module_name[FDT_NODE_NAME_MAX_SIZE]; - - retval = grub_snprintf (module_name, FDT_NODE_NAME_MAX_SIZE, "module@%lx", - xen_boot_address_align (module->start, - module->align)); - grub_dprintf ("xen_loader", "Module node name %s \n", module_name); - - if (retval < (int) sizeof ("module@")) - return grub_error (GRUB_ERR_IO, N_("failed to get FDT")); - - chosen_node = grub_fdt_find_subnode (xen_boot_fdt, 0, "chosen"); - if (chosen_node < 0) - chosen_node = grub_fdt_add_subnode (xen_boot_fdt, 0, "chosen"); - if (chosen_node < 1) - return grub_error (GRUB_ERR_IO, "failed to get chosen node in FDT"); - - module_node = - grub_fdt_find_subnode (xen_boot_fdt, chosen_node, module_name); - if (module_node < 0) - module_node = - grub_fdt_add_subnode (xen_boot_fdt, chosen_node, module_name); - - retval = grub_fdt_set_prop (xen_boot_fdt, module_node, "compatible", - MODULE_CUSTOM_COMPATIBLE, sizeof(MODULE_CUSTOM_COMPATIBLE)); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to update FDT"); - - grub_dprintf ("xen_loader", "Module\n"); - - retval = grub_fdt_set_reg64 (xen_boot_fdt, module_node, - xen_boot_address_align (module->start, - module->align), - module->size); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to update FDT"); - - if (module->cmdline && module->cmdline_size > 0) - { - grub_dprintf ("xen_loader", - "Module cmdline : %s @ %p size:%d\n", - module->cmdline, module->cmdline, module->cmdline_size); - - retval = grub_fdt_set_prop (xen_boot_fdt, module_node, "bootargs", - module->cmdline, module->cmdline_size + 1); - if (retval) - return grub_error (GRUB_ERR_IO, "failed to update FDT"); - } - else - { - grub_dprintf ("xen_loader", "Module has no bootargs!\n"); - } - - return GRUB_ERR_NONE; -} - -static grub_err_t -finalize_params_xen_boot (void) -{ - struct xen_boot_binary *module; - void *xen_boot_fdt; - grub_size_t additional_size = 0x1000; - - /* Hypervisor. */ - additional_size += FDT_NODE_NAME_MAX_SIZE + xen_hypervisor->cmdline_size; - FOR_LIST_ELEMENTS (module, module_head) - { - additional_size += 6 * FDT_NODE_NAME_MAX_SIZE + sizeof(MODULE_CUSTOM_COMPATIBLE) - 1 - + module->cmdline_size; - } - - xen_boot_fdt = grub_fdt_load (additional_size); - if (!xen_boot_fdt) - return grub_error (GRUB_ERR_IO, "failed to get FDT"); - - if (xen_hypervisor) - { - if (prepare_xen_hypervisor_params (xen_boot_fdt) != GRUB_ERR_NONE) - goto fail; - } - else - { - grub_dprintf ("xen_loader", "Failed to get Xen Hypervisor info!\n"); - goto fail; - } - - /* Set module params info */ - FOR_LIST_ELEMENTS (module, module_head) - { - if (module->start && module->size > 0) - { - grub_dprintf ("xen_loader", "Module @ 0x%lx size:0x%lx\n", - xen_boot_address_align (module->start, module->align), - module->size); - if (prepare_xen_module_params (module, xen_boot_fdt) != GRUB_ERR_NONE) - goto fail; - } - else - { - grub_dprintf ("xen_loader", "Module info error!\n"); - goto fail; - } - } - - if (grub_fdt_install() == GRUB_ERR_NONE) - return GRUB_ERR_NONE; - -fail: - grub_fdt_unload (); - - return grub_error (GRUB_ERR_IO, "failed to install/update FDT"); -} - - -static grub_err_t -xen_boot (void) -{ - grub_err_t err = finalize_params_xen_boot (); - if (err) - return err; - - return grub_arch_efi_linux_boot_image (xen_hypervisor->start, - xen_hypervisor->size, - xen_hypervisor->cmdline); -} - -static void -single_binary_unload (struct xen_boot_binary *binary) -{ - if (!binary) - return; - - if (binary->start && binary->size > 0) - { - grub_efi_free_pages ((grub_efi_physical_address_t) binary->start, - GRUB_EFI_BYTES_TO_PAGES (binary->size + binary->align)); - } - - if (binary->cmdline && binary->cmdline_size > 0) - { - grub_free (binary->cmdline); - grub_dprintf ("xen_loader", - "Module cmdline memory free @ %p size: %d\n", - binary->cmdline, binary->cmdline_size); - } - - if (!binary->is_hypervisor) - grub_list_remove (GRUB_AS_LIST (binary)); - - grub_dprintf ("xen_loader", - "Module struct memory free @ %p size: 0x%lx\n", - binary, sizeof (binary)); - grub_free (binary); - - return; -} - -static void -all_binaries_unload (void) -{ - struct xen_boot_binary *binary; - - FOR_LIST_ELEMENTS (binary, module_head) - { - single_binary_unload (binary); - } - - if (xen_hypervisor) - single_binary_unload (xen_hypervisor); - - return; -} - -static grub_err_t -xen_unload (void) -{ - loaded = 0; - all_binaries_unload (); - grub_fdt_unload (); - grub_dl_unref (my_mod); - - return GRUB_ERR_NONE; -} - -static void -xen_boot_binary_load (struct xen_boot_binary *binary, grub_file_t file, - int argc, char *argv[]) -{ - binary->size = grub_file_size (file); - grub_dprintf ("xen_loader", "Xen_boot file size: 0x%lx\n", binary->size); - - binary->start - = (grub_addr_t) grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES - (binary->size + - binary->align)); - if (!binary->start) - { - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - return; - } - - grub_dprintf ("xen_loader", "Xen_boot numpages: 0x%lx\n", - GRUB_EFI_BYTES_TO_PAGES (binary->size + binary->align)); - - if (grub_file_read (file, (void *) xen_boot_address_align (binary->start, - binary->align), - binary->size) != (grub_ssize_t) binary->size) - { - single_binary_unload (binary); - grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); - return; - } - - if (argc > 1) - { - binary->cmdline_size = grub_loader_cmdline_size (argc - 1, argv + 1); - binary->cmdline = grub_zalloc (binary->cmdline_size); - if (!binary->cmdline) - { - single_binary_unload (binary); - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); - return; - } - grub_create_loader_cmdline (argc - 1, argv + 1, binary->cmdline, - binary->cmdline_size, - GRUB_VERIFY_KERNEL_CMDLINE); - grub_dprintf ("xen_loader", - "Xen_boot cmdline @ %p %s, size: %d\n", - binary->cmdline, binary->cmdline, binary->cmdline_size); - } - else - { - binary->cmdline_size = 0; - binary->cmdline = NULL; - } - - grub_errno = GRUB_ERR_NONE; - return; -} - -static grub_err_t -grub_cmd_xen_module (grub_command_t cmd __attribute__((unused)), - int argc, char *argv[]) -{ - - struct xen_boot_binary *module = NULL; - grub_file_t file = 0; - int nounzip = 0; - - if (!argc) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - goto fail; - } - - if (grub_strcmp (argv[0], "--nounzip") == 0) - { - argv++; - argc--; - nounzip = 1; - } - - if (!argc) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - goto fail; - } - - if (!loaded) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("you need to load the Xen Hypervisor first")); - goto fail; - } - - module = - (struct xen_boot_binary *) grub_zalloc (sizeof (struct xen_boot_binary)); - if (!module) - return grub_errno; - - module->is_hypervisor = 0; - module->align = 4096; - - grub_dprintf ("xen_loader", "Init module and node info\n"); - - file = grub_file_open (argv[0], GRUB_FILE_TYPE_XEN_MODULE - | (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS - : GRUB_FILE_TYPE_NONE)); - if (!file) - goto fail; - - xen_boot_binary_load (module, file, argc, argv); - if (grub_errno == GRUB_ERR_NONE) - grub_list_push (GRUB_AS_LIST_P (&module_head), GRUB_AS_LIST (module)); - - fail: - if (file) - grub_file_close (file); - if (grub_errno != GRUB_ERR_NONE) - single_binary_unload (module); - - return grub_errno; -} - -static grub_err_t -grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) -{ - struct xen_hypervisor_header sh; - grub_file_t file = NULL; - - grub_dl_ref (my_mod); - - if (!argc) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - goto fail; - } - - file = grub_file_open (argv[0], GRUB_FILE_TYPE_XEN_HYPERVISOR); - if (!file) - goto fail; - - if (grub_file_read (file, &sh, sizeof (sh)) != (long) sizeof (sh)) - goto fail; - if (grub_arch_efi_linux_check_image - ((struct linux_arch_kernel_header *) &sh) != GRUB_ERR_NONE) - goto fail; - grub_file_seek (file, 0); - - /* if another module has called grub_loader_set, - we need to make sure that another module is unloaded properly */ - grub_loader_unset (); - - xen_hypervisor = - (struct xen_boot_binary *) grub_zalloc (sizeof (struct xen_boot_binary)); - if (!xen_hypervisor) - return grub_errno; - - xen_hypervisor->is_hypervisor = 1; - xen_hypervisor->align = (grub_size_t) sh.optional_header.section_alignment; - - xen_boot_binary_load (xen_hypervisor, file, argc, argv); - if (grub_errno == GRUB_ERR_NONE) - { - grub_loader_set (xen_boot, xen_unload, 0); - loaded = 1; - } - -fail: - if (file) - grub_file_close (file); - if (grub_errno != GRUB_ERR_NONE) - { - loaded = 0; - all_binaries_unload (); - grub_dl_unref (my_mod); - } - - return grub_errno; -} - -static grub_command_t cmd_xen_hypervisor; -static grub_command_t cmd_xen_module; - -GRUB_MOD_INIT (xen_boot) -{ - cmd_xen_hypervisor = - grub_register_command ("xen_hypervisor", grub_cmd_xen_hypervisor, 0, - N_("Load a xen hypervisor.")); - cmd_xen_module = - grub_register_command ("xen_module", grub_cmd_xen_module, 0, - N_("Load a xen module.")); - my_mod = mod; -} - -GRUB_MOD_FINI (xen_boot) -{ - grub_unregister_command (cmd_xen_hypervisor); - grub_unregister_command (cmd_xen_module); -} diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index 7b31c3fb9..233237018 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -106,32 +106,23 @@ grub_chainloader_boot (void) return grub_errno; } -static grub_err_t +static void copy_file_path (grub_efi_file_path_device_path_t *fp, const char *str, grub_efi_uint16_t len) { - grub_efi_char16_t *p, *path_name; + grub_efi_char16_t *p; grub_efi_uint16_t size; fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; - path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); - if (!path_name) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to allocate path buffer"); - - size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8, + size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8, (const grub_uint8_t *) str, len, 0); - for (p = path_name; p < path_name + size; p++) + for (p = fp->path_name; p < fp->path_name + size; p++) if (*p == '/') *p = '\\'; - grub_memcpy (fp->path_name, path_name, size * sizeof (*fp->path_name)); - /* File Path is NULL terminated */ - fp->path_name[size++] = '\0'; fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); - grub_free (path_name); - return GRUB_ERR_NONE; } static grub_efi_device_path_t * @@ -157,27 +148,16 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) size = 0; d = dp; - while (d) + while (1) { - grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (d); - - if (len < 4) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "malformed EFI Device Path node has length=%d", len); - return NULL; - } - - size += len; + size += GRUB_EFI_DEVICE_PATH_LENGTH (d); if ((GRUB_EFI_END_ENTIRE_DEVICE_PATH (d))) break; d = GRUB_EFI_NEXT_DEVICE_PATH (d); } - /* File Path is NULL terminated. Allocate space for 2 extra characters */ - /* FIXME why we split path in two components? */ file_path = grub_malloc (size - + ((grub_strlen (dir_start) + 2) + + ((grub_strlen (dir_start) + 1) * GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_efi_char16_t)) + sizeof (grub_efi_file_path_device_path_t) * 2); @@ -190,19 +170,13 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) d = (grub_efi_device_path_t *) ((char *) file_path + ((char *) d - (char *) dp)); grub_efi_print_device_path (d); - if (copy_file_path ((grub_efi_file_path_device_path_t *) d, - dir_start, dir_end - dir_start) != GRUB_ERR_NONE) - { - fail: - grub_free (file_path); - return 0; - } + copy_file_path ((grub_efi_file_path_device_path_t *) d, + dir_start, dir_end - dir_start); /* Fill the file path for the file. */ d = GRUB_EFI_NEXT_DEVICE_PATH (d); - if (copy_file_path ((grub_efi_file_path_device_path_t *) d, - dir_end + 1, grub_strlen (dir_end + 1)) != GRUB_ERR_NONE) - goto fail; + copy_file_path ((grub_efi_file_path_device_path_t *) d, + dir_end + 1, grub_strlen (dir_end + 1)); /* Fill the end of device path nodes. */ d = GRUB_EFI_NEXT_DEVICE_PATH (d); @@ -241,7 +215,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), b = grub_efi_system_table->boot_services; - file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE); + file = grub_file_open (filename); if (! file) goto fail; @@ -376,6 +350,8 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), } loaded_image->device_handle = dev_handle; + grub_file_close (file); + if (argc > 1) { int i, len; @@ -405,9 +381,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), loaded_image->load_options_size = len; } - grub_file_close (file); - grub_device_close (dev); - grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); return 0; diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c deleted file mode 100644 index ee9c5592c..000000000 --- a/grub-core/loader/efi/fdt.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013-2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void *loaded_fdt; -static void *fdt; - -#define FDT_ADDR_CELLS_STRING "#address-cells" -#define FDT_SIZE_CELLS_STRING "#size-cells" -#define FDT_ADDR_SIZE_EXTRA ((2 * grub_fdt_prop_entry_size (sizeof(grub_uint32_t))) + \ - sizeof (FDT_ADDR_CELLS_STRING) + \ - sizeof (FDT_SIZE_CELLS_STRING)) - -void * -grub_fdt_load (grub_size_t additional_size) -{ - void *raw_fdt; - unsigned int size; - - if (fdt) - { - size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)); - grub_efi_free_pages ((grub_addr_t) fdt, size); - } - - if (loaded_fdt) - raw_fdt = loaded_fdt; - else - raw_fdt = grub_efi_get_firmware_fdt(); - - if (raw_fdt) - size = grub_fdt_get_totalsize (raw_fdt); - else - size = GRUB_FDT_EMPTY_TREE_SZ + FDT_ADDR_SIZE_EXTRA; - - size += additional_size; - - grub_dprintf ("linux", "allocating %d bytes for fdt\n", size); - fdt = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (size)); - if (!fdt) - return NULL; - - if (raw_fdt) - { - grub_memmove (fdt, raw_fdt, size - additional_size); - grub_fdt_set_totalsize (fdt, size); - } - else - { - grub_fdt_create_empty_tree (fdt, size); - grub_fdt_set_prop32 (fdt, 0, FDT_ADDR_CELLS_STRING, 2); - grub_fdt_set_prop32 (fdt, 0, FDT_SIZE_CELLS_STRING, 2); - } - return fdt; -} - -grub_err_t -grub_fdt_install (void) -{ - grub_efi_boot_services_t *b; - grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; - grub_efi_status_t status; - - b = grub_efi_system_table->boot_services; - status = b->install_configuration_table (&fdt_guid, fdt); - if (status != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_IO, "failed to install FDT"); - - grub_dprintf ("fdt", "Installed/updated FDT configuration table @ %p\n", - fdt); - return GRUB_ERR_NONE; -} - -void -grub_fdt_unload (void) { - if (!fdt) { - return; - } - grub_efi_free_pages ((grub_addr_t) fdt, - GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt))); - fdt = NULL; -} - -static grub_err_t -grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) -{ - grub_file_t dtb; - void *blob = NULL; - int size; - - if (loaded_fdt) - grub_free (loaded_fdt); - loaded_fdt = NULL; - - /* No arguments means "use firmware FDT". */ - if (argc == 0) - { - return GRUB_ERR_NONE; - } - - dtb = grub_file_open (argv[0], GRUB_FILE_TYPE_DEVICE_TREE_IMAGE); - if (!dtb) - goto out; - - size = grub_file_size (dtb); - blob = grub_malloc (size); - if (!blob) - goto out; - - if (grub_file_read (dtb, blob, size) < size) - { - if (!grub_errno) - grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); - goto out; - } - - if (grub_fdt_check_header (blob, size) != 0) - { - grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree")); - goto out; - } - -out: - if (dtb) - grub_file_close (dtb); - - if (blob) - { - if (grub_errno == GRUB_ERR_NONE) - loaded_fdt = blob; - else - grub_free (blob); - } - - return grub_errno; -} - -static grub_command_t cmd_devicetree; - -GRUB_MOD_INIT (fdt) -{ - cmd_devicetree = - grub_register_command ("devicetree", grub_cmd_devicetree, 0, - N_("Load DTB file.")); -} - -GRUB_MOD_FINI (fdt) -{ - grub_unregister_command (cmd_devicetree); -} diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index f5bf7f89e..8f691e0e2 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -35,8 +35,6 @@ #include #include #include -#include -#include #ifdef GRUB_MACHINE_PCBIOS #include #endif @@ -236,8 +234,7 @@ grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len) { struct bsd_tag *p; for (p = tags; - p && p->type != (FREEBSD_MODINFO_METADATA - | FREEBSD_MODINFOMD_KERNEND); + p->type != (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_KERNEND); p = p->next); if (p) @@ -418,8 +415,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type, grub_addr_t addr, grub_uint32_t size) { const char *name; - grub_err_t err; - name = grub_strrchr (filename, '/'); if (name) name++; @@ -473,9 +468,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type, *(p++) = ' '; } *p = 0; - err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE); - if (err) - return err; } } @@ -581,9 +573,9 @@ freebsd_get_zfs (void) fs = grub_fs_probe (dev); if (!fs) return; - if (!fs->fs_uuid || grub_strcmp (fs->name, "zfs") != 0) + if (!fs->uuid || grub_strcmp (fs->name, "zfs") != 0) return; - err = fs->fs_uuid (dev, &uuid); + err = fs->uuid (dev, &uuid); if (err) return; if (!uuid) @@ -1013,16 +1005,11 @@ grub_netbsd_add_modules (void) struct grub_netbsd_btinfo_modules *mods; unsigned i; grub_err_t err; - grub_size_t sz; for (mod = netbsd_mods; mod; mod = mod->next) modcnt++; - if (grub_mul (modcnt, sizeof (mods->mods[0]), &sz) || - grub_add (sz, sizeof (*mods), &sz)) - return GRUB_ERR_OUT_OF_RANGE; - - mods = grub_malloc (sz); + mods = grub_malloc (sizeof (*mods) + sizeof (mods->mods[0]) * modcnt); if (!mods) return grub_errno; @@ -1469,7 +1456,7 @@ grub_bsd_load (int argc, char *argv[]) goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL); + file = grub_file_open (argv[0]); if (!file) goto fail; @@ -1546,7 +1533,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (err) return err; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -1621,7 +1608,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown disk type name"); - unit = grub_strtoul (arg, &arg, 10); + unit = grub_strtoul (arg, (char **) &arg, 10); if (! (arg && *arg >= 'a' && *arg <= 'z')) return grub_error (GRUB_ERR_BAD_ARGUMENT, "only device specifications of form " @@ -1639,7 +1626,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (ctxt->state[OPENBSD_SERIAL_ARG].set) { struct grub_openbsd_bootarg_console serial; - const char *ptr; + char *ptr; unsigned port = 0; unsigned speed = 9600; @@ -1705,7 +1692,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) { grub_file_t file; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL); + file = grub_file_open (argv[0]); if (! file) return grub_errno; @@ -1741,7 +1728,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (ctxt->state[NETBSD_SERIAL_ARG].set) { struct grub_netbsd_btinfo_serial serial; - const char *ptr; + char *ptr; grub_memset (&serial, 0, sizeof (serial)); grub_strcpy (serial.devname, "com"); @@ -1814,7 +1801,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1901,10 +1888,6 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)), grub_err_t err; void *src; - if (! grub_loader_is_loaded ()) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("you need to load the kernel first")); - if (kernel_type != KERNEL_TYPE_FREEBSD) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no FreeBSD loaded"); @@ -1919,7 +1902,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)), return 0; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE); + file = grub_file_open (argv[0]); if ((!file) || (!file->size)) goto fail; @@ -1970,7 +1953,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type) void *src; grub_err_t err; - file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE); + file = grub_file_open (filename); if ((!file) || (!file->size)) goto fail; @@ -2008,10 +1991,6 @@ grub_cmd_netbsd_module (grub_command_t cmd, { grub_uint32_t type; - if (! grub_loader_is_loaded ()) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("you need to load the kernel first")); - if (kernel_type != KERNEL_TYPE_NETBSD) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no NetBSD loaded"); @@ -2060,7 +2039,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)), return 0; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF); + file = grub_file_open (argv[0]); if (!file) return grub_errno; if (!file->size) @@ -2090,17 +2069,13 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)), if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - if (! grub_loader_is_loaded ()) - return grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("you need to load the kernel first")); - if (kernel_type != KERNEL_TYPE_OPENBSD) return grub_error (GRUB_ERR_BAD_OS, "no kOpenBSD loaded"); if (!openbsd_ramdisk.max_size) return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk"); - file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK); + file = grub_file_open (args[0]); if (! file) return grub_errno; diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c index a8d8bf7da..9e36cd4b6 100644 --- a/grub-core/loader/i386/bsdXX.c +++ b/grub-core/loader/i386/bsdXX.c @@ -48,15 +48,15 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); - *shdr = grub_calloc (e->e_shnum, e->e_shentsize); + *shdr = grub_malloc (e->e_shnum * e->e_shentsize); if (! *shdr) return grub_errno; if (grub_file_seek (file, e->e_shoff) == (grub_off_t) -1) return grub_errno; - if (grub_file_read (file, *shdr, (grub_uint32_t) e->e_shnum * e->e_shentsize) - != (grub_ssize_t) ((grub_uint32_t) e->e_shnum * e->e_shentsize)) + if (grub_file_read (file, *shdr, e->e_shnum * e->e_shentsize) + != e->e_shnum * e->e_shentsize) { if (grub_errno) return grub_errno; @@ -84,11 +84,11 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator, grub_size_t chunk_size = 0; void *chunk_src; - curload = module = ALIGN_PAGE (*kern_end); - err = read_headers (file, argv[0], &e, &shdr); if (err) - goto out; + return err; + + curload = module = ALIGN_PAGE (*kern_end); for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize); @@ -109,7 +109,7 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator, err = grub_relocator_alloc_chunk_addr (relocator, &ch, module, chunk_size); if (err) - goto out; + return err; chunk_src = get_virtual_current_address (ch); } @@ -135,7 +135,7 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator, err = load (file, argv[0], (grub_uint8_t *) chunk_src + curload - *kern_end, s->sh_offset, s->sh_size); if (err) - goto out; + return err; break; case SHT_NOBITS: grub_memset ((grub_uint8_t *) chunk_src + curload - *kern_end, 0, @@ -159,8 +159,6 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (struct grub_relocator *relocator, | FREEBSD_MODINFOMD_SHDR, shdr, e.e_shnum * e.e_shentsize); -out: - grub_free (shdr); return err; } @@ -179,11 +177,11 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, grub_size_t chunk_size = 0; void *chunk_src; - curload = module = ALIGN_PAGE (*kern_end); - err = read_headers (file, argv[0], &e, &shdr); if (err) - goto out; + return err; + + curload = module = ALIGN_PAGE (*kern_end); for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize); @@ -200,8 +198,8 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, if (chunk_size < sizeof (e)) chunk_size = sizeof (e); - chunk_size += (grub_uint32_t) e.e_phnum * e.e_phentsize; - chunk_size += (grub_uint32_t) e.e_shnum * e.e_shentsize; + chunk_size += e.e_phnum * e.e_phentsize; + chunk_size += e.e_shnum * e.e_shentsize; { grub_relocator_chunk_t ch; @@ -209,7 +207,7 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, err = grub_relocator_alloc_chunk_addr (relocator, &ch, module, chunk_size); if (err) - goto out; + return err; chunk_src = get_virtual_current_address (ch); } @@ -237,7 +235,7 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, + s->sh_addr - *kern_end, s->sh_offset, s->sh_size); if (err) - goto out; + return err; break; case SHT_NOBITS: grub_memset ((grub_uint8_t *) chunk_src + module @@ -253,24 +251,20 @@ SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator, curload = module + sizeof (e); load (file, argv[0], (grub_uint8_t *) chunk_src + curload - *kern_end, e.e_shoff, - (grub_uint32_t) e.e_shnum * e.e_shentsize); + e.e_shnum * e.e_shentsize); e.e_shoff = curload - module; - curload += (grub_uint32_t) e.e_shnum * e.e_shentsize; + curload += e.e_shnum * e.e_shentsize; load (file, argv[0], (grub_uint8_t *) chunk_src + curload - *kern_end, e.e_phoff, - (grub_uint32_t) e.e_phnum * e.e_phentsize); + e.e_phnum * e.e_phentsize); e.e_phoff = curload - module; - curload += (grub_uint32_t) e.e_phnum * e.e_phentsize; + curload += e.e_phnum * e.e_phentsize; *kern_end = curload; grub_freebsd_add_meta_module (argv[0], FREEBSD_MODTYPE_ELF_MODULE, argc - 1, argv + 1, module, curload - module); -out: - grub_free (shdr); - if (err) - return err; return SUFFIX (grub_freebsd_load_elf_meta) (relocator, file, argv[0], kern_end); } @@ -298,13 +292,13 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, err = read_headers (file, filename, &e, &shdr); if (err) - goto out; + return err; err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_ELFHDR, &e, sizeof (e)); if (err) - goto out; + return err; for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) (shdr + e.e_shnum * e.e_shentsize); @@ -313,10 +307,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, break; if (s >= (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize)) - { - err = grub_error (GRUB_ERR_BAD_OS, N_("no symbol table")); - goto out; - } + return grub_error (GRUB_ERR_BAD_OS, N_("no symbol table")); symoff = s->sh_offset; symsize = s->sh_size; symentsize = s->sh_entsize; @@ -334,7 +325,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, err = grub_relocator_alloc_chunk_addr (relocator, &ch, symtarget, chunk_size); if (err) - goto out; + return err; sym_chunk = get_virtual_current_address (ch); } @@ -346,38 +337,28 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, curload += sizeof (grub_freebsd_addr_t); if (grub_file_seek (file, symoff) == (grub_off_t) -1) - { - err = grub_errno; - goto out; - } + return grub_errno; sym = (Elf_Sym *) curload; if (grub_file_read (file, curload, symsize) != (grub_ssize_t) symsize) { if (! grub_errno) - err = grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - filename); - else - err = grub_errno; - goto out; + return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + return grub_errno; } curload += symsize; *((grub_freebsd_addr_t *) curload) = strsize; curload += sizeof (grub_freebsd_addr_t); if (grub_file_seek (file, stroff) == (grub_off_t) -1) - { - err = grub_errno; - goto out; - } + return grub_errno; str = (char *) curload; if (grub_file_read (file, curload, strsize) != (grub_ssize_t) strsize) { if (! grub_errno) - err = grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - filename); - else - err = grub_errno; - goto out; + return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + return grub_errno; } for (i = 0; @@ -397,20 +378,18 @@ SUFFIX (grub_freebsd_load_elf_meta) (struct grub_relocator *relocator, FREEBSD_MODINFOMD_DYNAMIC, &dynamic, sizeof (dynamic)); if (err) - goto out; + return err; } err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_SSYM, &symstart, sizeof (symstart)); if (err) - goto out; + return err; err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_ESYM, &symend, sizeof (symend)); -out: - grub_free (shdr); if (err) return err; @@ -438,10 +417,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, err = read_headers (file, filename, &e, &shdr); if (err) - { - grub_free (shdr); - return grub_errno; - } + return err; for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) (shdr + e.e_shnum * e.e_shentsize); @@ -450,10 +426,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, break; if (s >= (Elf_Shdr *) ((char *) shdr + e.e_shnum * e.e_shentsize)) - { - grub_free (shdr); - return GRUB_ERR_NONE; - } + return GRUB_ERR_NONE; symsize = s->sh_size; symsh = s; s = (Elf_Shdr *) (shdr + e.e_shentsize * s->sh_link); @@ -462,7 +435,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, chunk_size = ALIGN_UP (symsize, sizeof (grub_freebsd_addr_t)) + ALIGN_UP (strsize, sizeof (grub_freebsd_addr_t)) - + sizeof (e) + (grub_uint32_t) e.e_shnum * e.e_shentsize; + + sizeof (e) + e.e_shnum * e.e_shentsize; symtarget = ALIGN_UP (*kern_end, sizeof (grub_freebsd_addr_t)); { @@ -470,7 +443,7 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, err = grub_relocator_alloc_chunk_addr (relocator, &ch, symtarget, chunk_size); if (err) - goto out; + return err; sym_chunk = get_virtual_current_address (ch); } @@ -498,10 +471,10 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, s2 = (Elf_Shdr *) curload; grub_memcpy (curload, s, e.e_shentsize); if (s == symsh) - s2->sh_offset = sizeof (e) + (grub_uint32_t) e.e_shnum * e.e_shentsize; + s2->sh_offset = sizeof (e) + e.e_shnum * e.e_shentsize; else if (s == strsh) s2->sh_offset = ALIGN_UP (symsize, sizeof (grub_freebsd_addr_t)) - + sizeof (e) + (grub_uint32_t) e.e_shnum * e.e_shentsize; + + sizeof (e) + e.e_shnum * e.e_shentsize; else s2->sh_offset = 0; s2->sh_addr = s2->sh_offset; @@ -509,41 +482,29 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator, } if (grub_file_seek (file, symsh->sh_offset) == (grub_off_t) -1) - { - err = grub_errno; - goto out; - } + return grub_errno; if (grub_file_read (file, curload, symsize) != (grub_ssize_t) symsize) { if (! grub_errno) - err = grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - filename); - else - err = grub_errno; - goto out; + return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + return grub_errno; } curload += ALIGN_UP (symsize, sizeof (grub_freebsd_addr_t)); if (grub_file_seek (file, strsh->sh_offset) == (grub_off_t) -1) - { - err = grub_errno; - goto out; - } + return grub_errno; if (grub_file_read (file, curload, strsize) != (grub_ssize_t) strsize) { if (! grub_errno) - err = grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - filename); - else - err = grub_errno; - goto out; + return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + return grub_errno; } err = grub_bsd_add_meta (NETBSD_BTINFO_SYMTAB, &symtab, sizeof (symtab)); -out: - grub_free (shdr); if (err) return err; @@ -569,10 +530,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file, err = read_headers (file, filename, &e, &shdr); if (err) - { - grub_free (shdr); - return err; - } + return err; for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) (shdr + e.e_shnum * e.e_shentsize); @@ -625,11 +583,7 @@ SUFFIX(grub_openbsd_find_ramdisk) (grub_file_t file, } if (grub_file_seek (file, stroff) == (grub_off_t) -1) - { - grub_free (syms); - grub_free (strs); - return grub_errno; - } + return grub_errno; if (grub_file_read (file, strs, strsize) != (grub_ssize_t) strsize) { grub_free (syms); diff --git a/grub-core/loader/i386/coreboot/chainloader.c b/grub-core/loader/i386/coreboot/chainloader.c index 0a19ebb9c..d4cc40b7f 100644 --- a/grub-core/loader/i386/coreboot/chainloader.c +++ b/grub-core/loader/i386/coreboot/chainloader.c @@ -384,7 +384,6 @@ load_chewed (grub_file_t file, const char *filename) segment.len = 0; segment.offset = 0; segment.len = 0; - /* Fallthrough. */ case PAYLOAD_SEGMENT_CODE: case PAYLOAD_SEGMENT_DATA: { @@ -439,7 +438,7 @@ grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)), grub_loader_unset (); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_COREBOOT_CHAINLOADER); + file = grub_file_open (argv[0]); if (!file) return grub_errno; diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 976af3fae..291f7289f 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -35,8 +35,6 @@ #include #include #include -#include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -71,6 +69,7 @@ static grub_addr_t prot_mode_target; static void *initrd_mem; static grub_addr_t initrd_mem_target; static grub_size_t prot_init_space; +static grub_uint32_t initrd_pages; static struct grub_relocator *relocator = NULL; static void *efi_mmap_buf; static grub_size_t maximal_cmdline_size; @@ -103,6 +102,55 @@ page_align (grub_size_t size) return (size + (1 << 12) - 1) & (~((1 << 12) - 1)); } +#ifdef GRUB_MACHINE_EFI +/* Find the optimal number of pages for the memory map. Is it better to + move this code to efi/mm.c? */ +static grub_efi_uintn_t +find_efi_mmap_size (void) +{ + static grub_efi_uintn_t mmap_size = 0; + + if (mmap_size != 0) + return mmap_size; + + mmap_size = (1 << 12); + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + grub_efi_uintn_t cur_mmap_size = mmap_size; + + mmap = grub_malloc (cur_mmap_size); + if (! mmap) + return 0; + + ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + { + grub_error (GRUB_ERR_IO, "cannot get memory map"); + return 0; + } + else if (ret > 0) + break; + + if (mmap_size < cur_mmap_size) + mmap_size = cur_mmap_size; + mmap_size += (1 << 12); + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + mmap_size += (3 << 12); + + mmap_size = page_align (mmap_size); + return mmap_size; +} + +#endif + /* Helper for find_mmap_size. */ static int count_hook (grub_uint64_t addr __attribute__ ((unused)), @@ -181,8 +229,9 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, for (; err && *align + 1 > min_align; (*align)--) { grub_errno = GRUB_ERR_NONE; - err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, - UP_TO_TOP32 (prot_size), + err = grub_relocator_alloc_chunk_align (relocator, &ch, + 0x1000000, + 0xffffffff & ~prot_size, prot_size, 1 << *align, GRUB_RELOCATOR_PREFERENCE_LOW, 1); @@ -258,12 +307,6 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->lfb_line_len = mode_info.pitch; params->lfb_base = (grub_size_t) framebuffer; - -#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__) - params->ext_lfb_base = (grub_size_t) (((grub_uint64_t)(grub_size_t) framebuffer) >> 32); - params->capabilities |= VIDEO_CAPABILITY_64BIT_BASE; -#endif - params->lfb_size = ALIGN_UP (params->lfb_line_len * params->lfb_height, 65536); params->red_mask_size = mode_info.red_mask_size; @@ -509,10 +552,6 @@ grub_linux_boot (void) } } -#ifdef GRUB_KERNEL_USE_RSDP_ADDR - linux_params.acpi_rsdp_addr = grub_le_to_cpu64 (grub_rsdp_addr); -#endif - mmap_size = find_mmap_size (); /* Make sure that each size is aligned to a page boundary. */ cl_offset = ALIGN_UP (mmap_size + sizeof (linux_params), 4096); @@ -522,7 +561,7 @@ grub_linux_boot (void) ctx.real_size = ALIGN_UP (cl_offset + maximal_cmdline_size, 4096); #ifdef GRUB_MACHINE_EFI - efi_mmap_size = grub_efi_find_mmap_size (); + efi_mmap_size = find_efi_mmap_size (); if (efi_mmap_size == 0) return grub_errno; #endif @@ -547,13 +586,9 @@ grub_linux_boot (void) { grub_relocator_chunk_t ch; - grub_size_t sz; - - if (grub_add (ctx.real_size, efi_mmap_size, &sz)) - return GRUB_ERR_OUT_OF_RANGE; - err = grub_relocator_alloc_chunk_addr (relocator, &ch, - ctx.real_mode_target, sz); + ctx.real_mode_target, + (ctx.real_size + efi_mmap_size)); if (err) return err; real_mode_mem = get_virtual_current_address (ch); @@ -644,7 +679,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_file_t file = 0; - struct linux_i386_kernel_header lh; + struct linux_kernel_header lh; grub_uint8_t setup_sects; grub_size_t real_size, prot_size, prot_file_size; grub_ssize_t len; @@ -661,7 +696,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (! file) goto fail; @@ -687,7 +722,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* FIXME: 2.03 is not always good enough (Linux 2.4 can be 2.03 and still not support 32-bit boot. */ - if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0203) { grub_error (GRUB_ERR_BAD_OS, "version too old for 32-bit boot" @@ -765,26 +800,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; grub_memset (&linux_params, 0, sizeof (linux_params)); + grub_memcpy (&linux_params.setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1); - /* - * The Linux 32-bit boot protocol defines the setup header end - * to be at 0x202 + the byte value at 0x201. - */ - len = 0x202 + *((char *) &lh.jump + 1); + linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; + linux_params.kernel_alignment = (1 << align); + linux_params.ps_mouse = linux_params.padding10 = 0; - /* Verify the struct is big enough so we do not write past the end. */ - if (len > (char *) &linux_params.edd_mbr_sig_buffer - (char *) &linux_params) { - grub_error (GRUB_ERR_BAD_OS, "Linux setup header too big"); - goto fail; - } - - grub_memcpy (&linux_params.setup_sects, &lh.setup_sects, len - 0x1F1); - - /* We've already read lh so there is no need to read it second time. */ - len -= sizeof(lh); - - if ((len > 0) && - (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len)) + len = sizeof (linux_params) - sizeof (lh); + if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len) { if (!grub_errno) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), @@ -792,9 +815,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; - linux_params.kernel_alignment = (1 << align); - linux_params.ps_mouse = linux_params.padding10 = 0; linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; /* These two are used (instead of cmd_line_ptr) by older versions of Linux, @@ -896,8 +916,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_env_set ("gfxpayload", "text"); grub_printf_ (N_("%s is deprecated. " "Use set gfxpayload=%s before " - "linux command instead.\n"), - argv[i], "text"); + "linux command instead.\n"), "text", + argv[i]); break; case 1: @@ -906,8 +926,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_env_set ("gfxpayload", "text"); grub_printf_ (N_("%s is deprecated. " "Use set gfxpayload=%s before " - "linux command instead.\n"), - argv[i], "text"); + "linux command instead.\n"), "text", + argv[i]); break; default: /* Ignore invalid values. */ @@ -948,7 +968,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), #endif /* GRUB_MACHINE_PCBIOS */ if (grub_memcmp (argv[i], "mem=", 4) == 0) { - const char *val = argv[i] + 4; + char *val = argv[i] + 4; linux_mem_size = grub_strtoul (val, &val, 0); @@ -965,13 +985,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { case 'g': shift += 10; - /* FALLTHROUGH */ case 'm': shift += 10; - /* FALLTHROUGH */ case 'k': shift += 10; - /* FALLTHROUGH */ default: break; } @@ -993,17 +1010,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (!linux_cmdline) goto fail; grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - { - grub_err_t err; - err = grub_create_loader_cmdline (argc, argv, - linux_cmdline - + sizeof (LINUX_IMAGE) - 1, - maximal_cmdline_size - - (sizeof (LINUX_IMAGE) - 1), - GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - goto fail; - } + grub_create_loader_cmdline (argc, argv, + linux_cmdline + + sizeof (LINUX_IMAGE) - 1, + maximal_cmdline_size + - (sizeof (LINUX_IMAGE) - 1)); len = prot_file_size; if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno) @@ -1035,7 +1046,7 @@ static grub_err_t grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { - grub_size_t size = 0, aligned_size = 0; + grub_size_t size = 0; grub_addr_t addr_min, addr_max; grub_addr_t addr; grub_err_t err; @@ -1057,7 +1068,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; size = grub_get_initrd_size (&initrd_ctx); - aligned_size = ALIGN_UP (size, 4096); + + initrd_pages = (page_align (size) >> 12); /* Get the highest address available for the initrd. */ if (grub_le_to_cpu16 (linux_params.version) >= 0x0203) @@ -1085,7 +1097,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), addr_min = (grub_addr_t) prot_mode_target + prot_init_space; /* Put the initrd as high as possible, 4KiB aligned. */ - addr = (addr_max - aligned_size) & ~0xFFF; + addr = (addr_max - size) & ~0xFFF; if (addr < addr_min) { @@ -1096,8 +1108,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_align (relocator, &ch, - addr_min, addr, aligned_size, - 0x1000, + addr_min, addr, size, 0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 1); if (err) diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c index a67d9d0a8..f10c087f7 100644 --- a/grub-core/loader/i386/multiboot_mbi.c +++ b/grub-core/loader/i386/multiboot_mbi.c @@ -70,21 +70,9 @@ load_kernel (grub_file_t file, const char *filename, char *buffer, struct multiboot_header *header) { grub_err_t err; - mbi_load_data_t mld; - - mld.file = file; - mld.filename = filename; - mld.buffer = buffer; - mld.mbi_ver = 1; - mld.relocatable = 0; - mld.avoid_efi_boot_services = 0; - if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE) { - err = grub_multiboot_load_elf (&mld); - if (err == GRUB_ERR_NONE) { - return GRUB_ERR_NONE; - } + err = grub_multiboot_load_elf (file, filename, buffer); if (err == GRUB_ERR_UNKNOWN_OS && (header->flags & MULTIBOOT_AOUT_KLUDGE)) grub_errno = err = GRUB_ERR_NONE; } @@ -130,25 +118,7 @@ load_kernel (grub_file_t file, const char *filename, return GRUB_ERR_NONE; } - return grub_multiboot_load_elf (&mld); -} - -static struct multiboot_header * -find_header (char *buffer, grub_ssize_t len) -{ - struct multiboot_header *header; - - /* Look for the multiboot header in the buffer. The header should - be at least 12 bytes and aligned on a 4-byte boundary. */ - for (header = (struct multiboot_header *) buffer; - ((char *) header <= buffer + len - 12); - header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN)) - { - if (header->magic == MULTIBOOT_HEADER_MAGIC - && !(header->magic + header->flags + header->checksum)) - return header; - } - return NULL; + return grub_multiboot_load_elf (file, filename, buffer); } grub_err_t @@ -173,7 +143,16 @@ grub_multiboot_load (grub_file_t file, const char *filename) return grub_errno; } - header = find_header (buffer, len); + /* Look for the multiboot header in the buffer. The header should + be at least 12 bytes and aligned on a 4-byte boundary. */ + for (header = (struct multiboot_header *) buffer; + ((char *) header <= buffer + len - 12) || (header = 0); + header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN)) + { + if (header->magic == MULTIBOOT_HEADER_MAGIC + && !(header->magic + header->flags + header->checksum)) + break; + } if (header == 0) { @@ -239,7 +218,7 @@ grub_multiboot_get_mbi_size (void) ret = sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4) + modcnt * sizeof (struct multiboot_mod_list) + total_modcmd + ALIGN_UP (sizeof(PACKAGE_STRING), 4) - + grub_multiboot_get_mmap_count () * sizeof (struct multiboot_mmap_entry) + + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry) + elf_sec_entsize * elf_sec_num + 256 * sizeof (struct multiboot_color) #if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT @@ -466,9 +445,10 @@ grub_multiboot_make_mbi (grub_uint32_t *target) bufsize = grub_multiboot_get_mbi_size (); - err = grub_relocator_alloc_chunk_align_safe (grub_multiboot_relocator, &ch, - 0x10000, 0xa0000, bufsize, 4, - GRUB_RELOCATOR_PREFERENCE_NONE, 0); + err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + 0x10000, 0xa0000 - bufsize, + bufsize, 4, + GRUB_RELOCATOR_PREFERENCE_NONE, 0); if (err) return err; ptrorig = get_virtual_current_address (ch); @@ -541,7 +521,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target) mbi->mods_count = 0; } - mmap_size = grub_multiboot_get_mmap_count () + mmap_size = grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry); grub_fill_multiboot_mmap ((struct multiboot_mmap_entry *) ptrorig); mbi->mmap_length = mmap_size; @@ -672,8 +652,10 @@ grub_multiboot_init_mbi (int argc, char *argv[]) return grub_errno; cmdline_size = len; - return grub_create_loader_cmdline (argc, argv, cmdline, - cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE); + grub_create_loader_cmdline (argc, argv, cmdline, + cmdline_size); + + return GRUB_ERR_NONE; } grub_err_t @@ -682,7 +664,6 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size, { struct module *newmod; grub_size_t len = 0; - grub_err_t err; newmod = grub_malloc (sizeof (*newmod)); if (!newmod) @@ -702,13 +683,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size, newmod->cmdline_size = len; total_modcmd += ALIGN_UP (len, 4); - err = grub_create_loader_cmdline (argc, argv, newmod->cmdline, - newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE); - if (err) - { - grub_free (newmod); - return grub_errno; - } + grub_create_loader_cmdline (argc, argv, newmod->cmdline, + newmod->cmdline_size); if (modules_last) modules_last->next = newmod; diff --git a/grub-core/loader/i386/pc/chainloader.c b/grub-core/loader/i386/pc/chainloader.c index 976fea73a..c79c4fe0f 100644 --- a/grub-core/loader/i386/pc/chainloader.c +++ b/grub-core/loader/i386/pc/chainloader.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -87,16 +86,9 @@ grub_chainloader_unload (void) void grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl) { - grub_uint32_t part_start = 0, heads = 0, sectors = 0; + grub_uint32_t part_start = 0; if (dev && dev->disk) - { - part_start = grub_partition_get_start (dev->disk->partition); - if (dev->disk->data) - { - heads = ((struct grub_biosdisk_data *)(dev->disk->data))->heads; - sectors = ((struct grub_biosdisk_data *)(dev->disk->data))->sectors; - } - } + part_start = grub_partition_get_start (dev->disk->partition); if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name, "NTFS", 4) == 0) { @@ -125,7 +117,7 @@ grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl) if (bpb->num_reserved_sectors == 0) break; - if (bpb->num_total_sectors_16 == 0 && bpb->num_total_sectors_32 == 0) + if (bpb->num_total_sectors_16 == 0 || bpb->num_total_sectors_32 == 0) break; if (bpb->num_fats == 0) @@ -135,20 +127,12 @@ grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl) { bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); bpb->version_specific.fat12_or_fat16.num_ph_drive = dl; - if (sectors) - bpb->sectors_per_track = grub_cpu_to_le16 (sectors); - if (heads) - bpb->num_heads = grub_cpu_to_le16 (heads); return; } if (bpb->version_specific.fat32.sectors_per_fat_32) { bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start); bpb->version_specific.fat32.num_ph_drive = dl; - if (sectors) - bpb->sectors_per_track = grub_cpu_to_le16 (sectors); - if (heads) - bpb->num_heads = grub_cpu_to_le16 (heads); return; } break; @@ -172,8 +156,8 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) grub_dl_ref (my_mod); - file = grub_file_open (filename, GRUB_FILE_TYPE_PCCHAINLOADER - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (filename); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/freedos.c b/grub-core/loader/i386/pc/freedos.c index aac6c9715..478f3c513 100644 --- a/grub-core/loader/i386/pc/freedos.c +++ b/grub-core/loader/i386/pc/freedos.c @@ -110,7 +110,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)), if (!rel) goto fail; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS); + file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 814988ab9..870992b7d 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -35,7 +35,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -122,7 +121,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { grub_file_t file = 0; - struct linux_i386_kernel_header lh; + struct linux_kernel_header lh; grub_uint8_t setup_sects; grub_size_t real_size; grub_ssize_t len; @@ -140,7 +139,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (! file) goto fail; @@ -170,7 +169,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), maximal_cmdline_size = 256; - if (lh.header == grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + if (lh.header == grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) && grub_le_to_cpu16 (lh.version) >= 0x0200) { grub_linux_is_bzimage = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL); @@ -219,12 +218,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS; real_size = setup_sects << GRUB_DISK_SECTOR_BITS; - if (grub_sub (grub_file_size (file), real_size, &grub_linux16_prot_size) || - grub_sub (grub_linux16_prot_size, GRUB_DISK_SECTOR_SIZE, &grub_linux16_prot_size)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - goto fail; - } + grub_linux16_prot_size = grub_file_size (file) + - real_size - GRUB_DISK_SECTOR_SIZE; if (! grub_linux_is_bzimage && GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size @@ -241,6 +236,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), (unsigned) real_size, (unsigned) grub_linux16_prot_size); + relocator = grub_relocator_new (); + if (!relocator) + goto fail; + for (i = 1; i < argc; i++) if (grub_memcmp (argv[i], "vga=", 4) == 0) { @@ -264,7 +263,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } else if (grub_memcmp (argv[i], "mem=", 4) == 0) { - const char *val = argv[i] + 4; + char *val = argv[i] + 4; linux_mem_size = grub_strtoul (val, &val, 0); @@ -281,13 +280,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { case 'g': shift += 10; - /* Fallthrough. */ case 'm': shift += 10; - /* Fallthrough. */ case 'k': shift += 10; - /* Fallthrough. */ default: break; } @@ -300,10 +296,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } } - relocator = grub_relocator_new (); - if (!relocator) - goto fail; - { grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_addr (relocator, &ch, @@ -327,7 +319,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0200) /* Clear the heap space. */ grub_memset (grub_linux_real_chunk @@ -339,14 +331,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Create kernel command line. */ grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - err = grub_create_loader_cmdline (argc, argv, - (char *)grub_linux_real_chunk - + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1, - maximal_cmdline_size - - (sizeof (LINUX_IMAGE) - 1), - GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - goto fail; + grub_create_loader_cmdline (argc, argv, + (char *)grub_linux_real_chunk + + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1, + maximal_cmdline_size + - (sizeof (LINUX_IMAGE) - 1)); if (grub_linux_is_bzimage) grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR; @@ -363,7 +352,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), } len = grub_linux16_prot_size; - if (grub_file_read (file, grub_linux_prot_chunk, len) != len && !grub_errno) + if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size) + != (grub_ssize_t) grub_linux16_prot_size && !grub_errno) grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); @@ -394,7 +384,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { grub_size_t size = 0; grub_addr_t addr_max, addr_min; - struct linux_i386_kernel_header *lh; + struct linux_kernel_header *lh; grub_uint8_t *initrd_chunk; grub_addr_t initrd_addr; grub_err_t err; @@ -412,9 +402,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - lh = (struct linux_i386_kernel_header *) grub_linux_real_chunk; + lh = (struct linux_kernel_header *) grub_linux_real_chunk; - if (!(lh->header == grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + if (!(lh->header == grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) && grub_le_to_cpu16 (lh->version) >= 0x0200)) { grub_error (GRUB_ERR_BAD_OS, "the kernel is too old for initrd"); @@ -453,8 +443,10 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, addr_min, addr_max, size, - 0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 0); + err = grub_relocator_alloc_chunk_align (relocator, &ch, + addr_min, addr_max - size, + size, 0x1000, + GRUB_RELOCATOR_PREFERENCE_HIGH, 0); if (err) return err; initrd_chunk = get_virtual_current_address (ch); diff --git a/grub-core/loader/i386/pc/ntldr.c b/grub-core/loader/i386/pc/ntldr.c index f0d74145b..1b88f40d8 100644 --- a/grub-core/loader/i386/pc/ntldr.c +++ b/grub-core/loader/i386/pc/ntldr.c @@ -90,7 +90,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)), if (!rel) goto fail; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR); + file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/plan9.c b/grub-core/loader/i386/pc/plan9.c index 37550155d..0d10b1c24 100644 --- a/grub-core/loader/i386/pc/plan9.c +++ b/grub-core/loader/i386/pc/plan9.c @@ -33,7 +33,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -343,7 +342,6 @@ fill_disk (const char *name, void *data) if (!plan9name) { grub_print_error (); - grub_device_close (dev); return 0; } if (grub_extend_alloc (fill_ctx->pmapptr + grub_strlen (plan9name) @@ -351,7 +349,6 @@ fill_disk (const char *name, void *data) &fill_ctx->pmap)) { grub_free (plan9name); - grub_device_close (dev); return 1; } grub_strcpy (fill_ctx->pmap + fill_ctx->pmapptr, plan9name); @@ -369,19 +366,12 @@ fill_disk (const char *name, void *data) fill_ctx->noslash = 1; grub_memset (fill_ctx->prefixescnt, 0, sizeof (fill_ctx->prefixescnt)); if (grub_partition_iterate (dev->disk, fill_partition, fill_ctx)) - { - grub_device_close (dev); - return 1; - } + return 1; if (grub_extend_alloc (fill_ctx->pmapptr + 1, &fill_ctx->pmapalloc, &fill_ctx->pmap)) - { - grub_device_close (dev); - return 1; - } + return 1; fill_ctx->pmap[fill_ctx->pmapptr++] = '\n'; - grub_device_close (dev); return 0; } @@ -414,7 +404,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[]) if (!rel) goto fail; - fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL); + fill_ctx.file = grub_file_open (argv[0]); if (! fill_ctx.file) goto fail; @@ -506,7 +496,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[]) configptr = grub_stpcpy (configptr, "bootfile="); configptr = grub_stpcpy (configptr, bootpath); *configptr++ = '\n'; - char *cmdline = configptr; { int i; for (i = 1; i < argc; i++) @@ -515,15 +504,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[]) *configptr++ = '\n'; } } - - { - grub_err_t err; - *configptr = '\0'; - err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - goto fail; - } - configptr = grub_stpcpy (configptr, fill_ctx.pmap); { diff --git a/grub-core/loader/i386/pc/pxechainloader.c b/grub-core/loader/i386/pc/pxechainloader.c index acb061169..e60c62b1b 100644 --- a/grub-core/loader/i386/pc/pxechainloader.c +++ b/grub-core/loader/i386/pc/pxechainloader.c @@ -99,7 +99,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)), if (!rel) goto fail; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER); + file = grub_file_open (argv[0]); if (! file) goto fail; diff --git a/grub-core/loader/i386/pc/truecrypt.c b/grub-core/loader/i386/pc/truecrypt.c index cbeeec7be..159eab1a7 100644 --- a/grub-core/loader/i386/pc/truecrypt.c +++ b/grub-core/loader/i386/pc/truecrypt.c @@ -99,7 +99,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)), grub_dl_ref (my_mod); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_TRUECRYPT); + file = grub_file_open (argv[0]); if (! file) goto fail; @@ -205,7 +205,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)), fail: if (!grub_errno) - grub_error (GRUB_ERR_BAD_OS, "bad truecrypt ISO"); + return grub_error (GRUB_ERR_BAD_OS, "bad truecrypt ISO"); if (file) grub_file_close (file); diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c index cd24874ca..c16b4b249 100644 --- a/grub-core/loader/i386/xen.c +++ b/grub-core/loader/i386/xen.c @@ -39,61 +39,23 @@ #include #include #include -#include -#include -#include GRUB_MOD_LICENSE ("GPLv3+"); -#ifdef __x86_64__ -#define NUMBER_OF_LEVELS 4 -#define INTERMEDIATE_OR (GRUB_PAGE_PRESENT | GRUB_PAGE_RW | GRUB_PAGE_USER) -#define VIRT_MASK 0x0000ffffffffffffULL -#else -#define NUMBER_OF_LEVELS 3 -#define INTERMEDIATE_OR (GRUB_PAGE_PRESENT | GRUB_PAGE_RW) -#define VIRT_MASK 0x00000000ffffffffULL -#define HYPERVISOR_PUD_ADDRESS 0xc0000000ULL -#endif - -struct grub_xen_mapping_lvl { - grub_uint64_t virt_start; - grub_uint64_t virt_end; - grub_uint64_t pfn_start; - grub_uint64_t n_pt_pages; -}; - -struct grub_xen_mapping { - grub_uint64_t *where; - struct grub_xen_mapping_lvl area; - struct grub_xen_mapping_lvl lvls[NUMBER_OF_LEVELS]; -}; - -struct xen_loader_state { - struct grub_relocator *relocator; - struct grub_relocator_xen_state state; - struct start_info next_start; - struct grub_xen_file_info xen_inf; - grub_xen_mfn_t *virt_mfn_list; - struct start_info *virt_start_info; - grub_xen_mfn_t console_pfn; - grub_uint64_t max_addr; - grub_uint64_t pgtbl_end; - struct xen_multiboot_mod_list *module_info_page; - grub_uint64_t modules_target_start; - grub_size_t n_modules; - struct grub_xen_mapping *map_reloc; - struct grub_xen_mapping mappings[XEN_MAX_MAPPINGS]; - int n_mappings; - int loaded; -}; - -static struct xen_loader_state xen_state; - +static struct grub_relocator *relocator = NULL; +static grub_uint64_t max_addr; static grub_dl_t my_mod; +static int loaded = 0; +static struct start_info next_start; +static void *kern_chunk_src; +static struct grub_xen_file_info xen_inf; +static struct xen_multiboot_mod_list *xen_module_info_page; +static grub_uint64_t modules_target_start; +static grub_size_t n_modules; -#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_SIZE 4096 #define MAX_MODULES (PAGE_SIZE / sizeof (struct xen_multiboot_mod_list)) +#define PAGE_SHIFT 12 #define STACK_SIZE 1048576 #define ADDITIONAL_SIZE (1 << 19) #define ALIGN_SIZE (1 << 22) @@ -106,168 +68,105 @@ page2offset (grub_uint64_t page) return page << PAGE_SHIFT; } -static grub_err_t -get_pgtable_size (grub_uint64_t from, grub_uint64_t to, grub_uint64_t pfn) -{ - struct grub_xen_mapping *map, *map_cmp; - grub_uint64_t mask, bits; - int i, m; - - if (xen_state.n_mappings == XEN_MAX_MAPPINGS) - return grub_error (GRUB_ERR_BUG, "too many mapped areas"); - - grub_dprintf ("xen", "get_pgtable_size %d from=%llx, to=%llx, pfn=%llx\n", - xen_state.n_mappings, (unsigned long long) from, - (unsigned long long) to, (unsigned long long) pfn); - - map = xen_state.mappings + xen_state.n_mappings; - grub_memset (map, 0, sizeof (*map)); - - map->area.virt_start = from & VIRT_MASK; - map->area.virt_end = (to - 1) & VIRT_MASK; - map->area.n_pt_pages = 0; - - for (i = NUMBER_OF_LEVELS - 1; i >= 0; i--) - { - map->lvls[i].pfn_start = pfn + map->area.n_pt_pages; - if (i == NUMBER_OF_LEVELS - 1) - { - if (xen_state.n_mappings == 0) - { - map->lvls[i].virt_start = 0; - map->lvls[i].virt_end = VIRT_MASK; - map->lvls[i].n_pt_pages = 1; - map->area.n_pt_pages++; - } - continue; - } - - bits = PAGE_SHIFT + (i + 1) * LOG_POINTERS_PER_PAGE; - mask = (1ULL << bits) - 1; - map->lvls[i].virt_start = map->area.virt_start & ~mask; - map->lvls[i].virt_end = map->area.virt_end | mask; -#ifdef __i386__ - /* PAE wants last root directory present. */ - if (i == 1 && to <= HYPERVISOR_PUD_ADDRESS && xen_state.n_mappings == 0) - map->lvls[i].virt_end = VIRT_MASK; +#ifdef __x86_64__ +#define NUMBER_OF_LEVELS 4 +#define INTERMEDIATE_OR 7 +#else +#define NUMBER_OF_LEVELS 3 +#define INTERMEDIATE_OR 3 #endif - for (m = 0; m < xen_state.n_mappings; m++) - { - map_cmp = xen_state.mappings + m; - if (map_cmp->lvls[i].virt_start == map_cmp->lvls[i].virt_end) - continue; - if (map->lvls[i].virt_start >= map_cmp->lvls[i].virt_start && - map->lvls[i].virt_end <= map_cmp->lvls[i].virt_end) - { - map->lvls[i].virt_start = 0; - map->lvls[i].virt_end = 0; - break; - } - if (map->lvls[i].virt_start >= map_cmp->lvls[i].virt_start && - map->lvls[i].virt_start <= map_cmp->lvls[i].virt_end) - map->lvls[i].virt_start = map_cmp->lvls[i].virt_end + 1; - if (map->lvls[i].virt_end >= map_cmp->lvls[i].virt_start && - map->lvls[i].virt_end <= map_cmp->lvls[i].virt_end) - map->lvls[i].virt_end = map_cmp->lvls[i].virt_start - 1; - } - if (map->lvls[i].virt_start < map->lvls[i].virt_end) - map->lvls[i].n_pt_pages = - ((map->lvls[i].virt_end - map->lvls[i].virt_start) >> bits) + 1; - map->area.n_pt_pages += map->lvls[i].n_pt_pages; - grub_dprintf ("xen", "get_pgtable_size level %d: virt %llx-%llx %d pts\n", - i, (unsigned long long) map->lvls[i].virt_start, - (unsigned long long) map->lvls[i].virt_end, - (int) map->lvls[i].n_pt_pages); - } - - grub_dprintf ("xen", "get_pgtable_size return: %d page tables\n", - (int) map->area.n_pt_pages); - - xen_state.state.paging_start[xen_state.n_mappings] = pfn; - xen_state.state.paging_size[xen_state.n_mappings] = map->area.n_pt_pages; - - return GRUB_ERR_NONE; -} - -static grub_uint64_t * -get_pg_table_virt (int mapping, int level) -{ - grub_uint64_t pfn; - struct grub_xen_mapping *map; - - map = xen_state.mappings + mapping; - pfn = map->lvls[level].pfn_start - map->lvls[NUMBER_OF_LEVELS - 1].pfn_start; - return map->where + pfn * POINTERS_PER_PAGE; -} static grub_uint64_t -get_pg_table_prot (int level, grub_uint64_t pfn) +get_pgtable_size (grub_uint64_t total_pages, grub_uint64_t virt_base) { - int m; - grub_uint64_t pfn_s, pfn_e; - - if (level > 0) - return INTERMEDIATE_OR; - for (m = 0; m < xen_state.n_mappings; m++) + if (!virt_base) + total_pages++; + grub_uint64_t ret = 0; + grub_uint64_t ll = total_pages; + int i; + for (i = 0; i < NUMBER_OF_LEVELS; i++) { - pfn_s = xen_state.mappings[m].lvls[NUMBER_OF_LEVELS - 1].pfn_start; - pfn_e = xen_state.mappings[m].area.n_pt_pages + pfn_s; - if (pfn >= pfn_s && pfn < pfn_e) - return GRUB_PAGE_PRESENT | GRUB_PAGE_USER; + ll = (ll + POINTERS_PER_PAGE - 1) >> LOG_POINTERS_PER_PAGE; + /* PAE wants all 4 root directories present. */ +#ifdef __i386__ + if (i == 1) + ll = 4; +#endif + ret += ll; } - return GRUB_PAGE_PRESENT | GRUB_PAGE_RW | GRUB_PAGE_USER; + for (i = 1; i < NUMBER_OF_LEVELS; i++) + if (virt_base >> (PAGE_SHIFT + i * LOG_POINTERS_PER_PAGE)) + ret++; + return ret; } static void -generate_page_table (grub_xen_mfn_t *mfn_list) +generate_page_table (grub_uint64_t *where, grub_uint64_t paging_start, + grub_uint64_t total_pages, grub_uint64_t virt_base, + grub_xen_mfn_t *mfn_list) { - int l, m1, m2; - long p, p_s, p_e; - grub_uint64_t start, end, pfn; - grub_uint64_t *pg; - struct grub_xen_mapping_lvl *lvl; + if (!virt_base) + total_pages++; - for (m1 = 0; m1 < xen_state.n_mappings; m1++) - grub_memset (xen_state.mappings[m1].where, 0, - xen_state.mappings[m1].area.n_pt_pages * PAGE_SIZE); + grub_uint64_t lx[NUMBER_OF_LEVELS], lxs[NUMBER_OF_LEVELS]; + grub_uint64_t nlx, nls, sz = 0; + int l; - for (l = NUMBER_OF_LEVELS - 1; l >= 0; l--) + nlx = total_pages; + nls = virt_base >> PAGE_SHIFT; + for (l = 0; l < NUMBER_OF_LEVELS; l++) { - for (m1 = 0; m1 < xen_state.n_mappings; m1++) - { - start = xen_state.mappings[m1].lvls[l].virt_start; - end = xen_state.mappings[m1].lvls[l].virt_end; - pg = get_pg_table_virt(m1, l); - for (m2 = 0; m2 < xen_state.n_mappings; m2++) - { - lvl = (l > 0) ? xen_state.mappings[m2].lvls + l - 1 - : &xen_state.mappings[m2].area; - if (l > 0 && lvl->n_pt_pages == 0) - continue; - if (lvl->virt_start >= end || lvl->virt_end <= start) - continue; - p_s = (grub_max (start, lvl->virt_start) - start) >> - (PAGE_SHIFT + l * LOG_POINTERS_PER_PAGE); - p_e = (grub_min (end, lvl->virt_end) - start) >> - (PAGE_SHIFT + l * LOG_POINTERS_PER_PAGE); - pfn = ((grub_max (start, lvl->virt_start) - lvl->virt_start) >> - (PAGE_SHIFT + l * LOG_POINTERS_PER_PAGE)) + lvl->pfn_start; - grub_dprintf ("xen", "write page table entries level %d pg %p " - "mapping %d/%d index %lx-%lx pfn %llx\n", - l, pg, m1, m2, p_s, p_e, (unsigned long long) pfn); - for (p = p_s; p <= p_e; p++) - { - pg[p] = page2offset (mfn_list[pfn]) | - get_pg_table_prot (l, pfn); - pfn++; - } - } - } + nlx = (nlx + POINTERS_PER_PAGE - 1) >> LOG_POINTERS_PER_PAGE; + /* PAE wants all 4 root directories present. */ +#ifdef __i386__ + if (l == 1) + nlx = 4; +#endif + lx[l] = nlx; + sz += lx[l]; + lxs[l] = nls & (POINTERS_PER_PAGE - 1); + if (nls && l != 0) + sz++; + nls >>= LOG_POINTERS_PER_PAGE; + } + + grub_uint64_t lp; + grub_uint64_t j; + grub_uint64_t *pg = (grub_uint64_t *) where; + int pr = 0; + + grub_memset (pg, 0, sz * PAGE_SIZE); + + lp = paging_start + lx[NUMBER_OF_LEVELS - 1]; + for (l = NUMBER_OF_LEVELS - 1; l >= 1; l--) + { + if (lxs[l] || pr) + pg[0] = page2offset (mfn_list[lp++]) | INTERMEDIATE_OR; + if (pr) + pg += POINTERS_PER_PAGE; + for (j = 0; j < lx[l - 1]; j++) + pg[j + lxs[l]] = page2offset (mfn_list[lp++]) | INTERMEDIATE_OR; + pg += lx[l] * POINTERS_PER_PAGE; + if (lxs[l]) + pr = 1; + } + + if (lxs[0] || pr) + pg[0] = page2offset (mfn_list[total_pages]) | 5; + if (pr) + pg += POINTERS_PER_PAGE; + + for (j = 0; j < total_pages; j++) + { + if (j >= paging_start && j < lp) + pg[j + lxs[0]] = page2offset (mfn_list[j]) | 5; + else + pg[j + lxs[0]] = page2offset (mfn_list[j]) | 7; } } static grub_err_t -set_mfns (grub_xen_mfn_t pfn) +set_mfns (grub_xen_mfn_t * new_mfn_list, grub_xen_mfn_t pfn) { grub_xen_mfn_t i, t; grub_xen_mfn_t cn_pfn = -1, st_pfn = -1; @@ -276,34 +175,32 @@ set_mfns (grub_xen_mfn_t pfn) for (i = 0; i < grub_xen_start_page_addr->nr_pages; i++) { - if (xen_state.virt_mfn_list[i] == - grub_xen_start_page_addr->console.domU.mfn) + if (new_mfn_list[i] == grub_xen_start_page_addr->console.domU.mfn) cn_pfn = i; - if (xen_state.virt_mfn_list[i] == grub_xen_start_page_addr->store_mfn) + if (new_mfn_list[i] == grub_xen_start_page_addr->store_mfn) st_pfn = i; } if (cn_pfn == (grub_xen_mfn_t)-1) return grub_error (GRUB_ERR_BUG, "no console"); if (st_pfn == (grub_xen_mfn_t)-1) return grub_error (GRUB_ERR_BUG, "no store"); - t = xen_state.virt_mfn_list[pfn]; - xen_state.virt_mfn_list[pfn] = xen_state.virt_mfn_list[cn_pfn]; - xen_state.virt_mfn_list[cn_pfn] = t; - t = xen_state.virt_mfn_list[pfn + 1]; - xen_state.virt_mfn_list[pfn + 1] = xen_state.virt_mfn_list[st_pfn]; - xen_state.virt_mfn_list[st_pfn] = t; + t = new_mfn_list[pfn]; + new_mfn_list[pfn] = new_mfn_list[cn_pfn]; + new_mfn_list[cn_pfn] = t; + t = new_mfn_list[pfn + 1]; + new_mfn_list[pfn + 1] = new_mfn_list[st_pfn]; + new_mfn_list[st_pfn] = t; - m2p_updates[0].ptr = - page2offset (xen_state.virt_mfn_list[pfn]) | MMU_MACHPHYS_UPDATE; + m2p_updates[0].ptr = page2offset (new_mfn_list[pfn]) | MMU_MACHPHYS_UPDATE; m2p_updates[0].val = pfn; m2p_updates[1].ptr = - page2offset (xen_state.virt_mfn_list[pfn + 1]) | MMU_MACHPHYS_UPDATE; + page2offset (new_mfn_list[pfn + 1]) | MMU_MACHPHYS_UPDATE; m2p_updates[1].val = pfn + 1; m2p_updates[2].ptr = - page2offset (xen_state.virt_mfn_list[cn_pfn]) | MMU_MACHPHYS_UPDATE; + page2offset (new_mfn_list[cn_pfn]) | MMU_MACHPHYS_UPDATE; m2p_updates[2].val = cn_pfn; m2p_updates[3].ptr = - page2offset (xen_state.virt_mfn_list[st_pfn]) | MMU_MACHPHYS_UPDATE; + page2offset (new_mfn_list[st_pfn]) | MMU_MACHPHYS_UPDATE; m2p_updates[3].val = st_pfn; grub_xen_mmu_update (m2p_updates, 4, NULL, DOMID_SELF); @@ -311,222 +208,97 @@ set_mfns (grub_xen_mfn_t pfn) return GRUB_ERR_NONE; } -static grub_err_t -grub_xen_p2m_alloc (void) -{ - grub_relocator_chunk_t ch; - grub_size_t p2msize, p2malloc; - grub_err_t err; - struct grub_xen_mapping *map; - - if (xen_state.virt_mfn_list) - return GRUB_ERR_NONE; - - map = xen_state.mappings + xen_state.n_mappings; - p2msize = ALIGN_UP (sizeof (grub_xen_mfn_t) * - grub_xen_start_page_addr->nr_pages, PAGE_SIZE); - if (xen_state.xen_inf.has_p2m_base) - { - err = get_pgtable_size (xen_state.xen_inf.p2m_base, - xen_state.xen_inf.p2m_base + p2msize, - (xen_state.max_addr + p2msize) >> PAGE_SHIFT); - if (err) - return err; - - map->area.pfn_start = xen_state.max_addr >> PAGE_SHIFT; - p2malloc = p2msize + page2offset (map->area.n_pt_pages); - xen_state.n_mappings++; - xen_state.next_start.mfn_list = xen_state.xen_inf.p2m_base; - xen_state.next_start.first_p2m_pfn = map->area.pfn_start; - xen_state.next_start.nr_p2m_frames = p2malloc >> PAGE_SHIFT; - } - else - { - xen_state.next_start.mfn_list = - xen_state.max_addr + xen_state.xen_inf.virt_base; - p2malloc = p2msize; - } - - xen_state.state.mfn_list = xen_state.max_addr; - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, p2malloc); - if (err) - return err; - xen_state.virt_mfn_list = get_virtual_current_address (ch); - if (xen_state.xen_inf.has_p2m_base) - map->where = (grub_uint64_t *) xen_state.virt_mfn_list + - p2msize / sizeof (grub_uint64_t); - grub_memcpy (xen_state.virt_mfn_list, - (void *) grub_xen_start_page_addr->mfn_list, p2msize); - xen_state.max_addr += p2malloc; - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_xen_special_alloc (void) -{ - grub_relocator_chunk_t ch; - grub_err_t err; - - if (xen_state.virt_start_info) - return GRUB_ERR_NONE; - - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, - sizeof (xen_state.next_start)); - if (err) - return err; - xen_state.state.start_info = xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.virt_start_info = get_virtual_current_address (ch); - xen_state.max_addr = - ALIGN_UP (xen_state.max_addr + sizeof (xen_state.next_start), PAGE_SIZE); - xen_state.console_pfn = xen_state.max_addr >> PAGE_SHIFT; - xen_state.max_addr += 2 * PAGE_SIZE; - - xen_state.next_start.nr_pages = grub_xen_start_page_addr->nr_pages; - grub_memcpy (xen_state.next_start.magic, grub_xen_start_page_addr->magic, - sizeof (xen_state.next_start.magic)); - xen_state.next_start.store_mfn = grub_xen_start_page_addr->store_mfn; - xen_state.next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; - xen_state.next_start.console.domU = grub_xen_start_page_addr->console.domU; - xen_state.next_start.shared_info = grub_xen_start_page_addr->shared_info; - - return GRUB_ERR_NONE; -} - -static grub_err_t -grub_xen_pt_alloc (void) -{ - grub_relocator_chunk_t ch; - grub_err_t err; - grub_uint64_t nr_info_pages; - grub_uint64_t nr_need_pages; - grub_uint64_t try_virt_end; - struct grub_xen_mapping *map; - - if (xen_state.pgtbl_end) - return GRUB_ERR_NONE; - - map = xen_state.mappings + xen_state.n_mappings; - xen_state.map_reloc = map + 1; - - xen_state.next_start.pt_base = - xen_state.max_addr + xen_state.xen_inf.virt_base; - nr_info_pages = xen_state.max_addr >> PAGE_SHIFT; - nr_need_pages = nr_info_pages; - - while (1) - { - try_virt_end = ALIGN_UP (xen_state.xen_inf.virt_base + - page2offset (nr_need_pages) + - ADDITIONAL_SIZE + STACK_SIZE, ALIGN_SIZE); - - err = get_pgtable_size (xen_state.xen_inf.virt_base, try_virt_end, - nr_info_pages); - if (err) - return err; - xen_state.n_mappings++; - - /* Map the relocator page either at virtual 0 or after end of area. */ - nr_need_pages = nr_info_pages + map->area.n_pt_pages; - if (xen_state.xen_inf.virt_base) - err = get_pgtable_size (0, PAGE_SIZE, nr_need_pages); - else - err = get_pgtable_size (try_virt_end, try_virt_end + PAGE_SIZE, - nr_need_pages); - if (err) - return err; - nr_need_pages += xen_state.map_reloc->area.n_pt_pages; - - if (xen_state.xen_inf.virt_base + page2offset (nr_need_pages) <= - try_virt_end) - break; - - xen_state.n_mappings--; - } - - xen_state.n_mappings++; - nr_need_pages = map->area.n_pt_pages + xen_state.map_reloc->area.n_pt_pages; - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, - page2offset (nr_need_pages)); - if (err) - return err; - - map->where = get_virtual_current_address (ch); - map->area.pfn_start = 0; - xen_state.max_addr += page2offset (nr_need_pages); - xen_state.state.stack = - xen_state.max_addr + STACK_SIZE + xen_state.xen_inf.virt_base; - xen_state.next_start.nr_pt_frames = nr_need_pages; - xen_state.max_addr = try_virt_end - xen_state.xen_inf.virt_base; - xen_state.pgtbl_end = xen_state.max_addr >> PAGE_SHIFT; - xen_state.map_reloc->where = (grub_uint64_t *) ((char *) map->where + - page2offset (map->area.n_pt_pages)); - - return GRUB_ERR_NONE; -} - -/* Allocate all not yet allocated areas mapped by initial page tables. */ -static grub_err_t -grub_xen_alloc_boot_data (void) -{ - grub_err_t err; - - if (!xen_state.xen_inf.has_p2m_base) - { - err = grub_xen_p2m_alloc (); - if (err) - return err; - } - err = grub_xen_special_alloc (); - if (err) - return err; - err = grub_xen_pt_alloc (); - if (err) - return err; - - return GRUB_ERR_NONE; -} - static grub_err_t grub_xen_boot (void) { + struct grub_relocator_xen_state state; + grub_relocator_chunk_t ch; grub_err_t err; - grub_uint64_t nr_pages; + grub_size_t pgtsize; + struct start_info *nst; + grub_uint64_t nr_info_pages; + grub_uint64_t nr_pages, nr_pt_pages, nr_need_pages; struct gnttab_set_version gnttab_setver; + grub_xen_mfn_t *new_mfn_list; grub_size_t i; if (grub_xen_n_allocated_shared_pages) return grub_error (GRUB_ERR_BUG, "active grants"); - err = grub_xen_alloc_boot_data (); + state.mfn_list = max_addr; + next_start.mfn_list = max_addr + xen_inf.virt_base; + next_start.first_p2m_pfn = max_addr >> PAGE_SHIFT; /* Is this right? */ + pgtsize = sizeof (grub_xen_mfn_t) * grub_xen_start_page_addr->nr_pages; + err = grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, pgtsize); + next_start.nr_p2m_frames = (pgtsize + PAGE_SIZE - 1) >> PAGE_SHIFT; if (err) return err; - if (xen_state.xen_inf.has_p2m_base) + new_mfn_list = get_virtual_current_address (ch); + grub_memcpy (new_mfn_list, + (void *) grub_xen_start_page_addr->mfn_list, pgtsize); + max_addr = ALIGN_UP (max_addr + pgtsize, PAGE_SIZE); + + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + max_addr, sizeof (next_start)); + if (err) + return err; + state.start_info = max_addr + xen_inf.virt_base; + nst = get_virtual_current_address (ch); + max_addr = ALIGN_UP (max_addr + sizeof (next_start), PAGE_SIZE); + + next_start.nr_pages = grub_xen_start_page_addr->nr_pages; + grub_memcpy (next_start.magic, grub_xen_start_page_addr->magic, + sizeof (next_start.magic)); + next_start.store_mfn = grub_xen_start_page_addr->store_mfn; + next_start.store_evtchn = grub_xen_start_page_addr->store_evtchn; + next_start.console.domU = grub_xen_start_page_addr->console.domU; + next_start.shared_info = grub_xen_start_page_addr->shared_info; + + err = set_mfns (new_mfn_list, max_addr >> PAGE_SHIFT); + if (err) + return err; + max_addr += 2 * PAGE_SIZE; + + next_start.pt_base = max_addr + xen_inf.virt_base; + state.paging_start = max_addr >> PAGE_SHIFT; + + nr_info_pages = max_addr >> PAGE_SHIFT; + nr_pages = nr_info_pages; + + while (1) { - err = grub_xen_p2m_alloc (); - if (err) - return err; + nr_pages = ALIGN_UP (nr_pages, (ALIGN_SIZE >> PAGE_SHIFT)); + nr_pt_pages = get_pgtable_size (nr_pages, xen_inf.virt_base); + nr_need_pages = + nr_info_pages + nr_pt_pages + + ((ADDITIONAL_SIZE + STACK_SIZE) >> PAGE_SHIFT); + if (nr_pages >= nr_need_pages) + break; + nr_pages = nr_need_pages; } - err = set_mfns (xen_state.console_pfn); + grub_dprintf ("xen", "bootstrap domain %llx+%llx\n", + (unsigned long long) xen_inf.virt_base, + (unsigned long long) page2offset (nr_pages)); + + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + max_addr, page2offset (nr_pt_pages)); if (err) return err; - nr_pages = xen_state.max_addr >> PAGE_SHIFT; + generate_page_table (get_virtual_current_address (ch), + max_addr >> PAGE_SHIFT, nr_pages, + xen_inf.virt_base, new_mfn_list); - grub_dprintf ("xen", "bootstrap domain %llx+%llx\n", - (unsigned long long) xen_state.xen_inf.virt_base, - (unsigned long long) page2offset (nr_pages)); + max_addr += page2offset (nr_pt_pages); + state.stack = max_addr + STACK_SIZE + xen_inf.virt_base; + state.entry_point = xen_inf.entry_point; - xen_state.map_reloc->area.pfn_start = nr_pages; - generate_page_table (xen_state.virt_mfn_list); + next_start.nr_p2m_frames += nr_pt_pages; + next_start.nr_pt_frames = nr_pt_pages; + state.paging_size = nr_pt_pages; - xen_state.state.entry_point = xen_state.xen_inf.entry_point; - - *xen_state.virt_start_info = xen_state.next_start; + *nst = next_start; grub_memset (&gnttab_setver, 0, sizeof (gnttab_setver)); @@ -536,27 +308,19 @@ grub_xen_boot (void) for (i = 0; i < ARRAY_SIZE (grub_xen_shared_info->evtchn_pending); i++) grub_xen_shared_info->evtchn_pending[i] = 0; - return grub_relocator_xen_boot (xen_state.relocator, xen_state.state, nr_pages, - xen_state.xen_inf.virt_base < + return grub_relocator_xen_boot (relocator, state, nr_pages, + xen_inf.virt_base < PAGE_SIZE ? page2offset (nr_pages) : 0, - xen_state.pgtbl_end - 1, - page2offset (xen_state.pgtbl_end - 1) + - xen_state.xen_inf.virt_base); -} - -static void -grub_xen_reset (void) -{ - grub_relocator_unload (xen_state.relocator); - - grub_memset (&xen_state, 0, sizeof (xen_state)); + nr_pages - 1, + page2offset (nr_pages - 1) + + xen_inf.virt_base); } static grub_err_t grub_xen_unload (void) { - grub_xen_reset (); grub_dl_unref (my_mod); + loaded = 0; return GRUB_ERR_NONE; } @@ -633,28 +397,22 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), grub_file_t file; grub_elf_t elf; grub_err_t err; - void *kern_chunk_src; - grub_relocator_chunk_t ch; - grub_addr_t kern_start; - grub_addr_t kern_end; - grub_size_t sz; if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - /* Call grub_loader_unset early to avoid it being called by grub_loader_set */ grub_loader_unset (); - grub_xen_reset (); + grub_memset (&next_start, 0, sizeof (next_start)); - err = grub_create_loader_cmdline (argc - 1, argv + 1, - (char *) xen_state.next_start.cmd_line, - sizeof (xen_state.next_start.cmd_line) - 1, - GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - return err; + xen_module_info_page = NULL; + n_modules = 0; - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + grub_create_loader_cmdline (argc - 1, argv + 1, + (char *) next_start.cmd_line, + sizeof (next_start.cmd_line) - 1); + + file = grub_file_open (argv[0]); if (!file) return grub_errno; @@ -662,104 +420,99 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), if (!elf) goto fail; - err = grub_xen_get_info (elf, &xen_state.xen_inf); + err = grub_xen_get_info (elf, &xen_inf); if (err) goto fail; #ifdef __x86_64__ - if (xen_state.xen_inf.arch != GRUB_XEN_FILE_X86_64) + if (xen_inf.arch != GRUB_XEN_FILE_X86_64) #else - if (xen_state.xen_inf.arch != GRUB_XEN_FILE_I386_PAE - && xen_state.xen_inf.arch != GRUB_XEN_FILE_I386_PAE_BIMODE) + if (xen_inf.arch != GRUB_XEN_FILE_I386_PAE + && xen_inf.arch != GRUB_XEN_FILE_I386_PAE_BIMODE) #endif { grub_error (GRUB_ERR_BAD_OS, "incompatible architecture: %d", - xen_state.xen_inf.arch); + xen_inf.arch); goto fail; } - if (xen_state.xen_inf.virt_base & (PAGE_SIZE - 1)) + if (xen_inf.virt_base & (PAGE_SIZE - 1)) { grub_error (GRUB_ERR_BAD_OS, "unaligned virt_base"); goto fail; } grub_dprintf ("xen", "virt_base = %llx, entry = %llx\n", - (unsigned long long) xen_state.xen_inf.virt_base, - (unsigned long long) xen_state.xen_inf.entry_point); + (unsigned long long) xen_inf.virt_base, + (unsigned long long) xen_inf.entry_point); - xen_state.relocator = grub_relocator_new (); - if (!xen_state.relocator) + relocator = grub_relocator_new (); + if (!relocator) goto fail; - kern_start = xen_state.xen_inf.kern_start - xen_state.xen_inf.paddr_offset; - kern_end = xen_state.xen_inf.kern_end - xen_state.xen_inf.paddr_offset; + grub_relocator_chunk_t ch; + grub_addr_t kern_start = xen_inf.kern_start - xen_inf.paddr_offset; + grub_addr_t kern_end = xen_inf.kern_end - xen_inf.paddr_offset; - if (xen_state.xen_inf.has_hypercall_page) + if (xen_inf.has_hypercall_page) { grub_dprintf ("xen", "hypercall page at 0x%llx\n", - (unsigned long long) xen_state.xen_inf.hypercall_page); - kern_start = grub_min (kern_start, xen_state.xen_inf.hypercall_page - - xen_state.xen_inf.virt_base); - kern_end = grub_max (kern_end, xen_state.xen_inf.hypercall_page - - xen_state.xen_inf.virt_base + PAGE_SIZE); + (unsigned long long) xen_inf.hypercall_page); + if (xen_inf.hypercall_page - xen_inf.virt_base < kern_start) + kern_start = xen_inf.hypercall_page - xen_inf.virt_base; + + if (xen_inf.hypercall_page - xen_inf.virt_base + PAGE_SIZE > kern_end) + kern_end = xen_inf.hypercall_page - xen_inf.virt_base + PAGE_SIZE; } - xen_state.max_addr = ALIGN_UP (kern_end, PAGE_SIZE); + max_addr = ALIGN_UP (kern_end, PAGE_SIZE); - - if (grub_sub (kern_end, kern_start, &sz)) - { - err = GRUB_ERR_OUT_OF_RANGE; - goto fail; - } - - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, sz); + err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start, + kern_end - kern_start); if (err) goto fail; kern_chunk_src = get_virtual_current_address (ch); grub_dprintf ("xen", "paddr_offset = 0x%llx\n", - (unsigned long long) xen_state.xen_inf.paddr_offset); + (unsigned long long) xen_inf.paddr_offset); grub_dprintf ("xen", "kern_start = 0x%llx, kern_end = 0x%llx\n", - (unsigned long long) xen_state.xen_inf.kern_start, - (unsigned long long) xen_state.xen_inf.kern_end); + (unsigned long long) xen_inf.kern_start, + (unsigned long long) xen_inf.kern_end); err = grub_elfXX_load (elf, argv[0], (grub_uint8_t *) kern_chunk_src - kern_start - - xen_state.xen_inf.paddr_offset, 0, 0, 0); + - xen_inf.paddr_offset, 0, 0, 0); - if (xen_state.xen_inf.has_hypercall_page) + if (xen_inf.has_hypercall_page) { unsigned i; for (i = 0; i < PAGE_SIZE / HYPERCALL_INTERFACE_SIZE; i++) set_hypercall_interface ((grub_uint8_t *) kern_chunk_src + i * HYPERCALL_INTERFACE_SIZE + - xen_state.xen_inf.hypercall_page - - xen_state.xen_inf.virt_base - kern_start, i); + xen_inf.hypercall_page - xen_inf.virt_base - + kern_start, i); } if (err) goto fail; grub_dl_ref (my_mod); - xen_state.loaded = 1; + loaded = 1; grub_loader_set (grub_xen_boot, grub_xen_unload, 0); + loaded = 1; goto fail; fail: - /* grub_errno might be clobbered by further calls, save the error reason. */ - err = grub_errno; if (elf) grub_elf_close (elf); else if (file) grub_file_close (file); - if (err != GRUB_ERR_NONE) - grub_xen_reset (); + if (grub_errno != GRUB_ERR_NONE) + loaded = 0; - return err; + return grub_errno; } static grub_err_t @@ -768,7 +521,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { grub_size_t size = 0; grub_err_t err; - struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; + struct grub_linux_initrd_context initrd_ctx; grub_relocator_chunk_t ch; if (argc == 0) @@ -777,26 +530,19 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } - if (!xen_state.loaded) + if (!loaded) { grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); goto fail; } - if (xen_state.next_start.mod_start || xen_state.next_start.mod_len) + if (next_start.mod_start || next_start.mod_len) { grub_error (GRUB_ERR_BAD_ARGUMENT, N_("initrd already loaded")); goto fail; } - if (xen_state.xen_inf.unmapped_initrd) - { - err = grub_xen_alloc_boot_data (); - if (err) - goto fail; - } - if (grub_initrd_init (argc, argv, &initrd_ctx)) goto fail; @@ -804,32 +550,22 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (size) { - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, size); + err = grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); if (err) - goto fail; + return err; if (grub_initrd_load (&initrd_ctx, argv, get_virtual_current_address (ch))) goto fail; } - xen_state.next_start.mod_len = size; + next_start.mod_start = max_addr + xen_inf.virt_base; + next_start.mod_len = size; - if (xen_state.xen_inf.unmapped_initrd) - { - xen_state.next_start.flags |= SIF_MOD_START_PFN; - xen_state.next_start.mod_start = xen_state.max_addr >> PAGE_SHIFT; - } - else - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; + max_addr = ALIGN_UP (max_addr + size, PAGE_SIZE); grub_dprintf ("xen", "Initrd, addr=0x%x, size=0x%x\n", - (unsigned) (xen_state.max_addr + xen_state.xen_inf.virt_base), - (unsigned) size); - - xen_state.max_addr = ALIGN_UP (xen_state.max_addr + size, PAGE_SIZE); + (unsigned) next_start.mod_start, (unsigned) size); fail: grub_initrd_close (&initrd_ctx); @@ -861,77 +597,69 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - if (!xen_state.loaded) + if (!loaded) { return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); } - if ((xen_state.next_start.mod_start || xen_state.next_start.mod_len) && - !xen_state.module_info_page) + if ((next_start.mod_start || next_start.mod_len) && !xen_module_info_page) { return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("initrd already loaded")); } /* Leave one space for terminator. */ - if (xen_state.n_modules >= MAX_MODULES - 1) + if (n_modules >= MAX_MODULES - 1) { return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many modules"); } - if (!xen_state.module_info_page) + if (!xen_module_info_page) { - xen_state.xen_inf.unmapped_initrd = 0; - xen_state.n_modules = 0; - xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE); - xen_state.modules_target_start = xen_state.max_addr; - xen_state.next_start.mod_start = - xen_state.max_addr + xen_state.xen_inf.virt_base; - xen_state.next_start.flags |= SIF_MULTIBOOT_MOD; + n_modules = 0; + max_addr = ALIGN_UP (max_addr, PAGE_SIZE); + modules_target_start = max_addr; + next_start.mod_start = max_addr + xen_inf.virt_base; + next_start.flags |= SIF_MULTIBOOT_MOD; - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, MAX_MODULES + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + max_addr, MAX_MODULES * - sizeof (xen_state.module_info_page + sizeof (xen_module_info_page [0])); if (err) return err; - xen_state.module_info_page = get_virtual_current_address (ch); - grub_memset (xen_state.module_info_page, 0, MAX_MODULES - * sizeof (xen_state.module_info_page[0])); - xen_state.max_addr += - MAX_MODULES * sizeof (xen_state.module_info_page[0]); + xen_module_info_page = get_virtual_current_address (ch); + grub_memset (xen_module_info_page, 0, MAX_MODULES + * sizeof (xen_module_info_page[0])); + max_addr += MAX_MODULES * sizeof (xen_module_info_page[0]); } - xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE); + max_addr = ALIGN_UP (max_addr, PAGE_SIZE); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD | - (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : GRUB_FILE_TYPE_NONE)); + if (nounzip) + grub_file_filter_disable_compression (); + file = grub_file_open (argv[0]); if (!file) return grub_errno; size = grub_file_size (file); cmdline_len = grub_loader_cmdline_size (argc - 1, argv + 1); - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, cmdline_len); + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + max_addr, cmdline_len); if (err) goto fail; - err = grub_create_loader_cmdline (argc - 1, argv + 1, - get_virtual_current_address (ch), cmdline_len, - GRUB_VERIFY_MODULE_CMDLINE); - if (err) - goto fail; + grub_create_loader_cmdline (argc - 1, argv + 1, + get_virtual_current_address (ch), cmdline_len); - xen_state.module_info_page[xen_state.n_modules].cmdline = - xen_state.max_addr - xen_state.modules_target_start; - xen_state.max_addr = ALIGN_UP (xen_state.max_addr + cmdline_len, PAGE_SIZE); + xen_module_info_page[n_modules].cmdline = max_addr - modules_target_start; + max_addr = ALIGN_UP (max_addr + cmdline_len, PAGE_SIZE); if (size) { - err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, - xen_state.max_addr, size); + err = grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); if (err) goto fail; if (grub_file_read (file, get_virtual_current_address (ch), size) @@ -943,17 +671,15 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), goto fail; } } - xen_state.next_start.mod_len = - xen_state.max_addr + size - xen_state.modules_target_start; - xen_state.module_info_page[xen_state.n_modules].mod_start = - xen_state.max_addr - xen_state.modules_target_start; - xen_state.module_info_page[xen_state.n_modules].mod_end = - xen_state.max_addr + size - xen_state.modules_target_start; + next_start.mod_len = max_addr + size - modules_target_start; + xen_module_info_page[n_modules].mod_start = max_addr - modules_target_start; + xen_module_info_page[n_modules].mod_end = + max_addr + size - modules_target_start; - xen_state.n_modules++; + n_modules++; grub_dprintf ("xen", "module, addr=0x%x, size=0x%x\n", - (unsigned) xen_state.max_addr, (unsigned) size); - xen_state.max_addr = ALIGN_UP (xen_state.max_addr + size, PAGE_SIZE); + (unsigned) max_addr, (unsigned) size); + max_addr = ALIGN_UP (max_addr + size, PAGE_SIZE); fail: diff --git a/grub-core/loader/i386/xen_file.c b/grub-core/loader/i386/xen_file.c index 9af5d66df..583621890 100644 --- a/grub-core/loader/i386/xen_file.c +++ b/grub-core/loader/i386/xen_file.c @@ -20,16 +20,12 @@ #include #include -#define XZ_MAGIC "\3757zXZ\0" - grub_elf_t grub_xen_file (grub_file_t file) { grub_elf_t elf; - struct linux_i386_kernel_header lh; + struct linux_kernel_header lh; grub_file_t off_file; - grub_uint32_t payload_offset, payload_length; - grub_uint8_t magic[6]; elf = grub_elf_file (file, file->name); if (elf) @@ -43,43 +39,27 @@ grub_xen_file (grub_file_t file) goto fail; if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55) - || lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + || lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE) || grub_le_to_cpu16 (lh.version) < 0x0208) { grub_error (GRUB_ERR_BAD_OS, "version too old for xen boot"); return NULL; } - payload_length = lh.payload_length; - payload_offset = (lh.setup_sects + 1) * 512 - + lh.payload_offset; - - if (payload_length < sizeof (magic)) + if (lh.payload_length < 4) { grub_error (GRUB_ERR_BAD_OS, "payload too short"); return NULL; } grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n", - (unsigned long long) payload_offset, - (unsigned long long) lh.payload_length); + (unsigned long long) (lh.setup_sects + 1) * 512 + + lh.payload_offset, + (unsigned long long) lh.payload_length - 4); - grub_file_seek (file, payload_offset); - - if (grub_file_read (file, &magic, sizeof (magic)) != sizeof (magic)) - { - if (!grub_errno) - grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), - file->name); - goto fail; - } - - /* Kernel suffixes xz payload with their uncompressed size. - Trim it. */ - if (grub_memcmp (magic, XZ_MAGIC, sizeof (XZ_MAGIC) - 1) == 0) - payload_length -= 4; - off_file = grub_file_offset_open (file, GRUB_FILE_TYPE_LINUX_KERNEL, payload_offset, - payload_length); + off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512 + + lh.payload_offset, + lh.payload_length - 4); if (!off_file) goto fail; diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c index 27afcaacb..1ba5649e2 100644 --- a/grub-core/loader/i386/xen_fileXX.c +++ b/grub-core/loader/i386/xen_fileXX.c @@ -18,17 +18,14 @@ #include #include -#include static grub_err_t parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, grub_off_t off, grub_size_t sz) { char *buf; - const char *ptr; + char *ptr; int has_paddr = 0; - - grub_errno = GRUB_ERR_NONE; if (grub_file_seek (elf->file, off) == (grub_off_t) -1) return grub_errno; buf = grub_malloc (sz); @@ -38,8 +35,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, if (grub_file_read (elf->file, buf, sz) != (grub_ssize_t) sz) { if (grub_errno) - goto out; - grub_free (buf); + return grub_errno; return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), elf->file->name); } @@ -127,14 +123,14 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, { xi->virt_base = grub_strtoull (ptr + sizeof ("VIRT_BASE=") - 1, &ptr, 16); if (grub_errno) - goto out; + return grub_errno; continue; } if (grub_strncmp (ptr, "VIRT_ENTRY=", sizeof ("VIRT_ENTRY=") - 1) == 0) { xi->entry_point = grub_strtoull (ptr + sizeof ("VIRT_ENTRY=") - 1, &ptr, 16); if (grub_errno) - goto out; + return grub_errno; continue; } if (grub_strncmp (ptr, "HYPERCALL_PAGE=", sizeof ("HYPERCALL_PAGE=") - 1) == 0) @@ -142,7 +138,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->hypercall_page = grub_strtoull (ptr + sizeof ("HYPERCALL_PAGE=") - 1, &ptr, 16); xi->has_hypercall_page = 1; if (grub_errno) - goto out; + return grub_errno; continue; } if (grub_strncmp (ptr, "ELF_PADDR_OFFSET=", sizeof ("ELF_PADDR_OFFSET=") - 1) == 0) @@ -150,7 +146,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->paddr_offset = grub_strtoull (ptr + sizeof ("ELF_PADDR_OFFSET=") - 1, &ptr, 16); has_paddr = 1; if (grub_errno) - goto out; + return grub_errno; continue; } } @@ -158,11 +154,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, xi->hypercall_page = (xi->hypercall_page << 12) + xi->virt_base; if (!has_paddr) xi->paddr_offset = xi->virt_base; - -out: - grub_free (buf); - - return grub_errno; + return GRUB_ERR_NONE; } #pragma GCC diagnostic ignored "-Wcast-align" @@ -204,35 +196,35 @@ parse_note (grub_elf_t elf, struct grub_xen_file_info *xi, xi->has_note = 1; switch (nh->n_type) { - case XEN_ELFNOTE_ENTRY: + case 1: xi->entry_point = grub_le_to_cpu_addr (*(Elf_Addr *) desc); break; - case XEN_ELFNOTE_HYPERCALL_PAGE: + case 2: xi->hypercall_page = grub_le_to_cpu_addr (*(Elf_Addr *) desc); xi->has_hypercall_page = 1; break; - case XEN_ELFNOTE_VIRT_BASE: + case 3: xi->virt_base = grub_le_to_cpu_addr (*(Elf_Addr *) desc); break; - case XEN_ELFNOTE_PADDR_OFFSET: + case 4: xi->paddr_offset = grub_le_to_cpu_addr (*(Elf_Addr *) desc); break; - case XEN_ELFNOTE_XEN_VERSION: + case 5: grub_dprintf ("xen", "xenversion = `%s'\n", (char *) desc); break; - case XEN_ELFNOTE_GUEST_OS: + case 6: grub_dprintf ("xen", "name = `%s'\n", (char *) desc); break; - case XEN_ELFNOTE_GUEST_VERSION: + case 7: grub_dprintf ("xen", "version = `%s'\n", (char *) desc); break; - case XEN_ELFNOTE_LOADER: + case 8: if (descsz < 7 || grub_memcmp (desc, "generic", descsz == 7 ? 7 : 8) != 0) return grub_error (GRUB_ERR_BAD_OS, "invalid loader"); break; /* PAE */ - case XEN_ELFNOTE_PAE_MODE: + case 9: grub_dprintf ("xen", "pae = `%s', %d, %d\n", (char *) desc, xi->arch, descsz); if (xi->arch != GRUB_XEN_FILE_I386 @@ -261,13 +253,6 @@ parse_note (grub_elf_t elf, struct grub_xen_file_info *xi, descsz == 2 ? 2 : 3) == 0) xi->arch = GRUB_XEN_FILE_I386; break; - case XEN_ELFNOTE_INIT_P2M: - xi->p2m_base = grub_le_to_cpu_addr (*(Elf_Addr *) desc); - xi->has_p2m_base = 1; - break; - case XEN_ELFNOTE_MOD_START_PFN: - xi->unmapped_initrd = !!grub_le_to_cpu32(*(grub_uint32_t *) desc); - break; default: grub_dprintf ("xen", "unknown note type %d\n", nh->n_type); break; @@ -344,23 +329,6 @@ grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; - for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); - s = (Elf_Shdr *) ((char *) s + shentsize)) - { - if (s->sh_type == SHT_NOTE) - { - err = parse_note (elf, xi, s->sh_offset, s->sh_size); - if (err) - goto cleanup; - } - } - - if (xi->has_note) - { - err = GRUB_ERR_NONE; - goto cleanup; - } - for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); s = (Elf_Shdr *) ((char *) s + shentsize)) { diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index a70093607..e0506a676 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -35,7 +35,6 @@ #include #include #include -#include #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) @@ -262,19 +261,20 @@ grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev, if (!prop) return grub_errno; - prop->data = grub_malloc (datalen); - if (!prop->data) - { - grub_free (prop); - return grub_errno; - } - grub_memcpy (prop->data, data, datalen); - prop->name = utf8; prop->name16 = utf16; prop->name16len = utf16len; - prop->length = datalen; + prop->length = datalen; + prop->data = grub_malloc (prop->length); + if (!prop->data) + { + grub_free (prop); + grub_free (prop->name); + grub_free (prop->name16); + return grub_errno; + } + grub_memcpy (prop->data, data, prop->length); grub_list_push (GRUB_AS_LIST_P (&dev->properties), GRUB_AS_LIST (prop)); return GRUB_ERR_NONE; @@ -294,7 +294,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d return grub_errno; len = grub_strlen (name); - utf16 = grub_calloc (len, sizeof (grub_uint16_t)); + utf16 = grub_malloc (sizeof (grub_uint16_t) * len); if (!utf16) { grub_free (utf8); @@ -330,7 +330,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * grub_uint16_t *utf16; grub_err_t err; - utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); + utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); if (!utf16) return grub_errno; grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); @@ -338,7 +338,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * utf8 = grub_malloc (namelen * 4 + 1); if (!utf8) { - grub_free (utf16); + grub_free (utf8); return grub_errno; } @@ -486,7 +486,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), if (argc != 1) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (args[0], GRUB_FILE_XNU_DEVPROP); + file = grub_file_open (args[0]); if (! file) return grub_errno; size = grub_file_size (file); @@ -515,15 +515,14 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), devhead = buf; buf = devhead + 1; - dp = dpstart = buf; + dpstart = buf; - while (GRUB_EFI_DEVICE_PATH_VALID (dp) && buf < bufend) + do { - buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp); - if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) - break; dp = buf; + buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp); } + while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp) && buf < bufend); dev = grub_xnu_devprop_add_device (dpstart, (char *) buf - (char *) dpstart); @@ -578,31 +577,11 @@ static grub_err_t grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out) { struct grub_xnu_devtree_key *efikey; - struct grub_xnu_devtree_key *chosenkey; struct grub_xnu_devtree_key *cfgtablekey; struct grub_xnu_devtree_key *curval; struct grub_xnu_devtree_key *runtimesrvkey; struct grub_xnu_devtree_key *platformkey; unsigned i, j; - grub_err_t err; - - chosenkey = grub_xnu_create_key (&grub_xnu_devtree_root, "chosen"); - if (! chosenkey) - return grub_errno; - - /* Random seed. */ - curval = grub_xnu_create_value (&(chosenkey->first_child), "random-seed"); - if (! curval) - return grub_errno; - curval->datasize = 64; - curval->data = grub_malloc (curval->datasize); - if (! curval->data) - return grub_errno; - /* Our random is not peer-reviewed but xnu uses this seed only for - ASLR in kernel. */ - err = grub_crypto_get_random (curval->data, curval->datasize); - if (err) - return err; /* The value "model". */ /* FIXME: may this value be sometimes different? */ @@ -918,28 +897,6 @@ grub_xnu_set_video (struct grub_xnu_boot_params_common *params) return GRUB_ERR_NONE; } -static int -total_ram_hook (grub_uint64_t addr __attribute__ ((unused)), grub_uint64_t size, - grub_memory_type_t type, - void *data) -{ - grub_uint64_t *result = data; - - if (type != GRUB_MEMORY_AVAILABLE) - return 0; - *result += size; - return 0; -} - -static grub_uint64_t -get_total_ram (void) -{ - grub_uint64_t result = 0; - - grub_mmap_iterate (total_ram_hook, &result); - return result; -} - /* Boot xnu. */ grub_err_t grub_xnu_boot (void) @@ -1016,7 +973,6 @@ grub_xnu_boot (void) { bootparams_common = &bootparams->v2.common; bootparams->v2.fsbfreq = fsbfreq; - bootparams->v2.ram_size = get_total_ram(); } else bootparams_common = &bootparams->v1.common; @@ -1124,7 +1080,7 @@ grub_xnu_boot (void) bootparams_common->efi_mmap = memory_map_target; bootparams_common->efi_mmap_size = memory_map_size; bootparams_common->heap_start = grub_xnu_heap_target_start; - bootparams_common->heap_size = curruntimepage * GRUB_XNU_PAGESIZE - grub_xnu_heap_target_start; + bootparams_common->heap_size = grub_xnu_heap_size; /* Parameters for asm helper. */ grub_xnu_stack = bootparams_common->heap_start diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 7987fd1ba..efaa42ccd 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -33,7 +33,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -134,6 +133,48 @@ query_fpswa (void) } } +/* Find the optimal number of pages for the memory map. Is it better to + move this code to efi/mm.c? */ +static grub_efi_uintn_t +find_mmap_size (void) +{ + static grub_efi_uintn_t mmap_size = 0; + + if (mmap_size != 0) + return mmap_size; + + mmap_size = (1 << 12); + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + + mmap = grub_malloc (mmap_size); + if (! mmap) + return 0; + + ret = grub_efi_get_memory_map (&mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + { + grub_error (GRUB_ERR_IO, "cannot get memory map"); + return 0; + } + else if (ret > 0) + break; + + mmap_size += (1 << 12); + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + mmap_size += (1 << 12); + + return page_align (mmap_size); +} + static void free_pages (void) { @@ -171,7 +212,7 @@ allocate_pages (grub_uint64_t align, grub_uint64_t size_pages, size = size_pages << 12; - mmap_size = grub_efi_find_mmap_size (); + mmap_size = find_mmap_size (); if (!mmap_size) return 0; @@ -211,7 +252,7 @@ allocate_pages (grub_uint64_t align, grub_uint64_t size_pages, aligned_start += align; if (aligned_start + size > end) continue; - mem = grub_efi_allocate_fixed (aligned_start, size_pages); + mem = grub_efi_allocate_pages (aligned_start, size_pages); if (! mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate memory"); @@ -282,10 +323,10 @@ grub_linux_boot (void) /* MDT. Must be done after grub_machine_fini because map_key is used by exit_boot_services. */ - mmap_size = grub_efi_find_mmap_size (); + mmap_size = find_mmap_size (); if (! mmap_size) return grub_errno; - mmap_buf = grub_efi_allocate_any_pages (page_align (mmap_size) >> 12); + mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12); if (! mmap_buf) return grub_error (GRUB_ERR_IO, "cannot allocate memory map"); err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key, @@ -381,7 +422,7 @@ grub_load_elf64 (grub_file_t file, void *buffer, const char *filename) relocate = grub_env_get ("linux_relocate"); if (!relocate || grub_strcmp (relocate, "force") != 0) { - kernel_mem = grub_efi_allocate_fixed (low_addr, kernel_pages); + kernel_mem = grub_efi_allocate_pages (low_addr, kernel_pages); reloc_offset = 0; } /* Try to relocate. */ @@ -460,7 +501,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto fail; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (! file) goto fail; @@ -483,7 +524,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), len += grub_strlen (argv[i]) + 1; len += sizeof (struct ia64_boot_param) + 512; /* Room for extensions. */ boot_param_pages = page_align (len) >> 12; - boot_param = grub_efi_allocate_any_pages (boot_param_pages); + boot_param = grub_efi_allocate_pages (0, boot_param_pages); if (boot_param == 0) { grub_error (GRUB_ERR_OUT_OF_MEMORY, @@ -502,11 +543,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), p = grub_stpcpy (p, argv[i]); } cmdline[10] = '='; - - *p = '\0'; - - if (grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE)) - goto fail; boot_param->command_line = (grub_uint64_t) cmdline; boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table; @@ -553,7 +589,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), grub_dprintf ("linux", "Loading initrd\n"); initrd_pages = (page_align (initrd_size) >> 12); - initrd_mem = grub_efi_allocate_any_pages (initrd_pages); + initrd_mem = grub_efi_allocate_pages (0, initrd_pages); if (! initrd_mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate pages"); diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c index 3fe390f17..117232f0c 100644 --- a/grub-core/loader/linux.c +++ b/grub-core/loader/linux.c @@ -4,7 +4,6 @@ #include #include #include -#include struct newc_head { @@ -99,13 +98,13 @@ free_dir (struct dir *root) grub_free (root); } -static grub_err_t +static grub_size_t insert_dir (const char *name, struct dir **root, - grub_uint8_t *ptr, grub_size_t *size) + grub_uint8_t *ptr) { struct dir *cur, **head = root; const char *cb, *ce = name; - *size = 0; + grub_size_t size = 0; while (1) { for (cb = ce; *cb == '/'; cb++); @@ -131,22 +130,14 @@ insert_dir (const char *name, struct dir **root, ptr = make_header (ptr, name, ce - name, 040777, 0); } - if (grub_add (*size, - ALIGN_UP ((ce - (char *) name) - + sizeof (struct newc_head), 4), - size)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - grub_free (n->name); - grub_free (n); - return grub_errno; - } + size += ALIGN_UP ((ce - (char *) name) + + sizeof (struct newc_head), 4); *head = n; cur = n; } root = &cur->next; } - return GRUB_ERR_NONE; + return size; } grub_err_t @@ -160,7 +151,8 @@ grub_initrd_init (int argc, char *argv[], initrd_ctx->nfiles = 0; initrd_ctx->components = 0; - initrd_ctx->components = grub_calloc (argc, sizeof (initrd_ctx->components[0])); + initrd_ctx->components = grub_zalloc (argc + * sizeof (initrd_ctx->components[0])); if (!initrd_ctx->components) return grub_errno; @@ -169,9 +161,6 @@ grub_initrd_init (int argc, char *argv[], for (i = 0; i < argc; i++) { const char *fname = argv[i]; - - initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); - if (grub_memcmp (argv[i], "newc:", 5) == 0) { const char *ptr, *eptr; @@ -181,40 +170,33 @@ grub_initrd_init (int argc, char *argv[], eptr = grub_strchr (ptr, ':'); if (eptr) { - grub_size_t dir_size, name_len; - + grub_file_filter_disable_compression (); initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr); - if (!initrd_ctx->components[i].newc_name || - insert_dir (initrd_ctx->components[i].newc_name, &root, 0, - &dir_size)) + if (!initrd_ctx->components[i].newc_name) { grub_initrd_close (initrd_ctx); return grub_errno; } - name_len = grub_strlen (initrd_ctx->components[i].newc_name); - if (grub_add (initrd_ctx->size, - ALIGN_UP (sizeof (struct newc_head) + name_len, 4), - &initrd_ctx->size) || - grub_add (initrd_ctx->size, dir_size, &initrd_ctx->size)) - goto overflow; + initrd_ctx->size + += ALIGN_UP (sizeof (struct newc_head) + + grub_strlen (initrd_ctx->components[i].newc_name), + 4); + initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name, + &root, 0); newc = 1; fname = eptr + 1; } } else if (newc) { - if (grub_add (initrd_ctx->size, - ALIGN_UP (sizeof (struct newc_head) - + sizeof ("TRAILER!!!") - 1, 4), - &initrd_ctx->size)) - goto overflow; + initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) + + sizeof ("TRAILER!!!") - 1, 4); free_dir (root); root = 0; newc = 0; } - initrd_ctx->components[i].file = grub_file_open (fname, - GRUB_FILE_TYPE_LINUX_INITRD - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + initrd_ctx->components[i].file = grub_file_open (fname); if (!initrd_ctx->components[i].file) { grub_initrd_close (initrd_ctx); @@ -223,29 +205,18 @@ grub_initrd_init (int argc, char *argv[], initrd_ctx->nfiles++; initrd_ctx->components[i].size = grub_file_size (initrd_ctx->components[i].file); - if (grub_add (initrd_ctx->size, initrd_ctx->components[i].size, - &initrd_ctx->size)) - goto overflow; + initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4); } if (newc) { - initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); - if (grub_add (initrd_ctx->size, - ALIGN_UP (sizeof (struct newc_head) - + sizeof ("TRAILER!!!") - 1, 4), - &initrd_ctx->size)) - goto overflow; + initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) + + sizeof ("TRAILER!!!") - 1, 4); free_dir (root); root = 0; } return GRUB_ERR_NONE; - - overflow: - free_dir (root); - grub_initrd_close (initrd_ctx); - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); } grub_size_t @@ -277,25 +248,15 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, int i; int newc = 0; struct dir *root = 0; - grub_ssize_t cursize = 0; for (i = 0; i < initrd_ctx->nfiles; i++) { - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr += ALIGN_UP_OVERHEAD (cursize, 4); + grub_ssize_t cursize; if (initrd_ctx->components[i].newc_name) { - grub_size_t dir_size; - - if (insert_dir (initrd_ctx->components[i].newc_name, &root, ptr, - &dir_size)) - { - free_dir (root); - grub_initrd_close (initrd_ctx); - return grub_errno; - } - ptr += dir_size; + ptr += insert_dir (initrd_ctx->components[i].newc_name, + &root, ptr); ptr = make_header (ptr, initrd_ctx->components[i].newc_name, grub_strlen (initrd_ctx->components[i].newc_name), 0100777, @@ -322,13 +283,11 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, return grub_errno; } ptr += cursize; - } - if (newc) - { grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); ptr += ALIGN_UP_OVERHEAD (cursize, 4); - ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); } + if (newc) + ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); free_dir (root); root = 0; return GRUB_ERR_NONE; diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c index 05710c48e..59b195e27 100644 --- a/grub-core/loader/macho.c +++ b/grub-core/loader/macho.c @@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) == (grub_off_t) -1) goto fail; - archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); if (!archs) goto fail; if (grub_file_read (macho->file, archs, @@ -188,12 +188,12 @@ fail: } grub_macho_t -grub_macho_open (const char *name, enum grub_file_type type, int is_64bit) +grub_macho_open (const char *name, int is_64bit) { grub_file_t file; grub_macho_t macho; - file = grub_file_open (name, type); + file = grub_file_open (name); if (! file) return 0; diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index e4ed95921..5f383be3d 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -237,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + elf = grub_elf_open (argv[0]); if (! elf) return grub_errno; @@ -314,7 +314,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_memcpy (params, LINUX_IMAGE, sizeof (LINUX_IMAGE)); grub_create_loader_cmdline (argc, argv, params + sizeof (LINUX_IMAGE) - 1, - size, GRUB_VERIFY_KERNEL_CMDLINE); + size); #else linux_argv = extra; argv_off = (grub_uint8_t *) linux_argv - (grub_uint8_t *) playground; @@ -327,8 +327,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_argv++; linux_args += ALIGN_UP (sizeof ("a0"), 4); - char *params = linux_args; - #ifdef GRUB_MACHINE_MIPS_LOONGSON { unsigned mtype = grub_arch_machine; @@ -354,12 +352,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); } - *linux_args = '\0'; - - err = grub_verify_string (params, GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - return err; - /* Reserve space for rd arguments. */ rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground; linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4); @@ -442,9 +434,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), { grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, (target_addr & 0x1fffffff) + - linux_size + 0x10000, 0x10000000, size, - 0x10000, GRUB_RELOCATOR_PREFERENCE_NONE, 0); + err = grub_relocator_alloc_chunk_align (relocator, &ch, + (target_addr & 0x1fffffff) + + linux_size + 0x10000, + (0x10000000 - size), + size, 0x10000, + GRUB_RELOCATOR_PREFERENCE_NONE, 0); if (err) goto fail; diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index facb13f3d..4b71f3363 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -28,15 +28,7 @@ #include #include -#ifdef GRUB_USE_MULTIBOOT2 -#include -#define GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER GRUB_MULTIBOOT2_CONSOLE_FRAMEBUFFER -#define GRUB_MULTIBOOT_CONSOLE_EGA_TEXT GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT -#define GRUB_MULTIBOOT(x) grub_multiboot2_ ## x -#else #include -#define GRUB_MULTIBOOT(x) grub_multiboot_ ## x -#endif #include #include #include @@ -57,8 +49,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); #include #endif -struct grub_relocator *GRUB_MULTIBOOT (relocator) = NULL; -grub_uint32_t GRUB_MULTIBOOT (payload_eip); +struct grub_relocator *grub_multiboot_relocator = NULL; +grub_uint32_t grub_multiboot_payload_eip; #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) #define DEFAULT_VIDEO_MODE "text" #else @@ -86,7 +78,7 @@ count_hook (grub_uint64_t addr __attribute__ ((unused)), /* Return the length of the Multiboot mmap that will be needed to allocate our platform's map. */ grub_uint32_t -GRUB_MULTIBOOT (get_mmap_count) (void) +grub_get_multiboot_mmap_count (void) { grub_size_t count = 0; @@ -96,7 +88,7 @@ GRUB_MULTIBOOT (get_mmap_count) (void) } grub_err_t -GRUB_MULTIBOOT (set_video_mode) (void) +grub_multiboot_set_video_mode (void) { grub_err_t err; const char *modevar; @@ -126,72 +118,24 @@ GRUB_MULTIBOOT (set_video_mode) (void) return err; } -#ifdef GRUB_MACHINE_EFI -#ifdef __x86_64__ -#define grub_relocator_efi_boot grub_relocator64_efi_boot -#define grub_relocator_efi_state grub_relocator64_efi_state -#endif -#endif - -#ifdef grub_relocator_efi_boot -static void -efi_boot (struct grub_relocator *rel, - grub_uint32_t target) -{ -#ifdef GRUB_USE_MULTIBOOT2 - struct grub_relocator_efi_state state_efi = MULTIBOOT2_EFI_INITIAL_STATE; -#else - struct grub_relocator_efi_state state_efi = MULTIBOOT_EFI_INITIAL_STATE; -#endif - state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = GRUB_MULTIBOOT (payload_eip); - state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; - - grub_relocator_efi_boot (rel, state_efi); -} -#else -#define grub_efi_is_finished 1 -static void -efi_boot (struct grub_relocator *rel __attribute__ ((unused)), - grub_uint32_t target __attribute__ ((unused))) -{ -} -#endif - -#if defined (__i386__) || defined (__x86_64__) -static void -normal_boot (struct grub_relocator *rel, struct grub_relocator32_state state) -{ - grub_relocator32_boot (rel, state, 0); -} -#else -static void -normal_boot (struct grub_relocator *rel, struct grub_relocator32_state state) -{ - grub_relocator32_boot (rel, state); -} -#endif - static grub_err_t grub_multiboot_boot (void) { grub_err_t err; - -#ifdef GRUB_USE_MULTIBOOT2 - struct grub_relocator32_state state = MULTIBOOT2_INITIAL_STATE; -#else struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE; -#endif - state.MULTIBOOT_ENTRY_REGISTER = GRUB_MULTIBOOT (payload_eip); - err = GRUB_MULTIBOOT (make_mbi) (&state.MULTIBOOT_MBI_REGISTER); + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + + err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); if (err) return err; - if (grub_efi_is_finished) - normal_boot (GRUB_MULTIBOOT (relocator), state); - else - efi_boot (GRUB_MULTIBOOT (relocator), state.MULTIBOOT_MBI_REGISTER); +#if defined (__i386__) || defined (__x86_64__) + grub_relocator32_boot (grub_multiboot_relocator, state, 0); +#else + grub_relocator32_boot (grub_multiboot_relocator, state); +#endif /* Not reached. */ return GRUB_ERR_NONE; @@ -200,10 +144,10 @@ grub_multiboot_boot (void) static grub_err_t grub_multiboot_unload (void) { - GRUB_MULTIBOOT (free_mbi) (); + grub_multiboot_free_mbi (); - grub_relocator_unload (GRUB_MULTIBOOT (relocator)); - GRUB_MULTIBOOT (relocator) = NULL; + grub_relocator_unload (grub_multiboot_relocator); + grub_multiboot_relocator = NULL; grub_dl_unref (my_mod); @@ -222,20 +166,21 @@ static grub_uint64_t highest_load; /* Load ELF32 or ELF64. */ grub_err_t -GRUB_MULTIBOOT (load_elf) (mbi_load_data_t *mld) +grub_multiboot_load_elf (grub_file_t file, const char *filename, + void *buffer) { - if (grub_multiboot_is_elf32 (mld->buffer)) - return grub_multiboot_load_elf32 (mld); - else if (grub_multiboot_is_elf64 (mld->buffer)) - return grub_multiboot_load_elf64 (mld); + if (grub_multiboot_is_elf32 (buffer)) + return grub_multiboot_load_elf32 (file, filename, buffer); + else if (grub_multiboot_is_elf64 (buffer)) + return grub_multiboot_load_elf64 (file, filename, buffer); return grub_error (GRUB_ERR_UNKNOWN_OS, N_("invalid arch-dependent ELF magic")); } grub_err_t -GRUB_MULTIBOOT (set_console) (int console_type, int accepted_consoles, - int width, int height, int depth, - int console_req) +grub_multiboot_set_console (int console_type, int accepted_consoles, + int width, int height, int depth, + int console_req) { console_required = console_req; if (!(accepted_consoles @@ -295,52 +240,45 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)), #ifndef GRUB_USE_MULTIBOOT2 grub_multiboot_quirks = GRUB_MULTIBOOT_QUIRKS_NONE; - int option_found = 0; - do + if (argc != 0 && grub_strcmp (argv[0], "--quirk-bad-kludge") == 0) { - option_found = 0; - if (argc != 0 && grub_strcmp (argv[0], "--quirk-bad-kludge") == 0) - { - argc--; - argv++; - option_found = 1; - grub_multiboot_quirks |= GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE; - } + argc--; + argv++; + grub_multiboot_quirks |= GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE; + } - if (argc != 0 && grub_strcmp (argv[0], "--quirk-modules-after-kernel") == 0) - { - argc--; - argv++; - option_found = 1; - grub_multiboot_quirks |= GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL; - } - } while (option_found); + if (argc != 0 && grub_strcmp (argv[0], "--quirk-modules-after-kernel") == 0) + { + argc--; + argv++; + grub_multiboot_quirks |= GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL; + } #endif if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_KERNEL); + file = grub_file_open (argv[0]); if (! file) return grub_errno; grub_dl_ref (my_mod); /* Skip filename. */ - GRUB_MULTIBOOT (init_mbi) (argc - 1, argv + 1); + grub_multiboot_init_mbi (argc - 1, argv + 1); - grub_relocator_unload (GRUB_MULTIBOOT (relocator)); - GRUB_MULTIBOOT (relocator) = grub_relocator_new (); + grub_relocator_unload (grub_multiboot_relocator); + grub_multiboot_relocator = grub_relocator_new (); - if (!GRUB_MULTIBOOT (relocator)) + if (!grub_multiboot_relocator) goto fail; - err = GRUB_MULTIBOOT (load) (file, argv[0]); + err = grub_multiboot_load (file, argv[0]); if (err) goto fail; - GRUB_MULTIBOOT (set_bootdev) (); + grub_multiboot_set_bootdev (); grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0); @@ -350,8 +288,8 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)), if (grub_errno != GRUB_ERR_NONE) { - grub_relocator_unload (GRUB_MULTIBOOT (relocator)); - GRUB_MULTIBOOT (relocator) = NULL; + grub_relocator_unload (grub_multiboot_relocator); + grub_multiboot_relocator = NULL; grub_dl_unref (my_mod); } @@ -383,17 +321,18 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); - if (!GRUB_MULTIBOOT (relocator)) + if (!grub_multiboot_relocator) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); - file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_MODULE - | (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : GRUB_FILE_TYPE_NONE)); + if (nounzip) + grub_file_filter_disable_compression (); + + file = grub_file_open (argv[0]); if (! file) return grub_errno; #ifndef GRUB_USE_MULTIBOOT2 - lowest_addr = 0x100000; if (grub_multiboot_quirks & GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL) lowest_addr = ALIGN_UP (highest_load + 1048576, 4096); #endif @@ -402,8 +341,8 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), if (size) { grub_relocator_chunk_t ch; - err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, - lowest_addr, UP_TO_TOP32 (size), + err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + lowest_addr, (0xffffffff - size) + 1, size, MULTIBOOT_MOD_ALIGN, GRUB_RELOCATOR_PREFERENCE_NONE, 1); if (err) @@ -420,7 +359,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), target = 0; } - err = GRUB_MULTIBOOT (add_module) (target, size, argc - 1, argv + 1); + err = grub_multiboot_add_module (target, size, argc - 1, argv + 1); if (err) { grub_file_close (file); diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c index f2318e0d1..9dc21a1ba 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -51,15 +51,11 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) } static grub_err_t -CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) +CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, void *buffer) { - Elf_Ehdr *ehdr = (Elf_Ehdr *) mld->buffer; + Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer; char *phdr_base; - grub_err_t err; - grub_relocator_chunk_t ch; - grub_uint32_t load_offset = 0, load_size; int i; - void *source = NULL; if (ehdr->e_ident[EI_MAG0] != ELFMAG0 || ehdr->e_ident[EI_MAG1] != ELFMAG1 @@ -76,106 +72,57 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) return grub_error (GRUB_ERR_UNKNOWN_OS, N_("this ELF file is not of the right type")); /* FIXME: Should we support program headers at strange locations? */ - if (ehdr->e_phoff + (grub_uint32_t) ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH) + if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH) return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset"); - phdr_base = (char *) mld->buffer + ehdr->e_phoff; + phdr_base = (char *) buffer + ehdr->e_phoff; #define phdr(i) ((Elf_Phdr *) (phdr_base + (i) * ehdr->e_phentsize)) - mld->link_base_addr = ~0; - - /* Calculate lowest and highest load address. */ - for (i = 0; i < ehdr->e_phnum; i++) - if (phdr(i)->p_type == PT_LOAD) - { - mld->link_base_addr = grub_min (mld->link_base_addr, phdr(i)->p_paddr); - highest_load = grub_max (highest_load, phdr(i)->p_paddr + phdr(i)->p_memsz); - } - -#ifdef MULTIBOOT_LOAD_ELF64 - if (highest_load >= 0x100000000) - return grub_error (GRUB_ERR_BAD_OS, "segment crosses 4 GiB border"); -#endif - - if (mld->relocatable) - { - load_size = highest_load - mld->link_base_addr; - - grub_dprintf ("multiboot_loader", "align=0x%lx, preference=0x%x, " - "load_size=0x%x, avoid_efi_boot_services=%d\n", - (long) mld->align, mld->preference, load_size, - mld->avoid_efi_boot_services); - - if (load_size > mld->max_addr || mld->min_addr > mld->max_addr - load_size) - return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); - - err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch, - mld->min_addr, mld->max_addr, - load_size, mld->align ? mld->align : 1, - mld->preference, mld->avoid_efi_boot_services); - - if (err) - { - grub_dprintf ("multiboot_loader", "Cannot allocate memory for OS image\n"); - return err; - } - - mld->load_base_addr = get_physical_target_address (ch); - source = get_virtual_current_address (ch); - } - else - mld->load_base_addr = mld->link_base_addr; - - grub_dprintf ("multiboot_loader", "relocatable=%d, link_base_addr=0x%x, " - "load_base_addr=0x%x\n", mld->relocatable, - mld->link_base_addr, mld->load_base_addr); - /* Load every loadable segment in memory. */ for (i = 0; i < ehdr->e_phnum; i++) { if (phdr(i)->p_type == PT_LOAD) { + grub_err_t err; + void *source; + + if (phdr(i)->p_paddr + phdr(i)->p_memsz > highest_load) + highest_load = phdr(i)->p_paddr + phdr(i)->p_memsz; grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n", i, (long) phdr(i)->p_paddr, (long) phdr(i)->p_memsz, (long) phdr(i)->p_vaddr); - if (mld->relocatable) - { - load_offset = phdr(i)->p_paddr - mld->link_base_addr; - grub_dprintf ("multiboot_loader", "segment %d: load_offset=0x%x\n", i, load_offset); - } - else - { - err = grub_relocator_alloc_chunk_addr (GRUB_MULTIBOOT (relocator), &ch, - phdr(i)->p_paddr, phdr(i)->p_memsz); - - if (err) - { - grub_dprintf ("multiboot_loader", "Cannot allocate memory for OS image\n"); - return err; - } - - source = get_virtual_current_address (ch); - } + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, phdr(i)->p_paddr, + phdr(i)->p_memsz); + if (err) + { + grub_dprintf ("multiboot_loader", "Error loading phdr %d\n", i); + return err; + } + source = get_virtual_current_address (ch); + } if (phdr(i)->p_filesz != 0) { - if (grub_file_seek (mld->file, (grub_off_t) phdr(i)->p_offset) + if (grub_file_seek (file, (grub_off_t) phdr(i)->p_offset) == (grub_off_t) -1) return grub_errno; - if (grub_file_read (mld->file, (grub_uint8_t *) source + load_offset, phdr(i)->p_filesz) + if (grub_file_read (file, source, phdr(i)->p_filesz) != (grub_ssize_t) phdr(i)->p_filesz) { if (!grub_errno) grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), - mld->filename); + filename); return grub_errno; } } if (phdr(i)->p_filesz < phdr(i)->p_memsz) - grub_memset ((grub_uint8_t *) source + load_offset + phdr(i)->p_filesz, 0, + grub_memset ((grub_uint8_t *) source + phdr(i)->p_filesz, 0, phdr(i)->p_memsz - phdr(i)->p_filesz); } } @@ -184,7 +131,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) if (phdr(i)->p_vaddr <= ehdr->e_entry && phdr(i)->p_vaddr + phdr(i)->p_memsz > ehdr->e_entry) { - GRUB_MULTIBOOT (payload_eip) = (ehdr->e_entry - phdr(i)->p_vaddr) + grub_multiboot_payload_eip = (ehdr->e_entry - phdr(i)->p_vaddr) + phdr(i)->p_paddr; #ifdef MULTIBOOT_LOAD_ELF64 # ifdef __mips @@ -208,7 +155,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) #if defined (__i386__) || defined (__x86_64__) #elif defined (__mips) - GRUB_MULTIBOOT (payload_eip) |= 0x80000000; + grub_multiboot_payload_eip |= 0x80000000; #else #error Please complete this #endif @@ -217,22 +164,19 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) { grub_uint8_t *shdr, *shdrptr; - shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); + shdr = grub_malloc (ehdr->e_shnum * ehdr->e_shentsize); if (!shdr) return grub_errno; - if (grub_file_seek (mld->file, ehdr->e_shoff) == (grub_off_t) -1) - { - grub_free (shdr); - return grub_errno; - } + if (grub_file_seek (file, ehdr->e_shoff) == (grub_off_t) -1) + return grub_errno; - if (grub_file_read (mld->file, shdr, (grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize) + if (grub_file_read (file, shdr, ehdr->e_shnum * ehdr->e_shentsize) != (grub_ssize_t) ehdr->e_shnum * ehdr->e_shentsize) { if (!grub_errno) grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), - mld->filename); + filename); return grub_errno; } @@ -242,9 +186,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) Elf_Shdr *sh = (Elf_Shdr *) shdrptr; void *src; grub_addr_t target; - - if (mld->mbi_ver >= 2 && (sh->sh_type == SHT_REL || sh->sh_type == SHT_RELA)) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ELF files with relocs are not supported yet"); + grub_err_t err; /* This section is a loaded section, so we don't care. */ @@ -255,34 +197,39 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) if (sh->sh_size == 0) continue; - err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, 0, - UP_TO_TOP32 (sh->sh_size), - sh->sh_size, sh->sh_addralign, - GRUB_RELOCATOR_PREFERENCE_NONE, - mld->avoid_efi_boot_services); - if (err) - { - grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i); - return err; - } - src = get_virtual_current_address (ch); - target = get_physical_target_address (ch); + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, + &ch, 0, + (0xffffffff - sh->sh_size) + + 1, sh->sh_size, + sh->sh_addralign, + GRUB_RELOCATOR_PREFERENCE_NONE, + 0); + if (err) + { + grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i); + return err; + } + src = get_virtual_current_address (ch); + target = get_physical_target_address (ch); + } - if (grub_file_seek (mld->file, sh->sh_offset) == (grub_off_t) -1) + if (grub_file_seek (file, sh->sh_offset) == (grub_off_t) -1) return grub_errno; - if (grub_file_read (mld->file, src, sh->sh_size) + if (grub_file_read (file, src, sh->sh_size) != (grub_ssize_t) sh->sh_size) { if (!grub_errno) grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), - mld->filename); + filename); return grub_errno; } sh->sh_addr = target; } - GRUB_MULTIBOOT (add_elfsyms) (ehdr->e_shnum, ehdr->e_shentsize, - ehdr->e_shstrndx, shdr); + grub_multiboot_add_elfsyms (ehdr->e_shnum, ehdr->e_shentsize, + ehdr->e_shstrndx, shdr); } #undef phdr diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 9a943d7bd..83e8919fa 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -22,7 +22,7 @@ #include #include #endif -#include +#include #include #include #include @@ -48,12 +48,6 @@ #define HAS_VGA_TEXT 0 #endif -#if defined (__i386__) || defined (__x86_64__) -#define MBI_MIN_ADDR 0x1000 -#else -#define MBI_MIN_ADDR 0 -#endif - struct module { struct module *next; @@ -74,10 +68,9 @@ static grub_size_t elf_sec_num, elf_sec_entsize; static unsigned elf_sec_shstrndx; static void *elf_sections; static int keep_bs = 0; -static grub_uint32_t load_base_addr; void -grub_multiboot2_add_elfsyms (grub_size_t num, grub_size_t entsize, +grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize, unsigned shndx, void *data) { elf_sec_num = num; @@ -86,62 +79,50 @@ grub_multiboot2_add_elfsyms (grub_size_t num, grub_size_t entsize, elf_sections = data; } -static struct multiboot_header * -find_header (grub_properly_aligned_t *buffer, grub_ssize_t len) -{ - struct multiboot_header *header; - /* Look for the multiboot header in the buffer. The header should - be at least 12 bytes and aligned on a 4-byte boundary. */ - for (header = (struct multiboot_header *) buffer; - ((char *) header <= (char *) buffer + len - 12); - header = (struct multiboot_header *) ((grub_uint32_t *) header + MULTIBOOT_HEADER_ALIGN / 4)) - { - if (header->magic == MULTIBOOT2_HEADER_MAGIC - && !(header->magic + header->architecture - + header->header_length + header->checksum) - && header->architecture == MULTIBOOT2_ARCHITECTURE_CURRENT) - return header; - } - return NULL; -} - grub_err_t -grub_multiboot2_load (grub_file_t file, const char *filename) +grub_multiboot_load (grub_file_t file, const char *filename) { + grub_properly_aligned_t *buffer; grub_ssize_t len; struct multiboot_header *header; grub_err_t err; struct multiboot_header_tag *tag; struct multiboot_header_tag_address *addr_tag = NULL; - struct multiboot_header_tag_relocatable *rel_tag; - int entry_specified = 0, efi_entry_specified = 0; - grub_addr_t entry = 0, efi_entry = 0; + int entry_specified = 0; + grub_addr_t entry = 0; grub_uint32_t console_required = 0; struct multiboot_header_tag_framebuffer *fbtag = NULL; - int accepted_consoles = GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT; - mbi_load_data_t mld; + int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT; - mld.mbi_ver = 2; - mld.relocatable = 0; - - mld.buffer = grub_malloc (MULTIBOOT_SEARCH); - if (!mld.buffer) + buffer = grub_malloc (MULTIBOOT_SEARCH); + if (!buffer) return grub_errno; - len = grub_file_read (file, mld.buffer, MULTIBOOT_SEARCH); + len = grub_file_read (file, buffer, MULTIBOOT_SEARCH); if (len < 32) { - grub_free (mld.buffer); + grub_free (buffer); return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), filename); } COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); - header = find_header (mld.buffer, len); + /* Look for the multiboot header in the buffer. The header should + be at least 12 bytes and aligned on a 4-byte boundary. */ + for (header = (struct multiboot_header *) buffer; + ((char *) header <= (char *) buffer + len - 12) || (header = 0); + header = (struct multiboot_header *) ((grub_uint32_t *) header + MULTIBOOT_HEADER_ALIGN / 4)) + { + if (header->magic == MULTIBOOT_HEADER_MAGIC + && !(header->magic + header->architecture + + header->header_length + header->checksum) + && header->architecture == MULTIBOOT_ARCHITECTURE_CURRENT) + break; + } if (header == 0) { - grub_free (mld.buffer); + grub_free (buffer); return grub_error (GRUB_ERR_BAD_ARGUMENT, "no multiboot header found"); } @@ -161,7 +142,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) = (struct multiboot_header_tag_information_request *) tag; if (request_tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL) break; - for (i = 0; i < (request_tag->size - sizeof (*request_tag)) + for (i = 0; i < (request_tag->size - sizeof (request_tag)) / sizeof (request_tag->requests[0]); i++) switch (request_tag->requests[i]) { @@ -183,13 +164,10 @@ grub_multiboot2_load (grub_file_t file, const char *filename) case MULTIBOOT_TAG_TYPE_NETWORK: case MULTIBOOT_TAG_TYPE_EFI_MMAP: case MULTIBOOT_TAG_TYPE_EFI_BS: - case MULTIBOOT_TAG_TYPE_EFI32_IH: - case MULTIBOOT_TAG_TYPE_EFI64_IH: - case MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR: break; default: - grub_free (mld.buffer); + grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS, "unsupported information tag: 0x%x", request_tag->requests[i]); @@ -206,17 +184,10 @@ grub_multiboot2_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr; break; - case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64: -#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__) - efi_entry_specified = 1; - efi_entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr; -#endif - break; - case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS: if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags & MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED)) - accepted_consoles &= ~GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT; + accepted_consoles &= ~GRUB_MULTIBOOT_CONSOLE_EGA_TEXT; if (((struct multiboot_header_tag_console_flags *) tag)->console_flags & MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED) console_required = 1; @@ -224,28 +195,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) case MULTIBOOT_HEADER_TAG_FRAMEBUFFER: fbtag = (struct multiboot_header_tag_framebuffer *) tag; - accepted_consoles |= GRUB_MULTIBOOT2_CONSOLE_FRAMEBUFFER; - break; - - case MULTIBOOT_HEADER_TAG_RELOCATABLE: - mld.relocatable = 1; - rel_tag = (struct multiboot_header_tag_relocatable *) tag; - mld.min_addr = rel_tag->min_addr; - mld.max_addr = rel_tag->max_addr; - mld.align = rel_tag->align; - switch (rel_tag->preference) - { - case MULTIBOOT_LOAD_PREFERENCE_LOW: - mld.preference = GRUB_RELOCATOR_PREFERENCE_LOW; - break; - - case MULTIBOOT_LOAD_PREFERENCE_HIGH: - mld.preference = GRUB_RELOCATOR_PREFERENCE_HIGH; - break; - - default: - mld.preference = GRUB_RELOCATOR_PREFERENCE_NONE; - } + accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER; break; /* GRUB always page-aligns modules. */ @@ -253,24 +203,22 @@ grub_multiboot2_load (grub_file_t file, const char *filename) break; case MULTIBOOT_HEADER_TAG_EFI_BS: -#ifdef GRUB_MACHINE_EFI keep_bs = 1; -#endif break; default: if (! (tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL)) { - grub_free (mld.buffer); + grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS, "unsupported tag: 0x%x", tag->type); } break; } - if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) + if (addr_tag && !entry_specified) { - grub_free (mld.buffer); + grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS, "load address tag without entry address tag"); } @@ -279,8 +227,8 @@ grub_multiboot2_load (grub_file_t file, const char *filename) { grub_uint64_t load_addr = (addr_tag->load_addr + 1) ? addr_tag->load_addr : (addr_tag->header_addr - - ((char *) header - (char *) mld.buffer)); - int offset = ((char *) header - (char *) mld.buffer - + - ((char *) header - (char *) buffer)); + int offset = ((char *) header - (char *) buffer - (addr_tag->header_addr - load_addr)); int load_size = ((addr_tag->load_end_addr == 0) ? file->size - offset : addr_tag->load_end_addr - addr_tag->load_addr); @@ -293,50 +241,27 @@ grub_multiboot2_load (grub_file_t file, const char *filename) else code_size = load_size; - if (mld.relocatable) - { - if (code_size > mld.max_addr || mld.min_addr > mld.max_addr - code_size) - { - grub_free (mld.buffer); - return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); - } - - err = grub_relocator_alloc_chunk_align_safe (grub_multiboot2_relocator, &ch, - mld.min_addr, mld.max_addr, - code_size, mld.align ? mld.align : 1, - mld.preference, keep_bs); - } - else - err = grub_relocator_alloc_chunk_addr (grub_multiboot2_relocator, - &ch, load_addr, code_size); + err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, load_addr, + code_size); if (err) { grub_dprintf ("multiboot_loader", "Error loading aout kludge\n"); - grub_free (mld.buffer); + grub_free (buffer); return err; } - mld.link_base_addr = load_addr; - mld.load_base_addr = get_physical_target_address (ch); source = get_virtual_current_address (ch); - grub_dprintf ("multiboot_loader", "link_base_addr=0x%x, load_base_addr=0x%x, " - "load_size=0x%lx, relocatable=%d\n", mld.link_base_addr, - mld.load_base_addr, (long) code_size, mld.relocatable); - - if (mld.relocatable) - grub_dprintf ("multiboot_loader", "align=0x%lx, preference=0x%x, avoid_efi_boot_services=%d\n", - (long) mld.align, mld.preference, keep_bs); - if ((grub_file_seek (file, offset)) == (grub_off_t) -1) { - grub_free (mld.buffer); + grub_free (buffer); return grub_errno; } grub_file_read (file, source, load_size); if (grub_errno) { - grub_free (mld.buffer); + grub_free (buffer); return grub_errno; } @@ -346,50 +271,26 @@ grub_multiboot2_load (grub_file_t file, const char *filename) } else { - mld.file = file; - mld.filename = filename; - mld.avoid_efi_boot_services = keep_bs; - err = grub_multiboot2_load_elf (&mld); + err = grub_multiboot_load_elf (file, filename, buffer); if (err) { - grub_free (mld.buffer); + grub_free (buffer); return err; } } - load_base_addr = mld.load_base_addr; - - if (keep_bs && efi_entry_specified) - grub_multiboot2_payload_eip = efi_entry; - else if (entry_specified) - grub_multiboot2_payload_eip = entry; - - if (mld.relocatable) - { - /* - * Both branches are mathematically equivalent. However, it looks - * that real life (C?) is more complicated. I am trying to avoid - * wrap around here if mld.load_base_addr < mld.link_base_addr. - * If you look at C operator precedence then everything should work. - * However, I am not 100% sure that a given compiler will not - * optimize/break this stuff. So, maybe we should use signed - * 64-bit int here. - */ - if (mld.load_base_addr >= mld.link_base_addr) - grub_multiboot2_payload_eip += mld.load_base_addr - mld.link_base_addr; - else - grub_multiboot2_payload_eip -= mld.link_base_addr - mld.load_base_addr; - } + if (entry_specified) + grub_multiboot_payload_eip = entry; if (fbtag) - err = grub_multiboot2_set_console (GRUB_MULTIBOOT2_CONSOLE_FRAMEBUFFER, - accepted_consoles, - fbtag->width, fbtag->height, - fbtag->depth, console_required); + err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER, + accepted_consoles, + fbtag->width, fbtag->height, + fbtag->depth, console_required); else - err = grub_multiboot2_set_console (GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT, - accepted_consoles, - 0, 0, 0, console_required); + err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_EGA_TEXT, + accepted_consoles, + 0, 0, 0, console_required); return err; } @@ -413,6 +314,42 @@ acpiv2_size (void) static grub_efi_uintn_t efi_mmap_size = 0; +/* Find the optimal number of pages for the memory map. Is it better to + move this code to efi/mm.c? */ +static void +find_efi_mmap_size (void) +{ + efi_mmap_size = (1 << 12); + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + grub_efi_uintn_t cur_mmap_size = efi_mmap_size; + + mmap = grub_malloc (cur_mmap_size); + if (! mmap) + return; + + ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + return; + else if (ret > 0) + break; + + if (efi_mmap_size < cur_mmap_size) + efi_mmap_size = cur_mmap_size; + efi_mmap_size += (1 << 12); + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + efi_mmap_size += (3 << 12); + + efi_mmap_size = ALIGN_UP (efi_mmap_size, 4096); +} #endif static grub_size_t @@ -429,11 +366,11 @@ net_size (void) } static grub_size_t -grub_multiboot2_get_mbi_size (void) +grub_multiboot_get_mbi_size (void) { #ifdef GRUB_MACHINE_EFI - if (!keep_bs && !efi_mmap_size) - efi_mmap_size = grub_efi_find_mmap_size (); + if (!efi_mmap_size) + find_efi_mmap_size (); #endif return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag) + sizeof (struct multiboot_tag) @@ -448,19 +385,16 @@ grub_multiboot2_get_mbi_size (void) + ALIGN_UP (sizeof (struct multiboot_tag_elf_sections), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (elf_sec_entsize * elf_sec_num, MULTIBOOT_TAG_ALIGN) + ALIGN_UP ((sizeof (struct multiboot_tag_mmap) - + grub_multiboot2_get_mmap_count () + + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) + + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN) + + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_old_acpi) + sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (sizeof (struct multiboot_tag_load_base_addr), MULTIBOOT_TAG_ALIGN) + acpiv2_size () + net_size () #ifdef GRUB_MACHINE_EFI - + ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap) + efi_mmap_size, MULTIBOOT_TAG_ALIGN) #endif @@ -478,7 +412,6 @@ grub_fill_multiboot_mmap_iter (grub_uint64_t addr, grub_uint64_t size, (*mmap_entry)->addr = addr; (*mmap_entry)->len = size; (*mmap_entry)->type = type; - (*mmap_entry)->zero = 0; (*mmap_entry)++; return 0; @@ -492,7 +425,7 @@ grub_fill_multiboot_mmap (struct multiboot_tag_mmap *tag) tag->type = MULTIBOOT_TAG_TYPE_MMAP; tag->size = sizeof (struct multiboot_tag_mmap) - + sizeof (struct multiboot_mmap_entry) * grub_multiboot2_get_mmap_count (); + + sizeof (struct multiboot_mmap_entry) * grub_get_multiboot_mmap_count (); tag->entry_size = sizeof (struct multiboot_mmap_entry); tag->entry_version = 0; @@ -558,7 +491,7 @@ retrieve_video_parameters (grub_properly_aligned_t **ptrorig) struct multiboot_tag_framebuffer *tag = (struct multiboot_tag_framebuffer *) *ptrorig; - err = grub_multiboot2_set_video_mode (); + err = grub_multiboot_set_video_mode (); if (err) { grub_print_error (); @@ -701,7 +634,7 @@ retrieve_video_parameters (grub_properly_aligned_t **ptrorig) } grub_err_t -grub_multiboot2_make_mbi (grub_uint32_t *target) +grub_multiboot_make_mbi (grub_uint32_t *target) { grub_properly_aligned_t *ptrorig; grub_properly_aligned_t *mbistart; @@ -709,12 +642,12 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) grub_size_t bufsize; grub_relocator_chunk_t ch; - bufsize = grub_multiboot2_get_mbi_size (); + bufsize = grub_multiboot_get_mbi_size (); COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); - err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, - MBI_MIN_ADDR, UP_TO_TOP32 (bufsize), + err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + 0, 0xffffffff - bufsize, bufsize, MULTIBOOT_TAG_ALIGN, GRUB_RELOCATOR_PREFERENCE_NONE, 1); if (err) @@ -736,15 +669,6 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) % sizeof (grub_properly_aligned_t) == 0); ptrorig += (2 * sizeof (grub_uint32_t)) / sizeof (grub_properly_aligned_t); - { - struct multiboot_tag_load_base_addr *tag = (struct multiboot_tag_load_base_addr *) ptrorig; - tag->type = MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR; - tag->size = sizeof (struct multiboot_tag_load_base_addr); - tag->load_base_addr = load_base_addr; - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } - { struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig; tag->type = MULTIBOOT_TAG_TYPE_CMDLINE; @@ -807,13 +731,12 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) } } - if (!keep_bs) - { - struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; - grub_fill_multiboot_mmap (tag); - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } + { + struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; + grub_fill_multiboot_mmap (tag); + ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) + / sizeof (grub_properly_aligned_t); + } { struct multiboot_tag_elf_sections *tag @@ -829,19 +752,18 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - if (!keep_bs) - { - struct multiboot_tag_basic_meminfo *tag - = (struct multiboot_tag_basic_meminfo *) ptrorig; - tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO; - tag->size = sizeof (struct multiboot_tag_basic_meminfo); + { + struct multiboot_tag_basic_meminfo *tag + = (struct multiboot_tag_basic_meminfo *) ptrorig; + tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO; + tag->size = sizeof (struct multiboot_tag_basic_meminfo); - /* Convert from bytes to kilobytes. */ - tag->mem_lower = grub_mmap_get_lower () / 1024; - tag->mem_upper = grub_mmap_get_upper () / 1024; - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } + /* Convert from bytes to kilobytes. */ + tag->mem_lower = grub_mmap_get_lower () / 1024; + tag->mem_upper = grub_mmap_get_upper () / 1024; + ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) + / sizeof (grub_properly_aligned_t); + } { struct grub_net_network_level_interface *net; @@ -940,57 +862,36 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) grub_efi_uintn_t efi_desc_size; grub_efi_uint32_t efi_desc_version; + tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP; + tag->size = sizeof (*tag) + efi_mmap_size; + if (!keep_bs) + err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL, + &efi_desc_size, &efi_desc_version); + else { - tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP; - tag->size = sizeof (*tag) + efi_mmap_size; - - err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL, - &efi_desc_size, &efi_desc_version); - - if (err) - return err; - - tag->descr_size = efi_desc_size; - tag->descr_vers = efi_desc_version; - tag->size = sizeof (*tag) + efi_mmap_size; - - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); + if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap, + NULL, + &efi_desc_size, &efi_desc_version) <= 0) + err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map"); } + if (err) + return err; + tag->descr_size = efi_desc_size; + tag->descr_vers = efi_desc_version; + tag->size = sizeof (*tag) + efi_mmap_size; + + ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) + / sizeof (grub_properly_aligned_t); } if (keep_bs) { - { - struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type = MULTIBOOT_TAG_TYPE_EFI_BS; - tag->size = sizeof (struct multiboot_tag); - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } - -#ifdef __i386__ - { - struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig; - tag->type = MULTIBOOT_TAG_TYPE_EFI32_IH; - tag->size = sizeof (struct multiboot_tag_efi32_ih); - tag->pointer = (grub_addr_t) grub_efi_image_handle; - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } -#endif - -#ifdef __x86_64__ - { - struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; - tag->type = MULTIBOOT_TAG_TYPE_EFI64_IH; - tag->size = sizeof (struct multiboot_tag_efi64_ih); - tag->pointer = (grub_addr_t) grub_efi_image_handle; - ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) - / sizeof (grub_properly_aligned_t); - } -#endif + struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type = MULTIBOOT_TAG_TYPE_EFI_BS; + tag->size = sizeof (struct multiboot_tag); + ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) + / sizeof (grub_properly_aligned_t); } #endif @@ -1009,7 +910,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) } void -grub_multiboot2_free_mbi (void) +grub_multiboot_free_mbi (void) { struct module *cur, *next; @@ -1031,11 +932,11 @@ grub_multiboot2_free_mbi (void) } grub_err_t -grub_multiboot2_init_mbi (int argc, char *argv[]) +grub_multiboot_init_mbi (int argc, char *argv[]) { grub_ssize_t len = 0; - grub_multiboot2_free_mbi (); + grub_multiboot_free_mbi (); len = grub_loader_cmdline_size (argc, argv); @@ -1044,17 +945,18 @@ grub_multiboot2_init_mbi (int argc, char *argv[]) return grub_errno; cmdline_size = len; - return grub_create_loader_cmdline (argc, argv, cmdline, cmdline_size, - GRUB_VERIFY_KERNEL_CMDLINE); + grub_create_loader_cmdline (argc, argv, cmdline, + cmdline_size); + + return GRUB_ERR_NONE; } grub_err_t -grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, +grub_multiboot_add_module (grub_addr_t start, grub_size_t size, int argc, char *argv[]) { struct module *newmod; grub_size_t len = 0; - grub_err_t err; newmod = grub_malloc (sizeof (*newmod)); if (!newmod) @@ -1073,14 +975,8 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, newmod->cmdline_size = len; total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN); - err = grub_create_loader_cmdline (argc, argv, newmod->cmdline, - newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE); - if (err) - { - grub_free (newmod->cmdline); - grub_free (newmod); - return err; - } + grub_create_loader_cmdline (argc, argv, newmod->cmdline, + newmod->cmdline_size); if (modules_last) modules_last->next = newmod; @@ -1094,7 +990,7 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, } void -grub_multiboot2_set_bootdev (void) +grub_multiboot_set_bootdev (void) { grub_device_t dev; diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 818b2a86d..6e814649f 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -270,7 +270,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto out; } - elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + elf = grub_elf_open (argv[0]); if (! elf) goto out; @@ -302,9 +302,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Create kernel command line. */ grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, - size, GRUB_VERIFY_KERNEL_CMDLINE)) - goto out; + grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, + size); out: diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488e1..000000000 --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, - N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index bb47ee0cc..6389170e6 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -110,7 +110,7 @@ grub_linux_boot (void) int len = grub_strlen (linux_args) + 1; if (bp->len < len) len = bp->len; - grub_memcpy(bp->buf, linux_args, len); + memcpy(bp->buf, linux_args, len); bp->buf[len-1] = '\0'; bp->valid = 1; } @@ -140,17 +140,17 @@ grub_linux_boot (void) grub_dprintf ("loader", "Jumping to Linux...\n"); /* Boot the kernel. */ - asm volatile ("ldx %0, %%o4\n" - "ldx %1, %%o6\n" - "ldx %2, %%o5\n" - "mov %%g0, %%o0\n" - "mov %%g0, %%o2\n" - "mov %%g0, %%o3\n" - "jmp %%o5\n" - "mov %%g0, %%o1\n": : - "m"(grub_ieee1275_entry_fn), - "m"(grub_ieee1275_original_stack), - "m"(linux_addr)); + asm volatile ("sethi %hi(grub_ieee1275_entry_fn), %o1\n" + "ldx [%o1 + %lo(grub_ieee1275_entry_fn)], %o4\n" + "sethi %hi(grub_ieee1275_original_stack), %o1\n" + "ldx [%o1 + %lo(grub_ieee1275_original_stack)], %o6\n" + "sethi %hi(linux_addr), %o1\n" + "ldx [%o1 + %lo(linux_addr)], %o5\n" + "mov %g0, %o0\n" + "mov %g0, %o2\n" + "mov %g0, %o3\n" + "jmp %o5\n" + "mov %g0, %o1\n"); return GRUB_ERR_NONE; } @@ -196,26 +196,26 @@ alloc_phys_choose (grub_uint64_t addr, grub_uint64_t len, struct alloc_phys_ctx *ctx = data; grub_addr_t end = addr + len; - if (type != GRUB_MEMORY_AVAILABLE) + if (type != 1) return 0; addr = ALIGN_UP (addr, FOUR_MB); if (addr + ctx->size >= end) return 0; - /* OBP available region contains grub. Start at grub_phys_end. */ - /* grub_phys_start does not start at the beginning of the memory region */ - if ((grub_phys_start >= addr && grub_phys_end < end) || - (addr > grub_phys_start && addr < grub_phys_end)) + if (addr >= grub_phys_start && addr < grub_phys_end) + { + addr = ALIGN_UP (grub_phys_end, FOUR_MB); + if (addr + ctx->size >= end) + return 0; + } + if ((addr + ctx->size) >= grub_phys_start + && (addr + ctx->size) < grub_phys_end) { addr = ALIGN_UP (grub_phys_end, FOUR_MB); if (addr + ctx->size >= end) return 0; } - - grub_dprintf("loader", - "addr = 0x%lx grub_phys_start = 0x%lx grub_phys_end = 0x%lx\n", - addr, grub_phys_start, grub_phys_end); if (loaded) { @@ -306,7 +306,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), goto out; } - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); + file = grub_file_open (argv[0]); if (!file) goto out; @@ -340,9 +340,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Create kernel command line. */ grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); - if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, - size, GRUB_VERIFY_KERNEL_CMDLINE)) - goto out; + grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1, + size); out: if (elf) @@ -431,7 +430,7 @@ static int get_physbase (grub_uint64_t addr, grub_uint64_t len __attribute__ ((unused)), grub_memory_type_t type, void *data __attribute__ ((unused))) { - if (type != GRUB_MEMORY_AVAILABLE) + if (type != 1) return 0; if (addr < phys_base) phys_base = addr; diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index 9ae4ceb35..cdd9715ce 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -33,8 +33,6 @@ #include #include #include -#include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -60,17 +58,15 @@ grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target) { grub_err_t err; grub_relocator_chunk_t ch; - grub_addr_t tgt; - - if (grub_add (grub_xnu_heap_target_start, grub_xnu_heap_size, &tgt)) - return GRUB_ERR_OUT_OF_RANGE; - err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, tgt, size); + err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, + grub_xnu_heap_target_start + + grub_xnu_heap_size, size); if (err) return err; *src = get_virtual_current_address (ch); - *target = tgt; + *target = grub_xnu_heap_target_start + grub_xnu_heap_size; grub_xnu_heap_size += size; grub_dprintf ("xnu", "val=%p\n", *src); return GRUB_ERR_NONE; @@ -355,7 +351,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), grub_xnu_unload (); - macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 0); + macho = grub_macho_open (args[0], 0); if (! macho) return grub_errno; @@ -429,10 +425,6 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)), if (ptr != grub_xnu_cmdline) *(ptr - 1) = 0; - err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - return err; - #if defined (__i386) && !defined (GRUB_MACHINE_EFI) err = grub_efiemu_autocore (); if (err) @@ -464,7 +456,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), grub_xnu_unload (); - macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 1); + macho = grub_macho_open (args[0], 1); if (! macho) return grub_errno; @@ -542,10 +534,6 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)), if (ptr != grub_xnu_cmdline) *(ptr - 1) = 0; - err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE); - if (err) - return err; - #if defined (__i386) && !defined (GRUB_MACHINE_EFI) err = grub_efiemu_autocore (); if (err) @@ -686,7 +674,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, macho = 0; if (infoplistname) - infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST); + infoplist = grub_file_open (infoplistname); else infoplist = 0; grub_errno = GRUB_ERR_NONE; @@ -701,10 +689,10 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, /* Allocate the space. */ err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE); if (err) - goto fail; + return err; err = grub_xnu_heap_malloc (neededspace, &buf0, &buf_target); if (err) - goto fail; + return err; buf = buf0; exthead = (struct grub_xnu_extheader *) buf; @@ -721,7 +709,10 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, else err = grub_macho_readfile32 (macho, filename, buf); if (err) - goto fail; + { + grub_macho_close (macho); + return err; + } grub_macho_close (macho); buf += machosize; } @@ -756,10 +747,6 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile, /* Announce to kernel */ return grub_xnu_register_memory ("Driver-", &driversnum, buf_target, neededspace); -fail: - if (macho) - grub_macho_close (macho); - return err; } /* Load mkext. */ @@ -783,7 +770,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), if (! grub_xnu_heap_size) return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first")); - file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_MKEXT); + file = grub_file_open (args[0]); if (! file) return grub_errno; @@ -803,7 +790,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) { narchs = grub_be_to_cpu32 (head.nfat_arch); - archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); if (! archs) { grub_file_close (file); @@ -897,7 +884,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)), if (! grub_xnu_heap_size) return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first")); - file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_RAMDISK); + file = grub_file_open (args[0]); if (! file) return grub_errno; @@ -937,7 +924,7 @@ grub_xnu_check_os_bundle_required (char *plistname, if (binname) *binname = 0; - file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST); + file = grub_file_open (plistname); if (! file) return 0; @@ -1105,7 +1092,7 @@ grub_xnu_scan_dir_for_kexts (char *dirname, const char *osbundlerequired, path++; if (fs) - (fs->fs_dir) (dev, path, grub_xnu_scan_dir_for_kexts_load, &ctx); + (fs->dir) (dev, path, grub_xnu_scan_dir_for_kexts_load, &ctx); grub_device_close (dev); } grub_free (device_name); @@ -1204,7 +1191,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired, /* Look at the directory. */ if (fs) - (fs->fs_dir) (dev, path, grub_xnu_load_kext_from_dir_load, &ctx); + (fs->dir) (dev, path, grub_xnu_load_kext_from_dir_load, &ctx); if (ctx.plistname && grub_xnu_check_os_bundle_required (ctx.plistname, osbundlerequired, &binsuffix)) @@ -1222,7 +1209,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired, grub_strcpy (binname + grub_strlen (binname), "/"); grub_strcpy (binname + grub_strlen (binname), binsuffix); grub_dprintf ("xnu", "%s:%s\n", ctx.plistname, binname); - binfile = grub_file_open (binname, GRUB_FILE_TYPE_XNU_KEXT); + binfile = grub_file_open (binname); if (! binfile) grub_errno = GRUB_ERR_NONE; @@ -1265,7 +1252,7 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)), /* User explicitly specified plist and binary. */ if (grub_strcmp (args[1], "-") != 0) { - binfile = grub_file_open (args[1], GRUB_FILE_TYPE_XNU_KEXT); + binfile = grub_file_open (args[1]); if (! binfile) return grub_errno; } @@ -1391,8 +1378,6 @@ grub_xnu_fill_devicetree (void) name[len] = 0; curvalue = grub_xnu_create_value (curkey, name); - if (!curvalue) - return grub_errno; grub_free (name); data = grub_malloc (grub_strlen (var->value) + 1); diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c index d648ef0cd..534a74438 100644 --- a/grub-core/loader/xnu_resume.c +++ b/grub-core/loader/xnu_resume.c @@ -53,8 +53,8 @@ grub_xnu_resume (char *imagename) grub_addr_t target_image; grub_err_t err; - file = grub_file_open (imagename, GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE - | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (imagename); if (! file) return 0; @@ -129,7 +129,7 @@ grub_xnu_resume (char *imagename) { grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_align (grub_xnu_relocator, &ch, 0, - UP_TO_TOP32 (hibhead.image_size), + (0xffffffff - hibhead.image_size) + 1, hibhead.image_size, GRUB_XNU_PAGESIZE, GRUB_RELOCATOR_PREFERENCE_NONE, 0); diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c index bd495a184..a77efe81d 100644 --- a/grub-core/mmap/efi/mmap.c +++ b/grub-core/mmap/efi/mmap.c @@ -73,7 +73,6 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_AVAILABLE, hook_data); break; } - /* FALLTHROUGH */ case GRUB_EFI_RUNTIME_SERVICES_CODE: hook (desc->physical_start, desc->num_pages * 4096, GRUB_MEMORY_CODE, hook_data); @@ -84,6 +83,10 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_BADRAM, hook_data); break; + default: + grub_printf ("Unknown memory type %d, considering reserved\n", + desc->type); + case GRUB_EFI_BOOT_SERVICES_DATA: if (!avoid_efi_boot_services) { @@ -91,7 +94,6 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, GRUB_MEMORY_AVAILABLE, hook_data); break; } - /* FALLTHROUGH */ case GRUB_EFI_RESERVED_MEMORY_TYPE: case GRUB_EFI_RUNTIME_SERVICES_DATA: case GRUB_EFI_MEMORY_MAPPED_IO: @@ -117,18 +119,6 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data, hook (desc->physical_start, desc->num_pages * 4096, GRUB_MEMORY_NVS, hook_data); break; - - case GRUB_EFI_PERSISTENT_MEMORY: - hook (desc->physical_start, desc->num_pages * 4096, - GRUB_MEMORY_PERSISTENT, hook_data); - break; - - default: - grub_printf ("Unknown memory type %d, considering reserved\n", - desc->type); - hook (desc->physical_start, desc->num_pages * 4096, - GRUB_MEMORY_RESERVED, hook_data); - break; } } @@ -152,13 +142,6 @@ make_efi_memtype (int type) /* No way to remove a chunk of memory from EFI mmap. So mark it as unusable. */ case GRUB_MEMORY_HOLE: - /* - * AllocatePages() does not support GRUB_EFI_PERSISTENT_MEMORY, - * so no translation for GRUB_MEMORY_PERSISTENT or - * GRUB_MEMORY_PERSISTENT_LEGACY. - */ - case GRUB_MEMORY_PERSISTENT: - case GRUB_MEMORY_PERSISTENT_LEGACY: case GRUB_MEMORY_RESERVED: return GRUB_EFI_UNUSABLE_MEMORY; diff --git a/grub-core/mmap/i386/pc/mmap.c b/grub-core/mmap/i386/pc/mmap.c index 6ab4f6730..609994516 100644 --- a/grub-core/mmap/i386/pc/mmap.c +++ b/grub-core/mmap/i386/pc/mmap.c @@ -42,6 +42,14 @@ extern grub_uint16_t grub_machine_mmaphook_kblow; extern grub_uint16_t grub_machine_mmaphook_kbin16mb; extern grub_uint16_t grub_machine_mmaphook_64kbin4gb; +struct grub_e820_mmap_entry +{ + grub_uint64_t addr; + grub_uint64_t len; + grub_uint32_t type; +} GRUB_PACKED; + + /* Helper for preboot. */ static int fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, void *data) diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c index 64684c23d..6a31cbae3 100644 --- a/grub-core/mmap/mmap.c +++ b/grub-core/mmap/mmap.c @@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) /* Initialize variables. */ ctx.scanline_events = (struct grub_mmap_scan *) - grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); + grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); - present = grub_calloc (current_priority, sizeof (present[0])); + present = grub_zalloc (sizeof (present[0]) * current_priority); if (! ctx.scanline_events || !present) { @@ -423,7 +423,7 @@ static grub_err_t grub_cmd_badram (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { - const char *str; + char * str; struct badram_entry entry; if (argc != 1) @@ -465,7 +465,7 @@ static grub_uint64_t parsemem (const char *str) { grub_uint64_t ret; - const char *ptr; + char *ptr; ret = grub_strtoul (str, &ptr, 0); diff --git a/grub-core/modinfo.sh.in b/grub-core/modinfo.sh.in index f6cd657ce..69d833432 100644 --- a/grub-core/modinfo.sh.in +++ b/grub-core/modinfo.sh.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh # User-controllable options grub_modinfo_target_cpu=@target_cpu@ @@ -9,6 +9,8 @@ grub_have_font_source=@HAVE_FONT_SOURCE@ # Autodetected config grub_have_asm_uscore=@HAVE_ASM_USCORE@ +grub_i8086_addr32="@ADDR32@" +grub_i8086_data32="@DATA32@" grub_bss_start_symbol="@BSS_START_SYMBOL@" grub_end_symbol="@END_SYMBOL@" @@ -19,17 +21,11 @@ grub_target_cflags='@TARGET_CFLAGS@' grub_target_cppflags='@TARGET_CPPFLAGS@' grub_target_ccasflags='@TARGET_CCASFLAGS@' grub_target_ldflags='@TARGET_LDFLAGS@' -grub_cflags='@CFLAGS@' -grub_cppflags='@CPPFLAGS@' -grub_ccasflags='@CCASFLAGS@' -grub_ldflags='@LDFLAGS@' grub_target_strip='@TARGET_STRIP@' grub_target_nm='@TARGET_NM@' grub_target_ranlib='@TARGET_RANLIB@' grub_target_objconf='@TARGET_OBJCONV@' grub_target_obj2elf='@TARGET_OBJ2ELF@' -grub_target_img_base_ldopt='@TARGET_IMG_BASE_LDOPT@' -grub_target_img_ldflags='@TARGET_IMG_BASE_LDFLAGS@' # Version grub_version="@VERSION@" diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c index 54306e3b1..00d37b6c3 100644 --- a/grub-core/net/arp.c +++ b/grub-core/net/arp.c @@ -37,16 +37,12 @@ enum GRUB_NET_ARPHRD_ETHERNET = 1 }; -struct arppkt { +struct arphdr { grub_uint16_t hrd; grub_uint16_t pro; grub_uint8_t hln; grub_uint8_t pln; grub_uint16_t op; - grub_uint8_t sender_mac[6]; - grub_uint32_t sender_ip; - grub_uint8_t recv_mac[6]; - grub_uint32_t recv_ip; } GRUB_PACKED; static int have_pending; @@ -57,14 +53,21 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, const grub_net_network_level_address_t *proto_addr) { struct grub_net_buff nb; - struct arppkt *arp_packet; - grub_net_link_level_address_t target_mac_addr; + struct arphdr *arp_header; + grub_net_link_level_address_t target_hw_addr; + grub_uint8_t *aux, arp_data[128]; grub_err_t err; int i; + grub_size_t addrlen; + grub_uint16_t etherpro; grub_uint8_t *nbd; - grub_uint8_t arp_data[128]; - if (proto_addr->type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) + if (proto_addr->type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) + { + addrlen = 4; + etherpro = GRUB_NET_ETHERTYPE_IP; + } + else return grub_error (GRUB_ERR_BUG, "unsupported address family"); /* Build a request packet. */ @@ -73,26 +76,34 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, grub_netbuff_clear (&nb); grub_netbuff_reserve (&nb, 128); - err = grub_netbuff_push (&nb, sizeof (*arp_packet)); + err = grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + addrlen)); if (err) return err; - arp_packet = (struct arppkt *) nb.data; - arp_packet->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET); - arp_packet->hln = 6; - arp_packet->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP); - arp_packet->pln = 4; - arp_packet->op = grub_cpu_to_be16_compile_time (ARP_REQUEST); + arp_header = (struct arphdr *) nb.data; + arp_header->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET); + arp_header->hln = 6; + arp_header->pro = grub_cpu_to_be16 (etherpro); + arp_header->pln = addrlen; + arp_header->op = grub_cpu_to_be16_compile_time (ARP_REQUEST); + aux = (grub_uint8_t *) arp_header + sizeof (*arp_header); /* Sender hardware address. */ - grub_memcpy (arp_packet->sender_mac, &inf->hwaddress.mac, 6); - arp_packet->sender_ip = inf->address.ipv4; - grub_memset (arp_packet->recv_mac, 0, 6); - arp_packet->recv_ip = proto_addr->ipv4; + grub_memcpy (aux, &inf->hwaddress.mac, 6); + + aux += 6; + /* Sender protocol address */ + grub_memcpy (aux, &inf->address.ipv4, 4); + aux += addrlen; + /* Target hardware address */ + for (i = 0; i < 6; i++) + aux[i] = 0x00; + aux += 6; /* Target protocol address */ - grub_memset (&target_mac_addr.mac, 0xff, 6); + grub_memcpy (aux, &proto_addr->ipv4, 4); + grub_memset (&target_hw_addr.mac, 0xff, 6); nbd = nb.data; - send_ethernet_packet (inf, &nb, target_mac_addr, GRUB_NET_ETHERTYPE_ARP); + send_ethernet_packet (inf, &nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); for (i = 0; i < GRUB_NET_TRIES; i++) { if (grub_net_link_layer_resolve_check (inf, proto_addr)) @@ -104,7 +115,7 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, if (grub_net_link_layer_resolve_check (inf, proto_addr)) return GRUB_ERR_NONE; nb.data = nbd; - send_ethernet_packet (inf, &nb, target_mac_addr, GRUB_NET_ETHERTYPE_ARP); + send_ethernet_packet (inf, &nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP); } return GRUB_ERR_NONE; @@ -112,77 +123,71 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, grub_err_t grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, - grub_uint16_t *vlantag) + grub_uint16_t vlantag_vid) { - struct arppkt *arp_packet = (struct arppkt *) nb->data; + struct arphdr *arp_header = (struct arphdr *) nb->data; + grub_uint8_t *sender_hardware_address; + grub_uint8_t *target_hardware_address; grub_net_network_level_address_t sender_addr, target_addr; - grub_net_link_level_address_t sender_mac_addr; + grub_net_link_level_address_t sender_hw_addr; struct grub_net_network_level_interface *inf; + grub_uint8_t *sender_protocol_address, *target_protocol_address; - if (arp_packet->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP) - || arp_packet->pln != 4 || arp_packet->hln != 6 - || nb->tail - nb->data < (int) sizeof (*arp_packet)) + sender_hardware_address = + (grub_uint8_t *) arp_header + sizeof (*arp_header); + sender_protocol_address = sender_hardware_address + arp_header->hln; + target_hardware_address = sender_protocol_address + arp_header->pln; + target_protocol_address = target_hardware_address + arp_header->hln; + if (grub_be_to_cpu16 (arp_header->pro) == GRUB_NET_ETHERTYPE_IP + && arp_header->pln == 4) + { + sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + grub_memcpy (&sender_addr.ipv4, sender_protocol_address, 4); + grub_memcpy (&target_addr.ipv4, target_protocol_address, 4); + if (grub_memcmp (sender_protocol_address, &pending_req, 4) == 0) + have_pending = 1; + } + else return GRUB_ERR_NONE; - sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - sender_addr.ipv4 = arp_packet->sender_ip; - target_addr.ipv4 = arp_packet->recv_ip; - if (arp_packet->sender_ip == pending_req) - have_pending = 1; - - sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac, - sizeof (sender_mac_addr.mac)); - grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); + sender_hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + grub_memcpy (sender_hw_addr.mac, sender_hardware_address, + sizeof (sender_hw_addr.mac)); + grub_net_link_layer_add_address (card, &sender_addr, &sender_hw_addr, 1); FOR_NET_NETWORK_LEVEL_INTERFACES (inf) { - /* Verify vlantag id */ - if (inf->card == card && inf->vlantag != *vlantag) - { - grub_dprintf ("net", "invalid vlantag! %x != %x\n", - inf->vlantag, *vlantag); - break; - } + /* Check vlantag id */ + if (inf->card == card && + ((inf->vlantag.set && vlantag_vid != inf->vlantag.vid) || + (!inf->vlantag.set && vlantag_vid != 0))) + continue; /* Am I the protocol address target? */ if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 - && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) + && grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST) { grub_net_link_level_address_t target; - struct grub_net_buff nb_reply; - struct arppkt *arp_reply; - grub_uint8_t arp_data[128]; - grub_err_t err; + /* We've already checked that pln is either 4 or 16. */ + char tmp[16]; + grub_size_t pln = arp_header->pln; - nb_reply.head = arp_data; - nb_reply.end = arp_data + sizeof (arp_data); - grub_netbuff_clear (&nb_reply); - grub_netbuff_reserve (&nb_reply, 128); - - err = grub_netbuff_push (&nb_reply, sizeof (*arp_packet)); - if (err) - return err; - - arp_reply = (struct arppkt *) nb_reply.data; - - arp_reply->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET); - arp_reply->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP); - arp_reply->pln = 4; - arp_reply->hln = 6; - arp_reply->op = grub_cpu_to_be16_compile_time (ARP_REPLY); - arp_reply->sender_ip = arp_packet->recv_ip; - arp_reply->recv_ip = arp_packet->sender_ip; - arp_reply->hln = 6; + if (pln > 16) + pln = 16; target.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; - grub_memcpy (target.mac, arp_packet->sender_mac, 6); - grub_memcpy (arp_reply->sender_mac, inf->hwaddress.mac, 6); - grub_memcpy (arp_reply->recv_mac, arp_packet->sender_mac, 6); + grub_memcpy (target.mac, sender_hardware_address, 6); + grub_memcpy (target_hardware_address, target.mac, 6); + grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6); + + grub_memcpy (tmp, sender_protocol_address, pln); + grub_memcpy (sender_protocol_address, target_protocol_address, pln); + grub_memcpy (target_protocol_address, tmp, pln); /* Change operation to REPLY and send packet */ - send_ethernet_packet (inf, &nb_reply, target, GRUB_NET_ETHERTYPE_ARP); + arp_header->op = grub_be_to_cpu16 (ARP_REPLY); + send_ethernet_packet (inf, nb, target, GRUB_NET_ETHERTYPE_ARP); } } return GRUB_ERR_NONE; diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index e33be51f8..613675533 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -25,122 +25,25 @@ #include #include -struct grub_dhcp_discover_options +static void +parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) { - grub_uint8_t magic[4]; - struct - { - grub_uint8_t code; - grub_uint8_t len; - grub_uint8_t data; - } GRUB_PACKED message_type; - grub_uint8_t end; -} GRUB_PACKED; + const grub_uint8_t *ptr, *ptr0; -struct grub_dhcp_request_options -{ - grub_uint8_t magic[4]; - struct - { - grub_uint8_t code; - grub_uint8_t len; - grub_uint8_t data; - } GRUB_PACKED message_type; - struct - { - grub_uint8_t type; - grub_uint8_t len; - grub_uint32_t data; - } GRUB_PACKED server_identifier; - struct - { - grub_uint8_t type; - grub_uint8_t len; - grub_uint32_t data; - } GRUB_PACKED requested_ip; - struct - { - grub_uint8_t type; - grub_uint8_t len; - grub_uint8_t data[7]; - } GRUB_PACKED parameter_request; - grub_uint8_t end; -} GRUB_PACKED; - -enum -{ - GRUB_DHCP_OPT_OVERLOAD_FILE = 1, - GRUB_DHCP_OPT_OVERLOAD_SNAME = 2, -}; -enum -{ - GRUB_DHCP_MESSAGE_UNKNOWN, - GRUB_DHCP_MESSAGE_DISCOVER, - GRUB_DHCP_MESSAGE_OFFER, - GRUB_DHCP_MESSAGE_REQUEST, - GRUB_DHCP_MESSAGE_DECLINE, - GRUB_DHCP_MESSAGE_ACK, - GRUB_DHCP_MESSAGE_NAK, - GRUB_DHCP_MESSAGE_RELEASE, - GRUB_DHCP_MESSAGE_INFORM, -}; - -#define GRUB_BOOTP_MAX_OPTIONS_SIZE 64 - -/* Max timeout when waiting for BOOTP/DHCP reply */ -#define GRUB_DHCP_MAX_PACKET_TIMEOUT 32 - -#define GRUB_BOOTP_MAX_OPTIONS_SIZE 64 - -/* Max timeout when waiting for BOOTP/DHCP reply */ -#define GRUB_DHCP_MAX_PACKET_TIMEOUT 32 - -static char -hexdigit (grub_uint8_t val) -{ - if (val < 10) - return val + '0'; - return val + 'a' - 10; -} - -static const void * -find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, - grub_uint8_t opt_code, grub_uint8_t *opt_len) -{ - const grub_uint8_t *ptr; - grub_uint8_t overload = 0; - int end = 0; - grub_size_t i; - - if (opt_len) - *opt_len = 0; - - /* Is the packet big enough to hold at least the magic cookie? */ - if (size < sizeof (*bp) + sizeof (grub_uint32_t)) - return NULL; - - /* - * Pointer arithmetic to point behind the common stub packet, where - * the options start. - */ - ptr = (grub_uint8_t *) (bp + 1); + ptr = ptr0 = vend; if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) - return NULL; - - size -= sizeof (*bp); - i = sizeof (grub_uint32_t); - -again: - while (i < size) + return; + ptr = ptr + sizeof (grub_uint32_t); + while (ptr - ptr0 < limit) { grub_uint8_t tagtype; grub_uint8_t taglength; - tagtype = ptr[i++]; + tagtype = *ptr++; /* Pad tag. */ if (tagtype == GRUB_NET_BOOTP_PAD) @@ -148,78 +51,81 @@ again: /* End tag. */ if (tagtype == GRUB_NET_BOOTP_END) + return; + + taglength = *ptr++; + + switch (tagtype) { - end = 1; + case GRUB_NET_BOOTP_NETMASK: + if (taglength == 4) + { + int i; + for (i = 0; i < 32; i++) + if (!(ptr[i / 8] & (1 << (7 - (i % 8))))) + break; + *mask = i; + } break; + + case GRUB_NET_BOOTP_ROUTER: + if (taglength == 4) + { + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + char *rname; + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = 0; + target.ipv4.masksize = 0; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + grub_memcpy (&gw.ipv4, ptr, sizeof (gw.ipv4)); + rname = grub_xasprintf ("%s:default", name); + if (rname) + grub_net_add_route_gw (rname, target, gw); + grub_free (rname); + } + break; + case GRUB_NET_BOOTP_DNS: + { + int i; + for (i = 0; i < taglength / 4; i++) + { + struct grub_net_network_level_address s; + s.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + s.ipv4 = grub_get_unaligned32 (ptr); + s.option = DNS_OPTION_PREFER_IPV4; + grub_net_add_dns_server (&s); + ptr += 4; + } + } + continue; + case GRUB_NET_BOOTP_HOSTNAME: + grub_env_set_net_property (name, "hostname", (const char *) ptr, + taglength); + break; + + case GRUB_NET_BOOTP_DOMAIN: + grub_env_set_net_property (name, "domain", (const char *) ptr, + taglength); + break; + + case GRUB_NET_BOOTP_ROOT_PATH: + grub_env_set_net_property (name, "rootpath", (const char *) ptr, + taglength); + break; + + case GRUB_NET_BOOTP_EXTENSIONS_PATH: + grub_env_set_net_property (name, "extensionspath", (const char *) ptr, + taglength); + break; + + /* If you need any other options please contact GRUB + development team. */ } - if (i >= size) - return NULL; - - taglength = ptr[i++]; - if (i + taglength >= size) - return NULL; - - grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n", - tagtype, tagtype, taglength); - - /* FIXME RFC 3396 options concatentation */ - if (tagtype == opt_code) - { - if (opt_len) - *opt_len = taglength; - return &ptr[i]; - } - - if (tagtype == GRUB_NET_DHCP_OVERLOAD && taglength == 1) - overload = ptr[i]; - - i += taglength; + ptr += taglength; } - - if (!end) - return NULL; - - /* RFC2131, 4.1, 23ff: - * If the options in a DHCP message extend into the 'sname' and 'file' - * fields, the 'option overload' option MUST appear in the 'options' - * field, with value 1, 2 or 3, as specified in RFC 1533. If the - * 'option overload' option is present in the 'options' field, the - * options in the 'options' field MUST be terminated by an 'end' option, - * and MAY contain one or more 'pad' options to fill the options field. - * The options in the 'sname' and 'file' fields (if in use as indicated - * by the 'options overload' option) MUST begin with the first octet of - * the field, MUST be terminated by an 'end' option, and MUST be - * followed by 'pad' options to fill the remainder of the field. Any - * individual option in the 'options', 'sname' and 'file' fields MUST be - * entirely contained in that field. The options in the 'options' field - * MUST be interpreted first, so that any 'option overload' options may - * be interpreted. The 'file' field MUST be interpreted next (if the - * 'option overload' option indicates that the 'file' field contains - * DHCP options), followed by the 'sname' field. - * - * FIXME: We do not explicitly check for trailing 'pad' options here. - */ - end = 0; - if (overload & GRUB_DHCP_OPT_OVERLOAD_FILE) - { - overload &= ~GRUB_DHCP_OPT_OVERLOAD_FILE; - ptr = (grub_uint8_t *) &bp->boot_file[0]; - size = sizeof (bp->boot_file); - i = 0; - goto again; - } - - if (overload & GRUB_DHCP_OPT_OVERLOAD_SNAME) - { - overload &= ~GRUB_DHCP_OPT_OVERLOAD_SNAME; - ptr = (grub_uint8_t *) &bp->server_name[0]; - size = sizeof (bp->server_name); - i = 0; - goto again; - } - - return NULL; } #define OFFSET_OF(x, y) ((grub_size_t)((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y))) @@ -236,11 +142,6 @@ grub_net_configure_by_dhcp_ack (const char *name, grub_net_link_level_address_t hwaddr; struct grub_net_network_level_interface *inter; int mask = -1; - char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; - const grub_uint8_t *opt; - grub_uint8_t opt_len, overload = 0; - const char *boot_file = 0, *server_name = 0; - grub_size_t boot_file_len, server_name_len; addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; addr.ipv4 = bp->your_ip; @@ -256,55 +157,40 @@ grub_net_configure_by_dhcp_ack (const char *name, hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags); - if (!inter) - return 0; - - opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_OVERLOAD, &opt_len); - if (opt && opt_len == 1) - overload = *opt; - - opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_TFTP_SERVER_NAME, &opt_len); - if (opt && opt_len) + if (bp->gateway_ip) { - server_name = (const char *) opt; - server_name_len = opt_len; - } - else if (size > OFFSET_OF (server_name, bp) && !(overload & GRUB_DHCP_OPT_OVERLOAD_SNAME) && - bp->server_name[0]) - { - server_name = bp->server_name; - server_name_len = sizeof (bp->server_name); - } - - opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_BOOTFILE_NAME, &opt_len); - if (opt && opt_len) - { - boot_file = (const char *) opt; - boot_file_len = opt_len; - } - else if (size > OFFSET_OF (boot_file, bp) && !(overload && GRUB_DHCP_OPT_OVERLOAD_FILE) && - bp->boot_file[0]) - { - boot_file = bp->boot_file; - boot_file_len = sizeof (bp->boot_file); - } - - if (bp->server_ip) - { - grub_snprintf (server_ip, sizeof (server_ip), "%d.%d.%d.%d", - ((grub_uint8_t *) &bp->server_ip)[0], - ((grub_uint8_t *) &bp->server_ip)[1], - ((grub_uint8_t *) &bp->server_ip)[2], - ((grub_uint8_t *) &bp->server_ip)[3]); - grub_env_set_net_property (name, "next_server", server_ip, sizeof (server_ip)); - grub_print_error (); + grub_net_network_level_netaddress_t target; + grub_net_network_level_address_t gw; + char *rname; + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->server_ip; + target.ipv4.masksize = 32; + gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + gw.ipv4 = bp->gateway_ip; + rname = grub_xasprintf ("%s:gw", name); + if (rname) + grub_net_add_route_gw (rname, target, gw); + grub_free (rname); + + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4.base = bp->gateway_ip; + target.ipv4.masksize = 32; + grub_net_add_route (name, target, inter); } + if (size > OFFSET_OF (boot_file, bp)) + grub_env_set_net_property (name, "boot_file", bp->boot_file, + sizeof (bp->boot_file)); if (is_def) grub_net_default_server = 0; if (is_def && !grub_net_default_server && bp->server_ip) { - grub_net_default_server = grub_strdup (server_ip); + grub_net_default_server = grub_xasprintf ("%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); grub_print_error (); } @@ -316,140 +202,48 @@ grub_net_configure_by_dhcp_ack (const char *name, if (device && !*device && bp->server_ip) { - *device = grub_xasprintf ("tftp,%s", server_ip); + *device = grub_xasprintf ("tftp,%d.%d.%d.%d", + ((grub_uint8_t *) &bp->server_ip)[0], + ((grub_uint8_t *) &bp->server_ip)[1], + ((grub_uint8_t *) &bp->server_ip)[2], + ((grub_uint8_t *) &bp->server_ip)[3]); grub_print_error (); } - - if (server_name) + if (size > OFFSET_OF (server_name, bp) + && bp->server_name[0]) { - grub_env_set_net_property (name, "dhcp_server_name", server_name, server_name_len); + grub_env_set_net_property (name, "dhcp_server_name", bp->server_name, + sizeof (bp->server_name)); if (is_def && !grub_net_default_server) { - grub_net_default_server = grub_strdup (server_name); + grub_net_default_server = grub_strdup (bp->server_name); grub_print_error (); } if (device && !*device) { - *device = grub_xasprintf ("tftp,%s", server_name); + *device = grub_xasprintf ("tftp,%s", bp->server_name); grub_print_error (); } } - if (boot_file) + if (size > OFFSET_OF (boot_file, bp) && path) { - grub_env_set_net_property (name, "boot_file", boot_file, boot_file_len); - if (path) + *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file)); + grub_print_error (); + if (*path) { - *path = grub_strndup (boot_file, boot_file_len); - grub_print_error (); - if (*path) - { - char *slash; - slash = grub_strrchr (*path, '/'); - if (slash) - *slash = 0; - else - **path = 0; - } + char *slash; + slash = grub_strrchr (*path, '/'); + if (slash) + *slash = 0; + else + **path = 0; } } - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_NETMASK, &opt_len); - if (opt && opt_len == 4) - { - int i; - for (i = 0; i < 32; i++) - if (!(opt[i / 8] & (1 << (7 - (i % 8))))) - break; - mask = i; - } + if (size > OFFSET_OF (vendor, bp)) + parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); grub_net_add_ipv4_local (inter, mask); - - /* We do not implement dead gateway detection and the first entry SHOULD - be preferred one */ - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROUTER, &opt_len); - if (opt && opt_len && !(opt_len & 3)) - { - grub_net_network_level_netaddress_t target; - grub_net_network_level_address_t gw; - char *rname; - - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4.base = 0; - target.ipv4.masksize = 0; - gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - gw.ipv4 = grub_get_unaligned32 (opt); - rname = grub_xasprintf ("%s:default", name); - if (rname) - grub_net_add_route_gw (rname, target, gw, 0); - grub_free (rname); - } - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_DNS, &opt_len); - if (opt && opt_len && !(opt_len & 3)) - { - int i; - for (i = 0; i < opt_len / 4; i++) - { - struct grub_net_network_level_address s; - - s.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - s.ipv4 = grub_get_unaligned32 (opt); - s.option = DNS_OPTION_PREFER_IPV4; - grub_net_add_dns_server (&s); - opt += 4; - } - } - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_HOSTNAME, &opt_len); - if (opt && opt_len) - grub_env_set_net_property (name, "hostname", (const char *) opt, opt_len); - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_DOMAIN, &opt_len); - if (opt && opt_len) - grub_env_set_net_property (name, "domain", (const char *) opt, opt_len); - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROOT_PATH, &opt_len); - if (opt && opt_len) - grub_env_set_net_property (name, "rootpath", (const char *) opt, opt_len); - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_EXTENSIONS_PATH, &opt_len); - if (opt && opt_len) - grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len); - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_ID, &opt_len); - if (opt && opt_len) - grub_env_set_net_property (name, "clientid", (const char *) opt, opt_len); - - opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_UUID, &opt_len); - if (opt && opt_len == 17) - { - /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */ - char *val; - int i, j = 0; - - opt += 1; - opt_len -= 1; - - val = grub_malloc (2 * opt_len + 4 + 1); - if (!val) - return inter; - - for (i = 0; i < opt_len; i++) - { - val[2 * i + j] = hexdigit (opt[i] >> 4); - val[2 * i + 1 + j] = hexdigit (opt[i] & 0xf); - - if ((i == 3) || (i == 5) || (i == 7) || (i == 9)) - { - j++; - val[2 * i + 1+ j] = '-'; - } - } - grub_env_set_net_property (name, "clientuuid", (char *) val, 2 * opt_len + 4); - grub_free (val); - } - inter->dhcp_ack = grub_malloc (size); if (inter->dhcp_ack) { @@ -462,217 +256,44 @@ grub_net_configure_by_dhcp_ack (const char *name, return inter; } -static grub_err_t -send_dhcp_packet (struct grub_net_network_level_interface *iface) -{ - grub_err_t err; - struct grub_net_bootp_packet *pack; - struct grub_datetime date; - grub_int32_t t = 0; - struct grub_net_buff *nb; - struct udphdr *udph; - grub_net_network_level_address_t target; - grub_net_link_level_address_t ll_target; - - static struct grub_dhcp_discover_options discover_options = - { - { - GRUB_NET_BOOTP_RFC1048_MAGIC_0, - GRUB_NET_BOOTP_RFC1048_MAGIC_1, - GRUB_NET_BOOTP_RFC1048_MAGIC_2, - GRUB_NET_BOOTP_RFC1048_MAGIC_3, - }, - { - GRUB_NET_DHCP_MESSAGE_TYPE, - sizeof (discover_options.message_type.data), - GRUB_DHCP_MESSAGE_DISCOVER, - }, - GRUB_NET_BOOTP_END, - }; - - static struct grub_dhcp_request_options request_options = - { - { - GRUB_NET_BOOTP_RFC1048_MAGIC_0, - GRUB_NET_BOOTP_RFC1048_MAGIC_1, - GRUB_NET_BOOTP_RFC1048_MAGIC_2, - GRUB_NET_BOOTP_RFC1048_MAGIC_3, - }, - { - GRUB_NET_DHCP_MESSAGE_TYPE, - sizeof (request_options.message_type.data), - GRUB_DHCP_MESSAGE_REQUEST, - }, - { - GRUB_NET_DHCP_SERVER_IDENTIFIER, - sizeof (request_options.server_identifier.data), - 0, - }, - { - GRUB_NET_DHCP_REQUESTED_IP_ADDRESS, - sizeof (request_options.requested_ip.data), - 0, - }, - { - GRUB_NET_DHCP_PARAMETER_REQUEST_LIST, - sizeof (request_options.parameter_request.data), - { - GRUB_NET_BOOTP_NETMASK, - GRUB_NET_BOOTP_ROUTER, - GRUB_NET_BOOTP_DNS, - GRUB_NET_BOOTP_DOMAIN, - GRUB_NET_BOOTP_HOSTNAME, - GRUB_NET_BOOTP_ROOT_PATH, - GRUB_NET_BOOTP_EXTENSIONS_PATH, - }, - }, - GRUB_NET_BOOTP_END, - }; - - COMPILE_TIME_ASSERT (sizeof (discover_options) <= GRUB_BOOTP_MAX_OPTIONS_SIZE); - COMPILE_TIME_ASSERT (sizeof (request_options) <= GRUB_BOOTP_MAX_OPTIONS_SIZE); - - nb = grub_netbuff_alloc (sizeof (*pack) + GRUB_BOOTP_MAX_OPTIONS_SIZE + 128); - if (!nb) - return grub_errno; - - err = grub_netbuff_reserve (nb, sizeof (*pack) + GRUB_BOOTP_MAX_OPTIONS_SIZE + 128); - if (err) - goto out; - - err = grub_netbuff_push (nb, GRUB_BOOTP_MAX_OPTIONS_SIZE); - if (err) - goto out; - - grub_memset (nb->data, 0, GRUB_BOOTP_MAX_OPTIONS_SIZE); - if (!iface->srv_id) - { - grub_memcpy (nb->data, &discover_options, sizeof (discover_options)); - } - else - { - struct grub_dhcp_request_options *ro = (struct grub_dhcp_request_options *) nb->data; - - grub_memcpy (nb->data, &request_options, sizeof (request_options)); - /* my_ip and srv_id are stored in network order so do not need conversion. */ - grub_set_unaligned32 (&ro->server_identifier.data, iface->srv_id); - grub_set_unaligned32 (&ro->requested_ip.data, iface->my_ip); - } - - err = grub_netbuff_push (nb, sizeof (*pack)); - if (err) - goto out; - - pack = (void *) nb->data; - grub_memset (pack, 0, sizeof (*pack)); - pack->opcode = 1; - pack->hw_type = 1; - pack->hw_len = 6; - err = grub_get_datetime (&date); - if (err || !grub_datetime2unixtime (&date, &t)) - { - grub_errno = GRUB_ERR_NONE; - t = 0; - } - pack->seconds = grub_cpu_to_be16 (t); - if (!iface->srv_id) - iface->xid = pack->ident = grub_cpu_to_be32 (t); - else - pack->ident = iface->xid; - - grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, 6); - - grub_netbuff_push (nb, sizeof (*udph)); - - udph = (struct udphdr *) nb->data; - udph->src = grub_cpu_to_be16_compile_time (68); - udph->dst = grub_cpu_to_be16_compile_time (67); - udph->chksum = 0; - udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; - target.ipv4 = 0xffffffff; - err = grub_net_link_layer_resolve (iface, &target, &ll_target); - if (err) - goto out; - - udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP, - &iface->address, - &target); - - err = grub_net_send_ip_packet (iface, &target, &ll_target, nb, - GRUB_NET_IP_UDP); - -out: - grub_netbuff_free (nb); - return err; -} - -/* - * This is called directly from net/ip.c:handle_dgram(), because those - * BOOTP/DHCP packets are a bit special due to their improper - * sender/receiver IP fields. - */ void grub_net_process_dhcp (struct grub_net_buff *nb, - struct grub_net_network_level_interface *iface) + struct grub_net_card *card) { char *name; - struct grub_net_card *card = iface->card; - const struct grub_net_bootp_packet *bp = (const struct grub_net_bootp_packet *) nb->data; - grub_size_t size = nb->tail - nb->data; - const grub_uint8_t *opt; - grub_uint8_t opt_len, type; - grub_uint32_t srv_id = 0; + struct grub_net_network_level_interface *inf; - opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_MESSAGE_TYPE, &opt_len); - if (opt && opt_len == 1) - type = *opt; + name = grub_xasprintf ("%s:dhcp", card->name); + if (!name) + { + grub_print_error (); + return; + } + grub_net_configure_by_dhcp_ack (name, card, + 0, (const struct grub_net_bootp_packet *) nb->data, + (nb->tail - nb->data), 0, 0, 0); + grub_free (name); + if (grub_errno) + grub_print_error (); else - type = GRUB_DHCP_MESSAGE_UNKNOWN; + { + FOR_NET_NETWORK_LEVEL_INTERFACES(inf) + if (grub_memcmp (inf->name, card->name, grub_strlen (card->name)) == 0 + && grub_memcmp (inf->name + grub_strlen (card->name), + ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0) + { + grub_net_network_level_interface_unregister (inf); + break; + } + } +} - opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_SERVER_IDENTIFIER, &opt_len); - if (opt && opt_len == sizeof (srv_id)) - srv_id = grub_get_unaligned32 (opt); - - /* - * If we received BOOTP reply or DHCPACK, proceed with configuration. - * Otherwise store offered address and server id for later processing - * of DHCPACK. - * xid and srv_id are stored in network order so do not need conversion. - */ - if ((!iface->srv_id && type == GRUB_DHCP_MESSAGE_UNKNOWN) - || (iface->srv_id && type == GRUB_DHCP_MESSAGE_ACK - && bp->ident == iface->xid - && srv_id == iface->srv_id)) - { - name = grub_xasprintf ("%s:dhcp", card->name); - if (!name) - { - grub_print_error (); - return; - } - grub_net_configure_by_dhcp_ack (name, card, 0, bp, size, 0, 0, 0); - grub_free (name); - if (grub_errno) - grub_print_error (); - else - grub_net_network_level_interface_unregister (iface); - } - else if (!iface->srv_id && type == GRUB_DHCP_MESSAGE_OFFER && srv_id) - { - iface->srv_id = srv_id; - iface->my_ip = bp->your_ip; - /* Reset retransmission timer */ - iface->dhcp_tmo = iface->dhcp_tmo_left = 1; - } - else if (iface->srv_id && type == GRUB_DHCP_MESSAGE_NAK - && bp->ident == iface->xid - && srv_id == iface->srv_id) - { - iface->xid = iface->srv_id = iface->my_ip = 0; - /* Reset retransmission timer */ - iface->dhcp_tmo = iface->dhcp_tmo_left = 1; - } +static char +hexdigit (grub_uint8_t val) +{ + if (val < 10) + return val + '0'; + return val + 'a' - 10; } static grub_err_t @@ -680,8 +301,8 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), int argc, char **args) { struct grub_net_network_level_interface *inter; - unsigned num; - const grub_uint8_t *ptr; + int num; + grub_uint8_t *ptr; grub_uint8_t taglength; if (argc < 4) @@ -699,31 +320,47 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), if (!inter->dhcp_ack) return grub_error (GRUB_ERR_IO, N_("no DHCP info found")); - ptr = inter->dhcp_ack->vendor; - - /* This duplicates check in find_dhcp_option to preserve previous error return */ - if (inter->dhcp_acklen < OFFSET_OF (vendor, inter->dhcp_ack) + sizeof (grub_uint32_t) - || ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 - || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 - || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 - || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) + if (inter->dhcp_acklen <= OFFSET_OF (vendor, inter->dhcp_ack)) return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); num = grub_strtoul (args[2], 0, 0); if (grub_errno) return grub_errno; - /* Exclude PAD (0) and END (255) option codes */ - if (num == 0 || num > 254) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid DHCP option code")); + ptr = inter->dhcp_ack->vendor; - ptr = find_dhcp_option (inter->dhcp_ack, inter->dhcp_acklen, num, &taglength); - if (!ptr) - return grub_error (GRUB_ERR_IO, N_("no DHCP option %u found"), num); + if (ptr[0] != GRUB_NET_BOOTP_RFC1048_MAGIC_0 + || ptr[1] != GRUB_NET_BOOTP_RFC1048_MAGIC_1 + || ptr[2] != GRUB_NET_BOOTP_RFC1048_MAGIC_2 + || ptr[3] != GRUB_NET_BOOTP_RFC1048_MAGIC_3) + return grub_error (GRUB_ERR_IO, N_("no DHCP options found")); + ptr = ptr + sizeof (grub_uint32_t); + while (1) + { + grub_uint8_t tagtype; + + if (ptr >= ((grub_uint8_t *) inter->dhcp_ack) + inter->dhcp_acklen) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + tagtype = *ptr++; + + /* Pad tag. */ + if (tagtype == 0) + continue; + + /* End tag. */ + if (tagtype == 0xff) + return grub_error (GRUB_ERR_IO, N_("no DHCP option %d found"), num); + + taglength = *ptr++; + + if (tagtype == num) + break; + ptr += taglength; + } if (grub_strcmp (args[3], "string") == 0) { - grub_err_t err = GRUB_ERR_NONE; char *val = grub_malloc (taglength + 1); if (!val) return grub_errno; @@ -732,9 +369,8 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), if (args[0][0] == '-' && args[0][1] == 0) grub_printf ("%s\n", val); else - err = grub_env_set (args[0], val); - grub_free (val); - return err; + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; } if (grub_strcmp (args[3], "number") == 0) @@ -756,7 +392,6 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), if (grub_strcmp (args[3], "hex") == 0) { - grub_err_t err = GRUB_ERR_NONE; char *val = grub_malloc (2 * taglength + 1); int i; if (!val) @@ -770,9 +405,8 @@ grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), if (args[0][0] == '-' && args[0][1] == 0) grub_printf ("%s\n", val); else - err = grub_env_set (args[0], val); - grub_free (val); - return err; + return grub_env_set (args[0], val); + return GRUB_ERR_NONE; } return grub_error (GRUB_ERR_BAD_ARGUMENT, @@ -789,8 +423,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), struct grub_net_network_level_interface *ifaces; grub_size_t ncards = 0; unsigned j = 0; + int interval; grub_err_t err; - unsigned i; FOR_NET_CARDS (card) { @@ -802,7 +436,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), if (ncards == 0) return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); - ifaces = grub_calloc (ncards, sizeof (ifaces[0])); + ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); if (!ifaces) return grub_errno; @@ -819,6 +453,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), card->num_ifaces++; if (!ifaces[j].name) { + unsigned i; for (i = 0; i < j; i++) grub_free (ifaces[i].name); grub_free (ifaces); @@ -827,7 +462,6 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV; grub_memcpy (&ifaces[j].hwaddress, &card->default_address, sizeof (ifaces[j].hwaddress)); - ifaces[j].dhcp_tmo = ifaces[j].dhcp_tmo_left = 1; j++; } ifaces[ncards - 1].next = grub_net_network_level_interfaces; @@ -835,52 +469,82 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), grub_net_network_level_interfaces->prev = & ifaces[ncards - 1].next; grub_net_network_level_interfaces = &ifaces[0]; ifaces[0].prev = &grub_net_network_level_interfaces; - - /* - * Running DHCP restransmission timer is kept per interface in dhcp_tmo_left. - * When it runs off, dhcp_tmo is increased exponentionally and dhcp_tmo_left - * initialized to it. Max value is 32 which gives approximately 12s total per - * packet timeout assuming 200ms poll tick. Timeout is reset when DHCP OFFER - * is received, so total timeout is 25s in the worst case. - * - * DHCP NAK also resets timer and transaction starts again. - * - * Total wait time is limited to ~25s to prevent endless loop in case of - * permanent NAK - */ - for (i = 0; i < GRUB_DHCP_MAX_PACKET_TIMEOUT * 4; i++) + for (interval = 200; interval < 10000; interval *= 2) { - int need_poll = 0; + int done = 0; for (j = 0; j < ncards; j++) { - if (!ifaces[j].prev || - ifaces[j].dhcp_tmo > GRUB_DHCP_MAX_PACKET_TIMEOUT) - continue; + struct grub_net_bootp_packet *pack; + struct grub_datetime date; + grub_int32_t t = 0; + struct grub_net_buff *nb; + struct udphdr *udph; + grub_net_network_level_address_t target; + grub_net_link_level_address_t ll_target; - if (--ifaces[j].dhcp_tmo_left) + if (!ifaces[j].prev) + continue; + nb = grub_netbuff_alloc (sizeof (*pack) + 64 + 128); + if (!nb) { - need_poll = 1; - continue; + grub_netbuff_free (nb); + return grub_errno; } - - ifaces[j].dhcp_tmo *= 2; - if (ifaces[j].dhcp_tmo > GRUB_DHCP_MAX_PACKET_TIMEOUT) - continue; - - err = send_dhcp_packet (&ifaces[j]); + err = grub_netbuff_reserve (nb, sizeof (*pack) + 64 + 128); if (err) { - grub_print_error (); - /* To ignore it during next poll */ - ifaces[j].dhcp_tmo = GRUB_DHCP_MAX_PACKET_TIMEOUT + 1; - continue; + grub_netbuff_free (nb); + return err; } - ifaces[j].dhcp_tmo_left = ifaces[j].dhcp_tmo; - need_poll = 1; + err = grub_netbuff_push (nb, sizeof (*pack) + 64); + if (err) + { + grub_netbuff_free (nb); + return err; + } + pack = (void *) nb->data; + done = 1; + grub_memset (pack, 0, sizeof (*pack) + 64); + pack->opcode = 1; + pack->hw_type = 1; + pack->hw_len = 6; + err = grub_get_datetime (&date); + if (err || !grub_datetime2unixtime (&date, &t)) + { + grub_errno = GRUB_ERR_NONE; + t = 0; + } + pack->ident = grub_cpu_to_be32 (t); + pack->seconds = grub_cpu_to_be16 (t); + + grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); + + grub_netbuff_push (nb, sizeof (*udph)); + + udph = (struct udphdr *) nb->data; + udph->src = grub_cpu_to_be16_compile_time (68); + udph->dst = grub_cpu_to_be16_compile_time (67); + udph->chksum = 0; + udph->len = grub_cpu_to_be16 (nb->tail - nb->data); + target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + target.ipv4 = 0xffffffff; + err = grub_net_link_layer_resolve (&ifaces[j], &target, &ll_target); + if (err) + return err; + + udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP, + &ifaces[j].address, + &target); + + err = grub_net_send_ip_packet (&ifaces[j], &target, &ll_target, nb, + GRUB_NET_IP_UDP); + grub_netbuff_free (nb); + if (err) + return err; } - if (!need_poll) + if (!done) break; - grub_net_poll_cards (200, 0); + grub_net_poll_cards (interval, 0); } err = GRUB_ERR_NONE; @@ -900,7 +564,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), return err; } -static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp; +static grub_command_t cmd_getdhcp, cmd_bootp; void grub_bootp_init (void) @@ -908,9 +572,6 @@ grub_bootp_init (void) cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, N_("[CARD]"), N_("perform a bootp autoconfiguration")); - cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp, - N_("[CARD]"), - N_("perform a DHCP autoconfiguration")); cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); @@ -921,5 +582,4 @@ grub_bootp_fini (void) { grub_unregister_command (cmd_getdhcp); grub_unregister_command (cmd_bootp); - grub_unregister_command (cmd_dhcp); } diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c index 906ec7d67..0b771fb10 100644 --- a/grub-core/net/dns.c +++ b/grub-core/net/dns.c @@ -22,7 +22,6 @@ #include #include #include -#include struct dns_cache_element { @@ -52,15 +51,9 @@ grub_net_add_dns_server (const struct grub_net_network_level_address *s) { int na = dns_servers_alloc * 2; struct grub_net_network_level_address *ns; - grub_size_t sz; - if (na < 8) na = 8; - - if (grub_mul (na, sizeof (ns[0]), &sz)) - return GRUB_ERR_OUT_OF_RANGE; - - ns = grub_realloc (dns_servers, sz); + ns = grub_realloc (dns_servers, na * sizeof (ns[0])); if (!ns) return grub_errno; dns_servers_alloc = na; @@ -245,15 +238,6 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), char *redirect_save = NULL; grub_uint32_t ttl_all = ~0U; - /* Code apparently assumed that only one packet is received as response. - We may get multiple responses due to network condition, so check here - and quit early. */ - if (*data->addresses) - { - grub_netbuff_free (nb); - return GRUB_ERR_NONE; - } - head = (struct dns_header *) nb->data; ptr = (grub_uint8_t *) (head + 1); if (ptr >= nb->tail) @@ -278,7 +262,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), grub_netbuff_free (nb); return GRUB_ERR_NONE; } - for (i = 0; i < grub_be_to_cpu16 (head->qdcount); i++) + for (i = 0; i < grub_cpu_to_be16 (head->qdcount); i++) { if (ptr >= nb->tail) { @@ -292,8 +276,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), ptr++; ptr += 4; } - *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), - sizeof ((*data->addresses)[0])); + *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) + * grub_cpu_to_be16 (head->ancount)); if (!*data->addresses) { grub_errno = GRUB_ERR_NONE; @@ -302,7 +286,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), } reparse_ptr = ptr; reparse: - for (i = 0, ptr = reparse_ptr; i < grub_be_to_cpu16 (head->ancount); i++) + for (i = 0, ptr = reparse_ptr; i < grub_cpu_to_be16 (head->ancount); i++) { int ignored = 0; grub_uint8_t class; @@ -413,8 +397,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), dns_cache[h].addresses = 0; dns_cache[h].name = grub_strdup (data->oname); dns_cache[h].naddresses = *data->naddresses; - dns_cache[h].addresses = grub_calloc (*data->naddresses, - sizeof (dns_cache[h].addresses[0])); + dns_cache[h].addresses = grub_malloc (*data->naddresses + * sizeof (dns_cache[h].addresses[0])); dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; if (!dns_cache[h].addresses || !dns_cache[h].name) { @@ -453,7 +437,7 @@ grub_net_dns_lookup (const char *name, struct recv_data data = {naddresses, addresses, cache, grub_cpu_to_be16 (id++), 0, 0, name, 0}; grub_uint8_t *nbd; - grub_size_t try_server = 0; + int have_server = 0; if (!servers) { @@ -486,7 +470,7 @@ grub_net_dns_lookup (const char *name, } } - sockets = grub_calloc (n_servers, sizeof (sockets[0])); + sockets = grub_malloc (sizeof (sockets[0]) * n_servers); if (!sockets) return grub_errno; @@ -559,35 +543,38 @@ grub_net_dns_lookup (const char *name, for (i = 0; i < n_servers * 4; i++) { /* Connect to a next server. */ - while (!(i & 1) && try_server < n_servers) + while (!(i & 1) && send_servers < n_servers) { - sockets[send_servers] = grub_net_udp_open (servers[try_server++], + sockets[send_servers] = grub_net_udp_open (servers[send_servers], DNS_PORT, recv_hook, &data); - if (!sockets[send_servers]) + send_servers++; + if (!sockets[send_servers - 1]) { err = grub_errno; grub_errno = GRUB_ERR_NONE; } else { - send_servers++; + have_server = 1; break; } } - if (!send_servers) + if (!have_server) goto out; if (*data.naddresses) goto out; for (j = 0; j < send_servers; j++) { grub_err_t err2; + if (!sockets[j]) + continue; + nb->data = nbd; grub_size_t t = 0; do { - nb->data = nbd; if (servers[j].option == DNS_OPTION_IPV4 || ((servers[j].option == DNS_OPTION_PREFER_IPV4) && (t++ == 0)) || ((servers[j].option == DNS_OPTION_PREFER_IPV6) && (t++ == 1))) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 5388f952b..2b344d6ef 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -37,29 +37,28 @@ send_card_buffer (struct grub_net_card *dev, grub_efi_status_t st; grub_efi_simple_network_t *net = dev->efi_net; grub_uint64_t limit_time = grub_get_time_ms () + 4000; - void *txbuf; if (dev->txbusy) while (1) { - txbuf = NULL; + void *txbuf = NULL; st = efi_call_3 (net->get_status, net, 0, &txbuf); if (st != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_IO, N_("couldn't send network packet")); - /* - Some buggy firmware could return an arbitrary address instead of the - txbuf address we trasmitted, so just check that txbuf is non NULL - for success. This is ok because we open the SNP protocol in - exclusive mode so we know we're the only ones transmitting on this - box and since we only transmit one packet at a time we know our - transmit was successfull. - */ - if (txbuf) + if (txbuf == dev->txbuf) { dev->txbusy = 0; break; } + if (txbuf) + { + st = efi_call_7 (net->transmit, net, 0, dev->last_pkt_size, + dev->txbuf, NULL, NULL, NULL); + if (st != GRUB_EFI_SUCCESS) + return grub_error (GRUB_ERR_IO, + N_("couldn't send network packet")); + } if (limit_time < grub_get_time_ms ()) return grub_error (GRUB_ERR_TIMEOUT, N_("couldn't send network packet")); @@ -75,19 +74,7 @@ send_card_buffer (struct grub_net_card *dev, dev->txbuf, NULL, NULL, NULL); if (st != GRUB_EFI_SUCCESS) return grub_error (GRUB_ERR_IO, N_("couldn't send network packet")); - - /* - The card may have sent out the packet immediately - set txbusy - to 0 in this case. - Cases were observed where checking txbuf at the next call - of send_card_buffer() is too late: 0 is returned in txbuf and - we run in the GRUB_ERR_TIMEOUT case above. - Perhaps a timeout in the FW has discarded the recycle buffer. - */ - txbuf = NULL; - st = efi_call_3 (net->get_status, net, 0, &txbuf); - dev->txbusy = !(st == GRUB_EFI_SUCCESS && txbuf); - + dev->txbusy = 1; return GRUB_ERR_NONE; } @@ -143,80 +130,9 @@ get_card_packet (struct grub_net_card *dev) return nb; } -static grub_err_t -open_card (struct grub_net_card *dev) -{ - grub_efi_simple_network_t *net; - - /* Try to reopen SNP exlusively to close any active MNP protocol instance - that may compete for packet polling - */ - net = grub_efi_open_protocol (dev->efi_handle, &net_io_guid, - GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); - if (net) - { - if (net->mode->state == GRUB_EFI_NETWORK_STOPPED - && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net start failed", - dev->name); - - if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) - return grub_error (GRUB_ERR_NET_NO_CARD, "%s: card stopped", - dev->name); - - if (net->mode->state == GRUB_EFI_NETWORK_STARTED - && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) - return grub_error (GRUB_ERR_NET_NO_CARD, "%s: net initialize failed", - dev->name); - - /* Enable hardware receive filters if driver declares support for it. - We need unicast and broadcast and additionaly all nodes and - solicited multicast for IPv6. Solicited multicast is per-IPv6 - address and we currently do not have API to do it so simply - try to enable receive of all multicast packets or evertyhing in - the worst case (i386 PXE driver always enables promiscuous too). - - This does trust firmware to do what it claims to do. - */ - if (net->mode->receive_filter_mask) - { - grub_uint32_t filters = GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; - - filters &= net->mode->receive_filter_mask; - if (!(filters & GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST)) - filters |= (net->mode->receive_filter_mask & - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS); - - efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL); - } - - efi_call_4 (grub_efi_system_table->boot_services->close_protocol, - dev->efi_net, &net_io_guid, - grub_efi_image_handle, dev->efi_handle); - dev->efi_net = net; - } - - /* If it failed we just try to run as best as we can */ - return GRUB_ERR_NONE; -} - -static void -close_card (struct grub_net_card *dev) -{ - efi_call_1 (dev->efi_net->shutdown, dev->efi_net); - efi_call_1 (dev->efi_net->stop, dev->efi_net); - efi_call_4 (grub_efi_system_table->boot_services->close_protocol, - dev->efi_net, &net_io_guid, - grub_efi_image_handle, dev->efi_handle); -} - static struct grub_net_card_driver efidriver = { .name = "efinet", - .open = open_card, - .close = close_card, .send = send_card_buffer, .recv = get_card_packet }; @@ -246,29 +162,6 @@ grub_efinet_findcards (void) { grub_efi_simple_network_t *net; struct grub_net_card *card; - grub_efi_device_path_t *dp, *parent = NULL, *child = NULL; - - /* EDK2 UEFI PXE driver creates IPv4 and IPv6 messaging devices as - children of main MAC messaging device. We only need one device with - bound SNP per physical card, otherwise they compete with each other - when polling for incoming packets. - */ - dp = grub_efi_get_device_path (*handle); - if (!dp) - continue; - for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp); dp = GRUB_EFI_NEXT_DEVICE_PATH (dp)) - { - parent = child; - child = dp; - } - if (child - && GRUB_EFI_DEVICE_PATH_TYPE (child) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE - && (GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE - || GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) - && parent - && GRUB_EFI_DEVICE_PATH_TYPE (parent) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE - && GRUB_EFI_DEVICE_PATH_SUBTYPE (parent) == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE) - continue; net = grub_efi_open_protocol (*handle, &net_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); @@ -346,33 +239,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, if (! cdp) continue; if (grub_efi_compare_device_paths (dp, cdp) != 0) - { - grub_efi_device_path_t *ldp, *dup_dp, *dup_ldp; - int match; - - /* EDK2 UEFI PXE driver creates pseudo devices with type IPv4/IPv6 - as children of Ethernet card and binds PXE and Load File protocols - to it. Loaded Image Device Path protocol will point to these pseudo - devices. We skip them when enumerating cards, so here we need to - find matching MAC device. - */ - ldp = grub_efi_find_last_device_path (dp); - if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE - || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE - && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) - continue; - dup_dp = grub_efi_duplicate_device_path (dp); - if (!dup_dp) - continue; - dup_ldp = grub_efi_find_last_device_path (dup_dp); - dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; - dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; - dup_ldp->length = sizeof (*dup_ldp); - match = grub_efi_compare_device_paths (dup_dp, cdp) == 0; - grub_free (dup_dp); - if (!match) - continue; - } + continue; pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (! pxe) diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c index b19492086..7c977cd52 100644 --- a/grub-core/net/drivers/emu/emunet.c +++ b/grub-core/net/drivers/emu/emunet.c @@ -98,7 +98,7 @@ static int registered = 0; GRUB_MOD_INIT(emunet) { - if (!grub_emunet_create (&emucard.mtu)) + if (grub_emunet_create (&emucard.mtu)) { grub_net_card_register (&emucard); registered = 1; diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c index 3f4152d03..e8c0b22e2 100644 --- a/grub-core/net/drivers/i386/pc/pxe.c +++ b/grub-core/net/drivers/i386/pc/pxe.c @@ -218,7 +218,8 @@ grub_pxe_recv (struct grub_net_card *dev __attribute__ ((unused))) return NULL; /* Reserve 2 bytes so that 2 + 14/18 bytes of ethernet header is divisible by 4. So that IP header is aligned on 4 bytes. */ - if (grub_netbuff_reserve (buf, 2)) + grub_netbuff_reserve (buf, 2); + if (!buf) { grub_netbuff_free (buf); return NULL; diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index ac4e62a95..7eefb9aed 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -85,30 +85,24 @@ get_card_packet (struct grub_net_card *dev) grub_uint64_t start_time; struct grub_net_buff *nb; - start_time = grub_get_time_ms (); - do - rc = grub_ieee1275_read (data->handle, dev->rcvbuf, dev->rcvbufsize, &actual); - while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200)); - - if (actual <= 0) - return NULL; - - nb = grub_netbuff_alloc (actual + 2); + nb = grub_netbuff_alloc (dev->mtu + 64 + 2); if (!nb) return NULL; /* Reserve 2 bytes so that 2 + 14/18 bytes of ethernet header is divisible by 4. So that IP header is aligned on 4 bytes. */ grub_netbuff_reserve (nb, 2); - grub_memcpy (nb->data, dev->rcvbuf, actual); - - if (grub_netbuff_put (nb, actual)) + start_time = grub_get_time_ms (); + do + rc = grub_ieee1275_read (data->handle, nb->data, dev->mtu + 64, &actual); + while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200)); + if (actual > 0) { - grub_netbuff_free (nb); - return NULL; + grub_netbuff_put (nb, actual); + return nb; } - - return nb; + grub_netbuff_free (nb); + return NULL; } static struct grub_net_card_driver ofdriver = @@ -153,11 +147,11 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, char *comma_char = 0; char *equal_char = 0; grub_size_t field_counter = 0; - grub_net_network_level_address_t client_addr = {0, {0}, 0}, gateway_addr = {0, {0}, 0}, subnet_mask = {0, {0}, 0}; - grub_net_link_level_address_t hw_addr = {0, {{0, 0, 0, 0, 0, 0}}}; + grub_net_network_level_address_t client_addr, gateway_addr, subnet_mask; + grub_net_link_level_address_t hw_addr; grub_net_interface_flags_t flags = 0; - struct grub_net_network_level_interface *inter = NULL; - grub_uint16_t vlantag = 0; + struct grub_net_network_level_interface *inter; + grub_uint32_t vlantag = 0; hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; @@ -177,8 +171,15 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, grub_strlen(equal_char + 1)); if ((grub_strcmp (args, "vtag") == 0) && - (grub_strlen (equal_char + 1) == 8)) - vlantag = grub_strtoul (equal_char + 1 + 4, 0, 16); + (grub_strlen (equal_char + 1) > 4)) + { + vlantag = grub_strtoul (equal_char + 1, 0, 16) & 0xffff; + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + vlantag = 0; + grub_errno = GRUB_ERR_NONE; + } + } *equal_char = '='; } @@ -218,10 +219,14 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, hw_addr.mac, sizeof(hw_addr.mac), 0); inter = grub_net_add_addr ((*card)->name, *card, &client_addr, &hw_addr, flags); - inter->vlantag = vlantag; + if (vlantag > 0) + { + inter->vlantag.set = 1; + inter->vlantag.vid = vlantag & 0xfff; + } + grub_net_add_ipv4_local (inter, __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4))); - } if (gateway_addr.ipv4 != 0) @@ -234,7 +239,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, target.ipv4.masksize = 0; rname = grub_xasprintf ("%s:default", ((*card)->name)); if (rname) - grub_net_add_route_gw (rname, target, gateway_addr, inter); + grub_net_add_route_gw (rname, target, gateway_addr); else return grub_errno; } @@ -307,91 +312,6 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path, } } -/* Allocate memory with alloc-mem */ -static void * -grub_ieee1275_alloc_mem (grub_size_t len) -{ - struct alloc_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t len; - grub_ieee1275_cell_t catch; - grub_ieee1275_cell_t result; - } - args; - - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET)) - { - grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("interpret is not supported")); - return NULL; - } - - INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2); - args.len = len; - args.method = (grub_ieee1275_cell_t) "alloc-mem"; - - if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch) - { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("alloc-mem failed")); - return NULL; - } - else - return (void *)args.result; -} - -/* Free memory allocated by alloc-mem */ -static grub_err_t -grub_ieee1275_free_mem (void *addr, grub_size_t len) -{ - struct free_args - { - struct grub_ieee1275_common_hdr common; - grub_ieee1275_cell_t method; - grub_ieee1275_cell_t len; - grub_ieee1275_cell_t addr; - grub_ieee1275_cell_t catch; - } - args; - - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET)) - { - grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("interpret is not supported")); - return grub_errno; - } - - INIT_IEEE1275_COMMON (&args.common, "interpret", 3, 1); - args.addr = (grub_ieee1275_cell_t)addr; - args.len = len; - args.method = (grub_ieee1275_cell_t) "free-mem"; - - if (IEEE1275_CALL_ENTRY_FN(&args) == -1 || args.catch) - { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("free-mem failed")); - return grub_errno; - } - - return GRUB_ERR_NONE; -} - -static void * -ofnet_alloc_netbuf (grub_size_t len) -{ - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN)) - return grub_ieee1275_alloc_mem (len); - else - return grub_zalloc (len); -} - -static void -ofnet_free_netbuf (void *addr, grub_size_t len) -{ - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN)) - grub_ieee1275_free_mem (addr, len); - else - grub_free (addr); -} - static int search_net_devices (struct grub_ieee1275_devalias *alias) { @@ -403,7 +323,6 @@ search_net_devices (struct grub_ieee1275_devalias *alias) grub_uint64_t prop; grub_uint8_t *pprop; char *shortname; - char need_suffix = 1; if (grub_strcmp (alias->type, "network") != 0) return 0; @@ -424,43 +343,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) #define SUFFIX ":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512" - if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX)) - need_suffix = 0; - - /* sun4v vnet devices do not support setting duplex/speed */ - { - char *ptr; - - grub_ieee1275_finddevice (alias->path, &devhandle); - - grub_ieee1275_get_property_length (devhandle, "compatible", &prop_size); - if (prop_size > 0) - { - pprop = grub_malloc (prop_size); - if (!pprop) - { - grub_free (card); - grub_free (ofdata); - grub_print_error (); - return 1; - } - - if (!grub_ieee1275_get_property (devhandle, "compatible", - pprop, prop_size, NULL)) - { - for (ptr = (char *) pprop; ptr - (char *) pprop < prop_size; - ptr += grub_strlen (ptr) + 1) - { - if (!grub_strcmp(ptr, "SUNW,sun4v-network")) - need_suffix = 0; - } - } - - grub_free (pprop); - } - } - - if (need_suffix) + if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX)) ofdata->path = grub_malloc (grub_strlen (alias->path) + sizeof (SUFFIX)); else ofdata->path = grub_malloc (grub_strlen (alias->path) + 1); @@ -470,7 +353,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) return 0; } ofdata->suffix = grub_stpcpy (ofdata->path, alias->path); - if (need_suffix) + if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX)) grub_memcpy (ofdata->suffix, SUFFIX, sizeof (SUFFIX)); else *ofdata->suffix = '\0'; @@ -507,19 +390,40 @@ search_net_devices (struct grub_ieee1275_devalias *alias) card->default_address = lla; card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; - card->rcvbufsize = ALIGN_UP (card->mtu, 64) + 256; - card->txbuf = ofnet_alloc_netbuf (card->txbufsize); - if (!card->txbuf) - goto fail_netbuf; - - card->rcvbuf = ofnet_alloc_netbuf (card->rcvbufsize); - if (!card->rcvbuf) + if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN)) { - grub_error_push (); - ofnet_free_netbuf (card->txbuf, card->txbufsize); - grub_error_pop (); - goto fail_netbuf; + struct alloc_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t len; + grub_ieee1275_cell_t catch; + grub_ieee1275_cell_t result; + } + args; + INIT_IEEE1275_COMMON (&args.common, "interpret", 2, 2); + args.len = card->txbufsize; + args.method = (grub_ieee1275_cell_t) "alloc-mem"; + + if (IEEE1275_CALL_ENTRY_FN (&args) == -1 + || args.catch) + { + card->txbuf = 0; + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); + } + else + card->txbuf = (void *) args.result; + } + else + card->txbuf = grub_zalloc (card->txbufsize); + if (!card->txbuf) + { + grub_free (ofdata->path); + grub_free (ofdata); + grub_free (card); + grub_print_error (); + return 0; } card->driver = NULL; card->data = ofdata; @@ -532,13 +436,6 @@ search_net_devices (struct grub_ieee1275_devalias *alias) card->driver = &ofdriver; grub_net_card_register (card); return 0; - -fail_netbuf: - grub_free (ofdata->path); - grub_free (ofdata); - grub_free (card); - grub_print_error (); - return 0; } static void diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c index 4d7ceed6f..3a526b3bf 100644 --- a/grub-core/net/ethernet.c +++ b/grub-core/net/ethernet.c @@ -58,13 +58,12 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, struct etherhdr *eth; grub_err_t err; grub_uint8_t etherhdr_size; - grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER; etherhdr_size = sizeof (*eth); COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE); /* Increase ethernet header in case of vlantag */ - if (inf->vlantag != 0) + if (inf->vlantag.set) etherhdr_size += 4; err = grub_netbuff_push (nb, etherhdr_size); @@ -86,15 +85,17 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, } /* Check and add a vlan-tag if needed. */ - if (inf->vlantag != 0) + if (inf->vlantag.set) { + grub_uint32_t vlantag; + vlantag = grub_cpu_to_be32 ((VLANTAG_IDENTIFIER << 16) | inf->vlantag.vid); + /* Move eth type to the right */ grub_memcpy ((char *) nb->data + etherhdr_size - 2, (char *) nb->data + etherhdr_size - 6, 2); /* Add the tag in the middle */ - grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2); - grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *) &(inf->vlantag), 2); + grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag, 4); } return inf->card->driver->send (inf->card, nb); @@ -112,15 +113,16 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, grub_net_link_level_address_t src_hwaddress; grub_err_t err; grub_uint8_t etherhdr_size = sizeof (*eth); - grub_uint16_t vlantag = 0; - + grub_uint16_t vlantag_vid = 0; /* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */ /* longer than the original one. The vlantag id is extracted and the header */ /* is reseted to the original size. */ - if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == VLANTAG_IDENTIFIER) + if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == + grub_cpu_to_be16_compile_time (VLANTAG_IDENTIFIER)) { - vlantag = grub_get_unaligned16 (nb->data + etherhdr_size); + vlantag_vid = grub_be_to_cpu16 (grub_get_unaligned16 (nb->data + + etherhdr_size)) & 0x1fff; etherhdr_size += 4; /* Move eth type to the original position */ grub_memcpy((char *) nb->data + etherhdr_size - 6, @@ -157,14 +159,14 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, { /* ARP packet. */ case GRUB_NET_ETHERTYPE_ARP: - grub_net_arp_receive (nb, card, &vlantag); + grub_net_arp_receive (nb, card, vlantag_vid); grub_netbuff_free (nb); return GRUB_ERR_NONE; /* IP packet. */ case GRUB_NET_ETHERTYPE_IP: case GRUB_NET_ETHERTYPE_IP6: return grub_net_recv_ip_packets (nb, card, &hwaddress, &src_hwaddress, - &vlantag); + vlantag_vid); } grub_netbuff_free (nb); return GRUB_ERR_NONE; diff --git a/grub-core/net/http.c b/grub-core/net/http.c index b616cf40b..4684f8b33 100644 --- a/grub-core/net/http.c +++ b/grub-core/net/http.c @@ -107,7 +107,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) return GRUB_ERR_NONE; } ptr += sizeof ("HTTP/1.1 ") - 1; - code = grub_strtoul (ptr, (const char **)&ptr, 10); + code = grub_strtoul (ptr, &ptr, 10); if (grub_errno) return grub_errno; switch (code) @@ -134,7 +134,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) == 0 && !data->size_recv) { ptr += sizeof ("Content-Length: ") - 1; - file->size = grub_strtoull (ptr, (const char **)&ptr, 10); + file->size = grub_strtoull (ptr, &ptr, 10); data->size_recv = 1; return GRUB_ERR_NONE; } @@ -381,8 +381,9 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) ptr = nb->tail; grub_snprintf ((char *) ptr, sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX-" + "\r\n" "\r\n"), - "Range: bytes=%" PRIuGRUB_UINT64_T "-\r\n", + "Range: bytes=%" PRIuGRUB_UINT64_T "-\r\n\r\n", offset); grub_netbuff_put (nb, grub_strlen ((char *) ptr)); } @@ -392,7 +393,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) data->sock = grub_net_tcp_open (file->device->net->server, HTTP_PORT, http_receive, - http_err, NULL, + http_err, http_err, file); if (!data->sock) { @@ -449,7 +450,6 @@ http_seek (struct grub_file *file, grub_off_t off) } file->device->net->stall = 0; - file->device->net->eof = 0; file->device->net->offset = off; data = grub_zalloc (sizeof (*data)); diff --git a/grub-core/net/icmp.c b/grub-core/net/icmp.c index b1eef114e..28d825ba0 100644 --- a/grub-core/net/icmp.c +++ b/grub-core/net/icmp.c @@ -85,13 +85,22 @@ grub_net_recv_icmp_packet (struct grub_net_buff *nb, struct icmp_header *icmphr; if (icmph->code) break; - nb_reply = grub_netbuff_make_pkt (nb->tail - nb->data + sizeof (*icmphr)); + nb_reply = grub_netbuff_alloc (nb->tail - nb->data + 512); if (!nb_reply) { grub_netbuff_free (nb); return grub_errno; } - grub_memcpy (nb_reply->data + sizeof (*icmphr), nb->data, nb->tail - nb->data); + err = grub_netbuff_reserve (nb_reply, nb->tail - nb->data + 512); + if (err) + goto ping_fail; + err = grub_netbuff_push (nb_reply, nb->tail - nb->data); + if (err) + goto ping_fail; + grub_memcpy (nb_reply->data, nb->data, nb->tail - nb->data); + err = grub_netbuff_push (nb_reply, sizeof (*icmphr)); + if (err) + goto ping_fail; icmphr = (struct icmp_header *) nb_reply->data; icmphr->type = ICMP_ECHO_REPLY; icmphr->code = 0; @@ -101,6 +110,7 @@ grub_net_recv_icmp_packet (struct grub_net_buff *nb, err = grub_net_send_ip_packet (inf, src, ll_src, nb_reply, GRUB_NET_IP_ICMP); + ping_fail: grub_netbuff_free (nb); grub_netbuff_free (nb_reply); return err; diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c index 2cbd95dce..782239460 100644 --- a/grub-core/net/icmp6.c +++ b/grub-core/net/icmp6.c @@ -115,7 +115,6 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, grub_uint8_t ttl) { struct icmp_header *icmph; - struct grub_net_network_level_interface *orig_inf = inf; grub_err_t err; grub_uint16_t checksum; @@ -346,31 +345,14 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, { grub_uint8_t *ptr; struct option_header *ohdr; - struct router_adv *radv; - struct grub_net_network_level_interface *route_inf = NULL; - int default_route = 0; if (icmph->code) break; - radv = (struct router_adv *)nb->data; err = grub_netbuff_pull (nb, sizeof (struct router_adv)); if (err) { grub_netbuff_free (nb); return err; } - if (grub_be_to_cpu16 (radv->router_lifetime) > 0) - { - struct grub_net_route *route; - - FOR_NET_ROUTES (route) - { - if (!grub_memcmp (&route->gw, source, sizeof (route->gw))) - break; - } - if (route == NULL) - default_route = 1; - } - for (ptr = (grub_uint8_t *) nb->data; ptr < nb->tail; ptr += ohdr->len * 8) { @@ -431,11 +413,7 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, /* Update lease time if needed here once we have lease times. */ if (inf) - { - if (!route_inf) - route_inf = inf; - continue; - } + continue; grub_dprintf ("net", "creating slaac\n"); @@ -451,51 +429,12 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, inf = grub_net_add_addr (name, card, &addr, &slaac->address, 0); - if (!route_inf) - route_inf = inf; grub_net_add_route (name, netaddr, inf); grub_free (name); } } } } - if (default_route) - { - char *name; - grub_net_network_level_netaddress_t netaddr; - name = grub_xasprintf ("%s:ra:default6", card->name); - if (!name) - { - grub_errno = GRUB_ERR_NONE; - goto next; - } - /* Default routes take alll of the traffic, so make the mask huge */ - netaddr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; - netaddr.ipv6.masksize = 0; - netaddr.ipv6.base[0] = 0; - netaddr.ipv6.base[1] = 0; - - /* May not have gotten slaac info, find a global address on this - card. */ - if (route_inf == NULL) - { - FOR_NET_NETWORK_LEVEL_INTERFACES (inf) - { - if (inf->card == card && inf != orig_inf - && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6 - && grub_net_hwaddr_cmp(&inf->hwaddress, - &orig_inf->hwaddress) == 0) - { - route_inf = inf; - break; - } - } - } - if (route_inf != NULL) - grub_net_add_route_gw (name, netaddr, *source, route_inf); - grub_free (name); - } -next: if (ptr != nb->tail) break; } @@ -613,8 +552,8 @@ grub_net_icmp6_send_router_solicit (struct grub_net_network_level_interface *inf struct icmp_header *icmphr; multicast.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; - multicast.ipv6[0] = grub_cpu_to_be64_compile_time (0xff02ULL << 48); - multicast.ipv6[1] = grub_cpu_to_be64_compile_time (0x02ULL); + multicast.ipv6[0] = grub_cpu_to_be64 (0xff02ULL << 48); + multicast.ipv6[1] = grub_cpu_to_be64 (0x02ULL); err = grub_net_link_layer_resolve (inf, &multicast, &ll_multicast); if (err) diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index ea5edf8f1..a2addb3f6 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -191,18 +191,15 @@ grub_net_send_ip4_packet (struct grub_net_network_level_interface *inf, grub_net_ip_protocol_t proto) { struct iphdr *iph; - grub_err_t err; COMPILE_TIME_ASSERT (GRUB_NET_OUR_IPV4_HEADER_SIZE == sizeof (*iph)); if (nb->tail - nb->data + sizeof (struct iphdr) > inf->card->mtu) return send_fragmented (inf, target, nb, proto, *ll_target_addr); - err = grub_netbuff_push (nb, sizeof (*iph)); - if (err) - return err; - + grub_netbuff_push (nb, sizeof (*iph)); iph = (struct iphdr *) nb->data; + iph->verhdrlen = ((4 << 4) | 5); iph->service = 0; iph->len = grub_cpu_to_be16 (nb->tail - nb->data); @@ -228,7 +225,7 @@ handle_dgram (struct grub_net_buff *nb, grub_net_ip_protocol_t proto, const grub_net_network_level_address_t *source, const grub_net_network_level_address_t *dest, - grub_uint16_t *vlantag, + grub_uint16_t vlantag_vid, grub_uint8_t ttl) { struct grub_net_network_level_interface *inf = NULL; @@ -279,7 +276,7 @@ handle_dgram (struct grub_net_buff *nb, && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr, sizeof (inf->hwaddress.mac)) == 0) { - grub_net_process_dhcp (nb, inf); + grub_net_process_dhcp (nb, inf->card); grub_netbuff_free (nb); return GRUB_ERR_NONE; } @@ -295,13 +292,11 @@ handle_dgram (struct grub_net_buff *nb, && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) break; - /* Verify vlantag id */ - if (inf->card == card && inf->vlantag != *vlantag) - { - grub_dprintf ("net", "invalid vlantag! %x != %x\n", - inf->vlantag, *vlantag); - break; - } + /* Check vlantag id */ + if (inf->card == card && + ((inf->vlantag.set && vlantag_vid != inf->vlantag.vid) || + (!inf->vlantag.set && vlantag_vid != 0))) + continue; /* Solicited node multicast. */ if (inf->card == card @@ -373,9 +368,7 @@ static void free_old_fragments (void) { struct reassemble *rsm, **prev; - grub_uint64_t limit_time = grub_get_time_ms (); - - limit_time = (limit_time > 90000) ? limit_time - 90000 : 0; + grub_uint64_t limit_time = grub_get_time_ms () - 90000; for (prev = &reassembles, rsm = *prev; rsm; rsm = *prev) if (rsm->last_time < limit_time) @@ -394,7 +387,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb, struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag_vid) { struct iphdr *iph = (struct iphdr *) nb->data; grub_err_t err; @@ -469,7 +462,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb, dest.ipv4 = iph->dest; return handle_dgram (nb, card, src_hwaddress, hwaddress, iph->protocol, - &source, &dest, vlantag, iph->ttl); + &source, &dest, vlantag_vid, iph->ttl); } for (prev = &reassembles, rsm = *prev; rsm; prev = &rsm->next, rsm = *prev) @@ -605,7 +598,7 @@ grub_net_recv_ip4_packets (struct grub_net_buff *nb, dest.ipv4 = dst; return handle_dgram (ret, card, src_hwaddress, - hwaddress, proto, &source, &dest, vlantag, + hwaddress, proto, &source, &dest, vlantag_vid, ttl); } } @@ -618,18 +611,15 @@ grub_net_send_ip6_packet (struct grub_net_network_level_interface *inf, grub_net_ip_protocol_t proto) { struct ip6hdr *iph; - grub_err_t err; COMPILE_TIME_ASSERT (GRUB_NET_OUR_IPV6_HEADER_SIZE == sizeof (*iph)); if (nb->tail - nb->data + sizeof (struct iphdr) > inf->card->mtu) return grub_error (GRUB_ERR_NET_PACKET_TOO_BIG, "packet too big"); - err = grub_netbuff_push (nb, sizeof (*iph)); - if (err) - return err; - + grub_netbuff_push (nb, sizeof (*iph)); iph = (struct ip6hdr *) nb->data; + iph->version_class_flow = grub_cpu_to_be32_compile_time ((6 << 28)); iph->len = grub_cpu_to_be16 (nb->tail - nb->data - sizeof (*iph)); iph->protocol = proto; @@ -664,7 +654,7 @@ grub_net_recv_ip6_packets (struct grub_net_buff *nb, struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag_vid) { struct ip6hdr *iph = (struct ip6hdr *) nb->data; grub_err_t err; @@ -715,7 +705,7 @@ grub_net_recv_ip6_packets (struct grub_net_buff *nb, grub_memcpy (dest.ipv6, &iph->dest, sizeof (dest.ipv6)); return handle_dgram (nb, card, src_hwaddress, hwaddress, iph->protocol, - &source, &dest, vlantag, iph->ttl); + &source, &dest, vlantag_vid, iph->ttl); } grub_err_t @@ -723,16 +713,16 @@ grub_net_recv_ip_packets (struct grub_net_buff *nb, struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag) + grub_uint16_t vlantag_vid) { struct iphdr *iph = (struct iphdr *) nb->data; if ((iph->verhdrlen >> 4) == 4) return grub_net_recv_ip4_packets (nb, card, hwaddress, src_hwaddress, - vlantag); + vlantag_vid); if ((iph->verhdrlen >> 4) == 6) return grub_net_recv_ip6_packets (nb, card, hwaddress, src_hwaddress, - vlantag); + vlantag_vid); grub_dprintf ("net", "Bad IP version: %d\n", (iph->verhdrlen >> 4)); grub_netbuff_free (nb); return GRUB_ERR_NONE; diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 04ad10682..21a4e94d1 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -37,6 +37,21 @@ GRUB_MOD_LICENSE ("GPLv3+"); char *grub_net_default_server; +struct grub_net_route +{ + struct grub_net_route *next; + struct grub_net_route **prev; + grub_net_network_level_netaddress_t target; + char *name; + struct grub_net_network_level_protocol *prot; + int is_gateway; + union + { + struct grub_net_network_level_interface *interface; + grub_net_network_level_address_t gw; + }; +}; + struct grub_net_route *grub_net_routes = NULL; struct grub_net_network_level_interface *grub_net_network_level_interfaces = NULL; struct grub_net_card *grub_net_cards = NULL; @@ -284,6 +299,12 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card, char *ptr; grub_net_network_level_address_t addr; + name = grub_malloc (grub_strlen (card->name) + + GRUB_NET_MAX_STR_HWADDR_LEN + + sizeof (":link")); + if (!name) + return NULL; + addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; addr.ipv6[0] = grub_cpu_to_be64_compile_time (0xfe80ULL << 48); addr.ipv6[1] = grub_net_ipv6_get_id (hwaddr); @@ -296,12 +317,6 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card, return inf; } - name = grub_malloc (grub_strlen (card->name) - + GRUB_NET_MAX_STR_HWADDR_LEN - + sizeof (":link")); - if (!name) - return NULL; - ptr = grub_stpcpy (name, card->name); if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0) { @@ -333,8 +348,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), ncards++; } - ifaces = grub_calloc (ncards, sizeof (ifaces[0])); - slaacs = grub_calloc (ncards, sizeof (slaacs[0])); + ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); + slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); if (!ifaces || !slaacs) { grub_free (ifaces); @@ -395,6 +410,14 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), return err; } +static inline void +grub_net_route_register (struct grub_net_route *route) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), + GRUB_AS_LIST (route)); +} + +#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) static int parse_ip (const char *val, grub_uint32_t *ip, const char **rest) @@ -406,7 +429,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) for (i = 0; i < 4; i++) { unsigned long t; - t = grub_strtoul (ptr, &ptr, 0); + t = grub_strtoul (ptr, (char **) &ptr, 0); if (grub_errno) { grub_errno = GRUB_ERR_NONE; @@ -453,7 +476,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) ptr++; continue; } - t = grub_strtoul (ptr, &ptr, 16); + t = grub_strtoul (ptr, (char **) &ptr, 16); if (grub_errno) { grub_errno = GRUB_ERR_NONE; @@ -501,8 +524,6 @@ match_net (const grub_net_network_level_netaddress_t *net, case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: { grub_uint64_t mask[2]; - if (net->ipv6.masksize == 0) - return 1; if (net->ipv6.masksize <= 64) { mask[0] = 0xffffffffffffffffULL << (64 - net->ipv6.masksize); @@ -563,7 +584,7 @@ grub_net_resolve_net_address (const char *name, addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; if (*rest == '/') { - addr->ipv4.masksize = grub_strtoul (rest + 1, &rest, 0); + addr->ipv4.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); if (!grub_errno && *rest == 0) return GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE; @@ -579,7 +600,7 @@ grub_net_resolve_net_address (const char *name, addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; if (*rest == '/') { - addr->ipv6.masksize = grub_strtoul (rest + 1, &rest, 0); + addr->ipv6.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); if (!grub_errno && *rest == 0) return GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE; @@ -666,14 +687,7 @@ grub_net_route_address (grub_net_network_level_address_t addr, return GRUB_ERR_NONE; } if (depth == 0) - { - *gateway = bestroute->gw; - if (bestroute->interface != NULL) - { - *interf = bestroute->interface; - return GRUB_ERR_NONE; - } - } + *gateway = bestroute->gw; curtarget = bestroute->gw; } @@ -1095,8 +1109,7 @@ grub_net_add_route (const char *name, grub_err_t grub_net_add_route_gw (const char *name, grub_net_network_level_netaddress_t target, - grub_net_network_level_address_t gw, - struct grub_net_network_level_interface *inter) + grub_net_network_level_address_t gw) { struct grub_net_route *route; @@ -1114,7 +1127,6 @@ grub_net_add_route_gw (const char *name, route->target = target; route->is_gateway = 1; route->gw = gw; - route->interface = inter; grub_net_route_register (route); @@ -1140,7 +1152,7 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)), err = grub_net_resolve_address (args[3], &gw); if (err) return err; - return grub_net_add_route_gw (args[0], target, gw, NULL); + return grub_net_add_route_gw (args[0], target, gw); } else { @@ -1310,64 +1322,25 @@ grub_net_open_real (const char *name) if (!ret) return NULL; ret->protocol = proto; - ret->server = grub_strdup (server); - if (!ret->server) + if (server) { - grub_free (ret); - return NULL; + ret->server = grub_strdup (server); + if (!ret->server) + { + grub_free (ret); + return NULL; + } } + else + ret->server = NULL; ret->fs = &grub_net_fs; + ret->offset = 0; + ret->eof = 0; return ret; } } if (try == 0) { - const char *prefix, *root; - char *prefdev, *comma; - int skip = 0; - grub_size_t devlen; - - /* Do not attempt to load module if it requires protocol provided - by this module - it results in infinite recursion. Just continue, - fail and cleanup on next iteration. - */ - prefix = grub_env_get ("prefix"); - if (!prefix) - continue; - - prefdev = grub_file_get_device_name (prefix); - if (!prefdev) - { - root = grub_env_get ("root"); - if (!root) - continue; - prefdev = grub_strdup (root); - if (!prefdev) - continue; - } - - if (grub_strncmp (prefdev, "pxe", sizeof ("pxe") - 1) == 0 && - (!prefdev[sizeof ("pxe") - 1] || (prefdev[sizeof("pxe") - 1] == ':'))) - { - grub_free (prefdev); - prefdev = grub_strdup ("tftp"); - if (!prefdev) - continue; - } - - comma = grub_strchr (prefdev, ','); - if (comma) - *comma = '\0'; - devlen = grub_strlen (prefdev); - - if (protnamelen == devlen && grub_memcmp (prefdev, protname, devlen) == 0) - skip = 1; - - grub_free (prefdev); - - if (skip) - continue; - if (sizeof ("http") - 1 == protnamelen && grub_memcmp ("http", protname, protnamelen) == 0) { @@ -1418,10 +1391,7 @@ grub_net_fs_open (struct grub_file *file_out, const char *name) file->device->net->packs.last = NULL; file->device->net->name = grub_strdup (name); if (!file->device->net->name) - { - grub_free (file); - return grub_errno; - } + return grub_errno; err = file->device->net->protocol->open (file, name); if (err) @@ -1681,7 +1651,6 @@ grub_net_seek_real (struct grub_file *file, grub_off_t offset) file->device->net->packs.last = NULL; file->device->net->offset = 0; file->device->net->eof = 0; - file->device->net->stall = 0; err = file->device->net->protocol->open (file, file->device->net->name); if (err) return err; @@ -1706,13 +1675,13 @@ grub_net_fs_read (grub_file_t file, char *buf, grub_size_t len) static struct grub_fs grub_net_fs = { .name = "netfs", - .fs_dir = grub_net_fs_dir, - .fs_open = grub_net_fs_open, - .fs_read = grub_net_fs_read, - .fs_close = grub_net_fs_close, - .fs_label = NULL, - .fs_uuid = NULL, - .fs_mtime = NULL, + .dir = grub_net_fs_dir, + .open = grub_net_fs_open, + .read = grub_net_fs_read, + .close = grub_net_fs_close, + .label = NULL, + .uuid = NULL, + .mtime = NULL, }; static grub_err_t @@ -1735,138 +1704,6 @@ grub_net_restore_hw (void) return GRUB_ERR_NONE; } -static int -grub_config_search_through (char *config, char *suffix, - grub_size_t num_tries, grub_size_t slice_size) -{ - while (num_tries-- > 0) - { - grub_file_t file; - - grub_dprintf ("net", "attempt to fetch config %s\n", config); - - file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); - - if (file) - { - grub_file_close (file); - return 0; - } - else - { - if (grub_errno == GRUB_ERR_IO) - grub_errno = GRUB_ERR_NONE; - } - - if (grub_strlen (suffix) < slice_size) - break; - - config[grub_strlen (config) - slice_size] = '\0'; - } - - return 1; -} - -grub_err_t -grub_net_search_config_file (char *config) -{ - grub_size_t config_len; - char *suffix; - - config_len = grub_strlen (config); - config[config_len] = '-'; - suffix = config + config_len + 1; - - struct grub_net_network_level_interface *inf; - FOR_NET_NETWORK_LEVEL_INTERFACES (inf) - { - /* By the Client UUID. */ - char *ptr; - int client_uuid_len; - char *client_uuid_var; - const char *client_uuid; - - client_uuid_len = sizeof ("net_") + grub_strlen (inf->name) + - sizeof ("_clientuuid") + 1; - - client_uuid_var = grub_zalloc (client_uuid_len); - if (!client_uuid_var) - return grub_errno; - - grub_snprintf (client_uuid_var, client_uuid_len, - "net_%s_clientuuid", inf->name); - - client_uuid = grub_env_get (client_uuid_var); - grub_free (client_uuid_var); - - if (client_uuid) - { - grub_strcpy (suffix, client_uuid); - if (grub_config_search_through (config, suffix, 1, 0) == 0) - return GRUB_ERR_NONE; - } - - /* By the MAC address. */ - - /* Add ethernet type */ - grub_strcpy (suffix, "01-"); - - grub_net_hwaddr_to_str (&inf->hwaddress, suffix + 3); - - for (ptr = suffix; *ptr; ptr++) - if (*ptr == ':') - *ptr = '-'; - - if (grub_config_search_through (config, suffix, 1, 0) == 0) - return GRUB_ERR_NONE; - - /* By IP address */ - - switch ((&inf->address)->type) - { - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: - { - grub_uint32_t n = grub_be_to_cpu32 ((&inf->address)->ipv4); - - grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%02X%02X%02X%02X", \ - ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ - ((n >> 8) & 0xff), ((n >> 0) & 0xff)); - - if (grub_config_search_through (config, suffix, 8, 1) == 0) - return GRUB_ERR_NONE; - break; - } - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: - { - char buf[GRUB_NET_MAX_STR_ADDR_LEN]; - struct grub_net_network_level_address base; - base.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; - grub_memcpy (&base.ipv6, ((&inf->address)->ipv6), 16); - grub_net_addr_to_str (&base, buf); - - for (ptr = buf; *ptr; ptr++) - if (*ptr == ':') - *ptr = '-'; - - grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); - if (grub_config_search_through (config, suffix, 1, 0) == 0) - return GRUB_ERR_NONE; - break; - } - case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: - return grub_error (GRUB_ERR_BUG, "shouldn't reach here"); - default: - return grub_error (GRUB_ERR_BUG, - "unsupported address type %d", (&inf->address)->type); - } - } - - /* Remove the remaining minus sign at the end. */ - config[config_len] = '\0'; - - return GRUB_ERR_NONE; -} - static struct grub_preboot *fini_hnd; static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; diff --git a/grub-core/net/netbuff.c b/grub-core/net/netbuff.c index dbeeefe47..e97ecd23e 100644 --- a/grub-core/net/netbuff.c +++ b/grub-core/net/netbuff.c @@ -97,26 +97,6 @@ grub_netbuff_alloc (grub_size_t len) return nb; } -struct grub_net_buff * -grub_netbuff_make_pkt (grub_size_t len) -{ - struct grub_net_buff *nb; - grub_err_t err; - nb = grub_netbuff_alloc (len + 512); - if (!nb) - return NULL; - err = grub_netbuff_reserve (nb, len + 512); - if (err) - goto fail; - err = grub_netbuff_push (nb, len); - if (err) - goto fail; - return nb; - fail: - grub_netbuff_free (nb); - return NULL; -} - void grub_netbuff_free (struct grub_net_buff *nb) { diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c index e8ad34b84..1d90f1ec5 100644 --- a/grub-core/net/tcp.c +++ b/grub-core/net/tcp.c @@ -498,22 +498,11 @@ grub_net_tcp_accept (grub_net_tcp_socket_t sock, struct grub_net_buff *nb_ack; struct tcphdr *tcph; grub_err_t err; - grub_net_network_level_address_t gateway; - struct grub_net_network_level_interface *inf; sock->recv_hook = recv_hook; sock->error_hook = error_hook; sock->fin_hook = fin_hook; sock->hook_data = hook_data; - - err = grub_net_route_address (sock->out_nla, &gateway, &inf); - if (err) - return err; - - err = grub_net_link_layer_resolve (sock->inf, &gateway, &(sock->ll_target_addr)); - if (err) - return err; - nb_ack = grub_netbuff_alloc (sizeof (*tcph) + GRUB_NET_OUR_MAX_IP_HEADER_SIZE + GRUB_NET_MAX_LINK_HEADER_SIZE); @@ -606,15 +595,10 @@ grub_net_tcp_open (char *server, nb = grub_netbuff_alloc (sizeof (*tcph) + 128); if (!nb) - { - grub_free (socket); - return NULL; - } - + return NULL; err = grub_netbuff_reserve (nb, 128); if (err) { - grub_free (socket); grub_netbuff_free (nb); return NULL; } @@ -622,14 +606,12 @@ grub_net_tcp_open (char *server, err = grub_netbuff_put (nb, sizeof (*tcph)); if (err) { - grub_free (socket); grub_netbuff_free (nb); return NULL; } socket->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp); if (!socket->pq) { - grub_free (socket); grub_netbuff_free (nb); return NULL; } @@ -900,10 +882,7 @@ grub_net_recv_tcp_packet (struct grub_net_buff *nb, grub_priority_queue_pop (sock->pq); } if (grub_be_to_cpu32 (tcph->seqnr) != sock->their_cur_seq) - { - ack (sock); - return GRUB_ERR_NONE; - } + return GRUB_ERR_NONE; while (1) { nb_top_p = grub_priority_queue_top (sock->pq); @@ -985,7 +964,6 @@ grub_net_recv_tcp_packet (struct grub_net_buff *nb, cmp); if (!sock->pq) { - grub_free (sock); grub_netbuff_free (nb); return grub_errno; } diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 7e659a78b..1319671ff 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -25,6 +25,7 @@ #include #include #include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -105,8 +106,31 @@ typedef struct tftp_data int have_oack; struct grub_error_saved save_err; grub_net_udp_socket_t sock; + grub_priority_queue_t pq; } *tftp_data_t; +static int +cmp_block (grub_uint16_t a, grub_uint16_t b) +{ + grub_int16_t i = (grub_int16_t) (a - b); + if (i > 0) + return +1; + if (i < 0) + return -1; + return 0; +} + +static int +cmp (const void *a__, const void *b__) +{ + struct grub_net_buff *a_ = *(struct grub_net_buff **) a__; + struct grub_net_buff *b_ = *(struct grub_net_buff **) b__; + struct tftphdr *a = (struct tftphdr *) a_->data; + struct tftphdr *b = (struct tftphdr *) b_->data; + /* We want the first elements to be on top. */ + return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block)); +} + static grub_err_t ack (tftp_data_t data, grub_uint64_t block) { @@ -183,71 +207,73 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), return GRUB_ERR_NONE; } - /* - * Ack old/retransmitted block. - * - * The block number is a 16-bit counter, thus the maximum file size that - * could be transfered is 65535 * block size. Most TFTP hosts support to - * roll-over the block counter to allow unlimited transfer file size. - * - * This behavior is not defined in the RFC 1350 [0] but is implemented by - * most TFTP clients and hosts. - * - * [0]: https://tools.ietf.org/html/rfc1350 - */ - if (grub_be_to_cpu16 (tftph->u.data.block) < ((grub_uint16_t) (data->block + 1))) - ack (data, grub_be_to_cpu16 (tftph->u.data.block)); - /* Ignore unexpected block. */ - else if (grub_be_to_cpu16 (tftph->u.data.block) > ((grub_uint16_t) (data->block + 1))) - grub_dprintf ("tftp", "TFTP unexpected block # %d\n", tftph->u.data.block); - else - { - unsigned size; + err = grub_priority_queue_push (data->pq, &nb); + if (err) + return err; - if (file->device->net->packs.count < 50) - { - err = ack (data, data->block + 1); - if (err) - return err; - } - else - file->device->net->stall = 1; - - err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + - sizeof (tftph->u.data.block)); - if (err) - return err; - size = nb->tail - nb->data; - - data->block++; - if (size < data->block_size) - { - if (data->ack_sent < data->block) - ack (data, data->block); - file->device->net->eof = 1; - file->device->net->stall = 1; - grub_net_udp_close (data->sock); - data->sock = NULL; - } - /* - * Prevent garbage in broken cards. Is it still necessary - * given that IP implementation has been fixed? - */ - if (size > data->block_size) - { - err = grub_netbuff_unput (nb, size - data->block_size); - if (err) - return err; - } - /* If there is data, puts packet in socket list. */ - if ((nb->tail - nb->data) > 0) - { - grub_net_put_packet (&file->device->net->packs, nb); - /* Do not free nb. */ + { + struct grub_net_buff **nb_top_p, *nb_top; + while (1) + { + nb_top_p = grub_priority_queue_top (data->pq); + if (!nb_top_p) return GRUB_ERR_NONE; - } - } - grub_netbuff_free (nb); + nb_top = *nb_top_p; + tftph = (struct tftphdr *) nb_top->data; + if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0) + break; + ack (data, grub_be_to_cpu16 (tftph->u.data.block)); + grub_netbuff_free (nb_top); + grub_priority_queue_pop (data->pq); + } + while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) + { + unsigned size; + + grub_priority_queue_pop (data->pq); + + if (file->device->net->packs.count < 50) + err = ack (data, data->block + 1); + else + { + file->device->net->stall = 1; + err = 0; + } + if (err) + return err; + + err = grub_netbuff_pull (nb_top, sizeof (tftph->opcode) + + sizeof (tftph->u.data.block)); + if (err) + return err; + size = nb_top->tail - nb_top->data; + + data->block++; + if (size < data->block_size) + { + if (data->ack_sent < data->block) + ack (data, data->block); + file->device->net->eof = 1; + file->device->net->stall = 1; + grub_net_udp_close (data->sock); + data->sock = NULL; + } + /* Prevent garbage in broken cards. Is it still necessary + given that IP implementation has been fixed? + */ + if (size > data->block_size) + { + err = grub_netbuff_unput (nb_top, size - data->block_size); + if (err) + return err; + } + /* If there is data, puts packet in socket list. */ + if ((nb_top->tail - nb_top->data) > 0) + grub_net_put_packet (&file->device->net->packs, nb_top); + else + grub_netbuff_free (nb_top); + } + } return GRUB_ERR_NONE; case TFTP_ERROR: data->have_oack = 1; @@ -261,24 +287,17 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), } } -/* - * Create a normalized copy of the filename. Compress any string of consecutive - * forward slashes to a single forward slash. - */ static void -grub_normalize_filename (char *normalized, const char *filename) +destroy_pq (tftp_data_t data) { - char *dest = normalized; - const char *src = filename; - - while (*src != '\0') + struct grub_net_buff **nb_p; + while ((nb_p = grub_priority_queue_top (data->pq))) { - if (src[0] == '/' && src[1] == '/') - src++; - else - *dest++ = *src++; + grub_netbuff_free (*nb_p); + grub_priority_queue_pop (data->pq); } - *dest = '\0'; + + grub_priority_queue_destroy (data->pq); } static grub_err_t @@ -307,10 +326,7 @@ tftp_open (struct grub_file *file, const char *filename) grub_netbuff_reserve (&nb, 1500); err = grub_netbuff_push (&nb, sizeof (*tftph)); if (err) - { - grub_free (data); - return err; - } + return err; tftph = (struct tftphdr *) nb.data; @@ -318,14 +334,9 @@ tftp_open (struct grub_file *file, const char *filename) rrqlen = 0; tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ); - - /* - * Copy and normalize the filename to work-around issues on some TFTP - * servers when file names are being matched for remapping. - */ - grub_normalize_filename (rrq, filename); - rrqlen += grub_strlen (rrq) + 1; - rrq += grub_strlen (rrq) + 1; + grub_strcpy (rrq, filename); + rrqlen += grub_strlen (filename) + 1; + rrq += grub_strlen (filename) + 1; grub_strcpy (rrq, "octet"); rrqlen += grub_strlen ("octet") + 1; @@ -350,18 +361,19 @@ tftp_open (struct grub_file *file, const char *filename) err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen)); if (err) - { - grub_free (data); - return err; - } + return err; file->not_easily_seekable = 1; file->data = data; + data->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp); + if (!data->pq) + return grub_errno; + err = grub_net_resolve_address (file->device->net->server, &addr); if (err) { - grub_free (data); + destroy_pq (data); return err; } @@ -370,7 +382,7 @@ tftp_open (struct grub_file *file, const char *filename) file); if (!data->sock) { - grub_free (data); + destroy_pq (data); return grub_errno; } @@ -383,7 +395,7 @@ tftp_open (struct grub_file *file, const char *filename) if (err) { grub_net_udp_close (data->sock); - grub_free (data); + destroy_pq (data); return err; } grub_net_poll_cards (GRUB_NET_INTERVAL + (i * GRUB_NET_INTERVAL_ADDITION), @@ -399,7 +411,7 @@ tftp_open (struct grub_file *file, const char *filename) if (grub_errno) { grub_net_udp_close (data->sock); - grub_free (data); + destroy_pq (data); return grub_errno; } @@ -441,6 +453,7 @@ tftp_close (struct grub_file *file) grub_print_error (); grub_net_udp_close (data->sock); } + destroy_pq (data); grub_free (data); return GRUB_ERR_NONE; } diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c index 6be678c0d..c6bd96e28 100644 --- a/grub-core/normal/auth.c +++ b/grub-core/normal/auth.c @@ -166,19 +166,16 @@ grub_username_get (char buf[], unsigned buf_size) if (key == '\n' || key == '\r') break; - if (key == GRUB_TERM_ESC) + if (key == '\e') { cur_len = 0; break; } - if (key == GRUB_TERM_BACKSPACE) + if (key == '\b') { - if (cur_len) - { - cur_len--; - grub_printf ("\b \b"); - } + cur_len--; + grub_printf ("\b"); continue; } @@ -197,7 +194,7 @@ grub_username_get (char buf[], unsigned buf_size) grub_xputs ("\n"); grub_refresh (); - return (key != GRUB_TERM_ESC); + return (key != '\e'); } grub_err_t diff --git a/grub-core/normal/autofs.c b/grub-core/normal/autofs.c index 7a7cf2b0f..721b9c325 100644 --- a/grub-core/normal/autofs.c +++ b/grub-core/normal/autofs.c @@ -33,6 +33,12 @@ autoload_fs_module (void) { grub_named_list_t p; int ret = 0; + grub_file_filter_t grub_file_filters_was[GRUB_FILE_FILTER_MAX]; + + grub_memcpy (grub_file_filters_was, grub_file_filters_enabled, + sizeof (grub_file_filters_enabled)); + grub_memcpy (grub_file_filters_enabled, grub_file_filters_all, + sizeof (grub_file_filters_enabled)); while ((p = fs_module_list) != NULL) { @@ -50,6 +56,9 @@ autoload_fs_module (void) grub_free (p); } + grub_memcpy (grub_file_filters_enabled, grub_file_filters_was, + sizeof (grub_file_filters_enabled)); + return ret; } @@ -73,7 +82,7 @@ read_fs_list (const char *prefix) tmp_autoload_hook = grub_fs_autoload_hook; grub_fs_autoload_hook = NULL; - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST); + file = grub_file_open (filename); if (file) { /* Override previous fs.lst. */ diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c index 4dfcc3107..3e4c337da 100644 --- a/grub-core/normal/charset.c +++ b/grub-core/normal/charset.c @@ -48,7 +48,6 @@ #include #include #include -#include #if HAVE_FONT_SOURCE #include "widthspec.h" @@ -204,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, { grub_size_t msg_len = grub_strlen (msg); - *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); if (!*unicode_msg) return -1; @@ -465,7 +464,6 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, { struct grub_unicode_combining *n; unsigned j; - grub_size_t sz; if (!haveout) continue; @@ -479,14 +477,10 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, n = out->combining_inline; else if (out->ncomb > (int) ARRAY_SIZE (out->combining_inline)) { - if (grub_add (out->ncomb, 1, &sz) || - grub_mul (sz, sizeof (n[0]), &sz)) - goto fail; - - n = grub_realloc (out->combining_ptr, sz); + n = grub_realloc (out->combining_ptr, + sizeof (n[0]) * (out->ncomb + 1)); if (!n) { - fail: grub_errno = GRUB_ERR_NONE; continue; } @@ -494,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, } else { - n = grub_calloc (out->ncomb + 1, sizeof (n[0])); + n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); if (!n) { grub_errno = GRUB_ERR_NONE; @@ -848,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, } \ } - visual = grub_calloc (logical_len, sizeof (visual[0])); + visual = grub_malloc (sizeof (visual[0]) * logical_len); if (!visual) return -1; @@ -935,7 +929,6 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, case GRUB_BIDI_TYPE_R: case GRUB_BIDI_TYPE_AL: bidi_needed = 1; - /* Fallthrough. */ default: { if (join_state == JOIN_FORCE) @@ -1150,16 +1143,6 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, } } -static int -is_visible (const struct grub_unicode_glyph *gl) -{ - if (gl->ncomb) - return 1; - if (gl->base == GRUB_UNICODE_LRM || gl->base == GRUB_UNICODE_RLM) - return 0; - return 1; -} - grub_ssize_t grub_bidi_logical_to_visual (const grub_uint32_t *logical, grub_size_t logical_len, @@ -1171,8 +1154,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, { const grub_uint32_t *line_start = logical, *ptr; struct grub_unicode_glyph *visual_ptr; - *visual_out = visual_ptr = grub_calloc (logical_len + 2, - 3 * sizeof (visual_ptr[0])); + *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) + * (logical_len + 2)); if (!visual_ptr) return -1; for (ptr = logical; ptr <= logical + logical_len; ptr++) @@ -1180,7 +1163,6 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, if (ptr == logical + logical_len || *ptr == '\n') { grub_ssize_t ret; - grub_ssize_t i, j; ret = grub_bidi_line_logical_to_visual (line_start, ptr - line_start, visual_ptr, @@ -1199,10 +1181,7 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, grub_free (*visual_out); return ret; } - for (i = 0, j = 0; i < ret; i++) - if (is_visible(&visual_ptr[i])) - visual_ptr[j++] = visual_ptr[i]; - visual_ptr += j; + visual_ptr += ret; line_start = ptr; if (ptr != logical + logical_len) { diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index de03fe63b..204d15a4b 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -28,7 +28,6 @@ #include #include #include -#include static grub_uint32_t *kill_buf; @@ -42,7 +41,7 @@ grub_err_t grub_set_history (int newsize) { grub_uint32_t **old_hist_lines = hist_lines; - hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); + hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); /* Copy the old lines into the new buffer. */ if (old_hist_lines) @@ -115,7 +114,7 @@ static void grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) { grub_free (hist_lines[pos]); - hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); + hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); if (!hist_lines[pos]) { grub_print_error (); @@ -308,21 +307,12 @@ cl_insert (struct cmdline_term *cl_terms, unsigned nterms, if (len + (*llen) >= (*max_len)) { grub_uint32_t *nbuf; - grub_size_t sz; - - if (grub_mul (*max_len, 2, max_len) || - grub_mul (*max_len, sizeof (grub_uint32_t), &sz)) - { - grub_errno = GRUB_ERR_OUT_OF_RANGE; - goto fail; - } - - nbuf = grub_realloc ((*buf), sz); + (*max_len) *= 2; + nbuf = grub_realloc ((*buf), sizeof (grub_uint32_t) * (*max_len)); if (nbuf) (*buf) = nbuf; else { - fail: grub_print_error (); grub_errno = GRUB_ERR_NONE; (*max_len) /= 2; @@ -359,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) char *ret; unsigned nterms; - buf = grub_calloc (max_len, sizeof (grub_uint32_t)); + buf = grub_malloc (max_len * sizeof (grub_uint32_t)); if (!buf) return 0; @@ -387,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) FOR_ACTIVE_TERM_OUTPUTS(cur) nterms++; - cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); + cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); if (!cl_terms) { grub_free (buf); @@ -395,11 +385,10 @@ grub_cmdline_get (const char *prompt_translated) } cl_term_cur = cl_terms; - unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); if (!unicode_msg) { grub_free (buf); - grub_free (cl_terms); return 0; } msg_len = grub_utf8_to_ucs4 (unicode_msg, msg_len - 1, @@ -505,7 +494,7 @@ grub_cmdline_get (const char *prompt_translated) grub_uint32_t *insert; insertlen = grub_strlen (insertu8); - insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); + insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); if (!insert) { grub_free (insertu8); @@ -612,7 +601,7 @@ grub_cmdline_get (const char *prompt_translated) grub_free (kill_buf); - kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); + kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); if (grub_errno) { grub_print_error (); @@ -636,12 +625,12 @@ grub_cmdline_get (const char *prompt_translated) cl_insert (cl_terms, nterms, &lpos, &llen, &max_len, &buf, kill_buf); break; - case GRUB_TERM_ESC: + case '\e': grub_free (cl_terms); grub_free (buf); return 0; - case GRUB_TERM_BACKSPACE: + case '\b': if (lpos > 0) { lpos--; diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c index c07100a8d..2c9b9e931 100644 --- a/grub-core/normal/completion.c +++ b/grub-core/normal/completion.c @@ -284,11 +284,10 @@ complete_file (void) /* Cut away the filename part. */ dirfile = grub_strrchr (dir, '/'); - if (dirfile) - dirfile[1] = '\0'; + dirfile[1] = '\0'; /* Iterate the directory. */ - (fs->fs_dir) (dev, dir, iterate_dir, NULL); + (fs->dir) (dev, dir, iterate_dir, NULL); grub_free (dir); diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c index ee53d4a68..7e0a696f3 100644 --- a/grub-core/normal/context.c +++ b/grub-core/normal/context.c @@ -64,10 +64,7 @@ grub_env_new_context (int export_all) return grub_errno; menu = grub_zalloc (sizeof (*menu)); if (! menu) - { - grub_free (context); - return grub_errno; - } + return grub_errno; context->prev = grub_current_context; grub_current_context = context; diff --git a/grub-core/normal/crypto.c b/grub-core/normal/crypto.c index d01e6f271..2bfd67c8e 100644 --- a/grub-core/normal/crypto.c +++ b/grub-core/normal/crypto.c @@ -94,7 +94,7 @@ read_crypto_list (const char *prefix) return; } - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST); + file = grub_file_open (filename); grub_free (filename); if (!file) { @@ -147,8 +147,8 @@ read_crypto_list (const char *prefix) if (! cur->modname) { grub_errno = GRUB_ERR_NONE; - grub_free (cur->name); grub_free (cur); + grub_free (cur->name); continue; } cur->next = crypto_specs; diff --git a/grub-core/lib/datetime.c b/grub-core/normal/datetime.c similarity index 100% rename from grub-core/lib/datetime.c rename to grub-core/normal/datetime.c diff --git a/grub-core/normal/dyncmd.c b/grub-core/normal/dyncmd.c index 719ebf477..169c126f5 100644 --- a/grub-core/normal/dyncmd.c +++ b/grub-core/normal/dyncmd.c @@ -106,7 +106,7 @@ read_command_list (const char *prefix) { grub_file_t file; - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST); + file = grub_file_open (filename); if (file) { char *buf = NULL; diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index c4ebe9e22..c41f175bd 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -124,14 +123,14 @@ read_config_file (const char *config) } /* Try to open the config file. */ - rawfile = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); + rawfile = grub_file_open (config); if (! rawfile) return 0; file = grub_bufio_open (rawfile, 0); if (! file) { - grub_file_close (rawfile); + grub_file_close (file); return 0; } @@ -324,27 +323,10 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), prefix = grub_env_get ("prefix"); if (prefix) - { - grub_size_t config_len; - int disable_net_search = 0; - const char *net_search_cfg; - - config_len = grub_strlen (prefix) + - sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); - config = grub_malloc (config_len); - - if (!config) - goto quit; - - grub_snprintf (config, config_len, "%s/grub.cfg", prefix); - - net_search_cfg = grub_env_get ("feature_net_search_cfg"); - if (net_search_cfg && net_search_cfg[0] == 'n') - disable_net_search = 1; - - if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && - !disable_net_search) - grub_net_search_config_file (config); + { + config = grub_xasprintf ("%s/grub.cfg", prefix); + if (! config) + goto quit; grub_enter_normal_mode (config); grub_free (config); @@ -463,7 +445,7 @@ grub_cmdline_run (int nested, int force_auth) while (1) { - char *line = NULL; + char *line; if (grub_normal_exit_level) break; diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 8397886fa..719e2fb1c 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -170,7 +170,8 @@ grub_menu_set_timeout (int timeout) static int get_and_remove_first_entry_number (const char *name) { - const char *val, *tail; + const char *val; + char *tail; int entry; val = grub_env_get (name); @@ -623,7 +624,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) if (entry >= 0) break; } - if (grub_key_is_interrupt (key)) + if (key == GRUB_TERM_ESC) { timeout = -1; break; @@ -697,8 +698,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) c = grub_getkey_noblock (); - /* Negative values are returned on error. */ - if ((c != GRUB_TERM_NO_KEY) && (c > 0)) + if (c != GRUB_TERM_NO_KEY) { if (timeout >= 0) { @@ -763,7 +763,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) *auto_boot = 0; return current_entry; - case GRUB_TERM_ESC: + case '\e': if (nested) { menu_fini (); diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c index 50eef918c..62c7e1627 100644 --- a/grub-core/normal/menu_entry.c +++ b/grub-core/normal/menu_entry.c @@ -27,7 +27,6 @@ #include #include #include -#include enum update_mode { @@ -96,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) { linep->len = 0; linep->max_len = 80; - linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); - linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); + linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); + linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); if (! linep->buf || !linep->pos) { grub_free (linep->buf); @@ -114,18 +113,10 @@ ensure_space (struct line *linep, int extra) { if (linep->max_len < linep->len + extra) { - grub_size_t sz0, sz1; - - if (grub_add (linep->len, extra, &sz0) || - grub_mul (sz0, 2, &sz0) || - grub_add (sz0, 1, &sz1) || - grub_mul (sz1, sizeof (linep->buf[0]), &sz1)) - return 0; - - linep->buf = grub_realloc (linep->buf, sz1); + linep->max_len = 2 * (linep->len + extra); + linep->buf = grub_realloc (linep->buf, (linep->max_len + 1) * sizeof (linep->buf[0])); if (! linep->buf) return 0; - linep->max_len = sz0; } return 1; @@ -135,13 +126,9 @@ ensure_space (struct line *linep, int extra) static int get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen) { - grub_size_t width = grub_getstringwidth (linep->buf, linep->buf + linep->len, - term_screen->term); - - /* Empty line still consumes space on screen */ - return width ? (width + (unsigned) term_screen->geo.entry_width - 1) / - (unsigned) term_screen->geo.entry_width - : 1; + return (grub_getstringwidth (linep->buf, linep->buf + linep->len, + term_screen->term) + / (unsigned) term_screen->geo.entry_width) + 1; } static void @@ -263,8 +250,6 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, mode = ALL_LINES; } - grub_term_setcursor (term_screen->term, 0); - if (mode != NO_LINE) { /* Draw lines. This code is tricky, because this must calculate logical @@ -296,7 +281,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, pos = linep->pos + (term_screen - screen->terms); if (!*pos) - *pos = grub_calloc (linep->len + 1, sizeof (**pos)); + *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); if (i == region_start || linep == screen->lines + screen->line || (i > region_start && mode == ALL_LINES)) @@ -372,8 +357,6 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, } - grub_term_setcursor (term_screen->term, 1); - grub_term_refresh (term_screen->term); } @@ -480,7 +463,7 @@ insert_string (struct screen *screen, const char *s, int update) /* Insert the string. */ current_linep = screen->lines + screen->line; - unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); + unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); if (!unicode_msg) return 0; @@ -489,10 +472,7 @@ insert_string (struct screen *screen, const char *s, int update) (grub_uint8_t *) s, (p - s), 0); if (! ensure_space (current_linep, size)) - { - grub_free (unicode_msg); - return 0; - } + return 0; grub_memmove (current_linep->buf + screen->column + size, current_linep->buf + screen->column, @@ -1032,7 +1012,7 @@ complete (struct screen *screen, int continuous, int update) if (completion_buffer.buf) { buflen = grub_strlen (completion_buffer.buf); - ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); + ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); if (!ucs4) { @@ -1277,21 +1257,19 @@ grub_menu_entry_run (grub_menu_entry_t entry) for (i = 0; i < (unsigned) screen->num_lines; i++) { grub_free (screen->lines[i].pos); - screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); + screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); if (! screen->lines[i].pos) { grub_print_error (); - destroy_screen (screen); grub_errno = GRUB_ERR_NONE; return; } } - screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); + screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); if (!screen->terms) { grub_print_error (); - destroy_screen (screen); grub_errno = GRUB_ERR_NONE; return; } @@ -1412,7 +1390,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) goto fail; break; - case GRUB_TERM_ESC: + case '\e': destroy_screen (screen); return; diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c index 18240e76c..e22bb91f6 100644 --- a/grub-core/normal/menu_text.c +++ b/grub-core/normal/menu_text.c @@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, grub_size_t msg_len = grub_strlen (msg) + 2; int ret = 0; - unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); if (!unicode_msg) return 0; @@ -211,7 +211,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, title = entry ? entry->title : ""; title_len = grub_strlen (title); - unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); + unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); if (! unicode_title) /* XXX How to show this error? */ return; diff --git a/grub-core/normal/misc.c b/grub-core/normal/misc.c index 435cd9234..34d505eda 100644 --- a/grub-core/normal/misc.c +++ b/grub-core/normal/misc.c @@ -119,10 +119,10 @@ grub_normal_print_device_info (const char *name) if (grub_strcmp (fsname, "ext2") == 0) fsname = "ext*"; grub_printf_ (N_("Filesystem type %s"), fsname); - if (fs->fs_label) + if (fs->label) { char *label; - (fs->fs_label) (dev, &label); + (fs->label) (dev, &label); if (grub_errno == GRUB_ERR_NONE) { if (label && grub_strlen (label)) @@ -134,11 +134,11 @@ grub_normal_print_device_info (const char *name) } grub_errno = GRUB_ERR_NONE; } - if (fs->fs_mtime) + if (fs->mtime) { grub_int32_t tm; struct grub_datetime datetime; - (fs->fs_mtime) (dev, &tm); + (fs->mtime) (dev, &tm); if (grub_errno == GRUB_ERR_NONE) { grub_unixtime2datetime (tm, &datetime); @@ -154,10 +154,10 @@ grub_normal_print_device_info (const char *name) } grub_errno = GRUB_ERR_NONE; } - if (fs->fs_uuid) + if (fs->uuid) { char *uuid; - (fs->fs_uuid) (dev, &uuid); + (fs->uuid) (dev, &uuid); if (grub_errno == GRUB_ERR_NONE) { if (uuid && grub_strlen (uuid)) @@ -184,10 +184,9 @@ grub_normal_print_device_info (const char *name) /* TRANSLATORS: Replace dot with appropriate decimal separator for your language. */ (grub_disk_get_size (dev->disk) & 1) ? _(".5") : ""); - } - if (dev) - grub_device_close (dev); + grub_device_close (dev); + } grub_xputs ("\n"); return grub_errno; diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index cc8c173b6..4c2238b25 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -77,6 +77,8 @@ print_more (void) grub_term_output_t term; grub_uint32_t *unicode_str, *unicode_last_position; + pos = grub_term_save_pos (); + /* TRANSLATORS: This has to fit on one line. It's ok to include few words but don't write poems. */ grub_utf8_to_ucs4_alloc (_("--MORE--"), &unicode_str, @@ -88,8 +90,6 @@ print_more (void) return; } - pos = grub_term_save_pos (); - grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); FOR_ACTIVE_TERM_OUTPUTS(term) @@ -264,7 +264,7 @@ grub_term_save_pos (void) FOR_ACTIVE_TERM_OUTPUTS(cur) cnt++; - ret = grub_calloc (cnt, sizeof (ret[0])); + ret = grub_malloc (cnt * sizeof (ret[0])); if (!ret) return NULL; @@ -331,7 +331,7 @@ read_terminal_list (const char *prefix) return; } - file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST); + file = grub_file_open (filename); grub_free (filename); if (!file) { @@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) grub_error_push (); - unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); + unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); grub_error_pop (); diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c index 3b2c9de24..e1eeea7d0 100644 --- a/grub-core/osdep/aros/hostdisk.c +++ b/grub-core/osdep/aros/hostdisk.c @@ -61,7 +61,7 @@ static ULONG *bounce; char * -grub_canonicalize_file_name (const char *path) +canonicalize_file_name (const char *path) { char *ret; BPTR lck; @@ -194,7 +194,7 @@ grub_util_fd_open (const char *dev, int flg) p1 = dev + strlen (dev); else { - unit = grub_strtoul (p1 + 1, &p2, 16); + unit = grub_strtoul (p1 + 1, (char **) &p2, 16); if (p2 && *p2 == '/') flags = grub_strtoul (p2 + 1, 0, 16); } @@ -439,44 +439,36 @@ grub_util_get_fd_size (grub_util_fd_t fd, return -1; } -int +void grub_util_fd_close (grub_util_fd_t fd) { switch (fd->type) { case GRUB_UTIL_FD_FILE: - return close (fd->fd); + close (fd->fd); + return; case GRUB_UTIL_FD_DISK: CloseDevice ((struct IORequest *) fd->ioreq); DeleteIORequest((struct IORequest *) fd->ioreq); DeleteMsgPort (fd->mp); - return 0; + return; } - return 0; } static int allow_fd_syncs = 1; -static int +static void grub_util_fd_sync_volume (grub_util_fd_t fd) { - LONG err; - fd->ioreq->iotd_Req.io_Command = CMD_UPDATE; fd->ioreq->iotd_Req.io_Length = 0; fd->ioreq->iotd_Req.io_Data = 0; fd->ioreq->iotd_Req.io_Offset = 0; fd->ioreq->iotd_Req.io_Actual = 0; - err = DoIO ((struct IORequest *) fd->ioreq); - if (err) - { - grub_util_info ("I/O failed with error %d, IoErr=%d", (int)err, (int) IoErr ()); - return -1; - } - return 0; + DoIO ((struct IORequest *) fd->ioreq); } -int +void grub_util_fd_sync (grub_util_fd_t fd) { if (allow_fd_syncs) @@ -484,22 +476,22 @@ grub_util_fd_sync (grub_util_fd_t fd) switch (fd->type) { case GRUB_UTIL_FD_FILE: - return fsync (fd->fd); + fsync (fd->fd); + return; case GRUB_UTIL_FD_DISK: - return grub_util_fd_sync_volume (fd); + grub_util_fd_sync_volume (fd); + return; } } - return 0; } -int +void grub_util_file_sync (FILE *f) { - if (fflush (f) != 0) - return -1; + fflush (f); if (!allow_fd_syncs) - return 0; - return fsync (fileno (f)); + return; + fsync (fileno (f)); } void diff --git a/grub-core/osdep/basic/platform.c b/grub-core/osdep/basic/platform.c index a7dafd85a..4b5502aeb 100644 --- a/grub-core/osdep/basic/platform.c +++ b/grub-core/osdep/basic/platform.c @@ -18,12 +18,6 @@ #include -const char * -grub_install_get_default_arm_platform (void) -{ - return "arm-uboot"; -} - const char * grub_install_get_default_x86_platform (void) { diff --git a/grub-core/osdep/devmapper/getroot.c b/grub-core/osdep/devmapper/getroot.c index a13a39c96..d02386b34 100644 --- a/grub-core/osdep/devmapper/getroot.c +++ b/grub-core/osdep/devmapper/getroot.c @@ -40,12 +40,6 @@ #include #endif -#if defined(MAJOR_IN_MKDEV) -#include -#elif defined(MAJOR_IN_SYSMACROS) -#include -#endif - #include #include @@ -143,7 +137,7 @@ grub_util_get_dm_abstraction (const char *os_dev) grub_free (uuid); return GRUB_DEV_ABSTRACTION_LVM; } - if (strncmp (uuid, "CRYPT-LUKS1-", 12) == 0) + if (strncmp (uuid, "CRYPT-LUKS1-", 4) == 0) { grub_free (uuid); return GRUB_DEV_ABSTRACTION_LUKS; @@ -166,10 +160,7 @@ grub_util_pull_devmapper (const char *os_dev) uuid = get_dm_uuid (os_dev); if (!grub_util_open_dm (os_dev, &tree, &node)) - { - grub_free (uuid); - return; - } + return; while ((child = dm_tree_next_child (&handle, node, 0))) { @@ -201,7 +192,6 @@ grub_util_pull_devmapper (const char *os_dev) } else dm_tree_free (tree); - grub_free (uuid); } char * @@ -214,7 +204,8 @@ grub_util_devmapper_part_to_disk (struct stat *st, &major, &minor, 0)) { *is_part = 1; - return grub_find_device ("/dev", makedev (major, minor)); + return grub_find_device ("/dev", + (major << 8) | minor); } *is_part = 0; return xstrdup (path); @@ -229,14 +220,11 @@ grub_util_get_devmapper_grub_dev (const char *os_dev) uuid = get_dm_uuid (os_dev); if (!uuid) return NULL; - - switch (grub_util_get_dev_abstraction (os_dev)) + + if (strncmp (uuid, "LVM-", sizeof ("LVM-") - 1) == 0) { - case GRUB_DEV_ABSTRACTION_LVM: - { unsigned i; int dashes[] = { 0, 6, 10, 14, 18, 22, 26, 32, 38, 42, 46, 50, 54, 58}; - grub_dev = xmalloc (grub_strlen (uuid) + 40); optr = grub_stpcpy (grub_dev, "lvmid/"); for (i = 0; i < ARRAY_SIZE (dashes) - 1; i++) @@ -254,23 +242,18 @@ grub_util_get_devmapper_grub_dev (const char *os_dev) return grub_dev; } - case GRUB_DEV_ABSTRACTION_LUKS: - { - char *dash; - - dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); - if (dash) - *dash = 0; - grub_dev = grub_xasprintf ("cryptouuid/%s", - uuid + sizeof ("CRYPT-LUKS1-") - 1); - grub_free (uuid); - return grub_dev; - } - - default: + if (strncmp (uuid, "CRYPT-LUKS1-", sizeof ("CRYPT-LUKS1-") - 1) == 0) + { + char *dash; + dash = grub_strchr (uuid + sizeof ("CRYPT-LUKS1-") - 1, '-'); + if (dash) + *dash = 0; + grub_dev = grub_xasprintf ("cryptouuid/%s", + uuid + sizeof ("CRYPT-LUKS1-") - 1); grub_free (uuid); - return NULL; + return grub_dev; } + return NULL; } char * @@ -296,7 +279,6 @@ grub_util_get_vg_uuid (const char *os_dev) } optr--; *optr = '\0'; - grub_free (uuid); return vgid; } diff --git a/grub-core/osdep/devmapper/hostdisk.c b/grub-core/osdep/devmapper/hostdisk.c index a8afc0c94..19c1101fd 100644 --- a/grub-core/osdep/devmapper/hostdisk.c +++ b/grub-core/osdep/devmapper/hostdisk.c @@ -24,11 +24,6 @@ #include #include -#if defined(MAJOR_IN_MKDEV) -#include -#elif defined(MAJOR_IN_SYSMACROS) -#include -#endif #ifdef HAVE_DEVICE_MAPPER # include @@ -113,7 +108,7 @@ grub_util_get_dm_node_linear_info (dev_t dev, void *next = NULL; uint64_t length, start; char *target, *params; - const char *ptr; + char *ptr; int major = 0, minor = 0; int first = 1; grub_disk_addr_t partstart = 0; diff --git a/grub-core/osdep/freebsd/getroot.c b/grub-core/osdep/freebsd/getroot.c index b1e824495..ccc1d7028 100644 --- a/grub-core/osdep/freebsd/getroot.c +++ b/grub-core/osdep/freebsd/getroot.c @@ -338,8 +338,8 @@ grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **n grub_util_follow_gpart_up (name_tmp, &off, name_out); free (name_tmp); LIST_FOREACH (config, &provider->lg_config, lg_config) - if (strcasecmp (config->lg_name, "offset") == 0) - off += strtoull (config->lg_val, 0, 10) / provider->lg_sectorsize; + if (strcasecmp (config->lg_name, "start") == 0) + off += strtoull (config->lg_val, 0, 10); if (off_out) *off_out = off; return; diff --git a/grub-core/osdep/generic/blocklist.c b/grub-core/osdep/generic/blocklist.c index 2d9040302..74024fd06 100644 --- a/grub-core/osdep/generic/blocklist.c +++ b/grub-core/osdep/generic/blocklist.c @@ -59,7 +59,8 @@ grub_install_get_blocklist (grub_device_t root_dev, grub_disk_cache_invalidate_all (); - file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (core_path_dev); if (file) { if (grub_file_size (file) != core_size) @@ -116,7 +117,8 @@ grub_install_get_blocklist (grub_device_t root_dev, grub_file_t file; /* Now read the core image to determine where the sectors are. */ - file = grub_file_open (core_path_dev, GRUB_FILE_TYPE_NONE | GRUB_FILE_TYPE_NO_DECOMPRESS); + grub_file_filter_disable_compression (); + file = grub_file_open (core_path_dev); if (! file) grub_util_error ("%s", grub_errmsg); diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c index c77d6085c..10ddd11c1 100644 --- a/grub-core/osdep/linux/blocklist.c +++ b/grub-core/osdep/linux/blocklist.c @@ -130,7 +130,6 @@ grub_install_get_blocklist (grub_device_t root_dev, & (GRUB_DISK_SECTOR_SIZE - 1), fie2->fm_extents[i].fe_length, hook_data); } - free (fie2); } close (fd); } diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 001b818fe..7007193d9 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -35,12 +35,6 @@ #include #endif -#if defined(MAJOR_IN_MKDEV) -#include -#elif defined(MAJOR_IN_SYSMACROS) -#include -#endif - #include #include /* ioctl */ #include @@ -168,7 +162,7 @@ grub_util_raid_getmembers (const char *name, int bootable) if (ret != 0) grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); - devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); + devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); for (i = 0, j = 0; j < info.nr_disks; i++) { @@ -232,7 +226,7 @@ grub_find_root_devices_from_btrfs (const char *dir) char **ret; fd = open (dir, 0); - if (fd < 0) + if (!fd) return NULL; if (ioctl (fd, BTRFS_IOC_FS_INFO, &fsi) < 0) @@ -241,7 +235,7 @@ grub_find_root_devices_from_btrfs (const char *dir) return NULL; } - ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); + ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) { @@ -280,11 +274,11 @@ get_btrfs_fs_prefix (const char *mount_path) args.objectid = GRUB_BTRFS_TREE_ROOT_OBJECTID; if (ioctl (fd, BTRFS_IOC_INO_LOOKUP, &args) < 0) - goto fail; + return NULL; tree_id = args.treeid; if (fstat (fd, &st) < 0) - goto fail; + return NULL; inode_id = st.st_ino; while (tree_id != GRUB_BTRFS_ROOT_VOL_OBJECTID @@ -315,16 +309,16 @@ get_btrfs_fs_prefix (const char *mount_path) sargs.key.nr_items = 1; if (ioctl (fd, BTRFS_IOC_TREE_SEARCH, &sargs) < 0) - goto fail; + return NULL; if (sargs.key.nr_items == 0) - goto fail; - + return NULL; + tree_id = sargs.buf[2]; br = (struct grub_btrfs_root_backref *) (sargs.buf + 4); - inode_id = grub_le_to_cpu64 (br->inode_id); + inode_id = br->inode_id; name = br->name; - namelen = grub_le_to_cpu16 (br->n); + namelen = br->n; } else { @@ -342,16 +336,16 @@ get_btrfs_fs_prefix (const char *mount_path) sargs.key.max_type = GRUB_BTRFS_ITEM_TYPE_INODE_REF; if (ioctl (fd, BTRFS_IOC_TREE_SEARCH, &sargs) < 0) - goto fail; + return NULL; if (sargs.key.nr_items == 0) - goto fail; + return NULL; inode_id = sargs.buf[2]; ir = (struct grub_btrfs_inode_ref *) (sargs.buf + 4); name = ir->name; - namelen = grub_le_to_cpu16 (ir->n); + namelen = ir->n; } old = ret; ret = xmalloc (namelen + (old ? strlen (old) : 0) + 2); @@ -366,44 +360,32 @@ get_btrfs_fs_prefix (const char *mount_path) ret[1+namelen] = '\0'; } if (!ret) - ret = xstrdup ("/"); - close (fd); + return xstrdup ("/"); return ret; - - fail: - free (ret); - close (fd); - return NULL; } char ** grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) { - FILE *fp = NULL; + FILE *fp; char *buf = NULL; size_t len = 0; - grub_size_t entry_len, entry_max = 4; + grub_size_t entry_len = 0, entry_max = 4; struct mountinfo_entry *entries; struct mountinfo_entry parent_entry = { 0, 0, 0, "", "", "", "" }; int i; - int retry = 0; - int dir_fd = -1; - char **ret = NULL; if (! *dir) dir = "/"; if (relroot) *relroot = NULL; - entries = xcalloc (entry_max, sizeof (*entries)); - -again: fp = grub_util_fopen ("/proc/self/mountinfo", "r"); if (! fp) - goto out; /* fall through to other methods */ + return NULL; /* fall through to other methods */ - entry_len = 0; + entries = xmalloc (entry_max * sizeof (*entries)); /* First, build a list of relevant visible mounts. */ while (getline (&buf, &len, fp) > 0) @@ -490,6 +472,7 @@ again: /* Now scan visible mounts for the ones we're interested in. */ for (i = entry_len - 1; i >= 0; i--) { + char **ret = NULL; char *fs_prefix = NULL; if (!*entries[i].device) continue; @@ -520,23 +503,6 @@ again: ret = grub_find_root_devices_from_btrfs (dir); fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); } - else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) - { - /* If the best match is automounted, try to trigger mount. We cannot - simply return here because stat() on automounted directory does not - trigger mount and returns bogus (pseudo)device number instead. - We keep mountpoint open until end of scan to prevent timeout. */ - - int flags = O_RDONLY|O_DIRECTORY; - - fclose (fp); -#ifdef O_LARGEFILE - flags |= O_LARGEFILE; -#endif - dir_fd = open (entries[i].enc_path, flags); - retry = 1; - goto again; - } if (!ret) { ret = xmalloc (2 * sizeof (ret[0])); @@ -566,17 +532,16 @@ again: } if (fs_prefix != entries[i].enc_root) free (fs_prefix); - break; + free (buf); + free (entries); + fclose (fp); + return ret; } -out: free (buf); free (entries); - if (fp) - fclose (fp); - if (dir_fd != -1) - close (dir_fd); - return ret; + fclose (fp); + return NULL; } static char * @@ -723,7 +688,7 @@ char * grub_util_part_to_disk (const char *os_dev, struct stat *st, int *is_part) { - char *path; + char *path = xmalloc (PATH_MAX); if (! S_ISBLK (st->st_mode)) { @@ -731,8 +696,6 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, return xstrdup (os_dev); } - path = xmalloc (PATH_MAX); - if (! realpath (os_dev, path)) return NULL; @@ -921,19 +884,6 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, return path; } - /* If this is an rssd device. */ - if ((strncmp ("rssd", p, 4) == 0) && p[4] >= 'a' && p[4] <= 'z') - { - char *pp = p + 4; - while (*pp >= 'a' && *pp <= 'z') - pp++; - if (*pp) - *is_part = 1; - /* /dev/rssd[a-z]+[0-9]* */ - *pp = '\0'; - return path; - } - /* If this is a loop device */ if ((strncmp ("loop", p, 4) == 0) && p[4] >= '0' && p[4] <= '9') { @@ -1117,7 +1067,7 @@ grub_util_get_grub_dev_os (const char *os_dev) switch (grub_util_get_dev_abstraction (os_dev)) { /* Fallback for non-devmapper build. In devmapper-builds LVM is handled - in grub_util_get_devmapper_grub_dev and this point isn't reached. + in rub_util_get_devmapper_grub_dev and this point isn't reached. */ case GRUB_DEV_ABSTRACTION_LVM: { diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c index da62f924e..c96427a56 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -366,9 +366,6 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f #ifdef O_BINARY flags |= O_BINARY; #endif -#ifdef O_CLOEXEC - flags |= O_CLOEXEC; -#endif /* Linux has a bug that the disk cache for a whole disk is not consistent with the one for a partition of the disk. */ @@ -377,11 +374,9 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f char dev[PATH_MAX]; grub_disk_addr_t part_start = 0; - part_start = grub_partition_get_start (disk->partition) - >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); + part_start = grub_partition_get_start (disk->partition); - strncpy (dev, grub_util_biosdisk_get_osdev (disk), sizeof (dev) - 1); - dev[sizeof(dev) - 1] = '\0'; + strcpy (dev, grub_util_biosdisk_get_osdev (disk)); if (disk->partition && strncmp (dev, "/dev/", 5) == 0) { @@ -444,8 +439,7 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f if (*max == 0) *max = ~0ULL; is_partition = 0; - strncpy (dev, grub_util_biosdisk_get_osdev (disk), sizeof (dev) - 1); - dev[sizeof(dev) - 1] = '\0'; + strcpy (dev, grub_util_biosdisk_get_osdev (disk)); goto reopen; } sector -= part_start; diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c index a6153d359..8f24bc9e8 100644 --- a/grub-core/osdep/linux/ofpath.c +++ b/grub-core/osdep/linux/ofpath.c @@ -38,46 +38,6 @@ #include #include -#ifdef __sparc__ -typedef enum - { - GRUB_OFPATH_SPARC_WWN_ADDR = 1, - GRUB_OFPATH_SPARC_TGT_LUN, - } ofpath_sparc_addressing; - -struct ofpath_sparc_hba -{ - grub_uint32_t device_id; - ofpath_sparc_addressing addressing; -}; - -static struct ofpath_sparc_hba sparc_lsi_hba[] = { - /* Rhea, Jasper 320, LSI53C1020/1030. */ - {0x30, GRUB_OFPATH_SPARC_TGT_LUN}, - /* SAS-1068E. */ - {0x50, GRUB_OFPATH_SPARC_TGT_LUN}, - /* SAS-1064E. */ - {0x56, GRUB_OFPATH_SPARC_TGT_LUN}, - /* Pandora SAS-1068E. */ - {0x58, GRUB_OFPATH_SPARC_TGT_LUN}, - /* Aspen, Invader, LSI SAS-3108. */ - {0x5d, GRUB_OFPATH_SPARC_TGT_LUN}, - /* Niwot, SAS 2108. */ - {0x79, GRUB_OFPATH_SPARC_TGT_LUN}, - /* Erie, Falcon, LSI SAS 2008. */ - {0x72, GRUB_OFPATH_SPARC_WWN_ADDR}, - /* LSI WarpDrive 6203. */ - {0x7e, GRUB_OFPATH_SPARC_WWN_ADDR}, - /* LSI SAS 2308. */ - {0x87, GRUB_OFPATH_SPARC_WWN_ADDR}, - /* LSI SAS 3008. */ - {0x97, GRUB_OFPATH_SPARC_WWN_ADDR}, - {0, 0} -}; - -static const int LSI_VENDOR_ID = 0x1000; -#endif - #ifdef OFPATH_STANDALONE #define xmalloc malloc void @@ -160,21 +120,14 @@ find_obppath (const char *sysfs_path_orig) #endif fd = open(path, O_RDONLY); - -#ifndef __sparc__ if (fd < 0 || fstat (fd, &st) < 0) { - if (fd >= 0) - close (fd); snprintf(path, path_size, "%s/devspec", sysfs_path); fd = open(path, O_RDONLY); } -#endif if (fd < 0 || fstat (fd, &st) < 0) { - if (fd >= 0) - close (fd); kill_trailing_dir(sysfs_path); if (!strcmp(sysfs_path, "/sys")) { @@ -194,9 +147,6 @@ find_obppath (const char *sysfs_path_orig) { grub_util_info (_("cannot read `%s': %s"), path, strerror (errno)); close(fd); - free (path); - free (of_path); - free (sysfs_path); return NULL; } close(fd); @@ -350,55 +300,6 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi return ret; } -#ifdef __sparc__ -static char * -of_path_of_nvme(const char *sys_devname __attribute__((unused)), - const char *device, - const char *devnode __attribute__((unused)), - const char *devicenode) -{ - char *sysfs_path, *of_path, disk[MAX_DISK_CAT]; - const char *digit_string, *part_end; - - digit_string = trailing_digits (device); - part_end = devicenode + strlen (devicenode) - 1; - - if ((*digit_string != '\0') && (*part_end == 'p')) - { - /* We have a partition number, strip it off. */ - int part; - char *nvmedev, *end; - - nvmedev = strdup (devicenode); - - if (!nvmedev) - return NULL; - - end = nvmedev + strlen (nvmedev) - 1; - /* Remove the p. */ - *end = '\0'; - sscanf (digit_string, "%d", &part); - snprintf (disk, sizeof (disk), "/disk@1:%c", 'a' + (part - 1)); - sysfs_path = block_device_get_sysfs_path_and_link (nvmedev); - free (nvmedev); - } - else - { - /* We do not have the parition. */ - snprintf (disk, sizeof (disk), "/disk@1"); - sysfs_path = block_device_get_sysfs_path_and_link (device); - } - - of_path = find_obppath (sysfs_path); - - if (of_path) - strcat (of_path, disk); - - free (sysfs_path); - return of_path; -} -#endif - static int vendor_is_ATA(const char *path) { @@ -427,66 +328,8 @@ vendor_is_ATA(const char *path) return (memcmp(bufcont, "ATA", 3) == 0); } -#ifdef __sparc__ static void -check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id) -{ - char *ed = strstr (sysfs_path, "host"); - size_t path_size; - char *p, *path; - char buf[8]; - int fd; - - if (!ed) - return; - - p = xstrdup (sysfs_path); - ed = strstr (p, "host"); - - *ed = '\0'; - - path_size = (strlen (p) + sizeof ("vendor")); - path = xmalloc (path_size); - - if (!path) - goto out; - - snprintf (path, path_size, "%svendor", p); - fd = open (path, O_RDONLY); - - if (fd < 0) - goto out; - - memset (buf, 0, sizeof (buf)); - - if (read (fd, buf, sizeof (buf) - 1) < 0) - goto out; - - close (fd); - sscanf (buf, "%x", vendor); - - snprintf (path, path_size, "%sdevice", p); - fd = open (path, O_RDONLY); - - if (fd < 0) - goto out; - - memset (buf, 0, sizeof (buf)); - - if (read (fd, buf, sizeof (buf) - 1) < 0) - goto out; - - close (fd); - sscanf (buf, "%x", device_id); - - out: - free (path); - free (p); -} -#endif - -static void -check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) +check_sas (char *sysfs_path, int *tgt, unsigned long int *sas_address) { char *ed = strstr (sysfs_path, "end_device"); char *p, *q, *path; @@ -498,10 +341,8 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) return; /* SAS devices are identified using disk@$PHY_ID */ - p = xstrdup (sysfs_path); + p = strdup (sysfs_path); ed = strstr(p, "end_device"); - if (!ed) - return; q = ed; while (*q && *q != '/') @@ -546,7 +387,7 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev { const char *p, *digit_string, *disk_name; int host, bus, tgt, lun; - unsigned long int sas_address = 0; + unsigned long int sas_address; char *sysfs_path, disk[MAX_DISK_CAT - sizeof ("/fp@0,0")]; char *of_path; @@ -563,8 +404,9 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev } of_path = find_obppath(sysfs_path); + free (sysfs_path); if (!of_path) - goto out; + return NULL; if (strstr (of_path, "qlc")) strcat (of_path, "/fp@0,0"); @@ -593,46 +435,6 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev } else { -#ifdef __sparc__ - ofpath_sparc_addressing addressing = GRUB_OFPATH_SPARC_TGT_LUN; - int vendor = 0, device_id = 0; - char *optr = disk; - - check_hba_identifiers (sysfs_path, &vendor, &device_id); - - if (vendor == LSI_VENDOR_ID) - { - struct ofpath_sparc_hba *lsi_hba; - - /* - * Over time different OF addressing schemes have been supported. - * There is no generic addressing scheme that works across - * every HBA. - */ - for (lsi_hba = sparc_lsi_hba; lsi_hba->device_id; lsi_hba++) - if (lsi_hba->device_id == device_id) - { - addressing = lsi_hba->addressing; - break; - } - } - - if (addressing == GRUB_OFPATH_SPARC_WWN_ADDR) - optr += snprintf (disk, sizeof (disk), "/%s@w%lx,%x", disk_name, - sas_address, lun); - else - optr += snprintf (disk, sizeof (disk), "/%s@%x,%x", disk_name, tgt, - lun); - - if (*digit_string != '\0') - { - int part; - - sscanf (digit_string, "%d", &part); - snprintf (optr, sizeof (disk) - (optr - disk - 1), ":%c", 'a' - + (part - 1)); - } -#else if (lun == 0) { int sas_id = 0; @@ -678,14 +480,9 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev snprintf(disk, sizeof (disk), "/sas/%s@%lx,%lu:%c", disk_name, sas_address, longlun, 'a' + (part - 1)); } - free (lunstr); } -#endif } strcat(of_path, disk); - - out: - free (sysfs_path); return of_path; } @@ -730,15 +527,10 @@ grub_util_devname_to_ofpath (const char *sys_devname) /* All the models I've seen have a devalias "floppy". New models have no floppy at all. */ ofpath = xstrdup ("floppy"); -#ifdef __sparc__ - else if (device[0] == 'n' && device[1] == 'v' && device[2] == 'm' - && device[3] == 'e') - ofpath = of_path_of_nvme (name_buf, device, devnode, devicenode); -#endif else { - grub_util_warn (_("unknown device type %s"), device); - ofpath = NULL; + grub_util_warn (_("unknown device type %s\n"), device); + return NULL; } free (devnode); diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c index e28a79dab..4b9f6ef9d 100644 --- a/grub-core/osdep/linux/platform.c +++ b/grub-core/osdep/linux/platform.c @@ -60,53 +60,15 @@ is_64_kernel (void) return strcmp (un.machine, "x86_64") == 0; } -static int -read_platform_size (void) -{ - FILE *fp; - char *buf = NULL; - size_t len = 0; - int ret = 0; - - /* Newer kernels can tell us directly about the size of the - * underlying firmware - let's see if that interface is there. */ - fp = grub_util_fopen ("/sys/firmware/efi/fw_platform_size", "r"); - if (fp != NULL) - { - if (getline (&buf, &len, fp) >= 3) /* 2 digits plus newline */ - { - if (strncmp (buf, "32", 2) == 0) - ret = 32; - else if (strncmp (buf, "64", 2) == 0) - ret = 64; - } - free (buf); - fclose (fp); - } - - if (ret == 0) - { - /* Unrecognised - fall back to matching the kernel size - * instead */ - if (is_64_kernel ()) - ret = 64; - else - ret = 32; - } - - return ret; -} - -/* Are we running on an EFI-based system? */ -static int -is_efi_system (void) -{ +const char * +grub_install_get_default_x86_platform (void) +{ /* - * Linux uses efivarfs (mounted on /sys/firmware/efi/efivars) to access the - * EFI variable store. Some legacy systems may still use the deprecated - * efivars interface (accessed through /sys/firmware/efi/vars). Where both - * are present, libefivar will use the former in preference, so attempting - * to load efivars will not interfere with later operations. + On Linux, we need the efivars kernel modules. + If no EFI is available this module just does nothing + besides a small hello and if we detect efi we'll load it + anyway later. So it should be safe to + try to load it here. */ grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL }, NULL, NULL, "/dev/null"); @@ -115,36 +77,13 @@ is_efi_system (void) if (is_not_empty_directory ("/sys/firmware/efi")) { grub_util_info ("...found"); - return 1; - } - else - { - grub_util_info ("... not found"); - return 0; - } -} - -const char * -grub_install_get_default_arm_platform (void) -{ - if (is_efi_system()) - return "arm-efi"; - else - return "arm-uboot"; -} - -const char * -grub_install_get_default_x86_platform (void) -{ - if (is_efi_system()) - { - if (read_platform_size() == 64) + if (is_64_kernel ()) return "x86_64-efi"; else return "i386-efi"; } - grub_util_info ("Looking for /proc/device-tree .."); + grub_util_info ("... not found. Looking for /proc/device-tree .."); if (is_not_empty_directory ("/proc/device-tree")) { grub_util_info ("...found"); diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c index 7d6325138..65effa9f3 100644 --- a/grub-core/osdep/unix/config.c +++ b/grub-core/osdep/unix/config.c @@ -89,7 +89,7 @@ grub_util_load_config (struct grub_util_config *cfg) argv[0] = "sh"; argv[1] = "-c"; - script = xcalloc (4, strlen (cfgfile) + 300); + script = xmalloc (4 * strlen (cfgfile) + 300); ptr = script; memcpy (ptr, ". '", 3); diff --git a/grub-core/osdep/unix/exec.c b/grub-core/osdep/unix/exec.c index db3259f65..935ff120e 100644 --- a/grub-core/osdep/unix/exec.c +++ b/grub-core/osdep/unix/exec.c @@ -99,7 +99,7 @@ grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, { fd = open (stdin_file, O_RDONLY); if (fd < 0) - _exit (127); + exit (127); dup2 (fd, STDIN_FILENO); close (fd); } @@ -108,7 +108,7 @@ grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, { fd = open (stdout_file, O_WRONLY | O_CREAT, 0700); if (fd < 0) - _exit (127); + exit (127); dup2 (fd, STDOUT_FILENO); close (fd); } @@ -117,7 +117,7 @@ grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, { fd = open (stderr_file, O_WRONLY | O_CREAT, 0700); if (fd < 0) - _exit (127); + exit (127); dup2 (fd, STDERR_FILENO); close (fd); } @@ -126,7 +126,7 @@ grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, setenv ("LC_ALL", "C", 1); execvp ((char *) argv[0], (char **) argv); - _exit (127); + exit (127); } waitpid (pid, &status, 0); if (!WIFEXITED (status)) diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c index 46d7116c6..e3887cbea 100644 --- a/grub-core/osdep/unix/getroot.c +++ b/grub-core/osdep/unix/getroot.c @@ -34,7 +34,6 @@ #ifdef HAVE_LIMITS_H #include #endif - #include #include @@ -46,17 +45,18 @@ #ifdef __linux__ #include /* ioctl */ #include +#ifndef MAJOR +# ifndef MINORBITS +# define MINORBITS 8 +# endif /* ! MINORBITS */ +# define MAJOR(dev) ((unsigned) ((dev) >> MINORBITS)) +#endif /* ! MAJOR */ #ifndef FLOPPY_MAJOR # define FLOPPY_MAJOR 2 #endif /* ! FLOPPY_MAJOR */ #endif #include -#if defined(MAJOR_IN_MKDEV) -#include -#elif defined(MAJOR_IN_SYSMACROS) -#include -#endif #if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) # include @@ -70,6 +70,7 @@ #include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +# define MAJOR(dev) major(dev) # define FLOPPY_MAJOR 2 #endif @@ -86,6 +87,7 @@ #endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */ #if defined(__NetBSD__) || defined(__OpenBSD__) +# define MAJOR(dev) major(dev) # ifdef HAVE_GETRAWPARTITION # include /* getrawpartition */ # endif /* HAVE_GETRAWPARTITION */ @@ -114,8 +116,6 @@ #include #endif -#include "save-cwd.h" - #if !defined (__GNU__) static void strip_extra_slashes (char *dir) @@ -355,7 +355,7 @@ char * grub_find_device (const char *dir, dev_t dev) { DIR *dp; - struct saved_cwd saved_cwd; + char *saved_cwd; struct dirent *ent; if (! dir) @@ -365,17 +365,12 @@ grub_find_device (const char *dir, dev_t dev) if (! dp) return 0; - if (save_cwd (&saved_cwd) < 0) - { - grub_util_error ("%s", _("cannot save the original directory")); - closedir (dp); - return 0; - } + saved_cwd = xgetcwd (); grub_util_info ("changing current directory to %s", dir); if (chdir (dir) < 0) { - free_cwd (&saved_cwd); + free (saved_cwd); closedir (dp); return 0; } @@ -418,11 +413,11 @@ grub_find_device (const char *dir, dev_t dev) if (res) { - if (restore_cwd (&saved_cwd) < 0) + if (chdir (saved_cwd) < 0) grub_util_error ("%s", _("cannot restore the original directory")); - free_cwd (&saved_cwd); + free (saved_cwd); closedir (dp); return res; } @@ -436,11 +431,8 @@ grub_find_device (const char *dir, dev_t dev) { #ifdef __linux__ /* Skip device names like /dev/dm-0, which are short-hand aliases - to more descriptive device names, e.g. those under /dev/mapper. - Also, don't skip devices which names start with dm-[0-9] in - directories below /dev, e.g. /dev/mapper/dm-0-luks. */ - if (strcmp (dir, "/dev") == 0 && - ent->d_name[0] == 'd' && + to more descriptive device names, e.g. those under /dev/mapper */ + if (ent->d_name[0] == 'd' && ent->d_name[1] == 'm' && ent->d_name[2] == '-' && ent->d_name[3] >= '0' && @@ -476,19 +468,19 @@ grub_find_device (const char *dir, dev_t dev) continue; } - if (restore_cwd (&saved_cwd) < 0) + if (chdir (saved_cwd) < 0) grub_util_error ("%s", _("cannot restore the original directory")); - free_cwd (&saved_cwd); + free (saved_cwd); closedir (dp); return res; } } - if (restore_cwd (&saved_cwd) < 0) + if (chdir (saved_cwd) < 0) grub_util_error ("%s", _("cannot restore the original directory")); - free_cwd (&saved_cwd); + free (saved_cwd); closedir (dp); return 0; } @@ -499,7 +491,7 @@ grub_guess_root_devices (const char *dir_in) char **os_dev = NULL; struct stat st; dev_t dev; - char *dir = grub_canonicalize_file_name (dir_in); + char *dir = canonicalize_file_name (dir_in); if (!dir) grub_util_error (_("failed to get canonical path of `%s'"), dir_in); @@ -524,7 +516,7 @@ grub_guess_root_devices (const char *dir_in) *cur = tmp; else { - *cur = grub_canonicalize_file_name (tmp); + *cur = canonicalize_file_name (tmp); if (*cur == NULL) grub_util_error (_("failed to get canonical path of `%s'"), tmp); free (tmp); @@ -549,7 +541,6 @@ grub_guess_root_devices (const char *dir_in) if (stat (dir, &st) < 0) grub_util_error (_("cannot stat `%s': %s"), dir, strerror (errno)); - free (dir); dev = st.st_dev; @@ -630,10 +621,7 @@ grub_util_pull_lvm_by_command (const char *os_dev) free (vgname); if (!pid) - { - free (vgid); - return; - } + return; /* Parent. Read vgs' output. */ vgs = fdopen (fd, "r"); @@ -665,7 +653,6 @@ out: close (fd); waitpid (pid, NULL, 0); free (buf); - free (vgid); } /* ZFS has similar problems to those of btrfs (see above). */ diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c index 3a00d7451..b3bc0e425 100644 --- a/grub-core/osdep/unix/hostdisk.c +++ b/grub-core/osdep/unix/hostdisk.c @@ -77,19 +77,11 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz int grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off) { -#if SIZEOF_OFF_T == 8 off_t offset = (off_t) off; if (lseek (fd, offset, SEEK_SET) != offset) return -1; -#elif SIZEOF_OFF64_T == 8 - off64_t offset = (off64_t) off; - if (lseek64 (fd, offset, SEEK_SET) != offset) - return -1; -#else -#error "No large file support" -#endif return 0; } @@ -164,9 +156,6 @@ grub_util_fd_open (const char *os_dev, int flags) #ifdef O_BINARY flags |= O_BINARY; #endif -#ifdef O_CLOEXEC - flags |= O_CLOEXEC; -#endif return open (os_dev, flags, S_IROTH | S_IRGRP | S_IRUSR | S_IWUSR); } @@ -180,22 +169,20 @@ grub_util_fd_strerror (void) static int allow_fd_syncs = 1; -int +void grub_util_fd_sync (grub_util_fd_t fd) { if (allow_fd_syncs) - return fsync (fd); - return 0; + fsync (fd); } -int +void grub_util_file_sync (FILE *f) { - if (fflush (f) != 0) - return -1; + fflush (f); if (!allow_fd_syncs) - return 0; - return fsync (fileno (f)); + return; + fsync (fileno (f)); } void @@ -204,14 +191,14 @@ grub_util_disable_fd_syncs (void) allow_fd_syncs = 0; } -int +void grub_util_fd_close (grub_util_fd_t fd) { - return close (fd); + close (fd); } char * -grub_canonicalize_file_name (const char *path) +canonicalize_file_name (const char *path) { #if defined (PATH_MAX) char *ret; diff --git a/grub-core/osdep/unix/password.c b/grub-core/osdep/unix/password.c index 9996b244b..470a6ea62 100644 --- a/grub-core/osdep/unix/password.c +++ b/grub-core/osdep/unix/password.c @@ -53,11 +53,7 @@ grub_password_get (char buf[], unsigned buf_size) tty_changed = 0; grub_memset (buf, 0, buf_size); if (!fgets (buf, buf_size, stdin)) - { - if (in != stdin) - fclose (in); - return 0; - } + return 0; ptr = buf + strlen (buf) - 1; while (buf <= ptr && (*ptr == '\n' || *ptr == '\r')) *ptr-- = 0; @@ -68,8 +64,5 @@ grub_password_get (char buf[], unsigned buf_size) grub_xputs ("\n"); grub_refresh (); - if (in != stdin) - fclose (in); - return 1; } diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c index 55b8f4016..a3fcfcaca 100644 --- a/grub-core/osdep/unix/platform.c +++ b/grub-core/osdep/unix/platform.c @@ -78,20 +78,19 @@ get_ofpathname (const char *dev) dev); } -static int +static void grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) { int fd; pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd); char *line = NULL; size_t len = 0; - int rc = 0; if (!pid) { grub_util_warn (_("Unable to open stream from %s: %s"), "efibootmgr", strerror (errno)); - return errno; + return; } FILE *fp = fdopen (fd, "r"); @@ -99,7 +98,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) { grub_util_warn (_("Unable to open stream from %s: %s"), "efibootmgr", strerror (errno)); - return errno; + return; } line = xmalloc (80); @@ -120,25 +119,23 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) bootnum = line + sizeof ("Boot") - 1; bootnum[4] = '\0'; if (!verbosity) - rc = grub_util_exec ((const char * []){ "efibootmgr", "-q", + grub_util_exec ((const char * []){ "efibootmgr", "-q", "-b", bootnum, "-B", NULL }); else - rc = grub_util_exec ((const char * []){ "efibootmgr", + grub_util_exec ((const char * []){ "efibootmgr", "-b", bootnum, "-B", NULL }); } free (line); - return rc; } -int +void grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, const char *efi_distributor) { const char * efidir_disk; int efidir_part; - int ret; efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk); efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1; @@ -154,26 +151,23 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL }); #endif /* Delete old entries from the same distributor. */ - ret = grub_install_remove_efi_entries_by_distributor (efi_distributor); - if (ret) - return ret; + grub_install_remove_efi_entries_by_distributor (efi_distributor); char *efidir_part_str = xasprintf ("%d", efidir_part); if (!verbosity) - ret = grub_util_exec ((const char * []){ "efibootmgr", "-q", + grub_util_exec ((const char * []){ "efibootmgr", "-q", "-c", "-d", efidir_disk, "-p", efidir_part_str, "-w", "-L", efi_distributor, "-l", efifile_path, NULL }); else - ret = grub_util_exec ((const char * []){ "efibootmgr", + grub_util_exec ((const char * []){ "efibootmgr", "-c", "-d", efidir_disk, "-p", efidir_part_str, "-w", "-L", efi_distributor, "-l", efifile_path, NULL }); free (efidir_part_str); - return ret; } void diff --git a/grub-core/osdep/unix/relpath.c b/grub-core/osdep/unix/relpath.c index f719950fd..71c19d867 100644 --- a/grub-core/osdep/unix/relpath.c +++ b/grub-core/osdep/unix/relpath.c @@ -44,17 +44,14 @@ grub_make_system_path_relative_to_its_root (const char *path) char *poolfs = NULL; /* canonicalize. */ - p = grub_canonicalize_file_name (path); + p = canonicalize_file_name (path); if (p == NULL) grub_util_error (_("failed to get canonical path of `%s'"), path); #ifdef __linux__ ret = grub_make_system_path_relative_to_its_root_os (p); if (ret) - { - free (p); - return ret; - } + return ret; #endif /* For ZFS sub-pool filesystems. */ diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c index eada663b2..661d95461 100644 --- a/grub-core/osdep/windows/getroot.c +++ b/grub-core/osdep/windows/getroot.c @@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) for (ptr = path; *ptr; ptr++); allocsize = (ptr - path + 10) * 2; - out = xcalloc (allocsize, sizeof (out[0])); + out = xmalloc (allocsize * sizeof (out[0])); /* When pointing to EFI system partition GetVolumePathName fails for ESP root and returns abberant information for everything diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c index 0be327394..d390b25fc 100644 --- a/grub-core/osdep/windows/hostdisk.c +++ b/grub-core/osdep/windows/hostdisk.c @@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) while (1) { - fpa = xcalloc (alloc, sizeof (fpa[0])); + fpa = xmalloc (alloc * sizeof (fpa[0])); len = GetFullPathName (tpath, alloc, fpa, NULL); if (len >= alloc) @@ -275,18 +275,11 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len) static int allow_fd_syncs = 1; -int +void grub_util_fd_sync (grub_util_fd_t fd) { if (allow_fd_syncs) - { - if (!FlushFileBuffers (fd)) - { - grub_util_info ("flush err %x", (int) GetLastError ()); - return -1; - } - } - return 0; + FlushFileBuffers (fd); } void @@ -295,15 +288,10 @@ grub_util_disable_fd_syncs (void) allow_fd_syncs = 0; } -int +void grub_util_fd_close (grub_util_fd_t fd) { - if (!CloseHandle (fd)) - { - grub_util_info ("close err %x", (int) GetLastError ()); - return -1; - } - return 0; + CloseHandle (fd); } const char * @@ -340,7 +328,7 @@ grub_util_fd_strerror (void) } char * -grub_canonicalize_file_name (const char *path) +canonicalize_file_name (const char *path) { char *ret; LPTSTR windows_path; @@ -399,7 +387,7 @@ grub_util_fd_opendir (const char *name) for (l = 0; name_windows[l]; l++); for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); l++; - pattern = xcalloc (l + 3, sizeof (pattern[0])); + pattern = xmalloc ((l + 3) * sizeof (pattern[0])); memcpy (pattern, name_windows, l * sizeof (pattern[0])); pattern[l] = '\\'; pattern[l + 1] = '*'; @@ -632,25 +620,16 @@ grub_util_fopen (const char *path, const char *mode) return ret; } -int +void grub_util_file_sync (FILE *f) { HANDLE hnd; - if (fflush (f) != 0) - { - grub_util_info ("fflush err %x", (int) GetLastError ()); - return -1; - } + fflush (f); if (!allow_fd_syncs) - return 0; + return; hnd = (HANDLE) _get_osfhandle (fileno (f)); - if (!FlushFileBuffers (hnd)) - { - grub_util_info ("flush err %x", (int) GetLastError ()); - return -1; - } - return 0; + FlushFileBuffers (hnd); } int diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c index 6297de632..98c325c20 100644 --- a/grub-core/osdep/windows/init.c +++ b/grub-core/osdep/windows/init.c @@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), LPWSTR *targv; targv = CommandLineToArgvW (tcmdline, argc); - *argv = xcalloc (*argc + 1, sizeof (argv[0])); + *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); for (i = 0; i < *argc; i++) (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); @@ -170,7 +170,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), #error "Unsupported TCHAR size" #endif - grub_util_base_directory = grub_canonicalize_file_name ((*argv)[0]); + grub_util_base_directory = canonicalize_file_name ((*argv)[0]); if (!grub_util_base_directory) grub_util_base_directory = xstrdup ((*argv)[0]); for (ptr = grub_util_base_directory + strlen (grub_util_base_directory) - 1; diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c index 1ef86bf58..d217efe17 100644 --- a/grub-core/osdep/windows/platform.c +++ b/grub-core/osdep/windows/platform.c @@ -201,7 +201,7 @@ set_efi_variable_bootn (grub_uint16_t n, void *in, grub_size_t len) set_efi_variable (varname, in, len); } -int +void grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, const char *efi_distributor) @@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); distrib8_len = grub_strlen (efi_distributor); - distributor16 = xcalloc (distrib8_len + 1, - GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); + distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 + * sizeof (grub_uint16_t)); distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, (const grub_uint8_t *) efi_distributor, distrib8_len, 0); @@ -363,16 +363,16 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, grub_util_error ("%s", grub_errmsg); efidir_grub_dev->disk->partition = p; grub_memcpy (hddp->partition_signature, - &gptdata.guid, 16); + gptdata.guid, 16); hddp->partmap_type = 2; hddp->signature_type = 2; } hddp->partition_start = grub_partition_get_start (efidir_grub_dev->disk->partition) - >> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); + << (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); hddp->partition_size = grub_disk_get_size (efidir_grub_dev->disk) - >> (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); + << (efidir_grub_dev->disk->log_sector_size - GRUB_DISK_SECTOR_BITS); pathptr = hddp + 1; filep = pathptr; @@ -407,8 +407,6 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, set_efi_variable_bootn (order_num, entry, (grub_uint8_t *) pathptr - entry); set_efi_variable (L"BootOrder", new_boot_order, new_boot_order_len * sizeof (grub_uint16_t)); - - return 0; } void diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c index 478e8ef14..cb0861744 100644 --- a/grub-core/osdep/windows/relpath.c +++ b/grub-core/osdep/windows/relpath.c @@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) if (dirwindows[0] && dirwindows[1] == ':') offset = 2; } - ret = xcalloc (flen - offset + 2, sizeof (ret[0])); + ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); if (dirwindows[offset] != '\\' && dirwindows[offset] != '/' && dirwindows[offset]) diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c index 72a2e37cd..83bcba779 100644 --- a/grub-core/partmap/gpt.c +++ b/grub-core/partmap/gpt.c @@ -33,10 +33,10 @@ static grub_uint8_t grub_gpt_magic[8] = 0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54 }; -static const grub_gpt_part_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY; +static const grub_gpt_part_type_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY; #ifdef GRUB_UTIL -static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT; +static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT; #endif /* 512 << 7 = 65536 byte sectors. */ @@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, *nsectors = ctx.len; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index ee3f24982..46c406bff 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -175,9 +175,9 @@ grub_partition_msdos_iterate (grub_disk_t disk, e = mbr.entries + p.index; p.start = p.offset - + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) + + (grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) - delta; - p.len = (grub_uint64_t)grub_le_to_cpu32 (e->length) + p.len = grub_le_to_cpu32 (e->length) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); p.msdostype = e->type; @@ -210,7 +210,7 @@ grub_partition_msdos_iterate (grub_disk_t disk, if (grub_msdos_partition_is_extended (e->type)) { p.offset = ext_offset - + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) + + (grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = p.offset; @@ -249,7 +249,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (embed_type != GRUB_EMBED_PCBIOS) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "PC-style partitions currently support " + "PC-style partitions curently support " "only PC-BIOS embedding"); if (disk->partition) @@ -294,9 +294,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (!grub_msdos_partition_is_empty (e->type) && end > offset - + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) + + (grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) - end = offset + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) + end = offset + (grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); /* If this is a GPT partition, this MBR is just a dummy. */ @@ -312,7 +312,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (grub_msdos_partition_is_extended (e->type)) { offset = ext_offset - + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) + + (grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = offset; @@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, avail_nsectors = *nsectors; if (*nsectors > max_nsectors) *nsectors = max_nsectors; - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); if (!*sectors) return grub_errno; for (i = 0; i < *nsectors; i++) diff --git a/grub-core/partmap/sun.c b/grub-core/partmap/sun.c index aac30a320..dae360269 100644 --- a/grub-core/partmap/sun.c +++ b/grub-core/partmap/sun.c @@ -91,7 +91,7 @@ sun_partition_map_iterate (grub_disk_t disk, struct grub_partition p; union { - struct grub_sun_block sun_block; + struct grub_sun_block sun; grub_uint16_t raw[0]; } block; int partnum; @@ -103,7 +103,7 @@ sun_partition_map_iterate (grub_disk_t disk, if (err) return err; - if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.sun_block.magic)) + if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.sun.magic)) return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table"); if (! grub_sun_is_valid (block.raw)) @@ -115,14 +115,14 @@ sun_partition_map_iterate (grub_disk_t disk, { struct grub_sun_partition_descriptor *desc; - if (block.sun_block.infos[partnum].id == 0 - || block.sun_block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) + if (block.sun.infos[partnum].id == 0 + || block.sun.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID) continue; - desc = &block.sun_block.partitions[partnum]; + desc = &block.sun.partitions[partnum]; p.start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder) - * grub_be_to_cpu16 (block.sun_block.ntrks) - * grub_be_to_cpu16 (block.sun_block.nsect)); + * grub_be_to_cpu16 (block.sun.ntrks) + * grub_be_to_cpu16 (block.sun.nsect)); p.len = grub_be_to_cpu32 (desc->num_sectors); p.number = p.index = partnum; if (p.len) diff --git a/grub-core/partmap/sunpc.c b/grub-core/partmap/sunpc.c index 73a430c14..442763ee5 100644 --- a/grub-core/partmap/sunpc.c +++ b/grub-core/partmap/sunpc.c @@ -74,7 +74,7 @@ sun_pc_partition_map_iterate (grub_disk_t disk, grub_partition_t p; union { - struct grub_sun_pc_block sun_block; + struct grub_sun_pc_block sun; grub_uint16_t raw[0]; } block; int partnum; @@ -92,7 +92,7 @@ sun_pc_partition_map_iterate (grub_disk_t disk, return err; } - if (GRUB_PARTMAP_SUN_PC_MAGIC != grub_le_to_cpu16 (block.sun_block.magic)) + if (GRUB_PARTMAP_SUN_PC_MAGIC != grub_le_to_cpu16 (block.sun.magic)) { grub_free (p); return grub_error (GRUB_ERR_BAD_PART_TABLE, @@ -111,12 +111,12 @@ sun_pc_partition_map_iterate (grub_disk_t disk, { struct grub_sun_pc_partition_descriptor *desc; - if (block.sun_block.partitions[partnum].id == 0 - || block.sun_block.partitions[partnum].id + if (block.sun.partitions[partnum].id == 0 + || block.sun.partitions[partnum].id == GRUB_PARTMAP_SUN_PC_WHOLE_DISK_ID) continue; - desc = &block.sun_block.partitions[partnum]; + desc = &block.sun.partitions[partnum]; p->start = grub_le_to_cpu32 (desc->start_sector); p->len = grub_le_to_cpu32 (desc->num_sectors); p->number = partnum; diff --git a/grub-core/script/argv.c b/grub-core/script/argv.c index 5751fdd57..217ec5d1e 100644 --- a/grub-core/script/argv.c +++ b/grub-core/script/argv.c @@ -20,7 +20,6 @@ #include #include #include -#include /* Return nearest power of two that is >= v. */ static unsigned @@ -82,16 +81,11 @@ int grub_script_argv_next (struct grub_script_argv *argv) { char **p = argv->args; - grub_size_t sz; if (argv->args && argv->argc && argv->args[argv->argc - 1] == 0) return 0; - if (grub_add (argv->argc, 2, &sz) || - grub_mul (sz, sizeof (char *), &sz)) - return 1; - - p = grub_realloc (p, round_up_exp (sz)); + p = grub_realloc (p, round_up_exp ((argv->argc + 2) * sizeof (char *))); if (! p) return 1; @@ -111,19 +105,13 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s, { grub_size_t a; char *p = argv->args[argv->argc - 1]; - grub_size_t sz; if (! s) return 0; a = p ? grub_strlen (p) : 0; - if (grub_add (a, slen, &sz) || - grub_add (sz, 1, &sz) || - grub_mul (sz, sizeof (char), &sz)) - return 1; - - p = grub_realloc (p, round_up_exp (sz)); + p = grub_realloc (p, round_up_exp ((a + slen + 1) * sizeof (char))); if (! p) return 1; diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index ce83edd4b..afd551320 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -27,7 +27,6 @@ #include #include #include -#include /* Max digits for a char is 3 (0xFF is 255), similarly for an int it is sizeof (int) * 3, and one extra for a possible -ve sign. */ @@ -122,7 +121,7 @@ replace_scope (struct grub_script_scope *new_scope) grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]) { - const char *p = NULL; + char *p = 0; unsigned long count; if (argc == 0) @@ -154,7 +153,7 @@ grub_err_t grub_script_shift (grub_command_t cmd __attribute__((unused)), int argc, char *argv[]) { - const char *p = NULL; + char *p = 0; unsigned long n = 0; if (! scope) @@ -215,7 +214,7 @@ grub_err_t grub_script_return (grub_command_t cmd __attribute__((unused)), int argc, char *argv[]) { - const char *p = NULL; + char *p; unsigned long n; if (! scope || argc > 1) @@ -553,7 +552,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) for (iptr = orig_str; *iptr; iptr++) if (*iptr == '$') dollar_cnt++; - ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); + ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) goto fail; @@ -636,73 +635,57 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, { case GRUB_SCRIPT_ARG_TYPE_VAR: case GRUB_SCRIPT_ARG_TYPE_DQVAR: - { - int need_cleanup = 0; + values = grub_script_env_get (arg->str, arg->type); + for (i = 0; values && values[i]; i++) + { + if (i != 0 && grub_script_argv_next (&result)) + goto fail; - values = grub_script_env_get (arg->str, arg->type); - for (i = 0; values && values[i]; i++) - { - if (!need_cleanup) - { - if (i != 0 && grub_script_argv_next (&result)) - { - need_cleanup = 1; - goto cleanup; - } + if (arg->type == GRUB_SCRIPT_ARG_TYPE_VAR) + { + int len; + char ch; + char *p; + char *op; + const char *s = values[i]; - if (arg->type == GRUB_SCRIPT_ARG_TYPE_VAR) - { - int len; - char ch; - char *p; - char *op; - const char *s = values[i]; + len = grub_strlen (values[i]); + /* \? -> \\\? */ + /* \* -> \\\* */ + /* \ -> \\ */ + p = grub_malloc (len * 2 + 1); + if (! p) + goto fail; - len = grub_strlen (values[i]); - /* \? -> \\\? */ - /* \* -> \\\* */ - /* \ -> \\ */ - p = grub_malloc (len * 2 + 1); - if (! p) - { - need_cleanup = 1; - goto cleanup; - } + op = p; + while ((ch = *s++)) + { + if (ch == '\\') + { + *op++ = '\\'; + if (*s == '?' || *s == '*') + *op++ = '\\'; + } + *op++ = ch; + } + *op = '\0'; - op = p; - while ((ch = *s++)) - { - if (ch == '\\') - { - *op++ = '\\'; - if (*s == '?' || *s == '*') - *op++ = '\\'; - } - *op++ = ch; - } - *op = '\0'; + if (grub_script_argv_append (&result, p, op - p)) + { + grub_free (p); + goto fail; + } + } + else + { + if (append (&result, values[i], 1)) + goto fail; + } - need_cleanup = grub_script_argv_append (&result, p, op - p); - grub_free (p); - /* Fall through to cleanup */ - } - else - { - need_cleanup = append (&result, values[i], 1); - /* Fall through to cleanup */ - } - } - -cleanup: - grub_free (values[i]); - } - grub_free (values); - - if (need_cleanup) - goto fail; - - break; - } + grub_free (values[i]); + } + grub_free (values); + break; case GRUB_SCRIPT_ARG_TYPE_BLOCK: { @@ -838,9 +821,7 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args) old_scope = scope; scope = &new_scope; - func->executing++; ret = grub_script_execute (func->func); - func->executing--; function_return = 0; active_loops = loops; @@ -932,9 +913,8 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_err_t ret = 0; grub_script_function_t func = 0; char errnobuf[18]; - char *cmdname, *cmdstring; - int argc, offset = 0, cmdlen = 0; - unsigned int i; + char *cmdname; + int argc; char **args; int invert; struct grub_script_argv argv = { 0, 0, 0 }; @@ -943,26 +923,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0]) return grub_errno; - for (i = 0; i < argv.argc; i++) - { - cmdlen += grub_strlen (argv.args[i]) + 1; - } - - cmdstring = grub_malloc (cmdlen); - if (!cmdstring) - { - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - N_("cannot allocate command buffer")); - } - - for (i = 0; i < argv.argc; i++) - { - offset += grub_snprintf (cmdstring + offset, cmdlen - offset, "%s ", - argv.args[i]); - } - cmdstring[cmdlen - 1] = '\0'; - grub_verify_string (cmdstring, GRUB_VERIFY_COMMAND); - grub_free (cmdstring); invert = 0; argc = argv.argc - 1; args = argv.args + 1; @@ -1187,3 +1147,4 @@ grub_script_execute (struct grub_script *script) return grub_script_execute_cmd (script->cmd); } + diff --git a/grub-core/script/function.c b/grub-core/script/function.c index 3aad04bf9..d36655e51 100644 --- a/grub-core/script/function.c +++ b/grub-core/script/function.c @@ -34,7 +34,6 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, func = (grub_script_function_t) grub_malloc (sizeof (*func)); if (! func) return 0; - func->executing = 0; func->name = grub_strdup (functionname_arg->str); if (! func->name) @@ -61,19 +60,10 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, grub_script_function_t q; q = *p; + grub_script_free (q->func); + q->func = cmd; grub_free (func); - if (q->executing > 0) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, - N_("attempt to redefine a function being executed")); - func = NULL; - } - else - { - grub_script_free (q->func); - q->func = cmd; - func = q; - } + func = q; } else { diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c index 57778f881..89cf67706 100644 --- a/grub-core/script/lexer.c +++ b/grub-core/script/lexer.c @@ -24,7 +24,6 @@ #include #include #include -#include #define yytext_ptr char * #include "grub_script.tab.h" @@ -111,14 +110,10 @@ grub_script_lexer_record (struct grub_parser_param *parser, char *str) old = lexer->recording; if (lexer->recordlen < len) lexer->recordlen = len; - - if (grub_mul (lexer->recordlen, 2, &lexer->recordlen)) - goto fail; - + lexer->recordlen *= 2; lexer->recording = grub_realloc (lexer->recording, lexer->recordlen); if (!lexer->recording) { - fail: grub_free (old); lexer->recordpos = 0; lexer->recordlen = 0; @@ -135,7 +130,7 @@ int grub_script_lexer_yywrap (struct grub_parser_param *parserstate, const char *input) { - grub_size_t len = 0, sz; + grub_size_t len = 0; char *p = 0; char *line = 0; YY_BUFFER_STATE buffer; @@ -173,22 +168,12 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate, } else if (len && line[len - 1] != '\n') { - if (grub_add (len, 2, &sz)) - { - grub_free (line); - grub_script_yyerror (parserstate, N_("overflow is detected")); - return 1; - } - - p = grub_realloc (line, sz); + p = grub_realloc (line, len + 2); if (p) { p[len++] = '\n'; p[len] = '\0'; } - else - grub_free (line); - line = p; } @@ -266,6 +251,7 @@ grub_script_lexer_init (struct grub_parser_param *parser, char *script, { parser->lexerstate = 0; yylex_destroy (lexerstate->yyscanner); + grub_free (lexerstate->yyscanner); grub_free (lexerstate->text); grub_free (lexerstate); return 0; @@ -346,7 +332,7 @@ grub_script_yylex (union YYSTYPE *value, } void -grub_script_yyerror (struct grub_parser_param *state, const char *err) +grub_script_yyerror (struct grub_parser_param *state, char const *err) { if (err) grub_error (GRUB_ERR_INVALID_COMMAND, err); diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y index 4a18ab7ba..1d60e9de2 100644 --- a/grub-core/script/parser.y +++ b/grub-core/script/parser.y @@ -30,6 +30,7 @@ #include "grub_script.tab.h" +#pragma GCC diagnostic ignored "-Wunreachable-code" #pragma GCC diagnostic ignored "-Wmissing-declarations" %} @@ -279,7 +280,7 @@ function: "function" "name" $$ = state->scripts; state->scripts = 0; } - newlines0 "{" commands1 delimiters1 "}" + delimiters0 "{" commands1 delimiters1 "}" { struct grub_script *script; state->func_mem = grub_script_mem_record_stop (state, @@ -289,8 +290,7 @@ function: "function" "name" grub_script_mem_free (state->func_mem); else { script->children = state->scripts; - if (!grub_script_function_create ($2, script)) - grub_script_free (script); + grub_script_function_create ($2, script); } state->scripts = $3; diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index b7203c823..9c2cfe115 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -37,11 +37,11 @@ /* * As we don't have access to yyscanner, we cannot do much except to - * print the fatal error and exit. + * print the fatal error. */ #define YY_FATAL_ERROR(msg) \ do { \ - grub_fatal (_("fatal error: %s\n"), _(msg));\ + grub_printf (_("fatal error: %s\n"), _(msg)); \ } while (0) #define COPY(str, hint) \ @@ -91,8 +91,8 @@ typedef size_t yy_size_t; #define stdin 0 #define stdout 0 -#define fprintf(...) (void)0 -#define exit(...) grub_fatal("fatal error in lexer") +#define fprintf(...) 0 +#define exit(...) #endif } diff --git a/grub-core/term/arm/cros.c b/grub-core/term/arm/cros.c deleted file mode 100644 index 1ff9f8ccf..000000000 --- a/grub-core/term/arm/cros.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * - * Copyright (C) 2012 Google Inc. - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * This is based on depthcharge code. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct grub_ps2_state ps2_state; - -struct grub_cros_ec_keyscan old_scan; - -static const struct grub_fdtbus_dev *cros_ec; - -static grub_uint8_t map_code[GRUB_CROS_EC_KEYSCAN_COLS][GRUB_CROS_EC_KEYSCAN_ROWS]; - -static grub_uint8_t e0_translate[16] = - { - 0x1c, 0x1d, 0x35, 0x00, - 0x38, 0x00, 0x47, 0x48, - 0x49, 0x4b, 0x4d, 0x4f, - 0x50, 0x51, 0x52, 0x53, - }; - -/* If there is a character pending, return it; - otherwise return GRUB_TERM_NO_KEY. */ -static int -grub_cros_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) -{ - struct grub_cros_ec_keyscan scan; - int i, j; - if (grub_cros_ec_scan_keyboard (cros_ec, &scan) < 0) - return GRUB_TERM_NO_KEY; - for (i = 0; i < GRUB_CROS_EC_KEYSCAN_COLS; i++) - if (scan.data[i] ^ old_scan.data[i]) - for (j = 0; j < GRUB_CROS_EC_KEYSCAN_ROWS; j++) - if ((scan.data[i] ^ old_scan.data[i]) & (1 << j)) - { - grub_uint8_t code = map_code[i][j]; - int ret; - grub_uint8_t brk = 0; - if (!(scan.data[i] & (1 << j))) - brk = 0x80; - grub_dprintf ("cros_keyboard", "key <%d, %d> code %x\n", i, j, code); - if (code < 0x60) - ret = grub_ps2_process_incoming_byte (&ps2_state, code | brk); - else if (code >= 0x60 && code < 0x70 && e0_translate[code - 0x60]) - { - grub_ps2_process_incoming_byte (&ps2_state, 0xe0); - ret = grub_ps2_process_incoming_byte (&ps2_state, e0_translate[code - 0x60] | brk); - } - else - ret = GRUB_TERM_NO_KEY; - old_scan.data[i] ^= (1 << j); - if (ret != GRUB_TERM_NO_KEY) - return ret; - } - return GRUB_TERM_NO_KEY; -} - -static struct grub_term_input grub_cros_keyboard_term = - { - .name = "cros_keyboard", - .getkey = grub_cros_keyboard_getkey - }; - -static grub_err_t -cros_attach (const struct grub_fdtbus_dev *dev) -{ - grub_size_t keymap_size, i; - const grub_uint8_t *keymap = grub_fdtbus_get_prop (dev, "linux,keymap", &keymap_size); - - if (!dev->parent || !grub_cros_ec_validate (dev->parent)) - return GRUB_ERR_IO; - - if (keymap) - { - for (i = 0; i + 3 < keymap_size; i += 4) - if (keymap[i+1] < GRUB_CROS_EC_KEYSCAN_COLS && keymap[i] < GRUB_CROS_EC_KEYSCAN_ROWS - && keymap[i+2] == 0 && keymap[i+3] < 0x80) - map_code[keymap[i+1]][keymap[i]] = keymap[i+3]; - } - - cros_ec = dev->parent; - ps2_state.current_set = 1; - ps2_state.at_keyboard_status = 0; - grub_term_register_input ("cros_keyboard", &grub_cros_keyboard_term); - return GRUB_ERR_NONE; -} - -static struct grub_fdtbus_driver cros = -{ - .compatible = "google,cros-ec-keyb", - .attach = cros_attach -}; - -void -grub_cros_init (void) -{ - grub_fdtbus_register (&cros); -} diff --git a/grub-core/term/arm/cros_ec.c b/grub-core/term/arm/cros_ec.c deleted file mode 100644 index f4144818b..000000000 --- a/grub-core/term/arm/cros_ec.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * - * Copyright (C) 2012 Google Inc. - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * This is based on depthcharge code. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -static const grub_uint64_t FRAMING_TIMEOUT_MS = 300; - -static const grub_uint8_t EC_FRAMING_BYTE = 0xec; - -#define EC_CMD_MKBP_STATE 0x60 -#define EC_CMD_VERSION0 0xdc - -static grub_uint64_t last_transfer; - -static void -stop_bus (const struct grub_fdtbus_dev *spi) -{ - spi->driver->stop (spi); - last_transfer = grub_get_time_ms (); -} - -static int -wait_for_frame (const struct grub_fdtbus_dev *spi) -{ - grub_uint64_t start = grub_get_time_ms (); - grub_uint8_t byte; - do - { - if (spi->driver->receive (spi, &byte, 1)) - return -1; - if (byte != EC_FRAMING_BYTE && - grub_get_time_ms () - start > FRAMING_TIMEOUT_MS) - { - grub_dprintf ("cros", "Timeout waiting for framing byte.\n"); - return -1; - } - } - while (byte != EC_FRAMING_BYTE); - return 0; -} - -/* - * Calculate a simple 8-bit checksum of a data block - * - * @param data Data block to checksum - * @param size Size of data block in bytes - * @return checksum value (0 to 255) - */ -static grub_uint8_t -cros_ec_calc_checksum (const void *data, int size) -{ - grub_uint8_t csum; - const grub_uint8_t *bytes = data; - int i; - - for (i = csum = 0; i < size; i++) - csum += bytes[i]; - return csum & 0xff; -} - -enum -{ - /* response, arglen */ - CROS_EC_SPI_IN_HDR_SIZE = 2, - /* version, cmd, arglen */ - CROS_EC_SPI_OUT_HDR_SIZE = 3 -}; - -static grub_uint8_t busbuf[256]; -#define MSG_BYTES ((int)sizeof (busbuf)) - -static int -ec_command (const struct grub_fdtbus_dev *dev, int cmd, int cmd_version, - const void *dout, int dout_len, void *din, int din_len) -{ - const struct grub_fdtbus_dev *spi = dev->parent; - grub_uint8_t *bytes; - - /* Header + data + checksum. */ - grub_uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1; - grub_uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1; - - /* - * Sanity-check I/O sizes given transaction overhead in internal - * buffers. - */ - if (out_bytes > MSG_BYTES) - { - grub_dprintf ("cros", "Cannot send %d bytes\n", dout_len); - return -1; - } - if (in_bytes > MSG_BYTES) - { - grub_dprintf ("cros", "Cannot receive %d bytes\n", din_len); - return -1; - } - - /* Prepare the output. */ - bytes = busbuf; - *bytes++ = EC_CMD_VERSION0 + cmd_version; - *bytes++ = cmd; - *bytes++ = dout_len; - grub_memcpy (bytes, dout, dout_len); - bytes += dout_len; - - *bytes++ = cros_ec_calc_checksum (busbuf, - CROS_EC_SPI_OUT_HDR_SIZE + dout_len); - - /* Depthcharge uses 200 us here but GRUB timer resolution is only 1ms, - decrease this when we increase timer resolution. */ - while (grub_get_time_ms () - last_transfer < 1) - ; - - if (spi->driver->start (spi)) - return -1; - - /* Allow EC to ramp up clock after being awoken. */ - /* Depthcharge only waits 100 us here but GRUB timer resolution is only 1ms, - decrease this when we increase timer resolution. */ - grub_millisleep (1); - - if (spi->driver->send (spi, busbuf, out_bytes)) - { - stop_bus (spi); - return -1; - } - - /* Wait until the EC is ready. */ - if (wait_for_frame (spi)) - { - stop_bus (spi); - return -1; - } - - /* Read the response code and the data length. */ - bytes = busbuf; - if (spi->driver->receive (spi, bytes, 2)) - { - stop_bus (spi); - return -1; - } - grub_uint8_t result = *bytes++; - grub_uint8_t length = *bytes++; - - /* Make sure there's enough room for the data. */ - if (CROS_EC_SPI_IN_HDR_SIZE + length + 1 > MSG_BYTES) - { - grub_dprintf ("cros", "Received length %#02x too large\n", length); - stop_bus (spi); - return -1; - } - - /* Read the data and the checksum, and finish up. */ - if (spi->driver->receive (spi, bytes, length + 1)) - { - stop_bus (spi); - return -1; - } - bytes += length; - int expected = *bytes++; - stop_bus (spi); - - /* Check the integrity of the response. */ - if (result != 0) - { - grub_dprintf ("cros", "Received bad result code %d\n", result); - return -result; - } - - int csum = cros_ec_calc_checksum (busbuf, - CROS_EC_SPI_IN_HDR_SIZE + length); - - if (csum != expected) - { - grub_dprintf ("cros", "Invalid checksum rx %#02x, calced %#02x\n", - expected, csum); - return -1; - } - - /* If the caller wants the response, copy it out for them. */ - if (length < din_len) - din_len = length; - if (din) - { - grub_memcpy (din, (grub_uint8_t *) busbuf + CROS_EC_SPI_IN_HDR_SIZE, din_len); - } - - return din_len; -} - -int -grub_cros_ec_scan_keyboard (const struct grub_fdtbus_dev *dev, struct grub_cros_ec_keyscan *scan) -{ - if (ec_command (dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan, - sizeof (*scan)) < (int) sizeof (*scan)) - return -1; - - return 0; -} - -int -grub_cros_ec_validate (const struct grub_fdtbus_dev *dev) -{ - if (!grub_fdtbus_is_compatible("google,cros-ec-spi", dev)) - return 0; - if (!dev->parent) - return 0; - if (!dev->parent->driver) - return 0; - if (!dev->parent->driver->send - || !dev->parent->driver->receive) - return 0; - return 1; -} - diff --git a/grub-core/term/arm/pl050.c b/grub-core/term/arm/pl050.c deleted file mode 100644 index e4cda3056..000000000 --- a/grub-core/term/arm/pl050.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static volatile grub_uint32_t *pl050_regs; - -struct grub_ps2_state ps2_state; - -static void -keyboard_controller_wait_until_ready (void) -{ - while (! (pl050_regs[1] & 0x40)); -} - -static grub_uint8_t -wait_ack (void) -{ - grub_uint64_t endtime; - grub_uint8_t ack; - - endtime = grub_get_time_ms () + 20; - do - ack = pl050_regs[2]; - while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK - && grub_get_time_ms () < endtime); - return ack; -} - - -static int -write_mode (int mode) -{ - unsigned i; - for (i = 0; i < GRUB_AT_TRIES; i++) - { - grub_uint8_t ack; - keyboard_controller_wait_until_ready (); - pl050_regs[2] = 0xf0; - keyboard_controller_wait_until_ready (); - pl050_regs[2] = mode; - keyboard_controller_wait_until_ready (); - ack = wait_ack (); - if (ack == GRUB_AT_NACK) - continue; - if (ack == GRUB_AT_ACK) - break; - return 0; - } - - return (i != GRUB_AT_TRIES); -} - -static int -query_mode (void) -{ - grub_uint8_t ret; - int e; - - e = write_mode (0); - if (!e) - return 0; - - keyboard_controller_wait_until_ready (); - - do - ret = pl050_regs[2]; - while (ret == GRUB_AT_ACK); - - /* QEMU translates the set even in no-translate mode. */ - if (ret == 0x43 || ret == 1) - return 1; - if (ret == 0x41 || ret == 2) - return 2; - if (ret == 0x3f || ret == 3) - return 3; - return 0; -} - -static void -set_scancodes (void) -{ - write_mode (2); - ps2_state.current_set = query_mode (); - grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set); - if (ps2_state.current_set == 2) - return; - - write_mode (1); - ps2_state.current_set = query_mode (); - grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set); - if (ps2_state.current_set == 1) - return; - grub_dprintf ("atkeyb", "no supported scancode set found\n"); -} - -static void -keyboard_controller_led (grub_uint8_t leds) -{ - keyboard_controller_wait_until_ready (); - pl050_regs[2] = 0xed; - keyboard_controller_wait_until_ready (); - pl050_regs[2] = leds & 0x7; -} - -/* If there is a character pending, return it; - otherwise return GRUB_TERM_NO_KEY. */ -static int -grub_pl050_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) -{ - grub_uint8_t at_key; - int ret; - grub_uint8_t old_led; - - if (!(pl050_regs[1] & 0x10)) - return -1; - at_key = pl050_regs[2]; - old_led = ps2_state.led_status; - - ret = grub_ps2_process_incoming_byte (&ps2_state, at_key); - if (old_led != ps2_state.led_status) - keyboard_controller_led (ps2_state.led_status); - return ret; -} - -static struct grub_term_input grub_pl050_keyboard_term = - { - .name = "pl050_keyboard", - .getkey = grub_pl050_keyboard_getkey - }; - -static grub_err_t -pl050_attach(const struct grub_fdtbus_dev *dev) -{ - const grub_uint32_t *reg; - reg = grub_fdtbus_get_prop (dev, "reg", 0); - - /* Mouse. Nothing to do. */ - if (grub_be_to_cpu32 (*reg) == 0x7000) - return 0; - - pl050_regs = grub_fdtbus_map_reg (dev, 0, 0); - - if (!grub_fdtbus_is_mapping_valid (pl050_regs)) - return grub_error (GRUB_ERR_IO, "could not map pl050"); - - ps2_state.at_keyboard_status = 0; - set_scancodes (); - keyboard_controller_led (ps2_state.led_status); - - grub_term_register_input ("pl050_keyboard", &grub_pl050_keyboard_term); - return GRUB_ERR_NONE; -} - -struct grub_fdtbus_driver pl050 = -{ - .compatible = "arm,pl050", - .attach = pl050_attach -}; - -void -grub_pl050_init (void) -{ - grub_fdtbus_register (&pl050); -} diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 597111077..c234e92f2 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -22,26 +22,215 @@ #include #include #include +#include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); +static short at_keyboard_status = 0; +static int e0_received = 0; +static int f0_received = 0; + +static grub_uint8_t led_status; + +#define KEYBOARD_LED_SCROLL (1 << 0) +#define KEYBOARD_LED_NUM (1 << 1) +#define KEYBOARD_LED_CAPS (1 << 2) + static grub_uint8_t grub_keyboard_controller_orig; static grub_uint8_t grub_keyboard_orig_set; -struct grub_ps2_state ps2_state; - -static int ping_sent; +static grub_uint8_t current_set; static void grub_keyboard_controller_init (void); +static const grub_uint8_t set1_mapping[128] = + { + /* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE, + /* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2, + /* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4, + /* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6, + /* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8, + /* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0, + /* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL, + /* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB, + /* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W, + /* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R, + /* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y, + /* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I, + /* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P, + /* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET, + /* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL, + /* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S, + /* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F, + /* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H, + /* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K, + /* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON, + /* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE, + /* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH, + /* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X, + /* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V, + /* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N, + /* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA, + /* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH, + /* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL, + /* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE, + /* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1, + /* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3, + /* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5, + /* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7, + /* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9, + /* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK, + /* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7, + /* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9, + /* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4, + /* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6, + /* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1, + /* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3, + /* 0x52 */ GRUB_KEYBOARD_KEY_NUMDOT, GRUB_KEYBOARD_KEY_NUMDOT, + /* 0x54 */ 0, 0, + /* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11, + /* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0, + /* 0x5a */ 0, 0, + /* 0x5c */ 0, 0, + /* 0x5e */ 0, 0, + /* 0x60 */ 0, 0, + /* 0x62 */ 0, 0, + /* OLPC keys. Just mapped to normal keys. */ + /* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP, + /* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT, + /* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0, + /* 0x6a */ 0, 0, + /* 0x6c */ 0, 0, + /* 0x6e */ 0, 0, + /* 0x70 */ 0, 0, + /* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO, + /* 0x74 */ 0, 0, + /* 0x76 */ 0, 0, + /* 0x78 */ 0, 0, + /* 0x7a */ 0, 0, + /* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN, + /* 0x7e */ GRUB_KEYBOARD_KEY_KPCOMMA + }; + +static const struct +{ + grub_uint8_t from, to; +} set1_e0_mapping[] = + { + {0x1c, GRUB_KEYBOARD_KEY_NUMENTER}, + {0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL}, + {0x35, GRUB_KEYBOARD_KEY_NUMSLASH }, + {0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT}, + {0x47, GRUB_KEYBOARD_KEY_HOME}, + {0x48, GRUB_KEYBOARD_KEY_UP}, + {0x49, GRUB_KEYBOARD_KEY_PPAGE}, + {0x4b, GRUB_KEYBOARD_KEY_LEFT}, + {0x4d, GRUB_KEYBOARD_KEY_RIGHT}, + {0x4f, GRUB_KEYBOARD_KEY_END}, + {0x50, GRUB_KEYBOARD_KEY_DOWN}, + {0x51, GRUB_KEYBOARD_KEY_NPAGE}, + {0x52, GRUB_KEYBOARD_KEY_INSERT}, + {0x53, GRUB_KEYBOARD_KEY_DELETE}, + }; + +static const grub_uint8_t set2_mapping[256] = + { + /* 0x00 */ 0, GRUB_KEYBOARD_KEY_F9, + /* 0x02 */ 0, GRUB_KEYBOARD_KEY_F5, + /* 0x04 */ GRUB_KEYBOARD_KEY_F3, GRUB_KEYBOARD_KEY_F1, + /* 0x06 */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F12, + /* 0x08 */ 0, GRUB_KEYBOARD_KEY_F10, + /* 0x0a */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F6, + /* 0x0c */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_TAB, + /* 0x0e */ GRUB_KEYBOARD_KEY_RQUOTE, 0, + /* 0x10 */ 0, GRUB_KEYBOARD_KEY_LEFT_ALT, + /* 0x12 */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, 0, + /* 0x14 */ GRUB_KEYBOARD_KEY_LEFT_CTRL, GRUB_KEYBOARD_KEY_Q, + /* 0x16 */ GRUB_KEYBOARD_KEY_1, 0, + /* 0x18 */ 0, 0, + /* 0x1a */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_S, + /* 0x1c */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_W, + /* 0x1e */ GRUB_KEYBOARD_KEY_2, 0, + /* 0x20 */ 0, GRUB_KEYBOARD_KEY_C, + /* 0x22 */ GRUB_KEYBOARD_KEY_X, GRUB_KEYBOARD_KEY_D, + /* 0x24 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_4, + /* 0x26 */ GRUB_KEYBOARD_KEY_3, 0, + /* 0x28 */ 0, GRUB_KEYBOARD_KEY_SPACE, + /* 0x2a */ GRUB_KEYBOARD_KEY_V, GRUB_KEYBOARD_KEY_F, + /* 0x2c */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_R, + /* 0x2e */ GRUB_KEYBOARD_KEY_5, 0, + /* 0x30 */ 0, GRUB_KEYBOARD_KEY_N, + /* 0x32 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_H, + /* 0x34 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_Y, + /* 0x36 */ GRUB_KEYBOARD_KEY_6, 0, + /* 0x38 */ 0, 0, + /* 0x3a */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_J, + /* 0x3c */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_7, + /* 0x3e */ GRUB_KEYBOARD_KEY_8, 0, + /* 0x40 */ 0, GRUB_KEYBOARD_KEY_COMMA, + /* 0x42 */ GRUB_KEYBOARD_KEY_K, GRUB_KEYBOARD_KEY_I, + /* 0x44 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_0, + /* 0x46 */ GRUB_KEYBOARD_KEY_9, 0, + /* 0x48 */ 0, GRUB_KEYBOARD_KEY_DOT, + /* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L, + /* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P, + /* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0, + /* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO, + /* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0, + /* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL, + /* 0x56 */ 0, 0, + /* 0x58 */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_RIGHT_SHIFT, + /* 0x5a */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_RBRACKET, + /* 0x5c */ 0, GRUB_KEYBOARD_KEY_BACKSLASH, + /* 0x5e */ 0, 0, + /* 0x60 */ 0, GRUB_KEYBOARD_KEY_102ND, + /* 0x62 */ 0, 0, + /* 0x64 */ 0, 0, + /* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0, + /* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1, + /* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4, + /* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, GRUB_KEYBOARD_KEY_KPCOMMA, + /* 0x6e */ 0, 0, + /* 0x70 */ GRUB_KEYBOARD_KEY_NUMDOT, GRUB_KEYBOARD_KEY_NUM0, + /* 0x72 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM5, + /* 0x74 */ GRUB_KEYBOARD_KEY_NUM6, GRUB_KEYBOARD_KEY_NUM8, + /* 0x76 */ GRUB_KEYBOARD_KEY_ESCAPE, GRUB_KEYBOARD_KEY_NUM_LOCK, + /* 0x78 */ GRUB_KEYBOARD_KEY_F11, GRUB_KEYBOARD_KEY_NUMPLUS, + /* 0x7a */ GRUB_KEYBOARD_KEY_NUM3, GRUB_KEYBOARD_KEY_NUMMINUS, + /* 0x7c */ GRUB_KEYBOARD_KEY_NUMMUL, GRUB_KEYBOARD_KEY_NUM9, + /* 0x7e */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, 0, + /* 0x80 */ 0, 0, + /* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7, + }; + +static const struct +{ + grub_uint8_t from, to; +} set2_e0_mapping[] = + { + {0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT}, + {0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL}, + {0x4a, GRUB_KEYBOARD_KEY_NUMSLASH}, + {0x5a, GRUB_KEYBOARD_KEY_NUMENTER}, + {0x69, GRUB_KEYBOARD_KEY_END}, + {0x6b, GRUB_KEYBOARD_KEY_LEFT}, + {0x6c, GRUB_KEYBOARD_KEY_HOME}, + {0x70, GRUB_KEYBOARD_KEY_INSERT}, + {0x71, GRUB_KEYBOARD_KEY_DELETE}, + {0x72, GRUB_KEYBOARD_KEY_DOWN}, + {0x74, GRUB_KEYBOARD_KEY_RIGHT}, + {0x75, GRUB_KEYBOARD_KEY_UP}, + {0x7a, GRUB_KEYBOARD_KEY_NPAGE}, + {0x7d, GRUB_KEYBOARD_KEY_PPAGE}, + }; + +static int ping_sent; + static void keyboard_controller_wait_until_ready (void) { - /* 50 us would be enough but our current time resolution is 1ms. */ - grub_millisleep (1); while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))); } @@ -52,11 +241,10 @@ wait_ack (void) grub_uint8_t ack; endtime = grub_get_time_ms () + 20; - do { - keyboard_controller_wait_until_ready (); + do ack = grub_inb (KEYBOARD_REG_DATA); - } while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK - && grub_get_time_ms () < endtime); + while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK + && grub_get_time_ms () < endtime); return ack; } @@ -138,10 +326,12 @@ query_mode (void) if (!e) return 0; - do { - keyboard_controller_wait_until_ready (); + keyboard_controller_wait_until_ready (); + + do ret = grub_inb (KEYBOARD_REG_DATA); - } while (ret == GRUB_AT_ACK); + while (ret == GRUB_AT_ACK); + /* QEMU translates the set even in no-translate mode. */ if (ret == 0x43 || ret == 1) return 1; @@ -160,32 +350,28 @@ set_scancodes (void) if (!grub_keyboard_orig_set) { grub_dprintf ("atkeyb", "No sets support assumed\n"); - ps2_state.current_set = 1; + current_set = 1; return; } #if !USE_SCANCODE_SET - ps2_state.current_set = 1; + current_set = 1; return; #else grub_keyboard_controller_write (grub_keyboard_controller_orig - & ~KEYBOARD_AT_TRANSLATE - & ~KEYBOARD_AT_DISABLE); - - keyboard_controller_wait_until_ready (); - grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA); + & ~KEYBOARD_AT_TRANSLATE); write_mode (2); - ps2_state.current_set = query_mode (); - grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set); - if (ps2_state.current_set == 2) + current_set = query_mode (); + grub_dprintf ("atkeyb", "returned set %d\n", current_set); + if (current_set == 2) return; write_mode (1); - ps2_state.current_set = query_mode (); - grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set); - if (ps2_state.current_set == 1) + current_set = query_mode (); + grub_dprintf ("atkeyb", "returned set %d\n", current_set); + if (current_set == 1) return; grub_dprintf ("atkeyb", "no supported scancode set found\n"); #endif @@ -200,10 +386,164 @@ keyboard_controller_led (grub_uint8_t leds) grub_outb (leds & 0x7, KEYBOARD_REG_DATA); } +static int +fetch_key (int *is_break) +{ + int was_ext = 0; + grub_uint8_t at_key; + int ret = 0; + + if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS))) + return -1; + at_key = grub_inb (KEYBOARD_REG_DATA); + /* May happen if no keyboard is connected. Just ignore this. */ + if (at_key == 0xff) + return -1; + if (at_key == 0xe0) + { + e0_received = 1; + return -1; + } + + if ((current_set == 2 || current_set == 3) && at_key == 0xf0) + { + f0_received = 1; + return -1; + } + + /* Setting LEDs may generate ACKs. */ + if (at_key == GRUB_AT_ACK) + return -1; + + was_ext = e0_received; + e0_received = 0; + + switch (current_set) + { + case 1: + *is_break = !!(at_key & 0x80); + if (!was_ext) + ret = set1_mapping[at_key & 0x7f]; + else + { + unsigned i; + for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++) + if (set1_e0_mapping[i].from == (at_key & 0x7f)) + { + ret = set1_e0_mapping[i].to; + break; + } + } + break; + case 2: + *is_break = f0_received; + f0_received = 0; + if (!was_ext) + ret = set2_mapping[at_key]; + else + { + unsigned i; + for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++) + if (set2_e0_mapping[i].from == at_key) + { + ret = set2_e0_mapping[i].to; + break; + } + } + break; + default: + return -1; + } + if (!ret) + { + if (was_ext) + grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n", + at_key, current_set); + else + grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n", + at_key, current_set); + return -1; + } + return ret; +} + +/* FIXME: This should become an interrupt service routine. For now + it's just used to catch events from control keys. */ +static int +grub_keyboard_isr (grub_keyboard_key_t key, int is_break) +{ + if (!is_break) + switch (key) + { + case GRUB_KEYBOARD_KEY_LEFT_SHIFT: + at_keyboard_status |= GRUB_TERM_STATUS_LSHIFT; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_SHIFT: + at_keyboard_status |= GRUB_TERM_STATUS_RSHIFT; + return 1; + case GRUB_KEYBOARD_KEY_LEFT_CTRL: + at_keyboard_status |= GRUB_TERM_STATUS_LCTRL; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_CTRL: + at_keyboard_status |= GRUB_TERM_STATUS_RCTRL; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_ALT: + at_keyboard_status |= GRUB_TERM_STATUS_RALT; + return 1; + case GRUB_KEYBOARD_KEY_LEFT_ALT: + at_keyboard_status |= GRUB_TERM_STATUS_LALT; + return 1; + default: + return 0; + } + else + switch (key) + { + case GRUB_KEYBOARD_KEY_LEFT_SHIFT: + at_keyboard_status &= ~GRUB_TERM_STATUS_LSHIFT; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_SHIFT: + at_keyboard_status &= ~GRUB_TERM_STATUS_RSHIFT; + return 1; + case GRUB_KEYBOARD_KEY_LEFT_CTRL: + at_keyboard_status &= ~GRUB_TERM_STATUS_LCTRL; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_CTRL: + at_keyboard_status &= ~GRUB_TERM_STATUS_RCTRL; + return 1; + case GRUB_KEYBOARD_KEY_RIGHT_ALT: + at_keyboard_status &= ~GRUB_TERM_STATUS_RALT; + return 1; + case GRUB_KEYBOARD_KEY_LEFT_ALT: + at_keyboard_status &= ~GRUB_TERM_STATUS_LALT; + return 1; + default: + return 0; + } +} + +/* If there is a raw key pending, return it; otherwise return -1. */ +static int +grub_keyboard_getkey (void) +{ + int key; + int is_break = 0; + + key = fetch_key (&is_break); + if (key == -1) + return -1; + + if (grub_keyboard_isr (key, is_break)) + return -1; + if (is_break) + return -1; + return key; +} + int grub_at_keyboard_is_alive (void) { - if (ps2_state.current_set != 0) + if (current_set != 0) return 1; if (ping_sent && KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)) @@ -226,28 +566,51 @@ grub_at_keyboard_is_alive (void) static int grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))) { - grub_uint8_t at_key; - int ret; - grub_uint8_t old_led; + int code; if (!grub_at_keyboard_is_alive ()) return GRUB_TERM_NO_KEY; - if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS))) + code = grub_keyboard_getkey (); + if (code == -1) return GRUB_TERM_NO_KEY; - at_key = grub_inb (KEYBOARD_REG_DATA); - old_led = ps2_state.led_status; +#ifdef DEBUG_AT_KEYBOARD + grub_dprintf ("atkeyb", "Detected key 0x%x\n", code); +#endif + switch (code) + { + case GRUB_KEYBOARD_KEY_CAPS_LOCK: + at_keyboard_status ^= GRUB_TERM_STATUS_CAPS; + led_status ^= KEYBOARD_LED_CAPS; + keyboard_controller_led (led_status); - ret = grub_ps2_process_incoming_byte (&ps2_state, at_key); - if (old_led != ps2_state.led_status) - keyboard_controller_led (ps2_state.led_status); - return ret; +#ifdef DEBUG_AT_KEYBOARD + grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & GRUB_KEYBOARD_STATUS_CAPS_LOCK)); +#endif + return GRUB_TERM_NO_KEY; + case GRUB_KEYBOARD_KEY_NUM_LOCK: + at_keyboard_status ^= GRUB_TERM_STATUS_NUM; + led_status ^= KEYBOARD_LED_NUM; + keyboard_controller_led (led_status); + +#ifdef DEBUG_AT_KEYBOARD + grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & GRUB_KEYBOARD_STATUS_NUM_LOCK)); +#endif + return GRUB_TERM_NO_KEY; + case GRUB_KEYBOARD_KEY_SCROLL_LOCK: + at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL; + led_status ^= KEYBOARD_LED_SCROLL; + keyboard_controller_led (led_status); + return GRUB_TERM_NO_KEY; + default: + return grub_term_map_key (code, at_keyboard_status); + } } static void grub_keyboard_controller_init (void) { - ps2_state.at_keyboard_status = 0; + at_keyboard_status = 0; /* Drain input buffer. */ while (1) { @@ -269,13 +632,13 @@ grub_keyboard_controller_init (void) grub_keyboard_orig_set = query_mode (); #endif set_scancodes (); - keyboard_controller_led (ps2_state.led_status); + keyboard_controller_led (led_status); } static grub_err_t grub_keyboard_controller_fini (struct grub_term_input *term __attribute__ ((unused))) { - if (ps2_state.current_set == 0) + if (current_set == 0) return GRUB_ERR_NONE; if (grub_keyboard_orig_set) write_mode (grub_keyboard_orig_set); @@ -292,7 +655,7 @@ grub_at_fini_hw (int noreturn __attribute__ ((unused))) static grub_err_t grub_at_restore_hw (void) { - if (ps2_state.current_set == 0) + if (current_set == 0) return GRUB_ERR_NONE; /* Drain input buffer. */ @@ -305,7 +668,7 @@ grub_at_restore_hw (void) grub_inb (KEYBOARD_REG_DATA); } set_scancodes (); - keyboard_controller_led (ps2_state.led_status); + keyboard_controller_led (led_status); return GRUB_ERR_NONE; } diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c index 2f1ae85ba..a37eb841c 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -24,16 +24,6 @@ #include #include -typedef enum { - GRUB_TEXT_MODE_UNDEFINED = -1, - GRUB_TEXT_MODE_UNAVAILABLE = 0, - GRUB_TEXT_MODE_AVAILABLE -} -grub_text_mode; - -static grub_text_mode text_mode = GRUB_TEXT_MODE_UNDEFINED; -static grub_term_color_state text_colorstate = GRUB_TERM_COLOR_UNDEFINED; - static grub_uint32_t map_char (grub_uint32_t c) { @@ -75,6 +65,142 @@ map_char (grub_uint32_t c) return c; } +static void +grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)), + const struct grub_unicode_glyph *c) +{ + grub_efi_char16_t str[2 + 30]; + grub_efi_simple_text_output_interface_t *o; + unsigned i, j; + + if (grub_efi_is_finished) + return; + + o = grub_efi_system_table->con_out; + + /* For now, do not try to use a surrogate pair. */ + if (c->base > 0xffff) + str[0] = '?'; + else + str[0] = (grub_efi_char16_t) map_char (c->base & 0xffff); + j = 1; + for (i = 0; i < c->ncomb && j + 1 < ARRAY_SIZE (str); i++) + if (c->base < 0xffff) + str[j++] = grub_unicode_get_comb (c)[i].code; + str[j] = 0; + + /* Should this test be cached? */ + if ((c->base > 0x7f || c->ncomb) + && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS) + return; + + efi_call_2 (o->output_string, o, str); +} + +const unsigned efi_codes[] = + { + 0, GRUB_TERM_KEY_UP, GRUB_TERM_KEY_DOWN, GRUB_TERM_KEY_RIGHT, + GRUB_TERM_KEY_LEFT, GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END, GRUB_TERM_KEY_INSERT, + GRUB_TERM_KEY_DC, GRUB_TERM_KEY_PPAGE, GRUB_TERM_KEY_NPAGE, GRUB_TERM_KEY_F1, + GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3, GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, + GRUB_TERM_KEY_F6, GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9, + GRUB_TERM_KEY_F10, 0, 0, '\e' + }; + + +static int +grub_console_getkey (struct grub_term_input *term __attribute__ ((unused))) +{ + grub_efi_simple_input_interface_t *i; + grub_efi_input_key_t key; + grub_efi_status_t status; + + if (grub_efi_is_finished) + return 0; + + i = grub_efi_system_table->con_in; + status = efi_call_2 (i->read_key_stroke, i, &key); + + if (status != GRUB_EFI_SUCCESS) + return GRUB_TERM_NO_KEY; + + if (key.scan_code == 0) + { + /* Some firmware implementations use VT100-style codes against the spec. + This is especially likely if driven by serial. + */ + if (key.unicode_char < 0x20 && key.unicode_char != 0 + && key.unicode_char != '\t' && key.unicode_char != '\b' + && key.unicode_char != '\n' && key.unicode_char != '\r') + return GRUB_TERM_CTRL | (key.unicode_char - 1 + 'a'); + else + return key.unicode_char; + } + else if (key.scan_code < ARRAY_SIZE (efi_codes)) + return efi_codes[key.scan_code]; + + return GRUB_TERM_NO_KEY; +} + +static struct grub_term_coordinate +grub_console_getwh (struct grub_term_output *term __attribute__ ((unused))) +{ + grub_efi_simple_text_output_interface_t *o; + grub_efi_uintn_t columns, rows; + + o = grub_efi_system_table->con_out; + if (grub_efi_is_finished || efi_call_4 (o->query_mode, o, o->mode->mode, + &columns, &rows) != GRUB_EFI_SUCCESS) + { + /* Why does this fail? */ + columns = 80; + rows = 25; + } + + return (struct grub_term_coordinate) { columns, rows }; +} + +static struct grub_term_coordinate +grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) +{ + grub_efi_simple_text_output_interface_t *o; + + if (grub_efi_is_finished) + return (struct grub_term_coordinate) { 0, 0 }; + + o = grub_efi_system_table->con_out; + return (struct grub_term_coordinate) { o->mode->cursor_column, o->mode->cursor_row }; +} + +static void +grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)), + struct grub_term_coordinate pos) +{ + grub_efi_simple_text_output_interface_t *o; + + if (grub_efi_is_finished) + return; + + o = grub_efi_system_table->con_out; + efi_call_3 (o->set_cursor_position, o, pos.x, pos.y); +} + +static void +grub_console_cls (struct grub_term_output *term __attribute__ ((unused))) +{ + grub_efi_simple_text_output_interface_t *o; + grub_efi_int32_t orig_attr; + + if (grub_efi_is_finished) + return; + + o = grub_efi_system_table->con_out; + orig_attr = o->mode->attribute; + efi_call_2 (o->set_attributes, o, GRUB_EFI_BACKGROUND_BLACK); + efi_call_1 (o->clear_screen, o); + efi_call_2 (o->set_attributes, o, orig_attr); +} + static void grub_console_setcolorstate (struct grub_term_output *term __attribute__ ((unused)), @@ -117,318 +243,18 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), } static grub_err_t -grub_prepare_for_text_output (struct grub_term_output *term) +grub_efi_console_init (struct grub_term_output *term) { - if (grub_efi_is_finished) - return GRUB_ERR_BAD_DEVICE; - - if (text_mode != GRUB_TEXT_MODE_UNDEFINED) - return text_mode ? GRUB_ERR_NONE : GRUB_ERR_BAD_DEVICE; - - if (! grub_efi_set_text_mode (1)) - { - /* This really should never happen */ - grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); - text_mode = GRUB_TEXT_MODE_UNAVAILABLE; - return GRUB_ERR_BAD_DEVICE; - } - + grub_efi_set_text_mode (1); grub_console_setcursor (term, 1); - if (text_colorstate != GRUB_TERM_COLOR_UNDEFINED) - grub_console_setcolorstate (term, text_colorstate); - text_mode = GRUB_TEXT_MODE_AVAILABLE; - return GRUB_ERR_NONE; -} - -static void -grub_console_putchar (struct grub_term_output *term, - const struct grub_unicode_glyph *c) -{ - grub_efi_char16_t str[2 + 30]; - grub_efi_simple_text_output_interface_t *o; - unsigned i, j; - - if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE) - return; - - o = grub_efi_system_table->con_out; - - /* For now, do not try to use a surrogate pair. */ - if (c->base > 0xffff) - str[0] = '?'; - else - str[0] = (grub_efi_char16_t) map_char (c->base & 0xffff); - j = 1; - for (i = 0; i < c->ncomb && j + 1 < ARRAY_SIZE (str); i++) - if (c->base < 0xffff) - str[j++] = grub_unicode_get_comb (c)[i].code; - str[j] = 0; - - /* Should this test be cached? */ - if ((c->base > 0x7f || c->ncomb) - && efi_call_2 (o->test_string, o, str) != GRUB_EFI_SUCCESS) - return; - - efi_call_2 (o->output_string, o, str); -} - -const unsigned efi_codes[] = - { - 0, GRUB_TERM_KEY_UP, GRUB_TERM_KEY_DOWN, GRUB_TERM_KEY_RIGHT, - GRUB_TERM_KEY_LEFT, GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END, GRUB_TERM_KEY_INSERT, - GRUB_TERM_KEY_DC, GRUB_TERM_KEY_PPAGE, GRUB_TERM_KEY_NPAGE, GRUB_TERM_KEY_F1, - GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3, GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, - GRUB_TERM_KEY_F6, GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9, - GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12, GRUB_TERM_ESC - }; - -static int -grub_efi_translate_key (grub_efi_input_key_t key) -{ - if (key.scan_code == 0) - { - /* Some firmware implementations use VT100-style codes against the spec. - This is especially likely if driven by serial. - */ - if (key.unicode_char < 0x20 && key.unicode_char != 0 - && key.unicode_char != '\t' && key.unicode_char != '\b' - && key.unicode_char != '\n' && key.unicode_char != '\r') - return GRUB_TERM_CTRL | (key.unicode_char - 1 + 'a'); - else - return key.unicode_char; - } - /* Some devices send enter with scan_code 0x0d (F3) and unicode_char 0x0d. */ - else if (key.scan_code == '\r' && key.unicode_char == '\r') - return key.unicode_char; - else if (key.scan_code < ARRAY_SIZE (efi_codes)) - return efi_codes[key.scan_code]; - - if ((key.unicode_char >= 0x20 && key.unicode_char <= 0x7f) - || key.unicode_char == '\t' || key.unicode_char == '\b' - || key.unicode_char == '\n' || key.unicode_char == '\r') - return key.unicode_char; - - return GRUB_TERM_NO_KEY; -} - -static int -grub_console_getkey_con (struct grub_term_input *term __attribute__ ((unused))) -{ - grub_efi_simple_input_interface_t *i; - grub_efi_input_key_t key; - grub_efi_status_t status; - - i = grub_efi_system_table->con_in; - status = efi_call_2 (i->read_key_stroke, i, &key); - - if (status != GRUB_EFI_SUCCESS) - return GRUB_TERM_NO_KEY; - - return grub_efi_translate_key(key); -} - -/* - * When more then just modifiers are pressed, our getkeystatus() consumes a - * press from the queue, this function buffers the press for the regular - * getkey() so that it does not get lost. - */ -static grub_err_t -grub_console_read_key_stroke ( - grub_efi_simple_text_input_ex_interface_t *text_input, - grub_efi_key_data_t *key_data_ret, int *key_ret, - int consume) -{ - static grub_efi_key_data_t key_data; - grub_efi_status_t status; - int key; - - if (!text_input) - return GRUB_ERR_EOF; - - key = grub_efi_translate_key (key_data.key); - if (key == GRUB_TERM_NO_KEY) { - status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data); - if (status != GRUB_EFI_SUCCESS) - return GRUB_ERR_EOF; - - key = grub_efi_translate_key (key_data.key); - } - - *key_data_ret = key_data; - *key_ret = key; - - if (consume) { - key_data.key.scan_code = 0; - key_data.key.unicode_char = 0; - } - - return GRUB_ERR_NONE; -} - -static int -grub_console_getkey_ex (struct grub_term_input *term) -{ - grub_efi_key_data_t key_data; - grub_efi_uint32_t kss; - grub_err_t err; - int key = -1; - - err = grub_console_read_key_stroke (term->data, &key_data, &key, 1); - if (err != GRUB_ERR_NONE || key == GRUB_TERM_NO_KEY) - return GRUB_TERM_NO_KEY; - - kss = key_data.key_state.key_shift_state; - if (kss & GRUB_EFI_SHIFT_STATE_VALID) - { - if ((kss & GRUB_EFI_LEFT_SHIFT_PRESSED - || kss & GRUB_EFI_RIGHT_SHIFT_PRESSED) - && (key & GRUB_TERM_EXTENDED)) - key |= GRUB_TERM_SHIFT; - if (kss & GRUB_EFI_LEFT_ALT_PRESSED || kss & GRUB_EFI_RIGHT_ALT_PRESSED) - key |= GRUB_TERM_ALT; - if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED - || kss & GRUB_EFI_RIGHT_CONTROL_PRESSED) - key |= GRUB_TERM_CTRL; - } - - return key; -} - -static int -grub_console_getkeystatus (struct grub_term_input *term) -{ - grub_efi_key_data_t key_data; - grub_efi_uint32_t kss; - int key, mods = 0; - - if (grub_efi_is_finished) - return 0; - - if (grub_console_read_key_stroke (term->data, &key_data, &key, 0)) - return 0; - - kss = key_data.key_state.key_shift_state; - if (kss & GRUB_EFI_SHIFT_STATE_VALID) - { - if (kss & GRUB_EFI_LEFT_SHIFT_PRESSED) - mods |= GRUB_TERM_STATUS_LSHIFT; - if (kss & GRUB_EFI_RIGHT_SHIFT_PRESSED) - mods |= GRUB_TERM_STATUS_RSHIFT; - if (kss & GRUB_EFI_LEFT_ALT_PRESSED) - mods |= GRUB_TERM_STATUS_LALT; - if (kss & GRUB_EFI_RIGHT_ALT_PRESSED) - mods |= GRUB_TERM_STATUS_RALT; - if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED) - mods |= GRUB_TERM_STATUS_LCTRL; - if (kss & GRUB_EFI_RIGHT_CONTROL_PRESSED) - mods |= GRUB_TERM_STATUS_RCTRL; - } - - return mods; -} - -static grub_err_t -grub_efi_console_input_init (struct grub_term_input *term) -{ - grub_efi_guid_t text_input_ex_guid = - GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID; - - if (grub_efi_is_finished) - return 0; - - grub_efi_simple_text_input_ex_interface_t *text_input = term->data; - if (text_input) - return 0; - - text_input = grub_efi_open_protocol(grub_efi_system_table->console_in_handler, - &text_input_ex_guid, - GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); - term->data = (void *)text_input; - return 0; } -static int -grub_console_getkey (struct grub_term_input *term) -{ - if (grub_efi_is_finished) - return 0; - - if (term->data) - return grub_console_getkey_ex(term); - else - return grub_console_getkey_con(term); -} - -static struct grub_term_coordinate -grub_console_getwh (struct grub_term_output *term) -{ - grub_efi_simple_text_output_interface_t *o; - grub_efi_uintn_t columns, rows; - - o = grub_efi_system_table->con_out; - if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE || - efi_call_4 (o->query_mode, o, o->mode->mode, - &columns, &rows) != GRUB_EFI_SUCCESS) - { - /* Why does this fail? */ - columns = 80; - rows = 25; - } - - return (struct grub_term_coordinate) { columns, rows }; -} - -static struct grub_term_coordinate -grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) -{ - grub_efi_simple_text_output_interface_t *o; - - if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE) - return (struct grub_term_coordinate) { 0, 0 }; - - o = grub_efi_system_table->con_out; - return (struct grub_term_coordinate) { o->mode->cursor_column, o->mode->cursor_row }; -} - -static void -grub_console_gotoxy (struct grub_term_output *term, - struct grub_term_coordinate pos) -{ - grub_efi_simple_text_output_interface_t *o; - - if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE) - return; - - o = grub_efi_system_table->con_out; - efi_call_3 (o->set_cursor_position, o, pos.x, pos.y); -} - -static void -grub_console_cls (struct grub_term_output *term __attribute__ ((unused))) -{ - grub_efi_simple_text_output_interface_t *o; - grub_efi_int32_t orig_attr; - - if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE) - return; - - o = grub_efi_system_table->con_out; - orig_attr = o->mode->attribute; - efi_call_2 (o->set_attributes, o, GRUB_EFI_BACKGROUND_BLACK); - efi_call_1 (o->clear_screen, o); - efi_call_2 (o->set_attributes, o, orig_attr); -} - static grub_err_t -grub_efi_console_output_fini (struct grub_term_output *term) +grub_efi_console_fini (struct grub_term_output *term) { - if (text_mode != GRUB_TEXT_MODE_AVAILABLE) - return 0; - grub_console_setcursor (term, 0); grub_efi_set_text_mode (0); - text_mode = GRUB_TEXT_MODE_UNDEFINED; return 0; } @@ -436,14 +262,13 @@ static struct grub_term_input grub_console_term_input = { .name = "console", .getkey = grub_console_getkey, - .getkeystatus = grub_console_getkeystatus, - .init = grub_efi_console_input_init, }; static struct grub_term_output grub_console_term_output = { .name = "console", - .fini = grub_efi_console_output_fini, + .init = grub_efi_console_init, + .fini = grub_efi_console_fini, .putchar = grub_console_putchar, .getwh = grub_console_getwh, .getxy = grub_console_getxy, @@ -458,8 +283,16 @@ static struct grub_term_output grub_console_term_output = void grub_console_init (void) { - grub_term_register_output ("console", &grub_console_term_output); + /* FIXME: it is necessary to consider the case where no console control + is present but the default is already in text mode. */ + if (! grub_efi_set_text_mode (1)) + { + grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); + return; + } + grub_term_register_input ("console", &grub_console_term_input); + grub_term_register_output ("console", &grub_console_term_output); } void diff --git a/grub-core/term/efi/serial.c b/grub-core/term/efi/serial.c index 4c94723c5..c0911ad7b 100644 --- a/grub-core/term/efi/serial.c +++ b/grub-core/term/efi/serial.c @@ -173,10 +173,7 @@ grub_efiserial_init (void) port->name = grub_malloc (sizeof ("efiXXXXXXXXXXXXXXXXXXXX")); if (!port->name) - { - grub_free (port); - return; - } + return; grub_snprintf (port->name, sizeof ("efiXXXXXXXXXXXXXXXXXXXX"), "efi%d", num_serial++); diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c index af7c090a3..70f10f19c 100644 --- a/grub-core/term/gfxterm.c +++ b/grub-core/term/gfxterm.c @@ -668,7 +668,6 @@ draw_cursor (int show) unsigned int y; unsigned int width; unsigned int height; - unsigned int ascent; grub_video_color_t color; write_char (); @@ -680,18 +679,13 @@ draw_cursor (int show) >= virtual_screen.rows) return; - /* Ensure that cursor doesn't go outside of character box. */ - ascent = grub_font_get_ascent(virtual_screen.font); - if (ascent > virtual_screen.normal_char_height - 2) - ascent = virtual_screen.normal_char_height - 2; - /* Determine cursor properties and position on text layer. */ x = virtual_screen.cursor_x * virtual_screen.normal_char_width; width = virtual_screen.normal_char_width; color = virtual_screen.fg_color; y = ((virtual_screen.cursor_y + virtual_screen.total_scroll) * virtual_screen.normal_char_height - + ascent); + + grub_font_get_ascent (virtual_screen.font)); height = 2; /* Render cursor to text layer. */ diff --git a/grub-core/term/i386/coreboot/cbmemc.c b/grub-core/term/i386/coreboot/cbmemc.c index cea9b8431..25e64a05c 100644 --- a/grub-core/term/i386/coreboot/cbmemc.c +++ b/grub-core/term/i386/coreboot/cbmemc.c @@ -23,20 +23,17 @@ #include #include #include -#include +#include #include #include GRUB_MOD_LICENSE ("GPLv3+"); -#define CURSOR_MASK ((1 << 28) - 1) -#define OVERFLOW (1 << 31) - struct grub_linuxbios_cbmemc { grub_uint32_t size; - grub_uint32_t cursor; - char body[0]; + grub_uint32_t pointer; + char data[0]; }; static struct grub_linuxbios_cbmemc *cbmemc; @@ -44,20 +41,11 @@ static struct grub_linuxbios_cbmemc *cbmemc; static void put (struct grub_term_output *term __attribute__ ((unused)), const int c) { - grub_uint32_t flags, cursor; if (!cbmemc) return; - flags = cbmemc->cursor & ~CURSOR_MASK; - cursor = cbmemc->cursor & CURSOR_MASK; - if (cursor >= cbmemc->size) - return; - cbmemc->body[cursor++] = c; - if (cursor >= cbmemc->size) - { - cursor = 0; - flags |= OVERFLOW; - } - cbmemc->cursor = flags | cursor; + if (cbmemc->pointer < cbmemc->size) + cbmemc->data[cbmemc->pointer] = c; + cbmemc->pointer++; } struct grub_terminfo_output_state grub_cbmemc_terminfo_output = @@ -99,29 +87,21 @@ grub_cmd_cbmemc (struct grub_command *cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused))) { - grub_size_t size, cursor; - struct grub_linuxbios_cbmemc *real_cbmemc; + grub_size_t len; + char *str; + struct grub_linuxbios_cbmemc *cbmemc_saved; if (!cbmemc) return grub_error (GRUB_ERR_IO, "no CBMEM console found"); - real_cbmemc = cbmemc; + len = cbmemc->pointer; + if (len > cbmemc->size) + len = cbmemc->size; + str = cbmemc->data; + cbmemc_saved = cbmemc; cbmemc = 0; - cursor = real_cbmemc->cursor & CURSOR_MASK; - if (!(real_cbmemc->cursor & OVERFLOW) && cursor < real_cbmemc->size) - size = cursor; - else - size = real_cbmemc->size; - if (real_cbmemc->cursor & OVERFLOW) - { - if (cursor > size) - cursor = 0; - grub_xnputs(real_cbmemc->body + cursor, size - cursor); - grub_xnputs(real_cbmemc->body, cursor); - } - else - grub_xnputs(real_cbmemc->body, size); - cbmemc = real_cbmemc; + grub_xnputs (str, len); + cbmemc = cbmemc_saved; return 0; } diff --git a/grub-core/term/i386/pc/console.c b/grub-core/term/i386/pc/console.c index f6142a2de..28de46b57 100644 --- a/grub-core/term/i386/pc/console.c +++ b/grub-core/term/i386/pc/console.c @@ -204,7 +204,7 @@ static int grub_console_getkey (struct grub_term_input *term __attribute__ ((unused))) { const grub_uint16_t bypass_table[] = { - 0x0100 | GRUB_TERM_ESC, 0x0f00 | GRUB_TERM_TAB, 0x0e00 | GRUB_TERM_BACKSPACE, 0x1c00 | '\r', 0x1c00 | '\n' + 0x0100 | '\e', 0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r', 0x1c00 | '\n' }; struct grub_bios_int_registers regs; unsigned i; diff --git a/grub-core/term/ps2.c b/grub-core/term/ps2.c deleted file mode 100644 index 7ae4e9f2f..000000000 --- a/grub-core/term/ps2.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include - -#define KEYBOARD_LED_SCROLL (1 << 0) -#define KEYBOARD_LED_NUM (1 << 1) -#define KEYBOARD_LED_CAPS (1 << 2) - -static const grub_uint8_t set1_mapping[128] = - { - /* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE, - /* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2, - /* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4, - /* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6, - /* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8, - /* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0, - /* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL, - /* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB, - /* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W, - /* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R, - /* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y, - /* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I, - /* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P, - /* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET, - /* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL, - /* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S, - /* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F, - /* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H, - /* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K, - /* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON, - /* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE, - /* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH, - /* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X, - /* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V, - /* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N, - /* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA, - /* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH, - /* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL, - /* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE, - /* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1, - /* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3, - /* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5, - /* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7, - /* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9, - /* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK, - /* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7, - /* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9, - /* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4, - /* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6, - /* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1, - /* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3, - /* 0x52 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT, - /* 0x54 */ 0, 0, - /* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11, - /* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0, - /* 0x5a */ 0, 0, - /* 0x5c */ 0, 0, - /* 0x5e */ 0, 0, - /* 0x60 */ 0, 0, - /* 0x62 */ 0, 0, - /* OLPC keys. Just mapped to normal keys. */ - /* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP, - /* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT, - /* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0, - /* 0x6a */ 0, 0, - /* 0x6c */ 0, 0, - /* 0x6e */ 0, 0, - /* 0x70 */ 0, 0, - /* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO, - /* 0x74 */ 0, 0, - /* 0x76 */ 0, 0, - /* 0x78 */ 0, 0, - /* 0x7a */ 0, 0, - /* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN, - /* 0x7e */ GRUB_KEYBOARD_KEY_KPCOMMA - }; - -static const struct -{ - grub_uint8_t from, to; -} set1_e0_mapping[] = - { - {0x1c, GRUB_KEYBOARD_KEY_NUMENTER}, - {0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL}, - {0x35, GRUB_KEYBOARD_KEY_NUMSLASH }, - {0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT}, - {0x47, GRUB_KEYBOARD_KEY_HOME}, - {0x48, GRUB_KEYBOARD_KEY_UP}, - {0x49, GRUB_KEYBOARD_KEY_PPAGE}, - {0x4b, GRUB_KEYBOARD_KEY_LEFT}, - {0x4d, GRUB_KEYBOARD_KEY_RIGHT}, - {0x4f, GRUB_KEYBOARD_KEY_END}, - {0x50, GRUB_KEYBOARD_KEY_DOWN}, - {0x51, GRUB_KEYBOARD_KEY_NPAGE}, - {0x52, GRUB_KEYBOARD_KEY_INSERT}, - {0x53, GRUB_KEYBOARD_KEY_DELETE}, - }; - -static const grub_uint8_t set2_mapping[256] = - { - /* 0x00 */ 0, GRUB_KEYBOARD_KEY_F9, - /* 0x02 */ 0, GRUB_KEYBOARD_KEY_F5, - /* 0x04 */ GRUB_KEYBOARD_KEY_F3, GRUB_KEYBOARD_KEY_F1, - /* 0x06 */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F12, - /* 0x08 */ 0, GRUB_KEYBOARD_KEY_F10, - /* 0x0a */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F6, - /* 0x0c */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_TAB, - /* 0x0e */ GRUB_KEYBOARD_KEY_RQUOTE, 0, - /* 0x10 */ 0, GRUB_KEYBOARD_KEY_LEFT_ALT, - /* 0x12 */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, 0, - /* 0x14 */ GRUB_KEYBOARD_KEY_LEFT_CTRL, GRUB_KEYBOARD_KEY_Q, - /* 0x16 */ GRUB_KEYBOARD_KEY_1, 0, - /* 0x18 */ 0, 0, - /* 0x1a */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_S, - /* 0x1c */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_W, - /* 0x1e */ GRUB_KEYBOARD_KEY_2, 0, - /* 0x20 */ 0, GRUB_KEYBOARD_KEY_C, - /* 0x22 */ GRUB_KEYBOARD_KEY_X, GRUB_KEYBOARD_KEY_D, - /* 0x24 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_4, - /* 0x26 */ GRUB_KEYBOARD_KEY_3, 0, - /* 0x28 */ 0, GRUB_KEYBOARD_KEY_SPACE, - /* 0x2a */ GRUB_KEYBOARD_KEY_V, GRUB_KEYBOARD_KEY_F, - /* 0x2c */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_R, - /* 0x2e */ GRUB_KEYBOARD_KEY_5, 0, - /* 0x30 */ 0, GRUB_KEYBOARD_KEY_N, - /* 0x32 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_H, - /* 0x34 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_Y, - /* 0x36 */ GRUB_KEYBOARD_KEY_6, 0, - /* 0x38 */ 0, 0, - /* 0x3a */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_J, - /* 0x3c */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_7, - /* 0x3e */ GRUB_KEYBOARD_KEY_8, 0, - /* 0x40 */ 0, GRUB_KEYBOARD_KEY_COMMA, - /* 0x42 */ GRUB_KEYBOARD_KEY_K, GRUB_KEYBOARD_KEY_I, - /* 0x44 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_0, - /* 0x46 */ GRUB_KEYBOARD_KEY_9, 0, - /* 0x48 */ 0, GRUB_KEYBOARD_KEY_DOT, - /* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L, - /* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P, - /* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0, - /* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO, - /* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0, - /* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL, - /* 0x56 */ 0, 0, - /* 0x58 */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_RIGHT_SHIFT, - /* 0x5a */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_RBRACKET, - /* 0x5c */ 0, GRUB_KEYBOARD_KEY_BACKSLASH, - /* 0x5e */ 0, 0, - /* 0x60 */ 0, GRUB_KEYBOARD_KEY_102ND, - /* 0x62 */ 0, 0, - /* 0x64 */ 0, 0, - /* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0, - /* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1, - /* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4, - /* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, GRUB_KEYBOARD_KEY_KPCOMMA, - /* 0x6e */ 0, 0, - /* 0x70 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT, - /* 0x72 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM5, - /* 0x74 */ GRUB_KEYBOARD_KEY_NUM6, GRUB_KEYBOARD_KEY_NUM8, - /* 0x76 */ GRUB_KEYBOARD_KEY_ESCAPE, GRUB_KEYBOARD_KEY_NUM_LOCK, - /* 0x78 */ GRUB_KEYBOARD_KEY_F11, GRUB_KEYBOARD_KEY_NUMPLUS, - /* 0x7a */ GRUB_KEYBOARD_KEY_NUM3, GRUB_KEYBOARD_KEY_NUMMINUS, - /* 0x7c */ GRUB_KEYBOARD_KEY_NUMMUL, GRUB_KEYBOARD_KEY_NUM9, - /* 0x7e */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, 0, - /* 0x80 */ 0, 0, - /* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7, - }; - -static const struct -{ - grub_uint8_t from, to; -} set2_e0_mapping[] = - { - {0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT}, - {0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL}, - {0x4a, GRUB_KEYBOARD_KEY_NUMSLASH}, - {0x5a, GRUB_KEYBOARD_KEY_NUMENTER}, - {0x69, GRUB_KEYBOARD_KEY_END}, - {0x6b, GRUB_KEYBOARD_KEY_LEFT}, - {0x6c, GRUB_KEYBOARD_KEY_HOME}, - {0x70, GRUB_KEYBOARD_KEY_INSERT}, - {0x71, GRUB_KEYBOARD_KEY_DELETE}, - {0x72, GRUB_KEYBOARD_KEY_DOWN}, - {0x74, GRUB_KEYBOARD_KEY_RIGHT}, - {0x75, GRUB_KEYBOARD_KEY_UP}, - {0x7a, GRUB_KEYBOARD_KEY_NPAGE}, - {0x7d, GRUB_KEYBOARD_KEY_PPAGE}, - }; - -static int -fetch_key (struct grub_ps2_state *ps2_state, grub_uint8_t at_key, int *is_break) -{ - int was_ext = 0; - int ret = 0; - - /* May happen if no keyboard is connected. Just ignore this. */ - if (at_key == 0xff) - return -1; - if (at_key == 0xe0) - { - ps2_state->e0_received = 1; - return -1; - } - - if ((ps2_state->current_set == 2 || ps2_state->current_set == 3) && at_key == 0xf0) - { - ps2_state->f0_received = 1; - return -1; - } - - /* Setting LEDs may generate ACKs. */ - if (at_key == GRUB_AT_ACK) - return -1; - - was_ext = ps2_state->e0_received; - ps2_state->e0_received = 0; - - switch (ps2_state->current_set) - { - case 1: - *is_break = !!(at_key & 0x80); - if (!was_ext) - ret = set1_mapping[at_key & 0x7f]; - else - { - unsigned i; - for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++) - if (set1_e0_mapping[i].from == (at_key & 0x7f)) - { - ret = set1_e0_mapping[i].to; - break; - } - } - break; - case 2: - *is_break = ps2_state->f0_received; - ps2_state->f0_received = 0; - if (!was_ext) - ret = set2_mapping[at_key]; - else - { - unsigned i; - for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++) - if (set2_e0_mapping[i].from == at_key) - { - ret = set2_e0_mapping[i].to; - break; - } - } - break; - default: - return -1; - } - if (!ret) - { - if (was_ext) - grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n", - at_key, ps2_state->current_set); - else - grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n", - at_key, ps2_state->current_set); - return -1; - } - return ret; -} - -/* FIXME: This should become an interrupt service routine. For now - it's just used to catch events from control keys. */ -static int -grub_keyboard_isr (struct grub_ps2_state *ps2_state, - grub_keyboard_key_t key, int is_break) -{ - if (!is_break) - switch (key) - { - case GRUB_KEYBOARD_KEY_LEFT_SHIFT: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LSHIFT; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_SHIFT: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RSHIFT; - return 1; - case GRUB_KEYBOARD_KEY_LEFT_CTRL: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LCTRL; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_CTRL: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RCTRL; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_ALT: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RALT; - return 1; - case GRUB_KEYBOARD_KEY_LEFT_ALT: - ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LALT; - return 1; - default: - return 0; - } - else - switch (key) - { - case GRUB_KEYBOARD_KEY_LEFT_SHIFT: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LSHIFT; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_SHIFT: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RSHIFT; - return 1; - case GRUB_KEYBOARD_KEY_LEFT_CTRL: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LCTRL; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_CTRL: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RCTRL; - return 1; - case GRUB_KEYBOARD_KEY_RIGHT_ALT: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RALT; - return 1; - case GRUB_KEYBOARD_KEY_LEFT_ALT: - ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LALT; - return 1; - default: - return 0; - } -} - -/* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */ -int -grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state, - grub_uint8_t at_key) -{ - int code; - int is_break = 0; - - code = fetch_key (ps2_state, at_key, &is_break); - if (code == -1) - return GRUB_TERM_NO_KEY; - - if (grub_keyboard_isr (ps2_state, code, is_break)) - return GRUB_TERM_NO_KEY; - if (is_break) - return GRUB_TERM_NO_KEY; -#ifdef DEBUG_AT_KEYBOARD - grub_dprintf ("atkeyb", "Detected key 0x%x\n", code); -#endif - switch (code) - { - case GRUB_KEYBOARD_KEY_CAPS_LOCK: - ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_CAPS; - ps2_state->led_status ^= KEYBOARD_LED_CAPS; - -#ifdef DEBUG_AT_KEYBOARD - grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_CAPS_LOCK)); -#endif - return GRUB_TERM_NO_KEY; - case GRUB_KEYBOARD_KEY_NUM_LOCK: - ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_NUM; - ps2_state->led_status ^= KEYBOARD_LED_NUM; - -#ifdef DEBUG_AT_KEYBOARD - grub_dprintf ("atkeyb", "num_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_NUM_LOCK)); -#endif - return GRUB_TERM_NO_KEY; - case GRUB_KEYBOARD_KEY_SCROLL_LOCK: - ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL; - ps2_state->led_status ^= KEYBOARD_LED_SCROLL; - return GRUB_TERM_NO_KEY; - default: - return grub_term_map_key (code, ps2_state->at_keyboard_status); - } -} diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index f9271b092..db80b3ba0 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -269,7 +269,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) if (state[OPTION_BASE_CLOCK].set) { - const char *ptr; + char *ptr; config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0); if (grub_errno) return grub_errno; diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c index cd7200803..f0d3e3deb 100644 --- a/grub-core/term/terminfo.c +++ b/grub-core/term/terminfo.c @@ -398,7 +398,7 @@ grub_terminfo_getwh (struct grub_term_output *term) } static void -grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int max_len, +grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int (*readkey) (struct grub_term_input *term)) { int c; @@ -414,9 +414,6 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int ma if (c == -1) \ return; \ \ - if (*len >= max_len) \ - return; \ - \ keys[*len] = c; \ (*len)++; \ } @@ -429,12 +426,12 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int ma } *len = 1; keys[0] = c; - if (c != ANSI_CSI && c != GRUB_TERM_ESC) + if (c != ANSI_CSI && c != '\e') { /* Backspace: Ctrl-h. */ if (c == 0x7f) - c = GRUB_TERM_BACKSPACE; - if (c < 0x20 && c != GRUB_TERM_TAB && c!= GRUB_TERM_BACKSPACE && c != '\n' && c != '\r') + c = '\b'; + if (c < 0x20 && c != '\t' && c!= '\b' && c != '\n' && c != '\r') c = GRUB_TERM_CTRL | (c - 1 + 'a'); *len = 1; keys[0] = c; @@ -490,7 +487,7 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int ma GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END }; unsigned i; - if (c == GRUB_TERM_ESC) + if (c == '\e') { CONTINUE_READ; @@ -605,11 +602,11 @@ grub_terminfo_getkey (struct grub_term_input *termi) return ret; } - grub_terminfo_readkey (termi, data->input_buf, &data->npending, - GRUB_TERMINFO_READKEY_MAX_LEN, data->readkey); + grub_terminfo_readkey (termi, data->input_buf, + &data->npending, data->readkey); #if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) - if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC + if (data->npending == 1 && data->input_buf[0] == '\e' && grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT) && grub_get_time_ms () - data->last_key_time < 1000 && (data->last_key & GRUB_TERM_EXTENDED)) @@ -740,7 +737,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args) if (state[OPTION_GEOMETRY].set) { - const char *ptr = state[OPTION_GEOMETRY].arg; + char *ptr = state[OPTION_GEOMETRY].arg; w = grub_strtoul (ptr, &ptr, 0); if (grub_errno) return grub_errno; diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c index e67b8f785..3b7484635 100644 --- a/grub-core/term/usb_keyboard.c +++ b/grub-core/term/usb_keyboard.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/grub-core/tests/boot/kernel-8086.S b/grub-core/tests/boot/kernel-8086.S index 5ec5368ff..510897c88 100644 --- a/grub-core/tests/boot/kernel-8086.S +++ b/grub-core/tests/boot/kernel-8086.S @@ -46,5 +46,5 @@ message: .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n" .byte 0 - .org 510 - .short 0xaa55 + . = base + 510 + .short 0xaa55 \ No newline at end of file diff --git a/grub-core/tests/bswap_test.c b/grub-core/tests/bswap_test.c deleted file mode 100644 index 4eb3a9814..000000000 --- a/grub-core/tests/bswap_test.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_uint64_t vectors[] = { - 0xffffffffffffffffULL, 1, 2, 0, 0x0102030405060708ULL -}; - -static void -test16 (grub_uint16_t a) -{ - grub_uint16_t b, c; - grub_uint8_t *ap, *bp; - int i; - b = grub_swap_bytes16 (a); - c = grub_swap_bytes16 (b); - grub_test_assert (a == c, "bswap not idempotent: 0x%llx, 0x%llx, 0x%llx", - (long long) a, (long long) b, (long long) c); - ap = (grub_uint8_t *) &a; - bp = (grub_uint8_t *) &b; - for (i = 0; i < 2; i++) - { - grub_test_assert (ap[i] == bp[1 - i], - "bswap bytes wrong: 0x%llx, 0x%llx", - (long long) a, (long long) b); - } -} - -static void -test32 (grub_uint32_t a) -{ - grub_uint32_t b, c; - grub_uint8_t *ap, *bp; - int i; - b = grub_swap_bytes32 (a); - c = grub_swap_bytes32 (b); - grub_test_assert (a == c, "bswap not idempotent: 0x%llx, 0x%llx, 0x%llx", - (long long) a, (long long) b, (long long) c); - ap = (grub_uint8_t *) &a; - bp = (grub_uint8_t *) &b; - for (i = 0; i < 4; i++) - { - grub_test_assert (ap[i] == bp[3 - i], - "bswap bytes wrong: 0x%llx, 0x%llx", - (long long) a, (long long) b); - } -} - -static void -test64 (grub_uint64_t a) -{ - grub_uint64_t b, c; - grub_uint8_t *ap, *bp; - int i; - b = grub_swap_bytes64 (a); - c = grub_swap_bytes64 (b); - grub_test_assert (a == c, "bswap not idempotent: 0x%llx, 0x%llx, 0x%llx", - (long long) a, (long long) b, (long long) c); - ap = (grub_uint8_t *) &a; - bp = (grub_uint8_t *) &b; - for (i = 0; i < 4; i++) - { - grub_test_assert (ap[i] == bp[7 - i], - "bswap bytes wrong: 0x%llx, 0x%llx", - (long long) a, (long long) b); - } -} - -static void -test_all(grub_uint64_t a) -{ - test64 (a); - test32 (a); - test16 (a); -} - -static void -bswap_test (void) -{ - grub_uint64_t a = 404, b = 7; - grub_size_t i; - - for (i = 0; i < ARRAY_SIZE (vectors); i++) - { - test_all (vectors[i]); - } - for (i = 0; i < 40000; i++) - { - a = 17 * a + 13 * b; - b = 23 * a + 29 * b; - if (b == 0) - b = 1; - if (a == 0) - a = 1; - test_all (a); - test_all (b); - } -} - -/* Register example_test method as a functional test. */ -GRUB_FUNCTIONAL_TEST (bswap_test, bswap_test); diff --git a/grub-core/tests/checksums.h b/grub-core/tests/checksums.h index 8273bd105..c9807a0dc 100644 --- a/grub-core/tests/checksums.h +++ b/grub-core/tests/checksums.h @@ -1,129 +1,465 @@ - { "cmdline_cat", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xc69be699, 0xc69be699, 0xe17fc97c, 0xe17fc97c, 0xc2512486, 0xc2512486, 0x20260761, 0x20260761, 0xe3485349, 0xe3485349, 0x6020b4d9, 0x6020b4d9, 0x1605db98, 0x1605db98, 0xdca51b58, 0xdca51b58, 0xf3d66441, 0xf3d66441, 0x18cb7ce2, 0x18cb7ce2, 0x23b616d9, 0x23b616d9, 0xa1bf5dbf, 0xa1bf5dbf, 0x5e4a8b3d, 0x5e4a8b3d, 0x9933b3d8, 0x9933b3d8, 0xce7be2de, 0xce7be2de, 0x62531729, 0x62531729, 0xc39d3788, 0xc39d3788, 0xf7aee2fe, 0xf7aee2fe, 0xc66f4903, 0xc66f4903, 0x536c922f, 0x536c922f, 0xcb231652, 0x4ae07b67, 0x146816d5, 0x146816d5, }, 45 }, - { "cmdline_cat", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x29d0cfb7, 0x29d0cfb7, 0x4d57ad88, 0x4d57ad88, 0xaf7591cb, 0xaf7591cb, 0xb88e3c0, 0xb88e3c0, 0x5d55a031, 0x5d55a031, 0x4363bcff, 0x4363bcff, 0xe1142833, 0xe1142833, 0x9578c80d, 0x9578c80d, 0xff1f5174, 0xff1f5174, 0x6828d47, 0x6828d47, 0x2a849ae3, 0x2a849ae3, 0x27a811d9, 0x27a811d9, 0x6c42e1cb, 0x6c42e1cb, 0x5bba61f5, 0x5bba61f5, 0xc02ab705, 0xc02ab705, 0xeb3e0e05, 0xeb3e0e05, 0x6f4ce3c, 0x6f4ce3c, 0x2075c50e, 0x2075c50e, 0x54ac7fba, 0x54ac7fba, 0x335d1c21, 0x335d1c21, 0xf923fbd1, 0x1b489d4d, 0x1253eb5e, 0x1253eb5e, }, 45 }, - { "cmdline_cat", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x6ff92a98, 0x6ff92a98, 0xbd8264b3, 0xbd8264b3, 0x5c50282c, 0x5c50282c, 0xd18d6a5a, 0xd18d6a5a, 0x99cea139, 0x99cea139, 0x2590c545, 0x2590c545, 0x55c86045, 0x55c86045, 0xad53ef1e, 0xad53ef1e, 0x5b44a23a, 0x5b44a23a, 0xa255f863, 0xa255f863, 0x85b0bdca, 0x85b0bdca, 0x4220ee1f, 0x4220ee1f, 0xeb991a9f, 0xeb991a9f, 0x86f366dd, 0x86f366dd, 0xfa176b7d, 0xfa176b7d, 0xd7384ca9, 0xd7384ca9, 0xceebf5c1, 0xceebf5c1, 0xae62b268, 0xae62b268, 0x6e89bbd6, 0x6e89bbd6, 0x3fe07c8e, 0x3fe07c8e, 0xee5358fe, 0x162d1a8a, 0x876f8d10, 0x876f8d10, }, 45 }, - { "cmdline_cat", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xb96afaea, 0xb96afaea, 0xaa16ab1e, 0xaa16ab1e, 0x51ff382, 0x51ff382, 0xec74f127, 0xec74f127, 0xde4bca99, 0xde4bca99, 0x8ef3e8a5, 0x8ef3e8a5, 0x2daeb0b4, 0x2daeb0b4, 0x7cf5e243, 0x7cf5e243, 0x11fd57c6, 0x11fd57c6, 0x140723af, 0x140723af, 0x2bd93833, 0x2bd93833, 0xd731f4ac, 0xd731f4ac, 0x5fcd7114, 0x5fcd7114, 0xd1fea24a, 0xd1fea24a, 0x4083d53a, 0x4083d53a, 0x2e372605, 0x2e372605, 0x8e6316a7, 0x8e6316a7, 0x283ef6cc, 0x283ef6cc, 0x20cee9de, 0x20cee9de, 0xad6fa187, 0xad6fa187, 0xd691f438, 0xf3257e63, 0x4786ba7, 0x4786ba7, }, 45 }, - { "cmdline_cat", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x48acf1bf, 0x48acf1bf, 0xb8777469, 0xb8777469, 0xad2fad44, 0xad2fad44, 0xa415ac59, 0xa415ac59, 0x5a7bfb26, 0x5a7bfb26, 0xccb6016, 0xccb6016, 0x77a80cb3, 0x77a80cb3, 0x2034c102, 0x2034c102, 0x444b4ccd, 0x444b4ccd, 0xe6c31bea, 0xe6c31bea, 0x8408036e, 0x8408036e, 0x9e7c556f, 0x9e7c556f, 0x445dc388, 0x445dc388, 0x94b3f850, 0x94b3f850, 0xf6f15341, 0xf6f15341, 0xcb939b5f, 0xcb939b5f, 0xbe88067d, 0xbe88067d, 0x1efc4734, 0x1efc4734, 0x7f5dfca8, 0x7f5dfca8, 0xb7b10eb9, 0xb7b10eb9, 0xb94cb441, 0x9571329, 0x8a26912b, 0x8a26912b, }, 45 }, - { "cmdline_cat", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xc508d04e, 0xc508d04e, 0x6dbccbfe, 0x6dbccbfe, 0xbf06ff60, 0xbf06ff60, 0xbc5ab06, 0xbc5ab06, 0x97eeab3c, 0x97eeab3c, 0x62663589, 0x62663589, 0xb03e21e2, 0xb03e21e2, 0xea196bb6, 0xea196bb6, 0x672c16c4, 0x672c16c4, 0xefbca2cd, 0xefbca2cd, 0x1af5b410, 0x1af5b410, 0xc7a80569, 0xc7a80569, 0x4926a16, 0x4926a16, 0xee29c99c, 0xee29c99c, 0xffb15985, 0xffb15985, 0x4f608e46, 0x4f608e46, 0x3e450fd2, 0x3e450fd2, 0xac45215f, 0xac45215f, 0x789b0ce7, 0x789b0ce7, 0x4cedfe22, 0x4cedfe22, 0xa005588c, 0x701da05c, 0x6f25cec1, 0x6f25cec1, }, 45 }, - { "cmdline_cat", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x29e7a7f, 0x29e7a7f, 0xbd221052, 0xbd221052, 0x3b18b64, 0x3b18b64, 0x7f1e8462, 0x7f1e8462, 0xf28d5124, 0xf28d5124, 0xc336f170, 0xc336f170, 0xfe3bf988, 0xfe3bf988, 0x7bf89e05, 0x7bf89e05, 0x7857a3f8, 0x7857a3f8, 0x272c1a36, 0x272c1a36, 0xe8adb445, 0xe8adb445, 0x70cfe280, 0x70cfe280, 0x4f2b6120, 0x4f2b6120, 0xbaf5caa5, 0xbaf5caa5, 0x4b6bcab2, 0x4b6bcab2, 0x2bef7b92, 0x2bef7b92, 0x17b381dc, 0x17b381dc, 0x884c9c35, 0x884c9c35, 0x2f9eb909, 0x2f9eb909, 0xa811b3af, 0xa811b3af, 0x4c39478f, 0x5a72c3ab, 0x8071678a, 0x8071678a, }, 45 }, - { "gfxterm_menu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xd9f04953, 0xbf3fa5d0, 0xd9f04953, 0x9a068414, 0x59c36f00, 0x59c36f00, 0x620c0067, 0x620c0067, 0x620c0067, 0x1c8c6d01, 0x1c8c6d01, 0x1c8c6d01, 0xc3269013, 0xc3269013, 0xc3269013, 0x59c36f00, 0x9a068414, 0x9a068414, 0x59c36f00, }, 20 }, - { "gfxterm_menu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x9254157f, 0x367e92c7, 0x9254157f, 0xbc519000, 0xaa4593fe, 0xaa4593fe, 0xa8a596c8, 0xa8a596c8, 0xa8a596c8, 0xe509baf, 0xe509baf, 0xe509baf, 0x16f0dc06, 0x16f0dc06, 0x16f0dc06, 0xaa4593fe, 0xbc519000, 0xbc519000, 0xaa4593fe, }, 20 }, - { "gfxterm_menu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x354b1976, 0x8fc746ae, 0x354b1976, 0x685c74f2, 0xc9cbf769, 0xc9cbf769, 0x3ce35e1d, 0x3ce35e1d, 0x3ce35e1d, 0xc23b9fd1, 0xc23b9fd1, 0xc23b9fd1, 0x5b18528e, 0x5b18528e, 0x5b18528e, 0xc9cbf769, 0x685c74f2, 0x685c74f2, 0xc9cbf769, }, 20 }, - { "gfxterm_menu", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x1c9ec014, 0xaf3ec923, 0x1c9ec014, 0x43f5296, 0x9813a416, 0x9813a416, 0x43fda3fa, 0x43fda3fa, 0x43fda3fa, 0xd22625c9, 0xd22625c9, 0xd22625c9, 0x76a62c0a, 0x76a62c0a, 0x76a62c0a, 0x9813a416, 0x43f5296, 0x43f5296, 0x9813a416, }, 20 }, - { "gfxterm_menu", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xa704f7ea, 0xb7f2ec8b, 0xa704f7ea, 0xb279bf59, 0x5fcf013d, 0x5fcf013d, 0xf3582c48, 0xf3582c48, 0xf3582c48, 0x2148343e, 0x2148343e, 0x2148343e, 0x9c719024, 0x9c719024, 0x9c719024, 0x5fcf013d, 0xb279bf59, 0xb279bf59, 0x5fcf013d, }, 20 }, - { "gfxterm_menu", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xf293ce36, 0xa6eb6ae8, 0xf293ce36, 0xcd87647e, 0xdd28f52b, 0xdd28f52b, 0xb3c7ef80, 0xb3c7ef80, 0xb3c7ef80, 0x92fb1664, 0x92fb1664, 0x92fb1664, 0xd15b5e2e, 0xd15b5e2e, 0xd15b5e2e, 0xdd28f52b, 0xcd87647e, 0xcd87647e, 0xdd28f52b, }, 20 }, - { "gfxterm_menu", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x31e75bd7, 0x9a768c6a, 0x31e75bd7, 0xa8fc31a6, 0x43d1f34, 0x43d1f34, 0xa0717008, 0xa0717008, 0xa0717008, 0xdf7bd9a0, 0xdf7bd9a0, 0xdf7bd9a0, 0x8e5a9312, 0x8e5a9312, 0x8e5a9312, 0x43d1f34, 0xa8fc31a6, 0xa8fc31a6, 0x43d1f34, }, 20 }, - { "gfxmenu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x1ce7bd78, 0x682580f5, 0x1ce7bd78, 0x490ad6fe, 0x9a2e0d26, 0x64eb71ba, 0x64eb71ba, 0x64eb71ba, 0x3833877a, 0x3833877a, 0x3833877a, 0xcfc14f0a, 0xcfc14f0a, 0xcfc14f0a, 0x59c36f00, 0x490ad6fe, 0x490ad6fe, }, 18 }, - { "gfxmenu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x2b6ff87d, 0x63ce2ca2, 0x2b6ff87d, 0xf00f044e, 0xa9d58ccd, 0xe2c46577, 0xe2c46577, 0xe2c46577, 0xb79bcf7d, 0xb79bcf7d, 0xb79bcf7d, 0xbc30ed71, 0xbc30ed71, 0xbc30ed71, 0xaa4593fe, 0xf00f044e, 0xf00f044e, }, 18 }, - { "gfxmenu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xe61cadba, 0x9880b727, 0xe61cadba, 0xdf5f2fc0, 0x5411be8b, 0x4449774e, 0x4449774e, 0x4449774e, 0x3bf7d1da, 0x3bf7d1da, 0x3bf7d1da, 0xd2ddee01, 0xd2ddee01, 0xd2ddee01, 0xc9cbf769, 0xdf5f2fc0, 0xdf5f2fc0, }, 18 }, - { "gfxmenu", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x1c3742c9, 0xbe54acf7, 0x9b4ce770, 0xbe54acf7, 0x3111489, 0x740d78cf, 0x314c4c59, 0x314c4c59, 0x314c4c59, 0xdae9a625, 0xdae9a625, 0xdae9a625, 0xcbf8af57, 0xcbf8af57, 0xcbf8af57, 0x1c3742c9, 0x3111489, 0x3111489, }, 18 }, - { "gfxmenu", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0xcc5a7bed, 0xee571de5, 0x568aaeff, 0xee571de5, 0xe328b7a7, 0xbcda144c, 0xf56e1b60, 0xf56e1b60, 0xf56e1b60, 0x9a27c771, 0x9a27c771, 0x9a27c771, 0xd6d05397, 0xd6d05397, 0xd6d05397, 0xcc5a7bed, 0xe328b7a7, 0xe328b7a7, }, 18 }, - { "gfxmenu", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xef4a3312, 0x1db9877c, 0x7e1afeae, 0x1db9877c, 0x8fc0c430, 0x5d55a141, 0x96f335c6, 0x96f335c6, 0x96f335c6, 0x504171d8, 0x504171d8, 0x504171d8, 0x69f71c0, 0x69f71c0, 0x69f71c0, 0xef4a3312, 0x8fc0c430, 0x8fc0c430, }, 18 }, - { "gfxmenu", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x54e48d80, 0x151819bd, 0xea8d4865, 0x151819bd, 0x11d75fd2, 0x6d6bb4bc, 0x650ccd09, 0x650ccd09, 0x650ccd09, 0xe4ff3bd8, 0xe4ff3bd8, 0xe4ff3bd8, 0xc5308b73, 0xc5308b73, 0xc5308b73, 0x54e48d80, 0x11d75fd2, 0x11d75fd2, }, 18 }, - { "gfxterm_ar", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xd0b06c3d, 0xde50d1a5, 0xd0b06c3d, 0x9346a17a, 0x59c36f00, 0x59c36f00, 0xacff5d47, 0xacff5d47, 0xacff5d47, 0xd27f3021, 0xd27f3021, 0xd27f3021, 0xdd5cd33, 0xdd5cd33, 0xdd5cd33, 0x59c36f00, 0x9346a17a, 0x9346a17a, 0x59c36f00, }, 20 }, - { "gfxterm_ar", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xf32d50c1, 0x730a7ed, 0xf32d50c1, 0xdd28d5be, 0xaa4593fe, 0xaa4593fe, 0xba8a2d4c, 0xba8a2d4c, 0xba8a2d4c, 0x1c7f202b, 0x1c7f202b, 0x1c7f202b, 0x4df6782, 0x4df6782, 0x4df6782, 0xaa4593fe, 0xdd28d5be, 0xdd28d5be, 0xaa4593fe, }, 20 }, - { "gfxterm_ar", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x711a4ac1, 0x6396f14c, 0x711a4ac1, 0x2c0d2745, 0xc9cbf769, 0xc9cbf769, 0x6b6ccbb0, 0x6b6ccbb0, 0x6b6ccbb0, 0x95b40a7c, 0x95b40a7c, 0x95b40a7c, 0xc97c723, 0xc97c723, 0xc97c723, 0xc9cbf769, 0x2c0d2745, 0x2c0d2745, 0xc9cbf769, }, 20 }, - { "gfxterm_ar", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x29baad6a, 0x348b1f2b, 0x29baad6a, 0x311b3fe8, 0x9813a416, 0x9813a416, 0xe8e982cc, 0xe8e982cc, 0xe8e982cc, 0x793204ff, 0x793204ff, 0x793204ff, 0xddb20d3c, 0xddb20d3c, 0xddb20d3c, 0x9813a416, 0x311b3fe8, 0x311b3fe8, 0x9813a416, }, 20 }, - { "gfxterm_ar", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xf834b3bb, 0x3951bd1a, 0xf834b3bb, 0xed49fb08, 0x5fcf013d, 0x5fcf013d, 0x5aefa2a7, 0x5aefa2a7, 0x5aefa2a7, 0x88ffbad1, 0x88ffbad1, 0x88ffbad1, 0x35c61ecb, 0x35c61ecb, 0x35c61ecb, 0x5fcf013d, 0xed49fb08, 0xed49fb08, 0x5fcf013d, }, 20 }, - { "gfxterm_ar", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7e9a7a47, 0xb1651b5a, 0x7e9a7a47, 0x418ed00f, 0xdd28f52b, 0xdd28f52b, 0x83f9db69, 0x83f9db69, 0x83f9db69, 0xa2c5228d, 0xa2c5228d, 0xa2c5228d, 0xe1656ac7, 0xe1656ac7, 0xe1656ac7, 0xdd28f52b, 0x418ed00f, 0x418ed00f, 0xdd28f52b, }, 20 }, - { "gfxterm_ar", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xc6a0340, 0x7dd5855c, 0xc6a0340, 0x95716931, 0x43d1f34, 0x43d1f34, 0x5f1c24c0, 0x5f1c24c0, 0x5f1c24c0, 0x20168d68, 0x20168d68, 0x20168d68, 0x7137c7da, 0x7137c7da, 0x7137c7da, 0x43d1f34, 0x95716931, 0x95716931, 0x43d1f34, }, 20 }, - { "gfxterm_cyr", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xd3798aaa, 0xab48784c, 0xd3798aaa, 0x908f47ed, 0x59c36f00, 0x59c36f00, 0x1688ec7c, 0x1688ec7c, 0x1688ec7c, 0x6808811a, 0x6808811a, 0x6808811a, 0xb7a27c08, 0xb7a27c08, 0xb7a27c08, 0x59c36f00, 0x908f47ed, 0x908f47ed, 0x59c36f00, }, 20 }, - { "gfxterm_cyr", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xc30d9d2a, 0x60b9ed26, 0xc30d9d2a, 0xed081855, 0xaa4593fe, 0xaa4593fe, 0x3eba2192, 0x3eba2192, 0x3eba2192, 0x984f2cf5, 0x984f2cf5, 0x984f2cf5, 0x80ef6b5c, 0x80ef6b5c, 0x80ef6b5c, 0xaa4593fe, 0xed081855, 0xed081855, 0xaa4593fe, }, 20 }, - { "gfxterm_cyr", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xe469e6af, 0x46ac2012, 0xe469e6af, 0xb97e8b2b, 0xc9cbf769, 0xc9cbf769, 0x60f0d993, 0x60f0d993, 0x60f0d993, 0x9e28185f, 0x9e28185f, 0x9e28185f, 0x70bd500, 0x70bd500, 0x70bd500, 0xc9cbf769, 0xb97e8b2b, 0xb97e8b2b, 0xc9cbf769, }, 20 }, - { "gfxterm_cyr", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x8538d2ef, 0xab143284, 0x8538d2ef, 0x9d99406d, 0x9813a416, 0x9813a416, 0x7e8326ec, 0x7e8326ec, 0x7e8326ec, 0xef58a0df, 0xef58a0df, 0xef58a0df, 0x4bd8a91c, 0x4bd8a91c, 0x4bd8a91c, 0x9813a416, 0x9d99406d, 0x9d99406d, 0x9813a416, }, 20 }, - { "gfxterm_cyr", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x8115198c, 0x1abdaee1, 0x8115198c, 0x9468513f, 0x5fcf013d, 0x5fcf013d, 0xa5e86484, 0xa5e86484, 0xa5e86484, 0x77f87cf2, 0x77f87cf2, 0x77f87cf2, 0xcac1d8e8, 0xcac1d8e8, 0xcac1d8e8, 0x5fcf013d, 0x9468513f, 0x9468513f, 0x5fcf013d, }, 20 }, - { "gfxterm_cyr", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xea03b805, 0x74148290, 0xea03b805, 0xd517124d, 0xdd28f52b, 0xdd28f52b, 0x8f6eee40, 0x8f6eee40, 0x8f6eee40, 0xae5217a4, 0xae5217a4, 0xae5217a4, 0xedf25fee, 0xedf25fee, 0xedf25fee, 0xdd28f52b, 0xd517124d, 0xd517124d, 0xdd28f52b, }, 20 }, - { "gfxterm_cyr", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xa044490f, 0xe23458db, 0xa044490f, 0x395f237e, 0x43d1f34, 0x43d1f34, 0xe1ca82c2, 0xe1ca82c2, 0xe1ca82c2, 0x9ec02b6a, 0x9ec02b6a, 0x9ec02b6a, 0xcfe161d8, 0xcfe161d8, 0xcfe161d8, 0x43d1f34, 0x395f237e, 0x395f237e, 0x43d1f34, }, 20 }, - { "gfxterm_heb", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xf3259b30, 0xf1f01411, 0xf3259b30, 0xb0d35677, 0x59c36f00, 0x59c36f00, 0x97895f8e, 0x97895f8e, 0x97895f8e, 0xe90932e8, 0xe90932e8, 0xe90932e8, 0x36a3cffa, 0x36a3cffa, 0x36a3cffa, 0x59c36f00, 0xb0d35677, 0xb0d35677, 0x59c36f00, }, 20 }, - { "gfxterm_heb", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x53a43759, 0xe0f26bfa, 0x53a43759, 0x7da1b226, 0xaa4593fe, 0xaa4593fe, 0xbf482a4e, 0xbf482a4e, 0xbf482a4e, 0x19bd2729, 0x19bd2729, 0x19bd2729, 0x11d6080, 0x11d6080, 0x11d6080, 0xaa4593fe, 0x7da1b226, 0x7da1b226, 0xaa4593fe, }, 20 }, - { "gfxterm_heb", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xd7ff8d53, 0x665b2728, 0xd7ff8d53, 0x8ae8e0d7, 0xc9cbf769, 0xc9cbf769, 0x5a693e73, 0x5a693e73, 0x5a693e73, 0xa4b1ffbf, 0xa4b1ffbf, 0xa4b1ffbf, 0x3d9232e0, 0x3d9232e0, 0x3d9232e0, 0xc9cbf769, 0x8ae8e0d7, 0x8ae8e0d7, 0xc9cbf769, }, 20 }, - { "gfxterm_heb", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x99fddcbe, 0x6d5c8895, 0x99fddcbe, 0x815c4e3c, 0x9813a416, 0x9813a416, 0x9bcf9821, 0x9bcf9821, 0x9bcf9821, 0xa141e12, 0xa141e12, 0xa141e12, 0xae9417d1, 0xae9417d1, 0xae9417d1, 0x9813a416, 0x815c4e3c, 0x815c4e3c, 0x9813a416, }, 20 }, - { "gfxterm_heb", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x5797846, 0x25a6ad40, 0x5797846, 0x100430f5, 0x5fcf013d, 0x5fcf013d, 0xddc86daf, 0xddc86daf, 0xddc86daf, 0xfd875d9, 0xfd875d9, 0xfd875d9, 0xb2e1d1c3, 0xb2e1d1c3, 0xb2e1d1c3, 0x5fcf013d, 0x100430f5, 0x100430f5, 0x5fcf013d, }, 20 }, - { "gfxterm_heb", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x30653ae8, 0x7fcd187, 0x30653ae8, 0xf7190a0, 0xdd28f52b, 0xdd28f52b, 0x24c3d325, 0x24c3d325, 0x24c3d325, 0x5ff2ac1, 0x5ff2ac1, 0x5ff2ac1, 0x465f628b, 0x465f628b, 0x465f628b, 0xdd28f52b, 0xf7190a0, 0xf7190a0, 0xdd28f52b, }, 20 }, - { "gfxterm_heb", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x3bd91638, 0x1d74dd4a, 0x3bd91638, 0xa2c27c49, 0x43d1f34, 0x43d1f34, 0x53d1ad3d, 0x53d1ad3d, 0x53d1ad3d, 0x2cdb0495, 0x2cdb0495, 0x2cdb0495, 0x7dfa4e27, 0x7dfa4e27, 0x7dfa4e27, 0x43d1f34, 0xa2c27c49, 0xa2c27c49, 0x43d1f34, }, 20 }, - { "gfxterm_gre", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xbe2c351a, 0x2692720, 0xbe2c351a, 0xfddaf85d, 0x59c36f00, 0x59c36f00, 0x1b2e2301, 0x1b2e2301, 0x1b2e2301, 0x65ae4e67, 0x65ae4e67, 0x65ae4e67, 0xba04b375, 0xba04b375, 0xba04b375, 0x59c36f00, 0xfddaf85d, 0xfddaf85d, 0x59c36f00, }, 20 }, - { "gfxterm_gre", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x1eca82e1, 0xe8fa59cc, 0x1eca82e1, 0x30cf079e, 0xaa4593fe, 0xaa4593fe, 0xaf27ddc5, 0xaf27ddc5, 0xaf27ddc5, 0x9d2d0a2, 0x9d2d0a2, 0x9d2d0a2, 0x1172970b, 0x1172970b, 0x1172970b, 0xaa4593fe, 0x30cf079e, 0x30cf079e, 0xaa4593fe, }, 20 }, - { "gfxterm_gre", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xa9ccd435, 0x1ac646eb, 0xa9ccd435, 0xf4dbb9b1, 0xc9cbf769, 0xc9cbf769, 0x86d69aa0, 0x86d69aa0, 0x86d69aa0, 0x780e5b6c, 0x780e5b6c, 0x780e5b6c, 0xe12d9633, 0xe12d9633, 0xe12d9633, 0xc9cbf769, 0xf4dbb9b1, 0xf4dbb9b1, 0xc9cbf769, }, 20 }, - { "gfxterm_gre", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xf96d568, 0x7ad05c1b, 0xf96d568, 0x173747ea, 0x9813a416, 0x9813a416, 0xacf9792a, 0xacf9792a, 0xacf9792a, 0x3d22ff19, 0x3d22ff19, 0x3d22ff19, 0x99a2f6da, 0x99a2f6da, 0x99a2f6da, 0x9813a416, 0x173747ea, 0x173747ea, 0x9813a416, }, 20 }, - { "gfxterm_gre", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xa0dc6b9c, 0xc2761148, 0xa0dc6b9c, 0xb5a1232f, 0x5fcf013d, 0x5fcf013d, 0x4e05748b, 0x4e05748b, 0x4e05748b, 0x9c156cfd, 0x9c156cfd, 0x9c156cfd, 0x212cc8e7, 0x212cc8e7, 0x212cc8e7, 0x5fcf013d, 0xb5a1232f, 0xb5a1232f, 0x5fcf013d, }, 20 }, - { "gfxterm_gre", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xcd722f7d, 0xe4df8d6b, 0xcd722f7d, 0xf2668535, 0xdd28f52b, 0xdd28f52b, 0xbdbb8019, 0xbdbb8019, 0xbdbb8019, 0x9c8779fd, 0x9c8779fd, 0x9c8779fd, 0xdf2731b7, 0xdf2731b7, 0xdf2731b7, 0xdd28f52b, 0xf2668535, 0xf2668535, 0xdd28f52b, }, 20 }, - { "gfxterm_gre", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xa6c99d2f, 0x1de04317, 0xa6c99d2f, 0x3fd2f75e, 0x43d1f34, 0x43d1f34, 0x3f85b7d3, 0x3f85b7d3, 0x3f85b7d3, 0x408f1e7b, 0x408f1e7b, 0x408f1e7b, 0x11ae54c9, 0x11ae54c9, 0x11ae54c9, 0x43d1f34, 0x3fd2f75e, 0x3fd2f75e, 0x43d1f34, }, 20 }, - { "gfxterm_ru", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x1e35b709, 0x2683bf92, 0x1e35b709, 0x5dc37a4e, 0x59c36f00, 0x59c36f00, 0xd697967f, 0xd697967f, 0xd697967f, 0xa817fb19, 0xa817fb19, 0xa817fb19, 0x77bd060b, 0x77bd060b, 0x77bd060b, 0x59c36f00, 0x5dc37a4e, 0x5dc37a4e, 0x59c36f00, }, 20 }, - { "gfxterm_ru", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x53ff7735, 0x8cbf197c, 0x53ff7735, 0x7dfaf24a, 0xaa4593fe, 0xaa4593fe, 0x389a922, 0x389a922, 0x389a922, 0xa57ca445, 0xa57ca445, 0xa57ca445, 0xbddce3ec, 0xbddce3ec, 0xbddce3ec, 0xaa4593fe, 0x7dfaf24a, 0x7dfaf24a, 0xaa4593fe, }, 20 }, - { "gfxterm_ru", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x5217c47d, 0x7c8ae63e, 0x5217c47d, 0xf00a9f9, 0xc9cbf769, 0xc9cbf769, 0x3995409, 0x3995409, 0x3995409, 0xfd4195c5, 0xfd4195c5, 0xfd4195c5, 0x6462589a, 0x6462589a, 0x6462589a, 0xc9cbf769, 0xf00a9f9, 0xf00a9f9, 0xc9cbf769, }, 20 }, - { "gfxterm_ru", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x45b67706, 0x375fb5db, 0x45b67706, 0x5d17e584, 0x9813a416, 0x9813a416, 0x8195719b, 0x8195719b, 0x8195719b, 0x104ef7a8, 0x104ef7a8, 0x104ef7a8, 0xb4cefe6b, 0xb4cefe6b, 0xb4cefe6b, 0x9813a416, 0x5d17e584, 0x5d17e584, 0x9813a416, }, 20 }, - { "gfxterm_ru", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xfc209a25, 0xd5c20779, 0xfc209a25, 0xe95dd296, 0x5fcf013d, 0x5fcf013d, 0xe5699efe, 0xe5699efe, 0xe5699efe, 0x37798688, 0x37798688, 0x37798688, 0x8a402292, 0x8a402292, 0x8a402292, 0x5fcf013d, 0xe95dd296, 0xe95dd296, 0x5fcf013d, }, 20 }, - { "gfxterm_ru", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x77f956f0, 0xfb0cc079, 0x77f956f0, 0x48edfcb8, 0xdd28f52b, 0xdd28f52b, 0xd51b1dc9, 0xd51b1dc9, 0xd51b1dc9, 0xf427e42d, 0xf427e42d, 0xf427e42d, 0xb787ac67, 0xb787ac67, 0xb787ac67, 0xdd28f52b, 0x48edfcb8, 0x48edfcb8, 0xdd28f52b, }, 20 }, - { "gfxterm_ru", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x1d9ac82a, 0xa254aa53, 0x1d9ac82a, 0x8481a25b, 0x43d1f34, 0x43d1f34, 0xc304df68, 0xc304df68, 0xc304df68, 0xbc0e76c0, 0xbc0e76c0, 0xbc0e76c0, 0xed2f3c72, 0xed2f3c72, 0xed2f3c72, 0x43d1f34, 0x8481a25b, 0x8481a25b, 0x43d1f34, }, 20 }, - { "gfxterm_fr", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xa6239a89, 0x8dc4bfbb, 0xa6239a89, 0xe5d557ce, 0x59c36f00, 0x59c36f00, 0x244cf807, 0x244cf807, 0x244cf807, 0x5acc9561, 0x5acc9561, 0x5acc9561, 0x85666873, 0x85666873, 0x85666873, 0x59c36f00, 0xe5d557ce, 0xe5d557ce, 0x59c36f00, }, 20 }, - { "gfxterm_fr", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x742cede9, 0x83bb7a50, 0x742cede9, 0x5a296896, 0xaa4593fe, 0xaa4593fe, 0xd83f8aeb, 0xd83f8aeb, 0xd83f8aeb, 0x7eca878c, 0x7eca878c, 0x7eca878c, 0x666ac025, 0x666ac025, 0x666ac025, 0xaa4593fe, 0x5a296896, 0x5a296896, 0xaa4593fe, }, 20 }, - { "gfxterm_fr", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xe20a98b0, 0x7e8cedef, 0xe20a98b0, 0xbf1df534, 0xc9cbf769, 0xc9cbf769, 0x2748b88c, 0x2748b88c, 0x2748b88c, 0xd9907940, 0xd9907940, 0xd9907940, 0x40b3b41f, 0x40b3b41f, 0x40b3b41f, 0xc9cbf769, 0xbf1df534, 0xbf1df534, 0xc9cbf769, }, 20 }, - { "gfxterm_fr", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x8f911ca4, 0xcbf1d895, 0x8f911ca4, 0x97308e26, 0x9813a416, 0x9813a416, 0x5b359bf4, 0x5b359bf4, 0x5b359bf4, 0xcaee1dc7, 0xcaee1dc7, 0xcaee1dc7, 0x6e6e1404, 0x6e6e1404, 0x6e6e1404, 0x9813a416, 0x97308e26, 0x97308e26, 0x9813a416, }, 20 }, - { "gfxterm_fr", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x1bf82c82, 0xc7b39627, 0x1bf82c82, 0xe856431, 0x5fcf013d, 0x5fcf013d, 0xa9dbae99, 0xa9dbae99, 0xa9dbae99, 0x7bcbb6ef, 0x7bcbb6ef, 0x7bcbb6ef, 0xc6f212f5, 0xc6f212f5, 0xc6f212f5, 0x5fcf013d, 0xe856431, 0xe856431, 0x5fcf013d, }, 20 }, - { "gfxterm_fr", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xfae19a5c, 0xd1e8fabb, 0xfae19a5c, 0xc5f53014, 0xdd28f52b, 0xdd28f52b, 0xfa2c5565, 0xfa2c5565, 0xfa2c5565, 0xdb10ac81, 0xdb10ac81, 0xdb10ac81, 0x98b0e4cb, 0x98b0e4cb, 0x98b0e4cb, 0xdd28f52b, 0xc5f53014, 0xc5f53014, 0xdd28f52b, }, 20 }, - { "gfxterm_fr", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x9a18f7bc, 0x5fcecc43, 0x9a18f7bc, 0x3039dcd, 0x43d1f34, 0x43d1f34, 0x287a2b96, 0x287a2b96, 0x287a2b96, 0x5770823e, 0x5770823e, 0x5770823e, 0x651c88c, 0x651c88c, 0x651c88c, 0x43d1f34, 0x3039dcd, 0x3039dcd, 0x43d1f34, }, 20 }, - { "gfxterm_quot", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x65112dfc, 0x3dec17f, 0x65112dfc, 0x26e7e0bb, 0x59c36f00, 0x59c36f00, 0x620c0067, 0x620c0067, 0x620c0067, 0x1c8c6d01, 0x1c8c6d01, 0x1c8c6d01, 0xc3269013, 0xc3269013, 0xc3269013, 0x59c36f00, 0x26e7e0bb, 0x26e7e0bb, 0x59c36f00, }, 20 }, - { "gfxterm_quot", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x2b3430fb, 0x8f1eb743, 0x2b3430fb, 0x531b584, 0xaa4593fe, 0xaa4593fe, 0xa8a596c8, 0xa8a596c8, 0xa8a596c8, 0xe509baf, 0xe509baf, 0xe509baf, 0x16f0dc06, 0x16f0dc06, 0x16f0dc06, 0xaa4593fe, 0x531b584, 0x531b584, 0xaa4593fe, }, 20 }, - { "gfxterm_quot", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xb523e920, 0xfafb6f8, 0xb523e920, 0xe83484a4, 0xc9cbf769, 0xc9cbf769, 0x3ce35e1d, 0x3ce35e1d, 0x3ce35e1d, 0xc23b9fd1, 0xc23b9fd1, 0xc23b9fd1, 0x5b18528e, 0x5b18528e, 0x5b18528e, 0xc9cbf769, 0xe83484a4, 0xe83484a4, 0xc9cbf769, }, 20 }, - { "gfxterm_quot", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xa9bf7336, 0x1a1f7a01, 0xa9bf7336, 0xb11ee1b4, 0x9813a416, 0x9813a416, 0x43fda3fa, 0x43fda3fa, 0x43fda3fa, 0xd22625c9, 0xd22625c9, 0xd22625c9, 0x76a62c0a, 0x76a62c0a, 0x76a62c0a, 0x9813a416, 0xb11ee1b4, 0xb11ee1b4, 0x9813a416, }, 20 }, - { "gfxterm_quot", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xe5271912, 0xf5d10273, 0xe5271912, 0xf05a51a1, 0x5fcf013d, 0x5fcf013d, 0xf3582c48, 0xf3582c48, 0xf3582c48, 0x2148343e, 0x2148343e, 0x2148343e, 0x9c719024, 0x9c719024, 0x9c719024, 0x5fcf013d, 0xf05a51a1, 0xf05a51a1, 0x5fcf013d, }, 20 }, - { "gfxterm_quot", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x66a34f49, 0x32dbeb97, 0x66a34f49, 0x59b7e501, 0xdd28f52b, 0xdd28f52b, 0xb3c7ef80, 0xb3c7ef80, 0xb3c7ef80, 0x92fb1664, 0x92fb1664, 0x92fb1664, 0xd15b5e2e, 0xd15b5e2e, 0xd15b5e2e, 0xdd28f52b, 0x59b7e501, 0x59b7e501, 0xdd28f52b, }, 20 }, - { "gfxterm_quot", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x7c2f19da, 0xd7bece67, 0x7c2f19da, 0xe53473ab, 0x43d1f34, 0x43d1f34, 0xa0717008, 0xa0717008, 0xa0717008, 0xdf7bd9a0, 0xdf7bd9a0, 0xdf7bd9a0, 0x8e5a9312, 0x8e5a9312, 0x8e5a9312, 0x43d1f34, 0xe53473ab, 0xe53473ab, 0x43d1f34, }, 20 }, - { "gfxterm_piglatin", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x37943894, 0x78248c70, 0x37943894, 0x7462f5d3, 0x59c36f00, 0x59c36f00, 0xf4be229a, 0xf4be229a, 0xf4be229a, 0x8a3e4ffc, 0x8a3e4ffc, 0x8a3e4ffc, 0x5594b2ee, 0x5594b2ee, 0x5594b2ee, 0x59c36f00, 0x7462f5d3, 0x7462f5d3, 0x59c36f00, }, 20 }, - { "gfxterm_piglatin", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xd5158e6c, 0xdc71ba0f, 0xd5158e6c, 0xfb100b13, 0xaa4593fe, 0xaa4593fe, 0xd3ed72a3, 0xd3ed72a3, 0xd3ed72a3, 0x75187fc4, 0x75187fc4, 0x75187fc4, 0x6db8386d, 0x6db8386d, 0x6db8386d, 0xaa4593fe, 0xfb100b13, 0xfb100b13, 0xaa4593fe, }, 20 }, - { "gfxterm_piglatin", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x6277a9e6, 0xa3265ffb, 0x6277a9e6, 0x3f60c462, 0xc9cbf769, 0xc9cbf769, 0x2dcf8a8d, 0x2dcf8a8d, 0x2dcf8a8d, 0xd3174b41, 0xd3174b41, 0xd3174b41, 0x4a34861e, 0x4a34861e, 0x4a34861e, 0xc9cbf769, 0x3f60c462, 0x3f60c462, 0xc9cbf769, }, 20 }, - { "gfxterm_piglatin", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x81115dc4, 0xddf3f768, 0x81115dc4, 0x99b0cf46, 0x9813a416, 0x9813a416, 0x9b9d96df, 0x9b9d96df, 0x9b9d96df, 0xa4610ec, 0xa4610ec, 0xa4610ec, 0xaec6192f, 0xaec6192f, 0xaec6192f, 0x9813a416, 0x99b0cf46, 0x99b0cf46, 0x9813a416, }, 20 }, - { "gfxterm_piglatin", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x5e96a904, 0x27864d3d, 0x5e96a904, 0x4bebe1b7, 0x5fcf013d, 0x5fcf013d, 0x18cae7f4, 0x18cae7f4, 0x18cae7f4, 0xcadaff82, 0xcadaff82, 0xcadaff82, 0x77e35b98, 0x77e35b98, 0x77e35b98, 0x5fcf013d, 0x4bebe1b7, 0x4bebe1b7, 0x5fcf013d, }, 20 }, - { "gfxterm_piglatin", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xd00b19f8, 0xba73a9c6, 0xd00b19f8, 0xef1fb3b0, 0xdd28f52b, 0xdd28f52b, 0xb660046d, 0xb660046d, 0xb660046d, 0x975cfd89, 0x975cfd89, 0x975cfd89, 0xd4fcb5c3, 0xd4fcb5c3, 0xd4fcb5c3, 0xdd28f52b, 0xef1fb3b0, 0xef1fb3b0, 0xdd28f52b, }, 20 }, - { "gfxterm_piglatin", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x8b4b98cd, 0x78ddc6e4, 0x8b4b98cd, 0x1250f2bc, 0x43d1f34, 0x43d1f34, 0x4889d3fd, 0x4889d3fd, 0x4889d3fd, 0x37837a55, 0x37837a55, 0x37837a55, 0x66a230e7, 0x66a230e7, 0x66a230e7, 0x43d1f34, 0x1250f2bc, 0x1250f2bc, 0x43d1f34, }, 20 }, - { "gfxterm_ch", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xfecb570e, 0xccb97a7a, 0xfecb570e, 0xbd3d9a49, 0x59c36f00, 0x59c36f00, 0x40281258, 0x40281258, 0x40281258, 0x3ea87f3e, 0x3ea87f3e, 0x3ea87f3e, 0xe102822c, 0xe102822c, 0xe102822c, 0x59c36f00, 0xbd3d9a49, 0xbd3d9a49, 0x59c36f00, }, 20 }, - { "gfxterm_ch", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x897d1fac, 0xaa982529, 0x897d1fac, 0xa7789ad3, 0xaa4593fe, 0xaa4593fe, 0xa482510, 0xa482510, 0xa482510, 0xacbd2877, 0xacbd2877, 0xacbd2877, 0xb41d6fde, 0xb41d6fde, 0xb41d6fde, 0xaa4593fe, 0xa7789ad3, 0xa7789ad3, 0xaa4593fe, }, 20 }, - { "gfxterm_ch", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xd02a5297, 0xe627ab58, 0xd02a5297, 0x8d3d3f13, 0xc9cbf769, 0xc9cbf769, 0xbf0a8b7f, 0xbf0a8b7f, 0xbf0a8b7f, 0x41d24ab3, 0x41d24ab3, 0x41d24ab3, 0xd8f187ec, 0xd8f187ec, 0xd8f187ec, 0xc9cbf769, 0x8d3d3f13, 0x8d3d3f13, 0xc9cbf769, }, 20 }, - { "gfxterm_ch", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xa653dcda, 0x3392e976, 0xa653dcda, 0xbef24e58, 0x9813a416, 0x9813a416, 0x4f2bc106, 0x4f2bc106, 0x4f2bc106, 0xdef04735, 0xdef04735, 0xdef04735, 0x7a704ef6, 0x7a704ef6, 0x7a704ef6, 0x9813a416, 0xbef24e58, 0xbef24e58, 0x9813a416, }, 20 }, - { "gfxterm_ch", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xe2d7b585, 0x35241f36, 0xe2d7b585, 0xf7aafd36, 0x5fcf013d, 0x5fcf013d, 0xf2bd04db, 0xf2bd04db, 0xf2bd04db, 0x20ad1cad, 0x20ad1cad, 0x20ad1cad, 0x9d94b8b7, 0x9d94b8b7, 0x9d94b8b7, 0x5fcf013d, 0xf7aafd36, 0xf7aafd36, 0x5fcf013d, }, 20 }, - { "gfxterm_ch", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x72ff749c, 0xeda8c283, 0x72ff749c, 0x4debded4, 0xdd28f52b, 0xdd28f52b, 0xb8c9cc22, 0xb8c9cc22, 0xb8c9cc22, 0x99f535c6, 0x99f535c6, 0x99f535c6, 0xda557d8c, 0xda557d8c, 0xda557d8c, 0xdd28f52b, 0x4debded4, 0x4debded4, 0xdd28f52b, }, 20 }, - { "gfxterm_ch", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xb7cac764, 0xeb4bf417, 0xb7cac764, 0x2ed1ad15, 0x43d1f34, 0x43d1f34, 0xce718801, 0xce718801, 0xce718801, 0xb17b21a9, 0xb17b21a9, 0xb17b21a9, 0xe05a6b1b, 0xe05a6b1b, 0xe05a6b1b, 0x43d1f34, 0x2ed1ad15, 0x2ed1ad15, 0x43d1f34, }, 20 }, - { "gfxterm_red", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x930e8e13, 0xf5c16290, 0x930e8e13, 0x27f5f1c0, 0x59c36f00, 0x59c36f00, 0xbad4e11, 0xbad4e11, 0xbad4e11, 0x752d2377, 0x752d2377, 0x752d2377, 0xaa87de65, 0xaa87de65, 0xaa87de65, 0x59c36f00, 0x27f5f1c0, 0x27f5f1c0, 0x59c36f00, }, 20 }, - { "gfxterm_red", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xff9301f2, 0x5bb9864a, 0xff9301f2, 0x31c145de, 0xaa4593fe, 0xaa4593fe, 0x23bf2c32, 0x23bf2c32, 0x23bf2c32, 0x854a2155, 0x854a2155, 0x854a2155, 0x9dea66fc, 0x9dea66fc, 0x9dea66fc, 0xaa4593fe, 0x31c145de, 0x31c145de, 0xaa4593fe, }, 20 }, - { "gfxterm_red", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xfc5938ef, 0x46d56737, 0xfc5938ef, 0x23cf2668, 0xc9cbf769, 0xc9cbf769, 0xa8c549aa, 0xa8c549aa, 0xa8c549aa, 0x561d8866, 0x561d8866, 0x561d8866, 0xcf3e4539, 0xcf3e4539, 0xcf3e4539, 0xc9cbf769, 0x23cf2668, 0x23cf2668, 0xc9cbf769, }, 20 }, - { "gfxterm_red", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xe7160822, 0x54b60115, 0xe7160822, 0x168efa6f, 0x9813a416, 0x9813a416, 0xb774a5aa, 0xb774a5aa, 0xb774a5aa, 0x26af2399, 0x26af2399, 0x26af2399, 0x822f2a5a, 0x822f2a5a, 0x822f2a5a, 0x9813a416, 0x168efa6f, 0x168efa6f, 0x9813a416, }, 20 }, - { "gfxterm_red", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xf655f9b2, 0xe6a3e2d3, 0xf655f9b2, 0xd1d7405f, 0x5fcf013d, 0x5fcf013d, 0x2accaa08, 0x2accaa08, 0x2accaa08, 0xf8dcb27e, 0xf8dcb27e, 0xf8dcb27e, 0x45e51664, 0x45e51664, 0x45e51664, 0x5fcf013d, 0xd1d7405f, 0xd1d7405f, 0x5fcf013d, }, 20 }, - { "gfxterm_red", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x2d85ebdc, 0x79fd4f02, 0x2d85ebdc, 0xc48ae2b6, 0xdd28f52b, 0xdd28f52b, 0x76b28a95, 0x76b28a95, 0x76b28a95, 0x578e7371, 0x578e7371, 0x578e7371, 0x142e3b3b, 0x142e3b3b, 0x142e3b3b, 0xdd28f52b, 0xc48ae2b6, 0xc48ae2b6, 0xdd28f52b, }, 20 }, - { "gfxterm_red", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x29c00f98, 0x8251d825, 0x29c00f98, 0x35a750d1, 0x43d1f34, 0x43d1f34, 0x48b70bc8, 0x48b70bc8, 0x48b70bc8, 0x37bda260, 0x37bda260, 0x37bda260, 0x669ce8d2, 0x669ce8d2, 0x669ce8d2, 0x43d1f34, 0x35a750d1, 0x35a750d1, 0x43d1f34, }, 20 }, - { "gfxterm_high", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x4afab717, 0x2c355b94, 0x4afab717, 0x1166d9d0, 0x59c36f00, 0x59c36f00, 0x620c0067, 0x620c0067, 0x620c0067, 0x1c8c6d01, 0x1c8c6d01, 0x1c8c6d01, 0xc3269013, 0xc3269013, 0xc3269013, 0x59c36f00, 0x1166d9d0, 0x1166d9d0, 0x59c36f00, }, 20 }, - { "gfxterm_high", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xe3daadd4, 0x47f02a6c, 0xe3daadd4, 0x5ea9fb21, 0xaa4593fe, 0xaa4593fe, 0xa8a596c8, 0xa8a596c8, 0xa8a596c8, 0xe509baf, 0xe509baf, 0xe509baf, 0x16f0dc06, 0x16f0dc06, 0x16f0dc06, 0xaa4593fe, 0x5ea9fb21, 0x5ea9fb21, 0xaa4593fe, }, 20 }, - { "gfxterm_high", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xf140d1df, 0x4bcc8e07, 0xf140d1df, 0x7c962dcb, 0xc9cbf769, 0xc9cbf769, 0x3ce35e1d, 0x3ce35e1d, 0x3ce35e1d, 0xc23b9fd1, 0xc23b9fd1, 0xc23b9fd1, 0x5b18528e, 0x5b18528e, 0x5b18528e, 0xc9cbf769, 0x7c962dcb, 0x7c962dcb, 0xc9cbf769, }, 20 }, - { "gfxterm_high", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xe709a12d, 0x54a9a81a, 0xe709a12d, 0xde04d65c, 0x9813a416, 0x9813a416, 0x43fda3fa, 0x43fda3fa, 0x43fda3fa, 0xd22625c9, 0xd22625c9, 0xd22625c9, 0x76a62c0a, 0x76a62c0a, 0x76a62c0a, 0x9813a416, 0xde04d65c, 0xde04d65c, 0x9813a416, }, 20 }, - { "gfxterm_high", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x65eff77c, 0x7519ec1d, 0x65eff77c, 0x1cd7d353, 0x5fcf013d, 0x5fcf013d, 0xf3582c48, 0xf3582c48, 0xf3582c48, 0x2148343e, 0x2148343e, 0x2148343e, 0x9c719024, 0x9c719024, 0x9c719024, 0x5fcf013d, 0x1cd7d353, 0x1cd7d353, 0x5fcf013d, }, 20 }, - { "gfxterm_high", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7318831a, 0x276027c4, 0x7318831a, 0xd7e4f5bb, 0xdd28f52b, 0xdd28f52b, 0xb3c7ef80, 0xb3c7ef80, 0xb3c7ef80, 0x92fb1664, 0x92fb1664, 0x92fb1664, 0xd15b5e2e, 0xd15b5e2e, 0xd15b5e2e, 0xdd28f52b, 0xd7e4f5bb, 0xd7e4f5bb, 0xdd28f52b, }, 20 }, - { "gfxterm_high", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x6927a7d4, 0xc2b67069, 0x6927a7d4, 0xfc345163, 0x43d1f34, 0x43d1f34, 0xa0717008, 0xa0717008, 0xa0717008, 0xdf7bd9a0, 0xdf7bd9a0, 0xdf7bd9a0, 0x8e5a9312, 0x8e5a9312, 0x8e5a9312, 0x43d1f34, 0xfc345163, 0xfc345163, 0x43d1f34, }, 20 }, - { "videotest", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0xe6012f70, 0xe6012f70, 0xe6012f70, 0xe6012f70, 0xe6012f70, }, 5 }, - { "videotest", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xfb6be77b, 0xfb6be77b, 0xfb6be77b, 0xfb6be77b, 0xfb6be77b, }, 5 }, - { "videotest", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0x67c0629f, 0x67c0629f, 0x67c0629f, 0x67c0629f, 0x67c0629f, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x8f20afbb, 0xd8f7abc, 0x8f937344, 0xd3ca643, 0x8e471645, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0xdca764da, 0x9f76da9a, 0x5b04185a, 0x18d5a61a, 0xd60deb2b, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0x7b87af36, 0x7cb96093, 0x75fa307c, 0x72c4ffd9, 0x677c91a2, }, 5 }, - { "videotest", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x72981c65, 0x50120635, 0x378c28c5, 0x15063295, 0xf8b07525, }, 5 }, - { "videotest", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0xc8f64b58, 0xc8f64b58, 0xc8f64b58, 0xc8f64b58, 0xc8f64b58, }, 5 }, - { "videotest", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0x2b499dfa, 0x2b499dfa, 0x2b499dfa, 0x2b499dfa, 0x2b499dfa, }, 5 }, - { "videotest", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0x6156b420, 0x6156b420, 0x6156b420, 0x6156b420, 0x6156b420, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x363285ca, 0x363285ca, 0x363285ca, 0x363285ca, 0x363285ca, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0x25bb37f4, 0x25bb37f4, 0x25bb37f4, 0x25bb37f4, 0x25bb37f4, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0xeeab9e91, 0xeeab9e91, 0xeeab9e91, 0xeeab9e91, 0xeeab9e91, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x26a9a50b, 0x26a9a50b, 0x26a9a50b, 0x26a9a50b, 0x26a9a50b, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0x2c0f4fe7, 0x2c0f4fe7, 0x2c0f4fe7, 0x2c0f4fe7, 0x2c0f4fe7, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x46c11052, 0x46c11052, 0x46c11052, 0x46c11052, 0x46c11052, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0xe56cf615, 0xcd2be572, 0xb5e2d0db, 0x9da5c3bc, 0x4470bb89, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x2a25b871, 0x4bf85361, 0xe99e6e51, 0x88438541, 0xa8be62c0, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x81523037, 0xd8c0bfd3, 0x32772fff, 0x6be5a01b, 0xe2f47956, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x1833bb41, 0x1833bb41, 0x1833bb41, 0x1833bb41, 0x1833bb41, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0x2c39a0e8, 0x2c39a0e8, 0x2c39a0e8, 0x2c39a0e8, 0x2c39a0e8, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0xf0d4c23, 0xf0d4c23, 0xf0d4c23, 0xf0d4c23, 0xf0d4c23, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x456d063c, 0x456d063c, 0x456d063c, 0x456d063c, 0x456d063c, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0x47e15a2e, 0x47e15a2e, 0x47e15a2e, 0x47e15a2e, 0x47e15a2e, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x54d7300d, 0x54d7300d, 0x54d7300d, 0x54d7300d, 0x54d7300d, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x770da211, 0x8ef2528e, 0x811e35de, 0x78e1c541, 0x9ec6fb7e, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0xeb181fbc, 0xae648cc1, 0x61e13946, 0x249daa3b, 0xfb0624b9, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x2b6f64dc, 0xc25f8431, 0xfce2d3f7, 0x15d2331a, 0x81987c7b, }, 5 }, - { "videotest", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0xa260f7dd, 0x3e2f4980, 0x9f13fd96, 0x35c43cb, 0xd886e34b, }, 5 }, - { "videotest", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x41a9bff8, 0xa0d3f7c3, 0x86b1597f, 0x67cb1144, 0xca740407, }, 5 }, - { "videotest", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0x8f7a3b6d, 0xcb84c6e3, 0x687c071, 0x42793dff, 0x996dbba4, }, 5 }, + { "cmdline_cat", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x7dbff368, 0x7dbff368, 0x5a5bdc8d, 0x5a5bdc8d, 0x79753177, 0x79753177, 0xd01ede5b, 0xd01ede5b, 0x13708a73, 0x13708a73, 0x90186de3, 0x90186de3, 0xe63d02a2, 0xe63d02a2, 0x2c9dc262, 0x2c9dc262, 0x3eebd7b, 0x3eebd7b, 0xe8f3a5d8, 0xe8f3a5d8, 0xd38ecfe3, 0xd38ecfe3, 0x51878485, 0x51878485, 0xcbdb6d67, 0xcbdb6d67, 0xca25582, 0xca25582, 0x5bea0484, 0x5bea0484, 0x9ec5f71d, 0x9ec5f71d, 0x3f0bd7bc, 0x3f0bd7bc, 0xdbb0a5d2, 0xdbb0a5d2, 0xea710e2f, 0xea710e2f, 0xd14933fe, 0xd14933fe, 0x4906b783, 0xffd1d04b, 0xa159bdf9, 0xa159bdf9, }, 45 }, + { "cmdline_cat", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xf1546749, 0xf1546749, 0x95d30576, 0x95d30576, 0x77f13935, 0x77f13935, 0xcc296836, 0xcc296836, 0x9af42bc7, 0x9af42bc7, 0x84c23709, 0x84c23709, 0x26b5a3c5, 0x26b5a3c5, 0x52d943fb, 0x52d943fb, 0x38beda82, 0x38beda82, 0xc12306b1, 0xc12306b1, 0xed251115, 0xed251115, 0xe0099a2f, 0xe0099a2f, 0xee929157, 0xee929157, 0xd96a1169, 0xd96a1169, 0x42fac799, 0x42fac799, 0x635af416, 0x635af416, 0x8e90342f, 0x8e90342f, 0xed467cbf, 0xed467cbf, 0x999fc60b, 0x999fc60b, 0xb45d2b1f, 0xb45d2b1f, 0x7e23ccef, 0x8e988beb, 0x8783fdf8, 0x8783fdf8, }, 45 }, + { "cmdline_cat", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x50b82239, 0x50b82239, 0x82c36c12, 0x82c36c12, 0x6311208d, 0x6311208d, 0x816bd4b3, 0x816bd4b3, 0xc9281fd0, 0xc9281fd0, 0x75767bac, 0x75767bac, 0x52edeac, 0x52edeac, 0xfdb551f7, 0xfdb551f7, 0xba21cd3, 0xba21cd3, 0xf2b3468a, 0xf2b3468a, 0xd5560323, 0xd5560323, 0x12c650f6, 0x12c650f6, 0x3d6c5861, 0x3d6c5861, 0x50062423, 0x50062423, 0x2ce22983, 0x2ce22983, 0x4996bc4d, 0x4996bc4d, 0x50450525, 0x50450525, 0xe1c94312, 0xe1c94312, 0x21224aac, 0x21224aac, 0x94cbe214, 0x94cbe214, 0x4578c664, 0x38a9dbd2, 0xa9eb4c48, 0xa9eb4c48, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xbb687653, 0xbb687653, 0xa81427a7, 0xa81427a7, 0x71d7f3b, 0x71d7f3b, 0x25fea6ca, 0x25fea6ca, 0x17c19d74, 0x17c19d74, 0x4779bf48, 0x4779bf48, 0xe424e759, 0xe424e759, 0xb57fb5ae, 0xb57fb5ae, 0xd877002b, 0xd877002b, 0xdd8d7442, 0xdd8d7442, 0xe2536fde, 0xe2536fde, 0x1ebba341, 0x1ebba341, 0xef042176, 0xef042176, 0x6137f228, 0x6137f228, 0xf04a8558, 0xf04a8558, 0xff72172d, 0xff72172d, 0x5f26278f, 0x5f26278f, 0x3ed777c, 0x3ed777c, 0xb1d686e, 0xb1d686e, 0x5cead249, 0x5cead249, 0x271487f6, 0x9b7201b9, 0x6c2f147d, 0x6c2f147d, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x378dc141, 0x378dc141, 0xc7564497, 0xc7564497, 0xd20e9dba, 0xd20e9dba, 0xf84e8efb, 0xf84e8efb, 0x620d984, 0x620d984, 0x509042b4, 0x509042b4, 0x2bf32e11, 0x2bf32e11, 0x7c6fe3a0, 0x7c6fe3a0, 0x18106e6f, 0x18106e6f, 0xba983948, 0xba983948, 0xd85321cc, 0xd85321cc, 0xc22777cd, 0xc22777cd, 0x85b737c8, 0x85b737c8, 0x55590c10, 0x55590c10, 0x371ba701, 0x371ba701, 0x2da6264, 0x2da6264, 0x77c1ff46, 0x77c1ff46, 0xf2485577, 0xf2485577, 0x93e9eeeb, 0x93e9eeeb, 0x1460059, 0x1460059, 0xfbbbaa1, 0xa03c490a, 0x234dcb08, 0x234dcb08, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xd803b53b, 0xd803b53b, 0x70b7ae8b, 0x70b7ae8b, 0xa20d9a15, 0xa20d9a15, 0x6113d33b, 0x6113d33b, 0xfd38d301, 0xfd38d301, 0x8b04db4, 0x8b04db4, 0xdae859df, 0xdae859df, 0x80cf138b, 0x80cf138b, 0xdfa6ef9, 0xdfa6ef9, 0x856adaf0, 0x856adaf0, 0x7023cc2d, 0x7023cc2d, 0xad7e7d54, 0xad7e7d54, 0xde8eff49, 0xde8eff49, 0x34355cc3, 0x34355cc3, 0x25adccda, 0x25adccda, 0x6d6c350d, 0x6d6c350d, 0x1c49b499, 0x1c49b499, 0x8188f1b4, 0x8188f1b4, 0x5556dc0c, 0x5556dc0c, 0xbd9ef1f5, 0xbd9ef1f5, 0x5176575b, 0x19da9ee1, 0x6e2f07c, 0x6e2f07c, }, 45 }, + { "cmdline_cat", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xed7d2809, 0xed7d2809, 0x52c14224, 0x52c14224, 0xec52d912, 0xec52d912, 0x63276ae2, 0x63276ae2, 0xeeb4bfa4, 0xeeb4bfa4, 0xdf0f1ff0, 0xdf0f1ff0, 0xe2021708, 0xe2021708, 0x67c17085, 0x67c17085, 0x646e4d78, 0x646e4d78, 0x3b15f4b6, 0x3b15f4b6, 0xf4945ac5, 0xf4945ac5, 0x6cf60c00, 0x6cf60c00, 0x126648cd, 0x126648cd, 0xe7b8e348, 0xe7b8e348, 0x1626e35f, 0x1626e35f, 0x8022976c, 0x8022976c, 0xbc7e6d22, 0xbc7e6d22, 0xa2d50ad6, 0xa2d50ad6, 0x5072fea, 0x5072fea, 0x8481a563, 0x8481a563, 0x60a95143, 0x12fda168, 0xc8fe0549, 0xc8fe0549, }, 45 }, + { "cmdline_cat", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x7dbff368, 0x7dbff368, 0x5a5bdc8d, 0x5a5bdc8d, 0x79753177, 0x79753177, 0xd01ede5b, 0xd01ede5b, 0x13708a73, 0x13708a73, 0x90186de3, 0x90186de3, 0xe63d02a2, 0xe63d02a2, 0x2c9dc262, 0x2c9dc262, 0x3eebd7b, 0x3eebd7b, 0xe8f3a5d8, 0xe8f3a5d8, 0xd38ecfe3, 0xd38ecfe3, 0x51878485, 0x51878485, 0xcbdb6d67, 0xcbdb6d67, 0xca25582, 0xca25582, 0x5bea0484, 0x5bea0484, 0x9ec5f71d, 0x9ec5f71d, 0x3f0bd7bc, 0x3f0bd7bc, 0xdbb0a5d2, 0xdbb0a5d2, 0xea710e2f, 0xea710e2f, 0xd14933fe, 0xd14933fe, 0x4906b783, 0xffd1d04b, 0xa159bdf9, 0xa159bdf9, }, 45 }, + { "cmdline_cat", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0xf1546749, 0xf1546749, 0x95d30576, 0x95d30576, 0x77f13935, 0x77f13935, 0xcc296836, 0xcc296836, 0x9af42bc7, 0x9af42bc7, 0x84c23709, 0x84c23709, 0x26b5a3c5, 0x26b5a3c5, 0x52d943fb, 0x52d943fb, 0x38beda82, 0x38beda82, 0xc12306b1, 0xc12306b1, 0xed251115, 0xed251115, 0xe0099a2f, 0xe0099a2f, 0xee929157, 0xee929157, 0xd96a1169, 0xd96a1169, 0x42fac799, 0x42fac799, 0x635af416, 0x635af416, 0x8e90342f, 0x8e90342f, 0xed467cbf, 0xed467cbf, 0x999fc60b, 0x999fc60b, 0xb45d2b1f, 0xb45d2b1f, 0x7e23ccef, 0x8e988beb, 0x8783fdf8, 0x8783fdf8, }, 45 }, + { "cmdline_cat", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x50b82239, 0x50b82239, 0x82c36c12, 0x82c36c12, 0x6311208d, 0x6311208d, 0x816bd4b3, 0x816bd4b3, 0xc9281fd0, 0xc9281fd0, 0x75767bac, 0x75767bac, 0x52edeac, 0x52edeac, 0xfdb551f7, 0xfdb551f7, 0xba21cd3, 0xba21cd3, 0xf2b3468a, 0xf2b3468a, 0xd5560323, 0xd5560323, 0x12c650f6, 0x12c650f6, 0x3d6c5861, 0x3d6c5861, 0x50062423, 0x50062423, 0x2ce22983, 0x2ce22983, 0x4996bc4d, 0x4996bc4d, 0x50450525, 0x50450525, 0xe1c94312, 0xe1c94312, 0x21224aac, 0x21224aac, 0x94cbe214, 0x94cbe214, 0x4578c664, 0x38a9dbd2, 0xa9eb4c48, 0xa9eb4c48, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0x93fbd3a3, 0x93fbd3a3, 0x1617bee0, 0x1617bee0, 0x4bfbae7f, 0x4bfbae7f, 0xa3558248, 0xa3558248, 0xaf468a11, 0xaf468a11, 0x68ac5986, 0x68ac5986, 0xd8065600, 0xd8065600, 0xef6c6222, 0xef6c6222, 0x1a04371, 0x1a04371, 0xc92981b6, 0xc92981b6, 0x53f9bfc8, 0x53f9bfc8, 0xfef01300, 0xfef01300, 0xce753805, 0xce753805, 0x858f6540, 0x858f6540, 0x6429dae4, 0x6429dae4, 0x19222aa5, 0x19222aa5, 0x3f9a0303, 0x3f9a0303, 0x978a47da, 0x978a47da, 0x6bf7f199, 0x6bf7f199, 0x97dab6d, 0x97dab6d, 0xeb643dbd, 0x9fe6a006, 0x2b7a0b5b, 0x2b7a0b5b, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xe8381636, 0xe8381636, 0x977b32f5, 0x977b32f5, 0x54bb62c1, 0x54bb62c1, 0xe26211f2, 0xe26211f2, 0xb0d0aca3, 0xb0d0aca3, 0x8d1f7491, 0x8d1f7491, 0x261a3820, 0x261a3820, 0x571c16d3, 0x571c16d3, 0xdc5fb880, 0xdc5fb880, 0xc8b086fe, 0xc8b086fe, 0x55b07770, 0x55b07770, 0x1d5e160, 0x1d5e160, 0x5e5dddc8, 0x5e5dddc8, 0xceeaa332, 0xceeaa332, 0x81c9d3f3, 0x81c9d3f3, 0xa6bbab67, 0xa6bbab67, 0x9366a264, 0x9366a264, 0x4bcbc84c, 0x4bcbc84c, 0x8aacda73, 0x8aacda73, 0x356159d0, 0x356159d0, 0x74872545, 0x5a28a86f, 0x3a1f5494, 0x3a1f5494, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0xccbd401, 0xccbd401, 0x35859629, 0x35859629, 0x269f013b, 0x269f013b, 0xe8c8196, 0xe8c8196, 0x95e2849c, 0x95e2849c, 0xb2019543, 0xb2019543, 0xf739b6c9, 0xf739b6c9, 0xd8227519, 0xd8227519, 0x6b1ae8cf, 0x6b1ae8cf, 0x84fbe9b2, 0x84fbe9b2, 0xed69a305, 0xed69a305, 0x15f4f0cf, 0x15f4f0cf, 0x57ce0973, 0x57ce0973, 0x3f5b0b97, 0x3f5b0b97, 0xc3e87bef, 0xc3e87bef, 0x3ac7584b, 0x3ac7584b, 0xdb95f2c7, 0xdb95f2c7, 0xc1942d4c, 0xc1942d4c, 0x17e9634e, 0x17e9634e, 0xd8dd41a3, 0xd8dd41a3, 0x927a8a2f, 0x339d3240, 0x398e6a2a, 0x398e6a2a, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xa06498a0, 0xa06498a0, 0xd1336ad7, 0xd1336ad7, 0x68c888e0, 0x68c888e0, 0xf01fb74, 0xf01fb74, 0x6b743235, 0x6b743235, 0xe7b71a49, 0xe7b71a49, 0x798da4d7, 0x798da4d7, 0x5398f44b, 0x5398f44b, 0x4794ee5e, 0x4794ee5e, 0x61c2cb0d, 0x61c2cb0d, 0xad3fcef3, 0xad3fcef3, 0xd9b6f291, 0xd9b6f291, 0xbaf0962d, 0xbaf0962d, 0x11848b9e, 0x11848b9e, 0xb8f3d2bf, 0xb8f3d2bf, 0x3f9978, 0x3f9978, 0xafd76c24, 0xafd76c24, 0xee0b9b9e, 0xee0b9b9e, 0x1f80451e, 0x1f80451e, 0x817e030a, 0x817e030a, 0x64ee9a5d, 0x1d187aed, 0xb2c05a4a, 0xb2c05a4a, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x95c83b7d, 0x95c83b7d, 0xb8cac2b5, 0xb8cac2b5, 0xf0ef977f, 0xf0ef977f, 0xc4640770, 0xc4640770, 0x8ea8595e, 0x8ea8595e, 0xc7d26302, 0xc7d26302, 0x6f756fbc, 0x6f756fbc, 0x68bc6258, 0x68bc6258, 0xe77cff10, 0xe77cff10, 0x835ae8e5, 0x835ae8e5, 0x622cfc05, 0x622cfc05, 0xe192499f, 0xe192499f, 0x3b976218, 0x3b976218, 0xe2dcd75, 0xe2dcd75, 0xed05eae8, 0xed05eae8, 0xc0b8ee9a, 0xc0b8ee9a, 0x255ec66a, 0x255ec66a, 0x3391d9b6, 0x3391d9b6, 0x779834b3, 0x779834b3, 0xdf77a37f, 0xdf77a37f, 0xd3cc8a1d, 0xfec30b6e, 0x884fa360, 0x884fa360, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x698515fa, 0x698515fa, 0xc313ebe6, 0xc313ebe6, 0x32b9228f, 0x32b9228f, 0xa58d78e8, 0xa58d78e8, 0xf41d5153, 0xf41d5153, 0xdfa3af16, 0xdfa3af16, 0xd4a68422, 0xd4a68422, 0xa7ea67e0, 0xa7ea67e0, 0xaee4c8f6, 0xaee4c8f6, 0x78ddd8aa, 0x78ddd8aa, 0xe662b827, 0xe662b827, 0x190ab892, 0x190ab892, 0x7c1e04ab, 0x7c1e04ab, 0xae4e2ed2, 0xae4e2ed2, 0x9ac52f8d, 0x9ac52f8d, 0x7e7b6776, 0x7e7b6776, 0x21c37700, 0x21c37700, 0x4fc11e7c, 0x4fc11e7c, 0x612a17d, 0x612a17d, 0x1f549440, 0x1f549440, 0xd6ce5af0, 0x2751d45f, 0x41e24797, 0x41e24797, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x7a06e04b, 0x7a06e04b, 0x122f59ab, 0x122f59ab, 0x993a50b9, 0x993a50b9, 0x5545f8f, 0x5545f8f, 0xcdd2b587, 0xcdd2b587, 0x18bec138, 0x18bec138, 0xa9b4345d, 0xa9b4345d, 0x92c6eb1c, 0x92c6eb1c, 0x2aa44d63, 0x2aa44d63, 0xc9e7b549, 0xc9e7b549, 0x24732d85, 0x24732d85, 0xeedce06, 0xeedce06, 0x69a732a1, 0x69a732a1, 0xc53906e5, 0xc53906e5, 0x306e0f4b, 0x306e0f4b, 0x895e6f09, 0x895e6f09, 0x27f1c24e, 0x27f1c24e, 0x76a2b606, 0x76a2b606, 0x9fdd1ff3, 0x9fdd1ff3, 0x408d0a19, 0x408d0a19, 0xc9b3f877, 0xce19a637, 0x8cfd7321, 0x8cfd7321, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x9fa21cbe, 0x9fa21cbe, 0xa9ad84e6, 0xa9ad84e6, 0x4f4ccbc, 0x4f4ccbc, 0x6a4f5fda, 0x6a4f5fda, 0x4d4ccb50, 0x4d4ccb50, 0xb854236c, 0xb854236c, 0x990a5b4a, 0x990a5b4a, 0xa9dba8c8, 0xa9dba8c8, 0xe12b4ca1, 0xe12b4ca1, 0x4200ebc0, 0x4200ebc0, 0x86a931cf, 0x86a931cf, 0xda3a178, 0xda3a178, 0x2739917d, 0x2739917d, 0x48005e41, 0x48005e41, 0x550a94ac, 0x550a94ac, 0x73f363b6, 0x73f363b6, 0x4811082a, 0x4811082a, 0xdc025f10, 0xdc025f10, 0x4f18937e, 0x4f18937e, 0xa3749fd8, 0xa3749fd8, 0x93ce5c0b, 0xdddd4de6, 0x97f43654, 0x97f43654, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x7d9b5dd7, 0x7d9b5dd7, 0x42e1176a, 0x42e1176a, 0x7e2da576, 0x7e2da576, 0xd5a8afa, 0xd5a8afa, 0x3eb2146b, 0x3eb2146b, 0x60d9b3, 0x60d9b3, 0xb893f5ca, 0xb893f5ca, 0xd431b2bf, 0xd431b2bf, 0x8ea1b6a6, 0x8ea1b6a6, 0x4d730ad0, 0x4d730ad0, 0x28d1888b, 0x28d1888b, 0x6d8c3672, 0x6d8c3672, 0x65dec2dd, 0x65dec2dd, 0x9d7c6d99, 0x9d7c6d99, 0xdfcd1eba, 0xdfcd1eba, 0xed4fb650, 0xed4fb650, 0xd9f1574c, 0xd9f1574c, 0x2b05a17e, 0x2b05a17e, 0x64e652f5, 0x64e652f5, 0x5f83fdb1, 0x5f83fdb1, 0x7918b180, 0xf54e3c4a, 0xe26cf2de, 0xe26cf2de, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0x93fbd3a3, 0x93fbd3a3, 0x1617bee0, 0x1617bee0, 0x4bfbae7f, 0x4bfbae7f, 0xa3558248, 0xa3558248, 0xaf468a11, 0xaf468a11, 0x68ac5986, 0x68ac5986, 0xd8065600, 0xd8065600, 0xef6c6222, 0xef6c6222, 0x1a04371, 0x1a04371, 0xc92981b6, 0xc92981b6, 0x53f9bfc8, 0x53f9bfc8, 0xfef01300, 0xfef01300, 0xce753805, 0xce753805, 0x858f6540, 0x858f6540, 0x6429dae4, 0x6429dae4, 0x19222aa5, 0x19222aa5, 0x3f9a0303, 0x3f9a0303, 0x978a47da, 0x978a47da, 0x6bf7f199, 0x6bf7f199, 0x97dab6d, 0x97dab6d, 0xeb643dbd, 0x9fe6a006, 0x2b7a0b5b, 0x2b7a0b5b, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xe8381636, 0xe8381636, 0x977b32f5, 0x977b32f5, 0x54bb62c1, 0x54bb62c1, 0xe26211f2, 0xe26211f2, 0xb0d0aca3, 0xb0d0aca3, 0x8d1f7491, 0x8d1f7491, 0x261a3820, 0x261a3820, 0x571c16d3, 0x571c16d3, 0xdc5fb880, 0xdc5fb880, 0xc8b086fe, 0xc8b086fe, 0x55b07770, 0x55b07770, 0x1d5e160, 0x1d5e160, 0x5e5dddc8, 0x5e5dddc8, 0xceeaa332, 0xceeaa332, 0x81c9d3f3, 0x81c9d3f3, 0xa6bbab67, 0xa6bbab67, 0x9366a264, 0x9366a264, 0x4bcbc84c, 0x4bcbc84c, 0x8aacda73, 0x8aacda73, 0x356159d0, 0x356159d0, 0x74872545, 0x5a28a86f, 0x3a1f5494, 0x3a1f5494, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0xccbd401, 0xccbd401, 0x35859629, 0x35859629, 0x269f013b, 0x269f013b, 0xe8c8196, 0xe8c8196, 0x95e2849c, 0x95e2849c, 0xb2019543, 0xb2019543, 0xf739b6c9, 0xf739b6c9, 0xd8227519, 0xd8227519, 0x6b1ae8cf, 0x6b1ae8cf, 0x84fbe9b2, 0x84fbe9b2, 0xed69a305, 0xed69a305, 0x15f4f0cf, 0x15f4f0cf, 0x57ce0973, 0x57ce0973, 0x3f5b0b97, 0x3f5b0b97, 0xc3e87bef, 0xc3e87bef, 0x3ac7584b, 0x3ac7584b, 0xdb95f2c7, 0xdb95f2c7, 0xc1942d4c, 0xc1942d4c, 0x17e9634e, 0x17e9634e, 0xd8dd41a3, 0xd8dd41a3, 0x927a8a2f, 0x339d3240, 0x398e6a2a, 0x398e6a2a, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xa06498a0, 0xa06498a0, 0xd1336ad7, 0xd1336ad7, 0x68c888e0, 0x68c888e0, 0xf01fb74, 0xf01fb74, 0x6b743235, 0x6b743235, 0xe7b71a49, 0xe7b71a49, 0x798da4d7, 0x798da4d7, 0x5398f44b, 0x5398f44b, 0x4794ee5e, 0x4794ee5e, 0x61c2cb0d, 0x61c2cb0d, 0xad3fcef3, 0xad3fcef3, 0xd9b6f291, 0xd9b6f291, 0xbaf0962d, 0xbaf0962d, 0x11848b9e, 0x11848b9e, 0xb8f3d2bf, 0xb8f3d2bf, 0x3f9978, 0x3f9978, 0xafd76c24, 0xafd76c24, 0xee0b9b9e, 0xee0b9b9e, 0x1f80451e, 0x1f80451e, 0x817e030a, 0x817e030a, 0x64ee9a5d, 0x1d187aed, 0xb2c05a4a, 0xb2c05a4a, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x95c83b7d, 0x95c83b7d, 0xb8cac2b5, 0xb8cac2b5, 0xf0ef977f, 0xf0ef977f, 0xc4640770, 0xc4640770, 0x8ea8595e, 0x8ea8595e, 0xc7d26302, 0xc7d26302, 0x6f756fbc, 0x6f756fbc, 0x68bc6258, 0x68bc6258, 0xe77cff10, 0xe77cff10, 0x835ae8e5, 0x835ae8e5, 0x622cfc05, 0x622cfc05, 0xe192499f, 0xe192499f, 0x3b976218, 0x3b976218, 0xe2dcd75, 0xe2dcd75, 0xed05eae8, 0xed05eae8, 0xc0b8ee9a, 0xc0b8ee9a, 0x255ec66a, 0x255ec66a, 0x3391d9b6, 0x3391d9b6, 0x779834b3, 0x779834b3, 0xdf77a37f, 0xdf77a37f, 0xd3cc8a1d, 0xfec30b6e, 0x884fa360, 0x884fa360, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x698515fa, 0x698515fa, 0xc313ebe6, 0xc313ebe6, 0x32b9228f, 0x32b9228f, 0xa58d78e8, 0xa58d78e8, 0xf41d5153, 0xf41d5153, 0xdfa3af16, 0xdfa3af16, 0xd4a68422, 0xd4a68422, 0xa7ea67e0, 0xa7ea67e0, 0xaee4c8f6, 0xaee4c8f6, 0x78ddd8aa, 0x78ddd8aa, 0xe662b827, 0xe662b827, 0x190ab892, 0x190ab892, 0x7c1e04ab, 0x7c1e04ab, 0xae4e2ed2, 0xae4e2ed2, 0x9ac52f8d, 0x9ac52f8d, 0x7e7b6776, 0x7e7b6776, 0x21c37700, 0x21c37700, 0x4fc11e7c, 0x4fc11e7c, 0x612a17d, 0x612a17d, 0x1f549440, 0x1f549440, 0xd6ce5af0, 0x2751d45f, 0x41e24797, 0x41e24797, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x7a06e04b, 0x7a06e04b, 0x122f59ab, 0x122f59ab, 0x993a50b9, 0x993a50b9, 0x5545f8f, 0x5545f8f, 0xcdd2b587, 0xcdd2b587, 0x18bec138, 0x18bec138, 0xa9b4345d, 0xa9b4345d, 0x92c6eb1c, 0x92c6eb1c, 0x2aa44d63, 0x2aa44d63, 0xc9e7b549, 0xc9e7b549, 0x24732d85, 0x24732d85, 0xeedce06, 0xeedce06, 0x69a732a1, 0x69a732a1, 0xc53906e5, 0xc53906e5, 0x306e0f4b, 0x306e0f4b, 0x895e6f09, 0x895e6f09, 0x27f1c24e, 0x27f1c24e, 0x76a2b606, 0x76a2b606, 0x9fdd1ff3, 0x9fdd1ff3, 0x408d0a19, 0x408d0a19, 0xc9b3f877, 0xce19a637, 0x8cfd7321, 0x8cfd7321, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x9fa21cbe, 0x9fa21cbe, 0xa9ad84e6, 0xa9ad84e6, 0x4f4ccbc, 0x4f4ccbc, 0x6a4f5fda, 0x6a4f5fda, 0x4d4ccb50, 0x4d4ccb50, 0xb854236c, 0xb854236c, 0x990a5b4a, 0x990a5b4a, 0xa9dba8c8, 0xa9dba8c8, 0xe12b4ca1, 0xe12b4ca1, 0x4200ebc0, 0x4200ebc0, 0x86a931cf, 0x86a931cf, 0xda3a178, 0xda3a178, 0x2739917d, 0x2739917d, 0x48005e41, 0x48005e41, 0x550a94ac, 0x550a94ac, 0x73f363b6, 0x73f363b6, 0x4811082a, 0x4811082a, 0xdc025f10, 0xdc025f10, 0x4f18937e, 0x4f18937e, 0xa3749fd8, 0xa3749fd8, 0x93ce5c0b, 0xdddd4de6, 0x97f43654, 0x97f43654, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x7d9b5dd7, 0x7d9b5dd7, 0x42e1176a, 0x42e1176a, 0x7e2da576, 0x7e2da576, 0xd5a8afa, 0xd5a8afa, 0x3eb2146b, 0x3eb2146b, 0x60d9b3, 0x60d9b3, 0xb893f5ca, 0xb893f5ca, 0xd431b2bf, 0xd431b2bf, 0x8ea1b6a6, 0x8ea1b6a6, 0x4d730ad0, 0x4d730ad0, 0x28d1888b, 0x28d1888b, 0x6d8c3672, 0x6d8c3672, 0x65dec2dd, 0x65dec2dd, 0x9d7c6d99, 0x9d7c6d99, 0xdfcd1eba, 0xdfcd1eba, 0xed4fb650, 0xed4fb650, 0xd9f1574c, 0xd9f1574c, 0x2b05a17e, 0x2b05a17e, 0x64e652f5, 0x64e652f5, 0x5f83fdb1, 0x5f83fdb1, 0x7918b180, 0xf54e3c4a, 0xe26cf2de, 0xe26cf2de, }, 45 }, + { "cmdline_cat", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0xbb687653, 0xbb687653, 0xa81427a7, 0xa81427a7, 0x71d7f3b, 0x71d7f3b, 0x25fea6ca, 0x25fea6ca, 0x17c19d74, 0x17c19d74, 0x4779bf48, 0x4779bf48, 0xe424e759, 0xe424e759, 0xb57fb5ae, 0xb57fb5ae, 0xd877002b, 0xd877002b, 0xdd8d7442, 0xdd8d7442, 0xe2536fde, 0xe2536fde, 0x1ebba341, 0x1ebba341, 0xef042176, 0xef042176, 0x6137f228, 0x6137f228, 0xf04a8558, 0xf04a8558, 0xff72172d, 0xff72172d, 0x5f26278f, 0x5f26278f, 0x3ed777c, 0x3ed777c, 0xb1d686e, 0xb1d686e, 0x5cead249, 0x5cead249, 0x271487f6, 0x9b7201b9, 0x6c2f147d, 0x6c2f147d, }, 45 }, + { "cmdline_cat", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x378dc141, 0x378dc141, 0xc7564497, 0xc7564497, 0xd20e9dba, 0xd20e9dba, 0xf84e8efb, 0xf84e8efb, 0x620d984, 0x620d984, 0x509042b4, 0x509042b4, 0x2bf32e11, 0x2bf32e11, 0x7c6fe3a0, 0x7c6fe3a0, 0x18106e6f, 0x18106e6f, 0xba983948, 0xba983948, 0xd85321cc, 0xd85321cc, 0xc22777cd, 0xc22777cd, 0x85b737c8, 0x85b737c8, 0x55590c10, 0x55590c10, 0x371ba701, 0x371ba701, 0x2da6264, 0x2da6264, 0x77c1ff46, 0x77c1ff46, 0xf2485577, 0xf2485577, 0x93e9eeeb, 0x93e9eeeb, 0x1460059, 0x1460059, 0xfbbbaa1, 0xa03c490a, 0x234dcb08, 0x234dcb08, }, 45 }, + { "cmdline_cat", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xd803b53b, 0xd803b53b, 0x70b7ae8b, 0x70b7ae8b, 0xa20d9a15, 0xa20d9a15, 0x6113d33b, 0x6113d33b, 0xfd38d301, 0xfd38d301, 0x8b04db4, 0x8b04db4, 0xdae859df, 0xdae859df, 0x80cf138b, 0x80cf138b, 0xdfa6ef9, 0xdfa6ef9, 0x856adaf0, 0x856adaf0, 0x7023cc2d, 0x7023cc2d, 0xad7e7d54, 0xad7e7d54, 0xde8eff49, 0xde8eff49, 0x34355cc3, 0x34355cc3, 0x25adccda, 0x25adccda, 0x6d6c350d, 0x6d6c350d, 0x1c49b499, 0x1c49b499, 0x8188f1b4, 0x8188f1b4, 0x5556dc0c, 0x5556dc0c, 0xbd9ef1f5, 0xbd9ef1f5, 0x5176575b, 0x19da9ee1, 0x6e2f07c, 0x6e2f07c, }, 45 }, + { "gfxterm_menu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xc5faf369, 0x64eb297a, 0xc5faf369, 0x860c3e2e, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x860c3e2e, 0x860c3e2e, 0x59c36f00, }, 20 }, + { "gfxterm_menu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xd50b0276, 0x23b87c98, 0xd50b0276, 0xfb0e8709, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0xfb0e8709, 0xfb0e8709, 0xaa4593fe, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x353bd15d, 0x79836ff2, 0x353bd15d, 0x682cbcd9, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0x682cbcd9, 0x682cbcd9, 0xc9cbf769, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x22bcc2fc, 0xc6c23ab4, 0x22bcc2fc, 0x72a46652, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0x72a46652, 0x72a46652, 0x9813a416, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x3afb9165, 0x767dd6a7, 0x3afb9165, 0x31409f, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0x31409f, 0x31409f, 0x5fcf013d, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xe13f0039, 0xb5783cd1, 0xe13f0039, 0x814ca453, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0x814ca453, 0x814ca453, 0xdd28f52b, }, 20 }, + { "gfxterm_menu", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x154ac813, 0x5c191673, 0x154ac813, 0xeb0cc57e, 0x43d1f34, 0x43d1f34, 0xd204ac75, 0xd204ac75, 0xd204ac75, 0xad0e05dd, 0xad0e05dd, 0xad0e05dd, 0x452e3cf4, 0x452e3cf4, 0x452e3cf4, 0x43d1f34, 0xeb0cc57e, 0xeb0cc57e, 0x43d1f34, }, 20 }, + { "gfxterm_menu", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xc5faf369, 0x64eb297a, 0xc5faf369, 0x860c3e2e, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x860c3e2e, 0x860c3e2e, 0x59c36f00, }, 20 }, + { "gfxterm_menu", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0xd50b0276, 0x23b87c98, 0xd50b0276, 0xfb0e8709, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0xfb0e8709, 0xfb0e8709, 0xaa4593fe, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x353bd15d, 0x79836ff2, 0x353bd15d, 0x682cbcd9, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0x682cbcd9, 0x682cbcd9, 0xc9cbf769, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xe967dfb6, 0x7fedccee, 0xe967dfb6, 0xad6c250a, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0xad6c250a, 0xad6c250a, 0x5387d57f, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x985bd9b5, 0xd5604814, 0x985bd9b5, 0x2233942a, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0x2233942a, 0x2233942a, 0xf83ee7aa, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x928c0a8e, 0xd25dcf03, 0x928c0a8e, 0x83f9bfdb, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x83f9bfdb, 0x83f9bfdb, 0x724366e5, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x116c0258, 0xed7d4786, 0x116c0258, 0xfef8bf61, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0xfef8bf61, 0xfef8bf61, 0x5387d57f, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xd49b1c35, 0x37f70b09, 0xd49b1c35, 0xa55122d9, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0xa55122d9, 0xa55122d9, 0xf83ee7aa, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x2b3f0273, 0x6da0f134, 0x2b3f0273, 0xd9ed8903, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0xd9ed8903, 0xd9ed8903, 0x724366e5, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x1e6b0284, 0x18f0ad39, 0x1e6b0284, 0x1e0bba22, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0x1e0bba22, 0x1e0bba22, 0x1c955882, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x1f279ca1, 0x976cb6e3, 0x1f279ca1, 0xdb3505a5, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0xdb3505a5, 0xdb3505a5, 0x4d266f7a, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x21235dde, 0x13b8b442, 0x21235dde, 0xbdd75c39, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0xbdd75c39, 0xbdd75c39, 0x1ed9d731, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xe967dfb6, 0x7fedccee, 0xe967dfb6, 0xad6c250a, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0xad6c250a, 0xad6c250a, 0x5387d57f, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x985bd9b5, 0xd5604814, 0x985bd9b5, 0x2233942a, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0x2233942a, 0x2233942a, 0xf83ee7aa, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x928c0a8e, 0xd25dcf03, 0x928c0a8e, 0x83f9bfdb, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x83f9bfdb, 0x83f9bfdb, 0x724366e5, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x116c0258, 0xed7d4786, 0x116c0258, 0xfef8bf61, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0xfef8bf61, 0xfef8bf61, 0x5387d57f, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xd49b1c35, 0x37f70b09, 0xd49b1c35, 0xa55122d9, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0xa55122d9, 0xa55122d9, 0xf83ee7aa, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x2b3f0273, 0x6da0f134, 0x2b3f0273, 0xd9ed8903, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0xd9ed8903, 0xd9ed8903, 0x724366e5, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x1e6b0284, 0x18f0ad39, 0x1e6b0284, 0x1e0bba22, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0x1e0bba22, 0x1e0bba22, 0x1c955882, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x1f279ca1, 0x976cb6e3, 0x1f279ca1, 0xdb3505a5, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0xdb3505a5, 0xdb3505a5, 0x4d266f7a, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x21235dde, 0x13b8b442, 0x21235dde, 0xbdd75c39, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0xbdd75c39, 0xbdd75c39, 0x1ed9d731, }, 20 }, + { "gfxterm_menu", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x22bcc2fc, 0xc6c23ab4, 0x22bcc2fc, 0x72a46652, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0x72a46652, 0x72a46652, 0x9813a416, }, 20 }, + { "gfxterm_menu", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x3afb9165, 0x767dd6a7, 0x3afb9165, 0x31409f, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0x31409f, 0x31409f, 0x5fcf013d, }, 20 }, + { "gfxterm_menu", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xe13f0039, 0xb5783cd1, 0xe13f0039, 0x814ca453, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0x814ca453, 0x814ca453, 0xdd28f52b, }, 20 }, + { "gfxmenu", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x28e6b07d, 0xf54b3d6a, 0x28e6b07d, 0x7d0bdbfb, 0x9a2e0d26, 0xb22b0963, 0xb22b0963, 0xb22b0963, 0xeef3ffa3, 0xeef3ffa3, 0xeef3ffa3, 0x36f73b6, 0x36f73b6, 0x36f73b6, 0x59c36f00, 0x7d0bdbfb, 0x7d0bdbfb, }, 18 }, + { "gfxmenu", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x15bb581c, 0x7da084c6, 0x15bb581c, 0xcedba42f, 0xbc06c96d, 0xb3a8a15b, 0xb3a8a15b, 0xb3a8a15b, 0xe6f70b51, 0xe6f70b51, 0xe6f70b51, 0x8ce38109, 0x8ce38109, 0x8ce38109, 0xaa4593fe, 0xcedba42f, 0xcedba42f, }, 18 }, + { "gfxmenu", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x817e5fe2, 0x134e87ff, 0x817e5fe2, 0xb83ddd98, 0xdcd8c986, 0x79244533, 0x79244533, 0x79244533, 0x69ae3a7, 0x69ae3a7, 0x69ae3a7, 0xfc10b74f, 0xfc10b74f, 0xfc10b74f, 0xc9cbf769, 0xb83ddd98, 0xb83ddd98, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x1c3742c9, 0x95048302, 0x9f5bac7c, 0x95048302, 0x28413b7c, 0x740d78cf, 0x620e8524, 0x620e8524, 0x620e8524, 0x89ab6f58, 0x89ab6f58, 0x89ab6f58, 0x90218e3d, 0x90218e3d, 0x90218e3d, 0x1c3742c9, 0x28413b7c, 0x28413b7c, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0xcc5a7bed, 0x6cf38a7e, 0x35fcd6e8, 0x6cf38a7e, 0x618c203c, 0xe925e70d, 0xff9c8a81, 0xff9c8a81, 0xff9c8a81, 0x90d55690, 0x90d55690, 0x90d55690, 0xd3df13a0, 0xd3df13a0, 0xd3df13a0, 0xcc5a7bed, 0x618c203c, 0x618c203c, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xef4a3312, 0xd610d630, 0x98774981, 0xd610d630, 0x4469957c, 0x9869130b, 0xfb592a0d, 0xfb592a0d, 0xfb592a0d, 0x3deb6e13, 0x3deb6e13, 0x3deb6e13, 0xeaf96ec4, 0xeaf96ec4, 0xeaf96ec4, 0xef4a3312, 0x4469957c, 0x4469957c, }, 18 }, + { "gfxmenu", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x54e48d80, 0xf5c7a904, 0xaf9e8139, 0xf5c7a904, 0xf108ef6b, 0x91c7d0fe, 0xb57ab567, 0xb57ab567, 0xb57ab567, 0x348943b6, 0x348943b6, 0x348943b6, 0x9b076791, 0x9b076791, 0x9b076791, 0x54e48d80, 0xf108ef6b, 0xf108ef6b, }, 18 }, + { "gfxmenu", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xff8ab96b, 0x72a93e7f, 0xff8ab96b, 0x47d54a82, 0x42b837cf, 0x6abd338a, 0x6abd338a, 0x6abd338a, 0x3665c54a, 0x3665c54a, 0x3665c54a, 0xdbf9495f, 0xdbf9495f, 0xdbf9495f, 0x59c36f00, 0x47d54a82, 0x47d54a82, }, 18 }, + { "gfxmenu", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x73ad05f, 0x8434d91c, 0x73ad05f, 0x5316d3c6, 0xd7e75590, 0xd8493da6, 0xd8493da6, 0xd8493da6, 0x8d1697ac, 0x8d1697ac, 0x8d1697ac, 0xe7021df4, 0xe7021df4, 0xe7021df4, 0xaa4593fe, 0x5316d3c6, 0x5316d3c6, }, 18 }, + { "gfxmenu", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x83e29007, 0xd4329e28, 0x83e29007, 0x8c37fac6, 0x97d4f246, 0x32287ef3, 0x32287ef3, 0x32287ef3, 0x4d96d867, 0x4d96d867, 0x4d96d867, 0xb71c8c8f, 0xb71c8c8f, 0xb71c8c8f, 0xc9cbf769, 0x8c37fac6, 0x8c37fac6, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xe535f843, 0x39fb9c6c, 0xe535f843, 0x2fbd1b9, 0x7c892c8d, 0x3a8a1482, 0x3a8a1482, 0x3a8a1482, 0x2d7a2495, 0x2d7a2495, 0x2d7a2495, 0x84d821d, 0x84d821d, 0x84d821d, 0x5387d57f, 0x2fbd1b9, 0x2fbd1b9, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x8f8338d3, 0xdcad6ccd, 0x8f8338d3, 0x30c612d8, 0x36353d2b, 0xa9546353, 0xa9546353, 0xa9546353, 0x960ace5a, 0x960ace5a, 0x960ace5a, 0x62e43bb9, 0x62e43bb9, 0x62e43bb9, 0xf83ee7aa, 0x30c612d8, 0x30c612d8, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0xb7a13882, 0x68141e3a, 0xb7a13882, 0x65f6d15, 0x3101c32f, 0xc2b93e36, 0xc2b93e36, 0xc2b93e36, 0x1bee651a, 0x1bee651a, 0x1bee651a, 0xf7d3f08f, 0xf7d3f08f, 0xf7d3f08f, 0x724366e5, 0x65f6d15, 0x65f6d15, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x88a3c3aa, 0x8eade265, 0x88a3c3aa, 0xa5bf47d6, 0x9f8ae196, 0x56e34121, 0x56e34121, 0x56e34121, 0x2ccef01f, 0x2ccef01f, 0x2ccef01f, 0x7d1eee3b, 0x7d1eee3b, 0x7d1eee3b, 0x5387d57f, 0xa5bf47d6, 0xa5bf47d6, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x8452c39c, 0x65759f4c, 0x8452c39c, 0x7459c042, 0xf9023dca, 0xe78b8902, 0xe78b8902, 0xe78b8902, 0xf0960107, 0xf0960107, 0xf0960107, 0xd52b2285, 0xd52b2285, 0xd52b2285, 0xf83ee7aa, 0x7459c042, 0x7459c042, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x938d42a2, 0x709bc8ab, 0x938d42a2, 0x4db0e2de, 0xd710f4c, 0x4e9cc80d, 0x4e9cc80d, 0x4e9cc80d, 0x9bc8a372, 0x9bc8a372, 0x9bc8a372, 0xbac90ac7, 0xbac90ac7, 0xbac90ac7, 0x724366e5, 0x4db0e2de, 0x4db0e2de, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0xc060102b, 0x960bef0c, 0xc060102b, 0x1589677a, 0xe97d0978, 0xc795e31, 0xc795e31, 0xc795e31, 0xab33090, 0xab33090, 0xab33090, 0xbeea3971, 0xbeea3971, 0xbeea3971, 0x1c955882, 0x1589677a, 0x1589677a, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x6a4b2b8d, 0x274440b, 0x6a4b2b8d, 0xdef115d2, 0xed0808ad, 0x8d8ebcbb, 0x8d8ebcbb, 0x8d8ebcbb, 0x2b9b5d26, 0x2b9b5d26, 0x2b9b5d26, 0x790e10e2, 0x790e10e2, 0x790e10e2, 0x4d266f7a, 0xdef115d2, 0xdef115d2, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xdb8085be, 0x51d897c7, 0xdb8085be, 0xa3ce0221, 0x30fbd5f9, 0x12d25f5, 0x12d25f5, 0x12d25f5, 0xa4a480cb, 0xa4a480cb, 0xa4a480cb, 0xf3adca34, 0xf3adca34, 0xf3adca34, 0x1ed9d731, 0xa3ce0221, 0xa3ce0221, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0x475beaa4, 0xa62db977, 0x475beaa4, 0x3a62be0, 0x311b5810, 0x7718601f, 0x7718601f, 0x7718601f, 0x60e85008, 0x60e85008, 0x60e85008, 0x45dff680, 0x45dff680, 0x45dff680, 0x5387d57f, 0x3a62be0, 0x3a62be0, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x5788a7ac, 0xd4336209, 0x5788a7ac, 0x354678e9, 0x783d77de, 0xe75c29a6, 0xe75c29a6, 0xe75c29a6, 0xd80284af, 0xd80284af, 0xd80284af, 0x2cec714c, 0x2cec714c, 0x2cec714c, 0xf83ee7aa, 0x354678e9, 0x354678e9, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0xd1f64ea0, 0x4abd595a, 0xd1f64ea0, 0x97a6bea1, 0xf22a4cdb, 0x192b1c2, 0x192b1c2, 0x192b1c2, 0xd8c5eaee, 0xd8c5eaee, 0xd8c5eaee, 0x34f87f7b, 0x34f87f7b, 0x34f87f7b, 0x724366e5, 0x97a6bea1, 0x97a6bea1, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xfcd5f4bb, 0x36d1826d, 0xfcd5f4bb, 0x43d7de40, 0x84467c83, 0x4d2fdc34, 0x4d2fdc34, 0x4d2fdc34, 0x37026d0a, 0x37026d0a, 0x37026d0a, 0x66d2732e, 0x66d2732e, 0x66d2732e, 0x5387d57f, 0x43d7de40, 0x43d7de40, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x21e820a3, 0x2f9bf273, 0x21e820a3, 0xaa229449, 0x61b241cd, 0x7f3bf505, 0x7f3bf505, 0x7f3bf505, 0x68267d00, 0x68267d00, 0x68267d00, 0x4d9b5e82, 0x4d9b5e82, 0x4d9b5e82, 0xf83ee7aa, 0xaa229449, 0xaa229449, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x6fe66840, 0x64229598, 0x6fe66840, 0xedc02d98, 0x7131f7aa, 0x32dc30eb, 0x32dc30eb, 0x32dc30eb, 0xe7885b94, 0xe7885b94, 0xe7885b94, 0xc689f221, 0xc689f221, 0xc689f221, 0x724366e5, 0xedc02d98, 0xedc02d98, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0xdb159e45, 0x9b1475c9, 0xdb159e45, 0xaee6597b, 0x573454, 0xe553631d, 0xe553631d, 0xe553631d, 0xe3990dbc, 0xe3990dbc, 0xe3990dbc, 0x57c0045d, 0x57c0045d, 0x57c0045d, 0x1c955882, 0xaee6597b, 0xaee6597b, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x9a43dfc6, 0x67153087, 0x9a43dfc6, 0xe9bd482c, 0xe763cddd, 0x87e579cb, 0x87e579cb, 0x87e579cb, 0x21f09856, 0x21f09856, 0x21f09856, 0x7365d592, 0x7365d592, 0x7365d592, 0x4d266f7a, 0xe9bd482c, 0xe9bd482c, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x78bf287, 0x8e68ddb4, 0x78bf287, 0xb2b0d4a4, 0xcb49fd6e, 0xfa9f0d62, 0xfa9f0d62, 0xfa9f0d62, 0x5f16a85c, 0x5f16a85c, 0x5f16a85c, 0x81fe2a3, 0x81fe2a3, 0x81fe2a3, 0x1ed9d731, 0xb2b0d4a4, 0xb2b0d4a4, }, 18 }, + { "gfxmenu", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x1c3742c9, 0xb7ccf7ca, 0xfe517937, 0xb7ccf7ca, 0xfa1f93fd, 0x83d93b90, 0x95dac67b, 0x95dac67b, 0x95dac67b, 0x7e7f2c07, 0x7e7f2c07, 0x7e7f2c07, 0x67f5cd62, 0x67f5cd62, 0x67f5cd62, 0x1c3742c9, 0xfa1f93fd, 0xfa1f93fd, }, 18 }, + { "gfxmenu", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0xcc5a7bed, 0x663d292a, 0xa008c39, 0x663d292a, 0xcd82113f, 0x1c0b0f02, 0xab2628e, 0xab2628e, 0xab2628e, 0x65fbbe9f, 0x65fbbe9f, 0x65fbbe9f, 0x26f1fbaf, 0x26f1fbaf, 0x26f1fbaf, 0xcc5a7bed, 0xcd82113f, 0xcd82113f, }, 18 }, + { "gfxmenu", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xef4a3312, 0xfc2f0ab1, 0x6861f25e, 0xfc2f0ab1, 0x11b6b6f7, 0xcd618f3f, 0xae51b639, 0xae51b639, 0xae51b639, 0x68e3f227, 0x68e3f227, 0x68e3f227, 0xbff1f2f0, 0xbff1f2f0, 0xbff1f2f0, 0xef4a3312, 0x11b6b6f7, 0x11b6b6f7, }, 18 }, + { "gfxterm_ar", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xe0b5a23e, 0xee551fa6, 0xe0b5a23e, 0xa3436f79, 0x59c36f00, 0x59c36f00, 0x5e67c1f2, 0x5e67c1f2, 0x5e67c1f2, 0x20e7ac94, 0x20e7ac94, 0x20e7ac94, 0xe3c59159, 0xe3c59159, 0xe3c59159, 0x59c36f00, 0xa3436f79, 0xa3436f79, 0x59c36f00, }, 20 }, + { "gfxterm_ar", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x2bb3c18d, 0xdfae36a1, 0x2bb3c18d, 0x5b644f2, 0xaa4593fe, 0xaa4593fe, 0xccb764da, 0xccb764da, 0xccb764da, 0x6a4269bd, 0x6a4269bd, 0x6a4269bd, 0xe8e58bd6, 0xe8e58bd6, 0xe8e58bd6, 0xaa4593fe, 0x5b644f2, 0x5b644f2, 0xaa4593fe, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xdae90963, 0xc865b2ee, 0xdae90963, 0x87fe64e7, 0xc9cbf769, 0xc9cbf769, 0xbdb21287, 0xbdb21287, 0xbdb21287, 0x436ad34b, 0x436ad34b, 0x436ad34b, 0xab3c7c47, 0xab3c7c47, 0xab3c7c47, 0xc9cbf769, 0x87fe64e7, 0x87fe64e7, 0xc9cbf769, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xd5ca4355, 0xc8fbf114, 0xd5ca4355, 0x85d2e7fb, 0x9813a416, 0x9813a416, 0x4a1e101b, 0x4a1e101b, 0x4a1e101b, 0xdbc59628, 0xdbc59628, 0xdbc59628, 0x47b063ea, 0x47b063ea, 0x47b063ea, 0x9813a416, 0x85d2e7fb, 0x85d2e7fb, 0x9813a416, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x722a297e, 0xb34f27df, 0x722a297e, 0x48e0f884, 0x5fcf013d, 0x5fcf013d, 0xee9e0d69, 0xee9e0d69, 0xee9e0d69, 0x3c8e151f, 0x3c8e151f, 0x3c8e151f, 0x23a594e2, 0x23a594e2, 0x23a594e2, 0x5fcf013d, 0x48e0f884, 0x48e0f884, 0x5fcf013d, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x87be67c4, 0x484106d9, 0x87be67c4, 0xe7cdc3ae, 0xdd28f52b, 0xdd28f52b, 0x2063d7c8, 0x2063d7c8, 0x2063d7c8, 0x15f2e2c, 0x15f2e2c, 0x15f2e2c, 0x1b2e4dbd, 0x1b2e4dbd, 0x1b2e4dbd, 0xdd28f52b, 0xe7cdc3ae, 0xe7cdc3ae, 0xdd28f52b, }, 20 }, + { "gfxterm_ar", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xbf799219, 0xcec61405, 0xbf799219, 0x413f9f74, 0x43d1f34, 0x43d1f34, 0x9dc6a6fb, 0x9dc6a6fb, 0x9dc6a6fb, 0xe2cc0f53, 0xe2cc0f53, 0xe2cc0f53, 0xaec367a, 0xaec367a, 0xaec367a, 0x43d1f34, 0x413f9f74, 0x413f9f74, 0x43d1f34, }, 20 }, + { "gfxterm_ar", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xe0b5a23e, 0xee551fa6, 0xe0b5a23e, 0xa3436f79, 0x59c36f00, 0x59c36f00, 0x5e67c1f2, 0x5e67c1f2, 0x5e67c1f2, 0x20e7ac94, 0x20e7ac94, 0x20e7ac94, 0xe3c59159, 0xe3c59159, 0xe3c59159, 0x59c36f00, 0xa3436f79, 0xa3436f79, 0x59c36f00, }, 20 }, + { "gfxterm_ar", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x2bb3c18d, 0xdfae36a1, 0x2bb3c18d, 0x5b644f2, 0xaa4593fe, 0xaa4593fe, 0xccb764da, 0xccb764da, 0xccb764da, 0x6a4269bd, 0x6a4269bd, 0x6a4269bd, 0xe8e58bd6, 0xe8e58bd6, 0xe8e58bd6, 0xaa4593fe, 0x5b644f2, 0x5b644f2, 0xaa4593fe, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0xdae90963, 0xc865b2ee, 0xdae90963, 0x87fe64e7, 0xc9cbf769, 0xc9cbf769, 0xbdb21287, 0xbdb21287, 0xbdb21287, 0x436ad34b, 0x436ad34b, 0x436ad34b, 0xab3c7c47, 0xab3c7c47, 0xab3c7c47, 0xc9cbf769, 0x87fe64e7, 0x87fe64e7, 0xc9cbf769, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0x3b1768ca, 0xf9e5eedd, 0x3b1768ca, 0x7f1c9276, 0x5387d57f, 0x5387d57f, 0x927c1c5d, 0x927c1c5d, 0x927c1c5d, 0x52257091, 0x52257091, 0x52257091, 0xb5fbf207, 0xb5fbf207, 0xb5fbf207, 0x5387d57f, 0x7f1c9276, 0x7f1c9276, 0x5387d57f, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x54190c0f, 0xb6b42319, 0x54190c0f, 0xee714190, 0xf83ee7aa, 0xf83ee7aa, 0x1cbd869f, 0x1cbd869f, 0x1cbd869f, 0x80c4566c, 0x80c4566c, 0x80c4566c, 0xb877fdc4, 0xb877fdc4, 0xb877fdc4, 0xf83ee7aa, 0xee714190, 0xee714190, 0xf83ee7aa, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x25774ca3, 0x3d74e13a, 0x25774ca3, 0x3402f9f6, 0x724366e5, 0x724366e5, 0x447ccdbb, 0x447ccdbb, 0x447ccdbb, 0x3458f41, 0x3458f41, 0x3458f41, 0x6e6ba80b, 0x6e6ba80b, 0x6e6ba80b, 0x724366e5, 0x3402f9f6, 0x3402f9f6, 0x724366e5, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x9143e2a6, 0x6e596cd4, 0x9143e2a6, 0x7ed75f9f, 0x5387d57f, 0x5387d57f, 0x86a0aae, 0x86a0aae, 0x86a0aae, 0xd6a44573, 0xd6a44573, 0xd6a44573, 0x4527d76d, 0x4527d76d, 0x4527d76d, 0x5387d57f, 0x7ed75f9f, 0x7ed75f9f, 0x5387d57f, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xf943d873, 0xced7704, 0xf943d873, 0x8889e69f, 0xf83ee7aa, 0xf83ee7aa, 0x82576edb, 0x82576edb, 0x82576edb, 0xf08d7deb, 0xf08d7deb, 0xf08d7deb, 0xc1182c2d, 0xc1182c2d, 0xc1182c2d, 0xf83ee7aa, 0x8889e69f, 0x8889e69f, 0xf83ee7aa, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x63bd59d2, 0xf34f52d5, 0x63bd59d2, 0x916fd2a2, 0x724366e5, 0x724366e5, 0x11262bd6, 0x11262bd6, 0x11262bd6, 0x48b6d886, 0x48b6d886, 0x48b6d886, 0x8001b6c4, 0x8001b6c4, 0x8001b6c4, 0x724366e5, 0x916fd2a2, 0x916fd2a2, 0x724366e5, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0xed6af547, 0x9ff43eec, 0xed6af547, 0xed0a4de1, 0x1c955882, 0x1c955882, 0xa9dce4cb, 0xa9dce4cb, 0xa9dce4cb, 0x662ba95c, 0x662ba95c, 0x662ba95c, 0x9842a549, 0x9842a549, 0x9842a549, 0x1c955882, 0xed0a4de1, 0xed0a4de1, 0x1c955882, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xbda49d55, 0xf5b57989, 0xbda49d55, 0x79b60451, 0x4d266f7a, 0x4d266f7a, 0xeb1807b5, 0xeb1807b5, 0xeb1807b5, 0xd6f1c0a, 0xd6f1c0a, 0xd6f1c0a, 0x9556489a, 0x9556489a, 0x9556489a, 0x4d266f7a, 0x79b60451, 0x79b60451, 0x4d266f7a, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x90b1e6bc, 0xabcab9fe, 0x90b1e6bc, 0xc45e75b, 0x1ed9d731, 0x1ed9d731, 0xa6ac3ed0, 0xa6ac3ed0, 0xa6ac3ed0, 0x8c82015, 0x8c82015, 0x8c82015, 0x2ba131a3, 0x2ba131a3, 0x2ba131a3, 0x1ed9d731, 0xc45e75b, 0xc45e75b, 0x1ed9d731, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0x3b1768ca, 0xf9e5eedd, 0x3b1768ca, 0x7f1c9276, 0x5387d57f, 0x5387d57f, 0x927c1c5d, 0x927c1c5d, 0x927c1c5d, 0x52257091, 0x52257091, 0x52257091, 0xb5fbf207, 0xb5fbf207, 0xb5fbf207, 0x5387d57f, 0x7f1c9276, 0x7f1c9276, 0x5387d57f, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x54190c0f, 0xb6b42319, 0x54190c0f, 0xee714190, 0xf83ee7aa, 0xf83ee7aa, 0x1cbd869f, 0x1cbd869f, 0x1cbd869f, 0x80c4566c, 0x80c4566c, 0x80c4566c, 0xb877fdc4, 0xb877fdc4, 0xb877fdc4, 0xf83ee7aa, 0xee714190, 0xee714190, 0xf83ee7aa, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x25774ca3, 0x3d74e13a, 0x25774ca3, 0x3402f9f6, 0x724366e5, 0x724366e5, 0x447ccdbb, 0x447ccdbb, 0x447ccdbb, 0x3458f41, 0x3458f41, 0x3458f41, 0x6e6ba80b, 0x6e6ba80b, 0x6e6ba80b, 0x724366e5, 0x3402f9f6, 0x3402f9f6, 0x724366e5, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x9143e2a6, 0x6e596cd4, 0x9143e2a6, 0x7ed75f9f, 0x5387d57f, 0x5387d57f, 0x86a0aae, 0x86a0aae, 0x86a0aae, 0xd6a44573, 0xd6a44573, 0xd6a44573, 0x4527d76d, 0x4527d76d, 0x4527d76d, 0x5387d57f, 0x7ed75f9f, 0x7ed75f9f, 0x5387d57f, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xf943d873, 0xced7704, 0xf943d873, 0x8889e69f, 0xf83ee7aa, 0xf83ee7aa, 0x82576edb, 0x82576edb, 0x82576edb, 0xf08d7deb, 0xf08d7deb, 0xf08d7deb, 0xc1182c2d, 0xc1182c2d, 0xc1182c2d, 0xf83ee7aa, 0x8889e69f, 0x8889e69f, 0xf83ee7aa, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x63bd59d2, 0xf34f52d5, 0x63bd59d2, 0x916fd2a2, 0x724366e5, 0x724366e5, 0x11262bd6, 0x11262bd6, 0x11262bd6, 0x48b6d886, 0x48b6d886, 0x48b6d886, 0x8001b6c4, 0x8001b6c4, 0x8001b6c4, 0x724366e5, 0x916fd2a2, 0x916fd2a2, 0x724366e5, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0xed6af547, 0x9ff43eec, 0xed6af547, 0xed0a4de1, 0x1c955882, 0x1c955882, 0xa9dce4cb, 0xa9dce4cb, 0xa9dce4cb, 0x662ba95c, 0x662ba95c, 0x662ba95c, 0x9842a549, 0x9842a549, 0x9842a549, 0x1c955882, 0xed0a4de1, 0xed0a4de1, 0x1c955882, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xbda49d55, 0xf5b57989, 0xbda49d55, 0x79b60451, 0x4d266f7a, 0x4d266f7a, 0xeb1807b5, 0xeb1807b5, 0xeb1807b5, 0xd6f1c0a, 0xd6f1c0a, 0xd6f1c0a, 0x9556489a, 0x9556489a, 0x9556489a, 0x4d266f7a, 0x79b60451, 0x79b60451, 0x4d266f7a, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x90b1e6bc, 0xabcab9fe, 0x90b1e6bc, 0xc45e75b, 0x1ed9d731, 0x1ed9d731, 0xa6ac3ed0, 0xa6ac3ed0, 0xa6ac3ed0, 0x8c82015, 0x8c82015, 0x8c82015, 0x2ba131a3, 0x2ba131a3, 0x2ba131a3, 0x1ed9d731, 0xc45e75b, 0xc45e75b, 0x1ed9d731, }, 20 }, + { "gfxterm_ar", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0xd5ca4355, 0xc8fbf114, 0xd5ca4355, 0x85d2e7fb, 0x9813a416, 0x9813a416, 0x4a1e101b, 0x4a1e101b, 0x4a1e101b, 0xdbc59628, 0xdbc59628, 0xdbc59628, 0x47b063ea, 0x47b063ea, 0x47b063ea, 0x9813a416, 0x85d2e7fb, 0x85d2e7fb, 0x9813a416, }, 20 }, + { "gfxterm_ar", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x722a297e, 0xb34f27df, 0x722a297e, 0x48e0f884, 0x5fcf013d, 0x5fcf013d, 0xee9e0d69, 0xee9e0d69, 0xee9e0d69, 0x3c8e151f, 0x3c8e151f, 0x3c8e151f, 0x23a594e2, 0x23a594e2, 0x23a594e2, 0x5fcf013d, 0x48e0f884, 0x48e0f884, 0x5fcf013d, }, 20 }, + { "gfxterm_ar", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x87be67c4, 0x484106d9, 0x87be67c4, 0xe7cdc3ae, 0xdd28f52b, 0xdd28f52b, 0x2063d7c8, 0x2063d7c8, 0x2063d7c8, 0x15f2e2c, 0x15f2e2c, 0x15f2e2c, 0x1b2e4dbd, 0x1b2e4dbd, 0x1b2e4dbd, 0xdd28f52b, 0xe7cdc3ae, 0xe7cdc3ae, 0xdd28f52b, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x36622078, 0x979da8f3, 0x36622078, 0x7594ed3f, 0x59c36f00, 0x59c36f00, 0xe5e5cf13, 0xe5e5cf13, 0xe5e5cf13, 0x9b65a275, 0x9b65a275, 0x9b65a275, 0x58479fb8, 0x58479fb8, 0x58479fb8, 0x59c36f00, 0x7594ed3f, 0x7594ed3f, 0x59c36f00, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x48ee0ceb, 0xc6eb6d53, 0x48ee0ceb, 0x66eb8994, 0xaa4593fe, 0xaa4593fe, 0x86ac5984, 0x86ac5984, 0x86ac5984, 0x205954e3, 0x205954e3, 0x205954e3, 0xa2feb688, 0xa2feb688, 0xa2feb688, 0xaa4593fe, 0x66eb8994, 0x66eb8994, 0xaa4593fe, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xfa53f185, 0xaf8fa3eb, 0xfa53f185, 0xa7449c01, 0xc9cbf769, 0xc9cbf769, 0x50b94b47, 0x50b94b47, 0x50b94b47, 0xae618a8b, 0xae618a8b, 0xae618a8b, 0x46372587, 0x46372587, 0x46372587, 0xc9cbf769, 0xa7449c01, 0xa7449c01, 0xc9cbf769, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xc6eb6e6e, 0xc5217d5b, 0xc6eb6e6e, 0x96f3cac0, 0x9813a416, 0x9813a416, 0x5752c3fe, 0x5752c3fe, 0x5752c3fe, 0xc68945cd, 0xc68945cd, 0xc68945cd, 0x5afcb00f, 0x5afcb00f, 0x5afcb00f, 0x9813a416, 0x96f3cac0, 0x96f3cac0, 0x9813a416, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x7fd1def2, 0x98a2e53a, 0x7fd1def2, 0x451b0f08, 0x5fcf013d, 0x5fcf013d, 0x9f19ac09, 0x9f19ac09, 0x9f19ac09, 0x4d09b47f, 0x4d09b47f, 0x4d09b47f, 0x52223582, 0x52223582, 0x52223582, 0x5fcf013d, 0x451b0f08, 0x451b0f08, 0x5fcf013d, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xaac2ae55, 0x3e7a25f, 0xaac2ae55, 0xcab10a3f, 0xdd28f52b, 0xdd28f52b, 0x5f2b8179, 0x5f2b8179, 0x5f2b8179, 0x7e17789d, 0x7e17789d, 0x7e17789d, 0x64661b0c, 0x64661b0c, 0x64661b0c, 0xdd28f52b, 0xcab10a3f, 0xcab10a3f, 0xdd28f52b, }, 20 }, + { "gfxterm_cyr", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xfbdee88, 0x812f047f, 0xfbdee88, 0xf1fbe3e5, 0x43d1f34, 0x43d1f34, 0x6694d5e, 0x6694d5e, 0x6694d5e, 0x7963e4f6, 0x7963e4f6, 0x7963e4f6, 0x9143dddf, 0x9143dddf, 0x9143dddf, 0x43d1f34, 0xf1fbe3e5, 0xf1fbe3e5, 0x43d1f34, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x36622078, 0x979da8f3, 0x36622078, 0x7594ed3f, 0x59c36f00, 0x59c36f00, 0xe5e5cf13, 0xe5e5cf13, 0xe5e5cf13, 0x9b65a275, 0x9b65a275, 0x9b65a275, 0x58479fb8, 0x58479fb8, 0x58479fb8, 0x59c36f00, 0x7594ed3f, 0x7594ed3f, 0x59c36f00, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x48ee0ceb, 0xc6eb6d53, 0x48ee0ceb, 0x66eb8994, 0xaa4593fe, 0xaa4593fe, 0x86ac5984, 0x86ac5984, 0x86ac5984, 0x205954e3, 0x205954e3, 0x205954e3, 0xa2feb688, 0xa2feb688, 0xa2feb688, 0xaa4593fe, 0x66eb8994, 0x66eb8994, 0xaa4593fe, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0xfa53f185, 0xaf8fa3eb, 0xfa53f185, 0xa7449c01, 0xc9cbf769, 0xc9cbf769, 0x50b94b47, 0x50b94b47, 0x50b94b47, 0xae618a8b, 0xae618a8b, 0xae618a8b, 0x46372587, 0x46372587, 0x46372587, 0xc9cbf769, 0xa7449c01, 0xa7449c01, 0xc9cbf769, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xd8d870b3, 0x9128b01a, 0xd8d870b3, 0x9cd38a0f, 0x5387d57f, 0x5387d57f, 0x136cad2, 0x136cad2, 0x136cad2, 0xc16fa61e, 0xc16fa61e, 0xc16fa61e, 0x26b12488, 0x26b12488, 0x26b12488, 0x5387d57f, 0x9cd38a0f, 0x9cd38a0f, 0x5387d57f, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xeaeda16f, 0x36d21de0, 0xeaeda16f, 0x5085ecf0, 0xf83ee7aa, 0xf83ee7aa, 0x3eac591b, 0x3eac591b, 0x3eac591b, 0xa2d589e8, 0xa2d589e8, 0xa2d589e8, 0x9a662240, 0x9a662240, 0x9a662240, 0xf83ee7aa, 0x5085ecf0, 0x5085ecf0, 0xf83ee7aa, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x333a0d08, 0x47d0c238, 0x333a0d08, 0x224fb85d, 0x724366e5, 0x724366e5, 0xf4044671, 0xf4044671, 0xf4044671, 0xb33d048b, 0xb33d048b, 0xb33d048b, 0xde1323c1, 0xde1323c1, 0xde1323c1, 0x724366e5, 0x224fb85d, 0x224fb85d, 0x724366e5, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x4a43c1c8, 0xe019a943, 0x4a43c1c8, 0xa5d77cf1, 0x5387d57f, 0x5387d57f, 0x8171a604, 0x8171a604, 0x8171a604, 0x5fbfe9d9, 0x5fbfe9d9, 0x5fbfe9d9, 0xcc3c7bc7, 0xcc3c7bc7, 0xcc3c7bc7, 0x5387d57f, 0xa5d77cf1, 0xa5d77cf1, 0x5387d57f, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xb770c3fe, 0x50b21ef7, 0xb770c3fe, 0xc6bafd12, 0xf83ee7aa, 0xf83ee7aa, 0x8df53a5d, 0x8df53a5d, 0x8df53a5d, 0xff2f296d, 0xff2f296d, 0xff2f296d, 0xceba78ab, 0xceba78ab, 0xceba78ab, 0xf83ee7aa, 0xc6bafd12, 0xc6bafd12, 0xf83ee7aa, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0xe8f75cfb, 0x402c0692, 0xe8f75cfb, 0x1a25d78b, 0x724366e5, 0x724366e5, 0xaf01e304, 0xaf01e304, 0xaf01e304, 0xf6911054, 0xf6911054, 0xf6911054, 0x3e267e16, 0x3e267e16, 0x3e267e16, 0x724366e5, 0x1a25d78b, 0x1a25d78b, 0x724366e5, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x89f843d3, 0xc27ae37d, 0x89f843d3, 0x8998fb75, 0x1c955882, 0x1c955882, 0x698caa77, 0x698caa77, 0x698caa77, 0xa67be7e0, 0xa67be7e0, 0xa67be7e0, 0x5812ebf5, 0x5812ebf5, 0x5812ebf5, 0x1c955882, 0x8998fb75, 0x8998fb75, 0x1c955882, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xa10c24e6, 0x12eeef09, 0xa10c24e6, 0x651ebde2, 0x4d266f7a, 0x4d266f7a, 0x8ed47731, 0x8ed47731, 0x8ed47731, 0x68a36c8e, 0x68a36c8e, 0x68a36c8e, 0xf09a381e, 0xf09a381e, 0xf09a381e, 0x4d266f7a, 0x651ebde2, 0x651ebde2, 0x4d266f7a, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x85a30869, 0xbaa08e30, 0x85a30869, 0x1957098e, 0x1ed9d731, 0x1ed9d731, 0x4ffc007b, 0x4ffc007b, 0x4ffc007b, 0xe1981ebe, 0xe1981ebe, 0xe1981ebe, 0xc2f10f08, 0xc2f10f08, 0xc2f10f08, 0x1ed9d731, 0x1957098e, 0x1957098e, 0x1ed9d731, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xd8d870b3, 0x9128b01a, 0xd8d870b3, 0x9cd38a0f, 0x5387d57f, 0x5387d57f, 0x136cad2, 0x136cad2, 0x136cad2, 0xc16fa61e, 0xc16fa61e, 0xc16fa61e, 0x26b12488, 0x26b12488, 0x26b12488, 0x5387d57f, 0x9cd38a0f, 0x9cd38a0f, 0x5387d57f, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xeaeda16f, 0x36d21de0, 0xeaeda16f, 0x5085ecf0, 0xf83ee7aa, 0xf83ee7aa, 0x3eac591b, 0x3eac591b, 0x3eac591b, 0xa2d589e8, 0xa2d589e8, 0xa2d589e8, 0x9a662240, 0x9a662240, 0x9a662240, 0xf83ee7aa, 0x5085ecf0, 0x5085ecf0, 0xf83ee7aa, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x333a0d08, 0x47d0c238, 0x333a0d08, 0x224fb85d, 0x724366e5, 0x724366e5, 0xf4044671, 0xf4044671, 0xf4044671, 0xb33d048b, 0xb33d048b, 0xb33d048b, 0xde1323c1, 0xde1323c1, 0xde1323c1, 0x724366e5, 0x224fb85d, 0x224fb85d, 0x724366e5, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x4a43c1c8, 0xe019a943, 0x4a43c1c8, 0xa5d77cf1, 0x5387d57f, 0x5387d57f, 0x8171a604, 0x8171a604, 0x8171a604, 0x5fbfe9d9, 0x5fbfe9d9, 0x5fbfe9d9, 0xcc3c7bc7, 0xcc3c7bc7, 0xcc3c7bc7, 0x5387d57f, 0xa5d77cf1, 0xa5d77cf1, 0x5387d57f, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xb770c3fe, 0x50b21ef7, 0xb770c3fe, 0xc6bafd12, 0xf83ee7aa, 0xf83ee7aa, 0x8df53a5d, 0x8df53a5d, 0x8df53a5d, 0xff2f296d, 0xff2f296d, 0xff2f296d, 0xceba78ab, 0xceba78ab, 0xceba78ab, 0xf83ee7aa, 0xc6bafd12, 0xc6bafd12, 0xf83ee7aa, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0xe8f75cfb, 0x402c0692, 0xe8f75cfb, 0x1a25d78b, 0x724366e5, 0x724366e5, 0xaf01e304, 0xaf01e304, 0xaf01e304, 0xf6911054, 0xf6911054, 0xf6911054, 0x3e267e16, 0x3e267e16, 0x3e267e16, 0x724366e5, 0x1a25d78b, 0x1a25d78b, 0x724366e5, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x89f843d3, 0xc27ae37d, 0x89f843d3, 0x8998fb75, 0x1c955882, 0x1c955882, 0x698caa77, 0x698caa77, 0x698caa77, 0xa67be7e0, 0xa67be7e0, 0xa67be7e0, 0x5812ebf5, 0x5812ebf5, 0x5812ebf5, 0x1c955882, 0x8998fb75, 0x8998fb75, 0x1c955882, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xa10c24e6, 0x12eeef09, 0xa10c24e6, 0x651ebde2, 0x4d266f7a, 0x4d266f7a, 0x8ed47731, 0x8ed47731, 0x8ed47731, 0x68a36c8e, 0x68a36c8e, 0x68a36c8e, 0xf09a381e, 0xf09a381e, 0xf09a381e, 0x4d266f7a, 0x651ebde2, 0x651ebde2, 0x4d266f7a, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x85a30869, 0xbaa08e30, 0x85a30869, 0x1957098e, 0x1ed9d731, 0x1ed9d731, 0x4ffc007b, 0x4ffc007b, 0x4ffc007b, 0xe1981ebe, 0xe1981ebe, 0xe1981ebe, 0xc2f10f08, 0xc2f10f08, 0xc2f10f08, 0x1ed9d731, 0x1957098e, 0x1957098e, 0x1ed9d731, }, 20 }, + { "gfxterm_cyr", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0xc6eb6e6e, 0xc5217d5b, 0xc6eb6e6e, 0x96f3cac0, 0x9813a416, 0x9813a416, 0x5752c3fe, 0x5752c3fe, 0x5752c3fe, 0xc68945cd, 0xc68945cd, 0xc68945cd, 0x5afcb00f, 0x5afcb00f, 0x5afcb00f, 0x9813a416, 0x96f3cac0, 0x96f3cac0, 0x9813a416, }, 20 }, + { "gfxterm_cyr", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x7fd1def2, 0x98a2e53a, 0x7fd1def2, 0x451b0f08, 0x5fcf013d, 0x5fcf013d, 0x9f19ac09, 0x9f19ac09, 0x9f19ac09, 0x4d09b47f, 0x4d09b47f, 0x4d09b47f, 0x52223582, 0x52223582, 0x52223582, 0x5fcf013d, 0x451b0f08, 0x451b0f08, 0x5fcf013d, }, 20 }, + { "gfxterm_cyr", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xaac2ae55, 0x3e7a25f, 0xaac2ae55, 0xcab10a3f, 0xdd28f52b, 0xdd28f52b, 0x5f2b8179, 0x5f2b8179, 0x5f2b8179, 0x7e17789d, 0x7e17789d, 0x7e17789d, 0x64661b0c, 0x64661b0c, 0x64661b0c, 0xdd28f52b, 0xcab10a3f, 0xcab10a3f, 0xdd28f52b, }, 20 }, + { "gfxterm_heb", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x99e53699, 0x9b30b9b8, 0x99e53699, 0xda13fbde, 0x59c36f00, 0x59c36f00, 0xc6c80006, 0xc6c80006, 0xc6c80006, 0xb8486d60, 0xb8486d60, 0xb8486d60, 0x7b6a50ad, 0x7b6a50ad, 0x7b6a50ad, 0x59c36f00, 0xda13fbde, 0xda13fbde, 0x59c36f00, }, 20 }, + { "gfxterm_heb", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x5596d8c4, 0xe6c08467, 0x5596d8c4, 0x7b935dbb, 0xaa4593fe, 0xaa4593fe, 0xb2094db6, 0xb2094db6, 0xb2094db6, 0x14fc40d1, 0x14fc40d1, 0x14fc40d1, 0x965ba2ba, 0x965ba2ba, 0x965ba2ba, 0xaa4593fe, 0x7b935dbb, 0x7b935dbb, 0xaa4593fe, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x8b963803, 0x3a329278, 0x8b963803, 0xd6815587, 0xc9cbf769, 0xc9cbf769, 0x85733bd7, 0x85733bd7, 0x85733bd7, 0x7babfa1b, 0x7babfa1b, 0x7babfa1b, 0x93fd5517, 0x93fd5517, 0x93fd5517, 0xc9cbf769, 0xd6815587, 0xd6815587, 0xc9cbf769, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x27813091, 0xd32064ba, 0x27813091, 0x7799943f, 0x9813a416, 0x9813a416, 0x5cfa5159, 0x5cfa5159, 0x5cfa5159, 0xcd21d76a, 0xcd21d76a, 0xcd21d76a, 0x515422a8, 0x515422a8, 0x515422a8, 0x9813a416, 0x7799943f, 0x7799943f, 0x9813a416, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xf107273d, 0xd1d8f23b, 0xf107273d, 0xcbcdf6c7, 0x5fcf013d, 0x5fcf013d, 0x164d5584, 0x164d5584, 0x164d5584, 0xc45d4df2, 0xc45d4df2, 0xc45d4df2, 0xdb76cc0f, 0xdb76cc0f, 0xdb76cc0f, 0x5fcf013d, 0xcbcdf6c7, 0xcbcdf6c7, 0x5fcf013d, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xa54fb200, 0x92d6596f, 0xa54fb200, 0xc53c166a, 0xdd28f52b, 0xdd28f52b, 0x97b266c9, 0x97b266c9, 0x97b266c9, 0xb68e9f2d, 0xb68e9f2d, 0xb68e9f2d, 0xacfffcbc, 0xacfffcbc, 0xacfffcbc, 0xdd28f52b, 0xc53c166a, 0xc53c166a, 0xdd28f52b, }, 20 }, + { "gfxterm_heb", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x6d1ede55, 0x4bb31527, 0x6d1ede55, 0x9358d338, 0x43d1f34, 0x43d1f34, 0xa3f91b32, 0xa3f91b32, 0xa3f91b32, 0xdcf3b29a, 0xdcf3b29a, 0xdcf3b29a, 0x34d38bb3, 0x34d38bb3, 0x34d38bb3, 0x43d1f34, 0x9358d338, 0x9358d338, 0x43d1f34, }, 20 }, + { "gfxterm_heb", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x99e53699, 0x9b30b9b8, 0x99e53699, 0xda13fbde, 0x59c36f00, 0x59c36f00, 0xc6c80006, 0xc6c80006, 0xc6c80006, 0xb8486d60, 0xb8486d60, 0xb8486d60, 0x7b6a50ad, 0x7b6a50ad, 0x7b6a50ad, 0x59c36f00, 0xda13fbde, 0xda13fbde, 0x59c36f00, }, 20 }, + { "gfxterm_heb", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x5596d8c4, 0xe6c08467, 0x5596d8c4, 0x7b935dbb, 0xaa4593fe, 0xaa4593fe, 0xb2094db6, 0xb2094db6, 0xb2094db6, 0x14fc40d1, 0x14fc40d1, 0x14fc40d1, 0x965ba2ba, 0x965ba2ba, 0x965ba2ba, 0xaa4593fe, 0x7b935dbb, 0x7b935dbb, 0xaa4593fe, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x8b963803, 0x3a329278, 0x8b963803, 0xd6815587, 0xc9cbf769, 0xc9cbf769, 0x85733bd7, 0x85733bd7, 0x85733bd7, 0x7babfa1b, 0x7babfa1b, 0x7babfa1b, 0x93fd5517, 0x93fd5517, 0x93fd5517, 0xc9cbf769, 0xd6815587, 0xd6815587, 0xc9cbf769, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xeada5358, 0xa5081c9c, 0xeada5358, 0xaed1a9e4, 0x5387d57f, 0x5387d57f, 0xe7380617, 0xe7380617, 0xe7380617, 0x27616adb, 0x27616adb, 0x27616adb, 0xc0bfe84d, 0xc0bfe84d, 0xc0bfe84d, 0x5387d57f, 0xaed1a9e4, 0xaed1a9e4, 0x5387d57f, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x167e9ac0, 0xc5a57b5f, 0x167e9ac0, 0xac16d75f, 0xf83ee7aa, 0xf83ee7aa, 0xb47ab0cb, 0xb47ab0cb, 0xb47ab0cb, 0x28036038, 0x28036038, 0x28036038, 0x10b0cb90, 0x10b0cb90, 0x10b0cb90, 0xf83ee7aa, 0xac16d75f, 0xac16d75f, 0xf83ee7aa, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0xfd0449a3, 0xb946b16a, 0xfd0449a3, 0xec71fcf6, 0x724366e5, 0x724366e5, 0xab4d15ce, 0xab4d15ce, 0xab4d15ce, 0xec745734, 0xec745734, 0xec745734, 0x815a707e, 0x815a707e, 0x815a707e, 0x724366e5, 0xec71fcf6, 0xec71fcf6, 0x724366e5, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x1eb746a, 0x74afe43, 0x1eb746a, 0xee7fc953, 0x5387d57f, 0x5387d57f, 0x704981d6, 0x704981d6, 0x704981d6, 0xae87ce0b, 0xae87ce0b, 0xae87ce0b, 0x3d045c15, 0x3d045c15, 0x3d045c15, 0x5387d57f, 0xee7fc953, 0xee7fc953, 0x5387d57f, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xb9fa44c, 0xff4e04c7, 0xb9fa44c, 0x7a559aa0, 0xf83ee7aa, 0xf83ee7aa, 0xfccbce43, 0xfccbce43, 0xfccbce43, 0x8e11dd73, 0x8e11dd73, 0x8e11dd73, 0xbf848cb5, 0xbf848cb5, 0xbf848cb5, 0xf83ee7aa, 0x7a559aa0, 0x7a559aa0, 0xf83ee7aa, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0xcc83dbb8, 0x7fa3d9db, 0xcc83dbb8, 0x3e5150c8, 0x724366e5, 0x724366e5, 0x3d838d1c, 0x3d838d1c, 0x3d838d1c, 0x64137e4c, 0x64137e4c, 0x64137e4c, 0xaca4100e, 0xaca4100e, 0xaca4100e, 0x724366e5, 0x3e5150c8, 0x3e5150c8, 0x724366e5, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x2a9a3393, 0xc249bea, 0x2a9a3393, 0x2afa8b35, 0x1c955882, 0x1c955882, 0x9c6441e2, 0x9c6441e2, 0x9c6441e2, 0x53930c75, 0x53930c75, 0x53930c75, 0xadfa0060, 0xadfa0060, 0xadfa0060, 0x1c955882, 0x2afa8b35, 0x2afa8b35, 0x1c955882, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xcf807eaa, 0x4af8ad98, 0xcf807eaa, 0xb92e7ae, 0x4d266f7a, 0x4d266f7a, 0x15d955c1, 0x15d955c1, 0x15d955c1, 0xf3ae4e7e, 0xf3ae4e7e, 0xf3ae4e7e, 0x6b971aee, 0x6b971aee, 0x6b971aee, 0x4d266f7a, 0xb92e7ae, 0xb92e7ae, 0x4d266f7a, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x98e40974, 0xf0ed7ac2, 0x98e40974, 0x4100893, 0x1ed9d731, 0x1ed9d731, 0x7d102c2f, 0x7d102c2f, 0x7d102c2f, 0xd37432ea, 0xd37432ea, 0xd37432ea, 0xf01d235c, 0xf01d235c, 0xf01d235c, 0x1ed9d731, 0x4100893, 0x4100893, 0x1ed9d731, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xeada5358, 0xa5081c9c, 0xeada5358, 0xaed1a9e4, 0x5387d57f, 0x5387d57f, 0xe7380617, 0xe7380617, 0xe7380617, 0x27616adb, 0x27616adb, 0x27616adb, 0xc0bfe84d, 0xc0bfe84d, 0xc0bfe84d, 0x5387d57f, 0xaed1a9e4, 0xaed1a9e4, 0x5387d57f, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x167e9ac0, 0xc5a57b5f, 0x167e9ac0, 0xac16d75f, 0xf83ee7aa, 0xf83ee7aa, 0xb47ab0cb, 0xb47ab0cb, 0xb47ab0cb, 0x28036038, 0x28036038, 0x28036038, 0x10b0cb90, 0x10b0cb90, 0x10b0cb90, 0xf83ee7aa, 0xac16d75f, 0xac16d75f, 0xf83ee7aa, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0xfd0449a3, 0xb946b16a, 0xfd0449a3, 0xec71fcf6, 0x724366e5, 0x724366e5, 0xab4d15ce, 0xab4d15ce, 0xab4d15ce, 0xec745734, 0xec745734, 0xec745734, 0x815a707e, 0x815a707e, 0x815a707e, 0x724366e5, 0xec71fcf6, 0xec71fcf6, 0x724366e5, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x1eb746a, 0x74afe43, 0x1eb746a, 0xee7fc953, 0x5387d57f, 0x5387d57f, 0x704981d6, 0x704981d6, 0x704981d6, 0xae87ce0b, 0xae87ce0b, 0xae87ce0b, 0x3d045c15, 0x3d045c15, 0x3d045c15, 0x5387d57f, 0xee7fc953, 0xee7fc953, 0x5387d57f, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xb9fa44c, 0xff4e04c7, 0xb9fa44c, 0x7a559aa0, 0xf83ee7aa, 0xf83ee7aa, 0xfccbce43, 0xfccbce43, 0xfccbce43, 0x8e11dd73, 0x8e11dd73, 0x8e11dd73, 0xbf848cb5, 0xbf848cb5, 0xbf848cb5, 0xf83ee7aa, 0x7a559aa0, 0x7a559aa0, 0xf83ee7aa, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0xcc83dbb8, 0x7fa3d9db, 0xcc83dbb8, 0x3e5150c8, 0x724366e5, 0x724366e5, 0x3d838d1c, 0x3d838d1c, 0x3d838d1c, 0x64137e4c, 0x64137e4c, 0x64137e4c, 0xaca4100e, 0xaca4100e, 0xaca4100e, 0x724366e5, 0x3e5150c8, 0x3e5150c8, 0x724366e5, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x2a9a3393, 0xc249bea, 0x2a9a3393, 0x2afa8b35, 0x1c955882, 0x1c955882, 0x9c6441e2, 0x9c6441e2, 0x9c6441e2, 0x53930c75, 0x53930c75, 0x53930c75, 0xadfa0060, 0xadfa0060, 0xadfa0060, 0x1c955882, 0x2afa8b35, 0x2afa8b35, 0x1c955882, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xcf807eaa, 0x4af8ad98, 0xcf807eaa, 0xb92e7ae, 0x4d266f7a, 0x4d266f7a, 0x15d955c1, 0x15d955c1, 0x15d955c1, 0xf3ae4e7e, 0xf3ae4e7e, 0xf3ae4e7e, 0x6b971aee, 0x6b971aee, 0x6b971aee, 0x4d266f7a, 0xb92e7ae, 0xb92e7ae, 0x4d266f7a, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x98e40974, 0xf0ed7ac2, 0x98e40974, 0x4100893, 0x1ed9d731, 0x1ed9d731, 0x7d102c2f, 0x7d102c2f, 0x7d102c2f, 0xd37432ea, 0xd37432ea, 0xd37432ea, 0xf01d235c, 0xf01d235c, 0xf01d235c, 0x1ed9d731, 0x4100893, 0x4100893, 0x1ed9d731, }, 20 }, + { "gfxterm_heb", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x27813091, 0xd32064ba, 0x27813091, 0x7799943f, 0x9813a416, 0x9813a416, 0x5cfa5159, 0x5cfa5159, 0x5cfa5159, 0xcd21d76a, 0xcd21d76a, 0xcd21d76a, 0x515422a8, 0x515422a8, 0x515422a8, 0x9813a416, 0x7799943f, 0x7799943f, 0x9813a416, }, 20 }, + { "gfxterm_heb", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xf107273d, 0xd1d8f23b, 0xf107273d, 0xcbcdf6c7, 0x5fcf013d, 0x5fcf013d, 0x164d5584, 0x164d5584, 0x164d5584, 0xc45d4df2, 0xc45d4df2, 0xc45d4df2, 0xdb76cc0f, 0xdb76cc0f, 0xdb76cc0f, 0x5fcf013d, 0xcbcdf6c7, 0xcbcdf6c7, 0x5fcf013d, }, 20 }, + { "gfxterm_heb", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xa54fb200, 0x92d6596f, 0xa54fb200, 0xc53c166a, 0xdd28f52b, 0xdd28f52b, 0x97b266c9, 0x97b266c9, 0x97b266c9, 0xb68e9f2d, 0xb68e9f2d, 0xb68e9f2d, 0xacfffcbc, 0xacfffcbc, 0xacfffcbc, 0xdd28f52b, 0xc53c166a, 0xc53c166a, 0xdd28f52b, }, 20 }, + { "gfxterm_gre", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xfe511789, 0x421405b3, 0xfe511789, 0xbda7dace, 0x59c36f00, 0x59c36f00, 0x2a367884, 0x2a367884, 0x2a367884, 0x54b615e2, 0x54b615e2, 0x54b615e2, 0x9794282f, 0x9794282f, 0x9794282f, 0x59c36f00, 0xbda7dace, 0xbda7dace, 0x59c36f00, }, 20 }, + { "gfxterm_gre", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x2616eaaf, 0xd0263182, 0x2616eaaf, 0x8136fd0, 0xaa4593fe, 0xaa4593fe, 0x5b85b7a8, 0x5b85b7a8, 0x5b85b7a8, 0xfd70bacf, 0xfd70bacf, 0xfd70bacf, 0x7fd758a4, 0x7fd758a4, 0x7fd758a4, 0xaa4593fe, 0x8136fd0, 0x8136fd0, 0xaa4593fe, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x9214e205, 0x211e70db, 0x9214e205, 0xcf038f81, 0xc9cbf769, 0xc9cbf769, 0x5a304c, 0x5a304c, 0x5a304c, 0xfe82f180, 0xfe82f180, 0xfe82f180, 0x16d45e8c, 0x16d45e8c, 0x16d45e8c, 0xc9cbf769, 0xcf038f81, 0xcf038f81, 0xc9cbf769, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x8bbe1e38, 0xfef8974b, 0x8bbe1e38, 0xdba6ba96, 0x9813a416, 0x9813a416, 0xdf1a19a3, 0xdf1a19a3, 0xdf1a19a3, 0x4ec19f90, 0x4ec19f90, 0x4ec19f90, 0xd2b46a52, 0xd2b46a52, 0xd2b46a52, 0x9813a416, 0xdba6ba96, 0xdba6ba96, 0x9813a416, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xda045c37, 0xb8ae26e3, 0xda045c37, 0xe0ce8dcd, 0x5fcf013d, 0x5fcf013d, 0xee7a1c7, 0xee7a1c7, 0xee7a1c7, 0xdcf7b9b1, 0xdcf7b9b1, 0xdcf7b9b1, 0xc3dc384c, 0xc3dc384c, 0xc3dc384c, 0x5fcf013d, 0xe0ce8dcd, 0xe0ce8dcd, 0x5fcf013d, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x2e35339d, 0x798918b, 0x2e35339d, 0x4e4697f7, 0xdd28f52b, 0xdd28f52b, 0x92c68d60, 0x92c68d60, 0x92c68d60, 0xb3fa7484, 0xb3fa7484, 0xb3fa7484, 0xa98b1715, 0xa98b1715, 0xa98b1715, 0xdd28f52b, 0x4e4697f7, 0x4e4697f7, 0xdd28f52b, }, 20 }, + { "gfxterm_gre", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xb5c5482e, 0xeec9616, 0xb5c5482e, 0x4b834543, 0x43d1f34, 0x43d1f34, 0xd4fadab2, 0xd4fadab2, 0xd4fadab2, 0xabf0731a, 0xabf0731a, 0xabf0731a, 0x43d04a33, 0x43d04a33, 0x43d04a33, 0x43d1f34, 0x4b834543, 0x4b834543, 0x43d1f34, }, 20 }, + { "gfxterm_gre", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xfe511789, 0x421405b3, 0xfe511789, 0xbda7dace, 0x59c36f00, 0x59c36f00, 0x2a367884, 0x2a367884, 0x2a367884, 0x54b615e2, 0x54b615e2, 0x54b615e2, 0x9794282f, 0x9794282f, 0x9794282f, 0x59c36f00, 0xbda7dace, 0xbda7dace, 0x59c36f00, }, 20 }, + { "gfxterm_gre", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x2616eaaf, 0xd0263182, 0x2616eaaf, 0x8136fd0, 0xaa4593fe, 0xaa4593fe, 0x5b85b7a8, 0x5b85b7a8, 0x5b85b7a8, 0xfd70bacf, 0xfd70bacf, 0xfd70bacf, 0x7fd758a4, 0x7fd758a4, 0x7fd758a4, 0xaa4593fe, 0x8136fd0, 0x8136fd0, 0xaa4593fe, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x9214e205, 0x211e70db, 0x9214e205, 0xcf038f81, 0xc9cbf769, 0xc9cbf769, 0x5a304c, 0x5a304c, 0x5a304c, 0xfe82f180, 0xfe82f180, 0xfe82f180, 0x16d45e8c, 0x16d45e8c, 0x16d45e8c, 0xc9cbf769, 0xcf038f81, 0xcf038f81, 0xc9cbf769, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xa841a245, 0x7c4a37aa, 0xa841a245, 0xec4a58f9, 0x5387d57f, 0x5387d57f, 0x8670fc38, 0x8670fc38, 0x8670fc38, 0x462990f4, 0x462990f4, 0x462990f4, 0xa1f71262, 0xa1f71262, 0xa1f71262, 0x5387d57f, 0xec4a58f9, 0xec4a58f9, 0x5387d57f, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xc589c63a, 0xda1b2d71, 0xc589c63a, 0x7fe18ba5, 0xf83ee7aa, 0xf83ee7aa, 0x74883fe5, 0x74883fe5, 0x74883fe5, 0xe8f1ef16, 0xe8f1ef16, 0xe8f1ef16, 0xd04244be, 0xd04244be, 0xd04244be, 0xf83ee7aa, 0x7fe18ba5, 0x7fe18ba5, 0xf83ee7aa, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x5df86da, 0x97465d78, 0x5df86da, 0x14aa338f, 0x724366e5, 0x724366e5, 0x60829227, 0x60829227, 0x60829227, 0x27bbd0dd, 0x27bbd0dd, 0x27bbd0dd, 0x4a95f797, 0x4a95f797, 0x4a95f797, 0x724366e5, 0x14aa338f, 0x14aa338f, 0x724366e5, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xebf6bdc1, 0xaf2c370b, 0xebf6bdc1, 0x46200f8, 0x5387d57f, 0x5387d57f, 0x81cd0740, 0x81cd0740, 0x81cd0740, 0x5f03489d, 0x5f03489d, 0x5f03489d, 0xcc80da83, 0xcc80da83, 0xcc80da83, 0x5387d57f, 0x46200f8, 0x46200f8, 0x5387d57f, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x5455b923, 0x93681ea, 0x5455b923, 0x259f87cf, 0xf83ee7aa, 0xf83ee7aa, 0xf5cd3d43, 0xf5cd3d43, 0xf5cd3d43, 0x87172e73, 0x87172e73, 0x87172e73, 0xb6827fb5, 0xb6827fb5, 0xb6827fb5, 0xf83ee7aa, 0x259f87cf, 0x259f87cf, 0xf83ee7aa, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0xec9a1f85, 0x74e0a22a, 0xec9a1f85, 0x1e4894f5, 0x724366e5, 0x724366e5, 0xa74db0e6, 0xa74db0e6, 0xa74db0e6, 0xfedd43b6, 0xfedd43b6, 0xfedd43b6, 0x366a2df4, 0x366a2df4, 0x366a2df4, 0x724366e5, 0x1e4894f5, 0x1e4894f5, 0x724366e5, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x8cac1ee1, 0x7824cfba, 0x8cac1ee1, 0x8ccca647, 0x1c955882, 0x1c955882, 0xec40c88e, 0xec40c88e, 0xec40c88e, 0x23b78519, 0x23b78519, 0x23b78519, 0xddde890c, 0xddde890c, 0xddde890c, 0x1c955882, 0x8ccca647, 0x8ccca647, 0x1c955882, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xccb8f998, 0x89af656f, 0xccb8f998, 0x8aa609c, 0x4d266f7a, 0x4d266f7a, 0x863eb372, 0x863eb372, 0x863eb372, 0x6049a8cd, 0x6049a8cd, 0x6049a8cd, 0xf870fc5d, 0xf870fc5d, 0xf870fc5d, 0x4d266f7a, 0x8aa609c, 0x8aa609c, 0x4d266f7a, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xa3bd882a, 0x5adc164, 0xa3bd882a, 0x3f4989cd, 0x1ed9d731, 0x1ed9d731, 0x46a1472c, 0x46a1472c, 0x46a1472c, 0xe8c559e9, 0xe8c559e9, 0xe8c559e9, 0xcbac485f, 0xcbac485f, 0xcbac485f, 0x1ed9d731, 0x3f4989cd, 0x3f4989cd, 0x1ed9d731, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xa841a245, 0x7c4a37aa, 0xa841a245, 0xec4a58f9, 0x5387d57f, 0x5387d57f, 0x8670fc38, 0x8670fc38, 0x8670fc38, 0x462990f4, 0x462990f4, 0x462990f4, 0xa1f71262, 0xa1f71262, 0xa1f71262, 0x5387d57f, 0xec4a58f9, 0xec4a58f9, 0x5387d57f, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xc589c63a, 0xda1b2d71, 0xc589c63a, 0x7fe18ba5, 0xf83ee7aa, 0xf83ee7aa, 0x74883fe5, 0x74883fe5, 0x74883fe5, 0xe8f1ef16, 0xe8f1ef16, 0xe8f1ef16, 0xd04244be, 0xd04244be, 0xd04244be, 0xf83ee7aa, 0x7fe18ba5, 0x7fe18ba5, 0xf83ee7aa, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x5df86da, 0x97465d78, 0x5df86da, 0x14aa338f, 0x724366e5, 0x724366e5, 0x60829227, 0x60829227, 0x60829227, 0x27bbd0dd, 0x27bbd0dd, 0x27bbd0dd, 0x4a95f797, 0x4a95f797, 0x4a95f797, 0x724366e5, 0x14aa338f, 0x14aa338f, 0x724366e5, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xebf6bdc1, 0xaf2c370b, 0xebf6bdc1, 0x46200f8, 0x5387d57f, 0x5387d57f, 0x81cd0740, 0x81cd0740, 0x81cd0740, 0x5f03489d, 0x5f03489d, 0x5f03489d, 0xcc80da83, 0xcc80da83, 0xcc80da83, 0x5387d57f, 0x46200f8, 0x46200f8, 0x5387d57f, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x5455b923, 0x93681ea, 0x5455b923, 0x259f87cf, 0xf83ee7aa, 0xf83ee7aa, 0xf5cd3d43, 0xf5cd3d43, 0xf5cd3d43, 0x87172e73, 0x87172e73, 0x87172e73, 0xb6827fb5, 0xb6827fb5, 0xb6827fb5, 0xf83ee7aa, 0x259f87cf, 0x259f87cf, 0xf83ee7aa, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0xec9a1f85, 0x74e0a22a, 0xec9a1f85, 0x1e4894f5, 0x724366e5, 0x724366e5, 0xa74db0e6, 0xa74db0e6, 0xa74db0e6, 0xfedd43b6, 0xfedd43b6, 0xfedd43b6, 0x366a2df4, 0x366a2df4, 0x366a2df4, 0x724366e5, 0x1e4894f5, 0x1e4894f5, 0x724366e5, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x8cac1ee1, 0x7824cfba, 0x8cac1ee1, 0x8ccca647, 0x1c955882, 0x1c955882, 0xec40c88e, 0xec40c88e, 0xec40c88e, 0x23b78519, 0x23b78519, 0x23b78519, 0xddde890c, 0xddde890c, 0xddde890c, 0x1c955882, 0x8ccca647, 0x8ccca647, 0x1c955882, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xccb8f998, 0x89af656f, 0xccb8f998, 0x8aa609c, 0x4d266f7a, 0x4d266f7a, 0x863eb372, 0x863eb372, 0x863eb372, 0x6049a8cd, 0x6049a8cd, 0x6049a8cd, 0xf870fc5d, 0xf870fc5d, 0xf870fc5d, 0x4d266f7a, 0x8aa609c, 0x8aa609c, 0x4d266f7a, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xa3bd882a, 0x5adc164, 0xa3bd882a, 0x3f4989cd, 0x1ed9d731, 0x1ed9d731, 0x46a1472c, 0x46a1472c, 0x46a1472c, 0xe8c559e9, 0xe8c559e9, 0xe8c559e9, 0xcbac485f, 0xcbac485f, 0xcbac485f, 0x1ed9d731, 0x3f4989cd, 0x3f4989cd, 0x1ed9d731, }, 20 }, + { "gfxterm_gre", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x8bbe1e38, 0xfef8974b, 0x8bbe1e38, 0xdba6ba96, 0x9813a416, 0x9813a416, 0xdf1a19a3, 0xdf1a19a3, 0xdf1a19a3, 0x4ec19f90, 0x4ec19f90, 0x4ec19f90, 0xd2b46a52, 0xd2b46a52, 0xd2b46a52, 0x9813a416, 0xdba6ba96, 0xdba6ba96, 0x9813a416, }, 20 }, + { "gfxterm_gre", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xda045c37, 0xb8ae26e3, 0xda045c37, 0xe0ce8dcd, 0x5fcf013d, 0x5fcf013d, 0xee7a1c7, 0xee7a1c7, 0xee7a1c7, 0xdcf7b9b1, 0xdcf7b9b1, 0xdcf7b9b1, 0xc3dc384c, 0xc3dc384c, 0xc3dc384c, 0x5fcf013d, 0xe0ce8dcd, 0xe0ce8dcd, 0x5fcf013d, }, 20 }, + { "gfxterm_gre", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x2e35339d, 0x798918b, 0x2e35339d, 0x4e4697f7, 0xdd28f52b, 0xdd28f52b, 0x92c68d60, 0x92c68d60, 0x92c68d60, 0xb3fa7484, 0xb3fa7484, 0xb3fa7484, 0xa98b1715, 0xa98b1715, 0xa98b1715, 0xdd28f52b, 0x4e4697f7, 0x4e4697f7, 0xdd28f52b, }, 20 }, + { "gfxterm_ru", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xef4073b7, 0x7c0ec717, 0xef4073b7, 0xacb6bef0, 0x59c36f00, 0x59c36f00, 0x1b206d14, 0x1b206d14, 0x1b206d14, 0x65a00072, 0x65a00072, 0x65a00072, 0xa6823dbf, 0xa6823dbf, 0xa6823dbf, 0x59c36f00, 0xacb6bef0, 0xacb6bef0, 0x59c36f00, }, 20 }, + { "gfxterm_ru", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x439c3f9c, 0xb979a570, 0x439c3f9c, 0x6d99bae3, 0xaa4593fe, 0xaa4593fe, 0x7c7873ca, 0x7c7873ca, 0x7c7873ca, 0xda8d7ead, 0xda8d7ead, 0xda8d7ead, 0x582a9cc6, 0x582a9cc6, 0x582a9cc6, 0xaa4593fe, 0x6d99bae3, 0x6d99bae3, 0xaa4593fe, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x5ba2c945, 0x8734093, 0x5ba2c945, 0x6b5a4c1, 0xc9cbf769, 0xc9cbf769, 0xa3843a5a, 0xa3843a5a, 0xa3843a5a, 0x5d5cfb96, 0x5d5cfb96, 0x5d5cfb96, 0xb50a549a, 0xb50a549a, 0xb50a549a, 0xc9cbf769, 0x6b5a4c1, 0x6b5a4c1, 0xc9cbf769, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x1d557c7b, 0x8d172abd, 0x1d557c7b, 0x4d4dd8d5, 0x9813a416, 0x9813a416, 0xae45df54, 0xae45df54, 0xae45df54, 0x3f9e5967, 0x3f9e5967, 0x3f9e5967, 0xa3ebaca5, 0xa3ebaca5, 0xa3ebaca5, 0x9813a416, 0x4d4dd8d5, 0x4d4dd8d5, 0x9813a416, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x75e8bbc6, 0x79f972a, 0x75e8bbc6, 0x4f226a3c, 0x5fcf013d, 0x5fcf013d, 0xe1849dd3, 0xe1849dd3, 0xe1849dd3, 0x339485a5, 0x339485a5, 0x339485a5, 0x2cbf0458, 0x2cbf0458, 0x2cbf0458, 0x5fcf013d, 0x4f226a3c, 0x4f226a3c, 0x5fcf013d, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7391ddfb, 0x7d352e1, 0x7391ddfb, 0x13e27991, 0xdd28f52b, 0xdd28f52b, 0x25591550, 0x25591550, 0x25591550, 0x465ecb4, 0x465ecb4, 0x465ecb4, 0x1e148f25, 0x1e148f25, 0x1e148f25, 0xdd28f52b, 0x13e27991, 0x13e27991, 0xdd28f52b, }, 20 }, + { "gfxterm_ru", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xc009461b, 0xbaf1821c, 0xc009461b, 0x3e4f4b76, 0x43d1f34, 0x43d1f34, 0x19165017, 0x19165017, 0x19165017, 0x661cf9bf, 0x661cf9bf, 0x661cf9bf, 0x8e3cc096, 0x8e3cc096, 0x8e3cc096, 0x43d1f34, 0x3e4f4b76, 0x3e4f4b76, 0x43d1f34, }, 20 }, + { "gfxterm_ru", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xef4073b7, 0x7c0ec717, 0xef4073b7, 0xacb6bef0, 0x59c36f00, 0x59c36f00, 0x1b206d14, 0x1b206d14, 0x1b206d14, 0x65a00072, 0x65a00072, 0x65a00072, 0xa6823dbf, 0xa6823dbf, 0xa6823dbf, 0x59c36f00, 0xacb6bef0, 0xacb6bef0, 0x59c36f00, }, 20 }, + { "gfxterm_ru", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x439c3f9c, 0xb979a570, 0x439c3f9c, 0x6d99bae3, 0xaa4593fe, 0xaa4593fe, 0x7c7873ca, 0x7c7873ca, 0x7c7873ca, 0xda8d7ead, 0xda8d7ead, 0xda8d7ead, 0x582a9cc6, 0x582a9cc6, 0x582a9cc6, 0xaa4593fe, 0x6d99bae3, 0x6d99bae3, 0xaa4593fe, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x5ba2c945, 0x8734093, 0x5ba2c945, 0x6b5a4c1, 0xc9cbf769, 0xc9cbf769, 0xa3843a5a, 0xa3843a5a, 0xa3843a5a, 0x5d5cfb96, 0x5d5cfb96, 0x5d5cfb96, 0xb50a549a, 0xb50a549a, 0xb50a549a, 0xc9cbf769, 0x6b5a4c1, 0x6b5a4c1, 0xc9cbf769, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xb36b0c97, 0x8089853c, 0xb36b0c97, 0xf760f62b, 0x5387d57f, 0x5387d57f, 0x26a49a0, 0x26a49a0, 0x26a49a0, 0xc233256c, 0xc233256c, 0xc233256c, 0x25eda7fa, 0x25eda7fa, 0x25eda7fa, 0x5387d57f, 0xf760f62b, 0xf760f62b, 0x5387d57f, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x73036285, 0xc9508972, 0x73036285, 0xc96b2f1a, 0xf83ee7aa, 0xf83ee7aa, 0xd1a3be96, 0xd1a3be96, 0xd1a3be96, 0x4dda6e65, 0x4dda6e65, 0x4dda6e65, 0x7569c5cd, 0x7569c5cd, 0x7569c5cd, 0xf83ee7aa, 0xc96b2f1a, 0xc96b2f1a, 0xf83ee7aa, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x2f903fa3, 0xb074c7d0, 0x2f903fa3, 0x3ee58af6, 0x724366e5, 0x724366e5, 0xd7d194f8, 0xd7d194f8, 0xd7d194f8, 0x90e8d602, 0x90e8d602, 0x90e8d602, 0xfdc6f148, 0xfdc6f148, 0xfdc6f148, 0x724366e5, 0x3ee58af6, 0x3ee58af6, 0x724366e5, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xa54ffd19, 0xf7cc7ac2, 0xa54ffd19, 0x4adb4020, 0x5387d57f, 0x5387d57f, 0x5dbc1d5, 0x5dbc1d5, 0x5dbc1d5, 0xdb158e08, 0xdb158e08, 0xdb158e08, 0x48961c16, 0x48961c16, 0x48961c16, 0x5387d57f, 0x4adb4020, 0x4adb4020, 0x5387d57f, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xc66fad35, 0x8aac8190, 0xc66fad35, 0xb7a593d9, 0xf83ee7aa, 0xf83ee7aa, 0xb36d8105, 0xb36d8105, 0xb36d8105, 0xc1b79235, 0xc1b79235, 0xc1b79235, 0xf022c3f3, 0xf022c3f3, 0xf022c3f3, 0xf83ee7aa, 0xb7a593d9, 0xb7a593d9, 0xf83ee7aa, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x7f916214, 0x1c80967c, 0x7f916214, 0x8d43e964, 0x724366e5, 0x724366e5, 0xe456696, 0xe456696, 0xe456696, 0x57d595c6, 0x57d595c6, 0x57d595c6, 0x9f62fb84, 0x9f62fb84, 0x9f62fb84, 0x724366e5, 0x8d43e964, 0x8d43e964, 0x724366e5, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x4aeca683, 0xffbbb38e, 0x4aeca683, 0x4a8c1e25, 0x1c955882, 0x1c955882, 0xa0d2f3f6, 0xa0d2f3f6, 0xa0d2f3f6, 0x6f25be61, 0x6f25be61, 0x6f25be61, 0x914cb274, 0x914cb274, 0x914cb274, 0x1c955882, 0x4a8c1e25, 0x4a8c1e25, 0x1c955882, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xb44532a7, 0x73b09a92, 0xb44532a7, 0x7057aba3, 0x4d266f7a, 0x4d266f7a, 0x83606d88, 0x83606d88, 0x83606d88, 0x65177637, 0x65177637, 0x65177637, 0xfd2e22a7, 0xfd2e22a7, 0xfd2e22a7, 0x4d266f7a, 0x7057aba3, 0x7057aba3, 0x4d266f7a, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x62257381, 0xd5d910, 0x62257381, 0xfed17266, 0x1ed9d731, 0x1ed9d731, 0x12670373, 0x12670373, 0x12670373, 0xbc031db6, 0xbc031db6, 0xbc031db6, 0x9f6a0c00, 0x9f6a0c00, 0x9f6a0c00, 0x1ed9d731, 0xfed17266, 0xfed17266, 0x1ed9d731, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xb36b0c97, 0x8089853c, 0xb36b0c97, 0xf760f62b, 0x5387d57f, 0x5387d57f, 0x26a49a0, 0x26a49a0, 0x26a49a0, 0xc233256c, 0xc233256c, 0xc233256c, 0x25eda7fa, 0x25eda7fa, 0x25eda7fa, 0x5387d57f, 0xf760f62b, 0xf760f62b, 0x5387d57f, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x73036285, 0xc9508972, 0x73036285, 0xc96b2f1a, 0xf83ee7aa, 0xf83ee7aa, 0xd1a3be96, 0xd1a3be96, 0xd1a3be96, 0x4dda6e65, 0x4dda6e65, 0x4dda6e65, 0x7569c5cd, 0x7569c5cd, 0x7569c5cd, 0xf83ee7aa, 0xc96b2f1a, 0xc96b2f1a, 0xf83ee7aa, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x2f903fa3, 0xb074c7d0, 0x2f903fa3, 0x3ee58af6, 0x724366e5, 0x724366e5, 0xd7d194f8, 0xd7d194f8, 0xd7d194f8, 0x90e8d602, 0x90e8d602, 0x90e8d602, 0xfdc6f148, 0xfdc6f148, 0xfdc6f148, 0x724366e5, 0x3ee58af6, 0x3ee58af6, 0x724366e5, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xa54ffd19, 0xf7cc7ac2, 0xa54ffd19, 0x4adb4020, 0x5387d57f, 0x5387d57f, 0x5dbc1d5, 0x5dbc1d5, 0x5dbc1d5, 0xdb158e08, 0xdb158e08, 0xdb158e08, 0x48961c16, 0x48961c16, 0x48961c16, 0x5387d57f, 0x4adb4020, 0x4adb4020, 0x5387d57f, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xc66fad35, 0x8aac8190, 0xc66fad35, 0xb7a593d9, 0xf83ee7aa, 0xf83ee7aa, 0xb36d8105, 0xb36d8105, 0xb36d8105, 0xc1b79235, 0xc1b79235, 0xc1b79235, 0xf022c3f3, 0xf022c3f3, 0xf022c3f3, 0xf83ee7aa, 0xb7a593d9, 0xb7a593d9, 0xf83ee7aa, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x7f916214, 0x1c80967c, 0x7f916214, 0x8d43e964, 0x724366e5, 0x724366e5, 0xe456696, 0xe456696, 0xe456696, 0x57d595c6, 0x57d595c6, 0x57d595c6, 0x9f62fb84, 0x9f62fb84, 0x9f62fb84, 0x724366e5, 0x8d43e964, 0x8d43e964, 0x724366e5, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x4aeca683, 0xffbbb38e, 0x4aeca683, 0x4a8c1e25, 0x1c955882, 0x1c955882, 0xa0d2f3f6, 0xa0d2f3f6, 0xa0d2f3f6, 0x6f25be61, 0x6f25be61, 0x6f25be61, 0x914cb274, 0x914cb274, 0x914cb274, 0x1c955882, 0x4a8c1e25, 0x4a8c1e25, 0x1c955882, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xb44532a7, 0x73b09a92, 0xb44532a7, 0x7057aba3, 0x4d266f7a, 0x4d266f7a, 0x83606d88, 0x83606d88, 0x83606d88, 0x65177637, 0x65177637, 0x65177637, 0xfd2e22a7, 0xfd2e22a7, 0xfd2e22a7, 0x4d266f7a, 0x7057aba3, 0x7057aba3, 0x4d266f7a, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x62257381, 0xd5d910, 0x62257381, 0xfed17266, 0x1ed9d731, 0x1ed9d731, 0x12670373, 0x12670373, 0x12670373, 0xbc031db6, 0xbc031db6, 0xbc031db6, 0x9f6a0c00, 0x9f6a0c00, 0x9f6a0c00, 0x1ed9d731, 0xfed17266, 0xfed17266, 0x1ed9d731, }, 20 }, + { "gfxterm_ru", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x1d557c7b, 0x8d172abd, 0x1d557c7b, 0x4d4dd8d5, 0x9813a416, 0x9813a416, 0xae45df54, 0xae45df54, 0xae45df54, 0x3f9e5967, 0x3f9e5967, 0x3f9e5967, 0xa3ebaca5, 0xa3ebaca5, 0xa3ebaca5, 0x9813a416, 0x4d4dd8d5, 0x4d4dd8d5, 0x9813a416, }, 20 }, + { "gfxterm_ru", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x75e8bbc6, 0x79f972a, 0x75e8bbc6, 0x4f226a3c, 0x5fcf013d, 0x5fcf013d, 0xe1849dd3, 0xe1849dd3, 0xe1849dd3, 0x339485a5, 0x339485a5, 0x339485a5, 0x2cbf0458, 0x2cbf0458, 0x2cbf0458, 0x5fcf013d, 0x4f226a3c, 0x4f226a3c, 0x5fcf013d, }, 20 }, + { "gfxterm_ru", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7391ddfb, 0x7d352e1, 0x7391ddfb, 0x13e27991, 0xdd28f52b, 0xdd28f52b, 0x25591550, 0x25591550, 0x25591550, 0x465ecb4, 0x465ecb4, 0x465ecb4, 0x1e148f25, 0x1e148f25, 0x1e148f25, 0xdd28f52b, 0x13e27991, 0x13e27991, 0xdd28f52b, }, 20 }, + { "gfxterm_fr", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x371337c9, 0x8aa416bc, 0x371337c9, 0x74e5fa8e, 0x59c36f00, 0x59c36f00, 0xb169e11b, 0xb169e11b, 0xb169e11b, 0xcfe98c7d, 0xcfe98c7d, 0xcfe98c7d, 0xccbb1b0, 0xccbb1b0, 0xccbb1b0, 0x59c36f00, 0x74e5fa8e, 0x74e5fa8e, 0x59c36f00, }, 20 }, + { "gfxterm_fr", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x38692869, 0xefb9c2f4, 0x38692869, 0x166cad16, 0xaa4593fe, 0xaa4593fe, 0xe4f03f82, 0xe4f03f82, 0xe4f03f82, 0x420532e5, 0x420532e5, 0x420532e5, 0xc0a2d08e, 0xc0a2d08e, 0xc0a2d08e, 0xaa4593fe, 0x166cad16, 0x166cad16, 0xaa4593fe, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x7eb7ddfd, 0x19db9bb1, 0x7eb7ddfd, 0x23a0b079, 0xc9cbf769, 0xc9cbf769, 0x4500ac91, 0x4500ac91, 0x4500ac91, 0xbbd86d5d, 0xbbd86d5d, 0xbbd86d5d, 0x538ec251, 0x538ec251, 0x538ec251, 0xc9cbf769, 0x23a0b079, 0x23a0b079, 0xc9cbf769, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x35512c6d, 0xe29deaf0, 0x35512c6d, 0x654988c3, 0x9813a416, 0x9813a416, 0xc6920c94, 0xc6920c94, 0xc6920c94, 0x57498aa7, 0x57498aa7, 0x57498aa7, 0xcb3c7f65, 0xcb3c7f65, 0xcb3c7f65, 0x9813a416, 0x654988c3, 0x654988c3, 0x9813a416, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x73ff9071, 0x72b83f24, 0x73ff9071, 0x4935418b, 0x5fcf013d, 0x5fcf013d, 0x9963ff63, 0x9963ff63, 0x9963ff63, 0x4b73e715, 0x4b73e715, 0x4b73e715, 0x545866e8, 0x545866e8, 0x545866e8, 0x5fcf013d, 0x4935418b, 0x4935418b, 0x5fcf013d, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x46811b4e, 0xa463f7aa, 0x46811b4e, 0x26f2bf24, 0xdd28f52b, 0xdd28f52b, 0x452cf740, 0x452cf740, 0x452cf740, 0x64100ea4, 0x64100ea4, 0x64100ea4, 0x7e616d35, 0x7e616d35, 0x7e616d35, 0xdd28f52b, 0x26f2bf24, 0x26f2bf24, 0xdd28f52b, }, 20 }, + { "gfxterm_fr", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xd89b7256, 0xe60a4e85, 0xd89b7256, 0x26dd7f3b, 0x43d1f34, 0x43d1f34, 0x55b946c0, 0x55b946c0, 0x55b946c0, 0x2ab3ef68, 0x2ab3ef68, 0x2ab3ef68, 0xc293d641, 0xc293d641, 0xc293d641, 0x43d1f34, 0x26dd7f3b, 0x26dd7f3b, 0x43d1f34, }, 20 }, + { "gfxterm_fr", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x371337c9, 0x8aa416bc, 0x371337c9, 0x74e5fa8e, 0x59c36f00, 0x59c36f00, 0xb169e11b, 0xb169e11b, 0xb169e11b, 0xcfe98c7d, 0xcfe98c7d, 0xcfe98c7d, 0xccbb1b0, 0xccbb1b0, 0xccbb1b0, 0x59c36f00, 0x74e5fa8e, 0x74e5fa8e, 0x59c36f00, }, 20 }, + { "gfxterm_fr", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x38692869, 0xefb9c2f4, 0x38692869, 0x166cad16, 0xaa4593fe, 0xaa4593fe, 0xe4f03f82, 0xe4f03f82, 0xe4f03f82, 0x420532e5, 0x420532e5, 0x420532e5, 0xc0a2d08e, 0xc0a2d08e, 0xc0a2d08e, 0xaa4593fe, 0x166cad16, 0x166cad16, 0xaa4593fe, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x7eb7ddfd, 0x19db9bb1, 0x7eb7ddfd, 0x23a0b079, 0xc9cbf769, 0xc9cbf769, 0x4500ac91, 0x4500ac91, 0x4500ac91, 0xbbd86d5d, 0xbbd86d5d, 0xbbd86d5d, 0x538ec251, 0x538ec251, 0x538ec251, 0xc9cbf769, 0x23a0b079, 0x23a0b079, 0xc9cbf769, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0x60f63dde, 0xcb069f7a, 0x60f63dde, 0x24fdc762, 0x5387d57f, 0x5387d57f, 0xf5998b00, 0xf5998b00, 0xf5998b00, 0x35c0e7cc, 0x35c0e7cc, 0x35c0e7cc, 0xd21e655a, 0xd21e655a, 0xd21e655a, 0x5387d57f, 0x24fdc762, 0x24fdc762, 0x5387d57f, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x8fa5f86d, 0xed066d2c, 0x8fa5f86d, 0x35cdb5f2, 0xf83ee7aa, 0xf83ee7aa, 0x26e9dc45, 0x26e9dc45, 0x26e9dc45, 0xba900cb6, 0xba900cb6, 0xba900cb6, 0x8223a71e, 0x8223a71e, 0x8223a71e, 0xf83ee7aa, 0x35cdb5f2, 0x35cdb5f2, 0xf83ee7aa, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0xf3ebce27, 0x64821e83, 0xf3ebce27, 0xe29e7b72, 0x724366e5, 0x724366e5, 0xf2920fc5, 0xf2920fc5, 0xf2920fc5, 0xb5ab4d3f, 0xb5ab4d3f, 0xb5ab4d3f, 0xd8856a75, 0xd8856a75, 0xd8856a75, 0x724366e5, 0xe29e7b72, 0xe29e7b72, 0x724366e5, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xda2165d2, 0x5f811c6d, 0xda2165d2, 0x35b5d8eb, 0x5387d57f, 0x5387d57f, 0xe5a2fdfd, 0xe5a2fdfd, 0xe5a2fdfd, 0x3b6cb220, 0x3b6cb220, 0x3b6cb220, 0xa8ef203e, 0xa8ef203e, 0xa8ef203e, 0x5387d57f, 0x35b5d8eb, 0x35b5d8eb, 0x5387d57f, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xf52ba155, 0x4866b5cd, 0xf52ba155, 0x84e19fb9, 0xf83ee7aa, 0xf83ee7aa, 0xc1a44e99, 0xc1a44e99, 0xc1a44e99, 0xb37e5da9, 0xb37e5da9, 0xb37e5da9, 0x82eb0c6f, 0x82eb0c6f, 0x82eb0c6f, 0xf83ee7aa, 0x84e19fb9, 0x84e19fb9, 0xf83ee7aa, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x16d37834, 0x72eb8d00, 0x16d37834, 0xe401f344, 0x724366e5, 0x724366e5, 0xc80f0332, 0xc80f0332, 0xc80f0332, 0x919ff062, 0x919ff062, 0x919ff062, 0x59289e20, 0x59289e20, 0x59289e20, 0x724366e5, 0xe401f344, 0xe401f344, 0x724366e5, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x501ed137, 0x3eb913d3, 0x501ed137, 0x507e6991, 0x1c955882, 0x1c955882, 0xc988465d, 0xc988465d, 0xc988465d, 0x67f0bca, 0x67f0bca, 0x67f0bca, 0xf81607df, 0xf81607df, 0xf81607df, 0x1c955882, 0x507e6991, 0x507e6991, 0x1c955882, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xdbf45ff0, 0x4b12f903, 0xdbf45ff0, 0x1fe6c6f4, 0x4d266f7a, 0x4d266f7a, 0xee77b36d, 0xee77b36d, 0xee77b36d, 0x800a8d2, 0x800a8d2, 0x800a8d2, 0x9039fc42, 0x9039fc42, 0x9039fc42, 0x4d266f7a, 0x1fe6c6f4, 0x1fe6c6f4, 0x4d266f7a, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x6c3a9814, 0xaa19882a, 0x6c3a9814, 0xf0ce99f3, 0x1ed9d731, 0x1ed9d731, 0x5819ad52, 0x5819ad52, 0x5819ad52, 0xf67db397, 0xf67db397, 0xf67db397, 0xd514a221, 0xd514a221, 0xd514a221, 0x1ed9d731, 0xf0ce99f3, 0xf0ce99f3, 0x1ed9d731, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0x60f63dde, 0xcb069f7a, 0x60f63dde, 0x24fdc762, 0x5387d57f, 0x5387d57f, 0xf5998b00, 0xf5998b00, 0xf5998b00, 0x35c0e7cc, 0x35c0e7cc, 0x35c0e7cc, 0xd21e655a, 0xd21e655a, 0xd21e655a, 0x5387d57f, 0x24fdc762, 0x24fdc762, 0x5387d57f, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x8fa5f86d, 0xed066d2c, 0x8fa5f86d, 0x35cdb5f2, 0xf83ee7aa, 0xf83ee7aa, 0x26e9dc45, 0x26e9dc45, 0x26e9dc45, 0xba900cb6, 0xba900cb6, 0xba900cb6, 0x8223a71e, 0x8223a71e, 0x8223a71e, 0xf83ee7aa, 0x35cdb5f2, 0x35cdb5f2, 0xf83ee7aa, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0xf3ebce27, 0x64821e83, 0xf3ebce27, 0xe29e7b72, 0x724366e5, 0x724366e5, 0xf2920fc5, 0xf2920fc5, 0xf2920fc5, 0xb5ab4d3f, 0xb5ab4d3f, 0xb5ab4d3f, 0xd8856a75, 0xd8856a75, 0xd8856a75, 0x724366e5, 0xe29e7b72, 0xe29e7b72, 0x724366e5, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xda2165d2, 0x5f811c6d, 0xda2165d2, 0x35b5d8eb, 0x5387d57f, 0x5387d57f, 0xe5a2fdfd, 0xe5a2fdfd, 0xe5a2fdfd, 0x3b6cb220, 0x3b6cb220, 0x3b6cb220, 0xa8ef203e, 0xa8ef203e, 0xa8ef203e, 0x5387d57f, 0x35b5d8eb, 0x35b5d8eb, 0x5387d57f, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xf52ba155, 0x4866b5cd, 0xf52ba155, 0x84e19fb9, 0xf83ee7aa, 0xf83ee7aa, 0xc1a44e99, 0xc1a44e99, 0xc1a44e99, 0xb37e5da9, 0xb37e5da9, 0xb37e5da9, 0x82eb0c6f, 0x82eb0c6f, 0x82eb0c6f, 0xf83ee7aa, 0x84e19fb9, 0x84e19fb9, 0xf83ee7aa, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x16d37834, 0x72eb8d00, 0x16d37834, 0xe401f344, 0x724366e5, 0x724366e5, 0xc80f0332, 0xc80f0332, 0xc80f0332, 0x919ff062, 0x919ff062, 0x919ff062, 0x59289e20, 0x59289e20, 0x59289e20, 0x724366e5, 0xe401f344, 0xe401f344, 0x724366e5, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x501ed137, 0x3eb913d3, 0x501ed137, 0x507e6991, 0x1c955882, 0x1c955882, 0xc988465d, 0xc988465d, 0xc988465d, 0x67f0bca, 0x67f0bca, 0x67f0bca, 0xf81607df, 0xf81607df, 0xf81607df, 0x1c955882, 0x507e6991, 0x507e6991, 0x1c955882, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xdbf45ff0, 0x4b12f903, 0xdbf45ff0, 0x1fe6c6f4, 0x4d266f7a, 0x4d266f7a, 0xee77b36d, 0xee77b36d, 0xee77b36d, 0x800a8d2, 0x800a8d2, 0x800a8d2, 0x9039fc42, 0x9039fc42, 0x9039fc42, 0x4d266f7a, 0x1fe6c6f4, 0x1fe6c6f4, 0x4d266f7a, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x6c3a9814, 0xaa19882a, 0x6c3a9814, 0xf0ce99f3, 0x1ed9d731, 0x1ed9d731, 0x5819ad52, 0x5819ad52, 0x5819ad52, 0xf67db397, 0xf67db397, 0xf67db397, 0xd514a221, 0xd514a221, 0xd514a221, 0x1ed9d731, 0xf0ce99f3, 0xf0ce99f3, 0x1ed9d731, }, 20 }, + { "gfxterm_fr", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x35512c6d, 0xe29deaf0, 0x35512c6d, 0x654988c3, 0x9813a416, 0x9813a416, 0xc6920c94, 0xc6920c94, 0xc6920c94, 0x57498aa7, 0x57498aa7, 0x57498aa7, 0xcb3c7f65, 0xcb3c7f65, 0xcb3c7f65, 0x9813a416, 0x654988c3, 0x654988c3, 0x9813a416, }, 20 }, + { "gfxterm_fr", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x73ff9071, 0x72b83f24, 0x73ff9071, 0x4935418b, 0x5fcf013d, 0x5fcf013d, 0x9963ff63, 0x9963ff63, 0x9963ff63, 0x4b73e715, 0x4b73e715, 0x4b73e715, 0x545866e8, 0x545866e8, 0x545866e8, 0x5fcf013d, 0x4935418b, 0x4935418b, 0x5fcf013d, }, 20 }, + { "gfxterm_fr", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x46811b4e, 0xa463f7aa, 0x46811b4e, 0x26f2bf24, 0xdd28f52b, 0xdd28f52b, 0x452cf740, 0x452cf740, 0x452cf740, 0x64100ea4, 0x64100ea4, 0x64100ea4, 0x7e616d35, 0x7e616d35, 0x7e616d35, 0xdd28f52b, 0x26f2bf24, 0x26f2bf24, 0xdd28f52b, }, 20 }, + { "gfxterm_quot", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x791b97c6, 0xd80a4dd5, 0x791b97c6, 0x3aed5a81, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x3aed5a81, 0x3aed5a81, 0x59c36f00, }, 20 }, + { "gfxterm_quot", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x6c6b27f2, 0x9ad8591c, 0x6c6b27f2, 0x426ea28d, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0x426ea28d, 0x426ea28d, 0xaa4593fe, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xb553210b, 0xf9eb9fa4, 0xb553210b, 0xe8444c8f, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0xe8444c8f, 0xe8444c8f, 0xc9cbf769, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x979d71de, 0x73e38996, 0x979d71de, 0xc785d570, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0xc785d570, 0xc785d570, 0x9813a416, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x78d87f9d, 0x345e385f, 0x78d87f9d, 0x4212ae67, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0x4212ae67, 0x4212ae67, 0x5fcf013d, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x750f8146, 0x2148bdae, 0x750f8146, 0x157c252c, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0x157c252c, 0x157c252c, 0xdd28f52b, }, 20 }, + { "gfxterm_quot", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x58828a1e, 0x11d1547e, 0x58828a1e, 0xa6c48773, 0x43d1f34, 0x43d1f34, 0xd204ac75, 0xd204ac75, 0xd204ac75, 0xad0e05dd, 0xad0e05dd, 0xad0e05dd, 0x452e3cf4, 0x452e3cf4, 0x452e3cf4, 0x43d1f34, 0xa6c48773, 0xa6c48773, 0x43d1f34, }, 20 }, + { "gfxterm_quot", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x791b97c6, 0xd80a4dd5, 0x791b97c6, 0x3aed5a81, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x3aed5a81, 0x3aed5a81, 0x59c36f00, }, 20 }, + { "gfxterm_quot", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x6c6b27f2, 0x9ad8591c, 0x6c6b27f2, 0x426ea28d, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0x426ea28d, 0x426ea28d, 0xaa4593fe, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0xb553210b, 0xf9eb9fa4, 0xb553210b, 0xe8444c8f, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0xe8444c8f, 0xe8444c8f, 0xc9cbf769, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xe0300e88, 0x76ba1dd0, 0xe0300e88, 0xa43bf434, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0xa43bf434, 0xa43bf434, 0x5387d57f, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xa26081d9, 0xef5b1078, 0xa26081d9, 0x1808cc46, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0x1808cc46, 0x1808cc46, 0xf83ee7aa, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x6f16d50f, 0x2fc71082, 0x6f16d50f, 0x7e63605a, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x7e63605a, 0x7e63605a, 0x724366e5, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xc959920b, 0x3548d7d5, 0xc959920b, 0x26cd2f32, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0x26cd2f32, 0x26cd2f32, 0x5387d57f, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x93c26040, 0x70ae777c, 0x93c26040, 0xe2085eac, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0xe2085eac, 0xe2085eac, 0xf83ee7aa, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x73b37a76, 0x352c8931, 0x73b37a76, 0x8161f106, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0x8161f106, 0x8161f106, 0x724366e5, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0xe12eaf27, 0xe7b5009a, 0xe12eaf27, 0xe14e1781, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0xe14e1781, 0xe14e1781, 0x1c955882, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x5a376c04, 0xd27c4646, 0x5a376c04, 0x9e25f500, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0x9e25f500, 0x9e25f500, 0x4d266f7a, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x3f02033b, 0xd99eaa7, 0x3f02033b, 0xa3f602dc, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0xa3f602dc, 0xa3f602dc, 0x1ed9d731, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xe0300e88, 0x76ba1dd0, 0xe0300e88, 0xa43bf434, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0xa43bf434, 0xa43bf434, 0x5387d57f, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xa26081d9, 0xef5b1078, 0xa26081d9, 0x1808cc46, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0x1808cc46, 0x1808cc46, 0xf83ee7aa, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x6f16d50f, 0x2fc71082, 0x6f16d50f, 0x7e63605a, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x7e63605a, 0x7e63605a, 0x724366e5, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xc959920b, 0x3548d7d5, 0xc959920b, 0x26cd2f32, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0x26cd2f32, 0x26cd2f32, 0x5387d57f, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x93c26040, 0x70ae777c, 0x93c26040, 0xe2085eac, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0xe2085eac, 0xe2085eac, 0xf83ee7aa, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x73b37a76, 0x352c8931, 0x73b37a76, 0x8161f106, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0x8161f106, 0x8161f106, 0x724366e5, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0xe12eaf27, 0xe7b5009a, 0xe12eaf27, 0xe14e1781, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0xe14e1781, 0xe14e1781, 0x1c955882, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x5a376c04, 0xd27c4646, 0x5a376c04, 0x9e25f500, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0x9e25f500, 0x9e25f500, 0x4d266f7a, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x3f02033b, 0xd99eaa7, 0x3f02033b, 0xa3f602dc, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0xa3f602dc, 0xa3f602dc, 0x1ed9d731, }, 20 }, + { "gfxterm_quot", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x979d71de, 0x73e38996, 0x979d71de, 0xc785d570, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0xc785d570, 0xc785d570, 0x9813a416, }, 20 }, + { "gfxterm_quot", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x78d87f9d, 0x345e385f, 0x78d87f9d, 0x4212ae67, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0x4212ae67, 0x4212ae67, 0x5fcf013d, }, 20 }, + { "gfxterm_quot", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x750f8146, 0x2148bdae, 0x750f8146, 0x157c252c, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0x157c252c, 0x157c252c, 0xdd28f52b, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xaabbbcdc, 0x5f5dabb0, 0xaabbbcdc, 0xe94d719b, 0x59c36f00, 0x59c36f00, 0x18f47430, 0x18f47430, 0x18f47430, 0x66741956, 0x66741956, 0x66741956, 0xa556249b, 0xa556249b, 0xa556249b, 0x59c36f00, 0xe94d719b, 0xe94d719b, 0x59c36f00, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0xb6fa31f0, 0xc274fbe9, 0xb6fa31f0, 0x98ffb48f, 0xaa4593fe, 0xaa4593fe, 0x4fb2120a, 0x4fb2120a, 0x4fb2120a, 0xe9471f6d, 0xe9471f6d, 0xe9471f6d, 0x6be0fd06, 0x6be0fd06, 0x6be0fd06, 0xaa4593fe, 0x98ffb48f, 0x98ffb48f, 0xaa4593fe, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x9c83aa67, 0x67876bdc, 0x9c83aa67, 0xc194c7e3, 0xc9cbf769, 0xc9cbf769, 0xd6fd9f4a, 0xd6fd9f4a, 0xd6fd9f4a, 0x28255e86, 0x28255e86, 0x28255e86, 0xc073f18a, 0xc073f18a, 0xc073f18a, 0xc9cbf769, 0xc194c7e3, 0xc194c7e3, 0xc9cbf769, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x4878468, 0x58d7f660, 0x4878468, 0x549f20c6, 0x9813a416, 0x9813a416, 0x7c4d228e, 0x7c4d228e, 0x7c4d228e, 0xed96a4bd, 0xed96a4bd, 0xed96a4bd, 0x71e3517f, 0x71e3517f, 0x71e3517f, 0x9813a416, 0x549f20c6, 0x549f20c6, 0x9813a416, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xc24f3617, 0xe92e5f60, 0xc24f3617, 0xf885e7ed, 0x5fcf013d, 0x5fcf013d, 0x9a58adbf, 0x9a58adbf, 0x9a58adbf, 0x4848b5c9, 0x4848b5c9, 0x4848b5c9, 0x57633434, 0x57633434, 0x57633434, 0x5fcf013d, 0xf885e7ed, 0xf885e7ed, 0x5fcf013d, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xe0056f23, 0xe723a6de, 0xe0056f23, 0x8076cb49, 0xdd28f52b, 0xdd28f52b, 0x7cf3620d, 0x7cf3620d, 0x7cf3620d, 0x5dcf9be9, 0x5dcf9be9, 0x5dcf9be9, 0x47bef878, 0x47bef878, 0x47bef878, 0xdd28f52b, 0x8076cb49, 0x8076cb49, 0xdd28f52b, }, 20 }, + { "gfxterm_piglatin", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x74a1734e, 0x3152f141, 0x74a1734e, 0x8ae77e23, 0x43d1f34, 0x43d1f34, 0x83c19830, 0x83c19830, 0x83c19830, 0xfccb3198, 0xfccb3198, 0xfccb3198, 0x14eb08b1, 0x14eb08b1, 0x14eb08b1, 0x43d1f34, 0x8ae77e23, 0x8ae77e23, 0x43d1f34, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xaabbbcdc, 0x5f5dabb0, 0xaabbbcdc, 0xe94d719b, 0x59c36f00, 0x59c36f00, 0x18f47430, 0x18f47430, 0x18f47430, 0x66741956, 0x66741956, 0x66741956, 0xa556249b, 0xa556249b, 0xa556249b, 0x59c36f00, 0xe94d719b, 0xe94d719b, 0x59c36f00, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0xb6fa31f0, 0xc274fbe9, 0xb6fa31f0, 0x98ffb48f, 0xaa4593fe, 0xaa4593fe, 0x4fb2120a, 0x4fb2120a, 0x4fb2120a, 0xe9471f6d, 0xe9471f6d, 0xe9471f6d, 0x6be0fd06, 0x6be0fd06, 0x6be0fd06, 0xaa4593fe, 0x98ffb48f, 0x98ffb48f, 0xaa4593fe, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x9c83aa67, 0x67876bdc, 0x9c83aa67, 0xc194c7e3, 0xc9cbf769, 0xc9cbf769, 0xd6fd9f4a, 0xd6fd9f4a, 0xd6fd9f4a, 0x28255e86, 0x28255e86, 0x28255e86, 0xc073f18a, 0xc073f18a, 0xc073f18a, 0xc9cbf769, 0xc194c7e3, 0xc194c7e3, 0xc9cbf769, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xd63f83a3, 0x3dc5a0b4, 0xd63f83a3, 0x9234791f, 0x5387d57f, 0x5387d57f, 0x4cb03e4e, 0x4cb03e4e, 0x4cb03e4e, 0x8ce95282, 0x8ce95282, 0x8ce95282, 0x6b37d014, 0x6b37d014, 0x6b37d014, 0x5387d57f, 0x9234791f, 0x9234791f, 0x5387d57f, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x89626ffa, 0xb4d6175c, 0x89626ffa, 0x330a2265, 0xf83ee7aa, 0xf83ee7aa, 0xbbfb89b5, 0xbbfb89b5, 0xbbfb89b5, 0x27825946, 0x27825946, 0x27825946, 0x1f31f2ee, 0x1f31f2ee, 0x1f31f2ee, 0xf83ee7aa, 0x330a2265, 0x330a2265, 0xf83ee7aa, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x3df87fc2, 0x8c55d02c, 0x3df87fc2, 0x2c8dca97, 0x724366e5, 0x724366e5, 0x3f06ba55, 0x3f06ba55, 0x3f06ba55, 0x783ff8af, 0x783ff8af, 0x783ff8af, 0x1511dfe5, 0x1511dfe5, 0x1511dfe5, 0x724366e5, 0x2c8dca97, 0x2c8dca97, 0x724366e5, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0xe39cde76, 0x443930df, 0xe39cde76, 0xc08634f, 0x5387d57f, 0x5387d57f, 0x44754e5f, 0x44754e5f, 0x44754e5f, 0x9abb0182, 0x9abb0182, 0x9abb0182, 0x938939c, 0x938939c, 0x938939c, 0x5387d57f, 0xc08634f, 0xc08634f, 0x5387d57f, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xa0b7c23d, 0x8cd3be29, 0xa0b7c23d, 0xd17dfcd1, 0xf83ee7aa, 0xf83ee7aa, 0x5feda75, 0x5feda75, 0x5feda75, 0x7724c945, 0x7724c945, 0x7724c945, 0x46b19883, 0x46b19883, 0x46b19883, 0xf83ee7aa, 0xd17dfcd1, 0xd17dfcd1, 0xf83ee7aa, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0xa994524d, 0xc1900d08, 0xa994524d, 0x5b46d93d, 0x724366e5, 0x724366e5, 0x6d0a4799, 0x6d0a4799, 0x6d0a4799, 0x349ab4c9, 0x349ab4c9, 0x349ab4c9, 0xfc2dda8b, 0xfc2dda8b, 0xfc2dda8b, 0x724366e5, 0x5b46d93d, 0x5b46d93d, 0x724366e5, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x41755bc6, 0xf207b232, 0x41755bc6, 0x4115e360, 0x1c955882, 0x1c955882, 0x428d20f6, 0x428d20f6, 0x428d20f6, 0x8d7a6d61, 0x8d7a6d61, 0x8d7a6d61, 0x73136174, 0x73136174, 0x73136174, 0x1c955882, 0x4115e360, 0x4115e360, 0x1c955882, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xe47ded44, 0x862f2131, 0xe47ded44, 0x206f7440, 0x4d266f7a, 0x4d266f7a, 0x95d7f079, 0x95d7f079, 0x95d7f079, 0x73a0ebc6, 0x73a0ebc6, 0x73a0ebc6, 0xeb99bf56, 0xeb99bf56, 0xeb99bf56, 0x4d266f7a, 0x206f7440, 0x206f7440, 0x4d266f7a, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x946b2f62, 0x30dad54, 0x946b2f62, 0x89f2e85, 0x1ed9d731, 0x1ed9d731, 0xf20ee132, 0xf20ee132, 0xf20ee132, 0x5c6afff7, 0x5c6afff7, 0x5c6afff7, 0x7f03ee41, 0x7f03ee41, 0x7f03ee41, 0x1ed9d731, 0x89f2e85, 0x89f2e85, 0x1ed9d731, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xd63f83a3, 0x3dc5a0b4, 0xd63f83a3, 0x9234791f, 0x5387d57f, 0x5387d57f, 0x4cb03e4e, 0x4cb03e4e, 0x4cb03e4e, 0x8ce95282, 0x8ce95282, 0x8ce95282, 0x6b37d014, 0x6b37d014, 0x6b37d014, 0x5387d57f, 0x9234791f, 0x9234791f, 0x5387d57f, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x89626ffa, 0xb4d6175c, 0x89626ffa, 0x330a2265, 0xf83ee7aa, 0xf83ee7aa, 0xbbfb89b5, 0xbbfb89b5, 0xbbfb89b5, 0x27825946, 0x27825946, 0x27825946, 0x1f31f2ee, 0x1f31f2ee, 0x1f31f2ee, 0xf83ee7aa, 0x330a2265, 0x330a2265, 0xf83ee7aa, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x3df87fc2, 0x8c55d02c, 0x3df87fc2, 0x2c8dca97, 0x724366e5, 0x724366e5, 0x3f06ba55, 0x3f06ba55, 0x3f06ba55, 0x783ff8af, 0x783ff8af, 0x783ff8af, 0x1511dfe5, 0x1511dfe5, 0x1511dfe5, 0x724366e5, 0x2c8dca97, 0x2c8dca97, 0x724366e5, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0xe39cde76, 0x443930df, 0xe39cde76, 0xc08634f, 0x5387d57f, 0x5387d57f, 0x44754e5f, 0x44754e5f, 0x44754e5f, 0x9abb0182, 0x9abb0182, 0x9abb0182, 0x938939c, 0x938939c, 0x938939c, 0x5387d57f, 0xc08634f, 0xc08634f, 0x5387d57f, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xa0b7c23d, 0x8cd3be29, 0xa0b7c23d, 0xd17dfcd1, 0xf83ee7aa, 0xf83ee7aa, 0x5feda75, 0x5feda75, 0x5feda75, 0x7724c945, 0x7724c945, 0x7724c945, 0x46b19883, 0x46b19883, 0x46b19883, 0xf83ee7aa, 0xd17dfcd1, 0xd17dfcd1, 0xf83ee7aa, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0xa994524d, 0xc1900d08, 0xa994524d, 0x5b46d93d, 0x724366e5, 0x724366e5, 0x6d0a4799, 0x6d0a4799, 0x6d0a4799, 0x349ab4c9, 0x349ab4c9, 0x349ab4c9, 0xfc2dda8b, 0xfc2dda8b, 0xfc2dda8b, 0x724366e5, 0x5b46d93d, 0x5b46d93d, 0x724366e5, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x41755bc6, 0xf207b232, 0x41755bc6, 0x4115e360, 0x1c955882, 0x1c955882, 0x428d20f6, 0x428d20f6, 0x428d20f6, 0x8d7a6d61, 0x8d7a6d61, 0x8d7a6d61, 0x73136174, 0x73136174, 0x73136174, 0x1c955882, 0x4115e360, 0x4115e360, 0x1c955882, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xe47ded44, 0x862f2131, 0xe47ded44, 0x206f7440, 0x4d266f7a, 0x4d266f7a, 0x95d7f079, 0x95d7f079, 0x95d7f079, 0x73a0ebc6, 0x73a0ebc6, 0x73a0ebc6, 0xeb99bf56, 0xeb99bf56, 0xeb99bf56, 0x4d266f7a, 0x206f7440, 0x206f7440, 0x4d266f7a, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x946b2f62, 0x30dad54, 0x946b2f62, 0x89f2e85, 0x1ed9d731, 0x1ed9d731, 0xf20ee132, 0xf20ee132, 0xf20ee132, 0x5c6afff7, 0x5c6afff7, 0x5c6afff7, 0x7f03ee41, 0x7f03ee41, 0x7f03ee41, 0x1ed9d731, 0x89f2e85, 0x89f2e85, 0x1ed9d731, }, 20 }, + { "gfxterm_piglatin", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x4878468, 0x58d7f660, 0x4878468, 0x549f20c6, 0x9813a416, 0x9813a416, 0x7c4d228e, 0x7c4d228e, 0x7c4d228e, 0xed96a4bd, 0xed96a4bd, 0xed96a4bd, 0x71e3517f, 0x71e3517f, 0x71e3517f, 0x9813a416, 0x549f20c6, 0x549f20c6, 0x9813a416, }, 20 }, + { "gfxterm_piglatin", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xc24f3617, 0xe92e5f60, 0xc24f3617, 0xf885e7ed, 0x5fcf013d, 0x5fcf013d, 0x9a58adbf, 0x9a58adbf, 0x9a58adbf, 0x4848b5c9, 0x4848b5c9, 0x4848b5c9, 0x57633434, 0x57633434, 0x57633434, 0x5fcf013d, 0xf885e7ed, 0xf885e7ed, 0x5fcf013d, }, 20 }, + { "gfxterm_piglatin", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xe0056f23, 0xe723a6de, 0xe0056f23, 0x8076cb49, 0xdd28f52b, 0xdd28f52b, 0x7cf3620d, 0x7cf3620d, 0x7cf3620d, 0x5dcf9be9, 0x5dcf9be9, 0x5dcf9be9, 0x47bef878, 0x47bef878, 0x47bef878, 0xdd28f52b, 0x8076cb49, 0x8076cb49, 0xdd28f52b, }, 20 }, + { "gfxterm_ch", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0x5ee30ef2, 0xcb34e9e1, 0x5ee30ef2, 0x1d15c3b5, 0x59c36f00, 0x59c36f00, 0x201d9661, 0x201d9661, 0x201d9661, 0x5e9dfb07, 0x5e9dfb07, 0x5e9dfb07, 0x9dbfc6ca, 0x9dbfc6ca, 0x9dbfc6ca, 0x59c36f00, 0x1d15c3b5, 0x1d15c3b5, 0x59c36f00, }, 20 }, + { "gfxterm_ch", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x8f30caea, 0xabe72645, 0x8f30caea, 0xa1354f95, 0xaa4593fe, 0xaa4593fe, 0xe17bf494, 0xe17bf494, 0xe17bf494, 0x478ef9f3, 0x478ef9f3, 0x478ef9f3, 0xc5291b98, 0xc5291b98, 0xc5291b98, 0xaa4593fe, 0xa1354f95, 0xa1354f95, 0xaa4593fe, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x3a734c3, 0x18bd52c, 0x3a734c3, 0x5eb05947, 0xc9cbf769, 0xc9cbf769, 0x128d62c1, 0x128d62c1, 0x128d62c1, 0xec55a30d, 0xec55a30d, 0xec55a30d, 0x4030c01, 0x4030c01, 0x4030c01, 0xc9cbf769, 0x5eb05947, 0x5eb05947, 0xc9cbf769, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0x34a86f24, 0xfae0384, 0x34a86f24, 0x64b0cb8a, 0x9813a416, 0x9813a416, 0x13b7fe00, 0x13b7fe00, 0x13b7fe00, 0x826c7833, 0x826c7833, 0x826c7833, 0x1e198df1, 0x1e198df1, 0x1e198df1, 0x9813a416, 0x64b0cb8a, 0x64b0cb8a, 0x9813a416, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x7cf1a92b, 0x413f2fa3, 0x7cf1a92b, 0x463b78d1, 0x5fcf013d, 0x5fcf013d, 0x4f98bcd5, 0x4f98bcd5, 0x4f98bcd5, 0x9d88a4a3, 0x9d88a4a3, 0x9d88a4a3, 0x82a3255e, 0x82a3255e, 0x82a3255e, 0x5fcf013d, 0x463b78d1, 0x463b78d1, 0x5fcf013d, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7d24f50c, 0x85834892, 0x7d24f50c, 0x1d575166, 0xdd28f52b, 0xdd28f52b, 0x167fd4de, 0x167fd4de, 0x167fd4de, 0x37432d3a, 0x37432d3a, 0x37432d3a, 0x2d324eab, 0x2d324eab, 0x2d324eab, 0xdd28f52b, 0x1d575166, 0x1d575166, 0xdd28f52b, }, 20 }, + { "gfxterm_ch", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x505523f2, 0x24d00e51, 0x505523f2, 0xae132e9f, 0x43d1f34, 0x43d1f34, 0xcaaadc5e, 0xcaaadc5e, 0xcaaadc5e, 0xb5a075f6, 0xb5a075f6, 0xb5a075f6, 0x5d804cdf, 0x5d804cdf, 0x5d804cdf, 0x43d1f34, 0xae132e9f, 0xae132e9f, 0x43d1f34, }, 20 }, + { "gfxterm_ch", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0x5ee30ef2, 0xcb34e9e1, 0x5ee30ef2, 0x1d15c3b5, 0x59c36f00, 0x59c36f00, 0x201d9661, 0x201d9661, 0x201d9661, 0x5e9dfb07, 0x5e9dfb07, 0x5e9dfb07, 0x9dbfc6ca, 0x9dbfc6ca, 0x9dbfc6ca, 0x59c36f00, 0x1d15c3b5, 0x1d15c3b5, 0x59c36f00, }, 20 }, + { "gfxterm_ch", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x8f30caea, 0xabe72645, 0x8f30caea, 0xa1354f95, 0xaa4593fe, 0xaa4593fe, 0xe17bf494, 0xe17bf494, 0xe17bf494, 0x478ef9f3, 0x478ef9f3, 0x478ef9f3, 0xc5291b98, 0xc5291b98, 0xc5291b98, 0xaa4593fe, 0xa1354f95, 0xa1354f95, 0xaa4593fe, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x3a734c3, 0x18bd52c, 0x3a734c3, 0x5eb05947, 0xc9cbf769, 0xc9cbf769, 0x128d62c1, 0x128d62c1, 0x128d62c1, 0xec55a30d, 0xec55a30d, 0xec55a30d, 0x4030c01, 0x4030c01, 0x4030c01, 0xc9cbf769, 0x5eb05947, 0x5eb05947, 0xc9cbf769, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xeba6cfbb, 0xcfb5c41c, 0xeba6cfbb, 0xafad3507, 0x5387d57f, 0x5387d57f, 0x71f3f018, 0x71f3f018, 0x71f3f018, 0xb1aa9cd4, 0xb1aa9cd4, 0xb1aa9cd4, 0x56741e42, 0x56741e42, 0x56741e42, 0x5387d57f, 0xafad3507, 0xafad3507, 0x5387d57f, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x9003ad29, 0xb92d2c38, 0x9003ad29, 0x2a6be0b6, 0xf83ee7aa, 0xf83ee7aa, 0x49d26800, 0x49d26800, 0x49d26800, 0xd5abb8f3, 0xd5abb8f3, 0xd5abb8f3, 0xed18135b, 0xed18135b, 0xed18135b, 0xf83ee7aa, 0x2a6be0b6, 0x2a6be0b6, 0xf83ee7aa, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x238c7b12, 0x2eefc892, 0x238c7b12, 0x32f9ce47, 0x724366e5, 0x724366e5, 0x3d1942f9, 0x3d1942f9, 0x3d1942f9, 0x7a200003, 0x7a200003, 0x7a200003, 0x170e2749, 0x170e2749, 0x170e2749, 0x724366e5, 0x32f9ce47, 0x32f9ce47, 0x724366e5, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x9e1c123, 0xa92b0ab6, 0x9e1c123, 0xe6757c1a, 0x5387d57f, 0x5387d57f, 0xa443a74a, 0xa443a74a, 0xa443a74a, 0x7a8de897, 0x7a8de897, 0x7a8de897, 0xe90e7a89, 0xe90e7a89, 0xe90e7a89, 0x5387d57f, 0xe6757c1a, 0xe6757c1a, 0x5387d57f, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xabb151dd, 0xfa21aa13, 0xabb151dd, 0xda7b6f31, 0xf83ee7aa, 0xf83ee7aa, 0x9d6ae4fd, 0x9d6ae4fd, 0x9d6ae4fd, 0xefb0f7cd, 0xefb0f7cd, 0xefb0f7cd, 0xde25a60b, 0xde25a60b, 0xde25a60b, 0xf83ee7aa, 0xda7b6f31, 0xda7b6f31, 0xf83ee7aa, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x6dd9406d, 0xde872977, 0x6dd9406d, 0x9f0bcb1d, 0x724366e5, 0x724366e5, 0x8b3051ad, 0x8b3051ad, 0x8b3051ad, 0xd2a0a2fd, 0xd2a0a2fd, 0xd2a0a2fd, 0x1a17ccbf, 0x1a17ccbf, 0x1a17ccbf, 0x724366e5, 0x9f0bcb1d, 0x9f0bcb1d, 0x724366e5, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x397d3da2, 0xeb896cf, 0x397d3da2, 0x391d8504, 0x1c955882, 0x1c955882, 0x16aa0778, 0x16aa0778, 0x16aa0778, 0xd95d4aef, 0xd95d4aef, 0xd95d4aef, 0x273446fa, 0x273446fa, 0x273446fa, 0x1c955882, 0x391d8504, 0x391d8504, 0x1c955882, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xb4b2e2fa, 0x74314de8, 0xb4b2e2fa, 0x70a07bfe, 0x4d266f7a, 0x4d266f7a, 0xe69c42f4, 0xe69c42f4, 0xe69c42f4, 0xeb594b, 0xeb594b, 0xeb594b, 0x98d20ddb, 0x98d20ddb, 0x98d20ddb, 0x4d266f7a, 0x70a07bfe, 0x70a07bfe, 0x4d266f7a, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xd2db665c, 0xcb12d20c, 0xd2db665c, 0x4e2f67bb, 0x1ed9d731, 0x1ed9d731, 0x1952ab15, 0x1952ab15, 0x1952ab15, 0xb736b5d0, 0xb736b5d0, 0xb736b5d0, 0x945fa466, 0x945fa466, 0x945fa466, 0x1ed9d731, 0x4e2f67bb, 0x4e2f67bb, 0x1ed9d731, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xeba6cfbb, 0xcfb5c41c, 0xeba6cfbb, 0xafad3507, 0x5387d57f, 0x5387d57f, 0x71f3f018, 0x71f3f018, 0x71f3f018, 0xb1aa9cd4, 0xb1aa9cd4, 0xb1aa9cd4, 0x56741e42, 0x56741e42, 0x56741e42, 0x5387d57f, 0xafad3507, 0xafad3507, 0x5387d57f, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x9003ad29, 0xb92d2c38, 0x9003ad29, 0x2a6be0b6, 0xf83ee7aa, 0xf83ee7aa, 0x49d26800, 0x49d26800, 0x49d26800, 0xd5abb8f3, 0xd5abb8f3, 0xd5abb8f3, 0xed18135b, 0xed18135b, 0xed18135b, 0xf83ee7aa, 0x2a6be0b6, 0x2a6be0b6, 0xf83ee7aa, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x238c7b12, 0x2eefc892, 0x238c7b12, 0x32f9ce47, 0x724366e5, 0x724366e5, 0x3d1942f9, 0x3d1942f9, 0x3d1942f9, 0x7a200003, 0x7a200003, 0x7a200003, 0x170e2749, 0x170e2749, 0x170e2749, 0x724366e5, 0x32f9ce47, 0x32f9ce47, 0x724366e5, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x9e1c123, 0xa92b0ab6, 0x9e1c123, 0xe6757c1a, 0x5387d57f, 0x5387d57f, 0xa443a74a, 0xa443a74a, 0xa443a74a, 0x7a8de897, 0x7a8de897, 0x7a8de897, 0xe90e7a89, 0xe90e7a89, 0xe90e7a89, 0x5387d57f, 0xe6757c1a, 0xe6757c1a, 0x5387d57f, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xabb151dd, 0xfa21aa13, 0xabb151dd, 0xda7b6f31, 0xf83ee7aa, 0xf83ee7aa, 0x9d6ae4fd, 0x9d6ae4fd, 0x9d6ae4fd, 0xefb0f7cd, 0xefb0f7cd, 0xefb0f7cd, 0xde25a60b, 0xde25a60b, 0xde25a60b, 0xf83ee7aa, 0xda7b6f31, 0xda7b6f31, 0xf83ee7aa, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x6dd9406d, 0xde872977, 0x6dd9406d, 0x9f0bcb1d, 0x724366e5, 0x724366e5, 0x8b3051ad, 0x8b3051ad, 0x8b3051ad, 0xd2a0a2fd, 0xd2a0a2fd, 0xd2a0a2fd, 0x1a17ccbf, 0x1a17ccbf, 0x1a17ccbf, 0x724366e5, 0x9f0bcb1d, 0x9f0bcb1d, 0x724366e5, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0x397d3da2, 0xeb896cf, 0x397d3da2, 0x391d8504, 0x1c955882, 0x1c955882, 0x16aa0778, 0x16aa0778, 0x16aa0778, 0xd95d4aef, 0xd95d4aef, 0xd95d4aef, 0x273446fa, 0x273446fa, 0x273446fa, 0x1c955882, 0x391d8504, 0x391d8504, 0x1c955882, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xb4b2e2fa, 0x74314de8, 0xb4b2e2fa, 0x70a07bfe, 0x4d266f7a, 0x4d266f7a, 0xe69c42f4, 0xe69c42f4, 0xe69c42f4, 0xeb594b, 0xeb594b, 0xeb594b, 0x98d20ddb, 0x98d20ddb, 0x98d20ddb, 0x4d266f7a, 0x70a07bfe, 0x70a07bfe, 0x4d266f7a, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xd2db665c, 0xcb12d20c, 0xd2db665c, 0x4e2f67bb, 0x1ed9d731, 0x1ed9d731, 0x1952ab15, 0x1952ab15, 0x1952ab15, 0xb736b5d0, 0xb736b5d0, 0xb736b5d0, 0x945fa466, 0x945fa466, 0x945fa466, 0x1ed9d731, 0x4e2f67bb, 0x4e2f67bb, 0x1ed9d731, }, 20 }, + { "gfxterm_ch", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0x34a86f24, 0xfae0384, 0x34a86f24, 0x64b0cb8a, 0x9813a416, 0x9813a416, 0x13b7fe00, 0x13b7fe00, 0x13b7fe00, 0x826c7833, 0x826c7833, 0x826c7833, 0x1e198df1, 0x1e198df1, 0x1e198df1, 0x9813a416, 0x64b0cb8a, 0x64b0cb8a, 0x9813a416, }, 20 }, + { "gfxterm_ch", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x7cf1a92b, 0x413f2fa3, 0x7cf1a92b, 0x463b78d1, 0x5fcf013d, 0x5fcf013d, 0x4f98bcd5, 0x4f98bcd5, 0x4f98bcd5, 0x9d88a4a3, 0x9d88a4a3, 0x9d88a4a3, 0x82a3255e, 0x82a3255e, 0x82a3255e, 0x5fcf013d, 0x463b78d1, 0x463b78d1, 0x5fcf013d, }, 20 }, + { "gfxterm_ch", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x7d24f50c, 0x85834892, 0x7d24f50c, 0x1d575166, 0xdd28f52b, 0xdd28f52b, 0x167fd4de, 0x167fd4de, 0x167fd4de, 0x37432d3a, 0x37432d3a, 0x37432d3a, 0x2d324eab, 0x2d324eab, 0x2d324eab, 0xdd28f52b, 0x1d575166, 0x1d575166, 0xdd28f52b, }, 20 }, + { "gfxterm_red", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xa64abc46, 0x75b6655, 0xa64abc46, 0x8ab5be58, 0x59c36f00, 0x59c36f00, 0xa119c4f4, 0xa119c4f4, 0xa119c4f4, 0xdf99a992, 0xdf99a992, 0xdf99a992, 0x1cbb945f, 0x1cbb945f, 0x1cbb945f, 0x59c36f00, 0x8ab5be58, 0x8ab5be58, 0x59c36f00, }, 20 }, + { "gfxterm_red", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x58be41e7, 0xae0d3f09, 0x58be41e7, 0xda7a6cbf, 0xaa4593fe, 0xaa4593fe, 0x794b67, 0x794b67, 0x794b67, 0xa68c4600, 0xa68c4600, 0xa68c4600, 0x242ba46b, 0x242ba46b, 0x242ba46b, 0xaa4593fe, 0xda7a6cbf, 0xda7a6cbf, 0xaa4593fe, }, 20 }, + { "gfxterm_red", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0xaaa4d3ad, 0xe61c6d02, 0xaaa4d3ad, 0xff557024, 0xc9cbf769, 0xc9cbf769, 0x780542e8, 0x780542e8, 0x780542e8, 0x86dd8324, 0x86dd8324, 0x86dd8324, 0x6e8b2c28, 0x6e8b2c28, 0x6e8b2c28, 0xc9cbf769, 0xff557024, 0xff557024, 0xc9cbf769, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xf168f0ba, 0x151608f2, 0xf168f0ba, 0x1f8e266b, 0x9813a416, 0x9813a416, 0x358d1fb0, 0x358d1fb0, 0x358d1fb0, 0xa4569983, 0xa4569983, 0xa4569983, 0x38236c41, 0x38236c41, 0x38236c41, 0x9813a416, 0x1f8e266b, 0x1f8e266b, 0x9813a416, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x927c4cf9, 0xdefa0b3b, 0x927c4cf9, 0x64636a93, 0x5fcf013d, 0x5fcf013d, 0xae2ee3eb, 0xae2ee3eb, 0xae2ee3eb, 0x7c3efb9d, 0x7c3efb9d, 0x7c3efb9d, 0x63157a60, 0x63157a60, 0x63157a60, 0x5fcf013d, 0x64636a93, 0x64636a93, 0x5fcf013d, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x2d254926, 0x796275ce, 0x2d254926, 0x17c0c9cb, 0xdd28f52b, 0xdd28f52b, 0x79439443, 0x79439443, 0x79439443, 0x587f6da7, 0x587f6da7, 0x587f6da7, 0x420e0e36, 0x420e0e36, 0x420e0e36, 0xdd28f52b, 0x17c0c9cb, 0x17c0c9cb, 0xdd28f52b, }, 20 }, + { "gfxterm_red", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0x755377f, 0x4e06e91f, 0x755377f, 0xe42f3a5, 0x43d1f34, 0x43d1f34, 0x3ac2d7b5, 0x3ac2d7b5, 0x3ac2d7b5, 0x45c87e1d, 0x45c87e1d, 0x45c87e1d, 0xade84734, 0xade84734, 0xade84734, 0x43d1f34, 0xe42f3a5, 0xe42f3a5, 0x43d1f34, }, 20 }, + { "gfxterm_red", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xa64abc46, 0x75b6655, 0xa64abc46, 0x8ab5be58, 0x59c36f00, 0x59c36f00, 0xa119c4f4, 0xa119c4f4, 0xa119c4f4, 0xdf99a992, 0xdf99a992, 0xdf99a992, 0x1cbb945f, 0x1cbb945f, 0x1cbb945f, 0x59c36f00, 0x8ab5be58, 0x8ab5be58, 0x59c36f00, }, 20 }, + { "gfxterm_red", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x58be41e7, 0xae0d3f09, 0x58be41e7, 0xda7a6cbf, 0xaa4593fe, 0xaa4593fe, 0x794b67, 0x794b67, 0x794b67, 0xa68c4600, 0xa68c4600, 0xa68c4600, 0x242ba46b, 0x242ba46b, 0x242ba46b, 0xaa4593fe, 0xda7a6cbf, 0xda7a6cbf, 0xaa4593fe, }, 20 }, + { "gfxterm_red", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0xaaa4d3ad, 0xe61c6d02, 0xaaa4d3ad, 0xff557024, 0xc9cbf769, 0xc9cbf769, 0x780542e8, 0x780542e8, 0x780542e8, 0x86dd8324, 0x86dd8324, 0x86dd8324, 0x6e8b2c28, 0x6e8b2c28, 0x6e8b2c28, 0xc9cbf769, 0xff557024, 0xff557024, 0xc9cbf769, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xcffd463e, 0x59775566, 0xcffd463e, 0xb4e87140, 0x5387d57f, 0x5387d57f, 0xc2a27e06, 0xc2a27e06, 0xc2a27e06, 0x2fb12ca, 0x2fb12ca, 0x2fb12ca, 0xe525905c, 0xe525905c, 0xe525905c, 0x5387d57f, 0xb4e87140, 0xb4e87140, 0x5387d57f, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x91d12daf, 0xdceabc0e, 0x91d12daf, 0xf372b81f, 0xf83ee7aa, 0xf83ee7aa, 0x85a69692, 0x85a69692, 0x85a69692, 0x19df4661, 0x19df4661, 0x19df4661, 0x216cedc9, 0x216cedc9, 0x216cedc9, 0xf83ee7aa, 0xf372b81f, 0xf372b81f, 0xf83ee7aa, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0x5f5953b3, 0x1f88963e, 0x5f5953b3, 0x6aeb9112, 0x724366e5, 0x724366e5, 0xc5da2432, 0xc5da2432, 0xc5da2432, 0x82e366c8, 0x82e366c8, 0x82e366c8, 0xefcd4182, 0xefcd4182, 0xefcd4182, 0x724366e5, 0x6aeb9112, 0x6aeb9112, 0x724366e5, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x1227533e, 0xee3616e0, 0x1227533e, 0xc32db32e, 0x5387d57f, 0x5387d57f, 0xa347c834, 0xa347c834, 0xa347c834, 0x7d8987e9, 0x7d8987e9, 0x7d8987e9, 0xee0a15f7, 0xee0a15f7, 0xee0a15f7, 0x5387d57f, 0xc32db32e, 0xc32db32e, 0x5387d57f, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0xc548a908, 0x2624be34, 0xc548a908, 0x1745599, 0xf83ee7aa, 0xf83ee7aa, 0xaaaf7e14, 0xaaaf7e14, 0xaaaf7e14, 0xd8756d24, 0xd8756d24, 0xd8756d24, 0xe9e03ce2, 0xe9e03ce2, 0xe9e03ce2, 0xf83ee7aa, 0x1745599, 0x1745599, 0xf83ee7aa, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x30506e44, 0x76cf9d03, 0x30506e44, 0x33485d71, 0x724366e5, 0x724366e5, 0xd12bc953, 0xd12bc953, 0xd12bc953, 0x88bb3a03, 0x88bb3a03, 0x88bb3a03, 0x400c5441, 0x400c5441, 0x400c5441, 0x724366e5, 0x33485d71, 0x33485d71, 0x724366e5, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0xa3238023, 0xa5b82f9e, 0xa3238023, 0x93f8a252, 0x1c955882, 0x1c955882, 0x205b041f, 0x205b041f, 0x205b041f, 0xefac4988, 0xefac4988, 0xefac4988, 0x11c5459d, 0x11c5459d, 0x11c5459d, 0x1c955882, 0x93f8a252, 0x93f8a252, 0x1c955882, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xf651c995, 0x7e1ae3d7, 0xf651c995, 0xdab860af, 0x4d266f7a, 0x4d266f7a, 0x6272be10, 0x6272be10, 0x6272be10, 0x8405a5af, 0x8405a5af, 0x8405a5af, 0x1c3cf13f, 0x1c3cf13f, 0x1c3cf13f, 0x4d266f7a, 0xdab860af, 0xdab860af, 0x4d266f7a, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x2fa6119, 0x30618885, 0x2fa6119, 0xbfbe1b6a, 0x1ed9d731, 0x1ed9d731, 0x11353cf5, 0x11353cf5, 0x11353cf5, 0xbf512230, 0xbf512230, 0xbf512230, 0x9c383386, 0x9c383386, 0x9c383386, 0x1ed9d731, 0xbfbe1b6a, 0xbfbe1b6a, 0x1ed9d731, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0x4caf1997, 0xda250acf, 0x4caf1997, 0x2183903f, 0x5387d57f, 0x5387d57f, 0x6be656ff, 0x6be656ff, 0x6be656ff, 0xabbf3a33, 0xabbf3a33, 0xabbf3a33, 0x4c61b8a5, 0x4c61b8a5, 0x4c61b8a5, 0x5387d57f, 0x2183903f, 0x2183903f, 0x5387d57f, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x7b29cc8e, 0x36125d2f, 0x7b29cc8e, 0x1277092, 0xf83ee7aa, 0xf83ee7aa, 0x4830d5b5, 0x4830d5b5, 0x4830d5b5, 0xd4490546, 0xd4490546, 0xd4490546, 0xecfaaeee, 0xecfaaeee, 0xecfaaeee, 0xf83ee7aa, 0x1277092, 0x1277092, 0xf83ee7aa, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0x2e644de2, 0x6eb5886f, 0x2e644de2, 0x3d66c6af, 0x724366e5, 0x724366e5, 0x5d800f18, 0x5d800f18, 0x5d800f18, 0x1ab94de2, 0x1ab94de2, 0x1ab94de2, 0x77976aa8, 0x77976aa8, 0x77976aa8, 0x724366e5, 0x3d66c6af, 0x3d66c6af, 0x724366e5, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x5f11f8eb, 0xa300bd35, 0x5f11f8eb, 0xe2cba3fa, 0x5387d57f, 0x5387d57f, 0xfa2cee75, 0xfa2cee75, 0xfa2cee75, 0x24e2a1a8, 0x24e2a1a8, 0x24e2a1a8, 0xb76133b6, 0xb76133b6, 0xb76133b6, 0x5387d57f, 0xe2cba3fa, 0xe2cba3fa, 0x5387d57f, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x179340b2, 0xf4ff578e, 0x179340b2, 0xe378eba9, 0xf83ee7aa, 0xf83ee7aa, 0xf787fcc2, 0xf787fcc2, 0xf787fcc2, 0x855deff2, 0x855deff2, 0x855deff2, 0xb4c8be34, 0xb4c8be34, 0xb4c8be34, 0xf83ee7aa, 0xe378eba9, 0xe378eba9, 0xf83ee7aa, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x5703fa5a, 0x119c091d, 0x5703fa5a, 0xa13f0d1a, 0x724366e5, 0x724366e5, 0xd989a04d, 0xd989a04d, 0xd989a04d, 0x8019531d, 0x8019531d, 0x8019531d, 0x48ae3d5f, 0x48ae3d5f, 0x48ae3d5f, 0x724366e5, 0xa13f0d1a, 0xa13f0d1a, 0x724366e5, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0xf38c2b36, 0xf517848b, 0xf38c2b36, 0xa2621779, 0x1c955882, 0x1c955882, 0x153777fa, 0x153777fa, 0x153777fa, 0xdac03a6d, 0xdac03a6d, 0xdac03a6d, 0x24a93678, 0x24a93678, 0x24a93678, 0x1c955882, 0xa2621779, 0xa2621779, 0x1c955882, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0xb8253868, 0x306e122a, 0xb8253868, 0x83b58e9b, 0x4d266f7a, 0x4d266f7a, 0x98183444, 0x98183444, 0x98183444, 0x7e6f2ffb, 0x7e6f2ffb, 0x7e6f2ffb, 0xe6567b6b, 0xe6567b6b, 0xe6567b6b, 0x4d266f7a, 0x83b58e9b, 0x83b58e9b, 0x4d266f7a, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x40c62f40, 0x725dc6dc, 0x40c62f40, 0x50dfba34, 0x1ed9d731, 0x1ed9d731, 0x32e89a68, 0x32e89a68, 0x32e89a68, 0x9c8c84ad, 0x9c8c84ad, 0x9c8c84ad, 0xbfe5951b, 0xbfe5951b, 0xbfe5951b, 0x1ed9d731, 0x50dfba34, 0x50dfba34, 0x1ed9d731, }, 20 }, + { "gfxterm_red", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0xfaeb56f1, 0x1e95aeb9, 0xfaeb56f1, 0xe4ddf18b, 0x9813a416, 0x9813a416, 0x5da5926f, 0x5da5926f, 0x5da5926f, 0xcc7e145c, 0xcc7e145c, 0xcc7e145c, 0x500be19e, 0x500be19e, 0x500be19e, 0x9813a416, 0xe4ddf18b, 0xe4ddf18b, 0x9813a416, }, 20 }, + { "gfxterm_red", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xa11f0307, 0xed9944c5, 0xa11f0307, 0x93a8828e, 0x5fcf013d, 0x5fcf013d, 0xeabf61dc, 0xeabf61dc, 0xeabf61dc, 0x38af79aa, 0x38af79aa, 0x38af79aa, 0x2784f857, 0x2784f857, 0x2784f857, 0x5fcf013d, 0x93a8828e, 0x93a8828e, 0x5fcf013d, }, 20 }, + { "gfxterm_red", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0xeedd0ec5, 0xba9a322d, 0xeedd0ec5, 0x32205338, 0xdd28f52b, 0xdd28f52b, 0x14854a2b, 0x14854a2b, 0x14854a2b, 0x35b9b3cf, 0x35b9b3cf, 0x35b9b3cf, 0x2fc8d05e, 0x2fc8d05e, 0x2fc8d05e, 0xdd28f52b, 0x32205338, 0x32205338, 0xdd28f52b, }, 20 }, + { "gfxterm_high", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x59c36f00, 0xe7baf88f, 0x46ab229c, 0xe7baf88f, 0x2422eb85, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x2422eb85, 0x2422eb85, 0x59c36f00, }, 20 }, + { "gfxterm_high", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xaa4593fe, 0x86184b5, 0xfed2fa5b, 0x86184b5, 0xf984bb34, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0xf984bb34, 0xf984bb34, 0xaa4593fe, }, 20 }, + { "gfxterm_high", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xc9cbf769, 0x2dda8793, 0x6162393c, 0x2dda8793, 0x2a6bc689, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0x2a6bc689, 0x2a6bc689, 0xc9cbf769, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x9813a416, 0xf2b1715, 0xeb55ef5d, 0xf2b1715, 0x61e172d4, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0x61e172d4, 0x61e172d4, 0x9813a416, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x5fcf013d, 0x2a517b4, 0x4e235076, 0x2a517b4, 0x85b73555, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0x85b73555, 0x85b73555, 0x5fcf013d, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x53e34b0f, 0x7a477e7, 0x53e34b0f, 0x7b92ba0b, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0x7b92ba0b, 0x7b92ba0b, 0xdd28f52b, }, 20 }, + { "gfxterm_high", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x43d1f34, 0xcccbb8c0, 0x859866a0, 0xcccbb8c0, 0x2bf5b2f8, 0x43d1f34, 0x43d1f34, 0xd204ac75, 0xd204ac75, 0xd204ac75, 0xad0e05dd, 0xad0e05dd, 0xad0e05dd, 0x452e3cf4, 0x452e3cf4, 0x452e3cf4, 0x43d1f34, 0x2bf5b2f8, 0x2bf5b2f8, 0x43d1f34, }, 20 }, + { "gfxterm_high", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x59c36f00, 0xe7baf88f, 0x46ab229c, 0xe7baf88f, 0x2422eb85, 0x59c36f00, 0x59c36f00, 0xc8b88a82, 0xc8b88a82, 0xc8b88a82, 0xb638e7e4, 0xb638e7e4, 0xb638e7e4, 0x751ada29, 0x751ada29, 0x751ada29, 0x59c36f00, 0x2422eb85, 0x2422eb85, 0x59c36f00, }, 20 }, + { "gfxterm_high", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0xaa4593fe, 0x86184b5, 0xfed2fa5b, 0x86184b5, 0xf984bb34, 0xaa4593fe, 0xaa4593fe, 0x8b63f19d, 0x8b63f19d, 0x8b63f19d, 0x2d96fcfa, 0x2d96fcfa, 0x2d96fcfa, 0xaf311e91, 0xaf311e91, 0xaf311e91, 0xaa4593fe, 0xf984bb34, 0xf984bb34, 0xaa4593fe, }, 20 }, + { "gfxterm_high", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xc9cbf769, 0x2dda8793, 0x6162393c, 0x2dda8793, 0x2a6bc689, 0xc9cbf769, 0xc9cbf769, 0xec23555f, 0xec23555f, 0xec23555f, 0x12fb9493, 0x12fb9493, 0x12fb9493, 0xfaad3b9f, 0xfaad3b9f, 0xfaad3b9f, 0xc9cbf769, 0x2a6bc689, 0x2a6bc689, 0xc9cbf769, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x5387d57f, 0xc2dae336, 0x5450f06e, 0xc2dae336, 0x2fd25c3, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0x2fd25c3, 0x2fd25c3, 0x5387d57f, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0xf910eb1d, 0xb42b7abc, 0xf910eb1d, 0x6d5e8f22, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0x6d5e8f22, 0x6d5e8f22, 0xf83ee7aa, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0x724366e5, 0xa038bbb4, 0xe0e97e39, 0xa038bbb4, 0x4211aeac, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x4211aeac, 0x4211aeac, 0x724366e5, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x5387d57f, 0x4a2dd1b7, 0xb63c9469, 0x4a2dd1b7, 0xe8aea440, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0xe8aea440, 0xe8aea440, 0x5387d57f, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x8597e648, 0x66fbf174, 0x8597e648, 0xa99c8f36, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0xa99c8f36, 0xa99c8f36, 0xf83ee7aa, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x724366e5, 0x7c1b6088, 0x3a8493cf, 0x7c1b6088, 0xd5d88a3e, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0xd5d88a3e, 0xd5d88a3e, 0x724366e5, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x1c955882, 0x9f45f149, 0x99de5ef4, 0x9f45f149, 0x84437bc3, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0x84437bc3, 0x84437bc3, 0x1c955882, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x60f3276d, 0xe8b80d2f, 0x60f3276d, 0x1d7bae65, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0x1d7bae65, 0x1d7bae65, 0x4d266f7a, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0x1ed9d731, 0x66a98ee6, 0x5432677a, 0x66a98ee6, 0x691b88fb, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0x691b88fb, 0x691b88fb, 0x1ed9d731, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x5387d57f, 0xc26d8183, 0x54e792db, 0xc26d8183, 0x1473f9a0, 0x5387d57f, 0x5387d57f, 0x71381c6, 0x71381c6, 0x71381c6, 0xc74aed0a, 0xc74aed0a, 0xc74aed0a, 0x20946f9c, 0x20946f9c, 0x20946f9c, 0x5387d57f, 0x1473f9a0, 0x1473f9a0, 0x5387d57f, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0xf83ee7aa, 0x3ed65cd5, 0x73edcd74, 0x3ed65cd5, 0xb2351146, 0xf83ee7aa, 0xf83ee7aa, 0x610deea9, 0x610deea9, 0x610deea9, 0xfd743e5a, 0xfd743e5a, 0xfd743e5a, 0xc5c795f2, 0xc5c795f2, 0xc5c795f2, 0xf83ee7aa, 0xb2351146, 0xb2351146, 0xf83ee7aa, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0x724366e5, 0xc576da57, 0x85a71fda, 0xc576da57, 0x1ef86a3, 0x724366e5, 0x724366e5, 0xdbb2f05a, 0xdbb2f05a, 0xdbb2f05a, 0x9c8bb2a0, 0x9c8bb2a0, 0x9c8bb2a0, 0xf1a595ea, 0xf1a595ea, 0xf1a595ea, 0x724366e5, 0x1ef86a3, 0x1ef86a3, 0x724366e5, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0x5387d57f, 0x4778be32, 0xbb69fbec, 0x4778be32, 0x892b70c4, 0x5387d57f, 0x5387d57f, 0x23c74007, 0x23c74007, 0x23c74007, 0xfd090fda, 0xfd090fda, 0xfd090fda, 0x6e8a9dc4, 0x6e8a9dc4, 0x6e8a9dc4, 0x5387d57f, 0x892b70c4, 0x892b70c4, 0x5387d57f, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0xf83ee7aa, 0x9c6c6004, 0x7f007738, 0x9c6c6004, 0x80b05ef0, 0xf83ee7aa, 0xf83ee7aa, 0xa5fd8afa, 0xa5fd8afa, 0xa5fd8afa, 0xd72799ca, 0xd72799ca, 0xd72799ca, 0xe6b2c80c, 0xe6b2c80c, 0xe6b2c80c, 0xf83ee7aa, 0x80b05ef0, 0x80b05ef0, 0xf83ee7aa, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x724366e5, 0x84caa3c1, 0xc2555086, 0x84caa3c1, 0xd82d8d02, 0x724366e5, 0x724366e5, 0xd0002838, 0xd0002838, 0xd0002838, 0x8990db68, 0x8990db68, 0x8990db68, 0x4127b52a, 0x4127b52a, 0x4127b52a, 0x724366e5, 0xd82d8d02, 0xd82d8d02, 0x724366e5, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x1c955882, 0xe4dec6e6, 0xe245695b, 0xe4dec6e6, 0x9eed5252, 0x1c955882, 0x1c955882, 0x727420bf, 0x727420bf, 0x727420bf, 0xbd836d28, 0xbd836d28, 0xbd836d28, 0x43ea613d, 0x43ea613d, 0x43ea613d, 0x1c955882, 0x9eed5252, 0x9eed5252, 0x1c955882, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x4d266f7a, 0x19a935eb, 0x91e21fa9, 0x19a935eb, 0x7358a32a, 0x4d266f7a, 0x4d266f7a, 0xc23ec599, 0xc23ec599, 0xc23ec599, 0x2449de26, 0x2449de26, 0x2449de26, 0xbc708ab6, 0xbc708ab6, 0xbc708ab6, 0x4d266f7a, 0x7358a32a, 0x7358a32a, 0x4d266f7a, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0x1ed9d731, 0xb2b10aa1, 0x802ae33d, 0xb2b10aa1, 0x105ee3bb, 0x1ed9d731, 0x1ed9d731, 0x6ea8026e, 0x6ea8026e, 0x6ea8026e, 0xc0cc1cab, 0xc0cc1cab, 0xc0cc1cab, 0xe3a50d1d, 0xe3a50d1d, 0xe3a50d1d, 0x1ed9d731, 0x105ee3bb, 0x105ee3bb, 0x1ed9d731, }, 20 }, + { "gfxterm_high", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x9813a416, 0xeedf19a8, 0xaa1e1e0, 0xeedf19a8, 0x70c50dc2, 0x9813a416, 0x9813a416, 0xc10419e0, 0xc10419e0, 0xc10419e0, 0x50df9fd3, 0x50df9fd3, 0x50df9fd3, 0xccaa6a11, 0xccaa6a11, 0xccaa6a11, 0x9813a416, 0x70c50dc2, 0x70c50dc2, 0x9813a416, }, 20 }, + { "gfxterm_high", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x5fcf013d, 0xa474246a, 0xe8f263a8, 0xa474246a, 0xe7cea168, 0x5fcf013d, 0x5fcf013d, 0x77ba65ab, 0x77ba65ab, 0x77ba65ab, 0xa5aa7ddd, 0xa5aa7ddd, 0xa5aa7ddd, 0xba81fc20, 0xba81fc20, 0xba81fc20, 0x5fcf013d, 0xe7cea168, 0xe7cea168, 0x5fcf013d, }, 20 }, + { "gfxterm_high", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xdd28f52b, 0x653aabb4, 0x317d975c, 0x653aabb4, 0xab5387a0, 0xdd28f52b, 0xdd28f52b, 0xbc36f156, 0xbc36f156, 0xbc36f156, 0x9d0a08b2, 0x9d0a08b2, 0x9d0a08b2, 0x877b6b23, 0x877b6b23, 0x877b6b23, 0xdd28f52b, 0xab5387a0, 0xab5387a0, 0xdd28f52b, }, 20 }, + { "videotest", 640, 480, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi16 */, (grub_uint32_t []) { 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, 0x7f1853ba, }, 5 }, + { "videotest", 800, 600, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi16 */, (grub_uint32_t []) { 0xff1957f0, 0xff1957f0, 0xff1957f0, 0xff1957f0, 0xff1957f0, }, 5 }, + { "videotest", 1024, 768, 0x2, 16, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi16 */, (grub_uint32_t []) { 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, 0xcb45d8c5, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 640x480xrgba8888 */, (grub_uint32_t []) { 0x2b154617, 0x692e98df, 0xaf62fb87, 0xed59254f, 0x26164bc6, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 800x600xrgba8888 */, (grub_uint32_t []) { 0x3b0fbc56, 0xd9d57c0e, 0xfb564a17, 0x198c8a4f, 0xbe502625, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 1024x768xrgba8888 */, (grub_uint32_t []) { 0x6e6c9b36, 0x4ae9f137, 0x27664f34, 0x3e32535, 0xfc793332, }, 5 }, + { "videotest", 2560, 1440, 0x1, 256, 32, 4, 16, 8, 8, 8, 0, 8, 24, 8 /* 2560x1440xrgba8888 */, (grub_uint32_t []) { 0x91692eef, 0x89773091, 0xa1551213, 0xb94b0c6d, 0xf1115717, }, 5 }, + { "videotest", 640, 480, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 640x480xi256 */, (grub_uint32_t []) { 0x2d1b122b, 0x2d1b122b, 0x2d1b122b, 0x2d1b122b, 0x2d1b122b, }, 5 }, + { "videotest", 800, 600, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 800x600xi256 */, (grub_uint32_t []) { 0x327d1082, 0x327d1082, 0x327d1082, 0x327d1082, 0x327d1082, }, 5 }, + { "videotest", 1024, 768, 0x2, 256, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0 /* 1024x768xi256 */, (grub_uint32_t []) { 0xadd0f186, 0xadd0f186, 0xadd0f186, 0xadd0f186, 0xadd0f186, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 640x480xrgba5550 */, (grub_uint32_t []) { 0x2c97569c, 0x2c97569c, 0x2c97569c, 0x2c97569c, 0x2c97569c, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 800x600xrgba5550 */, (grub_uint32_t []) { 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, 0x9bd7a3ac, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 15, 2, 10, 5, 5, 5, 0, 5, 0, 0 /* 1024x768xrgba5550 */, (grub_uint32_t []) { 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, 0xedbceb9c, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 640x480xrgba5650 */, (grub_uint32_t []) { 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, 0x3c2a42f1, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 800x600xrgba5650 */, (grub_uint32_t []) { 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, 0xb25ce62a, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 16, 2, 11, 5, 5, 6, 0, 5, 0, 0 /* 1024x768xrgba5650 */, (grub_uint32_t []) { 0x66cee14c, 0x66cee14c, 0x66cee14c, 0x66cee14c, 0x66cee14c, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 640x480xrgba8880 */, (grub_uint32_t []) { 0x61db45b7, 0x1d867efe, 0x99613325, 0xe53c086c, 0x9543de62, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 800x600xrgba8880 */, (grub_uint32_t []) { 0xa46eb37f, 0xd2a59656, 0x49f8f92d, 0x3f33dc04, 0x7aae512a, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 24, 3, 16, 8, 8, 8, 0, 8, 0, 0 /* 1024x768xrgba8880 */, (grub_uint32_t []) { 0xb864a496, 0x6c22313b, 0x1505f93d, 0xc1436c90, 0xe74a6931, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 640x480xbgra5550 */, (grub_uint32_t []) { 0x9056f776, 0x9056f776, 0x9056f776, 0x9056f776, 0x9056f776, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 800x600xbgra5550 */, (grub_uint32_t []) { 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, 0x2bde3c67, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 15, 2, 0, 5, 5, 5, 10, 5, 0, 0 /* 1024x768xbgra5550 */, (grub_uint32_t []) { 0xb04615f3, 0xb04615f3, 0xb04615f3, 0xb04615f3, 0xb04615f3, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 640x480xbgra5650 */, (grub_uint32_t []) { 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, 0xba8df8dd, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 800x600xbgra5650 */, (grub_uint32_t []) { 0x84ac1329, 0x84ac1329, 0x84ac1329, 0x84ac1329, 0x84ac1329, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 16, 2, 0, 5, 5, 6, 11, 5, 0, 0 /* 1024x768xbgra5650 */, (grub_uint32_t []) { 0x145ad698, 0x145ad698, 0x145ad698, 0x145ad698, 0x145ad698, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 640x480xbgra8880 */, (grub_uint32_t []) { 0x4af6b480, 0x923db79c, 0xfe8cc449, 0x2647c755, 0x27ee23e3, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 800x600xbgra8880 */, (grub_uint32_t []) { 0x121d5e29, 0xf66c0aed, 0xdf138150, 0x3b62d594, 0x8dec962a, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 24, 3, 0, 8, 8, 8, 16, 8, 0, 0 /* 1024x768xbgra8880 */, (grub_uint32_t []) { 0xae86a12c, 0x4dabbe89, 0x6d30e897, 0x8e1df732, 0x2c0644ab, }, 5 }, + { "videotest", 640, 480, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 640x480xbgra8888 */, (grub_uint32_t []) { 0x2605d280, 0xc06e3172, 0xef3e6395, 0x9558067, 0xb19ec65b, }, 5 }, + { "videotest", 800, 600, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 800x600xbgra8888 */, (grub_uint32_t []) { 0x9404ef3b, 0xa4fdf18, 0xad7ef98c, 0x3335c9af, 0xe6f0c255, }, 5 }, + { "videotest", 1024, 768, 0x1, 256, 32, 4, 0, 8, 8, 8, 16, 8, 24, 8 /* 1024x768xbgra8888 */, (grub_uint32_t []) { 0xa008b770, 0xb98eb0d8, 0x9304b820, 0x8a82bf88, 0xc610a9d0, }, 5 }, diff --git a/grub-core/tests/cmdline_cat_test.c b/grub-core/tests/cmdline_cat_test.c index baea7688a..f1e21439e 100644 --- a/grub-core/tests/cmdline_cat_test.c +++ b/grub-core/tests/cmdline_cat_test.c @@ -103,7 +103,7 @@ cmdline_cat_test (void) '/', 't', 'e', 's', 't', '.', 't', 'x', 't', '\n', GRUB_TERM_NO_KEY, - GRUB_TERM_NO_KEY, GRUB_TERM_ESC}, + GRUB_TERM_NO_KEY, '\e'}, 23); grub_video_checksum ("cmdline_cat"); diff --git a/grub-core/tests/cmp_test.c b/grub-core/tests/cmp_test.c deleted file mode 100644 index af5b39576..000000000 --- a/grub-core/tests/cmp_test.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_uint64_t vectors[][2] = { - { 0xffffffffffffffffULL, 1}, - { 1, 0xffffffffffffffffULL}, - { 0xffffffffffffffffULL, 0xffffffffffffffffULL}, - { 1, 1 }, - { 2, 1 } -}; - -/* Don't change those to use shift as shift may call to compile rt - functions and we're not testing them now. - */ -static int -leading_bit64 (grub_uint64_t a) -{ - return !!(a & 0x8000000000000000LL); -} - -static int -leading_bit32 (grub_uint32_t a) -{ - return !!(a & 0x80000000); -} - -/* Computes (a < b) without involving comparison operator. */ -static int -is_less32 (grub_uint32_t a, grub_uint32_t b) -{ - if (leading_bit32(a) && !leading_bit32(b)) - return 0; - if (!leading_bit32(a) && leading_bit32(b)) - return 1; - return leading_bit32(a - b); -} - -static void -test32 (grub_uint32_t a, grub_uint32_t b) -{ - grub_test_assert ((a < b) == is_less32(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((a > b) == is_less32(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b < a) == is_less32(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b > a) == is_less32(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert (!(is_less32(a, b) && is_less32(b, a)), "comparison inconsistent: %lld, %lld", - (long long) a, (long long) b); -} - -/* Computes (a > b) without involving comparison operator. */ -static int -is_less32s (grub_int32_t a, grub_int32_t b) -{ - if (leading_bit32(a) && !leading_bit32(b)) - return 1; /* a < 0 && b >= 0. */ - if (!leading_bit32(a) && leading_bit32(b)) - return 0; /* b < 0 && a >= 0. */ - return leading_bit32(a - b); -} - -static void -test32s (grub_int32_t a, grub_int32_t b) -{ - grub_test_assert ((a < b) == is_less32s(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((a > b) == is_less32s(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b < a) == is_less32s(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b > a) == is_less32s(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert (!(is_less32s(a, b) && is_less32s(b, a)), "comparison inconsistent: %lld, %lld", - (long long) a, (long long) b); -} - -/* Computes (a > b) without involving comparison operator. */ -static int -is_less64 (grub_uint64_t a, grub_uint64_t b) -{ - if (leading_bit64(a) && !leading_bit64(b)) - return 0; - if (!leading_bit64(a) && leading_bit64(b)) - return 1; - return leading_bit64(a - b); -} - -static void -test64 (grub_uint64_t a, grub_uint64_t b) -{ - grub_test_assert ((a < b) == is_less64(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((a > b) == is_less64(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b < a) == is_less64(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b > a) == is_less64(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert (!(is_less64(a, b) && is_less64(b, a)), "comparison inconsistent: %lld, %lld", - (long long) a, (long long) b); -} - -/* Computes (a > b) without involving comparison operator. */ -static int -is_less64s (grub_int64_t a, grub_int64_t b) -{ - if (leading_bit64(a) && !leading_bit64(b)) - return 1; /* a < 0 && b >= 0. */ - if (!leading_bit64(a) && leading_bit64(b)) - return 0; /* b < 0 && a >= 0. */ - return leading_bit64(a - b); -} - -static void -test64s (grub_int64_t a, grub_int64_t b) -{ - grub_test_assert ((a < b) == is_less64s(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((a > b) == is_less64s(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b < a) == is_less64s(b, a), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert ((b > a) == is_less64s(a, b), "comparison result mismatch: %lld, %lld", - (long long) a, (long long) b); - grub_test_assert (!(is_less64s(a, b) && is_less64s(b, a)), "comparison inconsistent: %lld, %lld", - (long long) a, (long long) b); -} - -static void -test_all(grub_uint64_t a, grub_uint64_t b) -{ - test64 (a, b); - test32 (a, b); - test64s (a, b); - test32s (a, b); - test64s (a, -b); - test32s (a, -b); - test64s (-a, b); - test32s (-a, b); - test64s (-a, -b); - test32s (-a, -b); -} - -static void -cmp_test (void) -{ - grub_uint64_t a = 404, b = 7; - grub_size_t i; - - for (i = 0; i < ARRAY_SIZE (vectors); i++) - { - test_all (vectors[i][0], vectors[i][1]); - } - for (i = 0; i < 40000; i++) - { - a = 17 * a + 13 * b; - b = 23 * a + 29 * b; - if (b == 0) - b = 1; - if (a == 0) - a = 1; - test_all (a, b); - } -} - -/* Register example_test method as a functional test. */ -GRUB_FUNCTIONAL_TEST (cmp_test, cmp_test); diff --git a/grub-core/tests/ctz_test.c b/grub-core/tests/ctz_test.c deleted file mode 100644 index eb7a1df38..000000000 --- a/grub-core/tests/ctz_test.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -/* ull version is not used on i386 other than in this test. - Avoid requiring extra function. - */ -#if defined (__i386__) -#define SKIP_ULL 1 -#endif - -static grub_uint64_t vectors[] = { - 0xffffffffffffffffULL, 1, 2, 0, 0x0102030405060708ULL -}; - -static void -test_ui (unsigned int a) -{ - int i; - a |= 1; - for (i = 0; i < (int) (8 * sizeof (a)); i++) - { - grub_test_assert (__builtin_ctz(a << i) == i, - "ctz mismatch: ctz(0x%llx) != 0x%x", - (long long) (a << i), __builtin_ctz(a << i)); - } -} - -static void -test_ul (unsigned long a) -{ - int i; - a |= 1; - for (i = 0; i < (int) (8 * sizeof (a)); i++) - { - grub_test_assert (__builtin_ctzl(a << i) == i, - "ctzl mismatch: ctzl(0x%llx) != 0x%x", - (long long) (a << i), __builtin_ctz(a << i)); - } -} - -#ifndef SKIP_ULL -static void -test_ull (unsigned long long a) -{ - int i; - a |= 1; - for (i = 0; i < (int) (8 * sizeof (a)); i++) - { - grub_test_assert (__builtin_ctzll(a << i) == i, - "ctzll mismatch: ctzll(0x%llx) != 0x%x", - (long long) (a << i), __builtin_ctz(a << i)); - } -} -#endif - -static void -test_all(grub_uint64_t a) -{ - test_ui (a); - test_ul (a); -#ifndef SKIP_ULL - test_ull (a); -#endif -} - -static void -ctz_test (void) -{ - grub_uint64_t a = 404, b = 7; - grub_size_t i; - - for (i = 0; i < ARRAY_SIZE (vectors); i++) - { - test_all (vectors[i]); - } - for (i = 0; i < 40000; i++) - { - a = 17 * a + 13 * b; - b = 23 * a + 29 * b; - if (b == 0) - b = 1; - if (a == 0) - a = 1; - test_all (a); - test_all (b); - } -} - -/* Register example_test method as a functional test. */ -GRUB_FUNCTIONAL_TEST (ctz_test, ctz_test); diff --git a/grub-core/tests/div_test.c b/grub-core/tests/div_test.c index 9abc6d5c4..1928f8507 100644 --- a/grub-core/tests/div_test.c +++ b/grub-core/tests/div_test.c @@ -34,8 +34,6 @@ static void test32 (grub_uint32_t a, grub_uint32_t b) { grub_uint64_t q, r; - if (b == 0) - return; q = grub_divmod64 (a, b, &r); grub_test_assert (r < b, "remainder is larger than dividend: 0x%llx %% 0x%llx = 0x%llx", (long long) a, (long long) b, (long long) r); @@ -97,72 +95,6 @@ test64 (grub_uint64_t a, grub_uint64_t b) #endif } -static grub_int64_t -abs64(grub_int64_t a) -{ - return a > 0 ? a : -a; -} - -static void -test32s (grub_int32_t a, grub_int32_t b) -{ - grub_int64_t q, r; - if (b == 0) - return; - - q = grub_divmod64s (a, b, &r); - grub_test_assert (a > 0 ? r >= 0 : r <= 0, "remainder sign mismatch: %lld %% %lld = %lld", - (long long) a, (long long) b, (long long) r); - grub_test_assert (((a > 0) == (b > 0)) ? q >= 0 : q <= 0, "quotient sign mismatch: %lld / %lld = %lld", - (long long) a, (long long) b, (long long) q); - grub_test_assert (abs64(r) < abs64(b), "remainder is larger than dividend: %lld %% %lld = %lld", - (long long) a, (long long) b, (long long) r); - grub_test_assert (q * b + r == a, "division doesn't satisfy base property: %lld * %lld + %lld != %lld", (long long) q, (long long) b, (long long) r, - (long long) a); - if (0) { grub_test_assert (q == (a / b), - "C compiler division failure in 0x%llx, 0x%llx", (long long) a, (long long) b); - grub_test_assert (r == (a % b), - "C compiler modulo failure in 0x%llx, 0x%llx", (long long) a, (long long) b); - } -} - -static void -test64s (grub_int64_t a, grub_int64_t b) -{ - grub_int64_t q, r; - q = grub_divmod64s (a, b, &r); - - grub_test_assert (a > 0 ? r >= 0 : r <= 0, "remainder sign mismatch: %lld %% %lld = %lld", - (long long) a, (long long) b, (long long) r); - grub_test_assert (((a > 0) == (b > 0)) ? q >= 0 : q <= 0, "quotient sign mismatch: %lld / %lld = %lld", - (long long) a, (long long) b, (long long) q); - grub_test_assert (abs64(r) < abs64(b), "remainder is larger than dividend: %lld %% %lld = %lld", - (long long) a, (long long) b, (long long) r); - grub_test_assert (q * b + r == a, "division doesn't satisfy base property: 0x%llx * 0x%llx + 0x%llx != 0x%llx", (long long) q, (long long) b, (long long) r, - (long long) a); -#if GRUB_TARGET_SIZEOF_VOID_P == 8 - grub_test_assert (q == (a / b), - "C compiler division failure in 0x%llx, 0x%llx", (long long) a, (long long) b); - grub_test_assert (r == (a % b), - "C compiler modulo failure in 0x%llx, 0x%llx", (long long) a, (long long) b); -#endif -} - -static void -test_all(grub_uint64_t a, grub_uint64_t b) -{ - test64 (a, b); - test32 (a, b); - test64s (a, b); - test32s (a, b); - test64s (a, -b); - test32s (a, -b); - test64s (-a, b); - test32s (-a, b); - test64s (-a, -b); - test32s (-a, -b); -} - static void div_test (void) { @@ -171,7 +103,8 @@ div_test (void) for (i = 0; i < ARRAY_SIZE (vectors); i++) { - test_all (vectors[i][0], vectors[i][1]); + test64 (vectors[i][0], vectors[i][1]); + test32 (vectors[i][0], vectors[i][1]); } for (i = 0; i < 40000; i++) { @@ -181,7 +114,9 @@ div_test (void) b = 1; if (a == 0) a = 1; - test_all (a, b); + test64 (a, b); + test32 (a, b); + } } diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c index b5eb516be..2d6085298 100644 --- a/grub-core/tests/fake_input.c +++ b/grub-core/tests/fake_input.c @@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) saved = grub_term_inputs; if (seq) grub_free (seq); - seq = grub_calloc (nseq_in, sizeof (seq[0])); + seq = grub_malloc (nseq_in * sizeof (seq[0])); if (!seq) return; diff --git a/grub-core/tests/gfxterm_menu.c b/grub-core/tests/gfxterm_menu.c index 12836fb96..8f63dc27a 100644 --- a/grub-core/tests/gfxterm_menu.c +++ b/grub-core/tests/gfxterm_menu.c @@ -146,7 +146,7 @@ gfxterm_menu (void) return; } grub_terminal_input_fake_sequence ((int []) { -1, -1, -1, GRUB_TERM_KEY_DOWN, -1, 'e', - -1, GRUB_TERM_KEY_RIGHT, -1, 'x', -1, GRUB_TERM_ESC, -1, GRUB_TERM_ESC }, 14); + -1, GRUB_TERM_KEY_RIGHT, -1, 'x', -1, '\e', -1, '\e' }, 14); grub_video_checksum (tests[j].name); diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c index 96781fb39..5be7a58e5 100644 --- a/grub-core/tests/lib/functional_test.c +++ b/grub-core/tests/lib/functional_test.c @@ -26,23 +26,14 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_err_t grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)), - int argc, - char **args) + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) { grub_test_t test; int ok = 1; - int i; FOR_LIST_ELEMENTS (test, grub_test_list) { - if (argc != 0) - { - for (i = 0; i < argc; i++) - if (grub_strcmp(args[i], test->name) == 0) - break; - if (i == argc) - continue; - } grub_errno = 0; ok = ok && !grub_test_run (test); grub_errno = 0; @@ -74,11 +65,6 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)), grub_dl_load ("pbkdf2_test"); grub_dl_load ("signature_test"); grub_dl_load ("sleep_test"); - grub_dl_load ("bswap_test"); - grub_dl_load ("ctz_test"); - grub_dl_load ("cmp_test"); - grub_dl_load ("mul_test"); - grub_dl_load ("shift_test"); FOR_LIST_ELEMENTS (test, grub_test_list) ok = !grub_test_run (test) && ok; diff --git a/grub-core/tests/mul_test.c b/grub-core/tests/mul_test.c deleted file mode 100644 index cd6423192..000000000 --- a/grub-core/tests/mul_test.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_uint64_t vectors[][2] = { - { 0xffffffffffffffffULL, 1}, - { 1, 0xffffffffffffffffULL}, - { 0xffffffffffffffffULL, 0xffffffffffffffffULL}, - { 1, 1 }, - { 2, 1 } -}; - -static void -test64(grub_uint64_t a, grub_uint64_t b) -{ - grub_uint64_t r1 = a * b, r2 = 0, r3; - int i; - for (i = 0; i < 64; i++) - if ((a & (1LL << i))) - r2 += b << i; - r3 = ((grub_int64_t) a) * ((grub_int64_t) b); - grub_test_assert (r1 == r2, - "multiplication mismatch (u): 0x%llx x 0x%llx = 0x%llx != 0x%llx", - (long long) a, (long long) b, (long long) r2, (long long) r1); - grub_test_assert (r3 == r2, - "multiplication mismatch (s): 0x%llx x 0x%llx = 0x%llx != 0x%llx", - (long long) a, (long long) b, (long long) r2, (long long) r3); -} - -static void -mul_test (void) -{ - grub_uint64_t a = 404, b = 7; - grub_size_t i; - - for (i = 0; i < ARRAY_SIZE (vectors); i++) - { - test64 (vectors[i][0], vectors[i][1]); - } - for (i = 0; i < 40000; i++) - { - a = 17 * a + 13 * b; - b = 23 * a + 29 * b; - if (b == 0) - b = 1; - if (a == 0) - a = 1; - test64 (a, b); - } -} - -/* Register example_test method as a functional test. */ -GRUB_FUNCTIONAL_TEST (mul_test, mul_test); diff --git a/grub-core/tests/setjmp_test.c b/grub-core/tests/setjmp_test.c index 604a6ce8f..390cb26eb 100644 --- a/grub-core/tests/setjmp_test.c +++ b/grub-core/tests/setjmp_test.c @@ -25,10 +25,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_jmp_buf jmp_point; static int expected, ctr; -/* This fixes GCC7 "unintentional fallthrough" warning */ -static void jmp0 (void) __attribute__ ((noreturn)); -static void jmp1 (void) __attribute__ ((noreturn)); -static void jmp2 (void) __attribute__ ((noreturn)); +#pragma GCC diagnostic ignored "-Wmissing-noreturn" static void jmp0 (void) diff --git a/grub-core/tests/shift_test.c b/grub-core/tests/shift_test.c deleted file mode 100644 index 4120f520a..000000000 --- a/grub-core/tests/shift_test.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2015 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_uint64_t vectors[] = { - 0xffffffffffffffffULL, 1, 2, 0, 0x0102030405060708ULL -}; - -/* We're testing shifts, don't replace access to this with a shift. */ -static const grub_uint8_t bitmask[] = - { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; - -typedef union { - grub_uint64_t v64; - grub_uint8_t v8[8]; -} grub_raw_u64_t; - -static int -get_bit64 (grub_uint64_t v, int b) -{ - grub_raw_u64_t vr = { .v64 = v }; - grub_uint8_t *p = vr.v8; - if (b >= 64) - return 0; -#ifdef GRUB_CPU_WORDS_BIGENDIAN - p += 7 - b / 8; -#else - p += b / 8; -#endif - return !!(*p & bitmask[b % 8]); -} - -static grub_uint64_t -set_bit64 (grub_uint64_t v, int b) -{ - grub_raw_u64_t vr = { .v64 = v }; - grub_uint8_t *p = vr.v8; - if (b >= 64) - return v; -#ifdef GRUB_CPU_WORDS_BIGENDIAN - p += 7 - b / 8; -#else - p += b / 8; -#endif - *p |= bitmask[b % 8]; - return vr.v64; -} - -static grub_uint64_t -left_shift64 (grub_uint64_t v, int s) -{ - grub_uint64_t r = 0; - int i; - for (i = 0; i + s < 64; i++) - if (get_bit64 (v, i)) - r = set_bit64 (r, i + s); - return r; -} - -static grub_uint64_t -right_shift64 (grub_uint64_t v, int s) -{ - grub_uint64_t r = 0; - int i; - for (i = s; i < 64; i++) - if (get_bit64 (v, i)) - r = set_bit64 (r, i - s); - return r; -} - -static grub_uint64_t -arithmetic_right_shift64 (grub_uint64_t v, int s) -{ - grub_uint64_t r = 0; - int i; - for (i = s; i < 64; i++) - if (get_bit64 (v, i)) - r = set_bit64 (r, i - s); - if (get_bit64 (v, 63)) - for (i -= s; i < 64; i++) - r = set_bit64 (r, i); - - return r; -} - -static void -test64 (grub_uint64_t v) -{ - int i; - for (i = 0; i < 64; i++) - { - grub_test_assert ((v << i) == left_shift64 (v, i), - "lshift wrong: 0x%llx << %d: 0x%llx, 0x%llx", - (long long) v, i, - (long long) (v << i), (long long) left_shift64 (v, i)); - grub_test_assert ((v >> i) == right_shift64 (v, i), - "rshift wrong: 0x%llx >> %d: 0x%llx, 0x%llx", - (long long) v, i, - (long long) (v >> i), (long long) right_shift64 (v, i)); - grub_test_assert ((((grub_int64_t) v) >> i) == (grub_int64_t) arithmetic_right_shift64 (v, i), - "arithmetic rshift wrong: ((grub_int64_t) 0x%llx) >> %d: 0x%llx, 0x%llx", - (long long) v, i, - (long long) (((grub_int64_t) v) >> i), (long long) arithmetic_right_shift64 (v, i)); - } -} - -static void -test_all(grub_uint64_t a) -{ - test64 (a); -} - -static void -shift_test (void) -{ - grub_uint64_t a = 404, b = 7; - grub_size_t i; - - for (i = 0; i < ARRAY_SIZE (vectors); i++) - { - test_all (vectors[i]); - } - for (i = 0; i < 4000; i++) - { - a = 17 * a + 13 * b; - b = 23 * a + 29 * b; - if (b == 0) - b = 1; - if (a == 0) - a = 1; - test_all (a); - test_all (b); - } -} - -/* Register example_test method as a functional test. */ -GRUB_FUNCTIONAL_TEST (shift_test, shift_test); diff --git a/grub-core/tests/sleep_test.c b/grub-core/tests/sleep_test.c index 3d11c717c..3dda30312 100644 --- a/grub-core/tests/sleep_test.c +++ b/grub-core/tests/sleep_test.c @@ -33,19 +33,12 @@ sleep_test (void) { struct grub_datetime st, en; grub_int32_t stu = 0, enu = 0; - int is_delayok; grub_test_assert (!grub_get_datetime (&st), "Couldn't retrieve start time"); grub_millisleep (10000); grub_test_assert (!grub_get_datetime (&en), "Couldn't retrieve end time"); grub_test_assert (grub_datetime2unixtime (&st, &stu), "Invalid date"); grub_test_assert (grub_datetime2unixtime (&en, &enu), "Invalid date"); - is_delayok = (enu - stu >= 9 && enu - stu <= 11); -#ifdef __arm__ - /* Ignore QEMU bug */ - if (enu - stu >= 15 && enu - stu <= 17) - is_delayok = 1; -#endif - grub_test_assert (is_delayok, "Interval out of range: %d", enu-stu); + grub_test_assert (enu - stu >= 9 && enu - stu <= 11, "Interval out of range: %d", enu-stu); } diff --git a/grub-core/tests/strtoull_test.c b/grub-core/tests/strtoull_test.c deleted file mode 100644 index 5488ab26b..000000000 --- a/grub-core/tests/strtoull_test.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static void -strtoull_testcase (const char *input, int base, unsigned long long expected, - int num_digits, grub_err_t error) -{ - const char *output; - unsigned long long value; - grub_errno = 0; - value = grub_strtoull(input, &output, base); - grub_test_assert (grub_errno == error, - "unexpected error. Expected %d, got %d. Input \"%s\"", - error, grub_errno, input); - if (grub_errno) - { - grub_errno = 0; - return; - } - grub_test_assert (input + num_digits == output, - "unexpected number of digits. Expected %d, got %d, input \"%s\"", - num_digits, (int) (output - input), input); - grub_test_assert (value == expected, - "unexpected return value. Expected %llu, got %llu, input \"\%s\"", - expected, value, input); -} - -static void -strtoull_test (void) -{ - strtoull_testcase ("9", 0, 9, 1, GRUB_ERR_NONE); - strtoull_testcase ("0xaa", 0, 0xaa, 4, GRUB_ERR_NONE); - strtoull_testcase ("0xff", 0, 0xff, 4, GRUB_ERR_NONE); - strtoull_testcase ("0", 10, 0, 1, GRUB_ERR_NONE); - strtoull_testcase ("8", 8, 0, 0, GRUB_ERR_BAD_NUMBER); - strtoull_testcase ("38", 8, 3, 1, GRUB_ERR_NONE); - strtoull_testcase ("7", 8, 7, 1, GRUB_ERR_NONE); - strtoull_testcase ("1]", 16, 1, 1, GRUB_ERR_NONE); - strtoull_testcase ("18446744073709551616", 10, 0, 0, GRUB_ERR_OUT_OF_RANGE); -} - - -GRUB_FUNCTIONAL_TEST (strtoull_test, strtoull_test); diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c index 44d081069..74d5b65e5 100644 --- a/grub-core/tests/video_checksum.c +++ b/grub-core/tests/video_checksum.c @@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, { case 4: { - grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint8_t *buffer = xmalloc (mode_info->width * 3); grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); @@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, } case 3: { - grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint8_t *buffer = xmalloc (mode_info->width * 3); grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); @@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, } case 2: { - grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint8_t *buffer = xmalloc (mode_info->width * 3); grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c index 6256e209a..b2e031566 100644 --- a/grub-core/video/bitmap.c +++ b/grub-core/video/bitmap.c @@ -23,7 +23,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -59,7 +58,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, enum grub_video_blit_format blit_format) { struct grub_video_mode_info *mode_info; - grub_size_t size; + unsigned int size; if (!bitmap) return grub_error (GRUB_ERR_BUG, "invalid argument"); @@ -138,25 +137,19 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, mode_info->pitch = width * mode_info->bytes_per_pixel; - /* Calculate size needed for the data. */ - if (grub_mul (width, mode_info->bytes_per_pixel, &size) || - grub_mul (size, height, &size)) - { - grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - goto fail; - } + /* Calculate size needed for the data. */ + size = (width * mode_info->bytes_per_pixel) * height; (*bitmap)->data = grub_zalloc (size); if (! (*bitmap)->data) - goto fail; + { + grub_free (*bitmap); + *bitmap = 0; + + return grub_errno; + } return GRUB_ERR_NONE; - - fail: - grub_free (*bitmap); - *bitmap = NULL; - - return grub_errno; } /* Frees all resources allocated by bitmap. */ diff --git a/grub-core/video/bitmap_scale.c b/grub-core/video/bitmap_scale.c index 70c32f029..0b93d0206 100644 --- a/grub-core/video/bitmap_scale.c +++ b/grub-core/video/bitmap_scale.c @@ -361,46 +361,35 @@ scale_nn (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) unsigned dh = dst->mode_info.height; unsigned sw = src->mode_info.width; unsigned sh = src->mode_info.height; - int dstride = dst->mode_info.pitch; - int sstride = src->mode_info.pitch; + unsigned dstride = dst->mode_info.pitch; + unsigned sstride = src->mode_info.pitch; /* bytes_per_pixel is the same for both src and dst. */ - int bytes_per_pixel = dst->mode_info.bytes_per_pixel; - unsigned dy, sy, ystep, yfrac, yover; - unsigned sx, xstep, xfrac, xover; - grub_uint8_t *dptr, *dline_end, *sline; + unsigned bytes_per_pixel = dst->mode_info.bytes_per_pixel; - xstep = sw / dw; - xover = sw % dw; - ystep = sh / dh; - yover = sh % dh; - - for (dy = 0, sy = 0, yfrac = 0; dy < dh; dy++, sy += ystep, yfrac += yover) + unsigned dy; + for (dy = 0; dy < dh; dy++) { - if (yfrac >= dh) - { - yfrac -= dh; - sy++; - } - dptr = ddata + dy * dstride; - dline_end = dptr + dw * bytes_per_pixel; - sline = sdata + sy * sstride; - for (sx = 0, xfrac = 0; dptr < dline_end; sx += xstep, xfrac += xover, dptr += bytes_per_pixel) + unsigned dx; + for (dx = 0; dx < dw; dx++) { + grub_uint8_t *dptr; grub_uint8_t *sptr; - int comp; + unsigned sx; + unsigned sy; + unsigned comp; - if (xfrac >= dw) - { - xfrac -= dw; - sx++; - } + /* Compute the source coordinate that the destination coordinate + maps to. Note: sx/sw = dx/dw => sx = sw*dx/dw. */ + sx = sw * dx / dw; + sy = sh * dy / dh; /* Get the address of the pixels in src and dst. */ - sptr = sline + sx * bytes_per_pixel; + dptr = ddata + dy * dstride + dx * bytes_per_pixel; + sptr = sdata + sy * sstride + sx * bytes_per_pixel; - /* Copy the pixel color value. */ - for (comp = 0; comp < bytes_per_pixel; comp++) - dptr[comp] = sptr[comp]; + /* Copy the pixel color value. */ + for (comp = 0; comp < bytes_per_pixel; comp++) + dptr[comp] = sptr[comp]; } } return GRUB_ERR_NONE; @@ -433,40 +422,27 @@ scale_bilinear (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) int sstride = src->mode_info.pitch; /* bytes_per_pixel is the same for both src and dst. */ int bytes_per_pixel = dst->mode_info.bytes_per_pixel; - unsigned dy, syf, sy, ystep, yfrac, yover; - unsigned sxf, sx, xstep, xfrac, xover; - grub_uint8_t *dptr, *dline_end, *sline; - xstep = (sw << 8) / dw; - xover = (sw << 8) % dw; - ystep = (sh << 8) / dh; - yover = (sh << 8) % dh; - - for (dy = 0, syf = 0, yfrac = 0; dy < dh; dy++, syf += ystep, yfrac += yover) + unsigned dy; + for (dy = 0; dy < dh; dy++) { - if (yfrac >= dh) - { - yfrac -= dh; - syf++; - } - sy = syf >> 8; - dptr = ddata + dy * dstride; - dline_end = dptr + dw * bytes_per_pixel; - sline = sdata + sy * sstride; - for (sxf = 0, xfrac = 0; dptr < dline_end; sxf += xstep, xfrac += xover, dptr += bytes_per_pixel) + unsigned dx; + for (dx = 0; dx < dw; dx++) { + grub_uint8_t *dptr; grub_uint8_t *sptr; + unsigned sx; + unsigned sy; int comp; - if (xfrac >= dw) - { - xfrac -= dw; - sxf++; - } + /* Compute the source coordinate that the destination coordinate + maps to. Note: sx/sw = dx/dw => sx = sw*dx/dw. */ + sx = sw * dx / dw; + sy = sh * dy / dh; /* Get the address of the pixels in src and dst. */ - sx = sxf >> 8; - sptr = sline + sx * bytes_per_pixel; + dptr = ddata + dy * dstride + dx * bytes_per_pixel; + sptr = sdata + sy * sstride + sx * bytes_per_pixel; /* If we have enough space to do so, use bilinear interpolation. Otherwise, fall back to nearest neighbor for this pixel. */ @@ -477,27 +453,27 @@ scale_bilinear (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) /* Fixed-point .8 numbers representing the fraction of the distance in the x (u) and y (v) direction within the box of 4 pixels in the source. */ - unsigned u = sxf & 0xff; - unsigned v = syf & 0xff; + int u = (256 * sw * dx / dw) - (sx * 256); + int v = (256 * sh * dy / dh) - (sy * 256); for (comp = 0; comp < bytes_per_pixel; comp++) { /* Get the component's values for the four source corner pixels. */ - unsigned f00 = sptr[comp]; - unsigned f10 = sptr[comp + bytes_per_pixel]; - unsigned f01 = sptr[comp + sstride]; - unsigned f11 = sptr[comp + sstride + bytes_per_pixel]; + int f00 = sptr[comp]; + int f10 = sptr[comp + bytes_per_pixel]; + int f01 = sptr[comp + sstride]; + int f11 = sptr[comp + sstride + bytes_per_pixel]; /* Count coeffecients. */ - unsigned c00 = (256 - u) * (256 - v); - unsigned c10 = u * (256 - v); - unsigned c01 = (256 - u) * v; - unsigned c11 = u * v; + int c00 = (256 - u) * (256 - v); + int c10 = u * (256 - v); + int c01 = (256 - u) * v; + int c11 = u * v; /* Interpolate. */ - unsigned fxy = c00 * f00 + c01 * f01 + c10 * f10 + c11 * f11; - fxy = fxy >> 16; + int fxy = c00 * f00 + c01 * f01 + c10 * f10 + c11 * f11; + fxy = fxy / (256 * 256); dptr[comp] = fxy; } diff --git a/grub-core/video/bochs.c b/grub-core/video/bochs.c index 7a249eb21..9098f90d1 100644 --- a/grub-core/video/bochs.c +++ b/grub-core/video/bochs.c @@ -274,7 +274,7 @@ grub_video_bochs_setup (unsigned int width, unsigned int height, " supported by bochs video"); if (depth == 4) - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "4-bpp isn't supported"); + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "4-bpp isn't cupported"); bytes_per_pixel = (depth + 7) / 8; if (depth == 4) @@ -359,7 +359,6 @@ grub_video_bochs_setup (unsigned int width, unsigned int height, case 32: framebuffer.mode_info.reserved_mask_size = 8; framebuffer.mode_info.reserved_field_pos = 24; - /* Fallthrough. */ case 24: framebuffer.mode_info.red_mask_size = 8; diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c index 4d3195e01..4f83c7441 100644 --- a/grub-core/video/capture.c +++ b/grub-core/video/capture.c @@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, framebuffer.mode_info = *mode_info; framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); - framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); + framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); if (!framebuffer.ptr) return grub_errno; diff --git a/grub-core/video/cirrus.c b/grub-core/video/cirrus.c index e2149e8ce..4913084fa 100644 --- a/grub-core/video/cirrus.c +++ b/grub-core/video/cirrus.c @@ -440,7 +440,6 @@ grub_video_cirrus_setup (unsigned int width, unsigned int height, case 32: framebuffer.mode_info.reserved_mask_size = 8; framebuffer.mode_info.reserved_field_pos = 24; - /* Fallthrough. */ case 24: framebuffer.mode_info.red_mask_size = 8; diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c index be446f8d2..7f9d1c2df 100644 --- a/grub-core/video/efi_gop.c +++ b/grub-core/video/efi_gop.c @@ -71,10 +71,7 @@ check_protocol (void) handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &graphics_output_guid, NULL, &num_handles); if (!handles || num_handles == 0) - { - grub_dprintf ("video", "GOP: no handles\n"); - return 0; - } + return 0; for (i = 0; i < num_handles; i++) { @@ -84,7 +81,6 @@ check_protocol (void) grub_video_gop_iterate (check_protocol_hook, &have_usable_mode); if (have_usable_mode) { - grub_dprintf ("video", "GOP: found usable mode\n"); grub_free (handles); return 1; } @@ -93,8 +89,6 @@ check_protocol (void) gop = 0; gop_handle = 0; - grub_dprintf ("video", "GOP: no usable mode\n"); - return 0; } @@ -127,7 +121,6 @@ grub_video_gop_get_bpp (struct grub_efi_gop_mode_info *in) { case GRUB_EFI_GOT_BGRA8: case GRUB_EFI_GOT_RGBA8: - case GRUB_EFI_GOT_BLT_ONLY: return 32; case GRUB_EFI_GOT_BITMASK: @@ -194,7 +187,6 @@ grub_video_gop_fill_real_mode_info (unsigned mode, switch (in->pixel_format) { case GRUB_EFI_GOT_RGBA8: - case GRUB_EFI_GOT_BLT_ONLY: out->red_mask_size = 8; out->red_field_pos = 0; out->green_mask_size = 8; diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c index e74d6c235..464ede874 100644 --- a/grub-core/video/efi_uga.c +++ b/grub-core/video/efi_uga.c @@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; static struct grub_efi_uga_draw_protocol *uga; -static grub_uint64_t uga_fb; +static grub_uint32_t uga_fb; static grub_uint32_t uga_pitch; static struct @@ -52,7 +52,7 @@ static struct #define FBTEST_COUNT 8 static int -find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) +find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) { grub_uint32_t *base = (grub_uint32_t *) (grub_addr_t) *fb_base; int i; @@ -67,7 +67,7 @@ find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) { if ((base[j] & RGB_MASK) == RGB_MAGIC) { - *fb_base = (grub_uint64_t) (grub_addr_t) base; + *fb_base = (grub_uint32_t) (grub_addr_t) base; *line_len = j << 2; return 1; @@ -84,7 +84,7 @@ find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) /* Context for find_framebuf. */ struct find_framebuf_ctx { - grub_uint64_t *fb_base; + grub_uint32_t *fb_base; grub_uint32_t *line_len; int found; }; @@ -94,23 +94,14 @@ static int find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) { struct find_framebuf_ctx *ctx = data; - grub_pci_address_t addr, rcaddr; - grub_uint32_t subclass; + grub_pci_address_t addr; addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); - subclass = (grub_pci_read (addr) >> 16) & 0xffff; - - if (subclass != GRUB_PCI_CLASS_SUBCLASS_VGA) - return 0; - - /* Enable MEM address spaces */ - rcaddr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND); - grub_pci_write_word (rcaddr, grub_pci_read_word (rcaddr) | GRUB_PCI_COMMAND_MEM_ENABLED); - + if (grub_pci_read (addr) >> 24 == 0x3) { int i; - grub_dprintf ("video", "Display controller: %d:%d.%d\nDevice id: %x\n", + grub_dprintf ("fb", "Display controller: %d:%d.%d\nDevice id: %x\n", grub_pci_get_bus (dev), grub_pci_get_device (dev), grub_pci_get_function (dev), pciid); addr += 8; @@ -129,9 +120,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) if (i == 5) break; - i++; - addr += 4; - old_bar2 = grub_pci_read (addr); + old_bar2 = grub_pci_read (addr + 4); } else old_bar2 = 0; @@ -140,15 +129,10 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) base64 <<= 32; base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); - grub_dprintf ("video", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", + grub_dprintf ("fb", "%s(%d): 0x%llx\n", ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? - "VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i, - base64); - -#if GRUB_CPU_SIZEOF_VOID_P == 4 - if (old_bar2) - continue; -#endif + "VMEM" : "MMIO"), i, + (unsigned long long) base64); if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! ctx->found)) { @@ -156,6 +140,12 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) if (find_line_len (ctx->fb_base, ctx->line_len)) ctx->found++; } + + if (type == GRUB_PCI_ADDR_MEM_TYPE_64) + { + i++; + addr += 4; + } } } @@ -163,7 +153,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) } static int -find_framebuf (grub_uint64_t *fb_base, grub_uint32_t *line_len) +find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) { struct find_framebuf_ctx ctx = { .fb_base = fb_base, diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c index 0ebab6f57..a2f639f66 100644 --- a/grub-core/video/emu/sdl.c +++ b/grub-core/video/emu/sdl.c @@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, if (start + count > mode_info.number_of_colors) count = mode_info.number_of_colors - start; - tmp = grub_calloc (count, sizeof (tmp[0])); + tmp = grub_malloc (count * sizeof (tmp[0])); for (i = 0; i < count; i++) { tmp[i].r = palette_data[i].r; diff --git a/grub-core/video/fb/fbblit.c b/grub-core/video/fb/fbblit.c index d55924837..3a073cea7 100644 --- a/grub-core/video/fb/fbblit.c +++ b/grub-core/video/fb/fbblit.c @@ -1145,20 +1145,6 @@ grub_video_fbblit_replace_index_RGB888 (struct grub_video_fbblit_info *dst, } } -static inline grub_uint8_t -alpha_dilute (grub_uint8_t bg, grub_uint8_t fg, grub_uint8_t alpha) -{ - grub_uint16_t s; - grub_uint16_t h, l; - s = (fg * alpha) + (bg * (255 ^ alpha)); - /* Optimised division by 255. */ - h = s >> 8; - l = s & 0xff; - if (h + l >= 255) - h++; - return h; -} - /* Generic blending blitter. Works for every supported format. */ static void grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, @@ -1204,9 +1190,12 @@ grub_video_fbblit_blend (struct grub_video_fbblit_info *dst, grub_video_fb_unmap_color_int (dst, dst_color, &dst_red, &dst_green, &dst_blue, &dst_alpha); - dst_red = alpha_dilute (dst_red, src_red, src_alpha); - dst_green = alpha_dilute (dst_green, src_green, src_alpha); - dst_blue = alpha_dilute (dst_blue, src_blue, src_alpha); + dst_red = (((src_red * src_alpha) + + (dst_red * (255 ^ src_alpha))) / 255U); + dst_green = (((src_green * src_alpha) + + (dst_green * (255 ^ src_alpha))) / 255U); + dst_blue = (((src_blue * src_alpha) + + (dst_blue * (255 ^ src_alpha))) / 255U); dst_alpha = src_alpha; dst_color = grub_video_fb_map_rgba (dst_red, dst_green, dst_blue, @@ -1281,11 +1270,11 @@ grub_video_fbblit_blend_BGRA8888_RGBA8888 (struct grub_video_fbblit_info *dst, color = *dstptr; dr = (color >> 16) & 0xFF; - dr = alpha_dilute (dr, sr, a); + dr = (dr * (255 ^ a) + sr * a) / 255U; dg = (color >> 8) & 0xFF; - dg = alpha_dilute (dg, sg, a); + dg = (dg * (255 ^ a) + sg * a) / 255U; db = (color >> 0) & 0xFF; - db = alpha_dilute (db, sb, a); + db = (db * (255 ^ a) + sb * a) / 255U; } color = (a << 24) | (dr << 16) | (dg << 8) | db; @@ -1371,9 +1360,9 @@ grub_video_fbblit_blend_BGR888_RGBA8888 (struct grub_video_fbblit_info *dst, db = dstptr[2]; #endif - db = alpha_dilute (db, sb, a); - dg = alpha_dilute (dg, sg, a); - dr = alpha_dilute (dr, sr, a); + db = (db * (255 ^ a) + sb * a) / 255U; + dg = (dg * (255 ^ a) + sg * a) / 255U; + dr = (dr * (255 ^ a) + sr * a) / 255U; } #ifndef GRUB_CPU_WORDS_BIGENDIAN @@ -1451,9 +1440,9 @@ grub_video_fbblit_blend_RGBA8888_RGBA8888 (struct grub_video_fbblit_info *dst, dg = (color >> 8) & 0xFF; db = (color >> 16) & 0xFF; - dr = alpha_dilute (dr, sr, a); - dg = alpha_dilute (dg, sg, a); - db = alpha_dilute (db, sb, a); + dr = (dr * (255 ^ a) + sr * a) / 255U; + dg = (dg * (255 ^ a) + sg * a) / 255U; + db = (db * (255 ^ a) + sb * a) / 255U; color = (a << 24) | (db << 16) | (dg << 8) | dr; @@ -1536,9 +1525,9 @@ grub_video_fbblit_blend_RGB888_RGBA8888 (struct grub_video_fbblit_info *dst, dr = dstptr[2]; #endif - dr = alpha_dilute (dr, sr, a); - dg = alpha_dilute (dg, sg, a); - db = alpha_dilute (db, sb, a); + dr = (dr * (255 ^ a) + sr * a) / 255U; + dg = (dg * (255 ^ a) + sg * a) / 255U; + db = (db * (255 ^ a) + sb * a) / 255U; #ifndef GRUB_CPU_WORDS_BIGENDIAN *dstptr++ = dr; @@ -1612,9 +1601,9 @@ grub_video_fbblit_blend_index_RGBA8888 (struct grub_video_fbblit_info *dst, grub_video_fb_unmap_color_int (dst, *dstptr, &dr, &dg, &db, &da); - dr = alpha_dilute (dr, sr, a); - dg = alpha_dilute (dg, sg, a); - db = alpha_dilute (db, sb, a); + dr = (dr * (255 ^ a) + sr * a) / 255U; + dg = (dg * (255 ^ a) + sg * a) / 255U; + db = (db * (255 ^ a) + sb * a) / 255U; color = grub_video_fb_map_rgb(dr, dg, db); @@ -1694,9 +1683,9 @@ grub_video_fbblit_blend_XXXA8888_1bit (struct grub_video_fbblit_info *dst, grub_uint8_t d2 = (*dstptr >> 8) & 0xFF; grub_uint8_t d3 = (*dstptr >> 16) & 0xFF; - d1 = alpha_dilute (d1, s1, a); - d2 = alpha_dilute (d2, s2, a); - d3 = alpha_dilute (d3, s3, a); + d1 = (d1 * (255 ^ a) + s1 * a) / 255U; + d2 = (d2 * (255 ^ a) + s2 * a) / 255U; + d3 = (d3 * (255 ^ a) + s3 * a) / 255U; *dstptr = (a << 24) | (d3 << 16) | (d2 << 8) | d1; } @@ -1802,9 +1791,9 @@ grub_video_fbblit_blend_XXX888_1bit (struct grub_video_fbblit_info *dst, grub_uint8_t d2 = (*(grub_uint32_t *) dstptr >> 8) & 0xFF; grub_uint8_t d3 = (*(grub_uint32_t *) dstptr >> 16) & 0xFF; - ((grub_uint8_t *) dstptr)[0] = alpha_dilute (d1, s1, a); - ((grub_uint8_t *) dstptr)[1] = alpha_dilute (d2, s2, a); - ((grub_uint8_t *) dstptr)[2] = alpha_dilute (d3, s3, a); + ((grub_uint8_t *) dstptr)[0] = (d1 * (255 ^ a) + s1 * a) / 255U; + ((grub_uint8_t *) dstptr)[1] = (d2 * (255 ^ a) + s2 * a) / 255U; + ((grub_uint8_t *) dstptr)[2] = (d3 * (255 ^ a) + s3 * a) / 255U; } srcmask >>= 1; @@ -1898,9 +1887,9 @@ grub_video_fbblit_blend_XXX565_1bit (struct grub_video_fbblit_info *dst, grub_uint8_t d2 = (*dstptr >> 5) & 0x3F; grub_uint8_t d3 = (*dstptr >> 11) & 0x1F; - d1 = alpha_dilute (d1, s1, a); - d2 = alpha_dilute (d2, s2, a); - d3 = alpha_dilute (d3, s3, a); + d1 = (d1 * (255 ^ a) + s1 * a) / 255U; + d2 = (d2 * (255 ^ a) + s2 * a) / 255U; + d3 = (d3 * (255 ^ a) + s3 * a) / 255U; *dstptr = (d1 & 0x1f) | ((d2 & 0x3f) << 5) | ((d3 & 0x1f) << 11); } diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c index 1a602c8b2..722bb3bb4 100644 --- a/grub-core/video/fb/video_fb.c +++ b/grub-core/video/fb/video_fb.c @@ -743,7 +743,7 @@ grub_video_fb_unmap_color_int (struct grub_video_fbblit_info * source, if ((mode_info->mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != 0) { - if ((mode_info->mode_type + if ((framebuffer.render_target->mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_ALPHA) != 0 && color == 0xf0) { diff --git a/grub-core/video/coreboot/cbfb.c b/grub-core/video/i386/coreboot/cbfb.c similarity index 99% rename from grub-core/video/coreboot/cbfb.c rename to grub-core/video/i386/coreboot/cbfb.c index 9af81fa5b..dede0c37e 100644 --- a/grub-core/video/coreboot/cbfb.c +++ b/grub-core/video/i386/coreboot/cbfb.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable; diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index b7f911926..62b5c2245 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -304,7 +304,8 @@ grub_vbe_bios_getset_dac_palette_width (int set, int *dac_mask_size) struct grub_bios_int_registers regs; regs.eax = 0x4f08; - regs.ebx = ((*dac_mask_size & 0xff) << 8) | (set ? 1 : 0); + regs.ebx = (*dac_mask_size & 0xff) >> 8; + regs.ebx = set ? 1 : 0; regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; grub_bios_interrupt (0x10, ®s); *dac_mask_size = (regs.ebx >> 8) & 0xff; @@ -874,7 +875,6 @@ vbe2videoinfo (grub_uint32_t mode, /* CGA is basically 4-bit packed pixel. */ case GRUB_VBE_MEMORY_MODEL_CGA: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_CGA; - /* Fallthrough. */ case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; break; @@ -887,7 +887,6 @@ vbe2videoinfo (grub_uint32_t mode, /* Non chain 4 is a special case of planar. */ case GRUB_VBE_MEMORY_MODEL_NONCHAIN4_256: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_NONCHAIN4; - /* Fallthrough. */ case GRUB_VBE_MEMORY_MODEL_PLANAR: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_PLANAR | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c index b2f776c99..01f47112d 100644 --- a/grub-core/video/i386/pc/vga.c +++ b/grub-core/video/i386/pc/vga.c @@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, vga_height = height ? : 480; - framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); + framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); framebuffer.front_page = 0; framebuffer.back_page = 0; if (!framebuffer.temporary_buffer) diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c index 17a3dbbb5..0b150ec24 100644 --- a/grub-core/video/ieee1275.c +++ b/grub-core/video/ieee1275.c @@ -181,7 +181,6 @@ grub_video_ieee1275_fill_mode_info (grub_ieee1275_phandle_t dev, case 32: out->reserved_mask_size = 8; out->reserved_field_pos = 24; - /* FALLTHROUGH */ case 24: out->red_mask_size = 8; diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index 31359a4c9..38ea2395a 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -94,7 +94,7 @@ struct grub_jpeg_data jpeg_data_unit_t crdu; jpeg_data_unit_t cbdu; - unsigned log_vs, log_hs; + unsigned vs, hs; int dri; unsigned r1; @@ -315,14 +315,11 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data) ss = grub_jpeg_get_byte (data); /* Sampling factor. */ if (!id) { - grub_uint8_t vs, hs; - vs = ss & 0xF; /* Vertical sampling. */ - hs = ss >> 4; /* Horizontal sampling. */ - if ((vs > 2) || (hs > 2) || (vs == 0) || (hs == 0)) + data->vs = ss & 0xF; /* Vertical sampling. */ + data->hs = ss >> 4; /* Horizontal sampling. */ + if ((data->vs > 2) || (data->hs > 2) || (data->vs == 0) || (data->hs == 0)) return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: sampling method not supported"); - data->log_vs = (vs == 2); - data->log_hs = (hs == 2); } else if (ss != JPEG_SAMPLING_1x1) return grub_error (GRUB_ERR_BAD_FILE_TYPE, @@ -619,10 +616,10 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) unsigned c1, vb, hb, nr1, nc1; int rst = data->dri; - vb = 8 << data->log_vs; - hb = 8 << data->log_hs; - nr1 = (data->image_height + vb - 1) >> (3 + data->log_vs); - nc1 = (data->image_width + hb - 1) >> (3 + data->log_hs); + vb = data->vs * 8; + hb = data->hs * 8; + nr1 = (data->image_height + vb - 1) / vb; + nc1 = (data->image_width + hb - 1) / hb; for (; data->r1 < nr1 && (!data->dri || rst); data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3) @@ -632,8 +629,8 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) unsigned r2, c2, nr2, nc2; grub_uint8_t *ptr2; - for (r2 = 0; r2 < (1U << data->log_vs); r2++) - for (c2 = 0; c2 < (1U << data->log_hs); c2++) + for (r2 = 0; r2 < data->vs; r2++) + for (c2 = 0; c2 < data->hs; c2++) grub_jpeg_decode_du (data, 0, data->ydu[r2 * 2 + c2]); if (data->color_components >= 3) @@ -655,7 +652,7 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data) unsigned i0; int yy; - i0 = (r2 >> data->log_vs) * 8 + (c2 >> data->log_hs); + i0 = (r2 / data->vs) * 8 + (c2 / data->hs); yy = data->ydu[(r2 / 8) * 2 + (c2 / 8)][(r2 % 8) * 8 + (c2 % 8)]; if (data->color_components >= 3) @@ -736,7 +733,6 @@ grub_jpeg_decode_jpeg (struct grub_jpeg_data *data) case JPEG_MARKER_SOS: /* Start Of Scan. */ if (grub_jpeg_decode_sos (data)) break; - /* FALLTHROUGH */ case JPEG_MARKER_RST0: /* Restart. */ case JPEG_MARKER_RST1: case JPEG_MARKER_RST2: @@ -772,7 +768,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap, grub_file_t file; struct grub_jpeg_data *data; - file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0); + file = grub_buffile_open (filename, 0); if (!file) return grub_errno; diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c index 0157ff742..1f03f88d3 100644 --- a/grub-core/video/readers/png.c +++ b/grub-core/video/readers/png.c @@ -23,7 +23,6 @@ #include #include #include -#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -228,7 +227,7 @@ grub_png_decode_image_palette (struct grub_png_data *data, { unsigned i = 0, j; - if (len == 0) + if (len == 0 || len % 3 != 0) return GRUB_ERR_NONE; for (i = 0; 3 * i < len && i < 256; i++) @@ -302,23 +301,15 @@ grub_png_decode_image_header (struct grub_png_data *data) data->bpp <<= 1; data->color_bits = color_bits; - - if (grub_mul (data->image_width, data->bpp, &data->row_bytes)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - + data->row_bytes = data->image_width * data->bpp; if (data->color_bits <= 4) - { - if (grub_mul (data->image_width, data->color_bits + 7, &data->row_bytes)) - return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); - - data->row_bytes >>= 3; - } + data->row_bytes = (data->image_width * data->color_bits + 7) / 8; #ifndef GRUB_CPU_WORDS_BIGENDIAN if (data->is_16bit || data->is_gray || data->is_palette) #endif { - data->image_data = grub_calloc (data->image_height, data->row_bytes); + data->image_data = grub_malloc (data->image_height * data->row_bytes); if (grub_errno) return grub_errno; @@ -860,26 +851,15 @@ grub_png_convert_image (struct grub_png_data *data) int mask = (1 << data->color_bits) - 1; unsigned j; if (data->is_gray) - { - /* Generic formula is - (0xff * i) / ((1U << data->color_bits) - 1) - but for allowed bit depth of 1, 2 and for it's - equivalent to - (0xff / ((1U << data->color_bits) - 1)) * i - Precompute the multipliers to avoid division. - */ - - const grub_uint8_t multipliers[5] = { 0xff, 0xff, 0x55, 0x24, 0x11 }; - for (i = 0; i < (1U << data->color_bits); i++) - { - grub_uint8_t col = multipliers[data->color_bits] * i; - palette[i][0] = col; - palette[i][1] = col; - palette[i][2] = col; - } - } + for (i = 0; i < (1U << data->color_bits); i++) + { + grub_uint8_t col = (0xff * i) / ((1U << data->color_bits) - 1); + palette[i][0] = col; + palette[i][1] = col; + palette[i][2] = col; + } else - grub_memcpy (palette, data->palette, 3 << data->color_bits); + grub_memcpy (palette, data->palette, 16 * 3); d1c = d1; d2c = d2; for (j = 0; j < data->image_height; j++, d1c += data->image_width * 3, @@ -1095,7 +1075,7 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap, grub_file_t file; struct grub_png_data *data; - file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0); + file = grub_buffile_open (filename, 0); if (!file) return grub_errno; diff --git a/grub-core/video/readers/tga.c b/grub-core/video/readers/tga.c index 7cb9d1d2a..c7a16fa9c 100644 --- a/grub-core/video/readers/tga.c +++ b/grub-core/video/readers/tga.c @@ -297,7 +297,7 @@ grub_video_reader_tga (struct grub_video_bitmap **bitmap, grub_memset (&data, 0, sizeof (data)); - data.file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0); + data.file = grub_buffile_open (filename, 0); if (! data.file) return grub_errno; diff --git a/grub-core/video/video.c b/grub-core/video/video.c index 983424107..f252663c1 100644 --- a/grub-core/video/video.c +++ b/grub-core/video/video.c @@ -663,8 +663,6 @@ grub_video_set_mode (const char *modestring, return GRUB_ERR_NONE; } - else - continue; } err = parse_modespec (current_mode, &width, &height, &depth); diff --git a/include/grub/acpi.h b/include/grub/acpi.h index 84f49487d..f6e6a11c5 100644 --- a/include/grub/acpi.h +++ b/include/grub/acpi.h @@ -22,8 +22,6 @@ #ifndef GRUB_DSDT_TEST #include #include -#else -#define GRUB_PACKED __attribute__ ((packed)) #endif #define GRUB_RSDP_SIGNATURE "RSD PTR " @@ -69,14 +67,10 @@ struct grub_acpi_fadt grub_uint32_t dsdt_addr; grub_uint8_t somefields1[20]; grub_uint32_t pm1a; - grub_uint8_t somefields2[8]; - grub_uint32_t pmtimer; - grub_uint8_t somefields3[32]; - grub_uint32_t flags; - grub_uint8_t somefields4[16]; + grub_uint8_t somefields2[64]; grub_uint64_t facs_xaddr; grub_uint64_t dsdt_xaddr; - grub_uint8_t somefields5[96]; + grub_uint8_t somefields3[96]; } GRUB_PACKED; #define GRUB_ACPI_MADT_SIGNATURE "APIC" @@ -93,7 +87,7 @@ struct grub_acpi_madt grub_uint32_t lapic_addr; grub_uint32_t flags; struct grub_acpi_madt_entry_header entries[0]; -} GRUB_PACKED; +}; enum { @@ -182,9 +176,9 @@ enum #ifndef GRUB_DSDT_TEST struct grub_acpi_rsdp_v10 *grub_acpi_get_rsdpv1 (void); struct grub_acpi_rsdp_v20 *grub_acpi_get_rsdpv2 (void); -struct grub_acpi_rsdp_v10 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv1) (void); -struct grub_acpi_rsdp_v20 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv2) (void); -grub_uint8_t EXPORT_FUNC(grub_byte_checksum) (void *base, grub_size_t size); +struct grub_acpi_rsdp_v10 *grub_machine_acpi_get_rsdpv1 (void); +struct grub_acpi_rsdp_v20 *grub_machine_acpi_get_rsdpv2 (void); +grub_uint8_t grub_byte_checksum (void *base, grub_size_t size); grub_err_t grub_acpi_create_ebda (void); @@ -221,10 +215,9 @@ enum GRUB_ACPI_OPCODE_CONCATRES = 0x84, GRUB_ACPI_OPCODE_MOD = 0x85, GRUB_ACPI_OPCODE_INDEX = 0x88, - GRUB_ACPI_OPCODE_CREATE_DWORD_FIELD = 0x8a, + GRUB_ACPI_OPCODE_TOSTRING = 0x9c, GRUB_ACPI_OPCODE_CREATE_WORD_FIELD = 0x8b, GRUB_ACPI_OPCODE_CREATE_BYTE_FIELD = 0x8c, - GRUB_ACPI_OPCODE_TOSTRING = 0x9c, GRUB_ACPI_OPCODE_IF = 0xa0, GRUB_ACPI_OPCODE_ONES = 0xff }; enum @@ -241,7 +234,4 @@ enum GRUB_ACPI_EXTOPCODE_BANK_FIELD_OP = 0x87, }; -struct grub_acpi_fadt * -EXPORT_FUNC(grub_acpi_find_fadt) (void); - #endif /* ! GRUB_ACPI_HEADER */ diff --git a/include/grub/aout.h b/include/grub/aout.h index c8c1d94ec..10d7dde61 100644 --- a/include/grub/aout.h +++ b/include/grub/aout.h @@ -52,7 +52,6 @@ #define GRUB_AOUT_HEADER 1 #include -#include struct grub_aout32_header { diff --git a/include/grub/arc/arc.h b/include/grub/arc/arc.h index 999de7196..7615a49a9 100644 --- a/include/grub/arc/arc.h +++ b/include/grub/arc/arc.h @@ -53,7 +53,7 @@ enum grub_arc_memory_type #ifndef GRUB_CPU_WORDS_BIGENDIAN GRUB_ARC_MEMORY_FREE_CONTIGUOUS, #endif - }; + } grub_arc_memory_type_t; struct grub_arc_timeinfo { diff --git a/include/grub/arm/coreboot/kernel.h b/include/grub/arm/coreboot/kernel.h deleted file mode 100644 index 269505342..000000000 --- a/include/grub/arm/coreboot/kernel.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_KERNEL_MACHINE_HEADER -#define GRUB_KERNEL_MACHINE_HEADER 1 - -#ifndef ASM_FILE - -#include -#include - -struct grub_fdt_board -{ - const char *vendor, *part; - const grub_uint8_t *dtb; - grub_size_t dtb_size; -}; - -extern struct grub_fdt_board grub_fdt_boards[]; -void grub_machine_timer_init (void); -void grub_pl050_init (void); -void grub_cros_init (void); -void grub_rk3288_spi_init (void); -extern grub_addr_t EXPORT_VAR (start_of_ram); -#endif /* ! ASM_FILE */ - -#define GRUB_KERNEL_MACHINE_STACK_SIZE GRUB_KERNEL_ARM_STACK_SIZE - -#endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/arm/cros_ec.h b/include/grub/arm/cros_ec.h deleted file mode 100644 index 45a372572..000000000 --- a/include/grub/arm/cros_ec.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef GRUB_ARM_CROS_EC_H -#define GRUB_ARM_CROS_EC_H 1 - -#include -#include - -#define GRUB_CROS_EC_KEYSCAN_COLS 13 -#define GRUB_CROS_EC_KEYSCAN_ROWS 8 - -struct grub_cros_ec_keyscan { - grub_uint8_t data[GRUB_CROS_EC_KEYSCAN_COLS]; -}; - -int -grub_cros_ec_scan_keyboard (const struct grub_fdtbus_dev *dev, - struct grub_cros_ec_keyscan *scan); - -int -grub_cros_ec_validate (const struct grub_fdtbus_dev *dev); - -#endif diff --git a/include/grub/efi/fdtload.h b/include/grub/arm/efi/loader.h similarity index 66% rename from include/grub/efi/fdtload.h rename to include/grub/arm/efi/loader.h index 713c9424d..4bab18e83 100644 --- a/include/grub/efi/fdtload.h +++ b/include/grub/arm/efi/loader.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013-2015 Free Software Foundation, Inc. + * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,17 +16,11 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_FDTLOAD_CPU_HEADER -#define GRUB_FDTLOAD_CPU_HEADER 1 +#ifndef GRUB_LOADER_MACHINE_HEADER +#define GRUB_LOADER_MACHINE_HEADER 1 -#include -#include +grub_err_t EXPORT_FUNC (grub_efi_prepare_platform) (void); +void * EXPORT_FUNC (grub_efi_allocate_loader_memory) (grub_uint32_t min_offset, + grub_uint32_t size); -void * -grub_fdt_load (grub_size_t additional_size); -void -grub_fdt_unload (void); -grub_err_t -grub_fdt_install (void); - -#endif +#endif /* ! GRUB_LOADER_MACHINE_HEADER */ diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h index 2e98a6689..059dbba42 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -17,45 +17,33 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_ARM_LINUX_HEADER -#define GRUB_ARM_LINUX_HEADER 1 +#ifndef GRUB_LINUX_CPU_HEADER +#define GRUB_LINUX_CPU_HEADER 1 + +#define LINUX_ZIMAGE_OFFSET 0x24 +#define LINUX_ZIMAGE_MAGIC 0x016f2818 #include "system.h" -#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 - -struct linux_arm_kernel_header { - grub_uint32_t code0; - grub_uint32_t reserved1[8]; - grub_uint32_t magic; - grub_uint32_t start; /* _start */ - grub_uint32_t end; /* _edata */ - grub_uint32_t reserved2[4]; - grub_uint32_t hdr_offset; -}; - -#if defined(__arm__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE -# define linux_arch_kernel_header linux_arm_kernel_header -#endif - #if defined GRUB_MACHINE_UBOOT # include # define LINUX_ADDRESS (start_of_ram + 0x8000) -# define LINUX_INITRD_ADDRESS (start_of_ram + 0x03000000) +# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000) # define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000) # define grub_arm_firmware_get_boot_data grub_uboot_get_boot_data # define grub_arm_firmware_get_machine_type grub_uboot_get_machine_type -#elif defined (GRUB_MACHINE_COREBOOT) -#include -#include -# define LINUX_ADDRESS (start_of_ram + 0x8000) -# define LINUX_INITRD_ADDRESS (start_of_ram + 0x03000000) -# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000) -static inline const void * +#elif defined GRUB_MACHINE_EFI +# include +# include +/* On UEFI platforms - load the images at the lowest available address not + less than *_PHYS_OFFSET from the first available memory location. */ +# define LINUX_PHYS_OFFSET (0x00008000) +# define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000) +# define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000) +static inline grub_addr_t grub_arm_firmware_get_boot_data (void) { - return grub_fdtbus_get_fdt (); + return 0; } static inline grub_uint32_t grub_arm_firmware_get_machine_type (void) @@ -64,4 +52,6 @@ grub_arm_firmware_get_machine_type (void) } #endif -#endif /* ! GRUB_ARM_LINUX_HEADER */ +#define FDT_ADDITIONAL_ENTRIES_SIZE 0x300 + +#endif /* ! GRUB_LINUX_CPU_HEADER */ diff --git a/include/grub/arm/reloc.h b/include/grub/arm/reloc.h index ae92e21f1..b938037a0 100644 --- a/include/grub/arm/reloc.h +++ b/include/grub/arm/reloc.h @@ -43,9 +43,4 @@ void grub_arm_jump24_set_offset (grub_uint32_t *target, grub_int32_t offset); -grub_uint16_t -grub_arm_thm_movw_movt_get_value (grub_uint16_t *target); -void -grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value); - #endif diff --git a/include/grub/arm/startup.h b/include/grub/arm/startup.h deleted file mode 100644 index 9afb6c57c..000000000 --- a/include/grub/arm/startup.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GRUB_STARTUP_CPU_HEADER -#define GRUB_STARTUP_CPU_HEADER - -struct grub_arm_startup_registers -{ - /* registers 0-11 */ - /* for U-boot r[1] is machine type */ - /* for U-boot r[2] is boot data */ - grub_uint32_t r[12]; - grub_uint32_t sp; - grub_uint32_t lr; -}; - -extern struct grub_arm_startup_registers grub_arm_saved_registers; - -#endif diff --git a/include/grub/arm/time.h b/include/grub/arm/time.h index c5a685225..4128506cb 100644 --- a/include/grub/arm/time.h +++ b/include/grub/arm/time.h @@ -23,7 +23,7 @@ static __inline void grub_cpu_idle (void) { /* FIXME: this can't work until we handle interrupts. */ -/* asm volatile ("wfi"); */ +/* __asm__ __volatile__ ("wfi"); */ } #endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/arm/uboot/kernel.h b/include/grub/arm/uboot/kernel.h index ce0b149cc..06e543324 100644 --- a/include/grub/arm/uboot/kernel.h +++ b/include/grub/arm/uboot/kernel.h @@ -26,7 +26,7 @@ #endif /* ! ASM_FILE */ -#define GRUB_KERNEL_MACHINE_STACK_SIZE GRUB_KERNEL_ARM_STACK_SIZE +#define GRUB_KERNEL_MACHINE_STACK_SIZE 0x40000 #define GRUB_KERNEL_MACHINE_HEAP_SIZE (grub_size_t) (16 * 1024 * 1024) #endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h index 4269adc6d..864e5dc36 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h @@ -16,13 +16,15 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_ARM64_LINUX_HEADER -#define GRUB_ARM64_LINUX_HEADER 1 +#ifndef GRUB_LINUX_CPU_HEADER +#define GRUB_LINUX_CPU_HEADER 1 -#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ +#include + +#define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */ /* From linux/Documentation/arm64/booting.txt */ -struct linux_arm64_kernel_header +struct grub_arm64_linux_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ @@ -36,9 +38,4 @@ struct linux_arm64_kernel_header grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ }; -#if defined(__aarch64__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE -# define linux_arch_kernel_header linux_arm64_kernel_header -#endif - -#endif /* ! GRUB_ARM64_LINUX_HEADER */ +#endif /* ! GRUB_LINUX_CPU_HEADER */ diff --git a/include/grub/arm64/reloc.h b/include/grub/arm64/reloc.h index c8765de97..4aed3d715 100644 --- a/include/grub/arm64/reloc.h +++ b/include/grub/arm64/reloc.h @@ -19,23 +19,8 @@ #ifndef GRUB_ARM64_RELOC_H #define GRUB_ARM64_RELOC_H 1 -struct grub_arm64_trampoline -{ - grub_uint32_t ldr; /* ldr x16, 8 */ - grub_uint32_t br; /* br x16 */ - grub_uint64_t addr; -}; - int grub_arm_64_check_xxxx26_offset (grub_int64_t offset); void grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset); -int -grub_arm64_check_hi21_signed (grub_int64_t offset); -void -grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset); -void -grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target); -void -grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target); #endif diff --git a/include/grub/arm64/time.h b/include/grub/arm64/time.h index c5a685225..4128506cb 100644 --- a/include/grub/arm64/time.h +++ b/include/grub/arm64/time.h @@ -23,7 +23,7 @@ static __inline void grub_cpu_idle (void) { /* FIXME: this can't work until we handle interrupts. */ -/* asm volatile ("wfi"); */ +/* __asm__ __volatile__ ("wfi"); */ } #endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h index bcb4d9ba7..b4f8ff0a0 100644 --- a/include/grub/at_keyboard.h +++ b/include/grub/at_keyboard.h @@ -23,11 +23,13 @@ #define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) #define KEYBOARD_COMMAND_READ 0x20 #define KEYBOARD_COMMAND_WRITE 0x60 -#define KEYBOARD_COMMAND_ENABLE 0xf4 #define KEYBOARD_COMMAND_REBOOT 0xfe #define KEYBOARD_AT_TRANSLATE 0x40 -#define KEYBOARD_AT_DISABLE 0x10 + +#define GRUB_AT_ACK 0xfa +#define GRUB_AT_NACK 0xfe +#define GRUB_AT_TRIES 5 #define KEYBOARD_ISMAKE(x) !((x) & 0x80) #define KEYBOARD_ISREADY(x) ((x) & 0x01) diff --git a/include/grub/autoefi.h b/include/grub/autoefi.h index b7a252e07..b75591176 100644 --- a/include/grub/autoefi.h +++ b/include/grub/autoefi.h @@ -55,7 +55,7 @@ static inline grub_err_t grub_autoefi_prepare (void) # define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR # define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN # define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE -# define grub_efi_allocate_fixed(x,y) (x) +# define grub_efi_allocate_pages(x,y) (x) # define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS # define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services # define EFI_PRESENT 1 diff --git a/include/grub/bufio.h b/include/grub/bufio.h index 0ff72d103..acdd0c882 100644 --- a/include/grub/bufio.h +++ b/include/grub/bufio.h @@ -22,9 +22,7 @@ #include -grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, grub_size_t size); -grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, - enum grub_file_type type, - grub_size_t size); +grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, int size); +grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, int size); #endif /* ! GRUB_BUFIO_H */ diff --git a/include/grub/cache.h b/include/grub/cache.h index 7aa8d7933..a9b3f529c 100644 --- a/include/grub/cache.h +++ b/include/grub/cache.h @@ -34,17 +34,14 @@ void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len); #endif #ifndef GRUB_MACHINE_EMU -#if defined (__aarch64__) || defined (__ia64__) || defined (__powerpc__) || \ - defined (__sparc__) - -#elif defined (__i386__) || defined (__x86_64__) +#ifdef _mips +void EXPORT_FUNC(grub_arch_sync_dma_caches) (void *address, grub_size_t len); +#else static inline void -grub_arch_sync_dma_caches (volatile void *address __attribute__ ((unused)), +grub_arch_sync_dma_caches (void *address __attribute__ ((unused)), grub_size_t len __attribute__ ((unused))) { } -#else -void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address, grub_size_t len); #endif #endif diff --git a/include/grub/compiler-rt-emu.h b/include/grub/compiler-rt-emu.h deleted file mode 100644 index fde620ac1..000000000 --- a/include/grub/compiler-rt-emu.h +++ /dev/null @@ -1,265 +0,0 @@ -/* compiler-rt-emu.h - prototypes for compiler helpers. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010-2014 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_COMPILER_RT_HEADER -#define GRUB_COMPILER_RT_HEADER 1 - -#include -#include -#include - -#ifdef HAVE___UDIVSI3 -grub_uint32_t -EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b); -#endif - -#ifdef HAVE___UMODSI3 -grub_uint32_t -EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b); -#endif - -#ifdef HAVE___DIVSI3 -grub_int32_t -EXPORT_FUNC (__divsi3) (grub_int32_t a, grub_int32_t b); -#endif - -#ifdef HAVE___MODSI3 -grub_int32_t -EXPORT_FUNC (__modsi3) (grub_int32_t a, grub_int32_t b); -#endif - -#ifdef HAVE___DIVDI3 -grub_int64_t -EXPORT_FUNC (__divdi3) (grub_int64_t a, grub_int64_t b); -#endif - -#ifdef HAVE___MODDI3 -grub_int64_t -EXPORT_FUNC (__moddi3) (grub_int64_t a, grub_int64_t b); -#endif - -#ifdef HAVE___UDIVDI3 -grub_uint64_t -EXPORT_FUNC (__udivdi3) (grub_uint64_t a, grub_uint64_t b); -#endif - -#ifdef HAVE___UMODDI3 -grub_uint64_t -EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b); -#endif - -#ifdef HAVE___CTZDI2 -unsigned -EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); -#endif - -#ifdef HAVE___CTZSI2 -unsigned -EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); -#endif - -#ifdef HAVE___CLZDI2 -int -EXPORT_FUNC (__clzdi2) (grub_uint64_t x); -#endif - -#ifdef HAVE___AEABI_UIDIV -grub_uint32_t -EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); -#endif - -#ifdef HAVE___AEABI_UIDIVMOD -grub_uint32_t -EXPORT_FUNC (__aeabi_uidivmod) (grub_uint32_t a, grub_uint32_t b); -#endif - -#ifdef HAVE___AEABI_IDIV -grub_int32_t -EXPORT_FUNC (__aeabi_idiv) (grub_int32_t a, grub_int32_t b); -#endif - -#ifdef HAVE___AEABI_IDIVMOD -grub_int32_t -EXPORT_FUNC (__aeabi_idivmod) (grub_int32_t a, grub_int32_t b); -#endif - -#ifdef HAVE___AEABI_ULCMP -int -EXPORT_FUNC (__aeabi_ulcmp) (grub_uint64_t a, grub_uint64_t b); -#endif - -/* Needed for allowing modules to be compiled as thumb. */ -#ifdef HAVE___MULDI3 -grub_uint64_t -EXPORT_FUNC (__muldi3) (grub_uint64_t a, grub_uint64_t b); -#endif - -#ifdef HAVE___AEABI_LMUL -grub_uint64_t -EXPORT_FUNC (__aeabi_lmul) (grub_uint64_t a, grub_uint64_t b); -#endif - -#ifdef HAVE___AEABI_MEMCPY -void * -EXPORT_FUNC (__aeabi_memcpy) (void *dest, const void *src, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMCPY4 -void * -EXPORT_FUNC (__aeabi_memcpy4) (void *dest, const void *src, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMCPY8 -void * -EXPORT_FUNC (__aeabi_memcpy8) (void *dest, const void *src, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMSET -void * -EXPORT_FUNC(__aeabi_memset) (void *s, int c, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMCLR -void * -EXPORT_FUNC(__aeabi_memclr) (void *s, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMCLR4 -void * -EXPORT_FUNC(__aeabi_memclr4) (void *s, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_MEMCLR8 -void * -EXPORT_FUNC(__aeabi_memclr8) (void *s, grub_size_t n); -#endif - -#ifdef HAVE___AEABI_LASR -grub_uint64_t -EXPORT_FUNC (__aeabi_lasr) (grub_uint64_t u, int b); -#endif - -#ifdef HAVE___AEABI_LLSL -grub_uint64_t -EXPORT_FUNC (__aeabi_llsl) (grub_uint64_t u, int b); -#endif - -#ifdef HAVE___AEABI_LLSR -grub_uint64_t -EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b); -#endif - - -#ifdef HAVE__RESTGPR_14_X - -void EXPORT_FUNC (_restgpr_14_x) (void); -void EXPORT_FUNC (_restgpr_15_x) (void); -void EXPORT_FUNC (_restgpr_16_x) (void); -void EXPORT_FUNC (_restgpr_17_x) (void); -void EXPORT_FUNC (_restgpr_18_x) (void); -void EXPORT_FUNC (_restgpr_19_x) (void); -void EXPORT_FUNC (_restgpr_20_x) (void); -void EXPORT_FUNC (_restgpr_21_x) (void); -void EXPORT_FUNC (_restgpr_22_x) (void); -void EXPORT_FUNC (_restgpr_23_x) (void); -void EXPORT_FUNC (_restgpr_24_x) (void); -void EXPORT_FUNC (_restgpr_25_x) (void); -void EXPORT_FUNC (_restgpr_26_x) (void); -void EXPORT_FUNC (_restgpr_27_x) (void); -void EXPORT_FUNC (_restgpr_28_x) (void); -void EXPORT_FUNC (_restgpr_29_x) (void); -void EXPORT_FUNC (_restgpr_30_x) (void); -void EXPORT_FUNC (_restgpr_31_x) (void); -void EXPORT_FUNC (_savegpr_14) (void); -void EXPORT_FUNC (_savegpr_15) (void); -void EXPORT_FUNC (_savegpr_16) (void); -void EXPORT_FUNC (_savegpr_17) (void); -void EXPORT_FUNC (_savegpr_18) (void); -void EXPORT_FUNC (_savegpr_19) (void); -void EXPORT_FUNC (_savegpr_20) (void); -void EXPORT_FUNC (_savegpr_21) (void); -void EXPORT_FUNC (_savegpr_22) (void); -void EXPORT_FUNC (_savegpr_23) (void); -void EXPORT_FUNC (_savegpr_24) (void); -void EXPORT_FUNC (_savegpr_25) (void); -void EXPORT_FUNC (_savegpr_26) (void); -void EXPORT_FUNC (_savegpr_27) (void); -void EXPORT_FUNC (_savegpr_28) (void); -void EXPORT_FUNC (_savegpr_29) (void); -void EXPORT_FUNC (_savegpr_30) (void); -void EXPORT_FUNC (_savegpr_31) (void); - -#endif - -#ifdef HAVE___UCMPDI2 -int -EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b); -#endif - -#ifdef HAVE___ASHLDI3 -grub_uint64_t -EXPORT_FUNC(__ashldi3) (grub_uint64_t u, int b); -#endif - -#ifdef HAVE___ASHRDI3 -grub_uint64_t -EXPORT_FUNC(__ashrdi3) (grub_uint64_t u, int b); -#endif - -#ifdef HAVE___LSHRDI3 -grub_uint64_t -EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b); -#endif - -#ifdef HAVE___BSWAPSI2 -grub_uint32_t -EXPORT_FUNC(__bswapsi2) (grub_uint32_t u); -#endif - -#ifdef HAVE___BSWAPDI2 -grub_uint64_t -EXPORT_FUNC(__bswapdi2) (grub_uint64_t u); -#endif - -int EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n); -void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n); -void *EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n); -void *EXPORT_FUNC(memset) (void *s, int c, grub_size_t n); - -#ifdef HAVE___BZERO -void EXPORT_FUNC (__bzero) (void *s, grub_size_t n); -#endif - -#ifdef HAVE___REGISTER_FRAME_INFO -void EXPORT_FUNC (__register_frame_info) (void); -#endif - -#ifdef HAVE___DEREGISTER_FRAME_INFO -void EXPORT_FUNC (__deregister_frame_info) (void); -#endif -#ifdef HAVE____CHKSTK_MS -void EXPORT_FUNC (___chkstk_ms) (void); -#endif - -#ifdef HAVE___CHKSTK_MS -void EXPORT_FUNC (__chkstk_ms) (void); -#endif - -#endif - diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h deleted file mode 100644 index 7591980b4..000000000 --- a/include/grub/compiler-rt.h +++ /dev/null @@ -1,213 +0,0 @@ -/* compiler-rt.h - prototypes for compiler helpers. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010-2014 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_COMPILER_RT_HEADER -#define GRUB_COMPILER_RT_HEADER 1 - -#include -#include -#include -#include - -#if defined(GRUB_DIVISION_IN_SOFTWARE) && GRUB_DIVISION_IN_SOFTWARE - -grub_uint32_t -EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b); - -grub_uint32_t -EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b); - -grub_int32_t -EXPORT_FUNC (__divsi3) (grub_int32_t a, grub_int32_t b); - -grub_int32_t -EXPORT_FUNC (__modsi3) (grub_int32_t a, grub_int32_t b); - -grub_int64_t -EXPORT_FUNC (__divdi3) (grub_int64_t a, grub_int64_t b); - -grub_int64_t -EXPORT_FUNC (__moddi3) (grub_int64_t a, grub_int64_t b); - -grub_uint64_t -EXPORT_FUNC (__udivdi3) (grub_uint64_t a, grub_uint64_t b); - -grub_uint64_t -EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b); - -#endif - -#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || \ - defined (__arm__) || defined(__riscv) -unsigned -EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); -#define NEED_CTZDI2 1 -#endif - -#if defined (__mips__) || defined (__arm__) || \ - (defined(__riscv) && (__riscv_xlen == 32)) -unsigned -EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); -#define NEED_CTZSI2 1 -#endif - -#ifdef __arm__ -grub_uint32_t -EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); -grub_uint32_t -EXPORT_FUNC (__aeabi_uidivmod) (grub_uint32_t a, grub_uint32_t b); - -grub_int32_t -EXPORT_FUNC (__aeabi_idiv) (grub_int32_t a, grub_int32_t b); -grub_int32_t -EXPORT_FUNC (__aeabi_idivmod) (grub_int32_t a, grub_int32_t b); - -int -EXPORT_FUNC (__aeabi_ulcmp) (grub_uint64_t a, grub_uint64_t b); - -/* Needed for allowing modules to be compiled as thumb. */ -grub_uint64_t -EXPORT_FUNC (__muldi3) (grub_uint64_t a, grub_uint64_t b); -grub_uint64_t -EXPORT_FUNC (__aeabi_lmul) (grub_uint64_t a, grub_uint64_t b); - -void * -EXPORT_FUNC (__aeabi_memcpy) (void *dest, const void *src, grub_size_t n); -void * -EXPORT_FUNC (__aeabi_memcpy4) (void *dest, const void *src, grub_size_t n); -void * -EXPORT_FUNC (__aeabi_memcpy8) (void *dest, const void *src, grub_size_t n); -void * -EXPORT_FUNC(__aeabi_memset) (void *s, int c, grub_size_t n); -void EXPORT_FUNC(__aeabi_memclr) (void *s, grub_size_t n); -void EXPORT_FUNC(__aeabi_memclr4) (void *s, grub_size_t n); -void EXPORT_FUNC(__aeabi_memclr8) (void *s, grub_size_t n); - -grub_uint64_t -EXPORT_FUNC (__aeabi_lasr) (grub_uint64_t u, int b); - -grub_uint64_t -EXPORT_FUNC (__aeabi_llsl) (grub_uint64_t u, int b); - -grub_uint64_t -EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b); - -#endif - -#if defined(__mips__) || defined(__riscv) || defined(__sparc__) -int -EXPORT_FUNC (__clzsi2) (grub_uint32_t val); -#endif - -#if defined(__riscv) || defined(__sparc__) -int -EXPORT_FUNC (__clzdi2) (grub_uint64_t val); -#endif - -#if defined (__powerpc__) - -void EXPORT_FUNC (_restgpr_14_x) (void); -void EXPORT_FUNC (_restgpr_15_x) (void); -void EXPORT_FUNC (_restgpr_16_x) (void); -void EXPORT_FUNC (_restgpr_17_x) (void); -void EXPORT_FUNC (_restgpr_18_x) (void); -void EXPORT_FUNC (_restgpr_19_x) (void); -void EXPORT_FUNC (_restgpr_20_x) (void); -void EXPORT_FUNC (_restgpr_21_x) (void); -void EXPORT_FUNC (_restgpr_22_x) (void); -void EXPORT_FUNC (_restgpr_23_x) (void); -void EXPORT_FUNC (_restgpr_24_x) (void); -void EXPORT_FUNC (_restgpr_25_x) (void); -void EXPORT_FUNC (_restgpr_26_x) (void); -void EXPORT_FUNC (_restgpr_27_x) (void); -void EXPORT_FUNC (_restgpr_28_x) (void); -void EXPORT_FUNC (_restgpr_29_x) (void); -void EXPORT_FUNC (_restgpr_30_x) (void); -void EXPORT_FUNC (_restgpr_31_x) (void); -void EXPORT_FUNC (_savegpr_14) (void); -void EXPORT_FUNC (_savegpr_15) (void); -void EXPORT_FUNC (_savegpr_16) (void); -void EXPORT_FUNC (_savegpr_17) (void); -void EXPORT_FUNC (_savegpr_18) (void); -void EXPORT_FUNC (_savegpr_19) (void); -void EXPORT_FUNC (_savegpr_20) (void); -void EXPORT_FUNC (_savegpr_21) (void); -void EXPORT_FUNC (_savegpr_22) (void); -void EXPORT_FUNC (_savegpr_23) (void); -void EXPORT_FUNC (_savegpr_24) (void); -void EXPORT_FUNC (_savegpr_25) (void); -void EXPORT_FUNC (_savegpr_26) (void); -void EXPORT_FUNC (_savegpr_27) (void); -void EXPORT_FUNC (_savegpr_28) (void); -void EXPORT_FUNC (_savegpr_29) (void); -void EXPORT_FUNC (_savegpr_30) (void); -void EXPORT_FUNC (_savegpr_31) (void); - -#endif - -#if defined (__powerpc__) || defined(__mips__) || defined (__arm__) || \ - (defined(__riscv) && (__riscv_xlen == 32)) - -int -EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b); - -grub_uint64_t -EXPORT_FUNC(__ashldi3) (grub_uint64_t u, int b); - -grub_uint64_t -EXPORT_FUNC(__ashrdi3) (grub_uint64_t u, int b); - -grub_uint64_t -EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b); -#endif - -#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \ - defined (__arm__) || defined(__riscv) -grub_uint32_t -EXPORT_FUNC(__bswapsi2) (grub_uint32_t u); - -grub_uint64_t -EXPORT_FUNC(__bswapdi2) (grub_uint64_t u); -#endif - -#if defined (__APPLE__) && defined(__i386__) -#define GRUB_BUILTIN_ATTR __attribute__ ((regparm(0))) -#else -#define GRUB_BUILTIN_ATTR -#endif - -/* Prototypes for aliases. */ -int GRUB_BUILTIN_ATTR EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n); -void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n); -void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n); -void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memset) (void *s, int c, grub_size_t n); - -#ifdef __APPLE__ -void GRUB_BUILTIN_ATTR EXPORT_FUNC (__bzero) (void *s, grub_size_t n); -#endif - -#if defined (__MINGW32__) || defined (__CYGWIN__) -void EXPORT_FUNC (__register_frame_info) (void); -void EXPORT_FUNC (__deregister_frame_info) (void); -void EXPORT_FUNC (___chkstk_ms) (void); -void EXPORT_FUNC (__chkstk_ms) (void); -#endif - -#endif - diff --git a/include/grub/compiler.h b/include/grub/compiler.h index 8f3be3ae7..c9e1d7a73 100644 --- a/include/grub/compiler.h +++ b/include/grub/compiler.h @@ -48,12 +48,4 @@ # define WARN_UNUSED_RESULT #endif -#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) -# define CLANG_PREREQ(maj,min) \ - ((__clang_major__ > (maj)) || \ - (__clang_major__ == (maj) && __clang_minor__ >= (min))) -#else -# define CLANG_PREREQ(maj,min) 0 -#endif - #endif /* ! GRUB_COMPILER_HEADER */ diff --git a/include/grub/crypto.h b/include/grub/crypto.h index 21cd1f75a..a24e89dd9 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -56,6 +56,7 @@ typedef enum GPG_ERR_NOT_FOUND, GPG_ERR_NOT_IMPLEMENTED, GPG_ERR_NOT_SUPPORTED, + GPG_ERROR_CFLAGS, GPG_ERR_PUBKEY_ALGO, GPG_ERR_SELFTEST_FAILED, GPG_ERR_TOO_SHORT, diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index e1b21e785..f2ad2a79a 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -97,7 +97,6 @@ struct grub_cryptodisk grub_uint8_t rekey_key[64]; grub_uint64_t last_rekey; int rekey_derived_size; - grub_disk_addr_t partition_start; }; typedef struct grub_cryptodisk *grub_cryptodisk_t; @@ -130,9 +129,6 @@ grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr) #define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list)) -grub_err_t -grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, const char *ciphermode); - gcry_err_code_t grub_cryptodisk_setkey (grub_cryptodisk_t dev, grub_uint8_t *key, grub_size_t keysize); diff --git a/include/grub/disk.h b/include/grub/disk.h index 132a1bb75..b385af826 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -49,7 +49,6 @@ enum grub_disk_dev_id GRUB_DISK_DEVICE_CBFSDISK_ID, GRUB_DISK_DEVICE_UBOOTDISK_ID, GRUB_DISK_DEVICE_XEN, - GRUB_DISK_DEVICE_OBDISK_ID, }; struct grub_disk; @@ -77,26 +76,26 @@ struct grub_disk_dev enum grub_disk_dev_id id; /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*disk_iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data, + int (*iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data, grub_disk_pull_t pull); /* Open the device named NAME, and set up DISK. */ - grub_err_t (*disk_open) (const char *name, struct grub_disk *disk); + grub_err_t (*open) (const char *name, struct grub_disk *disk); /* Close the disk DISK. */ - void (*disk_close) (struct grub_disk *disk); + void (*close) (struct grub_disk *disk); /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */ - grub_err_t (*disk_read) (struct grub_disk *disk, grub_disk_addr_t sector, + grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector, grub_size_t size, char *buf); /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */ - grub_err_t (*disk_write) (struct grub_disk *disk, grub_disk_addr_t sector, + grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector, grub_size_t size, const char *buf); #ifdef GRUB_UTIL - struct grub_disk_memberlist *(*disk_memberlist) (struct grub_disk *disk); - const char * (*disk_raidname) (struct grub_disk *disk); + struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk); + const char * (*raidname) (struct grub_disk *disk); #endif /* The next disk device. */ @@ -174,13 +173,6 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t; /* Return value of grub_disk_get_size() in case disk size is unknown. */ #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL -/* Convert to GRUB native disk sized sector from disk sized sector. */ -static inline grub_disk_addr_t -grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector) -{ - return sector << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); -} - /* This is called from the memory manager. */ void grub_disk_cache_invalidate_all (void); @@ -194,7 +186,7 @@ grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data) for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) for (p = grub_disk_dev_list; p; p = p->next) - if (p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull)) + if (p->iterate && (p->iterate) (hook, hook_data, pull)) return 1; return 0; diff --git a/include/grub/diskfilter.h b/include/grub/diskfilter.h index 8deb1a8c3..1aedcd3df 100644 --- a/include/grub/diskfilter.h +++ b/include/grub/diskfilter.h @@ -172,7 +172,7 @@ grub_diskfilter_unregister (grub_diskfilter_t diskfilter) struct grub_diskfilter_vg * grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, - const char *name, grub_uint64_t disk_size, + char *name, grub_uint64_t disk_size, grub_uint64_t stripe_size, int layout, int level); @@ -189,15 +189,6 @@ typedef grub_err_t (*grub_raid6_recover_func_t) (struct grub_diskfilter_segment extern grub_raid5_recover_func_t grub_raid5_recover_func; extern grub_raid6_recover_func_t grub_raid6_recover_func; -typedef grub_err_t (* raid_recover_read_t)(void *data, int disk_nr, - grub_uint64_t addr, void *dest, - grub_size_t size); - -extern grub_err_t -grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p, - char *buf, grub_uint64_t sector, grub_size_t size, - int layout, raid_recover_read_t read_func); - grub_err_t grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg); grub_err_t diff --git a/include/grub/dl.h b/include/grub/dl.h index f03c03561..9562fa663 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -175,7 +175,6 @@ struct grub_dl { char *name; int ref_count; - int persistent; grub_dl_dep_t dep; grub_dl_segment_t segment; Elf_Sym *symtab; @@ -241,18 +240,6 @@ grub_dl_get (const char *name) return 0; } -static inline void -grub_dl_set_persistent (grub_dl_t mod) -{ - mod->persistent = 1; -} - -static inline int -grub_dl_is_persistent (grub_dl_t mod) -{ - return mod->persistent; -} - #endif grub_err_t grub_dl_register_symbol (const char *name, void *addr, @@ -276,30 +263,23 @@ void grub_arch_dl_init_linker (void); grub_err_t grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got); -grub_err_t -grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, - grub_size_t *got); #if defined (__ia64__) #define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN #define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN #define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size -#elif defined (__aarch64__) -#define grub_arch_dl_get_tramp_got_size grub_arm64_dl_get_tramp_got_size #else grub_err_t grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got); #endif -#if defined (__powerpc__) || defined (__mips__) || defined (__arm__) || \ - (defined(__riscv) && (__riscv_xlen == 32)) +#if defined (__powerpc__) || defined (__mips__) || defined (__arm__) #define GRUB_ARCH_DL_TRAMP_ALIGN 4 #define GRUB_ARCH_DL_GOT_ALIGN 4 #endif -#if defined (__aarch64__) || defined (__sparc__) || \ - (defined(__riscv) && (__riscv_xlen == 64)) +#if defined (__aarch64__) || defined (__sparc__) #define GRUB_ARCH_DL_TRAMP_ALIGN 8 #define GRUB_ARCH_DL_GOT_ALIGN 8 #endif diff --git a/include/grub/dma.h b/include/grub/dma.h deleted file mode 100644 index 19992ebc1..000000000 --- a/include/grub/dma.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_DMA_H -#define GRUB_DMA_H 1 - -struct grub_pci_dma_chunk; - -struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align, - grub_size_t size); -void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch); -volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch); -grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch); - -static inline void * -grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk) -{ - return ((grub_uint8_t *) grub_dma_get_virt (chunk) - + (phys - grub_dma_get_phys (chunk))); -} - -static inline grub_uint32_t -grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk) -{ - return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk)) - + grub_dma_get_phys (chunk)); -} - -#endif diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 1dcaa12f5..e5dd543a8 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -49,9 +49,6 @@ #define GRUB_EFI_MEMORY_WP 0x0000000000001000LL #define GRUB_EFI_MEMORY_RP 0x0000000000002000LL #define GRUB_EFI_MEMORY_XP 0x0000000000004000LL -#define GRUB_EFI_MEMORY_NV 0x0000000000008000LL -#define GRUB_EFI_MEMORY_MORE_RELIABLE 0x0000000000010000LL -#define GRUB_EFI_MEMORY_RO 0x0000000000020000LL #define GRUB_EFI_MEMORY_RUNTIME 0x8000000000000000LL #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001 @@ -114,7 +111,7 @@ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } -#define GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \ +#define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \ { 0xdd9e7534, 0x7762, 0x4698, \ { 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa } \ } @@ -249,51 +246,6 @@ { 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } \ } -#define GRUB_EFI_TIANO_CUSTOM_DECOMPRESS_GUID \ - { 0xa31280ad, 0x481e, 0x41b6, \ - { 0x95, 0xe8, 0x12, 0x7f, 0x4c, 0x98, 0x47, 0x79 } \ - } - -#define GRUB_EFI_CRC32_GUIDED_SECTION_EXTRACTION_GUID \ - { 0xfc1bcdb0, 0x7d31, 0x49aa, \ - { 0x93, 0x6a, 0xa4, 0x60, 0x0d, 0x9d, 0xd0, 0x83 } \ - } - -#define GRUB_EFI_LZMA_CUSTOM_DECOMPRESS_GUID \ - { 0xee4e5898, 0x3914, 0x4259, \ - { 0x9d, 0x6e, 0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf } \ - } - -#define GRUB_EFI_TSC_FREQUENCY_GUID \ - { 0xdba6a7e3, 0xbb57, 0x4be7, \ - { 0x8a, 0xf8, 0xd5, 0x78, 0xdb, 0x7e, 0x56, 0x87 } \ - } - -#define GRUB_EFI_SYSTEM_RESOURCE_TABLE_GUID \ - { 0xb122a263, 0x3661, 0x4f68, \ - { 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 } \ - } - -#define GRUB_EFI_DXE_SERVICES_TABLE_GUID \ - { 0x05ad34ba, 0x6f02, 0x4214, \ - { 0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9 } \ - } - -#define GRUB_EFI_HOB_LIST_GUID \ - { 0x7739f24c, 0x93d7, 0x11d4, \ - { 0x9a, 0x3a, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ - } - -#define GRUB_EFI_MEMORY_TYPE_INFORMATION_GUID \ - { 0x4c19049f, 0x4137, 0x4dd3, \ - { 0x9c, 0x10, 0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa } \ - } - -#define GRUB_EFI_DEBUG_IMAGE_INFO_TABLE_GUID \ - { 0x49152e77, 0x1ada, 0x4764, \ - { 0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b } \ - } - #define GRUB_EFI_MPS_TABLE_GUID \ { 0xeb9d2d2f, 0x2d88, 0x11d3, \ { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ @@ -314,11 +266,6 @@ { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ } -#define GRUB_EFI_SMBIOS3_TABLE_GUID \ - { 0xf2fd1544, 0x9794, 0x4a2c, \ - { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } \ - } - #define GRUB_EFI_SAL_TABLE_GUID \ { 0xeb9d2d32, 0x2d88, 0x11d3, \ { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ @@ -484,7 +431,6 @@ enum grub_efi_memory_type GRUB_EFI_MEMORY_MAPPED_IO, GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE, GRUB_EFI_PAL_CODE, - GRUB_EFI_PERSISTENT_MEMORY, GRUB_EFI_MAX_MEMORY_TYPE }; typedef enum grub_efi_memory_type grub_efi_memory_type_t; @@ -531,7 +477,7 @@ typedef grub_uint64_t grub_efi_uint64_t; typedef grub_uint8_t grub_efi_char8_t; typedef grub_uint16_t grub_efi_char16_t; -typedef grub_efi_uintn_t grub_efi_status_t; +typedef grub_efi_intn_t grub_efi_status_t; #define GRUB_EFI_ERROR_CODE(value) \ ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value)) @@ -630,7 +576,6 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; #define GRUB_EFI_DEVICE_PATH_TYPE(dp) ((dp)->type & 0x7f) #define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) ((dp)->subtype) #define GRUB_EFI_DEVICE_PATH_LENGTH(dp) ((dp)->length) -#define GRUB_EFI_DEVICE_PATH_VALID(dp) ((dp) != NULL && GRUB_EFI_DEVICE_PATH_LENGTH (dp) >= 4) /* The End of Device Path nodes. */ #define GRUB_EFI_END_DEVICE_PATH_TYPE (0xff & 0x7f) @@ -639,16 +584,13 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; #define GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE 0x01 #define GRUB_EFI_END_ENTIRE_DEVICE_PATH(dp) \ - (!GRUB_EFI_DEVICE_PATH_VALID (dp) || \ - (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ - && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ - == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE))) + (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ + && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ + == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)) #define GRUB_EFI_NEXT_DEVICE_PATH(dp) \ - (GRUB_EFI_DEVICE_PATH_VALID (dp) \ - ? ((grub_efi_device_path_t *) \ - ((char *) (dp) + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) \ - : NULL) + ((grub_efi_device_path_t *) ((char *) (dp) \ + + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) /* Hardware Device Path. */ #define GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE 1 @@ -1010,32 +952,6 @@ struct grub_efi_input_key }; typedef struct grub_efi_input_key grub_efi_input_key_t; -typedef grub_efi_uint8_t grub_efi_key_toggle_state_t; -struct grub_efi_key_state -{ - grub_efi_uint32_t key_shift_state; - grub_efi_key_toggle_state_t key_toggle_state; -}; -typedef struct grub_efi_key_state grub_efi_key_state_t; - -#define GRUB_EFI_SHIFT_STATE_VALID 0x80000000 -#define GRUB_EFI_RIGHT_SHIFT_PRESSED 0x00000001 -#define GRUB_EFI_LEFT_SHIFT_PRESSED 0x00000002 -#define GRUB_EFI_RIGHT_CONTROL_PRESSED 0x00000004 -#define GRUB_EFI_LEFT_CONTROL_PRESSED 0x00000008 -#define GRUB_EFI_RIGHT_ALT_PRESSED 0x00000010 -#define GRUB_EFI_LEFT_ALT_PRESSED 0x00000020 -#define GRUB_EFI_RIGHT_LOGO_PRESSED 0x00000040 -#define GRUB_EFI_LEFT_LOGO_PRESSED 0x00000080 -#define GRUB_EFI_MENU_KEY_PRESSED 0x00000100 -#define GRUB_EFI_SYS_REQ_PRESSED 0x00000200 - -#define GRUB_EFI_TOGGLE_STATE_VALID 0x80 -#define GRUB_EFI_KEY_STATE_EXPOSED 0x40 -#define GRUB_EFI_SCROLL_LOCK_ACTIVE 0x01 -#define GRUB_EFI_NUM_LOCK_ACTIVE 0x02 -#define GRUB_EFI_CAPS_LOCK_ACTIVE 0x04 - struct grub_efi_simple_text_output_mode { grub_efi_int32_t max_mode; @@ -1299,7 +1215,7 @@ struct grub_efi_runtime_services (*convert_pointer) (grub_efi_uintn_t debug_disposition, void **address); #define GRUB_EFI_GLOBAL_VARIABLE_GUID \ - { 0x8BE4DF61, 0x93CA, 0x11d2, { 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C }} + { 0x8BE4DF61, 0x93CA, 0x11d2, { 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B,0x8C }} grub_efi_status_t @@ -1378,43 +1294,6 @@ struct grub_efi_simple_input_interface }; typedef struct grub_efi_simple_input_interface grub_efi_simple_input_interface_t; -struct grub_efi_key_data { - grub_efi_input_key_t key; - grub_efi_key_state_t key_state; -}; -typedef struct grub_efi_key_data grub_efi_key_data_t; - -typedef grub_efi_status_t (*grub_efi_key_notify_function_t) ( - grub_efi_key_data_t *key_data - ); - -struct grub_efi_simple_text_input_ex_interface -{ - grub_efi_status_t - (*reset) (struct grub_efi_simple_text_input_ex_interface *this, - grub_efi_boolean_t extended_verification); - - grub_efi_status_t - (*read_key_stroke) (struct grub_efi_simple_text_input_ex_interface *this, - grub_efi_key_data_t *key_data); - - grub_efi_event_t wait_for_key; - - grub_efi_status_t - (*set_state) (struct grub_efi_simple_text_input_ex_interface *this, - grub_efi_key_toggle_state_t *key_toggle_state); - - grub_efi_status_t - (*register_key_notify) (struct grub_efi_simple_text_input_ex_interface *this, - grub_efi_key_data_t *key_data, - grub_efi_key_notify_function_t key_notification_function); - - grub_efi_status_t - (*unregister_key_notify) (struct grub_efi_simple_text_input_ex_interface *this, - void *notification_handle); -}; -typedef struct grub_efi_simple_text_input_ex_interface grub_efi_simple_text_input_ex_interface_t; - struct grub_efi_simple_text_output_interface { grub_efi_status_t @@ -1622,31 +1501,17 @@ enum GRUB_EFI_NETWORK_INITIALIZED, }; -enum - { - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST = 0x01, - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST = 0x02, - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST = 0x04, - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS = 0x08, - GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST = 0x10, - }; - struct grub_efi_simple_network { grub_uint64_t revision; grub_efi_status_t (*start) (struct grub_efi_simple_network *this); - grub_efi_status_t (*stop) (struct grub_efi_simple_network *this); + void (*stop) (void); grub_efi_status_t (*initialize) (struct grub_efi_simple_network *this, grub_efi_uintn_t extra_rx, grub_efi_uintn_t extra_tx); void (*reset) (void); - grub_efi_status_t (*shutdown) (struct grub_efi_simple_network *this); - grub_efi_status_t (*receive_filters) (struct grub_efi_simple_network *this, - grub_uint32_t enable, - grub_uint32_t disable, - grub_efi_boolean_t reset_mcast_filter, - grub_efi_uintn_t mcast_filter_count, - grub_efi_mac_address_t *mcast_filter); + void (*shutdown) (void); + void (*receive_filters) (void); void (*station_address) (void); void (*statistics) (void); void (*mcastiptomac) (void); @@ -1695,8 +1560,7 @@ struct grub_efi_block_io typedef struct grub_efi_block_io grub_efi_block_io_t; #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ - || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ - || defined(__riscv) + || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) #define efi_call_0(func) func() #define efi_call_1(func, a) func(a) diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e90e00dc4..489cf9e6d 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -38,34 +38,21 @@ void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle, int EXPORT_FUNC(grub_efi_set_text_mode) (int on); void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds); void * -EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address, - grub_efi_uintn_t pages, - grub_efi_allocate_type_t alloctype, - grub_efi_memory_type_t memtype); -void * -EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, +EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); -void * -EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); -grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); int EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_memory_descriptor_t *memory_map, grub_efi_uintn_t *map_key, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version); -void grub_efi_memory_fini (void); grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle); void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp); char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp); grub_efi_device_path_t * EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle); -grub_efi_device_path_t * -EXPORT_FUNC(grub_efi_find_last_device_path) (const grub_efi_device_path_t *dp); -grub_efi_device_path_t * -EXPORT_FUNC(grub_efi_duplicate_device_path) (const grub_efi_device_path_t *dp); grub_err_t EXPORT_FUNC (grub_efi_finish_boot_services) (grub_efi_uintn_t *outbuf_size, void *outbuf, grub_efi_uintn_t *map_key, grub_efi_uintn_t *efi_desc_size, @@ -90,15 +77,6 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, char **device, char **path); -#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) -void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); -grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); -#include -grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); -grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, - char *args); -#endif - grub_addr_t grub_efi_modules_addr (void); void grub_efi_mm_init (void); diff --git a/include/grub/efi/graphics_output.h b/include/grub/efi/graphics_output.h index e4388127c..129777411 100644 --- a/include/grub/efi/graphics_output.h +++ b/include/grub/efi/graphics_output.h @@ -28,8 +28,7 @@ typedef enum { GRUB_EFI_GOT_RGBA8, GRUB_EFI_GOT_BGRA8, - GRUB_EFI_GOT_BITMASK, - GRUB_EFI_GOT_BLT_ONLY, + GRUB_EFI_GOT_BITMASK } grub_efi_gop_pixel_format_t; diff --git a/include/grub/efi/memory.h b/include/grub/efi/memory.h index 08fe62277..20526b146 100644 --- a/include/grub/efi/memory.h +++ b/include/grub/efi/memory.h @@ -22,13 +22,6 @@ #include #include -/* The term "page" in UEFI refers only to a 4 KiB-aligned 4 KiB size region of - memory. It is not concerned with underlying translation management concepts, - but only used as the granule for memory allocations. */ -#define GRUB_EFI_PAGE_SHIFT 12 -#define GRUB_EFI_PAGE_SIZE (1 << GRUB_EFI_PAGE_SHIFT) -#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT) - #define GRUB_MMAP_REGISTER_BY_FIRMWARE 1 grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size, diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h index 0ed8781f0..f79c36c02 100644 --- a/include/grub/efi/pe32.h +++ b/include/grub/efi/pe32.h @@ -20,7 +20,6 @@ #define GRUB_EFI_PE32_HEADER 1 #include -#include /* The MSDOS compatibility stub. This was copied from the output of objcopy, and it is not necessary to care about what this means. */ @@ -46,19 +45,11 @@ #define GRUB_PE32_MSDOS_STUB_SIZE 0x80 -#define GRUB_PE32_MAGIC 0x5a4d - /* According to the spec, the minimal alignment is 512 bytes... But some examples (such as EFI drivers in the Intel Sample Implementation) use 32 bytes (0x20) instead, and it seems - to be working. - - However, there is firmware showing up in the field now with - page alignment constraints to guarantee that page protection - bits take effect. Because currently existing GRUB code can not - properly distinguish between in-memory and in-file layout, let's - bump all alignment to GRUB_EFI_PAGE_SIZE. */ -#define GRUB_PE32_SECTION_ALIGNMENT GRUB_EFI_PAGE_SIZE + to be working. For now, GRUB uses 512 bytes for safety. */ +#define GRUB_PE32_SECTION_ALIGNMENT 0x200 #define GRUB_PE32_FILE_ALIGNMENT GRUB_PE32_SECTION_ALIGNMENT struct grub_pe32_coff_header @@ -77,8 +68,6 @@ struct grub_pe32_coff_header #define GRUB_PE32_MACHINE_X86_64 0x8664 #define GRUB_PE32_MACHINE_ARMTHUMB_MIXED 0x01c2 #define GRUB_PE32_MACHINE_ARM64 0xAA64 -#define GRUB_PE32_MACHINE_RISCV32 0x5032 -#define GRUB_PE32_MACHINE_RISCV64 0x5064 #define GRUB_PE32_RELOCS_STRIPPED 0x0001 #define GRUB_PE32_EXECUTABLE_IMAGE 0x0002 @@ -290,12 +279,9 @@ struct grub_pe32_fixup_block #define GRUB_PE32_REL_BASED_HIGHADJ 4 #define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5 #define GRUB_PE32_REL_BASED_ARM_MOV32A 5 -#define GRUB_PE32_REL_BASED_RISCV_HI20 5 #define GRUB_PE32_REL_BASED_SECTION 6 #define GRUB_PE32_REL_BASED_REL 7 #define GRUB_PE32_REL_BASED_ARM_MOV32T 7 -#define GRUB_PE32_REL_BASED_RISCV_LOW12I 7 -#define GRUB_PE32_REL_BASED_RISCV_LOW12S 8 #define GRUB_PE32_REL_BASED_IA64_IMM64 9 #define GRUB_PE32_REL_BASED_DIR64 10 #define GRUB_PE32_REL_BASED_HIGH3ADJ 11 diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h deleted file mode 100644 index ec39725c0..000000000 --- a/include/grub/efi/tpm.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_EFI_TPM_HEADER -#define GRUB_EFI_TPM_HEADER 1 - -#define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }}; -#define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }}; - -#define TCG_ALG_SHA 0x00000004 - -/* These structs are as defined in the TCG EFI Protocol Specification, family 2.0. */ - -struct __TCG_VERSION -{ - grub_efi_uint8_t Major; - grub_efi_uint8_t Minor; - grub_efi_uint8_t RevMajor; - grub_efi_uint8_t RevMinor; -}; -typedef struct __TCG_VERSION TCG_VERSION; - -struct __TCG_EFI_BOOT_SERVICE_CAPABILITY -{ - /* Size of this structure. */ - grub_efi_uint8_t Size; - TCG_VERSION StructureVersion; - TCG_VERSION ProtocolSpecVersion; - /* Hash algorithms supported by this TPM. */ - grub_efi_uint8_t HashAlgorithmBitmap; - /* 1 if TPM present. */ - char TPMPresentFlag; - /* 1 if TPM deactivated. */ - char TPMDeactivatedFlag; -}; -typedef struct __TCG_EFI_BOOT_SERVICE_CAPABILITY TCG_EFI_BOOT_SERVICE_CAPABILITY; - -struct tdTCG_PCR_EVENT -{ - grub_efi_uint32_t PCRIndex; - grub_efi_uint32_t EventType; - grub_efi_uint8_t digest[20]; - grub_efi_uint32_t EventSize; - grub_efi_uint8_t Event[1]; -}; -typedef struct tdTCG_PCR_EVENT TCG_PCR_EVENT; - -struct grub_efi_tpm_protocol -{ - grub_efi_status_t (*status_check) (struct grub_efi_tpm_protocol *this, - TCG_EFI_BOOT_SERVICE_CAPABILITY * - ProtocolCapability, - grub_efi_uint32_t *TCGFeatureFlags, - grub_efi_physical_address_t * - EventLogLocation, - grub_efi_physical_address_t * - EventLogLastEntry); - grub_efi_status_t (*hash_all) (struct grub_efi_tpm_protocol *this, - grub_efi_uint8_t *HashData, - grub_efi_uint64_t HashLen, - grub_efi_uint32_t AlgorithmId, - grub_efi_uint64_t *HashedDataLen, - grub_efi_uint8_t **HashedDataResult); - grub_efi_status_t (*log_event) (struct grub_efi_tpm_protocol *this, - TCG_PCR_EVENT *TCGLogData, - grub_efi_uint32_t *EventNumber, - grub_efi_uint32_t Flags); - grub_efi_status_t (*pass_through_to_tpm) (struct grub_efi_tpm_protocol * - this, - grub_efi_uint32_t - TpmInputParameterBlockSize, - grub_efi_uint8_t * - TpmInputParameterBlock, - grub_efi_uint32_t - TpmOutputParameterBlockSize, - grub_efi_uint8_t * - TpmOutputParameterBlock); - grub_efi_status_t (*log_extend_event) (struct grub_efi_tpm_protocol *this, - grub_efi_physical_address_t HashData, - grub_efi_uint64_t HashDataLen, - grub_efi_uint32_t AlgorithmId, - TCG_PCR_EVENT *TCGLogData, - grub_efi_uint32_t *EventNumber, - grub_efi_physical_address_t * - EventLogLastEntry); -}; - -typedef struct grub_efi_tpm_protocol grub_efi_tpm_protocol_t; - -typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_BITMAP; -typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_FORMAT; -typedef grub_efi_uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP; - -struct tdEFI_TCG2_VERSION -{ - grub_efi_uint8_t Major; - grub_efi_uint8_t Minor; -} GRUB_PACKED; -typedef struct tdEFI_TCG2_VERSION EFI_TCG2_VERSION; - -struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY -{ - grub_efi_uint8_t Size; - EFI_TCG2_VERSION StructureVersion; - EFI_TCG2_VERSION ProtocolVersion; - EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap; - EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs; - grub_efi_boolean_t TPMPresentFlag; - grub_efi_uint16_t MaxCommandSize; - grub_efi_uint16_t MaxResponseSize; - grub_efi_uint32_t ManufacturerID; - grub_efi_uint32_t NumberOfPcrBanks; - EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks; -}; -typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY EFI_TCG2_BOOT_SERVICE_CAPABILITY; - -typedef grub_efi_uint32_t TCG_PCRINDEX; -typedef grub_efi_uint32_t TCG_EVENTTYPE; - -struct tdEFI_TCG2_EVENT_HEADER -{ - grub_efi_uint32_t HeaderSize; - grub_efi_uint16_t HeaderVersion; - TCG_PCRINDEX PCRIndex; - TCG_EVENTTYPE EventType; -} GRUB_PACKED; -typedef struct tdEFI_TCG2_EVENT_HEADER EFI_TCG2_EVENT_HEADER; - -struct tdEFI_TCG2_EVENT -{ - grub_efi_uint32_t Size; - EFI_TCG2_EVENT_HEADER Header; - grub_efi_uint8_t Event[1]; -} GRUB_PACKED; -typedef struct tdEFI_TCG2_EVENT EFI_TCG2_EVENT; - -struct grub_efi_tpm2_protocol -{ - grub_efi_status_t (*get_capability) (struct grub_efi_tpm2_protocol *this, - EFI_TCG2_BOOT_SERVICE_CAPABILITY * - ProtocolCapability); - grub_efi_status_t (*get_event_log) (struct grub_efi_tpm2_protocol *this, - EFI_TCG2_EVENT_LOG_FORMAT - EventLogFormat, - grub_efi_physical_address_t * - EventLogLocation, - grub_efi_physical_address_t * - EventLogLastEntry, - grub_efi_boolean_t * EventLogTruncated); - grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol * - this, grub_efi_uint64_t Flags, - grub_efi_physical_address_t - DataToHash, - grub_efi_uint64_t DataToHashLen, - EFI_TCG2_EVENT *EfiTcgEvent); - grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this, - grub_efi_uint32_t - InputParameterBlockSize, - grub_efi_uint8_t *InputParameterBlock, - grub_efi_uint32_t - OutputParameterBlockSize, - grub_efi_uint8_t * - OutputParameterBlock); - grub_efi_status_t (*get_active_pcr_banks) (struct grub_efi_tpm2_protocol * - this, - grub_efi_uint32_t * - ActivePcrBanks); - grub_efi_status_t (*set_active_pcr_banks) (struct grub_efi_tpm2_protocol * - this, - grub_efi_uint32_t - ActivePcrBanks); - grub_efi_status_t (*get_result_of_set_active_pcr_banks) (struct - grub_efi_tpm2_protocol - *this, - grub_efi_uint32_t * - OperationPresent, - grub_efi_uint32_t * - Response); -}; - -typedef struct grub_efi_tpm2_protocol grub_efi_tpm2_protocol_t; - -#endif diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h index 36d2dedf4..9b6b729f4 100644 --- a/include/grub/efiemu/runtime.h +++ b/include/grub/efiemu/runtime.h @@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel struct efi_variable { - grub_efi_packed_guid_t guid; + grub_efi_guid_t guid; grub_uint32_t namelen; grub_uint32_t size; grub_efi_uint32_t attributes; diff --git a/include/grub/elf.h b/include/grub/elf.h index c478933ee..caa796390 100644 --- a/include/grub/elf.h +++ b/include/grub/elf.h @@ -247,7 +247,6 @@ typedef struct #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_NUM 95 #define EM_AARCH64 183 /* ARM 64-bit architecture */ -#define EM_RISCV 243 /* RISC-V */ /* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the @@ -2069,14 +2068,8 @@ typedef Elf32_Addr Elf32_Conflict; #define R_AARCH64_NONE 0 /* No relocation. */ #define R_AARCH64_ABS64 257 /* Direct 64 bit. */ #define R_AARCH64_ABS32 258 /* Direct 32 bit. */ -#define R_AARCH64_PREL32 261 -#define R_AARCH64_ADR_PREL_PG_HI21 275 -#define R_AARCH64_ADD_ABS_LO12_NC 277 -#define R_AARCH64_LDST64_ABS_LO12_NC 286 #define R_AARCH64_JUMP26 282 /* 26-bit relative. */ #define R_AARCH64_CALL26 283 /* 26-bit relative. */ -#define R_AARCH64_ADR_GOT_PAGE 311 -#define R_AARCH64_LD64_GOT_LO12_NC 312 #define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */ #define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */ #define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */ @@ -2474,63 +2467,6 @@ typedef Elf32_Addr Elf32_Conflict; #define R_X86_64_NUM 24 -/* RISC-V relocations */ -#define R_RISCV_NONE 0 -#define R_RISCV_32 1 -#define R_RISCV_64 2 -#define R_RISCV_RELATIVE 3 -#define R_RISCV_COPY 4 -#define R_RISCV_JUMP_SLOT 5 -#define R_RISCV_TLS_DTPMOD32 6 -#define R_RISCV_TLS_DTPMOD64 7 -#define R_RISCV_TLS_DTPREL32 8 -#define R_RISCV_TLS_DTPREL64 9 -#define R_RISCV_TLS_TPREL32 10 -#define R_RISCV_TLS_TPREL64 11 - -#define R_RISCV_BRANCH 16 -#define R_RISCV_JAL 17 -#define R_RISCV_CALL 18 -#define R_RISCV_CALL_PLT 19 -#define R_RISCV_GOT_HI20 20 -#define R_RISCV_TLS_GOT_HI20 21 -#define R_RISCV_TLS_GD_HI20 22 -#define R_RISCV_PCREL_HI20 23 -#define R_RISCV_PCREL_LO12_I 24 -#define R_RISCV_PCREL_LO12_S 25 -#define R_RISCV_HI20 26 -#define R_RISCV_LO12_I 27 -#define R_RISCV_LO12_S 28 -#define R_RISCV_TPREL_HI20 29 -#define R_RISCV_TPREL_LO12_I 30 -#define R_RISCV_TPREL_LO12_S 31 -#define R_RISCV_TPREL_ADD 32 -#define R_RISCV_ADD8 33 -#define R_RISCV_ADD16 34 -#define R_RISCV_ADD32 35 -#define R_RISCV_ADD64 36 -#define R_RISCV_SUB8 37 -#define R_RISCV_SUB16 38 -#define R_RISCV_SUB32 39 -#define R_RISCV_SUB64 40 -#define R_RISCV_GNU_VTINHERIT 41 -#define R_RISCV_GNU_VTENTRY 42 -#define R_RISCV_ALIGN 43 -#define R_RISCV_RVC_BRANCH 44 -#define R_RISCV_RVC_JUMP 45 -#define R_RISCV_LUI 46 -#define R_RISCV_GPREL_I 47 -#define R_RISCV_GPREL_S 48 -#define R_RISCV_TPREL_I 49 -#define R_RISCV_TPREL_S 50 -#define R_RISCV_RELAX 51 -#define R_RISCV_SUB6 52 -#define R_RISCV_SET6 53 -#define R_RISCV_SET8 54 -#define R_RISCV_SET16 55 -#define R_RISCV_SET32 56 -#define R_RISCV_32_PCREL 57 - #ifdef GRUB_TARGET_WORDSIZE #if GRUB_TARGET_WORDSIZE == 32 diff --git a/include/grub/elfload.h b/include/grub/elfload.h index dbb609c9b..9a7ae4ebb 100644 --- a/include/grub/elfload.h +++ b/include/grub/elfload.h @@ -42,7 +42,7 @@ typedef int (*grub_elf32_phdr_iterate_hook_t) typedef int (*grub_elf64_phdr_iterate_hook_t) (grub_elf_t elf, Elf64_Phdr *phdr, void *arg); -grub_elf_t grub_elf_open (const char *, enum grub_file_type type); +grub_elf_t grub_elf_open (const char *); grub_elf_t grub_elf_file (grub_file_t file, const char *filename); grub_err_t grub_elf_close (grub_elf_t); diff --git a/include/grub/emu/hostfile.h b/include/grub/emu/hostfile.h index cfb1e2b56..8e37d5acb 100644 --- a/include/grub/emu/hostfile.h +++ b/include/grub/emu/hostfile.h @@ -47,11 +47,11 @@ grub_util_fd_t EXPORT_FUNC(grub_util_fd_open) (const char *os_dev, int flags); const char * EXPORT_FUNC(grub_util_fd_strerror) (void); -int +void grub_util_fd_sync (grub_util_fd_t fd); void grub_util_disable_fd_syncs (void); -int +void EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd); grub_uint64_t diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index ff9c48a64..a588ba21d 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -24,11 +24,9 @@ #include -#include #include #include #include -#include extern int verbosity; extern const char *program_name; @@ -44,21 +42,27 @@ char *grub_make_system_path_relative_to_its_root (const char *path) int grub_util_device_is_mapped (const char *dev); +#ifdef __MINGW32__ +#define GRUB_HOST_PRIuLONG_LONG "I64u" +#define GRUB_HOST_PRIxLONG_LONG "I64x" +#else #define GRUB_HOST_PRIuLONG_LONG "llu" #define GRUB_HOST_PRIxLONG_LONG "llx" +#endif -void * EXPORT_FUNC(xcalloc) (grub_size_t nmemb, grub_size_t size) WARN_UNUSED_RESULT; void * EXPORT_FUNC(xmalloc) (grub_size_t size) WARN_UNUSED_RESULT; void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) WARN_UNUSED_RESULT; char * EXPORT_FUNC(xstrdup) (const char *str) WARN_UNUSED_RESULT; -char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT; +char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))) WARN_UNUSED_RESULT; -void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); -void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); -void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2), noreturn)); +void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); +void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); +void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2), noreturn)); grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); +extern char * canonicalize_file_name (const char *path); + #ifdef HAVE_DEVICE_MAPPER int grub_device_mapper_supported (void); #endif @@ -70,6 +74,6 @@ FILE * grub_util_fopen (const char *path, const char *mode); #endif -int grub_util_file_sync (FILE *f); +void grub_util_file_sync (FILE *f); #endif /* GRUB_EMU_MISC_H */ diff --git a/include/grub/err.h b/include/grub/err.h index 24ba9f5f5..1590c688e 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -21,7 +21,6 @@ #define GRUB_ERR_HEADER 1 #include -#include #define GRUB_MAX_ERRMSG 256 @@ -92,6 +91,6 @@ int EXPORT_FUNC(grub_error_pop) (void); void EXPORT_FUNC(grub_print_error) (void); extern int EXPORT_VAR(grub_err_printed_errors); int grub_err_printf (const char *fmt, ...) - __attribute__ ((format (GNU_PRINTF, 1, 2))); + __attribute__ ((format (__printf__, 1, 2))); #endif /* ! GRUB_ERR_HEADER */ diff --git a/include/grub/fat.h b/include/grub/fat.h index 8d7e4a1e5..4a5aab793 100644 --- a/include/grub/fat.h +++ b/include/grub/fat.h @@ -28,15 +28,20 @@ struct grub_fat_bpb grub_uint16_t bytes_per_sector; grub_uint8_t sectors_per_cluster; grub_uint16_t num_reserved_sectors; - grub_uint8_t num_fats; /* 0x10 */ + grub_uint8_t num_fats; + /* 0x10 */ grub_uint16_t num_root_entries; grub_uint16_t num_total_sectors_16; - grub_uint8_t media; /* 0x15 */ + grub_uint8_t media; + /*0 x15 */ grub_uint16_t sectors_per_fat_16; - grub_uint16_t sectors_per_track; /* 0x18 */ - grub_uint16_t num_heads; /* 0x1A */ - grub_uint32_t num_hidden_sectors; /* 0x1C */ - grub_uint32_t num_total_sectors_32; /* 0x20 */ + grub_uint16_t sectors_per_track; + /*0 x19 */ + grub_uint16_t num_heads; + /*0 x1b */ + grub_uint32_t num_hidden_sectors; + /* 0x1f */ + grub_uint32_t num_total_sectors_32; union { struct diff --git a/include/grub/fdt.h b/include/grub/fdt.h index e609c7e41..301699830 100644 --- a/include/grub/fdt.h +++ b/include/grub/fdt.h @@ -20,10 +20,6 @@ #define GRUB_FDT_HEADER 1 #include -#include - -/* Space required when preparing the /chosen node after boot has been called. */ -#define GRUB_EFI_LINUX_FDT_EXTRA_SPACE 0x400 #define FDT_MAGIC 0xD00DFEED @@ -53,11 +49,6 @@ struct grub_fdt_empty_tree { #define GRUB_FDT_EMPTY_TREE_SZ sizeof (struct grub_fdt_empty_tree) -/* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff - fields, plus the property value, plus padding if needed. */ -#define grub_fdt_prop_entry_size(prop_len) \ - (3 * sizeof(grub_uint32_t) + ALIGN_UP(prop_len, sizeof(grub_uint32_t))) - #define grub_fdt_get_header(fdt, field) \ grub_be_to_cpu32(((const grub_fdt_header_t *)(fdt))->field) #define grub_fdt_set_header(fdt, field, value) \ @@ -104,22 +95,16 @@ struct grub_fdt_empty_tree { #define grub_fdt_set_size_dt_struct(fdt, value) \ grub_fdt_set_header(fdt, size_dt_struct, value) -int EXPORT_FUNC(grub_fdt_create_empty_tree) (void *fdt, unsigned int size); -int EXPORT_FUNC(grub_fdt_check_header) (const void *fdt, unsigned int size); -int EXPORT_FUNC(grub_fdt_check_header_nosize) (const void *fdt); -int EXPORT_FUNC(grub_fdt_find_subnode) (const void *fdt, unsigned int parentoffset, - const char *name); -int EXPORT_FUNC(grub_fdt_first_node) (const void *fdt, unsigned int parentoffset); -int EXPORT_FUNC(grub_fdt_next_node) (const void *fdt, unsigned int currentoffset); -int EXPORT_FUNC(grub_fdt_add_subnode) (void *fdt, unsigned int parentoffset, +int grub_fdt_create_empty_tree (void *fdt, unsigned int size); +int grub_fdt_check_header (void *fdt, unsigned int size); +int grub_fdt_check_header_nosize (void *fdt); +int grub_fdt_find_subnode (const void *fdt, unsigned int parentoffset, + const char *name); +int grub_fdt_add_subnode (void *fdt, unsigned int parentoffset, const char *name); -const char * -EXPORT_FUNC(grub_fdt_get_nodename) (const void *fdt, unsigned int nodeoffset); -const void *EXPORT_FUNC(grub_fdt_get_prop) (const void *fdt, unsigned int nodeoffset, const char *name, - grub_uint32_t *len); -int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const char *name, - const void *val, grub_uint32_t len); +int grub_fdt_set_prop (void *fdt, unsigned int nodeoffset, const char *name, + const void *val, grub_uint32_t len); #define grub_fdt_set_prop32(fdt, nodeoffset, name, val) \ ({ \ grub_uint32_t _val = grub_cpu_to_be32(val); \ @@ -132,16 +117,4 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch grub_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 8); \ }) -/* Setup "reg" property for - * #address-cells = <0x2> - * #size-cells = <0x2> - */ -#define grub_fdt_set_reg64(fdt, nodeoffset, addr, size) \ -({ \ - grub_uint64_t reg_64[2]; \ - reg_64[0] = grub_cpu_to_be64(addr); \ - reg_64[1] = grub_cpu_to_be64(size); \ - grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \ -}) - #endif /* ! GRUB_FDT_HEADER */ diff --git a/include/grub/fdtbus.h b/include/grub/fdtbus.h deleted file mode 100644 index f519c40ec..000000000 --- a/include/grub/fdtbus.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_FDTBUS_HEADER -#define GRUB_FDTBUS_HEADER 1 - -#include -#include - -struct grub_fdtbus_dev -{ - struct grub_fdtbus_dev *next; - struct grub_fdtbus_dev *parent; - int node; - struct grub_fdtbus_driver *driver; -}; - -struct grub_fdtbus_driver -{ - struct grub_fdtbus_driver *next; - struct grub_fdtbus_driver **prev; - - const char *compatible; - - grub_err_t (*attach) (const struct grub_fdtbus_dev *dev); - void (*detach) (const struct grub_fdtbus_dev *dev); - - /* Message bus operations. */ - grub_err_t (*send) (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz); - grub_err_t (*receive) (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz); - grub_err_t (*start) (const struct grub_fdtbus_dev *dev); - void (*stop) (const struct grub_fdtbus_dev *dev); -}; - -extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1]; - -static inline int -grub_fdtbus_is_mapping_valid (volatile void *m) -{ - return m != grub_fdtbus_invalid_mapping; -} - -volatile void * -EXPORT_FUNC(grub_fdtbus_map_reg) (const struct grub_fdtbus_dev *dev, int reg, grub_size_t *size); - -const void * -EXPORT_FUNC(grub_fdtbus_get_fdt) (void); - -const char * -EXPORT_FUNC(grub_fdtbus_get_name) (const struct grub_fdtbus_dev *dev); - -const void * -EXPORT_FUNC(grub_fdtbus_get_prop) (const struct grub_fdtbus_dev *dev, - const char *name, - grub_uint32_t *len); - -void -EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver); - -void -EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver); - -int -EXPORT_FUNC(grub_fdtbus_is_compatible) (const char *compat_string, - const struct grub_fdtbus_dev *dev); - -/* Must be called before any register(). */ -/* dtb is assumed to be unfreeable and must remain - valid for lifetime of GRUB. - */ -void -grub_fdtbus_init (const void *dtb, grub_size_t size); - -#endif diff --git a/include/grub/file.h b/include/grub/file.h index 31567483c..739488cbe 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -25,116 +25,6 @@ #include #include -enum grub_file_type - { - GRUB_FILE_TYPE_NONE = 0, - /* GRUB module to be loaded. */ - GRUB_FILE_TYPE_GRUB_MODULE, - /* Loopback file to be represented as disk. */ - GRUB_FILE_TYPE_LOOPBACK, - /* Linux kernel to be loaded. */ - GRUB_FILE_TYPE_LINUX_KERNEL, - /* Linux initrd. */ - GRUB_FILE_TYPE_LINUX_INITRD, - - /* Multiboot kernel. */ - GRUB_FILE_TYPE_MULTIBOOT_KERNEL, - /* Multiboot module. */ - GRUB_FILE_TYPE_MULTIBOOT_MODULE, - - /* Xen hypervisor - used on ARM only. */ - GRUB_FILE_TYPE_XEN_HYPERVISOR, - /* Xen module - used on ARM only. */ - GRUB_FILE_TYPE_XEN_MODULE, - - GRUB_FILE_TYPE_BSD_KERNEL, - GRUB_FILE_TYPE_FREEBSD_ENV, - GRUB_FILE_TYPE_FREEBSD_MODULE, - GRUB_FILE_TYPE_FREEBSD_MODULE_ELF, - GRUB_FILE_TYPE_NETBSD_MODULE, - GRUB_FILE_TYPE_OPENBSD_RAMDISK, - - GRUB_FILE_TYPE_XNU_INFO_PLIST, - GRUB_FILE_TYPE_XNU_MKEXT, - GRUB_FILE_TYPE_XNU_KEXT, - GRUB_FILE_TYPE_XNU_KERNEL, - GRUB_FILE_TYPE_XNU_RAMDISK, - GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE, - GRUB_FILE_XNU_DEVPROP, - - GRUB_FILE_TYPE_PLAN9_KERNEL, - - GRUB_FILE_TYPE_NTLDR, - GRUB_FILE_TYPE_TRUECRYPT, - GRUB_FILE_TYPE_FREEDOS, - GRUB_FILE_TYPE_PXECHAINLOADER, - GRUB_FILE_TYPE_PCCHAINLOADER, - - GRUB_FILE_TYPE_COREBOOT_CHAINLOADER, - - GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE, - - /* File holding signature. */ - GRUB_FILE_TYPE_SIGNATURE, - /* File holding public key to verify signature once. */ - GRUB_FILE_TYPE_PUBLIC_KEY, - /* File holding public key to add to trused keys. */ - GRUB_FILE_TYPE_PUBLIC_KEY_TRUST, - /* File of which we intend to print a blocklist to the user. */ - GRUB_FILE_TYPE_PRINT_BLOCKLIST, - /* File we intend to use for test loading or testing speed. */ - GRUB_FILE_TYPE_TESTLOAD, - /* File we open only to get its size. E.g. in ls output. */ - GRUB_FILE_TYPE_GET_SIZE, - /* Font file. */ - GRUB_FILE_TYPE_FONT, - /* File holding encryption key for encrypted ZFS. */ - GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY, - /* File we open n grub-fstest. */ - GRUB_FILE_TYPE_FSTEST, - /* File we open n grub-mount. */ - GRUB_FILE_TYPE_MOUNT, - /* File which we attempt to identify the type of. */ - GRUB_FILE_TYPE_FILE_ID, - /* File holding ACPI table. */ - GRUB_FILE_TYPE_ACPI_TABLE, - /* File holding Device Tree. */ - GRUB_FILE_TYPE_DEVICE_TREE_IMAGE, - /* File we intend show to user. */ - GRUB_FILE_TYPE_CAT, - GRUB_FILE_TYPE_HEXCAT, - /* One of pair of files we intend to compare. */ - GRUB_FILE_TYPE_CMP, - /* List of hashes for hashsum. */ - GRUB_FILE_TYPE_HASHLIST, - /* File hashed by hashsum. */ - GRUB_FILE_TYPE_TO_HASH, - /* Keyboard layout. */ - GRUB_FILE_TYPE_KEYBOARD_LAYOUT, - /* Picture file. */ - GRUB_FILE_TYPE_PIXMAP, - /* *.lst shipped by GRUB. */ - GRUB_FILE_TYPE_GRUB_MODULE_LIST, - /* config file. */ - GRUB_FILE_TYPE_CONFIG, - GRUB_FILE_TYPE_THEME, - GRUB_FILE_TYPE_GETTEXT_CATALOG, - GRUB_FILE_TYPE_FS_SEARCH, - GRUB_FILE_TYPE_AUDIO, - GRUB_FILE_TYPE_VBE_DUMP, - - GRUB_FILE_TYPE_LOADENV, - GRUB_FILE_TYPE_SAVEENV, - - GRUB_FILE_TYPE_VERIFY_SIGNATURE, - - GRUB_FILE_TYPE_MASK = 0xffff, - - /* --skip-sig is specified. */ - GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000, - GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000 - }; - /* File description. */ struct grub_file { @@ -178,7 +68,7 @@ extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook); /* Filters with lower ID are executed first. */ typedef enum grub_file_filter_id { - GRUB_FILE_FILTER_VERIFY, + GRUB_FILE_FILTER_PUBKEY, GRUB_FILE_FILTER_GZIO, GRUB_FILE_FILTER_XZIO, GRUB_FILE_FILTER_LZOPIO, @@ -187,26 +77,61 @@ typedef enum grub_file_filter_id GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO, } grub_file_filter_id_t; -typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type); +typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, const char *filename); -extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX]; +extern grub_file_filter_t EXPORT_VAR(grub_file_filters_all)[GRUB_FILE_FILTER_MAX]; +extern grub_file_filter_t EXPORT_VAR(grub_file_filters_enabled)[GRUB_FILE_FILTER_MAX]; static inline void grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter) { - grub_file_filters[id] = filter; + grub_file_filters_all[id] = filter; + grub_file_filters_enabled[id] = filter; } static inline void grub_file_filter_unregister (grub_file_filter_id_t id) { - grub_file_filters[id] = 0; + grub_file_filters_all[id] = 0; + grub_file_filters_enabled[id] = 0; +} + +static inline void +grub_file_filter_disable (grub_file_filter_id_t id) +{ + grub_file_filters_enabled[id] = 0; +} + +static inline void +grub_file_filter_disable_compression (void) +{ + grub_file_filter_id_t id; + + for (id = GRUB_FILE_FILTER_COMPRESSION_FIRST; + id <= GRUB_FILE_FILTER_COMPRESSION_LAST; id++) + grub_file_filters_enabled[id] = 0; +} + +static inline void +grub_file_filter_disable_all (void) +{ + grub_file_filter_id_t id; + + for (id = 0; + id < GRUB_FILE_FILTER_MAX; id++) + grub_file_filters_enabled[id] = 0; +} + +static inline void +grub_file_filter_disable_pubkey (void) +{ + grub_file_filters_enabled[GRUB_FILE_FILTER_PUBKEY] = 0; } /* Get a device name from NAME. */ char *EXPORT_FUNC(grub_file_get_device_name) (const char *name); -grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type); +grub_file_t EXPORT_FUNC(grub_file_open) (const char *name); grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf, grub_size_t len); grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset); @@ -234,8 +159,8 @@ grub_file_seekable (const grub_file_t file) } grub_file_t -grub_file_offset_open (grub_file_t parent, enum grub_file_type type, - grub_off_t start, grub_off_t size); +grub_file_offset_open (grub_file_t parent, grub_off_t start, + grub_off_t size); void grub_file_offset_close (grub_file_t file); diff --git a/include/grub/fs.h b/include/grub/fs.h index 302e48d4b..5678c60c2 100644 --- a/include/grub/fs.h +++ b/include/grub/fs.h @@ -58,34 +58,34 @@ struct grub_fs const char *name; /* Call HOOK with each file under DIR. */ - grub_err_t (*fs_dir) (grub_device_t device, const char *path, + grub_err_t (*dir) (grub_device_t device, const char *path, grub_fs_dir_hook_t hook, void *hook_data); /* Open a file named NAME and initialize FILE. */ - grub_err_t (*fs_open) (struct grub_file *file, const char *name); + grub_err_t (*open) (struct grub_file *file, const char *name); /* Read LEN bytes data from FILE into BUF. */ - grub_ssize_t (*fs_read) (struct grub_file *file, char *buf, grub_size_t len); + grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len); /* Close the file FILE. */ - grub_err_t (*fs_close) (struct grub_file *file); + grub_err_t (*close) (struct grub_file *file); /* Return the label of the device DEVICE in LABEL. The label is returned in a grub_malloc'ed buffer and should be freed by the caller. */ - grub_err_t (*fs_label) (grub_device_t device, char **label); + grub_err_t (*label) (grub_device_t device, char **label); /* Return the uuid of the device DEVICE in UUID. The uuid is returned in a grub_malloc'ed buffer and should be freed by the caller. */ - grub_err_t (*fs_uuid) (grub_device_t device, char **uuid); + grub_err_t (*uuid) (grub_device_t device, char **uuid); /* Get writing time of filesystem. */ - grub_err_t (*fs_mtime) (grub_device_t device, grub_int32_t *timebuf); + grub_err_t (*mtime) (grub_device_t device, grub_int32_t *timebuf); #ifdef GRUB_UTIL /* Determine sectors available for embedding. */ - grub_err_t (*fs_embed) (grub_device_t device, unsigned int *nsectors, + grub_err_t (*embed) (grub_device_t device, unsigned int *nsectors, unsigned int max_nsectors, grub_embed_type_t embed_type, grub_disk_addr_t **sectors); diff --git a/include/grub/fshelp.h b/include/grub/fshelp.h index eb1ba4f6c..38923044c 100644 --- a/include/grub/fshelp.h +++ b/include/grub/fshelp.h @@ -62,17 +62,6 @@ EXPORT_FUNC(grub_fshelp_find_file) (const char *path, enum grub_fshelp_filetype expect); -grub_err_t -EXPORT_FUNC(grub_fshelp_find_file_lookup) (const char *path, - grub_fshelp_node_t rootnode, - grub_fshelp_node_t *foundnode, - grub_err_t (*lookup_file) (grub_fshelp_node_t dir, - const char *name, - grub_fshelp_node_t *foundnode, - enum grub_fshelp_filetype *foundtype), - char *(*read_symlink) (grub_fshelp_node_t node), - enum grub_fshelp_filetype expect); - /* Read LEN bytes from the file NODE on disk DISK into the buffer BUF, beginning with the block POS. READ_HOOK should be set before reading a block from the file. GET_BLOCK is used to translate file diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h index 7a93f4329..1b32f6725 100644 --- a/include/grub/gpt_partition.h +++ b/include/grub/gpt_partition.h @@ -22,14 +22,14 @@ #include #include -struct grub_gpt_part_guid +struct grub_gpt_part_type { grub_uint32_t data1; grub_uint16_t data2; grub_uint16_t data3; grub_uint8_t data4[8]; -} GRUB_PACKED; -typedef struct grub_gpt_part_guid grub_gpt_part_guid_t; +} __attribute__ ((aligned(8))); +typedef struct grub_gpt_part_type grub_gpt_part_type_t; #define GRUB_GPT_PARTITION_TYPE_EMPTY \ { 0x0, 0x0, 0x0, \ @@ -70,8 +70,8 @@ struct grub_gpt_header struct grub_gpt_partentry { - grub_gpt_part_guid_t type; - grub_gpt_part_guid_t guid; + grub_gpt_part_type_t type; + grub_uint8_t guid[16]; grub_uint64_t start; grub_uint64_t end; grub_uint64_t attrib; diff --git a/include/grub/hfs.h b/include/grub/hfs.h index e27993c42..d935f5005 100644 --- a/include/grub/hfs.h +++ b/include/grub/hfs.h @@ -29,7 +29,7 @@ struct grub_hfs_extent /* The first physical block. */ grub_uint16_t first_block; grub_uint16_t count; -} GRUB_PACKED; +}; /* HFS stores extents in groups of 3. */ typedef struct grub_hfs_extent grub_hfs_datarecord_t[3]; diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h index 117740ae2..8ba8f3246 100644 --- a/include/grub/hfsplus.h +++ b/include/grub/hfsplus.h @@ -171,7 +171,7 @@ struct grub_hfsplus_catkey grub_uint16_t keylen; grub_uint32_t parent; grub_uint16_t namelen; - grub_uint16_t name[0]; + grub_uint16_t name[30]; } GRUB_PACKED; /* The on disk layout of an extent overflow file key. */ @@ -207,14 +207,12 @@ struct grub_hfsplus_btnode /* Return the offset of the record with the index INDEX, in the node NODE which is part of the B+ tree BTREE. */ -static inline grub_uint16_t +static inline grub_off_t grub_hfsplus_btree_recoffset (struct grub_hfsplus_btree *btree, - struct grub_hfsplus_btnode *node, unsigned index) + struct grub_hfsplus_btnode *node, int index) { char *cnode = (char *) node; void *recptr; - if (btree->nodesize < index * sizeof (grub_uint16_t) + 2) - index = 0; recptr = (&cnode[btree->nodesize - index * sizeof (grub_uint16_t) - 2]); return grub_be_to_cpu16 (grub_get_unaligned16 (recptr)); } @@ -223,13 +221,11 @@ grub_hfsplus_btree_recoffset (struct grub_hfsplus_btree *btree, NODE which is part of the B+ tree BTREE. */ static inline struct grub_hfsplus_key * grub_hfsplus_btree_recptr (struct grub_hfsplus_btree *btree, - struct grub_hfsplus_btnode *node, unsigned index) + struct grub_hfsplus_btnode *node, int index) { char *cnode = (char *) node; - grub_uint16_t offset; + grub_off_t offset; offset = grub_hfsplus_btree_recoffset (btree, node, index); - if (offset > btree->nodesize - sizeof (struct grub_hfsplus_key)) - offset = 0; return (struct grub_hfsplus_key *) &cnode[offset]; } diff --git a/include/grub/coreboot/lbio.h b/include/grub/i386/coreboot/lbio.h similarity index 93% rename from include/grub/coreboot/lbio.h rename to include/grub/i386/coreboot/lbio.h index 5076d36c7..1c3fa6f19 100644 --- a/include/grub/coreboot/lbio.h +++ b/include/grub/i386/coreboot/lbio.h @@ -20,9 +20,6 @@ #ifndef _GRUB_MACHINE_LBIO_HEADER #define _GRUB_MACHINE_LBIO_HEADER 1 -#include -#include - struct grub_linuxbios_table_header { grub_uint8_t signature[4]; @@ -105,10 +102,4 @@ EXPORT_FUNC(grub_linuxbios_table_iterate) (int (*hook) (grub_linuxbios_table_ite void *), void *hook_data); -grub_linuxbios_table_header_t -grub_linuxbios_get_tables (void); - -int -grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header); - #endif diff --git a/include/grub/i386/efi/kernel.h b/include/grub/i386/efi/kernel.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/grub/i386/ieee1275/kernel.h b/include/grub/i386/ieee1275/kernel.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/grub/i386/io.h b/include/grub/i386/io.h index e9cd80957..ae12a3e3d 100644 --- a/include/grub/i386/io.h +++ b/include/grub/i386/io.h @@ -28,7 +28,7 @@ grub_inb (unsigned short int port) { unsigned char _v; - asm volatile ("inb %w1,%0":"=a" (_v):"Nd" (port)); + __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port)); return _v; } @@ -37,7 +37,7 @@ grub_inw (unsigned short int port) { unsigned short _v; - asm volatile ("inw %w1,%0":"=a" (_v):"Nd" (port)); + __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port)); return _v; } @@ -46,27 +46,27 @@ grub_inl (unsigned short int port) { unsigned int _v; - asm volatile ("inl %w1,%0":"=a" (_v):"Nd" (port)); + __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port)); return _v; } static __inline void grub_outb (unsigned char value, unsigned short int port) { - asm volatile ("outb %b0,%w1": :"a" (value), "Nd" (port)); + __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port)); } static __inline void grub_outw (unsigned short int value, unsigned short int port) { - asm volatile ("outw %w0,%w1": :"a" (value), "Nd" (port)); + __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port)); } static __inline void grub_outl (unsigned int value, unsigned short int port) { - asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port)); + __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port)); } #endif /* _SYS_IO_H */ diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index ce30e7fb0..da0ca3b83 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -16,10 +16,10 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_I386_LINUX_HEADER -#define GRUB_I386_LINUX_HEADER 1 +#ifndef GRUB_LINUX_MACHINE_HEADER +#define GRUB_LINUX_MACHINE_HEADER 1 -#define GRUB_LINUX_I386_MAGIC_SIGNATURE 0x53726448 /* "HdrS" */ +#define GRUB_LINUX_MAGIC_SIGNATURE 0x53726448 /* "HdrS" */ #define GRUB_LINUX_DEFAULT_SETUP_SECTS 4 #define GRUB_LINUX_INITRD_MAX_ADDRESS 0x37FFFFFF #define GRUB_LINUX_MAX_SETUP_SECTS 64 @@ -43,12 +43,6 @@ #define GRUB_LINUX_CL_MAGIC 0xA33F -#define VIDEO_CAPABILITY_SKIP_QUIRKS (1 << 0) -#define VIDEO_CAPABILITY_64BIT_BASE (1 << 1) /* Frame buffer base is 64-bit. */ - -/* Maximum number of MBR signatures to store. */ -#define EDD_MBR_SIG_MAX 16 - #ifdef __x86_64__ #define GRUB_LINUX_EFI_SIGNATURE \ @@ -91,7 +85,7 @@ enum }; /* For the Linux/i386 boot protocol version 2.10. */ -struct linux_i386_kernel_header +struct linux_kernel_header { grub_uint8_t code1[0x0020]; grub_uint16_t cl_magic; /* Magic number 0xA33F */ @@ -145,7 +139,6 @@ struct linux_i386_kernel_header grub_uint64_t setup_data; grub_uint64_t pref_address; grub_uint32_t init_size; - grub_uint32_t handover_offset; } GRUB_PACKED; /* Boot parameters for Linux based on 2.6.12. This is used by the setup @@ -195,9 +188,8 @@ struct linux_kernel_params grub_uint16_t lfb_pages; /* 32 */ grub_uint16_t vesa_attrib; /* 34 */ grub_uint32_t capabilities; /* 36 */ - grub_uint32_t ext_lfb_base; /* 3a */ - grub_uint8_t padding3[0x40 - 0x3e]; + grub_uint8_t padding3[0x40 - 0x3a]; grub_uint16_t apm_version; /* 40 */ grub_uint16_t apm_code_segment; /* 42 */ @@ -214,9 +206,8 @@ struct linux_kernel_params grub_uint32_t ist_command; /* 64 */ grub_uint32_t ist_event; /* 68 */ grub_uint32_t ist_perf_level; /* 6c */ - grub_uint64_t acpi_rsdp_addr; /* 70 */ - grub_uint8_t padding5[0x80 - 0x78]; + grub_uint8_t padding5[0x80 - 0x70]; grub_uint8_t hd0_drive_info[0x10]; /* 80 */ grub_uint8_t hd1_drive_info[0x10]; /* 90 */ @@ -277,7 +268,6 @@ struct linux_kernel_params grub_uint8_t padding9[0x1f1 - 0x1e9]; - /* Linux setup header copy - BEGIN. */ grub_uint8_t setup_sects; /* The size of the setup in sectors */ grub_uint16_t root_flags; /* If the root is mounted readonly */ grub_uint16_t syssize; /* obsolete */ @@ -316,15 +306,10 @@ struct linux_kernel_params grub_uint32_t payload_offset; grub_uint32_t payload_length; grub_uint64_t setup_data; - grub_uint64_t pref_address; - grub_uint32_t init_size; - grub_uint32_t handover_offset; - /* Linux setup header copy - END. */ - - grub_uint8_t _pad7[40]; - grub_uint32_t edd_mbr_sig_buffer[EDD_MBR_SIG_MAX]; /* 290 */ + grub_uint8_t pad2[120]; /* 258 */ struct grub_e820_mmap e820_map[(0x400 - 0x2d0) / 20]; /* 2d0 */ + } GRUB_PACKED; #endif /* ! ASM_FILE */ -#endif /* ! GRUB_I386_LINUX_HEADER */ +#endif /* ! GRUB_LINUX_MACHINE_HEADER */ diff --git a/include/grub/i386/memory.h b/include/grub/i386/memory.h index 5cb607fb4..c9b13288f 100644 --- a/include/grub/i386/memory.h +++ b/include/grub/i386/memory.h @@ -20,8 +20,6 @@ #ifndef GRUB_MEMORY_CPU_HEADER #define GRUB_MEMORY_CPU_HEADER 1 -#define PAGE_SHIFT 12 - /* The flag for protected mode. */ #define GRUB_MEMORY_CPU_CR0_PE_ON 0x1 #define GRUB_MEMORY_CPU_CR4_PAE_ON 0x00000020 @@ -33,24 +31,12 @@ #define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */ #define GRUB_MEMORY_MACHINE_LOWER_SIZE GRUB_MEMORY_MACHINE_UPPER_START -/* Some PTE definitions. */ -#define GRUB_PAGE_PRESENT 0x00000001 -#define GRUB_PAGE_RW 0x00000002 -#define GRUB_PAGE_USER 0x00000004 - #ifndef ASM_FILE #define GRUB_MMAP_MALLOC_LOW 1 #include -struct grub_e820_mmap_entry -{ - grub_uint64_t addr; - grub_uint64_t len; - grub_uint32_t type; -} GRUB_PACKED; - grub_uint64_t grub_mmap_get_upper (void); grub_uint64_t grub_mmap_get_lower (void); grub_uint64_t grub_mmap_get_post64 (void); diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h index 0b596fc20..a1b94883d 100644 --- a/include/grub/i386/multiboot.h +++ b/include/grub/i386/multiboot.h @@ -19,13 +19,6 @@ #ifndef GRUB_MULTIBOOT_CPU_HEADER #define GRUB_MULTIBOOT_CPU_HEADER 1 -#define MULTIBOOT2_INITIAL_STATE { .eax = MULTIBOOT2_BOOTLOADER_MAGIC, \ - .ecx = 0, \ - .edx = 0, \ - /* Set esp to some random location in low memory to avoid breaking */ \ - /* non-compliant kernels. */ \ - .esp = 0x7ff00 \ - } #define MULTIBOOT_INITIAL_STATE { .eax = MULTIBOOT_BOOTLOADER_MAGIC, \ .ecx = 0, \ .edx = 0, \ @@ -35,22 +28,7 @@ } #define MULTIBOOT_ENTRY_REGISTER eip #define MULTIBOOT_MBI_REGISTER ebx -#define MULTIBOOT2_ARCHITECTURE_CURRENT MULTIBOOT2_ARCHITECTURE_I386 - -#ifdef GRUB_MACHINE_EFI -#ifdef __x86_64__ -#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ - .rcx = 0, \ - .rdx = 0, \ - } -#define MULTIBOOT2_EFI_INITIAL_STATE { .rax = MULTIBOOT2_BOOTLOADER_MAGIC, \ - .rcx = 0, \ - .rdx = 0, \ - } -#define MULTIBOOT_EFI_ENTRY_REGISTER rip -#define MULTIBOOT_EFI_MBI_REGISTER rbx -#endif -#endif +#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 #define MULTIBOOT_ELF32_MACHINE EM_386 #define MULTIBOOT_ELF64_MACHINE EM_X86_64 diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h index a60104001..16a53e4fe 100644 --- a/include/grub/i386/pc/int.h +++ b/include/grub/i386/pc/int.h @@ -20,11 +20,45 @@ #define GRUB_INTERRUPT_MACHINE_HEADER 1 #include -#include +#include + +struct grub_bios_int_registers +{ + grub_uint32_t eax; + grub_uint16_t es; + grub_uint16_t ds; + grub_uint16_t flags; + grub_uint16_t dummy; + grub_uint32_t ebx; + grub_uint32_t ecx; + grub_uint32_t edi; + grub_uint32_t esi; + grub_uint32_t edx; +}; + +#define GRUB_CPU_INT_FLAGS_CARRY 0x1 +#define GRUB_CPU_INT_FLAGS_PARITY 0x4 +#define GRUB_CPU_INT_FLAGS_ADJUST 0x10 +#define GRUB_CPU_INT_FLAGS_ZERO 0x40 +#define GRUB_CPU_INT_FLAGS_SIGN 0x80 +#define GRUB_CPU_INT_FLAGS_TRAP 0x100 +#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200 +#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400 +#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 +#ifdef GRUB_MACHINE_PCBIOS +#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT +#else +#define GRUB_CPU_INT_FLAGS_DEFAULT 0 +#endif void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno, struct grub_bios_int_registers *regs) __attribute__ ((regparm(3))); +struct grub_i386_idt +{ + grub_uint16_t limit; + grub_uint32_t base; +} GRUB_PACKED; #ifdef GRUB_MACHINE_PCBIOS extern struct grub_i386_idt *EXPORT_VAR(grub_realidt); diff --git a/include/grub/i386/pc/int_types.h b/include/grub/i386/pc/int_types.h deleted file mode 100644 index 2c5a69b63..000000000 --- a/include/grub/i386/pc/int_types.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_INTERRUPT_TYPES_MACHINE_HEADER -#define GRUB_INTERRUPT_TYPES_MACHINE_HEADER 1 - -#include - -#define GRUB_CPU_INT_FLAGS_CARRY 0x1 -#define GRUB_CPU_INT_FLAGS_PARITY 0x4 -#define GRUB_CPU_INT_FLAGS_ADJUST 0x10 -#define GRUB_CPU_INT_FLAGS_ZERO 0x40 -#define GRUB_CPU_INT_FLAGS_SIGN 0x80 -#define GRUB_CPU_INT_FLAGS_TRAP 0x100 -#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200 -#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400 -#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800 -#ifdef GRUB_MACHINE_PCBIOS -#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT -#else -#define GRUB_CPU_INT_FLAGS_DEFAULT 0 -#endif - -struct grub_bios_int_registers -{ - grub_uint32_t eax; - grub_uint16_t es; - grub_uint16_t ds; - grub_uint16_t flags; - grub_uint16_t dummy; - grub_uint32_t ebx; - grub_uint32_t ecx; - grub_uint32_t edi; - grub_uint32_t esi; - grub_uint32_t edx; -}; - -struct grub_i386_idt -{ - grub_uint16_t limit; - grub_uint32_t base; -} GRUB_PACKED; - -#endif diff --git a/include/grub/i386/pmtimer.h b/include/grub/i386/pmtimer.h deleted file mode 100644 index ac091806a..000000000 --- a/include/grub/i386/pmtimer.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef KERNEL_CPU_PMTIMER_HEADER -#define KERNEL_CPU_PMTIMER_HEADER 1 - -#include -#include - -/* - Preconditions: - * Caller has ensured that both pmtimer and tsc are supported - * 1 <= num_pm_ticks <= 3580 - Return: - * Number of TSC ticks elapsed - * 0 on failure. -*/ -grub_uint64_t -EXPORT_FUNC(grub_pmtimer_wait_count_tsc) (grub_port_t pmtimer, - grub_uint16_t num_pm_ticks); - -#endif diff --git a/include/grub/i386/rdmsr.h b/include/grub/i386/rdmsr.h deleted file mode 100644 index c0a0c717a..000000000 --- a/include/grub/i386/rdmsr.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_RDMSR_H -#define GRUB_RDMSR_H 1 - -/* - * TODO: Add a general protection exception handler. - * Accessing a reserved or unimplemented MSR address results in a GP#. - */ - -static inline grub_uint64_t -grub_msr_read (grub_uint32_t msr_id) -{ - grub_uint32_t low, high; - - asm volatile ("rdmsr" : "=a" (low), "=d" (high) : "c" (msr_id)); - - return ((grub_uint64_t)high << 32) | low; -} - -#endif /* GRUB_RDMSR_H */ diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h index 2a56c3b54..5f89a7ec8 100644 --- a/include/grub/i386/relocator.h +++ b/include/grub/i386/relocator.h @@ -65,20 +65,6 @@ struct grub_relocator64_state grub_addr_t cr3; }; -#ifdef GRUB_MACHINE_EFI -#ifdef __x86_64__ -struct grub_relocator64_efi_state -{ - grub_uint64_t rax; - grub_uint64_t rbx; - grub_uint64_t rcx; - grub_uint64_t rdx; - grub_uint64_t rip; - grub_uint64_t rsi; -}; -#endif -#endif - grub_err_t grub_relocator16_boot (struct grub_relocator *rel, struct grub_relocator16_state state); @@ -90,11 +76,4 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel, struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); -#ifdef GRUB_MACHINE_EFI -#ifdef __x86_64__ -grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, - struct grub_relocator64_efi_state state); -#endif -#endif - #endif /* ! GRUB_RELOCATOR_CPU_HEADER */ diff --git a/include/grub/i386/time.h b/include/grub/i386/time.h index 4da5ae93c..842882cf2 100644 --- a/include/grub/i386/time.h +++ b/include/grub/i386/time.h @@ -23,7 +23,7 @@ static __inline void grub_cpu_idle (void) { /* FIXME: this can't work until we handle interrupts. */ -/* asm volatile ("hlt"); */ +/* __asm__ __volatile__ ("hlt"); */ } #endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/i386/tsc.h b/include/grub/i386/tsc.h index 947e62fa1..71b32e6b8 100644 --- a/include/grub/i386/tsc.h +++ b/include/grub/i386/tsc.h @@ -20,51 +20,9 @@ #define KERNEL_CPU_TSC_HEADER 1 #include -#include void grub_tsc_init (void); /* In ms per 2^32 ticks. */ extern grub_uint32_t EXPORT_VAR(grub_tsc_rate); -int -grub_tsc_calibrate_from_xen (void); -int -grub_tsc_calibrate_from_efi (void); -int -grub_tsc_calibrate_from_pmtimer (void); -int -grub_tsc_calibrate_from_pit (void); - -/* Read the TSC value, which increments with each CPU clock cycle. */ -static __inline grub_uint64_t -grub_get_tsc (void) -{ - grub_uint32_t lo, hi; - grub_uint32_t a,b,c,d; - - /* The CPUID instruction is a 'serializing' instruction, and - avoids out-of-order execution of the RDTSC instruction. */ - grub_cpuid (0,a,b,c,d); - /* Read TSC value. We cannot use "=A", since this would use - %rax on x86_64. */ - asm volatile ("rdtsc":"=a" (lo), "=d" (hi)); - - return (((grub_uint64_t) hi) << 32) | lo; -} - -static __inline int -grub_cpu_is_tsc_supported (void) -{ -#if !defined(GRUB_MACHINE_XEN) && !defined(GRUB_MACHINE_XEN_PVH) - grub_uint32_t a,b,c,d; - if (! grub_cpu_is_cpuid_supported ()) - return 0; - - grub_cpuid(1,a,b,c,d); - - return (d & (1 << 4)) != 0; -#else - return 1; -#endif -} #endif /* ! KERNEL_CPU_TSC_HEADER */ diff --git a/include/grub/i386/wrmsr.h b/include/grub/i386/wrmsr.h deleted file mode 100644 index dea60aed1..000000000 --- a/include/grub/i386/wrmsr.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_WRMSR_H -#define GRUB_WRMSR_H 1 - -/* - * TODO: Add a general protection exception handler. - * Accessing a reserved or unimplemented MSR address results in a GP#. - */ - -static inline void -grub_msr_write(grub_uint32_t msr_id, grub_uint64_t msr_value) -{ - grub_uint32_t low = msr_value, high = msr_value >> 32; - - asm volatile ("wrmsr" : : "c" (msr_id), "a" (low), "d" (high)); -} - -#endif /* GRUB_WRMSR_H */ diff --git a/include/grub/i386/xen/hypercall.h b/include/grub/i386/xen/hypercall.h index 4e4c12a49..198ee94af 100644 --- a/include/grub/i386/xen/hypercall.h +++ b/include/grub/i386/xen/hypercall.h @@ -26,10 +26,7 @@ EXPORT_FUNC (grub_xen_hypercall) (grub_uint32_t callno, grub_uint32_t a0, grub_uint32_t a1, grub_uint32_t a2, grub_uint32_t a3, grub_uint32_t a4, grub_uint32_t a5) -#ifdef GRUB_MACHINE_XEN - __attribute__ ((regparm (3), cdecl)) -#endif - ; +__attribute__ ((regparm (3), cdecl)); static inline int grub_xen_sched_op (int cmd, void *arg) diff --git a/include/grub/i386/xen/kernel.h b/include/grub/i386/xen/kernel.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/grub/i386/xen_pvh/boot.h b/include/grub/i386/xen_pvh/boot.h deleted file mode 100644 index 6cd23aa83..000000000 --- a/include/grub/i386/xen_pvh/boot.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/grub/i386/xen_pvh/console.h b/include/grub/i386/xen_pvh/console.h deleted file mode 100644 index 305a46d8e..000000000 --- a/include/grub/i386/xen_pvh/console.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/grub/i386/xen_pvh/int.h b/include/grub/i386/xen_pvh/int.h deleted file mode 100644 index 0f1f9ee62..000000000 --- a/include/grub/i386/xen_pvh/int.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/grub/i386/xen_pvh/kernel.h b/include/grub/i386/xen_pvh/kernel.h deleted file mode 100644 index 2b7b8a129..000000000 --- a/include/grub/i386/xen_pvh/kernel.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_KERNEL_MACHINE_HEADER -#define GRUB_KERNEL_MACHINE_HEADER 1 - -#ifndef ASM_FILE - -#define GRUB_KERNEL_USE_RSDP_ADDR 1 - -extern grub_uint64_t EXPORT_VAR(grub_rsdp_addr); - -#endif /* ! ASM_FILE */ - -#endif /* GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/i386/xen_pvh/memory.h b/include/grub/i386/xen_pvh/memory.h deleted file mode 100644 index 8dd6f7c8c..000000000 --- a/include/grub/i386/xen_pvh/memory.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/grub/i386/xen_pvh/time.h b/include/grub/i386/xen_pvh/time.h deleted file mode 100644 index 2298ee8f4..000000000 --- a/include/grub/i386/xen_pvh/time.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/grub/i386/xnu.h b/include/grub/i386/xnu.h index 062a7ddbe..a076b8a97 100644 --- a/include/grub/i386/xnu.h +++ b/include/grub/i386/xnu.h @@ -89,8 +89,7 @@ struct grub_xnu_boot_params_v2 grub_uint64_t efi_runtime_first_page_virtual; grub_uint32_t efi_system_table; - grub_uint32_t unused2[9]; - grub_uint64_t ram_size; + grub_uint32_t unused2[11]; grub_uint64_t fsbfreq; grub_uint32_t unused3[734]; } GRUB_PACKED; diff --git a/include/grub/ia64/reloc.h b/include/grub/ia64/reloc.h index 45c8fba27..4c02ab2e6 100644 --- a/include/grub/ia64/reloc.h +++ b/include/grub/ia64/reloc.h @@ -26,8 +26,6 @@ grub_ia64_add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value); void grub_ia64_add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value); void -grub_ia64_set_immu64 (grub_addr_t addr, grub_uint64_t value); -void grub_ia64_make_trampoline (struct grub_ia64_trampoline *tr, grub_uint64_t addr); struct grub_ia64_trampoline diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 73e2f4644..8e4251303 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -146,8 +146,6 @@ enum grub_ieee1275_flag GRUB_IEEE1275_FLAG_BROKEN_REPEAT, GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN, - - GRUB_IEEE1275_FLAG_RAW_DEVNAMES, }; extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); @@ -212,25 +210,7 @@ int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle, int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle, int index, int r, int g, int b); int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs); -int EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle, - grub_uint32_t target, - grub_uint32_t lun); -int EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle, - const void *cmd_addr, - grub_ssize_t *result); -int EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle, - void *addr, grub_size_t size, - grub_uint32_t *phy_lo, - grub_uint32_t *phy_hi, - grub_uint32_t *lun_lo, - grub_uint32_t *lun_hi); -char *EXPORT_FUNC(grub_ieee1275_encode_uint4) (grub_ieee1275_ihandle_t ihandle, - grub_uint32_t phy_lo, - grub_uint32_t phy_hi, - grub_uint32_t lun_lo, - grub_uint32_t lun_hi, - grub_size_t *size); -int EXPORT_FUNC(grub_ieee1275_get_block_size) (grub_ieee1275_ihandle_t ihandle); + grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size); @@ -255,8 +235,6 @@ void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *al void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath, struct grub_ieee1275_devalias *alias); -char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void); - #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));) #define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \ diff --git a/include/grub/ieee1275/obdisk.h b/include/grub/ieee1275/obdisk.h deleted file mode 100644 index 5da51f812..000000000 --- a/include/grub/ieee1275/obdisk.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_OBDISK_HEADER -#define GRUB_OBDISK_HEADER 1 - -extern void grub_obdisk_init (void); -extern void grub_obdisk_fini (void); - -#endif diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h index 2f69e3f19..3f5831787 100644 --- a/include/grub/ieee1275/ofdisk.h +++ b/include/grub/ieee1275/ofdisk.h @@ -22,4 +22,7 @@ extern void grub_ofdisk_init (void); extern void grub_ofdisk_fini (void); +extern grub_err_t grub_ofdisk_get_block_size (const char *device, + grub_uint32_t *block_size); + #endif /* ! GRUB_INIT_HEADER */ diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 133a37c8d..20ddf2da2 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -28,8 +28,7 @@ enum OBJ_TYPE_MEMDISK, OBJ_TYPE_CONFIG, OBJ_TYPE_PREFIX, - OBJ_TYPE_PUBKEY, - OBJ_TYPE_DTB + OBJ_TYPE_PUBKEY }; /* The module header. */ @@ -79,9 +78,7 @@ struct grub_module_info64 #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) \ || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) \ || defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_ARC) \ - || (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) \ - || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN) \ - || defined(GRUB_MACHINE_XEN_PVH) + || (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN) /* FIXME: stack is between 2 heap regions. Move it. */ #define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 1 #endif diff --git a/include/grub/lib/cmdline.h b/include/grub/lib/cmdline.h index cdca09b7a..1fe8d0179 100644 --- a/include/grub/lib/cmdline.h +++ b/include/grub/lib/cmdline.h @@ -21,12 +21,11 @@ #define GRUB_CMDLINE_HEADER 1 #include -#include #define LINUX_IMAGE "BOOT_IMAGE=" unsigned int grub_loader_cmdline_size (int argc, char *argv[]); -grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf, - grub_size_t size, enum grub_verify_string_type type); +int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + grub_size_t size); #endif /* ! GRUB_CMDLINE_HEADER */ diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h new file mode 100644 index 000000000..8e93b6792 --- /dev/null +++ b/include/grub/libgcc.h @@ -0,0 +1,91 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +/* We need to include config-util.h.in for HAVE_*. */ +#ifndef __STDC_VERSION__ +#define __STDC_VERSION__ 0 +#endif +#include + +/* On x86 these functions aren't really needed. Save some space. */ +#if !defined (__i386__) && !defined (__x86_64__) +# ifdef HAVE___ASHLDI3 +void EXPORT_FUNC (__ashldi3) (void); +# endif +# ifdef HAVE___ASHRDI3 +void EXPORT_FUNC (__ashrdi3) (void); +# endif +# ifdef HAVE___LSHRDI3 +void EXPORT_FUNC (__lshrdi3) (void); +# endif +# ifdef HAVE___UCMPDI2 +void EXPORT_FUNC (__ucmpdi2) (void); +# endif +# ifdef HAVE___BSWAPSI2 +void EXPORT_FUNC (__bswapsi2) (void); +# endif +# ifdef HAVE___BSWAPDI2 +void EXPORT_FUNC (__bswapdi2) (void); +# endif +#endif + +#ifdef HAVE__RESTGPR_14_X +void EXPORT_FUNC (_restgpr_14_x) (void); +void EXPORT_FUNC (_restgpr_15_x) (void); +void EXPORT_FUNC (_restgpr_16_x) (void); +void EXPORT_FUNC (_restgpr_17_x) (void); +void EXPORT_FUNC (_restgpr_18_x) (void); +void EXPORT_FUNC (_restgpr_19_x) (void); +void EXPORT_FUNC (_restgpr_20_x) (void); +void EXPORT_FUNC (_restgpr_21_x) (void); +void EXPORT_FUNC (_restgpr_22_x) (void); +void EXPORT_FUNC (_restgpr_23_x) (void); +void EXPORT_FUNC (_restgpr_24_x) (void); +void EXPORT_FUNC (_restgpr_25_x) (void); +void EXPORT_FUNC (_restgpr_26_x) (void); +void EXPORT_FUNC (_restgpr_27_x) (void); +void EXPORT_FUNC (_restgpr_28_x) (void); +void EXPORT_FUNC (_restgpr_29_x) (void); +void EXPORT_FUNC (_restgpr_30_x) (void); +void EXPORT_FUNC (_restgpr_31_x) (void); +void EXPORT_FUNC (_savegpr_14) (void); +void EXPORT_FUNC (_savegpr_15) (void); +void EXPORT_FUNC (_savegpr_16) (void); +void EXPORT_FUNC (_savegpr_17) (void); +void EXPORT_FUNC (_savegpr_18) (void); +void EXPORT_FUNC (_savegpr_19) (void); +void EXPORT_FUNC (_savegpr_20) (void); +void EXPORT_FUNC (_savegpr_21) (void); +void EXPORT_FUNC (_savegpr_22) (void); +void EXPORT_FUNC (_savegpr_23) (void); +void EXPORT_FUNC (_savegpr_24) (void); +void EXPORT_FUNC (_savegpr_25) (void); +void EXPORT_FUNC (_savegpr_26) (void); +void EXPORT_FUNC (_savegpr_27) (void); +void EXPORT_FUNC (_savegpr_28) (void); +void EXPORT_FUNC (_savegpr_29) (void); +void EXPORT_FUNC (_savegpr_30) (void); +void EXPORT_FUNC (_savegpr_31) (void); +#endif + +#if defined (__arm__) +void EXPORT_FUNC (__aeabi_lasr) (void); +void EXPORT_FUNC (__aeabi_llsl) (void); +void EXPORT_FUNC (__aeabi_llsr) (void); +void EXPORT_FUNC (__aeabi_ulcmp) (void); +#endif diff --git a/include/grub/arm/coreboot/console.h b/include/grub/libusb.h similarity index 56% rename from include/grub/arm/coreboot/console.h rename to include/grub/libusb.h index 13a14b783..26548bccb 100644 --- a/include/grub/arm/coreboot/console.h +++ b/include/grub/libusb.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,14 +16,14 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_MACHINE_CONSOLE_HEADER -#define GRUB_MACHINE_CONSOLE_HEADER 1 - -void grub_video_coreboot_fb_init (void); -void grub_video_coreboot_fb_early_init (void); -void grub_video_coreboot_fb_late_init (void); -void grub_video_coreboot_fb_fini (void); - -extern struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable; - -#endif /* ! GRUB_MACHINE_CONSOLE_HEADER */ +void EXPORT_FUNC (usb_bulk_write) (void); +void EXPORT_FUNC (usb_find_busses) (void); +void EXPORT_FUNC (usb_init) (void); +void EXPORT_FUNC (usb_find_devices) (void); +void EXPORT_FUNC (usb_open) (void); +void EXPORT_FUNC (usb_get_busses) (void); +void EXPORT_FUNC (usb_control_msg) (void); +void EXPORT_FUNC (usb_release_interface) (void); +void EXPORT_FUNC (usb_close) (void); +void EXPORT_FUNC (usb_bulk_read) (void); +void EXPORT_FUNC (usb_claim_interface) (void); diff --git a/include/grub/list.h b/include/grub/list.h index b13acb962..d170ff6da 100644 --- a/include/grub/list.h +++ b/include/grub/list.h @@ -35,7 +35,6 @@ void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item); void EXPORT_FUNC(grub_list_remove) (grub_list_t item); #define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next) -#define FOR_LIST_ELEMENTS_NEXT(var, list) for ((var) = (var)->next; (var); (var) = (var)->next) #define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), ((nxt) = (var) ? (var)->next : 0)) static inline void * diff --git a/include/grub/loader.h b/include/grub/loader.h index b20864282..7f82a499f 100644 --- a/include/grub/loader.h +++ b/include/grub/loader.h @@ -33,7 +33,6 @@ enum { GRUB_LOADER_FLAG_NORETURN = 1, GRUB_LOADER_FLAG_PXE_NOT_UNLOAD = 2, - GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY = 4, }; void EXPORT_FUNC (grub_loader_set) (grub_err_t (*boot) (void), diff --git a/include/grub/machoload.h b/include/grub/machoload.h index f1157f410..1eec118f1 100644 --- a/include/grub/machoload.h +++ b/include/grub/machoload.h @@ -49,8 +49,7 @@ struct grub_macho_file }; typedef struct grub_macho_file *grub_macho_t; -grub_macho_t grub_macho_open (const char *, enum grub_file_type type, - int is_64bit); +grub_macho_t grub_macho_open (const char *, int is_64bit); grub_macho_t grub_macho_file (grub_file_t file, const char *filename, int is_64bit); grub_err_t grub_macho_close (grub_macho_t); diff --git a/include/grub/memory.h b/include/grub/memory.h index 6da114a1b..083cfb680 100644 --- a/include/grub/memory.h +++ b/include/grub/memory.h @@ -30,8 +30,6 @@ typedef enum grub_memory_type GRUB_MEMORY_ACPI = 3, GRUB_MEMORY_NVS = 4, GRUB_MEMORY_BADRAM = 5, - GRUB_MEMORY_PERSISTENT = 7, - GRUB_MEMORY_PERSISTENT_LEGACY = 12, GRUB_MEMORY_COREBOOT_TABLES = 16, GRUB_MEMORY_CODE = 20, /* This one is special: it's used internally but is never reported diff --git a/include/grub/mips/asm.h b/include/grub/mips/asm.h deleted file mode 100644 index 4c397f4a0..000000000 --- a/include/grub/mips/asm.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef GRUB_MIPS_ASM_HEADER -#define GRUB_MIPS_ASM_HEADER 1 - -#if defined(_MIPS_SIM) && defined(_ABIN32) && _MIPS_SIM == _ABIN32 -#define GRUB_ASM_T4 $a4 -#define GRUB_ASM_T5 $a5 -#define GRUB_ASM_SZREG 8 -#define GRUB_ASM_REG_S sd -#define GRUB_ASM_REG_L ld -#else -#define GRUB_ASM_T4 $t4 -#define GRUB_ASM_T5 $t5 -#define GRUB_ASM_SZREG 4 -#define GRUB_ASM_REG_S sw -#define GRUB_ASM_REG_L lw -#endif - -#endif diff --git a/include/grub/mips/multiboot.h b/include/grub/mips/multiboot.h index cdfb41e31..4aebf29e7 100644 --- a/include/grub/mips/multiboot.h +++ b/include/grub/mips/multiboot.h @@ -19,11 +19,11 @@ #ifndef GRUB_MULTIBOOT_CPU_HEADER #define GRUB_MULTIBOOT_CPU_HEADER 1 -#define MULTIBOOT2_INITIAL_STATE { .gpr[4] = MULTIBOOT2_BOOTLOADER_MAGIC, \ +#define MULTIBOOT_INITIAL_STATE { .gpr[4] = MULTIBOOT_BOOTLOADER_MAGIC, \ .jumpreg = 1 } #define MULTIBOOT_ENTRY_REGISTER gpr[1] #define MULTIBOOT_MBI_REGISTER gpr[5] -#define MULTIBOOT2_ARCHITECTURE_CURRENT MULTIBOOT2_ARCHITECTURE_MIPS32 +#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_MIPS32 #define MULTIBOOT_ELF32_MACHINE EM_MIPS #define MULTIBOOT_ELF64_MACHINE EM_MIPS diff --git a/include/grub/mips/setjmp.h b/include/grub/mips/setjmp.h index f8f6517ac..a99dde9ef 100644 --- a/include/grub/mips/setjmp.h +++ b/include/grub/mips/setjmp.h @@ -19,7 +19,7 @@ #ifndef GRUB_SETJMP_CPU_HEADER #define GRUB_SETJMP_CPU_HEADER 1 -typedef grub_uint64_t grub_jmp_buf[12]; +typedef unsigned long grub_jmp_buf[12]; int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); diff --git a/include/grub/misc.h b/include/grub/misc.h index b7ca6dd58..4b6ee06d4 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -71,6 +71,12 @@ grub_memcpy (void *dest, const void *src, grub_size_t n) return grub_memmove (dest, src, n); } +#if defined (__APPLE__) && defined(__i386__) && !defined (GRUB_UTIL) +#define GRUB_BUILTIN_ATTR __attribute__ ((regparm(0))) +#else +#define GRUB_BUILTIN_ATTR +#endif + #if defined(__x86_64__) && !defined (GRUB_UTIL) #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (__MINGW64__) #define GRUB_ASM_ATTR __attribute__ ((sysv_abi)) @@ -79,6 +85,19 @@ grub_memcpy (void *dest, const void *src, grub_size_t n) #endif #endif +/* Prototypes for aliases. */ +#ifndef GRUB_UTIL +int GRUB_BUILTIN_ATTR EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n); +void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n); +void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n); +void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memset) (void *s, int c, grub_size_t n); + +#ifdef __APPLE__ +void GRUB_BUILTIN_ATTR EXPORT_FUNC (__bzero) (void *s, grub_size_t n); +#endif + +#endif + int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n); int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2); int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n); @@ -243,29 +262,11 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) - (int) grub_tolower ((grub_uint8_t) *s2); } -/* - * Note that these differ from the C standard's definitions of strtol, - * strtoul(), and strtoull() by the addition of two const qualifiers on the end - * pointer, which make the declaration match the *semantic* requirements of - * their behavior. This means that instead of: - * - * char *s = "1234 abcd"; - * char *end; - * unsigned long l; - * - * l = grub_strtoul(s, &end, 10); - * - * We must one of: - * - * const char *end; - * ... or ... - * l = grub_strtoul(s, (const char ** const)&end, 10); - */ -unsigned long EXPORT_FUNC(grub_strtoul) (const char * restrict str, const char ** const restrict end, int base); -unsigned long long EXPORT_FUNC(grub_strtoull) (const char * restrict str, const char ** const restrict end, int base); +unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base); +unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base); static inline long -grub_strtol (const char * restrict str, const char ** const restrict end, int base) +grub_strtol (const char *str, char **end, int base) { int negative = 0; unsigned long long magnitude; @@ -340,7 +341,6 @@ grub_puts (const char *s) } int EXPORT_FUNC(grub_puts_) (const char *s); -int EXPORT_FUNC(grub_debug_enabled) (const char *condition); void EXPORT_FUNC(grub_real_dprintf) (const char *file, const int line, const char *condition, @@ -358,38 +358,13 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r); -/* Must match softdiv group in gentpl.py. */ -#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \ - (defined(__riscv) && (__riscv_xlen == 32))) -#define GRUB_DIVISION_IN_SOFTWARE 1 -#else -#define GRUB_DIVISION_IN_SOFTWARE 0 +#if (defined (__MINGW32__) || defined (__CYGWIN__)) && !defined(GRUB_UTIL) +void EXPORT_FUNC (__register_frame_info) (void); +void EXPORT_FUNC (__deregister_frame_info) (void); +void EXPORT_FUNC (___chkstk_ms) (void); +void EXPORT_FUNC (__chkstk_ms) (void); #endif -/* Some division functions need to be in kernel if compiler generates calls - to them. Otherwise we still need them for consistent tests but they go - into a separate module. */ -#if GRUB_DIVISION_IN_SOFTWARE -#define EXPORT_FUNC_IF_SOFTDIV EXPORT_FUNC -#else -#define EXPORT_FUNC_IF_SOFTDIV(x) x -#endif - -grub_int64_t -EXPORT_FUNC_IF_SOFTDIV(grub_divmod64s) (grub_int64_t n, - grub_int64_t d, - grub_int64_t *r); - -grub_uint32_t -EXPORT_FUNC_IF_SOFTDIV (grub_divmod32) (grub_uint32_t n, - grub_uint32_t d, - grub_uint32_t *r); - -grub_int32_t -EXPORT_FUNC_IF_SOFTDIV (grub_divmod32s) (grub_int32_t n, - grub_int32_t d, - grub_int32_t *r); - /* Inline functions. */ static inline char * @@ -416,8 +391,7 @@ grub_abs (int x) } /* Reboot the machine. */ -#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) || \ - defined (GRUB_MACHINE_EFI) +#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn)); #else void grub_reboot (void) __attribute__ ((noreturn)); @@ -459,6 +433,57 @@ grub_error_load (const struct grub_error_saved *save) grub_errno = save->grub_errno; } +#ifndef GRUB_UTIL + +#if defined (__arm__) + +grub_uint32_t +EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b); + +grub_uint32_t +EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b); + +#endif + +#if defined (__sparc__) || defined (__powerpc__) +unsigned +EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); +#define NEED_CTZDI2 1 +#endif + +#if defined (__mips__) || defined (__arm__) +unsigned +EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); +#define NEED_CTZSI2 1 +#endif + +#ifdef __arm__ +grub_uint32_t +EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); +grub_uint32_t +EXPORT_FUNC (__aeabi_uidivmod) (grub_uint32_t a, grub_uint32_t b); + +/* Needed for allowing modules to be compiled as thumb. */ +grub_uint64_t +EXPORT_FUNC (__muldi3) (grub_uint64_t a, grub_uint64_t b); +grub_uint64_t +EXPORT_FUNC (__aeabi_lmul) (grub_uint64_t a, grub_uint64_t b); + +#endif + +#if defined (__ia64__) + +grub_uint64_t +EXPORT_FUNC (__udivdi3) (grub_uint64_t a, grub_uint64_t b); + +grub_uint64_t +EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b); + +#endif + +#endif /* GRUB_UTIL */ + + #if BOOT_TIME_STATS struct grub_boot_time { diff --git a/include/grub/mm.h b/include/grub/mm.h index 9c38dd3ca..28e2e53eb 100644 --- a/include/grub/mm.h +++ b/include/grub/mm.h @@ -29,7 +29,6 @@ #endif void grub_mm_init_region (void *addr, grub_size_t size); -void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size); void *EXPORT_FUNC(grub_malloc) (grub_size_t size); void *EXPORT_FUNC(grub_zalloc) (grub_size_t size); void EXPORT_FUNC(grub_free) (void *ptr); @@ -49,9 +48,6 @@ extern int EXPORT_VAR(grub_mm_debug); void grub_mm_dump_free (void); void grub_mm_dump (unsigned lineno); -#define grub_calloc(nmemb, size) \ - grub_debug_calloc (GRUB_FILE, __LINE__, nmemb, size) - #define grub_malloc(size) \ grub_debug_malloc (GRUB_FILE, __LINE__, size) @@ -67,8 +63,6 @@ void grub_mm_dump (unsigned lineno); #define grub_free(ptr) \ grub_debug_free (GRUB_FILE, __LINE__, ptr) -void *EXPORT_FUNC(grub_debug_calloc) (const char *file, int line, - grub_size_t nmemb, grub_size_t size); void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line, grub_size_t size); void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line, diff --git a/include/grub/module_verifier.h b/include/grub/module_verifier.h deleted file mode 100644 index ba21c75e2..000000000 --- a/include/grub/module_verifier.h +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -#include - -#define GRUB_MODULE_VERIFY_SUPPORTS_REL 1 -#define GRUB_MODULE_VERIFY_SUPPORTS_RELA 2 - -struct grub_module_verifier_arch { - const char *name; - int voidp_sizeof; - int bigendian; - int machine; - int flags; - const int *supported_relocations; - const int *short_relocations; -}; - -void grub_module_verify64(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty); -void grub_module_verify32(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty); diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h index bd0a9873e..e13c0843b 100644 --- a/include/grub/multiboot.h +++ b/include/grub/multiboot.h @@ -22,11 +22,19 @@ #include +#ifdef GRUB_USE_MULTIBOOT2 +#include +/* Same thing as far as our loader is concerned. */ +#define MULTIBOOT_BOOTLOADER_MAGIC MULTIBOOT2_BOOTLOADER_MAGIC +#define MULTIBOOT_HEADER_MAGIC MULTIBOOT2_HEADER_MAGIC +#else #include +#endif #include #include +#ifndef GRUB_USE_MULTIBOOT2 typedef enum { GRUB_MULTIBOOT_QUIRKS_NONE = 0, @@ -34,6 +42,7 @@ typedef enum GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL = 2 } grub_multiboot_quirks_t; extern grub_multiboot_quirks_t grub_multiboot_quirks; +#endif extern struct grub_relocator *grub_multiboot_relocator; @@ -51,7 +60,7 @@ void grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize, unsigned shndx, void *data); -grub_uint32_t grub_multiboot_get_mmap_count (void); +grub_uint32_t grub_get_multiboot_mmap_count (void); grub_err_t grub_multiboot_set_video_mode (void); /* FIXME: support coreboot as well. */ @@ -82,28 +91,10 @@ grub_multiboot_set_console (int console_type, int accepted_consoles, int console_required); grub_err_t grub_multiboot_load (grub_file_t file, const char *filename); - -struct mbi_load_data -{ - grub_file_t file; - const char *filename; - void *buffer; - unsigned int mbi_ver; - int relocatable; - grub_uint32_t min_addr; - grub_uint32_t max_addr; - grub_size_t align; - grub_uint32_t preference; - grub_uint32_t link_base_addr; - grub_uint32_t load_base_addr; - int avoid_efi_boot_services; -}; -typedef struct mbi_load_data mbi_load_data_t; - /* Load ELF32 or ELF64. */ grub_err_t -grub_multiboot_load_elf (mbi_load_data_t *mld); - +grub_multiboot_load_elf (grub_file_t file, const char *filename, + void *buffer); extern grub_size_t grub_multiboot_pure_size; extern grub_size_t grub_multiboot_alloc_mbi; extern grub_uint32_t grub_multiboot_payload_eip; diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h deleted file mode 100644 index 502d34ef1..000000000 --- a/include/grub/multiboot2.h +++ /dev/null @@ -1,104 +0,0 @@ -/* multiboot.h - multiboot header file with grub definitions. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2007,2008,2010 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_MULTIBOOT2_HEADER -#define GRUB_MULTIBOOT2_HEADER 1 - -#include - -#include - -#include -#include - -extern struct grub_relocator *grub_multiboot2_relocator; - -void grub_multiboot2 (int argc, char *argv[]); -void grub_module2 (int argc, char *argv[]); - -void grub_multiboot2_set_accepts_video (int val); -grub_err_t grub_multiboot2_make_mbi (grub_uint32_t *target); -void grub_multiboot2_free_mbi (void); -grub_err_t grub_multiboot2_init_mbi (int argc, char *argv[]); -grub_err_t grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, - int argc, char *argv[]); -void grub_multiboot2_set_bootdev (void); -void -grub_multiboot2_add_elfsyms (grub_size_t num, grub_size_t entsize, - unsigned shndx, void *data); - -grub_uint32_t grub_multiboot2_get_mmap_count (void); -grub_err_t grub_multiboot2_set_video_mode (void); - -/* FIXME: support coreboot as well. */ -#if defined (GRUB_MACHINE_PCBIOS) -#define GRUB_MACHINE_HAS_VBE 1 -#else -#define GRUB_MACHINE_HAS_VBE 0 -#endif - -#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU) -#define GRUB_MACHINE_HAS_VGA_TEXT 1 -#else -#define GRUB_MACHINE_HAS_VGA_TEXT 0 -#endif - -#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) -#define GRUB_MACHINE_HAS_ACPI 1 -#else -#define GRUB_MACHINE_HAS_ACPI 0 -#endif - -#define GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT 1 -#define GRUB_MULTIBOOT2_CONSOLE_FRAMEBUFFER 2 - -grub_err_t -grub_multiboot2_set_console (int console_type, int accepted_consoles, - int width, int height, int depth, - int console_required); -grub_err_t -grub_multiboot2_load (grub_file_t file, const char *filename); - -struct mbi_load_data -{ - grub_file_t file; - const char *filename; - void *buffer; - unsigned int mbi_ver; - int relocatable; - grub_uint32_t min_addr; - grub_uint32_t max_addr; - grub_size_t align; - grub_uint32_t preference; - grub_uint32_t link_base_addr; - grub_uint32_t load_base_addr; - int avoid_efi_boot_services; -}; -typedef struct mbi_load_data mbi_load_data_t; - -/* Load ELF32 or ELF64. */ -grub_err_t -grub_multiboot2_load_elf (mbi_load_data_t *mld); - -extern grub_size_t grub_multiboot2_pure_size; -extern grub_size_t grub_multiboot2_alloc_mbi; -extern grub_uint32_t grub_multiboot2_payload_eip; - - -#endif /* ! GRUB_MULTIBOOT_HEADER */ diff --git a/include/grub/net.h b/include/grub/net.h index 7ae4b6bd8..66923e68c 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -191,18 +191,6 @@ typedef struct grub_net_network_level_netaddress }; } grub_net_network_level_netaddress_t; -struct grub_net_route -{ - struct grub_net_route *next; - struct grub_net_route **prev; - grub_net_network_level_netaddress_t target; - char *name; - struct grub_net_network_level_protocol *prot; - int is_gateway; - struct grub_net_network_level_interface *interface; - grub_net_network_level_address_t gw; -}; - #define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next) static inline grub_err_t @@ -280,6 +268,12 @@ typedef struct grub_net extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name); +struct grub_net_vlantag +{ + grub_uint8_t set; + grub_uint16_t vid; +}; + struct grub_net_network_level_interface { struct grub_net_network_level_interface *next; @@ -291,12 +285,7 @@ struct grub_net_network_level_interface grub_net_interface_flags_t flags; struct grub_net_bootp_packet *dhcp_ack; grub_size_t dhcp_acklen; - grub_uint16_t vlantag; - grub_uint32_t xid; /* DHCPv4 transaction id */ - grub_uint32_t srv_id; /* DHCPv4 server_identifier */ - grub_uint32_t my_ip; /* DHCPv4 offered IP address */ - unsigned dhcp_tmo_left; /* DHCPv4 running retransmission timeout */ - unsigned dhcp_tmo; /* DHCPv4 current retransmission timeout */ + struct grub_net_vlantag vlantag; void *data; }; @@ -385,16 +374,6 @@ grub_net_card_unregister (struct grub_net_card *card); #define FOR_NET_CARDS_SAFE(var, next) for (var = grub_net_cards, next = (var ? var->next : 0); var; var = next, next = (var ? var->next : 0)) -extern struct grub_net_route *grub_net_routes; - -static inline void -grub_net_route_register (struct grub_net_route *route) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), - GRUB_AS_LIST (route)); -} - -#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) struct grub_net_session * grub_net_open_tcp (char *address, grub_uint16_t port); @@ -420,8 +399,7 @@ grub_net_add_route (const char *name, grub_err_t grub_net_add_route_gw (const char *name, grub_net_network_level_netaddress_t target, - grub_net_network_level_address_t gw, - struct grub_net_network_level_interface *inter); + grub_net_network_level_address_t gw); #define GRUB_NET_BOOTP_MAC_ADDR_LEN 16 @@ -454,24 +432,15 @@ struct grub_net_bootp_packet enum { - GRUB_NET_BOOTP_PAD = 0, - GRUB_NET_BOOTP_NETMASK = 1, - GRUB_NET_BOOTP_ROUTER = 3, - GRUB_NET_BOOTP_DNS = 6, - GRUB_NET_BOOTP_HOSTNAME = 12, - GRUB_NET_BOOTP_DOMAIN = 15, - GRUB_NET_BOOTP_ROOT_PATH = 17, - GRUB_NET_BOOTP_EXTENSIONS_PATH = 18, - GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50, - GRUB_NET_DHCP_OVERLOAD = 52, - GRUB_NET_DHCP_MESSAGE_TYPE = 53, - GRUB_NET_DHCP_SERVER_IDENTIFIER = 54, - GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55, - GRUB_NET_BOOTP_CLIENT_ID = 61, - GRUB_NET_DHCP_TFTP_SERVER_NAME = 66, - GRUB_NET_DHCP_BOOTFILE_NAME = 67, - GRUB_NET_BOOTP_CLIENT_UUID = 97, - GRUB_NET_BOOTP_END = 255 + GRUB_NET_BOOTP_PAD = 0x00, + GRUB_NET_BOOTP_NETMASK = 0x01, + GRUB_NET_BOOTP_ROUTER = 0x03, + GRUB_NET_BOOTP_DNS = 0x06, + GRUB_NET_BOOTP_HOSTNAME = 0x0c, + GRUB_NET_BOOTP_DOMAIN = 0x0f, + GRUB_NET_BOOTP_ROOT_PATH = 0x11, + GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, + GRUB_NET_BOOTP_END = 0xff }; struct grub_net_network_level_interface * @@ -488,7 +457,7 @@ grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf, void grub_net_process_dhcp (struct grub_net_buff *nb, - struct grub_net_network_level_interface *iface); + struct grub_net_card *card); int grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, @@ -569,8 +538,6 @@ grub_net_add_dns_server (const struct grub_net_network_level_address *s); void grub_net_remove_dns_server (const struct grub_net_network_level_address *s); -grub_err_t -grub_net_search_config_file (char *config); extern char *grub_net_default_server; diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h index 8d9d08113..56336b356 100644 --- a/include/grub/net/arp.h +++ b/include/grub/net/arp.h @@ -23,7 +23,7 @@ extern grub_err_t grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, - grub_uint16_t *vlantag); + grub_uint16_t vlantag_vid); grub_err_t grub_net_arp_send_request (struct grub_net_network_level_interface *inf, diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h index ab9d68f98..8cd0bfdc0 100644 --- a/include/grub/net/ip.h +++ b/include/grub/net/ip.h @@ -49,7 +49,7 @@ grub_net_recv_ip_packets (struct grub_net_buff *nb, struct grub_net_card *card, const grub_net_link_level_address_t *hwaddress, const grub_net_link_level_address_t *src_hwaddress, - grub_uint16_t *vlantag); + grub_uint16_t vlantag_vid); grub_err_t grub_net_send_ip_packet (struct grub_net_network_level_interface *inf, diff --git a/include/grub/net/netbuff.h b/include/grub/net/netbuff.h index 1177c1220..9ac168c89 100644 --- a/include/grub/net/netbuff.h +++ b/include/grub/net/netbuff.h @@ -25,7 +25,6 @@ grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff, grub_size_t len); grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff, grub_size_t len); grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff); struct grub_net_buff * grub_netbuff_alloc (grub_size_t len); -struct grub_net_buff * grub_netbuff_make_pkt (grub_size_t len); void grub_netbuff_free (struct grub_net_buff *net_buff); #endif diff --git a/include/grub/offsets.h b/include/grub/offsets.h index 871e1cd4c..85e7401ae 100644 --- a/include/grub/offsets.h +++ b/include/grub/offsets.h @@ -36,10 +36,9 @@ #define GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE (0x9000-0x8200) /* The segment where the kernel is loaded. */ -#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800 +#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800 -#define GRUB_KERNEL_I386_PC_LINK_ADDR 0x9000 -#define GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR 0x100000 +#define GRUB_KERNEL_I386_PC_LINK_ADDR 0x9000 /* The upper memory area (starting at 640 kiB). */ #define GRUB_MEMORY_I386_PC_UPPER 0xa0000 @@ -51,11 +50,10 @@ /* The offset of GRUB_CORE_ENTRY_ADDR. */ #define GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR 0x8 -#define GRUB_KERNEL_I386_QEMU_LINK_ADDR 0x9000 +#define GRUB_KERNEL_I386_QEMU_LINK_ADDR 0x8200 /* The offset of GRUB_TOTAL_MODULE_SIZE. */ #define GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE 0x8 -#define GRUB_KERNEL_ARM_STACK_SIZE 0x40000 #define GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE 12 @@ -92,7 +90,7 @@ #define GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE 0x08 -#define GRUB_KERNEL_I386_COREBOOT_LINK_ADDR 0x9000 +#define GRUB_KERNEL_I386_COREBOOT_LINK_ADDR 0x8200 #define GRUB_KERNEL_I386_COREBOOT_MODULES_ADDR 0x100000 #define GRUB_KERNEL_I386_IEEE1275_LINK_ADDR 0x10000 @@ -102,17 +100,15 @@ #define GRUB_KERNEL_I386_MULTIBOOT_MOD_ALIGN GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN #define GRUB_KERNEL_X86_64_XEN_MOD_ALIGN 0x8 -#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8 -#define GRUB_KERNEL_I386_XEN_PVH_MOD_ALIGN 0x8 +#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8 /* Non-zero value is only needed for PowerMacs. */ -#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0 -#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0 -#define GRUB_KERNEL_I386_XEN_PVH_MOD_GAP 0x0 -#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0 -#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0 -#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0 -#define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0 +#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0 +#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0 +#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0 +#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0 +#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0 +#define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0 #define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000 #define GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN 3 @@ -124,12 +120,7 @@ #define GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN 0x8 #define GRUB_KERNEL_ARM_UBOOT_TOTAL_MODULE_SIZE 0x4 - -#define GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN 0x8 -#define GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE 0x4 - -#define GRUB_KERNEL_ARM_STACK_SIZE 0x40000 -#define GRUB_KERNEL_ARM_COREBOOT_MOD_GAP (GRUB_KERNEL_ARM_STACK_SIZE + 1024) +#define GRUB_KERNEL_ARM_UBOOT_LINK_ADDR 0x08000000 /* Minimal gap between _end and the start of the modules. It's a hack for PowerMac to prevent "CLAIM failed" error. The real fix is to diff --git a/include/grub/osdep/hostfile_aros.h b/include/grub/osdep/hostfile_aros.h index 161fbb7bd..a059c0fa4 100644 --- a/include/grub/osdep/hostfile_aros.h +++ b/include/grub/osdep/hostfile_aros.h @@ -68,12 +68,6 @@ grub_util_rename (const char *from, const char *to) return rename (from, to); } -static inline ssize_t -grub_util_readlink (const char *name, char *buf, size_t bufsize) -{ - return readlink(name, buf, bufsize); -} - #define grub_util_mkdir(a) mkdir ((a), 0755) struct grub_util_fd diff --git a/include/grub/osdep/hostfile_unix.h b/include/grub/osdep/hostfile_unix.h index 17cd3aa8b..9ffe46fa3 100644 --- a/include/grub/osdep/hostfile_unix.h +++ b/include/grub/osdep/hostfile_unix.h @@ -71,12 +71,6 @@ grub_util_rename (const char *from, const char *to) return rename (from, to); } -static inline ssize_t -grub_util_readlink (const char *name, char *buf, size_t bufsize) -{ - return readlink(name, buf, bufsize); -} - #define grub_util_mkdir(a) mkdir ((a), 0755) #if defined (__NetBSD__) diff --git a/include/grub/pci.h b/include/grub/pci.h index 262c89b74..70d9a0513 100644 --- a/include/grub/pci.h +++ b/include/grub/pci.h @@ -142,7 +142,27 @@ grub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev, void EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook, void *hook_data); -#include +struct grub_pci_dma_chunk; + +struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align, + grub_size_t size); +void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch); +volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch); +grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch); + +static inline void * +grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk) +{ + return ((grub_uint8_t *) grub_dma_get_virt (chunk) + + (phys - grub_dma_get_phys (chunk))); +} + +static inline grub_uint32_t +grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk) +{ + return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk)) + + grub_dma_get_phys (chunk)); +} grub_uint8_t EXPORT_FUNC (grub_pci_find_capability) (grub_pci_device_t dev, grub_uint8_t cap); diff --git a/include/grub/ps2.h b/include/grub/ps2.h deleted file mode 100644 index 4f2e527e4..000000000 --- a/include/grub/ps2.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_PS2_HEADER -#define GRUB_PS2_HEADER 1 - -#include - -#define GRUB_AT_ACK 0xfa -#define GRUB_AT_NACK 0xfe -#define GRUB_AT_TRIES 5 - -/* Make sure it's zeroed-out and set current_set at init. */ -struct grub_ps2_state -{ - int e0_received; - int f0_received; - grub_uint8_t led_status; - short at_keyboard_status; - grub_uint8_t current_set; -}; - -/* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */ -int -grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state, - grub_uint8_t data); - -#endif diff --git a/include/grub/pubkey.h b/include/grub/pubkey.h index fb8be9cbb..4a9d04b43 100644 --- a/include/grub/pubkey.h +++ b/include/grub/pubkey.h @@ -25,7 +25,7 @@ struct grub_public_key * grub_load_public_key (grub_file_t f); grub_err_t -grub_verify_signature (grub_file_t f, const char *fsig, +grub_verify_signature (grub_file_t f, grub_file_t sig, struct grub_public_key *pk); diff --git a/include/grub/random.h b/include/grub/random.h deleted file mode 100644 index 4b75c0e2b..000000000 --- a/include/grub/random.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2016 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_RANDOM_HEADER -#define GRUB_RANDOM_HEADER 1 - -#include -#include - -/* Not peer-reviewed. May not be any better than string of zeros. */ -grub_err_t -grub_crypto_get_random (void *buffer, grub_size_t sz); - -/* Do not use directly. Use grub_crypto_get_random instead. */ -int -grub_crypto_arch_get_random (void *buffer, grub_size_t sz); - -#endif diff --git a/include/grub/relocator.h b/include/grub/relocator.h index 1b3bdd92a..24d8672d2 100644 --- a/include/grub/relocator.h +++ b/include/grub/relocator.h @@ -49,35 +49,6 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, int preference, int avoid_efi_boot_services); -/* - * Wrapper for grub_relocator_alloc_chunk_align() with purpose of - * protecting against integer underflow. - * - * Compare to its callee, max_addr has different meaning here. - * It covers entire chunk and not just start address of the chunk. - */ -static inline grub_err_t -grub_relocator_alloc_chunk_align_safe (struct grub_relocator *rel, - grub_relocator_chunk_t *out, - grub_phys_addr_t min_addr, - grub_phys_addr_t max_addr, - grub_size_t size, grub_size_t align, - int preference, - int avoid_efi_boot_services) -{ - /* Sanity check and ensure following equation (max_addr - size) is safe. */ - if (max_addr < size || (max_addr - size) < min_addr) - return GRUB_ERR_OUT_OF_RANGE; - - return grub_relocator_alloc_chunk_align (rel, out, min_addr, - max_addr - size, - size, align, preference, - avoid_efi_boot_services); -} - -/* Top 32-bit address minus s bytes and plus 1 byte. */ -#define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1) - #define GRUB_RELOCATOR_PREFERENCE_NONE 0 #define GRUB_RELOCATOR_PREFERENCE_LOW 1 #define GRUB_RELOCATOR_PREFERENCE_HIGH 2 diff --git a/include/grub/riscv32/efi/memory.h b/include/grub/riscv32/efi/memory.h deleted file mode 100644 index e61c474ff..000000000 --- a/include/grub/riscv32/efi/memory.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GRUB_MEMORY_CPU_HEADER -#include - -#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffUL - -#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h deleted file mode 100644 index 512b777c8..000000000 --- a/include/grub/riscv32/linux.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_RISCV32_LINUX_HEADER -#define GRUB_RISCV32_LINUX_HEADER 1 - -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ - -/* From linux/Documentation/riscv/booting.txt */ -struct linux_riscv_kernel_header -{ - grub_uint32_t code0; /* Executable code */ - grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ - grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ - grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ -}; - -#define linux_arch_kernel_header linux_riscv_kernel_header - -#endif /* ! GRUB_RISCV32_LINUX_HEADER */ diff --git a/include/grub/riscv32/setjmp.h b/include/grub/riscv32/setjmp.h deleted file mode 100644 index 5a2123846..000000000 --- a/include/grub/riscv32/setjmp.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_SETJMP_CPU_HEADER -#define GRUB_SETJMP_CPU_HEADER 1 - -typedef unsigned long long grub_jmp_buf[14]; - -int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; -void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); - -#endif /* ! GRUB_SETJMP_CPU_HEADER */ diff --git a/include/grub/riscv32/time.h b/include/grub/riscv32/time.h deleted file mode 100644 index 20abd648b..000000000 --- a/include/grub/riscv32/time.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef KERNEL_CPU_TIME_HEADER -#define KERNEL_CPU_TIME_HEADER 1 - -static __inline void -grub_cpu_idle (void) -{ - /* TODO */ -} - -#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv32/types.h b/include/grub/riscv32/types.h deleted file mode 100644 index fac57a752..000000000 --- a/include/grub/riscv32/types.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_TYPES_CPU_HEADER -#define GRUB_TYPES_CPU_HEADER 1 - -/* The size of void *. */ -#define GRUB_TARGET_SIZEOF_VOID_P 4 - -/* The size of long. */ -#define GRUB_TARGET_SIZEOF_LONG 4 - -/* currently only support little-endian. */ -#undef GRUB_TARGET_WORDS_BIGENDIAN - -/* Unaligned accesses can be very slow, so avoid them */ -#undef GRUB_HAVE_UNALIGNED_ACCESS - -#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h deleted file mode 100644 index c6cb32417..000000000 --- a/include/grub/riscv64/efi/memory.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GRUB_MEMORY_CPU_HEADER -#include - -#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL - -#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h deleted file mode 100644 index 3630c30fb..000000000 --- a/include/grub/riscv64/linux.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_RISCV64_LINUX_HEADER -#define GRUB_RISCV64_LINUX_HEADER 1 - -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ - -#define GRUB_EFI_PE_MAGIC 0x5A4D - -/* From linux/Documentation/riscv/booting.txt */ -struct linux_riscv_kernel_header -{ - grub_uint32_t code0; /* Executable code */ - grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ - grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ - grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ -}; - -#define linux_arch_kernel_header linux_riscv_kernel_header - -#endif /* ! GRUB_RISCV64_LINUX_HEADER */ diff --git a/include/grub/riscv64/setjmp.h b/include/grub/riscv64/setjmp.h deleted file mode 100644 index 5a2123846..000000000 --- a/include/grub/riscv64/setjmp.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_SETJMP_CPU_HEADER -#define GRUB_SETJMP_CPU_HEADER 1 - -typedef unsigned long long grub_jmp_buf[14]; - -int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; -void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); - -#endif /* ! GRUB_SETJMP_CPU_HEADER */ diff --git a/include/grub/riscv64/time.h b/include/grub/riscv64/time.h deleted file mode 100644 index 20abd648b..000000000 --- a/include/grub/riscv64/time.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef KERNEL_CPU_TIME_HEADER -#define KERNEL_CPU_TIME_HEADER 1 - -static __inline void -grub_cpu_idle (void) -{ - /* TODO */ -} - -#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv64/types.h b/include/grub/riscv64/types.h deleted file mode 100644 index c6bcad470..000000000 --- a/include/grub/riscv64/types.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_TYPES_CPU_HEADER -#define GRUB_TYPES_CPU_HEADER 1 - -/* The size of void *. */ -#define GRUB_TARGET_SIZEOF_VOID_P 8 - -/* The size of long. */ -#define GRUB_TARGET_SIZEOF_LONG 8 - -/* currently only support little-endian. */ -#undef GRUB_TARGET_WORDS_BIGENDIAN - -/* Unaligned accesses can be very slow, so avoid them */ -#undef GRUB_HAVE_UNALIGNED_ACCESS - -#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/safemath.h b/include/grub/safemath.h deleted file mode 100644 index c17b89bba..000000000 --- a/include/grub/safemath.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2020 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - * - * Arithmetic operations that protect against overflow. - */ - -#ifndef GRUB_SAFEMATH_H -#define GRUB_SAFEMATH_H 1 - -#include - -/* These appear in gcc 5.1 and clang 3.8. */ -#if GNUC_PREREQ(5, 1) || CLANG_PREREQ(3, 8) - -#define grub_add(a, b, res) __builtin_add_overflow(a, b, res) -#define grub_sub(a, b, res) __builtin_sub_overflow(a, b, res) -#define grub_mul(a, b, res) __builtin_mul_overflow(a, b, res) - -#else -#error gcc 5.1 or newer or clang 3.8 or newer is required -#endif - -#endif /* GRUB_SAFEMATH_H */ diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h index e5b4d8450..360c2be1f 100644 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@ -318,7 +318,7 @@ void *grub_script_malloc (struct grub_parser_param *state, grub_size_t size); union YYSTYPE; int grub_script_yylex (union YYSTYPE *, struct grub_parser_param *); int grub_script_yyparse (struct grub_parser_param *); -void grub_script_yyerror (struct grub_parser_param *, const char *); +void grub_script_yyerror (struct grub_parser_param *, char const *); /* Commands to execute, don't use these directly. */ grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd); @@ -359,10 +359,13 @@ struct grub_script_function /* The script function. */ struct grub_script *func; + /* The flags. */ + unsigned flags; + /* The next element. */ struct grub_script_function *next; - unsigned executing; + int references; }; typedef struct grub_script_function *grub_script_function_t; diff --git a/include/grub/smbios.h b/include/grub/smbios.h deleted file mode 100644 index 15ec260b3..000000000 --- a/include/grub/smbios.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2019 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_SMBIOS_HEADER -#define GRUB_SMBIOS_HEADER 1 - -#include -#include - -#define GRUB_SMBIOS_TYPE_END_OF_TABLE ((grub_uint8_t)127) - -struct grub_smbios_ieps -{ - grub_uint8_t anchor[5]; /* "_DMI_" */ - grub_uint8_t checksum; - grub_uint16_t table_length; - grub_uint32_t table_address; - grub_uint16_t structures; - grub_uint8_t revision; -} GRUB_PACKED; - -struct grub_smbios_eps -{ - grub_uint8_t anchor[4]; /* "_SM_" */ - grub_uint8_t checksum; - grub_uint8_t length; /* 0x1f */ - grub_uint8_t version_major; - grub_uint8_t version_minor; - grub_uint16_t maximum_structure_size; - grub_uint8_t revision; - grub_uint8_t formatted[5]; - struct grub_smbios_ieps intermediate; -} GRUB_PACKED; - -struct grub_smbios_eps3 -{ - grub_uint8_t anchor[5]; /* "_SM3_" */ - grub_uint8_t checksum; - grub_uint8_t length; /* 0x18 */ - grub_uint8_t version_major; - grub_uint8_t version_minor; - grub_uint8_t docrev; - grub_uint8_t revision; - grub_uint8_t reserved; - grub_uint32_t maximum_table_length; - grub_uint64_t table_address; -} GRUB_PACKED; - -extern struct grub_smbios_eps *grub_machine_smbios_get_eps (void); -extern struct grub_smbios_eps3 *grub_machine_smbios_get_eps3 (void); - -extern struct grub_smbios_eps *EXPORT_FUNC (grub_smbios_get_eps) (void); - -#endif /* ! GRUB_SMBIOS_HEADER */ diff --git a/include/grub/sparc64/ieee1275/boot.h b/include/grub/sparc64/ieee1275/boot.h index cc5a941e3..02d53f28e 100644 --- a/include/grub/sparc64/ieee1275/boot.h +++ b/include/grub/sparc64/ieee1275/boot.h @@ -46,7 +46,8 @@ #define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80 -#define GRUB_BOOT_MACHINE_CODE_END 0x1fc +#define GRUB_BOOT_MACHINE_CODE_END \ + (0x1fc - GRUB_BOOT_AOUT_HEADER_SIZE) #define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200 diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index 4b18468d8..32c77f80f 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -42,8 +42,6 @@ extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr, extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr, grub_size_t size, grub_uint32_t align); -extern grub_uint64_t EXPORT_FUNC(grub_ieee1275_num_blocks) (grub_uint32_t ihandle); -extern grub_uint64_t EXPORT_FUNC(grub_ieee1275_num_blocks64) (grub_uint32_t ihandle); extern grub_addr_t EXPORT_VAR (grub_ieee1275_original_stack); diff --git a/include/grub/term.h b/include/grub/term.h index 3387cb052..5ffb38f69 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -55,8 +55,7 @@ #define GRUB_TERM_KEY_INSERT (GRUB_TERM_EXTENDED | 0x52) #define GRUB_TERM_KEY_CENTER (GRUB_TERM_EXTENDED | 0x4c) -/* Hex value is used for ESC, since '\e' is nonstandard */ -#define GRUB_TERM_ESC 0x1b +#define GRUB_TERM_ESC '\e' #define GRUB_TERM_TAB '\t' #define GRUB_TERM_BACKSPACE '\b' @@ -75,11 +74,9 @@ /* These are used to represent the various color states we use. */ typedef enum { - /* Used for uninitialized grub_term_color_state variables */ - GRUB_TERM_COLOR_UNDEFINED = -1, /* The color used to display all text that does not use the user defined colors below. */ - GRUB_TERM_COLOR_STANDARD = 0, + GRUB_TERM_COLOR_STANDARD, /* The user defined colors for normal text. */ GRUB_TERM_COLOR_NORMAL, /* The user defined colors for highlighted text. */ @@ -329,8 +326,6 @@ grub_term_unregister_output (grub_term_output_t term) void grub_putcode (grub_uint32_t code, struct grub_term_output *term); int EXPORT_FUNC(grub_getkey) (void); int EXPORT_FUNC(grub_getkey_noblock) (void); -int EXPORT_FUNC(grub_getkeystatus) (void); -int EXPORT_FUNC(grub_key_is_interrupt) (int key); void grub_cls (void); void EXPORT_FUNC(grub_refresh) (void); void grub_puts_terminal (const char *str, struct grub_term_output *term); diff --git a/include/grub/tpm.h b/include/grub/tpm.h deleted file mode 100644 index 5c285cbc5..000000000 --- a/include/grub/tpm.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_TPM_HEADER -#define GRUB_TPM_HEADER 1 - -#define GRUB_STRING_PCR 8 -#define GRUB_BINARY_PCR 9 - -#define SHA1_DIGEST_SIZE 20 - -#define TPM_BASE 0x0 -#define TPM_SUCCESS TPM_BASE -#define TPM_AUTHFAIL (TPM_BASE + 0x1) -#define TPM_BADINDEX (TPM_BASE + 0x2) - -#define TPM_TAG_RQU_COMMAND 0x00C1 -#define TPM_ORD_Extend 0x14 - -#define EV_IPL 0x0d - -grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size, - grub_uint8_t pcr, const char *description); -#endif diff --git a/include/grub/types.h b/include/grub/types.h index 035a4b528..79f765c62 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -130,26 +130,23 @@ typedef grub_int32_t grub_ssize_t; # define PRIdGRUB_SSIZE "d" #endif -#define GRUB_SCHAR_MAX 127 -#define GRUB_SCHAR_MIN (-GRUB_SCHAR_MAX - 1) #define GRUB_UCHAR_MAX 0xFF #define GRUB_USHRT_MAX 65535 #define GRUB_SHRT_MAX 0x7fff -#define GRUB_SHRT_MIN (-GRUB_SHRT_MAX - 1) #define GRUB_UINT_MAX 4294967295U #define GRUB_INT_MAX 0x7fffffff -#define GRUB_INT_MIN (-GRUB_INT_MAX - 1) +#define GRUB_INT32_MIN (-2147483647 - 1) #define GRUB_INT32_MAX 2147483647 -#define GRUB_INT32_MIN (-GRUB_INT32_MAX - 1) #if GRUB_CPU_SIZEOF_LONG == 8 # define GRUB_ULONG_MAX 18446744073709551615UL # define GRUB_LONG_MAX 9223372036854775807L +# define GRUB_LONG_MIN (-9223372036854775807L - 1) #else # define GRUB_ULONG_MAX 4294967295UL # define GRUB_LONG_MAX 2147483647L +# define GRUB_LONG_MIN (-2147483647L - 1) #endif -# define GRUB_LONG_MIN (-GRUB_LONG_MAX - 1) typedef grub_uint64_t grub_properly_aligned_t; @@ -182,7 +179,7 @@ static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x) | (_x >> 56)); \ }) -#if (defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)) || defined(__clang__) +#if defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3) static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t x) { return __builtin_bswap32(x); @@ -257,49 +254,55 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t _x) #endif /* ! WORDS_BIGENDIAN */ -struct grub_unaligned_uint16 +static inline grub_uint16_t grub_get_unaligned16 (const void *ptr) { - grub_uint16_t val; -} GRUB_PACKED; -struct grub_unaligned_uint32 + struct grub_unaligned_uint16_t + { + grub_uint16_t d; + } GRUB_PACKED; + const struct grub_unaligned_uint16_t *dd + = (const struct grub_unaligned_uint16_t *) ptr; + return dd->d; +} + +static inline void grub_set_unaligned16 (void *ptr, grub_uint16_t val) { - grub_uint32_t val; -} GRUB_PACKED; + struct grub_unaligned_uint16_t + { + grub_uint16_t d; + } GRUB_PACKED; + struct grub_unaligned_uint16_t *dd = (struct grub_unaligned_uint16_t *) ptr; + dd->d = val; +} + +static inline grub_uint32_t grub_get_unaligned32 (const void *ptr) +{ + struct grub_unaligned_uint32_t + { + grub_uint32_t d; + } GRUB_PACKED; + const struct grub_unaligned_uint32_t *dd + = (const struct grub_unaligned_uint32_t *) ptr; + return dd->d; +} + +static inline void grub_set_unaligned32 (void *ptr, grub_uint32_t val) +{ + struct grub_unaligned_uint32_t + { + grub_uint32_t d; + } GRUB_PACKED; + struct grub_unaligned_uint32_t *dd = (struct grub_unaligned_uint32_t *) ptr; + dd->d = val; +} + struct grub_unaligned_uint64 { grub_uint64_t val; } GRUB_PACKED; -typedef struct grub_unaligned_uint16 grub_unaligned_uint16_t; -typedef struct grub_unaligned_uint32 grub_unaligned_uint32_t; typedef struct grub_unaligned_uint64 grub_unaligned_uint64_t; -static inline grub_uint16_t grub_get_unaligned16 (const void *ptr) -{ - const struct grub_unaligned_uint16 *dd - = (const struct grub_unaligned_uint16 *) ptr; - return dd->val; -} - -static inline void grub_set_unaligned16 (void *ptr, grub_uint16_t val) -{ - struct grub_unaligned_uint16 *dd = (struct grub_unaligned_uint16 *) ptr; - dd->val = val; -} - -static inline grub_uint32_t grub_get_unaligned32 (const void *ptr) -{ - const struct grub_unaligned_uint32 *dd - = (const struct grub_unaligned_uint32 *) ptr; - return dd->val; -} - -static inline void grub_set_unaligned32 (void *ptr, grub_uint32_t val) -{ - struct grub_unaligned_uint32 *dd = (struct grub_unaligned_uint32 *) ptr; - dd->val = val; -} - static inline grub_uint64_t grub_get_unaligned64 (const void *ptr) { const struct grub_unaligned_uint64 *dd diff --git a/include/grub/uboot/uboot.h b/include/grub/uboot/uboot.h index 194130345..c122de6ab 100644 --- a/include/grub/uboot/uboot.h +++ b/include/grub/uboot/uboot.h @@ -72,8 +72,7 @@ int EXPORT_FUNC (grub_uboot_dev_enum) (void); struct device_info * EXPORT_FUNC (grub_uboot_dev_get) (int index); int EXPORT_FUNC (grub_uboot_dev_open) (struct device_info *dev); int EXPORT_FUNC (grub_uboot_dev_close) (struct device_info *dev); -int grub_uboot_dev_write (struct device_info *dev, const void *buf, - grub_size_t blocks, grub_uint32_t start); +int grub_uboot_dev_write (struct device_info *dev, void *buf, int *len); int grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks, grub_uint32_t start, grub_size_t * real_blocks); int EXPORT_FUNC (grub_uboot_dev_recv) (struct device_info *dev, void *buf, diff --git a/include/grub/unicode.h b/include/grub/unicode.h index 4de986a85..a0403e91f 100644 --- a/include/grub/unicode.h +++ b/include/grub/unicode.h @@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) grub_memcpy (out, in, sizeof (*in)); if (in->ncomb > ARRAY_SIZE (out->combining_inline)) { - out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); if (!out->combining_ptr) { grub_free (out); @@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, grub_memcpy (out, in, sizeof (*in)); if (in->ncomb > ARRAY_SIZE (out->combining_inline)) { - out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); if (!out->combining_ptr) return; grub_memcpy (out->combining_ptr, in->combining_ptr, diff --git a/include/grub/usb.h b/include/grub/usb.h index 512ae1dd0..11d96481f 100644 --- a/include/grub/usb.h +++ b/include/grub/usb.h @@ -321,9 +321,5 @@ grub_usb_err_t grub_usb_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual); void grub_usb_cancel_transfer (grub_usb_transfer_t trans); -void -grub_ehci_init_device (volatile void *regs); -void -grub_ehci_pci_scan (void); #endif /* GRUB_USB_H */ diff --git a/include/grub/util/install.h b/include/grub/util/install.h index 2631b1074..aedcd29f9 100644 --- a/include/grub/util/install.h +++ b/include/grub/util/install.h @@ -29,8 +29,6 @@ #define GRUB_INSTALL_OPTIONS \ { "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \ 0, N_("pre-load specified modules MODULES"), 1 }, \ - { "dtb", GRUB_INSTALL_OPTIONS_DTB, N_("FILE"), \ - 0, N_("embed a specific DTB"), 1 }, \ { "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \ N_("MODULES"), 0, \ N_("install only MODULES and their dependencies [default=all]"), 1 }, \ @@ -41,7 +39,7 @@ { "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\ 0, N_("install only LOCALES [default=all]"), 1 }, \ { "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \ - "no|xz|gz|lzo", 0, \ + "no,xz,gz,lzo", OPTION_ARG_OPTIONAL, \ N_("compress GRUB files [optional]"), 1 }, \ {"core-compress", GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, \ "xz|none|auto", \ @@ -100,11 +98,7 @@ enum grub_install_plat GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS, GRUB_INSTALL_PLATFORM_I386_XEN, GRUB_INSTALL_PLATFORM_X86_64_XEN, - GRUB_INSTALL_PLATFORM_I386_XEN_PVH, GRUB_INSTALL_PLATFORM_ARM64_EFI, - GRUB_INSTALL_PLATFORM_ARM_COREBOOT, - GRUB_INSTALL_PLATFORM_RISCV32_EFI, - GRUB_INSTALL_PLATFORM_RISCV64_EFI, GRUB_INSTALL_PLATFORM_MAX }; @@ -121,8 +115,7 @@ enum grub_install_options { GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY, GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY, GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, - GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, - GRUB_INSTALL_OPTIONS_DTB + GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS }; extern char *grub_install_source_directory; @@ -183,7 +176,7 @@ grub_install_generate_image (const char *dir, const char *prefix, char *config_path, const struct grub_install_image_target_desc *image_target, int note, - grub_compression_t comp, const char *dtb_file); + grub_compression_t comp); const struct grub_install_image_target_desc * grub_install_get_image_target (const char *arg); @@ -210,13 +203,10 @@ grub_util_get_target_dirname (const struct grub_install_image_target_desc *t); void grub_install_create_envblk_file (const char *name); -const char * -grub_install_get_default_arm_platform (void); - const char * grub_install_get_default_x86_platform (void); -int +void grub_install_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, const char *efi_distributor); diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index e9e0a6724..192874d42 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -41,7 +41,7 @@ void grub_util_write_image_at (const void *img, size_t size, off_t offset, char *make_system_path_relative_to_its_root (const char *path); -char *grub_canonicalize_file_name (const char *path); +char *canonicalize_file_name (const char *path); void grub_util_init_nls (void); diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h deleted file mode 100644 index ba9f568f6..000000000 --- a/include/grub/util/mkimage.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_UTIL_MKIMAGE_HEADER -#define GRUB_UTIL_MKIMAGE_HEADER 1 - -struct grub_mkimage_layout -{ - size_t exec_size; - size_t kernel_size; - size_t bss_size; - grub_uint64_t start_address; - void *reloc_section; - size_t reloc_size; - size_t align; - grub_size_t ia64jmp_off; - grub_size_t tramp_off; - grub_size_t got_off; - grub_size_t got_size; - unsigned ia64jmpnum; - grub_uint32_t bss_start; - grub_uint32_t end; -}; - -/* Private header. Use only in mkimage-related sources. */ -char * -grub_mkimage_load_image32 (const char *kernel_path, - size_t total_module_size, - struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target); -char * -grub_mkimage_load_image64 (const char *kernel_path, - size_t total_module_size, - struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target); -void -grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target, - int note, char **core_img, size_t *core_size, - Elf32_Addr target_addr, - struct grub_mkimage_layout *layout); -void -grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target, - int note, char **core_img, size_t *core_size, - Elf64_Addr target_addr, - struct grub_mkimage_layout *layout); - -struct grub_install_image_target_desc -{ - const char *dirname; - const char *names[6]; - grub_size_t voidp_sizeof; - int bigendian; - enum { - IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, - IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_SPARC64_CDCORE, - IMAGE_I386_IEEE1275, - IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, - IMAGE_FULOONG2F_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC, - IMAGE_QEMU_MIPS_FLASH, IMAGE_UBOOT, IMAGE_XEN, IMAGE_I386_PC_ELTORITO, - IMAGE_XEN_PVH - } id; - enum - { - PLATFORM_FLAGS_NONE = 0, - PLATFORM_FLAGS_DECOMPRESSORS = 2, - PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4, - } flags; - unsigned total_module_size; - unsigned decompressor_compressed_size; - unsigned decompressor_uncompressed_size; - unsigned decompressor_uncompressed_addr; - unsigned reloc_table_offset; - unsigned link_align; - grub_uint16_t elf_target; - unsigned section_align; - signed vaddr_offset; - grub_uint64_t link_addr; - unsigned mod_gap, mod_align; - grub_compression_t default_compression; - grub_uint16_t pe_target; -}; - -#define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x))) -#define grub_host_to_target32(x) (grub_host_to_target32_real (image_target, (x))) -#define grub_target_to_host64(x) (grub_target_to_host64_real (image_target, (x))) -#define grub_host_to_target64(x) (grub_host_to_target64_real (image_target, (x))) -#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (image_target, (x))) -#define grub_target_to_host16(x) (grub_target_to_host16_real (image_target, (x))) -#define grub_host_to_target16(x) (grub_host_to_target16_real (image_target, (x))) - -static inline grub_uint32_t -grub_target_to_host32_real (const struct grub_install_image_target_desc *image_target, - grub_uint32_t in) -{ - if (image_target->bigendian) - return grub_be_to_cpu32 (in); - else - return grub_le_to_cpu32 (in); -} - -static inline grub_uint64_t -grub_target_to_host64_real (const struct grub_install_image_target_desc *image_target, - grub_uint64_t in) -{ - if (image_target->bigendian) - return grub_be_to_cpu64 (in); - else - return grub_le_to_cpu64 (in); -} - -static inline grub_uint64_t -grub_host_to_target64_real (const struct grub_install_image_target_desc *image_target, - grub_uint64_t in) -{ - if (image_target->bigendian) - return grub_cpu_to_be64 (in); - else - return grub_cpu_to_le64 (in); -} - -static inline grub_uint32_t -grub_host_to_target32_real (const struct grub_install_image_target_desc *image_target, - grub_uint32_t in) -{ - if (image_target->bigendian) - return grub_cpu_to_be32 (in); - else - return grub_cpu_to_le32 (in); -} - -static inline grub_uint16_t -grub_target_to_host16_real (const struct grub_install_image_target_desc *image_target, - grub_uint16_t in) -{ - if (image_target->bigendian) - return grub_be_to_cpu16 (in); - else - return grub_le_to_cpu16 (in); -} - -static inline grub_uint16_t -grub_host_to_target16_real (const struct grub_install_image_target_desc *image_target, - grub_uint16_t in) -{ - if (image_target->bigendian) - return grub_cpu_to_be16 (in); - else - return grub_cpu_to_le16 (in); -} - -static inline grub_uint64_t -grub_host_to_target_addr_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in) -{ - if (image_target->voidp_sizeof == 8) - return grub_host_to_target64_real (image_target, in); - else - return grub_host_to_target32_real (image_target, in); -} - -static inline grub_uint64_t -grub_target_to_host_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in) -{ - if (image_target->voidp_sizeof == 8) - return grub_target_to_host64_real (image_target, in); - else - return grub_target_to_host32_real (image_target, in); -} - -#define grub_target_to_host(val) grub_target_to_host_real(image_target, (val)) - -#endif diff --git a/include/grub/util/resolve.h b/include/grub/util/resolve.h index 8923a6e6c..f42df32f9 100644 --- a/include/grub/util/resolve.h +++ b/include/grub/util/resolve.h @@ -31,6 +31,5 @@ struct grub_util_path_list * grub_util_resolve_dependencies (const char *prefix, const char *dep_list_file, char *modules[]); -void grub_util_free_path_list (struct grub_util_path_list *path_list); #endif /* ! GRUB_UTIL_RESOLVE_HEADER */ diff --git a/include/grub/verify.h b/include/grub/verify.h deleted file mode 100644 index ea0491433..000000000 --- a/include/grub/verify.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2017 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#ifndef GRUB_VERIFY_HEADER -#define GRUB_VERIFY_HEADER 1 - -#include -#include - -enum grub_verify_flags - { - GRUB_VERIFY_FLAGS_SKIP_VERIFICATION = 1, - GRUB_VERIFY_FLAGS_SINGLE_CHUNK = 2, - /* Defer verification to another authority. */ - GRUB_VERIFY_FLAGS_DEFER_AUTH = 4 - }; - -enum grub_verify_string_type - { - GRUB_VERIFY_KERNEL_CMDLINE, - GRUB_VERIFY_MODULE_CMDLINE, - GRUB_VERIFY_COMMAND, - }; - -struct grub_file_verifier -{ - struct grub_file_verifier *next; - struct grub_file_verifier **prev; - - const char *name; - - /* - * Check if file needs to be verified and set up context. - * init/read/fini is structured in the same way as hash interface. - */ - grub_err_t (*init) (grub_file_t io, enum grub_file_type type, - void **context, enum grub_verify_flags *flags); - - /* - * Right now we pass the whole file in one call but it may - * change in the future. If you insist on single buffer you - * need to set GRUB_VERIFY_FLAGS_SINGLE_CHUNK in verify_flags. - */ - grub_err_t (*write) (void *context, void *buf, grub_size_t size); - - grub_err_t (*fini) (void *context); - void (*close) (void *context); - - grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type); -}; - -extern struct grub_file_verifier *grub_file_verifiers; - -static inline void -grub_verifier_register (struct grub_file_verifier *ver) -{ - grub_list_push (GRUB_AS_LIST_P (&grub_file_verifiers), GRUB_AS_LIST (ver)); -} - -static inline void -grub_verifier_unregister (struct grub_file_verifier *ver) -{ - grub_list_remove (GRUB_AS_LIST (ver)); -} - -grub_err_t -grub_verify_string (char *str, enum grub_verify_string_type type); - -#endif /* ! GRUB_VERIFY_HEADER */ diff --git a/include/grub/x86_64/efi/kernel.h b/include/grub/x86_64/efi/kernel.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/grub/x86_64/time.h b/include/grub/x86_64/time.h index 4da5ae93c..842882cf2 100644 --- a/include/grub/x86_64/time.h +++ b/include/grub/x86_64/time.h @@ -23,7 +23,7 @@ static __inline void grub_cpu_idle (void) { /* FIXME: this can't work until we handle interrupts. */ -/* asm volatile ("hlt"); */ +/* __asm__ __volatile__ ("hlt"); */ } #endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/xen.h b/include/grub/xen.h index 91cb7cf81..6035d1a10 100644 --- a/include/grub/xen.h +++ b/include/grub/xen.h @@ -21,8 +21,6 @@ #define __XEN_INTERFACE_VERSION__ 0x0003020a -#define memset grub_memset - #ifdef ASM_FILE #define __ASSEMBLY__ #include @@ -33,12 +31,7 @@ #include #ifndef GRUB_SYMBOL_GENERATOR -typedef grub_int8_t int8_t; -typedef grub_int16_t int16_t; -typedef grub_uint8_t uint8_t; -typedef grub_uint16_t uint16_t; -typedef grub_uint32_t uint32_t; -typedef grub_uint64_t uint64_t; +#include #include #include @@ -95,11 +88,6 @@ typedef grub_uint64_t grub_xen_mfn_t; typedef grub_uint32_t grub_xen_mfn_t; #endif typedef unsigned int grub_xen_evtchn_t; - -#ifdef GRUB_MACHINE_XEN_PVH -extern struct hvm_start_info *pvh_start_info; -void grub_xen_setup_pvh (void); -#endif #endif #endif diff --git a/include/grub/xen/relocator.h b/include/grub/xen/relocator.h index 35a0ad9c7..ae45dce21 100644 --- a/include/grub/xen/relocator.h +++ b/include/grub/xen/relocator.h @@ -23,13 +23,11 @@ #include #include -#define XEN_MAX_MAPPINGS 3 - struct grub_relocator_xen_state { grub_addr_t start_info; - grub_addr_t paging_start[XEN_MAX_MAPPINGS]; - grub_addr_t paging_size[XEN_MAX_MAPPINGS]; + grub_addr_t paging_start; + grub_addr_t paging_size; grub_addr_t mfn_list; grub_addr_t stack; grub_addr_t entry_point; diff --git a/include/grub/xen_file.h b/include/grub/xen_file.h index 658799952..4b2ccba78 100644 --- a/include/grub/xen_file.h +++ b/include/grub/xen_file.h @@ -32,13 +32,10 @@ struct grub_xen_file_info grub_uint64_t entry_point; grub_uint64_t hypercall_page; grub_uint64_t paddr_offset; - grub_uint64_t p2m_base; int has_hypercall_page; int has_note; int has_xen_guest; - int has_p2m_base; int extended_cr3; - int unmapped_initrd; enum { GRUB_XEN_FILE_I386 = 1, diff --git a/include/grub/zfs/spa.h b/include/grub/zfs/spa.h index 8dd1fa8e3..7edb8ab7d 100644 --- a/include/grub/zfs/spa.h +++ b/include/grub/zfs/spa.h @@ -126,7 +126,7 @@ typedef struct zio_cksum { * +-------+-------+-------+-------+-------+-------+-------+-------+ * 5 |G| offset3 | * +-------+-------+-------+-------+-------+-------+-------+-------+ - * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | + * 6 |BDX|lvl| type | cksum | comp | PSIZE | LSIZE | * +-------+-------+-------+-------+-------+-------+-------+-------+ * 7 | padding | * +-------+-------+-------+-------+-------+-------+-------+-------+ @@ -160,8 +160,7 @@ typedef struct zio_cksum { * G gang block indicator * B byteorder (endianness) * D dedup - * X encryption - * E blkptr_t contains embedded data + * X unused * lvl level of indirection * type DMU object type * phys birth txg of block allocation; zero if same as logical birth txg @@ -204,8 +203,8 @@ typedef struct blkptr { #define BP_SET_LSIZE(bp, x) \ BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x) -#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7) -#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x) +#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8) +#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x) #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8) #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x) @@ -216,8 +215,6 @@ typedef struct blkptr { #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) -#define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) - #define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1) #define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x) @@ -280,27 +277,9 @@ typedef struct blkptr { (zcp)->zc_word[3] = w3; \ } -#define BPE_GET_ETYPE(bp) BP_GET_CHECKSUM(bp) -#define BPE_GET_LSIZE(bp) \ - BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1) -#define BPE_GET_PSIZE(bp) \ - BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1) - -typedef enum bp_embedded_type { - BP_EMBEDDED_TYPE_DATA, - NUM_BP_EMBEDDED_TYPES -} bp_embedded_type_t; - -#define BPE_NUM_WORDS 14 -#define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof(grub_uint64_t)) -#define BPE_IS_PAYLOADWORD(bp, wp) \ - ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) - #define BP_IDENTITY(bp) (&(bp)->blk_dva[0]) #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp)) -#define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ - (dva)->dva_word[1] == 0ULL) -#define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp)) +#define BP_IS_HOLE(bp) ((bp)->blk_birth == 0) /* BP_IS_RAIDZ(bp) assumes no block compression */ #define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \ diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h index 11447c166..95c67dcba 100644 --- a/include/grub/zfs/zap_leaf.h +++ b/include/grub/zfs/zap_leaf.h @@ -70,6 +70,7 @@ typedef struct zap_leaf_phys { */ grub_uint16_t l_hash[0]; + grub_properly_aligned_t l_entries[0]; } zap_leaf_phys_t; typedef union zap_leaf_chunk { diff --git a/include/multiboot2.h b/include/multiboot2.h index 5693923c0..3ccff15fc 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -60,9 +60,6 @@ #define MULTIBOOT_TAG_TYPE_NETWORK 16 #define MULTIBOOT_TAG_TYPE_EFI_MMAP 17 #define MULTIBOOT_TAG_TYPE_EFI_BS 18 -#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 -#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 -#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21 #define MULTIBOOT_HEADER_TAG_END 0 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1 @@ -72,17 +69,11 @@ #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6 #define MULTIBOOT_HEADER_TAG_EFI_BS 7 -#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 -#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10 -#define MULTIBOOT2_ARCHITECTURE_I386 0 -#define MULTIBOOT2_ARCHITECTURE_MIPS32 4 +#define MULTIBOOT_ARCHITECTURE_I386 0 +#define MULTIBOOT_ARCHITECTURE_MIPS32 4 #define MULTIBOOT_HEADER_TAG_OPTIONAL 1 -#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 -#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 -#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 - #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 @@ -165,17 +156,9 @@ struct multiboot_header_tag_module_align multiboot_uint16_t type; multiboot_uint16_t flags; multiboot_uint32_t size; -}; - -struct multiboot_header_tag_relocatable -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t min_addr; - multiboot_uint32_t max_addr; - multiboot_uint32_t align; - multiboot_uint32_t preference; + multiboot_uint32_t width; + multiboot_uint32_t height; + multiboot_uint32_t depth; }; struct multiboot_color @@ -196,7 +179,7 @@ struct multiboot_mmap_entry #define MULTIBOOT_MEMORY_BADRAM 5 multiboot_uint32_t type; multiboot_uint32_t zero; -}; +} GRUB_PACKED; typedef struct multiboot_mmap_entry multiboot_memory_map_t; struct multiboot_tag @@ -390,27 +373,6 @@ struct multiboot_tag_efi_mmap multiboot_uint8_t efi_mmap[0]; }; -struct multiboot_tag_efi32_ih -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t pointer; -}; - -struct multiboot_tag_efi64_ih -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t pointer; -}; - -struct multiboot_tag_load_base_addr -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t load_base_addr; -}; - #endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ diff --git a/include/xen/arch-x86/xen-x86_32.h b/include/xen/arch-x86/xen-x86_32.h deleted file mode 100644 index 7eca6cd41..000000000 --- a/include/xen/arch-x86/xen-x86_32.h +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * xen-x86_32.h - * - * Guest OS interface to x86 32-bit Xen. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2004-2007, K A Fraser - */ - -#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ -#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ - -/* - * Hypercall interface: - * Input: %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6) - * Output: %eax - * Access is via hypercall page (set up by guest loader or via a Xen MSR): - * call hypercall_page + hypercall-number * 32 - * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx) - */ - -/* - * These flat segments are in the Xen-private section of every GDT. Since these - * are also present in the initial GDT, many OSes will be able to avoid - * installing their own GDT. - */ -#define FLAT_RING1_CS 0xe019 /* GDT index 259 */ -#define FLAT_RING1_DS 0xe021 /* GDT index 260 */ -#define FLAT_RING1_SS 0xe021 /* GDT index 260 */ -#define FLAT_RING3_CS 0xe02b /* GDT index 261 */ -#define FLAT_RING3_DS 0xe033 /* GDT index 262 */ -#define FLAT_RING3_SS 0xe033 /* GDT index 262 */ - -#define FLAT_KERNEL_CS FLAT_RING1_CS -#define FLAT_KERNEL_DS FLAT_RING1_DS -#define FLAT_KERNEL_SS FLAT_RING1_SS -#define FLAT_USER_CS FLAT_RING3_CS -#define FLAT_USER_DS FLAT_RING3_DS -#define FLAT_USER_SS FLAT_RING3_SS - -#define __HYPERVISOR_VIRT_START_PAE 0xF5800000 -#define __MACH2PHYS_VIRT_START_PAE 0xF5800000 -#define __MACH2PHYS_VIRT_END_PAE 0xF6800000 -#define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE) -#define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE) -#define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE) - -/* Non-PAE bounds are obsolete. */ -#define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000 -#define __MACH2PHYS_VIRT_START_NONPAE 0xFC000000 -#define __MACH2PHYS_VIRT_END_NONPAE 0xFC400000 -#define HYPERVISOR_VIRT_START_NONPAE \ - xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE) -#define MACH2PHYS_VIRT_START_NONPAE \ - xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE) -#define MACH2PHYS_VIRT_END_NONPAE \ - xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE) - -#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE -#define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE -#define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE - -#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START) -#endif - -#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END) -#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2) -#ifndef machine_to_phys_mapping -#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START) -#endif - -/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */ -#if defined(__XEN__) || defined(__XEN_TOOLS__) -#undef ___DEFINE_XEN_GUEST_HANDLE -#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ - typedef struct { type *p; } \ - __guest_handle_ ## name; \ - typedef struct { union { type *p; uint64_aligned_t q; }; } \ - __guest_handle_64_ ## name -#undef set_xen_guest_handle_raw -#define set_xen_guest_handle_raw(hnd, val) \ - do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \ - (hnd).p = val; \ - } while ( 0 ) -#define int64_aligned_t int64_t __attribute__((aligned(8))) -#define uint64_aligned_t uint64_t __attribute__((aligned(8))) -#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name -#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name) -#endif - -#ifndef __ASSEMBLY__ - -struct cpu_user_regs { - uint32_t ebx; - uint32_t ecx; - uint32_t edx; - uint32_t esi; - uint32_t edi; - uint32_t ebp; - uint32_t eax; - uint16_t error_code; /* private */ - uint16_t entry_vector; /* private */ - uint32_t eip; - uint16_t cs; - uint8_t saved_upcall_mask; - uint8_t _pad0; - uint32_t eflags; /* eflags.IF == !saved_upcall_mask */ - uint32_t esp; - uint16_t ss, _pad1; - uint16_t es, _pad2; - uint16_t ds, _pad3; - uint16_t fs, _pad4; - uint16_t gs, _pad5; -}; -typedef struct cpu_user_regs cpu_user_regs_t; -DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t); - -/* - * Page-directory addresses above 4GB do not fit into architectural %cr3. - * When accessing %cr3, or equivalent field in vcpu_guest_context, guests - * must use the following accessor macros to pack/unpack valid MFNs. - */ -#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20)) -#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20)) - -struct arch_vcpu_info { - unsigned long cr2; - unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */ -}; -typedef struct arch_vcpu_info arch_vcpu_info_t; - -struct xen_callback { - unsigned long cs; - unsigned long eip; -}; -typedef struct xen_callback xen_callback_t; - -#endif /* !__ASSEMBLY__ */ - -#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/arch-x86/xen-x86_64.h b/include/xen/arch-x86/xen-x86_64.h deleted file mode 100644 index 5e18613bd..000000000 --- a/include/xen/arch-x86/xen-x86_64.h +++ /dev/null @@ -1,202 +0,0 @@ -/****************************************************************************** - * xen-x86_64.h - * - * Guest OS interface to x86 64-bit Xen. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2004-2006, K A Fraser - */ - -#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ -#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ - -/* - * Hypercall interface: - * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6) - * Output: %rax - * Access is via hypercall page (set up by guest loader or via a Xen MSR): - * call hypercall_page + hypercall-number * 32 - * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi) - */ - -/* - * 64-bit segment selectors - * These flat segments are in the Xen-private section of every GDT. Since these - * are also present in the initial GDT, many OSes will be able to avoid - * installing their own GDT. - */ - -#define FLAT_RING3_CS32 0xe023 /* GDT index 260 */ -#define FLAT_RING3_CS64 0xe033 /* GDT index 261 */ -#define FLAT_RING3_DS32 0xe02b /* GDT index 262 */ -#define FLAT_RING3_DS64 0x0000 /* NULL selector */ -#define FLAT_RING3_SS32 0xe02b /* GDT index 262 */ -#define FLAT_RING3_SS64 0xe02b /* GDT index 262 */ - -#define FLAT_KERNEL_DS64 FLAT_RING3_DS64 -#define FLAT_KERNEL_DS32 FLAT_RING3_DS32 -#define FLAT_KERNEL_DS FLAT_KERNEL_DS64 -#define FLAT_KERNEL_CS64 FLAT_RING3_CS64 -#define FLAT_KERNEL_CS32 FLAT_RING3_CS32 -#define FLAT_KERNEL_CS FLAT_KERNEL_CS64 -#define FLAT_KERNEL_SS64 FLAT_RING3_SS64 -#define FLAT_KERNEL_SS32 FLAT_RING3_SS32 -#define FLAT_KERNEL_SS FLAT_KERNEL_SS64 - -#define FLAT_USER_DS64 FLAT_RING3_DS64 -#define FLAT_USER_DS32 FLAT_RING3_DS32 -#define FLAT_USER_DS FLAT_USER_DS64 -#define FLAT_USER_CS64 FLAT_RING3_CS64 -#define FLAT_USER_CS32 FLAT_RING3_CS32 -#define FLAT_USER_CS FLAT_USER_CS64 -#define FLAT_USER_SS64 FLAT_RING3_SS64 -#define FLAT_USER_SS32 FLAT_RING3_SS32 -#define FLAT_USER_SS FLAT_USER_SS64 - -#define __HYPERVISOR_VIRT_START 0xFFFF800000000000 -#define __HYPERVISOR_VIRT_END 0xFFFF880000000000 -#define __MACH2PHYS_VIRT_START 0xFFFF800000000000 -#define __MACH2PHYS_VIRT_END 0xFFFF804000000000 - -#ifndef HYPERVISOR_VIRT_START -#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START) -#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END) -#endif - -#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START) -#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END) -#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3) -#ifndef machine_to_phys_mapping -#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START) -#endif - -/* - * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base) - * @which == SEGBASE_* ; @base == 64-bit base address - * Returns 0 on success. - */ -#define SEGBASE_FS 0 -#define SEGBASE_GS_USER 1 -#define SEGBASE_GS_KERNEL 2 -#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */ - -/* - * int HYPERVISOR_iret(void) - * All arguments are on the kernel stack, in the following format. - * Never returns if successful. Current kernel context is lost. - * The saved CS is mapped as follows: - * RING0 -> RING3 kernel mode. - * RING1 -> RING3 kernel mode. - * RING2 -> RING3 kernel mode. - * RING3 -> RING3 user mode. - * However RING0 indicates that the guest kernel should return to iteself - * directly with - * orb $3,1*8(%rsp) - * iretq - * If flags contains VGCF_in_syscall: - * Restore RAX, RIP, RFLAGS, RSP. - * Discard R11, RCX, CS, SS. - * Otherwise: - * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP. - * All other registers are saved on hypercall entry and restored to user. - */ -/* Guest exited in SYSCALL context? Return to guest with SYSRET? */ -#define _VGCF_in_syscall 8 -#define VGCF_in_syscall (1<<_VGCF_in_syscall) -#define VGCF_IN_SYSCALL VGCF_in_syscall - -#ifndef __ASSEMBLY__ - -struct iret_context { - /* Top of stack (%rsp at point of hypercall). */ - uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss; - /* Bottom of iret stack frame. */ -}; - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */ -#define __DECL_REG(name) union { \ - uint64_t r ## name, e ## name; \ - uint32_t _e ## name; \ -} -#else -/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */ -#define __DECL_REG(name) uint64_t r ## name -#endif - -struct cpu_user_regs { - uint64_t r15; - uint64_t r14; - uint64_t r13; - uint64_t r12; - __DECL_REG(bp); - __DECL_REG(bx); - uint64_t r11; - uint64_t r10; - uint64_t r9; - uint64_t r8; - __DECL_REG(ax); - __DECL_REG(cx); - __DECL_REG(dx); - __DECL_REG(si); - __DECL_REG(di); - uint32_t error_code; /* private */ - uint32_t entry_vector; /* private */ - __DECL_REG(ip); - uint16_t cs, _pad0[1]; - uint8_t saved_upcall_mask; - uint8_t _pad1[3]; - __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */ - __DECL_REG(sp); - uint16_t ss, _pad2[3]; - uint16_t es, _pad3[3]; - uint16_t ds, _pad4[3]; - uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */ - uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */ -}; -typedef struct cpu_user_regs cpu_user_regs_t; -DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t); - -#undef __DECL_REG - -#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12) -#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12) - -struct arch_vcpu_info { - unsigned long cr2; - unsigned long pad; /* sizeof(vcpu_info_t) == 64 */ -}; -typedef struct arch_vcpu_info arch_vcpu_info_t; - -typedef unsigned long xen_callback_t; - -#endif /* !__ASSEMBLY__ */ - -#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/arch-x86/xen.h b/include/xen/arch-x86/xen.h deleted file mode 100644 index 56be26cb6..000000000 --- a/include/xen/arch-x86/xen.h +++ /dev/null @@ -1,280 +0,0 @@ -/****************************************************************************** - * arch-x86/xen.h - * - * Guest OS interface to x86 Xen. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2004-2006, K A Fraser - */ - -#include "../xen.h" - -#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__ -#define __XEN_PUBLIC_ARCH_X86_XEN_H__ - -/* Structural guest handles introduced in 0x00030201. */ -#if __XEN_INTERFACE_VERSION__ >= 0x00030201 -#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ - typedef struct { type *p; } __guest_handle_ ## name -#else -#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \ - typedef type * __guest_handle_ ## name -#endif - -/* - * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field - * in a struct in memory. - * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an - * hypercall argument. - * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but - * they might not be on other architectures. - */ -#define __DEFINE_XEN_GUEST_HANDLE(name, type) \ - ___DEFINE_XEN_GUEST_HANDLE(name, type); \ - ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type) -#define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name) -#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name -#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name) -#define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name) -#define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0) -#ifdef __XEN_TOOLS__ -#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0) -#endif -#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val) - -#if defined(__i386__) -#include "xen-x86_32.h" -#elif defined(__x86_64__) -#include "xen-x86_64.h" -#endif - -#ifndef __ASSEMBLY__ -typedef unsigned long xen_pfn_t; -#define PRI_xen_pfn "lx" -#endif - -#define XEN_HAVE_PV_GUEST_ENTRY 1 - -#define XEN_HAVE_PV_UPCALL_MASK 1 - -/* - * `incontents 200 segdesc Segment Descriptor Tables - */ -/* - * ` enum neg_errnoval - * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries); - * ` - */ -/* - * A number of GDT entries are reserved by Xen. These are not situated at the - * start of the GDT because some stupid OSes export hard-coded selector values - * in their ABI. These hard-coded values are always near the start of the GDT, - * so Xen places itself out of the way, at the far end of the GDT. - * - * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op - */ -#define FIRST_RESERVED_GDT_PAGE 14 -#define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096) -#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8) - - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc); - * ` - * ` @pa The machine physical address of the descriptor to - * ` update. Must be either a descriptor page or writable. - * ` @desc The descriptor value to update, in the same format as a - * ` native descriptor table entry. - */ - -/* Maximum number of virtual CPUs in legacy multi-processor guests. */ -#define XEN_LEGACY_MAX_VCPUS 32 - -#ifndef __ASSEMBLY__ - -typedef unsigned long xen_ulong_t; -#define PRI_xen_ulong "lx" - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp); - * ` - * Sets the stack segment and pointer for the current vcpu. - */ - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]); - * ` - */ -/* - * Send an array of these to HYPERVISOR_set_trap_table(). - * Terminate the array with a sentinel entry, with traps[].address==0. - * The privilege level specifies which modes may enter a trap via a software - * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate - * privilege levels as follows: - * Level == 0: Noone may enter - * Level == 1: Kernel may enter - * Level == 2: Kernel may enter - * Level == 3: Everyone may enter - */ -#define TI_GET_DPL(_ti) ((_ti)->flags & 3) -#define TI_GET_IF(_ti) ((_ti)->flags & 4) -#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl)) -#define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2)) -struct trap_info { - uint8_t vector; /* exception vector */ - uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */ - uint16_t cs; /* code selector */ - unsigned long address; /* code offset */ -}; -typedef struct trap_info trap_info_t; -DEFINE_XEN_GUEST_HANDLE(trap_info_t); - -typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ - -/* - * The following is all CPU context. Note that the fpu_ctxt block is filled - * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used. - * - * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise - * for HVM and PVH guests, not all information in this structure is updated: - * - * - For HVM guests, the structures read include: fpu_ctxt (if - * VGCT_I387_VALID is set), flags, user_regs, debugreg[*] - * - * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to - * set cr3. All other fields not used should be set to 0. - */ -struct vcpu_guest_context { - /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */ - struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */ -#define VGCF_I387_VALID (1<<0) -#define VGCF_IN_KERNEL (1<<2) -#define _VGCF_i387_valid 0 -#define VGCF_i387_valid (1<<_VGCF_i387_valid) -#define _VGCF_in_kernel 2 -#define VGCF_in_kernel (1<<_VGCF_in_kernel) -#define _VGCF_failsafe_disables_events 3 -#define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events) -#define _VGCF_syscall_disables_events 4 -#define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events) -#define _VGCF_online 5 -#define VGCF_online (1<<_VGCF_online) - unsigned long flags; /* VGCF_* flags */ - struct cpu_user_regs user_regs; /* User-level CPU registers */ - struct trap_info trap_ctxt[256]; /* Virtual IDT */ - unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */ - unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */ - unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */ - /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */ - unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */ - unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */ -#ifdef __i386__ - unsigned long event_callback_cs; /* CS:EIP of event callback */ - unsigned long event_callback_eip; - unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */ - unsigned long failsafe_callback_eip; -#else - unsigned long event_callback_eip; - unsigned long failsafe_callback_eip; -#ifdef __XEN__ - union { - unsigned long syscall_callback_eip; - struct { - unsigned int event_callback_cs; /* compat CS of event cb */ - unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */ - }; - }; -#else - unsigned long syscall_callback_eip; -#endif -#endif - unsigned long vm_assist; /* VMASST_TYPE_* bitmap */ -#ifdef __x86_64__ - /* Segment base addresses. */ - uint64_t fs_base; - uint64_t gs_base_kernel; - uint64_t gs_base_user; -#endif -}; -typedef struct vcpu_guest_context vcpu_guest_context_t; -DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); - -struct arch_shared_info { - unsigned long max_pfn; /* max pfn that appears in table */ - /* Frame containing list of mfns containing list of mfns containing p2m. */ - xen_pfn_t pfn_to_mfn_frame_list_list; - unsigned long nmi_reason; - uint64_t pad[32]; -}; -typedef struct arch_shared_info arch_shared_info_t; - -#endif /* !__ASSEMBLY__ */ - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_fpu_taskswitch(int set); - * ` - * Sets (if set!=0) or clears (if set==0) CR0.TS. - */ - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_set_debugreg(int regno, unsigned long value); - * - * ` unsigned long - * ` HYPERVISOR_get_debugreg(int regno); - * For 0<=reg<=7, returns the debug register value. - * For other values of reg, returns ((unsigned long)-EINVAL). - * (Unfortunately, this interface is defective.) - */ - -/* - * Prefix forces emulation of some non-trapping instructions. - * Currently only CPUID. - */ -#ifdef __ASSEMBLY__ -#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; -#define XEN_CPUID XEN_EMULATE_PREFIX cpuid -#else -#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " -#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" -#endif - -/* - * Debug console IO port, also called "port E9 hack". Each character written - * to this IO port will be printed on the hypervisor console, subject to log - * level restrictions. - */ -#define XEN_HVM_DEBUGCONS_IOPORT 0xe9 - -#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/elfnote.h b/include/xen/elfnote.h deleted file mode 100644 index 71cd4ec52..000000000 --- a/include/xen/elfnote.h +++ /dev/null @@ -1,281 +0,0 @@ -/****************************************************************************** - * elfnote.h - * - * Definitions used for the Xen ELF notes. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2006, Ian Campbell, XenSource Ltd. - */ - -#ifndef __XEN_PUBLIC_ELFNOTE_H__ -#define __XEN_PUBLIC_ELFNOTE_H__ - -/* - * `incontents 200 elfnotes ELF notes - * - * The notes should live in a PT_NOTE segment and have "Xen" in the - * name field. - * - * Numeric types are either 4 or 8 bytes depending on the content of - * the desc field. - * - * LEGACY indicated the fields in the legacy __xen_guest string which - * this a note type replaces. - * - * String values (for non-legacy) are NULL terminated ASCII, also known - * as ASCIZ type. - */ - -/* - * NAME=VALUE pair (string). - */ -#define XEN_ELFNOTE_INFO 0 - -/* - * The virtual address of the entry point (numeric). - * - * LEGACY: VIRT_ENTRY - */ -#define XEN_ELFNOTE_ENTRY 1 - -/* The virtual address of the hypercall transfer page (numeric). - * - * LEGACY: HYPERCALL_PAGE. (n.b. legacy value is a physical page - * number not a virtual address) - */ -#define XEN_ELFNOTE_HYPERCALL_PAGE 2 - -/* The virtual address where the kernel image should be mapped (numeric). - * - * Defaults to 0. - * - * LEGACY: VIRT_BASE - */ -#define XEN_ELFNOTE_VIRT_BASE 3 - -/* - * The offset of the ELF paddr field from the actual required - * pseudo-physical address (numeric). - * - * This is used to maintain backwards compatibility with older kernels - * which wrote __PAGE_OFFSET into that field. This field defaults to 0 - * if not present. - * - * LEGACY: ELF_PADDR_OFFSET. (n.b. legacy default is VIRT_BASE) - */ -#define XEN_ELFNOTE_PADDR_OFFSET 4 - -/* - * The version of Xen that we work with (string). - * - * LEGACY: XEN_VER - */ -#define XEN_ELFNOTE_XEN_VERSION 5 - -/* - * The name of the guest operating system (string). - * - * LEGACY: GUEST_OS - */ -#define XEN_ELFNOTE_GUEST_OS 6 - -/* - * The version of the guest operating system (string). - * - * LEGACY: GUEST_VER - */ -#define XEN_ELFNOTE_GUEST_VERSION 7 - -/* - * The loader type (string). - * - * LEGACY: LOADER - */ -#define XEN_ELFNOTE_LOADER 8 - -/* - * The kernel supports PAE (x86/32 only, string = "yes", "no" or - * "bimodal"). - * - * For compatibility with Xen 3.0.3 and earlier the "bimodal" setting - * may be given as "yes,bimodal" which will cause older Xen to treat - * this kernel as PAE. - * - * LEGACY: PAE (n.b. The legacy interface included a provision to - * indicate 'extended-cr3' support allowing L3 page tables to be - * placed above 4G. It is assumed that any kernel new enough to use - * these ELF notes will include this and therefore "yes" here is - * equivalent to "yes[entended-cr3]" in the __xen_guest interface. - */ -#define XEN_ELFNOTE_PAE_MODE 9 - -/* - * The features supported/required by this kernel (string). - * - * The string must consist of a list of feature names (as given in - * features.h, without the "XENFEAT_" prefix) separated by '|' - * characters. If a feature is required for the kernel to function - * then the feature name must be preceded by a '!' character. - * - * LEGACY: FEATURES - */ -#define XEN_ELFNOTE_FEATURES 10 - -/* - * The kernel requires the symbol table to be loaded (string = "yes" or "no") - * LEGACY: BSD_SYMTAB (n.b. The legacy treated the presence or absence - * of this string as a boolean flag rather than requiring "yes" or - * "no". - */ -#define XEN_ELFNOTE_BSD_SYMTAB 11 - -/* - * The lowest address the hypervisor hole can begin at (numeric). - * - * This must not be set higher than HYPERVISOR_VIRT_START. Its presence - * also indicates to the hypervisor that the kernel can deal with the - * hole starting at a higher address. - */ -#define XEN_ELFNOTE_HV_START_LOW 12 - -/* - * List of maddr_t-sized mask/value pairs describing how to recognize - * (non-present) L1 page table entries carrying valid MFNs (numeric). - */ -#define XEN_ELFNOTE_L1_MFN_VALID 13 - -/* - * Whether or not the guest supports cooperative suspend cancellation. - * This is a numeric value. - * - * Default is 0 - */ -#define XEN_ELFNOTE_SUSPEND_CANCEL 14 - -/* - * The (non-default) location the initial phys-to-machine map should be - * placed at by the hypervisor (Dom0) or the tools (DomU). - * The kernel must be prepared for this mapping to be established using - * large pages, despite such otherwise not being available to guests. - * The kernel must also be able to handle the page table pages used for - * this mapping not being accessible through the initial mapping. - * (Only x86-64 supports this at present.) - */ -#define XEN_ELFNOTE_INIT_P2M 15 - -/* - * Whether or not the guest can deal with being passed an initrd not - * mapped through its initial page tables. - */ -#define XEN_ELFNOTE_MOD_START_PFN 16 - -/* - * The features supported by this kernel (numeric). - * - * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a - * kernel to specify support for features that older hypervisors don't - * know about. The set of features 4.2 and newer hypervisors will - * consider supported by the kernel is the combination of the sets - * specified through this and the string note. - * - * LEGACY: FEATURES - */ -#define XEN_ELFNOTE_SUPPORTED_FEATURES 17 - -/* - * Physical entry point into the kernel. - * - * 32bit entry point into the kernel. When requested to launch the - * guest kernel in a HVM container, Xen will use this entry point to - * launch the guest in 32bit protected mode with paging disabled. - * Ignored otherwise. - */ -#define XEN_ELFNOTE_PHYS32_ENTRY 18 - -/* - * The number of the highest elfnote defined. - */ -#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY - -/* - * System information exported through crash notes. - * - * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_INFO - * note in case of a system crash. This note will contain various - * information about the system, see xen/include/xen/elfcore.h. - */ -#define XEN_ELFNOTE_CRASH_INFO 0x1000001 - -/* - * System registers exported through crash notes. - * - * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_REGS - * note per cpu in case of a system crash. This note is architecture - * specific and will contain registers not saved in the "CORE" note. - * See xen/include/xen/elfcore.h for more information. - */ -#define XEN_ELFNOTE_CRASH_REGS 0x1000002 - - -/* - * xen dump-core none note. - * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_NONE - * in its dump file to indicate that the file is xen dump-core - * file. This note doesn't have any other information. - * See tools/libxc/xc_core.h for more information. - */ -#define XEN_ELFNOTE_DUMPCORE_NONE 0x2000000 - -/* - * xen dump-core header note. - * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_HEADER - * in its dump file. - * See tools/libxc/xc_core.h for more information. - */ -#define XEN_ELFNOTE_DUMPCORE_HEADER 0x2000001 - -/* - * xen dump-core xen version note. - * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_XEN_VERSION - * in its dump file. It contains the xen version obtained via the - * XENVER hypercall. - * See tools/libxc/xc_core.h for more information. - */ -#define XEN_ELFNOTE_DUMPCORE_XEN_VERSION 0x2000002 - -/* - * xen dump-core format version note. - * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION - * in its dump file. It contains a format version identifier. - * See tools/libxc/xc_core.h for more information. - */ -#define XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION 0x2000003 - -#endif /* __XEN_PUBLIC_ELFNOTE_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/event_channel.h b/include/xen/event_channel.h deleted file mode 100644 index 49ac8cca5..000000000 --- a/include/xen/event_channel.h +++ /dev/null @@ -1,381 +0,0 @@ -/****************************************************************************** - * event_channel.h - * - * Event channels between domains. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2003-2004, K A Fraser. - */ - -#ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__ -#define __XEN_PUBLIC_EVENT_CHANNEL_H__ - -#include "xen.h" - -/* - * `incontents 150 evtchn Event Channels - * - * Event channels are the basic primitive provided by Xen for event - * notifications. An event is the Xen equivalent of a hardware - * interrupt. They essentially store one bit of information, the event - * of interest is signalled by transitioning this bit from 0 to 1. - * - * Notifications are received by a guest via an upcall from Xen, - * indicating when an event arrives (setting the bit). Further - * notifications are masked until the bit is cleared again (therefore, - * guests must check the value of the bit after re-enabling event - * delivery to ensure no missed notifications). - * - * Event notifications can be masked by setting a flag; this is - * equivalent to disabling interrupts and can be used to ensure - * atomicity of certain operations in the guest kernel. - * - * Event channels are represented by the evtchn_* fields in - * struct shared_info and struct vcpu_info. - */ - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args) - * ` - * @cmd == EVTCHNOP_* (event-channel operation). - * @args == struct evtchn_* Operation-specific extra arguments (NULL if none). - */ - -/* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */ -#define EVTCHNOP_bind_interdomain 0 -#define EVTCHNOP_bind_virq 1 -#define EVTCHNOP_bind_pirq 2 -#define EVTCHNOP_close 3 -#define EVTCHNOP_send 4 -#define EVTCHNOP_status 5 -#define EVTCHNOP_alloc_unbound 6 -#define EVTCHNOP_bind_ipi 7 -#define EVTCHNOP_bind_vcpu 8 -#define EVTCHNOP_unmask 9 -#define EVTCHNOP_reset 10 -#define EVTCHNOP_init_control 11 -#define EVTCHNOP_expand_array 12 -#define EVTCHNOP_set_priority 13 -/* ` } */ - -typedef uint32_t evtchn_port_t; -DEFINE_XEN_GUEST_HANDLE(evtchn_port_t); - -/* - * EVTCHNOP_alloc_unbound: Allocate a port in domain and mark as - * accepting interdomain bindings from domain . A fresh port - * is allocated in and returned as . - * NOTES: - * 1. If the caller is unprivileged then must be DOMID_SELF. - * 2. may be DOMID_SELF, allowing loopback connections. - */ -struct evtchn_alloc_unbound { - /* IN parameters */ - domid_t dom, remote_dom; - /* OUT parameters */ - evtchn_port_t port; -}; -typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t; - -/* - * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between - * the calling domain and . must identify - * a port that is unbound and marked as accepting bindings from the calling - * domain. A fresh port is allocated in the calling domain and returned as - * . - * - * In case the peer domain has already tried to set our event channel - * pending, before it was bound, EVTCHNOP_bind_interdomain always sets - * the local event channel pending. - * - * The usual pattern of use, in the guest's upcall (or subsequent - * handler) is as follows: (Re-enable the event channel for subsequent - * signalling and then) check for the existence of whatever condition - * is being waited for by other means, and take whatever action is - * needed (if any). - * - * NOTES: - * 1. may be DOMID_SELF, allowing loopback connections. - */ -struct evtchn_bind_interdomain { - /* IN parameters. */ - domid_t remote_dom; - evtchn_port_t remote_port; - /* OUT parameters. */ - evtchn_port_t local_port; -}; -typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t; - -/* - * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ on specified - * vcpu. - * NOTES: - * 1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list - * in xen.h for the classification of each VIRQ. - * 2. Global VIRQs must be allocated on VCPU0 but can subsequently be - * re-bound via EVTCHNOP_bind_vcpu. - * 3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu. - * The allocated event channel is bound to the specified vcpu and the - * binding cannot be changed. - */ -struct evtchn_bind_virq { - /* IN parameters. */ - uint32_t virq; /* enum virq */ - uint32_t vcpu; - /* OUT parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_bind_virq evtchn_bind_virq_t; - -/* - * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ ). - * NOTES: - * 1. A physical IRQ may be bound to at most one event channel per domain. - * 2. Only a sufficiently-privileged domain may bind to a physical IRQ. - */ -struct evtchn_bind_pirq { - /* IN parameters. */ - uint32_t pirq; -#define BIND_PIRQ__WILL_SHARE 1 - uint32_t flags; /* BIND_PIRQ__* */ - /* OUT parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_bind_pirq evtchn_bind_pirq_t; - -/* - * EVTCHNOP_bind_ipi: Bind a local event channel to receive events. - * NOTES: - * 1. The allocated event channel is bound to the specified vcpu. The binding - * may not be changed. - */ -struct evtchn_bind_ipi { - uint32_t vcpu; - /* OUT parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_bind_ipi evtchn_bind_ipi_t; - -/* - * EVTCHNOP_close: Close a local event channel . If the channel is - * interdomain then the remote end is placed in the unbound state - * (EVTCHNSTAT_unbound), awaiting a new connection. - */ -struct evtchn_close { - /* IN parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_close evtchn_close_t; - -/* - * EVTCHNOP_send: Send an event to the remote end of the channel whose local - * endpoint is . - */ -struct evtchn_send { - /* IN parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_send evtchn_send_t; - -/* - * EVTCHNOP_status: Get the current status of the communication channel which - * has an endpoint at . - * NOTES: - * 1. may be specified as DOMID_SELF. - * 2. Only a sufficiently-privileged domain may obtain the status of an event - * channel for which is not DOMID_SELF. - */ -struct evtchn_status { - /* IN parameters */ - domid_t dom; - evtchn_port_t port; - /* OUT parameters */ -#define EVTCHNSTAT_closed 0 /* Channel is not in use. */ -#define EVTCHNSTAT_unbound 1 /* Channel is waiting interdom connection.*/ -#define EVTCHNSTAT_interdomain 2 /* Channel is connected to remote domain. */ -#define EVTCHNSTAT_pirq 3 /* Channel is bound to a phys IRQ line. */ -#define EVTCHNSTAT_virq 4 /* Channel is bound to a virtual IRQ line */ -#define EVTCHNSTAT_ipi 5 /* Channel is bound to a virtual IPI line */ - uint32_t status; - uint32_t vcpu; /* VCPU to which this channel is bound. */ - union { - struct { - domid_t dom; - } unbound; /* EVTCHNSTAT_unbound */ - struct { - domid_t dom; - evtchn_port_t port; - } interdomain; /* EVTCHNSTAT_interdomain */ - uint32_t pirq; /* EVTCHNSTAT_pirq */ - uint32_t virq; /* EVTCHNSTAT_virq */ - } u; -}; -typedef struct evtchn_status evtchn_status_t; - -/* - * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an - * event is pending. - * NOTES: - * 1. IPI-bound channels always notify the vcpu specified at bind time. - * This binding cannot be changed. - * 2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time. - * This binding cannot be changed. - * 3. All other channels notify vcpu0 by default. This default is set when - * the channel is allocated (a port that is freed and subsequently reused - * has its binding reset to vcpu0). - */ -struct evtchn_bind_vcpu { - /* IN parameters. */ - evtchn_port_t port; - uint32_t vcpu; -}; -typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t; - -/* - * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver - * a notification to the appropriate VCPU if an event is pending. - */ -struct evtchn_unmask { - /* IN parameters. */ - evtchn_port_t port; -}; -typedef struct evtchn_unmask evtchn_unmask_t; - -/* - * EVTCHNOP_reset: Close all event channels associated with specified domain. - * NOTES: - * 1. may be specified as DOMID_SELF. - * 2. Only a sufficiently-privileged domain may specify other than DOMID_SELF. - */ -struct evtchn_reset { - /* IN parameters. */ - domid_t dom; -}; -typedef struct evtchn_reset evtchn_reset_t; - -/* - * EVTCHNOP_init_control: initialize the control block for the FIFO ABI. - * - * Note: any events that are currently pending will not be resent and - * will be lost. Guests should call this before binding any event to - * avoid losing any events. - */ -struct evtchn_init_control { - /* IN parameters. */ - uint64_t control_gfn; - uint32_t offset; - uint32_t vcpu; - /* OUT parameters. */ - uint8_t link_bits; - uint8_t _pad[7]; -}; -typedef struct evtchn_init_control evtchn_init_control_t; - -/* - * EVTCHNOP_expand_array: add an additional page to the event array. - */ -struct evtchn_expand_array { - /* IN parameters. */ - uint64_t array_gfn; -}; -typedef struct evtchn_expand_array evtchn_expand_array_t; - -/* - * EVTCHNOP_set_priority: set the priority for an event channel. - */ -struct evtchn_set_priority { - /* IN parameters. */ - uint32_t port; - uint32_t priority; -}; -typedef struct evtchn_set_priority evtchn_set_priority_t; - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) - * ` - * Superceded by new event_channel_op() hypercall since 0x00030202. - */ -struct evtchn_op { - uint32_t cmd; /* enum event_channel_op */ - union { - struct evtchn_alloc_unbound alloc_unbound; - struct evtchn_bind_interdomain bind_interdomain; - struct evtchn_bind_virq bind_virq; - struct evtchn_bind_pirq bind_pirq; - struct evtchn_bind_ipi bind_ipi; - struct evtchn_close close; - struct evtchn_send send; - struct evtchn_status status; - struct evtchn_bind_vcpu bind_vcpu; - struct evtchn_unmask unmask; - } u; -}; -typedef struct evtchn_op evtchn_op_t; -DEFINE_XEN_GUEST_HANDLE(evtchn_op_t); - -/* - * 2-level ABI - */ - -#define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64) - -/* - * FIFO ABI - */ - -/* Events may have priorities from 0 (highest) to 15 (lowest). */ -#define EVTCHN_FIFO_PRIORITY_MAX 0 -#define EVTCHN_FIFO_PRIORITY_DEFAULT 7 -#define EVTCHN_FIFO_PRIORITY_MIN 15 - -#define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1) - -typedef uint32_t event_word_t; - -#define EVTCHN_FIFO_PENDING 31 -#define EVTCHN_FIFO_MASKED 30 -#define EVTCHN_FIFO_LINKED 29 -#define EVTCHN_FIFO_BUSY 28 - -#define EVTCHN_FIFO_LINK_BITS 17 -#define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1) - -#define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS) - -struct evtchn_fifo_control_block { - uint32_t ready; - uint32_t _rsvd; - uint32_t head[EVTCHN_FIFO_MAX_QUEUES]; -}; -typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t; - -#endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h deleted file mode 100644 index b8a3d6ceb..000000000 --- a/include/xen/grant_table.h +++ /dev/null @@ -1,662 +0,0 @@ -/****************************************************************************** - * grant_table.h - * - * Interface for granting foreign access to page frames, and receiving - * page-ownership transfers. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2004, K A Fraser - */ - -#ifndef __XEN_PUBLIC_GRANT_TABLE_H__ -#define __XEN_PUBLIC_GRANT_TABLE_H__ - -#include "xen.h" - -/* - * `incontents 150 gnttab Grant Tables - * - * Xen's grant tables provide a generic mechanism to memory sharing - * between domains. This shared memory interface underpins the split - * device drivers for block and network IO. - * - * Each domain has its own grant table. This is a data structure that - * is shared with Xen; it allows the domain to tell Xen what kind of - * permissions other domains have on its pages. Entries in the grant - * table are identified by grant references. A grant reference is an - * integer, which indexes into the grant table. It acts as a - * capability which the grantee can use to perform operations on the - * granter’s memory. - * - * This capability-based system allows shared-memory communications - * between unprivileged domains. A grant reference also encapsulates - * the details of a shared page, removing the need for a domain to - * know the real machine address of a page it is sharing. This makes - * it possible to share memory correctly with domains running in - * fully virtualised memory. - */ - -/*********************************** - * GRANT TABLE REPRESENTATION - */ - -/* Some rough guidelines on accessing and updating grant-table entries - * in a concurrency-safe manner. For more information, Linux contains a - * reference implementation for guest OSes (drivers/xen/grant_table.c, see - * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD - * - * NB. WMB is a no-op on current-generation x86 processors. However, a - * compiler barrier will still be required. - * - * Introducing a valid entry into the grant table: - * 1. Write ent->domid. - * 2. Write ent->frame: - * GTF_permit_access: Frame to which access is permitted. - * GTF_accept_transfer: Pseudo-phys frame slot being filled by new - * frame, or zero if none. - * 3. Write memory barrier (WMB). - * 4. Write ent->flags, inc. valid type. - * - * Invalidating an unused GTF_permit_access entry: - * 1. flags = ent->flags. - * 2. Observe that !(flags & (GTF_reading|GTF_writing)). - * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). - * NB. No need for WMB as reuse of entry is control-dependent on success of - * step 3, and all architectures guarantee ordering of ctrl-dep writes. - * - * Invalidating an in-use GTF_permit_access entry: - * This cannot be done directly. Request assistance from the domain controller - * which can set a timeout on the use of a grant entry and take necessary - * action. (NB. This is not yet implemented!). - * - * Invalidating an unused GTF_accept_transfer entry: - * 1. flags = ent->flags. - * 2. Observe that !(flags & GTF_transfer_committed). [*] - * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). - * NB. No need for WMB as reuse of entry is control-dependent on success of - * step 3, and all architectures guarantee ordering of ctrl-dep writes. - * [*] If GTF_transfer_committed is set then the grant entry is 'committed'. - * The guest must /not/ modify the grant entry until the address of the - * transferred frame is written. It is safe for the guest to spin waiting - * for this to occur (detect by observing GTF_transfer_completed in - * ent->flags). - * - * Invalidating a committed GTF_accept_transfer entry: - * 1. Wait for (ent->flags & GTF_transfer_completed). - * - * Changing a GTF_permit_access from writable to read-only: - * Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing. - * - * Changing a GTF_permit_access from read-only to writable: - * Use SMP-safe bit-setting instruction. - */ - -/* - * Reference to a grant entry in a specified domain's grant table. - */ -typedef uint32_t grant_ref_t; - -/* - * A grant table comprises a packed array of grant entries in one or more - * page frames shared between Xen and a guest. - * [XEN]: This field is written by Xen and read by the sharing guest. - * [GST]: This field is written by the guest and read by Xen. - */ - -/* - * Version 1 of the grant table entry structure is maintained purely - * for backwards compatibility. New guests should use version 2. - */ -#if __XEN_INTERFACE_VERSION__ < 0x0003020a -#define grant_entry_v1 grant_entry -#define grant_entry_v1_t grant_entry_t -#endif -struct grant_entry_v1 { - /* GTF_xxx: various type and flag information. [XEN,GST] */ - uint16_t flags; - /* The domain being granted foreign privileges. [GST] */ - domid_t domid; - /* - * GTF_permit_access: Frame that @domid is allowed to map and access. [GST] - * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN] - */ - uint32_t frame; -}; -typedef struct grant_entry_v1 grant_entry_v1_t; - -/* The first few grant table entries will be preserved across grant table - * version changes and may be pre-populated at domain creation by tools. - */ -#define GNTTAB_NR_RESERVED_ENTRIES 8 -#define GNTTAB_RESERVED_CONSOLE 0 -#define GNTTAB_RESERVED_XENSTORE 1 - -/* - * Type of grant entry. - * GTF_invalid: This grant entry grants no privileges. - * GTF_permit_access: Allow @domid to map/access @frame. - * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame - * to this guest. Xen writes the page number to @frame. - * GTF_transitive: Allow @domid to transitively access a subrange of - * @trans_grant in @trans_domid. No mappings are allowed. - */ -#define GTF_invalid (0U<<0) -#define GTF_permit_access (1U<<0) -#define GTF_accept_transfer (2U<<0) -#define GTF_transitive (3U<<0) -#define GTF_type_mask (3U<<0) - -/* - * Subflags for GTF_permit_access. - * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST] - * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN] - * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN] - * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST] - * GTF_sub_page: Grant access to only a subrange of the page. @domid - * will only be allowed to copy from the grant, and not - * map it. [GST] - */ -#define _GTF_readonly (2) -#define GTF_readonly (1U<<_GTF_readonly) -#define _GTF_reading (3) -#define GTF_reading (1U<<_GTF_reading) -#define _GTF_writing (4) -#define GTF_writing (1U<<_GTF_writing) -#define _GTF_PWT (5) -#define GTF_PWT (1U<<_GTF_PWT) -#define _GTF_PCD (6) -#define GTF_PCD (1U<<_GTF_PCD) -#define _GTF_PAT (7) -#define GTF_PAT (1U<<_GTF_PAT) -#define _GTF_sub_page (8) -#define GTF_sub_page (1U<<_GTF_sub_page) - -/* - * Subflags for GTF_accept_transfer: - * GTF_transfer_committed: Xen sets this flag to indicate that it is committed - * to transferring ownership of a page frame. When a guest sees this flag - * it must /not/ modify the grant entry until GTF_transfer_completed is - * set by Xen. - * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag - * after reading GTF_transfer_committed. Xen will always write the frame - * address, followed by ORing this flag, in a timely manner. - */ -#define _GTF_transfer_committed (2) -#define GTF_transfer_committed (1U<<_GTF_transfer_committed) -#define _GTF_transfer_completed (3) -#define GTF_transfer_completed (1U<<_GTF_transfer_completed) - -/* - * Version 2 grant table entries. These fulfil the same role as - * version 1 entries, but can represent more complicated operations. - * Any given domain will have either a version 1 or a version 2 table, - * and every entry in the table will be the same version. - * - * The interface by which domains use grant references does not depend - * on the grant table version in use by the other domain. - */ -#if __XEN_INTERFACE_VERSION__ >= 0x0003020a -/* - * Version 1 and version 2 grant entries share a common prefix. The - * fields of the prefix are documented as part of struct - * grant_entry_v1. - */ -struct grant_entry_header { - uint16_t flags; - domid_t domid; -}; -typedef struct grant_entry_header grant_entry_header_t; - -/* - * Version 2 of the grant entry structure. - */ -union grant_entry_v2 { - grant_entry_header_t hdr; - - /* - * This member is used for V1-style full page grants, where either: - * - * -- hdr.type is GTF_accept_transfer, or - * -- hdr.type is GTF_permit_access and GTF_sub_page is not set. - * - * In that case, the frame field has the same semantics as the - * field of the same name in the V1 entry structure. - */ - struct { - grant_entry_header_t hdr; - uint32_t pad0; - uint64_t frame; - } full_page; - - /* - * If the grant type is GTF_grant_access and GTF_sub_page is set, - * @domid is allowed to access bytes [@page_off,@page_off+@length) - * in frame @frame. - */ - struct { - grant_entry_header_t hdr; - uint16_t page_off; - uint16_t length; - uint64_t frame; - } sub_page; - - /* - * If the grant is GTF_transitive, @domid is allowed to use the - * grant @gref in domain @trans_domid, as if it was the local - * domain. Obviously, the transitive access must be compatible - * with the original grant. - * - * The current version of Xen does not allow transitive grants - * to be mapped. - */ - struct { - grant_entry_header_t hdr; - domid_t trans_domid; - uint16_t pad0; - grant_ref_t gref; - } transitive; - - uint32_t __spacer[4]; /* Pad to a power of two */ -}; -typedef union grant_entry_v2 grant_entry_v2_t; - -typedef uint16_t grant_status_t; - -#endif /* __XEN_INTERFACE_VERSION__ */ - -/*********************************** - * GRANT TABLE QUERIES AND USES - */ - -/* ` enum neg_errnoval - * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd, - * ` void *args, - * ` unsigned int count) - * ` - * - * @args points to an array of a per-command data structure. The array - * has @count members - */ - -/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */ -#define GNTTABOP_map_grant_ref 0 -#define GNTTABOP_unmap_grant_ref 1 -#define GNTTABOP_setup_table 2 -#define GNTTABOP_dump_table 3 -#define GNTTABOP_transfer 4 -#define GNTTABOP_copy 5 -#define GNTTABOP_query_size 6 -#define GNTTABOP_unmap_and_replace 7 -#if __XEN_INTERFACE_VERSION__ >= 0x0003020a -#define GNTTABOP_set_version 8 -#define GNTTABOP_get_status_frames 9 -#define GNTTABOP_get_version 10 -#define GNTTABOP_swap_grant_ref 11 -#endif /* __XEN_INTERFACE_VERSION__ */ -/* ` } */ - -/* - * Handle to track a mapping created via a grant reference. - */ -typedef uint32_t grant_handle_t; - -/* - * GNTTABOP_map_grant_ref: Map the grant entry (,) for access - * by devices and/or host CPUs. If successful, is a tracking number - * that must be presented later to destroy the mapping(s). On error, - * is a negative status code. - * NOTES: - * 1. If GNTMAP_device_map is specified then is the address - * via which I/O devices may access the granted frame. - * 2. If GNTMAP_host_map is specified then a mapping will be added at - * either a host virtual address in the current address space, or at - * a PTE at the specified machine address. The type of mapping to - * perform is selected through the GNTMAP_contains_pte flag, and the - * address is specified in . - * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a - * host mapping is destroyed by other means then it is *NOT* guaranteed - * to be accounted to the correct grant reference! - */ -struct gnttab_map_grant_ref { - /* IN parameters. */ - uint64_t host_addr; - uint32_t flags; /* GNTMAP_* */ - grant_ref_t ref; - domid_t dom; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ - grant_handle_t handle; - uint64_t dev_bus_addr; -}; -typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t); - -/* - * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings - * tracked by . If or is zero, that - * field is ignored. If non-zero, they must refer to a device/host mapping - * that is tracked by - * NOTES: - * 1. The call may fail in an undefined manner if either mapping is not - * tracked by . - * 3. After executing a batch of unmaps, it is guaranteed that no stale - * mappings will remain in the device or host TLBs. - */ -struct gnttab_unmap_grant_ref { - /* IN parameters. */ - uint64_t host_addr; - uint64_t dev_bus_addr; - grant_handle_t handle; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ -}; -typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t); - -/* - * GNTTABOP_setup_table: Set up a grant table for comprising at least - * pages. The frame addresses are written to the . - * Only addresses are written, even if the table is larger. - * NOTES: - * 1. may be specified as DOMID_SELF. - * 2. Only a sufficiently-privileged domain may specify != DOMID_SELF. - * 3. Xen may not support more than a single grant-table page per domain. - */ -struct gnttab_setup_table { - /* IN parameters. */ - domid_t dom; - uint32_t nr_frames; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ -#if __XEN_INTERFACE_VERSION__ < 0x00040300 - XEN_GUEST_HANDLE(ulong) frame_list; -#else - XEN_GUEST_HANDLE(xen_pfn_t) frame_list; -#endif -}; -typedef struct gnttab_setup_table gnttab_setup_table_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t); - -/* - * GNTTABOP_dump_table: Dump the contents of the grant table to the - * xen console. Debugging use only. - */ -struct gnttab_dump_table { - /* IN parameters. */ - domid_t dom; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ -}; -typedef struct gnttab_dump_table gnttab_dump_table_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t); - -/* - * GNTTABOP_transfer_grant_ref: Transfer to a foreign domain. The - * foreign domain has previously registered its interest in the transfer via - * . - * - * Note that, even if the transfer fails, the specified page no longer belongs - * to the calling domain *unless* the error is GNTST_bad_page. - */ -struct gnttab_transfer { - /* IN parameters. */ - xen_pfn_t mfn; - domid_t domid; - grant_ref_t ref; - /* OUT parameters. */ - int16_t status; -}; -typedef struct gnttab_transfer gnttab_transfer_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t); - - -/* - * GNTTABOP_copy: Hypervisor based copy - * source and destinations can be eithers MFNs or, for foreign domains, - * grant references. the foreign domain has to grant read/write access - * in its grant table. - * - * The flags specify what type source and destinations are (either MFN - * or grant reference). - * - * Note that this can also be used to copy data between two domains - * via a third party if the source and destination domains had previously - * grant appropriate access to their pages to the third party. - * - * source_offset specifies an offset in the source frame, dest_offset - * the offset in the target frame and len specifies the number of - * bytes to be copied. - */ - -#define _GNTCOPY_source_gref (0) -#define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref) -#define _GNTCOPY_dest_gref (1) -#define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref) - -struct gnttab_copy { - /* IN parameters. */ - struct { - union { - grant_ref_t ref; - xen_pfn_t gmfn; - } u; - domid_t domid; - uint16_t offset; - } source, dest; - uint16_t len; - uint16_t flags; /* GNTCOPY_* */ - /* OUT parameters. */ - int16_t status; -}; -typedef struct gnttab_copy gnttab_copy_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t); - -/* - * GNTTABOP_query_size: Query the current and maximum sizes of the shared - * grant table. - * NOTES: - * 1. may be specified as DOMID_SELF. - * 2. Only a sufficiently-privileged domain may specify != DOMID_SELF. - */ -struct gnttab_query_size { - /* IN parameters. */ - domid_t dom; - /* OUT parameters. */ - uint32_t nr_frames; - uint32_t max_nr_frames; - int16_t status; /* => enum grant_status */ -}; -typedef struct gnttab_query_size gnttab_query_size_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t); - -/* - * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings - * tracked by but atomically replace the page table entry with one - * pointing to the machine address under . will be - * redirected to the null entry. - * NOTES: - * 1. The call may fail in an undefined manner if either mapping is not - * tracked by . - * 2. After executing a batch of unmaps, it is guaranteed that no stale - * mappings will remain in the device or host TLBs. - */ -struct gnttab_unmap_and_replace { - /* IN parameters. */ - uint64_t host_addr; - uint64_t new_addr; - grant_handle_t handle; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ -}; -typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t); - -#if __XEN_INTERFACE_VERSION__ >= 0x0003020a -/* - * GNTTABOP_set_version: Request a particular version of the grant - * table shared table structure. This operation can only be performed - * once in any given domain. It must be performed before any grants - * are activated; otherwise, the domain will be stuck with version 1. - * The only defined versions are 1 and 2. - */ -struct gnttab_set_version { - /* IN/OUT parameters */ - uint32_t version; -}; -typedef struct gnttab_set_version gnttab_set_version_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t); - - -/* - * GNTTABOP_get_status_frames: Get the list of frames used to store grant - * status for . In grant format version 2, the status is separated - * from the other shared grant fields to allow more efficient synchronization - * using barriers instead of atomic cmpexch operations. - * specify the size of vector . - * The frame addresses are returned in the . - * Only addresses are returned, even if the table is larger. - * NOTES: - * 1. may be specified as DOMID_SELF. - * 2. Only a sufficiently-privileged domain may specify != DOMID_SELF. - */ -struct gnttab_get_status_frames { - /* IN parameters. */ - uint32_t nr_frames; - domid_t dom; - /* OUT parameters. */ - int16_t status; /* => enum grant_status */ - XEN_GUEST_HANDLE(uint64_t) frame_list; -}; -typedef struct gnttab_get_status_frames gnttab_get_status_frames_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t); - -/* - * GNTTABOP_get_version: Get the grant table version which is in - * effect for domain . - */ -struct gnttab_get_version { - /* IN parameters */ - domid_t dom; - uint16_t pad; - /* OUT parameters */ - uint32_t version; -}; -typedef struct gnttab_get_version gnttab_get_version_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t); - -/* - * GNTTABOP_swap_grant_ref: Swap the contents of two grant entries. - */ -struct gnttab_swap_grant_ref { - /* IN parameters */ - grant_ref_t ref_a; - grant_ref_t ref_b; - /* OUT parameters */ - int16_t status; /* => enum grant_status */ -}; -typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t; -DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t); - -#endif /* __XEN_INTERFACE_VERSION__ */ - -/* - * Bitfield values for gnttab_map_grant_ref.flags. - */ - /* Map the grant entry for access by I/O devices. */ -#define _GNTMAP_device_map (0) -#define GNTMAP_device_map (1<<_GNTMAP_device_map) - /* Map the grant entry for access by host CPUs. */ -#define _GNTMAP_host_map (1) -#define GNTMAP_host_map (1<<_GNTMAP_host_map) - /* Accesses to the granted frame will be restricted to read-only access. */ -#define _GNTMAP_readonly (2) -#define GNTMAP_readonly (1<<_GNTMAP_readonly) - /* - * GNTMAP_host_map subflag: - * 0 => The host mapping is usable only by the guest OS. - * 1 => The host mapping is usable by guest OS + current application. - */ -#define _GNTMAP_application_map (3) -#define GNTMAP_application_map (1<<_GNTMAP_application_map) - - /* - * GNTMAP_contains_pte subflag: - * 0 => This map request contains a host virtual address. - * 1 => This map request contains the machine addess of the PTE to update. - */ -#define _GNTMAP_contains_pte (4) -#define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte) - -#define _GNTMAP_can_fail (5) -#define GNTMAP_can_fail (1<<_GNTMAP_can_fail) - -/* - * Bits to be placed in guest kernel available PTE bits (architecture - * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set). - */ -#define _GNTMAP_guest_avail0 (16) -#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0) - -/* - * Values for error status returns. All errors are -ve. - */ -/* ` enum grant_status { */ -#define GNTST_okay (0) /* Normal return. */ -#define GNTST_general_error (-1) /* General undefined error. */ -#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */ -#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */ -#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */ -#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */ -#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/ -#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */ -#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */ -#define GNTST_bad_page (-9) /* Specified page was invalid for op. */ -#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */ -#define GNTST_address_too_big (-11) /* transfer page address too large. */ -#define GNTST_eagain (-12) /* Operation not done; try again. */ -/* ` } */ - -#define GNTTABOP_error_msgs { \ - "okay", \ - "undefined error", \ - "unrecognised domain id", \ - "invalid grant reference", \ - "invalid mapping handle", \ - "invalid virtual address", \ - "invalid device address", \ - "no spare translation slot in the I/O MMU", \ - "permission denied", \ - "bad page", \ - "copy arguments cross page boundary", \ - "page address size too large", \ - "operation not done; try again" \ -} - -#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/hvm/hvm_op.h b/include/xen/hvm/hvm_op.h deleted file mode 100644 index 0bdafdf59..000000000 --- a/include/xen/hvm/hvm_op.h +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2007, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_HVM_HVM_OP_H__ -#define __XEN_PUBLIC_HVM_HVM_OP_H__ - -#include "../xen.h" -#include "../trace.h" -#include "../event_channel.h" - -/* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */ -#define HVMOP_set_param 0 -#define HVMOP_get_param 1 -struct xen_hvm_param { - domid_t domid; /* IN */ - uint32_t index; /* IN */ - uint64_t value; /* IN/OUT */ -}; -typedef struct xen_hvm_param xen_hvm_param_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t); - -#if __XEN_INTERFACE_VERSION__ < 0x00040900 - -/* Set the logical level of one of a domain's PCI INTx wires. */ -#define HVMOP_set_pci_intx_level 2 -struct xen_hvm_set_pci_intx_level { - /* Domain to be updated. */ - domid_t domid; - /* PCI INTx identification in PCI topology (domain:bus:device:intx). */ - uint8_t domain, bus, device, intx; - /* Assertion level (0 = unasserted, 1 = asserted). */ - uint8_t level; -}; -typedef struct xen_hvm_set_pci_intx_level xen_hvm_set_pci_intx_level_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t); - -/* Set the logical level of one of a domain's ISA IRQ wires. */ -#define HVMOP_set_isa_irq_level 3 -struct xen_hvm_set_isa_irq_level { - /* Domain to be updated. */ - domid_t domid; - /* ISA device identification, by ISA IRQ (0-15). */ - uint8_t isa_irq; - /* Assertion level (0 = unasserted, 1 = asserted). */ - uint8_t level; -}; -typedef struct xen_hvm_set_isa_irq_level xen_hvm_set_isa_irq_level_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t); - -#define HVMOP_set_pci_link_route 4 -struct xen_hvm_set_pci_link_route { - /* Domain to be updated. */ - domid_t domid; - /* PCI link identifier (0-3). */ - uint8_t link; - /* ISA IRQ (1-15), or 0 (disable link). */ - uint8_t isa_irq; -}; -typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t); - -#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */ - -/* Flushes all VCPU TLBs: @arg must be NULL. */ -#define HVMOP_flush_tlbs 5 - -typedef enum { - HVMMEM_ram_rw, /* Normal read/write guest RAM */ - HVMMEM_ram_ro, /* Read-only; writes are discarded */ - HVMMEM_mmio_dm, /* Reads and write go to the device model */ -#if __XEN_INTERFACE_VERSION__ < 0x00040700 - HVMMEM_mmio_write_dm, /* Read-only; writes go to the device model */ -#else - HVMMEM_unused, /* Placeholder; setting memory to this type - will fail for code after 4.7.0 */ -#endif - HVMMEM_ioreq_server /* Memory type claimed by an ioreq server; type - changes to this value are only allowed after - an ioreq server has claimed its ownership. - Only pages with HVMMEM_ram_rw are allowed to - change to this type; conversely, pages with - this type are only allowed to be changed back - to HVMMEM_ram_rw. */ -} hvmmem_type_t; - -/* Hint from PV drivers for pagetable destruction. */ -#define HVMOP_pagetable_dying 9 -struct xen_hvm_pagetable_dying { - /* Domain with a pagetable about to be destroyed. */ - domid_t domid; - uint16_t pad[3]; /* align next field on 8-byte boundary */ - /* guest physical address of the toplevel pagetable dying */ - uint64_t gpa; -}; -typedef struct xen_hvm_pagetable_dying xen_hvm_pagetable_dying_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_pagetable_dying_t); - -/* Get the current Xen time, in nanoseconds since system boot. */ -#define HVMOP_get_time 10 -struct xen_hvm_get_time { - uint64_t now; /* OUT */ -}; -typedef struct xen_hvm_get_time xen_hvm_get_time_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_time_t); - -#define HVMOP_xentrace 11 -struct xen_hvm_xentrace { - uint16_t event, extra_bytes; - uint8_t extra[TRACE_EXTRA_MAX * sizeof(uint32_t)]; -}; -typedef struct xen_hvm_xentrace xen_hvm_xentrace_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t); - -/* Following tools-only interfaces may change in future. */ -#if defined(__XEN__) || defined(__XEN_TOOLS__) - -/* Deprecated by XENMEM_access_op_set_access */ -#define HVMOP_set_mem_access 12 - -/* Deprecated by XENMEM_access_op_get_access */ -#define HVMOP_get_mem_access 13 - -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ - -#define HVMOP_get_mem_type 15 -/* Return hvmmem_type_t for the specified pfn. */ -struct xen_hvm_get_mem_type { - /* Domain to be queried. */ - domid_t domid; - /* OUT variable. */ - uint16_t mem_type; - uint16_t pad[2]; /* align next field on 8-byte boundary */ - /* IN variable. */ - uint64_t pfn; -}; -typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t); - -/* Following tools-only interfaces may change in future. */ -#if defined(__XEN__) || defined(__XEN_TOOLS__) - -/* - * Definitions relating to DMOP_create_ioreq_server. (Defined here for - * backwards compatibility). - */ - -#define HVM_IOREQSRV_BUFIOREQ_OFF 0 -#define HVM_IOREQSRV_BUFIOREQ_LEGACY 1 -/* - * Use this when read_pointer gets updated atomically and - * the pointer pair gets read atomically: - */ -#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2 - -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ - -#if defined(__i386__) || defined(__x86_64__) - -/* - * HVMOP_set_evtchn_upcall_vector: Set a that should be used for event - * channel upcalls on the specified . If set, - * this vector will be used in preference to the - * domain global callback via (see - * HVM_PARAM_CALLBACK_IRQ). - */ -#define HVMOP_set_evtchn_upcall_vector 23 -struct xen_hvm_evtchn_upcall_vector { - uint32_t vcpu; - uint8_t vector; -}; -typedef struct xen_hvm_evtchn_upcall_vector xen_hvm_evtchn_upcall_vector_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_evtchn_upcall_vector_t); - -#endif /* defined(__i386__) || defined(__x86_64__) */ - -#define HVMOP_guest_request_vm_event 24 - -/* HVMOP_altp2m: perform altp2m state operations */ -#define HVMOP_altp2m 25 - -#define HVMOP_ALTP2M_INTERFACE_VERSION 0x00000001 - -struct xen_hvm_altp2m_domain_state { - /* IN or OUT variable on/off */ - uint8_t state; -}; -typedef struct xen_hvm_altp2m_domain_state xen_hvm_altp2m_domain_state_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_domain_state_t); - -struct xen_hvm_altp2m_vcpu_enable_notify { - uint32_t vcpu_id; - uint32_t pad; - /* #VE info area gfn */ - uint64_t gfn; -}; -typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_enable_notify_t); - -struct xen_hvm_altp2m_view { - /* IN/OUT variable */ - uint16_t view; - /* Create view only: default access type - * NOTE: currently ignored */ - uint16_t hvmmem_default_access; /* xenmem_access_t */ -}; -typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_view_t); - -struct xen_hvm_altp2m_set_mem_access { - /* view */ - uint16_t view; - /* Memory type */ - uint16_t hvmmem_access; /* xenmem_access_t */ - uint32_t pad; - /* gfn */ - uint64_t gfn; -}; -typedef struct xen_hvm_altp2m_set_mem_access xen_hvm_altp2m_set_mem_access_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_set_mem_access_t); - -struct xen_hvm_altp2m_change_gfn { - /* view */ - uint16_t view; - uint16_t pad1; - uint32_t pad2; - /* old gfn */ - uint64_t old_gfn; - /* new gfn, INVALID_GFN (~0UL) means revert */ - uint64_t new_gfn; -}; -typedef struct xen_hvm_altp2m_change_gfn xen_hvm_altp2m_change_gfn_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_change_gfn_t); - -struct xen_hvm_altp2m_op { - uint32_t version; /* HVMOP_ALTP2M_INTERFACE_VERSION */ - uint32_t cmd; -/* Get/set the altp2m state for a domain */ -#define HVMOP_altp2m_get_domain_state 1 -#define HVMOP_altp2m_set_domain_state 2 -/* Set the current VCPU to receive altp2m event notifications */ -#define HVMOP_altp2m_vcpu_enable_notify 3 -/* Create a new view */ -#define HVMOP_altp2m_create_p2m 4 -/* Destroy a view */ -#define HVMOP_altp2m_destroy_p2m 5 -/* Switch view for an entire domain */ -#define HVMOP_altp2m_switch_p2m 6 -/* Notify that a page of memory is to have specific access types */ -#define HVMOP_altp2m_set_mem_access 7 -/* Change a p2m entry to have a different gfn->mfn mapping */ -#define HVMOP_altp2m_change_gfn 8 - domid_t domain; - uint16_t pad1; - uint32_t pad2; - union { - struct xen_hvm_altp2m_domain_state domain_state; - struct xen_hvm_altp2m_vcpu_enable_notify enable_notify; - struct xen_hvm_altp2m_view view; - struct xen_hvm_altp2m_set_mem_access set_mem_access; - struct xen_hvm_altp2m_change_gfn change_gfn; - uint8_t pad[64]; - } u; -}; -typedef struct xen_hvm_altp2m_op xen_hvm_altp2m_op_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_op_t); - -#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/hvm/params.h b/include/xen/hvm/params.h deleted file mode 100644 index 2ec2e7c80..000000000 --- a/include/xen/hvm/params.h +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2007, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_HVM_PARAMS_H__ -#define __XEN_PUBLIC_HVM_PARAMS_H__ - -#include "hvm_op.h" - -/* - * Parameter space for HVMOP_{set,get}_param. - */ - -#define HVM_PARAM_CALLBACK_IRQ 0 -#define HVM_PARAM_CALLBACK_IRQ_TYPE_MASK xen_mk_ullong(0xFF00000000000000) -/* - * How should CPU0 event-channel notifications be delivered? - * - * If val == 0 then CPU0 event-channel notifications are not delivered. - * If val != 0, val[63:56] encodes the type, as follows: - */ - -#define HVM_PARAM_CALLBACK_TYPE_GSI 0 -/* - * val[55:0] is a delivery GSI. GSI 0 cannot be used, as it aliases val == 0, - * and disables all notifications. - */ - -#define HVM_PARAM_CALLBACK_TYPE_PCI_INTX 1 -/* - * val[55:0] is a delivery PCI INTx line: - * Domain = val[47:32], Bus = val[31:16] DevFn = val[15:8], IntX = val[1:0] - */ - -#if defined(__i386__) || defined(__x86_64__) -#define HVM_PARAM_CALLBACK_TYPE_VECTOR 2 -/* - * val[7:0] is a vector number. Check for XENFEAT_hvm_callback_vector to know - * if this delivery method is available. - */ -#elif defined(__arm__) || defined(__aarch64__) -#define HVM_PARAM_CALLBACK_TYPE_PPI 2 -/* - * val[55:16] needs to be zero. - * val[15:8] is interrupt flag of the PPI used by event-channel: - * bit 8: the PPI is edge(1) or level(0) triggered - * bit 9: the PPI is active low(1) or high(0) - * val[7:0] is a PPI number used by event-channel. - * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to - * the notification is handled by the interrupt controller. - */ -#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK 0xFF00 -#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2 -#endif - -/* - * These are not used by Xen. They are here for convenience of HVM-guest - * xenbus implementations. - */ -#define HVM_PARAM_STORE_PFN 1 -#define HVM_PARAM_STORE_EVTCHN 2 - -#define HVM_PARAM_PAE_ENABLED 4 - -#define HVM_PARAM_IOREQ_PFN 5 - -#define HVM_PARAM_BUFIOREQ_PFN 6 -#define HVM_PARAM_BUFIOREQ_EVTCHN 26 - -#if defined(__i386__) || defined(__x86_64__) - -/* - * Viridian enlightenments - * - * (See http://download.microsoft.com/download/A/B/4/AB43A34E-BDD0-4FA6-BDEF-79EEF16E880B/Hypervisor%20Top%20Level%20Functional%20Specification%20v4.0.docx) - * - * To expose viridian enlightenments to the guest set this parameter - * to the desired feature mask. The base feature set must be present - * in any valid feature mask. - */ -#define HVM_PARAM_VIRIDIAN 9 - -/* Base+Freq viridian feature sets: - * - * - Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) - * - APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR) - * - Virtual Processor index MSR (HV_X64_MSR_VP_INDEX) - * - Timer frequency MSRs (HV_X64_MSR_TSC_FREQUENCY and - * HV_X64_MSR_APIC_FREQUENCY) - */ -#define _HVMPV_base_freq 0 -#define HVMPV_base_freq (1 << _HVMPV_base_freq) - -/* Feature set modifications */ - -/* Disable timer frequency MSRs (HV_X64_MSR_TSC_FREQUENCY and - * HV_X64_MSR_APIC_FREQUENCY). - * This modification restores the viridian feature set to the - * original 'base' set exposed in releases prior to Xen 4.4. - */ -#define _HVMPV_no_freq 1 -#define HVMPV_no_freq (1 << _HVMPV_no_freq) - -/* Enable Partition Time Reference Counter (HV_X64_MSR_TIME_REF_COUNT) */ -#define _HVMPV_time_ref_count 2 -#define HVMPV_time_ref_count (1 << _HVMPV_time_ref_count) - -/* Enable Reference TSC Page (HV_X64_MSR_REFERENCE_TSC) */ -#define _HVMPV_reference_tsc 3 -#define HVMPV_reference_tsc (1 << _HVMPV_reference_tsc) - -/* Use Hypercall for remote TLB flush */ -#define _HVMPV_hcall_remote_tlb_flush 4 -#define HVMPV_hcall_remote_tlb_flush (1 << _HVMPV_hcall_remote_tlb_flush) - -/* Use APIC assist */ -#define _HVMPV_apic_assist 5 -#define HVMPV_apic_assist (1 << _HVMPV_apic_assist) - -/* Enable crash MSRs */ -#define _HVMPV_crash_ctl 6 -#define HVMPV_crash_ctl (1 << _HVMPV_crash_ctl) - -#define HVMPV_feature_mask \ - (HVMPV_base_freq | \ - HVMPV_no_freq | \ - HVMPV_time_ref_count | \ - HVMPV_reference_tsc | \ - HVMPV_hcall_remote_tlb_flush | \ - HVMPV_apic_assist | \ - HVMPV_crash_ctl) - -#endif - -/* - * Set mode for virtual timers (currently x86 only): - * delay_for_missed_ticks (default): - * Do not advance a vcpu's time beyond the correct delivery time for - * interrupts that have been missed due to preemption. Deliver missed - * interrupts when the vcpu is rescheduled and advance the vcpu's virtual - * time stepwise for each one. - * no_delay_for_missed_ticks: - * As above, missed interrupts are delivered, but guest time always tracks - * wallclock (i.e., real) time while doing so. - * no_missed_ticks_pending: - * No missed interrupts are held pending. Instead, to ensure ticks are - * delivered at some non-zero rate, if we detect missed ticks then the - * internal tick alarm is not disabled if the VCPU is preempted during the - * next tick period. - * one_missed_tick_pending: - * Missed interrupts are collapsed together and delivered as one 'late tick'. - * Guest time always tracks wallclock (i.e., real) time. - */ -#define HVM_PARAM_TIMER_MODE 10 -#define HVMPTM_delay_for_missed_ticks 0 -#define HVMPTM_no_delay_for_missed_ticks 1 -#define HVMPTM_no_missed_ticks_pending 2 -#define HVMPTM_one_missed_tick_pending 3 - -/* Boolean: Enable virtual HPET (high-precision event timer)? (x86-only) */ -#define HVM_PARAM_HPET_ENABLED 11 - -/* Identity-map page directory used by Intel EPT when CR0.PG=0. */ -#define HVM_PARAM_IDENT_PT 12 - -/* Device Model domain, defaults to 0. */ -#define HVM_PARAM_DM_DOMAIN 13 - -/* ACPI S state: currently support S0 and S3 on x86. */ -#define HVM_PARAM_ACPI_S_STATE 14 - -/* TSS used on Intel when CR0.PE=0. */ -#define HVM_PARAM_VM86_TSS 15 - -/* Boolean: Enable aligning all periodic vpts to reduce interrupts */ -#define HVM_PARAM_VPT_ALIGN 16 - -/* Console debug shared memory ring and event channel */ -#define HVM_PARAM_CONSOLE_PFN 17 -#define HVM_PARAM_CONSOLE_EVTCHN 18 - -/* - * Select location of ACPI PM1a and TMR control blocks. Currently two locations - * are supported, specified by version 0 or 1 in this parameter: - * - 0: default, use the old addresses - * PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48 - * - 1: use the new default qemu addresses - * PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008 - * You can find these address definitions in - */ -#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19 - -/* Deprecated */ -#define HVM_PARAM_MEMORY_EVENT_CR0 20 -#define HVM_PARAM_MEMORY_EVENT_CR3 21 -#define HVM_PARAM_MEMORY_EVENT_CR4 22 -#define HVM_PARAM_MEMORY_EVENT_INT3 23 -#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25 -#define HVM_PARAM_MEMORY_EVENT_MSR 30 - -/* Boolean: Enable nestedhvm (hvm only) */ -#define HVM_PARAM_NESTEDHVM 24 - -/* Params for the mem event rings */ -#define HVM_PARAM_PAGING_RING_PFN 27 -#define HVM_PARAM_MONITOR_RING_PFN 28 -#define HVM_PARAM_SHARING_RING_PFN 29 - -/* SHUTDOWN_* action in case of a triple fault */ -#define HVM_PARAM_TRIPLE_FAULT_REASON 31 - -#define HVM_PARAM_IOREQ_SERVER_PFN 32 -#define HVM_PARAM_NR_IOREQ_SERVER_PAGES 33 - -/* Location of the VM Generation ID in guest physical address space. */ -#define HVM_PARAM_VM_GENERATION_ID_ADDR 34 - -/* - * Set mode for altp2m: - * disabled: don't activate altp2m (default) - * mixed: allow access to all altp2m ops for both in-guest and external tools - * external: allow access to external privileged tools only - * limited: guest only has limited access (ie. control VMFUNC and #VE) - */ -#define HVM_PARAM_ALTP2M 35 -#define XEN_ALTP2M_disabled 0 -#define XEN_ALTP2M_mixed 1 -#define XEN_ALTP2M_external 2 -#define XEN_ALTP2M_limited 3 - -/* - * Size of the x87 FPU FIP/FDP registers that the hypervisor needs to - * save/restore. This is a workaround for a hardware limitation that - * does not allow the full FIP/FDP and FCS/FDS to be restored. - * - * Valid values are: - * - * 8: save/restore 64-bit FIP/FDP and clear FCS/FDS (default if CPU - * has FPCSDS feature). - * - * 4: save/restore 32-bit FIP/FDP, FCS/FDS, and clear upper 32-bits of - * FIP/FDP. - * - * 0: allow hypervisor to choose based on the value of FIP/FDP - * (default if CPU does not have FPCSDS). - * - * If FPCSDS (bit 13 in CPUID leaf 0x7, subleaf 0x0) is set, the CPU - * never saves FCS/FDS and this parameter should be left at the - * default of 8. - */ -#define HVM_PARAM_X87_FIP_WIDTH 36 - -/* - * TSS (and its size) used on Intel when CR0.PE=0. The address occupies - * the low 32 bits, while the size is in the high 32 ones. - */ -#define HVM_PARAM_VM86_TSS_SIZED 37 - -/* Enable MCA capabilities. */ -#define HVM_PARAM_MCA_CAP 38 -#define XEN_HVM_MCA_CAP_LMCE (xen_mk_ullong(1) << 0) -#define XEN_HVM_MCA_CAP_MASK XEN_HVM_MCA_CAP_LMCE - -#define HVM_NR_PARAMS 39 - -#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */ diff --git a/include/xen/hvm/start_info.h b/include/xen/hvm/start_info.h deleted file mode 100644 index 648415976..000000000 --- a/include/xen/hvm/start_info.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2016, Citrix Systems, Inc. - */ - -#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ -#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ - -/* - * Start of day structure passed to PVH guests and to HVM guests in %ebx. - * - * NOTE: nothing will be loaded at physical address 0, so a 0 value in any - * of the address fields should be treated as not present. - * - * 0 +----------------+ - * | magic | Contains the magic value XEN_HVM_START_MAGIC_VALUE - * | | ("xEn3" with the 0x80 bit of the "E" set). - * 4 +----------------+ - * | version | Version of this structure. Current version is 0. New - * | | versions are guaranteed to be backwards-compatible. - * 8 +----------------+ - * | flags | SIF_xxx flags. - * 12 +----------------+ - * | nr_modules | Number of modules passed to the kernel. - * 16 +----------------+ - * | modlist_paddr | Physical address of an array of modules - * | | (layout of the structure below). - * 24 +----------------+ - * | cmdline_paddr | Physical address of the command line, - * | | a zero-terminated ASCII string. - * 32 +----------------+ - * | rsdp_paddr | Physical address of the RSDP ACPI data structure. - * 40 +----------------+ - * - * The layout of each entry in the module structure is the following: - * - * 0 +----------------+ - * | paddr | Physical address of the module. - * 8 +----------------+ - * | size | Size of the module in bytes. - * 16 +----------------+ - * | cmdline_paddr | Physical address of the command line, - * | | a zero-terminated ASCII string. - * 24 +----------------+ - * | reserved | - * 32 +----------------+ - * - * The address and sizes are always a 64bit little endian unsigned integer. - * - * NB: Xen on x86 will always try to place all the data below the 4GiB - * boundary. - */ -#define XEN_HVM_START_MAGIC_VALUE 0x336ec578 - -/* - * C representation of the x86/HVM start info layout. - * - * The canonical definition of this layout is above, this is just a way to - * represent the layout described there using C types. - */ -struct hvm_start_info { - uint32_t magic; /* Contains the magic value 0x336ec578 */ - /* ("xEn3" with the 0x80 bit of the "E" set).*/ - uint32_t version; /* Version of this structure. */ - uint32_t flags; /* SIF_xxx flags. */ - uint32_t nr_modules; /* Number of modules passed to the kernel. */ - uint64_t modlist_paddr; /* Physical address of an array of */ - /* hvm_modlist_entry. */ - uint64_t cmdline_paddr; /* Physical address of the command line. */ - uint64_t rsdp_paddr; /* Physical address of the RSDP ACPI data */ - /* structure. */ -}; - -struct hvm_modlist_entry { - uint64_t paddr; /* Physical address of the module. */ - uint64_t size; /* Size of the module in bytes. */ - uint64_t cmdline_paddr; /* Physical address of the command line. */ - uint64_t reserved; -}; - -#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */ diff --git a/include/xen/io/blkif.h b/include/xen/io/blkif.h deleted file mode 100644 index c3e169ce2..000000000 --- a/include/xen/io/blkif.h +++ /dev/null @@ -1,608 +0,0 @@ -/****************************************************************************** - * blkif.h - * - * Unified block-device I/O interface for Xen guest OSes. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2003-2004, Keir Fraser - * Copyright (c) 2012, Spectra Logic Corporation - */ - -#ifndef __XEN_PUBLIC_IO_BLKIF_H__ -#define __XEN_PUBLIC_IO_BLKIF_H__ - -#include "ring.h" -#include "../grant_table.h" - -/* - * Front->back notifications: When enqueuing a new request, sending a - * notification can be made conditional on req_event (i.e., the generic - * hold-off mechanism provided by the ring macros). Backends must set - * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()). - * - * Back->front notifications: When enqueuing a new response, sending a - * notification can be made conditional on rsp_event (i.e., the generic - * hold-off mechanism provided by the ring macros). Frontends must set - * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()). - */ - -#ifndef blkif_vdev_t -#define blkif_vdev_t uint16_t -#endif -#define blkif_sector_t uint64_t - -/* - * Feature and Parameter Negotiation - * ================================= - * The two halves of a Xen block driver utilize nodes within the XenStore to - * communicate capabilities and to negotiate operating parameters. This - * section enumerates these nodes which reside in the respective front and - * backend portions of the XenStore, following the XenBus convention. - * - * All data in the XenStore is stored as strings. Nodes specifying numeric - * values are encoded in decimal. Integer value ranges listed below are - * expressed as fixed sized integer types capable of storing the conversion - * of a properly formated node string, without loss of information. - * - * Any specified default value is in effect if the corresponding XenBus node - * is not present in the XenStore. - * - * XenStore nodes in sections marked "PRIVATE" are solely for use by the - * driver side whose XenBus tree contains them. - * - * XenStore nodes marked "DEPRECATED" in their notes section should only be - * used to provide interoperability with legacy implementations. - * - * See the XenBus state transition diagram below for details on when XenBus - * nodes must be published and when they can be queried. - * - ***************************************************************************** - * Backend XenBus Nodes - ***************************************************************************** - * - *------------------ Backend Device Identification (PRIVATE) ------------------ - * - * mode - * Values: "r" (read only), "w" (writable) - * - * The read or write access permissions to the backing store to be - * granted to the frontend. - * - * params - * Values: string - * - * A free formatted string providing sufficient information for the - * backend driver to open the backing device. (e.g. the path to the - * file or block device representing the backing store.) - * - * type - * Values: "file", "phy", "tap" - * - * The type of the backing device/object. - * - *--------------------------------- Features --------------------------------- - * - * feature-barrier - * Values: 0/1 (boolean) - * Default Value: 0 - * - * A value of "1" indicates that the backend can process requests - * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests - * of this type may still be returned at any time with the - * BLKIF_RSP_EOPNOTSUPP result code. - * - * feature-flush-cache - * Values: 0/1 (boolean) - * Default Value: 0 - * - * A value of "1" indicates that the backend can process requests - * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests - * of this type may still be returned at any time with the - * BLKIF_RSP_EOPNOTSUPP result code. - * - * feature-discard - * Values: 0/1 (boolean) - * Default Value: 0 - * - * A value of "1" indicates that the backend can process requests - * containing the BLKIF_OP_DISCARD request opcode. Requests - * of this type may still be returned at any time with the - * BLKIF_RSP_EOPNOTSUPP result code. - * - * feature-persistent - * Values: 0/1 (boolean) - * Default Value: 0 - * Notes: 7 - * - * A value of "1" indicates that the backend can keep the grants used - * by the frontend driver mapped, so the same set of grants should be - * used in all transactions. The maximum number of grants the backend - * can map persistently depends on the implementation, but ideally it - * should be RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. Using this - * feature the backend doesn't need to unmap each grant, preventing - * costly TLB flushes. The backend driver should only map grants - * persistently if the frontend supports it. If a backend driver chooses - * to use the persistent protocol when the frontend doesn't support it, - * it will probably hit the maximum number of persistently mapped grants - * (due to the fact that the frontend won't be reusing the same grants), - * and fall back to non-persistent mode. Backend implementations may - * shrink or expand the number of persistently mapped grants without - * notifying the frontend depending on memory constraints (this might - * cause a performance degradation). - * - * If a backend driver wants to limit the maximum number of persistently - * mapped grants to a value less than RING_SIZE * - * BLKIF_MAX_SEGMENTS_PER_REQUEST a LRU strategy should be used to - * discard the grants that are less commonly used. Using a LRU in the - * backend driver paired with a LIFO queue in the frontend will - * allow us to have better performance in this scenario. - * - *----------------------- Request Transport Parameters ------------------------ - * - * max-ring-page-order - * Values: - * Default Value: 0 - * Notes: 1, 3 - * - * The maximum supported size of the request ring buffer in units of - * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, - * etc.). - * - * max-ring-pages - * Values: - * Default Value: 1 - * Notes: DEPRECATED, 2, 3 - * - * The maximum supported size of the request ring buffer in units of - * machine pages. The value must be a power of 2. - * - *------------------------- Backend Device Properties ------------------------- - * - * discard-alignment - * Values: - * Default Value: 0 - * Notes: 4, 5 - * - * The offset, in bytes from the beginning of the virtual block device, - * to the first, addressable, discard extent on the underlying device. - * - * discard-granularity - * Values: - * Default Value: <"sector-size"> - * Notes: 4 - * - * The size, in bytes, of the individually addressable discard extents - * of the underlying device. - * - * discard-secure - * Values: 0/1 (boolean) - * Default Value: 0 - * Notes: 10 - * - * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD - * requests with the BLKIF_DISCARD_SECURE flag set. - * - * info - * Values: (bitmap) - * - * A collection of bit flags describing attributes of the backing - * device. The VDISK_* macros define the meaning of each bit - * location. - * - * sector-size - * Values: - * - * The logical sector size, in bytes, of the backend device. - * - * physical-sector-size - * Values: - * - * The physical sector size, in bytes, of the backend device. - * - * sectors - * Values: - * - * The size of the backend device, expressed in units of its logical - * sector size ("sector-size"). - * - ***************************************************************************** - * Frontend XenBus Nodes - ***************************************************************************** - * - *----------------------- Request Transport Parameters ----------------------- - * - * event-channel - * Values: - * - * The identifier of the Xen event channel used to signal activity - * in the ring buffer. - * - * ring-ref - * Values: - * Notes: 6 - * - * The Xen grant reference granting permission for the backend to map - * the sole page in a single page sized ring buffer. - * - * ring-ref%u - * Values: - * Notes: 6 - * - * For a frontend providing a multi-page ring, a "number of ring pages" - * sized list of nodes, each containing a Xen grant reference granting - * permission for the backend to map the page of the ring located - * at page index "%u". Page indexes are zero based. - * - * protocol - * Values: string (XEN_IO_PROTO_ABI_*) - * Default Value: XEN_IO_PROTO_ABI_NATIVE - * - * The machine ABI rules governing the format of all ring request and - * response structures. - * - * ring-page-order - * Values: - * Default Value: 0 - * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order) - * Notes: 1, 3 - * - * The size of the frontend allocated request ring buffer in units - * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, - * etc.). - * - * num-ring-pages - * Values: - * Default Value: 1 - * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order)) - * Notes: DEPRECATED, 2, 3 - * - * The size of the frontend allocated request ring buffer in units of - * machine pages. The value must be a power of 2. - * - * feature-persistent - * Values: 0/1 (boolean) - * Default Value: 0 - * Notes: 7, 8, 9 - * - * A value of "1" indicates that the frontend will reuse the same grants - * for all transactions, allowing the backend to map them with write - * access (even when it should be read-only). If the frontend hits the - * maximum number of allowed persistently mapped grants, it can fallback - * to non persistent mode. This will cause a performance degradation, - * since the the backend driver will still try to map those grants - * persistently. Since the persistent grants protocol is compatible with - * the previous protocol, a frontend driver can choose to work in - * persistent mode even when the backend doesn't support it. - * - * It is recommended that the frontend driver stores the persistently - * mapped grants in a LIFO queue, so a subset of all persistently mapped - * grants gets used commonly. This is done in case the backend driver - * decides to limit the maximum number of persistently mapped grants - * to a value less than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. - * - *------------------------- Virtual Device Properties ------------------------- - * - * device-type - * Values: "disk", "cdrom", "floppy", etc. - * - * virtual-device - * Values: - * - * A value indicating the physical device to virtualize within the - * frontend's domain. (e.g. "The first ATA disk", "The third SCSI - * disk", etc.) - * - * See docs/misc/vbd-interface.txt for details on the format of this - * value. - * - * Notes - * ----- - * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer - * PV drivers. - * (2) Multi-page ring buffer scheme first used in some RedHat distributions - * including a distribution deployed on certain nodes of the Amazon - * EC2 cluster. - * (3) Support for multi-page ring buffers was implemented independently, - * in slightly different forms, by both Citrix and RedHat/Amazon. - * For full interoperability, block front and backends should publish - * identical ring parameters, adjusted for unit differences, to the - * XenStore nodes used in both schemes. - * (4) Devices that support discard functionality may internally allocate space - * (discardable extents) in units that are larger than the exported logical - * block size. If the backing device has such discardable extents the - * backend should provide both discard-granularity and discard-alignment. - * Providing just one of the two may be considered an error by the frontend. - * Backends supporting discard should include discard-granularity and - * discard-alignment even if it supports discarding individual sectors. - * Frontends should assume discard-alignment == 0 and discard-granularity - * == sector size if these keys are missing. - * (5) The discard-alignment parameter allows a physical device to be - * partitioned into virtual devices that do not necessarily begin or - * end on a discardable extent boundary. - * (6) When there is only a single page allocated to the request ring, - * 'ring-ref' is used to communicate the grant reference for this - * page to the backend. When using a multi-page ring, the 'ring-ref' - * node is not created. Instead 'ring-ref0' - 'ring-refN' are used. - * (7) When using persistent grants data has to be copied from/to the page - * where the grant is currently mapped. The overhead of doing this copy - * however doesn't suppress the speed improvement of not having to unmap - * the grants. - * (8) The frontend driver has to allow the backend driver to map all grants - * with write access, even when they should be mapped read-only, since - * further requests may reuse these grants and require write permissions. - * (9) Linux implementation doesn't have a limit on the maximum number of - * grants that can be persistently mapped in the frontend driver, but - * due to the frontent driver implementation it should never be bigger - * than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. - *(10) The discard-secure property may be present and will be set to 1 if the - * backing device supports secure discard. - */ - -/* - * STATE DIAGRAMS - * - ***************************************************************************** - * Startup * - ***************************************************************************** - * - * Tool stack creates front and back nodes with state XenbusStateInitialising. - * - * Front Back - * ================================= ===================================== - * XenbusStateInitialising XenbusStateInitialising - * o Query virtual device o Query backend device identification - * properties. data. - * o Setup OS device instance. o Open and validate backend device. - * o Publish backend features and - * transport parameters. - * | - * | - * V - * XenbusStateInitWait - * - * o Query backend features and - * transport parameters. - * o Allocate and initialize the - * request ring. - * o Publish transport parameters - * that will be in effect during - * this connection. - * | - * | - * V - * XenbusStateInitialised - * - * o Query frontend transport parameters. - * o Connect to the request ring and - * event channel. - * o Publish backend device properties. - * | - * | - * V - * XenbusStateConnected - * - * o Query backend device properties. - * o Finalize OS virtual device - * instance. - * | - * | - * V - * XenbusStateConnected - * - * Note: Drivers that do not support any optional features, or the negotiation - * of transport parameters, can skip certain states in the state machine: - * - * o A frontend may transition to XenbusStateInitialised without - * waiting for the backend to enter XenbusStateInitWait. In this - * case, default transport parameters are in effect and any - * transport parameters published by the frontend must contain - * their default values. - * - * o A backend may transition to XenbusStateInitialised, bypassing - * XenbusStateInitWait, without waiting for the frontend to first - * enter the XenbusStateInitialised state. In this case, default - * transport parameters are in effect and any transport parameters - * published by the backend must contain their default values. - * - * Drivers that support optional features and/or transport parameter - * negotiation must tolerate these additional state transition paths. - * In general this means performing the work of any skipped state - * transition, if it has not already been performed, in addition to the - * work associated with entry into the current state. - */ - -/* - * REQUEST CODES. - */ -#define BLKIF_OP_READ 0 -#define BLKIF_OP_WRITE 1 -/* - * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER - * operation code ("barrier request") must be completed prior to the - * execution of the barrier request. All writes issued after the barrier - * request must not execute until after the completion of the barrier request. - * - * Optional. See "feature-barrier" XenBus node documentation above. - */ -#define BLKIF_OP_WRITE_BARRIER 2 -/* - * Commit any uncommitted contents of the backing device's volatile cache - * to stable storage. - * - * Optional. See "feature-flush-cache" XenBus node documentation above. - */ -#define BLKIF_OP_FLUSH_DISKCACHE 3 -/* - * Used in SLES sources for device specific command packet - * contained within the request. Reserved for that purpose. - */ -#define BLKIF_OP_RESERVED_1 4 -/* - * Indicate to the backend device that a region of storage is no longer in - * use, and may be discarded at any time without impact to the client. If - * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the - * discarded region on the device must be rendered unrecoverable before the - * command returns. - * - * This operation is analogous to performing a trim (ATA) or unamp (SCSI), - * command on a native device. - * - * More information about trim/unmap operations can be found at: - * http://t13.org/Documents/UploadedDocuments/docs2008/ - * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc - * http://www.seagate.com/staticfiles/support/disc/manuals/ - * Interface%20manuals/100293068c.pdf - * - * Optional. See "feature-discard", "discard-alignment", - * "discard-granularity", and "discard-secure" in the XenBus node - * documentation above. - */ -#define BLKIF_OP_DISCARD 5 - -/* - * Recognized if "feature-max-indirect-segments" in present in the backend - * xenbus info. The "feature-max-indirect-segments" node contains the maximum - * number of segments allowed by the backend per request. If the node is - * present, the frontend might use blkif_request_indirect structs in order to - * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The - * maximum number of indirect segments is fixed by the backend, but the - * frontend can issue requests with any number of indirect segments as long as - * it's less than the number provided by the backend. The indirect_grefs field - * in blkif_request_indirect should be filled by the frontend with the - * grant references of the pages that are holding the indirect segments. - * These pages are filled with an array of blkif_request_segment that hold the - * information about the segments. The number of indirect pages to use is - * determined by the number of segments an indirect request contains. Every - * indirect page can contain a maximum of - * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to - * calculate the number of indirect pages to use we have to do - * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))). - * - * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not* - * create the "feature-max-indirect-segments" node! - */ -#define BLKIF_OP_INDIRECT 6 - -/* - * Maximum scatter/gather segments per request. - * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE. - * NB. This could be 12 if the ring indexes weren't stored in the same page. - */ -#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11 - -/* - * Maximum number of indirect pages to use per request. - */ -#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8 - -/* - * NB. first_sect and last_sect in blkif_request_segment, as well as - * sector_number in blkif_request, are always expressed in 512-byte units. - * However they must be properly aligned to the real sector size of the - * physical disk, which is reported in the "physical-sector-size" node in - * the backend xenbus info. Also the xenbus "sectors" node is expressed in - * 512-byte units. - */ -struct blkif_request_segment { - grant_ref_t gref; /* reference to I/O buffer frame */ - /* @first_sect: first sector in frame to transfer (inclusive). */ - /* @last_sect: last sector in frame to transfer (inclusive). */ - uint8_t first_sect, last_sect; -}; - -/* - * Starting ring element for any I/O request. - */ -struct blkif_request { - uint8_t operation; /* BLKIF_OP_??? */ - uint8_t nr_segments; /* number of segments */ - blkif_vdev_t handle; /* only for read/write requests */ - uint64_t id; /* private guest value, echoed in resp */ - blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ - struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; -}; -typedef struct blkif_request blkif_request_t; - -/* - * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD - * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request) - */ -struct blkif_request_discard { - uint8_t operation; /* BLKIF_OP_DISCARD */ - uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */ -#define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */ - blkif_vdev_t handle; /* same as for read/write requests */ - uint64_t id; /* private guest value, echoed in resp */ - blkif_sector_t sector_number;/* start sector idx on disk */ - uint64_t nr_sectors; /* number of contiguous sectors to discard*/ -}; -typedef struct blkif_request_discard blkif_request_discard_t; - -struct blkif_request_indirect { - uint8_t operation; /* BLKIF_OP_INDIRECT */ - uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */ - uint16_t nr_segments; /* number of segments */ - uint64_t id; /* private guest value, echoed in resp */ - blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ - blkif_vdev_t handle; /* same as for read/write requests */ - grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST]; -#ifdef __i386__ - uint64_t pad; /* Make it 64 byte aligned on i386 */ -#endif -}; -typedef struct blkif_request_indirect blkif_request_indirect_t; - -struct blkif_response { - uint64_t id; /* copied from request */ - uint8_t operation; /* copied from request */ - int16_t status; /* BLKIF_RSP_??? */ -}; -typedef struct blkif_response blkif_response_t; - -/* - * STATUS RETURN CODES. - */ - /* Operation not supported (only happens on barrier writes). */ -#define BLKIF_RSP_EOPNOTSUPP -2 - /* Operation failed for some unspecified reason (-EIO). */ -#define BLKIF_RSP_ERROR -1 - /* Operation completed successfully. */ -#define BLKIF_RSP_OKAY 0 - -/* - * Generate blkif ring structures and types. - */ -DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); - -#define VDISK_CDROM 0x1 -#define VDISK_REMOVABLE 0x2 -#define VDISK_READONLY 0x4 - -#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/io/console.h b/include/xen/io/console.h deleted file mode 100644 index e2cd97f77..000000000 --- a/include/xen/io/console.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * console.h - * - * Console I/O interface for Xen guest OSes. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2005, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_IO_CONSOLE_H__ -#define __XEN_PUBLIC_IO_CONSOLE_H__ - -typedef uint32_t XENCONS_RING_IDX; - -#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1)) - -struct xencons_interface { - char in[1024]; - char out[2048]; - XENCONS_RING_IDX in_cons, in_prod; - XENCONS_RING_IDX out_cons, out_prod; -}; - -#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/io/protocols.h b/include/xen/io/protocols.h deleted file mode 100644 index 80b196bc3..000000000 --- a/include/xen/io/protocols.h +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * protocols.h - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef __XEN_PROTOCOLS_H__ -#define __XEN_PROTOCOLS_H__ - -#define XEN_IO_PROTO_ABI_X86_32 "x86_32-abi" -#define XEN_IO_PROTO_ABI_X86_64 "x86_64-abi" -#define XEN_IO_PROTO_ABI_ARM "arm-abi" - -#if defined(__i386__) -# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32 -#elif defined(__x86_64__) -# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64 -#elif defined(__arm__) || defined(__aarch64__) -# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM -#else -# error arch fixup needed here -#endif - -#endif diff --git a/include/xen/io/ring.h b/include/xen/io/ring.h deleted file mode 100644 index 73e13d7ae..000000000 --- a/include/xen/io/ring.h +++ /dev/null @@ -1,312 +0,0 @@ -/****************************************************************************** - * ring.h - * - * Shared producer-consumer ring macros. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Tim Deegan and Andrew Warfield November 2004. - */ - -#ifndef __XEN_PUBLIC_IO_RING_H__ -#define __XEN_PUBLIC_IO_RING_H__ - -#include "../xen-compat.h" - -#if __XEN_INTERFACE_VERSION__ < 0x00030208 -#define xen_mb() mb() -#define xen_rmb() rmb() -#define xen_wmb() wmb() -#endif - -typedef unsigned int RING_IDX; - -/* Round a 32-bit unsigned constant down to the nearest power of two. */ -#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1)) -#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x)) -#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x)) -#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x)) -#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x)) - -/* - * Calculate size of a shared ring, given the total available space for the - * ring and indexes (_sz), and the name tag of the request/response structure. - * A ring contains as many entries as will fit, rounded down to the nearest - * power of two (so we can mask with (size-1) to loop around). - */ -#define __CONST_RING_SIZE(_s, _sz) \ - (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \ - sizeof(((struct _s##_sring *)0)->ring[0]))) -/* - * The same for passing in an actual pointer instead of a name tag. - */ -#define __RING_SIZE(_s, _sz) \ - (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0]))) - -/* - * Macros to make the correct C datatypes for a new kind of ring. - * - * To make a new ring datatype, you need to have two message structures, - * let's say request_t, and response_t already defined. - * - * In a header where you want the ring datatype declared, you then do: - * - * DEFINE_RING_TYPES(mytag, request_t, response_t); - * - * These expand out to give you a set of types, as you can see below. - * The most important of these are: - * - * mytag_sring_t - The shared ring. - * mytag_front_ring_t - The 'front' half of the ring. - * mytag_back_ring_t - The 'back' half of the ring. - * - * To initialize a ring in your code you need to know the location and size - * of the shared memory area (PAGE_SIZE, for instance). To initialise - * the front half: - * - * mytag_front_ring_t front_ring; - * SHARED_RING_INIT((mytag_sring_t *)shared_page); - * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE); - * - * Initializing the back follows similarly (note that only the front - * initializes the shared ring): - * - * mytag_back_ring_t back_ring; - * BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE); - */ - -#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \ - \ -/* Shared ring entry */ \ -union __name##_sring_entry { \ - __req_t req; \ - __rsp_t rsp; \ -}; \ - \ -/* Shared ring page */ \ -struct __name##_sring { \ - RING_IDX req_prod, req_event; \ - RING_IDX rsp_prod, rsp_event; \ - union { \ - struct { \ - uint8_t smartpoll_active; \ - } netif; \ - struct { \ - uint8_t msg; \ - } tapif_user; \ - uint8_t pvt_pad[4]; \ - } private; \ - uint8_t __pad[44]; \ - union __name##_sring_entry ring[1]; /* variable-length */ \ -}; \ - \ -/* "Front" end's private variables */ \ -struct __name##_front_ring { \ - RING_IDX req_prod_pvt; \ - RING_IDX rsp_cons; \ - unsigned int nr_ents; \ - struct __name##_sring *sring; \ -}; \ - \ -/* "Back" end's private variables */ \ -struct __name##_back_ring { \ - RING_IDX rsp_prod_pvt; \ - RING_IDX req_cons; \ - unsigned int nr_ents; \ - struct __name##_sring *sring; \ -}; \ - \ -/* Syntactic sugar */ \ -typedef struct __name##_sring __name##_sring_t; \ -typedef struct __name##_front_ring __name##_front_ring_t; \ -typedef struct __name##_back_ring __name##_back_ring_t - -/* - * Macros for manipulating rings. - * - * FRONT_RING_whatever works on the "front end" of a ring: here - * requests are pushed on to the ring and responses taken off it. - * - * BACK_RING_whatever works on the "back end" of a ring: here - * requests are taken off the ring and responses put on. - * - * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL. - * This is OK in 1-for-1 request-response situations where the - * requestor (front end) never has more than RING_SIZE()-1 - * outstanding requests. - */ - -/* Initialising empty rings */ -#define SHARED_RING_INIT(_s) do { \ - (_s)->req_prod = (_s)->rsp_prod = 0; \ - (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ - (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ -} while(0) - -#define FRONT_RING_INIT(_r, _s, __size) do { \ - (_r)->req_prod_pvt = 0; \ - (_r)->rsp_cons = 0; \ - (_r)->nr_ents = __RING_SIZE(_s, __size); \ - (_r)->sring = (_s); \ -} while (0) - -#define BACK_RING_INIT(_r, _s, __size) do { \ - (_r)->rsp_prod_pvt = 0; \ - (_r)->req_cons = 0; \ - (_r)->nr_ents = __RING_SIZE(_s, __size); \ - (_r)->sring = (_s); \ -} while (0) - -/* How big is this ring? */ -#define RING_SIZE(_r) \ - ((_r)->nr_ents) - -/* Number of free requests (for use on front side only). */ -#define RING_FREE_REQUESTS(_r) \ - (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons)) - -/* Test if there is an empty slot available on the front ring. - * (This is only meaningful from the front. ) - */ -#define RING_FULL(_r) \ - (RING_FREE_REQUESTS(_r) == 0) - -/* Test if there are outstanding messages to be processed on a ring. */ -#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ - ((_r)->sring->rsp_prod - (_r)->rsp_cons) - -#ifdef __GNUC__ -#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \ - unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \ - unsigned int rsp = RING_SIZE(_r) - \ - ((_r)->req_cons - (_r)->rsp_prod_pvt); \ - req < rsp ? req : rsp; \ -}) -#else -/* Same as above, but without the nice GCC ({ ... }) syntax. */ -#define RING_HAS_UNCONSUMED_REQUESTS(_r) \ - ((((_r)->sring->req_prod - (_r)->req_cons) < \ - (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \ - ((_r)->sring->req_prod - (_r)->req_cons) : \ - (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) -#endif - -/* Direct access to individual ring elements, by index. */ -#define RING_GET_REQUEST(_r, _idx) \ - (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req)) - -#define RING_GET_RESPONSE(_r, _idx) \ - (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp)) - -/* Loop termination condition: Would the specified index overflow the ring? */ -#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \ - (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r)) - -/* Ill-behaved frontend determination: Can there be this many requests? */ -#define RING_REQUEST_PROD_OVERFLOW(_r, _prod) \ - (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r)) - -#define RING_PUSH_REQUESTS(_r) do { \ - xen_wmb(); /* back sees requests /before/ updated producer index */ \ - (_r)->sring->req_prod = (_r)->req_prod_pvt; \ -} while (0) - -#define RING_PUSH_RESPONSES(_r) do { \ - xen_wmb(); /* front sees resps /before/ updated producer index */ \ - (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \ -} while (0) - -/* - * Notification hold-off (req_event and rsp_event): - * - * When queueing requests or responses on a shared ring, it may not always be - * necessary to notify the remote end. For example, if requests are in flight - * in a backend, the front may be able to queue further requests without - * notifying the back (if the back checks for new requests when it queues - * responses). - * - * When enqueuing requests or responses: - * - * Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument - * is a boolean return value. True indicates that the receiver requires an - * asynchronous notification. - * - * After dequeuing requests or responses (before sleeping the connection): - * - * Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES(). - * The second argument is a boolean return value. True indicates that there - * are pending messages on the ring (i.e., the connection should not be put - * to sleep). - * - * These macros will set the req_event/rsp_event field to trigger a - * notification on the very next message that is enqueued. If you want to - * create batches of work (i.e., only receive a notification after several - * messages have been enqueued) then you will need to create a customised - * version of the FINAL_CHECK macro in your own code, which sets the event - * field appropriately. - */ - -#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \ - RING_IDX __old = (_r)->sring->req_prod; \ - RING_IDX __new = (_r)->req_prod_pvt; \ - xen_wmb(); /* back sees requests /before/ updated producer index */ \ - (_r)->sring->req_prod = __new; \ - xen_mb(); /* back sees new requests /before/ we check req_event */ \ - (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \ - (RING_IDX)(__new - __old)); \ -} while (0) - -#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \ - RING_IDX __old = (_r)->sring->rsp_prod; \ - RING_IDX __new = (_r)->rsp_prod_pvt; \ - xen_wmb(); /* front sees resps /before/ updated producer index */ \ - (_r)->sring->rsp_prod = __new; \ - xen_mb(); /* front sees new resps /before/ we check rsp_event */ \ - (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \ - (RING_IDX)(__new - __old)); \ -} while (0) - -#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \ - (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ - if (_work_to_do) break; \ - (_r)->sring->req_event = (_r)->req_cons + 1; \ - xen_mb(); \ - (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ -} while (0) - -#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \ - (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ - if (_work_to_do) break; \ - (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \ - xen_mb(); \ - (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ -} while (0) - -#endif /* __XEN_PUBLIC_IO_RING_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/io/xenbus.h b/include/xen/io/xenbus.h deleted file mode 100644 index 927f9db55..000000000 --- a/include/xen/io/xenbus.h +++ /dev/null @@ -1,80 +0,0 @@ -/***************************************************************************** - * xenbus.h - * - * Xenbus protocol details. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (C) 2005 XenSource Ltd. - */ - -#ifndef _XEN_PUBLIC_IO_XENBUS_H -#define _XEN_PUBLIC_IO_XENBUS_H - -/* - * The state of either end of the Xenbus, i.e. the current communication - * status of initialisation across the bus. States here imply nothing about - * the state of the connection between the driver and the kernel's device - * layers. - */ -enum xenbus_state { - XenbusStateUnknown = 0, - - XenbusStateInitialising = 1, - - /* - * InitWait: Finished early initialisation but waiting for information - * from the peer or hotplug scripts. - */ - XenbusStateInitWait = 2, - - /* - * Initialised: Waiting for a connection from the peer. - */ - XenbusStateInitialised = 3, - - XenbusStateConnected = 4, - - /* - * Closing: The device is being closed due to an error or an unplug event. - */ - XenbusStateClosing = 5, - - XenbusStateClosed = 6, - - /* - * Reconfiguring: The device is being reconfigured. - */ - XenbusStateReconfiguring = 7, - - XenbusStateReconfigured = 8 -}; -typedef enum xenbus_state XenbusState; - -#endif /* _XEN_PUBLIC_IO_XENBUS_H */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/io/xs_wire.h b/include/xen/io/xs_wire.h deleted file mode 100644 index 585f0c8f5..000000000 --- a/include/xen/io/xs_wire.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Details of the "wire" protocol between Xen Store Daemon and client - * library or guest kernel. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (C) 2005 Rusty Russell IBM Corporation - */ - -#ifndef _XS_WIRE_H -#define _XS_WIRE_H - -enum xsd_sockmsg_type -{ - XS_DEBUG, - XS_DIRECTORY, - XS_READ, - XS_GET_PERMS, - XS_WATCH, - XS_UNWATCH, - XS_TRANSACTION_START, - XS_TRANSACTION_END, - XS_INTRODUCE, - XS_RELEASE, - XS_GET_DOMAIN_PATH, - XS_WRITE, - XS_MKDIR, - XS_RM, - XS_SET_PERMS, - XS_WATCH_EVENT, - XS_ERROR, - XS_IS_DOMAIN_INTRODUCED, - XS_RESUME, - XS_SET_TARGET, - XS_RESTRICT, - XS_RESET_WATCHES -}; - -#define XS_WRITE_NONE "NONE" -#define XS_WRITE_CREATE "CREATE" -#define XS_WRITE_CREATE_EXCL "CREATE|EXCL" - -/* We hand errors as strings, for portability. */ -struct xsd_errors -{ - int errnum; - const char *errstring; -}; -#ifdef EINVAL -#define XSD_ERROR(x) { x, #x } -/* LINTED: static unused */ -static struct xsd_errors xsd_errors[] -#if defined(__GNUC__) -__attribute__((unused)) -#endif - = { - XSD_ERROR(EINVAL), - XSD_ERROR(EACCES), - XSD_ERROR(EEXIST), - XSD_ERROR(EISDIR), - XSD_ERROR(ENOENT), - XSD_ERROR(ENOMEM), - XSD_ERROR(ENOSPC), - XSD_ERROR(EIO), - XSD_ERROR(ENOTEMPTY), - XSD_ERROR(ENOSYS), - XSD_ERROR(EROFS), - XSD_ERROR(EBUSY), - XSD_ERROR(EAGAIN), - XSD_ERROR(EISCONN), - XSD_ERROR(E2BIG) -}; -#endif - -struct xsd_sockmsg -{ - uint32_t type; /* XS_??? */ - uint32_t req_id;/* Request identifier, echoed in daemon's response. */ - uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */ - uint32_t len; /* Length of data following this. */ - - /* Generally followed by nul-terminated string(s). */ -}; - -enum xs_watch_type -{ - XS_WATCH_PATH = 0, - XS_WATCH_TOKEN -}; - -/* - * `incontents 150 xenstore_struct XenStore wire protocol. - * - * Inter-domain shared memory communications. */ -#define XENSTORE_RING_SIZE 1024 -typedef uint32_t XENSTORE_RING_IDX; -#define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1)) -struct xenstore_domain_interface { - char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */ - char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */ - XENSTORE_RING_IDX req_cons, req_prod; - XENSTORE_RING_IDX rsp_cons, rsp_prod; -}; - -/* Violating this is very bad. See docs/misc/xenstore.txt. */ -#define XENSTORE_PAYLOAD_MAX 4096 - -/* Violating these just gets you an error back */ -#define XENSTORE_ABS_PATH_MAX 3072 -#define XENSTORE_REL_PATH_MAX 2048 - -#endif /* _XS_WIRE_H */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/memory.h b/include/xen/memory.h deleted file mode 100644 index 20deef5cb..000000000 --- a/include/xen/memory.h +++ /dev/null @@ -1,665 +0,0 @@ -/****************************************************************************** - * memory.h - * - * Memory reservation and information. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2005, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_MEMORY_H__ -#define __XEN_PUBLIC_MEMORY_H__ - -#include "xen.h" -#include "physdev.h" - -/* - * Increase or decrease the specified domain's memory reservation. Returns the - * number of extents successfully allocated or freed. - * arg == addr of struct xen_memory_reservation. - */ -#define XENMEM_increase_reservation 0 -#define XENMEM_decrease_reservation 1 -#define XENMEM_populate_physmap 6 - -#if __XEN_INTERFACE_VERSION__ >= 0x00030209 -/* - * Maximum # bits addressable by the user of the allocated region (e.g., I/O - * devices often have a 32-bit limitation even in 64-bit systems). If zero - * then the user has no addressing restriction. This field is not used by - * XENMEM_decrease_reservation. - */ -#define XENMEMF_address_bits(x) (x) -#define XENMEMF_get_address_bits(x) ((x) & 0xffu) -/* NUMA node to allocate from. */ -#define XENMEMF_node(x) (((x) + 1) << 8) -#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu) -/* Flag to populate physmap with populate-on-demand entries */ -#define XENMEMF_populate_on_demand (1<<16) -/* Flag to request allocation only from the node specified */ -#define XENMEMF_exact_node_request (1<<17) -#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request) -/* Flag to indicate the node specified is virtual node */ -#define XENMEMF_vnode (1<<18) -#endif - -struct xen_memory_reservation { - - /* - * XENMEM_increase_reservation: - * OUT: MFN (*not* GMFN) bases of extents that were allocated - * XENMEM_decrease_reservation: - * IN: GMFN bases of extents to free - * XENMEM_populate_physmap: - * IN: GPFN bases of extents to populate with memory - * OUT: GMFN bases of extents that were allocated - * (NB. This command also updates the mach_to_phys translation table) - * XENMEM_claim_pages: - * IN: must be zero - */ - XEN_GUEST_HANDLE(xen_pfn_t) extent_start; - - /* Number of extents, and size/alignment of each (2^extent_order pages). */ - xen_ulong_t nr_extents; - unsigned int extent_order; - -#if __XEN_INTERFACE_VERSION__ >= 0x00030209 - /* XENMEMF flags. */ - unsigned int mem_flags; -#else - unsigned int address_bits; -#endif - - /* - * Domain whose reservation is being changed. - * Unprivileged domains can specify only DOMID_SELF. - */ - domid_t domid; -}; -typedef struct xen_memory_reservation xen_memory_reservation_t; -DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t); - -/* - * An atomic exchange of memory pages. If return code is zero then - * @out.extent_list provides GMFNs of the newly-allocated memory. - * Returns zero on complete success, otherwise a negative error code. - * On complete success then always @nr_exchanged == @in.nr_extents. - * On partial success @nr_exchanged indicates how much work was done. - * - * Note that only PV guests can use this operation. - */ -#define XENMEM_exchange 11 -struct xen_memory_exchange { - /* - * [IN] Details of memory extents to be exchanged (GMFN bases). - * Note that @in.address_bits is ignored and unused. - */ - struct xen_memory_reservation in; - - /* - * [IN/OUT] Details of new memory extents. - * We require that: - * 1. @in.domid == @out.domid - * 2. @in.nr_extents << @in.extent_order == - * @out.nr_extents << @out.extent_order - * 3. @in.extent_start and @out.extent_start lists must not overlap - * 4. @out.extent_start lists GPFN bases to be populated - * 5. @out.extent_start is overwritten with allocated GMFN bases - */ - struct xen_memory_reservation out; - - /* - * [OUT] Number of input extents that were successfully exchanged: - * 1. The first @nr_exchanged input extents were successfully - * deallocated. - * 2. The corresponding first entries in the output extent list correctly - * indicate the GMFNs that were successfully exchanged. - * 3. All other input and output extents are untouched. - * 4. If not all input exents are exchanged then the return code of this - * command will be non-zero. - * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! - */ - xen_ulong_t nr_exchanged; -}; -typedef struct xen_memory_exchange xen_memory_exchange_t; -DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t); - -/* - * Returns the maximum machine frame number of mapped RAM in this system. - * This command always succeeds (it never returns an error code). - * arg == NULL. - */ -#define XENMEM_maximum_ram_page 2 - -/* - * Returns the current or maximum memory reservation, in pages, of the - * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. - * arg == addr of domid_t. - */ -#define XENMEM_current_reservation 3 -#define XENMEM_maximum_reservation 4 - -/* - * Returns the maximum GPFN in use by the guest, or -ve errcode on failure. - */ -#define XENMEM_maximum_gpfn 14 - -/* - * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys - * mapping table. Architectures which do not have a m2p table do not implement - * this command. - * arg == addr of xen_machphys_mfn_list_t. - */ -#define XENMEM_machphys_mfn_list 5 -struct xen_machphys_mfn_list { - /* - * Size of the 'extent_start' array. Fewer entries will be filled if the - * machphys table is smaller than max_extents * 2MB. - */ - unsigned int max_extents; - - /* - * Pointer to buffer to fill with list of extent starts. If there are - * any large discontiguities in the machine address space, 2MB gaps in - * the machphys table will be represented by an MFN base of zero. - */ - XEN_GUEST_HANDLE(xen_pfn_t) extent_start; - - /* - * Number of extents written to the above array. This will be smaller - * than 'max_extents' if the machphys table is smaller than max_e * 2MB. - */ - unsigned int nr_extents; -}; -typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t; -DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t); - -/* - * For a compat caller, this is identical to XENMEM_machphys_mfn_list. - * - * For a non compat caller, this functions similarly to - * XENMEM_machphys_mfn_list, but returns the mfns making up the compatibility - * m2p table. - */ -#define XENMEM_machphys_compat_mfn_list 25 - -/* - * Returns the location in virtual address space of the machine_to_phys - * mapping table. Architectures which do not have a m2p table, or which do not - * map it by default into guest address space, do not implement this command. - * arg == addr of xen_machphys_mapping_t. - */ -#define XENMEM_machphys_mapping 12 -struct xen_machphys_mapping { - xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ - xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ -}; -typedef struct xen_machphys_mapping xen_machphys_mapping_t; -DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); - -/* Source mapping space. */ -/* ` enum phys_map_space { */ -#define XENMAPSPACE_shared_info 0 /* shared info page */ -#define XENMAPSPACE_grant_table 1 /* grant table page */ -#define XENMAPSPACE_gmfn 2 /* GMFN */ -#define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */ -#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom, - * XENMEM_add_to_physmap_batch only. */ -#define XENMAPSPACE_dev_mmio 5 /* device mmio region - ARM only; the region is mapped in - Stage-2 using the Normal Memory - Inner/Outer Write-Back Cacheable - memory attribute. */ -/* ` } */ - -/* - * Sets the GPFN at which a particular page appears in the specified guest's - * pseudophysical address space. - * arg == addr of xen_add_to_physmap_t. - */ -#define XENMEM_add_to_physmap 7 -struct xen_add_to_physmap { - /* Which domain to change the mapping for. */ - domid_t domid; - - /* Number of pages to go through for gmfn_range */ - uint16_t size; - - unsigned int space; /* => enum phys_map_space */ - -#define XENMAPIDX_grant_table_status 0x80000000 - - /* Index into space being mapped. */ - xen_ulong_t idx; - - /* GPFN in domid where the source mapping page should appear. */ - xen_pfn_t gpfn; -}; -typedef struct xen_add_to_physmap xen_add_to_physmap_t; -DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t); - -/* A batched version of add_to_physmap. */ -#define XENMEM_add_to_physmap_batch 23 -struct xen_add_to_physmap_batch { - /* IN */ - /* Which domain to change the mapping for. */ - domid_t domid; - uint16_t space; /* => enum phys_map_space */ - - /* Number of pages to go through */ - uint16_t size; - -#if __XEN_INTERFACE_VERSION__ < 0x00040700 - domid_t foreign_domid; /* IFF gmfn_foreign. Should be 0 for other spaces. */ -#else - union xen_add_to_physmap_batch_extra { - domid_t foreign_domid; /* gmfn_foreign */ - uint16_t res0; /* All the other spaces. Should be 0 */ - } u; -#endif - - /* Indexes into space being mapped. */ - XEN_GUEST_HANDLE(xen_ulong_t) idxs; - - /* GPFN in domid where the source mapping page should appear. */ - XEN_GUEST_HANDLE(xen_pfn_t) gpfns; - - /* OUT */ - - /* Per index error code. */ - XEN_GUEST_HANDLE(int) errs; -}; -typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t; -DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_batch_t); - -#if __XEN_INTERFACE_VERSION__ < 0x00040400 -#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch -#define xen_add_to_physmap_range xen_add_to_physmap_batch -typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t; -DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t); -#endif - -/* - * Unmaps the page appearing at a particular GPFN from the specified guest's - * pseudophysical address space. - * arg == addr of xen_remove_from_physmap_t. - */ -#define XENMEM_remove_from_physmap 15 -struct xen_remove_from_physmap { - /* Which domain to change the mapping for. */ - domid_t domid; - - /* GPFN of the current mapping of the page. */ - xen_pfn_t gpfn; -}; -typedef struct xen_remove_from_physmap xen_remove_from_physmap_t; -DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t); - -/*** REMOVED ***/ -/*#define XENMEM_translate_gpfn_list 8*/ - -/* - * Returns the pseudo-physical memory map as it was when the domain - * was started (specified by XENMEM_set_memory_map). - * arg == addr of xen_memory_map_t. - */ -#define XENMEM_memory_map 9 -struct xen_memory_map { - /* - * On call the number of entries which can be stored in buffer. On - * return the number of entries which have been stored in - * buffer. - */ - unsigned int nr_entries; - - /* - * Entries in the buffer are in the same format as returned by the - * BIOS INT 0x15 EAX=0xE820 call. - */ - XEN_GUEST_HANDLE(void) buffer; -}; -typedef struct xen_memory_map xen_memory_map_t; -DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); - -/* - * Returns the real physical memory map. Passes the same structure as - * XENMEM_memory_map. - * Specifying buffer as NULL will return the number of entries required - * to store the complete memory map. - * arg == addr of xen_memory_map_t. - */ -#define XENMEM_machine_memory_map 10 - -/* - * Set the pseudo-physical memory map of a domain, as returned by - * XENMEM_memory_map. - * arg == addr of xen_foreign_memory_map_t. - */ -#define XENMEM_set_memory_map 13 -struct xen_foreign_memory_map { - domid_t domid; - struct xen_memory_map map; -}; -typedef struct xen_foreign_memory_map xen_foreign_memory_map_t; -DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t); - -#define XENMEM_set_pod_target 16 -#define XENMEM_get_pod_target 17 -struct xen_pod_target { - /* IN */ - uint64_t target_pages; - /* OUT */ - uint64_t tot_pages; - uint64_t pod_cache_pages; - uint64_t pod_entries; - /* IN */ - domid_t domid; -}; -typedef struct xen_pod_target xen_pod_target_t; - -#if defined(__XEN__) || defined(__XEN_TOOLS__) - -#ifndef uint64_aligned_t -#define uint64_aligned_t uint64_t -#endif - -/* - * Get the number of MFNs saved through memory sharing. - * The call never fails. - */ -#define XENMEM_get_sharing_freed_pages 18 -#define XENMEM_get_sharing_shared_pages 19 - -#define XENMEM_paging_op 20 -#define XENMEM_paging_op_nominate 0 -#define XENMEM_paging_op_evict 1 -#define XENMEM_paging_op_prep 2 - -struct xen_mem_paging_op { - uint8_t op; /* XENMEM_paging_op_* */ - domid_t domain; - - /* PAGING_PREP IN: buffer to immediately fill page in */ - uint64_aligned_t buffer; - /* Other OPs */ - uint64_aligned_t gfn; /* IN: gfn of page being operated on */ -}; -typedef struct xen_mem_paging_op xen_mem_paging_op_t; -DEFINE_XEN_GUEST_HANDLE(xen_mem_paging_op_t); - -#define XENMEM_access_op 21 -#define XENMEM_access_op_set_access 0 -#define XENMEM_access_op_get_access 1 -/* - * XENMEM_access_op_enable_emulate and XENMEM_access_op_disable_emulate are - * currently unused, but since they have been in use please do not reuse them. - * - * #define XENMEM_access_op_enable_emulate 2 - * #define XENMEM_access_op_disable_emulate 3 - */ -#define XENMEM_access_op_set_access_multi 4 - -typedef enum { - XENMEM_access_n, - XENMEM_access_r, - XENMEM_access_w, - XENMEM_access_rw, - XENMEM_access_x, - XENMEM_access_rx, - XENMEM_access_wx, - XENMEM_access_rwx, - /* - * Page starts off as r-x, but automatically - * change to r-w on a write - */ - XENMEM_access_rx2rw, - /* - * Log access: starts off as n, automatically - * goes to rwx, generating an event without - * pausing the vcpu - */ - XENMEM_access_n2rwx, - /* Take the domain default */ - XENMEM_access_default -} xenmem_access_t; - -struct xen_mem_access_op { - /* XENMEM_access_op_* */ - uint8_t op; - /* xenmem_access_t */ - uint8_t access; - domid_t domid; - /* - * Number of pages for set op (or size of pfn_list for - * XENMEM_access_op_set_access_multi) - * Ignored on setting default access and other ops - */ - uint32_t nr; - /* - * First pfn for set op - * pfn for get op - * ~0ull is used to set and get the default access for pages - */ - uint64_aligned_t pfn; - /* - * List of pfns to set access for - * Used only with XENMEM_access_op_set_access_multi - */ - XEN_GUEST_HANDLE(const_uint64) pfn_list; - /* - * Corresponding list of access settings for pfn_list - * Used only with XENMEM_access_op_set_access_multi - */ - XEN_GUEST_HANDLE(const_uint8) access_list; -}; -typedef struct xen_mem_access_op xen_mem_access_op_t; -DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t); - -#define XENMEM_sharing_op 22 -#define XENMEM_sharing_op_nominate_gfn 0 -#define XENMEM_sharing_op_nominate_gref 1 -#define XENMEM_sharing_op_share 2 -#define XENMEM_sharing_op_debug_gfn 3 -#define XENMEM_sharing_op_debug_mfn 4 -#define XENMEM_sharing_op_debug_gref 5 -#define XENMEM_sharing_op_add_physmap 6 -#define XENMEM_sharing_op_audit 7 -#define XENMEM_sharing_op_range_share 8 - -#define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10) -#define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9) - -/* The following allows sharing of grant refs. This is useful - * for sharing utilities sitting as "filters" in IO backends - * (e.g. memshr + blktap(2)). The IO backend is only exposed - * to grant references, and this allows sharing of the grefs */ -#define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG (xen_mk_ullong(1) << 62) - -#define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val) \ - (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val) -#define XENMEM_SHARING_OP_FIELD_IS_GREF(field) \ - ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG) -#define XENMEM_SHARING_OP_FIELD_GET_GREF(field) \ - ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)) - -struct xen_mem_sharing_op { - uint8_t op; /* XENMEM_sharing_op_* */ - domid_t domain; - - union { - struct mem_sharing_op_nominate { /* OP_NOMINATE_xxx */ - union { - uint64_aligned_t gfn; /* IN: gfn to nominate */ - uint32_t grant_ref; /* IN: grant ref to nominate */ - } u; - uint64_aligned_t handle; /* OUT: the handle */ - } nominate; - struct mem_sharing_op_share { /* OP_SHARE/ADD_PHYSMAP */ - uint64_aligned_t source_gfn; /* IN: the gfn of the source page */ - uint64_aligned_t source_handle; /* IN: handle to the source page */ - uint64_aligned_t client_gfn; /* IN: the client gfn */ - uint64_aligned_t client_handle; /* IN: handle to the client page */ - domid_t client_domain; /* IN: the client domain id */ - } share; - struct mem_sharing_op_range { /* OP_RANGE_SHARE */ - uint64_aligned_t first_gfn; /* IN: the first gfn */ - uint64_aligned_t last_gfn; /* IN: the last gfn */ - uint64_aligned_t opaque; /* Must be set to 0 */ - domid_t client_domain; /* IN: the client domain id */ - uint16_t _pad[3]; /* Must be set to 0 */ - } range; - struct mem_sharing_op_debug { /* OP_DEBUG_xxx */ - union { - uint64_aligned_t gfn; /* IN: gfn to debug */ - uint64_aligned_t mfn; /* IN: mfn to debug */ - uint32_t gref; /* IN: gref to debug */ - } u; - } debug; - } u; -}; -typedef struct xen_mem_sharing_op xen_mem_sharing_op_t; -DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t); - -/* - * Attempt to stake a claim for a domain on a quantity of pages - * of system RAM, but _not_ assign specific pageframes. Only - * arithmetic is performed so the hypercall is very fast and need - * not be preemptible, thus sidestepping time-of-check-time-of-use - * races for memory allocation. Returns 0 if the hypervisor page - * allocator has atomically and successfully claimed the requested - * number of pages, else non-zero. - * - * Any domain may have only one active claim. When sufficient memory - * has been allocated to resolve the claim, the claim silently expires. - * Claiming zero pages effectively resets any outstanding claim and - * is always successful. - * - * Note that a valid claim may be staked even after memory has been - * allocated for a domain. In this case, the claim is not incremental, - * i.e. if the domain's tot_pages is 3, and a claim is staked for 10, - * only 7 additional pages are claimed. - * - * Caller must be privileged or the hypercall fails. - */ -#define XENMEM_claim_pages 24 - -/* - * XENMEM_claim_pages flags - the are no flags at this time. - * The zero value is appropriate. - */ - -/* - * With some legacy devices, certain guest-physical addresses cannot safely - * be used for other purposes, e.g. to map guest RAM. This hypercall - * enumerates those regions so the toolstack can avoid using them. - */ -#define XENMEM_reserved_device_memory_map 27 -struct xen_reserved_device_memory { - xen_pfn_t start_pfn; - xen_ulong_t nr_pages; -}; -typedef struct xen_reserved_device_memory xen_reserved_device_memory_t; -DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_t); - -struct xen_reserved_device_memory_map { -#define XENMEM_RDM_ALL 1 /* Request all regions (ignore dev union). */ - /* IN */ - uint32_t flags; - /* - * IN/OUT - * - * Gets set to the required number of entries when too low, - * signaled by error code -ERANGE. - */ - unsigned int nr_entries; - /* OUT */ - XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer; - /* IN */ - union { - struct physdev_pci_device pci; - } dev; -}; -typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t; -DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_map_t); - -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ - -/* - * XENMEM_get_vnumainfo used by guest to get - * vNUMA topology from hypervisor. - */ -#define XENMEM_get_vnumainfo 26 - -/* vNUMA node memory ranges */ -struct xen_vmemrange { - uint64_t start, end; - unsigned int flags; - unsigned int nid; -}; -typedef struct xen_vmemrange xen_vmemrange_t; -DEFINE_XEN_GUEST_HANDLE(xen_vmemrange_t); - -/* - * vNUMA topology specifies vNUMA node number, distance table, - * memory ranges and vcpu mapping provided for guests. - * XENMEM_get_vnumainfo hypercall expects to see from guest - * nr_vnodes, nr_vmemranges and nr_vcpus to indicate available memory. - * After filling guests structures, nr_vnodes, nr_vmemranges and nr_vcpus - * copied back to guest. Domain returns expected values of nr_vnodes, - * nr_vmemranges and nr_vcpus to guest if the values where incorrect. - */ -struct xen_vnuma_topology_info { - /* IN */ - domid_t domid; - uint16_t pad; - /* IN/OUT */ - unsigned int nr_vnodes; - unsigned int nr_vcpus; - unsigned int nr_vmemranges; - /* OUT */ - union { - XEN_GUEST_HANDLE(uint) h; - uint64_t pad; - } vdistance; - union { - XEN_GUEST_HANDLE(uint) h; - uint64_t pad; - } vcpu_to_vnode; - union { - XEN_GUEST_HANDLE(xen_vmemrange_t) h; - uint64_t pad; - } vmemrange; -}; -typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t; -DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t); - -/* Next available subop number is 28 */ - -#endif /* __XEN_PUBLIC_MEMORY_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/physdev.h b/include/xen/physdev.h deleted file mode 100644 index b6faf8350..000000000 --- a/include/xen/physdev.h +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2006, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_PHYSDEV_H__ -#define __XEN_PUBLIC_PHYSDEV_H__ - -#include "xen.h" - -/* - * Prototype for this hypercall is: - * int physdev_op(int cmd, void *args) - * @cmd == PHYSDEVOP_??? (physdev operation). - * @args == Operation-specific extra arguments (NULL if none). - */ - -/* - * Notify end-of-interrupt (EOI) for the specified IRQ. - * @arg == pointer to physdev_eoi structure. - */ -#define PHYSDEVOP_eoi 12 -struct physdev_eoi { - /* IN */ - uint32_t irq; -}; -typedef struct physdev_eoi physdev_eoi_t; -DEFINE_XEN_GUEST_HANDLE(physdev_eoi_t); - -/* - * Register a shared page for the hypervisor to indicate whether the guest - * must issue PHYSDEVOP_eoi. The semantics of PHYSDEVOP_eoi change slightly - * once the guest used this function in that the associated event channel - * will automatically get unmasked. The page registered is used as a bit - * array indexed by Xen's PIRQ value. - */ -#define PHYSDEVOP_pirq_eoi_gmfn_v1 17 -/* - * Register a shared page for the hypervisor to indicate whether the - * guest must issue PHYSDEVOP_eoi. This hypercall is very similar to - * PHYSDEVOP_pirq_eoi_gmfn_v1 but it doesn't change the semantics of - * PHYSDEVOP_eoi. The page registered is used as a bit array indexed by - * Xen's PIRQ value. - */ -#define PHYSDEVOP_pirq_eoi_gmfn_v2 28 -struct physdev_pirq_eoi_gmfn { - /* IN */ - xen_pfn_t gmfn; -}; -typedef struct physdev_pirq_eoi_gmfn physdev_pirq_eoi_gmfn_t; -DEFINE_XEN_GUEST_HANDLE(physdev_pirq_eoi_gmfn_t); - -/* - * Query the status of an IRQ line. - * @arg == pointer to physdev_irq_status_query structure. - */ -#define PHYSDEVOP_irq_status_query 5 -struct physdev_irq_status_query { - /* IN */ - uint32_t irq; - /* OUT */ - uint32_t flags; /* XENIRQSTAT_* */ -}; -typedef struct physdev_irq_status_query physdev_irq_status_query_t; -DEFINE_XEN_GUEST_HANDLE(physdev_irq_status_query_t); - -/* Need to call PHYSDEVOP_eoi when the IRQ has been serviced? */ -#define _XENIRQSTAT_needs_eoi (0) -#define XENIRQSTAT_needs_eoi (1U<<_XENIRQSTAT_needs_eoi) - -/* IRQ shared by multiple guests? */ -#define _XENIRQSTAT_shared (1) -#define XENIRQSTAT_shared (1U<<_XENIRQSTAT_shared) - -/* - * Set the current VCPU's I/O privilege level. - * @arg == pointer to physdev_set_iopl structure. - */ -#define PHYSDEVOP_set_iopl 6 -struct physdev_set_iopl { - /* IN */ - uint32_t iopl; -}; -typedef struct physdev_set_iopl physdev_set_iopl_t; -DEFINE_XEN_GUEST_HANDLE(physdev_set_iopl_t); - -/* - * Set the current VCPU's I/O-port permissions bitmap. - * @arg == pointer to physdev_set_iobitmap structure. - */ -#define PHYSDEVOP_set_iobitmap 7 -struct physdev_set_iobitmap { - /* IN */ -#if __XEN_INTERFACE_VERSION__ >= 0x00030205 - XEN_GUEST_HANDLE(uint8) bitmap; -#else - uint8_t *bitmap; -#endif - uint32_t nr_ports; -}; -typedef struct physdev_set_iobitmap physdev_set_iobitmap_t; -DEFINE_XEN_GUEST_HANDLE(physdev_set_iobitmap_t); - -/* - * Read or write an IO-APIC register. - * @arg == pointer to physdev_apic structure. - */ -#define PHYSDEVOP_apic_read 8 -#define PHYSDEVOP_apic_write 9 -struct physdev_apic { - /* IN */ - unsigned long apic_physbase; - uint32_t reg; - /* IN or OUT */ - uint32_t value; -}; -typedef struct physdev_apic physdev_apic_t; -DEFINE_XEN_GUEST_HANDLE(physdev_apic_t); - -/* - * Allocate or free a physical upcall vector for the specified IRQ line. - * @arg == pointer to physdev_irq structure. - */ -#define PHYSDEVOP_alloc_irq_vector 10 -#define PHYSDEVOP_free_irq_vector 11 -struct physdev_irq { - /* IN */ - uint32_t irq; - /* IN or OUT */ - uint32_t vector; -}; -typedef struct physdev_irq physdev_irq_t; -DEFINE_XEN_GUEST_HANDLE(physdev_irq_t); - -#define MAP_PIRQ_TYPE_MSI 0x0 -#define MAP_PIRQ_TYPE_GSI 0x1 -#define MAP_PIRQ_TYPE_UNKNOWN 0x2 -#define MAP_PIRQ_TYPE_MSI_SEG 0x3 -#define MAP_PIRQ_TYPE_MULTI_MSI 0x4 - -#define PHYSDEVOP_map_pirq 13 -struct physdev_map_pirq { - domid_t domid; - /* IN */ - int type; - /* IN (ignored for ..._MULTI_MSI) */ - int index; - /* IN or OUT */ - int pirq; - /* IN - high 16 bits hold segment for ..._MSI_SEG and ..._MULTI_MSI */ - int bus; - /* IN */ - int devfn; - /* IN (also OUT for ..._MULTI_MSI) */ - int entry_nr; - /* IN */ - uint64_t table_base; -}; -typedef struct physdev_map_pirq physdev_map_pirq_t; -DEFINE_XEN_GUEST_HANDLE(physdev_map_pirq_t); - -#define PHYSDEVOP_unmap_pirq 14 -struct physdev_unmap_pirq { - domid_t domid; - /* IN */ - int pirq; -}; - -typedef struct physdev_unmap_pirq physdev_unmap_pirq_t; -DEFINE_XEN_GUEST_HANDLE(physdev_unmap_pirq_t); - -#define PHYSDEVOP_manage_pci_add 15 -#define PHYSDEVOP_manage_pci_remove 16 -struct physdev_manage_pci { - /* IN */ - uint8_t bus; - uint8_t devfn; -}; - -typedef struct physdev_manage_pci physdev_manage_pci_t; -DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_t); - -#define PHYSDEVOP_restore_msi 19 -struct physdev_restore_msi { - /* IN */ - uint8_t bus; - uint8_t devfn; -}; -typedef struct physdev_restore_msi physdev_restore_msi_t; -DEFINE_XEN_GUEST_HANDLE(physdev_restore_msi_t); - -#define PHYSDEVOP_manage_pci_add_ext 20 -struct physdev_manage_pci_ext { - /* IN */ - uint8_t bus; - uint8_t devfn; - unsigned is_extfn; - unsigned is_virtfn; - struct { - uint8_t bus; - uint8_t devfn; - } physfn; -}; - -typedef struct physdev_manage_pci_ext physdev_manage_pci_ext_t; -DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_ext_t); - -/* - * Argument to physdev_op_compat() hypercall. Superceded by new physdev_op() - * hypercall since 0x00030202. - */ -struct physdev_op { - uint32_t cmd; - union { - struct physdev_irq_status_query irq_status_query; - struct physdev_set_iopl set_iopl; - struct physdev_set_iobitmap set_iobitmap; - struct physdev_apic apic_op; - struct physdev_irq irq_op; - } u; -}; -typedef struct physdev_op physdev_op_t; -DEFINE_XEN_GUEST_HANDLE(physdev_op_t); - -#define PHYSDEVOP_setup_gsi 21 -struct physdev_setup_gsi { - int gsi; - /* IN */ - uint8_t triggering; - /* IN */ - uint8_t polarity; - /* IN */ -}; - -typedef struct physdev_setup_gsi physdev_setup_gsi_t; -DEFINE_XEN_GUEST_HANDLE(physdev_setup_gsi_t); - -/* leave PHYSDEVOP 22 free */ - -/* type is MAP_PIRQ_TYPE_GSI or MAP_PIRQ_TYPE_MSI - * the hypercall returns a free pirq */ -#define PHYSDEVOP_get_free_pirq 23 -struct physdev_get_free_pirq { - /* IN */ - int type; - /* OUT */ - uint32_t pirq; -}; - -typedef struct physdev_get_free_pirq physdev_get_free_pirq_t; -DEFINE_XEN_GUEST_HANDLE(physdev_get_free_pirq_t); - -#define XEN_PCI_MMCFG_RESERVED 0x1 - -#define PHYSDEVOP_pci_mmcfg_reserved 24 -struct physdev_pci_mmcfg_reserved { - uint64_t address; - uint16_t segment; - uint8_t start_bus; - uint8_t end_bus; - uint32_t flags; -}; -typedef struct physdev_pci_mmcfg_reserved physdev_pci_mmcfg_reserved_t; -DEFINE_XEN_GUEST_HANDLE(physdev_pci_mmcfg_reserved_t); - -#define XEN_PCI_DEV_EXTFN 0x1 -#define XEN_PCI_DEV_VIRTFN 0x2 -#define XEN_PCI_DEV_PXM 0x4 - -#define PHYSDEVOP_pci_device_add 25 -struct physdev_pci_device_add { - /* IN */ - uint16_t seg; - uint8_t bus; - uint8_t devfn; - uint32_t flags; - struct { - uint8_t bus; - uint8_t devfn; - } physfn; - /* - * Optional parameters array. - * First element ([0]) is PXM domain associated with the device (if - * XEN_PCI_DEV_PXM is set) - */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - uint32_t optarr[]; -#elif defined(__GNUC__) - uint32_t optarr[0]; -#endif -}; -typedef struct physdev_pci_device_add physdev_pci_device_add_t; -DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_add_t); - -#define PHYSDEVOP_pci_device_remove 26 -#define PHYSDEVOP_restore_msi_ext 27 -/* - * Dom0 should use these two to announce MMIO resources assigned to - * MSI-X capable devices won't (prepare) or may (release) change. - */ -#define PHYSDEVOP_prepare_msix 30 -#define PHYSDEVOP_release_msix 31 -struct physdev_pci_device { - /* IN */ - uint16_t seg; - uint8_t bus; - uint8_t devfn; -}; -typedef struct physdev_pci_device physdev_pci_device_t; -DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_t); - -#define PHYSDEVOP_DBGP_RESET_PREPARE 1 -#define PHYSDEVOP_DBGP_RESET_DONE 2 - -#define PHYSDEVOP_DBGP_BUS_UNKNOWN 0 -#define PHYSDEVOP_DBGP_BUS_PCI 1 - -#define PHYSDEVOP_dbgp_op 29 -struct physdev_dbgp_op { - /* IN */ - uint8_t op; - uint8_t bus; - union { - struct physdev_pci_device pci; - } u; -}; -typedef struct physdev_dbgp_op physdev_dbgp_op_t; -DEFINE_XEN_GUEST_HANDLE(physdev_dbgp_op_t); - -/* - * Notify that some PIRQ-bound event channels have been unmasked. - * ** This command is obsolete since interface version 0x00030202 and is ** - * ** unsupported by newer versions of Xen. ** - */ -#define PHYSDEVOP_IRQ_UNMASK_NOTIFY 4 - -#if __XEN_INTERFACE_VERSION__ < 0x00040600 -/* - * These all-capitals physdev operation names are superceded by the new names - * (defined above) since interface version 0x00030202. The guard above was - * added post-4.5 only though and hence shouldn't check for 0x00030202. - */ -#define PHYSDEVOP_IRQ_STATUS_QUERY PHYSDEVOP_irq_status_query -#define PHYSDEVOP_SET_IOPL PHYSDEVOP_set_iopl -#define PHYSDEVOP_SET_IOBITMAP PHYSDEVOP_set_iobitmap -#define PHYSDEVOP_APIC_READ PHYSDEVOP_apic_read -#define PHYSDEVOP_APIC_WRITE PHYSDEVOP_apic_write -#define PHYSDEVOP_ASSIGN_VECTOR PHYSDEVOP_alloc_irq_vector -#define PHYSDEVOP_FREE_VECTOR PHYSDEVOP_free_irq_vector -#define PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY XENIRQSTAT_needs_eoi -#define PHYSDEVOP_IRQ_SHARED XENIRQSTAT_shared -#endif - -#if __XEN_INTERFACE_VERSION__ < 0x00040200 -#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v1 -#else -#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v2 -#endif - -#endif /* __XEN_PUBLIC_PHYSDEV_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/sched.h b/include/xen/sched.h deleted file mode 100644 index a30b11d96..000000000 --- a/include/xen/sched.h +++ /dev/null @@ -1,174 +0,0 @@ -/****************************************************************************** - * sched.h - * - * Scheduler state interactions - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2005, Keir Fraser - */ - -#ifndef __XEN_PUBLIC_SCHED_H__ -#define __XEN_PUBLIC_SCHED_H__ - -#include "event_channel.h" - -/* - * `incontents 150 sched Guest Scheduler Operations - * - * The SCHEDOP interface provides mechanisms for a guest to interact - * with the scheduler, including yield, blocking and shutting itself - * down. - */ - -/* - * The prototype for this hypercall is: - * ` long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...) - * - * @cmd == SCHEDOP_??? (scheduler operation). - * @arg == Operation-specific extra argument(s), as described below. - * ... == Additional Operation-specific extra arguments, described below. - * - * Versions of Xen prior to 3.0.2 provided only the following legacy version - * of this hypercall, supporting only the commands yield, block and shutdown: - * long sched_op(int cmd, unsigned long arg) - * @cmd == SCHEDOP_??? (scheduler operation). - * @arg == 0 (SCHEDOP_yield and SCHEDOP_block) - * == SHUTDOWN_* code (SCHEDOP_shutdown) - * - * This legacy version is available to new guests as: - * ` long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg) - */ - -/* ` enum sched_op { // SCHEDOP_* => struct sched_* */ -/* - * Voluntarily yield the CPU. - * @arg == NULL. - */ -#define SCHEDOP_yield 0 - -/* - * Block execution of this VCPU until an event is received for processing. - * If called with event upcalls masked, this operation will atomically - * reenable event delivery and check for pending events before blocking the - * VCPU. This avoids a "wakeup waiting" race. - * @arg == NULL. - */ -#define SCHEDOP_block 1 - -/* - * Halt execution of this domain (all VCPUs) and notify the system controller. - * @arg == pointer to sched_shutdown_t structure. - * - * If the sched_shutdown_t reason is SHUTDOWN_suspend then this - * hypercall takes an additional extra argument which should be the - * MFN of the guest's start_info_t. - * - * In addition, which reason is SHUTDOWN_suspend this hypercall - * returns 1 if suspend was cancelled or the domain was merely - * checkpointed, and 0 if it is resuming in a new domain. - */ -#define SCHEDOP_shutdown 2 - -/* - * Poll a set of event-channel ports. Return when one or more are pending. An - * optional timeout may be specified. - * @arg == pointer to sched_poll_t structure. - */ -#define SCHEDOP_poll 3 - -/* - * Declare a shutdown for another domain. The main use of this function is - * in interpreting shutdown requests and reasons for fully-virtualized - * domains. A para-virtualized domain may use SCHEDOP_shutdown directly. - * @arg == pointer to sched_remote_shutdown_t structure. - */ -#define SCHEDOP_remote_shutdown 4 - -/* - * Latch a shutdown code, so that when the domain later shuts down it - * reports this code to the control tools. - * @arg == sched_shutdown_t, as for SCHEDOP_shutdown. - */ -#define SCHEDOP_shutdown_code 5 - -/* - * Setup, poke and destroy a domain watchdog timer. - * @arg == pointer to sched_watchdog_t structure. - * With id == 0, setup a domain watchdog timer to cause domain shutdown - * after timeout, returns watchdog id. - * With id != 0 and timeout == 0, destroy domain watchdog timer. - * With id != 0 and timeout != 0, poke watchdog timer and set new timeout. - */ -#define SCHEDOP_watchdog 6 -/* ` } */ - -struct sched_shutdown { - unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ -}; -typedef struct sched_shutdown sched_shutdown_t; -DEFINE_XEN_GUEST_HANDLE(sched_shutdown_t); - -struct sched_poll { - XEN_GUEST_HANDLE(evtchn_port_t) ports; - unsigned int nr_ports; - uint64_t timeout; -}; -typedef struct sched_poll sched_poll_t; -DEFINE_XEN_GUEST_HANDLE(sched_poll_t); - -struct sched_remote_shutdown { - domid_t domain_id; /* Remote domain ID */ - unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ -}; -typedef struct sched_remote_shutdown sched_remote_shutdown_t; -DEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t); - -struct sched_watchdog { - uint32_t id; /* watchdog ID */ - uint32_t timeout; /* timeout */ -}; -typedef struct sched_watchdog sched_watchdog_t; -DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t); - -/* - * Reason codes for SCHEDOP_shutdown. These may be interpreted by control - * software to determine the appropriate action. For the most part, Xen does - * not care about the shutdown code. - */ -/* ` enum sched_shutdown_reason { */ -#define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ -#define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ -#define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ -#define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ -#define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. */ -#define SHUTDOWN_MAX 4 /* Maximum valid shutdown reason. */ -/* ` } */ - -#endif /* __XEN_PUBLIC_SCHED_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/trace.h b/include/xen/trace.h deleted file mode 100644 index a00c01733..000000000 --- a/include/xen/trace.h +++ /dev/null @@ -1,339 +0,0 @@ -/****************************************************************************** - * include/public/trace.h - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Mark Williamson, (C) 2004 Intel Research Cambridge - * Copyright (C) 2005 Bin Ren - */ - -#ifndef __XEN_PUBLIC_TRACE_H__ -#define __XEN_PUBLIC_TRACE_H__ - -#define TRACE_EXTRA_MAX 7 -#define TRACE_EXTRA_SHIFT 28 - -/* Trace classes */ -#define TRC_CLS_SHIFT 16 -#define TRC_GEN 0x0001f000 /* General trace */ -#define TRC_SCHED 0x0002f000 /* Xen Scheduler trace */ -#define TRC_DOM0OP 0x0004f000 /* Xen DOM0 operation trace */ -#define TRC_HVM 0x0008f000 /* Xen HVM trace */ -#define TRC_MEM 0x0010f000 /* Xen memory trace */ -#define TRC_PV 0x0020f000 /* Xen PV traces */ -#define TRC_SHADOW 0x0040f000 /* Xen shadow tracing */ -#define TRC_HW 0x0080f000 /* Xen hardware-related traces */ -#define TRC_GUEST 0x0800f000 /* Guest-generated traces */ -#define TRC_ALL 0x0ffff000 -#define TRC_HD_TO_EVENT(x) ((x)&0x0fffffff) -#define TRC_HD_CYCLE_FLAG (1UL<<31) -#define TRC_HD_INCLUDES_CYCLE_COUNT(x) ( !!( (x) & TRC_HD_CYCLE_FLAG ) ) -#define TRC_HD_EXTRA(x) (((x)>>TRACE_EXTRA_SHIFT)&TRACE_EXTRA_MAX) - -/* Trace subclasses */ -#define TRC_SUBCLS_SHIFT 12 - -/* trace subclasses for SVM */ -#define TRC_HVM_ENTRYEXIT 0x00081000 /* VMENTRY and #VMEXIT */ -#define TRC_HVM_HANDLER 0x00082000 /* various HVM handlers */ -#define TRC_HVM_EMUL 0x00084000 /* emulated devices */ - -#define TRC_SCHED_MIN 0x00021000 /* Just runstate changes */ -#define TRC_SCHED_CLASS 0x00022000 /* Scheduler-specific */ -#define TRC_SCHED_VERBOSE 0x00028000 /* More inclusive scheduling */ - -/* - * The highest 3 bits of the last 12 bits of TRC_SCHED_CLASS above are - * reserved for encoding what scheduler produced the information. The - * actual event is encoded in the last 9 bits. - * - * This means we have 8 scheduling IDs available (which means at most 8 - * schedulers generating events) and, in each scheduler, up to 512 - * different events. - */ -#define TRC_SCHED_ID_BITS 3 -#define TRC_SCHED_ID_SHIFT (TRC_SUBCLS_SHIFT - TRC_SCHED_ID_BITS) -#define TRC_SCHED_ID_MASK (((1UL<cpu_offset[cpu]). - */ -struct t_info { - uint16_t tbuf_size; /* Size in pages of each trace buffer */ - uint16_t mfn_offset[]; /* Offset within t_info structure of the page list per cpu */ - /* MFN lists immediately after the header */ -}; - -#endif /* __XEN_PUBLIC_TRACE_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xen/xen-compat.h b/include/xen/xen-compat.h deleted file mode 100644 index 3eb80a02d..000000000 --- a/include/xen/xen-compat.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * xen-compat.h - * - * Guest OS interface to Xen. Compatibility layer. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2006, Christian Limpach - */ - -#ifndef __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_PUBLIC_XEN_COMPAT_H__ - -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040400 - -#if defined(__XEN__) || defined(__XEN_TOOLS__) -/* Xen is built with matching headers and implements the latest interface. */ -#define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__ -#elif !defined(__XEN_INTERFACE_VERSION__) -/* Guests which do not specify a version get the legacy interface. */ -#define __XEN_INTERFACE_VERSION__ 0x00000000 -#endif - -#if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__ -#error "These header files do not support the requested interface version." -#endif - -#endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */ diff --git a/include/xen/xen.h b/include/xen/xen.h deleted file mode 100644 index 308109f17..000000000 --- a/include/xen/xen.h +++ /dev/null @@ -1,998 +0,0 @@ -/****************************************************************************** - * xen.h - * - * Guest OS interface to Xen. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Copyright (c) 2004, K A Fraser - */ - -#ifndef __XEN_PUBLIC_XEN_H__ -#define __XEN_PUBLIC_XEN_H__ - -#include "xen-compat.h" - -#if defined(__i386__) || defined(__x86_64__) -#include "arch-x86/xen.h" -#elif defined(__arm__) || defined (__aarch64__) -#include "arch-arm.h" -#else -#error "Unsupported architecture" -#endif - -#ifndef __ASSEMBLY__ -/* Guest handles for primitive C types. */ -DEFINE_XEN_GUEST_HANDLE(char); -__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char); -DEFINE_XEN_GUEST_HANDLE(int); -__DEFINE_XEN_GUEST_HANDLE(uint, unsigned int); -#if __XEN_INTERFACE_VERSION__ < 0x00040300 -DEFINE_XEN_GUEST_HANDLE(long); -__DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long); -#endif -DEFINE_XEN_GUEST_HANDLE(void); - -DEFINE_XEN_GUEST_HANDLE(uint64_t); -DEFINE_XEN_GUEST_HANDLE(xen_pfn_t); -DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); - -/* Turn a plain number into a C unsigned (long (long)) constant. */ -#define __xen_mk_uint(x) x ## U -#define __xen_mk_ulong(x) x ## UL -#ifndef __xen_mk_ullong -# define __xen_mk_ullong(x) x ## ULL -#endif -#define xen_mk_uint(x) __xen_mk_uint(x) -#define xen_mk_ulong(x) __xen_mk_ulong(x) -#define xen_mk_ullong(x) __xen_mk_ullong(x) - -#else - -/* In assembly code we cannot use C numeric constant suffixes. */ -#define xen_mk_uint(x) x -#define xen_mk_ulong(x) x -#define xen_mk_ullong(x) x - -#endif - -/* - * HYPERCALLS - */ - -/* `incontents 100 hcalls List of hypercalls - * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*() - */ - -#define __HYPERVISOR_set_trap_table 0 -#define __HYPERVISOR_mmu_update 1 -#define __HYPERVISOR_set_gdt 2 -#define __HYPERVISOR_stack_switch 3 -#define __HYPERVISOR_set_callbacks 4 -#define __HYPERVISOR_fpu_taskswitch 5 -#define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */ -#define __HYPERVISOR_platform_op 7 -#define __HYPERVISOR_set_debugreg 8 -#define __HYPERVISOR_get_debugreg 9 -#define __HYPERVISOR_update_descriptor 10 -#define __HYPERVISOR_memory_op 12 -#define __HYPERVISOR_multicall 13 -#define __HYPERVISOR_update_va_mapping 14 -#define __HYPERVISOR_set_timer_op 15 -#define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */ -#define __HYPERVISOR_xen_version 17 -#define __HYPERVISOR_console_io 18 -#define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */ -#define __HYPERVISOR_grant_table_op 20 -#define __HYPERVISOR_vm_assist 21 -#define __HYPERVISOR_update_va_mapping_otherdomain 22 -#define __HYPERVISOR_iret 23 /* x86 only */ -#define __HYPERVISOR_vcpu_op 24 -#define __HYPERVISOR_set_segment_base 25 /* x86/64 only */ -#define __HYPERVISOR_mmuext_op 26 -#define __HYPERVISOR_xsm_op 27 -#define __HYPERVISOR_nmi_op 28 -#define __HYPERVISOR_sched_op 29 -#define __HYPERVISOR_callback_op 30 -#define __HYPERVISOR_xenoprof_op 31 -#define __HYPERVISOR_event_channel_op 32 -#define __HYPERVISOR_physdev_op 33 -#define __HYPERVISOR_hvm_op 34 -#define __HYPERVISOR_sysctl 35 -#define __HYPERVISOR_domctl 36 -#define __HYPERVISOR_kexec_op 37 -#define __HYPERVISOR_tmem_op 38 -#define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */ -#define __HYPERVISOR_xenpmu_op 40 -#define __HYPERVISOR_dm_op 41 - -/* Architecture-specific hypercall definitions. */ -#define __HYPERVISOR_arch_0 48 -#define __HYPERVISOR_arch_1 49 -#define __HYPERVISOR_arch_2 50 -#define __HYPERVISOR_arch_3 51 -#define __HYPERVISOR_arch_4 52 -#define __HYPERVISOR_arch_5 53 -#define __HYPERVISOR_arch_6 54 -#define __HYPERVISOR_arch_7 55 - -/* ` } */ - -/* - * HYPERCALL COMPATIBILITY. - */ - -/* New sched_op hypercall introduced in 0x00030101. */ -#if __XEN_INTERFACE_VERSION__ < 0x00030101 -#undef __HYPERVISOR_sched_op -#define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat -#endif - -/* New event-channel and physdev hypercalls introduced in 0x00030202. */ -#if __XEN_INTERFACE_VERSION__ < 0x00030202 -#undef __HYPERVISOR_event_channel_op -#define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat -#undef __HYPERVISOR_physdev_op -#define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat -#endif - -/* New platform_op hypercall introduced in 0x00030204. */ -#if __XEN_INTERFACE_VERSION__ < 0x00030204 -#define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op -#endif - -/* - * VIRTUAL INTERRUPTS - * - * Virtual interrupts that a guest OS may receive from Xen. - * - * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a - * global VIRQ. The former can be bound once per VCPU and cannot be re-bound. - * The latter can be allocated only once per guest: they must initially be - * allocated to VCPU0 but can subsequently be re-bound. - */ -/* ` enum virq { */ -#define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */ -#define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */ -#define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */ -#define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */ -#define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */ -#define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */ -#define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */ -#define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */ -#define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */ -#define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */ -#define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient */ -#define VIRQ_ENOMEM 12 /* G. (DOM0) Low on heap memory */ -#define VIRQ_XENPMU 13 /* V. PMC interrupt */ - -/* Architecture-specific VIRQ definitions. */ -#define VIRQ_ARCH_0 16 -#define VIRQ_ARCH_1 17 -#define VIRQ_ARCH_2 18 -#define VIRQ_ARCH_3 19 -#define VIRQ_ARCH_4 20 -#define VIRQ_ARCH_5 21 -#define VIRQ_ARCH_6 22 -#define VIRQ_ARCH_7 23 -/* ` } */ - -#define NR_VIRQS 24 - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_mmu_update(const struct mmu_update reqs[], - * ` unsigned count, unsigned *done_out, - * ` unsigned foreigndom) - * ` - * @reqs is an array of mmu_update_t structures ((ptr, val) pairs). - * @count is the length of the above array. - * @pdone is an output parameter indicating number of completed operations - * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this - * hypercall invocation. Can be DOMID_SELF. - * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced - * in this hypercall invocation. The value of this field - * (x) encodes the PFD as follows: - * x == 0 => PFD == DOMID_SELF - * x != 0 => PFD == x - 1 - * - * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command. - * ------------- - * ptr[1:0] == MMU_NORMAL_PT_UPDATE: - * Updates an entry in a page table belonging to PFD. If updating an L1 table, - * and the new table entry is valid/present, the mapped frame must belong to - * FD. If attempting to map an I/O page then the caller assumes the privilege - * of the FD. - * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller. - * FD == DOMID_XEN: Map restricted areas of Xen's heap space. - * ptr[:2] -- Machine address of the page-table entry to modify. - * val -- Value to write. - * - * There also certain implicit requirements when using this hypercall. The - * pages that make up a pagetable must be mapped read-only in the guest. - * This prevents uncontrolled guest updates to the pagetable. Xen strictly - * enforces this, and will disallow any pagetable update which will end up - * mapping pagetable page RW, and will disallow using any writable page as a - * pagetable. In practice it means that when constructing a page table for a - * process, thread, etc, we MUST be very dilligient in following these rules: - * 1). Start with top-level page (PGD or in Xen language: L4). Fill out - * the entries. - * 2). Keep on going, filling out the upper (PUD or L3), and middle (PMD - * or L2). - * 3). Start filling out the PTE table (L1) with the PTE entries. Once - * done, make sure to set each of those entries to RO (so writeable bit - * is unset). Once that has been completed, set the PMD (L2) for this - * PTE table as RO. - * 4). When completed with all of the PMD (L2) entries, and all of them have - * been set to RO, make sure to set RO the PUD (L3). Do the same - * operation on PGD (L4) pagetable entries that have a PUD (L3) entry. - * 5). Now before you can use those pages (so setting the cr3), you MUST also - * pin them so that the hypervisor can verify the entries. This is done - * via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame - * number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op( - * MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be - * issued. - * For 32-bit guests, the L4 is not used (as there is less pagetables), so - * instead use L3. - * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE - * hypercall. Also if so desired the OS can also try to write to the PTE - * and be trapped by the hypervisor (as the PTE entry is RO). - * - * To deallocate the pages, the operations are the reverse of the steps - * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the - * pagetable MUST not be in use (meaning that the cr3 is not set to it). - * - * ptr[1:0] == MMU_MACHPHYS_UPDATE: - * Updates an entry in the machine->pseudo-physical mapping table. - * ptr[:2] -- Machine address within the frame whose mapping to modify. - * The frame must belong to the FD, if one is specified. - * val -- Value to write into the mapping entry. - * - * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD: - * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed - * with those in @val. - * - * @val is usually the machine frame number along with some attributes. - * The attributes by default follow the architecture defined bits. Meaning that - * if this is a X86_64 machine and four page table layout is used, the layout - * of val is: - * - 63 if set means No execute (NX) - * - 46-13 the machine frame number - * - 12 available for guest - * - 11 available for guest - * - 10 available for guest - * - 9 available for guest - * - 8 global - * - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages) - * - 6 dirty - * - 5 accessed - * - 4 page cached disabled - * - 3 page write through - * - 2 userspace accessible - * - 1 writeable - * - 0 present - * - * The one bits that does not fit with the default layout is the PAGE_PSE - * also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the - * HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB - * (or 2MB) instead of using the PAGE_PSE bit. - * - * The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen - * using it as the Page Attribute Table (PAT) bit - for details on it please - * refer to Intel SDM 10.12. The PAT allows to set the caching attributes of - * pages instead of using MTRRs. - * - * The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits): - * PAT4 PAT0 - * +-----+-----+----+----+----+-----+----+----+ - * | UC | UC- | WC | WB | UC | UC- | WC | WB | <= Linux - * +-----+-----+----+----+----+-----+----+----+ - * | UC | UC- | WT | WB | UC | UC- | WT | WB | <= BIOS (default when machine boots) - * +-----+-----+----+----+----+-----+----+----+ - * | rsv | rsv | WP | WC | UC | UC- | WT | WB | <= Xen - * +-----+-----+----+----+----+-----+----+----+ - * - * The lookup of this index table translates to looking up - * Bit 7, Bit 4, and Bit 3 of val entry: - * - * PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3). - * - * If all bits are off, then we are using PAT0. If bit 3 turned on, - * then we are using PAT1, if bit 3 and bit 4, then PAT2.. - * - * As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means - * that if a guest that follows Linux's PAT setup and would like to set Write - * Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is - * set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the - * caching as: - * - * WB = none (so PAT0) - * WC = PWT (bit 3 on) - * UC = PWT | PCD (bit 3 and 4 are on). - * - * To make it work with Xen, it needs to translate the WC bit as so: - * - * PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3 - * - * And to translate back it would: - * - * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7. - */ -#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ -#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ -#define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */ - -/* - * MMU EXTENDED OPERATIONS - * - * ` enum neg_errnoval - * ` HYPERVISOR_mmuext_op(mmuext_op_t uops[], - * ` unsigned int count, - * ` unsigned int *pdone, - * ` unsigned int foreigndom) - */ -/* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures. - * A foreigndom (FD) can be specified (or DOMID_SELF for none). - * Where the FD has some effect, it is described below. - * - * cmd: MMUEXT_(UN)PIN_*_TABLE - * mfn: Machine frame number to be (un)pinned as a p.t. page. - * The frame must belong to the FD, if one is specified. - * - * cmd: MMUEXT_NEW_BASEPTR - * mfn: Machine frame number of new page-table base to install in MMU. - * - * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only] - * mfn: Machine frame number of new page-table base to install in MMU - * when in user space. - * - * cmd: MMUEXT_TLB_FLUSH_LOCAL - * No additional arguments. Flushes local TLB. - * - * cmd: MMUEXT_INVLPG_LOCAL - * linear_addr: Linear address to be flushed from the local TLB. - * - * cmd: MMUEXT_TLB_FLUSH_MULTI - * vcpumask: Pointer to bitmap of VCPUs to be flushed. - * - * cmd: MMUEXT_INVLPG_MULTI - * linear_addr: Linear address to be flushed. - * vcpumask: Pointer to bitmap of VCPUs to be flushed. - * - * cmd: MMUEXT_TLB_FLUSH_ALL - * No additional arguments. Flushes all VCPUs' TLBs. - * - * cmd: MMUEXT_INVLPG_ALL - * linear_addr: Linear address to be flushed from all VCPUs' TLBs. - * - * cmd: MMUEXT_FLUSH_CACHE - * No additional arguments. Writes back and flushes cache contents. - * - * cmd: MMUEXT_FLUSH_CACHE_GLOBAL - * No additional arguments. Writes back and flushes cache contents - * on all CPUs in the system. - * - * cmd: MMUEXT_SET_LDT - * linear_addr: Linear address of LDT base (NB. must be page-aligned). - * nr_ents: Number of entries in LDT. - * - * cmd: MMUEXT_CLEAR_PAGE - * mfn: Machine frame number to be cleared. - * - * cmd: MMUEXT_COPY_PAGE - * mfn: Machine frame number of the destination page. - * src_mfn: Machine frame number of the source page. - * - * cmd: MMUEXT_[UN]MARK_SUPER - * mfn: Machine frame number of head of superpage to be [un]marked. - */ -/* ` enum mmuext_cmd { */ -#define MMUEXT_PIN_L1_TABLE 0 -#define MMUEXT_PIN_L2_TABLE 1 -#define MMUEXT_PIN_L3_TABLE 2 -#define MMUEXT_PIN_L4_TABLE 3 -#define MMUEXT_UNPIN_TABLE 4 -#define MMUEXT_NEW_BASEPTR 5 -#define MMUEXT_TLB_FLUSH_LOCAL 6 -#define MMUEXT_INVLPG_LOCAL 7 -#define MMUEXT_TLB_FLUSH_MULTI 8 -#define MMUEXT_INVLPG_MULTI 9 -#define MMUEXT_TLB_FLUSH_ALL 10 -#define MMUEXT_INVLPG_ALL 11 -#define MMUEXT_FLUSH_CACHE 12 -#define MMUEXT_SET_LDT 13 -#define MMUEXT_NEW_USER_BASEPTR 15 -#define MMUEXT_CLEAR_PAGE 16 -#define MMUEXT_COPY_PAGE 17 -#define MMUEXT_FLUSH_CACHE_GLOBAL 18 -#define MMUEXT_MARK_SUPER 19 -#define MMUEXT_UNMARK_SUPER 20 -/* ` } */ - -#ifndef __ASSEMBLY__ -struct mmuext_op { - unsigned int cmd; /* => enum mmuext_cmd */ - union { - /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR - * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */ - xen_pfn_t mfn; - /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */ - unsigned long linear_addr; - } arg1; - union { - /* SET_LDT */ - unsigned int nr_ents; - /* TLB_FLUSH_MULTI, INVLPG_MULTI */ -#if __XEN_INTERFACE_VERSION__ >= 0x00030205 - XEN_GUEST_HANDLE(const_void) vcpumask; -#else - const void *vcpumask; -#endif - /* COPY_PAGE */ - xen_pfn_t src_mfn; - } arg2; -}; -typedef struct mmuext_op mmuext_op_t; -DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); -#endif - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_update_va_mapping(unsigned long va, u64 val, - * ` enum uvm_flags flags) - * ` - * ` enum neg_errnoval - * ` HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, u64 val, - * ` enum uvm_flags flags, - * ` domid_t domid) - * ` - * ` @va: The virtual address whose mapping we want to change - * ` @val: The new page table entry, must contain a machine address - * ` @flags: Control TLB flushes - */ -/* These are passed as 'flags' to update_va_mapping. They can be ORed. */ -/* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */ -/* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */ -/* ` enum uvm_flags { */ -#define UVMF_NONE (xen_mk_ulong(0)<<0) /* No flushing at all. */ -#define UVMF_TLB_FLUSH (xen_mk_ulong(1)<<0) /* Flush entire TLB(s). */ -#define UVMF_INVLPG (xen_mk_ulong(2)<<0) /* Flush only one entry. */ -#define UVMF_FLUSHTYPE_MASK (xen_mk_ulong(3)<<0) -#define UVMF_MULTI (xen_mk_ulong(0)<<2) /* Flush subset of TLBs. */ -#define UVMF_LOCAL (xen_mk_ulong(0)<<2) /* Flush local TLB. */ -#define UVMF_ALL (xen_mk_ulong(1)<<2) /* Flush all TLBs. */ -/* ` } */ - -/* - * Commands to HYPERVISOR_console_io(). - */ -#define CONSOLEIO_write 0 -#define CONSOLEIO_read 1 - -/* - * Commands to HYPERVISOR_vm_assist(). - */ -#define VMASST_CMD_enable 0 -#define VMASST_CMD_disable 1 - -/* x86/32 guests: simulate full 4GB segment limits. */ -#define VMASST_TYPE_4gb_segments 0 - -/* x86/32 guests: trap (vector 15) whenever above vmassist is used. */ -#define VMASST_TYPE_4gb_segments_notify 1 - -/* - * x86 guests: support writes to bottom-level PTEs. - * NB1. Page-directory entries cannot be written. - * NB2. Guest must continue to remove all writable mappings of PTEs. - */ -#define VMASST_TYPE_writable_pagetables 2 - -/* x86/PAE guests: support PDPTs above 4GB. */ -#define VMASST_TYPE_pae_extended_cr3 3 - -/* - * x86 guests: Sane behaviour for virtual iopl - * - virtual iopl updated from do_iret() hypercalls. - * - virtual iopl reported in bounce frames. - * - guest kernels assumed to be level 0 for the purpose of iopl checks. - */ -#define VMASST_TYPE_architectural_iopl 4 - -/* - * All guests: activate update indicator in vcpu_runstate_info - * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped - * vcpu_runstate_info during updates of the runstate information. - */ -#define VMASST_TYPE_runstate_update_flag 5 - -/* - * x86/64 guests: strictly hide M2P from user mode. - * This allows the guest to control respective hypervisor behavior: - * - when not set, L4 tables get created with the respective slot blank, - * and whenever the L4 table gets used as a kernel one the missing - * mapping gets inserted, - * - when set, L4 tables get created with the respective slot initialized - * as before, and whenever the L4 table gets used as a user one the - * mapping gets zapped. - */ -#define VMASST_TYPE_m2p_strict 32 - -#if __XEN_INTERFACE_VERSION__ < 0x00040600 -#define MAX_VMASST_TYPE 3 -#endif - -/* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */ -#define DOMID_FIRST_RESERVED xen_mk_uint(0x7FF0) - -/* DOMID_SELF is used in certain contexts to refer to oneself. */ -#define DOMID_SELF xen_mk_uint(0x7FF0) - -/* - * DOMID_IO is used to restrict page-table updates to mapping I/O memory. - * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO - * is useful to ensure that no mappings to the OS's own heap are accidentally - * installed. (e.g., in Linux this could cause havoc as reference counts - * aren't adjusted on the I/O-mapping code path). - * This only makes sense as HYPERVISOR_mmu_update()'s and - * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument. For - * HYPERVISOR_mmu_update() context it can be specified by any calling domain, - * otherwise it's only permitted if the caller is privileged. - */ -#define DOMID_IO xen_mk_uint(0x7FF1) - -/* - * DOMID_XEN is used to allow privileged domains to map restricted parts of - * Xen's heap space (e.g., the machine_to_phys table). - * This only makes sense as - * - HYPERVISOR_mmu_update()'s, HYPERVISOR_mmuext_op()'s, or - * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument, - * - with XENMAPSPACE_gmfn_foreign, - * and is only permitted if the caller is privileged. - */ -#define DOMID_XEN xen_mk_uint(0x7FF2) - -/* - * DOMID_COW is used as the owner of sharable pages */ -#define DOMID_COW xen_mk_uint(0x7FF3) - -/* DOMID_INVALID is used to identify pages with unknown owner. */ -#define DOMID_INVALID xen_mk_uint(0x7FF4) - -/* Idle domain. */ -#define DOMID_IDLE xen_mk_uint(0x7FFF) - -#ifndef __ASSEMBLY__ - -typedef uint16_t domid_t; - -/* - * Send an array of these to HYPERVISOR_mmu_update(). - * NB. The fields are natural pointer/address size for this architecture. - */ -struct mmu_update { - uint64_t ptr; /* Machine address of PTE. */ - uint64_t val; /* New contents of PTE. */ -}; -typedef struct mmu_update mmu_update_t; -DEFINE_XEN_GUEST_HANDLE(mmu_update_t); - -/* - * ` enum neg_errnoval - * ` HYPERVISOR_multicall(multicall_entry_t call_list[], - * ` uint32_t nr_calls); - * - * NB. The fields are logically the natural register size for this - * architecture. In cases where xen_ulong_t is larger than this then - * any unused bits in the upper portion must be zero. - */ -struct multicall_entry { - xen_ulong_t op, result; - xen_ulong_t args[6]; -}; -typedef struct multicall_entry multicall_entry_t; -DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); - -#if __XEN_INTERFACE_VERSION__ < 0x00040400 -/* - * Event channel endpoints per domain (when using the 2-level ABI): - * 1024 if a long is 32 bits; 4096 if a long is 64 bits. - */ -#define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS -#endif - -struct vcpu_time_info { - /* - * Updates to the following values are preceded and followed by an - * increment of 'version'. The guest can therefore detect updates by - * looking for changes to 'version'. If the least-significant bit of - * the version number is set then an update is in progress and the guest - * must wait to read a consistent set of values. - * The correct way to interact with the version number is similar to - * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry. - */ - uint32_t version; - uint32_t pad0; - uint64_t tsc_timestamp; /* TSC at last update of time vals. */ - uint64_t system_time; /* Time, in nanosecs, since boot. */ - /* - * Current system time: - * system_time + - * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32) - * CPU frequency (Hz): - * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift - */ - uint32_t tsc_to_system_mul; - int8_t tsc_shift; -#if __XEN_INTERFACE_VERSION__ > 0x040600 - uint8_t flags; - uint8_t pad1[2]; -#else - int8_t pad1[3]; -#endif -}; /* 32 bytes */ -typedef struct vcpu_time_info vcpu_time_info_t; - -#define XEN_PVCLOCK_TSC_STABLE_BIT (1 << 0) -#define XEN_PVCLOCK_GUEST_STOPPED (1 << 1) - -struct vcpu_info { - /* - * 'evtchn_upcall_pending' is written non-zero by Xen to indicate - * a pending notification for a particular VCPU. It is then cleared - * by the guest OS /before/ checking for pending work, thus avoiding - * a set-and-check race. Note that the mask is only accessed by Xen - * on the CPU that is currently hosting the VCPU. This means that the - * pending and mask flags can be updated by the guest without special - * synchronisation (i.e., no need for the x86 LOCK prefix). - * This may seem suboptimal because if the pending flag is set by - * a different CPU then an IPI may be scheduled even when the mask - * is set. However, note: - * 1. The task of 'interrupt holdoff' is covered by the per-event- - * channel mask bits. A 'noisy' event that is continually being - * triggered can be masked at source at this very precise - * granularity. - * 2. The main purpose of the per-VCPU mask is therefore to restrict - * reentrant execution: whether for concurrency control, or to - * prevent unbounded stack usage. Whatever the purpose, we expect - * that the mask will be asserted only for short periods at a time, - * and so the likelihood of a 'spurious' IPI is suitably small. - * The mask is read before making an event upcall to the guest: a - * non-zero mask therefore guarantees that the VCPU will not receive - * an upcall activation. The mask is cleared when the VCPU requests - * to block: this avoids wakeup-waiting races. - */ - uint8_t evtchn_upcall_pending; -#ifdef XEN_HAVE_PV_UPCALL_MASK - uint8_t evtchn_upcall_mask; -#else /* XEN_HAVE_PV_UPCALL_MASK */ - uint8_t pad0; -#endif /* XEN_HAVE_PV_UPCALL_MASK */ - xen_ulong_t evtchn_pending_sel; - struct arch_vcpu_info arch; - struct vcpu_time_info time; -}; /* 64 bytes (x86) */ -#ifndef __XEN__ -typedef struct vcpu_info vcpu_info_t; -#endif - -/* - * `incontents 200 startofday_shared Start-of-day shared data structure - * Xen/kernel shared data -- pointer provided in start_info. - * - * This structure is defined to be both smaller than a page, and the - * only data on the shared page, but may vary in actual size even within - * compatible Xen versions; guests should not rely on the size - * of this structure remaining constant. - */ -struct shared_info { - struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS]; - - /* - * A domain can create "event channels" on which it can send and receive - * asynchronous event notifications. There are three classes of event that - * are delivered by this mechanism: - * 1. Bi-directional inter- and intra-domain connections. Domains must - * arrange out-of-band to set up a connection (usually by allocating - * an unbound 'listener' port and avertising that via a storage service - * such as xenstore). - * 2. Physical interrupts. A domain with suitable hardware-access - * privileges can bind an event-channel port to a physical interrupt - * source. - * 3. Virtual interrupts ('events'). A domain can bind an event-channel - * port to a virtual interrupt source, such as the virtual-timer - * device or the emergency console. - * - * Event channels are addressed by a "port index". Each channel is - * associated with two bits of information: - * 1. PENDING -- notifies the domain that there is a pending notification - * to be processed. This bit is cleared by the guest. - * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING - * will cause an asynchronous upcall to be scheduled. This bit is only - * updated by the guest. It is read-only within Xen. If a channel - * becomes pending while the channel is masked then the 'edge' is lost - * (i.e., when the channel is unmasked, the guest must manually handle - * pending notifications as no upcall will be scheduled by Xen). - * - * To expedite scanning of pending notifications, any 0->1 pending - * transition on an unmasked channel causes a corresponding bit in a - * per-vcpu selector word to be set. Each bit in the selector covers a - * 'C long' in the PENDING bitfield array. - */ - xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8]; - xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8]; - - /* - * Wallclock time: updated only by control software. Guests should base - * their gettimeofday() syscall on this wallclock-base value. - */ - uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */ - uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */ - uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */ -#if !defined(__i386__) - uint32_t wc_sec_hi; -# define xen_wc_sec_hi wc_sec_hi -#elif !defined(__XEN__) && !defined(__XEN_TOOLS__) -# define xen_wc_sec_hi arch.wc_sec_hi -#endif - - struct arch_shared_info arch; - -}; -#ifndef __XEN__ -typedef struct shared_info shared_info_t; -#endif - -/* - * `incontents 200 startofday Start-of-day memory layout - * - * 1. The domain is started within contiguous virtual-memory region. - * 2. The contiguous region ends on an aligned 4MB boundary. - * 3. This the order of bootstrap elements in the initial virtual region: - * a. relocated kernel image - * b. initial ram disk [mod_start, mod_len] - * (may be omitted) - * c. list of allocated page frames [mfn_list, nr_pages] - * (unless relocated due to XEN_ELFNOTE_INIT_P2M) - * d. start_info_t structure [register rSI (x86)] - * in case of dom0 this page contains the console info, too - * e. unless dom0: xenstore ring page - * f. unless dom0: console ring page - * g. bootstrap page tables [pt_base and CR3 (x86)] - * h. bootstrap stack [register ESP (x86)] - * 4. Bootstrap elements are packed together, but each is 4kB-aligned. - * 5. The list of page frames forms a contiguous 'pseudo-physical' memory - * layout for the domain. In particular, the bootstrap virtual-memory - * region is a 1:1 mapping to the first section of the pseudo-physical map. - * 6. All bootstrap elements are mapped read-writable for the guest OS. The - * only exception is the bootstrap page table, which is mapped read-only. - * 7. There is guaranteed to be at least 512kB padding after the final - * bootstrap element. If necessary, the bootstrap virtual region is - * extended by an extra 4MB to ensure this. - * - * Note: Prior to 25833:bb85bbccb1c9. ("x86/32-on-64 adjust Dom0 initial page - * table layout") a bug caused the pt_base (3.g above) and cr3 to not point - * to the start of the guest page tables (it was offset by two pages). - * This only manifested itself on 32-on-64 dom0 kernels and not 32-on-64 domU - * or 64-bit kernels of any colour. The page tables for a 32-on-64 dom0 got - * allocated in the order: 'first L1','first L2', 'first L3', so the offset - * to the page table base is by two pages back. The initial domain if it is - * 32-bit and runs under a 64-bit hypervisor should _NOT_ use two of the - * pages preceding pt_base and mark them as reserved/unused. - */ -#ifdef XEN_HAVE_PV_GUEST_ENTRY -struct start_info { - /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */ - char magic[32]; /* "xen--". */ - unsigned long nr_pages; /* Total pages allocated to this domain. */ - unsigned long shared_info; /* MACHINE address of shared info struct. */ - uint32_t flags; /* SIF_xxx flags. */ - xen_pfn_t store_mfn; /* MACHINE page number of shared page. */ - uint32_t store_evtchn; /* Event channel for store communication. */ - union { - struct { - xen_pfn_t mfn; /* MACHINE page number of console page. */ - uint32_t evtchn; /* Event channel for console page. */ - } domU; - struct { - uint32_t info_off; /* Offset of console_info struct. */ - uint32_t info_size; /* Size of console_info struct from start.*/ - } dom0; - } console; - /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */ - unsigned long pt_base; /* VIRTUAL address of page directory. */ - unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */ - unsigned long mfn_list; /* VIRTUAL address of page-frame list. */ - unsigned long mod_start; /* VIRTUAL address of pre-loaded module */ - /* (PFN of pre-loaded module if */ - /* SIF_MOD_START_PFN set in flags). */ - unsigned long mod_len; /* Size (bytes) of pre-loaded module. */ -#define MAX_GUEST_CMDLINE 1024 - int8_t cmd_line[MAX_GUEST_CMDLINE]; - /* The pfn range here covers both page table and p->m table frames. */ - unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */ - unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */ -}; -typedef struct start_info start_info_t; - -/* New console union for dom0 introduced in 0x00030203. */ -#if __XEN_INTERFACE_VERSION__ < 0x00030203 -#define console_mfn console.domU.mfn -#define console_evtchn console.domU.evtchn -#endif -#endif /* XEN_HAVE_PV_GUEST_ENTRY */ - -/* These flags are passed in the 'flags' field of start_info_t. */ -#define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */ -#define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */ -#define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */ -#define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */ -#define SIF_VIRT_P2M_4TOOLS (1<<4) /* Do Xen tools understand a virt. mapped */ - /* P->M making the 3 level tree obsolete? */ -#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */ - -/* - * A multiboot module is a package containing modules very similar to a - * multiboot module array. The only differences are: - * - the array of module descriptors is by convention simply at the beginning - * of the multiboot module, - * - addresses in the module descriptors are based on the beginning of the - * multiboot module, - * - the number of modules is determined by a termination descriptor that has - * mod_start == 0. - * - * This permits to both build it statically and reference it in a configuration - * file, and let the PV guest easily rebase the addresses to virtual addresses - * and at the same time count the number of modules. - */ -struct xen_multiboot_mod_list -{ - /* Address of first byte of the module */ - uint32_t mod_start; - /* Address of last byte of the module (inclusive) */ - uint32_t mod_end; - /* Address of zero-terminated command line */ - uint32_t cmdline; - /* Unused, must be zero */ - uint32_t pad; -}; -/* - * `incontents 200 startofday_dom0_console Dom0_console - * - * The console structure in start_info.console.dom0 - * - * This structure includes a variety of information required to - * have a working VGA/VESA console. - */ -typedef struct dom0_vga_console_info { - uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */ -#define XEN_VGATYPE_TEXT_MODE_3 0x03 -#define XEN_VGATYPE_VESA_LFB 0x23 -#define XEN_VGATYPE_EFI_LFB 0x70 - - union { - struct { - /* Font height, in pixels. */ - uint16_t font_height; - /* Cursor location (column, row). */ - uint16_t cursor_x, cursor_y; - /* Number of rows and columns (dimensions in characters). */ - uint16_t rows, columns; - } text_mode_3; - - struct { - /* Width and height, in pixels. */ - uint16_t width, height; - /* Bytes per scan line. */ - uint16_t bytes_per_line; - /* Bits per pixel. */ - uint16_t bits_per_pixel; - /* LFB physical address, and size (in units of 64kB). */ - uint32_t lfb_base; - uint32_t lfb_size; - /* RGB mask offsets and sizes, as defined by VBE 1.2+ */ - uint8_t red_pos, red_size; - uint8_t green_pos, green_size; - uint8_t blue_pos, blue_size; - uint8_t rsvd_pos, rsvd_size; -#if __XEN_INTERFACE_VERSION__ >= 0x00030206 - /* VESA capabilities (offset 0xa, VESA command 0x4f00). */ - uint32_t gbl_caps; - /* Mode attributes (offset 0x0, VESA command 0x4f01). */ - uint16_t mode_attrs; -#endif - } vesa_lfb; - } u; -} dom0_vga_console_info_t; -#define xen_vga_console_info dom0_vga_console_info -#define xen_vga_console_info_t dom0_vga_console_info_t - -typedef uint8_t xen_domain_handle_t[16]; - -__DEFINE_XEN_GUEST_HANDLE(uint8, uint8_t); -__DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t); -__DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t); -__DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t); - -typedef struct { - uint8_t a[16]; -} xen_uuid_t; - -/* - * XEN_DEFINE_UUID(0x00112233, 0x4455, 0x6677, 0x8899, - * 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff) - * will construct UUID 00112233-4455-6677-8899-aabbccddeeff presented as - * {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, - * 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; - * - * NB: This is compatible with Linux kernel and with libuuid, but it is not - * compatible with Microsoft, as they use mixed-endian encoding (some - * components are little-endian, some are big-endian). - */ -#define XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6) \ - {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF, \ - ((a) >> 8) & 0xFF, ((a) >> 0) & 0xFF, \ - ((b) >> 8) & 0xFF, ((b) >> 0) & 0xFF, \ - ((c) >> 8) & 0xFF, ((c) >> 0) & 0xFF, \ - ((d) >> 8) & 0xFF, ((d) >> 0) & 0xFF, \ - e1, e2, e3, e4, e5, e6}} - -#if defined(__STDC_VERSION__) ? __STDC_VERSION__ >= 199901L : defined(__GNUC__) -#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \ - ((xen_uuid_t)XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6)) -#else -#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \ - XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6) -#endif /* __STDC_VERSION__ / __GNUC__ */ - -#endif /* !__ASSEMBLY__ */ - -/* Default definitions for macros used by domctl/sysctl. */ -#if defined(__XEN__) || defined(__XEN_TOOLS__) - -#ifndef int64_aligned_t -#define int64_aligned_t int64_t -#endif -#ifndef uint64_aligned_t -#define uint64_aligned_t uint64_t -#endif -#ifndef XEN_GUEST_HANDLE_64 -#define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name) -#endif - -#ifndef __ASSEMBLY__ -struct xenctl_bitmap { - XEN_GUEST_HANDLE_64(uint8) bitmap; - uint32_t nr_bits; -}; -#endif - -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ - -#endif /* __XEN_PUBLIC_XEN_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/linguas.sh b/linguas.sh index b95ad4f7d..1de42ba2d 100755 --- a/linguas.sh +++ b/linguas.sh @@ -1,12 +1,12 @@ #!/bin/sh -rsync -Lrtvz translationproject.org::tp/latest/grub/ po +rsync -Lrtvz --exclude=ko.po translationproject.org::tp/latest/grub/ po autogenerated="en@quot en@hebrew de@hebrew en@cyrillic en@greek en@arabic en@piglatin de_CH" for x in $autogenerated; do - rm -f "po/$x.po"; + rm "po/$x.po"; done diff --git a/m4/00gnulib.m4 b/m4/00gnulib.m4 new file mode 100644 index 000000000..d4ad759fd --- /dev/null +++ b/m4/00gnulib.m4 @@ -0,0 +1,30 @@ +# 00gnulib.m4 serial 2 +dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This file must be named something that sorts before all other +dnl gnulib-provided .m4 files. It is needed until such time as we can +dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics. + +# AC_DEFUN_ONCE([NAME], VALUE) +# ---------------------------- +# Define NAME to expand to VALUE on the first use (whether by direct +# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses. +# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This +# definition is slower than the version in Autoconf 2.64, because it +# can only use interfaces that existed since 2.59; but it achieves the +# same effect. Quoting is necessary to avoid confusing Automake. +m4_version_prereq([2.63.263], [], +[m4_define([AC][_DEFUN_ONCE], + [AC][_DEFUN([$1], + [AC_REQUIRE([_gl_DEFUN_ONCE([$1])], + [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl +[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])]) + +# gl_00GNULIB +# ----------- +# Witness macro that this file has been included. Needed to force +# Automake to include this file prior to all other gnulib .m4 files. +AC_DEFUN([gl_00GNULIB]) diff --git a/m4/alloca.m4 b/m4/alloca.m4 new file mode 100644 index 000000000..270abd0cd --- /dev/null +++ b/m4/alloca.m4 @@ -0,0 +1,121 @@ +# alloca.m4 serial 14 +dnl Copyright (C) 2002-2004, 2006-2007, 2009-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_ALLOCA], +[ + AC_REQUIRE([AC_FUNC_ALLOCA]) + if test $ac_cv_func_alloca_works = no; then + gl_PREREQ_ALLOCA + fi + + # Define an additional variable used in the Makefile substitution. + if test $ac_cv_working_alloca_h = yes; then + AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ + AC_EGREP_CPP([Need own alloca], [ +#if defined __GNUC__ || defined _AIX || defined _MSC_VER + Need own alloca +#endif + ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) + ]) + if test $gl_cv_rpl_alloca = yes; then + dnl OK, alloca can be implemented through a compiler built-in. + AC_DEFINE([HAVE_ALLOCA], [1], + [Define to 1 if you have 'alloca' after including , + a header that may be supplied by this distribution.]) + ALLOCA_H=alloca.h + else + dnl alloca exists as a library function, i.e. it is slow and probably + dnl a memory leak. Don't define HAVE_ALLOCA in this case. + ALLOCA_H= + fi + else + ALLOCA_H=alloca.h + fi + AC_SUBST([ALLOCA_H]) + AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"]) +]) + +# Prerequisites of lib/alloca.c. +# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. +AC_DEFUN([gl_PREREQ_ALLOCA], [:]) + +# This works around a bug in autoconf <= 2.68. +# See . + +m4_version_prereq([2.69], [] ,[ + +# This is taken from the following Autoconf patch: +# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497 + +# _AC_LIBOBJ_ALLOCA +# ----------------- +# Set up the LIBOBJ replacement of 'alloca'. Well, not exactly +# AC_LIBOBJ since we actually set the output variable 'ALLOCA'. +# Nevertheless, for Automake, AC_LIBSOURCES it. +m4_define([_AC_LIBOBJ_ALLOCA], +[# The SVR3 libPW and SVR4 libucb both contain incompatible functions +# that cause trouble. Some versions do not even contain alloca or +# contain a buggy version. If you still want to use their alloca, +# use ar to extract alloca.o from them instead of compiling alloca.c. +AC_LIBSOURCES(alloca.c) +AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl +AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.]) + +AC_CACHE_CHECK(whether 'alloca.c' needs Cray hooks, ac_cv_os_cray, +[AC_EGREP_CPP(webecray, +[#if defined CRAY && ! defined CRAY2 +webecray +#else +wenotbecray +#endif +], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) +if test $ac_cv_os_cray = yes; then + for ac_func in _getb67 GETB67 getb67; do + AC_CHECK_FUNC($ac_func, + [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, + [Define to one of '_getb67', 'GETB67', + 'getb67' for Cray-2 and Cray-YMP + systems. This function is required for + 'alloca.c' support on those systems.]) + break]) + done +fi + +AC_CACHE_CHECK([stack direction for C alloca], + [ac_cv_c_stack_direction], +[AC_RUN_IFELSE([AC_LANG_SOURCE( +[AC_INCLUDES_DEFAULT +int +find_stack_direction (int *addr, int depth) +{ + int dir, dummy = 0; + if (! addr) + addr = &dummy; + *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; + dir = depth ? find_stack_direction (addr, depth - 1) : 0; + return dir + dummy; +} + +int +main (int argc, char **argv) +{ + return find_stack_direction (0, argc + !argv + 20) < 0; +}])], + [ac_cv_c_stack_direction=1], + [ac_cv_c_stack_direction=-1], + [ac_cv_c_stack_direction=0])]) +AH_VERBATIM([STACK_DIRECTION], +[/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +@%:@undef STACK_DIRECTION])dnl +AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) +])# _AC_LIBOBJ_ALLOCA +]) diff --git a/m4/argp.m4 b/m4/argp.m4 new file mode 100644 index 000000000..4445d8e6c --- /dev/null +++ b/m4/argp.m4 @@ -0,0 +1,61 @@ +# argp.m4 serial 14 +dnl Copyright (C) 2003-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_ARGP], +[ + AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS([program_invocation_name], [], + [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_NAME], [1], + [Define to 1 to add extern declaration of program_invocation_name to argp.h])], + [[#include ]]) + AC_CHECK_DECLS([program_invocation_short_name], [], + [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_SHORT_NAME], [1], + [Define to 1 to add extern declaration of program_invocation_short_name to argp.h])], + [[#include ]]) + + # Check if program_invocation_name and program_invocation_short_name + # are defined elsewhere. It is improbable that only one of them will + # be defined and other not, I prefer to stay on the safe side and to + # test each one separately. + AC_MSG_CHECKING([whether program_invocation_name is defined]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[program_invocation_name = "test";]])], + [AC_DEFINE([HAVE_PROGRAM_INVOCATION_NAME], [1], + [Define if program_invocation_name is defined]) + AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no])]) + + AC_MSG_CHECKING([whether program_invocation_short_name is defined]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[program_invocation_short_name = "test";]])], + [AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1], + [Define if program_invocation_short_name is defined]) + AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no])]) + + AC_CHECK_DECLS_ONCE([clearerr_unlocked]) + AC_CHECK_DECLS_ONCE([feof_unlocked]) + AC_CHECK_DECLS_ONCE([ferror_unlocked]) + AC_CHECK_DECLS_ONCE([fflush_unlocked]) + AC_CHECK_DECLS_ONCE([fgets_unlocked]) + AC_CHECK_DECLS_ONCE([fputc_unlocked]) + AC_CHECK_DECLS_ONCE([fputs_unlocked]) + AC_CHECK_DECLS_ONCE([fread_unlocked]) + AC_CHECK_DECLS_ONCE([fwrite_unlocked]) + AC_CHECK_DECLS_ONCE([getc_unlocked]) + AC_CHECK_DECLS_ONCE([getchar_unlocked]) + AC_CHECK_DECLS_ONCE([putc_unlocked]) + AC_CHECK_DECLS_ONCE([putchar_unlocked]) + AC_CHECK_FUNCS_ONCE([flockfile funlockfile]) + AC_CHECK_HEADERS_ONCE([features.h linewrap.h]) +]) + +dnl argp-parse.c depends on GNU getopt internals, therefore use GNU getopt +dnl always. +AC_DEFUN([gl_REPLACE_GETOPT_ALWAYS], []) diff --git a/m4/btowc.m4 b/m4/btowc.m4 new file mode 100644 index 000000000..978a06e9a --- /dev/null +++ b/m4/btowc.m4 @@ -0,0 +1,116 @@ +# btowc.m4 serial 10 +dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_BTOWC], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + dnl Check whether is usable at all, first. Otherwise the test + dnl program below may lead to an endless loop. See + dnl . + AC_REQUIRE([gl_WCHAR_H_INLINE_OK]) + + AC_CHECK_FUNCS_ONCE([btowc]) + if test $ac_cv_func_btowc = no; then + HAVE_BTOWC=0 + else + + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + + dnl Cygwin 1.7.2 btowc('\0') is WEOF, not 0. + AC_CACHE_CHECK([whether btowc(0) is correct], + [gl_cv_func_btowc_nul], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + if (btowc ('\0') != 0) + return 1; + return 0; +}]])], + [gl_cv_func_btowc_nul=yes], + [gl_cv_func_btowc_nul=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess no on Cygwin. + cygwin*) gl_cv_func_btowc_nul="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_btowc_nul="guessing yes" ;; + esac +changequote([,])dnl + ]) + ]) + + dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF. + AC_CACHE_CHECK([whether btowc(EOF) is correct], + [gl_cv_func_btowc_eof], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on IRIX. + irix*) gl_cv_func_btowc_eof="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_btowc_eof="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) + { + if (btowc (EOF) != WEOF) + return 1; + } + return 0; +}]])], + [gl_cv_func_btowc_eof=yes], + [gl_cv_func_btowc_eof=no], + [:]) + fi + ]) + + case "$gl_cv_func_btowc_nul" in + *yes) ;; + *) REPLACE_BTOWC=1 ;; + esac + case "$gl_cv_func_btowc_eof" in + *yes) ;; + *) REPLACE_BTOWC=1 ;; + esac + fi +]) + +# Prerequisites of lib/btowc.c. +AC_DEFUN([gl_PREREQ_BTOWC], [ + : +]) diff --git a/m4/codeset.m4 b/m4/codeset.m4 new file mode 100644 index 000000000..c2761be2a --- /dev/null +++ b/m4/codeset.m4 @@ -0,0 +1,23 @@ +# codeset.m4 serial 5 (gettext-0.18.2) +dnl Copyright (C) 2000-2002, 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([AM_LANGINFO_CODESET], +[ + AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[char* cs = nl_langinfo(CODESET); return !cs;]])], + [am_cv_langinfo_codeset=yes], + [am_cv_langinfo_codeset=no]) + ]) + if test $am_cv_langinfo_codeset = yes; then + AC_DEFINE([HAVE_LANGINFO_CODESET], [1], + [Define if you have and nl_langinfo(CODESET).]) + fi +]) diff --git a/m4/configmake.m4 b/m4/configmake.m4 new file mode 100644 index 000000000..823ffc0dd --- /dev/null +++ b/m4/configmake.m4 @@ -0,0 +1,50 @@ +# configmake.m4 serial 1 +dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_CONFIGMAKE_PREP +# ------------------ +# Guarantee all of the standard directory variables, even when used with +# autoconf 2.59 (datarootdir wasn't supported until 2.59c) or automake +# 1.9.6 (pkglibexecdir wasn't supported until 1.10b.). +AC_DEFUN([gl_CONFIGMAKE_PREP], +[ + dnl Technically, datadir should default to datarootdir. But if + dnl autoconf is too old to provide datarootdir, then reversing the + dnl definition is a reasonable compromise. Only AC_SUBST a variable + dnl if it was not already defined earlier by autoconf. + if test "x$datarootdir" = x; then + AC_SUBST([datarootdir], ['${datadir}']) + fi + dnl Copy the approach used in autoconf 2.60. + if test "x$docdir" = x; then + AC_SUBST([docdir], [m4_ifset([AC_PACKAGE_TARNAME], + ['${datarootdir}/doc/${PACKAGE_TARNAME}'], + ['${datarootdir}/doc/${PACKAGE}'])]) + fi + dnl The remaining variables missing from autoconf 2.59 are easier. + if test "x$htmldir" = x; then + AC_SUBST([htmldir], ['${docdir}']) + fi + if test "x$dvidir" = x; then + AC_SUBST([dvidir], ['${docdir}']) + fi + if test "x$pdfdir" = x; then + AC_SUBST([pdfdir], ['${docdir}']) + fi + if test "x$psdir" = x; then + AC_SUBST([psdir], ['${docdir}']) + fi + if test "x$lispdir" = x; then + AC_SUBST([lispdir], ['${datarootdir}/emacs/site-lisp']) + fi + if test "x$localedir" = x; then + AC_SUBST([localedir], ['${datarootdir}/locale']) + fi + + dnl Automake 1.9.6 only lacks pkglibexecdir; and since 1.11 merely + dnl provides it without AC_SUBST, this blind use of AC_SUBST is safe. + AC_SUBST([pkglibexecdir], ['${libexecdir}/${PACKAGE}']) +]) diff --git a/m4/dirname.m4 b/m4/dirname.m4 new file mode 100644 index 000000000..5897a2a8b --- /dev/null +++ b/m4/dirname.m4 @@ -0,0 +1,19 @@ +#serial 10 -*- autoconf -*- +dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_DIRNAME], +[ + AC_REQUIRE([gl_DIRNAME_LGPL]) +]) + +AC_DEFUN([gl_DIRNAME_LGPL], +[ + dnl Prerequisites of lib/dirname.h. + AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) + + dnl No prerequisites of lib/basename-lgpl.c, lib/dirname-lgpl.c, + dnl lib/stripslash.c. +]) diff --git a/m4/double-slash-root.m4 b/m4/double-slash-root.m4 new file mode 100644 index 000000000..bd6f86714 --- /dev/null +++ b/m4/double-slash-root.m4 @@ -0,0 +1,38 @@ +# double-slash-root.m4 serial 4 -*- Autoconf -*- +dnl Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_DOUBLE_SLASH_ROOT], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], + [ if test x"$cross_compiling" = xyes ; then + # When cross-compiling, there is no way to tell whether // is special + # short of a list of hosts. However, the only known hosts to date + # that have a distinct // are Apollo DomainOS (too old to port to), + # Cygwin, and z/OS. If anyone knows of another system for which // has + # special semantics and is distinct from /, please report it to + # . + case $host in + *-cygwin | i370-ibm-openedition) + gl_cv_double_slash_root=yes ;; + *) + # Be optimistic and assume that / and // are the same when we + # don't know. + gl_cv_double_slash_root='unknown, assuming no' ;; + esac + else + set x `ls -di / // 2>/dev/null` + if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then + gl_cv_double_slash_root=no + else + gl_cv_double_slash_root=yes + fi + fi]) + if test "$gl_cv_double_slash_root" = yes; then + AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1], + [Define to 1 if // is a file system root distinct from /.]) + fi +]) diff --git a/m4/eealloc.m4 b/m4/eealloc.m4 new file mode 100644 index 000000000..c640ec129 --- /dev/null +++ b/m4/eealloc.m4 @@ -0,0 +1,31 @@ +# eealloc.m4 serial 3 +dnl Copyright (C) 2003, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_EEALLOC], +[ + AC_REQUIRE([gl_EEMALLOC]) + AC_REQUIRE([gl_EEREALLOC]) +]) + +AC_DEFUN([gl_EEMALLOC], +[ + _AC_FUNC_MALLOC_IF( + [gl_cv_func_malloc_0_nonnull=1], + [gl_cv_func_malloc_0_nonnull=0]) + AC_DEFINE_UNQUOTED([MALLOC_0_IS_NONNULL], [$gl_cv_func_malloc_0_nonnull], + [If malloc(0) is != NULL, define this to 1. Otherwise define this + to 0.]) +]) + +AC_DEFUN([gl_EEREALLOC], +[ + _AC_FUNC_REALLOC_IF( + [gl_cv_func_realloc_0_nonnull=1], + [gl_cv_func_realloc_0_nonnull=0]) + AC_DEFINE_UNQUOTED([REALLOC_0_IS_NONNULL], [$gl_cv_func_realloc_0_nonnull], + [If realloc(NULL,0) is != NULL, define this to 1. Otherwise define this + to 0.]) +]) diff --git a/m4/errno_h.m4 b/m4/errno_h.m4 new file mode 100644 index 000000000..c813ea583 --- /dev/null +++ b/m4/errno_h.m4 @@ -0,0 +1,137 @@ +# errno_h.m4 serial 12 +dnl Copyright (C) 2004, 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN_ONCE([gl_HEADER_ERRNO_H], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_CACHE_CHECK([for complete errno.h], [gl_cv_header_errno_h_complete], [ + AC_EGREP_CPP([booboo],[ +#include +#if !defined ETXTBSY +booboo +#endif +#if !defined ENOMSG +booboo +#endif +#if !defined EIDRM +booboo +#endif +#if !defined ENOLINK +booboo +#endif +#if !defined EPROTO +booboo +#endif +#if !defined EMULTIHOP +booboo +#endif +#if !defined EBADMSG +booboo +#endif +#if !defined EOVERFLOW +booboo +#endif +#if !defined ENOTSUP +booboo +#endif +#if !defined ENETRESET +booboo +#endif +#if !defined ECONNABORTED +booboo +#endif +#if !defined ESTALE +booboo +#endif +#if !defined EDQUOT +booboo +#endif +#if !defined ECANCELED +booboo +#endif +#if !defined EOWNERDEAD +booboo +#endif +#if !defined ENOTRECOVERABLE +booboo +#endif +#if !defined EILSEQ +booboo +#endif + ], + [gl_cv_header_errno_h_complete=no], + [gl_cv_header_errno_h_complete=yes]) + ]) + if test $gl_cv_header_errno_h_complete = yes; then + ERRNO_H='' + else + gl_NEXT_HEADERS([errno.h]) + ERRNO_H='errno.h' + fi + AC_SUBST([ERRNO_H]) + AM_CONDITIONAL([GL_GENERATE_ERRNO_H], [test -n "$ERRNO_H"]) + gl_REPLACE_ERRNO_VALUE([EMULTIHOP]) + gl_REPLACE_ERRNO_VALUE([ENOLINK]) + gl_REPLACE_ERRNO_VALUE([EOVERFLOW]) +]) + +# Assuming $1 = EOVERFLOW. +# The EOVERFLOW errno value ought to be defined in , according to +# POSIX. But some systems (like OpenBSD 4.0 or AIX 3) don't define it, and +# some systems (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined. +# Check for the value of EOVERFLOW. +# Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE. +AC_DEFUN([gl_REPLACE_ERRNO_VALUE], +[ + if test -n "$ERRNO_H"; then + AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [ + AC_EGREP_CPP([yes],[ +#include +#ifdef ]$1[ +yes +#endif + ], + [gl_cv_header_errno_h_]$1[=yes], + [gl_cv_header_errno_h_]$1[=no]) + if test $gl_cv_header_errno_h_]$1[ = no; then + AC_EGREP_CPP([yes],[ +#define _XOPEN_SOURCE_EXTENDED 1 +#include +#ifdef ]$1[ +yes +#endif + ], [gl_cv_header_errno_h_]$1[=hidden]) + if test $gl_cv_header_errno_h_]$1[ = hidden; then + dnl The macro exists but is hidden. + dnl Define it to the same value. + AC_COMPUTE_INT([gl_cv_header_errno_h_]$1, $1, [ +#define _XOPEN_SOURCE_EXTENDED 1 +#include +/* The following two lines are a workaround against an autoconf-2.52 bug. */ +#include +#include +]) + fi + fi + ]) + case $gl_cv_header_errno_h_]$1[ in + yes | no) + ]$1[_HIDDEN=0; ]$1[_VALUE= + ;; + *) + ]$1[_HIDDEN=1; ]$1[_VALUE="$gl_cv_header_errno_h_]$1[" + ;; + esac + AC_SUBST($1[_HIDDEN]) + AC_SUBST($1[_VALUE]) + fi +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) diff --git a/m4/error.m4 b/m4/error.m4 new file mode 100644 index 000000000..29e6fdc9c --- /dev/null +++ b/m4/error.m4 @@ -0,0 +1,27 @@ +#serial 14 + +# Copyright (C) 1996-1998, 2001-2004, 2009-2013 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_ERROR], +[ + dnl We don't use AC_FUNC_ERROR_AT_LINE any more, because it is no longer + dnl maintained in Autoconf and because it invokes AC_LIBOBJ. + AC_CACHE_CHECK([for error_at_line], [ac_cv_lib_error_at_line], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[error_at_line (0, 0, "", 0, "an error occurred");]])], + [ac_cv_lib_error_at_line=yes], + [ac_cv_lib_error_at_line=no])]) +]) + +# Prerequisites of lib/error.c. +AC_DEFUN([gl_PREREQ_ERROR], +[ + AC_REQUIRE([AC_FUNC_STRERROR_R]) + : +]) diff --git a/m4/exponentd.m4 b/m4/exponentd.m4 new file mode 100644 index 000000000..09df468c9 --- /dev/null +++ b/m4/exponentd.m4 @@ -0,0 +1,116 @@ +# exponentd.m4 serial 3 +dnl Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION], +[ + AC_CACHE_CHECK([where to find the exponent in a 'double'], + [gl_cv_cc_double_expbit0], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +#include +#define NWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) +typedef union { double value; unsigned int word[NWORDS]; } memory_double; +static unsigned int ored_words[NWORDS]; +static unsigned int anded_words[NWORDS]; +static void add_to_ored_words (double x) +{ + memory_double m; + size_t i; + /* Clear it first, in case sizeof (double) < sizeof (memory_double). */ + memset (&m, 0, sizeof (memory_double)); + m.value = x; + for (i = 0; i < NWORDS; i++) + { + ored_words[i] |= m.word[i]; + anded_words[i] &= m.word[i]; + } +} +int main () +{ + size_t j; + FILE *fp = fopen ("conftest.out", "w"); + if (fp == NULL) + return 1; + for (j = 0; j < NWORDS; j++) + anded_words[j] = ~ (unsigned int) 0; + add_to_ored_words (0.25); + add_to_ored_words (0.5); + add_to_ored_words (1.0); + add_to_ored_words (2.0); + add_to_ored_words (4.0); + /* Remove bits that are common (e.g. if representation of the first mantissa + bit is explicit). */ + for (j = 0; j < NWORDS; j++) + ored_words[j] &= ~anded_words[j]; + /* Now find the nonzero word. */ + for (j = 0; j < NWORDS; j++) + if (ored_words[j] != 0) + break; + if (j < NWORDS) + { + size_t i; + for (i = j + 1; i < NWORDS; i++) + if (ored_words[i] != 0) + { + fprintf (fp, "unknown"); + return (fclose (fp) != 0); + } + for (i = 0; ; i++) + if ((ored_words[j] >> i) & 1) + { + fprintf (fp, "word %d bit %d", (int) j, (int) i); + return (fclose (fp) != 0); + } + } + fprintf (fp, "unknown"); + return (fclose (fp) != 0); +} + ]])], + [gl_cv_cc_double_expbit0=`cat conftest.out`], + [gl_cv_cc_double_expbit0="unknown"], + [ + dnl On ARM, there are two 'double' floating-point formats, used by + dnl different sets of instructions: The older FPA instructions assume + dnl that they are stored in big-endian word order, while the words + dnl (like integer types) are stored in little-endian byte order. + dnl The newer VFP instructions assume little-endian order + dnl consistently. + AC_EGREP_CPP([mixed_endianness], [ +#if defined arm || defined __arm || defined __arm__ + mixed_endianness +#endif + ], + [gl_cv_cc_double_expbit0="unknown"], + [ + pushdef([AC_MSG_CHECKING],[:])dnl + pushdef([AC_MSG_RESULT],[:])dnl + pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl + AC_C_BIGENDIAN( + [gl_cv_cc_double_expbit0="word 0 bit 20"], + [gl_cv_cc_double_expbit0="word 1 bit 20"], + [gl_cv_cc_double_expbit0="unknown"]) + popdef([AC_MSG_RESULT_UNQUOTED])dnl + popdef([AC_MSG_RESULT])dnl + popdef([AC_MSG_CHECKING])dnl + ]) + ]) + rm -f conftest.out + ]) + case "$gl_cv_cc_double_expbit0" in + word*bit*) + word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'` + bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'` + AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word], + [Define as the word index where to find the exponent of 'double'.]) + AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit], + [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.]) + ;; + esac +]) diff --git a/m4/extensions.m4 b/m4/extensions.m4 new file mode 100644 index 000000000..07ba376c0 --- /dev/null +++ b/m4/extensions.m4 @@ -0,0 +1,138 @@ +# serial 13 -*- Autoconf -*- +# Enable extensions on systems that normally disable them. + +# Copyright (C) 2003, 2006-2013 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS +# Autoconf. Perhaps we can remove this once we can assume Autoconf +# 2.70 or later everywhere, but since Autoconf mutates rapidly +# enough in this area it's likely we'll need to redefine +# AC_USE_SYSTEM_EXTENSIONS for quite some time. + +# If autoconf reports a warning +# warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS +# or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS +# the fix is +# 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked +# but always AC_REQUIREd, +# 2) to ensure that for each occurrence of +# AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) +# or +# AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) +# the corresponding gnulib module description has 'extensions' among +# its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS +# invocation occurs in gl_EARLY, not in gl_INIT. + +# AC_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +# +# Remember that #undef in AH_VERBATIM gets replaced with #define by +# AC_DEFINE. The goal here is to define all known feature-enabling +# macros, then, if reports of conflicts are made, disable macros that +# cause problems on some platforms (such as __EXTENSIONS__). +AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS], +[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl +AC_BEFORE([$0], [AC_RUN_IFELSE])dnl + + AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) + if test "$MINIX" = yes; then + AC_DEFINE([_POSIX_SOURCE], [1], + [Define to 1 if you need to in order for 'stat' and other + things to work.]) + AC_DEFINE([_POSIX_1_SOURCE], [2], + [Define to 2 if the system does not provide POSIX.1 features + except with this defined.]) + AC_DEFINE([_MINIX], [1], + [Define to 1 if on MINIX.]) + AC_DEFINE([_NETBSD_SOURCE], [1], + [Define to 1 to make NetBSD features available. MINIX 3 needs this.]) + fi + +dnl Use a different key than __EXTENSIONS__, as that name broke existing +dnl configure.ac when using autoheader 2.62. + AH_VERBATIM([USE_SYSTEM_EXTENSIONS], +[/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable general extensions on OS X. */ +#ifndef _DARWIN_C_SOURCE +# undef _DARWIN_C_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable X/Open extensions if necessary. HP-UX 11.11 defines + mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of + whether compiling with -Ae or -D_HPUX_SOURCE=1. */ +#ifndef _XOPEN_SOURCE +# undef _XOPEN_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif +]) + AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], + [ac_cv_safe_to_define___extensions__], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ +# define __EXTENSIONS__ 1 + ]AC_INCLUDES_DEFAULT])], + [ac_cv_safe_to_define___extensions__=yes], + [ac_cv_safe_to_define___extensions__=no])]) + test $ac_cv_safe_to_define___extensions__ = yes && + AC_DEFINE([__EXTENSIONS__]) + AC_DEFINE([_ALL_SOURCE]) + AC_DEFINE([_DARWIN_C_SOURCE]) + AC_DEFINE([_GNU_SOURCE]) + AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) + AC_DEFINE([_TANDEM_SOURCE]) + AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined], + [ac_cv_should_define__xopen_source], + [ac_cv_should_define__xopen_source=no + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #include + mbstate_t x;]])], + [], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #define _XOPEN_SOURCE 500 + #include + mbstate_t x;]])], + [ac_cv_should_define__xopen_source=yes])])]) + test $ac_cv_should_define__xopen_source = yes && + AC_DEFINE([_XOPEN_SOURCE], [500]) +])# AC_USE_SYSTEM_EXTENSIONS + +# gl_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], +[ + dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS. + dnl gnulib does not need it. But if it gets required by third-party macros + dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a + dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". + dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE, + dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck. + AC_REQUIRE([AC_GNU_SOURCE]) + + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) +]) diff --git a/m4/extern-inline.m4 b/m4/extern-inline.m4 new file mode 100644 index 000000000..0152f2932 --- /dev/null +++ b/m4/extern-inline.m4 @@ -0,0 +1,65 @@ +dnl 'extern inline' a la ISO C99. + +dnl Copyright 2012-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_EXTERN_INLINE], +[ + AH_VERBATIM([extern_inline], +[/* _GL_INLINE is a portable alternative to ISO C99 plain 'inline'. + _GL_EXTERN_INLINE is a portable alternative to 'extern inline'. + _GL_INLINE_HEADER_BEGIN contains useful stuff to put + in an include file, before uses of _GL_INLINE. + It suppresses GCC's bogus "no previous prototype for 'FOO'" diagnostic, + when FOO is an inline function in the header; see + . + _GL_INLINE_HEADER_END contains useful stuff to put + in the same include file, after uses of _GL_INLINE. + + Suppress extern inline with HP-UX cc, as it appears to be broken; see + . + + Suppress the use of extern inline on Apple's platforms, + as Libc-825.25 (2012-09-19) is incompatible with it; see + . + Perhaps Apple will fix this some day. */ +#if ((__GNUC__ \ + ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ + : 199901L <= __STDC_VERSION__ && !defined __HP_cc) \ + && !defined __APPLE__) +# define _GL_INLINE inline +# define _GL_EXTERN_INLINE extern inline +#elif 2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __APPLE__ +# if __GNUC_GNU_INLINE__ + /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ +# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) +# else +# define _GL_INLINE extern inline +# endif +# define _GL_EXTERN_INLINE extern +#else +# define _GL_INLINE static _GL_UNUSED +# define _GL_EXTERN_INLINE static _GL_UNUSED +#endif + +#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) +# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ +# define _GL_INLINE_HEADER_CONST_PRAGMA +# else +# define _GL_INLINE_HEADER_CONST_PRAGMA \ + _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") +# endif +# define _GL_INLINE_HEADER_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \ + _GL_INLINE_HEADER_CONST_PRAGMA +# define _GL_INLINE_HEADER_END \ + _Pragma ("GCC diagnostic pop") +#else +# define _GL_INLINE_HEADER_BEGIN +# define _GL_INLINE_HEADER_END +#endif]) +]) diff --git a/m4/fcntl-o.m4 b/m4/fcntl-o.m4 new file mode 100644 index 000000000..87cc4bd2d --- /dev/null +++ b/m4/fcntl-o.m4 @@ -0,0 +1,134 @@ +# fcntl-o.m4 serial 4 +dnl Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +# Test whether the flags O_NOATIME and O_NOFOLLOW actually work. +# Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. +# Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. +AC_DEFUN([gl_FCNTL_O_FLAGS], +[ + dnl Persuade glibc to define O_NOATIME and O_NOFOLLOW. + dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes + dnl AC_GNU_SOURCE. + m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], + [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], + [AC_REQUIRE([AC_GNU_SOURCE])]) + + AC_CHECK_HEADERS_ONCE([unistd.h]) + AC_CHECK_FUNCS_ONCE([symlink]) + AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + #if HAVE_UNISTD_H + # include + #else /* on Windows with MSVC */ + # include + # include + # defined sleep(n) _sleep ((n) * 1000) + #endif + #include + #ifndef O_NOATIME + #define O_NOATIME 0 + #endif + #ifndef O_NOFOLLOW + #define O_NOFOLLOW 0 + #endif + static int const constants[] = + { + O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, + O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY + }; + ]], + [[ + int result = !constants; + #if HAVE_SYMLINK + { + static char const sym[] = "conftest.sym"; + if (symlink ("/dev/null", sym) != 0) + result |= 2; + else + { + int fd = open (sym, O_WRONLY | O_NOFOLLOW | O_CREAT, 0); + if (fd >= 0) + { + close (fd); + result |= 4; + } + } + if (unlink (sym) != 0 || symlink (".", sym) != 0) + result |= 2; + else + { + int fd = open (sym, O_RDONLY | O_NOFOLLOW); + if (fd >= 0) + { + close (fd); + result |= 4; + } + } + unlink (sym); + } + #endif + { + static char const file[] = "confdefs.h"; + int fd = open (file, O_RDONLY | O_NOATIME); + if (fd < 0) + result |= 8; + else + { + struct stat st0; + if (fstat (fd, &st0) != 0) + result |= 16; + else + { + char c; + sleep (1); + if (read (fd, &c, 1) != 1) + result |= 24; + else + { + if (close (fd) != 0) + result |= 32; + else + { + struct stat st1; + if (stat (file, &st1) != 0) + result |= 40; + else + if (st0.st_atime != st1.st_atime) + result |= 64; + } + } + } + } + } + return result;]])], + [gl_cv_header_working_fcntl_h=yes], + [case $? in #( + 4) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( + 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( + 68) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( + *) gl_cv_header_working_fcntl_h='no';; + esac], + [gl_cv_header_working_fcntl_h=cross-compiling])]) + + case $gl_cv_header_working_fcntl_h in #( + *O_NOATIME* | no | cross-compiling) ac_val=0;; #( + *) ac_val=1;; + esac + AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val], + [Define to 1 if O_NOATIME works.]) + + case $gl_cv_header_working_fcntl_h in #( + *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #( + *) ac_val=1;; + esac + AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val], + [Define to 1 if O_NOFOLLOW works.]) +]) diff --git a/m4/float_h.m4 b/m4/float_h.m4 new file mode 100644 index 000000000..397f2d1fa --- /dev/null +++ b/m4/float_h.m4 @@ -0,0 +1,98 @@ +# float_h.m4 serial 9 +dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FLOAT_H], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + FLOAT_H= + REPLACE_FLOAT_LDBL=0 + case "$host_os" in + aix* | beos* | openbsd* | mirbsd* | irix*) + FLOAT_H=float.h + ;; + freebsd*) + case "$host_cpu" in +changequote(,)dnl + i[34567]86 ) +changequote([,])dnl + FLOAT_H=float.h + ;; + x86_64 ) + # On x86_64 systems, the C compiler may still be generating + # 32-bit code. + AC_EGREP_CPP([yes], + [#if defined __LP64__ || defined __x86_64__ || defined __amd64__ + yes + #endif], + [], + [FLOAT_H=float.h]) + ;; + esac + ;; + linux*) + case "$host_cpu" in + powerpc*) + FLOAT_H=float.h + ;; + esac + ;; + esac + case "$host_os" in + aix* | freebsd* | linux*) + if test -n "$FLOAT_H"; then + REPLACE_FLOAT_LDBL=1 + fi + ;; + esac + + dnl Test against glibc-2.7 Linux/SPARC64 bug. + REPLACE_ITOLD=0 + AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works], + [gl_cv_func_itold_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +int i = -1; +volatile long double ld; +int main () +{ + ld += i * 1.0L; + if (ld > 0) + return 1; + return 0; +}]])], + [gl_cv_func_itold_works=yes], + [gl_cv_func_itold_works=no], + [case "$host" in + sparc*-*-linux*) + AC_EGREP_CPP([yes], + [#if defined __LP64__ || defined __arch64__ + yes + #endif], + [gl_cv_func_itold_works="guessing no"], + [gl_cv_func_itold_works="guessing yes"]) + ;; + *) gl_cv_func_itold_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_itold_works" in + *no) + REPLACE_ITOLD=1 + dnl We add the workaround to but also to , + dnl to increase the chances that the fix function gets pulled in. + FLOAT_H=float.h + ;; + esac + + if test -n "$FLOAT_H"; then + gl_NEXT_HEADERS([float.h]) + fi + AC_SUBST([FLOAT_H]) + AM_CONDITIONAL([GL_GENERATE_FLOAT_H], [test -n "$FLOAT_H"]) + AC_SUBST([REPLACE_ITOLD]) +]) diff --git a/m4/fnmatch.m4 b/m4/fnmatch.m4 new file mode 100644 index 000000000..fa0ba4d22 --- /dev/null +++ b/m4/fnmatch.m4 @@ -0,0 +1,156 @@ +# Check for fnmatch - serial 9. + +# Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Autoconf defines AC_FUNC_FNMATCH, but that is obsolescent. +# New applications should use the macros below instead. + +# Request a POSIX compliant fnmatch function. +AC_DEFUN([gl_FUNC_FNMATCH_POSIX], +[ + m4_divert_text([DEFAULTS], [gl_fnmatch_required=POSIX]) + + dnl Persuade glibc to declare FNM_CASEFOLD etc. + dnl This is only needed if gl_fnmatch_required = GNU. It would be possible + dnl to avoid this dependency for gl_FUNC_FNMATCH_POSIX by putting + dnl gl_FUNC_FNMATCH_GNU into a separate .m4 file. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + FNMATCH_H= + gl_fnmatch_required_lowercase=` + echo $gl_fnmatch_required | LC_ALL=C tr '[[A-Z]]' '[[a-z]]' + ` + gl_fnmatch_cache_var="gl_cv_func_fnmatch_${gl_fnmatch_required_lowercase}" + AC_CACHE_CHECK([for working $gl_fnmatch_required fnmatch], + [$gl_fnmatch_cache_var], + [dnl Some versions of Solaris, SCO, and the GNU C Library + dnl have a broken or incompatible fnmatch. + dnl So we run a test program. If we are cross-compiling, take no chance. + dnl Thanks to John Oleynick, François Pinard, and Paul Eggert for this + dnl test. + if test $gl_fnmatch_required = GNU; then + gl_fnmatch_gnu_start= + gl_fnmatch_gnu_end= + else + gl_fnmatch_gnu_start='#if 0' + gl_fnmatch_gnu_end='#endif' + fi + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + static int + y (char const *pattern, char const *string, int flags) + { + return fnmatch (pattern, string, flags) == 0; + } + static int + n (char const *pattern, char const *string, int flags) + { + return fnmatch (pattern, string, flags) == FNM_NOMATCH; + } + ]], + [[char const *Apat = 'A' < '\\\\' ? "[A-\\\\\\\\]" : "[\\\\\\\\-A]"; + char const *apat = 'a' < '\\\\' ? "[a-\\\\\\\\]" : "[\\\\\\\\-a]"; + static char const A_1[] = { 'A' - 1, 0 }; + static char const A01[] = { 'A' + 1, 0 }; + static char const a_1[] = { 'a' - 1, 0 }; + static char const a01[] = { 'a' + 1, 0 }; + static char const bs_1[] = { '\\\\' - 1, 0 }; + static char const bs01[] = { '\\\\' + 1, 0 }; + int result = 0; + if (!n ("a*", "", 0)) + return 1; + if (!y ("a*", "abc", 0)) + return 1; + if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */ + return 1; + if (!n ("d*/*1", "d/s/1", FNM_PATHNAME)) + return 2; + if (!y ("a\\\\bc", "abc", 0)) + return 3; + if (!n ("a\\\\bc", "abc", FNM_NOESCAPE)) + return 3; + if (!y ("*x", ".x", 0)) + return 4; + if (!n ("*x", ".x", FNM_PERIOD)) + return 4; + if (!y (Apat, "\\\\", 0)) + return 5; + if (!y (Apat, "A", 0)) + return 5; + if (!y (apat, "\\\\", 0)) + return 5; + if (!y (apat, "a", 0)) + return 5; + if (!(n (Apat, A_1, 0) == ('A' < '\\\\'))) + return 5; + if (!(n (apat, a_1, 0) == ('a' < '\\\\'))) + return 5; + if (!(y (Apat, A01, 0) == ('A' < '\\\\'))) + return 5; + if (!(y (apat, a01, 0) == ('a' < '\\\\'))) + return 5; + if (!(y (Apat, bs_1, 0) == ('A' < '\\\\'))) + return 5; + if (!(y (apat, bs_1, 0) == ('a' < '\\\\'))) + return 5; + if (!(n (Apat, bs01, 0) == ('A' < '\\\\'))) + return 5; + if (!(n (apat, bs01, 0) == ('a' < '\\\\'))) + return 5; + $gl_fnmatch_gnu_start + if (!y ("xxXX", "xXxX", FNM_CASEFOLD)) + result |= 8; + if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)) + result |= 16; + if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME)) + result |= 32; + if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)) + result |= 64; + if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)) + result |= 64; + if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)) + result |= 64; + $gl_fnmatch_gnu_end + return result; + ]])], + [eval "$gl_fnmatch_cache_var=yes"], + [eval "$gl_fnmatch_cache_var=no"], + [eval "$gl_fnmatch_cache_var=\"guessing no\""]) + ]) + eval "gl_fnmatch_result=\"\$$gl_fnmatch_cache_var\"" + if test "$gl_fnmatch_result" = yes; then + dnl Not strictly necessary. Only to avoid spurious leftover files if people + dnl don't do "make distclean". + rm -f "$gl_source_base/fnmatch.h" + else + FNMATCH_H=fnmatch.h + fi + AC_SUBST([FNMATCH_H]) + AM_CONDITIONAL([GL_GENERATE_FNMATCH_H], [test -n "$FNMATCH_H"]) +]) + +# Request a POSIX compliant fnmatch function with GNU extensions. +AC_DEFUN([gl_FUNC_FNMATCH_GNU], +[ + m4_divert_text([INIT_PREPARE], [gl_fnmatch_required=GNU]) + + AC_REQUIRE([gl_FUNC_FNMATCH_POSIX]) +]) + +AC_DEFUN([gl_PREREQ_FNMATCH], +[ + dnl We must choose a different name for our function, since on ELF systems + dnl a broken fnmatch() in libc.so would override our fnmatch() if it is + dnl compiled into a shared library. + AC_DEFINE_UNQUOTED([fnmatch], [${gl_fnmatch_required_lowercase}_fnmatch], + [Define to a replacement function name for fnmatch().]) + dnl Prerequisites of lib/fnmatch.c. + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + AC_CHECK_DECLS([isblank], [], [], [[#include ]]) + AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy]) + AC_CHECK_HEADERS_ONCE([wctype.h]) +]) diff --git a/m4/getdelim.m4 b/m4/getdelim.m4 new file mode 100644 index 000000000..36f66a108 --- /dev/null +++ b/m4/getdelim.m4 @@ -0,0 +1,88 @@ +# getdelim.m4 serial 10 + +dnl Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc. +dnl +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_PREREQ([2.59]) + +AC_DEFUN([gl_FUNC_GETDELIM], +[ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + + dnl Persuade glibc to declare getdelim(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS_ONCE([getdelim]) + + AC_CHECK_FUNCS_ONCE([getdelim]) + if test $ac_cv_func_getdelim = yes; then + HAVE_GETDELIM=1 + dnl Found it in some library. Verify that it works. + AC_CACHE_CHECK([for working getdelim function], [gl_cv_func_working_getdelim], + [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +# include +# include +# include + int main () + { + FILE *in = fopen ("./conftest.data", "r"); + if (!in) + return 1; + { + /* Test result for a NULL buffer and a zero size. + Based on a test program from Karl Heuer. */ + char *line = NULL; + size_t siz = 0; + int len = getdelim (&line, &siz, '\n', in); + if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) + return 2; + } + { + /* Test result for a NULL buffer and a non-zero size. + This crashes on FreeBSD 8.0. */ + char *line = NULL; + size_t siz = (size_t)(~0) / 4; + if (getdelim (&line, &siz, '\n', in) == -1) + return 3; + } + return 0; + } + ]])], [gl_cv_func_working_getdelim=yes] dnl The library version works. + , [gl_cv_func_working_getdelim=no] dnl The library version does NOT work. + , dnl We're cross compiling. Assume it works on glibc2 systems. + [AC_EGREP_CPP([Lucky GNU user], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ >= 2) && !defined __UCLIBC__ + Lucky GNU user + #endif +#endif + ], + [gl_cv_func_working_getdelim="guessing yes"], + [gl_cv_func_working_getdelim="guessing no"])] + )]) + case "$gl_cv_func_working_getdelim" in + *no) + REPLACE_GETDELIM=1 + ;; + esac + else + HAVE_GETDELIM=0 + fi + + if test $ac_cv_have_decl_getdelim = no; then + HAVE_DECL_GETDELIM=0 + fi +]) + +# Prerequisites of lib/getdelim.c. +AC_DEFUN([gl_PREREQ_GETDELIM], +[ + AC_CHECK_FUNCS([flockfile funlockfile]) + AC_CHECK_DECLS([getc_unlocked]) +]) diff --git a/m4/getline.m4 b/m4/getline.m4 new file mode 100644 index 000000000..342bc9905 --- /dev/null +++ b/m4/getline.m4 @@ -0,0 +1,96 @@ +# getline.m4 serial 26 + +dnl Copyright (C) 1998-2003, 2005-2007, 2009-2013 Free Software Foundation, +dnl Inc. +dnl +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_PREREQ([2.59]) + +dnl See if there's a working, system-supplied version of the getline function. +dnl We can't just do AC_REPLACE_FUNCS([getline]) because some systems +dnl have a function by that name in -linet that doesn't have anything +dnl to do with the function we need. +AC_DEFUN([gl_FUNC_GETLINE], +[ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + + dnl Persuade glibc to declare getline(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS_ONCE([getline]) + + gl_getline_needs_run_time_check=no + AC_CHECK_FUNC([getline], + [dnl Found it in some library. Verify that it works. + gl_getline_needs_run_time_check=yes], + [am_cv_func_working_getline=no]) + if test $gl_getline_needs_run_time_check = yes; then + AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline], + [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +# include +# include +# include + int main () + { + FILE *in = fopen ("./conftest.data", "r"); + if (!in) + return 1; + { + /* Test result for a NULL buffer and a zero size. + Based on a test program from Karl Heuer. */ + char *line = NULL; + size_t siz = 0; + int len = getline (&line, &siz, in); + if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) + return 2; + } + { + /* Test result for a NULL buffer and a non-zero size. + This crashes on FreeBSD 8.0. */ + char *line = NULL; + size_t siz = (size_t)(~0) / 4; + if (getline (&line, &siz, in) == -1) + return 3; + } + return 0; + } + ]])], [am_cv_func_working_getline=yes] dnl The library version works. + , [am_cv_func_working_getline=no] dnl The library version does NOT work. + , dnl We're cross compiling. Assume it works on glibc2 systems. + [AC_EGREP_CPP([Lucky GNU user], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ >= 2) && !defined __UCLIBC__ + Lucky GNU user + #endif +#endif + ], + [am_cv_func_working_getline="guessing yes"], + [am_cv_func_working_getline="guessing no"])] + )]) + fi + + if test $ac_cv_have_decl_getline = no; then + HAVE_DECL_GETLINE=0 + fi + + case "$am_cv_func_working_getline" in + *no) + dnl Set REPLACE_GETLINE always: Even if we have not found the broken + dnl getline function among $LIBS, it may exist in libinet and the + dnl executable may be linked with -linet. + REPLACE_GETLINE=1 + ;; + esac +]) + +# Prerequisites of lib/getline.c. +AC_DEFUN([gl_PREREQ_GETLINE], +[ + : +]) diff --git a/m4/getopt.m4 b/m4/getopt.m4 new file mode 100644 index 000000000..50f450919 --- /dev/null +++ b/m4/getopt.m4 @@ -0,0 +1,368 @@ +# getopt.m4 serial 44 +dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Request a POSIX compliant getopt function. +AC_DEFUN([gl_FUNC_GETOPT_POSIX], +[ + m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX]) + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([gl_GETOPT_CHECK_HEADERS]) + dnl Other modules can request the gnulib implementation of the getopt + dnl functions unconditionally, by defining gl_REPLACE_GETOPT_ALWAYS. + dnl argp.m4 does this. + m4_ifdef([gl_REPLACE_GETOPT_ALWAYS], [ + REPLACE_GETOPT=1 + ], [ + REPLACE_GETOPT=0 + if test -n "$gl_replace_getopt"; then + REPLACE_GETOPT=1 + fi + ]) + if test $REPLACE_GETOPT = 1; then + dnl Arrange for getopt.h to be created. + gl_GETOPT_SUBSTITUTE_HEADER + fi +]) + +# Request a POSIX compliant getopt function with GNU extensions (such as +# options with optional arguments) and the functions getopt_long, +# getopt_long_only. +AC_DEFUN([gl_FUNC_GETOPT_GNU], +[ + m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU]) + + AC_REQUIRE([gl_FUNC_GETOPT_POSIX]) +]) + +# Determine whether to replace the entire getopt facility. +AC_DEFUN([gl_GETOPT_CHECK_HEADERS], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([AC_PROG_AWK]) dnl for awk that supports ENVIRON + + dnl Persuade Solaris to declare optarg, optind, opterr, optopt. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + gl_CHECK_NEXT_HEADERS([getopt.h]) + if test $ac_cv_header_getopt_h = yes; then + HAVE_GETOPT_H=1 + else + HAVE_GETOPT_H=0 + fi + AC_SUBST([HAVE_GETOPT_H]) + + gl_replace_getopt= + + dnl Test whether is available. + if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then + AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes]) + fi + + dnl Test whether the function getopt_long is available. + if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then + AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes]) + fi + + dnl POSIX 2008 does not specify leading '+' behavior, but see + dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on + dnl the next version of POSIX. For now, we only guarantee leading '+' + dnl behavior with getopt-gnu. + if test -z "$gl_replace_getopt"; then + AC_CACHE_CHECK([whether getopt is POSIX compatible], + [gl_cv_func_getopt_posix], + [ + dnl Merging these three different test programs into a single one + dnl would require a reset mechanism. On BSD systems, it can be done + dnl through 'optreset'; on some others (glibc), it can be done by + dnl setting 'optind' to 0; on others again (HP-UX, IRIX, OSF/1, + dnl Solaris 9, musl libc), there is no such mechanism. + if test $cross_compiling = no; then + dnl Sanity check. Succeeds everywhere (except on MSVC, + dnl which lacks and getopt() entirely). + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include + +int +main () +{ + static char program[] = "program"; + static char a[] = "-a"; + static char foo[] = "foo"; + static char bar[] = "bar"; + char *argv[] = { program, a, foo, bar, NULL }; + int c; + + c = getopt (4, argv, "ab"); + if (!(c == 'a')) + return 1; + c = getopt (4, argv, "ab"); + if (!(c == -1)) + return 2; + if (!(optind == 2)) + return 3; + return 0; +} +]])], + [gl_cv_func_getopt_posix=maybe], + [gl_cv_func_getopt_posix=no]) + if test $gl_cv_func_getopt_posix = maybe; then + dnl Sanity check with '+'. Succeeds everywhere (except on MSVC, + dnl which lacks and getopt() entirely). + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include + +int +main () +{ + static char program[] = "program"; + static char donald[] = "donald"; + static char p[] = "-p"; + static char billy[] = "billy"; + static char duck[] = "duck"; + static char a[] = "-a"; + static char bar[] = "bar"; + char *argv[] = { program, donald, p, billy, duck, a, bar, NULL }; + int c; + + c = getopt (7, argv, "+abp:q:"); + if (!(c == -1)) + return 4; + if (!(strcmp (argv[0], "program") == 0)) + return 5; + if (!(strcmp (argv[1], "donald") == 0)) + return 6; + if (!(strcmp (argv[2], "-p") == 0)) + return 7; + if (!(strcmp (argv[3], "billy") == 0)) + return 8; + if (!(strcmp (argv[4], "duck") == 0)) + return 9; + if (!(strcmp (argv[5], "-a") == 0)) + return 10; + if (!(strcmp (argv[6], "bar") == 0)) + return 11; + if (!(optind == 1)) + return 12; + return 0; +} +]])], + [gl_cv_func_getopt_posix=maybe], + [gl_cv_func_getopt_posix=no]) + fi + if test $gl_cv_func_getopt_posix = maybe; then + dnl Detect Mac OS X 10.5, AIX 7.1, mingw bug. + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include + +int +main () +{ + static char program[] = "program"; + static char ab[] = "-ab"; + char *argv[3] = { program, ab, NULL }; + if (getopt (2, argv, "ab:") != 'a') + return 13; + if (getopt (2, argv, "ab:") != '?') + return 14; + if (optopt != 'b') + return 15; + if (optind != 2) + return 16; + return 0; +} +]])], + [gl_cv_func_getopt_posix=yes], + [gl_cv_func_getopt_posix=no]) + fi + else + case "$host_os" in + darwin* | aix* | mingw*) gl_cv_func_getopt_posix="guessing no";; + *) gl_cv_func_getopt_posix="guessing yes";; + esac + fi + ]) + case "$gl_cv_func_getopt_posix" in + *no) gl_replace_getopt=yes ;; + esac + fi + + if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then + AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_getopt_gnu], + [# Even with POSIXLY_CORRECT, the GNU extension of leading '-' in the + # optstring is necessary for programs like m4 that have POSIX-mandated + # semantics for supporting options interspersed with files. + # Also, since getopt_long is a GNU extension, we require optind=0. + # Bash ties 'set -o posix' to a non-exported POSIXLY_CORRECT; + # so take care to revert to the correct (non-)export state. +dnl GNU Coding Standards currently allow awk but not env; besides, env +dnl is ambiguous with environment values that contain newlines. + gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }' + case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" + #include + #include + ]GL_NOCRASH[ + ]], [[ + int result = 0; + + nocrash_init(); + + /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw, + and fails on Mac OS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5, + OSF/1 5.1, Solaris 10. */ + { + static char conftest[] = "conftest"; + static char plus[] = "-+"; + char *argv[3] = { conftest, plus, NULL }; + opterr = 0; + if (getopt (2, argv, "+a") != '?') + result |= 1; + } + /* This code succeeds on glibc 2.8, mingw, + and fails on Mac OS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11, + IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x. */ + { + static char program[] = "program"; + static char p[] = "-p"; + static char foo[] = "foo"; + static char bar[] = "bar"; + char *argv[] = { program, p, foo, bar, NULL }; + + optind = 1; + if (getopt (4, argv, "p::") != 'p') + result |= 2; + else if (optarg != NULL) + result |= 4; + else if (getopt (4, argv, "p::") != -1) + result |= 6; + else if (optind != 2) + result |= 8; + } + /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */ + { + static char program[] = "program"; + static char foo[] = "foo"; + static char p[] = "-p"; + char *argv[] = { program, foo, p, NULL }; + optind = 0; + if (getopt (3, argv, "-p") != 1) + result |= 16; + else if (getopt (3, argv, "-p") != 'p') + result |= 16; + } + /* This code fails on glibc 2.11. */ + { + static char program[] = "program"; + static char b[] = "-b"; + static char a[] = "-a"; + char *argv[] = { program, b, a, NULL }; + optind = opterr = 0; + if (getopt (3, argv, "+:a:b") != 'b') + result |= 32; + else if (getopt (3, argv, "+:a:b") != ':') + result |= 32; + } + /* This code dumps core on glibc 2.14. */ + { + static char program[] = "program"; + static char w[] = "-W"; + static char dummy[] = "dummy"; + char *argv[] = { program, w, dummy, NULL }; + optind = opterr = 1; + if (getopt (3, argv, "W;") != 'W') + result |= 64; + } + return result; + ]])], + [gl_cv_func_getopt_gnu=yes], + [gl_cv_func_getopt_gnu=no], + [dnl Cross compiling. Assume the worst, even on glibc platforms. + gl_cv_func_getopt_gnu="guessing no" + ]) + case $gl_had_POSIXLY_CORRECT in + exported) ;; + yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;; + *) AS_UNSET([POSIXLY_CORRECT]) ;; + esac + ]) + if test "$gl_cv_func_getopt_gnu" != yes; then + gl_replace_getopt=yes + else + AC_CACHE_CHECK([for working GNU getopt_long function], + [gl_cv_func_getopt_long_gnu], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + #include + ]], + [[static const struct option long_options[] = + { + { "xtremely-",no_argument, NULL, 1003 }, + { "xtra", no_argument, NULL, 1001 }, + { "xtreme", no_argument, NULL, 1002 }, + { "xtremely", no_argument, NULL, 1003 }, + { NULL, 0, NULL, 0 } + }; + /* This code fails on OpenBSD 5.0. */ + { + static char program[] = "program"; + static char xtremel[] = "--xtremel"; + char *argv[] = { program, xtremel, NULL }; + int option_index; + optind = 1; opterr = 0; + if (getopt_long (2, argv, "", long_options, &option_index) != 1003) + return 1; + } + return 0; + ]])], + [gl_cv_func_getopt_long_gnu=yes], + [gl_cv_func_getopt_long_gnu=no], + [dnl Cross compiling. Guess no on OpenBSD, yes otherwise. + case "$host_os" in + openbsd*) gl_cv_func_getopt_long_gnu="guessing no";; + *) gl_cv_func_getopt_long_gnu="guessing yes";; + esac + ]) + ]) + case "$gl_cv_func_getopt_long_gnu" in + *yes) ;; + *) gl_replace_getopt=yes ;; + esac + fi + fi +]) + +AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], +[ + GETOPT_H=getopt.h + AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], + [Define to rpl_ if the getopt replacement functions and variables + should be used.]) + AC_SUBST([GETOPT_H]) +]) + +# Prerequisites of lib/getopt*. +AC_DEFUN([gl_PREREQ_GETOPT], +[ + AC_CHECK_DECLS_ONCE([getenv]) +]) diff --git a/m4/gettext.m4 b/m4/gettext.m4 new file mode 100644 index 000000000..8d1f0665c --- /dev/null +++ b/m4/gettext.m4 @@ -0,0 +1,401 @@ +# gettext.m4 serial 66 (gettext-0.18.2) +dnl Copyright (C) 1995-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995-2000. +dnl Bruno Haible , 2000-2006, 2008-2010. + +dnl Macro to add for using GNU gettext. + +dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). +dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The +dnl default (if it is not specified or empty) is 'no-libtool'. +dnl INTLSYMBOL should be 'external' for packages with no intl directory, +dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. +dnl If INTLSYMBOL is 'use-libtool', then a libtool library +dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, +dnl depending on --{enable,disable}-{shared,static} and on the presence of +dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library +dnl $(top_builddir)/intl/libintl.a will be created. +dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext +dnl implementations (in libc or libintl) without the ngettext() function +dnl will be ignored. If NEEDSYMBOL is specified and is +dnl 'need-formatstring-macros', then GNU gettext implementations that don't +dnl support the ISO C 99 formatstring macros will be ignored. +dnl INTLDIR is used to find the intl libraries. If empty, +dnl the value '$(top_builddir)/intl/' is used. +dnl +dnl The result of the configuration is one of three cases: +dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled +dnl and used. +dnl Catalog format: GNU --> install in $(datadir) +dnl Catalog extension: .mo after installation, .gmo in source tree +dnl 2) GNU gettext has been found in the system's C library. +dnl Catalog format: GNU --> install in $(datadir) +dnl Catalog extension: .mo after installation, .gmo in source tree +dnl 3) No internationalization, always use English msgid. +dnl Catalog format: none +dnl Catalog extension: none +dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. +dnl The use of .gmo is historical (it was needed to avoid overwriting the +dnl GNU format catalogs when building on a platform with an X/Open gettext), +dnl but we keep it in order not to force irrelevant filename changes on the +dnl maintainers. +dnl +AC_DEFUN([AM_GNU_GETTEXT], +[ + dnl Argument checking. + ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , + [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT +])])])])]) + ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old], + [AC_DIAGNOSE([obsolete], [Use of AM_GNU_GETTEXT without [external] argument is deprecated.])]) + ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , + [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT +])])])]) + define([gt_included_intl], + ifelse([$1], [external], + ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]), + [yes])) + define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) + gt_NEEDS_INIT + AM_GNU_GETTEXT_NEED([$2]) + + AC_REQUIRE([AM_PO_SUBDIRS])dnl + ifelse(gt_included_intl, yes, [ + AC_REQUIRE([AM_INTL_SUBDIR])dnl + ]) + + dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + + dnl Sometimes libintl requires libiconv, so first search for libiconv. + dnl Ideally we would do this search only after the + dnl if test "$USE_NLS" = "yes"; then + dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then + dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT + dnl the configure script would need to contain the same shell code + dnl again, outside any 'if'. There are two solutions: + dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. + dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. + dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not + dnl documented, we avoid it. + ifelse(gt_included_intl, yes, , [ + AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) + ]) + + dnl Sometimes, on Mac OS X, libintl requires linking with CoreFoundation. + gt_INTL_MACOSX + + dnl Set USE_NLS. + AC_REQUIRE([AM_NLS]) + + ifelse(gt_included_intl, yes, [ + BUILD_INCLUDED_LIBINTL=no + USE_INCLUDED_LIBINTL=no + ]) + LIBINTL= + LTLIBINTL= + POSUB= + + dnl Add a version number to the cache macros. + case " $gt_needs " in + *" need-formatstring-macros "*) gt_api_version=3 ;; + *" need-ngettext "*) gt_api_version=2 ;; + *) gt_api_version=1 ;; + esac + gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" + gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" + + dnl If we use NLS figure out what method + if test "$USE_NLS" = "yes"; then + gt_use_preinstalled_gnugettext=no + ifelse(gt_included_intl, yes, [ + AC_MSG_CHECKING([whether included gettext is requested]) + AC_ARG_WITH([included-gettext], + [ --with-included-gettext use the GNU gettext library included here], + nls_cv_force_use_gnu_gettext=$withval, + nls_cv_force_use_gnu_gettext=no) + AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext]) + + nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" + if test "$nls_cv_force_use_gnu_gettext" != "yes"; then + ]) + dnl User does not insist on using GNU NLS library. Figure out what + dnl to use. If GNU gettext is available we use this. Else we have + dnl to fall back to GNU NLS library. + + if test $gt_api_version -ge 3; then + gt_revision_test_code=' +#ifndef __GNU_GETTEXT_SUPPORTED_REVISION +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) +#endif +changequote(,)dnl +typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; +changequote([,])dnl +' + else + gt_revision_test_code= + fi + if test $gt_api_version -ge 2; then + gt_expression_test_code=' + * ngettext ("", "", 0)' + else + gt_expression_test_code= + fi + + AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +$gt_revision_test_code +extern int _nl_msg_cat_cntr; +extern int *_nl_domain_bindings; + ]], + [[ +bindtextdomain ("", ""); +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings + ]])], + [eval "$gt_func_gnugettext_libc=yes"], + [eval "$gt_func_gnugettext_libc=no"])]) + + if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then + dnl Sometimes libintl requires libiconv, so first search for libiconv. + ifelse(gt_included_intl, yes, , [ + AM_ICONV_LINK + ]) + dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL + dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) + dnl because that would add "-liconv" to LIBINTL and LTLIBINTL + dnl even if libiconv doesn't exist. + AC_LIB_LINKFLAGS_BODY([intl]) + AC_CACHE_CHECK([for GNU gettext in libintl], + [$gt_func_gnugettext_libintl], + [gt_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $INCINTL" + gt_save_LIBS="$LIBS" + LIBS="$LIBS $LIBINTL" + dnl Now see whether libintl exists and does not depend on libiconv. + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +$gt_revision_test_code +extern int _nl_msg_cat_cntr; +extern +#ifdef __cplusplus +"C" +#endif +const char *_nl_expand_alias (const char *); + ]], + [[ +bindtextdomain ("", ""); +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") + ]])], + [eval "$gt_func_gnugettext_libintl=yes"], + [eval "$gt_func_gnugettext_libintl=no"]) + dnl Now see whether libintl exists and depends on libiconv. + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then + LIBS="$LIBS $LIBICONV" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +$gt_revision_test_code +extern int _nl_msg_cat_cntr; +extern +#ifdef __cplusplus +"C" +#endif +const char *_nl_expand_alias (const char *); + ]], + [[ +bindtextdomain ("", ""); +return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") + ]])], + [LIBINTL="$LIBINTL $LIBICONV" + LTLIBINTL="$LTLIBINTL $LTLIBICONV" + eval "$gt_func_gnugettext_libintl=yes" + ]) + fi + CPPFLAGS="$gt_save_CPPFLAGS" + LIBS="$gt_save_LIBS"]) + fi + + dnl If an already present or preinstalled GNU gettext() is found, + dnl use it. But if this macro is used in GNU gettext, and GNU + dnl gettext is already preinstalled in libintl, we update this + dnl libintl. (Cf. the install rule in intl/Makefile.in.) + if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ + || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ + && test "$PACKAGE" != gettext-runtime \ + && test "$PACKAGE" != gettext-tools; }; then + gt_use_preinstalled_gnugettext=yes + else + dnl Reset the values set by searching for libintl. + LIBINTL= + LTLIBINTL= + INCINTL= + fi + + ifelse(gt_included_intl, yes, [ + if test "$gt_use_preinstalled_gnugettext" != "yes"; then + dnl GNU gettext is not found in the C library. + dnl Fall back on included GNU gettext library. + nls_cv_use_gnu_gettext=yes + fi + fi + + if test "$nls_cv_use_gnu_gettext" = "yes"; then + dnl Mark actions used to generate GNU NLS library. + BUILD_INCLUDED_LIBINTL=yes + USE_INCLUDED_LIBINTL=yes + LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" + LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" + LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` + fi + + CATOBJEXT= + if test "$gt_use_preinstalled_gnugettext" = "yes" \ + || test "$nls_cv_use_gnu_gettext" = "yes"; then + dnl Mark actions to use GNU gettext tools. + CATOBJEXT=.gmo + fi + ]) + + if test -n "$INTL_MACOSX_LIBS"; then + if test "$gt_use_preinstalled_gnugettext" = "yes" \ + || test "$nls_cv_use_gnu_gettext" = "yes"; then + dnl Some extra flags are needed during linking. + LIBINTL="$LIBINTL $INTL_MACOSX_LIBS" + LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS" + fi + fi + + if test "$gt_use_preinstalled_gnugettext" = "yes" \ + || test "$nls_cv_use_gnu_gettext" = "yes"; then + AC_DEFINE([ENABLE_NLS], [1], + [Define to 1 if translation of program messages to the user's native language + is requested.]) + else + USE_NLS=no + fi + fi + + AC_MSG_CHECKING([whether to use NLS]) + AC_MSG_RESULT([$USE_NLS]) + if test "$USE_NLS" = "yes"; then + AC_MSG_CHECKING([where the gettext function comes from]) + if test "$gt_use_preinstalled_gnugettext" = "yes"; then + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then + gt_source="external libintl" + else + gt_source="libc" + fi + else + gt_source="included intl directory" + fi + AC_MSG_RESULT([$gt_source]) + fi + + if test "$USE_NLS" = "yes"; then + + if test "$gt_use_preinstalled_gnugettext" = "yes"; then + if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then + AC_MSG_CHECKING([how to link with libintl]) + AC_MSG_RESULT([$LIBINTL]) + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) + fi + + dnl For backward compatibility. Some packages may be using this. + AC_DEFINE([HAVE_GETTEXT], [1], + [Define if the GNU gettext() function is already present or preinstalled.]) + AC_DEFINE([HAVE_DCGETTEXT], [1], + [Define if the GNU dcgettext() function is already present or preinstalled.]) + fi + + dnl We need to process the po/ directory. + POSUB=po + fi + + ifelse(gt_included_intl, yes, [ + dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL + dnl to 'yes' because some of the testsuite requires it. + if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then + BUILD_INCLUDED_LIBINTL=yes + fi + + dnl Make all variables we use known to autoconf. + AC_SUBST([BUILD_INCLUDED_LIBINTL]) + AC_SUBST([USE_INCLUDED_LIBINTL]) + AC_SUBST([CATOBJEXT]) + + dnl For backward compatibility. Some configure.ins may be using this. + nls_cv_header_intl= + nls_cv_header_libgt= + + dnl For backward compatibility. Some Makefiles may be using this. + DATADIRNAME=share + AC_SUBST([DATADIRNAME]) + + dnl For backward compatibility. Some Makefiles may be using this. + INSTOBJEXT=.mo + AC_SUBST([INSTOBJEXT]) + + dnl For backward compatibility. Some Makefiles may be using this. + GENCAT=gencat + AC_SUBST([GENCAT]) + + dnl For backward compatibility. Some Makefiles may be using this. + INTLOBJS= + if test "$USE_INCLUDED_LIBINTL" = yes; then + INTLOBJS="\$(GETTOBJS)" + fi + AC_SUBST([INTLOBJS]) + + dnl Enable libtool support if the surrounding package wishes it. + INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix + AC_SUBST([INTL_LIBTOOL_SUFFIX_PREFIX]) + ]) + + dnl For backward compatibility. Some Makefiles may be using this. + INTLLIBS="$LIBINTL" + AC_SUBST([INTLLIBS]) + + dnl Make all documented variables known to autoconf. + AC_SUBST([LIBINTL]) + AC_SUBST([LTLIBINTL]) + AC_SUBST([POSUB]) +]) + + +dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. +m4_define([gt_NEEDS_INIT], +[ + m4_divert_text([DEFAULTS], [gt_needs=]) + m4_define([gt_NEEDS_INIT], []) +]) + + +dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) +AC_DEFUN([AM_GNU_GETTEXT_NEED], +[ + m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) +]) + + +dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) +AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) diff --git a/m4/glibc2.m4 b/m4/glibc2.m4 new file mode 100644 index 000000000..0e5068266 --- /dev/null +++ b/m4/glibc2.m4 @@ -0,0 +1,31 @@ +# glibc2.m4 serial 3 +dnl Copyright (C) 2000-2002, 2004, 2008, 2010-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Test for the GNU C Library, version 2.0 or newer. +# From Bruno Haible. + +AC_DEFUN([gt_GLIBC2], + [ + AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer], + [ac_cv_gnu_library_2], + [AC_EGREP_CPP([Lucky GNU user], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ >= 2) && !defined __UCLIBC__ + Lucky GNU user + #endif +#endif + ], + [ac_cv_gnu_library_2=yes], + [ac_cv_gnu_library_2=no]) + ] + ) + AC_SUBST([GLIBC2]) + GLIBC2="$ac_cv_gnu_library_2" + ] +) diff --git a/m4/glibc21.m4 b/m4/glibc21.m4 new file mode 100644 index 000000000..613fb2a41 --- /dev/null +++ b/m4/glibc21.m4 @@ -0,0 +1,34 @@ +# glibc21.m4 serial 5 +dnl Copyright (C) 2000-2002, 2004, 2008, 2010-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Test for the GNU C Library, version 2.1 or newer, or uClibc. +# From Bruno Haible. + +AC_DEFUN([gl_GLIBC21], + [ + AC_CACHE_CHECK([whether we are using the GNU C Library >= 2.1 or uClibc], + [ac_cv_gnu_library_2_1], + [AC_EGREP_CPP([Lucky], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) + Lucky GNU user + #endif +#endif +#ifdef __UCLIBC__ + Lucky user +#endif + ], + [ac_cv_gnu_library_2_1=yes], + [ac_cv_gnu_library_2_1=no]) + ] + ) + AC_SUBST([GLIBC21]) + GLIBC21="$ac_cv_gnu_library_2_1" + ] +) diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 new file mode 100644 index 000000000..408918440 --- /dev/null +++ b/m4/gnulib-cache.m4 @@ -0,0 +1,55 @@ +# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this file. If not, see . +# +# As a special exception to the GNU General Public License, +# this file may be distributed as part of a program that +# contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the specification of how gnulib-tool is used. +# It acts as a cache: It is written and read by gnulib-tool. +# In projects that use version control, this file is meant to be put under +# version control, like the configure.ac and various Makefile.am files. + + +# Specification in the form of a command-line invocation: +# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex + +# Specification in the form of a few gnulib-tool.m4 macro invocations: +gl_LOCAL_DIR([]) +gl_MODULES([ + argp + error + fnmatch + getdelim + getline + gettext + progname + regex +]) +gl_AVOID([]) +gl_SOURCE_BASE([grub-core/gnulib]) +gl_M4_BASE([m4]) +gl_PO_BASE([]) +gl_DOC_BASE([doc]) +gl_TESTS_BASE([tests]) +gl_LIB([libgnu]) +gl_MAKEFILE_NAME([]) +gl_MACRO_PREFIX([gl]) +gl_PO_DOMAIN([]) +gl_WITNESS_C_MACRO([]) +gl_VC_FILES([false]) diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 new file mode 100644 index 000000000..0ae5a9ec6 --- /dev/null +++ b/m4/gnulib-common.m4 @@ -0,0 +1,377 @@ +# gnulib-common.m4 serial 33 +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_COMMON +# is expanded unconditionally through gnulib-tool magic. +AC_DEFUN([gl_COMMON], [ + dnl Use AC_REQUIRE here, so that the code is expanded once only. + AC_REQUIRE([gl_00GNULIB]) + AC_REQUIRE([gl_COMMON_BODY]) +]) +AC_DEFUN([gl_COMMON_BODY], [ + AH_VERBATIM([_Noreturn], +[/* The _Noreturn keyword of C11. */ +#if ! (defined _Noreturn \ + || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) +# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif +#endif +]) + AH_VERBATIM([isoc99_inline], +[/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports + the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of + earlier versions), but does not display it by setting __GNUC_STDC_INLINE__. + __APPLE__ && __MACH__ test for Mac OS X. + __APPLE_CC__ tests for the Apple compiler and its version. + __STDC_VERSION__ tests for the C99 mode. */ +#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__ +# define __GNUC_STDC_INLINE__ 1 +#endif]) + AH_VERBATIM([unused_parameter], +[/* Define as a marker that can be attached to declarations that might not + be used. This helps to reduce warnings, such as from + GCC -Wunused-parameter. */ +#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_UNUSED __attribute__ ((__unused__)) +#else +# define _GL_UNUSED +#endif +/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name + is a misnomer outside of parameter lists. */ +#define _UNUSED_PARAMETER_ _GL_UNUSED + +/* The __pure__ attribute was added in gcc 2.96. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) +# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +# define _GL_ATTRIBUTE_PURE /* empty */ +#endif + +/* The __const__ attribute was added in gcc 2.95. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) +# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) +#else +# define _GL_ATTRIBUTE_CONST /* empty */ +#endif +]) + dnl Preparation for running test programs: + dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not + dnl to /dev/tty, so they can be redirected to log files. Such diagnostics + dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N. + LIBC_FATAL_STDERR_=1 + export LIBC_FATAL_STDERR_ +]) + +# gl_MODULE_INDICATOR_CONDITION +# expands to a C preprocessor expression that evaluates to 1 or 0, depending +# whether a gnulib module that has been requested shall be considered present +# or not. +m4_define([gl_MODULE_INDICATOR_CONDITION], [1]) + +# gl_MODULE_INDICATOR_SET_VARIABLE([modulename]) +# sets the shell variable that indicates the presence of the given module to +# a C preprocessor expression that will evaluate to 1. +AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE], +[ + gl_MODULE_INDICATOR_SET_VARIABLE_AUX( + [GNULIB_[]m4_translit([[$1]], + [abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])], + [gl_MODULE_INDICATOR_CONDITION]) +]) + +# gl_MODULE_INDICATOR_SET_VARIABLE_AUX([variable]) +# modifies the shell variable to include the gl_MODULE_INDICATOR_CONDITION. +# The shell variable's value is a C preprocessor expression that evaluates +# to 0 or 1. +AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX], +[ + m4_if(m4_defn([gl_MODULE_INDICATOR_CONDITION]), [1], + [ + dnl Simplify the expression VALUE || 1 to 1. + $1=1 + ], + [gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([$1], + [gl_MODULE_INDICATOR_CONDITION])]) +]) + +# gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR([variable], [condition]) +# modifies the shell variable to include the given condition. The shell +# variable's value is a C preprocessor expression that evaluates to 0 or 1. +AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE_AUX_OR], +[ + dnl Simplify the expression 1 || CONDITION to 1. + if test "$[]$1" != 1; then + dnl Simplify the expression 0 || CONDITION to CONDITION. + if test "$[]$1" = 0; then + $1=$2 + else + $1="($[]$1 || $2)" + fi + fi +]) + +# gl_MODULE_INDICATOR([modulename]) +# defines a C macro indicating the presence of the given module +# in a location where it can be used. +# | Value | Value | +# | in lib/ | in tests/ | +# --------------------------------------------+---------+-----------+ +# Module present among main modules: | 1 | 1 | +# --------------------------------------------+---------+-----------+ +# Module present among tests-related modules: | 0 | 1 | +# --------------------------------------------+---------+-----------+ +# Module not present at all: | 0 | 0 | +# --------------------------------------------+---------+-----------+ +AC_DEFUN([gl_MODULE_INDICATOR], +[ + AC_DEFINE_UNQUOTED([GNULIB_]m4_translit([[$1]], + [abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), + [gl_MODULE_INDICATOR_CONDITION], + [Define to a C preprocessor expression that evaluates to 1 or 0, + depending whether the gnulib module $1 shall be considered present.]) +]) + +# gl_MODULE_INDICATOR_FOR_TESTS([modulename]) +# defines a C macro indicating the presence of the given module +# in lib or tests. This is useful to determine whether the module +# should be tested. +# | Value | Value | +# | in lib/ | in tests/ | +# --------------------------------------------+---------+-----------+ +# Module present among main modules: | 1 | 1 | +# --------------------------------------------+---------+-----------+ +# Module present among tests-related modules: | 1 | 1 | +# --------------------------------------------+---------+-----------+ +# Module not present at all: | 0 | 0 | +# --------------------------------------------+---------+-----------+ +AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], +[ + AC_DEFINE([GNULIB_TEST_]m4_translit([[$1]], + [abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1], + [Define to 1 when the gnulib module $1 should be tested.]) +]) + +# gl_ASSERT_NO_GNULIB_POSIXCHECK +# asserts that there will never be a need to #define GNULIB_POSIXCHECK. +# and thereby enables an optimization of configure and config.h. +# Used by Emacs. +AC_DEFUN([gl_ASSERT_NO_GNULIB_POSIXCHECK], +[ + dnl Override gl_WARN_ON_USE_PREPARE. + dnl But hide this definition from 'aclocal'. + AC_DEFUN([gl_W][ARN_ON_USE_PREPARE], []) +]) + +# gl_ASSERT_NO_GNULIB_TESTS +# asserts that there will be no gnulib tests in the scope of the configure.ac +# and thereby enables an optimization of config.h. +# Used by Emacs. +AC_DEFUN([gl_ASSERT_NO_GNULIB_TESTS], +[ + dnl Override gl_MODULE_INDICATOR_FOR_TESTS. + AC_DEFUN([gl_MODULE_INDICATOR_FOR_TESTS], []) +]) + +# Test whether exists. +# Set HAVE_FEATURES_H. +AC_DEFUN([gl_FEATURES_H], +[ + AC_CHECK_HEADERS_ONCE([features.h]) + if test $ac_cv_header_features_h = yes; then + HAVE_FEATURES_H=1 + else + HAVE_FEATURES_H=0 + fi + AC_SUBST([HAVE_FEATURES_H]) +]) + +# m4_foreach_w +# is a backport of autoconf-2.59c's m4_foreach_w. +# Remove this macro when we can assume autoconf >= 2.60. +m4_ifndef([m4_foreach_w], + [m4_define([m4_foreach_w], + [m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])]) + +# AS_VAR_IF(VAR, VALUE, [IF-MATCH], [IF-NOT-MATCH]) +# ---------------------------------------------------- +# Backport of autoconf-2.63b's macro. +# Remove this macro when we can assume autoconf >= 2.64. +m4_ifndef([AS_VAR_IF], +[m4_define([AS_VAR_IF], +[AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])]) + +# gl_PROG_CC_C99 +# Modifies the value of the shell variable CC in an attempt to make $CC +# understand ISO C99 source code. +# This is like AC_PROG_CC_C99, except that +# - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60, +# - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC +# , +# but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99 +# . +# Remaining problems: +# - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options +# to CC twice +# . +# - AC_PROG_CC_STDC is likely to change now that C11 is an ISO standard. +AC_DEFUN([gl_PROG_CC_C99], +[ + dnl Change that version number to the minimum Autoconf version that supports + dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls. + m4_version_prereq([9.0], + [AC_REQUIRE([AC_PROG_CC_C99])], + [AC_REQUIRE([AC_PROG_CC_STDC])]) +]) + +# gl_PROG_AR_RANLIB +# Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler. +# The user can set the variables AR, ARFLAGS, RANLIB if he wants to override +# the values. +AC_DEFUN([gl_PROG_AR_RANLIB], +[ + dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler + dnl as "cc", and GCC as "gcc". They have different object file formats and + dnl library formats. In particular, the GNU binutils programs ar, ranlib + dnl produce libraries that work only with gcc, not with cc. + AC_REQUIRE([AC_PROG_CC]) + AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler], + [ + AC_EGREP_CPP([Amsterdam], + [ +#ifdef __ACK__ +Amsterdam +#endif + ], + [gl_cv_c_amsterdam_compiler=yes], + [gl_cv_c_amsterdam_compiler=no]) + ]) + if test -z "$AR"; then + if test $gl_cv_c_amsterdam_compiler = yes; then + AR='cc -c.a' + if test -z "$ARFLAGS"; then + ARFLAGS='-o' + fi + else + dnl Use the Automake-documented default values for AR and ARFLAGS, + dnl but prefer ${host}-ar over ar (useful for cross-compiling). + AC_CHECK_TOOL([AR], [ar], [ar]) + if test -z "$ARFLAGS"; then + ARFLAGS='cru' + fi + fi + else + if test -z "$ARFLAGS"; then + ARFLAGS='cru' + fi + fi + AC_SUBST([AR]) + AC_SUBST([ARFLAGS]) + if test -z "$RANLIB"; then + if test $gl_cv_c_amsterdam_compiler = yes; then + RANLIB=':' + else + dnl Use the ranlib program if it is available. + AC_PROG_RANLIB + fi + fi + AC_SUBST([RANLIB]) +]) + +# AC_PROG_MKDIR_P +# is a backport of autoconf-2.60's AC_PROG_MKDIR_P, with a fix +# for interoperability with automake-1.9.6 from autoconf-2.62. +# Remove this macro when we can assume autoconf >= 2.62 or +# autoconf >= 2.60 && automake >= 1.10. +# AC_AUTOCONF_VERSION was introduced in 2.62, so use that as the witness. +m4_ifndef([AC_AUTOCONF_VERSION],[ +m4_ifdef([AC_PROG_MKDIR_P], [ + dnl For automake-1.9.6 && autoconf < 2.62: Ensure MKDIR_P is AC_SUBSTed. + m4_define([AC_PROG_MKDIR_P], + m4_defn([AC_PROG_MKDIR_P])[ + AC_SUBST([MKDIR_P])])], [ + dnl For autoconf < 2.60: Backport of AC_PROG_MKDIR_P. + AC_DEFUN_ONCE([AC_PROG_MKDIR_P], + [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake + MKDIR_P='$(mkdir_p)' + AC_SUBST([MKDIR_P])])]) +]) + +# AC_C_RESTRICT +# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61, +# so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++ +# works. +# This definition can be removed once autoconf >= 2.62 can be assumed. +# AC_AUTOCONF_VERSION was introduced in 2.62, so use that as the witness. +m4_ifndef([AC_AUTOCONF_VERSION],[ +AC_DEFUN([AC_C_RESTRICT], +[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], + [ac_cv_c_restrict=no + # The order here caters to the fact that C++ does not require restrict. + for ac_kw in __restrict __restrict__ _Restrict restrict; do + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[typedef int * int_ptr; + int foo (int_ptr $ac_kw ip) { + return ip[0]; + }]], + [[int s[1]; + int * $ac_kw t = s; + t[0] = 0; + return foo(t)]])], + [ac_cv_c_restrict=$ac_kw]) + test "$ac_cv_c_restrict" != no && break + done + ]) + AH_VERBATIM([restrict], +[/* Define to the equivalent of the C99 'restrict' keyword, or to + nothing if this is not supported. Do not define if restrict is + supported directly. */ +#undef restrict +/* Work around a bug in Sun C++: it does not support _Restrict, even + though the corresponding Sun C compiler does, which causes + "#define restrict _Restrict" in the previous line. Perhaps some future + version of Sun C++ will work with _Restrict; if so, it'll probably + define __RESTRICT, just as Sun C does. */ +#if defined __SUNPRO_CC && !defined __RESTRICT +# define _Restrict +#endif]) + case $ac_cv_c_restrict in + restrict) ;; + no) AC_DEFINE([restrict], []) ;; + *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; + esac +]) +]) + +# gl_BIGENDIAN +# is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd. +# Note that AC_REQUIRE([AC_C_BIGENDIAN]) does not work reliably because some +# macros invoke AC_C_BIGENDIAN with arguments. +AC_DEFUN([gl_BIGENDIAN], +[ + AC_C_BIGENDIAN +]) + +# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) +# is like AC_CACHE_VAL(cache-id, command-to-set-it), except that it does not +# output a spurious "(cached)" mark in the midst of other configure output. +# This macro should be used instead of AC_CACHE_VAL when it is not surrounded +# by an AC_MSG_CHECKING/AC_MSG_RESULT pair. +AC_DEFUN([gl_CACHE_VAL_SILENT], +[ + saved_as_echo_n="$as_echo_n" + as_echo_n=':' + AC_CACHE_VAL([$1], [$2]) + as_echo_n="$saved_as_echo_n" +]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 new file mode 100644 index 000000000..7a19f60d8 --- /dev/null +++ b/m4/gnulib-comp.m4 @@ -0,0 +1,756 @@ +# DO NOT EDIT! GENERATED AUTOMATICALLY! +# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this file. If not, see . +# +# As a special exception to the GNU General Public License, +# this file may be distributed as part of a program that +# contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the compiled summary of the specification in +# gnulib-cache.m4. It lists the computed macro invocations that need +# to be invoked from configure.ac. +# In projects that use version control, this file can be treated like +# other built files. + + +# This macro should be invoked from ./configure.ac, in the section +# "Checks for programs", right after AC_PROG_CC, and certainly before +# any checks for libraries, header files, types and library functions. +AC_DEFUN([gl_EARLY], +[ + m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace + m4_pattern_allow([^gl_ES$])dnl a valid locale name + m4_pattern_allow([^gl_LIBOBJS$])dnl a variable + m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable + AC_REQUIRE([gl_PROG_AR_RANLIB]) + AC_REQUIRE([AM_PROG_CC_C_O]) + # Code from module alloca: + # Code from module alloca-opt: + # Code from module argp: + # Code from module btowc: + # Code from module configmake: + # Code from module dirname-lgpl: + # Code from module dosname: + # Code from module double-slash-root: + # Code from module errno: + # Code from module error: + # Code from module extensions: + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + # Code from module extern-inline: + # Code from module float: + # Code from module fnmatch: + # Code from module getdelim: + # Code from module getline: + # Code from module getopt-gnu: + # Code from module getopt-posix: + # Code from module gettext: + # Code from module gettext-h: + # Code from module havelib: + # Code from module include_next: + # Code from module intprops: + # Code from module langinfo: + # Code from module localcharset: + # Code from module locale: + # Code from module localeconv: + # Code from module malloc-gnu: + # Code from module malloc-posix: + # Code from module mbrtowc: + # Code from module mbsinit: + # Code from module mbsrtowcs: + # Code from module mbswidth: + # Code from module mbtowc: + # Code from module memchr: + # Code from module mempcpy: + # Code from module msvc-inval: + # Code from module msvc-nothrow: + # Code from module multiarch: + # Code from module nl_langinfo: + # Code from module nocrash: + # Code from module progname: + # Code from module rawmemchr: + # Code from module realloc-posix: + # Code from module regex: + # Code from module size_max: + # Code from module sleep: + # Code from module snippet/_Noreturn: + # Code from module snippet/arg-nonnull: + # Code from module snippet/c++defs: + # Code from module snippet/warn-on-use: + # Code from module ssize_t: + # Code from module stdalign: + # Code from module stdbool: + # Code from module stddef: + # Code from module stdint: + # Code from module stdio: + # Code from module stdlib: + # Code from module strcase: + # Code from module strchrnul: + # Code from module streq: + # Code from module strerror: + # Code from module strerror-override: + # Code from module string: + # Code from module strings: + # Code from module strndup: + # Code from module strnlen: + # Code from module strnlen1: + # Code from module sys_types: + # Code from module sysexits: + # Code from module unistd: + # Code from module unitypes: + # Code from module uniwidth/base: + # Code from module uniwidth/width: + # Code from module vasnprintf: + # Code from module verify: + # Code from module vsnprintf: + # Code from module wchar: + # Code from module wcrtomb: + # Code from module wctype-h: + # Code from module wcwidth: + # Code from module xsize: +]) + +# This macro should be invoked from ./configure.ac, in the section +# "Check for header files, types and library functions". +AC_DEFUN([gl_INIT], +[ + AM_CONDITIONAL([GL_COND_LIBTOOL], [false]) + gl_cond_libtool=false + gl_libdeps= + gl_ltlibdeps= + gl_m4_base='m4' + m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) + m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) + m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) + m4_pushdef([gl_LIBSOURCES_LIST], []) + m4_pushdef([gl_LIBSOURCES_DIR], []) + gl_COMMON + gl_source_base='grub-core/gnulib' + gl_FUNC_ALLOCA + gl_ARGP + m4_ifdef([AM_XGETTEXT_OPTION], + [AM_][XGETTEXT_OPTION([--flag=argp_error:2:c-format]) + AM_][XGETTEXT_OPTION([--flag=argp_failure:4:c-format])]) + gl_FUNC_BTOWC + if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then + AC_LIBOBJ([btowc]) + gl_PREREQ_BTOWC + fi + gl_WCHAR_MODULE_INDICATOR([btowc]) + gl_CONFIGMAKE_PREP + gl_DIRNAME_LGPL + gl_DOUBLE_SLASH_ROOT + gl_HEADER_ERRNO_H + gl_ERROR + if test $ac_cv_lib_error_at_line = no; then + AC_LIBOBJ([error]) + gl_PREREQ_ERROR + fi + m4_ifdef([AM_XGETTEXT_OPTION], + [AM_][XGETTEXT_OPTION([--flag=error:3:c-format]) + AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])]) + AC_REQUIRE([gl_EXTERN_INLINE]) + gl_FLOAT_H + if test $REPLACE_FLOAT_LDBL = 1; then + AC_LIBOBJ([float]) + fi + if test $REPLACE_ITOLD = 1; then + AC_LIBOBJ([itold]) + fi + gl_FUNC_FNMATCH_POSIX + if test -n "$FNMATCH_H"; then + AC_LIBOBJ([fnmatch]) + gl_PREREQ_FNMATCH + fi + gl_FUNC_GETDELIM + if test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1; then + AC_LIBOBJ([getdelim]) + gl_PREREQ_GETDELIM + fi + gl_STDIO_MODULE_INDICATOR([getdelim]) + gl_FUNC_GETLINE + if test $REPLACE_GETLINE = 1; then + AC_LIBOBJ([getline]) + gl_PREREQ_GETLINE + fi + gl_STDIO_MODULE_INDICATOR([getline]) + gl_FUNC_GETOPT_GNU + if test $REPLACE_GETOPT = 1; then + AC_LIBOBJ([getopt]) + AC_LIBOBJ([getopt1]) + gl_PREREQ_GETOPT + dnl Arrange for unistd.h to include getopt.h. + GNULIB_GL_UNISTD_H_GETOPT=1 + fi + AC_SUBST([GNULIB_GL_UNISTD_H_GETOPT]) + gl_MODULE_INDICATOR_FOR_TESTS([getopt-gnu]) + gl_FUNC_GETOPT_POSIX + if test $REPLACE_GETOPT = 1; then + AC_LIBOBJ([getopt]) + AC_LIBOBJ([getopt1]) + gl_PREREQ_GETOPT + dnl Arrange for unistd.h to include getopt.h. + GNULIB_GL_UNISTD_H_GETOPT=1 + fi + AC_SUBST([GNULIB_GL_UNISTD_H_GETOPT]) + dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. + AM_GNU_GETTEXT_VERSION([0.18.1]) + AC_SUBST([LIBINTL]) + AC_SUBST([LTLIBINTL]) + gl_LANGINFO_H + gl_LOCALCHARSET + LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\"" + AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) + gl_LOCALE_H + gl_FUNC_LOCALECONV + if test $REPLACE_LOCALECONV = 1; then + AC_LIBOBJ([localeconv]) + gl_PREREQ_LOCALECONV + fi + gl_LOCALE_MODULE_INDICATOR([localeconv]) + gl_FUNC_MALLOC_GNU + if test $REPLACE_MALLOC = 1; then + AC_LIBOBJ([malloc]) + fi + gl_MODULE_INDICATOR([malloc-gnu]) + gl_FUNC_MALLOC_POSIX + if test $REPLACE_MALLOC = 1; then + AC_LIBOBJ([malloc]) + fi + gl_STDLIB_MODULE_INDICATOR([malloc-posix]) + gl_FUNC_MBRTOWC + if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then + AC_LIBOBJ([mbrtowc]) + gl_PREREQ_MBRTOWC + fi + gl_WCHAR_MODULE_INDICATOR([mbrtowc]) + gl_FUNC_MBSINIT + if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then + AC_LIBOBJ([mbsinit]) + gl_PREREQ_MBSINIT + fi + gl_WCHAR_MODULE_INDICATOR([mbsinit]) + gl_FUNC_MBSRTOWCS + if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then + AC_LIBOBJ([mbsrtowcs]) + AC_LIBOBJ([mbsrtowcs-state]) + gl_PREREQ_MBSRTOWCS + fi + gl_WCHAR_MODULE_INDICATOR([mbsrtowcs]) + gl_MBSWIDTH + gl_FUNC_MBTOWC + if test $REPLACE_MBTOWC = 1; then + AC_LIBOBJ([mbtowc]) + gl_PREREQ_MBTOWC + fi + gl_STDLIB_MODULE_INDICATOR([mbtowc]) + gl_FUNC_MEMCHR + if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then + AC_LIBOBJ([memchr]) + gl_PREREQ_MEMCHR + fi + gl_STRING_MODULE_INDICATOR([memchr]) + gl_FUNC_MEMPCPY + if test $HAVE_MEMPCPY = 0; then + AC_LIBOBJ([mempcpy]) + gl_PREREQ_MEMPCPY + fi + gl_STRING_MODULE_INDICATOR([mempcpy]) + gl_MSVC_INVAL + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + AC_LIBOBJ([msvc-inval]) + fi + gl_MSVC_NOTHROW + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + AC_LIBOBJ([msvc-nothrow]) + fi + gl_MULTIARCH + gl_FUNC_NL_LANGINFO + if test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1; then + AC_LIBOBJ([nl_langinfo]) + fi + gl_LANGINFO_MODULE_INDICATOR([nl_langinfo]) + AC_CHECK_DECLS([program_invocation_name], [], [], [#include ]) + AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include ]) + gl_FUNC_RAWMEMCHR + if test $HAVE_RAWMEMCHR = 0; then + AC_LIBOBJ([rawmemchr]) + gl_PREREQ_RAWMEMCHR + fi + gl_STRING_MODULE_INDICATOR([rawmemchr]) + gl_FUNC_REALLOC_POSIX + if test $REPLACE_REALLOC = 1; then + AC_LIBOBJ([realloc]) + fi + gl_STDLIB_MODULE_INDICATOR([realloc-posix]) + gl_REGEX + if test $ac_use_included_regex = yes; then + AC_LIBOBJ([regex]) + gl_PREREQ_REGEX + fi + gl_SIZE_MAX + gl_FUNC_SLEEP + if test $HAVE_SLEEP = 0 || test $REPLACE_SLEEP = 1; then + AC_LIBOBJ([sleep]) + fi + gl_UNISTD_MODULE_INDICATOR([sleep]) + gt_TYPE_SSIZE_T + gl_STDALIGN_H + AM_STDBOOL_H + gl_STDDEF_H + gl_STDINT_H + gl_STDIO_H + gl_STDLIB_H + gl_STRCASE + if test $HAVE_STRCASECMP = 0; then + AC_LIBOBJ([strcasecmp]) + gl_PREREQ_STRCASECMP + fi + if test $HAVE_STRNCASECMP = 0; then + AC_LIBOBJ([strncasecmp]) + gl_PREREQ_STRNCASECMP + fi + gl_FUNC_STRCHRNUL + if test $HAVE_STRCHRNUL = 0 || test $REPLACE_STRCHRNUL = 1; then + AC_LIBOBJ([strchrnul]) + gl_PREREQ_STRCHRNUL + fi + gl_STRING_MODULE_INDICATOR([strchrnul]) + gl_FUNC_STRERROR + if test $REPLACE_STRERROR = 1; then + AC_LIBOBJ([strerror]) + fi + gl_MODULE_INDICATOR([strerror]) + gl_STRING_MODULE_INDICATOR([strerror]) + AC_REQUIRE([gl_HEADER_ERRNO_H]) + AC_REQUIRE([gl_FUNC_STRERROR_0]) + if test -n "$ERRNO_H" || test $REPLACE_STRERROR_0 = 1; then + AC_LIBOBJ([strerror-override]) + gl_PREREQ_SYS_H_WINSOCK2 + fi + gl_HEADER_STRING_H + gl_HEADER_STRINGS_H + gl_FUNC_STRNDUP + if test $HAVE_STRNDUP = 0 || test $REPLACE_STRNDUP = 1; then + AC_LIBOBJ([strndup]) + fi + gl_STRING_MODULE_INDICATOR([strndup]) + gl_FUNC_STRNLEN + if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then + AC_LIBOBJ([strnlen]) + gl_PREREQ_STRNLEN + fi + gl_STRING_MODULE_INDICATOR([strnlen]) + gl_SYS_TYPES_H + AC_PROG_MKDIR_P + gl_SYSEXITS + gl_UNISTD_H + gl_LIBUNISTRING_LIBHEADER([0.9], [unitypes.h]) + gl_LIBUNISTRING_LIBHEADER([0.9], [uniwidth.h]) + gl_LIBUNISTRING_MODULE([0.9.4], [uniwidth/width]) + gl_FUNC_VASNPRINTF + gl_FUNC_VSNPRINTF + gl_STDIO_MODULE_INDICATOR([vsnprintf]) + gl_WCHAR_H + gl_FUNC_WCRTOMB + if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then + AC_LIBOBJ([wcrtomb]) + gl_PREREQ_WCRTOMB + fi + gl_WCHAR_MODULE_INDICATOR([wcrtomb]) + gl_WCTYPE_H + gl_FUNC_WCWIDTH + if test $HAVE_WCWIDTH = 0 || test $REPLACE_WCWIDTH = 1; then + AC_LIBOBJ([wcwidth]) + fi + gl_WCHAR_MODULE_INDICATOR([wcwidth]) + gl_XSIZE + # End of code from modules + m4_ifval(gl_LIBSOURCES_LIST, [ + m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || + for gl_file in ]gl_LIBSOURCES_LIST[ ; do + if test ! -r ]m4_defn([gl_LIBSOURCES_DIR])[/$gl_file ; then + echo "missing file ]m4_defn([gl_LIBSOURCES_DIR])[/$gl_file" >&2 + exit 1 + fi + done])dnl + m4_if(m4_sysval, [0], [], + [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) + ]) + m4_popdef([gl_LIBSOURCES_DIR]) + m4_popdef([gl_LIBSOURCES_LIST]) + m4_popdef([AC_LIBSOURCES]) + m4_popdef([AC_REPLACE_FUNCS]) + m4_popdef([AC_LIBOBJ]) + AC_CONFIG_COMMANDS_PRE([ + gl_libobjs= + gl_ltlibobjs= + if test -n "$gl_LIBOBJS"; then + # Remove the extension. + sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do + gl_libobjs="$gl_libobjs $i.$ac_objext" + gl_ltlibobjs="$gl_ltlibobjs $i.lo" + done + fi + AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) + AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) + ]) + gltests_libdeps= + gltests_ltlibdeps= + m4_pushdef([AC_LIBOBJ], m4_defn([gltests_LIBOBJ])) + m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gltests_REPLACE_FUNCS])) + m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES])) + m4_pushdef([gltests_LIBSOURCES_LIST], []) + m4_pushdef([gltests_LIBSOURCES_DIR], []) + gl_COMMON + gl_source_base='tests' +changequote(,)dnl + gltests_WITNESS=IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e 's/[^A-Z0-9_]/_/g'`_GNULIB_TESTS +changequote([, ])dnl + AC_SUBST([gltests_WITNESS]) + gl_module_indicator_condition=$gltests_WITNESS + m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition]) + m4_popdef([gl_MODULE_INDICATOR_CONDITION]) + m4_ifval(gltests_LIBSOURCES_LIST, [ + m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ || + for gl_file in ]gltests_LIBSOURCES_LIST[ ; do + if test ! -r ]m4_defn([gltests_LIBSOURCES_DIR])[/$gl_file ; then + echo "missing file ]m4_defn([gltests_LIBSOURCES_DIR])[/$gl_file" >&2 + exit 1 + fi + done])dnl + m4_if(m4_sysval, [0], [], + [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) + ]) + m4_popdef([gltests_LIBSOURCES_DIR]) + m4_popdef([gltests_LIBSOURCES_LIST]) + m4_popdef([AC_LIBSOURCES]) + m4_popdef([AC_REPLACE_FUNCS]) + m4_popdef([AC_LIBOBJ]) + AC_CONFIG_COMMANDS_PRE([ + gltests_libobjs= + gltests_ltlibobjs= + if test -n "$gltests_LIBOBJS"; then + # Remove the extension. + sed_drop_objext='s/\.o$//;s/\.obj$//' + for i in `for i in $gltests_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do + gltests_libobjs="$gltests_libobjs $i.$ac_objext" + gltests_ltlibobjs="$gltests_ltlibobjs $i.lo" + done + fi + AC_SUBST([gltests_LIBOBJS], [$gltests_libobjs]) + AC_SUBST([gltests_LTLIBOBJS], [$gltests_ltlibobjs]) + ]) + LIBGNU_LIBDEPS="$gl_libdeps" + AC_SUBST([LIBGNU_LIBDEPS]) + LIBGNU_LTLIBDEPS="$gl_ltlibdeps" + AC_SUBST([LIBGNU_LTLIBDEPS]) +]) + +# Like AC_LIBOBJ, except that the module name goes +# into gl_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gl_LIBOBJ], [ + AS_LITERAL_IF([$1], [gl_LIBSOURCES([$1.c])])dnl + gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext" +]) + +# Like AC_REPLACE_FUNCS, except that the module name goes +# into gl_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gl_REPLACE_FUNCS], [ + m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl + AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)]) +]) + +# Like AC_LIBSOURCES, except the directory where the source file is +# expected is derived from the gnulib-tool parameterization, +# and alloca is special cased (for the alloca-opt module). +# We could also entirely rely on EXTRA_lib..._SOURCES. +AC_DEFUN([gl_LIBSOURCES], [ + m4_foreach([_gl_NAME], [$1], [ + m4_if(_gl_NAME, [alloca.c], [], [ + m4_define([gl_LIBSOURCES_DIR], [grub-core/gnulib]) + m4_append([gl_LIBSOURCES_LIST], _gl_NAME, [ ]) + ]) + ]) +]) + +# Like AC_LIBOBJ, except that the module name goes +# into gltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gltests_LIBOBJ], [ + AS_LITERAL_IF([$1], [gltests_LIBSOURCES([$1.c])])dnl + gltests_LIBOBJS="$gltests_LIBOBJS $1.$ac_objext" +]) + +# Like AC_REPLACE_FUNCS, except that the module name goes +# into gltests_LIBOBJS instead of into LIBOBJS. +AC_DEFUN([gltests_REPLACE_FUNCS], [ + m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl + AC_CHECK_FUNCS([$1], , [gltests_LIBOBJ($ac_func)]) +]) + +# Like AC_LIBSOURCES, except the directory where the source file is +# expected is derived from the gnulib-tool parameterization, +# and alloca is special cased (for the alloca-opt module). +# We could also entirely rely on EXTRA_lib..._SOURCES. +AC_DEFUN([gltests_LIBSOURCES], [ + m4_foreach([_gl_NAME], [$1], [ + m4_if(_gl_NAME, [alloca.c], [], [ + m4_define([gltests_LIBSOURCES_DIR], [tests]) + m4_append([gltests_LIBSOURCES_LIST], _gl_NAME, [ ]) + ]) + ]) +]) + +# This macro records the list of files which have been installed by +# gnulib-tool and may be removed by future gnulib-tool invocations. +AC_DEFUN([gl_FILE_LIST], [ + build-aux/config.rpath + build-aux/snippet/_Noreturn.h + build-aux/snippet/arg-nonnull.h + build-aux/snippet/c++defs.h + build-aux/snippet/warn-on-use.h + lib/alloca.c + lib/alloca.in.h + lib/argp-ba.c + lib/argp-eexst.c + lib/argp-fmtstream.c + lib/argp-fmtstream.h + lib/argp-fs-xinl.c + lib/argp-help.c + lib/argp-namefrob.h + lib/argp-parse.c + lib/argp-pin.c + lib/argp-pv.c + lib/argp-pvh.c + lib/argp-xinl.c + lib/argp.h + lib/asnprintf.c + lib/basename-lgpl.c + lib/btowc.c + lib/config.charset + lib/dirname-lgpl.c + lib/dirname.h + lib/dosname.h + lib/errno.in.h + lib/error.c + lib/error.h + lib/float+.h + lib/float.c + lib/float.in.h + lib/fnmatch.c + lib/fnmatch.in.h + lib/fnmatch_loop.c + lib/getdelim.c + lib/getline.c + lib/getopt.c + lib/getopt.in.h + lib/getopt1.c + lib/getopt_int.h + lib/gettext.h + lib/intprops.h + lib/itold.c + lib/langinfo.in.h + lib/localcharset.c + lib/localcharset.h + lib/locale.in.h + lib/localeconv.c + lib/malloc.c + lib/mbrtowc.c + lib/mbsinit.c + lib/mbsrtowcs-impl.h + lib/mbsrtowcs-state.c + lib/mbsrtowcs.c + lib/mbswidth.c + lib/mbswidth.h + lib/mbtowc-impl.h + lib/mbtowc.c + lib/memchr.c + lib/memchr.valgrind + lib/mempcpy.c + lib/msvc-inval.c + lib/msvc-inval.h + lib/msvc-nothrow.c + lib/msvc-nothrow.h + lib/nl_langinfo.c + lib/printf-args.c + lib/printf-args.h + lib/printf-parse.c + lib/printf-parse.h + lib/progname.c + lib/progname.h + lib/rawmemchr.c + lib/rawmemchr.valgrind + lib/realloc.c + lib/ref-add.sin + lib/ref-del.sin + lib/regcomp.c + lib/regex.c + lib/regex.h + lib/regex_internal.c + lib/regex_internal.h + lib/regexec.c + lib/size_max.h + lib/sleep.c + lib/stdalign.in.h + lib/stdbool.in.h + lib/stddef.in.h + lib/stdint.in.h + lib/stdio.in.h + lib/stdlib.in.h + lib/strcasecmp.c + lib/strchrnul.c + lib/strchrnul.valgrind + lib/streq.h + lib/strerror-override.c + lib/strerror-override.h + lib/strerror.c + lib/string.in.h + lib/strings.in.h + lib/stripslash.c + lib/strncasecmp.c + lib/strndup.c + lib/strnlen.c + lib/strnlen1.c + lib/strnlen1.h + lib/sys_types.in.h + lib/sysexits.in.h + lib/unistd.c + lib/unistd.in.h + lib/unitypes.in.h + lib/uniwidth.in.h + lib/uniwidth/cjk.h + lib/uniwidth/width.c + lib/vasnprintf.c + lib/vasnprintf.h + lib/verify.h + lib/vsnprintf.c + lib/wchar.in.h + lib/wcrtomb.c + lib/wctype-h.c + lib/wctype.in.h + lib/wcwidth.c + lib/xsize.c + lib/xsize.h + m4/00gnulib.m4 + m4/alloca.m4 + m4/argp.m4 + m4/btowc.m4 + m4/codeset.m4 + m4/configmake.m4 + m4/dirname.m4 + m4/double-slash-root.m4 + m4/eealloc.m4 + m4/errno_h.m4 + m4/error.m4 + m4/exponentd.m4 + m4/extensions.m4 + m4/extern-inline.m4 + m4/fcntl-o.m4 + m4/float_h.m4 + m4/fnmatch.m4 + m4/getdelim.m4 + m4/getline.m4 + m4/getopt.m4 + m4/gettext.m4 + m4/glibc2.m4 + m4/glibc21.m4 + m4/gnulib-common.m4 + m4/iconv.m4 + m4/include_next.m4 + m4/intdiv0.m4 + m4/intl.m4 + m4/intldir.m4 + m4/intlmacosx.m4 + m4/intmax.m4 + m4/intmax_t.m4 + m4/inttypes-pri.m4 + m4/inttypes_h.m4 + m4/langinfo_h.m4 + m4/lcmessage.m4 + m4/lib-ld.m4 + m4/lib-link.m4 + m4/lib-prefix.m4 + m4/libunistring-base.m4 + m4/localcharset.m4 + m4/locale-fr.m4 + m4/locale-ja.m4 + m4/locale-zh.m4 + m4/locale_h.m4 + m4/localeconv.m4 + m4/lock.m4 + m4/longlong.m4 + m4/malloc.m4 + m4/math_h.m4 + m4/mbrtowc.m4 + m4/mbsinit.m4 + m4/mbsrtowcs.m4 + m4/mbstate_t.m4 + m4/mbswidth.m4 + m4/mbtowc.m4 + m4/memchr.m4 + m4/mempcpy.m4 + m4/mmap-anon.m4 + m4/msvc-inval.m4 + m4/msvc-nothrow.m4 + m4/multiarch.m4 + m4/nl_langinfo.m4 + m4/nls.m4 + m4/nocrash.m4 + m4/off_t.m4 + m4/po.m4 + m4/printf-posix.m4 + m4/printf.m4 + m4/progtest.m4 + m4/rawmemchr.m4 + m4/realloc.m4 + m4/regex.m4 + m4/size_max.m4 + m4/sleep.m4 + m4/ssize_t.m4 + m4/stdalign.m4 + m4/stdbool.m4 + m4/stddef_h.m4 + m4/stdint.m4 + m4/stdint_h.m4 + m4/stdio_h.m4 + m4/stdlib_h.m4 + m4/strcase.m4 + m4/strchrnul.m4 + m4/strerror.m4 + m4/string_h.m4 + m4/strings_h.m4 + m4/strndup.m4 + m4/strnlen.m4 + m4/sys_socket_h.m4 + m4/sys_types_h.m4 + m4/sysexits.m4 + m4/threadlib.m4 + m4/uintmax_t.m4 + m4/unistd_h.m4 + m4/vasnprintf.m4 + m4/visibility.m4 + m4/vsnprintf.m4 + m4/warn-on-use.m4 + m4/wchar_h.m4 + m4/wchar_t.m4 + m4/wcrtomb.m4 + m4/wctype_h.m4 + m4/wcwidth.m4 + m4/wint_t.m4 + m4/xsize.m4 +]) diff --git a/m4/gnulib-tool.m4 b/m4/gnulib-tool.m4 new file mode 100644 index 000000000..f3dea1a9f --- /dev/null +++ b/m4/gnulib-tool.m4 @@ -0,0 +1,57 @@ +# gnulib-tool.m4 serial 2 +dnl Copyright (C) 2004-2005, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl The following macros need not be invoked explicitly. +dnl Invoking them does nothing except to declare default arguments +dnl for "gnulib-tool --import". + +dnl Usage: gl_LOCAL_DIR([DIR]) +AC_DEFUN([gl_LOCAL_DIR], []) + +dnl Usage: gl_MODULES([module1 module2 ...]) +AC_DEFUN([gl_MODULES], []) + +dnl Usage: gl_AVOID([module1 module2 ...]) +AC_DEFUN([gl_AVOID], []) + +dnl Usage: gl_SOURCE_BASE([DIR]) +AC_DEFUN([gl_SOURCE_BASE], []) + +dnl Usage: gl_M4_BASE([DIR]) +AC_DEFUN([gl_M4_BASE], []) + +dnl Usage: gl_PO_BASE([DIR]) +AC_DEFUN([gl_PO_BASE], []) + +dnl Usage: gl_DOC_BASE([DIR]) +AC_DEFUN([gl_DOC_BASE], []) + +dnl Usage: gl_TESTS_BASE([DIR]) +AC_DEFUN([gl_TESTS_BASE], []) + +dnl Usage: gl_WITH_TESTS +AC_DEFUN([gl_WITH_TESTS], []) + +dnl Usage: gl_LIB([LIBNAME]) +AC_DEFUN([gl_LIB], []) + +dnl Usage: gl_LGPL or gl_LGPL([VERSION]) +AC_DEFUN([gl_LGPL], []) + +dnl Usage: gl_MAKEFILE_NAME([FILENAME]) +AC_DEFUN([gl_MAKEFILE_NAME], []) + +dnl Usage: gl_LIBTOOL +AC_DEFUN([gl_LIBTOOL], []) + +dnl Usage: gl_MACRO_PREFIX([PREFIX]) +AC_DEFUN([gl_MACRO_PREFIX], []) + +dnl Usage: gl_PO_DOMAIN([DOMAIN]) +AC_DEFUN([gl_PO_DOMAIN], []) + +dnl Usage: gl_VC_FILES([BOOLEAN]) +AC_DEFUN([gl_VC_FILES], []) diff --git a/m4/iconv.m4 b/m4/iconv.m4 new file mode 100644 index 000000000..a50364656 --- /dev/null +++ b/m4/iconv.m4 @@ -0,0 +1,268 @@ +# iconv.m4 serial 18 (gettext-0.18.2) +dnl Copyright (C) 2000-2002, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], +[ + dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + + dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV + dnl accordingly. + AC_LIB_LINKFLAGS_BODY([iconv]) +]) + +AC_DEFUN([AM_ICONV_LINK], +[ + dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and + dnl those with the standalone portable GNU libiconv installed). + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + + dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV + dnl accordingly. + AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) + + dnl Add $INCICONV to CPPFLAGS before performing the following checks, + dnl because if the user has installed libiconv and not disabled its use + dnl via --without-libiconv-prefix, he wants to use it. The first + dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed. + am_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) + + AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [ + am_cv_func_iconv="no, consider installing GNU libiconv" + am_cv_lib_iconv=no + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include + ]], + [[iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);]])], + [am_cv_func_iconv=yes]) + if test "$am_cv_func_iconv" != yes; then + am_save_LIBS="$LIBS" + LIBS="$LIBS $LIBICONV" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include + ]], + [[iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);]])], + [am_cv_lib_iconv=yes] + [am_cv_func_iconv=yes]) + LIBS="$am_save_LIBS" + fi + ]) + if test "$am_cv_func_iconv" = yes; then + AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [ + dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11, + dnl Solaris 10. + am_save_LIBS="$LIBS" + if test $am_cv_lib_iconv = yes; then + LIBS="$LIBS $LIBICONV" + fi + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +int main () +{ + int result = 0; + /* Test against AIX 5.1 bug: Failures are not distinguishable from successful + returns. */ + { + iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); + if (cd_utf8_to_88591 != (iconv_t)(-1)) + { + static const char input[] = "\342\202\254"; /* EURO SIGN */ + char buf[10]; + const char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_utf8_to_88591, + (char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res == 0) + result |= 1; + iconv_close (cd_utf8_to_88591); + } + } + /* Test against Solaris 10 bug: Failures are not distinguishable from + successful returns. */ + { + iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); + if (cd_ascii_to_88591 != (iconv_t)(-1)) + { + static const char input[] = "\263"; + char buf[10]; + const char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_ascii_to_88591, + (char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res == 0) + result |= 2; + iconv_close (cd_ascii_to_88591); + } + } + /* Test against AIX 6.1..7.1 bug: Buffer overrun. */ + { + iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); + if (cd_88591_to_utf8 != (iconv_t)(-1)) + { + static const char input[] = "\304"; + static char buf[2] = { (char)0xDE, (char)0xAD }; + const char *inptr = input; + size_t inbytesleft = 1; + char *outptr = buf; + size_t outbytesleft = 1; + size_t res = iconv (cd_88591_to_utf8, + (char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD) + result |= 4; + iconv_close (cd_88591_to_utf8); + } + } +#if 0 /* This bug could be worked around by the caller. */ + /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ + { + iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); + if (cd_88591_to_utf8 != (iconv_t)(-1)) + { + static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + char buf[50]; + const char *inptr = input; + size_t inbytesleft = strlen (input); + char *outptr = buf; + size_t outbytesleft = sizeof (buf); + size_t res = iconv (cd_88591_to_utf8, + (char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if ((int)res > 0) + result |= 8; + iconv_close (cd_88591_to_utf8); + } + } +#endif + /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is + provided. */ + if (/* Try standardized names. */ + iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) + /* Try IRIX, OSF/1 names. */ + && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) + /* Try AIX names. */ + && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) + /* Try HP-UX names. */ + && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) + result |= 16; + return result; +}]])], + [am_cv_func_iconv_works=yes], + [am_cv_func_iconv_works=no], + [ +changequote(,)dnl + case "$host_os" in + aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; + *) am_cv_func_iconv_works="guessing yes" ;; + esac +changequote([,])dnl + ]) + LIBS="$am_save_LIBS" + ]) + case "$am_cv_func_iconv_works" in + *no) am_func_iconv=no am_cv_lib_iconv=no ;; + *) am_func_iconv=yes ;; + esac + else + am_func_iconv=no am_cv_lib_iconv=no + fi + if test "$am_func_iconv" = yes; then + AC_DEFINE([HAVE_ICONV], [1], + [Define if you have the iconv() function and it works.]) + fi + if test "$am_cv_lib_iconv" = yes; then + AC_MSG_CHECKING([how to link with libiconv]) + AC_MSG_RESULT([$LIBICONV]) + else + dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV + dnl either. + CPPFLAGS="$am_save_CPPFLAGS" + LIBICONV= + LTLIBICONV= + fi + AC_SUBST([LIBICONV]) + AC_SUBST([LTLIBICONV]) +]) + +dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to +dnl avoid warnings like +dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required". +dnl This is tricky because of the way 'aclocal' is implemented: +dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. +dnl Otherwise aclocal's initial scan pass would miss the macro definition. +dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions. +dnl Otherwise aclocal would emit many "Use of uninitialized value $1" +dnl warnings. +m4_define([gl_iconv_AC_DEFUN], + m4_version_prereq([2.64], + [[AC_DEFUN_ONCE( + [$1], [$2])]], + [m4_ifdef([gl_00GNULIB], + [[AC_DEFUN_ONCE( + [$1], [$2])]], + [[AC_DEFUN( + [$1], [$2])]])])) +gl_iconv_AC_DEFUN([AM_ICONV], +[ + AM_ICONV_LINK + if test "$am_cv_func_iconv" = yes; then + AC_MSG_CHECKING([for iconv declaration]) + AC_CACHE_VAL([am_cv_proto_iconv], [ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include +extern +#ifdef __cplusplus +"C" +#endif +#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); +#else +size_t iconv(); +#endif + ]], + [[]])], + [am_cv_proto_iconv_arg1=""], + [am_cv_proto_iconv_arg1="const"]) + am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) + am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` + AC_MSG_RESULT([ + $am_cv_proto_iconv]) + AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1], + [Define as const if the declaration of iconv() needs const.]) + dnl Also substitute ICONV_CONST in the gnulib generated . + m4_ifdef([gl_ICONV_H_DEFAULTS], + [AC_REQUIRE([gl_ICONV_H_DEFAULTS]) + if test -n "$am_cv_proto_iconv_arg1"; then + ICONV_CONST="const" + fi + ]) + fi +]) diff --git a/m4/include_next.m4 b/m4/include_next.m4 new file mode 100644 index 000000000..108d94567 --- /dev/null +++ b/m4/include_next.m4 @@ -0,0 +1,270 @@ +# include_next.m4 serial 23 +dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert and Derek Price. + +dnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER. +dnl +dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to +dnl 'include' otherwise. +dnl +dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler +dnl supports it in the special case that it is the first include directive in +dnl the given file, or to 'include' otherwise. +dnl +dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next, +dnl so as to avoid GCC warnings when the gcc option -pedantic is used. +dnl '#pragma GCC system_header' has the same effect as if the file was found +dnl through the include search path specified with '-isystem' options (as +dnl opposed to the search path specified with '-I' options). Namely, gcc +dnl does not warn about some things, and on some systems (Solaris and Interix) +dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side +dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead +dnl of plain '__STDC__'. +dnl +dnl PRAGMA_COLUMNS can be used in files that override system header files, so +dnl as to avoid compilation errors on HP NonStop systems when the gnulib file +dnl is included by a system header file that does a "#pragma COLUMNS 80" (which +dnl has the effect of truncating the lines of that file and all files that it +dnl includes to 80 columns) and the gnulib file has lines longer than 80 +dnl columns. + +AC_DEFUN([gl_INCLUDE_NEXT], +[ + AC_LANG_PREPROC_REQUIRE() + AC_CACHE_CHECK([whether the preprocessor supports include_next], + [gl_cv_have_include_next], + [rm -rf conftestd1a conftestd1b conftestd2 + mkdir conftestd1a conftestd1b conftestd2 + dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on + dnl AIX 6.1 support include_next when used as first preprocessor directive + dnl in a file, but not when preceded by another include directive. Check + dnl for this bug by including . + dnl Additionally, with this same compiler, include_next is a no-op when + dnl used in a header file that was included by specifying its absolute + dnl file name. Despite these two bugs, include_next is used in the + dnl compiler's . By virtue of the second bug, we need to use + dnl include_next as well in this case. + cat < conftestd1a/conftest.h +#define DEFINED_IN_CONFTESTD1 +#include_next +#ifdef DEFINED_IN_CONFTESTD2 +int foo; +#else +#error "include_next doesn't work" +#endif +EOF + cat < conftestd1b/conftest.h +#define DEFINED_IN_CONFTESTD1 +#include +#include_next +#ifdef DEFINED_IN_CONFTESTD2 +int foo; +#else +#error "include_next doesn't work" +#endif +EOF + cat < conftestd2/conftest.h +#ifndef DEFINED_IN_CONFTESTD1 +#error "include_next test doesn't work" +#endif +#define DEFINED_IN_CONFTESTD2 +EOF + gl_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2" +dnl We intentionally avoid using AC_LANG_SOURCE here. + AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include ]], + [gl_cv_have_include_next=yes], + [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2" + AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include ]], + [gl_cv_have_include_next=buggy], + [gl_cv_have_include_next=no]) + ]) + CPPFLAGS="$gl_save_CPPFLAGS" + rm -rf conftestd1a conftestd1b conftestd2 + ]) + PRAGMA_SYSTEM_HEADER= + if test $gl_cv_have_include_next = yes; then + INCLUDE_NEXT=include_next + INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next + if test -n "$GCC"; then + PRAGMA_SYSTEM_HEADER='#pragma GCC system_header' + fi + else + if test $gl_cv_have_include_next = buggy; then + INCLUDE_NEXT=include + INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next + else + INCLUDE_NEXT=include + INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include + fi + fi + AC_SUBST([INCLUDE_NEXT]) + AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE]) + AC_SUBST([PRAGMA_SYSTEM_HEADER]) + AC_CACHE_CHECK([whether system header files limit the line length], + [gl_cv_pragma_columns], + [dnl HP NonStop systems, which define __TANDEM, have this misfeature. + AC_EGREP_CPP([choke me], + [ +#ifdef __TANDEM +choke me +#endif + ], + [gl_cv_pragma_columns=yes], + [gl_cv_pragma_columns=no]) + ]) + if test $gl_cv_pragma_columns = yes; then + PRAGMA_COLUMNS="#pragma COLUMNS 10000" + else + PRAGMA_COLUMNS= + fi + AC_SUBST([PRAGMA_COLUMNS]) +]) + +# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...) +# ------------------------------------------ +# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be +# ''; otherwise define it to be +# '"///usr/include/foo.h"', or whatever other absolute file name is suitable. +# Also, if #include_next works as first preprocessing directive in a file, +# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be ''; otherwise define it to +# be +# '"///usr/include/foo.h"', or whatever other absolute file name is suitable. +# That way, a header file with the following line: +# #@INCLUDE_NEXT@ @NEXT_FOO_H@ +# or +# #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@ +# behaves (after sed substitution) as if it contained +# #include_next +# even if the compiler does not support include_next. +# The three "///" are to pacify Sun C 5.8, which otherwise would say +# "warning: #include of /usr/include/... may be non-portable". +# Use '""', not '<>', so that the /// cannot be confused with a C99 comment. +# Note: This macro assumes that the header file is not empty after +# preprocessing, i.e. it does not only define preprocessor macros but also +# provides some type/enum definitions or function/variable declarations. +# +# This macro also checks whether each header exists, by invoking +# AC_CHECK_HEADERS_ONCE or AC_CHECK_HEADERS on each argument. +AC_DEFUN([gl_CHECK_NEXT_HEADERS], +[ + gl_NEXT_HEADERS_INTERNAL([$1], [check]) +]) + +# gl_NEXT_HEADERS(HEADER1 HEADER2 ...) +# ------------------------------------ +# Like gl_CHECK_NEXT_HEADERS, except do not check whether the headers exist. +# This is suitable for headers like that are standardized by C89 +# and therefore can be assumed to exist. +AC_DEFUN([gl_NEXT_HEADERS], +[ + gl_NEXT_HEADERS_INTERNAL([$1], [assume]) +]) + +# The guts of gl_CHECK_NEXT_HEADERS and gl_NEXT_HEADERS. +AC_DEFUN([gl_NEXT_HEADERS_INTERNAL], +[ + AC_REQUIRE([gl_INCLUDE_NEXT]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + m4_if([$2], [check], + [AC_CHECK_HEADERS_ONCE([$1]) + ]) + +dnl FIXME: gl_next_header and gl_header_exists must be used unquoted +dnl until we can assume autoconf 2.64 or newer. + m4_foreach_w([gl_HEADER_NAME], [$1], + [AS_VAR_PUSHDEF([gl_next_header], + [gl_cv_next_]m4_defn([gl_HEADER_NAME])) + if test $gl_cv_have_include_next = yes; then + AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>']) + else + AC_CACHE_CHECK( + [absolute name of <]m4_defn([gl_HEADER_NAME])[>], + m4_defn([gl_next_header]), + [m4_if([$2], [check], + [AS_VAR_PUSHDEF([gl_header_exists], + [ac_cv_header_]m4_defn([gl_HEADER_NAME])) + if test AS_VAR_GET(gl_header_exists) = yes; then + AS_VAR_POPDEF([gl_header_exists]) + ]) + AC_LANG_CONFTEST( + [AC_LANG_SOURCE( + [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] + )]) + dnl AIX "xlc -E" and "cc -E" omit #line directives for header + dnl files that contain only a #include of other header files and + dnl no non-comment tokens of their own. This leads to a failure + dnl to detect the absolute name of , , + dnl and others. The workaround is to force preservation + dnl of comments through option -C. This ensures all necessary + dnl #line directives are present. GCC supports option -C as well. + case "$host_os" in + aix*) gl_absname_cpp="$ac_cpp -C" ;; + *) gl_absname_cpp="$ac_cpp" ;; + esac +changequote(,) + case "$host_os" in + mingw*) + dnl For the sake of native Windows compilers (excluding gcc), + dnl treat backslash as a directory separator, like /. + dnl Actually, these compilers use a double-backslash as + dnl directory separator, inside the + dnl # line "filename" + dnl directives. + gl_dirsep_regex='[/\\]' + ;; + *) + gl_dirsep_regex='\/' + ;; + esac + dnl A sed expression that turns a string into a basic regular + dnl expression, for use within "/.../". + gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g' +changequote([,]) + gl_header_literal_regex=`echo ']m4_defn([gl_HEADER_NAME])[' \ + | sed -e "$gl_make_literal_regex_sed"` + gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{ + s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/ +changequote(,)dnl + s|^/[^/]|//&| +changequote([,])dnl + p + q + }' + dnl eval is necessary to expand gl_absname_cpp. + dnl Ultrix and Pyramid sh refuse to redirect output of eval, + dnl so use subshell. + AS_VAR_SET(gl_next_header, + ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | + sed -n "$gl_absolute_header_sed"`'"']) + m4_if([$2], [check], + [else + AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>']) + fi + ]) + ]) + fi + AC_SUBST( + AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])), + [AS_VAR_GET(gl_next_header)]) + if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then + # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next' + gl_next_as_first_directive='<'gl_HEADER_NAME'>' + else + # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include' + gl_next_as_first_directive=AS_VAR_GET(gl_next_header) + fi + AC_SUBST( + AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])), + [$gl_next_as_first_directive]) + AS_VAR_POPDEF([gl_next_header])]) +]) + +# Autoconf 2.68 added warnings for our use of AC_COMPILE_IFELSE; +# this fallback is safe for all earlier autoconf versions. +m4_define_default([AC_LANG_DEFINES_PROVIDED]) diff --git a/m4/intdiv0.m4 b/m4/intdiv0.m4 new file mode 100644 index 000000000..74d0e80d2 --- /dev/null +++ b/m4/intdiv0.m4 @@ -0,0 +1,87 @@ +# intdiv0.m4 serial 6 (gettext-0.18.2) +dnl Copyright (C) 2002, 2007-2008, 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gt_INTDIV0], +[ + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + + AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], + gt_cv_int_divbyzero_sigfpe, + [ + gt_cv_int_divbyzero_sigfpe= +changequote(,)dnl + case "$host_os" in + macos* | darwin[6-9]* | darwin[1-9][0-9]*) + # On Mac OS X 10.2 or newer, just assume the same as when cross- + # compiling. If we were to perform the real test, 1 Crash Report + # dialog window would pop up. + case "$host_cpu" in + i[34567]86 | x86_64) + gt_cv_int_divbyzero_sigfpe="guessing yes" ;; + esac + ;; + esac +changequote([,])dnl + if test -z "$gt_cv_int_divbyzero_sigfpe"; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include + +static void +sigfpe_handler (int sig) +{ + /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ + exit (sig != SIGFPE); +} + +int x = 1; +int y = 0; +int z; +int nan; + +int main () +{ + signal (SIGFPE, sigfpe_handler); +/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ +#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) + signal (SIGTRAP, sigfpe_handler); +#endif +/* Linux/SPARC yields signal SIGILL. */ +#if defined (__sparc__) && defined (__linux__) + signal (SIGILL, sigfpe_handler); +#endif + + z = x / y; + nan = y / y; + exit (2); +} +]])], + [gt_cv_int_divbyzero_sigfpe=yes], + [gt_cv_int_divbyzero_sigfpe=no], + [ + # Guess based on the CPU. +changequote(,)dnl + case "$host_cpu" in + alpha* | i[34567]86 | x86_64 | m68k | s390*) + gt_cv_int_divbyzero_sigfpe="guessing yes";; + *) + gt_cv_int_divbyzero_sigfpe="guessing no";; + esac +changequote([,])dnl + ]) + fi + ]) + case "$gt_cv_int_divbyzero_sigfpe" in + *yes) value=1;; + *) value=0;; + esac + AC_DEFINE_UNQUOTED([INTDIV0_RAISES_SIGFPE], [$value], + [Define if integer division by zero raises signal SIGFPE.]) +]) diff --git a/m4/intl.m4 b/m4/intl.m4 new file mode 100644 index 000000000..486b5cc64 --- /dev/null +++ b/m4/intl.m4 @@ -0,0 +1,300 @@ +# intl.m4 serial 22 (gettext-0.18.2) +dnl Copyright (C) 1995-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995-2000. +dnl Bruno Haible , 2000-2009. + +AC_PREREQ([2.60]) + +dnl Checks for all prerequisites of the intl subdirectory, +dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, +dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. +AC_DEFUN([AM_INTL_SUBDIR], +[ + AC_REQUIRE([AC_PROG_INSTALL])dnl + AC_REQUIRE([AC_PROG_MKDIR_P])dnl + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([gt_GLIBC2])dnl + AC_REQUIRE([AC_PROG_RANLIB])dnl + AC_REQUIRE([gl_VISIBILITY])dnl + AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl + AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl + AC_REQUIRE([gt_TYPE_WCHAR_T])dnl + AC_REQUIRE([gt_TYPE_WINT_T])dnl + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gt_TYPE_INTMAX_T]) + AC_REQUIRE([gt_PRINTF_POSIX]) + AC_REQUIRE([gl_GLIBC21])dnl + AC_REQUIRE([gl_XSIZE])dnl + AC_REQUIRE([gl_FCNTL_O_FLAGS])dnl + AC_REQUIRE([gt_INTL_MACOSX])dnl + + dnl Support for automake's --enable-silent-rules. + case "$enable_silent_rules" in + yes) INTL_DEFAULT_VERBOSITY=0;; + no) INTL_DEFAULT_VERBOSITY=1;; + *) INTL_DEFAULT_VERBOSITY=1;; + esac + AC_SUBST([INTL_DEFAULT_VERBOSITY]) + + AC_CHECK_TYPE([ptrdiff_t], , + [AC_DEFINE([ptrdiff_t], [long], + [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) + ]) + AC_CHECK_HEADERS([features.h stddef.h stdlib.h string.h]) + AC_CHECK_FUNCS([asprintf fwprintf newlocale putenv setenv setlocale \ + snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb]) + + dnl Use the _snprintf function only if it is declared (because on NetBSD it + dnl is defined as a weak alias of snprintf; we prefer to use the latter). + gt_CHECK_DECL(_snprintf, [#include ]) + gt_CHECK_DECL(_snwprintf, [#include ]) + + dnl Use the *_unlocked functions only if they are declared. + dnl (because some of them were defined without being declared in Solaris + dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built + dnl on Solaris 2.5.1 to run on Solaris 2.6). + dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. + gt_CHECK_DECL(getc_unlocked, [#include ]) + + case $gt_cv_func_printf_posix in + *yes) HAVE_POSIX_PRINTF=1 ;; + *) HAVE_POSIX_PRINTF=0 ;; + esac + AC_SUBST([HAVE_POSIX_PRINTF]) + if test "$ac_cv_func_asprintf" = yes; then + HAVE_ASPRINTF=1 + else + HAVE_ASPRINTF=0 + fi + AC_SUBST([HAVE_ASPRINTF]) + if test "$ac_cv_func_snprintf" = yes; then + HAVE_SNPRINTF=1 + else + HAVE_SNPRINTF=0 + fi + AC_SUBST([HAVE_SNPRINTF]) + if test "$ac_cv_func_newlocale" = yes; then + HAVE_NEWLOCALE=1 + else + HAVE_NEWLOCALE=0 + fi + AC_SUBST([HAVE_NEWLOCALE]) + if test "$ac_cv_func_wprintf" = yes; then + HAVE_WPRINTF=1 + else + HAVE_WPRINTF=0 + fi + AC_SUBST([HAVE_WPRINTF]) + + AM_LANGINFO_CODESET + gt_LC_MESSAGES + + dnl Compilation on mingw and Cygwin needs special Makefile rules, because + dnl 1. when we install a shared library, we must arrange to export + dnl auxiliary pointer variables for every exported variable, + dnl 2. when we install a shared library and a static library simultaneously, + dnl the include file specifies __declspec(dllimport) and therefore we + dnl must arrange to define the auxiliary pointer variables for the + dnl exported variables _also_ in the static library. + if test "$enable_shared" = yes; then + case "$host_os" in + mingw* | cygwin*) is_woe32dll=yes ;; + *) is_woe32dll=no ;; + esac + else + is_woe32dll=no + fi + WOE32DLL=$is_woe32dll + AC_SUBST([WOE32DLL]) + + dnl On mingw and Cygwin, we can activate special Makefile rules which add + dnl version information to the shared libraries and executables. + case "$host_os" in + mingw* | cygwin*) is_woe32=yes ;; + *) is_woe32=no ;; + esac + WOE32=$is_woe32 + AC_SUBST([WOE32]) + if test $WOE32 = yes; then + dnl Check for a program that compiles Windows resource files. + AC_CHECK_TOOL([WINDRES], [windres]) + fi + + dnl Determine whether when creating a library, "-lc" should be passed to + dnl libtool or not. On many platforms, it is required for the libtool option + dnl -no-undefined to work. On HP-UX, however, the -lc - stored by libtool + dnl in the *.la files - makes it impossible to create multithreaded programs, + dnl because libtool also reorders the -lc to come before the -pthread, and + dnl this disables pthread_create() . + case "$host_os" in + hpux*) LTLIBC="" ;; + *) LTLIBC="-lc" ;; + esac + AC_SUBST([LTLIBC]) + + dnl Rename some macros and functions used for locking. + AH_BOTTOM([ +#define __libc_lock_t gl_lock_t +#define __libc_lock_define gl_lock_define +#define __libc_lock_define_initialized gl_lock_define_initialized +#define __libc_lock_init gl_lock_init +#define __libc_lock_lock gl_lock_lock +#define __libc_lock_unlock gl_lock_unlock +#define __libc_lock_recursive_t gl_recursive_lock_t +#define __libc_lock_define_recursive gl_recursive_lock_define +#define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized +#define __libc_lock_init_recursive gl_recursive_lock_init +#define __libc_lock_lock_recursive gl_recursive_lock_lock +#define __libc_lock_unlock_recursive gl_recursive_lock_unlock +#define glthread_in_use libintl_thread_in_use +#define glthread_lock_init_func libintl_lock_init_func +#define glthread_lock_lock_func libintl_lock_lock_func +#define glthread_lock_unlock_func libintl_lock_unlock_func +#define glthread_lock_destroy_func libintl_lock_destroy_func +#define glthread_rwlock_init_multithreaded libintl_rwlock_init_multithreaded +#define glthread_rwlock_init_func libintl_rwlock_init_func +#define glthread_rwlock_rdlock_multithreaded libintl_rwlock_rdlock_multithreaded +#define glthread_rwlock_rdlock_func libintl_rwlock_rdlock_func +#define glthread_rwlock_wrlock_multithreaded libintl_rwlock_wrlock_multithreaded +#define glthread_rwlock_wrlock_func libintl_rwlock_wrlock_func +#define glthread_rwlock_unlock_multithreaded libintl_rwlock_unlock_multithreaded +#define glthread_rwlock_unlock_func libintl_rwlock_unlock_func +#define glthread_rwlock_destroy_multithreaded libintl_rwlock_destroy_multithreaded +#define glthread_rwlock_destroy_func libintl_rwlock_destroy_func +#define glthread_recursive_lock_init_multithreaded libintl_recursive_lock_init_multithreaded +#define glthread_recursive_lock_init_func libintl_recursive_lock_init_func +#define glthread_recursive_lock_lock_multithreaded libintl_recursive_lock_lock_multithreaded +#define glthread_recursive_lock_lock_func libintl_recursive_lock_lock_func +#define glthread_recursive_lock_unlock_multithreaded libintl_recursive_lock_unlock_multithreaded +#define glthread_recursive_lock_unlock_func libintl_recursive_lock_unlock_func +#define glthread_recursive_lock_destroy_multithreaded libintl_recursive_lock_destroy_multithreaded +#define glthread_recursive_lock_destroy_func libintl_recursive_lock_destroy_func +#define glthread_once_func libintl_once_func +#define glthread_once_singlethreaded libintl_once_singlethreaded +#define glthread_once_multithreaded libintl_once_multithreaded +]) +]) + + +dnl Checks for the core files of the intl subdirectory: +dnl dcigettext.c +dnl eval-plural.h +dnl explodename.c +dnl finddomain.c +dnl gettextP.h +dnl gmo.h +dnl hash-string.h hash-string.c +dnl l10nflist.c +dnl libgnuintl.h.in (except the *printf stuff) +dnl loadinfo.h +dnl loadmsgcat.c +dnl localealias.c +dnl log.c +dnl plural-exp.h plural-exp.c +dnl plural.y +dnl Used by libglocale. +AC_DEFUN([gt_INTL_SUBDIR_CORE], +[ + AC_REQUIRE([AC_C_INLINE])dnl + AC_REQUIRE([AC_TYPE_SIZE_T])dnl + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_REQUIRE([AC_FUNC_ALLOCA])dnl + AC_REQUIRE([AC_FUNC_MMAP])dnl + AC_REQUIRE([gt_INTDIV0])dnl + AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl + AC_REQUIRE([gt_INTTYPES_PRI])dnl + AC_REQUIRE([gl_LOCK])dnl + + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }]], + [[]])], + [AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], + [Define to 1 if the compiler understands __builtin_expect.])]) + + AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) + AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ + stpcpy strcasecmp strdup strtoul tsearch uselocale argz_count \ + argz_stringify argz_next __fsetlocking]) + + dnl Use the *_unlocked functions only if they are declared. + dnl (because some of them were defined without being declared in Solaris + dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built + dnl on Solaris 2.5.1 to run on Solaris 2.6). + dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. + gt_CHECK_DECL([feof_unlocked], [#include ]) + gt_CHECK_DECL([fgets_unlocked], [#include ]) + + AM_ICONV + + dnl intl/plural.c is generated from intl/plural.y. It requires bison, + dnl because plural.y uses bison specific features. It requires at least + dnl bison-1.26 because earlier versions generate a plural.c that doesn't + dnl compile. + dnl bison is only needed for the maintainer (who touches plural.y). But in + dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put + dnl the rule in general Makefile. Now, some people carelessly touch the + dnl files or have a broken "make" program, hence the plural.c rule will + dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not + dnl present or too old. + AC_CHECK_PROGS([INTLBISON], [bison]) + if test -z "$INTLBISON"; then + ac_verc_fail=yes + else + dnl Found it, now check the version. + AC_MSG_CHECKING([version of bison]) +changequote(<<,>>)dnl + ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` + case $ac_prog_version in + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; + 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) +changequote([,])dnl + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; + esac + AC_MSG_RESULT([$ac_prog_version]) + fi + if test $ac_verc_fail = yes; then + INTLBISON=: + fi +]) + + +dnl gt_CHECK_DECL(FUNC, INCLUDES) +dnl Check whether a function is declared. +AC_DEFUN([gt_CHECK_DECL], +[ + AC_CACHE_CHECK([whether $1 is declared], [ac_cv_have_decl_$1], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[$2]], + [[ +#ifndef $1 + char *p = (char *) $1; +#endif + ]])], + [ac_cv_have_decl_$1=yes], + [ac_cv_have_decl_$1=no])]) + if test $ac_cv_have_decl_$1 = yes; then + gt_value=1 + else + gt_value=0 + fi + AC_DEFINE_UNQUOTED([HAVE_DECL_]m4_translit($1, [a-z], [A-Z]), [$gt_value], + [Define to 1 if you have the declaration of '$1', and to 0 if you don't.]) +]) diff --git a/m4/intldir.m4 b/m4/intldir.m4 new file mode 100644 index 000000000..388ecd6fd --- /dev/null +++ b/m4/intldir.m4 @@ -0,0 +1,19 @@ +# intldir.m4 serial 2 (gettext-0.18) +dnl Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +AC_PREREQ([2.52]) + +dnl Tells the AM_GNU_GETTEXT macro to consider an intl/ directory. +AC_DEFUN([AM_GNU_GETTEXT_INTL_SUBDIR], []) diff --git a/m4/intlmacosx.m4 b/m4/intlmacosx.m4 new file mode 100644 index 000000000..ab97d39f9 --- /dev/null +++ b/m4/intlmacosx.m4 @@ -0,0 +1,56 @@ +# intlmacosx.m4 serial 5 (gettext-0.18.2) +dnl Copyright (C) 2004-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Checks for special options needed on Mac OS X. +dnl Defines INTL_MACOSX_LIBS. +AC_DEFUN([gt_INTL_MACOSX], +[ + dnl Check for API introduced in Mac OS X 10.2. + AC_CACHE_CHECK([for CFPreferencesCopyAppValue], + [gt_cv_func_CFPreferencesCopyAppValue], + [gt_save_LIBS="$LIBS" + LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[CFPreferencesCopyAppValue(NULL, NULL)]])], + [gt_cv_func_CFPreferencesCopyAppValue=yes], + [gt_cv_func_CFPreferencesCopyAppValue=no]) + LIBS="$gt_save_LIBS"]) + if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then + AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1], + [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) + fi + dnl Check for API introduced in Mac OS X 10.3. + AC_CACHE_CHECK([for CFLocaleCopyCurrent], [gt_cv_func_CFLocaleCopyCurrent], + [gt_save_LIBS="$LIBS" + LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[CFLocaleCopyCurrent();]])], + [gt_cv_func_CFLocaleCopyCurrent=yes], + [gt_cv_func_CFLocaleCopyCurrent=no]) + LIBS="$gt_save_LIBS"]) + if test $gt_cv_func_CFLocaleCopyCurrent = yes; then + AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], [1], + [Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) + fi + INTL_MACOSX_LIBS= + if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then + INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" + fi + AC_SUBST([INTL_MACOSX_LIBS]) +]) diff --git a/m4/intmax.m4 b/m4/intmax.m4 new file mode 100644 index 000000000..18733a52e --- /dev/null +++ b/m4/intmax.m4 @@ -0,0 +1,36 @@ +# intmax.m4 serial 6 (gettext-0.18.2) +dnl Copyright (C) 2002-2005, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether the system has the 'intmax_t' type, but don't attempt to +dnl find a replacement if it is lacking. + +AC_DEFUN([gt_TYPE_INTMAX_T], +[ + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_CACHE_CHECK([for intmax_t], [gt_cv_c_intmax_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include +#if HAVE_STDINT_H_WITH_UINTMAX +#include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +#include +#endif + ]], + [[intmax_t x = -1; + return !x;]])], + [gt_cv_c_intmax_t=yes], + [gt_cv_c_intmax_t=no])]) + if test $gt_cv_c_intmax_t = yes; then + AC_DEFINE([HAVE_INTMAX_T], [1], + [Define if you have the 'intmax_t' type in or .]) + fi +]) diff --git a/m4/intmax_t.m4 b/m4/intmax_t.m4 new file mode 100644 index 000000000..6ea70531c --- /dev/null +++ b/m4/intmax_t.m4 @@ -0,0 +1,67 @@ +# intmax_t.m4 serial 8 +dnl Copyright (C) 1997-2004, 2006-2007, 2009-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +AC_PREREQ([2.53]) + +# Define intmax_t to 'long' or 'long long' +# if it is not already defined in or . + +AC_DEFUN([gl_AC_TYPE_INTMAX_T], +[ + dnl For simplicity, we assume that a header file defines 'intmax_t' if and + dnl only if it defines 'uintmax_t'. + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + test $ac_cv_type_long_long_int = yes \ + && ac_type='long long' \ + || ac_type='long' + AC_DEFINE_UNQUOTED([intmax_t], [$ac_type], + [Define to long or long long if and don't define.]) + else + AC_DEFINE([HAVE_INTMAX_T], [1], + [Define if you have the 'intmax_t' type in or .]) + fi +]) + +dnl An alternative would be to explicitly test for 'intmax_t'. + +AC_DEFUN([gt_AC_TYPE_INTMAX_T], +[ + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_CACHE_CHECK([for intmax_t], [gt_cv_c_intmax_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include +#if HAVE_STDINT_H_WITH_UINTMAX +#include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +#include +#endif + ]], + [[intmax_t x = -1; return !x;]])], + [gt_cv_c_intmax_t=yes], + [gt_cv_c_intmax_t=no])]) + if test $gt_cv_c_intmax_t = yes; then + AC_DEFINE([HAVE_INTMAX_T], [1], + [Define if you have the 'intmax_t' type in or .]) + else + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + test $ac_cv_type_long_long_int = yes \ + && ac_type='long long' \ + || ac_type='long' + AC_DEFINE_UNQUOTED([intmax_t], [$ac_type], + [Define to long or long long if and don't define.]) + fi +]) diff --git a/m4/inttypes-pri.m4 b/m4/inttypes-pri.m4 new file mode 100644 index 000000000..e5a1e0571 --- /dev/null +++ b/m4/inttypes-pri.m4 @@ -0,0 +1,42 @@ +# inttypes-pri.m4 serial 7 (gettext-0.18.2) +dnl Copyright (C) 1997-2002, 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_PREREQ([2.53]) + +# Define PRI_MACROS_BROKEN if exists and defines the PRI* +# macros to non-string values. This is the case on AIX 4.3.3. + +AC_DEFUN([gt_INTTYPES_PRI], +[ + AC_CHECK_HEADERS([inttypes.h]) + if test $ac_cv_header_inttypes_h = yes; then + AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], + [gt_cv_inttypes_pri_broken], + [ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#ifdef PRId32 +char *p = PRId32; +#endif + ]], + [[]])], + [gt_cv_inttypes_pri_broken=no], + [gt_cv_inttypes_pri_broken=yes]) + ]) + fi + if test "$gt_cv_inttypes_pri_broken" = yes; then + AC_DEFINE_UNQUOTED([PRI_MACROS_BROKEN], [1], + [Define if exists and defines unusable PRI* macros.]) + PRI_MACROS_BROKEN=1 + else + PRI_MACROS_BROKEN=0 + fi + AC_SUBST([PRI_MACROS_BROKEN]) +]) diff --git a/m4/inttypes_h.m4 b/m4/inttypes_h.m4 new file mode 100644 index 000000000..5f05ac58c --- /dev/null +++ b/m4/inttypes_h.m4 @@ -0,0 +1,29 @@ +# inttypes_h.m4 serial 10 +dnl Copyright (C) 1997-2004, 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +# Define HAVE_INTTYPES_H_WITH_UINTMAX if exists, +# doesn't clash with , and declares uintmax_t. + +AC_DEFUN([gl_AC_HEADER_INTTYPES_H], +[ + AC_CACHE_CHECK([for inttypes.h], [gl_cv_header_inttypes_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include + ]], + [[uintmax_t i = (uintmax_t) -1; return !i;]])], + [gl_cv_header_inttypes_h=yes], + [gl_cv_header_inttypes_h=no])]) + if test $gl_cv_header_inttypes_h = yes; then + AC_DEFINE_UNQUOTED([HAVE_INTTYPES_H_WITH_UINTMAX], [1], + [Define if exists, doesn't clash with , + and declares uintmax_t. ]) + fi +]) diff --git a/m4/langinfo_h.m4 b/m4/langinfo_h.m4 new file mode 100644 index 000000000..73bef8bce --- /dev/null +++ b/m4/langinfo_h.m4 @@ -0,0 +1,105 @@ +# langinfo_h.m4 serial 7 +dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_LANGINFO_H], +[ + AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) + + dnl Persuade glibc-2.0.6 to define CODESET. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_CHECK_NEXT_HEADERS([langinfo.h]) + + dnl Determine whether exists. It is missing on mingw and BeOS. + HAVE_LANGINFO_CODESET=0 + HAVE_LANGINFO_T_FMT_AMPM=0 + HAVE_LANGINFO_ERA=0 + HAVE_LANGINFO_YESEXPR=0 + AC_CHECK_HEADERS_ONCE([langinfo.h]) + if test $ac_cv_header_langinfo_h = yes; then + HAVE_LANGINFO_H=1 + dnl Determine what defines. CODESET and ERA etc. are missing + dnl on OpenBSD 3.8. T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3. + AC_CACHE_CHECK([whether langinfo.h defines CODESET], + [gl_cv_header_langinfo_codeset], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include +int a = CODESET; +]])], + [gl_cv_header_langinfo_codeset=yes], + [gl_cv_header_langinfo_codeset=no]) + ]) + if test $gl_cv_header_langinfo_codeset = yes; then + HAVE_LANGINFO_CODESET=1 + fi + AC_CACHE_CHECK([whether langinfo.h defines T_FMT_AMPM], + [gl_cv_header_langinfo_t_fmt_ampm], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include +int a = T_FMT_AMPM; +]])], + [gl_cv_header_langinfo_t_fmt_ampm=yes], + [gl_cv_header_langinfo_t_fmt_ampm=no]) + ]) + if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then + HAVE_LANGINFO_T_FMT_AMPM=1 + fi + AC_CACHE_CHECK([whether langinfo.h defines ERA], + [gl_cv_header_langinfo_era], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include +int a = ERA; +]])], + [gl_cv_header_langinfo_era=yes], + [gl_cv_header_langinfo_era=no]) + ]) + if test $gl_cv_header_langinfo_era = yes; then + HAVE_LANGINFO_ERA=1 + fi + AC_CACHE_CHECK([whether langinfo.h defines YESEXPR], + [gl_cv_header_langinfo_yesexpr], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include +int a = YESEXPR; +]])], + [gl_cv_header_langinfo_yesexpr=yes], + [gl_cv_header_langinfo_yesexpr=no]) + ]) + if test $gl_cv_header_langinfo_yesexpr = yes; then + HAVE_LANGINFO_YESEXPR=1 + fi + else + HAVE_LANGINFO_H=0 + fi + AC_SUBST([HAVE_LANGINFO_H]) + AC_SUBST([HAVE_LANGINFO_CODESET]) + AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM]) + AC_SUBST([HAVE_LANGINFO_ERA]) + AC_SUBST([HAVE_LANGINFO_YESEXPR]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include + ]], [nl_langinfo]) +]) + +AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_LANGINFO_H_DEFAULTS], +[ + GNULIB_NL_LANGINFO=0; AC_SUBST([GNULIB_NL_LANGINFO]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_NL_LANGINFO=1; AC_SUBST([HAVE_NL_LANGINFO]) + REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO]) +]) diff --git a/m4/lcmessage.m4 b/m4/lcmessage.m4 new file mode 100644 index 000000000..d62a175fc --- /dev/null +++ b/m4/lcmessage.m4 @@ -0,0 +1,35 @@ +# lcmessage.m4 serial 7 (gettext-0.18.2) +dnl Copyright (C) 1995-2002, 2004-2005, 2008-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995. + +# Check whether LC_MESSAGES is available in . + +AC_DEFUN([gt_LC_MESSAGES], +[ + AC_CACHE_CHECK([for LC_MESSAGES], [gt_cv_val_LC_MESSAGES], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[return LC_MESSAGES]])], + [gt_cv_val_LC_MESSAGES=yes], + [gt_cv_val_LC_MESSAGES=no])]) + if test $gt_cv_val_LC_MESSAGES = yes; then + AC_DEFINE([HAVE_LC_MESSAGES], [1], + [Define if your file defines LC_MESSAGES.]) + fi +]) diff --git a/m4/lib-ld.m4 b/m4/lib-ld.m4 new file mode 100644 index 000000000..c145e478e --- /dev/null +++ b/m4/lib-ld.m4 @@ -0,0 +1,119 @@ +# lib-ld.m4 serial 6 +dnl Copyright (C) 1996-2003, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Subroutines of libtool.m4, +dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid +dnl collision with libtool.m4. + +dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no. +AC_DEFUN([AC_LIB_PROG_LD_GNU], +[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld], +[# I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 /dev/null 2>&1 \ + && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + || PATH_SEPARATOR=';' + } +fi + +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo "$ac_prog"| sed 's%\\\\%/%g'` + while echo "$ac_prog" | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL([acl_cv_path_LD], +[if test -z "$LD"; then + acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$acl_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + acl_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$acl_cv_path_LD" -v 2>&1 = 1.10 to complain if config.rpath is missing. + m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])]) + AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS + AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld + AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host + AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir + AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [ + CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ + ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh + . ./conftest.sh + rm -f ./conftest.sh + acl_cv_rpath=done + ]) + wl="$acl_cv_wl" + acl_libext="$acl_cv_libext" + acl_shlibext="$acl_cv_shlibext" + acl_libname_spec="$acl_cv_libname_spec" + acl_library_names_spec="$acl_cv_library_names_spec" + acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" + acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" + acl_hardcode_direct="$acl_cv_hardcode_direct" + acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" + dnl Determine whether the user wants rpath handling at all. + AC_ARG_ENABLE([rpath], + [ --disable-rpath do not hardcode runtime library paths], + :, enable_rpath=yes) +]) + +dnl AC_LIB_FROMPACKAGE(name, package) +dnl declares that libname comes from the given package. The configure file +dnl will then not have a --with-libname-prefix option but a +dnl --with-package-prefix option. Several libraries can come from the same +dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar +dnl macro call that searches for libname. +AC_DEFUN([AC_LIB_FROMPACKAGE], +[ + pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) + define([acl_frompackage_]NAME, [$2]) + popdef([NAME]) + pushdef([PACK],[$2]) + pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) + define([acl_libsinpackage_]PACKUP, + m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1]) + popdef([PACKUP]) + popdef([PACK]) +]) + +dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and +dnl the libraries corresponding to explicit and implicit dependencies. +dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. +dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found +dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. +AC_DEFUN([AC_LIB_LINKFLAGS_BODY], +[ + AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) + pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) + pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) + pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) + pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) + dnl Autoconf >= 2.61 supports dots in --with options. + pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[m4_translit(PACK,[.],[_])],PACK)]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_ARG_WITH(P_A_C_K[-prefix], +[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib + --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/$acl_libdirstem" + if test "$acl_libdirstem2" != "$acl_libdirstem" \ + && ! test -d "$withval/$acl_libdirstem"; then + additional_libdir="$withval/$acl_libdirstem2" + fi + fi + fi +]) + dnl Search the library and its dependencies in $additional_libdir and + dnl $LDFLAGS. Using breadth-first-seach. + LIB[]NAME= + LTLIB[]NAME= + INC[]NAME= + LIB[]NAME[]_PREFIX= + dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been + dnl computed. So it has to be reset here. + HAVE_LIB[]NAME= + rpathdirs= + ltrpathdirs= + names_already_handled= + names_next_round='$1 $2' + while test -n "$names_next_round"; do + names_this_round="$names_next_round" + names_next_round= + for name in $names_this_round; do + already_handled= + for n in $names_already_handled; do + if test "$n" = "$name"; then + already_handled=yes + break + fi + done + if test -z "$already_handled"; then + names_already_handled="$names_already_handled $name" + dnl See if it was already located by an earlier AC_LIB_LINKFLAGS + dnl or AC_LIB_HAVE_LINKFLAGS call. + uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'` + eval value=\"\$HAVE_LIB$uppername\" + if test -n "$value"; then + if test "$value" = yes; then + eval value=\"\$LIB$uppername\" + test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" + eval value=\"\$LTLIB$uppername\" + test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" + else + dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined + dnl that this library doesn't exist. So just drop it. + : + fi + else + dnl Search the library lib$name in $additional_libdir and $LDFLAGS + dnl and the already constructed $LIBNAME/$LTLIBNAME. + found_dir= + found_la= + found_so= + found_a= + eval libname=\"$acl_libname_spec\" # typically: libname=lib$name + if test -n "$acl_shlibext"; then + shrext=".$acl_shlibext" # typically: shrext=.so + else + shrext= + fi + if test $use_additional = yes; then + dir="$additional_libdir" + dnl The same code as in the loop below: + dnl First look for a shared library. + if test -n "$acl_shlibext"; then + if test -f "$dir/$libname$shrext"; then + found_dir="$dir" + found_so="$dir/$libname$shrext" + else + if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then + ver=`(cd "$dir" && \ + for f in "$libname$shrext".*; do echo "$f"; done \ + | sed -e "s,^$libname$shrext\\\\.,," \ + | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ + | sed 1q ) 2>/dev/null` + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + found_dir="$dir" + found_so="$dir/$libname$shrext.$ver" + fi + else + eval library_names=\"$acl_library_names_spec\" + for f in $library_names; do + if test -f "$dir/$f"; then + found_dir="$dir" + found_so="$dir/$f" + break + fi + done + fi + fi + fi + dnl Then look for a static library. + if test "X$found_dir" = "X"; then + if test -f "$dir/$libname.$acl_libext"; then + found_dir="$dir" + found_a="$dir/$libname.$acl_libext" + fi + fi + if test "X$found_dir" != "X"; then + if test -f "$dir/$libname.la"; then + found_la="$dir/$libname.la" + fi + fi + fi + if test "X$found_dir" = "X"; then + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + case "$x" in + -L*) + dir=`echo "X$x" | sed -e 's/^X-L//'` + dnl First look for a shared library. + if test -n "$acl_shlibext"; then + if test -f "$dir/$libname$shrext"; then + found_dir="$dir" + found_so="$dir/$libname$shrext" + else + if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then + ver=`(cd "$dir" && \ + for f in "$libname$shrext".*; do echo "$f"; done \ + | sed -e "s,^$libname$shrext\\\\.,," \ + | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ + | sed 1q ) 2>/dev/null` + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + found_dir="$dir" + found_so="$dir/$libname$shrext.$ver" + fi + else + eval library_names=\"$acl_library_names_spec\" + for f in $library_names; do + if test -f "$dir/$f"; then + found_dir="$dir" + found_so="$dir/$f" + break + fi + done + fi + fi + fi + dnl Then look for a static library. + if test "X$found_dir" = "X"; then + if test -f "$dir/$libname.$acl_libext"; then + found_dir="$dir" + found_a="$dir/$libname.$acl_libext" + fi + fi + if test "X$found_dir" != "X"; then + if test -f "$dir/$libname.la"; then + found_la="$dir/$libname.la" + fi + fi + ;; + esac + if test "X$found_dir" != "X"; then + break + fi + done + fi + if test "X$found_dir" != "X"; then + dnl Found the library. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" + if test "X$found_so" != "X"; then + dnl Linking with a shared library. We attempt to hardcode its + dnl directory into the executable's runpath, unless it's the + dnl standard /usr/lib. + if test "$enable_rpath" = no \ + || test "X$found_dir" = "X/usr/$acl_libdirstem" \ + || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then + dnl No hardcoding is needed. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $found_dir" + fi + dnl The hardcoding into $LIBNAME is system dependent. + if test "$acl_hardcode_direct" = yes; then + dnl Using DIR/libNAME.so during linking hardcodes DIR into the + dnl resulting binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $found_dir" + fi + else + dnl Rely on "-L$found_dir". + dnl But don't add it if it's already contained in the LDFLAGS + dnl or the already constructed $LIBNAME + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" + fi + if test "$acl_hardcode_minus_L" != no; then + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH + dnl here, because this doesn't fit in flags passed to the + dnl compiler. So give up. No hardcoding. This affects only + dnl very old systems. + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + fi + fi + fi + fi + else + if test "X$found_a" != "X"; then + dnl Linking with a static library. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" + else + dnl We shouldn't come here, but anyway it's good to have a + dnl fallback. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" + fi + fi + dnl Assume the include files are nearby. + additional_includedir= + case "$found_dir" in + */$acl_libdirstem | */$acl_libdirstem/) + basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` + if test "$name" = '$1'; then + LIB[]NAME[]_PREFIX="$basedir" + fi + additional_includedir="$basedir/include" + ;; + */$acl_libdirstem2 | */$acl_libdirstem2/) + basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'` + if test "$name" = '$1'; then + LIB[]NAME[]_PREFIX="$basedir" + fi + additional_includedir="$basedir/include" + ;; + esac + if test "X$additional_includedir" != "X"; then + dnl Potentially add $additional_includedir to $INCNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's /usr/local/include and we are using GCC on Linux, + dnl 3. if it's already present in $CPPFLAGS or the already + dnl constructed $INCNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux* | gnu* | k*bsd*-gnu) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + for x in $CPPFLAGS $INC[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $INCNAME. + INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" + fi + fi + fi + fi + fi + dnl Look for dependencies. + if test -n "$found_la"; then + dnl Read the .la file. It defines the variables + dnl dlname, library_names, old_library, dependency_libs, current, + dnl age, revision, installed, dlopen, dlpreopen, libdir. + save_libdir="$libdir" + case "$found_la" in + */* | *\\*) . "$found_la" ;; + *) . "./$found_la" ;; + esac + libdir="$save_libdir" + dnl We use only dependency_libs. + for dep in $dependency_libs; do + case "$dep" in + -L*) + additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` + dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's /usr/local/lib and we are using GCC on Linux, + dnl 3. if it's already present in $LDFLAGS or the already + dnl constructed $LIBNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \ + && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then + haveit= + if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \ + || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then + if test -n "$GCC"; then + case $host_os in + linux* | gnu* | k*bsd*-gnu) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LIBNAME. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" + fi + fi + haveit= + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LTLIBNAME. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" + fi + fi + fi + fi + ;; + -R*) + dir=`echo "X$dep" | sed -e 's/^X-R//'` + if test "$enable_rpath" != no; then + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $dir" + fi + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $dir" + fi + fi + ;; + -l*) + dnl Handle this in the next round. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` + ;; + *.la) + dnl Handle this in the next round. Throw away the .la's + dnl directory; it is already contained in a preceding -L + dnl option. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` + ;; + *) + dnl Most likely an immediate library name. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" + ;; + esac + done + fi + else + dnl Didn't find the library; assume it is in the system directories + dnl known to the linker and runtime loader. (All the system + dnl directories known to the linker should also be known to the + dnl runtime loader, otherwise the system is severely misconfigured.) + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" + fi + fi + fi + done + done + if test "X$rpathdirs" != "X"; then + if test -n "$acl_hardcode_libdir_separator"; then + dnl Weird platform: only the last -rpath option counts, the user must + dnl pass all path elements in one option. We can arrange that for a + dnl single library, but not when more than one $LIBNAMEs are used. + alldirs= + for found_dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" + done + dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + else + dnl The -rpath options are cumulative. + for found_dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$found_dir" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + done + fi + fi + if test "X$ltrpathdirs" != "X"; then + dnl When using libtool, the option that works for both libraries and + dnl executables is -R. The -R options are cumulative. + for found_dir in $ltrpathdirs; do + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" + done + fi + popdef([P_A_C_K]) + popdef([PACKLIBS]) + popdef([PACKUP]) + popdef([PACK]) + popdef([NAME]) +]) + +dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, +dnl unless already present in VAR. +dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes +dnl contains two or three consecutive elements that belong together. +AC_DEFUN([AC_LIB_APPENDTOVAR], +[ + for element in [$2]; do + haveit= + for x in $[$1]; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X$element"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + [$1]="${[$1]}${[$1]:+ }$element" + fi + done +]) + +dnl For those cases where a variable contains several -L and -l options +dnl referring to unknown libraries and directories, this macro determines the +dnl necessary additional linker options for the runtime path. +dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) +dnl sets LDADDVAR to linker options needed together with LIBSVALUE. +dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, +dnl otherwise linking without libtool is assumed. +AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], +[ + AC_REQUIRE([AC_LIB_RPATH]) + AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) + $1= + if test "$enable_rpath" != no; then + if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then + dnl Use an explicit option to hardcode directories into the resulting + dnl binary. + rpathdirs= + next= + for opt in $2; do + if test -n "$next"; then + dir="$next" + dnl No need to hardcode the standard /usr/lib. + if test "X$dir" != "X/usr/$acl_libdirstem" \ + && test "X$dir" != "X/usr/$acl_libdirstem2"; then + rpathdirs="$rpathdirs $dir" + fi + next= + else + case $opt in + -L) next=yes ;; + -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` + dnl No need to hardcode the standard /usr/lib. + if test "X$dir" != "X/usr/$acl_libdirstem" \ + && test "X$dir" != "X/usr/$acl_libdirstem2"; then + rpathdirs="$rpathdirs $dir" + fi + next= ;; + *) next= ;; + esac + fi + done + if test "X$rpathdirs" != "X"; then + if test -n ""$3""; then + dnl libtool is used for linking. Use -R options. + for dir in $rpathdirs; do + $1="${$1}${$1:+ }-R$dir" + done + else + dnl The linker is used for linking directly. + if test -n "$acl_hardcode_libdir_separator"; then + dnl Weird platform: only the last -rpath option counts, the user + dnl must pass all path elements in one option. + alldirs= + for dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" + done + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + $1="$flag" + else + dnl The -rpath options are cumulative. + for dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$dir" + eval flag=\"$acl_hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + $1="${$1}${$1:+ }$flag" + done + fi + fi + fi + fi + fi + AC_SUBST([$1]) +]) diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4 new file mode 100644 index 000000000..60908e8fb --- /dev/null +++ b/m4/lib-prefix.m4 @@ -0,0 +1,224 @@ +# lib-prefix.m4 serial 7 (gettext-0.18) +dnl Copyright (C) 2001-2005, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and +dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't +dnl require excessive bracketing. +ifdef([AC_HELP_STRING], +[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], +[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) + +dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed +dnl to access previously installed libraries. The basic assumption is that +dnl a user will want packages to use other packages he previously installed +dnl with the same --prefix option. +dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate +dnl libraries, but is otherwise very convenient. +AC_DEFUN([AC_LIB_PREFIX], +[ + AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_LIB_ARG_WITH([lib-prefix], +[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib + --without-lib-prefix don't search for libraries in includedir and libdir], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/$acl_libdirstem" + fi + fi +]) + if test $use_additional = yes; then + dnl Potentially add $additional_includedir to $CPPFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's already present in $CPPFLAGS, + dnl 3. if it's /usr/local/include and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + for x in $CPPFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux* | gnu* | k*bsd*-gnu) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $CPPFLAGS. + CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" + fi + fi + fi + fi + dnl Potentially add $additional_libdir to $LDFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's already present in $LDFLAGS, + dnl 3. if it's /usr/local/lib and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then + haveit= + for x in $LDFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LDFLAGS. + LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" + fi + fi + fi + fi + fi +]) + +dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, +dnl acl_final_exec_prefix, containing the values to which $prefix and +dnl $exec_prefix will expand at the end of the configure script. +AC_DEFUN([AC_LIB_PREPARE_PREFIX], +[ + dnl Unfortunately, prefix and exec_prefix get only finally determined + dnl at the end of configure. + if test "X$prefix" = "XNONE"; then + acl_final_prefix="$ac_default_prefix" + else + acl_final_prefix="$prefix" + fi + if test "X$exec_prefix" = "XNONE"; then + acl_final_exec_prefix='${prefix}' + else + acl_final_exec_prefix="$exec_prefix" + fi + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" + prefix="$acl_save_prefix" +]) + +dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the +dnl variables prefix and exec_prefix bound to the values they will have +dnl at the end of the configure script. +AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], +[ + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + $1 + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" +]) + +dnl AC_LIB_PREPARE_MULTILIB creates +dnl - a variable acl_libdirstem, containing the basename of the libdir, either +dnl "lib" or "lib64" or "lib/64", +dnl - a variable acl_libdirstem2, as a secondary possible value for +dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or +dnl "lib/amd64". +AC_DEFUN([AC_LIB_PREPARE_MULTILIB], +[ + dnl There is no formal standard regarding lib and lib64. + dnl On glibc systems, the current practice is that on a system supporting + dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under + dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine + dnl the compiler's default mode by looking at the compiler's library search + dnl path. If at least one of its elements ends in /lib64 or points to a + dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. + dnl Otherwise we use the default, namely "lib". + dnl On Solaris systems, the current practice is that on a system supporting + dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under + dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or + dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib. + AC_REQUIRE([AC_CANONICAL_HOST]) + acl_libdirstem=lib + acl_libdirstem2= + case "$host_os" in + solaris*) + dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment + dnl . + dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." + dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the + dnl symlink is missing, so we set acl_libdirstem2 too. + AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], + [AC_EGREP_CPP([sixtyfour bits], [ +#ifdef _LP64 +sixtyfour bits +#endif + ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) + ]) + if test $gl_cv_solaris_64bit = yes; then + acl_libdirstem=lib/64 + case "$host_cpu" in + sparc*) acl_libdirstem2=lib/sparcv9 ;; + i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; + esac + fi + ;; + *) + searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` + if test -n "$searchpath"; then + acl_save_IFS="${IFS= }"; IFS=":" + for searchdir in $searchpath; do + if test -d "$searchdir"; then + case "$searchdir" in + */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; + */../ | */.. ) + # Better ignore directories of this form. They are misleading. + ;; + *) searchdir=`cd "$searchdir" && pwd` + case "$searchdir" in + */lib64 ) acl_libdirstem=lib64 ;; + esac ;; + esac + fi + done + IFS="$acl_save_IFS" + fi + ;; + esac + test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" +]) diff --git a/m4/libunistring-base.m4 b/m4/libunistring-base.m4 new file mode 100644 index 000000000..d105c7217 --- /dev/null +++ b/m4/libunistring-base.m4 @@ -0,0 +1,141 @@ +# libunistring-base.m4 serial 5 +dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paolo Bonzini and Bruno Haible. + +dnl gl_LIBUNISTRING_MODULE([VERSION], [Module]) +dnl Declares that the source files of Module should be compiled, unless we +dnl are linking with libunistring and its version is >= the given VERSION. +dnl Defines an automake conditional LIBUNISTRING_COMPILE_$MODULE that is +dnl true if the source files of Module should be compiled. +dnl This macro is to be used for public libunistring API, not for +dnl undocumented API. +dnl +dnl You have to bump the VERSION argument to the next projected version +dnl number each time you make a change that affects the behaviour of the +dnl functions defined in Module (even if the sources of Module itself do not +dnl change). + +AC_DEFUN([gl_LIBUNISTRING_MODULE], +[ + AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE]) + dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from + dnl gl_LIBUNISTRING_CORE if that macro has been run. + AM_CONDITIONAL(AS_TR_CPP([LIBUNISTRING_COMPILE_$2]), + [gl_LIBUNISTRING_VERSION_CMP([$1])]) +]) + +dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile]) +dnl Declares that HeaderFile should be created, unless we are linking +dnl with libunistring and its version is >= the given VERSION. +dnl HeaderFile should be relative to the lib directory and end in '.h'. +dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty). +dnl +dnl When we are linking with the already installed libunistring and its version +dnl is < VERSION, we create HeaderFile here, because we may compile functions +dnl (via gl_LIBUNISTRING_MODULE above) that are not contained in the installed +dnl version. +dnl When we are linking with the already installed libunistring and its version +dnl is > VERSION, we don't create HeaderFile here: it could cause compilation +dnl errors in other libunistring header files if some types are missing. +dnl +dnl You have to bump the VERSION argument to the next projected version +dnl number each time you make a non-comment change to the HeaderFile. + +AC_DEFUN([gl_LIBUNISTRING_LIBHEADER], +[ + AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE]) + dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from + dnl gl_LIBUNISTRING_CORE if that macro has been run. + if gl_LIBUNISTRING_VERSION_CMP([$1]); then + LIBUNISTRING_[]AS_TR_CPP([$2])='$2' + else + LIBUNISTRING_[]AS_TR_CPP([$2])= + fi + AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2])) +]) + +dnl Miscellaneous preparations/initializations. + +AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE], +[ + dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point. + m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])]) + + AC_REQUIRE([AC_PROG_AWK]) + +dnl Sed expressions to extract the parts of a version number. +changequote(,) +gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;} +i\ +0 +q +' +gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;} +i\ +0 +q +' +gl_libunistring_sed_extract_subminor='/^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p;q;} +i\ +0 +q +' +changequote([,]) + + if test "$HAVE_LIBUNISTRING" = yes; then + LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"` + LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"` + LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"` + fi +]) + +dnl gl_LIBUNISTRING_VERSION_CMP([VERSION]) +dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION +dnl is less than the VERSION argument. +AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP], +[ { test "$HAVE_LIBUNISTRING" != yes \ + || { + dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least. + AS_LITERAL_IF([$1], + [dnl This is the optimized variant, that assumes the argument is a literal: + m4_pushdef([requested_version_major], + [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])]) + m4_pushdef([requested_version_minor], + [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])]) + m4_pushdef([requested_version_subminor], + [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])]) + test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \ + || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \ + && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \ + || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \ + && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor + } + } + } + m4_popdef([requested_version_subminor]) + m4_popdef([requested_version_minor]) + m4_popdef([requested_version_major]) + ], + [dnl This is the unoptimized variant: + requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"` + requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"` + requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"` + test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \ + || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \ + && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \ + || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \ + && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor + } + } + } + ]) + } + }]) + +dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the +dnl same as ORIG, otherwise to 0. +m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])]) diff --git a/m4/localcharset.m4 b/m4/localcharset.m4 new file mode 100644 index 000000000..2e93e5818 --- /dev/null +++ b/m4/localcharset.m4 @@ -0,0 +1,17 @@ +# localcharset.m4 serial 7 +dnl Copyright (C) 2002, 2004, 2006, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_LOCALCHARSET], +[ + dnl Prerequisites of lib/localcharset.c. + AC_REQUIRE([AM_LANGINFO_CODESET]) + AC_REQUIRE([gl_FCNTL_O_FLAGS]) + AC_CHECK_DECLS_ONCE([getc_unlocked]) + + dnl Prerequisites of the lib/Makefile.am snippet. + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([gl_GLIBC21]) +]) diff --git a/m4/locale-fr.m4 b/m4/locale-fr.m4 new file mode 100644 index 000000000..ef199e397 --- /dev/null +++ b/m4/locale-fr.m4 @@ -0,0 +1,250 @@ +# locale-fr.m4 serial 17 +dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Determine the name of a french locale with traditional encoding. +AC_DEFUN([gt_LOCALE_FR], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AM_LANGINFO_CODESET]) + AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ +changequote(,)dnl +#include +#include +#if HAVE_LANGINFO_CODESET +# include +#endif +#include +#include +struct tm t; +char buf[16]; +int main () { + /* Check whether the given locale name is recognized by the system. */ +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + /* On native Windows, setlocale(category, "") looks at the system settings, + not at the environment variables. Also, when an encoding suffix such + as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE + category of the locale to "C". */ + if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL + || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) + return 1; +#else + if (setlocale (LC_ALL, "") == NULL) return 1; +#endif + /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". + On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) + is empty, and the behaviour of Tcl 8.4 in this locale is not useful. + On OpenBSD 4.0, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "646". In this situation, + some unit tests fail. + On MirBSD 10, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "UTF-8". */ +#if HAVE_LANGINFO_CODESET + { + const char *cs = nl_langinfo (CODESET); + if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 + || strcmp (cs, "UTF-8") == 0) + return 1; + } +#endif +#ifdef __CYGWIN__ + /* On Cygwin, avoid locale names without encoding suffix, because the + locale_charset() function relies on the encoding suffix. Note that + LC_ALL is set on the command line. */ + if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; +#endif + /* Check whether in the abbreviation of the second month, the second + character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only + one byte long. This excludes the UTF-8 encoding. */ + t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; + if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1; +#if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy. */ + /* Check whether the decimal separator is a comma. + On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point + are nl_langinfo(RADIXCHAR) are both ".". */ + if (localeconv () ->decimal_point[0] != ',') return 1; +#endif + return 0; +} +changequote([,])dnl + ])]) + if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then + case "$host_os" in + # Handle native Windows specially, because there setlocale() interprets + # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256", + # "fr" or "fra" as "French" or "French_France.1252", + # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252", + # "ja" as "Japanese" or "Japanese_Japan.932", + # and similar. + mingw*) + # Test for the native Windows locale name. + if (LC_ALL=French_France.1252 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=French_France.1252 + else + # None found. + gt_cv_locale_fr=none + fi + ;; + *) + # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because + # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the + # configure script would override the LC_ALL setting. Likewise for + # LC_CTYPE, which is also set at the beginning of the configure script. + # Test for the usual locale name. + if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=fr_FR + else + # Test for the locale name with explicit encoding suffix. + if (LC_ALL=fr_FR.ISO-8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=fr_FR.ISO-8859-1 + else + # Test for the AIX, OSF/1, FreeBSD, NetBSD, OpenBSD locale name. + if (LC_ALL=fr_FR.ISO8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=fr_FR.ISO8859-1 + else + # Test for the HP-UX locale name. + if (LC_ALL=fr_FR.iso88591 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=fr_FR.iso88591 + else + # Test for the Solaris 7 locale name. + if (LC_ALL=fr LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr=fr + else + # None found. + gt_cv_locale_fr=none + fi + fi + fi + fi + fi + ;; + esac + fi + rm -fr conftest* + ]) + LOCALE_FR=$gt_cv_locale_fr + AC_SUBST([LOCALE_FR]) +]) + +dnl Determine the name of a french locale with UTF-8 encoding. +AC_DEFUN([gt_LOCALE_FR_UTF8], +[ + AC_REQUIRE([AM_LANGINFO_CODESET]) + AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ +changequote(,)dnl +#include +#include +#if HAVE_LANGINFO_CODESET +# include +#endif +#include +#include +struct tm t; +char buf[16]; +int main () { + /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl + imitates locale dependent behaviour by looking at the environment + variables, and all locales use the UTF-8 encoding. */ +#if !(defined __BEOS__ || defined __HAIKU__) + /* Check whether the given locale name is recognized by the system. */ +# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + /* On native Windows, setlocale(category, "") looks at the system settings, + not at the environment variables. Also, when an encoding suffix such + as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE + category of the locale to "C". */ + if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL + || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) + return 1; +# else + if (setlocale (LC_ALL, "") == NULL) return 1; +# endif + /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". + On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) + is empty, and the behaviour of Tcl 8.4 in this locale is not useful. + On OpenBSD 4.0, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "646". In this situation, + some unit tests fail. */ +# if HAVE_LANGINFO_CODESET + { + const char *cs = nl_langinfo (CODESET); + if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0) + return 1; + } +# endif +# ifdef __CYGWIN__ + /* On Cygwin, avoid locale names without encoding suffix, because the + locale_charset() function relies on the encoding suffix. Note that + LC_ALL is set on the command line. */ + if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; +# endif + /* Check whether in the abbreviation of the second month, the second + character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is + two bytes long, with UTF-8 encoding. */ + t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; + if (strftime (buf, sizeof (buf), "%b", &t) < 4 + || buf[1] != (char) 0xc3 || buf[2] != (char) 0xa9 || buf[3] != 'v') + return 1; +#endif +#if !defined __BIONIC__ /* Bionic libc's 'struct lconv' is just a dummy. */ + /* Check whether the decimal separator is a comma. + On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point + are nl_langinfo(RADIXCHAR) are both ".". */ + if (localeconv () ->decimal_point[0] != ',') return 1; +#endif + return 0; +} +changequote([,])dnl + ])]) + if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then + case "$host_os" in + # Handle native Windows specially, because there setlocale() interprets + # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256", + # "fr" or "fra" as "French" or "French_France.1252", + # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252", + # "ja" as "Japanese" or "Japanese_Japan.932", + # and similar. + mingw*) + # Test for the hypothetical native Windows locale name. + if (LC_ALL=French_France.65001 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr_utf8=French_France.65001 + else + # None found. + gt_cv_locale_fr_utf8=none + fi + ;; + *) + # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because + # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the + # configure script would override the LC_ALL setting. Likewise for + # LC_CTYPE, which is also set at the beginning of the configure script. + # Test for the usual locale name. + if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr_utf8=fr_FR + else + # Test for the locale name with explicit encoding suffix. + if (LC_ALL=fr_FR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr_utf8=fr_FR.UTF-8 + else + # Test for the Solaris 7 locale name. + if (LC_ALL=fr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_fr_utf8=fr.UTF-8 + else + # None found. + gt_cv_locale_fr_utf8=none + fi + fi + fi + ;; + esac + fi + rm -fr conftest* + ]) + LOCALE_FR_UTF8=$gt_cv_locale_fr_utf8 + AC_SUBST([LOCALE_FR_UTF8]) +]) diff --git a/m4/locale-ja.m4 b/m4/locale-ja.m4 new file mode 100644 index 000000000..132a3e779 --- /dev/null +++ b/m4/locale-ja.m4 @@ -0,0 +1,136 @@ +# locale-ja.m4 serial 12 +dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Determine the name of a japanese locale with EUC-JP encoding. +AC_DEFUN([gt_LOCALE_JA], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AM_LANGINFO_CODESET]) + AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ +changequote(,)dnl +#include +#include +#if HAVE_LANGINFO_CODESET +# include +#endif +#include +#include +struct tm t; +char buf[16]; +int main () +{ + const char *p; + /* Check whether the given locale name is recognized by the system. */ +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + /* On native Windows, setlocale(category, "") looks at the system settings, + not at the environment variables. Also, when an encoding suffix such + as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE + category of the locale to "C". */ + if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL + || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) + return 1; +#else + if (setlocale (LC_ALL, "") == NULL) return 1; +#endif + /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". + On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) + is empty, and the behaviour of Tcl 8.4 in this locale is not useful. + On OpenBSD 4.0, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "646". In this situation, + some unit tests fail. + On MirBSD 10, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "UTF-8". */ +#if HAVE_LANGINFO_CODESET + { + const char *cs = nl_langinfo (CODESET); + if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 + || strcmp (cs, "UTF-8") == 0) + return 1; + } +#endif +#ifdef __CYGWIN__ + /* On Cygwin, avoid locale names without encoding suffix, because the + locale_charset() function relies on the encoding suffix. Note that + LC_ALL is set on the command line. */ + if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; +#endif + /* Check whether MB_CUR_MAX is > 1. This excludes the dysfunctional locales + on Cygwin 1.5.x. */ + if (MB_CUR_MAX == 1) + return 1; + /* Check whether in a month name, no byte in the range 0x80..0x9F occurs. + This excludes the UTF-8 encoding (except on MirBSD). */ + t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; + if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1; + for (p = buf; *p != '\0'; p++) + if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0) + return 1; + return 0; +} +changequote([,])dnl + ])]) + if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then + case "$host_os" in + # Handle native Windows specially, because there setlocale() interprets + # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256", + # "fr" or "fra" as "French" or "French_France.1252", + # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252", + # "ja" as "Japanese" or "Japanese_Japan.932", + # and similar. + mingw*) + # Note that on native Windows, the Japanese locale is + # Japanese_Japan.932, and CP932 is very different from EUC-JP, so we + # cannot use it here. + gt_cv_locale_ja=none + ;; + *) + # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because + # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the + # configure script would override the LC_ALL setting. Likewise for + # LC_CTYPE, which is also set at the beginning of the configure script. + # Test for the AIX locale name. + if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_ja=ja_JP + else + # Test for the locale name with explicit encoding suffix. + if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_ja=ja_JP.EUC-JP + else + # Test for the HP-UX, OSF/1, NetBSD locale name. + if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_ja=ja_JP.eucJP + else + # Test for the IRIX, FreeBSD locale name. + if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_ja=ja_JP.EUC + else + # Test for the Solaris 7 locale name. + if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_ja=ja + else + # Special test for NetBSD 1.6. + if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then + gt_cv_locale_ja=ja_JP.eucJP + else + # None found. + gt_cv_locale_ja=none + fi + fi + fi + fi + fi + fi + ;; + esac + fi + rm -fr conftest* + ]) + LOCALE_JA=$gt_cv_locale_ja + AC_SUBST([LOCALE_JA]) +]) diff --git a/m4/locale-zh.m4 b/m4/locale-zh.m4 new file mode 100644 index 000000000..4eed73f40 --- /dev/null +++ b/m4/locale-zh.m4 @@ -0,0 +1,130 @@ +# locale-zh.m4 serial 12 +dnl Copyright (C) 2003, 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Determine the name of a chinese locale with GB18030 encoding. +AC_DEFUN([gt_LOCALE_ZH_CN], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AM_LANGINFO_CODESET]) + AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [ + AC_LANG_CONFTEST([AC_LANG_SOURCE([ +changequote(,)dnl +#include +#include +#include +#if HAVE_LANGINFO_CODESET +# include +#endif +#include +#include +struct tm t; +char buf[16]; +int main () +{ + const char *p; + /* Check whether the given locale name is recognized by the system. */ +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + /* On native Windows, setlocale(category, "") looks at the system settings, + not at the environment variables. Also, when an encoding suffix such + as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE + category of the locale to "C". */ + if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL + || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0) + return 1; +#else + if (setlocale (LC_ALL, "") == NULL) return 1; +#endif + /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646". + On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET) + is empty, and the behaviour of Tcl 8.4 in this locale is not useful. + On OpenBSD 4.0, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "646". In this situation, + some unit tests fail. + On MirBSD 10, when an unsupported locale is specified, setlocale() + succeeds but then nl_langinfo(CODESET) is "UTF-8". */ +#if HAVE_LANGINFO_CODESET + { + const char *cs = nl_langinfo (CODESET); + if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0 + || strcmp (cs, "UTF-8") == 0) + return 1; + } +#endif +#ifdef __CYGWIN__ + /* On Cygwin, avoid locale names without encoding suffix, because the + locale_charset() function relies on the encoding suffix. Note that + LC_ALL is set on the command line. */ + if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1; +#endif + /* Check whether in a month name, no byte in the range 0x80..0x9F occurs. + This excludes the UTF-8 encoding (except on MirBSD). */ + t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4; + if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1; + for (p = buf; *p != '\0'; p++) + if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0) + return 1; + /* Check whether a typical GB18030 multibyte sequence is recognized as a + single wide character. This excludes the GB2312 and GBK encodings. */ + if (mblen ("\203\062\332\066", 5) != 4) + return 1; + return 0; +} +changequote([,])dnl + ])]) + if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then + case "$host_os" in + # Handle native Windows specially, because there setlocale() interprets + # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256", + # "fr" or "fra" as "French" or "French_France.1252", + # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252", + # "ja" as "Japanese" or "Japanese_Japan.932", + # and similar. + mingw*) + # Test for the hypothetical native Windows locale name. + if (LC_ALL=Chinese_China.54936 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_zh_CN=Chinese_China.54936 + else + # None found. + gt_cv_locale_zh_CN=none + fi + ;; + solaris2.8) + # On Solaris 8, the locales zh_CN.GB18030, zh_CN.GBK, zh.GBK are + # broken. One witness is the test case in gl_MBRTOWC_SANITYCHECK. + # Another witness is that "LC_ALL=zh_CN.GB18030 bash -c true" dumps core. + gt_cv_locale_zh_CN=none + ;; + *) + # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because + # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the + # configure script would override the LC_ALL setting. Likewise for + # LC_CTYPE, which is also set at the beginning of the configure script. + # Test for the locale name without encoding suffix. + if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_zh_CN=zh_CN + else + # Test for the locale name with explicit encoding suffix. + if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then + gt_cv_locale_zh_CN=zh_CN.GB18030 + else + # None found. + gt_cv_locale_zh_CN=none + fi + fi + ;; + esac + else + # If there was a link error, due to mblen(), the system is so old that + # it certainly doesn't have a chinese locale. + gt_cv_locale_zh_CN=none + fi + rm -fr conftest* + ]) + LOCALE_ZH_CN=$gt_cv_locale_zh_CN + AC_SUBST([LOCALE_ZH_CN]) +]) diff --git a/m4/locale_h.m4 b/m4/locale_h.m4 new file mode 100644 index 000000000..8bd12e80e --- /dev/null +++ b/m4/locale_h.m4 @@ -0,0 +1,122 @@ +# locale_h.m4 serial 19 +dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_LOCALE_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_LOCALE_H_DEFAULTS]) + + dnl Persuade glibc to define locale_t and the int_p_*, int_n_* + dnl members of 'struct lconv'. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl If is replaced, then must also be replaced. + AC_REQUIRE([gl_STDDEF_H]) + + dnl Solaris 11 2011-11 defines the int_p_*, int_n_* members of 'struct lconv' + dnl only if _LCONV_C99 is defined. + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + solaris*) + AC_DEFINE([_LCONV_C99], [1], [Define to 1 on Solaris.]) + ;; + esac + + AC_CACHE_CHECK([whether locale.h conforms to POSIX:2001], + [gl_cv_header_locale_h_posix2001], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + int x = LC_MESSAGES; + int y = sizeof (((struct lconv *) 0)->decimal_point);]], + [[]])], + [gl_cv_header_locale_h_posix2001=yes], + [gl_cv_header_locale_h_posix2001=no])]) + + dnl Check for . + AC_CHECK_HEADERS_ONCE([xlocale.h]) + if test $ac_cv_header_xlocale_h = yes; then + HAVE_XLOCALE_H=1 + dnl Check whether use of locale_t requires inclusion of , + dnl e.g. on Mac OS X 10.5. If does not define locale_t by + dnl itself, we assume that will do so. + AC_CACHE_CHECK([whether locale.h defines locale_t], + [gl_cv_header_locale_has_locale_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + locale_t x;]], + [[]])], + [gl_cv_header_locale_has_locale_t=yes], + [gl_cv_header_locale_has_locale_t=no]) + ]) + if test $gl_cv_header_locale_has_locale_t = yes; then + gl_cv_header_locale_h_needs_xlocale_h=no + else + gl_cv_header_locale_h_needs_xlocale_h=yes + fi + else + HAVE_XLOCALE_H=0 + gl_cv_header_locale_h_needs_xlocale_h=no + fi + AC_SUBST([HAVE_XLOCALE_H]) + + dnl Check whether 'struct lconv' is complete. + dnl Bionic libc's 'struct lconv' is just a dummy. + dnl On OpenBSD 4.9, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin 1.5.x, + dnl mingw, MSVC 9, it lacks the int_p_* and int_n_* members. + AC_CACHE_CHECK([whether struct lconv is properly defined], + [gl_cv_sys_struct_lconv_ok], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + struct lconv l; + int x = sizeof (l.decimal_point); + int y = sizeof (l.int_p_cs_precedes);]], + [[]])], + [gl_cv_sys_struct_lconv_ok=yes], + [gl_cv_sys_struct_lconv_ok=no]) + ]) + if test $gl_cv_sys_struct_lconv_ok = no; then + REPLACE_STRUCT_LCONV=1 + fi + + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_NEXT_HEADERS([locale.h]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include +/* Some systems provide declarations in a non-standard header. */ +#if HAVE_XLOCALE_H +# include +#endif + ]], + [setlocale duplocale]) +]) + +AC_DEFUN([gl_LOCALE_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_LOCALE_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_LOCALE_H_DEFAULTS], +[ + GNULIB_LOCALECONV=0; AC_SUBST([GNULIB_LOCALECONV]) + GNULIB_SETLOCALE=0; AC_SUBST([GNULIB_SETLOCALE]) + GNULIB_DUPLOCALE=0; AC_SUBST([GNULIB_DUPLOCALE]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_DUPLOCALE=1; AC_SUBST([HAVE_DUPLOCALE]) + REPLACE_LOCALECONV=0; AC_SUBST([REPLACE_LOCALECONV]) + REPLACE_SETLOCALE=0; AC_SUBST([REPLACE_SETLOCALE]) + REPLACE_DUPLOCALE=0; AC_SUBST([REPLACE_DUPLOCALE]) + REPLACE_STRUCT_LCONV=0; AC_SUBST([REPLACE_STRUCT_LCONV]) +]) diff --git a/m4/localeconv.m4 b/m4/localeconv.m4 new file mode 100644 index 000000000..b8bb5964b --- /dev/null +++ b/m4/localeconv.m4 @@ -0,0 +1,22 @@ +# localeconv.m4 serial 1 +dnl Copyright (C) 2012-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_LOCALECONV], +[ + AC_REQUIRE([gl_LOCALE_H_DEFAULTS]) + AC_REQUIRE([gl_LOCALE_H]) + + if test $REPLACE_STRUCT_LCONV = 1; then + REPLACE_LOCALECONV=1 + fi +]) + +# Prerequisites of lib/localeconv.c. +AC_DEFUN([gl_PREREQ_LOCALECONV], +[ + AC_CHECK_MEMBERS([struct lconv.decimal_point], [], [], + [[#include ]]) +]) diff --git a/m4/lock.m4 b/m4/lock.m4 new file mode 100644 index 000000000..d3fc1eff0 --- /dev/null +++ b/m4/lock.m4 @@ -0,0 +1,39 @@ +# lock.m4 serial 13 (gettext-0.18.2) +dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gl_LOCK], +[ + AC_REQUIRE([gl_THREADLIB]) + if test "$gl_threads_api" = posix; then + # OSF/1 4.0 and Mac OS X 10.1 lack the pthread_rwlock_t type and the + # pthread_rwlock_* functions. + AC_CHECK_TYPE([pthread_rwlock_t], + [AC_DEFINE([HAVE_PTHREAD_RWLOCK], [1], + [Define if the POSIX multithreading library has read/write locks.])], + [], + [#include ]) + # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [[#include ]], + [[ +#if __FreeBSD__ == 4 +error "No, in FreeBSD 4.0 recursive mutexes actually don't work." +#else +int x = (int)PTHREAD_MUTEX_RECURSIVE; +return !x; +#endif + ]])], + [AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], [1], + [Define if the defines PTHREAD_MUTEX_RECURSIVE.])]) + fi + gl_PREREQ_LOCK +]) + +# Prerequisites of lib/glthread/lock.c. +AC_DEFUN([gl_PREREQ_LOCK], [:]) diff --git a/m4/longlong.m4 b/m4/longlong.m4 new file mode 100644 index 000000000..3af6ab5aa --- /dev/null +++ b/m4/longlong.m4 @@ -0,0 +1,113 @@ +# longlong.m4 serial 17 +dnl Copyright (C) 1999-2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +# Define HAVE_LONG_LONG_INT if 'long long int' works. +# This fixes a bug in Autoconf 2.61, and can be faster +# than what's in Autoconf 2.62 through 2.68. + +# Note: If the type 'long long int' exists but is only 32 bits large +# (as on some very old compilers), HAVE_LONG_LONG_INT will not be +# defined. In this case you can treat 'long long int' like 'long int'. + +AC_DEFUN([AC_TYPE_LONG_LONG_INT], +[ + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], + [ac_cv_type_long_long_int=yes + if test "x${ac_cv_prog_cc_c99-no}" = xno; then + ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int + if test $ac_cv_type_long_long_int = yes; then + dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. + dnl If cross compiling, assume the bug is not important, since + dnl nobody cross compiles for this platform as far as we know. + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@include + @%:@ifndef LLONG_MAX + @%:@ define HALF \ + (1LL << (sizeof (long long int) * CHAR_BIT - 2)) + @%:@ define LLONG_MAX (HALF - 1 + HALF) + @%:@endif]], + [[long long int n = 1; + int i; + for (i = 0; ; i++) + { + long long int m = n << i; + if (m >> i != n) + return 1; + if (LLONG_MAX / 2 < m) + break; + } + return 0;]])], + [], + [ac_cv_type_long_long_int=no], + [:]) + fi + fi]) + if test $ac_cv_type_long_long_int = yes; then + AC_DEFINE([HAVE_LONG_LONG_INT], [1], + [Define to 1 if the system has the type 'long long int'.]) + fi +]) + +# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. +# This fixes a bug in Autoconf 2.61, and can be faster +# than what's in Autoconf 2.62 through 2.68. + +# Note: If the type 'unsigned long long int' exists but is only 32 bits +# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT +# will not be defined. In this case you can treat 'unsigned long long int' +# like 'unsigned long int'. + +AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], +[ + AC_CACHE_CHECK([for unsigned long long int], + [ac_cv_type_unsigned_long_long_int], + [ac_cv_type_unsigned_long_long_int=yes + if test "x${ac_cv_prog_cc_c99-no}" = xno; then + AC_LINK_IFELSE( + [_AC_TYPE_LONG_LONG_SNIPPET], + [], + [ac_cv_type_unsigned_long_long_int=no]) + fi]) + if test $ac_cv_type_unsigned_long_long_int = yes; then + AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1], + [Define to 1 if the system has the type 'unsigned long long int'.]) + fi +]) + +# Expands to a C program that can be used to test for simultaneous support +# of 'long long' and 'unsigned long long'. We don't want to say that +# 'long long' is available if 'unsigned long long' is not, or vice versa, +# because too many programs rely on the symmetry between signed and unsigned +# integer types (excluding 'bool'). +AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], +[ + AC_LANG_PROGRAM( + [[/* For now, do not test the preprocessor; as of 2007 there are too many + implementations with broken preprocessors. Perhaps this can + be revisited in 2012. In the meantime, code should not expect + #if to work with literals wider than 32 bits. */ + /* Test literals. */ + long long int ll = 9223372036854775807ll; + long long int nll = -9223372036854775807LL; + unsigned long long int ull = 18446744073709551615ULL; + /* Test constant expressions. */ + typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) + ? 1 : -1)]; + typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 + ? 1 : -1)]; + int i = 63;]], + [[/* Test availability of runtime routines for shift and division. */ + long long int llmax = 9223372036854775807ll; + unsigned long long int ullmax = 18446744073709551615ull; + return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) + | (llmax / ll) | (llmax % ll) + | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) + | (ullmax / ull) | (ullmax % ull));]]) +]) diff --git a/m4/malloc.m4 b/m4/malloc.m4 new file mode 100644 index 000000000..4b24a0b11 --- /dev/null +++ b/m4/malloc.m4 @@ -0,0 +1,98 @@ +# malloc.m4 serial 14 +dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +m4_version_prereq([2.70], [] ,[ + +# This is taken from the following Autoconf patch: +# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 +AC_DEFUN([_AC_FUNC_MALLOC_IF], +[ + AC_REQUIRE([AC_HEADER_STDC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles + AC_CHECK_HEADERS([stdlib.h]) + AC_CACHE_CHECK([for GNU libc compatible malloc], + [ac_cv_func_malloc_0_nonnull], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H + # include + #else + char *malloc (); + #endif + ]], + [[return ! malloc (0);]]) + ], + [ac_cv_func_malloc_0_nonnull=yes], + [ac_cv_func_malloc_0_nonnull=no], + [case "$host_os" in + # Guess yes on platforms where we know the result. + *-gnu* | freebsd* | netbsd* | openbsd* \ + | hpux* | solaris* | cygwin* | mingw*) + ac_cv_func_malloc_0_nonnull=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_malloc_0_nonnull=no ;; + esac + ]) + ]) + AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2]) +])# _AC_FUNC_MALLOC_IF + +]) + +# gl_FUNC_MALLOC_GNU +# ------------------ +# Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if +# it is not. +AC_DEFUN([gl_FUNC_MALLOC_GNU], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + dnl _AC_FUNC_MALLOC_IF is defined in Autoconf. + _AC_FUNC_MALLOC_IF( + [AC_DEFINE([HAVE_MALLOC_GNU], [1], + [Define to 1 if your system has a GNU libc compatible 'malloc' + function, and to 0 otherwise.])], + [AC_DEFINE([HAVE_MALLOC_GNU], [0]) + REPLACE_MALLOC=1 + ]) +]) + +# gl_FUNC_MALLOC_POSIX +# -------------------- +# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it +# fails), and replace malloc if it is not. +AC_DEFUN([gl_FUNC_MALLOC_POSIX], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) + if test $gl_cv_func_malloc_posix = yes; then + AC_DEFINE([HAVE_MALLOC_POSIX], [1], + [Define if the 'malloc' function is POSIX compliant.]) + else + REPLACE_MALLOC=1 + fi +]) + +# Test whether malloc, realloc, calloc are POSIX compliant, +# Set gl_cv_func_malloc_posix to yes or no accordingly. +AC_DEFUN([gl_CHECK_MALLOC_POSIX], +[ + AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant], + [gl_cv_func_malloc_posix], + [ + dnl It is too dangerous to try to allocate a large amount of memory: + dnl some systems go to their knees when you do that. So assume that + dnl all Unix implementations of the function are POSIX compliant. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[]], + [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + choke me + #endif + ]])], + [gl_cv_func_malloc_posix=yes], + [gl_cv_func_malloc_posix=no]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 new file mode 100644 index 000000000..bf0845fd1 --- /dev/null +++ b/m4/math_h.m4 @@ -0,0 +1,353 @@ +# math_h.m4 serial 114 +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_MATH_H], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + gl_CHECK_NEXT_HEADERS([math.h]) + + AC_CACHE_CHECK([whether NAN macro works], [gl_cv_header_math_nan_works], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], + [[/* Solaris 10 has a broken definition of NAN. Other platforms + fail to provide NAN, or provide it only in C99 mode; this + test only needs to fail when NAN is provided but wrong. */ + float f = 1.0f; +#ifdef NAN + f = NAN; +#endif + return f == 0;]])], + [gl_cv_header_math_nan_works=yes], + [gl_cv_header_math_nan_works=no])]) + if test $gl_cv_header_math_nan_works = no; then + REPLACE_NAN=1 + fi + AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], + [[/* Solaris 10 has a broken definition of HUGE_VAL. */ + double d = HUGE_VAL; + return d == 0;]])], + [gl_cv_header_math_huge_val_works=yes], + [gl_cv_header_math_huge_val_works=no])]) + if test $gl_cv_header_math_huge_val_works = no; then + REPLACE_HUGE_VAL=1 + fi + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include ]], + [acosf acosl asinf asinl atanf atanl + cbrt cbrtf cbrtl ceilf ceill copysign copysignf copysignl cosf cosl coshf + expf expl exp2 exp2f exp2l expm1 expm1f expm1l + fabsf fabsl floorf floorl fma fmaf fmal + fmod fmodf fmodl frexpf frexpl hypotf hypotl + ilogb ilogbf ilogbl + ldexpf ldexpl + log logf logl log10 log10f log10l log1p log1pf log1pl log2 log2f log2l + logb logbf logbl + modf modff modfl powf + remainder remainderf remainderl + rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl + tanf tanl tanhf trunc truncf truncl]) +]) + +AC_DEFUN([gl_MATH_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_MATH_H_DEFAULTS], +[ + GNULIB_ACOSF=0; AC_SUBST([GNULIB_ACOSF]) + GNULIB_ACOSL=0; AC_SUBST([GNULIB_ACOSL]) + GNULIB_ASINF=0; AC_SUBST([GNULIB_ASINF]) + GNULIB_ASINL=0; AC_SUBST([GNULIB_ASINL]) + GNULIB_ATANF=0; AC_SUBST([GNULIB_ATANF]) + GNULIB_ATANL=0; AC_SUBST([GNULIB_ATANL]) + GNULIB_ATAN2F=0; AC_SUBST([GNULIB_ATAN2F]) + GNULIB_CBRT=0; AC_SUBST([GNULIB_CBRT]) + GNULIB_CBRTF=0; AC_SUBST([GNULIB_CBRTF]) + GNULIB_CBRTL=0; AC_SUBST([GNULIB_CBRTL]) + GNULIB_CEIL=0; AC_SUBST([GNULIB_CEIL]) + GNULIB_CEILF=0; AC_SUBST([GNULIB_CEILF]) + GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) + GNULIB_COPYSIGN=0; AC_SUBST([GNULIB_COPYSIGN]) + GNULIB_COPYSIGNF=0; AC_SUBST([GNULIB_COPYSIGNF]) + GNULIB_COPYSIGNL=0; AC_SUBST([GNULIB_COPYSIGNL]) + GNULIB_COSF=0; AC_SUBST([GNULIB_COSF]) + GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) + GNULIB_COSHF=0; AC_SUBST([GNULIB_COSHF]) + GNULIB_EXPF=0; AC_SUBST([GNULIB_EXPF]) + GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) + GNULIB_EXP2=0; AC_SUBST([GNULIB_EXP2]) + GNULIB_EXP2F=0; AC_SUBST([GNULIB_EXP2F]) + GNULIB_EXP2L=0; AC_SUBST([GNULIB_EXP2L]) + GNULIB_EXPM1=0; AC_SUBST([GNULIB_EXPM1]) + GNULIB_EXPM1F=0; AC_SUBST([GNULIB_EXPM1F]) + GNULIB_EXPM1L=0; AC_SUBST([GNULIB_EXPM1L]) + GNULIB_FABSF=0; AC_SUBST([GNULIB_FABSF]) + GNULIB_FABSL=0; AC_SUBST([GNULIB_FABSL]) + GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) + GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) + GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) + GNULIB_FMA=0; AC_SUBST([GNULIB_FMA]) + GNULIB_FMAF=0; AC_SUBST([GNULIB_FMAF]) + GNULIB_FMAL=0; AC_SUBST([GNULIB_FMAL]) + GNULIB_FMOD=0; AC_SUBST([GNULIB_FMOD]) + GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) + GNULIB_FMODL=0; AC_SUBST([GNULIB_FMODL]) + GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF]) + GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) + GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) + GNULIB_HYPOT=0; AC_SUBST([GNULIB_HYPOT]) + GNULIB_HYPOTF=0; AC_SUBST([GNULIB_HYPOTF]) + GNULIB_HYPOTL=0; AC_SUBST([GNULIB_HYPOTL]) + GNULIB_ILOGB=0; AC_SUBST([GNULIB_ILOGB]) + GNULIB_ILOGBF=0; AC_SUBST([GNULIB_ILOGBF]) + GNULIB_ILOGBL=0; AC_SUBST([GNULIB_ILOGBL]) + GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE]) + GNULIB_ISINF=0; AC_SUBST([GNULIB_ISINF]) + GNULIB_ISNAN=0; AC_SUBST([GNULIB_ISNAN]) + GNULIB_ISNANF=0; AC_SUBST([GNULIB_ISNANF]) + GNULIB_ISNAND=0; AC_SUBST([GNULIB_ISNAND]) + GNULIB_ISNANL=0; AC_SUBST([GNULIB_ISNANL]) + GNULIB_LDEXPF=0; AC_SUBST([GNULIB_LDEXPF]) + GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) + GNULIB_LOG=0; AC_SUBST([GNULIB_LOG]) + GNULIB_LOGF=0; AC_SUBST([GNULIB_LOGF]) + GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) + GNULIB_LOG10=0; AC_SUBST([GNULIB_LOG10]) + GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) + GNULIB_LOG10L=0; AC_SUBST([GNULIB_LOG10L]) + GNULIB_LOG1P=0; AC_SUBST([GNULIB_LOG1P]) + GNULIB_LOG1PF=0; AC_SUBST([GNULIB_LOG1PF]) + GNULIB_LOG1PL=0; AC_SUBST([GNULIB_LOG1PL]) + GNULIB_LOG2=0; AC_SUBST([GNULIB_LOG2]) + GNULIB_LOG2F=0; AC_SUBST([GNULIB_LOG2F]) + GNULIB_LOG2L=0; AC_SUBST([GNULIB_LOG2L]) + GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB]) + GNULIB_LOGBF=0; AC_SUBST([GNULIB_LOGBF]) + GNULIB_LOGBL=0; AC_SUBST([GNULIB_LOGBL]) + GNULIB_MODF=0; AC_SUBST([GNULIB_MODF]) + GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) + GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL]) + GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) + GNULIB_REMAINDER=0; AC_SUBST([GNULIB_REMAINDER]) + GNULIB_REMAINDERF=0; AC_SUBST([GNULIB_REMAINDERF]) + GNULIB_REMAINDERL=0; AC_SUBST([GNULIB_REMAINDERL]) + GNULIB_RINT=0; AC_SUBST([GNULIB_RINT]) + GNULIB_RINTF=0; AC_SUBST([GNULIB_RINTF]) + GNULIB_RINTL=0; AC_SUBST([GNULIB_RINTL]) + GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) + GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) + GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) + GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT]) + GNULIB_SINF=0; AC_SUBST([GNULIB_SINF]) + GNULIB_SINL=0; AC_SUBST([GNULIB_SINL]) + GNULIB_SINHF=0; AC_SUBST([GNULIB_SINHF]) + GNULIB_SQRTF=0; AC_SUBST([GNULIB_SQRTF]) + GNULIB_SQRTL=0; AC_SUBST([GNULIB_SQRTL]) + GNULIB_TANF=0; AC_SUBST([GNULIB_TANF]) + GNULIB_TANL=0; AC_SUBST([GNULIB_TANL]) + GNULIB_TANHF=0; AC_SUBST([GNULIB_TANHF]) + GNULIB_TRUNC=0; AC_SUBST([GNULIB_TRUNC]) + GNULIB_TRUNCF=0; AC_SUBST([GNULIB_TRUNCF]) + GNULIB_TRUNCL=0; AC_SUBST([GNULIB_TRUNCL]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_ACOSF=1; AC_SUBST([HAVE_ACOSF]) + HAVE_ACOSL=1; AC_SUBST([HAVE_ACOSL]) + HAVE_ASINF=1; AC_SUBST([HAVE_ASINF]) + HAVE_ASINL=1; AC_SUBST([HAVE_ASINL]) + HAVE_ATANF=1; AC_SUBST([HAVE_ATANF]) + HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) + HAVE_ATAN2F=1; AC_SUBST([HAVE_ATAN2F]) + HAVE_CBRT=1; AC_SUBST([HAVE_CBRT]) + HAVE_CBRTF=1; AC_SUBST([HAVE_CBRTF]) + HAVE_CBRTL=1; AC_SUBST([HAVE_CBRTL]) + HAVE_COPYSIGN=1; AC_SUBST([HAVE_COPYSIGN]) + HAVE_COPYSIGNL=1; AC_SUBST([HAVE_COPYSIGNL]) + HAVE_COSF=1; AC_SUBST([HAVE_COSF]) + HAVE_COSL=1; AC_SUBST([HAVE_COSL]) + HAVE_COSHF=1; AC_SUBST([HAVE_COSHF]) + HAVE_EXPF=1; AC_SUBST([HAVE_EXPF]) + HAVE_EXPL=1; AC_SUBST([HAVE_EXPL]) + HAVE_EXPM1=1; AC_SUBST([HAVE_EXPM1]) + HAVE_EXPM1F=1; AC_SUBST([HAVE_EXPM1F]) + HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) + HAVE_FABSL=1; AC_SUBST([HAVE_FABSL]) + HAVE_FMA=1; AC_SUBST([HAVE_FMA]) + HAVE_FMAF=1; AC_SUBST([HAVE_FMAF]) + HAVE_FMAL=1; AC_SUBST([HAVE_FMAL]) + HAVE_FMODF=1; AC_SUBST([HAVE_FMODF]) + HAVE_FMODL=1; AC_SUBST([HAVE_FMODL]) + HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF]) + HAVE_HYPOTF=1; AC_SUBST([HAVE_HYPOTF]) + HAVE_HYPOTL=1; AC_SUBST([HAVE_HYPOTL]) + HAVE_ILOGB=1; AC_SUBST([HAVE_ILOGB]) + HAVE_ILOGBF=1; AC_SUBST([HAVE_ILOGBF]) + HAVE_ILOGBL=1; AC_SUBST([HAVE_ILOGBL]) + HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) + HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) + HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) + HAVE_LDEXPF=1; AC_SUBST([HAVE_LDEXPF]) + HAVE_LOGF=1; AC_SUBST([HAVE_LOGF]) + HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) + HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F]) + HAVE_LOG10L=1; AC_SUBST([HAVE_LOG10L]) + HAVE_LOG1P=1; AC_SUBST([HAVE_LOG1P]) + HAVE_LOG1PF=1; AC_SUBST([HAVE_LOG1PF]) + HAVE_LOG1PL=1; AC_SUBST([HAVE_LOG1PL]) + HAVE_LOGBF=1; AC_SUBST([HAVE_LOGBF]) + HAVE_LOGBL=1; AC_SUBST([HAVE_LOGBL]) + HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) + HAVE_MODFL=1; AC_SUBST([HAVE_MODFL]) + HAVE_POWF=1; AC_SUBST([HAVE_POWF]) + HAVE_REMAINDER=1; AC_SUBST([HAVE_REMAINDER]) + HAVE_REMAINDERF=1; AC_SUBST([HAVE_REMAINDERF]) + HAVE_RINT=1; AC_SUBST([HAVE_RINT]) + HAVE_RINTL=1; AC_SUBST([HAVE_RINTL]) + HAVE_SINF=1; AC_SUBST([HAVE_SINF]) + HAVE_SINL=1; AC_SUBST([HAVE_SINL]) + HAVE_SINHF=1; AC_SUBST([HAVE_SINHF]) + HAVE_SQRTF=1; AC_SUBST([HAVE_SQRTF]) + HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) + HAVE_TANF=1; AC_SUBST([HAVE_TANF]) + HAVE_TANL=1; AC_SUBST([HAVE_TANL]) + HAVE_TANHF=1; AC_SUBST([HAVE_TANHF]) + HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) + HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) + HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) + HAVE_DECL_CBRTF=1; AC_SUBST([HAVE_DECL_CBRTF]) + HAVE_DECL_CBRTL=1; AC_SUBST([HAVE_DECL_CBRTL]) + HAVE_DECL_CEILF=1; AC_SUBST([HAVE_DECL_CEILF]) + HAVE_DECL_CEILL=1; AC_SUBST([HAVE_DECL_CEILL]) + HAVE_DECL_COPYSIGNF=1; AC_SUBST([HAVE_DECL_COPYSIGNF]) + HAVE_DECL_COSL=1; AC_SUBST([HAVE_DECL_COSL]) + HAVE_DECL_EXPL=1; AC_SUBST([HAVE_DECL_EXPL]) + HAVE_DECL_EXP2=1; AC_SUBST([HAVE_DECL_EXP2]) + HAVE_DECL_EXP2F=1; AC_SUBST([HAVE_DECL_EXP2F]) + HAVE_DECL_EXP2L=1; AC_SUBST([HAVE_DECL_EXP2L]) + HAVE_DECL_EXPM1L=1; AC_SUBST([HAVE_DECL_EXPM1L]) + HAVE_DECL_FLOORF=1; AC_SUBST([HAVE_DECL_FLOORF]) + HAVE_DECL_FLOORL=1; AC_SUBST([HAVE_DECL_FLOORL]) + HAVE_DECL_FREXPL=1; AC_SUBST([HAVE_DECL_FREXPL]) + HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL]) + HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL]) + HAVE_DECL_LOG10L=1; AC_SUBST([HAVE_DECL_LOG10L]) + HAVE_DECL_LOG2=1; AC_SUBST([HAVE_DECL_LOG2]) + HAVE_DECL_LOG2F=1; AC_SUBST([HAVE_DECL_LOG2F]) + HAVE_DECL_LOG2L=1; AC_SUBST([HAVE_DECL_LOG2L]) + HAVE_DECL_LOGB=1; AC_SUBST([HAVE_DECL_LOGB]) + HAVE_DECL_REMAINDER=1; AC_SUBST([HAVE_DECL_REMAINDER]) + HAVE_DECL_REMAINDERL=1; AC_SUBST([HAVE_DECL_REMAINDERL]) + HAVE_DECL_RINTF=1; AC_SUBST([HAVE_DECL_RINTF]) + HAVE_DECL_ROUND=1; AC_SUBST([HAVE_DECL_ROUND]) + HAVE_DECL_ROUNDF=1; AC_SUBST([HAVE_DECL_ROUNDF]) + HAVE_DECL_ROUNDL=1; AC_SUBST([HAVE_DECL_ROUNDL]) + HAVE_DECL_SINL=1; AC_SUBST([HAVE_DECL_SINL]) + HAVE_DECL_SQRTL=1; AC_SUBST([HAVE_DECL_SQRTL]) + HAVE_DECL_TANL=1; AC_SUBST([HAVE_DECL_TANL]) + HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC]) + HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF]) + HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL]) + REPLACE_CBRTF=0; AC_SUBST([REPLACE_CBRTF]) + REPLACE_CBRTL=0; AC_SUBST([REPLACE_CBRTL]) + REPLACE_CEIL=0; AC_SUBST([REPLACE_CEIL]) + REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) + REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) + REPLACE_EXPM1=0; AC_SUBST([REPLACE_EXPM1]) + REPLACE_EXPM1F=0; AC_SUBST([REPLACE_EXPM1F]) + REPLACE_EXP2=0; AC_SUBST([REPLACE_EXP2]) + REPLACE_EXP2L=0; AC_SUBST([REPLACE_EXP2L]) + REPLACE_FABSL=0; AC_SUBST([REPLACE_FABSL]) + REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR]) + REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF]) + REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL]) + REPLACE_FMA=0; AC_SUBST([REPLACE_FMA]) + REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF]) + REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL]) + REPLACE_FMOD=0; AC_SUBST([REPLACE_FMOD]) + REPLACE_FMODF=0; AC_SUBST([REPLACE_FMODF]) + REPLACE_FMODL=0; AC_SUBST([REPLACE_FMODL]) + REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF]) + REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) + REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL]) + REPLACE_HUGE_VAL=0; AC_SUBST([REPLACE_HUGE_VAL]) + REPLACE_HYPOT=0; AC_SUBST([REPLACE_HYPOT]) + REPLACE_HYPOTF=0; AC_SUBST([REPLACE_HYPOTF]) + REPLACE_HYPOTL=0; AC_SUBST([REPLACE_HYPOTL]) + REPLACE_ILOGB=0; AC_SUBST([REPLACE_ILOGB]) + REPLACE_ILOGBF=0; AC_SUBST([REPLACE_ILOGBF]) + REPLACE_ISFINITE=0; AC_SUBST([REPLACE_ISFINITE]) + REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) + REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) + REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) + REPLACE_LOG=0; AC_SUBST([REPLACE_LOG]) + REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF]) + REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL]) + REPLACE_LOG10=0; AC_SUBST([REPLACE_LOG10]) + REPLACE_LOG10F=0; AC_SUBST([REPLACE_LOG10F]) + REPLACE_LOG10L=0; AC_SUBST([REPLACE_LOG10L]) + REPLACE_LOG1P=0; AC_SUBST([REPLACE_LOG1P]) + REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF]) + REPLACE_LOG1PL=0; AC_SUBST([REPLACE_LOG1PL]) + REPLACE_LOG2=0; AC_SUBST([REPLACE_LOG2]) + REPLACE_LOG2F=0; AC_SUBST([REPLACE_LOG2F]) + REPLACE_LOG2L=0; AC_SUBST([REPLACE_LOG2L]) + REPLACE_LOGB=0; AC_SUBST([REPLACE_LOGB]) + REPLACE_LOGBF=0; AC_SUBST([REPLACE_LOGBF]) + REPLACE_LOGBL=0; AC_SUBST([REPLACE_LOGBL]) + REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) + REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF]) + REPLACE_MODFL=0; AC_SUBST([REPLACE_MODFL]) + REPLACE_NAN=0; AC_SUBST([REPLACE_NAN]) + REPLACE_REMAINDER=0; AC_SUBST([REPLACE_REMAINDER]) + REPLACE_REMAINDERF=0; AC_SUBST([REPLACE_REMAINDERF]) + REPLACE_REMAINDERL=0; AC_SUBST([REPLACE_REMAINDERL]) + REPLACE_ROUND=0; AC_SUBST([REPLACE_ROUND]) + REPLACE_ROUNDF=0; AC_SUBST([REPLACE_ROUNDF]) + REPLACE_ROUNDL=0; AC_SUBST([REPLACE_ROUNDL]) + REPLACE_SIGNBIT=0; AC_SUBST([REPLACE_SIGNBIT]) + REPLACE_SIGNBIT_USING_GCC=0; AC_SUBST([REPLACE_SIGNBIT_USING_GCC]) + REPLACE_SQRTL=0; AC_SUBST([REPLACE_SQRTL]) + REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) + REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) + REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL]) +]) + +# gl_LONG_DOUBLE_VS_DOUBLE +# determines whether 'long double' and 'double' have the same representation. +# Sets variable HAVE_SAME_LONG_DOUBLE_AS_DOUBLE to 0 or 1, and defines +# HAVE_SAME_LONG_DOUBLE_AS_DOUBLE accordingly. +# The currently known platforms where this is the case are: +# Linux/HPPA, Minix 3.1.8, AIX 5, AIX 6 and 7 with xlc, MSVC 9. +AC_DEFUN([gl_LONG_DOUBLE_VS_DOUBLE], +[ + AC_CACHE_CHECK([whether long double and double are the same], + [gl_cv_long_double_equals_double], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[typedef int check[sizeof (long double) == sizeof (double) + && LDBL_MANT_DIG == DBL_MANT_DIG + && LDBL_MAX_EXP == DBL_MAX_EXP + && LDBL_MIN_EXP == DBL_MIN_EXP + ? 1 : -1]; + ]])], + [gl_cv_long_double_equals_double=yes], + [gl_cv_long_double_equals_double=no]) + ]) + if test $gl_cv_long_double_equals_double = yes; then + AC_DEFINE([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE], [1], + [Define to 1 if 'long double' and 'double' have the same representation.]) + HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=1 + else + HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=0 + fi + AC_SUBST([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE]) +]) diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 new file mode 100644 index 000000000..4c9f38861 --- /dev/null +++ b/m4/mbrtowc.m4 @@ -0,0 +1,572 @@ +# mbrtowc.m4 serial 25 +dnl Copyright (C) 2001-2002, 2004-2005, 2008-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MBRTOWC], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + gl_MBSTATE_T_BROKEN + + AC_CHECK_FUNCS_ONCE([mbrtowc]) + if test $ac_cv_func_mbrtowc = no; then + HAVE_MBRTOWC=0 + AC_CHECK_DECLS([mbrtowc],,, [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +]]) + if test $ac_cv_have_decl_mbrtowc = yes; then + dnl On Minix 3.1.8, the system's declares mbrtowc() although + dnl it does not have the function. Avoid a collision with gnulib's + dnl replacement. + REPLACE_MBRTOWC=1 + fi + else + if test $REPLACE_MBSTATE_T = 1; then + REPLACE_MBRTOWC=1 + else + gl_MBRTOWC_NULL_ARG1 + gl_MBRTOWC_NULL_ARG2 + gl_MBRTOWC_RETVAL + gl_MBRTOWC_NUL_RETVAL + case "$gl_cv_func_mbrtowc_null_arg1" in + *yes) ;; + *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1], + [Define if the mbrtowc function has the NULL pwc argument bug.]) + REPLACE_MBRTOWC=1 + ;; + esac + case "$gl_cv_func_mbrtowc_null_arg2" in + *yes) ;; + *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1], + [Define if the mbrtowc function has the NULL string argument bug.]) + REPLACE_MBRTOWC=1 + ;; + esac + case "$gl_cv_func_mbrtowc_retval" in + *yes) ;; + *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], + [Define if the mbrtowc function returns a wrong return value.]) + REPLACE_MBRTOWC=1 + ;; + esac + case "$gl_cv_func_mbrtowc_nul_retval" in + *yes) ;; + *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1], + [Define if the mbrtowc function does not return 0 for a NUL character.]) + REPLACE_MBRTOWC=1 + ;; + esac + fi + fi +]) + +dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that +dnl redefines the semantics of the given mbstate_t type. +dnl Result is REPLACE_MBSTATE_T. +dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to +dnl avoid inconsistencies. + +AC_DEFUN([gl_MBSTATE_T_BROKEN], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + AC_CHECK_FUNCS_ONCE([mbsinit]) + AC_CHECK_FUNCS_ONCE([mbrtowc]) + if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then + gl_MBRTOWC_INCOMPLETE_STATE + gl_MBRTOWC_SANITYCHECK + REPLACE_MBSTATE_T=0 + case "$gl_cv_func_mbrtowc_incomplete_state" in + *yes) ;; + *) REPLACE_MBSTATE_T=1 ;; + esac + case "$gl_cv_func_mbrtowc_sanitycheck" in + *yes) ;; + *) REPLACE_MBSTATE_T=1 ;; + esac + else + REPLACE_MBSTATE_T=1 + fi +]) + +dnl Test whether mbrtowc puts the state into non-initial state when parsing an +dnl incomplete multibyte character. +dnl Result is gl_cv_func_mbrtowc_incomplete_state. + +AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_JA]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], + [gl_cv_func_mbrtowc_incomplete_state], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on AIX and OSF/1. + aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_JA != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) + { + const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) + if (mbsinit (&state)) + return 1; + } + return 0; +}]])], + [gl_cv_func_mbrtowc_incomplete_state=yes], + [gl_cv_func_mbrtowc_incomplete_state=no], + [:]) + fi + ]) +]) + +dnl Test whether mbrtowc works not worse than mbtowc. +dnl Result is gl_cv_func_mbrtowc_sanitycheck. + +AC_DEFUN([gl_MBRTOWC_SANITYCHECK], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_ZH_CN]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc], + [gl_cv_func_mbrtowc_sanitycheck], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on Solaris 8. + solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_ZH_CN != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + /* This fails on Solaris 8: + mbrtowc returns 2, and sets wc to 0x00F0. + mbtowc returns 4 (correct) and sets wc to 0x5EDC. */ + if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) + { + char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 6, &state) != 4 + && mbtowc (&wc, input + 3, 6) == 4) + return 1; + } + return 0; +}]])], + [gl_cv_func_mbrtowc_sanitycheck=yes], + [gl_cv_func_mbrtowc_sanitycheck=no], + [:]) + fi + ]) +]) + +dnl Test whether mbrtowc supports a NULL pwc argument correctly. +dnl Result is gl_cv_func_mbrtowc_null_arg1. + +AC_DEFUN([gl_MBRTOWC_NULL_ARG1], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument], + [gl_cv_func_mbrtowc_null_arg1], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on Solaris. + solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR_UTF8 != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + int result = 0; + + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + char input[] = "\303\237er"; + mbstate_t state; + wchar_t wc; + size_t ret; + + memset (&state, '\0', sizeof (mbstate_t)); + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 5, &state); + if (ret != 2) + result |= 1; + if (!mbsinit (&state)) + result |= 2; + + memset (&state, '\0', sizeof (mbstate_t)); + ret = mbrtowc (NULL, input, 5, &state); + if (ret != 2) /* Solaris 7 fails here: ret is -1. */ + result |= 4; + if (!mbsinit (&state)) + result |= 8; + } + return result; +}]])], + [gl_cv_func_mbrtowc_null_arg1=yes], + [gl_cv_func_mbrtowc_null_arg1=no], + [:]) + fi + ]) +]) + +dnl Test whether mbrtowc supports a NULL string argument correctly. +dnl Result is gl_cv_func_mbrtowc_null_arg2. + +AC_DEFUN([gl_MBRTOWC_NULL_ARG2], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument], + [gl_cv_func_mbrtowc_null_arg2], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on OSF/1. + osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_null_arg2="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR_UTF8 != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + mbstate_t state; + wchar_t wc; + int ret; + + memset (&state, '\0', sizeof (mbstate_t)); + wc = (wchar_t) 0xBADFACE; + mbrtowc (&wc, NULL, 5, &state); + /* Check that wc was not modified. */ + if (wc != (wchar_t) 0xBADFACE) + return 1; + } + return 0; +}]])], + [gl_cv_func_mbrtowc_null_arg2=yes], + [gl_cv_func_mbrtowc_null_arg2=no], + [:]) + fi + ]) +]) + +dnl Test whether mbrtowc, when parsing the end of a multibyte character, +dnl correctly returns the number of bytes that were needed to complete the +dnl character (not the total number of bytes of the multibyte character). +dnl Result is gl_cv_func_mbrtowc_retval. + +AC_DEFUN([gl_MBRTOWC_RETVAL], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([gt_LOCALE_JA]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([whether mbrtowc has a correct return value], + [gl_cv_func_mbrtowc_retval], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on HP-UX, Solaris, native Windows. + hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_retval="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \ + || { case "$host_os" in mingw*) true;; *) false;; esac; }; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + int result = 0; + int found_some_locale = 0; + /* This fails on Solaris. */ + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + char input[] = "B\303\274\303\237er"; /* "Büßer" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) + { + input[1] = '\0'; + if (mbrtowc (&wc, input + 2, 5, &state) != 1) + result |= 1; + } + found_some_locale = 1; + } + /* This fails on HP-UX 11.11. */ + if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) + { + char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) + { + input[1] = '\0'; + if (mbrtowc (&wc, input + 2, 5, &state) != 2) + result |= 2; + } + found_some_locale = 1; + } + /* This fails on native Windows. */ + if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL) + { + char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 4; + } + found_some_locale = 1; + } + if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL) + { + char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 8; + } + found_some_locale = 1; + } + if (setlocale (LC_ALL, "Chinese_China.936") != NULL) + { + char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 16; + } + found_some_locale = 1; + } + return (found_some_locale ? result : 77); +}]])], + [gl_cv_func_mbrtowc_retval=yes], + [if test $? != 77; then + gl_cv_func_mbrtowc_retval=no + fi + ], + [:]) + fi + ]) +]) + +dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0. +dnl Result is gl_cv_func_mbrtowc_nul_retval. + +AC_DEFUN([gl_MBRTOWC_NUL_RETVAL], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_ZH_CN]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character], + [gl_cv_func_mbrtowc_nul_retval], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on Solaris 8 and 9. + solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_ZH_CN != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + /* This fails on Solaris 8 and 9. */ + if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) + { + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, "", 1, &state) != 0) + return 1; + } + return 0; +}]])], + [gl_cv_func_mbrtowc_nul_retval=yes], + [gl_cv_func_mbrtowc_nul_retval=no], + [:]) + fi + ]) +]) + +# Prerequisites of lib/mbrtowc.c. +AC_DEFUN([gl_PREREQ_MBRTOWC], [ + : +]) + + +dnl From Paul Eggert + +dnl This is an override of an autoconf macro. + +AC_DEFUN([AC_FUNC_MBRTOWC], +[ + dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. + AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], + gl_cv_func_mbrtowc, + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[/* Tru64 with Desktop Toolkit C has a bug: must be + included before . + BSD/OS 4.0.1 has a bug: , and + must be included before . */ + #include + #include + #include + #include ]], + [[wchar_t wc; + char const s[] = ""; + size_t n = 1; + mbstate_t state; + return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], + gl_cv_func_mbrtowc=yes, + gl_cv_func_mbrtowc=no)]) + if test $gl_cv_func_mbrtowc = yes; then + AC_DEFINE([HAVE_MBRTOWC], [1], + [Define to 1 if mbrtowc and mbstate_t are properly declared.]) + fi +]) diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4 new file mode 100644 index 000000000..2e6d0921a --- /dev/null +++ b/m4/mbsinit.m4 @@ -0,0 +1,51 @@ +# mbsinit.m4 serial 8 +dnl Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MBSINIT], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + gl_MBSTATE_T_BROKEN + + AC_CHECK_FUNCS_ONCE([mbsinit]) + if test $ac_cv_func_mbsinit = no; then + HAVE_MBSINIT=0 + AC_CHECK_DECLS([mbsinit],,, [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +]]) + if test $ac_cv_have_decl_mbsinit = yes; then + dnl On Minix 3.1.8, the system's declares mbsinit() although + dnl it does not have the function. Avoid a collision with gnulib's + dnl replacement. + REPLACE_MBSINIT=1 + fi + else + if test $REPLACE_MBSTATE_T = 1; then + REPLACE_MBSINIT=1 + else + dnl On mingw, mbsinit() always returns 1, which is inappropriate for + dnl states produced by mbrtowc() for an incomplete multibyte character + dnl in multibyte locales. + case "$host_os" in + mingw*) REPLACE_MBSINIT=1 ;; + esac + fi + fi +]) + +# Prerequisites of lib/mbsinit.c. +AC_DEFUN([gl_PREREQ_MBSINIT], [ + : +]) diff --git a/m4/mbsrtowcs.m4 b/m4/mbsrtowcs.m4 new file mode 100644 index 000000000..c4934c281 --- /dev/null +++ b/m4/mbsrtowcs.m4 @@ -0,0 +1,155 @@ +# mbsrtowcs.m4 serial 13 +dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MBSRTOWCS], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + gl_MBSTATE_T_BROKEN + + AC_CHECK_FUNCS_ONCE([mbsrtowcs]) + if test $ac_cv_func_mbsrtowcs = no; then + HAVE_MBSRTOWCS=0 + AC_CHECK_DECLS([mbsrtowcs],,, [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +]]) + if test $ac_cv_have_decl_mbsrtowcs = yes; then + dnl On Minix 3.1.8, the system's declares mbsrtowcs() although + dnl it does not have the function. Avoid a collision with gnulib's + dnl replacement. + REPLACE_MBSRTOWCS=1 + fi + else + if test $REPLACE_MBSTATE_T = 1; then + REPLACE_MBSRTOWCS=1 + else + gl_MBSRTOWCS_WORKS + case "$gl_cv_func_mbsrtowcs_works" in + *yes) ;; + *) REPLACE_MBSRTOWCS=1 ;; + esac + fi + fi +]) + +dnl Test whether mbsrtowcs works. +dnl Result is gl_cv_func_mbsrtowcs_works. + +AC_DEFUN([gl_MBSRTOWCS_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([gt_LOCALE_JA]) + AC_REQUIRE([gt_LOCALE_ZH_CN]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether mbsrtowcs works], + [gl_cv_func_mbsrtowcs_works], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on HP-UX, Solaris, mingw. + hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbsrtowcs_works="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + int result = 0; + /* Test whether the function supports a NULL destination argument. + This fails on native Windows. */ + if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) + { + const char input[] = "\337er"; + const char *src = input; + mbstate_t state; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbsrtowcs (NULL, &src, 1, &state) != 3 + || src != input) + result |= 1; + } + /* Test whether the function works when started with a conversion state + in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */ + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + const char input[] = "B\303\274\303\237er"; + mbstate_t state; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2)) + if (!mbsinit (&state)) + { + const char *src = input + 2; + if (mbsrtowcs (NULL, &src, 10, &state) != 4) + result |= 2; + } + } + if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) + { + const char input[] = "<\306\374\313\334\270\354>"; + mbstate_t state; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2)) + if (!mbsinit (&state)) + { + const char *src = input + 4; + if (mbsrtowcs (NULL, &src, 10, &state) != 3) + result |= 4; + } + } + if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) + { + const char input[] = "B\250\271\201\060\211\070er"; + mbstate_t state; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2)) + if (!mbsinit (&state)) + { + const char *src = input + 2; + if (mbsrtowcs (NULL, &src, 10, &state) != 4) + result |= 8; + } + } + return result; +}]])], + [gl_cv_func_mbsrtowcs_works=yes], + [gl_cv_func_mbsrtowcs_works=no], + [:]) + fi + ]) +]) + +# Prerequisites of lib/mbsrtowcs.c. +AC_DEFUN([gl_PREREQ_MBSRTOWCS], [ + : +]) diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4 new file mode 100644 index 000000000..ed0011798 --- /dev/null +++ b/m4/mbstate_t.m4 @@ -0,0 +1,41 @@ +# mbstate_t.m4 serial 13 +dnl Copyright (C) 2000-2002, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# From Paul Eggert. + +# BeOS 5 has but does not define mbstate_t, +# so you can't declare an object of that type. +# Check for this incompatibility with Standard C. + +# AC_TYPE_MBSTATE_T +# ----------------- +AC_DEFUN([AC_TYPE_MBSTATE_T], +[ + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) dnl for HP-UX 11.11 + + AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include ]], + [[mbstate_t x; return sizeof x;]])], + [ac_cv_type_mbstate_t=yes], + [ac_cv_type_mbstate_t=no])]) + if test $ac_cv_type_mbstate_t = yes; then + AC_DEFINE([HAVE_MBSTATE_T], [1], + [Define to 1 if declares mbstate_t.]) + else + AC_DEFINE([mbstate_t], [int], + [Define to a type if does not define.]) + fi +]) diff --git a/m4/mbswidth.m4 b/m4/mbswidth.m4 new file mode 100644 index 000000000..39760fcd2 --- /dev/null +++ b/m4/mbswidth.m4 @@ -0,0 +1,46 @@ +# mbswidth.m4 serial 18 +dnl Copyright (C) 2000-2002, 2004, 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl autoconf tests required for use of mbswidth.c +dnl From Bruno Haible. + +AC_DEFUN([gl_MBSWIDTH], +[ + AC_CHECK_HEADERS_ONCE([wchar.h]) + AC_CHECK_FUNCS_ONCE([isascii mbsinit]) + + dnl UnixWare 7.1.1 has a declaration of a function mbswidth() + dnl that clashes with ours. + AC_CACHE_CHECK([whether mbswidth is declared in ], + [ac_cv_have_decl_mbswidth], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include + ]], + [[ + char *p = (char *) mbswidth; + return !p; + ]])], + [ac_cv_have_decl_mbswidth=yes], + [ac_cv_have_decl_mbswidth=no])]) + if test $ac_cv_have_decl_mbswidth = yes; then + ac_val=1 + else + ac_val=0 + fi + AC_DEFINE_UNQUOTED([HAVE_DECL_MBSWIDTH_IN_WCHAR_H], [$ac_val], + [Define to 1 if you have a declaration of mbswidth() in , and to 0 otherwise.]) + + AC_TYPE_MBSTATE_T +]) diff --git a/m4/mbtowc.m4 b/m4/mbtowc.m4 new file mode 100644 index 000000000..e47946196 --- /dev/null +++ b/m4/mbtowc.m4 @@ -0,0 +1,19 @@ +# mbtowc.m4 serial 2 +dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MBTOWC], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + + if false; then + REPLACE_MBTOWC=1 + fi +]) + +# Prerequisites of lib/mbtowc.c. +AC_DEFUN([gl_PREREQ_MBTOWC], [ + : +]) diff --git a/m4/memchr.m4 b/m4/memchr.m4 new file mode 100644 index 000000000..2d8abe75d --- /dev/null +++ b/m4/memchr.m4 @@ -0,0 +1,88 @@ +# memchr.m4 serial 12 +dnl Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN_ONCE([gl_FUNC_MEMCHR], +[ + dnl Check for prerequisites for memory fence checks. + gl_FUNC_MMAP_ANON + AC_CHECK_HEADERS_ONCE([sys/mman.h]) + AC_CHECK_FUNCS_ONCE([mprotect]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [ + dnl These days, we assume memchr is present. But if support for old + dnl platforms is desired: + AC_CHECK_FUNCS_ONCE([memchr]) + if test $ac_cv_func_memchr = no; then + HAVE_MEMCHR=0 + fi + ]) + if test $HAVE_MEMCHR = 1; then + # Detect platform-specific bugs in some versions of glibc: + # memchr should not dereference anything with length 0 + # http://bugzilla.redhat.com/499689 + # memchr should not dereference overestimated length after a match + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 + # http://sourceware.org/bugzilla/show_bug.cgi?id=10162 + # Assume that memchr works on platforms that lack mprotect. + AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#if HAVE_SYS_MMAN_H +# include +# include +# include +# include +# ifndef MAP_FILE +# define MAP_FILE 0 +# endif +#endif +]], [[ + int result = 0; + char *fence = NULL; +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT +# if HAVE_MAP_ANONYMOUS + const int flags = MAP_ANONYMOUS | MAP_PRIVATE; + const int fd = -1; +# else /* !HAVE_MAP_ANONYMOUS */ + const int flags = MAP_FILE | MAP_PRIVATE; + int fd = open ("/dev/zero", O_RDONLY, 0666); + if (fd >= 0) +# endif + { + int pagesize = getpagesize (); + char *two_pages = + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); + if (two_pages != (char *)(-1) + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + fence = two_pages + pagesize; + } +#endif + if (fence) + { + if (memchr (fence, 0, 0)) + result |= 1; + strcpy (fence - 9, "12345678"); + if (memchr (fence - 9, 0, 79) != fence - 1) + result |= 2; + if (memchr (fence - 1, 0, 3) != fence - 1) + result |= 4; + } + return result; +]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], + [dnl Be pessimistic for now. + gl_cv_func_memchr_works="guessing no"])]) + if test "$gl_cv_func_memchr_works" != yes; then + REPLACE_MEMCHR=1 + fi + fi +]) + +# Prerequisites of lib/memchr.c. +AC_DEFUN([gl_PREREQ_MEMCHR], [ + AC_CHECK_HEADERS([bp-sym.h]) +]) diff --git a/m4/mempcpy.m4 b/m4/mempcpy.m4 new file mode 100644 index 000000000..a48f2d107 --- /dev/null +++ b/m4/mempcpy.m4 @@ -0,0 +1,26 @@ +# mempcpy.m4 serial 11 +dnl Copyright (C) 2003-2004, 2006-2007, 2009-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_MEMPCPY], +[ + dnl Persuade glibc to declare mempcpy(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + dnl The mempcpy() declaration in lib/string.in.h uses 'restrict'. + AC_REQUIRE([AC_C_RESTRICT]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([mempcpy]) + if test $ac_cv_func_mempcpy = no; then + HAVE_MEMPCPY=0 + fi +]) + +# Prerequisites of lib/mempcpy.c. +AC_DEFUN([gl_PREREQ_MEMPCPY], [ + : +]) diff --git a/m4/mmap-anon.m4 b/m4/mmap-anon.m4 new file mode 100644 index 000000000..9b60ddfa4 --- /dev/null +++ b/m4/mmap-anon.m4 @@ -0,0 +1,55 @@ +# mmap-anon.m4 serial 10 +dnl Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Detect how mmap can be used to create anonymous (not file-backed) memory +# mappings. +# - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS +# and MAP_ANON exist and have the same value. +# - On HP-UX, only MAP_ANONYMOUS exists. +# - On Mac OS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists. +# - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be +# used. + +AC_DEFUN([gl_FUNC_MMAP_ANON], +[ + dnl Persuade glibc to define MAP_ANONYMOUS. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it + # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is + # irrelevant for anonymous mappings. + AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no]) + + # Try to allow MAP_ANONYMOUS. + gl_have_mmap_anonymous=no + if test $gl_have_mmap = yes; then + AC_MSG_CHECKING([for MAP_ANONYMOUS]) + AC_EGREP_CPP([I cannot identify this map], [ +#include +#ifdef MAP_ANONYMOUS + I cannot identify this map +#endif +], + [gl_have_mmap_anonymous=yes]) + if test $gl_have_mmap_anonymous != yes; then + AC_EGREP_CPP([I cannot identify this map], [ +#include +#ifdef MAP_ANON + I cannot identify this map +#endif +], + [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON], + [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.]) + gl_have_mmap_anonymous=yes]) + fi + AC_MSG_RESULT([$gl_have_mmap_anonymous]) + if test $gl_have_mmap_anonymous = yes; then + AC_DEFINE([HAVE_MAP_ANONYMOUS], [1], + [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including + config.h and .]) + fi + fi +]) diff --git a/m4/msvc-inval.m4 b/m4/msvc-inval.m4 new file mode 100644 index 000000000..9a6a47a74 --- /dev/null +++ b/m4/msvc-inval.m4 @@ -0,0 +1,19 @@ +# msvc-inval.m4 serial 1 +dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_MSVC_INVAL], +[ + AC_CHECK_FUNCS_ONCE([_set_invalid_parameter_handler]) + if test $ac_cv_func__set_invalid_parameter_handler = yes; then + HAVE_MSVC_INVALID_PARAMETER_HANDLER=1 + AC_DEFINE([HAVE_MSVC_INVALID_PARAMETER_HANDLER], [1], + [Define to 1 on MSVC platforms that have the "invalid parameter handler" + concept.]) + else + HAVE_MSVC_INVALID_PARAMETER_HANDLER=0 + fi + AC_SUBST([HAVE_MSVC_INVALID_PARAMETER_HANDLER]) +]) diff --git a/m4/msvc-nothrow.m4 b/m4/msvc-nothrow.m4 new file mode 100644 index 000000000..a39618a41 --- /dev/null +++ b/m4/msvc-nothrow.m4 @@ -0,0 +1,10 @@ +# msvc-nothrow.m4 serial 1 +dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_MSVC_NOTHROW], +[ + AC_REQUIRE([gl_MSVC_INVAL]) +]) diff --git a/m4/multiarch.m4 b/m4/multiarch.m4 new file mode 100644 index 000000000..552ec7e71 --- /dev/null +++ b/m4/multiarch.m4 @@ -0,0 +1,62 @@ +# multiarch.m4 serial 7 +dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Determine whether the compiler is or may be producing universal binaries. +# +# On Mac OS X 10.5 and later systems, the user can create libraries and +# executables that work on multiple system types--known as "fat" or +# "universal" binaries--by specifying multiple '-arch' options to the +# compiler but only a single '-arch' option to the preprocessor. Like +# this: +# +# ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ +# CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ +# CPP="gcc -E" CXXCPP="g++ -E" +# +# Detect this situation and set APPLE_UNIVERSAL_BUILD accordingly. + +AC_DEFUN_ONCE([gl_MULTIARCH], +[ + dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN. + gl_cv_c_multiarch=no + AC_COMPILE_IFELSE( + [AC_LANG_SOURCE( + [[#ifndef __APPLE_CC__ + not a universal capable compiler + #endif + typedef int dummy; + ]])], + [ + dnl Check for potential -arch flags. It is not universal unless + dnl there are at least two -arch flags with different values. + arch= + prev= + for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do + if test -n "$prev"; then + case $word in + i?86 | x86_64 | ppc | ppc64) + if test -z "$arch" || test "$arch" = "$word"; then + arch="$word" + else + gl_cv_c_multiarch=yes + fi + ;; + esac + prev= + else + if test "x$word" = "x-arch"; then + prev=arch + fi + fi + done + ]) + if test $gl_cv_c_multiarch = yes; then + APPLE_UNIVERSAL_BUILD=1 + else + APPLE_UNIVERSAL_BUILD=0 + fi + AC_SUBST([APPLE_UNIVERSAL_BUILD]) +]) diff --git a/m4/nl_langinfo.m4 b/m4/nl_langinfo.m4 new file mode 100644 index 000000000..25e210155 --- /dev/null +++ b/m4/nl_langinfo.m4 @@ -0,0 +1,50 @@ +# nl_langinfo.m4 serial 5 +dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_NL_LANGINFO], +[ + AC_REQUIRE([gl_LANGINFO_H_DEFAULTS]) + AC_REQUIRE([gl_LANGINFO_H]) + AC_CHECK_FUNCS_ONCE([nl_langinfo]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test $ac_cv_func_nl_langinfo = yes; then + # On Irix 6.5, YESEXPR is defined, but nl_langinfo(YESEXPR) is broken. + AC_CACHE_CHECK([whether YESEXPR works], + [gl_cv_func_nl_langinfo_yesexpr_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM([[#include +]], [[return !*nl_langinfo(YESEXPR); +]])], + [gl_cv_func_nl_langinfo_yesexpr_works=yes], + [gl_cv_func_nl_langinfo_yesexpr_works=no], + [ + case "$host_os" in + # Guess no on irix systems. + irix*) gl_cv_func_nl_langinfo_yesexpr_works="guessing no";; + # Guess yes elsewhere. + *) gl_cv_func_nl_langinfo_yesexpr_works="guessing yes";; + esac + ]) + ]) + case $gl_cv_func_nl_langinfo_yesexpr_works in + *yes) FUNC_NL_LANGINFO_YESEXPR_WORKS=1 ;; + *) FUNC_NL_LANGINFO_YESEXPR_WORKS=0 ;; + esac + AC_DEFINE_UNQUOTED([FUNC_NL_LANGINFO_YESEXPR_WORKS], + [$FUNC_NL_LANGINFO_YESEXPR_WORKS], + [Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string.]) + if test $HAVE_LANGINFO_CODESET = 1 && test $HAVE_LANGINFO_ERA = 1 \ + && test $FUNC_NL_LANGINFO_YESEXPR_WORKS = 1; then + : + else + REPLACE_NL_LANGINFO=1 + AC_DEFINE([REPLACE_NL_LANGINFO], [1], + [Define if nl_langinfo exists but is overridden by gnulib.]) + fi + else + HAVE_NL_LANGINFO=0 + fi +]) diff --git a/m4/nls.m4 b/m4/nls.m4 new file mode 100644 index 000000000..8f8a147be --- /dev/null +++ b/m4/nls.m4 @@ -0,0 +1,32 @@ +# nls.m4 serial 5 (gettext-0.18) +dnl Copyright (C) 1995-2003, 2005-2006, 2008-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995-2000. +dnl Bruno Haible , 2000-2003. + +AC_PREREQ([2.50]) + +AC_DEFUN([AM_NLS], +[ + AC_MSG_CHECKING([whether NLS is requested]) + dnl Default is enabled NLS + AC_ARG_ENABLE([nls], + [ --disable-nls do not use Native Language Support], + USE_NLS=$enableval, USE_NLS=yes) + AC_MSG_RESULT([$USE_NLS]) + AC_SUBST([USE_NLS]) +]) diff --git a/m4/nocrash.m4 b/m4/nocrash.m4 new file mode 100644 index 000000000..105b884f1 --- /dev/null +++ b/m4/nocrash.m4 @@ -0,0 +1,130 @@ +# nocrash.m4 serial 4 +dnl Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Based on libsigsegv, from Bruno Haible and Paolo Bonzini. + +AC_PREREQ([2.13]) + +dnl Expands to some code for use in .c programs that will cause the configure +dnl test to exit instead of crashing. This is useful to avoid triggering +dnl action from a background debugger and to avoid core dumps. +dnl Usage: ... +dnl ]GL_NOCRASH[ +dnl ... +dnl int main() { nocrash_init(); ... } +AC_DEFUN([GL_NOCRASH],[[ +#include +#if defined __MACH__ && defined __APPLE__ +/* Avoid a crash on Mac OS X. */ +#include +#include +#include +#include +#include +#include +/* The exception port on which our thread listens. */ +static mach_port_t our_exception_port; +/* The main function of the thread listening for exceptions of type + EXC_BAD_ACCESS. */ +static void * +mach_exception_thread (void *arg) +{ + /* Buffer for a message to be received. */ + struct { + mach_msg_header_t head; + mach_msg_body_t msgh_body; + char data[1024]; + } msg; + mach_msg_return_t retval; + /* Wait for a message on the exception port. */ + retval = mach_msg (&msg.head, MACH_RCV_MSG | MACH_RCV_LARGE, 0, sizeof (msg), + our_exception_port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); + if (retval != MACH_MSG_SUCCESS) + abort (); + exit (1); +} +static void +nocrash_init (void) +{ + mach_port_t self = mach_task_self (); + /* Allocate a port on which the thread shall listen for exceptions. */ + if (mach_port_allocate (self, MACH_PORT_RIGHT_RECEIVE, &our_exception_port) + == KERN_SUCCESS) { + /* See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/mach_port_insert_right.html. */ + if (mach_port_insert_right (self, our_exception_port, our_exception_port, + MACH_MSG_TYPE_MAKE_SEND) + == KERN_SUCCESS) { + /* The exceptions we want to catch. Only EXC_BAD_ACCESS is interesting + for us. */ + exception_mask_t mask = EXC_MASK_BAD_ACCESS; + /* Create the thread listening on the exception port. */ + pthread_attr_t attr; + pthread_t thread; + if (pthread_attr_init (&attr) == 0 + && pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) == 0 + && pthread_create (&thread, &attr, mach_exception_thread, NULL) == 0) { + pthread_attr_destroy (&attr); + /* Replace the exception port info for these exceptions with our own. + Note that we replace the exception port for the entire task, not only + for a particular thread. This has the effect that when our exception + port gets the message, the thread specific exception port has already + been asked, and we don't need to bother about it. + See http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_set_exception_ports.html. */ + task_set_exception_ports (self, mask, our_exception_port, + EXCEPTION_DEFAULT, MACHINE_THREAD_STATE); + } + } + } +} +#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Avoid a crash on native Windows. */ +#define WIN32_LEAN_AND_MEAN +#include +#include +static LONG WINAPI +exception_filter (EXCEPTION_POINTERS *ExceptionInfo) +{ + switch (ExceptionInfo->ExceptionRecord->ExceptionCode) + { + case EXCEPTION_ACCESS_VIOLATION: + case EXCEPTION_IN_PAGE_ERROR: + case EXCEPTION_STACK_OVERFLOW: + case EXCEPTION_GUARD_PAGE: + case EXCEPTION_PRIV_INSTRUCTION: + case EXCEPTION_ILLEGAL_INSTRUCTION: + case EXCEPTION_DATATYPE_MISALIGNMENT: + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + case EXCEPTION_NONCONTINUABLE_EXCEPTION: + exit (1); + } + return EXCEPTION_CONTINUE_SEARCH; +} +static void +nocrash_init (void) +{ + SetUnhandledExceptionFilter ((LPTOP_LEVEL_EXCEPTION_FILTER) exception_filter); +} +#else +/* Avoid a crash on POSIX systems. */ +#include +/* A POSIX signal handler. */ +static void +exception_handler (int sig) +{ + exit (1); +} +static void +nocrash_init (void) +{ +#ifdef SIGSEGV + signal (SIGSEGV, exception_handler); +#endif +#ifdef SIGBUS + signal (SIGBUS, exception_handler); +#endif +} +#endif +]]) diff --git a/m4/off_t.m4 b/m4/off_t.m4 new file mode 100644 index 000000000..d355d0131 --- /dev/null +++ b/m4/off_t.m4 @@ -0,0 +1,18 @@ +# off_t.m4 serial 1 +dnl Copyright (C) 2012-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Check whether to override the 'off_t' type. +dnl Set WINDOWS_64_BIT_OFF_T. + +AC_DEFUN([gl_TYPE_OFF_T], +[ + m4_ifdef([gl_LARGEFILE], [ + AC_REQUIRE([gl_LARGEFILE]) + ], [ + WINDOWS_64_BIT_OFF_T=0 + ]) + AC_SUBST([WINDOWS_64_BIT_OFF_T]) +]) diff --git a/m4/po.m4 b/m4/po.m4 new file mode 100644 index 000000000..f39572343 --- /dev/null +++ b/m4/po.m4 @@ -0,0 +1,452 @@ +# po.m4 serial 20 (gettext-0.18.2) +dnl Copyright (C) 1995-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1995-2000. +dnl Bruno Haible , 2000-2003. + +AC_PREREQ([2.60]) + +dnl Checks for all prerequisites of the po subdirectory. +AC_DEFUN([AM_PO_SUBDIRS], +[ + AC_REQUIRE([AC_PROG_MAKE_SET])dnl + AC_REQUIRE([AC_PROG_INSTALL])dnl + AC_REQUIRE([AC_PROG_MKDIR_P])dnl + AC_REQUIRE([AM_NLS])dnl + + dnl Release version of the gettext macros. This is used to ensure that + dnl the gettext macros and po/Makefile.in.in are in sync. + AC_SUBST([GETTEXT_MACRO_VERSION], [0.18]) + + dnl Perform the following tests also if --disable-nls has been given, + dnl because they are needed for "make dist" to work. + + dnl Search for GNU msgfmt in the PATH. + dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions. + dnl The second test excludes FreeBSD msgfmt. + AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, + [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && + (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], + :) + AC_PATH_PROG([GMSGFMT], [gmsgfmt], [$MSGFMT]) + + dnl Test whether it is GNU msgfmt >= 0.15. +changequote(,)dnl + case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; + *) MSGFMT_015=$MSGFMT ;; + esac +changequote([,])dnl + AC_SUBST([MSGFMT_015]) +changequote(,)dnl + case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; + *) GMSGFMT_015=$GMSGFMT ;; + esac +changequote([,])dnl + AC_SUBST([GMSGFMT_015]) + + dnl Search for GNU xgettext 0.12 or newer in the PATH. + dnl The first test excludes Solaris xgettext and early GNU xgettext versions. + dnl The second test excludes FreeBSD xgettext. + AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, + [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && + (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], + :) + dnl Remove leftover from FreeBSD xgettext call. + rm -f messages.po + + dnl Test whether it is GNU xgettext >= 0.15. +changequote(,)dnl + case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; + *) XGETTEXT_015=$XGETTEXT ;; + esac +changequote([,])dnl + AC_SUBST([XGETTEXT_015]) + + dnl Search for GNU msgmerge 0.11 or newer in the PATH. + AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, + [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) + + dnl Installation directories. + dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we + dnl have to define it here, so that it can be used in po/Makefile. + test -n "$localedir" || localedir='${datadir}/locale' + AC_SUBST([localedir]) + + dnl Support for AM_XGETTEXT_OPTION. + test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS= + AC_SUBST([XGETTEXT_EXTRA_OPTIONS]) + + AC_CONFIG_COMMANDS([po-directories], [[ + for ac_file in $CONFIG_FILES; do + # Support "outfile[:infile[:infile...]]" + case "$ac_file" in + *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + esac + # PO directories have a Makefile.in generated from Makefile.in.in. + case "$ac_file" in */Makefile.in) + # Adjust a relative srcdir. + ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` + ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'` + ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` + # In autoconf-2.13 it is called $ac_given_srcdir. + # In autoconf-2.50 it is called $srcdir. + test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" + case "$ac_given_srcdir" in + .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; + /*) top_srcdir="$ac_given_srcdir" ;; + *) top_srcdir="$ac_dots$ac_given_srcdir" ;; + esac + # Treat a directory as a PO directory if and only if it has a + # POTFILES.in file. This allows packages to have multiple PO + # directories under different names or in different locations. + if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then + rm -f "$ac_dir/POTFILES" + test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES" + gt_tab=`printf '\t'` + cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ${gt_tab}]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES" + POMAKEFILEDEPS="POTFILES.in" + # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend + # on $ac_dir but don't depend on user-specified configuration + # parameters. + if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then + # The LINGUAS file contains the set of available languages. + if test -n "$OBSOLETE_ALL_LINGUAS"; then + test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" + fi + ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` + # Hide the ALL_LINGUAS assignment from automake < 1.5. + eval 'ALL_LINGUAS''=$ALL_LINGUAS_' + POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" + else + # The set of available languages was given in configure.in. + # Hide the ALL_LINGUAS assignment from automake < 1.5. + eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' + fi + # Compute POFILES + # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) + # Compute UPDATEPOFILES + # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update) + # Compute DUMMYPOFILES + # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop) + # Compute GMOFILES + # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo) + case "$ac_given_srcdir" in + .) srcdirpre= ;; + *) srcdirpre='$(srcdir)/' ;; + esac + POFILES= + UPDATEPOFILES= + DUMMYPOFILES= + GMOFILES= + for lang in $ALL_LINGUAS; do + POFILES="$POFILES $srcdirpre$lang.po" + UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" + DUMMYPOFILES="$DUMMYPOFILES $lang.nop" + GMOFILES="$GMOFILES $srcdirpre$lang.gmo" + done + # CATALOGS depends on both $ac_dir and the user's LINGUAS + # environment variable. + INST_LINGUAS= + if test -n "$ALL_LINGUAS"; then + for presentlang in $ALL_LINGUAS; do + useit=no + if test "%UNSET%" != "$LINGUAS"; then + desiredlanguages="$LINGUAS" + else + desiredlanguages="$ALL_LINGUAS" + fi + for desiredlang in $desiredlanguages; do + # Use the presentlang catalog if desiredlang is + # a. equal to presentlang, or + # b. a variant of presentlang (because in this case, + # presentlang can be used as a fallback for messages + # which are not translated in the desiredlang catalog). + case "$desiredlang" in + "$presentlang"*) useit=yes;; + esac + done + if test $useit = yes; then + INST_LINGUAS="$INST_LINGUAS $presentlang" + fi + done + fi + CATALOGS= + if test -n "$INST_LINGUAS"; then + for lang in $INST_LINGUAS; do + CATALOGS="$CATALOGS $lang.gmo" + done + fi + test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile" + sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile" + for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do + if test -f "$f"; then + case "$f" in + *.orig | *.bak | *~) ;; + *) cat "$f" >> "$ac_dir/Makefile" ;; + esac + fi + done + fi + ;; + esac + done]], + [# Capture the value of obsolete ALL_LINGUAS because we need it to compute + # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it + # from automake < 1.5. + eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' + # Capture the value of LINGUAS because we need it to compute CATALOGS. + LINGUAS="${LINGUAS-%UNSET%}" + ]) +]) + +dnl Postprocesses a Makefile in a directory containing PO files. +AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE], +[ + # When this code is run, in config.status, two variables have already been + # set: + # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in, + # - LINGUAS is the value of the environment variable LINGUAS at configure + # time. + +changequote(,)dnl + # Adjust a relative srcdir. + ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` + ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'` + ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` + # In autoconf-2.13 it is called $ac_given_srcdir. + # In autoconf-2.50 it is called $srcdir. + test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" + case "$ac_given_srcdir" in + .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; + /*) top_srcdir="$ac_given_srcdir" ;; + *) top_srcdir="$ac_dots$ac_given_srcdir" ;; + esac + + # Find a way to echo strings without interpreting backslash. + if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then + gt_echo='echo' + else + if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then + gt_echo='printf %s\n' + else + echo_func () { + cat < "$ac_file.tmp" + tab=`printf '\t'` + if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then + # Add dependencies that cannot be formulated as a simple suffix rule. + for lang in $ALL_LINGUAS; do + frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` + cat >> "$ac_file.tmp" < /dev/null; then + # Add dependencies that cannot be formulated as a simple suffix rule. + for lang in $ALL_LINGUAS; do + frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'` + cat >> "$ac_file.tmp" <> "$ac_file.tmp" < +#include +/* The string "%2$d %1$d", with dollar characters protected from the shell's + dollar expansion (possibly an autoconf bug). */ +static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; +static char buf[100]; +int main () +{ + sprintf (buf, format, 33, 55); + return (strcmp (buf, "55 33") != 0); +}]])], + [gt_cv_func_printf_posix=yes], + [gt_cv_func_printf_posix=no], + [ + AC_EGREP_CPP([notposix], [ +#if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ + notposix +#endif + ], + [gt_cv_func_printf_posix="guessing no"], + [gt_cv_func_printf_posix="guessing yes"]) + ]) + ]) + case $gt_cv_func_printf_posix in + *yes) + AC_DEFINE([HAVE_POSIX_PRINTF], [1], + [Define if your printf() function supports format strings with positions.]) + ;; + esac +]) diff --git a/m4/printf.m4 b/m4/printf.m4 new file mode 100644 index 000000000..ef44f7851 --- /dev/null +++ b/m4/printf.m4 @@ -0,0 +1,1570 @@ +# printf.m4 serial 50 +dnl Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Test whether the *printf family of functions supports the 'j', 'z', 't', +dnl 'L' size specifiers. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_sizes_c99. + +AC_DEFUN([gl_PRINTF_SIZES_C99], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports size specifiers as in C99], + [gl_cv_func_printf_sizes_c99], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +#include +#if HAVE_STDINT_H_WITH_UINTMAX +# include +#endif +#if HAVE_INTTYPES_H_WITH_UINTMAX +# include +#endif +static char buf[100]; +int main () +{ + int result = 0; +#if HAVE_STDINT_H_WITH_UINTMAX || HAVE_INTTYPES_H_WITH_UINTMAX + buf[0] = '\0'; + if (sprintf (buf, "%ju %d", (uintmax_t) 12345671, 33, 44, 55) < 0 + || strcmp (buf, "12345671 33") != 0) + result |= 1; +#endif + buf[0] = '\0'; + if (sprintf (buf, "%zu %d", (size_t) 12345672, 33, 44, 55) < 0 + || strcmp (buf, "12345672 33") != 0) + result |= 2; + buf[0] = '\0'; + if (sprintf (buf, "%tu %d", (ptrdiff_t) 12345673, 33, 44, 55) < 0 + || strcmp (buf, "12345673 33") != 0) + result |= 4; + buf[0] = '\0'; + if (sprintf (buf, "%Lg %d", (long double) 1.5, 33, 44, 55) < 0 + || strcmp (buf, "1.5 33") != 0) + result |= 8; + return result; +}]])], + [gl_cv_func_printf_sizes_c99=yes], + [gl_cv_func_printf_sizes_c99=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_sizes_c99="guessing yes";; + # Guess yes on FreeBSD >= 5. + freebsd[1-4]*) gl_cv_func_printf_sizes_c99="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_printf_sizes_c99="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_printf_sizes_c99="guessing no";; + darwin*) gl_cv_func_printf_sizes_c99="guessing yes";; + # Guess yes on OpenBSD >= 3.9. + openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) + gl_cv_func_printf_sizes_c99="guessing no";; + openbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; + # Guess yes on Solaris >= 2.10. + solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; + solaris*) gl_cv_func_printf_sizes_c99="guessing no";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_printf_sizes_c99="guessing no";; + netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_sizes_c99="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports 'long double' +dnl arguments together with the 'L' size specifier. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_long_double. + +AC_DEFUN([gl_PRINTF_LONG_DOUBLE], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports 'long double' arguments], + [gl_cv_func_printf_long_double], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[10000]; +int main () +{ + int result = 0; + buf[0] = '\0'; + if (sprintf (buf, "%Lf %d", 1.75L, 33, 44, 55) < 0 + || strcmp (buf, "1.750000 33") != 0) + result |= 1; + buf[0] = '\0'; + if (sprintf (buf, "%Le %d", 1.75L, 33, 44, 55) < 0 + || strcmp (buf, "1.750000e+00 33") != 0) + result |= 2; + buf[0] = '\0'; + if (sprintf (buf, "%Lg %d", 1.75L, 33, 44, 55) < 0 + || strcmp (buf, "1.75 33") != 0) + result |= 4; + return result; +}]])], + [gl_cv_func_printf_long_double=yes], + [gl_cv_func_printf_long_double=no], + [ +changequote(,)dnl + case "$host_os" in + beos*) gl_cv_func_printf_long_double="guessing no";; + mingw* | pw*) gl_cv_func_printf_long_double="guessing no";; + *) gl_cv_func_printf_long_double="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports infinite and NaN +dnl 'double' arguments and negative zero arguments in the %f, %e, %g +dnl directives. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_infinite. + +AC_DEFUN([gl_PRINTF_INFINITE], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports infinite 'double' arguments], + [gl_cv_func_printf_infinite], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static int +strisnan (const char *string, size_t start_index, size_t end_index) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} +static int +have_minus_zero () +{ + static double plus_zero = 0.0; + double minus_zero = - plus_zero; + return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0; +} +static char buf[10000]; +static double zero = 0.0; +int main () +{ + int result = 0; + if (sprintf (buf, "%f", 1.0 / zero) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 1; + if (sprintf (buf, "%f", -1.0 / zero) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 1; + if (sprintf (buf, "%f", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + if (sprintf (buf, "%e", 1.0 / zero) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 4; + if (sprintf (buf, "%e", -1.0 / zero) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 4; + if (sprintf (buf, "%e", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 8; + if (sprintf (buf, "%g", 1.0 / zero) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 16; + if (sprintf (buf, "%g", -1.0 / zero) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 16; + if (sprintf (buf, "%g", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 32; + /* This test fails on HP-UX 10.20. */ + if (have_minus_zero ()) + if (sprintf (buf, "%g", - zero) < 0 + || strcmp (buf, "-0") != 0) + result |= 64; + return result; +}]])], + [gl_cv_func_printf_infinite=yes], + [gl_cv_func_printf_infinite=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_infinite="guessing yes";; + # Guess yes on FreeBSD >= 6. + freebsd[1-5]*) gl_cv_func_printf_infinite="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_printf_infinite="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_printf_infinite="guessing no";; + darwin*) gl_cv_func_printf_infinite="guessing yes";; + # Guess yes on HP-UX >= 11. + hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";; + hpux*) gl_cv_func_printf_infinite="guessing yes";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_printf_infinite="guessing no";; + netbsd*) gl_cv_func_printf_infinite="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_printf_infinite="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_infinite="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports infinite and NaN +dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_infinite_long_double. + +AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE], +[ + AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gl_BIGENDIAN]) + AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + dnl The user can set or unset the variable gl_printf_safe to indicate + dnl that he wishes a safe handling of non-IEEE-754 'long double' values. + if test -n "$gl_printf_safe"; then + AC_DEFINE([CHECK_PRINTF_SAFE], [1], + [Define if you wish *printf() functions that have a safe handling of + non-IEEE-754 'long double' values.]) + fi + case "$gl_cv_func_printf_long_double" in + *yes) + AC_CACHE_CHECK([whether printf supports infinite 'long double' arguments], + [gl_cv_func_printf_infinite_long_double], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +]GL_NOCRASH[ +#include +#include +#include +static int +strisnan (const char *string, size_t start_index, size_t end_index) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} +static char buf[10000]; +static long double zeroL = 0.0L; +int main () +{ + int result = 0; + nocrash_init(); + if (sprintf (buf, "%Lf", 1.0L / zeroL) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Lf", -1.0L / zeroL) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Lf", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 1; + if (sprintf (buf, "%Le", 1.0L / zeroL) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Le", -1.0L / zeroL) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Le", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 1; + if (sprintf (buf, "%Lg", 1.0L / zeroL) < 0 + || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Lg", -1.0L / zeroL) < 0 + || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) + result |= 1; + if (sprintf (buf, "%Lg", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 1; +#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE +/* Representation of an 80-bit 'long double' as an initializer for a sequence + of 'unsigned int' words. */ +# ifdef WORDS_BIGENDIAN +# define LDBL80_WORDS(exponent,manthi,mantlo) \ + { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ + ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \ + (unsigned int) (mantlo) << 16 \ + } +# else +# define LDBL80_WORDS(exponent,manthi,mantlo) \ + { mantlo, manthi, exponent } +# endif + { /* Quiet NaN. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + } + { + /* Signalling NaN. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 2; + } + { /* Pseudo-NaN. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 4; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 4; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 4; + } + { /* Pseudo-Infinity. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 8; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 8; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 8; + } + { /* Pseudo-Zero. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 16; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 16; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 16; + } + { /* Unnormalized number. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 32; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 32; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 32; + } + { /* Pseudo-Denormal. */ + static union { unsigned int word[4]; long double value; } x = + { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; + if (sprintf (buf, "%Lf", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 64; + if (sprintf (buf, "%Le", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 64; + if (sprintf (buf, "%Lg", x.value) < 0 + || !strisnan (buf, 0, strlen (buf))) + result |= 64; + } +#endif + return result; +}]])], + [gl_cv_func_printf_infinite_long_double=yes], + [gl_cv_func_printf_infinite_long_double=no], + [ +changequote(,)dnl + case "$host_cpu" in + # Guess no on ia64, x86_64, i386. + ia64 | x86_64 | i*86) gl_cv_func_printf_infinite_long_double="guessing no";; + *) + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_infinite_long_double="guessing yes";; + # Guess yes on FreeBSD >= 6. + freebsd[1-5]*) gl_cv_func_printf_infinite_long_double="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_printf_infinite_long_double="guessing yes";; + # Guess yes on HP-UX >= 11. + hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; + hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_infinite_long_double="guessing no";; + esac + ;; + esac +changequote([,])dnl + ]) + ]) + ;; + *) + gl_cv_func_printf_infinite_long_double="irrelevant" + ;; + esac +]) + +dnl Test whether the *printf family of functions supports the 'a' and 'A' +dnl conversion specifier for hexadecimal output of floating-point numbers. +dnl (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_directive_a. + +AC_DEFUN([gl_PRINTF_DIRECTIVE_A], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the 'a' and 'A' directives], + [gl_cv_func_printf_directive_a], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[100]; +static double zero = 0.0; +int main () +{ + int result = 0; + if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0 + || (strcmp (buf, "0x1.922p+1 33") != 0 + && strcmp (buf, "0x3.244p+0 33") != 0 + && strcmp (buf, "0x6.488p-1 33") != 0 + && strcmp (buf, "0xc.91p-2 33") != 0)) + result |= 1; + if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0 + || (strcmp (buf, "-0X1.922P+1 33") != 0 + && strcmp (buf, "-0X3.244P+0 33") != 0 + && strcmp (buf, "-0X6.488P-1 33") != 0 + && strcmp (buf, "-0XC.91P-2 33") != 0)) + result |= 2; + /* This catches a FreeBSD 6.1 bug: it doesn't round. */ + if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0 + || (strcmp (buf, "0x1.83p+0 33") != 0 + && strcmp (buf, "0x3.05p-1 33") != 0 + && strcmp (buf, "0x6.0ap-2 33") != 0 + && strcmp (buf, "0xc.14p-3 33") != 0)) + result |= 4; + /* This catches a FreeBSD 6.1 bug. See + */ + if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0 + || buf[0] == '0') + result |= 8; + /* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */ + if (sprintf (buf, "%.1a", 1.999) < 0 + || (strcmp (buf, "0x1.0p+1") != 0 + && strcmp (buf, "0x2.0p+0") != 0 + && strcmp (buf, "0x4.0p-1") != 0 + && strcmp (buf, "0x8.0p-2") != 0)) + result |= 16; + /* This catches the same Mac OS X 10.3.9 (Darwin 7.9) bug and also a + glibc 2.4 bug . */ + if (sprintf (buf, "%.1La", 1.999L) < 0 + || (strcmp (buf, "0x1.0p+1") != 0 + && strcmp (buf, "0x2.0p+0") != 0 + && strcmp (buf, "0x4.0p-1") != 0 + && strcmp (buf, "0x8.0p-2") != 0)) + result |= 32; + return result; +}]])], + [gl_cv_func_printf_directive_a=yes], + [gl_cv_func_printf_directive_a=no], + [ + case "$host_os" in + # Guess yes on glibc >= 2.5 systems. + *-gnu*) + AC_EGREP_CPP([BZ2908], [ + #include + #ifdef __GNU_LIBRARY__ + #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 5) || (__GLIBC__ > 2)) && !defined __UCLIBC__ + BZ2908 + #endif + #endif + ], + [gl_cv_func_printf_directive_a="guessing yes"], + [gl_cv_func_printf_directive_a="guessing no"]) + ;; + # If we don't know, assume the worst. + *) gl_cv_func_printf_directive_a="guessing no";; + esac + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports the %F format +dnl directive. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_directive_f. + +AC_DEFUN([gl_PRINTF_DIRECTIVE_F], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the 'F' directive], + [gl_cv_func_printf_directive_f], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[100]; +static double zero = 0.0; +int main () +{ + int result = 0; + if (sprintf (buf, "%F %d", 1234567.0, 33, 44, 55) < 0 + || strcmp (buf, "1234567.000000 33") != 0) + result |= 1; + if (sprintf (buf, "%F", 1.0 / zero) < 0 + || (strcmp (buf, "INF") != 0 && strcmp (buf, "INFINITY") != 0)) + result |= 2; + /* This catches a Cygwin 1.5.x bug. */ + if (sprintf (buf, "%.F", 1234.0) < 0 + || strcmp (buf, "1234") != 0) + result |= 4; + return result; +}]])], + [gl_cv_func_printf_directive_f=yes], + [gl_cv_func_printf_directive_f=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_directive_f="guessing yes";; + # Guess yes on FreeBSD >= 6. + freebsd[1-5]*) gl_cv_func_printf_directive_f="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_printf_directive_f="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_printf_directive_f="guessing no";; + darwin*) gl_cv_func_printf_directive_f="guessing yes";; + # Guess yes on Solaris >= 2.10. + solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; + solaris*) gl_cv_func_printf_sizes_c99="guessing no";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_directive_f="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports the %n format +dnl directive. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_printf_directive_n. + +AC_DEFUN([gl_PRINTF_DIRECTIVE_N], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the 'n' directive], + [gl_cv_func_printf_directive_n], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +#ifdef _MSC_VER +/* See page about "Parameter Validation" on msdn.microsoft.com. */ +static void cdecl +invalid_parameter_handler (const wchar_t *expression, + const wchar_t *function, + const wchar_t *file, unsigned int line, + uintptr_t dummy) +{ + exit (1); +} +#endif +static char fmtstring[10]; +static char buf[100]; +int main () +{ + int count = -1; +#ifdef _MSC_VER + _set_invalid_parameter_handler (invalid_parameter_handler); +#endif + /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) + support %n in format strings in read-only memory but not in writable + memory. */ + strcpy (fmtstring, "%d %n"); + if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0 + || strcmp (buf, "123 ") != 0 + || count != 4) + return 1; + return 0; +}]])], + [gl_cv_func_printf_directive_n=yes], + [gl_cv_func_printf_directive_n=no], + [ +changequote(,)dnl + case "$host_os" in + mingw*) gl_cv_func_printf_directive_n="guessing no";; + *) gl_cv_func_printf_directive_n="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports the %ls format +dnl directive and in particular, when a precision is specified, whether +dnl the functions stop converting the wide string argument when the number +dnl of bytes that have been produced by this conversion equals or exceeds +dnl the precision. +dnl Result is gl_cv_func_printf_directive_ls. + +AC_DEFUN([gl_PRINTF_DIRECTIVE_LS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the 'ls' directive], + [gl_cv_func_printf_directive_ls], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +#include +int main () +{ + int result = 0; + char buf[100]; + /* Test whether %ls works at all. + This test fails on OpenBSD 4.0, IRIX 6.5, Solaris 2.6, Haiku, but not on + Cygwin 1.5. */ + { + static const wchar_t wstring[] = { 'a', 'b', 'c', 0 }; + buf[0] = '\0'; + if (sprintf (buf, "%ls", wstring) < 0 + || strcmp (buf, "abc") != 0) + result |= 1; + } + /* This test fails on IRIX 6.5, Solaris 2.6, Cygwin 1.5, Haiku (with an + assertion failure inside libc), but not on OpenBSD 4.0. */ + { + static const wchar_t wstring[] = { 'a', 0 }; + buf[0] = '\0'; + if (sprintf (buf, "%ls", wstring) < 0 + || strcmp (buf, "a") != 0) + result |= 2; + } + /* Test whether precisions in %ls are supported as specified in ISO C 99 + section 7.19.6.1: + "If a precision is specified, no more than that many bytes are written + (including shift sequences, if any), and the array shall contain a + null wide character if, to equal the multibyte character sequence + length given by the precision, the function would need to access a + wide character one past the end of the array." + This test fails on Solaris 10. */ + { + static const wchar_t wstring[] = { 'a', 'b', (wchar_t) 0xfdfdfdfd, 0 }; + buf[0] = '\0'; + if (sprintf (buf, "%.2ls", wstring) < 0 + || strcmp (buf, "ab") != 0) + result |= 8; + } + return result; +}]])], + [gl_cv_func_printf_directive_ls=yes], + [gl_cv_func_printf_directive_ls=no], + [ +changequote(,)dnl + case "$host_os" in + openbsd*) gl_cv_func_printf_directive_ls="guessing no";; + irix*) gl_cv_func_printf_directive_ls="guessing no";; + solaris*) gl_cv_func_printf_directive_ls="guessing no";; + cygwin*) gl_cv_func_printf_directive_ls="guessing no";; + beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; + *) gl_cv_func_printf_directive_ls="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports POSIX/XSI format +dnl strings with positions. (POSIX:2001) +dnl Result is gl_cv_func_printf_positions. + +AC_DEFUN([gl_PRINTF_POSITIONS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports POSIX/XSI format strings with positions], + [gl_cv_func_printf_positions], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* The string "%2$d %1$d", with dollar characters protected from the shell's + dollar expansion (possibly an autoconf bug). */ +static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; +static char buf[100]; +int main () +{ + sprintf (buf, format, 33, 55); + return (strcmp (buf, "55 33") != 0); +}]])], + [gl_cv_func_printf_positions=yes], + [gl_cv_func_printf_positions=no], + [ +changequote(,)dnl + case "$host_os" in + netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*) + gl_cv_func_printf_positions="guessing no";; + beos*) gl_cv_func_printf_positions="guessing no";; + mingw* | pw*) gl_cv_func_printf_positions="guessing no";; + *) gl_cv_func_printf_positions="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports POSIX/XSI format +dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001) +dnl Result is gl_cv_func_printf_flag_grouping. + +AC_DEFUN([gl_PRINTF_FLAG_GROUPING], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the grouping flag], + [gl_cv_func_printf_flag_grouping], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[100]; +int main () +{ + if (sprintf (buf, "%'d %d", 1234567, 99) < 0 + || buf[strlen (buf) - 1] != '9') + return 1; + return 0; +}]])], + [gl_cv_func_printf_flag_grouping=yes], + [gl_cv_func_printf_flag_grouping=no], + [ +changequote(,)dnl + case "$host_os" in + cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; + netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; + mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; + *) gl_cv_func_printf_flag_grouping="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports the - flag correctly. +dnl (ISO C99.) See +dnl +dnl Result is gl_cv_func_printf_flag_leftadjust. + +AC_DEFUN([gl_PRINTF_FLAG_LEFTADJUST], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the left-adjust flag correctly], + [gl_cv_func_printf_flag_leftadjust], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[100]; +int main () +{ + /* Check that a '-' flag is not annihilated by a negative width. */ + if (sprintf (buf, "a%-*sc", -3, "b") < 0 + || strcmp (buf, "ab c") != 0) + return 1; + return 0; +}]])], + [gl_cv_func_printf_flag_leftadjust=yes], + [gl_cv_func_printf_flag_leftadjust=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on HP-UX 11. + hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; + # Guess no on HP-UX 10 and older. + hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; + # Guess yes otherwise. + *) gl_cv_func_printf_flag_leftadjust="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports padding of non-finite +dnl values with the 0 flag correctly. (ISO C99 + TC1 + TC2.) See +dnl +dnl Result is gl_cv_func_printf_flag_zero. + +AC_DEFUN([gl_PRINTF_FLAG_ZERO], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the zero flag correctly], + [gl_cv_func_printf_flag_zero], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[100]; +static double zero = 0.0; +int main () +{ + if (sprintf (buf, "%010f", 1.0 / zero, 33, 44, 55) < 0 + || (strcmp (buf, " inf") != 0 + && strcmp (buf, " infinity") != 0)) + return 1; + return 0; +}]])], + [gl_cv_func_printf_flag_zero=yes], + [gl_cv_func_printf_flag_zero=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_flag_zero="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_printf_flag_zero="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_flag_zero="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions supports large precisions. +dnl On mingw, precisions larger than 512 are treated like 512, in integer, +dnl floating-point or pointer output. On Solaris 10/x86, precisions larger +dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC, +dnl precisions larger than 510 in floating-point output yield wrong results. +dnl On AIX 7.1, precisions larger than 998 in floating-point output yield +dnl wrong results. On BeOS, precisions larger than 1044 crash the program. +dnl Result is gl_cv_func_printf_precision. + +AC_DEFUN([gl_PRINTF_PRECISION], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports large precisions], + [gl_cv_func_printf_precision], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static char buf[5000]; +int main () +{ + int result = 0; +#ifdef __BEOS__ + /* On BeOS, this would crash and show a dialog box. Avoid the crash. */ + return 1; +#endif + if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3) + result |= 1; + if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5) + result |= 2; + if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5 + || buf[0] != '1') + result |= 4; + if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5 + || buf[0] != '1') + result |= 4; + return result; +}]])], + [gl_cv_func_printf_precision=yes], + [gl_cv_func_printf_precision=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess no only on Solaris, native Windows, and BeOS systems. + solaris*) gl_cv_func_printf_precision="guessing no" ;; + mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; + beos*) gl_cv_func_printf_precision="guessing no" ;; + *) gl_cv_func_printf_precision="guessing yes" ;; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the *printf family of functions recovers gracefully in case +dnl of an out-of-memory condition, or whether it crashes the entire program. +dnl Result is gl_cv_func_printf_enomem. + +AC_DEFUN([gl_PRINTF_ENOMEM], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gl_MULTIARCH]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf survives out-of-memory conditions], + [gl_cv_func_printf_enomem], + [ + gl_cv_func_printf_enomem="guessing no" + if test "$cross_compiling" = no; then + if test $APPLE_UNIVERSAL_BUILD = 0; then + AC_LANG_CONFTEST([AC_LANG_SOURCE([ +]GL_NOCRASH[ +changequote(,)dnl +#include +#include +#include +#include +#include +int main() +{ + struct rlimit limit; + int ret; + nocrash_init (); + /* Some printf implementations allocate temporary space with malloc. */ + /* On BSD systems, malloc() is limited by RLIMIT_DATA. */ +#ifdef RLIMIT_DATA + if (getrlimit (RLIMIT_DATA, &limit) < 0) + return 77; + if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) + limit.rlim_max = 5000000; + limit.rlim_cur = limit.rlim_max; + if (setrlimit (RLIMIT_DATA, &limit) < 0) + return 77; +#endif + /* On Linux systems, malloc() is limited by RLIMIT_AS. */ +#ifdef RLIMIT_AS + if (getrlimit (RLIMIT_AS, &limit) < 0) + return 77; + if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) + limit.rlim_max = 5000000; + limit.rlim_cur = limit.rlim_max; + if (setrlimit (RLIMIT_AS, &limit) < 0) + return 77; +#endif + /* Some printf implementations allocate temporary space on the stack. */ +#ifdef RLIMIT_STACK + if (getrlimit (RLIMIT_STACK, &limit) < 0) + return 77; + if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > 5000000) + limit.rlim_max = 5000000; + limit.rlim_cur = limit.rlim_max; + if (setrlimit (RLIMIT_STACK, &limit) < 0) + return 77; +#endif + ret = printf ("%.5000000f", 1.0); + return !(ret == 5000002 || (ret < 0 && errno == ENOMEM)); +} +changequote([,])dnl + ])]) + if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then + (./conftest 2>&AS_MESSAGE_LOG_FD + result=$? + _AS_ECHO_LOG([\$? = $result]) + if test $result != 0 && test $result != 77; then result=1; fi + exit $result + ) >/dev/null 2>/dev/null + case $? in + 0) gl_cv_func_printf_enomem="yes" ;; + 77) gl_cv_func_printf_enomem="guessing no" ;; + *) gl_cv_func_printf_enomem="no" ;; + esac + else + gl_cv_func_printf_enomem="guessing no" + fi + rm -fr conftest* + else + dnl A universal build on Apple Mac OS X platforms. + dnl The result would be 'no' in 32-bit mode and 'yes' in 64-bit mode. + dnl But we need a configuration result that is valid in both modes. + gl_cv_func_printf_enomem="guessing no" + fi + fi + if test "$gl_cv_func_printf_enomem" = "guessing no"; then +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on Solaris. + solaris*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on AIX. + aix*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on HP-UX/hppa. + hpux*) case "$host_cpu" in + hppa*) gl_cv_func_printf_enomem="guessing yes";; + *) gl_cv_func_printf_enomem="guessing no";; + esac + ;; + # Guess yes on IRIX. + irix*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on OSF/1. + osf*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on Haiku. + haiku*) gl_cv_func_printf_enomem="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_enomem="guessing no";; + esac +changequote([,])dnl + fi + ]) +]) + +dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001) +dnl Result is ac_cv_func_snprintf. + +AC_DEFUN([gl_SNPRINTF_PRESENCE], +[ + AC_CHECK_FUNCS_ONCE([snprintf]) +]) + +dnl Test whether the string produced by the snprintf function is always NUL +dnl terminated. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_snprintf_truncation_c99. + +AC_DEFUN([gl_SNPRINTF_TRUNCATION_C99], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_SNPRINTF_PRESENCE]) + AC_CACHE_CHECK([whether snprintf truncates the result as in C99], + [gl_cv_func_snprintf_truncation_c99], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SNPRINTF +# define my_snprintf snprintf +#else +# include +static int my_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + va_start (args, format); + ret = vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} +#endif +static char buf[100]; +int main () +{ + strcpy (buf, "ABCDEF"); + my_snprintf (buf, 3, "%d %d", 4567, 89); + if (memcmp (buf, "45\0DEF", 6) != 0) + return 1; + return 0; +}]])], + [gl_cv_func_snprintf_truncation_c99=yes], + [gl_cv_func_snprintf_truncation_c99=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on FreeBSD >= 5. + freebsd[1-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_snprintf_truncation_c99="guessing no";; + darwin*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on OpenBSD >= 3.9. + openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) + gl_cv_func_snprintf_truncation_c99="guessing no";; + openbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on Solaris >= 2.6. + solaris2.[0-5] | solaris2.[0-5].*) + gl_cv_func_snprintf_truncation_c99="guessing no";; + solaris*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on AIX >= 4. + aix[1-3]*) gl_cv_func_snprintf_truncation_c99="guessing no";; + aix*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on HP-UX >= 11. + hpux[7-9]* | hpux10*) gl_cv_func_snprintf_truncation_c99="guessing no";; + hpux*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on IRIX >= 6.5. + irix6.5) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on OSF/1 >= 5. + osf[3-4]*) gl_cv_func_snprintf_truncation_c99="guessing no";; + osf*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_snprintf_truncation_c99="guessing no";; + netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_snprintf_truncation_c99="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the return value of the snprintf function is the number +dnl of bytes (excluding the terminating NUL) that would have been produced +dnl if the buffer had been large enough. (ISO C99, POSIX:2001) +dnl For example, this test program fails on IRIX 6.5: +dnl --------------------------------------------------------------------- +dnl #include +dnl int main() +dnl { +dnl static char buf[8]; +dnl int retval = snprintf (buf, 3, "%d", 12345); +dnl return retval >= 0 && retval < 3; +dnl } +dnl --------------------------------------------------------------------- +dnl Result is gl_cv_func_snprintf_retval_c99. + +AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_SNPRINTF_PRESENCE]) + AC_CACHE_CHECK([whether snprintf returns a byte count as in C99], + [gl_cv_func_snprintf_retval_c99], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SNPRINTF +# define my_snprintf snprintf +#else +# include +static int my_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + va_start (args, format); + ret = vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} +#endif +static char buf[100]; +int main () +{ + strcpy (buf, "ABCDEF"); + if (my_snprintf (buf, 3, "%d %d", 4567, 89) != 7) + return 1; + if (my_snprintf (buf, 0, "%d %d", 4567, 89) != 7) + return 2; + if (my_snprintf (NULL, 0, "%d %d", 4567, 89) != 7) + return 3; + return 0; +}]])], + [gl_cv_func_snprintf_retval_c99=yes], + [gl_cv_func_snprintf_retval_c99=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on FreeBSD >= 5. + freebsd[1-4]*) gl_cv_func_snprintf_retval_c99="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_snprintf_retval_c99="guessing no";; + darwin*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on OpenBSD >= 3.9. + openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*) + gl_cv_func_snprintf_retval_c99="guessing no";; + openbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on Solaris >= 2.10. + solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";; + solaris*) gl_cv_func_printf_sizes_c99="guessing no";; + # Guess yes on AIX >= 4. + aix[1-3]*) gl_cv_func_snprintf_retval_c99="guessing no";; + aix*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_snprintf_retval_c99="guessing no";; + netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_snprintf_retval_c99="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the snprintf function supports the %n format directive +dnl also in truncated portions of the format string. (ISO C99, POSIX:2001) +dnl Result is gl_cv_func_snprintf_directive_n. + +AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_SNPRINTF_PRESENCE]) + AC_CACHE_CHECK([whether snprintf fully supports the 'n' directive], + [gl_cv_func_snprintf_directive_n], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#if HAVE_SNPRINTF +# define my_snprintf snprintf +#else +# include +static int my_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + va_start (args, format); + ret = vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} +#endif +static char fmtstring[10]; +static char buf[100]; +int main () +{ + int count = -1; + /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) + support %n in format strings in read-only memory but not in writable + memory. */ + strcpy (fmtstring, "%d %n"); + my_snprintf (buf, 4, fmtstring, 12345, &count, 33, 44, 55); + if (count != 6) + return 1; + return 0; +}]])], + [gl_cv_func_snprintf_directive_n=yes], + [gl_cv_func_snprintf_directive_n=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on FreeBSD >= 5. + freebsd[1-4]*) gl_cv_func_snprintf_directive_n="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_snprintf_directive_n="guessing no";; + darwin*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on Solaris >= 2.6. + solaris2.[0-5] | solaris2.[0-5].*) + gl_cv_func_snprintf_directive_n="guessing no";; + solaris*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on AIX >= 4. + aix[1-3]*) gl_cv_func_snprintf_directive_n="guessing no";; + aix*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on IRIX >= 6.5. + irix6.5) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on OSF/1 >= 5. + osf[3-4]*) gl_cv_func_snprintf_directive_n="guessing no";; + osf*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_snprintf_directive_n="guessing no";; + netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_snprintf_directive_n="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_snprintf_directive_n="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl Test whether the snprintf function, when passed a size = 1, writes any +dnl output without bounds in this case, behaving like sprintf. This is the +dnl case on Linux libc5. +dnl Result is gl_cv_func_snprintf_size1. + +AC_DEFUN([gl_SNPRINTF_SIZE1], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gl_SNPRINTF_PRESENCE]) + AC_CACHE_CHECK([whether snprintf respects a size of 1], + [gl_cv_func_snprintf_size1], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#if HAVE_SNPRINTF +# define my_snprintf snprintf +#else +# include +static int my_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + va_start (args, format); + ret = vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} +#endif +int main() +{ + static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; + my_snprintf (buf, 1, "%d", 12345); + return buf[1] != 'E'; +}]])], + [gl_cv_func_snprintf_size1=yes], + [gl_cv_func_snprintf_size1=no], + [gl_cv_func_snprintf_size1="guessing yes"]) + ]) +]) + +dnl Test whether the vsnprintf function, when passed a zero size, produces no +dnl output. (ISO C99, POSIX:2001) +dnl For example, snprintf nevertheless writes a NUL byte in this case +dnl on OSF/1 5.1: +dnl --------------------------------------------------------------------- +dnl #include +dnl int main() +dnl { +dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; +dnl snprintf (buf, 0, "%d", 12345); +dnl return buf[0] != 'D'; +dnl } +dnl --------------------------------------------------------------------- +dnl And vsnprintf writes any output without bounds in this case, behaving like +dnl vsprintf, on HP-UX 11 and OSF/1 5.1: +dnl --------------------------------------------------------------------- +dnl #include +dnl #include +dnl static int my_snprintf (char *buf, int size, const char *format, ...) +dnl { +dnl va_list args; +dnl int ret; +dnl va_start (args, format); +dnl ret = vsnprintf (buf, size, format, args); +dnl va_end (args); +dnl return ret; +dnl } +dnl int main() +dnl { +dnl static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; +dnl my_snprintf (buf, 0, "%d", 12345); +dnl return buf[0] != 'D'; +dnl } +dnl --------------------------------------------------------------------- +dnl Result is gl_cv_func_vsnprintf_zerosize_c99. + +AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether vsnprintf respects a zero size as in C99], + [gl_cv_func_vsnprintf_zerosize_c99], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +static int my_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + va_start (args, format); + ret = vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} +int main() +{ + static char buf[8] = { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F' }; + my_snprintf (buf, 0, "%d", 12345); + return buf[0] != 'D'; +}]])], + [gl_cv_func_vsnprintf_zerosize_c99=yes], + [gl_cv_func_vsnprintf_zerosize_c99=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on FreeBSD >= 5. + freebsd[1-4]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + freebsd* | kfreebsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on Mac OS X >= 10.3. + darwin[1-6].*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + darwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on Cygwin. + cygwin*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on Solaris >= 2.6. + solaris2.[0-5] | solaris2.[0-5].*) + gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + solaris*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on AIX >= 4. + aix[1-3]*) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + aix*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on IRIX >= 6.5. + irix6.5) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on NetBSD >= 3. + netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) + gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on mingw. + mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # If we don't know, assume the worst. + *) gl_cv_func_vsnprintf_zerosize_c99="guessing no";; + esac +changequote([,])dnl + ]) + ]) +]) + +dnl The results of these tests on various platforms are: +dnl +dnl 1 = gl_PRINTF_SIZES_C99 +dnl 2 = gl_PRINTF_LONG_DOUBLE +dnl 3 = gl_PRINTF_INFINITE +dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE +dnl 5 = gl_PRINTF_DIRECTIVE_A +dnl 6 = gl_PRINTF_DIRECTIVE_F +dnl 7 = gl_PRINTF_DIRECTIVE_N +dnl 8 = gl_PRINTF_DIRECTIVE_LS +dnl 9 = gl_PRINTF_POSITIONS +dnl 10 = gl_PRINTF_FLAG_GROUPING +dnl 11 = gl_PRINTF_FLAG_LEFTADJUST +dnl 12 = gl_PRINTF_FLAG_ZERO +dnl 13 = gl_PRINTF_PRECISION +dnl 14 = gl_PRINTF_ENOMEM +dnl 15 = gl_SNPRINTF_PRESENCE +dnl 16 = gl_SNPRINTF_TRUNCATION_C99 +dnl 17 = gl_SNPRINTF_RETVAL_C99 +dnl 18 = gl_SNPRINTF_DIRECTIVE_N +dnl 19 = gl_SNPRINTF_SIZE1 +dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99 +dnl +dnl 1 = checking whether printf supports size specifiers as in C99... +dnl 2 = checking whether printf supports 'long double' arguments... +dnl 3 = checking whether printf supports infinite 'double' arguments... +dnl 4 = checking whether printf supports infinite 'long double' arguments... +dnl 5 = checking whether printf supports the 'a' and 'A' directives... +dnl 6 = checking whether printf supports the 'F' directive... +dnl 7 = checking whether printf supports the 'n' directive... +dnl 8 = checking whether printf supports the 'ls' directive... +dnl 9 = checking whether printf supports POSIX/XSI format strings with positions... +dnl 10 = checking whether printf supports the grouping flag... +dnl 11 = checking whether printf supports the left-adjust flag correctly... +dnl 12 = checking whether printf supports the zero flag correctly... +dnl 13 = checking whether printf supports large precisions... +dnl 14 = checking whether printf survives out-of-memory conditions... +dnl 15 = checking for snprintf... +dnl 16 = checking whether snprintf truncates the result as in C99... +dnl 17 = checking whether snprintf returns a byte count as in C99... +dnl 18 = checking whether snprintf fully supports the 'n' directive... +dnl 19 = checking whether snprintf respects a size of 1... +dnl 20 = checking whether vsnprintf respects a zero size as in C99... +dnl +dnl . = yes, # = no. +dnl +dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +dnl glibc 2.5 . . . . . . . . . . . . . . . . . . . . +dnl glibc 2.3.6 . . . . # . . . . . . . . . . . . . . . +dnl FreeBSD 5.4, 6.1 . . . . # . . . . . . # . # . . . . . . +dnl Mac OS X 10.5.8 . . . # # . . . . . . # . . . . . . . . +dnl Mac OS X 10.3.9 . . . . # . . . . . . # . # . . . . . . +dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . . . . . . +dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . +dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . +dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . +dnl Solaris 11 2011-11 . . # # # . . # . . . # . . . . . . . . +dnl Solaris 10 . . # # # . . # . . . # # . . . . . . . +dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . . +dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # +dnl AIX 7.1 . . # # # . . . . . . # # . . . . . . . +dnl AIX 5.2 . . # # # . . . . . . # . . . . . . . . +dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . . +dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . . +dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . # +dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? # +dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . . +dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . # +dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # # +dnl NetBSD 5.0 . . . # # . . . . . . # . # . . . . . . +dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . . . ? ? ? +dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . . +dnl Haiku . . . # # # . # . . . . . ? . . ? . . . +dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . . +dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . . +dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . . +dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . . +dnl mingw-w64 2011 # # # # # # . . # # . # # ? . # # # . . diff --git a/m4/progtest.m4 b/m4/progtest.m4 new file mode 100644 index 000000000..7b3912329 --- /dev/null +++ b/m4/progtest.m4 @@ -0,0 +1,91 @@ +# progtest.m4 serial 7 (gettext-0.18.2) +dnl Copyright (C) 1996-2003, 2005, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper , 1996. + +AC_PREREQ([2.50]) + +# Search path for a program which passes the given test. + +dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, +dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) +AC_DEFUN([AM_PATH_PROG_WITH_TEST], +[ +# Prepare PATH_SEPARATOR. +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which + # contains only /bin. Note that ksh looks also at the FPATH variable, + # so we have to set that as well for the test. + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ + || PATH_SEPARATOR=';' + } +fi + +# Find out how to test for executable files. Don't use a zero-byte file, +# as systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + ac_executable_p="test -x" +else + ac_executable_p="test -f" +fi +rm -f conf$$.file + +# Extract the first word of "$2", so it can be a program name with args. +set dummy $2; ac_word=[$]2 +AC_MSG_CHECKING([for $ac_word]) +AC_CACHE_VAL([ac_cv_path_$1], +[case "[$]$1" in + [[\\/]]* | ?:[[\\/]]*) + ac_cv_path_$1="[$]$1" # Let the user override the test with a path. + ;; + *) + ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in ifelse([$5], , $PATH, [$5]); do + IFS="$ac_save_IFS" + test -z "$ac_dir" && ac_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then + echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD + if [$3]; then + ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext" + break 2 + fi + fi + done + done + IFS="$ac_save_IFS" +dnl If no 4th arg is given, leave the cache variable unset, +dnl so AC_PATH_PROGS will keep looking. +ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" +])dnl + ;; +esac])dnl +$1="$ac_cv_path_$1" +if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then + AC_MSG_RESULT([$][$1]) +else + AC_MSG_RESULT([no]) +fi +AC_SUBST([$1])dnl +]) diff --git a/m4/rawmemchr.m4 b/m4/rawmemchr.m4 new file mode 100644 index 000000000..8c500547c --- /dev/null +++ b/m4/rawmemchr.m4 @@ -0,0 +1,20 @@ +# rawmemchr.m4 serial 2 +dnl Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_RAWMEMCHR], +[ + dnl Persuade glibc to declare rawmemchr(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([rawmemchr]) + if test $ac_cv_func_rawmemchr = no; then + HAVE_RAWMEMCHR=0 + fi +]) + +# Prerequisites of lib/strchrnul.c. +AC_DEFUN([gl_PREREQ_RAWMEMCHR], [:]) diff --git a/m4/realloc.m4 b/m4/realloc.m4 new file mode 100644 index 000000000..d477fb470 --- /dev/null +++ b/m4/realloc.m4 @@ -0,0 +1,76 @@ +# realloc.m4 serial 13 +dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +m4_version_prereq([2.70], [] ,[ + +# This is taken from the following Autoconf patch: +# http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9 +AC_DEFUN([_AC_FUNC_REALLOC_IF], +[ + AC_REQUIRE([AC_HEADER_STDC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles + AC_CHECK_HEADERS([stdlib.h]) + AC_CACHE_CHECK([for GNU libc compatible realloc], + [ac_cv_func_realloc_0_nonnull], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H + # include + #else + char *realloc (); + #endif + ]], + [[return ! realloc (0, 0);]]) + ], + [ac_cv_func_realloc_0_nonnull=yes], + [ac_cv_func_realloc_0_nonnull=no], + [case "$host_os" in + # Guess yes on platforms where we know the result. + *-gnu* | freebsd* | netbsd* | openbsd* \ + | hpux* | solaris* | cygwin* | mingw*) + ac_cv_func_realloc_0_nonnull=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_realloc_0_nonnull=no ;; + esac + ]) + ]) + AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2]) +])# AC_FUNC_REALLOC + +]) + +# gl_FUNC_REALLOC_GNU +# ------------------- +# Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace +# realloc if it is not. +AC_DEFUN([gl_FUNC_REALLOC_GNU], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + dnl _AC_FUNC_REALLOC_IF is defined in Autoconf. + _AC_FUNC_REALLOC_IF( + [AC_DEFINE([HAVE_REALLOC_GNU], [1], + [Define to 1 if your system has a GNU libc compatible 'realloc' + function, and to 0 otherwise.])], + [AC_DEFINE([HAVE_REALLOC_GNU], [0]) + REPLACE_REALLOC=1 + ]) +])# gl_FUNC_REALLOC_GNU + +# gl_FUNC_REALLOC_POSIX +# --------------------- +# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it +# fails), and replace realloc if it is not. +AC_DEFUN([gl_FUNC_REALLOC_POSIX], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) + if test $gl_cv_func_malloc_posix = yes; then + AC_DEFINE([HAVE_REALLOC_POSIX], [1], + [Define if the 'realloc' function is POSIX compliant.]) + else + REPLACE_REALLOC=1 + fi +]) diff --git a/m4/regex.m4 b/m4/regex.m4 new file mode 100644 index 000000000..3334c1041 --- /dev/null +++ b/m4/regex.m4 @@ -0,0 +1,261 @@ +# serial 64 + +# Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +dnl Initially derived from code in GNU grep. +dnl Mostly written by Jim Meyering. + +AC_PREREQ([2.50]) + +AC_DEFUN([gl_REGEX], +[ + AC_ARG_WITH([included-regex], + [AS_HELP_STRING([--without-included-regex], + [don't compile regex; this is the default on systems + with recent-enough versions of the GNU C Library + (use with caution on other systems).])]) + + case $with_included_regex in #( + yes|no) ac_use_included_regex=$with_included_regex + ;; + '') + # If the system regex support is good enough that it passes the + # following run test, then default to *not* using the included regex.c. + # If cross compiling, assume the test would fail and use the included + # regex.c. + AC_CHECK_DECLS_ONCE([alarm]) + AC_CACHE_CHECK([for working re_compile_pattern], + [gl_cv_func_re_compile_pattern_working], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + + #include + #include + #include + #if HAVE_DECL_ALARM + # include + # include + #endif + ]], + [[int result = 0; + static struct re_pattern_buffer regex; + unsigned char folded_chars[UCHAR_MAX + 1]; + int i; + const char *s; + struct re_registers regs; + +#if HAVE_DECL_ALARM + /* Some builds of glibc go into an infinite loop on this test. */ + signal (SIGALRM, SIG_DFL); + alarm (2); +#endif + if (setlocale (LC_ALL, "en_US.UTF-8")) + { + { + /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html + This test needs valgrind to catch the bug on Debian + GNU/Linux 3.1 x86, but it might catch the bug better + on other platforms and it shouldn't hurt to try the + test here. */ + static char const pat[] = "insert into"; + static char const data[] = + "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; + re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE + | RE_ICASE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern (pat, sizeof pat - 1, ®ex); + if (s) + result |= 1; + else if (re_search (®ex, data, sizeof data - 1, + 0, sizeof data - 1, ®s) + != -1) + result |= 1; + } + + { + /* This test is from glibc bug 15078. + The test case is from Andreas Schwab in + . + */ + static char const pat[] = "[^x]x"; + static char const data[] = + "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80" + "\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax"; + re_set_syntax (0); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern (pat, sizeof pat - 1, ®ex); + if (s) + result |= 1; + else if (re_search (®ex, data, sizeof data - 1, + 0, sizeof data - 1, 0) + != 21) + result |= 1; + } + + if (! setlocale (LC_ALL, "C")) + return 1; + } + + /* This test is from glibc bug 3957, reported by Andrew Mackey. */ + re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("a[^x]b", 6, ®ex); + if (s) + result |= 2; + /* This should fail, but succeeds for glibc-2.5. */ + else if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1) + result |= 2; + + /* This regular expression is from Spencer ere test number 75 + in grep-2.3. */ + re_set_syntax (RE_SYNTAX_POSIX_EGREP); + memset (®ex, 0, sizeof regex); + for (i = 0; i <= UCHAR_MAX; i++) + folded_chars[i] = i; + regex.translate = folded_chars; + s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); + /* This should fail with _Invalid character class name_ error. */ + if (!s) + result |= 4; + + /* Ensure that [b-a] is diagnosed as invalid, when + using RE_NO_EMPTY_RANGES. */ + re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("a[b-a]", 6, ®ex); + if (s == 0) + result |= 8; + + /* This should succeed, but does not for glibc-2.1.3. */ + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("{1", 2, ®ex); + if (s) + result |= 8; + + /* The following example is derived from a problem report + against gawk from Jorge Stolfi . */ + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("[an\371]*n", 7, ®ex); + if (s) + result |= 8; + /* This should match, but does not for glibc-2.2.1. */ + else if (re_match (®ex, "an", 2, 0, ®s) != 2) + result |= 8; + + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("x", 1, ®ex); + if (s) + result |= 8; + /* glibc-2.2.93 does not work with a negative RANGE argument. */ + else if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) + result |= 8; + + /* The version of regex.c in older versions of gnulib + ignored RE_ICASE. Detect that problem too. */ + re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("x", 1, ®ex); + if (s) + result |= 16; + else if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) + result |= 16; + + /* Catch a bug reported by Vin Shelton in + http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html + */ + re_set_syntax (RE_SYNTAX_POSIX_BASIC + & ~RE_CONTEXT_INVALID_DUP + & ~RE_NO_EMPTY_RANGES); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex); + if (s) + result |= 32; + + /* REG_STARTEND was added to glibc on 2004-01-15. + Reject older versions. */ + if (! REG_STARTEND) + result |= 64; + +#if 0 + /* It would be nice to reject hosts whose regoff_t values are too + narrow (including glibc on hosts with 64-bit ptrdiff_t and + 32-bit int), but we should wait until glibc implements this + feature. Otherwise, support for equivalence classes and + multibyte collation symbols would always be broken except + when compiling --without-included-regex. */ + if (sizeof (regoff_t) < sizeof (ptrdiff_t) + || sizeof (regoff_t) < sizeof (ssize_t)) + result |= 64; +#endif + + return result; + ]])], + [gl_cv_func_re_compile_pattern_working=yes], + [gl_cv_func_re_compile_pattern_working=no], + dnl When crosscompiling, assume it is not working. + [gl_cv_func_re_compile_pattern_working=no])]) + case $gl_cv_func_re_compile_pattern_working in #( + yes) ac_use_included_regex=no;; #( + no) ac_use_included_regex=yes;; + esac + ;; + *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) + ;; + esac + + if test $ac_use_included_regex = yes; then + AC_DEFINE([_REGEX_INCLUDE_LIMITS_H], [1], + [Define if you want to include , so that it + consistently overrides 's RE_DUP_MAX.]) + AC_DEFINE([_REGEX_LARGE_OFFSETS], [1], + [Define if you want regoff_t to be at least as wide POSIX requires.]) + AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], + [Define to rpl_re_syntax_options if the replacement should be used.]) + AC_DEFINE([re_set_syntax], [rpl_re_set_syntax], + [Define to rpl_re_set_syntax if the replacement should be used.]) + AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern], + [Define to rpl_re_compile_pattern if the replacement should be used.]) + AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap], + [Define to rpl_re_compile_fastmap if the replacement should be used.]) + AC_DEFINE([re_search], [rpl_re_search], + [Define to rpl_re_search if the replacement should be used.]) + AC_DEFINE([re_search_2], [rpl_re_search_2], + [Define to rpl_re_search_2 if the replacement should be used.]) + AC_DEFINE([re_match], [rpl_re_match], + [Define to rpl_re_match if the replacement should be used.]) + AC_DEFINE([re_match_2], [rpl_re_match_2], + [Define to rpl_re_match_2 if the replacement should be used.]) + AC_DEFINE([re_set_registers], [rpl_re_set_registers], + [Define to rpl_re_set_registers if the replacement should be used.]) + AC_DEFINE([re_comp], [rpl_re_comp], + [Define to rpl_re_comp if the replacement should be used.]) + AC_DEFINE([re_exec], [rpl_re_exec], + [Define to rpl_re_exec if the replacement should be used.]) + AC_DEFINE([regcomp], [rpl_regcomp], + [Define to rpl_regcomp if the replacement should be used.]) + AC_DEFINE([regexec], [rpl_regexec], + [Define to rpl_regexec if the replacement should be used.]) + AC_DEFINE([regerror], [rpl_regerror], + [Define to rpl_regerror if the replacement should be used.]) + AC_DEFINE([regfree], [rpl_regfree], + [Define to rpl_regfree if the replacement should be used.]) + fi +]) + +# Prerequisites of lib/regex.c and lib/regex_internal.c. +AC_DEFUN([gl_PREREQ_REGEX], +[ + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + AC_REQUIRE([gl_EEMALLOC]) + AC_CHECK_HEADERS([libintl.h]) + AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll]) + AC_CHECK_DECLS([isblank], [], [], [[#include ]]) +]) diff --git a/m4/size_max.m4 b/m4/size_max.m4 new file mode 100644 index 000000000..4b247abc0 --- /dev/null +++ b/m4/size_max.m4 @@ -0,0 +1,79 @@ +# size_max.m4 serial 10 +dnl Copyright (C) 2003, 2005-2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([gl_SIZE_MAX], +[ + AC_CHECK_HEADERS([stdint.h]) + dnl First test whether the system already has SIZE_MAX. + AC_CACHE_CHECK([for SIZE_MAX], [gl_cv_size_max], [ + gl_cv_size_max= + AC_EGREP_CPP([Found it], [ +#include +#if HAVE_STDINT_H +#include +#endif +#ifdef SIZE_MAX +Found it +#endif +], [gl_cv_size_max=yes]) + if test -z "$gl_cv_size_max"; then + dnl Define it ourselves. Here we assume that the type 'size_t' is not wider + dnl than the type 'unsigned long'. Try hard to find a definition that can + dnl be used in a preprocessor #if, i.e. doesn't contain a cast. + AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], + [#include +#include ], [size_t_bits_minus_1=]) + AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], + [#include ], [fits_in_uint=]) + if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then + if test $fits_in_uint = 1; then + dnl Even though SIZE_MAX fits in an unsigned int, it must be of type + dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + extern size_t foo; + extern unsigned long foo; + ]], + [[]])], + [fits_in_uint=0]) + fi + dnl We cannot use 'expr' to simplify this expression, because 'expr' + dnl works only with 'long' integers in the host environment, while we + dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. + if test $fits_in_uint = 1; then + gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" + else + gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" + fi + else + dnl Shouldn't happen, but who knows... + gl_cv_size_max='((size_t)~(size_t)0)' + fi + fi + ]) + if test "$gl_cv_size_max" != yes; then + AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], + [Define as the maximum value of type 'size_t', if the system doesn't define it.]) + fi + dnl Don't redefine SIZE_MAX in config.h if config.h is re-included after + dnl . Remember that the #undef in AH_VERBATIM gets replaced with + dnl #define by AC_DEFINE_UNQUOTED. + AH_VERBATIM([SIZE_MAX], +[/* Define as the maximum value of type 'size_t', if the system doesn't define + it. */ +#ifndef SIZE_MAX +# undef SIZE_MAX +#endif]) +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) diff --git a/m4/sleep.m4 b/m4/sleep.m4 new file mode 100644 index 000000000..a27baa6d5 --- /dev/null +++ b/m4/sleep.m4 @@ -0,0 +1,62 @@ +# sleep.m4 serial 7 +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_SLEEP], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + dnl We expect to see the declaration of sleep() in a header file. + dnl Older versions of mingw have a sleep() function that is an alias to + dnl _sleep() in MSVCRT. It has a different signature than POSIX sleep(): + dnl it takes the number of milliseconds as argument and returns void. + dnl mingw does not declare this function. + AC_CHECK_DECLS([sleep], , , [[#include ]]) + AC_CHECK_FUNCS_ONCE([sleep]) + if test $ac_cv_have_decl_sleep != yes; then + HAVE_SLEEP=0 + else + dnl Cygwin 1.5.x has a bug where sleep can't exceed 49.7 days. + AC_CACHE_CHECK([for working sleep], [gl_cv_func_sleep_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include +static void +handle_alarm (int sig) +{ + if (sig != SIGALRM) + _exit (2); +} +]], [[ + /* Failure to compile this test due to missing alarm is okay, + since all such platforms (mingw) also lack sleep. */ + unsigned int pentecost = 50 * 24 * 60 * 60; /* 50 days. */ + unsigned int remaining; + signal (SIGALRM, handle_alarm); + alarm (1); + remaining = sleep (pentecost); + if (remaining > pentecost) + return 3; + if (remaining <= pentecost - 10) + return 4; + return 0; + ]])], + [gl_cv_func_sleep_works=yes], [gl_cv_func_sleep_works=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_sleep_works="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_sleep_works="guessing no" ;; + esac + ])]) + case "$gl_cv_func_sleep_works" in + *yes) ;; + *) + REPLACE_SLEEP=1 + ;; + esac + fi +]) diff --git a/m4/ssize_t.m4 b/m4/ssize_t.m4 new file mode 100644 index 000000000..633813434 --- /dev/null +++ b/m4/ssize_t.m4 @@ -0,0 +1,23 @@ +# ssize_t.m4 serial 5 (gettext-0.18.2) +dnl Copyright (C) 2001-2003, 2006, 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether ssize_t is defined. + +AC_DEFUN([gt_TYPE_SSIZE_T], +[ + AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[int x = sizeof (ssize_t *) + sizeof (ssize_t); + return !x;]])], + [gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])]) + if test $gt_cv_ssize_t = no; then + AC_DEFINE([ssize_t], [int], + [Define as a signed type of the same size as size_t.]) + fi +]) diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 new file mode 100644 index 000000000..a866ff670 --- /dev/null +++ b/m4/stdalign.m4 @@ -0,0 +1,52 @@ +# Check for stdalign.h that conforms to C11. + +dnl Copyright 2011-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Prepare for substituting if it is not supported. + +AC_DEFUN([gl_STDALIGN_H], +[ + AC_CACHE_CHECK([for working stdalign.h], + [gl_cv_header_working_stdalign_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + + /* Test that alignof yields a result consistent with offsetof. + This catches GCC bug 52023 + . */ + #ifdef __cplusplus + template struct alignof_helper { char a; t b; }; + # define ao(type) offsetof (alignof_helper, b) + #else + # define ao(type) offsetof (struct { char a; type b; }, b) + #endif + char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1]; + char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; + char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; + + /* Test _Alignas only on platforms where gnulib can help. */ + #if \ + (__GNUC__ || __IBMC__ || __IBMCPP__ \ + || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) + struct alignas_test { char c; char alignas (8) alignas_8; }; + char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 + ? 1 : -1]; + #endif + ]])], + [gl_cv_header_working_stdalign_h=yes], + [gl_cv_header_working_stdalign_h=no])]) + + if test $gl_cv_header_working_stdalign_h = yes; then + STDALIGN_H='' + else + STDALIGN_H='stdalign.h' + fi + + AC_SUBST([STDALIGN_H]) + AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) +]) diff --git a/m4/stdbool.m4 b/m4/stdbool.m4 new file mode 100644 index 000000000..80d5559ab --- /dev/null +++ b/m4/stdbool.m4 @@ -0,0 +1,100 @@ +# Check for stdbool.h that conforms to C99. + +dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +#serial 5 + +# Prepare for substituting if it is not supported. + +AC_DEFUN([AM_STDBOOL_H], +[ + AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) + + # Define two additional variables used in the Makefile substitution. + + if test "$ac_cv_header_stdbool_h" = yes; then + STDBOOL_H='' + else + STDBOOL_H='stdbool.h' + fi + AC_SUBST([STDBOOL_H]) + AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"]) + + if test "$ac_cv_type__Bool" = yes; then + HAVE__BOOL=1 + else + HAVE__BOOL=0 + fi + AC_SUBST([HAVE__BOOL]) +]) + +# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. +AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) + +# This version of the macro is needed in autoconf <= 2.68. + +AC_DEFUN([AC_CHECK_HEADER_STDBOOL], + [AC_CACHE_CHECK([for stdbool.h that conforms to C99], + [ac_cv_header_stdbool_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ + #include + #ifndef bool + "error: bool is not defined" + #endif + #ifndef false + "error: false is not defined" + #endif + #if false + "error: false is not 0" + #endif + #ifndef true + "error: true is not defined" + #endif + #if true != 1 + "error: true is not 1" + #endif + #ifndef __bool_true_false_are_defined + "error: __bool_true_false_are_defined is not defined" + #endif + + struct s { _Bool s: 1; _Bool t; } s; + + char a[true == 1 ? 1 : -1]; + char b[false == 0 ? 1 : -1]; + char c[__bool_true_false_are_defined == 1 ? 1 : -1]; + char d[(bool) 0.5 == true ? 1 : -1]; + /* See body of main program for 'e'. */ + char f[(_Bool) 0.0 == false ? 1 : -1]; + char g[true]; + char h[sizeof (_Bool)]; + char i[sizeof s.t]; + enum { j = false, k = true, l = false * true, m = true * 256 }; + /* The following fails for + HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ + _Bool n[m]; + char o[sizeof n == m * sizeof n[0] ? 1 : -1]; + char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; + /* Catch a bug in an HP-UX C compiler. See + http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html + */ + _Bool q = true; + _Bool *pq = &q; + ]], + [[ + bool e = &s; + *pq |= q; + *pq |= ! q; + /* Refer to every declared value, to avoid compiler optimizations. */ + return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l + + !m + !n + !o + !p + !q + !pq); + ]])], + [ac_cv_header_stdbool_h=yes], + [ac_cv_header_stdbool_h=no])]) + AC_CHECK_TYPES([_Bool]) +]) diff --git a/m4/stddef_h.m4 b/m4/stddef_h.m4 new file mode 100644 index 000000000..5da8ab1ec --- /dev/null +++ b/m4/stddef_h.m4 @@ -0,0 +1,47 @@ +dnl A placeholder for POSIX 2008 , for platforms that have issues. +# stddef_h.m4 serial 4 +dnl Copyright (C) 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STDDEF_H], +[ + AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + STDDEF_H= + if test $gt_cv_c_wchar_t = no; then + HAVE_WCHAR_T=0 + STDDEF_H=stddef.h + fi + AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], + [gl_cv_decl_null_works], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include + int test[2 * (sizeof NULL == sizeof (void *)) -1]; +]])], + [gl_cv_decl_null_works=yes], + [gl_cv_decl_null_works=no])]) + if test $gl_cv_decl_null_works = no; then + REPLACE_NULL=1 + STDDEF_H=stddef.h + fi + AC_SUBST([STDDEF_H]) + AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) + if test -n "$STDDEF_H"; then + gl_NEXT_HEADERS([stddef.h]) + fi +]) + +AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) +]) + +AC_DEFUN([gl_STDDEF_H_DEFAULTS], +[ + dnl Assume proper GNU behavior unless another module says otherwise. + REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) + HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) +]) diff --git a/m4/stdint.m4 b/m4/stdint.m4 new file mode 100644 index 000000000..27cdcdb9a --- /dev/null +++ b/m4/stdint.m4 @@ -0,0 +1,484 @@ +# stdint.m4 serial 43 +dnl Copyright (C) 2001-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert and Bruno Haible. +dnl Test whether is supported or must be substituted. + +AC_DEFUN_ONCE([gl_STDINT_H], +[ + AC_PREREQ([2.59])dnl + + dnl Check for long long int and unsigned long long int. + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + if test $ac_cv_type_long_long_int = yes; then + HAVE_LONG_LONG_INT=1 + else + HAVE_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + if test $ac_cv_type_unsigned_long_long_int = yes; then + HAVE_UNSIGNED_LONG_LONG_INT=1 + else + HAVE_UNSIGNED_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) + + dnl Check for , in the same way as gl_WCHAR_H does. + AC_CHECK_HEADERS_ONCE([wchar.h]) + if test $ac_cv_header_wchar_h = yes; then + HAVE_WCHAR_H=1 + else + HAVE_WCHAR_H=0 + fi + AC_SUBST([HAVE_WCHAR_H]) + + dnl Check for . + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. + if test $ac_cv_header_inttypes_h = yes; then + HAVE_INTTYPES_H=1 + else + HAVE_INTTYPES_H=0 + fi + AC_SUBST([HAVE_INTTYPES_H]) + + dnl Check for . + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. + if test $ac_cv_header_sys_types_h = yes; then + HAVE_SYS_TYPES_H=1 + else + HAVE_SYS_TYPES_H=0 + fi + AC_SUBST([HAVE_SYS_TYPES_H]) + + gl_CHECK_NEXT_HEADERS([stdint.h]) + if test $ac_cv_header_stdint_h = yes; then + HAVE_STDINT_H=1 + else + HAVE_STDINT_H=0 + fi + AC_SUBST([HAVE_STDINT_H]) + + dnl Now see whether we need a substitute . + if test $ac_cv_header_stdint_h = yes; then + AC_CACHE_CHECK([whether stdint.h conforms to C99], + [gl_cv_header_working_stdint_h], + [gl_cv_header_working_stdint_h=no + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ +#include +/* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in . */ +#if !(defined WCHAR_MIN && defined WCHAR_MAX) +#error "WCHAR_MIN, WCHAR_MAX not defined in " +#endif +] +gl_STDINT_INCLUDES +[ +#ifdef INT8_MAX +int8_t a1 = INT8_MAX; +int8_t a1min = INT8_MIN; +#endif +#ifdef INT16_MAX +int16_t a2 = INT16_MAX; +int16_t a2min = INT16_MIN; +#endif +#ifdef INT32_MAX +int32_t a3 = INT32_MAX; +int32_t a3min = INT32_MIN; +#endif +#ifdef INT64_MAX +int64_t a4 = INT64_MAX; +int64_t a4min = INT64_MIN; +#endif +#ifdef UINT8_MAX +uint8_t b1 = UINT8_MAX; +#else +typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; +#endif +#ifdef UINT16_MAX +uint16_t b2 = UINT16_MAX; +#endif +#ifdef UINT32_MAX +uint32_t b3 = UINT32_MAX; +#endif +#ifdef UINT64_MAX +uint64_t b4 = UINT64_MAX; +#endif +int_least8_t c1 = INT8_C (0x7f); +int_least8_t c1max = INT_LEAST8_MAX; +int_least8_t c1min = INT_LEAST8_MIN; +int_least16_t c2 = INT16_C (0x7fff); +int_least16_t c2max = INT_LEAST16_MAX; +int_least16_t c2min = INT_LEAST16_MIN; +int_least32_t c3 = INT32_C (0x7fffffff); +int_least32_t c3max = INT_LEAST32_MAX; +int_least32_t c3min = INT_LEAST32_MIN; +int_least64_t c4 = INT64_C (0x7fffffffffffffff); +int_least64_t c4max = INT_LEAST64_MAX; +int_least64_t c4min = INT_LEAST64_MIN; +uint_least8_t d1 = UINT8_C (0xff); +uint_least8_t d1max = UINT_LEAST8_MAX; +uint_least16_t d2 = UINT16_C (0xffff); +uint_least16_t d2max = UINT_LEAST16_MAX; +uint_least32_t d3 = UINT32_C (0xffffffff); +uint_least32_t d3max = UINT_LEAST32_MAX; +uint_least64_t d4 = UINT64_C (0xffffffffffffffff); +uint_least64_t d4max = UINT_LEAST64_MAX; +int_fast8_t e1 = INT_FAST8_MAX; +int_fast8_t e1min = INT_FAST8_MIN; +int_fast16_t e2 = INT_FAST16_MAX; +int_fast16_t e2min = INT_FAST16_MIN; +int_fast32_t e3 = INT_FAST32_MAX; +int_fast32_t e3min = INT_FAST32_MIN; +int_fast64_t e4 = INT_FAST64_MAX; +int_fast64_t e4min = INT_FAST64_MIN; +uint_fast8_t f1 = UINT_FAST8_MAX; +uint_fast16_t f2 = UINT_FAST16_MAX; +uint_fast32_t f3 = UINT_FAST32_MAX; +uint_fast64_t f4 = UINT_FAST64_MAX; +#ifdef INTPTR_MAX +intptr_t g = INTPTR_MAX; +intptr_t gmin = INTPTR_MIN; +#endif +#ifdef UINTPTR_MAX +uintptr_t h = UINTPTR_MAX; +#endif +intmax_t i = INTMAX_MAX; +uintmax_t j = UINTMAX_MAX; + +#include /* for CHAR_BIT */ +#define TYPE_MINIMUM(t) \ + ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t))) +#define TYPE_MAXIMUM(t) \ + ((t) ((t) 0 < (t) -1 \ + ? (t) -1 \ + : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) +struct s { + int check_PTRDIFF: + PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t) + && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t) + ? 1 : -1; + /* Detect bug in FreeBSD 6.0 / ia64. */ + int check_SIG_ATOMIC: + SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t) + && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t) + ? 1 : -1; + int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1; + int check_WCHAR: + WCHAR_MIN == TYPE_MINIMUM (wchar_t) + && WCHAR_MAX == TYPE_MAXIMUM (wchar_t) + ? 1 : -1; + /* Detect bug in mingw. */ + int check_WINT: + WINT_MIN == TYPE_MINIMUM (wint_t) + && WINT_MAX == TYPE_MAXIMUM (wint_t) + ? 1 : -1; + + /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ + int check_UINT8_C: + (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; + int check_UINT16_C: + (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; + + /* Detect bugs in OpenBSD 3.9 stdint.h. */ +#ifdef UINT8_MAX + int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; +#endif +#ifdef UINT16_MAX + int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; +#endif +#ifdef UINT32_MAX + int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; +#endif +#ifdef UINT64_MAX + int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; +#endif + int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; + int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; + int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; + int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; + int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; + int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; + int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; + int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; + int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; + int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; + int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; +}; + ]])], + [dnl Determine whether the various *_MIN, *_MAX macros are usable + dnl in preprocessor expression. We could do it by compiling a test + dnl program for each of these macros. It is faster to run a program + dnl that inspects the macro expansion. + dnl This detects a bug on HP-UX 11.23/ia64. + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ +#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ +#include +] +gl_STDINT_INCLUDES +[ +#include +#include +#define MVAL(macro) MVAL1(macro) +#define MVAL1(expression) #expression +static const char *macro_values[] = + { +#ifdef INT8_MAX + MVAL (INT8_MAX), +#endif +#ifdef INT16_MAX + MVAL (INT16_MAX), +#endif +#ifdef INT32_MAX + MVAL (INT32_MAX), +#endif +#ifdef INT64_MAX + MVAL (INT64_MAX), +#endif +#ifdef UINT8_MAX + MVAL (UINT8_MAX), +#endif +#ifdef UINT16_MAX + MVAL (UINT16_MAX), +#endif +#ifdef UINT32_MAX + MVAL (UINT32_MAX), +#endif +#ifdef UINT64_MAX + MVAL (UINT64_MAX), +#endif + NULL + }; +]], [[ + const char **mv; + for (mv = macro_values; *mv != NULL; mv++) + { + const char *value = *mv; + /* Test whether it looks like a cast expression. */ + if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0 + || strncmp (value, "((unsigned short)"/*)*/, 17) == 0 + || strncmp (value, "((unsigned char)"/*)*/, 16) == 0 + || strncmp (value, "((int)"/*)*/, 6) == 0 + || strncmp (value, "((signed short)"/*)*/, 15) == 0 + || strncmp (value, "((signed char)"/*)*/, 14) == 0) + return mv - macro_values + 1; + } + return 0; +]])], + [gl_cv_header_working_stdint_h=yes], + [], + [dnl When cross-compiling, assume it works. + gl_cv_header_working_stdint_h=yes + ]) + ]) + ]) + fi + if test "$gl_cv_header_working_stdint_h" = yes; then + STDINT_H= + else + dnl Check for , and for + dnl (used in Linux libc4 >= 4.6.7 and libc5). + AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) + if test $ac_cv_header_sys_inttypes_h = yes; then + HAVE_SYS_INTTYPES_H=1 + else + HAVE_SYS_INTTYPES_H=0 + fi + AC_SUBST([HAVE_SYS_INTTYPES_H]) + if test $ac_cv_header_sys_bitypes_h = yes; then + HAVE_SYS_BITYPES_H=1 + else + HAVE_SYS_BITYPES_H=0 + fi + AC_SUBST([HAVE_SYS_BITYPES_H]) + + gl_STDINT_TYPE_PROPERTIES + STDINT_H=stdint.h + fi + AC_SUBST([STDINT_H]) + AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"]) +]) + +dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) +dnl Determine the size of each of the given types in bits. +AC_DEFUN([gl_STDINT_BITSIZEOF], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + m4_foreach_w([gltype], [$1], + [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to the number of bits in type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], + [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], + [$2 +#include ], [result=unknown]) + eval gl_cv_bitsizeof_${gltype}=\$result + ]) + eval result=\$gl_cv_bitsizeof_${gltype} + if test $result = unknown; then + dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, + dnl do a syntax check even on unused #if conditions and give an error + dnl on valid C code like this: + dnl #if 0 + dnl # if > 32 + dnl # endif + dnl #endif + result=0 + fi + GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) + eval BITSIZEOF_${GLTYPE}=\$result + done + m4_foreach_w([gltype], [$1], + [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) +dnl Determine the signedness of each of the given types. +dnl Define HAVE_SIGNED_TYPE if type is signed. +AC_DEFUN([gl_CHECK_TYPES_SIGNED], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + m4_foreach_w([gltype], [$1], + [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to 1 if ']gltype[' is a signed integer type.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2[ + int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], + result=yes, result=no) + eval gl_cv_type_${gltype}_signed=\$result + ]) + eval result=\$gl_cv_type_${gltype}_signed + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + if test "$result" = yes; then + AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1]) + eval HAVE_SIGNED_${GLTYPE}=1 + else + eval HAVE_SIGNED_${GLTYPE}=0 + fi + done + m4_foreach_w([gltype], [$1], + [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) +dnl Determine the suffix to use for integer constants of the given types. +dnl Define t_SUFFIX for each such type. +AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + m4_foreach_w([gltype], [$1], + [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], + [Define to l, ll, u, ul, ull, etc., as suitable for + constants of type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for $gltype integer literal suffix], + [gl_cv_type_${gltype}_suffix], + [eval gl_cv_type_${gltype}_suffix=no + eval result=\$gl_cv_type_${gltype}_signed + if test "$result" = yes; then + glsufu= + else + glsufu=u + fi + for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do + case $glsuf in + '') gltype1='int';; + l) gltype1='long int';; + ll) gltype1='long long int';; + i64) gltype1='__int64';; + u) gltype1='unsigned int';; + ul) gltype1='unsigned long int';; + ull) gltype1='unsigned long long int';; + ui64)gltype1='unsigned __int64';; + esac + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2[ + extern $gltype foo; + extern $gltype1 foo;]])], + [eval gl_cv_type_${gltype}_suffix=\$glsuf]) + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" != no && break + done]) + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" = no && result= + eval ${GLTYPE}_SUFFIX=\$result + AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result]) + done + m4_foreach_w([gltype], [$1], + [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) +]) + +dnl gl_STDINT_INCLUDES +AC_DEFUN([gl_STDINT_INCLUDES], +[[ + /* BSD/OS 4.0.1 has a bug: , and must be + included before . */ + #include + #include + #if HAVE_WCHAR_H + # include + # include + # include + #endif +]]) + +dnl gl_STDINT_TYPE_PROPERTIES +dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t +dnl of interest to stdint.in.h. +AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], +[ + AC_REQUIRE([gl_MULTIARCH]) + if test $APPLE_UNIVERSAL_BUILD = 0; then + gl_STDINT_BITSIZEOF([ptrdiff_t size_t], + [gl_STDINT_INCLUDES]) + fi + gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_cv_type_ptrdiff_t_signed=yes + gl_cv_type_size_t_signed=no + if test $APPLE_UNIVERSAL_BUILD = 0; then + gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t], + [gl_STDINT_INCLUDES]) + fi + gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + + dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99 + dnl requirement that wint_t is "unchanged by default argument promotions". + dnl In this case gnulib's and override wint_t. + dnl Set the variable BITSIZEOF_WINT_T accordingly. + if test $BITSIZEOF_WINT_T -lt 32; then + BITSIZEOF_WINT_T=32 + fi +]) + +dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. +dnl Remove this when we can assume autoconf >= 2.61. +m4_ifdef([AC_COMPUTE_INT], [], [ + AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) +]) + +# Hey Emacs! +# Local Variables: +# indent-tabs-mode: nil +# End: diff --git a/m4/stdint_h.m4 b/m4/stdint_h.m4 new file mode 100644 index 000000000..511ab4e9c --- /dev/null +++ b/m4/stdint_h.m4 @@ -0,0 +1,27 @@ +# stdint_h.m4 serial 9 +dnl Copyright (C) 1997-2004, 2006, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +# Define HAVE_STDINT_H_WITH_UINTMAX if exists, +# doesn't clash with , and declares uintmax_t. + +AC_DEFUN([gl_AC_HEADER_STDINT_H], +[ + AC_CACHE_CHECK([for stdint.h], [gl_cv_header_stdint_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include ]], + [[uintmax_t i = (uintmax_t) -1; return !i;]])], + [gl_cv_header_stdint_h=yes], + [gl_cv_header_stdint_h=no])]) + if test $gl_cv_header_stdint_h = yes; then + AC_DEFINE_UNQUOTED([HAVE_STDINT_H_WITH_UINTMAX], [1], + [Define if exists, doesn't clash with , + and declares uintmax_t. ]) + fi +]) diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 new file mode 100644 index 000000000..ebade067d --- /dev/null +++ b/m4/stdio_h.m4 @@ -0,0 +1,194 @@ +# stdio_h.m4 serial 43 +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STDIO_H], +[ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + gl_NEXT_HEADERS([stdio.h]) + + dnl No need to create extra modules for these functions. Everyone who uses + dnl likely needs them. + GNULIB_FSCANF=1 + gl_MODULE_INDICATOR([fscanf]) + GNULIB_SCANF=1 + gl_MODULE_INDICATOR([scanf]) + GNULIB_FGETC=1 + GNULIB_GETC=1 + GNULIB_GETCHAR=1 + GNULIB_FGETS=1 + GNULIB_FREAD=1 + dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c" + dnl "expected source file, required through AC_LIBSOURCES, not found". It is + dnl also an optimization, to avoid performing a configure check whose result + dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING + dnl or GNULIB_NONBLOCKING redundant. + m4_ifdef([gl_NONBLOCKING_IO], [ + gl_NONBLOCKING_IO + if test $gl_cv_have_nonblocking != yes; then + REPLACE_STDIO_READ_FUNCS=1 + AC_LIBOBJ([stdio-read]) + fi + ]) + + dnl No need to create extra modules for these functions. Everyone who uses + dnl likely needs them. + GNULIB_FPRINTF=1 + GNULIB_PRINTF=1 + GNULIB_VFPRINTF=1 + GNULIB_VPRINTF=1 + GNULIB_FPUTC=1 + GNULIB_PUTC=1 + GNULIB_PUTCHAR=1 + GNULIB_FPUTS=1 + GNULIB_PUTS=1 + GNULIB_FWRITE=1 + dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c" + dnl "expected source file, required through AC_LIBSOURCES, not found". It is + dnl also an optimization, to avoid performing a configure check whose result + dnl is not used. But it does not make the test of GNULIB_STDIO_H_SIGPIPE or + dnl GNULIB_SIGPIPE redundant. + m4_ifdef([gl_SIGNAL_SIGPIPE], [ + gl_SIGNAL_SIGPIPE + if test $gl_cv_header_signal_h_SIGPIPE != yes; then + REPLACE_STDIO_WRITE_FUNCS=1 + AC_LIBOBJ([stdio-write]) + fi + ]) + dnl This ifdef is necessary to avoid an error "missing file lib/stdio-write.c" + dnl "expected source file, required through AC_LIBSOURCES, not found". It is + dnl also an optimization, to avoid performing a configure check whose result + dnl is not used. But it does not make the test of GNULIB_STDIO_H_NONBLOCKING + dnl or GNULIB_NONBLOCKING redundant. + m4_ifdef([gl_NONBLOCKING_IO], [ + gl_NONBLOCKING_IO + if test $gl_cv_have_nonblocking != yes; then + REPLACE_STDIO_WRITE_FUNCS=1 + AC_LIBOBJ([stdio-write]) + fi + ]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, and which is not + dnl guaranteed by both C89 and C11. + gl_WARN_ON_USE_PREPARE([[#include + ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen + renameat snprintf tmpfile vdprintf vsnprintf]) +]) + +AC_DEFUN([gl_STDIO_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_STDIO_H_DEFAULTS], +[ + GNULIB_DPRINTF=0; AC_SUBST([GNULIB_DPRINTF]) + GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE]) + GNULIB_FDOPEN=0; AC_SUBST([GNULIB_FDOPEN]) + GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH]) + GNULIB_FGETC=0; AC_SUBST([GNULIB_FGETC]) + GNULIB_FGETS=0; AC_SUBST([GNULIB_FGETS]) + GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN]) + GNULIB_FPRINTF=0; AC_SUBST([GNULIB_FPRINTF]) + GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX]) + GNULIB_FPURGE=0; AC_SUBST([GNULIB_FPURGE]) + GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC]) + GNULIB_FPUTS=0; AC_SUBST([GNULIB_FPUTS]) + GNULIB_FREAD=0; AC_SUBST([GNULIB_FREAD]) + GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN]) + GNULIB_FSCANF=0; AC_SUBST([GNULIB_FSCANF]) + GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK]) + GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO]) + GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL]) + GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO]) + GNULIB_FWRITE=0; AC_SUBST([GNULIB_FWRITE]) + GNULIB_GETC=0; AC_SUBST([GNULIB_GETC]) + GNULIB_GETCHAR=0; AC_SUBST([GNULIB_GETCHAR]) + GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) + GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) + GNULIB_OBSTACK_PRINTF=0; AC_SUBST([GNULIB_OBSTACK_PRINTF]) + GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX]) + GNULIB_PCLOSE=0; AC_SUBST([GNULIB_PCLOSE]) + GNULIB_PERROR=0; AC_SUBST([GNULIB_PERROR]) + GNULIB_POPEN=0; AC_SUBST([GNULIB_POPEN]) + GNULIB_PRINTF=0; AC_SUBST([GNULIB_PRINTF]) + GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX]) + GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC]) + GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR]) + GNULIB_PUTS=0; AC_SUBST([GNULIB_PUTS]) + GNULIB_REMOVE=0; AC_SUBST([GNULIB_REMOVE]) + GNULIB_RENAME=0; AC_SUBST([GNULIB_RENAME]) + GNULIB_RENAMEAT=0; AC_SUBST([GNULIB_RENAMEAT]) + GNULIB_SCANF=0; AC_SUBST([GNULIB_SCANF]) + GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF]) + GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX]) + GNULIB_STDIO_H_NONBLOCKING=0; AC_SUBST([GNULIB_STDIO_H_NONBLOCKING]) + GNULIB_STDIO_H_SIGPIPE=0; AC_SUBST([GNULIB_STDIO_H_SIGPIPE]) + GNULIB_TMPFILE=0; AC_SUBST([GNULIB_TMPFILE]) + GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF]) + GNULIB_VFSCANF=0; AC_SUBST([GNULIB_VFSCANF]) + GNULIB_VSCANF=0; AC_SUBST([GNULIB_VSCANF]) + GNULIB_VDPRINTF=0; AC_SUBST([GNULIB_VDPRINTF]) + GNULIB_VFPRINTF=0; AC_SUBST([GNULIB_VFPRINTF]) + GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX]) + GNULIB_VPRINTF=0; AC_SUBST([GNULIB_VPRINTF]) + GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX]) + GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF]) + GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE]) + HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO]) + HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO]) + HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM]) + HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE]) + HAVE_DECL_OBSTACK_PRINTF=1; AC_SUBST([HAVE_DECL_OBSTACK_PRINTF]) + HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF]) + HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF]) + HAVE_DPRINTF=1; AC_SUBST([HAVE_DPRINTF]) + HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO]) + HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO]) + HAVE_PCLOSE=1; AC_SUBST([HAVE_PCLOSE]) + HAVE_POPEN=1; AC_SUBST([HAVE_POPEN]) + HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT]) + HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF]) + HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF]) + REPLACE_DPRINTF=0; AC_SUBST([REPLACE_DPRINTF]) + REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE]) + REPLACE_FDOPEN=0; AC_SUBST([REPLACE_FDOPEN]) + REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) + REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN]) + REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) + REPLACE_FPURGE=0; AC_SUBST([REPLACE_FPURGE]) + REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN]) + REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK]) + REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO]) + REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) + REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO]) + REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM]) + REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) + REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF]) + REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR]) + REPLACE_POPEN=0; AC_SUBST([REPLACE_POPEN]) + REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF]) + REPLACE_REMOVE=0; AC_SUBST([REPLACE_REMOVE]) + REPLACE_RENAME=0; AC_SUBST([REPLACE_RENAME]) + REPLACE_RENAMEAT=0; AC_SUBST([REPLACE_RENAMEAT]) + REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF]) + REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF]) + REPLACE_STDIO_READ_FUNCS=0; AC_SUBST([REPLACE_STDIO_READ_FUNCS]) + REPLACE_STDIO_WRITE_FUNCS=0; AC_SUBST([REPLACE_STDIO_WRITE_FUNCS]) + REPLACE_TMPFILE=0; AC_SUBST([REPLACE_TMPFILE]) + REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF]) + REPLACE_VDPRINTF=0; AC_SUBST([REPLACE_VDPRINTF]) + REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) + REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF]) + REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF]) + REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF]) +]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 new file mode 100644 index 000000000..2027ab3c1 --- /dev/null +++ b/m4/stdlib_h.m4 @@ -0,0 +1,117 @@ +# stdlib_h.m4 serial 42 +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STDLIB_H], +[ + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + gl_NEXT_HEADERS([stdlib.h]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, and which is not + dnl guaranteed by C89. + gl_WARN_ON_USE_PREPARE([[#include +#if HAVE_SYS_LOADAVG_H +# include +#endif +#if HAVE_RANDOM_H +# include +#endif + ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt + initstate initstate_r mkdtemp mkostemp mkostemps mkstemp mkstemps + posix_openpt ptsname ptsname_r random random_r realpath rpmatch + secure_getenv setenv setstate setstate_r srandom srandom_r + strtod strtoll strtoull unlockpt unsetenv]) +]) + +AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_STDLIB_H_DEFAULTS], +[ + GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT]) + GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL]) + GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX]) + GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME]) + GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG]) + GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) + GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT]) + GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX]) + GNULIB_MBTOWC=0; AC_SUBST([GNULIB_MBTOWC]) + GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) + GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP]) + GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS]) + GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) + GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS]) + GNULIB_POSIX_OPENPT=0; AC_SUBST([GNULIB_POSIX_OPENPT]) + GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME]) + GNULIB_PTSNAME_R=0; AC_SUBST([GNULIB_PTSNAME_R]) + GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) + GNULIB_RANDOM=0; AC_SUBST([GNULIB_RANDOM]) + GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R]) + GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX]) + GNULIB_REALPATH=0; AC_SUBST([GNULIB_REALPATH]) + GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH]) + GNULIB_SECURE_GETENV=0; AC_SUBST([GNULIB_SECURE_GETENV]) + GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV]) + GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD]) + GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL]) + GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL]) + GNULIB_SYSTEM_POSIX=0; AC_SUBST([GNULIB_SYSTEM_POSIX]) + GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT]) + GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) + GNULIB_WCTOMB=0; AC_SUBST([GNULIB_WCTOMB]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE__EXIT=1; AC_SUBST([HAVE__EXIT]) + HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) + HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) + HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) + HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) + HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) + HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) + HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) + HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) + HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP]) + HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) + HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT]) + HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) + HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R]) + HAVE_RANDOM=1; AC_SUBST([HAVE_RANDOM]) + HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H]) + HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) + HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH]) + HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH]) + HAVE_SECURE_GETENV=1; AC_SUBST([HAVE_SECURE_GETENV]) + HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) + HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV]) + HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD]) + HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL]) + HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL]) + HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA]) + HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) + HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) + HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV]) + REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC]) + REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) + REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) + REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) + REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) + REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME]) + REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R]) + REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) + REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R]) + REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC]) + REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH]) + REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV]) + REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) + REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV]) + REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB]) +]) diff --git a/m4/strcase.m4 b/m4/strcase.m4 new file mode 100644 index 000000000..22bf57c95 --- /dev/null +++ b/m4/strcase.m4 @@ -0,0 +1,45 @@ +# strcase.m4 serial 11 +dnl Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STRCASE], +[ + gl_FUNC_STRCASECMP + gl_FUNC_STRNCASECMP +]) + +AC_DEFUN([gl_FUNC_STRCASECMP], +[ + AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) + AC_CHECK_FUNCS([strcasecmp]) + if test $ac_cv_func_strcasecmp = no; then + HAVE_STRCASECMP=0 + fi +]) + +AC_DEFUN([gl_FUNC_STRNCASECMP], +[ + AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) + AC_CHECK_FUNCS([strncasecmp]) + if test $ac_cv_func_strncasecmp = yes; then + HAVE_STRNCASECMP=1 + else + HAVE_STRNCASECMP=0 + fi + AC_CHECK_DECLS([strncasecmp]) + if test $ac_cv_have_decl_strncasecmp = no; then + HAVE_DECL_STRNCASECMP=0 + fi +]) + +# Prerequisites of lib/strcasecmp.c. +AC_DEFUN([gl_PREREQ_STRCASECMP], [ + : +]) + +# Prerequisites of lib/strncasecmp.c. +AC_DEFUN([gl_PREREQ_STRNCASECMP], [ + : +]) diff --git a/m4/strchrnul.m4 b/m4/strchrnul.m4 new file mode 100644 index 000000000..b59eda9d7 --- /dev/null +++ b/m4/strchrnul.m4 @@ -0,0 +1,50 @@ +# strchrnul.m4 serial 9 +dnl Copyright (C) 2003, 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRCHRNUL], +[ + dnl Persuade glibc to declare strchrnul(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([strchrnul]) + if test $ac_cv_func_strchrnul = no; then + HAVE_STRCHRNUL=0 + else + AC_CACHE_CHECK([whether strchrnul works], + [gl_cv_func_strchrnul_works], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include /* for strchrnul */ +]], [[const char *buf = "a"; + return strchrnul (buf, 'b') != buf + 1; + ]])], + [gl_cv_func_strchrnul_works=yes], + [gl_cv_func_strchrnul_works=no], + [dnl Cygwin 1.7.9 introduced strchrnul, but it was broken until 1.7.10 + AC_EGREP_CPP([Lucky user], + [ +#if defined __CYGWIN__ + #include + #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 9) + Lucky user + #endif +#else + Lucky user +#endif + ], + [gl_cv_func_strchrnul_works="guessing yes"], + [gl_cv_func_strchrnul_works="guessing no"]) + ]) + ]) + case "$gl_cv_func_strchrnul_works" in + *yes) ;; + *) REPLACE_STRCHRNUL=1 ;; + esac + fi +]) + +# Prerequisites of lib/strchrnul.c. +AC_DEFUN([gl_PREREQ_STRCHRNUL], [:]) diff --git a/m4/strerror.m4 b/m4/strerror.m4 new file mode 100644 index 000000000..3989844b2 --- /dev/null +++ b/m4/strerror.m4 @@ -0,0 +1,96 @@ +# strerror.m4 serial 17 +dnl Copyright (C) 2002, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRERROR], +[ + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_REQUIRE([gl_HEADER_ERRNO_H]) + AC_REQUIRE([gl_FUNC_STRERROR_0]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [ + AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS]) + ]) + if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then + AC_CACHE_CHECK([for working strerror function], + [gl_cv_func_working_strerror], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[if (!*strerror (-2)) return 1;]])], + [gl_cv_func_working_strerror=yes], + [gl_cv_func_working_strerror=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_working_strerror="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_working_strerror="guessing no" ;; + esac + ]) + ]) + case "$gl_cv_func_working_strerror" in + *yes) ;; + *) + dnl The system's strerror() fails to return a string for out-of-range + dnl integers. Replace it. + REPLACE_STRERROR=1 + ;; + esac + m4_ifdef([gl_FUNC_STRERROR_R_WORKS], [ + dnl If the system's strerror_r or __xpg_strerror_r clobbers strerror's + dnl buffer, we must replace strerror. + case "$gl_cv_func_strerror_r_works" in + *no) REPLACE_STRERROR=1 ;; + esac + ]) + else + dnl The system's strerror() cannot know about the new errno values we add + dnl to , or any fix for strerror(0). Replace it. + REPLACE_STRERROR=1 + fi +]) + +dnl Detect if strerror(0) passes (that is, does not set errno, and does not +dnl return a string that matches strerror(-1)). +AC_DEFUN([gl_FUNC_STRERROR_0], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + REPLACE_STRERROR_0=0 + AC_CACHE_CHECK([whether strerror(0) succeeds], + [gl_cv_func_strerror_0_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + ]], + [[int result = 0; + char *str; + errno = 0; + str = strerror (0); + if (!*str) result |= 1; + if (errno) result |= 2; + if (strstr (str, "nknown") || strstr (str, "ndefined")) + result |= 4; + return result;]])], + [gl_cv_func_strerror_0_works=yes], + [gl_cv_func_strerror_0_works=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_strerror_0_works="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_strerror_0_works="guessing no" ;; + esac + ]) + ]) + case "$gl_cv_func_strerror_0_works" in + *yes) ;; + *) + REPLACE_STRERROR_0=1 + AC_DEFINE([REPLACE_STRERROR_0], [1], [Define to 1 if strerror(0) + does not return a message implying success.]) + ;; + esac +]) diff --git a/m4/string_h.m4 b/m4/string_h.m4 new file mode 100644 index 000000000..cc5fbbb32 --- /dev/null +++ b/m4/string_h.m4 @@ -0,0 +1,120 @@ +# Configure a GNU-like replacement for . + +# Copyright (C) 2007-2013 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 21 + +# Written by Paul Eggert. + +AC_DEFUN([gl_HEADER_STRING_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_HEADER_STRING_H_BODY]) +]) + +AC_DEFUN([gl_HEADER_STRING_H_BODY], +[ + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + gl_NEXT_HEADERS([string.h]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, and which is not + dnl guaranteed by C89. + gl_WARN_ON_USE_PREPARE([[#include + ]], + [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul + strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r + strerror_r strsignal strverscmp]) +]) + +AC_DEFUN([gl_STRING_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], +[ + GNULIB_FFSL=0; AC_SUBST([GNULIB_FFSL]) + GNULIB_FFSLL=0; AC_SUBST([GNULIB_FFSLL]) + GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR]) + GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) + GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) + GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) + GNULIB_RAWMEMCHR=0; AC_SUBST([GNULIB_RAWMEMCHR]) + GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) + GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) + GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) + GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) + GNULIB_STRNCAT=0; AC_SUBST([GNULIB_STRNCAT]) + GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) + GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) + GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) + GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) + GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) + GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) + GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) + GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN]) + GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN]) + GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR]) + GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR]) + GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) + GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP]) + GNULIB_MBSNCASECMP=0; AC_SUBST([GNULIB_MBSNCASECMP]) + GNULIB_MBSPCASECMP=0; AC_SUBST([GNULIB_MBSPCASECMP]) + GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR]) + GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN]) + GNULIB_MBSPBRK=0; AC_SUBST([GNULIB_MBSPBRK]) + GNULIB_MBSSPN=0; AC_SUBST([GNULIB_MBSSPN]) + GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP]) + GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) + GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) + GNULIB_STRERROR_R=0; AC_SUBST([GNULIB_STRERROR_R]) + GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) + GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) + HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_FFSL=1; AC_SUBST([HAVE_FFSL]) + HAVE_FFSLL=1; AC_SUBST([HAVE_FFSLL]) + HAVE_MEMCHR=1; AC_SUBST([HAVE_MEMCHR]) + HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) + HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) + HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) + HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR]) + HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) + HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) + HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) + HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) + HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) + HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) + HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) + HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) + HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) + HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) + HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R]) + HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) + HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) + REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) + REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) + REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY]) + REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) + REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) + REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) + REPLACE_STRCHRNUL=0; AC_SUBST([REPLACE_STRCHRNUL]) + REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) + REPLACE_STRERROR_R=0; AC_SUBST([REPLACE_STRERROR_R]) + REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) + REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) + REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN]) + REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) + REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) + UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) +]) diff --git a/m4/strings_h.m4 b/m4/strings_h.m4 new file mode 100644 index 000000000..76ef2424e --- /dev/null +++ b/m4/strings_h.m4 @@ -0,0 +1,52 @@ +# Configure a replacement for . +# serial 6 + +# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_HEADER_STRINGS_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_HEADER_STRINGS_H_BODY]) +]) + +AC_DEFUN([gl_HEADER_STRINGS_H_BODY], +[ + AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) + + gl_CHECK_NEXT_HEADERS([strings.h]) + if test $ac_cv_header_strings_h = yes; then + HAVE_STRINGS_H=1 + else + HAVE_STRINGS_H=0 + fi + AC_SUBST([HAVE_STRINGS_H]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ + /* Minix 3.1.8 has a bug: must be included before + . */ + #include + #include + ]], [ffs strcasecmp strncasecmp]) +]) + +AC_DEFUN([gl_STRINGS_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) +]) + +AC_DEFUN([gl_HEADER_STRINGS_H_DEFAULTS], +[ + GNULIB_FFS=0; AC_SUBST([GNULIB_FFS]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_FFS=1; AC_SUBST([HAVE_FFS]) + HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP]) + HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP]) +]) diff --git a/m4/strndup.m4 b/m4/strndup.m4 new file mode 100644 index 000000000..a1f82743f --- /dev/null +++ b/m4/strndup.m4 @@ -0,0 +1,55 @@ +# strndup.m4 serial 21 +dnl Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRNDUP], +[ + dnl Persuade glibc to declare strndup(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_DECLS_ONCE([strndup]) + AC_CHECK_FUNCS_ONCE([strndup]) + if test $ac_cv_have_decl_strndup = no; then + HAVE_DECL_STRNDUP=0 + fi + + if test $ac_cv_func_strndup = yes; then + HAVE_STRNDUP=1 + # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. + AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works], + [AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[#include + #include ]], [[ +#if !HAVE_DECL_STRNDUP + extern + #ifdef __cplusplus + "C" + #endif + char *strndup (const char *, size_t); +#endif + char *s; + s = strndup ("some longer string", 15); + free (s); + s = strndup ("shorter string", 13); + return s[13] != '\0';]])], + [gl_cv_func_strndup_works=yes], + [gl_cv_func_strndup_works=no], + [ +changequote(,)dnl + case $host_os in + aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";; + *) gl_cv_func_strndup_works="guessing yes";; + esac +changequote([,])dnl + ])]) + case $gl_cv_func_strndup_works in + *no) REPLACE_STRNDUP=1 ;; + esac + else + HAVE_STRNDUP=0 + fi +]) diff --git a/m4/strnlen.m4 b/m4/strnlen.m4 new file mode 100644 index 000000000..eae82b772 --- /dev/null +++ b/m4/strnlen.m4 @@ -0,0 +1,30 @@ +# strnlen.m4 serial 13 +dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, +dnl Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRNLEN], +[ + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + + dnl Persuade glibc to declare strnlen(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS_ONCE([strnlen]) + if test $ac_cv_have_decl_strnlen = no; then + HAVE_DECL_STRNLEN=0 + else + m4_pushdef([AC_LIBOBJ], [:]) + dnl Note: AC_FUNC_STRNLEN does AC_LIBOBJ([strnlen]). + AC_FUNC_STRNLEN + m4_popdef([AC_LIBOBJ]) + if test $ac_cv_func_strnlen_working = no; then + REPLACE_STRNLEN=1 + fi + fi +]) + +# Prerequisites of lib/strnlen.c. +AC_DEFUN([gl_PREREQ_STRNLEN], [:]) diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4 new file mode 100644 index 000000000..94863776d --- /dev/null +++ b/m4/sys_socket_h.m4 @@ -0,0 +1,176 @@ +# sys_socket_h.m4 serial 23 +dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson. + +AC_DEFUN([gl_HEADER_SYS_SOCKET], +[ + AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + + dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have + dnl old-style declarations (with return type 'int' instead of 'ssize_t') + dnl unless _POSIX_PII_SOCKET is defined. + case "$host_os" in + osf*) + AC_DEFINE([_POSIX_PII_SOCKET], [1], + [Define to 1 in order to get the POSIX compatible declarations + of socket functions.]) + ;; + esac + + AC_CACHE_CHECK([whether is self-contained], + [gl_cv_header_sys_socket_h_selfcontained], + [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[]])], + [gl_cv_header_sys_socket_h_selfcontained=yes], + [gl_cv_header_sys_socket_h_selfcontained=no]) + ]) + if test $gl_cv_header_sys_socket_h_selfcontained = yes; then + dnl If the shutdown function exists, should define + dnl SHUT_RD, SHUT_WR, SHUT_RDWR. + AC_CHECK_FUNCS([shutdown]) + if test $ac_cv_func_shutdown = yes; then + AC_CACHE_CHECK([whether defines the SHUT_* macros], + [gl_cv_header_sys_socket_h_shut], + [ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])], + [gl_cv_header_sys_socket_h_shut=yes], + [gl_cv_header_sys_socket_h_shut=no]) + ]) + if test $gl_cv_header_sys_socket_h_shut = no; then + SYS_SOCKET_H='sys/socket.h' + fi + fi + fi + # We need to check for ws2tcpip.h now. + gl_PREREQ_SYS_H_SOCKET + AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[ + /* sys/types.h is not needed according to POSIX, but the + sys/socket.h in i386-unknown-freebsd4.10 and + powerpc-apple-darwin5.5 required it. */ +#include +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +]) + if test $ac_cv_type_struct_sockaddr_storage = no; then + HAVE_STRUCT_SOCKADDR_STORAGE=0 + fi + if test $ac_cv_type_sa_family_t = no; then + HAVE_SA_FAMILY_T=0 + fi + if test $ac_cv_type_struct_sockaddr_storage != no; then + AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family], + [], + [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0], + [#include + #ifdef HAVE_SYS_SOCKET_H + #include + #endif + #ifdef HAVE_WS2TCPIP_H + #include + #endif + ]) + fi + if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \ + || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then + SYS_SOCKET_H='sys/socket.h' + fi + gl_PREREQ_SYS_H_WINSOCK2 + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +/* Some systems require prerequisite headers. */ +#include +#include + ]], [socket connect accept bind getpeername getsockname getsockopt + listen recv send recvfrom sendto setsockopt shutdown accept4]) +]) + +AC_DEFUN([gl_PREREQ_SYS_H_SOCKET], +[ + dnl Check prerequisites of the replacement. + AC_REQUIRE([gl_CHECK_SOCKET_HEADERS]) + gl_CHECK_NEXT_HEADERS([sys/socket.h]) + if test $ac_cv_header_sys_socket_h = yes; then + HAVE_SYS_SOCKET_H=1 + HAVE_WS2TCPIP_H=0 + else + HAVE_SYS_SOCKET_H=0 + if test $ac_cv_header_ws2tcpip_h = yes; then + HAVE_WS2TCPIP_H=1 + else + HAVE_WS2TCPIP_H=0 + fi + fi + AC_SUBST([HAVE_SYS_SOCKET_H]) + AC_SUBST([HAVE_WS2TCPIP_H]) +]) + +# Common prerequisites of the replacement and of the +# replacement. +# Sets and substitutes HAVE_WINSOCK2_H. +AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2], +[ + m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])]) + m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])]) + AC_CHECK_HEADERS_ONCE([sys/socket.h]) + if test $ac_cv_header_sys_socket_h != yes; then + dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make + dnl the check for those headers unconditional; yet cygwin reports + dnl that the headers are present but cannot be compiled (since on + dnl cygwin, all socket information should come from sys/socket.h). + AC_CHECK_HEADERS([winsock2.h]) + fi + if test "$ac_cv_header_winsock2_h" = yes; then + HAVE_WINSOCK2_H=1 + UNISTD_H_HAVE_WINSOCK2_H=1 + SYS_IOCTL_H_HAVE_WINSOCK2_H=1 + else + HAVE_WINSOCK2_H=0 + fi + AC_SUBST([HAVE_WINSOCK2_H]) +]) + +AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS], +[ + GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET]) + GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT]) + GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT]) + GNULIB_BIND=0; AC_SUBST([GNULIB_BIND]) + GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME]) + GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME]) + GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT]) + GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN]) + GNULIB_RECV=0; AC_SUBST([GNULIB_RECV]) + GNULIB_SEND=0; AC_SUBST([GNULIB_SEND]) + GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM]) + GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO]) + GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT]) + GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN]) + GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4]) + HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE]) + HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1; + AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY]) + HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T]) + HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4]) +]) diff --git a/m4/sys_types_h.m4 b/m4/sys_types_h.m4 new file mode 100644 index 000000000..d15c1b370 --- /dev/null +++ b/m4/sys_types_h.m4 @@ -0,0 +1,24 @@ +# sys_types_h.m4 serial 5 +dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN_ONCE([gl_SYS_TYPES_H], +[ + AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS]) + gl_NEXT_HEADERS([sys/types.h]) + + dnl Ensure the type pid_t gets defined. + AC_REQUIRE([AC_TYPE_PID_T]) + + dnl Ensure the type mode_t gets defined. + AC_REQUIRE([AC_TYPE_MODE_T]) + + dnl Whether to override the 'off_t' type. + AC_REQUIRE([gl_TYPE_OFF_T]) +]) + +AC_DEFUN([gl_SYS_TYPES_H_DEFAULTS], +[ +]) diff --git a/m4/sysexits.m4 b/m4/sysexits.m4 new file mode 100644 index 000000000..bd8abaa0d --- /dev/null +++ b/m4/sysexits.m4 @@ -0,0 +1,44 @@ +# sysexits.m4 serial 6 +dnl Copyright (C) 2003, 2005, 2007, 2009-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_SYSEXITS], +[ + AC_CHECK_HEADERS_ONCE([sysexits.h]) + if test $ac_cv_header_sysexits_h = yes; then + HAVE_SYSEXITS_H=1 + gl_CHECK_NEXT_HEADERS([sysexits.h]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[switch (0) + { + case EX_OK: + case EX_USAGE: + case EX_DATAERR: + case EX_NOINPUT: + case EX_NOUSER: + case EX_NOHOST: + case EX_UNAVAILABLE: + case EX_SOFTWARE: + case EX_OSERR: + case EX_OSFILE: + case EX_CANTCREAT: + case EX_IOERR: + case EX_TEMPFAIL: + case EX_PROTOCOL: + case EX_NOPERM: + case EX_CONFIG: + break; + } + ]])], + [SYSEXITS_H=], + [SYSEXITS_H=sysexits.h]) + else + HAVE_SYSEXITS_H=0 + SYSEXITS_H=sysexits.h + fi + AC_SUBST([HAVE_SYSEXITS_H]) + AC_SUBST([SYSEXITS_H]) + AM_CONDITIONAL([GL_GENERATE_SYSEXITS_H], [test -n "$SYSEXITS_H"]) +]) diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 new file mode 100644 index 000000000..26bdeb58a --- /dev/null +++ b/m4/threadlib.m4 @@ -0,0 +1,371 @@ +# threadlib.m4 serial 10 (gettext-0.18.2) +dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl gl_THREADLIB +dnl ------------ +dnl Tests for a multithreading library to be used. +dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO +dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the +dnl default is 'no', otherwise it is system dependent. In both cases, the user +dnl can change the choice through the options --enable-threads=choice or +dnl --disable-threads. +dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, +dnl USE_PTH_THREADS, USE_WINDOWS_THREADS +dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use +dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with +dnl libtool). +dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for +dnl programs that really need multithread functionality. The difference +dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak +dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". +dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for +dnl multithread-safe programs. + +AC_DEFUN([gl_THREADLIB_EARLY], +[ + AC_REQUIRE([gl_THREADLIB_EARLY_BODY]) +]) + +dnl The guts of gl_THREADLIB_EARLY. Needs to be expanded only once. + +AC_DEFUN([gl_THREADLIB_EARLY_BODY], +[ + dnl Ordering constraints: This macro modifies CPPFLAGS in a way that + dnl influences the result of the autoconf tests that test for *_unlocked + dnl declarations, on AIX 5 at least. Therefore it must come early. + AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl + AC_BEFORE([$0], [gl_ARGP])dnl + + AC_REQUIRE([AC_CANONICAL_HOST]) + dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. + dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes + dnl AC_GNU_SOURCE. + m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], + [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], + [AC_REQUIRE([AC_GNU_SOURCE])]) + dnl Check for multithreading. + m4_ifdef([gl_THREADLIB_DEFAULT_NO], + [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], + [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) + AC_ARG_ENABLE([threads], +AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ +AC_HELP_STRING([--disable-threads], [build without multithread safety])]), + [gl_use_threads=$enableval], + [if test -n "$gl_use_threads_default"; then + gl_use_threads="$gl_use_threads_default" + else +changequote(,)dnl + case "$host_os" in + dnl Disable multithreading by default on OSF/1, because it interferes + dnl with fork()/exec(): When msgexec is linked with -lpthread, its + dnl child process gets an endless segmentation fault inside execvp(). + dnl Disable multithreading by default on Cygwin 1.5.x, because it has + dnl bugs that lead to endless loops or crashes. See + dnl . + osf*) gl_use_threads=no ;; + cygwin*) + case `uname -r` in + 1.[0-5].*) gl_use_threads=no ;; + *) gl_use_threads=yes ;; + esac + ;; + *) gl_use_threads=yes ;; + esac +changequote([,])dnl + fi + ]) + if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then + # For using : + case "$host_os" in + osf*) + # On OSF/1, the compiler needs the flag -D_REENTRANT so that it + # groks . cc also understands the flag -pthread, but + # we don't use it because 1. gcc-2.95 doesn't understand -pthread, + # 2. putting a flag into CPPFLAGS that has an effect on the linker + # causes the AC_LINK_IFELSE test below to succeed unexpectedly, + # leading to wrong values of LIBTHREAD and LTLIBTHREAD. + CPPFLAGS="$CPPFLAGS -D_REENTRANT" + ;; + esac + # Some systems optimize for single-threaded programs by default, and + # need special flags to disable these optimizations. For example, the + # definition of 'errno' in . + case "$host_os" in + aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; + solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; + esac + fi +]) + +dnl The guts of gl_THREADLIB. Needs to be expanded only once. + +AC_DEFUN([gl_THREADLIB_BODY], +[ + AC_REQUIRE([gl_THREADLIB_EARLY_BODY]) + gl_threads_api=none + LIBTHREAD= + LTLIBTHREAD= + LIBMULTITHREAD= + LTLIBMULTITHREAD= + if test "$gl_use_threads" != no; then + dnl Check whether the compiler and linker support weak declarations. + AC_CACHE_CHECK([whether imported symbols can be declared weak], + [gl_cv_have_weak], + [gl_cv_have_weak=no + dnl First, test whether the compiler accepts it syntactically. + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[extern void xyzzy (); +#pragma weak xyzzy]], + [[xyzzy();]])], + [gl_cv_have_weak=maybe]) + if test $gl_cv_have_weak = maybe; then + dnl Second, test whether it actually works. On Cygwin 1.7.2, with + dnl gcc 4.3, symbols declared weak always evaluate to the address 0. + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#pragma weak fputs +int main () +{ + return (fputs == NULL); +}]])], + [gl_cv_have_weak=yes], + [gl_cv_have_weak=no], + [dnl When cross-compiling, assume that only ELF platforms support + dnl weak symbols. + AC_EGREP_CPP([Extensible Linking Format], + [#ifdef __ELF__ + Extensible Linking Format + #endif + ], + [gl_cv_have_weak="guessing yes"], + [gl_cv_have_weak="guessing no"]) + ]) + fi + ]) + if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then + # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that + # it groks . It's added above, in gl_THREADLIB_EARLY_BODY. + AC_CHECK_HEADER([pthread.h], + [gl_have_pthread_h=yes], [gl_have_pthread_h=no]) + if test "$gl_have_pthread_h" = yes; then + # Other possible tests: + # -lpthreads (FSU threads, PCthreads) + # -lgthreads + gl_have_pthread= + # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist + # in libc. IRIX 6.5 has the first one in both libc and libpthread, but + # the second one only in libpthread, and lock.c needs it. + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[pthread_mutex_lock((pthread_mutex_t*)0); + pthread_mutexattr_init((pthread_mutexattr_t*)0);]])], + [gl_have_pthread=yes]) + # Test for libpthread by looking for pthread_kill. (Not pthread_self, + # since it is defined as a macro on OSF/1.) + if test -n "$gl_have_pthread"; then + # The program links fine without libpthread. But it may actually + # need to link with libpthread in order to create multiple threads. + AC_CHECK_LIB([pthread], [pthread_kill], + [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread + # On Solaris and HP-UX, most pthread functions exist also in libc. + # Therefore pthread_in_use() needs to actually try to create a + # thread: pthread_create from libc will fail, whereas + # pthread_create will actually create a thread. + case "$host_os" in + solaris* | hpux*) + AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], + [Define if the pthread_in_use() detection is hard.]) + esac + ]) + else + # Some library is needed. Try libpthread and libc_r. + AC_CHECK_LIB([pthread], [pthread_kill], + [gl_have_pthread=yes + LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread + LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) + if test -z "$gl_have_pthread"; then + # For FreeBSD 4. + AC_CHECK_LIB([c_r], [pthread_kill], + [gl_have_pthread=yes + LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r + LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r]) + fi + fi + if test -n "$gl_have_pthread"; then + gl_threads_api=posix + AC_DEFINE([USE_POSIX_THREADS], [1], + [Define if the POSIX multithreading library can be used.]) + if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then + if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then + AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], + [Define if references to the POSIX multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + fi + fi + fi + if test -z "$gl_have_pthread"; then + if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then + gl_have_solaristhread= + gl_save_LIBS="$LIBS" + LIBS="$LIBS -lthread" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +#include + ]], + [[thr_self();]])], + [gl_have_solaristhread=yes]) + LIBS="$gl_save_LIBS" + if test -n "$gl_have_solaristhread"; then + gl_threads_api=solaris + LIBTHREAD=-lthread + LTLIBTHREAD=-lthread + LIBMULTITHREAD="$LIBTHREAD" + LTLIBMULTITHREAD="$LTLIBTHREAD" + AC_DEFINE([USE_SOLARIS_THREADS], [1], + [Define if the old Solaris multithreading library can be used.]) + if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then + AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1], + [Define if references to the old Solaris multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + fi + fi + if test "$gl_use_threads" = pth; then + gl_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_LINKFLAGS([pth]) + gl_have_pth= + gl_save_LIBS="$LIBS" + LIBS="$LIBS $LIBPTH" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#include ]], [[pth_self();]])], + [gl_have_pth=yes]) + LIBS="$gl_save_LIBS" + if test -n "$gl_have_pth"; then + gl_threads_api=pth + LIBTHREAD="$LIBPTH" + LTLIBTHREAD="$LTLIBPTH" + LIBMULTITHREAD="$LIBTHREAD" + LTLIBMULTITHREAD="$LTLIBTHREAD" + AC_DEFINE([USE_PTH_THREADS], [1], + [Define if the GNU Pth multithreading library can be used.]) + if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then + if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then + AC_DEFINE([USE_PTH_THREADS_WEAK], [1], + [Define if references to the GNU Pth multithreading library should be made weak.]) + LIBTHREAD= + LTLIBTHREAD= + fi + fi + else + CPPFLAGS="$gl_save_CPPFLAGS" + fi + fi + if test -z "$gl_have_pthread"; then + case "$gl_use_threads" in + yes | windows | win32) # The 'win32' is for backward compatibility. + if { case "$host_os" in + mingw*) true;; + *) false;; + esac + }; then + gl_threads_api=windows + AC_DEFINE([USE_WINDOWS_THREADS], [1], + [Define if the native Windows multithreading API can be used.]) + fi + ;; + esac + fi + fi + AC_MSG_CHECKING([for multithread API to use]) + AC_MSG_RESULT([$gl_threads_api]) + AC_SUBST([LIBTHREAD]) + AC_SUBST([LTLIBTHREAD]) + AC_SUBST([LIBMULTITHREAD]) + AC_SUBST([LTLIBMULTITHREAD]) +]) + +AC_DEFUN([gl_THREADLIB], +[ + AC_REQUIRE([gl_THREADLIB_EARLY]) + AC_REQUIRE([gl_THREADLIB_BODY]) +]) + + +dnl gl_DISABLE_THREADS +dnl ------------------ +dnl Sets the gl_THREADLIB default so that threads are not used by default. +dnl The user can still override it at installation time, by using the +dnl configure option '--enable-threads'. + +AC_DEFUN([gl_DISABLE_THREADS], [ + m4_divert_text([INIT_PREPARE], [gl_use_threads_default=no]) +]) + + +dnl Survey of platforms: +dnl +dnl Platform Available Compiler Supports test-lock +dnl flavours option weak result +dnl --------------- --------- --------- -------- --------- +dnl Linux 2.4/glibc posix -lpthread Y OK +dnl +dnl GNU Hurd/glibc posix +dnl +dnl FreeBSD 5.3 posix -lc_r Y +dnl posix -lkse ? Y +dnl posix -lpthread ? Y +dnl posix -lthr Y +dnl +dnl FreeBSD 5.2 posix -lc_r Y +dnl posix -lkse Y +dnl posix -lthr Y +dnl +dnl FreeBSD 4.0,4.10 posix -lc_r Y OK +dnl +dnl NetBSD 1.6 -- +dnl +dnl OpenBSD 3.4 posix -lpthread Y OK +dnl +dnl Mac OS X 10.[123] posix -lpthread Y OK +dnl +dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK +dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK +dnl +dnl HP-UX 11 posix -lpthread N (cc) OK +dnl Y (gcc) +dnl +dnl IRIX 6.5 posix -lpthread Y 0.5 +dnl +dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK +dnl +dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK +dnl -lpthread (gcc) Y +dnl +dnl Cygwin posix -lpthread Y OK +dnl +dnl Any of the above pth -lpth 0.0 +dnl +dnl Mingw windows N OK +dnl +dnl BeOS 5 -- +dnl +dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is +dnl turned off: +dnl OK if all three tests terminate OK, +dnl 0.5 if the first test terminates OK but the second one loops endlessly, +dnl 0.0 if the first test already loops endlessly. diff --git a/m4/uintmax_t.m4 b/m4/uintmax_t.m4 new file mode 100644 index 000000000..c6ff80067 --- /dev/null +++ b/m4/uintmax_t.m4 @@ -0,0 +1,30 @@ +# uintmax_t.m4 serial 12 +dnl Copyright (C) 1997-2004, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert. + +AC_PREREQ([2.13]) + +# Define uintmax_t to 'unsigned long' or 'unsigned long long' +# if it is not already defined in or . + +AC_DEFUN([gl_AC_TYPE_UINTMAX_T], +[ + AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([gl_AC_HEADER_STDINT_H]) + if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + test $ac_cv_type_unsigned_long_long_int = yes \ + && ac_type='unsigned long long' \ + || ac_type='unsigned long' + AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type], + [Define to unsigned long or unsigned long long + if and don't define.]) + else + AC_DEFINE([HAVE_UINTMAX_T], [1], + [Define if you have the 'uintmax_t' type in or .]) + fi +]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 new file mode 100644 index 000000000..32dcfa582 --- /dev/null +++ b/m4/unistd_h.m4 @@ -0,0 +1,186 @@ +# unistd_h.m4 serial 66 +dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Simon Josefsson, Bruno Haible. + +AC_DEFUN([gl_UNISTD_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + gl_CHECK_NEXT_HEADERS([unistd.h]) + if test $ac_cv_header_unistd_h = yes; then + HAVE_UNISTD_H=1 + else + HAVE_UNISTD_H=0 + fi + AC_SUBST([HAVE_UNISTD_H]) + + dnl Ensure the type pid_t gets defined. + AC_REQUIRE([AC_TYPE_PID_T]) + + dnl Determine WINDOWS_64_BIT_OFF_T. + AC_REQUIRE([gl_TYPE_OFF_T]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#if HAVE_UNISTD_H +# include +#endif +/* Some systems declare various items in the wrong headers. */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +# include +# include +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# include +# endif +#endif + ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat + fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups + gethostname getlogin getlogin_r getpagesize + getusershell setusershell endusershell + group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite + readlink readlinkat rmdir sethostname sleep symlink symlinkat ttyname_r + unlink unlinkat usleep]) +]) + +AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_UNISTD_H_DEFAULTS], +[ + GNULIB_CHDIR=0; AC_SUBST([GNULIB_CHDIR]) + GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) + GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE]) + GNULIB_DUP=0; AC_SUBST([GNULIB_DUP]) + GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) + GNULIB_DUP3=0; AC_SUBST([GNULIB_DUP3]) + GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) + GNULIB_EUIDACCESS=0; AC_SUBST([GNULIB_EUIDACCESS]) + GNULIB_FACCESSAT=0; AC_SUBST([GNULIB_FACCESSAT]) + GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) + GNULIB_FCHOWNAT=0; AC_SUBST([GNULIB_FCHOWNAT]) + GNULIB_FDATASYNC=0; AC_SUBST([GNULIB_FDATASYNC]) + GNULIB_FSYNC=0; AC_SUBST([GNULIB_FSYNC]) + GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) + GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) + GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME]) + GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE]) + GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS]) + GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) + GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN]) + GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) + GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) + GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL]) + GNULIB_GROUP_MEMBER=0; AC_SUBST([GNULIB_GROUP_MEMBER]) + GNULIB_ISATTY=0; AC_SUBST([GNULIB_ISATTY]) + GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN]) + GNULIB_LINK=0; AC_SUBST([GNULIB_LINK]) + GNULIB_LINKAT=0; AC_SUBST([GNULIB_LINKAT]) + GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) + GNULIB_PIPE=0; AC_SUBST([GNULIB_PIPE]) + GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2]) + GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD]) + GNULIB_PWRITE=0; AC_SUBST([GNULIB_PWRITE]) + GNULIB_READ=0; AC_SUBST([GNULIB_READ]) + GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK]) + GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT]) + GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR]) + GNULIB_SETHOSTNAME=0; AC_SUBST([GNULIB_SETHOSTNAME]) + GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP]) + GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK]) + GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT]) + GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R]) + GNULIB_UNISTD_H_NONBLOCKING=0; AC_SUBST([GNULIB_UNISTD_H_NONBLOCKING]) + GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE]) + GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK]) + GNULIB_UNLINKAT=0; AC_SUBST([GNULIB_UNLINKAT]) + GNULIB_USLEEP=0; AC_SUBST([GNULIB_USLEEP]) + GNULIB_WRITE=0; AC_SUBST([GNULIB_WRITE]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN]) + HAVE_DUP2=1; AC_SUBST([HAVE_DUP2]) + HAVE_DUP3=1; AC_SUBST([HAVE_DUP3]) + HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS]) + HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT]) + HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR]) + HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT]) + HAVE_FDATASYNC=1; AC_SUBST([HAVE_FDATASYNC]) + HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC]) + HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) + HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) + HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) + HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) + HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN]) + HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) + HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER]) + HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) + HAVE_LINK=1; AC_SUBST([HAVE_LINK]) + HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT]) + HAVE_PIPE=1; AC_SUBST([HAVE_PIPE]) + HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2]) + HAVE_PREAD=1; AC_SUBST([HAVE_PREAD]) + HAVE_PWRITE=1; AC_SUBST([HAVE_PWRITE]) + HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) + HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT]) + HAVE_SETHOSTNAME=1; AC_SUBST([HAVE_SETHOSTNAME]) + HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) + HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK]) + HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT]) + HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) + HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) + HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) + HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR]) + HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC]) + HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME]) + HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) + HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE]) + HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL]) + HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME]) + HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R]) + HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) + HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) + REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) + REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) + REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) + REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2]) + REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) + REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE]) + REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) + REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME]) + REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R]) + REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS]) + REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) + REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY]) + REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) + REPLACE_LINK=0; AC_SUBST([REPLACE_LINK]) + REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT]) + REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) + REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD]) + REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE]) + REPLACE_READ=0; AC_SUBST([REPLACE_READ]) + REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK]) + REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR]) + REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP]) + REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK]) + REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R]) + REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK]) + REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT]) + REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP]) + REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE]) + UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H]) + UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0; + AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS]) +]) diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4 new file mode 100644 index 000000000..d730e435a --- /dev/null +++ b/m4/vasnprintf.m4 @@ -0,0 +1,291 @@ +# vasnprintf.m4 serial 36 +dnl Copyright (C) 2002-2004, 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_VASNPRINTF], +[ + AC_CHECK_FUNCS_ONCE([vasnprintf]) + if test $ac_cv_func_vasnprintf = no; then + gl_REPLACE_VASNPRINTF + fi +]) + +AC_DEFUN([gl_REPLACE_VASNPRINTF], +[ + AC_CHECK_FUNCS_ONCE([vasnprintf]) + AC_LIBOBJ([vasnprintf]) + AC_LIBOBJ([printf-args]) + AC_LIBOBJ([printf-parse]) + AC_LIBOBJ([asnprintf]) + if test $ac_cv_func_vasnprintf = yes; then + AC_DEFINE([REPLACE_VASNPRINTF], [1], + [Define if vasnprintf exists but is overridden by gnulib.]) + fi + gl_PREREQ_PRINTF_ARGS + gl_PREREQ_PRINTF_PARSE + gl_PREREQ_VASNPRINTF + gl_PREREQ_ASNPRINTF +]) + +# Prerequisites of lib/printf-args.h, lib/printf-args.c. +AC_DEFUN([gl_PREREQ_PRINTF_ARGS], +[ + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) +]) + +# Prerequisites of lib/printf-parse.h, lib/printf-parse.c. +AC_DEFUN([gl_PREREQ_PRINTF_PARSE], +[ + AC_REQUIRE([gl_FEATURES_H]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + AC_REQUIRE([AC_TYPE_SIZE_T]) + AC_CHECK_TYPE([ptrdiff_t], , + [AC_DEFINE([ptrdiff_t], [long], + [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) + ]) + AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) +]) + +# Prerequisites of lib/vasnprintf.c. +AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], +[ + AC_REQUIRE([AC_FUNC_ALLOCA]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + AC_CHECK_FUNCS([snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb]) + dnl Use the _snprintf function only if it is declared (because on NetBSD it + dnl is defined as a weak alias of snprintf; we prefer to use the latter). + AC_CHECK_DECLS([_snprintf], , , [[#include ]]) + dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization + dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE. + AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION]) + dnl We can avoid a lot of code by assuming that snprintf's return value + dnl conforms to ISO C99. So check that. + AC_REQUIRE([gl_SNPRINTF_RETVAL_C99]) + case "$gl_cv_func_snprintf_retval_c99" in + *yes) + AC_DEFINE([HAVE_SNPRINTF_RETVAL_C99], [1], + [Define if the return value of the snprintf function is the number of + of bytes (excluding the terminating NUL) that would have been produced + if the buffer had been large enough.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting 'long double' +# arguments. +AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE], +[ + AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) + case "$gl_cv_func_printf_long_double" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + 'long double' arguments.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double' +# arguments. +AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE], +[ + AC_REQUIRE([gl_PRINTF_INFINITE]) + case "$gl_cv_func_printf_infinite" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + infinite 'double' arguments.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double' +# arguments. +AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE], +[ + AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE]) + dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if + dnl NEED_PRINTF_LONG_DOUBLE is already set. + AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE]) + case "$gl_cv_func_printf_long_double" in + *yes) + case "$gl_cv_func_printf_infinite_long_double" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + infinite 'long double' arguments.]) + ;; + esac + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive. +AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A], +[ + AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) + case "$gl_cv_func_printf_directive_a" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], [1], + [Define if the vasnprintf implementation needs special code for + the 'a' and 'A' directives.]) + AC_CHECK_FUNCS([nl_langinfo]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive. +AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F], +[ + AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) + case "$gl_cv_func_printf_directive_f" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], [1], + [Define if the vasnprintf implementation needs special code for + the 'F' directive.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the 'ls' directive. +AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS], +[ + AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS]) + case "$gl_cv_func_printf_directive_ls" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_DIRECTIVE_LS], [1], + [Define if the vasnprintf implementation needs special code for + the 'ls' directive.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. +AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], +[ + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) + case "$gl_cv_func_printf_flag_grouping" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1], + [Define if the vasnprintf implementation needs special code for the + ' flag.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the '-' flag. +AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST], +[ + AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST]) + case "$gl_cv_func_printf_flag_leftadjust" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_FLAG_LEFTADJUST], [1], + [Define if the vasnprintf implementation needs special code for the + '-' flag.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag. +AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO], +[ + AC_REQUIRE([gl_PRINTF_FLAG_ZERO]) + case "$gl_cv_func_printf_flag_zero" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_FLAG_ZERO], [1], + [Define if the vasnprintf implementation needs special code for the + 0 flag.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for supporting large precisions. +AC_DEFUN([gl_PREREQ_VASNPRINTF_PRECISION], +[ + AC_REQUIRE([gl_PRINTF_PRECISION]) + case "$gl_cv_func_printf_precision" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_UNBOUNDED_PRECISION], [1], + [Define if the vasnprintf implementation needs special code for + supporting large precisions without arbitrary bounds.]) + AC_DEFINE([NEED_PRINTF_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + 'double' arguments.]) + AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + 'long double' arguments.]) + ;; + esac +]) + +# Extra prerequisites of lib/vasnprintf.c for surviving out-of-memory +# conditions. +AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM], +[ + AC_REQUIRE([gl_PRINTF_ENOMEM]) + case "$gl_cv_func_printf_enomem" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_ENOMEM], [1], + [Define if the vasnprintf implementation needs special code for + surviving out-of-memory conditions.]) + AC_DEFINE([NEED_PRINTF_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + 'double' arguments.]) + AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], [1], + [Define if the vasnprintf implementation needs special code for + 'long double' arguments.]) + ;; + esac +]) + +# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance. +AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS], +[ + AC_REQUIRE([gl_PREREQ_VASNPRINTF]) + gl_PREREQ_VASNPRINTF_LONG_DOUBLE + gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE + gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE + gl_PREREQ_VASNPRINTF_DIRECTIVE_A + gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_DIRECTIVE_LS + gl_PREREQ_VASNPRINTF_FLAG_GROUPING + gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST + gl_PREREQ_VASNPRINTF_FLAG_ZERO + gl_PREREQ_VASNPRINTF_PRECISION + gl_PREREQ_VASNPRINTF_ENOMEM +]) + +# Prerequisites of lib/asnprintf.c. +AC_DEFUN([gl_PREREQ_ASNPRINTF], +[ +]) diff --git a/m4/visibility.m4 b/m4/visibility.m4 new file mode 100644 index 000000000..6cbd7e5f2 --- /dev/null +++ b/m4/visibility.m4 @@ -0,0 +1,77 @@ +# visibility.m4 serial 5 (gettext-0.18.2) +dnl Copyright (C) 2005, 2008, 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Tests whether the compiler supports the command-line option +dnl -fvisibility=hidden and the function and variable attributes +dnl __attribute__((__visibility__("hidden"))) and +dnl __attribute__((__visibility__("default"))). +dnl Does *not* test for __visibility__("protected") - which has tricky +dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on +dnl Mac OS X. +dnl Does *not* test for __visibility__("internal") - which has processor +dnl dependent semantics. +dnl Does *not* test for #pragma GCC visibility push(hidden) - which is +dnl "really only recommended for legacy code". +dnl Set the variable CFLAG_VISIBILITY. +dnl Defines and sets the variable HAVE_VISIBILITY. + +AC_DEFUN([gl_VISIBILITY], +[ + AC_REQUIRE([AC_PROG_CC]) + CFLAG_VISIBILITY= + HAVE_VISIBILITY=0 + if test -n "$GCC"; then + dnl First, check whether -Werror can be added to the command line, or + dnl whether it leads to an error because of some other option that the + dnl user has put into $CC $CFLAGS $CPPFLAGS. + AC_MSG_CHECKING([whether the -Werror option is usable]) + AC_CACHE_VAL([gl_cv_cc_vis_werror], [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Werror" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_vis_werror=yes], + [gl_cv_cc_vis_werror=no]) + CFLAGS="$gl_save_CFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_vis_werror]) + dnl Now check whether visibility declarations are supported. + AC_MSG_CHECKING([for simple visibility declarations]) + AC_CACHE_VAL([gl_cv_cc_visibility], [ + gl_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -fvisibility=hidden" + dnl We use the option -Werror and a function dummyfunc, because on some + dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning + dnl "visibility attribute not supported in this configuration; ignored" + dnl at the first function definition in every compilation unit, and we + dnl don't want to use the option in this case. + if test $gl_cv_cc_vis_werror = yes; then + CFLAGS="$CFLAGS -Werror" + fi + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[extern __attribute__((__visibility__("hidden"))) int hiddenvar; + extern __attribute__((__visibility__("default"))) int exportedvar; + extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); + extern __attribute__((__visibility__("default"))) int exportedfunc (void); + void dummyfunc (void) {} + ]], + [[]])], + [gl_cv_cc_visibility=yes], + [gl_cv_cc_visibility=no]) + CFLAGS="$gl_save_CFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_visibility]) + if test $gl_cv_cc_visibility = yes; then + CFLAG_VISIBILITY="-fvisibility=hidden" + HAVE_VISIBILITY=1 + fi + fi + AC_SUBST([CFLAG_VISIBILITY]) + AC_SUBST([HAVE_VISIBILITY]) + AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], + [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) +]) diff --git a/m4/vsnprintf.m4 b/m4/vsnprintf.m4 new file mode 100644 index 000000000..4900764ee --- /dev/null +++ b/m4/vsnprintf.m4 @@ -0,0 +1,54 @@ +# vsnprintf.m4 serial 6 +dnl Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Libintl 0.17 will replace vsnprintf only if it does not support %1$s, +dnl but defers to any gnulib vsnprintf replacements. Therefore, gnulib +dnl must guarantee that the decision for replacing vsnprintf is a superset +dnl of the reasons checked by libintl. +AC_DEFUN([gl_FUNC_VSNPRINTF], +[ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + gl_cv_func_vsnprintf_usable=no + AC_CHECK_FUNCS([vsnprintf]) + if test $ac_cv_func_vsnprintf = yes; then + gl_SNPRINTF_SIZE1 + case "$gl_cv_func_snprintf_size1" in + *yes) + gl_SNPRINTF_RETVAL_C99 + case "$gl_cv_func_snprintf_retval_c99" in + *yes) + gl_PRINTF_POSITIONS + case "$gl_cv_func_printf_positions" in + *yes) + gl_cv_func_vsnprintf_usable=yes + ;; + esac + ;; + esac + ;; + esac + fi + if test $gl_cv_func_vsnprintf_usable = no; then + gl_REPLACE_VSNPRINTF + fi + AC_CHECK_DECLS_ONCE([vsnprintf]) + if test $ac_cv_have_decl_vsnprintf = no; then + HAVE_DECL_VSNPRINTF=0 + fi +]) + +AC_DEFUN([gl_REPLACE_VSNPRINTF], +[ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + AC_LIBOBJ([vsnprintf]) + if test $ac_cv_func_vsnprintf = yes; then + REPLACE_VSNPRINTF=1 + fi + gl_PREREQ_VSNPRINTF +]) + +# Prerequisites of lib/vsnprintf.c. +AC_DEFUN([gl_PREREQ_VSNPRINTF], [:]) diff --git a/m4/warn-on-use.m4 b/m4/warn-on-use.m4 new file mode 100644 index 000000000..e43beebd9 --- /dev/null +++ b/m4/warn-on-use.m4 @@ -0,0 +1,47 @@ +# warn-on-use.m4 serial 5 +dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES) +# --------------------------------------- +# For each whitespace-separated element in the list of NAMES, define +# HAVE_RAW_DECL_name if the function has a declaration among INCLUDES +# even after being undefined as a macro. +# +# See warn-on-use.h for some hints on how to poison function names, as +# well as ideas on poisoning global variables and macros. NAMES may +# include global variables, but remember that only functions work with +# _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single +# header, but if the replacement header pulls in other headers because +# some systems declare functions in the wrong header, then INCLUDES +# should do likewise. +# +# It is generally safe to assume declarations for functions declared +# in the intersection of C89 and C11 (such as printf) without +# needing gl_WARN_ON_USE_PREPARE. +AC_DEFUN([gl_WARN_ON_USE_PREPARE], +[ + m4_foreach_w([gl_decl], [$2], + [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])), + [Define to 1 if ]m4_defn([gl_decl])[ is declared even after + undefining macros.])])dnl +dnl FIXME: gl_Symbol must be used unquoted until we can assume +dnl autoconf 2.64 or newer. + for gl_func in m4_flatten([$2]); do + AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl + AC_CACHE_CHECK([whether $gl_func is declared without a macro], + gl_Symbol, + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1], +[@%:@undef $gl_func + (void) $gl_func;])], + [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])]) + AS_VAR_IF(gl_Symbol, [yes], + [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1]) + dnl shortcut - if the raw declaration exists, then set a cache + dnl variable to allow skipping any later AC_CHECK_DECL efforts + eval ac_cv_have_decl_$gl_func=yes]) + AS_VAR_POPDEF([gl_Symbol])dnl + done +]) diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 new file mode 100644 index 000000000..bedb15a44 --- /dev/null +++ b/m4/wchar_h.m4 @@ -0,0 +1,225 @@ +dnl A placeholder for ISO C99 , for platforms that have issues. + +dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Eric Blake. + +# wchar_h.m4 serial 39 + +AC_DEFUN([gl_WCHAR_H], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([gl_WCHAR_H_INLINE_OK]) + dnl Prepare for creating substitute . + dnl Check for (missing in Linux uClibc when built without wide + dnl character support). + dnl is always overridden, because of GNULIB_POSIXCHECK. + gl_CHECK_NEXT_HEADERS([wchar.h]) + if test $ac_cv_header_wchar_h = yes; then + HAVE_WCHAR_H=1 + else + HAVE_WCHAR_H=0 + fi + AC_SUBST([HAVE_WCHAR_H]) + + AC_REQUIRE([gl_FEATURES_H]) + + AC_REQUIRE([gt_TYPE_WINT_T]) + if test $gt_cv_c_wint_t = yes; then + HAVE_WINT_T=1 + else + HAVE_WINT_T=0 + fi + AC_SUBST([HAVE_WINT_T]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +# include +# include +#endif +#include + ]], + [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb + wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset + wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp + wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr + wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth + ]) +]) + +dnl Check whether is usable at all. +AC_DEFUN([gl_WCHAR_H_INLINE_OK], +[ + dnl Test whether suffers due to the transition from '__inline' to + dnl 'gnu_inline'. See + dnl and . In summary, + dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and + dnl the option -std=c99 or -std=gnu99, leads to a broken . + AC_CACHE_CHECK([whether uses 'inline' correctly], + [gl_cv_header_wchar_h_correct_inline], + [gl_cv_header_wchar_h_correct_inline=yes + AC_LANG_CONFTEST([ + AC_LANG_SOURCE([[#define wcstod renamed_wcstod +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +extern int zero (void); +int main () { return zero(); } +]])]) + if AC_TRY_EVAL([ac_compile]); then + mv conftest.$ac_objext conftest1.$ac_objext + AC_LANG_CONFTEST([ + AC_LANG_SOURCE([[#define wcstod renamed_wcstod +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int zero (void) { return 0; } +]])]) + if AC_TRY_EVAL([ac_compile]); then + mv conftest.$ac_objext conftest2.$ac_objext + if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then + : + else + gl_cv_header_wchar_h_correct_inline=no + fi + fi + fi + rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext + ]) + if test $gl_cv_header_wchar_h_correct_inline = no; then + AC_MSG_ERROR([ cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS). +This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in +C99 mode. You have four options: + - Add the flag -fgnu89-inline to CC and reconfigure, or + - Fix your include files, using parts of + , or + - Use a gcc version older than 4.3, or + - Don't use the flags -std=c99 or -std=gnu99. +Configuration aborted.]) + fi +]) + +AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_WCHAR_H_DEFAULTS], +[ + GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC]) + GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB]) + GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT]) + GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC]) + GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN]) + GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS]) + GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS]) + GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB]) + GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS]) + GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS]) + GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH]) + GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR]) + GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP]) + GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY]) + GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE]) + GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET]) + GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN]) + GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN]) + GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY]) + GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY]) + GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY]) + GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY]) + GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT]) + GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT]) + GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP]) + GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP]) + GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP]) + GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP]) + GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL]) + GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM]) + GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP]) + GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR]) + GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR]) + GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN]) + GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN]) + GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK]) + GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR]) + GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK]) + GNULIB_WCSWIDTH=0; AC_SUBST([GNULIB_WCSWIDTH]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) + HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) + HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC]) + HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN]) + HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS]) + HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS]) + HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB]) + HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS]) + HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS]) + HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR]) + HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP]) + HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY]) + HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE]) + HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET]) + HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN]) + HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN]) + HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY]) + HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY]) + HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY]) + HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY]) + HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT]) + HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT]) + HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP]) + HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP]) + HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP]) + HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP]) + HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL]) + HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM]) + HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP]) + HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR]) + HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR]) + HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN]) + HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN]) + HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK]) + HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR]) + HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK]) + HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH]) + HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) + HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) + REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) + REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC]) + REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB]) + REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT]) + REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC]) + REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN]) + REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS]) + REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS]) + REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB]) + REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS]) + REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS]) + REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) + REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) +]) diff --git a/m4/wchar_t.m4 b/m4/wchar_t.m4 new file mode 100644 index 000000000..e1e1e699d --- /dev/null +++ b/m4/wchar_t.m4 @@ -0,0 +1,24 @@ +# wchar_t.m4 serial 4 (gettext-0.18.2) +dnl Copyright (C) 2002-2003, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether has the 'wchar_t' type. +dnl Prerequisite: AC_PROG_CC + +AC_DEFUN([gt_TYPE_WCHAR_T], +[ + AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + wchar_t foo = (wchar_t)'\0';]], + [[]])], + [gt_cv_c_wchar_t=yes], + [gt_cv_c_wchar_t=no])]) + if test $gt_cv_c_wchar_t = yes; then + AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.]) + fi +]) diff --git a/m4/wcrtomb.m4 b/m4/wcrtomb.m4 new file mode 100644 index 000000000..f56b5bae9 --- /dev/null +++ b/m4/wcrtomb.m4 @@ -0,0 +1,112 @@ +# wcrtomb.m4 serial 11 +dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_WCRTOMB], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + gl_MBSTATE_T_BROKEN + + AC_CHECK_FUNCS_ONCE([wcrtomb]) + if test $ac_cv_func_wcrtomb = no; then + HAVE_WCRTOMB=0 + AC_CHECK_DECLS([wcrtomb],,, [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +]]) + if test $ac_cv_have_decl_wcrtomb = yes; then + dnl On Minix 3.1.8, the system's declares wcrtomb() although + dnl it does not have the function. Avoid a collision with gnulib's + dnl replacement. + REPLACE_WCRTOMB=1 + fi + else + if test $REPLACE_MBSTATE_T = 1; then + REPLACE_WCRTOMB=1 + else + dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes + dnl returns 0 instead of 1. + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([gt_LOCALE_FR]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([gt_LOCALE_JA]) + AC_REQUIRE([gt_LOCALE_ZH_CN]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether wcrtomb return value is correct], + [gl_cv_func_wcrtomb_retval], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on AIX 4, OSF/1 and Solaris. + aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_wcrtomb_retval="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#include +#include +#include +#include +int main () +{ + int result = 0; + if (setlocale (LC_ALL, "$LOCALE_FR") != NULL) + { + if (wcrtomb (NULL, 0, NULL) != 1) + result |= 1; + } + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + if (wcrtomb (NULL, 0, NULL) != 1) + result |= 2; + } + if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) + { + if (wcrtomb (NULL, 0, NULL) != 1) + result |= 4; + } + if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) + { + if (wcrtomb (NULL, 0, NULL) != 1) + result |= 8; + } + return result; +}]])], + [gl_cv_func_wcrtomb_retval=yes], + [gl_cv_func_wcrtomb_retval=no], + [:]) + fi + ]) + case "$gl_cv_func_wcrtomb_retval" in + *yes) ;; + *) REPLACE_WCRTOMB=1 ;; + esac + fi + fi +]) + +# Prerequisites of lib/wcrtomb.c. +AC_DEFUN([gl_PREREQ_WCRTOMB], [ + : +]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 new file mode 100644 index 000000000..82ada0eee --- /dev/null +++ b/m4/wctype_h.m4 @@ -0,0 +1,209 @@ +# wctype_h.m4 serial 18 + +dnl A placeholder for ISO C99 , for platforms that lack it. + +dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_WCTYPE_H], +[ + AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CHECK_FUNCS_ONCE([iswcntrl]) + if test $ac_cv_func_iswcntrl = yes; then + HAVE_ISWCNTRL=1 + else + HAVE_ISWCNTRL=0 + fi + AC_SUBST([HAVE_ISWCNTRL]) + + AC_REQUIRE([gt_TYPE_WINT_T]) + if test $gt_cv_c_wint_t = yes; then + HAVE_WINT_T=1 + else + HAVE_WINT_T=0 + fi + AC_SUBST([HAVE_WINT_T]) + + gl_CHECK_NEXT_HEADERS([wctype.h]) + if test $ac_cv_header_wctype_h = yes; then + if test $ac_cv_func_iswcntrl = yes; then + dnl Linux libc5 has an iswprint function that returns 0 for all arguments. + dnl The other functions are likely broken in the same way. + AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + /* Tru64 with Desktop Toolkit C has a bug: must be + included before . + BSD/OS 4.0.1 has a bug: , and + must be included before . */ + #include + #include + #include + #include + #include + int main () { return iswprint ('x') == 0; } + ]])], + [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include + #if __GNU_LIBRARY__ == 1 + Linux libc5 i18n is broken. + #endif]], [])], + [gl_cv_func_iswcntrl_works="guessing yes"], + [gl_cv_func_iswcntrl_works="guessing no"]) + ]) + ]) + fi + HAVE_WCTYPE_H=1 + else + HAVE_WCTYPE_H=0 + fi + AC_SUBST([HAVE_WCTYPE_H]) + + case "$gl_cv_func_iswcntrl_works" in + *yes) REPLACE_ISWCNTRL=0 ;; + *) REPLACE_ISWCNTRL=1 ;; + esac + AC_SUBST([REPLACE_ISWCNTRL]) + + if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then + dnl Redefine all of iswcntrl, ..., iswxdigit in . + : + fi + + if test $REPLACE_ISWCNTRL = 1; then + REPLACE_TOWLOWER=1 + else + AC_CHECK_FUNCS([towlower]) + if test $ac_cv_func_towlower = yes; then + REPLACE_TOWLOWER=0 + else + AC_CHECK_DECLS([towlower],,, + [[/* Tru64 with Desktop Toolkit C has a bug: must be + included before . + BSD/OS 4.0.1 has a bug: , and + must be included before . */ + #include + #include + #include + #include + #if HAVE_WCTYPE_H + # include + #endif + ]]) + if test $ac_cv_have_decl_towlower = yes; then + dnl On Minix 3.1.8, the system's declares towlower() and + dnl towupper() although it does not have the functions. Avoid a + dnl collision with gnulib's replacement. + REPLACE_TOWLOWER=1 + else + REPLACE_TOWLOWER=0 + fi + fi + fi + AC_SUBST([REPLACE_TOWLOWER]) + + if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then + dnl Redefine towlower, towupper in . + : + fi + + dnl We assume that the wctype() and iswctype() functions exist if and only + dnl if the type wctype_t is defined in or in if that + dnl exists. + dnl HP-UX 11.00 declares all these in and lacks . + AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[/* Tru64 with Desktop Toolkit C has a bug: must be + included before . + BSD/OS 4.0.1 has a bug: , and + must be included before . */ + #include + #include + #include + #include + #if HAVE_WCTYPE_H + # include + #endif + wctype_t a; + ]], + [[]])], + [gl_cv_type_wctype_t=yes], + [gl_cv_type_wctype_t=no]) + ]) + if test $gl_cv_type_wctype_t = no; then + HAVE_WCTYPE_T=0 + fi + + dnl We assume that the wctrans() and towctrans() functions exist if and only + dnl if the type wctrans_t is defined in . + AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[/* Tru64 with Desktop Toolkit C has a bug: must be + included before . + BSD/OS 4.0.1 has a bug: , and + must be included before . */ + #include + #include + #include + #include + #include + wctrans_t a; + ]], + [[]])], + [gl_cv_type_wctrans_t=yes], + [gl_cv_type_wctrans_t=no]) + ]) + if test $gl_cv_type_wctrans_t = no; then + HAVE_WCTRANS_T=0 + fi + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +# include +# include +# include +#endif +#include + ]], + [wctype iswctype wctrans towctrans + ]) +]) + +AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_WCTYPE_H_DEFAULTS], +[ + GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK]) + GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE]) + GNULIB_ISWCTYPE=0; AC_SUBST([GNULIB_ISWCTYPE]) + GNULIB_WCTRANS=0; AC_SUBST([GNULIB_WCTRANS]) + GNULIB_TOWCTRANS=0; AC_SUBST([GNULIB_TOWCTRANS]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK]) + HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T]) + HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T]) + REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK]) +]) diff --git a/m4/wcwidth.m4 b/m4/wcwidth.m4 new file mode 100644 index 000000000..740f81ee1 --- /dev/null +++ b/m4/wcwidth.m4 @@ -0,0 +1,101 @@ +# wcwidth.m4 serial 23 +dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_WCWIDTH], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + + dnl Persuade glibc to declare wcwidth(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gt_TYPE_WCHAR_T]) + AC_REQUIRE([gt_TYPE_WINT_T]) + + AC_CHECK_HEADERS_ONCE([wchar.h]) + AC_CHECK_FUNCS_ONCE([wcwidth]) + + AC_CHECK_DECLS([wcwidth], [], [], [[ +/* AIX 3.2.5 declares wcwidth in . */ +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include +]]) + if test $ac_cv_have_decl_wcwidth != yes; then + HAVE_DECL_WCWIDTH=0 + fi + + if test $ac_cv_func_wcwidth = yes; then + HAVE_WCWIDTH=1 + dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1. + dnl On OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1. + dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1. + dnl This leads to bugs in 'ls' (coreutils). + AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales], + [gl_cv_func_wcwidth_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +/* AIX 3.2.5 declares wcwidth in . */ +#include +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include +#if !HAVE_DECL_WCWIDTH +extern +# ifdef __cplusplus +"C" +# endif +int wcwidth (int); +#endif +int main () +{ + int result = 0; + if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL) + { + if (wcwidth (0x0301) > 0) + result |= 1; + if (wcwidth (0x05B0) > 0) + result |= 2; + if (wcwidth (0x200B) > 0) + result |= 4; + } + return result; +}]])], + [gl_cv_func_wcwidth_works=yes], + [gl_cv_func_wcwidth_works=no], + [ +changequote(,)dnl + case "$host_os" in + # Guess yes on glibc and AIX 7 systems. + *-gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";; + *) gl_cv_func_wcwidth_works="guessing no";; + esac +changequote([,])dnl + ]) + ]) + case "$gl_cv_func_wcwidth_works" in + *yes) ;; + *no) REPLACE_WCWIDTH=1 ;; + esac + else + HAVE_WCWIDTH=0 + fi + dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not + dnl have the wcwidth function, then it does not declare it. +]) diff --git a/m4/wint_t.m4 b/m4/wint_t.m4 new file mode 100644 index 000000000..d7cd3db93 --- /dev/null +++ b/m4/wint_t.m4 @@ -0,0 +1,32 @@ +# wint_t.m4 serial 5 (gettext-0.18.2) +dnl Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. +dnl Test whether has the 'wint_t' type. +dnl Prerequisite: AC_PROG_CC + +AC_DEFUN([gt_TYPE_WINT_T], +[ + AC_CACHE_CHECK([for wint_t], [gt_cv_c_wint_t], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be included + before . */ +#include +#include +#include +#include + wint_t foo = (wchar_t)'\0';]], + [[]])], + [gt_cv_c_wint_t=yes], + [gt_cv_c_wint_t=no])]) + if test $gt_cv_c_wint_t = yes; then + AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.]) + fi +]) diff --git a/m4/xsize.m4 b/m4/xsize.m4 new file mode 100644 index 000000000..8ea9f2cd3 --- /dev/null +++ b/m4/xsize.m4 @@ -0,0 +1,12 @@ +# xsize.m4 serial 5 +dnl Copyright (C) 2003-2004, 2008-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_XSIZE], +[ + dnl Prerequisites of lib/xsize.h. + AC_REQUIRE([gl_SIZE_MAX]) + AC_CHECK_HEADERS([stdint.h]) +]) diff --git a/po/Makefile.in.in b/po/Makefile.in.in new file mode 100644 index 000000000..3619458e8 --- /dev/null +++ b/po/Makefile.in.in @@ -0,0 +1,469 @@ +# Makefile for PO directory in any package using GNU gettext. +# Copyright (C) 1995-1997, 2000-2007, 2009-2010 by Ulrich Drepper +# +# This file can be copied and used freely without restrictions. It can +# be used in projects which are not available under the GNU General Public +# License but which still want to provide support for the GNU gettext +# functionality. +# Please note that the actual code of GNU gettext is covered by the GNU +# General Public License and is *not* in the public domain. +# +# Origin: gettext-0.18 +GETTEXT_MACRO_VERSION = 0.18 + +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ + +SHELL = /bin/sh +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +datarootdir = @datarootdir@ +datadir = @datadir@ +localedir = @localedir@ +gettextsrcdir = $(datadir)/gettext/po + +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ + +# We use $(mkdir_p). +# In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as +# "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions, +# @install_sh@ does not start with $(SHELL), so we add it. +# In automake >= 1.10, @mkdir_p@ is derived from ${MKDIR_P}, which is defined +# either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake +# versions, $(mkinstalldirs) and $(install_sh) are unused. +mkinstalldirs = $(SHELL) @install_sh@ -d +install_sh = $(SHELL) @install_sh@ +MKDIR_P = @MKDIR_P@ +mkdir_p = @mkdir_p@ + +GMSGFMT_ = @GMSGFMT@ +GMSGFMT_no = @GMSGFMT@ +GMSGFMT_yes = @GMSGFMT_015@ +GMSGFMT = $(GMSGFMT_$(USE_MSGCTXT)) +MSGFMT_ = @MSGFMT@ +MSGFMT_no = @MSGFMT@ +MSGFMT_yes = @MSGFMT_015@ +MSGFMT = $(MSGFMT_$(USE_MSGCTXT)) +XGETTEXT_ = @XGETTEXT@ +XGETTEXT_no = @XGETTEXT@ +XGETTEXT_yes = @XGETTEXT_015@ +XGETTEXT = $(XGETTEXT_$(USE_MSGCTXT)) +MSGMERGE = msgmerge +MSGMERGE_UPDATE = @MSGMERGE@ --update +MSGINIT = msginit +MSGCONV = msgconv +MSGFILTER = msgfilter + +POFILES = @POFILES@ +GMOFILES = @GMOFILES@ +UPDATEPOFILES = @UPDATEPOFILES@ +DUMMYPOFILES = @DUMMYPOFILES@ +DISTFILES.common = Makefile.in.in remove-potcdate.sin \ +$(DISTFILES.common.extra1) $(DISTFILES.common.extra2) \ +$(DISTFILES.common.extra3) $(DISTFILES.common.extra4) $(DISTFILES.common.extra5) +DISTFILES = $(DISTFILES.common) Makevars POTFILES.in POTFILES-shell.in \ +$(POFILES) $(GMOFILES) \ +$(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3) $(DISTFILES.extra4) $(DISTFILES.extra5) grub.d.sed README + +POTFILES = \ + +CATALOGS = @CATALOGS@ + +# Makevars gets inserted here. (Don't remove this line!) + +.SUFFIXES: +.SUFFIXES: .po .gmo .mo .sed .sin .nop .po-create .po-update + +.po.mo: + @echo "$(MSGFMT) -c -o $@ $<"; \ + $(MSGFMT) --endianness=little -c -o t-$@ $< && mv t-$@ $@ + +.po.gmo: + @lang=`echo $* | sed -e 's,.*/,,'`; \ + test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ + echo "$${cdcmd}rm -f $${lang}.gmo && $(GMSGFMT) --endianness=little -c --statistics --verbose -o $${lang}.gmo $${lang}.po"; \ + cd $(srcdir) && rm -f $${lang}.gmo && $(GMSGFMT) --endianness=little -c --statistics --verbose -o t-$${lang}.gmo $${lang}.po && mv t-$${lang}.gmo $${lang}.gmo + +.sin.sed: + sed -e '/^#/d' $< > t-$@ + mv t-$@ $@ + + +all: check-macro-version all-@USE_NLS@ + +all-yes: stamp-po +all-no: + +# Ensure that the gettext macros and this Makefile.in.in are in sync. +check-macro-version: + @test "$(GETTEXT_MACRO_VERSION)" = "@GETTEXT_MACRO_VERSION@" \ + || { echo "*** error: gettext infrastructure mismatch: using a Makefile.in.in from gettext version $(GETTEXT_MACRO_VERSION) but the autoconf macros are from gettext version @GETTEXT_MACRO_VERSION@" 1>&2; \ + exit 1; \ + } + +# $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no +# internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because +# we don't want to bother translators with empty POT files). We assume that +# LINGUAS is empty in this case, i.e. $(POFILES) and $(GMOFILES) are empty. +# In this case, stamp-po is a nop (i.e. a phony target). + +# stamp-po is a timestamp denoting the last time at which the CATALOGS have +# been loosely updated. Its purpose is that when a developer or translator +# checks out the package via CVS, and the $(DOMAIN).pot file is not in CVS, +# "make" will update the $(DOMAIN).pot and the $(CATALOGS), but subsequent +# invocations of "make" will do nothing. This timestamp would not be necessary +# if updating the $(CATALOGS) would always touch them; however, the rule for +# $(POFILES) has been designed to not touch files that don't need to be +# changed. +stamp-po: $(srcdir)/$(DOMAIN).pot + test ! -f $(srcdir)/$(DOMAIN).pot || \ + test -z "$(GMOFILES)" || $(MAKE) $(GMOFILES) + @test ! -f $(srcdir)/$(DOMAIN).pot || { \ + echo "touch stamp-po" && \ + echo timestamp > stamp-poT && \ + mv stamp-poT stamp-po; \ + } + +# Note: Target 'all' must not depend on target '$(DOMAIN).pot-update', +# otherwise packages like GCC can not be built if only parts of the source +# have been downloaded. + +# This target rebuilds $(DOMAIN).pot; it is an expensive operation. +# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed. +$(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell.in remove-potcdate.sed + if LC_ALL=C grep 'GNU @PACKAGE@' $(top_srcdir)/* 2>/dev/null | grep -v 'libtool:' >/dev/null; then \ + package_gnu='GNU '; \ + else \ + package_gnu=''; \ + fi; \ + if test -n '$(MSGID_BUGS_ADDRESS)' || test '$(PACKAGE_BUGREPORT)' = '@'PACKAGE_BUGREPORT'@'; then \ + msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \ + else \ + msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \ + fi; \ + case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \ + $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ + --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \ + --files-from=$(srcdir)/POTFILES.in \ + --copyright-holder='$(COPYRIGHT_HOLDER)' \ + --msgid-bugs-address="$$msgid_bugs_address" \ + ;; \ + *) \ + $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ + --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \ + --files-from=$(srcdir)/POTFILES.in \ + --copyright-holder='$(COPYRIGHT_HOLDER)' \ + --package-name="$${package_gnu}@PACKAGE@" \ + --package-version='@VERSION@' \ + --msgid-bugs-address="$$msgid_bugs_address" \ + ;; \ + esac; \ + case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \ + $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ + --add-comments=TRANSLATORS: @XGETTEXT_EXTRA_OPTIONS@ \ + --files-from=$(srcdir)/POTFILES-shell.in \ + --copyright-holder='$(COPYRIGHT_HOLDER)' \ + --msgid-bugs-address="$$msgid_bugs_address" \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ + ;; \ + *) \ + $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ + --add-comments=TRANSLATORS: @XGETTEXT_EXTRA_OPTIONS@ \ + --files-from=$(srcdir)/POTFILES-shell.in \ + --copyright-holder='$(COPYRIGHT_HOLDER)' \ + --package-name="$${package_gnu}@PACKAGE@" \ + --package-version='@VERSION@' \ + --msgid-bugs-address="$$msgid_bugs_address" \ + --join-existing --language=Shell \ + --keyword=gettext_quoted --keyword=gettext_printf \ + ;; \ + esac ; \ + test ! -f $(DOMAIN).po || { \ + sed -f grub.d.sed < $(DOMAIN).po > $(DOMAIN).1po && \ + mv $(DOMAIN).1po $(DOMAIN).po; \ + if test -f $(srcdir)/$(DOMAIN).pot; then \ + sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ + sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \ + if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \ + rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \ + else \ + rm -f $(DOMAIN).1po $(DOMAIN).2po $(srcdir)/$(DOMAIN).pot && \ + mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \ + fi; \ + else \ + mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \ + fi; \ + } + +# This rule has no dependencies: we don't need to update $(DOMAIN).pot at +# every "make" invocation, only create it when it is missing. +# Only "make $(DOMAIN).pot-update" or "make dist" will force an update. +$(srcdir)/$(DOMAIN).pot: + $(MAKE) $(DOMAIN).pot-update + +# This target rebuilds a PO file if $(DOMAIN).pot has changed. +# Note that a PO file is not touched if it doesn't need to be changed. +$(POFILES): $(srcdir)/$(DOMAIN).pot + @lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \ + if test -f "$(srcdir)/$${lang}.po"; then \ + test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ + echo "$${cdcmd}$(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} $${lang}.po $(DOMAIN).pot"; \ + cd $(srcdir) \ + && { case `$(MSGMERGE_UPDATE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-7] | 0.1[0-7].*) \ + $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) $${lang}.po $(DOMAIN).pot;; \ + *) \ + $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} $${lang}.po $(DOMAIN).pot;; \ + esac; \ + }; \ + else \ + $(MAKE) $${lang}.po-create; \ + fi + + +install: install-exec install-data +install-exec: +install-data: install-data-@USE_NLS@ + if test "$(PACKAGE)" = "gettext-tools"; then \ + $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ + for file in $(DISTFILES.common) Makevars.template; do \ + $(INSTALL_DATA) $(srcdir)/$$file \ + $(DESTDIR)$(gettextsrcdir)/$$file; \ + done; \ + for file in Makevars; do \ + rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ + done; \ + else \ + : ; \ + fi +install-data-no: all +install-data-yes: all + @catalogs='$(CATALOGS)'; \ + for cat in $$catalogs; do \ + cat=`basename $$cat`; \ + lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ + dir=$(localedir)/$$lang/LC_MESSAGES; \ + $(mkdir_p) $(DESTDIR)$$dir; \ + if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \ + $(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \ + echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \ + for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \ + if test -n "$$lc"; then \ + if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \ + link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \ + mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ + mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ + (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \ + for file in *; do \ + if test -f $$file; then \ + ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \ + fi; \ + done); \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ + else \ + if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \ + :; \ + else \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \ + mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ + fi; \ + fi; \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ + ln -s ../LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \ + ln $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \ + cp -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ + echo "installing $$realcat link as $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo"; \ + fi; \ + done; \ + done + +install-strip: install + +installdirs: installdirs-exec installdirs-data +installdirs-exec: +installdirs-data: installdirs-data-@USE_NLS@ + if test "$(PACKAGE)" = "gettext-tools"; then \ + $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ + else \ + : ; \ + fi +installdirs-data-no: +installdirs-data-yes: + @catalogs='$(CATALOGS)'; \ + for cat in $$catalogs; do \ + cat=`basename $$cat`; \ + lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ + dir=$(localedir)/$$lang/LC_MESSAGES; \ + $(mkdir_p) $(DESTDIR)$$dir; \ + for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \ + if test -n "$$lc"; then \ + if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \ + link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \ + mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ + mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ + (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \ + for file in *; do \ + if test -f $$file; then \ + ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \ + fi; \ + done); \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ + else \ + if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \ + :; \ + else \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \ + mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ + fi; \ + fi; \ + fi; \ + done; \ + done + +# Define this as empty until I found a useful application. +installcheck: + +uninstall: uninstall-exec uninstall-data +uninstall-exec: +uninstall-data: uninstall-data-@USE_NLS@ + if test "$(PACKAGE)" = "gettext-tools"; then \ + for file in $(DISTFILES.common) Makevars.template; do \ + rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ + done; \ + else \ + : ; \ + fi +uninstall-data-no: +uninstall-data-yes: + catalogs='$(CATALOGS)'; \ + for cat in $$catalogs; do \ + cat=`basename $$cat`; \ + lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ + for lc in LC_MESSAGES $(EXTRA_LOCALE_CATEGORIES); do \ + rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ + done; \ + done + +check: all + +info dvi ps pdf html tags TAGS ctags CTAGS ID: + +mostlyclean: + rm -f remove-potcdate.sed + rm -f stamp-poT + rm -f core core.* $(DOMAIN).po $(DOMAIN).1po $(DOMAIN).2po *.new.po + rm -fr *.o + +clean: mostlyclean + +distclean: clean + rm -f Makefile Makefile.in POTFILES *.mo + +maintainer-clean: distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + rm -f stamp-po $(GMOFILES) + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) +dist distdir: + $(MAKE) update-po + @$(MAKE) dist2 +# This is a separate target because 'update-po' must be executed before. +dist2: stamp-po $(DISTFILES) + dists="$(DISTFILES)"; \ + if test "$(PACKAGE)" = "gettext-tools"; then \ + dists="$$dists Makevars.template"; \ + fi; \ + if test -f $(srcdir)/$(DOMAIN).pot; then \ + dists="$$dists $(DOMAIN).pot stamp-po"; \ + fi; \ + if test -f $(srcdir)/ChangeLog; then \ + dists="$$dists ChangeLog"; \ + fi; \ + for i in 0 1 2 3 4 5 6 7 8 9; do \ + if test -f $(srcdir)/ChangeLog.$$i; then \ + dists="$$dists ChangeLog.$$i"; \ + fi; \ + done; \ + if test -f $(srcdir)/LINGUAS; then dists="$$dists LINGUAS"; fi; \ + for file in $$dists; do \ + if test -f $$file; then \ + cp -p $$file $(distdir) || exit 1; \ + else \ + cp -p $(srcdir)/$$file $(distdir) || exit 1; \ + fi; \ + done + +update-po: Makefile + $(MAKE) $(DOMAIN).pot-update + test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES) + $(MAKE) update-gmo + +# General rule for creating PO files. + +.nop.po-create: + @lang=`echo $@ | sed -e 's/\.po-create$$//'`; \ + echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \ + exit 1 + +# General rule for updating PO files. + +.nop.po-update: + @lang=`echo $@ | sed -e 's/\.po-update$$//'`; \ + if test "$(PACKAGE)" = "gettext-tools"; then PATH=`pwd`/../src:$$PATH; fi; \ + tmpdir=`pwd`; \ + echo "$$lang:"; \ + test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ + echo "$${cdcmd}$(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \ + cd $(srcdir); \ + if { case `$(MSGMERGE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ + '' | 0.[0-9] | 0.[0-9].* | 0.1[0-7] | 0.1[0-7].*) \ + $(MSGMERGE) $(MSGMERGE_OPTIONS) -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \ + *) \ + $(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \ + esac; \ + }; then \ + if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ + rm -f $$tmpdir/$$lang.new.po; \ + else \ + if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ + :; \ + else \ + echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ + exit 1; \ + fi; \ + fi; \ + else \ + echo "msgmerge for $$lang.po failed!" 1>&2; \ + rm -f $$tmpdir/$$lang.new.po; \ + fi + +$(DUMMYPOFILES): + +update-gmo: Makefile $(GMOFILES) + @: + +# Recreate Makefile by invoking config.status. Explicitly invoke the shell, +# because execution permission bits may not work on the current file system. +# Use @SHELL@, which is the shell determined by autoconf for the use by its +# scripts, not $(SHELL) which is hardwired to /bin/sh and may be deficient. +Makefile: Makefile.in.in Makevars $(top_builddir)/config.status @POMAKEFILEDEPS@ + cd $(top_builddir) \ + && @SHELL@ ./config.status $(subdir)/$@.in po-directories + +force: + +# Tell versions [3.59,3.63) of GNU make not to export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/po/Makevars b/po/Makevars new file mode 100644 index 000000000..44857b1b8 --- /dev/null +++ b/po/Makevars @@ -0,0 +1,41 @@ +# Makefile variables for PO directory in any package using GNU gettext. + +# Usually the message domain is the same as the package name. +DOMAIN = $(PACKAGE) + +# These two variables depend on the location of this directory. +subdir = po +top_builddir = .. + +# These options get passed to xgettext. +XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ + +# This is the copyright holder that gets inserted into the header of the +# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding +# package. (Note that the msgstr strings, extracted from the package's +# sources, belong to the copyright holder of the package.) Translators are +# expected to transfer the copyright for their translations to this person +# or entity, or to disclaim their copyright. The empty string stands for +# the public domain; in this case the translators are expected to disclaim +# their copyright. +COPYRIGHT_HOLDER = Free Software Foundation, Inc. + +# This is the email address or URL to which the translators shall report +# bugs in the untranslated strings: +# - Strings which are not entire sentences, see the maintainer guidelines +# in the GNU gettext documentation, section 'Preparing Strings'. +# - Strings which use unclear terms or require additional context to be +# understood. +# - Strings which make invalid assumptions about notation of date, time or +# money. +# - Pluralisation problems. +# - Incorrect English spelling. +# - Incorrect formatting. +# It can be your email address, or a mailing list address where translators +# can write to without being subscribed, or the URL of a web page through +# which the translators can contact you. +MSGID_BUGS_ADDRESS = bug-grub@gnu.org + +# This is the list of locale categories, beyond LC_MESSAGES, for which the +# message catalogs shall be used. It is usually empty. +EXTRA_LOCALE_CATEGORIES = diff --git a/po/Rules-quot b/po/Rules-quot new file mode 100644 index 000000000..af5248792 --- /dev/null +++ b/po/Rules-quot @@ -0,0 +1,47 @@ +# Special Makefile rules for English message catalogs with quotation marks. + +DISTFILES.common.extra1 = quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot + +.SUFFIXES: .insert-header .po-update-en + +en@quot.po-create: + $(MAKE) en@quot.po-update +en@boldquot.po-create: + $(MAKE) en@boldquot.po-update + +en@quot.po-update: en@quot.po-update-en +en@boldquot.po-update: en@boldquot.po-update-en + +.insert-header.po-update-en: + @lang=`echo $@ | sed -e 's/\.po-update-en$$//'`; \ + if test "$(PACKAGE)" = "gettext"; then PATH=`pwd`/../src:$$PATH; GETTEXTLIBDIR=`cd $(top_srcdir)/src && pwd`; export GETTEXTLIBDIR; fi; \ + tmpdir=`pwd`; \ + echo "$$lang:"; \ + ll=`echo $$lang | sed -e 's/@.*//'`; \ + LC_ALL=C; export LC_ALL; \ + cd $(srcdir); \ + if $(MSGINIT) -i $(DOMAIN).pot --no-translator -l $$lang -o - 2>/dev/null | sed -f $$tmpdir/$$lang.insert-header | $(MSGCONV) -t UTF-8 | $(MSGFILTER) sed -f `echo $$lang | sed -e 's/.*@//'`.sed 2>/dev/null > $$tmpdir/$$lang.new.po; then \ + if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ + rm -f $$tmpdir/$$lang.new.po; \ + else \ + if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ + :; \ + else \ + echo "creation of $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ + exit 1; \ + fi; \ + fi; \ + else \ + echo "creation of $$lang.po failed!" 1>&2; \ + rm -f $$tmpdir/$$lang.new.po; \ + fi + +en@quot.insert-header: insert-header.sin + sed -e '/^#/d' -e 's/HEADER/en@quot.header/g' $(srcdir)/insert-header.sin > en@quot.insert-header + +en@boldquot.insert-header: insert-header.sin + sed -e '/^#/d' -e 's/HEADER/en@boldquot.header/g' $(srcdir)/insert-header.sin > en@boldquot.insert-header + +mostlyclean: mostlyclean-quot +mostlyclean-quot: + rm -f *.insert-header diff --git a/po/Rules-translit b/po/Rules-translit index ab84a5f1f..4f9176d30 100644 --- a/po/Rules-translit +++ b/po/Rules-translit @@ -1,16 +1,16 @@ DISTFILES.common.extra4 = hebrew.sed cyrillic.sed greek.sed arabic.sed Rules-translit de@hebrew.po-create: de.po hebrew.sed - LC_ALL=C $(MSGFILTER) -i $< -o $(srcdir)/de@hebrew.po sed -f $(srcdir)/hebrew.sed + LC_ALL=C.UTF-8 $(MSGFILTER) -i $< -o $(srcdir)/de@hebrew.po sed -f $(srcdir)/hebrew.sed en@hebrew.po-create: $(DOMAIN).pot hebrew.sed - LC_ALL=C $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@hebrew -o - 2>/dev/null | LC_ALL=C $(MSGCONV) -t UTF-8 | LC_ALL=C $(MSGFILTER) -o $(srcdir)/en@hebrew.po -i - sed -f $(srcdir)/hebrew.sed + LC_ALL=C.UTF-8 $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@hebrew -o - 2>/dev/null | LC_ALL=C.UTF-8 $(MSGCONV) -t UTF-8 | LC_ALL=C.UTF-8 $(MSGFILTER) -o $(srcdir)/en@hebrew.po -i - sed -f $(srcdir)/hebrew.sed en@cyrillic.po-create: $(DOMAIN).pot cyrillic.sed - LC_ALL=C $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@cyrillic -o - 2>/dev/null | LC_ALL=C $(MSGCONV) -t UTF-8 | LC_ALL=C $(MSGFILTER) -o $(srcdir)/en@cyrillic.po -i - sed -f $(srcdir)/cyrillic.sed + LC_ALL=C.UTF-8 $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@cyrillic -o - 2>/dev/null | LC_ALL=C.UTF-8 $(MSGCONV) -t UTF-8 | LC_ALL=C.UTF-8 $(MSGFILTER) -o $(srcdir)/en@cyrillic.po -i - sed -f $(srcdir)/cyrillic.sed en@greek.po-create: $(DOMAIN).pot greek.sed - LC_ALL=C $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@greek -o - 2>/dev/null | LC_ALL=C $(MSGCONV) -t UTF-8 | LC_ALL=C $(MSGFILTER) -o $(srcdir)/en@greek.po -i - sed -f $(srcdir)/greek.sed + LC_ALL=C.UTF-8 $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@greek -o - 2>/dev/null | LC_ALL=C.UTF-8 $(MSGCONV) -t UTF-8 | LC_ALL=C.UTF-8 $(MSGFILTER) -o $(srcdir)/en@greek.po -i - sed -f $(srcdir)/greek.sed en@arabic.po-create: $(DOMAIN).pot arabic.sed - LC_ALL=C $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@arabic -o - 2>/dev/null | LC_ALL=C $(MSGCONV) -t UTF-8 | LC_ALL=C $(MSGFILTER) -o $(srcdir)/en@arabic.po -i - sed -f $(srcdir)/arabic.sed + LC_ALL=C.UTF-8 $(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en@arabic -o - 2>/dev/null | LC_ALL=C.UTF-8 $(MSGCONV) -t UTF-8 | LC_ALL=C.UTF-8 $(MSGFILTER) -o $(srcdir)/en@arabic.po -i - sed -f $(srcdir)/arabic.sed diff --git a/po/arabic.sed b/po/arabic.sed index 21dc8b6db..b5b5db661 100644 --- a/po/arabic.sed +++ b/po/arabic.sed @@ -73,7 +73,6 @@ s,%\([0-9]*\)لد,%\1ld,g s,%\([0-9]*\)للد,%\1lld,g s,%\([0-9\.\*]*\)س,%\1s,g -s,%\([0-9\.\*]*\)Ù…,%\1m,g s,%\([0-9]*\)لو,%\1lu,g s,%\([0-9]*\)Ùˆ,%\1u,g s,%\([0-9]*\)للو,%\1llu,g diff --git a/po/cyrillic.sed b/po/cyrillic.sed index 2e3e6655d..46ddaec6e 100644 --- a/po/cyrillic.sed +++ b/po/cyrillic.sed @@ -10,84 +10,8 @@ /^Content-Transfer-Encoding:/ b /^Plural-Forms:/ b -s,a,а,g -s,b,б,g -s,c,ц,g -s,d,д,g -s,e,е,g -s,f,Ñ„,g -s,g,г,g -s,h,Ñ…,g -s,i,и,g -s,j,й,g -s,k,к,g -s,l,л,g -s,m,м,g -s,n,н,g -s,o,о,g -s,p,п,g -s,q,Ñœ,g -s,r,Ñ€,g -s,s,Ñ,g -s,t,Ñ‚,g -s,u,у,g -s,v,в,g -s,w,Ñž,g -s,x,ѯ,g -s,y,Ñ,g -s,z,з,g -s,A,Ð,g -s,B,Б,g -s,C,Ц,g -s,D,Д,g -s,E,Е,g -s,F,Ф,g -s,G,Г,g -s,H,Ð¥,g -s,I,И,g -s,J,Й,g -s,K,К,g -s,L,Л,g -s,M,М,g -s,N,Ð,g -s,O,О,g -s,P,П,g -s,Q,ÐŒ,g -s,R,Р,g -s,S,С,g -s,T,Т,g -s,U,У,g -s,V,Ð’,g -s,W,ÐŽ,g -s,X,Ñ®,g -s,Y,Ð,g -s,Z,З,g -s,Ð,Ð,g -s,Б,Б,g -s,Ц,Ц,g -s,Д,Д,g -s,Е,Е,g -s,Ф,Ф,g -s,Г,Г,g -s,Ð¥,Ð¥,g -s,И,И,g -s,Й,Й,g -s,К,К,g -s,Л,Л,g -s,М,М,g -s,Ð,Ð,g -s,О,О,g -s,П,П,g -s,ÐŒ,ÐŒ,g -s,Р,Р,g -s,С,С,g -s,Т,Т,g -s,У,У,g -s,Ð’,Ð’,g -s,ÐŽ,ÐŽ,g -s,Ñ®,Ñ®,g -s,Ð,Ð,g -s,З,З,g +y,abcdefghijklmnopqrstuvwxyz,абцдефгхийклмнопќрÑтувўѯÑз, +y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,ÐБЦДЕФГХИЙКЛМÐОПЌРСТУВЎѮÐЗ, s,%\([0-9]*\)Ц,%\1C,g s,%\([0-9]*\)ц,%\1c,g @@ -96,7 +20,6 @@ s,%\([0-9]*\)лд,%\1ld,g s,%\([0-9]*\)ллд,%\1lld,g s,%\([0-9\.\*]*\)Ñ,%\1s,g -s,%\([0-9\.\*]*\)м,%\1m,g s,%\([0-9]*\)лу,%\1lu,g s,%\([0-9]*\)у,%\1u,g s,%\([0-9]*\)ллу,%\1llu,g diff --git a/po/exclude.pot b/po/exclude.pot index 816089c30..1659eb01b 100644 --- a/po/exclude.pot +++ b/po/exclude.pot @@ -1214,7 +1214,6 @@ msgstr "" #: grub-core/commands/xnu_uuid.c:75 grub-core/fs/jfs.c:924 #: grub-core/fs/nilfs2.c:1135 -#: grub-core/fs/f2fs.c:1259 #, c-format msgid "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" msgstr "" @@ -2297,6 +2296,10 @@ msgstr "" msgid "WEEKDAY" msgstr "" +#: grub-core/io/lzopio.c:30 +msgid "‰LZO" +msgstr "" + #: grub-core/kern/dl.c:412 msgid "grub_mod_init" msgstr "" @@ -4212,10 +4215,22 @@ msgstr "" msgid "ext*" msgstr "" +#: grub-core/partmap/msdos.c:74 +msgid "ÔA õ" +msgstr "" + +#: grub-core/partmap/msdos.c:80 +msgid "ØA õ" +msgstr "" + #: grub-core/partmap/msdos.c:86 msgid "HP Backup and Recovery Manager (?)" msgstr "" +#: grub-core/partmap/msdos.c:87 +msgid "pŠ]F5Å“®=†ý±U>à" +msgstr "" + #: grub-core/partmap/msdos.c:94 msgid "ycgl" msgstr "" @@ -4559,6 +4574,10 @@ msgstr "" msgid " failed: %ld\n" msgstr "" +#: grub-core/lib/xzembed/xz_stream.h:35 +msgid "ý7zXZ" +msgstr "" + #: grub-core/lib/xzembed/xz_stream.h:38 msgid "YZ" msgstr "" @@ -7154,344 +7173,3 @@ msgstr "" #: util/grub-mkimagexx.c:845 msgid "CALL26 Relocation out of range" msgstr "" - -#: grub-core/commands/verify.c:313 -msgid "\x99" -msgstr "" - -#: grub-core/commands/videotest.c:122 -msgid "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00" - " \xC2\xA1\xCF\x84\xC3\xA4u! " - " \xE2\x84\xA4\xE2\x8A\x86\xE2\x84\x9D" -msgstr "" - -#: grub-core/disk/luks.c:40 -msgid "LUKS\xBA\xBE" -msgstr "" - -#: grub-core/disk/lvmparse.c:67 grub-core/disk/lvmparse.c:69 -msgid " = [" -msgstr "" - -#: grub-core/disk/lvmparse.c:115 grub-core/disk/lvmparse.c:123 -#: grub-core/disk/lvmparse.c:167 grub-core/disk/lvmparse.c:170 -msgid "id = \"" -msgstr "" - -#: grub-core/disk/lvmparse.c:127 -msgid "extent_size = " -msgstr "" - -#: grub-core/disk/lvmparse.c:143 grub-core/disk/lvmparse.c:146 -msgid "physical_volumes {" -msgstr "" - -#: grub-core/disk/lvmparse.c:174 -msgid "pe_start = " -msgstr "" - -#: grub-core/disk/lvmparse.c:199 -msgid "logical_volumes" -msgstr "" - -#: grub-core/disk/lvmparse.c:202 -msgid "logical_volumes = " -msgstr "" - -#: grub-core/disk/lvmparse.c:226 grub-core/disk/lvmparse.c:227 -msgid "status" -msgstr "" - -#: grub-core/disk/lvmparse.c:226 -msgid "VISIBLE" -msgstr "" - -#: grub-core/disk/lvmparse.c:227 -msgid "PVMOVE" -msgstr "" - -#: grub-core/disk/lvmparse.c:228 -msgid "segment_count = " -msgstr "" - -#: grub-core/disk/lvmparse.c:246 -msgid "segment" -msgstr "" - -#: grub-core/disk/lvmparse.c:255 -msgid "start_extent = " -msgstr "" - -#: grub-core/disk/lvmparse.c:263 -msgid "extent_count = " -msgstr "" - -#: grub-core/disk/lvmparse.c:272 grub-core/disk/lvmparse.c:275 -msgid "type = \"" -msgstr "" - -#: grub-core/disk/lvmparse.c:277 grub-core/disk/lvmparse.c:278 -msgid "striped\"" -msgstr "" - -#: grub-core/disk/lvmparse.c:282 -msgid "stripe_count = " -msgstr "" - -#: grub-core/disk/lvmparse.c:292 grub-core/disk/lvmparse.c:396 -msgid "stripe_size = " -msgstr "" - -#: grub-core/disk/lvmparse.c:299 grub-core/disk/lvmparse.c:307 -msgid "stripes = [" -msgstr "" - -#: grub-core/disk/lvmparse.c:332 -msgid "mirror\"" -msgstr "" - -#: grub-core/disk/lvmparse.c:336 -msgid "mirror_count = " -msgstr "" - -#: grub-core/disk/lvmparse.c:350 grub-core/disk/lvmparse.c:358 -msgid "mirrors = [" -msgstr "" - -#: grub-core/disk/lvmparse.c:375 grub-core/disk/lvmparse.c:376 -#: grub-core/disk/lvmparse.c:377 grub-core/disk/lvmparse.c:384 -msgid "raid" -msgstr "" - -#: grub-core/disk/lvmparse.c:378 -msgid "raidX" -msgstr "" - -#: grub-core/disk/lvmparse.c:386 -msgid "device_count = " -msgstr "" - -#: grub-core/disk/lvmparse.c:410 grub-core/disk/lvmparse.c:418 -msgid "raids = [" -msgstr "" - -#: grub-core/fs/cpio.c:24 -msgid "\xc7\x71" -msgstr "" - -#: grub-core/fs/cpio_be.c:23 -msgid "\x71\xc7" -msgstr "" - -#: grub-core/gfxmenu/gui_circular_progress.c:244 -msgid "\xc2\xb0" -msgstr "" - -#: grub-core/kern/ieee1275/cmain.c:88 -msgid "IBM pSeries (emulated by qemu)" -msgstr "" - -#: grub-core/lib/all_video.c:36 -msgid "/video.lst" -msgstr "" - -#: grub-core/osdep/unix/config.c:108 -#, c-format -msgid "" -"'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\" " -"\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\"" -msgstr "" - -#: include/grub/dl.h:141 -msgid "license" -msgstr "" - -#: util/grub-install.c:1106 -msgid "BOOTAA64.EFI" -msgstr "" - -#: util/grub-install.c:1133 -msgid "grubaa64.efi" -msgstr "" - -#: util/grub-install.c:1274 -msgid "GRUB_ENABLE_CRYPTODISK=y" -msgstr "" - -#: util/grub-mkrescue.c:656 -msgid "part_gpt" -msgstr "" - -#: util/grub-mkrescue.c:657 -msgid "part_msdos" -msgstr "" - -#: util/grub-mkrescue.c:663 util/grub-mkrescue.c:668 util/grub-mkrescue.c:723 -msgid "part_apple" -msgstr "" - -#: util/grub-mkrescue.c:677 -msgid "bootaa64.efi" -msgstr "" - -#: util/grub-probe.c:136 util/grub-probe.c:151 util/grub-probe.c:190 -#: util/grub-probe.c:247 -#, c-format -msgid "%s%c" -msgstr "" - -#: util/grub-probe.c:233 -#, c-format -msgid "lvm%c" -msgstr "" - -#: util/grub-probe.c:237 -#, c-format -msgid "ldm%c" -msgstr "" - -#: util/grub-probe.c:245 -#, c-format -msgid "diskfilter%c" -msgstr "" - -#: util/grub-probe.c:250 -#, c-format -msgid "raid5rec%c" -msgstr "" - -#: util/grub-probe.c:252 -#, c-format -msgid "raid6rec%c" -msgstr "" - -#: util/grub-mkrescue.c:136 -#, c-format -msgid "%s\n\n%s\n\n%s" -msgstr "" - -#: grub-core/kern/arm/cache.c:133 -msgid "couldn't get memory map, not enabling caches" -msgstr "" - -#: grub-core/kern/arm/cache.c:149 -#, c-format -msgid "%d crossers\n" -msgstr "" - -#: grub-core/kern/arm/cache.c:154 -msgid "couldn't allocate place for MMU table, not enabling caches" -msgstr "" - -#: grub-core/kern/arm/cache.c:212 -msgid "MMU tables generated\n" -msgstr "" - -#: grub-core/kern/arm/cache.c:216 -msgid "enabling MMU\n" -msgstr "" - -#: grub-core/kern/arm/cache.c:218 -msgid "MMU enabled\n" -msgstr "" - -#: grub-core/commands/verify.c:313 -msgid "™" -msgstr "" - -#: grub-core/commands/videotest.c:122 -msgid "Unicode test: happy☺ £ 5.00 ¡Ã„äu! ℤ⊆â„Â" -msgstr "" - -#: grub-core/disk/luks.c:40 -msgid "LUKSº¾" -msgstr "" - -#: grub-core/fs/cpio.c:24 -msgid "Çq" -msgstr "" - -#: grub-core/fs/cpio_be.c:23 -msgid "qÇ" -msgstr "" - -#: grub-core/gfxmenu/gui_circular_progress.c:244 -msgid "°" -msgstr "" - -#: grub-core/lib/xzembed/xz_stream.h:35 -msgid "ý7zXZ" -msgstr "" - -#: grub-core/partmap/msdos.c:74 -msgid "ÔA õ" -msgstr "" - -#: grub-core/partmap/msdos.c:80 -msgid "ØA õ" -msgstr "" - -#: grub-core/partmap/msdos.c:87 -msgid "pŠ]F5Ã…“®=†ý±U>à" -msgstr "" - -#: grub-core/io/lzopio.c:30 -msgid "" -"‰LZO\n" -"\n" -msgstr "" - -#: grub-core/bus/emu/pci.c:58 -#, c-format -msgid "mapping 0x%llx failed (error %d)" -msgstr "" - -#: grub-core/disk/dmraid_nvidia.c:175 -msgid "nv" -msgstr "" - -#: grub-core/fs/xfs.c:478 -msgid ") - %" -msgstr "" - -#: grub-core/fs/xfs.c:478 -#, c-format -msgid ", %d -" -msgstr "" - -#: grub-core/fs/xfs.c:550 -msgid "BMA3" -msgstr "" - -#: grub-core/fs/zfs/zfs.c:284 -msgid "com.delphix:hole_birth" -msgstr "" - -#: grub-core/fs/zfs/zfs.c:285 -msgid "com.delphix:embedded_data" -msgstr "" - -#: grub-core/fs/zfs/zfs.c:286 -msgid "com.delphix:extensible_dataset" -msgstr "" - -#: grub-core/fs/zfs/zfs.c:287 -msgid "org.open-zfs:large_blocks" -msgstr "" - -#: grub-core/fs/zfs/zfs.c:1877 -msgid "/%" -msgstr "" - -#: grub-core/osdep/linux/platform.c:73 -msgid "/sys/firmware/efi/fw_platform_size" -msgstr "" - -#: util/grub-mkrescue.c:454 -msgid "-output" -msgstr "" - -#: util/grub-mkrescue.c:455 -msgid "--output" -msgstr "" diff --git a/po/gettext-patches/0001-Support-POTFILES-shell.patch b/po/gettext-patches/0001-Support-POTFILES-shell.patch deleted file mode 100644 index 5a5d1ec00..000000000 --- a/po/gettext-patches/0001-Support-POTFILES-shell.patch +++ /dev/null @@ -1,54 +0,0 @@ -From d5bbd8f60aacb0f73ea5a0bde999152c467d0e78 Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Sun, 1 Mar 2020 11:57:58 +0000 -Subject: [PATCH 1/4] Support POTFILES-shell - ---- - gettext-runtime/po/Makefile.in.in | 24 ++++++++++++++++++++++-- - 1 file changed, 22 insertions(+), 2 deletions(-) - -diff --git a/gettext-runtime/po/Makefile.in.in b/gettext-runtime/po/Makefile.in.in -index fabdc76c9..32e9323d3 100644 ---- a/gettext-runtime/po/Makefile.in.in -+++ b/gettext-runtime/po/Makefile.in.in -@@ -142,7 +142,7 @@ stamp-po: $(srcdir)/$(DOMAIN).pot - # The determination of whether the package xyz is a GNU one is based on the - # heuristic whether some file in the top level directory mentions "GNU xyz". - # If GNU 'find' is available, we avoid grepping through monster files. --$(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in remove-potcdate.sed -+$(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell.in remove-potcdate.sed - if { if (LC_ALL=C find --version) 2>/dev/null | grep GNU >/dev/null; then \ - LC_ALL=C find -L $(top_srcdir) -maxdepth 1 -type f -size -10000000c -exec grep 'GNU @PACKAGE@' /dev/null '{}' ';' 2>/dev/null; \ - else \ -@@ -175,7 +175,27 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in remove-potcdate.sed - --package-version='@VERSION@' \ - --msgid-bugs-address="$$msgid_bugs_address" \ - ;; \ -- esac -+ esac; \ -+ case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ -+ '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \ -+ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ -+ --add-comments=TRANSLATORS: @XGETTEXT_EXTRA_OPTIONS@ \ -+ --files-from=$(srcdir)/POTFILES-shell.in \ -+ --copyright-holder='$(COPYRIGHT_HOLDER)' \ -+ --msgid-bugs-address="$$msgid_bugs_address" \ -+ --join-existing --language=Shell --keyword=gettext_quoted \ -+ ;; \ -+ *) \ -+ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ -+ --add-comments=TRANSLATORS: @XGETTEXT_EXTRA_OPTIONS@ \ -+ --files-from=$(srcdir)/POTFILES-shell.in \ -+ --copyright-holder='$(COPYRIGHT_HOLDER)' \ -+ --package-name="$${package_gnu}@PACKAGE@" \ -+ --package-version='@VERSION@' \ -+ --msgid-bugs-address="$$msgid_bugs_address" \ -+ --join-existing --language=Shell --keyword=gettext_quoted \ -+ ;; \ -+ esac; \ - test ! -f $(DOMAIN).po || { \ - if test -f $(srcdir)/$(DOMAIN).pot; then \ - sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ --- -2.17.1 - diff --git a/po/gettext-patches/0002-Handle-gettext_printf-shell-function.patch b/po/gettext-patches/0002-Handle-gettext_printf-shell-function.patch deleted file mode 100644 index 2767ed65e..000000000 --- a/po/gettext-patches/0002-Handle-gettext_printf-shell-function.patch +++ /dev/null @@ -1,46 +0,0 @@ -From fd17c51f2e6c87427679fbdfb5f6224ff48795db Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Sun, 1 Mar 2020 12:00:41 +0000 -Subject: [PATCH 2/4] Handle gettext_printf shell function - -Extract gettext_printf arguments. - -Run grub.d.sed over strings extracted from util/grub.d/, in order to set -c-format flags (xgettext refuses to include these itself for strings it -extracted from a shell file, but these really are c-format). ---- - gettext-runtime/po/Makefile.in.in | 8 ++++++-- - 1 file changed, 6 insertions(+), 2 deletions(-) - -diff --git a/gettext-runtime/po/Makefile.in.in b/gettext-runtime/po/Makefile.in.in -index 32e9323d3..32e0c99a2 100644 ---- a/gettext-runtime/po/Makefile.in.in -+++ b/gettext-runtime/po/Makefile.in.in -@@ -183,7 +183,8 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell - --files-from=$(srcdir)/POTFILES-shell.in \ - --copyright-holder='$(COPYRIGHT_HOLDER)' \ - --msgid-bugs-address="$$msgid_bugs_address" \ -- --join-existing --language=Shell --keyword=gettext_quoted \ -+ --join-existing --language=Shell \ -+ --keyword=gettext_quoted --keyword=gettext_printf \ - ;; \ - *) \ - $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ -@@ -193,10 +194,13 @@ $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in $(srcdir)/POTFILES-shell - --package-name="$${package_gnu}@PACKAGE@" \ - --package-version='@VERSION@' \ - --msgid-bugs-address="$$msgid_bugs_address" \ -- --join-existing --language=Shell --keyword=gettext_quoted \ -+ --join-existing --language=Shell \ -+ --keyword=gettext_quoted --keyword=gettext_printf \ - ;; \ - esac; \ - test ! -f $(DOMAIN).po || { \ -+ sed -f grub.d.sed < $(DOMAIN).po > $(DOMAIN).1po && \ -+ mv $(DOMAIN).1po $(DOMAIN).po; \ - if test -f $(srcdir)/$(DOMAIN).pot; then \ - sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ - sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \ --- -2.17.1 - diff --git a/po/gettext-patches/0003-Make-msgfmt-output-in-little-endian.patch b/po/gettext-patches/0003-Make-msgfmt-output-in-little-endian.patch deleted file mode 100644 index 414161133..000000000 --- a/po/gettext-patches/0003-Make-msgfmt-output-in-little-endian.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 156c523e2945c9b43c5500fb93988b0dd2f08d75 Mon Sep 17 00:00:00 2001 -From: Vladimir Serbinenko -Date: Sun, 1 Mar 2020 12:09:25 +0000 -Subject: [PATCH 3/4] Make msgfmt output in little-endian - -GRUB expects this. ---- - gettext-runtime/po/Makefile.in.in | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/gettext-runtime/po/Makefile.in.in b/gettext-runtime/po/Makefile.in.in -index 32e0c99a2..f3ef54c39 100644 ---- a/gettext-runtime/po/Makefile.in.in -+++ b/gettext-runtime/po/Makefile.in.in -@@ -84,13 +84,13 @@ CATALOGS = @CATALOGS@ - - .po.mo: - @echo "$(MSGFMT) -c -o $@ $<"; \ -- $(MSGFMT) -c -o t-$@ $< && mv t-$@ $@ -+ $(MSGFMT) --endianness=little -c -o t-$@ $< && mv t-$@ $@ - - .po.gmo: - @lang=`echo $* | sed -e 's,.*/,,'`; \ - test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ -- echo "$${cdcmd}rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics --verbose -o $${lang}.gmo $${lang}.po"; \ -- cd $(srcdir) && rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics --verbose -o t-$${lang}.gmo $${lang}.po && mv t-$${lang}.gmo $${lang}.gmo -+ echo "$${cdcmd}rm -f $${lang}.gmo && $(GMSGFMT) --endianness=little -c --statistics --verbose -o $${lang}.gmo $${lang}.po"; \ -+ cd $(srcdir) && rm -f $${lang}.gmo && $(GMSGFMT) --endianness=little -c --statistics --verbose -o t-$${lang}.gmo $${lang}.po && mv t-$${lang}.gmo $${lang}.gmo - - .sin.sed: - sed -e '/^#/d' $< > t-$@ --- -2.17.1 - diff --git a/po/gettext-patches/0004-Use-SHELL-rather-than-bin-sh.patch b/po/gettext-patches/0004-Use-SHELL-rather-than-bin-sh.patch deleted file mode 100644 index 790521d3f..000000000 --- a/po/gettext-patches/0004-Use-SHELL-rather-than-bin-sh.patch +++ /dev/null @@ -1,26 +0,0 @@ -From f36f12e77798223ee7ee882c0d09e0e63db11454 Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Sun, 1 Mar 2020 12:14:07 +0000 -Subject: [PATCH 4/4] Use @SHELL rather than /bin/sh - -/bin/sh might not exist. ---- - gettext-runtime/po/Makefile.in.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/gettext-runtime/po/Makefile.in.in b/gettext-runtime/po/Makefile.in.in -index f3ef54c39..285a55a9d 100644 ---- a/gettext-runtime/po/Makefile.in.in -+++ b/gettext-runtime/po/Makefile.in.in -@@ -16,7 +16,7 @@ VERSION = @VERSION@ - PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ - - SED = @SED@ --SHELL = /bin/sh -+SHELL = @SHELL@ - @SET_MAKE@ - - srcdir = @srcdir@ --- -2.17.1 - diff --git a/po/greek.sed b/po/greek.sed index 3543f6aac..17e4b0468 100644 --- a/po/greek.sed +++ b/po/greek.sed @@ -12,84 +12,8 @@ s,%\([0-9]*\)C,%\1#,g -s,a,α,g -s,b,Ï­,g -s,c,ϲ,g -s,d,δ,g -s,e,ε,g -s,f,φ,g -s,g,γ,g -s,h,χ,g -s,i,ι,g -s,j,ÏŠ,g -s,k,κ,g -s,l,λ,g -s,m,μ,g -s,n,ν,g -s,o,ο,g -s,p,Ï€,g -s,q,Ï—,g -s,r,Ï,g -s,s,σ,g -s,t,Ï„,g -s,u,Ï…,g -s,v,β,g -s,w,ω,g -s,x,ξ,g -s,y,Ï‹,g -s,z,ζ,g -s,A,Α,g -s,B,Ϭ,g -s,C,ϲ,g -s,D,Δ,g -s,E,Ε,g -s,F,Φ,g -s,G,Γ,g -s,H,Χ,g -s,I,Ι,g -s,J,Ϊ,g -s,K,Κ,g -s,L,Λ,g -s,M,Μ,g -s,N,Î,g -s,O,Ο,g -s,P,Π,g -s,Q,Ï,g -s,R,Ρ,g -s,S,Σ,g -s,T,Τ,g -s,U,Î¥,g -s,V,Î’,g -s,W,Ω,g -s,X,Ξ,g -s,Y,Ϋ,g -s,Z,Ζ,g -s,Ð,Ð,g -s,Б,Б,g -s,Ц,Ц,g -s,Д,Д,g -s,Е,Е,g -s,Ф,Ф,g -s,Г,Г,g -s,Ð¥,Ð¥,g -s,И,И,g -s,Й,Й,g -s,К,К,g -s,Л,Л,g -s,М,М,g -s,Ð,Ð,g -s,О,О,g -s,П,П,g -s,ÐŒ,ÐŒ,g -s,Р,Р,g -s,С,С,g -s,Т,Т,g -s,У,У,g -s,Ð’,Ð’,g -s,ÐŽ,ÐŽ,g -s,Ñ®,Ñ®,g -s,Ð,Ð,g -s,З,З,g +y,abcdefghijklmnopqrstuvwxyz,αϭϲδεφγχιϊκλμνοπϗÏστυβωξϋζ, +y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,ΑϬϲΔΕΦΓΧΙΪΚΛΜÎΟΠÏΡΣΤΥΒΩΞΫΖ, s,%\([0-9]*\)#,%\1C,g s,%\([0-9]*\)ϲ,%\1c,g @@ -98,7 +22,6 @@ s,%\([0-9]*\)λδ,%\1ld,g s,%\([0-9]*\)λλδ,%\1lld,g s,%\([0-9\.\*]*\)σ,%\1s,g -s,%\([0-9\.\*]*\)μ,%\1m,g s,%\([0-9]*\)λυ,%\1lu,g s,%\([0-9]*\)Ï…,%\1u,g s,%\([0-9]*\)λλυ,%\1llu,g diff --git a/po/hebrew.sed b/po/hebrew.sed index 9210014bc..a47bc6a28 100644 --- a/po/hebrew.sed +++ b/po/hebrew.sed @@ -81,7 +81,6 @@ s,%\([0-9]*\)לד,%\1ld,g s,%\([0-9]*\)ללד,%\1lld,g s,%\([0-9\.\*]*\)ש,%\1s,g -s,%\([0-9\.\*]*\)מ,%\1m,g s,%\([0-9]*\)לוּ,%\1lu,g s,%\([0-9]*\)וּ,%\1u,g s,%\([0-9]*\)ללוּ,%\1llu,g diff --git a/tests/ahci_test.in b/tests/ahci_test.in index 7df560462..e7d26ac07 100644 --- a/tests/ahci_test.in +++ b/tests/ahci_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mips*-arc | mips*-qemu_mips) exit 0;; # FIXME: No native drivers are available for those - powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + powerpc-ieee1275 | sparc64-ieee1275) exit 0;; esac diff --git a/tests/btrfs_test.in b/tests/btrfs_test.in index 0c9bf3a68..c55d9477f 100644 --- a/tests/btrfs_test.in +++ b/tests/btrfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e @@ -18,7 +18,6 @@ fi "@builddir@/grub-fs-tester" btrfs "@builddir@/grub-fs-tester" btrfs_zlib "@builddir@/grub-fs-tester" btrfs_lzo -"@builddir@/grub-fs-tester" btrfs_zstd "@builddir@/grub-fs-tester" btrfs_raid0 "@builddir@/grub-fs-tester" btrfs_raid1 "@builddir@/grub-fs-tester" btrfs_single diff --git a/tests/cdboot_test.in b/tests/cdboot_test.in index 75acdfedb..1cc901977 100644 --- a/tests/cdboot_test.in +++ b/tests/cdboot_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify diff --git a/tests/core_compress_test.in b/tests/core_compress_test.in index 9d216ebcf..1003587cc 100644 --- a/tests/core_compress_test.in +++ b/tests/core_compress_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify diff --git a/tests/cpio_test.in b/tests/cpio_test.in index 5742cf17b..0b09db549 100644 --- a/tests/cpio_test.in +++ b/tests/cpio_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/ehci_test.in b/tests/ehci_test.in index b197f8cdc..5cfe726df 100644 --- a/tests/ehci_test.in +++ b/tests/ehci_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mips*-arc | mips*-qemu_mips) exit 0;; # FIXME: No native drivers are available for those - powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + powerpc-ieee1275 | sparc64-ieee1275) exit 0;; esac diff --git a/tests/example_scripted_test.in b/tests/example_scripted_test.in index 783b7f138..09633e893 100644 --- a/tests/example_scripted_test.in +++ b/tests/example_scripted_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e true diff --git a/tests/exfat_test.in b/tests/exfat_test.in index cd3cd4cb2..fc1a0fe5e 100644 --- a/tests/exfat_test.in +++ b/tests/exfat_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/ext234_test.in b/tests/ext234_test.in index 4f1eb527e..8910b716f 100644 --- a/tests/ext234_test.in +++ b/tests/ext234_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e @@ -29,5 +29,3 @@ fi "@builddir@/grub-fs-tester" ext2 "@builddir@/grub-fs-tester" ext3 "@builddir@/grub-fs-tester" ext4 -"@builddir@/grub-fs-tester" ext4_metabg -"@builddir@/grub-fs-tester" ext4_encrypt diff --git a/tests/f2fs_test.in b/tests/f2fs_test.in deleted file mode 100644 index 1ea77c826..000000000 --- a/tests/f2fs_test.in +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -e - -if [ "x$EUID" = "x" ] ; then - EUID=`id -u` -fi - -if [ "$EUID" != 0 ] ; then - exit 77 -fi - -if ! which mkfs.f2fs >/dev/null 2>&1; then - echo "mkfs.f2fs not installed; cannot test f2fs." - exit 77 -fi - - -"@builddir@/grub-fs-tester" f2fs diff --git a/tests/fat_test.in b/tests/fat_test.in index b6b4748ca..1d132b517 100644 --- a/tests/fat_test.in +++ b/tests/fat_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/fddboot_test.in b/tests/fddboot_test.in index 2d7dfc889..a05eb3e75 100644 --- a/tests/fddboot_test.in +++ b/tests/fddboot_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -46,6 +46,6 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in exit 0;; esac -if [ "$(echo hello | "${grubshell}" --boot=fd --mkrescue-arg="--compress=xz --fonts= --locales= --themes= -no-pad")" != "Hello World" ]; then +if [ "$(echo hello | "${grubshell}" --boot=fd --mkrescue-arg="--compress=xz --fonts= --locales= --themes=")" != "Hello World" ]; then exit 1 fi diff --git a/tests/file_filter/file b/tests/file_filter/file deleted file mode 100644 index 64650ac58..000000000 --- a/tests/file_filter/file +++ /dev/null @@ -1 +0,0 @@ -Hello, user! diff --git a/tests/file_filter_test.in b/tests/file_filter_test.in index ed6abcb5a..8909e4021 100644 --- a/tests/file_filter_test.in +++ b/tests/file_filter_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2014 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -19,7 +19,7 @@ grubshell=@builddir@/grub-shell . "@builddir@/grub-core/modinfo.sh" -filters="gzio xzio lzopio pgp" +filters="gzio xzio lzopio verify" modules="cat mpi" for mod in $(cut -d ' ' -f 2 "@builddir@/grub-core/crypto.lst" | sort -u); do diff --git a/tests/gettext_strings_test.in b/tests/gettext_strings_test.in index 813999ebe..5c305e75b 100644 --- a/tests/gettext_strings_test.in +++ b/tests/gettext_strings_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh cd '@srcdir@' diff --git a/tests/grub_cmd_date.in b/tests/grub_cmd_date.in index f7c9ca004..a459353e8 100644 --- a/tests/grub_cmd_date.in +++ b/tests/grub_cmd_date.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash set -e . "@builddir@/grub-core/modinfo.sh" @@ -9,7 +9,7 @@ if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = sparc64-ieee1275 ]; fi pdt="$(date -u +%s)" -dt=`echo date | @builddir@/grub-shell | sed 's, [A-Z][a-z]*$,,'` +dt=`echo date | @builddir@/grub-shell` dtg="$(date -u -d "$dt" +%s)" ndt="$(date -u +%s)" diff --git a/tests/grub_cmd_regexp.in b/tests/grub_cmd_regexp.in index 6520bd6d7..e7e625701 100644 --- a/tests/grub_cmd_regexp.in +++ b/tests/grub_cmd_regexp.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash set -e # Run GRUB script in a Qemu instance diff --git a/tests/grub_cmd_set_date.in b/tests/grub_cmd_set_date.in index aac120a6c..c594ae3fc 100644 --- a/tests/grub_cmd_set_date.in +++ b/tests/grub_cmd_set_date.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash set -e . "@builddir@/grub-core/modinfo.sh" diff --git a/tests/grub_cmd_sleep.in b/tests/grub_cmd_sleep.in index 8797f6632..1c84fbfbb 100644 --- a/tests/grub_cmd_sleep.in +++ b/tests/grub_cmd_sleep.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash set -e . "@builddir@/grub-core/modinfo.sh" @@ -11,13 +11,8 @@ fi # Compare RTC with interval timer. # Not 100% proper but should check that timer is running ok dt=`echo 'date; sleep 10; date' | @builddir@/grub-shell` -dt1="$(date -u -d "$(echo "$dt" | head -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)" -dt2="$(date -u -d "$(echo "$dt" | tail -n 1 | sed 's, [A-Z][a-z]*$,,')" +%s)" - -# Ignore QEMU bug -if [ "${grub_modinfo_target_cpu}" = arm ] && [ $((dt2 - dt1)) -ge 15 ] && [ $((dt2 - dt1)) -le 17 ]; then - exit 0; -fi +dt1="$(date -u -d "$(echo "$dt" | head -n 1)" +%s)" +dt2="$(date -u -d "$(echo "$dt" | tail -n 1)" +%s)" if [ $((dt2 - dt1)) -gt 11 ] || [ $((dt2 - dt1)) -lt 9 ]; then echo "Interval not in range $dt2-$dt1 != 10" diff --git a/tests/grub_cmd_test.in b/tests/grub_cmd_test.in deleted file mode 100644 index 3399eb292..000000000 --- a/tests/grub_cmd_test.in +++ /dev/null @@ -1,67 +0,0 @@ -#! @BUILD_SHEBANG@ - -# create a randome file -empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 -non_empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 -cat >$non_empty <$outfile < /dev/null 2>&1; then - echo "GRUB test command file tests failed." - cat "$outfile" - exit 1 -else - rm -f "${outfile}" - exit 0 -fi diff --git a/tests/grub_cmd_tr.in b/tests/grub_cmd_tr.in index bed469c03..3fb15e35c 100644 --- a/tests/grub_cmd_tr.in +++ b/tests/grub_cmd_tr.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ -e +#! /bin/bash -e # Run GRUB script in a Qemu instance # Copyright (C) 2010 Free Software Foundation, Inc. diff --git a/tests/grub_func_test.in b/tests/grub_func_test.in index c67f9e422..c8cc26376 100644 --- a/tests/grub_func_test.in +++ b/tests/grub_func_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash set -e . "@builddir@/grub-core/modinfo.sh" diff --git a/tests/grub_script_blanklines.in b/tests/grub_script_blanklines.in index bd8735491..89ed763d3 100644 --- a/tests/grub_script_blanklines.in +++ b/tests/grub_script_blanklines.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e @builddir@/grub-script-check </dev/null 2>&1; then fi if ! mkfs.minix -h | grep -- -v > /dev/null; then - echo "mkfs.minix doesn't support minix2fs; cannot test minix*fs." - exit 77 -fi - -if ! mkfs.minix -h | grep -- -3 > /dev/null; then echo "mkfs.minix doesn't support minix3fs; cannot test minix*fs." exit 77 fi -if ! mkfs.minix -h | grep -- -B > /dev/null; then - echo "mkfs.minix doesn't support variable block size; cannot test minix*fs." - exit 77 -fi - "@builddir@/grub-fs-tester" minix "@builddir@/grub-fs-tester" minix2 "@builddir@/grub-fs-tester" minix3 diff --git a/tests/netboot_test.in b/tests/netboot_test.in index 9f71e3d88..c757023d9 100644 --- a/tests/netboot_test.in +++ b/tests/netboot_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify diff --git a/tests/nilfs2_test.in b/tests/nilfs2_test.in index ad44d5b33..780b60ec1 100644 --- a/tests/nilfs2_test.in +++ b/tests/nilfs2_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/ntfs_test.in b/tests/ntfs_test.in index 9eb7b01f6..6bf09e691 100644 --- a/tests/ntfs_test.in +++ b/tests/ntfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e @@ -15,10 +15,5 @@ if ! which mkfs.ntfs >/dev/null 2>&1; then exit 77 fi -if ! which setfattr >/dev/null 2>&1; then - echo "setfattr not installed; cannot test ntfs." - exit 77 -fi - "@builddir@/grub-fs-tester" ntfs -"@builddir@/grub-fs-tester" ntfscomp +"@builddir@/grub-fs-tester" ntfscomp \ No newline at end of file diff --git a/tests/ohci_test.in b/tests/ohci_test.in index 8693f8c47..f841bd25c 100644 --- a/tests/ohci_test.in +++ b/tests/ohci_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mips*-arc | mips*-qemu_mips) exit 0;; # FIXME: No native drivers are available for those - powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + powerpc-ieee1275 | sparc64-ieee1275) exit 0;; esac diff --git a/tests/partmap_test.in b/tests/partmap_test.in index 6ef518b0a..7786ccfbc 100644 --- a/tests/partmap_test.in +++ b/tests/partmap_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e # Copyright (C) 2010 Free Software Foundation, Inc. @@ -88,19 +88,10 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mipsel-arc) disk=arc/scsi0/disk0/rdisk0 ;; - arm*-efi) - disk=hd3 - ;; *) disk=hd0 ;; esac - -if ! which parted >/dev/null 2>&1; then - echo "parted not installed; cannot test partmap" - exit 77 -fi - imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 diff --git a/tests/pata_test.in b/tests/pata_test.in index 4b18fdef3..07d17b781 100644 --- a/tests/pata_test.in +++ b/tests/pata_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in *-arc) exit 0;; # FIXME: No native drivers are available for those - powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + powerpc-ieee1275 | sparc64-ieee1275) exit 0;; i386-ieee1275) disk=hdb diff --git a/tests/printf_unit_test.c b/tests/printf_unit_test.c index 098c29fd9..eb76bd002 100644 --- a/tests/printf_unit_test.c +++ b/tests/printf_unit_test.c @@ -23,10 +23,6 @@ #define MSG "printf test failed: %s, %s", real, expected -#if defined(__GNUC__) && __GNUC__ >= 7 -#pragma GCC diagnostic ignored "-Wformat-truncation=" -#endif - static void printf_test (void) { @@ -70,9 +66,6 @@ printf_test (void) grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3); snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3); grub_test_assert (strcmp (real, expected) == 0, MSG); - grub_snprintf (real, sizeof (real), "%%0%dd ", 1); - snprintf (expected, sizeof (expected), "%%0%dd ", 1); - grub_test_assert (strcmp (real, expected) == 0, MSG); } GRUB_UNIT_TEST ("printf_unit_test", printf_test); diff --git a/tests/pseries_test.in b/tests/pseries_test.in index 655eb4f3a..226494593 100644 --- a/tests/pseries_test.in +++ b/tests/pseries_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify diff --git a/tests/reiserfs_test.in b/tests/reiserfs_test.in index b5fed7635..678efe7b3 100644 --- a/tests/reiserfs_test.in +++ b/tests/reiserfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/romfs_test.in b/tests/romfs_test.in index 98bb50c32..83e09315a 100644 --- a/tests/romfs_test.in +++ b/tests/romfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/squashfs_test.in b/tests/squashfs_test.in index 2f044f95d..ec34e0108 100644 --- a/tests/squashfs_test.in +++ b/tests/squashfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg b/tests/syslinux/ubuntu10.04/isolinux/adtxt.cfg deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg b/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg deleted file mode 100644 index 2e107fade..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/dtmenu.cfg +++ /dev/null @@ -1,52 +0,0 @@ -menu hshift 9 -menu width 58 - -menu begin desktop - include stdmenu.cfg - menu hshift 13 - menu width 49 - menu label Alternative desktop environments - menu title Desktop environment menu - label mainmenu-kde - menu label ^Back.. - text help - Higher level options install the GNOME desktop environment - endtext - menu exit - menu begin kde-desktop - include stdmenu.cfg - menu label ^KDE - menu title KDE desktop boot menu - text help - Select the 'K Desktop Environment' for the Desktop task - endtext - label mainmenu-kde - menu label ^Back.. - menu exit - include kde/menu.cfg - menu end - menu begin lxde-desktop - include stdmenu.cfg - menu label ^LXDE - menu title LXDE desktop boot menu - text help - Select the 'Lightweight X11 Desktop Environment' for the Desktop task - endtext - label mainmenu-lxde - menu label ^Back.. - menu exit - include lxde/menu.cfg - menu end - menu begin xfce-desktop - include stdmenu.cfg - menu label ^Xfce - menu title Xfce desktop boot menu - text help - Select the 'Xfce lightweight desktop environment' for the Desktop task - endtext - label mainmenu-xfce - menu label ^Back.. - menu exit - include xfce/menu.cfg - menu end -menu end diff --git a/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg b/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg deleted file mode 100644 index 3119e654a..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/exithelp.cfg +++ /dev/null @@ -1,3 +0,0 @@ -label menu - kernel vesamenu.c32 - config isolinux.cfg diff --git a/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg b/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg deleted file mode 100644 index b799cb5cb..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/gfxboot.cfg +++ /dev/null @@ -1,12 +0,0 @@ -foreground=0xFFFFFF -background=0x958490 -screen-colour=0x270A1E -hidden-timeout=2 -label normal=Normal -append normal= -label driverupdates=Use driver update disc -append driverupdates=debian-installer/driver-update=true -applies driverupdates=live live-install -label oem=OEM install (for manufacturers) -append oem=oem-config/enable=true -applies oem=live live-install install diff --git a/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg b/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg deleted file mode 100644 index fd9c333b2..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg +++ /dev/null @@ -1,6 +0,0 @@ -# D-I config version 2.0 -include menu.cfg -default vesamenu.c32 -prompt 0 -timeout 50 -ui gfxboot bootlogo diff --git a/tests/syslinux/ubuntu10.04/isolinux/menu.cfg b/tests/syslinux/ubuntu10.04/isolinux/menu.cfg deleted file mode 100644 index 9f5607dea..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/menu.cfg +++ /dev/null @@ -1,23 +0,0 @@ -menu hshift 13 -menu width 49 -menu margin 8 - -menu title Installer boot menu -include stdmenu.cfg -include txt.cfg -include gtk.cfg -menu begin advanced - menu title Advanced options - include stdmenu.cfg - label mainmenu - menu label ^Back.. - menu exit - include adtxt.cfg - include adgtk.cfg -menu end -label help - menu label ^Help - text help - Display help screens; type 'menu' at boot prompt to return to this menu - endtext - config prompt.cfg diff --git a/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg b/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg deleted file mode 100644 index 75f67881c..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/po4a.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[po4a_langs] ar bn ca cs da de es eu fi fr gl hu id it ja ka ko ku lv nb nl pl pt pt_BR ru sk sv ta tr vi zh_CN zh_TW -[po4a_paths] po/help.pot $lang:po/$lang.po -[type:docbook] help.xml diff --git a/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg b/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg deleted file mode 100644 index f9984aedc..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg +++ /dev/null @@ -1,16 +0,0 @@ -prompt 1 -display f1.txt -timeout 50 -include menu.cfg -include exithelp.cfg - -f1 f1.txt -f2 f2.txt -f3 f3.txt -f4 f4.txt -f5 f5.txt -f6 f6.txt -f7 f7.txt -f8 f8.txt -f9 f9.txt -f0 f10.txt diff --git a/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg b/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg deleted file mode 100644 index bdf6231ae..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/rqtxt.cfg +++ /dev/null @@ -1,4 +0,0 @@ -label rescue - menu label ^Rescue mode - kernel /install/vmlinuz - append vga=788 initrd=/install/initrd.gz rescue/enable=true -- quiet diff --git a/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg b/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg deleted file mode 100644 index 671b16f78..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/stdmenu.cfg +++ /dev/null @@ -1,15 +0,0 @@ -menu background splash.png -menu color title * #FFFFFFFF * -menu color border * #00000000 #00000000 none -menu color sel * #ffffffff #76a1d0ff * -menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff * -menu color tabmsg * #ffffffff #00000000 * -menu color help 37;40 #ffdddd00 #00000000 none -menu vshift 12 -menu rows 10 -menu helpmsgrow 15 -# The command line must be at least one line from the bottom. -menu cmdlinerow 16 -menu timeoutrow 16 -menu tabmsgrow 18 -menu tabmsg Press ENTER to boot or TAB to edit a menu entry diff --git a/tests/syslinux/ubuntu10.04/isolinux/txt.cfg b/tests/syslinux/ubuntu10.04/isolinux/txt.cfg deleted file mode 100644 index 860daad80..000000000 --- a/tests/syslinux/ubuntu10.04/isolinux/txt.cfg +++ /dev/null @@ -1,19 +0,0 @@ -default live -label live - menu label ^Try Ubuntu without installing - kernel /casper/vmlinuz - append file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- -label live-install - menu label ^Install Ubuntu - kernel /casper/vmlinuz - append file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- -label check - menu label ^Check disc for defects - kernel /casper/vmlinuz - append boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- -label memtest - menu label Test ^memory - kernel /install/mt86plus -label hd - menu label ^Boot from first hard disk - localboot 0x80 diff --git a/tests/syslinux/ubuntu10.04_grub.cfg.in b/tests/syslinux/ubuntu10.04_grub.cfg.in deleted file mode 100644 index 441dec045..000000000 --- a/tests/syslinux/ubuntu10.04_grub.cfg.in +++ /dev/null @@ -1,236 +0,0 @@ - background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux'/'splash.png' -# D-I config version 2.0 - # UNSUPPORTED command 'menu hshift 13' - # UNSUPPORTED command 'menu width 49' - # UNSUPPORTED command 'menu margin 8' - - # UNSUPPORTED command 'menu title Installer boot menu' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' -set timeout=5 - default='vesamenu.c32' -menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Test memory' --hotkey 'm' --id 'memtest' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/install/mt86plus' -} -menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/gtk.cfg not found - # UNSUPPORTED command 'menu begin advanced' - # UNSUPPORTED command 'menu title Advanced options' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' - root=hd0; - chainloader +1; -} -menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { - # UNSUPPORTED command 'menu exit' -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/adgtk.cfg not found - # UNSUPPORTED command 'menu end' - # UNSUPPORTED entry type 0 -true; -} -menuentry 'Help' --hotkey 'h' --id 'help' { - # UNSUPPORTED command 'ui gfxboot bootlogo' -#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: - background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'splash.png' - # UNSUPPORTED command 'display f1.txt' - # UNSUPPORTED command 'menu hshift 13' - # UNSUPPORTED command 'menu width 49' - # UNSUPPORTED command 'menu margin 8' - - # UNSUPPORTED command 'menu title Installer boot menu' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' -set timeout=5 - default='live' -menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Test memory' --hotkey 'm' --id 'memtest' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/install/mt86plus' -} -menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//gtk.cfg not found - # UNSUPPORTED command 'menu begin advanced' - # UNSUPPORTED command 'menu title Advanced options' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' - root=hd0; - chainloader +1; -} -menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { - # UNSUPPORTED command 'menu exit' -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//adgtk.cfg not found - # UNSUPPORTED command 'menu end' - # UNSUPPORTED entry type 0 -true; -} -menuentry 'Help' --hotkey 'h' --id 'help' { -#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: - syslinux_configfile -r '/'/'/' -c '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'' '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'prompt.cfg' -} -menuentry 'menu' --id 'menu' { - # UNSUPPORTED command 'f1 f1.txt' - # UNSUPPORTED command 'f2 f2.txt' - # UNSUPPORTED command 'f3 f3.txt' - # UNSUPPORTED command 'f4 f4.txt' - # UNSUPPORTED command 'f5 f5.txt' - # UNSUPPORTED command 'f6 f6.txt' - # UNSUPPORTED command 'f7 f7.txt' - # UNSUPPORTED command 'f8 f8.txt' - # UNSUPPORTED command 'f9 f9.txt' - # UNSUPPORTED command 'f0 f10.txt' -#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/'/'isolinux.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg: - background_image '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'splash.png' -# D-I config version 2.0 - # UNSUPPORTED command 'menu hshift 13' - # UNSUPPORTED command 'menu width 49' - # UNSUPPORTED command 'menu margin 8' - - # UNSUPPORTED command 'menu title Installer boot menu' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' -set timeout=5 - default='vesamenu.c32' -menuentry 'Try Ubuntu without installing' --hotkey 't' --id 'live' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Install Ubuntu' --hotkey 'i' --id 'live-install' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Check disc for defects' --hotkey 'c' --id 'check' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/casper/vmlinuz' boot=casper integrity-check initrd=/casper/initrd.lz quiet splash -- - initrd$linux_suffix '/'/'/casper/initrd.lz' -} -menuentry 'Test memory' --hotkey 'm' --id 'memtest' { - if test x$grub_platform = xpc; then linux_suffix=16; else linux_suffix= ; fi - linux$linux_suffix '/'/'/install/mt86plus' -} -menuentry 'Boot from first hard disk' --hotkey 'b' --id 'hd' { -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux///gtk.cfg not found - # UNSUPPORTED command 'menu begin advanced' - # UNSUPPORTED command 'menu title Advanced options' - # UNSUPPORTED command 'menu color title * #FFFFFFFF *' - # UNSUPPORTED command 'menu color border * #00000000 #00000000 none' - # UNSUPPORTED command 'menu color sel * #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color hotsel 1;7;37;40 #ffffffff #76a1d0ff *' - # UNSUPPORTED command 'menu color tabmsg * #ffffffff #00000000 *' - # UNSUPPORTED command 'menu color help 37;40 #ffdddd00 #00000000 none' - # UNSUPPORTED command 'menu vshift 12' - # UNSUPPORTED command 'menu rows 10' - # UNSUPPORTED command 'menu helpmsgrow 15' -# The command line must be at least one line from the bottom. - # UNSUPPORTED command 'menu cmdlinerow 16' - # UNSUPPORTED command 'menu timeoutrow 16' - # UNSUPPORTED command 'menu tabmsgrow 18' - # UNSUPPORTED command 'menu tabmsg Press ENTER to boot or TAB to edit a menu entry' - root=hd0; - chainloader +1; -} -menuentry 'Back..' --hotkey 'b' --id 'mainmenu' { - # UNSUPPORTED command 'menu exit' -# File (host)/@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux///adgtk.cfg not found - # UNSUPPORTED command 'menu end' - # UNSUPPORTED entry type 0 -true; -} -menuentry 'Help' --hotkey 'h' --id 'help' { - # UNSUPPORTED command 'ui gfxboot bootlogo' -#'@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'prompt.cfg' (host)@simplified_abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/prompt.cfg: - syslinux_configfile -r '/'/'/' -c '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'' '@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux//'/'prompt.cfg' -} -} -} diff --git a/tests/syslinux_test.in b/tests/syslinux_test.in deleted file mode 100644 index 4ea86390e..000000000 --- a/tests/syslinux_test.in +++ /dev/null @@ -1,16 +0,0 @@ -#!@BUILD_SHEBANG@ - -set -e - -outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 - -"@builddir@/grub-syslinux2cfg" -r "@abs_top_srcdir@/tests/syslinux/ubuntu10.04" "@abs_top_srcdir@/tests/syslinux/ubuntu10.04/isolinux/isolinux.cfg" -o "$outfile" - -echo "$outfile" - -if ! diff -u "$outfile" "@builddir@/tests/syslinux/ubuntu10.04_grub.cfg"; then - echo "Mismatch in ubuntu10.04" - exit 1; -fi - -exit 0 diff --git a/tests/tar_test.in b/tests/tar_test.in index 6e2f2de8b..46ba3bce2 100644 --- a/tests/tar_test.in +++ b/tests/tar_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/test_sha512sum.in b/tests/test_sha512sum.in index 027092a8b..524c1d1c0 100644 --- a/tests/test_sha512sum.in +++ b/tests/test_sha512sum.in @@ -1,7 +1,7 @@ -#! @BUILD_SHEBANG@ +#! /bin/bash # create a randome file -file="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 +file=`mktemp` cat >$file <$outfile1 <$outfile2 SHA1=`cat $outfile1 | tr -d '\n' | cut -f1 -d\ ` diff --git a/tests/udf_test.in b/tests/udf_test.in index fb92f0173..fe244e2bd 100644 --- a/tests/udf_test.in +++ b/tests/udf_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/tests/uhci_test.in b/tests/uhci_test.in index f0eec5032..3dea51c01 100644 --- a/tests/uhci_test.in +++ b/tests/uhci_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mips*-arc | mips*-qemu_mips) exit 0;; # FIXME: No native drivers are available for those - powerpc-ieee1275 | sparc64-ieee1275 | arm*-efi) + powerpc-ieee1275 | sparc64-ieee1275) exit 0;; esac @@ -41,7 +41,7 @@ echo "hello" > "$outfile" tar cf "$imgfile" "$outfile" -if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device ich9-usb-uhci1 -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then +if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-usb -usbdevice disk:$imgfile" | tail -n 1)" != "Hello World" ]; then rm "$imgfile" rm "$outfile" exit 1 diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in index bfc425e1f..565692725 100644 --- a/tests/util/grub-fs-tester.in +++ b/tests/util/grub-fs-tester.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/bash set -e @@ -10,32 +10,11 @@ tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 # This wrapper is to ease insertion of valgrind or time statistics run_it () { - LC_ALL=C "$GRUBFSTEST" "$@" -} - -range() { - range_counter="$1" - while test "$range_counter" -le "$2"; do - echo "$range_counter" - range_counter="$((range_counter + $3))" - done -} - -powrange() { - range_counter="$1" - while test "$range_counter" -le "$2"; do - echo "$range_counter" - range_counter="$((range_counter * 2))" - done + "$GRUBFSTEST" "$@" } run_grubfstest () { - need_images= - for i in $(range 0 $((NEED_IMAGES_N-1)) 1); do - need_images="$need_images $FSIMAGEP${i}.img"; - done - - run_it -c $NEED_IMAGES_N $need_images "$@" + run_it -c $NEED_IMAGES_N "${NEED_IMAGES[@]}" "$@" } # OS LIMITATION: GNU/Linux has no AFS support, so we use a premade image and a reference tar file. I.a. no multiblocksize test @@ -61,10 +40,6 @@ case x"$fs" in MINLOGSECSIZE=9 # OS LIMITATION: GNU/Linux doesn't accept > 4096 MAXLOGSECSIZE=12;; - xxfs_crc) - MINLOGSECSIZE=9 - # OS LIMITATION: GNU/Linux doesn't accept > 1024 - MAXLOGSECSIZE=10;; xzfs*) # OS LIMITATION: zfs-fuse hangs when creating zpool with sectors <=256B. MINLOGSECSIZE=9 @@ -72,7 +47,7 @@ case x"$fs" in # OS limitation: zfs-fuse always uses ashift=9 with loop devices MAXLOGSECSIZE=9;; esac -for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do +for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE + 1)); do SECSIZE="$((1 << LOGSECSIZE))" MINBLKSIZE=512 MAXBLKSIZE=512 @@ -106,10 +81,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MAXBLKSIZE=1048576 ;; xnilfs2) - # nilfs2 supports blocksizes from 1024 to 4096 - # but non-4096 results in kernel oops in some cases, - # avoid it. - MINBLKSIZE=4096 + MINBLKSIZE=1024 MAXBLKSIZE=4096 ;; xsfs*) @@ -130,7 +102,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do # OS LIMITATION: Linux oopses with >=32768K MAXBLKSIZE=$((16384*1024)) ;; - x"lvm_raid1"* | x"lvm_raid4" | x"lvm_raid5" | x"lvm_raid6") + x"lvm_raid4" | x"lvm_raid5" | x"lvm_raid6") # OS LIMITATION: Linux crashes with less than 16384 MINBLKSIZE=16384 # Could go further but what's the point? @@ -156,12 +128,6 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do # Could go further but what's the point? MAXBLKSIZE=$((65536*1024)) ;; - xext4_encrypt) - # OS LIMITATION: Linux currently only allows the 'encrypt' feature - # in combination with block_size = PAGE_SIZE (4096 bytes on x86). - MINBLKSIZE=$(getconf PAGE_SIZE) - MAXBLKSIZE=$MINBLKSIZE - ;; xext*) MINBLKSIZE=1024 if [ $MINBLKSIZE -lt $SECSIZE ]; then @@ -172,14 +138,10 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do xsquash*) MINBLKSIZE=4096 MAXBLKSIZE=1048576;; - xxfs|xf2fs) + xxfs) MINBLKSIZE=$SECSIZE # OS Limitation: GNU/Linux doesn't accept > 4096 MAXBLKSIZE=4096;; - xxfs_crc) - # OS Limitation: GNU/Linux doesn't accept != 1024 - MINBLKSIZE=1024 - MAXBLKSIZE=1024;; xudf) MINBLKSIZE=1024 MAXBLKSIZE=4096;; @@ -196,12 +158,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MINBLKSIZE=1024 MAXBLKSIZE=4096;; esac - if test "$BLKSTEP" -eq 0; then - blksizes="$(powrange "$MINBLKSIZE" "$MAXBLKSIZE")" - else - blksizes="$(range "$MINBLKSIZE" "$MAXBLKSIZE" "$BLKSTEP")" - fi - for BLKSIZE in $blksizes; do + for ((BLKSIZE=MINBLKSIZE;BLKSIZE<=MAXBLKSIZE;BLKSIZE=BLKSTEP?BLKSIZE+BLKSTEP:2*BLKSIZE)); do MAXDEVICES=1 MINDEVICES=1 export fs @@ -209,7 +166,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do x"zfs_raidz" | x"zfs_stripe" | x"zfs_mirror" | xbtrfs_raid0 \ | xbtrfs_raid1 | x"mdraid"*"_raid4" | x"mdraid"*"_raid5" \ | x"mdraid"*"_linear" \ - | x"mdraid"*"_raid10" | xlvm_raid1* | xlvm_mirror1 | xlvm_mirrorall) + | x"mdraid"*"_raid10" | xlvm_mirror1 | xlvm_mirrorall) MINDEVICES=2 MAXDEVICES=7 ;; @@ -231,16 +188,18 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MAXDEVICES=7;; esac - for NDEVICES in $(range "$MINDEVICES" "$MAXDEVICES" 1); do + for ((NDEVICES=MINDEVICES; NDEVICES <= MAXDEVICES; NDEVICES++)); do export NDEVICES - unset FSIMAGEP - FSIMAGEP="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_" - export FSIMAGEP + unset FSIMAGES + for ((i=0; i < NDEVICES; i++)); do + FSIMAGES[i]="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_$i.img" + done + export FSIMAGES unset NEED_IMAGES; case x$fs in # RAID 1 has to work with even one device of the set. - xzfs_mirror | x"mdraid"*"_raid1" | xlvm_mirrorall | xlvm_raid1all) + xzfs_mirror | x"mdraid"*"_raid1" | xlvm_mirrorall) NEED_IMAGES_N=1;; # Degrade raidz by removing 3 devices xzfs_raidz3) @@ -251,12 +210,16 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do # Degrade raidz and btrfs RAID1 by removing one device xbtrfs_raid1 | xbtrfs_raid10 | xzfs_raidz | x"mdraid"*"_raid4" \ | x"mdraid"*"_raid5" | x"mdraid"*"_raid10" | xlvm_mirror1 \ - | x"lvm_raid1" | x"lvm_raid4" | x"lvm_raid5") + | x"lvm_raid4" | x"lvm_raid5") NEED_IMAGES_N=$((NDEVICES-1));; *) NEED_IMAGES_N=$NDEVICES;; esac + for ((i=0;i < NEED_IMAGES_N; i++)); do + NEED_IMAGES[i]="${FSIMAGES[i]}"; + done export NEED_IMAGES_N + export NEED_IMAGES MNTPOINTRO="${tempdir}/${fs}_ro" MNTPOINTRW="${tempdir}/${fs}_rw" @@ -264,28 +227,23 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MOUNTFS="$fs" MASTER="${tempdir}/master" FSLABEL="grub_;/testé莭ð¯¦ð¯¦™ðŸ˜ÐºÐ¸Ñ€Ð¸Ñ‚i urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfew" - CFILESRC= - for cand in /usr/share/dict/american-english /usr/share/dict/linux.words /data/data/com.termux/files/usr/share/hunspell/en_US.dic; do - if test -f "$cand" ; then - CFILESRC="$cand" - break - fi - done - if test "$CFILESRC" = "" ; then - echo "Couldn't find compressible file" >&2 - exit 1 + CFILESN=1 + if test -f /usr/share/dict/american-english; then + CFILESSRC[0]="/usr/share/dict/american-english" + else + CFILESSRC[0]="/usr/share/dict/linux.words" fi case x"$fs" in # FS LIMITATION: 8.3 names xmsdos*) - CFILE="american.eng";; + CFILES[0]="american.eng";; xiso9660) - CFILE="american_english";; + CFILES[0]="american_english";; *) - CFILE="american-english";; + CFILES[0]="american-english";; esac # OS LIMITATION: Limited by NAME_MAX (usually 255) in GNU/Linux - LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoi" + LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoirewoifoiwqwoieqfrqwioerijewr" rm -rf "$MASTER" case x"$fs" in @@ -297,11 +255,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do ;; # FS LIMITATION: btrfs label is at most 255 UTF-8 chars x"btrfs"*) - FSLABEL="grub_;/testé莭ð¯¦ðŸ˜ÐºÐ¸Ñ€Ð¸Ñ‚i urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoi";; - - # FS LIMITATION: f2fs label is at most 512 UTF-16 chars - x"f2fs") - FSLABEL="grub_;/testéäŒä“ä•киритiurewfceniuewruewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoirvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoircreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq";; + FSLABEL="grub_;/testé莭ð¯¦ðŸ˜ÐºÐ¸Ñ€Ð¸Ñ‚i urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoif";; # FS LIMITATION: exfat is at most 15 UTF-16 chars x"exfat") @@ -327,13 +281,13 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do #FSLABEL="g;/_é莭ð¯¦ðŸ˜ÐºÐ¸Ñ‚ u" ;; # FS LIMITATION: reiserfs, extN and jfs label is at most 16 UTF-8 characters - x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"mdraid"* | x"jfs" | x"jfs_caseins") + x"reiserfs_old" | x"reiserfs" | x"ext2" | xext2_old | x"ext3" | x"ext4" | x"lvm"* | x"mdraid"* | x"jfs" | x"jfs_caseins") FSLABEL="g;/éт 莭ðŸ˜";; # FS LIMITATION: No underscore, space, semicolon, slash or international characters in UFS* in label. Limited to 32 UTF-8 characters x"ufs1" | x"ufs1_sun" | x"ufs2") FSLABEL="grubtest""ieurrucnenreeiurueurewf";; # FS LIMITATION: XFS label is at most 12 UTF-8 characters - x"xfs"|x"xfs_crc") + x"xfs") FSLABEL="géт ðŸ˜Ðº";; # FS LIMITATION: FAT labels limited to 11 characters, no international characters or lowercase x"vfat"* | xmsdos*) @@ -423,8 +377,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do ;; x"vfat16" | xmsdos16) BIGBLOCKCNT=$((25000 * BLKSIZE)) - if [ $BIGBLOCKCNT -gt 4294967295 ]; then - BIGBLOCKCNT=4294967295 + if [ $BIGBLOCKCNT -gt $((16#ffffffff)) ]; then + BIGBLOCKCNT=$((16#ffffffff)) fi ;; x"minix") @@ -445,7 +399,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do BIGBLOCKCNT=$((4000 * 1048576));; # FS LIMITATION: These FS have uint32 as file size field x"vfat"* | xmsdos* | x"cpio_crc" | x"cpio_newc" | x"cpio_bin" | x"cpio_hpbin" | xsfs*) - BIGBLOCKCNT=4294967295;; + BIGBLOCKCNT=$((16#ffffffff));; # FS LIMITATION: These FS have int32 as file size field # FIXME: not so sure about AFFS # OS LIMITATION: minix2/minix3 could be formatted in a way to permit more. @@ -511,8 +465,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do case x"$fs" in # FIXME: Not sure about BtrFS, NTFS, JFS, AFS, UDF and SFS. Check it. # FS LIMITATION: as far as I know those FS don't store their last modification date. - x"jfs_caseins" | x"jfs" | x"xfs" | x"xfs_crc" | x"btrfs"* | x"reiserfs_old" | x"reiserfs" \ - | x"bfs" | x"afs" | x"f2fs" \ + x"jfs_caseins" | x"jfs" | x"xfs"| x"btrfs"* | x"reiserfs_old" | x"reiserfs" \ + | x"bfs" | x"afs" \ | x"tarfs" | x"cpio_"* | x"minix" | x"minix2" \ | x"minix3" | x"ntfs"* | x"udf" | x"sfs"*) NOFSTIME=y;; @@ -536,8 +490,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do NOFSLABEL=y;; esac - PDIRCOMPNUM=210 - PDIR2COMPNUM=210 + PDIRCOMPNUM=220 + PDIR2COMPNUM=220 case x$fs in # OS LIMITATION: bfs_fuse bugs beyond that @@ -552,7 +506,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do # FS LIMITATION: at most 255 on path length # FS LIMITATION: at most 100 on symlink length xcpio_ustar) - PDIRCOMPNUM=84 + PDIRCOMPNUM=85 PDIR2COMPNUM=30;; # OS LIMITATION: Linux supports only symlink at most one block long on reiserfs xreiserfs | xreiserfs_old) @@ -578,18 +532,18 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do PDIR="" # OS LIMITATION: Limited by PATH_MAX (usually 1024) - for i in $(range 0 $((PDIRCOMPNUM-1)) 1); do + for ((i=0;i /dev/null - LODEVICE=$(losetup --find --show "$FSIMAGEP${i}.img") - LODEVICES="$LODEVICES $LODEVICE" - if test "$i" = 0; then - MOUNTDEVICE="$LODEVICE" - fi + for ((i=0; i < NDEVICES; i++)); do + dd if=/dev/zero of="${FSIMAGES[i]}" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null + LODEVICES[i]=`losetup -f` + losetup "${LODEVICES[i]}" "${FSIMAGES[i]}" done ;; esac + MOUNTDEVICE="${LODEVICES[0]}" case x"$fs" in x"afs") ;; x"btrfs") - "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" ;; - x"btrfs_zlib" | x"btrfs_lzo" | x"btrfs_zstd") - "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" + "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${LODEVICES[0]}" ;; + x"btrfs_zlib" | x"btrfs_lzo") + "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${LODEVICES[0]}" MOUNTOPTS="compress=${fs/btrfs_/}," MOUNTFS="btrfs" ;; x"btrfs_raid0") - "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" $LODEVICES + "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" "${LODEVICES[@]}" MOUNTFS="btrfs" ;; x"btrfs_raid1") - "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" $LODEVICES + "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" "${LODEVICES[@]}" MOUNTFS="btrfs" ;; x"btrfs_raid10") - "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" $LODEVICES + "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" "${LODEVICES[@]}" MOUNTFS="btrfs" ;; x"btrfs_single") - "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" $LODEVICES + "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" "${LODEVICES[@]}" MOUNTFS="btrfs" ;; x"exfat") - "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${MOUNTDEVICE}" + "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${LODEVICES[0]}" MOUNTOPTS="iocharset=utf8," MOUNTFS="exfat-fuse";; x"minix") - "mkfs.minix" "${MOUNTDEVICE}" + "mkfs.minix" "${LODEVICES[0]}" ;; # mkfs.hfs and mkfs.hfsplus don't fill UUID. x"hfsplus") - "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" - dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;; + "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}" + dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;; x"hfsplus_wrap") - "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" - dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 + "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}" + dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8 MOUNTFS="hfsplus";; x"hfsplus_casesens") - "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}" - dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 + "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}" + dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8 MOUNTFS="hfsplus";; x"hfs") - "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${MOUNTDEVICE}" - dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#474)) conv=notrunc count=8 + "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${LODEVICES[0]}" + dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#474)) conv=notrunc count=8 MOUNTOPTS="iocharset=utf8,codepage=macroman," ;; x"vfat"*|xmsdos*) @@ -682,111 +632,106 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else A= fi - "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${MOUNTDEVICE}" + "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${LODEVICES[0]}" MOUNTOPTS="iocharset=utf8,codepage=437," MOUNTFS="$(echo "$fs"|sed 's,[0-9]*a\?$,,')";; x"minix2") - "mkfs.minix" -v "${MOUNTDEVICE}" + "mkfs.minix" -v "${LODEVICES[0]}" MOUNTFS="minix";; x"minix3") - "mkfs.minix" -B $BLKSIZE -3 "${MOUNTDEVICE}" + "mkfs.minix" -B $BLKSIZE -3 "${LODEVICES[0]}" MOUNTFS="minix";; x"ntfs"*) - "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${MOUNTDEVICE}" + "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${LODEVICES[0]}" MOUNTOPTS="iocharset=utf8,compression," MOUNTFS="ntfs-3g";; x"udf") - "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${MOUNTDEVICE}" + "/usr/bin/mkudffs" -b $BLKSIZE --utf8 --lvid="$FSLABEL" "${LODEVICES[0]}" MOUNTOPTS="iocharset=utf8,bs=$BLKSIZE,";; x"ufs2") - "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${MOUNTDEVICE}" + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${LODEVICES[0]}" MOUNTOPTS="ufstype=ufs2," MOUNTFS="ufs";; x"ufs1") - "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}" + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${LODEVICES[0]}" MOUNTOPTS="ufstype=44bsd," MOUNTFS="ufs";; x"ufs1_sun") - "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}" + "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${LODEVICES[0]}" MOUNTOPTS="ufstype=sun," MOUNTFS="ufs";; x"zfs") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"zfs_caseins") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}" sleep 1 "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs" sleep 1;; x"zfs_lzjb" | xzfs_gzip | xzfs_zle) - "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}" + "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}" sleep 1 "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs" sleep 1;; x"zfs_raidz") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 $LODEVICES + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 "${LODEVICES[@]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"zfs_raidz2") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 $LODEVICES + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 "${LODEVICES[@]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"zfs_raidz3") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 $LODEVICES + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 "${LODEVICES[@]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"zfs_mirror") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror $LODEVICES + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror "${LODEVICES[@]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"zfs_stripe") - "zpool" create -R "$MNTPOINTRW" "$FSLABEL" $LODEVICES + "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[@]}" sleep 1 "zfs" create "$FSLABEL"/"grub fs" sleep 1;; x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*) INSTDEVICE=/dev/null;; x"reiserfs") - "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;; + "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${LODEVICES[0]}" ;; x"reiserfs_old") - "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" + "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${LODEVICES[0]}" MOUNTFS=reiserfs;; x"jfs") - "mkfs.jfs" -L "$FSLABEL" -q "${MOUNTDEVICE}" + "mkfs.jfs" -L "$FSLABEL" -q "${LODEVICES[0]}" MOUNTOPTS="iocharset=utf8,";; x"jfs_caseins") - "mkfs.jfs" -O -L "$FSLABEL" -q "${MOUNTDEVICE}" + "mkfs.jfs" -O -L "$FSLABEL" -q "${LODEVICES[0]}" MOUNTFS=jfs MOUNTOPTS="iocharset=utf8,";; x"mdraid"*) - mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" $LODEVICES + mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" "${LODEVICES[@]}" MOUNTDEVICE="/dev/md/${fs}_${NDEVICES}" MOUNTFS=ext2 "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; x"lvm"*) - for lodev in $LODEVICES; do - pvcreate "$lodev" + for ((i=0;i /dev/null; + cp "${CFILESSRC[0]}" "$MNTPOINTRW/$OSDIR/${CFILES[0]}" &> /dev/null; else - - cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}"; - + for ((i=0;i<$CFILESN;i++)); do + cp "${CFILESSRC[i]}" "$MNTPOINTRW/$OSDIR/${CFILES[i]}"; + done fi if [ x$NOSYMLINK != xy ]; then @@ -1015,72 +942,70 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do sleep 2 ;; x"tarfs") - (cd "$MASTER"; tar cf "${FSIMAGEP}0.img" .) ;; + (cd "$MASTER"; tar cf "${FSIMAGES[0]}" .) ;; x"cpio_"*) - (cd "$MASTER"; find . | cpio -o -H "$(echo ${fs} | sed 's@^cpio_@@')" > "${FSIMAGEP}0.img" ) ;; + (cd "$MASTER"; find . | cpio -o -H "${fs/cpio_/}" > "${FSIMAGES[0]}" ) ;; x"ziso9660") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;; + xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;; x"iso9660") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"joliet") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"rockridge") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"rockridge_joliet") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"iso9660_1999") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"joliet_1999") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"rockridge_1999") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"rockridge_joliet_1999") FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00); - xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER" ;; + xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER" ;; x"romfs") - genromfs -V "$FSLABEL" -f "${FSIMAGEP}0.img" -d "$MASTER" ;; + genromfs -V "$FSLABEL" -f "${FSIMAGES[0]}" -d "$MASTER" ;; xsquash4_*) - echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE - mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;; + echo mksquashfs "$MASTER" "${FSIMAGES[0]}" -comp "${fs/squash4_/}" -b $BLKSIZE + mksquashfs "$MASTER" "${FSIMAGES[0]}" -comp "${fs/squash4_/}" -b $BLKSIZE ;; x"bfs") sleep 1 fusermount -u "$MNTPOINTRW" ;; xlvm*) sleep 1 - for try in $(range 0 20 1); do + for ((try=0;try < 20; try++)); do if umount "$MNTPOINTRW" ; then break; fi sleep 1; done - UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S") sleep 1 vgchange -a n grub_test ;; xmdraid*) sleep 1 - for try in $(range 0 20 1); do + for ((try=0;try < 20; try++)); do if umount "$MNTPOINTRW" ; then break; fi sleep 1; done - UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S") sleep 1 mdadm --stop /dev/md/"${fs}_$NDEVICES" ;; *) sleep 1 - for try in $(range 0 20 1); do + for ((try=0;try < 20; try++)); do if umount "$MNTPOINTRW" ; then break; fi @@ -1113,7 +1038,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do sleep 1 mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; xmdraid*) - mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES + mdadm --assemble /dev/md/"${fs}_$NDEVICES" "${LODEVICES[@]}" sleep 1 mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; *) @@ -1132,7 +1057,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo LIST FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO" exit 1 fi @@ -1141,7 +1066,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo NLIST FAIL echo "$LSROUT" - TZ=UTC ls -lA "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -lA "$MNTPOINTRO" exit 1 fi @@ -1150,7 +1075,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo ILIST FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO" exit 1 fi @@ -1159,7 +1084,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo LONG LIST FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO" exit 1 fi @@ -1170,7 +1095,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo TIME FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO" exit 1 fi @@ -1180,42 +1105,11 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo LONG TIME FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO" exit 1 fi fi - case x"$fs" in - x"zfs"*) - LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/.");; - *) - LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.");; - esac - if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then - : - else - echo DOT IN ROOTDIR FAIL - echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" - exit 1 - fi - - case x"$fs" in - x"zfs"*) - ;; - *) - LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.."); - if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then - : - else - echo DOTDOT IN ROOTDIR FAIL - echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO" - exit 1 - fi - ;; - esac - case x"$fs" in x"zfs"*) LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/////sdir");; @@ -1227,7 +1121,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo SLIST FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO/sdir" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/sdir" exit 1 fi @@ -1242,37 +1136,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do else echo PLIST FAIL echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO/$PDIR" - exit 1 - fi - - case x"$fs" in - x"zfs"*) - LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/.");; - *) - LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/.");; - esac - if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then - : - else - echo DOT IN SUBDIR FAIL - echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/sdir" - exit 1 - fi - - case x"$fs" in - x"zfs"*) - LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/../sdir");; - *) - LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/../sdir");; - esac - if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then - : - else - echo DOTDOT IN SUBDIR FAIL - echo "$LSROUT" - TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/ssdir" + TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/$PDIR" exit 1 fi @@ -1292,8 +1156,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do case x"$fs" in x"iso9660" | x"ziso9660" | xrockridge | xjoliet | xrockridge_joliet | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;; x"zfs"*) - for lodev in $LODEVICES; do - FSUUID=$(printf "%016x\n" $(blkid -o export "$lodev" |grep -F UUID=|sed s,UUID=,,g)) + for ((i=0;i /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM1" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM2" || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM3" > /dev/null; then - : - else - echo FSTIME FAIL - echo "$FSTIME" - echo "$LSOUT" - exit 1 - fi + if [ x$NOFSTIME = xy ]; then + : + elif echo "$LSOUT" | grep -F 'Last modification time '"$FSTIME" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM1" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM2" > /dev/null; then + : + else + echo FSTIME FAIL + echo "$FSTIME" + echo "$LSOUT" + exit 1 fi if [ x$NOHARDLINK != xy ]; then @@ -1457,9 +1315,11 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do exit 1 fi ok=true - if ! run_grubfstest cmp "$GRUBDIR/${CFILE}" "$MNTPOINTRO/$OSDIR/${CFILE}" ; then - ok=false; - fi + for ((i=0;i<$CFILESN;i++)); do + if ! run_grubfstest cmp "$GRUBDIR/${CFILES[i]}" "$MNTPOINTRO/$OSDIR/${CFILES[i]}" ; then + ok=false; + fi + done if test x$ok = xtrue; then : else @@ -1548,17 +1408,15 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do sleep 1 ;; esac - case x"$fs" in - x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;; - *) - for lodev in $LODEVICES; do - while ! losetup -d "$lodev"; do + for ((i=0; i < NDEVICES; i++)); do + case x"$fs" in + x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;; + *) + while ! losetup -d "${LODEVICES[i]}"; do sleep 1 - done - done;; - esac - for i in $(range 0 $((NDEVICES-1)) 1); do - rm "$FSIMAGEP${i}.img" + done;; + esac + rm "${FSIMAGES[i]}" done if [ x"$fs" = x"zfs" ]; then rmdir "$MNTPOINTRW"/"grub fs" || true @@ -1569,4 +1427,3 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do done done done -rmdir "${tempdir}" diff --git a/tests/util/grub-shell-tester.in b/tests/util/grub-shell-tester.in index 8a87109b1..5adce0a47 100644 --- a/tests/util/grub-shell-tester.in +++ b/tests/util/grub-shell-tester.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e # Compares GRUB script output with BASH output. diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in index 93e9f5148..5b66139a9 100644 --- a/tests/util/grub-shell.in +++ b/tests/util/grub-shell.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh set -e # Run GRUB script in a Qemu instance @@ -65,7 +65,7 @@ serial_port=com0 serial_null= halt_cmd=halt pseries=n -disk="hda " +disk=hda case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in *-emu) device_map=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 @@ -74,7 +74,6 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in disk=0 # To skip "Welcome to GRUB" and color setttings trim=1 - serial_port= ;; powerpc-ieee1275) boot=hd @@ -83,7 +82,6 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in serial_port=escc-ch-b serial_null="-serial null" netbootext=elf - trim=1 ;; sparc64-ieee1275) @@ -99,13 +97,13 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mips-qemu_mips) boot=mips_qemu qemu=qemu-system-mips - qemuopts="-M mips $qemuopts" + qemuopts="$qemuopts -M mips" console=vga_text ;; mips-arc) boot=cd qemu=qemu-system-mips64 - qemuopts="-M indy $qemuopts" + qemuopts="$qemuopts -M indy" serial_port=arc/serial0/line0 console= trim=1 @@ -113,7 +111,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mipsel-arc) boot=cd qemu=qemu-system-mips64el - qemuopts="-M magnum $qemuopts -no-reboot" + qemuopts="$qemuopts -M magnum -no-reboot" serial_port=arc/multi0/serial0 console=console halt_cmd=reboot @@ -122,13 +120,13 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in mipsel-qemu_mips) boot=mipsel_qemu qemu=qemu-system-mipsel - qemuopts="-M mips $qemuopts" + qemuopts="$qemuopts -M mips" console=vga_text ;; mipsel-loongson) boot=mipsel_fulong2e qemu=qemu-system-mips64el - qemuopts="-M fulong2e $qemuopts" + qemuopts="$qemuopts -M fulong2e" console= trim=1 ;; @@ -147,7 +145,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in qemu=qemu-system-i386 console=console trim=1 - disk="hdb " + disk=hdb ;; i386-qemu) boot=qemu @@ -166,32 +164,12 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in boot=cd console=console trim=1 - qemuopts="-bios OVMF-ia32.fd $qemuopts" ;; x86_64-efi) qemu=qemu-system-x86_64 boot=cd console=console trim=1 - qemuopts="-bios OVMF.fd $qemuopts" - ;; - arm64-efi) - qemu=qemu-system-aarch64 - boot=hd - console=console - trim=1 - qemuopts="-machine virt -cpu cortex-a57 -bios /usr/share/qemu-efi/QEMU_EFI.fd $qemuopts" - disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file=" - serial_port= - ;; - arm-efi) - qemu=qemu-system-arm - boot=hd - console=console - trim=1 - qemuopts="-machine virt -bios /usr/share/ovmf-arm/QEMU_EFI.fd $qemuopts" - disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file=" - serial_port=efi0 ;; *) boot=hd @@ -244,17 +222,17 @@ for option in "$@"; do echo "(hd$disk) $dsk" >> "$device_map" disk="$((disk+1))" else - if [ "$disk" = error ]; then + if [ $disk = error ]; then echo "Too many disks" 1>&2 exit 1; fi - qemuopts="$qemuopts -$disk$dsk" - if [ "$disk" = "hda " ]; then - disk="hdb "; - elif [ "$disk" = "hdb " ]; then + qemuopts="$qemuopts -$disk $dsk" + if [ "$disk" = hda ]; then + disk=hdb; + elif [ "$disk" = hdb ]; then # CDROM is hdc - disk="hdd " - elif [ "$disk" = "hdd " ]; then + disk=hdd + elif [ "$disk" = hdd ]; then # CDROM is hdc disk=error fi @@ -311,8 +289,6 @@ fi cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cat <${cfgfile} grubshell=yes -enable_progress_indicator=0 -export enable_progress_indicator EOF @@ -323,7 +299,7 @@ fi if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ]; then echo insmod escc >>${cfgfile} fi -if [ "${serial_port}" != "" ]; then +if [ "${grub_modinfo_platform}" != emu ]; then echo "serial ${serial_port}" >>${cfgfile} term="serial_${serial_port}" else @@ -353,8 +329,7 @@ cat <>${cfgfile} source "\$prefix/testcase.cfg" # Stop serial output to suppress "ACPI shutdown failed" error. EOF -# Attempt to switch to console on i386-ieee1275 causes "screen not found" message -if [ x$console != x ] && [ x"${grub_modinfo_target_cpu}-${grub_modinfo_platform}" != xi386-ieee1275 ]; then +if [ x$console != x ]; then echo "terminal_output $console" >>${cfgfile} fi echo "${halt_cmd}" >>${cfgfile} @@ -369,28 +344,18 @@ test -z "$debug" || echo "GRUB ROM directory: ${rom_directory}" >&2 if test -z "$debug"; then qemuopts="${qemuopts} -nographic -monitor file:/dev/null" - # SeaBIOS 1.11.0 added support for VGA emulation over a serial port. If - # this is configured in SeaBIOS, then -nographic causes some extra junk to - # end up on the serial console, which interferes with our tests. This - # workaround unfortunately causes qemu to issue a warning 'externally - # provided fw_cfg item names should be prefixed with "opt/"', but there - # doesn't seem to be a better option. - qemuopts="${qemuopts} -fw_cfg name=etc/sercon-port,string=0" fi if [ x$boot != xnet ] && [ x$boot != xemu ]; then pkgdatadir="@builddir@" "@builddir@/grub-mkrescue" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \ --rom-directory="${rom_directory}" \ - --locale-directory="@srcdir@/po" \ --themes-directory="@srcdir@/themes" \ $mkimage_extra_arg ${mkrescue_args} \ "/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \ ${files} >/dev/null 2>&1 fi if [ x$boot = xhd ]; then - if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then - device="device virtio-blk-device,drive=hd0 -drive if=none,id=hd0,file=" - elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then + if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = mips-arc ]; then device="hdb " else device="hda " @@ -398,9 +363,7 @@ if [ x$boot = xhd ]; then bootdev="-boot c" fi if [ x$boot = xcd ]; then - if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then - device="device virtio-blk-device,drive=cd0 -drive if=none,id=cd0,media=cdrom,file=" - elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then + if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = powerpc-ieee1275 ] && [ x$pseries != xy ] ; then device="-drive if=ide,media=cdrom,file=" else device="cdrom " @@ -435,7 +398,7 @@ fi if [ x$boot = xcoreboot ]; then imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 cp "${GRUB_COREBOOT_ROM}" "${imgfile}" - "${GRUB_CBFSTOOL}" "${imgfile}" add-payload -f "${rom_directory}/coreboot.elf" -n fallback/payload + "${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload bootdev="-bios ${imgfile}" device="cdrom " test -z "$debug" || echo "Coreboot image: ${imgfile}" >&2 @@ -483,12 +446,11 @@ if [ x$boot = xnet ]; then [ -z "$files" ] || copy_extra_files "$netdir" $files timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic | cat | tr -d "\r" | do_trim elif [ x$boot = xemu ]; then - rootdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" - grubdir="$rootdir/boot/grub" + grubdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" mkdir -p "$grubdir/fonts" mkdir -p "$grubdir/themes" mkdir -p "$grubdir/locale" - test -f "@builddir@/"unicode.pf2 && cp "@builddir@/"unicode.pf2 "$grubdir/fonts/unicode.pf2" + cp "@builddir@/"unicode.pf2 "$grubdir/fonts/unicode.pf2" cp -R "@srcdir@/themes/starfield" "$grubdir/themes/starfield" for file in "@srcdir@/po/"*.gmo; do if [ -f "$file" ]; then @@ -497,12 +459,8 @@ elif [ x$boot = xemu ]; then done cp "${cfgfile}" "$grubdir/grub.cfg" cp "${source}" "$grubdir/testcase.cfg" - [ -z "$files" ] || copy_extra_files "$rootdir" $files - roottar="$(mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")" - (cd "$rootdir"; tar cf "$roottar" .) - @builddir@/grub-core/grub-emu -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" | tr -d "\r" | do_trim - test -n "$debug" || rm -rf "$rootdir" - test -n "$debug" || rm -f "$roottar" + @builddir@/grub-core/grub-emu -m "$device_map" -d "$grubdir" | tr -d "\r" | do_trim + rm -rf "$grubdir" else timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | do_trim fi diff --git a/tests/xfs_test.in b/tests/xfs_test.in index 03a351359..173b1cfe6 100644 --- a/tests/xfs_test.in +++ b/tests/xfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e @@ -16,5 +16,4 @@ if ! which mkfs.xfs >/dev/null 2>&1; then fi -"@builddir@/grub-fs-tester" xfs_crc "@builddir@/grub-fs-tester" xfs diff --git a/tests/xzcompress_test.in b/tests/xzcompress_test.in index 03bfb5e95..b2bd999ec 100644 --- a/tests/xzcompress_test.in +++ b/tests/xzcompress_test.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! /bin/sh # Copyright (C) 2013 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify diff --git a/tests/zfs_test.in b/tests/zfs_test.in index eee62c10d..047120e47 100644 --- a/tests/zfs_test.in +++ b/tests/zfs_test.in @@ -1,4 +1,4 @@ -#!@BUILD_SHEBANG@ +#!/bin/sh set -e diff --git a/util/editenv.c b/util/editenv.c index c532b046f..c6f8d2298 100644 --- a/util/editenv.c +++ b/util/editenv.c @@ -28,23 +28,15 @@ #include #include -#if !defined(_WIN32) -#include -#endif #define DEFAULT_ENVBLK_SIZE 1024 -#define GRUB_ENVBLK_MESSAGE "# WARNING: Do not edit this file by tools other than "PACKAGE"-editenv!!!\n" void grub_util_create_envblk_file (const char *name) { FILE *fp; - char *buf, *pbuf, *namenew; -#if !defined(_WIN32) - ssize_t size = 1; - char *rename_target = xstrdup (name); - int rc; -#endif + char *buf; + char *namenew; buf = xmalloc (DEFAULT_ENVBLK_SIZE); @@ -54,82 +46,20 @@ grub_util_create_envblk_file (const char *name) grub_util_error (_("cannot open `%s': %s"), namenew, strerror (errno)); - pbuf = buf; - memcpy (pbuf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1); - pbuf += sizeof (GRUB_ENVBLK_SIGNATURE) - 1; - memcpy (pbuf, GRUB_ENVBLK_MESSAGE, sizeof (GRUB_ENVBLK_MESSAGE) - 1); - pbuf += sizeof (GRUB_ENVBLK_MESSAGE) - 1; - memset (pbuf , '#', - DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) - sizeof (GRUB_ENVBLK_MESSAGE) + 2); + memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1); + memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#', + DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1); if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE) grub_util_error (_("cannot write to `%s': %s"), namenew, strerror (errno)); - if (grub_util_file_sync (fp) < 0) - grub_util_error (_("cannot sync `%s': %s"), namenew, strerror (errno)); + grub_util_file_sync (fp); free (buf); fclose (fp); -#if defined(_WIN32) if (grub_util_rename (namenew, name) < 0) grub_util_error (_("cannot rename the file %s to %s"), namenew, name); -#else - while (1) - { - char *linkbuf; - ssize_t retsize; - - linkbuf = xmalloc (size + 1); - retsize = grub_util_readlink (rename_target, linkbuf, size); - if (retsize < 0 && (errno == ENOENT || errno == EINVAL)) - { - free (linkbuf); - break; - } - else if (retsize < 0) - { - free (linkbuf); - grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); - } - else if (retsize == size) - { - free (linkbuf); - size += 128; - continue; - } - - linkbuf[retsize] = '\0'; - if (linkbuf[0] == '/') - { - free (rename_target); - rename_target = linkbuf; - } - else - { - char *dbuf = xstrdup (rename_target); - const char *dir = dirname (dbuf); - - free (rename_target); - rename_target = xasprintf ("%s/%s", dir, linkbuf); - free (dbuf); - free (linkbuf); - } - } - - rc = grub_util_rename (namenew, rename_target); - if (rc < 0 && errno == EXDEV) - { - rc = grub_install_copy_file (namenew, rename_target, 1); - grub_util_unlink (namenew); - } - - free (rename_target); - - if (rc < 0) - grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); -#endif - free (namenew); } diff --git a/util/getroot.c b/util/getroot.c index a5eaa64fd..3958105d8 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -99,7 +99,7 @@ grub_util_pull_device (const char *os_dev) { case GRUB_DEV_ABSTRACTION_LVM: grub_util_pull_lvm_by_command (os_dev); - /* Fallthrough - in case that lvm-tools are unavailable. */ + /* Fallthrough in case that lvm-tools are unavailable. */ case GRUB_DEV_ABSTRACTION_LUKS: grub_util_pull_devmapper (os_dev); return; @@ -107,7 +107,6 @@ grub_util_pull_device (const char *os_dev) default: if (grub_util_pull_device_os (os_dev, ab)) return; - /* Fallthrough. */ case GRUB_DEV_ABSTRACTION_NONE: free (grub_util_biosdisk_get_grub_dev (os_dev)); return; @@ -200,7 +199,7 @@ make_device_name (const char *drive) char *ret, *ptr; const char *iptr; - ret = xcalloc (2, strlen (drive)); + ret = xmalloc (strlen (drive) * 2); ptr = ret; for (iptr = drive; *iptr; iptr++) { @@ -383,6 +382,9 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) grub_util_info ("%s starts from %" GRUB_HOST_PRIuLONG_LONG, os_dev, (unsigned long long) ctx.start); + if (ctx.start == 0 && !is_part) + return name; + grub_util_info ("opening the device %s", name); disk = grub_disk_open (name); free (name); @@ -403,7 +405,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) os_dev); grub_errno = GRUB_ERR_NONE; - canon = grub_canonicalize_file_name (os_dev); + canon = canonicalize_file_name (os_dev); drive = grub_hostdisk_os_dev_to_grub_drive (canon ? : os_dev, 1); if (canon) free (canon); @@ -415,10 +417,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) name = grub_util_get_ldm (disk, ctx.start); if (name) - { - grub_disk_close (disk); - return name; - } + return name; ctx.partname = NULL; diff --git a/util/grub-editenv.c b/util/grub-editenv.c index f3662c95b..118e89fe5 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -197,8 +197,7 @@ write_envblk (const char *name, grub_envblk_t envblk) grub_util_error (_("cannot write to `%s': %s"), name, strerror (errno)); - if (grub_util_file_sync (fp) < 0) - grub_util_error (_("cannot sync `%s': %s"), name, strerror (errno)); + grub_util_file_sync (fp); fclose (fp); } diff --git a/util/grub-file.c b/util/grub-file.c index b2e7dd69f..9989dfe7b 100644 --- a/util/grub-file.c +++ b/util/grub-file.c @@ -54,7 +54,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); - argv2 = xcalloc (argc, sizeof (argv2[0])); + argv2 = xmalloc (argc * sizeof (argv2[0])); if (argc == 2 && strcmp (argv[1], "--version") == 0) { @@ -77,7 +77,7 @@ main (int argc, char *argv[]) } if (had_file) grub_util_error ("one argument expected"); - argv2[i - 1] = grub_canonicalize_file_name (argv[i]); + argv2[i - 1] = canonicalize_file_name (argv[i]); if (!argv2[i - 1]) { grub_util_error (_("cannot open `%s': %s"), argv[i], diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 838656420..31af2a7ad 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -120,9 +120,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len, void return; } - file = grub_file_open (pathname, ((uncompress == 0) - ? GRUB_FILE_TYPE_NO_DECOMPRESS : GRUB_FILE_TYPE_NONE) - | GRUB_FILE_TYPE_FSTEST); + if (uncompress == 0) + grub_file_filter_disable_compression (); + file = grub_file_open (pathname); if (!file) { grub_util_error (_("cannot open `%s': %s"), pathname, @@ -470,9 +470,9 @@ fstest (int n) fs = grub_fs_probe (dev); if (!fs) grub_util_error ("%s", grub_errmsg); - if (!fs->fs_uuid) + if (!fs->uuid) grub_util_error ("%s", _("couldn't retrieve UUID")); - if (fs->fs_uuid (dev, &uuid)) + if (fs->uuid (dev, &uuid)) grub_util_error ("%s", grub_errmsg); if (!uuid) grub_util_error ("%s", _("couldn't retrieve UUID")); @@ -538,7 +538,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; static error_t argp_parser (int key, char *arg, struct argp_state *state) { - const char *p; + char *p; switch (key) { @@ -570,12 +570,12 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; } real_size = fread (buf, 1, 1024, f); - fclose (f); if (real_size < 0) { printf (_("%s: error:"), program_name); printf (_("cannot read `%s': %s"), arg, strerror (errno)); printf ("\n"); + fclose (f); return 0; } grub_zfs_add_key (buf, real_size, 0); @@ -650,8 +650,8 @@ argp_parser (int key, char *arg, struct argp_state *state) if (args_count < num_disks) { if (args_count == 0) - images = xcalloc (num_disks, sizeof (images[0])); - images[args_count] = grub_canonicalize_file_name (arg); + images = xmalloc (num_disks * sizeof (images[0])); + images[args_count] = canonicalize_file_name (arg); args_count++; return 0; } @@ -734,7 +734,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); - args = xcalloc (argc, sizeof (args[0])); + args = xmalloc (argc * sizeof (args[0])); argp_parse (&argp, argc, argv, 0, 0, 0); diff --git a/util/grub-install-common.c b/util/grub-install-common.c index 277eaf4e2..b6dec93ea 100644 --- a/util/grub-install-common.c +++ b/util/grub-install-common.c @@ -73,7 +73,6 @@ grub_install_help_filter (int key, const char *text, static int (*compress_func) (const char *src, const char *dest) = NULL; char *grub_install_copy_buffer; -static char *dtb; int grub_install_copy_file (const char *src, @@ -112,16 +111,11 @@ grub_install_copy_file (const char *src, r = grub_util_fd_read (in, grub_install_copy_buffer, GRUB_INSTALL_COPY_BUFFER_SIZE); if (r <= 0) break; - r = grub_util_fd_write (out, grub_install_copy_buffer, r); - if (r <= 0) - break; + grub_util_fd_write (out, grub_install_copy_buffer, r); } - if (grub_util_fd_sync (out) < 0) - r = -1; - if (grub_util_fd_close (in) < 0) - r = -1; - if (grub_util_fd_close (out) < 0) - r = -1; + grub_util_fd_sync (out); + grub_util_fd_close (in); + grub_util_fd_close (out); if (r < 0) grub_util_error (_("cannot copy `%s' to `%s': %s"), @@ -244,7 +238,7 @@ grub_install_push_module (const char *val) if (modules.n_alloc < 16) modules.n_alloc = 16; modules.entries = xrealloc (modules.entries, - modules.n_alloc * sizeof (*modules.entries)); + modules.n_alloc * sizeof (modules.entries)); } modules.entries[modules.n_entries++] = xstrdup (val); modules.entries[modules.n_entries] = NULL; @@ -286,7 +280,7 @@ handle_install_list (struct install_list *il, const char *val, il->n_entries++; } il->n_alloc = il->n_entries + 1; - il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); + il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); ptr = val; for (ce = il->entries; ; ce++) { @@ -370,11 +364,6 @@ grub_install_parse (int key, char *arg) case GRUB_INSTALL_OPTIONS_INSTALL_FONTS: handle_install_list (&install_fonts, arg, 0); return 1; - case GRUB_INSTALL_OPTIONS_DTB: - if (dtb) - free (dtb); - dtb = xstrdup (arg); - return 1; case GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS: if (strcmp (arg, "no") == 0 || strcmp (arg, "none") == 0) @@ -497,21 +486,19 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix, grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'" " --output '%s' " - " --dtb '%s' " "--format '%s' --compression '%s' %s %s\n", dir, prefix, - outname, dtb ? : "", mkimage_target, + outname, mkimage_target, compnames[compression], note ? "--note" : "", s); - free (s); tgt = grub_install_get_image_target (mkimage_target); if (!tgt) - grub_util_error (_("unknown target format %s"), mkimage_target); + grub_util_error (_("unknown target format %s\n"), mkimage_target); grub_install_generate_image (dir, prefix, fp, outname, modules.entries, memdisk_path, pubkeys, npubkeys, config_path, tgt, - note, compression, dtb); + note, compression); while (dc--) grub_install_pop_module (); } @@ -531,8 +518,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix, grub_install_make_image_wrap_file (dir, prefix, fp, outname, memdisk_path, config_path, mkimage_target, note); - if (grub_util_file_sync (fp) < 0) - grub_util_error (_("cannot sync `%s': %s"), outname, strerror (errno)); + grub_util_file_sync (fp); fclose (fp); } @@ -598,7 +584,6 @@ copy_all (const char *srcd, grub_util_fd_closedir (d); } -#if (defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS) static const char * get_localedir (void) { @@ -653,59 +638,6 @@ copy_locales (const char *dstd) } grub_util_fd_closedir (d); } -#endif - -static void -grub_install_copy_nls(const char *src __attribute__ ((unused)), - const char *dst __attribute__ ((unused))) -{ -#if (defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS) - char *dst_locale; - - dst_locale = grub_util_path_concat (2, dst, "locale"); - grub_install_mkdir_p (dst_locale); - clean_grub_dir (dst_locale); - - if (install_locales.is_default) - { - char *srcd = grub_util_path_concat (2, src, "po"); - copy_by_ext (srcd, dst_locale, ".mo", 0); - copy_locales (dst_locale); - free (srcd); - } - else - { - size_t i; - const char *locale_dir = get_localedir (); - - for (i = 0; i < install_locales.n_entries; i++) - { - char *srcf = grub_util_path_concat_ext (3, src, "po", - install_locales.entries[i], - ".mo"); - char *dstf = grub_util_path_concat_ext (2, dst_locale, - install_locales.entries[i], - ".mo"); - if (grub_install_compress_file (srcf, dstf, 0)) - { - free (srcf); - free (dstf); - continue; - } - free (srcf); - srcf = grub_util_path_concat_ext (4, locale_dir, - install_locales.entries[i], - "LC_MESSAGES", PACKAGE, ".mo"); - if (grub_install_compress_file (srcf, dstf, 0) == 0) - grub_util_error (_("cannot find locale `%s'"), - install_locales.entries[i]); - free (srcf); - free (dstf); - } - } - free (dst_locale); -#endif -} static struct { @@ -722,7 +654,6 @@ static struct [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64", "efi" }, [GRUB_INSTALL_PLATFORM_I386_XEN] = { "i386", "xen" }, [GRUB_INSTALL_PLATFORM_X86_64_XEN] = { "x86_64", "xen" }, - [GRUB_INSTALL_PLATFORM_I386_XEN_PVH] = { "i386", "xen_pvh" }, [GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON] = { "mipsel", "loongson" }, [GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS] = { "mipsel", "qemu_mips" }, [GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS] = { "mips", "qemu_mips" }, @@ -734,9 +665,6 @@ static struct [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm", "efi" }, [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64", "efi" }, [GRUB_INSTALL_PLATFORM_ARM_UBOOT] = { "arm", "uboot" }, - [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] = { "arm", "coreboot" }, - [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32", "efi" }, - [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64", "efi" }, }; char * @@ -794,7 +722,7 @@ grub_install_copy_files (const char *src, const char *dst, enum grub_install_plat platid) { - char *dst_platform, *dst_fonts; + char *dst_platform, *dst_locale, *dst_fonts; const char *pkgdatadir = grub_util_get_pkgdatadir (); char *themes_dir; @@ -805,12 +733,13 @@ grub_install_copy_files (const char *src, dst_platform = grub_util_path_concat (2, dst, platform); free (platform); } + dst_locale = grub_util_path_concat (2, dst, "locale"); dst_fonts = grub_util_path_concat (2, dst, "fonts"); grub_install_mkdir_p (dst_platform); + grub_install_mkdir_p (dst_locale); clean_grub_dir (dst); clean_grub_dir (dst_platform); - - grub_install_copy_nls(src, dst); + clean_grub_dir (dst_locale); if (install_modules.is_default) copy_by_ext (src, dst_platform, ".mod", 1); @@ -835,8 +764,6 @@ grub_install_copy_files (const char *src, grub_install_compress_file (srcf, dstf, 1); free (dstf); } - - grub_util_free_path_list (path_list); } const char *pkglib_DATA[] = {"efiemu32.o", "efiemu64.o", @@ -859,6 +786,50 @@ grub_install_copy_files (const char *src, free (dstf); } + if (install_locales.is_default) + { + char *srcd = grub_util_path_concat (2, src, "po"); + copy_by_ext (srcd, dst_locale, ".mo", 0); + copy_locales (dst_locale); + free (srcd); + } + else + { + const char *locale_dir = get_localedir (); + + for (i = 0; i < install_locales.n_entries; i++) + { + char *srcf = grub_util_path_concat_ext (3, src, + "po", + install_locales.entries[i], + ".mo"); + char *dstf = grub_util_path_concat_ext (2, dst_locale, + install_locales.entries[i], + ".mo"); + if (grub_install_compress_file (srcf, dstf, 0)) + { + free (srcf); + free (dstf); + continue; + } + free (srcf); + srcf = grub_util_path_concat_ext (4, + locale_dir, + install_locales.entries[i], + "LC_MESSAGES", + PACKAGE, + ".mo"); + if (grub_install_compress_file (srcf, dstf, 0)) + { + free (srcf); + free (dstf); + continue; + } + grub_util_error (_("cannot find locale `%s'"), + install_locales.entries[i]); + } + } + if (install_themes.is_default) { install_themes.is_default = 0; @@ -921,6 +892,7 @@ grub_install_copy_files (const char *src, } free (dst_platform); + free (dst_locale); free (dst_fonts); } @@ -929,7 +901,7 @@ grub_install_get_target (const char *src) { char *fn; grub_util_fd_t f; - char buf[8192]; + char buf[2048]; ssize_t r; char *c, *pl, *p; size_t i; diff --git a/util/grub-install.c b/util/grub-install.c index a35a2e2e8..7d61c32be 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -319,19 +319,11 @@ get_default_platform (void) #elif defined (__ia64__) return "ia64-efi"; #elif defined (__arm__) - return grub_install_get_default_arm_platform (); + return "arm-uboot"; #elif defined (__aarch64__) return "arm64-efi"; #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) return grub_install_get_default_x86_platform (); -#elif defined (__riscv) -#if __riscv_xlen == 32 - return "riscv32-efi"; -#elif __riscv_xlen == 64 - return "riscv64-efi"; -#else - return NULL; -#endif #else return NULL; #endif @@ -454,8 +446,8 @@ probe_mods (grub_disk_t disk) if (raid_level >= 0) { grub_install_push_module ("diskfilter"); - if (disk->dev->disk_raidname) - grub_install_push_module (disk->dev->disk_raidname (disk)); + if (disk->dev->raidname) + grub_install_push_module (disk->dev->raidname (disk)); } if (raid_level == 5) grub_install_push_module ("raid5rec"); @@ -463,8 +455,8 @@ probe_mods (grub_disk_t disk) grub_install_push_module ("raid6rec"); /* In case of LVM/RAID, check the member devices as well. */ - if (disk->dev->disk_memberlist) - list = disk->dev->disk_memberlist (disk); + if (disk->dev->memberlist) + list = disk->dev->memberlist (disk); while (list) { probe_mods (list->disk); @@ -485,8 +477,6 @@ have_bootdev (enum grub_install_plat pl) case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: @@ -496,7 +486,6 @@ have_bootdev (enum grub_install_plat pl) case GRUB_INSTALL_PLATFORM_I386_QEMU: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: @@ -506,7 +495,6 @@ have_bootdev (enum grub_install_plat pl) case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: return 0; /* pacify warning. */ @@ -522,9 +510,9 @@ probe_cryptodisk_uuid (grub_disk_t disk) grub_disk_memberlist_t list = NULL, tmp; /* In case of LVM/RAID, check the member devices as well. */ - if (disk->dev->disk_memberlist) + if (disk->dev->memberlist) { - list = disk->dev->disk_memberlist (disk); + list = disk->dev->memberlist (disk); } while (list) { @@ -627,6 +615,8 @@ device_map_check_duplicates (const char *dev_map) char **d; size_t i; + d = xmalloc (alloced * sizeof (d[0])); + if (dev_map[0] == '\0') return; @@ -634,8 +624,6 @@ device_map_check_duplicates (const char *dev_map) if (! fp) return; - d = xcalloc (alloced, sizeof (d[0])); - while (fgets (buf, sizeof (buf), fp)) { char *p = buf; @@ -725,7 +713,7 @@ is_prep_partition (grub_device_t dev) if (grub_disk_read (dev->disk, p->offset, p->index, sizeof (gptdata), &gptdata) == 0) { - const grub_gpt_part_guid_t template = { + const grub_gpt_part_type_t template = { grub_cpu_to_le32_compile_time (0x9e1a2d38), grub_cpu_to_le16_compile_time (0xc612), grub_cpu_to_le16_compile_time (0x4316), @@ -785,7 +773,7 @@ bless (grub_device_t dev, const char *path, int x86) err = grub_mac_bless_inode (dev, st.st_ino, S_ISDIR (st.st_mode), x86); if (err) grub_util_error ("%s", grub_errmsg); - grub_util_info ("blessed"); + grub_util_info ("blessed\n"); } static void @@ -910,8 +898,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: @@ -921,12 +907,10 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM_UBOOT: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: break; case GRUB_INSTALL_PLATFORM_I386_QEMU: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: @@ -957,21 +941,17 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_ARM_UBOOT: case GRUB_INSTALL_PLATFORM_I386_QEMU: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: free (install_device); install_device = NULL; break; @@ -987,7 +967,7 @@ main (int argc, char *argv[]) { char * t = grub_util_path_concat (2, bootdir, GRUB_DIR_NAME); grub_install_mkdir_p (t); - grubdir = grub_canonicalize_file_name (t); + grubdir = canonicalize_file_name (t); if (!grubdir) grub_util_error (_("failed to get canonical path of `%s'"), t); free (t); @@ -1012,8 +992,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: is_efi = 1; break; @@ -1092,7 +1070,7 @@ main (int argc, char *argv[]) efidir_is_mac = 1; if (!efidir_is_mac && grub_strcmp (fs->name, "fat") != 0) - grub_util_error (_("%s doesn't look like an EFI partition"), efidir); + grub_util_error (_("%s doesn't look like an EFI partition.\n"), efidir); /* The EFI specification requires that an EFI System Partition must contain an "EFI" subdirectory, and that OS loaders are stored in @@ -1127,12 +1105,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM64_EFI: efi_file = "BOOTAA64.EFI"; break; - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - efi_file = "BOOTRISCV32.EFI"; - break; - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: - efi_file = "BOOTRISCV64.EFI"; - break; default: grub_util_error ("%s", _("You've found a bug")); break; @@ -1160,12 +1132,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM64_EFI: efi_file = "grubaa64.efi"; break; - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - efi_file = "grubriscv32.efi"; - break; - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: - efi_file = "grubriscv64.efi"; - break; default: efi_file = "grub.efi"; break; @@ -1268,7 +1234,7 @@ main (int argc, char *argv[]) ndev++; } - grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); + grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, curdrive++) @@ -1305,7 +1271,7 @@ main (int argc, char *argv[]) if (!config.is_cryptodisk_enabled && have_cryptodisk) grub_util_error (_("attempt to install to encrypted disk without cryptodisk enabled. " - "Set `%s' in file `%s'"), "GRUB_ENABLE_CRYPTODISK=y", + "Set `%s' in file `%s'."), "GRUB_ENABLE_CRYPTODISK=y", grub_util_get_config_filename ()); if (disk_module && grub_strcmp (disk_module, "ata") == 0) @@ -1316,7 +1282,6 @@ main (int argc, char *argv[]) grub_install_push_module ("ahci"); grub_install_push_module ("ohci"); grub_install_push_module ("uhci"); - grub_install_push_module ("ehci"); grub_install_push_module ("usbms"); } else if (disk_module && disk_module[0]) @@ -1334,7 +1299,7 @@ main (int argc, char *argv[]) { char *t = grub_util_path_concat (2, grubdir, platname); - platdir = grub_canonicalize_file_name (t); + platdir = canonicalize_file_name (t); if (!platdir) grub_util_error (_("failed to get canonical path of `%s'"), t); @@ -1386,8 +1351,8 @@ main (int argc, char *argv[]) { char *uuid = NULL; /* generic method (used on coreboot and ata mod). */ - if (!force_file_id - && grub_fs->fs_uuid && grub_fs->fs_uuid (grub_dev, &uuid)) + if (!force_file_id && grub_fs->uuid && grub_fs->uuid (grub_dev, + &uuid)) { grub_print_error (); grub_errno = 0; @@ -1468,8 +1433,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: g = grub_util_guess_efi_drive (*curdev); break; @@ -1484,7 +1447,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: case GRUB_INSTALL_PLATFORM_I386_QEMU: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: @@ -1495,7 +1457,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_ARM_UBOOT: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: grub_util_warn ("%s", _("no hints available for your platform. Expect reduced performance")); break; /* pacify warning. */ @@ -1506,7 +1467,6 @@ main (int argc, char *argv[]) { grub_util_fprint_full_disk_name (load_cfg_f, g, dev); fprintf (load_cfg_f, " "); - free (g); } if (dev != grub_dev) grub_device_close (dev); @@ -1563,8 +1523,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_X86_64_EFI: case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: core_name = "core.efi"; snprintf (mkimage_target, sizeof (mkimage_target), @@ -1583,13 +1541,11 @@ main (int argc, char *argv[]) break; case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: core_name = "core.elf"; snprintf (mkimage_target, sizeof (mkimage_target), "%s-%s", @@ -1668,13 +1624,10 @@ main (int argc, char *argv[]) break; case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_I386_PC: case GRUB_INSTALL_PLATFORM_MIPSEL_ARC: @@ -1684,7 +1637,6 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: break; /* pacify warning. */ case GRUB_INSTALL_PLATFORM_MAX: @@ -1746,7 +1698,7 @@ main (int argc, char *argv[]) /* Now perform the installation. */ if (install_bootsector) grub_util_sparc_setup (platdir, "boot.img", "core.img", - install_drive, force, + install_device, force, fs_probe, allow_floppy, 0 /* unused */ ); break; @@ -1775,7 +1727,7 @@ main (int argc, char *argv[]) grub_elf = grub_util_path_concat (2, core_services, "grub.elf"); grub_install_copy_file (imgfile, grub_elf, 1); - f = grub_util_fopen (mach_kernel, "a+"); + f = grub_util_fopen (mach_kernel, "r+"); if (!f) grub_util_error (_("Can't create file: %s"), strerror (errno)); fclose (f); @@ -1857,7 +1809,7 @@ main (int argc, char *argv[]) grub_install_copy_file (imgfile, dst, 1); free (dst); } - /* Fallthrough. */ + case GRUB_INSTALL_PLATFORM_X86_64_EFI: if (efidir_is_mac) { @@ -1888,13 +1840,9 @@ main (int argc, char *argv[]) if (!removable && update_nvram) { /* Try to make this image bootable using the EFI Boot Manager, if available. */ - int ret; - ret = grub_install_register_efi (efidir_grub_dev, - "\\System\\Library\\CoreServices", - efi_distributor); - if (ret) - grub_util_error (_("efibootmgr failed to register the boot entry: %s"), - strerror (ret)); + grub_install_register_efi (efidir_grub_dev, + "\\System\\Library\\CoreServices", + efi_distributor); } grub_device_close (ins_dev); @@ -1902,11 +1850,8 @@ main (int argc, char *argv[]) free (mach_kernel); break; } - /* FALLTHROUGH */ case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: - case GRUB_INSTALL_PLATFORM_RISCV32_EFI: - case GRUB_INSTALL_PLATFORM_RISCV64_EFI: case GRUB_INSTALL_PLATFORM_IA64_EFI: { char *dst = grub_util_path_concat (2, efidir, efi_file); @@ -1917,7 +1862,6 @@ main (int argc, char *argv[]) { char * efifile_path; char * part; - int ret; /* Try to make this image bootable using the EFI Boot Manager, if available. */ if (!efi_distributor || efi_distributor[0] == '\0') @@ -1934,11 +1878,8 @@ main (int argc, char *argv[]) efidir_grub_dev->disk->name, (part ? ",": ""), (part ? : "")); grub_free (part); - ret = grub_install_register_efi (efidir_grub_dev, - efifile_path, efi_distributor); - if (ret) - grub_util_error (_("efibootmgr failed to register the boot entry: %s"), - strerror (ret)); + grub_install_register_efi (efidir_grub_dev, + efifile_path, efi_distributor); } break; @@ -1946,14 +1887,12 @@ main (int argc, char *argv[]) case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS: case GRUB_INSTALL_PLATFORM_I386_COREBOOT: - case GRUB_INSTALL_PLATFORM_ARM_COREBOOT: case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT: case GRUB_INSTALL_PLATFORM_MIPSEL_ARC: case GRUB_INSTALL_PLATFORM_ARM_UBOOT: case GRUB_INSTALL_PLATFORM_I386_QEMU: case GRUB_INSTALL_PLATFORM_I386_XEN: case GRUB_INSTALL_PLATFORM_X86_64_XEN: - case GRUB_INSTALL_PLATFORM_I386_XEN_PVH: grub_util_warn ("%s", _("WARNING: no platform-specific install was performed")); break; diff --git a/util/grub-kbdcomp.in b/util/grub-kbdcomp.in index a15ec24e5..715c483af 100644 --- a/util/grub-kbdcomp.in +++ b/util/grub-kbdcomp.in @@ -25,7 +25,7 @@ usage () { gettext "Make GRUB keyboard layout file."; echo echo print_option_help "-h, --help" "$(gettext "print this message and exit")" - print_option_help "-V, --version" "$(gettext "print the version information and exit")" + print_option_help "-v, --version" "$(gettext "print the version information and exit")" print_option_help "-o, --output=$(gettext FILE)" "$(gettext "save output in FILE [required]")" echo gettext_printf "%s generates a keyboard layout for GRUB using ckbcomp\n" "$self" @@ -54,7 +54,7 @@ do -h | --help) usage exit 0 ;; - -V | --version) + -v | --version) echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" exit 0 ;; -o | --output) diff --git a/util/grub-macbless.c b/util/grub-macbless.c index e9b15a053..742353a42 100644 --- a/util/grub-macbless.c +++ b/util/grub-macbless.c @@ -64,7 +64,7 @@ bless (const char *path, int x86) grub_err_t err; struct stat st; - grub_path = grub_canonicalize_file_name (path); + grub_path = canonicalize_file_name (path); if (stat (grub_path, &st) < 0) grub_util_error (N_("cannot stat `%s': %s"), @@ -92,8 +92,6 @@ bless (const char *path, int x86) free (filebuf_via_grub); free (filebuf_via_sys); free (drive_name); - free (devices); - grub_device_close (dev); } static struct argp_option options[] = { diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index d3e879b8e..d1fae4937 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -33,9 +33,6 @@ datadir="@datadir@" if [ "x$pkgdatadir" = x ]; then pkgdatadir="${datadir}/@PACKAGE@" fi -# export it for scripts -export pkgdatadir - grub_cfg="" grub_mkconfig_dir="${sysconfdir}"/grub.d @@ -59,7 +56,7 @@ usage () { echo print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" print_option_help "-h, --help" "$(gettext "print this message and exit")" - print_option_help "-V, --version" "$(gettext "print the version information and exit")" + print_option_help "-v, --version" "$(gettext "print the version information and exit")" echo gettext "Report bugs to ."; echo } @@ -85,7 +82,7 @@ do -h | --help) usage exit 0 ;; - -V | --version) + -v | --version) echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" exit 0 ;; -o | --output) @@ -134,7 +131,6 @@ fi # Device containing our userland. Typically used for root= parameter. GRUB_DEVICE="`${grub_probe} --target=device /`" GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true -GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2> /dev/null`" || true # Device containing our /boot partition. Usually the same as GRUB_DEVICE. GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" @@ -145,28 +141,13 @@ GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_u GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`" if [ x"$GRUB_FS" = xunknown ]; then - GRUB_FS="$(stat -f -c %T / || echo unknown)" -fi - -# Provide a default set of stock linux early initrd images. -# Define here so the list can be modified in the sourced config file. -if [ "x${GRUB_EARLY_INITRD_LINUX_STOCK}" = "x" ]; then - GRUB_EARLY_INITRD_LINUX_STOCK="intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio" + GRUB_FS="$(stat -f --printf=%T / || echo unknown)" fi if test -f ${sysconfdir}/default/grub ; then . ${sysconfdir}/default/grub fi -if [ "x${GRUB_DISABLE_UUID}" = "xtrue" ]; then - if [ -z "${GRUB_DISABLE_LINUX_UUID}" ]; then - GRUB_DISABLE_LINUX_UUID="true" - fi - if [ -z "${GRUB_DISABLE_LINUX_PARTUUID}" ]; then - GRUB_DISABLE_LINUX_PARTUUID="true" - fi -fi - # XXX: should this be deprecated at some point? if [ "x${GRUB_TERMINAL}" != "x" ] ; then GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}" @@ -198,7 +179,6 @@ if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub # override them. export GRUB_DEVICE \ GRUB_DEVICE_UUID \ - GRUB_DEVICE_PARTUUID \ GRUB_DEVICE_BOOT \ GRUB_DEVICE_BOOT_UUID \ GRUB_FS \ @@ -228,14 +208,10 @@ export GRUB_DEFAULT \ GRUB_CMDLINE_NETBSD \ GRUB_CMDLINE_NETBSD_DEFAULT \ GRUB_CMDLINE_GNUMACH \ - GRUB_EARLY_INITRD_LINUX_CUSTOM \ - GRUB_EARLY_INITRD_LINUX_STOCK \ GRUB_TERMINAL_INPUT \ GRUB_TERMINAL_OUTPUT \ GRUB_SERIAL_COMMAND \ - GRUB_DISABLE_UUID \ GRUB_DISABLE_LINUX_UUID \ - GRUB_DISABLE_LINUX_PARTUUID \ GRUB_DISABLE_RECOVERY \ GRUB_VIDEO_BACKEND \ GRUB_GFXMODE \ @@ -294,11 +270,9 @@ Ensure that there are no errors in /etc/default/grub and /etc/grub.d/* files or please file a bug report with %s file attached." "${grub_cfg}.new" >&2 echo >&2 - exit 1 else # none of the children aborted with error, install the new grub.cfg - cat ${grub_cfg}.new > ${grub_cfg} - rm -f ${grub_cfg}.new + mv -f ${grub_cfg}.new ${grub_cfg} fi fi diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 301d1ac22..29ef865d4 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -34,7 +34,7 @@ if test "x$grub_mkrelpath" = x; then grub_mkrelpath="${bindir}/@grub_mkrelpath@" fi -if command -v gettext >/dev/null; then +if which gettext >/dev/null 2>/dev/null; then : else gettext () { @@ -145,7 +145,7 @@ prepare_grub_to_access_device () done if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then - for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do + for uuid in "`"${grub_probe}" --device $@ --target=cryptodisk_uuid`"; do echo "cryptomount -u $uuid" done fi @@ -156,17 +156,13 @@ prepare_grub_to_access_device () if [ "x$fs_hint" != x ]; then echo "set root='$fs_hint'" fi - if [ "x${GRUB_DISABLE_UUID}" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then + if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints= - if [ "x$hints" != x ]; then - echo "if [ x\$feature_platform_search_hint = xy ]; then" - echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" - echo "else" - echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" - echo "fi" - else - echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" - fi + echo "if [ x\$feature_platform_search_hint = xy ]; then" + echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" + echo "else" + echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" + echo "fi" fi IFS="$old_ifs" } @@ -177,7 +173,7 @@ grub_get_device_id () IFS=' ' device="$1" - if [ "x${GRUB_DISABLE_UUID}" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then + if fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then echo "$fs_uuid"; else echo $device |sed 's, ,_,g' @@ -192,7 +188,6 @@ grub_file_is_not_garbage () *.dpkg-*) return 1 ;; # debian dpkg *.rpmsave|*.rpmnew) return 1 ;; README*|*/README*) return 1 ;; # documentation - *.sig) return 1 ;; # signatures esac else return 1 diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 0fe45a610..a0cab3a93 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -179,6 +179,9 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, if (font_info->flags & GRUB_FONT_FLAG_BOLD) FT_GlyphSlot_Embolden (glyph); + if (glyph->next) + printf ("%x\n", char_code); + if (nocut) cuttop = cutbottom = cutleft = cutright = 0; else diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 912564e36..1e0bcf1bf 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -71,7 +71,6 @@ static struct argp_option options[] = { N_("embed FILE as a memdisk image\n" "Implies `-p (memdisk)/boot/grub' and overrides any prefix supplied previously," " but the prefix itself can be overridden by later options"), 0}, - {"dtb", 'D', N_("FILE"), 0, N_("embed FILE as a device tree (DTB)\n"), 0}, /* TRANSLATORS: "embed" is a verb (command description). "*/ {"config", 'c', N_("FILE"), 0, N_("embed FILE as an early config"), 0}, /* TRANSLATORS: "embed" is a verb (command description). "*/ @@ -118,7 +117,6 @@ struct arguments char *dir; char *prefix; char *memdisk; - char *dtb; char **pubkeys; size_t npubkeys; char *font; @@ -178,13 +176,6 @@ argp_parser (int key, char *arg, struct argp_state *state) arguments->prefix = xstrdup ("(memdisk)/boot/grub"); break; - case 'D': - if (arguments->dtb) - free (arguments->dtb); - - arguments->dtb = xstrdup (arg); - break; - case 'k': arguments->pubkeys = xrealloc (arguments->pubkeys, sizeof (arguments->pubkeys[0]) @@ -249,7 +240,6 @@ main (int argc, char *argv[]) { FILE *fp = stdout; struct arguments arguments; - unsigned i; grub_util_host_init (&argc, &argv); @@ -309,21 +299,13 @@ main (int argc, char *argv[]) arguments.memdisk, arguments.pubkeys, arguments.npubkeys, arguments.config, arguments.image_target, arguments.note, - arguments.comp, arguments.dtb); + arguments.comp); - if (grub_util_file_sync (fp) < 0) - grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout", - strerror (errno)); - if (fclose (fp) == EOF) - grub_util_error (_("cannot close `%s': %s"), arguments.output ? : "stdout", - strerror (errno)); + grub_util_file_sync (fp); + fclose (fp); - for (i = 0; i < arguments.nmodules; i++) - free (arguments.modules[i]); - - free (arguments.dir); - free (arguments.prefix); - free (arguments.modules); + if (arguments.dir) + free (arguments.dir); if (arguments.output) free (arguments.output); diff --git a/util/grub-mkimage32.c b/util/grub-mkimage32.c deleted file mode 100644 index 026a2dd59..000000000 --- a/util/grub-mkimage32.c +++ /dev/null @@ -1,26 +0,0 @@ -#define MKIMAGE_ELF32 1 - -# define SUFFIX(x) x ## 32 -# define ELFCLASSXX ELFCLASS32 -# define Elf_Ehdr Elf32_Ehdr -# define Elf_Phdr Elf32_Phdr -# define Elf_Nhdr Elf32_Nhdr -# define Elf_Addr Elf32_Addr -# define Elf_Sym Elf32_Sym -# define Elf_Off Elf32_Off -# define Elf_Shdr Elf32_Shdr -# define Elf_Rela Elf32_Rela -# define Elf_Rel Elf32_Rel -# define Elf_Word Elf32_Word -# define Elf_Half Elf32_Half -# define Elf_Section Elf32_Section -# define ELF_R_SYM(val) ELF32_R_SYM(val) -# define ELF_R_TYPE(val) ELF32_R_TYPE(val) -# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) - -#define XEN_NOTE_SIZE 132 -#define XEN_PVH_NOTE_SIZE 20 - -#ifndef GRUB_MKIMAGEXX -#include "grub-mkimagexx.c" -#endif diff --git a/util/grub-mkimage64.c b/util/grub-mkimage64.c deleted file mode 100644 index 170defb40..000000000 --- a/util/grub-mkimage64.c +++ /dev/null @@ -1,26 +0,0 @@ -#define MKIMAGE_ELF64 1 - -# define SUFFIX(x) x ## 64 -# define ELFCLASSXX ELFCLASS64 -# define Elf_Ehdr Elf64_Ehdr -# define Elf_Phdr Elf64_Phdr -# define Elf_Nhdr Elf64_Nhdr -# define Elf_Addr Elf64_Addr -# define Elf_Sym Elf64_Sym -# define Elf_Off Elf64_Off -# define Elf_Shdr Elf64_Shdr -# define Elf_Rela Elf64_Rela -# define Elf_Rel Elf64_Rel -# define Elf_Word Elf64_Word -# define Elf_Half Elf64_Half -# define Elf_Section Elf64_Section -# define ELF_R_SYM(val) ELF64_R_SYM(val) -# define ELF_R_TYPE(val) ELF64_R_TYPE(val) -# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val) - -#define XEN_NOTE_SIZE 120 -#define XEN_PVH_NOTE_SIZE 24 - -#ifndef GRUB_MKIMAGEXX -#include "grub-mkimagexx.c" -#endif diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 00f49ccaa..0a1ac9e51 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -17,199 +17,58 @@ * along with GRUB. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#undef ELF_R_SYM +#undef ELF_R_TYPE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#pragma GCC diagnostic ignored "-Wcast-align" - -#define GRUB_MKIMAGEXX -#if !defined(MKIMAGE_ELF32) && !defined(MKIMAGE_ELF64) -#if __SIZEOF_POINTER__ == 8 -#include "grub-mkimage64.c" +#if defined(MKIMAGE_ELF32) +# define SUFFIX(x) x ## 32 +# define ELFCLASSXX ELFCLASS32 +# define Elf_Ehdr Elf32_Ehdr +# define Elf_Phdr Elf32_Phdr +# define Elf_Nhdr Elf32_Nhdr +# define Elf_Addr Elf32_Addr +# define Elf_Sym Elf32_Sym +# define Elf_Off Elf32_Off +# define Elf_Shdr Elf32_Shdr +# define Elf_Rela Elf32_Rela +# define Elf_Rel Elf32_Rel +# define Elf_Word Elf32_Word +# define Elf_Half Elf32_Half +# define Elf_Section Elf32_Section +# define ELF_R_SYM(val) ELF32_R_SYM(val) +# define ELF_R_TYPE(val) ELF32_R_TYPE(val) +# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) +#define XEN_NOTE_SIZE 132 +#elif defined(MKIMAGE_ELF64) +# define SUFFIX(x) x ## 64 +# define ELFCLASSXX ELFCLASS64 +# define Elf_Ehdr Elf64_Ehdr +# define Elf_Phdr Elf64_Phdr +# define Elf_Nhdr Elf64_Nhdr +# define Elf_Addr Elf64_Addr +# define Elf_Sym Elf64_Sym +# define Elf_Off Elf64_Off +# define Elf_Shdr Elf64_Shdr +# define Elf_Rela Elf64_Rela +# define Elf_Rel Elf64_Rel +# define Elf_Word Elf64_Word +# define Elf_Half Elf64_Half +# define Elf_Section Elf64_Section +# define ELF_R_SYM(val) ELF64_R_SYM(val) +# define ELF_R_TYPE(val) ELF64_R_TYPE(val) +# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val) +#define XEN_NOTE_SIZE 120 #else -#include "grub-mkimage32.c" -#endif +#error "I'm confused" #endif -/* These structures are defined according to the CHRP binding to IEEE1275, - "Client Program Format" section. */ +static Elf_Addr SUFFIX (entry_point); -struct grub_ieee1275_note_desc -{ - grub_uint32_t real_mode; - grub_uint32_t real_base; - grub_uint32_t real_size; - grub_uint32_t virt_base; - grub_uint32_t virt_size; - grub_uint32_t load_base; -}; - -#define GRUB_IEEE1275_NOTE_NAME "PowerPC" -#define GRUB_IEEE1275_NOTE_TYPE 0x1275 - -struct grub_ieee1275_note -{ - Elf32_Nhdr header; - char name[ALIGN_UP(sizeof (GRUB_IEEE1275_NOTE_NAME), 4)]; - struct grub_ieee1275_note_desc descriptor; -}; - -#define GRUB_XEN_NOTE_NAME "Xen" - -struct fixup_block_list -{ - struct fixup_block_list *next; - int state; - struct grub_pe32_fixup_block b; -}; - -#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof)) - -struct section_metadata -{ - Elf_Half num_sections; - Elf_Shdr *sections; - Elf_Addr *addrs; - Elf_Addr *vaddrs; - Elf_Half section_entsize; - Elf_Shdr *symtab; - const char *strtab; -}; - -static int -is_relocatable (const struct grub_install_image_target_desc *image_target) -{ - return image_target->id == IMAGE_EFI || image_target->id == IMAGE_UBOOT - || (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM); -} - -#ifdef MKIMAGE_ELF32 - -/* - * R_ARM_THM_CALL/THM_JUMP24 - * - * Relocate Thumb (T32) instruction set relative branches: - * B.W, BL and BLX - */ -static grub_err_t -grub_arm_reloc_thm_call (grub_uint16_t *target, Elf32_Addr sym_addr) -{ - grub_int32_t offset; - - offset = grub_arm_thm_call_get_offset (target); - - grub_dprintf ("dl", " sym_addr = 0x%08x", sym_addr); - - offset += sym_addr; - - grub_dprintf("dl", " BL*: target=%p, sym_addr=0x%08x, offset=%d\n", - target, sym_addr, offset); - - /* Keep traditional (pre-Thumb2) limits on blx. In any case if the kernel - is bigger than 2M (currently under 150K) then we probably have a problem - somewhere else. */ - if (offset < -0x200000 || offset >= 0x200000) - return grub_error (GRUB_ERR_BAD_MODULE, - "THM_CALL Relocation out of range."); - - grub_dprintf ("dl", " relative destination = %p", - (char *) target + offset); - - return grub_arm_thm_call_set_offset (target, offset); -} - -/* - * R_ARM_THM_JUMP19 - * - * Relocate conditional Thumb (T32) B.W - */ -static grub_err_t -grub_arm_reloc_thm_jump19 (grub_uint16_t *target, Elf32_Addr sym_addr) -{ - grub_int32_t offset; - - if (!(sym_addr & 1)) - return grub_error (GRUB_ERR_BAD_MODULE, - "Relocation targeting wrong execution state"); - - offset = grub_arm_thm_jump19_get_offset (target); - - /* Adjust and re-truncate offset */ - offset += sym_addr; - - if (!grub_arm_thm_jump19_check_offset (offset)) - return grub_error (GRUB_ERR_BAD_MODULE, - "THM_JUMP19 Relocation out of range."); - - grub_arm_thm_jump19_set_offset (target, offset); - - return GRUB_ERR_NONE; -} - -/* - * R_ARM_JUMP24 - * - * Relocate ARM (A32) B - */ -static grub_err_t -grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) -{ - grub_int32_t offset; - - if (sym_addr & 1) - return grub_error (GRUB_ERR_BAD_MODULE, - "Relocation targeting wrong execution state"); - - offset = grub_arm_jump24_get_offset (target); - offset += sym_addr; - - if (!grub_arm_jump24_check_offset (offset)) - return grub_error (GRUB_ERR_BAD_MODULE, - "JUMP24 Relocation out of range."); - - - grub_arm_jump24_set_offset (target, offset); - - return GRUB_ERR_NONE; -} - -#endif - -void -SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target, - int note, char **core_img, size_t *core_size, - Elf_Addr target_addr, - struct grub_mkimage_layout *layout) +static void +SUFFIX (generate_elf) (const struct grub_install_image_target_desc *image_target, + int note, char **core_img, size_t *core_size, + Elf_Addr target_addr, grub_size_t align, + size_t kernel_size, size_t bss_size) { char *elf_img; size_t program_size; @@ -229,20 +88,20 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc phnum++; footer_size += sizeof (struct grub_ieee1275_note); } - if (image_target->id == IMAGE_XEN || image_target->id == IMAGE_XEN_PVH) + if (image_target->id == IMAGE_XEN) { phnum++; shnum++; string_size += sizeof (".xen"); - footer_size += (image_target->id == IMAGE_XEN) ? XEN_NOTE_SIZE : XEN_PVH_NOTE_SIZE; + footer_size += XEN_NOTE_SIZE; } header_size = ALIGN_UP (sizeof (*ehdr) + phnum * sizeof (*phdr) - + shnum * sizeof (*shdr) + string_size, layout->align); + + shnum * sizeof (*shdr) + string_size, align); program_size = ALIGN_ADDR (*core_size); elf_img = xmalloc (program_size + header_size + footer_size); - memset (elf_img, 0, program_size + header_size + footer_size); + memset (elf_img, 0, program_size + header_size); memcpy (elf_img + header_size, *core_img, *core_size); ehdr = (void *) elf_img; phdr = (void *) (elf_img + sizeof (*ehdr)); @@ -281,8 +140,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc ehdr->e_entry = grub_host_to_target32 (target_addr); phdr->p_vaddr = grub_host_to_target32 (target_addr); phdr->p_paddr = grub_host_to_target32 (target_addr); - phdr->p_align = grub_host_to_target32 (layout->align > image_target->link_align ? - layout->align : image_target->link_align); + phdr->p_align = grub_host_to_target32 (align > image_target->link_align ? align : image_target->link_align); if (image_target->id == IMAGE_LOONGSON_ELF) ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER | EF_MIPS_PIC | EF_MIPS_CPIC); @@ -296,34 +154,27 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc else { grub_uint32_t target_addr_mods; - phdr->p_filesz = grub_host_to_target32 (layout->kernel_size); - if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM) - phdr->p_memsz = grub_host_to_target32 (layout->kernel_size); - else - phdr->p_memsz = grub_host_to_target32 (layout->kernel_size + layout->bss_size); + phdr->p_filesz = grub_host_to_target32 (kernel_size); + phdr->p_memsz = grub_host_to_target32 (kernel_size + bss_size); phdr++; phdr->p_type = grub_host_to_target32 (PT_GNU_STACK); - phdr->p_offset = grub_host_to_target32 (header_size + layout->kernel_size); + phdr->p_offset = grub_host_to_target32 (header_size + kernel_size); phdr->p_paddr = phdr->p_vaddr = phdr->p_filesz = phdr->p_memsz = 0; phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X); phdr->p_align = grub_host_to_target32 (image_target->link_align); phdr++; phdr->p_type = grub_host_to_target32 (PT_LOAD); - phdr->p_offset = grub_host_to_target32 (header_size + layout->kernel_size); + phdr->p_offset = grub_host_to_target32 (header_size + kernel_size); phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X); phdr->p_filesz = phdr->p_memsz - = grub_host_to_target32 (*core_size - layout->kernel_size); + = grub_host_to_target32 (*core_size - kernel_size); - if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_386) + if (image_target->id == IMAGE_COREBOOT) target_addr_mods = GRUB_KERNEL_I386_COREBOOT_MODULES_ADDR; - else if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM) - target_addr_mods = ALIGN_UP (target_addr + layout->end - + image_target->mod_gap, - image_target->mod_align); else - target_addr_mods = ALIGN_UP (target_addr + layout->kernel_size + layout->bss_size + target_addr_mods = ALIGN_UP (target_addr + kernel_size + bss_size + image_target->mod_gap, image_target->mod_align); phdr->p_vaddr = grub_host_to_target_addr (target_addr_mods); @@ -343,7 +194,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (sizeof (PACKAGE_NAME)); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_GUEST_OS); + note_ptr->n_type = grub_host_to_target32 (6); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -354,7 +205,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (sizeof ("generic")); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_LOADER); + note_ptr->n_type = grub_host_to_target32 (8); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -365,7 +216,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (sizeof ("xen-3.0")); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_XEN_VERSION); + note_ptr->n_type = grub_host_to_target32 (5); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -376,7 +227,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (image_target->voidp_sizeof); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_ENTRY); + note_ptr->n_type = grub_host_to_target32 (1); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -387,7 +238,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (image_target->voidp_sizeof); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_VIRT_BASE); + note_ptr->n_type = grub_host_to_target32 (3); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -400,7 +251,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc note_ptr = (Elf_Nhdr *) ptr; note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); note_ptr->n_descsz = grub_host_to_target32 (sizeof ("yes,bimodal")); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_PAE_MODE); + note_ptr->n_type = grub_host_to_target32 (9); ptr += sizeof (Elf_Nhdr); memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); @@ -421,39 +272,6 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc phdr->p_offset = grub_host_to_target32 (header_size + program_size); } - if (image_target->id == IMAGE_XEN_PVH) - { - char *note_start = (elf_img + program_size + header_size); - Elf_Nhdr *note_ptr; - char *ptr = (char *) note_start; - - grub_util_info ("adding XEN NOTE segment"); - - /* Phys32 Entry. */ - note_ptr = (Elf_Nhdr *) ptr; - note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_XEN_NOTE_NAME)); - note_ptr->n_descsz = grub_host_to_target32 (image_target->voidp_sizeof); - note_ptr->n_type = grub_host_to_target32 (XEN_ELFNOTE_PHYS32_ENTRY); - ptr += sizeof (Elf_Nhdr); - memcpy (ptr, GRUB_XEN_NOTE_NAME, sizeof (GRUB_XEN_NOTE_NAME)); - ptr += ALIGN_UP (sizeof (GRUB_XEN_NOTE_NAME), 4); - memset (ptr, 0, image_target->voidp_sizeof); - *(grub_uint32_t *) ptr = GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR; - ptr += image_target->voidp_sizeof; - - assert (XEN_PVH_NOTE_SIZE == (ptr - note_start)); - - phdr++; - phdr->p_type = grub_host_to_target32 (PT_NOTE); - phdr->p_flags = grub_host_to_target32 (PF_R); - phdr->p_align = grub_host_to_target32 (image_target->voidp_sizeof); - phdr->p_vaddr = 0; - phdr->p_paddr = 0; - phdr->p_filesz = grub_host_to_target32 (XEN_PVH_NOTE_SIZE); - phdr->p_memsz = 0; - phdr->p_offset = grub_host_to_target32 (header_size + program_size); - } - if (note) { int note_size = sizeof (struct grub_ieee1275_note); @@ -463,7 +281,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc grub_util_info ("adding CHRP NOTE segment"); note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_IEEE1275_NOTE_NAME)); - note_ptr->header.n_descsz = grub_host_to_target32 (sizeof (struct grub_ieee1275_note_desc)); + note_ptr->header.n_descsz = grub_host_to_target32 (note_size); note_ptr->header.n_type = grub_host_to_target32 (GRUB_IEEE1275_NOTE_TYPE); strcpy (note_ptr->name, GRUB_IEEE1275_NOTE_NAME); note_ptr->descriptor.real_mode = grub_host_to_target32 (0xffffffff); @@ -498,7 +316,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc shdr->sh_size = grub_host_to_target32 (string_size); shdr->sh_link = grub_host_to_target32 (0); shdr->sh_info = grub_host_to_target32 (0); - shdr->sh_addralign = grub_host_to_target32 (layout->align); + shdr->sh_addralign = grub_host_to_target32 (align); shdr->sh_entsize = grub_host_to_target32 (0); shdr++; @@ -509,10 +327,10 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS); shdr->sh_addr = grub_host_to_target_addr (target_addr); shdr->sh_offset = grub_host_to_target_addr (header_size); - shdr->sh_size = grub_host_to_target32 (layout->kernel_size); + shdr->sh_size = grub_host_to_target32 (kernel_size); shdr->sh_link = grub_host_to_target32 (0); shdr->sh_info = grub_host_to_target32 (0); - shdr->sh_addralign = grub_host_to_target32 (layout->align); + shdr->sh_addralign = grub_host_to_target32 (align); shdr->sh_entsize = grub_host_to_target32 (0); shdr++; @@ -520,27 +338,24 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc shdr->sh_name = grub_host_to_target32 (ptr - str_start); ptr += sizeof ("mods"); shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS); - shdr->sh_addr = grub_host_to_target_addr (target_addr + layout->kernel_size); - shdr->sh_offset = grub_host_to_target_addr (header_size + layout->kernel_size); - shdr->sh_size = grub_host_to_target32 (*core_size - layout->kernel_size); + shdr->sh_addr = grub_host_to_target_addr (target_addr + kernel_size); + shdr->sh_offset = grub_host_to_target_addr (header_size + kernel_size); + shdr->sh_size = grub_host_to_target32 (*core_size - kernel_size); shdr->sh_link = grub_host_to_target32 (0); shdr->sh_info = grub_host_to_target32 (0); shdr->sh_addralign = grub_host_to_target32 (image_target->voidp_sizeof); shdr->sh_entsize = grub_host_to_target32 (0); shdr++; - if (image_target->id == IMAGE_XEN || image_target->id == IMAGE_XEN_PVH) + if (image_target->id == IMAGE_XEN) { memcpy (ptr, ".xen", sizeof (".xen")); shdr->sh_name = grub_host_to_target32 (ptr - str_start); ptr += sizeof (".xen"); shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS); - shdr->sh_addr = grub_host_to_target_addr (target_addr + layout->kernel_size); + shdr->sh_addr = grub_host_to_target_addr (target_addr + kernel_size); shdr->sh_offset = grub_host_to_target_addr (program_size + header_size); - if (image_target->id == IMAGE_XEN) - shdr->sh_size = grub_host_to_target32 (XEN_NOTE_SIZE); - else - shdr->sh_size = grub_host_to_target32 (XEN_PVH_NOTE_SIZE); + shdr->sh_size = grub_host_to_target32 (XEN_NOTE_SIZE); shdr->sh_link = grub_host_to_target32 (0); shdr->sh_info = grub_host_to_target32 (0); shdr->sh_addralign = grub_host_to_target32 (image_target->voidp_sizeof); @@ -557,28 +372,30 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc /* Relocate symbols; note that this function overwrites the symbol table. Return the address of a start symbol. */ static Elf_Addr -SUFFIX (relocate_symbols) (Elf_Ehdr *e, struct section_metadata *smd, +SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, + Elf_Shdr *symtab_section, Elf_Addr *section_addresses, + Elf_Half section_entsize, Elf_Half num_sections, void *jumpers, Elf_Addr jumpers_addr, - Elf_Addr bss_start, Elf_Addr end, const struct grub_install_image_target_desc *image_target) { Elf_Word symtab_size, sym_size, num_syms; Elf_Off symtab_offset; - Elf_Addr start_address = (Elf_Addr) -1; + Elf_Addr start_address = 0; Elf_Sym *sym; Elf_Word i; - Elf_Shdr *symtab_section; - const char *symtab; + Elf_Shdr *strtab_section; + const char *strtab; grub_uint64_t *jptr = jumpers; - symtab_section = (Elf_Shdr *) ((char *) smd->sections - + grub_target_to_host32 (smd->symtab->sh_link) - * smd->section_entsize); - symtab = (char *) e + grub_target_to_host (symtab_section->sh_offset); + strtab_section + = (Elf_Shdr *) ((char *) sections + + (grub_target_to_host32 (symtab_section->sh_link) + * section_entsize)); + strtab = (char *) e + grub_target_to_host (strtab_section->sh_offset); - symtab_size = grub_target_to_host (smd->symtab->sh_size); - sym_size = grub_target_to_host (smd->symtab->sh_entsize); - symtab_offset = grub_target_to_host (smd->symtab->sh_offset); + symtab_size = grub_target_to_host (symtab_section->sh_size); + sym_size = grub_target_to_host (symtab_section->sh_entsize); + symtab_offset = grub_target_to_host (symtab_section->sh_offset); num_syms = symtab_size / sym_size; for (i = 0, sym = (Elf_Sym *) ((char *) e + symtab_offset); @@ -588,7 +405,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, struct section_metadata *smd, Elf_Section cur_index; const char *name; - name = symtab + grub_target_to_host32 (sym->st_name); + name = strtab + grub_target_to_host32 (sym->st_name); cur_index = grub_target_to_host16 (sym->st_shndx); if (cur_index == STN_ABS) @@ -597,22 +414,16 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, struct section_metadata *smd, } else if (cur_index == STN_UNDEF) { - if (sym->st_name && grub_strcmp (name, "__bss_start") == 0) - sym->st_value = bss_start; - else if (sym->st_name && grub_strcmp (name, "_end") == 0) - sym->st_value = end; - else if (sym->st_name) + if (sym->st_name) grub_util_error ("undefined symbol %s", name); else continue; } - else if (cur_index >= smd->num_sections) + else if (cur_index >= num_sections) grub_util_error ("section %d does not exist", cur_index); - else - { - sym->st_value = (grub_target_to_host (sym->st_value) - + smd->vaddrs[cur_index]); - } + + sym->st_value = (grub_target_to_host (sym->st_value) + + section_addresses[cur_index]); if (image_target->elf_target == EM_IA_64 && ELF_ST_TYPE (sym->st_info) == STT_FUNC) @@ -626,9 +437,9 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, struct section_metadata *smd, grub_util_info ("locating %s at 0x%" GRUB_HOST_PRIxLONG_LONG " (0x%" GRUB_HOST_PRIxLONG_LONG ")", name, (unsigned long long) sym->st_value, - (unsigned long long) smd->vaddrs[cur_index]); + (unsigned long long) section_addresses[cur_index]); - if (start_address == (Elf_Addr)-1) + if (! start_address) if (strcmp (name, "_start") == 0 || strcmp (name, "start") == 0) start_address = sym->st_value; } @@ -763,19 +574,17 @@ arm_get_trampoline_size (Elf_Ehdr *e, } #endif -static int -SUFFIX (is_kept_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target); -static int -SUFFIX (is_kept_reloc_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target, - struct section_metadata *smd); - /* Deal with relocation information. This function relocates addresses within the virtual address space starting from 0. So only relative addresses can be fully resolved. Absolute addresses must be relocated again by a PE32 relocator when loaded. */ static void -SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, - char *pe_target, Elf_Addr tramp_off, Elf_Addr got_off, +SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, + Elf_Addr *section_addresses, + Elf_Half section_entsize, Elf_Half num_sections, + const char *strtab, + char *pe_target, Elf_Addr tramp_off, + Elf_Addr got_off, const struct grub_install_image_target_desc *image_target) { Elf_Half i; @@ -783,43 +592,38 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, #ifdef MKIMAGE_ELF64 struct grub_ia64_trampoline *tr = (void *) (pe_target + tramp_off); grub_uint64_t *gpptr = (void *) (pe_target + got_off); - unsigned unmatched_adr_got_page = 0; #define MASK19 ((1 << 19) - 1) #else grub_uint32_t *tr = (void *) (pe_target + tramp_off); #endif - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) if ((s->sh_type == grub_host_to_target32 (SHT_REL)) || (s->sh_type == grub_host_to_target32 (SHT_RELA))) { Elf_Rela *r; Elf_Word rtab_size, r_size, num_rs; Elf_Off rtab_offset; + Elf_Shdr *symtab_section; Elf_Word target_section_index; Elf_Addr target_section_addr; Elf_Shdr *target_section; Elf_Word j; - if (!SUFFIX (is_kept_section) (s, image_target) && - !SUFFIX (is_kept_reloc_section) (s, image_target, smd)) - { - grub_util_info ("not translating relocations for omitted section %s", - smd->strtab + grub_le_to_cpu32 (s->sh_name)); - continue; - } - + symtab_section = (Elf_Shdr *) ((char *) sections + + (grub_target_to_host32 (s->sh_link) + * section_entsize)); target_section_index = grub_target_to_host32 (s->sh_info); - target_section_addr = smd->addrs[target_section_index]; - target_section = (Elf_Shdr *) ((char *) smd->sections + target_section_addr = section_addresses[target_section_index]; + target_section = (Elf_Shdr *) ((char *) sections + (target_section_index - * smd->section_entsize)); + * section_entsize)); grub_util_info ("dealing with the relocation section %s for %s", - smd->strtab + grub_target_to_host32 (s->sh_name), - smd->strtab + grub_target_to_host32 (target_section->sh_name)); + strtab + grub_target_to_host32 (s->sh_name), + strtab + grub_target_to_host32 (target_section->sh_name)); rtab_size = grub_target_to_host (s->sh_size); r_size = grub_target_to_host (s->sh_entsize); @@ -840,7 +644,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, target = SUFFIX (get_target_address) (e, target_section, offset, image_target); info = grub_target_to_host (r->r_info); - sym_addr = SUFFIX (get_symbol_address) (e, smd->symtab, + sym_addr = SUFFIX (get_symbol_address) (e, symtab_section, ELF_R_SYM (info), image_target); addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ? @@ -902,7 +706,6 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, break; case R_X86_64_PC32: - case R_X86_64_PLT32: { grub_uint32_t *t32 = (grub_uint32_t *) target; *t32 = grub_host_to_target64 (grub_target_to_host32 (*t32) @@ -971,14 +774,13 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, Elf_Sym *sym; sym = (Elf_Sym *) ((char *) e - + grub_target_to_host (smd->symtab->sh_offset) - + ELF_R_SYM (info) * grub_target_to_host (smd->symtab->sh_entsize)); + + grub_target_to_host (symtab_section->sh_offset) + + ELF_R_SYM (info) * grub_target_to_host (symtab_section->sh_entsize)); if (ELF_ST_TYPE (sym->st_info) == STT_FUNC) sym_addr = grub_target_to_host64 (*(grub_uint64_t *) (pe_target + sym->st_value - image_target->vaddr_offset)); } - /* FALLTHROUGH */ case R_IA64_LTOFF_FPTR22: *gpptr = grub_host_to_target64 (addend + sym_addr); grub_ia64_add_value_to_slot_21 ((grub_addr_t) target, @@ -991,10 +793,6 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, grub_ia64_add_value_to_slot_21 ((grub_addr_t) target, addend + sym_addr); break; - case R_IA64_GPREL64I: - grub_ia64_set_immu64 ((grub_addr_t) target, - addend + sym_addr); - break; case R_IA64_PCREL64LSB: *target = grub_host_to_target64 (grub_target_to_host64 (*target) + addend + sym_addr @@ -1038,31 +836,11 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, *target = grub_host_to_target64 (grub_target_to_host64 (*target) + sym_addr); } break; - case R_AARCH64_PREL32: - { - grub_uint32_t *t32 = (grub_uint32_t *) target; - *t32 = grub_host_to_target64 (grub_target_to_host32 (*t32) - + sym_addr - - target_section_addr - offset - - image_target->vaddr_offset); - grub_util_info ("relocating an R_AARCH64_PREL32 entry to 0x%x at the offset 0x%" - GRUB_HOST_PRIxLONG_LONG, - *t32, (unsigned long long) offset); - break; - } - case R_AARCH64_ADD_ABS_LO12_NC: - grub_arm64_set_abs_lo12 ((grub_uint32_t *) target, - sym_addr); - break; - case R_AARCH64_LDST64_ABS_LO12_NC: - grub_arm64_set_abs_lo12_ldst64 ((grub_uint32_t *) target, - sym_addr); - break; case R_AARCH64_JUMP26: case R_AARCH64_CALL26: { sym_addr -= offset; - sym_addr -= target_section_addr + image_target->vaddr_offset; + sym_addr -= SUFFIX (entry_point); if (!grub_arm_64_check_xxxx26_offset (sym_addr)) grub_util_error ("%s", "CALL26 Relocation out of range"); @@ -1070,52 +848,6 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, sym_addr); } break; - case R_AARCH64_ADR_GOT_PAGE: - { - Elf64_Rela *rel2; - grub_int64_t gpoffset = (((char *) gpptr - (char *) pe_target + image_target->vaddr_offset) & ~0xfffULL) - - ((offset + target_section_addr + image_target->vaddr_offset) & ~0xfffULL); - unsigned k; - *gpptr = grub_host_to_target64 (sym_addr); - unmatched_adr_got_page++; - if (!grub_arm64_check_hi21_signed (gpoffset)) - grub_util_error ("HI21 out of range"); - grub_arm64_set_hi21((grub_uint32_t *)target, - gpoffset); - for (k = 0, rel2 = (Elf_Rela *) ((char *) r + r_size); - k < num_rs; - k++, rel2 = (Elf_Rela *) ((char *) rel2 + r_size)) - if (ELF_R_SYM (rel2->r_info) - == ELF_R_SYM (r->r_info) - && r->r_addend == rel2->r_addend - && ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC) - { - grub_arm64_set_abs_lo12_ldst64 ((grub_uint32_t *) SUFFIX (get_target_address) (e, target_section, - grub_target_to_host (rel2->r_offset), image_target), - ((char *) gpptr - (char *) pe_target + image_target->vaddr_offset)); - break; - } - if (k >= num_rs) - grub_util_error ("ADR_GOT_PAGE without matching LD64_GOT_LO12_NC"); - gpptr++; - } - break; - case R_AARCH64_LD64_GOT_LO12_NC: - if (unmatched_adr_got_page == 0) - grub_util_error ("LD64_GOT_LO12_NC without matching ADR_GOT_PAGE"); - unmatched_adr_got_page--; - break; - case R_AARCH64_ADR_PREL_PG_HI21: - { - sym_addr &= ~0xfffULL; - sym_addr -= (offset + target_section_addr + image_target->vaddr_offset) & ~0xfffULL; - if (!grub_arm64_check_hi21_signed (sym_addr)) - grub_util_error ("%s", "CALL26 Relocation out of range"); - - grub_arm64_set_hi21((grub_uint32_t *)target, - sym_addr); - } - break; default: grub_util_error (_("relocation 0x%x is not implemented yet"), (unsigned int) ELF_R_TYPE (info)); @@ -1128,7 +860,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, case EM_ARM: { sym_addr += addend; - sym_addr -= image_target->vaddr_offset; + sym_addr -= SUFFIX (entry_point); switch (ELF_R_TYPE (info)) { case R_ARM_ABS32: @@ -1136,8 +868,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, grub_util_info (" ABS32:\toffset=%d\t(0x%08x)", (int) sym_addr, (int) sym_addr); /* Data will be naturally aligned */ - if (image_target->id == IMAGE_EFI) - sym_addr += GRUB_PE32_SECTION_ALIGNMENT; + sym_addr += 0x400; *target = grub_host_to_target32 (grub_target_to_host32 (*target) + sym_addr); } break; @@ -1151,16 +882,10 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, case R_ARM_THM_JUMP19: { grub_err_t err; - Elf_Sym *sym; grub_util_info (" THM_JUMP24:\ttarget=0x%08lx\toffset=(0x%08x)", (unsigned long) ((char *) target - (char *) e), sym_addr); - sym = (Elf_Sym *) ((char *) e - + grub_target_to_host (smd->symtab->sh_offset) - + ELF_R_SYM (info) * grub_target_to_host (smd->symtab->sh_entsize)); - if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) - sym_addr |= 1; if (!(sym_addr & 1)) { grub_uint32_t tr_addr; @@ -1226,196 +951,6 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, break; } #endif /* MKIMAGE_ELF32 */ - case EM_RISCV: - { - grub_uint64_t *t64 = (grub_uint64_t *) target; - grub_uint32_t *t32 = (grub_uint32_t *) target; - grub_uint16_t *t16 = (grub_uint16_t *) target; - grub_uint8_t *t8 = (grub_uint8_t *) target; - grub_int64_t off; - - /* - * Instructions and instruction encoding are documented in the RISC-V - * specification. This file is based on version 2.2: - * - * https://github.com/riscv/riscv-isa-manual/blob/master/release/riscv-spec-v2.2.pdf - */ - - sym_addr += addend; - off = sym_addr - target_section_addr - offset - image_target->vaddr_offset; - - switch (ELF_R_TYPE (info)) - { - case R_RISCV_ADD8: - *t8 = *t8 + sym_addr; - break; - case R_RISCV_ADD16: - *t16 = grub_host_to_target16 (grub_target_to_host16 (*t16) + sym_addr); - break; - case R_RISCV_32: - case R_RISCV_ADD32: - *t32 = grub_host_to_target32 (grub_target_to_host32 (*t32) + sym_addr); - break; - case R_RISCV_64: - case R_RISCV_ADD64: - *t64 = grub_host_to_target64 (grub_target_to_host64 (*t64) + sym_addr); - break; - - case R_RISCV_SUB8: - *t8 = sym_addr - *t8; - break; - case R_RISCV_SUB16: - *t16 = grub_host_to_target16 (grub_target_to_host16 (*t16) - sym_addr); - break; - case R_RISCV_SUB32: - *t32 = grub_host_to_target32 (grub_target_to_host32 (*t32) - sym_addr); - break; - case R_RISCV_SUB64: - *t64 = grub_host_to_target64 (grub_target_to_host64 (*t64) - sym_addr); - break; - case R_RISCV_BRANCH: - { - grub_uint32_t imm12 = (off & 0x1000) << (31 - 12); - grub_uint32_t imm11 = (off & 0x800) >> (11 - 7); - grub_uint32_t imm10_5 = (off & 0x7e0) << (30 - 10); - grub_uint32_t imm4_1 = (off & 0x1e) << (11 - 4); - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) - | imm12 | imm11 | imm10_5 | imm4_1); - } - break; - case R_RISCV_JAL: - { - grub_uint32_t imm20 = (off & 0x100000) << (31 - 20); - grub_uint32_t imm19_12 = (off & 0xff000); - grub_uint32_t imm11 = (off & 0x800) << (20 - 11); - grub_uint32_t imm10_1 = (off & 0x7fe) << (30 - 10); - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) - | imm20 | imm19_12 | imm11 | imm10_1); - } - break; - case R_RISCV_CALL: - { - grub_uint32_t hi20, lo12; - - if (off != (grub_int32_t)off) - grub_util_error ("target %lx not reachable from pc=%lx", (long)sym_addr, (long)((char *)target - (char *)e)); - - hi20 = (off + 0x800) & 0xfffff000; - lo12 = (off - hi20) & 0xfff; - t32[0] = grub_host_to_target32 ((grub_target_to_host32 (t32[0]) & 0xfff) | hi20); - t32[1] = grub_host_to_target32 ((grub_target_to_host32 (t32[1]) & 0xfffff) | (lo12 << 20)); - } - break; - case R_RISCV_RVC_BRANCH: - { - grub_uint16_t imm8 = (off & 0x100) << (12 - 8); - grub_uint16_t imm7_6 = (off & 0xc0) >> (6 - 5); - grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); - grub_uint16_t imm4_3 = (off & 0x18) << (12 - 5); - grub_uint16_t imm2_1 = (off & 0x6) << (12 - 10); - *t16 = grub_host_to_target16 ((grub_target_to_host16 (*t16) & 0xe383) - | imm8 | imm7_6 | imm5 | imm4_3 | imm2_1); - } - break; - case R_RISCV_RVC_JUMP: - { - grub_uint16_t imm11 = (off & 0x800) << (12 - 11); - grub_uint16_t imm10 = (off & 0x400) >> (10 - 8); - grub_uint16_t imm9_8 = (off & 0x300) << (12 - 11); - grub_uint16_t imm7 = (off & 0x80) >> (7 - 6); - grub_uint16_t imm6 = (off & 0x40) << (12 - 11); - grub_uint16_t imm5 = (off & 0x20) >> (5 - 2); - grub_uint16_t imm4 = (off & 0x10) << (12 - 5); - grub_uint16_t imm3_1 = (off & 0xe) << (12 - 10); - *t16 = grub_host_to_target16 ((grub_target_to_host16 (*t16) & 0xe003) - | imm11 | imm10 | imm9_8 | imm7 | imm6 - | imm5 | imm4 | imm3_1); - } - break; - case R_RISCV_PCREL_HI20: - { - grub_int32_t hi20; - - if (off != (grub_int32_t)off) - grub_util_error ("target %lx not reachable from pc=%lx", (long)sym_addr, (long)((char *)target - (char *)e)); - - hi20 = (off + 0x800) & 0xfffff000; - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) | hi20); - } - break; - case R_RISCV_PCREL_LO12_I: - case R_RISCV_PCREL_LO12_S: - { - Elf_Rela *rel2; - Elf_Word k; - /* Search backwards for matching HI20 reloc. */ - for (k = j, rel2 = (Elf_Rela *) ((char *) r - r_size); - k > 0; - k--, rel2 = (Elf_Rela *) ((char *) rel2 - r_size)) - { - Elf_Addr rel2_info; - Elf_Addr rel2_offset; - Elf_Addr rel2_sym_addr; - Elf_Addr rel2_addend; - Elf_Addr rel2_loc; - grub_int64_t rel2_off; - - rel2_offset = grub_target_to_host (rel2->r_offset); - rel2_info = grub_target_to_host (rel2->r_info); - rel2_loc = target_section_addr + rel2_offset + image_target->vaddr_offset; - - if (ELF_R_TYPE (rel2_info) == R_RISCV_PCREL_HI20 - && rel2_loc == sym_addr) - { - rel2_sym_addr = SUFFIX (get_symbol_address) - (e, smd->symtab, ELF_R_SYM (rel2_info), - image_target); - rel2_addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ? - grub_target_to_host (rel2->r_addend) : 0; - rel2_off = rel2_sym_addr + rel2_addend - rel2_loc; - off = rel2_off - ((rel2_off + 0x800) & 0xfffff000); - - if (ELF_R_TYPE (info) == R_RISCV_PCREL_LO12_I) - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfffff) | (off & 0xfff) << 20); - else - { - grub_uint32_t imm11_5 = (off & 0xfe0) << (31 - 11); - grub_uint32_t imm4_0 = (off & 0x1f) << (11 - 4); - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) | imm11_5 | imm4_0); - } - break; - } - } - if (k == 0) - grub_util_error ("cannot find matching HI20 relocation"); - } - break; - case R_RISCV_HI20: - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfff) | (((grub_int32_t) sym_addr + 0x800) & 0xfffff000)); - break; - case R_RISCV_LO12_I: - { - grub_int32_t lo12 = (grub_int32_t) sym_addr - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0xfffff) | ((lo12 & 0xfff) << 20)); - } - break; - case R_RISCV_LO12_S: - { - grub_int32_t lo12 = (grub_int32_t) sym_addr - (((grub_int32_t) sym_addr + 0x800) & 0xfffff000); - grub_uint32_t imm11_5 = (lo12 & 0xfe0) << (31 - 11); - grub_uint32_t imm4_0 = (lo12 & 0x1f) << (11 - 4); - *t32 = grub_host_to_target32 ((grub_target_to_host32 (*t32) & 0x1fff07f) | imm11_5 | imm4_0); - } - break; - case R_RISCV_RELAX: - break; - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; - } default: grub_util_error ("unknown architecture type %d", image_target->elf_target); @@ -1427,9 +962,9 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, /* Add a PE32's fixup entry for a relocation. Return the resulting address after having written to the file OUT. */ static Elf_Addr -add_fixup_entry (struct fixup_block_list **cblock, grub_uint16_t type, - Elf_Addr addr, int flush, Elf_Addr current_address, - const struct grub_install_image_target_desc *image_target) +SUFFIX (add_fixup_entry) (struct fixup_block_list **cblock, grub_uint16_t type, + Elf_Addr addr, int flush, Elf_Addr current_address, + const struct grub_install_image_target_desc *image_target) { struct grub_pe32_fixup_block *b; @@ -1519,453 +1054,25 @@ add_fixup_entry (struct fixup_block_list **cblock, grub_uint16_t type, return current_address; } -struct raw_reloc -{ - struct raw_reloc *next; - grub_uint32_t offset; - enum raw_reloc_type { - RAW_RELOC_NONE = -1, - RAW_RELOC_32 = 0, - RAW_RELOC_MAX = 1, - } type; -}; - -struct translate_context -{ - /* PE */ - struct fixup_block_list *lst, *lst0; - Elf_Addr current_address; - - /* Raw */ - struct raw_reloc *raw_relocs; -}; - -static void -translate_reloc_start (struct translate_context *ctx, - const struct grub_install_image_target_desc *image_target) -{ - grub_memset (ctx, 0, sizeof (*ctx)); - if (image_target->id == IMAGE_EFI) - { - ctx->lst = ctx->lst0 = xmalloc (sizeof (*ctx->lst) + 2 * 0x1000); - memset (ctx->lst, 0, sizeof (*ctx->lst) + 2 * 0x1000); - ctx->current_address = 0; - } -} - -static void -translate_relocation_pe (struct translate_context *ctx, - Elf_Addr addr, - Elf_Addr info, - const struct grub_install_image_target_desc *image_target) -{ - /* Necessary to relocate only absolute addresses. */ - switch (image_target->elf_target) - { - case EM_386: - if (ELF_R_TYPE (info) == R_386_32) - { - grub_util_info ("adding a relocation entry for 0x%" - GRUB_HOST_PRIxLONG_LONG, - (unsigned long long) addr); - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_HIGHLOW, - addr, 0, ctx->current_address, - image_target); - } - break; - case EM_X86_64: - if ((ELF_R_TYPE (info) == R_X86_64_32) || - (ELF_R_TYPE (info) == R_X86_64_32S)) - { - grub_util_error ("can\'t add fixup entry for R_X86_64_32(S)"); - } - else if (ELF_R_TYPE (info) == R_X86_64_64) - { - grub_util_info ("adding a relocation entry for 0x%" - GRUB_HOST_PRIxLONG_LONG, - (unsigned long long) addr); - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_DIR64, - addr, - 0, ctx->current_address, - image_target); - } - break; - case EM_IA_64: - switch (ELF_R_TYPE (info)) - { - case R_IA64_PCREL64LSB: - case R_IA64_LDXMOV: - case R_IA64_PCREL21B: - case R_IA64_LTOFF_FPTR22: - case R_IA64_LTOFF22X: - case R_IA64_LTOFF22: - case R_IA64_GPREL22: - case R_IA64_GPREL64I: - case R_IA64_SEGREL64LSB: - break; - - case R_IA64_FPTR64LSB: - case R_IA64_DIR64LSB: -#if 1 - { - grub_util_info ("adding a relocation entry for 0x%" - GRUB_HOST_PRIxLONG_LONG, - (unsigned long long) addr); - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_DIR64, - addr, - 0, ctx->current_address, - image_target); - } -#endif - break; - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; - case EM_AARCH64: - switch (ELF_R_TYPE (info)) - { - case R_AARCH64_ABS64: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_DIR64, - addr, 0, ctx->current_address, - image_target); - } - break; - /* Relative relocations do not require fixup entries. */ - case R_AARCH64_CALL26: - case R_AARCH64_JUMP26: - case R_AARCH64_PREL32: - break; - /* Page-relative relocations do not require fixup entries. */ - case R_AARCH64_ADR_PREL_PG_HI21: - /* We page-align the whole kernel, so no need - for fixup entries. - */ - case R_AARCH64_ADD_ABS_LO12_NC: - case R_AARCH64_LDST64_ABS_LO12_NC: - break; - - /* GOT is relocated separately. */ - case R_AARCH64_ADR_GOT_PAGE: - case R_AARCH64_LD64_GOT_LO12_NC: - break; - - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; - break; -#if defined(MKIMAGE_ELF32) - case EM_ARM: - switch (ELF_R_TYPE (info)) - { - case R_ARM_V4BX: - /* Relative relocations do not require fixup entries. */ - case R_ARM_JUMP24: - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP19: - case R_ARM_THM_JUMP24: - case R_ARM_CALL: - { - grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) ctx->current_address); - } - break; - /* Create fixup entry for PE/COFF loader */ - case R_ARM_ABS32: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_HIGHLOW, - addr, 0, ctx->current_address, - image_target); - } - break; - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; -#endif /* defined(MKIMAGE_ELF32) */ - case EM_RISCV: - switch (ELF_R_TYPE (info)) - { - case R_RISCV_32: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_HIGHLOW, - addr, 0, ctx->current_address, - image_target); - } - break; - case R_RISCV_64: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_DIR64, - addr, 0, ctx->current_address, - image_target); - } - break; - /* Relative relocations do not require fixup entries. */ - case R_RISCV_BRANCH: - case R_RISCV_JAL: - case R_RISCV_CALL: - case R_RISCV_PCREL_HI20: - case R_RISCV_PCREL_LO12_I: - case R_RISCV_PCREL_LO12_S: - case R_RISCV_RVC_BRANCH: - case R_RISCV_RVC_JUMP: - case R_RISCV_ADD32: - case R_RISCV_SUB32: - grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) ctx->current_address); - break; - case R_RISCV_HI20: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_RISCV_HI20, - addr, 0, ctx->current_address, - image_target); - } - break; - case R_RISCV_LO12_I: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_RISCV_LOW12I, - addr, 0, ctx->current_address, - image_target); - } - break; - case R_RISCV_LO12_S: - { - ctx->current_address - = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_RISCV_LOW12S, - addr, 0, ctx->current_address, - image_target); - } - break; - case R_RISCV_RELAX: - break; - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; - default: - grub_util_error ("unknown machine type 0x%x", image_target->elf_target); - } -} - -static enum raw_reloc_type -classify_raw_reloc (Elf_Addr info, - const struct grub_install_image_target_desc *image_target) -{ - /* Necessary to relocate only absolute addresses. */ - switch (image_target->elf_target) - { - case EM_ARM: - switch (ELF_R_TYPE (info)) - { - case R_ARM_V4BX: - case R_ARM_JUMP24: - case R_ARM_THM_CALL: - case R_ARM_THM_JUMP19: - case R_ARM_THM_JUMP24: - case R_ARM_CALL: - return RAW_RELOC_NONE; - case R_ARM_ABS32: - return RAW_RELOC_32; - default: - grub_util_error (_("relocation 0x%x is not implemented yet"), - (unsigned int) ELF_R_TYPE (info)); - break; - } - break; - default: - grub_util_error ("unknown machine type 0x%x", image_target->elf_target); - } -} - -static void -translate_relocation_raw (struct translate_context *ctx, - Elf_Addr addr, - Elf_Addr info, - const struct grub_install_image_target_desc *image_target) -{ - enum raw_reloc_type class = classify_raw_reloc (info, image_target); - struct raw_reloc *rel; - if (class == RAW_RELOC_NONE) - return; - rel = xmalloc (sizeof (*rel)); - rel->next = ctx->raw_relocs; - rel->type = class; - rel->offset = addr; - ctx->raw_relocs = rel; -} - -static void -translate_relocation (struct translate_context *ctx, - Elf_Addr addr, - Elf_Addr info, - const struct grub_install_image_target_desc *image_target) -{ - if (image_target->id == IMAGE_EFI) - translate_relocation_pe (ctx, addr, info, image_target); - else - translate_relocation_raw (ctx, addr, info, image_target); -} - -static void -finish_reloc_translation_pe (struct translate_context *ctx, struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target) -{ - ctx->current_address = add_fixup_entry (&ctx->lst, 0, 0, 1, ctx->current_address, image_target); - - { - grub_uint8_t *ptr; - layout->reloc_section = ptr = xmalloc (ctx->current_address); - for (ctx->lst = ctx->lst0; ctx->lst; ctx->lst = ctx->lst->next) - if (ctx->lst->state) - { - memcpy (ptr, &ctx->lst->b, grub_target_to_host32 (ctx->lst->b.block_size)); - ptr += grub_target_to_host32 (ctx->lst->b.block_size); - } - assert ((ctx->current_address + (grub_uint8_t *) layout->reloc_section) == ptr); - } - - for (ctx->lst = ctx->lst0; ctx->lst; ) - { - struct fixup_block_list *next; - next = ctx->lst->next; - free (ctx->lst); - ctx->lst = next; - } - - layout->reloc_size = ctx->current_address; - if (image_target->elf_target == EM_ARM && layout->reloc_size > GRUB_KERNEL_ARM_STACK_SIZE) - grub_util_error ("Reloc section (%d) is bigger than stack size (%d). " - "This breaks assembly assumptions. Please increase stack size", - (int) layout->reloc_size, - (int) GRUB_KERNEL_ARM_STACK_SIZE); -} - -/* - Layout: - - - - - ... - - - each relocation starts with 32-bit offset. Rest depends on relocation. - mkimage stops when it sees first unknown type or end marker. - This allows images to be created with mismatched mkimage and - kernel as long as no relocations are present in kernel that mkimage - isn't aware of (in which case mkimage aborts). - This also allows simple assembly to do the relocs. -*/ - -#define RAW_SEPARATOR 0xfffffffe -#define RAW_END_MARKER 0xffffffff - -static void -finish_reloc_translation_raw (struct translate_context *ctx, struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target) -{ - size_t count = 0, sz; - enum raw_reloc_type highest = RAW_RELOC_NONE; - enum raw_reloc_type curtype; - struct raw_reloc *cur; - grub_uint32_t *p; - if (!ctx->raw_relocs) - { - layout->reloc_section = p = xmalloc (sizeof (grub_uint32_t)); - p[0] = RAW_END_MARKER; - layout->reloc_size = sizeof (grub_uint32_t); - return; - } - for (cur = ctx->raw_relocs; cur; cur = cur->next) - { - count++; - if (cur->type > highest) - highest = cur->type; - } - /* highest separators, count relocations and one end marker. */ - sz = (highest + count + 1) * sizeof (grub_uint32_t); - layout->reloc_section = p = xmalloc (sz); - for (curtype = 0; curtype <= highest; curtype++) - { - /* Support for special cases would go here. */ - for (cur = ctx->raw_relocs; cur; cur = cur->next) - if (cur->type == curtype) - { - *p++ = cur->offset; - } - *p++ = RAW_SEPARATOR; - } - *--p = RAW_END_MARKER; - layout->reloc_size = sz; -} - -static void -finish_reloc_translation (struct translate_context *ctx, struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target) -{ - if (image_target->id == IMAGE_EFI) - finish_reloc_translation_pe (ctx, layout, image_target); - else - finish_reloc_translation_raw (ctx, layout, image_target); -} - - -static void -create_u64_fixups (struct translate_context *ctx, - Elf_Addr jumpers, grub_size_t njumpers, - const struct grub_install_image_target_desc *image_target) -{ - unsigned i; - assert (image_target->id == IMAGE_EFI); - for (i = 0; i < njumpers; i++) - ctx->current_address = add_fixup_entry (&ctx->lst, - GRUB_PE32_REL_BASED_DIR64, - jumpers + 8 * i, - 0, ctx->current_address, - image_target); -} - /* Make a .reloc section. */ -static void -make_reloc_section (Elf_Ehdr *e, struct grub_mkimage_layout *layout, - struct section_metadata *smd, - const struct grub_install_image_target_desc *image_target) +static Elf_Addr +SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out, + Elf_Addr *section_addresses, Elf_Shdr *sections, + Elf_Half section_entsize, Elf_Half num_sections, + const char *strtab, + Elf_Addr jumpers, grub_size_t njumpers, + const struct grub_install_image_target_desc *image_target) { unsigned i; Elf_Shdr *s; - struct translate_context ctx; + struct fixup_block_list *lst, *lst0; + Elf_Addr current_address = 0; - translate_reloc_start (&ctx, image_target); + lst = lst0 = xmalloc (sizeof (*lst) + 2 * 0x1000); + memset (lst, 0, sizeof (*lst) + 2 * 0x1000); - for (i = 0, s = smd->sections; i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) + for (i = 0, s = sections; i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) if ((grub_target_to_host32 (s->sh_type) == SHT_REL) || (grub_target_to_host32 (s->sh_type) == SHT_RELA)) { @@ -1975,22 +1082,15 @@ make_reloc_section (Elf_Ehdr *e, struct grub_mkimage_layout *layout, Elf_Addr section_address; Elf_Word j; - if (!SUFFIX (is_kept_reloc_section) (s, image_target, smd)) - { - grub_util_info ("not translating the skipped relocation section %s", - smd->strtab + grub_le_to_cpu32 (s->sh_name)); - continue; - } - grub_util_info ("translating the relocation section %s", - smd->strtab + grub_le_to_cpu32 (s->sh_name)); + strtab + grub_le_to_cpu32 (s->sh_name)); rtab_size = grub_target_to_host (s->sh_size); r_size = grub_target_to_host (s->sh_entsize); rtab_offset = grub_target_to_host (s->sh_offset); num_rs = rtab_size / r_size; - section_address = smd->vaddrs[grub_le_to_cpu32 (s->sh_info)]; + section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)]; for (j = 0, r = (Elf_Rel *) ((char *) e + rtab_offset); j < num_rs; @@ -1998,31 +1098,190 @@ make_reloc_section (Elf_Ehdr *e, struct grub_mkimage_layout *layout, { Elf_Addr info; Elf_Addr offset; - Elf_Addr addr; offset = grub_target_to_host (r->r_offset); info = grub_target_to_host (r->r_info); - addr = section_address + offset; + /* Necessary to relocate only absolute addresses. */ + switch (image_target->elf_target) + { + case EM_386: + if (ELF_R_TYPE (info) == R_386_32) + { + Elf_Addr addr; - translate_relocation (&ctx, addr, info, image_target); + addr = section_address + offset; + grub_util_info ("adding a relocation entry for 0x%" + GRUB_HOST_PRIxLONG_LONG, + (unsigned long long) addr); + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_HIGHLOW, + addr, 0, current_address, + image_target); + } + break; + case EM_X86_64: + if ((ELF_R_TYPE (info) == R_X86_64_32) || + (ELF_R_TYPE (info) == R_X86_64_32S)) + { + grub_util_error ("can\'t add fixup entry for R_X86_64_32(S)"); + } + else if (ELF_R_TYPE (info) == R_X86_64_64) + { + Elf_Addr addr; + + addr = section_address + offset; + grub_util_info ("adding a relocation entry for 0x%" + GRUB_HOST_PRIxLONG_LONG, + (unsigned long long) addr); + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + addr, + 0, current_address, + image_target); + } + break; + case EM_IA_64: + switch (ELF_R_TYPE (info)) + { + case R_IA64_PCREL64LSB: + case R_IA64_LDXMOV: + case R_IA64_PCREL21B: + case R_IA64_LTOFF_FPTR22: + case R_IA64_LTOFF22X: + case R_IA64_LTOFF22: + case R_IA64_GPREL22: + case R_IA64_SEGREL64LSB: + break; + + case R_IA64_FPTR64LSB: + case R_IA64_DIR64LSB: +#if 1 + { + Elf_Addr addr; + + addr = section_address + offset; + grub_util_info ("adding a relocation entry for 0x%" + GRUB_HOST_PRIxLONG_LONG, + (unsigned long long) addr); + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + addr, + 0, current_address, + image_target); + } +#endif + break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); + break; + } + break; + case EM_AARCH64: + switch (ELF_R_TYPE (info)) + { + case R_AARCH64_ABS64: + { + Elf_Addr addr; + + addr = section_address + offset; + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + addr, 0, current_address, + image_target); + } + break; + /* Relative relocations do not require fixup entries. */ + case R_AARCH64_CALL26: + case R_AARCH64_JUMP26: + break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); + break; + } + break; + break; +#if defined(MKIMAGE_ELF32) + case EM_ARM: + switch (ELF_R_TYPE (info)) + { + case R_ARM_V4BX: + /* Relative relocations do not require fixup entries. */ + case R_ARM_JUMP24: + case R_ARM_THM_CALL: + case R_ARM_THM_JUMP19: + case R_ARM_THM_JUMP24: + case R_ARM_CALL: + { + Elf_Addr addr; + + addr = section_address + offset; + grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) current_address); + } + break; + /* Create fixup entry for PE/COFF loader */ + case R_ARM_ABS32: + { + Elf_Addr addr; + + addr = section_address + offset; + current_address + = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_HIGHLOW, + addr, 0, current_address, + image_target); + } + break; + default: + grub_util_error (_("relocation 0x%x is not implemented yet"), + (unsigned int) ELF_R_TYPE (info)); + break; + } + break; +#endif /* defined(MKIMAGE_ELF32) */ + default: + grub_util_error ("unknown machine type 0x%x", image_target->elf_target); + } } } if (image_target->elf_target == EM_IA_64) - create_u64_fixups (&ctx, - layout->ia64jmp_off - + image_target->vaddr_offset, - 2 * layout->ia64jmpnum, - image_target); - if (image_target->elf_target == EM_IA_64 || image_target->elf_target == EM_AARCH64) - create_u64_fixups (&ctx, - layout->got_off - + image_target->vaddr_offset, - (layout->got_size / 8), - image_target); + for (i = 0; i < njumpers; i++) + current_address = SUFFIX (add_fixup_entry) (&lst, + GRUB_PE32_REL_BASED_DIR64, + jumpers + 8 * i, + 0, current_address, + image_target); - finish_reloc_translation (&ctx, layout, image_target); + current_address = SUFFIX (add_fixup_entry) (&lst, 0, 0, 1, current_address, image_target); + + { + grub_uint8_t *ptr; + ptr = *out = xmalloc (current_address); + for (lst = lst0; lst; lst = lst->next) + if (lst->state) + { + memcpy (ptr, &lst->b, grub_target_to_host32 (lst->b.block_size)); + ptr += grub_target_to_host32 (lst->b.block_size); + } + assert ((current_address + (grub_uint8_t *) *out) == ptr); + } + + for (lst = lst0; lst; ) + { + struct fixup_block_list *next; + next = lst->next; + free (lst); + lst = next; + } + + return current_address; } /* Determine if this section is a text section. Return false if this @@ -2030,81 +1289,24 @@ make_reloc_section (Elf_Ehdr *e, struct grub_mkimage_layout *layout, static int SUFFIX (is_text_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target) { - if (!is_relocatable (image_target) + if (image_target->id != IMAGE_EFI && grub_target_to_host32 (s->sh_type) != SHT_PROGBITS) return 0; return ((grub_target_to_host (s->sh_flags) & (SHF_EXECINSTR | SHF_ALLOC)) == (SHF_EXECINSTR | SHF_ALLOC)); } -/* Determine if this section is a data section. */ +/* Determine if this section is a data section. This assumes that + BSS is also a data section, since the converter initializes BSS + when producing PE32 to avoid a bug in EFI implementations. */ static int SUFFIX (is_data_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target) { - if (!is_relocatable (image_target) + if (image_target->id != IMAGE_EFI && grub_target_to_host32 (s->sh_type) != SHT_PROGBITS) return 0; return ((grub_target_to_host (s->sh_flags) & (SHF_EXECINSTR | SHF_ALLOC)) - == SHF_ALLOC) && !(grub_target_to_host32 (s->sh_type) == SHT_NOBITS); -} - -static int -SUFFIX (is_bss_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target) -{ - if (!is_relocatable (image_target)) - return 0; - return ((grub_target_to_host (s->sh_flags) & (SHF_EXECINSTR | SHF_ALLOC)) - == SHF_ALLOC) && (grub_target_to_host32 (s->sh_type) == SHT_NOBITS); -} - -/* Determine if a section is going to be in the final output */ -static int -SUFFIX (is_kept_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target) -{ - /* We keep .text and .data */ - if (SUFFIX (is_text_section) (s, image_target) - || SUFFIX (is_data_section) (s, image_target)) - return 1; - - /* - * And we keep .bss if we're producing PE binaries or the target doesn't - * have a relocating loader. Platforms other than EFI and U-boot shouldn't - * have .bss in their binaries as we build with -Wl,-Ttext. - */ - if (SUFFIX (is_bss_section) (s, image_target) - && (image_target->id == IMAGE_EFI || !is_relocatable (image_target))) - return 1; - - /* Otherwise this is not a section we're keeping in the final output. */ - return 0; -} - -static int -SUFFIX (is_kept_reloc_section) (Elf_Shdr *s, const struct grub_install_image_target_desc *image_target, - struct section_metadata *smd) -{ - int i; - int r = 0; - const char *name = smd->strtab + grub_host_to_target32 (s->sh_name); - - if (!strncmp (name, ".rela.", 6)) - name += 5; - else if (!strncmp (name, ".rel.", 5)) - name += 4; - else - return 1; - - for (i = 0, s = smd->sections; i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - { - const char *sname = smd->strtab + grub_host_to_target32 (s->sh_name); - if (strcmp (sname, name)) - continue; - - return SUFFIX (is_kept_section) (s, image_target); - } - - return r; + == SHF_ALLOC); } /* Return if the ELF header is valid. */ @@ -2124,14 +1326,84 @@ SUFFIX (check_elf_header) (Elf_Ehdr *e, size_t size, const struct grub_install_i return 1; } -static Elf_Addr -SUFFIX (put_section) (Elf_Shdr *s, int i, - Elf_Addr current_address, - struct section_metadata *smd, - const struct grub_install_image_target_desc *image_target) +/* Locate section addresses by merging code sections and data sections + into .text and .data, respectively. Return the array of section + addresses. */ +static Elf_Addr * +SUFFIX (locate_sections) (const char *kernel_path, + Elf_Shdr *sections, Elf_Half section_entsize, + Elf_Half num_sections, const char *strtab, + size_t *exec_size, size_t *kernel_sz, + size_t *all_align, + const struct grub_install_image_target_desc *image_target) { + int i; + Elf_Addr current_address; + Elf_Addr *section_addresses; + Elf_Shdr *s; + + *all_align = 1; + + section_addresses = xmalloc (sizeof (*section_addresses) * num_sections); + memset (section_addresses, 0, sizeof (*section_addresses) * num_sections); + + current_address = 0; + + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) + if ((grub_target_to_host (s->sh_flags) & SHF_ALLOC) + && grub_host_to_target32 (s->sh_addralign) > *all_align) + *all_align = grub_host_to_target32 (s->sh_addralign); + + + /* .text */ + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) + if (SUFFIX (is_text_section) (s, image_target)) + { Elf_Word align = grub_host_to_target_addr (s->sh_addralign); - const char *name = smd->strtab + grub_host_to_target32 (s->sh_name); + const char *name = strtab + grub_host_to_target32 (s->sh_name); + if (align) + current_address = ALIGN_UP (current_address + image_target->vaddr_offset, + align) - image_target->vaddr_offset; + grub_util_info ("locating the section %s at 0x%" + GRUB_HOST_PRIxLONG_LONG, + name, (unsigned long long) current_address); + if (image_target->id != IMAGE_EFI) + { + current_address = grub_host_to_target_addr (s->sh_addr) + - image_target->link_addr; + if (grub_host_to_target_addr (s->sh_addr) + != image_target->link_addr) + { + char *msg + = grub_xasprintf (_("`%s' is miscompiled: its start address is 0x%llx" + " instead of 0x%llx: ld.gold bug?"), + kernel_path, + (unsigned long long) grub_host_to_target_addr (s->sh_addr), + (unsigned long long) image_target->link_addr); + grub_util_error ("%s", msg); + } + } + section_addresses[i] = current_address; + current_address += grub_host_to_target_addr (s->sh_size); + } + + current_address = ALIGN_UP (current_address + image_target->vaddr_offset, + image_target->section_align) + - image_target->vaddr_offset; + *exec_size = current_address; + + /* .data */ + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) + if (SUFFIX (is_data_section) (s, image_target)) + { + Elf_Word align = grub_host_to_target_addr (s->sh_addralign); + const char *name = strtab + grub_host_to_target32 (s->sh_name); if (align) current_address = ALIGN_UP (current_address + image_target->vaddr_offset, @@ -2141,135 +1413,45 @@ SUFFIX (put_section) (Elf_Shdr *s, int i, grub_util_info ("locating the section %s at 0x%" GRUB_HOST_PRIxLONG_LONG, name, (unsigned long long) current_address); - if (!is_relocatable (image_target)) + if (image_target->id != IMAGE_EFI) current_address = grub_host_to_target_addr (s->sh_addr) - - image_target->link_addr; - smd->addrs[i] = current_address; + - image_target->link_addr; + section_addresses[i] = current_address; current_address += grub_host_to_target_addr (s->sh_size); - return current_address; -} - -/* - * Locate section addresses by merging code sections and data sections - * into .text and .data, respectively. - */ -static void -SUFFIX (locate_sections) (Elf_Ehdr *e, const char *kernel_path, - struct section_metadata *smd, - struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target) -{ - int i; - Elf_Shdr *s; - - layout->align = 1; - /* Page-aligning simplifies relocation handling. */ - if (image_target->elf_target == EM_AARCH64) - layout->align = 4096; - - layout->kernel_size = 0; - - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - if ((grub_target_to_host (s->sh_flags) & SHF_ALLOC) - && grub_host_to_target32 (s->sh_addralign) > layout->align) - layout->align = grub_host_to_target32 (s->sh_addralign); - - /* .text */ - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - if (SUFFIX (is_text_section) (s, image_target)) - { - layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size, - smd, image_target); - if (!is_relocatable (image_target) && - grub_host_to_target_addr (s->sh_addr) != image_target->link_addr) - { - char *msg - = grub_xasprintf (_("`%s' is miscompiled: its start address is 0x%llx" - " instead of 0x%llx: ld.gold bug?"), - kernel_path, - (unsigned long long) grub_host_to_target_addr (s->sh_addr), - (unsigned long long) image_target->link_addr); - grub_util_error ("%s", msg); - } } -#ifdef MKIMAGE_ELF32 - if (image_target->elf_target == EM_ARM) - { - grub_size_t tramp; - - layout->kernel_size = ALIGN_UP (layout->kernel_size, 16); - - tramp = arm_get_trampoline_size (e, smd->sections, smd->section_entsize, - smd->num_sections, image_target); - - layout->tramp_off = layout->kernel_size; - layout->kernel_size += ALIGN_UP (tramp, 16); - } -#endif - - layout->kernel_size = ALIGN_UP (layout->kernel_size + image_target->vaddr_offset, - image_target->section_align) - - image_target->vaddr_offset; - layout->exec_size = layout->kernel_size; - - /* .data */ - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - if (SUFFIX (is_data_section) (s, image_target)) - layout->kernel_size = SUFFIX (put_section) (s, i, layout->kernel_size, smd, - image_target); - - layout->bss_start = layout->kernel_size; - layout->end = layout->kernel_size; - - /* .bss */ - for (i = 0, s = smd->sections; - i < smd->num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd->section_entsize)) - { - if (SUFFIX (is_bss_section) (s, image_target)) - layout->end = SUFFIX (put_section) (s, i, layout->end, smd, image_target); - - /* - * This must to be in the last time this function passes through the loop. - */ - smd->vaddrs[i] = smd->addrs[i] + image_target->vaddr_offset; - } - - layout->end = ALIGN_UP (layout->end + image_target->vaddr_offset, + current_address = ALIGN_UP (current_address + image_target->vaddr_offset, image_target->section_align) - image_target->vaddr_offset; - /* Explicitly initialize BSS - when producing PE32 to avoid a bug in EFI implementations. - Platforms other than EFI and U-boot shouldn't have .bss in - their binaries as we build with -Wl,-Ttext. - */ - if (image_target->id == IMAGE_EFI || !is_relocatable (image_target)) - layout->kernel_size = layout->end; + *kernel_sz = current_address; + return section_addresses; } -char * -SUFFIX (grub_mkimage_load_image) (const char *kernel_path, - size_t total_module_size, - struct grub_mkimage_layout *layout, - const struct grub_install_image_target_desc *image_target) +static char * +SUFFIX (load_image) (const char *kernel_path, size_t *exec_size, + size_t *kernel_sz, size_t *bss_size, + size_t total_module_size, grub_uint64_t *start, + void **reloc_section, size_t *reloc_size, + size_t *align, + const struct grub_install_image_target_desc *image_target) { char *kernel_img, *out_img; - struct section_metadata smd = { 0, 0, 0, 0, 0, 0, 0 }; + const char *strtab; Elf_Ehdr *e; + Elf_Shdr *sections; + Elf_Addr *section_addresses; + Elf_Addr *section_vaddresses; int i; Elf_Shdr *s; + Elf_Half num_sections; Elf_Off section_offset; + Elf_Half section_entsize; grub_size_t kernel_size; + grub_size_t ia64jmp_off = 0, tramp_off = 0, ia64_got_off = 0; + unsigned ia64jmpnum = 0; + Elf_Shdr *symtab_section = 0; + grub_size_t got = 0; - grub_memset (layout, 0, sizeof (*layout)); - - layout->start_address = 0; + *start = 0; kernel_size = grub_util_get_image_size (kernel_path); kernel_img = xmalloc (kernel_size); @@ -2280,169 +1462,200 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, grub_util_error ("invalid ELF header"); section_offset = grub_target_to_host (e->e_shoff); - smd.section_entsize = grub_target_to_host16 (e->e_shentsize); - smd.num_sections = grub_target_to_host16 (e->e_shnum); + section_entsize = grub_target_to_host16 (e->e_shentsize); + num_sections = grub_target_to_host16 (e->e_shnum); - if (kernel_size < section_offset - + (grub_uint32_t) smd.section_entsize * smd.num_sections) + if (kernel_size < section_offset + section_entsize * num_sections) grub_util_error (_("premature end of file %s"), kernel_path); - smd.sections = (Elf_Shdr *) (kernel_img + section_offset); + sections = (Elf_Shdr *) (kernel_img + section_offset); /* Relocate sections then symbols in the virtual address space. */ - s = (Elf_Shdr *) ((char *) smd.sections - + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); - smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); + s = (Elf_Shdr *) ((char *) sections + + grub_host_to_target16 (e->e_shstrndx) * section_entsize); + strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); - smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); - smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); + section_addresses = SUFFIX (locate_sections) (kernel_path, + sections, section_entsize, + num_sections, strtab, + exec_size, kernel_sz, align, + image_target); - SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); + section_vaddresses = xmalloc (sizeof (*section_addresses) * num_sections); - if (!is_relocatable (image_target)) + for (i = 0; i < num_sections; i++) + section_vaddresses[i] = section_addresses[i] + image_target->vaddr_offset; + + if (image_target->id != IMAGE_EFI) { - Elf_Addr current_address = layout->kernel_size; + Elf_Addr current_address = *kernel_sz; - for (i = 0, s = smd.sections; - i < smd.num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd.section_entsize)) + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) if (grub_target_to_host32 (s->sh_type) == SHT_NOBITS) { Elf_Word sec_align = grub_host_to_target_addr (s->sh_addralign); - const char *name = smd.strtab + grub_host_to_target32 (s->sh_name); + const char *name = strtab + grub_host_to_target32 (s->sh_name); if (sec_align) current_address = ALIGN_UP (current_address + image_target->vaddr_offset, sec_align) - image_target->vaddr_offset; - + grub_util_info ("locating the section %s at 0x%" GRUB_HOST_PRIxLONG_LONG, name, (unsigned long long) current_address); - if (!is_relocatable (image_target)) + if (image_target->id != IMAGE_EFI) current_address = grub_host_to_target_addr (s->sh_addr) - image_target->link_addr; - smd.vaddrs[i] = current_address + section_vaddresses[i] = current_address + image_target->vaddr_offset; current_address += grub_host_to_target_addr (s->sh_size); } current_address = ALIGN_UP (current_address + image_target->vaddr_offset, image_target->section_align) - image_target->vaddr_offset; - layout->bss_size = current_address - layout->kernel_size; + *bss_size = current_address - *kernel_sz; } else - layout->bss_size = 0; + *bss_size = 0; if (image_target->id == IMAGE_SPARC64_AOUT || image_target->id == IMAGE_SPARC64_RAW - || image_target->id == IMAGE_UBOOT - || image_target->id == IMAGE_COREBOOT || image_target->id == IMAGE_SPARC64_CDCORE) - layout->kernel_size = ALIGN_UP (layout->kernel_size, image_target->mod_align); + *kernel_sz = ALIGN_UP (*kernel_sz, image_target->mod_align); - if (is_relocatable (image_target)) + if (image_target->id == IMAGE_EFI) { - smd.symtab = NULL; - for (i = 0, s = smd.sections; - i < smd.num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd.section_entsize)) + symtab_section = NULL; + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) if (s->sh_type == grub_host_to_target32 (SHT_SYMTAB)) { - smd.symtab = s; + symtab_section = s; break; } - if (! smd.symtab) - grub_util_error ("%s", _("no symbol table")); + +#ifdef MKIMAGE_ELF32 + if (image_target->elf_target == EM_ARM) + { + grub_size_t tramp; + + *kernel_sz = ALIGN_UP (*kernel_sz, 16); + + tramp = arm_get_trampoline_size (e, sections, section_entsize, + num_sections, image_target); + + tramp_off = *kernel_sz; + *kernel_sz += ALIGN_UP (tramp, 16); + } +#endif + #ifdef MKIMAGE_ELF64 if (image_target->elf_target == EM_IA_64) { grub_size_t tramp; - layout->kernel_size = ALIGN_UP (layout->kernel_size, 16); + *kernel_sz = ALIGN_UP (*kernel_sz, 16); - grub_ia64_dl_get_tramp_got_size (e, &tramp, &layout->got_size); + grub_ia64_dl_get_tramp_got_size (e, &tramp, &got); - layout->tramp_off = layout->kernel_size; - layout->kernel_size += ALIGN_UP (tramp, 16); + tramp_off = *kernel_sz; + *kernel_sz += ALIGN_UP (tramp, 16); - layout->ia64jmp_off = layout->kernel_size; - layout->ia64jmpnum = SUFFIX (count_funcs) (e, smd.symtab, - image_target); - layout->kernel_size += 16 * layout->ia64jmpnum; + ia64jmp_off = *kernel_sz; + ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section, + image_target); + *kernel_sz += 16 * ia64jmpnum; - layout->got_off = layout->kernel_size; - layout->kernel_size += ALIGN_UP (layout->got_size, 16); - } - if (image_target->elf_target == EM_AARCH64) - { - grub_size_t tramp; - - layout->kernel_size = ALIGN_UP (layout->kernel_size, 16); - - grub_arm64_dl_get_tramp_got_size (e, &tramp, &layout->got_size); - - layout->got_off = layout->kernel_size; - layout->kernel_size += ALIGN_UP (layout->got_size, 16); + ia64_got_off = *kernel_sz; + *kernel_sz += ALIGN_UP (got, 16); } #endif + + if (! symtab_section) + grub_util_error ("%s", _("no symbol table")); } else { - layout->reloc_size = 0; - layout->reloc_section = NULL; + *reloc_size = 0; + *reloc_section = NULL; } - out_img = xmalloc (layout->kernel_size + total_module_size); - memset (out_img, 0, layout->kernel_size + total_module_size); + out_img = xmalloc (*kernel_sz + total_module_size); - if (is_relocatable (image_target)) + if (image_target->id == IMAGE_EFI) { - layout->start_address = SUFFIX (relocate_symbols) (e, &smd, - (char *) out_img + layout->ia64jmp_off, - layout->ia64jmp_off + image_target->vaddr_offset, - layout->bss_start, layout->end, image_target); - - if (layout->start_address == (Elf_Addr) -1) + *start = SUFFIX (relocate_symbols) (e, sections, symtab_section, + section_vaddresses, section_entsize, + num_sections, + (char *) out_img + ia64jmp_off, + ia64jmp_off + + image_target->vaddr_offset, + image_target); + if (*start == 0) grub_util_error ("start symbol is not defined"); - /* Resolve addrs in the virtual address space. */ - SUFFIX (relocate_addrs) (e, &smd, out_img, layout->tramp_off, - layout->got_off, image_target); + SUFFIX (entry_point) = (Elf_Addr) *start; - make_reloc_section (e, layout, &smd, image_target); - if (image_target->id != IMAGE_EFI) - { - out_img = xrealloc (out_img, layout->kernel_size + total_module_size - + ALIGN_UP (layout->reloc_size, image_target->mod_align)); - memcpy (out_img + layout->kernel_size, layout->reloc_section, layout->reloc_size); - memset (out_img + layout->kernel_size + layout->reloc_size, 0, - total_module_size + ALIGN_UP (layout->reloc_size, image_target->mod_align) - layout->reloc_size); - layout->kernel_size += ALIGN_UP (layout->reloc_size, image_target->mod_align); - } + /* Resolve addresses in the virtual address space. */ + SUFFIX (relocate_addresses) (e, sections, section_addresses, + section_entsize, + num_sections, strtab, + out_img, tramp_off, ia64_got_off, + image_target); + + *reloc_size = SUFFIX (make_reloc_section) (e, reloc_section, + section_vaddresses, sections, + section_entsize, num_sections, + strtab, ia64jmp_off + + image_target->vaddr_offset, + 2 * ia64jmpnum + (got / 8), + image_target); } - for (i = 0, s = smd.sections; - i < smd.num_sections; - i++, s = (Elf_Shdr *) ((char *) s + smd.section_entsize)) - if (SUFFIX (is_kept_section) (s, image_target)) + for (i = 0, s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) + if (SUFFIX (is_data_section) (s, image_target) + || SUFFIX (is_text_section) (s, image_target)) { if (grub_target_to_host32 (s->sh_type) == SHT_NOBITS) - memset (out_img + smd.addrs[i], 0, + memset (out_img + section_addresses[i], 0, grub_host_to_target_addr (s->sh_size)); else - memcpy (out_img + smd.addrs[i], + memcpy (out_img + section_addresses[i], kernel_img + grub_host_to_target_addr (s->sh_offset), grub_host_to_target_addr (s->sh_size)); } free (kernel_img); - free (smd.vaddrs); - smd.vaddrs = NULL; - free (smd.addrs); - smd.addrs = NULL; + free (section_vaddresses); + free (section_addresses); return out_img; } + + +#undef SUFFIX +#undef ELFCLASSXX +#undef Elf_Ehdr +#undef Elf_Phdr +#undef Elf_Nhdr +#undef Elf_Shdr +#undef Elf_Addr +#undef Elf_Sym +#undef Elf_Off +#undef Elf_Rela +#undef Elf_Rel +#undef ELF_R_TYPE +#undef ELF_R_SYM +#undef Elf_Word +#undef Elf_Half +#undef Elf_Section +#undef ELF_ST_TYPE +#undef XEN_NOTE_SIZE diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index d171c2700..1a4f1b4c8 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -384,13 +384,6 @@ write_keymaps (FILE *in, FILE *out, const char *out_filename) sscanf (line, "keycode %u = %60s %60s %60s %60s", &keycode_linux, normal, shift, normalalt, shiftalt); - if (keycode_linux >= ARRAY_SIZE (linux_to_usb_map)) - { - /* TRANSLATORS: scan code is keyboard key numeric identifier. */ - fprintf (stderr, _("Unknown keyboard scan code 0x%02x\n"), keycode_linux); - continue; - } - /* Not used. */ if (keycode_linux == 0x77 /* Pause */ /* Some obscure keys */ diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c index 602574d52..8366a1121 100644 --- a/util/grub-mknetdir.c +++ b/util/grub-mknetdir.c @@ -106,10 +106,7 @@ static const struct [GRUB_INSTALL_PLATFORM_I386_EFI] = { "i386-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" }, [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" }, - [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" }, - [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" }, - [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" }, - [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" }, + [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" } }; static void @@ -143,7 +140,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) prefix = xasprintf ("/%s", subdir); if (!targets[platform].mkimage_target) - grub_util_error (_("unsupported platform %s"), platsub); + grub_util_error (_("unsupported platform %s\n"), platsub); grub_cfg = grub_util_path_concat (2, grubdir, "grub.cfg"); cfg = grub_util_fopen (grub_cfg, "wb"); diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c index 51831027f..e71983982 100644 --- a/util/grub-mkrescue.c +++ b/util/grub-mkrescue.c @@ -44,6 +44,9 @@ static char *label_color; static char *label_bgcolor; static char *product_name; static char *product_version; +static int xorriso_tail_argc; +static int xorriso_tail_arg_alloc; +static char **xorriso_tail_argv; static char *output_image; static char *xorriso; static char *boot_grub; @@ -212,6 +215,16 @@ argp_parser (int key, char *arg, struct argp_state *state) xorriso = xstrdup (arg); return 0; + case ARGP_KEY_ARG: + if (xorriso_tail_arg_alloc <= xorriso_tail_argc) + { + xorriso_tail_arg_alloc = 2 * (4 + xorriso_tail_argc); + xorriso_tail_argv = xrealloc (xorriso_tail_argv, + sizeof (xorriso_tail_argv[0]) + * xorriso_tail_arg_alloc); + } + xorriso_tail_argv[xorriso_tail_argc++] = xstrdup (arg); + return 0; default: return ARGP_ERR_UNKNOWN; } @@ -310,7 +323,6 @@ make_image_fwdisk_abs (enum grub_install_plat plat, grub_install_make_image_wrap (source_dirs[plat], "()/boot/grub", output, 0, load_cfg, mkimage_target, 0); grub_install_pop_module (); - grub_util_unlink (load_cfg); } static int @@ -323,7 +335,6 @@ check_xorriso (const char *val) char *buf = NULL; size_t len = 0; int ret = 0; - int wstatus = 0; argv[0] = xorriso; argv[1] = "-as"; @@ -348,10 +359,8 @@ check_xorriso (const char *val) } close (fd); - waitpid (pid, &wstatus, 0); + waitpid (pid, NULL, 0); free (buf); - if (!WIFEXITED (wstatus) || WEXITSTATUS(wstatus) != 0) - return 0; return ret; } @@ -365,71 +374,12 @@ make_image_fwdisk (enum grub_install_plat plat, free (out); } -static int -option_is_end (const struct argp_option *opt) -{ - return !opt->key && !opt->name && !opt->doc && !opt->group; -} - - -static int -args_to_eat (const char *arg) -{ - int j; - - if (arg[0] != '-') - return 0; - - if (arg[1] == '-') - { - for (j = 0; !option_is_end(&options[j]); j++) - { - size_t len = strlen (options[j].name); - if (strncmp (arg + 2, options[j].name, len) == 0) - { - if (arg[2 + len] == '=') - return 1; - if (arg[2 + len] == '\0' && options[j].arg) - return 2; - if (arg[2 + len] == '\0') - return 1; - } - } - if (strcmp (arg, "--help") == 0) - return 1; - if (strcmp (arg, "--usage") == 0) - return 1; - if (strcmp (arg, "--version") == 0) - return 1; - return 0; - } - if (arg[2] && arg[3]) - return 0; - for (j = 0; !option_is_end(&options[j]); j++) - { - if (options[j].key > 0 && options[j].key < 128 && arg[1] == options[j].key) - { - if (options[j].arg) - return 2; - return 1; - } - if (arg[1] == '?') - return 1; - } - return 0; -} - int main (int argc, char *argv[]) { char *romdir; char *sysarea_img = NULL; const char *pkgdatadir; - int argp_argc; - char **argp_argv; - int xorriso_tail_argc; - char **xorriso_tail_argv; - int rv; grub_util_host_init (&argc, &argv); grub_util_disable_fd_syncs (); @@ -441,51 +391,11 @@ main (int argc, char *argv[]) xorriso = xstrdup ("xorriso"); label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); - argp_argv = xcalloc (argc, sizeof (argp_argv[0])); - xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); - - xorriso_tail_argc = 0; - /* Program name */ - argp_argv[0] = argv[0]; - argp_argc = 1; - - /* argp doesn't allow us to catch unknwon arguments, - so catch them before passing to argp - */ - { - int i; - for (i = 1; i < argc; i++) - { - if (strcmp (argv[i], "-output") == 0) { - argp_argv[argp_argc++] = (char *) "--output"; - i++; - argp_argv[argp_argc++] = argv[i]; - continue; - } - switch (args_to_eat (argv[i])) - { - case 2: - argp_argv[argp_argc++] = argv[i++]; - /* Fallthrough */ - case 1: - argp_argv[argp_argc++] = argv[i]; - break; - case 0: - xorriso_tail_argv[xorriso_tail_argc++] = argv[i]; - break; - } - } - } - - argp_parse (&argp, argp_argc, argp_argv, 0, 0, 0); + argp_parse (&argp, argc, argv, 0, 0, 0); if (!output_image) grub_util_error ("%s", _("output file must be specified")); - if (!check_xorriso ("graft-points")) { - grub_util_error ("%s", _("xorriso not found")); - } - grub_init_all (); grub_hostfs_init (); grub_host_init (); @@ -538,8 +448,6 @@ main (int argc, char *argv[]) || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI] - || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI] - || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]) system_area = SYS_AREA_COMMON; else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275]) @@ -658,7 +566,6 @@ main (int argc, char *argv[]) } grub_install_pop_module (); grub_install_pop_module (); - grub_util_unlink (load_cfg); } /** build multiboot core.img */ @@ -737,9 +644,7 @@ main (int argc, char *argv[]) || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI] - || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI] - || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI] - || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]) + || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]) { char *efidir = grub_util_make_temporary_dir (); char *efidir_efi = grub_util_path_concat (2, efidir, "efi"); @@ -748,9 +653,6 @@ main (int argc, char *argv[]) char *efiimgfat; grub_install_mkdir_p (efidir_efi_boot); - grub_install_push_module ("part_gpt"); - grub_install_push_module ("part_msdos"); - imgname = grub_util_path_concat (2, efidir_efi_boot, "bootia64.efi"); make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, "ia64-efi", imgname); free (imgname); @@ -774,16 +676,6 @@ main (int argc, char *argv[]) imgname); free (imgname); - imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi", - imgname); - free (imgname); - - imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi", - imgname); - free (imgname); - if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]) { imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi"); @@ -809,13 +701,9 @@ main (int argc, char *argv[]) free (efidir_efi_boot); efiimgfat = grub_util_path_concat (2, iso9660_dir, "efi.img"); - rv = grub_util_exec ((const char * []) { "mformat", "-C", "-f", "2880", "-L", "16", "-i", + grub_util_exec ((const char * []) { "mformat", "-C", "-f", "2880", "-L", "16", "-i", efiimgfat, "::", NULL }); - if (rv != 0) - grub_util_error ("`%s` invocation failed\n", "mformat"); - rv = grub_util_exec ((const char * []) { "mcopy", "-s", "-i", efiimgfat, efidir_efi, "::/", NULL }); - if (rv != 0) - grub_util_error ("`%s` invocation failed\n", "mcopy"); + grub_util_exec ((const char * []) { "mcopy", "-s", "-i", efiimgfat, efidir_efi, "::/", NULL }); xorriso_push ("--efi-boot"); xorriso_push ("efi.img"); xorriso_push ("-efi-boot-part"); @@ -825,8 +713,6 @@ main (int argc, char *argv[]) free (efiimgfat); free (efidir_efi); free (efidir); - grub_install_pop_module (); - grub_install_pop_module (); } grub_install_push_module ("part_apple"); @@ -981,9 +867,7 @@ main (int argc, char *argv[]) xorriso_argv[xorriso_argc] = NULL; - rv = grub_util_exec ((const char *const *)xorriso_argv); - if (rv != 0) - grub_util_error ("`%s` invocation failed\n", "xorriso"); + grub_util_exec ((const char *const *)xorriso_argv); grub_util_unlink_recursive (iso9660_dir); diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c index edf309717..6017d7155 100644 --- a/util/grub-mkstandalone.c +++ b/util/grub-mkstandalone.c @@ -284,7 +284,6 @@ add_tar_file (const char *from, grub_util_fd_close (in); write_pad (size); - free (tcn); } int @@ -296,7 +295,7 @@ main (int argc, char *argv[]) grub_util_host_init (&argc, &argv); grub_util_disable_fd_syncs (); - files = xcalloc (argc + 1, sizeof (files[0])); + files = xmalloc ((argc + 1) * sizeof (files[0])); argp_parse (&argp, argc, argv, 0, 0, 0); diff --git a/util/grub-module-verifier.c b/util/grub-module-verifier.c deleted file mode 100644 index 163529ca9..000000000 --- a/util/grub-module-verifier.c +++ /dev/null @@ -1,234 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -struct grub_module_verifier_arch archs[] = { - { "i386", 4, 0, EM_386, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){ - R_386_32, - R_386_PC32, - -1 - } }, - { "x86_64", 8, 0, EM_X86_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_X86_64_64, - R_X86_64_PC64, - /* R_X86_64_32, R_X86_64_32S are supported but shouldn't be used because of their limited range. */ - -1 - }, (int[]){ - R_X86_64_PC32, - R_X86_64_PLT32, - -1 - } - }, - { "powerpc", 4, 1, EM_PPC, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - GRUB_ELF_R_PPC_ADDR16_LO, - GRUB_ELF_R_PPC_REL24, /* It has limited range but GRUB adds trampolines when necessarry. */ - GRUB_ELF_R_PPC_ADDR16_HA, - GRUB_ELF_R_PPC_ADDR32, - GRUB_ELF_R_PPC_REL32, - GRUB_ELF_R_PPC_PLTREL24, - -1 - } }, - { "sparc64", 8, 1, EM_SPARCV9, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_SPARC_WDISP30, /* It has limited range but GRUB adds trampolines when necessarry. */ - R_SPARC_HH22, - R_SPARC_HM10, - R_SPARC_LM22, - R_SPARC_LO10, - R_SPARC_64, - R_SPARC_OLO10, - /* Following 2 relocations have limited range but unfortunately - clang generates them, as it doesn't implement mcmodel=large properly. - At least our heap and core are under 4G, so it's not a problem - usually. */ - R_SPARC_HI22, - R_SPARC_32, - -1 - } }, - { "ia64", 8, 0, EM_IA_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_IA64_PCREL21B, /* We should verify that it's pointing either - to a function or to a section in the same module. - Checking that external symbol is a function is - non-trivial and I have never seen this relocation used - for anything else, so assume that it always points to a - function. - */ - R_IA64_SEGREL64LSB, - R_IA64_FPTR64LSB, - R_IA64_DIR64LSB, - R_IA64_PCREL64LSB, - R_IA64_LTOFF22X, - R_IA64_LTOFF22, - R_IA64_GPREL64I, - R_IA64_LTOFF_FPTR22, - R_IA64_LDXMOV, - -1 - }, (int[]){ - R_IA64_GPREL22, - -1 - } }, - { "mipsel", 4, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_MIPS_HI16, - R_MIPS_LO16, - R_MIPS_32, - R_MIPS_GPREL32, - R_MIPS_26, - R_MIPS_GOT16, - R_MIPS_CALL16, - R_MIPS_JALR, - -1 - } }, - { "mips", 4, 1, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_MIPS_HI16, - R_MIPS_LO16, - R_MIPS_32, - R_MIPS_GPREL32, - R_MIPS_26, - R_MIPS_GOT16, - R_MIPS_CALL16, - R_MIPS_JALR, - -1 - } }, - { "arm", 4, 0, EM_ARM, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){ - /* Some relocations are range-limited but trampolines are added when necessarry. */ - R_ARM_ABS32, - R_ARM_CALL, - R_ARM_JUMP24, - R_ARM_THM_CALL, - R_ARM_THM_JUMP24, - R_ARM_V4BX, - R_ARM_THM_MOVW_ABS_NC, - R_ARM_THM_MOVT_ABS, - R_ARM_THM_JUMP19, - -1 - } }, - { "arm64", 8, 0, EM_AARCH64, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_AARCH64_ABS64, - R_AARCH64_CALL26, - R_AARCH64_JUMP26, - R_AARCH64_ADR_GOT_PAGE, - R_AARCH64_LD64_GOT_LO12_NC, - -1 - }, (int[]){ - R_AARCH64_ADR_PREL_PG_HI21, - R_AARCH64_ADD_ABS_LO12_NC, - R_AARCH64_LDST64_ABS_LO12_NC, - R_AARCH64_PREL32, - -1 - } }, - { "riscv32", 4, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_RISCV_32, - R_RISCV_64, - R_RISCV_ADD8, - R_RISCV_ADD16, - R_RISCV_ADD32, - R_RISCV_ADD64, - R_RISCV_SUB8, - R_RISCV_SUB16, - R_RISCV_SUB32, - R_RISCV_SUB64, - R_RISCV_ALIGN, - R_RISCV_BRANCH, - R_RISCV_CALL, - R_RISCV_CALL_PLT, - R_RISCV_GOT_HI20, - R_RISCV_HI20, - R_RISCV_JAL, - R_RISCV_LO12_I, - R_RISCV_LO12_S, - R_RISCV_PCREL_HI20, - R_RISCV_PCREL_LO12_I, - R_RISCV_PCREL_LO12_S, - R_RISCV_RELAX, - R_RISCV_RVC_BRANCH, - R_RISCV_RVC_JUMP, - -1 - } }, - { "riscv64", 8, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){ - R_RISCV_32, - R_RISCV_64, - R_RISCV_ADD8, - R_RISCV_ADD16, - R_RISCV_ADD32, - R_RISCV_ADD64, - R_RISCV_SUB8, - R_RISCV_SUB16, - R_RISCV_SUB32, - R_RISCV_SUB64, - R_RISCV_ALIGN, - R_RISCV_BRANCH, - R_RISCV_CALL, - R_RISCV_CALL_PLT, - R_RISCV_GOT_HI20, - R_RISCV_HI20, - R_RISCV_JAL, - R_RISCV_LO12_I, - R_RISCV_LO12_S, - R_RISCV_PCREL_HI20, - R_RISCV_PCREL_LO12_I, - R_RISCV_PCREL_LO12_S, - R_RISCV_RELAX, - R_RISCV_RVC_BRANCH, - R_RISCV_RVC_JUMP, - -1 - } - }, -}; - -struct platform_whitelist { - const char *arch; - const char *platform; - const char **whitelist_empty; -}; - -static struct platform_whitelist whitelists[] = { - {"i386", "xen", (const char *[]) {"all_video", 0}}, - {"i386", "xen_pvh", (const char *[]) {"all_video", 0}}, - {"x86_64", "xen", (const char *[]) {"all_video", 0}}, - {"sparc64", "ieee1275", (const char *[]) {"all_video", 0}}, - - /* video is compiled-in on MIPS. */ - {"mipsel", "loongson", (const char *[]) {"all_video", 0}}, - {"mipsel", "qemu_mips", (const char *[]) {"all_video", 0}}, - {"mipsel", "arc", (const char *[]) {"all_video", 0}}, - {"mips", "qemu_mips", (const char *[]) {"all_video", 0}}, - {"mips", "arc", (const char *[]) {"all_video", 0}}, -}; - - -int -main (int argc, char **argv) -{ - size_t module_size; - unsigned arch, whitelist; - const char **whitelist_empty = 0; - char *module_img; - if (argc != 4) { - fprintf (stderr, "usage: %s FILE ARCH PLATFORM\n", argv[0]); - return 1; - } - - for (arch = 0; arch < ARRAY_SIZE(archs); arch++) - if (strcmp(archs[arch].name, argv[2]) == 0) - break; - if (arch == ARRAY_SIZE(archs)) - grub_util_error("%s: unknown arch: %s", argv[1], argv[2]); - - for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++) - if (strcmp(whitelists[whitelist].arch, argv[2]) == 0 - && strcmp(whitelists[whitelist].platform, argv[3]) == 0) - break; - if (whitelist != ARRAY_SIZE(whitelists)) - whitelist_empty = whitelists[whitelist].whitelist_empty; - - module_size = grub_util_get_image_size (argv[1]); - module_img = grub_util_read_image (argv[1]); - if (archs[arch].voidp_sizeof == 8) - grub_module_verify64(argv[1], module_img, module_size, &archs[arch], whitelist_empty); - else - grub_module_verify32(argv[1], module_img, module_size, &archs[arch], whitelist_empty); - return 0; -} diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c deleted file mode 100644 index 257229f8f..000000000 --- a/util/grub-module-verifier32.c +++ /dev/null @@ -1,2 +0,0 @@ -#define MODULEVERIFIER_ELF32 1 -#include "grub-module-verifierXX.c" diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c deleted file mode 100644 index 4db6b4bed..000000000 --- a/util/grub-module-verifier64.c +++ /dev/null @@ -1,2 +0,0 @@ -#define MODULEVERIFIER_ELF64 1 -#include "grub-module-verifierXX.c" diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c deleted file mode 100644 index ceb24309a..000000000 --- a/util/grub-module-verifierXX.c +++ /dev/null @@ -1,439 +0,0 @@ -#include - -#include -#include -#include - -#if defined(MODULEVERIFIER_ELF32) -# define SUFFIX(x) x ## 32 -# define ELFCLASSXX ELFCLASS32 -# define Elf_Ehdr Elf32_Ehdr -# define Elf_Phdr Elf32_Phdr -# define Elf_Nhdr Elf32_Nhdr -# define Elf_Addr Elf32_Addr -# define Elf_Sym Elf32_Sym -# define Elf_Off Elf32_Off -# define Elf_Shdr Elf32_Shdr -# define Elf_Rela Elf32_Rela -# define Elf_Rel Elf32_Rel -# define Elf_Word Elf32_Word -# define Elf_Half Elf32_Half -# define Elf_Section Elf32_Section -# define ELF_R_SYM(val) ELF32_R_SYM(val) -# define ELF_R_TYPE(val) ELF32_R_TYPE(val) -# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) -#elif defined(MODULEVERIFIER_ELF64) -# define SUFFIX(x) x ## 64 -# define ELFCLASSXX ELFCLASS64 -# define Elf_Ehdr Elf64_Ehdr -# define Elf_Phdr Elf64_Phdr -# define Elf_Nhdr Elf64_Nhdr -# define Elf_Addr Elf64_Addr -# define Elf_Sym Elf64_Sym -# define Elf_Off Elf64_Off -# define Elf_Shdr Elf64_Shdr -# define Elf_Rela Elf64_Rela -# define Elf_Rel Elf64_Rel -# define Elf_Word Elf64_Word -# define Elf_Half Elf64_Half -# define Elf_Section Elf64_Section -# define ELF_R_SYM(val) ELF64_R_SYM(val) -# define ELF_R_TYPE(val) ELF64_R_TYPE(val) -# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val) -#else -#error "I'm confused" -#endif - -#define grub_target_to_host32(x) (grub_target_to_host32_real (arch, (x))) -#define grub_host_to_target32(x) (grub_host_to_target32_real (arch, (x))) -#define grub_target_to_host64(x) (grub_target_to_host64_real (arch, (x))) -#define grub_host_to_target64(x) (grub_host_to_target64_real (arch, (x))) -#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (arch, (x))) -#define grub_target_to_host16(x) (grub_target_to_host16_real (arch, (x))) -#define grub_host_to_target16(x) (grub_host_to_target16_real (arch, (x))) -#define grub_target_to_host(val) grub_target_to_host_real(arch, (val)) - -static inline grub_uint32_t -grub_target_to_host32_real (const struct grub_module_verifier_arch *arch, - grub_uint32_t in) -{ - if (arch->bigendian) - return grub_be_to_cpu32 (in); - else - return grub_le_to_cpu32 (in); -} - -static inline grub_uint64_t -grub_target_to_host64_real (const struct grub_module_verifier_arch *arch, - grub_uint64_t in) -{ - if (arch->bigendian) - return grub_be_to_cpu64 (in); - else - return grub_le_to_cpu64 (in); -} - -static inline grub_uint64_t -grub_host_to_target64_real (const struct grub_module_verifier_arch *arch, - grub_uint64_t in) -{ - if (arch->bigendian) - return grub_cpu_to_be64 (in); - else - return grub_cpu_to_le64 (in); -} - -static inline grub_uint32_t -grub_host_to_target32_real (const struct grub_module_verifier_arch *arch, - grub_uint32_t in) -{ - if (arch->bigendian) - return grub_cpu_to_be32 (in); - else - return grub_cpu_to_le32 (in); -} - -static inline grub_uint16_t -grub_target_to_host16_real (const struct grub_module_verifier_arch *arch, - grub_uint16_t in) -{ - if (arch->bigendian) - return grub_be_to_cpu16 (in); - else - return grub_le_to_cpu16 (in); -} - -static inline grub_uint16_t -grub_host_to_target16_real (const struct grub_module_verifier_arch *arch, - grub_uint16_t in) -{ - if (arch->bigendian) - return grub_cpu_to_be16 (in); - else - return grub_cpu_to_le16 (in); -} - -static inline grub_uint64_t -grub_host_to_target_addr_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in) -{ - if (arch->voidp_sizeof == 8) - return grub_host_to_target64_real (arch, in); - else - return grub_host_to_target32_real (arch, in); -} - -static inline grub_uint64_t -grub_target_to_host_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in) -{ - if (arch->voidp_sizeof == 8) - return grub_target_to_host64_real (arch, in); - else - return grub_target_to_host32_real (arch, in); -} - - -static Elf_Shdr * -find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name) -{ - Elf_Shdr *s; - const char *str; - unsigned i; - - s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host16 (e->e_shstrndx) * grub_target_to_host16 (e->e_shentsize)); - str = (char *) e + grub_target_to_host (s->sh_offset); - - for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); - i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) - if (strcmp (str + grub_target_to_host32 (s->sh_name), name) == 0) - return s; - return NULL; -} - -static void -check_license (const char * const filename, - const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) -{ - Elf_Shdr *s = find_section (arch, e, ".module_license"); - if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0 - || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0 - || strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0)) - return; - grub_util_error ("%s: incompatible license", filename); -} - -static Elf_Sym * -get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize) -{ - unsigned i; - Elf_Shdr *s, *sections; - Elf_Sym *sym; - - sections = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); - for (i = 0, s = sections; - i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) - if (grub_target_to_host32 (s->sh_type) == SHT_SYMTAB) - break; - - if (i == grub_target_to_host16 (e->e_shnum)) - return NULL; - - sym = (Elf_Sym *) ((char *) e + grub_target_to_host (s->sh_offset)); - *size = grub_target_to_host (s->sh_size); - *entsize = grub_target_to_host (s->sh_entsize); - return sym; -} - -static int -is_whitelisted (const char *modname, const char **whitelist) -{ - const char **ptr; - if (!whitelist) - return 0; - if (!modname) - return 0; - for (ptr = whitelist; *ptr; ptr++) - if (strcmp (modname, *ptr) == 0) - return 1; - return 0; -} - -static void -check_symbols (const struct grub_module_verifier_arch *arch, - Elf_Ehdr *e, const char *modname, - const char **whitelist_empty) -{ - Elf_Sym *sym; - Elf_Word size, entsize; - unsigned i; - - /* Module without symbol table and without .moddeps section is useless - at boot time, so catch it early to prevent build errors */ - sym = get_symtab (arch, e, &size, &entsize); - if (!sym) - { - Elf_Shdr *s; - - /* However some modules are dependencies-only, - e.g. insmod all_video pulls in all video drivers. - Some platforms e.g. xen have no video drivers, so - the module does nothing. */ - if (is_whitelisted (modname, whitelist_empty)) - return; - - s = find_section (arch, e, ".moddeps"); - - if (!s) - grub_util_error ("%s: no symbol table and no .moddeps section", modname); - - if (!s->sh_size) - grub_util_error ("%s: no symbol table and empty .moddeps section", modname); - - return; - } - - for (i = 0; - i < size / entsize; - i++, sym = (Elf_Sym *) ((char *) sym + entsize)) - { - unsigned char type = ELF_ST_TYPE (sym->st_info); - - switch (type) - { - case STT_NOTYPE: - case STT_OBJECT: - case STT_FUNC: - case STT_SECTION: - case STT_FILE: - break; - - default: - return grub_util_error ("%s: unknown symbol type `%d'", modname, (int) type); - } - } -} - -static int -is_symbol_local(Elf_Sym *sym) -{ - switch (ELF_ST_TYPE (sym->st_info)) - { - case STT_NOTYPE: - case STT_OBJECT: - if (sym->st_name != 0 && sym->st_shndx == 0) - return 0; - return 1; - - case STT_FUNC: - case STT_SECTION: - return 1; - - default: - return 0; - } -} - -static void -section_check_relocations (const char * const modname, - const struct grub_module_verifier_arch *arch, void *ehdr, - Elf_Shdr *s, size_t target_seg_size) -{ - Elf_Rel *rel, *max; - Elf_Sym *symtab; - Elf_Word symtabsize, symtabentsize; - - symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize); - if (!symtab) - grub_util_error ("%s: relocation without symbol table", modname); - - for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)), - max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size)); - rel < max; - rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize))) - { - Elf_Sym *sym; - unsigned i; - - if (target_seg_size < grub_target_to_host (rel->r_offset)) - grub_util_error ("%s: reloc offset is out of the segment", modname); - - grub_uint32_t type = ELF_R_TYPE (grub_target_to_host (rel->r_info)); - - if (arch->machine == EM_SPARCV9) - type &= 0xff; - - for (i = 0; arch->supported_relocations[i] != -1; i++) - if (type == arch->supported_relocations[i]) - break; - if (arch->supported_relocations[i] != -1) - continue; - if (!arch->short_relocations) - grub_util_error ("%s: unsupported relocation 0x%x", modname, type); - for (i = 0; arch->short_relocations[i] != -1; i++) - if (type == arch->short_relocations[i]) - break; - if (arch->short_relocations[i] == -1) - grub_util_error ("%s: unsupported relocation 0x%x", modname, type); - sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (grub_target_to_host (rel->r_info))); - - if (is_symbol_local (sym)) - continue; - grub_util_error ("%s: relocation 0x%x is not module-local", modname, type); - } -#if defined(MODULEVERIFIER_ELF64) - if (arch->machine == EM_AARCH64) - { - unsigned unmatched_adr_got_page = 0; - Elf_Rela *rel2; - for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)), - max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size)); - rel < max; - rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize))) - { - switch (ELF_R_TYPE (grub_target_to_host (rel->r_info))) - { - case R_AARCH64_ADR_GOT_PAGE: - unmatched_adr_got_page++; - for (rel2 = (Elf_Rela *) ((char *) rel + grub_target_to_host (s->sh_entsize)); - rel2 < (Elf_Rela *) max; - rel2 = (Elf_Rela *) ((char *) rel2 + grub_target_to_host (s->sh_entsize))) - if (ELF_R_SYM (rel2->r_info) - == ELF_R_SYM (rel->r_info) - && ((Elf_Rela *) rel)->r_addend == rel2->r_addend - && ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC) - break; - if (rel2 >= (Elf_Rela *) max) - grub_util_error ("%s: ADR_GOT_PAGE without matching LD64_GOT_LO12_NC", modname); - break; - case R_AARCH64_LD64_GOT_LO12_NC: - if (unmatched_adr_got_page == 0) - grub_util_error ("%s: LD64_GOT_LO12_NC without matching ADR_GOT_PAGE", modname); - unmatched_adr_got_page--; - break; - } - } - } -#endif -} - -static void -check_relocations (const char * const modname, - const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) -{ - Elf_Shdr *s; - unsigned i; - - for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff)); - i < grub_target_to_host16 (e->e_shnum); - i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize))) - if (grub_target_to_host32 (s->sh_type) == SHT_REL || grub_target_to_host32 (s->sh_type) == SHT_RELA) - { - Elf_Shdr *ts; - - if (grub_target_to_host32 (s->sh_type) == SHT_REL && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_REL)) - grub_util_error ("%s: unsupported SHT_REL", modname); - if (grub_target_to_host32 (s->sh_type) == SHT_RELA && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_RELA)) - grub_util_error ("%s: unsupported SHT_RELA", modname); - - /* Find the target segment. */ - if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum)) - grub_util_error ("%s: orphaned reloc section", modname); - ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize)); - - section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size)); - } -} - -void -SUFFIX(grub_module_verify) (const char * const filename, - void *module_img, size_t size, - const struct grub_module_verifier_arch *arch, - const char **whitelist_empty) -{ - Elf_Ehdr *e = module_img; - - /* Check the header size. */ - if (size < sizeof (Elf_Ehdr)) - grub_util_error ("%s: ELF header smaller than expected", filename); - - /* Check the magic numbers. */ - if (e->e_ident[EI_MAG0] != ELFMAG0 - || e->e_ident[EI_MAG1] != ELFMAG1 - || e->e_ident[EI_MAG2] != ELFMAG2 - || e->e_ident[EI_MAG3] != ELFMAG3 - || e->e_ident[EI_VERSION] != EV_CURRENT - || grub_target_to_host32 (e->e_version) != EV_CURRENT) - grub_util_error ("%s: invalid arch-independent ELF magic", filename); - - if (e->e_ident[EI_CLASS] != ELFCLASSXX - || e->e_ident[EI_DATA] != (arch->bigendian ? ELFDATA2MSB : ELFDATA2LSB) - || grub_target_to_host16 (e->e_machine) != arch->machine) - grub_util_error ("%s: invalid arch-dependent ELF magic", filename); - - if (grub_target_to_host16 (e->e_type) != ET_REL) - { - grub_util_error ("%s: this ELF file is not of the right type", filename); - } - - /* Make sure that every section is within the core. */ - if (size < grub_target_to_host (e->e_shoff) - + (grub_uint32_t) grub_target_to_host16 (e->e_shentsize) * grub_target_to_host16(e->e_shnum)) - { - grub_util_error ("%s: ELF sections outside core", filename); - } - - check_license (filename, arch, e); - - Elf_Shdr *s; - const char *modname; - - s = find_section (arch, e, ".modname"); - if (!s) - grub_util_error ("%s: no module name found", filename); - - modname = (const char *) e + grub_target_to_host (s->sh_offset); - - check_symbols(arch, e, modname, whitelist_empty); - check_relocations(modname, arch, e); -} diff --git a/util/grub-mount.c b/util/grub-mount.c index d7be2a427..19de2e620 100644 --- a/util/grub-mount.c +++ b/util/grub-mount.c @@ -151,6 +151,7 @@ fuse_getattr (const char *path, struct stat *st) { struct fuse_getattr_ctx ctx; char *pathname, *path2; + const char *pathname_t; if (path[0] == '/' && path[1] == 0) { @@ -169,7 +170,12 @@ fuse_getattr (const char *path, struct stat *st) ctx.file_exists = 0; - pathname = xstrdup (path); + pathname_t = grub_strchr (path, ')'); + if (! pathname_t) + pathname_t = path; + else + pathname_t++; + pathname = xstrdup (pathname_t); /* Remove trailing '/'. */ while (*pathname && pathname[grub_strlen (pathname) - 1] == '/') @@ -190,7 +196,7 @@ fuse_getattr (const char *path, struct stat *st) } /* It's the whole device. */ - (fs->fs_dir) (dev, path2, fuse_getattr_find_file, &ctx); + (fs->dir) (dev, path2, fuse_getattr_find_file, &ctx); grub_free (path2); if (!ctx.file_exists) @@ -208,7 +214,7 @@ fuse_getattr (const char *path, struct stat *st) if (!ctx.file_info.dir) { grub_file_t file; - file = grub_file_open (path, GRUB_FILE_TYPE_GET_SIZE); + file = grub_file_open (path); if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE) { grub_errno = GRUB_ERR_NONE; @@ -244,7 +250,7 @@ static int fuse_open (const char *path, struct fuse_file_info *fi __attribute__ ((unused))) { grub_file_t file; - file = grub_file_open (path, GRUB_FILE_TYPE_MOUNT); + file = grub_file_open (path); if (! file) return translate_error (); files[first_fd++] = file; @@ -308,7 +314,7 @@ fuse_readdir_call_fill (const char *filename, grub_file_t file; char *tmp; tmp = xasprintf ("%s/%s", ctx->path, filename); - file = grub_file_open (tmp, GRUB_FILE_TYPE_GET_SIZE); + file = grub_file_open (tmp); free (tmp); /* Symlink to directory. */ if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE) @@ -352,7 +358,7 @@ fuse_readdir (const char *path, void *buf, && pathname[grub_strlen (pathname) - 1] == '/') pathname[grub_strlen (pathname) - 1] = 0; - (fs->fs_dir) (dev, pathname, fuse_readdir_call_fill, &ctx); + (fs->dir) (dev, pathname, fuse_readdir_call_fill, &ctx); free (pathname); grub_errno = GRUB_ERR_NONE; return 0; @@ -510,7 +516,6 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; } grub_zfs_add_key (buf, real_size, 0); - fclose (f); } return 0; @@ -530,7 +535,6 @@ argp_parser (int key, char *arg, struct argp_state *state) if (arg[0] != '-') break; - /* FALLTHROUGH */ default: if (!arg) return 0; @@ -542,7 +546,7 @@ argp_parser (int key, char *arg, struct argp_state *state) } images = xrealloc (images, (num_disks + 1) * sizeof (images[0])); - images[num_disks] = grub_canonicalize_file_name (arg); + images[num_disks] = canonicalize_file_name (arg); num_disks++; return 0; diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index 11331294f..f4abf70a3 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, char *pe_strtab = (image + pe_chdr->symtab_offset + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); - section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); + section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); section_map[0] = 0; - shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); + shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); idx = 1; idx_reloc = pe_chdr->num_sections + 1; @@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, pe_sec = pe_shdr + shdr[i].sh_link; pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); - rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); + rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); num_rels = 0; modified = 0; @@ -279,7 +279,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, break; #endif default: - grub_util_error ("unknown pe relocation type %d", pe_rel->type); + grub_util_error ("unknown pe relocation type %d\n", pe_rel->type); } if (type == @@ -365,10 +365,12 @@ write_symbol_table (FILE* fp, const char *name, char *image, pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); - symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); + symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * + sizeof (Elf_Sym)); + memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); num_syms = 1; - symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); + symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); for (i = 0; i < (int) pe_chdr->num_symbols; i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) diff --git a/util/grub-probe.c b/util/grub-probe.c index cbe6ed94c..ecb7b6bbd 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -63,7 +62,6 @@ enum { PRINT_DRIVE, PRINT_DEVICE, PRINT_PARTMAP, - PRINT_PARTUUID, PRINT_ABSTRACTION, PRINT_CRYPTODISK_UUID, PRINT_HINT_STR, @@ -87,7 +85,6 @@ static const char *targets[] = [PRINT_DRIVE] = "drive", [PRINT_DEVICE] = "device", [PRINT_PARTMAP] = "partmap", - [PRINT_PARTUUID] = "partuuid", [PRINT_ABSTRACTION] = "abstraction", [PRINT_CRYPTODISK_UUID] = "cryptodisk_uuid", [PRINT_HINT_STR] = "hints_string", @@ -132,20 +129,6 @@ get_targets_string (void) return str; } -static int -print_gpt_guid (grub_gpt_part_guid_t guid) -{ - guid.data1 = grub_le_to_cpu32 (guid.data1); - guid.data2 = grub_le_to_cpu16 (guid.data2); - guid.data3 = grub_le_to_cpu16 (guid.data3); - - return grub_printf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - guid.data1, guid.data2, guid.data3, guid.data4[0], - guid.data4[1], guid.data4[2], guid.data4[3], - guid.data4[4], guid.data4[5], guid.data4[6], - guid.data4[7]); -} - static void do_print (const char *x, void *data) { @@ -171,9 +154,9 @@ probe_partmap (grub_disk_t disk, char delim) grub_diskfilter_get_partmap (disk, do_print, &delim); /* In case of LVM/RAID, check the member devices as well. */ - if (disk->dev->disk_memberlist) + if (disk->dev->memberlist) { - list = disk->dev->disk_memberlist (disk); + list = disk->dev->memberlist (disk); } while (list) { @@ -184,54 +167,15 @@ probe_partmap (grub_disk_t disk, char delim) } } -static void -probe_partuuid (grub_disk_t disk, char delim) -{ - grub_partition_t p = disk->partition; - - /* - * Nested partitions not supported for now. - * Non-nested partitions must have disk->partition->parent == NULL - */ - if (p && p->parent == NULL) - { - disk->partition = p->parent; - - if (strcmp(p->partmap->name, "msdos") == 0) - { - /* - * The partition GUID for MSDOS is the partition number (starting - * with 1) prepended with the NT disk signature. - */ - grub_uint32_t nt_disk_sig; - - if (grub_disk_read (disk, 0, GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, - sizeof(nt_disk_sig), &nt_disk_sig) == 0) - grub_printf ("%08x-%02x", - grub_le_to_cpu32(nt_disk_sig), 1 + p->number); - } - else if (strcmp(p->partmap->name, "gpt") == 0) - { - struct grub_gpt_partentry gptdata; - - if (grub_disk_read (disk, p->offset, p->index, - sizeof(gptdata), &gptdata) == 0) - print_gpt_guid(gptdata.guid); - } - - disk->partition = p; - } -} - static void probe_cryptodisk_uuid (grub_disk_t disk, char delim) { grub_disk_memberlist_t list = NULL, tmp; /* In case of LVM/RAID, check the member devices as well. */ - if (disk->dev->disk_memberlist) + if (disk->dev->memberlist) { - list = disk->dev->disk_memberlist (disk); + list = disk->dev->memberlist (disk); } while (list) { @@ -272,8 +216,8 @@ probe_abstraction (grub_disk_t disk, char delim) grub_disk_memberlist_t list = NULL, tmp; int raid_level; - if (disk->dev->disk_memberlist) - list = disk->dev->disk_memberlist (disk); + if (disk->dev->memberlist) + list = disk->dev->memberlist (disk); while (list) { probe_abstraction (list->disk, delim); @@ -299,8 +243,8 @@ probe_abstraction (grub_disk_t disk, char delim) if (raid_level >= 0) { printf ("diskfilter%c", delim); - if (disk->dev->disk_raidname) - printf ("%s%c", disk->dev->disk_raidname (disk), delim); + if (disk->dev->raidname) + printf ("%s%c", disk->dev->raidname (disk), delim); } if (raid_level == 5) printf ("raid5rec%c", delim); @@ -318,7 +262,7 @@ probe (const char *path, char **device_names, char delim) if (path != NULL) { - grub_path = grub_canonicalize_file_name (path); + grub_path = canonicalize_file_name (path); if (! grub_path) grub_util_error (_("failed to get canonical path of `%s'"), path); device_names = grub_guess_root_devices (grub_path); @@ -335,7 +279,7 @@ probe (const char *path, char **device_names, char delim) printf ("%s", *curdev); putchar (delim); } - goto free_device_names; + return; } if (print == PRINT_DISK) @@ -351,9 +295,8 @@ probe (const char *path, char **device_names, char delim) } printf ("%s", disk); putchar (delim); - free (disk); } - goto free_device_names; + return; } for (curdev = device_names; *curdev; curdev++) @@ -361,8 +304,8 @@ probe (const char *path, char **device_names, char delim) grub_util_pull_device (*curdev); ndev++; } - - drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); + + drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, curdrive++) @@ -446,10 +389,10 @@ probe (const char *path, char **device_names, char delim) else if (print == PRINT_FS_UUID) { char *uuid; - if (! fs->fs_uuid) + if (! fs->uuid) grub_util_error (_("%s does not support UUIDs"), fs->name); - if (fs->fs_uuid (dev, &uuid) != GRUB_ERR_NONE) + if (fs->uuid (dev, &uuid) != GRUB_ERR_NONE) grub_util_error ("%s", grub_errmsg); printf ("%s", uuid); @@ -458,11 +401,11 @@ probe (const char *path, char **device_names, char delim) else if (print == PRINT_FS_LABEL) { char *label; - if (! fs->fs_label) + if (! fs->label) grub_util_error (_("filesystem `%s' does not support labels"), fs->name); - if (fs->fs_label (dev, &label) != GRUB_ERR_NONE) + if (fs->label (dev, &label) != GRUB_ERR_NONE) grub_util_error ("%s", grub_errmsg); printf ("%s", label); @@ -485,7 +428,7 @@ probe (const char *path, char **device_names, char delim) if (print == PRINT_HINT_STR) { const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); - char *ofpath = osdev ? grub_util_devname_to_ofpath (osdev) : 0; + const char *ofpath = osdev ? grub_util_devname_to_ofpath (osdev) : 0; char *biosname, *bare, *efi; const char *map; @@ -499,7 +442,6 @@ probe (const char *path, char **device_names, char delim) grub_util_fprint_full_disk_name (stdout, tmp, dev); printf ("' "); free (tmp); - free (ofpath); } biosname = grub_util_guess_bios_drive (*curdev); @@ -542,18 +484,22 @@ probe (const char *path, char **device_names, char delim) printf (" "); else printf ("\n"); + + grub_device_close (dev); + continue; } - else if ((print == PRINT_COMPATIBILITY_HINT || print == PRINT_BIOS_HINT + if ((print == PRINT_COMPATIBILITY_HINT || print == PRINT_BIOS_HINT || print == PRINT_IEEE1275_HINT || print == PRINT_BAREMETAL_HINT || print == PRINT_EFI_HINT || print == PRINT_ARC_HINT) && dev->disk->dev->id != GRUB_DISK_DEVICE_HOSTDISK_ID) { grub_util_fprint_full_disk_name (stdout, dev->disk->name, dev); putchar (delim); + continue; } - else if (print == PRINT_COMPATIBILITY_HINT) + if (print == PRINT_COMPATIBILITY_HINT) { const char *map; char *biosname; @@ -571,14 +517,16 @@ probe (const char *path, char **device_names, char delim) { grub_util_fprint_full_disk_name (stdout, biosname, dev); putchar (delim); - free (biosname); - /* Compatibility hint is one device only. */ - grub_device_close (dev); - break; } + free (biosname); + grub_device_close (dev); + /* Compatibility hint is one device only. */ + if (biosname) + break; + continue; } - else if (print == PRINT_BIOS_HINT) + if (print == PRINT_BIOS_HINT) { char *biosname; biosname = grub_util_guess_bios_drive (*curdev); @@ -586,13 +534,15 @@ probe (const char *path, char **device_names, char delim) { grub_util_fprint_full_disk_name (stdout, biosname, dev); putchar (delim); - free (biosname); } + free (biosname); + grub_device_close (dev); + continue; } - else if (print == PRINT_IEEE1275_HINT) + if (print == PRINT_IEEE1275_HINT) { const char *osdev = grub_util_biosdisk_get_osdev (dev->disk); - char *ofpath = grub_util_devname_to_ofpath (osdev); + const char *ofpath = grub_util_devname_to_ofpath (osdev); const char *map; map = grub_util_biosdisk_get_compatibility_hint (dev->disk); @@ -610,11 +560,13 @@ probe (const char *path, char **device_names, char delim) strcpy (p, ofpath); grub_util_fprint_full_disk_name (stdout, tmp, dev); free (tmp); - free (ofpath); putchar (delim); } + + grub_device_close (dev); + continue; } - else if (print == PRINT_EFI_HINT) + if (print == PRINT_EFI_HINT) { char *biosname; const char *map; @@ -630,11 +582,14 @@ probe (const char *path, char **device_names, char delim) { grub_util_fprint_full_disk_name (stdout, biosname, dev); putchar (delim); - free (biosname); } + + free (biosname); + grub_device_close (dev); + continue; } - else if (print == PRINT_BAREMETAL_HINT) + if (print == PRINT_BAREMETAL_HINT) { char *biosname; const char *map; @@ -651,11 +606,14 @@ probe (const char *path, char **device_names, char delim) { grub_util_fprint_full_disk_name (stdout, biosname, dev); putchar (delim); - free (biosname); } + + free (biosname); + grub_device_close (dev); + continue; } - else if (print == PRINT_ARC_HINT) + if (print == PRINT_ARC_HINT) { const char *map; @@ -665,34 +623,46 @@ probe (const char *path, char **device_names, char delim) grub_util_fprint_full_disk_name (stdout, map, dev); putchar (delim); } + + /* FIXME */ + grub_device_close (dev); + continue; } - else if (print == PRINT_ABSTRACTION) - probe_abstraction (dev->disk, delim); - - else if (print == PRINT_CRYPTODISK_UUID) - probe_cryptodisk_uuid (dev->disk, delim); - - else if (print == PRINT_PARTMAP) - /* Check if dev->disk itself is contained in a partmap. */ - probe_partmap (dev->disk, delim); - - else if (print == PRINT_PARTUUID) + if (print == PRINT_ABSTRACTION) { - probe_partuuid (dev->disk, delim); - putchar (delim); + probe_abstraction (dev->disk, delim); + grub_device_close (dev); + continue; } - else if (print == PRINT_MSDOS_PARTTYPE) + if (print == PRINT_CRYPTODISK_UUID) + { + probe_cryptodisk_uuid (dev->disk, delim); + grub_device_close (dev); + continue; + } + + if (print == PRINT_PARTMAP) + { + /* Check if dev->disk itself is contained in a partmap. */ + probe_partmap (dev->disk, delim); + grub_device_close (dev); + continue; + } + + if (print == PRINT_MSDOS_PARTTYPE) { if (dev->disk->partition && strcmp(dev->disk->partition->partmap->name, "msdos") == 0) printf ("%02x", dev->disk->partition->msdostype); putchar (delim); + grub_device_close (dev); + continue; } - else if (print == PRINT_GPT_PARTTYPE) + if (print == PRINT_GPT_PARTTYPE) { if (dev->disk->partition && strcmp (dev->disk->partition->partmap->name, "gpt") == 0) @@ -703,27 +673,33 @@ probe (const char *path, char **device_names, char delim) if (grub_disk_read (dev->disk, p->offset, p->index, sizeof (gptdata), &gptdata) == 0) - print_gpt_guid(gptdata.type); + { + grub_gpt_part_type_t gpttype; + gpttype.data1 = grub_le_to_cpu32 (gptdata.type.data1); + gpttype.data2 = grub_le_to_cpu16 (gptdata.type.data2); + gpttype.data3 = grub_le_to_cpu16 (gptdata.type.data3); + grub_memcpy (gpttype.data4, gptdata.type.data4, 8); + + grub_printf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + gpttype.data1, gpttype.data2, + gpttype.data3, gpttype.data4[0], + gpttype.data4[1], gpttype.data4[2], + gpttype.data4[3], gpttype.data4[4], + gpttype.data4[5], gpttype.data4[6], + gpttype.data4[7]); + } dev->disk->partition = p; } putchar (delim); + grub_device_close (dev); + continue; } - - grub_device_close (dev); } end: for (curdrive = drives_names; *curdrive; curdrive++) free (*curdrive); free (drives_names); - -free_device_names: - if (path != NULL) - { - for (curdev = device_names; *curdev; curdev++) - free (*curdev); - free (device_names); - } } static struct argp_option options[] = { @@ -749,14 +725,11 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused))) case 't': { - char *ret, *t = get_targets_string (), *def; + char *ret, *t = get_targets_string (); - def = xasprintf (_("[default=%s]"), targets[print]); - - ret = xasprintf ("%s\n%s %s %s", _("print TARGET"), - _("available targets:"), t, def); + ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"), + _("available targets:"), t, targets[print]); free (t); - free (def); return ret; } diff --git a/util/grub-reboot.in b/util/grub-reboot.in index ef3b5c049..225fe5f21 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -20,7 +20,6 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ -sbindir=@sbindir@ sysconfdir="@sysconfdir@" PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_VERSION=@PACKAGE_VERSION@ @@ -33,7 +32,6 @@ fi self=`basename $0` grub_editenv=${bindir}/@grub_editenv@ -grub_probe=${sbindir}/@grub_probe@ rootdir= bootdir= grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` @@ -49,7 +47,7 @@ usage () { gettext_printf "Usage: %s [OPTION] MENU_ENTRY\n" "$self" gettext "Set the default boot menu entry for GRUB, for the next boot only."; echo print_option_help "-h, --help" "$(gettext "print this message and exit")" - print_option_help "-V, --version" "$(gettext "print the version information and exit")" + print_option_help "-v, --version" "$(gettext "print the version information and exit")" dirmsg="$(gettext_printf "expect GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")" print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg" echo @@ -58,8 +56,6 @@ submenus or sub-submenus require specifying the submenu components and then the menu item component. The titles should be separated using the greater-than character (>) with no extra spaces. Depending on your shell some characters including > may need escaping. More information about this is available in the GRUB Manual in the section about the 'default' command. "; echo - echo - gettext "NOTE: In cases where GRUB cannot write to the environment block, such as when it is stored on an MDRAID or LVM device, the chosen boot menu entry will remain the default even after reboot. "; echo echo gettext "Report bugs to ."; echo } @@ -85,7 +81,7 @@ do -h | --help) usage exit 0 ;; - -V | --version) + -v | --version) echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" exit 0 ;; @@ -135,18 +131,6 @@ fi grubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'` -abstractions=`$grub_probe --target=abstraction ${grubdir}/grubenv` -for abstraction in $abstractions; do - case "$abstraction" in - diskfilter | lvm) - gettext_printf "\nWARNING: Detected GRUB environment block on $abstraction device\n" - gettext_printf "%s will remain the default boot entry until manually cleared with:\n" "${entry}" - gettext_printf " grub-editenv ${grubdir}/grubenv unset next_entry\n\n" - break - ;; - esac -done - # Restore saved_entry if it was set by previous version prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^prev_saved_entry=//p'` if [ "$prev_saved_entry" ]; then diff --git a/util/grub-set-default.in b/util/grub-set-default.in index 6036f81e5..83a7be12f 100644 --- a/util/grub-set-default.in +++ b/util/grub-set-default.in @@ -49,7 +49,7 @@ usage () { gettext_printf "This requires setting GRUB_DEFAULT=saved in %s/default/grub.\n" "$sysconfdir" echo print_option_help "-h, --help" "$(gettext "print this message and exit")" - print_option_help "-V, --version" "$(gettext "print the version information and exit")" + print_option_help "-v, --version" "$(gettext "print the version information and exit")" dirmsg="$(gettext_printf "expect GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")" print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg" echo @@ -79,7 +79,7 @@ do -h | --help) usage exit 0 ;; - -V | --version) + -v | --version) echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" exit 0 ;; diff --git a/util/grub-setup.c b/util/grub-setup.c index 42b98ad3c..993b02068 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -69,7 +69,7 @@ #define DEFAULT_CORE_FILE "core.img" /* Non-printable "keys" for arguments with no short form. - * See grub-core/lib/gnulib/argp.h for details. */ + * See grub-core/gnulib/argp.h for details. */ enum { NO_RS_CODES_KEY = 0x100, }; diff --git a/util/grub-syslinux2cfg.c b/util/grub-syslinux2cfg.c index 85fa0da14..f4fda6db9 100644 --- a/util/grub-syslinux2cfg.c +++ b/util/grub-syslinux2cfg.c @@ -175,7 +175,7 @@ main (int argc, char *argv[]) grub_host_init (); char *t, *inpfull, *rootfull, *res; - t = grub_canonicalize_file_name (arguments.input); + t = canonicalize_file_name (arguments.input); if (!t) { grub_util_error (_("cannot open `%s': %s"), arguments.input, @@ -185,7 +185,7 @@ main (int argc, char *argv[]) inpfull = xasprintf ("(host)/%s", t); free (t); - t = grub_canonicalize_file_name (arguments.root ? : "/"); + t = canonicalize_file_name (arguments.root ? : "/"); if (!t) { grub_util_error (_("cannot open `%s': %s"), arguments.root, @@ -206,7 +206,7 @@ main (int argc, char *argv[]) cwd = xstrdup ("."); } - t = grub_canonicalize_file_name (arguments.cwd ? : cwd); + t = canonicalize_file_name (arguments.cwd ? : cwd); if (!t) { grub_util_error (_("cannot open `%s': %s"), arguments.root, diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in index 93a90233e..ce2ec819d 100644 --- a/util/grub.d/00_header.in +++ b/util/grub.d/00_header.in @@ -25,7 +25,7 @@ grub_lang=`echo $LANG | cut -d . -f 1` export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" # Do this as early as possible, since other commands might depend on it. # (e.g. the `loadfont' command might need lvm or raid modules) diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in index 3663d360e..29b455423 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -24,7 +24,7 @@ datarootdir="@datarootdir@" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" CLASS="--class gnu --class os" @@ -156,15 +156,7 @@ is_top_level=true while [ "x$kernels" != "x" ] ; do kernel=`version_find_latest $kernels` - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then hurd_entry "$kernel" simple submenu_indentation="$grub_tab" diff --git a/util/grub.d/10_illumos.in b/util/grub.d/10_illumos.in index a133e1b3f..0de616e89 100644 --- a/util/grub.d/10_illumos.in +++ b/util/grub.d/10_illumos.in @@ -20,7 +20,7 @@ set -e prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 199b20e16..65f6c32a0 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -20,7 +20,7 @@ set -e prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" @@ -214,15 +214,7 @@ while [ "x$list" != "x" ] ; do module_dir_rel=$(make_system_path_relative_to_its_root $module_dir) fi - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then kfreebsd_entry "${OS}" "${version}" simple submenu_indentation="$grub_tab" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index e8b01c0d0..a2a84dce4 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -21,7 +21,7 @@ prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" @@ -43,22 +43,10 @@ case ${GRUB_DEVICE} in ;; esac -# Default to disabling partition uuid support to maintian compatibility with -# older kernels. -GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} - -# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter -# and mounting btrfs requires user space scanning, so force UUID in this case. -if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ - || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ - && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ - || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ - || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then LINUX_ROOT_DEVICE=${GRUB_DEVICE} -elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ - || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then - LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi @@ -73,7 +61,7 @@ case x"$GRUB_FS" in xzfs) rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}" + LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" ;; esac @@ -146,13 +134,9 @@ EOF if test -n "${initrd}" ; then # TRANSLATORS: ramdisk isn't identifier. Should be translated. message="$(gettext_printf "Loading initial ramdisk ...")" - initrd_path= - for i in ${initrd}; do - initrd_path="${initrd_path} ${rel_dirname}/${i}" - done sed "s/^/$submenu_indentation/" << EOF echo '$(echo "$message" | grub_quote)' - initrd $(echo $initrd_path) + initrd ${rel_dirname}/${initrd} EOF fi sed "s/^/$submenu_indentation/" << EOF @@ -202,15 +186,7 @@ while [ "x$list" != "x" ] ; do alt_version=`echo $version | sed -e "s,\.old$,,g"` linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" - initrd_early= - for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ - ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do - if test -e "${dirname}/${i}" ; then - initrd_early="${initrd_early} ${i}" - fi - done - - initrd_real= + initrd= for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ "initrd-${version}" "initramfs-${version}.img" \ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ @@ -220,22 +196,11 @@ while [ "x$list" != "x" ] ; do "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do if test -e "${dirname}/${i}" ; then - initrd_real="${i}" + initrd="$i" break fi done - initrd= - if test -n "${initrd_early}" || test -n "${initrd_real}"; then - initrd="${initrd_early} ${initrd_real}" - - initrd_display= - for i in ${initrd}; do - initrd_display="${initrd_display} ${dirname}/${i}" - done - gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 - fi - config= for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do if test -e "${i}" ; then @@ -249,27 +214,15 @@ while [ "x$list" != "x" ] ; do initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` fi - if test -z "${initramfs}" && test -z "${initrd_real}" ; then + if test -n "${initrd}" ; then + gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2 + elif test -z "${initramfs}" ; then # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's # no initrd or builtin initramfs, it can't work here. - if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ - || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then - - linux_root_device_thisversion=${GRUB_DEVICE} - else - linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} - fi + linux_root_device_thisversion=${GRUB_DEVICE} fi - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then linux_entry "${OS}" "${version}" simple \ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in index dc0cd1b17..9988a42bc 100644 --- a/util/grub.d/10_netbsd.in +++ b/util/grub.d/10_netbsd.in @@ -20,7 +20,7 @@ set -e prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" @@ -157,15 +157,7 @@ for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do gettext_printf "Found NetBSD kernel: %s\n" "$k" >&2 - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then netbsd_entry "knetbsd" "$k" simple "${GRUB_CMDLINE_NETBSD_DEFAULT}" submenu_indentation="$grub_tab" diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in index 554c5614b..48bd95546 100644 --- a/util/grub.d/10_windows.in +++ b/util/grub.d/10_windows.in @@ -24,7 +24,7 @@ datarootdir="@datarootdir@" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" case "`uname 2>/dev/null`" in CYGWIN*) ;; diff --git a/util/grub.d/10_xnu.in b/util/grub.d/10_xnu.in index 9c40b4536..4270385f3 100644 --- a/util/grub.d/10_xnu.in +++ b/util/grub.d/10_xnu.in @@ -24,7 +24,7 @@ datarootdir="@datarootdir@" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" osx_entry() { if [ x$2 = x32 ]; then @@ -56,9 +56,6 @@ EOF fi if [ /kernelcache -nt /System/Library/Extensions ]; then $1 /kernelcache boot-uuid=\${uuid} rd=*uuid - elif [ -f /System/Library/Kernels/kernel ]; then - $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid - xnu_kextdir /System/Library/Extensions else $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index 3b1f47049..de34c8d73 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -21,7 +21,7 @@ prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" @@ -43,22 +43,10 @@ case ${GRUB_DEVICE} in ;; esac -# Default to disabling partition uuid support to maintian compatibility with -# older kernels. -GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} - -# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter -# and mounting btrfs requires user space scanning, so force UUID in this case. -if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ - || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ - && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ - || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ - || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || uses_abstraction "${GRUB_DEVICE}" lvm; then LINUX_ROOT_DEVICE=${GRUB_DEVICE} -elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ - || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then - LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi @@ -81,18 +69,13 @@ case x"$GRUB_FS" in xzfs) rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}" + LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" ;; esac title_correction_code= linux_entry () -{ - linux_entry_xsm "$@" false - linux_entry_xsm "$@" true -} -linux_entry_xsm () { os="$1" version="$2" @@ -100,18 +83,6 @@ linux_entry_xsm () type="$4" args="$5" xen_args="$6" - xsm="$7" - # If user wants to enable XSM support, make sure there's - # corresponding policy file. - if ${xsm} ; then - xenpolicy="xenpolicy-$xen_version" - if test ! -e "${xen_dirname}/${xenpolicy}" ; then - return - fi - xen_args="$xen_args flask=enforcing" - xen_version="$(gettext_printf "%s (XSM enabled)" "$xen_version")" - # xen_version is used for messages only; actual file is xen_basename - fi if [ -z "$boot_device_id" ]; then boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" fi @@ -149,27 +120,16 @@ linux_entry_xsm () else xen_rm_opts="no-real-mode edd=off" fi - ${xen_loader} ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts} + multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts} echo '$(echo "$lmessage" | grub_quote)' - ${module_loader} ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} + module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then # TRANSLATORS: ramdisk isn't identifier. Should be translated. message="$(gettext_printf "Loading initial ramdisk ...")" - initrd_path= - for i in ${initrd}; do - initrd_path="${initrd_path} ${rel_dirname}/${i}" - done sed "s/^/$submenu_indentation/" << EOF echo '$(echo "$message" | grub_quote)' - ${module_loader} --nounzip $(echo $initrd_path) -EOF - fi - if test -n "${xenpolicy}" ; then - message="$(gettext_printf "Loading XSM policy ...")" - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' - ${module_loader} ${rel_dirname}/${xenpolicy} + module --nounzip ${rel_dirname}/${initrd} EOF fi sed "s/^/$submenu_indentation/" << EOF @@ -197,14 +157,10 @@ if [ "x${linux_list}" = "x" ] ; then exit 0 fi -file_is_not_xen_garbage () { +file_is_not_sym () { case "$1" in */xen-syms-*) return 1;; - */xenpolicy-*) - return 1;; - */*.config) - return 1;; *) return 0;; esac @@ -212,7 +168,7 @@ file_is_not_xen_garbage () { xen_list= for i in /boot/xen*; do - if grub_file_is_not_garbage "$i" && file_is_not_xen_garbage "$i" ; then xen_list="$xen_list $i" ; fi + if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then xen_list="$xen_list $i" ; fi done prepare_boot_cache= boot_device_id= @@ -248,27 +204,6 @@ while [ "x${xen_list}" != "x" ] ; do if [ "x$is_top_level" != xtrue ]; then echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {" fi - if ($grub_file --is-arm64-efi $current_xen); then - xen_loader="xen_hypervisor" - module_loader="xen_module" - else - if ($grub_file --is-x86-multiboot2 $current_xen); then - xen_loader="multiboot2" - module_loader="module2" - else - xen_loader="multiboot" - module_loader="module" - fi - fi - - initrd_early= - for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ - ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do - if test -e "${xen_dirname}/${i}" ; then - initrd_early="${initrd_early} ${i}" - fi - done - while [ "x$list" != "x" ] ; do linux=`version_find_latest $list` gettext_printf "Found linux image: %s\n" "$linux" >&2 @@ -279,7 +214,7 @@ while [ "x${xen_list}" != "x" ] ; do alt_version=`echo $version | sed -e "s,\.old$,,g"` linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" - initrd_real= + initrd= for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ "initrd-${version}" "initramfs-${version}.img" \ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ @@ -289,42 +224,18 @@ while [ "x${xen_list}" != "x" ] ; do "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do if test -e "${dirname}/${i}" ; then - initrd_real="$i" + initrd="$i" break fi done - - initrd= - if test -n "${initrd_early}" || test -n "${initrd_real}"; then - initrd="${initrd_early} ${initrd_real}" - - initrd_display= - for i in ${initrd}; do - initrd_display="${initrd_display} ${dirname}/${i}" - done - gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 - fi - - if test -z "${initrd_real}"; then + if test -n "${initrd}" ; then + gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2 + else # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here. - if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ - || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then - - linux_root_device_thisversion=${GRUB_DEVICE} - else - linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} - fi + linux_root_device_thisversion=${GRUB_DEVICE} fi - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then linux_entry "${OS}" "${version}" "${xen_version}" simple \ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}" diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in index 1b91c102f..4ee601565 100644 --- a/util/grub.d/30_os-prober.in +++ b/util/grub.d/30_os-prober.in @@ -24,13 +24,13 @@ datarootdir="@datarootdir@" export TEXTDOMAIN=@PACKAGE@ export TEXTDOMAINDIR="@localedir@" -. "$pkgdatadir/grub-mkconfig_lib" +. "@datadir@/@PACKAGE@/grub-mkconfig_lib" if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then exit 0 fi -if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/null ; then +if [ -z "`which os-prober 2> /dev/null`" ] || [ -z "`which linux-boot-prober 2> /dev/null`" ] ; then # missing os-prober and/or linux-boot-prober exit 0 fi @@ -71,9 +71,6 @@ EOF fi if [ /kernelcache -nt /System/Library/Extensions ]; then $1 /kernelcache boot-uuid=\${uuid} rd=*uuid - elif [ -f /System/Library/Kernels/kernel ]; then - $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid - xnu_kextdir /System/Library/Extensions else $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then @@ -138,9 +135,6 @@ for OS in ${OSPROBED} ; do LONGNAME="${LABEL}" fi - # os-prober returns text string followed by optional counter - CLASS="--class $(echo "${LABEL}" | LC_ALL=C sed 's,[[:digit:]]*$,,' | cut -d' ' -f1 | tr 'A-Z' 'a-z' | LC_ALL=C sed 's,[^[:alnum:]_],_,g')" - gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2 case ${BOOT} in @@ -148,7 +142,7 @@ for OS in ${OSPROBED} ; do onstr="$(gettext_printf "(on %s)" "${DEVICE}")" cat << EOF -menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' { +menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' { EOF save_default_entry | grub_add_tab prepare_grub_to_access_device ${DEVICE} | grub_add_tab @@ -180,7 +174,7 @@ EOF DEVICE=${DEVICE%@*} onstr="$(gettext_printf "(on %s)" "${DEVICE}")" cat << EOF -menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' { +menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' { EOF save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" @@ -234,17 +228,9 @@ EOF prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | grub_add_tab)" fi - # The GRUB_DISABLE_SUBMENU option used to be different than others since it was - # mentioned in the documentation that has to be set to 'y' instead of 'true' to - # enable it. This caused a lot of confusion to users that set the option to 'y', - # 'yes' or 'true'. This was fixed but all of these values must be supported now. - if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then - GRUB_DISABLE_SUBMENU="true" - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then cat << EOF -menuentry '$(echo "$OS $onstr" | grub_quote)' $CLASS --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' { +menuentry '$(echo "$OS $onstr" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' { EOF save_default_entry | grub_add_tab printf '%s\n' "${prepare_boot_cache}" diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in deleted file mode 100644 index d344d3883..000000000 --- a/util/grub.d/30_uefi-firmware.in +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/sh -set -e - -# grub-mkconfig helper script. -# Copyright (C) 2020 Free Software Foundation, Inc. -# -# GRUB is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# GRUB is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GRUB. If not, see . - -prefix="@prefix@" -exec_prefix="@exec_prefix@" -datarootdir="@datarootdir@" - -export TEXTDOMAIN=@PACKAGE@ -export TEXTDOMAINDIR="@localedir@" - -. "$pkgdatadir/grub-mkconfig_lib" - -EFI_VARS_DIR=/sys/firmware/efi/efivars -EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c -OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" - -if [ -e "$OS_INDICATIONS" ] && \ - [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then - LABEL="UEFI Firmware Settings" - - gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 - - cat << EOF -menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { - fwsetup -} -EOF -fi diff --git a/util/grub.d/41_custom.in b/util/grub.d/41_custom.in index a08363da1..fcc21a987 100644 --- a/util/grub.d/41_custom.in +++ b/util/grub.d/41_custom.in @@ -3,7 +3,7 @@ cat < #include #include -#include #define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof)) @@ -54,26 +53,55 @@ #include #endif -#pragma GCC diagnostic ignored "-Wcast-align" - #define TARGET_NO_FIELD 0xffffffff -/* use 2015-01-01T00:00:00+0000 as a stock timestamp */ -#define STABLE_EMBEDDING_TIMESTAMP 1420070400 +struct grub_install_image_target_desc +{ + const char *dirname; + const char *names[6]; + grub_size_t voidp_sizeof; + int bigendian; + enum { + IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT, + IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_SPARC64_CDCORE, + IMAGE_I386_IEEE1275, + IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH, + IMAGE_FULOONG2F_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC, + IMAGE_QEMU_MIPS_FLASH, IMAGE_UBOOT, IMAGE_XEN, IMAGE_I386_PC_ELTORITO + } id; + enum + { + PLATFORM_FLAGS_NONE = 0, + PLATFORM_FLAGS_DECOMPRESSORS = 2, + PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4, + } flags; + unsigned total_module_size; + unsigned decompressor_compressed_size; + unsigned decompressor_uncompressed_size; + unsigned decompressor_uncompressed_addr; + unsigned link_align; + grub_uint16_t elf_target; + unsigned section_align; + signed vaddr_offset; + grub_uint64_t link_addr; + unsigned mod_gap, mod_align; + grub_compression_t default_compression; + grub_uint16_t pe_target; +}; #define EFI32_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \ + GRUB_PE32_SIGNATURE_SIZE \ + sizeof (struct grub_pe32_coff_header) \ + sizeof (struct grub_pe32_optional_header) \ + 4 * sizeof (struct grub_pe32_section_table), \ - GRUB_PE32_FILE_ALIGNMENT) + GRUB_PE32_SECTION_ALIGNMENT) #define EFI64_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \ + GRUB_PE32_SIGNATURE_SIZE \ + sizeof (struct grub_pe32_coff_header) \ + sizeof (struct grub_pe64_optional_header) \ + 4 * sizeof (struct grub_pe32_section_table), \ - GRUB_PE32_FILE_ALIGNMENT) + GRUB_PE32_SECTION_ALIGNMENT) static const struct grub_install_image_target_desc image_targets[] = { @@ -88,7 +116,6 @@ static const struct grub_install_image_target_desc image_targets[] = .decompressor_compressed_size = TARGET_NO_FIELD, .decompressor_uncompressed_size = TARGET_NO_FIELD, .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .reloc_table_offset = TARGET_NO_FIELD, .section_align = 1, .vaddr_offset = 0, .link_addr = GRUB_KERNEL_I386_COREBOOT_LINK_ADDR, @@ -132,24 +159,6 @@ static const struct grub_install_image_target_desc image_targets[] = .link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR, .default_compression = GRUB_COMPRESSION_LZMA }, - { - .dirname = "i386-xen_pvh", - .names = { "i386-xen_pvh", NULL }, - .voidp_sizeof = 4, - .bigendian = 0, - .id = IMAGE_XEN_PVH, - .flags = PLATFORM_FLAGS_NONE, - .total_module_size = TARGET_NO_FIELD, - .decompressor_compressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .elf_target = EM_386, - .section_align = 1, - .vaddr_offset = 0, - .link_addr = GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR, - .mod_align = GRUB_KERNEL_I386_XEN_PVH_MOD_ALIGN, - .link_align = 4 - }, { .dirname = "i386-pc", .names = { "i386-pc-pxe", NULL }, @@ -546,50 +555,12 @@ static const struct grub_install_image_target_desc image_targets[] = .decompressor_uncompressed_addr = TARGET_NO_FIELD, .section_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN, .vaddr_offset = 0, + .link_addr = GRUB_KERNEL_ARM_UBOOT_LINK_ADDR, .elf_target = EM_ARM, .mod_gap = GRUB_KERNEL_ARM_UBOOT_MOD_GAP, .mod_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN, .link_align = 4 }, - /* For coreboot versions that don't support self-relocating images. */ - { - .dirname = "arm-coreboot-vexpress", - .names = { "arm-coreboot-vexpress", NULL }, - .voidp_sizeof = 4, - .bigendian = 0, - .id = IMAGE_COREBOOT, - .flags = PLATFORM_FLAGS_NONE, - .total_module_size = GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE, - .decompressor_compressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .section_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN, - .vaddr_offset = 0, - .elf_target = EM_ARM, - .mod_gap = GRUB_KERNEL_ARM_COREBOOT_MOD_GAP, - .mod_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN, - .link_align = 4, - .link_addr = 0x62000000, - }, - { - .dirname = "arm-coreboot-veyron", - .names = { "arm-coreboot-veyron", NULL }, - .voidp_sizeof = 4, - .bigendian = 0, - .id = IMAGE_COREBOOT, - .flags = PLATFORM_FLAGS_NONE, - .total_module_size = GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE, - .decompressor_compressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .section_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN, - .vaddr_offset = 0, - .elf_target = EM_ARM, - .mod_gap = GRUB_KERNEL_ARM_COREBOOT_MOD_GAP, - .mod_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN, - .link_align = 4, - .link_addr = 0x43000000, - }, { .dirname = "arm-efi", .names = { "arm-efi", NULL }, @@ -602,7 +573,12 @@ static const struct grub_install_image_target_desc image_targets[] = .decompressor_uncompressed_size = TARGET_NO_FIELD, .decompressor_uncompressed_addr = TARGET_NO_FIELD, .section_align = GRUB_PE32_SECTION_ALIGNMENT, - .vaddr_offset = EFI32_HEADER_SIZE, + .vaddr_offset = ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE + + GRUB_PE32_SIGNATURE_SIZE + + sizeof (struct grub_pe32_coff_header) + + sizeof (struct grub_pe32_optional_header) + + 4 * sizeof (struct grub_pe32_section_table), + GRUB_PE32_SECTION_ALIGNMENT), .pe_target = GRUB_PE32_MACHINE_ARMTHUMB_MIXED, .elf_target = EM_ARM, }, @@ -622,40 +598,121 @@ static const struct grub_install_image_target_desc image_targets[] = .pe_target = GRUB_PE32_MACHINE_ARM64, .elf_target = EM_AARCH64, }, - { - .dirname = "riscv32-efi", - .names = { "riscv32-efi", NULL }, - .voidp_sizeof = 4, - .bigendian = 0, - .id = IMAGE_EFI, - .flags = PLATFORM_FLAGS_NONE, - .total_module_size = TARGET_NO_FIELD, - .decompressor_compressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .section_align = GRUB_PE32_SECTION_ALIGNMENT, - .vaddr_offset = EFI32_HEADER_SIZE, - .pe_target = GRUB_PE32_MACHINE_RISCV32, - .elf_target = EM_RISCV, - }, - { - .dirname = "riscv64-efi", - .names = { "riscv64-efi", NULL }, - .voidp_sizeof = 8, - .bigendian = 0, - .id = IMAGE_EFI, - .flags = PLATFORM_FLAGS_NONE, - .total_module_size = TARGET_NO_FIELD, - .decompressor_compressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_size = TARGET_NO_FIELD, - .decompressor_uncompressed_addr = TARGET_NO_FIELD, - .section_align = GRUB_PE32_SECTION_ALIGNMENT, - .vaddr_offset = EFI64_HEADER_SIZE, - .pe_target = GRUB_PE32_MACHINE_RISCV64, - .elf_target = EM_RISCV, - }, }; +#define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x))) +#define grub_host_to_target32(x) (grub_host_to_target32_real (image_target, (x))) +#define grub_target_to_host64(x) (grub_target_to_host64_real (image_target, (x))) +#define grub_host_to_target64(x) (grub_host_to_target64_real (image_target, (x))) +#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (image_target, (x))) +#define grub_target_to_host16(x) (grub_target_to_host16_real (image_target, (x))) +#define grub_host_to_target16(x) (grub_host_to_target16_real (image_target, (x))) + +static inline grub_uint32_t +grub_target_to_host32_real (const struct grub_install_image_target_desc *image_target, + grub_uint32_t in) +{ + if (image_target->bigendian) + return grub_be_to_cpu32 (in); + else + return grub_le_to_cpu32 (in); +} + +static inline grub_uint64_t +grub_target_to_host64_real (const struct grub_install_image_target_desc *image_target, + grub_uint64_t in) +{ + if (image_target->bigendian) + return grub_be_to_cpu64 (in); + else + return grub_le_to_cpu64 (in); +} + +static inline grub_uint64_t +grub_host_to_target64_real (const struct grub_install_image_target_desc *image_target, + grub_uint64_t in) +{ + if (image_target->bigendian) + return grub_cpu_to_be64 (in); + else + return grub_cpu_to_le64 (in); +} + +static inline grub_uint32_t +grub_host_to_target32_real (const struct grub_install_image_target_desc *image_target, + grub_uint32_t in) +{ + if (image_target->bigendian) + return grub_cpu_to_be32 (in); + else + return grub_cpu_to_le32 (in); +} + +static inline grub_uint16_t +grub_target_to_host16_real (const struct grub_install_image_target_desc *image_target, + grub_uint16_t in) +{ + if (image_target->bigendian) + return grub_be_to_cpu16 (in); + else + return grub_le_to_cpu16 (in); +} + +static inline grub_uint16_t +grub_host_to_target16_real (const struct grub_install_image_target_desc *image_target, + grub_uint16_t in) +{ + if (image_target->bigendian) + return grub_cpu_to_be16 (in); + else + return grub_cpu_to_le16 (in); +} + +static inline grub_uint64_t +grub_host_to_target_addr_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in) +{ + if (image_target->voidp_sizeof == 8) + return grub_host_to_target64_real (image_target, in); + else + return grub_host_to_target32_real (image_target, in); +} + +static inline grub_uint64_t +grub_target_to_host_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in) +{ + if (image_target->voidp_sizeof == 8) + return grub_target_to_host64_real (image_target, in); + else + return grub_target_to_host32_real (image_target, in); +} + +#define GRUB_IEEE1275_NOTE_NAME "PowerPC" +#define GRUB_IEEE1275_NOTE_TYPE 0x1275 + +/* These structures are defined according to the CHRP binding to IEEE1275, + "Client Program Format" section. */ + +struct grub_ieee1275_note_desc +{ + grub_uint32_t real_mode; + grub_uint32_t real_base; + grub_uint32_t real_size; + grub_uint32_t virt_base; + grub_uint32_t virt_size; + grub_uint32_t load_base; +}; + +struct grub_ieee1275_note +{ + Elf32_Nhdr header; + char name[ALIGN_UP(sizeof (GRUB_IEEE1275_NOTE_NAME), 4)]; + struct grub_ieee1275_note_desc descriptor; +}; + +#define GRUB_XEN_NOTE_NAME "Xen" + +#define grub_target_to_host(val) grub_target_to_host_real(image_target, (val)) + #include static void *SzAlloc(void *p __attribute__ ((unused)), size_t size) { return xmalloc(size); } @@ -763,20 +820,125 @@ compress_kernel (const struct grub_install_image_target_desc *image_target, char if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS && (comp != GRUB_COMPRESSION_NONE)) - grub_util_error (_("unknown compression %d"), comp); + grub_util_error (_("unknown compression %d\n"), comp); *core_img = xmalloc (kernel_size); memcpy (*core_img, kernel_img, kernel_size); *core_size = kernel_size; } +struct fixup_block_list +{ + struct fixup_block_list *next; + int state; + struct grub_pe32_fixup_block b; +}; + +/* + * R_ARM_THM_CALL/THM_JUMP24 + * + * Relocate Thumb (T32) instruction set relative branches: + * B.W, BL and BLX + */ +static grub_err_t +grub_arm_reloc_thm_call (grub_uint16_t *target, Elf32_Addr sym_addr) +{ + grub_int32_t offset; + + offset = grub_arm_thm_call_get_offset (target); + + grub_dprintf ("dl", " sym_addr = 0x%08x", sym_addr); + + offset += sym_addr; + + grub_dprintf("dl", " BL*: target=%p, sym_addr=0x%08x, offset=%d\n", + target, sym_addr, offset); + + /* Keep traditional (pre-Thumb2) limits on blx. In any case if the kernel + is bigger than 2M (currently under 150K) then we probably have a problem + somewhere else. */ + if (offset < -0x200000 || offset >= 0x200000) + return grub_error (GRUB_ERR_BAD_MODULE, + "THM_CALL Relocation out of range."); + + grub_dprintf ("dl", " relative destination = %p", + (char *) target + offset); + + return grub_arm_thm_call_set_offset (target, offset); +} + +/* + * R_ARM_THM_JUMP19 + * + * Relocate conditional Thumb (T32) B.W + */ +static grub_err_t +grub_arm_reloc_thm_jump19 (grub_uint16_t *target, Elf32_Addr sym_addr) +{ + grub_int32_t offset; + + if (!(sym_addr & 1)) + return grub_error (GRUB_ERR_BAD_MODULE, + "Relocation targeting wrong execution state"); + + offset = grub_arm_thm_jump19_get_offset (target); + + /* Adjust and re-truncate offset */ + offset += sym_addr; + + if (!grub_arm_thm_jump19_check_offset (offset)) + return grub_error (GRUB_ERR_BAD_MODULE, + "THM_JUMP19 Relocation out of range."); + + grub_arm_thm_jump19_set_offset (target, offset); + + return GRUB_ERR_NONE; +} + +/* + * R_ARM_JUMP24 + * + * Relocate ARM (A32) B + */ +static grub_err_t +grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr) +{ + grub_int32_t offset; + + if (sym_addr & 1) + return grub_error (GRUB_ERR_BAD_MODULE, + "Relocation targeting wrong execution state"); + + offset = grub_arm_jump24_get_offset (target); + offset += sym_addr; + + if (!grub_arm_jump24_check_offset (offset)) + return grub_error (GRUB_ERR_BAD_MODULE, + "JUMP24 Relocation out of range."); + + + grub_arm_jump24_set_offset (target, offset); + + return GRUB_ERR_NONE; +} + +#pragma GCC diagnostic ignored "-Wcast-align" + +#define MKIMAGE_ELF32 1 +#include "grub-mkimagexx.c" +#undef MKIMAGE_ELF32 + +#define MKIMAGE_ELF64 1 +#include "grub-mkimagexx.c" +#undef MKIMAGE_ELF64 + const struct grub_install_image_target_desc * grub_install_get_image_target (const char *arg) { unsigned i, j; for (i = 0; i < ARRAY_SIZE (image_targets); i++) - for (j = 0; j < ARRAY_SIZE (image_targets[i].names) && - image_targets[i].names[j]; j++) + for (j = 0; image_targets[i].names[j] + && j < ARRAY_SIZE (image_targets[i].names); j++) if (strcmp (arg, image_targets[i].names[j]) == 0) return &image_targets[i]; return NULL; @@ -822,17 +984,21 @@ grub_install_generate_image (const char *dir, const char *prefix, char *memdisk_path, char **pubkey_paths, size_t npubkeys, char *config_path, const struct grub_install_image_target_desc *image_target, - int note, grub_compression_t comp, const char *dtb_path) + int note, + grub_compression_t comp) { char *kernel_img, *core_img; - size_t total_module_size, core_size; - size_t memdisk_size = 0, config_size = 0; - size_t prefix_size = 0, dtb_size = 0; + size_t kernel_size, total_module_size, core_size, exec_size; + size_t memdisk_size = 0, config_size = 0, config_size_pure = 0; + size_t prefix_size = 0; char *kernel_path; size_t offset; - struct grub_util_path_list *path_list, *p; + struct grub_util_path_list *path_list, *p, *next; + size_t bss_size; + grub_uint64_t start_address; + void *rel_section = 0; + size_t reloc_size = 0, align; size_t decompress_size = 0; - struct grub_mkimage_layout layout; if (comp == GRUB_COMPRESSION_AUTO) comp = image_target->default_compression; @@ -872,15 +1038,10 @@ grub_install_generate_image (const char *dir, const char *prefix, total_module_size += memdisk_size + sizeof (struct grub_module_header); } - if (dtb_path) - { - dtb_size = ALIGN_ADDR(grub_util_get_image_size (dtb_path)); - total_module_size += dtb_size + sizeof (struct grub_module_header); - } - if (config_path) { - config_size = ALIGN_ADDR (grub_util_get_image_size (config_path) + 1); + config_size_pure = grub_util_get_image_size (config_path) + 1; + config_size = ALIGN_ADDR (config_size_pure); grub_util_info ("the size of config file is 0x%" GRUB_HOST_PRIxLONG_LONG, (unsigned long long) config_size); total_module_size += config_size + sizeof (struct grub_module_header); @@ -900,14 +1061,15 @@ grub_install_generate_image (const char *dir, const char *prefix, (unsigned long long) total_module_size); if (image_target->voidp_sizeof == 4) - kernel_img = grub_mkimage_load_image32 (kernel_path, total_module_size, - &layout, image_target); + kernel_img = load_image32 (kernel_path, &exec_size, &kernel_size, &bss_size, + total_module_size, &start_address, &rel_section, + &reloc_size, &align, image_target); else - kernel_img = grub_mkimage_load_image64 (kernel_path, total_module_size, - &layout, image_target); - if ((image_target->id == IMAGE_XEN || image_target->id == IMAGE_XEN_PVH) && - layout.align < 4096) - layout.align = 4096; + kernel_img = load_image64 (kernel_path, &exec_size, &kernel_size, &bss_size, + total_module_size, &start_address, &rel_section, + &reloc_size, &align, image_target); + if (image_target->id == IMAGE_XEN && align < 4096) + align = 4096; if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS) && (image_target->total_module_size != TARGET_NO_FIELD)) @@ -915,10 +1077,7 @@ grub_install_generate_image (const char *dir, const char *prefix, = grub_host_to_target32 (total_module_size); if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) - { - memmove (kernel_img + total_module_size, kernel_img, layout.kernel_size); - memset (kernel_img, 0, total_module_size); - } + memmove (kernel_img + total_module_size, kernel_img, kernel_size); if (image_target->voidp_sizeof == 8) { @@ -927,14 +1086,15 @@ grub_install_generate_image (const char *dir, const char *prefix, if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) modinfo = (struct grub_module_info64 *) kernel_img; else - modinfo = (struct grub_module_info64 *) (kernel_img + layout.kernel_size); + modinfo = (struct grub_module_info64 *) (kernel_img + kernel_size); + memset (modinfo, 0, sizeof (struct grub_module_info64)); modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC); modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info64)); modinfo->size = grub_host_to_target_addr (total_module_size); if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) offset = sizeof (struct grub_module_info64); else - offset = layout.kernel_size + sizeof (struct grub_module_info64); + offset = kernel_size + sizeof (struct grub_module_info64); } else { @@ -943,27 +1103,31 @@ grub_install_generate_image (const char *dir, const char *prefix, if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) modinfo = (struct grub_module_info32 *) kernel_img; else - modinfo = (struct grub_module_info32 *) (kernel_img + layout.kernel_size); + modinfo = (struct grub_module_info32 *) (kernel_img + kernel_size); + memset (modinfo, 0, sizeof (struct grub_module_info32)); modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC); modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info32)); modinfo->size = grub_host_to_target_addr (total_module_size); if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL) offset = sizeof (struct grub_module_info32); else - offset = layout.kernel_size + sizeof (struct grub_module_info32); + offset = kernel_size + sizeof (struct grub_module_info32); } for (p = path_list; p; p = p->next) { struct grub_module_header *header; - size_t mod_size; + size_t mod_size, orig_size; - mod_size = ALIGN_ADDR (grub_util_get_image_size (p->name)); + orig_size = grub_util_get_image_size (p->name); + mod_size = ALIGN_ADDR (orig_size); header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); header->type = grub_host_to_target32 (OBJ_TYPE_ELF); header->size = grub_host_to_target32 (mod_size + sizeof (*header)); offset += sizeof (*header); + memset (kernel_img + offset + orig_size, 0, mod_size - orig_size); grub_util_load_image (p->name, kernel_img + offset); offset += mod_size; @@ -979,6 +1143,7 @@ grub_install_generate_image (const char *dir, const char *prefix, curs = grub_util_get_image_size (pubkey_paths[i]); header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); header->type = grub_host_to_target32 (OBJ_TYPE_PUBKEY); header->size = grub_host_to_target32 (curs + sizeof (*header)); offset += sizeof (*header); @@ -993,6 +1158,7 @@ grub_install_generate_image (const char *dir, const char *prefix, struct grub_module_header *header; header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); header->type = grub_host_to_target32 (OBJ_TYPE_MEMDISK); header->size = grub_host_to_target32 (memdisk_size + sizeof (*header)); offset += sizeof (*header); @@ -1001,29 +1167,18 @@ grub_install_generate_image (const char *dir, const char *prefix, offset += memdisk_size; } - if (dtb_path) - { - struct grub_module_header *header; - - header = (struct grub_module_header *) (kernel_img + offset); - header->type = grub_host_to_target32 (OBJ_TYPE_DTB); - header->size = grub_host_to_target32 (dtb_size + sizeof (*header)); - offset += sizeof (*header); - - grub_util_load_image (dtb_path, kernel_img + offset); - offset += dtb_size; - } - if (config_path) { struct grub_module_header *header; header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); header->type = grub_host_to_target32 (OBJ_TYPE_CONFIG); header->size = grub_host_to_target32 (config_size + sizeof (*header)); offset += sizeof (*header); grub_util_load_image (config_path, kernel_img + offset); + *(kernel_img + offset + config_size_pure - 1) = 0; offset += config_size; } @@ -1032,18 +1187,20 @@ grub_install_generate_image (const char *dir, const char *prefix, struct grub_module_header *header; header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); header->type = grub_host_to_target32 (OBJ_TYPE_PREFIX); header->size = grub_host_to_target32 (prefix_size + sizeof (*header)); offset += sizeof (*header); + grub_memset (kernel_img + offset, 0, prefix_size); grub_strcpy (kernel_img + offset, prefix); offset += prefix_size; } grub_util_info ("kernel_img=%p, kernel_size=0x%" GRUB_HOST_PRIxLONG_LONG, kernel_img, - (unsigned long long) layout.kernel_size); - compress_kernel (image_target, kernel_img, layout.kernel_size + total_module_size, + (unsigned long long) kernel_size); + compress_kernel (image_target, kernel_img, kernel_size + total_module_size, &core_img, &core_size, comp); free (kernel_img); @@ -1074,7 +1231,7 @@ grub_install_generate_image (const char *dir, const char *prefix, name = "none_decompress.img"; break; default: - grub_util_error (_("unknown compression %d"), comp); + grub_util_error (_("unknown compression %d\n"), comp); } decompress_path = grub_util_get_path (dir, name); @@ -1095,7 +1252,7 @@ grub_install_generate_image (const char *dir, const char *prefix, if (image_target->decompressor_uncompressed_size != TARGET_NO_FIELD) *((grub_uint32_t *) (decompress_img + image_target->decompressor_uncompressed_size)) - = grub_host_to_target32 (layout.kernel_size + total_module_size); + = grub_host_to_target32 (kernel_size + total_module_size); if (image_target->decompressor_uncompressed_addr != TARGET_NO_FIELD) { @@ -1109,16 +1266,18 @@ grub_install_generate_image (const char *dir, const char *prefix, full_size = core_size + decompress_size; full_img = xmalloc (full_size); + memset (full_img, 0, full_size); memcpy (full_img, decompress_img, decompress_size); memcpy (full_img + decompress_size, core_img, core_size); + memset (full_img + decompress_size + core_size, 0, + full_size - (decompress_size + core_size)); + free (core_img); core_img = full_img; core_size = full_size; - free (decompress_img); - free (decompress_path); } switch (image_target->id) @@ -1128,17 +1287,16 @@ grub_install_generate_image (const char *dir, const char *prefix, case IMAGE_I386_PC_ELTORITO: if (GRUB_KERNEL_I386_PC_LINK_ADDR + core_size > 0x78000 || (core_size > (0xffff << GRUB_DISK_SECTOR_BITS)) - || (layout.kernel_size + layout.bss_size - + GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000)) + || (kernel_size + bss_size + GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000)) grub_util_error (_("core image is too big (0x%x > 0x%x)"), GRUB_KERNEL_I386_PC_LINK_ADDR + (unsigned) core_size, 0x78000); /* fallthrough */ case IMAGE_COREBOOT: case IMAGE_QEMU: - if (image_target->elf_target != EM_ARM && layout.kernel_size + layout.bss_size + GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000) + if (kernel_size + bss_size + GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000) grub_util_error (_("kernel image is too big (0x%x > 0x%x)"), - (unsigned) layout.kernel_size + (unsigned) layout.bss_size + (unsigned) kernel_size + (unsigned) bss_size + GRUB_KERNEL_I386_PC_LINK_ADDR, 0x68000); break; @@ -1149,7 +1307,6 @@ grub_install_generate_image (const char *dir, const char *prefix, case IMAGE_MIPS_ARC: case IMAGE_QEMU_MIPS_FLASH: case IMAGE_XEN: - case IMAGE_XEN_PVH: break; case IMAGE_SPARC64_AOUT: case IMAGE_SPARC64_RAW: @@ -1259,15 +1416,14 @@ grub_install_generate_image (const char *dir, const char *prefix, header_size = EFI64_HEADER_SIZE; reloc_addr = ALIGN_UP (header_size + core_size, - GRUB_PE32_FILE_ALIGNMENT); + image_target->section_align); - pe_size = ALIGN_UP (reloc_addr + layout.reloc_size, - GRUB_PE32_FILE_ALIGNMENT); - pe_img = xmalloc (reloc_addr + layout.reloc_size); + pe_size = ALIGN_UP (reloc_addr + reloc_size, + image_target->section_align); + pe_img = xmalloc (reloc_addr + reloc_size); memset (pe_img, 0, header_size); memcpy ((char *) pe_img + header_size, core_img, core_size); - memset ((char *) pe_img + header_size + core_size, 0, reloc_addr - (header_size + core_size)); - memcpy ((char *) pe_img + reloc_addr, layout.reloc_section, layout.reloc_size); + memcpy ((char *) pe_img + reloc_addr, rel_section, reloc_size); header = pe_img; /* The magic. */ @@ -1281,7 +1437,7 @@ grub_install_generate_image (const char *dir, const char *prefix, c->machine = grub_host_to_target16 (image_target->pe_target); c->num_sections = grub_host_to_target16 (4); - c->time = grub_host_to_target32 (STABLE_EMBEDDING_TIMESTAMP); + c->time = grub_host_to_target32 (time (0)); c->characteristics = grub_host_to_target16 (GRUB_PE32_EXECUTABLE_IMAGE | GRUB_PE32_LINE_NUMS_STRIPPED | ((image_target->voidp_sizeof == 4) @@ -1301,18 +1457,18 @@ grub_install_generate_image (const char *dir, const char *prefix, (header + GRUB_PE32_MSDOS_STUB_SIZE + GRUB_PE32_SIGNATURE_SIZE + sizeof (struct grub_pe32_coff_header)); o->magic = grub_host_to_target16 (GRUB_PE32_PE32_MAGIC); - o->code_size = grub_host_to_target32 (layout.exec_size); - o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size + o->code_size = grub_host_to_target32 (exec_size); + o->data_size = grub_cpu_to_le32 (reloc_addr - exec_size - header_size); - o->bss_size = grub_cpu_to_le32 (layout.bss_size); - o->entry_addr = grub_cpu_to_le32 (layout.start_address); + o->bss_size = grub_cpu_to_le32 (bss_size); + o->entry_addr = grub_cpu_to_le32 (start_address); o->code_base = grub_cpu_to_le32 (header_size); - o->data_base = grub_host_to_target32 (header_size + layout.exec_size); + o->data_base = grub_host_to_target32 (header_size + exec_size); o->image_base = 0; o->section_alignment = grub_host_to_target32 (image_target->section_align); - o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT); + o->file_alignment = grub_host_to_target32 (image_target->section_align); o->image_size = grub_host_to_target32 (pe_size); o->header_size = grub_host_to_target32 (header_size); o->subsystem = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION); @@ -1326,7 +1482,7 @@ grub_install_generate_image (const char *dir, const char *prefix, o->num_data_directories = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES); o->base_relocation_table.rva = grub_host_to_target32 (reloc_addr); - o->base_relocation_table.size = grub_host_to_target32 (layout.reloc_size); + o->base_relocation_table.size = grub_host_to_target32 (reloc_size); sections = o + 1; } else @@ -1339,15 +1495,15 @@ grub_install_generate_image (const char *dir, const char *prefix, (header + GRUB_PE32_MSDOS_STUB_SIZE + GRUB_PE32_SIGNATURE_SIZE + sizeof (struct grub_pe32_coff_header)); o->magic = grub_host_to_target16 (GRUB_PE32_PE64_MAGIC); - o->code_size = grub_host_to_target32 (layout.exec_size); - o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size + o->code_size = grub_host_to_target32 (exec_size); + o->data_size = grub_cpu_to_le32 (reloc_addr - exec_size - header_size); - o->bss_size = grub_cpu_to_le32 (layout.bss_size); - o->entry_addr = grub_cpu_to_le32 (layout.start_address); + o->bss_size = grub_cpu_to_le32 (bss_size); + o->entry_addr = grub_cpu_to_le32 (start_address); o->code_base = grub_cpu_to_le32 (header_size); o->image_base = 0; o->section_alignment = grub_host_to_target32 (image_target->section_align); - o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT); + o->file_alignment = grub_host_to_target32 (image_target->section_align); o->image_size = grub_host_to_target32 (pe_size); o->header_size = grub_host_to_target32 (header_size); o->subsystem = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION); @@ -1362,15 +1518,15 @@ grub_install_generate_image (const char *dir, const char *prefix, = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES); o->base_relocation_table.rva = grub_host_to_target32 (reloc_addr); - o->base_relocation_table.size = grub_host_to_target32 (layout.reloc_size); + o->base_relocation_table.size = grub_host_to_target32 (reloc_size); sections = o + 1; } /* The sections. */ text_section = sections; strcpy (text_section->name, ".text"); - text_section->virtual_size = grub_cpu_to_le32 (layout.exec_size); + text_section->virtual_size = grub_cpu_to_le32 (exec_size); text_section->virtual_address = grub_cpu_to_le32 (header_size); - text_section->raw_data_size = grub_cpu_to_le32 (layout.exec_size); + text_section->raw_data_size = grub_cpu_to_le32 (exec_size); text_section->raw_data_offset = grub_cpu_to_le32 (header_size); text_section->characteristics = grub_cpu_to_le32_compile_time ( GRUB_PE32_SCN_CNT_CODE @@ -1379,10 +1535,10 @@ grub_install_generate_image (const char *dir, const char *prefix, data_section = text_section + 1; strcpy (data_section->name, ".data"); - data_section->virtual_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size); - data_section->virtual_address = grub_cpu_to_le32 (header_size + layout.exec_size); - data_section->raw_data_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size); - data_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.exec_size); + data_section->virtual_size = grub_cpu_to_le32 (kernel_size - exec_size); + data_section->virtual_address = grub_cpu_to_le32 (header_size + exec_size); + data_section->raw_data_size = grub_cpu_to_le32 (kernel_size - exec_size); + data_section->raw_data_offset = grub_cpu_to_le32 (header_size + exec_size); data_section->characteristics = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_READ @@ -1391,8 +1547,8 @@ grub_install_generate_image (const char *dir, const char *prefix, #if 0 bss_section = data_section + 1; strcpy (bss_section->name, ".bss"); - bss_section->virtual_size = grub_cpu_to_le32 (layout.bss_size); - bss_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size); + bss_section->virtual_size = grub_cpu_to_le32 (bss_size); + bss_section->virtual_address = grub_cpu_to_le32 (header_size + kernel_size); bss_section->raw_data_size = 0; bss_section->raw_data_offset = 0; bss_section->characteristics @@ -1405,10 +1561,10 @@ grub_install_generate_image (const char *dir, const char *prefix, mods_section = data_section + 1; strcpy (mods_section->name, "mods"); - mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size); - mods_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size + layout.bss_size); - mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size); - mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.kernel_size); + mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - kernel_size - header_size); + mods_section->virtual_address = grub_cpu_to_le32 (header_size + kernel_size + bss_size); + mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - kernel_size - header_size); + mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + kernel_size); mods_section->characteristics = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA | GRUB_PE32_SCN_MEM_READ @@ -1416,9 +1572,9 @@ grub_install_generate_image (const char *dir, const char *prefix, reloc_section = mods_section + 1; strcpy (reloc_section->name, ".reloc"); - reloc_section->virtual_size = grub_cpu_to_le32 (layout.reloc_size); - reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + layout.bss_size); - reloc_section->raw_data_size = grub_cpu_to_le32 (layout.reloc_size); + reloc_section->virtual_size = grub_cpu_to_le32 (reloc_size); + reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + bss_size); + reloc_section->raw_data_size = grub_cpu_to_le32 (reloc_size); reloc_section->raw_data_offset = grub_cpu_to_le32 (reloc_addr); reloc_section->characteristics = grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA @@ -1588,8 +1744,6 @@ grub_install_generate_image (const char *dir, const char *prefix, free (core_img); core_img = rom_img; core_size = rom_size; - free (boot_img); - free (boot_path); } break; case IMAGE_QEMU_MIPS_FLASH: @@ -1624,11 +1778,11 @@ grub_install_generate_image (const char *dir, const char *prefix, memset (hdr, 0, sizeof (*hdr)); hdr->ih_magic = grub_cpu_to_be32_compile_time (GRUB_UBOOT_IH_MAGIC); - hdr->ih_time = grub_cpu_to_be32 (STABLE_EMBEDDING_TIMESTAMP); + hdr->ih_time = grub_cpu_to_be32 (time (0)); hdr->ih_size = grub_cpu_to_be32 (core_size); - hdr->ih_load = 0; - hdr->ih_ep = 0; - hdr->ih_type = GRUB_UBOOT_IH_TYPE_KERNEL_NOLOAD; + hdr->ih_load = grub_cpu_to_be32 (image_target->link_addr); + hdr->ih_ep = grub_cpu_to_be32 (image_target->link_addr); + hdr->ih_type = GRUB_UBOOT_IH_TYPE_KERNEL; hdr->ih_os = GRUB_UBOOT_IH_OS_LINUX; hdr->ih_arch = GRUB_UBOOT_IH_ARCH_ARM; hdr->ih_comp = GRUB_UBOOT_IH_COMP_NONE; @@ -1689,7 +1843,7 @@ grub_install_generate_image (const char *dir, const char *prefix, target_addr = (image_target->link_addr - decompress_size); else target_addr = ALIGN_UP (image_target->link_addr - + layout.kernel_size + total_module_size, 32); + + kernel_size + total_module_size, 32); ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section)); grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section)); @@ -1726,7 +1880,6 @@ grub_install_generate_image (const char *dir, const char *prefix, case IMAGE_LOONGSON_ELF: case IMAGE_PPC: case IMAGE_XEN: - case IMAGE_XEN_PVH: case IMAGE_COREBOOT: case IMAGE_I386_IEEE1275: { @@ -1737,16 +1890,16 @@ grub_install_generate_image (const char *dir, const char *prefix, target_addr = (image_target->link_addr - decompress_size); else target_addr = ALIGN_UP (image_target->link_addr - + layout.kernel_size + total_module_size, 32); + + kernel_size + total_module_size, 32); } else target_addr = image_target->link_addr; if (image_target->voidp_sizeof == 4) - grub_mkimage_generate_elf32 (image_target, note, &core_img, &core_size, - target_addr, &layout); + generate_elf32 (image_target, note, &core_img, &core_size, + target_addr, align, kernel_size, bss_size); else - grub_mkimage_generate_elf64 (image_target, note, &core_img, &core_size, - target_addr, &layout); + generate_elf64 (image_target, note, &core_img, &core_size, + target_addr, align, kernel_size, bss_size); } break; } @@ -1754,7 +1907,13 @@ grub_install_generate_image (const char *dir, const char *prefix, grub_util_write_image (core_img, core_size, out, outname); free (core_img); free (kernel_path); - free (layout.reloc_section); + free (rel_section); - grub_util_free_path_list (path_list); + while (path_list) + { + next = path_list->next; + free ((void *) path_list->name); + free (path_list); + path_list = next; + } } diff --git a/util/probe.c b/util/probe.c index fa7ca34d1..c389f5dcf 100644 --- a/util/probe.c +++ b/util/probe.c @@ -73,7 +73,7 @@ grub_util_guess_bios_drive (const char *orig_path) { char *canon; char *ptr; - canon = grub_canonicalize_file_name (orig_path); + canon = canonicalize_file_name (orig_path); if (!canon) return NULL; ptr = strrchr (orig_path, '/'); @@ -102,7 +102,7 @@ grub_util_guess_efi_drive (const char *orig_path) { char *canon; char *ptr; - canon = grub_canonicalize_file_name (orig_path); + canon = canonicalize_file_name (orig_path); if (!canon) return NULL; ptr = strrchr (orig_path, '/'); @@ -131,7 +131,7 @@ grub_util_guess_baremetal_drive (const char *orig_path) { char *canon; char *ptr; - canon = grub_canonicalize_file_name (orig_path); + canon = canonicalize_file_name (orig_path); if (!canon) return NULL; ptr = strrchr (orig_path, '/'); diff --git a/util/render-label.c b/util/render-label.c index 91c080c9c..39663a8a7 100644 --- a/util/render-label.c +++ b/util/render-label.c @@ -157,7 +157,7 @@ grub_util_render_label (const char *label_font, ieee1275_palette[cptr].a = 0xff; char * t; - t = grub_canonicalize_file_name (label_font); + t = canonicalize_file_name (label_font); if (!t) { grub_util_error (_("cannot open `%s': %s"), label_font, diff --git a/util/resolve.c b/util/resolve.c index 3e887d2ff..002bfbd72 100644 --- a/util/resolve.c +++ b/util/resolve.c @@ -271,17 +271,3 @@ grub_util_resolve_dependencies (const char *prefix, return prev; } } - -void -grub_util_free_path_list (struct grub_util_path_list *path_list) -{ - struct grub_util_path_list *next; - - while (path_list) - { - next = path_list->next; - free ((void *) path_list->name); - free (path_list); - path_list = next; - } -} diff --git a/util/setup.c b/util/setup.c index 3be88aae1..9fb91a82f 100644 --- a/util/setup.c +++ b/util/setup.c @@ -137,9 +137,6 @@ struct blocklists struct grub_boot_blocklist *first_block, *block; #ifdef GRUB_SETUP_BIOS grub_uint16_t current_segment; -#endif -#ifdef GRUB_SETUP_SPARC64 - grub_uint64_t gpt_offset; #endif grub_uint16_t last_length; grub_disk_addr_t first_sector; @@ -154,10 +151,6 @@ save_blocklists (grub_disk_addr_t sector, unsigned offset, unsigned length, struct grub_boot_blocklist *prev = bl->block + 1; grub_uint64_t seclen; -#ifdef GRUB_SETUP_SPARC64 - sector -= bl->gpt_offset; -#endif - grub_util_info ("saving <%" GRUB_HOST_PRIuLONG_LONG ",%u,%u>", (unsigned long long) sector, offset, length); @@ -205,6 +198,7 @@ save_blocklists (grub_disk_addr_t sector, unsigned offset, unsigned length, #endif } +#ifdef GRUB_SETUP_BIOS /* Context for setup/identify_partmap. */ struct identify_partmap_ctx { @@ -240,6 +234,7 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)), ctx->multiple_partmaps = 1; return 1; } +#endif #ifdef GRUB_SETUP_BIOS #define SETUP grub_util_bios_setup @@ -260,7 +255,9 @@ SETUP (const char *dir, char *boot_img, *core_img, *boot_path; char *root = 0; size_t boot_size, core_size; +#ifdef GRUB_SETUP_BIOS grub_uint16_t core_sectors; +#endif grub_device_t root_dev = 0, dest_dev, core_dev; grub_util_fd_t fp; struct blocklists bl; @@ -270,9 +267,6 @@ SETUP (const char *dir, #ifdef GRUB_SETUP_BIOS bl.current_segment = GRUB_BOOT_I386_PC_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4); -#endif -#ifdef GRUB_SETUP_SPARC64 - bl.gpt_offset = 0; #endif bl.last_length = 0; @@ -287,8 +281,10 @@ SETUP (const char *dir, core_path = grub_util_get_path (dir, core_file); core_size = grub_util_get_image_size (core_path); +#ifdef GRUB_SETUP_BIOS core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); +#endif if (core_size < GRUB_DISK_SECTOR_SIZE) grub_util_error (_("the size of `%s' is too small"), core_path); #ifdef GRUB_SETUP_BIOS @@ -302,8 +298,9 @@ SETUP (const char *dir, bl.first_block = (struct grub_boot_blocklist *) (core_img + GRUB_DISK_SECTOR_SIZE - sizeof (*bl.block)); + grub_util_info ("root is `%s', dest is `%s'", root, dest); - grub_util_info ("Opening dest `%s'", dest); + grub_util_info ("Opening dest"); dest_dev = grub_device_open (dest); if (! dest_dev) grub_util_error ("%s", grub_errmsg); @@ -315,9 +312,6 @@ SETUP (const char *dir, char **cur; int found = 0; - if (!root_devices) - grub_util_error (_("cannot find a device for %s (is /dev mounted?)"), dir); - for (cur = root_devices; *cur; cur++) { char *drive; @@ -328,10 +322,7 @@ SETUP (const char *dir, continue; try_dev = grub_device_open (drive); if (! try_dev) - { - free (drive); - continue; - } + continue; if (!found && try_dev->disk->id == dest_dev->disk->id && try_dev->disk->dev->id == dest_dev->disk->dev->id) { @@ -359,18 +350,14 @@ SETUP (const char *dir, } grub_util_info ("guessed root_dev `%s' from " "dir `%s'", root_dev->disk->name, dir); - - for (cur = root_devices; *cur; cur++) - free (*cur); - free (root_devices); } grub_util_info ("setting the root device to `%s'", root); if (grub_env_set ("root", root) != GRUB_ERR_NONE) grub_util_error ("%s", grub_errmsg); - { #ifdef GRUB_SETUP_BIOS + { char *tmp_img; grub_uint8_t *boot_drive_check; @@ -395,7 +382,6 @@ SETUP (const char *dir, boot_drive_check[0] = 0x90; boot_drive_check[1] = 0x90; } -#endif struct identify_partmap_ctx ctx = { .dest_partmap = NULL, @@ -411,7 +397,6 @@ SETUP (const char *dir, grub_partition_iterate (dest_dev->disk, identify_partmap, &ctx); -#ifdef GRUB_SETUP_BIOS /* Copy the partition table. */ if (ctx.dest_partmap || (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))) @@ -420,7 +405,6 @@ SETUP (const char *dir, GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC); free (tmp_img); -#endif if (ctx.container && grub_strcmp (ctx.container->partmap->name, "msdos") == 0 @@ -494,7 +478,7 @@ SETUP (const char *dir, goto unable_to_embed; } - if (fs && !fs->fs_embed) + if (fs && !fs->embed) { grub_util_warn (_("File system `%s' doesn't support embedding"), fs->name); @@ -508,22 +492,10 @@ SETUP (const char *dir, else maxsec = core_sectors; -#ifdef GRUB_SETUP_BIOS if (maxsec > ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) >> GRUB_DISK_SECTOR_BITS)) maxsec = ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) >> GRUB_DISK_SECTOR_BITS); -#endif - -#ifdef GRUB_SETUP_SPARC64 - /* - * On SPARC we need two extra. One is because we are combining the - * core.img with the boot.img. The other is because the boot sector - * starts at 1. - */ - nsec += 2; - maxsec += 2; -#endif if (is_ldm) err = grub_util_ldm_embed (dest_dev->disk, &nsec, maxsec, @@ -532,8 +504,8 @@ SETUP (const char *dir, err = ctx.dest_partmap->embed (dest_dev->disk, &nsec, maxsec, GRUB_EMBED_PCBIOS, §ors); else - err = fs->fs_embed (dest_dev, &nsec, maxsec, - GRUB_EMBED_PCBIOS, §ors); + err = fs->embed (dest_dev, &nsec, maxsec, + GRUB_EMBED_PCBIOS, §ors); if (!err && nsec < core_sectors) { err = grub_error (GRUB_ERR_OUT_OF_RANGE, @@ -554,7 +526,7 @@ SETUP (const char *dir, bl.block = bl.first_block; while (bl.block->len) { - grub_memset (bl.block, 0, sizeof (*bl.block)); + grub_memset (bl.block, 0, sizeof (bl.block)); bl.block--; @@ -572,39 +544,9 @@ SETUP (const char *dir, bl.block--; bl.block->start = 0; bl.block->len = 0; -#ifdef GRUB_SETUP_BIOS bl.block->segment = 0; -#endif -#ifdef GRUB_SETUP_SPARC64 - { - /* - * On SPARC, the block-list entries need to be based off the beginning - * of the parition, not the beginning of the disk. - */ - struct grub_boot_blocklist *block; - block = bl.first_block; - - while (block->len) - { - block->start -= bl.first_sector; - block--; - } - } - - /* - * Reserve space for the boot block since it can not be in the - * Parition table on SPARC. - */ - assert (bl.first_block->len > 2); - bl.first_block->start += 2; - bl.first_block->len -= 2; - write_rootdev (root_dev, boot_img, sectors[BOOT_SECTOR + 1] - bl.first_sector); -#endif - -#ifdef GRUB_SETUP_BIOS write_rootdev (root_dev, boot_img, bl.first_sector); -#endif /* Round up to the nearest sector boundary, and zero the extra memory */ core_img = xrealloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE); @@ -614,7 +556,7 @@ SETUP (const char *dir, bl.first_block = (struct grub_boot_blocklist *) (core_img + GRUB_DISK_SECTOR_SIZE - sizeof (*bl.block)); -#if GRUB_SETUP_BIOS + grub_size_t no_rs_length; no_rs_length = grub_target_to_host16 (grub_get_unaligned16 (core_img @@ -645,34 +587,14 @@ SETUP (const char *dir, grub_disk_write (dest_dev->disk, sectors[i], 0, GRUB_DISK_SECTOR_SIZE, core_img + i * GRUB_DISK_SECTOR_SIZE); -#endif -#ifdef GRUB_SETUP_SPARC64 - { - int isec = BOOT_SECTOR; - - /* Write the boot image onto the disk. */ - if (grub_disk_write (dest_dev->disk, sectors[isec++], 0, - GRUB_DISK_SECTOR_SIZE, boot_img)) - grub_util_error ("%s", grub_errmsg); - - /* Write the core image onto the disk. */ - for (i = 0 ; isec < nsec; i++, isec++) - { - if (grub_disk_write (dest_dev->disk, sectors[isec], 0, - GRUB_DISK_SECTOR_SIZE, - core_img + i * GRUB_DISK_SECTOR_SIZE)) - grub_util_error ("%s", grub_errmsg); - } - } - -#endif grub_free (sectors); goto finish; } unable_to_embed: +#endif if (dest_dev->disk->dev->id != root_dev->disk->dev->id) grub_util_error ("%s", _("embedding is not possible, but this is required for " @@ -730,15 +652,6 @@ unable_to_embed: bl.block = bl.first_block; -#ifdef GRUB_SETUP_SPARC64 - { - grub_partition_t container = root_dev->disk->partition; - - if (grub_strstr (container->partmap->name, "gpt")) - bl.gpt_offset = grub_partition_get_start (container); - } -#endif - grub_install_get_blocklist (root_dev, core_path, core_img, core_size, save_blocklists, &bl); @@ -754,17 +667,15 @@ unable_to_embed: if (dest_dev->disk->id != root_dev->disk->id || dest_dev->disk->dev->id != root_dev->disk->dev->id) { - char *dest_ofpath; + const char *dest_ofpath; dest_ofpath = grub_util_devname_to_ofpath (grub_util_biosdisk_get_osdev (root_dev->disk)); - /* FIXME handle NULL result */ grub_util_info ("dest_ofpath is `%s'", dest_ofpath); strncpy (boot_devpath, dest_ofpath, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END - GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1); boot_devpath[GRUB_BOOT_MACHINE_BOOT_DEVPATH_END - GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0; - free (dest_ofpath); } else { @@ -789,10 +700,8 @@ unable_to_embed: != GRUB_DISK_SECTOR_SIZE * 2) grub_util_error (_("cannot write to `%s': %s"), core_path, strerror (errno)); - if (grub_util_fd_sync (fp) < 0) - grub_util_error (_("cannot sync `%s': %s"), core_path, strerror (errno)); - if (grub_util_fd_close (fp) < 0) - grub_util_error (_("cannot close `%s': %s"), core_path, strerror (errno)); + grub_util_fd_sync (fp); + grub_util_fd_close (fp); grub_util_biosdisk_flush (root_dev->disk); grub_disk_cache_invalidate_all (); @@ -800,18 +709,15 @@ unable_to_embed: { char *buf, *ptr = core_img; size_t len = core_size; - grub_uint64_t blk, offset = 0; + grub_uint64_t blk; grub_partition_t container = core_dev->disk->partition; grub_err_t err; core_dev->disk->partition = 0; -#ifdef GRUB_SETUP_SPARC64 - offset = bl.gpt_offset; -#endif buf = xmalloc (core_size); blk = bl.first_sector; - err = grub_disk_read (core_dev->disk, blk + offset, 0, GRUB_DISK_SECTOR_SIZE, buf); + err = grub_disk_read (core_dev->disk, blk, 0, GRUB_DISK_SECTOR_SIZE, buf); if (err) grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name, grub_errmsg); @@ -830,7 +736,7 @@ unable_to_embed: if (cur > len) cur = len; - err = grub_disk_read (core_dev->disk, blk + offset, 0, cur, buf); + err = grub_disk_read (core_dev->disk, blk, 0, cur, buf); if (err) grub_util_error (_("cannot read `%s': %s"), core_dev->disk->name, grub_errmsg); @@ -860,10 +766,6 @@ unable_to_embed: 0, GRUB_DISK_SECTOR_SIZE, boot_img)) grub_util_error ("%s", grub_errmsg); -#ifdef GRUB_SETUP_SPARC64 - finish: -#endif - grub_util_biosdisk_flush (root_dev->disk); grub_util_biosdisk_flush (dest_dev->disk);