1 /* vm/access.c - checking access rights
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Edwin Steiner
31 $Id: access.c 4435 2006-02-04 23:59:54Z twisti $
42 #include "vm/access.h"
43 #include "vm/builtin.h"
47 /****************************************************************************/
49 /****************************************************************************/
56 #define ACCESS_ASSERT(cond) assert(cond)
58 #define ACCESS_ASSERT(cond)
61 /****************************************************************************/
63 /****************************************************************************/
65 /* access_is_accessible_class **************************************************
67 Check if a class is accessible from another class
70 referer..........the class containing the reference
71 cls..............the result of resolving the reference
74 true.............access permitted
75 false............access denied
78 This function performs the checks listed in section 5.4.4.
79 "Access Control" of "The Java(TM) Virtual Machine Specification,
82 *******************************************************************************/
84 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
86 ACCESS_ASSERT(referer);
89 /* public classes are always accessible */
90 if (cls->flags & ACC_PUBLIC)
93 /* a class in the same package is always accessible */
94 if (SAME_PACKAGE(referer, cls))
97 /* a non-public class in another package is not accessible */
104 /* access_is_accessible_member *************************************************
106 Check if a field or method is accessible from a given class
109 referer..........the class containing the reference
110 declarer.........the class declaring the member
111 memberflags......the access flags of the member
114 true.............access permitted
115 false............access denied
118 This function only performs the checks listed in section 5.4.4.
119 "Access Control" of "The Java(TM) Virtual Machine Specification,
122 In particular a special condition for protected access with is
123 part of the verification process according to the spec is not
124 checked in this function.
126 *******************************************************************************/
128 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
131 ACCESS_ASSERT(referer);
132 ACCESS_ASSERT(declarer);
134 /* public members are accessible */
135 if (memberflags & ACC_PUBLIC)
138 /* {declarer is not an interface} */
140 /* private members are only accessible by the class itself */
141 if (memberflags & ACC_PRIVATE)
142 return (referer == declarer);
144 /* {the member is protected or package private} */
146 /* protected and package private members are accessible in the same package */
147 if (SAME_PACKAGE(referer,declarer))
150 /* package private members are not accessible outside the package */
151 if (!(memberflags & ACC_PROTECTED))
154 /* {the member is protected and declarer is in another package} */
156 /* a necessary condition for access is that referer is a subclass of declarer */
157 ACCESS_ASSERT(referer->linked && declarer->linked);
158 if (builtin_isanysubclass(referer,declarer))
166 * These are local overrides for various environment variables in Emacs.
167 * Please do not remove this and leave it at the end of the file, where
168 * Emacs will automagically detect them.
169 * ---------------------------------------------------------------------
172 * indent-tabs-mode: t
176 * vim:noexpandtab:sw=4:ts=4: