mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
- In GCC 4.2 __builtin_frame_address() was fixed to include the
V9 stack bias so we no longer need to add it in db_backtrace() and stack_capture() respectively. This also reverts r182018, which kludged around the resulting unaligned access. - Sync the sun4v versions of db_trace.c and stack_machdep.c with the sparc64 ones and fix some style bugs. MFC after: 3 days
This commit is contained in:
parent
f3dcc5387b
commit
c2526b097f
@ -276,10 +276,9 @@ db_backtrace(struct thread *td, struct frame *fp, int count)
|
|||||||
void
|
void
|
||||||
db_trace_self(void)
|
db_trace_self(void)
|
||||||
{
|
{
|
||||||
db_expr_t addr;
|
|
||||||
|
|
||||||
addr = (db_expr_t)__builtin_frame_address(1);
|
db_backtrace(curthread,
|
||||||
db_backtrace(curthread, (struct frame *)(addr + SPOFF), -1);
|
(struct frame *)__builtin_frame_address(1), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -288,5 +287,6 @@ db_trace_thread(struct thread *td, int count)
|
|||||||
struct pcb *ctx;
|
struct pcb *ctx;
|
||||||
|
|
||||||
ctx = kdb_thr_ctx(td);
|
ctx = kdb_thr_ctx(td);
|
||||||
return (db_backtrace(td, (struct frame*)(ctx->pcb_sp + SPOFF), count));
|
return (db_backtrace(td,
|
||||||
|
(struct frame *)(ctx->pcb_sp + SPOFF), count));
|
||||||
}
|
}
|
||||||
|
@ -28,31 +28,24 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/endian.h>
|
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/stack.h>
|
#include <sys/stack.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
|
|
||||||
#include <vm/vm.h>
|
|
||||||
#include <vm/vm_page.h>
|
|
||||||
#include <vm/vm_map.h>
|
|
||||||
|
|
||||||
#include <machine/cpu.h>
|
|
||||||
#include <machine/pcb.h>
|
#include <machine/pcb.h>
|
||||||
#include <machine/stack.h>
|
#include <machine/stack.h>
|
||||||
#include <machine/trap.h>
|
|
||||||
#include <machine/vmparam.h>
|
#include <machine/vmparam.h>
|
||||||
|
|
||||||
|
static void stack_capture(struct stack *st, struct frame *fp);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stack_capture(struct stack *st, uint64_t addr)
|
stack_capture(struct stack *st, struct frame *fp)
|
||||||
{
|
{
|
||||||
vm_offset_t callpc;
|
vm_offset_t callpc;
|
||||||
|
|
||||||
stack_zero(st);
|
stack_zero(st);
|
||||||
while (1) {
|
while (1) {
|
||||||
addr += SPOFF;
|
callpc = fp->fr_pc;
|
||||||
callpc =
|
|
||||||
be64dec((void *)(addr + offsetof(struct frame, fr_pc)));
|
|
||||||
if (!INKERNEL(callpc))
|
if (!INKERNEL(callpc))
|
||||||
break;
|
break;
|
||||||
/* Don't bother traversing trap frames. */
|
/* Don't bother traversing trap frames. */
|
||||||
@ -63,30 +56,25 @@ stack_capture(struct stack *st, uint64_t addr)
|
|||||||
break;
|
break;
|
||||||
if (stack_put(st, callpc) == -1)
|
if (stack_put(st, callpc) == -1)
|
||||||
break;
|
break;
|
||||||
addr =
|
fp = v9next_frame(fp);
|
||||||
be64dec((void *)(addr + offsetof(struct frame, fr_fp)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stack_save_td(struct stack *st, struct thread *td)
|
stack_save_td(struct stack *st, struct thread *td)
|
||||||
{
|
{
|
||||||
uint64_t addr;
|
|
||||||
|
|
||||||
if (TD_IS_SWAPPED(td))
|
if (TD_IS_SWAPPED(td))
|
||||||
panic("stack_save_td: swapped");
|
panic("stack_save_td: swapped");
|
||||||
if (TD_IS_RUNNING(td))
|
if (TD_IS_RUNNING(td))
|
||||||
panic("stack_save_td: running");
|
panic("stack_save_td: running");
|
||||||
|
|
||||||
addr = td->td_pcb->pcb_sp;
|
stack_capture(st, (struct frame *)(td->td_pcb->pcb_sp + SPOFF));
|
||||||
stack_capture(st, addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stack_save(struct stack *st)
|
stack_save(struct stack *st)
|
||||||
{
|
{
|
||||||
uint64_t addr;
|
|
||||||
|
|
||||||
addr = (uint64_t)__builtin_frame_address(1);
|
stack_capture(st, (struct frame *)__builtin_frame_address(1));
|
||||||
stack_capture(st, addr);
|
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
|
||||||
* $FreeBSD$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/kdb.h>
|
#include <sys/kdb.h>
|
||||||
@ -241,7 +242,6 @@ db_backtrace(struct thread *td, struct frame *fp, int count)
|
|||||||
db_addr_t pc;
|
db_addr_t pc;
|
||||||
int trap;
|
int trap;
|
||||||
int user;
|
int user;
|
||||||
int quit;
|
|
||||||
|
|
||||||
if (count == -1)
|
if (count == -1)
|
||||||
count = 1024;
|
count = 1024;
|
||||||
@ -249,7 +249,6 @@ db_backtrace(struct thread *td, struct frame *fp, int count)
|
|||||||
trap = 0;
|
trap = 0;
|
||||||
user = 0;
|
user = 0;
|
||||||
npc = 0;
|
npc = 0;
|
||||||
quit = 0;
|
|
||||||
while (count-- && !user && !db_pager_quit) {
|
while (count-- && !user && !db_pager_quit) {
|
||||||
pc = (db_addr_t)db_get_value((db_addr_t)&fp->fr_pc,
|
pc = (db_addr_t)db_get_value((db_addr_t)&fp->fr_pc,
|
||||||
sizeof(fp->fr_pc), FALSE);
|
sizeof(fp->fr_pc), FALSE);
|
||||||
@ -288,10 +287,9 @@ db_backtrace(struct thread *td, struct frame *fp, int count)
|
|||||||
void
|
void
|
||||||
db_trace_self(void)
|
db_trace_self(void)
|
||||||
{
|
{
|
||||||
db_expr_t addr;
|
|
||||||
|
|
||||||
addr = (db_expr_t)__builtin_frame_address(1);
|
db_backtrace(curthread,
|
||||||
db_backtrace(curthread, (struct frame *)(addr + SPOFF), -1);
|
(struct frame *)__builtin_frame_address(1), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -300,5 +298,6 @@ db_trace_thread(struct thread *td, int count)
|
|||||||
struct pcb *ctx;
|
struct pcb *ctx;
|
||||||
|
|
||||||
ctx = kdb_thr_ctx(td);
|
ctx = kdb_thr_ctx(td);
|
||||||
return (db_backtrace(td, (struct frame*)(ctx->pcb_sp + SPOFF), count));
|
return (db_backtrace(td,
|
||||||
|
(struct frame *)(ctx->pcb_sp + SPOFF), count));
|
||||||
}
|
}
|
||||||
|
@ -32,54 +32,43 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/stack.h>
|
#include <sys/stack.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
|
|
||||||
#include <vm/vm.h>
|
|
||||||
#include <vm/vm_page.h>
|
|
||||||
#include <vm/vm_map.h>
|
|
||||||
|
|
||||||
#include <machine/cpu.h>
|
|
||||||
#include <machine/pcb.h>
|
#include <machine/pcb.h>
|
||||||
#include <machine/stack.h>
|
#include <machine/stack.h>
|
||||||
#include <machine/trap.h>
|
|
||||||
#include <machine/vmparam.h>
|
#include <machine/vmparam.h>
|
||||||
|
|
||||||
|
static void stack_capture(struct stack *st, struct frame *fp);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stack_capture(struct stack *st, uint64_t addr)
|
stack_capture(struct stack *st, struct frame *fp)
|
||||||
{
|
{
|
||||||
struct frame *fp;
|
|
||||||
vm_offset_t callpc;
|
vm_offset_t callpc;
|
||||||
|
|
||||||
stack_zero(st);
|
stack_zero(st);
|
||||||
fp = (struct frame *)(addr + SPOFF);
|
|
||||||
while (1) {
|
while (1) {
|
||||||
callpc = fp->fr_pc;
|
callpc = fp->fr_pc;
|
||||||
if (!INKERNEL(callpc))
|
if (!INKERNEL(callpc))
|
||||||
break;
|
break;
|
||||||
if (stack_put(st, callpc) == -1)
|
if (stack_put(st, callpc) == -1)
|
||||||
break;
|
break;
|
||||||
fp = (struct frame *)(fp->fr_fp + SPOFF);
|
fp = v9next_frame(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stack_save_td(struct stack *st, struct thread *td)
|
stack_save_td(struct stack *st, struct thread *td)
|
||||||
{
|
{
|
||||||
uint64_t addr;
|
|
||||||
|
|
||||||
if (TD_IS_SWAPPED(td))
|
if (TD_IS_SWAPPED(td))
|
||||||
panic("stack_save_td: swapped");
|
panic("stack_save_td: swapped");
|
||||||
if (TD_IS_RUNNING(td))
|
if (TD_IS_RUNNING(td))
|
||||||
panic("stack_save_td: running");
|
panic("stack_save_td: running");
|
||||||
|
|
||||||
addr = td->td_pcb->pcb_sp;
|
stack_capture(st, (struct frame *)(td->td_pcb->pcb_sp + SPOFF));
|
||||||
stack_capture(st, addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stack_save(struct stack *st)
|
stack_save(struct stack *st)
|
||||||
{
|
{
|
||||||
uint64_t addr;
|
|
||||||
|
|
||||||
addr = (uint64_t)__builtin_frame_address(1);
|
stack_capture(st, (struct frame *)__builtin_frame_address(1));
|
||||||
stack_capture(st, addr);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user