xref: /freebsd-src/sys/cddl/compat/opensolaris/kern/opensolaris_proc.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1*9e579a58SMark Johnston /*-
2*9e579a58SMark Johnston  * Copyright 2016 Mark Johnston <markj@FreeBSD.org>
3*9e579a58SMark Johnston  *
4*9e579a58SMark Johnston  * Redistribution and use in source and binary forms, with or without
5*9e579a58SMark Johnston  * modification, are permitted provided that the following conditions
6*9e579a58SMark Johnston  * are met:
7*9e579a58SMark Johnston  * 1. Redistributions of source code must retain the above copyright
8*9e579a58SMark Johnston  *    notice, this list of conditions and the following disclaimer.
9*9e579a58SMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
10*9e579a58SMark Johnston  *    notice, this list of conditions and the following disclaimer in the
11*9e579a58SMark Johnston  *    documentation and/or other materials provided with the distribution.
12*9e579a58SMark Johnston  *
13*9e579a58SMark Johnston  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*9e579a58SMark Johnston  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*9e579a58SMark Johnston  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*9e579a58SMark Johnston  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17*9e579a58SMark Johnston  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*9e579a58SMark Johnston  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*9e579a58SMark Johnston  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*9e579a58SMark Johnston  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*9e579a58SMark Johnston  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*9e579a58SMark Johnston  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*9e579a58SMark Johnston  * SUCH DAMAGE.
24*9e579a58SMark Johnston  */
25*9e579a58SMark Johnston 
26*9e579a58SMark Johnston #include <sys/types.h>
27*9e579a58SMark Johnston #include <sys/proc.h>
28*9e579a58SMark Johnston #include <sys/ptrace.h>
29*9e579a58SMark Johnston 
30*9e579a58SMark Johnston int
uread(proc_t * p,void * kaddr,size_t len,uintptr_t uaddr)31*9e579a58SMark Johnston uread(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr)
32*9e579a58SMark Johnston {
33*9e579a58SMark Johnston 	ssize_t n;
34*9e579a58SMark Johnston 
35*9e579a58SMark Johnston 	n = proc_readmem(curthread, p, uaddr, kaddr, len);
36*9e579a58SMark Johnston 	if (n != len)
37*9e579a58SMark Johnston 		return (ENOMEM);
38*9e579a58SMark Johnston 	return (0);
39*9e579a58SMark Johnston }
40*9e579a58SMark Johnston 
41*9e579a58SMark Johnston int
uwrite(proc_t * p,void * kaddr,size_t len,uintptr_t uaddr)42*9e579a58SMark Johnston uwrite(proc_t *p, void *kaddr, size_t len, uintptr_t uaddr)
43*9e579a58SMark Johnston {
44*9e579a58SMark Johnston 	ssize_t n;
45*9e579a58SMark Johnston 
46*9e579a58SMark Johnston 	n = proc_writemem(curthread, p, uaddr, kaddr, len);
47*9e579a58SMark Johnston 	if (n != len)
48*9e579a58SMark Johnston 		return (ENOMEM);
49*9e579a58SMark Johnston 	return (0);
50*9e579a58SMark Johnston }
51