X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F00C3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1676454251; bh=EOIMzbT1asXEoT3GfPfASDTY4gcRBbPDwGPjTHxk3GE=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WRv/sOMD2qSk039xDj+Ck30I+4eAvJGDqJNJ1wvTfFUdbH9IkUUJ3JIKCN49PRiw1 huDfLqfggdpBlkTBm3ZWXUqpKqG286VQpG2FxTKISHA1RZAJPDbamz0AGYVJQlfaiW xYkPZPWiOzufdbgHv8x3QT9yL9pwZfyW1yGnLSWI= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB7FB3858D35 Date: Wed, 15 Feb 2023 09:43:10 +0000 To: "cygwin AT cygwin DOT com" , "cygwin-developers AT cygwin DOT com" Subject: Re: Why do these mprotect always fail? Message-ID: In-Reply-To: References: Feedback-ID: 67221101:user:proton MIME-Version: 1.0 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 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: w6b7rk5yu4mt25v3 via Cygwin Reply-To: w6b7rk5yu4mt25v3 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" 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 compilation 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: > > unsigned char* buffer; > int32_t available, size; > > if(size > PAGE_SIZE) { > > factor = size / PAGE_SIZE + 1; > } > available = factor * PAGE_SIZE; > > 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); > } > > mprotect 2: > > if(posix_memalign((void**)& buffer, PAGE_SIZE, PAGE_SIZE)) { > std::wcerr << L"Unable to allocate JIT memory!" << std::endl; > exit(1); > } > > if(mprotect(buffer, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { > std::wcerr << L"Unable to mprotect" << std::endl; > exit(1); > } > > > Sent with Proton Mail secure email. -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple