zdump: introduce ELF_NOTE_ROUNDUP macro

Introduce and use `ELF_NOTE_ROUNDUP` macro.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2022-09-07 12:42:21 +02:00
committed by Jan Höppner
parent da9b96fb12
commit 39b6c4a273
3 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -57,10 +57,10 @@ void *nt_init(void *buf, Elf64_Word type, const void *desc, int d_len,
len = sizeof(Elf64_Nhdr);
memcpy(buf + len, name, note->n_namesz);
len = ROUNDUP(len + note->n_namesz, 4);
len = ELF_NOTE_ROUNDUP(len + note->n_namesz);
memcpy(buf + len, desc, note->n_descsz);
len = ROUNDUP(len + note->n_descsz, 4);
len = ELF_NOTE_ROUNDUP(len + note->n_descsz);
return PTR_ADD(buf, len);
}
+2
View File
@@ -69,6 +69,8 @@
#define NT_S390_VXRS_HIGH 0x30a
#endif
#define ELF_NOTE_ROUNDUP(size) ROUNDUP(size, 4)
/*
* prstatus ELF Note
*/
+3 -4
View File
@@ -87,13 +87,13 @@ static int nt_read(const Elf64_Nhdr *note, void *buf, size_t buf_len)
if (note->n_descsz < buf_len)
return -EINVAL;
/* Skip note's name and position file at note's descriptor */
zg_seek_cur(g.fh, ROUNDUP(note->n_namesz, 4), ZG_CHECK);
zg_seek_cur(g.fh, ELF_NOTE_ROUNDUP(note->n_namesz), ZG_CHECK);
/* Read note's descriptor */
nread = zg_read(g.fh, buf, buf_len, ZG_CHECK_ERR);
if (nread < 0 || (size_t)nread != buf_len)
return -EINVAL;
/* Skip the rest of note's descriptor until the next note */
zg_seek_cur(g.fh, ROUNDUP(note->n_descsz, 4) - buf_len, ZG_CHECK);
zg_seek_cur(g.fh, ELF_NOTE_ROUNDUP(note->n_descsz) - buf_len, ZG_CHECK);
return 0;
}
@@ -103,8 +103,7 @@ static int nt_read(const Elf64_Nhdr *note, void *buf, size_t buf_len)
static void nt_skip(const Elf64_Nhdr *note)
{
/* Skip note's name + descriptor and position file at the next note */
zg_seek_cur(g.fh,
ROUNDUP(note->n_namesz, 4) + ROUNDUP(note->n_descsz, 4),
zg_seek_cur(g.fh, ELF_NOTE_ROUNDUP(note->n_namesz) + ELF_NOTE_ROUNDUP(note->n_descsz),
ZG_CHECK);
}