Changeset 3e828ea in mainline for kernel/generic/src/lib
- Timestamp:
- 2019-09-23T12:49:29Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9be2358
- Parents:
- 9259d20 (diff), 1a4ec93f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- Jiri Svoboda <jiri@…> (2019-09-22 12:49:07)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-09-23 12:49:29)
- Location:
- kernel/generic/src/lib
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/elf.c
r9259d20 r3e828ea 50 50 #include <lib/elf_load.h> 51 51 52 static const char *error_codes[] = { 53 "no error", 54 "invalid image", 55 "address space error", 56 "incompatible image", 57 "unsupported image type", 58 "irrecoverable error" 59 }; 60 61 static int load_segment(elf_segment_header_t *, elf_header_t *, as_t *); 52 static errno_t load_segment(elf_segment_header_t *, elf_header_t *, as_t *); 62 53 63 54 /** ELF loader … … 67 58 * @param flags A combination of ELD_F_* 68 59 * 69 * @return E E_OK on success60 * @return EOK on success 70 61 * 71 62 */ 72 unsigned int elf_load(elf_header_t *header, as_t *as)63 errno_t elf_load(elf_header_t *header, as_t *as) 73 64 { 74 65 /* Identify ELF */ … … 77 68 (header->e_ident[EI_MAG2] != ELFMAG2) || 78 69 (header->e_ident[EI_MAG3] != ELFMAG3)) 79 return E E_INVALID;70 return EINVAL; 80 71 81 72 /* Identify ELF compatibility */ … … 85 76 (header->e_version != EV_CURRENT) || 86 77 (header->e_ident[EI_CLASS] != ELF_CLASS)) 87 return E E_INCOMPATIBLE;78 return EINVAL; 88 79 89 80 if (header->e_phentsize != sizeof(elf_segment_header_t)) 90 return E E_INCOMPATIBLE;81 return EINVAL; 91 82 92 83 /* Check if the object type is supported. */ 93 84 if (header->e_type != ET_EXEC) 94 return E E_UNSUPPORTED;85 return ENOTSUP; 95 86 96 87 /* Check if the ELF image starts on a page boundary */ 97 88 if (ALIGN_UP((uintptr_t) header, PAGE_SIZE) != (uintptr_t) header) 98 return E E_UNSUPPORTED;89 return ENOTSUP; 99 90 100 91 /* Walk through all segment headers and process them. */ … … 108 99 continue; 109 100 110 int rc = load_segment(seghdr, header, as);111 if (rc != E E_OK)101 errno_t rc = load_segment(seghdr, header, as); 102 if (rc != EOK) 112 103 return rc; 113 104 } 114 105 115 return EE_OK; 116 } 117 118 /** Print error message according to error code. 119 * 120 * @param rc Return code returned by elf_load(). 121 * 122 * @return NULL terminated description of error. 123 * 124 */ 125 const char *elf_error(unsigned int rc) 126 { 127 assert(rc < sizeof(error_codes) / sizeof(char *)); 128 129 return error_codes[rc]; 106 return EOK; 130 107 } 131 108 … … 136 113 * @param as Address space into wich the ELF is being loaded. 137 114 * 138 * @return E E_OK on success, error code otherwise.115 * @return EOK on success, error code otherwise. 139 116 * 140 117 */ 141 int load_segment(elf_segment_header_t *entry, elf_header_t *elf, as_t *as)118 errno_t load_segment(elf_segment_header_t *entry, elf_header_t *elf, as_t *as) 142 119 { 143 120 mem_backend_data_t backend_data; … … 146 123 if ((entry->p_offset % entry->p_align) != 147 124 (entry->p_vaddr % entry->p_align)) 148 return E E_INVALID;125 return EINVAL; 149 126 } 150 127 … … 177 154 AS_AREA_ATTR_NONE, &elf_backend, &backend_data, &base, 0); 178 155 if (!area) 179 return E E_MEMORY;156 return ENOMEM; 180 157 181 158 /* … … 184 161 */ 185 162 186 return E E_OK;163 return EOK; 187 164 } 188 165 -
kernel/generic/src/lib/str.c
r9259d20 r3e828ea 789 789 str_ncpy(dest, size + 1, src, size); 790 790 return dest; 791 }792 793 /** Convert string to uint64_t (internal variant).794 *795 * @param nptr Pointer to string.796 * @param endptr Pointer to the first invalid character is stored here.797 * @param base Zero or number between 2 and 36 inclusive.798 * @param neg Indication of unary minus is stored here.799 * @apram result Result of the conversion.800 *801 * @return EOK if conversion was successful.802 *803 */804 static errno_t str_uint(const char *nptr, char **endptr, unsigned int base,805 bool *neg, uint64_t *result)806 {807 assert(endptr != NULL);808 assert(neg != NULL);809 assert(result != NULL);810 811 *neg = false;812 const char *str = nptr;813 814 /* Ignore leading whitespace */815 while (isspace(*str))816 str++;817 818 if (*str == '-') {819 *neg = true;820 str++;821 } else if (*str == '+')822 str++;823 824 if (base == 0) {825 /* Decode base if not specified */826 base = 10;827 828 if (*str == '0') {829 base = 8;830 str++;831 832 switch (*str) {833 case 'b':834 case 'B':835 base = 2;836 str++;837 break;838 case 'o':839 case 'O':840 base = 8;841 str++;842 break;843 case 'd':844 case 'D':845 case 't':846 case 'T':847 base = 10;848 str++;849 break;850 case 'x':851 case 'X':852 base = 16;853 str++;854 break;855 default:856 str--;857 }858 }859 } else {860 /* Check base range */861 if ((base < 2) || (base > 36)) {862 *endptr = (char *) str;863 return EINVAL;864 }865 }866 867 *result = 0;868 const char *startstr = str;869 870 while (*str != 0) {871 unsigned int digit;872 873 if ((*str >= 'a') && (*str <= 'z'))874 digit = *str - 'a' + 10;875 else if ((*str >= 'A') && (*str <= 'Z'))876 digit = *str - 'A' + 10;877 else if ((*str >= '0') && (*str <= '9'))878 digit = *str - '0';879 else880 break;881 882 if (digit >= base)883 break;884 885 uint64_t prev = *result;886 *result = (*result) * base + digit;887 888 if (*result < prev) {889 /* Overflow */890 *endptr = (char *) str;891 return EOVERFLOW;892 }893 894 str++;895 }896 897 if (str == startstr) {898 /*899 * No digits were decoded => first invalid character is900 * the first character of the string.901 */902 str = nptr;903 }904 905 *endptr = (char *) str;906 907 if (str == nptr)908 return EINVAL;909 910 return EOK;911 }912 913 /** Convert string to uint64_t.914 *915 * @param nptr Pointer to string.916 * @param endptr If not NULL, pointer to the first invalid character917 * is stored here.918 * @param base Zero or number between 2 and 36 inclusive.919 * @param strict Do not allow any trailing characters.920 * @param result Result of the conversion.921 *922 * @return EOK if conversion was successful.923 *924 */925 errno_t str_uint64_t(const char *nptr, char **endptr, unsigned int base,926 bool strict, uint64_t *result)927 {928 assert(result != NULL);929 930 bool neg;931 char *lendptr;932 errno_t ret = str_uint(nptr, &lendptr, base, &neg, result);933 934 if (endptr != NULL)935 *endptr = (char *) lendptr;936 937 if (ret != EOK)938 return ret;939 940 /* Do not allow negative values */941 if (neg)942 return EINVAL;943 944 /*945 * Check whether we are at the end of946 * the string in strict mode947 */948 if ((strict) && (*lendptr != 0))949 return EINVAL;950 951 return EOK;952 791 } 953 792
Note:
See TracChangeset
for help on using the changeset viewer.
