-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgccrun
executable file
·61 lines (57 loc) · 1.07 KB
/
gccrun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
if [ "$#" = 0 ]; then
{
echo "usage: $0 [-w wrapper] <C code...>"
echo "CFLAGS environment variable is honored."
} >&2
exit 1
fi
if [ "$1" = -w ]; then
wrapper="$2"
shift 2
fi
f=$(mktemp -d -t gccrun.XXXXXXXX) || exit 1
cat > "$f/command.c" << EOF
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <linux/prctl.h> /* Definition of PR_* constants */
#include <sys/prctl.h>
int
main(int argc, char *argv[], char *envp[])
{
(void)argc;
(void)argv;
(void)envp;
$1;
return 0;
}
EOF
shift
# shellcheck disable=SC2086
if ! gcc $CFLAGS -o "$f/command" "$f/command.c" "$@"; then
exit 1
fi
if [ -n "$wrapper" ]; then
$wrapper "$f/command"
else
"$f/command"
fi
r=$?
rm -r "$f"
exit $r