1.\" $OpenBSD: mimmutable.2,v 1.3 2022/11/06 20:15:44 jmc Exp $ 2.\" 3.\" Copyright (c) 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)mimmutable.2 8.1 (Berkeley) 6/9/93 31.\" 32.Dd $Mdocdate: November 6 2022 $ 33.Dt MIMMUTABLE 2 34.Os 35.Sh NAME 36.Nm mimmutable 37.Nd control the immutability of pages 38.Sh SYNOPSIS 39.In sys/mman.h 40.Ft int 41.Fn mimmutable "void *addr" "size_t len" 42.Sh DESCRIPTION 43The 44.Fn mimmutable 45system call 46changes currently mapped pages in the region to be marked immutable, 47which means their protection or mapping may not be changed in the future. 48.Xr mmap 2 , 49.Xr mprotect 2 , 50and 51.Xr munmap 2 52to pages marked immutable will return with error 53.Er EPERM . 54.Pp 55Unmapped pages in the region do not retain immutability, but this 56behaviour should not be relied upon. 57.Pp 58Not all implementations will guarantee that the immutable characteristic 59can be set on a page basis; 60the granularity of changes may be as large as an entire region. 61.Sh RETURN VALUES 62.Rv -std 63.Sh ERRORS 64The 65.Fn mimmutable 66system call will fail if: 67.Bl -tag -width Er 68.It Bq Er EINVAL 69The virtual address range specified by the 70.Fa addr 71and 72.Fa len 73arguments is not valid. 74.El 75.Sh SEE ALSO 76.Xr mmap 2 , 77.Xr mprotect 2 , 78.Xr munmap 2 79.Sh HISTORY 80The 81.Fn mimmutable 82function first appeared in 83.Ox 7.3 . 84.Sh CAVEATS 85At present, 86.Xr mprotect 2 87may reduce permissions on immutable pages marked 88.Dv PROT_READ | PROT_WRITE 89to the less permissive 90.Dv PROT_READ . 91This one-way operation is permitted for an introductory period to observe how 92software uses this mechanism. 93It may change to require explicit mutable region annotation with 94.Va __attribute__((section(".openbsd.mutable"))) 95and explicit calls to 96.Fn mimmutable . 97