Fix note_syscall_leave_s to avoid unaligned access

This commit is contained in:
Nakamura, Yuuichi 2020-10-16 23:08:48 +09:00 committed by Xiang Xiao
parent 6ef47323a2
commit 007033f295
2 changed files with 61 additions and 11 deletions

View File

@ -457,6 +457,7 @@ static void dump_notes(size_t nread)
{
FAR struct note_spinlock_s *note_spinlock =
(FAR struct note_spinlock_s *)note;
FAR void *spinlock;
if (note->nc_length != sizeof(struct note_spinlock_s))
{
@ -466,6 +467,21 @@ static void dump_notes(size_t nread)
return;
}
spinlock = (FAR void *)
((uintptr_t)note_spinlock->nsp_spinlock[0]
+ ((uintptr_t)note_spinlock->nsp_spinlock[1] << 8)
#if UINTPTR_MAX > UINT16_MAX
+ ((uintptr_t)note_spinlock->nsp_spinlock[2] << 16)
+ ((uintptr_t)note_spinlock->nsp_spinlock[3] << 24)
#if UINTPTR_MAX > UINT32_MAX
+ ((uintptr_t)note_spinlock->nsp_spinlock[4] << 32)
+ ((uintptr_t)note_spinlock->nsp_spinlock[5] << 40)
+ ((uintptr_t)note_spinlock->nsp_spinlock[6] << 48)
+ ((uintptr_t)note_spinlock->nsp_spinlock[7] << 56)
#endif
#endif
);
switch (note->nc_type)
{
#ifdef CONFIG_SMP
@ -476,7 +492,7 @@ static void dump_notes(size_t nread)
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
(unsigned int)note->nc_cpu,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -489,7 +505,7 @@ static void dump_notes(size_t nread)
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
(unsigned int)note->nc_cpu,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -502,7 +518,7 @@ static void dump_notes(size_t nread)
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
(unsigned int)note->nc_cpu,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -515,7 +531,7 @@ static void dump_notes(size_t nread)
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
(unsigned int)note->nc_cpu,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -527,7 +543,7 @@ static void dump_notes(size_t nread)
"%08lx: Task %u wait for spinlock=%p value=%u "
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -538,7 +554,7 @@ static void dump_notes(size_t nread)
syslog(LOG_INFO,
"%08lx: Task %u has spinlock=%p value=%u priority %u\n",
(unsigned long)systime, (unsigned int)pid,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -550,7 +566,7 @@ static void dump_notes(size_t nread)
"%08lx: Task %u unlocking spinlock=%p value=%u "
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
(unsigned int)note->nc_cpu,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
@ -562,13 +578,15 @@ static void dump_notes(size_t nread)
"%08lx: Task %u abort wait on spinlock=%p value=%u "
"priority %u\n",
(unsigned long)systime, (unsigned int)pid,
note_spinlock->nsp_spinlock,
spinlock,
(unsigned int)note_spinlock->nsp_value,
(unsigned int)note->nc_priority);
}
break;
#endif
}
break;
}
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
@ -596,6 +614,7 @@ static void dump_notes(size_t nread)
{
FAR struct note_syscall_leave_s *note_sysleave =
(FAR struct note_syscall_leave_s *)note;
uintptr_t result;
if (note->nc_length != sizeof(struct note_syscall_leave_s))
{
@ -605,10 +624,24 @@ static void dump_notes(size_t nread)
return;
}
result = (uintptr_t)note_sysleave->nsc_result[0]
+ ((uintptr_t)note_sysleave->nsc_result[1] << 8)
#if UINTPTR_MAX > UINT16_MAX
+ ((uintptr_t)note_sysleave->nsc_result[2] << 16)
+ ((uintptr_t)note_sysleave->nsc_result[3] << 24)
#if UINTPTR_MAX > UINT32_MAX
+ ((uintptr_t)note_sysleave->nsc_result[4] << 32)
+ ((uintptr_t)note_sysleave->nsc_result[5] << 40)
+ ((uintptr_t)note_sysleave->nsc_result[6] << 48)
+ ((uintptr_t)note_sysleave->nsc_result[7] << 56)
#endif
#endif
;
syslog(LOG_INFO,
"%08lx: Task %u Leave SYSCALL %d: %" PRIdPTR "\n",
(unsigned long)systime, (unsigned int)pid,
note_sysleave->nsc_nr, note_sysleave->nsc_result);
note_sysleave->nsc_nr, result);
}
break;
#endif

View File

@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@ -459,6 +460,7 @@ static int trace_dump_one(FAR FILE *out,
{
FAR struct note_syscall_leave_s *nsc;
FAR struct trace_dump_task_context_s *tctx;
uintptr_t result;
/* Exclude the case of syscall issued by an interrupt handler and
* nested syscalls to correct tracecompass display.
@ -491,9 +493,24 @@ static int trace_dump_one(FAR FILE *out,
}
trace_dump_header(out, note, ctx);
fprintf(out, "sys_%s -> 0x%x\n",
result = (uintptr_t)nsc->nsc_result[0]
+ ((uintptr_t)nsc->nsc_result[1] << 8)
#if UINTPTR_MAX > UINT16_MAX
+ ((uintptr_t)nsc->nsc_result[2] << 16)
+ ((uintptr_t)nsc->nsc_result[3] << 24)
#if UINTPTR_MAX > UINT32_MAX
+ ((uintptr_t)nsc->nsc_result[4] << 32)
+ ((uintptr_t)nsc->nsc_result[5] << 40)
+ ((uintptr_t)nsc->nsc_result[6] << 48)
+ ((uintptr_t)nsc->nsc_result[7] << 56)
#endif
#endif
;
fprintf(out, "sys_%s -> 0x%" PRIxPTR "\n",
g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED],
nsc->nsc_result);
result);
}
break;
#endif