Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce compile-time warnings on FreeBSD/x86_64 #541

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tdep-x86_64/libunwind_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ extern void tdep_fetch_frame (struct dwarf_cursor *c, unw_word_t ip,
extern int tdep_cache_frame (struct dwarf_cursor *c);
extern void tdep_reuse_frame (struct dwarf_cursor *c,
int frame);
#endif
extern void tdep_stash_frame (struct dwarf_cursor *c,
struct dwarf_reg_state *rs);
#endif

extern int tdep_getcontext_trace (unw_tdep_context_t *);
extern int tdep_trace (unw_cursor_t *cursor, void **addresses, int *n);
Expand Down
40 changes: 39 additions & 1 deletion src/ptrace/_UPT_access_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}
#elif HAVE_DECL_PT_GETREGS
#elif defined(HAVE_DECL_PT_GETREGS) && defined(__linux__)
# include <sys/user.h>

int
Expand Down Expand Up @@ -359,6 +359,44 @@ _UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}

#elif defined(HAVE_DECL_PT_GETREGS) && defined(__FreeBSD__)
int
_UPT_access_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val,
int write, void *arg)
{
struct UPT_info *ui = arg;
pid_t pid = ui->pid;
gregset_t regs;
char *r;

#if UNW_DEBUG
Debug(16, "using getregs: reg: %s [%u], val: %lx, write: %u\n", unw_regname(reg), (unsigned) reg, (long) val, write);

if (write)
Debug (16, "%s [%u] <- %lx\n", unw_regname (reg), (unsigned) reg, (long) *val);
#endif

if ((unsigned) reg >= ARRAY_SIZE (_UPT_reg_offset))
{
errno = EINVAL;
goto badreg;
}
r = (char *)&regs + _UPT_reg_offset[reg];
if (ptrace(PT_GETREGS, pid, (caddr_t)&regs, 0) == -1)
goto badreg;
if (write) {
memcpy(r, val, sizeof(unw_word_t));
if (ptrace(PT_SETREGS, pid, (caddr_t)&regs, 0) == -1)
goto badreg;
} else
memcpy(val, r, sizeof(unw_word_t));
return 0;

badreg:
Debug (1, "bad register %s [%u] (error: %s)\n", unw_regname(reg), reg, strerror (errno));
return -UNW_EBADREG;
}
#else
#error Port me
#endif
10 changes: 9 additions & 1 deletion src/x86_64/Ginit.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ static int msync_validate (unw_word_t addr, size_t len)
#ifdef HAVE_MINCORE
static int mincore_validate (unw_word_t addr, size_t len)
{
#ifdef __FreeBSD__
char mvec[2];
#else
unsigned char mvec[2]; /* Unaligned access may cross page boundary */
#endif

/* mincore could fail with EAGAIN but we conservatively return -1
instead of looping. */
Expand Down Expand Up @@ -213,9 +217,13 @@ tdep_init_mem_validate (void)
unsigned char present = 1;
size_t len = unw_page_size;
unw_word_t addr = unw_page_start((unw_word_t)&present);
#ifdef __FreeBSD__
char mvec[2];
#else
unsigned char mvec[1];
#endif
int ret;
while ((ret = mincore ((void*)addr, len, (unsigned char *)mvec)) == -1 &&
while ((ret = mincore ((void*)addr, len, mvec)) == -1 &&
errno == EAGAIN) {}
if (ret == 0)
{
Expand Down
Loading