Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linux/linux_futex.c
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
LIN_SDT_PROBE_DEFINE1(futex, fetch_robust_entry, copyin_error, "int"); | LIN_SDT_PROBE_DEFINE1(futex, fetch_robust_entry, copyin_error, "int"); | ||||
LIN_SDT_PROBE_DEFINE1(futex, release_futexes, copyin_error, "int"); | LIN_SDT_PROBE_DEFINE1(futex, release_futexes, copyin_error, "int"); | ||||
#define FUTEX_SHARED 0x8 /* shared futex */ | #define FUTEX_SHARED 0x8 /* shared futex */ | ||||
#define GET_SHARED(a) (a->flags & FUTEX_SHARED) ? AUTO_SHARE : THREAD_SHARE | #define GET_SHARED(a) (a->flags & FUTEX_SHARED) ? AUTO_SHARE : THREAD_SHARE | ||||
static int futex_atomic_op(struct thread *, int, uint32_t *); | static int futex_atomic_op(struct thread *, int, uint32_t *); | ||||
static int handle_futex_death(struct linux_emuldata *, uint32_t *, | static int handle_futex_death(struct thread *td, struct linux_emuldata *, | ||||
unsigned int); | uint32_t *, unsigned int); | ||||
static int fetch_robust_entry(struct linux_robust_list **, | static int fetch_robust_entry(struct linux_robust_list **, | ||||
struct linux_robust_list **, unsigned int *); | struct linux_robust_list **, unsigned int *); | ||||
struct linux_futex_args { | struct linux_futex_args { | ||||
uint32_t *uaddr; | uint32_t *uaddr; | ||||
int32_t op; | int32_t op; | ||||
uint32_t flags; | uint32_t flags; | ||||
bool clockrt; | bool clockrt; | ||||
▲ Show 20 Lines • Show All 857 Lines • ▼ Show 20 Lines | if (error) { | ||||
LIN_SDT_PROBE1(futex, linux_get_robust_list, copyout_error, | LIN_SDT_PROBE1(futex, linux_get_robust_list, copyout_error, | ||||
error); | error); | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
handle_futex_death(struct linux_emuldata *em, uint32_t *uaddr, | handle_futex_death(struct thread *td, struct linux_emuldata *em, uint32_t *uaddr, | ||||
unsigned int pi) | unsigned int pi) | ||||
{ | { | ||||
uint32_t uval, nval, mval; | uint32_t uval, nval, mval; | ||||
int error; | int error; | ||||
retry: | retry: | ||||
error = fueword32(uaddr, &uval); | error = fueword32(uaddr, &uval); | ||||
if (error != 0) | if (error != 0) | ||||
return (EFAULT); | return (EFAULT); | ||||
if ((uval & FUTEX_TID_MASK) == em->em_tid) { | if ((uval & FUTEX_TID_MASK) == em->em_tid) { | ||||
mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED; | mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED; | ||||
nval = casuword32(uaddr, uval, mval); | error = casueword32(uaddr, uval, &nval, mval); | ||||
if (error == -1) | |||||
if (nval == -1) | |||||
return (EFAULT); | return (EFAULT); | ||||
if (error == 1) { | |||||
if (nval != uval) | error = thread_check_susp(td, false); | ||||
if (error != 0) | |||||
kib: error != 0 | |||||
return (error); | |||||
goto retry; | goto retry; | ||||
} | |||||
Not Done Inline ActionsThis is fine as the step, but please look at 30b3018d48e4441083b483 kib: This is fine as the step, but please look at 30b3018d48e4441083b483 | |||||
Not Done Inline Actionssure, did I understand correctly that on ll/sc architectures casueword can fails as there are two operations, dchagin: sure, did I understand correctly that on ll/sc architectures casueword can fails as there are… | |||||
Not Done Inline ActionsRight. Generally casueword is allowed to spuriously fail on all arches, same as cmpset/fcmpset. kib: Right. Generally casueword is allowed to spuriously fail on all arches, same as cmpset/fcmpset. | |||||
if (!pi && (uval & FUTEX_WAITERS)) { | if (!pi && (uval & FUTEX_WAITERS)) { | ||||
error = futex_wake(curthread, uaddr, 1, true); | error = futex_wake(td, uaddr, 1, true); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
} else if (pi && (uval & FUTEX_WAITERS)) { | } else if (pi && (uval & FUTEX_WAITERS)) { | ||||
error = futex_wake_pi(curthread, uaddr, true); | error = futex_wake_pi(td, uaddr, true); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | release_futexes(struct thread *td, struct linux_emuldata *em) | ||||
if (fetch_robust_entry(&pending, PTRIN(&head->pending_list), &pip)) | if (fetch_robust_entry(&pending, PTRIN(&head->pending_list), &pip)) | ||||
return; | return; | ||||
while (entry != &head->list) { | while (entry != &head->list) { | ||||
rc = fetch_robust_entry(&next_entry, PTRIN(&entry->next), &next_pi); | rc = fetch_robust_entry(&next_entry, PTRIN(&entry->next), &next_pi); | ||||
if (entry != pending) | if (entry != pending) | ||||
if (handle_futex_death(em, | if (handle_futex_death(td, em, | ||||
(uint32_t *)((caddr_t)entry + futex_offset), pi)) { | (uint32_t *)((caddr_t)entry + futex_offset), pi)) { | ||||
return; | return; | ||||
} | } | ||||
if (rc) | if (rc) | ||||
return; | return; | ||||
entry = next_entry; | entry = next_entry; | ||||
pi = next_pi; | pi = next_pi; | ||||
if (!--limit) | if (!--limit) | ||||
break; | break; | ||||
sched_relinquish(curthread); | sched_relinquish(curthread); | ||||
} | } | ||||
if (pending) | if (pending) | ||||
handle_futex_death(em, (uint32_t *)((caddr_t)pending + futex_offset), pip); | handle_futex_death(td, em, | ||||
(uint32_t *)((caddr_t)pending + futex_offset), pip); | |||||
} | } |
error != 0