2022-04-18 00:01:26 -07:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
2023-12-07 22:11:56 -05:00
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
2022-04-18 00:01:26 -07:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
|
|
|
│ │
|
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
|
|
#include "libc/calls/calls.h"
|
2023-06-03 08:12:13 -07:00
|
|
|
#include "libc/calls/prctl.internal.h"
|
2023-05-02 13:38:16 -07:00
|
|
|
#include "libc/calls/syscall-sysv.internal.h"
|
2022-08-13 13:11:56 -07:00
|
|
|
#include "libc/dce.h"
|
2022-04-18 00:01:26 -07:00
|
|
|
#include "libc/errno.h"
|
2022-06-25 18:17:31 -07:00
|
|
|
#include "libc/intrin/describeflags.internal.h"
|
2023-04-26 20:45:01 -07:00
|
|
|
#include "libc/intrin/strace.internal.h"
|
2022-04-18 08:54:42 -07:00
|
|
|
#include "libc/sysv/consts/pr.h"
|
2022-04-18 00:01:26 -07:00
|
|
|
#include "libc/sysv/errfuns.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tunes process on Linux.
|
|
|
|
*
|
2022-07-08 06:29:24 -07:00
|
|
|
* @raise ENOSYS on non-Linux
|
2022-04-18 00:01:26 -07:00
|
|
|
*/
|
2023-06-08 04:37:05 -07:00
|
|
|
int prctl(int operation, ...) {
|
2022-04-18 00:01:26 -07:00
|
|
|
int rc;
|
|
|
|
va_list va;
|
2022-07-23 12:06:41 -07:00
|
|
|
intptr_t a, b, c, d;
|
|
|
|
|
2022-04-18 00:01:26 -07:00
|
|
|
va_start(va, operation);
|
|
|
|
a = va_arg(va, intptr_t);
|
|
|
|
b = va_arg(va, intptr_t);
|
|
|
|
c = va_arg(va, intptr_t);
|
|
|
|
d = va_arg(va, intptr_t);
|
|
|
|
va_end(va);
|
2022-07-23 12:06:41 -07:00
|
|
|
|
2022-04-18 00:01:26 -07:00
|
|
|
if (IsLinux()) {
|
2023-06-03 08:12:13 -07:00
|
|
|
rc = sys_prctl(operation, a, b, c, d);
|
|
|
|
if (rc < 0) {
|
|
|
|
errno = -rc;
|
|
|
|
rc = -1;
|
|
|
|
}
|
2023-05-12 22:42:57 -07:00
|
|
|
} else {
|
|
|
|
rc = enosys();
|
|
|
|
}
|
2022-07-23 12:06:41 -07:00
|
|
|
|
2023-11-29 03:45:54 -08:00
|
|
|
#if SYSDEBUG
|
2022-07-23 12:06:41 -07:00
|
|
|
if (operation == PR_CAPBSET_READ || operation == PR_CAPBSET_DROP) {
|
|
|
|
STRACE("prctl(%s, %s) → %d% m", DescribePrctlOperation(operation),
|
|
|
|
DescribeCapability(a), rc);
|
|
|
|
} else {
|
|
|
|
STRACE("prctl(%s, %p, %p, %p, %p) → %d% m",
|
|
|
|
DescribePrctlOperation(operation), a, b, c, d, rc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-18 00:01:26 -07:00
|
|
|
return rc;
|
|
|
|
}
|