From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-4325.protonmail.ch (mail-4325.protonmail.ch [185.70.43.25]) by sourceware.org (Postfix) with ESMTPS id DB7FB3858D35; Wed, 15 Feb 2023 09:43:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB7FB3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com Date: Wed, 15 Feb 2023 09:43:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1676454196; x=1676713396; bh=jxhrrXWjmR1mblCMO6kNkv4p7cGnHCIYZ/glKr36dWw=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=U5dQYFENQxjiZTykj4IHQeMkmPfiOIOnB7YhxvhK2LvlMr8HF77iqwqfwcKk1AsqV zv9YWL/54n6Vu2dY89TTQaTe3Nx+gOhiRh4c+rMIqFVCHLBI0JDWLV27OV6uznXeVS p3eMe7Da3zeLYVRKE+bSTKzxF+Wb3OCmRn1ldx0K+xgfEbleKvXe2T4M3BIBnUvtRz jWTKcwQd4iVBYr9puq3upjvZpR8GoapFuY5o2B/17fK/1ZzbfBB8x+K8p0JuOo6oy8 /IdBpoicXSM/rna21ZkSztAoO8RaW+LYXx/ngDw/lJ+yetQ2+ZPeIQszAvJRdptvVb Jwne12NFsUuJw== To: "cygwin@cygwin.com" , "cygwin-developers@cygwin.com" From: w6b7rk5yu4mt25v3 Subject: Re: Why do these mprotect always fail? Message-ID: In-Reply-To: References: Feedback-ID: 67221101:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Almost forgot, PAGE_SIZE is set to 4096. This is a Linux application, when = I compile on Cygwin it complained that PAGE_SIZE is redefined but the compi= lation was success nevertheless. Only when I run the application, I always = exited with "Unable to mprotect". Sent with Proton Mail secure email. ------- Original Message ------- On Wednesday, February 15th, 2023 at 16:38, w6b7rk5yu4mt25v3 wrote: > mprotect 1: >=20 > unsigned char* buffer; > int32_t available, size; >=20 > if(size > PAGE_SIZE) { >=20 > factor =3D size / PAGE_SIZE + 1; > } > available =3D factor * PAGE_SIZE; >=20 > if(posix_memalign((void**)&buffer, PAGE_SIZE, available)) { > std::wcerr << L"Unable to allocate JIT memory!" << std::endl; > exit(1); > } > if(mprotect(buffer, available, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { > std::wcerr << L"Unable to mprotect" << std::endl; > exit(1); > } >=20 > mprotect 2: >=20 > if(posix_memalign((void**)& buffer, PAGE_SIZE, PAGE_SIZE)) { > std::wcerr << L"Unable to allocate JIT memory!" << std::endl; > exit(1); > } >=20 > if(mprotect(buffer, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { > std::wcerr << L"Unable to mprotect" << std::endl; > exit(1); > } >=20 >=20 > Sent with Proton Mail secure email.