Граф коммитов

180 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 6988977096 [runtime] Improve comment. 2017-04-20 10:05:47 +02:00
Rolf Bjarne Kvinge 488cccb8d4 [mtouch] Put simulator assemblies into MonoBundle/simulator for frameworks.
Put simulator assemblies in MonoBundle/simulator for frameworks, so that we
can have a single framework that contains both device and simulator
assemblies without assemblies conflicting between device and simulator.

The device assemblies continue in the same place, in the MonoBundle directory,
so no additional checks are needed on device.
2017-04-18 15:18:46 +02:00
Rolf Bjarne Kvinge 1afae37c7f [runtime] Add support for initializing in an embedder mode. 2017-04-18 11:13:42 +02:00
Rolf Bjarne Kvinge 6b9e61eebc [runtime] Make xamarin_open_assembly public and stable. (#2011)
This is needed for Embeddinator-4000.
2017-04-17 18:38:52 +02:00
Rolf Bjarne Kvinge 1c67a84d90 [runtime] Make headers safe for compiling C code. (#2010) 2017-04-17 18:12:37 +02:00
Rolf Bjarne Kvinge 337feb6cc0 [runtime] Fix lookup of assembly in default location in framework. (#1998) 2017-04-12 15:54:30 +02:00
Rolf Bjarne Kvinge bbbe881747 Fix how we build frameworks. Fixes #53813. (#1952)
Previously we copied any equivalent .dylib and ran install_name_tool on the
library to change the library id to make it a framework.

Unfortunately this does not work when the library contains bitcode, because
bitcode embeds linker flags (-install_name for instance), and
install_name_tool does not change those linker flags.

This means that we need to create frameworks by linking with the proper
arguments, since it's much more difficult to fixup the embedded bitcode linker
flags as well.

So change how be build Mono.framework, Xamarin.framework, and any frameworks
built from assemblies to:

* Always link instead of fixup a dylib. For Mono.framework this means
  extracting all the object files from libmonosgen-2.0.a and linking those,
  for Xamarin.framework this means linking the object files we've already
  built.

* Make sure the library is correctly named when linked (once again: bitcode
  contains embedded linker flags, so renaming the executable later breaks
  stuff as well).

I've also extracted the logic that creates Mono.framework from
libmonosgen-2.0.a to a separate shell script, to deduplicate this logic.

This required a minor change in the mono builds: we need the Mono.framework
when building the `all` target, so make sure that happens.

https://bugzilla.xamarin.com/show_bug.cgi?id=53813
2017-04-03 11:52:29 +02:00
Sebastien Pouliot 22a5cb5ab9 [runtime] Remove unicode character causing warnings at build time (#1945)
16:59:44 monotouch-debug.m:568:3: warning: treating Unicode character as whitespace [-Wunicode-whitespace]
16:59:44         } else if ((shmkey = ftok ("/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch", 0)) == -1) {
16:59:44          ^
2017-03-30 18:00:48 +02:00
Vincent Dondain d819d25bff [modelio] Add missing MDLMesh constructors and fix xtro (#1826)
Fixes bug #52575: Missing ModelIO API
(https://bugzilla.xamarin.com/show_bug.cgi?id=52575)

We turn the MDLMesh constructors into static ones because we don't want to lose the shape name.
Also, the signatures of these constructors differ so it would not be possible to use an enum to differentiate the shapes.
2017-03-28 10:08:12 -05:00
Rolf Bjarne Kvinge b41307bb7f Merge commit '2272efbb189d457dc6c599cefd875425baad92a5' into framework-sdk 2017-03-14 19:24:07 +01:00
Rolf Bjarne Kvinge 24dacc6d02 [runtime] Don't look in shared memory for debug data in normal apps (#1841)
* Bump maccore to get fix for launching the simulator for app extensions.

* [runtime] Don't look in shared memory for debug data in normal apps.

Don't look in shared memory for debug data in normal apps, because it
interferes when debugging extensions from the same solution as a container
app:

Example, for a keyboard extension:

1. Run extension in XS.
2. Manually launch the extension's container app (which contains a textbox
   that can be used to launch the keyboard).
3. The container app reads the debug data in shared memory which was intented
   for the extension, and takes over the debugger.
4. Launch keyboard, which will not be able to connect to the IDE because the
   container app already connected to the IDE.
2017-03-08 20:00:58 +01:00
Rolf Bjarne Kvinge 1e498bce22 Merge remote-tracking branch 'origin/master' into framework-sdk 2017-03-07 07:38:30 +01:00
Alex Soto b52d067558 [runtime] Fix bug 52308 Console.WriteLine text is not showing in Device Log. (#1821)
https://bugzilla.xamarin.com/show_bug.cgi?id=52308

Apple moved to os_log[1] in iOS 10 / macOS 10.12 / tvOS 10 / watchOS 3.0
whenever you call NSLog we used to rely on NSLog parsing "%S" but
it seems broken. We now just create a NSString from the unicode str
and give that to NSLog when not in watch (NSLog in watch is broken yay).

[1]: https://developer.apple.com/reference/os/logging?language=objc
2017-03-03 14:19:23 -06:00
Rolf Bjarne Kvinge d212b97b1a Merge remote-tracking branch 'origin/master' into framework-sdk 2017-02-21 18:14:29 +01:00
Rolf Bjarne Kvinge 1d9e377adf [runtime] Fix potential memory leak in error conditions. (#1723)
This was found by clang's static analyzer:

    trampolines.m:94:16: warning: Potential leak of memory pointed to by 'buf'
                                                             return NULL;
                                                                    ^~~~
2017-02-20 19:35:40 +01:00
Rolf Bjarne Kvinge 1992b667ec [runtime] Plug a leak in http debugging. (#1720)
Clang's static analyzer tought me something new today: 'copy' properties are
not automatically deallocated 😒:

    monotouch-debug.m:237:1: warning: 'XamarinHttpConnection' lacks a 'dealloc' instance method but must release '_completion_handler' and others
    @implementation XamarinHttpConnection
    ^
2017-02-20 19:35:17 +01:00
Rolf Bjarne Kvinge 679b981b66 [runtime] Work around static analyzer warning about incorrect refcount decrement. (#1718)
This warning:

    shared.m:216:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
                    [pool release];
                    ^~~~~~~~~~~~~~

is somewhat incorrect, because we're using NSAutoreleasePools in uncommon ways
(at the same time it's not entirely incorrect either, because we're not
following Apple's documentation about how to use NSAutoreleasePools).

Luckily calling [NSAutoreleasePool drain] is equivalent to [NSAutoreleasePool
release], so just replace the latter with the former to silence the warning,
since clang doesn't know those two are equivalent.
2017-02-20 19:30:23 +01:00
Rolf Bjarne Kvinge e5d601c8a5 [runtime] Remove unused return value from the *_connect_* debug functions. (#1719)
At the beginning of dawn, not long after the big bang, we used to vibrate the
phone if there was a problem when connecting to the debugger in the IDE, and
the number of times the phone vibrated indicated a certain error condition.

This innovative debugging technique was at some point replaced with more
intuitive (albeit less innovative) error reporting, however the *_connect_*
family of functions continued returning the number of times the phone should
vibrate, even if the caller was now soundlessly ignoring this information.

After many years someone had the wonderful idea of running a static analyzer
on the code, and now the unused return value is not so silent anymore:

    monotouch-debug.m:663:5: warning: Value stored to 'rv' is never read
                                    rv = monotouch_connect_usb ();
                                    ^    ~~~~~~~~~~~~~~~~~~~~~~~~
    monotouch-debug.m:665:5: warning: Value stored to 'rv' is never read
                                    rv = monotouch_connect_wifi (hosts);
                                    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    monotouch-debug.m:667:5: warning: Value stored to 'rv' is never read
                                    rv = xamarin_connect_http (hosts);
                                    ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So fix the warning by removing the return value.
2017-02-20 19:30:09 +01:00
Rolf Bjarne Kvinge 0f59d51536 [runtime] Make sure to always dispose objects that should be disposed, even if things go wrong. (#1725)
This fixes an issue clang's static analyzer found: if an exception occured in
a call to managed code, we wouldn't process the list of objects to dispose:

    trampolines-invoke.m:549:2: warning: Potential leak of memory pointed to by 'dispose_list'
            MONO_THREAD_DETACH; // COOP: This will switch to GC_SAFE
            ^~~~~~~~~~~~~~~~~~
    ./xamarin/runtime.h:306:11: note: expanded from macro 'MONO_THREAD_DETACH'
            } while (0)
                     ^

Fix this by always processing the list of objects to dispose, even if
exceptions occur.
2017-02-20 19:29:56 +01:00
Rolf Bjarne Kvinge a4d2998e5b [runtime] Allocate memory correctly to make clang's static analyzer happy. (#1724)
trampolines.m:75:22: warning: Result of 'malloc' is converted to a pointer of type 'id', which is incompatible with sizeof operand type 'void *'
                                    id *buf = (id *) malloc (sizeof (void *) * length);
                                    ~~~~             ^~~~~~  ~~~~~~~~~~~~~~~
2017-02-20 19:29:13 +01:00
Rolf Bjarne Kvinge bf36860c1e [runtime] Make the clang's static analyzer happy. (#1722)
trampolines-i386.m:126:19: warning: Assigned value is garbage or undefined
                            it->state->edx = v[1];
                                           ^ ~~~~
    trampolines-x86_64.m:410:16: warning: Assigned value is garbage or undefined
                                                    *reg_ptr = v [stores];
                                                             ^ ~~~~~~~~~~
    trampolines-x86_64.m:447:14: warning: Assigned value is garbage or undefined
                                    *reg_ptr = v [stores++];
                                             ^ ~~~~~~~~~~~~
2017-02-20 17:20:13 +01:00
Rolf Bjarne Kvinge a868ab2a3f [runtime] Fix an extraneous timezone release. (#1721)
Getting a time zone instance in two different code paths, one allocating the
time zone instance, and the other not allocating, is problematic when we're
unconditionally freeing the time zone at the end.

    xamarin-support.m:58:2: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
            [tz release];
            ^~~~~~~~~~~~

So fix this by autoreleasing the allocated timezone.
2017-02-20 17:19:38 +01:00
Rolf Bjarne Kvinge 3ea9fddc7b [runtime] Check in container app's root directory for assemblies.
If an extension is sharing code with the container app, then assemblies may be
placed in:

* The container app's Framework directory (for assemblies whose code is
  shared, and the build action is 'framework'). We already handle this case.
* The container app's root directory (for assemblies whose code is shared, and
  the build action is not 'framework'). This case we didn't handle, and we're
  now fixing it.
* In the extension (for assemblies whose code is not shared). We already
  handle this case.
2017-02-10 16:39:13 +01:00
Rolf Bjarne Kvinge dea33a6770 [runtime] Lookup assembly-related resources from parent bundles as well.
Add support for finding assembly-related resources (debug files, config files,
satellite assemblies, aotdata files, etc) in multiple locations:

* The bundle's root directory.
* A pointer-size specific size directory (.monotouch-32|64)
* A framework's MonoBundle directory (and the framework may not be named after
  the assembly, which means it's not necessarily possible to deduce the
  framework's name at runtime).
* In a container bundle.

Some files may also have an arch-specific suffix.
2017-02-10 14:29:10 +01:00
Rolf Bjarne Kvinge 7ce53a98e8 [runtime] Make internal function static. 2017-02-10 14:29:09 +01:00
Rolf Bjarne Kvinge ddedfc2798 [mtouch] Make the architecture a suffix instead of infix for aotdata filenames.
Make the architecture a suffix instead of infix for aotdata filenames so that
it's easier to compute the filename from the assembly name without passing
printf-style format strings around.
2017-02-10 14:29:09 +01:00
Rolf Bjarne Kvinge 365b293d97 Create a Xamarin[-debug].framework. 2017-02-10 14:29:09 +01:00
Chris Hamons 2c835c5294 [XM] Add hybrid/standard AOT option and improve AOT code (#1650)
* [XM] Seperate parsing from compilation in AOT code

- Parsing command line options was too entangled with actually compiling
- Refactor test code to centralize Compile, reducing some complexity of tests
- Groundwork for hybrid vs non-hybrid AOT work

* Add hybrid/standard AOT support

* Add xammac_tests to makefile/jenkins

* Add flag to force AOT

* Disable MonoTouchFixtures.Contacts.ContactStoreTest.GetUnifiedContacts on XM due to prompts on Jenkins
2017-02-08 13:40:48 -06:00
Rolf Bjarne Kvinge 3dac0bae81 Use @rpath instead of @executable_path in dylibs. (#1552)
Use @rpath instead of @executable_path in dylibs, since it allows us to be
more flexible when placing dylibs in the app.

In particular with this change it's trivial to put libmonosgen-2.0.dylib in
the container app, and reference it from extensions.
2017-01-24 20:24:32 +01:00
Rolf Bjarne Kvinge 0a07b6ba8e Remove unnecessary bitcode from dylibs. Fixes #51352 (#1469)
This is a series of fixes to the dynamic libraries we build / create to remove
any unnecessary bloat (unused architectures, bitcode).

A brand new watchOS app with no changes goes from 35MB to 11MB with these
fixes (with incremental builds disabled, the app size is 10MB).

--------------------------------------------------------------------------------

* [runtime] Split list of architectures into simulator and device-specific lists.

* [runtime] Build separate dylibs for device and simulator.

Build separate dylibs for device and simulator, since we already install these
into different locations.

This makes both the simulator and device builds slightly faster (since the
respective dylibs are smaller, and less data to copy around).

For watchOS apps, this saves ~430kb.

* [runtime] Strip bitcode from dylibs. Fixes #51352.

We know that dylibs will never be shipped to the App Store, so we'll never
need them to have bitcode.

So just strip the bitcode from all our dylibs, since this makes apps with
fastdev significantly smaller (and thus much faster to upload to watch
devices).

For watchOS apps this is a very significant improvement: a branch new watchOS
app without any changes goes from 35MB to 17MB.

https://bugzilla.xamarin.com/show_bug.cgi?id=51352

* [mtouch] Fix dylib compilation to not embed full bitcode.

Facts
=====

a. The output from the AOT compiler is an assembly (.s) file.
b. Clang's assembler does not support -fembed-bitcode-marker (only -fembed-
   bitcode), so when we ask clang to -fembed-bitcode-marker, the assembler
   receives a -fembed-bitcode argument.
c. This means that the assembled object file does not contain the
   __LLVM/__bitcode and __LLVM/__cmdline sections (it does however contain an
   __LLVM/__asm section).
d. The native linker will create a bitcode assembly section if none of the
   object files passed to the linker contain a __LLVM/__bitcode section and
   there's an __LLVM/__asm section present.
e. The end result is that when we build to a dylib, we end up (unexpectedly,
   because we ask Clang to -fembed-bitcode-marker) including both armv7k and
   bitcode in the dylib, thus bloating the dylib size significantly.

Solution
========

We manually add the __LLVM/__bitcode and __LLVM/__cmdline sections to the .s
file Mono's AOT compiler generated. This way the .o file will have the magic
sections, and the linker will not include bitcode (only the bitcode marker) in
the final library.

An empty watchOS extension with incremental builds is now 6MB smaller (down
to 11MB from 17MB).
2017-01-16 12:32:06 +01:00
Chris Hamons ffe142d0b5 [XM] AOT support in Xamarin.Mac (#1340) 2017-01-11 14:10:39 -06:00
Rolf Bjarne Kvinge 8e229908df [runtime] Blocks must be copied, not just assigned. Fixes #44568. (#1471)
The completion handler block must be copied to the XamarinHttpConnection
instance, otherwise we'll just store a pointer to a stack block, and once we
invoke the block we'll access stack memory (probably from another thread),
which is really not what we want to do.

https://bugzilla.xamarin.com/show_bug.cgi?id=44568
2017-01-11 19:45:38 +01:00
Rolf Bjarne Kvinge a520c5077a [runtime] Use safer versions of strncpy/strncat/strcat. (#1434)
The length argument for `strncpy` specifies how many characters to copy, not
the length of the target string, which makes our usage incorrect.

Fix our usage, and use the `strlcpy` variant instead, which takes the length
of the target string.

And use `strlcat` instead of `strcat`.
2017-01-04 18:10:47 +01:00
Sebastien Pouliot b5632f9c2f merge xcode8.2 into master 2016-12-12 21:26:23 -05:00
Rolf Bjarne Kvinge c00dbbb30c [runtime] Assert instead of exiting with a printf. (#1222)
Asserting produces a potentially useful crash report, while just exiting doesn't.
2016-11-21 14:39:16 +01:00
Rolf Bjarne Kvinge ea24c1d3b4 [runtime] Remove unused variable. (#1221) 2016-11-21 14:38:14 +01:00
Rolf Bjarne Kvinge 657d603b03 [runtime] Fix signature for mono_thread_detach_if_exiting. (#1217) 2016-11-18 20:42:31 +01:00
Rolf Bjarne Kvinge 7728c4cd19 [registrar] Use metadata tokens instead of strings to find types and methods. (#1085)
Use metadata tokens instead of strings to find types and methods.

This makes the code to find methods more compact (a lot less strings in the
executable, and additionally in most cases a compact representation (32-bit
integer) of the corresponding metadata token and additional information can be
used, which results in less executable code (fewer parameters to methods,
etc)), resulting in smaller executables.

Size savings are around 200kb for dont link apps, and 20-60kb for linked apps
(this obviously varies a lot depending on how much has to registered by the
registrar).

|                |    Before     |     After     |       Diff        |
|----------------|--------------:|--------------:|------------------:|
| dontlink/32bit |  102.810.144  |  102.609.456  | -200.688 = -0,20% |
| dontlink/64bit |  107.420.576  |  107.221.792  | -198.784 = -0,19% |
| linksdk/32bit  |   40.957.296  |   40.936.864  |  -20.432 = -0,05% |
| linksdk/64bit  |   43.113.136  |   43.093.936  |  -19.200 = -0,04% |
| linkall/32bit  |   38.410.032  |   38.348.288  |  -61.744 = -0,16% |
| linkall/64bit  |   40.315.200  |   40.267.344  |  -47.856 = -0,12% |

Additionally I've removed the `lazy_map` dictionary, which we populated at
startup and was used to map between Class instances and the corresponding
managed type's FullName, and instead iterate over a native array of Class ->
metadata token mappings whenever we need to look up the managed type for a
certain Class instance.

This is slightly slower for each type we need to look up (for a non-linked app
there might be a 2000-3000 entries in the native array, which would be
iterated instead of using a hashtable lookup), but it's only done once per
type and there's a significant startup memory improvement.

For a non-linked test app I get the following using the Xamarin profiler:

|                   |  Before |  After  |       Diff      |
|-------------------|--------:|--------:|----------------:|
| Memory allocated  |  2,8 MB |  2,4 MB | -0,4 MB = -14 % |
| Objects allocated |   43678 |   38463 |   -5215 = -12 % |
| Private bytes     | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
| Working set       | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
2016-11-01 14:34:56 -04:00
Rolf Bjarne Kvinge 4aea22ef15 [ObjCRuntime] Store a pointer to the initialization options in managed memory. (#1076)
This makes it possible to access the initialization options at a later point
(soon to be used by the registrar).
2016-11-01 12:40:51 +01:00
Rolf Bjarne Kvinge 0c43ddc615 Disable managed exception marshaling when the debugger is attached. Fixes #45116. (#1055)
Managed exception marshaling interferes with the debugger, because it adds
exception handlers to executing code, which makes the Mono runtime think an
exception is handled when logically it's not (although technically it is).

The consequence is that the IDEs will only be notified when we re-throw the
exception after catching it, making it impossible for the IDEs to stop when
the exception is thrown (they will instead stop when we re-throw the
exception).

So disable managed exception marshaling (unless the user changed the default
behavior) when a debugger is attached.

This is the same behavior as Xamarin.Android.

https://bugzilla.xamarin.com/show_bug.cgi?id=45116
2016-10-28 19:07:01 +02:00
Rolf Bjarne Kvinge 71a578ee38 [runtime] Remove deprecated and ignored mono option. (#1019)
Setting this option prints this to stdout:

> Mono Warning: option gen-compact-seq-points is deprecated.

and it's ignored, so just don't set this option.
2016-10-27 16:04:19 -04:00
Rolf Bjarne Kvinge 94485580b5 Use ExceptionDispatchInfo to keep stack traces when unhandled exceptions are marshaled. Improves bug #45742 a bit. (#1040)
Example code:

	public override void ViewDidLoad ()
	{
		throw new Exception ("USELESS");
	}

Current output with unhandled exceptions that are marshaled:

    Unhandled Exception:
    System.Exception: USELESS
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10
    [ERROR] FATAL UNHANDLED EXCEPTION: UselessExceptions.CustomException: USELESS
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10

Note how the managed frame where the exception was thrown does not show up.

This is because we technically catch exceptions when marshaling them, and then
later we call mono_raise_exception to raise the same exception. Unfortunately
that leads to overwriting the initial stack trace, and we end up with a stack
trace that does not include the location where the original exception was
thrown.

So instead of calling mono_raise_exception to rethrow the same exception, we
use ExceptionDispatchInfo, which is able to capture the stack trace for both
the original exception and the new exception, producing the following output:

    System.Exception: USELESS
      at UselessExceptions.ViewController.ViewDidLoad () [0x0000c] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/ViewController.cs:27
    --- End of stack trace from previous location where exception was thrown ---
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10
    [ERROR] FATAL UNHANDLED EXCEPTION: UselessExceptions.CustomException: USELESS
      at UselessExceptions.ViewController.ViewDidLoad () [0x0000c] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/ViewController.cs:27
    --- End of stack trace from previous location where exception was thrown ---
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10

Incidently this is how Xamarin.Android does it [1].

[1]: 9387f2fe16

https://bugzilla.xamarin.com/show_bug.cgi?id=45742
2016-10-27 20:03:11 +02:00
Rolf Bjarne Kvinge 7666748486 [runtime] Make startup profiling code compile. (#1001) 2016-10-18 21:40:42 -04:00
Rolf Bjarne Kvinge 2a9f5a8238 Merge pull request #988 from rolfbjarne/bug44709d
Unify stret detection between the generator and platform assemblies, and fix stret detection on watchOS. Fixes #44709.
2016-10-13 19:44:02 +02:00
Chris Hamons 17bb354dca [XM] Fix 44707 by fixing launcher and mmp (#971)
- https://bugzilla.xamarin.com/show_bug.cgi?id=44707
- Sets MONO_CFG_DIR to work around embedding API bug: https://bugzilla.xamarin.com/show_bug.cgi?id=45279
- Added ability to run single XM test by setting XM_TEST_NAME to full test name.
2016-10-13 10:42:05 -05:00
Rolf Bjarne Kvinge a9188a3bf3 [runtime] Fix returning structs with size < 8. 2016-10-13 17:35:51 +02:00
Rolf Bjarne Kvinge f448f6d55c [runtime] Fix returning 'float,float' and 'double' structs on x86_64. 2016-10-13 17:35:50 +02:00
Rolf Bjarne Kvinge c660307b55 [runtime] Simplify stret check in the x86_64 trampolines. 2016-10-13 17:35:50 +02:00
Rolf Bjarne Kvinge 9a40b22857 [runtime] Simplify stret check in the x86 trampolines. 2016-10-13 17:35:50 +02:00
Rolf Bjarne Kvinge d3ae54adb6 Fix xamarin_log to not treat % as format specifiers. Fixes #45046. (#952) 2016-10-06 14:01:14 +02:00
Rolf Bjarne Kvinge 0863e412b4 Remove XI/Classic support (#926)
* [tests] Remove Classic SDK tests.

* Remove XI/Classic support.

This also means we can remove support for the legacy registrars.

* [monotouch-test] Remove legacy registrar tests.

* [tests/mtouch] Remove Classic tests (and legacy registrar logic).

* [tests/scripted] Fix tests to reference Xamarin.iOS.dll.
2016-09-30 15:02:17 -04:00
Rolf Bjarne Kvinge 19d237473e [runtime] Fix support for debugging on watch device with multiple IP addresses. Fixes #44568. (#898)
At startup we send a request to all the IP addresses we have,
so we must make sure to not get confused if we get responses
from more than one of them.

This fix also requires an updated mlaunch.

https://bugzilla.xamarin.com/show_bug.cgi?id=44568
2016-09-27 08:07:31 -04:00
Rolf Bjarne Kvinge 1412b5bbed Remove any code related to the IL registrar. (#874)
We've used the dynamic registrar for years now when selecting the IL registrar
(and I've never heard about anybody doing it), so just remove all the related
(and in fact dead) code.
2016-09-22 14:27:54 +02:00
Rolf Bjarne Kvinge 8be3807162 [runtime] Re-enable the GC pump on watchOS to help track down issues. (#838) 2016-09-15 14:24:32 -04:00
Rolf Bjarne Kvinge 3eb0fdfdea [runtime] Fix compiler warning (unicode character treated as whitespace). (#822) 2016-09-13 10:04:15 -04:00
Sebastien Pouliot 38148c718a Merge branch 'xcode8' 2016-09-09 15:29:37 -04:00
Sebastien Pouliot 0cc8b176e8 Merge branch 'cycle8' into xcode8 2016-09-06 18:46:23 -04:00
Rolf Bjarne Kvinge cfb84f6e17 [runtime] Use printf on watchOS, NSLog doesn't shown up (by default) (#772)
* [runtime] Use printf on watchOS, NSLog doesn't shown up (by default).

* [runtime] Use a wrapper function for logging.

So that we can chose between printf and NSLog at runtime,
depending on where we're running.
2016-09-06 16:55:23 -04:00
Rolf Bjarne Kvinge 3859240031 Add support for debugging over http. Fixes #41554.
The watchOS device has limited networking support; in particular
it does not allow inbound/output network connections using 'bind'
(kernel-level sandbox restrictions).

This means that we can't use BSD sockets to connect to the debugger
in the IDE on the desktop. Instead we create an http tunnel that
knows how to convert socket send/recv data into http requests on
both sides.

https://bugzilla.xamarin.com/show_bug.cgi?id=41554
2016-09-05 10:05:00 +02:00
Rolf Bjarne Kvinge a9294ab9c8 [runtime] Check if debug mode is specified in environment variables. 2016-09-05 10:05:00 +02:00
Rolf Bjarne Kvinge 18a5b4eccb [runtime] Make the debugger mode an enum instead of bool to allow more than two debugger modes. 2016-09-05 10:05:00 +02:00
Rolf Bjarne Kvinge d11b3f2761 [runtime] Only enable debugging on watchOS devices if a native debugger is also attached.
Launching a watchOS extension on device with the managed debugger
attached is slow, which means that the launch watchdog will kick in
and kill the app before it has launched.

So we attach the native debugger as well, which prevents the launch
watchdog from killing the app. Incidentally it also makes watchOS
not background the app.

We're using private API to determine whether a native debugger is
attached, but it's only in debug code, and as such would not be
included in release builds for customer apps. Also the code is
currently limited to watchOS since it's not needed on other
platforms for now.
2016-09-05 10:05:00 +02:00
Rolf Bjarne Kvinge 1d17cc6390 Add support for debugging over http. Fixes #41554.
The watchOS device has limited networking support; in particular
it does not allow inbound/output network connections using 'bind'
(kernel-level sandbox restrictions).

This means that we can't use BSD sockets to connect to the debugger
in the IDE on the desktop. Instead we create an http tunnel that
knows how to convert socket send/recv data into http requests on
both sides.

https://bugzilla.xamarin.com/show_bug.cgi?id=41554
2016-09-01 16:55:49 +02:00
Rolf Bjarne Kvinge 7a4536c8f0 [runtime] Check if debug mode is specified in environment variables. 2016-09-01 16:55:48 +02:00
Rolf Bjarne Kvinge 5a13600e20 [runtime] Make the debugger mode an enum instead of bool to allow more than two debugger modes. 2016-09-01 16:55:47 +02:00
Rolf Bjarne Kvinge 1b9c638020 [runtime] Only enable debugging on watchOS devices if a native debugger is also attached.
Launching a watchOS extension on device with the managed debugger
attached is slow, which means that the launch watchdog will kick in
and kill the app before it has launched.

So we attach the native debugger as well, which prevents the launch
watchdog from killing the app. Incidentally it also makes watchOS
not background the app.

We're using private API to determine whether a native debugger is
attached, but it's only in debug code, and as such would not be
included in release builds for customer apps. Also the code is
currently limited to watchOS since it's not needed on other
platforms for now.
2016-09-01 16:55:47 +02:00
Rolf Bjarne Kvinge 70f1346bf3 Create iOS 32-bit dylibs with min iOS version 8.0. Fixes #43102. (#731)
64-bit iOS 9+ devices have a pagesize of 16kb (even when running 32-bit apps).
This means all executable code must have sectors aligned to 16kb when running
on such devices.

The native linker uses the min iOS version to determine the sector alignment;
if min iOS version is < 8.0, then the sector alignment is 4k, otherwise 16k.

This means that when we create our 32-bit dylibs we must link them with a min
iOS version of 8.0, or they won't work on a 64-bit device in a 32-bit app (bug

So change our makefiles to link armv7[s] dylibs with min iOS version 8.0.

[1] https://bugzilla.xamarin.com/show_bug.cgi?id=43102
2016-09-01 15:45:23 +02:00
Alex Soto 209f4f3709 [GameplayKit] Update from Xcode8 Beta 1 to Beta 6 (#689)
Runtime
- Added support for Vector2d, Vector3d and Vector4d SIMD types
- Added support for GKBox, GKQuad and GKTriangle SIMD types

GameplayKit
- Apple introduced GKQuadTreeNode and GKQuadTree in Xcode 7.1 and
  removed those types in a later Xcode (7.2?) but we kept them around.
  Now apple introduced again both types but renamed them to GKQuadtreeNode
  and GKQuadtree (lowercase t), this is a breaking change and since we do
  care about binary compat we are just changing the registration name and
  keeping the same managed name deprecating old methods and introducing
  the new ones.
- Added tests for new SIMD types
2016-08-30 15:32:46 -04:00
Rolf Bjarne Kvinge 36ea73ca65 Share the same block descriptors between copies of a block. Fixes #43592. (#683)
In bug #43592 the following occurs:

* App calls an API that takes a block.
* We create a stack-based ObjC block based on the delegate the app provided.
  This block has a pointer to a block description, describing the block
  in question (including the signature of the block, as an ObjC-type
  encoded string). We allocate a new block description for every block.
* Apple's API stores the pointer to the signature string somewhere.
* Apple calls _Block_copy to get a heap-based block.
* We create a heap-based block, and copy the entire description into the
  new heap-based block (including a copy of the signature).
* Apple returns from the API, and then we free the stack-based block
  (and the descriptor, and thus the signature string in the descriptor).
* Apple uses the pointer to the signature stored previously to investigate
  the signature of the block, and crashes because this signature has been
  freed.

The assumption in Apple's code is that the description will never be freed,
which is true for any Xcode project (clang will always be able to create the
block description at compile-time and emit it in the binary, which means the
memory will never be freed). We could potentially do the same thing in the
static registrar, but we'd still need a solution when using the dynamic
registrar.

To fix this instead of copying the entire description structure when creating
a heap-based block from the stack-based block, we make the description ref-
counted, and just use the same description in the heap-based block.

The signature will now stay in memory until both the heap-based and stack-
based blocks have been freed, and we hope Apple doesn't have any API that
needs the signature after all the blocks for that signature have been freed.

https://bugzilla.xamarin.com/show_bug.cgi?id=43592
2016-08-26 19:22:38 +02:00
Chris Hamons 1c6e1959b7 [XM] Add support for disabling lldb attach on crash (#670)
- https://bugzilla.xamarin.com/show_bug.cgi?id=23482
2016-08-25 13:06:38 -05:00
Vincent Dondain 5999d9cc4e [modelio] Update for iOS 10 beta 1 (#606) 2016-08-19 13:55:59 -04:00
Vincent Dondain ddd1988f64 [spritekit] Update for iOS 10 beta 1 (#498)
* [spritekit] Update for iOS 10 beta 1

* [spritekit] Add missing MarshalDirective

* [runtime] Add missing simd function signatures

- Add matrix_float2x2 and matrix_float3x3 natives types.

* [introspection] Fix ApiSignatureTest

- We now avoid checking {?=[X]} encoded signatures.
- We now calculate the right size for matrix_float2x2, matrix_float3x3 and matrix_float4x4.
- Fix SKWarpGeometryGrid wrong bindings revealed by tests (IntPtr instead of Vector2).

* [monotouch-test] Add SKUniform and SKWarpGeometryGrid tests
2016-08-03 19:12:07 +02:00
Rolf Bjarne Kvinge eed9b5d8d0 [runtime] Specify if MONO_REGISTRY_PATH points to a directory or not. Fixes #37794. (#514)
The [NSURL URLByAppendingPathComponent:] will try and check if a file:///
url is point to a directory or not, and in that process it will read metadata
about the file, which strangely enough makes macOS create a new thread.

Just after calling URLByAppendingPathComponent: we will call setenv to set
MONO_REGISTRY_PATH to the calculated path.

At the same time (sometimes _exactly_ at the same time) the new thread will
read the current environment variables.

Since getenv/setenv isn't thread-safe (!!!), there's a race condition here
that may once in a while cause a crash (bug #37794).

So instead of calling URLByAppendingPathComponent: we call
URLByAppendingPathComponent:isDirectory:, thus telling the API
if the resulting path is a directory or not, which means it doesn't
have to check (and won't create any new threads).

So with this change Xamarin.Mac apps are effectively single-threaded
until we're done setting environment variables.

https://bugzilla.xamarin.com/show_bug.cgi?id=37794
2016-08-01 16:14:21 +02:00
Rolf Bjarne Kvinge 1c8a8db412 [runtime] Make sure to call mono_gc_init_finalizer_thread for watchOS. Fixes #42780. (#504)
https://bugzilla.xamarin.com/show_bug.cgi?id=42780
2016-07-28 09:56:55 +02:00
Rolf Bjarne Kvinge 8afea75ead [runtime] Make sure to call mono_gc_init_finalizer_thread for watchOS. Fixes #42780. (#502)
https://bugzilla.xamarin.com/show_bug.cgi?id=42780
2016-07-27 17:54:01 +02:00
Rolf Bjarne Kvinge 22921dd8b7 [runtime] Fix a crash that occurs when Objective-C holds weak references. Fixes #39236. (#501)
Fix xamarin_switch_gchandle to not crash if the gchandle happens
to point to null (a collected object).

https://bugzilla.xamarin.com/show_bug.cgi?id=39236
2016-07-27 17:43:28 +02:00
Rolf Bjarne Kvinge 6e1f5c631b [runtime] Fix a crash that occurs when Objective-C holds weak references. Fixes #39236. (#500)
Fix xamarin_switch_gchandle to not crash if the gchandle happens
to point to null (a collected object).

https://bugzilla.xamarin.com/show_bug.cgi?id=39236
2016-07-27 12:47:35 +02:00
Rolf Bjarne Kvinge 774fdf80b6 [runtime] Set base directory and config file name for extensions. Fixes #42784. (#493)
The base directory and config file name is normally set automatically
when we ask Mono to execute the Main function, but in the case of extensions,
there is no Main function, so these values are not set, causing some
features (reflection-only assembly load) to not work correctly.

https://bugzilla.xamarin.com/show_bug.cgi?id=42784
2016-07-26 11:39:33 -04:00
Rolf Bjarne Kvinge 6e41b65f95 [runtime] Set base directory and config file name for extensions. Fixes #42784. (#489)
The base directory and config file name is normally set automatically
when we ask Mono to execute the Main function, but in the case of extensions,
there is no Main function, so these values are not set, causing some
features (reflection-only assembly load) to not work correctly.

https://bugzilla.xamarin.com/show_bug.cgi?id=42784
2016-07-26 15:51:31 +02:00
Rolf Bjarne Kvinge e6fc5a15d0 [runtime] Parse unions in objc encodings correctly. Fixes #42452. (#394)
Unions are defined as follows:

    (name=type...)

and we were not correctly parsing the 'name=' part.

https://bugzilla.xamarin.com/show_bug.cgi?id=42452
2016-07-14 18:03:02 +02:00
Rolf Bjarne Kvinge 249cf2f402 [runtime] Parse unions in objc encodings correctly. Fixes #42452. (#382)
Unions are defined as follows:

    (name=type...)

and we were not correctly parsing the 'name=' part.

https://bugzilla.xamarin.com/show_bug.cgi?id=42452
2016-07-12 20:19:06 -04:00
Rolf Bjarne Kvinge 905a6bc03c [runtime] Fix watchOS debugging. (#318)
Don't call any COOP macros when configuring the debugger/profiler.

This occurs before the root domain has been created, which means
that the current thread can't be attached.

Since the COOP macros assert that the thread is attached,
we end up aborting:

    Jun 29 13:35:56 Rolfs-Mac-Pro monotouchtest[97569]: Cannot enter GC safe region if the thread is not attached

    Thread 2 Crashed:
    0   libsystem_kernel.dylib        	0x08753572 __pthread_kill + 10
    1   libsystem_pthread.dylib       	0x0871b654 pthread_kill + 101
    2   libsystem_c.dylib             	0x084a962d abort + 156
    3   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x0033901f monoeg_log_default_handler + 159
    4   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00339087 monoeg_g_log + 103 (goutput.c:114)
    5   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00329e00 check_info + 96 (mono-threads-coop.c:93)
    6   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00329b3d mono_threads_enter_gc_safe_region_unbalanced_with_info + 45 (mono-threads-coop.c:230)
    7   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00329a7a mono_threads_enter_gc_safe_region_with_info + 26 (mono-threads-coop.c:204)
    8   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00329a4b mono_threads_enter_gc_safe_region + 27 (mono-threads-coop.c:193)
    9   com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x0035e2d2 recv_uninterrupted(int, void*, int) + 50 (monotouch-debug.m:402)
    10  com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x0035e531 monotouch_process_connection(int) + 193 (monotouch-debug.m:828)
    11  com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x0035e0cf monotouch_connect_wifi(NSMutableArray*) + 2815 (monotouch-debug.m:604)
    12  com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x0035cb42 monotouch_configure_debugging + 3858 (monotouch-debug.m:344)
    13  com.xamarin.monotouch-test.watchkitapp.watchkitextension	0x00351d37 -[CocoaThreadInitializer entryPoint:] + 119 (shared.m:131)
    14  com.apple.Foundation          	0x01d30259 -[NSThread main] + 76
    15  com.apple.Foundation          	0x01de5484 __NSThread__start__ + 1346
    16  libsystem_pthread.dylib       	0x08718780 _pthread_body + 138
    17  libsystem_pthread.dylib       	0x087186f6 _pthread_start + 155
    18  libsystem_pthread.dylib       	0x08715f7a thread_start + 34
2016-06-29 08:45:43 -07:00
Rolf Bjarne Kvinge 386c15c503 Merge pull request #153 from rolfbjarne/more-exceptions
Handle any exceptions when returning from managed code back to our native runtime.
2016-06-09 18:13:23 +02:00
Chris Hamons b7a797b068 [XM] Dynamically look up NSExtensionMain to unbreak pre-10.10 XM apps (#154)
* [XM] Dynamically look up NSExtensionMain to unbreak pre-10.10 XM apps

- So having a simple reference to NSExtensionMain is enough for /usr/lib/libextension.dylib to get added as a reference to libxammac.dylib
- If you have a reference to /usr/lib/libextension.dylib then any XM app (including our tests) bomb out on startup. This is suboptimal.
- So dlopen/dysm our way to victory.

* Fix spacing
2016-06-09 00:19:16 +02:00
Rolf Bjarne Kvinge b9629ac8ba [runtime] Improve documentation about exceptions a little bit. 2016-06-08 20:11:07 +02:00
Rolf Bjarne Kvinge 2d28e24837 [runtime] Handle any exceptions whenever we return from managed code. 2016-06-08 20:05:54 +02:00
Rolf Bjarne Kvinge 5e302f9719 [runtime] Catch and process managed exceptions that are thrown in reverse P/Invoke (delegate) callbacks. 2016-06-08 20:05:54 +02:00
Rolf Bjarne Kvinge 71f4d78b18 [runtime] Generated binding wrappers that catch ObjC exceptions are supposed to always convert to managed exceptions. (#133) 2016-06-06 14:33:37 +02:00
Rolf Bjarne Kvinge db68e69a1d [runtime] Support binding NSObjects as IntPtr. Fixes #41132. (#103)
Support binding NSObjects as IntPtr. This is usually not
a problem, because when we fetch the ObjC signature for a
method, we usually get the signature as exported by us,
(in which case a parameter bound as 'IntPtr' would be treated
as 'void *' in the dynamic registrar) *except* when the
selector corresponds with a protocol the type implements,
in which case we get the signature as defined in the protocol.

https://bugzilla.xamarin.com/show_bug.cgi?id=41132
2016-05-31 11:58:27 +02:00
Rolf Bjarne Kvinge c9bcf1f56d [runtime] Mark all the new Mono API we're using for coop as optional. (#100)
This fixes Xamarin.Mac apps using older system monos.
2016-05-30 15:27:02 +02:00
Rolf Bjarne Kvinge 0b24bc0b8d [runtime] Fix boolean logic for thread attach/detach implementation. 2016-05-27 10:35:05 +02:00
Rolf Bjarne Kvinge e1464027f2 [runtime] Make new functions optional so that they don't hang XM apps using system mono at launch. 2016-05-26 17:47:44 +02:00
Rolf Bjarne Kvinge 5054c1ee45 [runtime] Update thread attach/detach according to mono changes.
* Restore the mono_jit_thread_attach signature to how it's in
  the latest stable.

* Don't use the new attach/detach methods when using the dynamic
  mono runtime, since the methods aren't available in any released
  version of mono. Also XM doesn't support coop yet, so it's not
  needed.

* And finally don't use the new attach/detach methods for anything
  that isn't building using mono/master (iow only watchOS). This
  should be changed once the rest of the products starts using
  mono/master again.
2016-05-26 17:47:44 +02:00
Zoltan Varga 5270b63cee [runtime] Use the same coop gc macro names as mono master does. 2016-05-26 17:47:10 +02:00
Zoltan Varga 8b59d42144 Make the sdb send/receive functions run in gc safe mode. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge 13b7c6dd11 [runtime] Make sure to switch to GC SAFE before calling xamarin_switch_gchandle. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge ac8d493581 [runtime] Attach the current thread in xamarin_invoke_trampoline.
It's entirely possible to call xamarin_invoke_trampoline on a
thread we've never heard about before.
2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge 4a5ce42b48 [runtime] Add a MONO_ASSERT_GC_SAFE_OR_DETACHED.
Since MONO_ASSERT_GC_SAFE asserts when executed on a detached thread,
and yet it's clearly safe for the GC to run when a thread is detached.
2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge d7bdc5d126 [runtime] mono_set_pending_exception expects to be in GC Unsafe mode. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge af0d01c93a Initial review pass for COOP for watchOS. 2016-05-26 17:47:10 +02:00