diff options
author | Miguel de Icaza <miguel@gnome.org> | 2018-02-14 05:48:53 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2018-02-14 20:53:08 +0300 |
commit | 47187bbc9b552f6ca5b2d80a2be6c7395b40da9e (patch) | |
tree | b40736eb56e09c29330abb4a163a57b1a1dea196 /mcs/class/Mono.Posix | |
parent | 57f3f34e60ee6d17fb1dada4b8799f3d753ca2b0 (diff) |
[Mono.Posix] .NET Core compatibility - Use [In,Out] for arrays of structures
While Mono does copy the values of arrays back when they are marshaled
to unmanaged code, .NET does not seem to be doing this, and manifests
as the Syscall.poll invocation in Mono.Posix with .NET Core does not update
the values in the provided array.
The following example should print "Got 1 and 1" with the following command:
```
echo foo | dotnet run
```
But instead prints 0 and 1 on .NET Core, but the correct result with Mono.
This patch is going here for the sake of the Mono.Posix.NetCore package that
we publish.
Sample:
```
using System;
using System.Runtime.InteropServices;
class X {
private struct _pollfd {
public int fd;
public short events;
public short revents;
}
[DllImport("libc")]
static extern int poll ([In,Out]_pollfd[] ufds, uint nfds, int timeout);
static void Main ()
{
var p2 = new _pollfd [1] { new _pollfd () { fd = 0, events = 1 } };
var m = poll (p2, 1, -1);
Console.WriteLine ("Got: {0} and {1}", n, pollmap [0].revents);
Console.ReadLine ();
}
}
```
Diffstat (limited to 'mcs/class/Mono.Posix')
-rw-r--r-- | mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs index c750e5fa86b..a919644f85d 100644 --- a/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs +++ b/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs @@ -3783,7 +3783,7 @@ namespace Mono.Unix.Native { public static extern int epoll_ctl (int epfd, EpollOp op, int fd, ref EpollEvent ee); [DllImport (LIBC, SetLastError=true, EntryPoint="epoll_wait")] - private static extern int sys_epoll_wait (int epfd, EpollEvent [] ee, int maxevents, int timeout); + private static extern int sys_epoll_wait (int epfd, [In,Out] EpollEvent [] ee, int maxevents, int timeout); #endregion #region <sys/mman.h> Declarations @@ -3866,7 +3866,7 @@ namespace Mono.Unix.Native { #pragma warning restore 649 [DllImport (LIBC, SetLastError=true, EntryPoint="poll")] - private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout); + private static extern int sys_poll ([In,Out] _pollfd[] ufds, uint nfds, int timeout); public static int poll (Pollfd [] fds, uint nfds, int timeout) { |