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 589785dc23ec0b1bdf8260b23dc34ddefba18046..a9f6035bfa37e4da4bfa20988d9ea83481981ac0 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 a0527c5b23c56579d6c71219f7db0c1a51209f80..4f4acd3a28e7877a3d92bf60e2a62598101bb8be 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 6fdf0fb83229be71e76833ff6e4f5aba6c7c5121..b38fc3d77a6479dfc2a794fee555587e9fcec699 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 7ce8427c4ba6d440d752f9628875f3c56c19f1a5..71c66ffde9d9dd043b6d4448b39d6a38d75b59ed 100644 (file)
@@ -1,4 +1,6 @@
+#ifdef linux
 lib "anl";
+#endif
 
 #include <netdb.h>
 
index e4e2e9bdd4348cdec0e7eaad857a754269aab5e4..0eedec2960b104a20d7949b8dd3d8bbc8ea6b695 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 13b8c83af47b697cad4dbbe5b34ea38e9d3f988a..24b6965e379a8ed0205dc869a1d163b79f5aa67f 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 */