This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug nptl/837] New: can't setstack in share library.
- From: "zhouxw at nanjing-fnst dot com" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 9 Apr 2005 04:18:14 -0000
- Subject: [Bug nptl/837] New: can't setstack in share library.
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
Following code causes "Segmentation fault" (kernel:linux2.6.9)
/*my_thread.c*/
#include <pthread.h>
#include <sys/shm.h>
#define PAGE_SIZE 4UL*1024UL*1024UL
#define ADDR (0x00000000UL)
int my_pthread_create(pthread_t * id, pthread_attr_t * attribute, void
* (*start_routine)(void *), void * arg)
{
pthread_attr_t attr;
pthread_attr_init(&attr);
int ret;
int shmid = 0;
void *addr = NULL;
key_t key = 566;
shmid = shmget(key, PAGE_SIZE,
SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W|SHM_RND);
if(shmid != -1)
{
addr = shmat(shmid, (void *)ADDR , 0);
if (((long)addr) == -1)
return 1;
}
ret = pthread_attr_setstack (&attr, addr , PAGE_SIZE);
if(ret != 0 )
return 1;
ret=pthread_create(id,&attr,(void *)start_routine, NULL);
if(ret != 0 )
return 1;
return (0);
}
/*test.c*/
#include <stdio.h>
#include <errno.h>
#include "my_thread.h"
void thread1(void)
{
int i=11;
printf("first variable of thread1 addr = %pn", &i);
}
int main(void)
{
pthread_t id;
int ret;
ret = my_pthread_create(&id,NULL,(void *)thread1, NULL);
if(ret != 0 )
printf("errno = %dn",errno);
pthread_join(id,NULL);
return (0);
}
/*my_thread.h*/
#include <pthread.h>
#include <sys/shm.h>
extern int my_pthread_create(pthread_t * id, pthread_attr_t * attr1,
void * (*start_routine)(void *), void * arg);
/*Makefile*/
TEST:
gcc -fpic -c -g my_thread.c my_thread.h
gcc -shared -Wl,-soname,libmy_thread.so -o libmy_thread.so
my_thread.o
cp ./libmy_thread.so /lib/
cp ./libmy_thread.so /usr/lib
gcc test.c -o test -lmy_thread -lpthread
clear:
rm -f *.o libmy_thread.so test
--
Summary: can't setstack in share library.
Product: glibc
Version: 2.3.4
Status: NEW
Severity: critical
Priority: P2
Component: nptl
AssignedTo: drepper at redhat dot com
ReportedBy: zhouxw at nanjing-fnst dot com
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: i386-pc-linux2.6.9-gnu
GCC host triplet: i386-pc-linux2.6.9-gnu
GCC target triplet: i386-pc-linux2.6.9-gnu
http://sources.redhat.com/bugzilla/show_bug.cgi?id=837
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.