xref: /freebsd/share/man/man9/fetch.9 (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1.\"	$NetBSD: fetch.9,v 1.2 1996/01/09 21:59:24 perry Exp $
2.\"
3.\" Copyright (c) 1996 Jason R. Thorpe.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed by Kenneth Stailey.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed for the NetBSD Project
19.\"	by Jason R. Thorpe.
20.\" 4. The name of the author may not be used to endorse or promote products
21.\"    derived from this software without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\" $FreeBSD$
36.\"
37.Dd January 23, 2020
38.Dt FETCH 9
39.Os
40.Sh NAME
41.Nm fetch ,
42.Nm fubyte ,
43.Nm fuword ,
44.Nm fuword16 ,
45.Nm fuword32 ,
46.Nm fuword64 ,
47.Nm fueword ,
48.Nm fueword32 ,
49.Nm fueword64
50.Nd fetch data from user-space
51.Sh SYNOPSIS
52.In sys/types.h
53.In sys/systm.h
54.Ft int
55.Fn fubyte "volatile const void *base"
56.Ft long
57.Fn fuword "volatile const void *base"
58.Ft int
59.Fn fuword16 "volatile const void *base"
60.Ft int32_t
61.Fn fuword32 "volatile const void *base"
62.Ft int64_t
63.Fn fuword64 "volatile const void *base"
64.Ft int
65.Fn fueword "volatile const void *base" "long *val"
66.Ft int
67.Fn fueword32 "volatile const void *base" "int32_t *val"
68.Ft int
69.Fn fueword64 "volatile const void *base" "int64_t *val"
70.In sys/resourcevar.h
71.Sh DESCRIPTION
72The
73.Nm
74functions are designed to copy small amounts of data from user-space
75of the current process.
76If read is successful, it is performed atomically.
77The data read must be naturally aligned.
78.Pp
79The
80.Nm
81routines provide the following functionality:
82.Bl -tag -width "fueword32()"
83.It Fn fubyte
84Fetches a byte of data from the user-space address
85.Pa base .
86The byte read is zero-extended into the results variable.
87.It Fn fuword
88Fetches a word of data (long) from the user-space address
89.Pa base .
90.It Fn fuword16
91Fetches 16 bits of data from the user-space address
92.Pa base .
93The half-word read is zero-extended into the results variable.
94.It Fn fuword32
95Fetches 32 bits of data from the user-space address
96.Pa base .
97.It Fn fuword64
98Fetches 64 bits of data from the user-space address
99.Pa base .
100.It Fn fueword
101Fetches a word of data (long) from the user-space address
102.Pa base
103and stores the result in the variable pointed by
104.Pa val .
105.It Fn fueword32
106Fetches 32 bits of data from the user-space address
107.Pa base
108and stores the result in the variable pointed by
109.Pa val .
110.It Fn fueword64
111Fetches 64 bits of data from the user-space address
112.Pa base
113and stores the result in the variable pointed by
114.Pa val .
115.El
116.Pp
117The callers of
118.Fn fuword ,
119.Fn fuword32
120and
121.Fn fuword64
122functions cannot distinguish between -1 read from
123userspace and function failure.
124.Sh RETURN VALUES
125The
126.Fn fubyte ,
127.Fn fuword ,
128.Fn fuword16 ,
129.Fn fuword32 ,
130and
131.Fn fuword64
132functions return the data fetched or -1 on failure.
133The
134.Fn fueword ,
135.Fn fueword32
136and
137.Fn fueword64
138functions return 0 on success and -1 on failure.
139.Sh SEE ALSO
140.Xr copy 9 ,
141.Xr store 9
142