Calling system() in multi-threads.

Takashi Yano takashi.yano@nifty.ne.jp
Fri Jul 18 15:11:54 GMT 2025


On Sat, 19 Jul 2025 00:04:56 +0900
Takashi Yano wrote:
> On Fri, 18 Jul 2025 16:25:49 +0200
> Corinna Vinschen wrote:
> > On Jul 18 22:32, Takashi Yano via Cygwin wrote:
> > > I embedded debug code into mm/cygheap.cc, that is:
> > > 
> > > diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
> > > index 338886468..bab4067e0 100644
> > > --- a/winsup/cygwin/mm/cygheap.cc
> > > +++ b/winsup/cygwin/mm/cygheap.cc
> > > @@ -371,7 +371,16 @@ _cmalloc (unsigned size)
> > >    if (cygheap->buckets[b])
> > >      {
> > >        rvc = (_cmalloc_entry *) cygheap->buckets[b];
> > > -      cygheap->buckets[b] = rvc->ptr;
> > > +      __try
> > > +	{
> > > +	  cygheap->buckets[b] = rvc->ptr;
> > > +	}
> > > +      __except (NO_ERROR)
> > > +	{ /* Shouldl not reach */
> > > +	  system_printf("b = %d", b);
> > > +	  assert (false);
> > > +	}
> > > +      __endtry
> > >        rvc->b = b;
> > >      }
> > >    else
> > > The result is like this! Why???
> > > 
> > >       0 [main] sh 617 _cmalloc: b = 1
> > > assertion "false" failed: file "../../.././winsup/cygwin/mm/cygheap.cc", line 381, function: void* _cmalloc(unsigned int)
> > 
> > I don't know.  Looks like rvc points into nirvana.  Who's the caller?
> > what's the value of cygheap->buckets[1]?  Is something filling up cygheap
> > fast, perhaps?  
> 
>       0 [main] sh 403 _cmalloc: b = 0
>     164 [main] sh 403 _cmalloc: cygheap->buckets[b] = 0x63005C003A0043
>       0 [main] sh 405 _cmalloc: b = 0
>       0 [main] sh 408 _cmalloc: b = 0
>     164 [main] sh 405 _cmalloc: cygheap->buckets[b] = 0x6
>       0 [main] sh 407 _cmalloc: b = 0
>     166 [main] sh 408 _cmalloc: cygheap->buckets[b] = 0x6
>     218 [main] sh 407 _cmalloc: cygheap->buckets[b] = 0x6
>       0 [main] sh 404 _cmalloc: b = 0
>     167 [main] sh 404 _cmalloc: cygheap->buckets[b] = 0x6
>       0 [main] sh 409 _cmalloc: b = 0
>     131 [main] sh 409 _cmalloc: cygheap->buckets[b] = 0x6
>       1 [main] sh 406 _cmalloc: b = 0
>     172 [main] sh 406 _cmalloc: cygheap->buckets[b] = 0x6
> 
> cygheap->buckets[b] seems to be broken.
> 
> 403:
> ... (infinite loop for ritrieving stacktrace) ...
> #2  0x00007fff8bd36ad8 in _cmalloc (size=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:382
> #3  0x00007fff8bd37418 in cmalloc (fn=0x0, n=9, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:476
> #4  cmalloc (n=9, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:483
> #5  crealloc (fn=0x7fff8beb5984 <P+1444> "crealloc", n=9, s=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:496
> #6  crealloc_abort (s=<optimized out>, n=9) at ../../.././winsup/cygwin/mm/cygheap.cc:514
> #7  0x00007fff8bc55fd6 in path_conv::set_posix (path_copy=0x1210720 "/dev/tty", this=0x7ffffc800) at ../../.././winsup/cygwin/path.cc:451
> #8  path_conv::set_posix (path_copy=0x1210720 "/dev/tty", this=0x7ffffc800) at ../../.././winsup/cygwin/path.cc:446
> #9  path_conv::check (this=this@entry=0x7ffffc800, src=<optimized out>, src@entry=0x0, opt=6817, suffixes=0x7fff8bf2d1c0 <stat_suffixes>) at ../../.././winsup/cygwin/path.cc:1310
> #10 0x00007fff8bc1959c in path_conv::path_conv (suffixes=<optimized out>, opt=6817, src=0x0, this=0x7ffffc800) at /home/yano/newlib-cygwin/winsup/cygwin/local_includes/path.h:312
> #11 build_fh_name (name=name@entry=0x10049d830 "/dev/tty", opt=opt@entry=6657, si=<optimized out>) at ../../.././winsup/cygwin/dtable.cc:439
> #12 0x00007fff8bc92f7a in open (unix_path=0x10049d830 "/dev/tty", flags=16386) at ../../.././winsup/cygwin/syscalls.cc:1488
> #13 0x00007fff8bd5a1c4 in _sigfe () at sigfe.s:35
> #14 0x000000010040dee5 in check_dev_tty ()
> #15 0x00000001004948f1 in main ()
> 
> 405:
> ... (infinite loop for ritrieving stacktrace) ...
> #2  0x00007fff8bd36ad8 in _cmalloc (size=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:382
> #3  0x00007fff8bd37418 in cmalloc (fn=0x0, n=9, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:476
> #4  cmalloc (n=9, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:483
> #5  crealloc (fn=0x7fff8beb5984 <P+1444> "crealloc", n=9, s=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:496
> #6  crealloc_abort (s=<optimized out>, n=9) at ../../.././winsup/cygwin/mm/cygheap.cc:514
> #7  0x00007fff8bc55fd6 in path_conv::set_posix (path_copy=0x1390720 "/dev/tty", this=0x7ffffc800) at ../../.././winsup/cygwin/path.cc:451
> #8  path_conv::set_posix (path_copy=0x1390720 "/dev/tty", this=0x7ffffc800) at ../../.././winsup/cygwin/path.cc:446
> #9  path_conv::check (this=this@entry=0x7ffffc800, src=<optimized out>, src@entry=0x0, opt=6817, suffixes=0x7fff8bf2d1c0 <stat_suffixes>) at ../../.././winsup/cygwin/path.cc:1310
> #10 0x00007fff8bc1959c in path_conv::path_conv (suffixes=<optimized out>, opt=6817, src=0x0, this=0x7ffffc800) at /home/yano/newlib-cygwin/winsup/cygwin/local_includes/path.h:312
> #11 build_fh_name (name=name@entry=0x10049d830 "/dev/tty", opt=opt@entry=6657, si=<optimized out>) at ../../.././winsup/cygwin/dtable.cc:439
> #12 0x00007fff8bc92f7a in open (unix_path=0x10049d830 "/dev/tty", flags=16386) at ../../.././winsup/cygwin/syscalls.cc:1488
> #13 0x00007fff8bd5a1c4 in _sigfe () at sigfe.s:35
> #14 0x000000010040dee5 in check_dev_tty ()
> #15 0x00000001004948f1 in main ()

Another case:
...
#2  0x00007fff8bd36ad8 in _cmalloc (size=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:382
#3  0x00007fff8bd3791a in cmalloc (fn=0x0, n=82, x=HEAP_1_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:476
#4  cmalloc (n=82, x=HEAP_1_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:483
#5  cstrdup1 (s=0xa00014410 "VS140COMNTOOLS=C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\") at ../../.././winsup/cygwin/mm/cygheap.cc:588
#6  0x00007fff8bc1df95 in build_env (envp=<optimized out>, envp@entry=0xa000134c0, envblock=@0x7fff8be6bbe0: 0x0, envc=@0xa000163c0: 16843009, no_envblock=false, new_token=0x0) at ../../.././winsup/cygwin/environ.cc:1155
#7  0x00007fff8bc85584 in child_info_spawn::worker (this=0xa00016920, this@entry=0x7fff8be6a8e0 <ch_spawn>, prog_arg=prog_arg@entry=0xa00016a40 "/usr/bin/echo", argv=argv@entry=0xa00009500, envp=envp@entry=0xa000134c0, mode=mode@entry=3, in__stdin=in__stdin@entry=-1, in__stdout=in__stdout@entry=-1) at ../../.././winsup/cygwin/spawn.cc:507
#8  0x00007fff8bc87061 in spawnve (mode=3, path=0xa00016a40 "/usr/bin/echo", argv=0xa00009500, envp=0xa000134c0) at ../../.././winsup/cygwin/spawn.cc:955
#9  0x00007fff8bd5a1c4 in _sigfe () at sigfe.s:35
#10 0x0000000100415e24 in shell_execve ()
#11 0x0000000100416704 in shell_execve ()
#12 0x000000010041807e in execute_command_internal ()
#13 0x000000010047090f in parse_and_execute ()
#14 0x0000000100401b73 in ?? ()
#15 0x00000001004959b3 in main ()

Yet another case:
...
#2  0x00007fff8bd36ad8 in _cmalloc (size=<optimized out>) at ../../.././winsup/cygwin/mm/cygheap.cc:382
#3  0x00007fff8bd3783a in cmalloc (fn=0x0, n=31, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:476
#4  cmalloc (n=31, x=HEAP_STR) at ../../.././winsup/cygwin/mm/cygheap.cc:483
#5  cstrdup (s=0x8000405c0 "C:\\cygwin64\\home\\yano\\20250611") at ../../.././winsup/cygwin/mm/cygheap.cc:578
#6  0x00007fff8bcbb7e2 in path_conv::eq_worker (in_path=0x8000405c0 "C:\\cygwin64\\home\\yano\\20250611", pc=..., this=<optimized out>) at /home/yano/newlib-cygwin/winsup/cygwin/local_includes/path.h:375
#7  path_conv::operator<< (this=0x800025e08, pc=...) at /home/yano/newlib-cygwin/winsup/cygwin/local_includes/path.h:400
#8  0x00007fff8bc1849c in build_fh_pc (pc=...) at ../../.././winsup/cygwin/dtable.cc:670
#9  0x00007fff8bc9571e in stat_worker (pc=..., buf=buf@entry=0x7ffffc680) at ../../.././winsup/cygwin/syscalls.cc:2107
#10 0x00007fff8bc950be in stat(const char * __restrict__, stat * __restrict__) (name=0xa0000c6e0 "/home/yano/20250611", buf=0x7ffffc680) at ../../.././winsup/cygwin/syscalls.cc:2134
#11 0x00007fff8bd5a1c4 in _sigfe () at sigfe.s:35
#12 0x000000010040dfad in same_file ()
#13 0x0000000100420ae5 in set_pwd ()
#14 0x0000000100423917 in initialize_shell_variables ()
#15 0x00000001004019a9 in ?? ()
#16 0x000000010049526c in main ()

Inconsistent...

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>


More information about the Cygwin mailing list