Commit 029a45b8 authored by David Gibson's avatar David Gibson Committed by Dan Good

altstack: Use ptrint instead of bare casts

Functions invoked with altstack take a void * parameter.  However, the
test program wants to pass an integer, and so uses the trick of casting
the integer values to (void *) and back again.

The ptrint() module handles exactly this case in a more portable and
(somewhat) typesafe way, so use that instead.
Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent 15c555b3
......@@ -122,6 +122,11 @@ int main(int argc, char *argv[])
if (strcmp(argv[1], "depends") == 0)
return 0;
if (strcmp(argv[1], "testdepends") == 0) {
printf("ccan/ptrint\n");
return 0;
}
if (strcmp(argv[1], "ported") == 0) {
#ifdef __x86_64__
printf("\n");
......
......@@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <ccan/tap/tap.h>
#include <ccan/ptrint/ptrint.h>
#include <ccan/altstack/altstack.h>
#include <stdio.h>
......@@ -53,7 +54,7 @@ static void __attribute__((optimize("O0"))) dn(unsigned long i)
}
static void *wrap(void *i)
{
dn((unsigned long) i);
dn(ptr2int(i));
return wrap;
}
......@@ -86,43 +87,43 @@ int main(void)
plan_tests(50);
chkfail(getrlimit_, altstack(8*MiB, wrap, 0, 0) == -1, e(getrlimit_),
chkfail(getrlimit_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(getrlimit_),
0,
0);
chkfail(setrlimit_, altstack(8*MiB, wrap, 0, 0) == -1, e(setrlimit_),
chkfail(setrlimit_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(setrlimit_),
getrlimit_,
0);
chkfail(mmap_, altstack(8*MiB, wrap, 0, 0) == -1, e(mmap_),
chkfail(mmap_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(mmap_),
getrlimit_|setrlimit_,
setrlimit_);
chkfail(sigaltstack_, altstack(8*MiB, wrap, 0, 0) == -1, e(sigaltstack_),
chkfail(sigaltstack_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaltstack_),
getrlimit_|setrlimit_|mmap_,
setrlimit_|munmap_);
chkfail(sigaction_, altstack(8*MiB, wrap, 0, 0) == -1, e(sigaction_),
chkfail(sigaction_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaction_),
getrlimit_|setrlimit_|mmap_|sigaltstack_,
setrlimit_|munmap_|sigaltstack_);
chkfail(munmap_, altstack(8*MiB, wrap, 0, 0) == 1, e(munmap_),
chkfail(munmap_, altstack(8*MiB, wrap, int2ptr(0), 0) == 1, e(munmap_),
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1)
err(1, "munmap");
chkok( altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
chkok( altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
// be sure segv catch is repeatable (SA_NODEFER)
chkok( altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
chkok( altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
used = 1;
chkfail(munmap_, altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
chkfail(munmap_, altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1)
......@@ -149,7 +150,7 @@ int main(void)
ok1(strcmp(buf, estr "\n") == 0);
used = 1;
chkok( altstack(8*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
chkok( altstack(8*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
......@@ -157,7 +158,7 @@ int main(void)
ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz);
used = 0;
chkok( altstack(8*MiB, wrap, (void *) 100000, 0) == 0, 0,
chkok( altstack(8*MiB, wrap, int2ptr(100000), 0) == 0, 0,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_|munmap_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment