Page MenuHomeFreeBSD

D62168.1795963693.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D62168.1795963693.diff

diff --git a/sys/dev/vt/vt.h b/sys/dev/vt/vt.h
--- a/sys/dev/vt/vt.h
+++ b/sys/dev/vt/vt.h
@@ -88,8 +88,13 @@
struct vt_driver;
+typedef void vt_hold_grab_t(void *, bool);
+
int vt_allocate(const struct vt_driver *, void *);
int vt_deallocate(const struct vt_driver *, void *);
+int vt_backend_hold(vt_hold_grab_t *, void *, const struct vt_driver **,
+ void **);
+void vt_backend_release(void);
typedef unsigned int vt_axis_t;
@@ -167,6 +172,10 @@
struct mtx vd_flush_lock; /* (?) vt_flush() lock. */
bool *vd_pos_to_flush;/* (?) Positions to flush. */
+ bool vd_held; /* (d) Backend is held. */
+ bool vd_hold_grabbed; /* (d) Holder saw cngrab. */
+ vt_hold_grab_t *vd_hold_grab; /* (d) Holder's cngrab. */
+ void *vd_hold_arg; /* (d) Its argument. */
};
#define VD_PASTEBUF(vd) ((vd)->vd_pastebuf.vpb_buf)
diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c
--- a/sys/dev/vt/vt_core.c
+++ b/sys/dev/vt/vt_core.c
@@ -2090,6 +2090,26 @@
return (0);
}
+static void
+vt_hold_notify(struct vt_device *vd, bool grabbed)
+{
+ vt_hold_grab_t *grab;
+ bool locked;
+
+ /* As in vt_window_switch(), the debugger cannot take the lock. */
+ locked = !kdb_active;
+ if (locked)
+ VT_LOCK(vd);
+ grab = (vt_hold_grab_t *)atomic_load_acq_ptr(
+ (uintptr_t *)&vd->vd_hold_grab);
+ if (grab != NULL && vd->vd_hold_grabbed != grabbed) {
+ vd->vd_hold_grabbed = grabbed;
+ grab(vd->vd_hold_arg, grabbed);
+ }
+ if (locked)
+ VT_UNLOCK(vd);
+}
+
static void
vtterm_cngrab(struct terminal *tm)
{
@@ -2103,6 +2123,8 @@
if (vd->vd_grabwindow == NULL)
vd->vd_grabwindow = vd->vd_curwindow;
+ vt_hold_notify(vd, true);
+
if (!cold)
vt_window_switch(vw);
@@ -2135,6 +2157,8 @@
if (!cold)
vt_window_switch(grabwindow);
+
+ vt_hold_notify(vd, false);
}
static void
@@ -3426,6 +3450,21 @@
vd->vd_flags &= ~VDF_SUSPENDED;
}
+static int
+vt_backend_tryhold(struct vt_device *vd)
+{
+
+ VT_LOCK(vd);
+ if (vd->vd_held) {
+ VT_UNLOCK(vd);
+ return (EBUSY);
+ }
+ vd->vd_held = true;
+ VT_UNLOCK(vd);
+
+ return (0);
+}
+
int
vt_allocate(const struct vt_driver *drv, void *softc)
{
@@ -3433,6 +3472,10 @@
if (!vty_enabled(VTY_VT))
return (EINVAL);
+ /* A holder has precedence over any new driver. */
+ if (vt_backend_tryhold(main_vd) != 0)
+ return (EEXIST);
+
if (main_vd->vd_driver == NULL) {
main_vd->vd_driver = drv;
printf("VT: initialize with new VT driver \"%s\".\n",
@@ -3445,6 +3488,7 @@
if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
printf("VT: Driver priority %d too low. Current %d\n ",
drv->vd_priority, main_vd->vd_driver->vd_priority);
+ vt_backend_release();
return (EEXIST);
}
printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
@@ -3452,6 +3496,7 @@
}
vt_replace_backend(drv, softc);
+ vt_backend_release();
return (0);
}
@@ -3459,23 +3504,75 @@
int
vt_deallocate(const struct vt_driver *drv, void *softc)
{
+ int error;
if (!vty_enabled(VTY_VT))
return (EINVAL);
+ error = vt_backend_tryhold(main_vd);
+ if (error != 0)
+ return (error);
+
if (main_vd->vd_prev_driver == NULL ||
main_vd->vd_driver != drv ||
- main_vd->vd_softc != softc)
+ main_vd->vd_softc != softc) {
+ vt_backend_release();
return (EPERM);
+ }
printf("VT: Switching back from \"%s\" to \"%s\".\n",
main_vd->vd_driver->vd_name, main_vd->vd_prev_driver->vd_name);
vt_replace_backend(NULL, NULL);
+ vt_backend_release();
return (0);
}
+int
+vt_backend_hold(vt_hold_grab_t *grab, void *arg,
+ const struct vt_driver **drvp, void **softcp)
+{
+ struct vt_device *vd;
+
+ if (!vty_enabled(VTY_VT))
+ return (EINVAL);
+
+ vd = main_vd;
+ VT_LOCK(vd);
+ if (vd->vd_held) {
+ VT_UNLOCK(vd);
+ return (EBUSY);
+ }
+ if (vd->vd_driver == NULL) {
+ VT_UNLOCK(vd);
+ return (ENXIO);
+ }
+ vd->vd_held = true;
+ vd->vd_hold_grabbed = false;
+ vd->vd_hold_arg = arg;
+ atomic_store_rel_ptr((uintptr_t *)&vd->vd_hold_grab, (uintptr_t)grab);
+ *drvp = vd->vd_driver;
+ *softcp = vd->vd_softc;
+ VT_UNLOCK(vd);
+
+ return (0);
+}
+
+void
+vt_backend_release(void)
+{
+ struct vt_device *vd;
+
+ vd = main_vd;
+ VT_LOCK(vd);
+ MPASS(vd->vd_held);
+ atomic_store_rel_ptr((uintptr_t *)&vd->vd_hold_grab, 0);
+ vd->vd_hold_arg = NULL;
+ vd->vd_held = false;
+ VT_UNLOCK(vd);
+}
+
void
vt_suspend(struct vt_device *vd)
{

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 29, 2:48 PM (11 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42091490
Default Alt Text
D62168.1795963693.diff (4 KB)

Event Timeline