linux.cc revision 11383
1/* 2 * Copyright (c) 2011 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * Copyright (c) 2007-2008 The Florida State University 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; 22 * redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution; 25 * neither the name of the copyright holders nor the names of its 26 * contributors may be used to endorse or promote products derived from 27 * this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Stephen Hines 42 */ 43 44#include "arch/arm/linux/linux.hh" 45 46#include <fcntl.h> 47#include <sys/mman.h> 48 49// open(2) flags translation table 50SyscallFlagTransTable ArmLinux32::openFlagTable[] = { 51#ifdef _MSC_VER 52 { ArmLinux32::TGT_O_RDONLY, _O_RDONLY }, 53 { ArmLinux32::TGT_O_WRONLY, _O_WRONLY }, 54 { ArmLinux32::TGT_O_RDWR, _O_RDWR }, 55 { ArmLinux32::TGT_O_CREAT, _O_CREAT }, 56 { ArmLinux32::TGT_O_EXCL, _O_EXCL }, 57#ifdef _O_NOCTTY 58 { ArmLinux32::TGT_O_NOCTTY, _O_NOCTTY }, 59#endif 60 { ArmLinux32::TGT_O_TRUNC, _O_TRUNC }, 61 { ArmLinux32::TGT_O_APPEND, _O_APPEND }, 62#ifdef _O_NONBLOCK 63 { ArmLinux32::TGT_O_NONBLOCK, _O_NONBLOCK }, 64#endif 65#ifdef _O_DSYNC 66 { ArmLinux32::TGT_O_DSYNC, _O_DSYNC }, 67#endif 68 { ArmLinux32::TGT_FASYNC, _O_ASYNC }, 69 { ArmLinux32::TGT_O_DIRECT, _O_DIRECT }, 70 { ArmLinux32::TGT_O_LARGEFILE, _O_LARGEFILE }, 71 { ArmLinux32::TGT_O_DIRECTORY, _O_DIRECTORY }, 72 { ArmLinux32::TGT_O_NOFOLLOW, _O_NOFOLLOW }, 73 { ArmLinux32::TGT_O_NOATIME, _O_NOATIME }, 74#ifdef _O_CLOEXEC 75 { ArmLinux32::TGT_O_CLOEXEC, _O_CLOEXEC }, 76#endif 77#ifdef _O_SYNC 78 { ArmLinux32::TGT_O_SYNC, _O_SYNC }, 79#endif 80#ifdef _O_PATH 81 { ArmLinux32::TGT_O_PATH, _O_PATH }, 82#endif 83#else /* !_MSC_VER */ 84 { ArmLinux32::TGT_O_RDONLY, O_RDONLY }, 85 { ArmLinux32::TGT_O_WRONLY, O_WRONLY }, 86 { ArmLinux32::TGT_O_RDWR, O_RDWR }, 87 { ArmLinux32::TGT_O_CREAT, O_CREAT }, 88 { ArmLinux32::TGT_O_EXCL, O_EXCL }, 89 { ArmLinux32::TGT_O_NOCTTY, O_NOCTTY }, 90 { ArmLinux32::TGT_O_TRUNC, O_TRUNC }, 91 { ArmLinux32::TGT_O_APPEND, O_APPEND }, 92 { ArmLinux32::TGT_O_NONBLOCK, O_NONBLOCK }, 93#ifdef O_DSYNC 94 { ArmLinux32::TGT_O_DSYNC, O_DSYNC }, 95#endif 96 { ArmLinux32::TGT_FASYNC, O_ASYNC }, 97#ifdef O_DIRECT 98 { ArmLinux32::TGT_O_DIRECT, O_DIRECT }, 99#endif 100#ifdef O_LARGEFILE 101 { ArmLinux32::TGT_O_LARGEFILE, O_LARGEFILE }, 102#endif 103#ifdef O_DIRECTORY 104 { ArmLinux32::TGT_O_DIRECTORY, O_DIRECTORY }, 105#endif 106#ifdef O_NOFOLLOW 107 { ArmLinux32::TGT_O_NOFOLLOW, O_NOFOLLOW }, 108#endif 109 { ArmLinux32::TGT_O_NOATIME, O_NOATIME }, 110#ifdef O_CLOEXEC 111 { ArmLinux32::TGT_O_CLOEXEC, O_CLOEXEC }, 112#endif 113#ifdef O_SYNC 114 { ArmLinux32::TGT_O_SYNC, O_SYNC }, 115#endif 116#ifdef O_PATH 117 { ArmLinux32::TGT_O_PATH, O_PATH }, 118#endif 119#endif /* _MSC_VER */ 120}; 121 122const int ArmLinux32::NUM_OPEN_FLAGS = sizeof(ArmLinux32::openFlagTable) / 123 sizeof(ArmLinux32::openFlagTable[0]); 124 125// mmap(2) flags translation table 126SyscallFlagTransTable ArmLinux32::mmapFlagTable[] = { 127 { ArmLinux32::TGT_MAP_SHARED, MAP_SHARED }, 128 { ArmLinux32::TGT_MAP_PRIVATE, MAP_PRIVATE }, 129 { ArmLinux32::TGT_MAP_ANON, MAP_ANON }, 130 { ArmLinux32::TGT_MAP_DENYWRITE, MAP_DENYWRITE }, 131 { ArmLinux32::TGT_MAP_EXECUTABLE, MAP_EXECUTABLE }, 132 { ArmLinux32::TGT_MAP_FILE, MAP_FILE }, 133 { ArmLinux32::TGT_MAP_GROWSDOWN, MAP_GROWSDOWN }, 134 { ArmLinux32::TGT_MAP_HUGETLB, MAP_HUGETLB }, 135 { ArmLinux32::TGT_MAP_LOCKED, MAP_LOCKED }, 136 { ArmLinux32::TGT_MAP_NONBLOCK, MAP_NONBLOCK }, 137 { ArmLinux32::TGT_MAP_NORESERVE, MAP_NORESERVE }, 138 { ArmLinux32::TGT_MAP_POPULATE, MAP_POPULATE }, 139#ifdef MAP_STACK 140 { ArmLinux32::TGT_MAP_STACK, MAP_STACK }, 141#endif 142 { ArmLinux32::TGT_MAP_ANONYMOUS, MAP_ANONYMOUS }, 143 { ArmLinux32::TGT_MAP_FIXED, MAP_FIXED }, 144}; 145 146const unsigned ArmLinux32::NUM_MMAP_FLAGS = 147 sizeof(ArmLinux32::mmapFlagTable) / 148 sizeof(ArmLinux32::mmapFlagTable[0]); 149 150// open(2) flags translation table 151SyscallFlagTransTable ArmLinux64::openFlagTable[] = { 152#ifdef _MSC_VER 153 { ArmLinux64::TGT_O_RDONLY, _O_RDONLY }, 154 { ArmLinux64::TGT_O_WRONLY, _O_WRONLY }, 155 { ArmLinux64::TGT_O_RDWR, _O_RDWR }, 156 { ArmLinux64::TGT_O_CREAT, _O_CREAT }, 157 { ArmLinux64::TGT_O_EXCL, _O_EXCL }, 158#ifdef _O_NOCTTY 159 { ArmLinux64::TGT_O_NOCTTY, _O_NOCTTY }, 160#endif 161 { ArmLinux64::TGT_O_TRUNC, _O_TRUNC }, 162 { ArmLinux64::TGT_O_APPEND, _O_APPEND }, 163#ifdef _O_NONBLOCK 164 { ArmLinux64::TGT_O_NONBLOCK, _O_NONBLOCK }, 165#endif 166#ifdef _O_DSYNC 167 { ArmLinux64::TGT_O_DSYNC, _O_DSYNC }, 168#endif 169 { ArmLinux64::TGT_FASYNC, _O_ASYNC }, 170 { ArmLinux64::TGT_O_DIRECT, _O_DIRECT }, 171 { ArmLinux64::TGT_O_LARGEFILE, _O_LARGEFILE }, 172 { ArmLinux64::TGT_O_DIRECTORY, _O_DIRECTORY }, 173 { ArmLinux64::TGT_O_NOFOLLOW, _O_NOFOLLOW }, 174 { ArmLinux64::TGT_O_NOATIME, _O_NOATIME }, 175#ifdef _O_CLOEXEC 176 { ArmLinux64::TGT_O_CLOEXEC, _O_CLOEXEC }, 177#endif 178#ifdef _O_SYNC 179 { ArmLinux64::TGT_O_SYNC, _O_SYNC }, 180#endif 181#ifdef _O_PATH 182 { ArmLinux64::TGT_O_PATH, _O_PATH }, 183#endif 184#else /* !_MSC_VER */ 185 { ArmLinux64::TGT_O_RDONLY, O_RDONLY }, 186 { ArmLinux64::TGT_O_WRONLY, O_WRONLY }, 187 { ArmLinux64::TGT_O_RDWR, O_RDWR }, 188 { ArmLinux64::TGT_O_CREAT, O_CREAT }, 189 { ArmLinux64::TGT_O_EXCL, O_EXCL }, 190 { ArmLinux64::TGT_O_NOCTTY, O_NOCTTY }, 191 { ArmLinux64::TGT_O_TRUNC, O_TRUNC }, 192 { ArmLinux64::TGT_O_APPEND, O_APPEND }, 193 { ArmLinux64::TGT_O_NONBLOCK, O_NONBLOCK }, 194 { ArmLinux64::TGT_O_DSYNC, O_DSYNC }, 195#ifdef FASYNC 196 { ArmLinux64::TGT_FASYNC, O_ASYNC }, 197#endif 198#ifdef O_DIRECT 199 { ArmLinux64::TGT_O_DIRECT, O_DIRECT }, 200#endif 201#ifdef O_LARGEFILE 202 { ArmLinux64::TGT_O_LARGEFILE, O_LARGEFILE }, 203#endif 204#ifdef O_DIRECTORY 205 { ArmLinux64::TGT_O_DIRECTORY, O_DIRECTORY }, 206#endif 207#ifdef O_NOFOLLOW 208 { ArmLinux64::TGT_O_NOFOLLOW, O_NOFOLLOW }, 209#endif 210 { ArmLinux64::TGT_O_NOATIME, O_NOATIME }, 211#ifdef O_CLOEXEC 212 { ArmLinux64::TGT_O_CLOEXEC, O_CLOEXEC }, 213#endif 214#ifdef O_SYNC 215 { ArmLinux64::TGT_O_SYNC, O_SYNC }, 216#endif 217#ifdef O_PATH 218 { ArmLinux64::TGT_O_PATH, O_PATH }, 219#endif 220#endif /* _MSC_VER */ 221}; 222 223const int ArmLinux64::NUM_OPEN_FLAGS = sizeof(ArmLinux64::openFlagTable) / 224 sizeof(ArmLinux64::openFlagTable[0]); 225 226// mmap(2) flags translation table 227SyscallFlagTransTable ArmLinux64::mmapFlagTable[] = { 228 { ArmLinux64::TGT_MAP_SHARED, MAP_SHARED }, 229 { ArmLinux64::TGT_MAP_PRIVATE, MAP_PRIVATE }, 230 { ArmLinux64::TGT_MAP_ANON, MAP_ANON }, 231 { ArmLinux64::TGT_MAP_DENYWRITE, MAP_DENYWRITE }, 232 { ArmLinux64::TGT_MAP_EXECUTABLE, MAP_EXECUTABLE }, 233 { ArmLinux64::TGT_MAP_FILE, MAP_FILE }, 234 { ArmLinux64::TGT_MAP_GROWSDOWN, MAP_GROWSDOWN }, 235 { ArmLinux64::TGT_MAP_HUGETLB, MAP_HUGETLB }, 236 { ArmLinux64::TGT_MAP_LOCKED, MAP_LOCKED }, 237 { ArmLinux64::TGT_MAP_NONBLOCK, MAP_NONBLOCK }, 238 { ArmLinux64::TGT_MAP_NORESERVE, MAP_NORESERVE }, 239 { ArmLinux64::TGT_MAP_POPULATE, MAP_POPULATE }, 240#ifdef MAP_STACK 241 { ArmLinux64::TGT_MAP_STACK, MAP_STACK }, 242#endif 243 { ArmLinux64::TGT_MAP_ANONYMOUS, MAP_ANONYMOUS }, 244 { ArmLinux64::TGT_MAP_FIXED, MAP_FIXED }, 245}; 246 247const unsigned ArmLinux64::NUM_MMAP_FLAGS = 248 sizeof(ArmLinux64::mmapFlagTable) / 249 sizeof(ArmLinux64::mmapFlagTable[0]); 250 251