mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Decentralize Python native module linkage
We can now link even smaller Python binaries. For example, the hello.com program in the Python build directory is a compiled linked executable of hello.py which just prints hello world. Using decentralized sections, we can make that binary 1.9mb in size (noting that python.com is 6.3 megs!) This works for nontrivial programs too. For example, say we want an APE binary that's equivalent to python.com -m http.server. Our makefile now builds such a binary using the new launcher and it's only 3.2mb in size since Python sources get turned into ELF objects, which tell our linker that we need things like native hashing algorithm code.
This commit is contained in:
parent
dfa0359b50
commit
559b024e1d
129 changed files with 2798 additions and 13514 deletions
|
@ -13,5 +13,6 @@
|
|||
#define kNtFsctlSetSparse 0x000900C4u
|
||||
#define kNtFsctlSetZeroData 0x000980C8u
|
||||
#define kNtFsctlGetReparsePoint 0x000900a8u
|
||||
#define kNtFsctlSetReparsePoint 0x000900a4u
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_ */
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
|
||||
#include "libc/nt/struct/msg.h"
|
||||
#include "libc/nt/struct/point.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
/* ░░░░
|
||||
▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
|
||||
▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
|
||||
|
@ -39,19 +40,28 @@ bool32 GetCursorPos(struct NtPoint *lpPoint);
|
|||
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
|
||||
int64_t lParam);
|
||||
|
||||
#define EVENTLOG_SUCCESS 0x00000000
|
||||
#define EVENTLOG_ERROR_TYPE 0x00000001
|
||||
#define EVENTLOG_WARNING_TYPE 0x00000002
|
||||
#define EVENTLOG_INFORMATION_TYPE 0x00000004
|
||||
#define EVENTLOG_AUDIT_SUCCESS 0x00000008
|
||||
#define EVENTLOG_AUDIT_FAILURE 0x00000010
|
||||
#define EVENTLOG_SUCCESS 0x00000000
|
||||
#define EVENTLOG_ERROR_TYPE 0x00000001
|
||||
#define EVENTLOG_WARNING_TYPE 0x00000002
|
||||
#define EVENTLOG_INFORMATION_TYPE 0x00000004
|
||||
#define EVENTLOG_AUDIT_SUCCESS 0x00000008
|
||||
#define EVENTLOG_AUDIT_FAILURE 0x00000010
|
||||
|
||||
int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
|
||||
uint32_t dwEventID, const char *lpUserId, uint16_t wNumStrings,
|
||||
uint32_t dwDataSize, const char **lpStrings, void **lpRawData);
|
||||
int64_t RegisterEventSourceA(const char *lpUNCServerName, const char *lpSourceName);
|
||||
uint32_t dwEventID, const char *lpUserId,
|
||||
uint16_t wNumStrings, uint32_t dwDataSize,
|
||||
const char **lpStrings, void **lpRawData);
|
||||
int64_t RegisterEventSourceA(const char *lpUNCServerName,
|
||||
const char *lpSourceName);
|
||||
int32_t DeregisterEventSource(uint64_t handle);
|
||||
|
||||
int64_t CreateEvent(struct NtSecurityAttributes *lpEventAttributes,
|
||||
bool32 bManualReset, bool32 bInitialState,
|
||||
const char16_t *lpName);
|
||||
int64_t CreateEventEx(struct NtSecurityAttributes *lpEventAttributes,
|
||||
const char16_t *lpName, uint32_t dwFlags,
|
||||
uint32_t dwDesiredAccess);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_EVENTS_H_ */
|
||||
|
|
|
@ -211,6 +211,12 @@ uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
|
|||
uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
|
||||
char16_t *lpBuffer, char16_t **lpFilePart);
|
||||
|
||||
bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
|
||||
uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
|
||||
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
|
||||
uint32_t *lpNumberOfBytesTransferred,
|
||||
uint32_t dwMilliseconds, bool32 bAlertable);
|
||||
|
||||
#if ShouldUseMsabiAttribute()
|
||||
#include "libc/nt/thunk/files.inc"
|
||||
#endif /* ShouldUseMsabiAttribute() */
|
||||
|
|
|
@ -68,19 +68,19 @@ bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
|
|||
uint32_t nOutBufferSize, uint32_t *lpBytesRead,
|
||||
uint32_t nTimeOut);
|
||||
|
||||
bool32 ConnectNamedPipe(int64_t *hNamedPipe, struct NtOverlapped *lpOverlapped);
|
||||
bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
|
||||
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
|
||||
bool32 DisconnectNamedPipe(int64_t *hNamedPipe);
|
||||
bool32 DisconnectNamedPipe(int64_t hNamedPipe);
|
||||
|
||||
bool32 SetNamedPipeHandleState(int64_t *hNamedPipe, uint32_t *lpMode,
|
||||
bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
|
||||
uint32_t *lpMaxCollectionCount,
|
||||
uint32_t *lpCollectDataTimeout);
|
||||
|
||||
bool32 PeekNamedPipe(int64_t *hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
|
||||
bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
|
||||
uint32_t *lpBytesRead, uint32_t *lpTotalBytesAvail,
|
||||
uint32_t *lpBytesLeftThisMessage);
|
||||
|
||||
bool32 TransactNamedPipe(int64_t *hNamedPipe, void *lpInBuffer,
|
||||
bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
|
||||
uint32_t nInBufferSize, void *lpOutBuffer,
|
||||
uint32_t nOutBufferSize, uint32_t *lpBytesRead,
|
||||
struct NtOverlapped *lpOverlapped);
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_CreateEventA,CreateEventA,0
|
||||
|
||||
.text.windows
|
||||
CreateEventA:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_CreateEventA(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn CreateEventA,globl
|
||||
.previous
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_CreateEventExA,CreateEventExA,0
|
||||
|
||||
.text.windows
|
||||
CreateEventExA:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_CreateEventExA(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn CreateEventExA,globl
|
||||
.previous
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_CreateEventExW,CreateEventExW,0
|
||||
|
||||
.text.windows
|
||||
CreateEventEx:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_CreateEventExW(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn CreateEventEx,globl
|
||||
.previous
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_CreateEventW,CreateEventW,0
|
||||
|
||||
.text.windows
|
||||
CreateEvent:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_CreateEventW(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn CreateEvent,globl
|
||||
.previous
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_GetOverlappedResult,GetOverlappedResult,0
|
||||
|
||||
.text.windows
|
||||
GetOverlappedResult:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_GetOverlappedResult(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
.endfn GetOverlappedResult,globl
|
||||
.previous
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
.include "o/libc/nt/codegen.inc"
|
||||
.imp kernel32,__imp_GetOverlappedResultEx,GetOverlappedResultEx,0
|
||||
|
||||
.text.windows
|
||||
GetOverlappedResultEx:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov __imp_GetOverlappedResultEx(%rip),%rax
|
||||
jmp __sysv2nt6
|
||||
.endfn GetOverlappedResultEx,globl
|
||||
.previous
|
||||
|
|
|
@ -587,10 +587,10 @@ imp 'CreateEllipticRgnIndirect' CreateEllipticRgnIndirect gdi32 1074
|
|||
imp 'CreateEnclave' CreateEnclave KernelBase 180
|
||||
imp 'CreateEnhMetaFileA' CreateEnhMetaFileA gdi32 1075
|
||||
imp 'CreateEnhMetaFile' CreateEnhMetaFileW gdi32 1076
|
||||
imp 'CreateEventA' CreateEventA kernel32 0 # KernelBase
|
||||
imp 'CreateEventExA' CreateEventExA kernel32 0 # KernelBase
|
||||
imp 'CreateEventEx' CreateEventExW kernel32 0 # KernelBase
|
||||
imp 'CreateEvent' CreateEventW kernel32 0 # KernelBase
|
||||
imp 'CreateEventA' CreateEventA kernel32 0 4 # KernelBase
|
||||
imp 'CreateEventExA' CreateEventExA kernel32 0 4 # KernelBase
|
||||
imp 'CreateEventEx' CreateEventExW kernel32 0 4 # KernelBase
|
||||
imp 'CreateEvent' CreateEventW kernel32 0 4 # KernelBase
|
||||
imp 'CreateFiber' CreateFiber kernel32 0 # KernelBase
|
||||
imp 'CreateFiberEx' CreateFiberEx kernel32 0 # KernelBase
|
||||
imp 'CreateFile' CreateFileW kernel32 0 7 # KernelBase
|
||||
|
@ -2384,8 +2384,8 @@ imp 'GetOsSafeBootMode' GetOsSafeBootMode KernelBase 626
|
|||
imp 'GetOutlineTextMetricsA' GetOutlineTextMetricsA gdi32 1685
|
||||
imp 'GetOutlineTextMetrics' GetOutlineTextMetricsW gdi32 1686
|
||||
imp 'GetOverlappedAccessResults' GetOverlappedAccessResults advapi32 1348
|
||||
imp 'GetOverlappedResult' GetOverlappedResult kernel32 0 # KernelBase
|
||||
imp 'GetOverlappedResultEx' GetOverlappedResultEx kernel32 0 # KernelBase
|
||||
imp 'GetOverlappedResult' GetOverlappedResult kernel32 0 4 # KernelBase
|
||||
imp 'GetOverlappedResultEx' GetOverlappedResultEx kernel32 0 5 # KernelBase
|
||||
imp 'GetPackageApplicationContext' GetPackageApplicationContext KernelBase 629
|
||||
imp 'GetPackageApplicationIds' GetPackageApplicationIds kernel32 0 # KernelBase
|
||||
imp 'GetPackageApplicationProperty' GetPackageApplicationProperty KernelBase 631
|
||||
|
|
|
@ -55,7 +55,7 @@ bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);
|
|||
|
||||
bool32 CancelSynchronousIo(int64_t hThread);
|
||||
bool32 CancelIo(int64_t hFile);
|
||||
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped opt_lpOverlapped);
|
||||
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);
|
||||
|
||||
#if ShouldUseMsabiAttribute()
|
||||
#include "libc/nt/thunk/thread.inc"
|
||||
|
|
163
libc/str/blake2.c
Normal file
163
libc/str/blake2.c
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Google LLC │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/blake2.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define ROR(v, n) (((v) >> (n)) | ((v) << (64 - (n))))
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
boringssl blake2b (ISC License)\\n\
|
||||
Copyright 2021 Google LLC\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.6
|
||||
static const uint64_t kIV[8] = {
|
||||
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b,
|
||||
0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f,
|
||||
0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
|
||||
};
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.7
|
||||
static const uint8_t kSigma[10][16] = {
|
||||
// clang-format off
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
|
||||
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
|
||||
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
|
||||
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
|
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
|
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
|
||||
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
|
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.1
|
||||
static void Blake2bMix(uint64_t v[16], int a, int b, int c, int d, uint64_t x,
|
||||
uint64_t y) {
|
||||
v[a] = v[a] + v[b] + x;
|
||||
v[d] = ROR(v[d] ^ v[a], 32);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = ROR(v[b] ^ v[c], 24);
|
||||
v[a] = v[a] + v[b] + y;
|
||||
v[d] = ROR(v[d] ^ v[a], 16);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = ROR(v[b] ^ v[c], 63);
|
||||
}
|
||||
|
||||
static void Blake2bTransform(
|
||||
struct Blake2b *b2b, const uint64_t w[BLAKE2B_CBLOCK / sizeof(uint64_t)],
|
||||
size_t num_bytes, int is_final_block) {
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.2
|
||||
uint64_t v[16];
|
||||
_Static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
|
||||
memcpy(v, b2b->h, sizeof(b2b->h));
|
||||
memcpy(&v[8], kIV, sizeof(kIV));
|
||||
b2b->t_low += num_bytes;
|
||||
if (b2b->t_low < num_bytes) {
|
||||
b2b->t_high++;
|
||||
}
|
||||
v[12] ^= b2b->t_low;
|
||||
v[13] ^= b2b->t_high;
|
||||
if (is_final_block) {
|
||||
v[14] = ~v[14];
|
||||
}
|
||||
for (int i = 0; i < 12; i++) {
|
||||
Blake2bMix(v, 0, 4, 8, 12, w[kSigma[i % 10][0]], w[kSigma[i % 10][1]]);
|
||||
Blake2bMix(v, 1, 5, 9, 13, w[kSigma[i % 10][2]], w[kSigma[i % 10][3]]);
|
||||
Blake2bMix(v, 2, 6, 10, 14, w[kSigma[i % 10][4]], w[kSigma[i % 10][5]]);
|
||||
Blake2bMix(v, 3, 7, 11, 15, w[kSigma[i % 10][6]], w[kSigma[i % 10][7]]);
|
||||
Blake2bMix(v, 0, 5, 10, 15, w[kSigma[i % 10][8]], w[kSigma[i % 10][9]]);
|
||||
Blake2bMix(v, 1, 6, 11, 12, w[kSigma[i % 10][10]], w[kSigma[i % 10][11]]);
|
||||
Blake2bMix(v, 2, 7, 8, 13, w[kSigma[i % 10][12]], w[kSigma[i % 10][13]]);
|
||||
Blake2bMix(v, 3, 4, 9, 14, w[kSigma[i % 10][14]], w[kSigma[i % 10][15]]);
|
||||
}
|
||||
for (size_t i = 0; i < ARRAYLEN(b2b->h); i++) {
|
||||
b2b->h[i] ^= v[i];
|
||||
b2b->h[i] ^= v[i + 8];
|
||||
}
|
||||
}
|
||||
|
||||
int BLAKE2B256_Init(struct Blake2b *b2b) {
|
||||
bzero(b2b, sizeof(struct Blake2b));
|
||||
_Static_assert(sizeof(kIV) == sizeof(b2b->h), "");
|
||||
memcpy(&b2b->h, kIV, sizeof(kIV));
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.5
|
||||
b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BLAKE2B256_Process(struct Blake2b *b2b,
|
||||
const uint64_t data[BLAKE2B_CBLOCK / 8]) {
|
||||
Blake2bTransform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) {
|
||||
const uint8_t *data = (const uint8_t *)in_data;
|
||||
size_t todo = sizeof(b2b->block.bytes) - b2b->block_used;
|
||||
if (todo > len) {
|
||||
todo = len;
|
||||
}
|
||||
memcpy(&b2b->block.bytes[b2b->block_used], data, todo);
|
||||
b2b->block_used += todo;
|
||||
data += todo;
|
||||
len -= todo;
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
// More input remains therefore we must have filled |b2b->block|.
|
||||
assert(b2b->block_used == BLAKE2B_CBLOCK);
|
||||
Blake2bTransform(b2b, b2b->block.words, BLAKE2B_CBLOCK,
|
||||
/*is_final_block=*/0);
|
||||
b2b->block_used = 0;
|
||||
while (len > BLAKE2B_CBLOCK) {
|
||||
uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)];
|
||||
memcpy(block_words, data, sizeof(block_words));
|
||||
Blake2bTransform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
data += BLAKE2B_CBLOCK;
|
||||
len -= BLAKE2B_CBLOCK;
|
||||
}
|
||||
memcpy(b2b->block.bytes, data, len);
|
||||
b2b->block_used = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BLAKE2B256_Final(struct Blake2b *b2b,
|
||||
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
|
||||
bzero(&b2b->block.bytes[b2b->block_used],
|
||||
sizeof(b2b->block.bytes) - b2b->block_used);
|
||||
Blake2bTransform(b2b, b2b->block.words, b2b->block_used,
|
||||
/*is_final_block=*/1);
|
||||
_Static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
|
||||
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BLAKE2B256(const void *data, size_t len,
|
||||
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
|
||||
struct Blake2b ctx;
|
||||
BLAKE2B256_Init(&ctx);
|
||||
BLAKE2B256_Update(&ctx, data, len);
|
||||
BLAKE2B256_Final(&ctx, out);
|
||||
return 0;
|
||||
}
|
29
libc/str/blake2.h
Normal file
29
libc/str/blake2.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STR_BLAKE2_H_
|
||||
#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_
|
||||
|
||||
#define BLAKE2B256_DIGEST_LENGTH 32
|
||||
#define BLAKE2B_CBLOCK 128
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct Blake2b {
|
||||
uint64_t h[8];
|
||||
uint64_t t_low;
|
||||
uint64_t t_high;
|
||||
union {
|
||||
uint8_t bytes[BLAKE2B_CBLOCK];
|
||||
uint64_t words[16];
|
||||
} block;
|
||||
size_t block_used;
|
||||
};
|
||||
|
||||
int BLAKE2B256_Init(struct Blake2b *);
|
||||
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
|
||||
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
|
||||
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
|
||||
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_BLAKE2_H_ */
|
|
@ -29,6 +29,8 @@ static uint32_t kCrc32Tab[256];
|
|||
* 0b100000100110000010001110110110111
|
||||
* bitreverse32(0x104c11db7)
|
||||
*
|
||||
* This implementation takes 32 picoseconds per byte or 30 gibibyte/s.
|
||||
*
|
||||
* @param h is initial value
|
||||
*/
|
||||
uint32_t crc32_z(uint32_t h, const void *data, size_t size) {
|
||||
|
|
|
@ -47,7 +47,7 @@ void *GetZipCdir(const uint8_t *p, size_t n) {
|
|||
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + j))) {
|
||||
return p + ZIP_LOCATE64_OFFSET(p + j);
|
||||
}
|
||||
} while (j-- && i - j < 1024);
|
||||
} while (j-- && i - j < 128);
|
||||
return p + i;
|
||||
}
|
||||
} while (i--);
|
||||
|
|
|
@ -52,6 +52,8 @@ o//libc/str/bzero.o: \
|
|||
OVERRIDE_CFLAGS += \
|
||||
-O2
|
||||
|
||||
o/$(MODE)/libc/str/fun3.o \
|
||||
o/$(MODE)/libc/str/sha3.o \
|
||||
o/$(MODE)/libc/str/dosdatetimetounix.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-O3
|
||||
|
|
89
libc/unicode/langinfo.c
Normal file
89
libc/unicode/langinfo.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/unicode/langinfo.h"
|
||||
|
||||
static const char c_time[] = "\
|
||||
Sun\0\n\
|
||||
Mon\0\n\
|
||||
Tue\0\n\
|
||||
Wed\0\n\
|
||||
Thu\0\n\
|
||||
Fri\0\n\
|
||||
Sat\0\n\
|
||||
Sunday\0\n\
|
||||
Monday\0\n\
|
||||
Tuesday\0\n\
|
||||
Wednesday\0\n\
|
||||
Thursday\0\n\
|
||||
Friday\0\n\
|
||||
Saturday\0\n\
|
||||
Jan\0\n\
|
||||
Feb\0\n\
|
||||
Mar\0\n\
|
||||
Apr\0\n\
|
||||
May\0\n\
|
||||
Jun\0\n\
|
||||
Jul\0\n\
|
||||
Aug\0\n\
|
||||
Sep\0\n\
|
||||
Oct\0\n\
|
||||
Nov\0\n\
|
||||
Dec\0\n\
|
||||
January\0\n\
|
||||
February\0\n\
|
||||
March\0\n\
|
||||
April\0\n\
|
||||
May\0\n\
|
||||
June\0\n\
|
||||
July\0\n\
|
||||
August\0\n\
|
||||
September\0\n\
|
||||
October\0\n\
|
||||
November\0\n\
|
||||
December\0\n\
|
||||
AM\0\n\
|
||||
PM\0\n\
|
||||
a %b %e %T %Y\0\n\
|
||||
m/%d/%y\0\n\
|
||||
H:%M:%S\0\n\
|
||||
I:%M:%S %p\0\n\
|
||||
0\n\
|
||||
0\n\
|
||||
m/%d/%y\0\n\
|
||||
0123456789\0\n\
|
||||
a %b %e %T %Y\0\n\
|
||||
H:%M:%S";
|
||||
|
||||
static const char c_messages[] = "\
|
||||
^[yY]\0\
|
||||
^[nN]\0\
|
||||
yes\0\
|
||||
no";
|
||||
|
||||
static const char c_numeric[] = "\
|
||||
.\0\
|
||||
";
|
||||
|
||||
char *nl_langinfo(int item) {
|
||||
if (item == CODESET) {
|
||||
return "UTF-8";
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
86
libc/unicode/langinfo.h
Normal file
86
libc/unicode/langinfo.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_
|
||||
#define COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define ABDAY_1 0x20000
|
||||
#define ABDAY_2 0x20001
|
||||
#define ABDAY_3 0x20002
|
||||
#define ABDAY_4 0x20003
|
||||
#define ABDAY_5 0x20004
|
||||
#define ABDAY_6 0x20005
|
||||
#define ABDAY_7 0x20006
|
||||
|
||||
#define DAY_1 0x20007
|
||||
#define DAY_2 0x20008
|
||||
#define DAY_3 0x20009
|
||||
#define DAY_4 0x2000A
|
||||
#define DAY_5 0x2000B
|
||||
#define DAY_6 0x2000C
|
||||
#define DAY_7 0x2000D
|
||||
|
||||
#define ABMON_1 0x2000E
|
||||
#define ABMON_2 0x2000F
|
||||
#define ABMON_3 0x20010
|
||||
#define ABMON_4 0x20011
|
||||
#define ABMON_5 0x20012
|
||||
#define ABMON_6 0x20013
|
||||
#define ABMON_7 0x20014
|
||||
#define ABMON_8 0x20015
|
||||
#define ABMON_9 0x20016
|
||||
#define ABMON_10 0x20017
|
||||
#define ABMON_11 0x20018
|
||||
#define ABMON_12 0x20019
|
||||
|
||||
#define MON_1 0x2001A
|
||||
#define MON_2 0x2001B
|
||||
#define MON_3 0x2001C
|
||||
#define MON_4 0x2001D
|
||||
#define MON_5 0x2001E
|
||||
#define MON_6 0x2001F
|
||||
#define MON_7 0x20020
|
||||
#define MON_8 0x20021
|
||||
#define MON_9 0x20022
|
||||
#define MON_10 0x20023
|
||||
#define MON_11 0x20024
|
||||
#define MON_12 0x20025
|
||||
|
||||
#define AM_STR 0x20026
|
||||
#define PM_STR 0x20027
|
||||
|
||||
#define D_T_FMT 0x20028
|
||||
#define D_FMT 0x20029
|
||||
#define T_FMT 0x2002A
|
||||
#define T_FMT_AMPM 0x2002B
|
||||
|
||||
#define ERA 0x2002C
|
||||
#define ERA_D_FMT 0x2002E
|
||||
#define ALT_DIGITS 0x2002F
|
||||
#define ERA_D_T_FMT 0x20030
|
||||
#define ERA_T_FMT 0x20031
|
||||
|
||||
#define CODESET 14
|
||||
|
||||
#define CRNCYSTR 0x4000F
|
||||
|
||||
#define RADIXCHAR 0x10000
|
||||
#define THOUSEP 0x10001
|
||||
#define YESEXPR 0x50000
|
||||
#define NOEXPR 0x50001
|
||||
|
||||
#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)
|
||||
|
||||
#if defined(_GNU_SOURCE)
|
||||
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define YESSTR 0x50002
|
||||
#define NOSTR 0x50003
|
||||
#endif
|
||||
|
||||
char *nl_langinfo(int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue