I am currently working with threads using linux 2.6.11 and glibc 2.3.5 on x86. When i am trying to create thread with user defined stacks glibc gives segmentation fault. I have written a wrapper to pthread_create () and generated shared object for the same. When i am trying to create any thread (for user defined stack) using this shared object i am getting segmentation fault. If i don't create shared object and try to create thread (with user defined stack) using same code, it works fine. I am not able to understand this behavior. Why creating a thread using shared object shall result in segfault. And how to overcome this situation.
NOTE: I got same behavior when tried with linux 2.6.12 and glibc-2.3.6 on arm platform.
gdb output for the behavior is :
Loaded symbols for /lib/libgcc_s.so.1
#0 0x0018a777 in memset () from /lib/libc.so.6
(gdb) bt'
#0 0x0018a777 in memset () from /lib/libc.so.6
No symbol table info available.
#1 0x003e27ef in pthread_create@@GLIBC_2.1 () from /lib/libpthread.so.0
No symbol table info available.
#2 0x003e29fd in pthread_create@GLIBC_2.0 () from /lib/libpthread.so.0
No symbol table info available.
#3 0x00ed9880 in process_create (entry_point=0x8048f4c <ThreadEntryPoint>, pArg=0x1, pStack=0x82e08a8, ulStack_Size=16384, ulPrio=127)
at multithreading.c:1916
stThAttr = {__size = "c\000\000\000\002\000\000\000j\000\000\000\000\02 0\000\000¨H.\b\000@", '\0' <repeats 13 times>, __align = 99}
stSchedParam = {__sched_priority = 99}
pstTd = (ThreadData_t *) 0xedd7d8
state = 0
chPriority = 99 'c'
ulRetVal = 0
pRetVal = 0x0
__FUNCTION__ = "process_create"
#4 0x08049af8 in process_create_test (ulInParam=1) at multithreading_test.c:539
ulIndex = 0
lRetVal = -1
ulThreadIndex = 1
lTestPassFlag = 0
stack = (void *) 0x82d88a8
pStack = (void *) 0x82e08a8
ulPrio = 127
stackSize = 16384
__FUNCTION__ = "process_create_test"
#5 0x0804b14b in main () at multithreading_test.c:1460
chChoice = "1"
lChoice = 1
stack = (void *) 0x0
stackSize = 0
ulPrio = 0
ulLoopIndex = 0
stTime = 134533384
stTimeInfo = {tm_sec = 4, tm_min = 53, tm_hour = 7, tm_mday = 7, tm_mon = 3, tm_year = 74, tm_wday = 0, tm_yday = 96, tm_isdst = 0,
tm_gmtoff = 19800, tm_zone = 0x82d81b8 "IST"}
achTimebuf = "04/07/1974 07:53:w"
stThAttr = {__size = '\0' <repeats 13 times>, "\020", '\0' <repeats 21 times>, __align = 0}
lFlag = 1
chFlag = 0
lTestPassFlag = 0
ulThreadIndex = 0
ulloopIndex = 1
ulThreadId = {0, 0, 0, 0}
__FUNCTION__ = "main"
(gdb) f 0
#0 0x0018a777 in memset () from /lib/libc.so.6
(gdb) f 1
#1 0x003e27ef in pthread_create@@GLIBC_2.1 () from /lib/libpthread.so.0
(gdb)
I am calling pthread_create () inside library call itself And not in main, stack is allocated (using malloc) in main and passed with size argument to library function. may this be the cause for segfault? Is it not possible to pass stack pointer, size and entry point function to thread to library function and library inturn creates thread ?
Is there anything wrong with the above code ? I am not able to figure it out .
edit by bakunin: please use code-tags when posting code. It makes your program text all the more readable.
stackbase2 is being zeroed with no memory allocated for it.
That's probably your problem.
<EDIT>
Nevermind. I don't understand the gymnastics you are doing with the stackbase and size parameters to test_main.
You are passing what looks like an invalid address with the the pointer arithmetic here:
and then attempting to set the stack to this address. That's all I can see.
Last edited by ramen_noodle; 04-01-2008 at 09:47 AM..
stackbase2 is not getting used in program so i didn't bother about it. Passing pointer argument in test_main () function also i have tried with giving proper values like base as stack address and size as stack size. Same code works fine if i compile all in one file. Problem comes only if i move library code to another file and compile it to generate shared object (.so library). And when i link this to compile and run with main() then i get segmentation fault.
I can't see any other problem offhand. The link in my first post does note that there are some common-sense issues that could be pertinent.
I'll see if I can find time to try your code as a shared lib and try to duplicate your issue.
Here is the way i compiled and generated the behavior. May be i am doing something wrong while compiling and linking itself. I am giving steps to duplicate the issue:
Step 1: source code given below is kept in a file name test.c
Step 2 : Code given below is kept in a file test_shared.c
Step : 3 : Now i generated .so using command given below.
Step : 4 : Now i compiled test.c with command as below.
Step : 5 : Now i run the application using given command:
These step will generate issue posted by me. If i compile these files like the following command i don't get any issue.
I am struggling to find cause for this behavior. Please let me know the cause for same.
I have to debug a function getopt_long in glibc-2.11.3-17.31.1.
For that how can I download and install its corresponding glibc-debug on SLES 11? (8 Replies)
Hi, i would like to create user defined commands.
e,g:
if an user executes ,
mkdircd test then a directory called test should be created and it should be cd to test.
How i can create the command mkdircd with below action:
mkdir $1 && cd $1.
Please help me in achieving this (7 Replies)
Hi;
Is der ne to to use user defined functions for the values in awk
find $1 -type f -ls | nawk '{{print "|"$3"|"$5"|"$6"|"$8"|"$9"|"$10"|"} for(i=11;i<=NF;i++){printf("%s",$i)}}'
In above command i want to append some values returned by user functions on line.
thnks;
ajay (1 Reply)
Hi
Is there a way to add more user-defined signals?
I am currently using SIGUSR1 and SIGUSR2 - but I need another one.
How can I do that?
Thanks! (9 Replies)
Hi,
I am currently working with threads using linux 2.6.11 and glibc 2.3.5 on x86. When i am trying to create thread with user defined stacks glibc gives segmentation fault. I have written a wrapper to pthread_create () and generated shared object for the same. When i am trying to create any... (0 Replies)
Dear Friends,
I need a help regarding User defined function in shell script.
My problem is as follows:
my_func.sh
my_funcI(){
grep 'mystring' I.dat
}
my_funcQ(){
grep 'mystring' Q.dat
}
myfuncI
myfuncQ
But As both the function has same function only the... (11 Replies)
I want to add a new IP service which executes a script on SCO OS5.
I have amended /etc/services and added to port number (3333)
I have amended /etc/inetd.conf and added a line for this service but I can't get it to execute my own shell script
When I telnet to the IP address on port 3333 I... (1 Reply)
Hi,
I am just running a incremental back-up on one of my server.
But these days It abrubtly fails with below error.
==========
User defined signal 1
===========
When I rerun the back-up, It completed successfully.Earlier this was not happening.
Any Idea, what could be the problem... (0 Replies)
HELP!!!! I am in an on-line shell programming class and have a question. Here is the data:
Mike Harrington:(510) 548-1278:250:100:175
Christian Dobbins:(408) 538-2358:155:90:201
Susan Dalsass:(206) 654-6279:250:60:50
(There are 12 contribuors total)
This database contains names, phone... (1 Reply)