xref: /freebsd/share/man/man9/casuword.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1*30b3018dSKonstantin Belousov.\" Copyright (c) 2014, 2019 The FreeBSD Foundation
24f3dc900SKonstantin Belousov.\"
34f3dc900SKonstantin Belousov.\" Part of this documentation was written by
44f3dc900SKonstantin Belousov.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
54f3dc900SKonstantin Belousov.\" from the FreeBSD Foundation.
64f3dc900SKonstantin Belousov.\"
74f3dc900SKonstantin Belousov.\" Redistribution and use in source and binary forms, with or without
84f3dc900SKonstantin Belousov.\" modification, are permitted provided that the following conditions
94f3dc900SKonstantin Belousov.\" are met:
104f3dc900SKonstantin Belousov.\" 1. Redistributions of source code must retain the above copyright
114f3dc900SKonstantin Belousov.\"    notice, this list of conditions and the following disclaimer.
124f3dc900SKonstantin Belousov.\" 2. Redistributions in binary form must reproduce the above copyright
134f3dc900SKonstantin Belousov.\"    notice, this list of conditions and the following disclaimer in the
144f3dc900SKonstantin Belousov.\"    documentation and/or other materials provided with the distribution.
154f3dc900SKonstantin Belousov.\"
164f3dc900SKonstantin Belousov.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
174f3dc900SKonstantin Belousov.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184f3dc900SKonstantin Belousov.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194f3dc900SKonstantin Belousov.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
204f3dc900SKonstantin Belousov.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214f3dc900SKonstantin Belousov.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224f3dc900SKonstantin Belousov.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234f3dc900SKonstantin Belousov.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244f3dc900SKonstantin Belousov.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254f3dc900SKonstantin Belousov.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264f3dc900SKonstantin Belousov.\" SUCH DAMAGE.
274f3dc900SKonstantin Belousov.\"
28*30b3018dSKonstantin Belousov.Dd April 19, 2019
294f3dc900SKonstantin Belousov.Dt CASU 9
304f3dc900SKonstantin Belousov.Os
314f3dc900SKonstantin Belousov.Sh NAME
324f3dc900SKonstantin Belousov.Nm casueword ,
334f3dc900SKonstantin Belousov.Nm casueword32 ,
344f3dc900SKonstantin Belousov.Nm casuword ,
354f3dc900SKonstantin Belousov.Nm casuword32
364f3dc900SKonstantin Belousov.Nd fetch, compare and store data from user-space
374f3dc900SKonstantin Belousov.Sh SYNOPSIS
384f3dc900SKonstantin Belousov.In sys/types.h
394f3dc900SKonstantin Belousov.In sys/systm.h
404f3dc900SKonstantin Belousov.Ft int
41e1be41acSKonstantin Belousov.Fo casueword
42e1be41acSKonstantin Belousov.Fa "volatile u_long *base"
43e1be41acSKonstantin Belousov.Fa "u_long oldval"
44e1be41acSKonstantin Belousov.Fa "u_long *oldvalp"
45e1be41acSKonstantin Belousov.Fa "u_long newval"
46e1be41acSKonstantin Belousov.Fc
474f3dc900SKonstantin Belousov.Ft int
48e1be41acSKonstantin Belousov.Fo casueword32
49e1be41acSKonstantin Belousov.Fa "volatile uint32_t *base"
50e1be41acSKonstantin Belousov.Fa "uint32_t oldval"
51e1be41acSKonstantin Belousov.Fa "uint32_t *oldvalp"
52e1be41acSKonstantin Belousov.Fa "uint32_t newval"
53e1be41acSKonstantin Belousov.Fc
544f3dc900SKonstantin Belousov.Ft u_long
55e1be41acSKonstantin Belousov.Fo casuword
56e1be41acSKonstantin Belousov.Fa "volatile u_long *base"
57e1be41acSKonstantin Belousov.Fa "u_long oldval"
58e1be41acSKonstantin Belousov.Fa "u_long newval"
59e1be41acSKonstantin Belousov.Fc
604f3dc900SKonstantin Belousov.Ft uint32_t
61e1be41acSKonstantin Belousov.Fo casuword32
62e1be41acSKonstantin Belousov.Fa "volatile uint32_t *base"
63e1be41acSKonstantin Belousov.Fa "uint32_t oldval"
64e1be41acSKonstantin Belousov.Fa "uint32_t newval"
65e1be41acSKonstantin Belousov.Fc
664f3dc900SKonstantin Belousov.Sh DESCRIPTION
674f3dc900SKonstantin BelousovThe
684f3dc900SKonstantin Belousov.Nm
694f3dc900SKonstantin Belousovfunctions are designed to perform atomic compare-and-swap operation on
704f3dc900SKonstantin Belousovthe value in the usermode memory of the current process.
714f3dc900SKonstantin Belousov.Pp
724f3dc900SKonstantin BelousovThe
734f3dc900SKonstantin Belousov.Nm
744f3dc900SKonstantin Belousovroutines reads the value from user memory with address
754f3dc900SKonstantin Belousov.Pa base ,
764f3dc900SKonstantin Belousovand compare the value read with
774f3dc900SKonstantin Belousov.Pa oldval .
784f3dc900SKonstantin BelousovIf the values are equal,
794f3dc900SKonstantin Belousov.Pa newval
804f3dc900SKonstantin Belousovis written to the
814f3dc900SKonstantin Belousov.Pa *base .
824f3dc900SKonstantin BelousovIn case of
834f3dc900SKonstantin Belousov.Fn casueword32
844f3dc900SKonstantin Belousovand
854f3dc900SKonstantin Belousov.Fn casueword ,
864f3dc900SKonstantin Belousovold value is stored into the (kernel-mode) variable pointed by
874f3dc900SKonstantin Belousov.Pa *oldvalp .
884f3dc900SKonstantin BelousovThe userspace value must be naturally aligned.
894f3dc900SKonstantin Belousov.Pp
904f3dc900SKonstantin BelousovThe callers of
914f3dc900SKonstantin Belousov.Fn casuword
924f3dc900SKonstantin Belousovand
934f3dc900SKonstantin Belousov.Fn casuword32
944f3dc900SKonstantin Belousovfunctions cannot distinguish between -1 read from
954f3dc900SKonstantin Belousovuserspace and function failure.
964f3dc900SKonstantin Belousov.Sh RETURN VALUES
974f3dc900SKonstantin BelousovThe
984f3dc900SKonstantin Belousov.Fn casuword
994f3dc900SKonstantin Belousovand
1004f3dc900SKonstantin Belousov.Fn casuword32
1014f3dc900SKonstantin Belousovfunctions return the data fetched or -1 on failure.
1024f3dc900SKonstantin BelousovThe
1034f3dc900SKonstantin Belousov.Fn casueword
1044f3dc900SKonstantin Belousovand
1054f3dc900SKonstantin Belousov.Fn casueword32
106*30b3018dSKonstantin Belousovfunctions return 0 on success, -1 on failure to access memory,
107*30b3018dSKonstantin Belousovand 1 when comparison or store failed.
108*30b3018dSKonstantin BelousovThe store can fail on load-linked/store-conditional architectures.
1094f3dc900SKonstantin Belousov.Sh SEE ALSO
1104f3dc900SKonstantin Belousov.Xr atomic 9 ,
1114f3dc900SKonstantin Belousov.Xr fetch 9 ,
1124f3dc900SKonstantin Belousov.Xr store 9
113