* [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs
@ 2013-01-07 22:24 Laurent Vivier
2013-01-07 23:06 ` Richard Henderson
2013-01-10 20:42 ` [Qemu-devel] [PATCH][v2] " Laurent Vivier
0 siblings, 2 replies; 6+ messages in thread
From: Laurent Vivier @ 2013-01-07 22:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, dillona, Richard Henderson
on alpha, F_RDLCK, F_WRLCK, F_UNLCK, F_EXLCK, F_SHLCK
are not the standard ones.
This patch allows to run "dpkg" (database lock).
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 50 +++++++++++++++++++++++++++++++++++++++------
linux-user/syscall_defs.h | 18 ++++++++++++++++
2 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3167a87..2232bb8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4512,6 +4512,41 @@ static int target_to_host_fcntl_cmd(int cmd)
return -TARGET_EINVAL;
}
+static short target_to_host_flock_type(short type)
+{
+ switch (type) {
+ case TARGET_F_RDLCK:
+ return F_RDLCK;
+ case TARGET_F_WRLCK:
+ return F_WRLCK;
+ case TARGET_F_UNLCK:
+ return F_UNLCK;
+ case TARGET_F_EXLCK:
+ return F_EXLCK;
+ case TARGET_F_SHLCK:
+ return F_SHLCK;
+ default:
+ return type;
+ }
+}
+
+static short host_to_target_flock_type(short type)
+{
+ switch (type) {
+ case F_RDLCK:
+ return TARGET_F_RDLCK;
+ case F_WRLCK:
+ return TARGET_F_WRLCK;
+ case F_UNLCK:
+ return TARGET_F_UNLCK;
+ case F_EXLCK:
+ return TARGET_F_EXLCK;
+ case F_SHLCK:
+ return TARGET_F_SHLCK;
+ default:
+ return type;
+ }
+}
static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
{
struct flock fl;
@@ -4528,7 +4563,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_GETLK:
if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1))
return -TARGET_EFAULT;
- fl.l_type = tswap16(target_fl->l_type);
+ fl.l_type = target_to_host_flock_type(tswap16(target_fl->l_type));
fl.l_whence = tswap16(target_fl->l_whence);
fl.l_start = tswapal(target_fl->l_start);
fl.l_len = tswapal(target_fl->l_len);
@@ -4538,7 +4573,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret == 0) {
if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0))
return -TARGET_EFAULT;
- target_fl->l_type = tswap16(fl.l_type);
+ target_fl->l_type = host_to_target_flock_type(tswap16(fl.l_type));
target_fl->l_whence = tswap16(fl.l_whence);
target_fl->l_start = tswapal(fl.l_start);
target_fl->l_len = tswapal(fl.l_len);
@@ -4551,7 +4586,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_SETLKW:
if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1))
return -TARGET_EFAULT;
- fl.l_type = tswap16(target_fl->l_type);
+ fl.l_type = target_to_host_flock_type(tswap16(target_fl->l_type));
fl.l_whence = tswap16(target_fl->l_whence);
fl.l_start = tswapal(target_fl->l_start);
fl.l_len = tswapal(target_fl->l_len);
@@ -4563,7 +4598,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_GETLK64:
if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1))
return -TARGET_EFAULT;
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
+ fl64.l_type =
+ target_to_host_flock_type(tswap16(target_fl64->l_type)) >> 1;
fl64.l_whence = tswap16(target_fl64->l_whence);
fl64.l_start = tswap64(target_fl64->l_start);
fl64.l_len = tswap64(target_fl64->l_len);
@@ -4573,7 +4609,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret == 0) {
if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0))
return -TARGET_EFAULT;
- target_fl64->l_type = tswap16(fl64.l_type) >> 1;
+ target_fl64->l_type =
+ host_to_target_flock_type(tswap16(fl64.l_type)) >> 1;
target_fl64->l_whence = tswap16(fl64.l_whence);
target_fl64->l_start = tswap64(fl64.l_start);
target_fl64->l_len = tswap64(fl64.l_len);
@@ -4585,7 +4622,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_SETLKW64:
if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1))
return -TARGET_EFAULT;
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
+ fl64.l_type =
+ target_to_host_flock_type(tswap16(target_fl64->l_type)) >> 1;
fl64.l_whence = tswap16(target_fl64->l_whence);
fl64.l_start = tswap64(target_fl64->l_start);
fl64.l_len = tswap64(target_fl64->l_len);
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 69aa6b8..6095992 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2017,6 +2017,12 @@ struct target_statfs64 {
#define TARGET_F_SETLKW 9
#define TARGET_F_SETOWN 5 /* for sockets. */
#define TARGET_F_GETOWN 6 /* for sockets. */
+
+#define TARGET_F_RDLCK 1
+#define TARGET_F_WRLCK 2
+#define TARGET_F_UNLCK 8
+#define TARGET_F_EXLCK 16
+#define TARGET_F_SHLCK 32
#elif defined(TARGET_MIPS)
#define TARGET_F_GETLK 14
#define TARGET_F_SETLK 6
@@ -2031,6 +2037,18 @@ struct target_statfs64 {
#define TARGET_F_GETOWN 9 /* for sockets. */
#endif
+#ifndef TARGET_F_RDLCK
+#define TARGET_F_RDLCK 0
+#define TARGET_F_WRLCK 1
+#define TARGET_F_UNLCK 2
+#endif
+
+#ifndef TARGET_F_EXLCK
+#define TARGET_F_EXLCK 4
+#define TARGET_F_SHLCK 8
+#endif
+
+
#define TARGET_F_SETSIG 10 /* for sockets. */
#define TARGET_F_GETSIG 11 /* for sockets. */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs
2013-01-07 22:24 [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs Laurent Vivier
@ 2013-01-07 23:06 ` Richard Henderson
2013-01-08 9:18 ` Laurent Vivier
2013-01-10 20:42 ` [Qemu-devel] [PATCH][v2] " Laurent Vivier
1 sibling, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2013-01-07 23:06 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, qemu-devel, dillona
On 01/07/2013 02:24 PM, Laurent Vivier wrote:
> +static short target_to_host_flock_type(short type)
> +{
> + switch (type) {
> + case TARGET_F_RDLCK:
> + return F_RDLCK;
> + case TARGET_F_WRLCK:
> + return F_WRLCK;
> + case TARGET_F_UNLCK:
> + return F_UNLCK;
> + case TARGET_F_EXLCK:
> + return F_EXLCK;
> + case TARGET_F_SHLCK:
> + return F_SHLCK;
> + default:
> + return type;
> + }
> +}
> +
> +static short host_to_target_flock_type(short type)
> +{
> + switch (type) {
> + case F_RDLCK:
> + return TARGET_F_RDLCK;
> + case F_WRLCK:
> + return TARGET_F_WRLCK;
> + case F_UNLCK:
> + return TARGET_F_UNLCK;
> + case F_EXLCK:
> + return TARGET_F_EXLCK;
> + case F_SHLCK:
> + return TARGET_F_SHLCK;
> + default:
> + return type;
> + }
> +}
Any reason not to use the bitmask_transtbl method of translation?
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs
2013-01-07 23:06 ` Richard Henderson
@ 2013-01-08 9:18 ` Laurent Vivier
0 siblings, 0 replies; 6+ messages in thread
From: Laurent Vivier @ 2013-01-08 9:18 UTC (permalink / raw)
To: Richard Henderson; +Cc: Riku Voipio, qemu-devel, dillona
[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]
Le 8 janvier 2013 à 00:06, Richard Henderson <rth@twiddle.net> a écrit :
> On 01/07/2013 02:24 PM, Laurent Vivier wrote:
> > +static short target_to_host_flock_type(short type)
> > +{
> > + switch (type) {
> > + case TARGET_F_RDLCK:
> > + return F_RDLCK;
> > + case TARGET_F_WRLCK:
> > + return F_WRLCK;
> > + case TARGET_F_UNLCK:
> > + return F_UNLCK;
> > + case TARGET_F_EXLCK:
> > + return F_EXLCK;
> > + case TARGET_F_SHLCK:
> > + return F_SHLCK;
> > + default:
> > + return type;
> > + }
> > +}
> > +
> > +static short host_to_target_flock_type(short type)
> > +{
> > + switch (type) {
> > + case F_RDLCK:
> > + return TARGET_F_RDLCK;
> > + case F_WRLCK:
> > + return TARGET_F_WRLCK;
> > + case F_UNLCK:
> > + return TARGET_F_UNLCK;
> > + case F_EXLCK:
> > + return TARGET_F_EXLCK;
> > + case F_SHLCK:
> > + return TARGET_F_SHLCK;
> > + default:
> > + return type;
> > + }
> > +}
>
> Any reason not to use the bitmask_transtbl method of translation?
>
No reason. I correct this.
Regards,
Laurent
[-- Attachment #2: Type: text/html, Size: 2393 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH][v2] linux-user, alpha: l_type of fcntl() flock differs
2013-01-07 22:24 [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs Laurent Vivier
2013-01-07 23:06 ` Richard Henderson
@ 2013-01-10 20:42 ` Laurent Vivier
2013-01-10 21:05 ` Richard Henderson
1 sibling, 1 reply; 6+ messages in thread
From: Laurent Vivier @ 2013-01-10 20:42 UTC (permalink / raw)
To: Richard Henderson; +Cc: Riku Voipio, qemu-devel, Laurent Vivier
on alpha, F_RDLCK, F_WRLCK, F_UNLCK, F_EXLCK, F_SHLCK
are not the standard ones.
This patch allows to run "dpkg" (database lock).
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
v2: use bitmask_transtbl
linux-user/syscall.c | 28 ++++++++++++++++++++++------
linux-user/syscall_defs.h | 18 ++++++++++++++++++
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3167a87..94f79dd 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4512,6 +4512,16 @@ static int target_to_host_fcntl_cmd(int cmd)
return -TARGET_EINVAL;
}
+#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a }
+static const bitmask_transtbl flock_tbl[] = {
+ TRANSTBL_CONVERT(F_RDLCK),
+ TRANSTBL_CONVERT(F_WRLCK),
+ TRANSTBL_CONVERT(F_UNLCK),
+ TRANSTBL_CONVERT(F_EXLCK),
+ TRANSTBL_CONVERT(F_SHLCK),
+ { 0, 0, 0, 0 }
+};
+
static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
{
struct flock fl;
@@ -4528,7 +4538,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_GETLK:
if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1))
return -TARGET_EFAULT;
- fl.l_type = tswap16(target_fl->l_type);
+ fl.l_type =
+ target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl);
fl.l_whence = tswap16(target_fl->l_whence);
fl.l_start = tswapal(target_fl->l_start);
fl.l_len = tswapal(target_fl->l_len);
@@ -4538,7 +4549,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret == 0) {
if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0))
return -TARGET_EFAULT;
- target_fl->l_type = tswap16(fl.l_type);
+ target_fl->l_type =
+ host_to_target_bitmask(tswap16(fl.l_type), flock_tbl);
target_fl->l_whence = tswap16(fl.l_whence);
target_fl->l_start = tswapal(fl.l_start);
target_fl->l_len = tswapal(fl.l_len);
@@ -4551,7 +4563,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_SETLKW:
if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1))
return -TARGET_EFAULT;
- fl.l_type = tswap16(target_fl->l_type);
+ fl.l_type =
+ target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl);
fl.l_whence = tswap16(target_fl->l_whence);
fl.l_start = tswapal(target_fl->l_start);
fl.l_len = tswapal(target_fl->l_len);
@@ -4563,7 +4576,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_GETLK64:
if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1))
return -TARGET_EFAULT;
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
+ fl64.l_type =
+ target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1;
fl64.l_whence = tswap16(target_fl64->l_whence);
fl64.l_start = tswap64(target_fl64->l_start);
fl64.l_len = tswap64(target_fl64->l_len);
@@ -4573,7 +4587,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret == 0) {
if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0))
return -TARGET_EFAULT;
- target_fl64->l_type = tswap16(fl64.l_type) >> 1;
+ target_fl64->l_type =
+ host_to_target_bitmask(tswap16(fl64.l_type), flock_tbl) >> 1;
target_fl64->l_whence = tswap16(fl64.l_whence);
target_fl64->l_start = tswap64(fl64.l_start);
target_fl64->l_len = tswap64(fl64.l_len);
@@ -4585,7 +4600,8 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_SETLKW64:
if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1))
return -TARGET_EFAULT;
- fl64.l_type = tswap16(target_fl64->l_type) >> 1;
+ fl64.l_type =
+ target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1;
fl64.l_whence = tswap16(target_fl64->l_whence);
fl64.l_start = tswap64(target_fl64->l_start);
fl64.l_len = tswap64(target_fl64->l_len);
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 69aa6b8..6095992 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2017,6 +2017,12 @@ struct target_statfs64 {
#define TARGET_F_SETLKW 9
#define TARGET_F_SETOWN 5 /* for sockets. */
#define TARGET_F_GETOWN 6 /* for sockets. */
+
+#define TARGET_F_RDLCK 1
+#define TARGET_F_WRLCK 2
+#define TARGET_F_UNLCK 8
+#define TARGET_F_EXLCK 16
+#define TARGET_F_SHLCK 32
#elif defined(TARGET_MIPS)
#define TARGET_F_GETLK 14
#define TARGET_F_SETLK 6
@@ -2031,6 +2037,18 @@ struct target_statfs64 {
#define TARGET_F_GETOWN 9 /* for sockets. */
#endif
+#ifndef TARGET_F_RDLCK
+#define TARGET_F_RDLCK 0
+#define TARGET_F_WRLCK 1
+#define TARGET_F_UNLCK 2
+#endif
+
+#ifndef TARGET_F_EXLCK
+#define TARGET_F_EXLCK 4
+#define TARGET_F_SHLCK 8
+#endif
+
+
#define TARGET_F_SETSIG 10 /* for sockets. */
#define TARGET_F_GETSIG 11 /* for sockets. */
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH][v2] linux-user, alpha: l_type of fcntl() flock differs
2013-01-10 20:42 ` [Qemu-devel] [PATCH][v2] " Laurent Vivier
@ 2013-01-10 21:05 ` Richard Henderson
2013-01-10 21:10 ` Laurent Vivier
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2013-01-10 21:05 UTC (permalink / raw)
To: Laurent Vivier; +Cc: Riku Voipio, qemu-devel
On 01/10/2013 12:42 PM, Laurent Vivier wrote:
> +static const bitmask_transtbl flock_tbl[] = {
> + TRANSTBL_CONVERT(F_RDLCK),
> + TRANSTBL_CONVERT(F_WRLCK),
> + TRANSTBL_CONVERT(F_UNLCK),
> + TRANSTBL_CONVERT(F_EXLCK),
> + TRANSTBL_CONVERT(F_SHLCK),
> + { 0, 0, 0, 0 }
> +};
Oh, I forgot to mention that you'll need to protect against the
case of F_RDLCK == 0 && TARGET_F_RDLCK == 0. The easiest way to
handle this is place that entry last.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH][v2] linux-user, alpha: l_type of fcntl() flock differs
2013-01-10 21:05 ` Richard Henderson
@ 2013-01-10 21:10 ` Laurent Vivier
0 siblings, 0 replies; 6+ messages in thread
From: Laurent Vivier @ 2013-01-10 21:10 UTC (permalink / raw)
To: Richard Henderson; +Cc: Riku Voipio, qemu-devel
Le jeudi 10 janvier 2013 à 13:05 -0800, Richard Henderson a écrit :
> On 01/10/2013 12:42 PM, Laurent Vivier wrote:
> > +static const bitmask_transtbl flock_tbl[] = {
> > + TRANSTBL_CONVERT(F_RDLCK),
> > + TRANSTBL_CONVERT(F_WRLCK),
> > + TRANSTBL_CONVERT(F_UNLCK),
> > + TRANSTBL_CONVERT(F_EXLCK),
> > + TRANSTBL_CONVERT(F_SHLCK),
> > + { 0, 0, 0, 0 }
> > +};
>
> Oh, I forgot to mention that you'll need to protect against the
> case of F_RDLCK == 0 && TARGET_F_RDLCK == 0. The easiest way to
> handle this is place that entry last.
Look at the macro, I put all masks to -1, is it a mistake ?
Regards,
Laurent
--
"Just play. Have fun. Enjoy the game."
- Michael Jordan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-01-10 21:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-07 22:24 [Qemu-devel] [PATCH] linux-user, alpha: l_type of fcntl() flock differs Laurent Vivier
2013-01-07 23:06 ` Richard Henderson
2013-01-08 9:18 ` Laurent Vivier
2013-01-10 20:42 ` [Qemu-devel] [PATCH][v2] " Laurent Vivier
2013-01-10 21:05 ` Richard Henderson
2013-01-10 21:10 ` Laurent Vivier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).