diff options
author | Rickard Green <[email protected]> | 2010-04-22 12:00:00 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-08-20 08:51:45 +0200 |
commit | d35dc5f707f307300665c7da2ae3092d0baa9bdd (patch) | |
tree | 0bea0d2b7b16a452dbdbde8b48886d6ba81b75f0 /erts/emulator/beam/io.c | |
parent | f0dbde23b539999add8754ec84541698419fc8b5 (diff) | |
download | otp-d35dc5f707f307300665c7da2ae3092d0baa9bdd.tar.gz otp-d35dc5f707f307300665c7da2ae3092d0baa9bdd.tar.bz2 otp-d35dc5f707f307300665c7da2ae3092d0baa9bdd.zip |
erts: Patch 1113
OTP-8475 Driver threads, such as async threads, using port data locks
peeked at the port status field without proper locking when
looking up the driver queue.
OTP-8487 A call to the BIF unregister(RegName) when a port had the
name RegName registered in the runtime system without SMP
support caused a runtime system crash. (Thanks to Per Hedeland
for the bugfix and test case.)
OTP-8591 Fix memory management bug causing crash of non-SMP emulator
with async threads enabled. The bug did first appear in
R13B03.
Diffstat (limited to 'erts/emulator/beam/io.c')
-rw-r--r-- | erts/emulator/beam/io.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/erts/emulator/beam/io.c b/erts/emulator/beam/io.c index ad0b909b2a..3309b77086 100644 --- a/erts/emulator/beam/io.c +++ b/erts/emulator/beam/io.c @@ -77,15 +77,35 @@ static ERTS_INLINE ErlIOQueue* drvport2ioq(ErlDrvPort drvport) { int ix = (int) drvport; + Uint32 status; + if (ix < 0 || erts_max_ports <= ix) return NULL; - if (erts_port[ix].status & ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP) - return NULL; - ERTS_LC_ASSERT(!erts_port[ix].port_data_lock - || erts_lc_mtx_is_locked(&erts_port[ix].port_data_lock->mtx)); - ERTS_SMP_LC_ASSERT(erts_port[ix].port_data_lock - || erts_lc_is_port_locked(&erts_port[ix])); - return &erts_port[ix].ioq; + + if (erts_get_scheduler_data()) { + ERTS_SMP_LC_ASSERT(erts_lc_is_port_locked(&erts_port[ix])); + ERTS_LC_ASSERT(!erts_port[ix].port_data_lock + || erts_lc_mtx_is_locked( + &erts_port[ix].port_data_lock->mtx)); + + status = erts_port[ix].status; + } + else { + erts_smp_port_state_lock(&erts_port[ix]); + status = erts_port[ix].status; + erts_smp_port_state_unlock(&erts_port[ix]); + + ERTS_LC_ASSERT((status & ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP) + || erts_port[ix].port_data_lock); + ERTS_LC_ASSERT(!erts_port[ix].port_data_lock + || erts_lc_mtx_is_locked( + &erts_port[ix].port_data_lock->mtx)); + + } + + return ((status & ERTS_PORT_SFLGS_INVALID_DRIVER_LOOKUP) + ? NULL + : &erts_port[ix].ioq); } static ERTS_INLINE int |