| 1896 | #endif |
| 1897 | |
| 1898 | static int |
| 1899 | get_proc_vector(struct thread *td, struct proc *p, char ***proc_vectorp, |
| 1900 | size_t *vsizep, enum proc_vector_type type) |
| 1901 | { |
| 1902 | struct ps_strings pss; |
| 1903 | Elf_Auxinfo aux; |
| 1904 | vm_offset_t vptr, ptr; |
| 1905 | char **proc_vector; |
| 1906 | size_t vsize, size; |
| 1907 | int i; |
| 1908 | |
| 1909 | #ifdef COMPAT_FREEBSD32 |
| 1910 | if (SV_PROC_FLAG(p, SV_ILP32) != 0) |
| 1911 | return (get_proc_vector32(td, p, proc_vectorp, vsizep, type)); |
| 1912 | #endif |
| 1913 | if (proc_readmem(td, p, (vm_offset_t)p->p_sysent->sv_psstrings, &pss, |
| 1914 | sizeof(pss)) != sizeof(pss)) |
| 1915 | return (ENOMEM); |
| 1916 | switch (type) { |
| 1917 | case PROC_ARG: |
| 1918 | vptr = (vm_offset_t)pss.ps_argvstr; |
| 1919 | vsize = pss.ps_nargvstr; |
| 1920 | if (vsize > ARG_MAX) |
| 1921 | return (ENOEXEC); |
| 1922 | size = vsize * sizeof(char *); |
| 1923 | break; |
| 1924 | case PROC_ENV: |
| 1925 | vptr = (vm_offset_t)pss.ps_envstr; |
| 1926 | vsize = pss.ps_nenvstr; |
| 1927 | if (vsize > ARG_MAX) |
| 1928 | return (ENOEXEC); |
| 1929 | size = vsize * sizeof(char *); |
| 1930 | break; |
| 1931 | case PROC_AUX: |
| 1932 | /* |
| 1933 | * The aux array is just above env array on the stack. Check |
| 1934 | * that the address is naturally aligned. |
| 1935 | */ |
| 1936 | vptr = (vm_offset_t)pss.ps_envstr + (pss.ps_nenvstr + 1) |
| 1937 | * sizeof(char *); |
| 1938 | #if __ELF_WORD_SIZE == 64 |
| 1939 | if (vptr % sizeof(uint64_t) != 0) |
| 1940 | #else |
| 1941 | if (vptr % sizeof(uint32_t) != 0) |
| 1942 | #endif |
| 1943 | return (ENOEXEC); |
| 1944 | /* |
| 1945 | * We count the array size reading the aux vectors from the |
| 1946 | * stack until AT_NULL vector is returned. So (to keep the code |
| 1947 | * simple) we read the process stack twice: the first time here |
| 1948 | * to find the size and the second time when copying the vectors |
| 1949 | * to the allocated proc_vector. |
| 1950 | */ |
| 1951 | for (ptr = vptr, i = 0; i < PROC_AUXV_MAX; i++) { |
| 1952 | if (proc_readmem(td, p, ptr, &aux, sizeof(aux)) != |
| 1953 | sizeof(aux)) |
| 1954 | return (ENOMEM); |
| 1955 | if (aux.a_type == AT_NULL) |
no test coverage detected