Lines Matching +full:src +full:- +full:2

1 /*-
2 * Copyright (c) 2006-2011 Joseph Koshy
10 * 2. Redistributions in binary form must reproduce the above copyright
33 ELFTC_VCSID("$Id: libelf_convert.m4 3712 2019-03-16 22:23:34Z jkoshy $");
37 divert(-1)
39 # Generate conversion routines for converting between in-memory and
53 # 2. Whether the type has word size dependent variants. For example,
56 # can be 32- or 64- bit wide.
69 # `In-memory' representations of an Elf data structure use natural
73 # tighter than its `in-memory' representation, and could be of a
87 # NOCVT(TYPE) -- Do not generate the cvt[] structure entry for TYPE
90 # NOFUNC(TYPE) -- Do not generate a conversion function for TYPE
93 # IGNORE(TYPE) -- Completely ignore the type.
98 # Types for which we use functions with non-standard names.
102 # Types for which we supply hand-coded functions.
110 # ELF types that don't exist in a 32-bit world.
129 # Note the primitive types that are size-dependent.
137 # `$2': C structure name suffix.
144 _libelf_cvt_$1$4_tof(unsigned char *dst, size_t dsz, unsigned char *src,
147 Elf$3_$2 t, *s = (Elf$3_$2 *) (uintptr_t) src;
153 (void) memcpy(dst, src, count * sizeof(*s));
167 _libelf_cvt_$1$4_tom(unsigned char *dst, size_t dsz, unsigned char *src,
170 Elf$3_$2 t, *d = (Elf$3_$2 *) (uintptr_t) dst;
173 if (dsz < count * sizeof(Elf$3_$2))
177 (void) memcpy(dst, src, count * sizeof(*d));
182 READ_$1$4(src,t);
195 # SWAP_FIELD(FIELDNAME,ELFTYPE) -- Generate code to swap one field.
197 `ifdef(`SIZEDEP_'$2,
198 `SWAP_$2'SZ()`(t.$1);
200 `SWAP_$2(t.$1);
203 # SWAP_MEMBERS(STRUCT) -- Iterate over a structure definition.
208 # SWAP_STRUCT(CTYPE,SIZE) -- Generate code to swap an ELF structure.
210 `pushdef(`SZ',$2)/* Swap an Elf$2_$1 */
211 SWAP_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
213 # WRITE_FIELD(ELFTYPE,FIELDNAME) -- Generate code to write one field.
215 `ifdef(`SIZEDEP_'$2,
216 `WRITE_$2'SZ()`(dst,t.$1);
218 `WRITE_$2(dst,t.$1);
221 # WRITE_MEMBERS(ELFTYPELIST) -- Iterate over a structure definition.
226 # WRITE_STRUCT(CTYPE,SIZE) -- Generate code to write out an ELF structure.
228 `pushdef(`SZ',$2)/* Write an Elf$2_$1 */
229 WRITE_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
231 # READ_FIELD(ELFTYPE,CTYPE) -- Generate code to read one field.
233 `ifdef(`SIZEDEP_'$2,
234 `READ_$2'SZ()`(s,t.$1);
236 `READ_$2(s,t.$1);
239 # READ_MEMBERS(ELFTYPELIST) -- Iterate over a structure definition.
244 # READ_STRUCT(CTYPE,SIZE) -- Generate code to read an ELF structure.
246 `pushdef(`SZ',$2)/* Read an Elf$2_$1 */
247 READ_MEMBERS(Elf$2_$1_DEF)popdef(`SZ')')
250 # MAKECOMPFUNCS -- Generate converters for composite ELF structures.
253 # be naturally aligned for a data structure's in-memory
257 # For in-place conversions, when converting to file representations,
264 # `$2': C structure name suffix.
268 _libelf_cvt_$1$3_tof(unsigned char *dst, size_t dsz, unsigned char *src,
271 Elf$3_$2 t, *s;
276 s = (Elf$3_$2 *) (uintptr_t) src;
280 SWAP_STRUCT($2,$3)
282 WRITE_STRUCT($2,$3)
289 _libelf_cvt_$1$3_tom(unsigned char *dst, size_t dsz, unsigned char *src,
292 Elf$3_$2 t, *d;
297 d = ((Elf$3_$2 *) (uintptr_t) dst) + (count - 1);
298 s0 = src + (count - 1) * fsz;
300 if (dsz < count * sizeof(Elf$3_$2))
303 while (count--) {
305 READ_STRUCT($2,$3)
307 SWAP_STRUCT($2,$3)
309 *d-- = t; s0 -= fsz;
320 # - Skip convertors marked as `NOFUNC'.
321 # - Invoke `MAKEPRIMFUNCS' or `MAKECOMPFUNCS' as appropriate.
326 `MAKEPRIMFUNCS($1,$2,32,32)dnl
327 MAKEPRIMFUNCS($1,$2,64,64)',
328 `MAKEPRIMFUNCS($1,$2,64)')',
329 `MAKECOMPFUNCS($1,$2,32)dnl
330 MAKECOMPFUNCS($1,$2,64)')')')
332 # MAKE_TYPE_CONVERTERS(ELFTYPELIST) -- Generate conversion functions.
346 `ifdef(`NOFUNC_'$1$2,
347 `.$3$2 = NULL',
350 `.$3$2 = _libelf_cvt_$1$2_$3',
351 `.$3$2 = _libelf_cvt_$1_$3')',
352 `.$3$2 = _libelf_cvt_$1$2_$3')')')
379 # _FSZ(FIELD,BASETYPE) - return the file size for a field.
381 `ifelse($2,`HALF',2,
382 $2,`WORD',4)')
384 # FSZ(STRUCT) - determine the file size of a structure.
389 # MAKE_VERSION_CONVERTERS(TYPE,BASE,AUX,PFX) -- Generate conversion
392 `MAKE_VERSION_CONVERTER($1,$2,$3,$4,32)
393 MAKE_VERSION_CONVERTER($1,$2,$3,$4,64)')
395 # MAKE_VERSION_CONVERTOR(TYPE,CBASE,CAUX,PFX,SIZE) -- Generate a
399 _libelf_cvt_$1$5_tof(unsigned char *dst, size_t dsz, unsigned char *src,
402 Elf$5_$2 t;
404 const size_t verfsz = FSZ(Elf$5_$2_DEF);
406 const size_t vermsz = sizeof(Elf$5_$2);
409 unsigned char * const srcend = src + count;
414 vnext != 0 && dtmp + verfsz <= dstend && src + vermsz <= srcend;
415 dtmp += vnext, src += vnext) {
417 /* Read in an Elf$5_$2 structure. */
418 t = *((Elf$5_$2 *) (uintptr_t) src);
425 SWAP_STRUCT($2, $5)
429 WRITE_STRUCT($2, $5)
435 for (anext = ~0U, dstaux = dtmp + aux, srcaux = src + aux;
438 dstaux += anext, srcaux += anext, cnt--) {
463 _libelf_cvt_$1$5_tom(unsigned char *dst, size_t dsz, unsigned char *src,
466 Elf$5_$2 t, *dp;
468 const size_t verfsz = FSZ(Elf$5_$2_DEF);
470 const size_t vermsz = sizeof(Elf$5_$2);
473 unsigned char * const srcend = src + count;
477 for (stmp = src, vnext = ~0U;
483 READ_STRUCT($2, $5)
485 SWAP_STRUCT($2, $5)
488 dp = (Elf$5_$2 *) (uintptr_t) dst;
502 dstaux += anext, srcaux += anext, cnt--) {
575 * - The destination pointer could be unaligned.
576 * - Values are written out in native byte order.
577 * - The destination pointer is incremented after the write.
590 (P) = _p + 2; \
598 _p[2] = _q[2]; \
611 _p[2] = _q[2]; \
633 * - The source pointer could be unaligned.
634 * - Values are read in native byte order.
635 * - The source pointer is incremented appropriately.
651 (P) = (P) + 2; \
661 _q[2] = _p[2]; \
677 _q[2] = _p[2]; \
696 #define ROUNDUP2(V,N) (V) = ((((V) + (N) - 1)) & ~((N) - 1))
710 _libelf_cvt_BYTE_tox(unsigned char *dst, size_t dsz, unsigned char *src,
716 if (dst != src)
717 (void) memcpy(dst, src, count);
722 * Sections of type ELF_T_GNUHASH start with a header containing 4 32-bit
731 * 32-bit case we need to translate `srcsz' to a count of 32-bit words.
735 _libelf_cvt_GNUHASH32_tom(unsigned char *dst, size_t dsz, unsigned char *src,
738 return (_libelf_cvt_WORD_tom(dst, dsz, src, srcsz / sizeof(uint32_t),
743 _libelf_cvt_GNUHASH32_tof(unsigned char *dst, size_t dsz, unsigned char *src,
746 return (_libelf_cvt_WORD_tof(dst, dsz, src, srcsz / sizeof(uint32_t),
751 _libelf_cvt_GNUHASH64_tom(unsigned char *dst, size_t dsz, unsigned char *src,
765 READ_WORD(src, nbuckets);
766 READ_WORD(src, symndx);
767 READ_WORD(src, maskwords);
768 READ_WORD(src, shift2);
770 srcsz -= sz;
785 gh->gh_nbuckets = nbuckets;
786 gh->gh_symndx = symndx;
787 gh->gh_maskwords = maskwords;
788 gh->gh_shift2 = shift2;
790 dsz -= sizeof(Elf_GNU_Hash_Header);
797 READ_XWORD(src, t64);
808 READ_WORD(src, t32);
817 dsz -= sz;
818 srcsz -= sz;
827 READ_WORD(src, t32);
837 _libelf_cvt_GNUHASH64_tof(unsigned char *dst, size_t dsz, unsigned char *src,
850 gh = (Elf_GNU_Hash_Header *) (uintptr_t) src;
852 t0 = nbuckets = gh->gh_nbuckets;
853 t1 = gh->gh_symndx;
854 t2 = maskwords = gh->gh_maskwords;
855 t3 = gh->gh_shift2;
857 src += sizeof(Elf_GNU_Hash_Header);
858 srcsz -= sizeof(Elf_GNU_Hash_Header);
859 dsz -= hdrsz;
861 sz = gh->gh_nbuckets * sizeof(uint32_t) + gh->gh_maskwords *
881 s64 = (uint64_t *) (uintptr_t) src;
897 srcsz -= sz;
898 dsz -= sz;
924 _libelf_cvt_NOTE_tom(unsigned char *dst, size_t dsz, unsigned char *src,
939 (void) memcpy(dst, src, count);
946 READ_WORD(src, namesz);
947 READ_WORD(src, descsz);
948 READ_WORD(src, type);
957 en->n_namesz = namesz;
958 en->n_descsz = descsz;
959 en->n_type = type;
961 dsz -= sizeof(Elf_Note);
963 count -= hdrsz;
973 (void) memcpy(dst, src, sz);
975 src += sz;
978 count -= sz;
979 dsz -= sz;
986 _libelf_cvt_NOTE_tof(unsigned char *dst, size_t dsz, unsigned char *src,
997 (void) memcpy(dst, src, count);
1003 en = (Elf_Note *) (uintptr_t) src;
1004 namesz = en->n_namesz;
1005 descsz = en->n_descsz;
1006 type = en->n_type;
1021 src += sizeof(Elf_Note);
1022 count -= sizeof(Elf_Note);
1027 (void) memcpy(dst, src, sz);
1029 src += sz;
1031 count -= sz;
1038 int (*tof32)(unsigned char *dst, size_t dsz, unsigned char *src,
1040 int (*tom32)(unsigned char *dst, size_t dsz, unsigned char *src,
1042 int (*tof64)(unsigned char *dst, size_t dsz, unsigned char *src,
1044 int (*tom64)(unsigned char *dst, size_t dsz, unsigned char *src,
1055 * Types that need hand-coded converters follow.