1 /* vm/access.c - checking access rights
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Edwin Steiner
31 $Id: access.c 3451 2005-10-19 22:01:25Z twisti $
40 #include "vm/access.h"
41 #include "vm/builtin.h"
45 /****************************************************************************/
47 /****************************************************************************/
54 #define ACCESS_ASSERT(cond) assert(cond)
56 #define ACCESS_ASSERT(cond)
59 /****************************************************************************/
61 /****************************************************************************/
63 /* access_is_accessible_class **************************************************
65 Check if a class is accessible from another class
68 referer..........the class containing the reference
69 cls..............the result of resolving the reference
72 true.............access permitted
73 false............access denied
76 This function performs the checks listed in section 5.4.4.
77 "Access Control" of "The Java(TM) Virtual Machine Specification,
80 *******************************************************************************/
82 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
84 ACCESS_ASSERT(referer);
87 /* public classes are always accessible */
88 if (cls->flags & ACC_PUBLIC)
91 /* a class in the same package is always accessible */
92 if (SAME_PACKAGE(referer, cls))
95 /* a non-public class in another package is not accessible */
102 /* access_is_accessible_member *************************************************
104 Check if a field or method is accessible from a given class
107 referer..........the class containing the reference
108 declarer.........the class declaring the member
109 memberflags......the access flags of the member
112 true.............access permitted
113 false............access denied
116 This function only performs the checks listed in section 5.4.4.
117 "Access Control" of "The Java(TM) Virtual Machine Specification,
120 In particular a special condition for protected access with is
121 part of the verification process according to the spec is not
122 checked in this function.
124 *******************************************************************************/
126 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
129 ACCESS_ASSERT(referer);
130 ACCESS_ASSERT(declarer);
132 /* public members are accessible */
133 if (memberflags & ACC_PUBLIC)
136 /* {declarer is not an interface} */
138 /* private members are only accessible by the class itself */
139 if (memberflags & ACC_PRIVATE)
140 return (referer == declarer);
142 /* {the member is protected or package private} */
144 /* protected and package private members are accessible in the same package */
145 if (SAME_PACKAGE(referer,declarer))
148 /* package private members are not accessible outside the package */
149 if (!(memberflags & ACC_PROTECTED))
152 /* {the member is protected and declarer is in another package} */
154 /* a necessary condition for access is that referer is a subclass of declarer */
155 ACCESS_ASSERT(referer->linked && declarer->linked);
156 if (builtin_isanysubclass(referer,declarer))
164 * These are local overrides for various environment variables in Emacs.
165 * Please do not remove this and leave it at the end of the file, where
166 * Emacs will automagically detect them.
167 * ---------------------------------------------------------------------
170 * indent-tabs-mode: t
174 * vim:noexpandtab:sw=4:ts=4: