Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/elfctl/elfctl.c
Show First 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | if (operation == '+') { | ||||
return (false); | return (false); | ||||
} | } | ||||
return (true); | return (true); | ||||
} | } | ||||
static bool | static bool | ||||
edit_file_features(Elf *elf, int phcount, int fd, char *val, bool endian_swap) | edit_file_features(Elf *elf, int phcount, int fd, char *val, bool endian_swap) | ||||
{ | { | ||||
uint32_t features; | uint32_t features, prev_features; | ||||
uint64_t off; | uint64_t off; | ||||
if (!get_file_features(elf, phcount, fd, &features, &off, | if (!get_file_features(elf, phcount, fd, &features, &off, | ||||
endian_swap)) { | endian_swap)) { | ||||
warnx("NT_FREEBSD_FEATURE_CTL note not found"); | warnx("NT_FREEBSD_FEATURE_CTL note not found"); | ||||
return (false); | return (false); | ||||
} | } | ||||
prev_features = features; | |||||
if (!convert_to_feature_val(val, &features)) | if (!convert_to_feature_val(val, &features)) | ||||
return (false); | return (false); | ||||
/* Avoid touching file if no change. */ | |||||
if (features == prev_features) | |||||
return (true); | |||||
if (endian_swap) | if (endian_swap) | ||||
features = bswap32(features); | features = bswap32(features); | ||||
if (lseek(fd, off, SEEK_SET) == -1 || | if (lseek(fd, off, SEEK_SET) == -1 || | ||||
write(fd, &features, sizeof(features)) < | write(fd, &features, sizeof(features)) < | ||||
markj: I am surprised that we do not use libelf to write the update. | |||||
Done Inline Actions
Yeah, we could; libelf doesn't really provide much in the way of convenience functions for accessing or modifying individual notes, but we could operate on the note section in memory and use libelf to write it back out. emaste: > I am surprised that we do not use libelf to write the update.
Yeah, we could; libelf doesn't… | |||||
(ssize_t)sizeof(features)) { | (ssize_t)sizeof(features)) { | ||||
warnx("error writing feature value"); | warnx("error writing feature value"); | ||||
return (false); | return (false); | ||||
} | } | ||||
return (true); | return (true); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |
I am surprised that we do not use libelf to write the update.