summaryrefslogtreecommitdiff
path: root/sys/src/9/port/sysproc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-02-01 10:16:55 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2014-02-01 10:16:55 +0100
commit7613608b23211a418cfe7404dbe2fcb3ee8b0cd7 (patch)
tree06a4176245dac3df98862e963bbeac52e11b3744 /sys/src/9/port/sysproc.c
parent88476df5416ba346c060727d38b9bc35c5f70015 (diff)
kernel: handle amd64 40 byte headers in exec()
Diffstat (limited to 'sys/src/9/port/sysproc.c')
-rw-r--r--sys/src/9/port/sysproc.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c
index 2b368e7ca..8f2ee849c 100644
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -243,7 +243,7 @@ sysexec(va_list list)
char *a, *charp, *args, *file, *file0;
char *progarg[sizeof(Exec)/2+1], *elem, progelem[64];
ulong magic, ssize, nargs, nbytes, n;
- uintptr t, d, b, entry, bssend, text, data, bss, tstk;
+ uintptr t, d, b, entry, bssend, text, data, bss, tstk, align;
int indir;
Exec exec;
char line[sizeof(Exec)];
@@ -266,6 +266,7 @@ sysexec(va_list list)
pexit(up->errstr, 1);
nexterror();
}
+ align = BY2PG;
indir = 0;
file = file0;
for(;;){
@@ -284,6 +285,10 @@ sysexec(va_list list)
text = l2be(exec.text);
entry = l2be(exec.entry);
if(n==sizeof(Exec) && (magic == AOUT_MAGIC)){
+ if(magic == S_MAGIC){
+ text += 8;
+ align = 0x200000ull; /* 2MB segment alignment for amd64 */
+ }
if(text >= (USTKTOP-USTKSIZE)-(UTZERO+sizeof(Exec))
|| entry < UTZERO+sizeof(Exec)
|| entry >= UTZERO+sizeof(Exec)+text)
@@ -318,10 +323,12 @@ sysexec(va_list list)
data = l2be(exec.data);
bss = l2be(exec.bss);
- t = (UTZERO+sizeof(Exec)+text+(BY2PG-1)) & ~(BY2PG-1);
- d = (t + data + (BY2PG-1)) & ~(BY2PG-1);
+ align--;
+ t = (UTZERO+sizeof(Exec)+text+align) & ~align;
+ align = BY2PG-1;
+ d = (t + data + align) & ~align;
bssend = t + data + bss;
- b = (bssend + (BY2PG-1)) & ~(BY2PG-1);
+ b = (bssend + align) & ~align;
if(t >= (USTKTOP-USTKSIZE) || d >= (USTKTOP-USTKSIZE) || b >= (USTKTOP-USTKSIZE))
error(Ebadexec);