Re: seg fault on kse_release () (fwd)

From: Jose Hidalgo Herrera (jose_at_hostarica.com)
Date: 01/25/05

  • Next message: João Carlos Mendes Luís: "Re: Resuming from a crashdump"
    To: Yan Yu <yanyu@CS.UCLA.EDU>
    Date: Tue, 25 Jan 2005 14:47:36 -0600
    
    

    The line causing the SEGFAULT is
    rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);

    Why?, because t is declared as:
    int t;
    then you say:
    args for start_routine in pthread_create are located in the address: t

    This will be what you want:
    rc = pthread_create(&threads[t], NULL, PrintHello, (void *) & t);

    You also have an error in this line:

    printf("\n%d: Hello World!\n", threadid);

    Since threadid is not an int, its a pointer

    On Tue, 2005-01-25 at 10:31 -0800, Yan Yu wrote:
    > Hi, thanks a LOT for looking into this.
    > yes, that is exactly my output before the SEG fault happens (btw, i add
    > "if (p)" before
    > "p[id]++ ", the prob remains..
    > what confuses me is that, if the system is out of memory, then i should
    > see the error returned from pthread_create() or calloc(), but not SEG
    > fault, or i must have missed something?
    >
    > Thanks,
    > yan
    >
    >
    > On Tue, 25 Jan 2005, Jose Hidalgo Herrera wrote:
    >
    > > I ran it into:
    > > 4.11-STABLE FreeBSD Wed Jan 19 15:23:33 CST 2005
    > > What you find in
    > > http://www1.cr.freebsd.org/~jose/stress.tgz
    > > is the output of:
    > > ktrace ./a.out > stress.txt
    > >
    > >
    > > On Mon, 2005-01-24 at 14:27 -0800, Yan Yu wrote:
    > > > Hi, all, I have a newbie Q:
    > > > I am trying to use creating large number of threads and allocting
    > > > memory to stress the system.
    > > > My user program causes SEG fault in the kernel code, kse_release () in
    > > > kern_kse.c.
    > > > (it SEG fault before the system can be stressed;(
    > > >
    > > > the stack when the SEG fault happens are:
    > > > #0 0x08064e54 in kse_release ()
    > > > #1 0x080531c4 in kse_sched_single ()
    > > > #2 0x00000000 in ?? ()
    > > >
    > > > My simple program is:
    > > > I have a simple function to create threads:
    > > >
    > > > #define NUM_THREADS 5000
    > > > #define THREADS_IN_ONE_PROCESS 5
    > > > #define BSIZE 500000
    > > > static int cc;
    > > >
    > > > void CreateThread(int n)
    > > > {
    > > > assert( n <= NUM_THREADS );
    > > > pthread_t threads[NUM_THREADS];
    > > > int rc, t;
    > > > for(t=0;t < n;t++){
    > > > printf("#%d: Creating thread %d\n", cc, t);
    > > > cc++;
    > > > rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
    > > > if (rc){
    > > > printf("ERROR; return code from pthread_create() is %d\n", rc);
    > > > }
    > > > }
    > > >
    > > > unsigned long id;
    > > > char * p = (char *) calloc(BSIZE, sizeof(char) );
    > > > if ( p == NULL )
    > > > {
    > > > fprintf(stderr, "calloc error\n");
    > > > }
    > > > while (1)
    > > > {
    > > > while (BSIZE <= (id = rand() / (RAND_MAX/BSIZE)));
    > > > p[id] ++;
    > > > }
    > > > }
    > > >
    > > > void *PrintHello(void *threadid)
    > > > {
    > > > printf("\n%d: Hello World!\n", threadid);
    > > > CreateThread(THREADS_IN_ONE_PROCESS);
    > > > pthread_exit(NULL);
    > > > }
    > > >
    > > > int main (int argc, char *argv[])
    > > > {
    > > > CreateThread(THREADS_IN_ONE_PROCESS);
    > > > }
    > > >
    > > > The SEG fault happens after creating nearly 5000 threads.
    > > > and I use the default pthread.h coming w/ freeBSD 5.3
    > > > #define PTHREAD_KEYS_MAX 256
    > > > #define PTHREAD_STACK_MIN (1 << 22)
    > > > #define PTHREAD_THREADS_MAX ULONG_MAX
    > > >
    > > >
    > > > Any idea on what might happen?
    > > >
    > > > Many Thanks!
    > > > yan
    > > > _______________________________________________
    > > > freebsd-hackers@freebsd.org mailing list
    > > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    > > > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    > >

    -- 
    Jose Hidalgo Herrera <jose@hostarica.com>
    Corp. Hostarica
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: João Carlos Mendes Luís: "Re: Resuming from a crashdump"

    Relevant Pages

    • Re: Newbie question: Why does this work?
      ... void insertion_sort(int a, int length) ... IMHO the segfault should occur at line 9 as on the first pass through ... guarantee that it would cause a seg fault, ... The behavior is simply undefined (i.e., the C standard says ...
      (comp.lang.c)
    • Re: what is wrong with this code ? hi-q
      ... When run it gives me seg fault in linux. ... > int i, j; ... These are all valid ranges for the array a so no seg fault here. ... as one double for loop or something that initialized the first bit as ...
      (comp.lang.c)
    • Re: kernel module function arguments
      ... int main ... arguments to load into the "args" array. ... It is not typical for kernel system call handlers to take the type ... additional arguments into the first slot in the ...
      (comp.os.linux.development.system)
    • EXPLOIT for Re: [VSA0402] OpenFTPD format string vulnerability
      ... all of the args to command are passed directly through to the msg ... int align; ... void login(char *user, char *pass, int sock) ...
      (Bugtraq)
    • Re: Code fails with Segmentation Fault
      ... I am trying to learn C, especially pointers. ... First of all use a debugger to find out where the seg fault occurs. ... int main ... I would probably do the expansion earlier; expand if we need the extra room ...
      (comp.lang.c)