From dddf3694e9566a7e304c3c91e8fc5cd5900d551f Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 30 Oct 2018 17:10:16 +0000 Subject: [PATCH] add O_MAYEXEC support for CLIP OS, zero cost otherwise cf. https://lwn.net/Articles/768819/ --- exec.c | 4 ++-- main.c | 6 +++--- sh.h | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 089091e..67d54be 100644 --- a/exec.c +++ b/exec.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.202 2018/10/07 01:10:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.203 2018/10/30 17:10:14 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" @@ -886,7 +886,7 @@ scriptexec(struct op *tp, const char **ap) *tp->args-- = tp->str; #ifndef MKSH_SMALL - if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) { + if ((fd = binopen2(tp->str, O_RDONLY | O_MAYEXEC)) >= 0) { unsigned char *cp; #ifndef MKSH_EBCDIC unsigned short m; diff --git a/main.c b/main.c index fbae4b2..7e05554 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.349 2018/05/08 17:37:36 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.350 2018/10/30 17:10:15 tg Exp $"); #ifndef MKSHRC_PATH #define MKSHRC_PATH "~/.mkshrc" @@ -513,7 +513,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) #else s->file = argv[argi++]; #endif - s->u.shf = shf_open(s->file, O_RDONLY, 0, + s->u.shf = shf_open(s->file, O_RDONLY | O_MAYEXEC, 0, SHF_MAPHI | SHF_CLEXEC); if (s->u.shf == NULL) { shl_stdout_ok = false; @@ -713,7 +713,7 @@ include(const char *name, int argc, const char **argv, bool intr_ok) volatile int old_argc; int i; - shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC); + shf = shf_open(name, O_RDONLY | O_MAYEXEC, 0, SHF_MAPHI | SHF_CLEXEC); if (shf == NULL) return (-1); diff --git a/sh.h b/sh.h index 1cec417..3ca8e55 100644 --- a/sh.h +++ b/sh.h @@ -182,7 +182,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.866 2018/10/20 18:45:58 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.867 2018/10/30 17:10:16 tg Exp $"); #endif #define MKSH_VERSION "R56 2018/10/20" @@ -491,6 +491,10 @@ extern int __cdecl setegid(gid_t); #define O_BINARY 0 #endif +#ifndef O_MAYEXEC +#define O_MAYEXEC 0 +#endif + #ifdef MKSH__NO_SYMLINK #undef S_ISLNK #define S_ISLNK(m) (/* CONSTCOND */ 0)