Hash :
bb1a84ed
Author :
Date :
2025-03-30T12:07:59
Add the "ABI_ATTR" attribute to called functions (#891) (#892)
I accidentally omitted the "ABI_ATTR" attribute, so that the testsuite
fails when testing the Microsoft ABI.
Fixes: fe203ffbb2bd ("Fix bugs in the x86-64 and x32 target (#887) (#889)")
Signed-off-by: Mikulas Patocka <mikulas@twibright.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/* Area: ffi_call
Purpose: Tests if ffi_call reads data beyond end.
Limitations: needs mmap.
PR: 887
Originator: Mikulas Patocka <mikulas@twibright.com> */
/* { dg-do run } */
#include "ffitest.h"
#ifdef __linux__
#include <sys/mman.h>
#include <unistd.h>
static int ABI_ATTR fn(unsigned char a, unsigned short b, unsigned int c, unsigned long d)
{
return (int)(a + b + c + d);
}
#endif
int main(void)
{
#ifdef __linux__
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
char *m;
int ps;
args[0] = &ffi_type_uchar;
args[1] = &ffi_type_ushort;
args[2] = &ffi_type_uint;
args[3] = &ffi_type_ulong;
CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, &ffi_type_sint, args) == FFI_OK);
ps = getpagesize();
m = mmap(NULL, ps * 3, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
CHECK(m != MAP_FAILED);
CHECK(mprotect(m, ps, PROT_NONE) == 0);
CHECK(mprotect(m + ps * 2, ps, PROT_NONE) == 0);
values[0] = m + ps * 2 - sizeof(unsigned char);
values[1] = m + ps * 2 - sizeof(unsigned short);
values[2] = m + ps * 2 - sizeof(unsigned int);
values[3] = m + ps * 2 - sizeof(unsigned long);
ffi_call(&cif, FFI_FN(fn), &rint, values);
CHECK((int)rint == 0);
values[0] = m + ps;
values[1] = m + ps;
values[2] = m + ps;
values[3] = m + ps;
ffi_call(&cif, FFI_FN(fn), &rint, values);
CHECK((int)rint == 0);
#endif
exit(0);
}