linux.hh (13537:2441d9a15e3c) linux.hh (13538:642e19fa9db8)
1/*
2 * Copyright (c) 2010, 2011-2012, 2015 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: Ali Saidi
42 * Stephen Hines
43 */
44
45#ifndef __ARCH_ARM_LINUX_LINUX_HH__
46#define __ARCH_ARM_LINUX_LINUX_HH__
47
48#include "arch/arm/utility.hh"
49#include "kern/linux/linux.hh"
50
51class ArmLinux : public Linux
52{
53 public:
54 static void
55 archClone(uint64_t flags,
56 Process *pp, Process *cp,
57 ThreadContext *ptc, ThreadContext *ctc,
58 uint64_t stack, uint64_t tls)
59 {
60 ArmISA::copyRegs(ptc, ctc);
1/*
2 * Copyright (c) 2010, 2011-2012, 2015 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: Ali Saidi
42 * Stephen Hines
43 */
44
45#ifndef __ARCH_ARM_LINUX_LINUX_HH__
46#define __ARCH_ARM_LINUX_LINUX_HH__
47
48#include "arch/arm/utility.hh"
49#include "kern/linux/linux.hh"
50
51class ArmLinux : public Linux
52{
53 public:
54 static void
55 archClone(uint64_t flags,
56 Process *pp, Process *cp,
57 ThreadContext *ptc, ThreadContext *ctc,
58 uint64_t stack, uint64_t tls)
59 {
60 ArmISA::copyRegs(ptc, ctc);
61
62 if (flags & TGT_CLONE_SETTLS) {
63 /* TPIDR_EL0 is architecturally mapped to TPIDRURW, so
64 * this works for both aarch32 and aarch64. */
65 ctc->setMiscReg(ArmISA::MISCREG_TPIDR_EL0, tls);
66 }
61 }
62};
63
64class ArmLinux32 : public ArmLinux
65{
66 public:
67
68 static const int TGT_SIGHUP = 0x000001;
69 static const int TGT_SIGINT = 0x000002;
70 static const int TGT_SIGQUIT = 0x000003;
71 static const int TGT_SIGILL = 0x000004;
72 static const int TGT_SIGTRAP = 0x000005;
73 static const int TGT_SIGABRT = 0x000006;
74 static const int TGT_SIGIOT = 0x000006;
75 static const int TGT_SIGBUS = 0x000007;
76 static const int TGT_SIGFPE = 0x000008;
77 static const int TGT_SIGKILL = 0x000009;
78 static const int TGT_SIGUSR1 = 0x00000a;
79 static const int TGT_SIGSEGV = 0x00000b;
80 static const int TGT_SIGUSR2 = 0x00000c;
81 static const int TGT_SIGPIPE = 0x00000d;
82 static const int TGT_SIGALRM = 0x00000e;
83 static const int TGT_SIGTERM = 0x00000f;
84 static const int TGT_SIGSTKFLT = 0x000010;
85 static const int TGT_SIGCHLD = 0x000011;
86 static const int TGT_SIGCONT = 0x000012;
87 static const int TGT_SIGSTOP = 0x000013;
88 static const int TGT_SIGTSTP = 0x000014;
89 static const int TGT_SIGTTIN = 0x000015;
90 static const int TGT_SIGTTOU = 0x000016;
91 static const int TGT_SIGURG = 0x000017;
92 static const int TGT_SIGXCPU = 0x000018;
93 static const int TGT_SIGXFSZ = 0x000019;
94 static const int TGT_SIGVTALRM = 0x00001a;
95 static const int TGT_SIGPROF = 0x00001b;
96 static const int TGT_SIGWINCH = 0x00001c;
97 static const int TGT_SIGIO = 0x00001d;
98 static const int TGT_SIGPOLL = 0x00001d;
99 static const int TGT_SIGPWR = 0x00001e;
100 static const int TGT_SIGSYS = 0x00001f;
101 static const int TGT_SIGUNUSED = 0x00001f;
102
103 /// This table maps the target open() flags to the corresponding
104 /// host open() flags.
105 static SyscallFlagTransTable openFlagTable[];
106
107 /// Number of entries in openFlagTable[].
108 static const int NUM_OPEN_FLAGS;
109
110 //@{
111 /// Basic ARM Linux types
112 typedef uint32_t size_t;
113 typedef uint32_t off_t;
114 typedef int32_t time_t;
115 typedef int32_t clock_t;
116 //@}
117
118 //@{
119 /// open(2) flag values.
120 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
121 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
122 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
123 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
124 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
125 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
126 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
127 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
128 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
129 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
130 static const int TGT_FASYNC = 000020000; //!< FASYNC
131 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
132 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
133 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
134 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
135 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
136 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
137 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
138 static const int TGT_O_PATH = 010000000; //!< O_PATH
139 //@}
140
141 static const unsigned TGT_MAP_SHARED = 0x00001;
142 static const unsigned TGT_MAP_PRIVATE = 0x00002;
143 static const unsigned TGT_MAP_ANON = 0x00020;
144 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
145 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
146 static const unsigned TGT_MAP_FILE = 0x00000;
147 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
148 static const unsigned TGT_MAP_HUGETLB = 0x40000;
149 static const unsigned TGT_MAP_LOCKED = 0x02000;
150 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
151 static const unsigned TGT_MAP_NORESERVE = 0x04000;
152 static const unsigned TGT_MAP_POPULATE = 0x08000;
153 static const unsigned TGT_MAP_STACK = 0x20000;
154 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
155 static const unsigned TGT_MAP_FIXED = 0x00010;
156
157 static const unsigned NUM_MMAP_FLAGS;
158
159 /// For table().
160 static const int TBL_SYSINFO = 12;
161
162 /// Limit struct for getrlimit/setrlimit.
163 struct rlimit {
164 uint32_t rlim_cur; //!< soft limit
165 uint32_t rlim_max; //!< hard limit
166 };
167
168 /// For gettimeofday().
169 struct timeval {
170 int32_t tv_sec; //!< seconds
171 int32_t tv_usec; //!< microseconds
172 };
173
174 struct timespec {
175 int32_t tv_sec; //!< seconds
176 int32_t tv_nsec; //!< nanoseconds
177 };
178
179 // For writev/readv
180 struct tgt_iovec {
181 uint32_t iov_base; // void *
182 uint32_t iov_len;
183 };
184
185
186 typedef struct {
187 uint32_t st_dev;
188 uint32_t st_ino;
189 uint16_t st_mode;
190 uint16_t st_nlink;
191 uint16_t st_uid;
192 uint16_t st_gid;
193 uint32_t st_rdev;
194 uint32_t __pad1;
195 uint32_t st_size;
196 uint32_t st_blksize;
197 uint32_t __pad2;
198 uint32_t st_blocks;
199 uint32_t st_atimeX;
200 uint32_t st_atime_nsec;
201 uint32_t st_mtimeX;
202 uint32_t st_mtime_nsec;
203 uint32_t st_ctimeX;
204 uint32_t st_ctime_nsec;
205 } tgt_stat;
206
207 typedef struct {
208 uint64_t st_dev;
209 uint8_t __pad0[4];
210 uint32_t __st_ino;
211 uint32_t st_mode;
212 uint32_t st_nlink;
213 uint32_t st_uid;
214 uint32_t st_gid;
215 uint64_t st_rdev;
216 uint8_t __pad3[4];
217 int64_t __attribute__ ((aligned (8))) st_size;
218 uint32_t st_blksize;
219 uint64_t __attribute__ ((aligned (8))) st_blocks;
220 uint32_t st_atimeX;
221 uint32_t st_atime_nsec;
222 uint32_t st_mtimeX;
223 uint32_t st_mtime_nsec;
224 uint32_t st_ctimeX;
225 uint32_t st_ctime_nsec;
226 uint64_t st_ino;
227 } tgt_stat64;
228
229 typedef struct {
230 int32_t uptime; /* Seconds since boot */
231 uint32_t loads[3]; /* 1, 5, and 15 minute load averages */
232 uint32_t totalram; /* Total usable main memory size */
233 uint32_t freeram; /* Available memory size */
234 uint32_t sharedram; /* Amount of shared memory */
235 uint32_t bufferram; /* Memory used by buffers */
236 uint32_t totalswap; /* Total swap space size */
237 uint32_t freeswap; /* swap space still available */
238 uint16_t procs; /* Number of current processes */
239 uint32_t totalhigh; /* Total high memory size */
240 uint32_t freehigh; /* Available high memory size */
241 uint32_t mem_unit; /* Memory unit size in bytes */
242 } tgt_sysinfo;
243
244 /// For getrusage().
245 struct rusage {
246 struct timeval ru_utime; //!< user time used
247 struct timeval ru_stime; //!< system time used
248 int32_t ru_maxrss; //!< max rss
249 int32_t ru_ixrss; //!< integral shared memory size
250 int32_t ru_idrss; //!< integral unshared data "
251 int32_t ru_isrss; //!< integral unshared stack "
252 int32_t ru_minflt; //!< page reclaims - total vmfaults
253 int32_t ru_majflt; //!< page faults
254 int32_t ru_nswap; //!< swaps
255 int32_t ru_inblock; //!< block input operations
256 int32_t ru_oublock; //!< block output operations
257 int32_t ru_msgsnd; //!< messages sent
258 int32_t ru_msgrcv; //!< messages received
259 int32_t ru_nsignals; //!< signals received
260 int32_t ru_nvcsw; //!< voluntary context switches
261 int32_t ru_nivcsw; //!< involuntary "
262 };
263
264 /// For times().
265 struct tms {
266 int32_t tms_utime; //!< user time
267 int32_t tms_stime; //!< system time
268 int32_t tms_cutime; //!< user time of children
269 int32_t tms_cstime; //!< system time of children
270 };
271
272 static void
273 archClone(uint64_t flags,
274 Process *pp, Process *cp,
275 ThreadContext *ptc, ThreadContext *ctc,
276 uint64_t stack, uint64_t tls)
277 {
278 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
279
280 if (stack)
281 ctc->setIntReg(ArmISA::INTREG_SP, stack);
282 }
283};
284
285class ArmLinux64 : public ArmLinux
286{
287 public:
288
289 static const int TGT_SIGHUP = 0x000001;
290 static const int TGT_SIGINT = 0x000002;
291 static const int TGT_SIGQUIT = 0x000003;
292 static const int TGT_SIGILL = 0x000004;
293 static const int TGT_SIGTRAP = 0x000005;
294 static const int TGT_SIGABRT = 0x000006;
295 static const int TGT_SIGIOT = 0x000006;
296 static const int TGT_SIGBUS = 0x000007;
297 static const int TGT_SIGFPE = 0x000008;
298 static const int TGT_SIGKILL = 0x000009;
299 static const int TGT_SIGUSR1 = 0x00000a;
300 static const int TGT_SIGSEGV = 0x00000b;
301 static const int TGT_SIGUSR2 = 0x00000c;
302 static const int TGT_SIGPIPE = 0x00000d;
303 static const int TGT_SIGALRM = 0x00000e;
304 static const int TGT_SIGTERM = 0x00000f;
305 static const int TGT_SIGSTKFLT = 0x000010;
306 static const int TGT_SIGCHLD = 0x000011;
307 static const int TGT_SIGCONT = 0x000012;
308 static const int TGT_SIGSTOP = 0x000013;
309 static const int TGT_SIGTSTP = 0x000014;
310 static const int TGT_SIGTTIN = 0x000015;
311 static const int TGT_SIGTTOU = 0x000016;
312 static const int TGT_SIGURG = 0x000017;
313 static const int TGT_SIGXCPU = 0x000018;
314 static const int TGT_SIGXFSZ = 0x000019;
315 static const int TGT_SIGVTALRM = 0x00001a;
316 static const int TGT_SIGPROF = 0x00001b;
317 static const int TGT_SIGWINCH = 0x00001c;
318 static const int TGT_SIGIO = 0x00001d;
319 static const int TGT_SIGPOLL = 0x00001d;
320 static const int TGT_SIGPWR = 0x00001e;
321 static const int TGT_SIGSYS = 0x00001f;
322 static const int TGT_SIGUNUSED = 0x00001f;
323
324 /// This table maps the target open() flags to the corresponding
325 /// host open() flags.
326 static SyscallFlagTransTable openFlagTable[];
327
328 /// Number of entries in openFlagTable[].
329 static const int NUM_OPEN_FLAGS;
330
331 //@{
332 /// Basic ARM Linux types
333 typedef uint64_t size_t;
334 typedef uint64_t off_t;
335 typedef int64_t time_t;
336 typedef int64_t clock_t;
337 //@}
338
339 //@{
340 /// open(2) flag values.
341 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
342 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
343 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
344 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
345 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
346 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
347 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
348 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
349 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
350 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
351 static const int TGT_FASYNC = 000020000; //!< FASYNC
352 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
353 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
354 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
355 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
356 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
357 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
358 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
359 static const int TGT_O_PATH = 010000000; //!< O_PATH
360 //@}
361
362 /// For mmap().
363 static SyscallFlagTransTable mmapFlagTable[];
364
365 static const unsigned TGT_MAP_SHARED = 0x00001;
366 static const unsigned TGT_MAP_PRIVATE = 0x00002;
367 static const unsigned TGT_MAP_ANON = 0x00020;
368 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
369 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
370 static const unsigned TGT_MAP_FILE = 0x00000;
371 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
372 static const unsigned TGT_MAP_HUGETLB = 0x40000;
373 static const unsigned TGT_MAP_LOCKED = 0x02000;
374 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
375 static const unsigned TGT_MAP_NORESERVE = 0x04000;
376 static const unsigned TGT_MAP_POPULATE = 0x08000;
377 static const unsigned TGT_MAP_STACK = 0x20000;
378 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
379 static const unsigned TGT_MAP_FIXED = 0x00010;
380
381 static const unsigned NUM_MMAP_FLAGS;
382
383 //@{
384 /// For getrusage().
385 static const int TGT_RUSAGE_SELF = 0;
386 static const int TGT_RUSAGE_CHILDREN = -1;
387 static const int TGT_RUSAGE_BOTH = -2;
388 //@}
389
390 //@{
391 /// ioctl() command codes.
392 static const unsigned TIOCGETP_ = 0x5401;
393 static const unsigned TIOCSETP_ = 0x80067409;
394 static const unsigned TIOCSETN_ = 0x8006740a;
395 static const unsigned TIOCSETC_ = 0x80067411;
396 static const unsigned TIOCGETC_ = 0x40067412;
397 static const unsigned FIONREAD_ = 0x4004667f;
398 static const unsigned TIOCISATTY_ = 0x2000745e;
399 static const unsigned TIOCGETS_ = 0x402c7413;
400 static const unsigned TIOCGETA_ = 0x5405;
401 static const unsigned TCSETAW_ = 0x5407; // 2.6.15 kernel
402 //@}
403
404 /// For table().
405 static const int TBL_SYSINFO = 12;
406
407 /// Resource enumeration for getrlimit().
408 enum rlimit_resources {
409 TGT_RLIMIT_CPU = 0,
410 TGT_RLIMIT_FSIZE = 1,
411 TGT_RLIMIT_DATA = 2,
412 TGT_RLIMIT_STACK = 3,
413 TGT_RLIMIT_CORE = 4,
414 TGT_RLIMIT_RSS = 5,
415 TGT_RLIMIT_NPROC = 6,
416 TGT_RLIMIT_NOFILE = 7,
417 TGT_RLIMIT_MEMLOCK = 8,
418 TGT_RLIMIT_AS = 9,
419 TGT_RLIMIT_LOCKS = 10
420 };
421
422 /// Limit struct for getrlimit/setrlimit.
423 struct rlimit {
424 uint64_t rlim_cur; //!< soft limit
425 uint64_t rlim_max; //!< hard limit
426 };
427
428 /// For gettimeofday().
429 struct timeval {
430 int64_t tv_sec; //!< seconds
431 int64_t tv_usec; //!< microseconds
432 };
433
434 struct timespec {
435 int64_t tv_sec; //!< seconds
436 int64_t tv_nsec; //!< nanoseconds
437 };
438
439 // For writev/readv
440 struct tgt_iovec {
441 uint64_t iov_base; // void *
442 uint64_t iov_len;
443 };
444
445 typedef struct {
446 uint64_t st_dev;
447 uint64_t st_ino;
448 uint64_t st_nlink;
449 uint32_t st_mode;
450 uint32_t st_uid;
451 uint32_t st_gid;
452 uint32_t __pad0;
453 uint64_t st_rdev;
454 uint64_t st_size;
455 uint64_t st_blksize;
456 uint64_t st_blocks;
457 uint64_t st_atimeX;
458 uint64_t st_atime_nsec;
459 uint64_t st_mtimeX;
460 uint64_t st_mtime_nsec;
461 uint64_t st_ctimeX;
462 uint64_t st_ctime_nsec;
463 } tgt_stat;
464
465 typedef struct {
466 uint64_t st_dev;
467 uint64_t st_ino;
468 uint32_t st_mode;
469 uint32_t st_nlink;
470 uint32_t st_uid;
471 uint32_t st_gid;
472 uint32_t __pad0;
473 uint64_t st_rdev;
474 uint64_t st_size;
475 uint64_t st_blksize;
476 uint64_t st_blocks;
477 uint64_t st_atimeX;
478 uint64_t st_atime_nsec;
479 uint64_t st_mtimeX;
480 uint64_t st_mtime_nsec;
481 uint64_t st_ctimeX;
482 uint64_t st_ctime_nsec;
483 } tgt_stat64;
484
485 typedef struct {
486 int64_t uptime; /* Seconds since boot */
487 uint64_t loads[3]; /* 1, 5, and 15 minute load averages */
488 uint64_t totalram; /* Total usable main memory size */
489 uint64_t freeram; /* Available memory size */
490 uint64_t sharedram; /* Amount of shared memory */
491 uint64_t bufferram; /* Memory used by buffers */
492 uint64_t totalswap; /* Total swap space size */
493 uint64_t freeswap; /* swap space still available */
494 uint16_t procs; /* Number of current processes */
495 uint16_t pad;
496 uint64_t totalhigh; /* Total high memory size */
497 uint64_t freehigh; /* Available high memory size */
498 uint32_t mem_unit; /* Memory unit size in bytes */
499 } tgt_sysinfo;
500
501 /// For getrusage().
502 struct rusage {
503 struct timeval ru_utime; //!< user time used
504 struct timeval ru_stime; //!< system time used
505 int64_t ru_maxrss; //!< max rss
506 int64_t ru_ixrss; //!< integral shared memory size
507 int64_t ru_idrss; //!< integral unshared data "
508 int64_t ru_isrss; //!< integral unshared stack "
509 int64_t ru_minflt; //!< page reclaims - total vmfaults
510 int64_t ru_majflt; //!< page faults
511 int64_t ru_nswap; //!< swaps
512 int64_t ru_inblock; //!< block input operations
513 int64_t ru_oublock; //!< block output operations
514 int64_t ru_msgsnd; //!< messages sent
515 int64_t ru_msgrcv; //!< messages received
516 int64_t ru_nsignals; //!< signals received
517 int64_t ru_nvcsw; //!< voluntary context switches
518 int64_t ru_nivcsw; //!< involuntary "
519 };
520
521 /// For times().
522 struct tms {
523 int64_t tms_utime; //!< user time
524 int64_t tms_stime; //!< system time
525 int64_t tms_cutime; //!< user time of children
526 int64_t tms_cstime; //!< system time of children
527 };
528
529 static void archClone(uint64_t flags,
530 Process *pp, Process *cp,
531 ThreadContext *ptc, ThreadContext *ctc,
532 uint64_t stack, uint64_t tls)
533 {
534 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
535
536 if (stack)
537 ctc->setIntReg(ArmISA::INTREG_SP0, stack);
538 }
539};
540
541#endif
67 }
68};
69
70class ArmLinux32 : public ArmLinux
71{
72 public:
73
74 static const int TGT_SIGHUP = 0x000001;
75 static const int TGT_SIGINT = 0x000002;
76 static const int TGT_SIGQUIT = 0x000003;
77 static const int TGT_SIGILL = 0x000004;
78 static const int TGT_SIGTRAP = 0x000005;
79 static const int TGT_SIGABRT = 0x000006;
80 static const int TGT_SIGIOT = 0x000006;
81 static const int TGT_SIGBUS = 0x000007;
82 static const int TGT_SIGFPE = 0x000008;
83 static const int TGT_SIGKILL = 0x000009;
84 static const int TGT_SIGUSR1 = 0x00000a;
85 static const int TGT_SIGSEGV = 0x00000b;
86 static const int TGT_SIGUSR2 = 0x00000c;
87 static const int TGT_SIGPIPE = 0x00000d;
88 static const int TGT_SIGALRM = 0x00000e;
89 static const int TGT_SIGTERM = 0x00000f;
90 static const int TGT_SIGSTKFLT = 0x000010;
91 static const int TGT_SIGCHLD = 0x000011;
92 static const int TGT_SIGCONT = 0x000012;
93 static const int TGT_SIGSTOP = 0x000013;
94 static const int TGT_SIGTSTP = 0x000014;
95 static const int TGT_SIGTTIN = 0x000015;
96 static const int TGT_SIGTTOU = 0x000016;
97 static const int TGT_SIGURG = 0x000017;
98 static const int TGT_SIGXCPU = 0x000018;
99 static const int TGT_SIGXFSZ = 0x000019;
100 static const int TGT_SIGVTALRM = 0x00001a;
101 static const int TGT_SIGPROF = 0x00001b;
102 static const int TGT_SIGWINCH = 0x00001c;
103 static const int TGT_SIGIO = 0x00001d;
104 static const int TGT_SIGPOLL = 0x00001d;
105 static const int TGT_SIGPWR = 0x00001e;
106 static const int TGT_SIGSYS = 0x00001f;
107 static const int TGT_SIGUNUSED = 0x00001f;
108
109 /// This table maps the target open() flags to the corresponding
110 /// host open() flags.
111 static SyscallFlagTransTable openFlagTable[];
112
113 /// Number of entries in openFlagTable[].
114 static const int NUM_OPEN_FLAGS;
115
116 //@{
117 /// Basic ARM Linux types
118 typedef uint32_t size_t;
119 typedef uint32_t off_t;
120 typedef int32_t time_t;
121 typedef int32_t clock_t;
122 //@}
123
124 //@{
125 /// open(2) flag values.
126 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
127 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
128 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
129 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
130 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
131 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
132 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
133 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
134 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
135 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
136 static const int TGT_FASYNC = 000020000; //!< FASYNC
137 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
138 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
139 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
140 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
141 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
142 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
143 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
144 static const int TGT_O_PATH = 010000000; //!< O_PATH
145 //@}
146
147 static const unsigned TGT_MAP_SHARED = 0x00001;
148 static const unsigned TGT_MAP_PRIVATE = 0x00002;
149 static const unsigned TGT_MAP_ANON = 0x00020;
150 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
151 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
152 static const unsigned TGT_MAP_FILE = 0x00000;
153 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
154 static const unsigned TGT_MAP_HUGETLB = 0x40000;
155 static const unsigned TGT_MAP_LOCKED = 0x02000;
156 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
157 static const unsigned TGT_MAP_NORESERVE = 0x04000;
158 static const unsigned TGT_MAP_POPULATE = 0x08000;
159 static const unsigned TGT_MAP_STACK = 0x20000;
160 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
161 static const unsigned TGT_MAP_FIXED = 0x00010;
162
163 static const unsigned NUM_MMAP_FLAGS;
164
165 /// For table().
166 static const int TBL_SYSINFO = 12;
167
168 /// Limit struct for getrlimit/setrlimit.
169 struct rlimit {
170 uint32_t rlim_cur; //!< soft limit
171 uint32_t rlim_max; //!< hard limit
172 };
173
174 /// For gettimeofday().
175 struct timeval {
176 int32_t tv_sec; //!< seconds
177 int32_t tv_usec; //!< microseconds
178 };
179
180 struct timespec {
181 int32_t tv_sec; //!< seconds
182 int32_t tv_nsec; //!< nanoseconds
183 };
184
185 // For writev/readv
186 struct tgt_iovec {
187 uint32_t iov_base; // void *
188 uint32_t iov_len;
189 };
190
191
192 typedef struct {
193 uint32_t st_dev;
194 uint32_t st_ino;
195 uint16_t st_mode;
196 uint16_t st_nlink;
197 uint16_t st_uid;
198 uint16_t st_gid;
199 uint32_t st_rdev;
200 uint32_t __pad1;
201 uint32_t st_size;
202 uint32_t st_blksize;
203 uint32_t __pad2;
204 uint32_t st_blocks;
205 uint32_t st_atimeX;
206 uint32_t st_atime_nsec;
207 uint32_t st_mtimeX;
208 uint32_t st_mtime_nsec;
209 uint32_t st_ctimeX;
210 uint32_t st_ctime_nsec;
211 } tgt_stat;
212
213 typedef struct {
214 uint64_t st_dev;
215 uint8_t __pad0[4];
216 uint32_t __st_ino;
217 uint32_t st_mode;
218 uint32_t st_nlink;
219 uint32_t st_uid;
220 uint32_t st_gid;
221 uint64_t st_rdev;
222 uint8_t __pad3[4];
223 int64_t __attribute__ ((aligned (8))) st_size;
224 uint32_t st_blksize;
225 uint64_t __attribute__ ((aligned (8))) st_blocks;
226 uint32_t st_atimeX;
227 uint32_t st_atime_nsec;
228 uint32_t st_mtimeX;
229 uint32_t st_mtime_nsec;
230 uint32_t st_ctimeX;
231 uint32_t st_ctime_nsec;
232 uint64_t st_ino;
233 } tgt_stat64;
234
235 typedef struct {
236 int32_t uptime; /* Seconds since boot */
237 uint32_t loads[3]; /* 1, 5, and 15 minute load averages */
238 uint32_t totalram; /* Total usable main memory size */
239 uint32_t freeram; /* Available memory size */
240 uint32_t sharedram; /* Amount of shared memory */
241 uint32_t bufferram; /* Memory used by buffers */
242 uint32_t totalswap; /* Total swap space size */
243 uint32_t freeswap; /* swap space still available */
244 uint16_t procs; /* Number of current processes */
245 uint32_t totalhigh; /* Total high memory size */
246 uint32_t freehigh; /* Available high memory size */
247 uint32_t mem_unit; /* Memory unit size in bytes */
248 } tgt_sysinfo;
249
250 /// For getrusage().
251 struct rusage {
252 struct timeval ru_utime; //!< user time used
253 struct timeval ru_stime; //!< system time used
254 int32_t ru_maxrss; //!< max rss
255 int32_t ru_ixrss; //!< integral shared memory size
256 int32_t ru_idrss; //!< integral unshared data "
257 int32_t ru_isrss; //!< integral unshared stack "
258 int32_t ru_minflt; //!< page reclaims - total vmfaults
259 int32_t ru_majflt; //!< page faults
260 int32_t ru_nswap; //!< swaps
261 int32_t ru_inblock; //!< block input operations
262 int32_t ru_oublock; //!< block output operations
263 int32_t ru_msgsnd; //!< messages sent
264 int32_t ru_msgrcv; //!< messages received
265 int32_t ru_nsignals; //!< signals received
266 int32_t ru_nvcsw; //!< voluntary context switches
267 int32_t ru_nivcsw; //!< involuntary "
268 };
269
270 /// For times().
271 struct tms {
272 int32_t tms_utime; //!< user time
273 int32_t tms_stime; //!< system time
274 int32_t tms_cutime; //!< user time of children
275 int32_t tms_cstime; //!< system time of children
276 };
277
278 static void
279 archClone(uint64_t flags,
280 Process *pp, Process *cp,
281 ThreadContext *ptc, ThreadContext *ctc,
282 uint64_t stack, uint64_t tls)
283 {
284 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
285
286 if (stack)
287 ctc->setIntReg(ArmISA::INTREG_SP, stack);
288 }
289};
290
291class ArmLinux64 : public ArmLinux
292{
293 public:
294
295 static const int TGT_SIGHUP = 0x000001;
296 static const int TGT_SIGINT = 0x000002;
297 static const int TGT_SIGQUIT = 0x000003;
298 static const int TGT_SIGILL = 0x000004;
299 static const int TGT_SIGTRAP = 0x000005;
300 static const int TGT_SIGABRT = 0x000006;
301 static const int TGT_SIGIOT = 0x000006;
302 static const int TGT_SIGBUS = 0x000007;
303 static const int TGT_SIGFPE = 0x000008;
304 static const int TGT_SIGKILL = 0x000009;
305 static const int TGT_SIGUSR1 = 0x00000a;
306 static const int TGT_SIGSEGV = 0x00000b;
307 static const int TGT_SIGUSR2 = 0x00000c;
308 static const int TGT_SIGPIPE = 0x00000d;
309 static const int TGT_SIGALRM = 0x00000e;
310 static const int TGT_SIGTERM = 0x00000f;
311 static const int TGT_SIGSTKFLT = 0x000010;
312 static const int TGT_SIGCHLD = 0x000011;
313 static const int TGT_SIGCONT = 0x000012;
314 static const int TGT_SIGSTOP = 0x000013;
315 static const int TGT_SIGTSTP = 0x000014;
316 static const int TGT_SIGTTIN = 0x000015;
317 static const int TGT_SIGTTOU = 0x000016;
318 static const int TGT_SIGURG = 0x000017;
319 static const int TGT_SIGXCPU = 0x000018;
320 static const int TGT_SIGXFSZ = 0x000019;
321 static const int TGT_SIGVTALRM = 0x00001a;
322 static const int TGT_SIGPROF = 0x00001b;
323 static const int TGT_SIGWINCH = 0x00001c;
324 static const int TGT_SIGIO = 0x00001d;
325 static const int TGT_SIGPOLL = 0x00001d;
326 static const int TGT_SIGPWR = 0x00001e;
327 static const int TGT_SIGSYS = 0x00001f;
328 static const int TGT_SIGUNUSED = 0x00001f;
329
330 /// This table maps the target open() flags to the corresponding
331 /// host open() flags.
332 static SyscallFlagTransTable openFlagTable[];
333
334 /// Number of entries in openFlagTable[].
335 static const int NUM_OPEN_FLAGS;
336
337 //@{
338 /// Basic ARM Linux types
339 typedef uint64_t size_t;
340 typedef uint64_t off_t;
341 typedef int64_t time_t;
342 typedef int64_t clock_t;
343 //@}
344
345 //@{
346 /// open(2) flag values.
347 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
348 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
349 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
350 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
351 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
352 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
353 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
354 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
355 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
356 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
357 static const int TGT_FASYNC = 000020000; //!< FASYNC
358 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
359 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
360 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
361 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
362 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
363 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
364 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
365 static const int TGT_O_PATH = 010000000; //!< O_PATH
366 //@}
367
368 /// For mmap().
369 static SyscallFlagTransTable mmapFlagTable[];
370
371 static const unsigned TGT_MAP_SHARED = 0x00001;
372 static const unsigned TGT_MAP_PRIVATE = 0x00002;
373 static const unsigned TGT_MAP_ANON = 0x00020;
374 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
375 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
376 static const unsigned TGT_MAP_FILE = 0x00000;
377 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
378 static const unsigned TGT_MAP_HUGETLB = 0x40000;
379 static const unsigned TGT_MAP_LOCKED = 0x02000;
380 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
381 static const unsigned TGT_MAP_NORESERVE = 0x04000;
382 static const unsigned TGT_MAP_POPULATE = 0x08000;
383 static const unsigned TGT_MAP_STACK = 0x20000;
384 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
385 static const unsigned TGT_MAP_FIXED = 0x00010;
386
387 static const unsigned NUM_MMAP_FLAGS;
388
389 //@{
390 /// For getrusage().
391 static const int TGT_RUSAGE_SELF = 0;
392 static const int TGT_RUSAGE_CHILDREN = -1;
393 static const int TGT_RUSAGE_BOTH = -2;
394 //@}
395
396 //@{
397 /// ioctl() command codes.
398 static const unsigned TIOCGETP_ = 0x5401;
399 static const unsigned TIOCSETP_ = 0x80067409;
400 static const unsigned TIOCSETN_ = 0x8006740a;
401 static const unsigned TIOCSETC_ = 0x80067411;
402 static const unsigned TIOCGETC_ = 0x40067412;
403 static const unsigned FIONREAD_ = 0x4004667f;
404 static const unsigned TIOCISATTY_ = 0x2000745e;
405 static const unsigned TIOCGETS_ = 0x402c7413;
406 static const unsigned TIOCGETA_ = 0x5405;
407 static const unsigned TCSETAW_ = 0x5407; // 2.6.15 kernel
408 //@}
409
410 /// For table().
411 static const int TBL_SYSINFO = 12;
412
413 /// Resource enumeration for getrlimit().
414 enum rlimit_resources {
415 TGT_RLIMIT_CPU = 0,
416 TGT_RLIMIT_FSIZE = 1,
417 TGT_RLIMIT_DATA = 2,
418 TGT_RLIMIT_STACK = 3,
419 TGT_RLIMIT_CORE = 4,
420 TGT_RLIMIT_RSS = 5,
421 TGT_RLIMIT_NPROC = 6,
422 TGT_RLIMIT_NOFILE = 7,
423 TGT_RLIMIT_MEMLOCK = 8,
424 TGT_RLIMIT_AS = 9,
425 TGT_RLIMIT_LOCKS = 10
426 };
427
428 /// Limit struct for getrlimit/setrlimit.
429 struct rlimit {
430 uint64_t rlim_cur; //!< soft limit
431 uint64_t rlim_max; //!< hard limit
432 };
433
434 /// For gettimeofday().
435 struct timeval {
436 int64_t tv_sec; //!< seconds
437 int64_t tv_usec; //!< microseconds
438 };
439
440 struct timespec {
441 int64_t tv_sec; //!< seconds
442 int64_t tv_nsec; //!< nanoseconds
443 };
444
445 // For writev/readv
446 struct tgt_iovec {
447 uint64_t iov_base; // void *
448 uint64_t iov_len;
449 };
450
451 typedef struct {
452 uint64_t st_dev;
453 uint64_t st_ino;
454 uint64_t st_nlink;
455 uint32_t st_mode;
456 uint32_t st_uid;
457 uint32_t st_gid;
458 uint32_t __pad0;
459 uint64_t st_rdev;
460 uint64_t st_size;
461 uint64_t st_blksize;
462 uint64_t st_blocks;
463 uint64_t st_atimeX;
464 uint64_t st_atime_nsec;
465 uint64_t st_mtimeX;
466 uint64_t st_mtime_nsec;
467 uint64_t st_ctimeX;
468 uint64_t st_ctime_nsec;
469 } tgt_stat;
470
471 typedef struct {
472 uint64_t st_dev;
473 uint64_t st_ino;
474 uint32_t st_mode;
475 uint32_t st_nlink;
476 uint32_t st_uid;
477 uint32_t st_gid;
478 uint32_t __pad0;
479 uint64_t st_rdev;
480 uint64_t st_size;
481 uint64_t st_blksize;
482 uint64_t st_blocks;
483 uint64_t st_atimeX;
484 uint64_t st_atime_nsec;
485 uint64_t st_mtimeX;
486 uint64_t st_mtime_nsec;
487 uint64_t st_ctimeX;
488 uint64_t st_ctime_nsec;
489 } tgt_stat64;
490
491 typedef struct {
492 int64_t uptime; /* Seconds since boot */
493 uint64_t loads[3]; /* 1, 5, and 15 minute load averages */
494 uint64_t totalram; /* Total usable main memory size */
495 uint64_t freeram; /* Available memory size */
496 uint64_t sharedram; /* Amount of shared memory */
497 uint64_t bufferram; /* Memory used by buffers */
498 uint64_t totalswap; /* Total swap space size */
499 uint64_t freeswap; /* swap space still available */
500 uint16_t procs; /* Number of current processes */
501 uint16_t pad;
502 uint64_t totalhigh; /* Total high memory size */
503 uint64_t freehigh; /* Available high memory size */
504 uint32_t mem_unit; /* Memory unit size in bytes */
505 } tgt_sysinfo;
506
507 /// For getrusage().
508 struct rusage {
509 struct timeval ru_utime; //!< user time used
510 struct timeval ru_stime; //!< system time used
511 int64_t ru_maxrss; //!< max rss
512 int64_t ru_ixrss; //!< integral shared memory size
513 int64_t ru_idrss; //!< integral unshared data "
514 int64_t ru_isrss; //!< integral unshared stack "
515 int64_t ru_minflt; //!< page reclaims - total vmfaults
516 int64_t ru_majflt; //!< page faults
517 int64_t ru_nswap; //!< swaps
518 int64_t ru_inblock; //!< block input operations
519 int64_t ru_oublock; //!< block output operations
520 int64_t ru_msgsnd; //!< messages sent
521 int64_t ru_msgrcv; //!< messages received
522 int64_t ru_nsignals; //!< signals received
523 int64_t ru_nvcsw; //!< voluntary context switches
524 int64_t ru_nivcsw; //!< involuntary "
525 };
526
527 /// For times().
528 struct tms {
529 int64_t tms_utime; //!< user time
530 int64_t tms_stime; //!< system time
531 int64_t tms_cutime; //!< user time of children
532 int64_t tms_cstime; //!< system time of children
533 };
534
535 static void archClone(uint64_t flags,
536 Process *pp, Process *cp,
537 ThreadContext *ptc, ThreadContext *ctc,
538 uint64_t stack, uint64_t tls)
539 {
540 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
541
542 if (stack)
543 ctc->setIntReg(ArmISA::INTREG_SP0, stack);
544 }
545};
546
547#endif