Update Traditional Chinese translation for the binutils sub-directory.
[deliverable/binutils-gdb.git] / gdb / nat / linux-personality.c
CommitLineData
8cc73a39
SDJ
1/* Disable address space randomization based on inferior personality.
2
b811d2c2 3 Copyright (C) 2008-2020 Free Software Foundation, Inc.
8cc73a39
SDJ
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
268a13a5 20#include "gdbsupport/common-defs.h"
8cc73a39
SDJ
21#include "nat/linux-personality.h"
22
23#ifdef HAVE_PERSONALITY
24# include <sys/personality.h>
4c347be6 25# if !HAVE_DECL_ADDR_NO_RANDOMIZE
8cc73a39
SDJ
26# define ADDR_NO_RANDOMIZE 0x0040000
27# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
28#endif /* HAVE_PERSONALITY */
29
8cc73a39
SDJ
30/* See comment on nat/linux-personality.h. */
31
41272101 32maybe_disable_address_space_randomization::
8cc73a39 33maybe_disable_address_space_randomization (int disable_randomization)
41272101
TT
34 : m_personality_set (false),
35 m_personality_orig (0)
8cc73a39 36{
8cc73a39
SDJ
37#ifdef HAVE_PERSONALITY
38 if (disable_randomization)
39 {
40 errno = 0;
41272101
TT
41 m_personality_orig = personality (0xffffffff);
42 if (errno == 0 && !(m_personality_orig & ADDR_NO_RANDOMIZE))
8cc73a39 43 {
41272101
TT
44 m_personality_set = true;
45 personality (m_personality_orig | ADDR_NO_RANDOMIZE);
8cc73a39 46 }
41272101 47 if (errno != 0 || (m_personality_set
8cc73a39
SDJ
48 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
49 warning (_("Error disabling address space randomization: %s"),
50 safe_strerror (errno));
51 }
52#endif /* HAVE_PERSONALITY */
41272101
TT
53}
54
55maybe_disable_address_space_randomization::
56~maybe_disable_address_space_randomization ()
57{
58#ifdef HAVE_PERSONALITY
8cc73a39 59
41272101
TT
60 if (m_personality_set)
61 {
62 errno = 0;
63 personality (m_personality_orig);
64 if (errno != 0)
65 warning (_("Error restoring address space randomization: %s"),
66 safe_strerror (errno));
67 }
68#endif /* HAVE_PERSONALITY */
8cc73a39 69}
This page took 0.53081 seconds and 4 git commands to generate.