diff options
-rw-r--r-- | miscutils/taskset.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 100b1d926..fb352ab8d 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
@@ -75,27 +75,26 @@ static char *from_cpuset(cpu_set_t *mask) | |||
75 | #define TASKSET_PRINTF_MASK "%llx" | 75 | #define TASKSET_PRINTF_MASK "%llx" |
76 | static unsigned long long from_cpuset(cpu_set_t *mask) | 76 | static unsigned long long from_cpuset(cpu_set_t *mask) |
77 | { | 77 | { |
78 | char *p = (void*)mask; | 78 | BUILD_BUG_ON(CPU_SETSIZE < 8*sizeof(int)); |
79 | 79 | ||
80 | BUILD_BUG_ON(CPU_SETSIZE < sizeof(int)); | 80 | /* Take the least significant bits. Assume cpu_set_t is |
81 | 81 | * implemented as an array of unsigned long or unsigned | |
82 | /* Take the least significant bits. Careful! | 82 | * int. |
83 | * Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases | ||
84 | */ | 83 | */ |
85 | #if BB_BIG_ENDIAN | 84 | if (CPU_SETSIZE < 8*sizeof(long)) |
86 | /* For big endian, it means LAST bits */ | 85 | return *(unsigned*)mask; |
87 | if (CPU_SETSIZE < sizeof(long)) | 86 | if (CPU_SETSIZE < 8*sizeof(long long)) |
88 | p += CPU_SETSIZE - sizeof(int); | 87 | return *(unsigned long*)mask; |
89 | else if (CPU_SETSIZE < sizeof(long long)) | 88 | # if BB_BIG_ENDIAN |
90 | p += CPU_SETSIZE - sizeof(long); | 89 | if (sizeof(long long) > sizeof(long)) { |
91 | else | 90 | /* We can put two long in the long long, but they have to |
92 | p += CPU_SETSIZE - sizeof(long long); | 91 | * be swapped: the least significant word comes first in the |
93 | #endif | 92 | * array */ |
94 | if (CPU_SETSIZE < sizeof(long)) | 93 | unsigned long *p = (void*)mask; |
95 | return *(unsigned*)p; | 94 | return p[0] + ((unsigned long long)p[1] << (8*sizeof(long))); |
96 | if (CPU_SETSIZE < sizeof(long long)) | 95 | } |
97 | return *(unsigned long*)p; | 96 | # endif |
98 | return *(unsigned long long*)p; | 97 | return *(unsigned long long*)mask; |
99 | } | 98 | } |
100 | #endif | 99 | #endif |
101 | 100 | ||