AuxiliaryVector.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Types.h>
  9. /* Auxiliary Vector types, from Intel386 ABI ver 1.0 section 2.3.3 */
  10. typedef struct
  11. {
  12. long a_type; /* Note: Extended to long from int, for ease of compatibility w/64 bit */
  13. union {
  14. long a_val;
  15. void* a_ptr;
  16. void (*a_fnc)(); /* In spec, not used */
  17. } a_un;
  18. } auxv_t;
  19. static_assert(sizeof(auxv_t) % sizeof(FlatPtr) == 0);
  20. #define AT_NULL 0 /* No length, last entry's a_type has this value */
  21. #define AT_IGNORE 1 /* Entry has no meaning, a_un undefined */
  22. #define AT_EXECFD 2 /* a_val contains a file descriptor of the main program image */
  23. #define AT_PHDR 3 /* a_ptr contains pointer to program header table of main program image */
  24. #define AT_PHENT 4 /* a_val holds size of program header table entries */
  25. #define AT_PHNUM 5 /* a_val holds number of program header table entries */
  26. #define AT_PAGESZ 6 /* a_val gives system page size in bytes */
  27. #define AT_BASE 7 /* a_ptr holds base address that Loader was loaded into memory */
  28. #define AT_FLAGS 8 /* a_val holds 1 bit flags. Undefined flags are 0 */
  29. #define AT_ENTRY 9 /* a_ptr holds entry point of the main program */
  30. #define AT_NOTELF 10 /* a_val non-zero if the program is not ELF */
  31. #define AT_UID 11 /* a_val holds real user id of process */
  32. #define AT_EUID 12 /* a_val holds effective user id of process */
  33. #define AT_GID 13 /* a_val holds real group id of process */
  34. #define AT_EGID 14 /* a_val holds effective group id of process */
  35. #define AT_PLATFORM 15 /* a_val points to a string containing platform name */
  36. #define AT_HWCAP 16 /* a_val contains bitmask of CPU features. Equivalent to CPUID 1.EDX*/
  37. #define AT_CLKTCK 17 /* a_val contains frequence at which times() increments. (Re: Spec. What is times()?) */
  38. #define AT_SECURE 23 /* a_val holds 1 if program in secure mode (e.g. suid). Otherwise 0 */
  39. #define AT_BASE_PLATFORM 24 /* a_ptr points to a string identifying base platform name, which might be different from platform (e.g x86_64 when in i386 compat) */
  40. #define AT_RANDOM 25 /* a_ptr points to 16 securely generated random bytes */
  41. #define AT_HWCAP2 26 /* a_val holds extended hw feature mask. Currently 0 */
  42. #define AT_EXECFN 31 /* a_ptr points to filename of executed program */
  43. #define AT_EXE_BASE 32 /* a_ptr holds base address where main program was loaded into memory */
  44. #define AT_EXE_SIZE 33 /* a_val holds the size of the main program in memory */
  45. namespace ELF {
  46. struct AuxiliaryValue {
  47. enum Type {
  48. Null = AT_NULL,
  49. Ignore = AT_IGNORE,
  50. ExecFileDescriptor = AT_EXECFD,
  51. Phdr = AT_PHDR,
  52. Phent = AT_PHENT,
  53. Phnum = AT_PHNUM,
  54. PageSize = AT_PAGESZ,
  55. BaseAddress = AT_BASE,
  56. Flags = AT_FLAGS,
  57. Entry = AT_ENTRY,
  58. NotELF = AT_NOTELF,
  59. Uid = AT_UID,
  60. EUid = AT_EUID,
  61. Gid = AT_GID,
  62. EGid = AT_EGID,
  63. Platform = AT_PLATFORM,
  64. HwCap = AT_HWCAP,
  65. ClockTick = AT_CLKTCK,
  66. Secure = AT_SECURE,
  67. BasePlatform = AT_BASE_PLATFORM,
  68. Random = AT_RANDOM,
  69. HwCap2 = AT_HWCAP2,
  70. ExecFilename = AT_EXECFN,
  71. ExeBaseAddress = AT_EXE_BASE,
  72. ExeSize = AT_EXE_SIZE
  73. };
  74. AuxiliaryValue(Type type, long val)
  75. {
  76. auxv.a_type = type;
  77. auxv.a_un.a_val = val;
  78. }
  79. AuxiliaryValue(Type type, void* ptr)
  80. {
  81. auxv.a_type = type;
  82. auxv.a_un.a_ptr = (void*)ptr;
  83. }
  84. AuxiliaryValue(Type type, String string)
  85. {
  86. auxv.a_type = type;
  87. auxv.a_un.a_ptr = nullptr;
  88. optional_string = string;
  89. }
  90. auxv_t auxv {};
  91. String optional_string;
  92. };
  93. }