create_module.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* vi: set sw=4 ts=4: */
  2. /* Syscalls for uClibc
  3. *
  4. * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
  5. * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
  6. * Written by Erik Andersen <andersen@uclibc.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. #include <errno.h>
  23. #include <unistd.h>
  24. #include <features.h>
  25. #include <sys/types.h>
  26. #include <sys/syscall.h>
  27. //#define __NR_create_module 127
  28. #ifdef __NR_create_module
  29. #if defined(__i386__) || defined(__m68k__) || defined(__arm__) || defined(__cris__) || defined(__i960__)
  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
  62. #else
  63. unsigned long create_module(const char *name, size_t size)
  64. {
  65. __set_errno(ENOSYS);
  66. return (unsigned long)-1;
  67. }
  68. #endif