2002-01-22 21:41:14 +00:00
|
|
|
#include <stdio.h>
|
2002-01-27 20:11:58 +00:00
|
|
|
#include "linuxthreads.h"
|
2002-02-02 19:07:10 +00:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2002-01-23 01:23:10 +00:00
|
|
|
|
2002-01-23 03:14:19 +00:00
|
|
|
/* this function is only really necessary to get the main thread's
|
|
|
|
* pthread_descr, as the other threads store the pthread_descr (actually the
|
|
|
|
* first member of struct _pthread_descr_struct, which points to itself for the
|
|
|
|
* default (non-indirected) case) at the top of the stack. */
|
2002-01-23 01:23:10 +00:00
|
|
|
static _pthread_descr linuxthreads_self()
|
|
|
|
{
|
|
|
|
pthread_mutexattr_t mutexattr;
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
_pthread_descr self;
|
|
|
|
|
|
|
|
pthread_mutexattr_init (&mutexattr);
|
|
|
|
pthread_mutexattr_setkind_np (&mutexattr, PTHREAD_MUTEX_ERRORCHECK_NP);
|
|
|
|
pthread_mutex_init (&mutex, &mutexattr);
|
|
|
|
|
|
|
|
pthread_mutex_lock (&mutex);
|
|
|
|
self = mutex.__m_owner;
|
|
|
|
pthread_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
printf ("pthread_self: %d\n", pthread_self());
|
|
|
|
printf ("descr: %p\n", self);
|
2002-01-23 03:14:19 +00:00
|
|
|
printf ("*descr: %p\n", *(int*)self);
|
2002-01-23 01:23:10 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *pthread (void *unused)
|
|
|
|
{
|
2002-01-23 03:14:19 +00:00
|
|
|
char *sp = CURRENT_STACK_FRAME;
|
|
|
|
|
2002-01-23 01:23:10 +00:00
|
|
|
linuxthreads_self();
|
2002-01-23 03:14:19 +00:00
|
|
|
printf ("sp: %p\n", sp);
|
|
|
|
printf ("sp | 0x020000: 0x%x\n", (int) sp | 0x020000 );
|
|
|
|
printf ("(sp | (0x020000-1))+1 - 1K: 0x%x\n", ((((int)sp | (STACK_SIZE-1))+1) - 1024));
|
|
|
|
printf ("*(sp | (0x020000-1))+1 - 1K: %p\n", *(int*)((((long int)sp | (STACK_SIZE-1))+1) - 1024));
|
|
|
|
printf ("(sp &~ (0x020000-1))+1: 0x%x\n", (((int)sp &~ (STACK_SIZE-1))+1));
|
2002-01-23 01:23:10 +00:00
|
|
|
return NULL;
|
2002-01-22 21:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2002-01-23 01:23:10 +00:00
|
|
|
pthread_t tid;
|
2002-01-23 03:14:19 +00:00
|
|
|
int i;
|
2002-02-02 19:07:10 +00:00
|
|
|
struct rlimit limit;
|
2002-01-23 01:23:10 +00:00
|
|
|
|
2002-02-02 19:07:10 +00:00
|
|
|
for (i=0; i<5; i++) {
|
2002-01-23 03:14:19 +00:00
|
|
|
pthread_create (&tid, NULL, pthread, NULL);
|
2002-02-02 19:07:10 +00:00
|
|
|
sleep(1);
|
2002-01-23 03:14:19 +00:00
|
|
|
}
|
2002-01-23 01:23:10 +00:00
|
|
|
|
|
|
|
linuxthreads_self();
|
2002-02-02 19:07:10 +00:00
|
|
|
|
|
|
|
getrlimit (RLIMIT_STACK, &limit);
|
|
|
|
printf ("\nstack size: %d\nmax stack sizeL %d\n", limit.rlim_cur, limit.rlim_max);
|
|
|
|
|
2002-01-23 01:23:10 +00:00
|
|
|
exit (0);
|
2002-01-22 21:41:14 +00:00
|
|
|
}
|