Compare commits

...
Author SHA1 Message Date
Miguel de Icaza 3a1d727692 Update configure.ac 2015-03-06 12:22:18 -05:00
Sebastien Pouliot f4495ef33e Remove the EXPORT ciphers and related code path
That was still useful in 2003/2004 but the technical and legal landscape
    changed a lot since then. Removing the old, limited key size, cipher
    suites also allow removed additional parts of the code that deals with
    them.
2015-03-06 10:39:22 -05:00
Sebastien Pouliot 2df4a3f96a Remove the client-side SSLv2 fallback.
There's almost no SSLv3 web site left so a v2 fallback is only extra
    code we do not need to carry forward.
2015-03-06 10:39:19 -05:00
Sebastien Pouliot fe29bba462 TLS protocol: add handshake state validation 2015-03-06 10:39:17 -05:00
Miguel de Icaza b0a20f0c39 SslClientStream: Fix build for the 3.10 branch 2015-02-28 09:50:01 -05:00
Miguel de Icaza 3f77a31818 [SslClientStream] Prevent crashes when a connection is closed
When a socket has been closed as part of the negotiation, the
SendAlert method would crash when trying to reuse the socket.

Add try/catch around this to prevent this.

Fixes #19334

Conflicts:
	mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs
2015-02-27 15:13:02 -05:00
Zoltan Varga ce003f4d1f Use SIGWINCH as the android debugger signal (), SIGUSR2 doesn't seem to work on emulators. 2014-11-19 18:20:42 -05:00
Zoltan Varga 197d3bbcab Another attempt at fixing #22968/#23987. The previous backport didn't work because the 3.10 debugger uses another code path. 2014-11-15 04:28:44 -05:00
Zoltan Varga 92c48842a3 [runtime] Fix the errors in edb931dfb9 so it actually works. 2014-11-13 22:29:29 -05:00
Zoltan Varga 771f43fe6c [arm] Fix OP_LOCALLOC on arm so it correctly adjusts sp with the param area size even if the size is large. Fixes #24221. 2014-11-10 17:11:42 -05:00
Zoltan Varga c4d7214b27 [runtime] Use a separate signal with the SA_RESTART flag set for suspending/resuming threads during debugging on android, since lots of android native code cannot handle the interruptions caused by the normal abort signal. Fixes #22968/#23987. 2014-11-07 14:13:50 -05:00
Alexis Christoforides ec8eadce15 Bump to include xamarin/bockbuild@9fb47d1f10 2014-11-03 21:03:49 -05:00
Alexis Christoforides e658d6d71e Bump to include xamarin/bockbuild@3051b3a8ca: [pango] Fix Helvetica Neue Bold and Helvetica Neue Condensed Bold. 2014-11-03 12:49:32 -05:00
Alexis Christoforides d1a1ea3f0d Bump to include xamarin/bockbuild@c5425a0be4. Fixes second issue behind #23553. 2014-10-26 15:26:04 -04:00
Marek Safar fe854adddc Tests update 2014-10-15 12:46:38 +02:00
Marek Safar 66c7cc2489 [mcs] Fix codegen for coalescing operator involving user operator conversion to result type 2014-10-15 11:09:14 +02:00
Marek Safar e204655fb7 [mcs] A pointer-type may be used as the type of a volatile field. Fixes #23770 2014-10-13 12:29:23 +02:00
Marek Safar 18af4c203b [mcs] More tweaks to conditional tokenizer. Fixes #23319 2014-10-13 12:04:27 +02:00
Marek Safar eaee49888d [mcs] Parsing of ternary expressions whose then condition is a lambda. Fixes #22523 2014-10-13 12:04:18 +02:00
Alexis Christoforides 633e444670 Trigger package build to bring in xamarin/bockbuild@99730f1980. Fixes #23553. 2014-10-02 17:25:23 -07:00
Marcos Henrich 47db8687f9 Fix Uri UserInfo parsing. Fixes 23246. 2014-09-29 18:59:42 +01:00
Zoltan Varga 53e316103e [llvm] Fix support for unaligned offsets in the store_membase_imm opcodes. Fixes #23267. 2014-09-22 18:53:10 -04:00
Zoltan Varga f28698eaf3 [runtime] Fix the lookup of nested types which have a namespace. Fixes #21653. 2014-09-22 16:28:43 -04:00
Marek Safar ac510020e7 [xbuild] Workaround for issues with CreateItem task where metadata are not generated due to up-to-data inputs. Fixes #23022 2014-09-17 20:20:35 +02:00
Zoltan Varga 491d1f508a [runtime] Make stack walks done by the sampling profiler async safe. 2014-09-16 16:57:12 -04:00
Zoltan Varga 97d0d52d75 [arm64] Increase some opcode sizes. Fixes #23026. 2014-09-15 20:52:26 -04:00
Marek Safar 13b06d2154 Update test verification data 2014-09-12 16:37:38 +02:00
Marek Safar 79d82d18d2 [mcs] Don't use `1 naming for compiler generated second level and deeper nested types. Fixes #22893 2014-09-12 16:25:23 +02:00
Zoltan Varga bf375c28e4 [jit] Always pass the imt arg to interface calls in gsharedvt methods. Fixes #22624. 2014-09-11 18:46:32 -04:00
Jo Shields b4dde7d30e Fix "make dist" error
ad8236ebb8 broke "make dist", by removing Makefile.am.in whilst leaving it in EXTRA_DIST
2014-09-11 14:09:58 -04:00
Zoltan Varga 19797cc6bb Fix the build. 2014-09-11 14:09:58 -04:00
Zoltan Varga 13c6efb7c6 [runtime] Get rid of the Makefile.am.in->Makefile.am change in metadata/, its not needed. 2014-09-11 14:09:58 -04:00
Rolf Bjarne Kvinge 8037a90611 Don't throw TimeZoneNotFoundExceptions when iOS gives us invalid data.
iOS 8 GM lists "Asia/Chita" among its time zones, but when requesting
the time zone data for that time zone, no data is returned.

With this change we ignore time zones without any data when fetching
all the timezones on the system.
2014-09-11 19:22:52 +02:00
Rodrigo Kumpera 9913521258 Revert "[mcs] Use closed delegate over static generated methods from anonymous methods"
This reverts commit 7edcd42a15.

Conflicts:
	mcs/tests/ver-il-net_4_5.xml
2014-09-10 11:46:00 -04:00
Zoltan Varga e9b744caef Fix the linux build. 2014-09-10 00:10:01 -04:00
Zoltan Varga 2342e18144 [runtime] Fix the linux build. 2014-09-09 11:48:04 -04:00
Zoltan Varga c8ef103f07 [jit] Store the epilog length in MonoArchEHJitInfo instead of encoding it in jinfo->unwind_desc, since the latter can overflow for methods with large epilogs. Fixes #22685. 2014-09-05 18:09:19 -04:00
Rodrigo Kumpera 9add1e0fc2 [utils] Add android extension point to threading. 2014-09-04 17:26:05 -04:00
Rodrigo Kumpera 32c8b7a212 [runtime] Cleanup the horrible ifdef hell that is the stack bounds discovery code.
This split a single chunk of intractable ifdef hell into a beautiful set of per-target
files.

This will allow us to actually figure out what's going on on each target.
2014-09-04 17:25:59 -04:00
Alexis Christoforides 292b18ead6 Bump Mono version -> 3.10.0 2014-09-04 00:13:32 -04:00
Zoltan Varga 39d843f11f [runtime] Load the runtime config file before initializing the runtime, so it can pick up the aot-cache configuration information. 2014-09-03 23:09:18 -04:00
Zoltan Varga 33ec8fd66b [sgen] Use mono_thread_info_get_stack_bounds () on win32 as well, the stack bottom value returned by it is correct, only the stack top value is unusable, since windows dynamically extends the stack. 2014-09-03 21:54:00 -04:00
Zoltan Varga 13dd8b3588 Fix a warning. 2014-09-03 00:56:27 -04:00
Zoltan Varga 47af9db998 [runtime] Add an 'app' attribute to the 'aotcache' config section to specify which apps should use the AOT cache. 2014-09-03 00:56:20 -04:00
Zoltan Varga d4d62e73c2 Disable a sys.data test which fails on wrench because of an old sqlite version. 2014-09-02 13:10:19 -04:00
Marek Safar 1ce0cbe0c8 [mcs] Remove wrong test 2014-09-01 13:29:18 +02:00
Marek Safar 5d73ab53fb [system.net.http] Update RequestMessage.RequestUri.AbsoluteUri after redirect. Fixes #22383 2014-09-01 10:11:23 +02:00
Zoltan Varga 085fa4ce86 [runtime] Fix the windows build. 2014-08-31 12:56:17 -04:00
Zoltan Varga cd4fa869d9 [jit] Avoid uninitialized fields in the MonoDelegateTrampInfo structure. 2014-08-31 12:56:08 -04:00
Zoltan Varga 174c85763f [aot] Fix full-aot support when the AOT cache is enabled. 2014-08-31 12:56:00 -04:00
Marek Safar 5ab589ace2 [xbuild] Fix InstalledAssemblyTables signature 2014-08-30 14:19:35 +02:00
Marek Safar 2eeebc9530 [mcs] Revert to broken native csc definite assignment for structs 2014-08-30 14:19:12 +02:00
Zoltan Varga c5a361b157 [sdb] Fix the checking of the handshake message. 2014-08-29 15:53:43 -04:00
Zoltan Varga fcb962d82f [runtime] Add functionality for AOTing assemblies on demand when they are first used. Configurable using a new "aotconfig" config element, i.e. <aotcache assemblies="mscorlib System"/>. 2014-08-29 15:53:16 -04:00
Zoltan Varga 5e200e65eb [runtime] Add Steve Reid's public domain SHA1 code. 2014-08-29 15:53:08 -04:00
77 changed files with 2179 additions and 1583 deletions

No files matched your search

-1
View File
@@ -123,7 +123,6 @@ if test x$has_ext_mod = xtrue; then
popd
else
cat mono/mini/Makefile.am.in > mono/mini/Makefile.am
cat mono/metadata/Makefile.am.in > mono/metadata/Makefile.am
fi
+1 -1
View File
@@ -1,7 +1,7 @@
# Process this file with autoconf to produce a configure script.
#AC_PREREQ([2.62])
AC_INIT(mono, [3.8.1],
AC_INIT(mono, [3.10.1],
[http://bugzilla.xamarin.com/enter_bug.cgi?classification=Mono])
AC_CONFIG_SRCDIR([README.md])
+1 -1
@@ -99,8 +99,12 @@ namespace Microsoft.Build.BuildEngine {
try {
TaskExecutionMode taskExecutionMode;
string reason;
if (!BuildTargetNeeded (out reason)) {
bool skip_completely;
if (!BuildTargetNeeded (out reason, out skip_completely)) {
LogTargetSkipped (target, reason);
if (skip_completely)
return true;
taskExecutionMode = TaskExecutionMode.SkipAndSetOutput;
} else {
taskExecutionMode = TaskExecutionMode.Complete;
@@ -113,8 +117,27 @@ namespace Microsoft.Build.BuildEngine {
//FIXME: parsing attributes repeatedly
IBuildTask bt = target.BuildTasks [i];
// HACK: need some form of cross references checks
var tem = taskExecutionMode;
if (tem == TaskExecutionMode.SkipAndSetOutput) {
var bti = bt as BuildTask;
//
// BuildTargetNeeded checks only files timestamps but ignores any metadata dependencies
// that way we can end up in the situation when output metadata are populated but from
// incomplete dependencies.
//
// E.g.
// <CreateItem Include="$(IntermediateOutputPath)%(_PngImage.LogicalName)" AdditionalMetadata="LogicalName=%(_PngImage.LogicalName)">
// <Output TaskParameter="Include" />
// </CreateItem>
//
if (bti != null && bti.Name == "CreateItem")
tem = TaskExecutionMode.Complete;
}
TaskBatchingImpl batchingImpl = new TaskBatchingImpl (project);
bool task_result = batchingImpl.Build (bt, taskExecutionMode, out executeOnErrors);
bool task_result = batchingImpl.Build (bt, tem, out executeOnErrors);
if (task_result)
continue;
@@ -149,15 +172,17 @@ namespace Microsoft.Build.BuildEngine {
ParseAttribute (outputs);
}
bool BuildTargetNeeded (out string reason)
bool BuildTargetNeeded (out string reason, out bool skipCompletely)
{
reason = String.Empty;
ITaskItem [] inputFiles;
ITaskItem [] outputFiles;
DateTime youngestInput, oldestOutput;
skipCompletely = false;
if (String.IsNullOrEmpty (inputs.Trim ()))
if (String.IsNullOrEmpty (inputs.Trim ())) {
return true;
}
if (String.IsNullOrEmpty (outputs.Trim ())) {
project.ParentEngine.LogError ("Target {0} has inputs but no outputs specified.", name);
@@ -178,6 +203,7 @@ namespace Microsoft.Build.BuildEngine {
}
if (inputFiles == null || inputFiles.Length == 0) {
skipCompletely = true;
reason = String.Format ("No input files were specified for target {0}, skipping.", name);
return false;
}
@@ -53,7 +53,6 @@ namespace Microsoft.Build.Tasks {
bool findRelatedFiles;
bool findSatellites;
bool findSerializationAssemblies;
string[] installedAssemblyTables;
ITaskItem[] relatedFiles;
ITaskItem[] resolvedDependencyFiles;
ITaskItem[] resolvedFiles;
@@ -626,12 +625,15 @@ namespace Microsoft.Build.Tasks {
get { return findSerializationAssemblies; }
set { findSerializationAssemblies = value; }
}
/*
public string[] InstalledAssemblyTables {
get { return installedAssemblyTables; }
set { installedAssemblyTables = value; }
}
*/
public
#if NET_4_0
ITaskItem[]
#else
string[]
#endif
InstalledAssemblyTables { get; set; }
[Output]
public ITaskItem[] RelatedFiles {
get { return relatedFiles; }
@@ -116,14 +116,14 @@ namespace Mono.Security.Protocol.Tls
scs.Add((0x00 << 0x08) | 0x09, "TLS_RSA_WITH_DES_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, false, true, 8, 8, 56, 8, 8);
// Supported exportable ciphers
scs.Add((0x00 << 0x08) | 0x03, "TLS_RSA_EXPORT_WITH_RC4_40_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 5, 16, 40, 0, 0);
scs.Add((0x00 << 0x08) | 0x06, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 16, 40, 8, 8);
scs.Add((0x00 << 0x08) | 0x08, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 8, 40, 8, 8);
scs.Add((0x00 << 0x08) | 0x60, "TLS_RSA_EXPORT_WITH_RC4_56_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
scs.Add((0x00 << 0x08) | 0x61, "TLS_RSA_EXPORT_WITH_RC2_CBC_56_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 7, 16, 56, 8, 8);
// scs.Add((0x00 << 0x08) | 0x03, "TLS_RSA_EXPORT_WITH_RC4_40_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 5, 16, 40, 0, 0);
// scs.Add((0x00 << 0x08) | 0x06, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 16, 40, 8, 8);
// scs.Add((0x00 << 0x08) | 0x08, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 8, 40, 8, 8);
// scs.Add((0x00 << 0x08) | 0x60, "TLS_RSA_EXPORT_WITH_RC4_56_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// scs.Add((0x00 << 0x08) | 0x61, "TLS_RSA_EXPORT_WITH_RC2_CBC_56_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 7, 16, 56, 8, 8);
// 56 bits but we use 64 bits because of parity (DES is really 56 bits)
scs.Add((0x00 << 0x08) | 0x62, "TLS_RSA_EXPORT_WITH_DES_CBC_56_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 8, 8, 64, 8, 8);
scs.Add((0x00 << 0x08) | 0x64, "TLS_RSA_EXPORT_WITH_RC4_56_SHA", CipherAlgorithmType.Rc4, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// scs.Add((0x00 << 0x08) | 0x62, "TLS_RSA_EXPORT_WITH_DES_CBC_56_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 8, 8, 64, 8, 8);
// scs.Add((0x00 << 0x08) | 0x64, "TLS_RSA_EXPORT_WITH_RC4_56_SHA", CipherAlgorithmType.Rc4, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// Default CipherSuite
// scs.Add(0, "TLS_NULL_WITH_NULL_NULL", CipherAlgorithmType.None, HashAlgorithmType.None, ExchangeAlgorithmType.None, true, false, 0, 0, 0, 0, 0);
@@ -195,14 +195,14 @@ namespace Mono.Security.Protocol.Tls
scs.Add((0x00 << 0x08) | 0x09, "SSL_RSA_WITH_DES_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, false, true, 8, 8, 56, 8, 8);
// Supported exportable ciphers
scs.Add((0x00 << 0x08) | 0x03, "SSL_RSA_EXPORT_WITH_RC4_40_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 5, 16, 40, 0, 0);
scs.Add((0x00 << 0x08) | 0x06, "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 16, 40, 8, 8);
scs.Add((0x00 << 0x08) | 0x08, "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 8, 40, 8, 8);
scs.Add((0x00 << 0x08) | 0x60, "SSL_RSA_EXPORT_WITH_RC4_56_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
scs.Add((0x00 << 0x08) | 0x61, "SSL_RSA_EXPORT_WITH_RC2_CBC_56_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 7, 16, 56, 8, 8);
// scs.Add((0x00 << 0x08) | 0x03, "SSL_RSA_EXPORT_WITH_RC4_40_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 5, 16, 40, 0, 0);
// scs.Add((0x00 << 0x08) | 0x06, "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 16, 40, 8, 8);
// scs.Add((0x00 << 0x08) | 0x08, "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 5, 8, 40, 8, 8);
// scs.Add((0x00 << 0x08) | 0x60, "SSL_RSA_EXPORT_WITH_RC4_56_MD5", CipherAlgorithmType.Rc4, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// scs.Add((0x00 << 0x08) | 0x61, "SSL_RSA_EXPORT_WITH_RC2_CBC_56_MD5", CipherAlgorithmType.Rc2, HashAlgorithmType.Md5, ExchangeAlgorithmType.RsaKeyX, true, true, 7, 16, 56, 8, 8);
// 56 bits but we use 64 bits because of parity (DES is really 56 bits)
scs.Add((0x00 << 0x08) | 0x62, "SSL_RSA_EXPORT_WITH_DES_CBC_56_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 8, 8, 64, 8, 8);
scs.Add((0x00 << 0x08) | 0x64, "SSL_RSA_EXPORT_WITH_RC4_56_SHA", CipherAlgorithmType.Rc4, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// scs.Add((0x00 << 0x08) | 0x62, "SSL_RSA_EXPORT_WITH_DES_CBC_56_SHA", CipherAlgorithmType.Des, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, true, 8, 8, 64, 8, 8);
// scs.Add((0x00 << 0x08) | 0x64, "SSL_RSA_EXPORT_WITH_RC4_56_SHA", CipherAlgorithmType.Rc4, HashAlgorithmType.Sha1, ExchangeAlgorithmType.RsaKeyX, true, false, 7, 16, 56, 0, 0);
// Default CipherSuite
// scs.Add(0, "SSL_NULL_WITH_NULL_NULL", CipherAlgorithmType.None, HashAlgorithmType.None, true, false, 0, 0, 0, 0, 0);
@@ -129,6 +129,7 @@ namespace Mono.Security.Protocol.Tls
HandshakeType type, byte[] buffer)
{
ClientContext context = (ClientContext)this.context;
var last = context.LastHandshakeMsg;
switch (type)
{
@@ -148,23 +149,37 @@ namespace Mono.Security.Protocol.Tls
return null;
case HandshakeType.ServerHello:
if (last != HandshakeType.HelloRequest)
break;
return new TlsServerHello(this.context, buffer);
// Optional
case HandshakeType.Certificate:
if (last != HandshakeType.ServerHello)
break;
return new TlsServerCertificate(this.context, buffer);
case HandshakeType.ServerKeyExchange:
return new TlsServerKeyExchange(this.context, buffer);
// Optional
case HandshakeType.CertificateRequest:
return new TlsServerCertificateRequest(this.context, buffer);
if (last == HandshakeType.ServerKeyExchange || last == HandshakeType.Certificate)
return new TlsServerCertificateRequest(this.context, buffer);
break;
case HandshakeType.ServerHelloDone:
return new TlsServerHelloDone(this.context, buffer);
if (last == HandshakeType.CertificateRequest || last == HandshakeType.Certificate || last == HandshakeType.ServerHello)
return new TlsServerHelloDone(this.context, buffer);
break;
case HandshakeType.Finished:
return new TlsServerFinished(this.context, buffer);
// depends if a full (ServerHelloDone) or an abbreviated handshake (ServerHello) is being done
bool check = context.AbbreviatedHandshake ? (last == HandshakeType.ServerHello) : (last == HandshakeType.ServerHelloDone);
// ChangeCipherSpecDone is not an handshake message (it's a content type) but still needs to be happens before finished
if (check && context.ChangeCipherSpecDone) {
context.ChangeCipherSpecDone = false;
return new TlsServerFinished (this.context, buffer);
}
break;
default:
throw new TlsException(
AlertDescription.UnexpectedMessage,
@@ -172,6 +187,7 @@ namespace Mono.Security.Protocol.Tls
"Unknown server handshake message received ({0})",
type.ToString()));
}
throw new TlsException (AlertDescription.HandshakeFailiure, String.Format ("Protocol error, unexpected protocol transition from {0} to {1}", last, type));
}
#endregion
@@ -122,6 +122,8 @@ namespace Mono.Security.Protocol.Tls
set { this.protocolNegotiated = value; }
}
public bool ChangeCipherSpecDone { get; set; }
public SecurityProtocolType SecurityProtocol
{
get
@@ -88,6 +88,8 @@ namespace Mono.Security.Protocol.Tls
} else {
ctx.StartSwitchingSecurityParameters (false);
}
ctx.ChangeCipherSpecDone = true;
}
public virtual HandshakeMessage GetMessage(HandshakeType type)
@@ -348,9 +350,6 @@ namespace Mono.Security.Protocol.Tls
// Try to read the Record Content Type
int type = internalResult.InitialBuffer[0];
// Set last handshake message received to None
this.context.LastHandshakeMsg = HandshakeType.ClientHello;
ContentType contentType = (ContentType)type;
byte[] buffer = this.ReadRecordBuffer(type, record);
if (buffer == null)
@@ -458,9 +457,6 @@ namespace Mono.Security.Protocol.Tls
// Try to read the Record Content Type
int type = recordTypeBuffer[0];
// Set last handshake message received to None
this.context.LastHandshakeMsg = HandshakeType.ClientHello;
ContentType contentType = (ContentType)type;
byte[] buffer = this.ReadRecordBuffer(type, record);
if (buffer == null)
@@ -523,87 +519,11 @@ namespace Mono.Security.Protocol.Tls
private byte[] ReadRecordBuffer (int contentType, Stream record)
{
switch (contentType)
{
case 0x80:
return this.ReadClientHelloV2(record);
default:
if (!Enum.IsDefined(typeof(ContentType), (ContentType)contentType))
{
throw new TlsException(AlertDescription.DecodeError);
}
return this.ReadStandardRecordBuffer(record);
}
}
private byte[] ReadClientHelloV2 (Stream record)
{
int msgLength = record.ReadByte ();
// process further only if the whole record is available
if (record.CanSeek && (msgLength + 1 > record.Length))
{
return null;
}
byte[] message = new byte[msgLength];
record.Read (message, 0, msgLength);
int msgType = message [0];
if (msgType != 1)
{
throw new TlsException(AlertDescription.DecodeError);
}
int protocol = (message [1] << 8 | message [2]);
int cipherSpecLength = (message [3] << 8 | message [4]);
int sessionIdLength = (message [5] << 8 | message [6]);
int challengeLength = (message [7] << 8 | message [8]);
int length = (challengeLength > 32) ? 32 : challengeLength;
// Read CipherSpecs
byte[] cipherSpecV2 = new byte[cipherSpecLength];
Buffer.BlockCopy (message, 9, cipherSpecV2, 0, cipherSpecLength);
// Read session ID
byte[] sessionId = new byte[sessionIdLength];
Buffer.BlockCopy (message, 9 + cipherSpecLength, sessionId, 0, sessionIdLength);
// Read challenge ID
byte[] challenge = new byte[challengeLength];
Buffer.BlockCopy (message, 9 + cipherSpecLength + sessionIdLength, challenge, 0, challengeLength);
if (challengeLength < 16 || cipherSpecLength == 0 || (cipherSpecLength % 3) != 0)
if (!Enum.IsDefined(typeof(ContentType), (ContentType)contentType))
{
throw new TlsException(AlertDescription.DecodeError);
}
// Updated the Session ID
if (sessionId.Length > 0)
{
this.context.SessionId = sessionId;
}
// Update the protocol version
this.Context.ChangeProtocol((short)protocol);
// Select the Cipher suite
this.ProcessCipherSpecV2Buffer(this.Context.SecurityProtocol, cipherSpecV2);
// Updated the Client Random
this.context.ClientRandom = new byte [32]; // Always 32
// 1. if challenge is bigger than 32 bytes only use the last 32 bytes
// 2. right justify (0) challenge in ClientRandom if less than 32
Buffer.BlockCopy (challenge, challenge.Length - length, this.context.ClientRandom, 32 - length, length);
// Set
this.context.LastHandshakeMsg = HandshakeType.ClientHello;
this.context.ProtocolNegotiated = true;
return message;
}
private byte[] ReadStandardRecordBuffer (Stream record)
{
byte[] header = new byte[4];
if (record.Read (header, 0, 4) != 4)
throw new TlsException ("buffer underrun");
@@ -1031,96 +951,5 @@ namespace Mono.Security.Protocol.Tls
}
#endregion
#region CipherSpecV2 processing
private void ProcessCipherSpecV2Buffer (SecurityProtocolType protocol, byte[] buffer)
{
TlsStream codes = new TlsStream(buffer);
string prefix = (protocol == SecurityProtocolType.Ssl3) ? "SSL_" : "TLS_";
while (codes.Position < codes.Length)
{
byte check = codes.ReadByte();
if (check == 0)
{
// SSL/TLS cipher spec
short code = codes.ReadInt16();
int index = this.Context.SupportedCiphers.IndexOf(code);
if (index != -1)
{
this.Context.Negotiating.Cipher = this.Context.SupportedCiphers[index];
break;
}
}
else
{
byte[] tmp = new byte[2];
codes.Read(tmp, 0, tmp.Length);
int tmpCode = ((check & 0xff) << 16) | ((tmp[0] & 0xff) << 8) | (tmp[1] & 0xff);
CipherSuite cipher = this.MapV2CipherCode(prefix, tmpCode);
if (cipher != null)
{
this.Context.Negotiating.Cipher = cipher;
break;
}
}
}
if (this.Context.Negotiating == null)
{
throw new TlsException(AlertDescription.InsuficientSecurity, "Insuficient Security");
}
}
private CipherSuite MapV2CipherCode(string prefix, int code)
{
try
{
switch (code)
{
case 65664:
// TLS_RC4_128_WITH_MD5
return this.Context.SupportedCiphers[prefix + "RSA_WITH_RC4_128_MD5"];
case 131200:
// TLS_RC4_128_EXPORT40_WITH_MD5
return this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC4_40_MD5"];
case 196736:
// TLS_RC2_CBC_128_CBC_WITH_MD5
return this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC2_CBC_40_MD5"];
case 262272:
// TLS_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
return this.Context.SupportedCiphers[prefix + "RSA_EXPORT_WITH_RC2_CBC_40_MD5"];
case 327808:
// TLS_IDEA_128_CBC_WITH_MD5
return null;
case 393280:
// TLS_DES_64_CBC_WITH_MD5
return null;
case 458944:
// TLS_DES_192_EDE3_CBC_WITH_MD5
return null;
default:
return null;
}
}
catch
{
return null;
}
}
#endregion
}
}
@@ -33,6 +33,8 @@ namespace Mono.Security.Protocol.Tls
{
internal class ServerRecordProtocol : RecordProtocol
{
TlsClientCertificate cert;
#region Constructors
public ServerRecordProtocol(
@@ -93,30 +95,45 @@ namespace Mono.Security.Protocol.Tls
private HandshakeMessage createClientHandshakeMessage(
HandshakeType type, byte[] buffer)
{
var last = context.LastHandshakeMsg;
switch (type)
{
case HandshakeType.ClientHello:
return new TlsClientHello(this.context, buffer);
case HandshakeType.Certificate:
return new TlsClientCertificate(this.context, buffer);
if (last != HandshakeType.ClientHello)
break;
cert = new TlsClientCertificate(this.context, buffer);
return cert;
case HandshakeType.ClientKeyExchange:
return new TlsClientKeyExchange(this.context, buffer);
if (last == HandshakeType.ClientHello || last == HandshakeType.Certificate)
return new TlsClientKeyExchange(this.context, buffer);
break;
case HandshakeType.CertificateVerify:
return new TlsClientCertificateVerify(this.context, buffer);
if (last == HandshakeType.ClientKeyExchange && cert != null)
return new TlsClientCertificateVerify(this.context, buffer);
break;
case HandshakeType.Finished:
return new TlsClientFinished(this.context, buffer);
// Certificates are optional, but if provided, they should send a CertificateVerify
bool check = (cert == null) ? (last == HandshakeType.ClientKeyExchange) : (last == HandshakeType.CertificateVerify);
// ChangeCipherSpecDone is not an handshake message (it's a content type) but still needs to be happens before finished
if (check && context.ChangeCipherSpecDone) {
context.ChangeCipherSpecDone = false;
return new TlsClientFinished(this.context, buffer);
}
break;
default:
throw new TlsException(
AlertDescription.UnexpectedMessage,
String.Format(CultureInfo.CurrentUICulture,
"Unknown server handshake message received ({0})",
type.ToString()));
throw new TlsException(AlertDescription.UnexpectedMessage, String.Format(CultureInfo.CurrentUICulture,
"Unknown server handshake message received ({0})",
type.ToString()));
break;
}
throw new TlsException (AlertDescription.HandshakeFailiure, String.Format ("Protocol error, unexpected protocol transition from {0} to {1}", last, type));
}
private HandshakeMessage createServerHandshakeMessage(
@@ -190,59 +190,15 @@ namespace Mono.Security.Protocol.Tls
this.Context.ClientWriteKey = keyBlock.ReadBytes(this.KeyMaterialSize);
this.Context.ServerWriteKey = keyBlock.ReadBytes(this.KeyMaterialSize);
if (!this.IsExportable)
if (this.IvSize != 0)
{
if (this.IvSize != 0)
{
this.Context.ClientWriteIV = keyBlock.ReadBytes(this.IvSize);
this.Context.ServerWriteIV = keyBlock.ReadBytes(this.IvSize);
}
else
{
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
this.Context.ClientWriteIV = keyBlock.ReadBytes(this.IvSize);
this.Context.ServerWriteIV = keyBlock.ReadBytes(this.IvSize);
}
else
{
HashAlgorithm md5 = MD5.Create();
int keySize = (md5.HashSize >> 3); //in bytes not bits
byte[] temp = new byte [keySize];
// Generate final write keys
md5.TransformBlock(this.Context.ClientWriteKey, 0, this.Context.ClientWriteKey.Length, temp, 0);
md5.TransformFinalBlock(this.Context.RandomCS, 0, this.Context.RandomCS.Length);
byte[] finalClientWriteKey = new byte[this.ExpandedKeyMaterialSize];
Buffer.BlockCopy(md5.Hash, 0, finalClientWriteKey, 0, this.ExpandedKeyMaterialSize);
md5.Initialize();
md5.TransformBlock(this.Context.ServerWriteKey, 0, this.Context.ServerWriteKey.Length, temp, 0);
md5.TransformFinalBlock(this.Context.RandomSC, 0, this.Context.RandomSC.Length);
byte[] finalServerWriteKey = new byte[this.ExpandedKeyMaterialSize];
Buffer.BlockCopy(md5.Hash, 0, finalServerWriteKey, 0, this.ExpandedKeyMaterialSize);
this.Context.ClientWriteKey = finalClientWriteKey;
this.Context.ServerWriteKey = finalServerWriteKey;
// Generate IV keys
if (this.IvSize > 0)
{
md5.Initialize();
temp = md5.ComputeHash(this.Context.RandomCS, 0, this.Context.RandomCS.Length);
this.Context.ClientWriteIV = new byte[this.IvSize];
Buffer.BlockCopy(temp, 0, this.Context.ClientWriteIV, 0, this.IvSize);
md5.Initialize();
temp = md5.ComputeHash(this.Context.RandomSC, 0, this.Context.RandomSC.Length);
this.Context.ServerWriteIV = new byte[this.IvSize];
Buffer.BlockCopy(temp, 0, this.Context.ServerWriteIV, 0, this.IvSize);
}
else
{
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
DebugHelper.WriteLine(">>>> KeyBlock", keyBlock.ToArray());
@@ -588,14 +588,19 @@ namespace Mono.Security.Protocol.Tls
}
catch (TlsException ex)
{
// FIXME: should the send alert also be done asynchronously here and below?
this.protocol.SendAlert(ex.Alert);
negotiate.SetComplete (new IOException("The authentication or decryption has failed.", ex));
try {
this.protocol.SendAlert(ex.Alert != null ? ex.Alert : new Alert (AlertDescription.InternalError));
} catch {
}
negotiate.SetComplete(new IOException("The authentication or decryption has failed.", ex));
}
catch (Exception ex)
{
this.protocol.SendAlert(AlertDescription.InternalError);
negotiate.SetComplete (new IOException("The authentication or decryption has failed.", ex));
try {
this.protocol.SendAlert(AlertDescription.InternalError);
} catch {
}
negotiate.SetComplete(new IOException("The authentication or decryption has failed.", ex));
}
}
@@ -233,16 +233,8 @@ namespace Mono.Security.Protocol.Tls
// Send ServerCertificate message
this.protocol.SendRecord(HandshakeType.Certificate);
// If the negotiated cipher is a KeyEx cipher send ServerKeyExchange
if (this.context.Negotiating.Cipher.IsExportable)
{
this.protocol.SendRecord(HandshakeType.ServerKeyExchange);
}
// If the negotiated cipher is a KeyEx cipher or
// the client certificate is required send the CertificateRequest message
if (this.context.Negotiating.Cipher.IsExportable ||
((ServerContext)this.context).ClientCertificateRequired ||
// If the client certificate is required send the CertificateRequest message
if (((ServerContext)this.context).ClientCertificateRequired ||
((ServerContext)this.context).RequestClientCertificate)
{
this.protocol.SendRecord(HandshakeType.CertificateRequest);
@@ -123,45 +123,15 @@ namespace Mono.Security.Protocol.Tls
this.Context.ClientWriteKey = keyBlock.ReadBytes(this.KeyMaterialSize);
this.Context.ServerWriteKey = keyBlock.ReadBytes(this.KeyMaterialSize);
if (!this.IsExportable)
if (this.IvSize != 0)
{
if (this.IvSize != 0)
{
this.Context.ClientWriteIV = keyBlock.ReadBytes(this.IvSize);
this.Context.ServerWriteIV = keyBlock.ReadBytes(this.IvSize);
}
else
{
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
this.Context.ClientWriteIV = keyBlock.ReadBytes(this.IvSize);
this.Context.ServerWriteIV = keyBlock.ReadBytes(this.IvSize);
}
else
{
// Generate final write keys
byte[] finalClientWriteKey = PRF(this.Context.ClientWriteKey, "client write key", this.Context.RandomCS, this.ExpandedKeyMaterialSize);
byte[] finalServerWriteKey = PRF(this.Context.ServerWriteKey, "server write key", this.Context.RandomCS, this.ExpandedKeyMaterialSize);
this.Context.ClientWriteKey = finalClientWriteKey;
this.Context.ServerWriteKey = finalServerWriteKey;
if (this.IvSize > 0)
{
// Generate IV block
byte[] ivBlock = PRF(CipherSuite.EmptyArray, "IV block", this.Context.RandomCS, this.IvSize*2);
// Generate IV keys
this.Context.ClientWriteIV = new byte[this.IvSize];
Buffer.BlockCopy(ivBlock, 0, this.Context.ClientWriteIV, 0, this.Context.ClientWriteIV.Length);
this.Context.ServerWriteIV = new byte[this.IvSize];
Buffer.BlockCopy(ivBlock, this.IvSize, this.Context.ServerWriteIV, 0, this.Context.ServerWriteIV.Length);
}
else
{
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
this.Context.ClientWriteIV = CipherSuite.EmptyArray;
this.Context.ServerWriteIV = CipherSuite.EmptyArray;
}
DebugHelper.WriteLine(">>>> KeyBlock", keyBlock.ToArray());
@@ -64,12 +64,15 @@ namespace System {
[DllImport ("__Internal")]
extern static IntPtr monotouch_timezone_get_data (string name, ref int size);
static Stream GetMonoTouchData (string name)
static Stream GetMonoTouchData (string name, bool throw_on_error = true)
{
int size = 0;
IntPtr data = monotouch_timezone_get_data (name, ref size);
if (size <= 0)
throw new TimeZoneNotFoundException ();
if (size <= 0) {
if (throw_on_error)
throw new TimeZoneNotFoundException ();
return null;
}
unsafe {
var s = new UnmanagedMemoryStream ((byte*) data, size);
+3 -1
View File
@@ -651,7 +651,9 @@ namespace System
#elif MONOTOUCH
if (systemTimeZones.Count == 0) {
foreach (string name in GetMonoTouchNames ()) {
using (Stream stream = GetMonoTouchData (name)) {
using (Stream stream = GetMonoTouchData (name, false)) {
if (stream == null)
continue;
systemTimeZones.Add (BuildFromStream (name, stream));
}
}
@@ -225,6 +225,7 @@ sqliteDataAdapter.Update (dataSet, "Primus");
}
[Test]
[Category ("NotWorking")] // Requires newer sqlite than is on wrench
public void UpdateResetRowErrorCorrectly ()
{
const string connectionString = "URI = file::memory:; Version = 3";
@@ -306,6 +306,8 @@ namespace System.Net.Http
item_headers.TryAddWithoutValidation (key, value);
}
requestMessage.RequestUri = wr.ResponseUri;
return response;
}
@@ -800,6 +800,30 @@ namespace MonoTests.System.Net.Http
}
}
[Test]
public void RequestUriAfterRedirect ()
{
var listener = CreateListener (l => {
var request = l.Request;
var response = l.Response;
response.StatusCode = (int)HttpStatusCode.Moved;
response.RedirectLocation = "http://xamarin.com/";
});
try {
var chandler = new HttpClientHandler ();
chandler.AllowAutoRedirect = true;
var client = new HttpClient (chandler);
var resp = client.GetAsync (LocalServer).Result;
Assert.AreEqual ("http://xamarin.com/", resp.RequestMessage.RequestUri.AbsoluteUri, "#1");
} finally {
listener.Abort ();
listener.Close ();
}
}
[Test]
/*
* Properties may only be modified before sending the first request.
@@ -336,7 +336,13 @@ namespace System {
if (ch == '%'){
if (!Uri.IsHexEncoding (part, index))
return false;
var oldIndex = index;
ch = Uri.HexUnescape (part, ref index);
index--;
if (ch == '@') {
sb.Append (part.Substring (oldIndex, index - oldIndex + 1));
continue;
}
}
if (Char.IsLetterOrDigit (ch) || IsUnreserved (ch) || IsSubDelim (ch) || ch == ':'){
+18
View File
@@ -0,0 +1,18 @@
// CS0171: Field `S1.s2' must be fully assigned before control leaves the constructor
// Line: 11
using System;
struct S1
{
S2 s2;
public S1 (int arg)
{
}
}
struct S2
{
int field;
}
-26
View File
@@ -1,26 +0,0 @@
// CS0429: Unreachable expression code detected
// Line: 24
// Compiler options: -warnaserror
using System;
struct S
{
}
class C
{
public static implicit operator S (C c)
{
return new S ();
}
}
class Program
{
static void Main ()
{
C c = new C ();
Console.WriteLine (c ?? new S ());
}
}
+11
View File
@@ -0,0 +1,11 @@
// CS0677: `X.e': A volatile field cannot be of the type `E'
// Line: 10
enum E : long
{
}
class X
{
volatile E e;
}
+6 -2
View File
@@ -1792,8 +1792,12 @@ namespace Mono.CSharp {
// this argument is generated during compilation which speeds up dispatch
// by about 25%
//
method_parameters = ParametersCompiled.Prefix (method_parameters,
new Parameter (null, null, 0, null, loc), ec.Module.Compiler.BuiltinTypes.Object);
//
// Disabled for now due to JIT bug
//
//method_parameters = ParametersCompiled.Prefix (method_parameters,
// new Parameter (null, null, 0, null, loc), ec.Module.Compiler.BuiltinTypes.Object);
}
if (storey == null && hoisted_tparams == null)
+5 -9
View File
@@ -44,7 +44,6 @@ namespace Mono.CSharp
public abstract class TypeContainer : MemberCore
{
public readonly MemberKind Kind;
public readonly string Basename;
protected List<TypeContainer> containers;
@@ -62,9 +61,6 @@ namespace Mono.CSharp
: base (parent, name, attrs)
{
this.Kind = kind;
if (name != null)
this.Basename = name.Basename;
defined_names = new Dictionary<string, MemberCore> ();
}
@@ -111,7 +107,7 @@ namespace Mono.CSharp
public virtual void AddPartial (TypeDefinition next_part)
{
MemberCore mc;
(PartialContainer ?? this).defined_names.TryGetValue (next_part.Basename, out mc);
(PartialContainer ?? this).defined_names.TryGetValue (next_part.MemberName.Basename, out mc);
AddPartial (next_part, mc as TypeDefinition);
}
@@ -380,7 +376,7 @@ namespace Mono.CSharp
containers.Remove (cont);
var tc = Parent == Module ? Module : this;
tc.defined_names.Remove (cont.Basename);
tc.defined_names.Remove (cont.MemberName.Basename);
}
public virtual void VerifyMembers ()
@@ -772,7 +768,7 @@ namespace Mono.CSharp
public override void AddTypeContainer (TypeContainer tc)
{
AddNameToContainer (tc, tc.Basename);
AddNameToContainer (tc, tc.MemberName.Basename);
base.AddTypeContainer (tc);
}
@@ -1295,7 +1291,7 @@ namespace Mono.CSharp
CreateMetadataName (sb);
TypeBuilder = Module.CreateBuilder (sb.ToString (), TypeAttr, type_size);
} else {
TypeBuilder = parent_def.TypeBuilder.DefineNestedType (Basename, TypeAttr, null, type_size);
TypeBuilder = parent_def.TypeBuilder.DefineNestedType (MemberName.Basename, TypeAttr, null, type_size);
}
if (DeclaringAssembly.Importer != null)
@@ -1795,7 +1791,7 @@ namespace Mono.CSharp
{
base.RemoveContainer (cont);
Members.Remove (cont);
Cache.Remove (cont.Basename);
Cache.Remove (cont.MemberName.Basename);
}
protected virtual bool DoResolveTypeParameters ()
+10 -2
View File
@@ -1268,6 +1268,7 @@ namespace Mono.CSharp
int next_token;
int parens = 0;
int generics = 0;
int brackets = 0;
var nt = xtoken ();
switch (nt) {
@@ -1319,7 +1320,6 @@ namespace Mono.CSharp
case Token.COMMA:
case Token.SEMICOLON:
case Token.OPEN_BRACE:
case Token.CLOSE_PARENS:
case Token.IN:
next_token = Token.INTERR_NULLABLE;
break;
@@ -1334,6 +1334,15 @@ namespace Mono.CSharp
++parens;
goto default;
case Token.OPEN_BRACKET:
case Token.OPEN_BRACKET_EXPR:
++brackets;
goto default;
case Token.CLOSE_PARENS:
--parens;
goto default;
case Token.OP_GENERICS_LT:
case Token.OP_GENERICS_LT_DECL:
case Token.GENERIC_DIMENSION:
@@ -1345,7 +1354,6 @@ namespace Mono.CSharp
int interrs = 1;
int colons = 0;
int braces = 0;
int brackets = 0;
//
// All shorcuts failed, do it hard way
//
-5
View File
@@ -195,11 +195,6 @@ namespace Mono.CSharp {
return name + "`" + args.Count;
}
public static string MakeName (string name, int count)
{
return name + "`" + count;
}
}
public class SimpleMemberName
+1 -1
View File
@@ -1277,7 +1277,7 @@ namespace Mono.CSharp
if (current_container.Containers != null)
{
var existing = current_container.Containers.FirstOrDefault (l => l.Basename == tc.Basename);
var existing = current_container.Containers.FirstOrDefault (l => l.MemberName.Basename == tc.MemberName.Basename);
if (existing != null) {
current_container.RemoveContainer (existing);
undo_actions.Add (() => current_container.AddTypeContainer (existing));
+3
View File
@@ -10530,6 +10530,9 @@ namespace Mono.CSharp
get {
return source;
}
set {
source = value;
}
}
public override bool ContainsEmitWithAwait ()
+15 -1
View File
@@ -605,9 +605,23 @@ namespace Mono.CSharp
if (TypeSpec.IsReferenceType (MemberType))
return true;
if (MemberType.IsEnum)
if (MemberType.IsPointer)
return true;
if (MemberType.IsEnum) {
switch (EnumSpec.GetUnderlyingType (MemberType).BuiltinType) {
case BuiltinTypeSpec.Type.SByte:
case BuiltinTypeSpec.Type.Byte:
case BuiltinTypeSpec.Type.Short:
case BuiltinTypeSpec.Type.UShort:
case BuiltinTypeSpec.Type.Int:
case BuiltinTypeSpec.Type.UInt:
return true;
default:
return false;
}
}
return false;
}
-8
View File
@@ -697,14 +697,6 @@ namespace Mono.CSharp {
if ((name_entry.Modifiers & Modifiers.STATIC) != 0)
continue;
//
// Ignore user private fields for definite assignment. This is sort of unexpected but
// rationale is to have consistent results when using reference assemblies which don't
// include any private fields and full assemblies
//
if ((name_entry.Modifiers & (Modifiers.PRIVATE | Modifiers.BACKING_FIELD)) == Modifiers.PRIVATE)
continue;
//
// Fixed size buffers are not subject to definite assignment checking
//
+3 -4
View File
@@ -488,8 +488,8 @@ namespace Mono.CSharp {
public void RemoveContainer (TypeContainer tc)
{
types.Remove (tc.Basename);
cached_types.Remove (tc.Basename);
types.Remove (tc.MemberName.Basename);
cached_types.Remove (tc.MemberName.Basename);
}
public void SetBuiltinType (BuiltinTypeSpec pts)
@@ -790,9 +790,8 @@ namespace Mono.CSharp {
public override void AddTypeContainer (TypeContainer tc)
{
string name = tc.Basename;
var mn = tc.MemberName;
var name = mn.Basename;
while (mn.Left != null) {
mn = mn.Left;
name = mn.Name;
+43 -13
View File
@@ -1220,12 +1220,6 @@ namespace Mono.CSharp.Nullable
return ReducedExpression.Create (right, this, false).Resolve (ec);
left = Convert.ImplicitConversion (ec, unwrap ?? left, rtype, loc);
if (TypeSpec.IsValueType (left.Type) && !left.Type.IsNullableType) {
Warning_UnreachableExpression (ec, right.Location);
return ReducedExpression.Create (left, this, false).Resolve (ec);
}
type = rtype;
return this;
}
@@ -1285,16 +1279,52 @@ namespace Mono.CSharp.Nullable
return;
}
left.Emit (ec);
ec.Emit (OpCodes.Dup);
//
// Null check is done on original expression not after expression is converted to
// result type. This is in most cases same but when user conversion is involved
// we can end up in situation when use operator does the null handling which is
// not what the operator is supposed to do
//
var op_expr = left as UserCast;
if (op_expr != null) {
op_expr.Source.Emit (ec);
LocalTemporary temp;
// Only to make verifier happy
if (left.Type.IsGenericParameter)
ec.Emit (OpCodes.Box, left.Type);
// TODO: More load kinds can be special cased
if (!(op_expr.Source is VariableReference)) {
temp = new LocalTemporary (op_expr.Source.Type);
temp.Store (ec);
temp.Emit (ec);
op_expr.Source = temp;
} else {
temp = null;
}
ec.Emit (OpCodes.Brtrue, end_label);
var right_label = ec.DefineLabel ();
ec.Emit (OpCodes.Brfalse_S, right_label);
left.Emit (ec);
ec.Emit (OpCodes.Br, end_label);
ec.MarkLabel (right_label);
if (temp != null)
temp.Release (ec);
} else {
//
// Common case where expression is not modified before null check and
// we generate better/smaller code
//
left.Emit (ec);
ec.Emit (OpCodes.Dup);
// Only to make verifier happy
if (left.Type.IsGenericParameter)
ec.Emit (OpCodes.Box, left.Type);
ec.Emit (OpCodes.Brtrue, end_label);
ec.Emit (OpCodes.Pop);
}
ec.Emit (OpCodes.Pop);
right.Emit (ec);
ec.MarkLabel (end_label);
+10
View File
@@ -150,6 +150,16 @@ public class ConditionalParsing
}
}
void Test_18 (bool b, Action a)
{
var e = b ? () => { } : a;
}
void Test_19 (int[,] table)
{
var x = 1 > 0 ? table[5, 1] : 0;
}
static void Helper<T> (T arg)
{
}
+7
View File
@@ -1,3 +1,4 @@
// Compiler options: -unsafe
//
// Tests the valid value types for volatile fields.
//
@@ -11,6 +12,9 @@ enum XX {
A
}
struct S {
}
class X {
volatile byte a;
volatile sbyte b;
@@ -26,6 +30,9 @@ class X {
volatile XX dd;
volatile IntPtr ip;
volatile UIntPtr uip;
unsafe volatile ushort* uc;
unsafe volatile XX* udd;
unsafe volatile S* us;
public static void Main () {}
}
-24
View File
@@ -1,24 +0,0 @@
using System;
// C#6 change
struct S1
{
S2 s2;
public S1 (int arg)
{
}
}
struct S2
{
int field;
}
class X
{
public static void Main ()
{
}
}
+20 -1
View File
@@ -6,17 +6,36 @@ struct S
class C
{
public static int ConversionCalled;
public static implicit operator S (C c)
{
++ConversionCalled;
return new S ();
}
}
class Program
{
static void Main ()
static C field;
static int Main ()
{
C c = new C ();
var x = c ?? new S ();
if (C.ConversionCalled != 1)
return 1;
c = null;
x = c ?? new S ();
if (C.ConversionCalled != 1)
return 2;
x = field ?? new S ();
if (C.ConversionCalled != 1)
return 3;
return 0;
}
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Reflection;
class CorrectEncodingOfNestedTypes
{
static async Task<T> GetAsync<T>(string s) where T : new()
{
return await Task.Factory.StartNew(async () => {
var response = await Task.FromResult (s);
return (T)new object();
}).Unwrap();
}
public static int Main ()
{
var t = typeof (CorrectEncodingOfNestedTypes).GetNestedTypes (BindingFlags.NonPublic) [0].GetNestedTypes (BindingFlags.NonPublic) [0];
var m = t.GetMethods (BindingFlags.NonPublic | BindingFlags.Instance) [0];
var ca = (AsyncStateMachineAttribute) m.GetCustomAttributes (true) [0];
if (ca.StateMachineType.GetGenericArguments ().Length != 1)
return 1;
return 0;
}
}
File diff suppressed because it is too large. Load diff
@@ -340,10 +340,4 @@ endif
endif
EXTRA_DIST = make-bundle.pl sample-bundle $(win32_sources) $(unix_sources) $(null_sources) runtime.h \
tpool-poll.c tpool-epoll.c tpool-kqueue.c Makefile.am.in
if HAS_EXTENSION_MODULE
else
Makefile.am: Makefile.am.in
cp $< $@
endif
tpool-poll.c tpool-epoll.c tpool-kqueue.c
+1
View File
@@ -175,6 +175,7 @@ typedef struct
typedef struct
{
guint32 stack_size;
guint32 epilog_size;
} MonoArchEHJitInfo;
typedef struct {
+9
View File
@@ -138,6 +138,9 @@ static const MonoRuntimeInfo supported_runtimes[] = {
static MonoCreateDomainFunc create_domain_hook;
static MonoFreeDomainFunc free_domain_hook;
/* AOT cache configuration */
static MonoAotCacheConfig aot_cache_config;
/* This is intentionally not in the header file, so people don't misuse it. */
extern void _mono_debug_init_corlib (MonoDomain *domain);
@@ -2776,3 +2779,9 @@ mono_enable_debug_domain_unload (gboolean enable)
{
debug_domain_unload = enable;
}
MonoAotCacheConfig *
mono_get_aot_cache_config (void)
{
return &aot_cache_config;
}
+12
View File
@@ -2266,6 +2266,18 @@ mono_stack_walk_no_il (MonoStackWalk func, gpointer user_data)
mono_get_eh_callbacks ()->mono_walk_stack_with_ctx (stack_walk_adapter, NULL, MONO_UNWIND_DEFAULT, &ud);
}
/*
* mono_stack_walk_async_safe:
*
* Async safe version callable from signal handlers.
*/
void
mono_stack_walk_async_safe (MonoStackWalk func, gpointer user_data)
{
StackWalkUserData ud = { func, user_data };
mono_get_eh_callbacks ()->mono_walk_stack_with_ctx (stack_walk_adapter, NULL, MONO_UNWIND_NONE, &ud);
}
static gboolean
last_managed (MonoMethod *m, gint no, gint ilo, gboolean managed, gpointer data)
{
+3
View File
@@ -90,6 +90,9 @@ mono_stack_walk (MonoStackWalk func, void* user_data);
MONO_API void
mono_stack_walk_no_il (MonoStackWalk func, void* user_data);
MONO_API void
mono_stack_walk_async_safe (MonoStackWalk func, void* user_data);
MONO_END_DECLS
#endif
+15
View File
@@ -523,6 +523,19 @@ struct _MonoMethodSignature {
MonoType *params [MONO_ZERO_LEN_ARRAY];
};
/*
* AOT cache configuration loaded from config files.
* Doesn't really belong here.
*/
typedef struct {
/*
* Enable aot caching for applications whose main assemblies are in
* this list.
*/
GSList *apps;
GSList *assemblies;
} MonoAotCacheConfig;
#define MONO_SIZEOF_METHOD_SIGNATURE (sizeof (struct _MonoMethodSignature) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
static inline gboolean
@@ -785,5 +798,7 @@ MonoMethod *mono_get_method_constrained_with_method (MonoImage *image, MonoMetho
void mono_type_set_alignment (MonoTypeEnum type, int align) MONO_INTERNAL;
MonoAotCacheConfig *mono_get_aot_cache_config (void) MONO_INTERNAL;
#endif /* __MONO_METADATA_INTERNALS_H__ */
+49 -1
View File
@@ -357,6 +357,54 @@ legacyUEP_handler = {
NULL, /* finish */
};
static void
aot_cache_start (gpointer user_data,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values)
{
int i;
MonoAotCacheConfig *config;
if (strcmp (element_name, "aotcache") != 0)
return;
config = mono_get_aot_cache_config ();
/* Per-app configuration */
for (i = 0; attribute_names [i]; ++i) {
if (!strcmp (attribute_names [i], "app")) {
config->apps = g_slist_prepend (config->apps, g_strdup (attribute_values [i]));
return;
}
}
/* Global configuration */
for (i = 0; attribute_names [i]; ++i) {
if (!strcmp (attribute_names [i], "assemblies")) {
char **parts, **ptr;
char *part;
parts = g_strsplit (attribute_values [i], " ", -1);
for (ptr = parts; ptr && *ptr; ptr ++) {
part = *ptr;
config->assemblies = g_slist_prepend (config->assemblies, g_strdup (part));
}
g_strfreev (parts);
}
}
}
static const MonoParseHandler
aot_cache_handler = {
"aotcache",
NULL, /* init */
aot_cache_start,
NULL, /* text */
NULL, /* end */
NULL, /* finish */
};
static int inited = 0;
static void
@@ -366,6 +414,7 @@ mono_config_init (void)
config_handlers = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (config_handlers, (gpointer) dllmap_handler.element_name, (gpointer) &dllmap_handler);
g_hash_table_insert (config_handlers, (gpointer) legacyUEP_handler.element_name, (gpointer) &legacyUEP_handler);
g_hash_table_insert (config_handlers, (gpointer) aot_cache_handler.element_name, (gpointer) &aot_cache_handler);
}
void
@@ -407,7 +456,6 @@ mono_config_parse_file_with_context (ParseState *state, const char *filename)
if (!g_file_get_contents (filename, &text, &len, NULL))
return 0;
offset = 0;
if (len > 3 && text [0] == '\xef' && text [1] == (gchar) '\xbb' && text [2] == '\xbf')
offset = 3; /* Skip UTF-8 BOM */
+43 -5
View File
@@ -7501,14 +7501,52 @@ mono_reflection_get_type_internal (MonoImage *rootimage, MonoImage* image, MonoT
mono_class_init (parent);
while ((klass = mono_class_get_nested_types (parent, &iter))) {
if (ignorecase) {
if (mono_utf8_strcasecmp (klass->name, mod->data) == 0)
break;
char *lastp;
char *nested_name, *nested_nspace;
gboolean match = TRUE;
lastp = strrchr (mod->data, '.');
if (lastp) {
/* Nested classes can have namespaces */
int nspace_len;
nested_name = g_strdup (lastp + 1);
nspace_len = lastp - (char*)mod->data;
nested_nspace = g_malloc (nspace_len + 1);
memcpy (nested_nspace, mod->data, nspace_len);
nested_nspace [nspace_len] = '\0';
} else {
if (strcmp (klass->name, mod->data) == 0)
break;
nested_name = mod->data;
nested_nspace = NULL;
}
if (nested_nspace) {
if (ignorecase) {
if (!(klass->name_space && mono_utf8_strcasecmp (klass->name_space, nested_nspace) == 0))
match = FALSE;
} else {
if (!(klass->name_space && strcmp (klass->name_space, nested_nspace) == 0))
match = FALSE;
}
}
if (match) {
if (ignorecase) {
if (mono_utf8_strcasecmp (klass->name, nested_name) != 0)
match = FALSE;
} else {
if (strcmp (klass->name, nested_name) != 0)
match = FALSE;
}
}
if (lastp) {
g_free (nested_name);
g_free (nested_nspace);
}
if (match)
break;
}
if (!klass)
break;
}
+2 -2
View File
@@ -3835,11 +3835,11 @@ sgen_thread_register (SgenThreadInfo* info, void *addr)
binary_protocol_thread_register ((gpointer)mono_thread_info_get_tid (info));
/* On win32, stack_start_limit should be 0, since the stack can grow dynamically */
#ifndef HOST_WIN32
mono_thread_info_get_stack_bounds (&staddr, &stsize);
#endif
if (staddr) {
#ifndef HOST_WIN32
info->stack_start_limit = staddr;
#endif
info->stack_end = staddr + stsize;
} else {
gsize stack_bottom = (gsize)addr;
+2 -12
View File
@@ -5333,18 +5333,7 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
encoded = mono_unwind_ops_encode (cfg->unwind_ops, &encoded_len);
unwind_desc = get_unwind_info_offset (acfg, encoded, encoded_len);
g_assert (unwind_desc < 0xffff);
if (cfg->has_unwind_info_for_epilog) {
/*
* The lower 16 bits identify the unwind descriptor, the upper 16 bits contain the offset of
* the start of the epilog from the end of the method.
*/
g_assert (cfg->code_size - cfg->epilog_begin < 0xffff);
encode_value (((cfg->code_size - cfg->epilog_begin) << 16) | unwind_desc, p, &p);
g_free (encoded);
} else {
encode_value (unwind_desc, p, &p);
}
encode_value (unwind_desc, p, &p);
} else {
encode_value (jinfo->unwind_info, p, &p);
}
@@ -5443,6 +5432,7 @@ emit_exception_debug_info (MonoAotCompile *acfg, MonoCompile *cfg)
eh_info = mono_jit_info_get_arch_eh_info (jinfo);
encode_value (eh_info->stack_size, p, &p);
encode_value (eh_info->epilog_size, p, &p);
}
if (jinfo->has_generic_jit_info) {
+260 -106
View File
@@ -55,12 +55,17 @@
#include <mono/utils/mono-mmap.h>
#include "mono/utils/mono-compiler.h"
#include <mono/utils/mono-counters.h>
#include <mono/utils/mono-digest.h>
#include "mini.h"
#include "version.h"
#ifndef DISABLE_AOT
#ifdef TARGET_OSX
#define ENABLE_AOT_CACHE
#endif
#ifdef TARGET_WIN32
#define SHARED_EXT ".dll"
#elif ((defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__)) || defined(__MACH__)) && !defined(__linux__)
@@ -167,15 +172,11 @@ static GHashTable *ji_to_amodule;
/*
* Whenever to AOT compile loaded assemblies on demand and store them in
* a cache under $HOME/.mono/aot-cache.
* a cache.
*/
static gboolean use_aot_cache = FALSE;
static gboolean enable_aot_cache = FALSE;
/*
* Whenever to spawn a new process to AOT a file or do it in-process. Only relevant if
* use_aot_cache is TRUE.
*/
static gboolean spawn_compiler = TRUE;
static gboolean mscorlib_aot_loaded;
/* For debugging */
static gint32 mono_last_aot_method = -1;
@@ -243,7 +244,7 @@ load_image (MonoAotModule *amodule, int index, gboolean set_error)
assembly = mono_assembly_load (&amodule->image_names [index], amodule->assembly->basedir, &status);
if (!assembly) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable because dependency %s is not found.\n", amodule->aot_name, amodule->image_names [index].name);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: module %s is unusable because dependency %s is not found.\n", amodule->aot_name, amodule->image_names [index].name);
amodule->out_of_date = TRUE;
if (set_error) {
@@ -255,7 +256,7 @@ load_image (MonoAotModule *amodule, int index, gboolean set_error)
}
if (strcmp (assembly->image->guid, amodule->image_guids [index])) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable (GUID of dependent assembly %s doesn't match (expected '%s', got '%s').\n", amodule->aot_name, amodule->image_names [index].name, amodule->image_guids [index], assembly->image->guid);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: module %s is unusable (GUID of dependent assembly %s doesn't match (expected '%s', got '%s').\n", amodule->aot_name, amodule->image_names [index].name, amodule->image_guids [index], assembly->image->guid);
amodule->out_of_date = TRUE;
return NULL;
}
@@ -1272,132 +1273,270 @@ decode_resolve_method_ref (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
return decode_resolve_method_ref_with_target (module, NULL, buf, endbuf);
}
#ifdef ENABLE_AOT_CACHE
/* AOT CACHE */
/*
* FIXME:
* - Add options for controlling the cache size
* - Handle full cache by deleting old assemblies lru style
* - Maybe add a threshold after an assembly is AOT compiled
* - Add options for enabling this for specific main assemblies
*/
/* The cache directory */
static char *cache_dir;
/* The number of assemblies AOTed in this run */
static int cache_count;
/* Whenever to AOT in-process */
static gboolean in_process;
static void
create_cache_structure (void)
collect_assemblies (gpointer data, gpointer user_data)
{
const char *home;
char *tmp;
int err;
MonoAssembly *ass = data;
GSList **l = user_data;
home = g_get_home_dir ();
if (!home)
*l = g_slist_prepend (*l, ass);
}
#define SHA1_DIGEST_LENGTH 20
/*
* get_aot_config_hash:
*
* Return a hash for all the version information an AOT module depends on.
*/
static G_GNUC_UNUSED char*
get_aot_config_hash (MonoAssembly *assembly)
{
char *build_info;
GSList *l, *assembly_list = NULL;
GString *s;
int i;
guint8 digest [SHA1_DIGEST_LENGTH];
char *digest_str;
build_info = mono_get_runtime_build_info ();
s = g_string_new (build_info);
mono_assembly_foreach (collect_assemblies, &assembly_list);
/*
* The assembly list includes the current assembly as well, no need
* to add it.
*/
for (l = assembly_list; l; l = l->next) {
MonoAssembly *ass = l->data;
g_string_append (s, "_");
g_string_append (s, ass->aname.name);
g_string_append (s, "_");
g_string_append (s, ass->image->guid);
}
for (i = 0; i < s->len; ++i) {
if (!isalnum (s->str [i]) && s->str [i] != '-')
s->str [i] = '_';
}
mono_sha1_get_digest ((guint8*)s->str, s->len, digest);
digest_str = g_malloc0 ((SHA1_DIGEST_LENGTH * 2) + 1);
for (i = 0; i < SHA1_DIGEST_LENGTH; ++i)
sprintf (digest_str + (i * 2), "%02x", digest [i]);
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT: file dependencies: %s, hash %s", s->str, digest_str);
g_string_free (s, TRUE);
return digest_str;
}
static void
aot_cache_init (void)
{
if (mono_aot_only)
return;
tmp = g_build_filename (home, ".mono", NULL);
if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT creating directory %s", tmp);
#ifdef HOST_WIN32
err = mkdir (tmp);
#else
err = mkdir (tmp, 0777);
#endif
if (err) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT failed: %s", g_strerror (errno));
g_free (tmp);
return;
}
}
g_free (tmp);
tmp = g_build_filename (home, ".mono", "aot-cache", NULL);
if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT creating directory %s", tmp);
#ifdef HOST_WIN32
err = mkdir (tmp);
#else
err = mkdir (tmp, 0777);
#endif
if (err) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT failed: %s", g_strerror (errno));
g_free (tmp);
return;
}
}
g_free (tmp);
enable_aot_cache = TRUE;
in_process = TRUE;
}
/*
* load_aot_module_from_cache:
* aot_cache_load_module:
*
* Experimental code to AOT compile loaded assemblies on demand.
*
* FIXME:
* - Add environment variable MONO_AOT_CACHE_OPTIONS
* - Add options for controlling the cache size
* - Handle full cache by deleting old assemblies lru style
* - Add options for excluding assemblies during development
* - Maybe add a threshold after an assembly is AOT compiled
* - invoking a new mono process is a security risk
* - recompile the AOT module if one of its dependencies changes
* Load the AOT image corresponding to ASSEMBLY from the aot cache, AOTing it if neccessary.
*/
static MonoDl*
load_aot_module_from_cache (MonoAssembly *assembly, char **aot_name)
aot_cache_load_module (MonoAssembly *assembly, char **aot_name)
{
char *fname, *cmd, *tmp2, *aot_options;
MonoAotCacheConfig *config;
GSList *l;
char *fname, *tmp2, *aot_options;
const char *home;
MonoDl *module;
gboolean res;
gchar *out, *err;
gint exit_status;
char *hash;
int pid;
gboolean enabled;
*aot_name = NULL;
if (image_is_dynamic (assembly->image))
return NULL;
create_cache_structure ();
/* Check in the list of assemblies enabled for aot caching */
config = mono_get_aot_cache_config ();
home = g_get_home_dir ();
enabled = FALSE;
if (config->apps) {
MonoDomain *domain = mono_domain_get ();
MonoAssembly *entry_assembly = domain->entry_assembly;
tmp2 = g_strdup_printf ("%s-%s%s", assembly->image->assembly_name, assembly->image->guid, SHARED_EXT);
fname = g_build_filename (home, ".mono", "aot-cache", tmp2, NULL);
for (l = config->apps; l; l = l->next) {
char *n = l->data;
if ((entry_assembly && !strcmp (entry_assembly->aname.name, n)) || (!entry_assembly && !strcmp (assembly->aname.name, n)))
break;
}
if (l)
enabled = TRUE;
}
if (!enabled) {
for (l = config->assemblies; l; l = l->next) {
char *n = l->data;
if (!strcmp (assembly->aname.name, n))
break;
}
if (l)
enabled = TRUE;
}
if (!enabled)
return NULL;
if (!cache_dir) {
home = g_get_home_dir ();
if (!home)
return NULL;
cache_dir = g_strdup_printf ("%s/Library/Caches/mono/aot-cache", home);
if (!g_file_test (cache_dir, G_FILE_TEST_EXISTS|G_FILE_TEST_IS_DIR))
g_mkdir_with_parents (cache_dir, 0777);
}
/*
* The same assembly can be used in multiple configurations, i.e. multiple
* versions of the runtime, with multiple versions of dependent assemblies etc.
* To handle this, we compute a version string containing all this information, hash it,
* and use the hash as a filename suffix.
*/
hash = get_aot_config_hash (assembly);
tmp2 = g_strdup_printf ("%s-%s%s", assembly->image->assembly_name, hash, SHARED_EXT);
fname = g_build_filename (cache_dir, tmp2, NULL);
*aot_name = fname;
g_free (tmp2);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT trying to load from cache: '%s'.", fname);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: loading from cache: '%s'.", fname);
module = mono_dl_open (fname, MONO_DL_LAZY, NULL);
if (!module) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT not found.");
if (module)
return module;
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT precompiling assembly '%s'... ", assembly->image->name);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: not found.");
if (!strcmp (assembly->aname.name, "mscorlib") && !mono_defaults.corlib)
/* Can't AOT this during startup */
return NULL;
/* Only AOT one assembly per run to avoid slowing down execution too much */
if (cache_count > 0)
return NULL;
cache_count ++;
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT: compiling assembly '%s'... ", assembly->image->name);
/*
* We need to invoke the AOT compiler here. There are multiple approaches:
* - spawn a new runtime process. This can be hard when running with mkbundle, and
* its hard to make the new process load the same set of assemblies.
* - doing it in-process. This exposes the current process to bugs/leaks/side effects of
* the AOT compiler.
* - fork a new process and do the work there.
*/
if (in_process) {
FILE *logfile;
char *logfile_name;
logfile_name = g_strdup_printf ("%s/aot.log", cache_dir);
logfile = fopen (logfile_name, "a+");
aot_options = g_strdup_printf ("outfile=%s", fname);
/* Maybe due this in another thread ? */
res = mono_compile_assembly (assembly, mono_parse_default_optimizations (NULL), aot_options);
// FIXME: Cache failures
} else {
/*
* - Avoid waiting for the aot process to finish ?
* (less overhead, but multiple processes could aot the same assembly at the same time)
*/
pid = fork ();
if (pid == 0) {
FILE *logfile;
char *logfile_name;
if (spawn_compiler) {
/* FIXME: security */
/* FIXME: Has to pass the assembly loading path to the child process */
cmd = g_strdup_printf ("mono -O=all --aot=%s %s", aot_options, assembly->image->name);
/* Child */
res = g_spawn_command_line_sync (cmd, &out, &err, &exit_status, NULL);
logfile_name = g_strdup_printf ("%s/aot.log", cache_dir);
logfile = fopen (logfile_name, "a+");
g_free (logfile_name);
#if !defined(HOST_WIN32) && !defined(__ppc__) && !defined(__ppc64__) && !defined(__powerpc__)
if (res) {
if (!WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) == 0))
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT failed: %s.", err);
else
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT succeeded.");
g_free (out);
g_free (err);
}
#endif
g_free (cmd);
} else {
dup2 (fileno (logfile), 1);
dup2 (fileno (logfile), 2);
aot_options = g_strdup_printf ("outfile=%s", fname);
res = mono_compile_assembly (assembly, mono_parse_default_optimizations (NULL), aot_options);
if (!res) {
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT failed.");
exit (1);
} else {
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT succeeded.");
exit (0);
}
} else {
/* Parent */
waitpid (pid, &exit_status, 0);
if (!WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) == 0))
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT: failed.");
else
mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT: succeeded.");
}
module = mono_dl_open (fname, MONO_DL_LAZY, NULL);
g_free (aot_options);
}
module = mono_dl_open (fname, MONO_DL_LAZY, NULL);
return module;
}
#else
static void
aot_cache_init (void)
{
}
static MonoDl*
aot_cache_load_module (MonoAssembly *assembly, char **aot_name)
{
return NULL;
}
#endif
static void
find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *value)
{
@@ -1589,6 +1728,10 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
if (mono_security_cas_enabled ())
return;
if (enable_aot_cache && !strcmp (assembly->aname.name, "mscorlib") && !mono_defaults.corlib && !mono_aot_only)
/* Loaded later from mono_aot_get_method () */
return;
mono_aot_lock ();
if (static_aot_modules)
info = g_hash_table_lookup (static_aot_modules, assembly->aname.name);
@@ -1596,16 +1739,17 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
info = NULL;
mono_aot_unlock ();
sofile = NULL;
if (info) {
/* Statically linked AOT module */
sofile = NULL;
aot_name = g_strdup_printf ("%s", assembly->aname.name);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "Found statically linked AOT module '%s'.\n", aot_name);
globals = info->globals;
} else {
if (use_aot_cache)
sofile = load_aot_module_from_cache (assembly, &aot_name);
else {
if (enable_aot_cache)
sofile = aot_cache_load_module (assembly, &aot_name);
if (!sofile) {
char *err;
aot_name = g_strdup_printf ("%s%s", assembly->image->name, SHARED_EXT);
@@ -1652,7 +1796,7 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
fprintf (stderr, "Failed to load AOT module '%s' while running in aot-only mode: %s.\n", aot_name, msg);
exit (1);
} else {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable: %s.\n", aot_name, msg);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: module %s is unusable: %s.\n", aot_name, msg);
}
g_free (msg);
g_free (aot_name);
@@ -1873,14 +2017,14 @@ load_aot_module (MonoAssembly *assembly, gpointer user_data)
}
if (amodule->out_of_date) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT Module %s is unusable because a dependency is out-of-date.\n", assembly->image->name);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: Module %s is unusable because a dependency is out-of-date.\n", assembly->image->name);
if (mono_aot_only) {
fprintf (stderr, "Failed to load AOT module '%s' while running in aot-only mode because a dependency cannot be found or it is out of date.\n", aot_name);
exit (1);
}
}
else
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT loaded AOT Module for %s.\n", assembly->image->name);
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT: loaded AOT Module for %s.\n", assembly->image->name);
}
/*
@@ -1943,8 +2087,9 @@ mono_aot_init (void)
if (g_getenv ("MONO_LASTAOT"))
mono_last_aot_method = atoi (g_getenv ("MONO_LASTAOT"));
if (g_getenv ("MONO_AOT_CACHE"))
use_aot_cache = TRUE;
#ifdef ENABLE_AOT_CACHE
aot_cache_init ();
#endif
}
void
@@ -2537,6 +2682,7 @@ decode_exception_debug_info (MonoAotModule *amodule, MonoDomain *domain,
eh_info = mono_jit_info_get_arch_eh_info (jinfo);
eh_info->stack_size = decode_value (p, &p);
eh_info->epilog_size = decode_value (p, &p);
}
if (async) {
@@ -2696,8 +2842,7 @@ mono_aot_get_unwind_info (MonoJitInfo *ji, guint32 *unwind_info_len)
mono_aot_unlock ();
}
/* The upper 16 bits of ji->unwind_info might contain the epilog offset */
p = amodule->unwind_info + (ji->unwind_info & 0xffff);
p = amodule->unwind_info + ji->unwind_info;
*unwind_info_len = decode_value (p, &p);
return p;
}
@@ -3324,7 +3469,7 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM
if (!method)
method = mono_get_method (image, token, NULL);
full_name = mono_method_full_name (method, TRUE);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT NOT FOUND: %s.", full_name);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT: NOT FOUND: %s.", full_name);
g_free (full_name);
}
return NULL;
@@ -3443,7 +3588,7 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM
if (!jinfo)
jinfo = mono_aot_find_jit_info (domain, amodule->assembly->image, code);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT FOUND method %s [%p - %p %p]", full_name, code, code + jinfo->code_size, info);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT: FOUND method %s [%p - %p %p]", full_name, code, code + jinfo->code_size, info);
g_free (full_name);
}
@@ -3639,6 +3784,15 @@ mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
MonoAotModule *amodule = klass->image->aot_module;
guint8 *code;
if (enable_aot_cache && !amodule && domain->entry_assembly && klass->image == mono_defaults.corlib) {
/* This cannot be AOTed during startup, so do it now */
if (!mscorlib_aot_loaded) {
load_aot_module (klass->image->assembly, NULL);
amodule = klass->image->aot_module;
}
mscorlib_aot_loaded = TRUE;
}
if (!amodule)
return NULL;
@@ -4149,7 +4303,7 @@ load_function_full (MonoAotModule *amodule, const char *name, MonoTrampInfo **ou
if (!code)
g_error ("Symbol '%s' not found in AOT file '%s'.\n", name, amodule->aot_name);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT FOUND function '%s' in AOT file '%s'.", name, amodule->aot_name);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT: FOUND function '%s' in AOT file '%s'.", name, amodule->aot_name);
/* Load info */
@@ -4770,7 +4924,7 @@ mono_aot_set_make_unreadable (gboolean unreadable)
make_unreadable = unreadable;
if (make_unreadable && !inited) {
mono_counters_register ("AOT pagefaults", MONO_COUNTER_JIT | MONO_COUNTER_INT, &n_pagefaults);
mono_counters_register ("AOT: pagefaults", MONO_COUNTER_JIT | MONO_COUNTER_INT, &n_pagefaults);
}
}
+3 -3
View File
@@ -321,9 +321,9 @@ icompare_imm: src1:i len:12
long_conv_to_ovf_i4_2: dest:i src1:i src2:i len:36
vcall2: len:32 clob:c
vcall2_reg: src1:i len:32 clob:c
vcall2_membase: src1:b len:32 clob:c
vcall2: len:40 clob:c
vcall2_reg: src1:i len:40 clob:c
vcall2_membase: src1:b len:40 clob:c
dyn_call: src1:i src2:i len:120 clob:c
# This is different from the original JIT opcodes
+21 -1
View File
@@ -1105,6 +1105,16 @@ mono_debugger_agent_cleanup (void)
mono_cond_destroy (&debugger_thread_exited_cond);
}
int
mono_debugger_agent_get_interrupt_signal (void)
{
#ifdef PLATFORM_ANDROID
return SIGWINCH;
#else
return -1;
#endif
}
/*
* SOCKET TRANSPORT
*/
@@ -1581,7 +1591,7 @@ transport_handshake (void)
/* Read answer */
res = transport_recv (buf, strlen (handshake_msg));
if ((res != strlen (handshake_msg)) || (memcmp (buf, handshake_msg, strlen (handshake_msg) != 0))) {
if ((res != strlen (handshake_msg)) || (memcmp (buf, handshake_msg, strlen (handshake_msg)) != 0)) {
fprintf (stderr, "debugger-agent: DWP handshake failed.\n");
return FALSE;
}
@@ -2798,7 +2808,11 @@ notify_thread (gpointer key, gpointer value, gpointer user_data)
mono_thread_info_finish_suspend_and_resume (info);
}
} else {
#ifdef PLATFORM_ANDROID
res = mono_thread_kill (thread, SIGWINCH);
#else
res = mono_thread_kill (thread, mono_thread_get_abort_signal ());
#endif
if (res) {
DEBUG(1, fprintf (log_file, "[%p] mono_thread_kill () failed for %p: %d...\n", (gpointer)GetCurrentThreadId (), (gpointer)tid, res));
/*
@@ -9775,5 +9789,11 @@ mono_debugger_agent_unhandled_exception (MonoException *exc)
g_assert_not_reached ();
}
int
mono_debugger_agent_get_interrupt_signal (void)
{
return -1;
}
#endif
+3
View File
@@ -59,4 +59,7 @@ mono_debugger_agent_debug_log_is_enabled (void) MONO_INTERNAL;
gboolean
mono_debugger_agent_transport_handshake (void) MONO_INTERNAL;
int
mono_debugger_agent_get_interrupt_signal (void) MONO_INTERNAL;
#endif
+5 -5
View File
@@ -1903,6 +1903,11 @@ mono_main (int argc, char* argv[])
mono_load_coree (argv [i]);
#endif
/* Parse gac loading options before loading assemblies. */
if (mono_compile_aot || action == DO_EXEC || action == DO_DEBUGGER) {
mono_config_parse (config_file);
}
mono_set_defaults (mini_verbose, opt);
domain = mini_init (argv [i], forced_version);
@@ -1968,11 +1973,6 @@ mono_main (int argc, char* argv[])
break;
}
/* Parse gac loading options before loading assemblies. */
if (mono_compile_aot || action == DO_EXEC || action == DO_DEBUGGER) {
mono_config_parse (config_file);
}
#ifdef MONO_JIT_INFO_TABLE_TEST
if (test_jit_info_table)
jit_info_table_test (domain);
+1 -1
View File
@@ -604,7 +604,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
printf ("%s %p %p\n", ji->d.method->name, ji->code_start, ip);
mono_print_unwind_info (unwind_info, unwind_info_len);
*/
epilog = (guint8*)ji->code_start + ji->code_size - (ji->unwind_info >> 16);
epilog = (guint8*)ji->code_start + ji->code_size - mono_jinfo_get_epilog_size (ji);
regs [AMD64_RAX] = new_ctx->rax;
regs [AMD64_RBX] = new_ctx->rbx;
+41
View File
@@ -944,6 +944,47 @@ public class Tests
return 0;
}
public interface IFace1<T> {
void m1 ();
void m2 ();
void m3 ();
void m4 ();
void m5 ();
}
public class ClassIFace<T> : IFace1<T> {
public void m1 () {
}
public void m2 () {
}
public void m3 () {
}
public void m4 () {
}
public void m5 () {
}
}
interface IFaceIFaceCall {
void call<T, T2> (IFace1<object> iface);
}
class MakeIFaceCall : IFaceIFaceCall {
public void call<T, T2> (IFace1<object> iface) {
iface.m1 ();
}
}
// Check normal interface calls from gsharedvt call to fully instantiated methods
public static int test_0_instatiated_iface_call () {
ClassIFace<object> c1 = new ClassIFace<object> ();
IFaceIFaceCall c = new MakeIFaceCall ();
c.call<object, int> (c1);
return 0;
}
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static string to_string<T, T2>(T t, T2 t2) {
return t.ToString ();
+5
View File
@@ -8432,6 +8432,11 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
cmethod, MONO_RGCTX_INFO_METHOD);
/* This is not needed, as the trampoline code will pass one, and it might be passed in the same reg as the imt arg */
vtable_arg = NULL;
} else if ((cmethod->klass->flags & TYPE_ATTRIBUTE_INTERFACE) && !imt_arg) {
/* This can happen when we call a fully instantiated iface method */
imt_arg = emit_get_rgctx_method (cfg, context_used,
cmethod, MONO_RGCTX_INFO_METHOD);
vtable_arg = NULL;
}
}
+29 -10
View File
@@ -247,9 +247,32 @@ emit_big_add (guint8 *code, int dreg, int sreg, int imm)
ARM_ADD_REG_IMM (code, dreg, sreg, imm8, rot_amount);
return code;
}
g_assert (dreg != sreg);
code = mono_arm_emit_load_imm (code, dreg, imm);
ARM_ADD_REG_REG (code, dreg, dreg, sreg);
if (dreg == sreg) {
code = mono_arm_emit_load_imm (code, ARMREG_IP, imm);
ARM_ADD_REG_REG (code, dreg, sreg, ARMREG_IP);
} else {
code = mono_arm_emit_load_imm (code, dreg, imm);
ARM_ADD_REG_REG (code, dreg, dreg, sreg);
}
return code;
}
/* If dreg == sreg, this clobbers IP */
static guint8*
emit_sub_imm (guint8 *code, int dreg, int sreg, int imm)
{
int imm8, rot_amount;
if ((imm8 = mono_arm_is_rotated_imm8 (imm, &rot_amount)) >= 0) {
ARM_SUB_REG_IMM (code, dreg, sreg, imm8, rot_amount);
return code;
}
if (dreg == sreg) {
code = mono_arm_emit_load_imm (code, ARMREG_IP, imm);
ARM_SUB_REG_REG (code, dreg, sreg, ARMREG_IP);
} else {
code = mono_arm_emit_load_imm (code, dreg, imm);
ARM_SUB_REG_REG (code, dreg, dreg, sreg);
}
return code;
}
@@ -4945,15 +4968,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;
}
case OP_LOCALLOC: {
/* keep alignment */
int alloca_waste = cfg->param_area;
alloca_waste += 7;
alloca_waste &= ~7;
/* round the size to 8 bytes */
ARM_ADD_REG_IMM8 (code, ins->dreg, ins->sreg1, 7);
ARM_BIC_REG_IMM8 (code, ins->dreg, ins->dreg, 7);
if (alloca_waste)
ARM_ADD_REG_IMM8 (code, ins->dreg, ins->dreg, alloca_waste);
ARM_SUB_REG_REG (code, ARMREG_SP, ARMREG_SP, ins->dreg);
/* memzero the area: dreg holds the size, sp is the pointer */
if (ins->flags & MONO_INST_INIT) {
@@ -4969,7 +4986,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ARM_B_COND (code, ARMCOND_GE, 0);
arm_patch (code - 4, start_loop);
}
ARM_ADD_REG_IMM8 (code, ins->dreg, ARMREG_SP, alloca_waste);
ARM_MOV_REG_REG (code, ins->dreg, ARMREG_SP);
if (cfg->param_area)
code = emit_sub_imm (code, ARMREG_SP, ARMREG_SP, ALIGN_TO (cfg->param_area, MONO_ARCH_FRAME_ALIGNMENT));
break;
}
case OP_DYN_CALL: {
+12 -2
View File
@@ -2759,6 +2759,16 @@ mono_jinfo_get_unwind_info (MonoJitInfo *ji, guint32 *unwind_info_len)
if (ji->from_aot)
return mono_aot_get_unwind_info (ji, unwind_info_len);
else
/* The upper 16 bits of ji->unwind_info might contain the epilog offset */
return mono_get_cached_unwind_info (ji->unwind_info & 0xffff, unwind_info_len);
return mono_get_cached_unwind_info (ji->unwind_info, unwind_info_len);
}
int
mono_jinfo_get_epilog_size (MonoJitInfo *ji)
{
MonoArchEHJitInfo *info;
info = mono_jit_info_get_arch_eh_info (ji);
g_assert (info);
return info->epilog_size;
}
+1 -1
View File
@@ -3156,7 +3156,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
index = LLVMConstInt (LLVMInt32Type (), ins->inst_offset / size, FALSE);
addr = LLVMBuildGEP (builder, convert (ctx, values [ins->inst_destbasereg], LLVMPointerType (t, 0)), &index, 1, "");
}
emit_store (ctx, bb, &builder, size, convert (ctx, LLVMConstInt (IntPtrType (), ins->inst_imm, FALSE), t), addr, is_volatile);
emit_store (ctx, bb, &builder, size, convert (ctx, LLVMConstInt (IntPtrType (), ins->inst_imm, FALSE), t), convert (ctx, addr, LLVMPointerType (t, 0)), is_volatile);
break;
}
+6 -1
View File
@@ -437,6 +437,8 @@ add_signal_handler (int signo, gpointer handler)
sa.sa_sigaction = handler;
sigemptyset (&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
if (signo == mono_debugger_agent_get_interrupt_signal ())
sa.sa_flags |= SA_RESTART;
#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
/*Apple likes to deliver SIGBUS for *0 */
@@ -502,7 +504,6 @@ remove_signal_handler (int signo)
void
mono_runtime_posix_install_handlers (void)
{
sigset_t signal_set;
if (mini_get_debug_options ()->handle_sigint)
@@ -517,6 +518,10 @@ mono_runtime_posix_install_handlers (void)
if (!mono_thread_info_new_interrupt_enabled ())
add_signal_handler (mono_thread_get_abort_signal (), sigusr1_signal_handler);
if (mono_debugger_agent_get_interrupt_signal () != -1)
add_signal_handler (mono_debugger_agent_get_interrupt_signal (), sigusr1_signal_handler);
/* it seems to have become a common bug for some programs that run as parents
* of many processes to block signal delivery for real time signals.
* We try to detect and work around their breakage here.
+1 -1
View File
@@ -983,7 +983,7 @@ create_delegate_trampoline_data (MonoDomain *domain, MonoClass *klass, MonoMetho
invoke = mono_get_delegate_invoke (klass);
g_assert (invoke);
tramp_data = mono_domain_alloc (domain, sizeof (MonoDelegateTrampInfo));
tramp_data = mono_domain_alloc0 (domain, sizeof (MonoDelegateTrampInfo));
tramp_data->invoke = invoke;
tramp_data->invoke_sig = mono_method_signature (invoke);
tramp_data->impl_this = mono_arch_get_delegate_invoke_impl (mono_method_signature (invoke), TRUE);
+9 -9
View File
@@ -4354,6 +4354,9 @@ create_jit_info (MonoCompile *cfg, MonoMethod *method_to_compile)
if (stack_size)
arch_eh_info_size = sizeof (MonoArchEHJitInfo);
}
if (cfg->has_unwind_info_for_epilog && !arch_eh_info_size)
arch_eh_info_size = sizeof (MonoArchEHJitInfo);
if (cfg->try_block_holes) {
for (tmp = cfg->try_block_holes; tmp; tmp = tmp->next) {
@@ -4651,16 +4654,13 @@ create_jit_info (MonoCompile *cfg, MonoMethod *method_to_compile)
unwind_desc = mono_cache_unwind_info (unwind_info, info_len);
if (cfg->has_unwind_info_for_epilog) {
/*
* The lower 16 bits identify the unwind descriptor, the upper 16 bits contain the offset of
* the start of the epilog from the end of the method.
*/
g_assert (unwind_desc < 0xffff);
g_assert (cfg->code_size - cfg->epilog_begin < 0xffff);
jinfo->unwind_info = ((cfg->code_size - cfg->epilog_begin) << 16) | unwind_desc;
} else {
jinfo->unwind_info = unwind_desc;
MonoArchEHJitInfo *info;
info = mono_jit_info_get_arch_eh_info (jinfo);
g_assert (info);
info->epilog_size = cfg->code_size - cfg->epilog_begin;
}
jinfo->unwind_info = unwind_desc;
g_free (unwind_info);
} else {
jinfo->unwind_info = cfg->used_int_regs;
+2 -1
View File
@@ -123,7 +123,7 @@
#endif
/* Version number of the AOT file format */
#define MONO_AOT_FILE_VERSION 101
#define MONO_AOT_FILE_VERSION 102
//TODO: This is x86/amd64 specific.
#define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
@@ -2511,6 +2511,7 @@ typedef gboolean (*MonoExceptionFrameWalk) (MonoMethod *method, gpointer ip
gboolean mono_exception_walk_trace (MonoException *ex, MonoExceptionFrameWalk func, gpointer user_data);
void mono_restore_context (MonoContext *ctx) MONO_INTERNAL;
guint8* mono_jinfo_get_unwind_info (MonoJitInfo *ji, guint32 *unwind_info_len) MONO_INTERNAL;
int mono_jinfo_get_epilog_size (MonoJitInfo *ji) MONO_INTERNAL;
gboolean
mono_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls,
+9 -6
View File
@@ -831,10 +831,13 @@ walk_stack (MonoMethod *method, int32_t native_offset, int32_t il_offset, mono_b
* event, hence the collect_bt/emit_bt split.
*/
static void
collect_bt (FrameData *data)
collect_bt (FrameData *data, gboolean async_safe)
{
data->count = 0;
mono_stack_walk_no_il (walk_stack, data);
if (async_safe)
mono_stack_walk_async_safe (walk_stack, data);
else
mono_stack_walk_no_il (walk_stack, data);
}
static void
@@ -867,7 +870,7 @@ gc_alloc (MonoProfiler *prof, MonoObject *obj, MonoClass *klass)
len += 7;
len &= ~7;
if (do_bt)
collect_bt (&data);
collect_bt (&data, FALSE);
logbuffer = ensure_logbuf (32 + MAX_FRAMES * 8);
now = current_time ();
ENTER_LOG (logbuffer, "gcalloc");
@@ -1132,7 +1135,7 @@ throw_exc (MonoProfiler *prof, MonoObject *object)
FrameData data;
LogBuffer *logbuffer;
if (do_bt)
collect_bt (&data);
collect_bt (&data, FALSE);
logbuffer = ensure_logbuf (16 + MAX_FRAMES * 8);
now = current_time ();
ENTER_LOG (logbuffer, "throw");
@@ -1168,7 +1171,7 @@ monitor_event (MonoProfiler *profiler, MonoObject *object, MonoProfilerMonitorEv
FrameData data;
LogBuffer *logbuffer;
if (do_bt)
collect_bt (&data);
collect_bt (&data, FALSE);
logbuffer = ensure_logbuf (16 + MAX_FRAMES * 8);
now = current_time ();
ENTER_LOG (logbuffer, "monitor");
@@ -1230,7 +1233,7 @@ mono_sample_hit (MonoProfiler *profiler, unsigned char *ip, void *context)
if (in_shutdown)
return;
now = current_time ();
collect_bt (&bt_data);
collect_bt (&bt_data, TRUE);
elapsed = (now - profiler->startup_time) / 10000;
if (do_debug) {
int len;
+7 -1
View File
@@ -99,6 +99,10 @@ monoutils_sources = \
mono-threads-mach.c \
mono-threads-mach-helper.c \
mono-threads-windows.c \
mono-threads-linux.c \
mono-threads-freebsd.c \
mono-threads-openbsd.c \
mono-threads-android.c \
mono-threads.h \
mono-tls.h \
mono-tls.c \
@@ -112,7 +116,9 @@ monoutils_sources = \
bsearch.c \
mono-signal-handler.h \
mono-conc-hashtable.h \
mono-conc-hashtable.c
mono-conc-hashtable.c \
sha1.h \
sha1.c
arch_sources =
+9
View File
@@ -0,0 +1,9 @@
#include <config.h>
#if defined(PLATFORM_ANDROID)
#ifdef ENABLE_EXTENSION_MODULE
#include "../../../mono-extensions/mono/utils/mono-threads-android.c"
#endif
#endif
+24
View File
@@ -0,0 +1,24 @@
#include <config.h>
#if defined(__FreeBSD__)
#include <pthread.h>
#include <pthread_np.h>
void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
pthread_attr_t attr;
guint8 *current = (guint8*)&attr;
*staddr = NULL;
*stsize = (size_t)-1;
pthread_attr_init (&attr);
pthread_attr_get_np (pthread_self (), &attr);
pthread_attr_getstack (&attr, (void**)staddr, stsize);
pthread_attr_destroy (&attr);
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#include <config.h>
#if defined(__linux__) && !defined(PLATFORM_ANDROID)
#include <mono/utils/mono-threads.h>
#include <pthread.h>
void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
pthread_attr_t attr;
*staddr = NULL;
*stsize = (size_t)-1;
pthread_getattr_np (pthread_self (), &attr);
pthread_attr_getstack (&attr, (void**)staddr, stsize);
pthread_attr_destroy (&attr);
}
#endif
+25 -4
View File
@@ -11,18 +11,19 @@
#if defined(__MACH__)
/* For pthread_main_np, pthread_get_stackaddr_np and pthread_get_stacksize_np */
#define _DARWIN_C_SOURCE 1
#include <mono/utils/mach-support.h>
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-semaphore.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/hazard-pointer.h>
#include <mono/utils/mono-mmap.h>
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/threads-types.h>
#include <pthread.h>
#include <errno.h>
void
mono_threads_init_platform (void)
{
@@ -47,7 +48,7 @@ mono_threads_core_needs_abort_syscall (void)
}
gboolean
mono_threads_core_suspend (MonoThreadInfo *info)
mono_threads_core_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
{
kern_return_t ret;
gboolean res;
@@ -148,4 +149,24 @@ mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
/* pthread_setnmae_np() on Mac is not documented and doesn't receive thread id. */
}
void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
*staddr = (guint8*)pthread_get_stackaddr_np (pthread_self());
*stsize = pthread_get_stacksize_np (pthread_self());
#ifdef TARGET_OSX
/*
* Mavericks reports stack sizes as 512kb:
* http://permalink.gmane.org/gmane.comp.java.openjdk.hotspot.devel/11590
* https://bugs.openjdk.java.net/browse/JDK-8020753
*/
if (pthread_main_np () && *stsize == 512 * 1024)
*stsize = 2048 * mono_pagesize ();
#endif
/* staddr points to the start of the stack, not the end */
*staddr -= *stsize;
}
#endif
+32
View File
@@ -0,0 +1,32 @@
#include <config.h>
#if defined(__OpenBSD__)
#include <pthread.h>
#include <pthread_np.h>
void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
/* TODO : Determine if this code is actually still needed. It may already be covered by the case above. */
pthread_attr_t attr;
guint8 *current = (guint8*)&attr;
*staddr = NULL;
*stsize = (size_t)-1;
pthread_attr_init (&attr);
stack_t ss;
int rslt;
rslt = pthread_stackseg_np (pthread_self (), &ss);
g_assert (rslt == 0);
*staddr = (guint8*)((size_t)ss.ss_sp - ss.ss_size);
*stsize = ss.ss_size;
pthread_attr_destroy (&attr);
}
#endif
+36 -131
View File
@@ -9,17 +9,6 @@
#include <config.h>
#if defined(TARGET_OSX)
/* For pthread_main_np () */
#define _DARWIN_C_SOURCE 1
#include <pthread.h>
#endif
#if defined(__OpenBSD__) || defined(__FreeBSD__)
#include <pthread.h>
#include <pthread_np.h>
#endif
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-semaphore.h>
#include <mono/utils/mono-threads.h>
@@ -34,11 +23,6 @@
extern int tkill (pid_t tid, int signal);
#endif
#if defined(PLATFORM_MACOSX) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
void *pthread_get_stackaddr_np(pthread_t);
size_t pthread_get_stacksize_np(pthread_t);
#endif
#if defined(_POSIX_VERSION) || defined(__native_client__)
#include <sys/resource.h>
#include <signal.h>
@@ -55,6 +39,10 @@ typedef struct {
HANDLE handle;
} StartInfo;
#ifdef PLATFORM_ANDROID
static int no_interrupt_signo;
#endif
static void*
inner_start_thread (void *arg)
{
@@ -185,113 +173,6 @@ mono_threads_core_resume_created (MonoThreadInfo *info, MonoNativeThreadId tid)
MONO_SEM_POST (&info->create_suspended_sem);
}
void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
#if defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
/* Mac OS X */
*staddr = (guint8*)pthread_get_stackaddr_np (pthread_self());
*stsize = pthread_get_stacksize_np (pthread_self());
#ifdef TARGET_OSX
/*
* Mavericks reports stack sizes as 512kb:
* http://permalink.gmane.org/gmane.comp.java.openjdk.hotspot.devel/11590
* https://bugs.openjdk.java.net/browse/JDK-8020753
*/
if (pthread_main_np () && *stsize == 512 * 1024)
*stsize = 2048 * mono_pagesize ();
#endif
/* staddr points to the start of the stack, not the end */
*staddr -= *stsize;
/* When running under emacs, sometimes staddr is not aligned to a page size */
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize() - 1));
return;
#elif (defined(HAVE_PTHREAD_GETATTR_NP) || defined(HAVE_PTHREAD_ATTR_GET_NP)) && defined(HAVE_PTHREAD_ATTR_GETSTACK)
/* Linux, BSD */
pthread_attr_t attr;
guint8 *current = (guint8*)&attr;
*staddr = NULL;
*stsize = (size_t)-1;
pthread_attr_init (&attr);
#if defined(HAVE_PTHREAD_GETATTR_NP)
/* Linux */
pthread_getattr_np (pthread_self(), &attr);
#elif defined(HAVE_PTHREAD_ATTR_GET_NP)
/* BSD */
pthread_attr_get_np (pthread_self(), &attr);
#else
#error Cannot determine which API is needed to retrieve pthread attributes.
#endif
pthread_attr_getstack (&attr, (void**)staddr, stsize);
pthread_attr_destroy (&attr);
if (*staddr)
g_assert ((current > *staddr) && (current < *staddr + *stsize));
/* When running under emacs, sometimes staddr is not aligned to a page size */
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1));
return;
#elif defined(__OpenBSD__)
/* OpenBSD */
/* TODO : Determine if this code is actually still needed. It may already be covered by the case above. */
pthread_attr_t attr;
guint8 *current = (guint8*)&attr;
*staddr = NULL;
*stsize = (size_t)-1;
pthread_attr_init (&attr);
stack_t ss;
int rslt;
rslt = pthread_stackseg_np(pthread_self(), &ss);
g_assert (rslt == 0);
*staddr = (guint8*)((size_t)ss.ss_sp - ss.ss_size);
*stsize = ss.ss_size;
pthread_attr_destroy (&attr);
if (*staddr)
g_assert ((current > *staddr) && (current < *staddr + *stsize));
/* When running under emacs, sometimes staddr is not aligned to a page size */
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1));
return;
#elif defined(sun) || defined(__native_client__)
/* Solaris/Illumos, NaCl */
pthread_attr_t attr;
pthread_attr_init (&attr);
pthread_attr_getstacksize (&attr, &stsize);
pthread_attr_destroy (&attr);
*staddr = NULL;
return;
#else
/* FIXME: It'd be better to use the 'error' preprocessor macro here so we know
at compile-time if the target platform isn't supported. */
#warning "Unable to determine how to retrieve a thread's stack-bounds for this platform in 'mono_thread_get_stack_bounds()'."
*staddr = NULL;
*stsize = 0;
return;
#endif
}
gboolean
mono_threads_core_yield (void)
{
@@ -404,7 +285,7 @@ suspend_signal_handler (int _dummy, siginfo_t *info, void *context)
#endif
static void
mono_posix_add_signal_handler (int signo, gpointer handler)
mono_posix_add_signal_handler (int signo, gpointer handler, int flags)
{
#if !defined(__native_client__)
/*FIXME, move the code from mini to utils and do the right thing!*/
@@ -414,7 +295,7 @@ mono_posix_add_signal_handler (int signo, gpointer handler)
sa.sa_sigaction = handler;
sigemptyset (&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sa.sa_flags = SA_SIGINFO | flags;
ret = sigaction (signo, &sa, &previous_sa);
g_assert (ret != -1);
@@ -425,19 +306,36 @@ void
mono_threads_init_platform (void)
{
#if !defined(__native_client__)
int abort_signo;
/*
FIXME we should use all macros from mini to make this more portable
FIXME it would be very sweet if sgen could end up using this too.
*/
if (mono_thread_info_new_interrupt_enabled ())
mono_posix_add_signal_handler (mono_thread_get_abort_signal (), suspend_signal_handler);
if (!mono_thread_info_new_interrupt_enabled ())
return;
abort_signo = mono_thread_get_abort_signal ();
mono_posix_add_signal_handler (abort_signo, suspend_signal_handler, 0);
#ifdef PLATFORM_ANDROID
/*
* Lots of android native code can't handle the EINTR caused by
* the normal abort signal, so use a different signal for the
* no interruption case, which is used by sdb.
* FIXME: Use this on all platforms.
* SIGUSR1 is used by dalvik/art.
*/
no_interrupt_signo = SIGUSR2;
g_assert (abort_signo != no_interrupt_signo);
mono_posix_add_signal_handler (no_interrupt_signo, suspend_signal_handler, SA_RESTART);
#endif
#endif
}
/*nothing to be done here since suspend always abort syscalls due using signals*/
void
mono_threads_core_interrupt (MonoThreadInfo *info)
{
/* Handled in mono_threads_core_suspend () */
}
int
@@ -478,10 +376,17 @@ mono_threads_core_needs_abort_syscall (void)
}
gboolean
mono_threads_core_suspend (MonoThreadInfo *info)
mono_threads_core_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
{
/*FIXME, check return value*/
mono_threads_pthread_kill (info, mono_thread_get_abort_signal ());
#ifdef PLATFORM_ANDROID
if (!interrupt_kernel)
mono_threads_pthread_kill (info, no_interrupt_signo);
else
mono_threads_pthread_kill (info, mono_thread_get_abort_signal ());
#else
mono_threads_pthread_kill (info, mono_thread_get_abort_signal ());
#endif
while (MONO_SEM_WAIT (&info->begin_suspend_semaphore) != 0) {
/* g_assert (errno == EINTR); */
}
@@ -505,7 +410,7 @@ mono_threads_platform_register (MonoThreadInfo *info)
MONO_SEM_INIT (&info->begin_suspend_semaphore, 0);
#if defined (PLATFORM_ANDROID)
info->native_handle = (gpointer) gettid ();
info->native_handle = gettid ();
#endif
}
+1 -1
View File
@@ -44,7 +44,7 @@ mono_threads_core_self_suspend (MonoThreadInfo *info)
}
gboolean
mono_threads_core_suspend (MonoThreadInfo *info)
mono_threads_core_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
{
g_assert_not_reached ();
}
+11 -1
View File
@@ -14,6 +14,7 @@
#include <mono/utils/mono-tls.h>
#include <mono/utils/hazard-pointer.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-mmap.h>
#include <errno.h>
@@ -425,7 +426,7 @@ mono_thread_info_suspend_sync (MonoNativeThreadId tid, gboolean interrupt_kernel
return info;
}
if (!mono_threads_core_suspend (info)) {
if (!mono_threads_core_suspend (info, interrupt_kernel)) {
MONO_SEM_POST (&info->suspend_semaphore);
mono_hazard_pointer_clear (hp, 1);
*error_condition = "Could not suspend thread";
@@ -787,7 +788,16 @@ mono_threads_create_thread (LPTHREAD_START_ROUTINE start, gpointer arg, guint32
void
mono_thread_info_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
guint8 *current = (guint8 *)&stsize;
mono_threads_core_get_stack_bounds (staddr, stsize);
if (!*staddr)
return;
/* Sanity check the result */
g_assert ((current > *staddr) && (current < *staddr + *stsize));
/* When running under emacs, sometimes staddr is not aligned to a page size */
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1));
}
gboolean
+1 -1
View File
@@ -323,7 +323,7 @@ mono_threads_pthread_kill (THREAD_INFO_TYPE *info, int signum) MONO_INTERNAL;
/* Plartform specific functions DON'T use them */
void mono_threads_init_platform (void) MONO_INTERNAL; //ok
gboolean mono_threads_core_suspend (THREAD_INFO_TYPE *info) MONO_INTERNAL;
gboolean mono_threads_core_suspend (THREAD_INFO_TYPE *info, gboolean interrupt_kernel) MONO_INTERNAL;
gboolean mono_threads_core_resume (THREAD_INFO_TYPE *info) MONO_INTERNAL;
void mono_threads_platform_register (THREAD_INFO_TYPE *info) MONO_INTERNAL; //ok
void mono_threads_platform_free (THREAD_INFO_TYPE *info) MONO_INTERNAL;
+176
View File
@@ -0,0 +1,176 @@
/* $OpenBSD: sha1.c,v 1.22 2012/08/27 21:05:43 miod Exp $ */
/*
* SHA-1 in C
* By Steve Reid <steve@edmweb.com>
* 100% Public Domain
*
* Test Vectors (from FIPS PUB 180-1)
* "abc"
* A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
* 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
* A million repetitions of "a"
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#include <sys/param.h>
#include <string.h>
#include <stdint.h>
#include <sha1.h>
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/*
* blk0() and blk() perform the initial expand.
* I got the idea of expanding during the round function from SSLeay
*/
#if BYTE_ORDER == LITTLE_ENDIAN
# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|(rol(block->l[i],8)&0x00FF00FF))
#else
# define blk0(i) block->l[i]
#endif
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
^block->l[(i+2)&15]^block->l[i&15],1))
/*
* (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
*/
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
typedef union {
guint8 c[64];
guint32 l[16];
} CHAR64LONG16;
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
void
SHA1Transform(guint32 state[5], const guint8 buffer[SHA1_BLOCK_LENGTH])
{
guint32 a, b, c, d, e;
guint8 workspace[SHA1_BLOCK_LENGTH];
CHAR64LONG16 *block = (CHAR64LONG16 *)workspace;
(void)memcpy(block, buffer, SHA1_BLOCK_LENGTH);
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
}
/*
* SHA1Init - Initialize new context
*/
void
SHA1Init(SHA1_CTX *context)
{
/* SHA1 initialization constants */
context->count = 0;
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
}
/*
* Run your data through this.
*/
void
SHA1Update(SHA1_CTX *context, const guint8 *data, size_t len)
{
size_t i, j;
j = (size_t)((context->count >> 3) & 63);
context->count += (len << 3);
if ((j + len) > 63) {
(void)memcpy(&context->buffer[j], data, (i = 64-j));
SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64)
SHA1Transform(context->state, (guint8 *)&data[i]);
j = 0;
} else {
i = 0;
}
(void)memcpy(&context->buffer[j], &data[i], len - i);
}
/*
* Add padding and return the message digest.
*/
void
SHA1Pad(SHA1_CTX *context)
{
guint8 finalcount[8];
guint i;
for (i = 0; i < 8; i++) {
finalcount[i] = (guint8)((context->count >>
((7 - (i & 7)) * 8)) & 255); /* Endian independent */
}
SHA1Update(context, (guint8 *)"\200", 1);
while ((context->count & 504) != 448)
SHA1Update(context, (guint8 *)"\0", 1);
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
}
void
SHA1Final(guint8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
{
guint i;
SHA1Pad(context);
if (digest) {
for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
digest[i] = (guint8)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
memset(context, 0, sizeof(*context));
}
}
+50
View File
@@ -0,0 +1,50 @@
/* $OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $ */
/*
* SHA-1 in C
* By Steve Reid <steve@edmweb.com>
* 100% Public Domain
*/
#ifndef _SHA1_H
#define _SHA1_H
#include <glib.h>
#define SHA1_BLOCK_LENGTH 64
#define SHA1_DIGEST_LENGTH 20
#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
typedef struct {
guint32 state[5];
guint64 count;
guint8 buffer[SHA1_BLOCK_LENGTH];
} SHA1_CTX;
__BEGIN_DECLS
void SHA1Init(SHA1_CTX *);
void SHA1Pad(SHA1_CTX *);
void SHA1Transform(guint32 [5], const guint8 [SHA1_BLOCK_LENGTH]);
void SHA1Update(SHA1_CTX *, const guint8 *, size_t);
void SHA1Final(guint8 [SHA1_DIGEST_LENGTH], SHA1_CTX *);
char *SHA1End(SHA1_CTX *, char *);
char *SHA1File(const char *, char *);
char *SHA1FileChunk(const char *, char *, off_t, off_t);
char *SHA1Data(const guint8 *, size_t, char *);
__END_DECLS
#define HTONDIGEST(x) do { \
x[0] = htonl(x[0]); \
x[1] = htonl(x[1]); \
x[2] = htonl(x[2]); \
x[3] = htonl(x[3]); \
x[4] = htonl(x[4]); } while (0)
#define NTOHDIGEST(x) do { \
x[0] = ntohl(x[0]); \
x[1] = ntohl(x[1]); \
x[2] = ntohl(x[2]); \
x[3] = ntohl(x[3]); \
x[4] = ntohl(x[4]); } while (0)
#endif /* _SHA1_H */