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