aboutsummaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorChen Gang <chengang@emindsoft.com.cn>2020-06-05 09:32:21 +0800
committerLaurent Vivier <laurent@vivier.eu>2020-06-29 13:04:37 +0200
commite865b97ff4d924a81c28b9d9f3d6fe3e198bcdb9 (patch)
treea3af12ac4a3fb2abb1fc8535432c340e1f1e1151 /linux-user/syscall.c
parentd43624c400597aec18dff917c1424b807bbb473d (diff)
linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
Another DRM_IOCTL_* commands will be done later. Signed-off-by: Chen Gang <chengang@emindsoft.com.cn> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200605013221.22828-1-chengang@emindsoft.com.cn> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 97de9fb5c9..17ed7f8d6b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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,101 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp,
}
#endif
+#ifdef HAVE_DRM_H
+
+static void unlock_drm_version(struct drm_version *host_ver,
+ struct target_drm_version *target_ver,
+ bool copy)
+{
+ unlock_user(host_ver->name, target_ver->name,
+ copy ? host_ver->name_len : 0);
+ unlock_user(host_ver->date, target_ver->date,
+ copy ? host_ver->date_len : 0);
+ unlock_user(host_ver->desc, target_ver->desc,
+ copy ? host_ver->desc_len : 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) {
+ return -EFAULT;
+ }
+ }
+
+ __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) {
+ 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, target_ver, false);
+ return -EFAULT;
+}
+
+static inline void host_to_target_drmversion(
+ struct target_drm_version *target_ver,
+ struct drm_version *host_ver)
+{
+ __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_drm_version(host_ver, target_ver, true);
+}
+
+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)) {
+ 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)) {
+ unlock_drm_version(ver, target_ver, false);
+ } else {
+ host_to_target_drmversion(target_ver, ver);
+ }
+ }
+ unlock_user_struct(target_ver, arg, 0);
+ return ret;
+ }
+ return -TARGET_ENOSYS;
+}
+
+#endif
+
static IOCTLEntry ioctl_entries[] = {
#define IOCTL(cmd, access, ...) \
{ TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },