2014-02-24 20:31:01 -07:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
#include "arch_GOARCH.h"
|
|
|
|
#include "defs_GOOS_GOARCH.h"
|
|
|
|
#include "os_GOOS.h"
|
|
|
|
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
// Solaris runtime-integrated network poller.
|
|
|
|
//
|
|
|
|
// Solaris uses event ports for scalable network I/O. Event
|
|
|
|
// ports are level-triggered, unlike epoll and kqueue which
|
|
|
|
// can be configured in both level-triggered and edge-triggered
|
|
|
|
// mode. Level triggering means we have to keep track of a few things
|
|
|
|
// ourselves. After we receive an event for a file descriptor,
|
|
|
|
// it's our responsibility to ask again to be notified for future
|
|
|
|
// events for that descriptor. When doing this we must keep track of
|
|
|
|
// what kind of events the goroutines are currently interested in,
|
|
|
|
// for example a fd may be open both for reading and writing.
|
|
|
|
//
|
|
|
|
// A description of the high level operation of this code
|
|
|
|
// follows. Networking code will get a file descriptor by some means
|
|
|
|
// and will register it with the netpolling mechanism by a code path
|
|
|
|
// that eventually calls runtime·netpollopen. runtime·netpollopen
|
|
|
|
// calls port_associate with an empty event set. That means that we
|
|
|
|
// will not receive any events at this point. The association needs
|
|
|
|
// to be done at this early point because we need to process the I/O
|
|
|
|
// readiness notification at some point in the future. If I/O becomes
|
|
|
|
// ready when nobody is listening, when we finally care about it,
|
|
|
|
// nobody will tell us anymore.
|
|
|
|
//
|
|
|
|
// Beside calling runtime·netpollopen, the networking code paths
|
|
|
|
// will call runtime·netpollarm each time goroutines are interested
|
|
|
|
// in doing network I/O. Because now we know what kind of I/O we
|
|
|
|
// are interested in (reading/writting), we can call port_associate
|
|
|
|
// passing the correct type of event set (POLLIN/POLLOUT). As we made
|
|
|
|
// sure to have already associated the file descriptor with the port,
|
|
|
|
// when we now call port_associate, we will unblock the main poller
|
|
|
|
// loop (in runtime·netpoll) right away if the socket is actually
|
|
|
|
// ready for I/O.
|
|
|
|
//
|
|
|
|
// The main poller loop runs in its own thread waiting for events
|
|
|
|
// using port_getn. When an event happens, it will tell the scheduler
|
|
|
|
// about it using runtime·netpollready. Besides doing this, it must
|
|
|
|
// also re-associate the events that were not part of this current
|
|
|
|
// notification with the file descriptor. Failing to do this would
|
|
|
|
// mean each notification will prevent concurrent code using the
|
|
|
|
// same file descriptor in parallel.
|
|
|
|
//
|
|
|
|
// The logic dealing with re-associations is encapsulated in
|
|
|
|
// runtime·netpollupdate. This function takes care to associate the
|
|
|
|
// descriptor only with the subset of events that were previously
|
|
|
|
// part of the association, except the one that just happened. We
|
|
|
|
// can't re-associate with that right away, because event ports
|
|
|
|
// are level triggered so it would cause a busy loop. Instead, that
|
|
|
|
// association is effected only by the runtime·netpollarm code path,
|
|
|
|
// when Go code actually asks for I/O.
|
|
|
|
//
|
|
|
|
// The open and arming mechanisms are serialized using the lock
|
|
|
|
// inside PollDesc. This is required because the netpoll loop runs
|
|
|
|
// asynchonously in respect to other Go code and by the time we get
|
|
|
|
// to call port_associate to update the association in the loop, the
|
|
|
|
// file descriptor might have been closed and reopened already. The
|
|
|
|
// lock allows runtime·netpollupdate to be called synchronously from
|
|
|
|
// the loop thread while preventing other threads operating to the
|
|
|
|
// same PollDesc, so once we unblock in the main loop, until we loop
|
|
|
|
// again we know for sure we are always talking about the same file
|
|
|
|
// descriptor and can safely access the data we want (the event set).
|
|
|
|
|
2014-02-24 20:31:01 -07:00
|
|
|
#pragma dynimport libc·fcntl fcntl "libc.so"
|
|
|
|
#pragma dynimport libc·port_create port_create "libc.so"
|
|
|
|
#pragma dynimport libc·port_associate port_associate "libc.so"
|
|
|
|
#pragma dynimport libc·port_dissociate port_dissociate "libc.so"
|
|
|
|
#pragma dynimport libc·port_getn port_getn "libc.so"
|
|
|
|
extern uintptr libc·fcntl;
|
|
|
|
extern uintptr libc·port_create;
|
|
|
|
extern uintptr libc·port_associate;
|
|
|
|
extern uintptr libc·port_dissociate;
|
|
|
|
extern uintptr libc·port_getn;
|
|
|
|
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 09:54:39 -06:00
|
|
|
#define errno (*g->m->perrno)
|
2014-02-24 20:31:01 -07:00
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·fcntl(int32 fd, int32 cmd, uintptr arg)
|
|
|
|
{
|
2014-08-29 04:28:09 -06:00
|
|
|
return runtime·sysvicall3(libc·fcntl, (uintptr)fd, (uintptr)cmd, (uintptr)arg);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·port_create(void)
|
|
|
|
{
|
2014-08-29 04:28:09 -06:00
|
|
|
return runtime·sysvicall0(libc·port_create);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·port_associate(int32 port, int32 source, uintptr object, int32 events, uintptr user)
|
|
|
|
{
|
2014-08-29 04:28:09 -06:00
|
|
|
return runtime·sysvicall5(libc·port_associate, (uintptr)port, (uintptr)source, object, (uintptr)events, user);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·port_dissociate(int32 port, int32 source, uintptr object)
|
|
|
|
{
|
2014-08-29 04:28:09 -06:00
|
|
|
return runtime·sysvicall3(libc·port_dissociate, (uintptr)port, (uintptr)source, object);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·port_getn(int32 port, PortEvent *evs, uint32 max, uint32 *nget, Timespec *timeout)
|
|
|
|
{
|
2014-08-29 04:28:09 -06:00
|
|
|
return runtime·sysvicall5(libc·port_getn, (uintptr)port, (uintptr)evs, (uintptr)max, (uintptr)nget, (uintptr)timeout);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int32 portfd = -1;
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·netpollinit(void)
|
|
|
|
{
|
|
|
|
if((portfd = runtime·port_create()) >= 0) {
|
|
|
|
runtime·fcntl(portfd, F_SETFD, FD_CLOEXEC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
runtime·printf("netpollinit: failed to create port (%d)\n", errno);
|
|
|
|
runtime·throw("netpollinit: failed to create port");
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·netpollopen(uintptr fd, PollDesc *pd)
|
|
|
|
{
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
int32 r;
|
|
|
|
|
|
|
|
runtime·netpolllock(pd);
|
|
|
|
// We don't register for any specific type of events yet, that's
|
|
|
|
// netpollarm's job. We merely ensure we call port_associate before
|
|
|
|
// asynchonous connect/accept completes, so when we actually want
|
|
|
|
// to do any I/O, the call to port_associate (from netpollarm,
|
|
|
|
// with the interested event set) will unblock port_getn right away
|
|
|
|
// because of the I/O readiness notification.
|
|
|
|
*runtime·netpolluser(pd) = 0;
|
|
|
|
r = runtime·port_associate(portfd, PORT_SOURCE_FD, fd, 0, (uintptr)pd);
|
|
|
|
runtime·netpollunlock(pd);
|
|
|
|
return r;
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·netpollclose(uintptr fd)
|
|
|
|
{
|
|
|
|
return runtime·port_dissociate(portfd, PORT_SOURCE_FD, fd);
|
|
|
|
}
|
|
|
|
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
// Updates the association with a new set of interested events. After
|
|
|
|
// this call, port_getn will return one and only one event for that
|
|
|
|
// particular descriptor, so this function needs to be called again.
|
2014-02-24 20:31:01 -07:00
|
|
|
void
|
|
|
|
runtime·netpollupdate(PollDesc* pd, uint32 set, uint32 clear)
|
|
|
|
{
|
|
|
|
uint32 *ep, old, events;
|
|
|
|
uintptr fd = runtime·netpollfd(pd);
|
|
|
|
ep = (uint32*)runtime·netpolluser(pd);
|
|
|
|
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
if(runtime·netpollclosing(pd))
|
|
|
|
return;
|
2014-02-24 20:31:01 -07:00
|
|
|
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
old = *ep;
|
|
|
|
events = (old & ~clear) | set;
|
|
|
|
if(old == events)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(events && runtime·port_associate(portfd, PORT_SOURCE_FD, fd, events, (uintptr)pd) != 0) {
|
|
|
|
runtime·printf("netpollupdate: failed to associate (%d)\n", errno);
|
|
|
|
runtime·throw("netpollupdate: failed to associate");
|
|
|
|
}
|
|
|
|
*ep = events;
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
// subscribe the fd to the port such that port_getn will return one event.
|
2014-02-24 20:31:01 -07:00
|
|
|
void
|
|
|
|
runtime·netpollarm(PollDesc* pd, int32 mode)
|
|
|
|
{
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
runtime·netpolllock(pd);
|
2014-02-24 20:31:01 -07:00
|
|
|
switch(mode) {
|
|
|
|
case 'r':
|
|
|
|
runtime·netpollupdate(pd, POLLIN, 0);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
runtime·netpollupdate(pd, POLLOUT, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
runtime·throw("netpollarm: bad mode");
|
|
|
|
}
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
runtime·netpollunlock(pd);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// polls for ready network connections
|
|
|
|
// returns list of goroutines that become runnable
|
|
|
|
G*
|
|
|
|
runtime·netpoll(bool block)
|
|
|
|
{
|
|
|
|
static int32 lasterr;
|
|
|
|
PortEvent events[128], *ev;
|
|
|
|
PollDesc *pd;
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
int32 i, mode, clear;
|
2014-02-24 20:31:01 -07:00
|
|
|
uint32 n;
|
|
|
|
Timespec *wait = nil, zero;
|
|
|
|
G *gp;
|
|
|
|
|
|
|
|
if(portfd == -1)
|
|
|
|
return (nil);
|
|
|
|
|
|
|
|
if(!block) {
|
|
|
|
zero.tv_sec = 0;
|
|
|
|
zero.tv_nsec = 0;
|
|
|
|
wait = &zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
|
|
|
n = 1;
|
|
|
|
if(runtime·port_getn(portfd, events, nelem(events), &n, wait) < 0) {
|
|
|
|
if(errno != EINTR && errno != lasterr) {
|
|
|
|
lasterr = errno;
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
runtime·printf("runtime: port_getn on fd %d failed with %d\n", portfd, errno);
|
2014-02-24 20:31:01 -07:00
|
|
|
}
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
gp = nil;
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
ev = &events[i];
|
|
|
|
|
|
|
|
if(ev->portev_events == 0)
|
|
|
|
continue;
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
pd = (PollDesc *)ev->portev_user;
|
2014-02-24 20:31:01 -07:00
|
|
|
|
|
|
|
mode = 0;
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
clear = 0;
|
|
|
|
if(ev->portev_events & (POLLIN|POLLHUP|POLLERR)) {
|
2014-02-24 20:31:01 -07:00
|
|
|
mode += 'r';
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
clear |= POLLIN;
|
|
|
|
}
|
|
|
|
if(ev->portev_events & (POLLOUT|POLLHUP|POLLERR)) {
|
2014-02-24 20:31:01 -07:00
|
|
|
mode += 'w';
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
clear |= POLLOUT;
|
|
|
|
}
|
2014-02-24 20:31:01 -07:00
|
|
|
// To effect edge-triggered events, we need to be sure to
|
|
|
|
// update our association with whatever events were not
|
runtime: fix use after close race in Solaris network poller
The Solaris network poller uses event ports, which are
level-triggered. As such, it has to re-arm itself after each
wakeup. The arming mechanism (which runs in its own thread) raced
with the closing of a file descriptor happening in a different
thread. When a network file descriptor is about to be closed,
the network poller is awaken to give it a chance to remove its
association with the file descriptor. Because the poller always
re-armed itself, it raced with code that closed the descriptor.
This change makes the network poller check before re-arming if
the file descriptor is about to be closed, in which case it will
ignore the re-arming request. It uses the per-PollDesc lock in
order to serialize access to the PollDesc.
This change also adds extensive documentation describing the
Solaris implementation of the network poller.
Fixes #7410.
LGTM=dvyukov, iant
R=golang-codereviews, bradfitz, iant, dvyukov, aram.h, gobot
CC=golang-codereviews
https://golang.org/cl/69190044
2014-03-14 07:53:05 -06:00
|
|
|
// set with the event. For example if we are registered
|
|
|
|
// for POLLIN|POLLOUT, and we get POLLIN, besides waking
|
|
|
|
// the goroutine interested in POLLIN we have to not forget
|
|
|
|
// about the one interested in POLLOUT.
|
|
|
|
if(clear != 0) {
|
|
|
|
runtime·netpolllock(pd);
|
|
|
|
runtime·netpollupdate(pd, 0, clear);
|
|
|
|
runtime·netpollunlock(pd);
|
|
|
|
}
|
2014-02-24 20:31:01 -07:00
|
|
|
|
|
|
|
if(mode)
|
|
|
|
runtime·netpollready(&gp, pd, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(block && gp == nil)
|
|
|
|
goto retry;
|
|
|
|
return gp;
|
|
|
|
}
|