[PATCH v2 8/8] linux-user: Add support for btrfs ioctls used to scrub a filesystem

2020-08-03 Thread Filip Bozuta
This patch implements functionality for following ioctls:

BTRFS_IOC_SCRUB - Starting a btrfs filesystem scrub

Start a btrfs filesystem scrub. The third ioctls argument
is a pointer to a following type:

struct btrfs_ioctl_scrub_args {
__u64 devid;/* in */
__u64 start;/* in */
__u64 end;  /* in */
__u64 flags;/* in */
struct btrfs_scrub_progress progress;   /* out */
/* pad to 1k */
__u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
};

Before calling this ioctl, field 'devid' should be filled
with value that represents the device id of the btrfs filesystem
for which the scrub is to be started.

BTRFS_IOC_SCRUB_CANCEL - Canceling scrub of a btrfs filesystem

Cancel a btrfs filesystem scrub if it is running. The third
ioctls argument is ignored.

BTRFS_IOC_SCRUB_PROGRESS - Getting status of a running scrub

Read the status of a running btrfs filesystem scrub. The third
ioctls argument is a pointer to the above mentioned
'struct btrfs_ioctl_scrub_args'. Similarly as with 'BTRFS_IOC_SCRUB',
the 'devid' field should be filled with value that represents the
id of the btrfs device for which the scrub has started. The status
of a running scrub is returned in the field 'progress' which is
of type 'struct btrfs_scrub_progress' and its definition can be
found at:

https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L150

Implementation nots:

Ioctls in this patch use type 'struct btrfs_ioctl_scrub_args' as their
third argument. That is the reason why an aproppriate thunk type
    definition is added in file 'syscall_types.h'.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/ioctls.h| 11 +++
 linux-user/syscall_defs.h  |  3 +++
 linux-user/syscall_types.h | 27 +++
 3 files changed, 41 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 8665f504bf..bf80615438 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -215,6 +215,17 @@
 #ifdef BTRFS_IOC_SUBVOL_SETFLAGS
  IOCTL(BTRFS_IOC_SUBVOL_SETFLAGS, IOC_W, MK_PTR(TYPE_ULONGLONG))
 #endif
+#ifdef BTRFS_IOC_SCRUB
+ IOCTL(BTRFS_IOC_SCRUB, IOC_RW,
+   MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args)))
+#endif
+#ifdef BTRFS_IOC_SCRUB_CANCEL
+ IOCTL(BTRFS_IOC_SCRUB_CANCEL, 0, TYPE_NULL)
+#endif
+#ifdef BTRFS_IOC_SCRUB_PROGRESS
+ IOCTL(BTRFS_IOC_SCRUB_PROGRESS, IOC_RW,
+   MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_scrub_args)))
+#endif
 #ifdef BTRFS_IOC_DEV_INFO
  IOCTL(BTRFS_IOC_DEV_INFO, IOC_RW,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_dev_info_args)))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 1b1b2c2d96..83c291f2d3 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -982,6 +982,9 @@ struct target_rtc_pll_info {
abi_ullong)
 #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGSTARGET_IOW(BTRFS_IOCTL_MAGIC, 
26,\
abi_ullong)
+#define TARGET_BTRFS_IOC_SCRUB  
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 27)
+#define TARGET_BTRFS_IOC_SCRUB_CANCEL   TARGET_IO(BTRFS_IOCTL_MAGIC, 
28)
+#define TARGET_BTRFS_IOC_SCRUB_PROGRESS 
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 29)
 #define TARGET_BTRFS_IOC_DEV_INFO   
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30)
 #define TARGET_BTRFS_IOC_INO_PATHS  
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 35)
 #define TARGET_BTRFS_IOC_LOGICAL_INO
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 36)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 2f5bad808e..fd6a91a309 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -373,6 +373,33 @@ STRUCT(btrfs_ioctl_ino_lookup_user_args,
MK_ARRAY(TYPE_CHAR, BTRFS_VOL_NAME_MAX + 1), /* name */
MK_ARRAY(TYPE_CHAR, BTRFS_INO_LOOKUP_USER_PATH_MAX)) /* path */
 
+STRUCT(btrfs_scrub_progress,
+   TYPE_ULONGLONG, /* data_extents_scrubbed */
+   TYPE_ULONGLONG, /* tree_extents_scrubbed */
+   TYPE_ULONGLONG, /* data_bytes_scrubbed */
+   TYPE_ULONGLONG, /* tree_bytes_scrubbed */
+   TYPE_ULONGLONG, /* read_errors */
+   TYPE_ULONGLONG, /* csum_errors */
+   TYPE_ULONGLONG, /* verify_errors */
+   TYPE_ULONGLONG, /* no_csum */
+   TYPE_ULONGLONG, /* csum_discards */
+   TYPE_ULONGLONG, /* super_errors */
+   TYPE_ULONGLONG, /* malloc_errors */
+   TYPE_ULONGLONG, /* uncorrectable_errors */
+   TYPE_ULONGLONG, /* corrected_er */
+   TYPE_ULONGLONG, /* last_physical */
+   TYPE_ULONGLONG) /* unverified_errors */
+
+STRUCT(btrfs_ioctl_

[PATCH v2 4/8] linux-user: Add support for btrfs ioctls used to get/set features

2020-08-03 Thread Filip Bozuta
This patch implements functionality for following ioctls:

BTRFS_IOC_GET_FEATURES - Getting feature flags

Read feature flags for a btrfs filesystem. The feature flags
are returned inside the ioctl's third argument which represents
a pointer to a following structure type:

struct btrfs_ioctl_feature_flags {
__u64 compat_flags;
__u64 compat_ro_flags;
__u64 incompat_flags;
};

All of the structure field represent bit masks that can be composed
of values which can be found on:
https://elixir.bootlin.com/linux/latest/source/fs/btrfs/ctree.h#L282

BTRFS_IOC_SET_FEATURES - Setting feature flags

Set and clear feature flags for a btrfs filesystem. The feature flags
are set using the ioctl's third argument which represents a
'struct btrfs_ioctl_feature_flags[2]' array. The first element of the
array represent flags which are to be cleared and the second element of
the array represent flags which are to be set. The second element has the
priority over the first, which means that if there are matching flags
in the elements, they will be set in the filesystem. If the flag values
in the third argument aren't correctly set to be composed of the available
predefined flag values, errno ENOPERM ("Operation not permitted") is 
returned.

BTRFS_IOC_GET_SUPPORTED_FEATURES - Getting supported feature flags

Read supported feature flags for a btrfs filesystem. The supported
feature flags are read using the ioctl's third argument which represents
a 'struct btrfs_ioctl_feature_flags[3]' array. The first element of this
array represents all of the supported flags in the btrfs filesystem.
The second element represents flags that can be safely set and third element
represent flags that can be safely clearead.

Implementation notes:

All of the implemented ioctls use 'struct btrfs_ioctl_feature_flags' as
third argument. That is the reason why a corresponding defintion was added
    in file 'linux-user/syscall_types.h'.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/ioctls.h| 12 
 linux-user/syscall_defs.h  |  3 +++
 linux-user/syscall_types.h |  5 +
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c20bd97736..c6303a0406 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -216,6 +216,18 @@
  IOCTL(BTRFS_IOC_GET_DEV_STATS, IOC_RW,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_dev_stats)))
 #endif
+#ifdef BTRFS_IOC_GET_FEATURES
+ IOCTL(BTRFS_IOC_GET_FEATURES, IOC_R,
+   MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags)))
+#endif
+#ifdef BTRFS_IOC_SET_FEATURES
+ IOCTL(BTRFS_IOC_SET_FEATURES, IOC_W,
+   MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 2)))
+#endif
+#ifdef BTRFS_IOC_GET_SUPPORTED_FEATURES
+ IOCTL(BTRFS_IOC_GET_SUPPORTED_FEATURES, IOC_R,
+   MK_PTR(MK_ARRAY(MK_STRUCT(STRUCT_btrfs_ioctl_feature_flags), 3)))
+#endif
 #ifdef BTRFS_IOC_GET_SUBVOL_INFO
  IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args)))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 23f966d552..13a444356b 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -981,6 +981,9 @@ struct target_rtc_pll_info {
abi_ullong)
 #define TARGET_BTRFS_IOC_DEV_INFO   
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 30)
 #define TARGET_BTRFS_IOC_GET_DEV_STATS  
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 52)
+#define TARGET_BTRFS_IOC_GET_FEATURES   TARGET_IORU(BTRFS_IOCTL_MAGIC, 
57)
+#define TARGET_BTRFS_IOC_SET_FEATURES   TARGET_IOWU(BTRFS_IOCTL_MAGIC, 
57)
+#define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 
57)
 #define TARGET_BTRFS_IOC_GET_SUBVOL_INFOTARGET_IORU(BTRFS_IOCTL_MAGIC, 
60)
 
 /* usb ioctls */
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index b5718231e5..e26ab01e8f 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -365,6 +365,11 @@ STRUCT(btrfs_ioctl_get_dev_stats,
MK_ARRAY(TYPE_ULONGLONG,
 128 - 2 - BTRFS_DEV_STAT_VALUES_MAX)) /* unused */
 
+STRUCT(btrfs_ioctl_feature_flags,
+   TYPE_ULONGLONG, /* compat_flags */
+   TYPE_ULONGLONG, /* compat_ro_flags */
+   TYPE_ULONGLONG) /* incompat_flags */
+
 STRUCT(rtc_time,
TYPE_INT, /* tm_sec */
TYPE_INT, /* tm_min */
-- 
2.25.1




[PATCH v2 7/8] linux-user: Add support for btrfs ioctls used to manage quota

2020-08-03 Thread Filip Bozuta
This patch implements functionality for following ioctls:

BTRFS_IOC_QUOTA_CTL - Enabling/Disabling quota support

Enable or disable quota support for a btrfs filesystem. Quota
support is enabled or disabled using the ioctls third argument
which represents a pointer to a following type:

struct btrfs_ioctl_quota_ctl_args {
__u64 cmd;
__u64 status;
};

Before calling this ioctl, the 'cmd' field should be filled
with one of the values 'BTRFS_QUOTA_CTL_ENABLE' (enabling quota)
'BTRFS_QUOTA_CTL_DISABLE' (disabling quota).

BTRFS_IOC_QGROUP_CREATE - Creating/Removing a subvolume quota group

Create or remove a subvolume quota group. The subvolume quota
group is created or removed using the ioctl's third argument which
represents a pointer to a following type:

struct btrfs_ioctl_qgroup_create_args {
__u64 create;
__u64 qgroupid;
};

Before calling this ioctl, the 'create' field should be filled
with the aproppriate value depending on if the user wants to
create or remove a quota group (0 for removing, everything else
for creating). Also, the 'qgroupid' field should be filled with
the value for the quota group id that is to be created.

BTRFS_IOC_QGROUP_ASSIGN - Asigning or removing a quota group as child group

Asign or remove a quota group as child quota group of another
group in the btrfs filesystem. The asignment is done using the
ioctl's third argument which represents a pointert to a following type:

struct btrfs_ioctl_qgroup_assign_args {
__u64 assign;
__u64 src;
__u64 dst;
};

Before calling this ioctl, the 'assign' field should be filled with
the aproppriate value depending on if the user wants to asign or remove
a quota group as a child quota group of another group (0 for removing,
everythin else for asigning). Also, the 'src' and 'dst' fields should
be filled with the aproppriate quota group id values depending on which
quota group needs to asigned or removed as child quota group of another
group ('src' gets asigned or removed as child group of 'dst').

BTRFS_IOC_QGROUP_LIMIT - Limiting the size of a quota group

Limit the size of a quota group. The size of the quota group is limited
with the ioctls third argument which represents a pointer to a following
type:

struct btrfs_ioctl_qgroup_limit_args {
__u64   qgroupid;
struct btrfs_qgroup_limit lim;
};

Before calling this ioctl, the 'qgroup' id field should be filled with
aproppriate value of the quota group id for which the size is to be
limited. The second field is of following type:

struct btrfs_qgroup_limit {
__u64   flags;
__u64   max_rfer;
__u64   max_excl;
__u64   rsv_rfer;
__u64   rsv_excl;
};

The 'max_rfer' field should be filled with the size to which the quota
group should be limited. The 'flags' field can be used for passing
additional options and can have values which can be found on:

https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/btrfs.h#L67

BTRFS_IOC_QUOTA_RESCAN_STATUS - Checking status of running rescan operation

Check status of a running rescan operation. The status is checked using
the ioctl's third argument which represents a pointer to a following type:

struct btrfs_ioctl_quota_rescan_args {
__u64   flags;
__u64   progress;
__u64   reserved[6];
};

If there is a rescan operation running, 'flags' field is set to 1, and
'progress' field is set to aproppriate value which represents the progress
of the operation.

BTRFS_IOC_QUOTA_RESCAN - Starting a rescan operation

Start ar rescan operation to Trash all quota groups and scan the metadata
again with the current config. Before calling this ioctl,
BTRFS_IOC_QUOTA_RESCAN_STATUS sould be run to check if there is already a
rescan operation runing. After that ioctl call, the received
'struct btrfs_ioctl_quota_rescan_args' should be than passed as this ioctls
third argument.

BTRFS_IOC_QUOTA_RESCAN_WAIT - Waiting for a rescan operation to finish

Wait until a rescan operation is finished (if there is a rescan operation
running). The third ioctls argument is ignored.

Implementation notes:

Almost all of the ioctls in this patch use structure types as third 
arguments.
That is the reason why aproppriate thunk definitions were added in file
'syscall_types.h'.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/ioctls.h| 27 +++
 linux-user/syscall_defs.h  |  7 +++
 linux-user/syscall_types.h | 29 +
 3 files changed, 63 inser

[PATCH v2 6/8] linux-user: Add support for two btrfs ioctls used for subvolume

2020-08-03 Thread Filip Bozuta
This patch implements functionality for following ioctl:

BTRFS_IOC_DEFAULT_SUBVOL - Setting a default subvolume

Set a default subvolume for a btrfs filesystem. The third
ioctl's argument is a '__u64' (unsigned long long) which
represents the id of a subvolume that is to be set as
the default.

BTRFS_IOC_GET_SUBVOL_ROOTREF - Getting tree and directory id of subvolumes

Read tree and directory id of subvolumes from a btrfs
filesystem. The tree and directory id's are returned in the
ioctl's third argument which represents a pointer to a
following type:

struct btrfs_ioctl_get_subvol_rootref_args {
/* in/out, minimum id of rootref's treeid to be searched */
__u64 min_treeid;

/* out */
struct {
__u64 treeid;
__u64 dirid;
} rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM];

/* out, number of found items */
__u8 num_items;
__u8 align[7];
 };

 Before calling this ioctl, 'min_treeid' field should be filled
 with value that represent the minimum value for the tree id.

Implementation notes:

Ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF uses the above mentioned structure
type as third argument. That is the reason why a aproppriate thunk
structure definition is added in file 'syscall_types.h'.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/ioctls.h|  7 +++
 linux-user/syscall_defs.h  |  3 +++
 linux-user/syscall_types.h | 11 +++
 3 files changed, 21 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index a7f5664487..2c553103e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -206,6 +206,9 @@
  IOCTL(BTRFS_IOC_INO_LOOKUP, IOC_RW,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_args)))
 #endif
+#ifdef BTRFS_IOC_DEFAULT_SUBVOL
+ IOCTL(BTRFS_IOC_DEFAULT_SUBVOL, IOC_W, MK_PTR(TYPE_ULONGLONG))
+#endif
 #ifdef BTRFS_IOC_SUBVOL_GETFLAGS
  IOCTL(BTRFS_IOC_SUBVOL_GETFLAGS, IOC_R, MK_PTR(TYPE_ULONGLONG))
 #endif
@@ -248,6 +251,10 @@
  IOCTL(BTRFS_IOC_GET_SUBVOL_INFO, IOC_R,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_info_args)))
 #endif
+#ifdef BTRFS_IOC_GET_SUBVOL_ROOTREF
+ IOCTL(BTRFS_IOC_GET_SUBVOL_ROOTREF, IOC_RW,
+   MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_get_subvol_rootref_args)))
+#endif
 #ifdef BTRFS_IOC_INO_LOOKUP_USER
  IOCTL(BTRFS_IOC_INO_LOOKUP_USER, IOC_RW,
MK_PTR(MK_STRUCT(STRUCT_btrfs_ioctl_ino_lookup_user_args)))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 538b884b8f..f1718ac521 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -976,6 +976,8 @@ struct target_rtc_pll_info {
 #define TARGET_BTRFS_IOC_SUBVOL_CREATE  TARGET_IOWU(BTRFS_IOCTL_MAGIC, 
14)
 #define TARGET_BTRFS_IOC_SNAP_DESTROY   TARGET_IOWU(BTRFS_IOCTL_MAGIC, 
15)
 #define TARGET_BTRFS_IOC_INO_LOOKUP 
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 18)
+#define TARGET_BTRFS_IOC_DEFAULT_SUBVOL TARGET_IOW(BTRFS_IOCTL_MAGIC, 
19,\
+   abi_ullong)
 #define TARGET_BTRFS_IOC_SUBVOL_GETFLAGSTARGET_IOR(BTRFS_IOCTL_MAGIC, 
25,\
abi_ullong)
 #define TARGET_BTRFS_IOC_SUBVOL_SETFLAGSTARGET_IOW(BTRFS_IOCTL_MAGIC, 
26,\
@@ -989,6 +991,7 @@ struct target_rtc_pll_info {
 #define TARGET_BTRFS_IOC_GET_SUPPORTED_FEATURES TARGET_IORU(BTRFS_IOCTL_MAGIC, 
57)
 #define TARGET_BTRFS_IOC_LOGICAL_INO_V2 
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 59)
 #define TARGET_BTRFS_IOC_GET_SUBVOL_INFOTARGET_IORU(BTRFS_IOCTL_MAGIC, 
60)
+#define TARGET_BTRFS_IOC_GET_SUBVOL_ROOTREF 
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 61)
 #define TARGET_BTRFS_IOC_INO_LOOKUP_USER
TARGET_IOWRU(BTRFS_IOCTL_MAGIC, 62)
 
 /* usb ioctls */
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 978f2d682c..6bac8f46bb 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -381,6 +381,17 @@ STRUCT(btrfs_ioctl_dev_info_args,
MK_ARRAY(TYPE_ULONGLONG, 379), /* unused */
MK_ARRAY(TYPE_CHAR, BTRFS_DEVICE_PATH_NAME_MAX)) /* path */
 
+STRUCT(rootref,
+   TYPE_ULONGLONG, /* treeid */
+   TYPE_ULONGLONG) /* dirid */
+
+STRUCT(btrfs_ioctl_get_subvol_rootref_args,
+   TYPE_ULONGLONG, /* min_treeid */
+   MK_ARRAY(MK_STRUCT(STRUCT_rootref),
+BTRFS_MAX_ROOTREF_BUFFER_NUM), /* rootref */
+   TYPE_CHAR, /* num_items */
+   MK_ARRAY(TYPE_CHAR, 7)) /* align */
+
 STRUCT(btrfs_ioctl_get_dev_stats,
TYPE_ULONGLONG, /* devid */
TYPE_ULONGLONG, /* nr_items */
-- 
2.25.1




[PATCH v2 0/8] linux-user: Adding support for a group of btrfs ioctls

2020-08-03 Thread Filip Bozuta
This series covers support for following btrfs ioctls

*BTRFS_SUBVOL_CREATE   *BTRFS_IOC_ADD_DEV
*BTRFS_SUBVOL_SETFLAGS *BTRFS_IOC_RM_DEV
*BTRFS_SUBVOL_GETFLAGS *BTRFS_IOC_DEV_INFO
*BTRFS_GET_SUBVOL_INFO *BTRFS_IOC_GET_DEV_STATS
*BTRFS_IOC_SNAP_CREATE *BTRFS_IOC_GET_FEATURES
*BTRFS_IOC_SNAP_DESTROY*BTRFS_IOC_SET_FEATURES
*BTRFS_IOC_SCAN_DEV*BTRFS_IOC_GET_SUPPORTED_FEATURES
*BTRFS_IOC_DEFAULT_SUBVOL  *BTRFS_IOC_QUOTA_RESCAN
*BTRFS_IOC_GET_SUBVOL_ROOTREF  *BTRFS_IOC_QUOTA_RESCAN_WAIT
*BTRFS_IOC_QUOTA_CTL   *BTRFS_IOC_SCRUB
*BTRFS_IOC_QGROUP_CREATE   *BTRFS_IOC_SCRUB_CANCEL
*BTRFS_IOC_QGROUP_ASSIGN   *BTRFS_IOC_SCRUB_PROGRESS
*BTRFS_IOC_INO_PATHS   *BTRFS_IOC_QGROUP_LIMIT
*BTRFS_IOC_LOGICAL_INO *BTRFS_IOC_QUOTA_RESCAN_STATUS
*BTRFS_IOC_LOGICAL_INO_V2
*BTRFS_IOC_INO_LOOKUP_USER
*BTRFS_IOC_INO_LOOKUP

The functionalities of individual ioctls were described in this series
patch commit messages. Since all of these ioctls are added in kernel
version 3.9, their definitions in file 'linux-user/ioctls.h' are
enwrapped in an #ifdef directive.

Testing method:

Mini test programs were written for these ioctls. These test programs
can be found on a repositort which is located on the link:
https://github.com/bozutaf/btrfs-tests

These test programs were compiled (sometimes using cross compilers) for
following architectures:

 * Intel 64-bit (little endian)
 * Power pc 32-bit (big endian)
 * Power pc 64-bit (big endian)

The corresponding native programs were executed without using QEMU on
an intel x86_64 host.

All applicable compiled programs were in turn executed through QEMU
and the results obtained were the same ones gotten for native
execution.

v2:

* Merged two series in one 8 patch series
* Changed target ioctl definitions from IOR/IOW/IOWR to IORU/IOWU/IOWRU
* Fixed some thunk struct definitions

Filip Bozuta (8):
  linux-user: Add support for a group of btrfs ioctls used for
subvolumes
  linux-user: Add support for a group of btrfs ioctls used for snapshots
  linux-user: Add support for btrfs ioctls used to manipulate with
devices
  linux-user: Add support for btrfs ioctls used to get/set features
  linux-user: Add support for a group of btrfs inode ioctls
  linux-user: Add support for two btrfs ioctls used for subvolume
  linux-user: Add support for btrfs ioctls used to manage quota
  linux-user: Add support for btrfs ioctls used to scrub a filesystem

 configure  |   9 +++
 linux-user/ioctls.h| 124 
 linux-user/syscall.c   |   3 +
 linux-user/syscall_defs.h  |  37 ++
 linux-user/syscall_types.h | 140 +
 5 files changed, 313 insertions(+)

-- 
2.25.1




[PATCH] linux-user: Fix 'utimensat()' implementation

2020-08-11 Thread Filip Bozuta
Implementation of syscall 'utimensat()' in 'syscall.c' uses functions
target_to_host/host_to_target_timespec() to convert values of
'struct timespec' between host and target. However, the implementation
doesn't check whether the conversion succeeds and thus can cause an
inappropriate error or succeed unappropriately instead of setting errno
EFAULT ('Bad address') which is supposed to be set in these cases.

This was confirmed with the LTP test for utimensat ('testcases/utimensat')
which fails for test cases when the errno EFAULT is expected. After changes
from this patch, the test passes for all test cases.

Signed-off-by: Filip Bozuta 
---
 linux-user/syscall.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 05f03919ff..920656191b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11722,8 +11722,13 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 if (!arg3) {
 tsp = NULL;
 } else {
-target_to_host_timespec(ts, arg3);
-target_to_host_timespec(ts+1, arg3+sizeof(struct 
target_timespec));
+if (target_to_host_timespec(ts, arg3)) {
+return -TARGET_EFAULT;
+}
+if (target_to_host_timespec(ts + 1, arg3 +
+sizeof(struct target_timespec))) {
+return -TARGET_EFAULT;
+}
 tsp = ts;
 }
 if (!arg2)
-- 
2.25.1




[PATCH v4 2/5] linux-user: Add strace support for printing arguments of truncate()/ftruncate() and getsid()

2020-08-11 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* truncate, ftruncate - truncate a file to a specified length

int truncate/truncate64(const char *path, off_t length)
int ftruncate/ftruncate64(int fd, off_t length)
man page: https://man7.org/linux/man-pages/man2/truncate.2.html

* getsid - get session ID

pid_t getsid(pid_t pid)
man page: https://man7.org/linux/man-pages/man2/getsid.2.html

Implementation notes:

Syscalls truncate/truncate64 take string argument types and thus a
separate print function "print_truncate/print_truncate64" is stated in
file "strace.list". This function is defined and implemented in "strace.c"
by using an existing function used to print string arguments: 
"print_string()".
For syscall ftruncate64, a separate printing function was also stated in
"strace.c" as it requires a special kind of handling.
The other syscalls have only primitive argument types, so the rest of the
implementation was handled by stating an appropriate printing format in file
"strace.list".
Function "regpairs_aligned()" was cut & pasted from "syscall.c" to "qemu.h"
as it is used by functions "print_truncate64()" and "print_ftruncate64()"
to print the offset arguments of "truncate64()" and "ftruncate64()".

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/qemu.h  | 35 +++
 linux-user/strace.c| 47 ++
 linux-user/strace.list | 10 -
 linux-user/syscall.c   | 32 
 4 files changed, 87 insertions(+), 37 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 63ddfe86fd..f431805e57 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -706,6 +706,41 @@ static inline uint64_t target_offset64(uint64_t word0, 
uint64_t word1)
 }
 #endif /* TARGET_ABI_BITS != 32 */
 
+
+/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
+#ifdef TARGET_ARM
+static inline int regpairs_aligned(void *cpu_env, int num)
+{
+return CPUARMState *)cpu_env)->eabi) == 1) ;
+}
+#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
+/*
+ * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
+ * of registers which translates to the same as ARM/MIPS, because we start with
+ * r3 as arg1
+ */
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+#elif defined(TARGET_SH4)
+/* SH4 doesn't align register pairs, except for p{read,write}64 */
+static inline int regpairs_aligned(void *cpu_env, int num)
+{
+switch (num) {
+case TARGET_NR_pread64:
+case TARGET_NR_pwrite64:
+return 1;
+
+default:
+return 0;
+}
+}
+#elif defined(TARGET_XTENSA)
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+#else
+static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
+#endif
+
 /**
  * preexit_cleanup: housekeeping before the guest exits
  *
diff --git a/linux-user/strace.c b/linux-user/strace.c
index f0624b6206..7dc239b9f1 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1958,6 +1958,53 @@ print_lseek(void *cpu_env, const struct syscallname 
*name,
 }
 #endif
 
+#ifdef TARGET_NR_truncate
+static void
+print_truncate(void *cpu_env, const struct syscallname *name,
+   abi_long arg0, abi_long arg1, abi_long arg2,
+   abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_truncate64
+static void
+print_truncate64(void *cpu_env, const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
+arg1 = arg2;
+arg2 = arg3;
+}
+print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_ftruncate64
+static void
+print_ftruncate64(void *cpu_env, const struct syscallname *name,
+  abi_long arg0, abi_long arg1, abi_long arg2,
+  abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
+arg1 = arg2;
+arg2 = arg3;
+}
+print_raw_param("%" PRIu64, ta

[PATCH v4 0/5] Add strace support for printing arguments for a group of selected syscalls

2020-08-11 Thread Filip Bozuta
This series covers strace support for following syscalls:

   *truncate() *munlock()  *clock_gettimeofday()
   *ftruncate()*munlockall()   *clock_getitimer()
   *getsid()   *clock_getres() *clock_setitimer()
   *mlock()*clock_gettime()
   *mlockall() *clock_settime()

Testing method:

Mini test programs were written that run these syscalls for different 
arguments.
Those programs were compiled (sometimes using cross-compilers) for the 
following
architectures:

* Intel 64-bit (little endian) (gcc)
* Power pc 32-bit (big endian) (powerpc-linux-gnu-gcc)
* Power pc 64-bit (big endian) (powerpc64-linux-gnu-gcc)

The corresponding native programs were executed with strace, without using
QEMU, on intel (x86_64) host.

All applicable compiled programs were in turn executed with "-strace"
through QEMU and the strace printing results obtained were the same
ones gotten for native execution.

v2:
* added patch that enables 'cpu_env' to be accessible from "strace.c"
* cut and pasted "regpairs_aligned" from 'syscall.c' to 'qemu.h' so
  that it can be used for "print_truncate64" and "print_ftruncate64"
* changed flag names from 'TARGET_MLOCKALL_MCL_*' to 'TARGET_MCL_*'
* added target flag value 'TARGET_MCL_ONFAULT' for 'MCL_ONFAULT'
* added 'print_syscall_ret_setitimer' for old value of the interval
  timer
* added a function 'print_itimer_type' that prints the interval timer
  type

v3:

* added patch that introduces an api that prints enumarted values
  with strace
* used this new introduced api to print certain arguments of syscalls
  in patch 4
* rebased the series to use the new 'print_syscall_err()'

v4:

* modified 'print_itimerval()' function in 'syscall.c'

Filip Bozuta (5):
  linux-user: Make cpu_env accessible in strace.c
  linux-user: Add strace support for printing arguments of
truncate()/ftruncate() and getsid()
  linux-user: Add strace support for printing arguments of syscalls used
to lock and unlock memory
  linux-user: Add an api to print enumareted argument values with strace
  linux-user: Add strace support for printing arguments of some clock
and time functions

 linux-user/aarch64/target_syscall.h|   5 +-
 linux-user/alpha/target_syscall.h  |   5 +-
 linux-user/arm/target_syscall.h|   6 +-
 linux-user/cris/target_syscall.h   |   5 +-
 linux-user/hppa/target_syscall.h   |   5 +-
 linux-user/i386/target_syscall.h   |   5 +-
 linux-user/m68k/target_syscall.h   |   6 +-
 linux-user/microblaze/target_syscall.h |   5 +-
 linux-user/mips/target_syscall.h   |   5 +-
 linux-user/mips64/target_syscall.h |   5 +-
 linux-user/nios2/target_syscall.h  |   5 +-
 linux-user/openrisc/target_syscall.h   |   5 +-
 linux-user/ppc/target_syscall.h|   5 +-
 linux-user/qemu.h  |  39 +-
 linux-user/riscv/target_syscall.h  |   5 +-
 linux-user/s390x/target_syscall.h  |   5 +-
 linux-user/sh4/target_syscall.h|   5 +-
 linux-user/sparc/target_syscall.h  |   5 +-
 linux-user/sparc64/target_syscall.h|   5 +-
 linux-user/strace.c| 865 -
 linux-user/strace.list |  35 +-
 linux-user/syscall.c   |  47 +-
 linux-user/tilegx/target_syscall.h |   5 +-
 linux-user/x86_64/target_syscall.h |   5 +-
 linux-user/xtensa/target_syscall.h |   5 +-
 25 files changed, 694 insertions(+), 399 deletions(-)

-- 
2.25.1




[PATCH v4 4/5] linux-user: Add an api to print enumareted argument values with strace

2020-08-11 Thread Filip Bozuta
This patch introduces a type 'struct enums' and function 'print_enums()'
that can be used to print enumerated argument values of some syscalls
in strace. This can be used in future strace implementations.

Also, macros 'ENUM_GENERIC()', 'ENUM_TARGET()' and 'ENUM_END', are
introduced to enable automatic generation of aproppriate enumarated
values and their repsective string representations (these macros are
exactly the same as 'FLAG_GENERIC()', 'FLAG_TARGET()' and 'FLAG_END').

Future patches are planned to modify all existing print functions in
'strace.c' that print arguments of syscalls with enumerated values to
use this new api.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/strace.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 40f863c6e2..def92c4d73 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -52,9 +52,23 @@ struct flags {
 /* end of flags array */
 #define FLAG_END   { 0, NULL }
 
+/* Structure used to translate enumerated values into strings */
+struct enums {
+abi_longe_value;   /* enum value */
+const char  *e_string; /* stringified enum */
+};
+
+/* common enums for all architectures */
+#define ENUM_GENERIC(name) { name, #name }
+/* target specific enums */
+#define ENUM_TARGET(name)  { TARGET_ ## name, #name }
+/* end of enums array */
+#define ENUM_END   { 0, NULL }
+
 UNUSED static const char *get_comma(int);
 UNUSED static void print_pointer(abi_long, int);
 UNUSED static void print_flags(const struct flags *, abi_long, int);
+UNUSED static void print_enums(const struct enums *, abi_long, int);
 UNUSED static void print_at_dirfd(abi_long, int);
 UNUSED static void print_file_mode(abi_long, int);
 UNUSED static void print_open_flags(abi_long, int);
@@ -1248,6 +1262,23 @@ print_flags(const struct flags *f, abi_long flags, int 
last)
 }
 }
 
+static void
+print_enums(const struct enums *e, abi_long enum_arg, int last)
+{
+for (; e->e_string != NULL; e++) {
+if (e->e_value == enum_arg) {
+qemu_log("%s", e->e_string);
+break;
+}
+}
+
+if (e->e_string == NULL) {
+qemu_log("%#x", (unsigned int)enum_arg);
+}
+
+qemu_log("%s", get_comma(last));
+}
+
 static void
 print_at_dirfd(abi_long dirfd, int last)
 {
-- 
2.25.1




[PATCH v4 3/5] linux-user: Add strace support for printing arguments of syscalls used to lock and unlock memory

2020-08-11 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* mlock, munlock, mlockall, munlockall - lock and unlock memory

   int mlock(const void *addr, size_t len)
   int munlock(const void *addr, size_t len)
   int mlockall(int flags)
   int munlockall(void)
   man page: https://man7.org/linux/man-pages/man2/mlock.2.html

Implementation notes:

Syscall mlockall() takes an argument that is composed of predefined values
which represent flags that determine the type of locking operation that is
to be performed. For that reason, a printing function "print_mlockall" was
stated in file "strace.list". This printing function uses an already 
existing
function "print_flags()" to print the "flags" argument.  These flags are 
stated
inside an array "mlockall_flags" that contains values of type "struct 
flags".
These values are instantiated using an existing macro "FLAG_TARGET()" that
crates aproppriate target flag values based on those defined in files
'/target_syscall.h'. These target flag values were changed from
"TARGET_MLOCKALL_MCL*" to "TARGET_MCL_*" so that they can be aproppriately 
set
and recognised in "strace.c" with "FLAG_TARGET()". Value for "MCL_ONFAULT"
was added in this patch. This value was also added in "syscall.c" in 
function
"target_to_host_mlockall_arg()". Because this flag value was added in kernel
version 4.4, it is enwrapped in an #ifdef directive (both in "syscall.c" and
in "strace.c") as to support older kernel versions.
The other syscalls have only primitive argument types, so the
rest of the implementation was handled by stating an appropriate
printing format in file "strace.list". Syscall mlock2() is not implemented 
in
"syscall.c" and thus it's argument printing is not implemented in this 
patch.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/aarch64/target_syscall.h|  5 +++--
 linux-user/alpha/target_syscall.h  |  5 +++--
 linux-user/arm/target_syscall.h|  6 --
 linux-user/cris/target_syscall.h   |  5 +++--
 linux-user/hppa/target_syscall.h   |  5 +++--
 linux-user/i386/target_syscall.h   |  5 +++--
 linux-user/m68k/target_syscall.h   |  6 +++---
 linux-user/microblaze/target_syscall.h |  5 +++--
 linux-user/mips/target_syscall.h   |  5 +++--
 linux-user/mips64/target_syscall.h |  5 +++--
 linux-user/nios2/target_syscall.h  |  5 +++--
 linux-user/openrisc/target_syscall.h   |  5 +++--
 linux-user/ppc/target_syscall.h|  5 +++--
 linux-user/riscv/target_syscall.h  |  5 +++--
 linux-user/s390x/target_syscall.h  |  5 +++--
 linux-user/sh4/target_syscall.h|  5 +++--
 linux-user/sparc/target_syscall.h  |  5 +++--
 linux-user/sparc64/target_syscall.h|  5 +++--
 linux-user/strace.c| 21 +
 linux-user/strace.list |  8 
 linux-user/syscall.c   | 10 --
 linux-user/tilegx/target_syscall.h |  5 +++--
 linux-user/x86_64/target_syscall.h |  5 +++--
 linux-user/xtensa/target_syscall.h |  5 +++--
 24 files changed, 97 insertions(+), 49 deletions(-)

diff --git a/linux-user/aarch64/target_syscall.h 
b/linux-user/aarch64/target_syscall.h
index 995e475c73..3194e6b009 100644
--- a/linux-user/aarch64/target_syscall.h
+++ b/linux-user/aarch64/target_syscall.h
@@ -16,8 +16,9 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "3.8.0"
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ   2048
-#define TARGET_MLOCKALL_MCL_CURRENT 1
-#define TARGET_MLOCKALL_MCL_FUTURE  2
+#define TARGET_MCL_CURRENT 1
+#define TARGET_MCL_FUTURE  2
+#define TARGET_MCL_ONFAULT 4
 
 #define TARGET_PR_SVE_SET_VL  50
 #define TARGET_PR_SVE_GET_VL  51
diff --git a/linux-user/alpha/target_syscall.h 
b/linux-user/alpha/target_syscall.h
index 3426cc5b4e..fd389422e3 100644
--- a/linux-user/alpha/target_syscall.h
+++ b/linux-user/alpha/target_syscall.h
@@ -258,7 +258,8 @@ struct target_pt_regs {
 #define TARGET_UAC_NOFIX   2
 #define TARGET_UAC_SIGBUS  4
 #define TARGET_MINSIGSTKSZ  4096
-#define TARGET_MLOCKALL_MCL_CURRENT 0x2000
-#define TARGET_MLOCKALL_MCL_FUTURE  0x4000
+#define TARGET_MCL_CURRENT 0x2000
+#define TARGET_MCL_FUTURE  0x4000
+#define TARGET_MCL_ONFAULT 0x8000
 
 #endif /* ALPHA_TARGET_SYSCALL_H */
diff --git a/linux-user/arm/target_syscall.h b/linux-user/arm/target_syscall.h
index f85cbdaf56..e870ed7a54 100644
--- a/linux-user/arm/target_syscall.h
+++ b/linux-user/arm/target_syscall.h
@@ -28,8 +28,10 @@ struct target_pt_regs {
 #define TARGET_CLONE_BACKWARDS
 
 #define TARGET_MINSIGSTKSZ 2048
-#define TA

[PATCH v4 5/5] linux-user: Add strace support for printing arguments of some clock and time functions

2020-08-11 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* clock_getres, clock_gettime, clock_settime - clock and time functions

int clock_getres(clockid_t clockid, struct timespec *res)
int clock_gettime(clockid_t clockid, struct timespec *tp)
int clock_settime(clockid_t clockid, const struct timespec *tp)
man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html

* gettimeofday - get time

int gettimeofday(struct timeval *tv, struct timezone *tz)
man page: https://man7.org/linux/man-pages/man2/gettimeofday.2.html

* getitimer, setitimer - get or set value of an interval timer

int getitimer(int which, struct itimerval *curr_value)
int setitimer(int which, const struct itimerval *new_value,
  struct itimerval *old_value)
man page: https://man7.org/linux/man-pages/man2/getitimer.2.html

Implementation notes:

All of the syscalls have some structue types as argument types and thus
a separate printing function was stated in file "strace.list" for each
of them. All of these functions use existing functions for their
appropriate structure types ("print_timeval()" and "print_timezone()").

Functions "print_timespec()" and "print_itimerval()" were added in this
patch so that they can be used to print types "struct timespec" and
"struct itimerval" used by some of the syscalls. Function 
"print_itimerval()"
uses the existing function "print_timeval()" to print fields of the
structure "struct itimerval" that are of type "struct timeval".

Function "print_enums()", which was introduced in the previous patch, is 
used
to print the interval timer type which is the first argument of 
"getitimer()"
and "setitimer()". Also, this function is used to print the clock id which
is the first argument of "clock_getres()" and "clock_gettime()". For that
reason, the existing function "print_clockid()" was removed in this patch.
Existing function "print_clock_adjtime()" was also changed for this reason
to use "print_enums()".

The existing function "print_timeval()" was changed a little so that it
prints the field names beside the values.

Syscalls "clock_getres()" and "clock_gettime()" have the same number
and types of arguments and thus their print functions "print_clock_getres"
and "print_clock_gettime" share a common definition in file "strace.c".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 287 +++--
 linux-user/strace.list |  17 ++-
 2 files changed, 232 insertions(+), 72 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index def92c4d73..1a5c4c820a 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -78,7 +78,9 @@ UNUSED static void print_string(abi_long, int);
 UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
+UNUSED static void print_timespec(abi_ulong, int);
 UNUSED static void print_timezone(abi_ulong, int);
+UNUSED static void print_itimerval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
 UNUSED static void print_signal(abi_ulong, int);
 UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
@@ -578,69 +580,6 @@ print_fdset(int n, abi_ulong target_fds_addr)
 }
 #endif
 
-#ifdef TARGET_NR_clock_adjtime
-/* IDs of the various system clocks */
-#define TARGET_CLOCK_REALTIME  0
-#define TARGET_CLOCK_MONOTONIC 1
-#define TARGET_CLOCK_PROCESS_CPUTIME_ID2
-#define TARGET_CLOCK_THREAD_CPUTIME_ID 3
-#define TARGET_CLOCK_MONOTONIC_RAW 4
-#define TARGET_CLOCK_REALTIME_COARSE   5
-#define TARGET_CLOCK_MONOTONIC_COARSE  6
-#define TARGET_CLOCK_BOOTTIME  7
-#define TARGET_CLOCK_REALTIME_ALARM8
-#define TARGET_CLOCK_BOOTTIME_ALARM9
-#define TARGET_CLOCK_SGI_CYCLE 10
-#define TARGET_CLOCK_TAI   11
-
-static void
-print_clockid(int clockid, int last)
-{
-switch (clockid) {
-case TARGET_CLOCK_REALTIME:
-qemu_log("CLOCK_REALTIME");
-break;
-case TARGET_CLOCK_MONOTONIC:
-qemu_log("CLOCK_MONOTONIC");
-break;
-case TARGET_CLOCK_PROCESS_CPUTIME_ID:
-qemu_log("CLOCK_PROCESS_CPUTIME_ID");
-break;
-case TARGET_CLOCK_THREAD_CPUTIME_ID:
-qemu_log("CLOCK_THREAD_CPUTIME_ID");
-break;
-case TARGET_CLOCK_MONOTONIC_RAW:
-qemu_log("CLOCK_MONOTONIC_RAW");
-break;
-case TARGET_CLOCK_RE

[PATCH v4 1/5] linux-user: Make cpu_env accessible in strace.c

2020-08-11 Thread Filip Bozuta
Variable "cpu_env" is used in file "syscall.c" to store
the information about the cpu environment. This variable
is used because values of some syscalls can vary between
cpu architectures. This patch makes the "cpu_env" accessible
in "strace.c" so it can enable aproppriate "-strace" argument
printing for these syscalls. This will be a useful addition
for future "-strace" implementation in QEMU.

Implementation notes:

Functions "print_syscall()" and "print_syscall_ret()" which
are stated and defined in "qemu.h" and "strace.c" respectively
are used to print syscall arguments before and after syscall
execution. These functions were changed with addition of a
new argument "void *cpu_env". Strucute "struct syscallname"
in "strace.c" is used to store the information about syscalls.
Fields "call" and "result" represent pointers to functions which
are used to print syscall arguments before and after execution.
These fields were also changed with addition of a new "void *"
argumetn.
Also, all defined "print_*" and "print_syscall_ret*" functions
in "strace.c" were changed to have the new "void *cpu_env".
This was done to not cause build errors (even though none of
these functions use this argument).

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/qemu.h|   4 +-
 linux-user/strace.c  | 479 ++-
 linux-user/syscall.c |   5 +-
 3 files changed, 247 insertions(+), 241 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 5c964389c1..63ddfe86fd 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -400,10 +400,10 @@ extern long safe_syscall_base(int *pending, long number, 
...);
 int host_to_target_waitstatus(int status);
 
 /* strace.c */
-void print_syscall(int num,
+void print_syscall(void *cpu_env, int num,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6);
-void print_syscall_ret(int num, abi_long ret,
+void print_syscall_ret(void *cpu_env, int num, abi_long ret,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6);
 /**
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 13981341b3..f0624b6206 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -16,10 +16,10 @@ struct syscallname {
 int nr;
 const char *name;
 const char *format;
-void (*call)(const struct syscallname *,
+void (*call)(void *, const struct syscallname *,
  abi_long, abi_long, abi_long,
  abi_long, abi_long, abi_long);
-void (*result)(const struct syscallname *, abi_long,
+void (*result)(void *, const struct syscallname *, abi_long,
abi_long, abi_long, abi_long,
abi_long, abi_long, abi_long);
 };
@@ -634,7 +634,7 @@ print_clockid(int clockid, int last)
 /* select */
 #ifdef TARGET_NR__newselect
 static void
-print_newselect(const struct syscallname *name,
+print_newselect(void *cpu_env, const struct syscallname *name,
 abi_long arg1, abi_long arg2, abi_long arg3,
 abi_long arg4, abi_long arg5, abi_long arg6)
 {
@@ -652,7 +652,7 @@ print_newselect(const struct syscallname *name,
 
 #ifdef TARGET_NR_semctl
 static void
-print_semctl(const struct syscallname *name,
+print_semctl(void *cpu_env, const struct syscallname *name,
  abi_long arg1, abi_long arg2, abi_long arg3,
  abi_long arg4, abi_long arg5, abi_long arg6)
 {
@@ -664,7 +664,7 @@ print_semctl(const struct syscallname *name,
 #endif
 
 static void
-print_execve(const struct syscallname *name,
+print_execve(void *cpu_env, const struct syscallname *name,
  abi_long arg1, abi_long arg2, abi_long arg3,
  abi_long arg4, abi_long arg5, abi_long arg6)
 {
@@ -697,7 +697,7 @@ print_execve(const struct syscallname *name,
 
 #ifdef TARGET_NR_ipc
 static void
-print_ipc(const struct syscallname *name,
+print_ipc(void *cpu_env, const struct syscallname *name,
   abi_long arg1, abi_long arg2, abi_long arg3,
   abi_long arg4, abi_long arg5, abi_long arg6)
 {
@@ -741,9 +741,10 @@ print_syscall_err(abi_long ret)
 }
 
 static void
-print_syscall_ret_addr(const struct syscallname *name, abi_long ret,
-   abi_long arg0, abi_long arg1, abi_long arg2,
-   abi_long arg3, abi_long arg4, abi_long arg5)
+print_syscall_ret_addr(void *cpu_env, const struct syscallname *name,
+   abi_long ret, abi_long arg0, abi_long arg1,
+   abi_long arg2, abi_long arg3, abi_long arg4,
+   abi_long arg5)
 {
 if (!p

[PATCH 2/2] linux-user: Add support for 'utimensat_time64()' and 'semtimedop_time64()'

2020-08-12 Thread Filip Bozuta
This patch introduces functionality for following time64 syscalls:

*utimensat_time64()

int utimensat(int dirfd, const char *pathname,
  const struct timespec times[2], int flags);
-- change file timestamps with nanosecond precision --
man page: https://man7.org/linux/man-pages/man2/utimensat.2.html

*semtimedop_time64()

int semtimedop(int semid, struct sembuf *sops, size_t nsops,
   const struct timespec *timeout);
-- System V semaphore operations --
man page: https://www.man7.org/linux/man-pages/man2/semtimedop.2.html

Implementation notes:

   Syscall 'utimensat_time64()' is implemented in similar way as its
   regular variants only difference being that time64 converting function
   is used to convert values of 'struct timespec' between host and target
   ('target_to_host_timespec64()').

   For syscall 'semtimedop_time64()' and additional argument is added
   in function 'do_semtimedop()' through which the aproppriate 'struct timespec'
   converting function is called (0 for regular target_to_host_timespec()
   and anything else for target_to_host_timespec64()). For 'do_ipc()' an
   check was added as that additional argument: 'TARGET_ABI_BITS == 64'.

Signed-off-by: Filip Bozuta 
---
 linux-user/syscall.c | 55 
 1 file changed, 46 insertions(+), 9 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8f63a46f58..44a13c5ec2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1253,7 +1253,8 @@ static inline abi_long target_to_host_timespec(struct 
timespec *host_ts,
 #endif
 
 #if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \
-defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64)
+defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) || \
+defined(TARGET_NR_utimensat_time64) || defined(TARGET_NR_semtimedop_time64)
 static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
  abi_ulong target_addr)
 {
@@ -3886,7 +3887,7 @@ static inline abi_long target_to_host_sembuf(struct 
sembuf *host_sembuf,
 }
 
 #if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \
-defined(TARGET_NR_semtimedop)
+defined(TARGET_NR_semtimedop) || defined(TARGET_NR_semtimedop_time64)
 
 /*
  * This macro is required to handle the s390 variants, which passes the
@@ -3903,7 +3904,7 @@ static inline abi_long target_to_host_sembuf(struct 
sembuf *host_sembuf,
 static inline abi_long do_semtimedop(int semid,
  abi_long ptr,
  unsigned nsops,
- abi_long timeout)
+ abi_long timeout, int time64)
 {
 struct sembuf sops[nsops];
 struct timespec ts, *pts = NULL;
@@ -3911,7 +3912,10 @@ static inline abi_long do_semtimedop(int semid,
 
 if (timeout) {
 pts = &ts;
-if (target_to_host_timespec(pts, timeout)) {
+if (!time64 && target_to_host_timespec(pts, timeout)) {
+return -TARGET_EFAULT;
+}
+if (time64 && target_to_host_timespec64(pts, timeout)) {
 return -TARGET_EFAULT;
 }
 }
@@ -4426,7 +4430,7 @@ static abi_long do_ipc(CPUArchState *cpu_env,
 
 switch (call) {
 case IPCOP_semop:
-ret = do_semtimedop(first, ptr, second, 0);
+ret = do_semtimedop(first, ptr, second, 0, 0);
 break;
 case IPCOP_semtimedop:
 /*
@@ -4436,9 +4440,9 @@ static abi_long do_ipc(CPUArchState *cpu_env,
  * to a struct timespec where the generic variant uses fifth parameter.
  */
 #if defined(TARGET_S390X)
-ret = do_semtimedop(first, ptr, second, third);
+ret = do_semtimedop(first, ptr, second, third, TARGET_ABI_BITS == 64);
 #else
-ret = do_semtimedop(first, ptr, second, fifth);
+ret = do_semtimedop(first, ptr, second, fifth, TARGET_ABI_BITS == 64);
 #endif
 break;
 
@@ -9783,11 +9787,15 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #endif
 #ifdef TARGET_NR_semop
 case TARGET_NR_semop:
-return do_semtimedop(arg1, arg2, arg3, 0);
+return do_semtimedop(arg1, arg2, arg3, 0, 0);
 #endif
 #ifdef TARGET_NR_semtimedop
 case TARGET_NR_semtimedop:
-return do_semtimedop(arg1, arg2, arg3, arg4);
+return do_semtimedop(arg1, arg2, arg3, arg4, 0);
+#endif
+#ifdef TARGET_NR_semtimedop_time64
+case TARGET_NR_semtimedop_time64:
+return do_semtimedop(arg1, arg2, arg3, arg4, 1);
 #endif
 #ifdef TARGET_NR_semctl
 case TARGET_NR_semctl:
@@ -11969,6 +11977,35 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 }
 return ret;
 #endif
+#ifdef TARGET_NR_utimensat_time64
+case TAR

[PATCH 1/2] linux-user: Add support for 'ppoll_time64()' and 'pselect6_time64()'

2020-08-12 Thread Filip Bozuta
This patch introduces functionality for following time64 syscalls:

*ppoll_time64

This is a year 2038 safe variant of:

int poll(struct pollfd *fds, nfds_t nfds, int timeout)
-- wait for some event on a file descriptor --
man page: https://man7.org/linux/man-pages/man2/ppoll.2.html

*pselect6_time64

This is a year 2038 safe variant of:

int pselect6(int nfds, fd_set *readfds, fd_set *writefds,
 fd_set *exceptfds, const struct timespec *timeout,
 const sigset_t *sigmask);
-- synchronous I/O multiplexing --
man page: https://man7.org/linux/man-pages/man2/pselect6.2.html

Implementation notes:

Year 2038 safe syscalls in this patch were implemented
with the same code as their regular variants (ppoll() and pselect()).
A switch/case statement was used to call an apropriate converting
function for 'struct timespec' between target and host.
(target_to_host/host_to_target_timespec() for regular and
 target_to_host/host_to_target_timespec64() for time64 variants)

Signed-off-by: Filip Bozuta 
---
 linux-user/syscall.c | 101 ---
 1 file changed, 86 insertions(+), 15 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1211e759c2..8f63a46f58 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -397,7 +397,7 @@ static int sys_getcwd1(char *buf, size_t size)
   return strlen(buf)+1;
 }
 
-#ifdef TARGET_NR_utimensat
+#if defined(TARGET_NR_utimensat)
 #if defined(__NR_utimensat)
 #define __NR_sys_utimensat __NR_utimensat
 _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,
@@ -763,11 +763,11 @@ safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, 
siginfo_t *, infop, \
   int, options, struct rusage *, rusage)
 safe_syscall3(int, execve, const char *, filename, char **, argv, char **, 
envp)
 #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
-defined(TARGET_NR_pselect6)
+defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
 safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, 
\
   fd_set *, exceptfds, struct timespec *, timeout, void *, sig)
 #endif
-#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_poll)
+#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_ppoll_time64)
 safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
   struct timespec *, tsp, const sigset_t *, sigmask,
   size_t, sigsetsize)
@@ -984,7 +984,7 @@ abi_long do_brk(abi_ulong new_brk)
 }
 
 #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
-defined(TARGET_NR_pselect6)
+defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
 static inline abi_long copy_from_user_fdset(fd_set *fds,
 abi_ulong target_fds_addr,
 int n)
@@ -1252,7 +1252,8 @@ static inline abi_long target_to_host_timespec(struct 
timespec *host_ts,
 }
 #endif
 
-#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64)
+#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \
+defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64)
 static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
  abi_ulong target_addr)
 {
@@ -9043,8 +9044,13 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #endif
 return ret;
 #endif
+#if defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
 #ifdef TARGET_NR_pselect6
 case TARGET_NR_pselect6:
+#endif
+#ifdef TARGET_NR_pselect6_time64
+case TARGET_NR_pselect6_time64:
+#endif
 {
 abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
 fd_set rfds, wfds, efds;
@@ -9088,8 +9094,21 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
  * use the do_select() helper ...
  */
 if (ts_addr) {
-if (target_to_host_timespec(&ts, ts_addr)) {
-return -TARGET_EFAULT;
+switch (num) {
+#ifdef TARGET_NR_pselect6
+case TARGET_NR_pselect6:
+if (target_to_host_timespec(&ts, ts_addr)) {
+return -TARGET_EFAULT;
+}
+break;
+#endif
+#ifdef TARGET_NR_pselect6_time64
+case TARGET_NR_pselect6_time64:
+if (target_to_host_timespec64(&ts, ts_addr)) {
+return -TARGET_EFAULT;
+}
+break;
+#endif
 }
 ts_ptr = &ts;
 } else {
@@ -9140,8 +9159,22 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))

[PATCH] linux-user: Fix 'semop()' and 'semtimedop()' implementation

2020-08-12 Thread Filip Bozuta
The implementations of syscalls 'semop()' and 'semtimedop()' in
file 'syscall.c' use function 'target_to_host_sembuf()' to convert
values of 'struct sembuf' from host to target. However, before this
conversion it should be check whether the number of semaphore operations
'nsops' is not bigger than maximum allowed semaphor operations per
syscall: 'SEMOPM'. In these cases, errno 'E2BIG' ("Arg list too long")
should be set. But the implementation will set errno 'EFAULT' ("Bad address")
in this case since the conversion from target to host fails.

This was confirmed with the LTP test for 'semop()' ('ipc/semop/semop02') in
test case where 'nsops' is greater than SEMOPM with unaproppriate errno EFAULT:

semop02.c:130: FAIL: semop failed unexpectedly; expected: E2BIG: EFAULT (14)

This patch changes this by adding a check whether 'nsops' is bigger than
'SEMOPM' before the conversion function 'target_to_host_sembuf()' is called.
After the changes from this patch, the test works fine along with the other
LTP testcases for 'semop()'):

semop02.c:126: PASS: semop failed as expected: E2BIG (7)

Implementation notes:

A target value ('TARGET_SEMOPM') was added for 'SEMOPM' as to be sure
in case the value is not available for some targets.

Signed-off-by: Filip Bozuta 
---
 linux-user/syscall.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1211e759c2..4743a5bef2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3899,6 +3899,8 @@ static inline abi_long target_to_host_sembuf(struct 
sembuf *host_sembuf,
   (__nsops), 0, (__sops), (__timeout)
 #endif
 
+#define TARGET_SEMOPM 500
+
 static inline abi_long do_semtimedop(int semid,
  abi_long ptr,
  unsigned nsops,
@@ -3915,8 +3917,13 @@ static inline abi_long do_semtimedop(int semid,
 }
 }
 
-if (target_to_host_sembuf(sops, ptr, nsops))
+if (nsops > TARGET_SEMOPM) {
+return -TARGET_E2BIG;
+}
+
+if (target_to_host_sembuf(sops, ptr, nsops)) {
 return -TARGET_EFAULT;
+}
 
 ret = -TARGET_ENOSYS;
 #ifdef __NR_semtimedop
-- 
2.25.1




[PATCH 0/2] linux-user: Adding support for a group of 4 time64 syscalls

2020-08-12 Thread Filip Bozuta
This two patch series introduces functionality for following
Year 2038 safe syscalls:

--Introduced in first patch--
*ppoll_time64()
*pselect6_time64()

--Introduced in second patch--
*utimensat_time64()
*semtimedop_time64()

Testing notes:

   The implementations of these time64 syscalls was tested
   using tests from the LTP test suite which was built inside
   a chroot.

Filip Bozuta (2):
  linux-user: Add support for ppoll_time64() and pselect6_time64()
  linux-user: Add support for utimensat_time64() and semtimedop_time64()

 linux-user/syscall.c | 154 ---
 1 file changed, 131 insertions(+), 23 deletions(-)

-- 
2.25.1




[PATCH 1/3] linux-user: Add strace support for printing arguments of truncate()/ftruncate() and getsid()

2020-06-26 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* truncate, ftruncate - truncate a file to a specified length

int truncate(const char *path, off_t length)
int ftruncate(int fd, off_t length)
man page: https://man7.org/linux/man-pages/man2/truncate.2.html

* getsid - get session ID

pid_t getsid(pid_t pid)
man page: https://man7.org/linux/man-pages/man2/getsid.2.html

Implementation notes:

Syscalls truncate/truncate64 takes string as argument type and thus a
separate print function "print_truncate/print_truncate64" is stated in
file "strace.list". This function is defined and implemented in "strace.c"
by using an existing function used to print string arguments: 
"print_string()".
The other syscalls have only primitive argument types, so the rest of the
implementation was handled by stating an appropriate printing format in file
    "strace.list".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 14 ++
 linux-user/strace.list | 10 +-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6044c66954..dccfbc46e9 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1925,6 +1925,20 @@ print_lseek(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_truncate
+static void
+print_truncate(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
+print_syscall_epilogue(name);
+}
+#define print_truncate64 print_truncate
+#endif
+
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 10e3e4a814..3b77b22daf 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -258,10 +258,10 @@
 { TARGET_NR_ftime, "ftime" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_ftruncate
-{ TARGET_NR_ftruncate, "ftruncate" , NULL, NULL, NULL },
+{ TARGET_NR_ftruncate, "ftruncate" , "%s(%d," TARGET_ABI_FMT_ld ")", NULL, 
NULL },
 #endif
 #ifdef TARGET_NR_ftruncate64
-{ TARGET_NR_ftruncate64, "ftruncate64" , NULL, NULL, NULL },
+{ TARGET_NR_ftruncate64, "ftruncate64" , "%s(%d," TARGET_ABI_FMT_ld ")", NULL, 
NULL },
 #endif
 #ifdef TARGET_NR_futex
 { TARGET_NR_futex, "futex" , NULL, print_futex, NULL },
@@ -372,7 +372,7 @@
 { TARGET_NR_getrusage, "getrusage" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_getsid
-{ TARGET_NR_getsid, "getsid" , NULL, NULL, NULL },
+{ TARGET_NR_getsid, "getsid" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getsockname
 { TARGET_NR_getsockname, "getsockname" , NULL, NULL, NULL },
@@ -1534,10 +1534,10 @@
 { TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL },
 #endif
 #ifdef TARGET_NR_truncate
-{ TARGET_NR_truncate, "truncate" , NULL, NULL, NULL },
+{ TARGET_NR_truncate, "truncate" , NULL, print_truncate, NULL },
 #endif
 #ifdef TARGET_NR_truncate64
-{ TARGET_NR_truncate64, "truncate64" , NULL, NULL, NULL },
+{ TARGET_NR_truncate64, "truncate64" , NULL, print_truncate64, NULL },
 #endif
 #ifdef TARGET_NR_tuxcall
 { TARGET_NR_tuxcall, "tuxcall" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH 3/3] linux-user: Add strace support for printing arguments of some clock and time functions

2020-06-26 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* clock_getres, clock_gettime, clock_settime - clock and time functions

int clock_getres(clockid_t clockid, struct timespec *res)
int clock_gettime(clockid_t clockid, struct timespec *tp)
int clock_settime(clockid_t clockid, const struct timespec *tp)
man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html

* gettimeofday - get time

int gettimeofday(struct timeval *tv, struct timezone *tz)
man page: https://man7.org/linux/man-pages/man2/gettimeofday.2.html

* getitimer, setitimer - get or set value of an interval timer

int getitimer(int which, struct itimerval *curr_value)
int setitimer(int which, const struct itimerval *new_value,
  struct itimerval *old_value)
man page: https://man7.org/linux/man-pages/man2/getitimer.2.html

Implementation notes:

All of the syscalls have some structue types as argument types and thus
a separate printing function was stated in file "strace.list" for each
of them. All of these functions use existing functions for their
appropriate structure types ("print_timeval()" and "print_timezone()").
Functions "print_timespec()" and "print_itimerval()" were added in this
patch so that they can be used to print types "struct timespec" and
"struct itimerval" used by some of the syscalls. Function 
"print_itimerval()"
uses the existing function "print_timeval()" to print fields of the
structure "struct itimerval" that are of type "struct timeval".
Also, the existing function "print_timeval()" was changed a little so
that it prints the field names beside the values. Syscalls "clock_getres()"
and "clocK_gettime()" have the same number and types of arguments and
thus their print functions "print_clock_getres" and "print_clock_gettime"
shate a common definition in file "strace.c".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 186 -
 linux-user/strace.list |  16 ++--
 2 files changed, 194 insertions(+), 8 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 1fc4404310..414748d0fa 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -64,7 +64,9 @@ UNUSED static void print_string(abi_long, int);
 UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
+UNUSED static void print_timespec(abi_ulong, int);
 UNUSED static void print_timezone(abi_ulong, int);
+UNUSED static void print_itimerval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
 UNUSED static void print_signal(abi_ulong, int);
 UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
@@ -833,6 +835,65 @@ print_syscall_ret_adjtimex(const struct syscallname *name, 
abi_long ret,
 }
 #endif
 
+#if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
+static void
+print_syscall_ret_clock_gettime(const struct syscallname *name, abi_long ret,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_err(ret);
+
+if (ret >= 0) {
+qemu_log(TARGET_ABI_FMT_ld, ret);
+qemu_log(" (");
+print_timespec(arg1, 1);
+qemu_log(")");
+}
+
+qemu_log("\n");
+}
+#define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
+#endif
+
+#ifdef TARGET_NR_gettimeofday
+static void
+print_syscall_ret_gettimeofday(const struct syscallname *name, abi_long ret,
+   abi_long arg0, abi_long arg1, abi_long arg2,
+   abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_err(ret);
+
+if (ret >= 0) {
+qemu_log(TARGET_ABI_FMT_ld, ret);
+qemu_log(" (");
+print_timeval(arg0, 0);
+print_timezone(arg1, 1);
+qemu_log(")");
+}
+
+qemu_log("\n");
+}
+#endif
+
+#ifdef TARGET_NR_getitimer
+static void
+print_syscall_ret_getitimer(const struct syscallname *name, abi_long ret,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_err(ret);
+
+if (ret >= 0) {
+qemu_log(TARGET_ABI_FMT_ld, ret);
+qemu_log(" (");
+print_itimerval(arg1, 1);
+qemu_log(")");
+}
+
+qemu_log("\n");
+}
+#endif
+
 #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
  || define

[PATCH 2/3] linux-user: Add strace support for printing arguments of syscalls used to lock and unlock memory

2020-06-26 Thread Filip Bozuta
This patch implements strace argument printing functionality for following 
syscalls:

* mlock, munlock, mlockall, munlockall - lock and unlock memory

   int mlock(const void *addr, size_t len)
   int munlock(const void *addr, size_t len)
   int mlockall(int flags)
   int munlockall(void)
   man page: https://man7.org/linux/man-pages/man2/mlock.2.html

Implementation notes:

Syscall mlockall() takes an argument that is composed of predefined values
which represent flags that determine the type of locking operation that is
to be performed. For that reason, a printing function "print_mlockall" was
stated in file "strace.list". This printing function uses an already 
existing
function "print_flags()" to print the "flags" argument.  These flags are 
stated
inside an array "mlockall_flags" that contains values of type "struct 
flags".
These values are instantiated using an existing macro "FLAG_GENERIC()".
The other syscalls have only primitive argument types, so the
rest of the implementation was handled by stating an appropriate
printing format in file "strace.list". Syscall mlock2() is not implemented 
in
"syscall.c" and thus it's argument printing is not implemented in this 
patch.

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 21 +
 linux-user/strace.list |  8 
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index dccfbc46e9..1fc4404310 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1161,6 +1161,15 @@ UNUSED static struct flags falloc_flags[] = {
 #endif
 };
 
+UNUSED static struct flags mlockall_flags[] = {
+FLAG_GENERIC(MCL_CURRENT),
+FLAG_GENERIC(MCL_FUTURE),
+#ifdef MCL_ONFAULT
+FLAG_GENERIC(MCL_ONFAULT),
+#endif
+FLAG_END,
+};
+
 /*
  * print_xxx utility functions.  These are used to print syscall
  * parameters in certain format.  All of these have parameter
@@ -1939,6 +1948,18 @@ print_truncate(const struct syscallname *name,
 #define print_truncate64 print_truncate
 #endif
 
+#ifdef TARGET_NR_mlockall
+static void
+print_mlockall(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_flags(mlockall_flags, arg0, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 3b77b22daf..822b6be49c 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -567,13 +567,13 @@
 { TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL },
 #endif
 #ifdef TARGET_NR_mlock
-{ TARGET_NR_mlock, "mlock" , NULL, NULL, NULL },
+{ TARGET_NR_mlock, "mlock" , "%s(%p," TARGET_FMT_lu ")", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mlock2
 { TARGET_NR_mlock2, "mlock2" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mlockall
-{ TARGET_NR_mlockall, "mlockall" , NULL, NULL, NULL },
+{ TARGET_NR_mlockall, "mlockall" , NULL, print_mlockall, NULL },
 #endif
 #ifdef TARGET_NR_mmap
 { TARGET_NR_mmap, "mmap" , NULL, print_mmap, print_syscall_ret_addr },
@@ -636,10 +636,10 @@
 { TARGET_NR_multiplexer, "multiplexer" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_munlock
-{ TARGET_NR_munlock, "munlock" , NULL, NULL, NULL },
+{ TARGET_NR_munlock, "munlock" , "%s(%p," TARGET_FMT_lu ")", NULL, NULL },
 #endif
 #ifdef TARGET_NR_munlockall
-{ TARGET_NR_munlockall, "munlockall" , NULL, NULL, NULL },
+{ TARGET_NR_munlockall, "munlockall" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_munmap
 { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
-- 
2.17.1




[PATCH 0/3] Add strace support for printing arguments for a group of selected syscalls

2020-06-26 Thread Filip Bozuta
This series covers strace support for following syscalls:

   *truncate() *munlock()  *clock_gettimeofday()
   *ftruncate()*munlockall()   *clock_getitimer()
   *getsid()   *clock_getres() *clock_setitimer()
   *mlock()*clock_gettime()
   *mlockall() *clock_settime()


Filip Bozuta (3):
  linux-user: Add strace support for printing arguments of
truncate()/ftruncate() and getsid()
  linux-user: Add strace support for printing arguments of syscalls used
to lock and unlock memory
  linux-user: Add strace support for printing arguments of some clock
and time functions

 linux-user/strace.c| 221 -
 linux-user/strace.list |  34 ---
 2 files changed, 238 insertions(+), 17 deletions(-)

-- 
2.17.1




[PATCH] linux-user: Fix "print_fdset()" in "strace.c" to not print ", " after last value

2020-07-02 Thread Filip Bozuta
Function "print_fdset()" in "strace.c" is used to print the file descriptor
values in "print__newselect()" which prints arguments of syscall _newselect().
Until changes from this patch, this function was printing "," even after the
last value of the fd_set argument. This was changed in this patch by removing
this unnecessary "," after the last fd value and thus improving the estetics of
the _newselect() "-strace" print.

Implementation notes:

   The printing fix was made possible by using an existing function 
"get_comma()"
   which returns a "," or an empty string "" based on its argument (0 for "," 
and
   other for "").
---
 linux-user/strace.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6044c66954..23ca5d88c8 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -541,6 +541,7 @@ static void
 print_fdset(int n, abi_ulong target_fds_addr)
 {
 int i;
+int first = 1;
 
 qemu_log("[");
 if( target_fds_addr ) {
@@ -555,9 +556,12 @@ print_fdset(int n, abi_ulong target_fds_addr)
 return;
 
 for (i=n; i>=0; i--) {
-if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & 
(TARGET_ABI_BITS - 1))) & 1)
-qemu_log("%d,", i);
+if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >>
+(i & (TARGET_ABI_BITS - 1))) & 1) {
+qemu_log("%s%d", get_comma(first), i);
+first = 0;
 }
+}
 unlock_user(target_fds, target_fds_addr, 0);
 }
 qemu_log("]");
-- 
2.17.1




[PATCH 2/2] tests/tcg/multiarch: Add tests for implemented alsa sound timer ioctls

2020-01-20 Thread Filip Bozuta
This patch adds tests for following 14 implemented alsa timer ioctls:

* SNDRV_TIMER_IOCTL_PVERSION* SNDRV_TIMER_IOCTL_INFO
* SNDRV_TIMER_IOCTL_NEXT_DEVICE * SNDRV_TIMER_IOCTL_PARAMS
* SNDRV_TIMER_IOCTL_TREAD   * SNDRV_TIMER_IOCTL_STATUS
* SNDRV_TIMER_IOCTL_GINFO   * SNDRV_TIMER_IOCTL_START
* SNDRV_TIMER_IOCTL_GPARAMS * SNDRV_TIMER_IOCTL_STOP
* SNDRV_TIMER_IOCTL_GSTATUS * SNDRV_TIMER_IOCTL_CONTINUE
* SNDRV_TIMER_IOCTL_SELECT  * SNDRV_TIMER_IOCTL_PAUSE

Names and descriptions of these ioctls can be found in patches that
implement them.

Test folder for these ioctl tests is located at
"tests/tcg/multiarch/alsa-timer-ioctl-tests/"

Tests for individual ioctls are located in separate folders. These
folders are arranged by the same way these ioctls are implemented
in patches. These test files are simple programs that use these
ioctls to set/read some alsa timer features or to run some simple
alsa timer instructions.

Besides tests for individual ioctls, a global alsa ioctl test was
added at "tests/tcg/multiarch/rtc-ioctl-tests/GlobalTest/timer.c".
This test file was downloaded from a git repository that contains
alsa ioctl test suite. This repository is located at
"https://github.com/takaswie/alsa-ioctl-test";.
It is used to test all of the alsa timer ioctls at once by running
a test macro defined in that file. The file was modified a little
bit by adding an output line that shows which test passed and at
which test the program aborts. It was also modified so that it
doesn't have styling problems detected by 'scripts/checkpatch.pl'.

Signed-off-by: Filip Bozuta 
---
 .../Disable/disableEnhancedRead.c  |  29 
 .../EnhancedRead-test/Enable/enableEnhancedRead.c  |  29 
 .../alsa-timer-ioctl-tests/GlobalTest/timer.c  | 158 +
 .../Instructions-tests/Continue/continue.c |  39 +
 .../Instructions-tests/Pause/pause.c   |  39 +
 .../Instructions-tests/Start/start.c   |  39 +
 .../Instructions-tests/Stop/stop.c |  39 +
 .../SelectedParameters-tests/Info/info.c   |  46 ++
 .../SelectedParameters-tests/Params/params.c   |  44 ++
 .../SelectedParameters-tests/Status/status.c   |  45 ++
 .../alsa-timer-ioctl-tests/Selecting-test/select.c |  34 +
 .../SpecifiedParameters-tests/Ginfo/ginfo.c|  43 ++
 .../SpecifiedParameters-tests/Gparams/gparams.c|  37 +
 .../SpecifiedParameters-tests/Gstatus/gstatus.c|  36 +
 .../Version-id-tests/NextDevice/nextDevice.c   |  34 +
 .../Version-id-tests/Pversion/pversion.c   |  30 
 16 files changed, 721 insertions(+)
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Disable/disableEnhancedRead.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Enable/enableEnhancedRead.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/GlobalTest/timer.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Continue/continue.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Pause/pause.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Start/start.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Stop/stop.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Info/info.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Params/params.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Status/status.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Selecting-test/select.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Ginfo/ginfo.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Gparams/gparams.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Gstatus/gstatus.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Version-id-tests/NextDevice/nextDevice.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Version-id-tests/Pversion/pversion.c

diff --git 
a/tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Disable/disableEnhancedRead.c
 
b/tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Disable/disableEnhancedRead.c
new file mode 100644
index 000..2f930b6
--- /dev/null
+++ 
b/tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Disable/disableEnhancedRead.c
@@ -0,0 +1,29 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ERROR -1
+
+int main()
+{
+int fd = open("/dev/snd/timer", O_RDWR);
+
+if (fd == ERROR) {
+perror("open");
+  

[PATCH 1/2] tests/tcg/multiarch: Add tests for implemented rtc ioctls

2020-01-20 Thread Filip Bozuta
This patch adds tests for following 22 implemented rtc ioctls:

* RTC_AIE_ON * RTC_ALM_SET  * RTC_WKALM_SET
* RTC_AIE_OFF* RTC_ALM_READ * RTC_WKALM_RD
* RTC_UIE_ON * RTC_RD_TIME  * RTC_PLL_GET
* RTC_UIE_OFF* RTC_SET_TIME * RTC_PLL_SET
* RTC_PIE_ON * RTC_IRQP_READ* RTC_VL_READ
* RTC_PIE_OFF* RTC_IRQP_SET * RTC_VL_CLR
* RTC_WIE_ON * RTC_EPOCH_READ
* RTC_WIE_OFF* RTC_EPOCH_SET

Names and descriptions of these ioctls can be found in patches that
implement them.

Test folder for these ioctl tests is located at
"tests/tcg/multiarch/rtc-ioctl-tests/"

Tests for individual ioctls are located in separate folders. These
folders are arranged by the same way these ioctls are implemented
in patches. These test files are simple programs that use these ioctls
to set/read or turn on/off some rtc features.

Besides tests for individual ioctls, a global rtc ioctl test was
added at "tests/tcg/multiarch/rtc-ioctl-tests/GlobalTest/rtc-test.c"
This test file was downloaded from linux kernel and is located at
"linux/drivers/rtc/rtc-test.c".
This file was modified a little bit so that it doesn't have styling
problems identified by "scripts/checkpatch.pl".
It is used to further test functionalities of some rtc ioctls by
running rtc clock at different frequencies.

Signed-off-by: Filip Bozuta 
---
 .../Alarm-time-test/ReadAlarm/getAlarm.c   |  33 +++
 .../Alarm-time-test/ReadTime/getTime.c |  35 
 .../Alarm-time-test/SetAlarm/setAlarm.c|  31 +++
 .../Alarm-time-test/SetTime/setTime.c  |  33 +++
 .../AlarmInterrupt/Disable/disableAlarmInterrupt.c |  29 +++
 .../AlarmInterrupt/Enable/enableAlarmInterrupt.c   |  29 +++
 .../Disable/disablePeriodicInterrupt.c |  30 +++
 .../Enable/enablePeriodicInterrupt.c   |  29 +++
 .../Disable/disableUpdateInterrupt.c   |  29 +++
 .../UpdateInterrupt/Enable/enableUpdateInterrupt.c |  29 +++
 .../Disable/disableWatchdogInterrupt.c |  30 +++
 .../Enable/enableWatchdogInterrupt.c   |  31 +++
 .../rtc-ioctl-tests/GlobalTest/rtc-test.c  | 227 +
 .../ReadEpoch/getEpoch.c   |  32 +++
 .../ReadPeriodicInterrupt/getPeriodicInterrupt.c   |  31 +++
 .../SetEpoch/setEpoch.c|  32 +++
 .../SetPeriodicInterrupt/setPeriodicInterrupt.c|  31 +++
 .../ReadPllCorrection/getPllCorrection.c   |  35 
 .../SetPllCorrection/setPllCorrection.c|  32 +++
 .../ClearVoltageLow/clearVoltageLow.c  |  32 +++
 .../ReadVoltageLow/getVoltageLow.c |  32 +++
 .../ReadWakeupAlarm/getWakeupAlarm.c   |  36 
 .../SetWakeupAlarm/setWakeupAlarm.c|  34 +++
 23 files changed, 922 insertions(+)
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Alarm-time-test/ReadAlarm/getAlarm.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Alarm-time-test/ReadTime/getTime.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Alarm-time-test/SetAlarm/setAlarm.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Alarm-time-test/SetTime/setTime.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/AlarmInterrupt/Disable/disableAlarmInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/AlarmInterrupt/Enable/enableAlarmInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/PeriodicInterrupt/Disable/disablePeriodicInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/PeriodicInterrupt/Enable/enablePeriodicInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/UpdateInterrupt/Disable/disableUpdateInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/UpdateInterrupt/Enable/enableUpdateInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/WatchdogInterrupt/Disable/disableWatchdogInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Features-test/WatchdogInterrupt/Enable/enableWatchdogInterrupt.c
 create mode 100644 tests/tcg/multiarch/rtc-ioctl-tests/GlobalTest/rtc-test.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Periodic-interrupt-epoch-test/ReadEpoch/getEpoch.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Periodic-interrupt-epoch-test/ReadPeriodicInterrupt/getPeriodicInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Periodic-interrupt-epoch-test/SetEpoch/setEpoch.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Periodic-interrupt-epoch-test/SetPeriodicInterrupt/setPeriodicInterrupt.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Pll-correction-test/ReadPllCorrection/getPllCorrection.c
 create mode 100644 
tests/tcg/multiarch/rtc-ioctl-tests/Pll-correction-test/SetPllCorrection/setPllCorrection.c

[PATCH 0/2] tests/tcg/multiarch: Add tests for implemented real

2020-01-20 Thread Filip Bozuta
This series covers tests for implemented rtc and alsa timer ioctls. The names
of ioctls that are covered by these tests can be found in patch descriptions.
The functionalities of each ioctl that is tested can be found in patches that
implement them.

Some of the features that are accessible through these ioctls are not supported
on all test host pc's. These tests were written so that the implemented ioctls
can be properly tested on pc's that support all of their features.

Both rtc and alsa timer test folders contain separate programs that test 
functionalities
of individual ioctls and one global program that tests multiple ioctls at once.
Individual tests were written manually while the global tests were obtained 
remotely and
modified so that they fit the QEMU coding style.

Filip Bozuta (2):
  tests/tcg/multiarch: Add tests for implemented rtc ioctls
  tests/tcg/multiarch: Add tests for implemented alsa sound timer ioctls

 .../Disable/disableEnhancedRead.c  |  29 +++
 .../EnhancedRead-test/Enable/enableEnhancedRead.c  |  29 +++
 .../alsa-timer-ioctl-tests/GlobalTest/timer.c  | 158 ++
 .../Instructions-tests/Continue/continue.c |  39 
 .../Instructions-tests/Pause/pause.c   |  39 
 .../Instructions-tests/Start/start.c   |  39 
 .../Instructions-tests/Stop/stop.c |  39 
 .../SelectedParameters-tests/Info/info.c   |  46 +
 .../SelectedParameters-tests/Params/params.c   |  44 
 .../SelectedParameters-tests/Status/status.c   |  45 
 .../alsa-timer-ioctl-tests/Selecting-test/select.c |  34 +++
 .../SpecifiedParameters-tests/Ginfo/ginfo.c|  43 
 .../SpecifiedParameters-tests/Gparams/gparams.c|  37 
 .../SpecifiedParameters-tests/Gstatus/gstatus.c|  36 
 .../Version-id-tests/NextDevice/nextDevice.c   |  34 +++
 .../Version-id-tests/Pversion/pversion.c   |  30 +++
 .../Alarm-time-test/ReadAlarm/getAlarm.c   |  33 +++
 .../Alarm-time-test/ReadTime/getTime.c |  35 
 .../Alarm-time-test/SetAlarm/setAlarm.c|  31 +++
 .../Alarm-time-test/SetTime/setTime.c  |  33 +++
 .../AlarmInterrupt/Disable/disableAlarmInterrupt.c |  29 +++
 .../AlarmInterrupt/Enable/enableAlarmInterrupt.c   |  29 +++
 .../Disable/disablePeriodicInterrupt.c |  30 +++
 .../Enable/enablePeriodicInterrupt.c   |  29 +++
 .../Disable/disableUpdateInterrupt.c   |  29 +++
 .../UpdateInterrupt/Enable/enableUpdateInterrupt.c |  29 +++
 .../Disable/disableWatchdogInterrupt.c |  30 +++
 .../Enable/enableWatchdogInterrupt.c   |  31 +++
 .../rtc-ioctl-tests/GlobalTest/rtc-test.c  | 227 +
 .../ReadEpoch/getEpoch.c   |  32 +++
 .../ReadPeriodicInterrupt/getPeriodicInterrupt.c   |  31 +++
 .../SetEpoch/setEpoch.c|  32 +++
 .../SetPeriodicInterrupt/setPeriodicInterrupt.c|  31 +++
 .../ReadPllCorrection/getPllCorrection.c   |  35 
 .../SetPllCorrection/setPllCorrection.c|  32 +++
 .../ClearVoltageLow/clearVoltageLow.c  |  32 +++
 .../ReadVoltageLow/getVoltageLow.c |  32 +++
 .../ReadWakeupAlarm/getWakeupAlarm.c   |  36 
 .../SetWakeupAlarm/setWakeupAlarm.c|  34 +++
 39 files changed, 1643 insertions(+)
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Disable/disableEnhancedRead.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/EnhancedRead-test/Enable/enableEnhancedRead.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/GlobalTest/timer.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Continue/continue.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Pause/pause.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Start/start.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Instructions-tests/Stop/stop.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Info/info.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Params/params.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SelectedParameters-tests/Status/status.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Selecting-test/select.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Ginfo/ginfo.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Gparams/gparams.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/SpecifiedParameters-tests/Gstatus/gstatus.c
 create mode 100644 
tests/tcg/multiarch/alsa-timer-ioctl-tests/Version-id-tests/NextDevice/nextDevice.c
 create mode 100644 

[PATCH for 5.0 2/6] linux-user: Add set and read for rtc time and alarm using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..ff1cdd2 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..2298547 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH for 5.0 4/6] linux-user: Add get and set for rtc wakeup alarm using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7d76a9f..5830315 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e69071f..3a0eb6b 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH for 5.0 3/6] linux-user: Add read and set for rtc periodic interrupt and epoch using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index ff1cdd2..7d76a9f 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 2298547..e69071f 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH for 5.0 6/6] linux-user: Add rtc voltage low detector read and clear using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index eea65e1..330e502 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, TYPE_INT)
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 367e9bd..6ad827b 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH for 5.0 0/6] linux-user: Add support for real time clock ioctls

2019-11-13 Thread Filip Bozuta
Add ioctls for all rtc features that are currently supported in linux kernell.

Filip Bozuta (6):
  linux-user: Add support for enabling/disabling rtc features using
ioctls
  linux-user: Add set and read for rtc time and alarm using ioctls
  linux-user: Add read and set for rtc periodic interrupt and epoch
using ioctls
  linux-user: Add get and set for rtc wakeup alarm using ioctls
  linux-user: Add get and set for rtc pll correction using ioctls
  linux-user: Add rtc voltage low detector read and clear using ioctls

 linux-user/ioctls.h| 23 +++
 linux-user/syscall.c   |  1 +
 linux-user/syscall_defs.h  | 36 
 linux-user/syscall_types.h | 25 +
 4 files changed, 85 insertions(+)

-- 
2.7.4




[PATCH for 5.0 5/6] linux-user: Add get and set for rtc pll correction using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 5830315..eea65e1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 3a0eb6b..367e9bd 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..baf43ee 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_ULONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH for 5.0 1/6] linux-user: Add support for enabling/disabling rtc features using ioctls

2019-11-13 Thread Filip Bozuta
Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH v2 for 5.0 4/6] linux-user: Add support for get/set RTC wakeup alarm using ioctls

2019-11-14 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Get/Set wakeup alarm

Some RTCs support a more powerful alarm interface, using these
ioctls to read or write the RTC's alarm time (respectively)
with this structure:

struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};

The enabled flag is used to enable or disable the alarm inter‐
rupt, or to read its current status; when using these calls,
RTC_AIE_ON and RTC_AIE_OFF are not used.  The pending flag is
used by RTC_WKALM_RD to report a pending interrupt (so it's
mostly useless on Linux, except when talking to the RTC man‐
aged by EFI firmware).  The time field is as used with
RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
and tm_year fields are also valid.  A pointer to this struc‐
ture should be passed as the third ioctl's argument.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_wkalrm
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are either of type 'unsigned char'
or 'struct rtc_time' (that was covered in one of previous
patches), the rest of the implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index fa2fe7f..e4d89c2 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v2 for 5.0 3/6] linux-user: Add support for read/set RTC periodic interrupt and epoch using ioctls

2019-11-14 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Read/Set IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts.  The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests.  The third ioctl's argument is an
unsigned long * or an unsigned long, respectively.  The value
is the frequency in interrupts per second.  The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192.  Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq.  (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Read/Set epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number.  In
both cases, the number is interpreted relative to this RTC's
Epoch.  The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year.  With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively.  The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch.  To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..fa2fe7f 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v2 for 5.0 0/6] linux-user: Add support for real time clock ioctls

2019-11-14 Thread Filip Bozuta
Add ioctls for all RTC features that are currently supported in linux kernel.

This series covers following iocts:

* RTC_AIE_ON
* RTC_AIE_OFF
* RTC_UIE_ON
* RTC_UIE_OFF
* RTC_PIE_ON
* RTC_PIE_OFF
* RTC_WIE_ON
* RTC_WIE_OFF
* RTC_ALM_SET
* RTC_ALM_READ
* RTC_RD_TIME
* RTC_SET_TIME
* RTC_IRQP_READ
* RTC_IRQP_SET
* RTC_EPOCH_READ
* RTC_EPOCH_SET
* RTC_WKALM_SET
* RTC_WKALM_RD
* RTC_PLL_GET
* RTC_PLL_SET
* RTC_VL_READ
* RTC_VL_CLR

The functionalities of individual ioctls were described in this series
patch commit messages.

Testing method:

Mini test programs were written for each ioctl. Those programs were
compiled (sometimes using cross-compilers) for the following 
architectures:

* Intel 64-bit (little endian)
* Power pc 32-bit (big endian)
* Power pc 64-bit (big endian)

The corresponding native programs were executed without using 
QEMU on following hosts:

* Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
*.7447A, (ppc32 host)

All applicable compiled programs were in turn executed through QEMU
and the results obtained were the same ones gotten for native
execution.

Example of a test program:

For ioctl RTC_RD_TIME we have used the following test program:

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ERROR -1

int main()
{

int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);

if(fd == ERROR)
{
perror("open");
return -1;
}

struct rtc_time cur_time;

if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
{
perror("ioctl");
return -1;
}

printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: 
%d,",
cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour, 
cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);

return 0;
}



Filip Bozuta (6):
  linux-user: Add support for enable/disable RTC features using ioctls
  linux-user: Add support for read/set RTC time and alarm using ioctls
  linux-user: Add support for read/set RTC periodic interrupt and epoch
using ioctls
  linux-user: Add support for get/set RTC wakeup alarm using ioctls
  linux-user: Add support for get/set RTC PLL correction using ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
ioctls

 linux-user/ioctls.h| 23 +++
 linux-user/syscall.c   |  1 +
 linux-user/syscall_defs.h  | 36 
 linux-user/syscall_types.h | 25 +
 4 files changed, 85 insertions(+)

-- 
2.7.4




[PATCH v2 for 5.0 2/6] linux-user: Add support for read/set RTC time and alarm using ioctls

2019-11-14 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_RD_TIME - Read RTC time

Returns this RTC's time in the following structure:

struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};

The fields in this structure have the same meaning and ranges
as for the tm structure described in gmtime man page.  A pointer
to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Set RTC time

Sets this RTC's time to the time specified by the rtc_time
structure pointed to by the third ioctl's argument.  To set
the RTC's time the process must be privileged (i.e., have the
CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Read/Set alarm time

Read and set the alarm time, for RTCs that support alarms.
The alarm interrupt must be separately enabled or disabled
using the RTC_AIE_ON, RTC_AIE_OFF requests.  The third
ioctl's argument is a pointer to an rtc_time structure.  Only
the tm_sec, tm_min, and tm_hour fields of this structure are
used.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_time
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are of type 'int', the rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v2 for 5.0 6/6] linux-user: Add support for read/clear RTC voltage low detector using ioctls

2019-11-14 Thread Filip Bozuta
RTC_VL_READ - Read voltage low detection information

Read the voltage low for RTCs that support voltage low.
The third ioctl's' argument points to an int in which
the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

Clear the information about voltage low for RTCs that
support voltage low. The third ioctl(2) argument is
ignored.

Implementation notes:

Since one ioctl has a pointer to 'int' as its third agrument,
and another ioctl has NULL as its third argument, their
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index a8dd235..371c25e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v2 for 5.0 1/6] linux-user: Add support for enable/disable RTC features using ioctls

2019-11-14 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enable on/off

Enable or disable the alarm interrupt, for RTCs that support
alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enable on/off

Enable or disable the interrupt on every clock update, for
RTCs that support this once-per-second interrupt.  The third
ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enable on/off

Enable or disable the periodic interrupt, for RTCs that sup‐
port these periodic interrupts.  The third ioctl's argument
is ignored.  Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can enable the periodic interrupt
if the frequency is currently set above the value specified in
/proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enable on/off

Enable or disable the Watchdog interrupt, for RTCs that sup-
port this Watchdog interrupt. The third ioctl's argument is
ignored.

Implementation notes:

Since all of involved ioctls have NULL as their third argument,
their implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls.  This needs to be
done only once in this series of commits.  Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH v2 for 5.0 5/6] linux-user: Add support for get/set RTC PLL correction using ioctls

2019-11-14 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_PLL_GET - Get PLL correction

Read the PLL correction for RTCs that support PLL. The PLL correction
is returned in the following structure:

struct rtc_pll_info {
int pll_ctrl;/* placeholder for fancier control */
int pll_value;   /* get/set correction value */
int pll_max; /* max +ve (faster) adjustment value */
int pll_min; /* max -ve (slower) adjustment value */
int pll_posmult; /* factor for +ve correction */
int pll_negmult; /* factor for -ve correction */
long pll_clock;  /* base PLL frequency */
};

A pointer to this structure should be passed as the third
ioctl's argument.

RTC_PLL_SET - Set PLL correction

Sets the PLL correction for RTCs that support PLL. The PLL correction
that is set is specified by the rtc_pll_info structure pointed to by
the third ioctl's' argument.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_pll_info
as their third argument. All elements of this structure are of
type 'int', except the last one that is of type 'long'. That is
the reason why a separate target structure (target_rtc_pll_info)
is defined in linux-user/syscall_defs. The rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index e4d89c2..a8dd235 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v3 for 5.0 0/6] linux-user: Add support for real time clock ioctls

2019-11-15 Thread Filip Bozuta
Add ioctls for all RTC features that are currently supported in linux kernel.

This series covers following 22 iocts:

* RTC_AIE_ON
* RTC_AIE_OFF
* RTC_UIE_ON
* RTC_UIE_OFF
* RTC_PIE_ON
* RTC_PIE_OFF
* RTC_WIE_ON
* RTC_WIE_OFF
* RTC_ALM_SET
* RTC_ALM_READ
* RTC_RD_TIME
* RTC_SET_TIME
* RTC_IRQP_READ
* RTC_IRQP_SET
* RTC_EPOCH_READ
* RTC_EPOCH_SET
* RTC_WKALM_SET
* RTC_WKALM_RD
* RTC_PLL_GET
* RTC_PLL_SET
* RTC_VL_READ
* RTC_VL_CLR

The functionalities of individual ioctls were described in this series
patch commit messages.

Testing method:

Mini test programs were written for each ioctl. Those programs were
compiled (sometimes using cross-compilers) for the following 
architectures:

* Intel 64-bit (little endian)
* Power pc 32-bit (big endian)
* Power pc 64-bit (big endian)

The corresponding native programs were executed without using 
QEMU on following hosts:

* Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
*.7447A, (ppc32 host)

All applicable compiled programs were in turn executed through QEMU
and the results obtained were the same ones gotten for native
execution.

Example of a test program:

For ioctl RTC_RD_TIME we have used the following test program:

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ERROR -1

int main()
{

int fd = open("/dev/rtc", O_RDWR | O_NONBLOCK);

if(fd == ERROR)
{
perror("open");
return -1;
}

struct rtc_time cur_time;

if(ioctl(fd, RTC_RD_TIME, &cur_time) < 0)
{
perror("ioctl");
return -1;
}

printf("Second: %d, Minute: %d, Hour: %d, Day: %d, Month: %d, Year: 
%d,",
cur_time.tm_sec, cur_time.tm_min, cur_time.tm_hour, 
cur_time.tm_mday, cur_time.tm_mon, cur_time.tm_year);

return 0;
}

Limitations of testing:

My test host (intel pc) has RTC that doesn't support all
RTC features that are accessible through ioctls. This
means that testing can't discover functionality errors
related to the third argument of ioctls that are used
for features that are not supported. For example,
running my test program for ioctl RTC_EPOCH_READ gives
the error output: inappropriate ioctl for device. As 
expected, i get the same output through QEMU which means
that this ioctl is recognized in QEMU but doesn't really
do anything beacuse it is not supported in my computer's
RTC.

Conclusion: Some RTC ioctls need to be tested on computers
that support their functionalities so that we can be sure
that they are really supported in QEMU. In absence of such
test hosts, we need to carefully check the specifications
of those ioctls manually and update implementations
accordingly.

v3:

* changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

* added description of each ioctl in patches
* wrote a more detailed cover letter with description of testing
* changed one instance of TYPE_INT to MK_PTR(TYPE_INT)

Filip Bozuta (6):
  linux-user: Add support for enable/disable RTC features using ioctls
  linux-user: Add support for read/set RTC time and alarm using ioctls
  linux-user: Add support for read/set RTC periodic interrupt and epoch
using ioctls
  linux-user: Add support for get/set RTC wakeup alarm using ioctls
  linux-user: Add support for get/set RTC PLL correction using ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
ioctls

 linux-user/ioctls.h| 23 +++
 linux-user/syscall.c   |  1 +
 linux-user/syscall_defs.h  | 36 
 linux-user/syscall_types.h | 25 +
 4 files changed, 85 insertions(+)

-- 
2.7.4




[PATCH v3 for 5.0 6/6] linux-user: Add support for read/clear RTC voltage low detector using ioctls

2019-11-15 Thread Filip Bozuta
RTC_VL_READ - Read voltage low detection information

Read the voltage low for RTCs that support voltage low.
The third ioctl's' argument points to an int in which
the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

Clear the information about voltage low for RTCs that
support voltage low. The third ioctl(2) argument is
ignored.

Implementation notes:

Since one ioctl has a pointer to 'int' as its third agrument,
and another ioctl has NULL as its third argument, their
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 0a4e3f1..1f1f3e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v3 for 5.0 5/6] linux-user: Add support for get/set RTC PLL correction using ioctls

2019-11-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_PLL_GET - Get PLL correction

Read the PLL correction for RTCs that support PLL. The PLL correction
is returned in the following structure:

struct rtc_pll_info {
int pll_ctrl;/* placeholder for fancier control */
int pll_value;   /* get/set correction value */
int pll_max; /* max +ve (faster) adjustment value */
int pll_min; /* max -ve (slower) adjustment value */
int pll_posmult; /* factor for +ve correction */
int pll_negmult; /* factor for -ve correction */
long pll_clock;  /* base PLL frequency */
};

A pointer to this structure should be passed as the third
ioctl's argument.

RTC_PLL_SET - Set PLL correction

Sets the PLL correction for RTCs that support PLL. The PLL correction
that is set is specified by the rtc_pll_info structure pointed to by
the third ioctl's' argument.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_pll_info
as their third argument. All elements of this structure are of
type 'int', except the last one that is of type 'long'. That is
the reason why a separate target structure (target_rtc_pll_info)
is defined in linux-user/syscall_defs. The rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index b09396e..0a4e3f1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v3 for 5.0 4/6] linux-user: Add support for get/set RTC wakeup alarm using ioctls

2019-11-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Get/Set wakeup alarm

Some RTCs support a more powerful alarm interface, using these
ioctls to read or write the RTC's alarm time (respectively)
with this structure:

struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};

The enabled flag is used to enable or disable the alarm inter‐
rupt, or to read its current status; when using these calls,
RTC_AIE_ON and RTC_AIE_OFF are not used.  The pending flag is
used by RTC_WKALM_RD to report a pending interrupt (so it's
mostly useless on Linux, except when talking to the RTC man‐
aged by EFI firmware).  The time field is as used with
RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
and tm_year fields are also valid.  A pointer to this struc‐
ture should be passed as the third ioctl's argument.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_wkalrm
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are either of type 'unsigned char'
or 'struct rtc_time' (that was covered in one of previous
patches), the rest of the implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index accbdee..b09396e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v3 for 5.0 1/6] linux-user: Add support for enable/disable RTC features using ioctls

2019-11-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enable on/off

Enable or disable the alarm interrupt, for RTCs that support
alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enable on/off

Enable or disable the interrupt on every clock update, for
RTCs that support this once-per-second interrupt.  The third
ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enable on/off

Enable or disable the periodic interrupt, for RTCs that sup‐
port these periodic interrupts.  The third ioctl's argument
is ignored.  Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can enable the periodic interrupt
if the frequency is currently set above the value specified in
/proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enable on/off

Enable or disable the Watchdog interrupt, for RTCs that sup-
port this Watchdog interrupt. The third ioctl's argument is
ignored.

Implementation notes:

Since all of involved ioctls have NULL as their third argument,
their implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls.  This needs to be
done only once in this series of commits.  Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH v3 for 5.0 3/6] linux-user: Add support for read/set RTC periodic interrupt and epoch using ioctls

2019-11-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Read/Set IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts.  The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests.  The third ioctl's argument is an
unsigned long * or an unsigned long, respectively.  The value
is the frequency in interrupts per second.  The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192.  Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq.  (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Read/Set epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number.  In
both cases, the number is interpreted relative to this RTC's
Epoch.  The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year.  With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively.  The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch.  To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v3 for 5.0 2/6] linux-user: Add support for read/set RTC time and alarm using ioctls

2019-11-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_RD_TIME - Read RTC time

Returns this RTC's time in the following structure:

struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};

The fields in this structure have the same meaning and ranges
as for the tm structure described in gmtime man page.  A pointer
to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Set RTC time

Sets this RTC's time to the time specified by the rtc_time
structure pointed to by the third ioctl's argument.  To set
the RTC's time the process must be privileged (i.e., have the
CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Read/Set alarm time

Read and set the alarm time, for RTCs that support alarms.
The alarm interrupt must be separately enabled or disabled
using the RTC_AIE_ON, RTC_AIE_OFF requests.  The third
ioctl's argument is a pointer to an rtc_time structure.  Only
the tm_sec, tm_min, and tm_hour fields of this structure are
used.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_time
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are of type 'int', the rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 5/5] linux-user: Add strace support for printing arguments of fallocate()

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscall:

*fallocate - manipulate file space

int fallocate(int fd, int mode, off_t offset, off_t len)
man page: https://www.man7.org/linux/man-pages/man2/fallocate.2.html

Implementation notes:

This syscall's second argument "mode" is composed of predefined values
which represent flags that determine the type of operation that is
to be performed on the file space. For that reason, a printing
function "print_fallocate" was stated in file "strace.list". This printing
function uses an already existing function "print_flags()" to print flags of
the "mode" argument. These flags are stated inside an array "falloc_flags"
that contains values of type "struct flags". These values are instantiated
using an existing macro "FLAG_GENERIC()". Most of these flags are defined
after kernel version 3.0 which is why they are enwrapped in an #ifdef
directive.
The syscall's third ant fourth argument are of type "off_t" which can
cause variations between 32/64-bit architectures. To handle this variation,
function "target_offset64()" was copied from file "strace.c" and used in
"print_fallocate" to print "off_t" arguments for 32-bit architectures.

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 56 ++
 linux-user/strace.list |  2 +-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 542bfdeb91..3998a00bb4 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -34,6 +34,22 @@ struct syscallname {
 #define UNUSED
 #endif
 
+#if TARGET_ABI_BITS == 32
+static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
+{
+#ifdef TARGET_WORDS_BIGENDIAN
+return ((uint64_t)word0 << 32) | word1;
+#else
+return ((uint64_t)word1 << 32) | word0;
+#endif
+}
+#else /* TARGET_ABI_BITS == 32 */
+static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
+{
+return word0;
+}
+#endif /* TARGET_ABI_BITS != 32 */
+
 /*
  * Structure used to translate flag values into strings.  This is
  * similar that is in the actual strace tool.
@@ -1097,6 +1113,26 @@ UNUSED static struct flags statx_mask[] = {
 FLAG_END,
 };
 
+UNUSED static struct flags falloc_flags[] = {
+FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
+FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
+#ifdef FALLOC_FL_NO_HIDE_STALE
+FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
+#endif
+#ifdef FALLOC_FL_COLLAPSE_RANGE
+FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
+#endif
+#ifdef FALLOC_FL_ZERO_RANGE
+FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
+#endif
+#ifdef FALLOC_FL_INSERT_RANGE
+FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
+#endif
+#ifdef FALLOC_FL_UNSHARE_RANGE
+FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
+#endif
+};
+
 /*
  * print_xxx utility functions.  These are used to print syscall
  * parameters in certain format.  All of these have parameter
@@ -1514,6 +1550,26 @@ print_faccessat(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_fallocate
+static void
+print_fallocate(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_flags(falloc_flags, arg1, 0);
+#if TARGET_ABI_BITS == 32
+print_raw_param("%ld", target_offset64(arg2, arg3), 0);
+print_raw_param("%ld", target_offset64(arg4, arg5), 1);
+#else
+print_raw_param("%ld", arg2, 0);
+print_raw_param("%ld", arg3, 1);
+#endif
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_fchmodat
 static void
 print_fchmodat(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index b72f757d3f..d7458ce884 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -182,7 +182,7 @@
 { TARGET_NR_fadvise64_64, "fadvise64_64" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_fallocate
-{ TARGET_NR_fallocate, "fallocate" , NULL, NULL, NULL },
+{ TARGET_NR_fallocate, "fallocate" , NULL, print_fallocate, NULL },
 #endif
 #ifdef TARGET_NR_fanotify_init
 { TARGET_NR_fanotify_init, "fanotify_init" , NULL, NULL, NULL },
-- 
2.17.1




Re: [PATCH 1/2] mailmap: Change email address of Filip Bozuta

2020-06-02 Thread Filip Bozuta
On 2.6.20. 10:52, Aleksandar Markovic wrote:
> Filip Buzuta wants to use his new email address for his future
> work in QEMU.
>
> CC: Filip Bozuta 
> Signed-off-by: Aleksandar Markovic 
Reviewed-by: Filip Bozuta 
> ---
>   .mailmap | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/.mailmap b/.mailmap
> index e3628c7a66..9f2a3a55f9 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -45,6 +45,7 @@ Aleksandar Markovic  
> 
>   Aleksandar Rikalo  
>   Aleksandar Rikalo  
> 
>   Anthony Liguori  Anthony Liguori 
> 
> +Filip Bozuta  
>   James Hogan  
>   Leif Lindholm  
>   Paul Burton  




[PATCH 2/5] linux-user: Add strace support for printing argument of syscalls used for extend attributes

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscalls:

*getxattr, lgetxattr, fgetxattr - retrieve an extended attribute value

ssize_t getxattr(const char *path, const char *name, void *value, 
size_t size)
ssize_t lgetxattr(const char *path, const char *name, void *value, 
size_t size)
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size)
man page: https://www.man7.org/linux/man-pages/man2/getxattr.2.html

*listxattr, llistxattr, flistxattr - list extended attribute names

ssize_t listxattr(const char *path, char *list, size_t size)
ssize_t llistxattr(const char *path, char *list, size_t size)
ssize_t flistxattr(int fd, char *list, size_t size)
man page: https://www.man7.org/linux/man-pages/man2/listxattr.2.html

Implementation notes:

All of the syscalls have strings as argument types and thus a separate
printing function was stated in file "strace.list" for every one of them.
All of these printing functions were defined in "strace.c" using existing
printing functions for appropriate argument types:
   "print_strig()" - for (const char*) type
   "print_pointer()" - for (char*) and (void *) type
   "print_raw_param()" for (int) and (size_t) type
Syscalls "getxattr()" and "lgetxattr()" have the same number and type of
arguments and thus their print functions ("print_getxattr", 
"print_lgetxattr")
share a same definition. The same statement applies to syscalls 
"listxattr()"
and "llistxattr()".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 60 ++
 linux-user/strace.list | 12 -
 2 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index c578876d22..5cf419989c 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1629,6 +1629,66 @@ print_fcntl(const struct syscallname *name,
 #define print_fcntl64   print_fcntl
 #endif
 
+#ifdef TARGET_NR_fgetxattr
+static void
+print_fgetxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_string(arg1, 0);
+print_pointer(arg2, 0);
+print_raw_param("%u", arg3, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_flistxattr
+static void
+print_flistxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_pointer(arg1, 0);
+print_raw_param("%u", arg2, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
+static void
+print_getxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_string(arg1, 0);
+print_pointer(arg2, 0);
+print_raw_param("%u", arg3, 1);
+print_syscall_epilogue(name);
+}
+#define print_lgetxattr print_getxattr
+#endif
+
+#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
+static void
+print_listxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_pointer(arg1, 0);
+print_raw_param("%u", arg2, 1);
+print_syscall_epilogue(name);
+}
+#define print_llistxattr print_listxattr
+#endif
+
 #ifdef TARGET_NR_futimesat
 static void
 print_futimesat(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index fb9799e7e6..8d51c54bca 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -218,13 +218,13 @@
 { TARGET_NR_fdatasync, "fdatasync" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fgetxattr
-{ TARGET_NR_fgetxattr, "fgetxattr" , NULL, NULL, NULL },
+{ TARGET_NR_fgetxattr, "fgetxattr" , NULL, print_fgetxattr, NULL },
 #endif
 #ifdef TARGET_NR_finit_module
 { TARGET_NR_finit_module, "finit_module" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_flistxattr
-{ TARGET_NR_flistxattr, "flistxattr" , NULL, NULL, NULL },
+{ TARGET_NR_flistxattr, "flistxattr" , NULL, print_flistxattr, NULL },
 #endif
 #ifdef TARGET_NR_flock
 { TARGET_NR_flock, "flock" , NULL, NULL, NULL },
@@ -396,7 +396,7 @@
 { TARGET_NR_getuid32, "getuid32" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_getxattr
-{

[PATCH 3/5] linux-user: Add strace support for printing arguments of lseek()

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for syscall:

*lseek - reposition read/write file offset

 off_t lseek(int fd, off_t offset, int whence)
 man page: https://www.man7.org/linux/man-pages/man2/lseek.2.html

Implementation notes:

The syscall's third argument "whence" has predefined values:
"SEEK_SET","SEEK_CUR","SEEK_END","SEEK_DATA","SEEK_HOLE"
and thus a separate printing function "print_lseek" was stated
in file "strace.list". This function is defined in "strace.c"
by using an existing function "print_raw_param()" to print
the first and second argument and a switch(case) statement
for the predefined values of the third argument.
Values "SEEK_DATA" and "SEEK_HOLE" are defined in kernel version 3.1.
    That is the reason why case statements for these values are
enwrapped in #ifdef directive.

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 32 
 linux-user/strace.list |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5cf419989c..b7f012f1b5 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1768,6 +1768,38 @@ print__llseek(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_lseek
+static void
+print_lseek(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_raw_param("%ld", arg1, 0);
+switch (arg2) {
+case SEEK_SET:
+qemu_log("SEEK_SET"); break;
+case SEEK_CUR:
+qemu_log("SEEK_CUR"); break;
+case SEEK_END:
+qemu_log("SEEK_END"); break;
+#ifdef SEEK_DATA
+case SEEK_DATA:
+qemu_log("SEEK_DATA"); break;
+#endif
+#ifdef SEEK_HOLE
+case SEEK_HOLE:
+qemu_log("SEEK_HOLE"); break;
+#endif
+default:
+print_raw_param("%#x", arg2, 1);
+qemu_log(" /* SEEK_??? */");
+}
+print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 8d51c54bca..5a56212532 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -513,7 +513,7 @@
 { TARGET_NR_lremovexattr, "lremovexattr" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_lseek
-{ TARGET_NR_lseek, "lseek" , NULL, NULL, NULL },
+{ TARGET_NR_lseek, "lseek" , NULL, print_lseek, NULL },
 #endif
 #ifdef TARGET_NR_lsetxattr
 { TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH 0/5] Add strace support for printing arguments of selected syscalls

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This series covers strace support for printing arguments of following syscalls:

*acct() *lgetxattr()*lseek()
*fsync()*fgetxattr()*chown()
*fdatasync()*listxattr()*lchown()
*listen()   *llistxattr()   *fallocate()
*getxattr() *flistxattr()

The implementation details for strace support is described in this series patch
commit messages.

Testing method:

Mini test programs were written that run these syscalls for different 
arguments.
Those programs were compiled (sometimes using cross-compilers) for the 
following
architectures:

* Intel 64-bit (little endian) (gcc)
* Power pc 32-bit (big endian) (powerpc-linux-gnu-gcc)
* Power pc 64-bit (big endian) (powerpc64-linux-gnu-gcc)
* Mips 32-bit (little endian) (mipsel-linux-gnu-gcc)
* Mips 64-bit (little endian) (mips64el-linux-gnuabi64-gcc)

The corresponding native programs were executed with strace, without using
QEMU, on Intel Core i7-4790K (x86_64) host.

All applicable compiled programs were in turn executed with "-strace"
through QEMU and the strace printing results obtained were the same 
ones gotten for native execution.

Filip Bozuta (5):
  linux-user: Add strace support for a group of syscalls
  linux-user: Add strace support for printing argument of syscalls used
for extend attributes
  linux-user: Add strace support for printing arguments of lseek()
  linux-user: Add strace support for printing arguments of
chown()/lchown()
  linux-user: Add strace support for printing arguments of fallocate()

 linux-user/strace.c| 174 +
 linux-user/strace.list |  28 +++
 2 files changed, 188 insertions(+), 14 deletions(-)

-- 
2.17.1




[PATCH 1/5] linux-user: Add strace support for a group of syscalls

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscalls:

*acct - switch process accounting on or off

int acct(const char *filename)
man page: https://www.man7.org/linux/man-pages/man2/acct.2.html

*fsync, fdatasync - synchronize a file's in-core state with storage device

int fsync(int fd)
int fdatasync(int fd)
man page: https://www.man7.org/linux/man-pages/man2/fsync.2.html

*listen - listen for connections on a socket

int listen(int sockfd, int backlog)
man page: https://www.man7.org/linux/man-pages/man2/listen.2.html

Implementation notes:

Syscall acct() takes string as its only argument and thus a separate
print function "print_acct" is stated in file "strace.list". This
function is defined and implemented in "strace.c" by using an
existing function used to print string arguments: "print_string()".
All the other syscalls have only primitive argument types, so the
rest of the implementation was handled by stating an appropriate
printing format in file "strace.list".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 13 -
 linux-user/strace.list |  8 
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0d9095c674..c578876d22 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1353,6 +1353,18 @@ print_access(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_acct
+static void
+print_acct(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_brk
 static void
 print_brk(const struct syscallname *name,
@@ -1617,7 +1629,6 @@ print_fcntl(const struct syscallname *name,
 #define print_fcntl64   print_fcntl
 #endif
 
-
 #ifdef TARGET_NR_futimesat
 static void
 print_futimesat(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index d49a1e92a8..fb9799e7e6 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -13,7 +13,7 @@
 { TARGET_NR_access, "access" , NULL, print_access, NULL },
 #endif
 #ifdef TARGET_NR_acct
-{ TARGET_NR_acct, "acct" , NULL, NULL, NULL },
+{ TARGET_NR_acct, "acct" , NULL, print_acct, NULL },
 #endif
 #ifdef TARGET_NR_add_key
 { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
@@ -215,7 +215,7 @@
 { TARGET_NR_fcntl64, "fcntl64" , NULL, print_fcntl64, NULL },
 #endif
 #ifdef TARGET_NR_fdatasync
-{ TARGET_NR_fdatasync, "fdatasync" , NULL, NULL, NULL },
+{ TARGET_NR_fdatasync, "fdatasync" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fgetxattr
 { TARGET_NR_fgetxattr, "fgetxattr" , NULL, NULL, NULL },
@@ -251,7 +251,7 @@
 { TARGET_NR_fstatfs64, "fstatfs64" , "%s(%d,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fsync
-{ TARGET_NR_fsync, "fsync" , NULL, NULL, NULL },
+{ TARGET_NR_fsync, "fsync" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_ftime
 { TARGET_NR_ftime, "ftime" , NULL, NULL, NULL },
@@ -492,7 +492,7 @@
 { TARGET_NR_Linux, "Linux" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_listen
-{ TARGET_NR_listen, "listen" , NULL, NULL, NULL },
+{ TARGET_NR_listen, "listen" , "%s(%d,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_listxattr
 { TARGET_NR_listxattr, "listxattr" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH 4/5] linux-user: Add strace support for printing arguments of chown()/lchown()

2020-06-02 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for syscalls:

*chown, lchown - change ownership of a file

int chown(const char *pathname, uid_t owner, gid_t group)
int lchown(const char *pathname, uid_t owner, gid_t group)
man page: https://www.man7.org/linux/man-pages/man2/lchown.2.html

Implementation notes:

Both syscalls use strings as arguments and thus a separate
printing function was stated in "strace.list" for them.
Both syscalls share the same number and types of arguments
and thus share a same definition in file "syscall.c".
This defintion uses existing functions "print_string()" to
print the string argument and "print_raw_param()" to print
other two arguments that are of basic types.

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 15 +++
 linux-user/strace.list |  4 ++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index b7f012f1b5..542bfdeb91 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1414,6 +1414,21 @@ print_chmod(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
+static void
+print_chown(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_raw_param("%d", arg1, 0);
+print_raw_param("%d", arg2, 1);
+print_syscall_epilogue(name);
+}
+#define print_lchown print_chown
+#endif
+
 #ifdef TARGET_NR_clock_adjtime
 static void
 print_clock_adjtime(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 5a56212532..b72f757d3f 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -71,7 +71,7 @@
 { TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL },
 #endif
 #ifdef TARGET_NR_chown
-{ TARGET_NR_chown, "chown" , NULL, NULL, NULL },
+{ TARGET_NR_chown, "chown" , NULL, print_chown, NULL },
 #endif
 #ifdef TARGET_NR_chown32
 { TARGET_NR_chown32, "chown32" , NULL, NULL, NULL },
@@ -474,7 +474,7 @@
 { TARGET_NR_kill, "kill", NULL, print_kill, NULL },
 #endif
 #ifdef TARGET_NR_lchown
-{ TARGET_NR_lchown, "lchown" , NULL, NULL, NULL },
+{ TARGET_NR_lchown, "lchown" , NULL, print_lchown, NULL },
 #endif
 #ifdef TARGET_NR_lchown32
 { TARGET_NR_lchown32, "lchown32" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH v2 1/6] linux-user: Extend strace support to enable argument printing after syscall execution

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

Structure "struct syscallname" in file "strace.c" is used for "-strace"
to print arguments and return values of syscalls. The last field of
this structure "result" represents the calling function that prints the
return values. This field was extended in this patch so that this functions
takes all syscalls arguments beside the return value. In this way, it 
enables
"-strace" to print arguments of syscalls that have changed after the syscall
execution. This extension will be useful as there are many syscalls that
return values inside their arguments (i.e. listxattr() that returns the list
of extended attributes inside the "list" argument).

Implementation notes:

Since there are already three existing "print_syscall_ret*" functions inside
"strace.c" ("print_syscall_ret_addr()", "print_syscall_ret_adjtimex()",
"print_syscall_ret_newselect()"), they were changed to have all syscall 
arguments
beside the return value. This was done so that these functions don't cause 
build
errors (even though syscall arguments are not used in these functions).

Signed-off-by: Filip Bozuta 
---
 linux-user/qemu.h|  4 +++-
 linux-user/strace.c  | 24 ++--
 linux-user/syscall.c |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index ce902f5132..8f938b8105 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -383,7 +383,9 @@ int host_to_target_waitstatus(int status);
 void print_syscall(int num,
abi_long arg1, abi_long arg2, abi_long arg3,
abi_long arg4, abi_long arg5, abi_long arg6);
-void print_syscall_ret(int num, abi_long arg1);
+void print_syscall_ret(int num, abi_long ret,
+   abi_long arg1, abi_long arg2, abi_long arg3,
+   abi_long arg4, abi_long arg5, abi_long arg6);
 /**
  * print_taken_signal:
  * @target_signum: target signal being taken
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0d9095c674..23f7c386b5 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -19,7 +19,9 @@ struct syscallname {
 void (*call)(const struct syscallname *,
  abi_long, abi_long, abi_long,
  abi_long, abi_long, abi_long);
-void (*result)(const struct syscallname *, abi_long);
+void (*result)(const struct syscallname *, abi_long,
+   abi_long, abi_long, abi_long,
+   abi_long, abi_long, abi_long);
 };
 
 #ifdef __GNUC__
@@ -736,7 +738,9 @@ print_ipc(const struct syscallname *name,
  */
 
 static void
-print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
+print_syscall_ret_addr(const struct syscallname *name, abi_long ret,
+   abi_long arg0, abi_long arg1, abi_long arg2,
+   abi_long arg3, abi_long arg4, abi_long arg5)
 {
 const char *errstr = NULL;
 
@@ -760,7 +764,9 @@ print_syscall_ret_raw(struct syscallname *name, abi_long 
ret)
 
 #ifdef TARGET_NR__newselect
 static void
-print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
+print_syscall_ret_newselect(const struct syscallname *name, abi_long ret,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
 {
 qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
 print_fdset(newselect_arg1,newselect_arg2);
@@ -783,7 +789,9 @@ print_syscall_ret_newselect(const struct syscallname *name, 
abi_long ret)
 #define TARGET_TIME_ERROR5   /* clock not synchronized */
 #ifdef TARGET_NR_adjtimex
 static void
-print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
+print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret,
+   abi_long arg0, abi_long arg1, abi_long arg2,
+   abi_long arg3, abi_long arg4, abi_long arg5)
 {
 const char *errstr = NULL;
 
@@ -2847,7 +2855,9 @@ print_syscall(int num,
 
 
 void
-print_syscall_ret(int num, abi_long ret)
+print_syscall_ret(int num, abi_long ret,
+  abi_long arg1, abi_long arg2, abi_long arg3,
+  abi_long arg4, abi_long arg5, abi_long arg6)
 {
 int i;
 const char *errstr = NULL;
@@ -2855,7 +2865,9 @@ print_syscall_ret(int num, abi_long ret)
 for(i=0;i

[PATCH v2 2/6] linux-user: Add strace support for a group of syscalls

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscalls:

*acct - switch process accounting on or off

int acct(const char *filename)
man page: https://www.man7.org/linux/man-pages/man2/acct.2.html

*fsync, fdatasync - synchronize a file's in-core state with storage device

int fsync(int fd)
int fdatasync(int fd)
man page: https://www.man7.org/linux/man-pages/man2/fsync.2.html

*listen - listen for connections on a socket

int listen(int sockfd, int backlog)
man page: https://www.man7.org/linux/man-pages/man2/listen.2.html

Implementation notes:

Syscall acct() takes string as its only argument and thus a separate
print function "print_acct" is stated in file "strace.list". This
function is defined and implemented in "strace.c" by using an
existing function used to print string arguments: "print_string()".
All the other syscalls have only primitive argument types, so the
rest of the implementation was handled by stating an appropriate
printing format in file "strace.list".

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/strace.c| 13 -
 linux-user/strace.list |  8 
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 23f7c386b5..f980451e3f 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1361,6 +1361,18 @@ print_access(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_acct
+static void
+print_acct(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_brk
 static void
 print_brk(const struct syscallname *name,
@@ -1625,7 +1637,6 @@ print_fcntl(const struct syscallname *name,
 #define print_fcntl64   print_fcntl
 #endif
 
-
 #ifdef TARGET_NR_futimesat
 static void
 print_futimesat(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index d49a1e92a8..fb9799e7e6 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -13,7 +13,7 @@
 { TARGET_NR_access, "access" , NULL, print_access, NULL },
 #endif
 #ifdef TARGET_NR_acct
-{ TARGET_NR_acct, "acct" , NULL, NULL, NULL },
+{ TARGET_NR_acct, "acct" , NULL, print_acct, NULL },
 #endif
 #ifdef TARGET_NR_add_key
 { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
@@ -215,7 +215,7 @@
 { TARGET_NR_fcntl64, "fcntl64" , NULL, print_fcntl64, NULL },
 #endif
 #ifdef TARGET_NR_fdatasync
-{ TARGET_NR_fdatasync, "fdatasync" , NULL, NULL, NULL },
+{ TARGET_NR_fdatasync, "fdatasync" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fgetxattr
 { TARGET_NR_fgetxattr, "fgetxattr" , NULL, NULL, NULL },
@@ -251,7 +251,7 @@
 { TARGET_NR_fstatfs64, "fstatfs64" , "%s(%d,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fsync
-{ TARGET_NR_fsync, "fsync" , NULL, NULL, NULL },
+{ TARGET_NR_fsync, "fsync" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_ftime
 { TARGET_NR_ftime, "ftime" , NULL, NULL, NULL },
@@ -492,7 +492,7 @@
 { TARGET_NR_Linux, "Linux" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_listen
-{ TARGET_NR_listen, "listen" , NULL, NULL, NULL },
+{ TARGET_NR_listen, "listen" , "%s(%d,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_listxattr
 { TARGET_NR_listxattr, "listxattr" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH v2 3/6] linux-user: Add strace support for printing argument of syscalls used for extended attributes

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscalls:

*getxattr, lgetxattr, fgetxattr - retrieve an extended attribute value

ssize_t getxattr(const char *path, const char *name, void *value, 
size_t size)
ssize_t lgetxattr(const char *path, const char *name, void *value, 
size_t size)
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size)
man page: https://www.man7.org/linux/man-pages/man2/getxattr.2.html

*listxattr, llistxattr, flistxattr - list extended attribute names

ssize_t listxattr(const char *path, char *list, size_t size)
ssize_t llistxattr(const char *path, char *list, size_t size)
ssize_t flistxattr(int fd, char *list, size_t size)
man page: https://www.man7.org/linux/man-pages/man2/listxattr.2.html

*removexattr, lremovexattr, fremovexattr - remove an extended attribute

 int removexattr(const char *path, const char *name)
 int lremovexattr(const char *path, const char *name)
 int fremovexattr(int fd, const char *name)
 man page: https://www.man7.org/linux/man-pages/man2/removexattr.2.html

Implementation notes:

All of the syscalls have strings as argument types and thus a separate
printing function was stated in file "strace.list" for every one of them.
All of these printing functions were defined in "strace.c" using existing
printing functions for appropriate argument types:
   "print_string()" - for (const char*) type
   "print_pointer()" - for (char*) and (void *) type
   "print_raw_param()" for (int) and (size_t) type
Syscalls "getxattr()" and "lgetxattr()" have the same number and type of
arguments and thus their print functions ("print_getxattr", 
"print_lgetxattr")
share a same definition. The same statement applies to syscalls 
"listxattr()"
and "llistxattr()".
Function "print_syscall_ret_listxattr()" was added to print the returned 
list
of extended attributes for syscalls and was listed as a "result" function 
in file
"strace.list" for syscalls: "listxattr(), llistxattr(), flistxattr()".

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 126 +
 linux-user/strace.list |  21 ---
 2 files changed, 138 insertions(+), 9 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index f980451e3f..59fdb0a05f 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -830,6 +830,45 @@ print_syscall_ret_adjtimex(const struct syscallname *name, 
abi_long ret,
 }
 #endif
 
+#if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
+ || defined(TARGGET_NR_flistxattr)
+static void
+print_syscall_ret_listxattr(const struct syscallname *name, abi_long ret,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+const char *errstr = NULL;
+
+qemu_log(" = ");
+if (ret < 0) {
+qemu_log("-1 errno=%d", errno);
+errstr = target_strerror(-ret);
+if (errstr) {
+qemu_log(" (%s)", errstr);
+}
+} else {
+qemu_log(TARGET_ABI_FMT_ld, ret);
+qemu_log(" (list = ");
+if (arg1 != 0) {
+abi_long attr = arg1;
+for (;;) {
+print_string(attr, 1);
+attr += target_strlen(attr) + 1;
+if (target_strlen(attr) == 0) {
+break;
+}
+qemu_log(",");
+}
+} else {
+qemu_log("NULL");
+}
+qemu_log(")");
+}
+
+qemu_log("\n");
+}
+#endif
+
 UNUSED static struct flags access_flags[] = {
 FLAG_GENERIC(F_OK),
 FLAG_GENERIC(R_OK),
@@ -1637,6 +1676,93 @@ print_fcntl(const struct syscallname *name,
 #define print_fcntl64   print_fcntl
 #endif
 
+#ifdef TARGET_NR_fgetxattr
+static void
+print_fgetxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_string(arg1, 0);
+print_pointer(arg2, 0);
+print_raw_param(TARGET_FMT_lu, arg3, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_flistxattr
+static void
+print_flistxattr(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_pointer(arg1, 0);
+print_raw_param(TARGET_FMT_lu, arg2, 1);
+print_syscall_

[PATCH v2 5/6] linux-user: Add strace support for printing arguments of chown()/lchown()

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for syscalls:

*chown, lchown - change ownership of a file

int chown(const char *pathname, uid_t owner, gid_t group)
int lchown(const char *pathname, uid_t owner, gid_t group)
man page: https://www.man7.org/linux/man-pages/man2/lchown.2.html

Implementation notes:

Both syscalls use strings as arguments and thus a separate
printing function was stated in "strace.list" for them.
Both syscalls share the same number and types of arguments
and thus share a same definition in file "syscall.c".
This defintion uses existing functions "print_string()" to
print the string argument and "print_raw_param()" to print
other two arguments that are of basic types.

Signed-off-by: Filip Bozuta 
Reviewed-by: Laurent Vivier 
---
 linux-user/strace.c| 15 +++
 linux-user/strace.list |  4 ++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index adf9a47465..cd6a2b8e3f 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1461,6 +1461,21 @@ print_chmod(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
+static void
+print_chown(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_string(arg0, 0);
+print_raw_param("%d", arg1, 0);
+print_raw_param("%d", arg2, 1);
+print_syscall_epilogue(name);
+}
+#define print_lchown print_chown
+#endif
+
 #ifdef TARGET_NR_clock_adjtime
 static void
 print_clock_adjtime(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index bd04596c50..44eb515ca4 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -71,7 +71,7 @@
 { TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL },
 #endif
 #ifdef TARGET_NR_chown
-{ TARGET_NR_chown, "chown" , NULL, NULL, NULL },
+{ TARGET_NR_chown, "chown" , NULL, print_chown, NULL },
 #endif
 #ifdef TARGET_NR_chown32
 { TARGET_NR_chown32, "chown32" , NULL, NULL, NULL },
@@ -475,7 +475,7 @@
 { TARGET_NR_kill, "kill", NULL, print_kill, NULL },
 #endif
 #ifdef TARGET_NR_lchown
-{ TARGET_NR_lchown, "lchown" , NULL, NULL, NULL },
+{ TARGET_NR_lchown, "lchown" , NULL, print_lchown, NULL },
 #endif
 #ifdef TARGET_NR_lchown32
 { TARGET_NR_lchown32, "lchown32" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH v2 4/6] linux-user: Add strace support for printing arguments of lseek()

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for syscall:

*lseek - reposition read/write file offset

 off_t lseek(int fd, off_t offset, int whence)
 man page: https://www.man7.org/linux/man-pages/man2/lseek.2.html

Implementation notes:

The syscall's third argument "whence" has predefined values:
"SEEK_SET","SEEK_CUR","SEEK_END","SEEK_DATA","SEEK_HOLE"
and thus a separate printing function "print_lseek" was stated
in file "strace.list". This function is defined in "strace.c"
by using an existing function "print_raw_param()" to print
the first and second argument and a switch(case) statement
for the predefined values of the third argument.
Values "SEEK_DATA" and "SEEK_HOLE" are defined in kernel version 3.1.
    That is the reason why case statements for these values are
enwrapped in #ifdef directive.

Signed-off-by: Filip Bozuta 
---
 linux-user/strace.c| 31 +++
 linux-user/strace.list |  2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 59fdb0a05f..adf9a47465 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1842,6 +1842,37 @@ print__llseek(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_lseek
+static void
+print_lseek(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
+switch (arg2) {
+case SEEK_SET:
+qemu_log("SEEK_SET"); break;
+case SEEK_CUR:
+qemu_log("SEEK_CUR"); break;
+case SEEK_END:
+qemu_log("SEEK_END"); break;
+#ifdef SEEK_DATA
+case SEEK_DATA:
+qemu_log("SEEK_DATA"); break;
+#endif
+#ifdef SEEK_HOLE
+case SEEK_HOLE:
+qemu_log("SEEK_HOLE"); break;
+#endif
+default:
+print_raw_param("%#x", arg2, 1);
+}
+print_syscall_epilogue(name);
+}
+#endif
+
 #if defined(TARGET_NR_socket)
 static void
 print_socket(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 05a72370c1..bd04596c50 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -516,7 +516,7 @@
 { TARGET_NR_lremovexattr, "lremovexattr" , NULL, print_lremovexattr, NULL },
 #endif
 #ifdef TARGET_NR_lseek
-{ TARGET_NR_lseek, "lseek" , NULL, NULL, NULL },
+{ TARGET_NR_lseek, "lseek" , NULL, print_lseek, NULL },
 #endif
 #ifdef TARGET_NR_lsetxattr
 { TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },
-- 
2.17.1




[PATCH v2 6/6] linux-user: Add strace support for printing arguments of fallocate()

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This patch implements strace argument printing functionality for following 
syscall:

*fallocate - manipulate file space

int fallocate(int fd, int mode, off_t offset, off_t len)
man page: https://www.man7.org/linux/man-pages/man2/fallocate.2.html

Implementation notes:

This syscall's second argument "mode" is composed of predefined values
which represent flags that determine the type of operation that is
to be performed on the file space. For that reason, a printing
function "print_fallocate" was stated in file "strace.list". This printing
function uses an already existing function "print_flags()" to print flags of
the "mode" argument. These flags are stated inside an array "falloc_flags"
that contains values of type "struct flags". These values are instantiated
using an existing macro "FLAG_GENERIC()". Most of these flags are defined
after kernel version 3.0 which is why they are enwrapped in an #ifdef
directive.
The syscall's third ant fourth argument are of type "off_t" which can
cause variations between 32/64-bit architectures. To handle this variation,
function "target_offset64()" was copied from file "strace.c" and used in
"print_fallocate" to print "off_t" arguments for 32-bit architectures.

Signed-off-by: Filip Bozuta 
---
 linux-user/qemu.h  | 16 
 linux-user/strace.c| 40 
 linux-user/strace.list |  2 +-
 linux-user/syscall.c   | 16 
 4 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 8f938b8105..be67391ba4 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -670,6 +670,22 @@ static inline int is_error(abi_long ret)
 return (abi_ulong)ret >= (abi_ulong)(-4096);
 }
 
+#if TARGET_ABI_BITS == 32
+static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
+{
+#ifdef TARGET_WORDS_BIGENDIAN
+return ((uint64_t)word0 << 32) | word1;
+#else
+return ((uint64_t)word1 << 32) | word0;
+#endif
+}
+#else /* TARGET_ABI_BITS == 32 */
+static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
+{
+return word0;
+}
+#endif /* TARGET_ABI_BITS != 32 */
+
 /**
  * preexit_cleanup: housekeeping before the guest exits
  *
diff --git a/linux-user/strace.c b/linux-user/strace.c
index cd6a2b8e3f..3ef7f80cd7 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1144,6 +1144,26 @@ UNUSED static struct flags statx_mask[] = {
 FLAG_END,
 };
 
+UNUSED static struct flags falloc_flags[] = {
+FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
+FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
+#ifdef FALLOC_FL_NO_HIDE_STALE
+FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
+#endif
+#ifdef FALLOC_FL_COLLAPSE_RANGE
+FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
+#endif
+#ifdef FALLOC_FL_ZERO_RANGE
+FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
+#endif
+#ifdef FALLOC_FL_INSERT_RANGE
+FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
+#endif
+#ifdef FALLOC_FL_UNSHARE_RANGE
+FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
+#endif
+};
+
 /*
  * print_xxx utility functions.  These are used to print syscall
  * parameters in certain format.  All of these have parameter
@@ -1561,6 +1581,26 @@ print_faccessat(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_fallocate
+static void
+print_fallocate(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_flags(falloc_flags, arg1, 0);
+#if TARGET_ABI_BITS == 32
+print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
+print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
+#else
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
+#endif
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_fchmodat
 static void
 print_fchmodat(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 44eb515ca4..a8d7cbe7a4 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -182,7 +182,7 @@
 { TARGET_NR_fadvise64_64, "fadvise64_64" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_fallocate
-{ TARGET_NR_fallocate, "fallocate" , NULL, NULL, NULL },
+{ TARGET_NR_fallocate, "fallocate" , NULL, print_fallocate, NULL },
 #endif
 #ifdef TARGET_NR_fanotify_init
 { TARGET_NR_fanotify_init, "fanotify_init" , NULL, NULL, NULL },
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 009bb67422..7cc5a65b4f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6608,22 +6608,6 @@ void syscall_init(void)
 }
 }
 
-#if TARGET_

[PATCH v2 0/6] Add strace support for printing arguments of selected syscalls

2020-06-08 Thread Filip Bozuta
From: Filip Bozuta 

This series covers strace support for printing arguments of following syscalls:

*acct()   *lgetxattr()   *removexattr()   *lchown()
*fsync()  *fgetxattr()   *lremovexattr()  *fallocate()
*fdatasync()  *listxattr()   *fremovexattr()
*listen() *llistxattr()  *lseek()
*getxattr()   *flistxattr()  *chown()

The implementation details for strace support is described in this series patch
commit messages.

Testing method:

Mini test programs were written that run these syscalls for different 
arguments.
Those programs were compiled (sometimes using cross-compilers) for the 
following
architectures:

* Intel 64-bit (little endian) (gcc)
* Power pc 32-bit (big endian) (powerpc-linux-gnu-gcc)
* Power pc 64-bit (big endian) (powerpc64-linux-gnu-gcc)
* Mips 32-bit (little endian) (mipsel-linux-gnu-gcc)
* Mips 64-bit (little endian) (mips64el-linux-gnuabi64-gcc)

The corresponding native programs were executed with strace, without using
QEMU, on Intel Core i7-4790K (x86_64) host.

All applicable compiled programs were in turn executed with "-strace"
through QEMU and the strace printing results obtained were the same 
ones gotten for native execution.

v2:

* Added patch that extends strace support by enabling argument printing
  after syscall execution
* Added strace support for argument printing for syscalls:
  removexattr(), lremovexattr(), fremovexattr()
* Added "print_syscall_ret_listxattr()" that prints list of extended
  attributes after execution of syscalls: listxattr(), llistxattr(),
  flistxattr()
* Corrected formats in some printing functions
* Moved target_offset64() function definition from "syscall.c" to
  "qemu.h"

Filip Bozuta (6):
  linux-user: Extend strace support to enable argument printing after
syscall execution
  linux-user: Add strace support for a group of syscalls
  linux-user: Add strace support for printing argument of syscalls used
for extended attributes
  linux-user: Add strace support for printing arguments of lseek()
  linux-user: Add strace support for printing arguments of
chown()/lchown()
  linux-user: Add strace support for printing arguments of fallocate()

 linux-user/qemu.h  |  20 +++-
 linux-user/strace.c| 247 -
 linux-user/strace.list |  37 +++---
 linux-user/syscall.c   |  18 +--
 4 files changed, 281 insertions(+), 41 deletions(-)

-- 
2.17.1




[PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_RD_TIME - Getting RTC time

Returns this RTC's time in the following structure:

struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};

The fields in this structure have the same meaning and ranges
as the tm structure described in gmtime man page. A pointer
to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Setting RTC time

Sets this RTC's time to the time specified by the rtc_time
structure pointed to by the third ioctl's argument. To set
the RTC's time the process must be privileged (i.e., have the
CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Getting/Setting alarm time

Read and set the alarm time, for RTCs that support alarms.
The alarm interrupt must be separately enabled or disabled
using the RTC_AIE_ON, RTC_AIE_OFF requests. The third
ioctl's argument is a pointer to an rtc_time structure. Only
the tm_sec, tm_min, and tm_hour fields of this structure are
used.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_time
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are of type 'int', the rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Getting/Setting wakeup alarm

Some RTCs support a more powerful alarm interface, using these
ioctls to read or write the RTC's alarm time (respectively)
with this structure:

struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};

The enabled flag is used to enable or disable the alarm
interrupt, or to read its current status; when using these
calls, RTC_AIE_ON and RTC_AIE_OFF are not used. The pending
flag is used by RTC_WKALM_RD to report a pending interrupt
(so it's mostly useless on Linux, except when talking to the
RTC managed by EFI firmware). The time field is as used with
RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
and tm_year fields are also valid. A pointer to this structure
should be passed as the third ioctl's argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure
rtc_wkalrm as their third argument. That is the reason why
corresponding definition is added in linux-user/syscall_types.h.
Since all  elements of this structure are either of type
'unsigned char' or 'struct rtc_time' (that was covered in one
of previous patches), the rest of the implementation is
    straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index accbdee..b09396e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 00/12] linux-user: Add support for real time clock and

2020-01-09 Thread Filip Bozuta
t programs were written to test further functionalities
of individual ioctls. Those programs were, like the file "timer.c",
compiled for different architectures and were executed both natively
and thgrough QEMU to compare the results.

Example of a test program:

For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:

#include 
#include 
#include 
#include 
#include 
#include 

#define ERROR -1

int main()
{
int fd = open("/dev/snd/timer", O_RDWR);

if(fd == ERROR)
{
perror("open");
return -1;
}

struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
  SNDRV_TIMER_SCLASS_NONE, -1, 
  SNDRV_TIMER_GLOBAL_SYSTEM, 0};

struct snd_timer_ginfo ginfo;
ginfo.tid = id;

if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
{
perror("ioctl");
return -1;
}

printf("flags: %u\n", ginfo.flags);
printf("card: %d\n", ginfo.card);
printf("id: %s\n", ginfo.id);
printf("name: %s\n", ginfo.name);
printf("reserved0: %lu\n", ginfo.reserved0);
printf("resolution: %lu\n", ginfo.resolution);
printf("resolution_min: %lu\n", ginfo.resolution_min);
printf("reolution_max: %lu\n", ginfo.resolution_max);
printf("clients: %u\n", ginfo.clients);
printf("reserved: %s\n", ginfo.reserved);

return 0;
}

v5:

* added support for alsa sound timer ioctls

v4:

* changed patch descriptions so that they are better
  formatted and more cemprehensible

v3:

* changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

* added description of each ioctl in patches
* wrote a more detailed cover letter with description of testing
* changed one instance of TYPE_INT to MK_PTR(TYPE_INT)


Filip Bozuta (12):
  linux-user: Add support for enabling/disabling RTC features using
ioctls
  linux-user: Add support for getting/setting RTC time and alarm using
ioctls
  linux-user: Add support for getting/setting RTC periodic interrupt and
epoch using ioctls
  linux-user: Add support for getting/setting RTC wakeup alarm using
ioctls
  linux-user: Add support for getting/setting RTC PLL correction using
ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
ioctls
  linux-user: Add support for getting alsa timer version and id
  linux-user: Add support for setting alsa timer enhanced read using
ioctl
  linux-user: Add support for getting/setting specified alsa timer
parameters using ioctls
  linux-user: Add support for selecting alsa timer using ioctl
  linux-user: Add support for getting/setting selected alsa timer
parameters using ioctls
  linux-user: Add support for selected alsa timer instructions using
ioctls

 linux-user/ioctls.h|  45 +
 linux-user/syscall.c   |   2 +
 linux-user/syscall_defs.h  | 121 +
 linux-user/syscall_types.h |  91 ++
 4 files changed, 259 insertions(+)

-- 
2.7.4




[PATCH 07/12] linux-user: Add support for getting alsa timer version and id

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_PVERSION - Getting the sound timer version

Read the sound timer version. The third ioctl's argument is
a pointer to an int in which the specified timers version
is returned.

SNDRV_TIMER_IOCTL_NEXT_DEVICE - Getting id information about next timer

Read id information about the next timer device from the sound timer
device list. The id infomration is returned in the following structure:

struct snd_timer_id {
int dev_class;/* timer device class number */
int dev_sclass;   /* slave device class number (unused) */
int card; /* card number */
int device;   /* device number */
int subdevice;/* sub-device number */
};

The devices in the sound timer device list are arranged by the fields
of this structure respectively (first by dev_class number, then by
card number, ...). A pointer to this structure should be passed as
the third ioctl's argument. Before calling the ioctl, the parameters
of this structure should be initialized in relation to the next timer
device which information is to be obtained. For example, if a wanted
timer device has the device class number equal to or bigger then 2,
the field dev_class should be initialized to 2. After the ioctl call,
the structure fields are filled with values from the next device in
the sound timer device list. If there is no next device in the list,
then the structure is filled with "zero" id values (in that case all
fields are filled with value -1).

Implementation notes:

The ioctl 'SNDRV_TIMER_IOCTL_NEXT_DEVICE' has a pointer to a
'struct snd_timer_id' as its third argument. That is the reason why
corresponding definition is added in 'linux-user/syscall_types.h'.
Since all elements of this structure are of type 'int', the rest of
the implementation is straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
    worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 4 
 linux-user/syscall.c   | 1 +
 linux-user/syscall_defs.h  | 5 +
 linux-user/syscall_types.h | 7 +++
 4 files changed, 17 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 1f1f3e6..ed1bd4c 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -449,6 +449,10 @@
   IOCTL(SOUND_MIXER_WRITE_LOUD, IOC_W, MK_PTR(TYPE_INT))
   IOCTL(SOUND_MIXER_WRITE_RECSRC, IOC_W, MK_PTR(TYPE_INT))
 
+  IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
+  IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(HDIO_GET_MULTCOUNT, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 74c3c08..a3993a2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -108,6 +108,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index af4f366..7409021 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2425,6 +2425,11 @@ struct target_statfs64 {
 
 #define TARGET_SOUND_MIXER_WRITE_RECSRC
TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
 
+/* alsa timer ioctls */
+#define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
+#define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
+  struct snd_timer_id)
+
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4027272..2f4cd78 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -83,6 +83,13 @@ STRUCT(buffmem_desc,
 STRUCT(mixer_info,
MK_ARRAY(TYPE_CHAR, 16), MK_ARRAY(TYPE_CHAR, 32), TYPE_INT, 
MK_ARRAY(TYPE_INT, 10))
 
+STRUCT(snd_timer_id,
+   TYPE_INT, /* dev_class */
+   TYPE_INT, /* dev_sclass */
+   TYPE_INT, /* card */
+   TYPE_INT, /* device */
+   TYPE_INT) /* subdevice */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




[PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts. The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests. The third ioctl's argument is an
unsigned long * or an unsigned long, respectively. The value
is the frequency in interrupts per second. The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq. (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number. In
both cases, the number is interpreted relative to this RTC's
Epoch. The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year. With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively. The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch. To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH 12/12] linux-user: Add support for selected alsa timer instructions using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_START - Start selected alsa timer

Starts the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be started. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_STOP - Stop selected alsa timer

Stops the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be stopped. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_CONTINUE - Continue selected alsa timer

Continues the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be continued. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_PAUSE - Pause selected alsa timer

Pauses the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be paused. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

Implementation notes:

Since all of the implemented ioctls have NULL as their third argument,
their implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 43e7e5d..75a2f0e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -466,6 +466,10 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
   IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
+  IOCTL(SNDRV_TIMER_IOCTL_START, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_STOP, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_CONTINUE, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_PAUSE, 0, TYPE_NULL)
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d76124d..311aec0 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2505,6 +2505,10 @@ struct target_snd_timer_status {
  struct 
snd_timer_params)
 #define TARGET_SNDRV_TIMER_IOCTL_STATUS   TARGET_IOR('T', 0x14,
  \
  struct 
target_snd_timer_status)
+#define TARGET_SNDRV_TIMER_IOCTL_STARTTARGET_IO('T', 0xa0)
+#define TARGET_SNDRV_TIMER_IOCTL_STOP TARGET_IO('T', 0xa1)
+#define TARGET_SNDRV_TIMER_IOCTL_CONTINUE TARGET_IO('T', 0xa2)
+#define TARGET_SNDRV_TIMER_IOCTL_PAUSETARGET_IO('T', 0xa3)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enabling on/off

Enable or disable the alarm interrupt, for RTCs that support
alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enabling on/off

Enable or disable the interrupt on every clock update, for
RTCs that support this once-per-second interrupt.  The third
ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enabling on/off

Enable or disable the periodic interrupt, for RTCs that sup‐
port these periodic interrupts.  The third ioctl's argument
is ignored.  Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can enable the periodic interrupt
if the frequency is currently set above the value specified in
/proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enabling on/off

Enable or disable the Watchdog interrupt, for RTCs that sup-
port this Watchdog interrupt. The third ioctl's argument is
ignored.

Implementation notes:

Since all of involved ioctls have NULL as their third argument,
their implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_GINFO - Getting information about specified timer

Read information about the specified timer. The information about the
timer is returned in the following structure:

struct snd_timer_ginfo {
struct snd_timer_id tid;  /* requested timer ID */
unsigned int flags;   /* timer flags - SNDRV_TIMER_FLG_* */
int card; /* card number */
unsigned char id[64]; /* timer identification */
unsigned char name[80];   /* timer name */
unsigned long reserved0;  /* reserved for future use */
unsigned long resolution; /* average period resolution in ns */
unsigned long resolution_min; /* minimal period resolution in ns */
unsigned long resolution_max; /* maximal period resolution in ns */
unsigned int clients; /* active timer clients */
unsigned char reserved[32];   /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which information is to be obtained. After the
ioctl call, the rest of the structure fields are filled with values from
the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

SNDRV_TIMER_IOCTL_GPARAMS - Setting precise period duration

Sets timer precise period duration numerator and denominator in seconds. The
period duration is set in the following structure:

struct snd_timer_gparams {
struct snd_timer_id tid;/* requested timer ID */
unsigned long period_num;   /* period duration - numerator */
unsigned long period_den;   /* period duration - denominator */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period duration is to be set. Also, the
fileds "period_num" and "period_den" should be filled with the period
duration numerator and denominator values that are to be set respectively.
If there is no device with the specified id, the error ENODEV ("No such
device") is returned.

SNDRV_TIMER_IOCTL_GSTATUS - Getting current period resolution

Read timer current period resolution in nanoseconds and period resolution
numerator and denominator in seconds. The period resolution information is
returned in the following structure:

struct snd_timer_gstatus {
struct snd_timer_id tid;/* requested timer ID */
unsigned long resolution;   /* current period resolution in ns */
unsigned long resolution_num;   /* period resolution - numerator */
unsigned long resolution_den;   /* period resolution - denominator */
unsigned char reserved[32]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period resolution is to be obtained. After
the ioctl call, the rest of the structure fields are filled with values
from the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure as their
third argument. That is the reason why corresponding definitions were added
in 'linux-user/syscall_types.h'. All of these strcutures have some fields
that are of type 'unsigned long'. That is the reason why separate target
structures were defined in 'linux-user/syscall_defs.h'. Also, all of the
structures have a field with type 'struct snd_timer_id' which is the reason
why a separate target structure 'struct target_snd_timer_id' was also
defined. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  6 ++
 linux-user/syscall_defs.h  | 43 +++
 linux-user/syscall_types.h | 26 ++
 3 files changed, 75 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 9106773..989eb9b 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -453,6 +453,12 @@
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
   IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(T

[PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector using ioctls

2020-01-09 Thread Filip Bozuta
RTC_VL_READ - Read voltage low detection information

Read the voltage low for RTCs that support voltage low.
The third ioctl's' argument points to an int in which
the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

Clear the information about voltage low for RTCs that
support voltage low. The third ioctl(2) argument is
ignored.

Implementation notes:

Since one ioctl has a pointer to 'int' as its third agrument,
and another ioctl has NULL as its third argument, their
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 0a4e3f1..1f1f3e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_PLL_GET - Getting PLL correction

Read the PLL correction for RTCs that support PLL. The PLL correction
is returned in the following structure:

struct rtc_pll_info {
int pll_ctrl;/* placeholder for fancier control */
int pll_value;   /* get/set correction value */
int pll_max; /* max +ve (faster) adjustment value */
int pll_min; /* max -ve (slower) adjustment value */
int pll_posmult; /* factor for +ve correction */
int pll_negmult; /* factor for -ve correction */
long pll_clock;  /* base PLL frequency */
};

A pointer to this structure should be passed as the third
ioctl's argument.

RTC_PLL_SET - Setting PLL correction

Sets the PLL correction for RTCs that support PLL. The PLL correction
that is set is specified by the rtc_pll_info structure pointed to by
the third ioctl's' argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure rtc_pll_info
as their third argument. All elements of this structure are of
type 'int', except the last one that is of type 'long'. That is
the reason why a separate target structure (target_rtc_pll_info)
is defined in linux-user/syscall_defs. The rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index b09396e..0a4e3f1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctl:

SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read

Sets enhanced time read which is used for reading time with timestamps
and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
reading is set if the third argument is different than 0, otherwise normal
time reading is set.

Implementation notes:

Because the implemented ioctl has 'int' as its third argument, the
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index ed1bd4c..9106773 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -452,6 +452,7 @@
   IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+  IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(TYPE_INT))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7409021..8d505c1 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2429,6 +2429,7 @@ struct target_statfs64 {
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
   struct snd_timer_id)
+#define TARGET_SNDRV_TIMER_IOCTL_TREADTARGET_IOW('T', 0x02, int)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl

2020-01-09 Thread Filip Bozuta
This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_SELECT - Selecting timer

Selects the timer which id is specified. The timer id is specified in the
following strcuture:

struct snd_timer_select {
struct snd_timer_id id; /* timer ID */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which is to be selected. If there is no timer
device with the specified id, the error ENODEV ("No such device") is
returned.

Implementation notes:

Ioctl implemented in this patch has a pointer to a
'struct snd_timer_select' as its third argument.
That is the reason why a corresponding definition
was added in 'linux-user/syscall_types.h'. The rest
of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 7 +++
 linux-user/syscall_types.h | 4 
 3 files changed, 13 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 989eb9b..7652117 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -459,6 +459,8 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gparams)))
   IOCTL(SNDRV_TIMER_IOCTL_GSTATUS, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
+  IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 4d4dad3..9a33b71 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2462,6 +2462,11 @@ struct target_snd_timer_gstatus {
 unsigned char reserved[32];
 };
 
+struct target_snd_timer_select {
+struct target_snd_timer_id id;
+unsigned char reserved[32];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
@@ -2473,6 +2478,8 @@ struct target_snd_timer_gstatus {
  struct 
target_snd_timer_gparams)
 #define TARGET_SNDRV_TIMER_IOCTL_GSTATUS  TARGET_IOWR('T', 0x05,   
  \
   struct 
target_snd_timer_gstatus)
+#define TARGET_SNDRV_TIMER_IOCTL_SELECT   TARGET_IOW('T', 0x10,
  \
+ struct 
target_snd_timer_select)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e90716..767632d 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -116,6 +116,10 @@ STRUCT(snd_timer_gstatus,
TYPE_ULONG, /* resolution_den */
MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
 
+STRUCT(snd_timer_select,
+   MK_STRUCT(STRUCT_snd_timer_id), /* id */
+   MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




[PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls

2020-01-09 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_INFO - Getting information about selected timer

Read information about the selected timer. The information is returned in
the following structure:

struct snd_timer_info {
unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */
int card;   /* card number */
unsigned char id[64];   /* timer identificator */
unsigned char name[80]; /* timer name */
unsigned long reserved0;/* reserved for future use */
unsigned long resolution;   /* average period resolution in ns */
unsigned char reserved[64]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which information is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_PARAMS - Setting parameters for selected timer

Sets parameters for the selected timer. The paramaters are set in the
following structure:

struct snd_timer_params {
unsigned int flags; /* flags - SNDRV_TIMER_PSFLG_* */
unsigned int ticks; /* requested resolution in ticks */
unsigned int queue_size;/* total size of queue (32-1024) */
unsigned int reserved0; /* reserved, was: failure locations */
unsigned int filter;/* event filter */
unsigned char reserved[60]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which parameters are to be set. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_STATUS - Getting status of selected timer

Read status of the selected timer. The status of the timer is returned in
the following structure:

struct snd_timer_status {
struct timespec tstamp; /* Timestamp - last update */
unsigned int resolution;/* current period resolution in ns */
unsigned int lost;  /* counter of master tick lost */
unsigned int overrun;   /* count of read queue overruns */
unsigned int queue; /* used queue size */
unsigned char reserved[64]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which status is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure
as their third argument. That is the reason why corresponding
definitions were added in 'linux-user/syscall_types.h'. Structure
'snd_timer_status' has field of type 'struct timespec' which is why
a corresponding definition of that structure was also added in
'linux-user/syscall_types.h'. All of these strucutures have some
fields that are of type 'unsigned long'. That is the reason why
separate target structures were defined in 'linux-user/syscall_defs.h'.
Structure 'struct timespec' already had a separate target definition
so that definition was used to define a target structure for
'snd_timer_status'. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  5 +
 linux-user/syscall_defs.h  | 25 +
 linux-user/syscall_types.h | 29 +
 3 files changed, 59 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7652117..43e7e5d 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -461,6 +461,11 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
   IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
+  IOCTL(SNDRV_TIMER_IOCTL_INFO, IOC_R, 
MK_PTR(MK_STRUCT(STRUCT_snd_timer_info)))
+  IOCTL(SNDRV_TIMER_IOCTL_PARAMS, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
+  IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 9a33b71..d76124d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2467,6 +2467,25 @@ struct target_snd_timer_select {
 

[PATCH 01/12] linux-user: Add support for enabling/disabling RTC features using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enabling on/off

Enable or disable the alarm interrupt, for RTCs that support
alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enabling on/off

Enable or disable the interrupt on every clock update, for
RTCs that support this once-per-second interrupt. The third
ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enabling on/off

Enable or disable the periodic interrupt, for RTCs that sup‐
port these periodic interrupts. The third ioctl's argument
is ignored. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can enable the periodic interrupt
if the frequency is currently set above the value specified in
/proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enabling on/off

Enable or disable the Watchdog interrupt, for RTCs that sup-
port this Watchdog interrupt. The third ioctl's argument is
ignored.

Implementation notes:

Since all of involved ioctls have NULL as their third argument,
their implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH 07/12] linux-user: Add support for getting alsa timer version and id

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_PVERSION - Getting the sound timer version

Read the sound timer version. The third ioctl's argument is
a pointer to an int in which the specified timers version
is returned.

SNDRV_TIMER_IOCTL_NEXT_DEVICE - Getting id information about next timer

Read id information about the next timer device from the sound timer
device list. The id infomration is returned in the following structure:

struct snd_timer_id {
int dev_class;/* timer device class number */
int dev_sclass;   /* slave device class number (unused) */
int card; /* card number */
int device;   /* device number */
int subdevice;/* sub-device number */
};

The devices in the sound timer device list are arranged by the fields
of this structure respectively (first by dev_class number, then by
card number, ...). A pointer to this structure should be passed as
the third ioctl's argument. Before calling the ioctl, the parameters
of this structure should be initialized in relation to the next timer
device which information is to be obtained. For example, if a wanted
timer device has the device class number equal to or bigger then 2,
the field dev_class should be initialized to 2. After the ioctl call,
the structure fields are filled with values from the next device in
the sound timer device list. If there is no next device in the list,
the structure is filled with "zero" id values (in that case all
fields are filled with value -1).

Implementation notes:

The ioctl 'SNDRV_TIMER_IOCTL_NEXT_DEVICE' has a pointer to a
'struct snd_timer_id' as its third argument. That is the reason why
corresponding definition is added in 'linux-user/syscall_types.h'.
Since all elements of this structure are of type 'int', the rest of
the implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
    worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 4 
 linux-user/syscall.c   | 1 +
 linux-user/syscall_defs.h  | 5 +
 linux-user/syscall_types.h | 7 +++
 4 files changed, 17 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 1f1f3e6..ed1bd4c 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -449,6 +449,10 @@
   IOCTL(SOUND_MIXER_WRITE_LOUD, IOC_W, MK_PTR(TYPE_INT))
   IOCTL(SOUND_MIXER_WRITE_RECSRC, IOC_W, MK_PTR(TYPE_INT))
 
+  IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
+  IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(HDIO_GET_MULTCOUNT, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c0b7314..022d064 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -108,6 +108,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index af4f366..7409021 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2425,6 +2425,11 @@ struct target_statfs64 {
 
 #define TARGET_SOUND_MIXER_WRITE_RECSRC
TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
 
+/* alsa timer ioctls */
+#define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
+#define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
+  struct snd_timer_id)
+
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4027272..2f4cd78 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -83,6 +83,13 @@ STRUCT(buffmem_desc,
 STRUCT(mixer_info,
MK_ARRAY(TYPE_CHAR, 16), MK_ARRAY(TYPE_CHAR, 32), TYPE_INT, 
MK_ARRAY(TYPE_INT, 10))
 
+STRUCT(snd_timer_id,
+   TYPE_INT, /* dev_class */
+   TYPE_INT, /* dev_sclass */
+   TYPE_INT, /* card */
+   TYPE_INT, /* device */
+   TYPE_INT) /* subdevice */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




[PATCH 05/12] linux-user: Add support for getting/setting RTC PLL correction using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_PLL_GET - Getting PLL correction

Read the PLL correction for RTCs that support PLL. The PLL correction
is returned in the following structure:

struct rtc_pll_info {
int pll_ctrl;/* placeholder for fancier control */
int pll_value;   /* get/set correction value */
int pll_max; /* max +ve (faster) adjustment value */
int pll_min; /* max -ve (slower) adjustment value */
int pll_posmult; /* factor for +ve correction */
int pll_negmult; /* factor for -ve correction */
long pll_clock;  /* base PLL frequency */
};

A pointer to this structure should be passed as the third
ioctl's argument.

RTC_PLL_SET - Setting PLL correction

Sets the PLL correction for RTCs that support PLL. The PLL correction
that is set is specified by the rtc_pll_info structure pointed to by
the third ioctl's' argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure rtc_pll_info
as their third argument. All elements of this structure are of
type 'int', except the last one that is of type 'long'. That is
the reason why a separate target structure (target_rtc_pll_info)
is defined in linux-user/syscall_defs. The rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index b09396e..0a4e3f1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 03/12] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts. The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests. The third ioctl's argument is an
unsigned long * or an unsigned long, respectively. The value
is the frequency in interrupts per second. The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq. (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number. In
both cases, the number is interpreted relative to this RTC's
Epoch. The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year. With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively. The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch. To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.
Because ioctls RTC_IRQP_SET and RTC_EPOCH_SET are ioctls of
type IOW(writing type) that have unsigned long as their
third argument, a case statement for "TYPE_ULONG" was added
in the appropriate place for function "abi_ulong do_ioctl"
in file "syscall.c". There were no implemented ioctls of
type IOW with unsigned long as third argument before this
patch, which is the reason why this case statement was added
now for the first time.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall.c  | 1 +
 linux-user/syscall_defs.h | 4 
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 74c3c08..c0b7314 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5175,6 +5175,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
 break;
 case TYPE_PTRVOID:
 case TYPE_INT:
+case TYPE_ULONG:
 ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
 break;
 case TYPE_PTR:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH 04/12] linux-user: Add support for getting/setting RTC wakeup alarm using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Getting/Setting wakeup alarm

Some RTCs support a more powerful alarm interface, using these
ioctls to read or write the RTC's alarm time (respectively)
with this structure:

struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};

The enabled flag is used to enable or disable the alarm
interrupt, or to read its current status; when using these
calls, RTC_AIE_ON and RTC_AIE_OFF are not used. The pending
flag is used by RTC_WKALM_RD to report a pending interrupt
(so it's mostly useless on Linux, except when talking to the
RTC managed by EFI firmware). The time field is as used with
RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
and tm_year fields are also valid. A pointer to this structure
should be passed as the third ioctl's argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure
rtc_wkalrm as their third argument. That is the reason why
corresponding definition is added in linux-user/syscall_types.h.
Since all  elements of this structure are either of type
'unsigned char' or 'struct rtc_time' (that was covered in one
of previous patches), the rest of the implementation is
    straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index accbdee..b09396e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 11/12] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_INFO - Getting information about selected timer

Read information about the selected timer. The information is returned in
the following structure:

struct snd_timer_info {
unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */
int card;   /* card number */
unsigned char id[64];   /* timer identificator */
unsigned char name[80]; /* timer name */
unsigned long reserved0;/* reserved for future use */
unsigned long resolution;   /* average period resolution in ns */
unsigned char reserved[64]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which information is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_PARAMS - Setting parameters for selected timer

Sets parameters for the selected timer. The paramaters are set in the
following structure:

struct snd_timer_params {
unsigned int flags; /* flags - SNDRV_TIMER_PSFLG_* */
unsigned int ticks; /* requested resolution in ticks */
unsigned int queue_size;/* total size of queue (32-1024) */
unsigned int reserved0; /* reserved, was: failure locations */
unsigned int filter;/* event filter */
unsigned char reserved[60]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which parameters are to be set. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_STATUS - Getting status of selected timer

Read status of the selected timer. The status of the timer is returned in
the following structure:

struct snd_timer_status {
struct timespec tstamp; /* Timestamp - last update */
unsigned int resolution;/* current period resolution in ns */
unsigned int lost;  /* counter of master tick lost */
unsigned int overrun;   /* count of read queue overruns */
unsigned int queue; /* used queue size */
unsigned char reserved[64]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which status is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure
as their third argument. That is the reason why corresponding
definitions were added in 'linux-user/syscall_types.h'. Structure
'snd_timer_status' has field of type 'struct timespec' which is why
a corresponding definition of that structure was also added in
'linux-user/syscall_types.h'. All of these strucutures have some
fields that are of type 'unsigned long'. That is the reason why
separate target structures were defined in 'linux-user/syscall_defs.h'.
Structure 'struct timespec' already had a separate target definition
so that definition was used to define a target structure for
'snd_timer_status'. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  5 +
 linux-user/syscall_defs.h  | 25 +
 linux-user/syscall_types.h | 29 +
 3 files changed, 59 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7652117..43e7e5d 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -461,6 +461,11 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
   IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
+  IOCTL(SNDRV_TIMER_IOCTL_INFO, IOC_R, 
MK_PTR(MK_STRUCT(STRUCT_snd_timer_info)))
+  IOCTL(SNDRV_TIMER_IOCTL_PARAMS, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
+  IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 9a33b71..d76124d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2467,6 +2467,25 @@ struct target_snd_timer_select {
 

[PATCH 00/12] linux-user: Add support for real time clock and

2020-01-15 Thread Filip Bozuta
t programs were written to test further functionalities
of individual ioctls. Those programs were, like the file "timer.c",
compiled for different architectures and were executed both natively
and thgrough QEMU to compare the results.

Example of a test program:

For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:

#include 
#include 
#include 
#include 
#include 
#include 

#define ERROR -1

int main()
{
int fd = open("/dev/snd/timer", O_RDWR);

if(fd == ERROR)
{
perror("open");
return -1;
}

struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
  SNDRV_TIMER_SCLASS_NONE, -1, 
  SNDRV_TIMER_GLOBAL_SYSTEM, 0};

struct snd_timer_ginfo ginfo;
ginfo.tid = id;

if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
{
perror("ioctl");
return -1;
}

printf("flags: %u\n", ginfo.flags);
printf("card: %d\n", ginfo.card);
printf("id: %s\n", ginfo.id);
printf("name: %s\n", ginfo.name);
printf("reserved0: %lu\n", ginfo.reserved0);
printf("resolution: %lu\n", ginfo.resolution);
printf("resolution_min: %lu\n", ginfo.resolution_min);
printf("reolution_max: %lu\n", ginfo.resolution_max);
printf("clients: %u\n", ginfo.clients);
printf("reserved: %s\n", ginfo.reserved);

return 0;
}

v6:

* fixed one patch by adding a case statement for 'unsigned long'
  to recognize two ioctls that are implemented in that patch

* changed patch descriptions a little bit so that they are more
  comprehensible

v5:

* added support for alsa sound timer ioctls

v4:

* changed patch descriptions so that they are better
  formatted and more comprehensible

v3:

* changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

* added description of each ioctl in patches
* wrote a more detailed cover letter with description of testing
* changed one instance of TYPE_INT to MK_PTR(TYPE_INT)

Filip Bozuta (12):
  linux-user: Add support for enabling/disabling RTC features using
ioctls
  linux-user: Add support for getting/setting RTC time and alarm using
ioctls
  linux-user: Add support for getting/setting RTC periodic interrupt and
epoch using ioctls
  linux-user: Add support for getting/setting RTC wakeup alarm using
ioctls
  linux-user: Add support for getting/setting RTC PLL correction using
ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
ioctls
  linux-user: Add support for getting alsa timer version and id
  linux-user: Add support for setting alsa timer enhanced read using
ioctl
  linux-user: Add support for getting/setting specified alsa timer
parameters using ioctls
  linux-user: Add support for selecting alsa timer using ioctl
  linux-user: Add support for getting/setting selected alsa timer
parameters using ioctls
  linux-user: Add support for selected alsa timer instructions using
ioctls

 linux-user/ioctls.h|  45 +
 linux-user/syscall.c   |   3 ++
 linux-user/syscall_defs.h  | 121 +
 linux-user/syscall_types.h |  91 ++
 4 files changed, 260 insertions(+)

-- 
2.7.4




[PATCH 06/12] linux-user: Add support for read/clear RTC voltage low detector using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_VL_READ - Read voltage low detection information

Read the voltage low for RTCs that support voltage low.
The third ioctl's' argument points to an int in which
the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

Clear the information about voltage low for RTCs that
support voltage low. The third ioctl(2) argument is
ignored.

Implementation notes:

Since one ioctl has a pointer to 'int' as its third agrument,
and another ioctl has NULL as its third argument, their
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 0a4e3f1..1f1f3e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH 10/12] linux-user: Add support for selecting alsa timer using ioctl

2020-01-15 Thread Filip Bozuta
This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_SELECT - Selecting timer

Selects the timer which id is specified. The timer id is specified in the
following strcuture:

struct snd_timer_select {
struct snd_timer_id id; /* timer ID */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which is to be selected. If there is no timer
device with the specified id, the error ENODEV ("No such device") is
returned.

Implementation notes:

Ioctl implemented in this patch has a pointer to a
'struct snd_timer_select' as its third argument.
That is the reason why a corresponding definition
was added in 'linux-user/syscall_types.h'. The rest
of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 7 +++
 linux-user/syscall_types.h | 4 
 3 files changed, 13 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 989eb9b..7652117 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -459,6 +459,8 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gparams)))
   IOCTL(SNDRV_TIMER_IOCTL_GSTATUS, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
+  IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 4d4dad3..9a33b71 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2462,6 +2462,11 @@ struct target_snd_timer_gstatus {
 unsigned char reserved[32];
 };
 
+struct target_snd_timer_select {
+struct target_snd_timer_id id;
+unsigned char reserved[32];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
@@ -2473,6 +2478,8 @@ struct target_snd_timer_gstatus {
  struct 
target_snd_timer_gparams)
 #define TARGET_SNDRV_TIMER_IOCTL_GSTATUS  TARGET_IOWR('T', 0x05,   
  \
   struct 
target_snd_timer_gstatus)
+#define TARGET_SNDRV_TIMER_IOCTL_SELECT   TARGET_IOW('T', 0x10,
  \
+ struct 
target_snd_timer_select)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e90716..767632d 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -116,6 +116,10 @@ STRUCT(snd_timer_gstatus,
TYPE_ULONG, /* resolution_den */
MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
 
+STRUCT(snd_timer_select,
+   MK_STRUCT(STRUCT_snd_timer_id), /* id */
+   MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




[PATCH 02/12] linux-user: Add support for getting/setting RTC time and alarm using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_RD_TIME - Getting RTC time

Returns this RTC's time in the following structure:

struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};

The fields in this structure have the same meaning and ranges
as the tm structure described in gmtime man page. A pointer
to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Setting RTC time

Sets this RTC's time to the time specified by the rtc_time
structure pointed to by the third ioctl's argument. To set
the RTC's time the process must be privileged (i.e., have the
CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Getting/Setting alarm time

Read and set the alarm time, for RTCs that support alarms.
The alarm interrupt must be separately enabled or disabled
using the RTC_AIE_ON, RTC_AIE_OFF requests. The third
ioctl's argument is a pointer to a rtc_time structure. Only
the tm_sec, tm_min, and tm_hour fields of this structure are
used.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_time
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are of type 'int', the rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl

2020-01-15 Thread Filip Bozuta
This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read

Sets enhanced time read which is used for reading time with timestamps
and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
reading is set if the third argument is different than 0, otherwise normal
time reading is set.

Implementation notes:

Because the implemented ioctl has 'int' as its third argument, the
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index ed1bd4c..9106773 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -452,6 +452,7 @@
   IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+  IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(TYPE_INT))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7409021..8d505c1 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2429,6 +2429,7 @@ struct target_statfs64 {
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
  \
   struct snd_timer_id)
+#define TARGET_SNDRV_TIMER_IOCTL_TREADTARGET_IOW('T', 0x02, int)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH 09/12] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_GINFO - Getting information about specified timer

Read information about the specified timer. The information about the
timer is returned in the following structure:

struct snd_timer_ginfo {
struct snd_timer_id tid;  /* requested timer ID */
unsigned int flags;   /* timer flags - SNDRV_TIMER_FLG_* */
int card; /* card number */
unsigned char id[64]; /* timer identification */
unsigned char name[80];   /* timer name */
unsigned long reserved0;  /* reserved for future use */
unsigned long resolution; /* average period resolution in ns */
unsigned long resolution_min; /* minimal period resolution in ns */
unsigned long resolution_max; /* maximal period resolution in ns */
unsigned int clients; /* active timer clients */
unsigned char reserved[32];   /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which information is to be obtained. After the
ioctl call, the rest of the structure fields are filled with values from
the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

SNDRV_TIMER_IOCTL_GPARAMS - Setting precise period duration

Sets timer precise period duration numerator and denominator in seconds. The
period duration is set in the following structure:

struct snd_timer_gparams {
struct snd_timer_id tid;/* requested timer ID */
unsigned long period_num;   /* period duration - numerator */
unsigned long period_den;   /* period duration - denominator */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period duration is to be set. Also, the
fileds "period_num" and "period_den" should be filled with the period
duration numerator and denominator values that are to be set respectively.
If there is no device with the specified id, the error ENODEV ("No such
device") is returned.

SNDRV_TIMER_IOCTL_GSTATUS - Getting current period resolution

Read timer current period resolution in nanoseconds and period resolution
numerator and denominator in seconds. The period resolution information is
returned in the following structure:

struct snd_timer_gstatus {
struct snd_timer_id tid;/* requested timer ID */
unsigned long resolution;   /* current period resolution in ns */
unsigned long resolution_num;   /* period resolution - numerator */
unsigned long resolution_den;   /* period resolution - denominator */
unsigned char reserved[32]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period resolution is to be obtained. After
the ioctl call, the rest of the structure fields are filled with values
from the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure as their
third argument. That is the reason why corresponding definitions were added
in 'linux-user/syscall_types.h'. All of these strcutures have some fields
that are of type 'unsigned long'. That is the reason why separate target
structures were defined in 'linux-user/syscall_defs.h'. Also, all of the
structures have a field with type 'struct snd_timer_id' which is the reason
why a separate target structure 'struct target_snd_timer_id' was also
defined. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  6 ++
 linux-user/syscall_defs.h  | 43 +++
 linux-user/syscall_types.h | 26 ++
 3 files changed, 75 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 9106773..989eb9b 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -453,6 +453,12 @@
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
   IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(T

[PATCH 12/12] linux-user: Add support for selected alsa timer instructions using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_START - Start selected alsa timer

Starts the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be started. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_STOP - Stop selected alsa timer

Stops the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be stopped. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_CONTINUE - Continue selected alsa timer

Continues the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be continued. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_PAUSE - Pause selected alsa timer

Pauses the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be paused. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

Implementation notes:

Since all of the implemented ioctls have NULL as their third argument,
their implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 43e7e5d..75a2f0e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -466,6 +466,10 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
   IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
+  IOCTL(SNDRV_TIMER_IOCTL_START, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_STOP, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_CONTINUE, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_PAUSE, 0, TYPE_NULL)
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d76124d..311aec0 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2505,6 +2505,10 @@ struct target_snd_timer_status {
  struct 
snd_timer_params)
 #define TARGET_SNDRV_TIMER_IOCTL_STATUS   TARGET_IOR('T', 0x14,
  \
  struct 
target_snd_timer_status)
+#define TARGET_SNDRV_TIMER_IOCTL_STARTTARGET_IO('T', 0xa0)
+#define TARGET_SNDRV_TIMER_IOCTL_STOP TARGET_IO('T', 0xa1)
+#define TARGET_SNDRV_TIMER_IOCTL_CONTINUE TARGET_IO('T', 0xa2)
+#define TARGET_SNDRV_TIMER_IOCTL_PAUSETARGET_IO('T', 0xa3)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH v7 02/13] linux-user: Add support for getting/setting RTC time and alarm using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_RD_TIME - Getting RTC time

Returns this RTC's time in the following structure:

struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};

The fields in this structure have the same meaning and ranges
as the tm structure described in gmtime man page. A pointer
to this structure should be passed as the third ioctl's argument.

RTC_SET_TIME - Setting RTC time

Sets this RTC's time to the time specified by the rtc_time
structure pointed to by the third ioctl's argument. To set
the RTC's time the process must be privileged (i.e., have the
CAP_SYS_TIME capability).

RTC_ALM_READ, RTC_ALM_SET - Getting/Setting alarm time

Read and set the alarm time, for RTCs that support alarms.
The alarm interrupt must be separately enabled or disabled
using the RTC_AIE_ON, RTC_AIE_OFF requests. The third
ioctl's argument is a pointer to a rtc_time structure. Only
the tm_sec, tm_min, and tm_hour fields of this structure are
used.

Implementation notes:

All ioctls in this patch have pointer to a structure rtc_time
as their third argument. That is the reason why corresponding
definition is added in linux-user/syscall_types.h. Since all
elements of this structure are of type 'int', the rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  4 
 linux-user/syscall_defs.h  |  4 
 linux-user/syscall_types.h | 11 +++
 3 files changed, 19 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 97741c7..f472794 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -77,6 +77,10 @@
  IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
  IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
  IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_ALM_READ, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f91579a..f0bf09d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -772,6 +772,10 @@ struct target_pollfd {
 #define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
 #define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
 #define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+#define TARGET_RTC_ALM_READ TARGET_IOR('p', 0x08, struct rtc_time)
+#define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
+#define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
+#define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e36983..a35072a 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -255,6 +255,17 @@ STRUCT(blkpg_partition,
MK_ARRAY(TYPE_CHAR, BLKPG_DEVNAMELTH), /* devname */
MK_ARRAY(TYPE_CHAR, BLKPG_VOLNAMELTH)) /* volname */
 
+STRUCT(rtc_time,
+   TYPE_INT, /* tm_sec */
+   TYPE_INT, /* tm_min */
+   TYPE_INT, /* tm_hour */
+   TYPE_INT, /* tm_mday */
+   TYPE_INT, /* tm_mon */
+   TYPE_INT, /* tm_year */
+   TYPE_INT, /* tm_wday */
+   TYPE_INT, /* tm_yday */
+   TYPE_INT) /* tm_isdst */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v7 08/13] linux-user: Add support for setting alsa timer enhanced read using ioctl

2020-01-15 Thread Filip Bozuta
This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read

Sets enhanced time read which is used for reading time with timestamps
and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
reading is set if the third argument is different than 0, otherwise normal
time reading is set.

Implementation notes:

Because the implemented ioctl has 'int' as its third argument, the
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index ed1bd4c..9106773 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -452,6 +452,7 @@
   IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+  IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(TYPE_INT))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7ceb6f8..0971623 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2429,6 +2429,7 @@ struct target_statfs64 {
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
\
 struct snd_timer_id)
+#define TARGET_SNDRV_TIMER_IOCTL_TREADTARGET_IOW('T', 0x02, int)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH v7 03/13] linux-user: Add support for getting/setting RTC periodic interrupt and epoch using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_IRQP_READ, RTC_IRQP_SET - Getting/Setting IRQ rate

Read and set the frequency for periodic interrupts, for RTCs
that support periodic interrupts. The periodic interrupt must
be separately enabled or disabled using the RTC_PIE_ON,
RTC_PIE_OFF requests. The third ioctl's argument is an
unsigned long * or an unsigned long, respectively. The value
is the frequency in interrupts per second. The set of allow‐
able frequencies is the multiples of two in the range 2 to
8192. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can set frequencies above the
value specified in /proc/sys/dev/rtc/max-user-freq. (This
file contains the value 64 by default.)

RTC_EPOCH_READ, RTC_EPOCH_SET - Getting/Setting epoch

Many RTCs encode the year in an 8-bit register which is either
interpreted as an 8-bit binary number or as a BCD number. In
both cases, the number is interpreted relative to this RTC's
Epoch. The RTC's Epoch is initialized to 1900 on most systems
but on Alpha and MIPS it might also be initialized to 1952,
1980, or 2000, depending on the value of an RTC register for
the year. With some RTCs, these operations can be used to
read or to set the RTC's Epoch, respectively. The third
ioctl's argument is an unsigned long * or an unsigned long,
respectively, and the value returned (or assigned) is the
Epoch. To set the RTC's Epoch the process must be privileged
(i.e., have the CAP_SYS_TIME capability).

Implementation notes:

All ioctls in this patch have a pointer to 'ulong' as their
third argument. That is the reason why corresponding parts
of added code in linux-user/syscall_defs.h contain special
handling related to 'ulong' type: they use 'abi_ulong' type
to make sure that ioctl's code is calculated correctly for
both 32-bit and 64-bit targets. Also, 'MK_PTR(TYPE_ULONG)'
is used for the similar reason in linux-user/ioctls.h.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f472794..accbdee 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -81,6 +81,10 @@
  IOCTL(RTC_ALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_RD_TIME, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
  IOCTL(RTC_SET_TIME, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_time)))
+ IOCTL(RTC_IRQP_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
+ IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index f0bf09d..bbfa935 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -776,6 +776,10 @@ struct target_pollfd {
 #define TARGET_RTC_ALM_SET  TARGET_IOW('p', 0x07, struct rtc_time)
 #define TARGET_RTC_RD_TIME  TARGET_IOR('p', 0x09, struct rtc_time)
 #define TARGET_RTC_SET_TIME TARGET_IOW('p', 0x0a, struct rtc_time)
+#define TARGET_RTC_IRQP_READTARGET_IOR('p', 0x0b, abi_ulong)
+#define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
+#define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
+#define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v7 01/13] linux-user: Add support for enabling/disabling RTC features using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_AIE_ON, RTC_AIE_OFF - Alarm interrupt enabling on/off

Enable or disable the alarm interrupt, for RTCs that support
alarms.  The third ioctl's argument is ignored.

RTC_UIE_ON, RTC_UIE_OFF - Update interrupt enabling on/off

Enable or disable the interrupt on every clock update, for
RTCs that support this once-per-second interrupt. The third
ioctl's argument is ignored.

RTC_PIE_ON, RTC_PIE_OFF - Periodic interrupt enabling on/off

Enable or disable the periodic interrupt, for RTCs that sup‐
port these periodic interrupts. The third ioctl's argument
is ignored. Only a privileged process (i.e., one having the
CAP_SYS_RESOURCE capability) can enable the periodic interrupt
if the frequency is currently set above the value specified in
/proc/sys/dev/rtc/max-user-freq.

RTC_WIE_ON, RTC_WIE_OFF - Watchdog interrupt enabling on/off

Enable or disable the Watchdog interrupt, for RTCs that sup-
port this Watchdog interrupt. The third ioctl's argument is
ignored.

Implementation notes:

Since all of involved ioctls have NULL as their third argument,
their implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   |  9 +
 linux-user/syscall.c  |  1 +
 linux-user/syscall_defs.h | 10 ++
 3 files changed, 20 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index c6b9d6a..97741c7 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -69,6 +69,15 @@
  IOCTL(KDSETLED, 0, TYPE_INT)
  IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
+ IOCTL(RTC_AIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_AIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_UIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_PIE_OFF, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_ON, 0, TYPE_NULL)
+ IOCTL(RTC_WIE_OFF, 0, TYPE_NULL)
+
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(BLKRRPART, 0, TYPE_NULL)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ce399a5..74c3c08 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -107,6 +107,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 98c2119..f91579a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+/* real time clock ioctls */
+#define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
+#define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
+#define TARGET_RTC_UIE_ON   TARGET_IO('p', 0x03)
+#define TARGET_RTC_UIE_OFF  TARGET_IO('p', 0x04)
+#define TARGET_RTC_PIE_ON   TARGET_IO('p', 0x05)
+#define TARGET_RTC_PIE_OFF  TARGET_IO('p', 0x06)
+#define TARGET_RTC_WIE_ON   TARGET_IO('p', 0x0f)
+#define TARGET_RTC_WIE_OFF  TARGET_IO('p', 0x10)
+
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
 #define TARGET_FIOGETOWN   TARGET_IOR('f', 123, int)
-- 
2.7.4




[PATCH v7 07/13] linux-user: Add support for getting alsa timer version and id

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_PVERSION - Getting the sound timer version

Read the sound timer version. The third ioctl's argument is
a pointer to an int in which the specified timers version
is returned.

SNDRV_TIMER_IOCTL_NEXT_DEVICE - Getting id information about next timer

Read id information about the next timer device from the sound timer
device list. The id infomration is returned in the following structure:

struct snd_timer_id {
int dev_class;/* timer device class number */
int dev_sclass;   /* slave device class number (unused) */
int card; /* card number */
int device;   /* device number */
int subdevice;/* sub-device number */
};

The devices in the sound timer device list are arranged by the fields
of this structure respectively (first by dev_class number, then by
card number, ...). A pointer to this structure should be passed as
the third ioctl's argument. Before calling the ioctl, the parameters
of this structure should be initialized in relation to the next timer
device which information is to be obtained. For example, if a wanted
timer device has the device class number equal to or bigger then 2,
the field dev_class should be initialized to 2. After the ioctl call,
the structure fields are filled with values from the next device in
the sound timer device list. If there is no next device in the list,
the structure is filled with "zero" id values (in that case all
fields are filled with value -1).

Implementation notes:

The ioctl 'SNDRV_TIMER_IOCTL_NEXT_DEVICE' has a pointer to a
'struct snd_timer_id' as its third argument. That is the reason why
corresponding definition is added in 'linux-user/syscall_types.h'.
Since all elements of this structure are of type 'int', the rest of
the implementation was straightforward.

The line '#include ' was added to recognize
preprocessor definitions for these ioctls. This needs to be
done only once in this series of commits. Also, the content
of this file (with respect to ioctl definitions) remained
unchanged for a long time, therefore there is no need to
    worry about supporting older Linux kernel version.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 4 
 linux-user/syscall.c   | 1 +
 linux-user/syscall_defs.h  | 5 +
 linux-user/syscall_types.h | 7 +++
 4 files changed, 17 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 1f1f3e6..ed1bd4c 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -449,6 +449,10 @@
   IOCTL(SOUND_MIXER_WRITE_LOUD, IOC_W, MK_PTR(TYPE_INT))
   IOCTL(SOUND_MIXER_WRITE_RECSRC, IOC_W, MK_PTR(TYPE_INT))
 
+  IOCTL(SNDRV_TIMER_IOCTL_PVERSION, IOC_R, MK_PTR(TYPE_INT))
+  IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
+
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
   IOCTL(HDIO_GET_MULTCOUNT, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 74c3c08..a3993a2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -108,6 +108,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "uname.h"
 
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index af4f366..7ceb6f8 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2425,6 +2425,11 @@ struct target_statfs64 {
 
 #define TARGET_SOUND_MIXER_WRITE_RECSRC
TARGET_MIXER_WRITE(SOUND_MIXER_RECSRC)
 
+/* alsa timer ioctls */
+#define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
+#define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
\
+struct snd_timer_id)
+
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4027272..2f4cd78 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -83,6 +83,13 @@ STRUCT(buffmem_desc,
 STRUCT(mixer_info,
MK_ARRAY(TYPE_CHAR, 16), MK_ARRAY(TYPE_CHAR, 32), TYPE_INT, 
MK_ARRAY(TYPE_INT, 10))
 
+STRUCT(snd_timer_id,
+   TYPE_INT, /* dev_class */
+   TYPE_INT, /* dev_sclass */
+   TYPE_INT, /* card */
+   TYPE_INT, /* device */
+   TYPE_INT) /* subdevice */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




[PATCH v7 05/13] linux-user: Add support for getting/setting RTC PLL correction using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_PLL_GET - Getting PLL correction

Read the PLL correction for RTCs that support PLL. The PLL correction
is returned in the following structure:

struct rtc_pll_info {
int pll_ctrl;/* placeholder for fancier control */
int pll_value;   /* get/set correction value */
int pll_max; /* max +ve (faster) adjustment value */
int pll_min; /* max -ve (slower) adjustment value */
int pll_posmult; /* factor for +ve correction */
int pll_negmult; /* factor for -ve correction */
long pll_clock;  /* base PLL frequency */
};

A pointer to this structure should be passed as the third
ioctl's argument.

RTC_PLL_SET - Setting PLL correction

Sets the PLL correction for RTCs that support PLL. The PLL correction
that is set is specified by the rtc_pll_info structure pointed to by
the third ioctl's' argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure rtc_pll_info
as their third argument. All elements of this structure are of
type 'int', except the last one that is of type 'long'. That is
the reason why a separate target structure (target_rtc_pll_info)
is defined in linux-user/syscall_defs. The rest of the
implementation is straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  2 ++
 linux-user/syscall_defs.h  | 14 ++
 linux-user/syscall_types.h |  9 +
 3 files changed, 25 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index b09396e..0a4e3f1 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -87,6 +87,8 @@
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 37504a2..8370f41 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -763,6 +763,16 @@ struct target_pollfd {
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
 #define TARGET_KDSIGACCEPT 0x4B4E
 
+struct target_rtc_pll_info {
+int pll_ctrl;
+int pll_value;
+int pll_max;
+int pll_min;
+int pll_posmult;
+int pll_negmult;
+abi_long pll_clock;
+};
+
 /* real time clock ioctls */
 #define TARGET_RTC_AIE_ON   TARGET_IO('p', 0x01)
 #define TARGET_RTC_AIE_OFF  TARGET_IO('p', 0x02)
@@ -782,6 +792,10 @@ struct target_pollfd {
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
 #define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
 #define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
+#define TARGET_RTC_PLL_GET  TARGET_IOR('p', 0x11,  
\
+   struct target_rtc_pll_info)
+#define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
+   struct target_rtc_pll_info)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 820bc8e..4027272 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -271,6 +271,15 @@ STRUCT(rtc_wkalrm,
TYPE_CHAR, /* pending */
MK_STRUCT(STRUCT_rtc_time)) /* time */
 
+STRUCT(rtc_pll_info,
+   TYPE_INT, /* pll_ctrl */
+   TYPE_INT, /* pll_value */
+   TYPE_INT, /* pll_max */
+   TYPE_INT, /* pll_min */
+   TYPE_INT, /* pll_posmult */
+   TYPE_INT, /* pll_negmult */
+   TYPE_LONG) /* pll_clock */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v7 06/13] linux-user: Add support for read/clear RTC voltage low detector using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_VL_READ - Read voltage low detection information

Read the voltage low for RTCs that support voltage low.
The third ioctl's' argument points to an int in which
the voltage low is returned.

RTC_VL_CLR - Clear voltage low information

Clear the information about voltage low for RTCs that
support voltage low. The third ioctl(2) argument is
ignored.

Implementation notes:

Since one ioctl has a pointer to 'int' as its third agrument,
and another ioctl has NULL as its third argument, their
implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 2 ++
 linux-user/syscall_defs.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 0a4e3f1..1f1f3e6 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -89,6 +89,8 @@
  IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
  IOCTL(RTC_PLL_GET, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
  IOCTL(RTC_PLL_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_pll_info)))
+ IOCTL(RTC_VL_READ, IOC_R, MK_PTR(TYPE_INT))
+ IOCTL(RTC_VL_CLR, 0, TYPE_NULL)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 8370f41..af4f366 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -796,6 +796,8 @@ struct target_rtc_pll_info {
struct target_rtc_pll_info)
 #define TARGET_RTC_PLL_SET  TARGET_IOW('p', 0x12,  
\
struct target_rtc_pll_info)
+#define TARGET_RTC_VL_READ  TARGET_IOR('p', 0x13, int)
+#define TARGET_RTC_VL_CLR   TARGET_IO('p', 0x14)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
-- 
2.7.4




[PATCH v7 00/13] linux-user: Add support for real time clock and

2020-01-15 Thread Filip Bozuta
t programs were written to test further functionalities
of individual ioctls. Those programs were, like the file "timer.c",
compiled for different architectures and were executed both natively
and thgrough QEMU to compare the results.

Example of a test program:

For ioctl SNDRV_TIMER_IOCTL_GINFO the following test program was used:

#include 
#include 
#include 
#include 
#include 
#include 

#define ERROR -1

int main()
{
int fd = open("/dev/snd/timer", O_RDWR);

if(fd == ERROR)
{
perror("open");
return -1;
}

struct snd_timer_id id = {SNDRV_TIMER_CLASS_GLOBAL, 
  SNDRV_TIMER_SCLASS_NONE, -1, 
  SNDRV_TIMER_GLOBAL_SYSTEM, 0};

struct snd_timer_ginfo ginfo;
ginfo.tid = id;

if(ioctl(fd, SNDRV_TIMER_IOCTL_GINFO, &ginfo) == ERROR)
{
perror("ioctl");
return -1;
}

printf("flags: %u\n", ginfo.flags);
printf("card: %d\n", ginfo.card);
printf("id: %s\n", ginfo.id);
printf("name: %s\n", ginfo.name);
printf("reserved0: %lu\n", ginfo.reserved0);
printf("resolution: %lu\n", ginfo.resolution);
printf("resolution_min: %lu\n", ginfo.resolution_min);
printf("reolution_max: %lu\n", ginfo.resolution_max);
printf("clients: %u\n", ginfo.clients);
printf("reserved: %s\n", ginfo.reserved);

return 0;
}

v7:

* added separate patch for support for ioctls that have 'long' and
  'unsigned long' as third argument (this functionality was added
  in v6 but in v7 a separate patch was added for it)

* modified coding style for files that had styling problems
  detected by script located in 'scripts/checkpatch.pl'

v6:

* fixed one patch by adding a case statement for 'unsigned long'
  to recognize two ioctls that are implemented in that patch

* changed patch descriptions a little bit so that they are more
  comprehensible

v5:

* added support for alsa sound timer ioctls

v4:

* changed patch descriptions so that they are better
  formatted and more comprehensible

v3:

* changed two instances of MK_PTR(TYPE_ULONG) to TYPE_ULONG

v2:

* added description of each ioctl in patches
* wrote a more detailed cover letter with description of testing
* changed one instance of TYPE_INT to MK_PTR(TYPE_INT)

Filip Bozuta (13):
  linux-user: Add support for enabling/disabling RTC features using
ioctls
  linux-user: Add support for getting/setting RTC time and alarm using
ioctls
  linux-user: Add support for getting/setting RTC periodic interrupt and
epoch using ioctls
  linux-user: Add support for getting/setting RTC wakeup alarm using
ioctls
  linux-user: Add support for getting/setting RTC PLL correction using
ioctls
  linux-user: Add support for read/clear RTC voltage low detector using
ioctls
  linux-user: Add support for getting alsa timer version and id
  linux-user: Add support for setting alsa timer enhanced read using
ioctl
  linux-user: Add support for getting/setting specified alsa timer
parameters using ioctls
  linux-user: Add support for selecting alsa timer using ioctl
  linux-user: Add support for getting/setting selected alsa timer
parameters using ioctls
  linux-user: Add support for selected alsa timer instructions using
ioctls
  linux-user: Add support for TYPE_LONG and TYPE_ULONG in do_ioctl()

 linux-user/ioctls.h|  45 +
 linux-user/syscall.c   |   4 ++
 linux-user/syscall_defs.h  | 121 +
 linux-user/syscall_types.h |  91 ++
 4 files changed, 261 insertions(+)

-- 
2.7.4




[PATCH v7 04/13] linux-user: Add support for getting/setting RTC wakeup alarm using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

RTC_WKALM_SET, RTC_WKALM_GET - Getting/Setting wakeup alarm

Some RTCs support a more powerful alarm interface, using these
ioctls to read or write the RTC's alarm time (respectively)
with this structure:

struct rtc_wkalrm {
unsigned char enabled;
unsigned char pending;
struct rtc_time time;
};

The enabled flag is used to enable or disable the alarm
interrupt, or to read its current status; when using these
calls, RTC_AIE_ON and RTC_AIE_OFF are not used. The pending
flag is used by RTC_WKALM_RD to report a pending interrupt
(so it's mostly useless on Linux, except when talking to the
RTC managed by EFI firmware). The time field is as used with
RTC_ALM_READ and RTC_ALM_SET except that the tm_mday, tm_mon,
and tm_year fields are also valid. A pointer to this structure
should be passed as the third ioctl's argument.

Implementation notes:

All ioctls in this patch have a pointer to a structure
rtc_wkalrm as their third argument. That is the reason why
corresponding definition is added in linux-user/syscall_types.h.
Since all  elements of this structure are either of type
'unsigned char' or 'struct rtc_time' (that was covered in one
of previous patches), the rest of the implementation is
    straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 2 ++
 linux-user/syscall_types.h | 5 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index accbdee..b09396e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -85,6 +85,8 @@
  IOCTL(RTC_IRQP_SET, IOC_W, TYPE_ULONG)
  IOCTL(RTC_EPOCH_READ, IOC_R, MK_PTR(TYPE_ULONG))
  IOCTL(RTC_EPOCH_SET, IOC_W, TYPE_ULONG)
+ IOCTL(RTC_WKALM_RD, IOC_R, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
+ IOCTL(RTC_WKALM_SET, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtc_wkalrm)))
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index bbfa935..37504a2 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -780,6 +780,8 @@ struct target_pollfd {
 #define TARGET_RTC_IRQP_SET TARGET_IOW('p', 0x0c, abi_ulong)
 #define TARGET_RTC_EPOCH_READ   TARGET_IOR('p', 0x0d, abi_ulong)
 #define TARGET_RTC_EPOCH_SETTARGET_IOW('p', 0x0e, abi_ulong)
+#define TARGET_RTC_WKALM_RD TARGET_IOR('p', 0x10, struct rtc_wkalrm)
+#define TARGET_RTC_WKALM_SETTARGET_IOW('p', 0x0f, struct rtc_wkalrm)
 
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SH4) ||
\
defined(TARGET_XTENSA)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index a35072a..820bc8e 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -266,6 +266,11 @@ STRUCT(rtc_time,
TYPE_INT, /* tm_yday */
TYPE_INT) /* tm_isdst */
 
+STRUCT(rtc_wkalrm,
+   TYPE_CHAR, /* enabled */
+   TYPE_CHAR, /* pending */
+   MK_STRUCT(STRUCT_rtc_time)) /* time */
+
 STRUCT(blkpg_ioctl_arg,
TYPE_INT, /* op */
TYPE_INT, /* flags */
-- 
2.7.4




[PATCH v7 12/13] linux-user: Add support for selected alsa timer instructions using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_START - Start selected alsa timer

Starts the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be started. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_STOP - Stop selected alsa timer

Stops the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be stopped. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_CONTINUE - Continue selected alsa timer

Continues the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be continued. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

SNDRV_TIMER_IOCTL_PAUSE - Pause selected alsa timer

Pauses the timer device that is selected. The third ioctl's argument is
ignored. Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT"
should be called first to select the timer that is to be paused. If no
timer is selected, the error EBADFD ("File descriptor in bad shape")
is returned.

Implementation notes:

Since all of the implemented ioctls have NULL as their third argument,
their implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h   | 4 
 linux-user/syscall_defs.h | 4 
 2 files changed, 8 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 43e7e5d..75a2f0e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -466,6 +466,10 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
   IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
+  IOCTL(SNDRV_TIMER_IOCTL_START, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_STOP, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_CONTINUE, 0, TYPE_NULL)
+  IOCTL(SNDRV_TIMER_IOCTL_PAUSE, 0, TYPE_NULL)
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d5f5cad..2d86d78 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2505,6 +2505,10 @@ struct target_snd_timer_status {
 struct snd_timer_params)
 #define TARGET_SNDRV_TIMER_IOCTL_STATUS   TARGET_IOR('T', 0x14,
\
 struct target_snd_timer_status)
+#define TARGET_SNDRV_TIMER_IOCTL_STARTTARGET_IO('T', 0xa0)
+#define TARGET_SNDRV_TIMER_IOCTL_STOP TARGET_IO('T', 0xa1)
+#define TARGET_SNDRV_TIMER_IOCTL_CONTINUE TARGET_IO('T', 0xa2)
+#define TARGET_SNDRV_TIMER_IOCTL_PAUSETARGET_IO('T', 0xa3)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
-- 
2.7.4




[PATCH v7 10/13] linux-user: Add support for selecting alsa timer using ioctl

2020-01-15 Thread Filip Bozuta
This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_SELECT - Selecting timer

Selects the timer which id is specified. The timer id is specified in the
following strcuture:

struct snd_timer_select {
struct snd_timer_id id; /* timer ID */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which is to be selected. If there is no timer
device with the specified id, the error ENODEV ("No such device") is
returned.

Implementation notes:

Ioctl implemented in this patch has a pointer to a
'struct snd_timer_select' as its third argument.
That is the reason why a corresponding definition
was added in 'linux-user/syscall_types.h'. The rest
of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h| 2 ++
 linux-user/syscall_defs.h  | 7 +++
 linux-user/syscall_types.h | 4 
 3 files changed, 13 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 989eb9b..7652117 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -459,6 +459,8 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gparams)))
   IOCTL(SNDRV_TIMER_IOCTL_GSTATUS, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
+  IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index a675b92..39b9739 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2462,6 +2462,11 @@ struct target_snd_timer_gstatus {
 unsigned char reserved[32];
 };
 
+struct target_snd_timer_select {
+struct target_snd_timer_id id;
+unsigned char reserved[32];
+};
+
 /* alsa timer ioctls */
 #define TARGET_SNDRV_TIMER_IOCTL_PVERSION TARGET_IOR('T', 0x00, int)
 #define TARGET_SNDRV_TIMER_IOCTL_NEXT_DEVICE  TARGET_IOWR('T', 0x01,   
\
@@ -2473,6 +2478,8 @@ struct target_snd_timer_gstatus {
 struct 
target_snd_timer_gparams)
 #define TARGET_SNDRV_TIMER_IOCTL_GSTATUS  TARGET_IOWR('T', 0x05,   
\
 struct 
target_snd_timer_gstatus)
+#define TARGET_SNDRV_TIMER_IOCTL_SELECT   TARGET_IOW('T', 0x10,
\
+struct target_snd_timer_select)
 
 /* vfat ioctls */
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 4e90716..767632d 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -116,6 +116,10 @@ STRUCT(snd_timer_gstatus,
TYPE_ULONG, /* resolution_den */
MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
 
+STRUCT(snd_timer_select,
+   MK_STRUCT(STRUCT_snd_timer_id), /* id */
+   MK_ARRAY(TYPE_CHAR, 32)) /* reserved */
+
 /* loop device ioctls */
 STRUCT(loop_info,
TYPE_INT, /* lo_number */
-- 
2.7.4




Re: [PATCH 08/12] linux-user: Add support for setting alsa timer enhanced read using ioctl

2020-01-15 Thread Filip Bozuta



On 15.1.20. 17:37, Arnd Bergmann wrote:

On Wed, Jan 15, 2020 at 5:32 PM Laurent Vivier  wrote:

Le 15/01/2020 à 17:18, Arnd Bergmann a écrit :

On Wed, Jan 15, 2020 at 4:53 PM Filip Bozuta  wrote:

This patch implements functionality of following ioctl:

SNDRV_TIMER_IOCTL_TREAD - Setting enhanced time read

 Sets enhanced time read which is used for reading time with timestamps
 and events. The third ioctl's argument is a pointer to an 'int'. Enhanced
 reading is set if the third argument is different than 0, otherwise normal
 time reading is set.

Implementation notes:

 Because the implemented ioctl has 'int' as its third argument, the
 implementation was straightforward.

Signed-off-by: Filip Bozuta 

I think this one is wrong when you go between 32-bit and 64-bit

kernel uses an "int" and "int" is always 32bit.
The problem is most likely with timespec I think.


targets, and it gets worse with the kernel patches that just got
merged for linux-5.5, which extends the behavior to deal with
64-bit time_t on 32-bit architectures.

Please have a look at
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?h=80fe7430c70859

Yes, we already had the same kind of problem with SIOCGSTAMP and
SIOCGSTAMPNS.

Do the kernel patches add new ioctl numbers to differentiate 32bit and
64bit time_t?

Yes, though SNDRV_TIMER_IOCTL_TREAD is worse: the ioctl argument
is a pure 'int' that decides what format you get when you 'read' from the
same file descriptor.

For emulating 64-bit on 32-bit kernels, you have to use the new
SNDRV_TIMER_IOCTL_TREAD64, and for emulating 32-bit on
64-bit kernels, you probably have to return -ENOTTY to
SNDRV_TIMER_IOCTL_TREAD_OLD unless you also want to
emulate the read() behavior.
When a 32-bit process calls SNDRV_TIMER_IOCTL_TREAD64,
you can translate that into the 64-bit
SNDRV_TIMER_IOCTL_TREAD_OLD.

  Arnd



Thank you for bringing this up to my attention. Unfortunately i have 
some duties of academic nature in next month so i won't have much time 
fix this bug. I will try to fix this as soon as possible.


Best regards,

Filip Bozuta




[PATCH v7 09/13] linux-user: Add support for getting/setting specified alsa timer parameters using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_GINFO - Getting information about specified timer

Read information about the specified timer. The information about the
timer is returned in the following structure:

struct snd_timer_ginfo {
struct snd_timer_id tid;  /* requested timer ID */
unsigned int flags;   /* timer flags - SNDRV_TIMER_FLG_* */
int card; /* card number */
unsigned char id[64]; /* timer identification */
unsigned char name[80];   /* timer name */
unsigned long reserved0;  /* reserved for future use */
unsigned long resolution; /* average period resolution in ns */
unsigned long resolution_min; /* minimal period resolution in ns */
unsigned long resolution_max; /* maximal period resolution in ns */
unsigned int clients; /* active timer clients */
unsigned char reserved[32];   /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which information is to be obtained. After the
ioctl call, the rest of the structure fields are filled with values from
the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

SNDRV_TIMER_IOCTL_GPARAMS - Setting precise period duration

Sets timer precise period duration numerator and denominator in seconds. The
period duration is set in the following structure:

struct snd_timer_gparams {
struct snd_timer_id tid;/* requested timer ID */
unsigned long period_num;   /* period duration - numerator */
unsigned long period_den;   /* period duration - denominator */
unsigned char reserved[32]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period duration is to be set. Also, the
fileds "period_num" and "period_den" should be filled with the period
duration numerator and denominator values that are to be set respectively.
If there is no device with the specified id, the error ENODEV ("No such
device") is returned.

SNDRV_TIMER_IOCTL_GSTATUS - Getting current period resolution

Read timer current period resolution in nanoseconds and period resolution
numerator and denominator in seconds. The period resolution information is
returned in the following structure:

struct snd_timer_gstatus {
struct snd_timer_id tid;/* requested timer ID */
unsigned long resolution;   /* current period resolution in ns */
unsigned long resolution_num;   /* period resolution - numerator */
unsigned long resolution_den;   /* period resolution - denominator */
unsigned char reserved[32]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling the ioctl, the field "tid" should be initialized with the id
information for the timer which period resolution is to be obtained. After
the ioctl call, the rest of the structure fields are filled with values
from the timer device with the specified id. If there is no device with the
specified id, the error ENODEV ("No such device") is returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure as their
third argument. That is the reason why corresponding definitions were added
in 'linux-user/syscall_types.h'. All of these strcutures have some fields
that are of type 'unsigned long'. That is the reason why separate target
structures were defined in 'linux-user/syscall_defs.h'. Also, all of the
structures have a field with type 'struct snd_timer_id' which is the reason
why a separate target structure 'struct target_snd_timer_id' was also
defined. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  6 ++
 linux-user/syscall_defs.h  | 43 +++
 linux-user/syscall_types.h | 26 ++
 3 files changed, 75 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 9106773..989eb9b 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -453,6 +453,12 @@
   IOCTL(SNDRV_TIMER_IOCTL_NEXT_DEVICE, IOC_RW,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_id)))
   IOCTL(SNDRV_TIMER_IOCTL_TREAD, IOC_W, MK_PTR(T

[PATCH v7 13/13] linux-user: Add support for TYPE_LONG and TYPE_ULONG in do_ioctl()

2020-01-15 Thread Filip Bozuta
Function "do_ioctl()" located in file "syscall.c" was missing
an option for TYPE_LONG and TYPE_ULONG. This caused some ioctls
to not be recognised because they had the third argument that was
of type 'long' or 'unsigned long'.

For example:

Since implemented ioctls RTC_IRQP_SET and RTC_EPOCH_SET
are of type IOW(writing type) that have unsigned long as
their third argument, they were not recognised in QEMU
before the changes of this patch.

Signed-off-by: Filip Bozuta 
---
 linux-user/syscall.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a3993a2..2ba2c5c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5176,6 +5176,8 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
 break;
 case TYPE_PTRVOID:
 case TYPE_INT:
+case TYPE_LONG:
+case TYPE_ULONG:
 ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg));
 break;
 case TYPE_PTR:
-- 
2.7.4




[PATCH v7 11/13] linux-user: Add support for getting/setting selected alsa timer parameters using ioctls

2020-01-15 Thread Filip Bozuta
This patch implements functionalities of following ioctls:

SNDRV_TIMER_IOCTL_INFO - Getting information about selected timer

Read information about the selected timer. The information is returned in
the following structure:

struct snd_timer_info {
unsigned int flags; /* timer flags - SNDRV_TIMER_FLG_* */
int card;   /* card number */
unsigned char id[64];   /* timer identificator */
unsigned char name[80]; /* timer name */
unsigned long reserved0;/* reserved for future use */
unsigned long resolution;   /* average period resolution in ns */
unsigned char reserved[64]; /* reserved for future use */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which information is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_PARAMS - Setting parameters for selected timer

Sets parameters for the selected timer. The paramaters are set in the
following structure:

struct snd_timer_params {
unsigned int flags; /* flags - SNDRV_TIMER_PSFLG_* */
unsigned int ticks; /* requested resolution in ticks */
unsigned int queue_size;/* total size of queue (32-1024) */
unsigned int reserved0; /* reserved, was: failure locations */
unsigned int filter;/* event filter */
unsigned char reserved[60]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which parameters are to be set. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

SNDRV_TIMER_IOCTL_STATUS - Getting status of selected timer

Read status of the selected timer. The status of the timer is returned in
the following structure:

struct snd_timer_status {
struct timespec tstamp; /* Timestamp - last update */
unsigned int resolution;/* current period resolution in ns */
unsigned int lost;  /* counter of master tick lost */
unsigned int overrun;   /* count of read queue overruns */
unsigned int queue; /* used queue size */
unsigned char reserved[64]; /* reserved */
};

A pointer to this structure should be passed as the third ioctl's argument.
Before calling this ioctl, the ioctl "SNDRV_TIMER_IOCTL_SELECT" should be
called first to select the timer which status is to be obtained. If no
timer is selected, the error EBADFD ("File descriptor in bad shape") is
returned.

Implementation notes:

All ioctls in this patch have pointer to some kind of a structure
as their third argument. That is the reason why corresponding
definitions were added in 'linux-user/syscall_types.h'. Structure
'snd_timer_status' has field of type 'struct timespec' which is why
a corresponding definition of that structure was also added in
'linux-user/syscall_types.h'. All of these strucutures have some
fields that are of type 'unsigned long'. That is the reason why
separate target structures were defined in 'linux-user/syscall_defs.h'.
Structure 'struct timespec' already had a separate target definition
so that definition was used to define a target structure for
'snd_timer_status'. The rest of the implementation was straightforward.

Signed-off-by: Filip Bozuta 
---
 linux-user/ioctls.h|  5 +
 linux-user/syscall_defs.h  | 25 +
 linux-user/syscall_types.h | 29 +
 3 files changed, 59 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 7652117..43e7e5d 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -461,6 +461,11 @@
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_gstatus)))
   IOCTL(SNDRV_TIMER_IOCTL_SELECT, IOC_W,
 MK_PTR(MK_STRUCT(STRUCT_snd_timer_select)))
+  IOCTL(SNDRV_TIMER_IOCTL_INFO, IOC_R, 
MK_PTR(MK_STRUCT(STRUCT_snd_timer_info)))
+  IOCTL(SNDRV_TIMER_IOCTL_PARAMS, IOC_W,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_params)))
+  IOCTL(SNDRV_TIMER_IOCTL_STATUS, IOC_R,
+MK_PTR(MK_STRUCT(STRUCT_snd_timer_status)))
 
   IOCTL(HDIO_GETGEO, IOC_R, MK_PTR(MK_STRUCT(STRUCT_hd_geometry)))
   IOCTL(HDIO_GET_UNMASKINTR, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 39b9739..d5f5cad 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2467,6 +2467,25 @@ struct target_snd_timer_select {
 

<    1   2   3   >