delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2017/12/29/07:40:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
X-Virus-Scanned: Debian amavisd-new at medvecky.net
X-Spam-Flag: NO
X-Spam-Score: -2.823
X-Spam-Level:
X-Spam-Status: No, score=-2.823 tagged_above=-999 required=3.8
tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, TW_CR=0.077] autolearn=ham
To: djgpp AT delorie DOT com
From: "Rudolf Marek (r DOT marek AT assembler DOT cz) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
Subject: valloc() returns NULL for larger requests, but malloc works fine
Message-ID: <3459b672-8f4d-9840-5a01-246db011ed06@assembler.cz>
Date: Fri, 29 Dec 2017 13:39:22 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.5.0
MIME-Version: 1.0
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id vBTCe3wb032496
Reply-To: djgpp AT delorie DOT com

Hi,

I was testing the flashrom DOS port before new release, and it turns out
there is something wrong with the valloc(). It refuses to allocate larger
areas, but malloc with same size works fine. The very same code was working fine with the 2.04 from 2009.

I performed my experiment with following rpms installed:

djcross-binutils-2.29.1-1ap.x86_64.rpm 
djcross-gcc-7.2.0-1ap.x86_64.rpm 
djcrx-2.05-5.x86_64.rpm

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

int main(void)
{
	printf("VALLOC %lx\n", valloc(1024*1024)); /* Fails with 0 */
	printf("MALLOC %lx\n", malloc(1024)); /* Works fine */ 
	printf("MALLOC %lx\n", malloc(1024*1024)); /* Works fine */
	printf("VALLOC %lx\n", valloc(1024)); /* Fails with 0 */
	printf("MEMALIGN %lx\n", memalign(4096, 1024)); /* Fails with 0 */
	printf("MEMALIGN %lx\n", memalign(64, 1024)); /* Fails with 0 */
	printf("MEMALIGN %lx\n", memalign(32, 64)); /* Works fine */
}

I suspect something went wrong with memalign() internally, as for larger allocations it does some advanced trickery.

Thanks
Rudolf

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019