This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Stack access violations in eCos


Larice Robert wrote:

I'm using SH4 (SH7751).

Aha! The one we definitely identified as potentially having the problem. So it looks like we've solved this one. Phew.


calmrisc16 calmrisc32 seem to lack this alignment in HAL_THREAD_INIT_CONTEXT too.

Actually they lack HAL_THREAD_INIT_CONTEXT entirely! They're RedBoot-only ports.


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?


After this I'll check in the other parts of your patch to do with the stuff that would remain a problem.

One tiny issue then remains, the length of actual available space will be
nondeterministic. Somebody might sooner or later recompile some application,
get a different alignment of his char stack[], which will be corrected by
the macro, but the actual available stackspace might suddenly be smaller up
to 15 bytes. Of course one should have had enough headroom.

Definitely. Trying to be byte accurate with stack sizes tends to be a losing strategy.


> But suddenly
getting a stack overflow, just by recompilation, might be a somewhat
unpleasant experience.
Perhaps it would thus be reasonable to add the alignment too, just for
better design practice.

Not sure. I'm not inclined to since conversely we don't want to overalign things as that can be wasteful, but it's not a strong feeling. Unless someone else speaks up anyway?


Jifl
--
eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/sh/arch/current/ChangeLog,v
retrieving revision 1.42
diff -u -5 -p -r1.42 ChangeLog
--- ChangeLog	11 Mar 2003 17:14:15 -0000	1.42
+++ ChangeLog	3 Apr 2003 20:30:36 -0000
@@ -1,5 +1,11 @@
+2003-04-03  Jonathan Larmour  <jifl at eCosCentric dot com>
+
+	* include/hal_var_bank.h (HAL_THREAD_INIT_CONTEXT): Align stack
+	pointer before using it.
+	* include/hal_var_sp.h (HAL_THREAD_INIT_CONTEXT): Ditto.
+
 2003-03-11  Mark Salter  <msalter at redhat dot com>
 
 	* src/redboot_linux_exec.c (do_exec): Call eth_drv_stop as necessary.
 
 2003-01-31  Mark Salter  <msalter at redhat dot com>
Index: include/hal_var_bank.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/sh/arch/current/include/hal_var_bank.h,v
retrieving revision 1.2
diff -u -5 -p -r1.2 hal_var_bank.h
--- include/hal_var_bank.h	23 May 2002 23:04:37 -0000	1.2
+++ include/hal_var_bank.h	3 Apr 2003 20:30:36 -0000
@@ -86,13 +86,17 @@ typedef struct
 // _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_;                                                                  \
-    _regs_ = (HAL_SavedRegisters *)((_sparg_) - sizeof(HAL_SavedRegisters));  \
+    _sp_ = _sp_ & ~(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));     \
     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               */   \
Index: include/hal_var_sp.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/sh/arch/current/include/hal_var_sp.h,v
retrieving revision 1.2
diff -u -5 -p -r1.2 hal_var_sp.h
--- include/hal_var_sp.h	23 May 2002 23:04:38 -0000	1.2
+++ include/hal_var_sp.h	3 Apr 2003 20:30:36 -0000
@@ -91,13 +91,17 @@ typedef struct
 // _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_;                                                                  \
-    _regs_ = (HAL_SavedRegisters *)((_sparg_) - sizeof(HAL_SavedRegisters));  \
+    _sp_ = _sp_ & ~(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));     \
     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               */   \

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]