MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_proc_vector

Function get_proc_vector

freebsd/kern/kern_proc.c:1898–1983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1896#endif
1897
1898static int
1899get_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)

Callers 2

get_ps_stringsFunction · 0.85
proc_getauxvFunction · 0.85

Calls 4

get_proc_vector32Function · 0.85
proc_readmemFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected