xref: /freebsd/sys/fs/procfs/procfs_mem.c (revision 29363fb4)
1d167cf6fSWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1993 Jan-Simon Pendry
5df8bae1dSRodney W. Grimes  * Copyright (c) 1993 Sean Eric Fagan
6df8bae1dSRodney W. Grimes  * Copyright (c) 1993
7df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
8df8bae1dSRodney W. Grimes  *
9df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
10df8bae1dSRodney W. Grimes  * Jan-Simon Pendry and Sean Eric Fagan.
11df8bae1dSRodney W. Grimes  *
12df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
13df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
14df8bae1dSRodney W. Grimes  * are met:
15df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
17df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
18df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
19df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
20fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37df8bae1dSRodney W. Grimes #include <sys/param.h>
38fb919e4dSMark Murray #include <sys/lock.h>
3923955314SAlfred Perlstein #include <sys/mutex.h>
40df8bae1dSRodney W. Grimes #include <sys/proc.h>
41fb919e4dSMark Murray #include <sys/ptrace.h>
4254a4c5bfSBruce Evans #include <sys/systm.h>
433a669c52SDag-Erling Smørgrav #include <sys/uio.h>
44fb919e4dSMark Murray 
453a669c52SDag-Erling Smørgrav #include <fs/pseudofs/pseudofs.h>
4699d300a1SRuslan Ermilov #include <fs/procfs/procfs.h>
47fb919e4dSMark Murray 
48df8bae1dSRodney W. Grimes /*
49df8bae1dSRodney W. Grimes  * Copy data in and out of the target process.
50df8bae1dSRodney W. Grimes  * We do this by mapping the process's page into
51df8bae1dSRodney W. Grimes  * the kernel and then doing a uiomove direct
52df8bae1dSRodney W. Grimes  * from the kernel address space.
53df8bae1dSRodney W. Grimes  */
54df8bae1dSRodney W. Grimes int
procfs_doprocmem(PFS_FILL_ARGS)553a669c52SDag-Erling Smørgrav procfs_doprocmem(PFS_FILL_ARGS)
56df8bae1dSRodney W. Grimes {
57f2e6be58SRobert Watson 	int error;
58df8bae1dSRodney W. Grimes 
59df8bae1dSRodney W. Grimes 	if (uio->uio_resid == 0)
60df8bae1dSRodney W. Grimes 		return (0);
61df8bae1dSRodney W. Grimes 
62ce5aaf45SJohn Baldwin 	PROC_LOCK(p);
63f44d9e24SJohn Baldwin 	error = p_candebug(td, p);
64ce5aaf45SJohn Baldwin 	PROC_UNLOCK(p);
65ce5aaf45SJohn Baldwin 	if (error == 0)
663a669c52SDag-Erling Smørgrav 		error = proc_rwmem(p, uio);
6749356a1fSSean Eric Fagan 
683a669c52SDag-Erling Smørgrav 	return (error);
69df8bae1dSRodney W. Grimes }
70