create_module.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * create_module syscall for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <features.h>
  10. #define __need_size_t
  11. #include <stddef.h>
  12. #include <errno.h>
  13. #include <sys/syscall.h>
  14. #ifdef __NR_create_module
  15. unsigned long create_module(const char *name, size_t size);
  16. #if defined(__UCLIBC_BROKEN_CREATE_MODULE__)
  17. # define __NR___create_module __NR_create_module
  18. static __inline__ _syscall2(long, __create_module, const char *, name, size_t, size)
  19. /* By checking the value of errno, we know if we have been fooled
  20. * by the syscall2 macro making a very high address look like a
  21. * negative, so we fix it up here. */
  22. unsigned long create_module(const char *name, size_t size)
  23. {
  24. long ret = __create_module(name, size);
  25. /* Jump through hoops to fixup error return codes */
  26. if (ret == -1 && errno > 125) {
  27. ret = -errno;
  28. __set_errno(0);
  29. }
  30. return ret;
  31. }
  32. #elif defined(__UCLIBC_SLIGHTLY_BROKEN_CREATE_MODULE__)
  33. # define __NR___create_module __NR_create_module
  34. /* Alpha doesn't have the same problem, exactly, but a bug in older
  35. kernels fails to clear the error flag. Clear it here explicitly. */
  36. static __inline__ _syscall4(unsigned long, __create_module, const char *, name,
  37. size_t, size, size_t, dummy, size_t, err)
  38. unsigned long create_module(const char *name, size_t size)
  39. {
  40. return __create_module(name, size, 0, 0);
  41. }
  42. #else
  43. /* Sparc, MIPS, etc don't mistake return values for errors. */
  44. _syscall2(unsigned long, create_module, const char *, name, size_t, size)
  45. #endif
  46. #endif