prctl: Add support for PR_SET_THP_DISABLE and PR_GET_THP_DISABLE

Change-Id: I04c5568a9eb78bcac632b734f34bba49cf602c4d
Refs: #1181
This commit is contained in:
Ken Sato
2018-12-12 15:41:32 +09:00
committed by Masamichi Takagi
parent eb184419ea
commit dfd23c3ebe
24 changed files with 773 additions and 1 deletions

View File

@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/prctl.h>
#define EXARG_MAX 64
#define CMD_MAX_LEN 1024
int main(int argc, char *argv[])
{
int rc = 0, i;
int thp_disable = 0;
char *exargv[EXARG_MAX] = {};
char *exenvp[1] = {NULL};
char execcmd[CMD_MAX_LEN] = {};
if (argc < 3) {
printf("err: too few arguments\n");
return -1;
}
if (argc > EXARG_MAX + 1) {
printf("err: too many arguments\n");
return -1;
}
thp_disable = atoi(argv[1]);
rc = prctl(PR_SET_THP_DISABLE, thp_disable, 0, 0, 0);
if (rc < 0) {
perror("err: PR_SET_THP_DISABLE");
}
printf("set thp_disable: %d\n", thp_disable);
for (i = 1; i < argc; i++) {
exargv[i - 2] = argv[i];
}
for (i = 0; i < EXARG_MAX; i++) {
if (!exargv[i]) {
break;
}
if (i != 0) {
strncat(execcmd, " ", CMD_MAX_LEN - 2);
}
strncat(execcmd, exargv[i], CMD_MAX_LEN - strlen(execcmd) - 1);
}
printf("exec: %s\n", execcmd);
execve(exargv[0], exargv, exenvp);
/* can't reach here */
printf("err: execve failed\n");
return -1;
}