xref: /aosp_15_r20/external/elfutils/libelf/chdr_xlate.h (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker #include "common.h"
2*7304104dSAndroid Build Coastguard Worker 
3*7304104dSAndroid Build Coastguard Worker /* These functions convert a while section, one Chdr plus compression data.  */
4*7304104dSAndroid Build Coastguard Worker 
5*7304104dSAndroid Build Coastguard Worker static void
Elf32_cvt_chdr(void * dest,const void * src,size_t len,int encode)6*7304104dSAndroid Build Coastguard Worker Elf32_cvt_chdr (void *dest, const void *src, size_t len, int encode)
7*7304104dSAndroid Build Coastguard Worker {
8*7304104dSAndroid Build Coastguard Worker   if (len == 0)
9*7304104dSAndroid Build Coastguard Worker     return;
10*7304104dSAndroid Build Coastguard Worker 
11*7304104dSAndroid Build Coastguard Worker   /* Move everything over, if necessary, we only need to xlate the
12*7304104dSAndroid Build Coastguard Worker      header, not the compressed data following it.  */
13*7304104dSAndroid Build Coastguard Worker   if (dest != src)
14*7304104dSAndroid Build Coastguard Worker     memmove (dest, src, len);
15*7304104dSAndroid Build Coastguard Worker 
16*7304104dSAndroid Build Coastguard Worker   if (len >= sizeof (Elf32_Chdr))
17*7304104dSAndroid Build Coastguard Worker     Elf32_cvt_Chdr (dest, src, sizeof (Elf32_Chdr), encode);
18*7304104dSAndroid Build Coastguard Worker }
19*7304104dSAndroid Build Coastguard Worker 
20*7304104dSAndroid Build Coastguard Worker static void
Elf64_cvt_chdr(void * dest,const void * src,size_t len,int encode)21*7304104dSAndroid Build Coastguard Worker Elf64_cvt_chdr (void *dest, const void *src, size_t len, int encode)
22*7304104dSAndroid Build Coastguard Worker {
23*7304104dSAndroid Build Coastguard Worker   if (len == 0)
24*7304104dSAndroid Build Coastguard Worker     return;
25*7304104dSAndroid Build Coastguard Worker 
26*7304104dSAndroid Build Coastguard Worker   /* Move everything over, if necessary, we only need to xlate the
27*7304104dSAndroid Build Coastguard Worker      header, not the compressed data following it.  */
28*7304104dSAndroid Build Coastguard Worker   if (dest != src)
29*7304104dSAndroid Build Coastguard Worker     memmove (dest, src, len);
30*7304104dSAndroid Build Coastguard Worker 
31*7304104dSAndroid Build Coastguard Worker   if (len >= sizeof (Elf64_Chdr))
32*7304104dSAndroid Build Coastguard Worker     Elf64_cvt_Chdr (dest, src, sizeof (Elf64_Chdr), encode);
33*7304104dSAndroid Build Coastguard Worker }
34