xref: /netbsd-src/sys/miscfs/procfs/procfs_auxv.c (revision 37c269d9aae9dbc2fc37145ae0c871b9cf64efe2)
1*37c269d9Schristos /*	$NetBSD: procfs_auxv.c,v 1.4 2019/09/27 14:36:18 christos Exp $	*/
22d1443a6Schristos 
32d1443a6Schristos /*-
42d1443a6Schristos  * Copyright (c) 2017 The NetBSD Foundation, Inc.
52d1443a6Schristos  * All rights reserved.
62d1443a6Schristos  *
72d1443a6Schristos  * This code is derived from software contributed to The NetBSD Foundation
82d1443a6Schristos  * by Christos Zoulas.
92d1443a6Schristos  *
102d1443a6Schristos  * Redistribution and use in source and binary forms, with or without
112d1443a6Schristos  * modification, are permitted provided that the following conditions
122d1443a6Schristos  * are met:
132d1443a6Schristos  * 1. Redistributions of source code must retain the above copyright
142d1443a6Schristos  *    notice, this list of conditions and the following disclaimer.
152d1443a6Schristos  * 2. Redistributions in binary form must reproduce the above copyright
162d1443a6Schristos  *    notice, this list of conditions and the following disclaimer in the
172d1443a6Schristos  *    documentation and/or other materials provided with the distribution.
182d1443a6Schristos  *
192d1443a6Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
202d1443a6Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
212d1443a6Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
222d1443a6Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
232d1443a6Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
242d1443a6Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
252d1443a6Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
262d1443a6Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
272d1443a6Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
282d1443a6Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
292d1443a6Schristos  * POSSIBILITY OF SUCH DAMAGE.
302d1443a6Schristos  */
312d1443a6Schristos #include <sys/cdefs.h>
32*37c269d9Schristos __KERNEL_RCSID(0, "$NetBSD: procfs_auxv.c,v 1.4 2019/09/27 14:36:18 christos Exp $");
332d1443a6Schristos 
342d1443a6Schristos #include <sys/param.h>
352d1443a6Schristos #include <sys/systm.h>
362d1443a6Schristos #include <sys/proc.h>
372d1443a6Schristos #include <sys/kmem.h>
382d1443a6Schristos 
392d1443a6Schristos #include <miscfs/procfs/procfs.h>
402d1443a6Schristos 
412d1443a6Schristos int
procfs_doauxv(struct lwp * curl,struct proc * p,struct pfsnode * pfs,struct uio * uio)422d1443a6Schristos procfs_doauxv(struct lwp *curl, struct proc *p, struct pfsnode *pfs,
432d1443a6Schristos      struct uio *uio)
442d1443a6Schristos {
452d1443a6Schristos 	int error;
462d1443a6Schristos 	void *buffer;
472d1443a6Schristos 	size_t bufsize;
482d1443a6Schristos 
492d1443a6Schristos 	if (uio->uio_rw != UIO_READ)
502d1443a6Schristos 		return EOPNOTSUPP;
512d1443a6Schristos 
522d1443a6Schristos 	if ((error = proc_getauxv(p, &buffer, &bufsize)) != 0)
532d1443a6Schristos 		return error;
542d1443a6Schristos 
55*37c269d9Schristos 	if ((uintmax_t)uio->uio_offset < bufsize)
562d1443a6Schristos 		error = uiomove((char *)buffer + uio->uio_offset,
572d1443a6Schristos 		    bufsize - uio->uio_offset, uio);
582d1443a6Schristos 	else
592d1443a6Schristos 		error = 0;
602d1443a6Schristos 
612d1443a6Schristos 	kmem_free(buffer, bufsize);
622d1443a6Schristos 	return error;
632d1443a6Schristos }
642d1443a6Schristos 
652d1443a6Schristos int
procfs_validauxv(struct lwp * l,struct mount * mp)662d1443a6Schristos procfs_validauxv(struct lwp *l, struct mount *mp)
672d1443a6Schristos {
682d1443a6Schristos 	return l != NULL && l->l_proc != NULL && l->l_proc->p_execsw != NULL;
692d1443a6Schristos }
70