mono / mono.posix

POSIX/Unix interface for Mono, .NET and .NET Core. Provides functionality for managed code to access POSIX/Unix features not accessible via the BCL. This repository supersedes the older code in https://github.com/mono/mono
MIT License
40 stars 9 forks source link

execve doesn't work, string array isn't being marshaled right. #36

Closed kjpgit closed 1 year ago

kjpgit commented 1 year ago

using Mono.Unix.Native;

string program = "vim"; string[] args = {"hello.txt", ""}; int ret = Syscall.execv(program, args);

strace: 187570 execve("vim", ["hello.txt", "", 0x7fc16f6e6e00, 0x81], 0x7ffcfed411c8 / 39 vars /) = -1 EFAULT (Bad address)

.net 8 preview 7, linux, "Mono.Posix" Version="7.1.0-final.1.21458.1"

kjpgit commented 1 year ago

Same with Mono.Posix.NETStandard 1.0.

188813 execve("vim", ["hello.txt", "", "\20\235\356\317jU", 0x191], 0x7ffe670a4818 / 39 vars /) = -1 EFAULT (Bad address)

kjpgit commented 1 year ago

I'm hoping this isn't an 18 year old cursed comment?

    **// TODO: does Mono marshal arrays properly?**
    [DllImport (LIBC, SetLastError=true)]
    public static extern int execve (
            [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))]
            string path, string[] argv, string[] envp);
kjpgit commented 1 year ago

I figured it out. The string[] arrays need a NULL in the last element.