The doubt about "link-layer header type" for loopback packet

2017-11-19 Thread Nan Xiao
Hi tech@,

Now, when I use tcpdump file to capture loopback packets on OpenBSD,
the "link-layer header type" in global header of pcap file is 0x0C,
means "raw IP" packet. I download the file in Windows, and the
Wireshark on Windows can't analyze it , and just shows "
Raw packet data".

After referring
https://www.wireshark.org/lists/wireshark-bugs/201502/msg00295.html,
I change the "link-layer header type" from 0x0C to 0x6C(108), the
pcap file can be decoded successfully (About link type, you can refer
http://www.tcpdump.org/linktypes.html).

Concerning about the "link-layer header type" of loopback packet, is
it reasonable to use "0x6C" instead of "0x0C"?

Thanks very much in advance!

Best Regards
Nan Xiao



armv7/sxie: gate def for emac

2017-11-19 Thread Artturi Alm
Hi,

i'm about to need this, thanks :)

-Artturi


--- a/sys/dev/fdt/sxiccmu_clocks.h
+++ b/sys/dev/fdt/sxiccmu_clocks.h
@@ -18,6 +18,7 @@
 #define A10_CLK_AHB_MMC1   35
 #define A10_CLK_AHB_MMC2   36
 #define A10_CLK_AHB_MMC3   37
+#define A10_CLK_AHB_EMAC   42
 #define A10_CLK_AHB_SATA   49
 #define A10_CLK_AHB_GMAC   66
 #define A10_CLK_APB0_PIO   74
@@ -49,6 +50,7 @@
[A10_CLK_AHB_MMC1] =   { 0x0060, 9 },
[A10_CLK_AHB_MMC2] =   { 0x0060, 10 },
[A10_CLK_AHB_MMC3] =   { 0x0060, 11 },
+   [A10_CLK_AHB_EMAC] =   { 0x0060, 17 },
[A10_CLK_AHB_SATA] =   { 0x0060, 25 },
[A10_CLK_AHB_GMAC] =   { 0x0064, 17 },
[A10_CLK_APB0_PIO] =   { 0x0068, 5 },



Re: faster printf

2017-11-19 Thread Theo Buehler
Since I am not aware of any further objections and most responses seemed
positive, I think it's time to move forward.

For your convenience, I attached the diff again below.

ok?

Index: lib/libc/stdio/vfprintf.c
===
RCS file: /var/cvs/src/lib/libc/stdio/vfprintf.c,v
retrieving revision 1.77
diff -u -p -r1.77 vfprintf.c
--- lib/libc/stdio/vfprintf.c   29 Aug 2016 12:20:57 -  1.77
+++ lib/libc/stdio/vfprintf.c   19 Nov 2017 20:44:07 -
@@ -279,8 +279,6 @@ __vfprintf(FILE *fp, const char *fmt0, _
int width;  /* width from format (%8d), or 0 */
int prec;   /* precision from format; <0 for N/A */
char sign;  /* sign prefix (' ', '+', '-', or \0) */
-   wchar_t wc;
-   mbstate_t ps;
 #ifdef FLOATING_POINT
/*
 * We can decompose the printed representation of floating
@@ -481,25 +479,13 @@ __vfprintf(FILE *fp, const char *fmt0, _
convbuf = NULL;
 #endif
 
-   memset(, 0, sizeof(ps));
/*
 * Scan the format for conversions (`%' character).
 */
for (;;) {
-   size_t len;
+   for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+   continue;
 
-   cp = fmt;
-   while ((len = mbrtowc(, fmt, MB_CUR_MAX, )) != 0) {
-   if (len == (size_t)-1 || len == (size_t)-2) {
-   ret = -1;
-   goto error;
-   }
-   fmt += len;
-   if (wc == '%') {
-   fmt--;
-   break;
-   }
-   }
if (fmt != cp) {
ptrdiff_t m = fmt - cp;
if (m < 0 || m > INT_MAX - ret)
@@ -507,7 +493,7 @@ __vfprintf(FILE *fp, const char *fmt0, _
PRINT(cp, m);
ret += m;
}
-   if (len == 0)
+   if (ch == '\0')
goto done;
fmt++;  /* skip over '%' */
 
@@ -852,7 +838,9 @@ fp_common:
xdigs = xdigs_lower;
ox[1] = 'x';
goto nosign;
-   case 's':
+   case 's': {
+   size_t len;
+
 #ifdef PRINTF_WIDE_CHAR
if (flags & LONGINT) {
wchar_t *wcp;
@@ -878,6 +866,7 @@ fp_common:
}
} else
 #endif /* PRINTF_WIDE_CHAR */
+
if ((cp = GETARG(char *)) == NULL) {
struct syslog_data sdata = SYSLOG_DATA_INIT;
int save_errno = errno;
@@ -893,6 +882,7 @@ fp_common:
goto overflow;
size = (int)len;
sign = '\0';
+   }
break;
case 'U':
flags |= LONGINT;
@@ -1156,8 +1146,6 @@ __find_arguments(const char *fmt0, va_li
int tablemax;   /* largest used index in table */
int nextarg;/* 1-based argument index */
int ret = 0;/* return value */
-   wchar_t wc;
-   mbstate_t ps;
 
/*
 * Add an argument type to the table, expanding if necessary.
@@ -1211,25 +1199,14 @@ __find_arguments(const char *fmt0, va_li
tablemax = 0;
nextarg = 1;
memset(typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
-   memset(, 0, sizeof(ps));
 
/*
 * Scan the format for conversions (`%' character).
 */
for (;;) {
-   size_t len;
-
-   cp = fmt;
-   while ((len = mbrtowc(, fmt, MB_CUR_MAX, )) != 0) {
-   if (len == (size_t)-1 || len == (size_t)-2)
-   return (-1);
-   fmt += len;
-   if (wc == '%') {
-   fmt--;
-   break;
-   }
-   }
-   if (len == 0)
+   for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++)
+   continue;
+   if (ch == '\0')
goto done;
fmt++;  /* skip over '%' */
 



Re: Implement __cxa_thread_atexit

2017-11-19 Thread Joerg Sonnenberger
On Sun, Nov 19, 2017 at 11:05:31PM +0100, Joerg Sonnenberger wrote:
> On Sun, Nov 19, 2017 at 10:04:45PM +0100, Mark Kettenis wrote:
> > Here is an update diff that implements __cxa_thread_atexit which is
> > emitted by clang (and modern gcc) to implement certain aspects of
> > C++11 thread_local.
> 
> Note that without providing __cxa_thread_atexit, gcc will not detect it
> and try to provide its own.

__cxa_thread_atexit_impl I mean, sorry.

Joerg



Re: Implement __cxa_thread_atexit

2017-11-19 Thread Joerg Sonnenberger
On Sun, Nov 19, 2017 at 10:04:45PM +0100, Mark Kettenis wrote:
> Here is an update diff that implements __cxa_thread_atexit which is
> emitted by clang (and modern gcc) to implement certain aspects of
> C++11 thread_local.

Note that without providing __cxa_thread_atexit, gcc will not detect it
and try to provide its own.

Joerg



Implement __cxa_thread_atexit

2017-11-19 Thread Mark Kettenis
Here is an update diff that implements __cxa_thread_atexit which is
emitted by clang (and modern gcc) to implement certain aspects of
C++11 thread_local.

Compared to the previous function this now also prevents unloading of
shared libraries that call __cxa_thread_atexit.

As before uou'll need to install header files and build and install
ld.so before installing the new libc.  This also needs a libc minor
bump (not included).

ok?


Index: include/dlfcn.h
===
RCS file: /cvs/src/include/dlfcn.h,v
retrieving revision 1.13
diff -u -p -r1.13 dlfcn.h
--- include/dlfcn.h 24 Mar 2013 01:37:21 -  1.13
+++ include/dlfcn.h 19 Nov 2017 20:59:08 -
@@ -72,6 +72,7 @@ typedef   struct dl_info {
 #define DL_GETLOADADDR x
 #define DL_SETTHREADLCK2
 #define DL_SETBINDLCK  3
+#define DL_REFERENCE   4
 
 #defineDL_LAZY RTLD_LAZY   /* Compat */
 
Index: include/tib.h
===
RCS file: /cvs/src/include/tib.h,v
retrieving revision 1.5
diff -u -p -r1.5 tib.h
--- include/tib.h   10 Aug 2017 13:35:18 -  1.5
+++ include/tib.h   19 Nov 2017 20:59:08 -
@@ -135,6 +135,7 @@
  */
 
 struct tib {
+   void*tib_atexit;
int tib_thread_flags;   /* internal to libpthread */
pid_t   tib_tid;
int tib_cantcancel;
@@ -182,16 +183,12 @@ struct tib {
int tib_cantcancel;
pid_t   tib_tid;
int tib_thread_flags;   /* internal to libpthread */
-#if !defined(__LP64__) && !defined(__i386)
-   int __tib_padding;  /* padding for 8byte alignment */
-#endif
+   void*tib_atexit;
 };
 
 #if defined(__i386) || defined(__amd64)
 # define _TIB_PREP(tib)\
((void)((tib)->__tib_self = (tib)))
-#elif !defined(__LP64__) && !defined(__i386)
-# define _TIB_PREP(tib)((void)((tib)->__tib_padding = 0))
 #endif
 
 #defineTIB_EXTRA_ALIGN sizeof(void *)
@@ -207,6 +204,7 @@ struct tib {
 
 #defineTIB_INIT(tib, dtv, thread)  do {\
(tib)->tib_thread   = (thread); \
+   (tib)->tib_atexit   = NULL; \
(tib)->tib_locale   = NULL; \
(tib)->tib_cantcancel   = 0;\
(tib)->tib_cancel_point = 0;\
Index: lib/libc/Symbols.list
===
RCS file: /cvs/src/lib/libc/Symbols.list,v
retrieving revision 1.61
diff -u -p -r1.61 Symbols.list
--- lib/libc/Symbols.list   4 Nov 2017 22:53:57 -   1.61
+++ lib/libc/Symbols.list   19 Nov 2017 20:59:08 -
@@ -1466,6 +1466,7 @@ random
 /* stdlib */
 _Exit
 __cxa_atexit
+__cxa_thread_atexit
 __cxa_finalize
 __isthreaded
 a64l
Index: lib/libc/include/thread_private.h
===
RCS file: /cvs/src/lib/libc/include/thread_private.h,v
retrieving revision 1.32
diff -u -p -r1.32 thread_private.h
--- lib/libc/include/thread_private.h   4 Nov 2017 22:53:57 -   1.32
+++ lib/libc/include/thread_private.h   19 Nov 2017 20:59:09 -
@@ -394,6 +394,7 @@ void_spinunlock(volatile _atomic_lock_t
 void   _rthread_debug(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
 pid_t  _thread_dofork(pid_t (*_sys_fork)(void));
+void   _thread_finalize(void);
 
 /*
  * Threading syscalls not declared in system headers
Index: lib/libc/stdlib/atexit.c
===
RCS file: /cvs/src/lib/libc/stdlib/atexit.c,v
retrieving revision 1.24
diff -u -p -r1.24 atexit.c
--- lib/libc/stdlib/atexit.c10 Nov 2015 04:14:03 -  1.24
+++ lib/libc/stdlib/atexit.c19 Nov 2017 20:59:09 -
@@ -31,12 +31,26 @@
 
 #include 
 #include 
+#include 
+#ifndef NO_PIC
+#include 
+#pragma weak _DYNAMIC
+#endif
 #include 
 #include 
 #include 
 #include "atexit.h"
 #include "atfork.h"
 #include "thread_private.h"
+#include "tib.h"
+
+typeof(dlctl) dlctl asm("_dlctl") __attribute__((weak));
+
+struct thread_atexit_fn {
+   void (*func)(void *);
+   void *arg;
+   struct thread_atexit_fn *next;
+};
 
 struct atexit *__atexit;
 static int restartloop;
@@ -121,6 +135,43 @@ atexit(void (*fn)(void))
 }
 DEF_STRONG(atexit);
 
+int
+__cxa_thread_atexit(void (*func)(void *), void *arg, void *dso)
+{
+   struct thread_atexit_fn *fnp;
+   struct tib *tib = TIB_GET();
+
+   fnp = calloc(1, sizeof(struct thread_atexit_fn));
+   if (fnp == NULL)
+   return -1;
+
+#ifndef NO_PIC
+   if (_DYNAMIC)
+   dlctl(NULL, DL_REFERENCE, dso);
+#endif
+
+   fnp->func = func;
+   fnp->arg = arg;
+   fnp->next = tib->tib_atexit;
+   tib->tib_atexit = fnp;
+
+   return 0;
+}
+DEF_STRONG(__cxa_thread_atexit);
+
+void