@@ -68,7 +68,7 @@ static const char * abstract[] = {
68680 };
6969
7070static const char usage [] =
71- "Usage: shc [-e date] [-m addr] [-i iopt] [-x cmd] [-l lopt] [-o outfile] [-rvDSUHCABh ] -f script" ;
71+ "Usage: shc [-e date] [-m addr] [-i iopt] [-x cmd] [-l lopt] [-o outfile] [-rvDSUHCAB2h ] -f script" ;
7272
7373static const char * help [] = {
7474"" ,
@@ -89,6 +89,7 @@ static const char * help[] = {
8989" -C Display license and exit" ,
9090" -A Display abstract and exit" ,
9191" -B Compile for busybox" ,
92+ " -2 Use the system call mmap2" ,
9293" -h Display help and exit" ,
9394"" ,
9495" Environment variables used:" ,
@@ -142,6 +143,9 @@ static int TRACEABLE_flag = 1;
142143static const char HARDENING_line [] =
143144"#define HARDENING %d /* Define as 1 to disable ptrace/dump the executable */\n" ;
144145static int HARDENING_flag = 0 ;
146+ static const char MMAP2_line [] =
147+ "#define MMAP2 %d /* Define as 1 to use syscall mmap2 */\n" ;
148+ static int MMAP2_flag = 0 ;
145149static const char BUSYBOXON_line [] =
146150"#define BUSYBOXON %d /* Define as 1 to enable work with busybox */\n" ;
147151static int BUSYBOXON_flag = 0 ;
@@ -338,7 +342,11 @@ static const char * RTC[] = {
338342" /* list of allowed syscalls */" ,
339343" Allow(exit_group), /* exits a process */" ,
340344" Allow(brk), /* for malloc(), inside libc */" ,
345+ "#if MMAP2" ,
346+ " Allow(mmap2), /* also for malloc() */" ,
347+ "#else" ,
341348" Allow(mmap), /* also for malloc() */" ,
349+ "#endif" ,
342350" Allow(munmap), /* for free(), inside libc */" ,
343351"" ,
344352" /* and if we don't match above, die */" ,
@@ -751,7 +759,7 @@ static const char * RTC[] = {
751759static int parse_an_arg (int argc , char * argv [])
752760{
753761 extern char * optarg ;
754- const char * opts = "e:m:f:i:x:l:o:rvDSUHCABh " ;
762+ const char * opts = "e:m:f:i:x:l:o:rvDSUHCAB2h " ;
755763 struct tm tmp [1 ];
756764 time_t expdate ;
757765 int cnt , l ;
@@ -853,6 +861,9 @@ static int parse_an_arg(int argc, char * argv[])
853861 case 'B' :
854862 BUSYBOXON_flag = 1 ;
855863 break ;
864+ case '2' :
865+ MMAP2_flag = 1 ;
866+ break ;
856867 case ':' :
857868 fprintf (stderr , "%s parse: Missing parameter\n" , my_name );
858869 return -1 ;
@@ -1277,6 +1288,7 @@ int write_C(char * file, char * argv[])
12771288 fprintf (o , TRACEABLE_line , TRACEABLE_flag );
12781289 fprintf (o , HARDENING_line , HARDENING_flag );
12791290 fprintf (o , BUSYBOXON_line , BUSYBOXON_flag );
1291+ fprintf (o , MMAP2_line , MMAP2_flag );
12801292 for (indx = 0 ; RTC [indx ]; indx ++ )
12811293 fprintf (o , "%s\n" , RTC [indx ]);
12821294 fflush (o );
0 commit comments