Вернуть значение из ассемблера в C# через С в Linux x64
|
|
Четверг, 17 Сентября 2020 г. 11:00
+ в цитатник
Sunless:
#define EXPORT __attribute__((visibility("default")))
EXPORT int foo(void);
int foo(void)
{
extern int _start();
return 1;
}
.text
.globl _start
_start:
movq 1, %rax
movq , %rdi
syscall
using System.Runtime.InteropServices;
class Program{
[DllImport("lib.so")] public static extern int foo ();
static void Main(string[] args)
{
int code = foo();
System.Console.WriteLine(code);
}
}
Тут я делаю gcc -shared -fpic -o lib.so my.c asm.s
затем dotnet run
и получаю в консоли 1
Если верну в Си return _start();, то получаю сообщение Hosting components are already initialized. Re-initialization to execute an app is not allowed.
https://forum.sources.ru/index.php?showtopic=416410&view=findpost&p=3838926
Метки:
Assembler
-
Запись понравилась
-
0
Процитировали
-
0
Сохранили
-