test/ffi_test/ktap_ffi_test.c - ktap

Global variables defined

Data types defined

Functions defined

Source code

  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/sched.h>

  5. void ffi_test_void(void)
  6. {
  7. }
  8. EXPORT_SYMBOL(ffi_test_void);

  9. int ffi_test_int1(unsigned char a, char b, unsigned short c, short d)
  10. {
  11.     return a + b + c + d;
  12. }
  13. EXPORT_SYMBOL(ffi_test_int1);

  14. long long ffi_test_int2(unsigned int a, int b, unsigned long c, long d,
  15.         unsigned long long e, long long f, long long g)
  16. {
  17.     return a + b + c + d + e + f + g;
  18. }
  19. EXPORT_SYMBOL(ffi_test_int2);

  20. void *ffi_test_pointer1(char *a) {
  21.     return a;
  22. }
  23. EXPORT_SYMBOL(ffi_test_pointer1);

  24. long long ffi_test_var_arg(int n, ...) {
  25.     va_list ap;
  26.     int i;
  27.     long long sum = 0;
  28.     va_start(ap, n);
  29.     for (i = 0; i < n; i++) {
  30.         sum += va_arg(ap, long long);
  31.     }
  32.     va_end(ap);
  33.     return sum;
  34. }
  35. EXPORT_SYMBOL(ffi_test_var_arg);

  36. unsigned long long ffi_test_sched_clock(void)
  37. {
  38.     return sched_clock();
  39. }
  40. EXPORT_SYMBOL(ffi_test_sched_clock);

  41. int ffi_test_array(int *arr, int idx)
  42. {
  43.     return arr[idx];
  44. }
  45. EXPORT_SYMBOL(ffi_test_array);

  46. struct ffi_struct {
  47.     int val;
  48. };

  49. int ffi_test_struct(struct ffi_struct *s)
  50. {
  51.     return s->val;
  52. }
  53. EXPORT_SYMBOL(ffi_test_struct);

  54. struct ffi_struct_loop {
  55.     int val;
  56.     struct ffi_struct_loop *next;
  57. };

  58. int ffi_test_struct_loop(struct ffi_struct_loop *s)
  59. {
  60.     if (s == s->next)
  61.         return s->val;
  62.     return 0;
  63. }
  64. EXPORT_SYMBOL(ffi_test_struct_loop);

  65. union ffi_union {
  66.     int val;
  67.     int val2;
  68.     int val3;
  69. };

  70. int ffi_test_union(union ffi_union *s)
  71. {
  72.     return s->val;
  73. }
  74. EXPORT_SYMBOL(ffi_test_union);

  75. struct ffi_struct_array {
  76.     int val[20];
  77. };

  78. int ffi_test_struct_array(struct ffi_struct_array *s)
  79. {
  80.     int sum = 0, i;
  81.     for (i = 0; i < 20; i++)
  82.         sum += s->val[i];
  83.     return sum;
  84. }
  85. EXPORT_SYMBOL(ffi_test_struct_array);

  86. struct ffi_struct_noname {
  87.     struct {
  88.         int pad;
  89.         int val;
  90.     };
  91. };

  92. int ffi_test_struct_noname(struct ffi_struct_noname *s)
  93. {
  94.     return s->val;
  95. }
  96. EXPORT_SYMBOL(ffi_test_struct_noname);


  97. static int __init ffi_test_init(void)
  98. {
  99.     return 0;
  100. }

  101. static void __exit ffi_test_exit(void)
  102. {
  103. }


  104. MODULE_DESCRIPTION("ktap ffi test module");
  105. MODULE_LICENSE("GPL");

  106. module_init(ffi_test_init);
  107. module_exit(ffi_test_exit);