Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cheribsdtest: Add tests in anticipation of c18n where function pointers are wrapped by default #2299

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bin/cheribsdtest/cheribsdtest_fptr_canon.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* SUCH DAMAGE.
*/

#include <sys/types.h>

#include <dlfcn.h>

#include <cheribsdtest_dynamic.h>
Expand Down Expand Up @@ -82,3 +84,21 @@ CHERIBSDTEST(fptr_canon_dlfunc,

cheribsdtest_success();
}

CHERIBSDTEST(fptr_canon_int,
"Check that function pointers are canonical when relocated as integer "
"addresses")
{
volatile ptraddr_t fptr_int;
void (* volatile fptr_dlsym)(void);

fptr_int = cheribsdtest_dynamic_get_dummy_fptr_addr();
fptr_dlsym = (void (*)(void))dlsym(RTLD_DEFAULT,
"cheribsdtest_dynamic_dummy_func");

CHERIBSDTEST_VERIFY2(fptr_int == (ptraddr_t)fptr_dlsym,
"Integer address %#p differs from dlsym %#p",
(void *)(uintptr_t)fptr_int, fptr_dlsym);

cheribsdtest_success();
}
2 changes: 2 additions & 0 deletions bin/cheribsdtest/cheribsdtest_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ CHERIBSDTEST(signal_returncap,
CHERIBSDTEST_VERIFY2(v == CHERI_CAP_USER_CODE_LENGTH,
"length 0x%jx (expected <= 0x%jx)", v,
(uintmax_t)CHERI_CAP_USER_CODE_LENGTH);
#elif defined(CHERIBSD_C18N_TESTS)
CHERIBSDTEST_VERIFY2(v <= 0x300, "length 0x%jx (expected <= 0x300)", v);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, rather the PR’s title is a bit misleading.

#else
CHERIBSDTEST_VERIFY2(v <= 0x100, "length 0x%jx (expected <= 0x100)", v);
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/libcheribsdtest_dynamic/cheribsdtest_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

void cheribsdtest_dynamic_dummy_func(void);
void (*cheribsdtest_dynamic_get_dummy_fptr(void))(void);
ptraddr_t cheribsdtest_dynamic_get_dummy_fptr_addr(void);

void * __capability cheribsdtest_dynamic_identity_cap(void * __capability cap);

Expand Down
8 changes: 8 additions & 0 deletions lib/libcheribsdtest_dynamic/cheribsdtest_dynamic_fptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@
{
return (&cheribsdtest_dynamic_dummy_func);
}

ptraddr_t
cheribsdtest_dynamic_get_dummy_fptr_addr(void)
{
static volatile ptraddr_t addr =
(ptraddr_t)&cheribsdtest_dynamic_dummy_func;
return (addr);
}

Check warning on line 54 in lib/libcheribsdtest_dynamic/cheribsdtest_dynamic_fptr.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line