You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -39,6 +39,7 @@ MPH_UNIX_SOURCE = \
|
||||
serial.c \
|
||||
sys-mman.c \
|
||||
sys-sendfile.c \
|
||||
sys-socket.c \
|
||||
sys-stat.c \
|
||||
sys-statvfs.c \
|
||||
sys-time.c \
|
||||
@@ -135,12 +136,14 @@ refresh:
|
||||
--impl-macro=_GNU_SOURCE --impl-macro=_XOPEN_SOURCE \
|
||||
--impl-header="<sys/types.h>" \
|
||||
--impl-header="<sys/stat.h>" \
|
||||
--autoconf-header="<netinet/in.h>" \
|
||||
--autoconf-header="<sys/time.h>" \
|
||||
--autoconf-header="<sys/poll.h>" \
|
||||
--autoconf-header="<sys/wait.h>" \
|
||||
--autoconf-header="<sys/statvfs.h>" \
|
||||
--autoconf-header="<sys/xattr.h>" \
|
||||
--autoconf-header="<sys/mman.h>" \
|
||||
--autoconf-header="<sys/socket.h>" \
|
||||
--autoconf-header="<sys/uio.h>" \
|
||||
--autoconf-header="<unistd.h>" \
|
||||
--impl-header="<fcntl.h>" \
|
||||
@@ -158,7 +161,7 @@ refresh:
|
||||
--rename-member=st_mtime=st_mtime_ \
|
||||
--rename-namespace=Mono.Unix.Native=Mono.Posix \
|
||||
--library=MonoPosixHelper \
|
||||
$(mcs_topdir)/class/lib/net_4_5/Mono.Posix.dll map
|
||||
$(mcs_topdir)/class/lib/net_4_x/Mono.Posix.dll map
|
||||
|
||||
# Useful if mono is compiled with --enable-shared=no
|
||||
patch-libtool:
|
||||
|
||||
@@ -136,20 +136,21 @@ libMonoPosixHelper_la_DEPENDENCIES = $(am__DEPENDENCIES_2) \
|
||||
am__libMonoPosixHelper_la_SOURCES_DIST = errno.c map.c map.h mph.h \
|
||||
signal.c stdio.c string.c stdlib.c dirent.c fcntl.c fstab.c \
|
||||
grp.c macros.c nl.c nl.h old-map.c old-map.h pwd.c serial.c \
|
||||
sys-mman.c sys-sendfile.c sys-stat.c sys-statvfs.c sys-time.c \
|
||||
sys-uio.c sys-utsname.c sys-wait.c sys-xattr.c syslog.c time.c \
|
||||
unistd.c utime.c x-struct-str.c zlib-helper.c adler32.c \
|
||||
compress.c crc32.c uncompr.c deflate.c trees.c zutil.c \
|
||||
inflate.c infback.c inftrees.c inffast.c crc32.h deflate.h \
|
||||
inffast.h inffixed.h inflate.h inftrees.h trees.h zconf.h \
|
||||
zlib.h zutil.h minizip/crypt.h minizip/ioapi.c minizip/ioapi.h \
|
||||
minizip/unzip.c minizip/unzip.h minizip/zip.c minizip/zip.h
|
||||
sys-mman.c sys-sendfile.c sys-socket.c sys-stat.c \
|
||||
sys-statvfs.c sys-time.c sys-uio.c sys-utsname.c sys-wait.c \
|
||||
sys-xattr.c syslog.c time.c unistd.c utime.c x-struct-str.c \
|
||||
zlib-helper.c adler32.c compress.c crc32.c uncompr.c deflate.c \
|
||||
trees.c zutil.c inflate.c infback.c inftrees.c inffast.c \
|
||||
crc32.h deflate.h inffast.h inffixed.h inflate.h inftrees.h \
|
||||
trees.h zconf.h zlib.h zutil.h minizip/crypt.h minizip/ioapi.c \
|
||||
minizip/ioapi.h minizip/unzip.c minizip/unzip.h minizip/zip.c \
|
||||
minizip/zip.h
|
||||
am__objects_1 = errno.lo map.lo signal.lo stdio.lo string.lo stdlib.lo
|
||||
am__objects_2 = dirent.lo fcntl.lo fstab.lo grp.lo macros.lo nl.lo \
|
||||
old-map.lo pwd.lo serial.lo sys-mman.lo sys-sendfile.lo \
|
||||
sys-stat.lo sys-statvfs.lo sys-time.lo sys-uio.lo \
|
||||
sys-utsname.lo sys-wait.lo sys-xattr.lo syslog.lo time.lo \
|
||||
unistd.lo utime.lo x-struct-str.lo
|
||||
sys-socket.lo sys-stat.lo sys-statvfs.lo sys-time.lo \
|
||||
sys-uio.lo sys-utsname.lo sys-wait.lo sys-xattr.lo syslog.lo \
|
||||
time.lo unistd.lo utime.lo x-struct-str.lo
|
||||
@HOST_WIN32_FALSE@am__objects_3 = $(am__objects_1) $(am__objects_2)
|
||||
@HOST_WIN32_TRUE@am__objects_3 = $(am__objects_1)
|
||||
am__objects_4 = adler32.lo compress.lo crc32.lo uncompr.lo deflate.lo \
|
||||
@@ -249,8 +250,6 @@ AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BOEHM_DEFINES = @BOEHM_DEFINES@
|
||||
BUILD_EXEEXT = @BUILD_EXEEXT@
|
||||
BUILD_GLIB_CFLAGS = @BUILD_GLIB_CFLAGS@
|
||||
BUILD_GLIB_LIBS = @BUILD_GLIB_LIBS@
|
||||
CC = @CC@
|
||||
CCAS = @CCAS@
|
||||
CCASDEPMODE = @CCASDEPMODE@
|
||||
@@ -266,9 +265,9 @@ CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFAULT_PROFILE = @DEFAULT_PROFILE@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DISABLE_SHARED_HANDLES = @DISABLE_SHARED_HANDLES@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DOLT_BASH = @DOLT_BASH@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
@@ -286,8 +285,6 @@ GDKX11 = @GDKX11@
|
||||
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
|
||||
GLIB_CFLAGS = @GLIB_CFLAGS@
|
||||
GLIB_LIBS = @GLIB_LIBS@
|
||||
GMODULE_CFLAGS = @GMODULE_CFLAGS@
|
||||
GMODULE_LIBS = @GMODULE_LIBS@
|
||||
GMSGFMT = @GMSGFMT@
|
||||
GMSGFMT_015 = @GMSGFMT_015@
|
||||
GREP = @GREP@
|
||||
@@ -485,6 +482,7 @@ MPH_UNIX_SOURCE = \
|
||||
serial.c \
|
||||
sys-mman.c \
|
||||
sys-sendfile.c \
|
||||
sys-socket.c \
|
||||
sys-stat.c \
|
||||
sys-statvfs.c \
|
||||
sys-time.c \
|
||||
@@ -683,6 +681,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/supportw.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-mman.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-sendfile.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-socket.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-stat.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-statvfs.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys-time.Plo@am__quote@
|
||||
@@ -956,12 +955,14 @@ refresh:
|
||||
--impl-macro=_GNU_SOURCE --impl-macro=_XOPEN_SOURCE \
|
||||
--impl-header="<sys/types.h>" \
|
||||
--impl-header="<sys/stat.h>" \
|
||||
--autoconf-header="<netinet/in.h>" \
|
||||
--autoconf-header="<sys/time.h>" \
|
||||
--autoconf-header="<sys/poll.h>" \
|
||||
--autoconf-header="<sys/wait.h>" \
|
||||
--autoconf-header="<sys/statvfs.h>" \
|
||||
--autoconf-header="<sys/xattr.h>" \
|
||||
--autoconf-header="<sys/mman.h>" \
|
||||
--autoconf-header="<sys/socket.h>" \
|
||||
--autoconf-header="<sys/uio.h>" \
|
||||
--autoconf-header="<unistd.h>" \
|
||||
--impl-header="<fcntl.h>" \
|
||||
@@ -979,7 +980,7 @@ refresh:
|
||||
--rename-member=st_mtime=st_mtime_ \
|
||||
--rename-namespace=Mono.Unix.Native=Mono.Posix \
|
||||
--library=MonoPosixHelper \
|
||||
$(mcs_topdir)/class/lib/net_4_5/Mono.Posix.dll map
|
||||
$(mcs_topdir)/class/lib/net_4_x/Mono.Posix.dll map
|
||||
|
||||
# Useful if mono is compiled with --enable-shared=no
|
||||
patch-libtool:
|
||||
|
||||
@@ -1 +1 @@
|
||||
737c217727585521e981daf3f93ed8c7b5eb1f7b
|
||||
ee61ae661d9be7e741c0997fdf7e6de54ccc5d9a
|
||||
@@ -1 +1 @@
|
||||
9c170eac0dc5faf2d525c4e40aa2121080901830
|
||||
9f89fcde93b94c6326a863c767ea2ff2b4b877c7
|
||||
@@ -149,6 +149,13 @@ typedef gint64 suseconds_t;
|
||||
return ret; \
|
||||
}}G_STMT_END
|
||||
|
||||
#define mph_have_uint_overflow(var) ((var) < 0 || (var) > UINT_MAX)
|
||||
|
||||
#define mph_return_val_if_uint_overflow(var, ret) \
|
||||
_mph_return_val_if_cb_(var, ret, mph_have_uint_overflow)
|
||||
|
||||
#define mph_return_if_uint_overflow(var) mph_return_val_if_uint_overflow(var, -1)
|
||||
|
||||
#define mph_have_long_overflow(var) ((var) > LONG_MAX || (var) < LONG_MIN)
|
||||
|
||||
#define mph_return_val_if_long_overflow(var, ret) \
|
||||
@@ -156,14 +163,14 @@ typedef gint64 suseconds_t;
|
||||
|
||||
#define mph_return_if_long_overflow(var) mph_return_val_if_long_overflow(var, -1)
|
||||
|
||||
#define mph_have_ulong_overflow(var) ((var) > ULONG_MAX)
|
||||
#define mph_have_ulong_overflow(var) (var) < 0 || ((var) > ULONG_MAX)
|
||||
|
||||
#define mph_return_val_if_ulong_overflow(var, ret) \
|
||||
_mph_return_val_if_cb_(var, ret, mph_have_ulong_overflow)
|
||||
|
||||
#define mph_return_if_ulong_overflow(var) mph_return_val_if_ulong_overflow(var, -1)
|
||||
|
||||
#define mph_have_size_t_overflow(var) ((var) > MPH_SIZE_T_MAX)
|
||||
#define mph_have_size_t_overflow(var) ((var) < 0 || (var) > MPH_SIZE_T_MAX)
|
||||
|
||||
#define mph_return_val_if_size_t_overflow(var, ret) \
|
||||
_mph_return_val_if_cb_(var, ret, mph_have_size_t_overflow)
|
||||
@@ -185,6 +192,8 @@ typedef gint64 suseconds_t;
|
||||
|
||||
#define mph_return_if_time_t_overflow(var) mph_return_if_long_overflow(var)
|
||||
|
||||
#define mph_return_if_socklen_t_overflow(var) mph_return_if_uint_overflow(var)
|
||||
|
||||
#define mph_return_if_val_in_list5(var,a,b,c,d,e) \
|
||||
do { \
|
||||
int v = (var); \
|
||||
|
||||
@@ -34,7 +34,11 @@
|
||||
|
||||
/* sys/time.h (for timeval) is required when using osx 10.3 (but not 10.4) */
|
||||
/* IOKit is a private framework in iOS, so exclude there */
|
||||
#if defined(__APPLE__) && !defined(HOST_IOS)
|
||||
#if defined(__APPLE__) && !defined(HOST_IOS) && !defined(HOST_WATCHOS) && !defined(HOST_APPLETVOS)
|
||||
#define HAVE_IOKIT 1
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_IOKIT)
|
||||
#include <sys/time.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/serial/IOSerialKeys.h>
|
||||
@@ -384,7 +388,7 @@ set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStop
|
||||
if (cfsetospeed (&newtio, baud_rate) < 0 || cfsetispeed (&newtio, baud_rate) < 0)
|
||||
return FALSE;
|
||||
} else {
|
||||
#if __linux__ || (defined(__APPLE__) && !defined(HOST_IOS))
|
||||
#if __linux__ || defined(HAVE_IOKIT)
|
||||
|
||||
/* On Linux to set a custom baud rate, we must set the
|
||||
* "standard" baud_rate to 38400. On Apple we set it purely
|
||||
@@ -417,7 +421,7 @@ set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStop
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#elif defined(__APPLE__) && !defined(HOST_IOS)
|
||||
#elif defined(HAVE_IOKIT)
|
||||
speed_t speed = baud_rate;
|
||||
if (ioctl(fd, IOSSIOSPEED, &speed) == -1)
|
||||
return FALSE;
|
||||
|
||||
214
support/signal.c
214
support/signal.c
@@ -107,23 +107,28 @@ int Mono_Posix_FromRealTimeSignum (int offset, int *r)
|
||||
|
||||
#ifndef HOST_WIN32
|
||||
|
||||
// Atomicity rules: Fields of signal_info read or written by the signal handler
|
||||
// (see UnixSignal.cs) should be read and written using atomic functions.
|
||||
// (For simplicity, we're protecting some things we don't strictly need to.)
|
||||
|
||||
// Because we are in MonoPosixHelper, we are banned from linking mono.
|
||||
// We can still use atomic.h because that's all inline functions--
|
||||
// unless WAPI_NO_ATOMIC_ASM is defined, in which case atomic.h calls linked functions.
|
||||
#ifndef WAPI_NO_ATOMIC_ASM
|
||||
#define mph_int_get(p) InterlockedExchangeAdd ((p), 0)
|
||||
#define mph_int_inc(p) InterlockedIncrement ((p))
|
||||
#define mph_int_dec_test(p) (InterlockedDecrement ((p)) == 0)
|
||||
#define mph_int_set(p,o,n) InterlockedExchange ((p), (n))
|
||||
#define mph_int_set(p,n) InterlockedExchange ((p), (n))
|
||||
// Pointer, original, new
|
||||
#define mph_int_test_and_set(p,o,n) (o == InterlockedCompareExchange ((p), (n), (o)))
|
||||
#elif GLIB_CHECK_VERSION(2,4,0)
|
||||
#define mph_int_get(p) g_atomic_int_get ((p))
|
||||
#define mph_int_inc(p) do {g_atomic_int_inc ((p));} while (0)
|
||||
#define mph_int_dec_test(p) g_atomic_int_dec_and_test ((p))
|
||||
#define mph_int_set(p,o,n) do { \
|
||||
while (!g_atomic_int_compare_and_exchange ((p), (o), (n))) {} \
|
||||
} while (0)
|
||||
#define mph_int_set(p,n) g_atomic_int_set ((p),(n))
|
||||
#define mph_int_test_and_set(p,o,n) g_atomic_int_compare_and_exchange ((p), (o), (n))
|
||||
#else
|
||||
#define mph_int_get(p) (*(p))
|
||||
#define mph_int_inc(p) do { (*(p))++; } while (0)
|
||||
#define mph_int_dec_test(p) (--(*(p)) == 0)
|
||||
#define mph_int_set(p,o,n) do { *(p) = n; } while (0)
|
||||
#error "GLIB 2.4 required because building without ASM atomics"
|
||||
#endif
|
||||
|
||||
#if HAVE_PSIGNAL
|
||||
@@ -166,6 +171,90 @@ keep_trying (int r)
|
||||
return r == -1 && errno == EINTR;
|
||||
}
|
||||
|
||||
// This tiny ad-hoc read/write lock is needed because of the very specific
|
||||
// synchronization needed between default_handler and teardown_pipes:
|
||||
// - Many default_handlers can be running at once
|
||||
// - The signals_mutex already ensures only one teardown_pipes runs at once
|
||||
// - If teardown_pipes starts while a default_handler is ongoing, it must block
|
||||
// - If default_handler starts while a teardown_pipes is ongoing, it must *not* block
|
||||
// Locks are implemented as ints.
|
||||
|
||||
// The lock is split into a teardown bit and a handler count (sign bit unused).
|
||||
// There is a teardown running or waiting to run if the teardown bit is set.
|
||||
// There is a handler running if the handler count is nonzero.
|
||||
#define PIPELOCK_TEARDOWN_BIT ( (int)0x40000000 )
|
||||
#define PIPELOCK_COUNT_MASK (~((int)0xC0000000))
|
||||
#define PIPELOCK_GET_COUNT(x) ((x) & PIPELOCK_COUNT_MASK)
|
||||
#define PIPELOCK_INCR_COUNT(x, by) (((x) & PIPELOCK_TEARDOWN_BIT) | (PIPELOCK_GET_COUNT (PIPELOCK_GET_COUNT (x) + (by))))
|
||||
|
||||
static inline void
|
||||
acquire_pipelock_teardown (int *lock)
|
||||
{
|
||||
int lockvalue_draining;
|
||||
// First mark that a teardown is occurring, so handlers will stop entering the lock.
|
||||
while (1) {
|
||||
int lockvalue = mph_int_get (lock);
|
||||
lockvalue_draining = lockvalue | PIPELOCK_TEARDOWN_BIT;
|
||||
if (mph_int_test_and_set (lock, lockvalue, lockvalue_draining))
|
||||
break;
|
||||
}
|
||||
// Now wait for all handlers to complete.
|
||||
while (1) {
|
||||
if (0 == PIPELOCK_GET_COUNT (lockvalue_draining))
|
||||
break; // We now hold the lock.
|
||||
// Handler is still running, spin until it completes.
|
||||
sched_yield (); // We can call this because !defined(HOST_WIN32)
|
||||
lockvalue_draining = mph_int_get (lock);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
release_pipelock_teardown (int *lock)
|
||||
{
|
||||
while (1) {
|
||||
int lockvalue = mph_int_get (lock);
|
||||
int lockvalue_new = lockvalue & ~PIPELOCK_TEARDOWN_BIT;
|
||||
// Technically this can't fail, because we hold both the pipelock and the mutex, but
|
||||
if (mph_int_test_and_set (lock, lockvalue, lockvalue_new))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Return 1 for success
|
||||
static inline int
|
||||
acquire_pipelock_handler (int *lock)
|
||||
{
|
||||
while (1) {
|
||||
int lockvalue = mph_int_get (lock);
|
||||
if (lockvalue & PIPELOCK_TEARDOWN_BIT) // Final lock is being torn down
|
||||
return 0;
|
||||
int lockvalue_new = PIPELOCK_INCR_COUNT (lockvalue, 1);
|
||||
if (mph_int_test_and_set (lock, lockvalue, lockvalue_new))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
release_pipelock_handler (int *lock)
|
||||
{
|
||||
while (1) {
|
||||
int lockvalue = mph_int_get (lock);
|
||||
int lockvalue_new = PIPELOCK_INCR_COUNT (lockvalue, -1);
|
||||
if (mph_int_test_and_set (lock, lockvalue, lockvalue_new))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This handler is registered once for each UnixSignal object. A pipe is maintained
|
||||
// for each one; Wait users read at one end of this pipe, and default_handler sends
|
||||
// a write on the pipe for each signal received while the Wait is ongoing.
|
||||
//
|
||||
// Notice a fairly unlikely race condition exists here: Because we synchronize with
|
||||
// pipe teardown, but not install/uninstall (in other words, we are only trying to
|
||||
// protect against writing on a closed pipe) it is technically possible a full
|
||||
// uninstall and then an install could complete after signum is checked but before
|
||||
// the remaining instructions execute. In this unlikely case count could be
|
||||
// incremented or a byte written on the wrong signal handler.
|
||||
static void
|
||||
default_handler (int signum)
|
||||
{
|
||||
@@ -175,29 +264,36 @@ default_handler (int signum)
|
||||
signal_info* h = &signals [i];
|
||||
if (mph_int_get (&h->signum) != signum)
|
||||
continue;
|
||||
|
||||
mph_int_inc (&h->count);
|
||||
|
||||
if (!acquire_pipelock_handler (&h->pipelock))
|
||||
continue; // Teardown is occurring on this object, no one to send to.
|
||||
|
||||
fd = mph_int_get (&h->write_fd);
|
||||
if (fd > 0) {
|
||||
if (fd > 0) { // If any listener exists to write to
|
||||
int j,pipecounter;
|
||||
char c = signum;
|
||||
pipecounter = mph_int_get (&h->pipecnt);
|
||||
char c = signum; // (Value is meaningless)
|
||||
pipecounter = mph_int_get (&h->pipecnt); // Write one byte per pipe listener
|
||||
for (j = 0; j < pipecounter; ++j) {
|
||||
int r;
|
||||
do { r = write (fd, &c, 1); } while (keep_trying (r));
|
||||
fsync (fd); /* force */
|
||||
}
|
||||
}
|
||||
release_pipelock_handler (&h->pipelock);
|
||||
}
|
||||
}
|
||||
|
||||
static pthread_mutex_t signals_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// A UnixSignal object is being constructed
|
||||
void*
|
||||
Mono_Unix_UnixSignal_install (int sig)
|
||||
{
|
||||
#if defined(HAVE_SIGNAL)
|
||||
int i;
|
||||
signal_info* h = NULL;
|
||||
int have_handler = 0;
|
||||
signal_info* h = NULL; // signals[] slot to install to
|
||||
int have_handler = 0; // Candidates for signal_info handler fields
|
||||
void* handler = NULL;
|
||||
|
||||
if (acquire_mutex (&signals_mutex) == -1)
|
||||
@@ -211,13 +307,16 @@ Mono_Unix_UnixSignal_install (int sig)
|
||||
if (sinfo.sa_handler != SIG_DFL || (void*)sinfo.sa_sigaction != (void*)SIG_DFL) {
|
||||
pthread_mutex_unlock (&signals_mutex);
|
||||
errno = EADDRINUSE;
|
||||
return NULL;
|
||||
return NULL; // This is an rt signal with an existing handler. Bail out.
|
||||
}
|
||||
}
|
||||
#endif /*defined (SIGRTMIN) && defined (SIGRTMAX)*/
|
||||
|
||||
// Scan through signals list looking for (1) an unused spot (2) a usable value for handler
|
||||
for (i = 0; i < NUM_SIGNALS; ++i) {
|
||||
if (h == NULL && signals [i].signum == 0) {
|
||||
int just_installed = 0;
|
||||
// We're still looking for a signal_info spot, and this one is available:
|
||||
if (h == NULL && mph_int_get (&signals [i].signum) == 0) {
|
||||
h = &signals [i];
|
||||
h->handler = signal (sig, default_handler);
|
||||
if (h->handler == SIG_ERR) {
|
||||
@@ -226,32 +325,41 @@ Mono_Unix_UnixSignal_install (int sig)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
h->have_handler = 1;
|
||||
just_installed = 1;
|
||||
}
|
||||
}
|
||||
if (!have_handler && signals [i].signum == sig &&
|
||||
// Check if this slot has a "usable" (not installed by this file) handler-to-restore-later:
|
||||
// (On the first signal to be installed, signals [i] will be == h when this happens.)
|
||||
if (!have_handler && (just_installed || mph_int_get (&signals [i].signum) == sig) &&
|
||||
signals [i].handler != default_handler) {
|
||||
have_handler = 1;
|
||||
handler = signals [i].handler;
|
||||
}
|
||||
if (h && have_handler)
|
||||
if (h && have_handler) // We have everything we need
|
||||
break;
|
||||
}
|
||||
|
||||
if (h && have_handler) {
|
||||
h->have_handler = 1;
|
||||
h->handler = handler;
|
||||
}
|
||||
|
||||
if (h) {
|
||||
mph_int_set (&h->count, h->count, 0);
|
||||
mph_int_set (&h->signum, h->signum, sig);
|
||||
mph_int_set (&h->pipecnt, h->pipecnt, 0);
|
||||
// If we reached here without have_handler, this means that default_handler
|
||||
// was set as the signal handler before the first UnixSignal object was installed.
|
||||
g_assert (have_handler);
|
||||
|
||||
// Overwrite the tenative handler we set a moment ago with a known-usable one
|
||||
h->handler = handler;
|
||||
h->have_handler = 1;
|
||||
|
||||
mph_int_set (&h->count, 0);
|
||||
mph_int_set (&h->pipecnt, 0);
|
||||
mph_int_set (&h->signum, sig);
|
||||
}
|
||||
|
||||
release_mutex (&signals_mutex);
|
||||
|
||||
return h;
|
||||
#else
|
||||
g_error ("signal() is not supported by this platform");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -260,15 +368,17 @@ count_handlers (int signum)
|
||||
int i;
|
||||
int count = 0;
|
||||
for (i = 0; i < NUM_SIGNALS; ++i) {
|
||||
if (signals [i].signum == signum)
|
||||
if (mph_int_get (&signals [i].signum) == signum)
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// A UnixSignal object is being Disposed
|
||||
int
|
||||
Mono_Unix_UnixSignal_uninstall (void* info)
|
||||
{
|
||||
#if defined(HAVE_SIGNAL)
|
||||
signal_info* h;
|
||||
int r = -1;
|
||||
|
||||
@@ -281,21 +391,27 @@ Mono_Unix_UnixSignal_uninstall (void* info)
|
||||
errno = EINVAL;
|
||||
else {
|
||||
/* last UnixSignal -- we can unregister */
|
||||
if (h->have_handler && count_handlers (h->signum) == 1) {
|
||||
mph_sighandler_t p = signal (h->signum, h->handler);
|
||||
int signum = mph_int_get (&h->signum);
|
||||
if (h->have_handler && count_handlers (signum) == 1) {
|
||||
mph_sighandler_t p = signal (signum, h->handler);
|
||||
if (p != SIG_ERR)
|
||||
r = 0;
|
||||
h->handler = NULL;
|
||||
h->have_handler = 0;
|
||||
}
|
||||
h->signum = 0;
|
||||
mph_int_set (&h->signum, 0);
|
||||
}
|
||||
|
||||
release_mutex (&signals_mutex);
|
||||
|
||||
return r;
|
||||
#else
|
||||
g_error ("signal() is not supported by this platform");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set up a signal_info to begin waiting for signal
|
||||
static int
|
||||
setup_pipes (signal_info** signals, int count, struct pollfd *fd_structs, int *currfd)
|
||||
{
|
||||
@@ -307,21 +423,22 @@ setup_pipes (signal_info** signals, int count, struct pollfd *fd_structs, int *c
|
||||
|
||||
h = signals [i];
|
||||
|
||||
if (mph_int_get (&h->pipecnt) == 0) {
|
||||
if (mph_int_get (&h->pipecnt) == 0) { // First listener for this signal_info
|
||||
if ((r = pipe (filedes)) != 0) {
|
||||
break;
|
||||
}
|
||||
h->read_fd = filedes [0];
|
||||
h->write_fd = filedes [1];
|
||||
mph_int_set (&h->read_fd, filedes [0]);
|
||||
mph_int_set (&h->write_fd, filedes [1]);
|
||||
}
|
||||
mph_int_inc (&h->pipecnt);
|
||||
fd_structs[*currfd].fd = h->read_fd;
|
||||
fd_structs[*currfd].fd = mph_int_get (&h->read_fd);
|
||||
fd_structs[*currfd].events = POLLIN;
|
||||
++(*currfd);
|
||||
++(*currfd); // count is verified less than NUM_SIGNALS by caller
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// Cleanup a signal_info after waiting for signal
|
||||
static void
|
||||
teardown_pipes (signal_info** signals, int count)
|
||||
{
|
||||
@@ -329,21 +446,28 @@ teardown_pipes (signal_info** signals, int count)
|
||||
for (i = 0; i < count; ++i) {
|
||||
signal_info* h = signals [i];
|
||||
|
||||
if (mph_int_dec_test (&h->pipecnt)) {
|
||||
if (h->read_fd != 0)
|
||||
close (h->read_fd);
|
||||
if (h->write_fd != 0)
|
||||
close (h->write_fd);
|
||||
h->read_fd = 0;
|
||||
h->write_fd = 0;
|
||||
if (mph_int_dec_test (&h->pipecnt)) { // Final listener for this signal_info
|
||||
acquire_pipelock_teardown (&h->pipelock);
|
||||
int read_fd = mph_int_get (&h->read_fd);
|
||||
int write_fd = mph_int_get (&h->write_fd);
|
||||
if (read_fd != 0)
|
||||
close (read_fd);
|
||||
if (write_fd != 0)
|
||||
close (write_fd);
|
||||
mph_int_set (&h->read_fd, 0);
|
||||
mph_int_set (&h->write_fd, 0);
|
||||
release_pipelock_teardown (&h->pipelock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Given pipes set up, wait for a byte to arrive on one of them
|
||||
static int
|
||||
wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_structs, int timeout, Mono_Posix_RuntimeIsShuttingDown shutting_down)
|
||||
{
|
||||
int r, idx;
|
||||
// Poll until one of this signal_info's pipes is ready to read.
|
||||
// Once a second, stop to check if the VM is shutting down.
|
||||
do {
|
||||
struct timeval tv;
|
||||
struct timeval *ptv = NULL;
|
||||
@@ -358,7 +482,7 @@ wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_s
|
||||
idx = -1;
|
||||
if (r == 0)
|
||||
idx = timeout;
|
||||
else if (r > 0) {
|
||||
else if (r > 0) { // The pipe[s] are ready to read.
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
signal_info* h = signals [i];
|
||||
@@ -366,7 +490,7 @@ wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_s
|
||||
int r;
|
||||
char c;
|
||||
do {
|
||||
r = read (h->read_fd, &c, 1);
|
||||
r = read (mph_int_get (&h->read_fd), &c, 1);
|
||||
} while (keep_trying (r) && !shutting_down ());
|
||||
if (idx == -1)
|
||||
idx = i;
|
||||
|
||||
@@ -14,6 +14,13 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
// See Stdlib.cs
|
||||
const char *
|
||||
Mono_Unix_VersionString ()
|
||||
{
|
||||
return "MonoProject-2015-12-1";
|
||||
}
|
||||
|
||||
gint32
|
||||
Mono_Posix_Stdlib_EXIT_FAILURE (void)
|
||||
{
|
||||
|
||||
140
support/sys-socket.c
Normal file
140
support/sys-socket.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* <sys/socket.h> wrapper functions.
|
||||
*
|
||||
* Authors:
|
||||
* Steffen Kiess (s-kiess@web.de)
|
||||
*
|
||||
* Copyright (C) 2015 Steffen Kiess
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "map.h"
|
||||
#include "mph.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_socketpair (int domain, int type, int protocol, int* socket1, int* socket2)
|
||||
{
|
||||
int filedes[2] = {-1, -1};
|
||||
int r;
|
||||
|
||||
r = socketpair (domain, type, protocol, filedes);
|
||||
|
||||
*socket1 = filedes[0];
|
||||
*socket2 = filedes[1];
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_getsockopt (int socket, int level, int option_name, void* option_value, gint64* option_len)
|
||||
{
|
||||
socklen_t len;
|
||||
int r;
|
||||
|
||||
mph_return_if_socklen_t_overflow (*option_len);
|
||||
|
||||
len = *option_len;
|
||||
|
||||
r = getsockopt (socket, level, option_name, option_value, &len);
|
||||
|
||||
*option_len = len;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_getsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value)
|
||||
{
|
||||
struct timeval tv;
|
||||
int r;
|
||||
socklen_t size;
|
||||
|
||||
size = sizeof (struct timeval);
|
||||
r = getsockopt (socket, level, option_name, &tv, &size);
|
||||
|
||||
if (r != -1 && size == sizeof (struct timeval)) {
|
||||
if (Mono_Posix_ToTimeval (&tv, option_value) != 0)
|
||||
return -1;
|
||||
} else {
|
||||
memset (option_value, 0, sizeof (struct Mono_Posix_Timeval));
|
||||
if (r != -1)
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_getsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value)
|
||||
{
|
||||
struct linger ling;
|
||||
int r;
|
||||
socklen_t size;
|
||||
|
||||
size = sizeof (struct linger);
|
||||
r = getsockopt (socket, level, option_name, &ling, &size);
|
||||
|
||||
if (r != -1 && size == sizeof (struct linger)) {
|
||||
if (Mono_Posix_ToLinger (&ling, option_value) != 0)
|
||||
return -1;
|
||||
} else {
|
||||
memset (option_value, 0, sizeof (struct Mono_Posix_Linger));
|
||||
if (r != -1)
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_setsockopt (int socket, int level, int option_name, void* option_value, gint64 option_len)
|
||||
{
|
||||
mph_return_if_socklen_t_overflow (option_len);
|
||||
|
||||
return setsockopt (socket, level, option_name, option_value, option_len);
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_setsockopt_timeval (int socket, int level, int option_name, struct Mono_Posix_Timeval* option_value)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (Mono_Posix_FromTimeval (option_value, &tv) != 0)
|
||||
return -1;
|
||||
|
||||
return setsockopt (socket, level, option_name, &tv, sizeof (struct timeval));
|
||||
}
|
||||
|
||||
int
|
||||
Mono_Posix_Syscall_setsockopt_linger (int socket, int level, int option_name, struct Mono_Posix_Linger* option_value)
|
||||
{
|
||||
struct linger ling;
|
||||
|
||||
if (Mono_Posix_FromLinger (option_value, &ling) != 0)
|
||||
return -1;
|
||||
|
||||
return setsockopt (socket, level, option_name, &ling, sizeof (struct linger));
|
||||
}
|
||||
|
||||
gint64
|
||||
Mono_Posix_Syscall_recv (int socket, void* message, guint64 length, int flags)
|
||||
{
|
||||
mph_return_if_size_t_overflow (length);
|
||||
|
||||
return recv (socket, message, length, flags);
|
||||
}
|
||||
|
||||
gint64
|
||||
Mono_Posix_Syscall_send (int socket, void* message, guint64 length, int flags)
|
||||
{
|
||||
mph_return_if_size_t_overflow (length);
|
||||
|
||||
return send (socket, message, length, flags);
|
||||
}
|
||||
@@ -30,9 +30,13 @@ Mono_Posix_FromStat (struct Mono_Posix_Stat *from, void *_to)
|
||||
|
||||
to->st_dev = from->st_dev;
|
||||
to->st_ino = from->st_ino;
|
||||
if (Mono_Posix_FromFilePermissions (from->st_mode, &to->st_mode) != 0) {
|
||||
|
||||
unsigned int to_st_mode;
|
||||
if (Mono_Posix_FromFilePermissions (from->st_mode, &to_st_mode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
to->st_mode = to_st_mode;
|
||||
to->st_nlink = from->st_nlink;
|
||||
to->st_uid = from->st_uid;
|
||||
to->st_gid = from->st_gid;
|
||||
|
||||
@@ -187,7 +187,7 @@ ReadZStream (ZStream *stream, guchar *buffer, gint length)
|
||||
stream->eof = TRUE;
|
||||
}
|
||||
zs->next_in = stream->buffer;
|
||||
zs->avail_in = n;
|
||||
zs->avail_in = n < 0 ? 0 : n;
|
||||
}
|
||||
|
||||
if (zs->avail_in == 0 && zs->total_in == 0)
|
||||
|
||||
Reference in New Issue
Block a user