From 19c523704f05daf9faecaa9f033058611e1cb032 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 13 Jun 2017 20:29:48 +0200 Subject: [PATCH] Fix stack overflow when running on Linux Java.Interop native code is built with `-std=c99` which, on Linux, makes the `strdup(3)` and `realpath(3)` functions undeclared (they're not part of the C99 standard). This posesa problem since both of them return pointers and the assumed return value for an undeclared function is an `int` - when running on a 64-bit system the "integer" is cast to a pointer so that the high 32-bits of the resulting value are set to 1 thus creating an invalid pointer. This commit makes sure both functions are declared. The commit also removes call to `gettid` which does not have a wrapper in glibc and should be called directly using `syscall(2)` --- src/java-interop/java-interop-gc-bridge-mono.c | 3 ++- src/java-interop/java-interop.mdproj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/java-interop/java-interop-gc-bridge-mono.c b/src/java-interop/java-interop-gc-bridge-mono.c index 5cbf18cf9..e43e36222 100644 --- a/src/java-interop/java-interop-gc-bridge-mono.c +++ b/src/java-interop/java-interop-gc-bridge-mono.c @@ -9,6 +9,7 @@ #include "java-interop-mono.h" #ifdef __linux__ + #include #include #endif /* !defined (__linux__) */ @@ -1178,7 +1179,7 @@ get_thread_id (void) return _mono_thread_get_managed_id (thread); } #if __linux__ - int64_t tid = gettid (); + int64_t tid = (int64_t)((pid_t)syscall(SYS_gettid)); #else int64_t tid = (int64_t) pthread_self (); #endif diff --git a/src/java-interop/java-interop.mdproj b/src/java-interop/java-interop.mdproj index 978ccba0d..33d4b613c 100644 --- a/src/java-interop/java-interop.mdproj +++ b/src/java-interop/java-interop.mdproj @@ -116,7 +116,7 @@ <_Files>@(Compile -> '%(Identity)', ' ') - +