View | Details | Raw Unified | Return to bug 20116
Collapse All | Expand All

(-)glibc-2.22_orig/nptl/createthread.c (-3 / +3 lines)
Lines 25-37 Link Here
25
25
26
static int
26
static int
27
create_thread (struct pthread *pd, const struct pthread_attr *attr,
27
create_thread (struct pthread *pd, const struct pthread_attr *attr,
28
	       bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
28
	       bool *stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
29
{
29
{
30
  /* If the implementation needs to do some tweaks to the thread after
30
  /* If the implementation needs to do some tweaks to the thread after
31
     it has been created at the OS level, it can set STOPPED_START here.  */
31
     it has been created at the OS level, it can set STOPPED_START here.  */
32
32
33
  pd->stopped_start = stopped_start;
33
  pd->stopped_start = *stopped_start;
34
  if (__glibc_unlikely (stopped_start))
34
  if (__glibc_unlikely (*stopped_start))
35
    /* We make sure the thread does not run far by forcing it to get a
35
    /* We make sure the thread does not run far by forcing it to get a
36
       lock.  We lock it here too so that the new thread cannot continue
36
       lock.  We lock it here too so that the new thread cannot continue
37
       until we tell it to.  */
37
       until we tell it to.  */
(-)glibc-2.22_orig/nptl/pthread_create.c (-4 / +7 lines)
Lines 72-78 Link Here
72
   case it is responsible for doing its own cleanup.  */
72
   case it is responsible for doing its own cleanup.  */
73
73
74
static int create_thread (struct pthread *pd, const struct pthread_attr *attr,
74
static int create_thread (struct pthread *pd, const struct pthread_attr *attr,
75
			  bool stopped_start, STACK_VARIABLES_PARMS,
75
			  bool *stopped_start, STACK_VARIABLES_PARMS,
76
			  bool *thread_ran);
76
			  bool *thread_ran);
77
77
78
#include <createthread.c>
78
#include <createthread.c>
Lines 633-646 Link Here
633
     that cares whether the thread count is correct.  */
633
     that cares whether the thread count is correct.  */
634
  atomic_increment (&__nptl_nthreads);
634
  atomic_increment (&__nptl_nthreads);
635
635
636
  bool stopped_start = false;
636
  bool thread_ran = false;
637
  bool thread_ran = false;
637
638
638
  /* Start the thread.  */
639
  /* Start the thread.  */
639
  if (__glibc_unlikely (report_thread_creation (pd)))
640
  if (__glibc_unlikely (report_thread_creation (pd)))
640
    {
641
    {
642
      stopped_start = true;
641
      /* Create the thread.  We always create the thread stopped
643
      /* Create the thread.  We always create the thread stopped
642
	 so that it does not get far before we tell the debugger.  */
644
	 so that it does not get far before we tell the debugger.  */
643
      retval = create_thread (pd, iattr, true, STACK_VARIABLES_ARGS,
645
      retval = create_thread (pd, iattr, &stopped_start, STACK_VARIABLES_ARGS,
644
			      &thread_ran);
646
			      &thread_ran);
645
      if (retval == 0)
647
      if (retval == 0)
646
	{
648
	{
Lines 667-673 Link Here
667
	}
669
	}
668
    }
670
    }
669
  else
671
  else
670
    retval = create_thread (pd, iattr, false, STACK_VARIABLES_ARGS,
672
    retval = create_thread (pd, iattr, &stopped_start, STACK_VARIABLES_ARGS,
671
			    &thread_ran);
673
			    &thread_ran);
672
674
673
  if (__glibc_unlikely (retval != 0))
675
  if (__glibc_unlikely (retval != 0))
Lines 701-707 Link Here
701
    }
703
    }
702
  else
704
  else
703
    {
705
    {
704
      if (pd->stopped_start)
706
      /* do not use pd->stopped_start to avoid use after free */
707
      if (stopped_start)
705
	/* The thread blocked on this lock either because we're doing TD_CREATE
708
	/* The thread blocked on this lock either because we're doing TD_CREATE
706
	   event reporting, or for some other reason that create_thread chose.
709
	   event reporting, or for some other reason that create_thread chose.
707
	   Now let it run free.  */
710
	   Now let it run free.  */
(-)glibc-2.22_orig/sysdeps/nacl/createthread.c (-3 / +3 lines)
Lines 32-43 Link Here
32
32
33
static int
33
static int
34
create_thread (struct pthread *pd, const struct pthread_attr *attr,
34
create_thread (struct pthread *pd, const struct pthread_attr *attr,
35
	       bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
35
	       bool *stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
36
{
36
{
37
  pd->tid = __nacl_get_tid (pd);
37
  pd->tid = __nacl_get_tid (pd);
38
38
39
  pd->stopped_start = stopped_start;
39
  pd->stopped_start = *stopped_start;
40
  if (__glibc_unlikely (stopped_start))
40
  if (__glibc_unlikely (*stopped_start))
41
    /* We make sure the thread does not run far by forcing it to get a
41
    /* We make sure the thread does not run far by forcing it to get a
42
       lock.  We lock it here too so that the new thread cannot continue
42
       lock.  We lock it here too so that the new thread cannot continue
43
       until we tell it to.  */
43
       until we tell it to.  */
(-)glibc-2.22_orig/sysdeps/unix/sysv/linux/createthread.c (-6 / +6 lines)
Lines 46-52 Link Here
46
46
47
static int
47
static int
48
create_thread (struct pthread *pd, const struct pthread_attr *attr,
48
create_thread (struct pthread *pd, const struct pthread_attr *attr,
49
	       bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
49
	       bool *stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
50
{
50
{
51
  /* Determine whether the newly created threads has to be started
51
  /* Determine whether the newly created threads has to be started
52
     stopped since we have to set the scheduling parameters or set the
52
     stopped since we have to set the scheduling parameters or set the
Lines 54-63 Link Here
54
  if (attr != NULL
54
  if (attr != NULL
55
      && (__glibc_unlikely (attr->cpuset != NULL)
55
      && (__glibc_unlikely (attr->cpuset != NULL)
56
	  || __glibc_unlikely ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0)))
56
	  || __glibc_unlikely ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0)))
57
    stopped_start = true;
57
    *stopped_start = true;
58
58
59
  pd->stopped_start = stopped_start;
59
  pd->stopped_start = *stopped_start;
60
  if (__glibc_unlikely (stopped_start))
60
  if (__glibc_unlikely (*stopped_start))
61
    /* We make sure the thread does not run far by forcing it to get a
61
    /* We make sure the thread does not run far by forcing it to get a
62
       lock.  We lock it here too so that the new thread cannot continue
62
       lock.  We lock it here too so that the new thread cannot continue
63
       until we tell it to.  */
63
       until we tell it to.  */
Lines 117-123 Link Here
117
      /* Set the affinity mask if necessary.  */
117
      /* Set the affinity mask if necessary.  */
118
      if (attr->cpuset != NULL)
118
      if (attr->cpuset != NULL)
119
	{
119
	{
120
	  assert (stopped_start);
120
	  assert (*stopped_start);
121
121
122
	  res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid,
122
	  res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid,
123
				  attr->cpusetsize, attr->cpuset);
123
				  attr->cpusetsize, attr->cpuset);
Lines 140-146 Link Here
140
      /* Set the scheduling parameters.  */
140
      /* Set the scheduling parameters.  */
141
      if ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0)
141
      if ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0)
142
	{
142
	{
143
	  assert (stopped_start);
143
	  assert (*stopped_start);
144
144
145
	  res = INTERNAL_SYSCALL (sched_setscheduler, err, 3, pd->tid,
145
	  res = INTERNAL_SYSCALL (sched_setscheduler, err, 3, pd->tid,
146
				  pd->schedpolicy, &pd->schedparam);
146
				  pd->schedpolicy, &pd->schedparam);

Return to bug 20116