Start adding locking to sc_cngetc().
Restore an splx() lost in r228644. We aren't nearly ready to remove spl's. They give hints about missing locking. This lost one was misplaced. Dropping it early for convenience gave race windows for accesses to the fkey buffer. Giant locking accidentally fixed this for non-console cases. Put the spl's around the whole function. Since there are many returns that would need splx() just before them for a direct fix, split the function into a wrapper that does the spl's and a "locked" function that does the work. Return earlier when no keyboard is attached to match the ordering in a planned version. This breaks the dubious feature of returning keys from the fkey buffer after the keyboard has gone away. Losing the keys wouldn't matter, but we keep them too long now.
This commit is contained in:
parent
db569b239b
commit
5bbb6b3eb8
@ -1648,6 +1648,7 @@ sc_cnterm(struct consdev *cp)
|
||||
}
|
||||
|
||||
static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
|
||||
static int sc_cngetc_locked(struct sc_cnstate *sp);
|
||||
static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
|
||||
static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
|
||||
static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
|
||||
@ -1823,16 +1824,29 @@ sc_cnputc(struct consdev *cd, int c)
|
||||
|
||||
static int
|
||||
sc_cngetc(struct consdev *cd)
|
||||
{
|
||||
int c, s;
|
||||
|
||||
/* assert(sc_console != NULL) */
|
||||
s = spltty(); /* block sckbdevent and scrn_timer while we poll */
|
||||
if (sc_console->sc->kbd == NULL) {
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
c = sc_cngetc_locked(NULL);
|
||||
splx(s);
|
||||
return c;
|
||||
}
|
||||
|
||||
static int
|
||||
sc_cngetc_locked(struct sc_cnstate *sp)
|
||||
{
|
||||
static struct fkeytab fkey;
|
||||
static int fkeycp;
|
||||
scr_stat *scp;
|
||||
const u_char *p;
|
||||
int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
|
||||
int c;
|
||||
|
||||
/* assert(sc_console != NULL) */
|
||||
|
||||
/*
|
||||
* Stop the screen saver and update the screen if necessary.
|
||||
* What if we have been running in the screen saver code... XXX
|
||||
@ -1841,15 +1855,8 @@ sc_cngetc(struct consdev *cd)
|
||||
scp = sc_console->sc->cur_scp; /* XXX */
|
||||
sccnupdate(scp);
|
||||
|
||||
if (fkeycp < fkey.len) {
|
||||
splx(s);
|
||||
if (fkeycp < fkey.len)
|
||||
return fkey.str[fkeycp++];
|
||||
}
|
||||
|
||||
if (scp->sc->kbd == NULL) {
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user