File: arm-cmse.c

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-16
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,368 kB
  • sloc: cpp: 5,593,980; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (57 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download | duplicates (8)
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
55
56
57
// RUN: %clang_cc1 -triple thumbv8m.base-none-eabi -mcmse -verify %s

typedef void (*callback_ns_1t)() __attribute__((cmse_nonsecure_call));
typedef void (*callback_1t)();
typedef void (*callback_ns_2t)() __attribute__((cmse_nonsecure_call));
typedef void (*callback_2t)();

void foo(callback_ns_1t nsfptr, // expected-error{{functions may not be declared with 'cmse_nonsecure_call' attribute}}
         callback_1t fptr) __attribute__((cmse_nonsecure_call))
{
  callback_1t fp1 = nsfptr; // expected-warning{{incompatible function pointer types initializing 'callback_1t'}}
  callback_ns_1t fp2 = fptr; // expected-warning{{incompatible function pointer types initializing 'callback_ns_1t'}}
  callback_2t fp3 = fptr;
  callback_ns_2t fp4 = nsfptr;
}

static void bar() __attribute__((cmse_nonsecure_entry)) // expected-warning{{'cmse_nonsecure_entry' cannot be applied to functions with internal linkage}}
{
}

typedef void nonsecure_fn_t(int) __attribute__((cmse_nonsecure_call));
extern nonsecure_fn_t baz; // expected-error{{functions may not be declared with 'cmse_nonsecure_call' attribute}}

int v0 __attribute__((cmse_nonsecure_call)); // expected-warning {{'cmse_nonsecure_call' only applies to function types; type here is 'int'}}
int v1 __attribute__((cmse_nonsecure_entry)); // expected-warning {{'cmse_nonsecure_entry' attribute only applies to functions}}

void fn0() __attribute__((cmse_nonsecure_entry));
void fn1() __attribute__((cmse_nonsecure_entry(1)));  // expected-error {{'cmse_nonsecure_entry' attribute takes no arguments}}

typedef void (*fn2_t)() __attribute__((cmse_nonsecure_call("abc"))); // expected-error {{'cmse_nonsecure_call' attribute takes no argument}}

union U { unsigned n; char b[4]; } u;

union U xyzzy() __attribute__((cmse_nonsecure_entry)) {
  return u; // expected-warning {{passing union across security boundary via return value may leak information}}
}

void (*fn2)(int, union U) __attribute__((cmse_nonsecure_call));
void (*fn3)() __attribute__ ((cmse_nonsecure_call));

struct S {
  int t;
  union {
    char b[4];
    unsigned w;
  };
} s;

void qux() {
  fn2(1,
      u); // expected-warning {{passing union across security boundary via parameter 1 may leak information}}

  fn3(
       u, // expected-warning {{passing union across security boundary via parameter 0 may leak information}}
       1,
       s); // expected-warning {{passing union across security boundary via parameter 2 may leak information}}
}