Skip to content

Commit

Permalink
subproc/mount: use better types for flags, u64 for clone, unsigned lo…
Browse files Browse the repository at this point in the history
…ng for mount
  • Loading branch information
robertswiecki committed Oct 24, 2022
1 parent 2e62649 commit 285ea15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions mnt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ namespace mnt {
#define MS_LAZYTIME (1 << 25)
#endif /* if !defined(MS_LAZYTIME) */

static const std::string flagsToStr(uintptr_t flags) {
static const std::string flagsToStr(unsigned long flags) {
std::string res;

struct {
const uint64_t flag;
const unsigned long flag;
const char* const name;
} static const mountFlags[] = {
NS_VALSTR_STRUCT(MS_RDONLY),
Expand Down Expand Up @@ -92,7 +92,7 @@ static const std::string flagsToStr(uintptr_t flags) {
#endif /* defined(MS_NOUSER) */
};

uint64_t knownFlagMask = 0U;
unsigned knownFlagMask = 0U;
for (const auto& i : mountFlags) {
if (flags & i.flag) {
if (!res.empty()) {
Expand All @@ -104,7 +104,7 @@ static const std::string flagsToStr(uintptr_t flags) {
}

if (flags & ~(knownFlagMask)) {
util::StrAppend(&res, "|%#tx", flags & ~(knownFlagMask));
util::StrAppend(&res, "|%#lx", flags & ~(knownFlagMask));
}

return res;
Expand Down
12 changes: 6 additions & 6 deletions subproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace subproc {
#define CLONE_NEWTIME 0x00000080
#endif /* !defined(CLONE_NEWTIME) */

static const std::string cloneFlagsToStr(uintptr_t flags) {
static const std::string cloneFlagsToStr(uint64_t flags) {
std::string res;

struct {
Expand Down Expand Up @@ -112,7 +112,7 @@ static const std::string cloneFlagsToStr(uintptr_t flags) {
}

if (flags & ~(knownFlagMask)) {
util::StrAppend(&res, "|%#tx", flags & ~(knownFlagMask));
util::StrAppend(&res, "|%#" PRIx64, flags & ~(knownFlagMask));
}
return res;
}
Expand Down Expand Up @@ -445,7 +445,7 @@ pid_t runChild(nsjconf_t* nsjconf, int netfd, int fd_in, int fd_out, int fd_err)
if (!net::limitConns(nsjconf, netfd)) {
return 0;
}
unsigned long flags = 0UL;
uint64_t flags = 0UL;
flags |= (nsjconf->clone_newnet ? CLONE_NEWNET : 0);
flags |= (nsjconf->clone_newuser ? CLONE_NEWUSER : 0);
flags |= (nsjconf->clone_newns ? CLONE_NEWNS : 0);
Expand Down Expand Up @@ -527,7 +527,7 @@ static int cloneFunc(void* arg __attribute__((unused))) {
* update the internal PID/TID caches, what can lead to invalid values being returned by getpid()
* or incorrect PID/TIDs used in raise()/abort() functions
*/
pid_t cloneProc(uintptr_t flags, int exit_signal) {
pid_t cloneProc(uint64_t flags, int exit_signal) {
exit_signal &= CSIGNAL;

if (flags & CLONE_VM) {
Expand All @@ -544,7 +544,7 @@ pid_t cloneProc(uintptr_t flags, int exit_signal) {

#if defined(__NR_clone3)
struct clone_args ca = {};
ca.flags = (uint64_t)flags;
ca.flags = flags;
ca.exit_signal = (uint64_t)exit_signal;

pid_t ret = util::syscall(__NR_clone3, (uintptr_t)&ca, sizeof(ca));
Expand All @@ -568,7 +568,7 @@ pid_t cloneProc(uintptr_t flags, int exit_signal) {
*/
void* stack = &cloneStack[sizeof(cloneStack) / 2];
/* Parent */
return clone(cloneFunc, stack, flags | exit_signal, NULL, NULL, NULL);
return clone(cloneFunc, stack, (int)flags | exit_signal, NULL, NULL, NULL);
}
/* Child */
return 0;
Expand Down

2 comments on commit 285ea15

@jvvv
Copy link
Contributor

@jvvv jvvv commented on 285ea15 Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pid_t cloneProc(uintptr_t flags, int exit_signal);

Also need:
sed -i -e 's/cloneProc(uintptr_t /cloneProc(uint64_t /' subproc.h

Builds fine without on 64bit, but not on 32bit.

@robertswiecki
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added in fdc640e

Please sign in to comment.