mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Import some Lua documentation
I personally find it easier to read the documentation in Emacs using JavaDoc style comments.
This commit is contained in:
parent
41b9eb6873
commit
7d25fb0090
16 changed files with 801 additions and 108 deletions
|
@ -23,14 +23,6 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static noasan bool __asan_is_valid_strlist(char *const *p) {
|
||||
for (;; ++p) {
|
||||
if (!__asan_is_valid(p, sizeof(char *))) return false;
|
||||
if (!*p) return true;
|
||||
if (!__asan_is_valid(*p, 1)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces current process with program.
|
||||
*
|
||||
|
|
|
@ -402,6 +402,14 @@ bool __asan_is_valid_iov(const struct iovec *iov, int iovlen) {
|
|||
}
|
||||
}
|
||||
|
||||
bool __asan_is_valid_strlist(char *const *p) {
|
||||
for (;; ++p) {
|
||||
if (!__asan_is_valid(p, sizeof(char *))) return false;
|
||||
if (!*p) return true;
|
||||
if (!__asan_is_valid(*p, 1)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *__asan_dscribe_heap_poison(long c) {
|
||||
switch (c) {
|
||||
case kAsanHeapFree:
|
||||
|
|
|
@ -25,5 +25,6 @@ void __asan_poison(uintptr_t, size_t, int);
|
|||
void __asan_unpoison(uintptr_t, size_t);
|
||||
bool __asan_is_valid(const void *, size_t);
|
||||
bool __asan_is_valid_iov(const struct iovec *, int);
|
||||
bool __asan_is_valid_strlist(char *const *);
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_ASAN_H_ */
|
||||
|
|
|
@ -38,18 +38,18 @@ void *GetZipCdir(const uint8_t *p, size_t n) {
|
|||
if (READ32LE(p + i) == kZipCdir64LocatorMagic &&
|
||||
i + kZipCdir64LocatorSize <= n &&
|
||||
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + i))) {
|
||||
return (void *)(p + ZIP_LOCATE64_OFFSET(p + i));
|
||||
return p + ZIP_LOCATE64_OFFSET(p + i);
|
||||
} else if (READ32LE(p + i) == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) {
|
||||
j = i;
|
||||
do {
|
||||
if (READ32LE(p + j) == kZipCdir64LocatorMagic &&
|
||||
j + kZipCdir64LocatorSize <= n &&
|
||||
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + j))) {
|
||||
return (void *)(p + ZIP_LOCATE64_OFFSET(p + j));
|
||||
return p + ZIP_LOCATE64_OFFSET(p + j);
|
||||
}
|
||||
} while (j-- && i - j < 1024);
|
||||
return (void *)(p + i);
|
||||
return p + i;
|
||||
}
|
||||
} while (i--);
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/str/highwayhash64.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -30,14 +31,14 @@ typedef struct {
|
|||
} HighwayHashState;
|
||||
|
||||
static void HighwayHashReset(const uint64_t key[4], HighwayHashState *state) {
|
||||
state->mul0[0] = 0xdbe6d5d5fe4cce2full;
|
||||
state->mul0[1] = 0xa4093822299f31d0ull;
|
||||
state->mul0[2] = 0x13198a2e03707344ull;
|
||||
state->mul0[3] = 0x243f6a8885a308d3ull;
|
||||
state->mul1[0] = 0x3bd39e10cb0ef593ull;
|
||||
state->mul1[1] = 0xc0acf169b5f18a8cull;
|
||||
state->mul1[2] = 0xbe5466cf34e90c6cull;
|
||||
state->mul1[3] = 0x452821e638d01377ull;
|
||||
state->mul0[0] = 0xdbe6d5d5fe4cce2f;
|
||||
state->mul0[1] = 0xa4093822299f31d0;
|
||||
state->mul0[2] = 0x13198a2e03707344;
|
||||
state->mul0[3] = 0x243f6a8885a308d3;
|
||||
state->mul1[0] = 0x3bd39e10cb0ef593;
|
||||
state->mul1[1] = 0xc0acf169b5f18a8c;
|
||||
state->mul1[2] = 0xbe5466cf34e90c6c;
|
||||
state->mul1[3] = 0x452821e638d01377;
|
||||
state->v0[0] = state->mul0[0] ^ key[0];
|
||||
state->v0[1] = state->mul0[1] ^ key[1];
|
||||
state->v0[2] = state->mul0[2] ^ key[2];
|
||||
|
@ -50,14 +51,14 @@ static void HighwayHashReset(const uint64_t key[4], HighwayHashState *state) {
|
|||
|
||||
static void ZipperMergeAndAdd(const uint64_t v1, const uint64_t v0,
|
||||
uint64_t *add1, uint64_t *add0) {
|
||||
*add0 += (((v0 & 0xff000000ull) | (v1 & 0xff00000000ull)) >> 24) |
|
||||
(((v0 & 0xff0000000000ull) | (v1 & 0xff000000000000ull)) >> 16) |
|
||||
(v0 & 0xff0000ull) | ((v0 & 0xff00ull) << 32) |
|
||||
((v1 & 0xff00000000000000ull) >> 8) | (v0 << 56);
|
||||
*add1 += (((v1 & 0xff000000ull) | (v0 & 0xff00000000ull)) >> 24) |
|
||||
(v1 & 0xff0000ull) | ((v1 & 0xff0000000000ull) >> 16) |
|
||||
((v1 & 0xff00ull) << 24) | ((v0 & 0xff000000000000ull) >> 8) |
|
||||
((v1 & 0xffull) << 48) | (v0 & 0xff00000000000000ull);
|
||||
*add0 += (((v0 & 0xff000000) | (v1 & 0xff00000000)) >> 24) |
|
||||
(((v0 & 0xff0000000000) | (v1 & 0xff000000000000)) >> 16) |
|
||||
(v0 & 0xff0000) | ((v0 & 0xff00) << 32) |
|
||||
((v1 & 0xff00000000000000) >> 8) | (v0 << 56);
|
||||
*add1 += (((v1 & 0xff000000) | (v0 & 0xff00000000)) >> 24) | (v1 & 0xff0000) |
|
||||
((v1 & 0xff0000000000) >> 16) | ((v1 & 0xff00) << 24) |
|
||||
((v0 & 0xff000000000000) >> 8) | ((v1 & 0xff) << 48) |
|
||||
(v0 & 0xff00000000000000);
|
||||
}
|
||||
|
||||
static void Update(const uint64_t lanes[4], HighwayHashState *state) {
|
||||
|
@ -74,20 +75,13 @@ static void Update(const uint64_t lanes[4], HighwayHashState *state) {
|
|||
ZipperMergeAndAdd(state->v0[3], state->v0[2], &state->v1[3], &state->v1[2]);
|
||||
}
|
||||
|
||||
static uint64_t Read64(const uint8_t *src) {
|
||||
return (uint64_t)src[0] | ((uint64_t)src[1] << 8) | ((uint64_t)src[2] << 16) |
|
||||
((uint64_t)src[3] << 24) | ((uint64_t)src[4] << 32) |
|
||||
((uint64_t)src[5] << 40) | ((uint64_t)src[6] << 48) |
|
||||
((uint64_t)src[7] << 56);
|
||||
}
|
||||
|
||||
static void HighwayHashUpdatePacket(const uint8_t *packet,
|
||||
HighwayHashState *state) {
|
||||
uint64_t lanes[4];
|
||||
lanes[0] = Read64(packet + 0);
|
||||
lanes[1] = Read64(packet + 8);
|
||||
lanes[2] = Read64(packet + 16);
|
||||
lanes[3] = Read64(packet + 24);
|
||||
lanes[0] = READ64LE(packet + 000);
|
||||
lanes[1] = READ64LE(packet + 010);
|
||||
lanes[2] = READ64LE(packet + 020);
|
||||
lanes[3] = READ64LE(packet + 030);
|
||||
Update(lanes, state);
|
||||
}
|
||||
|
||||
|
@ -130,10 +124,10 @@ static void HighwayHashUpdateRemainder(const uint8_t *bytes,
|
|||
}
|
||||
|
||||
static void Permute(const uint64_t v[4], uint64_t *permuted) {
|
||||
permuted[0] = (v[2] >> 32) | (v[2] << 32);
|
||||
permuted[1] = (v[3] >> 32) | (v[3] << 32);
|
||||
permuted[2] = (v[0] >> 32) | (v[0] << 32);
|
||||
permuted[3] = (v[1] >> 32) | (v[1] << 32);
|
||||
permuted[0] = v[2] >> 32 | v[2] << 32;
|
||||
permuted[1] = v[3] >> 32 | v[3] << 32;
|
||||
permuted[2] = v[0] >> 32 | v[0] << 32;
|
||||
permuted[3] = v[1] >> 32 | v[1] << 32;
|
||||
}
|
||||
|
||||
static void PermuteAndUpdate(HighwayHashState *state) {
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
|
||||
#define ThomPikeCont(x) (((x)&0300) == 0200)
|
||||
#define ThomPikeCont(x) (0200 == (0300 & (x)))
|
||||
#define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
|
||||
#define ThomPikeLen(x) (7 - ThomPikeMsb(x))
|
||||
#define ThomPikeMsb(x) (((x)&0xff) < 252 ? bsr(~(x)&0xff) : 1)
|
||||
#define ThomPikeMerge(x, y) ((x) << 6 | (y)&077)
|
||||
#define ThomPikeMsb(x) ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
|
||||
#define ThomPikeMerge(x, y) ((x) << 6 | 077 & (y))
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
* Converts Windows COBOL timestamp to UNIX epoch in microseconds.
|
||||
*/
|
||||
struct timeval WindowsTimeToTimeVal(int64_t x) {
|
||||
/* return WindowsDurationToTimeVal(x - MODERNITYSECONDS * HECTONANOSECONDS);
|
||||
*/
|
||||
return (struct timeval){x / HECTONANOSECONDS - MODERNITYSECONDS,
|
||||
x % HECTONANOSECONDS / 10};
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/madv.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
|
@ -55,7 +55,7 @@ int filecmp(const char *pathname1, const char *pathname2) {
|
|||
madvise(addr1, size1, MADV_WILLNEED | MADV_SEQUENTIAL);
|
||||
madvise(addr2, size2, MADV_WILLNEED | MADV_SEQUENTIAL);
|
||||
errno = olderr;
|
||||
res = memcmp(addr1, addr2, min(size1, size2));
|
||||
res = memcmp(addr1, addr2, MIN(size1, size2));
|
||||
if (!res && size1 != size2) {
|
||||
char kNul = '\0';
|
||||
if (size1 > size2) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue