115 lines
4.2 KiB
Diff
115 lines
4.2 KiB
Diff
Index: qemu-0.9.0/linux-user/syscall.c
|
|
===================================================================
|
|
--- qemu-0.9.0.orig/linux-user/syscall.c
|
|
+++ qemu-0.9.0/linux-user/syscall.c
|
|
@@ -2127,11 +2127,40 @@ static inline void host_to_target_timesp
|
|
unlock_user_struct(target_ts, target_addr, 1);
|
|
}
|
|
|
|
+#ifdef BSWAP_NEEDED
|
|
+static int futex_op(int oldval, int op, int oparg)
|
|
+{
|
|
+ int retval = oparg;
|
|
+ switch(op) {
|
|
+ case FUTEX_OP_SET: break;
|
|
+ case FUTEX_OP_ADD: retval += oparg; break;
|
|
+ case FUTEX_OP_OR: retval |= oparg; break;
|
|
+ case FUTEX_OP_ANDN: retval &= oparg; break;
|
|
+ case FUTEX_OP_XOR: retval ^= oparg; break;
|
|
+ }
|
|
+ return retval;
|
|
+}
|
|
+
|
|
+static int futex_cmp(int oldval, int cmp, int cmparg)
|
|
+{
|
|
+ switch(cmp) {
|
|
+ case FUTEX_OP_CMP_EQ: return oldval == cmparg;
|
|
+ case FUTEX_OP_CMP_NE: return oldval != cmparg;
|
|
+ case FUTEX_OP_CMP_LT: return oldval < cmparg;
|
|
+ case FUTEX_OP_CMP_LE: return oldval <= cmparg;
|
|
+ case FUTEX_OP_CMP_GT: return oldval > cmparg;
|
|
+ case FUTEX_OP_CMP_GE: return oldval >= cmparg;
|
|
+ }
|
|
+ return -1;
|
|
+}
|
|
+#endif
|
|
+
|
|
static long do_futex(target_ulong uaddr, int op, uint32_t val,
|
|
target_ulong utime, target_ulong uaddr2,
|
|
uint32_t val3)
|
|
{
|
|
struct timespec host_utime;
|
|
unsigned long val2 = utime;
|
|
+ long retval;
|
|
|
|
if (utime && (op == FUTEX_WAIT || op == FUTEX_LOCK_PI)) {
|
|
@@ -2141,6 +2170,7 @@ static long do_futex(target_ulong uaddr,
|
|
}
|
|
|
|
#ifdef BSWAP_NEEDED
|
|
+// if( op == FUTEX_WAKE_OP ) { gemu_log("FUTEX_WAKE_OP -> FUTEX_WAKE\n"); op = FUTEX_WAKE; sleep(1); }
|
|
switch(op) {
|
|
case FUTEX_CMP_REQUEUE:
|
|
val3 = tswap32(val3);
|
|
@@ -2148,41 +2178,40 @@ static long do_futex(target_ulong uaddr,
|
|
val2 = tswap32(val2);
|
|
case FUTEX_WAIT:
|
|
case FUTEX_WAKE:
|
|
+ case FUTEX_WAKE_OP:
|
|
val = tswap32(val);
|
|
case FUTEX_LOCK_PI: /* This one's icky, but comes out OK */
|
|
case FUTEX_UNLOCK_PI:
|
|
break;
|
|
default:
|
|
gemu_log("qemu: Unsupported futex op %d\n", op);
|
|
+ spin_unlock(&mmap_lock);
|
|
return -ENOSYS;
|
|
}
|
|
-#if 0 /* No, it's worse than this */
|
|
if (op == FUTEX_WAKE_OP) {
|
|
/* Need to munge the secondary operation (val3) */
|
|
val3 = tswap32(val3);
|
|
- int op2 = (val3 >> 28) & 7;
|
|
- int cmp = (val3 >> 24) & 15;
|
|
- int oparg = (val3 << 8) >> 20;
|
|
- int cmparg = (val3 << 20) >> 20;
|
|
+ int op2 = (val3 >> 28) & 0xf;
|
|
+ int cmp = (val3 >> 24) & 0xf;
|
|
+ int oparg = (val3 >> 12) & 0xfff;
|
|
+ int cmparg = val3 & 0xfff;
|
|
int shift = val3 & (FUTEX_OP_OPARG_SHIFT << 28);
|
|
-
|
|
+ int oldval = tget32(uaddr2);
|
|
if (shift)
|
|
- oparg = (oparg & 7) + 24 - (oparg & 24);
|
|
- else oparg =
|
|
- if (op2 == FUTEX_OP_ADD) {
|
|
- gemu_log("qemu: Unsupported wrong-endian FUTEX_OP_ADD\n");
|
|
- return -ENOSYS;
|
|
- }
|
|
- if (cmparg == FUTEX_OP_CMP_LT || cmparg == FUTEX_OP_CMP_GE ||
|
|
- cmparg == FUTEX_OP_CMP_LE || cmparg == FUTEX_OP_CMP_GT) {
|
|
- gemu_log("qemu: Unsupported wrong-endian futex cmparg %d\n", cmparg);
|
|
- return -ENOSYS;
|
|
- }
|
|
- val3 = shift | (op2<<28) | (cmp<<24) | (oparg<<12) | cmparg;
|
|
+ oparg = 1 << oparg;
|
|
+
|
|
+ tput32(uaddr2,futex_op(oldval, op2, oparg));
|
|
+ retval = syscall(__NR_futex, g2h(uaddr), FUTEX_WAKE, val, 0, 0, 0);
|
|
+ if(futex_cmp(oldval, cmp, cmparg)) {
|
|
+ retval = syscall(__NR_futex, g2h(uaddr2), FUTEX_WAKE, val2, 0, 0, 0);
|
|
+ }
|
|
+ } else {
|
|
+ retval = syscall(__NR_futex, g2h(uaddr), op, val, val2, g2h(uaddr2), val3);
|
|
}
|
|
-#endif
|
|
+#else
|
|
+ retval = syscall(__NR_futex, g2h(uaddr), op, val, val2, g2h(uaddr2), val3);
|
|
#endif
|
|
- return syscall(__NR_futex, g2h(uaddr), op, val, val2, g2h(uaddr2), val3);
|
|
+ return retval;
|
|
}
|
|
|
|
int do_set_tid_address(target_ulong tidptr)
|