xref: /freebsd/share/man/man9/casuword.9 (revision 4f3dc900231ae7975a614581b973ce530836a0c9)
1*4f3dc900SKonstantin Belousov.\" Copyright (c) 2014 The FreeBSD Foundation
2*4f3dc900SKonstantin Belousov.\" All rights reserved.
3*4f3dc900SKonstantin Belousov.\"
4*4f3dc900SKonstantin Belousov.\" Part of this documentation was written by
5*4f3dc900SKonstantin Belousov.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
6*4f3dc900SKonstantin Belousov.\" from the FreeBSD Foundation.
7*4f3dc900SKonstantin Belousov.\"
8*4f3dc900SKonstantin Belousov.\" Redistribution and use in source and binary forms, with or without
9*4f3dc900SKonstantin Belousov.\" modification, are permitted provided that the following conditions
10*4f3dc900SKonstantin Belousov.\" are met:
11*4f3dc900SKonstantin Belousov.\" 1. Redistributions of source code must retain the above copyright
12*4f3dc900SKonstantin Belousov.\"    notice, this list of conditions and the following disclaimer.
13*4f3dc900SKonstantin Belousov.\" 2. Redistributions in binary form must reproduce the above copyright
14*4f3dc900SKonstantin Belousov.\"    notice, this list of conditions and the following disclaimer in the
15*4f3dc900SKonstantin Belousov.\"    documentation and/or other materials provided with the distribution.
16*4f3dc900SKonstantin Belousov.\"
17*4f3dc900SKonstantin Belousov.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18*4f3dc900SKonstantin Belousov.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4f3dc900SKonstantin Belousov.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4f3dc900SKonstantin Belousov.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21*4f3dc900SKonstantin Belousov.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4f3dc900SKonstantin Belousov.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4f3dc900SKonstantin Belousov.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4f3dc900SKonstantin Belousov.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4f3dc900SKonstantin Belousov.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4f3dc900SKonstantin Belousov.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4f3dc900SKonstantin Belousov.\" SUCH DAMAGE.
28*4f3dc900SKonstantin Belousov.\"
29*4f3dc900SKonstantin Belousov.\" $FreeBSD$
30*4f3dc900SKonstantin Belousov.\"
31*4f3dc900SKonstantin Belousov.Dd October 21, 2014
32*4f3dc900SKonstantin Belousov.Dt CASU 9
33*4f3dc900SKonstantin Belousov.Os
34*4f3dc900SKonstantin Belousov.Sh NAME
35*4f3dc900SKonstantin Belousov.Nm casueword ,
36*4f3dc900SKonstantin Belousov.Nm casueword32 ,
37*4f3dc900SKonstantin Belousov.Nm casuword ,
38*4f3dc900SKonstantin Belousov.Nm casuword32
39*4f3dc900SKonstantin Belousov.Nd fetch, compare and store data from user-space
40*4f3dc900SKonstantin Belousov.Sh SYNOPSIS
41*4f3dc900SKonstantin Belousov.In sys/types.h
42*4f3dc900SKonstantin Belousov.In sys/systm.h
43*4f3dc900SKonstantin Belousov.Ft int
44*4f3dc900SKonstantin Belousov.Fn casueword "volatile u_long *base" "u_long oldval" "u_long *oldvalp" "u_long newval"
45*4f3dc900SKonstantin Belousov.Ft int
46*4f3dc900SKonstantin Belousov.Fn casueword32 "volatile uint32_t *base" "uint32_t oldval" "uint32_t *oldvalp" "uint32_t newval"
47*4f3dc900SKonstantin Belousov.Ft u_long
48*4f3dc900SKonstantin Belousov.Fn casuword "volatile u_long *base" "u_long oldval" "u_long newval"
49*4f3dc900SKonstantin Belousov.Ft uint32_t
50*4f3dc900SKonstantin Belousov.Fn casuword32 "volatile uint32_t *base" "uint32_t oldval" "uint32_t newval"
51*4f3dc900SKonstantin Belousov.Sh DESCRIPTION
52*4f3dc900SKonstantin BelousovThe
53*4f3dc900SKonstantin Belousov.Nm
54*4f3dc900SKonstantin Belousovfunctions are designed to perform atomic compare-and-swap operation on
55*4f3dc900SKonstantin Belousovthe value in the usermode memory of the current process.
56*4f3dc900SKonstantin Belousov.Pp
57*4f3dc900SKonstantin BelousovThe
58*4f3dc900SKonstantin Belousov.Nm
59*4f3dc900SKonstantin Belousovroutines reads the value from user memory with address
60*4f3dc900SKonstantin Belousov.Pa base ,
61*4f3dc900SKonstantin Belousovand compare the value read with
62*4f3dc900SKonstantin Belousov.Pa oldval .
63*4f3dc900SKonstantin BelousovIf the values are equal,
64*4f3dc900SKonstantin Belousov.Pa newval
65*4f3dc900SKonstantin Belousovis written to the
66*4f3dc900SKonstantin Belousov.Pa *base .
67*4f3dc900SKonstantin BelousovIn case of
68*4f3dc900SKonstantin Belousov.Fn casueword32
69*4f3dc900SKonstantin Belousovand
70*4f3dc900SKonstantin Belousov.Fn casueword ,
71*4f3dc900SKonstantin Belousovold value is stored into the (kernel-mode) variable pointed by
72*4f3dc900SKonstantin Belousov.Pa *oldvalp .
73*4f3dc900SKonstantin BelousovThe userspace value must be naturally aligned.
74*4f3dc900SKonstantin Belousov.Pp
75*4f3dc900SKonstantin BelousovThe callers of
76*4f3dc900SKonstantin Belousov.Fn casuword
77*4f3dc900SKonstantin Belousovand
78*4f3dc900SKonstantin Belousov.Fn casuword32
79*4f3dc900SKonstantin Belousovfunctions cannot distinguish between -1 read from
80*4f3dc900SKonstantin Belousovuserspace and function failure.
81*4f3dc900SKonstantin Belousov.Sh RETURN VALUES
82*4f3dc900SKonstantin BelousovThe
83*4f3dc900SKonstantin Belousov.Fn casuword
84*4f3dc900SKonstantin Belousovand
85*4f3dc900SKonstantin Belousov.Fn casuword32
86*4f3dc900SKonstantin Belousovfunctions return the data fetched or -1 on failure.
87*4f3dc900SKonstantin BelousovThe
88*4f3dc900SKonstantin Belousov.Fn casueword
89*4f3dc900SKonstantin Belousovand
90*4f3dc900SKonstantin Belousov.Fn casueword32
91*4f3dc900SKonstantin Belousovfunctions return 0 on success and -1 on failure.
92*4f3dc900SKonstantin Belousov.Sh SEE ALSO
93*4f3dc900SKonstantin Belousov.Xr atomic 9 ,
94*4f3dc900SKonstantin Belousov.Xr fetch 9 ,
95*4f3dc900SKonstantin Belousov.Xr store 9
96