diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index be8893864a5..b24fddb7785 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -408,6 +408,11 @@ task array_to_any(type: RunKonanTest) { source = "codegen/basics/array_to_any.kt" } +task runtime_basic_exit(type: RunKonanTest) { + source = "runtime/basic/exit.kt" + expectedExitStatus = 42 +} + task hello0(type: RunKonanTest) { goldValue = "Hello, world!\n" source = "runtime/basic/hello0.kt" diff --git a/backend.native/tests/runtime/basic/exit.kt b/backend.native/tests/runtime/basic/exit.kt new file mode 100644 index 00000000000..42d062ea051 --- /dev/null +++ b/backend.native/tests/runtime/basic/exit.kt @@ -0,0 +1,5 @@ +import kotlin.system.* + +fun main(args: Array) { + exitProcess(42) +} \ No newline at end of file diff --git a/runtime/src/main/cpp/Natives.cpp b/runtime/src/main/cpp/Natives.cpp index 2615abd770d..cc34af90846 100644 --- a/runtime/src/main/cpp/Natives.cpp +++ b/runtime/src/main/cpp/Natives.cpp @@ -66,4 +66,8 @@ void Kotlin_interop_free(void* ptr) { konan::free(ptr); } +void Kotlin_system_exitProcess(KInt status) { + exit(status); +} + } // extern "C" diff --git a/runtime/src/main/kotlin/kotlin/system/Process.kt b/runtime/src/main/kotlin/kotlin/system/Process.kt new file mode 100644 index 00000000000..38947054d21 --- /dev/null +++ b/runtime/src/main/kotlin/kotlin/system/Process.kt @@ -0,0 +1,11 @@ +package kotlin.system + +/** + * Terminates the currently running process. + * The argument serves as a status code; by convention, + * a nonzero status code indicates abnormal termination. + * + * This method never returns normally. + */ +@SymbolName("Kotlin_system_exitProcess") +public external fun exitProcess(status: Int): Nothing \ No newline at end of file