Date: Sun, 21 Aug 2016 15:36:18 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304558 - head/sys/compat/cloudabi64 Message-ID: <201608211536.u7LFaIkb052542@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Sun Aug 21 15:36:18 2016 New Revision: 304558 URL: https://svnweb.freebsd.org/changeset/base/304558 Log: Add a utility macro for converting 64-bit pointers to native pointers. Right now we're casting uint64_t's to native pointers. This isn't causing any problems right now, but if we want to provide a 32-bit compatibility layer that works on 64-bit systems as well, this will cause problems. Casting a uint32_t to a 64-bit pointer throws a compiler error. Introduce a TO_PTR() macro that casts the value to uintptr_t before casting it to a pointer. Modified: head/sys/compat/cloudabi64/cloudabi64_fd.c head/sys/compat/cloudabi64/cloudabi64_poll.c head/sys/compat/cloudabi64/cloudabi64_sock.c head/sys/compat/cloudabi64/cloudabi64_util.h Modified: head/sys/compat/cloudabi64/cloudabi64_fd.c ============================================================================== --- head/sys/compat/cloudabi64/cloudabi64_fd.c Sun Aug 21 15:14:06 2016 (r304557) +++ head/sys/compat/cloudabi64/cloudabi64_fd.c Sun Aug 21 15:36:18 2016 (r304558) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <contrib/cloudabi/cloudabi64_types.h> #include <compat/cloudabi64/cloudabi64_proto.h> +#include <compat/cloudabi64/cloudabi64_util.h> /* Copies in 64-bit iovec structures from userspace. */ static int @@ -70,7 +71,7 @@ cloudabi64_copyinuio(const cloudabi64_io free(uio, M_IOV); return (error); } - iov[i].iov_base = (void *)iovobj.iov_base; + iov[i].iov_base = TO_PTR(iovobj.iov_base); iov[i].iov_len = iovobj.iov_len; if (iov[i].iov_len > INT64_MAX - uio->uio_resid) { free(uio, M_IOV); @@ -105,8 +106,7 @@ cloudabi64_sys_fd_pwrite(struct thread * struct uio *uio; int error; - error = cloudabi64_copyinuio((const cloudabi64_iovec_t *)uap->iov, - uap->iovcnt, &uio); + error = cloudabi64_copyinuio(TO_PTR(uap->iov), uap->iovcnt, &uio); if (error != 0) return (error); error = kern_pwritev(td, uap->fd, uio, uap->offset); @@ -136,8 +136,7 @@ cloudabi64_sys_fd_write(struct thread *t struct uio *uio; int error; - error = cloudabi64_copyinuio((const cloudabi64_iovec_t *)uap->iov, - uap->iovcnt, &uio); + error = cloudabi64_copyinuio(TO_PTR(uap->iov), uap->iovcnt, &uio); if (error != 0) return (error); error = kern_writev(td, uap->fd, uio); Modified: head/sys/compat/cloudabi64/cloudabi64_poll.c ============================================================================== --- head/sys/compat/cloudabi64/cloudabi64_poll.c Sun Aug 21 15:14:06 2016 (r304557) +++ head/sys/compat/cloudabi64/cloudabi64_poll.c Sun Aug 21 15:36:18 2016 (r304558) @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include <compat/cloudabi/cloudabi_util.h> #include <compat/cloudabi64/cloudabi64_proto.h> +#include <compat/cloudabi64/cloudabi64_util.h> /* Converts a FreeBSD signal number to a CloudABI signal number. */ static cloudabi_signal_t @@ -98,7 +99,7 @@ cloudabi64_kevent_copyin(void *arg, stru return (error); memset(kevp, 0, sizeof(*kevp)); - kevp->udata = (void *)sub.userdata; + kevp->udata = TO_PTR(sub.userdata); switch (sub.type) { case CLOUDABI_EVENTTYPE_CLOCK: kevp->filter = EVFILT_TIMER; @@ -264,9 +265,9 @@ cloudabi64_sys_poll(struct thread *td, s ev.condvar.condvar = sub.condvar.condvar; ev.error = cloudabi_convert_errno( cloudabi_futex_condvar_wait( - td, (cloudabi_condvar_t *)sub.condvar.condvar, + td, TO_PTR(sub.condvar.condvar), sub.condvar.condvar_scope, - (cloudabi_lock_t *)sub.condvar.lock, + TO_PTR(sub.condvar.lock), sub.condvar.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; @@ -276,7 +277,7 @@ cloudabi64_sys_poll(struct thread *td, s ev.lock.lock = sub.lock.lock; ev.error = cloudabi_convert_errno( cloudabi_futex_lock_rdlock( - td, (cloudabi_lock_t *)sub.lock.lock, + td, TO_PTR(sub.lock.lock), sub.lock.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; @@ -286,7 +287,7 @@ cloudabi64_sys_poll(struct thread *td, s ev.lock.lock = sub.lock.lock; ev.error = cloudabi_convert_errno( cloudabi_futex_lock_wrlock( - td, (cloudabi_lock_t *)sub.lock.lock, + td, TO_PTR(sub.lock.lock), sub.lock.lock_scope, CLOUDABI_CLOCK_MONOTONIC, UINT64_MAX, 0)); td->td_retval[0] = 1; @@ -311,9 +312,9 @@ cloudabi64_sys_poll(struct thread *td, s ev[0].condvar.condvar = sub[0].condvar.condvar; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_condvar_wait( - td, (cloudabi_condvar_t *)sub[0].condvar.condvar, + td, TO_PTR(sub[0].condvar.condvar), sub[0].condvar.condvar_scope, - (cloudabi_lock_t *)sub[0].condvar.lock, + TO_PTR(sub[0].condvar.lock), sub[0].condvar.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { @@ -332,7 +333,7 @@ cloudabi64_sys_poll(struct thread *td, s ev[0].lock.lock = sub[0].lock.lock; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_lock_rdlock( - td, (cloudabi_lock_t *)sub[0].lock.lock, + td, TO_PTR(sub[0].lock.lock), sub[0].lock.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { @@ -351,7 +352,7 @@ cloudabi64_sys_poll(struct thread *td, s ev[0].lock.lock = sub[0].lock.lock; ev[1].clock.identifier = sub[1].clock.identifier; error = cloudabi_futex_lock_wrlock( - td, (cloudabi_lock_t *)sub[0].lock.lock, + td, TO_PTR(sub[0].lock.lock), sub[0].lock.lock_scope, sub[1].clock.clock_id, sub[1].clock.timeout, sub[1].clock.precision); if (error == ETIMEDOUT) { Modified: head/sys/compat/cloudabi64/cloudabi64_sock.c ============================================================================== --- head/sys/compat/cloudabi64/cloudabi64_sock.c Sun Aug 21 15:14:06 2016 (r304557) +++ head/sys/compat/cloudabi64/cloudabi64_sock.c Sun Aug 21 15:36:18 2016 (r304558) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include <compat/cloudabi/cloudabi_util.h> #include <compat/cloudabi64/cloudabi64_proto.h> +#include <compat/cloudabi64/cloudabi64_util.h> static MALLOC_DEFINE(M_SOCKET, "socket", "CloudABI socket"); @@ -52,6 +53,7 @@ cloudabi64_sys_sock_recv(struct thread * cloudabi64_recv_out_t ro = {}; cloudabi64_iovec_t iovobj; struct msghdr msghdr = {}; + const cloudabi64_iovec_t *user_iov; size_t i; int error; @@ -65,14 +67,14 @@ cloudabi64_sys_sock_recv(struct thread * msghdr.msg_iovlen = ri.ri_datalen; msghdr.msg_iov = malloc(msghdr.msg_iovlen * sizeof(struct iovec), M_SOCKET, M_WAITOK); + user_iov = TO_PTR(ri.ri_data); for (i = 0; i < msghdr.msg_iovlen; i++) { - error = copyin(&((cloudabi64_iovec_t *)ri.ri_data)[i], &iovobj, - sizeof(iovobj)); + error = copyin(&user_iov[i], &iovobj, sizeof(iovobj)); if (error != 0) { free(msghdr.msg_iov, M_SOCKET); return (error); } - msghdr.msg_iov[i].iov_base = (void *)iovobj.iov_base; + msghdr.msg_iov[i].iov_base = TO_PTR(iovobj.iov_base); msghdr.msg_iov[i].iov_len = iovobj.iov_len; } msghdr.msg_name = &ss; @@ -104,6 +106,7 @@ cloudabi64_sys_sock_send(struct thread * cloudabi64_send_out_t so = {}; cloudabi64_ciovec_t iovobj; struct msghdr msghdr = {}; + const cloudabi64_ciovec_t *user_iov; size_t i; int error, flags; @@ -117,14 +120,14 @@ cloudabi64_sys_sock_send(struct thread * msghdr.msg_iovlen = si.si_datalen; msghdr.msg_iov = malloc(msghdr.msg_iovlen * sizeof(struct iovec), M_SOCKET, M_WAITOK); + user_iov = TO_PTR(si.si_data); for (i = 0; i < msghdr.msg_iovlen; i++) { - error = copyin(&((cloudabi64_ciovec_t *)si.si_data)[i], &iovobj, - sizeof(iovobj)); + error = copyin(&user_iov[i], &iovobj, sizeof(iovobj)); if (error != 0) { free(msghdr.msg_iov, M_SOCKET); return (error); } - msghdr.msg_iov[i].iov_base = (void *)iovobj.iov_base; + msghdr.msg_iov[i].iov_base = TO_PTR(iovobj.iov_base); msghdr.msg_iov[i].iov_len = iovobj.iov_len; } Modified: head/sys/compat/cloudabi64/cloudabi64_util.h ============================================================================== --- head/sys/compat/cloudabi64/cloudabi64_util.h Sun Aug 21 15:14:06 2016 (r304557) +++ head/sys/compat/cloudabi64/cloudabi64_util.h Sun Aug 21 15:36:18 2016 (r304558) @@ -38,6 +38,8 @@ struct thread; extern Elf64_Brandinfo cloudabi64_brand; +#define TO_PTR(x) ((void *)(uintptr_t)(x)) + /* Stack initialization during process execution. */ register_t *cloudabi64_copyout_strings(struct image_params *); int cloudabi64_fixup(register_t **, struct image_params *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608211536.u7LFaIkb052542>