module.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* include/kernel/module.h
  2. *
  3. * Copyright (C) 2021, 2022 intirain.
  4. *
  5. * This file is part of evx.
  6. *
  7. * evx is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * evx is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with evx. If not, see <https://www.gnu.org/licenses/>
  19. */
  20. #ifndef __MODULE_H
  21. #define __MODULE_H
  22. #ifndef __ASSEMBLER__
  23. #include <sys/types.h>
  24. struct modfuncs {
  25. /* point to blk/chr/net operations */
  26. void *ops;
  27. struct modfuncs *next;
  28. };
  29. struct kmodule {
  30. char *mod_name;
  31. /* this module compiled inside kernel */
  32. #define MODTYPE_KINSIDE 0x0001
  33. #define MODTYPE_GPL 0x0002
  34. #define MODTYPE_BLKDRV 0x0004
  35. #define MODTYPE_CHRDRV 0x0008
  36. #define MODTYPE_NETDRV 0x0010
  37. #define MODTYPE_KPATCH 0x0020
  38. #define MODTYPE_FS 0x0040
  39. /* there is a panic (or oops) caused by this module */
  40. #define MODTYPE_CAUSED_PANIC 0x0080
  41. __uint16_t mod_type;
  42. /* reference count of this module. */
  43. __uint32_t mod_refer;
  44. struct modfuncs *mod_funcs;
  45. /* the uid of the installer of this module */
  46. __uid_t installer_uid;
  47. };
  48. #define module_init(fn) \
  49. void *__initcall_##fn __attribute__ ((__section__ (".initcalls.modules"))) = fn; \
  50. #endif
  51. #endif