#include <stdlib.h>
#include <errno.h>
#include <libproc.h>
#include <sys/sysmacros.h>
#include <sys/mman.h>
#include <sys/debug.h>
int
main(void)
{
pstatus_t status;
void *sentinel = (void *)0xbad00000;
void *buf = sentinel;
int err = 0;
err = posix_memalign(&buf, sizeof (void *) - 1, 16);
VERIFY3S(err, ==, EINVAL);
VERIFY3P(buf, ==, sentinel);
err = posix_memalign(&buf, sizeof (void *) + 1, 16);
VERIFY3S(err, ==, EINVAL);
VERIFY3P(buf, ==, sentinel);
err = posix_memalign(&buf, 23, 16);
VERIFY3S(err, ==, EINVAL);
VERIFY3P(buf, ==, sentinel);
err = posix_memalign(&buf, sizeof (void *), 16);
VERIFY3S(err, ==, 0);
VERIFY3B(IS_P2ALIGNED(buf, sizeof (void *)), ==, B_TRUE);
VERIFY3P(buf, !=, sentinel);
VERIFY3P(buf, !=, NULL);
free(buf);
buf = sentinel;
VERIFY0(proc_get_status(getpid(), &status));
VERIFY3P(mmap((caddr_t)P2ROUNDUP(status.pr_brkbase +
status.pr_brksize, 0x1000), 0x1000,
PROT_READ, MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0),
!=, (void *)-1);
for (;;) {
if (malloc(16) == NULL)
break;
}
for (;;) {
if (posix_memalign(&buf, sizeof (void *), 16) == ENOMEM)
break;
}
buf = sentinel;
err = posix_memalign(&buf, sizeof (void *), 16);
VERIFY3S(err, ==, ENOMEM);
VERIFY3P(buf, ==, sentinel);
return (0);
}