create_module.c 2.3 KB

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