Skip to content

Fix handling of pvalloc(0)#363

Merged
thestinger merged 1 commit into
GrapheneOS:mainfrom
rdevshp:pvalloc_0
Jul 7, 2026
Merged

Fix handling of pvalloc(0)#363
thestinger merged 1 commit into
GrapheneOS:mainfrom
rdevshp:pvalloc_0

Conversation

@rdevshp

@rdevshp rdevshp commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

pvalloc(0) currently returns NULL and sets errno = ENOMEM. This PR fixes handling of pvalloc(0).

@thestinger

Copy link
Copy Markdown
Member

This is an overly complicated way of doing this.

@rdevshp

rdevshp commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

This is an overly complicated way of doing this.

I have switched to checking if the size is zero at the beginning of pvalloc instead.

@thestinger

Copy link
Copy Markdown
Member

Have you verified this is what glibc malloc does?

@rdevshp

rdevshp commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Have you verified this is what glibc malloc does?

I have checked that with glibc's pvalloc, the program

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

int main(void) {
    errno = 0;
    void *p = pvalloc(0);
    int saved_errno = errno;
    printf("p=%p errno=%d\n", p, saved_errno);
    free(p);
    return 0;
}

prints a non-null p with errno=0.

@thestinger thestinger merged commit eb475dd into GrapheneOS:main Jul 7, 2026
12 checks passed
@thestinger

Copy link
Copy Markdown
Member

@rdevshp Is it page-aligned though?

@rdevshp

rdevshp commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@rdevshp Is it page-aligned though?

Yes, the pointer that I got from glibc's pvalloc is page-aligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants