diff options
author | 2023-10-10 14:33:42 +0000 | |
---|---|---|
committer | 2023-10-10 14:33:42 +0000 | |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms')
8 files changed, 568 insertions, 0 deletions
diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/applink.c b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/applink.c new file mode 100644 index 000000000..238dbff35 --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/applink.c @@ -0,0 +1,138 @@ +/* + * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#define APPLINK_STDIN 1 +#define APPLINK_STDOUT 2 +#define APPLINK_STDERR 3 +#define APPLINK_FPRINTF 4 +#define APPLINK_FGETS 5 +#define APPLINK_FREAD 6 +#define APPLINK_FWRITE 7 +#define APPLINK_FSETMOD 8 +#define APPLINK_FEOF 9 +#define APPLINK_FCLOSE 10 /* should not be used */ + +#define APPLINK_FOPEN 11 /* solely for completeness */ +#define APPLINK_FSEEK 12 +#define APPLINK_FTELL 13 +#define APPLINK_FFLUSH 14 +#define APPLINK_FERROR 15 +#define APPLINK_CLEARERR 16 +#define APPLINK_FILENO 17 /* to be used with below */ + +#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */ +#define APPLINK_READ 19 +#define APPLINK_WRITE 20 +#define APPLINK_LSEEK 21 +#define APPLINK_CLOSE 22 +#define APPLINK_MAX 22 /* always same as last macro */ + +#ifndef APPMACROS_ONLY +# include <stdio.h> +# include <io.h> +# include <fcntl.h> + +static void *app_stdin(void) +{ + return stdin; +} + +static void *app_stdout(void) +{ + return stdout; +} + +static void *app_stderr(void) +{ + return stderr; +} + +static int app_feof(FILE *fp) +{ + return feof(fp); +} + +static int app_ferror(FILE *fp) +{ + return ferror(fp); +} + +static void app_clearerr(FILE *fp) +{ + clearerr(fp); +} + +static int app_fileno(FILE *fp) +{ + return _fileno(fp); +} + +static int app_fsetmod(FILE *fp, char mod) +{ + return _setmode(_fileno(fp), mod == 'b' ? _O_BINARY : _O_TEXT); +} + +#ifdef __cplusplus +extern "C" { +#endif + +__declspec(dllexport) +void ** +# if defined(__BORLANDC__) +/* + * __stdcall appears to be the only way to get the name + * decoration right with Borland C. Otherwise it works + * purely incidentally, as we pass no parameters. + */ +__stdcall +# else +__cdecl +# endif +OPENSSL_Applink(void) +{ + static int once = 1; + static void *OPENSSL_ApplinkTable[APPLINK_MAX + 1] = + { (void *)APPLINK_MAX }; + + if (once) { + OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin; + OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout; + OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr; + OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf; + OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets; + OPENSSL_ApplinkTable[APPLINK_FREAD] = fread; + OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite; + OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod; + OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof; + OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose; + + OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen; + OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek; + OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell; + OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush; + OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror; + OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr; + OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno; + + OPENSSL_ApplinkTable[APPLINK_OPEN] = _open; + OPENSSL_ApplinkTable[APPLINK_READ] = _read; + OPENSSL_ApplinkTable[APPLINK_WRITE] = _write; + OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek; + OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close; + + once = 0; + } + + return OPENSSL_ApplinkTable; +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/cmp.pl b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/cmp.pl new file mode 100755 index 000000000..265ce56ed --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/cmp.pl @@ -0,0 +1,53 @@ +#! /usr/bin/env perl +# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +($#ARGV == 1) || die "usage: cmp.pl <file1> <file2>\n"; + +open(IN0,"<$ARGV[0]") || die "unable to open $ARGV[0]\n"; +open(IN1,"<$ARGV[1]") || die "unable to open $ARGV[1]\n"; +binmode IN0; +binmode IN1; + +$tot=0; +$ret=1; +for (;;) +{ + $n1=sysread(IN0,$b1,4096); + $n2=sysread(IN1,$b2,4096); + + last if ($n1 != $n2); + last if ($b1 ne $b2); + last if ($n1 < 0); + if ($n1 == 0) + { + $ret=0; + last; + } + $tot+=$n1; +} + +close(IN0); +close(IN1); +if ($ret) +{ + printf STDERR "$ARGV[0] and $ARGV[1] are different\n"; + @a1=unpack("C*",$b1); + @a2=unpack("C*",$b2); + for ($i=0; $i<=$#a1; $i++) + { + if ($a1[$i] ne $a2[$i]) + { + printf "%02X %02X <<\n",$a1[$i],$a2[$i]; + last; + } + } + $nm=$tot+$n1; + $tot+=$i+1; + printf STDERR "diff at char $tot of $nm\n"; +} +exit($ret); diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-common.pl b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-common.pl new file mode 100755 index 000000000..e2ab59456 --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-common.pl @@ -0,0 +1,28 @@ +#! /usr/bin/env perl +# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +# pull APPLINK_MAX value from applink.c... +$applink_c=$0; +$applink_c=~s|[^/\\]+$||g; +$applink_c.="applink.c"; +open(INPUT,$applink_c) || die "can't open $applink_c: $!"; +@max=grep {/APPLINK_MAX\s+(\d+)/} <INPUT>; +close(INPUT); +($#max==0) or die "can't find APPLINK_MAX in $applink_c"; + +$max[0]=~/APPLINK_MAX\s+(\d+)/; +$N=$1; # number of entries in OPENSSL_UplinkTable not including + # OPENSSL_UplinkTable[0], which contains this value... + +1; + +# Idea is to fill the OPENSSL_UplinkTable with pointers to stubs +# which invoke 'void OPENSSL_Uplink (ULONG_PTR *table,int index)'; +# and then dereference themselves. Latter shall result in endless +# loop *unless* OPENSSL_Uplink does not replace 'table[index]' with +# something else, e.g. as 'table[index]=unimplemented;'... diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-ia64.pl b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-ia64.pl new file mode 100755 index 000000000..0636f13e7 --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-ia64.pl @@ -0,0 +1,61 @@ +#! /usr/bin/env perl +# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +$output = pop; +open STDOUT,">$output"; + +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +push(@INC,"${dir}."); + +require "uplink-common.pl"; + +local $V=8; # max number of args uplink functions may accept... +my $loc0 = "r".(32+$V); +print <<___; +.text +.global OPENSSL_Uplink# +.type OPENSSL_Uplink#,\@function + +___ +for ($i=1;$i<=$N;$i++) { +print <<___; +.proc lazy$i# +lazy$i: + .prologue +{ .mii; .save ar.pfs,$loc0 + alloc loc0=ar.pfs,$V,3,2,0 + .save b0,loc1 + mov loc1=b0 + addl loc2=\@ltoff(OPENSSL_UplinkTable#),gp };; + .body +{ .mmi; ld8 out0=[loc2] + mov out1=$i };; +{ .mib; add loc2=8*$i,out0 + br.call.sptk.many b0=OPENSSL_Uplink# };; +{ .mmi; ld8 r31=[loc2];; + ld8 r30=[r31],8 };; +{ .mii; ld8 gp=[r31] + mov b6=r30 + mov b0=loc1 };; +{ .mib; mov ar.pfs=loc0 + br.many b6 };; +.endp lazy$i# + +___ +} +print <<___; +.data +.global OPENSSL_UplinkTable# +OPENSSL_UplinkTable: data8 $N // amount of following entries +___ +for ($i=1;$i<=$N;$i++) { print " data8 \@fptr(lazy$i#)\n"; } +print <<___; +.size OPENSSL_UplinkTable,.-OPENSSL_UplinkTable# +___ + +close STDOUT; diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86.pl b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86.pl new file mode 100755 index 000000000..e79cff72d --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86.pl @@ -0,0 +1,44 @@ +#! /usr/bin/env perl +# Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +push(@INC, "${dir}.", "${dir}../crypto/perlasm"); +require "x86asm.pl"; + +require "uplink-common.pl"; + +$output = pop; +open STDOUT,">$output"; + +&asm_init($ARGV[0]); + +&external_label("OPENSSL_Uplink"); +&public_label("OPENSSL_UplinkTable"); + +for ($i=1;$i<=$N;$i++) { +&function_begin_B("_\$lazy${i}"); + &lea ("eax",&DWP(&label("OPENSSL_UplinkTable"))); + &push ($i); + &push ("eax"); + &call (&label("OPENSSL_Uplink")); + &pop ("eax"); + &add ("esp",4); + &jmp_ptr(&DWP(4*$i,"eax")); +&function_end_B("_\$lazy${i}"); +} + +&dataseg(); +&align(4); +&set_label("OPENSSL_UplinkTable"); +&data_word($N); +for ($i=1;$i<=$N;$i++) { +&data_word(&label("_\$lazy${i}")); +} +&asm_finish(); + +close STDOUT; diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86_64.pl b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86_64.pl new file mode 100755 index 000000000..1f244504c --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink-x86_64.pl @@ -0,0 +1,71 @@ +#! /usr/bin/env perl +# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +$output=pop; +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +open OUT,"| \"$^X\" \"${dir}../crypto/perlasm/x86_64-xlate.pl\" \"$output\""; +*STDOUT=*OUT; +push(@INC,"${dir}."); + +require "uplink-common.pl"; + +$prefix="_lazy"; + +print <<___; +.text +.extern OPENSSL_Uplink +.globl OPENSSL_UplinkTable +___ +for ($i=1;$i<=$N;$i++) { +print <<___; +.type $prefix${i},\@abi-omnipotent +.align 16 +$prefix${i}: + .byte 0x48,0x83,0xEC,0x28 # sub rsp,40 + mov %rcx,48(%rsp) + mov %rdx,56(%rsp) + mov %r8,64(%rsp) + mov %r9,72(%rsp) + lea OPENSSL_UplinkTable(%rip),%rcx + mov \$$i,%rdx + call OPENSSL_Uplink + mov 48(%rsp),%rcx + mov 56(%rsp),%rdx + mov 64(%rsp),%r8 + mov 72(%rsp),%r9 + lea OPENSSL_UplinkTable(%rip),%rax + add \$40,%rsp + jmp *8*$i(%rax) +$prefix${i}_end: +.size $prefix${i},.-$prefix${i} +___ +} +print <<___; +.data +OPENSSL_UplinkTable: + .quad $N +___ +for ($i=1;$i<=$N;$i++) { print " .quad $prefix$i\n"; } +print <<___; +.section .pdata,"r" +.align 4 +___ +for ($i=1;$i<=$N;$i++) { +print <<___; + .rva $prefix${i},$prefix${i}_end,${prefix}_unwind_info +___ +} +print <<___; +.section .xdata,"r" +.align 8 +${prefix}_unwind_info: + .byte 0x01,0x04,0x01,0x00 + .byte 0x04,0x42,0x00,0x00 +___ + +close STDOUT; diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.c b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.c new file mode 100644 index 000000000..cd4e96b78 --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.c @@ -0,0 +1,135 @@ +/* + * Copyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#if (defined(_WIN64) || defined(_WIN32_WCE)) && !defined(UNICODE) +# define UNICODE +#endif +#if defined(UNICODE) && !defined(_UNICODE) +# define _UNICODE +#endif +#if defined(_UNICODE) && !defined(UNICODE) +# define UNICODE +#endif + +#include <windows.h> +#include <tchar.h> +#include <stdio.h> +#include "uplink.h" +void OPENSSL_showfatal(const char *, ...); + +static TCHAR msg[128]; + +static void unimplemented(void) +{ + OPENSSL_showfatal(sizeof(TCHAR) == sizeof(char) ? "%s\n" : "%S\n", msg); + TerminateProcess(GetCurrentProcess(), 1); +} + +void OPENSSL_Uplink(volatile void **table, int index) +{ + static HMODULE volatile apphandle = NULL; + static void **volatile applinktable = NULL; + int len; + void (*func) (void) = unimplemented; + HANDLE h; + void **p; + + /* + * Note that the below code is not MT-safe in respect to msg buffer, but + * what's the worst thing that can happen? Error message might be + * misleading or corrupted. As error condition is fatal and should never + * be risen, I accept the risk... + */ + /* + * One can argue that I should have used InterlockedExchangePointer or + * something to update static variables and table[]. Well, store + * instructions are as atomic as they can get and assigned values are + * effectively constant... So that volatile qualifier should be + * sufficient [it prohibits compiler to reorder memory access + * instructions]. + */ + do { + len = _sntprintf(msg, sizeof(msg) / sizeof(TCHAR), + _T("OPENSSL_Uplink(%p,%02X): "), table, index); + _tcscpy(msg + len, _T("unimplemented function")); + + if ((h = apphandle) == NULL) { + if ((h = GetModuleHandle(NULL)) == NULL) { + apphandle = (HMODULE) - 1; + _tcscpy(msg + len, _T("no host application")); + break; + } + apphandle = h; + } + if ((h = apphandle) == (HMODULE) - 1) /* revalidate */ + break; + + if (applinktable == NULL) { + void **(*applink) (); + + applink = (void **(*)())GetProcAddress(h, "OPENSSL_Applink"); + if (applink == NULL) { + apphandle = (HMODULE) - 1; + _tcscpy(msg + len, _T("no OPENSSL_Applink")); + break; + } + p = (*applink) (); + if (p == NULL) { + apphandle = (HMODULE) - 1; + _tcscpy(msg + len, _T("no ApplinkTable")); + break; + } + applinktable = p; + } else + p = applinktable; + + if (index > (int)p[0]) + break; + + if (p[index]) + func = p[index]; + } while (0); + + table[index] = func; +} + +#if defined(_MSC_VER) && defined(_M_IX86) +# define LAZY(i) \ +__declspec(naked) static void lazy##i (void) { \ + _asm push i \ + _asm push OFFSET OPENSSL_UplinkTable \ + _asm call OPENSSL_Uplink \ + _asm add esp,8 \ + _asm jmp OPENSSL_UplinkTable+4*i } + +# if APPLINK_MAX>25 +# error "Add more stubs..." +# endif +/* make some in advance... */ +LAZY(1) LAZY(2) LAZY(3) LAZY(4) LAZY(5) + LAZY(6) LAZY(7) LAZY(8) LAZY(9) LAZY(10) + LAZY(11) LAZY(12) LAZY(13) LAZY(14) LAZY(15) + LAZY(16) LAZY(17) LAZY(18) LAZY(19) LAZY(20) + LAZY(21) LAZY(22) LAZY(23) LAZY(24) LAZY(25) +void *OPENSSL_UplinkTable[] = { + (void *)APPLINK_MAX, + lazy1, lazy2, lazy3, lazy4, lazy5, + lazy6, lazy7, lazy8, lazy9, lazy10, + lazy11, lazy12, lazy13, lazy14, lazy15, + lazy16, lazy17, lazy18, lazy19, lazy20, + lazy21, lazy22, lazy23, lazy24, lazy25, +}; +#endif + +#ifdef SELFTEST +main() +{ + UP_fprintf(UP_stdout, "hello, world!\n"); +} +#endif diff --git a/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.h b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.h new file mode 100644 index 000000000..f6cd0380a --- /dev/null +++ b/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/ms/uplink.h @@ -0,0 +1,38 @@ +/* + * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#define APPMACROS_ONLY +#include "applink.c" + +extern void *OPENSSL_UplinkTable[]; + +#define UP_stdin (*(void *(*)(void))OPENSSL_UplinkTable[APPLINK_STDIN])() +#define UP_stdout (*(void *(*)(void))OPENSSL_UplinkTable[APPLINK_STDOUT])() +#define UP_stderr (*(void *(*)(void))OPENSSL_UplinkTable[APPLINK_STDERR])() +#define UP_fprintf (*(int (*)(void *,const char *,...))OPENSSL_UplinkTable[APPLINK_FPRINTF]) +#define UP_fgets (*(char *(*)(char *,int,void *))OPENSSL_UplinkTable[APPLINK_FGETS]) +#define UP_fread (*(size_t (*)(void *,size_t,size_t,void *))OPENSSL_UplinkTable[APPLINK_FREAD]) +#define UP_fwrite (*(size_t (*)(const void *,size_t,size_t,void *))OPENSSL_UplinkTable[APPLINK_FWRITE]) +#define UP_fsetmod (*(int (*)(void *,char))OPENSSL_UplinkTable[APPLINK_FSETMOD]) +#define UP_feof (*(int (*)(void *))OPENSSL_UplinkTable[APPLINK_FEOF]) +#define UP_fclose (*(int (*)(void *))OPENSSL_UplinkTable[APPLINK_FCLOSE]) + +#define UP_fopen (*(void *(*)(const char *,const char *))OPENSSL_UplinkTable[APPLINK_FOPEN]) +#define UP_fseek (*(int (*)(void *,long,int))OPENSSL_UplinkTable[APPLINK_FSEEK]) +#define UP_ftell (*(long (*)(void *))OPENSSL_UplinkTable[APPLINK_FTELL]) +#define UP_fflush (*(int (*)(void *))OPENSSL_UplinkTable[APPLINK_FFLUSH]) +#define UP_ferror (*(int (*)(void *))OPENSSL_UplinkTable[APPLINK_FERROR]) +#define UP_clearerr (*(void (*)(void *))OPENSSL_UplinkTable[APPLINK_CLEARERR]) +#define UP_fileno (*(int (*)(void *))OPENSSL_UplinkTable[APPLINK_FILENO]) + +#define UP_open (*(int (*)(const char *,int,...))OPENSSL_UplinkTable[APPLINK_OPEN]) +#define UP_read (*(ossl_ssize_t (*)(int,void *,size_t))OPENSSL_UplinkTable[APPLINK_READ]) +#define UP_write (*(ossl_ssize_t (*)(int,const void *,size_t))OPENSSL_UplinkTable[APPLINK_WRITE]) +#define UP_lseek (*(long (*)(int,long,int))OPENSSL_UplinkTable[APPLINK_LSEEK]) +#define UP_close (*(int (*)(int))OPENSSL_UplinkTable[APPLINK_CLOSE]) |