9ce345bc6de2a8c4a8fff4e1615f773bc8c51cad
1 /* Disable address space randomization based on inferior personality.
3 Copyright (C) 2008-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "gdbsupport/common-defs.h"
21 #include "nat/linux-personality.h"
23 #include <sys/personality.h>
25 /* See comment on nat/linux-personality.h. */
27 maybe_disable_address_space_randomization::
28 maybe_disable_address_space_randomization (int disable_randomization
)
29 : m_personality_set (false),
30 m_personality_orig (0)
32 if (disable_randomization
)
35 m_personality_orig
= personality (0xffffffff);
36 if (errno
== 0 && !(m_personality_orig
& ADDR_NO_RANDOMIZE
))
38 m_personality_set
= true;
39 personality (m_personality_orig
| ADDR_NO_RANDOMIZE
);
41 if (errno
!= 0 || (m_personality_set
42 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE
)))
43 warning (_("Error disabling address space randomization: %s"),
44 safe_strerror (errno
));
48 maybe_disable_address_space_randomization::
49 ~maybe_disable_address_space_randomization ()
51 if (m_personality_set
)
54 personality (m_personality_orig
);
56 warning (_("Error restoring address space randomization: %s"),
57 safe_strerror (errno
));
This page took 0.042963 seconds and 3 git commands to generate.