With a learning type project I am developing ( <ht...
# kotlin-native
n
With a learning type project I am developing ( https://gitlab.com/napperley/containers ) it is partially based on this article: https://cesarvr.github.io/post/2018-05-22-create-containers/ There is a strange issue occurring where after running the Kotlin Native program a seg fault occurs in the child process, yet no seg fault occurs in the parent process. With the child process the seg fault seems to occur when calling a function from the POSIX library which is weird. Below is the function that represents the child process:
Copy code
@Suppress("UNUSED_PARAMETER")
private fun runContainer(args: COpaquePointer?): Int {
    // Seg fault occurs on the line below.
    println("Hello from Child! (PID: ${getpid()})")
    // Remove all environment variables for this process.
    clearenv()
    // Load the shell process.
    val rc = runProgram("/bin/sh")
    return if (rc == -1) EXIT_FAILURE else EXIT_SUCCESS
}
@Pavel Kunyavskiy [JB] - Has the Kotlin Native team done any testing with the experimental memory model in multi process use cases (using one of the Linux targets)?
p
Probably not. And I'm quite sure it wouldn't work out-of-box, as only calling thread is cloned to the new process, while others are not, and lots of internal machinery is totally unready for that, as for thread id changes.
Also, it seams you have a bug in runProgram function - it should add null as last array element. This could lead to interesting problems too.
n
Aren't Kotlin Arrays null terminated?
Kotlin Native doesn't seem to have the functionality to move an allocated C Pointer. For example, point an existing C Pointer to the end so it can be used like stack memory. Luckily I have found a workaround which involves moving the pointer on the C side in a def file: https://gitlab.com/napperley/containers/-/blob/master/src/nativeInterop/cinterop/scheduler.def#L5