aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/io.c
diff options
context:
space:
mode:
authorRickard Green <[email protected]>2010-03-10 12:03:09 +0000
committerErlang/OTP <[email protected]>2010-03-10 12:03:09 +0000
commite6ba8d5ede7fb2af9312180459a8a3db0cb081be (patch)
treeccdf9463921f6ca52487fe4adb687861b842228c /erts/emulator/beam/io.c
parentade99a7081bc00c536f5717e9acebcc4b3082a45 (diff)
downloadotp-e6ba8d5ede7fb2af9312180459a8a3db0cb081be.tar.gz
otp-e6ba8d5ede7fb2af9312180459a8a3db0cb081be.tar.bz2
otp-e6ba8d5ede7fb2af9312180459a8a3db0cb081be.zip
OTP-8475 status lock needed when looking up ioq from async threads
Driver threads, such as async threads, using <seealso marker="erl_driver#ErlDrvPDL">port data locks</seealso> peeked at the port status field without proper locking when looking up the driver queue.
Diffstat (limited to 'erts/emulator/beam/io.c')
-rw-r--r--erts/emulator/beam/io.c34
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