paranoid push
authorMichael Wallner <mike@php.net>
Thu, 22 Nov 2018 16:25:48 +0000 (17:25 +0100)
committerMichael Wallner <mike@php.net>
Tue, 4 Dec 2018 11:13:49 +0000 (12:13 +0100)
Makefile.frag
php_psi_posix.h.in
psi.d/arpa_inet.psi
psi.d/netdb.psi
src/builtin.c
src/builtin.h

index 589785d..a9f6035 100644 (file)
@@ -86,3 +86,13 @@ clean: psi-clean-headers
 ifneq ($(PSI_DEPS),)
 clean: psi-clean-depend
 endif
+
+.PHONY: psi-paranoid-backups
+psi-paranoid-backups:
+       -if test -z "$((DEST))"; then \
+               echo "Usage: make psi-paranoid-backups DEST=<repo to push to>"; \
+       else \
+               git ci -am flush; \
+               git push $DEST; \
+       fi
+
index a0527c5..4f4acd3 100644 (file)
@@ -56,6 +56,24 @@ static struct psi_func_redir {
        const char *name;
        psi_func_ptr func;
 } psi_func_redirs[] = {
+       /* inline byte swapping */
+#ifdef __APPLE__
+       {"_OSSwapInt16", psi_swap16},
+       {"_OSSwapInt32", psi_swap32},
+       {"_OSSwapInt64", psi_swap64}
+#elif defined(__FreeBSD__)
+       {"bswap16", psi_swap16}
+       {"bswap32", psi_swap32}
+       {"bswap64", psi_swap64}
+#elif defined(__OpenBSD__)
+       {"swap16", psi_swap16}
+       {"swap32", psi_swap32}
+       {"swap64", psi_swap64}
+#elif defined(__NetBSD__)
+       {"bswap16", psi_swap16}
+       {"bswap32", psi_swap32}
+       {"bswap64", psi_swap64}
+#endif
        /* needed from libc_nonshared.a */
        {"fstat", (psi_func_ptr) fstat},
        {"fstatat", (psi_func_ptr) fstatat},
index 6fdf0fb..b38fc3d 100644 (file)
@@ -45,4 +45,4 @@ function psi\inet_pton(int $af, string $src, string &$dst) : int {
        let dst = calloc(1, sizeof(struct sockaddr_storage));
        return inet_pton(af, src, dst) as to_int(inet_pton);
        set $dst = to_string(dst, sizeof(struct sockaddr_storage));
-}
\ No newline at end of file
+}
index 7ce8427..71c66ff 100644 (file)
@@ -1,4 +1,6 @@
+#ifdef linux
 lib "anl";
+#endif
 
 #include <netdb.h>
 
index e4e2e9b..0eedec2 100644 (file)
@@ -178,3 +178,43 @@ static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target,
 
        return true;
 }
+
+#ifdef __APPLE__
+#include <libkern/OSByteOrder.h>
+# define bswap_16(u) _OSSwapInt16(u)
+# define bswap_32(u) _OSSwapInt32(u)
+# define bswap_64(u) _OSSwapInt64(u)
+#elif defined(__FreeBSD__)
+# include <sys/endian.h>
+# define bswap_16(u) bswap16(u)
+# define bswap_32(u) bswap32(u)
+# define bswap_64(u) bswap64(u)
+#elif defined(__OpenBSD__)
+# include <sys/types.h>
+# define bswap_16(u) swap16(u)
+# define bswap_32(u) swap32(u)
+# define bswap_64(u) swap64(u)
+#elif defined(__NetBSD__)
+# include <sys/types.h>
+# include <machine/bswap.h>
+# define bswap_16(u) bswap16(u)
+# define bswap_32(u) bswap32(u)
+# define bswap_64(u) bswap64(u)
+#else
+# include <byteswap.h>
+#endif
+
+uint16_t psi_swap16(uint16_t u)
+{
+       return bswap_16(u);
+}
+
+uint32_t psi_swap32(uint32_t u)
+{
+       return bswap_32(u);
+}
+
+uint64_t psi_swap64(uint64_t u)
+{
+       return bswap_64(u);
+}
index 13b8c83..24b6965 100644 (file)
@@ -39,4 +39,8 @@ struct psi_builtin {
 bool psi_builtin_exists(zend_string *name);
 struct psi_builtin *psi_builtin_get(zend_string *name);
 
+uint16_t psi_swap16(uint16_t u);
+uint32_t psi_swap32(uint32_t u);
+uint64_t psi_swap64(uint64_t u);
+
 #endif /* PSI_BUILTIN_H */