| 1134 | on error. */ |
| 1135 | |
| 1136 | static int |
| 1137 | elf_fetch_bits (const unsigned char **ppin, const unsigned char *pinend, |
| 1138 | uint64_t *pval, unsigned int *pbits) |
| 1139 | { |
| 1140 | unsigned int bits; |
| 1141 | const unsigned char *pin; |
| 1142 | uint64_t val; |
| 1143 | uint32_t next; |
| 1144 | |
| 1145 | bits = *pbits; |
| 1146 | if (bits >= 15) |
| 1147 | return 1; |
| 1148 | pin = *ppin; |
| 1149 | val = *pval; |
| 1150 | |
| 1151 | if (unlikely (pinend - pin < 4)) |
| 1152 | { |
| 1153 | elf_uncompress_failed (); |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ |
| 1158 | && defined(__ORDER_BIG_ENDIAN__) \ |
| 1159 | && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \ |
| 1160 | || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
| 1161 | /* We've ensured that PIN is aligned. */ |
| 1162 | next = *(const uint32_t *)pin; |
| 1163 | |
| 1164 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 1165 | next = __builtin_bswap32 (next); |
| 1166 | #endif |
| 1167 | #else |
| 1168 | next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24); |
| 1169 | #endif |
| 1170 | |
| 1171 | val |= (uint64_t)next << bits; |
| 1172 | bits += 32; |
| 1173 | pin += 4; |
| 1174 | |
| 1175 | /* We will need the next four bytes soon. */ |
| 1176 | __builtin_prefetch (pin, 0, 0); |
| 1177 | |
| 1178 | *ppin = pin; |
| 1179 | *pval = val; |
| 1180 | *pbits = bits; |
| 1181 | return 1; |
| 1182 | } |
| 1183 | |
| 1184 | /* This is like elf_fetch_bits, but it fetchs the bits backward, and ensures at |
| 1185 | least 16 bits. This is for zstd. */ |
no test coverage detected