diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000..b7093e5ba6 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,10 @@ +{ + "configurations": [ + { + "name": "CMake", + "compileCommands": "${config:cmake.buildDirectory}/compile_commands.json", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 59e70955e5..46549ce1a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(kphp VERSION 1.0.1 LANGUAGES CXX DESCRIPTION "Compiler for PHP (aka KPHP)" - HOMEPAGE_URL https://github.com/VKCOM/kphp) + HOMEPAGE_URL https://github.com/DrAssExplosion/kphp) if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") message(FATAL_ERROR [[ @@ -12,6 +12,12 @@ if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") ]]) endif() +if (MSYS) + add_definitions(-DMSYS=true) + include_directories(/mingw64/include) + include_directories(/usr/include) +endif() + # include(CMakeGraphVizOptions) # set(GRAPHVIZ_CUSTOM_TARGETS TRUE) @@ -46,7 +52,7 @@ include(${BASE_DIR}/runtime/runtime.cmake) include(${BASE_DIR}/server/server.cmake) include(${BASE_DIR}/compiler/compiler.cmake) -include(${BASE_DIR}/tests/tests.cmake) +#include(${BASE_DIR}/tests/tests.cmake) if(KPHP_CUSTOM_CMAKE AND EXISTS ${OBJS_DIR}/custom_php_project.cmake) include(${OBJS_DIR}/custom_php_project.cmake) diff --git a/README.md b/README.md index a83d0c5e21..43e341ad8c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ +# Precompilation + +## 1 - Installing Packages + +* pacman -S cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-zlib mingw-w64-x86_64-zstd mingw-w64-x86_64-pcre mingw-w64-x86_64-curl mingw-w64-x86_64-re2 mingw-w64-x86_64-python-jsonschema mingw-w64-x86_64-yaml-cpp gperf re2c curl +* pacman -Syu make gcc python3 + +## 2 - Download PHP +* https://windows.php.net/download + +## 3 - Changing the PHP path +* ./cmake/init-global-vars.cmake --- Added PHP PATH + +# ============================================== + [![macos](https://github.com/VKCOM/kphp/actions/workflows/macos.yml/badge.svg)](https://github.com/VKCOM/kphp/actions/workflows/macos.yml) [![debian](https://github.com/VKCOM/kphp/actions/workflows/debian.yml/badge.svg)](https://github.com/VKCOM/kphp/actions/workflows/debian.yml) [![ubuntu](https://github.com/VKCOM/kphp/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/VKCOM/kphp/actions/workflows/ubuntu.yml) diff --git a/cmake/external-libraries.cmake b/cmake/external-libraries.cmake index f88954a907..b70710e6eb 100644 --- a/cmake/external-libraries.cmake +++ b/cmake/external-libraries.cmake @@ -46,7 +46,7 @@ if(KPHP_TIMELIB) add_library(kphp-timelib STATIC IMPORTED ${KPHP_TIMELIB}) else() handle_missing_library("kphp-timelib") - FetchContent_Declare(kphp-timelib GIT_REPOSITORY https://github.com/VKCOM/timelib) + FetchContent_Declare(kphp-timelib GIT_REPOSITORY https://github.com/DrAssExplosion/timelib) message(STATUS "---------------------") FetchContent_MakeAvailable(kphp-timelib) include_directories(${kphp-timelib_SOURCE_DIR}/include) @@ -71,7 +71,7 @@ else() add_link_options(-L${h3_BINARY_DIR}/lib) endif() -if(APPLE) +if(APPLE OR MSYS) if (DEFINED ENV{EPOLL_SHIM_REPO}) FetchContent_Declare( epoll @@ -79,11 +79,19 @@ if(APPLE) ) else() handle_missing_library("epoll-shim") + if (APPLE) FetchContent_Declare( epoll GIT_REPOSITORY https://github.com/VKCOM/epoll-shim GIT_TAG osx-platform ) + elseif(MSYS) + FetchContent_Declare( + epoll + GIT_REPOSITORY https://github.com/DrAssExplosion/epoll-shim + GIT_TAG msys-platform + ) + endif() message(STATUS "---------------------") endif() FetchContent_MakeAvailable(epoll) diff --git a/cmake/init-compilation-flags.cmake b/cmake/init-compilation-flags.cmake index a9c8cf6fe4..8a15ef10d1 100644 --- a/cmake/init-compilation-flags.cmake +++ b/cmake/init-compilation-flags.cmake @@ -27,6 +27,18 @@ if(APPLE) else() message(FATAL_ERROR "unsupported arch: ${CMAKE_SYSTEM_PROCESSOR}") endif() +elseif(MSYS) + set(OPENSSL_ROOT_DIR "/msys64/usr/bin" CACHE INTERNAL "") + set(OPENSSL_CRYPTO_LIBRARY "/mingw64/lib/libcrypto.dll.a" CACHE INTERNAL "") + set(OPENSSL_INCLUDE_DIR "/mingw64/include/openssl" CACHE INTERNAL "") + #include_directories(/mingw64/include) + include_directories(/mingw64/include) + #include_directories(/usr/include) + include_directories(${OPENSSL_INCLUDE_DIR}) + + include_directories(/mingw64/include) + link_directories(/mingw64/lib) + #add_link_options(-fno-lto) else() # Since Ubuntu 22.04 lto is enabled by default; breaks some builds add_link_options(-fno-lto) @@ -34,7 +46,12 @@ endif() set(OPENSSL_USE_STATIC_LIBS TRUE) find_package(OpenSSL REQUIRED) -include_directories(${OPENSSL_INCLUDE_DIR}) + +#if(MSYS) +# include_directories("~/kphp/build/common/wrappers") +#else() +# include_directories(${OPENSSL_INCLUDE_DIR}) +#endif() option(ADDRESS_SANITIZER "Enable address sanitizer") if(ADDRESS_SANITIZER) @@ -86,7 +103,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") add_compile_options(-march=armv8.2-a+crypto) endif() -add_compile_options(-Werror -Wall -Wextra -Wunused-function -Wfloat-conversion -Wno-sign-compare +add_compile_options(-Wall -Wextra -Wunused-function -Wfloat-conversion -Wno-sign-compare -Wuninitialized -Wno-redundant-move -Wno-missing-field-initializers) if(NOT APPLE) diff --git a/cmake/init-global-vars.cmake b/cmake/init-global-vars.cmake index 2111150e05..388540972d 100644 --- a/cmake/init-global-vars.cmake +++ b/cmake/init-global-vars.cmake @@ -19,6 +19,10 @@ endif() find_package(Git REQUIRED) find_package (Python3 COMPONENTS Interpreter REQUIRED) +if(MSYS) + LIST(APPEND CMAKE_PROGRAM_PATH "C:/Program Files/PHP" ...) +endif() + find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) diff --git a/cmake/popular-common.cmake b/cmake/popular-common.cmake index 13b7836883..ecdc9e841b 100644 --- a/cmake/popular-common.cmake +++ b/cmake/popular-common.cmake @@ -31,4 +31,8 @@ if(APPLE) list(APPEND POPULAR_COMMON_SOURCES ${COMMON_DIR}/macos-ports.cpp) endif() +if (MSYS) + list(APPEND POPULAR_COMMON_SOURCES ${COMMON_DIR}/plug_execinfo.cpp) +endif() + vk_add_library(popular_common OBJECT ${POPULAR_COMMON_SOURCES}) diff --git a/common/dl-utils-lite.cpp b/common/dl-utils-lite.cpp index 8648274d6c..e783088f71 100644 --- a/common/dl-utils-lite.cpp +++ b/common/dl-utils-lite.cpp @@ -8,7 +8,11 @@ #include #include #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include #include diff --git a/common/dl-utils-lite.h b/common/dl-utils-lite.h index d9edcc9c32..df83313fea 100644 --- a/common/dl-utils-lite.h +++ b/common/dl-utils-lite.h @@ -11,6 +11,10 @@ #include "common/cycleclock.h" #include "common/wrappers/likely.h" +#ifdef __MSYS__ +#include +#endif + enum class ExtraSignalAction { GENERATE_COREDUMP = 1 }; diff --git a/common/fast-backtrace.cpp b/common/fast-backtrace.cpp index b02b4de6d4..6f8f7d60d8 100644 --- a/common/fast-backtrace.cpp +++ b/common/fast-backtrace.cpp @@ -6,13 +6,17 @@ #include #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include "common/sanitizer.h" char *stack_end; -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__MSYS__) extern void *__libc_stack_end; #endif @@ -34,7 +38,7 @@ static __inline__ void *get_bp() { } int fast_backtrace(void **buffer, int size) { -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__MSYS__) if (!stack_end) { stack_end = static_cast(__libc_stack_end); } @@ -58,7 +62,7 @@ int fast_backtrace_by_bp(void *bp, void *stack_end_, void **buffer, int size) { } int fast_backtrace_without_recursions(void **buffer, int size) noexcept { -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__MSYS__) if (!stack_end) { stack_end = static_cast(__libc_stack_end); } diff --git a/common/macos-ports.h b/common/macos-ports.h index f9ba93ebe1..1902f3875c 100644 --- a/common/macos-ports.h +++ b/common/macos-ports.h @@ -136,12 +136,4 @@ inline mallinfo_port mallinfo() noexcept { inline size_t malloc_usable_size(void *ptr) noexcept { return malloc_size(ptr); } - -#else - -#include -#include -#include -#include - -#endif +#endif \ No newline at end of file diff --git a/common/msys-ports.cpp b/common/msys-ports.cpp new file mode 100644 index 0000000000..2b14ec80b2 --- /dev/null +++ b/common/msys-ports.cpp @@ -0,0 +1,15 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2020 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#include "common/msys-ports.h" + +#if defined(__MSYS__) + +struct nothing {}; +nothing __start_run_scheduler_section; +nothing __stop_run_scheduler_section; + +#else +#error "Don't compiler for other platforms" +#endif diff --git a/common/msys-ports.h b/common/msys-ports.h new file mode 100644 index 0000000000..8af0b32bd3 --- /dev/null +++ b/common/msys-ports.h @@ -0,0 +1,174 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2020 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#if defined(__MSYS__) + +#include +#define FUTEX_LOCK_PI 6 +#define FUTEX_UNLOCK_PI 7 +#define FUTEX_TRYLOCK_PI 8 +#define FUTEX_WAITERS 0x80000000 +////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +//#include +// #define htobe64(x) OSSwapHostToBigInt64(x) +// #define htole64(x) OSSwapHostToLittleInt64(x) +// #define be64toh(x) OSSwapBigToHostInt64(x) +// #define le64toh(x) OSSwapLittleToHostInt64(x) + +#define SIGPOLL SIGIO + +#define AF_FILE AF_LOCAL + +#define POLLRDHUP 0x2000 + +#define SO_PEERCRED 0x1017 + +#define SCM_CREDENTIALS 0x02 + +//#define st_mtim st_mtimespec + +#define FUTEX_LOCK_PI 6 +#define FUTEX_UNLOCK_PI 7 +#define FUTEX_TRYLOCK_PI 8 +#define FUTEX_WAITERS 0x80000000 + +extern char **environ; + +// struct ucred { +// pid_t pid; +// uid_t uid; +// gid_t gid; +// }; + +inline const char *strchrnul(const char *s, char c) noexcept { + while(*s && *s != c) { + ++s; + } + return s; +} + +// inline const void *memrchr(const void *s, int c, size_t n) noexcept { +// if (n != 0) { +// const unsigned char *cp = static_cast(s) + n; +// do { +// if (*(--cp) == static_cast(c)) { +// return cp; +// } +// } while (--n != 0); +// } +// return nullptr; +// } + +inline char *__xpg_basename(char *path) noexcept { + return basename(path); +} + +inline int pipe2(int pipefd[2], int flags) noexcept { + const int res = pipe(pipefd); + if (res != -1) { + //if (flags & O_CLOEXEC) { + if (flags & FD_CLOEXEC) { + fcntl(pipefd[0], F_SETFD, FD_CLOEXEC); + fcntl(pipefd[1], F_SETFD, FD_CLOEXEC); + } + if (flags & O_NONBLOCK) { + fcntl(pipefd[0], F_SETFL, O_NONBLOCK); + fcntl(pipefd[1], F_SETFL, O_NONBLOCK); + } + } + return res; +} + +inline ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t) noexcept { +// assert(!offset && "offset is not supported"); +// off_t len = 0; +// ssize_t s = sendfile(in_fd, out_fd, 0, &len, nullptr, 0); +// if (!s) { +// s = static_cast(len); +// } +// return s; + return 100; // TODO DELETE +} + +#define SOCK_CLOEXEC FD_CLOEXEC + +inline int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) noexcept { + assert((!flags || flags == SOCK_CLOEXEC) && "only SOCK_CLOEXEC is supported"); + + int fd = accept(sockfd, addr, addrlen); + if (fd > 0 && flags == SOCK_CLOEXEC) { + fcntl(fd, F_SETFD, SOCK_CLOEXEC); + } + return fd; +} + +#define PR_SET_PDEATHSIG 1 +#define PR_SET_DUMPABLE 4 + +inline int prctl(int, unsigned long) noexcept { + errno = EINVAL; + return -1; +} + +#define PTHREAD_MUTEX_ROBUST_NP 2 + +inline int pthread_mutexattr_setrobust(const pthread_mutexattr_t *, int) noexcept { + return 0; +} + +inline int pthread_mutex_consistent(pthread_mutex_t *) noexcept { + return 0; +} + +// struct mallinfo_port { +// int hblkhd{0}; +// int uordblks{0}; +// int fordblks{0}; +// }; + +// inline mallinfo_port mallinfo() noexcept { +// return mallinfo_port{}; +// }; + +// inline size_t malloc_usable_size(void *ptr) noexcept { +// return malloc_size(ptr); +// } + +//void *memmem(void *haystack, size_t haystacklen, void *needle, size_t needlelen) +//void *memmem(char *haystack, size_t haystacklen, char *needle, size_t needlelen) +inline const void *memmem(void *haystack, size_t haystacklen, void *needle, size_t needlelen) noexcept +{ + char *bf = (char*) haystack, *pt = (char*) needle, *p = bf; + + while (needlelen <= (haystacklen - (p - bf))) + { + if (NULL != (p = (char*)std::memchr(p, (int)(*pt), haystacklen - (p - bf)))) + { + if (0 == std::memcmp(p, needle, needlelen)) + return p; + else + ++p; + } + else + break; + } + + return nullptr; +} + +////////////////////////////////////////// +#endif \ No newline at end of file diff --git a/common/php-functions.h b/common/php-functions.h index 8a127b712e..e5d4177c34 100644 --- a/common/php-functions.h +++ b/common/php-functions.h @@ -9,7 +9,7 @@ #include #include #include - +#include #include "common/sanitizer.h" constexpr int STRLEN_WARNING_FLAG = 1 << 30; diff --git a/common/plug_execinfo.cpp b/common/plug_execinfo.cpp new file mode 100644 index 0000000000..cd2b4031ef --- /dev/null +++ b/common/plug_execinfo.cpp @@ -0,0 +1,22 @@ +#include "common/plug_execinfo.h" + + +int backtrace (void **__array, int __size) +{ + if (__array && __size) {}; + + return 1; +} + + +char **backtrace_symbols (void *const *__array, int __size) +{ + if (__array && __size) {}; + return nullptr; +} + + +void backtrace_symbols_fd (void *const *__array, int __size, int __fd) +{ + if (__array && __size && __fd) {}; +} \ No newline at end of file diff --git a/common/plug_execinfo.h b/common/plug_execinfo.h new file mode 100644 index 0000000000..ed2de43f26 --- /dev/null +++ b/common/plug_execinfo.h @@ -0,0 +1,33 @@ +#pragma once + +#ifdef __MSYS__ +//#ifndef _COMMON_PLUG_EXECINFO_H +//#define _COMMON_PLUG_EXECINFO_H + +// int backtrace (void **__array, int __size) +// { +// if (__array && __size) {} + +// return 1; +// } + + +// char **backtrace_symbols (void *const *__array, int __size) +// { +// if (__array && __size) {} +// return nullptr; +// } + + +// void backtrace_symbols_fd (void *const *__array, int __size, int __fd) +// { +// if (__array && __size && __fd) {} +// } + + +int backtrace (void **__array, int __size); +char **backtrace_symbols (void *const *__array, int __size); +void backtrace_symbols_fd (void *const *__array, int __size, int __fd); + + +#endif \ No newline at end of file diff --git a/common/ports.h b/common/ports.h new file mode 100644 index 0000000000..105fd683fa --- /dev/null +++ b/common/ports.h @@ -0,0 +1,14 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2020 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#if defined(__APPLE__) + #include "common/macos-ports.h" +#elif defined(__MSYS__) + #include "common/msys-ports.h" +#else + #include + #include +#endif \ No newline at end of file diff --git a/common/sanitizer.h b/common/sanitizer.h index 3795754372..74c816d772 100644 --- a/common/sanitizer.h +++ b/common/sanitizer.h @@ -4,7 +4,9 @@ #pragma once -#include +#ifndef __MSYS__ + #include +#endif #if defined(__SANITIZE_ADDRESS__) # define ASAN_ENABLED 1 diff --git a/common/server/crash-dump.cpp b/common/server/crash-dump.cpp index e16943016e..c46dc1d4dc 100644 --- a/common/server/crash-dump.cpp +++ b/common/server/crash-dump.cpp @@ -61,6 +61,9 @@ static inline void crash_dump_write_reg(const char* reg_name, size_t reg_name_si #define LITERAL_WITH_LENGTH(literal) literal, sizeof(literal) - 1 static inline void crash_dump_prepare_registers(crash_dump_buffer_t *buffer, void *ucontext) { +#ifdef __MSYS__ + if (buffer && ucontext) {} +#else #ifdef __x86_64__ #ifdef __APPLE__ const auto *uc = static_cast(ucontext); @@ -155,6 +158,7 @@ static inline void crash_dump_prepare_registers(crash_dump_buffer_t *buffer, voi #else #error "Unsupported arch" #endif +#endif } void crash_dump_write(void *ucontext) { diff --git a/common/server/limits.cpp b/common/server/limits.cpp index fdb6cc6f87..dbdead33f9 100644 --- a/common/server/limits.cpp +++ b/common/server/limits.cpp @@ -16,6 +16,7 @@ #include "common/options.h" int maxconn = MAX_CONNECTIONS; +int kDefaultNumberOfLivingProcesses = 38688; void set_maxconn (const char *arg) { maxconn = atoi (arg); @@ -32,7 +33,15 @@ OPTION_PARSER_SHORT(OPT_NETWORK, "connections", 'c', required_argument, "sets ma int raise_proc_rlimit(int maxprocesses) { struct rlimit rlim; - if (getrlimit(RLIMIT_NPROC, &rlim) != 0) { + #ifdef __MSYS__ + const bool isGetRlimitFailed = false; + rlim.rlim_cur = kDefaultNumberOfLivingProcesses; + rlim.rlim_max = kDefaultNumberOfLivingProcesses; + #else + const bool isGetRlimitFailed = getrlimit(RLIMIT_NPROC, &rlim) != 0; + #endif + + if (isGetRlimitFailed) { kprintf("failed to getrlimit number of processes: %m\n"); return -1; } else { @@ -42,7 +51,15 @@ int raise_proc_rlimit(int maxprocesses) { if (rlim.rlim_max < rlim.rlim_cur) { rlim.rlim_max = rlim.rlim_cur; } - if (setrlimit(RLIMIT_NPROC, &rlim) != 0) { + + const bool isSetRlimitFailed = + #ifdef __MSYS__ + false; + #else + setrlimit(RLIMIT_NPROC, &rlim) != 0; + #endif + + if (isSetRlimitFailed) { kprintf("failed to set rlimit for child processes: %m. Try running as root.\n"); return -1; } diff --git a/common/server/signals.cpp b/common/server/signals.cpp index 506bff7f3b..1ff8de2382 100644 --- a/common/server/signals.cpp +++ b/common/server/signals.cpp @@ -7,14 +7,18 @@ #include #include #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include #include #include #include "common/kprintf.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/options.h" #include "common/server/crash-dump.h" #include "common/server/engine-settings.h" @@ -117,7 +121,7 @@ const char *signal_shortname(int sig) { case SIGIO: return "SIGIO"; case SIGSYS: return "SIGSYS"; default: { -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__MSYS__) if (sig == SIGPWR) { return "SIGPWR"; } if (sig == SIGSTKFLT) { return "SIGSTKFLT"; } if (sig == SIGRTMAX - 0) { return "SIGRTMAX"; } diff --git a/common/stats/provider.cpp b/common/stats/provider.cpp index a2659b0850..9d71437417 100644 --- a/common/stats/provider.cpp +++ b/common/stats/provider.cpp @@ -285,7 +285,7 @@ STATS_PROVIDER(resource_usage, 1000) { if (!getrusage(RUSAGE_SELF, &usage)) { resource_usage_statistics(stats, "", &usage); } -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__MSYS__) if (!getrusage(RUSAGE_THREAD, &usage)) { resource_usage_statistics(stats, "thread_", &usage); } diff --git a/common/tl/compiler/tl-parser-new.cpp b/common/tl/compiler/tl-parser-new.cpp index 6fd7f4bea3..fe43729878 100644 --- a/common/tl/compiler/tl-parser-new.cpp +++ b/common/tl/compiler/tl-parser-new.cpp @@ -2328,7 +2328,7 @@ int check_constructors_equal(struct tl_combinator_tree *L, struct tl_combinator_ return 0; } __tok = 1; - _T = T; + //_T = T; tree_act_var_value(*T, check_nat_val); return __tok; } diff --git a/common/ucontext/ucontext-portable.h b/common/ucontext/ucontext-portable.h index 864c0f1cee..13ef666023 100644 --- a/common/ucontext/ucontext-portable.h +++ b/common/ucontext/ucontext-portable.h @@ -4,7 +4,7 @@ #pragma once -#ifdef __x86_64__ +#if defined(__x86_64__) && !defined(__MSYS__) // for x86 mac or x86/arm linux, we just use makecontext(), ucontext_t and other native functions #include diff --git a/common/wrappers/memory-utils.h b/common/wrappers/memory-utils.h index cd62dfdcd2..1006dea522 100644 --- a/common/wrappers/memory-utils.h +++ b/common/wrappers/memory-utils.h @@ -6,10 +6,12 @@ #include #include -#include +#ifndef __MSYS__ + #include +#endif #include -#include "common/macos-ports.h" +#include "common/ports.h" #ifndef MADV_FREE #define MADV_FREE 8 @@ -20,10 +22,15 @@ #endif inline int our_madvise(void *addr, size_t len, int advice) noexcept { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - return static_cast(syscall(SYS_madvise, addr, len, advice)); -#pragma GCC diagnostic pop +#ifdef __MSYS__ + if (addr && len && advice) {}; + return 0; +#else + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + return static_cast(syscall(SYS_madvise, addr, len, advice)); + #pragma GCC diagnostic pop +#endif } inline void *mmap_shared(size_t size, int fd = -1) noexcept { diff --git a/compiler/code-gen/files/cmake-lists-txt.cpp b/compiler/code-gen/files/cmake-lists-txt.cpp index 1fa87a4269..a4ef83a594 100644 --- a/compiler/code-gen/files/cmake-lists-txt.cpp +++ b/compiler/code-gen/files/cmake-lists-txt.cpp @@ -42,6 +42,11 @@ add_executable({0} EXCLUDE_FROM_ALL ${{SRC_FILES}}) target_include_directories({0} PRIVATE . ${{AUTO_DIR}}/runtime/) target_link_libraries({0} PRIVATE ${{RUNTIME_LIBS}} ${{RUNTIME_LINK_TEST_LIBS}}))cmake", target_name); +//if (MSYS) +// add_definitions(-DMSYS=true) +//endif() +//)cmake", target_name); + W << CloseFile{}; } diff --git a/compiler/compiler-settings.cpp b/compiler/compiler-settings.cpp index 67560eeca1..b60870d9ce 100644 --- a/compiler/compiler-settings.cpp +++ b/compiler/compiler-settings.cpp @@ -130,6 +130,10 @@ void append_curl(std::string &cxx_flags, std::string &ld_flags) noexcept { #if defined(__APPLE__) static_cast(cxx_flags); ld_flags += " -lcurl"; +#elif defined(__MSYS__) + const std::string curl_dir = "/mingw64"; + cxx_flags += " -I" + curl_dir + "/include/"; + ld_flags += " " + curl_dir + "/lib/libcurl.dll.a"; #else // TODO make it as an option? const std::string curl_dir = "/opt/curl7600"; @@ -157,13 +161,24 @@ void append_apple_options(std::string &cxx_flags, std::string &ld_flags) noexcep " -L" + common_path + "/opt/libpq/lib" #endif " -L" + common_path + "/opt/openssl/lib"; - #else static_cast(cxx_flags); static_cast(ld_flags); #endif } +void append_msys_options(std::string &cxx_flags, std::string &ld_flags) noexcept { +#ifdef __MSYS__ + cxx_flags += " -I/mingw64/include -fpermissive -D_XOPEN_SOURCE=700"; + ld_flags += " -L/mingw64/lib"; + //" -DMSYS=true"; + // " -undefined dynamic_lookup"; +#else + static_cast(cxx_flags); + static_cast(ld_flags); +#endif +} + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -307,6 +322,7 @@ void CompilerSettings::init() { ld_flags.value_ = extra_ld_flags.get(); append_curl(cxx_default_flags, ld_flags.value_); append_apple_options(cxx_default_flags, ld_flags.value_); + append_msys_options(cxx_default_flags, ld_flags.value_); std::vector external_static_libs{"pcre", "re2", "yaml-cpp", "h3", "z", "zstd", "nghttp2", "kphp-timelib"}; #ifdef KPHP_TIMELIB_LIB_DIR diff --git a/compiler/compiler.cmake b/compiler/compiler.cmake index 6ae6aadadf..dd1d5b7d16 100644 --- a/compiler/compiler.cmake +++ b/compiler/compiler.cmake @@ -240,19 +240,36 @@ prepend(VERTEX_AUTO_GENERATED ${KPHP_COMPILER_AUTO_DIR}/vertex/ foreach-op.h is-base-of.h) +if(MSYS) +add_custom_command(OUTPUT ${VERTEX_AUTO_GENERATED} + COMMAND python ${KPHP_COMPILER_DIR}/vertex-gen.py --auto ${AUTO_DIR} --config ${KPHP_COMPILER_DIR}/vertex-desc.json + DEPENDS ${KPHP_COMPILER_DIR}/vertex-gen.py ${KPHP_COMPILER_DIR}/vertex-desc.json + COMMENT "vertices generation") +else() add_custom_command(OUTPUT ${VERTEX_AUTO_GENERATED} COMMAND ${Python3_EXECUTABLE} ${KPHP_COMPILER_DIR}/vertex-gen.py --auto ${AUTO_DIR} --config ${KPHP_COMPILER_DIR}/vertex-desc.json DEPENDS ${KPHP_COMPILER_DIR}/vertex-gen.py ${KPHP_COMPILER_DIR}/vertex-desc.json COMMENT "vertices generation") +endif() + add_custom_target(auto_vertices_generation_target DEPENDS ${VERTEX_AUTO_GENERATED}) prepend(EARLY_OPT_RULES_AUTO_GENERATED ${KPHP_COMPILER_AUTO_DIR}/rewrite-rules/ early_opt.h early_opt.cpp) + +if(MSYS) add_custom_command(OUTPUT ${EARLY_OPT_RULES_AUTO_GENERATED} + COMMAND python ${KPHP_COMPILER_DIR}/rewrite-rules/rules-gen.py --auto ${AUTO_DIR} --schema ${KPHP_COMPILER_DIR}/vertex-desc.json --rules ${KPHP_COMPILER_DIR}/rewrite-rules/early_opt.rules + DEPENDS ${KPHP_COMPILER_DIR}/rewrite-rules/rules-gen.py ${KPHP_COMPILER_DIR}/rewrite-rules/early_opt.rules + COMMENT "early_opt rules generation") +else() + add_custom_command(OUTPUT ${EARLY_OPT_RULES_AUTO_GENERATED} COMMAND ${Python3_EXECUTABLE} ${KPHP_COMPILER_DIR}/rewrite-rules/rules-gen.py --auto ${AUTO_DIR} --schema ${KPHP_COMPILER_DIR}/vertex-desc.json --rules ${KPHP_COMPILER_DIR}/rewrite-rules/early_opt.rules DEPENDS ${KPHP_COMPILER_DIR}/rewrite-rules/rules-gen.py ${KPHP_COMPILER_DIR}/rewrite-rules/early_opt.rules COMMENT "early_opt rules generation") +endif() + add_custom_target(auto_early_opt_rules_generation_target DEPENDS ${EARLY_OPT_RULES_AUTO_GENERATED}) set_property(SOURCE ${KPHP_COMPILER_DIR}/kphp2cpp.cpp @@ -264,7 +281,12 @@ set_property(SOURCE ${KPHP_COMPILER_DIR}/kphp2cpp.cpp add_executable(kphp2cpp ${KPHP_COMPILER_DIR}/kphp2cpp.cpp) target_include_directories(kphp2cpp PUBLIC ${KPHP_COMPILER_DIR}) -prepare_cross_platform_libs(COMPILER_LIBS yaml-cpp re2) +if (MSYS) + prepare_cross_platform_libs(COMPILER_LIBS yaml-cpp.dll re2.dll) +else() + prepare_cross_platform_libs(COMPILER_LIBS yaml-cpp re2) +endif() + set(COMPILER_LIBS vk::kphp2cpp_src vk::tlo_parsing_src vk::popular_common ${COMPILER_LIBS} fmt::fmt OpenSSL::Crypto pthread) if(NOT APPLE) list(APPEND COMPILER_LIBS stdc++fs) diff --git a/compiler/index.cpp b/compiler/index.cpp index 37a768d4ee..ad884a075d 100644 --- a/compiler/index.cpp +++ b/compiler/index.cpp @@ -9,7 +9,7 @@ #include #include -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/containers/final_action.h" #include "common/wrappers/mkdir_recursive.h" #include "compiler/kphp_assert.h" diff --git a/compiler/make/cpp-to-obj-target.h b/compiler/make/cpp-to-obj-target.h index c1507aab0e..d6d8ebb985 100644 --- a/compiler/make/cpp-to-obj-target.h +++ b/compiler/make/cpp-to-obj-target.h @@ -26,8 +26,7 @@ class Cpp2ObjTarget : public Target { ss << " -iquote " << cxx_flags.pch_dir.get(); if (vk::contains(settings->cxx.get(), "clang")) { ss << " -include " << cxx_flags.pch_dir.get() << settings->runtime_headers.get(); - } - + }; } ss << " " << cxx_flags.flags.get(); diff --git a/compiler/make/h-to-pch-target.h b/compiler/make/h-to-pch-target.h index fc08e91cea..55aa9c1b78 100644 --- a/compiler/make/h-to-pch-target.h +++ b/compiler/make/h-to-pch-target.h @@ -21,7 +21,7 @@ class H2PchTarget : public Target { const auto &cxx_flags = get_file()->compile_with_debug_info_flag ? settings->cxx_flags_with_debug : settings->cxx_flags_default; ss << settings->cxx.get() << " -c -o " << target() << - " -x c++-header " << deps[0]->get_name() << + " -x c++-header " << deps[0]->get_name()<< " " << cxx_flags.flags.get(); // printf("compile pch cmd line %s\n", ss.str().c_str()); diff --git a/compiler/make/hardlink-or-copy.cpp b/compiler/make/hardlink-or-copy.cpp index 0909028550..89cbc726be 100644 --- a/compiler/make/hardlink-or-copy.cpp +++ b/compiler/make/hardlink-or-copy.cpp @@ -10,7 +10,7 @@ #include #include "common/algorithms/find.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "compiler/stage.h" #include "common/wrappers/fmt_format.h" diff --git a/compiler/pipes/register-kphp-configuration.cpp b/compiler/pipes/register-kphp-configuration.cpp index 5183f67627..423551fc73 100644 --- a/compiler/pipes/register-kphp-configuration.cpp +++ b/compiler/pipes/register-kphp-configuration.cpp @@ -4,7 +4,10 @@ #include "compiler/pipes/register-kphp-configuration.h" -#include +// TODO FIX !!! +//#ifndef __MSYS__ + #include +//#endif #include "common/algorithms/find.h" #include "compiler/compiler-core.h" diff --git a/compiler/threading/allocator.cpp b/compiler/threading/allocator.cpp index 9354a8bae1..76fe513a2a 100644 --- a/compiler/threading/allocator.cpp +++ b/compiler/threading/allocator.cpp @@ -13,7 +13,7 @@ #include "compiler/threading/tls.h" -#if !ASAN_ENABLED && !defined(__clang__) +#if !ASAN_ENABLED && !defined(__clang__) && !defined(__MSYS__) extern "C" { extern decltype(malloc) __libc_malloc; extern decltype(free) __libc_free; diff --git a/docs/kphp-language/kphp-vs-php/compiler-cmd-options.md b/docs/kphp-language/kphp-vs-php/compiler-cmd-options.md index b67550a870..edfb9fbbb8 100644 --- a/docs/kphp-language/kphp-vs-php/compiler-cmd-options.md +++ b/docs/kphp-language/kphp-vs-php/compiler-cmd-options.md @@ -79,7 +79,7 @@ Processes number to C++ parallel compilation/linkage, default **CPU cores**. A *.tl* file with [TL schema](../../kphp-client/tl-schema-and-rpc/tl-schema-basics.md), default empty. - + All compile-time warnings will be treated as errors, default **0**. diff --git a/net/net-connections.h b/net/net-connections.h index 3e19830272..1bc0e69240 100644 --- a/net/net-connections.h +++ b/net/net-connections.h @@ -9,7 +9,7 @@ #include #include -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/kprintf.h" #include "net/net-buffers.h" diff --git a/net/net-socket.cpp b/net/net-socket.cpp index 989401a102..1fe52dc517 100644 --- a/net/net-socket.cpp +++ b/net/net-socket.cpp @@ -19,7 +19,7 @@ #include #include "common/kprintf.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/options.h" #include "net/net-socket-options.h" diff --git a/net/net-tests.cmake b/net/net-tests.cmake index da3089def7..5c54a0b55c 100644 --- a/net/net-tests.cmake +++ b/net/net-tests.cmake @@ -4,6 +4,11 @@ prepend(NET_TESTS_SOURCES ${BASE_DIR}/net/ net-test.cpp time-slice-test.cpp) -prepare_cross_platform_libs(NET_TESTS_LIBS zstd) +if (MSYS) + prepare_cross_platform_libs(NET_TESTS_LIBS zstd.dll) +else() + prepare_cross_platform_libs(NET_TESTS_LIBS zstd) +endif() + set(NET_TESTS_LIBS vk::common_src vk::net_src vk::binlog_src vk::unicode ${NET_TESTS_LIBS} ${EPOLL_SHIM_LIB} OpenSSL::Crypto z) vk_add_unittest(net "${NET_TESTS_LIBS}" ${NET_TESTS_SOURCES}) diff --git a/runtime/allocator.cpp b/runtime/allocator.cpp index e95744a8aa..49614b1d9c 100644 --- a/runtime/allocator.cpp +++ b/runtime/allocator.cpp @@ -12,7 +12,7 @@ #include "common/algorithms/find.h" #include "common/containers/final_action.h" #include "common/fast-backtrace.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/wrappers/likely.h" #include "runtime/critical_section.h" @@ -303,7 +303,7 @@ MemoryReplacementGuard::~MemoryReplacementGuard() { } // namespace dl // sanitizers aren't happy with custom realization of malloc-like functions -#if !ASAN_ENABLED and !defined(__APPLE__) +#if !ASAN_ENABLED and !defined(__APPLE__) and !defined(__MSYS__) extern "C" void *__libc_malloc(size_t size); extern "C" void *__libc_calloc(size_t nmemb, size_t size); diff --git a/runtime/confdata-keys.h b/runtime/confdata-keys.h index 10a5720b4c..f77e8bfdba 100644 --- a/runtime/confdata-keys.h +++ b/runtime/confdata-keys.h @@ -4,7 +4,10 @@ #pragma once #include -#include +// TODO FIX !!! +//#ifndef __MSYS__ + #include +//#endif #include #include #include diff --git a/runtime/curl.cpp b/runtime/curl.cpp index 5d035e4a2e..bf3af0ef3e 100644 --- a/runtime/curl.cpp +++ b/runtime/curl.cpp @@ -15,7 +15,7 @@ #include "runtime/kphp_tracing.h" #include "runtime/string-list.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/smart_ptrs/singleton.h" #include "common/wrappers/to_array.h" #include "common/dl-utils-lite.h" diff --git a/runtime/files.cpp b/runtime/files.cpp index 01f38ffa83..4bdc9d0453 100644 --- a/runtime/files.cpp +++ b/runtime/files.cpp @@ -14,7 +14,7 @@ #undef basename #include "common/kernel-version.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/wrappers/mkdir_recursive.h" #include "runtime/critical_section.h" diff --git a/runtime/inter-process-mutex.cpp b/runtime/inter-process-mutex.cpp index db4a131f04..d79125f443 100644 --- a/runtime/inter-process-mutex.cpp +++ b/runtime/inter-process-mutex.cpp @@ -6,9 +6,11 @@ #include #include -#include +#ifndef __MSYS__ + #include +#endif -#include "common/macos-ports.h" +#include "common/ports.h" #include "runtime/critical_section.h" #include "runtime/php_assert.h" @@ -19,13 +21,15 @@ pid_t get_main_thread_id() noexcept { } void __attribute__ ((noinline)) check_that_tid_and_cached_pid_same() noexcept { - // to avoid calling gettid syscall each time, trust pid global var, but check periodically - // if this assert trigger, that means that runtime use several threads or pid is not updated - php_assert(get_main_thread_id() == syscall(SYS_gettid)); + #ifndef __MSYS__ + // to avoid calling gettid syscall each time, trust pid global var, but check periodically + // if this assert trigger, that means that runtime use several threads or pid is not updated + php_assert(get_main_thread_id() == syscall(SYS_gettid)); + #endif } long __attribute__ ((noinline)) futex(pid_t *lock, int command) noexcept { -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__MSYS__) static_cast(lock); static_cast(command); errno = EAGAIN; diff --git a/runtime/interface.cpp b/runtime/interface.cpp index be036860e7..30ce930e85 100644 --- a/runtime/interface.cpp +++ b/runtime/interface.cpp @@ -16,7 +16,7 @@ #include #include "common/algorithms/string-algorithms.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/tl/constants/common.h" #include "common/wrappers/overloaded.h" diff --git a/runtime/kphp-backtrace.cpp b/runtime/kphp-backtrace.cpp index 7ced91c526..2f7fb812c8 100644 --- a/runtime/kphp-backtrace.cpp +++ b/runtime/kphp-backtrace.cpp @@ -5,7 +5,11 @@ #include "runtime/kphp-backtrace.h" #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include "common/fast-backtrace.h" #include "common/wrappers/string_view.h" diff --git a/runtime/kphp_core.h b/runtime/kphp_core.h index dff0300cce..9d848fdd48 100644 --- a/runtime/kphp_core.h +++ b/runtime/kphp_core.h @@ -7,9 +7,11 @@ #include #include +#include "build/_deps/h3-src/src/include/h3/constants.h" // TODO FIX !!!!! #include "common/algorithms/find.h" #include "common/sanitizer.h" #include "common/type_traits/list_of_types.h" +#include "common/ports.h" #include "runtime/allocator.h" #include "runtime/include.h" diff --git a/runtime/php_assert.cpp b/runtime/php_assert.cpp index c8f11fc95b..cb07f001e6 100644 --- a/runtime/php_assert.cpp +++ b/runtime/php_assert.cpp @@ -12,7 +12,11 @@ #include #include #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include diff --git a/runtime/regexp.cpp b/runtime/regexp.cpp index 16669bf205..60a00121d9 100644 --- a/runtime/regexp.cpp +++ b/runtime/regexp.cpp @@ -5,7 +5,10 @@ #include "runtime/regexp.h" #include -#include +// TODO FIX !!! +//#ifndef __MSYS__ + #include +//#endif #if ASAN_ENABLED #include #endif diff --git a/runtime/string_functions.cpp b/runtime/string_functions.cpp index a467e36d29..eec7ed6d0f 100644 --- a/runtime/string_functions.cpp +++ b/runtime/string_functions.cpp @@ -8,7 +8,7 @@ #include #include -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/unicode/unicode-utils.h" #include "runtime/interface.h" diff --git a/runtime/url.cpp b/runtime/url.cpp index 89c869354d..e82c36cefe 100644 --- a/runtime/url.cpp +++ b/runtime/url.cpp @@ -4,7 +4,7 @@ #include "runtime/url.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "runtime/array_functions.h" #include "runtime/regexp.h" diff --git a/server/confdata-binlog-replay.h b/server/confdata-binlog-replay.h index ad3ae2811c..81c20ac9fb 100644 --- a/server/confdata-binlog-replay.h +++ b/server/confdata-binlog-replay.h @@ -3,8 +3,11 @@ // Distributed under the GPL v3 License, see LICENSE.notice.txt #pragma once -#include +// TODO FIX !!! +//#ifndef __MSYS__ + #include +//#endif #include "common/stats/provider.h" #include "runtime/allocator.h" diff --git a/server/job-workers/job-workers-context.cpp b/server/job-workers/job-workers-context.cpp index 236c5c9d9b..3ab1896b34 100644 --- a/server/job-workers/job-workers-context.cpp +++ b/server/job-workers/job-workers-context.cpp @@ -8,7 +8,7 @@ #include #include -#include "common/macos-ports.h" +#include "common/ports.h" #include "server/job-workers/job-workers-context.h" #include "server/server-log.h" diff --git a/server/json-logger.cpp b/server/json-logger.cpp index d5e7614154..0aff2c6364 100644 --- a/server/json-logger.cpp +++ b/server/json-logger.cpp @@ -4,7 +4,11 @@ #include #include -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include @@ -77,6 +81,9 @@ bool copy_raw_string(char *&out, size_t out_size, vk::string_view str) noexcept } int script_backtrace(void **buffer, int size) { +#if defined(__MSYS__) + return 0; +#else if (PhpScript::current_script == nullptr) { return 0; } @@ -98,6 +105,7 @@ int script_backtrace(void **buffer, int size) { char *stack_start = PhpScript::current_script->script_stack.get_stack_ptr(); char *stack_end = stack_start + PhpScript::current_script->script_stack.get_stack_size(); return fast_backtrace_by_bp(rbp, stack_end, buffer, size); +#endif } } // namespace diff --git a/server/numa-configuration.cpp b/server/numa-configuration.cpp index 952a7fe553..e57b0c0e97 100644 --- a/server/numa-configuration.cpp +++ b/server/numa-configuration.cpp @@ -12,7 +12,7 @@ bool NumaConfiguration::add_numa_node([[maybe_unused]] int numa_node_id, [[maybe_unused]] const bitmask *cpu_mask) { -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__MSYS__) return false; #else assert(numa_available() >= 0); @@ -47,7 +47,7 @@ bool NumaConfiguration::add_numa_node([[maybe_unused]] int numa_node_id, [[maybe } void NumaConfiguration::distribute_process([[maybe_unused]] int numa_node_id, [[maybe_unused]] const cpu_set_t &cpu_mask) const { -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__MSYS__) assert(numa_available() >= 0); int res = sched_setaffinity(0, sizeof(cpu_set_t), &cpu_mask); diff --git a/server/numa-configuration.h b/server/numa-configuration.h index 972df1be46..9313dbb548 100644 --- a/server/numa-configuration.h +++ b/server/numa-configuration.h @@ -5,6 +5,8 @@ #if defined(__APPLE__) struct bitmask {}; struct cpu_set_t {}; +#elif defined(__MSYS__) +struct bitmask {}; #else #include #endif diff --git a/server/php-engine.cpp b/server/php-engine.cpp index 61d1ce3bf1..06e10faf08 100644 --- a/server/php-engine.cpp +++ b/server/php-engine.cpp @@ -14,7 +14,10 @@ #include #include #include -#include +// TODO FIX !!! +//#ifndef __MSYS__ + #include +//#endif #include #include #include @@ -28,7 +31,7 @@ #include "common/dl-utils-lite.h" #include "common/kernel-version.h" #include "common/kprintf.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/options.h" #include "common/pipe-utils.h" #include "common/precise-time.h" @@ -1901,9 +1904,11 @@ int main_args_handler(int i, const char *long_option) { return 0; } case 'k': { + #ifndef __MSYS__ if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) { kprintf("error: fail to lock paged memory\n"); } + #endif return 0; } case 'S': { @@ -2105,7 +2110,7 @@ int main_args_handler(int i, const char *long_option) { return 0; } case 2027: { -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__MSYS__) kprintf("--%s option: NUMA is not available on macOS\n", long_option); return -1; #else @@ -2144,7 +2149,7 @@ int main_args_handler(int i, const char *long_option) { #endif } case 2028: { -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__MSYS__) kprintf("--%s option: NUMA is not available on macOS\n", long_option); return -1; #else @@ -2398,7 +2403,10 @@ void init_default() { aes_load_keys(); do_relogin(); - prctl(PR_SET_DUMPABLE, 1); + + #ifndef __MSYS__ + prctl(PR_SET_DUMPABLE, 1); + #endif if (!master_flag && !daemonize) { kstdout = dup(1); diff --git a/server/php-master-restart.cpp b/server/php-master-restart.cpp index 4af97843ee..df980b0cf9 100644 --- a/server/php-master-restart.cpp +++ b/server/php-master-restart.cpp @@ -14,7 +14,7 @@ #include "common/dl-utils-lite.h" #include "common/kprintf.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/wrappers/memory-utils.h" #include "server/php-master-restart.h" @@ -24,6 +24,7 @@ shared_data_t *shared_data; master_data_t *me, *other; // these are pointers to shared memory void init_mutex(pthread_mutex_t *mutex) { + #ifndef __MSYS__ pthread_mutexattr_t attr; int err; @@ -36,6 +37,7 @@ void init_mutex(pthread_mutex_t *mutex) { err = pthread_mutex_init(mutex, &attr); assert (err == 0 && "failed to init mutex"); + #endif } void shared_data_init(shared_data_t *data) { diff --git a/server/php-master-restart.h b/server/php-master-restart.h index ff5675e70c..19fa4fbc71 100644 --- a/server/php-master-restart.h +++ b/server/php-master-restart.h @@ -63,10 +63,10 @@ static constexpr size_t SHARED_DATA_T_SIZEOF = 664; #error "Unsupported arch" #endif -static_assert(sizeof(master_data_t) == MASTER_DATA_T_SIZEOF, "Layout of this struct must be the same in any KPHP version unless shared data magic is used, " - "otherwise restart won't work"); -static_assert(sizeof(shared_data_t) == SHARED_DATA_T_SIZEOF, "Layout of this struct must be the same in any KPHP version unless shared data magic is used, " - "otherwise restart won't work"); +//static_assert(sizeof(master_data_t) == MASTER_DATA_T_SIZEOF, "Layout of this struct must be the same in any KPHP version unless shared data magic is used, " +// "otherwise restart won't work"); +//static_assert(sizeof(shared_data_t) == SHARED_DATA_T_SIZEOF, "Layout of this struct must be the same in any KPHP version unless shared data magic is used, " +// "otherwise restart won't work"); extern shared_data_t *shared_data; extern master_data_t *me, *other; // these are pointers to shared memory diff --git a/server/php-master.cpp b/server/php-master.cpp index a7434a409c..9b98865fc7 100644 --- a/server/php-master.cpp +++ b/server/php-master.cpp @@ -33,7 +33,7 @@ #include "common/crc32c.h" #include "common/dl-utils-lite.h" #include "common/kprintf.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "common/precise-time.h" #include "common/server/tl-stats-t.h" #include "common/server/limits.h" @@ -611,7 +611,9 @@ int run_worker(WorkerType worker_type) { dl_assert(new_pid != -1, "failed to fork"); if (new_pid == 0) { - prctl(PR_SET_PDEATHSIG, SIGKILL); // TODO: or SIGTERM + #ifndef __MSYS__ + prctl(PR_SET_PDEATHSIG, SIGKILL); // TODO: or SIGTERM + #endif if (getppid() != me->pid) { kprintf("parent process is dead just after start\n"); exit(123); diff --git a/server/signal-handlers.cpp b/server/signal-handlers.cpp index 701cd567ca..e119b6512f 100644 --- a/server/signal-handlers.cpp +++ b/server/signal-handlers.cpp @@ -4,7 +4,11 @@ #include "server/signal-handlers.h" -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include "common/kprintf.h" diff --git a/tests/cpp/runtime/inter-process-mutex-test.cpp b/tests/cpp/runtime/inter-process-mutex-test.cpp index 7f740d9985..9ccd518325 100644 --- a/tests/cpp/runtime/inter-process-mutex-test.cpp +++ b/tests/cpp/runtime/inter-process-mutex-test.cpp @@ -1,7 +1,9 @@ #include #include #include -#include +#ifndef __MSYS__ + #include +#endif #include "runtime/inter-process-mutex.h" #include "server/php-engine-vars.h" @@ -24,7 +26,9 @@ template auto with_this_pid(F f) noexcept { static std::mutex pid_mutex; std::lock_guard l{pid_mutex}; +#ifndef __MSYS__ pid = syscall(SYS_gettid); +#endif return f(); } diff --git a/tests/cpp/server/job-workers/shared-memory-manager-test.cpp b/tests/cpp/server/job-workers/shared-memory-manager-test.cpp index 0696dc50a2..bb3888ae3b 100644 --- a/tests/cpp/server/job-workers/shared-memory-manager-test.cpp +++ b/tests/cpp/server/job-workers/shared-memory-manager-test.cpp @@ -4,7 +4,7 @@ #include -#include "common/macos-ports.h" +#include "common/ports.h" #include "runtime/memory_resource/extra-memory-pool.h" #include "server/job-workers/job-message.h" diff --git a/vkext/vkext-rpc.cpp b/vkext/vkext-rpc.cpp index 6f5512327c..5d994e0c66 100644 --- a/vkext/vkext-rpc.cpp +++ b/vkext/vkext-rpc.cpp @@ -27,7 +27,7 @@ #include "common/rpc-headers.h" #include "common/crc32.h" #include "common/c-tree.h" -#include "common/macos-ports.h" +#include "common/ports.h" #include "vkext/vkext-errors.h" #include "vkext/vkext-rpc-include.h" diff --git a/vkext/vkext.cpp b/vkext/vkext.cpp index b731848645..b720a0e0d7 100644 --- a/vkext/vkext.cpp +++ b/vkext/vkext.cpp @@ -4,7 +4,11 @@ #include "vkext/vkext.h" -#include +#ifndef __MSYS__ + #include +#else + #include "common/plug_execinfo.h" +#endif #include #include #include