svn commit: r247431 - in user/attilio/vmobj-rwlock: . include lib/libc/stdio sys/boot/common sys/dev/mfi sys/dev/watchdog sys/netinet sys/sys tools/regression/lib/libc/stdio tools/test/iconv/tableg...
Attilio Rao
attilio at FreeBSD.org
Thu Feb 28 00:24:16 UTC 2013
Author: attilio
Date: Thu Feb 28 00:24:13 2013
New Revision: 247431
URL: http://svnweb.freebsd.org/changeset/base/247431
Log:
MFC
Added:
user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.3
- copied unchanged from r247429, head/lib/libc/stdio/open_memstream.3
user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.c
- copied unchanged from r247429, head/lib/libc/stdio/open_memstream.c
user/attilio/vmobj-rwlock/lib/libc/stdio/open_wmemstream.c
- copied unchanged from r247429, head/lib/libc/stdio/open_wmemstream.c
user/attilio/vmobj-rwlock/tools/regression/lib/libc/stdio/test-open_memstream.c
- copied unchanged from r247429, head/tools/regression/lib/libc/stdio/test-open_memstream.c
user/attilio/vmobj-rwlock/tools/regression/lib/libc/stdio/test-open_memstream.t
- copied unchanged from r247429, head/tools/regression/lib/libc/stdio/test-open_memstream.t
user/attilio/vmobj-rwlock/tools/regression/lib/libc/stdio/test-open_wmemstream.c
- copied unchanged from r247429, head/tools/regression/lib/libc/stdio/test-open_wmemstream.c
user/attilio/vmobj-rwlock/tools/regression/lib/libc/stdio/test-open_wmemstream.t
- copied unchanged from r247429, head/tools/regression/lib/libc/stdio/test-open_wmemstream.t
Modified:
user/attilio/vmobj-rwlock/UPDATING
user/attilio/vmobj-rwlock/include/stdio.h
user/attilio/vmobj-rwlock/include/wchar.h
user/attilio/vmobj-rwlock/lib/libc/stdio/Makefile.inc
user/attilio/vmobj-rwlock/lib/libc/stdio/Symbol.map
user/attilio/vmobj-rwlock/sys/boot/common/load_elf.c
user/attilio/vmobj-rwlock/sys/dev/mfi/mfi.c
user/attilio/vmobj-rwlock/sys/dev/watchdog/watchdog.c
user/attilio/vmobj-rwlock/sys/netinet/sctputil.c
user/attilio/vmobj-rwlock/sys/sys/watchdog.h
user/attilio/vmobj-rwlock/tools/regression/lib/libc/stdio/Makefile
user/attilio/vmobj-rwlock/tools/test/iconv/tablegen/cmp.sh
user/attilio/vmobj-rwlock/usr.sbin/watchdogd/watchdogd.8
user/attilio/vmobj-rwlock/usr.sbin/watchdogd/watchdogd.c
Directory Properties:
user/attilio/vmobj-rwlock/ (props changed)
user/attilio/vmobj-rwlock/lib/libc/ (props changed)
user/attilio/vmobj-rwlock/sys/ (props changed)
user/attilio/vmobj-rwlock/sys/boot/ (props changed)
Modified: user/attilio/vmobj-rwlock/UPDATING
==============================================================================
--- user/attilio/vmobj-rwlock/UPDATING Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/UPDATING Thu Feb 28 00:24:13 2013 (r247431)
@@ -26,6 +26,13 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10
disable the most expensive debugging functionality run
"ln -s 'abort:false,junk:false' /etc/malloc.conf".)
+20130208:
+ A new compression method (lz4) has been merged to -HEAD. Please
+ refer to zpool-features(7) for more information.
+
+ Please refer to the "ZFS notes" section of this file for information
+ on upgrading boot ZFS pools.
+
20130129:
A BSD-licensed patch(1) variant has been added and is installed
as bsdpatch, being the GNU version the default patch.
Modified: user/attilio/vmobj-rwlock/include/stdio.h
==============================================================================
--- user/attilio/vmobj-rwlock/include/stdio.h Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/include/stdio.h Thu Feb 28 00:24:13 2013 (r247431)
@@ -346,6 +346,7 @@ char *tempnam(const char *, const char *
FILE *fmemopen(void * __restrict, size_t, const char * __restrict);
ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
FILE * __restrict);
+FILE *open_memstream(char **, size_t *);
int renameat(int, const char *, int, const char *);
int vdprintf(int, const char * __restrict, __va_list);
Modified: user/attilio/vmobj-rwlock/include/wchar.h
==============================================================================
--- user/attilio/vmobj-rwlock/include/wchar.h Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/include/wchar.h Thu Feb 28 00:24:13 2013 (r247431)
@@ -207,6 +207,7 @@ int wcwidth(wchar_t);
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
size_t, mbstate_t * __restrict);
+FILE *open_wmemstream(wchar_t **, size_t *);
wchar_t *wcpcpy(wchar_t * __restrict, const wchar_t * __restrict);
wchar_t *wcpncpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
wchar_t *wcsdup(const wchar_t *) __malloc_like;
Modified: user/attilio/vmobj-rwlock/lib/libc/stdio/Makefile.inc
==============================================================================
--- user/attilio/vmobj-rwlock/lib/libc/stdio/Makefile.inc Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/lib/libc/stdio/Makefile.inc Thu Feb 28 00:24:13 2013 (r247431)
@@ -14,6 +14,7 @@ SRCS+= _flock_stub.c asprintf.c clrerr.c
ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \
fwrite.c getc.c getchar.c getdelim.c getline.c \
gets.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \
+ open_memstream.c open_wmemstream.c \
perror.c printf.c printf-pos.c putc.c putchar.c \
puts.c putw.c putwc.c putwchar.c \
refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \
@@ -36,7 +37,7 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.
flockfile.3 \
fopen.3 fputs.3 \
fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
- getline.3 getwc.3 mktemp.3 \
+ getline.3 getwc.3 mktemp.3 open_memstream.3 \
printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \
stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
@@ -60,6 +61,7 @@ MLINKS+=getc.3 fgetc.3 getc.3 getc_unloc
MLINKS+=getline.3 getdelim.3
MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3
+MLINKS+=open_memstream.3 open_wmemstream.3
MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \
printf.3 snprintf.3 printf.3 sprintf.3 \
printf.3 vasprintf.3 printf.3 vdprintf.3 \
Modified: user/attilio/vmobj-rwlock/lib/libc/stdio/Symbol.map
==============================================================================
--- user/attilio/vmobj-rwlock/lib/libc/stdio/Symbol.map Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/lib/libc/stdio/Symbol.map Thu Feb 28 00:24:13 2013 (r247431)
@@ -156,6 +156,8 @@ FBSD_1.3 {
putwc_l;
putwchar_l;
fmemopen;
+ open_memstream;
+ open_wmemstream;
};
FBSDprivate_1.0 {
Copied: user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.3 (from r247429, head/lib/libc/stdio/open_memstream.3)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.3 Thu Feb 28 00:24:13 2013 (r247431, copy of r247429, head/lib/libc/stdio/open_memstream.3)
@@ -0,0 +1,155 @@
+.\" Copyright (c) 2013 Advanced Computing Technologies LLC
+.\" Written by: John H. Baldwin <jhb at FreeBSD.org>
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 27, 2013
+.Dt OPEN_MEMSTREAM 3
+.Os
+.Sh NAME
+.Nm open_memstream ,
+.Nm open_wmemstream
+.Nd dynamic memory buffer stream open functions
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft FILE *
+.Fn open_memstream "char **bufp" "size_t **sizep"
+.In wchar.h
+.Ft FILE *
+.Fn open_wmemstream "wchar_t **bufp" "size_t **sizep"
+.Sh DESCRIPTION
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions create a write-only, seekable stream backed by a dynamically
+allocated memory buffer.
+The
+.Fn open_memstream
+function creates a byte-oriented stream,
+while the
+.Fn open_wmemstream
+function creates a wide-oriented stream.
+.Pp
+Each stream maintains a current position and size.
+Initially,
+the position and size are set to zero.
+Each write begins at the current position and advances it the number of
+successfully written bytes for
+.Fn open_memstream
+or wide characters for
+.Fn open_wmemstream .
+If a write moves the current position beyond the length of the buffer,
+the length of the buffer is extended and a null character is appended to the
+buffer.
+.Pp
+A stream's buffer always contains a null character at the end of the buffer
+that is not included in the current length.
+.Pp
+If a stream's current position is moved beyond the current length via a
+seek operation and a write is performed,
+the characters between the current length and the current position are filled
+with null characters before the write is performed.
+.Pp
+After a successful call to
+.Xr fclose 3
+or
+.Xr fflush 3 ,
+the pointer referenced by
+.Fa bufp
+will contain the start of the memory buffer and the variable referenced by
+.Fa sizep
+will contain the smaller of the current position and the current buffer length.
+.Pp
+After a successful call to
+.Xr fflush 3,
+the pointer referenced by
+.Fa bufp
+and the variable referenced by
+.Fa sizep
+are only valid until the next write operation or a call to
+.Xr fclose 3.
+.Pp
+Once a stream is closed,
+the allocated buffer referenced by
+.Fa bufp
+should be released via a call to
+.Xr free 3
+when it is no longer needed.
+.Sh IMPLEMENTATION NOTES
+Internally all I/O streams are effectively byte-oriented,
+so using wide-oriented operations to write to a stream opened via
+.Fn open_wmemstream
+results in wide characters being expanded to a stream of multibyte characters
+in stdio's internal buffers.
+These multibyte characters are then converted back to wide characters when
+written into the stream.
+As a result,
+the wide-oriented streams maintain an internal multibyte character conversion
+state that is cleared on any seek opertion that changes the current position.
+This should have no effect as long as wide-oriented output operations are used
+on a wide-oriented stream.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn open_memstream
+and
+.Fn open_wmemstream
+return a
+.Tn FILE
+pointer.
+Otherwise,
+.Dv NULL
+is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The
+.Fa bufp
+or
+.Fa sizep
+argument was
+.Dv NULL .
+.It Bq Er ENOMEM
+Memory for the stream or buffer could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr fclose 3 ,
+.Xr fflush 3 ,
+.Xr fopen 3 ,
+.Xr free 3 ,
+.Xr fseek 3 ,
+.Xr sbuf 3 ,
+.Xr stdio 3
+.Sh STANDARDS
+The
+.Fn open_memstream
+and
+.Fn open_wmemstream
+functions conform to
+.St -p1003.1-2008 .
Copied: user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.c (from r247429, head/lib/libc/stdio/open_memstream.c)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/attilio/vmobj-rwlock/lib/libc/stdio/open_memstream.c Thu Feb 28 00:24:13 2013 (r247431, copy of r247429, head/lib/libc/stdio/open_memstream.c)
@@ -0,0 +1,209 @@
+/*-
+ * Copyright (c) 2013 Advanced Computing Technologies LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "un-namespace.h"
+
+/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */
+#define FPOS_MAX OFF_MAX
+
+struct memstream {
+ char **bufp;
+ size_t *sizep;
+ ssize_t len;
+ fpos_t offset;
+};
+
+static int
+memstream_grow(struct memstream *ms, fpos_t newoff)
+{
+ char *buf;
+ ssize_t newsize;
+
+ if (newoff < 0 || newoff >= SSIZE_MAX)
+ newsize = SSIZE_MAX - 1;
+ else
+ newsize = newoff;
+ if (newsize > ms->len) {
+ buf = realloc(*ms->bufp, newsize + 1);
+ if (buf != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "MS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
+#endif
+ memset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
+ return (1);
+ }
+ return (0);
+ }
+ return (1);
+}
+
+static void
+memstream_update(struct memstream *ms)
+{
+
+ assert(ms->len >= 0 && ms->offset >= 0);
+ *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
+}
+
+static int
+memstream_write(void *cookie, const char *buf, int len)
+{
+ struct memstream *ms;
+ ssize_t tocopy;
+
+ ms = cookie;
+ if (!memstream_grow(ms, ms->offset + len))
+ return (-1);
+ tocopy = ms->len - ms->offset;
+ if (len < tocopy)
+ tocopy = len;
+ memcpy(*ms->bufp + ms->offset, buf, tocopy);
+ ms->offset += tocopy;
+ memstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "MS: write(%p, %d) = %zd\n", ms, len, tocopy);
+#endif
+ return (tocopy);
+}
+
+static fpos_t
+memstream_seek(void *cookie, fpos_t pos, int whence)
+{
+ struct memstream *ms;
+#ifdef DEBUG
+ fpos_t old;
+#endif
+
+ ms = cookie;
+#ifdef DEBUG
+ old = ms->offset;
+#endif
+ switch (whence) {
+ case SEEK_SET:
+ /* _fseeko() checks for negative offsets. */
+ assert(pos >= 0);
+ ms->offset = pos;
+ break;
+ case SEEK_CUR:
+ /* This is only called by _ftello(). */
+ assert(pos == 0);
+ break;
+ case SEEK_END:
+ if (pos < 0) {
+ if (pos + ms->len < 0) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "MS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ } else {
+ if (FPOS_MAX - ms->len < pos) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "MS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EOVERFLOW;
+ return (-1);
+ }
+ }
+ ms->offset = ms->len + pos;
+ break;
+ }
+ memstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "MS: seek(%p, %jd, %d) %jd -> %jd\n", ms, (intmax_t)pos,
+ whence, (intmax_t)old, (intmax_t)ms->offset);
+#endif
+ return (ms->offset);
+}
+
+static int
+memstream_close(void *cookie)
+{
+
+ free(cookie);
+ return (0);
+}
+
+FILE *
+open_memstream(char **bufp, size_t *sizep)
+{
+ struct memstream *ms;
+ int save_errno;
+ FILE *fp;
+
+ if (bufp == NULL || sizep == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ *bufp = calloc(1, 1);
+ if (*bufp == NULL)
+ return (NULL);
+ ms = malloc(sizeof(*ms));
+ if (ms == NULL) {
+ save_errno = errno;
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ ms->bufp = bufp;
+ ms->sizep = sizep;
+ ms->len = 0;
+ ms->offset = 0;
+ memstream_update(ms);
+ fp = funopen(ms, NULL, memstream_write, memstream_seek,
+ memstream_close);
+ if (fp == NULL) {
+ save_errno = errno;
+ free(ms);
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ fwide(fp, -1);
+ return (fp);
+}
Copied: user/attilio/vmobj-rwlock/lib/libc/stdio/open_wmemstream.c (from r247429, head/lib/libc/stdio/open_wmemstream.c)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/attilio/vmobj-rwlock/lib/libc/stdio/open_wmemstream.c Thu Feb 28 00:24:13 2013 (r247431, copy of r247429, head/lib/libc/stdio/open_wmemstream.c)
@@ -0,0 +1,271 @@
+/*-
+ * Copyright (c) 2013 Advanced Computing Technologies LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "un-namespace.h"
+
+/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */
+#define FPOS_MAX OFF_MAX
+
+struct wmemstream {
+ wchar_t **bufp;
+ size_t *sizep;
+ ssize_t len;
+ fpos_t offset;
+ mbstate_t mbstate;
+};
+
+static int
+wmemstream_grow(struct wmemstream *ms, fpos_t newoff)
+{
+ wchar_t *buf;
+ ssize_t newsize;
+
+ if (newoff < 0 || newoff >= SSIZE_MAX / sizeof(wchar_t))
+ newsize = SSIZE_MAX / sizeof(wchar_t) - 1;
+ else
+ newsize = newoff;
+ if (newsize > ms->len) {
+ buf = realloc(*ms->bufp, (newsize + 1) * sizeof(wchar_t));
+ if (buf != NULL) {
+#ifdef DEBUG
+ fprintf(stderr, "WMS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
+#endif
+ wmemset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
+ return (1);
+ }
+ return (0);
+ }
+ return (1);
+}
+
+static void
+wmemstream_update(struct wmemstream *ms)
+{
+
+ assert(ms->len >= 0 && ms->offset >= 0);
+ *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
+}
+
+/*
+ * Based on a starting multibyte state and an input buffer, determine
+ * how many wchar_t's would be output. This doesn't use mbsnrtowcs()
+ * so that it can handle embedded null characters.
+ */
+static size_t
+wbuflen(const mbstate_t *state, const char *buf, int len)
+{
+ mbstate_t lenstate;
+ size_t charlen, count;
+
+ count = 0;
+ lenstate = *state;
+ while (len > 0) {
+ charlen = mbrlen(buf, len, &lenstate);
+ if (charlen == (size_t)-1)
+ return (-1);
+ if (charlen == (size_t)-2)
+ break;
+ if (charlen == 0)
+ /* XXX: Not sure how else to handle this. */
+ charlen = 1;
+ len -= charlen;
+ buf += charlen;
+ count++;
+ }
+ return (count);
+}
+
+static int
+wmemstream_write(void *cookie, const char *buf, int len)
+{
+ struct wmemstream *ms;
+ ssize_t consumed, wlen;
+ size_t charlen;
+
+ ms = cookie;
+ wlen = wbuflen(&ms->mbstate, buf, len);
+ if (wlen < 0) {
+ errno = EILSEQ;
+ return (-1);
+ }
+ if (!wmemstream_grow(ms, ms->offset + wlen))
+ return (-1);
+
+ /*
+ * This copies characters one at a time rather than using
+ * mbsnrtowcs() so it can properly handle embedded null
+ * characters.
+ */
+ consumed = 0;
+ while (len > 0 && ms->offset < ms->len) {
+ charlen = mbrtowc(*ms->bufp + ms->offset, buf, len,
+ &ms->mbstate);
+ if (charlen == (size_t)-1) {
+ if (consumed == 0) {
+ errno = EILSEQ;
+ return (-1);
+ }
+ /* Treat it as a successful short write. */
+ break;
+ }
+ if (charlen == 0)
+ /* XXX: Not sure how else to handle this. */
+ charlen = 1;
+ if (charlen == (size_t)-2) {
+ consumed += len;
+ len = 0;
+ } else {
+ consumed += charlen;
+ buf += charlen;
+ len -= charlen;
+ ms->offset++;
+ }
+ }
+ wmemstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "WMS: write(%p, %d) = %zd\n", ms, len, consumed);
+#endif
+ return (consumed);
+}
+
+static fpos_t
+wmemstream_seek(void *cookie, fpos_t pos, int whence)
+{
+ struct wmemstream *ms;
+ fpos_t old;
+
+ ms = cookie;
+ old = ms->offset;
+ switch (whence) {
+ case SEEK_SET:
+ /* _fseeko() checks for negative offsets. */
+ assert(pos >= 0);
+ ms->offset = pos;
+ break;
+ case SEEK_CUR:
+ /* This is only called by _ftello(). */
+ assert(pos == 0);
+ break;
+ case SEEK_END:
+ if (pos < 0) {
+ if (pos + ms->len < 0) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "WMS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EINVAL;
+ return (-1);
+ }
+ } else {
+ if (FPOS_MAX - ms->len < pos) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "WMS: bad SEEK_END: pos %jd, len %zd\n",
+ (intmax_t)pos, ms->len);
+#endif
+ errno = EOVERFLOW;
+ return (-1);
+ }
+ }
+ ms->offset = ms->len + pos;
+ break;
+ }
+ /* Reset the multibyte state if a seek changes the position. */
+ if (ms->offset != old)
+ memset(&ms->mbstate, 0, sizeof(ms->mbstate));
+ wmemstream_update(ms);
+#ifdef DEBUG
+ fprintf(stderr, "WMS: seek(%p, %jd, %d) %jd -> %jd\n", ms,
+ (intmax_t)pos, whence, (intmax_t)old, (intmax_t)ms->offset);
+#endif
+ return (ms->offset);
+}
+
+static int
+wmemstream_close(void *cookie)
+{
+
+ free(cookie);
+ return (0);
+}
+
+FILE *
+open_wmemstream(wchar_t **bufp, size_t *sizep)
+{
+ struct wmemstream *ms;
+ int save_errno;
+ FILE *fp;
+
+ if (bufp == NULL || sizep == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ *bufp = calloc(1, sizeof(wchar_t));
+ if (*bufp == NULL)
+ return (NULL);
+ ms = malloc(sizeof(*ms));
+ if (ms == NULL) {
+ save_errno = errno;
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ ms->bufp = bufp;
+ ms->sizep = sizep;
+ ms->len = 0;
+ ms->offset = 0;
+ memset(&ms->mbstate, 0, sizeof(mbstate_t));
+ wmemstream_update(ms);
+ fp = funopen(ms, NULL, wmemstream_write, wmemstream_seek,
+ wmemstream_close);
+ if (fp == NULL) {
+ save_errno = errno;
+ free(ms);
+ free(*bufp);
+ *bufp = NULL;
+ errno = save_errno;
+ return (NULL);
+ }
+ fwide(fp, 1);
+ return (fp);
+}
Modified: user/attilio/vmobj-rwlock/sys/boot/common/load_elf.c
==============================================================================
--- user/attilio/vmobj-rwlock/sys/boot/common/load_elf.c Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/sys/boot/common/load_elf.c Thu Feb 28 00:24:13 2013 (r247431)
@@ -304,7 +304,7 @@ __elfN(loadimage)(struct preloaded_file
* only adjust the entry point if it's a virtual address to begin with.
*/
off = -0xc0000000u;
- if ((ehdr->e_entry & 0xc0000000u) == 0xc000000u)
+ if ((ehdr->e_entry & 0xc0000000u) == 0xc0000000u)
ehdr->e_entry += off;
#ifdef ELF_VERBOSE
printf("ehdr->e_entry 0x%08x, va<->pa off %llx\n", ehdr->e_entry, off);
Modified: user/attilio/vmobj-rwlock/sys/dev/mfi/mfi.c
==============================================================================
--- user/attilio/vmobj-rwlock/sys/dev/mfi/mfi.c Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/sys/dev/mfi/mfi.c Thu Feb 28 00:24:13 2013 (r247431)
@@ -157,6 +157,11 @@ SYSCTL_INT(_hw_mfi, OID_AUTO, polled_cmd
&mfi_polled_cmd_timeout, 0,
"Polled command timeout - used for firmware flash etc (in seconds)");
+static int mfi_cmd_timeout = MFI_CMD_TIMEOUT;
+TUNABLE_INT("hw.mfi.cmd_timeout", &mfi_cmd_timeout);
+SYSCTL_INT(_hw_mfi, OID_AUTO, cmd_timeout, CTLFLAG_RWTUN, &mfi_cmd_timeout,
+ 0, "Command timeout (in seconds)");
+
/* Management interface */
static d_open_t mfi_open;
static d_close_t mfi_close;
@@ -782,7 +787,7 @@ mfi_attach(struct mfi_softc *sc)
/* Start the timeout watchdog */
callout_init(&sc->mfi_watchdog_callout, CALLOUT_MPSAFE);
- callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz,
+ callout_reset(&sc->mfi_watchdog_callout, mfi_cmd_timeout * hz,
mfi_timeout, sc);
if (sc->mfi_flags & MFI_FLAGS_TBOLT) {
@@ -3714,7 +3719,7 @@ mfi_dump_all(void)
break;
device_printf(sc->mfi_dev, "Dumping\n\n");
timedout = 0;
- deadline = time_uptime - MFI_CMD_TIMEOUT;
+ deadline = time_uptime - mfi_cmd_timeout;
mtx_lock(&sc->mfi_io_lock);
TAILQ_FOREACH(cm, &sc->mfi_busy, cm_link) {
if (cm->cm_timestamp <= deadline) {
@@ -3745,10 +3750,11 @@ mfi_timeout(void *data)
time_t deadline;
int timedout = 0;
- deadline = time_uptime - MFI_CMD_TIMEOUT;
+ deadline = time_uptime - mfi_cmd_timeout;
if (sc->adpreset == 0) {
if (!mfi_tbolt_reset(sc)) {
- callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz, mfi_timeout, sc);
+ callout_reset(&sc->mfi_watchdog_callout,
+ mfi_cmd_timeout * hz, mfi_timeout, sc);
return;
}
}
@@ -3785,7 +3791,7 @@ mfi_timeout(void *data)
mtx_unlock(&sc->mfi_io_lock);
- callout_reset(&sc->mfi_watchdog_callout, MFI_CMD_TIMEOUT * hz,
+ callout_reset(&sc->mfi_watchdog_callout, mfi_cmd_timeout * hz,
mfi_timeout, sc);
if (0)
Modified: user/attilio/vmobj-rwlock/sys/dev/watchdog/watchdog.c
==============================================================================
--- user/attilio/vmobj-rwlock/sys/dev/watchdog/watchdog.c Thu Feb 28 00:22:04 2013 (r247430)
+++ user/attilio/vmobj-rwlock/sys/dev/watchdog/watchdog.c Thu Feb 28 00:24:13 2013 (r247431)
@@ -1,5 +1,8 @@
/*-
* Copyright (c) 2004 Poul-Henning Kamp
+ * Copyright (c) 2013 iXsystems.com,
+ * author: Alfred Perlstein <alfred at freebsd.org>
+ *
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,21 +32,40 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/types.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
+#include <sys/syslog.h>
#include <sys/watchdog.h>
#include <sys/bus.h>
#include <machine/bus.h>
+#include <sys/syscallsubr.h> /* kern_clock_gettime() */
+
+static int wd_set_pretimeout(int newtimeout, int disableiftoolong);
+static void wd_timeout_cb(void *arg);
+
+static struct callout wd_pretimeo_handle;
+static int wd_pretimeout;
+static int wd_pretimeout_act = WD_SOFT_LOG;
+
+static struct callout wd_softtimeo_handle;
+static int wd_softtimer; /* true = use softtimer instead of hardware
+ watchdog */
+static int wd_softtimeout_act = WD_SOFT_LOG; /* action for the software timeout */
+
static struct cdev *wd_dev;
-static volatile u_int wd_last_u;
+static volatile u_int wd_last_u; /* last timeout value set by kern_do_pat */
-static int
-kern_do_pat(u_int utim)
+static int wd_lastpat_valid = 0;
+static time_t wd_lastpat = 0; /* when the watchdog was last patted */
+
+int
+wdog_kern_pat(u_int utim)
{
int error;
@@ -51,11 +73,20 @@ kern_do_pat(u_int utim)
return (EINVAL);
if ((utim & WD_LASTVAL) != 0) {
+ /*
+ * if WD_LASTVAL is set, fill in the bits for timeout
+ * from the saved value in wd_last_u.
+ */
MPASS((wd_last_u & ~WD_INTERVAL) == 0);
utim &= ~WD_LASTVAL;
utim |= wd_last_u;
- } else
+ } else {
+ /*
+ * Otherwise save the new interval.
+ * This can be zero (to disable the watchdog)
+ */
wd_last_u = (utim & WD_INTERVAL);
+ }
if ((utim & WD_INTERVAL) == WD_TO_NEVER) {
utim = 0;
@@ -65,18 +96,49 @@ kern_do_pat(u_int utim)
/* Assume no watchdog available; watchdog flags success */
error = EOPNOTSUPP;
}
- EVENTHANDLER_INVOKE(watchdog_list, utim, &error);
+ if (wd_softtimer) {
+ if (utim == 0) {
+ callout_stop(&wd_softtimeo_handle);
+ } else {
+ (void) callout_reset(&wd_softtimeo_handle,
+ hz*utim, wd_timeout_cb, "soft");
+ }
+ error = 0;
+ } else {
+ EVENTHANDLER_INVOKE(watchdog_list, utim, &error);
+ }
+ wd_set_pretimeout(wd_pretimeout, true);
+ /*
+ * If we were able to arm/strobe the watchdog, then
+ * update the last time it was strobed for WDIOC_GETTIMELEFT
+ */
+ if (!error) {
+ struct timespec ts;
+
+ error = kern_clock_gettime(curthread /* XXX */,
+ CLOCK_MONOTONIC_FAST, &ts);
+ if (!error) {
+ wd_lastpat = ts.tv_sec;
+ wd_lastpat_valid = 1;
+ }
+ }
return (error);
}
static int
-wd_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data,
- int flags __unused, struct thread *td)
+wd_valid_act(int act)
+{
+
+ if ((act & ~(WD_SOFT_MASK)) != 0)
+ return false;
+ return true;
+}
+
+static int
+wd_ioctl_patpat(caddr_t data)
{
u_int u;
- if (cmd != WDIOCPATPAT)
- return (ENOIOCTL);
u = *(u_int *)data;
if (u & ~(WD_ACTIVE | WD_PASSIVE | WD_LASTVAL | WD_INTERVAL))
return (EINVAL);
@@ -89,24 +151,162 @@ wd_ioctl(struct cdev *dev __unused, u_lo
return (ENOSYS); /* XXX Not implemented yet */
u &= ~(WD_ACTIVE | WD_PASSIVE);
- return (kern_do_pat(u));
+ return (wdog_kern_pat(u));
}
-u_int
-wdog_kern_last_timeout(void)
+static int
+wd_get_time_left(struct thread *td, time_t *remainp)
{
+ struct timespec ts;
+ int error;
- return (wd_last_u);
+ error = kern_clock_gettime(td, CLOCK_MONOTONIC_FAST, &ts);
+ if (error)
+ return (error);
+ if (!wd_lastpat_valid)
+ return (ENOENT);
+ *remainp = ts.tv_sec - wd_lastpat;
+ return (0);
}
-int
-wdog_kern_pat(u_int utim)
+static void
+wd_timeout_cb(void *arg)
{
+ const char *type = arg;
- if (utim & ~(WD_LASTVAL | WD_INTERVAL))
- return (EINVAL);
+#ifdef DDB
+ if ((wd_pretimeout_act & WD_SOFT_DDB)) {
+ char kdb_why[80];
+ snprintf(kdb_why, sizeof(buf), "watchdog %s timeout", type);
+ kdb_backtrace();
+ kdb_enter(KDB_WHY_WATCHDOG, kdb_why);
+ }
+#endif
+ if ((wd_pretimeout_act & WD_SOFT_LOG))
+ log(LOG_EMERG, "watchdog %s-timeout, WD_SOFT_LOG", type);
+ if ((wd_pretimeout_act & WD_SOFT_PRINTF))
+ printf("watchdog %s-timeout, WD_SOFT_PRINTF\n", type);
+ if ((wd_pretimeout_act & WD_SOFT_PANIC))
+ panic("watchdog %s-timeout, WD_SOFT_PANIC set", type);
+}
- return (kern_do_pat(utim));
+/*
+ * Called to manage timeouts.
+ * newtimeout needs to be in the range of 0 to actual watchdog timeout.
+ * if 0, we disable the pre-timeout.
+ * otherwise we set the pre-timeout provided it's not greater than the
+ * current actual watchdog timeout.
+ */
+static int
+wd_set_pretimeout(int newtimeout, int disableiftoolong)
+{
+ u_int utime;
+
+ utime = wdog_kern_last_timeout();
+ /* do not permit a pre-timeout >= than the timeout. */
+ if (newtimeout >= utime) {
+ /*
+ * If 'disableiftoolong' then just fall through
+ * so as to disable the pre-watchdog
+ */
+ if (disableiftoolong)
+ newtimeout = 0;
+ else
+ return EINVAL;
+ }
+
+ /* disable the pre-timeout */
+ if (newtimeout == 0) {
+ wd_pretimeout = 0;
+ callout_stop(&wd_pretimeo_handle);
+ return 0;
+ }
+
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-user
mailing list