From 036752dbbcb77494de9935ac459ea5cf0ea34b4b Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 22 Nov 2018 17:25:48 +0100 Subject: [PATCH] paranoid push --- Makefile.frag | 10 ++++++++++ php_psi_posix.h.in | 18 ++++++++++++++++++ psi.d/arpa_inet.psi | 2 +- psi.d/netdb.psi | 2 ++ src/builtin.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/builtin.h | 4 ++++ 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Makefile.frag b/Makefile.frag index 589785d..a9f6035 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -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="; \ + else \ + git ci -am flush; \ + git push $DEST; \ + fi + diff --git a/php_psi_posix.h.in b/php_psi_posix.h.in index a0527c5..4f4acd3 100644 --- a/php_psi_posix.h.in +++ b/php_psi_posix.h.in @@ -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}, diff --git a/psi.d/arpa_inet.psi b/psi.d/arpa_inet.psi index 6fdf0fb..b38fc3d 100644 --- a/psi.d/arpa_inet.psi +++ b/psi.d/arpa_inet.psi @@ -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 +} diff --git a/psi.d/netdb.psi b/psi.d/netdb.psi index 7ce8427..71c66ff 100644 --- a/psi.d/netdb.psi +++ b/psi.d/netdb.psi @@ -1,4 +1,6 @@ +#ifdef linux lib "anl"; +#endif #include diff --git a/src/builtin.c b/src/builtin.c index e4e2e9b..0eedec2 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -178,3 +178,43 @@ static bool COUNTER__(struct psi_cpp *cpp, struct psi_token *target, return true; } + +#ifdef __APPLE__ +#include +# define bswap_16(u) _OSSwapInt16(u) +# define bswap_32(u) _OSSwapInt32(u) +# define bswap_64(u) _OSSwapInt64(u) +#elif defined(__FreeBSD__) +# include +# define bswap_16(u) bswap16(u) +# define bswap_32(u) bswap32(u) +# define bswap_64(u) bswap64(u) +#elif defined(__OpenBSD__) +# include +# define bswap_16(u) swap16(u) +# define bswap_32(u) swap32(u) +# define bswap_64(u) swap64(u) +#elif defined(__NetBSD__) +# include +# include +# define bswap_16(u) bswap16(u) +# define bswap_32(u) bswap32(u) +# define bswap_64(u) bswap64(u) +#else +# include +#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); +} diff --git a/src/builtin.h b/src/builtin.h index 13b8c83..24b6965 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -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 */ -- 2.30.2