This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Stack access violations in eCos
- From: Larice Robert <larice at vidisys dot de>
- To: Jonathan Larmour <jifl at eCosCentric dot com>
- Cc: ecos-discuss at sources dot redhat dot com, ecos-patches at sources dot redhat dot com
- Date: Fri, 4 Apr 2003 10:07:52 +0200 (CEST)
- Subject: Re: [ECOS] Stack access violations in eCos
> > I agree with Bart, fixing HAL_THREAD_INIT_CONTEXT is the best way.
>
> Yep. I'll do this now, however I don't have an SH. Can you try the
> attached patch?
thanks Jifl,
your patch is applicable, and doesn't cause a crash when
cyg_thread_create() is called with a forced odd stackspace.
but why didn't you do
--- hal_var_bank.h- Fri Apr 4 09:01:23 2003
+++ hal_var_bank.h Fri Apr 4 10:00:59 2003
@@ -83,26 +83,26 @@
// Arguments:
// _sparg_ name of variable containing current sp, will be written with new sp
// _thread_ thread object address, passed as argument to entry point
// _entry_ entry point address.
// _id_ bit pattern used in initializing registers, for debugging.
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ ) \
CYG_MACRO_START \
register CYG_WORD _sp_ = (CYG_WORD)_sparg_; \
register HAL_SavedRegisters *_regs_; \
int _i_; \
- _sp_ = _sp_ & ~(CYGARC_ALIGNMENT-1); \
+ _sp_ = (_sp_ - sizeof(HAL_SavedRegisters)) & ~(CYGARC_ALIGNMENT-1); \
/* Note that _regs_ below should be aligned if HAL_SavedRegisters */ \
/* stops being aligned to CYGARC_ALIGNMENT */ \
- _regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters)); \
+ _regs_ = (HAL_SavedRegisters *) _sp_; \
for( _i_ = 0; _i_ < 16; _i_++ ) (_regs_)->r[_i_] = (_id_)|_i_; \
(_regs_)->r[15] = (CYG_WORD)(_regs_); /* SP = top of stack */ \
(_regs_)->r[04] = (CYG_WORD)(_thread_); /* R4 = arg1 = thread ptr */ \
(_regs_)->mach = 0; /* MACH = 0 */ \
(_regs_)->macl = 0; /* MACL = 0 */ \
(_regs_)->pr = (CYG_WORD)(_entry_); /* PR = entry point */ \
(_regs_)->sr = 0; /* SR = enable interrupts */ \
(_regs_)->pc = (CYG_WORD)(_entry_); /* set PC for thread dbg */ \
_sparg_ = (CYG_ADDRESS)_regs_; \
CYG_MACRO_END
(same for hal_var_sp.h)
this would gurantee _sparg_ to be where it should,
even if sizeof(HAL_SavedRegisters) is not multiple of CYGARC_ALIGNMENT,
without additional waste of space.
thanks,
Robert Larice
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss