linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
PATCH v6 1/1 linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
From: Chen Gang <[email protected]>
Another DRM_IOCTL_* commands will be done later.
--- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 95 ++++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 ++++++ linux-user/syscall_types.h | 11 +++++ 5 files changed, 136 insertions(+)
configure +10 -0
@@ -3136,6 +3136,13 @@ if ! check_include "ifaddrs.h" ; then have_ifaddrs_h=no fi +######################################### +# libdrm check +have_drm_h=no +if check_include "libdrm/drm.h" ; then + have_drm_h=yes +fi + ########################################## # VTE probe
@@ -7127,6 +7134,9 @@ fi if test "$have_ifaddrs_h" = "yes" ; then echo "HAVE_IFADDRS_H=y" >> $config_host_mak fi +if test "$have_drm_h" = "yes" ; then + echo "HAVE_DRM_H=y" >> $config_host_mak +fi if test "$have_broken_size_max" = "yes" ; then echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak fi
linux-user/ioctls.h +5 -0
@@ -574,6 +574,11 @@IOCTL_SPECIAL (SIOCDELRT ,IOC_W , do_ioctl_rt, MK_PTR(MK_STRUCT(STRUCT_rtentry))) +#ifdef HAVE_DRM_H +IOCTL_SPECIAL (DRM_IOCTL_VERSION ,IOC_RW , do_ioctl_drm, + MK_PTR(MK_STRUCT(STRUCT_drm_version))) +#endif +#ifdef TARGET_TIOCSTART IOCTL_IGNORE (TIOCSTART)IOCTL_IGNORE (TIOCSTOP)
linux-user/syscall.c +95 -0
107 lines not on this page · raw message
linux-user/syscall_defs.h +15 -0
@@ -1167,6 +1167,9 @@ struct target_rtc_pll_info {#define TARGET_DM_TARGET_MSG TARGET_IOWRU(0xfd, 0x0e)#define TARGET_DM_DEV_SET_GEOMETRY TARGET_IOWRU(0xfd, 0x0f) +/* drm ioctls */ +#define TARGET_DRM_IOCTL_VERSION TARGET_IOWRU('d', 0x00) +/* from asm/termbits.h */ #define TARGET_NCC 8
@@ -2598,6 +2601,18 @@ struct target_mq_attr {abi_long mq_curmsgs; }; +struct target_drm_version { +int version_major; +int version_minor; +int version_patchlevel; +abi_ulong name_len; +abi_ulong name; +abi_ulong date_len; +abi_ulong date; +abi_ulong desc_len; +abi_ulong desc; +}; +#include "socket.h" #include "errno_defs.h"
linux-user/syscall_types.h +11 -0
@@ -292,6 +292,17 @@ STRUCT(dm_target_versions,STRUCT (dm_target_msg, TYPE_ULONGLONG) /* sector */ +STRUCT (drm_version, +TYPE_INT ,/* version_major */ +TYPE_INT ,/* version_minor */ +TYPE_INT ,/* version_patchlevel */ +TYPE_ULONG ,/* name_len */ +TYPE_PTRVOID ,/* name */ +TYPE_ULONG ,/* date_len */ +TYPE_PTRVOID ,/* date */ +TYPE_ULONG ,/* desc_len */ + TYPE_PTRVOID) /* desc */ + STRUCT(file_clone_range, TYPE_LONGLONG, /* src_fd */ TYPE_ULONGLONG, /* src_offset */
Signature · 1 line
2.24.0.308.g228f53135a
Le 04/06/2020 à 03:45, [email protected] a écrit :
Quoted 73 lines
From: Chen Gang <[email protected]>
Another DRM_IOCTL_* commands will be done later.
Signed-off-by Chen Gang <[email protected]>--- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 95 ++++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 ++++++ linux-user/syscall_types.h | 11 +++++ 5 files changed, 136 insertions(+)configure +10
-0@@ -3136,6 +3136,13 @@ if ! check_include "ifaddrs.h" ; then have_ifaddrs_h=no fi +######################################### +# libdrm check +have_drm_h=no +if check_include "libdrm/drm.h" ; then + have_drm_h=yes +fi + ########################################## # VTE probe@@ -7127,6 +7134,9 @@ fi if test "$have_ifaddrs_h" = "yes" ; then echo "HAVE_IFADDRS_H=y" >> $config_host_mak fi +if test "$have_drm_h" = "yes" ; then + echo "HAVE_DRM_H=y" >> $config_host_mak +fi if test "$have_broken_size_max" = "yes" ; then echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak filinux-user/ioctls.h +5
-0@@ -574,6 +574,11 @@IOCTL_SPECIAL (SIOCDELRT ,IOC_W , do_ioctl_rt, MK_PTR(MK_STRUCT(STRUCT_rtentry))) +#ifdef HAVE_DRM_H +IOCTL_SPECIAL (DRM_IOCTL_VERSION ,IOC_RW , do_ioctl_drm, + MK_PTR(MK_STRUCT(STRUCT_drm_version))) +#endif +#ifdef TARGET_TIOCSTART IOCTL_IGNORE (TIOCSTART)IOCTL_IGNORE (TIOCSTOP)linux-user/syscall.c +3
-0@@ -112,6 +112,9 @@#include <linux/if_alg.h> #include <linux/rtc.h> #include <sound/asound.h> +#ifdef HAVE_DRM_H +#include <libdrm/drm.h> +#endif #include "linux_loop.h" #include "uname.h" @@ -5276,6 +5279,98 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, }
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5289
Quoted 10 lines
linux-user/syscall.c +8
-0#endif +#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +unlock_user (host_ver->name,0UL ,0 ); +unlock_user (host_ver->date,0UL ,0 ); +unlock_user (host_ver->desc,0UL ,0 ); +}
This is correct but I would prefer to not have this kind of function with 0UL parameter.
You can use target_ver for the guest pointer and host_ver for the len, guest pointer will be ignored if host pointer is NULL.
You can have a generic function that not copies data in case of error:
static void unlock_drm_strings(struct drm_version *host_ver,
struct target_drm_version *target_ver, int copy)
{
unlock_user(host_ver->name, target_ver->name,
copy ? host_ver->name_len : 0);...
Quoted 26 lines
linux-user/syscall.c +26
-0+ +static inline abi_long target_to_host_drmversion (struct drm_version *host_ver, +struct target_drm_version *target_ver) +{ +memset (host_ver,0 ,sizeof (*host_ver)); + +__get_user (host_ver->name_len, &target_ver->name_len); +if (host_ver->name_len) { + host_ver->name =lock_user (VERIFY_WRITE , target_ver->name, + target_ver->name_len,0 ); +if (!host_ver->name) { + goto err; + } + } + +__get_user (host_ver->date_len, &target_ver->date_len); +if (host_ver->date_len) { + host_ver->date =lock_user (VERIFY_WRITE , target_ver->date, + target_ver->date_len,0 ); +if (!host_ver->date) { + goto err; + } + } + +__get_user (host_ver->desc_len, &target_ver->desc_len); +if (host_ver->desc_len) {
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5325
Quoted 10 lines
linux-user/syscall.c +10
-0+ host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) { + goto err; + } + } + +return 0 ; +err: +unlock_drm_version (host_ver);
unlock_drm_strings(host_ver, target_ver, 0);
Quoted 6 lines
linux-user/syscall.c +6
-0+return -EFAULT ; +} + +static inline abi_long host_to_target_drmversion ( +struct target_drm_version *target_ver, +struct drm_version *host_ver)
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5341
Quoted 10 lines
linux-user/syscall.c +10
-0+{ +__put_user (host_ver->version_major, &target_ver->version_major); +__put_user (host_ver->version_minor, &target_ver->version_minor); +__put_user (host_ver->version_patchlevel, &target_ver->version_patchlevel); +__put_user (host_ver->name_len, &target_ver->name_len); +__put_user (host_ver->date_len, &target_ver->date_len); +__put_user (host_ver->desc_len, &target_ver->desc_len); +unlock_user (host_ver->name, target_ver->name, host_ver->name_len); +unlock_user (host_ver->date, target_ver->date, host_ver->date_len); +unlock_user (host_ver->desc, target_ver->desc, host_ver->desc_len);
unlock_drm_strings(host_ver, target_ver, 1);
Quoted 13 lines
linux-user/syscall.c +13
-0+return 0 ; +} + +static abi_long do_ioctl_drm (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +struct drm_version *ver; +struct target_drm_version *target_ver; +abi_long ret; + +switch (ie->host_cmd) { +case DRM_IOCTL_VERSION : +if (!lock_user_struct (VERIFY_WRITE , target_ver, arg,0 )) {
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5364
Quoted 10 lines
linux-user/syscall.c +10
-0+return -TARGET_EFAULT ; + } + ver = (struct drm_version *)buf_temp; + ret =target_to_host_drmversion (ver, target_ver); +if (!is_error (ret)) { + ret =get_errno (safe_ioctl (fd, ie->host_cmd, ver)); +if (!is_error (ret)) { + ret =host_to_target_drmversion (target_ver, ver); + } +unlock_drm_version (ver);
} else {
unlock_drm_strings(host_ver, target_ver, 0);
}Thanks,
Laurent
That sounds good, I'll send patch v7, thanks.
Quoted 193 lines · Laurent Vivier
Le 04/06/2020 à 03:45, [email protected] a écrit :
Quoted 73 lines
From: Chen Gang <[email protected]>
Another DRM_IOCTL_* commands will be done later.
Signed-off-by Chen Gang <[email protected]>--- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 95 ++++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 ++++++ linux-user/syscall_types.h | 11 +++++ 5 files changed, 136 insertions(+)configure +10
-0@@ -3136,6 +3136,13 @@ if ! check_include "ifaddrs.h" ; then have_ifaddrs_h=no fi +######################################### +# libdrm check +have_drm_h=no +if check_include "libdrm/drm.h" ; then + have_drm_h=yes +fi + ########################################## # VTE probe@@ -7127,6 +7134,9 @@ fi if test "$have_ifaddrs_h" = "yes" ; then echo "HAVE_IFADDRS_H=y" >> $config_host_mak fi +if test "$have_drm_h" = "yes" ; then + echo "HAVE_DRM_H=y" >> $config_host_mak +fi if test "$have_broken_size_max" = "yes" ; then echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak filinux-user/ioctls.h +5
-0@@ -574,6 +574,11 @@IOCTL_SPECIAL (SIOCDELRT ,IOC_W , do_ioctl_rt, MK_PTR(MK_STRUCT(STRUCT_rtentry))) +#ifdef HAVE_DRM_H +IOCTL_SPECIAL (DRM_IOCTL_VERSION ,IOC_RW , do_ioctl_drm, + MK_PTR(MK_STRUCT(STRUCT_drm_version))) +#endif +#ifdef TARGET_TIOCSTART IOCTL_IGNORE (TIOCSTART)IOCTL_IGNORE (TIOCSTOP)linux-user/syscall.c +3
-0@@ -112,6 +112,9 @@#include <linux/if_alg.h> #include <linux/rtc.h> #include <sound/asound.h> +#ifdef HAVE_DRM_H +#include <libdrm/drm.h> +#endif #include "linux_loop.h" #include "uname.h" @@ -5276,6 +5279,98 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, }linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5289
Quoted 10 lines
linux-user/syscall.c +8
-0#endif +#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +unlock_user (host_ver->name,0UL ,0 ); +unlock_user (host_ver->date,0UL ,0 ); +unlock_user (host_ver->desc,0UL ,0 ); +}This is correct but I would prefer to not have this kind of function with 0UL parameter.
You can use
target_verfor the guest pointer andhost_verfor the len, guest pointer will be ignored if host pointer is NULL.You can have a generic function that not copies data in case of error:
static void unlock_drm_strings(struct
drm_version*host_ver,
structtarget_drm_version*target_ver, int copy){ unlock_user(host_ver->name, target_ver->name, copy ? host_ver->name_len : 0);...
Quoted 26 lines
linux-user/syscall.c +26
-0+ +static inline abi_long target_to_host_drmversion (struct drm_version *host_ver, +struct target_drm_version *target_ver) +{ +memset (host_ver,0 ,sizeof (*host_ver)); + +__get_user (host_ver->name_len, &target_ver->name_len); +if (host_ver->name_len) { + host_ver->name =lock_user (VERIFY_WRITE , target_ver->name, + target_ver->name_len,0 ); +if (!host_ver->name) { + goto err; + } + } + +__get_user (host_ver->date_len, &target_ver->date_len); +if (host_ver->date_len) { + host_ver->date =lock_user (VERIFY_WRITE , target_ver->date, + target_ver->date_len,0 ); +if (!host_ver->date) { + goto err; + } + } + +__get_user (host_ver->desc_len, &target_ver->desc_len); +if (host_ver->desc_len) {linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5325
Quoted 10 lines
linux-user/syscall.c +10
-0+ host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) { + goto err; + } + } + +return 0 ; +err: +unlock_drm_version (host_ver);
unlock_drm_strings(host_ver, target_ver, 0);Quoted 6 lines
linux-user/syscall.c +6
-0+return -EFAULT ; +} + +static inline abi_long host_to_target_drmversion ( +struct target_drm_version *target_ver, +struct drm_version *host_ver)linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5341
Quoted 10 lines
linux-user/syscall.c +10
-0+{ +__put_user (host_ver->version_major, &target_ver->version_major); +__put_user (host_ver->version_minor, &target_ver->version_minor); +__put_user (host_ver->version_patchlevel, &target_ver->version_patchlevel); +__put_user (host_ver->name_len, &target_ver->name_len); +__put_user (host_ver->date_len, &target_ver->date_len); +__put_user (host_ver->desc_len, &target_ver->desc_len); +unlock_user (host_ver->name, target_ver->name, host_ver->name_len); +unlock_user (host_ver->date, target_ver->date, host_ver->date_len); +unlock_user (host_ver->desc, target_ver->desc, host_ver->desc_len);
unlock_drm_strings(host_ver, target_ver, 1);Quoted 13 lines
linux-user/syscall.c +13
-0+return 0 ; +} + +static abi_long do_ioctl_drm (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +struct drm_version *ver; +struct target_drm_version *target_ver; +abi_long ret; + +switch (ie->host_cmd) { +case DRM_IOCTL_VERSION : +if (!lock_user_struct (VERIFY_WRITE , target_ver, arg,0 )) {linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5364
Quoted 10 lines
linux-user/syscall.c +10
-0+return -TARGET_EFAULT ; + } + ver = (struct drm_version *)buf_temp; + ret =target_to_host_drmversion (ver, target_ver); +if (!is_error (ret)) { + ret =get_errno (safe_ioctl (fd, ie->host_cmd, ver)); +if (!is_error (ret)) { + ret =host_to_target_drmversion (target_ver, ver); + } +unlock_drm_version (ver);} else { unlock_drm_strings(host_ver, target_ver, 0); }Thanks,
Laurent