public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] getcontext() correctly implemented ?
@ 2001-09-20 17:34 stefan
  2001-09-20 18:26 ` David Mosberger
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: stefan @ 2001-09-20 17:34 UTC (permalink / raw)
  To: linux-ia64

Hello list,

in order to save the full register set of the ia64 I want to use
getcontext(&ctx) instead of setjmp(jmpbuf) and check the registers in
ctx.uc_mcontext for references in a garbage collected system.

My question is: Is getcontext() correctly implemented in glibc(). Which
version do I need and can I use it for the described purpose at all ?

Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
@ 2001-09-20 18:26 ` David Mosberger
  2001-09-20 22:09 ` stefan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: David Mosberger @ 2001-09-20 18:26 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Thu, 20 Sep 2001 19:34:00 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> Hello list, in order to save the full register set of the
  Stefan> ia64 I want to use getcontext(&ctx) instead of
  Stefan> setjmp(jmpbuf) and check the registers in ctx.uc_mcontext
  Stefan> for references in a garbage collected system.

The *context() routines are designed to support synchronous context
switches only (see glibc FAQ).  Thus, they basically save the
"preserved" state only.

  Stefan> My question is: Is getcontext() correctly implemented in
  Stefan> glibc(). Which version do I need and can I use it for the
  Stefan> described purpose at all ?

It's implemented to meet the requirements of SuS.  In that sense, it
should be correct (you'll probably need glibc 2.2.4 as there were some
silly bugs in earlier versions).

To get the full machine context, in a signal handler, you'd have to
either (a) use stack unwinding to recover the preserved state at the
point of the signal or (b) use a combination of sigcontext and
setjmp() or getcontext().  Can say a little more about what you're
trying to do?  That would make it easier to give a specific example.

To accomplish (a), we really need a user-level unwinder.  It's been on
the todo list for some time, but nobody got around to implement it, so
far.

	--david


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
  2001-09-20 18:26 ` David Mosberger
@ 2001-09-20 22:09 ` stefan
  2001-09-20 22:58 ` David Mosberger
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: stefan @ 2001-09-20 22:09 UTC (permalink / raw)
  To: linux-ia64

On Thu, 20 Sep 2001, David Mosberger wrote:

> To get the full machine context, in a signal handler, you'd have to
> either (a) use stack unwinding to recover the preserved state at the
> point of the signal or (b) use a combination of sigcontext and
> setjmp() or getcontext().  Can say a little more about what you're
> trying to do?  That would make it easier to give a specific example.
> 
> To accomplish (a), we really need a user-level unwinder.  It's been on
> the todo list for some time, but nobody got around to implement it, so
> far.

The garbage collector of GNU Guile does not need the machine context in a
signal handler. It just looks for heap references within the programs
stack. The top of the stack is saved when starting the program, the bottom
is gained from the current stack position when garbage collecting. More
references might be within the machines registers. That is why it uses
setjmp() in order to get these into a defined buffer. On a ia64 Linux
setjump() is not said to save *all* registers. That is why I thought the
getcontext() function could help here. Is that true ? I already tried it
with glibc 2.2.3 without success. Still missed some references...

Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
  2001-09-20 18:26 ` David Mosberger
  2001-09-20 22:09 ` stefan
@ 2001-09-20 22:58 ` David Mosberger
  2001-09-21  8:41 ` Andrew Haley
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: David Mosberger @ 2001-09-20 22:58 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Fri, 21 Sep 2001 00:09:11 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> The garbage collector of GNU Guile does not need the machine
  Stefan> context in a signal handler. It just looks for heap
  Stefan> references within the programs stack. The top of the stack
  Stefan> is saved when starting the program, the bottom is gained
  Stefan> from the current stack position when garbage
  Stefan> collecting. More references might be within the machines
  Stefan> registers.

You didn't mention the register backing store.  Be sure to scan that
one too!  For the main thread, libc exports a global variable which
will help you find the beginning of the backing store.  The variable
is called "__libc_ia64_register_backing_store_base".  I'm not sure
what pthreads does (Hans can you help?).  The top of the register
backing store can be obtained from the "sc_bsp" member in the ucontext
(uc->uc_mcontext.sc_bsp).

  Stefan> That is why it uses setjmp() in order to get these into a
  Stefan> defined buffer. On a ia64 Linux setjump() is not said to
  Stefan> save *all* registers. That is why I thought the getcontext()
  Stefan> function could help here. Is that true ? I already tried it
  Stefan> with glibc 2.2.3 without success. Still missed some
  Stefan> references...

Do you need *all* registers or *all live* registers?  If it's the
latter and if you're willing to make a function call to obtain this
state, then getcontext() should do all you need: the scratch state
gets killed by the call to getcontext() and hence the "preserved"
registers that it saves is really all you need.

For your particular case, setjmp() would be an option, too.  The major
difference between setjmp() and getcontext() is that the latter
flushes the register stack, whereas the former does not (but you could
do this on your own later on).  Overall, I'd still recommend using
getcontext() though.  It's a little safer for two reasons:

 (a) We go try hard to avoid changing the layout of "struct
     sigcontext" (and ucontext_t by implication).  For the
     jump-buffer, we really only try to avoid changing its size; the
     internal structure could easily change.

 (b) getcontext() is defined to be used for synchronous context
     switches, so you can be certain that it saves all "preserved"
     state.

Hope this helps.

	--david


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
                   ` (2 preceding siblings ...)
  2001-09-20 22:58 ` David Mosberger
@ 2001-09-21  8:41 ` Andrew Haley
  2001-09-21 14:11 ` stefan
  2001-09-21 21:28 ` Boehm, Hans
  5 siblings, 0 replies; 7+ messages in thread
From: Andrew Haley @ 2001-09-21  8:41 UTC (permalink / raw)
  To: linux-ia64

stefan writes:
 > 
 > The garbage collector of GNU Guile does not need the machine
 > context in a signal handler. It just looks for heap references
 > within the programs stack. The top of the stack is saved when
 > starting the program, the bottom is gained from the current stack
 > position when garbage collecting. More references might be within
 > the machines registers. That is why it uses setjmp() in order to
 > get these into a defined buffer. On a ia64 Linux setjump() is not
 > said to save *all* registers. That is why I thought the
 > getcontext() function could help here. Is that true ? I already
 > tried it with glibc 2.2.3 without success. Still missed some
 > references...

I can't help thinking you'd be best looking at Hans Boehm's garbage
collector and the way it accesses registers on IA-64.  boehm-gc is in
a subdir of the gcc soures.

Andrew.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
                   ` (3 preceding siblings ...)
  2001-09-21  8:41 ` Andrew Haley
@ 2001-09-21 14:11 ` stefan
  2001-09-21 21:28 ` Boehm, Hans
  5 siblings, 0 replies; 7+ messages in thread
From: stefan @ 2001-09-21 14:11 UTC (permalink / raw)
  To: linux-ia64

On Thu, 20 Sep 2001, David Mosberger wrote:

> You didn't mention the register backing store.  Be sure to scan that
> one too!  For the main thread, libc exports a global variable which
> will help you find the beginning of the backing store.  The variable
> is called "__libc_ia64_register_backing_store_base".  I'm not sure
> what pthreads does (Hans can you help?).  The top of the register
> backing store can be obtained from the "sc_bsp" member in the ucontext
> (uc->uc_mcontext.sc_bsp).

Wow ! This fixed this specific problem. With a little change:
uc->uc_mcontext.sc_bsp is uc->uc_mcontext.sc_ar_bsp.

Thanks a lot,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [Linux-ia64] getcontext() correctly implemented ?
  2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
                   ` (4 preceding siblings ...)
  2001-09-21 14:11 ` stefan
@ 2001-09-21 21:28 ` Boehm, Hans
  5 siblings, 0 replies; 7+ messages in thread
From: Boehm, Hans @ 2001-09-21 21:28 UTC (permalink / raw)
  To: linux-ia64

In the threads case, I intercept thread creation, and thus capture the
backing store pointer on thread startup.  For the main thread, I use the
variable if its available (glibc 2.2.4+ ?), and a rather brittle heuristic
(which happens to work on current kernels) if it's not.

Hans

> -----Original Message-----
> From: stefan [mailto:stefan@lkcc.org]
> Sent: Friday, September 21, 2001 7:12 AM
> To: David Mosberger
> Cc: linux-ia64@linuxia64.org
> Subject: Re: [Linux-ia64] getcontext() correctly implemented ?
> 
> 
> On Thu, 20 Sep 2001, David Mosberger wrote:
> 
> > You didn't mention the register backing store.  Be sure to scan that
> > one too!  For the main thread, libc exports a global variable which
> > will help you find the beginning of the backing store.  The variable
> > is called "__libc_ia64_register_backing_store_base".  I'm not sure
> > what pthreads does (Hans can you help?).  The top of the register
> > backing store can be obtained from the "sc_bsp" member in 
> the ucontext
> > (uc->uc_mcontext.sc_bsp).
> 
> Wow ! This fixed this specific problem. With a little change:
> uc->uc_mcontext.sc_bsp is uc->uc_mcontext.sc_ar_bsp.
> 
> Thanks a lot,
> 	stefan@lkcc.org
> 
> 
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-09-21 21:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-20 17:34 [Linux-ia64] getcontext() correctly implemented ? stefan
2001-09-20 18:26 ` David Mosberger
2001-09-20 22:09 ` stefan
2001-09-20 22:58 ` David Mosberger
2001-09-21  8:41 ` Andrew Haley
2001-09-21 14:11 ` stefan
2001-09-21 21:28 ` Boehm, Hans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox