Update go waku & Shorten shutdown
This commit is contained in:
parent
caca511aed
commit
df2a5d8e21
|
@ -204,7 +204,7 @@ func (w *gethWakuWrapper) GetFilter(id string) types.Filter {
|
|||
return NewWakuFilterWrapper(w.waku.GetFilter(id), id)
|
||||
}
|
||||
|
||||
func (w *gethWakuWrapper) Unsubscribe(id string) error {
|
||||
func (w *gethWakuWrapper) Unsubscribe(ctx context.Context, id string) error {
|
||||
return w.waku.Unsubscribe(id)
|
||||
}
|
||||
|
||||
|
|
|
@ -152,8 +152,8 @@ func (w *gethWakuV2Wrapper) GetFilter(id string) types.Filter {
|
|||
return NewWakuV2FilterWrapper(w.waku.GetFilter(id), id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Unsubscribe(id string) error {
|
||||
return w.waku.Unsubscribe(id)
|
||||
func (w *gethWakuV2Wrapper) Unsubscribe(ctx context.Context, id string) error {
|
||||
return w.waku.Unsubscribe(ctx, id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) UnsubscribeMany(ids []string) error {
|
||||
|
|
|
@ -130,7 +130,7 @@ type Waku interface {
|
|||
|
||||
Subscribe(opts *SubscriptionOptions) (string, error)
|
||||
GetFilter(id string) Filter
|
||||
Unsubscribe(id string) error
|
||||
Unsubscribe(ctx context.Context, id string) error
|
||||
UnsubscribeMany(ids []string) error
|
||||
|
||||
// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
|
||||
|
|
2
go.mod
2
go.mod
|
@ -83,7 +83,7 @@ require (
|
|||
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||
github.com/schollz/peerdiscovery v1.7.0
|
||||
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230707130306-0d4ff8bff7f4
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230717093439-b7a0c8fa1812
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.7
|
||||
github.com/yeqown/go-qrcode/v2 v2.2.1
|
||||
github.com/yeqown/go-qrcode/writer/standard v1.2.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2090,8 +2090,8 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF
|
|||
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
|
||||
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE=
|
||||
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230707130306-0d4ff8bff7f4 h1:FHoWj4WpAaQ334xWY1a5MRqPIE62fNZ5hdUB90jicLw=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230707130306-0d4ff8bff7f4/go.mod h1:52Ulzg6Y4zmQexM41I9DqVR+8d91JJGDUUp23Vw6HNg=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230717093439-b7a0c8fa1812 h1:KjjLDuKXnIZNFgs5rdRtQ85HkPp1+W2MOYYdG/3yazM=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230717093439-b7a0c8fa1812/go.mod h1:52Ulzg6Y4zmQexM41I9DqVR+8d91JJGDUUp23Vw6HNg=
|
||||
github.com/waku-org/go-zerokit-rln v0.1.12 h1:66+tU6sTlmUpuUlEv7kCFOGZ37MwZYFJBXHcm8QquwU=
|
||||
github.com/waku-org/go-zerokit-rln v0.1.12/go.mod h1:MUW+wB6Yj7UBMdZrhko7oHfUZeY2wchggXYjpUiMoac=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 h1:Q5XQqo+PEmvrybT8D7BEsKCwIYDi80s+00Q49cfm9Gs=
|
||||
|
|
|
@ -521,7 +521,17 @@ func NewMessenger(
|
|||
pushNotificationClient.Stop,
|
||||
communitiesManager.Stop,
|
||||
encryptionProtocol.Stop,
|
||||
transp.ResetFilters,
|
||||
func() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
err := transp.ResetFilters(ctx)
|
||||
if err != nil {
|
||||
logger.Warn("could not reset filters", zap.Error(err))
|
||||
}
|
||||
// We don't want to thrown an error in this case, this is a soft
|
||||
// fail
|
||||
return nil
|
||||
},
|
||||
transp.Stop,
|
||||
func() error { sender.Stop(); return nil },
|
||||
// Currently this often fails, seems like it's safe to ignore them
|
||||
|
|
|
@ -2,6 +2,7 @@ package transport
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"sync"
|
||||
|
@ -37,7 +38,7 @@ type FiltersService interface {
|
|||
DeleteSymKey(id string) bool
|
||||
|
||||
Subscribe(opts *types.SubscriptionOptions) (string, error)
|
||||
Unsubscribe(id string) error
|
||||
Unsubscribe(ctx context.Context, id string) error
|
||||
UnsubscribeMany(ids []string) error
|
||||
}
|
||||
|
||||
|
@ -188,7 +189,7 @@ func (f *FiltersManager) InitWithFilters(filters []*Filter) ([]*Filter, error) {
|
|||
return f.Init(chatIDs, publicKeys)
|
||||
}
|
||||
|
||||
func (f *FiltersManager) Reset() error {
|
||||
func (f *FiltersManager) Reset(ctx context.Context) error {
|
||||
var filters []*Filter
|
||||
|
||||
f.mutex.Lock()
|
||||
|
@ -197,7 +198,7 @@ func (f *FiltersManager) Reset() error {
|
|||
}
|
||||
f.mutex.Unlock()
|
||||
|
||||
return f.Remove(filters...)
|
||||
return f.Remove(ctx, filters...)
|
||||
}
|
||||
|
||||
func (f *FiltersManager) Filters() (result []*Filter) {
|
||||
|
@ -271,12 +272,12 @@ func (f *FiltersManager) FilterByChatID(chatID string) *Filter {
|
|||
}
|
||||
|
||||
// Remove remove all the filters associated with a chat/identity
|
||||
func (f *FiltersManager) Remove(filters ...*Filter) error {
|
||||
func (f *FiltersManager) Remove(ctx context.Context, filters ...*Filter) error {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
for _, filter := range filters {
|
||||
if err := f.service.Unsubscribe(filter.FilterID); err != nil {
|
||||
if err := f.service.Unsubscribe(ctx, filter.FilterID); err != nil {
|
||||
return err
|
||||
}
|
||||
if filter.SymKeyID != "" {
|
||||
|
@ -325,7 +326,7 @@ func (f *FiltersManager) RemoveFilterByChatID(chatID string) (*Filter, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
err := f.Remove(filter)
|
||||
err := f.Remove(context.Background(), filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -169,15 +169,15 @@ func (t *Transport) InitCommunityFilters(pks []*ecdsa.PrivateKey) ([]*Filter, er
|
|||
}
|
||||
|
||||
func (t *Transport) RemoveFilters(filters []*Filter) error {
|
||||
return t.filters.Remove(filters...)
|
||||
return t.filters.Remove(context.Background(), filters...)
|
||||
}
|
||||
|
||||
func (t *Transport) RemoveFilterByChatID(chatID string) (*Filter, error) {
|
||||
return t.filters.RemoveFilterByChatID(chatID)
|
||||
}
|
||||
|
||||
func (t *Transport) ResetFilters() error {
|
||||
return t.filters.Reset()
|
||||
func (t *Transport) ResetFilters(ctx context.Context) error {
|
||||
return t.filters.Reset(ctx)
|
||||
}
|
||||
|
||||
func (t *Transport) ProcessNegotiatedSecret(secret types.NegotiatedSecret) (*Filter, error) {
|
||||
|
@ -197,7 +197,7 @@ func (t *Transport) LeavePublic(chatID string) error {
|
|||
if chat != nil {
|
||||
return nil
|
||||
}
|
||||
return t.filters.Remove(chat)
|
||||
return t.filters.Remove(context.Background(), chat)
|
||||
}
|
||||
|
||||
func (t *Transport) JoinPrivate(publicKey *ecdsa.PublicKey) (*Filter, error) {
|
||||
|
|
150
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.c
generated
vendored
Normal file
150
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.c
generated
vendored
Normal file
|
@ -0,0 +1,150 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2015 Pieter Wuille *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <secp256k1.h>
|
||||
|
||||
#include "lax_der_parsing.h"
|
||||
|
||||
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
|
||||
size_t rpos, rlen, spos, slen;
|
||||
size_t pos = 0;
|
||||
size_t lenbyte;
|
||||
unsigned char tmpsig[64] = {0};
|
||||
int overflow = 0;
|
||||
|
||||
/* Hack to initialize sig with a correctly-parsed but invalid signature. */
|
||||
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
|
||||
|
||||
/* Sequence tag byte */
|
||||
if (pos == inputlen || input[pos] != 0x30) {
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
|
||||
/* Sequence length bytes */
|
||||
if (pos == inputlen) {
|
||||
return 0;
|
||||
}
|
||||
lenbyte = input[pos++];
|
||||
if (lenbyte & 0x80) {
|
||||
lenbyte -= 0x80;
|
||||
if (pos + lenbyte > inputlen) {
|
||||
return 0;
|
||||
}
|
||||
pos += lenbyte;
|
||||
}
|
||||
|
||||
/* Integer tag byte for R */
|
||||
if (pos == inputlen || input[pos] != 0x02) {
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
|
||||
/* Integer length for R */
|
||||
if (pos == inputlen) {
|
||||
return 0;
|
||||
}
|
||||
lenbyte = input[pos++];
|
||||
if (lenbyte & 0x80) {
|
||||
lenbyte -= 0x80;
|
||||
if (pos + lenbyte > inputlen) {
|
||||
return 0;
|
||||
}
|
||||
while (lenbyte > 0 && input[pos] == 0) {
|
||||
pos++;
|
||||
lenbyte--;
|
||||
}
|
||||
if (lenbyte >= sizeof(size_t)) {
|
||||
return 0;
|
||||
}
|
||||
rlen = 0;
|
||||
while (lenbyte > 0) {
|
||||
rlen = (rlen << 8) + input[pos];
|
||||
pos++;
|
||||
lenbyte--;
|
||||
}
|
||||
} else {
|
||||
rlen = lenbyte;
|
||||
}
|
||||
if (rlen > inputlen - pos) {
|
||||
return 0;
|
||||
}
|
||||
rpos = pos;
|
||||
pos += rlen;
|
||||
|
||||
/* Integer tag byte for S */
|
||||
if (pos == inputlen || input[pos] != 0x02) {
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
|
||||
/* Integer length for S */
|
||||
if (pos == inputlen) {
|
||||
return 0;
|
||||
}
|
||||
lenbyte = input[pos++];
|
||||
if (lenbyte & 0x80) {
|
||||
lenbyte -= 0x80;
|
||||
if (pos + lenbyte > inputlen) {
|
||||
return 0;
|
||||
}
|
||||
while (lenbyte > 0 && input[pos] == 0) {
|
||||
pos++;
|
||||
lenbyte--;
|
||||
}
|
||||
if (lenbyte >= sizeof(size_t)) {
|
||||
return 0;
|
||||
}
|
||||
slen = 0;
|
||||
while (lenbyte > 0) {
|
||||
slen = (slen << 8) + input[pos];
|
||||
pos++;
|
||||
lenbyte--;
|
||||
}
|
||||
} else {
|
||||
slen = lenbyte;
|
||||
}
|
||||
if (slen > inputlen - pos) {
|
||||
return 0;
|
||||
}
|
||||
spos = pos;
|
||||
pos += slen;
|
||||
|
||||
/* Ignore leading zeroes in R */
|
||||
while (rlen > 0 && input[rpos] == 0) {
|
||||
rlen--;
|
||||
rpos++;
|
||||
}
|
||||
/* Copy R value */
|
||||
if (rlen > 32) {
|
||||
overflow = 1;
|
||||
} else {
|
||||
memcpy(tmpsig + 32 - rlen, input + rpos, rlen);
|
||||
}
|
||||
|
||||
/* Ignore leading zeroes in S */
|
||||
while (slen > 0 && input[spos] == 0) {
|
||||
slen--;
|
||||
spos++;
|
||||
}
|
||||
/* Copy S value */
|
||||
if (slen > 32) {
|
||||
overflow = 1;
|
||||
} else {
|
||||
memcpy(tmpsig + 64 - slen, input + spos, slen);
|
||||
}
|
||||
|
||||
if (!overflow) {
|
||||
overflow = !secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
|
||||
}
|
||||
if (overflow) {
|
||||
memset(tmpsig, 0, 64);
|
||||
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
91
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.h
generated
vendored
Normal file
91
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.h
generated
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2015 Pieter Wuille *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
/****
|
||||
* Please do not link this file directly. It is not part of the libsecp256k1
|
||||
* project and does not promise any stability in its API, functionality or
|
||||
* presence. Projects which use this code should instead copy this header
|
||||
* and its accompanying .c file directly into their codebase.
|
||||
****/
|
||||
|
||||
/* This file defines a function that parses DER with various errors and
|
||||
* violations. This is not a part of the library itself, because the allowed
|
||||
* violations are chosen arbitrarily and do not follow or establish any
|
||||
* standard.
|
||||
*
|
||||
* In many places it matters that different implementations do not only accept
|
||||
* the same set of valid signatures, but also reject the same set of signatures.
|
||||
* The only means to accomplish that is by strictly obeying a standard, and not
|
||||
* accepting anything else.
|
||||
*
|
||||
* Nonetheless, sometimes there is a need for compatibility with systems that
|
||||
* use signatures which do not strictly obey DER. The snippet below shows how
|
||||
* certain violations are easily supported. You may need to adapt it.
|
||||
*
|
||||
* Do not use this for new systems. Use well-defined DER or compact signatures
|
||||
* instead if you have the choice (see secp256k1_ecdsa_signature_parse_der and
|
||||
* secp256k1_ecdsa_signature_parse_compact).
|
||||
*
|
||||
* The supported violations are:
|
||||
* - All numbers are parsed as nonnegative integers, even though X.609-0207
|
||||
* section 8.3.3 specifies that integers are always encoded as two's
|
||||
* complement.
|
||||
* - Integers can have length 0, even though section 8.3.1 says they can't.
|
||||
* - Integers with overly long padding are accepted, violation section
|
||||
* 8.3.2.
|
||||
* - 127-byte long length descriptors are accepted, even though section
|
||||
* 8.1.3.5.c says that they are not.
|
||||
* - Trailing garbage data inside or after the signature is ignored.
|
||||
* - The length descriptor of the sequence is ignored.
|
||||
*
|
||||
* Compared to for example OpenSSL, many violations are NOT supported:
|
||||
* - Using overly long tag descriptors for the sequence or integers inside,
|
||||
* violating section 8.1.2.2.
|
||||
* - Encoding primitive integers as constructed values, violating section
|
||||
* 8.3.1.
|
||||
*/
|
||||
|
||||
#ifndef _SECP256K1_CONTRIB_LAX_DER_PARSING_H_
|
||||
#define _SECP256K1_CONTRIB_LAX_DER_PARSING_H_
|
||||
|
||||
#include <secp256k1.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/** Parse a signature in "lax DER" format
|
||||
*
|
||||
* Returns: 1 when the signature could be parsed, 0 otherwise.
|
||||
* Args: ctx: a secp256k1 context object
|
||||
* Out: sig: a pointer to a signature object
|
||||
* In: input: a pointer to the signature to be parsed
|
||||
* inputlen: the length of the array pointed to be input
|
||||
*
|
||||
* This function will accept any valid DER encoded signature, even if the
|
||||
* encoded numbers are out of range. In addition, it will accept signatures
|
||||
* which violate the DER spec in various ways. Its purpose is to allow
|
||||
* validation of the Bitcoin blockchain, which includes non-DER signatures
|
||||
* from before the network rules were updated to enforce DER. Note that
|
||||
* the set of supported violations is a strict subset of what OpenSSL will
|
||||
* accept.
|
||||
*
|
||||
* After the call, sig will always be initialized. If parsing failed or the
|
||||
* encoded numbers are out of range, signature validation with it is
|
||||
* guaranteed to fail for every message and public key.
|
||||
*/
|
||||
int ecdsa_signature_parse_der_lax(
|
||||
const secp256k1_context* ctx,
|
||||
secp256k1_ecdsa_signature* sig,
|
||||
const unsigned char *input,
|
||||
size_t inputlen
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
113
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_privatekey_parsing.c
generated
vendored
Normal file
113
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_privatekey_parsing.c
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2014, 2015 Pieter Wuille *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <secp256k1.h>
|
||||
|
||||
#include "lax_der_privatekey_parsing.h"
|
||||
|
||||
int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
|
||||
const unsigned char *end = privkey + privkeylen;
|
||||
int lenb = 0;
|
||||
int len = 0;
|
||||
memset(out32, 0, 32);
|
||||
/* sequence header */
|
||||
if (end < privkey+1 || *privkey != 0x30) {
|
||||
return 0;
|
||||
}
|
||||
privkey++;
|
||||
/* sequence length constructor */
|
||||
if (end < privkey+1 || !(*privkey & 0x80)) {
|
||||
return 0;
|
||||
}
|
||||
lenb = *privkey & ~0x80; privkey++;
|
||||
if (lenb < 1 || lenb > 2) {
|
||||
return 0;
|
||||
}
|
||||
if (end < privkey+lenb) {
|
||||
return 0;
|
||||
}
|
||||
/* sequence length */
|
||||
len = privkey[lenb-1] | (lenb > 1 ? privkey[lenb-2] << 8 : 0);
|
||||
privkey += lenb;
|
||||
if (end < privkey+len) {
|
||||
return 0;
|
||||
}
|
||||
/* sequence element 0: version number (=1) */
|
||||
if (end < privkey+3 || privkey[0] != 0x02 || privkey[1] != 0x01 || privkey[2] != 0x01) {
|
||||
return 0;
|
||||
}
|
||||
privkey += 3;
|
||||
/* sequence element 1: octet string, up to 32 bytes */
|
||||
if (end < privkey+2 || privkey[0] != 0x04 || privkey[1] > 0x20 || end < privkey+2+privkey[1]) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
|
||||
if (!secp256k1_ec_seckey_verify(ctx, out32)) {
|
||||
memset(out32, 0, 32);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
|
||||
secp256k1_pubkey pubkey;
|
||||
size_t pubkeylen = 0;
|
||||
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
|
||||
*privkeylen = 0;
|
||||
return 0;
|
||||
}
|
||||
if (compressed) {
|
||||
static const unsigned char begin[] = {
|
||||
0x30,0x81,0xD3,0x02,0x01,0x01,0x04,0x20
|
||||
};
|
||||
static const unsigned char middle[] = {
|
||||
0xA0,0x81,0x85,0x30,0x81,0x82,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
|
||||
0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
|
||||
0x21,0x02,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
|
||||
0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
|
||||
0x17,0x98,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
|
||||
0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x24,0x03,0x22,0x00
|
||||
};
|
||||
unsigned char *ptr = privkey;
|
||||
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
|
||||
memcpy(ptr, key32, 32); ptr += 32;
|
||||
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
|
||||
pubkeylen = 33;
|
||||
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
|
||||
ptr += pubkeylen;
|
||||
*privkeylen = ptr - privkey;
|
||||
} else {
|
||||
static const unsigned char begin[] = {
|
||||
0x30,0x82,0x01,0x13,0x02,0x01,0x01,0x04,0x20
|
||||
};
|
||||
static const unsigned char middle[] = {
|
||||
0xA0,0x81,0xA5,0x30,0x81,0xA2,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
|
||||
0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
|
||||
0x41,0x04,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
|
||||
0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
|
||||
0x17,0x98,0x48,0x3A,0xDA,0x77,0x26,0xA3,0xC4,0x65,0x5D,0xA4,0xFB,0xFC,0x0E,0x11,
|
||||
0x08,0xA8,0xFD,0x17,0xB4,0x48,0xA6,0x85,0x54,0x19,0x9C,0x47,0xD0,0x8F,0xFB,0x10,
|
||||
0xD4,0xB8,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
|
||||
0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x44,0x03,0x42,0x00
|
||||
};
|
||||
unsigned char *ptr = privkey;
|
||||
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
|
||||
memcpy(ptr, key32, 32); ptr += 32;
|
||||
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
|
||||
pubkeylen = 65;
|
||||
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
|
||||
ptr += pubkeylen;
|
||||
*privkeylen = ptr - privkey;
|
||||
}
|
||||
return 1;
|
||||
}
|
90
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_privatekey_parsing.h
generated
vendored
Normal file
90
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_privatekey_parsing.h
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2014, 2015 Pieter Wuille *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
/****
|
||||
* Please do not link this file directly. It is not part of the libsecp256k1
|
||||
* project and does not promise any stability in its API, functionality or
|
||||
* presence. Projects which use this code should instead copy this header
|
||||
* and its accompanying .c file directly into their codebase.
|
||||
****/
|
||||
|
||||
/* This file contains code snippets that parse DER private keys with
|
||||
* various errors and violations. This is not a part of the library
|
||||
* itself, because the allowed violations are chosen arbitrarily and
|
||||
* do not follow or establish any standard.
|
||||
*
|
||||
* It also contains code to serialize private keys in a compatible
|
||||
* manner.
|
||||
*
|
||||
* These functions are meant for compatibility with applications
|
||||
* that require BER encoded keys. When working with secp256k1-specific
|
||||
* code, the simple 32-byte private keys normally used by the
|
||||
* library are sufficient.
|
||||
*/
|
||||
|
||||
#ifndef _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_
|
||||
#define _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_
|
||||
|
||||
#include <secp256k1.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
/** Export a private key in DER format.
|
||||
*
|
||||
* Returns: 1 if the private key was valid.
|
||||
* Args: ctx: pointer to a context object, initialized for signing (cannot
|
||||
* be NULL)
|
||||
* Out: privkey: pointer to an array for storing the private key in BER.
|
||||
* Should have space for 279 bytes, and cannot be NULL.
|
||||
* privkeylen: Pointer to an int where the length of the private key in
|
||||
* privkey will be stored.
|
||||
* In: seckey: pointer to a 32-byte secret key to export.
|
||||
* compressed: 1 if the key should be exported in
|
||||
* compressed format, 0 otherwise
|
||||
*
|
||||
* This function is purely meant for compatibility with applications that
|
||||
* require BER encoded keys. When working with secp256k1-specific code, the
|
||||
* simple 32-byte private keys are sufficient.
|
||||
*
|
||||
* Note that this function does not guarantee correct DER output. It is
|
||||
* guaranteed to be parsable by secp256k1_ec_privkey_import_der
|
||||
*/
|
||||
SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der(
|
||||
const secp256k1_context* ctx,
|
||||
unsigned char *privkey,
|
||||
size_t *privkeylen,
|
||||
const unsigned char *seckey,
|
||||
int compressed
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
|
||||
|
||||
/** Import a private key in DER format.
|
||||
* Returns: 1 if a private key was extracted.
|
||||
* Args: ctx: pointer to a context object (cannot be NULL).
|
||||
* Out: seckey: pointer to a 32-byte array for storing the private key.
|
||||
* (cannot be NULL).
|
||||
* In: privkey: pointer to a private key in DER format (cannot be NULL).
|
||||
* privkeylen: length of the DER private key pointed to be privkey.
|
||||
*
|
||||
* This function will accept more than just strict DER, and even allow some BER
|
||||
* violations. The public key stored inside the DER-encoded private key is not
|
||||
* verified for correctness, nor are the curve parameters. Use this function
|
||||
* only if you know in advance it is supposed to contain a secp256k1 private
|
||||
* key.
|
||||
*/
|
||||
SECP256K1_WARN_UNUSED_RESULT int ec_privkey_import_der(
|
||||
const secp256k1_context* ctx,
|
||||
unsigned char *seckey,
|
||||
const unsigned char *privkey,
|
||||
size_t privkeylen
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
377
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_NativeSecp256k1.c
generated
vendored
Normal file
377
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_NativeSecp256k1.c
generated
vendored
Normal file
|
@ -0,0 +1,377 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "org_bitcoin_NativeSecp256k1.h"
|
||||
#include "include/secp256k1.h"
|
||||
#include "include/secp256k1_ecdh.h"
|
||||
#include "include/secp256k1_recovery.h"
|
||||
|
||||
|
||||
SECP256K1_API jlong JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ctx_1clone
|
||||
(JNIEnv* env, jclass classObject, jlong ctx_l)
|
||||
{
|
||||
const secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
|
||||
jlong ctx_clone_l = (uintptr_t) secp256k1_context_clone(ctx);
|
||||
|
||||
(void)classObject;(void)env;
|
||||
|
||||
return ctx_clone_l;
|
||||
|
||||
}
|
||||
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1context_1randomize
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
|
||||
const unsigned char* seed = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return secp256k1_context_randomize(ctx, seed);
|
||||
|
||||
}
|
||||
|
||||
SECP256K1_API void JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1destroy_1context
|
||||
(JNIEnv* env, jclass classObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
|
||||
secp256k1_context_destroy(ctx);
|
||||
|
||||
(void)classObject;(void)env;
|
||||
}
|
||||
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1verify
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint siglen, jint publen)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
|
||||
unsigned char* data = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* sigdata = { (unsigned char*) (data + 32) };
|
||||
const unsigned char* pubdata = { (unsigned char*) (data + siglen + 32) };
|
||||
|
||||
secp256k1_ecdsa_signature sig;
|
||||
secp256k1_pubkey pubkey;
|
||||
|
||||
int ret = secp256k1_ecdsa_signature_parse_der(ctx, &sig, sigdata, siglen);
|
||||
|
||||
if( ret ) {
|
||||
ret = secp256k1_ec_pubkey_parse(ctx, &pubkey, pubdata, publen);
|
||||
|
||||
if( ret ) {
|
||||
ret = secp256k1_ecdsa_verify(ctx, &sig, data, &pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1sign
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
unsigned char* data = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
unsigned char* secKey = (unsigned char*) (data + 32);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray sigArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
|
||||
secp256k1_ecdsa_signature sig[72];
|
||||
|
||||
int ret = secp256k1_ecdsa_sign(ctx, sig, data, secKey, NULL, NULL );
|
||||
|
||||
unsigned char outputSer[72];
|
||||
size_t outputLen = 72;
|
||||
|
||||
if( ret ) {
|
||||
int ret2 = secp256k1_ecdsa_signature_serialize_der(ctx,outputSer, &outputLen, sig ); (void)ret2;
|
||||
}
|
||||
|
||||
intsarray[0] = outputLen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
sigArray = (*env)->NewByteArray(env, outputLen);
|
||||
(*env)->SetByteArrayRegion(env, sigArray, 0, outputLen, (jbyte*)outputSer);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, sigArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
||||
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
unsigned char* secKey = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return secp256k1_ec_seckey_verify(ctx, secKey);
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1pubkey_1create
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
const unsigned char* secKey = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
|
||||
secp256k1_pubkey pubkey;
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray pubkeyArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
|
||||
int ret = secp256k1_ec_pubkey_create(ctx, &pubkey, secKey);
|
||||
|
||||
unsigned char outputSer[65];
|
||||
size_t outputLen = 65;
|
||||
|
||||
if( ret ) {
|
||||
int ret2 = secp256k1_ec_pubkey_serialize(ctx,outputSer, &outputLen, &pubkey,SECP256K1_EC_UNCOMPRESSED );(void)ret2;
|
||||
}
|
||||
|
||||
intsarray[0] = outputLen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
pubkeyArray = (*env)->NewByteArray(env, outputLen);
|
||||
(*env)->SetByteArrayRegion(env, pubkeyArray, 0, outputLen, (jbyte*)outputSer);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, pubkeyArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1add
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
unsigned char* privkey = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* tweak = (unsigned char*) (privkey + 32);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray privArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
|
||||
int privkeylen = 32;
|
||||
|
||||
int ret = secp256k1_ec_privkey_tweak_add(ctx, privkey, tweak);
|
||||
|
||||
intsarray[0] = privkeylen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
privArray = (*env)->NewByteArray(env, privkeylen);
|
||||
(*env)->SetByteArrayRegion(env, privArray, 0, privkeylen, (jbyte*)privkey);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, privArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1mul
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
unsigned char* privkey = (unsigned char*) (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* tweak = (unsigned char*) (privkey + 32);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray privArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
|
||||
int privkeylen = 32;
|
||||
|
||||
int ret = secp256k1_ec_privkey_tweak_mul(ctx, privkey, tweak);
|
||||
|
||||
intsarray[0] = privkeylen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
privArray = (*env)->NewByteArray(env, privkeylen);
|
||||
(*env)->SetByteArrayRegion(env, privArray, 0, privkeylen, (jbyte*)privkey);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, privArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1add
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
/* secp256k1_pubkey* pubkey = (secp256k1_pubkey*) (*env)->GetDirectBufferAddress(env, byteBufferObject);*/
|
||||
unsigned char* pkey = (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* tweak = (unsigned char*) (pkey + publen);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray pubArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
unsigned char outputSer[65];
|
||||
size_t outputLen = 65;
|
||||
|
||||
secp256k1_pubkey pubkey;
|
||||
int ret = secp256k1_ec_pubkey_parse(ctx, &pubkey, pkey, publen);
|
||||
|
||||
if( ret ) {
|
||||
ret = secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, tweak);
|
||||
}
|
||||
|
||||
if( ret ) {
|
||||
int ret2 = secp256k1_ec_pubkey_serialize(ctx,outputSer, &outputLen, &pubkey,SECP256K1_EC_UNCOMPRESSED );(void)ret2;
|
||||
}
|
||||
|
||||
intsarray[0] = outputLen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
pubArray = (*env)->NewByteArray(env, outputLen);
|
||||
(*env)->SetByteArrayRegion(env, pubArray, 0, outputLen, (jbyte*)outputSer);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, pubArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1mul
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
unsigned char* pkey = (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* tweak = (unsigned char*) (pkey + publen);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray pubArray, intsByteArray;
|
||||
unsigned char intsarray[2];
|
||||
unsigned char outputSer[65];
|
||||
size_t outputLen = 65;
|
||||
|
||||
secp256k1_pubkey pubkey;
|
||||
int ret = secp256k1_ec_pubkey_parse(ctx, &pubkey, pkey, publen);
|
||||
|
||||
if ( ret ) {
|
||||
ret = secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey, tweak);
|
||||
}
|
||||
|
||||
if( ret ) {
|
||||
int ret2 = secp256k1_ec_pubkey_serialize(ctx,outputSer, &outputLen, &pubkey,SECP256K1_EC_UNCOMPRESSED );(void)ret2;
|
||||
}
|
||||
|
||||
intsarray[0] = outputLen;
|
||||
intsarray[1] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
pubArray = (*env)->NewByteArray(env, outputLen);
|
||||
(*env)->SetByteArrayRegion(env, pubArray, 0, outputLen, (jbyte*)outputSer);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, pubArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 2);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 2, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
||||
|
||||
SECP256K1_API jlong JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1pubkey_1combine
|
||||
(JNIEnv * env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint numkeys)
|
||||
{
|
||||
(void)classObject;(void)env;(void)byteBufferObject;(void)ctx_l;(void)numkeys;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdh
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen)
|
||||
{
|
||||
secp256k1_context *ctx = (secp256k1_context*)(uintptr_t)ctx_l;
|
||||
const unsigned char* secdata = (*env)->GetDirectBufferAddress(env, byteBufferObject);
|
||||
const unsigned char* pubdata = (const unsigned char*) (secdata + 32);
|
||||
|
||||
jobjectArray retArray;
|
||||
jbyteArray outArray, intsByteArray;
|
||||
unsigned char intsarray[1];
|
||||
secp256k1_pubkey pubkey;
|
||||
unsigned char nonce_res[32];
|
||||
size_t outputLen = 32;
|
||||
|
||||
int ret = secp256k1_ec_pubkey_parse(ctx, &pubkey, pubdata, publen);
|
||||
|
||||
if (ret) {
|
||||
ret = secp256k1_ecdh(
|
||||
ctx,
|
||||
nonce_res,
|
||||
&pubkey,
|
||||
secdata
|
||||
);
|
||||
}
|
||||
|
||||
intsarray[0] = ret;
|
||||
|
||||
retArray = (*env)->NewObjectArray(env, 2,
|
||||
(*env)->FindClass(env, "[B"),
|
||||
(*env)->NewByteArray(env, 1));
|
||||
|
||||
outArray = (*env)->NewByteArray(env, outputLen);
|
||||
(*env)->SetByteArrayRegion(env, outArray, 0, 32, (jbyte*)nonce_res);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 0, outArray);
|
||||
|
||||
intsByteArray = (*env)->NewByteArray(env, 1);
|
||||
(*env)->SetByteArrayRegion(env, intsByteArray, 0, 1, (jbyte*)intsarray);
|
||||
(*env)->SetObjectArrayElement(env, retArray, 1, intsByteArray);
|
||||
|
||||
(void)classObject;
|
||||
|
||||
return retArray;
|
||||
}
|
119
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_NativeSecp256k1.h
generated
vendored
Normal file
119
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_NativeSecp256k1.h
generated
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
#include "include/secp256k1.h"
|
||||
/* Header for class org_bitcoin_NativeSecp256k1 */
|
||||
|
||||
#ifndef _Included_org_bitcoin_NativeSecp256k1
|
||||
#define _Included_org_bitcoin_NativeSecp256k1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ctx_clone
|
||||
* Signature: (J)J
|
||||
*/
|
||||
SECP256K1_API jlong JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ctx_1clone
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_context_randomize
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)I
|
||||
*/
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1context_1randomize
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_privkey_tweak_add
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1add
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_privkey_tweak_mul
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1mul
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_pubkey_tweak_add
|
||||
* Signature: (Ljava/nio/ByteBuffer;JI)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1add
|
||||
(JNIEnv *, jclass, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_pubkey_tweak_mul
|
||||
* Signature: (Ljava/nio/ByteBuffer;JI)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1mul
|
||||
(JNIEnv *, jclass, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_destroy_context
|
||||
* Signature: (J)V
|
||||
*/
|
||||
SECP256K1_API void JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1destroy_1context
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ecdsa_verify
|
||||
* Signature: (Ljava/nio/ByteBuffer;JII)I
|
||||
*/
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1verify
|
||||
(JNIEnv *, jclass, jobject, jlong, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ecdsa_sign
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1sign
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ec_seckey_verify
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)I
|
||||
*/
|
||||
SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ec_pubkey_create
|
||||
* Signature: (Ljava/nio/ByteBuffer;J)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1pubkey_1create
|
||||
(JNIEnv *, jclass, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ec_pubkey_parse
|
||||
* Signature: (Ljava/nio/ByteBuffer;JI)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1pubkey_1parse
|
||||
(JNIEnv *, jclass, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: org_bitcoin_NativeSecp256k1
|
||||
* Method: secp256k1_ecdh
|
||||
* Signature: (Ljava/nio/ByteBuffer;JI)[[B
|
||||
*/
|
||||
SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdh
|
||||
(JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
15
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.c
generated
vendored
Normal file
15
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.c
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "org_bitcoin_Secp256k1Context.h"
|
||||
#include "include/secp256k1.h"
|
||||
|
||||
SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context
|
||||
(JNIEnv* env, jclass classObject)
|
||||
{
|
||||
secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
|
||||
|
||||
(void)classObject;(void)env;
|
||||
|
||||
return (uintptr_t)ctx;
|
||||
}
|
||||
|
22
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.h
generated
vendored
Normal file
22
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.h
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
#include "include/secp256k1.h"
|
||||
/* Header for class org_bitcoin_Secp256k1Context */
|
||||
|
||||
#ifndef _Included_org_bitcoin_Secp256k1Context
|
||||
#define _Included_org_bitcoin_Secp256k1Context
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_bitcoin_Secp256k1Context
|
||||
* Method: secp256k1_init_context
|
||||
* Signature: ()J
|
||||
*/
|
||||
SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
54
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/main_impl.h
generated
vendored
Normal file
54
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/main_impl.h
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2015 Andrew Poelstra *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef _SECP256K1_MODULE_ECDH_MAIN_
|
||||
#define _SECP256K1_MODULE_ECDH_MAIN_
|
||||
|
||||
#include "include/secp256k1_ecdh.h"
|
||||
#include "ecmult_const_impl.h"
|
||||
|
||||
int secp256k1_ecdh(const secp256k1_context* ctx, unsigned char *result, const secp256k1_pubkey *point, const unsigned char *scalar) {
|
||||
int ret = 0;
|
||||
int overflow = 0;
|
||||
secp256k1_gej res;
|
||||
secp256k1_ge pt;
|
||||
secp256k1_scalar s;
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(result != NULL);
|
||||
ARG_CHECK(point != NULL);
|
||||
ARG_CHECK(scalar != NULL);
|
||||
|
||||
secp256k1_pubkey_load(ctx, &pt, point);
|
||||
secp256k1_scalar_set_b32(&s, scalar, &overflow);
|
||||
if (overflow || secp256k1_scalar_is_zero(&s)) {
|
||||
ret = 0;
|
||||
} else {
|
||||
unsigned char x[32];
|
||||
unsigned char y[1];
|
||||
secp256k1_sha256_t sha;
|
||||
|
||||
secp256k1_ecmult_const(&res, &pt, &s);
|
||||
secp256k1_ge_set_gej(&pt, &res);
|
||||
/* Compute a hash of the point in compressed form
|
||||
* Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not
|
||||
* expect its output to be secret and has a timing sidechannel. */
|
||||
secp256k1_fe_normalize(&pt.x);
|
||||
secp256k1_fe_normalize(&pt.y);
|
||||
secp256k1_fe_get_b32(x, &pt.x);
|
||||
y[0] = 0x02 | secp256k1_fe_is_odd(&pt.y);
|
||||
|
||||
secp256k1_sha256_initialize(&sha);
|
||||
secp256k1_sha256_write(&sha, y, sizeof(y));
|
||||
secp256k1_sha256_write(&sha, x, sizeof(x));
|
||||
secp256k1_sha256_finalize(&sha, result);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
secp256k1_scalar_clear(&s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
105
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/tests_impl.h
generated
vendored
Normal file
105
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/tests_impl.h
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2015 Andrew Poelstra *
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef _SECP256K1_MODULE_ECDH_TESTS_
|
||||
#define _SECP256K1_MODULE_ECDH_TESTS_
|
||||
|
||||
void test_ecdh_api(void) {
|
||||
/* Setup context that just counts errors */
|
||||
secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
|
||||
secp256k1_pubkey point;
|
||||
unsigned char res[32];
|
||||
unsigned char s_one[32] = { 0 };
|
||||
int32_t ecount = 0;
|
||||
s_one[31] = 1;
|
||||
|
||||
secp256k1_context_set_error_callback(tctx, counting_illegal_callback_fn, &ecount);
|
||||
secp256k1_context_set_illegal_callback(tctx, counting_illegal_callback_fn, &ecount);
|
||||
CHECK(secp256k1_ec_pubkey_create(tctx, &point, s_one) == 1);
|
||||
|
||||
/* Check all NULLs are detected */
|
||||
CHECK(secp256k1_ecdh(tctx, res, &point, s_one) == 1);
|
||||
CHECK(ecount == 0);
|
||||
CHECK(secp256k1_ecdh(tctx, NULL, &point, s_one) == 0);
|
||||
CHECK(ecount == 1);
|
||||
CHECK(secp256k1_ecdh(tctx, res, NULL, s_one) == 0);
|
||||
CHECK(ecount == 2);
|
||||
CHECK(secp256k1_ecdh(tctx, res, &point, NULL) == 0);
|
||||
CHECK(ecount == 3);
|
||||
CHECK(secp256k1_ecdh(tctx, res, &point, s_one) == 1);
|
||||
CHECK(ecount == 3);
|
||||
|
||||
/* Cleanup */
|
||||
secp256k1_context_destroy(tctx);
|
||||
}
|
||||
|
||||
void test_ecdh_generator_basepoint(void) {
|
||||
unsigned char s_one[32] = { 0 };
|
||||
secp256k1_pubkey point[2];
|
||||
int i;
|
||||
|
||||
s_one[31] = 1;
|
||||
/* Check against pubkey creation when the basepoint is the generator */
|
||||
for (i = 0; i < 100; ++i) {
|
||||
secp256k1_sha256_t sha;
|
||||
unsigned char s_b32[32];
|
||||
unsigned char output_ecdh[32];
|
||||
unsigned char output_ser[32];
|
||||
unsigned char point_ser[33];
|
||||
size_t point_ser_len = sizeof(point_ser);
|
||||
secp256k1_scalar s;
|
||||
|
||||
random_scalar_order(&s);
|
||||
secp256k1_scalar_get_b32(s_b32, &s);
|
||||
|
||||
/* compute using ECDH function */
|
||||
CHECK(secp256k1_ec_pubkey_create(ctx, &point[0], s_one) == 1);
|
||||
CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32) == 1);
|
||||
/* compute "explicitly" */
|
||||
CHECK(secp256k1_ec_pubkey_create(ctx, &point[1], s_b32) == 1);
|
||||
CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1);
|
||||
CHECK(point_ser_len == sizeof(point_ser));
|
||||
secp256k1_sha256_initialize(&sha);
|
||||
secp256k1_sha256_write(&sha, point_ser, point_ser_len);
|
||||
secp256k1_sha256_finalize(&sha, output_ser);
|
||||
/* compare */
|
||||
CHECK(memcmp(output_ecdh, output_ser, sizeof(output_ser)) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void test_bad_scalar(void) {
|
||||
unsigned char s_zero[32] = { 0 };
|
||||
unsigned char s_overflow[32] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
|
||||
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
|
||||
0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
|
||||
};
|
||||
unsigned char s_rand[32] = { 0 };
|
||||
unsigned char output[32];
|
||||
secp256k1_scalar rand;
|
||||
secp256k1_pubkey point;
|
||||
|
||||
/* Create random point */
|
||||
random_scalar_order(&rand);
|
||||
secp256k1_scalar_get_b32(s_rand, &rand);
|
||||
CHECK(secp256k1_ec_pubkey_create(ctx, &point, s_rand) == 1);
|
||||
|
||||
/* Try to multiply it by bad values */
|
||||
CHECK(secp256k1_ecdh(ctx, output, &point, s_zero) == 0);
|
||||
CHECK(secp256k1_ecdh(ctx, output, &point, s_overflow) == 0);
|
||||
/* ...and a good one */
|
||||
s_overflow[31] -= 1;
|
||||
CHECK(secp256k1_ecdh(ctx, output, &point, s_overflow) == 1);
|
||||
}
|
||||
|
||||
void run_ecdh_tests(void) {
|
||||
test_ecdh_api();
|
||||
test_ecdh_generator_basepoint();
|
||||
test_bad_scalar();
|
||||
}
|
||||
|
||||
#endif
|
35
vendor/github.com/mutecomm/go-sqlcipher/v4/_example/mod_regexp/sqlite3_mod_regexp.c
generated
vendored
Normal file
35
vendor/github.com/mutecomm/go-sqlcipher/v4/_example/mod_regexp/sqlite3_mod_regexp.c
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <pcre.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
|
||||
if (argc >= 2) {
|
||||
const char *target = (const char *)sqlite3_value_text(argv[1]);
|
||||
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
|
||||
const char* errstr = NULL;
|
||||
int erroff = 0;
|
||||
int vec[500];
|
||||
int n, rc;
|
||||
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
|
||||
if (!re) {
|
||||
sqlite3_result_error(context, errstr, 0);
|
||||
return;
|
||||
}
|
||||
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
|
||||
if (rc <= 0) {
|
||||
sqlite3_result_int(context, 0);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_int(context, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
|
||||
SQLITE_EXTENSION_INIT2(api);
|
||||
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, (void*)db, regexp_func, NULL, NULL);
|
||||
}
|
1040
vendor/github.com/mutecomm/go-sqlcipher/v4/_example/mod_vtable/picojson.h
generated
vendored
Normal file
1040
vendor/github.com/mutecomm/go-sqlcipher/v4/_example/mod_vtable/picojson.h
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
80
vendor/github.com/waku-org/go-waku/waku/persistence/sql_queries.go
generated
vendored
Normal file
80
vendor/github.com/waku-org/go-waku/waku/persistence/sql_queries.go
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
package persistence
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Queries are the SQL queries for a given table.
|
||||
type Queries struct {
|
||||
deleteQuery string
|
||||
existsQuery string
|
||||
getQuery string
|
||||
putQuery string
|
||||
queryQuery string
|
||||
prefixQuery string
|
||||
limitQuery string
|
||||
offsetQuery string
|
||||
getSizeQuery string
|
||||
}
|
||||
|
||||
// CreateQueries Function creates a set of queries for an SQL table.
|
||||
// Note: Do not use this function to create queries for a table, rather use <rdb>.NewQueries to create table as well as queries.
|
||||
func CreateQueries(tbl string, db *sql.DB) *Queries {
|
||||
return &Queries{
|
||||
deleteQuery: fmt.Sprintf("DELETE FROM %s WHERE key = $1", tbl),
|
||||
existsQuery: fmt.Sprintf("SELECT exists(SELECT 1 FROM %s WHERE key=$1)", tbl),
|
||||
getQuery: fmt.Sprintf("SELECT data FROM %s WHERE key = $1", tbl),
|
||||
putQuery: fmt.Sprintf("INSERT INTO %s (key, data) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET data = $2", tbl),
|
||||
queryQuery: fmt.Sprintf("SELECT key, data FROM %s", tbl),
|
||||
prefixQuery: ` WHERE key LIKE '%s%%' ORDER BY key`,
|
||||
limitQuery: ` LIMIT %d`,
|
||||
offsetQuery: ` OFFSET %d`,
|
||||
getSizeQuery: fmt.Sprintf("SELECT length(data) FROM %s WHERE key = $1", tbl),
|
||||
}
|
||||
}
|
||||
|
||||
// Delete returns the query for deleting a row.
|
||||
func (q Queries) Delete() string {
|
||||
return q.deleteQuery
|
||||
}
|
||||
|
||||
// Exists returns the query for determining if a row exists.
|
||||
func (q Queries) Exists() string {
|
||||
return q.existsQuery
|
||||
}
|
||||
|
||||
// Get returns the query for getting a row.
|
||||
func (q Queries) Get() string {
|
||||
return q.getQuery
|
||||
}
|
||||
|
||||
// Put returns the query for putting a row.
|
||||
func (q Queries) Put() string {
|
||||
return q.putQuery
|
||||
}
|
||||
|
||||
// Query returns the query for getting multiple rows.
|
||||
func (q Queries) Query() string {
|
||||
return q.queryQuery
|
||||
}
|
||||
|
||||
// Prefix returns the query fragment for getting a rows with a key prefix.
|
||||
func (q Queries) Prefix() string {
|
||||
return q.prefixQuery
|
||||
}
|
||||
|
||||
// Limit returns the query fragment for limiting results.
|
||||
func (q Queries) Limit() string {
|
||||
return q.limitQuery
|
||||
}
|
||||
|
||||
// Offset returns the query fragment for returning rows from a given offset.
|
||||
func (q Queries) Offset() string {
|
||||
return q.offsetQuery
|
||||
}
|
||||
|
||||
// GetSize returns the query for determining the size of a value.
|
||||
func (q Queries) GetSize() string {
|
||||
return q.getSizeQuery
|
||||
}
|
|
@ -19,6 +19,7 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// MessageProvider is an interface that provides access to store/retrieve messages from a persistence store.
|
||||
type MessageProvider interface {
|
||||
GetAll() ([]StoredMessage, error)
|
||||
Validate(env *protocol.Envelope) error
|
||||
|
@ -29,8 +30,13 @@ type MessageProvider interface {
|
|||
Stop()
|
||||
}
|
||||
|
||||
// ErrInvalidCursor indicates that an invalid cursor has been passed to access store
|
||||
var ErrInvalidCursor = errors.New("invalid cursor")
|
||||
|
||||
// ErrFutureMessage indicates that a message with timestamp in future was requested to be stored
|
||||
var ErrFutureMessage = errors.New("message timestamp in the future")
|
||||
|
||||
// ErrMessageTooOld indicates that a message that was too old was requested to be stored.
|
||||
var ErrMessageTooOld = errors.New("message too old")
|
||||
|
||||
// WALMode for sqlite.
|
||||
|
@ -58,6 +64,7 @@ type DBStore struct {
|
|||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// StoredMessage is the format of the message stored in persistence store
|
||||
type StoredMessage struct {
|
||||
ID []byte
|
||||
PubsubTopic string
|
||||
|
@ -76,6 +83,7 @@ func WithDB(db *sql.DB) DBOption {
|
|||
}
|
||||
}
|
||||
|
||||
// ConnectionPoolOptions is the options to be used for DB connection pooling
|
||||
type ConnectionPoolOptions struct {
|
||||
MaxOpenConnections int
|
||||
MaxIdleConnections int
|
||||
|
@ -123,6 +131,7 @@ func WithMigrations(migrationFn func(db *sql.DB) error) DBOption {
|
|||
}
|
||||
}
|
||||
|
||||
// DefaultOptions returns the default DBoptions to be used.
|
||||
func DefaultOptions() []DBOption {
|
||||
return []DBOption{}
|
||||
}
|
||||
|
@ -154,6 +163,7 @@ func NewDBStore(log *zap.Logger, options ...DBOption) (*DBStore, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// Start starts the store server functionality
|
||||
func (d *DBStore) Start(ctx context.Context, timesource timesource.Timesource) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
|
@ -172,17 +182,17 @@ func (d *DBStore) Start(ctx context.Context, timesource timesource.Timesource) e
|
|||
return nil
|
||||
}
|
||||
|
||||
func (store *DBStore) updateMetrics(ctx context.Context) {
|
||||
func (d *DBStore) updateMetrics(ctx context.Context) {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
defer ticker.Stop()
|
||||
defer store.wg.Done()
|
||||
defer d.wg.Done()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
msgCount, err := store.Count()
|
||||
msgCount, err := d.Count()
|
||||
if err != nil {
|
||||
store.log.Error("updating store metrics", zap.Error(err))
|
||||
d.log.Error("updating store metrics", zap.Error(err))
|
||||
} else {
|
||||
metrics.RecordArchiveMessage(ctx, "stored", msgCount)
|
||||
}
|
||||
|
@ -256,6 +266,7 @@ func (d *DBStore) Stop() {
|
|||
d.db.Close()
|
||||
}
|
||||
|
||||
// Validate validates the message to be stored against possible fradulent conditions.
|
||||
func (d *DBStore) Validate(env *protocol.Envelope) error {
|
||||
n := time.Unix(0, env.Index().ReceiverTime)
|
||||
upperBound := n.Add(MaxTimeVariance)
|
||||
|
@ -300,21 +311,65 @@ func (d *DBStore) Put(env *protocol.Envelope) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Query retrieves messages from the DB
|
||||
func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, error) {
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
elapsed := time.Since(start)
|
||||
d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed))
|
||||
}()
|
||||
func (d *DBStore) handleQueryCursor(query *pb.HistoryQuery, paramCnt *int, conditions []string, parameters []interface{}) ([]string, []interface{}, error) {
|
||||
usesCursor := false
|
||||
if query.PagingInfo.Cursor != nil {
|
||||
usesCursor = true
|
||||
var exists bool
|
||||
cursorDBKey := NewDBKey(uint64(query.PagingInfo.Cursor.SenderTime), uint64(query.PagingInfo.Cursor.ReceiverTime), query.PagingInfo.Cursor.PubsubTopic, query.PagingInfo.Cursor.Digest)
|
||||
|
||||
err := d.db.QueryRow("SELECT EXISTS(SELECT 1 FROM message WHERE id = $1)",
|
||||
cursorDBKey.Bytes(),
|
||||
).Scan(&exists)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if exists {
|
||||
eqOp := ">"
|
||||
if query.PagingInfo.Direction == pb.PagingInfo_BACKWARD {
|
||||
eqOp = "<"
|
||||
}
|
||||
*paramCnt++
|
||||
conditions = append(conditions, fmt.Sprintf("id %s $%d", eqOp, *paramCnt))
|
||||
|
||||
parameters = append(parameters, cursorDBKey.Bytes())
|
||||
} else {
|
||||
return nil, nil, ErrInvalidCursor
|
||||
}
|
||||
}
|
||||
|
||||
handleTimeParam := func(time int64, op string) {
|
||||
*paramCnt++
|
||||
conditions = append(conditions, fmt.Sprintf("id %s $%d", op, *paramCnt))
|
||||
timeDBKey := NewDBKey(uint64(time), uint64(time), "", []byte{})
|
||||
parameters = append(parameters, timeDBKey.Bytes())
|
||||
}
|
||||
|
||||
if query.StartTime != 0 {
|
||||
if !usesCursor || query.PagingInfo.Direction == pb.PagingInfo_BACKWARD {
|
||||
handleTimeParam(query.StartTime, ">=")
|
||||
}
|
||||
}
|
||||
|
||||
if query.EndTime != 0 {
|
||||
if !usesCursor || query.PagingInfo.Direction == pb.PagingInfo_FORWARD {
|
||||
handleTimeParam(query.EndTime, "<=")
|
||||
}
|
||||
}
|
||||
return conditions, parameters, nil
|
||||
}
|
||||
|
||||
func (d *DBStore) prepareQuerySQL(query *pb.HistoryQuery) (string, []interface{}, error) {
|
||||
sqlQuery := `SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version
|
||||
FROM message
|
||||
%s
|
||||
ORDER BY senderTimestamp %s, id %s, pubsubTopic %s, receiverTimestamp %s `
|
||||
FROM message
|
||||
%s
|
||||
ORDER BY senderTimestamp %s, id %s, pubsubTopic %s, receiverTimestamp %s `
|
||||
|
||||
var conditions []string
|
||||
var parameters []interface{}
|
||||
//var parameters []interface{}
|
||||
parameters := make([]interface{}, 0) //Allocating as a slice so that references get passed rather than value
|
||||
paramCnt := 0
|
||||
|
||||
if query.PubsubTopic != "" {
|
||||
|
@ -335,53 +390,10 @@ func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, err
|
|||
conditions = append(conditions, "contentTopic IN ("+strings.Join(ctPlaceHolder, ", ")+")")
|
||||
}
|
||||
|
||||
usesCursor := false
|
||||
if query.PagingInfo.Cursor != nil {
|
||||
usesCursor = true
|
||||
var exists bool
|
||||
cursorDBKey := NewDBKey(uint64(query.PagingInfo.Cursor.SenderTime), uint64(query.PagingInfo.Cursor.ReceiverTime), query.PagingInfo.Cursor.PubsubTopic, query.PagingInfo.Cursor.Digest)
|
||||
|
||||
err := d.db.QueryRow("SELECT EXISTS(SELECT 1 FROM message WHERE id = $1)",
|
||||
cursorDBKey.Bytes(),
|
||||
).Scan(&exists)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if exists {
|
||||
eqOp := ">"
|
||||
if query.PagingInfo.Direction == pb.PagingInfo_BACKWARD {
|
||||
eqOp = "<"
|
||||
}
|
||||
paramCnt++
|
||||
conditions = append(conditions, fmt.Sprintf("id %s $%d", eqOp, paramCnt))
|
||||
|
||||
parameters = append(parameters, cursorDBKey.Bytes())
|
||||
} else {
|
||||
return nil, nil, ErrInvalidCursor
|
||||
}
|
||||
conditions, parameters, err := d.handleQueryCursor(query, ¶mCnt, conditions, parameters)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if query.StartTime != 0 {
|
||||
if !usesCursor || query.PagingInfo.Direction == pb.PagingInfo_BACKWARD {
|
||||
paramCnt++
|
||||
conditions = append(conditions, fmt.Sprintf("id >= $%d", paramCnt))
|
||||
startTimeDBKey := NewDBKey(uint64(query.StartTime), uint64(query.StartTime), "", []byte{})
|
||||
parameters = append(parameters, startTimeDBKey.Bytes())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if query.EndTime != 0 {
|
||||
if !usesCursor || query.PagingInfo.Direction == pb.PagingInfo_FORWARD {
|
||||
paramCnt++
|
||||
conditions = append(conditions, fmt.Sprintf("id <= $%d", paramCnt))
|
||||
endTimeDBKey := NewDBKey(uint64(query.EndTime), uint64(query.EndTime), "", []byte{})
|
||||
parameters = append(parameters, endTimeDBKey.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
conditionStr := ""
|
||||
if len(conditions) != 0 {
|
||||
conditionStr = "WHERE " + strings.Join(conditions, " AND ")
|
||||
|
@ -393,18 +405,36 @@ func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, err
|
|||
}
|
||||
|
||||
paramCnt++
|
||||
|
||||
sqlQuery += fmt.Sprintf("LIMIT $%d", paramCnt)
|
||||
sqlQuery = fmt.Sprintf(sqlQuery, conditionStr, orderDirection, orderDirection, orderDirection, orderDirection)
|
||||
d.log.Info(fmt.Sprintf("sqlQuery: %s", sqlQuery))
|
||||
|
||||
return sqlQuery, parameters, nil
|
||||
|
||||
}
|
||||
|
||||
// Query retrieves messages from the DB
|
||||
func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, error) {
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
elapsed := time.Since(start)
|
||||
d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed))
|
||||
}()
|
||||
|
||||
sqlQuery, parameters, err := d.prepareQuerySQL(query)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
stmt, err := d.db.Prepare(sqlQuery)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
pageSize := query.PagingInfo.PageSize + 1
|
||||
|
||||
parameters = append(parameters, pageSize)
|
||||
|
||||
measurementStart := time.Now()
|
||||
rows, err := stmt.Query(parameters...)
|
||||
if err != nil {
|
||||
|
|
|
@ -79,7 +79,7 @@ type PeerData struct {
|
|||
ENR *enode.Node
|
||||
}
|
||||
|
||||
// PeerChannel receives channels on which discovered peers should be pushed
|
||||
// Subscribe receives channels on which discovered peers should be pushed
|
||||
func (c *PeerConnectionStrategy) Subscribe(ctx context.Context, ch <-chan PeerData) {
|
||||
if c.cancel != nil {
|
||||
c.wg.Add(1)
|
||||
|
|
|
@ -241,6 +241,12 @@ func (d *DiscoveryV5) Stop() {
|
|||
|
||||
d.wg.Wait()
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
d.log.Info("recovering from panic and quitting")
|
||||
}
|
||||
}()
|
||||
|
||||
close(d.peerCh)
|
||||
}
|
||||
|
||||
|
@ -445,7 +451,3 @@ restartLoop:
|
|||
func (d *DiscoveryV5) IsStarted() bool {
|
||||
return d.started.Load()
|
||||
}
|
||||
|
||||
func (d *DiscoveryV5) PeerChannel() <-chan v2.PeerData {
|
||||
return d.peerCh
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) {
|
|||
rendezvousPoints = append(rendezvousPoints, peerID)
|
||||
}
|
||||
|
||||
w.rendezvous = rendezvous.NewRendezvous(w.opts.enableRendezvousServer, w.opts.rendezvousDB, rendezvousPoints, w.log)
|
||||
w.rendezvous = rendezvous.NewRendezvous(w.opts.enableRendezvousServer, w.opts.rendezvousDB, rendezvousPoints, w.peerConnector, w.log)
|
||||
w.relay = relay.NewWakuRelay(w.bcaster, w.opts.minRelayPeersToPublish, w.timesource, w.log, w.opts.wOpts...)
|
||||
w.legacyFilter = legacy_filter.NewWakuFilter(w.bcaster, w.opts.isLegacyFilterFullnode, w.timesource, w.log, w.opts.legacyFilterOpts...)
|
||||
w.filterFullnode = filter.NewWakuFilterFullnode(w.timesource, w.log, w.opts.filterOpts...)
|
||||
|
|
|
@ -26,6 +26,10 @@ type rendezvousPoint struct {
|
|||
cookie []byte
|
||||
}
|
||||
|
||||
type PeerConnector interface {
|
||||
Subscribe(context.Context, <-chan v2.PeerData)
|
||||
}
|
||||
|
||||
type Rendezvous struct {
|
||||
host host.Host
|
||||
|
||||
|
@ -34,14 +38,15 @@ type Rendezvous struct {
|
|||
rendezvousSvc *rvs.RendezvousService
|
||||
|
||||
rendezvousPoints []*rendezvousPoint
|
||||
peerCh chan v2.PeerData
|
||||
peerConnector PeerConnector
|
||||
|
||||
log *zap.Logger
|
||||
wg sync.WaitGroup
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func NewRendezvous(enableServer bool, db *DB, rendezvousPoints []peer.ID, log *zap.Logger) *Rendezvous {
|
||||
// NewRendezvous creates an instance of a Rendezvous which might act as rendezvous point for other nodes, or act as a client node
|
||||
func NewRendezvous(enableServer bool, db *DB, rendezvousPoints []peer.ID, peerConnector PeerConnector, log *zap.Logger) *Rendezvous {
|
||||
logger := log.Named("rendezvous")
|
||||
|
||||
var rendevousPoints []*rendezvousPoint
|
||||
|
@ -55,7 +60,7 @@ func NewRendezvous(enableServer bool, db *DB, rendezvousPoints []peer.ID, log *z
|
|||
enableServer: enableServer,
|
||||
db: db,
|
||||
rendezvousPoints: rendevousPoints,
|
||||
peerCh: make(chan v2.PeerData),
|
||||
peerConnector: peerConnector,
|
||||
log: logger,
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +96,6 @@ func (r *Rendezvous) getRandomServer() *rendezvousPoint {
|
|||
}
|
||||
|
||||
func (r *Rendezvous) Discover(ctx context.Context, topic string, numPeers int) {
|
||||
defer r.wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
@ -114,17 +118,22 @@ func (r *Rendezvous) Discover(ctx context.Context, topic string, numPeers int) {
|
|||
server.cookie = cookie
|
||||
server.Unlock()
|
||||
|
||||
peerCh := make(chan v2.PeerData)
|
||||
r.peerConnector.Subscribe(context.Background(), peerCh)
|
||||
for _, addr := range addrInfo {
|
||||
peer := v2.PeerData{
|
||||
Origin: peers.Rendezvous,
|
||||
AddrInfo: addr,
|
||||
}
|
||||
fmt.Println("PPPPPPPPPPPPPP")
|
||||
select {
|
||||
case r.peerCh <- peer:
|
||||
case peerCh <- peer:
|
||||
fmt.Println("DISCOVERED")
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
close(peerCh)
|
||||
} else {
|
||||
// TODO: improve this by adding an exponential backoff?
|
||||
time.Sleep(5 * time.Second)
|
||||
|
@ -190,10 +199,6 @@ func (r *Rendezvous) RegisterRelayShards(ctx context.Context, rs protocol.RelayS
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Rendezvous) PeerChannel() <-chan v2.PeerData {
|
||||
return r.peerCh
|
||||
}
|
||||
|
||||
func (r *Rendezvous) Stop() {
|
||||
r.cancel()
|
||||
r.wg.Wait()
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
// +build ingore
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
*
|
||||
* Copyright 2013 Garrett D'Amore <garrett@damore.org>
|
||||
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2004 Tim J. Robbins.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2011 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
* Portions of this software were developed by David Chisnall
|
||||
* under sponsorship from the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _MBLOCAL_H_
|
||||
#define _MBLOCAL_H_
|
||||
|
||||
#include <runetype.h>
|
||||
#include "xlocale_private.h"
|
||||
|
||||
#define SS2 0x008e
|
||||
#define SS3 0x008f
|
||||
|
||||
/*
|
||||
* Conversion function pointers for current encoding.
|
||||
*/
|
||||
struct xlocale_ctype {
|
||||
struct xlocale_component header;
|
||||
_RuneLocale *runes;
|
||||
size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
|
||||
size_t, mbstate_t * __restrict);
|
||||
int (*__mbsinit)(const mbstate_t *);
|
||||
size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
|
||||
size_t, size_t, mbstate_t * __restrict);
|
||||
size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
|
||||
size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
|
||||
size_t, size_t, mbstate_t * __restrict);
|
||||
int __mb_cur_max;
|
||||
int __mb_sb_limit;
|
||||
/** Persistent state used by mblen() calls. */
|
||||
__mbstate_t mblen;
|
||||
/** Persistent state used by mbrlen() calls. */
|
||||
__mbstate_t mbrlen;
|
||||
/** Persistent state used by mbrtoc16() calls. */
|
||||
__mbstate_t mbrtoc16;
|
||||
/** Persistent state used by mbrtoc32() calls. */
|
||||
__mbstate_t mbrtoc32;
|
||||
/** Persistent state used by mbrtowc() calls. */
|
||||
__mbstate_t mbrtowc;
|
||||
/** Persistent state used by mbsnrtowcs() calls. */
|
||||
__mbstate_t mbsnrtowcs;
|
||||
/** Persistent state used by mbsrtowcs() calls. */
|
||||
__mbstate_t mbsrtowcs;
|
||||
/** Persistent state used by mbtowc() calls. */
|
||||
__mbstate_t mbtowc;
|
||||
/** Persistent state used by c16rtomb() calls. */
|
||||
__mbstate_t c16rtomb;
|
||||
/** Persistent state used by c32rtomb() calls. */
|
||||
__mbstate_t c32rtomb;
|
||||
/** Persistent state used by wcrtomb() calls. */
|
||||
__mbstate_t wcrtomb;
|
||||
/** Persistent state used by wcsnrtombs() calls. */
|
||||
__mbstate_t wcsnrtombs;
|
||||
/** Persistent state used by wcsrtombs() calls. */
|
||||
__mbstate_t wcsrtombs;
|
||||
/** Persistent state used by wctomb() calls. */
|
||||
__mbstate_t wctomb;
|
||||
};
|
||||
#define XLOCALE_CTYPE(x) ((struct xlocale_ctype*)(x)->components[XLC_CTYPE])
|
||||
extern struct xlocale_ctype __xlocale_global_ctype;
|
||||
|
||||
/*
|
||||
* Rune initialization function prototypes.
|
||||
*/
|
||||
int _none_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _UTF8_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _EUC_CN_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _EUC_JP_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _EUC_KR_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _EUC_TW_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _GB18030_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _GB2312_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _GBK_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _BIG5_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _MSKanji_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
int _ascii_init(struct xlocale_ctype *, _RuneLocale *) __hidden;
|
||||
|
||||
typedef size_t (*mbrtowc_pfn_t)(wchar_t * __restrict,
|
||||
const char * __restrict, size_t, mbstate_t * __restrict);
|
||||
typedef size_t (*wcrtomb_pfn_t)(char * __restrict, wchar_t,
|
||||
mbstate_t * __restrict);
|
||||
size_t __mbsnrtowcs_std(wchar_t * __restrict, const char ** __restrict,
|
||||
size_t, size_t, mbstate_t * __restrict, mbrtowc_pfn_t);
|
||||
size_t __wcsnrtombs_std(char * __restrict, const wchar_t ** __restrict,
|
||||
size_t, size_t, mbstate_t * __restrict, wcrtomb_pfn_t);
|
||||
|
||||
#endif /* _MBLOCAL_H_ */
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#ifndef _SETLOCALE_H_
|
||||
#define _SETLOCALE_H_
|
||||
|
||||
#define ENCODING_LEN 31
|
||||
#define CATEGORY_LEN 11
|
||||
|
||||
extern char *_PathLocale;
|
||||
|
||||
int __detect_path_locale(void);
|
||||
int __wrap_setrunelocale(const char *);
|
||||
|
||||
#endif /* !_SETLOCALE_H_ */
|
|
@ -0,0 +1,267 @@
|
|||
// +build ingore
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Paul Borman at Krystal Technologies.
|
||||
*
|
||||
* Copyright (c) 2011 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
* Portions of this software were developed by David Chisnall
|
||||
* under sponsorship from the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <ctype.h>
|
||||
#include <runetype.h>
|
||||
#include <wchar.h>
|
||||
#include "mblocal.h"
|
||||
|
||||
const _RuneLocale _DefaultRuneLocale = {
|
||||
_RUNE_MAGIC_1,
|
||||
"NONE",
|
||||
NULL,
|
||||
NULL,
|
||||
0xFFFD,
|
||||
|
||||
{ /*00*/ _CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
/*08*/ _CTYPE_C,
|
||||
_CTYPE_C|_CTYPE_S|_CTYPE_B,
|
||||
_CTYPE_C|_CTYPE_S,
|
||||
_CTYPE_C|_CTYPE_S,
|
||||
_CTYPE_C|_CTYPE_S,
|
||||
_CTYPE_C|_CTYPE_S,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
/*10*/ _CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
/*18*/ _CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
_CTYPE_C,
|
||||
/*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
/*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
/*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|0,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|1,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|2,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|3,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|4,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|5,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|6,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|7,
|
||||
/*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|8,
|
||||
_CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|_CTYPE_N|9,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
/*40*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14,
|
||||
_CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*48*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*50*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*58*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
/*60*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14,
|
||||
_CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*68*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*70*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
/*78*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_P|_CTYPE_R|_CTYPE_G,
|
||||
_CTYPE_C,
|
||||
},
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||
'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||
'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
},
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
},
|
||||
};
|
||||
|
||||
#undef _CurrentRuneLocale
|
||||
const _RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;
|
||||
|
||||
_RuneLocale *
|
||||
__runes_for_locale(locale_t locale, int *mb_sb_limit)
|
||||
{
|
||||
FIX_LOCALE(locale);
|
||||
struct xlocale_ctype *c = XLOCALE_CTYPE(locale);
|
||||
*mb_sb_limit = c->__mb_sb_limit;
|
||||
return c->runes;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,228 @@
|
|||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
*
|
||||
* Copyright (c) 2011 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by David Chisnall under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _XLOCALE_PRIVATE__H_
|
||||
#define _XLOCALE_PRIVATE__H_
|
||||
|
||||
#include <xlocale.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <machine/atomic.h>
|
||||
#include "setlocale.h"
|
||||
|
||||
/**
|
||||
* The XLC_ values are indexes into the components array. They are defined in
|
||||
* the same order as the LC_ values in locale.h, but without the LC_ALL zero
|
||||
* value. Translating from LC_X to XLC_X is done by subtracting one.
|
||||
*
|
||||
* Any reordering of this enum should ensure that these invariants are not
|
||||
* violated.
|
||||
*/
|
||||
enum {
|
||||
XLC_COLLATE = 0,
|
||||
XLC_CTYPE,
|
||||
XLC_MONETARY,
|
||||
XLC_NUMERIC,
|
||||
XLC_TIME,
|
||||
XLC_MESSAGES,
|
||||
XLC_LAST
|
||||
};
|
||||
|
||||
_Static_assert(XLC_LAST - XLC_COLLATE == 6, "XLC values should be contiguous");
|
||||
_Static_assert(XLC_COLLATE == LC_COLLATE - 1,
|
||||
"XLC_COLLATE doesn't match the LC_COLLATE value.");
|
||||
_Static_assert(XLC_CTYPE == LC_CTYPE - 1,
|
||||
"XLC_CTYPE doesn't match the LC_CTYPE value.");
|
||||
_Static_assert(XLC_MONETARY == LC_MONETARY - 1,
|
||||
"XLC_MONETARY doesn't match the LC_MONETARY value.");
|
||||
_Static_assert(XLC_NUMERIC == LC_NUMERIC - 1,
|
||||
"XLC_NUMERIC doesn't match the LC_NUMERIC value.");
|
||||
_Static_assert(XLC_TIME == LC_TIME - 1,
|
||||
"XLC_TIME doesn't match the LC_TIME value.");
|
||||
_Static_assert(XLC_MESSAGES == LC_MESSAGES - 1,
|
||||
"XLC_MESSAGES doesn't match the LC_MESSAGES value.");
|
||||
|
||||
/**
|
||||
* Header used for objects that are reference counted. Objects may optionally
|
||||
* have a destructor associated, which is responsible for destroying the
|
||||
* structure. Global / static versions of the structure should have no
|
||||
* destructor set - they can then have their reference counts manipulated as
|
||||
* normal, but will not do anything with them.
|
||||
*
|
||||
* The header stores a retain count - objects are assumed to have a reference
|
||||
* count of 1 when they are created, but the retain count is 0. When the
|
||||
* retain count is less than 0, they are freed.
|
||||
*/
|
||||
struct xlocale_refcounted {
|
||||
/** Number of references to this component. */
|
||||
long retain_count;
|
||||
/** Function used to destroy this component, if one is required*/
|
||||
void(*destructor)(void*);
|
||||
};
|
||||
|
||||
#define XLOCALE_DEF_VERSION_LEN 12
|
||||
|
||||
/**
|
||||
* Header for a locale component. All locale components must begin with this
|
||||
* header.
|
||||
*/
|
||||
struct xlocale_component {
|
||||
struct xlocale_refcounted header;
|
||||
/** Name of the locale used for this component. */
|
||||
char locale[ENCODING_LEN+1];
|
||||
/** Version of the definition for this component. */
|
||||
char version[XLOCALE_DEF_VERSION_LEN];
|
||||
};
|
||||
|
||||
/**
|
||||
* xlocale structure, stores per-thread locale information.
|
||||
*/
|
||||
struct _xlocale {
|
||||
struct xlocale_refcounted header;
|
||||
/** Components for the locale. */
|
||||
struct xlocale_component *components[XLC_LAST];
|
||||
/** Flag indicating if components[XLC_MONETARY] has changed since the
|
||||
* last call to localeconv_l() with this locale. */
|
||||
int monetary_locale_changed;
|
||||
/** Flag indicating whether this locale is actually using a locale for
|
||||
* LC_MONETARY (1), or if it should use the C default instead (0). */
|
||||
int using_monetary_locale;
|
||||
/** Flag indicating if components[XLC_NUMERIC] has changed since the
|
||||
* last call to localeconv_l() with this locale. */
|
||||
int numeric_locale_changed;
|
||||
/** Flag indicating whether this locale is actually using a locale for
|
||||
* LC_NUMERIC (1), or if it should use the C default instead (0). */
|
||||
int using_numeric_locale;
|
||||
/** Flag indicating whether this locale is actually using a locale for
|
||||
* LC_TIME (1), or if it should use the C default instead (0). */
|
||||
int using_time_locale;
|
||||
/** Flag indicating whether this locale is actually using a locale for
|
||||
* LC_MESSAGES (1), or if it should use the C default instead (0). */
|
||||
int using_messages_locale;
|
||||
/** The structure to be returned from localeconv_l() for this locale. */
|
||||
struct lconv lconv;
|
||||
/** Buffer used by nl_langinfo_l() */
|
||||
char *csym;
|
||||
};
|
||||
|
||||
/**
|
||||
* Increments the reference count of a reference-counted structure.
|
||||
*/
|
||||
__attribute__((unused)) static void*
|
||||
xlocale_retain(void *val)
|
||||
{
|
||||
struct xlocale_refcounted *obj = val;
|
||||
atomic_add_long(&(obj->retain_count), 1);
|
||||
return (val);
|
||||
}
|
||||
/**
|
||||
* Decrements the reference count of a reference-counted structure, freeing it
|
||||
* if this is the last reference, calling its destructor if it has one.
|
||||
*/
|
||||
__attribute__((unused)) static void
|
||||
xlocale_release(void *val)
|
||||
{
|
||||
struct xlocale_refcounted *obj = val;
|
||||
long count;
|
||||
|
||||
count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1;
|
||||
if (count < 0 && obj->destructor != NULL)
|
||||
obj->destructor(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load functions. Each takes the name of a locale and a pointer to the data
|
||||
* to be initialised as arguments. Two special values are allowed for the
|
||||
*/
|
||||
extern void* __collate_load(const char*, locale_t);
|
||||
extern void* __ctype_load(const char*, locale_t);
|
||||
extern void* __messages_load(const char*, locale_t);
|
||||
extern void* __monetary_load(const char*, locale_t);
|
||||
extern void* __numeric_load(const char*, locale_t);
|
||||
extern void* __time_load(const char*, locale_t);
|
||||
|
||||
extern struct _xlocale __xlocale_global_locale;
|
||||
extern struct _xlocale __xlocale_C_locale;
|
||||
|
||||
/**
|
||||
* Caches the rune table in TLS for fast access.
|
||||
*/
|
||||
void __set_thread_rune_locale(locale_t loc);
|
||||
/**
|
||||
* Flag indicating whether a per-thread locale has been set. If no per-thread
|
||||
* locale has ever been set, then we always use the global locale.
|
||||
*/
|
||||
extern int __has_thread_locale;
|
||||
|
||||
/**
|
||||
* The per-thread locale. Avoids the need to use pthread lookup functions when
|
||||
* getting the per-thread locale.
|
||||
*/
|
||||
extern _Thread_local locale_t __thread_locale;
|
||||
|
||||
/**
|
||||
* Returns the current locale for this thread, or the global locale if none is
|
||||
* set. The caller does not have to free the locale. The return value from
|
||||
* this call is not guaranteed to remain valid after the locale changes. As
|
||||
* such, this should only be called within libc functions.
|
||||
*/
|
||||
static inline locale_t __get_locale(void)
|
||||
{
|
||||
|
||||
if (!__has_thread_locale) {
|
||||
return (&__xlocale_global_locale);
|
||||
}
|
||||
return (__thread_locale ? __thread_locale : &__xlocale_global_locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Two magic values are allowed for locale_t objects. NULL and -1. This
|
||||
* function maps those to the real locales that they represent.
|
||||
*/
|
||||
static inline locale_t get_real_locale(locale_t locale)
|
||||
{
|
||||
switch ((intptr_t)locale) {
|
||||
case 0: return (&__xlocale_C_locale);
|
||||
case -1: return (&__xlocale_global_locale);
|
||||
default: return (locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a placeholder locale with the real global or thread-local locale_t.
|
||||
*/
|
||||
#define FIX_LOCALE(l) (l = get_real_locale(l))
|
||||
|
||||
#endif
|
|
@ -0,0 +1,82 @@
|
|||
#define a_ll a_ll
|
||||
static inline int a_ll(volatile int *p)
|
||||
{
|
||||
int v;
|
||||
__asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define a_sc a_sc
|
||||
static inline int a_sc(volatile int *p, int v)
|
||||
{
|
||||
int r;
|
||||
__asm__ __volatile__ ("stlxr %w0,%w2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory");
|
||||
return !r;
|
||||
}
|
||||
|
||||
#define a_barrier a_barrier
|
||||
static inline void a_barrier()
|
||||
{
|
||||
__asm__ __volatile__ ("dmb ish" : : : "memory");
|
||||
}
|
||||
|
||||
#define a_cas a_cas
|
||||
static inline int a_cas(volatile int *p, int t, int s)
|
||||
{
|
||||
int old;
|
||||
do {
|
||||
old = a_ll(p);
|
||||
if (old != t) {
|
||||
a_barrier();
|
||||
break;
|
||||
}
|
||||
} while (!a_sc(p, s));
|
||||
return old;
|
||||
}
|
||||
|
||||
#define a_ll_p a_ll_p
|
||||
static inline void *a_ll_p(volatile void *p)
|
||||
{
|
||||
void *v;
|
||||
__asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define a_sc_p a_sc_p
|
||||
static inline int a_sc_p(volatile int *p, void *v)
|
||||
{
|
||||
int r;
|
||||
__asm__ __volatile__ ("stlxr %w0,%2,%1" : "=&r"(r), "=Q"(*(void *volatile *)p) : "r"(v) : "memory");
|
||||
return !r;
|
||||
}
|
||||
|
||||
#define a_cas_p a_cas_p
|
||||
static inline void *a_cas_p(volatile void *p, void *t, void *s)
|
||||
{
|
||||
void *old;
|
||||
do {
|
||||
old = a_ll_p(p);
|
||||
if (old != t) {
|
||||
a_barrier();
|
||||
break;
|
||||
}
|
||||
} while (!a_sc_p(p, s));
|
||||
return old;
|
||||
}
|
||||
|
||||
#define a_ctz_64 a_ctz_64
|
||||
static inline int a_ctz_64(uint64_t x)
|
||||
{
|
||||
__asm__(
|
||||
" rbit %0, %1\n"
|
||||
" clz %0, %0\n"
|
||||
: "=r"(x) : "r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define a_clz_64 a_clz_64
|
||||
static inline int a_clz_64(uint64_t x)
|
||||
{
|
||||
__asm__("clz %0, %1" : "=r"(x) : "r"(x));
|
||||
return x;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_DIRECTORY 040000
|
||||
#define O_NOFOLLOW 0100000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 0200000
|
||||
#define O_LARGEFILE 0400000
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_TMPFILE 020040000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
#define F_GETLK 5
|
||||
#define F_SETLK 6
|
||||
#define F_SETLKW 7
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define F_GETOWNER_UIDS 17
|
|
@ -0,0 +1,19 @@
|
|||
#define FE_INVALID 1
|
||||
#define FE_DIVBYZERO 2
|
||||
#define FE_OVERFLOW 4
|
||||
#define FE_UNDERFLOW 8
|
||||
#define FE_INEXACT 16
|
||||
#define FE_ALL_EXCEPT 31
|
||||
#define FE_TONEAREST 0
|
||||
#define FE_DOWNWARD 0x800000
|
||||
#define FE_UPWARD 0x400000
|
||||
#define FE_TOWARDZERO 0xc00000
|
||||
|
||||
typedef unsigned int fexcept_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int __fpcr;
|
||||
unsigned int __fpsr;
|
||||
} fenv_t;
|
||||
|
||||
#define FE_DFL_ENV ((const fenv_t *) -1)
|
|
@ -0,0 +1,31 @@
|
|||
#define FLT_EVAL_METHOD 0
|
||||
|
||||
// #define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L
|
||||
// #define LDBL_MIN 3.36210314311209350626267781732175260e-4932L
|
||||
// #define LDBL_MAX 1.18973149535723176508575932662800702e+4932L
|
||||
// #define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L
|
||||
//
|
||||
// #define LDBL_MANT_DIG 113
|
||||
// #define LDBL_MIN_EXP (-16381)
|
||||
// #define LDBL_MAX_EXP 16384
|
||||
//
|
||||
// #define LDBL_DIG 33
|
||||
// #define LDBL_MIN_10_EXP (-4931)
|
||||
// #define LDBL_MAX_10_EXP 4932
|
||||
//
|
||||
// #define DECIMAL_DIG 36
|
||||
|
||||
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
|
||||
#define LDBL_MIN 2.22507385850720138309e-308L
|
||||
#define LDBL_MAX 1.79769313486231570815e+308L
|
||||
#define LDBL_EPSILON 2.22044604925031308085e-16L
|
||||
|
||||
#define LDBL_MANT_DIG 53
|
||||
#define LDBL_MIN_EXP (-1021)
|
||||
#define LDBL_MAX_EXP 1024
|
||||
|
||||
#define LDBL_DIG 15
|
||||
#define LDBL_MIN_10_EXP (-307)
|
||||
#define LDBL_MAX_10_EXP 308
|
||||
|
||||
#define DECIMAL_DIG 17
|
|
@ -0,0 +1,40 @@
|
|||
#define HWCAP_FP (1 << 0)
|
||||
#define HWCAP_ASIMD (1 << 1)
|
||||
#define HWCAP_EVTSTRM (1 << 2)
|
||||
#define HWCAP_AES (1 << 3)
|
||||
#define HWCAP_PMULL (1 << 4)
|
||||
#define HWCAP_SHA1 (1 << 5)
|
||||
#define HWCAP_SHA2 (1 << 6)
|
||||
#define HWCAP_CRC32 (1 << 7)
|
||||
#define HWCAP_ATOMICS (1 << 8)
|
||||
#define HWCAP_FPHP (1 << 9)
|
||||
#define HWCAP_ASIMDHP (1 << 10)
|
||||
#define HWCAP_CPUID (1 << 11)
|
||||
#define HWCAP_ASIMDRDM (1 << 12)
|
||||
#define HWCAP_JSCVT (1 << 13)
|
||||
#define HWCAP_FCMA (1 << 14)
|
||||
#define HWCAP_LRCPC (1 << 15)
|
||||
#define HWCAP_DCPOP (1 << 16)
|
||||
#define HWCAP_SHA3 (1 << 17)
|
||||
#define HWCAP_SM3 (1 << 18)
|
||||
#define HWCAP_SM4 (1 << 19)
|
||||
#define HWCAP_ASIMDDP (1 << 20)
|
||||
#define HWCAP_SHA512 (1 << 21)
|
||||
#define HWCAP_SVE (1 << 22)
|
||||
#define HWCAP_ASIMDFHM (1 << 23)
|
||||
#define HWCAP_DIT (1 << 24)
|
||||
#define HWCAP_USCAT (1 << 25)
|
||||
#define HWCAP_ILRCPC (1 << 26)
|
||||
#define HWCAP_FLAGM (1 << 27)
|
||||
#define HWCAP_SSBS (1 << 28)
|
||||
#define HWCAP_SB (1 << 29)
|
||||
#define HWCAP_PACA (1 << 30)
|
||||
#define HWCAP_PACG (1UL << 31)
|
||||
|
||||
#define HWCAP2_DCPODP (1 << 0)
|
||||
#define HWCAP2_SVE2 (1 << 1)
|
||||
#define HWCAP2_SVEAES (1 << 2)
|
||||
#define HWCAP2_SVEPMULL (1 << 3)
|
||||
#define HWCAP2_SVEBITPERM (1 << 4)
|
||||
#define HWCAP2_SVESHA3 (1 << 5)
|
||||
#define HWCAP2_SVESM4 (1 << 6)
|
|
@ -0,0 +1,2 @@
|
|||
#define _POSIX_V6_LP64_OFF64 1
|
||||
#define _POSIX_V7_LP64_OFF64 1
|
|
@ -0,0 +1,2 @@
|
|||
#undef __WORDSIZE
|
||||
#define __WORDSIZE 64
|
|
@ -0,0 +1 @@
|
|||
typedef unsigned long __jmp_buf[22];
|
|
@ -0,0 +1,153 @@
|
|||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
||||
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
|
||||
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define MINSIGSTKSZ 6144
|
||||
#define SIGSTKSZ 12288
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
typedef unsigned long greg_t;
|
||||
typedef unsigned long gregset_t[34];
|
||||
|
||||
typedef struct {
|
||||
long double vregs[32];
|
||||
unsigned int fpsr;
|
||||
unsigned int fpcr;
|
||||
} fpregset_t;
|
||||
typedef struct sigcontext {
|
||||
unsigned long fault_address;
|
||||
unsigned long regs[31];
|
||||
unsigned long sp, pc, pstate;
|
||||
long double __reserved[256];
|
||||
} mcontext_t;
|
||||
|
||||
#define FPSIMD_MAGIC 0x46508001
|
||||
#define ESR_MAGIC 0x45535201
|
||||
#define EXTRA_MAGIC 0x45585401
|
||||
#define SVE_MAGIC 0x53564501
|
||||
struct _aarch64_ctx {
|
||||
unsigned int magic;
|
||||
unsigned int size;
|
||||
};
|
||||
struct fpsimd_context {
|
||||
struct _aarch64_ctx head;
|
||||
unsigned int fpsr;
|
||||
unsigned int fpcr;
|
||||
long double vregs[32];
|
||||
};
|
||||
struct esr_context {
|
||||
struct _aarch64_ctx head;
|
||||
unsigned long esr;
|
||||
};
|
||||
struct extra_context {
|
||||
struct _aarch64_ctx head;
|
||||
unsigned long datap;
|
||||
unsigned int size;
|
||||
unsigned int __reserved[3];
|
||||
};
|
||||
struct sve_context {
|
||||
struct _aarch64_ctx head;
|
||||
unsigned short vl;
|
||||
unsigned short __reserved[3];
|
||||
};
|
||||
#define SVE_VQ_BYTES 16
|
||||
#define SVE_VQ_MIN 1
|
||||
#define SVE_VQ_MAX 512
|
||||
#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES)
|
||||
#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES)
|
||||
#define SVE_NUM_ZREGS 32
|
||||
#define SVE_NUM_PREGS 16
|
||||
#define sve_vl_valid(vl) \
|
||||
((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX)
|
||||
#define sve_vq_from_vl(vl) ((vl) / SVE_VQ_BYTES)
|
||||
#define sve_vl_from_vq(vq) ((vq) * SVE_VQ_BYTES)
|
||||
#define SVE_SIG_ZREG_SIZE(vq) ((unsigned)(vq) * SVE_VQ_BYTES)
|
||||
#define SVE_SIG_PREG_SIZE(vq) ((unsigned)(vq) * (SVE_VQ_BYTES / 8))
|
||||
#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq)
|
||||
#define SVE_SIG_REGS_OFFSET \
|
||||
((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) \
|
||||
/ SVE_VQ_BYTES * SVE_VQ_BYTES)
|
||||
#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET
|
||||
#define SVE_SIG_ZREG_OFFSET(vq, n) \
|
||||
(SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n))
|
||||
#define SVE_SIG_ZREGS_SIZE(vq) \
|
||||
(SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET)
|
||||
#define SVE_SIG_PREGS_OFFSET(vq) \
|
||||
(SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq))
|
||||
#define SVE_SIG_PREG_OFFSET(vq, n) \
|
||||
(SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n))
|
||||
#define SVE_SIG_PREGS_SIZE(vq) \
|
||||
(SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq))
|
||||
#define SVE_SIG_FFR_OFFSET(vq) \
|
||||
(SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq))
|
||||
#define SVE_SIG_REGS_SIZE(vq) \
|
||||
(SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET)
|
||||
#define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq))
|
||||
#else
|
||||
typedef struct {
|
||||
long double __regs[18+256];
|
||||
} mcontext_t;
|
||||
#endif
|
||||
|
||||
struct sigaltstack {
|
||||
void *ss_sp;
|
||||
int ss_flags;
|
||||
size_t ss_size;
|
||||
};
|
||||
|
||||
typedef struct __ucontext {
|
||||
unsigned long uc_flags;
|
||||
struct __ucontext *uc_link;
|
||||
stack_t uc_stack;
|
||||
sigset_t uc_sigmask;
|
||||
mcontext_t uc_mcontext;
|
||||
} ucontext_t;
|
||||
|
||||
#define SA_NOCLDSTOP 1
|
||||
#define SA_NOCLDWAIT 2
|
||||
#define SA_SIGINFO 4
|
||||
#define SA_ONSTACK 0x08000000
|
||||
#define SA_RESTART 0x10000000
|
||||
#define SA_NODEFER 0x40000000
|
||||
#define SA_RESETHAND 0x80000000
|
||||
#define SA_RESTORER 0x04000000
|
||||
|
||||
#endif
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGIOT SIGABRT
|
||||
#define SIGBUS 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGUSR1 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGUSR2 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGSTKFLT 16
|
||||
#define SIGCHLD 17
|
||||
#define SIGCONT 18
|
||||
#define SIGSTOP 19
|
||||
#define SIGTSTP 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
#define SIGURG 23
|
||||
#define SIGXCPU 24
|
||||
#define SIGXFSZ 25
|
||||
#define SIGVTALRM 26
|
||||
#define SIGPROF 27
|
||||
#define SIGWINCH 28
|
||||
#define SIGIO 29
|
||||
#define SIGPOLL 29
|
||||
#define SIGPWR 30
|
||||
#define SIGSYS 31
|
||||
#define SIGUNUSED SIGSYS
|
||||
|
||||
#define _NSIG 65
|
|
@ -0,0 +1,18 @@
|
|||
struct stat {
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
unsigned long __pad;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
int __pad2;
|
||||
blkcnt_t st_blocks;
|
||||
struct timespec st_atim;
|
||||
struct timespec st_mtim;
|
||||
struct timespec st_ctim;
|
||||
unsigned __unused[2];
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
typedef int32_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef uint32_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
|
||||
#define INT_FAST16_MIN INT32_MIN
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
|
||||
#define INT_FAST16_MAX INT32_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
|
||||
#define UINT_FAST16_MAX UINT32_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
|
||||
#define INTPTR_MIN INT64_MIN
|
||||
#define INTPTR_MAX INT64_MAX
|
||||
#define UINTPTR_MAX UINT64_MAX
|
||||
#define PTRDIFF_MIN INT64_MIN
|
||||
#define PTRDIFF_MAX INT64_MAX
|
||||
#define SIZE_MAX UINT64_MAX
|
|
@ -0,0 +1,16 @@
|
|||
struct user_regs_struct {
|
||||
unsigned long long regs[31];
|
||||
unsigned long long sp;
|
||||
unsigned long long pc;
|
||||
unsigned long long pstate;
|
||||
};
|
||||
|
||||
struct user_fpsimd_struct {
|
||||
long double vregs[32];
|
||||
unsigned int fpsr;
|
||||
unsigned int fpcr;
|
||||
};
|
||||
|
||||
#define ELF_NREG 34
|
||||
typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NREG];
|
||||
typedef struct user_fpsimd_struct elf_fpregset_t;
|
|
@ -0,0 +1,15 @@
|
|||
__asm__(
|
||||
".text \n"
|
||||
".global " START "\n"
|
||||
".type " START ",%function\n"
|
||||
START ":\n"
|
||||
" mov x29, #0\n"
|
||||
" mov x30, #0\n"
|
||||
" mov x0, sp\n"
|
||||
".weak _DYNAMIC\n"
|
||||
".hidden _DYNAMIC\n"
|
||||
" adrp x1, _DYNAMIC\n"
|
||||
" add x1, x1, #:lo12:_DYNAMIC\n"
|
||||
" and sp, x0, #-16\n"
|
||||
" b " START "_c\n"
|
||||
);
|
|
@ -0,0 +1,25 @@
|
|||
#define fp_barrierf fp_barrierf
|
||||
static inline float fp_barrierf(float x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define fp_barrier fp_barrier
|
||||
static inline double fp_barrier(double x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define fp_force_evalf fp_force_evalf
|
||||
static inline void fp_force_evalf(float x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w"(x));
|
||||
}
|
||||
|
||||
#define fp_force_eval fp_force_eval
|
||||
static inline void fp_force_eval(double x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w"(x));
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
struct kstat {
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
unsigned long __pad;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
int __pad2;
|
||||
blkcnt_t st_blocks;
|
||||
long st_atime_sec;
|
||||
long st_atime_nsec;
|
||||
long st_mtime_sec;
|
||||
long st_mtime_nsec;
|
||||
long st_ctime_sec;
|
||||
long st_ctime_nsec;
|
||||
unsigned __unused[2];
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
static inline struct pthread *__pthread_self()
|
||||
{
|
||||
char *self;
|
||||
__asm__ ("mrs %0,tpidr_el0" : "=r"(self));
|
||||
return (void*)(self - sizeof(struct pthread));
|
||||
}
|
||||
|
||||
#define TLS_ABOVE_TP
|
||||
#define GAP_ABOVE_TP 16
|
||||
#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread))
|
||||
|
||||
#define MC_PC pc
|
|
@ -0,0 +1,24 @@
|
|||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define ENDIAN_SUFFIX "_be"
|
||||
#else
|
||||
#define ENDIAN_SUFFIX ""
|
||||
#endif
|
||||
|
||||
#define LDSO_ARCH "aarch64" ENDIAN_SUFFIX
|
||||
|
||||
#define NO_LEGACY_INITFINI
|
||||
|
||||
#define TPOFF_K 0
|
||||
|
||||
#define REL_SYMBOLIC R_AARCH64_ABS64
|
||||
#define REL_GOT R_AARCH64_GLOB_DAT
|
||||
#define REL_PLT R_AARCH64_JUMP_SLOT
|
||||
#define REL_RELATIVE R_AARCH64_RELATIVE
|
||||
#define REL_COPY R_AARCH64_COPY
|
||||
#define REL_DTPMOD R_AARCH64_TLS_DTPMOD64
|
||||
#define REL_DTPOFF R_AARCH64_TLS_DTPREL64
|
||||
#define REL_TPOFF R_AARCH64_TLS_TPREL64
|
||||
#define REL_TLSDESC R_AARCH64_TLSDESC
|
||||
|
||||
#define CRTJMP(pc,sp) __asm__ __volatile__( \
|
||||
"mov sp,%1 ; br %0" : : "r"(pc), "r"(sp) : "memory" )
|
|
@ -0,0 +1,78 @@
|
|||
#define __SYSCALL_LL_E(x) (x)
|
||||
#define __SYSCALL_LL_O(x) (x)
|
||||
|
||||
#define __asm_syscall(...) do { \
|
||||
__asm__ __volatile__ ( "svc 0" \
|
||||
: "=r"(x0) : __VA_ARGS__ : "memory", "cc"); \
|
||||
return x0; \
|
||||
} while (0)
|
||||
|
||||
inline long __syscall0(long n)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0");
|
||||
__asm_syscall("r"(x8));
|
||||
}
|
||||
|
||||
inline long __syscall1(long n, long a)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
__asm_syscall("r"(x8), "0"(x0));
|
||||
}
|
||||
|
||||
inline long __syscall2(long n, long a, long b)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
register long x1 __asm__("x1") = b;
|
||||
__asm_syscall("r"(x8), "0"(x0), "r"(x1));
|
||||
}
|
||||
|
||||
inline long __syscall3(long n, long a, long b, long c)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
register long x1 __asm__("x1") = b;
|
||||
register long x2 __asm__("x2") = c;
|
||||
__asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2));
|
||||
}
|
||||
|
||||
inline long __syscall4(long n, long a, long b, long c, long d)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
register long x1 __asm__("x1") = b;
|
||||
register long x2 __asm__("x2") = c;
|
||||
register long x3 __asm__("x3") = d;
|
||||
__asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3));
|
||||
}
|
||||
|
||||
inline long __syscall5(long n, long a, long b, long c, long d, long e)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
register long x1 __asm__("x1") = b;
|
||||
register long x2 __asm__("x2") = c;
|
||||
register long x3 __asm__("x3") = d;
|
||||
register long x4 __asm__("x4") = e;
|
||||
__asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4));
|
||||
}
|
||||
|
||||
inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
|
||||
{
|
||||
register long x8 __asm__("x8") = n;
|
||||
register long x0 __asm__("x0") = a;
|
||||
register long x1 __asm__("x1") = b;
|
||||
register long x2 __asm__("x2") = c;
|
||||
register long x3 __asm__("x3") = d;
|
||||
register long x4 __asm__("x4") = e;
|
||||
register long x5 __asm__("x5") = f;
|
||||
__asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5));
|
||||
}
|
||||
|
||||
#define VDSO_USEFUL
|
||||
#define VDSO_CGT_SYM "__kernel_clock_gettime"
|
||||
#define VDSO_CGT_VER "LINUX_2.6.39"
|
||||
|
||||
#define IPC_64 0
|
|
@ -0,0 +1,109 @@
|
|||
#include "libc.h"
|
||||
|
||||
#if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4
|
||||
#define BLX "mov lr,pc\n\tbx"
|
||||
#else
|
||||
#define BLX "blx"
|
||||
#endif
|
||||
|
||||
extern hidden uintptr_t __a_cas_ptr, __a_barrier_ptr;
|
||||
|
||||
#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \
|
||||
|| __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
||||
|
||||
#define a_ll a_ll
|
||||
static inline int a_ll(volatile int *p)
|
||||
{
|
||||
int v;
|
||||
__asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define a_sc a_sc
|
||||
static inline int a_sc(volatile int *p, int v)
|
||||
{
|
||||
int r;
|
||||
__asm__ __volatile__ ("strex %0,%2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory");
|
||||
return !r;
|
||||
}
|
||||
|
||||
#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
||||
|
||||
#define a_barrier a_barrier
|
||||
static inline void a_barrier()
|
||||
{
|
||||
__asm__ __volatile__ ("dmb ish" : : : "memory");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define a_pre_llsc a_barrier
|
||||
#define a_post_llsc a_barrier
|
||||
|
||||
#else
|
||||
|
||||
#define a_cas a_cas
|
||||
static inline int a_cas(volatile int *p, int t, int s)
|
||||
{
|
||||
__asm__ __volatile__ ("TODO");
|
||||
//TODO for (;;) {
|
||||
//TODO register int r0 __asm__("r0") = t;
|
||||
//TODO register int r1 __asm__("r1") = s;
|
||||
//TODO register volatile int *r2 __asm__("r2") = p;
|
||||
//TODO register uintptr_t r3 __asm__("r3") = __a_cas_ptr;
|
||||
//TODO int old;
|
||||
//TODO __asm__ __volatile__ (
|
||||
//TODO BLX " r3"
|
||||
//TODO : "+r"(r0), "+r"(r3) : "r"(r1), "r"(r2)
|
||||
//TODO : "memory", "lr", "ip", "cc" );
|
||||
//TODO if (!r0) return t;
|
||||
//TODO if ((old=*p)!=t) return old;
|
||||
//TODO }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef a_barrier
|
||||
#define a_barrier a_barrier
|
||||
static inline void a_barrier()
|
||||
{
|
||||
__asm__ __volatile__ ("TODO");
|
||||
//TODO register uintptr_t ip __asm__("ip") = __a_barrier_ptr;
|
||||
//TODO __asm__ __volatile__( BLX " ip" : "+r"(ip) : : "memory", "cc", "lr" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#define a_crash a_crash
|
||||
static inline void a_crash()
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
#ifndef __thumb__
|
||||
".word 0xe7f000f0"
|
||||
#else
|
||||
".short 0xdeff"
|
||||
#endif
|
||||
: : : "memory");
|
||||
}
|
||||
|
||||
#if __ARM_ARCH >= 5 && (!__thumb__ || __thumb2__)
|
||||
|
||||
#define a_clz_32 a_clz_32
|
||||
static inline int a_clz_32(uint32_t x)
|
||||
{
|
||||
__asm__ ("clz %0, %1" : "=r"(x) : "r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#if __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
||||
|
||||
#define a_ctz_32 a_ctz_32
|
||||
static inline int a_ctz_32(uint32_t x)
|
||||
{
|
||||
uint32_t xr;
|
||||
__asm__ ("rbit %0, %1" : "=r"(xr) : "r"(x));
|
||||
return a_clz_32(xr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_DIRECTORY 040000
|
||||
#define O_NOFOLLOW 0100000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 0200000
|
||||
#define O_LARGEFILE 0400000
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_TMPFILE 020040000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define F_GETLK 12
|
||||
#define F_SETLK 13
|
||||
#define F_SETLKW 14
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define F_GETOWNER_UIDS 17
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef __ARM_PCS_VFP
|
||||
#define FE_ALL_EXCEPT 0
|
||||
#define FE_TONEAREST 0
|
||||
#else
|
||||
#define FE_INVALID 1
|
||||
#define FE_DIVBYZERO 2
|
||||
#define FE_OVERFLOW 4
|
||||
#define FE_UNDERFLOW 8
|
||||
#define FE_INEXACT 16
|
||||
#define FE_ALL_EXCEPT 31
|
||||
#define FE_TONEAREST 0
|
||||
#define FE_DOWNWARD 0x800000
|
||||
#define FE_UPWARD 0x400000
|
||||
#define FE_TOWARDZERO 0xc00000
|
||||
#endif
|
||||
|
||||
typedef unsigned long fexcept_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned long __cw;
|
||||
} fenv_t;
|
||||
|
||||
#define FE_DFL_ENV ((const fenv_t *) -1)
|
|
@ -0,0 +1,16 @@
|
|||
#define FLT_EVAL_METHOD 0
|
||||
|
||||
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
|
||||
#define LDBL_MIN 2.22507385850720138309e-308L
|
||||
#define LDBL_MAX 1.79769313486231570815e+308L
|
||||
#define LDBL_EPSILON 2.22044604925031308085e-16L
|
||||
|
||||
#define LDBL_MANT_DIG 53
|
||||
#define LDBL_MIN_EXP (-1021)
|
||||
#define LDBL_MAX_EXP 1024
|
||||
|
||||
#define LDBL_DIG 15
|
||||
#define LDBL_MIN_10_EXP (-307)
|
||||
#define LDBL_MAX_10_EXP 308
|
||||
|
||||
#define DECIMAL_DIG 17
|
|
@ -0,0 +1,53 @@
|
|||
#define HWCAP_SWP (1 << 0)
|
||||
#define HWCAP_HALF (1 << 1)
|
||||
#define HWCAP_THUMB (1 << 2)
|
||||
#define HWCAP_26BIT (1 << 3)
|
||||
#define HWCAP_FAST_MULT (1 << 4)
|
||||
#define HWCAP_FPA (1 << 5)
|
||||
#define HWCAP_VFP (1 << 6)
|
||||
#define HWCAP_EDSP (1 << 7)
|
||||
#define HWCAP_JAVA (1 << 8)
|
||||
#define HWCAP_IWMMXT (1 << 9)
|
||||
#define HWCAP_CRUNCH (1 << 10)
|
||||
#define HWCAP_THUMBEE (1 << 11)
|
||||
#define HWCAP_NEON (1 << 12)
|
||||
#define HWCAP_VFPv3 (1 << 13)
|
||||
#define HWCAP_VFPv3D16 (1 << 14)
|
||||
#define HWCAP_TLS (1 << 15)
|
||||
#define HWCAP_VFPv4 (1 << 16)
|
||||
#define HWCAP_IDIVA (1 << 17)
|
||||
#define HWCAP_IDIVT (1 << 18)
|
||||
#define HWCAP_VFPD32 (1 << 19)
|
||||
#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
|
||||
#define HWCAP_LPAE (1 << 20)
|
||||
#define HWCAP_EVTSTRM (1 << 21)
|
||||
|
||||
#define HWCAP2_AES (1 << 0)
|
||||
#define HWCAP2_PMULL (1 << 1)
|
||||
#define HWCAP2_SHA1 (1 << 2)
|
||||
#define HWCAP2_SHA2 (1 << 3)
|
||||
#define HWCAP2_CRC32 (1 << 4)
|
||||
|
||||
#define HWCAP_ARM_SWP (1 << 0)
|
||||
#define HWCAP_ARM_HALF (1 << 1)
|
||||
#define HWCAP_ARM_THUMB (1 << 2)
|
||||
#define HWCAP_ARM_26BIT (1 << 3)
|
||||
#define HWCAP_ARM_FAST_MULT (1 << 4)
|
||||
#define HWCAP_ARM_FPA (1 << 5)
|
||||
#define HWCAP_ARM_VFP (1 << 6)
|
||||
#define HWCAP_ARM_EDSP (1 << 7)
|
||||
#define HWCAP_ARM_JAVA (1 << 8)
|
||||
#define HWCAP_ARM_IWMMXT (1 << 9)
|
||||
#define HWCAP_ARM_CRUNCH (1 << 10)
|
||||
#define HWCAP_ARM_THUMBEE (1 << 11)
|
||||
#define HWCAP_ARM_NEON (1 << 12)
|
||||
#define HWCAP_ARM_VFPv3 (1 << 13)
|
||||
#define HWCAP_ARM_VFPv3D16 (1 << 14)
|
||||
#define HWCAP_ARM_TLS (1 << 15)
|
||||
#define HWCAP_ARM_VFPv4 (1 << 16)
|
||||
#define HWCAP_ARM_IDIVA (1 << 17)
|
||||
#define HWCAP_ARM_IDIVT (1 << 18)
|
||||
#define HWCAP_ARM_VFPD32 (1 << 19)
|
||||
#define HWCAP_ARM_IDIV (HWCAP_ARM_IDIVA | HWCAP_ARM_IDIVT)
|
||||
#define HWCAP_ARM_LPAE (1 << 20)
|
||||
#define HWCAP_ARM_EVTSTRM (1 << 21)
|
|
@ -0,0 +1,2 @@
|
|||
#undef FIOQSIZE
|
||||
#define FIOQSIZE 0x545e
|
|
@ -0,0 +1 @@
|
|||
#define IPC_STAT 0x102
|
|
@ -0,0 +1,18 @@
|
|||
struct msqid_ds {
|
||||
struct ipc_perm msg_perm;
|
||||
unsigned long __msg_stime_lo;
|
||||
unsigned long __msg_stime_hi;
|
||||
unsigned long __msg_rtime_lo;
|
||||
unsigned long __msg_rtime_hi;
|
||||
unsigned long __msg_ctime_lo;
|
||||
unsigned long __msg_ctime_hi;
|
||||
unsigned long msg_cbytes;
|
||||
msgqnum_t msg_qnum;
|
||||
msglen_t msg_qbytes;
|
||||
pid_t msg_lspid;
|
||||
pid_t msg_lrpid;
|
||||
unsigned long __unused[2];
|
||||
time_t msg_stime;
|
||||
time_t msg_rtime;
|
||||
time_t msg_ctime;
|
||||
};
|
|
@ -0,0 +1,2 @@
|
|||
#define _POSIX_V6_ILP32_OFFBIG 1
|
||||
#define _POSIX_V7_ILP32_OFFBIG 1
|
|
@ -0,0 +1,25 @@
|
|||
#define PTRACE_GETWMMXREGS 18
|
||||
#define PTRACE_SETWMMXREGS 19
|
||||
#define PTRACE_GET_THREAD_AREA 22
|
||||
#define PTRACE_SET_SYSCALL 23
|
||||
#define PTRACE_GETCRUNCHREGS 25
|
||||
#define PTRACE_SETCRUNCHREGS 26
|
||||
#define PTRACE_GETVFPREGS 27
|
||||
#define PTRACE_SETVFPREGS 28
|
||||
#define PTRACE_GETHBPREGS 29
|
||||
#define PTRACE_SETHBPREGS 30
|
||||
#define PTRACE_GETFDPIC 31
|
||||
#define PTRACE_GETFDPIC_EXEC 0
|
||||
#define PTRACE_GETFDPIC_INTERP 1
|
||||
|
||||
#define PT_GETWMMXREGS PTRACE_GETWMMXREGS
|
||||
#define PT_SETWMMXREGS PTRACE_SETWMMXREGS
|
||||
#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA
|
||||
#define PT_SET_SYSCALL PTRACE_SET_SYSCALL
|
||||
#define PT_GETCRUNCHREGS PTRACE_GETCRUNCHREGS
|
||||
#define PT_SETCRUNCHREGS PTRACE_SETCRUNCHREGS
|
||||
#define PT_GETVFPREGS PTRACE_GETVFPREGS
|
||||
#define PT_SETVFPREGS PTRACE_SETVFPREGS
|
||||
#define PT_GETHBPREGS PTRACE_GETHBPREGS
|
||||
#define PT_SETHBPREGS PTRACE_SETHBPREGS
|
||||
#define PT_GETFDPIC PTRACE_GETFDPIC
|
|
@ -0,0 +1,3 @@
|
|||
#undef __WORDSIZE
|
||||
#define __WORDSIZE 32
|
||||
/* FIXME */
|
|
@ -0,0 +1,18 @@
|
|||
struct semid_ds {
|
||||
struct ipc_perm sem_perm;
|
||||
unsigned long __sem_otime_lo;
|
||||
unsigned long __sem_otime_hi;
|
||||
unsigned long __sem_ctime_lo;
|
||||
unsigned long __sem_ctime_hi;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
unsigned short sem_nsems;
|
||||
char __sem_nsems_pad[sizeof(long)-sizeof(short)];
|
||||
#else
|
||||
char __sem_nsems_pad[sizeof(long)-sizeof(short)];
|
||||
unsigned short sem_nsems;
|
||||
#endif
|
||||
long __unused3;
|
||||
long __unused4;
|
||||
time_t sem_otime;
|
||||
time_t sem_ctime;
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
typedef unsigned long long __jmp_buf[32];
|
|
@ -0,0 +1,31 @@
|
|||
#define SHMLBA 4096
|
||||
|
||||
struct shmid_ds {
|
||||
struct ipc_perm shm_perm;
|
||||
size_t shm_segsz;
|
||||
unsigned long __shm_atime_lo;
|
||||
unsigned long __shm_atime_hi;
|
||||
unsigned long __shm_dtime_lo;
|
||||
unsigned long __shm_dtime_hi;
|
||||
unsigned long __shm_ctime_lo;
|
||||
unsigned long __shm_ctime_hi;
|
||||
pid_t shm_cpid;
|
||||
pid_t shm_lpid;
|
||||
unsigned long shm_nattch;
|
||||
unsigned long __pad1;
|
||||
unsigned long __pad2;
|
||||
unsigned long __pad3;
|
||||
time_t shm_atime;
|
||||
time_t shm_dtime;
|
||||
time_t shm_ctime;
|
||||
};
|
||||
|
||||
struct shminfo {
|
||||
unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
|
||||
};
|
||||
|
||||
struct shm_info {
|
||||
int __used_ids;
|
||||
unsigned long shm_tot, shm_rss, shm_swp;
|
||||
unsigned long __swap_attempts, __swap_successes;
|
||||
};
|
|
@ -0,0 +1,86 @@
|
|||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
||||
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
|
||||
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define MINSIGSTKSZ 2048
|
||||
#define SIGSTKSZ 8192
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
typedef int greg_t, gregset_t[18];
|
||||
typedef struct sigcontext {
|
||||
unsigned long trap_no, error_code, oldmask;
|
||||
unsigned long arm_r0, arm_r1, arm_r2, arm_r3;
|
||||
unsigned long arm_r4, arm_r5, arm_r6, arm_r7;
|
||||
unsigned long arm_r8, arm_r9, arm_r10, arm_fp;
|
||||
unsigned long arm_ip, arm_sp, arm_lr, arm_pc;
|
||||
unsigned long arm_cpsr, fault_address;
|
||||
} mcontext_t;
|
||||
#else
|
||||
typedef struct {
|
||||
unsigned long __regs[21];
|
||||
} mcontext_t;
|
||||
#endif
|
||||
|
||||
struct sigaltstack {
|
||||
void *ss_sp;
|
||||
int ss_flags;
|
||||
size_t ss_size;
|
||||
};
|
||||
|
||||
typedef struct __ucontext {
|
||||
unsigned long uc_flags;
|
||||
struct __ucontext *uc_link;
|
||||
stack_t uc_stack;
|
||||
mcontext_t uc_mcontext;
|
||||
sigset_t uc_sigmask;
|
||||
unsigned long long uc_regspace[64];
|
||||
} ucontext_t;
|
||||
|
||||
#define SA_NOCLDSTOP 1
|
||||
#define SA_NOCLDWAIT 2
|
||||
#define SA_SIGINFO 4
|
||||
#define SA_ONSTACK 0x08000000
|
||||
#define SA_RESTART 0x10000000
|
||||
#define SA_NODEFER 0x40000000
|
||||
#define SA_RESETHAND 0x80000000
|
||||
#define SA_RESTORER 0x04000000
|
||||
|
||||
#endif
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGIOT SIGABRT
|
||||
#define SIGBUS 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGUSR1 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGUSR2 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGSTKFLT 16
|
||||
#define SIGCHLD 17
|
||||
#define SIGCONT 18
|
||||
#define SIGSTOP 19
|
||||
#define SIGTSTP 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
#define SIGURG 23
|
||||
#define SIGXCPU 24
|
||||
#define SIGXFSZ 25
|
||||
#define SIGVTALRM 26
|
||||
#define SIGPROF 27
|
||||
#define SIGWINCH 28
|
||||
#define SIGIO 29
|
||||
#define SIGPOLL 29
|
||||
#define SIGPWR 30
|
||||
#define SIGSYS 31
|
||||
#define SIGUNUSED SIGSYS
|
||||
|
||||
#define _NSIG 65
|
|
@ -0,0 +1,25 @@
|
|||
/* copied from kernel definition, but with padding replaced
|
||||
* by the corresponding correctly-sized userspace types. */
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev;
|
||||
int __st_dev_padding;
|
||||
long __st_ino_truncated;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
int __st_rdev_padding;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
struct {
|
||||
long tv_sec;
|
||||
long tv_nsec;
|
||||
} __st_atim32, __st_mtim32, __st_ctim32;
|
||||
ino_t st_ino;
|
||||
struct timespec st_atim;
|
||||
struct timespec st_mtim;
|
||||
struct timespec st_ctim;
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
typedef int32_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef uint32_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
|
||||
#define INT_FAST16_MIN INT32_MIN
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
|
||||
#define INT_FAST16_MAX INT32_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
|
||||
#define UINT_FAST16_MAX UINT32_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
#define PTRDIFF_MIN INT32_MIN
|
||||
#define PTRDIFF_MAX INT32_MAX
|
||||
#define SIZE_MAX UINT32_MAX
|
|
@ -0,0 +1,36 @@
|
|||
typedef struct user_fpregs {
|
||||
struct fp_reg {
|
||||
unsigned sign1:1;
|
||||
unsigned unused:15;
|
||||
unsigned sign2:1;
|
||||
unsigned exponent:14;
|
||||
unsigned j:1;
|
||||
unsigned mantissa1:31;
|
||||
unsigned mantissa0:32;
|
||||
} fpregs[8];
|
||||
unsigned fpsr:32;
|
||||
unsigned fpcr:32;
|
||||
unsigned char ftype[8];
|
||||
unsigned int init_flag;
|
||||
} elf_fpregset_t;
|
||||
|
||||
struct user_regs {
|
||||
unsigned long uregs[18];
|
||||
};
|
||||
#define ELF_NGREG 18
|
||||
typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];
|
||||
|
||||
struct user {
|
||||
struct user_regs regs;
|
||||
int u_fpvalid;
|
||||
unsigned long u_tsize, u_dsize, u_ssize;
|
||||
unsigned long start_code, start_stack;
|
||||
long signal;
|
||||
int reserved;
|
||||
struct user_regs *u_ar0;
|
||||
unsigned long magic;
|
||||
char u_comm[32];
|
||||
int u_debugreg[8];
|
||||
struct user_fpregs u_fp;
|
||||
struct user_fpregs *u_fp0;
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
__asm__(
|
||||
".text \n"
|
||||
".global " START " \n"
|
||||
".type " START ",%function \n"
|
||||
START ": \n"
|
||||
" mov fp, #0 \n"
|
||||
" mov lr, #0 \n"
|
||||
" ldr a2, 1f \n"
|
||||
" add a2, pc, a2 \n"
|
||||
" mov a1, sp \n"
|
||||
"2: and ip, a1, #-16 \n"
|
||||
" mov sp, ip \n"
|
||||
" bl " START "_c \n"
|
||||
".weak _DYNAMIC \n"
|
||||
".hidden _DYNAMIC \n"
|
||||
".align 2 \n"
|
||||
"1: .word _DYNAMIC-2b \n"
|
||||
);
|
|
@ -0,0 +1,21 @@
|
|||
struct kstat {
|
||||
dev_t st_dev;
|
||||
int __st_dev_padding;
|
||||
long __st_ino_truncated;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
int __st_rdev_padding;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
long st_atime_sec;
|
||||
long st_atime_nsec;
|
||||
long st_mtime_sec;
|
||||
long st_mtime_nsec;
|
||||
long st_ctime_sec;
|
||||
long st_ctime_nsec;
|
||||
ino_t st_ino;
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
#if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \
|
||||
|| __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
||||
|
||||
static inline pthread_t __pthread_self()
|
||||
{
|
||||
char *p;
|
||||
__asm__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(p) );
|
||||
return (void *)(p-sizeof(struct pthread));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4
|
||||
#define BLX "mov lr,pc\n\tbx"
|
||||
#else
|
||||
#define BLX "blx"
|
||||
#endif
|
||||
|
||||
static inline pthread_t __pthread_self()
|
||||
{
|
||||
extern hidden uintptr_t __a_gettp_ptr;
|
||||
register uintptr_t p __asm__("r0");
|
||||
__asm__ ( BLX " %1" : "=r"(p) : "r"(__a_gettp_ptr) : "cc", "lr" );
|
||||
return (void *)(p-sizeof(struct pthread));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define TLS_ABOVE_TP
|
||||
#define GAP_ABOVE_TP 8
|
||||
#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread))
|
||||
|
||||
#define MC_PC arm_pc
|
|
@ -0,0 +1,32 @@
|
|||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define ENDIAN_SUFFIX "eb"
|
||||
#else
|
||||
#define ENDIAN_SUFFIX ""
|
||||
#endif
|
||||
|
||||
#if __ARM_PCS_VFP
|
||||
#define FP_SUFFIX "hf"
|
||||
#else
|
||||
#define FP_SUFFIX ""
|
||||
#endif
|
||||
|
||||
#define LDSO_ARCH "arm" ENDIAN_SUFFIX FP_SUFFIX
|
||||
|
||||
#define NO_LEGACY_INITFINI
|
||||
|
||||
#define TPOFF_K 0
|
||||
|
||||
#define REL_SYMBOLIC R_ARM_ABS32
|
||||
#define REL_GOT R_ARM_GLOB_DAT
|
||||
#define REL_PLT R_ARM_JUMP_SLOT
|
||||
#define REL_RELATIVE R_ARM_RELATIVE
|
||||
#define REL_COPY R_ARM_COPY
|
||||
#define REL_DTPMOD R_ARM_TLS_DTPMOD32
|
||||
#define REL_DTPOFF R_ARM_TLS_DTPOFF32
|
||||
#define REL_TPOFF R_ARM_TLS_TPOFF32
|
||||
#define REL_TLSDESC R_ARM_TLS_DESC
|
||||
|
||||
#define TLSDESC_BACKWARDS
|
||||
|
||||
#define CRTJMP(pc,sp) __asm__ __volatile__( \
|
||||
"mov sp,%1 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
|
|
@ -0,0 +1,103 @@
|
|||
#define __SYSCALL_LL_E(x) \
|
||||
((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
|
||||
((union { long long ll; long l[2]; }){ .ll = x }).l[1]
|
||||
#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
|
||||
|
||||
#ifdef __thumb__
|
||||
|
||||
/* Avoid use of r7 in asm constraints when producing thumb code,
|
||||
* since it's reserved as frame pointer and might not be supported. */
|
||||
#define __ASM____R7__
|
||||
#define __asm_syscall(...) do { \
|
||||
__asm__ __volatile__ ( "mov %1,r7 ; mov r7,%2 ; svc 0 ; mov r7,%1" \
|
||||
: "=r"(r0), "=&r"((int){0}) : __VA_ARGS__ : "memory"); \
|
||||
return r0; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define __ASM____R7__ __asm__("r7")
|
||||
#define __asm_syscall(...) do { \
|
||||
__asm__ __volatile__ ( "svc 0" \
|
||||
: "=r"(r0) : __VA_ARGS__ : "memory"); \
|
||||
return r0; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* For thumb2, we can allow 8-bit immediate syscall numbers, saving a
|
||||
* register in the above dance around r7. Does not work for thumb1 where
|
||||
* only movs, not mov, supports immediates, and we can't use movs because
|
||||
* it doesn't support high regs. */
|
||||
#ifdef __thumb2__
|
||||
#define R7_OPERAND "rI"(r7)
|
||||
#else
|
||||
#define R7_OPERAND "r"(r7)
|
||||
#endif
|
||||
|
||||
inline long __syscall0(long n)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0");
|
||||
__asm_syscall(R7_OPERAND);
|
||||
}
|
||||
|
||||
inline long __syscall1(long n, long a)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0));
|
||||
}
|
||||
|
||||
inline long __syscall2(long n, long a, long b)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
register long r1 __asm__("r1") = b;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0), "r"(r1));
|
||||
}
|
||||
|
||||
inline long __syscall3(long n, long a, long b, long c)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
register long r1 __asm__("r1") = b;
|
||||
register long r2 __asm__("r2") = c;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2));
|
||||
}
|
||||
|
||||
inline long __syscall4(long n, long a, long b, long c, long d)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
register long r1 __asm__("r1") = b;
|
||||
register long r2 __asm__("r2") = c;
|
||||
register long r3 __asm__("r3") = d;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3));
|
||||
}
|
||||
|
||||
inline long __syscall5(long n, long a, long b, long c, long d, long e)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
register long r1 __asm__("r1") = b;
|
||||
register long r2 __asm__("r2") = c;
|
||||
register long r3 __asm__("r3") = d;
|
||||
register long r4 __asm__("r4") = e;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4));
|
||||
}
|
||||
|
||||
inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
|
||||
{
|
||||
register long r7 __ASM____R7__ = n;
|
||||
register long r0 __asm__("r0") = a;
|
||||
register long r1 __asm__("r1") = b;
|
||||
register long r2 __asm__("r2") = c;
|
||||
register long r3 __asm__("r3") = d;
|
||||
register long r4 __asm__("r4") = e;
|
||||
register long r5 __asm__("r5") = f;
|
||||
__asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5));
|
||||
}
|
||||
|
||||
#define SYSCALL_FADVISE_6_ARG
|
||||
|
||||
#define SYSCALL_IPC_BROKEN_MODE
|
|
@ -0,0 +1,11 @@
|
|||
#define _DIRENT_HAVE_D_RECLEN
|
||||
#define _DIRENT_HAVE_D_OFF
|
||||
#define _DIRENT_HAVE_D_TYPE
|
||||
|
||||
struct dirent {
|
||||
ino_t d_ino;
|
||||
off_t d_off;
|
||||
unsigned short d_reclen;
|
||||
unsigned char d_type;
|
||||
char d_name[256];
|
||||
};
|
|
@ -0,0 +1,134 @@
|
|||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EFAULT 14
|
||||
#define ENOTBLK 15
|
||||
#define EBUSY 16
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENODEV 19
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define EINVAL 22
|
||||
#define ENFILE 23
|
||||
#define EMFILE 24
|
||||
#define ENOTTY 25
|
||||
#define ETXTBSY 26
|
||||
#define EFBIG 27
|
||||
#define ENOSPC 28
|
||||
#define ESPIPE 29
|
||||
#define EROFS 30
|
||||
#define EMLINK 31
|
||||
#define EPIPE 32
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
#define EDEADLK 35
|
||||
#define ENAMETOOLONG 36
|
||||
#define ENOLCK 37
|
||||
#define ENOSYS 38
|
||||
#define ENOTEMPTY 39
|
||||
#define ELOOP 40
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
#define ENOMSG 42
|
||||
#define EIDRM 43
|
||||
#define ECHRNG 44
|
||||
#define EL2NSYNC 45
|
||||
#define EL3HLT 46
|
||||
#define EL3RST 47
|
||||
#define ELNRNG 48
|
||||
#define EUNATCH 49
|
||||
#define ENOCSI 50
|
||||
#define EL2HLT 51
|
||||
#define EBADE 52
|
||||
#define EBADR 53
|
||||
#define EXFULL 54
|
||||
#define ENOANO 55
|
||||
#define EBADRQC 56
|
||||
#define EBADSLT 57
|
||||
#define EDEADLOCK EDEADLK
|
||||
#define EBFONT 59
|
||||
#define ENOSTR 60
|
||||
#define ENODATA 61
|
||||
#define ETIME 62
|
||||
#define ENOSR 63
|
||||
#define ENONET 64
|
||||
#define ENOPKG 65
|
||||
#define EREMOTE 66
|
||||
#define ENOLINK 67
|
||||
#define EADV 68
|
||||
#define ESRMNT 69
|
||||
#define ECOMM 70
|
||||
#define EPROTO 71
|
||||
#define EMULTIHOP 72
|
||||
#define EDOTDOT 73
|
||||
#define EBADMSG 74
|
||||
#define EOVERFLOW 75
|
||||
#define ENOTUNIQ 76
|
||||
#define EBADFD 77
|
||||
#define EREMCHG 78
|
||||
#define ELIBACC 79
|
||||
#define ELIBBAD 80
|
||||
#define ELIBSCN 81
|
||||
#define ELIBMAX 82
|
||||
#define ELIBEXEC 83
|
||||
#define EILSEQ 84
|
||||
#define ERESTART 85
|
||||
#define ESTRPIPE 86
|
||||
#define EUSERS 87
|
||||
#define ENOTSOCK 88
|
||||
#define EDESTADDRREQ 89
|
||||
#define EMSGSIZE 90
|
||||
#define EPROTOTYPE 91
|
||||
#define ENOPROTOOPT 92
|
||||
#define EPROTONOSUPPORT 93
|
||||
#define ESOCKTNOSUPPORT 94
|
||||
#define EOPNOTSUPP 95
|
||||
#define ENOTSUP EOPNOTSUPP
|
||||
#define EPFNOSUPPORT 96
|
||||
#define EAFNOSUPPORT 97
|
||||
#define EADDRINUSE 98
|
||||
#define EADDRNOTAVAIL 99
|
||||
#define ENETDOWN 100
|
||||
#define ENETUNREACH 101
|
||||
#define ENETRESET 102
|
||||
#define ECONNABORTED 103
|
||||
#define ECONNRESET 104
|
||||
#define ENOBUFS 105
|
||||
#define EISCONN 106
|
||||
#define ENOTCONN 107
|
||||
#define ESHUTDOWN 108
|
||||
#define ETOOMANYREFS 109
|
||||
#define ETIMEDOUT 110
|
||||
#define ECONNREFUSED 111
|
||||
#define EHOSTDOWN 112
|
||||
#define EHOSTUNREACH 113
|
||||
#define EALREADY 114
|
||||
#define EINPROGRESS 115
|
||||
#define ESTALE 116
|
||||
#define EUCLEAN 117
|
||||
#define ENOTNAM 118
|
||||
#define ENAVAIL 119
|
||||
#define EISNAM 120
|
||||
#define EREMOTEIO 121
|
||||
#define EDQUOT 122
|
||||
#define ENOMEDIUM 123
|
||||
#define EMEDIUMTYPE 124
|
||||
#define ECANCELED 125
|
||||
#define ENOKEY 126
|
||||
#define EKEYEXPIRED 127
|
||||
#define EKEYREVOKED 128
|
||||
#define EKEYREJECTED 129
|
||||
#define EOWNERDEAD 130
|
||||
#define ENOTRECOVERABLE 131
|
||||
#define ERFKILL 132
|
||||
#define EHWPOISON 133
|
|
@ -0,0 +1,40 @@
|
|||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
#define O_TRUNC 01000
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000
|
||||
#define O_DSYNC 010000
|
||||
#define O_SYNC 04010000
|
||||
#define O_RSYNC 04010000
|
||||
#define O_DIRECTORY 0200000
|
||||
#define O_NOFOLLOW 0400000
|
||||
#define O_CLOEXEC 02000000
|
||||
|
||||
#define O_ASYNC 020000
|
||||
#define O_DIRECT 040000
|
||||
#define O_LARGEFILE 0100000
|
||||
#define O_NOATIME 01000000
|
||||
#define O_PATH 010000000
|
||||
#define O_TMPFILE 020200000
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define F_SETOWN 8
|
||||
#define F_GETOWN 9
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define F_GETLK 12
|
||||
#define F_SETLK 13
|
||||
#define F_SETLKW 14
|
||||
|
||||
#define F_SETOWN_EX 15
|
||||
#define F_GETOWN_EX 16
|
||||
|
||||
#define F_GETOWNER_UIDS 17
|
|
@ -0,0 +1,10 @@
|
|||
#define FE_ALL_EXCEPT 0
|
||||
#define FE_TONEAREST 0
|
||||
|
||||
typedef unsigned long fexcept_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned long __cw;
|
||||
} fenv_t;
|
||||
|
||||
#define FE_DFL_ENV ((const fenv_t *) -1)
|
|
@ -0,0 +1,115 @@
|
|||
#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
|
||||
#define _IOC_NONE 0U
|
||||
#define _IOC_WRITE 1U
|
||||
#define _IOC_READ 2U
|
||||
|
||||
#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
|
||||
#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
|
||||
#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
|
||||
#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
|
||||
|
||||
#define TCGETS 0x5401
|
||||
#define TCSETS 0x5402
|
||||
#define TCSETSW 0x5403
|
||||
#define TCSETSF 0x5404
|
||||
#define TCGETA 0x5405
|
||||
#define TCSETA 0x5406
|
||||
#define TCSETAW 0x5407
|
||||
#define TCSETAF 0x5408
|
||||
#define TCSBRK 0x5409
|
||||
#define TCXONC 0x540A
|
||||
#define TCFLSH 0x540B
|
||||
#define TIOCEXCL 0x540C
|
||||
#define TIOCNXCL 0x540D
|
||||
#define TIOCSCTTY 0x540E
|
||||
#define TIOCGPGRP 0x540F
|
||||
#define TIOCSPGRP 0x5410
|
||||
#define TIOCOUTQ 0x5411
|
||||
#define TIOCSTI 0x5412
|
||||
#define TIOCGWINSZ 0x5413
|
||||
#define TIOCSWINSZ 0x5414
|
||||
#define TIOCMGET 0x5415
|
||||
#define TIOCMBIS 0x5416
|
||||
#define TIOCMBIC 0x5417
|
||||
#define TIOCMSET 0x5418
|
||||
#define TIOCGSOFTCAR 0x5419
|
||||
#define TIOCSSOFTCAR 0x541A
|
||||
#define FIONREAD 0x541B
|
||||
#define TIOCINQ FIONREAD
|
||||
#define TIOCLINUX 0x541C
|
||||
#define TIOCCONS 0x541D
|
||||
#define TIOCGSERIAL 0x541E
|
||||
#define TIOCSSERIAL 0x541F
|
||||
#define TIOCPKT 0x5420
|
||||
#define FIONBIO 0x5421
|
||||
#define TIOCNOTTY 0x5422
|
||||
#define TIOCSETD 0x5423
|
||||
#define TIOCGETD 0x5424
|
||||
#define TCSBRKP 0x5425
|
||||
#define TIOCSBRK 0x5427
|
||||
#define TIOCCBRK 0x5428
|
||||
#define TIOCGSID 0x5429
|
||||
#define TIOCGRS485 0x542E
|
||||
#define TIOCSRS485 0x542F
|
||||
#define TIOCGPTN 0x80045430
|
||||
#define TIOCSPTLCK 0x40045431
|
||||
#define TIOCGDEV 0x80045432
|
||||
#define TCGETX 0x5432
|
||||
#define TCSETX 0x5433
|
||||
#define TCSETXF 0x5434
|
||||
#define TCSETXW 0x5435
|
||||
#define TIOCSIG 0x40045436
|
||||
#define TIOCVHANGUP 0x5437
|
||||
#define TIOCGPKT 0x80045438
|
||||
#define TIOCGPTLCK 0x80045439
|
||||
#define TIOCGEXCL 0x80045440
|
||||
#define TIOCGPTPEER 0x5441
|
||||
#define TIOCGISO7816 0x80285442
|
||||
#define TIOCSISO7816 0xc0285443
|
||||
|
||||
#define FIONCLEX 0x5450
|
||||
#define FIOCLEX 0x5451
|
||||
#define FIOASYNC 0x5452
|
||||
#define TIOCSERCONFIG 0x5453
|
||||
#define TIOCSERGWILD 0x5454
|
||||
#define TIOCSERSWILD 0x5455
|
||||
#define TIOCGLCKTRMIOS 0x5456
|
||||
#define TIOCSLCKTRMIOS 0x5457
|
||||
#define TIOCSERGSTRUCT 0x5458
|
||||
#define TIOCSERGETLSR 0x5459
|
||||
#define TIOCSERGETMULTI 0x545A
|
||||
#define TIOCSERSETMULTI 0x545B
|
||||
|
||||
#define TIOCMIWAIT 0x545C
|
||||
#define TIOCGICOUNT 0x545D
|
||||
#define FIOQSIZE 0x5460
|
||||
|
||||
#define TIOCM_LE 0x001
|
||||
#define TIOCM_DTR 0x002
|
||||
#define TIOCM_RTS 0x004
|
||||
#define TIOCM_ST 0x008
|
||||
#define TIOCM_SR 0x010
|
||||
#define TIOCM_CTS 0x020
|
||||
#define TIOCM_CAR 0x040
|
||||
#define TIOCM_RNG 0x080
|
||||
#define TIOCM_DSR 0x100
|
||||
#define TIOCM_CD TIOCM_CAR
|
||||
#define TIOCM_RI TIOCM_RNG
|
||||
#define TIOCM_OUT1 0x2000
|
||||
#define TIOCM_OUT2 0x4000
|
||||
#define TIOCM_LOOP 0x8000
|
||||
|
||||
#define FIOSETOWN 0x8901
|
||||
#define SIOCSPGRP 0x8902
|
||||
#define FIOGETOWN 0x8903
|
||||
#define SIOCGPGRP 0x8904
|
||||
#define SIOCATMARK 0x8905
|
||||
#if __LONG_MAX == 0x7fffffff
|
||||
#define SIOCGSTAMP _IOR(0x89, 6, char[16])
|
||||
#define SIOCGSTAMPNS _IOR(0x89, 7, char[16])
|
||||
#else
|
||||
#define SIOCGSTAMP 0x8906
|
||||
#define SIOCGSTAMPNS 0x8907
|
||||
#endif
|
||||
|
||||
#include <bits/ioctl_fix.h>
|
|
@ -0,0 +1,11 @@
|
|||
struct ipc_perm {
|
||||
key_t __ipc_perm_key;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
uid_t cuid;
|
||||
gid_t cgid;
|
||||
mode_t mode;
|
||||
int __ipc_perm_seq;
|
||||
long __pad1;
|
||||
long __pad2;
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
#define IPC_STAT 2
|
|
@ -0,0 +1 @@
|
|||
#include <linux/kd.h>
|
|
@ -0,0 +1 @@
|
|||
typedef uint32_t Elf_Symndx;
|
|
@ -0,0 +1,12 @@
|
|||
struct msqid_ds {
|
||||
struct ipc_perm msg_perm;
|
||||
time_t msg_stime;
|
||||
time_t msg_rtime;
|
||||
time_t msg_ctime;
|
||||
unsigned long msg_cbytes;
|
||||
msgqnum_t msg_qnum;
|
||||
msglen_t msg_qbytes;
|
||||
pid_t msg_lspid;
|
||||
pid_t msg_lrpid;
|
||||
unsigned long __unused[2];
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
struct semid_ds {
|
||||
struct ipc_perm sem_perm;
|
||||
time_t sem_otime;
|
||||
time_t sem_ctime;
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
unsigned short sem_nsems;
|
||||
char __sem_nsems_pad[sizeof(long)-sizeof(short)];
|
||||
#else
|
||||
char __sem_nsems_pad[sizeof(long)-sizeof(short)];
|
||||
unsigned short sem_nsems;
|
||||
#endif
|
||||
long __unused3;
|
||||
long __unused4;
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
#define SHMLBA 4096
|
||||
|
||||
struct shmid_ds {
|
||||
struct ipc_perm shm_perm;
|
||||
size_t shm_segsz;
|
||||
time_t shm_atime;
|
||||
time_t shm_dtime;
|
||||
time_t shm_ctime;
|
||||
pid_t shm_cpid;
|
||||
pid_t shm_lpid;
|
||||
unsigned long shm_nattch;
|
||||
unsigned long __pad1;
|
||||
unsigned long __pad2;
|
||||
};
|
||||
|
||||
struct shminfo {
|
||||
unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
|
||||
};
|
||||
|
||||
struct shm_info {
|
||||
int __used_ids;
|
||||
unsigned long shm_tot, shm_rss, shm_swp;
|
||||
unsigned long __swap_attempts, __swap_successes;
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
#include <linux/soundcard.h>
|
|
@ -0,0 +1,7 @@
|
|||
struct statfs {
|
||||
unsigned long f_type, f_bsize;
|
||||
fsblkcnt_t f_blocks, f_bfree, f_bavail;
|
||||
fsfilcnt_t f_files, f_ffree;
|
||||
fsid_t f_fsid;
|
||||
unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
|
||||
};
|
|
@ -0,0 +1,166 @@
|
|||
struct termios {
|
||||
tcflag_t c_iflag;
|
||||
tcflag_t c_oflag;
|
||||
tcflag_t c_cflag;
|
||||
tcflag_t c_lflag;
|
||||
cc_t c_line;
|
||||
cc_t c_cc[NCCS];
|
||||
speed_t __c_ispeed;
|
||||
speed_t __c_ospeed;
|
||||
};
|
||||
|
||||
#define VINTR 0
|
||||
#define VQUIT 1
|
||||
#define VERASE 2
|
||||
#define VKILL 3
|
||||
#define VEOF 4
|
||||
#define VTIME 5
|
||||
#define VMIN 6
|
||||
#define VSWTC 7
|
||||
#define VSTART 8
|
||||
#define VSTOP 9
|
||||
#define VSUSP 10
|
||||
#define VEOL 11
|
||||
#define VREPRINT 12
|
||||
#define VDISCARD 13
|
||||
#define VWERASE 14
|
||||
#define VLNEXT 15
|
||||
#define VEOL2 16
|
||||
|
||||
#define IGNBRK 0000001
|
||||
#define BRKINT 0000002
|
||||
#define IGNPAR 0000004
|
||||
#define PARMRK 0000010
|
||||
#define INPCK 0000020
|
||||
#define ISTRIP 0000040
|
||||
#define INLCR 0000100
|
||||
#define IGNCR 0000200
|
||||
#define ICRNL 0000400
|
||||
#define IUCLC 0001000
|
||||
#define IXON 0002000
|
||||
#define IXANY 0004000
|
||||
#define IXOFF 0010000
|
||||
#define IMAXBEL 0020000
|
||||
#define IUTF8 0040000
|
||||
|
||||
#define OPOST 0000001
|
||||
#define OLCUC 0000002
|
||||
#define ONLCR 0000004
|
||||
#define OCRNL 0000010
|
||||
#define ONOCR 0000020
|
||||
#define ONLRET 0000040
|
||||
#define OFILL 0000100
|
||||
#define OFDEL 0000200
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
|
||||
#define NLDLY 0000400
|
||||
#define NL0 0000000
|
||||
#define NL1 0000400
|
||||
#define CRDLY 0003000
|
||||
#define CR0 0000000
|
||||
#define CR1 0001000
|
||||
#define CR2 0002000
|
||||
#define CR3 0003000
|
||||
#define TABDLY 0014000
|
||||
#define TAB0 0000000
|
||||
#define TAB1 0004000
|
||||
#define TAB2 0010000
|
||||
#define TAB3 0014000
|
||||
#define BSDLY 0020000
|
||||
#define BS0 0000000
|
||||
#define BS1 0020000
|
||||
#define FFDLY 0100000
|
||||
#define FF0 0000000
|
||||
#define FF1 0100000
|
||||
#endif
|
||||
|
||||
#define VTDLY 0040000
|
||||
#define VT0 0000000
|
||||
#define VT1 0040000
|
||||
|
||||
#define B0 0000000
|
||||
#define B50 0000001
|
||||
#define B75 0000002
|
||||
#define B110 0000003
|
||||
#define B134 0000004
|
||||
#define B150 0000005
|
||||
#define B200 0000006
|
||||
#define B300 0000007
|
||||
#define B600 0000010
|
||||
#define B1200 0000011
|
||||
#define B1800 0000012
|
||||
#define B2400 0000013
|
||||
#define B4800 0000014
|
||||
#define B9600 0000015
|
||||
#define B19200 0000016
|
||||
#define B38400 0000017
|
||||
|
||||
#define B57600 0010001
|
||||
#define B115200 0010002
|
||||
#define B230400 0010003
|
||||
#define B460800 0010004
|
||||
#define B500000 0010005
|
||||
#define B576000 0010006
|
||||
#define B921600 0010007
|
||||
#define B1000000 0010010
|
||||
#define B1152000 0010011
|
||||
#define B1500000 0010012
|
||||
#define B2000000 0010013
|
||||
#define B2500000 0010014
|
||||
#define B3000000 0010015
|
||||
#define B3500000 0010016
|
||||
#define B4000000 0010017
|
||||
|
||||
#define CSIZE 0000060
|
||||
#define CS5 0000000
|
||||
#define CS6 0000020
|
||||
#define CS7 0000040
|
||||
#define CS8 0000060
|
||||
#define CSTOPB 0000100
|
||||
#define CREAD 0000200
|
||||
#define PARENB 0000400
|
||||
#define PARODD 0001000
|
||||
#define HUPCL 0002000
|
||||
#define CLOCAL 0004000
|
||||
|
||||
#define ISIG 0000001
|
||||
#define ICANON 0000002
|
||||
#define ECHO 0000010
|
||||
#define ECHOE 0000020
|
||||
#define ECHOK 0000040
|
||||
#define ECHONL 0000100
|
||||
#define NOFLSH 0000200
|
||||
#define TOSTOP 0000400
|
||||
#define IEXTEN 0100000
|
||||
|
||||
#define TCOOFF 0
|
||||
#define TCOON 1
|
||||
#define TCIOFF 2
|
||||
#define TCION 3
|
||||
|
||||
#define TCIFLUSH 0
|
||||
#define TCOFLUSH 1
|
||||
#define TCIOFLUSH 2
|
||||
|
||||
#define TCSANOW 0
|
||||
#define TCSADRAIN 1
|
||||
#define TCSAFLUSH 2
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
#define EXTA 0000016
|
||||
#define EXTB 0000017
|
||||
#define CBAUD 0010017
|
||||
#define CBAUDEX 0010000
|
||||
#define CIBAUD 002003600000
|
||||
#define CMSPAR 010000000000
|
||||
#define CRTSCTS 020000000000
|
||||
|
||||
#define XCASE 0000004
|
||||
#define ECHOCTL 0001000
|
||||
#define ECHOPRT 0002000
|
||||
#define ECHOKE 0004000
|
||||
#define FLUSHO 0010000
|
||||
#define PENDIN 0040000
|
||||
#define EXTPROC 0200000
|
||||
|
||||
#define XTABS 0014000
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
#include <linux/vt.h>
|
|
@ -0,0 +1,108 @@
|
|||
#define a_cas a_cas
|
||||
static inline int a_cas(volatile int *p, int t, int s)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"lock ; cmpxchg %3, %1"
|
||||
: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
|
||||
return t;
|
||||
}
|
||||
|
||||
#define a_swap a_swap
|
||||
static inline int a_swap(volatile int *p, int v)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"xchg %0, %1"
|
||||
: "=r"(v), "=m"(*p) : "0"(v) : "memory" );
|
||||
return v;
|
||||
}
|
||||
|
||||
#define a_fetch_add a_fetch_add
|
||||
static inline int a_fetch_add(volatile int *p, int v)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"lock ; xadd %0, %1"
|
||||
: "=r"(v), "=m"(*p) : "0"(v) : "memory" );
|
||||
return v;
|
||||
}
|
||||
|
||||
#define a_and a_and
|
||||
static inline void a_and(volatile int *p, int v)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"lock ; and %1, %0"
|
||||
: "=m"(*p) : "r"(v) : "memory" );
|
||||
}
|
||||
|
||||
#define a_or a_or
|
||||
static inline void a_or(volatile int *p, int v)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"lock ; or %1, %0"
|
||||
: "=m"(*p) : "r"(v) : "memory" );
|
||||
}
|
||||
|
||||
#define a_inc a_inc
|
||||
static inline void a_inc(volatile int *p)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"lock ; incl %0"
|
||||
: "=m"(*p) : "m"(*p) : "memory" );
|
||||
}
|
||||
|
||||
#define a_dec a_dec
|
||||
static inline void a_dec(volatile int *p)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"lock ; decl %0"
|
||||
: "=m"(*p) : "m"(*p) : "memory" );
|
||||
}
|
||||
|
||||
#define a_store a_store
|
||||
static inline void a_store(volatile int *p, int x)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"mov %1, %0 ; lock ; orl $0,(%%esp)"
|
||||
: "=m"(*p) : "r"(x) : "memory" );
|
||||
}
|
||||
|
||||
#define a_barrier a_barrier
|
||||
static inline void a_barrier()
|
||||
{
|
||||
__asm__ __volatile__( "" : : : "memory" );
|
||||
}
|
||||
|
||||
#define a_spin a_spin
|
||||
static inline void a_spin()
|
||||
{
|
||||
__asm__ __volatile__( "pause" : : : "memory" );
|
||||
}
|
||||
|
||||
#define a_crash a_crash
|
||||
static inline void a_crash()
|
||||
{
|
||||
__asm__ __volatile__( "hlt" : : : "memory" );
|
||||
}
|
||||
|
||||
#define a_ctz_64 a_ctz_64
|
||||
static inline int a_ctz_64(uint64_t x)
|
||||
{
|
||||
int r;
|
||||
__asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:"
|
||||
: "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
|
||||
return r;
|
||||
}
|
||||
|
||||
#define a_ctz_32 a_ctz_32
|
||||
static inline int a_ctz_32(uint32_t x)
|
||||
{
|
||||
int r;
|
||||
__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
|
||||
return r;
|
||||
}
|
||||
|
||||
#define a_clz_32 a_clz_32
|
||||
static inline int a_clz_32(uint32_t x)
|
||||
{
|
||||
__asm__( "bsr %1,%0 ; xor $31,%0" : "=r"(x) : "r"(x) );
|
||||
return x;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#define FE_INVALID 1
|
||||
#define __FE_DENORM 2
|
||||
#define FE_DIVBYZERO 4
|
||||
#define FE_OVERFLOW 8
|
||||
#define FE_UNDERFLOW 16
|
||||
#define FE_INEXACT 32
|
||||
|
||||
#define FE_ALL_EXCEPT 63
|
||||
|
||||
#define FE_TONEAREST 0
|
||||
#define FE_DOWNWARD 0x400
|
||||
#define FE_UPWARD 0x800
|
||||
#define FE_TOWARDZERO 0xc00
|
||||
|
||||
typedef unsigned short fexcept_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short __control_word;
|
||||
unsigned short __unused1;
|
||||
unsigned short __status_word;
|
||||
unsigned short __unused2;
|
||||
unsigned short __tags;
|
||||
unsigned short __unused3;
|
||||
unsigned int __eip;
|
||||
unsigned short __cs_selector;
|
||||
unsigned int __opcode:11;
|
||||
unsigned int __unused4:5;
|
||||
unsigned int __data_offset;
|
||||
unsigned short __data_selector;
|
||||
unsigned short __unused5;
|
||||
} fenv_t;
|
||||
|
||||
#define FE_DFL_ENV ((const fenv_t *) -1)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue