/linux-abi/branches/IBCS3/svr4/sysconf.c

https://github.com/cpc26/abi_linux · C · 189 lines · 112 code · 35 blank · 42 comment · 2 complexity · 37be7cf81082921e2dc0cbe73e42a421 MD5 · raw file

  1. /*
  2. * sysconf.c - sysv sysconf(2) and sysconfig(2) emulation
  3. *
  4. * Copyright (C) 1994 Mike Jagdis (jaggy@purplet.demon.co.uk)
  5. */
  6. //#ident "%W% %G%"
  7. #include "../include/util/i386_std.h"
  8. #include <linux/module.h>
  9. #include <linux/errno.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/stddef.h>
  14. #include <linux/limits.h>
  15. #ifndef CHILD_MAX
  16. #define CHILD_MAX 999
  17. #endif
  18. #ifndef OPEN_MAX
  19. #define OPEN_MAX 256
  20. #endif
  21. //#include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/fcntl.h>
  24. #include <linux/smp.h>
  25. #include <linux/swap.h>
  26. #include <linux/fs.h>
  27. #include <linux/sys.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/system.h>
  30. #include "../include/svr4/sysconf.h"
  31. #include "../include/util/trace.h"
  32. /* The sysconf() call is supposed to give applications access to various
  33. * kernel parameters. According to SCO's man page this a POSIX mandated
  34. * function. Perhaps it should be moved across as a native Linux call?
  35. *
  36. * N.B. SCO only has sysconf in the Xenix group. Therefore this is based
  37. * on the Xenix spec. Is SVR4 the same? Wyse Unix V.3.2.1A doesn't have
  38. * sysconf documented at all.
  39. *
  40. * N.B. 0-7 are required (by who?). Other values may be defined for
  41. * various systems but there appears no guarantee that they match across
  42. * platforms. Thus, unless we can identify what system the executable
  43. * was compiled for, we probably prefer to have extensions fail. Hell,
  44. * nothing important is going to use this obscure stuff anyway...
  45. */
  46. #define _SC_ARG_MAX 0
  47. #define _SC_CHILD_MAX 1
  48. #define _SC_CLK_TCK 2
  49. #define _SC_NGROUPS_MAX 3
  50. #define _SC_OPEN_MAX 4
  51. #define _SC_JOB_CONTROL 5
  52. #define _SC_SAVED_IDS 6
  53. #define _SC_VERSION 7
  54. #define _SC_PAGESIZE 11
  55. #define _SCO_SC_PAGESIZE 34
  56. /* This is an SVR4 system call that is undocumented except for some
  57. * hints in a header file. It appears to be a forerunner to the
  58. * POSIX sysconf() call.
  59. */
  60. int svr4_sysconfig(int name)
  61. {
  62. switch (name) {
  63. case _CONFIG_NGROUPS:
  64. /* From limits.h */
  65. return (NGROUPS_MAX);
  66. case _CONFIG_CHILD_MAX:
  67. /* From limits.h */
  68. return (CHILD_MAX);
  69. case _CONFIG_OPEN_FILES:
  70. /* From limits.h */
  71. return (OPEN_MAX);
  72. case _CONFIG_POSIX_VER:
  73. /* The version of the POSIX standard we conform
  74. * to. SCO defines _POSIX_VERSION as 198808L
  75. * sys/unistd.h. What are we? We are 199009L.
  76. */
  77. return (199009L);
  78. case _CONFIG_PAGESIZE:
  79. return (PAGE_SIZE);
  80. case _CONFIG_CLK_TCK:
  81. return (HZ);
  82. case _CONFIG_XOPEN_VER:
  83. return 4;
  84. case _CONFIG_NACLS_MAX:
  85. return 0;
  86. case _CONFIG_NPROC:
  87. return 4000; /* max_threads */
  88. case _CONFIG_NENGINE:
  89. case _CONFIG_NENGINE_ONLN:
  90. return (num_online_cpus());
  91. case _CONFIG_TOTAL_MEMORY:
  92. case _CONFIG_USEABLE_MEMORY:
  93. case _CONFIG_GENERAL_MEMORY:
  94. #ifdef max_mapnr
  95. return (max_mapnr << (PAGE_SHIFT-10));
  96. #endif
  97. case _CONFIG_DEDICATED_MEMORY:
  98. return 0;
  99. case _CONFIG_NCGS_CONF:
  100. case _CONFIG_NCGS_ONLN:
  101. case _CONFIG_MAX_ENG_PER_CG:
  102. return 1; /* no NUMA-Q support on Linux yet */
  103. /* well, there is. we lie anyway --hch */
  104. case _CONFIG_CACHE_LINE:
  105. return 32; /* XXX is there a more accurate way? */
  106. case _CONFIG_KERNEL_VM:
  107. return -EINVAL;
  108. case _CONFIG_ARG_MAX:
  109. /* From limits.h */
  110. return (ARG_MAX);
  111. }
  112. #if defined(CONFIG_ABI_TRACE)
  113. abi_trace(ABI_TRACE_API, "unsupported sysconfig call %d\n", name);
  114. #endif
  115. return -EINVAL;
  116. }
  117. int ibcs_sysconf(int name)
  118. {
  119. switch (name) {
  120. case _SC_ARG_MAX:
  121. /* From limits.h */
  122. return (ARG_MAX);
  123. case _SC_CHILD_MAX:
  124. /* From limits.h */
  125. return (CHILD_MAX);
  126. case _SC_CLK_TCK:
  127. return (HZ);
  128. case _SC_NGROUPS_MAX:
  129. /* From limits.h */
  130. return (NGROUPS_MAX);
  131. case _SC_OPEN_MAX:
  132. /* From limits.h */
  133. return (OPEN_MAX);
  134. case _SC_JOB_CONTROL:
  135. return (1);
  136. case _SC_SAVED_IDS:
  137. return (1);
  138. case _SC_PAGESIZE:
  139. case _SCO_SC_PAGESIZE:
  140. return PAGE_SIZE;
  141. case _SC_VERSION:
  142. /* The version of the POSIX standard we conform
  143. * to. SCO defines _POSIX_VERSION as 198808L
  144. * sys/unistd.h. What are we?
  145. */
  146. return (198808L);
  147. }
  148. #if defined(CONFIG_ABI_TRACE)
  149. abi_trace(ABI_TRACE_API, "unsupported sysconf call %d\n", name);
  150. #endif
  151. return -EINVAL;
  152. }
  153. EXPORT_SYMBOL(ibcs_sysconf);
  154. EXPORT_SYMBOL(svr4_sysconfig);