align <sys/ucontext.h> <sys/uio.h> <sys/un.h>

Change-Id: I70adf01fddf931a3a6931083adaa4bbe647ea6a3
This commit is contained in:
Ben Gras 2013-12-10 09:57:38 +01:00 committed by Lionel Sambuc
parent 01624e6f86
commit 17587738d3
15 changed files with 274 additions and 85 deletions

View file

@ -69,7 +69,8 @@ do_accept(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
for (i = 0; i < NR_FDS; i++) {
if (uds_fd_table[i].addr.sun_family == AF_UNIX &&
!strncmp(addr.sun_path, uds_fd_table[i].addr.sun_path,
UNIX_PATH_MAX) && uds_fd_table[i].listening == 1)
sizeof(uds_fd_table[i].addr.sun_path)) &&
uds_fd_table[i].listening == 1)
break;
}
@ -167,7 +168,7 @@ do_connect(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
return rc;
if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path,
UNIX_PATH_MAX)) != OK)
sizeof(addr.sun_path))) != OK)
return rc;
/*
@ -182,7 +183,7 @@ do_connect(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
if (uds_fd_table[i].addr.sun_family != AF_UNIX)
continue;
if (strncmp(addr.sun_path, uds_fd_table[i].addr.sun_path,
UNIX_PATH_MAX))
sizeof(uds_fd_table[i].addr.sun_path)))
continue;
/* Found a matching socket. */
@ -356,14 +357,14 @@ do_bind(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
return ENOENT;
if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path,
UNIX_PATH_MAX)) != OK)
sizeof(addr.sun_path))) != OK)
return rc;
/* Make sure the address isn't already in use by another socket. */
for (i = 0; i < NR_FDS; i++) {
if (uds_fd_table[i].addr.sun_family == AF_UNIX &&
!strncmp(addr.sun_path, uds_fd_table[i].addr.sun_path,
UNIX_PATH_MAX)) {
sizeof(uds_fd_table[i].addr.sun_path))) {
/* Another socket is bound to this sun_path. */
return EADDRINUSE;
}
@ -612,7 +613,7 @@ do_sendto(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
return EINVAL;
if ((rc = checkperms(uds_fd_table[minor].owner, addr.sun_path,
UNIX_PATH_MAX)) != OK)
sizeof(addr.sun_path))) != OK)
return rc;
memcpy(&uds_fd_table[minor].target, &addr, sizeof(struct sockaddr_un));
@ -826,7 +827,8 @@ do_sendmsg(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant)
if (uds_fd_table[i].type == SOCK_DGRAM &&
uds_fd_table[i].addr.sun_family == AF_UNIX &&
!strncmp(uds_fd_table[minor].target.sun_path,
uds_fd_table[i].addr.sun_path, UNIX_PATH_MAX)) {
uds_fd_table[i].addr.sun_path,
sizeof(uds_fd_table[i].addr.sun_path))) {
peer = i;
break;
}

View file

@ -391,7 +391,8 @@ uds_perform_write(devminor_t minor, endpoint_t endpt, cp_grant_id_t grant,
if (uds_fd_table[i].type == SOCK_DGRAM &&
uds_fd_table[i].addr.sun_family == AF_UNIX &&
!strncmp(uds_fd_table[minor].target.sun_path,
uds_fd_table[i].addr.sun_path, UNIX_PATH_MAX)) {
uds_fd_table[i].addr.sun_path,
sizeof(uds_fd_table[i].addr.sun_path))) {
peer = i;
break;
}

View file

@ -7,18 +7,6 @@ IMPORT(setuctx)
IMPORT(resumecontext)
/* MCF_MAGIC value from <mcontext.h> */
#define MCF_MAGIC 0xc0ffee
/* Values from <sys/ucontext.h> */
#define UCF_IGNFPU 0x002
#define UCF_IGNSIGM 0x004
/* EINVAL from errno.h */
#define EFAULT 14
#define EINVAL 22
/* int getcontext(ucontext_t *ucp)
* Initialise the structure pointed to by ucp to the current user context
* of the calling thread. */
@ -45,9 +33,9 @@ ENTRY(getcontext)
3: /* Check flags */
ldr r1, [r0, #UC_FLAGS] /* r1 = ucp->uc_flags */
mov r2, #(UCF_IGNFPU | UCF_IGNSIGM)
cmp r1, r2 /* is UCF_IGNFPU or UCF_IGNSIGM set? */
beq 1f /* Both are set, skip getuctx */
and r1, r1, #[_UC_IGNFPU|_UC_IGNSIGM]
cmp r1, #[_UC_IGNFPU|_UC_IGNSIGM] /* Allowed to ignore both? */
beq 1f /* If so, skip getuctx */
0:
push {r0, r3}
@ -116,9 +104,9 @@ ENTRY(setcontext)
4: ldr r1, [r0, #UC_FLAGS] /* r1 = ucp->uc_flags */
mov r2, #(UCF_IGNFPU | UCF_IGNSIGM)
cmp r1, r2 /* Are UCF_IGNFPU and UCF_IGNSIGM flags set? */
beq 1f /* Both are set, so don't bother restoring FPU
and r1, r1, #[_UC_IGNFPU|_UC_IGNSIGM]
cmp r1, #[_UC_IGNFPU|_UC_IGNSIGM] /* Allowed to ignore both? */
beq 1f /* Neither are set, so don't bother restoring FPU
* state and signal mask */
push {r0, r3}

View file

@ -1,6 +1,8 @@
include <minix/type.h>
include <sys/ucontext.h>
include <sys/errno.h>
include <machine/mcontext.h>
struct __ucontext
member UC_FLAGS uc_flags
@ -22,4 +24,8 @@ member REG12 uc_mcontext.mc_p_reg.r12
member SPREG uc_mcontext.mc_p_reg.sp
member LRREG uc_mcontext.mc_p_reg.lr
member PCREG uc_mcontext.mc_p_reg.pc
define EFAULT EFAULT
define EINVAL EINVAL
define MCF_MAGIC MCF_MAGIC
define _UC_IGNFPU _UC_IGNFPU
define _UC_IGNSIGM _UC_IGNSIGM

View file

@ -7,19 +7,6 @@ IMPORT(resumecontext)
.globl _C_LABEL(__errno)
/* MCF_MAGIC value from <mcontext.h> */
#define MCF_MAGIC 0xc0ffee
/* Values from <sys/ucontext.h> */
#define UCF_IGNFPU 0x002
#define UCF_IGNSIGM 0x004
/* EINVAL from errno.h */
#define EFAULT 14
#define EINVAL 22
/* int getcontext(ucontext_t *ucp)
* Initialise the structure pointed to by ucp to the current user context
* of the calling thread. */
@ -42,8 +29,9 @@ ENTRY(getcontext)
3: /* Check flags */
mov UC_FLAGS(%edx), %eax /* eax = ucp->uc_flags */
xor $[UCF_IGNFPU|UCF_IGNSIGM], %eax /* toggle both flags */
jz 5f /* Both were set, skip getuctx */
and $[_UC_IGNFPU|_UC_IGNSIGM], %eax
cmp $[_UC_IGNFPU|_UC_IGNSIGM], %eax
jz 5f /* Ignore both, skip getuctx */
PIC_PROLOGUE
push %edx
call PIC_PLT(_C_LABEL(getuctx)) /* getuctx(ucp) */
@ -101,8 +89,9 @@ ENTRY(setcontext)
4: mov UC_FLAGS(%edx), %eax /* eax = ucp->uc_flags */
xor $[UCF_IGNFPU|UCF_IGNSIGM], %eax /* toggle both flags */
jz 5f /* Both are set, so don't bother restoring FPU
and $[_UC_IGNFPU|_UC_IGNSIGM], %eax
cmp $[_UC_IGNFPU|_UC_IGNSIGM], %eax
jz 5f /* Ignore both, so don't bother restoring FPU
* state and signal mask */
PIC_PROLOGUE

View file

@ -1,6 +1,8 @@
include <minix/type.h>
include <sys/ucontext.h>
include <sys/errno.h>
include <machine/mcontext.h>
struct __ucontext
member UC_FLAGS uc_flags
@ -15,4 +17,8 @@ member CX uc_mcontext.mc_p_reg.cx
member DX uc_mcontext.mc_p_reg.dx
member PC uc_mcontext.mc_p_reg.pc
member SP uc_mcontext.mc_p_reg.sp
define EFAULT EFAULT
define EINVAL EINVAL
define MCF_MAGIC MCF_MAGIC
define _UC_IGNFPU _UC_IGNFPU
define _UC_IGNSIGM _UC_IGNSIGM

View file

@ -25,13 +25,13 @@ int setuctx(const ucontext_t *ucp)
return(-1);
}
if (!(ucp->uc_flags & UCF_IGNSIGM)) {
if (!(ucp->uc_flags & _UC_IGNSIGM)) {
/* Set signal mask */
if ((r = sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL)) == -1)
return(r);
}
if (!(ucp->uc_flags & UCF_IGNFPU)) {
if (!(ucp->uc_flags & _UC_IGNFPU)) {
if ((r = setmcontext(&(ucp->uc_mcontext))) == -1)
return(r);
}
@ -52,13 +52,13 @@ int getuctx(ucontext_t *ucp)
return(-1);
}
if (!(ucp->uc_flags & UCF_IGNSIGM)) {
if (!(ucp->uc_flags & _UC_IGNSIGM)) {
/* Get signal mask */
if ((r = sigprocmask(0, NULL, &ucp->uc_sigmask)) == -1)
return(r);
}
if (!(ucp->uc_flags & UCF_IGNFPU)) {
if (!(ucp->uc_flags & _UC_IGNFPU)) {
if ((r = getmcontext(&(ucp->uc_mcontext))) != 0)
return(r);
}
@ -232,10 +232,10 @@ int swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
return(-1);
}
oucp->uc_flags &= ~UCF_SWAPPED;
oucp->uc_flags &= ~_UC_SWAPPED;
r = getcontext(oucp);
if ((r == 0) && !(oucp->uc_flags & UCF_SWAPPED)) {
oucp->uc_flags |= UCF_SWAPPED;
if ((r == 0) && !(oucp->uc_flags & _UC_SWAPPED)) {
oucp->uc_flags |= _UC_SWAPPED;
r = setcontext(ucp);
}

View file

@ -4,6 +4,9 @@
#undef NDEBUG
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/ioc_net.h>
#include <sys/socket.h>

View file

@ -20,7 +20,7 @@ ucontext_t *ctx;
/* We're not interested in FPU state nor signals, so ignore them.
* Coincidentally, this significantly speeds up performance.
*/
ctx->uc_flags |= (UCF_IGNFPU | UCF_IGNSIGM);
ctx->uc_flags |= _UC_IGNSIGM | _UC_IGNFPU;
return getcontext(ctx);
}

View file

@ -828,9 +828,10 @@ size_t pathlen;
struct fproc *rfp;
char canon_path[PATH_MAX];
struct lookup resolve;
struct sockaddr_un sun;
if (isokendpt(ep, &slot) != OK) return(EINVAL);
if (pathlen < UNIX_PATH_MAX || pathlen >= PATH_MAX) return(EINVAL);
if (pathlen < sizeof(sun.sun_path) || pathlen >= PATH_MAX) return(EINVAL);
rfp = &(fproc[slot]);
r = sys_safecopyfrom(who_e, io_gr, (vir_bytes) 0, (vir_bytes) canon_path,

View file

@ -40,9 +40,9 @@ typedef struct __ucontext ucontext_t;
struct __ucontext {
unsigned int uc_flags; /* properties */
ucontext_t * uc_link; /* context to resume */
mcontext_t uc_mcontext; /* machine state */
sigset_t uc_sigmask; /* signals blocked in this context */
stack_t uc_stack; /* the stack used by this context */
mcontext_t uc_mcontext; /* machine state */
#if defined(_UC_MACHINE_PAD)
long __uc_pad[_UC_MACHINE_PAD];
#endif
@ -52,16 +52,81 @@ struct __ucontext {
#define _UC_UCONTEXT_ALIGN (~0)
#endif
#define UCF_SWAPPED 001 /* Context has been swapped in by swapcontext(3) */
#define UCF_IGNFPU 002 /* Ignore FPU context by get or setcontext(3) */
#define UCF_IGNSIGM 004 /* Ignore signal mask by get or setcontext(3) */
/* uc_flags */
#define _UC_SIGMASK 0x01 /* valid uc_sigmask */
#define _UC_STACK 0x02 /* valid uc_stack */
#define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */
#define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */
#ifdef __minix
#define _UC_SWAPPED 0x10000
#define _UC_IGNFPU 0x20000
#define _UC_IGNSIGM 0x40000
#endif
#define _UC_MD 0x400f0020 /* MD bits. see below */
#define NCARGS 6
/*
* if your port needs more MD bits, please try to choose bits from _UC_MD
* first, rather than picking random unused bits.
*
* _UC_MD details
*
* _UC_TLSBASE Context contains valid pthread private pointer
* All ports must define this MD flag
* 0x00040000 hppa, mips
* 0x00000020 alpha
* 0x00080000 all other ports
*
* _UC_SETSTACK Context uses signal stack
* 0x00020000 arm
* [undefined] alpha, powerpc and vax
* 0x00010000 other ports
*
* _UC_CLRSTACK Context does not use signal stack
* 0x00040000 arm
* [undefined] alpha, powerpc and vax
* 0x00020000 other ports
*
* _UC_POWERPC_VEC Context does not use signal stack
* 0x00010000 powerpc only
*
* _UC_POWERPC_SPE Context contains valid SPE context
* 0x00020000 powerpc only
*
* _UC_M68K_UC_USER Used by m68k machdep code, but undocumented
* 0x40000000 m68k only
*
* _UC_ARM_VFP Unused
* 0x00010000 arm only
*
* _UC_VM Context contains valid virtual 8086 context
* 0x00040000 i386, amd64 only
*
* _UC_FXSAVE Context contains FPU context in that
* is in FXSAVE format in XMM space
* 0x00000020 i386, amd64 only
*/
#ifdef _KERNEL
struct lwp;
#ifdef __UCONTEXT_SIZE
__CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE);
#endif
void getucontext(struct lwp *, ucontext_t *);
int setucontext(struct lwp *, const ucontext_t *);
void cpu_getmcontext(struct lwp *, mcontext_t *, unsigned int *);
int cpu_setmcontext(struct lwp *, const mcontext_t *, unsigned int);
int cpu_mcontext_validate(struct lwp *, const mcontext_t *);
#endif /* _KERNEL */
#ifdef __minix
__BEGIN_DECLS
void resumecontext(ucontext_t *ucp);
#ifdef __UCONTEXT_SIZE
__CTASSERT(sizeof(ucontext_t) == __UCONTEXT_SIZE);
#endif
/* These functions get and set ucontext structure through PM/kernel. They don't
* manipulate the stack. */
int getuctx(ucontext_t *ucp);

View file

@ -34,6 +34,12 @@
#ifndef _SYS_UIO_H_
#define _SYS_UIO_H_
#ifdef _KERNEL
#ifndef __UIO_EXPOSE
#define __UIO_EXPOSE
#endif
#endif
#include <machine/ansi.h>
#include <sys/featuretest.h>
@ -53,6 +59,37 @@ struct iovec {
};
#if defined(_NETBSD_SOURCE)
#include <sys/ansi.h>
#ifndef off_t
typedef __off_t off_t; /* file offset */
#define off_t __off_t
#endif
enum uio_rw { UIO_READ, UIO_WRITE };
/* Segment flag values. */
enum uio_seg {
UIO_USERSPACE, /* from user data space */
UIO_SYSSPACE /* from system space */
};
#ifdef __UIO_EXPOSE
struct vmspace;
struct uio {
struct iovec *uio_iov; /* pointer to array of iovecs */
int uio_iovcnt; /* number of iovecs in array */
off_t uio_offset; /* offset into file this uio corresponds to */
size_t uio_resid; /* residual i/o count */
enum uio_rw uio_rw; /* see above */
struct vmspace *uio_vmspace;
};
#define UIO_SETUP_SYSSPACE(uio) uio_setup_sysspace(uio)
#endif /* __UIO_EXPOSE */
/*
* Limits
*/
@ -60,11 +97,27 @@ struct iovec {
#define UIO_MAXIOV 1024 /* max 1K of iov's */
#endif /* _NETBSD_SOURCE */
#ifdef _KERNEL
/* 8 on stack, more will be dynamically allocated. */
#define UIO_SMALLIOV 8
void uio_setup_sysspace(struct uio *);
#endif
#ifndef _KERNEL
#include <sys/cdefs.h>
__BEGIN_DECLS
#if defined(_NETBSD_SOURCE)
ssize_t preadv(int, const struct iovec *, int, off_t);
ssize_t pwritev(int, const struct iovec *, int, off_t);
#endif /* _NETBSD_SOURCE */
ssize_t readv(int, const struct iovec *, int);
ssize_t writev(int, const struct iovec *, int);
__END_DECLS
#else
int ureadc(int, struct uio *);
#endif /* !_KERNEL */
#endif /* !_SYS_UIO_H_ */

View file

@ -1,3 +1,36 @@
/* $NetBSD: un.h,v 1.46 2011/06/26 16:43:12 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)un.h 8.3 (Berkeley) 2/19/95
*/
#ifndef _SYS_UN_H_
#define _SYS_UN_H_
@ -10,26 +43,68 @@ typedef __sa_family_t sa_family_t;
#define sa_family_t __sa_family_t
#endif
#define UNIX_PATH_MAX 127
/*
* Definitions for UNIX IPC domain.
*/
struct sockaddr_un {
uint8_t sun_len;
sa_family_t sun_family;
char sun_path[UNIX_PATH_MAX];
uint8_t sun_len; /* total sockaddr length */
sa_family_t sun_family; /* AF_LOCAL */
char sun_path[104]; /* path name (gag) */
};
#include <string.h>
/* Compute the actual length of a struct sockaddr_un pointed
* to by 'unp'. sun_path must be NULL terminated. Length does
* not include the NULL byte. This is not a POSIX standard
* definition, but BSD and Linux have it, so it is here for
* compatibility.
/*
* Socket options for UNIX IPC domain.
*/
#define SUN_LEN(unp) \
((size_t)((sizeof(*(unp)) - sizeof((unp)->sun_path)) + strlen((unp)->sun_path)))
#if defined(_NETBSD_SOURCE)
#define LOCAL_CREDS 0x0001 /* pass credentials to receiver */
#define LOCAL_CONNWAIT 0x0002 /* connects block until accepted */
#define LOCAL_PEEREID 0x0003 /* get peer identification */
#endif
#endif /* _SYS_UN_H_ */
/*
* Data automatically stored inside connect() for use by LOCAL_PEEREID
*/
struct unpcbid {
pid_t unp_pid; /* process id */
uid_t unp_euid; /* effective user id */
gid_t unp_egid; /* effective group id */
};
#ifdef _KERNEL
struct unpcb;
struct socket;
struct sockopt;
int uipc_usrreq(struct socket *, int, struct mbuf *,
struct mbuf *, struct mbuf *, struct lwp *);
int uipc_ctloutput(int, struct socket *, struct sockopt *);
void uipc_init (void);
kmutex_t *uipc_dgramlock (void);
kmutex_t *uipc_streamlock (void);
kmutex_t *uipc_rawlock (void);
int unp_attach (struct socket *);
int unp_bind (struct socket *, struct mbuf *, struct lwp *);
int unp_connect (struct socket *, struct mbuf *, struct lwp *);
int unp_connect2 (struct socket *, struct socket *, int);
void unp_detach (struct unpcb *);
void unp_discard (struct file *);
void unp_disconnect (struct unpcb *);
bool unp_drop (struct unpcb *, int);
void unp_shutdown (struct unpcb *);
int unp_externalize (struct mbuf *, struct lwp *, int);
int unp_internalize (struct mbuf **);
void unp_dispose (struct mbuf *);
int unp_output (struct mbuf *, struct mbuf *, struct unpcb *,
struct lwp *);
void unp_setaddr (struct socket *, struct mbuf *, bool);
#else /* !_KERNEL */
/* actual length of an initialized sockaddr_un */
#if defined(_NETBSD_SOURCE)
#define SUN_LEN(su) \
(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
#endif /* !_NetBSD_SOURCE */
#endif /* _KERNEL */
#endif /* !_SYS_UN_H_ */

View file

@ -13,14 +13,22 @@
#include <string.h>
#include <ucontext.h>
#include <math.h>
#ifndef __arm__
#include <fenv.h>
#else
#include <ieeefp.h>
#endif
#include <sys/signal.h>
/* We can't use a global subtest variable reliably, because threads might
change the value when we reenter a thread (i.e., report wrong subtest
number). */
#define err(st, en) do { subtest = st; e(en); } while(0)
void do_calcs(void);
void do_child(void);
void do_parent(void);
void err(int subtest, int error_no);
void func1(int a, int b, int c, int d, int e, int f, int g, int h, int
i, int j, int k, int l, int m, int n, int o, int p, int q, int r, int s,
int t, int u, int v, int w, int x, int y, int z, int aa, int bb);
@ -313,12 +321,3 @@ int main(void)
return(-1);
}
/* We can't use a global subtest variable reliably, because threads might
change the value when we reenter a thread (i.e., report wrong subtest
number). */
void err(int sub, int error_no)
{
subtest = sub;
e(error_no);
}

View file

@ -5,6 +5,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
/*
* For now, just test the most dreaded case: the driver being told to use the