exec_conf.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $OpenBSD: exec_conf.c,v 1.33 2015/07/18 00:15:10 mpi Exp $ */
  2. /* $NetBSD: exec_conf.c,v 1.16 1995/12/09 05:34:47 cgd Exp $ */
  3. /*
  4. * Copyright (c) 1993, 1994 Christopher G. Demetriou
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by Christopher G. Demetriou.
  18. * 4. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include <sys/param.h>
  33. #include <sys/exec.h>
  34. #include <sys/exec_script.h>
  35. #if defined(_KERN_DO_ELF) || defined(_KERN_DO_ELF64)
  36. #include <sys/exec_elf.h>
  37. #endif
  38. #ifdef COMPAT_LINUX
  39. #include <compat/linux/linux_exec.h>
  40. #endif
  41. extern struct emul emul_native, emul_linux_elf;
  42. struct execsw execsw[] = {
  43. { EXEC_SCRIPT_HDRSZ, exec_script_makecmds, &emul_native, }, /* shell scripts */
  44. #ifdef _KERN_DO_ELF
  45. { sizeof(Elf32_Ehdr), exec_elf32_makecmds, &emul_native }, /* elf binaries */
  46. #endif
  47. #ifdef _KERN_DO_ELF64
  48. { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_native }, /* elf binaries */
  49. #endif /* ELF64 */
  50. #ifdef COMPAT_LINUX
  51. { sizeof(Elf32_Ehdr), exec_linux_elf32_makecmds, &emul_linux_elf },
  52. #endif
  53. };
  54. int nexecs = (sizeof execsw / sizeof(*execsw));
  55. int exec_maxhdrsz;
  56. void init_exec(void);
  57. void
  58. init_exec(void)
  59. {
  60. int i;
  61. /*
  62. * figure out the maximum size of an exec header.
  63. */
  64. for (i = 0; i < nexecs; i++)
  65. if (execsw[i].es_check != NULL &&
  66. execsw[i].es_hdrsz > exec_maxhdrsz)
  67. exec_maxhdrsz = execsw[i].es_hdrsz;
  68. }