create_module.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Syscalls for uClibc
  4. *
  5. * Copyright (C) 2000 by Lineo, inc. Written by Erik Andersen
  6. * <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Library General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <errno.h>
  24. #include <features.h>
  25. #include <sys/types.h>
  26. #include <sys/syscall.h>
  27. //#define __NR_create_module 127
  28. #if defined(__i386__) || defined(__m68k__) || defined(__arm__)
  29. #define __NR___create_module __NR_create_module
  30. #ifdef __STR_NR_create_module
  31. #define __STR_NR___create_module __STR_NR_create_module
  32. #endif
  33. _syscall2(long, __create_module, const char *, name, size_t, size);
  34. /* By checking the value of errno, we know if we have been fooled
  35. * by the syscall2 macro making a very high address look like a
  36. * negaitive, so we we fix it up here. */
  37. unsigned long create_module(const char *name, size_t size)
  38. {
  39. long ret = __create_module(name, size);
  40. /* Jump through hoops to fixup error return codes */
  41. if (ret == -1 && errno > 125) {
  42. ret = -errno;
  43. __set_errno(0);
  44. }
  45. return ret;
  46. }
  47. #elif defined(__alpha__)
  48. #define __NR___create_module __NR_create_module
  49. /* Alpha doesn't have the same problem, exactly, but a bug in older
  50. kernels fails to clear the error flag. Clear it here explicitly. */
  51. _syscall4(unsigned long, __create_module, const char *, name,
  52. size_t, size, size_t, dummy, size_t, err);
  53. unsigned long create_module(const char *name, size_t size)
  54. {
  55. return __create_module(name, size, 0, 0);
  56. }
  57. #else
  58. /* Sparc, MIPS, etc don't mistake return values for errors. */
  59. _syscall2(unsigned long, create_module, const char *, name, size_t, size)
  60. #endif