From patchwork Tue Dec 1 16:39:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 84658 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 97FB6A04DB; Tue, 1 Dec 2020 17:40:17 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8FA7DC9BA; Tue, 1 Dec 2020 17:40:15 +0100 (CET) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by dpdk.org (Postfix) with ESMTP id DB81AC9B0; Tue, 1 Dec 2020 17:40:12 +0100 (CET) Received: by mail-lf1-f67.google.com with SMTP id s27so5472104lfp.5; Tue, 01 Dec 2020 08:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QbmWO+YKhe6EtJ7j/WcyKnbqtWbiS8sOwIaUczbyv/A=; b=Up2vktK9pZvjASGBzSAUVSskhJUPCHbvfGLW00WKTsUbWAVhqXEi14iMDrPJQGLB9s 8SLKWR0o+lalBwiQNzmJQ982R0hax4zJxfE6OuH4GT9pnZhnZY0eoWVlMEyzjW1EoUjE miwWrwnQ6NwwrcsEcIqpF2niJ9DCBoAQGENztWIvE5d2mKKyzP2/Qtf3y+Bj8TPD3rTw oj8x2TGv4M0jL8P8ptNCnJvKqj+LmOoQmuU1kAcuflw/+inZOL1Cm6m8zSIpK1Cb/o2n yj8RL1cdjqFuH/oTHWQfNsROqUD1eS44gqzEe9pfgio/MbdeGGVHoTI8wpFDfmMEeWxh NEoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QbmWO+YKhe6EtJ7j/WcyKnbqtWbiS8sOwIaUczbyv/A=; b=TBNyJJkcx84yUeahq6yTnNRYMiPFTQPX80TwyIDc6u2Lu9tCcHBgFHIyTog6M+4xo8 uruYN2U+/tGdtfFYcbgORG0Z3UEmbOUIp1i6IzIr3kFGun8t40MYhSQbT/F48aocafpF rsWpve7HH/lP30RphNnZ67oiSyuqxDQuplMDqn9pqw8OKK9U7qocQsUfoxu4dWVjoSlN 3ncm7jnerp71Hr4+RypEUyfO+FbTcQ1kKbK3RSuVZVRZXP+IAPrufBMmgt/SlQZ3H0ru awg2hOl8ds1uygg8+XyJmO/GfY/Qz6AJ+AsjXVAg9dQ4zU3xIw076VEhN1PMhnnvKWPj E6yw== X-Gm-Message-State: AOAM530acvEi3K1SPmqrJfvFHAWEu3NdvCd4eK+fURl27SPZomBbI8Bt 8orgL4ddTnU98rl+AoB7aZBVlxe8QAbFYQ== X-Google-Smtp-Source: ABdhPJziiyivBG1o+moy9PMk/OfKfQOCVJRm9awtBcFUke+lLPlhCdbAKIqcFna9/4kGmTn0BEjcuQ== X-Received: by 2002:a05:6512:405:: with SMTP id u5mr1628955lfk.286.1606840811055; Tue, 01 Dec 2020 08:40:11 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id q27sm253553lfo.242.2020.12.01.08.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 08:40:10 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , stable@dpdk.org, Thomas Monjalon , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Tue, 1 Dec 2020 19:39:58 +0300 Message-Id: <20201201163959.9590-1-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] eal/windows: fix build with MinGW-w64 8.0.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" MinGW-w64 above 8.0.0 exposes VirtualAlloc2() API in headers, but lacks it in import libraries. Hence, availability of this API at compile-time can't be used to choose between locating VirtualAlloc2() manually or relying on the dynamic linker. Fix redefinition compile-time errors. Always link VirtualAlloc2() when using GCC. Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management") Cc: stable@dpdk.org Reported-by: Thomas Monjalon Signed-off-by: Dmitry Kozlyuk --- lib/librte_eal/windows/eal_memory.c | 42 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/librte_eal/windows/eal_memory.c b/lib/librte_eal/windows/eal_memory.c index 7f8d3c2fa..2cf5a5e64 100644 --- a/lib/librte_eal/windows/eal_memory.c +++ b/lib/librte_eal/windows/eal_memory.c @@ -18,13 +18,12 @@ #include /* MinGW-w64 headers lack VirtualAlloc2() in some distributions. - * Provide a copy of definitions and code to load it dynamically. * Note: definitions are copied verbatim from Microsoft documentation * and don't follow DPDK code style. - * - * MEM_RESERVE_PLACEHOLDER being defined means VirtualAlloc2() is present too. */ -#ifndef MEM_PRESERVE_PLACEHOLDER +#ifndef MEM_EXTENDED_PARAMETER_TYPE_BITS + +#define MEM_EXTENDED_PARAMETER_TYPE_BITS 4 /* https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-mem_extended_parameter_type */ typedef enum MEM_EXTENDED_PARAMETER_TYPE { @@ -37,8 +36,6 @@ typedef enum MEM_EXTENDED_PARAMETER_TYPE { MemExtendedParameterMax } *PMEM_EXTENDED_PARAMETER_TYPE; -#define MEM_EXTENDED_PARAMETER_TYPE_BITS 4 - /* https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-mem_extended_parameter */ typedef struct MEM_EXTENDED_PARAMETER { struct { @@ -54,6 +51,8 @@ typedef struct MEM_EXTENDED_PARAMETER { } DUMMYUNIONNAME; } MEM_EXTENDED_PARAMETER, *PMEM_EXTENDED_PARAMETER; +#endif /* defined(MEM_EXTENDED_PARAMETER_TYPE_BITS) */ + /* https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc2 */ typedef PVOID (*VirtualAlloc2_type)( HANDLE Process, @@ -65,17 +64,19 @@ typedef PVOID (*VirtualAlloc2_type)( ULONG ParameterCount ); -/* VirtualAlloc2() flags. */ +/* MinGW-w64 distributions, even those that declare VirtualAlloc2(), + * lack it in import libraries, which results in a failure at link time. + * Link it dynamically in such case. + */ +static VirtualAlloc2_type VirtualAlloc2_ptr; + +#ifdef RTE_TOOLCHAIN_GCC + #define MEM_COALESCE_PLACEHOLDERS 0x00000001 #define MEM_PRESERVE_PLACEHOLDER 0x00000002 #define MEM_REPLACE_PLACEHOLDER 0x00004000 #define MEM_RESERVE_PLACEHOLDER 0x00040000 -/* Named exactly as the function, so that user code does not depend - * on it being found at compile time or dynamically. - */ -static VirtualAlloc2_type VirtualAlloc2; - int eal_mem_win32api_init(void) { @@ -89,7 +90,7 @@ eal_mem_win32api_init(void) int ret = 0; /* Already done. */ - if (VirtualAlloc2 != NULL) + if (VirtualAlloc2_ptr != NULL) return 0; library = LoadLibraryA(library_name); @@ -98,9 +99,9 @@ eal_mem_win32api_init(void) return -1; } - VirtualAlloc2 = (VirtualAlloc2_type)( + VirtualAlloc2_ptr = (VirtualAlloc2_type)( (void *)GetProcAddress(library, function)); - if (VirtualAlloc2 == NULL) { + if (VirtualAlloc2_ptr == NULL) { RTE_LOG_WIN32_ERR("GetProcAddress(\"%s\", \"%s\")\n", library_name, function); @@ -117,14 +118,15 @@ eal_mem_win32api_init(void) #else -/* Stub in case VirtualAlloc2() is provided by the compiler. */ +/* Stub in case VirtualAlloc2() is provided by the toolchain. */ int eal_mem_win32api_init(void) { + VirtualAlloc2_ptr = VirtualAlloc2; return 0; } -#endif /* defined(MEM_RESERVE_PLACEHOLDER) */ +#endif /* defined(RTE_TOOLCHAIN_GCC) */ static HANDLE virt2phys_device = INVALID_HANDLE_VALUE; @@ -278,7 +280,7 @@ eal_mem_reserve(void *requested_addr, size_t size, int flags) process = GetCurrentProcess(); - virt = VirtualAlloc2(process, requested_addr, size, + virt = VirtualAlloc2_ptr(process, requested_addr, size, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS, NULL, 0); if (virt == NULL) { @@ -364,7 +366,7 @@ eal_mem_commit(void *requested_addr, size_t size, int socket_id) } flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; - addr = VirtualAlloc2(process, requested_addr, size, + addr = VirtualAlloc2_ptr(process, requested_addr, size, flags, PAGE_READWRITE, ¶m, param_count); if (addr == NULL) { /* Logging may overwrite GetLastError() result. */ @@ -406,7 +408,7 @@ eal_mem_decommit(void *addr, size_t size) } flags = MEM_RESERVE | MEM_RESERVE_PLACEHOLDER; - stub = VirtualAlloc2( + stub = VirtualAlloc2_ptr( process, addr, size, flags, PAGE_NOACCESS, NULL, 0); if (stub == NULL) { /* We lost the race for the VA. */