xref: /freebsd/share/man/man9/fetch.9 (revision a31070e90de2602a7364c81c45f25f69aa9e9d3e)
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 October 29, 2014
38.Dt FETCH 9
39.Os
40.Sh NAME
41.Nm fetch ,
42.Nm fubyte ,
43.Nm fuswintr ,
44.Nm fuword ,
45.Nm fuword16 ,
46.Nm fuword32 ,
47.Nm fuword64 ,
48.Nm fueword ,
49.Nm fueword32 ,
50.Nm fueword64
51.Nd fetch data from user-space
52.Sh SYNOPSIS
53.In sys/types.h
54.In sys/systm.h
55.Ft int
56.Fn fubyte "volatile const void *base"
57.Ft long
58.Fn fuword "volatile const void *base"
59.Ft int
60.Fn fuword16 "volatile const void *base"
61.Ft int32_t
62.Fn fuword32 "volatile const void *base"
63.Ft int64_t
64.Fn fuword64 "volatile const void *base"
65.Ft long
66.Fn fueword "volatile const void *base" "long *val"
67.Ft int32_t
68.Fn fueword32 "volatile const void *base" "int32_t *val"
69.Ft int64_t
70.Fn fueword64 "volatile const void *base" "int64_t *val"
71.In sys/resourcevar.h
72.Ft int
73.Fn fuswintr "void *base"
74.Sh DESCRIPTION
75The
76.Nm
77functions are designed to copy small amounts of data from user-space
78of the current process.
79If read is successful, it is performed atomically.
80The data read must be naturally aligned.
81.Pp
82The
83.Nm
84routines provide the following functionality:
85.Bl -tag -width "fueword32()"
86.It Fn fubyte
87Fetches a byte of data from the user-space address
88.Pa base .
89The byte read is zero-extended into the results variable.
90.It Fn fuword
91Fetches a word of data (long) from the user-space address
92.Pa base .
93.It Fn fuword16
94Fetches 16 bits of data from the user-space address
95.Pa base .
96The half-word read is zero-extended into the results variable.
97.It Fn fuword32
98Fetches 32 bits of data from the user-space address
99.Pa base .
100.It Fn fuword64
101Fetches 64 bits of data from the user-space address
102.Pa base .
103.It Fn fuswintr
104Fetches a short word of data from the user-space address
105.Pa base .
106This function is safe to call during an interrupt context.
107.It Fn fueword
108Fetches a word of data (long) from the user-space address
109.Pa base
110and stores the result in the variable pointed by
111.Pa val .
112.It Fn fueword32
113Fetches 32 bits of data from the user-space address
114.Pa base
115and stores the result in the variable pointed by
116.Pa val .
117.It Fn fueword64
118Fetches 64 bits of data from the user-space address
119.Pa base
120and stores the result in the variable pointed by
121.Pa val .
122.El
123.Pp
124The callers of
125.Fn fuword ,
126.Fn fuword32
127and
128.Fn fuword64
129functions cannot distinguish between -1 read from
130userspace and function failure.
131.Sh RETURN VALUES
132The
133.Fn fubyte ,
134.Fn fuword ,
135.Fn fuword16 ,
136.Fn fuword32 ,
137.Fn fuword64 ,
138and
139.Fn fuswintr
140functions return the data fetched or -1 on failure.
141The
142.Fn fueword ,
143.Fn fueword32
144and
145.Fn fueword64
146functions return 0 on success and -1 on failure.
147.Sh SEE ALSO
148.Xr copy 9 ,
149.Xr store 9
150