Hi Serhei,
On Tue, Mar 24, 2026 at 6:37 PM Serhei Makarov <[email protected]> wrote:
>
> These should have been size_t all along, matching the public
> libdwfl_stacktrace dwflst_sample_getframes interface. Fix.
>
> * backends/aarch64_initreg_sample.c (aarch64_sample_sp_pc): Fixup
> argument type for n_regs_mapping.
> * backends/i386_initreg_sample.c (i386_sample_sp_pc): Fixup argument
> type for n_regs_mapping.
> * backends/libebl_PERF_FLAGS.h (generic_sample_sp_pc): Fixup argument
> type for n_regs_mapping, adjust loop index var accordingly.
> * backends/x86_64_initreg_sample.c (x86_64_sample_sp_pc): Fixup
> argument type for n_regs_mapping.
> * libebl/ebl-hooks.h (sample_sp_pc): Fixup argument type for
> n_regs_mapping.
> ---
> backends/aarch64_initreg_sample.c | 2 +-
> backends/i386_initreg_sample.c | 2 +-
> backends/libebl_PERF_FLAGS.h | 6 +++---
> backends/x86_64_initreg_sample.c | 2 +-
> libebl/ebl-hooks.h | 2 +-
> 5 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/backends/aarch64_initreg_sample.c
> b/backends/aarch64_initreg_sample.c
> index 1ea17324..b6820cde 100644
> --- a/backends/aarch64_initreg_sample.c
> +++ b/backends/aarch64_initreg_sample.c
> @@ -41,7 +41,7 @@
>
> bool
> aarch64_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
> - const int *regs_mapping, uint32_t n_regs_mapping,
> + const int *regs_mapping, size_t n_regs_mapping,
> Dwarf_Word *sp, Dwarf_Word *pc)
> {
> return generic_sample_sp_pc (regs, n_regs, regs_mapping, n_regs_mapping,
> diff --git a/backends/i386_initreg_sample.c b/backends/i386_initreg_sample.c
> index ae3ab11e..1e194146 100644
> --- a/backends/i386_initreg_sample.c
> +++ b/backends/i386_initreg_sample.c
> @@ -47,7 +47,7 @@
>
> bool
> i386_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
> - const int *regs_mapping, uint32_t n_regs_mapping,
> + const int *regs_mapping, size_t n_regs_mapping,
> Dwarf_Word *sp, Dwarf_Word *pc)
> {
> /* XXX for dwarf_regs indices, compare i386_initreg.c */
> diff --git a/backends/libebl_PERF_FLAGS.h b/backends/libebl_PERF_FLAGS.h
> index 54eb38a9..986e3f16 100644
> --- a/backends/libebl_PERF_FLAGS.h
> +++ b/backends/libebl_PERF_FLAGS.h
> @@ -75,7 +75,7 @@
>
> static inline bool
> generic_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
> - const int *regs_mapping, uint32_t n_regs_mapping,
> + const int *regs_mapping, size_t n_regs_mapping,
> Dwarf_Word *sp, uint sp_index /* into dwarf_regs */,
> Dwarf_Word *pc, uint pc_index /* into dwarf_regs */)
> {
> @@ -84,8 +84,8 @@ generic_sample_sp_pc (const Dwarf_Word *regs, uint32_t
> n_regs,
> /* TODO: Register locations could be cached and rechecked on a
> fastpath without needing to loop, though the overhead reduction
> is minimal. */
> - int j, need_sp = (sp != NULL), need_pc = (pc != NULL);
> - for (j = 0; (need_sp || need_pc) && n_regs_mapping > (uint32_t)j; j++)
> + int need_sp = (sp != NULL), need_pc = (pc != NULL);
> + for (size_t j = 0; (need_sp || need_pc) && n_regs_mapping > j; j++)
> {
> if (n_regs < (uint32_t)j) break;
This cast will truncate j when size_t is uint64_t, although having
more than 2^32 registers is unlikely.
Aaron
> if (need_sp && regs_mapping[j] == (int)sp_index)
> diff --git a/backends/x86_64_initreg_sample.c
> b/backends/x86_64_initreg_sample.c
> index 83966ff9..48a365f5 100644
> --- a/backends/x86_64_initreg_sample.c
> +++ b/backends/x86_64_initreg_sample.c
> @@ -47,7 +47,7 @@
>
> bool
> x86_64_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
> - const int *regs_mapping, uint32_t n_regs_mapping,
> + const int *regs_mapping, size_t n_regs_mapping,
> Dwarf_Word *sp, Dwarf_Word *pc)
> {
> /* XXX for dwarf_regs indices, compare x86_64_initreg.c */
> diff --git a/libebl/ebl-hooks.h b/libebl/ebl-hooks.h
> index 29ce9649..054284d8 100644
> --- a/libebl/ebl-hooks.h
> +++ b/libebl/ebl-hooks.h
> @@ -172,7 +172,7 @@ bool EBLHOOK(set_initial_registers_sample) (const
> Dwarf_Word *regs,
> /* Extract the stack address and instruction pointer from a register sample.
> */
> bool EBLHOOK(sample_sp_pc) (const Dwarf_Word *regs, uint32_t n_regs,
> const int *regs_mapping,
> - uint32_t n_regs_mapping,
> + size_t n_regs_mapping,
> Dwarf_Word *sp, Dwarf_Word *pc);
>
> /* Translate from linux perf_events PERF_REGS_MASK and ABI to a generic
> --
> 2.53.0
>