priv_vm_mlock.c revision 172106
1178476Sjb/*-
2178476Sjb * Copyright (c) 2006 nCircle Network Security, Inc.
3178476Sjb * Copyright (c) 2007 Robert N. M. Watson
4178476Sjb * All rights reserved.
5178476Sjb *
6178476Sjb * This software was developed by Robert N. M. Watson for the TrustedBSD
7178476Sjb * Project under contract to nCircle Network Security, Inc.
8178476Sjb *
9178476Sjb * Redistribution and use in source and binary forms, with or without
10178476Sjb * modification, are permitted provided that the following conditions
11178476Sjb * are met:
12178476Sjb * 1. Redistributions of source code must retain the above copyright
13178476Sjb *    notice, this list of conditions and the following disclaimer.
14178476Sjb * 2. Redistributions in binary form must reproduce the above copyright
15178476Sjb *    notice, this list of conditions and the following disclaimer in the
16178476Sjb *    documentation and/or other materials provided with the distribution.
17178476Sjb *
18178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21178476Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
22178476Sjb * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23178476Sjb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24178476Sjb * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25178476Sjb * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26178476Sjb * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27178476Sjb * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28178476Sjb * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29178476Sjb *
30178476Sjb * $FreeBSD: head/tools/regression/priv/priv_vm_mlock.c 172106 2007-09-09 23:08:39Z rwatson $
31178476Sjb */
32178476Sjb
33178476Sjb/*
34178476Sjb * Test that mlock() requires privilege.
35178476Sjb */
36178476Sjb
37178476Sjb#include <sys/types.h>
38178476Sjb#include <sys/mman.h>
39178476Sjb
40178476Sjb#include <err.h>
41178476Sjb#include <errno.h>
42178476Sjb#include <unistd.h>
43178476Sjb
44178476Sjb#include "main.h"
45178476Sjb
46178476Sjbint
47178476Sjbpriv_vm_mlock_setup(int asroot, int injail, struct test *test)
48178476Sjb{
49
50	return (0);
51}
52
53void
54priv_vm_mlock(int asroot, int injail, struct test *test)
55{
56	int error;
57
58	error = mlock(&error, getpagesize());
59	if (asroot && injail)
60		expect("priv_vm_mlock(asroot, injail)", error, -1, EPERM);
61	if (asroot && !injail)
62		expect("priv_vm_mlock(asroot, !injail", error, 0, 0);
63	if (!asroot && injail)
64		expect("priv_vm_mlock(!asroot, injail", error, -1, EPERM);
65	if (!asroot && !injail)
66		expect("priv_vm_mlock(!asroot, !injail", error, -1, EPERM);
67}
68
69void
70priv_vm_mlock_cleanup(int asroot, int injail, struct test *test)
71{
72
73}
74