sched_getaffinity.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <sched.h>
  16. #include <string.h>
  17. #include <sysdep.h>
  18. #include <sys/param.h>
  19. #include <sys/types.h>
  20. #include <shlib-compat.h>
  21. #ifdef __NR_sched_getaffinity
  22. # if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
  23. extern int __sched_getaffinity_new (pid_t, size_t, cpu_set_t *);
  24. libc_hidden_proto (__sched_getaffinity_new)
  25. # endif
  26. int
  27. __sched_getaffinity_new (pid_t pid, size_t cpusetsize, cpu_set_t *cpuset)
  28. {
  29. int res = INLINE_SYSCALL (sched_getaffinity, 3, pid,
  30. MIN (INT_MAX, cpusetsize), cpuset);
  31. if (res != -1)
  32. {
  33. /* Clean the rest of the memory the kernel didn't do. */
  34. memset ((char *) cpuset + res, '\0', cpusetsize - res);
  35. res = 0;
  36. }
  37. return res;
  38. }
  39. versioned_symbol (libc, __sched_getaffinity_new, sched_getaffinity,
  40. GLIBC_2_3_4);
  41. # if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
  42. libc_hidden_def (__sched_getaffinity_new)
  43. int
  44. attribute_compat_text_section
  45. __sched_getaffinity_old (pid_t pid, cpu_set_t *cpuset)
  46. {
  47. /* The old interface by default assumed a 1024 processor bitmap. */
  48. return __sched_getaffinity_new (pid, 128, cpuset);
  49. }
  50. compat_symbol (libc, __sched_getaffinity_old, sched_getaffinity, GLIBC_2_3_3);
  51. # endif
  52. #else
  53. # include <posix/sched_getaffinity.c>
  54. #endif