diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c index 0dc923d7..0915da84 100644 --- a/bsd-core/drm_bufs.c +++ b/bsd-core/drm_bufs.c @@ -136,6 +136,16 @@ int DRM(addmap)( DRM_IOCTL_ARGS ) } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { + /* Prevent a 2nd X Server from creating a 2nd lock */ + DRM_LOCK(); + if (dev->lock.hw_lock != NULL) { + DRM_UNLOCK(); + DRM(free)(map->handle, map->size, + DRM_MEM_SAREA); + DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); + return DRM_ERR(EBUSY); + } + DRM_UNLOCK(); dev->lock.hw_lock = map->handle; /* Pointer to lock */ } break; diff --git a/bsd/drm_bufs.h b/bsd/drm_bufs.h index 0dc923d7..0915da84 100644 --- a/bsd/drm_bufs.h +++ b/bsd/drm_bufs.h @@ -136,6 +136,16 @@ int DRM(addmap)( DRM_IOCTL_ARGS ) } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { + /* Prevent a 2nd X Server from creating a 2nd lock */ + DRM_LOCK(); + if (dev->lock.hw_lock != NULL) { + DRM_UNLOCK(); + DRM(free)(map->handle, map->size, + DRM_MEM_SAREA); + DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); + return DRM_ERR(EBUSY); + } + DRM_UNLOCK(); dev->lock.hw_lock = map->handle; /* Pointer to lock */ } break; diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c index 77573709..e30e6de8 100644 --- a/linux-core/drm_bufs.c +++ b/linux-core/drm_bufs.c @@ -161,6 +161,12 @@ int DRM(addmap)( struct inode *inode, struct file *filp, } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { + /* Prevent a 2nd X Server from creating a 2nd lock */ + if (dev->lock.hw_lock != NULL) { + vfree( map->handle ); + DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); + return -EBUSY; + } dev->sigdata.lock = dev->lock.hw_lock = map->handle; /* Pointer to lock */ } diff --git a/linux/drm_bufs.h b/linux/drm_bufs.h index 77573709..e30e6de8 100644 --- a/linux/drm_bufs.h +++ b/linux/drm_bufs.h @@ -161,6 +161,12 @@ int DRM(addmap)( struct inode *inode, struct file *filp, } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { + /* Prevent a 2nd X Server from creating a 2nd lock */ + if (dev->lock.hw_lock != NULL) { + vfree( map->handle ); + DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); + return -EBUSY; + } dev->sigdata.lock = dev->lock.hw_lock = map->handle; /* Pointer to lock */ }