Bug 43786

Summary: peverify is broken again
Product: [Mono] Runtime Reporter: Marek Safar <masafa>
Component: GeneralAssignee: Ludovic Henry <ludovic>
Status: RESOLVED FIXED    
Severity: normal CC: andi.mcclure, kumpera, mono-bugs+mono, mono-bugs+runtime, vargaz
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: Yes
Last known good build:

Description Marek Safar 2016-08-26 12:35:13 UTC
peverify any .exe

peverify x.exe
mono_os_mutex_lock: pthread_mutex_lock failed with "Invalid argument" (22)
Abort trap: 6
Comment 1 Andi McClure 2016-08-29 15:45:48 UTC
I can't repro this.

Marek, what OS, mono version etc was this?
Comment 2 Marek Safar 2016-08-29 16:22:21 UTC
Mac OS, mono master

x.cs

class X
{
	static void Main ()
	{
	}
}

mcs x.cs
peverify x.exe

mono_os_mutex_lock: pthread_mutex_lock failed with "Invalid argument" (22)
Abort trap: 6
Comment 3 Rodrigo Kumpera 2016-08-29 18:59:11 UTC
4.4 is broken and won't be fixed.

4.6 works.

Master with the following commit works:

commit dcd650d6fc59817b1efd6fc088ac41ce304a41c2
Author: Zoltan Varga <vargaz@gmail.com>
Date:   Thu Aug 25 22:18:45 2016 +0200
Comment 4 Andi McClure 2016-08-29 19:02:20 UTC
As mentioned, I was not reproducing this. This was with mono master
d185b75dd7170e2555d2bb70f7a53b54ecbf855c

I *do* reproduce this with the newest mono master
6a5599d71e3c241a4ffbd2833d4d92fe7c89afed
Comment 5 Andi McClure 2016-08-29 19:07:57 UTC
Reopening. Rodrigo, if you are still not reproducing this after upgrading to 6a5599d, let me know.
Comment 6 Andi McClure 2016-08-29 19:23:24 UTC
The crash occurs because scan_mutex is not valid when pedump calls mono_init_version and wapi_init is called.

In between d185b75dd and 6a5599d71e is e5a4d23fc7d431ddb61ad271a5b1e6ad28612104:

"[w32handle] Initialize them earlier...", a commit by ludovic

This moves mono_w32handle_init from mono_init_internal where wapi_init is called to mono_main.

However pedump does not call mono_main, it calls mono_init_version, so now mono_w32handle_init is never called. This could potentially impact anyone who uses the embedding API.

dcd650d6fc59 which Rodrigo tested is newer than e5a4d23fc so I'm not sure why Rodrigo was not reproducing the problem.
Comment 7 Andi McClure 2016-08-29 19:26:42 UTC
Ludovic, can you take a look at this?
Comment 8 Zoltan Varga 2016-08-29 20:39:17 UTC
https://github.com/mono/mono/pull/3478

It would be nice to to all of this stuff in a managed tool instead of C. Since we don't so sandboxing anymore, we don't need a verifier in the runtime.
Comment 9 Rodrigo Kumpera 2016-08-29 21:51:49 UTC
Merged Zoltan's PR.
Comment 10 Rodrigo Kumpera 2016-08-29 22:12:48 UTC
it was reverted, sorry guys :(
Comment 11 Ludovic Henry 2016-08-30 08:33:10 UTC
It is now fixed with https://github.com/mono/mono/commit/e8a221683d31cc392c46ccea67dc1ae8c6d108e7