Question about s390 THREAD_SET_STACK_GUARD

Gc Frix gfrix98@gmail.com
Fri Nov 2 22:40:00 GMT 2018


Hello,

I was looking through the s390 sources and I noticed something I don't
quite understand. From sysdeps/s390/nptl/tls.h:

```
/* Set the stack guard field in TCB head.  */
#define THREAD_SET_STACK_GUARD(value) \
  do \
   { \
     __asm__ __volatile__ ("" : : : "a0", "a1"); \
     THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
   } \
  while (0)

/* For reference, here's THREAD_SETMEM and THREAD_SELF.  */
#define THREAD_SETMEM(descr, member, value) \
  descr->member = (value)

# define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
```

I can't figure out what the point of the asm in THREAD_SET_STACK_GUARD
is. I know that for s390x, the thread pointer is split between a0 and
a1, and that __builtin_thread_pointer() is a GCC builtin that represents
them (__builtin_thread_pointer is completely undocumented for s390, by
the way). What I don't understand is why the asm is necessary at all.
The most I can figure is that it's meant to force a reload from a0 and
a1, but why? Shouldn't they only ever get modified by context switches
after they get set?

I'm new to glibc, so I apologize if this is a dumb question.

Regards,
Giancarlo Frix



More information about the Libc-help mailing list