-
Notifications
You must be signed in to change notification settings - Fork 57
Update OpenBSD support to new drm API introduced in 6.9 #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tobhe
wants to merge
3
commits into
Smithay:develop
Choose a base branch
from
tobhe:openbsd
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,40 @@ fn devname(dev: dev_t) -> Option<String> { | |
Some(String::from_utf8(dev_name).expect("Returned device name is not valid utf8")) | ||
} | ||
|
||
#[cfg(target_os = "openbsd")] | ||
use std::sync::Mutex; | ||
|
||
#[cfg(target_os = "openbsd")] | ||
static DEVNAME_LOCK: Mutex<()> = Mutex::new(()); | ||
|
||
#[cfg(target_os = "openbsd")] | ||
fn devname(dev: dev_t) -> Option<String> { | ||
use std::ffi::CStr; | ||
|
||
let _lock = DEVNAME_LOCK.lock().unwrap(); | ||
let buf = unsafe { | ||
libc::devname( | ||
dev, | ||
libc::S_IFCHR, // Must be S_IFCHR or S_IFBLK | ||
) | ||
}; | ||
|
||
if buf.is_null() { | ||
return None; | ||
} | ||
|
||
let dev_str = | ||
unsafe { CStr::from_ptr(buf).to_str() }.expect("Returned device name is not valid utf8"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
|
||
// If no device matches the specified values, or no information is | ||
// available, a pointer to the string "??" is returned. | ||
if dev_str == "??" { | ||
return None; | ||
} | ||
|
||
Some(dev_str.to_owned()) | ||
} | ||
|
||
/// Returns if the given device by major:minor pair is a DRM device. | ||
#[cfg(target_os = "linux")] | ||
pub fn is_device_drm(dev: dev_t) -> bool { | ||
|
@@ -241,7 +275,7 @@ pub fn is_device_drm(dev: dev_t) -> bool { | |
} | ||
|
||
/// Returns if the given device by major:minor pair is a DRM device. | ||
#[cfg(target_os = "freebsd")] | ||
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))] | ||
pub fn is_device_drm(dev: dev_t) -> bool { | ||
devname(dev).map_or(false, |dev_name| { | ||
dev_name.starts_with("drm/") | ||
|
@@ -252,7 +286,7 @@ pub fn is_device_drm(dev: dev_t) -> bool { | |
} | ||
|
||
/// Returns if the given device by major:minor pair is a DRM device. | ||
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))] | ||
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))] | ||
pub fn is_device_drm(dev: dev_t) -> bool { | ||
major(dev) == DRM_MAJOR | ||
} | ||
|
@@ -313,7 +347,7 @@ pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> { | |
} | ||
|
||
/// Returns the path of a specific type of node from the DRM device described by major and minor device numbers. | ||
#[cfg(target_os = "freebsd")] | ||
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))] | ||
pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> { | ||
// Based on libdrm `drmGetMinorNameForFD`. Should be updated if the code | ||
// there is replaced with anything more sensible... | ||
|
@@ -351,7 +385,7 @@ pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> { | |
} | ||
|
||
/// Returns the path of a specific type of node from the DRM device described by major and minor device numbers. | ||
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))] | ||
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))] | ||
pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> { | ||
use std::io::ErrorKind; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to keep this
static
locally inside the function for now? And/or do we expect other calls todevname()
?Note that this won't help if user code - through other means - calls
libc::devname()
without knowing about "your / our" lock 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can do that
True, but that's how the underlying API works so not much we can do about it imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I suggested the lock, I wonder if we should instead mark
devname
unsafe and all functions using it, while documenting thatthis is unsound to call from multiple threads on some platforms
.