blob: d44ebdca79d982284634a1feb82154c0e22bca31 [file] [log] [blame]
sewardj4cfea4f2006-10-14 19:26:10 +00001
2/*--------------------------------------------------------------------*/
3/*--- Notional "implementation" for m_vki. ---*/
4/*--- m_vki.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
sewardj03f8d3f2012-08-05 15:46:46 +000011 Copyright (C) 2006-2012 OpenWorks LLP
sewardj4cfea4f2006-10-14 19:26:10 +000012 info@open-works.co.uk
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#include "pub_core_basics.h"
njncda2f0f2009-05-18 02:12:08 +000033#include "pub_core_libcassert.h"
sewardj4cfea4f2006-10-14 19:26:10 +000034#include "pub_core_vki.h" /* self */
35
36/* We have pub_{core,tool}_vki.h. This is the matching implementation
37 for that interface. In fact there is no implementation, as the
38 sole purpose of the module is to export types and constants
sewardje66f2e02006-12-30 17:45:08 +000039 describing the kernel interface, so this file is nearly empty. */
40
41
42/* ppc32/64-linux determines page size at startup, hence m_vki is
43 the logical place to store that info. */
44
45#if defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux)
46unsigned long VKI_PAGE_SHIFT = 12;
47unsigned long VKI_PAGE_SIZE = 1UL << 12;
48#endif
sewardj4cfea4f2006-10-14 19:26:10 +000049
50
njncda2f0f2009-05-18 02:12:08 +000051/* Do initial consistency checks on some of the definitions to do with
52 signals (vki_sigset_t and vki_sigaction_{toK,fromK}_t). This stuff
53 is fragile enough that it's important to check at startup that
54 the world looks like what we expect it to look like.
55
56 The most important thing is to check that the definition of signal
57 sets for this platform is right. A signal set consists of some
58 number _VKI_NSIG_WORDS of 32- or 64-bit words. Because the kernel
59 itself has some indexing scheme to set/clear individual bits in the
60 set, we must make sure we use the same layout/scheme: where this
61 requirement bites us is in the VG_(sigfillset) etc functions in
62 m_libcsignal.c. So we check carefully here that it's all sensible.
63*/
64void VG_(vki_do_initial_consistency_checks) ( void )
65{
66 /* --- Platform-independent checks on signal sets --- */
67
68 vki_sigset_t set;
69 // Set's size must agree with _VKI_NSIG
70 vg_assert( 8 * sizeof(set) == _VKI_NSIG );
71 // Set's word size must agree with _VKI_NSIG_BPW
72 vg_assert( 8 * sizeof(set.sig[0]) == _VKI_NSIG_BPW );
73 // The set elements are 32- or 64-bit
74 vg_assert( _VKI_NSIG_BPW == 32 || _VKI_NSIG_BPW == 64 );
75
76 /* --- Platform-specific checks on signal sets --- */
77
sewardj6e9de462011-06-28 07:25:29 +000078# if defined(VGO_linux)
njncda2f0f2009-05-18 02:12:08 +000079 /* nothing to check */
njnf76d27a2009-05-28 01:53:07 +000080# elif defined(VGP_x86_darwin) || defined(VGP_amd64_darwin)
81 vg_assert(_VKI_NSIG == NSIG);
82 vg_assert(_VKI_NSIG == 32);
83 vg_assert(_VKI_NSIG_WORDS == 1);
84 vg_assert(sizeof(sigset_t) /* defined by Darwin */
85 == sizeof(vki_sigset_t) /* what we actually use */);
njncda2f0f2009-05-18 02:12:08 +000086# else
87# error "Unknown plat"
88# endif
89
90 /* --- Platform-specific checks on sigactions --- */
91
sewardj6e9de462011-06-28 07:25:29 +000092# if defined(VGO_linux)
njncda2f0f2009-05-18 02:12:08 +000093 /* the toK- and fromK- forms are identical */
94 vg_assert( sizeof(vki_sigaction_toK_t)
95 == sizeof(vki_sigaction_fromK_t) );
njnf76d27a2009-05-28 01:53:07 +000096# elif defined(VGO_darwin)
97 /* the toK- and fromK- forms differ by one function-pointer field
98 (sa_tramp) */
99 vg_assert( sizeof(vki_sigaction_toK_t)
100 == sizeof(vki_sigaction_fromK_t) + sizeof(void*) );
101
102 vg_assert(sizeof(struct sigaction) == sizeof(vki_sigaction_fromK_t));
103 vg_assert(sizeof(struct __sigaction) == sizeof(vki_sigaction_toK_t));
104 { struct __sigaction t1;
105 vki_sigaction_toK_t t2;
106 struct sigaction f1;
107 vki_sigaction_fromK_t f2;
108 vg_assert(sizeof(t1.sa_handler) == sizeof(t2.ksa_handler));
109 vg_assert(sizeof(t1.sa_tramp) == sizeof(t2.sa_tramp));
110 vg_assert(sizeof(t1.sa_mask) == sizeof(t2.sa_mask));
111 vg_assert(sizeof(t1.sa_flags) == sizeof(t2.sa_flags));
112 vg_assert(sizeof(f1.sa_handler) == sizeof(f2.ksa_handler));
113 vg_assert(sizeof(f1.sa_mask) == sizeof(f2.sa_mask));
114 vg_assert(sizeof(f1.sa_flags) == sizeof(f2.sa_flags));
115# if 0
116 vg_assert(offsetof(t1,sa_handler) == offsetof(t2.ksa_handler));
117 vg_assert(offsetof(t1.sa_tramp) == offsetof(t2.sa_tramp));
118 vg_assert(offsetof(t1.sa_mask) == offsetof(t2.sa_mask));
119 vg_assert(offsetof(t1.sa_flags) == offsetof(t2.sa_flags));
120 vg_assert(offsetof(f1.sa_handler) == offsetof(f2.ksa_handler));
121 vg_assert(offsetof(f1.sa_mask) == offsetof(f2.sa_mask));
122 vg_assert(offsetof(f1.sa_flags) == offsetof(f2.sa_flags));
123# endif
124 }
125 /* also .. */
126 /* VKI_SET_SIGMASK is hardwired into syscall-x86-darwin.S and
127 syscall-amd64-darwin.S */
128 vg_assert(VKI_SIG_SETMASK == 3);
njncda2f0f2009-05-18 02:12:08 +0000129
130# else
131# error "Unknown OS"
132# endif
133}
134
135
sewardj4cfea4f2006-10-14 19:26:10 +0000136/*--------------------------------------------------------------------*/
137/*--- end m_vki.c ---*/
138/*--------------------------------------------------------------------*/