From: Zbigniew Jędrzejewski-Szmek Date: Tue, 22 May 2018 07:13:31 +0000 (+0200) Subject: systemd-nspawn: make SettingsMask 64 bit wide X-Git-Tag: v239~227^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b49c6ca089a3eb663e42aa55a06df8c1fea8543c;p=thirdparty%2Fsystemd.git systemd-nspawn: make SettingsMask 64 bit wide The use of UINT64_C() in the SettingsMask enum definition is misleading: it does not mean that individual fields have this width. E.g., with enum { FOO = UINT64_C(1) } sizeof(FOO) gives 4. It only means that the shift is done properly. So 1 << 35 is undefined, but UINT64_C(1) << 35 is the expected 64 bit constant. Thus, the use UINT64_C() is useful, because we know that the shifts are done properly, no matter what the value of _RLIMIT_MAX is, but when those fields are used in expressions, we don't know what size they will be (probably 4). Let's add a define which "hides" the enum definition behind a define which gives the same value but is actually 64 bit. I think this is a nicer solution than requiring all users to cast SETTING_RLIMIT_FIRST before use. Fixes #9035. --- diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h index c786bf8c86b..4e9cf3e3159 100644 --- a/src/nspawn/nspawn-settings.h +++ b/src/nspawn/nspawn-settings.h @@ -56,9 +56,19 @@ typedef enum SettingsMask { SETTING_CPU_AFFINITY = UINT64_C(1) << 20, SETTING_RLIMIT_FIRST = UINT64_C(1) << 21, /* we define one bit per resource limit here */ SETTING_RLIMIT_LAST = UINT64_C(1) << (21 + _RLIMIT_MAX - 1), - _SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1 + _SETTINGS_MASK_ALL = (UINT64_C(1) << (21 + _RLIMIT_MAX)) - 1, + _FORCE_ENUM_WIDTH = UINT64_MAX } SettingsMask; +/* We want to use SETTING_RLIMIT_FIRST in shifts, so make sure it is really 64 bits + * when used in expressions. */ +#define SETTING_RLIMIT_FIRST ((uint64_t) SETTING_RLIMIT_FIRST) +#define SETTING_RLIMIT_LAST ((uint64_t) SETTING_RLIMIT_LAST) + +assert_cc(sizeof(SettingsMask) == 8); +assert_cc(sizeof(SETTING_RLIMIT_FIRST) == 8); +assert_cc(sizeof(SETTING_RLIMIT_LAST) == 8); + typedef struct Settings { /* [Run] */ StartMode start_mode;