create_module.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. _syscall2(long, __create_module, const char *, name, size_t, size);
  31. /* By checking the value of errno, we know if we have been fooled
  32. * by the syscall2 macro making a very high address look like a
  33. * negaitive, so we we fix it up here. */
  34. unsigned long create_module(const char *name, size_t size)
  35. {
  36. long ret = __create_module(name, size);
  37. /* Jump through hoops to fixup error return codes */
  38. if (ret == -1 && errno > 125) {
  39. ret = -errno;
  40. __set_errno(0);
  41. }
  42. return ret;
  43. }
  44. #elif defined(__alpha__)
  45. #define __NR___create_module __NR_create_module
  46. /* Alpha doesn't have the same problem, exactly, but a bug in older
  47. kernels fails to clear the error flag. Clear it here explicitly. */
  48. _syscall4(unsigned long, __create_module, const char *, name,
  49. size_t, size, size_t, dummy, size_t, err);
  50. unsigned long create_module(const char *name, size_t size)
  51. {
  52. return __create_module(name, size, 0, 0);
  53. }
  54. #else
  55. /* Sparc, MIPS, etc don't mistake return values for errors. */
  56. _syscall2(unsigned long, create_module, const char *, name, size_t, size)
  57. #endif