| 1878 | } |
| 1879 | |
| 1880 | int |
| 1881 | kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, |
| 1882 | id_t id, size_t cpusetsize, cpuset_t *maskp) |
| 1883 | { |
| 1884 | struct thread *ttd; |
| 1885 | struct cpuset *nset; |
| 1886 | struct cpuset *set; |
| 1887 | struct proc *p; |
| 1888 | cpuset_t *mask; |
| 1889 | int error; |
| 1890 | size_t size; |
| 1891 | |
| 1892 | if (cpusetsize < sizeof(cpuset_t) || cpusetsize > CPU_MAXSIZE / NBBY) |
| 1893 | return (ERANGE); |
| 1894 | error = cpuset_check_capabilities(td, level, which, id); |
| 1895 | if (error != 0) |
| 1896 | return (error); |
| 1897 | size = cpusetsize; |
| 1898 | mask = malloc(size, M_TEMP, M_WAITOK | M_ZERO); |
| 1899 | error = cpuset_which(which, id, &p, &ttd, &set); |
| 1900 | if (error) |
| 1901 | goto out; |
| 1902 | switch (level) { |
| 1903 | case CPU_LEVEL_ROOT: |
| 1904 | case CPU_LEVEL_CPUSET: |
| 1905 | switch (which) { |
| 1906 | case CPU_WHICH_TID: |
| 1907 | case CPU_WHICH_PID: |
| 1908 | thread_lock(ttd); |
| 1909 | set = cpuset_ref(ttd->td_cpuset); |
| 1910 | thread_unlock(ttd); |
| 1911 | break; |
| 1912 | case CPU_WHICH_CPUSET: |
| 1913 | case CPU_WHICH_JAIL: |
| 1914 | break; |
| 1915 | case CPU_WHICH_IRQ: |
| 1916 | case CPU_WHICH_INTRHANDLER: |
| 1917 | case CPU_WHICH_ITHREAD: |
| 1918 | case CPU_WHICH_DOMAIN: |
| 1919 | error = EINVAL; |
| 1920 | goto out; |
| 1921 | } |
| 1922 | if (level == CPU_LEVEL_ROOT) |
| 1923 | nset = cpuset_refroot(set); |
| 1924 | else |
| 1925 | nset = cpuset_refbase(set); |
| 1926 | CPU_COPY(&nset->cs_mask, mask); |
| 1927 | cpuset_rel(nset); |
| 1928 | break; |
| 1929 | case CPU_LEVEL_WHICH: |
| 1930 | switch (which) { |
| 1931 | case CPU_WHICH_TID: |
| 1932 | thread_lock(ttd); |
| 1933 | CPU_COPY(&ttd->td_cpuset->cs_mask, mask); |
| 1934 | thread_unlock(ttd); |
| 1935 | break; |
| 1936 | case CPU_WHICH_PID: |
| 1937 | FOREACH_THREAD_IN_PROC(p, ttd) { |
no test coverage detected