forked from chaos/slurm-spank-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addr-no-randomize.c
114 lines (95 loc) · 3.1 KB
/
addr-no-randomize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*****************************************************************************
*
* Copyright (C) 2007-2008 Lawrence Livermore National Security, LLC.
* Produced at Lawrence Livermore National Laboratory.
* Written by Mark Grondona <[email protected]>.
*
* UCRL-CODE-235358
*
* This file is part of chaos-spankings, a set of spank plugins for SLURM.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <sys/personality.h>
#include <slurm/spank.h>
/*
* All spank plugins must define this macro for the SLURM plugin loader.
*/
SPANK_PLUGIN(no-randomize, 1);
#define ADDR_NO_RANDOMIZE 0x0040000
static int default_randomize = 0;
static int randomize = -1;
#define OPT_RANDOMIZE 1
#define OPT_NO_RANDOMIZE 2
static int process_opts (int val, const char *optarg, int remote);
/*
* Provide options to srun:
*/
struct spank_option spank_options[] =
{
{ "addr-randomize", NULL,
"Enable address space randomization", 0, OPT_RANDOMIZE,
(spank_opt_cb_f) process_opts
},
{ "no-addr-randomize", NULL,
"Disable address space randomization", 0, OPT_NO_RANDOMIZE,
(spank_opt_cb_f) process_opts
},
SPANK_OPTIONS_TABLE_END
};
/*
* Called from both srun and slurmd.
*/
int slurm_spank_init (spank_t sp, int ac, char **av)
{
int i;
for (i = 0; i < ac; i++) {
if (strncmp ("default_randomize=", av[i], 8) == 0) {
const char *optarg = av[i] + 18;
if (*optarg == '0')
default_randomize = 0;
else if (*optarg == '1')
default_randomize = 1;
else
slurm_error ("no-randomize: Ignoring invalid default value: "
"\"%s\"", av[i]);
}
else {
slurm_error ("no-randomize: Invalid option \"%s\"", av[i]);
}
}
randomize = default_randomize;
return (0);
}
static int process_opts (int val, const char *optarg, int remote)
{
if (val == OPT_RANDOMIZE)
randomize = 1;
else if (val == OPT_NO_RANDOMIZE)
randomize = 0;
else
randomize = default_randomize;
return (0);
}
int slurm_spank_task_init (spank_t sp, int ac, char **av)
{
if (randomize == -1)
randomize = default_randomize;
slurm_info ("randomize = %d\n", randomize);
if (randomize == 0 && (personality (ADDR_NO_RANDOMIZE) < 0))
slurm_error ("Failed to set personality: %m");
return 0;
}