This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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 guard updating source


Hi!

I have written simple test:

#include <sys/syscall.h>
#include <stdio.h>
#include <pthread.h>

int get_guard() {
  int i;
  asm ("mov %%gs:0x14, %0": "=d" (i));
  return i;
}

void* th_test(void* q) {
  int i;
  i = get_guard();
  printf("[%d] gs:0x14 = %d\n", syscall(SYS_gettid), i);
}

int main(int argc, char** argv){
  int i = 0;

  while (i < 10) {
    pthread_t thread_id;
    int result = pthread_create(&thread_id, NULL, th_test, NULL);
    pthread_join(thread_id, NULL);
    ++i;
  }
}


Test stdout:
[8955] gs:0x14 = 217606400
[8956] gs:0x14 = 217606400
[8957] gs:0x14 = 217606400
[8958] gs:0x14 = 217606400
[8959] gs:0x14 = 217606400
[8960] gs:0x14 = 217606400
[8961] gs:0x14 = 217606400
[8962] gs:0x14 = 217606400
[8963] gs:0x14 = 217606400
[8964] gs:0x14 = 217606400

The guard value is identical for any thread, the guard value isn't
thread specific.

2012/10/10 Roland McGrath <roland@hack.frob.com>:
> It's not there because it's thread-specific.
> It's just there because that's the cheapest way to access it.


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