blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 4
721
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 5
91
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringclasses 321
values | visit_date
timestamp[ns]date 2016-08-12 09:31:09
2023-09-06 10:45:07
| revision_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| github_id
int64 426
681M
| star_events_count
int64 101
243k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 23
values | gha_event_created_at
timestamp[ns]date 2012-06-28 18:51:49
2023-09-14 21:59:16
⌀ | gha_created_at
timestamp[ns]date 2008-02-11 22:55:26
2023-08-10 11:14:58
⌀ | gha_language
stringclasses 147
values | src_encoding
stringclasses 26
values | language
stringclasses 2
values | is_vendor
bool 2
classes | is_generated
bool 2
classes | length_bytes
int64 6
10.2M
| extension
stringclasses 115
values | filename
stringlengths 3
113
| content
stringlengths 6
10.2M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
96c550e6a6a32030b546183014020dd8d5c9839c
|
8886361e436c7598419f444a52ae587bf94b1fbe
|
/internal-complibs/zlib-ng-2.0.7/zbuild.h
|
17f98101a43dc7f29d836317dde0fccc173baf8d
|
[
"BSD-3-Clause",
"Zlib"
] |
permissive
|
Blosc/c-blosc2
|
d4b69bf735e1440ea1d7e147f434b488f975c8d4
|
6bbade9e13bd166ea0189f8c3b6253c9bbe9bb54
|
refs/heads/main
| 2023-08-31T15:47:35.224132
| 2023-08-31T03:01:37
| 2023-08-31T06:01:40
| 40,355,993
| 358
| 85
|
NOASSERTION
| 2023-09-12T09:26:36
| 2015-08-07T10:51:35
|
C
|
UTF-8
|
C
| false
| false
| 1,070
|
h
|
zbuild.h
|
#ifndef _ZBUILD_H
#define _ZBUILD_H
#ifndef _ISOC11_SOURCE
# define _ISOC11_SOURCE 1 /* aligned_alloc */
#endif
/* This has to be first include that defines any types */
#if defined(_MSC_VER)
# if defined(_WIN64)
typedef __int64 ssize_t;
# else
typedef long ssize_t;
# endif
#endif
#if defined(ZLIB_COMPAT)
# define PREFIX(x) x
# define PREFIX2(x) ZLIB_ ## x
# define PREFIX3(x) z_ ## x
# define PREFIX4(x) x ## 64
# define zVersion zlibVersion
# define z_size_t unsigned long
#else
# define PREFIX(x) zng_ ## x
# define PREFIX2(x) ZLIBNG_ ## x
# define PREFIX3(x) zng_ ## x
# define PREFIX4(x) zng_ ## x
# define zVersion zlibng_version
# define z_size_t size_t
#endif
/* Minimum of a and b. */
#define MIN(a, b) ((a) > (b) ? (b) : (a))
/* Maximum of a and b. */
#define MAX(a, b) ((a) < (b) ? (b) : (a))
/* Ignore unused variable warning */
#define Z_UNUSED(var) (void)(var)
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# define Z_MEMORY_SANITIZER 1
# include <sanitizer/msan_interface.h>
# endif
#endif
#endif
|
66c61d0f769d89aad9d1bd26a201ab288d687b6d
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/src/VBox/Devices/PC/ipxe/src/include/ipxe/ib_pathrec.h
|
1fe67f87dc6342393e2cbfb8a26c2c852e4936bd
|
[
"MIT",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"CDDL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.1-or-later",
"GPL-2.0-or-later",
"MPL-1.0",
"LicenseRef-scancode-generic-exception",
"Apache-2.0",
"OpenSSL"
] |
permissive
|
thalium/icebox
|
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
|
6f78952d58da52ea4f0e55b2ab297f28e80c1160
|
refs/heads/master
| 2022-08-14T00:19:36.984579
| 2022-02-22T13:10:31
| 2022-02-22T13:10:31
| 190,019,914
| 585
| 109
|
MIT
| 2022-01-13T20:58:15
| 2019-06-03T14:18:12
|
C++
|
UTF-8
|
C
| false
| false
| 1,669
|
h
|
ib_pathrec.h
|
#ifndef _IPXE_IB_PATHREC_H
#define _IPXE_IB_PATHREC_H
/** @file
*
* Infiniband path records
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/infiniband.h>
struct ib_mad_transaction;
struct ib_path;
/** Infiniband path operations */
struct ib_path_operations {
/** Handle path transaction completion
*
* @v ibdev Infiniband device
* @v path Path
* @v rc Status code
* @v av Address vector, or NULL on error
*/
void ( * complete ) ( struct ib_device *ibdev,
struct ib_path *path, int rc,
struct ib_address_vector *av );
};
/** An Infiniband path */
struct ib_path {
/** Infiniband device */
struct ib_device *ibdev;
/** Address vector */
struct ib_address_vector av;
/** Management transaction */
struct ib_mad_transaction *madx;
/** Path operations */
struct ib_path_operations *op;
/** Owner private data */
void *owner_priv;
};
/**
* Set Infiniband path owner-private data
*
* @v path Path
* @v priv Private data
*/
static inline __always_inline void
ib_path_set_ownerdata ( struct ib_path *path, void *priv ) {
path->owner_priv = priv;
}
/**
* Get Infiniband path owner-private data
*
* @v path Path
* @ret priv Private data
*/
static inline __always_inline void *
ib_path_get_ownerdata ( struct ib_path *path ) {
return path->owner_priv;
}
extern struct ib_path *
ib_create_path ( struct ib_device *ibdev, struct ib_address_vector *av,
struct ib_path_operations *op );
extern void ib_destroy_path ( struct ib_device *ibdev,
struct ib_path *path );
extern int ib_resolve_path ( struct ib_device *ibdev,
struct ib_address_vector *av );
#endif /* _IPXE_IB_PATHREC_H */
|
e1bd3bbba63ccafea2c576d0edd57f3472e74e09
|
ea401c3e792a50364fe11f7cea0f35f99e8f4bde
|
/hackathon/donghao/Bigneuron_donghao_soma/fastmarching/msfm.h
|
963246323d09f4527cbead5cef8296afc5a18e16
|
[
"MIT",
"Apache-2.0"
] |
permissive
|
Vaa3D/vaa3d_tools
|
edb696aa3b9b59acaf83d6d27c6ae0a14bf75fe9
|
e6974d5223ae70474efaa85e1253f5df1814fae8
|
refs/heads/master
| 2023-08-03T06:12:01.013752
| 2023-08-02T07:26:01
| 2023-08-02T07:26:01
| 50,527,925
| 107
| 86
|
MIT
| 2023-05-22T23:43:48
| 2016-01-27T18:19:17
|
C++
|
UTF-8
|
C
| false
| false
| 172
|
h
|
msfm.h
|
#ifndef __MSFM_H__
#define __MSFM_H__
#include "stackutil.h"
double* msfm(double *F, V3DLONG* in_sz, int *SourcePoints, bool useseconda, bool usecrossa, bool Ed);
#endif
|
6c5531cdc176f23419a42163306680a3e140512e
|
7bc1d8634529eac952490399fb71f10bcedf05cc
|
/third_party/mbedtls/repo/tests/src/threading_helpers.c
|
ca91b7933a5cb5eedd29693cea2621f30c40137f
|
[
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"GPL-2.0-or-later",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause"
] |
permissive
|
openthread/openthread
|
6a9e25d1cd224bde9796d9616f04f423dba27d77
|
102a631cb3f8938389d0d10199a14c59184039cd
|
refs/heads/main
| 2023-08-18T10:46:03.820124
| 2023-08-17T22:20:55
| 2023-08-17T22:20:55
| 55,808,787
| 3,485
| 1,296
|
BSD-3-Clause
| 2023-09-14T15:50:53
| 2016-04-08T20:47:41
|
C++
|
UTF-8
|
C
| false
| false
| 8,299
|
c
|
threading_helpers.c
|
/** Mutex usage verification framework. */
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <test/helpers.h>
#include <test/macros.h>
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
#include "mbedtls/threading.h"
/** Mutex usage verification framework.
*
* The mutex usage verification code below aims to detect bad usage of
* Mbed TLS's mutex abstraction layer at runtime. Note that this is solely
* about the use of the mutex itself, not about checking whether the mutex
* correctly protects whatever it is supposed to protect.
*
* The normal usage of a mutex is:
* ```
* digraph mutex_states {
* "UNINITIALIZED"; // the initial state
* "IDLE";
* "FREED";
* "LOCKED";
* "UNINITIALIZED" -> "IDLE" [label="init"];
* "FREED" -> "IDLE" [label="init"];
* "IDLE" -> "LOCKED" [label="lock"];
* "LOCKED" -> "IDLE" [label="unlock"];
* "IDLE" -> "FREED" [label="free"];
* }
* ```
*
* All bad transitions that can be unambiguously detected are reported.
* An attempt to use an uninitialized mutex cannot be detected in general
* since the memory content may happen to denote a valid state. For the same
* reason, a double init cannot be detected.
* All-bits-zero is the state of a freed mutex, which is distinct from an
* initialized mutex, so attempting to use zero-initialized memory as a mutex
* without calling the init function is detected.
*
* The framework attempts to detect missing calls to init and free by counting
* calls to init and free. If there are more calls to init than free, this
* means that a mutex is not being freed somewhere, which is a memory leak
* on platforms where a mutex consumes resources other than the
* mbedtls_threading_mutex_t object itself. If there are more calls to free
* than init, this indicates a missing init, which is likely to be detected
* by an attempt to lock the mutex as well. A limitation of this framework is
* that it cannot detect scenarios where there is exactly the same number of
* calls to init and free but the calls don't match. A bug like this is
* unlikely to happen uniformly throughout the whole test suite though.
*
* If an error is detected, this framework will report what happened and the
* test case will be marked as failed. Unfortunately, the error report cannot
* indicate the exact location of the problematic call. To locate the error,
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
*/
enum value_of_mutex_is_valid_field
{
/* Potential values for the is_valid field of mbedtls_threading_mutex_t.
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
* compatibility with threading_mutex_init_pthread() and
* threading_mutex_free_pthread(). MUTEX_LOCKED could be any nonzero
* value. */
MUTEX_FREED = 0, //!< Set by threading_mutex_free_pthread
MUTEX_IDLE = 1, //!< Set by threading_mutex_init_pthread and by our unlock
MUTEX_LOCKED = 2, //!< Set by our lock
};
typedef struct
{
void (*init)( mbedtls_threading_mutex_t * );
void (*free)( mbedtls_threading_mutex_t * );
int (*lock)( mbedtls_threading_mutex_t * );
int (*unlock)( mbedtls_threading_mutex_t * );
} mutex_functions_t;
static mutex_functions_t mutex_functions;
/** The total number of calls to mbedtls_mutex_init(), minus the total number
* of calls to mbedtls_mutex_free().
*
* Reset to 0 after each test case.
*/
static int live_mutexes;
static void mbedtls_test_mutex_usage_error( mbedtls_threading_mutex_t *mutex,
const char *msg )
{
(void) mutex;
if( mbedtls_test_info.mutex_usage_error == NULL )
mbedtls_test_info.mutex_usage_error = msg;
mbedtls_fprintf( stdout, "[mutex: %s] ", msg );
/* Don't mark the test as failed yet. This way, if the test fails later
* for a functional reason, the test framework will report the message
* and location for this functional reason. If the test passes,
* mbedtls_test_mutex_usage_check() will mark it as failed. */
}
static void mbedtls_test_wrap_mutex_init( mbedtls_threading_mutex_t *mutex )
{
mutex_functions.init( mutex );
if( mutex->is_valid )
++live_mutexes;
}
static void mbedtls_test_wrap_mutex_free( mbedtls_threading_mutex_t *mutex )
{
switch( mutex->is_valid )
{
case MUTEX_FREED:
mbedtls_test_mutex_usage_error( mutex, "free without init or double free" );
break;
case MUTEX_IDLE:
/* Do nothing. The underlying free function will reset is_valid
* to 0. */
break;
case MUTEX_LOCKED:
mbedtls_test_mutex_usage_error( mutex, "free without unlock" );
break;
default:
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
break;
}
if( mutex->is_valid )
--live_mutexes;
mutex_functions.free( mutex );
}
static int mbedtls_test_wrap_mutex_lock( mbedtls_threading_mutex_t *mutex )
{
int ret = mutex_functions.lock( mutex );
switch( mutex->is_valid )
{
case MUTEX_FREED:
mbedtls_test_mutex_usage_error( mutex, "lock without init" );
break;
case MUTEX_IDLE:
if( ret == 0 )
mutex->is_valid = 2;
break;
case MUTEX_LOCKED:
mbedtls_test_mutex_usage_error( mutex, "double lock" );
break;
default:
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
break;
}
return( ret );
}
static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex )
{
int ret = mutex_functions.unlock( mutex );
switch( mutex->is_valid )
{
case MUTEX_FREED:
mbedtls_test_mutex_usage_error( mutex, "unlock without init" );
break;
case MUTEX_IDLE:
mbedtls_test_mutex_usage_error( mutex, "unlock without lock" );
break;
case MUTEX_LOCKED:
if( ret == 0 )
mutex->is_valid = MUTEX_IDLE;
break;
default:
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
break;
}
return( ret );
}
void mbedtls_test_mutex_usage_init( void )
{
mutex_functions.init = mbedtls_mutex_init;
mutex_functions.free = mbedtls_mutex_free;
mutex_functions.lock = mbedtls_mutex_lock;
mutex_functions.unlock = mbedtls_mutex_unlock;
mbedtls_mutex_init = &mbedtls_test_wrap_mutex_init;
mbedtls_mutex_free = &mbedtls_test_wrap_mutex_free;
mbedtls_mutex_lock = &mbedtls_test_wrap_mutex_lock;
mbedtls_mutex_unlock = &mbedtls_test_wrap_mutex_unlock;
}
void mbedtls_test_mutex_usage_check( void )
{
if( live_mutexes != 0 )
{
/* A positive number (more init than free) means that a mutex resource
* is leaking (on platforms where a mutex consumes more than the
* mbedtls_threading_mutex_t object itself). The rare case of a
* negative number means a missing init somewhere. */
mbedtls_fprintf( stdout, "[mutex: %d leaked] ", live_mutexes );
live_mutexes = 0;
if( mbedtls_test_info.mutex_usage_error == NULL )
mbedtls_test_info.mutex_usage_error = "missing free";
}
if( mbedtls_test_info.mutex_usage_error != NULL &&
mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED )
{
/* Functionally, the test passed. But there was a mutex usage error,
* so mark the test as failed after all. */
mbedtls_test_fail( "Mutex usage error", __LINE__, __FILE__ );
}
mbedtls_test_info.mutex_usage_error = NULL;
}
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
ada332278376d20ee9ee8e72424168f46d4cde37
|
02cf845d18aea2fa6bc97c0cf61721905544f58c
|
/src/dns_resolver_ares.c
|
d1258c361277b637c715c69e2973154c8183b786
|
[
"MIT"
] |
permissive
|
Azure/azure-c-shared-utility
|
cd2921698074ed815a45ff7a11fbc11b14a934ac
|
0e120535898c4b00bb2ec6f3c4c7f59ee5e8ead8
|
refs/heads/master
| 2023-09-03T11:53:56.873558
| 2023-08-29T23:28:44
| 2023-08-29T23:28:44
| 44,986,892
| 116
| 239
|
NOASSERTION
| 2023-09-12T21:03:08
| 2015-10-26T17:53:51
|
C
|
UTF-8
|
C
| false
| false
| 13,032
|
c
|
dns_resolver_ares.c
|
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
// This file is OS-specific, and is identified by setting include directories
// in the project
#include "socket_async_os.h"
#include "azure_c_shared_utility/dns_resolver.h"
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/crt_abstractions.h"
#include "azure_c_shared_utility/xlogging.h"
#include "ares.h"
// EXTRACT_IPV4 pulls the uint32_t IPv4 address out of an addrinfo struct
// The default definition handles lwIP. Please add comments for other systems tested.
#define EXTRACT_IPV4(ptr) ((struct sockaddr_in *) ptr->ai_addr)->sin_addr.s_addr
#ifdef IPV6_ENABLED
// EXTRACT_IPV6 pulls the uint32_t IPv6 address out of an addrinfo struct
#define EXTRACT_IPV6(ptr) ((struct sockaddr_in6 *) ptr->ai_addr)->sin6_addr.s6_addr
#endif // IPV6_ENABLED
typedef struct
{
char* hostname;
int port;
uint32_t ip_v4;
#ifdef IPV6_ENABLED
uint8_t ip_v6[16];
#endif // IPV6_ENABLED
bool is_complete;
bool is_failed;
bool in_progress;
struct addrinfo* addrInfo;
ares_channel ares_resolver;
} DNSRESOLVER_INSTANCE;
DNSRESOLVER_HANDLE dns_resolver_create(const char* hostname, int port, const DNSRESOLVER_OPTIONS* options)
{
/* Codes_SRS_dns_resolver_30_012: [ The optional options parameter shall be ignored. ]*/
DNSRESOLVER_INSTANCE* result;
int status;
(void)options;
if (hostname == NULL)
{
/* Codes_SRS_dns_resolver_30_011: [ If the hostname parameter is NULL, dns_resolver_create shall log an error and return NULL. ]*/
LogError("NULL hostname");
result = NULL;
}
else
{
result = calloc(1, sizeof(DNSRESOLVER_INSTANCE));
if (result == NULL)
{
/* Codes_SRS_dns_resolver_30_014: [ On any failure, dns_resolver_create shall log an error and return NULL. ]*/
LogError("malloc instance failed");
result = NULL;
}
else
{
int ms_result;
result->is_complete = false;
result->is_failed = false;
result->in_progress = false;
result->ip_v4 = 0;
#ifdef IPV6_ENABLED
memset(result->ip_v6, 0, sizeof(result->ip_v6)); // zero out the IPv6 address
#endif // IPV6_ENABLED
result->port = port;
/* Codes_SRS_dns_resolver_30_010: [ dns_resolver_create shall make a copy of the hostname parameter to allow immediate deletion by the caller. ]*/
ms_result = mallocAndStrcpy_s(&result->hostname, hostname);
if (ms_result != 0)
{
/* Codes_SRS_dns_resolver_30_014: [ On any failure, dns_resolver_create shall log an error and return NULL. ]*/
LogError("dns_resolver_create: hostname allocation failed");
free(result);
result = NULL;
}
else
{
status = ares_library_init(ARES_LIB_INIT_WIN32);
if (status != ARES_SUCCESS)
{
LogError("ares_library_init failed: %s\n", ares_strerror(status));
free(result);
result = NULL;
}
else
{
status = ares_init(&(result->ares_resolver));
if(status != ARES_SUCCESS)
{
LogError("ares_init failed: %s\n", ares_strerror(status));
ares_library_cleanup();
free(result);
result = NULL;
}
}
}
}
}
if(result != NULL)
{
result->addrInfo = NULL;
}
return result;
}
static void query_completed_cb(void *arg, int status, int timeouts, struct hostent *he)
{
int i;
struct addrinfo *ptr = NULL;
struct sockaddr_in *addr;
#ifdef IPV6_ENABLED
struct sockaddr_in6 *addr6;
#endif // IPV6_ENABLED
DNSRESOLVER_INSTANCE *dns = (DNSRESOLVER_INSTANCE *)arg;
(void)timeouts;
if(status != ARES_SUCCESS)
{
LogError("ARES error: %d", status);
}
else
{
dns->addrInfo = calloc(1, sizeof(struct addrinfo));
if(dns->addrInfo == NULL)
{
LogError("dns addrInfo: allocation failed");
dns->is_failed = true;
dns->is_complete = true;
dns->in_progress = false;
}
#ifdef IPV6_ENABLED
else if (he->h_addrtype == AF_INET6)
{
ptr = dns->addrInfo;
ptr->ai_addr = calloc(1, sizeof(struct sockaddr_in6));
if(ptr->ai_addr == NULL)
{
LogError("dns addrinfo ai_addr: allocation failed");
free(dns->addrInfo);
dns->is_failed = true;
dns->is_complete = true;
dns->in_progress = false;
}
else
{
addr6 = (void *)ptr->ai_addr;
memcpy(&addr6->sin6_addr, he->h_addr_list[0], sizeof(struct in6_addr));
addr6->sin6_family = AF_INET6;
addr6->sin6_port = htons((unsigned short)dns->port);
/* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/
memcpy(dns->ip_v6, EXTRACT_IPV6(ptr), 16); // IPv6 address is 16 bytes
dns->addrInfo->ai_addrlen = sizeof(struct sockaddr_in6);
dns->addrInfo->ai_family = AF_INET6;
dns->addrInfo->ai_socktype = SOCK_STREAM;
dns->addrInfo->ai_protocol = IPPROTO_TCP;
dns->is_failed = (dns->ip_v6 == 0);
dns->is_complete = true;
dns->in_progress = false;
}
}
#endif // IPV6_ENABLED
else
{
ptr = dns->addrInfo;
ptr->ai_addr = calloc(1, sizeof(struct sockaddr_in));
if(ptr->ai_addr == NULL)
{
LogError("dns addrinfo ai_addr: allocation failed");
free(dns->addrInfo);
dns->is_failed = true;
dns->is_complete = true;
dns->in_progress = false;
}
else
{
addr = (void *)ptr->ai_addr;
if (he->h_addrtype == AF_INET)
{
memcpy(&addr->sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
addr->sin_family = he->h_addrtype;
addr->sin_port = htons((unsigned short)dns->port);
/* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/
dns->ip_v4 = EXTRACT_IPV4(ptr);
dns->addrInfo->ai_addrlen = sizeof(struct sockaddr_in);
dns->addrInfo->ai_family = AF_INET;
dns->addrInfo->ai_socktype = SOCK_STREAM;
dns->addrInfo->ai_protocol = IPPROTO_TCP;
dns->is_failed = (dns->ip_v4 == 0);
dns->is_complete = true;
dns->in_progress = false;
}
}
}
}
}
/* Codes_SRS_dns_resolver_30_021: [ dns_resolver_is_create_complete shall perform the asynchronous work of DNS lookup and log any errors. ]*/
bool dns_resolver_is_lookup_complete(DNSRESOLVER_HANDLE dns_in)
{
DNSRESOLVER_INSTANCE* dns = (DNSRESOLVER_INSTANCE*)dns_in;
ares_socket_t socket;
bool result;
if (dns == NULL)
{
/* Codes_SRS_dns_resolver_30_020: [ If the dns parameter is NULL, dns_resolver_is_create_complete shall log an error and return false. ]*/
LogError("NULL dns");
result = false;
}
else
{
if (dns->is_complete)
{
/* Codes_SRS_dns_resolver_30_024: [ If dns_resolver_is_create_complete has previously returned true, dns_resolver_is_create_complete shall do nothing and return true. ]*/
result = true;
}
else if(dns->is_failed)
{
dns->in_progress = false;
result = false;
}
else if(!dns->in_progress)
{
#ifdef IPV6_ENABLED
ares_gethostbyname(dns->ares_resolver, dns->hostname, AF_UNSPEC, query_completed_cb, (void*)dns);
#else
ares_gethostbyname(dns->ares_resolver, dns->hostname, AF_INET, query_completed_cb, (void*)dns);
#endif // IPV6_ENABLED
dns->in_progress = true;
// This synchronous implementation is incapable of being incomplete, so SRS_dns_resolver_30_023 does not ever happen
/* Codes_SRS_dns_resolver_30_023: [ If the DNS lookup process is not yet complete, dns_resolver_is_create_complete shall return false. ]*/
/* Codes_SRS_dns_resolver_30_022: [ If the DNS lookup process has completed, dns_resolver_is_create_complete shall return true. ]*/
result = false;
}
else
{
ares_getsock((ares_channel)dns->ares_resolver, &socket, 1);
ares_process_fd((ares_channel)dns->ares_resolver, socket, socket);
result = false;
}
}
return result;
}
void dns_resolver_destroy(DNSRESOLVER_HANDLE dns_in)
{
DNSRESOLVER_INSTANCE* dns = (DNSRESOLVER_INSTANCE*)dns_in;
if (dns == NULL)
{
/* Codes_SRS_dns_resolver_30_050: [ If the dns parameter is NULL, dns_resolver_destroy shall log an error and do nothing. ]*/
LogError("NULL dns");
}
else
{
/* Codes_SRS_dns_resolver_30_051: [ dns_resolver_destroy shall delete all acquired resources and delete the DNSRESOLVER_HANDLE. ]*/
ares_destroy(dns->ares_resolver);
ares_library_cleanup();
if(dns->addrInfo != NULL)
{
if(dns->addrInfo->ai_addr != NULL)
{
free(dns->addrInfo->ai_addr);
}
free(dns->addrInfo);
}
free(dns->hostname);
free(dns);
dns = NULL;
}
}
uint32_t dns_resolver_get_ipv4(DNSRESOLVER_HANDLE dns_in)
{
DNSRESOLVER_INSTANCE* dns = (DNSRESOLVER_INSTANCE*)dns_in;
uint32_t result;
if (dns == NULL)
{
/* Codes_SRS_dns_resolver_30_030: [ If the dns parameter is NULL, dns_resolver_get_ipv4 shall log an error and return 0. ]*/
LogError("NULL dns");
result = 0;
}
else
{
if (dns->is_complete)
{
if (dns->is_failed)
{
/* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/
result = 0;
}
else
{
/* Codes_SRS_dns_resolver_30_032: [ If dns_resolver_is_create_complete has returned true and the lookup process has succeeded, dns_resolver_get_ipv4 shall return the discovered IPv4 address. ]*/
result = dns->ip_v4;
}
}
else
{
/* Codes_SRS_dns_resolver_30_031: [ If dns_resolver_is_create_complete has not yet returned true, dns_resolver_get_ipv4 shall log an error and return 0. ]*/
LogError("dns_resolver_get_ipv4 when not complete");
result = 0;
}
}
return result;
}
struct addrinfo* dns_resolver_get_addrInfo(DNSRESOLVER_HANDLE dns_in)
{
DNSRESOLVER_INSTANCE* dns = (DNSRESOLVER_INSTANCE*)dns_in;
struct addrinfo* result;
if (dns == NULL)
{
/* Codes_SRS_dns_resolver_30_030: [ If the dns parameter is NULL, dns_resolver_get_ipv4 shall log an error and return 0. ]*/
LogError("NULL dns");
result = NULL;
}
else
{
if (dns->is_complete)
{
if (dns->is_failed)
{
/* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/
result = NULL;
}
else
{
/* Codes_SRS_dns_resolver_30_032: [ If dns_resolver_is_create_complete has returned true and the lookup process has succeeded, dns_resolver_get_ipv4 shall return the discovered IPv4 address. ]*/
result = dns->addrInfo;
}
}
else
{
/* Codes_SRS_dns_resolver_30_031: [ If dns_resolver_is_create_complete has not yet returned true, dns_resolver_get_ipv4 shall log an error and return 0. ]*/
LogError("dns_resolver_get_ipv4 when not complete");
result = NULL;
}
}
return result;
}
|
a4e3b407e302b83db0213d4b963b7c5fdbf10620
|
c6759b857e55991fea3ef0b465dbcee53fa38714
|
/examples/gap8/nn/autotiler/Cifar10/CifarData.h
|
dca20f3b9de429d6e48a356256ab3a13bdb3f160
|
[
"Apache-2.0"
] |
permissive
|
GreenWaves-Technologies/gap_sdk
|
1b343bba97b7a5ce62a24162bd72eef5cc67e269
|
3fea306d52ee33f923f2423c5a75d9eb1c07e904
|
refs/heads/master
| 2023-09-01T14:38:34.270427
| 2023-08-10T09:04:44
| 2023-08-10T09:04:44
| 133,324,605
| 145
| 96
|
Apache-2.0
| 2023-08-27T19:03:52
| 2018-05-14T07:50:29
|
C
|
UTF-8
|
C
| false
| false
| 6,509
|
h
|
CifarData.h
|
/*
* Copyright (C) 2020 GreenWaves Technologies
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*
*/
L2_MEM short int ImageIn[]={
3907, 2880, 3057, 3569, 4885, 6039, 7093, 7333, 7747, 7902, 6812, 6544, 7570, 7438, 6993, 6484, 7038, 6984, 6385, 7380, 7321, 6894, 6957, 7148, 7924, 8624, 8956, 8488, 8529, 8638, 8211, 8116,
1218, 0, 607, 1955, 3608, 5552, 5989, 5834, 5893, 5366, 4789, 4576, 4771, 5057, 4812, 4961, 5407, 4857, 4685, 5953, 6116, 5698, 6038, 5597, 5402, 6043, 6170, 6343, 6443, 5921, 5616, 5870,
1526, 535, 1928, 3504, 4952, 6179, 6243, 5584, 5230, 5266, 5321, 5053, 4917, 6139, 5852, 6202, 6025, 5752, 5348, 5707, 6330, 6393, 6806, 6048, 5980, 5998, 6188, 7011, 6302, 5648, 5675, 4989,
1662, 1442, 3749, 4429, 4893, 5111, 4988, 4393, 4693, 5666, 6030, 5071, 5207, 7020, 6156, 5747, 5238, 5229, 5915, 5534, 6206, 6625, 6607, 6243, 5793, 6129, 6106, 6292, 6084, 5879, 5725, 4253,
2228, 2305, 4494, 5492, 5347, 5306, 5356, 5089, 4880, 5921, 6029, 4671, 4844, 5647, 5365, 4689, 4390, 5026, 5448, 5452, 6275, 7020, 6361, 6669, 6247, 5747, 5420, 5389, 4589, 3895, 3259, 2932,
3277, 3658, 4980, 5651, 6051, 5788, 5765, 5284, 4798, 5584, 5529, 4494, 4867, 5149, 4985, 4408, 4190, 4326, 3845, 3994, 4666, 4663, 3812, 5291, 6623, 6547, 5470, 4698, 3758, 2750, 928, 1042,
4636, 5080, 5730, 5756, 6046, 5746, 5156, 5147, 5706, 6392, 5429, 5398, 4835, 3423, 2955, 2945, 3783, 4074, 2636, 2510, 2618, 3518, 6450, 5107, 6153, 7182, 5929, 4720, 4103, 4335, 4154, 3169,
5512, 5220, 6070, 6551, 6024, 5588, 6178, 6115, 5906, 6061, 6165, 4825, 2835, 1919, 1619, 2461, 7405, 8977, 5364, 2845, 2673, 3658, 5450, 4312, 5786, 7009, 6424, 5180, 4717, 4521, 6161, 4958,
6715, 5651, 6161, 5911, 5498, 5593, 5802, 5829, 5461, 6515, 6293, 3004, 1940, 2069, 1997, 3006, 7825, 8178, 6610, 4215, 3076, 3081, 2885, 2720, 4661, 6465, 6506, 6111, 5989, 5584, 5811, 6393,
7951, 7532, 7673, 6742, 5957, 5834, 5838, 6098, 6488, 6511, 4086, 2487, 2413, 2813, 3481, 3924, 5392, 5082, 5780, 5310, 4192, 3906, 3457, 2839, 4380, 6224, 6269, 6275, 6270, 6257, 5852, 6238,
8065, 7797, 7810, 7224, 6643, 6706, 6833, 6757, 7329, 5906, 2962, 3802, 3343, 4011, 6255, 5927, 6208, 5304, 5809, 5941, 6427, 8722, 6670, 4275, 4625, 6111, 5938, 6174, 6542, 6415, 5883, 6306,
7556, 7270, 7252, 6493, 6166, 6320, 5657, 4954, 6767, 5652, 4297, 5991, 5496, 7836, 7836, 6846, 7791, 6677, 8276, 7509, 9981, 10990, 9632, 5424, 4443, 6501, 6447, 6275, 6424, 6129, 5956, 6242,
7548, 7047, 6984, 7020, 7333, 5984, 3840, 4118, 5317, 4066, 5550, 9981, 8196, 9859, 11104, 9746, 10741, 10699, 10885, 9509, 10328, 9820, 8033, 5764, 5356, 5965, 6179, 6279, 6306, 6206, 6110, 6197,
8548, 7874, 7129, 6874, 6242, 4067, 3077, 3572, 3362, 4064, 7286, 11531, 8974, 10247, 13869, 12382, 12227, 12151, 11464, 11355, 11128, 10897, 10452, 9046, 7896, 6465, 6483, 6070, 6215, 6655, 6110, 6560,
7557, 7279, 7215, 7065, 6447, 3317, 3944, 4698, 3738, 5637, 10032, 9728, 6792, 10672, 12896, 14501, 14483, 13988, 13974, 12696, 12373, 13410, 13089, 13324, 12360, 7838, 6043, 6352, 6370, 6488, 6011, 6202,
7643, 6774, 6765, 6774, 6416, 2860, 2991, 3620, 4655, 9610, 12440, 6469, 7258, 10399, 10823, 14959, 16024, 15920, 14865, 13892, 13355, 12560, 13901, 15396, 14574, 8503, 6240, 6385, 6103, 6057, 5921, 5930,
7611, 6483, 6596, 6782, 5969, 2782, 4009, 4824, 8055, 13060, 11787, 6313, 9089, 10408, 12245, 14523, 15132, 14819, 14278, 13878, 11570, 8722, 12302, 15337, 13693, 9027, 8019, 8092, 7746, 7333, 6100, 5458,
7388, 6033, 6679, 6992, 6151, 4439, 4980, 6983, 11719, 15383, 9583, 8117, 11576, 12772, 13350, 13969, 13569, 11942, 10538, 10224, 10975, 9927, 10505, 13874, 13129, 8571, 7454, 7287, 7315, 7737, 7501, 6564,
7610, 5166, 5403, 6021, 6102, 5647, 4044, 10060, 14473, 15460, 8873, 8912, 13809, 13924, 10870, 10316, 9416, 7780, 7656, 8147, 10138, 12443, 12575, 14151, 13646, 8224, 5784, 5561, 5598, 5708, 6759, 8118,
7069, 5638, 6061, 6229, 6061, 6384, 9416, 14474, 15723, 13678, 8987, 8127, 11890, 10933, 5966, 6561, 6080, 7520, 8352, 6521, 8140, 11711, 14551, 14445, 12695, 7729, 5126, 5112, 4584, 4381, 4796, 7651,
6970, 5533, 5883, 5824, 5879, 6806, 12619, 14819, 12747, 11174, 8537, 7055, 9668, 9501, 5861, 6896, 7110, 8647, 7152, 6217, 7358, 9680, 11792, 11024, 11310, 8093, 4750, 5318, 5813, 6054, 5359, 7487,
6961, 5297, 5860, 5615, 5529, 7743, 7761, 9202, 10769, 10165, 8864, 7782, 9827, 10037, 7274, 6483, 7092, 7342, 6797, 6797, 6675, 6711, 7347, 7029, 7271, 7335, 6225, 6700, 7172, 7207, 7355, 10178,
6847, 5574, 6142, 6041, 6192, 7419, 6111, 6533, 9032, 9019, 9968, 10603, 10381, 8642, 7256, 6619, 6810, 7101, 7356, 7211, 6952, 6997, 6965, 6851, 6335, 6533, 7555, 7745, 7559, 7134, 8398, 11536,
6951, 6041, 6110, 6623, 7454, 7146, 6988, 7037, 8163, 8255, 9319, 11417, 10995, 11500, 7452, 6501, 6847, 6347, 7192, 7446, 7306, 6743, 5081, 4117, 4019, 6045, 8411, 8113, 6832, 6571, 9225, 10945,
7223, 5610, 6064, 6764, 7051, 7315, 7528, 7873, 8768, 9658, 8273, 10986, 12763, 11306, 10715, 9478, 7092, 5620, 6560, 7510, 7310, 5057, 3063, 3459, 4733, 7248, 8082, 7036, 6148, 7597, 10458, 8436,
8501, 6037, 5856, 6064, 6129, 6383, 7296, 7909, 8082, 9135, 8018, 7378, 9773, 8010, 8133, 8610, 7301, 6201, 5824, 5988, 5725, 5661, 6251, 7015, 7080, 7177, 6678, 6004, 6672, 10194, 11615, 6976,
10255, 8524, 6711, 5483, 5297, 6042, 6624, 7110, 7160, 6796, 6055, 5651, 7306, 8105, 6710, 5997, 5929, 7278, 7178, 6142, 6433, 7392, 7619, 7241, 7487, 6961, 6194, 6093, 8597, 11725, 9989, 5717,
11242, 8879, 7917, 7257, 5934, 5597, 6370, 6742, 6487, 6274, 5329, 5920, 6706, 6806, 6379, 5715, 5669, 6433, 7301, 7037, 6460, 6179, 6938, 7051, 7215, 7265, 6698, 7066, 10815, 11143, 6135, 3264,
11679, 9653, 9368, 8787, 7695, 6749, 6706, 7328, 7141, 6602, 5885, 6242, 6928, 6779, 6056, 5660, 5637, 6109, 6855, 7114, 6887, 5392, 5761, 6756, 7111, 7398, 6585, 5713, 10020, 9293, 2118, 1352,
10992, 9843, 10132, 9859, 9281, 8609, 7853, 7098, 6375, 5929, 6373, 6732, 6523, 6728, 6228, 6128, 6196, 6910, 7155, 6996, 7396, 6356, 5234, 5734, 6829, 6798, 4541, 1818, 6907, 8540, 2201, 2355,
9200, 8133, 9213, 9709, 10031, 10354, 9673, 8727, 7658, 6562, 6560, 6632, 6332, 6378, 6255, 6278, 6523, 6661, 6602, 6560, 6405, 5801, 5398, 4925, 5516, 4594, 2246, 686, 6311, 9656, 4289, 3690,
9478, 8573, 9283, 9634, 10694, 11904, 11977, 11364, 10367, 9252, 8647, 8451, 8415, 8196, 7642, 8023, 8260, 7710, 7006, 7041, 7272, 6523, 5881, 6017, 6425, 5852, 4504, 5204, 9147, 11937, 7797, 6179,};
|
504c9b44dacc9774217e1b12efcd4a0b94a6463b
|
f9e7d65cb784c01a0200145ba8d289afe41d4a56
|
/board/cheza/usb_pd_policy.c
|
694899ab79ae72f11a0e82f53047ebae3aaeb268
|
[
"BSD-3-Clause"
] |
permissive
|
FrameworkComputer/EmbeddedController
|
ad7086769e87d0a4179eae96a7c9ff5e383ff54e
|
f6d6b927eed71550d3475411cfc3e59abe5cef2a
|
refs/heads/hx20-hx30
| 2023-08-08T20:45:10.621169
| 2023-05-26T07:03:59
| 2023-05-26T07:03:59
| 447,021,040
| 846
| 48
|
BSD-3-Clause
| 2023-05-26T07:04:59
| 2022-01-12T00:11:14
|
C
|
UTF-8
|
C
| false
| false
| 5,556
|
c
|
usb_pd_policy.c
|
/* Copyright 2018 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "charge_manager.h"
#include "console.h"
#include "gpio.h"
#include "pi3usb9281.h"
#include "system.h"
#include "usb_mux.h"
#include "usbc_ppc.h"
#include "util.h"
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
int pd_check_vconn_swap(int port)
{
/* TODO(waihong): Check any case we do not allow. */
return 1;
}
__override void pd_execute_data_swap(int port,
enum pd_data_role data_role)
{
int enable = (data_role == PD_ROLE_UFP);
int type;
/*
* Exclude the PD charger, in which the "USB Communications Capable"
* bit is unset in the Fixed Supply PDO.
*/
if (pd_capable(port))
enable = enable && pd_get_partner_usb_comm_capable(port);
/*
* The hub behind the BC1.2 chip may advertise a BC1.2 type. So
* disconnect the switch when getting the charger type to ensure
* the detected type is from external.
*/
usb_charger_set_switches(port, USB_SWITCH_DISCONNECT);
type = pi3usb9281_get_device_type(port);
usb_charger_set_switches(port, USB_SWITCH_RESTORE);
/* Exclude the BC1.2 charger, which is not detected as CDP or SDP. */
enable = enable && (type & (PI3USB9281_TYPE_CDP | PI3USB9281_TYPE_SDP));
/* Only mux one port to AP. If already muxed, return. */
if (enable && (!gpio_get_level(GPIO_USB_C0_HS_MUX_SEL) ||
gpio_get_level(GPIO_USB_C1_HS_MUX_SEL)))
return;
/* Port-0 and port-1 have different polarities. */
if (port == 0)
gpio_set_level(GPIO_USB_C0_HS_MUX_SEL, enable ? 0 : 1);
else if (port == 1)
gpio_set_level(GPIO_USB_C1_HS_MUX_SEL, enable ? 1 : 0);
}
static uint8_t vbus_en[CONFIG_USB_PD_PORT_MAX_COUNT];
static uint8_t vbus_rp[CONFIG_USB_PD_PORT_MAX_COUNT] = {TYPEC_RP_1A5,
TYPEC_RP_1A5};
static void board_vbus_update_source_current(int port)
{
if (port == 0) {
/*
* Port 0 is controlled by a USB-C PPC SN5S330.
*/
ppc_set_vbus_source_current_limit(port, vbus_rp[port]);
ppc_vbus_source_enable(port, vbus_en[port]);
} else if (port == 1) {
/*
* Port 1 is controlled by a USB-C current-limited power
* switch, NX5P3290. Change the GPIO driving the load switch.
*
* 1.5 vs 3.0 A limit is controlled by a dedicated gpio.
* If the GPIO is asserted, it shorts a n-MOSFET to put a
* 16.5k resistance (2x 33k in parallel) on the NX5P3290 load
* switch ILIM pin, setting a minimum OCP current of 3100 mA.
* If the GPIO is deasserted, the n-MOSFET is open that makes
* a single 33k resistor on ILIM, setting a minimum OCP
* current of 1505 mA.
*/
gpio_set_level(GPIO_EN_USB_C1_3A,
vbus_rp[port] == TYPEC_RP_3A0 ? 1 : 0);
gpio_set_level(GPIO_EN_USB_C1_5V_OUT, vbus_en[port]);
}
}
void pd_power_supply_reset(int port)
{
int prev_en;
prev_en = vbus_en[port];
/* Disable VBUS */
vbus_en[port] = 0;
board_vbus_update_source_current(port);
/* Enable discharge if we were previously sourcing 5V */
if (prev_en)
pd_set_vbus_discharge(port, 1);
#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
/* Give back the current quota we are no longer using */
charge_manager_source_port(port, 0);
#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */
/* notify host of power info change */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
int pd_set_power_supply_ready(int port)
{
/* Disable charging */
board_vbus_sink_enable(port, 0);
pd_set_vbus_discharge(port, 0);
/* Provide VBUS */
vbus_en[port] = 1;
board_vbus_update_source_current(port);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);
/* notify host of power info change */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
return EC_SUCCESS; /* we are ready */
}
int board_vbus_source_enabled(int port)
{
return vbus_en[port];
}
__override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp)
{
vbus_rp[port] = rp;
board_vbus_update_source_current(port);
}
int pd_snk_is_vbus_provided(int port)
{
return !gpio_get_level(port ? GPIO_USB_C1_VBUS_DET_L :
GPIO_USB_C0_VBUS_DET_L);
}
/* ----------------- Vendor Defined Messages ------------------ */
/**
* Is the port fine to be muxed its DisplayPort lines?
*
* Only one port can be muxed to DisplayPort at a time.
*
* @param port Port number of TCPC.
* @return 1 is fine; 0 is bad as other port is already muxed;
*/
static int is_dp_muxable(int port)
{
int i;
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
if (i != port) {
if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
return 0;
}
return 1;
}
extern uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
__override int svdm_dp_attention(int port, uint32_t *payload)
{
int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]);
int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]);
int mf_pref = PD_VDO_DPSTS_MF_PREF(payload[1]);
dp_status[port] = payload[1];
usb_mux_hpd_update(port, lvl, irq);
if (lvl && is_dp_muxable(port)) {
/*
* The GPIO USBC_MUX_CONF1 enables the mux of the DP redriver
* for the port 1.
*/
gpio_set_level(GPIO_USBC_MUX_CONF1, port == 1);
usb_mux_set(port, mf_pref ?
USB_PD_MUX_DOCK : USB_PD_MUX_DP_ENABLED,
USB_SWITCH_CONNECT, pd_get_polarity(port));
} else {
usb_mux_set(port, mf_pref ?
USB_PD_MUX_USB_ENABLED : USB_PD_MUX_NONE,
USB_SWITCH_CONNECT, pd_get_polarity(port));
}
/* ack */
return 1;
}
|
2ac653265fb0f84d1df1177363d56ae4ddfb7bf9
|
5eff7a36d9a9917dce9111f0c3074375fe6f7656
|
/driver/xf86-video-openchrome/src/via_vgahw.c
|
1f7b7cf583fc346768c8b65090d59e6ff10a75b8
|
[
"MIT"
] |
permissive
|
openbsd/xenocara
|
cb392d02ebba06f6ff7d826fd8a89aa3b8401779
|
a012b5de33ea0b977095d77316a521195b26cc6b
|
refs/heads/master
| 2023-08-25T12:16:58.862008
| 2023-08-12T16:16:25
| 2023-08-12T16:16:25
| 66,967,384
| 177
| 66
| null | 2023-07-22T18:12:37
| 2016-08-30T18:36:01
|
C
|
UTF-8
|
C
| false
| false
| 3,490
|
c
|
via_vgahw.c
|
/*
* Copyright 2004-2005 The Unichrome Project [unichrome.sf.net]
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* Wrappers around xf86 vgaHW functions.
* And some generic IO calls lacking in the current vgaHW implementation.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "compiler.h"
#include "xf86.h"
#include "via_driver.h" /* for HAVE_DEBUG */
void
ViaCrtcMask(vgaHWPtr hwp, CARD8 index, CARD8 value, CARD8 mask)
{
CARD8 tmp;
tmp = hwp->readCrtc(hwp, index);
tmp &= ~mask;
tmp |= (value & mask);
hwp->writeCrtc(hwp, index, tmp);
}
void
ViaSeqMask(vgaHWPtr hwp, CARD8 index, CARD8 value, CARD8 mask)
{
CARD8 tmp;
tmp = hwp->readSeq(hwp, index);
tmp &= ~mask;
tmp |= (value & mask);
hwp->writeSeq(hwp, index, tmp);
}
void
ViaGrMask(vgaHWPtr hwp, CARD8 index, CARD8 value, CARD8 mask)
{
CARD8 tmp;
tmp = hwp->readGr(hwp, index);
tmp &= ~mask;
tmp |= (value & mask);
hwp->writeGr(hwp, index, tmp);
}
#ifdef HAVE_DEBUG
void
ViaVgahwPrint(vgaHWPtr hwp)
{
int i;
if (!hwp)
return;
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "VGA Sequence registers:\n");
for (i = 0x00; i < 0x80; i++)
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"SR%02X: 0x%02X\n", i, hwp->readSeq(hwp, i));
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "VGA CRTM/C registers:\n");
for (i = 0x00; i < 0x19; i++)
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"CR%02X: 0x%02X\n", i, hwp->readCrtc(hwp, i));
for (i = 0x33; i < 0xA3; i++)
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"CR%02X: 0x%02X\n", i, hwp->readCrtc(hwp, i));
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "VGA Graphics registers:\n");
for (i = 0x00; i < 0x08; i++)
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"GR%02X: 0x%02X\n", i, hwp->readGr(hwp, i));
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "VGA Attribute registers:\n");
for (i = 0x00; i < 0x14; i++)
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"AR%02X: 0x%02X\n", i, hwp->readAttr(hwp, i));
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "VGA Miscellaneous register:\n");
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO,
"Misc: 0x%02X\n", hwp->readMiscOut(hwp));
xf86DrvMsg(hwp->pScrn->scrnIndex, X_INFO, "End of VGA registers.\n");
}
#endif /* HAVE_DEBUG */
|
d41cb64ca2506b9749f640734a353fe1c0130b0c
|
7be8e3636bf08ebdc6662879dc5afec548705537
|
/ios/Pods/Headers/Private/OpenSSL-Universal/openssl/crypto.h
|
b84d4f8a1e35159d9ac692df5cb969c66dc05b55
|
[
"MIT"
] |
permissive
|
rdhox/react-native-smooth-picker
|
3c7384f1fed0e37f076361cce96071d01b70e209
|
ae9316c49512f7ed9824c5a3ad50cdf5e80fffa9
|
refs/heads/master
| 2023-01-08T16:59:40.709147
| 2021-07-03T14:13:21
| 2021-07-03T14:13:21
| 160,224,312
| 230
| 31
|
MIT
| 2023-01-06T01:46:04
| 2018-12-03T16:54:10
|
TypeScript
|
UTF-8
|
C
| false
| false
| 58
|
h
|
crypto.h
|
../../../../OpenSSL-Universal/ios/include/openssl/crypto.h
|
f2b9da2926f2cc8563f1f263ea9d31bebd46be30
|
ecafcf4501aa0af63925fdae669ab09fa3949077
|
/source/websocket_decoder.c
|
bcaa3c6912c40ac76ecbe8cf92e281c944c259c4
|
[
"Apache-2.0"
] |
permissive
|
awslabs/aws-c-http
|
082753f9556bbd075da7c11cf39e4790f679a110
|
a36253d55279bb910a2fe1566061daa556dcd5ad
|
refs/heads/main
| 2023-09-04T11:20:27.332890
| 2023-09-01T20:29:34
| 2023-09-01T20:29:34
| 142,940,518
| 119
| 41
|
Apache-2.0
| 2023-09-01T20:29:35
| 2018-07-31T00:07:24
|
C
|
UTF-8
|
C
| false
| false
| 15,281
|
c
|
websocket_decoder.c
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/http/private/websocket_decoder.h>
#include <aws/common/encoding.h>
#include <inttypes.h>
typedef int(state_fn)(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data);
/* STATE_INIT: Resets things, consumes no data */
static int s_state_init(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
(void)data;
AWS_ZERO_STRUCT(decoder->current_frame);
decoder->state = AWS_WEBSOCKET_DECODER_STATE_OPCODE_BYTE;
return AWS_OP_SUCCESS;
}
/* STATE_OPCODE_BYTE: Decode first byte of frame, which has all kinds of goodies in it. */
static int s_state_opcode_byte(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
if (data->len == 0) {
return AWS_OP_SUCCESS;
}
uint8_t byte = data->ptr[0];
aws_byte_cursor_advance(data, 1);
/* first 4 bits are all bools */
decoder->current_frame.fin = byte & 0x80;
decoder->current_frame.rsv[0] = byte & 0x40;
decoder->current_frame.rsv[1] = byte & 0x20;
decoder->current_frame.rsv[2] = byte & 0x10;
/* next 4 bits are opcode */
decoder->current_frame.opcode = byte & 0x0F;
/* RFC-6455 Section 5.2 - Opcode
* If an unknown opcode is received, the receiving endpoint MUST _Fail the WebSocket Connection_. */
switch (decoder->current_frame.opcode) {
case AWS_WEBSOCKET_OPCODE_CONTINUATION:
case AWS_WEBSOCKET_OPCODE_TEXT:
case AWS_WEBSOCKET_OPCODE_BINARY:
case AWS_WEBSOCKET_OPCODE_CLOSE:
case AWS_WEBSOCKET_OPCODE_PING:
case AWS_WEBSOCKET_OPCODE_PONG:
break;
default:
AWS_LOGF_ERROR(
AWS_LS_HTTP_WEBSOCKET,
"id=%p: Received frame with unknown opcode 0x%" PRIx8,
(void *)decoder->user_data,
decoder->current_frame.opcode);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
/* RFC-6455 Section 5.2 Fragmentation
*
* Data frames with the FIN bit clear are considered fragmented and must be followed by
* 1+ CONTINUATION frames, where only the final CONTINUATION frame's FIN bit is set.
*
* Control frames may be injected in the middle of a fragmented message,
* but control frames may not be fragmented themselves.
*/
if (aws_websocket_is_data_frame(decoder->current_frame.opcode)) {
bool is_continuation_frame = AWS_WEBSOCKET_OPCODE_CONTINUATION == decoder->current_frame.opcode;
if (decoder->expecting_continuation_data_frame != is_continuation_frame) {
AWS_LOGF_ERROR(
AWS_LS_HTTP_WEBSOCKET,
"id=%p: Fragmentation error. Received start of new message before end of previous message",
(void *)decoder->user_data);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
decoder->expecting_continuation_data_frame = !decoder->current_frame.fin;
} else {
/* Control frames themselves MUST NOT be fragmented. */
if (!decoder->current_frame.fin) {
AWS_LOGF_ERROR(
AWS_LS_HTTP_WEBSOCKET,
"id=%p: Received fragmented control frame. This is illegal",
(void *)decoder->user_data);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
}
if (decoder->current_frame.opcode == AWS_WEBSOCKET_OPCODE_TEXT) {
decoder->processing_text_message = true;
}
decoder->state = AWS_WEBSOCKET_DECODER_STATE_LENGTH_BYTE;
return AWS_OP_SUCCESS;
}
/* STATE_LENGTH_BYTE: Decode byte containing length, determine if we need to decode extended length. */
static int s_state_length_byte(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
if (data->len == 0) {
return AWS_OP_SUCCESS;
}
uint8_t byte = data->ptr[0];
aws_byte_cursor_advance(data, 1);
/* first bit is a bool */
decoder->current_frame.masked = byte & 0x80;
/* remaining 7 bits are payload length */
decoder->current_frame.payload_length = byte & 0x7F;
if (decoder->current_frame.payload_length >= AWS_WEBSOCKET_7BIT_VALUE_FOR_2BYTE_EXTENDED_LENGTH) {
/* If 7bit payload length has a high value, then the next few bytes contain the real payload length */
decoder->state_bytes_processed = 0;
decoder->state = AWS_WEBSOCKET_DECODER_STATE_EXTENDED_LENGTH;
} else {
/* If 7bit payload length has low value, that's the actual payload size, jump past EXTENDED_LENGTH state */
decoder->state = AWS_WEBSOCKET_DECODER_STATE_MASKING_KEY_CHECK;
}
return AWS_OP_SUCCESS;
}
/* STATE_EXTENDED_LENGTH: Decode extended length (state skipped if no extended length). */
static int s_state_extended_length(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
if (data->len == 0) {
return AWS_OP_SUCCESS;
}
/* The 7bit payload value loaded during the previous state indicated that
* actual payload length is encoded across the next 2 or 8 bytes. */
uint8_t total_bytes_extended_length;
uint64_t min_acceptable_value;
uint64_t max_acceptable_value;
if (decoder->current_frame.payload_length == AWS_WEBSOCKET_7BIT_VALUE_FOR_2BYTE_EXTENDED_LENGTH) {
total_bytes_extended_length = 2;
min_acceptable_value = AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MIN_VALUE;
max_acceptable_value = AWS_WEBSOCKET_2BYTE_EXTENDED_LENGTH_MAX_VALUE;
} else {
AWS_ASSERT(decoder->current_frame.payload_length == AWS_WEBSOCKET_7BIT_VALUE_FOR_8BYTE_EXTENDED_LENGTH);
total_bytes_extended_length = 8;
min_acceptable_value = AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MIN_VALUE;
max_acceptable_value = AWS_WEBSOCKET_8BYTE_EXTENDED_LENGTH_MAX_VALUE;
}
/* Copy bytes of extended-length to state_cache, we'll process them later.*/
AWS_ASSERT(total_bytes_extended_length > decoder->state_bytes_processed);
size_t remaining_bytes = (size_t)(total_bytes_extended_length - decoder->state_bytes_processed);
size_t bytes_to_consume = remaining_bytes <= data->len ? remaining_bytes : data->len;
AWS_ASSERT(bytes_to_consume + decoder->state_bytes_processed <= sizeof(decoder->state_cache));
memcpy(decoder->state_cache + decoder->state_bytes_processed, data->ptr, bytes_to_consume);
aws_byte_cursor_advance(data, bytes_to_consume);
decoder->state_bytes_processed += bytes_to_consume;
/* Return, still waiting on more bytes */
if (decoder->state_bytes_processed < total_bytes_extended_length) {
return AWS_OP_SUCCESS;
}
/* All bytes have been copied into state_cache, now read them together as one number,
* transforming from network byte order (big endian) to native endianness. */
struct aws_byte_cursor cache_cursor = aws_byte_cursor_from_array(decoder->state_cache, total_bytes_extended_length);
if (total_bytes_extended_length == 2) {
uint16_t val;
aws_byte_cursor_read_be16(&cache_cursor, &val);
decoder->current_frame.payload_length = val;
} else {
aws_byte_cursor_read_be64(&cache_cursor, &decoder->current_frame.payload_length);
}
if (decoder->current_frame.payload_length < min_acceptable_value ||
decoder->current_frame.payload_length > max_acceptable_value) {
AWS_LOGF_ERROR(AWS_LS_HTTP_WEBSOCKET, "id=%p: Failed to decode payload length", (void *)decoder->user_data);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
decoder->state = AWS_WEBSOCKET_DECODER_STATE_MASKING_KEY_CHECK;
return AWS_OP_SUCCESS;
}
/* MASKING_KEY_CHECK: Determine if we need to decode masking-key. Consumes no data. */
static int s_state_masking_key_check(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
(void)data;
/* If mask bit was set, move to next state to process 4 bytes of masking key.
* Otherwise skip next step, there is no masking key. */
if (decoder->current_frame.masked) {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_MASKING_KEY;
decoder->state_bytes_processed = 0;
} else {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_PAYLOAD_CHECK;
}
return AWS_OP_SUCCESS;
}
/* MASKING_KEY: Decode masking-key (state skipped if no masking key). */
static int s_state_masking_key(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
if (data->len == 0) {
return AWS_OP_SUCCESS;
}
AWS_ASSERT(4 > decoder->state_bytes_processed);
size_t bytes_remaining = 4 - (size_t)decoder->state_bytes_processed;
size_t bytes_to_consume = bytes_remaining < data->len ? bytes_remaining : data->len;
memcpy(decoder->current_frame.masking_key + decoder->state_bytes_processed, data->ptr, bytes_to_consume);
aws_byte_cursor_advance(data, bytes_to_consume);
decoder->state_bytes_processed += bytes_to_consume;
/* If all bytes consumed, proceed to next state */
if (decoder->state_bytes_processed == 4) {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_PAYLOAD_CHECK;
}
return AWS_OP_SUCCESS;
}
/* PAYLOAD_CHECK: Determine if we need to decode a payload. Consumes no data. */
static int s_state_payload_check(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
(void)data;
/* Invoke on_frame() callback to inform user of non-payload data. */
int err = decoder->on_frame(&decoder->current_frame, decoder->user_data);
if (err) {
return AWS_OP_ERR;
}
/* Choose next state: either we have payload to process or we don't. */
if (decoder->current_frame.payload_length > 0) {
decoder->state_bytes_processed = 0;
decoder->state = AWS_WEBSOCKET_DECODER_STATE_PAYLOAD;
} else {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_FRAME_END;
}
return AWS_OP_SUCCESS;
}
/* PAYLOAD: Decode payload until we're done (state skipped if no payload). */
static int s_state_payload(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
if (data->len == 0) {
return AWS_OP_SUCCESS;
}
AWS_ASSERT(decoder->current_frame.payload_length > decoder->state_bytes_processed);
uint64_t bytes_remaining = decoder->current_frame.payload_length - decoder->state_bytes_processed;
size_t bytes_to_consume = bytes_remaining < data->len ? (size_t)bytes_remaining : data->len;
struct aws_byte_cursor payload = aws_byte_cursor_advance(data, bytes_to_consume);
/* Unmask data, if necessary.
* RFC-6455 Section 5.3 Client-to-Server Masking
* Each byte of payload is XOR against a byte of the masking-key */
if (decoder->current_frame.masked) {
uint64_t mask_index = decoder->state_bytes_processed;
/* Optimization idea: don't do this 1 byte at a time */
uint8_t *current_byte = payload.ptr;
uint8_t *end_byte = payload.ptr + payload.len;
while (current_byte != end_byte) {
*current_byte++ ^= decoder->current_frame.masking_key[mask_index++ % 4];
}
}
/* TODO: validate payload of CLOSE frame */
/* Validate the UTF-8 for TEXT messages (a TEXT frame and any subsequent CONTINUATION frames) */
if (decoder->processing_text_message && aws_websocket_is_data_frame(decoder->current_frame.opcode)) {
if (aws_utf8_decoder_update(decoder->text_message_validator, payload)) {
AWS_LOGF_ERROR(AWS_LS_HTTP_WEBSOCKET, "id=%p: Received invalid UTF-8", (void *)decoder->user_data);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
}
/* Invoke on_payload() callback to inform user of payload data */
int err = decoder->on_payload(payload, decoder->user_data);
if (err) {
return AWS_OP_ERR;
}
decoder->state_bytes_processed += payload.len;
AWS_ASSERT(decoder->state_bytes_processed <= decoder->current_frame.payload_length);
/* If all data consumed, proceed to next state. */
if (decoder->state_bytes_processed == decoder->current_frame.payload_length) {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_FRAME_END;
}
return AWS_OP_SUCCESS;
}
/* FRAME_END: Perform checks once we reach the end of the frame. */
static int s_state_frame_end(struct aws_websocket_decoder *decoder, struct aws_byte_cursor *data) {
(void)data;
/* If we're done processing a text message (a TEXT frame and any subsequent CONTINUATION frames),
* complete the UTF-8 validation */
if (decoder->processing_text_message && aws_websocket_is_data_frame(decoder->current_frame.opcode) &&
decoder->current_frame.fin) {
if (aws_utf8_decoder_finalize(decoder->text_message_validator)) {
AWS_LOGF_ERROR(
AWS_LS_HTTP_WEBSOCKET,
"id=%p: Received invalid UTF-8 (incomplete encoding)",
(void *)decoder->user_data);
return aws_raise_error(AWS_ERROR_HTTP_WEBSOCKET_PROTOCOL_ERROR);
}
decoder->processing_text_message = false;
}
/* Done! */
decoder->state = AWS_WEBSOCKET_DECODER_STATE_DONE;
return AWS_OP_SUCCESS;
}
static state_fn *s_state_functions[AWS_WEBSOCKET_DECODER_STATE_DONE] = {
s_state_init,
s_state_opcode_byte,
s_state_length_byte,
s_state_extended_length,
s_state_masking_key_check,
s_state_masking_key,
s_state_payload_check,
s_state_payload,
s_state_frame_end,
};
int aws_websocket_decoder_process(
struct aws_websocket_decoder *decoder,
struct aws_byte_cursor *data,
bool *frame_complete) {
/* Run state machine until frame is completely decoded, or the state stops changing.
* Note that we don't stop looping when data->len reaches zero, because some states consume no data. */
while (decoder->state != AWS_WEBSOCKET_DECODER_STATE_DONE) {
enum aws_websocket_decoder_state prev_state = decoder->state;
int err = s_state_functions[decoder->state](decoder, data);
if (err) {
return AWS_OP_ERR;
}
if (decoder->state == prev_state) {
AWS_ASSERT(data->len == 0); /* If no more work to do, all possible data should have been consumed */
break;
}
}
if (decoder->state == AWS_WEBSOCKET_DECODER_STATE_DONE) {
decoder->state = AWS_WEBSOCKET_DECODER_STATE_INIT;
*frame_complete = true;
return AWS_OP_SUCCESS;
}
*frame_complete = false;
return AWS_OP_SUCCESS;
}
void aws_websocket_decoder_init(
struct aws_websocket_decoder *decoder,
struct aws_allocator *alloc,
aws_websocket_decoder_frame_fn *on_frame,
aws_websocket_decoder_payload_fn *on_payload,
void *user_data) {
AWS_ZERO_STRUCT(*decoder);
decoder->user_data = user_data;
decoder->on_frame = on_frame;
decoder->on_payload = on_payload;
decoder->text_message_validator = aws_utf8_decoder_new(alloc, NULL /*options*/);
}
void aws_websocket_decoder_clean_up(struct aws_websocket_decoder *decoder) {
aws_utf8_decoder_destroy(decoder->text_message_validator);
AWS_ZERO_STRUCT(*decoder);
}
|
1d98a5bf9815cf504633b152795e8ea2d9e34b18
|
97897b9c2031e06969b796bdda7dfda021bfbf2b
|
/tests/monoclock/main.c
|
97794d05476b2b7c6aeb0f10d266cf2e98fe8ab8
|
[
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
Tarsnap/libcperciva
|
ebe2bc76cc78bff5d2b558ca5de2c5c9c5be749f
|
11ce1ee363efd06c9b19cfb954dcf4a3be19cc37
|
refs/heads/master
| 2023-08-31T22:00:25.807052
| 2023-08-26T22:47:22
| 2023-08-26T22:47:22
| 36,064,362
| 140
| 21
|
NOASSERTION
| 2023-09-13T18:25:19
| 2015-05-22T09:36:27
|
C
|
UTF-8
|
C
| false
| false
| 1,015
|
c
|
main.c
|
#include <sys/time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "warnp.h"
#include "monoclock.h"
int
main(int argc, char * argv[])
{
struct timeval tv_wall, tv_cpu;
double timer_resolution;
WARNP_INIT;
(void)argc; /* UNUSED */
(void)argv; /* UNUSED */
/* Get time and process CPU time. */
if (monoclock_get(&tv_wall)) {
warnp("monoclock_get()");
goto err0;
}
if (monoclock_get_cputime(&tv_cpu)) {
warnp("monoclock_get_cputime()");
goto err0;
}
/* Get timer resolution. */
if (monoclock_getres(&timer_resolution)) {
warnp("monoclock_getres()");
goto err0;
}
/* Display times. */
printf("monoclock_get():\t\t%ju seconds,\t%06ji microseconds\n",
(uintmax_t)tv_wall.tv_sec, (intmax_t)tv_wall.tv_usec);
printf("monoclock_get_cputime():\t%ju seconds,\t%06ji microseconds\n",
(uintmax_t)tv_cpu.tv_sec, (intmax_t)tv_cpu.tv_usec);
printf("monoclock_getres():\t\t%g\n", timer_resolution);
/* Success! */
exit(0);
err0:
/* Failure! */
exit(1);
}
|
fdcbdd53a874b51cb7848b0336682138752491b9
|
e73547787354afd9b717ea57fe8dd0695d161821
|
/src/world/area_nok/nok_02/nok_02_7_demo.c
|
9392639b01a775218ad1be92910a2c46cd2c1402
|
[] |
no_license
|
pmret/papermario
|
8b514b19653cef8d6145e47499b3636b8c474a37
|
9774b26d93f1045dd2a67e502b6efc9599fb6c31
|
refs/heads/main
| 2023-08-31T07:09:48.951514
| 2023-08-21T18:07:08
| 2023-08-21T18:07:08
| 287,151,133
| 904
| 139
| null | 2023-09-14T02:44:23
| 2020-08-13T01:22:57
|
C
|
UTF-8
|
C
| false
| false
| 4,878
|
c
|
nok_02_7_demo.c
|
#include "nok_02.h"
#include "world/partners.h"
EvtScript N(EVS_ProvideDemoInputs) = {
EVT_CALL(DemoJoystickXY, 6, 4)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 29, 20)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 64, 34)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 68, 41)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 67, 44)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 65, 52)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 63, 60)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 62, 65)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 62, 66)
EVT_WAIT(3)
EVT_CALL(DemoJoystickXY, 62, 67)
EVT_WAIT(2)
EVT_CALL(DemoJoystickXY, 61, 69)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 24, 79)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 1, 83)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 2, 84)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 2, 82)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 3, 43)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, -1, 0)
EVT_WAIT(3)
EVT_CALL(DemoSetButtons, BUTTON_A)
EVT_WAIT(8)
EVT_CALL(DemoSetButtons, 0)
EVT_WAIT(75)
EVT_CALL(DemoJoystickXY, 7, 2)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 39, 8)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 74, 10)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 74, 12)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 74, 19)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 72, 29)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 68, 42)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 65, 54)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 63, 62)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 62, 66)
EVT_WAIT(3)
EVT_CALL(DemoJoystickXY, 59, 70)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 53, 72)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 52, 73)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 43, 75)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 35, 77)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 33, 77)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 34, 77)
EVT_WAIT(3)
EVT_CALL(DemoJoystickXY, 33, 77)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 18, 78)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 11, 79)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 4, 32)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, -1, 1)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, -1, 0)
EVT_WAIT(1)
EVT_CALL(DemoSetButtons, BUTTON_A)
EVT_WAIT(6)
EVT_CALL(DemoSetButtons, 0)
EVT_WAIT(53)
EVT_CALL(DemoJoystickXY, 2, 0)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 11, 1)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 28, 5)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 57, 15)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 68, 26)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 69, 33)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 65, 51)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 63, 61)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 62, 66)
EVT_WAIT(4)
EVT_CALL(DemoJoystickXY, 61, 66)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 52, 68)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 38, 72)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 30, 74)
EVT_WAIT(2)
EVT_CALL(DemoJoystickXY, 27, 67)
EVT_WAIT(1)
EVT_CALL(DemoJoystickXY, 0, 0)
EVT_WAIT(10)
EVT_IF_EQ(GF_DemoSceneDone, TRUE)
EVT_RETURN
EVT_END_IF
EVT_SET(GF_DemoSceneDone, TRUE)
EVT_CALL(GotoMapSpecial, EVT_PTR("nok_02"), nok_02_ENTRY_2, TRANSITION_END_DEMO_SCENE_BLACK)
EVT_WAIT(110)
EVT_RETURN
EVT_END
};
EvtScript N(EVS_MonitorDemoState) = {
EVT_WAIT(10)
EVT_LOOP(0)
EVT_CALL(GetDemoState, LVar0)
EVT_IF_EQ(LVar0, DEMO_STATE_CHANGE_MAP)
EVT_BREAK_LOOP
EVT_END_IF
EVT_WAIT(1)
EVT_END_LOOP
EVT_IF_EQ(GF_DemoSceneDone, TRUE)
EVT_RETURN
EVT_END_IF
EVT_SET(GF_DemoSceneDone, TRUE)
EVT_CALL(GotoMapSpecial, EVT_PTR("nok_02"), nok_02_ENTRY_2, TRANSITION_END_DEMO_SCENE_WHITE)
EVT_WAIT(110)
EVT_RETURN
EVT_END
};
s32 N(DemoInitState) = 0;
API_CALLABLE(N(SetupDemoScene)) {
PlayerStatus* playerStatus = &gPlayerStatus;
switch (N(DemoInitState)) {
case 0:
N(DemoInitState) = 1;
break;
case 1:
case 2:
N(DemoInitState)++;
break;
case 3:
partner_clear_player_tracking(wPartnerNpc);
partner_set_goal_pos(playerStatus->pos.x, playerStatus->pos.z);
func_800EF3D4(0);
set_npc_yaw(wPartnerNpc, 90.0f);
playerStatus->targetYaw = 90.0f;
playerStatus->curYaw = 90.0f;
playerStatus->spriteFacingAngle = 0.0f;
return ApiStatus_DONE2;
}
return ApiStatus_BLOCK;
}
EvtScript N(EVS_SetupDemo) = {
EVT_CALL(N(SetupDemoScene))
EVT_SET(GF_DemoSceneDone, FALSE)
EVT_EXEC(N(EVS_MonitorDemoState))
EVT_EXEC(N(EVS_ProvideDemoInputs))
EVT_RETURN
EVT_END
};
|
8778420b732cbf2c82b393cd9a18ae03ccfb6f7e
|
3f55217e912141e04815bc8bcb6fbd5638d0896e
|
/src/common/modobject.c
|
e5e9251e77b1ca586bc17305ea8782666b3936d6
|
[
"BSD-2-Clause"
] |
permissive
|
NREL/Radiance
|
bfbb93c99d86368ad0f27052a2a5504aeced47f8
|
2fcca99ace2f2435f32a09525ad31f2b3be3c1bc
|
refs/heads/master
| 2021-12-26T12:42:04.586614
| 2021-12-18T00:43:56
| 2021-12-18T00:43:56
| 8,210,805
| 164
| 68
|
NOASSERTION
| 2019-06-06T19:57:11
| 2013-02-15T00:47:56
|
C
|
UTF-8
|
C
| false
| false
| 5,555
|
c
|
modobject.c
|
#ifndef lint
static const char RCSid[] = "$Id: modobject.c,v 2.20 2021/02/01 17:36:45 greg Exp $";
#endif
/*
* Routines for tracking object modifiers
*
* External symbols declared in object.h
*/
#include "copyright.h"
#include "standard.h"
#include "object.h"
#include "otypes.h"
static struct ohtab {
int hsiz; /* current table size */
OBJECT *htab; /* table, if allocated */
} modtab = {100, NULL}, objtab = {1000, NULL}; /* modifiers and objects */
static int otndx(char *, struct ohtab *);
OBJECT
objndx( /* get object number from pointer */
OBJREC *op
)
{
int i;
long j;
for (i = (nobjects-1)>>OBJBLKSHFT; i >= 0; i--) {
j = op - objblock[i];
if ((j >= 0) & (j < OBJBLKSIZ))
return(((OBJECT)i<<OBJBLKSHFT) + (OBJECT)j);
}
return(OVOID);
}
OBJECT
lastmod( /* find modifier definition before obj */
OBJECT obj,
char *mname
)
{
OBJREC *op;
int i;
i = modifier(mname); /* try hash table first */
if ((obj == OVOID) | (i < obj))
return(i);
for (i = obj; i-- > 0; ) { /* need to search */
op = objptr(i);
if (ismodifier(op->otype) && op->oname[0] == mname[0] &&
!strcmp(op->oname, mname))
return(i);
}
return(OVOID);
}
OBJECT
modifier( /* get a modifier number from its name */
char *mname
)
{
int ndx;
ndx = otndx(mname, &modtab);
return(modtab.htab[ndx]);
}
#ifdef GETOBJ
OBJECT
object( /* get an object number from its name */
char *oname
)
{
int ndx;
ndx = otndx(oname, &objtab);
return(objtab.htab[ndx]);
}
#endif
int
eqreal( /* are two real values close enough to equal? */
double d1,
double d2
)
{
if (d2 != 0.0)
d1 = d1/d2 - 1.0;
return((-FTINY <= d1) & (d1 <= FTINY));
}
int
eqobjects( /* check if two objects are equal */
OBJECT obj1,
OBJECT obj2
)
{
OBJREC *op1, *op2;
int i, n;
while (obj1 != obj2) {
if (obj1 == OVOID)
return(0);
if (obj2 == OVOID)
return(0);
op1 = objptr(obj1);
op2 = objptr(obj2);
if (op1->otype != op2->otype)
return(0);
if (op1->oargs.nsargs != op2->oargs.nsargs)
return(0);
if (op1->oargs.nfargs != op2->oargs.nfargs)
return(0);
#ifdef IARGS
if (op1->oargs.niargs != op2->oargs.niargs)
return(0);
for (i = op1->oargs.niargs; i-- > 0; )
if (op1->oargs.iarg[i] != op2->oargs.iarg[i])
return(0);
#endif
for (i = op1->oargs.nfargs; i-- > 0; )
if (!eqreal(op1->oargs.farg[i], op2->oargs.farg[i]))
return(0);
n = 0;
switch (op1->otype) { /* special cases (KEEP CONSISTENT!) */
case MOD_ALIAS:
case MAT_ILLUM:
case MAT_MIRROR:
n = (op1->oargs.nsargs > 0);
break;
case MIX_FUNC:
case MIX_DATA:
case MIX_TEXT:
case MIX_PICT:
n = 2*(op1->oargs.nsargs >= 2);
break;
case MAT_CLIP:
n = op1->oargs.nsargs;
break;
}
/* check other string arguments */
for (i = op1->oargs.nsargs; i-- > n; )
if (strcmp(op1->oargs.sarg[i], op2->oargs.sarg[i]))
return(0);
while (n-- > 0) /* check modifier references */
if (!eqobjects( lastmod(obj1, op1->oargs.sarg[n]),
lastmod(obj2, op2->oargs.sarg[n]) ))
return(0);
obj1 = op1->omod;
obj2 = op2->omod;
}
return(1);
}
void
insertobject( /* insert new object into our list */
OBJECT obj
)
{
int i;
if (ismodifier(objptr(obj)->otype)) {
i = otndx(objptr(obj)->oname, &modtab);
if (eqobjects(obj, modtab.htab[i]))
return; /* don't index if same as earlier def. */
modtab.htab[i] = obj;
}
#ifdef GETOBJ
else {
i = otndx(objptr(obj)->oname, &objtab);
objtab.htab[i] = obj;
}
#endif
for (i = 0; addobjnotify[i] != NULL; i++)
(*addobjnotify[i])(obj);
}
void
truncobjndx(void) /* remove bogus table entries past end */
{
int ndx;
if (nobjects <= 0) {
if (modtab.htab != NULL) {
free((void *)modtab.htab);
modtab.htab = NULL;
modtab.hsiz = 100;
}
if (objtab.htab != NULL) {
free((void *)objtab.htab);
objtab.htab = NULL;
objtab.hsiz = 100;
}
return;
}
for (ndx = modtab.hsiz*(modtab.htab != NULL); ndx--; )
if (modtab.htab[ndx] >= nobjects)
modtab.htab[ndx] = OVOID;
for (ndx = objtab.hsiz*(objtab.htab != NULL); ndx--; )
if (objtab.htab[ndx] >= nobjects)
objtab.htab[ndx] = OVOID;
}
static int
nexthsiz( /* return next hash table size */
int oldsiz
)
{
static int hsiztab[] = {
251, 509, 1021, 2039, 4093, 8191, 16381,
32749, 65521, 131071, 262139, 0
};
int *hsp;
for (hsp = hsiztab; *hsp; hsp++)
if (*hsp > oldsiz)
return(*hsp);
return(oldsiz*2 + 1); /* not always prime */
}
static int
otndx( /* get object table index for name */
char *name,
struct ohtab *tab
)
{
char *onm;
OBJECT *oldhtab;
int hval, i;
int ndx;
if (tab->htab == NULL) { /* new table */
tab->hsiz = nexthsiz(tab->hsiz);
tab->htab = (OBJECT *)malloc(tab->hsiz*sizeof(OBJECT));
if (tab->htab == NULL)
error(SYSTEM, "out of memory in otndx");
ndx = tab->hsiz;
while (ndx--) /* empty it */
tab->htab[ndx] = OVOID;
}
/* look up object */
hval = shash(name);
tryagain:
for (i = 0; i < tab->hsiz; i++) {
ndx = (hval + (unsigned long)i*i) % tab->hsiz;
if (tab->htab[ndx] == OVOID)
return(ndx);
onm = objptr(tab->htab[ndx])->oname;
if (onm != NULL && !strcmp(onm, name))
return(ndx);
}
/* table is full, reallocate */
oldhtab = tab->htab;
ndx = tab->hsiz;
tab->htab = NULL;
while (ndx--)
if (oldhtab[ndx] != OVOID) {
onm = objptr(oldhtab[ndx])->oname;
if (onm == NULL)
continue;
i = otndx(onm, tab);
tab->htab[i] = oldhtab[ndx];
}
free((void *)oldhtab);
goto tryagain; /* should happen only once! */
}
|
86319879ae8f7df3b9c873f02f4c96b498abb503
|
c68f791005359cfec81af712aae0276c70b512b0
|
/0-unclassified/a.c
|
e4276a0f559df1b48345fc2af3c923105fb63ff5
|
[] |
no_license
|
luqmanarifin/cp
|
83b3435ba2fdd7e4a9db33ab47c409adb088eb90
|
08c2d6b6dd8c4eb80278ec34dc64fd4db5878f9f
|
refs/heads/master
| 2022-10-16T14:30:09.683632
| 2022-10-08T20:35:42
| 2022-10-08T20:35:42
| 51,346,488
| 106
| 46
| null | 2017-04-16T11:06:18
| 2016-02-09T04:26:58
|
C++
|
UTF-8
|
C
| false
| false
| 106
|
c
|
a.c
|
1,3,7,11,21,21,43,43,61,63,111,77,157,129,147,171,273,183,343,231,301,333,507,301,521,471,547,473,813,441,
|
0ca0dcf2f4faaf3e1ce92106d655a9f2e21e1f19
|
d84c7df450292867f8c7bb58d1507735479d746d
|
/include/ceed-impl.h
|
1b7773088d18da35b23599a4080a2d26b8c3dac4
|
[
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
CEED/libCEED
|
c17e8b2f8e9ccfafc0505bb6db451e2f7cfed690
|
c6c10e0994b55ea1726a79024cd4c333c40de38a
|
refs/heads/main
| 2023-09-01T20:13:21.268643
| 2023-09-01T20:08:36
| 2023-09-01T20:08:36
| 113,349,904
| 167
| 54
|
BSD-2-Clause
| 2023-09-14T20:37:58
| 2017-12-06T17:57:40
|
C
|
UTF-8
|
C
| false
| false
| 17,254
|
h
|
ceed-impl.h
|
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
//
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of CEED: http://github.com/ceed
/// @file
/// Private header for frontend components of libCEED
#ifndef CEED_IMPL_H
#define CEED_IMPL_H
#include <ceed.h>
#include <ceed/backend.h>
#include <stdbool.h>
CEED_INTERN const char *CeedJitSourceRootDefault;
/** @defgroup CeedUser Public API for Ceed
@ingroup Ceed
*/
/** @defgroup CeedBackend Backend API for Ceed
@ingroup Ceed
*/
/** @defgroup CeedDeveloper Internal library functions for Ceed
@ingroup Ceed
*/
/** @defgroup CeedVectorUser Public API for CeedVector
@ingroup CeedVector
*/
/** @defgroup CeedVectorBackend Backend API for CeedVector
@ingroup CeedVector
*/
/** @defgroup CeedVectorDeveloper Internal library functions for CeedVector
@ingroup CeedVector
*/
/** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction
@ingroup CeedElemRestriction
*/
/** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction
@ingroup CeedElemRestriction
*/
/** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction
@ingroup CeedElemRestriction
*/
/** @defgroup CeedBasisUser Public API for CeedBasis
@ingroup CeedBasis
*/
/** @defgroup CeedBasisBackend Backend API for CeedBasis
@ingroup CeedBasis
*/
/** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis
@ingroup CeedBasis
*/
/** @defgroup CeedQFunctionUser Public API for CeedQFunction
@ingroup CeedQFunction
*/
/** @defgroup CeedQFunctionBackend Backend API for CeedQFunction
@ingroup CeedQFunction
*/
/** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction
@ingroup CeedQFunction
*/
/** @defgroup CeedOperatorUser Public API for CeedOperator
@ingroup CeedOperator
*/
/** @defgroup CeedOperatorBackend Backend API for CeedOperator
@ingroup CeedOperator
*/
/** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator
@ingroup CeedOperator
*/
// Lookup table field for backend functions
typedef struct {
const char *func_name;
size_t offset;
} FOffset;
// Lookup table field for object delegates
typedef struct {
char *obj_name;
Ceed delegate;
} ObjDelegate;
struct Ceed_private {
const char *resource;
Ceed delegate;
Ceed parent;
ObjDelegate *obj_delegates;
int obj_delegate_count;
Ceed op_fallback_ceed, op_fallback_parent;
const char *op_fallback_resource;
char **jit_source_roots;
CeedInt num_jit_source_roots;
int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list *);
int (*SetStream)(Ceed, void *);
int (*GetPreferredMemType)(CeedMemType *);
int (*Destroy)(Ceed);
int (*VectorCreate)(CeedSize, CeedVector);
int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, const CeedInt *, const bool *, const CeedInt8 *, CeedElemRestriction);
int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, const CeedInt *, const bool *, const CeedInt8 *, CeedElemRestriction);
int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
CeedBasis);
int (*BasisCreateHdiv)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
CeedBasis);
int (*BasisCreateHcurl)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
CeedBasis);
int (*TensorContractCreate)(CeedBasis, CeedTensorContract);
int (*QFunctionCreate)(CeedQFunction);
int (*QFunctionContextCreate)(CeedQFunctionContext);
int (*OperatorCreate)(CeedOperator);
int (*CompositeOperatorCreate)(CeedOperator);
int ref_count;
void *data;
bool is_debug;
bool has_valid_op_fallback_resource;
bool is_deterministic;
char err_msg[CEED_MAX_RESOURCE_LEN];
FOffset *f_offsets;
};
struct CeedVector_private {
Ceed ceed;
int (*HasValidArray)(CeedVector, bool *);
int (*HasBorrowedArrayOfType)(CeedVector, CeedMemType, bool *);
int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
int (*SetValue)(CeedVector, CeedScalar);
int (*SyncArray)(CeedVector, CeedMemType);
int (*TakeArray)(CeedVector, CeedMemType, CeedScalar **);
int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
int (*GetArrayWrite)(CeedVector, CeedMemType, CeedScalar **);
int (*RestoreArray)(CeedVector);
int (*RestoreArrayRead)(CeedVector);
int (*Norm)(CeedVector, CeedNormType, CeedScalar *);
int (*Scale)(CeedVector, CeedScalar);
int (*AXPY)(CeedVector, CeedScalar, CeedVector);
int (*AXPBY)(CeedVector, CeedScalar, CeedScalar, CeedVector);
int (*PointwiseMult)(CeedVector, CeedVector, CeedVector);
int (*Reciprocal)(CeedVector);
int (*Destroy)(CeedVector);
int ref_count;
CeedSize length;
uint64_t state;
uint64_t num_readers;
void *data;
};
struct CeedElemRestriction_private {
Ceed ceed;
CeedElemRestriction rstr_base;
int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
int (*ApplyUnsigned)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
int (*ApplyUnoriented)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **);
int (*GetOrientations)(CeedElemRestriction, CeedMemType, const bool **);
int (*GetCurlOrientations)(CeedElemRestriction, CeedMemType, const CeedInt8 **);
int (*Destroy)(CeedElemRestriction);
int ref_count;
CeedInt num_elem; /* number of elements */
CeedInt elem_size; /* number of nodes per element */
CeedInt num_comp; /* number of components */
CeedInt comp_stride; /* Component stride for L-vector ordering */
CeedSize l_size; /* size of the L-vector, can be used for checking for correct vector sizes */
CeedInt block_size; /* number of elements in a batch */
CeedInt num_block; /* number of blocks of elements */
CeedInt *strides; /* strides between [nodes, components, elements] */
CeedInt layout[3]; /* E-vector layout [nodes, components, elements] */
CeedRestrictionType
rstr_type; /* initialized in element restriction constructor for default, oriented, curl-oriented, or strided element restriction */
uint64_t num_readers; /* number of instances of offset read only access */
void *data; /* place for the backend to store any data */
};
struct CeedBasis_private {
Ceed ceed;
int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector);
int (*ApplyAtPoints)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector, CeedVector);
int (*Destroy)(CeedBasis);
int ref_count;
bool is_tensor_basis; /* flag for tensor basis */
CeedInt dim; /* topological dimension */
CeedElemTopology topo; /* element topology */
CeedInt num_comp; /* number of field components (1 for scalar fields) */
CeedInt P_1d; /* number of nodes in one dimension */
CeedInt Q_1d; /* number of quadrature points in one dimension */
CeedInt P; /* total number of nodes */
CeedInt Q; /* total number of quadrature points */
CeedFESpace fe_space; /* initialized in basis constructor with 1, 2, 3 for H^1, H(div), and H(curl) FE space */
CeedTensorContract contract; /* tensor contraction object */
CeedScalar *q_ref_1d; /* array of length Q1d holding the locations of quadrature points on the 1D reference element [-1, 1] */
CeedScalar *q_weight_1d; /* array of length Q1d holding the quadrature weights on the reference element */
CeedScalar *interp; /* row-major matrix of shape [Q, P] or [dim * Q, P] expressing the values of nodal basis functions or vector basis functions at
quadrature points */
CeedScalar *interp_1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of nodal basis functions at quadrature points */
CeedScalar *grad; /* row-major matrix of shape [dim * Q, P] matrix expressing derivatives of nodal basis functions at quadrature points */
CeedScalar *grad_1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of nodal basis functions at quadrature points */
CeedScalar *div; /* row-major matrix of shape [Q, P] expressing the divergence of basis functions at quadrature points for H(div) discretizations */
CeedScalar *curl; /* row-major matrix of shape [curl_dim * Q, P], curl_dim = 1 if dim < 3 else dim, expressing the curl of basis functions at
quadrature points for H(curl) discretizations */
CeedVector vec_chebyshev;
CeedBasis basis_chebyshev; /* basis interpolating from nodes to Chebyshev polynomial coefficients */
void *data; /* place for the backend to store any data */
};
struct CeedTensorContract_private {
Ceed ceed;
int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
const CeedScalar *restrict, CeedScalar *restrict);
int (*Destroy)(CeedTensorContract);
int ref_count;
void *data;
};
struct CeedQFunctionField_private {
const char *field_name;
CeedInt size;
CeedEvalMode eval_mode;
};
struct CeedQFunction_private {
Ceed ceed;
int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
int (*SetCUDAUserFunction)(CeedQFunction, void *);
int (*SetHIPUserFunction)(CeedQFunction, void *);
int (*Destroy)(CeedQFunction);
int ref_count;
CeedInt vec_length; /* Number of quadrature points must be padded to a multiple of vec_length */
CeedQFunctionField *input_fields;
CeedQFunctionField *output_fields;
CeedInt num_input_fields, num_output_fields;
CeedQFunctionUser function;
CeedInt user_flop_estimate;
const char *user_source;
const char *source_path;
const char *kernel_name;
const char *gallery_name;
bool is_gallery;
bool is_identity;
bool is_fortran;
bool is_immutable;
bool is_context_writable;
CeedQFunctionContext ctx; /* user context for function */
void *data; /* place for the backend to store any data */
};
struct CeedQFunctionContext_private {
Ceed ceed;
int ref_count;
int (*HasValidData)(CeedQFunctionContext, bool *);
int (*HasBorrowedDataOfType)(CeedQFunctionContext, CeedMemType, bool *);
int (*SetData)(CeedQFunctionContext, CeedMemType, CeedCopyMode, void *);
int (*TakeData)(CeedQFunctionContext, CeedMemType, void *);
int (*GetData)(CeedQFunctionContext, CeedMemType, void *);
int (*GetDataRead)(CeedQFunctionContext, CeedMemType, void *);
int (*RestoreData)(CeedQFunctionContext);
int (*RestoreDataRead)(CeedQFunctionContext);
int (*DataDestroy)(CeedQFunctionContext);
int (*Destroy)(CeedQFunctionContext);
CeedQFunctionContextDataDestroyUser data_destroy_function;
CeedMemType data_destroy_mem_type;
CeedInt num_fields;
CeedInt max_fields;
CeedContextFieldLabel *field_labels;
uint64_t state;
uint64_t num_readers;
size_t ctx_size;
void *data;
};
/// Struct to handle the context data to use the Fortran QFunction stub
/// @ingroup CeedQFunction
struct CeedFortranContext_private {
CeedQFunctionContext inner_ctx;
void (*f)(void *ctx, int *nq, const CeedScalar *u, const CeedScalar *u1, const CeedScalar *u2, const CeedScalar *u3, const CeedScalar *u4,
const CeedScalar *u5, const CeedScalar *u6, const CeedScalar *u7, const CeedScalar *u8, const CeedScalar *u9, const CeedScalar *u10,
const CeedScalar *u11, const CeedScalar *u12, const CeedScalar *u13, const CeedScalar *u14, const CeedScalar *u15, CeedScalar *v,
CeedScalar *v1, CeedScalar *v2, CeedScalar *v3, CeedScalar *v4, CeedScalar *v5, CeedScalar *v6, CeedScalar *v7, CeedScalar *v8,
CeedScalar *v9, CeedScalar *v10, CeedScalar *v11, CeedScalar *v12, CeedScalar *v13, CeedScalar *v14, CeedScalar *v15, int *err);
};
typedef struct CeedFortranContext_private *CeedFortranContext;
struct CeedContextFieldLabel_private {
const char *name;
const char *description;
CeedContextFieldType type;
size_t size;
size_t num_values;
size_t offset;
CeedInt num_sub_labels;
CeedContextFieldLabel *sub_labels;
bool from_op;
};
struct CeedOperatorField_private {
CeedElemRestriction elem_rstr; /* Restriction from L-vector */
CeedBasis basis; /* Basis or CEED_BASIS_NONE for collocated fields */
CeedVector vec; /* State vector for passive fields or CEED_VECTOR_NONE for no vector */
const char *field_name; /* matching QFunction field name */
};
struct CeedQFunctionAssemblyData_private {
Ceed ceed;
int ref_count;
bool is_setup;
bool reuse_data;
bool needs_data_update;
CeedVector vec;
CeedElemRestriction rstr;
};
struct CeedOperatorAssemblyData_private {
Ceed ceed;
CeedInt num_active_bases;
CeedBasis *active_bases;
CeedElemRestriction *active_elem_rstrs;
CeedInt *num_eval_modes_in, *num_eval_modes_out;
CeedEvalMode **eval_modes_in, **eval_modes_out;
CeedScalar **assembled_bases_in, **assembled_bases_out;
CeedSize **eval_mode_offsets_in, **eval_mode_offsets_out, num_output_components;
};
struct CeedOperator_private {
Ceed ceed;
CeedOperator op_fallback, op_fallback_parent;
int ref_count;
int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, CeedElemRestriction *, CeedRequest *);
int (*LinearAssembleQFunctionUpdate)(CeedOperator, CeedVector, CeedElemRestriction, CeedRequest *);
int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *);
int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *);
int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, CeedRequest *);
int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, CeedRequest *);
int (*LinearAssembleSymbolic)(CeedOperator, CeedSize *, CeedInt **, CeedInt **);
int (*LinearAssemble)(CeedOperator, CeedVector);
int (*LinearAssembleSingle)(CeedOperator, CeedInt, CeedVector);
int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *);
int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, CeedVector, CeedRequest *);
int (*Destroy)(CeedOperator);
CeedOperatorField *input_fields;
CeedOperatorField *output_fields;
CeedSize input_size, output_size;
CeedInt num_elem; /* Number of elements */
CeedInt num_qpts; /* Number of quadrature points over all elements */
CeedInt num_fields; /* Number of fields that have been set */
CeedQFunction qf;
CeedQFunction dqf;
CeedQFunction dqfT;
const char *name;
bool is_immutable;
bool is_interface_setup;
bool is_backend_setup;
bool is_composite;
bool has_restriction;
CeedQFunctionAssemblyData qf_assembled;
CeedOperatorAssemblyData op_assembled;
CeedOperator *sub_operators;
CeedInt num_suboperators;
void *data;
CeedInt num_context_labels;
CeedInt max_context_labels;
CeedContextFieldLabel *context_labels;
};
#endif // CEED_IMPL_H
|
e916964a413118302e908baa2c8c9897068a0d44
|
eed3cdaa263de8fced4b982bf3e92d0ab16fdbbf
|
/Switch/ext/ebtree/common/config.h
|
5833cfcdb869e38840881b38c5bef56457e08bde
|
[
"LGPL-2.1-only",
"Apache-2.0"
] |
permissive
|
phaistos-networks/TANK
|
4eeaf2e51b8397ff63705a9c63c28fa12b368fc3
|
ecb7a2d23532bf6eb21c5f587490f71b7afdb859
|
refs/heads/master
| 2023-03-08T06:01:00.660937
| 2022-09-06T08:22:58
| 2022-09-06T08:22:58
| 62,232,843
| 1,022
| 82
|
Apache-2.0
| 2020-02-01T07:12:34
| 2016-06-29T14:35:45
|
C++
|
UTF-8
|
C
| false
| false
| 2,258
|
h
|
config.h
|
/*
* include/common/config.h
* This files contains most of the user-configurable settings.
*
* Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, version 2.1
* exclusively.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _COMMON_CONFIG_H
#define _COMMON_CONFIG_H
#include <common/compiler.h>
#include <common/defaults.h>
/* this reduces the number of calls to select() by choosing appropriate
* sheduler precision in milliseconds. It should be near the minimum
* time that is needed by select() to collect all events. All timeouts
* are rounded up by adding this value prior to pass it to select().
*/
#define SCHEDULER_RESOLUTION 9
/* CONFIG_HAP_MEM_OPTIM
* This enables use of memory pools instead of malloc()/free(). There
* is no reason to disable it, except perhaps for rare debugging.
*/
#ifndef CONFIG_HAP_NO_MEM_OPTIM
# define CONFIG_HAP_MEM_OPTIM
#endif /* CONFIG_HAP_NO_MEM_OPTIM */
/* CONFIG_HAP_MALLOC / CONFIG_HAP_CALLOC / CONFIG_HAP_FREE
* This macro allows to replace the malloc function with another one.
*/
#ifdef CONFIG_HAP_MALLOC
#define MALLOC CONFIG_HAP_MALLOC
#else
#define MALLOC malloc
#endif
#ifdef CONFIG_HAP_CALLOC
#define CALLOC CONFIG_HAP_CALLOC
#else
#define CALLOC calloc
#endif
#ifdef CONFIG_HAP_FREE
#define FREE CONFIG_HAP_FREE
#else
#define FREE free
#endif
/* CONFIG_HAP_INLINE_FD_SET
* This makes use of inline FD_* macros instead of calling equivalent
* functions. Benchmarks on a Pentium-M show that using functions is
* generally twice as fast. So it's better to keep this option unset.
*/
//#undef CONFIG_HAP_INLINE_FD_SET
#endif /* _COMMON_CONFIG_H */
|
da8b819d8204343fd6a4ab5db90f0c9c13098caf
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/usermode/modules/syscallemu/syscallemu.h
|
87508842daf794a6a6b11a22f5abe3a4e28956d4
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 2,567
|
h
|
syscallemu.h
|
/* $NetBSD: syscallemu.h,v 1.1 2012/01/05 13:26:51 jmcneill Exp $ */
/*-
* Copyright (c) 2012 Jared D. McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _HAVE_SYSCALLEMU_H
#define _HAVE_SYSCALLEMU_H
#include <sys/cdefs.h>
#include <sys/syscall.h>
#include <sys/syscallargs.h>
struct proc;
/*
* Process specific syscallemu configuration
*/
struct syscallemu_data {
vaddr_t sce_user_start;
vaddr_t sce_user_end;
void *sce_md_syscall;
};
/*
* Get process specific syscallemu data
*/
struct syscallemu_data * syscallemu_getsce(struct proc *);
/*
* Set process specific syscallemu data
*/
void syscallemu_setsce(struct proc *, struct syscallemu_data *);
/*
* MD specific syscallemu syscall setup (in syscallemu_${MACHINE_ARCH}.c)
*/
void * md_syscallemu(struct proc *);
/* syscall: "syscallemu" ret: "int" args: "uintptr_t" "uintptr_t" */
#define SYS_syscallemu 511
struct sys_syscallemu_args {
syscallarg(uintptr_t) user_start;
syscallarg(uintptr_t) user_end;
};
check_syscall_args(sys_syscallemu);
int sys_syscallemu(struct lwp *, const struct sys_syscallemu_args *,
register_t *);
__CTASSERT(SYS_syscallemu >= SYS_MAXSYSCALL);
__CTASSERT(SYS_syscallemu < SYS_NSYSENT);
#endif /* !_HAVE_SYSCALLEMU_H */
|
2a9af61755b28dc5a5183071d13570d138b9ce3b
|
cf35a104dabc3d3647df66aff9db32d18b002e1b
|
/cmd/wmiir.c
|
c242d14ec52c7431985df37aff2795762da30f70
|
[
"MIT"
] |
permissive
|
0intro/wmii
|
ba2dff4be1a049c7d4475218a914585a3f810ab5
|
024f29d1058b58aa4ee6b956500a78f69355fb53
|
refs/heads/main
| 2023-07-11T18:08:43.660898
| 2023-06-25T18:57:45
| 2023-06-25T18:57:45
| 74,551,919
| 110
| 17
| null | null | null | null |
UTF-8
|
C
| false
| false
| 10,535
|
c
|
wmiir.c
|
/* Copyight ©2007-2010 Kris Maglione <maglione.k at Gmail>
* See LICENSE file for license details.
*/
#define IXP_NO_P9_
#define IXP_P9_STRUCTS
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <ixp.h>
#include <stuff/util.h>
#include <bio.h>
#include <fmt.h>
char *argv0;
static IxpClient* client;
static Biobuf* outbuf;
static bool binary;
static void
usage(void) {
lprint(1,
"usage: %s [-a <address>] [-b] {create | ls [-dlp] | read | remove | write} <file>\n"
" %s [-a <address>] xwrite <file> <data>\n"
" %s -v\n", argv0, argv0, argv0);
exit(1);
}
static int
errfmt(Fmt *f) {
return fmtstrcpy(f, ixp_errbuf());
}
static bool
flush(IxpCFid *fid, char *in, int len, bool binary) {
static mbstate_t state;
static char buf[IXP_MAX_MSG];
static char *out = buf, *outend = buf + sizeof buf;
char *inend;
wchar_t w;
Rune r;
int res;
if(binary)
return ixp_write(fid, in, len) == len;
inend = in + len;
do {
if(in == nil || out + UTFmax > outend) {
if(ixp_write(fid, buf, out - buf) != out - buf)
return false;
out = buf;
}
if(in == nil) {
state = (mbstate_t){0};
return true;
}
switch((res = mbrtowc(&w, in, inend - in, &state))) {
case -1:
return false;
case 0:
case -2:
return true;
default:
in += res;
r = w < Runemax ? w : Runesync;
out += runetochar(out, &r);
}
} while(in < inend);
return true;
}
static bool
unflush(int fd, char *in, int len, bool binary) {
static mbstate_t state;
static char buf[IXP_MAX_MSG], extra[UTFmax];
static char *out = buf, *outend = buf + sizeof buf;
static int nextra;
char *start;
Rune r;
int res, n;
if(binary)
return write(fd, in, len) == len;
if(in) {
if((n = nextra)) {
nextra = 0;
while(len > 0 && n < UTFmax && !fullrune(extra, n)) {
extra[n++] = *in++;
len--;
}
unflush(fd, extra, n, binary);
}
n = utfnlen(in, len);
}
start = in;
do {
if(in == nil || out + MB_LEN_MAX > outend) {
if(write(fd, buf, out - buf) != out - buf)
return false;
out = buf;
}
if(in == nil || n == 0) {
state = (mbstate_t){0};
return true;
}
in += chartorune(&r, in);
n--;
res = wcrtomb(out, r, &state);
if(res == -1)
*out++ = '?';
else
out += res;
} while(n > 0);
if(in < start + len) {
nextra = min(sizeof extra, len - (in - start));
memcpy(extra, in, nextra);
}
return true;
}
/* Utility Functions */
static void
write_data(IxpCFid *fid, char *name, bool binary) {
char buf[IXP_MAX_MSG];
int len;
while((len = read(0, buf, fid->iounit)) > 0)
if(!flush(fid, buf, len, binary))
fatal("cannot write file %q\n", name);
if(!binary)
flush(fid, nil, 0, binary);
}
static int
comp_stat(const void *s1, const void *s2) {
Stat *st1, *st2;
st1 = (Stat*)s1;
st2 = (Stat*)s2;
return strcmp(st1->name, st2->name);
}
static void
setrwx(long m, char *s) {
static char *modes[] = {
"---", "--x", "-w-",
"-wx", "r--", "r-x",
"rw-", "rwx",
};
strncpy(s, modes[m], 3);
}
static char *
modestr(uint mode) {
static char buf[16];
buf[0]='-';
if(mode & P9_DMDIR)
buf[0]='d';
buf[1]='-';
setrwx((mode >> 6) & 7, &buf[2]);
setrwx((mode >> 3) & 7, &buf[5]);
setrwx((mode >> 0) & 7, &buf[8]);
buf[11] = 0;
return buf;
}
static char*
timestr(time_t val) {
static char buf[32];
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M", localtime(&val));
return buf;
}
static void
print_stat(Stat *s, int lflag, char *file, int pflag) {
char *slash;
slash = "";
if(pflag)
slash = "/";
else
file = "";
if(lflag)
Blprint(outbuf, "%s %s %s %5llud %s %s%s%s\n",
modestr(s->mode), s->uid, s->gid, s->length,
timestr(s->mtime), file, slash, s->name);
else {
if((s->mode&P9_DMDIR) && strcmp(s->name, "/"))
Blprint(outbuf, "%s%s%s/\n", file, slash, s->name);
else
Blprint(outbuf, "%s%s%s\n", file, slash, s->name);
}
}
/* Service Functions */
static int
xwrite(int argc, char *argv[]) {
IxpCFid *fid;
char *file;
ARGBEGIN{
default:
usage();
}ARGEND;
file = EARGF(usage());
fid = ixp_open(client, file, P9_OWRITE);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
write_data(fid, file, binary);
ixp_close(fid);
return 0;
}
static int
xawrite(int argc, char *argv[]) {
IxpCFid *fid;
char *file, *buf;
int nbuf, i;
ARGBEGIN{
default:
usage();
}ARGEND;
file = EARGF(usage());
fid = ixp_open(client, file, P9_OWRITE);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
nbuf = 1;
for(i=0; i < argc; i++)
nbuf += strlen(argv[i]) + (i > 0);
buf = emalloc(nbuf);
buf[0] = '\0';
while(argc) {
strcat(buf, ARGF());
if(argc)
strcat(buf, " ");
}
if(!(flush(fid, buf, nbuf, binary) && (binary || flush(fid, 0, 0, binary))))
fatal("cannot write file '%s': %r\n", file);
ixp_close(fid);
free(buf);
return 0;
}
static int
xcreate(int argc, char *argv[]) {
IxpCFid *fid;
char *file;
ARGBEGIN{
default:
usage();
}ARGEND;
file = EARGF(usage());
fid = ixp_create(client, file, 0777, P9_OWRITE);
if(fid == nil)
fatal("Can't create file '%s': %r\n", file);
if((fid->qid.type&P9_DMDIR) == 0)
write_data(fid, file, binary);
ixp_close(fid);
return 0;
}
static int
xremove(int argc, char *argv[]) {
char *file;
ARGBEGIN{
default:
usage();
}ARGEND;
file = EARGF(usage());
do {
if(!ixp_remove(client, file))
lprint(2, "%s: Can't remove file '%s': %r\n", argv0, file);
}while((file = ARGF()));
return 0;
}
static int
xread(int argc, char *argv[]) {
IxpCFid *fid;
char *file, *buf;
int count;
ARGBEGIN{
default:
usage();
}ARGEND;
if(argc == 0)
usage();
file = EARGF(usage());
do {
fid = ixp_open(client, file, P9_OREAD);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
buf = emalloc(fid->iounit);
while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
unflush(1, buf, count, binary);
if (!binary && count < fid->iounit)
unflush(1, 0, 0, binary);
}
if(!binary)
unflush(1, 0, 0, binary);
ixp_close(fid);
if(count == -1)
lprint(2, "%s: cannot read file '%s': %r\n", argv0, file);
} while((file = ARGF()));
return 0;
}
static int
xls(int argc, char *argv[]) {
IxpMsg m;
Stat *stat;
IxpCFid *fid;
char *file;
char *buf;
int lflag, dflag, pflag;
int count, nstat, mstat, i;
lflag = dflag = pflag = 0;
ARGBEGIN{
case 'l':
lflag++;
break;
case 'd':
dflag++;
break;
case 'p':
pflag++;
break;
default:
usage();
}ARGEND;
count = 0;
file = EARGF(usage());
do {
stat = ixp_stat(client, file);
if(stat == nil)
fatal("cannot stat file '%s': %r\n", file);
i = strlen(file);
if(file[i-1] == '/') {
file[i-1] = '\0';
if(!(stat->mode&P9_DMDIR))
fatal("%s: not a directory", file);
}
if(dflag || (stat->mode&P9_DMDIR) == 0) {
print_stat(stat, lflag, file, pflag);
ixp_freestat(stat);
continue;
}
ixp_freestat(stat);
fid = ixp_open(client, file, P9_OREAD);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
nstat = 0;
mstat = 16;
stat = emalloc(mstat * sizeof *stat);
buf = emalloc(fid->iounit);
while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
m = ixp_message(buf, count, MsgUnpack);
while(m.pos < m.end) {
if(nstat == mstat) {
mstat <<= 1;
stat = erealloc(stat, mstat * sizeof *stat);
}
ixp_pstat(&m, &stat[nstat++]);
}
}
ixp_close(fid);
qsort(stat, nstat, sizeof *stat, comp_stat);
for(i = 0; i < nstat; i++) {
print_stat(&stat[i], lflag, file, pflag);
ixp_freestat(&stat[i]);
}
free(stat);
} while((file = ARGF()));
if(count == -1)
fatal("cannot read directory '%s': %r\n", file);
return 0;
}
static int
xnamespace(int argc, char *argv[]) {
char *path;
ARGBEGIN{
default:
usage();
}ARGEND;
path = ixp_namespace();
if(path == nil)
fatal("can't find namespace: %r\n");
Blprint(outbuf, "%s", path);
return 0;
}
static int
xproglist(int argc, char *argv[]) {
DIR *d;
struct dirent *de;
struct stat st;
char *dir, *cwd;
int i;
quotefmtinstall();
ARGBEGIN{
default:
usage();
}ARGEND;
i = 7, cwd = nil;
do
cwd = erealloc(cwd, 1<<i);
while(!getcwd(cwd, 1<<i) && errno == ERANGE);
while((dir = ARGF()))
/* Don't use Blprint. wimenu expects UTF-8. */
if(!chdir(cwd) && !chdir(dir) && (d = opendir(dir))) {
while((de = readdir(d))) {
stat(de->d_name, &st);
if(S_ISREG(st.st_mode) && !access(de->d_name, X_OK))
Bprint(outbuf, "%q\n", de->d_name);
}
closedir(d);
}
return 0; /* NOTREACHED */
}
static int
xsetsid(int argc, char *argv[]) {
char *av0;
bool dofork;
av0 = nil;
dofork = false;
ARGBEGIN{
case '0':
av0 = EARGF(usage());
break;
case 'f':
dofork = true;
break;
default:
usage();
}ARGEND;
if(av0 == nil)
av0 = argv[0];
if(av0 == nil)
return 1;
setsid();
if(dofork)
switch(fork()) {
case 0: break;
case -1: fatal("can't fork: %r\n");
default: return 0;
}
execvp(av0, argv);
fatal("setsid: can't exec: %r");
return 1; /* NOTREACHED */
}
typedef struct exectab exectab;
struct exectab {
char *cmd;
int (*fn)(int, char**);
} fstab[] = {
{"cat", xread},
{"create", xcreate},
{"ls", xls},
{"read", xread},
{"remove", xremove},
{"rm", xremove},
{"write", xwrite},
{"xwrite", xawrite},
{0, }
}, utiltab[] = {
{"namespace", xnamespace},
{"ns", xnamespace},
{"proglist", xproglist},
{"setsid", xsetsid},
{0, }
};
int
main(int argc, char *argv[]) {
char *address;
exectab *tab;
int ret;
IXP_ASSERT_VERSION;
setlocale(LC_ALL, "");
binary = utf8locale();
quotefmtinstall();
fmtinstall('r', errfmt);
address = getenv("WMII_ADDRESS");
ARGBEGIN{
case 'b':
binary = true;
break;
case 'v':
lprint(1, "%s-" VERSION ", " COPYRIGHT "\n", argv0);
exit(0);
case 'a':
address = EARGF(usage());
break;
default:
usage();
}ARGEND;
if(argc < 1)
usage();
outbuf = Bfdopen(1, OWRITE);
for(tab=utiltab; tab->cmd; tab++)
if(!strcmp(*argv, tab->cmd)) {
ret = tab->fn(argc, argv);
goto done;
}
if(address && *address)
client = ixp_mount(address);
else
client = ixp_nsmount("wmii");
if(client == nil)
fatal("can't mount: %r\n");
signal(SIGPIPE, SIG_DFL);
for(tab=fstab; tab->cmd; tab++)
if(strcmp(*argv, tab->cmd) == 0) break;
if(tab->cmd == 0)
usage();
ret = tab->fn(argc, argv);
ixp_unmount(client);
done:
Bterm(outbuf);
return ret;
}
|
554da49b103c23c4e99d4b9b5a8ca4ba484429a4
|
810237086aae7600b9ef87a610aec4777b1bf156
|
/Example/Pods/Headers/Public/SJVideoPlayer/SJMoreSettingControlLayer.h
|
cbc0952623dafc73a575bee4ee8a0a685df0c315
|
[
"MIT"
] |
permissive
|
changsanjiang/SJVideoPlayer
|
f63f3156d5ad07ec107b0feb481110222dd45a85
|
bff75e1f7f033edc05e07c333ce3557cb289c95c
|
refs/heads/master
| 2022-12-20T22:47:04.095976
| 2022-12-10T08:57:46
| 2022-12-10T08:57:46
| 100,693,284
| 2,680
| 513
|
MIT
| 2022-11-02T11:04:42
| 2017-08-18T08:56:30
|
Objective-C
|
UTF-8
|
C
| false
| false
| 96
|
h
|
SJMoreSettingControlLayer.h
|
../../../../../SJVideoPlayer/ControlLayers/SJMoreSettingControlLayer/SJMoreSettingControlLayer.h
|
0269dfeda98383278d5518e9f2ed1a8dc3872b52
|
de21f9075f55640514c29ef0f1fe3f0690845764
|
/regression/contracts-dfcc/invar_struct_member/main.c
|
dc585980b22f2258049f48c8a1054c51fb8a0370
|
[
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference",
"BSD-4-Clause"
] |
permissive
|
diffblue/cbmc
|
975a074ac445febb3b5715f8792beb545522dc18
|
decd2839c2f51a54b2ad0f3e89fdc1b4bf78cd16
|
refs/heads/develop
| 2023-08-31T05:52:05.342195
| 2023-08-30T13:31:51
| 2023-08-30T13:31:51
| 51,877,056
| 589
| 309
|
NOASSERTION
| 2023-09-14T18:49:17
| 2016-02-16T23:03:52
|
C++
|
UTF-8
|
C
| false
| false
| 218
|
c
|
main.c
|
struct test
{
int x;
};
void main()
{
struct test t;
t.x = 0;
unsigned n;
for(unsigned i = 0; i < n; ++i)
__CPROVER_loop_invariant(i <= n)
{
t.x += 2;
}
assert(t.x == 0 || t.x == 2);
}
|
ed2ae2cfa767e7eaf08295c3f1f75a9da486d2f3
|
70ffcb065027032a399f44b9ec91e7b61d73583d
|
/common/addr.c
|
4fa783714d250fc633657ed775857f1e2bca23ee
|
[
"MIT"
] |
permissive
|
ElementsProject/lightning
|
4e260841b2ebad8c772a5ff91ef1ebbc3fe1ad71
|
990096f904e26386527a4eddd8d3262464bacabd
|
refs/heads/master
| 2023-09-01T07:11:34.794039
| 2023-08-31T09:55:14
| 2023-08-31T22:02:14
| 37,350,472
| 2,812
| 961
|
NOASSERTION
| 2023-09-14T19:33:22
| 2015-06-13T00:04:22
|
C
|
UTF-8
|
C
| false
| false
| 959
|
c
|
addr.c
|
#include "config.h"
#include <bitcoin/address.h>
#include <bitcoin/base58.h>
#include <bitcoin/script.h>
#include <common/addr.h>
#include <common/bech32.h>
char *encode_scriptpubkey_to_addr(const tal_t *ctx,
const struct chainparams *chainparams,
const u8 *scriptPubkey)
{
char *out;
size_t scriptLen = tal_bytelen(scriptPubkey);
struct bitcoin_address pkh;
struct ripemd160 sh;
int witver;
if (is_p2pkh(scriptPubkey, &pkh))
return bitcoin_to_base58(ctx, chainparams, &pkh);
if (is_p2sh(scriptPubkey, &sh))
return p2sh_to_base58(ctx, chainparams, &sh);
out = tal_arr(ctx, char, 73 + strlen(chainparams->onchain_hrp));
if (is_p2tr(scriptPubkey, NULL))
witver = 1;
else if (is_p2wpkh(scriptPubkey, NULL) || is_p2wsh(scriptPubkey, NULL))
witver = 0;
else {
return tal_free(out);
}
if (!segwit_addr_encode(out, chainparams->onchain_hrp, witver,
scriptPubkey + 2, scriptLen - 2))
return tal_free(out);
return out;
}
|
150f07a120a055099595fc40e60c28ce7aebb03a
|
ec76c8d9fac473bfee15ce73f1e6ae30acf55671
|
/exploits/CVE-2021-3156/exploit3/sudo-1.8.31/lib/util/strtoid.c
|
1312aa6a495be0dae0235675537a8a51056c1986
|
[
"MIT",
"LGPL-2.1-or-later",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
TH3xACE/SUDO_KILLER
|
3e26441402951dd322d1d72aca3366b47d5452d4
|
c2376637fdd9fd3ad8dc19a04049e6aa99cf3bea
|
refs/heads/master
| 2023-08-11T04:13:58.713001
| 2023-07-24T14:58:32
| 2023-07-24T14:58:32
| 160,875,594
| 2,026
| 264
|
MIT
| 2021-03-26T18:07:52
| 2018-12-07T21:08:02
|
Shell
|
UTF-8
|
C
| false
| false
| 3,300
|
c
|
strtoid.c
|
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2013-2019 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
*/
#include <config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(HAVE_STDINT_H)
# include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# include "compat/stdbool.h"
#endif
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "sudo_gettext.h" /* must be included before sudo_compat.h */
#include "sudo_compat.h"
#include "sudo_debug.h"
#include "sudo_util.h"
/* strtoid.c (not exported) */
long long sudo_strtonumx(const char *str, long long minval, long long maxval, char **ep, const char **errstrp);
/*
* Make sure that the ID ends with a valid separator char.
*/
static bool
valid_separator(const char *p, const char *ep, const char *sep)
{
bool valid = false;
if (ep != p) {
/* check for valid separator (including '\0') */
if (sep == NULL)
sep = "";
do {
if (*ep == *sep)
valid = true;
} while (*sep++ != '\0');
}
return valid;
}
/*
* Parse a uid/gid in string form.
* If sep is non-NULL, it contains valid separator characters (e.g. comma, space)
* If endp is non-NULL it is set to the next char after the ID.
* On success, returns the parsed ID and clears errstr.
* On error, returns 0 and sets errstr.
*/
id_t
sudo_strtoidx_v1(const char *p, const char *sep, char **endp, const char **errstrp)
{
const char *errstr;
char *ep;
id_t ret;
debug_decl(sudo_strtoid, SUDO_DEBUG_UTIL)
ret = sudo_strtonumx(p, INT_MIN, UINT_MAX, &ep, &errstr);
if (errstr == NULL) {
/*
* Disallow id -1 (UINT_MAX), which means "no change"
* and check for a valid separator (if specified).
*/
if (ret == (id_t)-1 || ret == (id_t)UINT_MAX || !valid_separator(p, ep, sep)) {
errstr = N_("invalid value");
errno = EINVAL;
ret = 0;
}
}
if (errstrp != NULL)
*errstrp = errstr;
if (endp != NULL)
*endp = ep;
debug_return_id_t(ret);
}
/* Backwards compatibility */
id_t
sudo_strtoid_v1(const char *p, const char *sep, char **endp, const char **errstrp)
{
return sudo_strtoidx_v1(p, sep, endp, errstrp);
}
/* Simplified interface */
id_t
sudo_strtoid_v2(const char *p, const char **errstrp)
{
return sudo_strtoidx_v1(p, NULL, NULL, errstrp);
}
|
d2fe7c085c20bf46a875c021d90c3e7e948ac235
|
b49bb32eafeea931b86ddfc44ef43c01e81a9128
|
/Sources/BlocksRuntime/runtime.c
|
1b7945b949c5774b6b8cfcaa1c586f95cabaadd9
|
[
"Apache-2.0",
"Swift-exception"
] |
permissive
|
apple/swift-corelibs-foundation
|
a70e9d95bc69de33ea26343efde3941c5d4d7c85
|
9f53cc551e065d73b327a80147895822bc8f89e0
|
refs/heads/main
| 2023-08-18T01:25:02.154068
| 2023-08-11T20:54:56
| 2023-08-11T20:54:56
| 45,863,890
| 5,583
| 1,542
|
Apache-2.0
| 2023-09-12T00:47:36
| 2015-11-09T20:12:23
|
Swift
|
UTF-8
|
C
| false
| false
| 27,857
|
c
|
runtime.c
|
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
#include "Block_private.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#if TARGET_OS_WIN32
#include <Windows.h>
#include <Psapi.h>
#else
#include <dlfcn.h>
#endif
#if __has_include(<os/assumes.h>)
#include <os/assumes.h>
#else
#include <assert.h>
#endif
#ifndef os_assumes
#define os_assumes(_x) _x
#endif
#ifndef os_assert
#define os_assert(_x) assert(_x)
#endif
#if !defined(__has_builtin)
#define __has_builtin(builtin) 0
#endif
#if __has_builtin(__sync_bool_compare_and_swap)
#define OSAtomicCompareAndSwapInt(Old, New, Ptr) \
__sync_bool_compare_and_swap(Ptr, Old, New)
#elif TARGET_OS_WIN32
#define _CRT_SECURE_NO_WARNINGS 1
#include <Windows.h>
static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi,
int volatile *dst) {
// fixme barrier is overkill -- see objc-os.h
int original = InterlockedCompareExchange((LONG volatile *)dst, newi, oldi);
return (original == oldi);
}
#endif
/***********************
Globals
************************/
static void *_Block_copy_class = _NSConcreteMallocBlock;
static void *_Block_copy_finalizing_class = _NSConcreteMallocBlock;
static int _Block_copy_flag = BLOCK_NEEDS_FREE;
static int _Byref_flag_initial_value = BLOCK_BYREF_NEEDS_FREE | 4; // logical 2
static bool isGC = false;
/*******************************************************************************
Internal Utilities
********************************************************************************/
static int32_t latching_incr_int(volatile int32_t *where) {
while (1) {
int32_t old_value = *where;
if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
return BLOCK_REFCOUNT_MASK;
}
if (OSAtomicCompareAndSwapInt(old_value, old_value+2, where)) {
return old_value+2;
}
}
}
static bool latching_incr_int_not_deallocating(volatile int32_t *where) {
while (1) {
int32_t old_value = *where;
if (old_value & BLOCK_DEALLOCATING) {
// if deallocating we can't do this
return false;
}
if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
// if latched, we're leaking this block, and we succeed
return true;
}
if (OSAtomicCompareAndSwapInt(old_value, old_value+2, where)) {
// otherwise, we must store a new retained value without the deallocating bit set
return true;
}
}
}
// return should_deallocate?
static bool latching_decr_int_should_deallocate(volatile int32_t *where) {
while (1) {
int32_t old_value = *where;
if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
return false; // latched high
}
if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
return false; // underflow, latch low
}
int32_t new_value = old_value - 2;
bool result = false;
if ((old_value & (BLOCK_REFCOUNT_MASK|BLOCK_DEALLOCATING)) == 2) {
new_value = old_value - 1;
result = true;
}
if (OSAtomicCompareAndSwapInt(old_value, new_value, where)) {
return result;
}
}
}
// hit zero?
static bool latching_decr_int_now_zero(volatile int32_t *where) {
while (1) {
int32_t old_value = *where;
if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
return false; // latched high
}
if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
return false; // underflow, latch low
}
int32_t new_value = old_value - 2;
if (OSAtomicCompareAndSwapInt(old_value, new_value, where)) {
return (new_value & BLOCK_REFCOUNT_MASK) == 0;
}
}
}
/***********************
GC support stub routines
************************/
#if !TARGET_OS_WIN32
#pragma mark GC Support Routines
#endif
static void *_Block_alloc_default(size_t size, const bool initialCountIsOne, const bool isObject) {
return malloc(size);
}
static void _Block_assign_default(void *value, void **destptr) {
*destptr = value;
}
static void _Block_setHasRefcount_default(const void *ptr, const bool hasRefcount) {
}
static void _Block_do_nothing(const void *aBlock) { }
static void _Block_retain_object_default(const void *ptr) {
}
static void _Block_release_object_default(const void *ptr) {
}
static void _Block_assign_weak_default(const void *ptr, void *dest) {
#if !TARGET_OS_WIN32
*(long *)dest = (long)ptr;
#else
*(void **)dest = (void *)ptr;
#endif
}
static void _Block_memmove_default(void *dst, void *src, unsigned long size) {
memmove(dst, src, (size_t)size);
}
static void _Block_memmove_gc_broken(void *dest, void *src, unsigned long size) {
void **destp = (void **)dest;
void **srcp = (void **)src;
while (size) {
_Block_assign_default(*srcp, destp);
destp++;
srcp++;
size -= sizeof(void *);
}
}
static void _Block_destructInstance_default(const void *aBlock) {}
/**************************************************************************
GC support callout functions - initially set to stub routines
***************************************************************************/
static void *(*_Block_allocator)(size_t, const bool isOne, const bool isObject) = _Block_alloc_default;
static void (*_Block_deallocator)(const void *) = (void (*)(const void *))free;
static void (*_Block_assign)(void *value, void **destptr) = _Block_assign_default;
static void (*_Block_setHasRefcount)(const void *ptr, const bool hasRefcount) = _Block_setHasRefcount_default;
static void (*_Block_retain_object)(const void *ptr) = _Block_retain_object_default;
static void (*_Block_release_object)(const void *ptr) = _Block_release_object_default;
static void (*_Block_assign_weak)(const void *dest, void *ptr) = _Block_assign_weak_default;
static void (*_Block_memmove)(void *dest, void *src, unsigned long size) = _Block_memmove_default;
static void (*_Block_destructInstance) (const void *aBlock) = _Block_destructInstance_default;
/**************************************************************************
GC support SPI functions - called from ObjC runtime and CoreFoundation
***************************************************************************/
// Public SPI
// Called from objc-auto to turn on GC.
// version 3, 4 arg, but changed 1st arg
void _Block_use_GC( void *(*alloc)(size_t, const bool isOne, const bool isObject),
void (*setHasRefcount)(const void *, const bool),
void (*gc_assign)(void *, void **),
void (*gc_assign_weak)(const void *, void *),
void (*gc_memmove)(void *, void *, unsigned long)) {
isGC = true;
_Block_allocator = alloc;
_Block_deallocator = _Block_do_nothing;
_Block_assign = gc_assign;
_Block_copy_flag = BLOCK_IS_GC;
_Block_copy_class = _NSConcreteAutoBlock;
// blocks with ctors & dtors need to have the dtor run from a class with a finalizer
_Block_copy_finalizing_class = _NSConcreteFinalizingBlock;
_Block_setHasRefcount = setHasRefcount;
_Byref_flag_initial_value = BLOCK_BYREF_IS_GC; // no refcount
_Block_retain_object = _Block_do_nothing;
_Block_release_object = _Block_do_nothing;
_Block_assign_weak = gc_assign_weak;
_Block_memmove = gc_memmove;
}
// transitional
void _Block_use_GC5( void *(*alloc)(size_t, const bool isOne, const bool isObject),
void (*setHasRefcount)(const void *, const bool),
void (*gc_assign)(void *, void **),
void (*gc_assign_weak)(const void *, void *)) {
// until objc calls _Block_use_GC it will call us; supply a broken internal memmove implementation until then
_Block_use_GC(alloc, setHasRefcount, gc_assign, gc_assign_weak, _Block_memmove_gc_broken);
}
// Called from objc-auto to alternatively turn on retain/release.
// Prior to this the only "object" support we can provide is for those
// super special objects that live in libSystem, namely dispatch queues.
// Blocks and Block_byrefs have their own special entry points.
void _Block_use_RR( void (*retain)(const void *),
void (*release)(const void *)) {
_Block_retain_object = retain;
_Block_release_object = release;
#if TARGET_OS_WIN32
HANDLE hProcess = GetCurrentProcess();
HMODULE hModule[1024];
DWORD cbNeeded = 0;
if (!EnumProcessModules(hProcess, hModule, sizeof(hModule), &cbNeeded))
return;
if (cbNeeded > sizeof(hModule))
return;
for (unsigned I = 0; I < (cbNeeded / sizeof(HMODULE)); ++I) {
_Block_destructInstance =
(void (*)(const void *))GetProcAddress(hModule[I],
"objc_destructInstance");
if (_Block_destructInstance)
break;
}
#else
_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance");
#endif
}
// Called from CF to indicate MRR. Newer version uses a versioned structure, so we can add more functions
// without defining a new entry point.
void _Block_use_RR2(const Block_callbacks_RR *callbacks) {
_Block_retain_object = callbacks->retain;
_Block_release_object = callbacks->release;
_Block_destructInstance = callbacks->destructInstance;
}
/****************************************************************************
Accessors for block descriptor fields
*****************************************************************************/
#if 0
static struct Block_descriptor_1 * _Block_descriptor_1(struct Block_layout *aBlock)
{
return aBlock->descriptor;
}
#endif
static struct Block_descriptor_2 * _Block_descriptor_2(struct Block_layout *aBlock)
{
if (! (aBlock->flags & BLOCK_HAS_COPY_DISPOSE)) return NULL;
uint8_t *desc = (uint8_t *)aBlock->descriptor;
desc += sizeof(struct Block_descriptor_1);
return (struct Block_descriptor_2 *)desc;
}
static struct Block_descriptor_3 * _Block_descriptor_3(struct Block_layout *aBlock)
{
if (! (aBlock->flags & BLOCK_HAS_SIGNATURE)) return NULL;
uint8_t *desc = (uint8_t *)aBlock->descriptor;
desc += sizeof(struct Block_descriptor_1);
if (aBlock->flags & BLOCK_HAS_COPY_DISPOSE) {
desc += sizeof(struct Block_descriptor_2);
}
return (struct Block_descriptor_3 *)desc;
}
static __inline bool _Block_has_layout(struct Block_layout *aBlock) {
if (! (aBlock->flags & BLOCK_HAS_SIGNATURE)) return false;
uint8_t *desc = (uint8_t *)aBlock->descriptor;
desc += sizeof(struct Block_descriptor_1);
if (aBlock->flags & BLOCK_HAS_COPY_DISPOSE) {
desc += sizeof(struct Block_descriptor_2);
}
return ((struct Block_descriptor_3 *)desc)->layout != NULL;
}
static void _Block_call_copy_helper(void *result, struct Block_layout *aBlock)
{
struct Block_descriptor_2 *desc = _Block_descriptor_2(aBlock);
if (!desc) return;
(*desc->copy)(result, aBlock); // do fixup
}
static void _Block_call_dispose_helper(struct Block_layout *aBlock)
{
struct Block_descriptor_2 *desc = _Block_descriptor_2(aBlock);
if (!desc) return;
(*desc->dispose)(aBlock);
}
/*******************************************************************************
Internal Support routines for copying
********************************************************************************/
#if !TARGET_OS_WIN32
#pragma mark Copy/Release support
#endif
// Copy, or bump refcount, of a block. If really copying, call the copy helper if present.
static void *_Block_copy_internal(const void *arg, const bool wantsOne) {
struct Block_layout *aBlock;
if (!arg) return NULL;
// The following would be better done as a switch statement
aBlock = (struct Block_layout *)arg;
if (aBlock->flags & BLOCK_NEEDS_FREE) {
// latches on high
latching_incr_int(&aBlock->flags);
return aBlock;
}
else if (aBlock->flags & BLOCK_IS_GC) {
// GC refcounting is expensive so do most refcounting here.
if (wantsOne && ((latching_incr_int(&aBlock->flags) & BLOCK_REFCOUNT_MASK) == 2)) {
// Tell collector to hang on this - it will bump the GC refcount version
_Block_setHasRefcount(aBlock, true);
}
return aBlock;
}
else if (aBlock->flags & BLOCK_IS_GLOBAL) {
return aBlock;
}
// Its a stack block. Make a copy.
if (!isGC) {
struct Block_layout *result = malloc(aBlock->descriptor->size);
if (!result) return NULL;
memmove(result, aBlock, aBlock->descriptor->size); // bitcopy first
// reset refcount
result->flags &= ~(BLOCK_REFCOUNT_MASK|BLOCK_DEALLOCATING); // XXX not needed
result->flags |= BLOCK_NEEDS_FREE | 2; // logical refcount 1
result->isa = _NSConcreteMallocBlock;
_Block_call_copy_helper(result, aBlock);
return result;
}
else {
// Under GC want allocation with refcount 1 so we ask for "true" if wantsOne
// This allows the copy helper routines to make non-refcounted block copies under GC
int32_t flags = aBlock->flags;
bool hasCTOR = (flags & BLOCK_HAS_CTOR) != 0;
struct Block_layout *result = _Block_allocator(aBlock->descriptor->size, wantsOne, hasCTOR || _Block_has_layout(aBlock));
if (!result) return NULL;
memmove(result, aBlock, aBlock->descriptor->size); // bitcopy first
// reset refcount
// if we copy a malloc block to a GC block then we need to clear NEEDS_FREE.
flags &= ~(BLOCK_NEEDS_FREE|BLOCK_REFCOUNT_MASK|BLOCK_DEALLOCATING); // XXX not needed
if (wantsOne)
flags |= BLOCK_IS_GC | 2;
else
flags |= BLOCK_IS_GC;
result->flags = flags;
_Block_call_copy_helper(result, aBlock);
if (hasCTOR) {
result->isa = _NSConcreteFinalizingBlock;
}
else {
result->isa = _NSConcreteAutoBlock;
}
return result;
}
}
// Runtime entry points for maintaining the sharing knowledge of byref data blocks.
// A closure has been copied and its fixup routine is asking us to fix up the reference to the shared byref data
// Closures that aren't copied must still work, so everyone always accesses variables after dereferencing the forwarding ptr.
// We ask if the byref pointer that we know about has already been copied to the heap, and if so, increment it.
// Otherwise we need to copy it and update the stack forwarding pointer
static void _Block_byref_assign_copy(void *dest, const void *arg, const int flags) {
struct Block_byref **destp = (struct Block_byref **)dest;
struct Block_byref *src = (struct Block_byref *)arg;
if (src->forwarding->flags & BLOCK_BYREF_IS_GC) {
; // don't need to do any more work
}
else if ((src->forwarding->flags & BLOCK_REFCOUNT_MASK) == 0) {
// src points to stack
bool isWeak = ((flags & (BLOCK_FIELD_IS_BYREF|BLOCK_FIELD_IS_WEAK)) == (BLOCK_FIELD_IS_BYREF|BLOCK_FIELD_IS_WEAK));
// if its weak ask for an object (only matters under GC)
struct Block_byref *copy = (struct Block_byref *)_Block_allocator(src->size, false, isWeak);
copy->flags = src->flags | _Byref_flag_initial_value; // non-GC one for caller, one for stack
copy->forwarding = copy; // patch heap copy to point to itself (skip write-barrier)
src->forwarding = copy; // patch stack to point to heap copy
copy->size = src->size;
if (isWeak) {
copy->isa = &_NSConcreteWeakBlockVariable; // mark isa field so it gets weak scanning
}
if (src->flags & BLOCK_BYREF_HAS_COPY_DISPOSE) {
// Trust copy helper to copy everything of interest
// If more than one field shows up in a byref block this is wrong XXX
struct Block_byref_2 *src2 = (struct Block_byref_2 *)(src+1);
struct Block_byref_2 *copy2 = (struct Block_byref_2 *)(copy+1);
copy2->byref_keep = src2->byref_keep;
copy2->byref_destroy = src2->byref_destroy;
if (src->flags & BLOCK_BYREF_LAYOUT_EXTENDED) {
struct Block_byref_3 *src3 = (struct Block_byref_3 *)(src2+1);
struct Block_byref_3 *copy3 = (struct Block_byref_3*)(copy2+1);
copy3->layout = src3->layout;
}
(*src2->byref_keep)(copy, src);
}
else {
// just bits. Blast 'em using _Block_memmove in case they're __strong
// This copy includes Block_byref_3, if any.
_Block_memmove(copy+1, src+1,
src->size - sizeof(struct Block_byref));
}
}
// already copied to heap
else if ((src->forwarding->flags & BLOCK_BYREF_NEEDS_FREE) == BLOCK_BYREF_NEEDS_FREE) {
latching_incr_int(&src->forwarding->flags);
}
// assign byref data block pointer into new Block
_Block_assign(src->forwarding, (void **)destp);
}
// Old compiler SPI
static void _Block_byref_release(const void *arg) {
struct Block_byref *byref = (struct Block_byref *)arg;
int32_t refcount;
// dereference the forwarding pointer since the compiler isn't doing this anymore (ever?)
byref = byref->forwarding;
// To support C++ destructors under GC we arrange for there to be a finalizer for this
// by using an isa that directs the code to a finalizer that calls the byref_destroy method.
if ((byref->flags & BLOCK_BYREF_NEEDS_FREE) == 0) {
return; // stack or GC or global
}
refcount = byref->flags & BLOCK_REFCOUNT_MASK;
os_assert(refcount);
if (latching_decr_int_should_deallocate(&byref->flags)) {
if (byref->flags & BLOCK_BYREF_HAS_COPY_DISPOSE) {
struct Block_byref_2 *byref2 = (struct Block_byref_2 *)(byref+1);
(*byref2->byref_destroy)(byref);
}
_Block_deallocator((struct Block_layout *)byref);
}
}
/************************************************************
*
* API supporting SPI
* _Block_copy, _Block_release, and (old) _Block_destroy
*
***********************************************************/
#if !TARGET_OS_WIN32
#pragma mark SPI/API
#endif
void *_Block_copy(const void *arg) {
return _Block_copy_internal(arg, true);
}
// API entry point to release a copied Block
void _Block_release(const void *arg) {
struct Block_layout *aBlock = (struct Block_layout *)arg;
if (!aBlock
|| (aBlock->flags & BLOCK_IS_GLOBAL)
|| ((aBlock->flags & (BLOCK_IS_GC|BLOCK_NEEDS_FREE)) == 0)
) return;
if (aBlock->flags & BLOCK_IS_GC) {
if (latching_decr_int_now_zero(&aBlock->flags)) {
// Tell GC we no longer have our own refcounts. GC will decr its refcount
// and unless someone has done a CFRetain or marked it uncollectable it will
// now be subject to GC reclamation.
_Block_setHasRefcount(aBlock, false);
}
}
else if (aBlock->flags & BLOCK_NEEDS_FREE) {
if (latching_decr_int_should_deallocate(&aBlock->flags)) {
_Block_call_dispose_helper(aBlock);
_Block_destructInstance(aBlock);
_Block_deallocator(aBlock);
}
}
}
bool _Block_tryRetain(const void *arg) {
struct Block_layout *aBlock = (struct Block_layout *)arg;
return latching_incr_int_not_deallocating(&aBlock->flags);
}
bool _Block_isDeallocating(const void *arg) {
struct Block_layout *aBlock = (struct Block_layout *)arg;
return (aBlock->flags & BLOCK_DEALLOCATING) != 0;
}
// Old Compiler SPI point to release a copied Block used by the compiler in dispose helpers
static void _Block_destroy(const void *arg) {
struct Block_layout *aBlock;
if (!arg) return;
aBlock = (struct Block_layout *)arg;
if (aBlock->flags & BLOCK_IS_GC) {
// assert(aBlock->Block_flags & BLOCK_HAS_CTOR);
return; // ignore, we are being called because of a DTOR
}
_Block_release(aBlock);
}
/************************************************************
*
* SPI used by other layers
*
***********************************************************/
// SPI, also internal. Called from NSAutoBlock only under GC
void *_Block_copy_collectable(const void *aBlock) {
return _Block_copy_internal(aBlock, false);
}
// SPI
size_t Block_size(void *aBlock) {
return ((struct Block_layout *)aBlock)->descriptor->size;
}
bool _Block_use_stret(void *aBlock) {
struct Block_layout *layout = (struct Block_layout *)aBlock;
int requiredFlags = BLOCK_HAS_SIGNATURE | BLOCK_USE_STRET;
return (layout->flags & requiredFlags) == requiredFlags;
}
// Checks for a valid signature, not merely the BLOCK_HAS_SIGNATURE bit.
bool _Block_has_signature(void *aBlock) {
return _Block_signature(aBlock) ? true : false;
}
const char * _Block_signature(void *aBlock)
{
struct Block_descriptor_3 *desc3 = _Block_descriptor_3(aBlock);
if (!desc3) return NULL;
return desc3->signature;
}
const char * _Block_layout(void *aBlock)
{
// Don't return extended layout to callers expecting GC layout
struct Block_layout *layout = (struct Block_layout *)aBlock;
if (layout->flags & BLOCK_HAS_EXTENDED_LAYOUT) return NULL;
struct Block_descriptor_3 *desc3 = _Block_descriptor_3(aBlock);
if (!desc3) return NULL;
return desc3->layout;
}
const char * _Block_extended_layout(void *aBlock)
{
// Don't return GC layout to callers expecting extended layout
struct Block_layout *layout = (struct Block_layout *)aBlock;
if (! (layout->flags & BLOCK_HAS_EXTENDED_LAYOUT)) return NULL;
struct Block_descriptor_3 *desc3 = _Block_descriptor_3(aBlock);
if (!desc3) return NULL;
// Return empty string (all non-object bytes) instead of NULL
// so callers can distinguish "empty layout" from "no layout".
if (!desc3->layout) return "";
else return desc3->layout;
}
#if !TARGET_OS_WIN32
#pragma mark Compiler SPI entry points
#endif
/*******************************************************
Entry points used by the compiler - the real API!
A Block can reference four different kinds of things that require help when the Block is copied to the heap.
1) C++ stack based objects
2) References to Objective-C objects
3) Other Blocks
4) __block variables
In these cases helper functions are synthesized by the compiler for use in Block_copy and Block_release, called the copy and dispose helpers. The copy helper emits a call to the C++ const copy constructor for C++ stack based objects and for the rest calls into the runtime support function _Block_object_assign. The dispose helper has a call to the C++ destructor for case 1 and a call into _Block_object_dispose for the rest.
The flags parameter of _Block_object_assign and _Block_object_dispose is set to
* BLOCK_FIELD_IS_OBJECT (3), for the case of an Objective-C Object,
* BLOCK_FIELD_IS_BLOCK (7), for the case of another Block, and
* BLOCK_FIELD_IS_BYREF (8), for the case of a __block variable.
If the __block variable is marked weak the compiler also or's in BLOCK_FIELD_IS_WEAK (16)
So the Block copy/dispose helpers should only ever generate the four flag values of 3, 7, 8, and 24.
When a __block variable is either a C++ object, an Objective-C object, or another Block then the compiler also generates copy/dispose helper functions. Similarly to the Block copy helper, the "__block" copy helper (formerly and still a.k.a. "byref" copy helper) will do a C++ copy constructor (not a const one though!) and the dispose helper will do the destructor. And similarly the helpers will call into the same two support functions with the same values for objects and Blocks with the additional BLOCK_BYREF_CALLER (128) bit of information supplied.
So the __block copy/dispose helpers will generate flag values of 3 or 7 for objects and Blocks respectively, with BLOCK_FIELD_IS_WEAK (16) or'ed as appropriate and always 128 or'd in, for the following set of possibilities:
__block id 128+3 (0x83)
__block (^Block) 128+7 (0x87)
__weak __block id 128+3+16 (0x93)
__weak __block (^Block) 128+7+16 (0x97)
********************************************************/
//
// When Blocks or Block_byrefs hold objects then their copy routine helpers use this entry point
// to do the assignment.
//
void _Block_object_assign(void *destAddr, const void *object, const int flags) {
switch (os_assumes(flags & BLOCK_ALL_COPY_DISPOSE_FLAGS)) {
case BLOCK_FIELD_IS_OBJECT:
/*******
id object = ...;
[^{ object; } copy];
********/
_Block_retain_object(object);
_Block_assign((void *)object, destAddr);
break;
case BLOCK_FIELD_IS_BLOCK:
/*******
void (^object)(void) = ...;
[^{ object; } copy];
********/
_Block_assign(_Block_copy_internal(object, false), destAddr);
break;
case BLOCK_FIELD_IS_BYREF | BLOCK_FIELD_IS_WEAK:
case BLOCK_FIELD_IS_BYREF:
/*******
// copy the onstack __block container to the heap
__block ... x;
__weak __block ... x;
[^{ x; } copy];
********/
_Block_byref_assign_copy(destAddr, object, flags);
break;
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT:
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK:
/*******
// copy the actual field held in the __block container
__block id object;
__block void (^object)(void);
[^{ object; } copy];
********/
// under manual retain release __block object/block variables are dangling
_Block_assign((void *)object, destAddr);
break;
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT | BLOCK_FIELD_IS_WEAK:
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK | BLOCK_FIELD_IS_WEAK:
/*******
// copy the actual field held in the __block container
__weak __block id object;
__weak __block void (^object)(void);
[^{ object; } copy];
********/
_Block_assign_weak(object, destAddr);
break;
default:
break;
}
}
// When Blocks or Block_byrefs hold objects their destroy helper routines call this entry point
// to help dispose of the contents
// Used initially only for __attribute__((NSObject)) marked pointers.
void _Block_object_dispose(const void *object, const int flags) {
switch (os_assumes(flags & BLOCK_ALL_COPY_DISPOSE_FLAGS)) {
case BLOCK_FIELD_IS_BYREF | BLOCK_FIELD_IS_WEAK:
case BLOCK_FIELD_IS_BYREF:
// get rid of the __block data structure held in a Block
_Block_byref_release(object);
break;
case BLOCK_FIELD_IS_BLOCK:
_Block_destroy(object);
break;
case BLOCK_FIELD_IS_OBJECT:
_Block_release_object(object);
break;
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT:
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK:
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT | BLOCK_FIELD_IS_WEAK:
case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK | BLOCK_FIELD_IS_WEAK:
break;
default:
break;
}
}
|
7b38a30e3968925ec5a20b3bdd0c3c736de55bc7
|
82f7cf8e21b19221ee6afcc212a2dd459c5ce244
|
/backends/winmidi.c
|
649af2e0c39c1d78078135da71dc5c0a492c7926
|
[
"BSD-2-Clause"
] |
permissive
|
cbdevnet/midimonster
|
0cc375e20c95cf7b5aac3aed5e8d6d80d6307a6f
|
811592c8190d12c6c7affa5772db3be30ba941e9
|
refs/heads/master
| 2023-08-28T10:27:41.541472
| 2022-04-28T18:41:19
| 2022-04-28T18:41:19
| 93,693,951
| 415
| 52
|
BSD-2-Clause
| 2022-11-20T20:38:14
| 2017-06-08T01:13:43
|
C
|
UTF-8
|
C
| false
| false
| 20,630
|
c
|
winmidi.c
|
#define BACKEND_NAME "winmidi"
#include <string.h>
#include "libmmbackend.h"
#include <mmsystem.h>
#include "winmidi.h"
static struct {
uint8_t list_devices;
uint8_t detect;
int socket_pair[2];
CRITICAL_SECTION push_events;
volatile size_t events_alloc;
volatile size_t events_active;
volatile winmidi_event* event;
} backend_config = {
.list_devices = 0,
.socket_pair = {-1, -1}
};
//TODO receive feedback socket until EAGAIN
MM_PLUGIN_API int init(){
backend winmidi = {
.name = BACKEND_NAME,
.conf = winmidi_configure,
.create = winmidi_instance,
.conf_instance = winmidi_configure_instance,
.channel = winmidi_channel,
.handle = winmidi_set,
.process = winmidi_handle,
.start = winmidi_start,
.shutdown = winmidi_shutdown
};
if(sizeof(winmidi_channel_ident) != sizeof(uint64_t)){
LOG("Channel identification union out of bounds");
return 1;
}
//register backend
if(mm_backend_register(winmidi)){
LOG("Failed to register backend");
return 1;
}
//initialize critical section
InitializeCriticalSectionAndSpinCount(&backend_config.push_events, 4000);
return 0;
}
static int winmidi_configure(char* option, char* value){
if(!strcmp(option, "list")){
backend_config.list_devices = 0;
if(!strcmp(value, "on")){
backend_config.list_devices = 1;
}
return 0;
}
else if(!strcmp(option, "detect")){
backend_config.detect = 0;
if(!strcmp(value, "on")){
backend_config.detect = 1;
}
return 0;
}
LOGPF("Unknown backend option %s", option);
return 1;
}
static int winmidi_configure_instance(instance* inst, char* option, char* value){
winmidi_instance_data* data = (winmidi_instance_data*) inst->impl;
if(!strcmp(option, "read") || !strcmp(option, "source")){
if(data->read){
LOGPF("Instance %s already connected to an input device", inst->name);
return 1;
}
data->read = strdup(value);
return 0;
}
else if(!strcmp(option, "write") || !strcmp(option, "target")){
if(data->write){
LOGPF("Instance %s already connected to an output device", inst->name);
return 1;
}
data->write = strdup(value);
return 0;
}
else if(!strcmp(option, "epn-tx")){
data->epn_tx_short = 0;
if(!strcmp(value, "short")){
data->epn_tx_short = 1;
}
return 0;
}
LOGPF("Unknown instance configuration option %s on instance %s", option, inst->name);
return 1;
}
static int winmidi_instance(instance* inst){
inst->impl = calloc(1, sizeof(winmidi_instance_data));
if(!inst->impl){
LOG("Failed to allocate memory");
return 1;
}
return 0;
}
static channel* winmidi_channel(instance* inst, char* spec, uint8_t flags){
char* next_token = NULL;
winmidi_channel_ident ident = {
.label = 0
};
if(!strncmp(spec, "ch", 2)){
next_token = spec + 2;
if(!strncmp(spec, "channel", 7)){
next_token = spec + 7;
}
}
if(!next_token){
LOGPF("Invalid channel specification %s", spec);
return NULL;
}
ident.fields.channel = strtoul(next_token, &next_token, 10);
if(ident.fields.channel > 15){
LOGPF("MIDI channel out of range in spec %s", spec);
return NULL;
}
if(*next_token != '.'){
LOGPF("Channel specification %s does not conform to channel<X>.<control><Y>", spec);
return NULL;
}
next_token++;
if(!strncmp(next_token, "cc", 2)){
ident.fields.type = cc;
next_token += 2;
}
else if(!strncmp(next_token, "note", 4)){
ident.fields.type = note;
next_token += 4;
}
else if(!strncmp(next_token, "pressure", 8)){
ident.fields.type = pressure;
next_token += 8;
}
else if(!strncmp(next_token, "rpn", 3)){
ident.fields.type = rpn;
next_token += 3;
}
else if(!strncmp(next_token, "nrpn", 4)){
ident.fields.type = nrpn;
next_token += 4;
}
else if(!strncmp(next_token, "pitch", 5)){
ident.fields.type = pitchbend;
}
else if(!strncmp(next_token, "aftertouch", 10)){
ident.fields.type = aftertouch;
}
else if(!strncmp(next_token, "program", 7)){
ident.fields.type = program;
}
else{
LOGPF("Unknown control type in %s", spec);
return NULL;
}
ident.fields.control = strtoul(next_token, NULL, 10);
if(ident.label){
return mm_channel(inst, ident.label, 1);
}
return NULL;
}
static void winmidi_tx(HMIDIOUT port, uint8_t type, uint8_t channel, uint8_t control, uint16_t value){
union {
struct {
uint8_t status;
uint8_t data1;
uint8_t data2;
uint8_t unused;
} components;
DWORD dword;
} output = {
.dword = 0
};
output.components.status = type | channel;
output.components.data1 = control;
output.components.data2 = value & 0x7F;
if(type == pitchbend){
output.components.data1 = value & 0x7F;
output.components.data2 = (value >> 7) & 0x7F;
}
else if(type == aftertouch || type == program){
output.components.data1 = value;
output.components.data2 = 0;
}
midiOutShortMsg(port, output.dword);
}
static int winmidi_set(instance* inst, size_t num, channel** c, channel_value* v){
winmidi_instance_data* data = (winmidi_instance_data*) inst->impl;
winmidi_channel_ident ident = {
.label = 0
};
size_t u;
if(!data->device_out){
LOGPF("Instance %s has no output device", inst->name);
return 0;
}
for(u = 0; u < num; u++){
ident.label = c[u]->ident;
switch(ident.fields.type){
case rpn:
case nrpn:
//transmit parameter number
winmidi_tx(data->device_out, cc, ident.fields.channel, (ident.fields.type == rpn) ? 101 : 99, (ident.fields.control >> 7) & 0x7F);
winmidi_tx(data->device_out, cc, ident.fields.channel, (ident.fields.type == rpn) ? 100 : 98, ident.fields.control & 0x7F);
//transmit parameter value
winmidi_tx(data->device_out, cc, ident.fields.channel, 6, (((uint16_t) (v[u].normalised * 16383.0)) >> 7) & 0x7F);
winmidi_tx(data->device_out, cc, ident.fields.channel, 38, ((uint16_t) (v[u].normalised * 16383.0)) & 0x7F);
if(!data->epn_tx_short){
//clear active parameter
winmidi_tx(data->device_out, cc, ident.fields.channel, 101, 127);
winmidi_tx(data->device_out, cc, ident.fields.channel, 100, 127);
}
break;
case pitchbend:
winmidi_tx(data->device_out, ident.fields.type, ident.fields.channel, ident.fields.control, v[u].normalised * 16383.0);
break;
default:
winmidi_tx(data->device_out, ident.fields.type, ident.fields.channel, ident.fields.control, v[u].normalised * 127.0);
}
}
return 0;
}
static char* winmidi_type_name(uint8_t typecode){
switch(typecode){
case note:
return "note";
case cc:
return "cc";
case rpn:
return "rpn";
case nrpn:
return "nrpn";
case pressure:
return "pressure";
case aftertouch:
return "aftertouch";
case pitchbend:
return "pitch";
case program:
return "program";
}
return "unknown";
}
static int winmidi_handle(size_t num, managed_fd* fds){
size_t u;
ssize_t bytes = 0;
char recv_buf[1024];
channel* chan = NULL;
if(!num){
return 0;
}
//flush the feedback socket
for(u = 0; u < num; u++){
bytes += recv(fds[u].fd, recv_buf, sizeof(recv_buf), 0);
}
//push queued events
EnterCriticalSection(&backend_config.push_events);
for(u = 0; u < backend_config.events_active; u++){
if(backend_config.detect){
//pretty-print channel-wide events
if(backend_config.event[u].channel.fields.type == pitchbend
|| backend_config.event[u].channel.fields.type == aftertouch
|| backend_config.event[u].channel.fields.type == program){
LOGPF("Incoming data on channel %s.ch%d.%s, value %f",
backend_config.event[u].inst->name,
backend_config.event[u].channel.fields.channel,
winmidi_type_name(backend_config.event[u].channel.fields.type),
backend_config.event[u].value.normalised);
}
else{
LOGPF("Incoming data on channel %s.ch%d.%s%d, value %f",
backend_config.event[u].inst->name,
backend_config.event[u].channel.fields.channel,
winmidi_type_name(backend_config.event[u].channel.fields.type),
backend_config.event[u].channel.fields.control,
backend_config.event[u].value.normalised);
}
}
chan = mm_channel(backend_config.event[u].inst, backend_config.event[u].channel.label, 0);
if(chan){
mm_channel_event(chan, backend_config.event[u].value);
}
}
DBGPF("Flushed %" PRIsize_t " wakeups, handled %" PRIsize_t " events", bytes, backend_config.events_active);
backend_config.events_active = 0;
LeaveCriticalSection(&backend_config.push_events);
return 0;
}
static int winmidi_enqueue_input(instance* inst, winmidi_channel_ident ident, channel_value val){
EnterCriticalSection(&backend_config.push_events);
if(backend_config.events_alloc <= backend_config.events_active){
backend_config.event = realloc((void*) backend_config.event, (backend_config.events_alloc + 1) * sizeof(winmidi_event));
if(!backend_config.event){
LOG("Failed to allocate memory");
backend_config.events_alloc = 0;
backend_config.events_active = 0;
LeaveCriticalSection(&backend_config.push_events);
return 1;
}
backend_config.events_alloc++;
}
backend_config.event[backend_config.events_active].inst = inst;
backend_config.event[backend_config.events_active].channel.label = ident.label;
backend_config.event[backend_config.events_active].value = val;
backend_config.events_active++;
LeaveCriticalSection(&backend_config.push_events);
return 0;
}
//this state machine was copied more-or-less verbatim from the alsa midi implementation - fixes there will need to be integrated
static void winmidi_handle_epn(instance* inst, uint8_t chan, uint16_t control, uint16_t value){
winmidi_instance_data* data = (winmidi_instance_data*) inst->impl;
winmidi_channel_ident ident = {
.label = 0
};
channel_value val;
//switching between nrpn and rpn clears all valid bits
if(((data->epn_status[chan] & EPN_NRPN) && (control == 101 || control == 100))
|| (!(data->epn_status[chan] & EPN_NRPN) && (control == 99 || control == 98))){
data->epn_status[chan] &= ~(EPN_NRPN | EPN_PARAMETER_LO | EPN_PARAMETER_HI);
}
//setting an address always invalidates the value valid bits
if(control >= 98 && control <= 101){
data->epn_status[chan] &= ~EPN_VALUE_HI;
}
//parameter hi
if(control == 101 || control == 99){
data->epn_control[chan] &= 0x7F;
data->epn_control[chan] |= value << 7;
data->epn_status[chan] |= EPN_PARAMETER_HI | ((control == 99) ? EPN_NRPN : 0);
if(control == 101 && value == 127){
data->epn_status[chan] &= ~EPN_PARAMETER_HI;
}
}
//parameter lo
if(control == 100 || control == 98){
data->epn_control[chan] &= ~0x7F;
data->epn_control[chan] |= value & 0x7F;
data->epn_status[chan] |= EPN_PARAMETER_LO | ((control == 98) ? EPN_NRPN : 0);
if(control == 100 && value == 127){
data->epn_status[chan] &= ~EPN_PARAMETER_LO;
}
}
//value hi, clears low, mark as update candidate
if(control == 6
//check if parameter is set before accepting value update
&& ((data->epn_status[chan] & (EPN_PARAMETER_HI | EPN_PARAMETER_LO)) == (EPN_PARAMETER_HI | EPN_PARAMETER_LO))){
data->epn_value[chan] = value << 7;
data->epn_status[chan] |= EPN_VALUE_HI;
}
//value lo, flush the value
if(control == 38
&& data->epn_status[chan] & EPN_VALUE_HI){
data->epn_value[chan] &= ~0x7F;
data->epn_value[chan] |= value & 0x7F;
data->epn_status[chan] &= ~EPN_VALUE_HI;
//find the updated channel
ident.fields.type = data->epn_status[chan] & EPN_NRPN ? nrpn : rpn;
ident.fields.channel = chan;
ident.fields.control = data->epn_control[chan];
val.normalised = (double) data->epn_value[chan] / 16383.0;
winmidi_enqueue_input(inst, ident, val);
}
}
static void CALLBACK winmidi_input_callback(HMIDIIN device, unsigned message, DWORD_PTR inst, DWORD param1, DWORD param2){
winmidi_channel_ident ident = {
.label = 0
};
channel_value val = {
0
};
union {
struct {
uint8_t status;
uint8_t data1;
uint8_t data2;
uint8_t unused;
} components;
DWORD dword;
} input = {
.dword = 0
};
//callbacks may run on different threads, so we queue all events and alert the main thread via the feedback socket
DBGPF("Input callback on thread %ld", GetCurrentThreadId());
switch(message){
case MIM_MOREDATA:
//processing too slow, do not immediately alert the main loop
case MIM_DATA:
//param1 has the message
input.dword = param1;
ident.fields.channel = input.components.status & 0x0F;
ident.fields.type = input.components.status & 0xF0;
ident.fields.control = input.components.data1;
val.normalised = (double) input.components.data2 / 127.0;
val.raw.u64 = input.components.data2;
if(ident.fields.type == 0x80){
ident.fields.type = note;
val.normalised = 0;
val.raw.u64 = 0;
}
else if(ident.fields.type == pitchbend){
ident.fields.control = 0;
val.normalised = (double) ((input.components.data2 << 7) | input.components.data1) / 16383.0;
val.raw.u64 = input.components.data2 << 7 | input.components.data1;
}
else if(ident.fields.type == aftertouch || ident.fields.type == program){
ident.fields.control = 0;
val.normalised = (double) input.components.data1 / 127.0;
val.raw.u64 = input.components.data1;
}
break;
case MIM_LONGDATA:
//sysex message, ignore
return;
case MIM_ERROR:
//error in input stream
LOG("Error in input stream");
return;
case MIM_OPEN:
case MIM_CLOSE:
//device opened/closed
return;
}
//pass changes in the (n)rpn CCs to the EPN state machine
if(ident.fields.type == cc
&& ((ident.fields.control <= 101 && ident.fields.control >= 98)
|| ident.fields.control == 6
|| ident.fields.control == 38)){
winmidi_handle_epn((instance*) inst, ident.fields.channel, ident.fields.control, val.raw.u64);
}
DBGPF("Incoming message type %d channel %d control %d value %f",
ident.fields.type, ident.fields.channel, ident.fields.control, val.normalised);
if(winmidi_enqueue_input((instance*) inst, ident, val)){
LOG("Failed to enqueue incoming data");
}
if(message != MIM_MOREDATA){
//alert the main loop
send(backend_config.socket_pair[1], "w", 1, 0);
}
}
static void CALLBACK winmidi_output_callback(HMIDIOUT device, unsigned message, DWORD_PTR inst, DWORD param1, DWORD param2){
DBGPF("Output callback on thread %ld", GetCurrentThreadId());
}
static int winmidi_match_input(char* prefix){
MIDIINCAPS input_caps;
unsigned inputs = midiInGetNumDevs();
char* next_token = NULL;
size_t n;
if(!prefix){
LOGPF("Detected %u input devices", inputs);
}
else{
n = strtoul(prefix, &next_token, 10);
if(!(*next_token) && n < inputs){
midiInGetDevCaps(n, &input_caps, sizeof(MIDIINCAPS));
LOGPF("Selected input device %s for ID %d", input_caps.szPname, n);
return n;
}
}
//find prefix match for input device
for(n = 0; n < inputs; n++){
midiInGetDevCaps(n, &input_caps, sizeof(MIDIINCAPS));
if(!prefix){
LOGPF("\tID %d: %s", n, input_caps.szPname);
}
else if(!strncmp(input_caps.szPname, prefix, strlen(prefix))){
LOGPF("Selected input device %s (ID %" PRIsize_t ") for name %s", input_caps.szPname, n, prefix);
return n;
}
}
return -1;
}
static int winmidi_match_output(char* prefix){
MIDIOUTCAPS output_caps;
unsigned outputs = midiOutGetNumDevs();
char* next_token = NULL;
size_t n;
if(!prefix){
LOGPF("Detected %u output devices", outputs);
}
else{
n = strtoul(prefix, &next_token, 10);
if(!(*next_token) && n < outputs){
midiOutGetDevCaps(n, &output_caps, sizeof(MIDIOUTCAPS));
LOGPF("Selected output device %s for ID %d", output_caps.szPname, n);
return n;
}
}
//find prefix match for output device
for(n = 0; n < outputs; n++){
midiOutGetDevCaps(n, &output_caps, sizeof(MIDIOUTCAPS));
if(!prefix){
LOGPF("\tID %d: %s", n, output_caps.szPname);
}
else if(!strncmp(output_caps.szPname, prefix, strlen(prefix))){
LOGPF("Selected output device %s (ID %" PRIsize_t " for name %s", output_caps.szPname, n, prefix);
return n;
}
}
return -1;
}
static int winmidi_socket_pair(int* fds){
//this really should be a size_t but getsockname specifies int* for some reason
int sockadd_len = sizeof(struct sockaddr_storage);
char* error = NULL;
struct sockaddr_storage sockadd = {
0
};
//for some reason the feedback connection fails to work on 'real' windows with ipv6
fds[0] = mmbackend_socket("127.0.0.1", "0", SOCK_DGRAM, 1, 0, 0);
if(fds[0] < 0){
LOG("Failed to open feedback socket");
return 1;
}
if(getsockname(fds[0], (struct sockaddr*) &sockadd, &sockadd_len)){
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
LOGPF("Failed to query feedback socket information: %s", error);
LocalFree(error);
return 1;
}
//getsockname on 'real' windows may not set the address - works on wine, though
switch(sockadd.ss_family){
case AF_INET:
case AF_INET6:
((struct sockaddr_in*) &sockadd)->sin_family = AF_INET;
((struct sockaddr_in*) &sockadd)->sin_addr.s_addr = htobe32(INADDR_LOOPBACK);
break;
//for some absurd reason 'real' windows announces the socket as AF_INET6 but rejects any connection unless its AF_INET
// case AF_INET6:
// ((struct sockaddr_in6*) &sockadd)->sin6_addr = in6addr_any;
// break;
default:
LOG("Invalid feedback socket family");
return 1;
}
DBGPF("Feedback socket family %d port %d", sockadd.ss_family, be16toh(((struct sockaddr_in*)&sockadd)->sin_port));
fds[1] = socket(sockadd.ss_family, SOCK_DGRAM, IPPROTO_UDP);
if(fds[1] < 0 || connect(backend_config.socket_pair[1], (struct sockaddr*) &sockadd, sockadd_len)){
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
LOGPF("Failed to connect to feedback socket: %s", error);
LocalFree(error);
return 1;
}
return 0;
}
static int winmidi_start(size_t n, instance** inst){
size_t p;
int device, rv = -1;
winmidi_instance_data* data = NULL;
DBGPF("Main thread ID is %ld", GetCurrentThreadId());
//output device list if requested
if(backend_config.list_devices){
winmidi_match_input(NULL);
winmidi_match_output(NULL);
}
//open the feedback sockets
if(winmidi_socket_pair(backend_config.socket_pair)){
return 1;
}
//set up instances and start input
for(p = 0; p < n; p++){
data = (winmidi_instance_data*) inst[p]->impl;
inst[p]->ident = p;
//connect input device if requested
if(data->read){
device = winmidi_match_input(data->read);
if(device < 0){
LOGPF("Failed to match input device %s for instance %s", data->read, inst[p]->name);
goto bail;
}
if(midiInOpen(&(data->device_in), device, (DWORD_PTR) winmidi_input_callback, (DWORD_PTR) inst[p], CALLBACK_FUNCTION | MIDI_IO_STATUS) != MMSYSERR_NOERROR){
LOGPF("Failed to open input device for instance %s", inst[p]->name);
goto bail;
}
//start midi input callbacks
midiInStart(data->device_in);
}
//connect output device if requested
if(data->write){
device = winmidi_match_output(data->write);
if(device < 0){
LOGPF("Failed to match output device %s for instance %s", data->read, inst[p]->name);
goto bail;
}
if(midiOutOpen(&(data->device_out), device, (DWORD_PTR) winmidi_output_callback, (DWORD_PTR) inst[p], CALLBACK_FUNCTION) != MMSYSERR_NOERROR){
LOGPF("Failed to open output device for instance %s", inst[p]->name);
goto bail;
}
}
}
//register the feedback socket to the core
LOG("Registering 1 descriptor to core");
if(mm_manage_fd(backend_config.socket_pair[0], BACKEND_NAME, 1, NULL)){
goto bail;
}
rv = 0;
bail:
return rv;
}
static int winmidi_shutdown(size_t n, instance** inst){
size_t u;
winmidi_instance_data* data = NULL;
for(u = 0; u < n; u++){
data = (winmidi_instance_data*) inst[u]->impl;
free(data->read);
data->read = NULL;
free(data->write);
data->write = NULL;
if(data->device_in){
midiInStop(data->device_in);
midiInClose(data->device_in);
data->device_in = NULL;
}
if(data->device_out){
midiOutReset(data->device_out);
midiOutClose(data->device_out);
data->device_out = NULL;
}
free(inst[u]->impl);
}
closesocket(backend_config.socket_pair[0]);
closesocket(backend_config.socket_pair[1]);
EnterCriticalSection(&backend_config.push_events);
free((void*) backend_config.event);
backend_config.event = NULL;
backend_config.events_alloc = 0;
backend_config.events_active = 0;
LeaveCriticalSection(&backend_config.push_events);
DeleteCriticalSection(&backend_config.push_events);
LOG("Backend shut down");
return 0;
}
|
d0fed8d1b43197e0b67cda321aeb2242fb916a4c
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/drivers/sensors/mpl115a.c
|
82198c24a016e2fd9a2cdc43aada888b03ba4f63
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 11,940
|
c
|
mpl115a.c
|
/****************************************************************************
* drivers/sensors/mpl115a.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* Character driver for the Freescale MPL115A1 Barometer Sensor */
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <fixedmath.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>
#include <nuttx/random.h>
#include <nuttx/fs/fs.h>
#include <nuttx/spi/spi.h>
#include <nuttx/sensors/mpl115a.h>
#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_MPL115A)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private
****************************************************************************/
struct mpl115a_dev_s
{
FAR struct spi_dev_s *spi; /* SPI interface */
int16_t mpl115a_cal_a0;
int16_t mpl115a_cal_b1;
int16_t mpl115a_cal_b2;
int16_t mpl115a_cal_c12;
uint16_t mpl115a_temperature;
uint16_t mpl115a_pressure;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static inline void mpl115a_configspi(FAR struct spi_dev_s *spi);
static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv,
uint8_t regaddr);
static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv);
static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv);
static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv);
/* Character driver methods */
static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct file_operations g_mpl115afops =
{
NULL, /* open */
NULL, /* close */
mpl115a_read, /* read */
mpl115a_write, /* write */
};
/****************************************************************************
* Private Functions
****************************************************************************/
static inline void mpl115a_configspi(FAR struct spi_dev_s *spi)
{
/* Configure SPI for the MPL115A */
SPI_SETMODE(spi, SPIDEV_MODE0);
SPI_SETBITS(spi, 8);
SPI_HWFEATURES(spi, 0);
SPI_SETFREQUENCY(spi, MPL115A_SPI_MAXFREQUENCY);
}
/****************************************************************************
* Name: mpl115a_getreg8
*
* Description:
* Read from an 8-bit MPL115A register
*
****************************************************************************/
static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv,
uint8_t regaddr)
{
uint8_t regval;
/* If SPI bus is shared then lock and configure it */
SPI_LOCK(priv->spi, true);
mpl115a_configspi(priv->spi);
/* Select the MPL115A */
SPI_SELECT(priv->spi, SPIDEV_BAROMETER(0), true);
/* Send register to read and get the next byte */
SPI_SEND(priv->spi, regaddr);
SPI_RECVBLOCK(priv->spi, ®val, 1);
/* Deselect the MPL115A */
SPI_SELECT(priv->spi, SPIDEV_BAROMETER(0), false);
/* Unlock bus */
SPI_LOCK(priv->spi, false);
#ifdef CONFIG_MPL115A_REGDEBUG
_err("%02x->%02x\n", regaddr, regval);
#endif
return regval;
}
/****************************************************************************
* Name: mpl115a_updatecaldata
*
* Description:
* Update Calibration Coefficient Data
*
****************************************************************************/
static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv)
{
/* Get a0 coefficient */
priv->mpl115a_cal_a0 =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_MSB << 1)) << 8;
priv->mpl115a_cal_a0 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_LSB << 1));
sninfo("a0 = %d\n", priv->mpl115a_cal_a0);
/* Get b1 coefficient */
priv->mpl115a_cal_b1 =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_MSB << 1)) << 8;
priv->mpl115a_cal_b1 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_LSB << 1));
sninfo("b1 = %d\n", priv->mpl115a_cal_b1);
/* Get b2 coefficient */
priv->mpl115a_cal_b2 =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_MSB << 1)) << 8;
priv->mpl115a_cal_b2 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_LSB << 1));
sninfo("b2 = %d\n", priv->mpl115a_cal_b2);
/* Get c12 coefficient */
priv->mpl115a_cal_c12 =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_MSB << 1)) << 8;
priv->mpl115a_cal_c12 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_LSB << 1));
sninfo("c12 = %d\n", priv->mpl115a_cal_c12);
}
/****************************************************************************
* Name: mpl115a_read_press_temp
*
* Description:
* Read raw pressure and temperature from MPL115A and store it in the
* mpl115a_dev_s structure.
*
****************************************************************************/
static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv)
{
/* Start a new conversion */
mpl115a_getreg8(priv, (MPL115A_CONVERT << 1));
/* Delay 5ms */
nxsig_usleep(5000);
priv->mpl115a_pressure =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_MSB << 1)) << 8;
priv->mpl115a_pressure |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_LSB << 1));
priv->mpl115a_pressure >>= 6; /* Padc is 10bit unsigned */
sninfo("Pressure = %d\n", priv->mpl115a_pressure);
priv->mpl115a_temperature =
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_MSB << 1)) << 8;
priv->mpl115a_temperature |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_LSB << 1));
priv->mpl115a_temperature >>= 6; /* Tadc is 10bit unsigned */
sninfo("Temperature = %d\n", priv->mpl115a_temperature);
/* Feed sensor data to entropy pool */
add_sensor_randomness((priv->mpl115a_pressure << 16) ^
priv->mpl115a_temperature);
}
/****************************************************************************
* Name: mpl115a_getpressure
*
* Description:
* Calculate the Barometric Pressure using the temperature compensated
* See Freescale AN3785 and MPL115A1 data sheet for details
*
****************************************************************************/
static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv)
{
int32_t c12x2;
int32_t a1;
int32_t a1x1;
int32_t y1;
int32_t a2x2;
int32_t pcomp;
uint16_t padc;
uint16_t tadc;
uint16_t pressure;
/* Check if coefficient data were read correctly */
if ((priv->mpl115a_cal_a0 == 0) || (priv->mpl115a_cal_b1 == 0) ||
(priv->mpl115a_cal_b2 == 0) || (priv->mpl115a_cal_c12 == 0))
{
mpl115a_updatecaldata(priv);
}
/* Read temperature and pressure */
mpl115a_read_press_temp(priv);
padc = priv->mpl115a_pressure;
tadc = priv->mpl115a_temperature;
/* These code are from Freescale AN3785 */
c12x2 = ((int32_t)priv->mpl115a_cal_c12 * tadc) >> 11;
a1 = (int32_t) (priv->mpl115a_cal_b1 + c12x2);
a1x1 = a1 * padc;
y1 = (((int32_t)priv->mpl115a_cal_a0) << 10) + a1x1;
a2x2 = (((int32_t)priv->mpl115a_cal_b2) * tadc) >> 1;
pcomp = (y1 + a2x2) >> 9;
/* Calculate the pressure in 1/16 kPa from compensated */
pressure = (((((int32_t)pcomp) * 1041) >> 14) + 800);
/* Note that the final pressure value is reported with 4 bit fractional
* This may be eliminated by right shifting the result 4 bits.
*/
sninfo("Final Pressure = %d\n", pressure >> 4);
return pressure;
}
/****************************************************************************
* Name: mpl115a_read
****************************************************************************/
static ssize_t mpl115a_read(FAR struct file *filep,
FAR char *buffer, size_t buflen)
{
FAR struct inode *inode = filep->f_inode;
FAR struct mpl115a_dev_s *priv = inode->i_private;
FAR uint16_t *press = (FAR uint16_t *) buffer;
if (!buffer)
{
snerr("ERROR: Buffer is null\n");
return -1;
}
if (buflen != 2)
{
snerr("ERROR:");
snerr(" You can't read something other than 16 bits (2 bytes)\n");
return -1;
}
/* Get the pressure compensated */
*press = mpl115a_getpressure(priv);
/* Return size of uint16_t (2 bytes) */
return 2;
}
/****************************************************************************
* Name: mpl115a_write
****************************************************************************/
static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen)
{
return -ENOSYS;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mpl115a_register
*
* Description:
* Register the MPL115A character device as 'devpath'
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* i2c - An instance of the I2C interface to use to communicate with
* MPL115A
* addr - The I2C address of the LM-75. The base I2C address of the
* MPL115A is 0x48. Bits 0-3 can be controlled to get 8 unique
* addresses from 0x48 through 0x4f.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int mpl115a_register(FAR const char *devpath, FAR struct spi_dev_s *spi)
{
FAR struct mpl115a_dev_s *priv;
int ret;
/* Initialize the MPL115A device structure */
priv = (FAR struct mpl115a_dev_s *)
kmm_malloc(sizeof(struct mpl115a_dev_s));
if (!priv)
{
snerr("ERROR: Failed to allocate instance\n");
return -ENOMEM;
}
priv->spi = spi;
priv->mpl115a_cal_a0 = 0;
priv->mpl115a_cal_b1 = 0;
priv->mpl115a_cal_b2 = 0;
priv->mpl115a_cal_c12 = 0;
/* Read the coefficient value */
mpl115a_updatecaldata(priv);
/* Register the character driver */
ret = register_driver(devpath, &g_mpl115afops, 0666, priv);
if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
}
return ret;
}
#endif /* CONFIG_SPI && CONFIG_SENSORS_MPL115A */
|
601d0cffb3325b9f12d4d9ce97e9675d42294567
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/include/any-linux-any/linux/spi/spidev.h
|
e7aa4773ea17c29770cb091d396f4800ec7b2189
|
[
"MIT"
] |
permissive
|
ziglang/zig
|
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
|
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
|
refs/heads/master
| 2023-08-31T13:16:45.980913
| 2023-08-31T05:50:29
| 2023-08-31T05:50:29
| 40,276,274
| 25,560
| 2,399
|
MIT
| 2023-09-14T21:09:50
| 2015-08-06T00:51:28
|
Zig
|
UTF-8
|
C
| false
| false
| 4,693
|
h
|
spidev.h
|
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
/*
* include/linux/spi/spidev.h
*
* Copyright (C) 2006 SWAPP
* Andrea Paterniani <a.paterniani@swapp-eng.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SPIDEV_H
#define SPIDEV_H
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/spi/spi.h>
/* IOCTL commands */
#define SPI_IOC_MAGIC 'k'
/**
* struct spi_ioc_transfer - describes a single SPI transfer
* @tx_buf: Holds pointer to userspace buffer with transmit data, or null.
* If no data is provided, zeroes are shifted out.
* @rx_buf: Holds pointer to userspace buffer for receive data, or null.
* @len: Length of tx and rx buffers, in bytes.
* @speed_hz: Temporary override of the device's bitrate.
* @bits_per_word: Temporary override of the device's wordsize.
* @delay_usecs: If nonzero, how long to delay after the last bit transfer
* before optionally deselecting the device before the next transfer.
* @cs_change: True to deselect device before starting the next transfer.
* @word_delay_usecs: If nonzero, how long to wait between words within one
* transfer. This property needs explicit support in the SPI controller,
* otherwise it is silently ignored.
*
* This structure is mapped directly to the kernel spi_transfer structure;
* the fields have the same meanings, except of course that the pointers
* are in a different address space (and may be of different sizes in some
* cases, such as 32-bit i386 userspace over a 64-bit x86_64 kernel).
* Zero-initialize the structure, including currently unused fields, to
* accommodate potential future updates.
*
* SPI_IOC_MESSAGE gives userspace the equivalent of kernel spi_sync().
* Pass it an array of related transfers, they'll execute together.
* Each transfer may be half duplex (either direction) or full duplex.
*
* struct spi_ioc_transfer mesg[4];
* ...
* status = ioctl(fd, SPI_IOC_MESSAGE(4), mesg);
*
* So for example one transfer might send a nine bit command (right aligned
* in a 16-bit word), the next could read a block of 8-bit data before
* terminating that command by temporarily deselecting the chip; the next
* could send a different nine bit command (re-selecting the chip), and the
* last transfer might write some register values.
*/
struct spi_ioc_transfer {
__u64 tx_buf;
__u64 rx_buf;
__u32 len;
__u32 speed_hz;
__u16 delay_usecs;
__u8 bits_per_word;
__u8 cs_change;
__u8 tx_nbits;
__u8 rx_nbits;
__u8 word_delay_usecs;
__u8 pad;
/* If the contents of 'struct spi_ioc_transfer' ever change
* incompatibly, then the ioctl number (currently 0) must change;
* ioctls with constant size fields get a bit more in the way of
* error checking than ones (like this) where that field varies.
*
* NOTE: struct layout is the same in 64bit and 32bit userspace.
*/
};
/* not all platforms use <asm-generic/ioctl.h> or _IOC_TYPECHECK() ... */
#define SPI_MSGSIZE(N) \
((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
/* Read / Write of SPI mode (SPI_MODE_0..SPI_MODE_3) (limited to 8 bits) */
#define SPI_IOC_RD_MODE _IOR(SPI_IOC_MAGIC, 1, __u8)
#define SPI_IOC_WR_MODE _IOW(SPI_IOC_MAGIC, 1, __u8)
/* Read / Write SPI bit justification */
#define SPI_IOC_RD_LSB_FIRST _IOR(SPI_IOC_MAGIC, 2, __u8)
#define SPI_IOC_WR_LSB_FIRST _IOW(SPI_IOC_MAGIC, 2, __u8)
/* Read / Write SPI device word length (1..N) */
#define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8)
#define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8)
/* Read / Write SPI device default max speed hz */
#define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32)
#define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32)
/* Read / Write of the SPI mode field */
#define SPI_IOC_RD_MODE32 _IOR(SPI_IOC_MAGIC, 5, __u32)
#define SPI_IOC_WR_MODE32 _IOW(SPI_IOC_MAGIC, 5, __u32)
#endif /* SPIDEV_H */
|
818452876e377c92ac18a44859134e012bb79fb7
|
3b2f6a98860ef1252d7e2188cb1330490764055c
|
/source/images/icon_SMS.h
|
bd691043189d7e2e33f44e13ba027a9c24a03b5f
|
[
"Apache-2.0"
] |
permissive
|
Sterophonick/SimpleLight
|
3d9b36e32b15acb529962c7b4a842d0a0d468199
|
f7783a9b8e6be1096f41ad824f590810e73bbf91
|
refs/heads/master
| 2022-06-21T19:49:08.043526
| 2022-06-21T17:27:58
| 2022-06-21T17:27:58
| 208,100,354
| 112
| 28
|
Apache-2.0
| 2022-06-17T18:13:27
| 2019-09-12T16:53:12
|
C
|
UTF-8
|
C
| false
| false
| 2,136
|
h
|
icon_SMS.h
|
//{{BLOCK(gImage_icon_SMS)
//======================================================================
//
// gImage_icon_SMS, 16x14@16,
// + bitmap not compressed
// Total size: 448 = 448
//
// Time-stamp: 2019-11-19, 10:37:59
// Exported by Cearn's GBA Image Transmogrifier, v0.8.3
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================
const unsigned short gImage_icon_SMS[224] __attribute__((aligned(4)))=
{
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0421,0x0421,0x0421,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0421,0x20E7,0x2D6B,0x4A72,0x0421,0x0421,
0x0421,0x0421,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0421,0x1CE7,0x2D6B,0x39AD,0x35AD,0x2529,0x2107,
0x2508,0x39CD,0x0421,0x0421,0x0421,0x0421,0x0000,0x0000,
0x0421,0x1CE6,0x1CE6,0x1CE7,0x1CE6,0x1CE6,0x318C,0x20E5,
0x1090,0x1090,0x1CEF,0x18AE,0x18CD,0x2D6A,0x0421,0x0421,
0x0421,0x14A7,0x1CE9,0x1CE9,0x1CE9,0x20E7,0x1CE6,0x18CB,
0x35BB,0x4638,0x0857,0x1CF4,0x14AF,0x2507,0x18C6,0x0421,
0x0421,0x14A4,0x1084,0x18C5,0x20E7,0x20E9,0x1CE8,0x18CD,
0x1095,0x0C78,0x10BB,0x4A59,0x14B1,0x2527,0x18C6,0x0421,
0x0000,0x0421,0x0421,0x0421,0x0421,0x14A4,0x1063,0x14A4,
0x20E5,0x14A4,0x20E8,0x14B0,0x1CE7,0x2529,0x0421,0x0421,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0421,0x0421,0x0421,
0x4210,0x20E7,0x0841,0x14A3,0x1CC6,0x20E8,0x41EF,0x0421,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0421,0x0421,0x0421,0x0421,0x0421,0x18C6,0x0421,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0421,0x0421,0x0421,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
};
//}}BLOCK(gImage_icon_SMS)
|
ff5f7494d700123c1a64f9500c45e4586fa6dfac
|
2d11442aa09b51e10c245ee2b64231aeb051744f
|
/platforms/Mac OS/vm/sqMacEncoding.h
|
b6e5d2210d7e030dcf8727607d041639475fd940
|
[
"MIT"
] |
permissive
|
OpenSmalltalk/opensmalltalk-vm
|
622b01c10017a93fdff4f1ef2188c45342384c78
|
330d6779ad2ecbce1f07131f53d75cd168165f0b
|
refs/heads/Cog
| 2023-09-04T05:36:54.320281
| 2023-08-17T11:32:52
| 2023-08-31T12:26:44
| 59,481,716
| 556
| 153
|
NOASSERTION
| 2023-06-19T19:58:13
| 2016-05-23T12:40:27
|
C
|
UTF-8
|
C
| false
| false
| 898
|
h
|
sqMacEncoding.h
|
/*
* sqMacEncoding.h
* SqueakVMForCarbon
*
* Created by John M McIntosh on Mon Dec 01 2003.
*
*/
#include <Carbon/Carbon.h>
void getVMPathWithEncoding(char *target,UInt32 encoding);
void SetVMPathFromCFString(CFMutableStringRef strRef);
Boolean VMPathIsEmpty(void);
void getImageNameWithEncoding(char *target,UInt32 encoding);
void SetImageNameViaCFString(CFStringRef string);
void SetImageNameViaString(char *string,UInt32 encoding);
Boolean ImageNameIsEmpty(void);
char *getImageName(void);
void getShortImageNameWithEncoding(char *target,UInt32 encoding);
void SetShortImageNameViaString(char *string,UInt32 encoding);
Boolean ShortImageNameIsEmpty(void);
void getDocumentNameWithEncoding(char *target,UInt32 encoding);
void SetDocumentNameViaString(char *string,UInt32 encoding);
void setEncodingType (char *aType);
char* getEncodingType (UInt32 aType);
int IsImageName(char *name);
|
09c5e588e8ccd85310129fd44e4dfcfb6124e83d
|
fff6d13af91db925a94b3e3474108fafd519bba0
|
/src/General/stdMath.h
|
322a80727cd5d25c75263ede40fed2814a6fc6d5
|
[
"LicenseRef-scancode-warranty-disclaimer"
] |
no_license
|
shinyquagsire23/OpenJKDF2
|
94f1364628924ac944466107606b91c6faeec3df
|
b79b8c210878b6f276ed3d1a5dad91d9219e6ce1
|
refs/heads/master
| 2023-07-08T16:41:38.986577
| 2023-06-28T08:47:39
| 2023-06-28T08:47:39
| 139,542,792
| 381
| 34
|
NOASSERTION
| 2023-06-28T08:47:40
| 2018-07-03T07:09:45
|
C
|
UTF-8
|
C
| false
| false
| 3,719
|
h
|
stdMath.h
|
#ifndef _STDMATH_H
#define _STDMATH_H
#include "hook.h"
#define _USE_MATH_DEFINES
#include <math.h>
#define stdMath_FlexPower_ADDR (0x00431E20)
#define stdMath_NormalizeAngle_ADDR (0x00431E5B)
#define stdMath_NormalizeAngleAcute_ADDR (0x00431F10)
#define stdMath_NormalizeDeltaAngle_ADDR (0x00431F45)
#define stdMath_SinCos_ADDR (0x00431FBD)
#define stdMath_Tan_ADDR (0x00432396)
#define stdMath_ArcSin1_ADDR (0x00432623)
#define stdMath_ArcSin2_ADDR (0x004326FC)
#define stdMath_ArcSin3_ADDR (0x00432809)
#define stdMath_ArcTan1_ADDR (0x0043294A)
#define stdMath_ArcTan2_ADDR (0x00432AC6)
#define stdMath_ArcTan3_ADDR (0x00432C5C)
#define stdMath_ArcTan4_ADDR (0x00432E0C)
#define stdMath_FloorDivMod_ADDR (0x00432FD6)
#define stdMath_Dist2D1_ADDR (0x0043303E)
#define stdMath_Dist2D2_ADDR (0x004330E2)
#define stdMath_Dist2D3_ADDR (0x00433186)
#define stdMath_Dist2D4_ADDR (0x0043322A)
#define stdMath_Dist3D1_ADDR (0x00433302)
#define stdMath_Dist3D2_ADDR (0x00433418)
#define stdMath_Dist3D3_ADDR (0x0043352E)
#define stdMath_Floor_ADDR (0x00433650)
#define stdMath_Sqrt_ADDR (0x00433670)
float stdMath_FlexPower(float num, int32_t exp);
float stdMath_NormalizeAngle(float angle);
float stdMath_NormalizeAngleAcute(float angle);
float stdMath_NormalizeDeltaAngle(float a1, float a2);
void stdMath_SinCos(float angle, float *pSinOut, float *pCosOut);
float stdMath_Tan(float a1);
float stdMath_ArcSin1(float val);
float stdMath_ArcSin2(float val);
float stdMath_ArcSin3(float val);
float stdMath_ArcTan1(float a1, float a2);
float stdMath_ArcTan2(float a1, float a2);
float stdMath_ArcTan3(float a1, float a2);
float stdMath_ArcTan4(float a1, float a2);
int32_t stdMath_FloorDivMod(int32_t in1, int32_t in2, int32_t *out1, int32_t *out2);
//IMPORT_FUNC(stdMath_SinCos, void, (float, float*, float*), stdMath_SinCos_ADDR)
//IMPORT_FUNC(stdMath_Tan, float, (float), stdMath_Tan_ADDR)
//IMPORT_FUNC(stdMath_ArcSin1, float, (float), stdMath_ArcSin1_ADDR)
//IMPORT_FUNC(stdMath_ArcSin2, float, (float), stdMath_ArcSin2_ADDR)
//IMPORT_FUNC(stdMath_ArcSin3, float, (float), stdMath_ArcSin3_ADDR)
//IMPORT_FUNC(stdMath_ArcTan1, float, (float, float), stdMath_ArcTan1_ADDR)
//IMPORT_FUNC(stdMath_ArcTan2, float, (float, float), stdMath_ArcTan2_ADDR)
//IMPORT_FUNC(stdMath_ArcTan3, float, (float, float), stdMath_ArcTan3_ADDR)
//IMPORT_FUNC(stdMath_ArcTan4, float, (float, float), stdMath_ArcTan4_ADDR)
//IMPORT_FUNC(stdMath_FloorDivMod, int, (int, int, int*, int*), stdMath_FloorDivMod_ADDR)
static void (*_stdMath_SinCos)(float angle, float *pSinOut, float *pCosOut) = (void*)stdMath_SinCos_ADDR;
float stdMath_Dist2D1(float a1, float a2);
float stdMath_Dist2D2(float a1, float a2);
float stdMath_Dist2D3(float a1, float a2);
float stdMath_Dist2D4(float a1, float a2);
float stdMath_Dist3D1(float a1, float a2, float a3);
float stdMath_Dist3D2(float a1, float a2, float a3);
float stdMath_Dist3D3(float a1, float a2, float a3);
float stdMath_Floor(float a);
float stdMath_Sqrt(float a);
// Added
float stdMath_ClipPrecision(float val);
float stdMath_Clamp(float val, float valMin, float valMax);
float stdMath_ClampValue(float val, float valAbsMax);
static inline float stdMath_Fabs(float val)
{
return fabs(val);
}
static inline int32_t stdMath_ClampInt(int32_t val, int32_t valMin, int32_t valMax)
{
if (val < valMin)
return valMin;
if (val > valMax)
return valMax;
return val;
}
static inline uint8_t stdMath_ClampU8(uint8_t val, uint8_t valMin, uint8_t valMax)
{
if (val < valMin)
return valMin;
if (val > valMax)
return valMax;
return val;
}
extern const float aSinTable[4096];
extern const float aTanTable[4096];
#endif // _STDMATH_H
|
e3eff09067855772600b8d6a1b2af7bf9110b694
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/libs/libnx/nxtk/nxtk_block.c
|
9ec5781f103a6c287f07e4d51b291c7913814d04
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 2,885
|
c
|
nxtk_block.c
|
/****************************************************************************
* libs/libnx/nxtk/nxtk_block.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxtk.h>
#include <nuttx/nx/nxmu.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxtk_block
*
* Description:
* This is callback will do to things: (1) any queue a 'blocked' callback
* to the window and then (2) block any further window messaging.
*
* The 'blocked' callback is the response from nx_block (or nxtk_block).
* Those blocking interfaces are used to assure that no further messages
* are are directed to the window. Receipt of the blocked callback
* signifies that (1) there are no further pending callbacks and (2) that
* the window is now 'defunct' and will receive no further callbacks.
*
* This callback supports coordinated destruction of a window in multi-
* user mode. In multi-use mode, the client window logic must stay
* intact until all of the queued callbacks are processed. Then the
* window may be safely closed. Closing the window prior with pending
* callbacks can lead to bad behavior when the callback is executed.
*
* Input Parameters:
* hfwnd - The window to be blocked
* arg - An argument that will accompany the block messages (This is arg2
* in the blocked callback).
*
* Returned Value:
* OK on success; ERROR on failure with errno set appropriately
*
****************************************************************************/
int nxtk_block(NXTKWINDOW hfwnd, FAR void *arg)
{
return nx_block((NXWINDOW)hfwnd, arg);
}
|
85dee503d7123afc88f69a0fd3c4ff0f5936c81c
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/arch/prep/include/ieee.h
|
a89f604d9c6a97752e0f1cf72aac1c5b172a76f6
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 88
|
h
|
ieee.h
|
/* $NetBSD: ieee.h,v 1.1 2000/02/29 15:21:29 nonaka Exp $ */
#include <powerpc/ieee.h>
|
a6d07671d9254da8ef2fac1affddecd882f6c75d
|
090cd251faddf7100670f45ae10cad0cae6ff868
|
/3rdParty/stb_image_write.h
|
a83f1afc59e76496c66de19f2b9ed5640b5e763f
|
[
"MIT"
] |
permissive
|
smallstepforman/Medo
|
378a423fcb08f7824ff6d76f0340af35808211ac
|
48d1d7495b099c9b68e0b1a8e39617b442d05575
|
refs/heads/main
| 2023-09-01T12:19:13.424310
| 2023-08-20T09:22:36
| 2023-08-20T09:22:36
| 323,201,021
| 135
| 8
|
MIT
| 2021-05-17T22:43:33
| 2020-12-21T01:28:20
|
C++
|
UTF-8
|
C
| false
| false
| 8,677
|
h
|
stb_image_write.h
|
/* stb_image_write - v1.14 - public domain - http://nothings.org/stb
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk
Before #including,
#define STB_IMAGE_WRITE_IMPLEMENTATION
in the file that you want to have the implementation.
Will probably not work correctly with strict-aliasing optimizations.
ABOUT:
This header file is a library for writing images to C stdio or a callback.
The PNG output is not optimal; it is 20-50% larger than the file
written by a decent optimizing implementation; though providing a custom
zlib compress function (see STBIW_ZLIB_COMPRESS) can mitigate that.
This library is designed for source code compactness and simplicity,
not optimal image file size or run-time performance.
BUILDING:
You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h.
You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace
malloc,realloc,free.
You can #define STBIW_MEMMOVE() to replace memmove()
You can #define STBIW_ZLIB_COMPRESS to use a custom zlib-style compress function
for PNG compression (instead of the builtin one), it must have the following signature:
unsigned char * my_compress(unsigned char *data, int data_len, int *out_len, int quality);
The returned data will be freed with STBIW_FREE() (free() by default),
so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
UNICODE:
If compiling for Windows and you wish to use Unicode filenames, compile
with
#define STBIW_WINDOWS_UTF8
and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
Windows wchar_t filenames to utf8.
USAGE:
There are five functions, one for each image file format:
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality);
int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically
There are also five equivalent functions that use an arbitrary write function. You are
expected to open/close your file-equivalent before and after calling these:
int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
where the callback is:
void stbi_write_func(void *context, void *data, int size);
You can configure it with these global variables:
int stbi_write_tga_with_rle; // defaults to true; set to 0 to disable RLE
int stbi_write_png_compression_level; // defaults to 8; set to higher for more compression
int stbi_write_force_png_filter; // defaults to -1; set to 0..5 to force a filter mode
You can define STBI_WRITE_NO_STDIO to disable the file variant of these
functions, so the library will not use stdio.h at all. However, this will
also disable HDR writing, because it requires stdio for formatted output.
Each function returns 0 on failure and non-0 on success.
The functions create an image file defined by the parameters. The image
is a rectangle of pixels stored from left-to-right, top-to-bottom.
Each pixel contains 'comp' channels of data stored interleaved with 8-bits
per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
The *data pointer points to the first byte of the top-left-most pixel.
For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
a row of pixels to the first byte of the next row of pixels.
PNG creates output files with the same number of components as the input.
The BMP format expands Y to RGB in the file format and does not
output alpha.
PNG supports writing rectangles of data even when the bytes storing rows of
data are not consecutive in memory (e.g. sub-rectangles of a larger image),
by supplying the stride between the beginning of adjacent rows. The other
formats do not. (Thus you cannot write a native-format BMP through the BMP
writer, both because it is in BGR order and because it may have padding
at the end of the line.)
PNG allows you to set the deflate compression level by setting the global
variable 'stbi_write_png_compression_level' (it defaults to 8).
HDR expects linear float data. Since the format is always 32-bit rgb(e)
data, alpha (if provided) is discarded, and for monochrome data it is
replicated across all three channels.
TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed
data, set the global variable 'stbi_write_tga_with_rle' to 0.
JPEG does ignore alpha channels in input data; quality is between 1 and 100.
Higher quality looks better but results in a bigger image.
JPEG baseline (no JPEG progressive).
CREDITS:
Sean Barrett - PNG/BMP/TGA
Baldur Karlsson - HDR
Jean-Sebastien Guay - TGA monochrome
Tim Kelsey - misc enhancements
Alan Hickman - TGA RLE
Emmanuel Julien - initial file IO callback implementation
Jon Olick - original jo_jpeg.cpp code
Daniel Gibson - integrate JPEG, allow external zlib
Aarni Koskela - allow choosing PNG filter
bugfixes:
github:Chribba
Guillaume Chereau
github:jry2
github:romigrou
Sergio Gonzalez
Jonas Karlsson
Filip Wasil
Thatcher Ulrich
github:poppolopoppo
Patrick Boettcher
github:xeekworx
Cap Petschulat
Simon Rodriguez
Ivan Tikhonov
github:ignotion
Adam Schackart
LICENSE
See end of file for license information.
*/
#ifndef INCLUDE_STB_IMAGE_WRITE_H
#define INCLUDE_STB_IMAGE_WRITE_H
#include <stdlib.h>
// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
#ifndef STBIWDEF
#ifdef STB_IMAGE_WRITE_STATIC
#define STBIWDEF static
#else
#ifdef __cplusplus
#define STBIWDEF extern "C"
#else
#define STBIWDEF extern
#endif
#endif
#endif
#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations
extern int stbi_write_tga_with_rle;
extern int stbi_write_png_compression_level;
extern int stbi_write_force_png_filter;
#endif
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
#ifdef STBI_WINDOWS_UTF8
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
#endif
#endif
typedef void stbi_write_func(void *context, void *data, int size);
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
#endif//INCLUDE_STB_IMAGE_WRITE_H
|
949631702fdcb2a8e890b93fe4c01a966c8f0a52
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/external/bsd/drm2/include/linux/regulator/consumer.h
|
0cd3ca0e5e6c13afd55c0767abcf1f17a725df79
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 2,762
|
h
|
consumer.h
|
/* $NetBSD: consumer.h,v 1.5 2018/11/19 10:48:59 maya Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Taylor R. Campbell.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _LINUX_REGULATOR_CONSUMER_H_
#define _LINUX_REGULATOR_CONSUMER_H_
#ifdef _KERNEL_OPT
#include "opt_fdt.h"
#endif
#ifdef FDT
#include <machine/limits.h>
#include <dev/fdt/fdtvar.h>
struct regulator {
struct fdtbus_regulator regulator;
};
static inline int
regulator_get_voltage(struct regulator *reg)
{
unsigned uvolt;
int error;
error = fdtbus_regulator_get_voltage(®->regulator, &uvolt);
if (error) {
/* XXX errno NetBSD->Linux */
KASSERTMSG(error > 0, "negative error: %d", error);
return -error;
}
KASSERTMSG(uvolt <= INT_MAX, "high voltage: %u uV", uvolt);
return (int)uvolt;
}
static inline int
regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
{
if (min_uvolt < 0 || max_uvolt < 0)
return -EINVAL;
/* XXX errno NetBSD->Linux */
return -fdtbus_regulator_set_voltage(®->regulator, min_uvolt,
max_uvolt);
}
#else
struct regulator;
static inline int
regulator_get_voltage(struct regulator *reg)
{
panic("no voltage regulators here");
}
static inline int
regulator_set_voltage(struct regulator *reg, int min_uvolt, int max_uvolt)
{
panic("no voltage regulators here");
}
#endif
#endif /* _LINUX_REGULATOR_CONSUMER_H_ */
|
7bbc837703bea388820c09e700c18676e39d7eca
|
8838eb997879add5759b6dfb23f9a646464e53ca
|
/src/drivers/interrupt/riscv_plic/riscv_plic.c
|
0cc7ff8a48a38217f9e22bdf4d0146b7734000c9
|
[
"BSD-2-Clause"
] |
permissive
|
embox/embox
|
d6aacec876978522f01cdc4b8de37a668c6f4c80
|
98e3c06e33f3fdac10a29c069c20775568e0a6d1
|
refs/heads/master
| 2023-09-04T03:02:20.165042
| 2023-09-02T14:55:31
| 2023-09-02T14:55:31
| 33,078,138
| 1,087
| 325
|
BSD-2-Clause
| 2023-09-14T16:58:34
| 2015-03-29T15:27:48
|
C
|
UTF-8
|
C
| false
| false
| 1,773
|
c
|
riscv_plic.c
|
/**
* @file
*
* @brief RISC-V build-in interrupt controller
*
* @date 04.10.2019
* @author Anastasia Nizharadze
*/
#include <stdint.h>
#include <assert.h>
#include <hal/reg.h>
#include <asm/regs.h>
#include <asm/interrupts.h>
#include <drivers/irqctrl.h>
#include <embox/unit.h>
#define PLIC_ADDR OPTION_GET(NUMBER, base_addr)
#define IPL_ADDR(num) (PLIC_ADDR + (num * 4))
#define PRIORITY_THRESHOLD_ADDR (PLIC_ADDR + 0x200000U)
#define CLAIM_COMPLETE_ADDR (PLIC_ADDR + 0x200004U) /* offset for hart 0 claim/complere reg */
#define INTERRUPT_ENABLE_REG_1 (PLIC_ADDR + 0x2000U)
#define INTERRUPT_ENABLE_REG_2 (PLIC_ADDR + 0x2004U)
static int plic_init(void) {
REG32_STORE(PRIORITY_THRESHOLD_ADDR, 0);
enable_external_interrupts();
return 0;
}
int irqctrl_get_num(void) {
uint32_t claim;
claim = REG32_LOAD(CLAIM_COMPLETE_ADDR);
return claim;
}
void irqctrl_enable(unsigned int interrupt_nr) {
uint32_t reg;
REG32_STORE(IPL_ADDR(interrupt_nr), 1);
if (interrupt_nr < 32) {
reg = REG32_LOAD(INTERRUPT_ENABLE_REG_1);
reg |= (1U << interrupt_nr);
REG32_STORE(INTERRUPT_ENABLE_REG_1, reg);
} else {
reg = REG32_LOAD(INTERRUPT_ENABLE_REG_2);
reg |= (1U << (interrupt_nr - 32));
REG32_STORE(INTERRUPT_ENABLE_REG_2, reg);
}
}
void irqctrl_disable(unsigned int interrupt_nr) {
uint32_t reg;
if (interrupt_nr < 32) {
reg = REG32_LOAD(INTERRUPT_ENABLE_REG_1);
reg &= ~(1U << interrupt_nr);
REG32_STORE(INTERRUPT_ENABLE_REG_1, reg);
} else {
reg = REG32_LOAD(INTERRUPT_ENABLE_REG_2);
reg &= ~(1U << (interrupt_nr - 32));
REG32_STORE(INTERRUPT_ENABLE_REG_2, reg);
}
}
void irqctrl_eoi(unsigned int irq) {
REG32_STORE(CLAIM_COMPLETE_ADDR, irq);
}
IRQCTRL_DEF(riscv_plic, plic_init);
|
4ddcac8d539ece80e034e3d098a0cf5b02aba59d
|
aa5c1a530f95d629e686ac9124caf1a49a9f23e9
|
/samples/static_library/create_c_module.c
|
2dfc0fd90012a58708f1a32698a4bbc78d322fbe
|
[
"Apache-2.0",
"LLVM-exception",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
openxla/iree
|
eacf5b239559e1d3b40c38039ac4c26315b523f7
|
13ef677e556d0a1d154e45b052fe016256057f65
|
refs/heads/main
| 2023-09-06T01:19:49.598662
| 2023-09-04T07:01:30
| 2023-09-04T07:01:30
| 208,145,128
| 387
| 110
|
Apache-2.0
| 2023-09-14T20:48:00
| 2019-09-12T20:57:39
|
C++
|
UTF-8
|
C
| false
| false
| 629
|
c
|
create_c_module.c
|
// Copyright 2021 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <stdio.h>
#include "samples/static_library/simple_mul_emitc.h"
// A function to create the C module.
iree_status_t create_module(iree_vm_instance_t* instance,
iree_vm_module_t** out_module) {
return module_create(instance, iree_vm_instance_allocator(instance),
out_module);
}
void print_success() { printf("static_library_run_c passed\n"); }
|
e00f2a26196139fc3305cd31f90df4761b595f15
|
67801a1568b81ea5e45ed534301cd35949066e6d
|
/src/states.c
|
fd93812cb09358196094e4c64c5888202ce5fb5d
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
fossasia/pslab-firmware
|
dcb8e570d162c0ef24cdedf43483c706bc736259
|
c93ac629442315c1430120b7ab3c0026d03e3503
|
refs/heads/main
| 2023-07-22T18:22:30.827478
| 2023-07-05T05:32:15
| 2023-07-05T05:38:34
| 86,472,725
| 2,212
| 89
|
Apache-2.0
| 2023-09-14T20:36:23
| 2017-03-28T14:53:27
|
C
|
UTF-8
|
C
| false
| false
| 1,110
|
c
|
states.c
|
#include "registers/system/system.h"
#include "bus/uart/uart.h"
#include "registers/system/watchdog.h"
#include "commands.h"
#include "states.h"
/**
* @brief Wait for incoming serial traffic.
* @return STATE_STANDBY or STATE_RUNCOMMAND
*/
state_t Standby(void) {
if (UART_IsRxReady(U1SELECT)) {
return STATE_RUNCOMMAND;
} else {
WATCHDOG_TimerClear();
return STATE_STANDBY;
}
}
/**
* @brief Receive commands bytes, run command, and send response.
* @return STATE_STANDBY
*/
state_t RunCommand(void) {
command_t primary_cmd = UART1_Read();
command_t secondary_cmd = UART1_Read();
// Sanitize input.
if (primary_cmd > NUM_PRIMARY_CMDS) return STATE_STANDBY;
if (secondary_cmd > num_secondary_cmds[primary_cmd]) return STATE_STANDBY;
response_t response = cmd_table[primary_cmd][secondary_cmd]();
if (response) UART1_Write(response);
return STATE_STANDBY;
}
state_func_t* const state_table[NUM_STATES] = {
Standby,
RunCommand,
};
state_t STATES_RunState(state_t current_state) {
return state_table[current_state]();
};
|
929d8ceef4625d02aa92ccda792e45809cefd7f6
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/dev/hil/hilid.c
|
46ad931f264813e1984b060946c6128c8bf94a62
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 2,954
|
c
|
hilid.c
|
/* $OpenBSD: hilid.c,v 1.5 2022/04/06 18:59:28 naddy Exp $ */
/*
* Copyright (c) 2003, Miodrag Vallat.
* All rights reserved.
*
* 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 ``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 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.
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/ioctl.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <dev/hil/hilreg.h>
#include <dev/hil/hilvar.h>
#include <dev/hil/hildevs.h>
struct hilid_softc {
struct hildev_softc sc_hildev;
u_int8_t sc_id[16];
};
int hilidprobe(struct device *, void *, void *);
void hilidattach(struct device *, struct device *, void *);
int hiliddetach(struct device *, int);
struct cfdriver hilid_cd = {
NULL, "hilid", DV_DULL
};
const struct cfattach hilid_ca = {
sizeof(struct hilid_softc), hilidprobe, hilidattach, hiliddetach,
};
int
hilidprobe(struct device *parent, void *match, void *aux)
{
struct hil_attach_args *ha = aux;
if (ha->ha_type != HIL_DEVICE_IDMODULE)
return (0);
return (1);
}
void
hilidattach(struct device *parent, struct device *self, void *aux)
{
struct hilid_softc *sc = (void *)self;
struct hil_attach_args *ha = aux;
u_int i, len;
sc->hd_code = ha->ha_code;
sc->hd_type = ha->ha_type;
sc->hd_infolen = ha->ha_infolen;
bcopy(ha->ha_info, sc->hd_info, ha->ha_infolen);
sc->hd_fn = NULL;
printf("\n");
bzero(sc->sc_id, sizeof(sc->sc_id));
len = sizeof(sc->sc_id);
printf("%s: security code", self->dv_xname);
if (send_hildev_cmd((struct hildev_softc *)sc,
HIL_SECURITY, sc->sc_id, &len) == 0) {
for (i = 0; i < sizeof(sc->sc_id); i++)
printf(" %02x", sc->sc_id[i]);
printf("\n");
} else
printf(" unavailable\n");
}
int
hiliddetach(struct device *self, int flags)
{
return (0);
}
|
1ce07fff05ea57223042e809b8eb4d606a94ad7d
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/arch/armv7/include/conf.h
|
45b48a90bd1a626fa428741d102adee4cfa0672e
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 338
|
h
|
conf.h
|
/* $OpenBSD: conf.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */
/* $NetBSD: conf.h,v 1.8 2002/02/10 12:26:03 chris Exp $ */
#ifndef _MACHINE_CONF_H_
#define _MACHINE_CONF_H_
#include <sys/conf.h>
/*
* BEAGLEBOARD specific device includes go in here
*/
/*#define CONF_HAVE_GPIO*/
#include <arm/conf.h>
#endif /* _MACHINE_CONF_H_ */
|
aeae0bea386690f2e881b403fb0bc1f26a80c96f
|
d84c7df450292867f8c7bb58d1507735479d746d
|
/tests/t406-qfunction.h
|
c77a684beb78d297bc80779423a4fd5207fce4c8
|
[
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
CEED/libCEED
|
c17e8b2f8e9ccfafc0505bb6db451e2f7cfed690
|
c6c10e0994b55ea1726a79024cd4c333c40de38a
|
refs/heads/main
| 2023-09-01T20:13:21.268643
| 2023-09-01T20:08:36
| 2023-09-01T20:08:36
| 113,349,904
| 167
| 54
|
BSD-2-Clause
| 2023-09-14T20:37:58
| 2017-12-06T17:57:40
|
C
|
UTF-8
|
C
| false
| false
| 1,032
|
h
|
t406-qfunction.h
|
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
//
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of CEED: http://github.com/ceed
// Note: intentionally testing strange spacing in '#include's
#include <ceed.h>
#include <math.h>
#include "./t406-qfunction-scales.h"
#include "t406-qfunction-helper.h"
CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
const CeedScalar *w = in[0];
CeedScalar *q_data = out[0];
for (CeedInt i = 0; i < Q; i++) {
q_data[i] = w[i];
}
return 0;
}
CEED_QFUNCTION(mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
const CeedScalar *q_data = in[0], *u = in[1];
CeedScalar *v = out[0];
for (CeedInt i = 0; i < Q; i++) {
v[i] = q_data[i] * (times_two(u[i]) + times_three(u[i])) * sqrt(1.0 * SCALE_TWO);
}
return 0;
}
|
2af73d64559abc317f7585b9fd99b8e9f7d07fea
|
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
|
/games/quarry/patches/patch-src_gui-gtk_quarry-text-buffer.c
|
efae30c3ba73b27b144f0f3b30afbdbdeecf05dc
|
[] |
no_license
|
NetBSD/pkgsrc
|
a0732c023519650ef821ab89c23ab6ab59e25bdb
|
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
|
refs/heads/trunk
| 2023-09-01T07:40:12.138283
| 2023-09-01T05:25:19
| 2023-09-01T05:25:19
| 88,439,572
| 321
| 138
| null | 2023-07-12T22:34:14
| 2017-04-16T20:04:15
| null |
UTF-8
|
C
| false
| false
| 389
|
c
|
patch-src_gui-gtk_quarry-text-buffer.c
|
$NetBSD: patch-src_gui-gtk_quarry-text-buffer.c,v 1.1 2012/11/16 00:50:39 joerg Exp $
--- src/gui-gtk/quarry-text-buffer.c.orig 2012-11-15 15:16:11.000000000 +0000
+++ src/gui-gtk/quarry-text-buffer.c
@@ -983,7 +983,7 @@ quarry_text_buffer_undo_entry_delete (Qu
}
-inline gboolean
+gboolean
quarry_text_buffer_undo_entry_is_empty
(const QuarryTextBufferUndoEntry *undo_entry)
{
|
07cd0eeeff46673e6b60f7dca48c24a0cacdc40d
|
25c64fb97b7cdb30ec1b6ddd2acf9a755fc33adf
|
/src/strengthen.h
|
1e6a395fc7220511c335b0127253bf943490c3fd
|
[
"MIT"
] |
permissive
|
arminbiere/kissat
|
386c1cfadf43562d36fccc47064c95296c9b812f
|
630d64d4d63c2816fc79a1a0340286b39677e97d
|
refs/heads/master
| 2023-09-04T01:39:44.293487
| 2023-06-24T15:51:43
| 2023-06-24T15:51:43
| 267,257,286
| 350
| 63
|
MIT
| 2022-06-23T12:15:24
| 2020-05-27T07:57:59
|
C
|
UTF-8
|
C
| false
| false
| 456
|
h
|
strengthen.h
|
#ifndef _strengthen_h_INCLUDED
#define _strengthen_h_INCLUDED
#include <stdbool.h>
struct clause;
struct kissat;
struct clause *kissat_on_the_fly_strengthen (struct kissat *,
struct clause *, unsigned lit);
void kissat_on_the_fly_subsume (struct kissat *, struct clause *,
struct clause *);
bool issat_strengthen_clause (struct kissat *, struct clause *, unsigned);
#endif
|
348d386c5b20d9bc9a448c46f86db22d67e981e4
|
f62ddee2dcadcae0e90f969be513b04e16dabf58
|
/data/source/tests/yal_test_type/open_source-start.c
|
e4ca379ad766f4357a3a3fdcbbd342c15100d297
|
[
"Apache-2.0"
] |
permissive
|
libyal/libyal
|
30bccf56471dbf874292fe32d5d9173fd470df0e
|
124111953917f65782a66a80e96a502ce2331b09
|
refs/heads/main
| 2023-07-25T09:25:46.068071
| 2023-07-08T09:56:44
| 2023-07-08T09:56:44
| 23,780,738
| 196
| 30
|
Apache-2.0
| 2022-11-27T19:01:42
| 2014-09-08T05:57:58
|
C
|
UTF-8
|
C
| false
| false
| 1,110
|
c
|
open_source-start.c
|
/* Creates and opens a source ${type_name}
* Returns 1 if successful or -1 on error
*/
int ${library_name_suffix}_test_${type_name}_open_source(
${library_name}_${type_name}_t **${type_name},
${test_options_function_arguments},
libcerror_error_t **error )
{
static char *function = "${library_name_suffix}_test_${type_name}_open_source";
${test_options_function_variables}
if( ${type_name} == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid ${type_name}.",
function );
return( -1 );
}
if( file_io_${bfio_type} == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid file IO ${bfio_type}.",
function );
return( -1 );
}
if( ${library_name}_${type_name}_initialize(
${type_name},
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize ${type_name}.",
function );
goto on_error;
}
|
05ae006f7bd1250b63c0b4836f5c5d477875ca8c
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/databases/Boxlib3D/Boxlib3DPluginInfo.C
|
970c0be50878a878e3060e4af9237749754d9298
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 4,596
|
c
|
Boxlib3DPluginInfo.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ****************************************************************************
// File: Boxlib3DPluginInfo.C
// ****************************************************************************
#include <Boxlib3DPluginInfo.h>
#include <visit-config.h>
VISIT_PLUGIN_VERSION(Boxlib3D,DBP_EXPORT)
VISIT_DATABASE_PLUGIN_ENTRY(Boxlib3D,General)
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::GetName
//
// Purpose:
// Return the name of the database plugin.
//
// Returns: A pointer to the name of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
Boxlib3DGeneralPluginInfo::GetName() const
{
return "Boxlib3D";
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::GetVersion
//
// Purpose:
// Return the version of the database plugin.
//
// Returns: A pointer to the version of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
Boxlib3DGeneralPluginInfo::GetVersion() const
{
return "1.0";
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::GetID
//
// Purpose:
// Return the id of the database plugin.
//
// Returns: A pointer to the id of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
Boxlib3DGeneralPluginInfo::GetID() const
{
return "Boxlib3D_1.0";
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::EnabledByDefault
//
// Purpose:
// Return true if this plugin should be enabled by default; false otherwise.
//
// Returns: true/false
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
Boxlib3DGeneralPluginInfo::EnabledByDefault() const
{
return true;
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::HasWriter
//
// Purpose:
// Return true if this plugin has a database writer.
//
// Returns: true/false
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
Boxlib3DGeneralPluginInfo::HasWriter() const
{
return false;
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::GetDefaultFilePatterns
//
// Purpose:
// Returns the default patterns for a Boxlib3D database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
std::vector<std::string>
Boxlib3DGeneralPluginInfo::GetDefaultFilePatterns() const
{
std::vector<std::string> defaultPatterns;
defaultPatterns.push_back("*.boxlib3d");
defaultPatterns.push_back("Header");
return defaultPatterns;
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::AreDefaultFilePatternsStrict
//
// Purpose:
// Returns if the file patterns for a Boxlib3D database are
// intended to be interpreted strictly by default.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
Boxlib3DGeneralPluginInfo::AreDefaultFilePatternsStrict() const
{
return true;
}
// ****************************************************************************
// Method: Boxlib3DGeneralPluginInfo::OpensWholeDirectory
//
// Purpose:
// Returns if the Boxlib3D plugin opens a whole directory name
// instead of a single file.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
Boxlib3DGeneralPluginInfo::OpensWholeDirectory() const
{
return false;
}
|
579cce223b6e4f45e259e8cca00d7a495fcd22eb
|
c30beb817a4788c3eb9027c5cede0c7ae4006578
|
/demos/FPL_GameTemplate/fpl_gametemplate.h
|
c3cff528ac2188a141c5f834d06510d20d63c2ed
|
[
"MIT"
] |
permissive
|
f1nalspace/final_game_tech
|
232c34ce6d737b9069073b53c665bf14e513898c
|
33b63dc0664e16682d4298371f3166869c233b0f
|
refs/heads/master
| 2023-06-25T07:27:01.747802
| 2021-09-07T08:03:17
| 2021-09-07T08:08:08
| 91,165,055
| 178
| 18
|
MIT
| 2023-01-04T12:40:05
| 2017-05-13T09:59:36
|
C
|
UTF-8
|
C
| false
| false
| 691
|
h
|
fpl_gametemplate.h
|
#ifndef FPL_GAMETEMPLATE_H
#define FPL_GAMETEMPLATE_H
#include <final_math.h>
#include <final_geometry.h>
#include <final_fontloader.h>
#include <final_render.h>
#include <final_utils.h>
#include <final_assets.h>
struct Assets {
FontAsset consoleFont;
char dataPath[1024];
};
struct Entity {
Vec2f position;
Vec2f velocity;
Vec2f radius;
Vec4f color;
float moveSpeed;
float moveDrag;
};
struct World {
Entity player;
};
struct GameState {
Assets assets;
World world;
Camera2D camera;
Mat4f viewProjection;
Viewport viewport;
Vec2f mouseWorldPos;
float deltaTime;
float framesPerSecond[2];
bool isExiting;
bool isDebugRendering;
};
#endif // FPL_GAMETEMPLATE_H
|
476374525b364e67930a0c740ba946c15935f2de
|
50dd46b8ece33f3cdd174284b15d1d51f89669d4
|
/third_party/edk2/AppPkg/Applications/Python/Python-2.7.2/Python/getcwd.c
|
54897c5b0a3f50d043a5d4dc531dffbb44b9bf50
|
[
"LicenseRef-scancode-generic-cla",
"Apache-2.0",
"BSD-2-Clause",
"OpenSSL",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-python-cwi",
"LicenseRef-scancode-free-unknown",
"Python-2.0",
"GPL-1.0-or-later"
] |
permissive
|
google/google-ctf
|
f99da1ee07729bbccb869fff1cbaed6a80e43bcc
|
df02323eaf945d15e124801c74abaadca2749dc7
|
refs/heads/master
| 2023-08-31T14:30:27.548081
| 2023-08-29T13:04:20
| 2023-08-29T13:04:20
| 131,317,137
| 4,136
| 607
|
Apache-2.0
| 2023-08-30T22:17:02
| 2018-04-27T15:56:03
|
Go
|
UTF-8
|
C
| false
| false
| 1,626
|
c
|
getcwd.c
|
/* Two PD getcwd() implementations.
Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_GETWD
/* Version for BSD systems -- use getwd() */
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifndef MAXPATHLEN
#if defined(PATH_MAX) && PATH_MAX > 1024
#define MAXPATHLEN PATH_MAX
#else
#define MAXPATHLEN 1024
#endif
#endif
extern char *getwd(char *);
char *
getcwd(char *buf, int size)
{
char localbuf[MAXPATHLEN+1];
char *ret;
if (size <= 0) {
errno = EINVAL;
return NULL;
}
ret = getwd(localbuf);
if (ret != NULL && strlen(localbuf) >= (size_t)size) {
errno = ERANGE;
return NULL;
}
if (ret == NULL) {
errno = EACCES; /* Most likely error */
return NULL;
}
strncpy(buf, localbuf, size);
return buf;
}
#else /* !HAVE_GETWD */
/* Version for really old UNIX systems -- use pipe from pwd */
#ifndef PWD_CMD
#define PWD_CMD "/bin/pwd"
#endif
char *
getcwd(char *buf, int size)
{
FILE *fp;
char *p;
if (size <= 0) {
errno = EINVAL;
return NULL;
}
if ((fp = popen(PWD_CMD, "r")) == NULL)
return NULL;
if (fgets(buf, size, fp) == NULL || pclose(fp) != 0) {
errno = EACCES; /* Most likely error */
return NULL;
}
for (p = buf; *p != '\n'; p++) {
if (*p == '\0') {
errno = ERANGE;
return NULL;
}
}
*p = '\0';
return buf;
}
#endif /* !HAVE_GETWD */
|
3554bcce081d54b71a9a5551965aca3423113fb6
|
676acab8ff535019faff7da3afb8eecc3fa127f5
|
/src/lib/mavlink/v2.0/common/mavlink_msg_gimbal_manager_information.h
|
5d8dca4a7acf0d897a2485006f4501412a7f2ea7
|
[
"Apache-2.0"
] |
permissive
|
Firmament-Autopilot/FMT-Firmware
|
f8c324577245bd7e91af436954b4ce9421acbb41
|
0212fe89820376bfbedaded519552f6b011a7b8a
|
refs/heads/master
| 2023-09-01T11:37:46.194145
| 2023-08-29T06:33:10
| 2023-08-29T06:33:10
| 402,557,689
| 351
| 143
|
Apache-2.0
| 2023-09-12T05:28:39
| 2021-09-02T20:42:56
|
C
|
UTF-8
|
C
| false
| false
| 24,170
|
h
|
mavlink_msg_gimbal_manager_information.h
|
#pragma once
// MESSAGE GIMBAL_MANAGER_INFORMATION PACKING
#define MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION 280
typedef struct __mavlink_gimbal_manager_information_t {
uint32_t time_boot_ms; /*< [ms] Timestamp (time since system boot).*/
uint32_t cap_flags; /*< Bitmap of gimbal capability flags.*/
float tilt_max; /*< [rad] Maximum tilt/pitch angle (positive: up, negative: down)*/
float tilt_min; /*< [rad] Minimum tilt/pitch angle (positive: up, negative: down)*/
float tilt_rate_max; /*< [rad/s] Maximum tilt/pitch angular rate (positive: up, negative: down)*/
float pan_max; /*< [rad] Maximum pan/yaw angle (positive: to the right, negative: to the left)*/
float pan_min; /*< [rad] Minimum pan/yaw angle (positive: to the right, negative: to the left)*/
float pan_rate_max; /*< [rad/s] Minimum pan/yaw angular rate (positive: to the right, negative: to the left)*/
uint8_t gimbal_device_id; /*< Gimbal device ID that this gimbal manager is responsible for.*/
} mavlink_gimbal_manager_information_t;
#define MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN 33
#define MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN 33
#define MAVLINK_MSG_ID_280_LEN 33
#define MAVLINK_MSG_ID_280_MIN_LEN 33
#define MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC 166
#define MAVLINK_MSG_ID_280_CRC 166
#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_GIMBAL_MANAGER_INFORMATION \
{ \
280, \
"GIMBAL_MANAGER_INFORMATION", \
9, \
{ \
{ "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_gimbal_manager_information_t, time_boot_ms) }, \
{ "cap_flags", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_gimbal_manager_information_t, cap_flags) }, \
{ "gimbal_device_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_gimbal_manager_information_t, gimbal_device_id) }, \
{ "tilt_max", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_gimbal_manager_information_t, tilt_max) }, \
{ "tilt_min", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_gimbal_manager_information_t, tilt_min) }, \
{ "tilt_rate_max", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_gimbal_manager_information_t, tilt_rate_max) }, \
{ "pan_max", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_gimbal_manager_information_t, pan_max) }, \
{ "pan_min", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_gimbal_manager_information_t, pan_min) }, \
{ "pan_rate_max", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_gimbal_manager_information_t, pan_rate_max) }, \
} \
}
#else
#define MAVLINK_MESSAGE_INFO_GIMBAL_MANAGER_INFORMATION \
{ \
"GIMBAL_MANAGER_INFORMATION", \
9, \
{ \
{ "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_gimbal_manager_information_t, time_boot_ms) }, \
{ "cap_flags", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_gimbal_manager_information_t, cap_flags) }, \
{ "gimbal_device_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 32, offsetof(mavlink_gimbal_manager_information_t, gimbal_device_id) }, \
{ "tilt_max", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_gimbal_manager_information_t, tilt_max) }, \
{ "tilt_min", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_gimbal_manager_information_t, tilt_min) }, \
{ "tilt_rate_max", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_gimbal_manager_information_t, tilt_rate_max) }, \
{ "pan_max", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_gimbal_manager_information_t, pan_max) }, \
{ "pan_min", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_gimbal_manager_information_t, pan_min) }, \
{ "pan_rate_max", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_gimbal_manager_information_t, pan_rate_max) }, \
} \
}
#endif
/**
* @brief Pack a gimbal_manager_information message
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param msg The MAVLink message to compress the data into
*
* @param time_boot_ms [ms] Timestamp (time since system boot).
* @param cap_flags Bitmap of gimbal capability flags.
* @param gimbal_device_id Gimbal device ID that this gimbal manager is responsible for.
* @param tilt_max [rad] Maximum tilt/pitch angle (positive: up, negative: down)
* @param tilt_min [rad] Minimum tilt/pitch angle (positive: up, negative: down)
* @param tilt_rate_max [rad/s] Maximum tilt/pitch angular rate (positive: up, negative: down)
* @param pan_max [rad] Maximum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_min [rad] Minimum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_rate_max [rad/s] Minimum pan/yaw angular rate (positive: to the right, negative: to the left)
* @return length of the message in bytes (excluding serial stream start sign)
*/
static inline uint16_t mavlink_msg_gimbal_manager_information_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
uint32_t time_boot_ms, uint32_t cap_flags, uint8_t gimbal_device_id, float tilt_max, float tilt_min, float tilt_rate_max, float pan_max, float pan_min, float pan_rate_max)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN];
_mav_put_uint32_t(buf, 0, time_boot_ms);
_mav_put_uint32_t(buf, 4, cap_flags);
_mav_put_float(buf, 8, tilt_max);
_mav_put_float(buf, 12, tilt_min);
_mav_put_float(buf, 16, tilt_rate_max);
_mav_put_float(buf, 20, pan_max);
_mav_put_float(buf, 24, pan_min);
_mav_put_float(buf, 28, pan_rate_max);
_mav_put_uint8_t(buf, 32, gimbal_device_id);
memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN);
#else
mavlink_gimbal_manager_information_t packet;
packet.time_boot_ms = time_boot_ms;
packet.cap_flags = cap_flags;
packet.tilt_max = tilt_max;
packet.tilt_min = tilt_min;
packet.tilt_rate_max = tilt_rate_max;
packet.pan_max = pan_max;
packet.pan_min = pan_min;
packet.pan_rate_max = pan_rate_max;
packet.gimbal_device_id = gimbal_device_id;
memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN);
#endif
msg->msgid = MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION;
return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
}
/**
* @brief Pack a gimbal_manager_information message on a channel
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param chan The MAVLink channel this message will be sent over
* @param msg The MAVLink message to compress the data into
* @param time_boot_ms [ms] Timestamp (time since system boot).
* @param cap_flags Bitmap of gimbal capability flags.
* @param gimbal_device_id Gimbal device ID that this gimbal manager is responsible for.
* @param tilt_max [rad] Maximum tilt/pitch angle (positive: up, negative: down)
* @param tilt_min [rad] Minimum tilt/pitch angle (positive: up, negative: down)
* @param tilt_rate_max [rad/s] Maximum tilt/pitch angular rate (positive: up, negative: down)
* @param pan_max [rad] Maximum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_min [rad] Minimum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_rate_max [rad/s] Minimum pan/yaw angular rate (positive: to the right, negative: to the left)
* @return length of the message in bytes (excluding serial stream start sign)
*/
static inline uint16_t mavlink_msg_gimbal_manager_information_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
mavlink_message_t* msg,
uint32_t time_boot_ms, uint32_t cap_flags, uint8_t gimbal_device_id, float tilt_max, float tilt_min, float tilt_rate_max, float pan_max, float pan_min, float pan_rate_max)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN];
_mav_put_uint32_t(buf, 0, time_boot_ms);
_mav_put_uint32_t(buf, 4, cap_flags);
_mav_put_float(buf, 8, tilt_max);
_mav_put_float(buf, 12, tilt_min);
_mav_put_float(buf, 16, tilt_rate_max);
_mav_put_float(buf, 20, pan_max);
_mav_put_float(buf, 24, pan_min);
_mav_put_float(buf, 28, pan_rate_max);
_mav_put_uint8_t(buf, 32, gimbal_device_id);
memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN);
#else
mavlink_gimbal_manager_information_t packet;
packet.time_boot_ms = time_boot_ms;
packet.cap_flags = cap_flags;
packet.tilt_max = tilt_max;
packet.tilt_min = tilt_min;
packet.tilt_rate_max = tilt_rate_max;
packet.pan_max = pan_max;
packet.pan_min = pan_min;
packet.pan_rate_max = pan_rate_max;
packet.gimbal_device_id = gimbal_device_id;
memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN);
#endif
msg->msgid = MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION;
return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
}
/**
* @brief Encode a gimbal_manager_information struct
*
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param msg The MAVLink message to compress the data into
* @param gimbal_manager_information C-struct to read the message contents from
*/
static inline uint16_t mavlink_msg_gimbal_manager_information_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_gimbal_manager_information_t* gimbal_manager_information)
{
return mavlink_msg_gimbal_manager_information_pack(system_id, component_id, msg, gimbal_manager_information->time_boot_ms, gimbal_manager_information->cap_flags, gimbal_manager_information->gimbal_device_id, gimbal_manager_information->tilt_max, gimbal_manager_information->tilt_min, gimbal_manager_information->tilt_rate_max, gimbal_manager_information->pan_max, gimbal_manager_information->pan_min, gimbal_manager_information->pan_rate_max);
}
/**
* @brief Encode a gimbal_manager_information struct on a channel
*
* @param system_id ID of this system
* @param component_id ID of this component (e.g. 200 for IMU)
* @param chan The MAVLink channel this message will be sent over
* @param msg The MAVLink message to compress the data into
* @param gimbal_manager_information C-struct to read the message contents from
*/
static inline uint16_t mavlink_msg_gimbal_manager_information_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_gimbal_manager_information_t* gimbal_manager_information)
{
return mavlink_msg_gimbal_manager_information_pack_chan(system_id, component_id, chan, msg, gimbal_manager_information->time_boot_ms, gimbal_manager_information->cap_flags, gimbal_manager_information->gimbal_device_id, gimbal_manager_information->tilt_max, gimbal_manager_information->tilt_min, gimbal_manager_information->tilt_rate_max, gimbal_manager_information->pan_max, gimbal_manager_information->pan_min, gimbal_manager_information->pan_rate_max);
}
/**
* @brief Send a gimbal_manager_information message
* @param chan MAVLink channel to send the message
*
* @param time_boot_ms [ms] Timestamp (time since system boot).
* @param cap_flags Bitmap of gimbal capability flags.
* @param gimbal_device_id Gimbal device ID that this gimbal manager is responsible for.
* @param tilt_max [rad] Maximum tilt/pitch angle (positive: up, negative: down)
* @param tilt_min [rad] Minimum tilt/pitch angle (positive: up, negative: down)
* @param tilt_rate_max [rad/s] Maximum tilt/pitch angular rate (positive: up, negative: down)
* @param pan_max [rad] Maximum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_min [rad] Minimum pan/yaw angle (positive: to the right, negative: to the left)
* @param pan_rate_max [rad/s] Minimum pan/yaw angular rate (positive: to the right, negative: to the left)
*/
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
static inline void mavlink_msg_gimbal_manager_information_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint32_t cap_flags, uint8_t gimbal_device_id, float tilt_max, float tilt_min, float tilt_rate_max, float pan_max, float pan_min, float pan_rate_max)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN];
_mav_put_uint32_t(buf, 0, time_boot_ms);
_mav_put_uint32_t(buf, 4, cap_flags);
_mav_put_float(buf, 8, tilt_max);
_mav_put_float(buf, 12, tilt_min);
_mav_put_float(buf, 16, tilt_rate_max);
_mav_put_float(buf, 20, pan_max);
_mav_put_float(buf, 24, pan_min);
_mav_put_float(buf, 28, pan_rate_max);
_mav_put_uint8_t(buf, 32, gimbal_device_id);
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, buf, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
#else
mavlink_gimbal_manager_information_t packet;
packet.time_boot_ms = time_boot_ms;
packet.cap_flags = cap_flags;
packet.tilt_max = tilt_max;
packet.tilt_min = tilt_min;
packet.tilt_rate_max = tilt_rate_max;
packet.pan_max = pan_max;
packet.pan_min = pan_min;
packet.pan_rate_max = pan_rate_max;
packet.gimbal_device_id = gimbal_device_id;
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, (const char*)&packet, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
#endif
}
/**
* @brief Send a gimbal_manager_information message
* @param chan MAVLink channel to send the message
* @param struct The MAVLink struct to serialize
*/
static inline void mavlink_msg_gimbal_manager_information_send_struct(mavlink_channel_t chan, const mavlink_gimbal_manager_information_t* gimbal_manager_information)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
mavlink_msg_gimbal_manager_information_send(chan, gimbal_manager_information->time_boot_ms, gimbal_manager_information->cap_flags, gimbal_manager_information->gimbal_device_id, gimbal_manager_information->tilt_max, gimbal_manager_information->tilt_min, gimbal_manager_information->tilt_rate_max, gimbal_manager_information->pan_max, gimbal_manager_information->pan_min, gimbal_manager_information->pan_rate_max);
#else
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, (const char*)gimbal_manager_information, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
#endif
}
#if MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
This varient of _send() can be used to save stack space by re-using
memory from the receive buffer. The caller provides a
mavlink_message_t which is the size of a full mavlink message. This
is usually the receive buffer for the channel, and allows a reply to an
incoming message with minimum stack space usage.
*/
static inline void mavlink_msg_gimbal_manager_information_send_buf(mavlink_message_t* msgbuf, mavlink_channel_t chan, uint32_t time_boot_ms, uint32_t cap_flags, uint8_t gimbal_device_id, float tilt_max, float tilt_min, float tilt_rate_max, float pan_max, float pan_min, float pan_rate_max)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char* buf = (char*)msgbuf;
_mav_put_uint32_t(buf, 0, time_boot_ms);
_mav_put_uint32_t(buf, 4, cap_flags);
_mav_put_float(buf, 8, tilt_max);
_mav_put_float(buf, 12, tilt_min);
_mav_put_float(buf, 16, tilt_rate_max);
_mav_put_float(buf, 20, pan_max);
_mav_put_float(buf, 24, pan_min);
_mav_put_float(buf, 28, pan_rate_max);
_mav_put_uint8_t(buf, 32, gimbal_device_id);
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, buf, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
#else
mavlink_gimbal_manager_information_t* packet = (mavlink_gimbal_manager_information_t*)msgbuf;
packet->time_boot_ms = time_boot_ms;
packet->cap_flags = cap_flags;
packet->tilt_max = tilt_max;
packet->tilt_min = tilt_min;
packet->tilt_rate_max = tilt_rate_max;
packet->pan_max = pan_max;
packet->pan_min = pan_min;
packet->pan_rate_max = pan_rate_max;
packet->gimbal_device_id = gimbal_device_id;
_mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, (const char*)packet, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_MIN_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_CRC);
#endif
}
#endif
#endif
// MESSAGE GIMBAL_MANAGER_INFORMATION UNPACKING
/**
* @brief Get field time_boot_ms from gimbal_manager_information message
*
* @return [ms] Timestamp (time since system boot).
*/
static inline uint32_t mavlink_msg_gimbal_manager_information_get_time_boot_ms(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint32_t(msg, 0);
}
/**
* @brief Get field cap_flags from gimbal_manager_information message
*
* @return Bitmap of gimbal capability flags.
*/
static inline uint32_t mavlink_msg_gimbal_manager_information_get_cap_flags(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint32_t(msg, 4);
}
/**
* @brief Get field gimbal_device_id from gimbal_manager_information message
*
* @return Gimbal device ID that this gimbal manager is responsible for.
*/
static inline uint8_t mavlink_msg_gimbal_manager_information_get_gimbal_device_id(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint8_t(msg, 32);
}
/**
* @brief Get field tilt_max from gimbal_manager_information message
*
* @return [rad] Maximum tilt/pitch angle (positive: up, negative: down)
*/
static inline float mavlink_msg_gimbal_manager_information_get_tilt_max(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 8);
}
/**
* @brief Get field tilt_min from gimbal_manager_information message
*
* @return [rad] Minimum tilt/pitch angle (positive: up, negative: down)
*/
static inline float mavlink_msg_gimbal_manager_information_get_tilt_min(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 12);
}
/**
* @brief Get field tilt_rate_max from gimbal_manager_information message
*
* @return [rad/s] Maximum tilt/pitch angular rate (positive: up, negative: down)
*/
static inline float mavlink_msg_gimbal_manager_information_get_tilt_rate_max(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 16);
}
/**
* @brief Get field pan_max from gimbal_manager_information message
*
* @return [rad] Maximum pan/yaw angle (positive: to the right, negative: to the left)
*/
static inline float mavlink_msg_gimbal_manager_information_get_pan_max(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 20);
}
/**
* @brief Get field pan_min from gimbal_manager_information message
*
* @return [rad] Minimum pan/yaw angle (positive: to the right, negative: to the left)
*/
static inline float mavlink_msg_gimbal_manager_information_get_pan_min(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 24);
}
/**
* @brief Get field pan_rate_max from gimbal_manager_information message
*
* @return [rad/s] Minimum pan/yaw angular rate (positive: to the right, negative: to the left)
*/
static inline float mavlink_msg_gimbal_manager_information_get_pan_rate_max(const mavlink_message_t* msg)
{
return _MAV_RETURN_float(msg, 28);
}
/**
* @brief Decode a gimbal_manager_information message into a struct
*
* @param msg The message to decode
* @param gimbal_manager_information C-struct to decode the message contents into
*/
static inline void mavlink_msg_gimbal_manager_information_decode(const mavlink_message_t* msg, mavlink_gimbal_manager_information_t* gimbal_manager_information)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
gimbal_manager_information->time_boot_ms = mavlink_msg_gimbal_manager_information_get_time_boot_ms(msg);
gimbal_manager_information->cap_flags = mavlink_msg_gimbal_manager_information_get_cap_flags(msg);
gimbal_manager_information->tilt_max = mavlink_msg_gimbal_manager_information_get_tilt_max(msg);
gimbal_manager_information->tilt_min = mavlink_msg_gimbal_manager_information_get_tilt_min(msg);
gimbal_manager_information->tilt_rate_max = mavlink_msg_gimbal_manager_information_get_tilt_rate_max(msg);
gimbal_manager_information->pan_max = mavlink_msg_gimbal_manager_information_get_pan_max(msg);
gimbal_manager_information->pan_min = mavlink_msg_gimbal_manager_information_get_pan_min(msg);
gimbal_manager_information->pan_rate_max = mavlink_msg_gimbal_manager_information_get_pan_rate_max(msg);
gimbal_manager_information->gimbal_device_id = mavlink_msg_gimbal_manager_information_get_gimbal_device_id(msg);
#else
uint8_t len = msg->len < MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN ? msg->len : MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN;
memset(gimbal_manager_information, 0, MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION_LEN);
memcpy(gimbal_manager_information, _MAV_PAYLOAD(msg), len);
#endif
}
|
009f69fde93fc55beaac33038f5a9ccf29700e52
|
e5ec9a33aaca93a653df46e7d3c351ece1b4abc5
|
/ZQ_GEMM/math/zq_gemm_32f_auto.c
|
6f9877944c70824e36269473cfcacbe413cc6006
|
[
"MIT"
] |
permissive
|
zuoqing1988/ZQCNN
|
0b0dbe79acf3094c252e6016dca0dbf37134ce37
|
9c89e94debaa9a241d2ac0cbc7d32c7bb8436490
|
refs/heads/master
| 2022-08-28T08:09:58.698706
| 2022-08-22T04:20:27
| 2022-08-22T04:20:27
| 132,091,868
| 2,152
| 487
|
MIT
| 2020-10-23T07:37:06
| 2018-05-04T05:30:54
|
Objective-C
|
UTF-8
|
C
| false
| false
| 14,790
|
c
|
zq_gemm_32f_auto.c
|
#include "zq_gemm_32f_align_c.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#if __ARM_NEON
#define SWAP_A_Bt \
if (M*N < 0.1*(M*N*K) && M + 8 < N) \
{ \
swap = 1; \
A = oldB; \
Bt = oldA; \
lda = old_ldb; \
ldb = old_lda; \
M = old_N; \
N = old_M; \
ldc = N; \
C = _aligned_malloc(M*N * sizeof(float), 32); \
}
#define SWAP_C \
if (swap == 1) \
{ \
for (n = 0; n < N; n++) \
{ \
for (m = 0; m < M; m++) \
{ \
old_C[n*old_ldc + m] = C[m*ldc + n]; \
} \
} \
_aligned_free(C); \
}
int zq_gemm_32f_AnoTrans_Btrans_special(int M, int N, int K, const float* A, int lda, const float* Bt, int ldb, float* C, int ldc)
{
const float* oldA = A, *oldB = Bt;
float* old_C = C;
int old_lda = lda, old_ldb = ldb, old_ldc = ldc, old_M = M, old_N = N;
int m, n;
int swap = 0;
int handled = 0;
#if __ARM_NEON_ARMV8
if (K == 16)
{
if ((M == 576 && N == 32) //det3-dw48-fast
|| (M == 121 && N == 32) //det2-dw24-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 24)
{
if ((M >= 1 && N == 2) //det1-dw20-fast
|| (M >= 1 && N == 4) //det1-dw20-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N8(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 28)
{
if (
(M == 3136 && N == 64) //mobilefacenet
|| (M == 8836 && N == 32) //det5-dw96-v2s
|| (M % 2304 == 0 && N == 16) //det3-dw48-fast
|| (M % 484 == 0 && N == 16) //det2-dw24-fast
|| (M >= 2500 && N == 8) //det1-dw20-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 32)
{
if ((M == 8649 && N == 32) //det5-dw96-v2s
|| (M == 2116 && N == 64) //det5-dw96-v2s
|| (M == 144 && N == 64) //det3-dw48-fast
|| (M == 25 && N == 64) //det2-dw24-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 64)
{
if (
//(M == 3136 && N == 128) //mobilefacenet
//||
(M == 3136 && N == 64) //mobilefacenet-res2-6-10-2
|| (M == 2025 && N == 64) //det5-dw96-v2s
|| (M == 484 && N == 64) //det5-dw96-v2s
|| (M == 441 && N == 64) //det5-dw96-v2s
|| (M == 25 && N == 64) //det3-dw48-fast
|| (M == 9 && N == 128) //det3-dw48-fast && det2-dw24-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 128)
{
if ((M == 16 && N == 256) //det5-dw96-v2s
|| (M >= 1 && N == 2) //det3-dw48-fast && det2-dw24-fast
|| (M >= 1 && N == 4) //det3-dw48-fast && det2-dw24-fast
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 256)
{
if ((M == 9 && N == 256) //det5-dw96-v2s
|| (M == 1 && N == 212) //det5-dw96-v2s
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 512)
{
if ((M == 1 && (N == 128 || N == 256 || N == 512)) ////mobilefacenet & mobilefacenet-res2-6-10-2
|| (M == 49 && N == 512) //mobilefacenet-res2-6-10-2
)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
#endif
return handled;
}
#if __ARM_NEON_ARMV8
void zq_gemm_32f_AnoTrans_Btrans_auto(int M, int N, int K, const float* A, int lda, const float* Bt, int ldb, float* C, int ldc)
{
const float* oldA = A, *oldB = Bt;
float* old_C = C;
int old_lda = lda, old_ldb = ldb, old_ldc = ldc, old_M = M, old_N = N;
int m, n;
int swap = 0;
int handled = 0;
if (K == 8)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 16)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 24)
{
if (N == 8 || N == 16)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N8(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 27) //3*3*3
{
if (N <= 16)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (N <= 128)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 28)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 32)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 64)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 72) // 3*3*8
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
//back up methods
if (handled == 0)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
#else // not ARMV8
void zq_gemm_32f_AnoTrans_Btrans_auto(int M, int N, int K, const float* A, int lda, const float* Bt, int ldb, float* C, int ldc)
{
const float* oldA = A, *oldB = Bt;
float* old_C = C;
int old_lda = lda, old_ldb = ldb, old_ldc = ldc, old_M = M, old_N = N;
int m, n;
int swap = 0;
int handled = 0;
if (K == 16)
{
if (N >= 8)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 27) //3*3*3
{
if (N <= 16)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (N <= 128)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 28)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (K == 32)
{
if (N >= 8)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 64)
{
if (N >= 8)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 72) // 3*3*8
{
if (N <= 64)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (N <= 128)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 128)
{
if (N >= 256)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 144) // 3*3*16
{
if (N <= 32)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
else if (N <= 128)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 256)
{
if (N >= 256)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 512)
{
if (N >= 256)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
else if (K == 1024)
{
if (N >= 256)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
SWAP_C;
}
}
//back up methods
if (handled == 0)
{
if (K <= 64)
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else
{
SWAP_A_Bt;
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
SWAP_C;
}
}
#endif// __ARM_NEON_ARMV8
#else // not __ARM_NEON
void zq_gemm_32f_AnoTrans_Btrans_auto(int M, int N, int K, const float* A, int lda, const float* Bt, int ldb, float* C, int ldc)
{
const float* oldA = A, *oldB = Bt;
float* old_C = C;
int old_lda = lda, old_ldb = ldb, old_ldc = ldc, old_M = M, old_N = N;
int m, n;
int swap = 0;
if (M*N < 0.1*(M*N*K) && M + 8 < N)
{
swap = 1;
A = oldB;
Bt = oldA;
lda = old_ldb;
ldb = old_lda;
M = old_N;
N = old_M;
ldc = N;
C = _aligned_malloc(M*N * sizeof(float), 32);
}
int handled = 0;
#if ZQ_CNN_USE_SSETYPE >= ZQ_CNN_SSETYPE_AVX
if (K == 16)
{
if (N >= 8)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 27) //3*3*3
{
if (N <= 16)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M1_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 28)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (K == 32)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 64)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 72) // 3*3*8
{
if (N <= 64)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M1_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 128)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 144) // 3*3*16
{
if (N <= 32)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M1_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 256)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 512)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 1024)
{
if (N >= 8)
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
//back up methods
if (handled == 0)
{
if (K <= 64)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else
{
zq_gemm_32f_align256bit_AnoTrans_Btrans_M4_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
#elif ZQ_CNN_USE_SSETYPE >= ZQ_CNN_SSETYPE_SSE
if (K == 16)
{
if (N >= 8)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 27) //3*3*3
{
if (N <= 16)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 28)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M2_N4(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (K == 32)
{
if (N >= 8)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 64)
{
if (N >= 8)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 72) // 3*3*8
{
if (N <= 64)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 128)
{
if (N >= 256)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 144) // 3*3*16
{
if (N <= 32)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else if (N <= 128)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 256)
{
if (N >= 256)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 512)
{
if (N >= 256)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
else if (K == 1024)
{
if (N >= 256)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
//back up methods
if (handled == 0)
{
if (K <= 64)
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M4_N2(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
else
{
zq_gemm_32f_align128bit_AnoTrans_Btrans_M8_N1(M, N, K, A, lda, Bt, ldb, C, ldc);
handled = 1;
}
}
#else
zq_gemm_32f_align0_AnoTrans_Btrans(M, N, K, A, lda, Bt, ldb, C, ldc);
#endif
if (swap == 1)
{
for (n = 0; n < N; n++)
{
for (m = 0; m < M; m++)
{
old_C[n*old_ldc + m] = C[m*ldc + n];
}
}
_aligned_free(C);
}
}
#endif
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
|
1c6da3692b12088d40ef1b894b86e1227654bc01
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/mips/include/asm/netlogic/xlr/pic.h
|
63c99176dffe98c29a31c16c561b3766c1ff0b87
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 10,838
|
h
|
pic.h
|
/*
* Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
* reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the NetLogic
* license below:
*
* 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 NETLOGIC ``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 NETLOGIC 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.
*/
#ifndef _ASM_NLM_XLR_PIC_H
#define _ASM_NLM_XLR_PIC_H
#define PIC_CLK_HZ 66666666
/* PIC hardware interrupt numbers */
#define PIC_IRT_WD_INDEX 0
#define PIC_IRT_TIMER_0_INDEX 1
#define PIC_IRT_TIMER_INDEX(i) ((i) + PIC_IRT_TIMER_0_INDEX)
#define PIC_IRT_TIMER_1_INDEX 2
#define PIC_IRT_TIMER_2_INDEX 3
#define PIC_IRT_TIMER_3_INDEX 4
#define PIC_IRT_TIMER_4_INDEX 5
#define PIC_IRT_TIMER_5_INDEX 6
#define PIC_IRT_TIMER_6_INDEX 7
#define PIC_IRT_TIMER_7_INDEX 8
#define PIC_IRT_CLOCK_INDEX PIC_IRT_TIMER_7_INDEX
#define PIC_IRT_UART_0_INDEX 9
#define PIC_IRT_UART_1_INDEX 10
#define PIC_IRT_I2C_0_INDEX 11
#define PIC_IRT_I2C_1_INDEX 12
#define PIC_IRT_PCMCIA_INDEX 13
#define PIC_IRT_GPIO_INDEX 14
#define PIC_IRT_HYPER_INDEX 15
#define PIC_IRT_PCIX_INDEX 16
/* XLS */
#define PIC_IRT_CDE_INDEX 15
#define PIC_IRT_BRIDGE_TB_XLS_INDEX 16
/* XLS */
#define PIC_IRT_GMAC0_INDEX 17
#define PIC_IRT_GMAC1_INDEX 18
#define PIC_IRT_GMAC2_INDEX 19
#define PIC_IRT_GMAC3_INDEX 20
#define PIC_IRT_XGS0_INDEX 21
#define PIC_IRT_XGS1_INDEX 22
#define PIC_IRT_HYPER_FATAL_INDEX 23
#define PIC_IRT_PCIX_FATAL_INDEX 24
#define PIC_IRT_BRIDGE_AERR_INDEX 25
#define PIC_IRT_BRIDGE_BERR_INDEX 26
#define PIC_IRT_BRIDGE_TB_XLR_INDEX 27
#define PIC_IRT_BRIDGE_AERR_NMI_INDEX 28
/* XLS */
#define PIC_IRT_GMAC4_INDEX 21
#define PIC_IRT_GMAC5_INDEX 22
#define PIC_IRT_GMAC6_INDEX 23
#define PIC_IRT_GMAC7_INDEX 24
#define PIC_IRT_BRIDGE_ERR_INDEX 25
#define PIC_IRT_PCIE_LINK0_INDEX 26
#define PIC_IRT_PCIE_LINK1_INDEX 27
#define PIC_IRT_PCIE_LINK2_INDEX 23
#define PIC_IRT_PCIE_LINK3_INDEX 24
#define PIC_IRT_PCIE_XLSB0_LINK2_INDEX 28
#define PIC_IRT_PCIE_XLSB0_LINK3_INDEX 29
#define PIC_IRT_SRIO_LINK0_INDEX 26
#define PIC_IRT_SRIO_LINK1_INDEX 27
#define PIC_IRT_SRIO_LINK2_INDEX 28
#define PIC_IRT_SRIO_LINK3_INDEX 29
#define PIC_IRT_PCIE_INT_INDEX 28
#define PIC_IRT_PCIE_FATAL_INDEX 29
#define PIC_IRT_GPIO_B_INDEX 30
#define PIC_IRT_USB_INDEX 31
/* XLS */
#define PIC_NUM_IRTS 32
#define PIC_CLOCK_TIMER 7
/* PIC Registers */
#define PIC_CTRL 0x00
#define PIC_CTRL_STE 8 /* timer enable start bit */
#define PIC_IPI 0x04
#define PIC_INT_ACK 0x06
#define WD_MAX_VAL_0 0x08
#define WD_MAX_VAL_1 0x09
#define WD_MASK_0 0x0a
#define WD_MASK_1 0x0b
#define WD_HEARBEAT_0 0x0c
#define WD_HEARBEAT_1 0x0d
#define PIC_IRT_0_BASE 0x40
#define PIC_IRT_1_BASE 0x80
#define PIC_TIMER_MAXVAL_0_BASE 0x100
#define PIC_TIMER_MAXVAL_1_BASE 0x110
#define PIC_TIMER_COUNT_0_BASE 0x120
#define PIC_TIMER_COUNT_1_BASE 0x130
#define PIC_IRT_0(picintr) (PIC_IRT_0_BASE + (picintr))
#define PIC_IRT_1(picintr) (PIC_IRT_1_BASE + (picintr))
#define PIC_TIMER_MAXVAL_0(i) (PIC_TIMER_MAXVAL_0_BASE + (i))
#define PIC_TIMER_MAXVAL_1(i) (PIC_TIMER_MAXVAL_1_BASE + (i))
#define PIC_TIMER_COUNT_0(i) (PIC_TIMER_COUNT_0_BASE + (i))
#define PIC_TIMER_COUNT_1(i) (PIC_TIMER_COUNT_0_BASE + (i))
/*
* Mapping between hardware interrupt numbers and IRQs on CPU
* we use a simple scheme to map PIC interrupts 0-31 to IRQs
* 8-39. This leaves the IRQ 0-7 for cpu interrupts like
* count/compare and FMN
*/
#define PIC_IRQ_BASE 8
#define PIC_INTR_TO_IRQ(i) (PIC_IRQ_BASE + (i))
#define PIC_IRQ_TO_INTR(i) ((i) - PIC_IRQ_BASE)
#define PIC_IRT_FIRST_IRQ PIC_IRQ_BASE
#define PIC_WD_IRQ PIC_INTR_TO_IRQ(PIC_IRT_WD_INDEX)
#define PIC_TIMER_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_0_INDEX)
#define PIC_TIMER_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_1_INDEX)
#define PIC_TIMER_2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_2_INDEX)
#define PIC_TIMER_3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_3_INDEX)
#define PIC_TIMER_4_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_4_INDEX)
#define PIC_TIMER_5_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_5_INDEX)
#define PIC_TIMER_6_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_6_INDEX)
#define PIC_TIMER_7_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_7_INDEX)
#define PIC_CLOCK_IRQ (PIC_TIMER_7_IRQ)
#define PIC_UART_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_UART_0_INDEX)
#define PIC_UART_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_UART_1_INDEX)
#define PIC_I2C_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_I2C_0_INDEX)
#define PIC_I2C_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_I2C_1_INDEX)
#define PIC_PCMCIA_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCMCIA_INDEX)
#define PIC_GPIO_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GPIO_INDEX)
#define PIC_HYPER_IRQ PIC_INTR_TO_IRQ(PIC_IRT_HYPER_INDEX)
#define PIC_PCIX_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIX_INDEX)
/* XLS */
#define PIC_CDE_IRQ PIC_INTR_TO_IRQ(PIC_IRT_CDE_INDEX)
#define PIC_BRIDGE_TB_XLS_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_TB_XLS_INDEX)
/* end XLS */
#define PIC_GMAC_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC0_INDEX)
#define PIC_GMAC_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC1_INDEX)
#define PIC_GMAC_2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC2_INDEX)
#define PIC_GMAC_3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC3_INDEX)
#define PIC_XGS_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_XGS0_INDEX)
#define PIC_XGS_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_XGS1_INDEX)
#define PIC_HYPER_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_HYPER_FATAL_INDEX)
#define PIC_PCIX_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIX_FATAL_INDEX)
#define PIC_BRIDGE_AERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_AERR_INDEX)
#define PIC_BRIDGE_BERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_BERR_INDEX)
#define PIC_BRIDGE_TB_XLR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_TB_XLR_INDEX)
#define PIC_BRIDGE_AERR_NMI_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_AERR_NMI_INDEX)
/* XLS defines */
#define PIC_GMAC_4_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC4_INDEX)
#define PIC_GMAC_5_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC5_INDEX)
#define PIC_GMAC_6_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC6_INDEX)
#define PIC_GMAC_7_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC7_INDEX)
#define PIC_BRIDGE_ERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_ERR_INDEX)
#define PIC_PCIE_LINK0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK0_INDEX)
#define PIC_PCIE_LINK1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK1_INDEX)
#define PIC_PCIE_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK2_INDEX)
#define PIC_PCIE_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK3_INDEX)
#define PIC_PCIE_XLSB0_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_XLSB0_LINK2_INDEX)
#define PIC_PCIE_XLSB0_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_XLSB0_LINK3_INDEX)
#define PIC_SRIO_LINK0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK0_INDEX)
#define PIC_SRIO_LINK1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK1_INDEX)
#define PIC_SRIO_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK2_INDEX)
#define PIC_SRIO_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK3_INDEX)
#define PIC_PCIE_INT_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_INT__INDEX)
#define PIC_PCIE_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_FATAL_INDEX)
#define PIC_GPIO_B_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GPIO_B_INDEX)
#define PIC_USB_IRQ PIC_INTR_TO_IRQ(PIC_IRT_USB_INDEX)
#define PIC_IRT_LAST_IRQ PIC_USB_IRQ
/* end XLS */
#ifndef __ASSEMBLY__
#define PIC_IRQ_IS_EDGE_TRIGGERED(irq) (((irq) >= PIC_TIMER_0_IRQ) && \
((irq) <= PIC_TIMER_7_IRQ))
#define PIC_IRQ_IS_IRT(irq) (((irq) >= PIC_IRT_FIRST_IRQ) && \
((irq) <= PIC_IRT_LAST_IRQ))
static inline int
nlm_irq_to_irt(int irq)
{
if (PIC_IRQ_IS_IRT(irq) == 0)
return -1;
return PIC_IRQ_TO_INTR(irq);
}
static inline int
nlm_irt_to_irq(int irt)
{
return PIC_INTR_TO_IRQ(irt);
}
static inline void
nlm_pic_enable_irt(uint64_t base, int irt)
{
uint32_t reg;
reg = nlm_read_reg(base, PIC_IRT_1(irt));
nlm_write_reg(base, PIC_IRT_1(irt), reg | (1u << 31));
}
static inline void
nlm_pic_disable_irt(uint64_t base, int irt)
{
uint32_t reg;
reg = nlm_read_reg(base, PIC_IRT_1(irt));
nlm_write_reg(base, PIC_IRT_1(irt), reg & ~(1u << 31));
}
static inline void
nlm_pic_send_ipi(uint64_t base, int hwt, int irq, int nmi)
{
unsigned int tid, pid;
tid = hwt & 0x3;
pid = (hwt >> 2) & 0x07;
nlm_write_reg(base, PIC_IPI,
(pid << 20) | (tid << 16) | (nmi << 8) | irq);
}
static inline void
nlm_pic_ack(uint64_t base, int irt)
{
nlm_write_reg(base, PIC_INT_ACK, 1u << irt);
}
static inline void
nlm_pic_init_irt(uint64_t base, int irt, int irq, int hwt, int en)
{
nlm_write_reg(base, PIC_IRT_0(irt), (1u << hwt));
/* local scheduling, invalid, level by default */
nlm_write_reg(base, PIC_IRT_1(irt),
(en << 30) | (1 << 6) | irq);
}
static inline uint64_t
nlm_pic_read_timer(uint64_t base, int timer)
{
uint32_t up1, up2, low;
up1 = nlm_read_reg(base, PIC_TIMER_COUNT_1(timer));
low = nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
up2 = nlm_read_reg(base, PIC_TIMER_COUNT_1(timer));
if (up1 != up2) /* wrapped, get the new low */
low = nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
return ((uint64_t)up2 << 32) | low;
}
static inline uint32_t
nlm_pic_read_timer32(uint64_t base, int timer)
{
return nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
}
static inline void
nlm_pic_set_timer(uint64_t base, int timer, uint64_t value, int irq, int cpu)
{
uint32_t up, low;
uint64_t pic_ctrl = nlm_read_reg(base, PIC_CTRL);
int en;
en = (irq > 0);
up = value >> 32;
low = value & 0xFFFFFFFF;
nlm_write_reg(base, PIC_TIMER_MAXVAL_0(timer), low);
nlm_write_reg(base, PIC_TIMER_MAXVAL_1(timer), up);
nlm_pic_init_irt(base, PIC_IRT_TIMER_INDEX(timer), irq, cpu, 0);
/* enable the timer */
pic_ctrl |= (1 << (PIC_CTRL_STE + timer));
nlm_write_reg(base, PIC_CTRL, pic_ctrl);
}
#endif
#endif /* _ASM_NLM_XLR_PIC_H */
|
131fc6cdf48c996398e61a7cbe95a27436169ade
|
fa86c0a8e2df3a0dc58fb3c309d509efcbf1c567
|
/src/openssl.h
|
a663c6fb132315767732d62547ddf51f65802eee
|
[
"BSD-3-Clause"
] |
permissive
|
libssh2/libssh2
|
26bc8337ea76cada4ca814a79a1023163d5dc6b9
|
88a960a86b9ffbabd17a4bbcf767e26514c4678e
|
refs/heads/master
| 2023-08-29T00:44:02.435773
| 2023-08-28T23:47:21
| 2023-08-28T23:47:21
| 31,701,703
| 1,275
| 680
|
BSD-3-Clause
| 2023-08-28T23:47:23
| 2015-03-05T07:38:30
|
C
|
UTF-8
|
C
| false
| false
| 15,658
|
h
|
openssl.h
|
#ifndef __LIBSSH2_OPENSSL_H
#define __LIBSSH2_OPENSSL_H
/* Copyright (C) Simon Josefsson
* Copyright (C) The Written Word, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 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.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl
/* disable deprecated warnings in OpenSSL 3 */
#define OPENSSL_SUPPRESS_DEPRECATED
#ifdef LIBSSH2_WOLFSSL
#include <wolfssl/options.h>
#include <openssl/ecdh.h>
#if defined(NO_DSA) || defined(HAVE_FIPS)
#define OPENSSL_NO_DSA
#endif
#if defined(NO_MD5) || defined(HAVE_FIPS)
#define OPENSSL_NO_MD5
#endif
#if !defined(WOLFSSL_RIPEMD) || defined(HAVE_FIPS)
#define OPENSSL_NO_RIPEMD
#endif
#if defined(NO_RC4) || defined(HAVE_FIPS)
#define OPENSSL_NO_RC4
#endif
#ifdef NO_DES3
#define OPENSSL_NO_DES
#endif
/* wolfSSL doesn't support Blowfish or CAST. */
#define OPENSSL_NO_BF
#define OPENSSL_NO_CAST
/* wolfSSL has no engine framework. */
#define OPENSSL_NO_ENGINE
#endif /* LIBSSH2_WOLFSSL */
#include <openssl/opensslconf.h>
#include <openssl/sha.h>
#include <openssl/rsa.h>
#ifndef OPENSSL_NO_ENGINE
#include <openssl/engine.h>
#endif
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_MD5
#include <openssl/md5.h>
#endif
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
#include <openssl/rand.h>
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L && \
!defined(LIBRESSL_VERSION_NUMBER)) || defined(LIBSSH2_WOLFSSL) || \
(defined(LIBRESSL_VERSION_NUMBER) && \
LIBRESSL_VERSION_NUMBER >= 0x3050000fL)
/* For wolfSSL, whether the structs are truly opaque or not, it's best to not
* rely on their internal data members being exposed publicly. */
# define HAVE_OPAQUE_STRUCTS 1
#endif
#ifdef OPENSSL_NO_RSA
# define LIBSSH2_RSA 0
# define LIBSSH2_RSA_SHA1 0
# define LIBSSH2_RSA_SHA2 0
#else
# define LIBSSH2_RSA 1
# define LIBSSH2_RSA_SHA1 1
# define LIBSSH2_RSA_SHA2 1
#endif
#ifdef OPENSSL_NO_DSA
# define LIBSSH2_DSA 0
#else
# define LIBSSH2_DSA 1
#endif
#if defined(OPENSSL_NO_ECDSA) || defined(OPENSSL_NO_EC)
# define LIBSSH2_ECDSA 0
#else
# define LIBSSH2_ECDSA 1
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && \
!defined(LIBRESSL_VERSION_NUMBER)) || \
(defined(LIBRESSL_VERSION_NUMBER) && \
LIBRESSL_VERSION_NUMBER >= 0x3070000fL)
# define LIBSSH2_ED25519 1
#else
# define LIBSSH2_ED25519 0
#endif
#ifdef OPENSSL_NO_MD5
# define LIBSSH2_MD5 0
#else
# define LIBSSH2_MD5 1
#endif
#if defined(OPENSSL_NO_RIPEMD) || defined(OPENSSL_NO_RMD160)
# define LIBSSH2_HMAC_RIPEMD 0
#else
# define LIBSSH2_HMAC_RIPEMD 1
#endif
#define LIBSSH2_HMAC_SHA256 1
#define LIBSSH2_HMAC_SHA512 1
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L && !defined(OPENSSL_NO_AES)) || \
(defined(LIBSSH2_WOLFSSL) && defined(WOLFSSL_AES_COUNTER))
# define LIBSSH2_AES_CTR 1
# define LIBSSH2_AES_CBC 1
#else
# define LIBSSH2_AES_CTR 0
# define LIBSSH2_AES_CBC 0
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x01010100fL && !defined(OPENSSL_NO_AES)) || \
(defined(LIBSSH2_WOLFSSL) && \
defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM))
# define LIBSSH2_AES_GCM 1
#else
# define LIBSSH2_AES_GCM 0
#endif
#ifdef OPENSSL_NO_BF
# define LIBSSH2_BLOWFISH 0
#else
# define LIBSSH2_BLOWFISH 1
#endif
#ifdef OPENSSL_NO_RC4
# define LIBSSH2_RC4 0
#else
# define LIBSSH2_RC4 1
#endif
#ifdef OPENSSL_NO_CAST
# define LIBSSH2_CAST 0
#else
# define LIBSSH2_CAST 1
#endif
#ifdef OPENSSL_NO_DES
# define LIBSSH2_3DES 0
#else
# define LIBSSH2_3DES 1
#endif
#include "crypto_config.h"
#define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1)
#define _libssh2_random(buf, len) \
_libssh2_openssl_random((buf), (len))
#define libssh2_prepare_iovec(vec, len) /* Empty. */
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha1_ctx EVP_MD_CTX *
#else
#define libssh2_sha1_ctx EVP_MD_CTX
#endif
/* returns 0 in case of failure */
int _libssh2_sha1_init(libssh2_sha1_ctx *ctx);
#define libssh2_sha1_init(x) _libssh2_sha1_init(x)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len)
#define libssh2_sha1_final(ctx, out) do { \
EVP_DigestFinal(ctx, out, NULL); \
EVP_MD_CTX_free(ctx); \
} while(0)
#else
#define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_sha1_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
#endif
int _libssh2_sha1(const unsigned char *message, size_t len,
unsigned char *out);
#define libssh2_sha1(x,y,z) _libssh2_sha1(x,y,z)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha256_ctx EVP_MD_CTX *
#else
#define libssh2_sha256_ctx EVP_MD_CTX
#endif
/* returns 0 in case of failure */
int _libssh2_sha256_init(libssh2_sha256_ctx *ctx);
#define libssh2_sha256_init(x) _libssh2_sha256_init(x)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha256_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len)
#define libssh2_sha256_final(ctx, out) do { \
EVP_DigestFinal(ctx, out, NULL); \
EVP_MD_CTX_free(ctx); \
} while(0)
#else
#define libssh2_sha256_update(ctx, data, len) \
EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_sha256_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
#endif
int _libssh2_sha256(const unsigned char *message, size_t len,
unsigned char *out);
#define libssh2_sha256(x,y,z) _libssh2_sha256(x,y,z)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha384_ctx EVP_MD_CTX *
#else
#define libssh2_sha384_ctx EVP_MD_CTX
#endif
/* returns 0 in case of failure */
int _libssh2_sha384_init(libssh2_sha384_ctx *ctx);
#define libssh2_sha384_init(x) _libssh2_sha384_init(x)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha384_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len)
#define libssh2_sha384_final(ctx, out) do { \
EVP_DigestFinal(ctx, out, NULL); \
EVP_MD_CTX_free(ctx); \
} while(0)
#else
#define libssh2_sha384_update(ctx, data, len) \
EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_sha384_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
#endif
int _libssh2_sha384(const unsigned char *message, size_t len,
unsigned char *out);
#define libssh2_sha384(x,y,z) _libssh2_sha384(x,y,z)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha512_ctx EVP_MD_CTX *
#else
#define libssh2_sha512_ctx EVP_MD_CTX
#endif
/* returns 0 in case of failure */
int _libssh2_sha512_init(libssh2_sha512_ctx *ctx);
#define libssh2_sha512_init(x) _libssh2_sha512_init(x)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_sha512_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len)
#define libssh2_sha512_final(ctx, out) do { \
EVP_DigestFinal(ctx, out, NULL); \
EVP_MD_CTX_free(ctx); \
} while(0)
#else
#define libssh2_sha512_update(ctx, data, len) \
EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_sha512_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
#endif
int _libssh2_sha512(const unsigned char *message, size_t len,
unsigned char *out);
#define libssh2_sha512(x,y,z) _libssh2_sha512(x,y,z)
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_md5_ctx EVP_MD_CTX *
#else
#define libssh2_md5_ctx EVP_MD_CTX
#endif
/* returns 0 in case of failure */
int _libssh2_md5_init(libssh2_md5_ctx *ctx);
#define libssh2_md5_init(x) _libssh2_md5_init(x)
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len)
#define libssh2_md5_final(ctx, out) do { \
EVP_DigestFinal(ctx, out, NULL); \
EVP_MD_CTX_free(ctx); \
} while(0)
#else
#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_md5_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
#endif
#endif
#ifdef HAVE_OPAQUE_STRUCTS
#define libssh2_hmac_ctx HMAC_CTX *
#define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new()
#define libssh2_hmac_sha1_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL)
#define libssh2_hmac_md5_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL)
#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL)
#define libssh2_hmac_sha256_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL)
#define libssh2_hmac_sha512_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL)
#ifdef LIBSSH2_WOLFSSL
/* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */
#define libssh2_hmac_update(ctx, data, datalen) \
HMAC_Update(ctx, data, (int)datalen)
#else
#define libssh2_hmac_update(ctx, data, datalen) \
HMAC_Update(ctx, data, datalen)
#endif /* LIBSSH2_WOLFSSL */
#define libssh2_hmac_final(ctx, data) HMAC_Final(ctx, data, NULL)
#define libssh2_hmac_cleanup(ctx) HMAC_CTX_free(*(ctx))
#else
#define libssh2_hmac_ctx HMAC_CTX
#define libssh2_hmac_ctx_init(ctx) \
HMAC_CTX_init(&ctx)
#define libssh2_hmac_sha1_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL)
#define libssh2_hmac_md5_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL)
#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL)
#define libssh2_hmac_sha256_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL)
#define libssh2_hmac_sha512_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL)
#define libssh2_hmac_update(ctx, data, datalen) \
HMAC_Update(&(ctx), data, datalen)
#define libssh2_hmac_final(ctx, data) HMAC_Final(&(ctx), data, NULL)
#define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx)
#endif
extern void _libssh2_openssl_crypto_init(void);
extern void _libssh2_openssl_crypto_exit(void);
#define libssh2_crypto_init() _libssh2_openssl_crypto_init()
#define libssh2_crypto_exit() _libssh2_openssl_crypto_exit()
#if LIBSSH2_RSA
#define libssh2_rsa_ctx RSA
#define _libssh2_rsa_free(rsactx) RSA_free(rsactx)
#endif
#if LIBSSH2_DSA
#define libssh2_dsa_ctx DSA
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
#endif
#if LIBSSH2_ECDSA
#define libssh2_ecdsa_ctx EC_KEY
#define _libssh2_ecdsa_free(ecdsactx) EC_KEY_free(ecdsactx)
#define _libssh2_ec_key EC_KEY
typedef enum {
LIBSSH2_EC_CURVE_NISTP256 = NID_X9_62_prime256v1,
LIBSSH2_EC_CURVE_NISTP384 = NID_secp384r1,
LIBSSH2_EC_CURVE_NISTP521 = NID_secp521r1
}
libssh2_curve_type;
#else
#define _libssh2_ec_key void
#endif /* LIBSSH2_ECDSA */
#if LIBSSH2_ED25519
#define libssh2_ed25519_ctx EVP_PKEY
#define _libssh2_ed25519_free(ctx) EVP_PKEY_free(ctx)
#endif /* ED25519 */
#define _libssh2_cipher_type(name) const EVP_CIPHER *(*name)(void)
#ifdef HAVE_OPAQUE_STRUCTS
#define _libssh2_cipher_ctx EVP_CIPHER_CTX *
#else
#define _libssh2_cipher_ctx EVP_CIPHER_CTX
#endif
#define _libssh2_cipher_aes256gcm EVP_aes_256_gcm
#define _libssh2_cipher_aes128gcm EVP_aes_128_gcm
#define _libssh2_cipher_aes256 EVP_aes_256_cbc
#define _libssh2_cipher_aes192 EVP_aes_192_cbc
#define _libssh2_cipher_aes128 EVP_aes_128_cbc
#define _libssh2_cipher_aes128ctr EVP_aes_128_ctr
#define _libssh2_cipher_aes192ctr EVP_aes_192_ctr
#define _libssh2_cipher_aes256ctr EVP_aes_256_ctr
#define _libssh2_cipher_blowfish EVP_bf_cbc
#define _libssh2_cipher_arcfour EVP_rc4
#define _libssh2_cipher_cast5 EVP_cast5_cbc
#define _libssh2_cipher_3des EVP_des_ede3_cbc
#ifdef HAVE_OPAQUE_STRUCTS
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_free(*(ctx))
#else
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
#endif
#define _libssh2_bn BIGNUM
#define _libssh2_bn_ctx BN_CTX
#define _libssh2_bn_ctx_new() BN_CTX_new()
#define _libssh2_bn_ctx_free(bnctx) BN_CTX_free(bnctx)
#define _libssh2_bn_init() BN_new()
#define _libssh2_bn_init_from_bin() _libssh2_bn_init()
#define _libssh2_bn_set_word(bn, val) BN_set_word(bn, val)
#define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, (int)len, bn)
#define _libssh2_bn_to_bin(bn, val) BN_bn2bin(bn, val)
#define _libssh2_bn_bytes(bn) BN_num_bytes(bn)
#define _libssh2_bn_bits(bn) BN_num_bits(bn)
#define _libssh2_bn_free(bn) BN_clear_free(bn)
/* Default generate and safe prime sizes for
diffie-hellman-group-exchange-sha1 */
#define LIBSSH2_DH_GEX_MINGROUP 2048
#define LIBSSH2_DH_GEX_OPTGROUP 4096
#define LIBSSH2_DH_GEX_MAXGROUP 8192
#define LIBSSH2_DH_MAX_MODULUS_BITS 16384
#define _libssh2_dh_ctx BIGNUM *
#define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx)
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
_libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx)
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
_libssh2_dh_secret(dhctx, secret, f, p, bnctx)
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx);
extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public,
_libssh2_bn *g, _libssh2_bn *p,
int group_order,
_libssh2_bn_ctx *bnctx);
extern int _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret,
_libssh2_bn *f, _libssh2_bn *p,
_libssh2_bn_ctx *bnctx);
extern void _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx);
extern int _libssh2_openssl_random(void *buf, size_t len);
const EVP_CIPHER *_libssh2_EVP_aes_128_ctr(void);
const EVP_CIPHER *_libssh2_EVP_aes_192_ctr(void);
const EVP_CIPHER *_libssh2_EVP_aes_256_ctr(void);
#endif /* __LIBSSH2_OPENSSL_H */
|
17823b46df80d95be2aaedb3cefa4d5ad9fdfd4c
|
baa9fffc817a2a993d4ecc774d3f277783308c20
|
/src/uct/sm/mm/base/mm_ep.c
|
bdc5d172abf37a3a5535bedc0145a462ba8f4e35
|
[
"BSD-3-Clause"
] |
permissive
|
openucx/ucx
|
9a0f2205295afbdf3cff14b5d24af781b123f5ea
|
73a48700badb7cbace64d94b82f408e2a26fca32
|
refs/heads/master
| 2023-09-01T16:51:26.913950
| 2023-09-01T13:02:25
| 2023-09-01T13:02:25
| 25,379,390
| 966
| 420
|
NOASSERTION
| 2023-09-14T12:29:35
| 2014-10-17T22:17:24
|
C
|
UTF-8
|
C
| false
| false
| 20,227
|
c
|
mm_ep.c
|
/**
* Copyright (C) UT-Battelle, LLC. 2015. ALL RIGHTS RESERVED.
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2019. ALL RIGHTS RESERVED.
* Copyright (C) ARM Ltd. 2016. ALL RIGHTS RESERVED.
* See file LICENSE for terms.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "mm_ep.h"
#include "uct/sm/base/sm_ep.h"
#include <uct/base/uct_iov.inl>
#include <ucs/arch/atomic.h>
/* send modes */
typedef enum {
UCT_MM_SEND_AM_BCOPY,
UCT_MM_SEND_AM_SHORT,
UCT_MM_SEND_AM_SHORT_IOV
} uct_mm_send_op_t;
/* Check if the resources on the remote peer are available for sending to it.
* i.e. check if the remote receive FIFO has room in it.
* return 1 if can send.
* return 0 if can't send.
* We compare after casting to int32 in order to ignore the event arm bit.
*/
#define UCT_MM_EP_IS_ABLE_TO_SEND(_head, _tail, _fifo_size) \
ucs_likely((int32_t)((_head) - (_tail)) < (int32_t)(_fifo_size))
static UCS_F_NOINLINE ucs_status_t
uct_mm_ep_attach_remote_seg(uct_mm_ep_t *ep, uct_mm_seg_id_t seg_id,
size_t length, void **address_p)
{
uct_mm_iface_t *iface = ucs_derived_of(ep->super.super.iface,
uct_mm_iface_t);
uct_mm_remote_seg_t *remote_seg;
ucs_status_t status;
khiter_t khiter;
int khret;
khiter = kh_put(uct_mm_remote_seg, &ep->remote_segs, seg_id, &khret);
if (khret == UCS_KH_PUT_FAILED) {
ucs_error("failed to add remote segment to mm ep hash");
return UCS_ERR_NO_MEMORY;
}
/* we expect the key would either be
* never used (BUCKET_EMPTY) or deleted (BUCKET_CLEAR) */
ucs_assert_always((khret == UCS_KH_PUT_BUCKET_EMPTY) ||
(khret == UCS_KH_PUT_BUCKET_CLEAR));
remote_seg = &kh_val(&ep->remote_segs, khiter);
status = uct_mm_iface_mapper_call(iface, mem_attach, seg_id, length,
ep->remote_iface_addr, remote_seg);
if (status != UCS_OK) {
kh_del(uct_mm_remote_seg, &ep->remote_segs, khiter);
return status;
}
*address_p = remote_seg->address;
ucs_debug("mm_ep %p: attached remote segment id 0x%"PRIx64" at %p cookie %p",
ep, seg_id, remote_seg->address, remote_seg->cookie);
return UCS_OK;
}
static UCS_F_ALWAYS_INLINE ucs_status_t
uct_mm_ep_get_remote_seg(uct_mm_ep_t *ep, uct_mm_seg_id_t seg_id, size_t length,
void **address_p)
{
khiter_t khiter;
/* fast path - segment is already present */
khiter = kh_get(uct_mm_remote_seg, &ep->remote_segs, seg_id);
if (ucs_likely(khiter != kh_end(&ep->remote_segs))) {
*address_p = kh_val(&ep->remote_segs, khiter).address;
return UCS_OK;
}
/* slow path - attach new segment */
return uct_mm_ep_attach_remote_seg(ep, seg_id, length, address_p);
}
/* send a signal to remote interface using Unix-domain socket */
static void uct_mm_ep_signal_remote(uct_mm_ep_t *ep)
{
uct_mm_iface_t *iface = ucs_derived_of(ep->super.super.iface, uct_mm_iface_t);
char dummy = 0;
int ret;
ucs_trace("ep %p: signal remote", ep);
for (;;) {
ret = sendto(iface->signal_fd, &dummy, sizeof(dummy), 0,
(const struct sockaddr*)&ep->fifo_ctl->signal_sockaddr,
ep->fifo_ctl->signal_addrlen);
if (ucs_unlikely(ret < 0)) {
if (errno == EINTR) {
/* Interrupted system call - retry */
continue;
}
if ((errno == EAGAIN) || (errno == ECONNREFUSED)) {
/* If we failed to signal because buffer is full - ignore the error
* since it means the remote side would get a signal anyway.
* If the remote side is not there - ignore the error as well.
*/
ucs_trace("failed to send wakeup signal: %m");
return;
} else {
ucs_warn("failed to send wakeup signal: %m");
return;
}
} else {
ucs_assert(ret == sizeof(dummy));
ucs_trace("sent wakeup from socket %d to %s", iface->signal_fd,
ep->fifo_ctl->signal_sockaddr.sun_path);
return;
}
}
}
void uct_mm_ep_cleanup_remote_segs(uct_mm_ep_t *ep)
{
uct_mm_iface_t *iface = ucs_derived_of(ep->super.super.iface,
uct_mm_iface_t);
uct_mm_remote_seg_t remote_seg;
kh_foreach_value(&ep->remote_segs, remote_seg, {
uct_mm_iface_mapper_call(iface, mem_detach, &remote_seg);
})
kh_destroy_inplace(uct_mm_remote_seg, &ep->remote_segs);
}
static UCS_CLASS_INIT_FUNC(uct_mm_ep_t, const uct_ep_params_t *params)
{
uct_mm_iface_t *iface = ucs_derived_of(params->iface, uct_mm_iface_t);
uct_mm_md_t *md = ucs_derived_of(iface->super.super.md, uct_mm_md_t);
const uct_mm_iface_addr_t *addr = (const void *)params->iface_addr;
ucs_status_t status;
void *fifo_ptr;
UCT_EP_PARAMS_CHECK_DEV_IFACE_ADDRS(params);
UCS_CLASS_CALL_SUPER_INIT(uct_base_ep_t, &iface->super.super);
kh_init_inplace(uct_mm_remote_seg, &self->remote_segs);
ucs_arbiter_group_init(&self->arb_group);
/* save remote md address */
if (md->iface_addr_len > 0) {
self->remote_iface_addr = ucs_malloc(md->iface_addr_len, "mm_md_addr");
if (self->remote_iface_addr == NULL) {
status = UCS_ERR_NO_MEMORY;
goto err;
}
memcpy(self->remote_iface_addr, addr + 1, md->iface_addr_len);
} else {
self->remote_iface_addr = NULL;
}
/* Attach the remote FIFO, use the same method as bcopy descriptors */
status = uct_mm_ep_get_remote_seg(self, addr->fifo_seg_id,
UCT_MM_GET_FIFO_SIZE(iface), &fifo_ptr);
if (status != UCS_OK) {
ucs_error("mm ep failed to connect to remote FIFO id 0x%"PRIx64": %s",
addr->fifo_seg_id, ucs_status_string(status));
goto err_free_md_addr;
}
/* Initialize remote FIFO control structure */
uct_mm_iface_set_fifo_ptrs(fifo_ptr, &self->fifo_ctl, &self->fifo_elems);
self->cached_tail = self->fifo_ctl->tail;
ucs_arbiter_elem_init(&self->arb_elem);
status = uct_ep_keepalive_init(&self->keepalive, self->fifo_ctl->pid);
if (status != UCS_OK) {
goto err_free_segs;
}
ucs_debug("created mm ep %p, connected to remote FIFO id 0x%"PRIx64,
self, addr->fifo_seg_id);
return UCS_OK;
err_free_segs:
uct_mm_ep_cleanup_remote_segs(self);
err_free_md_addr:
ucs_free(self->remote_iface_addr);
err:
return status;
}
static UCS_CLASS_CLEANUP_FUNC(uct_mm_ep_t)
{
uct_mm_ep_pending_purge(&self->super.super, NULL, NULL);
uct_mm_ep_cleanup_remote_segs(self);
ucs_free(self->remote_iface_addr);
}
UCS_CLASS_DEFINE(uct_mm_ep_t, uct_base_ep_t)
UCS_CLASS_DEFINE_NEW_FUNC(uct_mm_ep_t, uct_ep_t, const uct_ep_params_t *);
UCS_CLASS_DEFINE_DELETE_FUNC(uct_mm_ep_t, uct_ep_t);
static inline ucs_status_t
uct_mm_ep_get_remote_elem(uct_mm_ep_t *ep, uint64_t head,
uct_mm_fifo_element_t **elem)
{
uct_mm_iface_t *iface = ucs_derived_of(ep->super.super.iface, uct_mm_iface_t);
uint64_t new_head, prev_head;
uint64_t elem_index; /* index of the element to write */
elem_index = head & iface->fifo_mask;
*elem = UCT_MM_IFACE_GET_FIFO_ELEM(iface, ep->fifo_elems, elem_index);
new_head = (head + 1) & ~UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED;
/* try to get ownership of the head element */
prev_head = ucs_atomic_cswap64(ucs_unaligned_ptr(&ep->fifo_ctl->head), head,
new_head);
if (prev_head != head) {
return UCS_ERR_NO_RESOURCE;
}
return UCS_OK;
}
static inline void uct_mm_ep_update_cached_tail(uct_mm_ep_t *ep)
{
ucs_memory_cpu_load_fence();
ep->cached_tail = ep->fifo_ctl->tail;
}
static UCS_F_ALWAYS_INLINE void uct_mm_ep_peer_check(uct_mm_ep_t *ep,
unsigned flags)
{
if (ucs_unlikely(flags & UCT_SEND_FLAG_PEER_CHECK)) {
uct_ep_keepalive_check(&ep->super.super, &ep->keepalive,
ep->fifo_ctl->pid, 0, NULL);
}
}
static UCS_F_ALWAYS_INLINE ucs_status_t
uct_mm_ep_no_resources_handle(uct_mm_ep_t *ep, unsigned flags)
{
UCS_STATS_UPDATE_COUNTER(ep->super.stats, UCT_EP_STAT_NO_RES, 1);
uct_mm_ep_peer_check(ep, flags);
return UCS_ERR_NO_RESOURCE;
}
/* A common mm active message sending function.
* The first parameter indicates the origin of the call.
*/
static UCS_F_ALWAYS_INLINE ssize_t uct_mm_ep_am_common_send(
uct_mm_send_op_t send_op, uct_mm_ep_t *ep, uct_mm_iface_t *iface,
uint8_t am_id, size_t length, uint64_t header, const void *payload,
uct_pack_callback_t pack_cb, void *arg, const uct_iov_t *iov,
size_t iovcnt, unsigned flags)
{
uct_mm_fifo_element_t *elem;
ucs_status_t status;
void *base_address;
uint8_t elem_flags;
uint64_t head;
ucs_iov_iter_t iov_iter;
void *desc_data;
UCT_CHECK_AM_ID(am_id);
retry:
head = ep->fifo_ctl->head;
/* check if there is room in the remote process's receive FIFO to write */
if (!UCT_MM_EP_IS_ABLE_TO_SEND(head, ep->cached_tail, iface->config.fifo_size)) {
if (!ucs_arbiter_group_is_empty(&ep->arb_group)) {
/* pending isn't empty. don't send now to prevent out-of-order sending */
return uct_mm_ep_no_resources_handle(ep, flags);
} else {
/* pending is empty. update the local copy of the tail to its
* actual value on the remote peer */
uct_mm_ep_update_cached_tail(ep);
if (!UCT_MM_EP_IS_ABLE_TO_SEND(head, ep->cached_tail, iface->config.fifo_size)) {
ucs_arbiter_group_push_head_elem_always(&ep->arb_group,
&ep->arb_elem);
ucs_arbiter_group_schedule_nonempty(&iface->arbiter,
&ep->arb_group);
return uct_mm_ep_no_resources_handle(ep, flags);
}
}
}
status = uct_mm_ep_get_remote_elem(ep, head, &elem);
if (status != UCS_OK) {
ucs_assert(status == UCS_ERR_NO_RESOURCE);
ucs_trace_poll("couldn't get an available FIFO element. retrying");
goto retry;
}
switch (send_op) {
case UCT_MM_SEND_AM_SHORT:
/* write to the remote FIFO */
uct_am_short_fill_data(elem + 1, header, payload, length);
elem_flags = UCT_MM_FIFO_ELEM_FLAG_INLINE;
elem->length = length + sizeof(header);
uct_mm_iface_trace_am(iface, UCT_AM_TRACE_TYPE_SEND, elem_flags, am_id,
elem + 1, elem->length,
head & ~UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED);
UCT_TL_EP_STAT_OP(&ep->super, AM, SHORT, sizeof(header) + length);
break;
case UCT_MM_SEND_AM_BCOPY:
/* write to the remote descriptor */
/* get the base_address: local ptr to remote memory chunk after attaching to it */
status = uct_mm_ep_get_remote_seg(ep, elem->desc.seg_id,
elem->desc.seg_size, &base_address);
if (ucs_unlikely(status != UCS_OK)) {
return status;
}
desc_data = UCS_PTR_BYTE_OFFSET(base_address, elem->desc.offset);
length = pack_cb(desc_data, arg);
elem_flags = 0;
elem->length = length;
uct_mm_iface_trace_am(iface, UCT_AM_TRACE_TYPE_SEND, elem_flags, am_id,
desc_data, elem->length,
head & ~UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED);
UCT_TL_EP_STAT_OP(&ep->super, AM, BCOPY, length);
break;
case UCT_MM_SEND_AM_SHORT_IOV:
elem_flags = UCT_MM_FIFO_ELEM_FLAG_INLINE;
ucs_iov_iter_init(&iov_iter);
elem->length = uct_iov_to_buffer(iov, iovcnt, &iov_iter, elem + 1,
SIZE_MAX);
uct_mm_iface_trace_am(iface, UCT_AM_TRACE_TYPE_SEND, elem_flags, am_id,
elem + 1, elem->length,
head & ~UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED);
UCT_TL_EP_STAT_OP(&ep->super, AM, SHORT, elem->length);
break;
}
elem->am_id = am_id;
/* memory barrier - make sure that the memory is flushed before setting the
* 'writing is complete' flag which the reader checks */
ucs_memory_cpu_store_fence();
/* set the owner bit to indicate that the writing is complete.
* the owner bit flips after every FIFO wraparound */
if (head & iface->config.fifo_size) {
elem_flags |= UCT_MM_FIFO_ELEM_FLAG_OWNER;
}
elem->flags = elem_flags;
if (ucs_unlikely(head & UCT_MM_IFACE_FIFO_HEAD_EVENT_ARMED)) {
uct_mm_ep_signal_remote(ep);
}
uct_mm_ep_peer_check(ep, flags);
switch (send_op) {
case UCT_MM_SEND_AM_SHORT:
case UCT_MM_SEND_AM_SHORT_IOV:
return UCS_OK;
case UCT_MM_SEND_AM_BCOPY:
return length;
default:
return UCS_ERR_INVALID_PARAM;
}
}
ucs_status_t uct_mm_ep_am_short(uct_ep_h tl_ep, uint8_t id, uint64_t header,
const void *payload, unsigned length)
{
uct_mm_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_mm_iface_t);
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
UCT_CHECK_LENGTH(length + sizeof(header), 0,
iface->config.fifo_elem_size - sizeof(uct_mm_fifo_element_t),
"am_short");
return (ucs_status_t)uct_mm_ep_am_common_send(UCT_MM_SEND_AM_SHORT, ep,
iface, id, length, header,
payload, NULL, NULL, NULL, 0,
0);
}
ucs_status_t uct_mm_ep_am_short_iov(uct_ep_h tl_ep, uint8_t id,
const uct_iov_t *iov, size_t iovcnt)
{
uct_mm_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_mm_iface_t);
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
UCT_CHECK_LENGTH(uct_iov_total_length(iov, iovcnt), 0,
iface->config.fifo_elem_size -
sizeof(uct_mm_fifo_element_t),
"am_short_iov");
return (ucs_status_t)uct_mm_ep_am_common_send(UCT_MM_SEND_AM_SHORT_IOV, ep,
iface, id, 0, 0, NULL, NULL,
NULL, iov, iovcnt, 0);
}
ssize_t uct_mm_ep_am_bcopy(uct_ep_h tl_ep, uint8_t id, uct_pack_callback_t pack_cb,
void *arg, unsigned flags)
{
uct_mm_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_mm_iface_t);
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
return uct_mm_ep_am_common_send(UCT_MM_SEND_AM_BCOPY, ep, iface, id, 0, 0,
NULL, pack_cb, arg, NULL, 0, flags);
}
static inline int uct_mm_ep_has_tx_resources(uct_mm_ep_t *ep)
{
uct_mm_iface_t *iface = ucs_derived_of(ep->super.super.iface, uct_mm_iface_t);
return UCT_MM_EP_IS_ABLE_TO_SEND(ep->fifo_ctl->head, ep->cached_tail,
iface->config.fifo_size);
}
ucs_status_t uct_mm_ep_pending_add(uct_ep_h tl_ep, uct_pending_req_t *n,
unsigned flags)
{
uct_mm_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_mm_iface_t);
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
/* check if resources became available */
if (uct_mm_ep_has_tx_resources(ep)) {
ucs_assert(ucs_arbiter_group_is_empty(&ep->arb_group));
return UCS_ERR_BUSY;
}
UCS_STATIC_ASSERT(sizeof(uct_pending_req_priv_arb_t) <=
UCT_PENDING_REQ_PRIV_LEN);
uct_pending_req_arb_group_push(&ep->arb_group, n);
/* add the ep's group to the arbiter */
ucs_arbiter_group_schedule(&iface->arbiter, &ep->arb_group);
UCT_TL_EP_STAT_PEND(&ep->super);
return UCS_OK;
}
ucs_arbiter_cb_result_t uct_mm_ep_process_pending(ucs_arbiter_t *arbiter,
ucs_arbiter_group_t *group,
ucs_arbiter_elem_t *elem,
void *arg)
{
uct_mm_ep_t *ep = ucs_container_of(group, uct_mm_ep_t, arb_group);
unsigned *count = (unsigned*)arg;
uct_pending_req_t *req;
ucs_status_t status;
/* update the local tail with its actual value from the remote peer
* making sure that the pending sends would use the real tail value */
uct_mm_ep_update_cached_tail(ep);
if (!uct_mm_ep_has_tx_resources(ep)) {
return UCS_ARBITER_CB_RESULT_RESCHED_GROUP;
}
if (elem == &ep->arb_elem) {
return UCS_ARBITER_CB_RESULT_REMOVE_ELEM;
}
req = ucs_container_of(elem, uct_pending_req_t, priv);
ucs_trace_data("progressing pending request %p", req);
status = req->func(req);
ucs_trace_data("status returned from progress pending: %s",
ucs_status_string(status));
if (status == UCS_OK) {
(*count)++;
/* sent successfully. remove from the arbiter */
return UCS_ARBITER_CB_RESULT_REMOVE_ELEM;
} else if (status == UCS_INPROGRESS) {
(*count)++;
/* sent but not completed, keep in the arbiter */
return UCS_ARBITER_CB_RESULT_NEXT_GROUP;
} else {
/* couldn't send. keep this request in the arbiter until the next time
* this function is called */
return UCS_ARBITER_CB_RESULT_RESCHED_GROUP;
}
}
static ucs_arbiter_cb_result_t uct_mm_ep_arbiter_purge_cb(ucs_arbiter_t *arbiter,
ucs_arbiter_group_t *group,
ucs_arbiter_elem_t *elem,
void *arg)
{
uct_mm_ep_t *ep = ucs_container_of(group, uct_mm_ep_t,
arb_group);
uct_purge_cb_args_t *cb_args = arg;
uct_pending_purge_callback_t cb = cb_args->cb;
uct_pending_req_t *req;
if (elem == &ep->arb_elem) {
return UCS_ARBITER_CB_RESULT_REMOVE_ELEM;
}
req = ucs_container_of(elem, uct_pending_req_t, priv);
if (cb != NULL) {
cb(req, cb_args->arg);
} else {
ucs_warn("ep=%p canceling user pending request %p", ep, req);
}
return UCS_ARBITER_CB_RESULT_REMOVE_ELEM;
}
void uct_mm_ep_pending_purge(uct_ep_h tl_ep, uct_pending_purge_callback_t cb,
void *arg)
{
uct_mm_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_mm_iface_t);
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
uct_purge_cb_args_t args = {cb, arg};
ucs_arbiter_group_purge(&iface->arbiter, &ep->arb_group,
uct_mm_ep_arbiter_purge_cb, &args);
}
ucs_status_t uct_mm_ep_flush(uct_ep_h tl_ep, unsigned flags,
uct_completion_t *comp)
{
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
if (!uct_mm_ep_has_tx_resources(ep)) {
if (!ucs_arbiter_group_is_empty(&ep->arb_group)) {
return UCS_ERR_NO_RESOURCE;
} else {
uct_mm_ep_update_cached_tail(ep);
if (!uct_mm_ep_has_tx_resources(ep)) {
return UCS_ERR_NO_RESOURCE;
}
}
}
ucs_memory_cpu_store_fence();
UCT_TL_EP_STAT_FLUSH(&ep->super);
return UCS_OK;
}
ucs_status_t
uct_mm_ep_check(uct_ep_h tl_ep, unsigned flags, uct_completion_t *comp)
{
uct_mm_ep_t *ep = ucs_derived_of(tl_ep, uct_mm_ep_t);
UCT_EP_KEEPALIVE_CHECK_PARAM(flags, comp);
uct_ep_keepalive_check(tl_ep, &ep->keepalive, ep->fifo_ctl->pid, flags,
comp);
return UCS_OK;
}
|
c7019af94b8638ec4dc5f241cbe5effdfb0127fd
|
22f5ec4d85105dc2cb9b2ae38ad806fa5a138f3a
|
/src/mulle-objc-uniqueid.c
|
c5220f69723f2805ae14cc184e7caf828cd0d25b
|
[
"BSD-3-Clause"
] |
permissive
|
mulle-objc/mulle-objc-runtime
|
0fd0fd4c0a4221f693bf7aa33bc43cf5e091dd12
|
558d9cb71a331315fff0dfbfb1ea20b90d20652f
|
refs/heads/release
| 2023-05-01T08:44:16.846552
| 2023-04-21T21:47:23
| 2023-04-21T21:47:23
| 73,371,608
| 133
| 8
|
NOASSERTION
| 2022-01-12T13:56:19
| 2016-11-10T10:29:50
|
C
|
UTF-8
|
C
| false
| false
| 4,216
|
c
|
mulle-objc-uniqueid.c
|
//
// mulle_objc_uniqueid.c
// mulle-objc-runtime
//
// Created by Nat! on 05.02.16.
// Copyright (c) 2016 Nat! - Mulle kybernetiK.
// Copyright (c) 2016 Codeon GmbH.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 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.
//
// Neither the name of Mulle kybernetiK 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
//
#include "mulle-objc-uniqueid.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "include-private.h"
//
// TODO: for certain special strings, we could use small numbers that
// produce smaller constants, which might save instruction space
//
mulle_objc_uniqueid_t mulle_objc_uniqueid_from_string( char *s)
{
mulle_objc_uniqueid_t value;
unsigned int len;
if( ! s)
{
errno = EINVAL;
return( MULLE_OBJC_INVALID_UNIQUEID);
}
len = (unsigned int) strlen( s);
if( ! len)
{
errno = EINVAL;
return( MULLE_OBJC_INVALID_UNIQUEID);
}
#if MULLE_OBJC_UNIQUEHASH_ALGORITHM == MULLE_OBJC_UNIQUEHASH_FNV1A
value = _mulle_fnv1a_32( s, len);
#else
# error fnv not supported any longer
#endif
//
// fnv1 favors the last byte disproportionally, but that' usually just ':'
// lets rotate it a bit, so the hash bit portions used for cache
// access are better. This doesn't affect collisions at all as all bits
// are preserved.
//
value = (value << MULLE_OBJC_UNIQUEHASH_SHIFT) | (value >> (32 - MULLE_OBJC_UNIQUEHASH_SHIFT));
if( value == MULLE_OBJC_NO_UNIQUEID)
value = MULLE_OBJC_INVALID_UNIQUEID;
if( value == MULLE_OBJC_INVALID_UNIQUEID)
{
fprintf( stderr, "Congratulations, your string \"%s\" "
"hashes badly (rare and precious, please tweet it @mulle_nat, then rename it).", s);
#ifdef DEBUG
abort();
#endif
}
return( value);
}
int mulle_objc_uniqueid_is_sane_string( mulle_objc_uniqueid_t uniqueid, char *s)
{
if( ! mulle_objc_uniqueid_is_sane( uniqueid))
{
errno = EINVAL;
return( 0);
}
#if DEBUG
{
mulle_objc_uniqueid_t correct;
correct = mulle_objc_uniqueid_from_string( s);
if( uniqueid != correct)
{
fprintf( stderr, "error: String \"%s\" should have "
"uniqueid %08x but has uniqueid %08x\n",
s, correct, uniqueid);
errno = EINVAL; // this is needed for tests
return( 0);
}
}
#endif
return( 1);
}
unsigned int _mulle_objc_uniqueid_arraycount( mulle_objc_uniqueid_t *ids)
{
unsigned int n;
n = 0;
if( ids)
while( *ids++)
++n;
return( n);
}
int _mulle_objc_uniqueid_qsortcompare( mulle_objc_uniqueid_t *a, mulle_objc_uniqueid_t *b)
{
intptr_t diff;
diff = (intptr_t) *a - (intptr_t) *b;
if( diff < 0)
return( -1);
return( ! ! diff);
}
|
8bb48fa8e5c79c7e19d35eef42d5a828fea0bc72
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/arch/arm/cpu/armv7/sun50iw1p1/spl/fip_common.c
|
9f9e0d36c48819ca3d41477bb6a06427b2cc88f4
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 18,867
|
c
|
fip_common.c
|
#include <linux/types.h>
#include <config.h>
//#include "bl_common.h"
#include <private_uboot.h>
#include <asm/io.h>
//index for merge uboot with bl31,bl32
/* EL3 Runtime Firmware BL31 */
#define BL31_IMAGE_NAME 0
/* Trusted OS*/
#define BL32_IMAGE_NAME 1
/* Scp*/
#define SCP_IMAGE_NAME 2
//**********************************************************************
extern int printf(const char *fmt, ...);
extern void * memcpy(void * dest,const void *src,size_t count);
extern void * memset(void * s, int c, size_t count);
int sunxi_deassert_arisc(void)
{
printf("set arisc reset to de-assert state\n");
{
volatile unsigned long value;
value = readl(SUNXI_RCPUCFG_BASE + 0x0);
value &= ~1;
writel(value, SUNXI_RCPUCFG_BASE + 0x0);
value = readl(SUNXI_RCPUCFG_BASE + 0x0);
value |= 1;
writel(value, SUNXI_RCPUCFG_BASE + 0x0);
}
return 0;
}
int load_image(u32 image_index,u32 image_base)
{
struct spare_boot_head_t* header;
u32 offset;
u32 image_size;
/* Obtain a reference to the image by querying the platform layer */
header = (struct spare_boot_head_t* )CONFIG_SYS_TEXT_BASE;
offset = header->boot_ext[image_index].data[0];
image_size = header->boot_ext[image_index].data[1];
if(0 == offset || 0 == image_size)
{
//printf("index %d for file not found\n", image_index);
return -1;
}
if(image_index == SCP_IMAGE_NAME)
{
memcpy((void*)SCP_SRAM_BASE,(void*)(CONFIG_SYS_TEXT_BASE+offset), CONFIG_SYS_SRAMA2_SIZE);
memcpy((void*)SCP_DRAM_BASE,(void*)(CONFIG_SYS_TEXT_BASE+offset+0x18000), SCP_DRAM_SIZE);
}
else
{
memcpy((void*)image_base,(void*)(CONFIG_SYS_TEXT_BASE+offset), image_size);
}
printf("Loading file %d at address 0x%x,size 0x%x success\n",image_index, image_base,image_size);
return 0;
}
/*******************************************************************************
* The only thing to do in BL2 is to load further images and pass control to
* BL3-1. The memory occupied by BL2 will be reclaimed by BL3-x stages. BL2 runs
* entirely in S-EL1.
******************************************************************************/
int load_fip(int *use_monitor)
{
int e;
struct spare_boot_head_t* header;
header = (struct spare_boot_head_t* )CONFIG_SYS_TEXT_BASE;
printf("boot0: %s\n", "start load other image");
printf("boot0: Loading BL3-1\n");
e = load_image(BL31_IMAGE_NAME,BL31_BASE);
if (e)
{
printf("Failed to load BL3-1\n");
}
else
{
*use_monitor = 1;
header->boot_data.secureos_exist = 1;
}
printf("boot0: Loading scp\n");
e = load_image(SCP_IMAGE_NAME,SCP_SRAM_BASE);
if (e)
{
printf("Failed to load SCP\n");
return -1;
}
else
{
sunxi_deassert_arisc();
}
/*
printf("boot0: Loading BL3-2\n");
e = load_image(BL32_IMAGE_NAME,BL32_BASE);
if (e) {
ERROR("Failed to load BL3-2 (%d)\n", e);
return -1;
}
printf("boot0: Loading BL3-3\n");
e = load_image(BL33_IMAGE_NAME,BL33_BASE);
if (e) {
ERROR("Failed to load BL3-3 (%d)\n", e);
return -1;
}
*/
/* Flush the params to be passed to memory */
//bl2_plat_flush_bl31_params();
return 0;
}
#if 0
#include "fip_type.h"
#include <config.h>
#include "bl_common.h"
#include <private_uboot.h>
//index for merge uboot with bl31,bl32
/* EL3 Runtime Firmware BL31 */
#define BL31_IMAGE_NAME 0
/* Trusted OS*/
#define BL32_IMAGE_NAME 1
#define UBOOT_BASE 0x4A000000
#define DRAM_BASE 0x40000000
//bl31(monitor area)
#define PLAT_TRUSTED_MONITOR_BASE 0x7e000000 /*for test on fpga*/
#define PLAT_TRUSTED_MONITOR_SIZE 0x00100000 /* 1MB */
//bl32(trusted os area)
#define PLAT_TRUSTED_DRAM_BASE 0x7f000000 /*0x40000000+0x40000000-0x02000000*/
#define PLAT_TRUSTED_DRAM_SIZE 0x01000000 /* 16 MB */
//shared memory for monitor
#define PLAT_SHARED_RAM_BASE PLAT_TRUSTED_DRAM_BASE
#define PLAT_SHARED_RAM_SIZE 0x1000
//bl31 base addr
#define BL31_BASE PLAT_TRUSTED_MONITOR_BASE
/*bl32 run on trusted dram*/
#define BL32_BASE (PLAT_TRUSTED_DRAM_BASE + PLAT_SHARED_RAM_SIZE)
/*bl33 base addr*/
#define BL33_BASE UBOOT_BASE
/*******************************************************************************
* Shared Data
******************************************************************************/
/* Entrypoint mailboxes */
#define MBOX_BASE PLAT_SHARED_RAM_BASE
#define MBOX_SIZE 0x200
/* Base address where parameters to BL31 are stored */
#define PARAMS_BASE (MBOX_BASE + MBOX_SIZE)
//************************************arch macro********************************
#define MODE_RW_SHIFT 0x4
#define MODE_RW_MASK 0x1
#define MODE_RW_64 0x0
#define MODE_RW_32 0x1
#define MODE_EL_SHIFT 0x2
#define MODE_EL_MASK 0x3
#define MODE_EL3 0x3
#define MODE_EL2 0x2
#define MODE_EL1 0x1
#define MODE_EL0 0x0
#define MODE_SP_SHIFT 0x0
#define MODE_SP_MASK 0x1
#define MODE_SP_EL0 0x0
#define MODE_SP_ELX 0x1
/* CPSR/SPSR definitions */
#define DAIF_FIQ_BIT (1 << 0)
#define DAIF_IRQ_BIT (1 << 1)
#define DAIF_ABT_BIT (1 << 2)
#define DAIF_DBG_BIT (1 << 3)
#define SPSR_DAIF_SHIFT 6
#define SPSR_DAIF_MASK 0xf
#define SPSR_AIF_SHIFT 6
#define SPSR_AIF_MASK 0x7
#define SPSR_E_SHIFT 9
#define SPSR_E_MASK 0x1
#define SPSR_E_LITTLE 0x0
#define SPSR_E_BIG 0x1
#define SPSR_T_SHIFT 5
#define SPSR_T_MASK 0x1
#define SPSR_T_ARM 0x0
#define SPSR_T_THUMB 0x1
#define DISABLE_ALL_EXCEPTIONS \
(DAIF_FIQ_BIT | DAIF_IRQ_BIT | DAIF_ABT_BIT | DAIF_DBG_BIT)
#define SPSR_64(el, sp, daif) \
(MODE_RW_64 << MODE_RW_SHIFT | \
((el) & MODE_EL_MASK) << MODE_EL_SHIFT | \
((sp) & MODE_SP_MASK) << MODE_SP_SHIFT | \
((daif) & SPSR_DAIF_MASK) << SPSR_DAIF_SHIFT)
#define MODE32_SHIFT 0
#define MODE32_MASK 0xf
#define MODE32_usr 0x0
#define MODE32_fiq 0x1
#define MODE32_irq 0x2
#define MODE32_svc 0x3
#define MODE32_mon 0x6
#define MODE32_abt 0x7
#define MODE32_hyp 0xa
#define MODE32_und 0xb
#define MODE32_sys 0xf
#define GET_RW(mode) (((mode) >> MODE_RW_SHIFT) & MODE_RW_MASK)
#define GET_EL(mode) (((mode) >> MODE_EL_SHIFT) & MODE_EL_MASK)
#define GET_SP(mode) (((mode) >> MODE_SP_SHIFT) & MODE_SP_MASK)
#define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
#define SPSR_64(el, sp, daif) \
(MODE_RW_64 << MODE_RW_SHIFT | \
((el) & MODE_EL_MASK) << MODE_EL_SHIFT | \
((sp) & MODE_SP_MASK) << MODE_SP_SHIFT | \
((daif) & SPSR_DAIF_MASK) << SPSR_DAIF_SHIFT)
#define SPSR_MODE32(mode, isa, endian, aif) \
(MODE_RW_32 << MODE_RW_SHIFT | \
((mode) & MODE32_MASK) << MODE32_SHIFT | \
((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | \
((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
//**********************************************************************
extern int printf(const char *fmt, ...);
extern void * memcpy(void * dest,const void *src,size_t count);
extern void * memset(void * s, int c, size_t count);
#define ERROR(...) printf("ERROR: " __VA_ARGS__)
#define WARN(...) printf("WARN: " __VA_ARGS__)
#define INFO(...) printf("INFO: " __VA_ARGS__)
#define NULL ((void *)0)
#define assert(x) { if(!(x)) {while(*(volatile uint32_t*)(0x4a000000) != 0x1122);}}
static bl31_params_t *bl2_to_bl31_params;
static entry_point_info_t *bl31_ep_info;
/*******************************************************************************
* Before calling this function BL31 is loaded in memory and its entrypoint
* is set by load_image. This is a placeholder for the platform to change
* the entrypoint of BL31 and set SPSR and security state.
* On FVP we are only setting the security state, entrypoint
******************************************************************************/
void bl2_plat_set_bl31_ep_info(image_info_t *bl31_image_info,
entry_point_info_t *bl31_ep_info)
{
SET_SECURITY_STATE(bl31_ep_info->h.attr, SECURE);
bl31_ep_info->spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
DISABLE_ALL_EXCEPTIONS);
}
/*******************************************************************************
* Before calling this function BL32 is loaded in memory and its entrypoint
* is set by load_image. This is a placeholder for the platform to change
* the entrypoint of BL32 and set SPSR and security state.
* On FVP we are only setting the security state, entrypoint
******************************************************************************/
void bl2_plat_set_bl32_ep_info(image_info_t *bl32_image_info,
entry_point_info_t *bl32_ep_info)
{
SET_SECURITY_STATE(bl32_ep_info->h.attr, SECURE);
bl32_ep_info->spsr = 0;
}
/*******************************************************************************
* Before calling this function BL33 is loaded in memory and its entrypoint
* is set by load_image. This is a placeholder for the platform to change
* the entrypoint of BL33 and set SPSR and security state.
* On FVP we are only setting the security state, entrypoint
******************************************************************************/
void bl2_plat_set_bl33_ep_info(image_info_t *image,
entry_point_info_t *bl33_ep_info)
{
//when use AA64 uboot
//SET_SECURITY_STATE(bl33_ep_info->h.attr, NON_SECURE);
//bl33_ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
//when use AA32 uboot
SET_SECURITY_STATE(bl33_ep_info->h.attr, NON_SECURE);
bl33_ep_info->spsr = SPSR_MODE32(MODE32_svc,SPSR_T_ARM,SPSR_E_LITTLE,DISABLE_ALL_EXCEPTIONS);
INFO("bl33 spsr is 0x%x\n", bl33_ep_info->spsr);
}
/*******************************************************************************
* This function assigns a pointer to the memory that the platform has kept
* aside to pass platform specific and trusted firmware related information
* to BL31. This memory is allocated by allocating memory to
* bl2_to_bl31_params_mem_t structure which is a superset of all the
* structure whose information is passed to BL31
* NOTE: This function should be called only once and should be done
* before generating params to BL31
******************************************************************************/
bl31_params_t *bl2_plat_get_bl31_params(void)
{
bl2_to_bl31_params_mem_t *bl31_params_mem;
/*
* Allocate the memory for all the arguments that needs to
* be passed to BL31
*/
bl31_params_mem = (bl2_to_bl31_params_mem_t *)PARAMS_BASE;
memset((void *)PARAMS_BASE, 0, sizeof(bl2_to_bl31_params_mem_t));
/* Assign memory for TF related information */
bl2_to_bl31_params = &bl31_params_mem->bl31_params;
SET_PARAM_HEAD(bl2_to_bl31_params, PARAM_BL31, VERSION_1, 0);
/* Fill BL31 related information */
bl31_ep_info = &bl31_params_mem->bl31_ep_info;
bl2_to_bl31_params->bl31_image_info = &bl31_params_mem->bl31_image_info;
SET_PARAM_HEAD(bl2_to_bl31_params->bl31_image_info, PARAM_IMAGE_BINARY,
VERSION_1, 0);
/* Fill BL32 related information if it exists */
if (BL32_BASE) {
bl2_to_bl31_params->bl32_ep_info =
&bl31_params_mem->bl32_ep_info;
SET_PARAM_HEAD(bl2_to_bl31_params->bl32_ep_info,
PARAM_EP, VERSION_1, 0);
bl2_to_bl31_params->bl32_image_info =
&bl31_params_mem->bl32_image_info;
SET_PARAM_HEAD(bl2_to_bl31_params->bl32_image_info,
PARAM_IMAGE_BINARY,
VERSION_1, 0);
}
/* Fill BL33 related information */
bl2_to_bl31_params->bl33_ep_info = &bl31_params_mem->bl33_ep_info;
SET_PARAM_HEAD(bl2_to_bl31_params->bl33_ep_info,
PARAM_EP, VERSION_1, 0);
bl2_to_bl31_params->bl33_image_info = &bl31_params_mem->bl33_image_info;
SET_PARAM_HEAD(bl2_to_bl31_params->bl33_image_info, PARAM_IMAGE_BINARY,
VERSION_1, 0);
return bl2_to_bl31_params;
}
#if 0
int load_image(meminfo_t *mem_layout,
const char *image_name,
uint64_t image_base,
image_info_t *image_data,
entry_point_info_t *entry_point_info)
{
fip_toc_header_t *header;
fip_toc_entry_t *fip_file_entry;
uint32_t bufer_offset = 0;
uuid_t file_uuid;
int found_file = 0;
const uuid_t uuid_null = {0};
//assert(mem_layout != NULL);
assert(image_name != NULL);
assert(image_data != NULL);
assert(image_data->h.version >= VERSION_1);
/* Obtain a reference to the image by querying the platform layer */
header = (fip_toc_header_t*)FIP_LOAD_ADDR;
if (!is_valid_header(header))
{
printf("Firmware Image Package header check failed.\n");
return -1;
}
else
{
printf("FIP header looks OK.\n");
}
bufer_offset = sizeof(fip_toc_header_t);
fip_file_entry = (fip_toc_entry_t *)(FIP_LOAD_ADDR+bufer_offset);
if(file_to_uuid(image_name, &file_uuid))
{
printf("file %s is not config in name_uuid table\n", image_name);
return -1;
}
do {
if (compare_uuids(&fip_file_entry->uuid,
&file_uuid) == 0)
{
found_file = 1;
break;
}
fip_file_entry++;
}while (compare_uuids(&fip_file_entry->uuid, &uuid_null) != 0);
if(!found_file)
{
printf("uuid for file %s not found\n", image_name);
return -1;
}
memcpy((void*)image_base,(void*)(FIP_LOAD_ADDR+fip_file_entry->offset_address), fip_file_entry->size);
image_data->image_base = image_base;
image_data->image_size = fip_file_entry->size;
if (entry_point_info != NULL)
entry_point_info->pc = image_base;
printf("Loading file '%s' at address 0x%x,size 0x%x sucess\n",
image_name, (uint32_t)image_base,(uint32_t)image_data->image_size);
return 0;
}
#endif
int load_image(meminfo_t *mem_layout,
uint32_t image_index,
uint32_t image_base,
image_info_t *image_data,
entry_point_info_t *entry_point_info)
{
struct spare_boot_head_t* header;
uint32_t offset;
uint32_t image_size;
assert(image_data != NULL);
assert(image_data->h.version >= VERSION_1);
/* Obtain a reference to the image by querying the platform layer */
header = (struct spare_boot_head_t* )UBOOT_BASE;
offset = header->boot_ext[image_index].data[0];
image_size = header->boot_ext[image_index].data[1];
if(0 == offset || 0 == image_size)
{
printf("index %d for file not found\n", image_index);
return -1;
}
memcpy((void*)image_base,(void*)(UBOOT_BASE+offset), image_size);
image_data->image_base = image_base;
image_data->image_size = image_size;
if (entry_point_info != NULL)
entry_point_info->pc = image_base;
INFO("Loading file %d at address 0x%x,size 0x%x success\n",
image_index, (uint32_t)image_base,(uint32_t)image_data->image_size);
return 0;
}
/*******************************************************************************
* Load the BL3-1 image.
* The bl2_to_bl31_params and bl31_ep_info params will be updated with the
* relevant BL3-1 information.
* Return 0 on success, a negative error code otherwise.
******************************************************************************/
static int load_bl31(bl31_params_t *bl2_to_bl31_params,
entry_point_info_t *bl31_ep_info)
{
meminfo_t *bl2_tzram_layout;
int e;
INFO("BL2: Loading BL3-1\n");
assert(bl2_to_bl31_params != NULL);
assert(bl31_ep_info != NULL);
/* Find out how much free trusted ram remains after BL2 load */
bl2_tzram_layout = NULL;//bl2_plat_sec_mem_layout();
/* Set the X0 parameter to BL3-1 */
bl31_ep_info->args.arg0 = (unsigned long)bl2_to_bl31_params;
/* Load the BL3-1 image */
e = load_image(bl2_tzram_layout,
BL31_IMAGE_NAME,
BL31_BASE,
bl2_to_bl31_params->bl31_image_info,
bl31_ep_info);
if (e == 0)
bl2_plat_set_bl31_ep_info(bl2_to_bl31_params->bl31_image_info,
bl31_ep_info);
return e;
}
/*******************************************************************************
* Load the BL3-2 image if there's one.
* The bl2_to_bl31_params param will be updated with the relevant BL3-2
* information.
* If a platform does not want to attempt to load BL3-2 image it must leave
* BL32_BASE undefined.
* Return 0 on success or if there's no BL3-2 image to load, a negative error
* code otherwise.
******************************************************************************/
static int load_bl32(bl31_params_t *bl2_to_bl31_params)
{
int e = 0;
#ifdef BL32_BASE
//meminfo_t bl32_mem_info;
INFO("BL2: Loading BL3-2\n");
assert(bl2_to_bl31_params != NULL);
/*
* It is up to the platform to specify where BL3-2 should be loaded if
* it exists. It could create space in the secure sram or point to a
* completely different memory.
*/
e = load_image(NULL,
BL32_IMAGE_NAME,
BL32_BASE,
bl2_to_bl31_params->bl32_image_info,
bl2_to_bl31_params->bl32_ep_info);
if (e == 0) {
bl2_plat_set_bl32_ep_info(
bl2_to_bl31_params->bl32_image_info,
bl2_to_bl31_params->bl32_ep_info);
}
#endif /* BL32_BASE */
return e;
}
/*******************************************************************************
* Load the BL3-3 image.
* The bl2_to_bl31_params param will be updated with the relevant BL3-3
* information.
* Return 0 on success, a negative error code otherwise.
******************************************************************************/
static int load_bl33(bl31_params_t *bl2_to_bl31_params)
{
INFO("BL2: Loading BL3-3\n");
assert(bl2_to_bl31_params != NULL);
//bl33 is in place ,just set para
bl2_to_bl31_params->bl33_image_info->image_base = BL33_BASE;
bl2_to_bl31_params->bl33_image_info->image_size = 1;//value is uboot size,don't care here
if (bl2_to_bl31_params->bl33_ep_info != NULL)
bl2_to_bl31_params->bl33_ep_info->pc = BL33_BASE;
bl2_plat_set_bl33_ep_info(bl2_to_bl31_params->bl33_image_info,
bl2_to_bl31_params->bl33_ep_info);
return 0;
}
/*******************************************************************************
* This function returns a pointer to the shared memory that the platform
* has kept to point to entry point information of BL31 to BL2
******************************************************************************/
struct entry_point_info *bl2_plat_get_bl31_ep_info(void)
{
return bl31_ep_info;
}
/*******************************************************************************
* The only thing to do in BL2 is to load further images and pass control to
* BL3-1. The memory occupied by BL2 will be reclaimed by BL3-x stages. BL2 runs
* entirely in S-EL1.
******************************************************************************/
int bl2_main(void)
{
bl31_params_t *bl2_to_bl31_params;
entry_point_info_t *bl31_ep_info;
int e;
INFO("BL2: %s\n", "start load other image");
/*
* Get a pointer to the memory the platform has set aside to pass
* information to BL3-1.
*/
bl2_to_bl31_params = bl2_plat_get_bl31_params();
bl31_ep_info = bl2_plat_get_bl31_ep_info();
e = load_bl31(bl2_to_bl31_params, bl31_ep_info);
if (e) {
ERROR("Failed to load BL3-1 (%d)\n", e);
return -1;
}
e = load_bl32(bl2_to_bl31_params);
if (e)
WARN("Failed to load BL3-2 (%d)\n", e);
e = load_bl33(bl2_to_bl31_params);
if (e) {
ERROR("Failed to load BL3-3 (%d)\n", e);
return -1;
}
/* Flush the params to be passed to memory */
//bl2_plat_flush_bl31_params();
return 0;
}
#endif
|
00489525e0513e898b1c9b39b0894c5bcc1ef10c
|
f54021ed2b6bb09a18b2bd6331b01fdfacba4f08
|
/src/io/tap.c
|
85c42d1e6418eeef3986cd28d3637c138355bfe7
|
[
"MIT"
] |
permissive
|
Snaipe/Criterion
|
e13784611d4f024114759c81db7978a34158a571
|
9c01cbe75002ad8640e0f411f453fbcd0567ff79
|
refs/heads/bleeding
| 2023-09-01T14:38:14.824224
| 2023-05-13T15:44:26
| 2023-05-13T16:02:30
| 30,111,969
| 1,965
| 240
|
MIT
| 2023-04-29T11:26:11
| 2015-01-31T12:45:39
|
C
|
UTF-8
|
C
| false
| false
| 4,809
|
c
|
tap.c
|
/*
* The MIT License (MIT)
*
* Copyright © 2015-2016 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "criterion/stats.h"
#include "criterion/options.h"
#include "compat/posix.h"
#include "compat/strtok.h"
#include "compat/time.h"
#include "config.h"
#include "common.h"
static void print_prelude(FILE *f, struct criterion_global_stats *stats)
{
fprintf(f, "TAP version 13\n1..%" CRI_PRIuSIZE "\n", stats->nb_tests);
fprintf(f, "# Criterion %s\n", VERSION);
}
static void print_pre_suite(FILE *f, struct criterion_suite_stats *stats)
{
fprintf(f, "#\n# Running %" CRI_PRIuSIZE " tests from %s\n",
stats->nb_tests,
stats->suite->name);
}
static void print_test_normal(FILE *f, struct criterion_test_stats *stats)
{
const char *format = "%s - %s::%s %s (%3.2fs)\n";
if (!criterion_options.measure_time) {
format = "%s - %s::%s %s\n";
}
fprintf(f, format,
stats->test_status == CR_STATUS_FAILED ? "not ok" : "ok",
stats->test->category,
stats->test->name,
DEF(stats->test->data->description, ""),
stats->elapsed_time);
if (stats->test_status == CR_STATUS_FAILED) {
fprintf(f, " ---\n");
fprintf(f, " assertions: %" CRI_PRIuSIZE "\n",
(size_t) (stats->passed_asserts + stats->failed_asserts));
fprintf(f, " failures:\n");
for (struct criterion_assert_stats *asrt = stats->asserts; asrt; asrt = asrt->next) {
if (!asrt->passed) {
char *dup = strdup(asrt->message && *asrt->message ? asrt->message : "");
char *saveptr = NULL;
char *line = strtok_r(dup, "\n", &saveptr);
bool sf = criterion_options.short_filename;
fprintf(f, " - %s:%u: |+\n Assertion failed: %s\n",
sf ? basename_compat(asrt->file) : asrt->file,
asrt->line,
line ? line : "(no message)");
while ((line = strtok_r(NULL, "\n", &saveptr)))
fprintf(f, " %s\n", line);
free(dup);
}
}
fprintf(f, " ...\n");
}
}
static void print_test_crashed(FILE *f, struct criterion_test_stats *stats)
{
bool sf = criterion_options.short_filename;
fprintf(f, "not ok - %s::%s unexpected signal after %s:%u\n",
stats->test->category,
stats->test->name,
sf ? basename_compat(stats->file) : stats->file,
stats->progress);
}
static void print_test_timeout(FILE *f, struct criterion_test_stats *stats)
{
fprintf(f, "not ok - %s::%s timed out (%3.2fs)\n",
stats->test->category,
stats->test->name,
stats->elapsed_time);
}
static void print_test(FILE *f, struct criterion_test_stats *ts)
{
if (ts->test_status == CR_STATUS_SKIPPED) {
fprintf(f, "ok - %s::%s %s # SKIP %s\n",
ts->test->category,
ts->test->name,
DEF(ts->test->data->description, ""),
ts->message ? ts->message : "test was skipped");
} else if (ts->crashed) {
print_test_crashed(f, ts);
} else if (ts->timed_out) {
print_test_timeout(f, ts);
} else {
print_test_normal(f, ts);
}
}
void tap_report(FILE *f, struct criterion_global_stats *stats)
{
print_prelude(f, stats);
for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) {
print_pre_suite(f, ss);
for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next)
print_test(f, ts);
}
}
|
07e9dbe999dd4e10e7b063aaee1358a95b41960f
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/lib/libkern/copystr.c
|
668973921696dcea0e7dcfd63e9bdec2d4c2fea6
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 1,900
|
c
|
copystr.c
|
/* $NetBSD: copystr.c,v 1.1 2020/06/30 16:20:02 maxv Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Maxime Villard.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#include <sys/systm.h>
#include <sys/errno.h>
int
copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done)
{
const char *src = kfaddr;
char *dst = kdaddr;
size_t i;
for (i = 0; i < len; i++) {
if ((*dst++ = *src++) == '\0') {
if (done)
*done = i + 1;
return 0;
}
}
if (done)
*done = i;
return ENAMETOOLONG;
}
|
6c49291eabc7dc12fb202ae786e94724ec25ef64
|
50dd46b8ece33f3cdd174284b15d1d51f89669d4
|
/2021/quals/hw-pcivault/challenge/guest-utils/flag_placer.c
|
8eed570cec200bcf2e2ac2b6d4b088fcacaf26d4
|
[
"LicenseRef-scancode-generic-cla",
"Apache-2.0"
] |
permissive
|
google/google-ctf
|
f99da1ee07729bbccb869fff1cbaed6a80e43bcc
|
df02323eaf945d15e124801c74abaadca2749dc7
|
refs/heads/master
| 2023-08-31T14:30:27.548081
| 2023-08-29T13:04:20
| 2023-08-29T13:04:20
| 131,317,137
| 4,136
| 607
|
Apache-2.0
| 2023-08-30T22:17:02
| 2018-04-27T15:56:03
|
Go
|
UTF-8
|
C
| false
| false
| 1,766
|
c
|
flag_placer.c
|
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This is intended to be executed on the secondary VM (the one that the
// contestants will not have access to). It is responsible for placing the first
// flag inside the device and the second one inside the kernel heap.
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
static const char flag[] = "CTF{D1ff3r3nT_D3v1Ce_S4mE_Tr1Ckz}";
static const char flag2[64] = "CTF{B3h1nD_S3vEn_D4v1C3s}";
static const char key[256] = "flag";
char verify[64] = {};
system("sysctl -w kernel.panic_on_oops=1");
int f = open("/dev/pcivault", O_RDWR);
if (f < 0) err(1, "open");
// Set "encryption key"
if (ioctl(f, 0, flag2) < 0) err(1, "ioctl");
while (1) {
// Set key
if (ioctl(f, 1, key) < 0) err(1, "ioctl");
// Write flag
if (write(f, flag, sizeof(flag)) != sizeof(flag)) err(1, "writing flag");
// Verify flag
if (read(f, verify, sizeof(verify)) != sizeof(flag) || strcmp(verify, flag)) {
fprintf(stderr, "Verifying flag failed\n");
}
sleep(2);
}
close(f);
return 0;
}
|
43409e93a41c3b396a037d22311837fa2b921412
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/sh/kernel/cpu/sh3/setup-sh7710.c
|
93c9c5e24a7abbe7e7c5b832b0497c54be6adb03
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 6,058
|
c
|
setup-sh7710.c
|
/*
* SH3 Setup code for SH7710, SH7712
*
* Copyright (C) 2006 - 2009 Paul Mundt
* Copyright (C) 2007 Nobuhiro Iwamatsu
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/serial.h>
#include <linux/serial_sci.h>
#include <linux/sh_timer.h>
#include <linux/sh_intc.h>
#include <asm/rtc.h>
enum {
UNUSED = 0,
/* interrupt sources */
IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5,
DMAC1, SCIF0, SCIF1, DMAC2, IPSEC,
EDMAC0, EDMAC1, EDMAC2,
SIOF0, SIOF1,
TMU0, TMU1, TMU2,
RTC, WDT, REF,
};
static struct intc_vect vectors[] __initdata = {
/* IRQ0->5 are handled in setup-sh3.c */
INTC_VECT(DMAC1, 0x800), INTC_VECT(DMAC1, 0x820),
INTC_VECT(DMAC1, 0x840), INTC_VECT(DMAC1, 0x860),
INTC_VECT(SCIF0, 0x880), INTC_VECT(SCIF0, 0x8a0),
INTC_VECT(SCIF0, 0x8c0), INTC_VECT(SCIF0, 0x8e0),
INTC_VECT(SCIF1, 0x900), INTC_VECT(SCIF1, 0x920),
INTC_VECT(SCIF1, 0x940), INTC_VECT(SCIF1, 0x960),
INTC_VECT(DMAC2, 0xb80), INTC_VECT(DMAC2, 0xba0),
#ifdef CONFIG_CPU_SUBTYPE_SH7710
INTC_VECT(IPSEC, 0xbe0),
#endif
INTC_VECT(EDMAC0, 0xc00), INTC_VECT(EDMAC1, 0xc20),
INTC_VECT(EDMAC2, 0xc40),
INTC_VECT(SIOF0, 0xe00), INTC_VECT(SIOF0, 0xe20),
INTC_VECT(SIOF0, 0xe40), INTC_VECT(SIOF0, 0xe60),
INTC_VECT(SIOF1, 0xe80), INTC_VECT(SIOF1, 0xea0),
INTC_VECT(SIOF1, 0xec0), INTC_VECT(SIOF1, 0xee0),
INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
INTC_VECT(TMU2, 0x440),
INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
INTC_VECT(RTC, 0x4c0),
INTC_VECT(WDT, 0x560),
INTC_VECT(REF, 0x580),
};
static struct intc_prio_reg prio_registers[] __initdata = {
{ 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
{ 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF, 0, 0 } },
{ 0xa4000016, 0, 16, 4, /* IPRC */ { IRQ3, IRQ2, IRQ1, IRQ0 } },
{ 0xa4000018, 0, 16, 4, /* IPRD */ { 0, 0, IRQ5, IRQ4 } },
{ 0xa400001a, 0, 16, 4, /* IPRE */ { DMAC1, SCIF0, SCIF1 } },
{ 0xa4080000, 0, 16, 4, /* IPRF */ { IPSEC, DMAC2 } },
{ 0xa4080002, 0, 16, 4, /* IPRG */ { EDMAC0, EDMAC1, EDMAC2 } },
{ 0xa4080004, 0, 16, 4, /* IPRH */ { 0, 0, 0, SIOF0 } },
{ 0xa4080006, 0, 16, 4, /* IPRI */ { 0, 0, SIOF1 } },
};
static DECLARE_INTC_DESC(intc_desc, "sh7710", vectors, NULL,
NULL, prio_registers, NULL);
static struct resource rtc_resources[] = {
[0] = {
.start = 0xa413fec0,
.end = 0xa413fec0 + 0x1e,
.flags = IORESOURCE_IO,
},
[1] = {
.start = evt2irq(0x480),
.flags = IORESOURCE_IRQ,
},
};
static struct sh_rtc_platform_info rtc_info = {
.capabilities = RTC_CAP_4_DIGIT_YEAR,
};
static struct platform_device rtc_device = {
.name = "sh-rtc",
.id = -1,
.num_resources = ARRAY_SIZE(rtc_resources),
.resource = rtc_resources,
.dev = {
.platform_data = &rtc_info,
},
};
static struct plat_sci_port scif0_platform_data = {
.mapbase = 0xa4400000,
.flags = UPF_BOOT_AUTOCONF,
.scscr = SCSCR_TE | SCSCR_RE | SCSCR_REIE |
SCSCR_CKE1 | SCSCR_CKE0,
.scbrr_algo_id = SCBRR_ALGO_2,
.type = PORT_SCIF,
.irqs = SCIx_IRQ_MUXED(evt2irq(0x880)),
};
static struct platform_device scif0_device = {
.name = "sh-sci",
.id = 0,
.dev = {
.platform_data = &scif0_platform_data,
},
};
static struct plat_sci_port scif1_platform_data = {
.mapbase = 0xa4410000,
.flags = UPF_BOOT_AUTOCONF,
.scscr = SCSCR_TE | SCSCR_RE | SCSCR_REIE |
SCSCR_CKE1 | SCSCR_CKE0,
.scbrr_algo_id = SCBRR_ALGO_2,
.type = PORT_SCIF,
.irqs = SCIx_IRQ_MUXED(evt2irq(0x900)),
};
static struct platform_device scif1_device = {
.name = "sh-sci",
.id = 1,
.dev = {
.platform_data = &scif1_platform_data,
},
};
static struct sh_timer_config tmu0_platform_data = {
.channel_offset = 0x02,
.timer_bit = 0,
.clockevent_rating = 200,
};
static struct resource tmu0_resources[] = {
[0] = {
.start = 0xa412fe94,
.end = 0xa412fe9f,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = evt2irq(0x400),
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device tmu0_device = {
.name = "sh_tmu",
.id = 0,
.dev = {
.platform_data = &tmu0_platform_data,
},
.resource = tmu0_resources,
.num_resources = ARRAY_SIZE(tmu0_resources),
};
static struct sh_timer_config tmu1_platform_data = {
.channel_offset = 0xe,
.timer_bit = 1,
.clocksource_rating = 200,
};
static struct resource tmu1_resources[] = {
[0] = {
.start = 0xa412fea0,
.end = 0xa412feab,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = evt2irq(0x420),
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device tmu1_device = {
.name = "sh_tmu",
.id = 1,
.dev = {
.platform_data = &tmu1_platform_data,
},
.resource = tmu1_resources,
.num_resources = ARRAY_SIZE(tmu1_resources),
};
static struct sh_timer_config tmu2_platform_data = {
.channel_offset = 0x1a,
.timer_bit = 2,
};
static struct resource tmu2_resources[] = {
[0] = {
.start = 0xa412feac,
.end = 0xa412feb5,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = evt2irq(0x440),
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device tmu2_device = {
.name = "sh_tmu",
.id = 2,
.dev = {
.platform_data = &tmu2_platform_data,
},
.resource = tmu2_resources,
.num_resources = ARRAY_SIZE(tmu2_resources),
};
static struct platform_device *sh7710_devices[] __initdata = {
&scif0_device,
&scif1_device,
&tmu0_device,
&tmu1_device,
&tmu2_device,
&rtc_device,
};
static int __init sh7710_devices_setup(void)
{
return platform_add_devices(sh7710_devices,
ARRAY_SIZE(sh7710_devices));
}
arch_initcall(sh7710_devices_setup);
static struct platform_device *sh7710_early_devices[] __initdata = {
&scif0_device,
&scif1_device,
&tmu0_device,
&tmu1_device,
&tmu2_device,
};
void __init plat_early_device_setup(void)
{
early_platform_add_devices(sh7710_early_devices,
ARRAY_SIZE(sh7710_early_devices));
}
void __init plat_irq_setup(void)
{
register_intc_controller(&intc_desc);
plat_irq_setup_sh3();
}
|
4159791152ce5345a79f4f42ba35b62617e11af5
|
693bd39eb66eade67997bc608fe84e76e66eeec2
|
/utils/mpp_opt.c
|
3c37cf3df8f685714deac03396bbc9cac2371e82
|
[] |
permissive
|
HermanChen/mpp
|
6a1751777b120b764f86e0f34975231054a3c262
|
0af9b5becc76c4685831214808e124e65543297b
|
refs/heads/develop
| 2023-08-17T07:17:49.489974
| 2023-07-31T08:26:14
| 2023-08-11T07:38:17
| 71,088,248
| 139
| 79
|
Apache-2.0
| 2023-03-08T09:44:01
| 2016-10-17T01:13:37
|
C
|
UTF-8
|
C
| false
| false
| 3,511
|
c
|
mpp_opt.c
|
/*
* Copyright 2020 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define MODULE_TAG "mpp_opt"
#include "mpp_mem.h"
#include "mpp_log.h"
#include "mpp_trie.h"
#include "mpp_common.h"
#include "mpp_opt.h"
typedef struct MppOptImpl_t {
void *ctx;
MppTrie trie;
RK_S32 node_cnt;
RK_S32 info_cnt;
} MppOptImpl;
MPP_RET mpp_opt_init(MppOpt *opt)
{
MppOptImpl *impl = mpp_calloc(MppOptImpl, 1);
*opt = impl;
return (impl) ? MPP_OK : MPP_NOK;
}
MPP_RET mpp_opt_deinit(MppOpt opt)
{
MppOptImpl *impl = (MppOptImpl *)opt;
if (NULL == impl)
return MPP_NOK;
if (impl->trie) {
mpp_trie_deinit(impl->trie);
impl->trie = NULL;
}
MPP_FREE(impl);
return MPP_OK;
}
MPP_RET mpp_opt_setup(MppOpt opt, void *ctx, RK_S32 node_cnt, RK_S32 opt_cnt)
{
MppOptImpl *impl = (MppOptImpl *)opt;
if (NULL == impl)
return MPP_NOK;
mpp_trie_init(&impl->trie, node_cnt, opt_cnt);
if (impl->trie) {
impl->ctx = ctx;
impl->node_cnt = node_cnt;
impl->info_cnt = opt_cnt;
return MPP_OK;
}
mpp_err_f("failed to setup node %d opt %d\n", node_cnt, opt_cnt);
return MPP_NOK;
}
MPP_RET mpp_opt_add(MppOpt opt, MppOptInfo *info)
{
MppOptImpl *impl = (MppOptImpl *)opt;
if (NULL == impl || NULL == impl->trie)
return MPP_NOK;
if (NULL == info) {
RK_S32 node_cnt = mpp_trie_get_node_count(impl->trie);
RK_S32 info_cnt = mpp_trie_get_info_count(impl->trie);
if (impl->node_cnt != node_cnt || impl->info_cnt != info_cnt)
mpp_log("setup:real node %d:%d info %d:%d\n",
impl->node_cnt, node_cnt, impl->info_cnt, info_cnt);
return MPP_OK;
}
return mpp_trie_add_info(impl->trie, &info->name);
}
MPP_RET mpp_opt_parse(MppOpt opt, int argc, char **argv)
{
MppOptImpl *impl = (MppOptImpl *)opt;
MPP_RET ret = MPP_NOK;
RK_S32 opt_idx = 0;
if (NULL == impl || NULL == impl->trie || argc < 2 || NULL == argv)
return ret;
ret = MPP_OK;
while (opt_idx <= argc) {
RK_S32 opt_next = opt_idx + 1;
char *opts = argv[opt_idx++];
char *next = (opt_next >= argc) ? NULL : argv[opt_next];
if (NULL == opts)
break;
if (opts[0] == '-' && opts[1] != '\0') {
MppOptInfo *info = NULL;
const char **name = mpp_trie_get_info(impl->trie, opts + 1);
RK_S32 step = 0;
if (NULL == name) {
mpp_err("invalid option %s\n", opts + 1);
continue;
}
info = container_of(name, MppOptInfo, name);
if (info->proc)
step = info->proc(impl->ctx, next);
/* option failure or help */
if (step < 0) {
ret = step;
break;
}
opt_idx += step;
}
}
return ret;
}
|
c7a6f480aa0cf2b1ae32f249fb9b4b22bb776bdf
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/sim/V2/lib/VisItControlInterface_V2.h
|
646ddbd014ce21b28f290ace47fb9d926e86cb82
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 55,954
|
h
|
VisItControlInterface_V2.h
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
#ifndef VISIT_CONTROL_INTERFACE_V2_H
#define VISIT_CONTROL_INTERFACE_V2_H
#include <VisItInterfaceTypes_V2.h>
/*****************************************************************************
* File: VisItControlInterface_V2.h
*
* Purpose:
* Abstraction of VisIt Engine wrapper library. Handles the
* grunt work of actually connecting to visit that must be done
* outside of the VisItEngine DLL.
*
* Programmer: Brad Whitlock,
* Creation: Thu Mar 11 14:42:24 PST 2010
*
* Modifications:
*
*****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************
* Function: VisItSetBroadcastIntFunction
*
* Purpose:
* This function installs a callback function that allows libsim to broadcast
* an integer from the root process to slave processes.
*
* Arguments: A pointer to a callback function with prototype:
* int func(int *, int);
*
* Returns: None
*
* Note: All processors must call this function and install a callback
* function after initializing MPI. The callback function must be
* installed prior to VisItDetectInput.
*
* Sample callback function:
* static int visit_broadcast_int_callback(int *value, int sender)
* {
* return MPI_Bcast(value, 1, MPI_INT, sender, MPI_COMM_WORLD);
* }
*
* ****************************************************************************/
/* DEPRECATED */
void VisItSetBroadcastIntFunction(int (*bicb)(int *, int));
/******************************************************************************
* Function: VisItSetBroadcastIntFunction2
*
* Purpose:
* This function installs a callback function that allows libsim to broadcast
* an integer from the root process to slave processes.
*
* Arguments: A pointer to a callback function with prototype:
* int func(int *, int, void *);
*
* Returns: None
*
* Note: All processors must call this function and install a callback
* function after initializing MPI. The callback function must be
* installed prior to VisItDetectInput.
*
* Sample callback function:
* static int visit_broadcast_int_callback(int *value, int sender,
* void *ptr)
* {
* simdata_t *sim = (simdata_t *)ptr;
* return MPI_Bcast(value, 1, MPI_INT, sender, sim->communicator);
* }
*
* ****************************************************************************/
void VisItSetBroadcastIntFunction2(int (*cb)(int *, int, void *), void *);
/******************************************************************************
* Function: VisItSetBroadcastStringFunction
*
* Purpose:
* This function installs a callback function that allows libsim to broadcast
* a character string from the root process to slave processes.
*
* Arguments: A pointer to a callback function with prototype:
* int func(char *, int, int);
*
* Returns: None
*
* Note: All processors must call this function and install a callback
* function after initializing MPI. The callback function must be
* installed prior to VisItDetectInput.
*
* Sample callback function:
* static int visit_broadcast_string_callback(char *str, int len, int sender)
* {
* return MPI_Bcast(str, len, MPI_CHAR, sender, MPI_COMM_WORLD);
* }
*
* ****************************************************************************/
/* DEPRECATED */
void VisItSetBroadcastStringFunction(int (*bscb)(char *, int, int));
/******************************************************************************
* Function: VisItSetBroadcastStringFunction2
*
* Purpose:
* This function installs a callback function that allows libsim to broadcast
* a character string from the root process to slave processes.
*
* Arguments: A pointer to a callback function with prototype:
* int func(char *, int, int, void *);
*
* Returns: None
*
* Note: All processors must call this function and install a callback
* function after initializing MPI. The callback function must be
* installed prior to VisItDetectInput.
*
* Sample callback function:
* static int visit_broadcast_string_callback(char *str, int len,
* int sender, void *ptr)
* {
* simdata_t *sim = (simdata_t *)ptr;
* return MPI_Bcast(str, len, MPI_CHAR, sender, sim->communicator);
* }
*
* ****************************************************************************/
void VisItSetBroadcastStringFunction2(int (*cb)(char *, int, int, void *), void *);
/******************************************************************************
* Function: VisItSetParallel
*
* Purpose:
* Set whether or not libsim will be operating in parallel.
*
* Arguments:
* flag : Pass a non-zero value to indicate parallel; 0 for serial operation.
*
* Returns: None
*
* Note: All processors must call this function. Only parallel simulations
* need to call this function.
*
* ****************************************************************************/
void VisItSetParallel(int);
/******************************************************************************
* Function: VisItSetParallelRank
*
* Purpose:
* Set the rank of the current process within its MPI communicator.
*
* Arguments:
* rank : The MPI rank of the process.
*
* Returns: None
*
* Note: All processors must call this function. Only parallel simulations
* need to call this function.
*
* ****************************************************************************/
void VisItSetParallelRank(int);
/******************************************************************************
* Function: VisItSetDirectory
*
* Purpose:
* Set the path to the top level directory where VisIt is installed. This lets
* libsim load runtime libraries from a specific version of VisIt. If you never
* call this function, libsim will obtain VisIt runtime information using the
* "visit" script in your path. If that is the case, the latest runtime libraries
* will be used but it may not match the version of the client that is trying
* to connect to VisIt. Version mismatches are avoided (but not eliminated) by
* only using installed versions of VisIt to connect to a simulation.
*
* Arguments:
* path : The path to the top level VisIt directory. This does not include the
* "bin/visit" part of the path; just "/path/to/visitdir".
*
* Returns: None
*
* Note: All processors must call this function. This function must be
* called before VisItSetupEnvironment.
*
* ****************************************************************************/
void VisItSetDirectory(char *);
/******************************************************************************
* Function: VisItSetOptions
*
* Purpose:
* Pass command line arguments that will be used when calling out to VisIt to
* determine the runtime libraries that libsim will need to load when VisIt
* connects. You can use this function to pass arguments such as
* "-forceversion 1.12.0" to force a specific version of VisIt.
*
* Arguments:
* args : A null-terminated string containing additional arguments will be
* passed to VisIt when determining the runtime libraries that need to
* be loaded when VisIt connects to the simulation.
*
* Returns: None
*
* Note: All processors must call this function. This function must be
* called before VisItSetupEnvironment.
*
* ****************************************************************************/
void VisItSetOptions(char *);
/******************************************************************************
* Function: VisItSetupEnvironment
*
* Purpose:
* Sets up the environment so VisIt can be loaded into libsim when the
* VisIt client wants to connect
*
* Arguments: None
*
* Returns: TRUE, FALSE
*
* Note: All processors must call this function and they must call it
* before VisItInitializeSocketAndDumpSimFile and VisItDetectInput.
*
* If is recommended that parallel simulations call these functions
* beforehand so this function will be able to use a collective
* broadcast internally to speed up sending the environment to
* other processors: VisItSetParallel, VisItSetParallelRank,
* VisItSetBroadcastStringFunction.
*
* ****************************************************************************/
int VisItSetupEnvironment(void);
/******************************************************************************
* Function: VisItSetupEnvironment2
*
* Purpose:
* Sets up the environment so VisIt can be loaded into libsim when the
* VisIt client wants to connect. This function does the same thing as
* VisItSetupEnvironment but it lets you pass in the environment string
* discovered by VisItGetEnvironment.
*
* You would use this version when your MPI does not like to let your
* application spawn processes to discover the environment.
*
* Arguments: env : The environment returned by
*
* Returns: TRUE, FALSE
*
* Note: All processors must call this function and they must call it
* before VisItInitializeSocketAndDumpSimFile and VisItDetectInput.
*
* Non-rank 0 processors may pass NULL for the environment if they
* wish to inherit the environment read by processor 0.
*
* If is recommended that parallel simulations call these functions
* beforehand so this function will be able to use a collective
* broadcast internally to speed up sending the environment to
* other processors: VisItSetParallel, VisItSetParallelRank,
* VisItSetBroadcastStringFunction.
*
* Non-rank 0 processors may pass NULL for the environment if they
* wish to inherit the environment read by processor 0. (Only if
* you have set up collective broadcast). Otherwise, passing NULL
* will cause an implicit call to VisItGetEnvironment.
*
* ****************************************************************************/
int VisItSetupEnvironment2(char *env);
/******************************************************************************
* Function: VisItGetEnvironment
*
* Purpose:
* Discover the environment needed so VisIt can be loaded into libsim when
* the VisIt client wants to connect.
*
* Arguments: None
*
* Returns: A user-owned character buffer containing the environment strings.
*
* ****************************************************************************/
char *VisItGetEnvironment(void);
/******************************************************************************
* Function: VisItInitializeSocketAndDumpSimFile
*
* Purpose:
* This function makes the simulation start listening for inbound VisIt
* socket connections and it writes a .sim1 file that tells VisIt how to
* connect to the simulation.
*
* Arguments:
* name : The name of the simulation, which will be used in the
* created filename.
* comment : A comment describing the simulation.
* path : The path where the simulation was started.
* inputfile : reserved, pass NULL
* guifile : reserved, pass NULL
* absoluteFilename : reserved, pass NULL
*
* Returns: 1 on success, 0 on failure
*
* Note: Only the root processor should call this function. This function
* should be called early on and before the calls to VisItDetectInput.
*
* ****************************************************************************/
int VisItInitializeSocketAndDumpSimFile(const char *name,
const char *comment,
const char *path,
const char *inputfile,
const char *guifile,
const char *absoluteFilename);
/******************************************************************************
* Function: VisItDetectInput
*
* Purpose:
* Simulations call this function to detect input from the listen socket,
* client socket, or console. Call this function in a loop to form the main
* event loop for a simulation.
*
* Arguments:
* blocking : Pass a non-zero value to tell the function to wait until there
* is input before returning. If you want to run the simulation
* without waiting for input, you will want to pass 0 so the
* function times out and returns whether or not there is input
* to be handled.
*
* consoledesc : If you want to handle input from another file in addition
* to the VisIt sockets, pass a file descriptor for the file
* that you want to monitor. If you want to monitor the console
* for typed commands, pass fileno(stdin). If you do not want
* to monitor other files, pass -1 for the descriptor.
*
* Returns:
* -5: Logic error (fell through all cases)
* -4: Logic error (no descriptors but blocking)
* -3: Logic error (a socket was selected but not one we set)
* -2: Unknown error in select
* -1: Interrupted by EINTR in select
* 0: Okay - Timed out
* 1: Listen socket input
* 2: Engine socket input
* 3: Console socket input
*
* Note: This function should only be called by the root process in
* parallel. The results of this function should be broadcast to
* other processors so that all may follow the same general call
* pattern.
*
* What to do with a return value:
* 0 : The function timed out; execute a time step
* 1 : An inbound VisIt connection is being made. Call the
* VisItAttemptToCompleteConnection function.
* 2 : The VisIt viewer sent instructions to the simulation so
* call the VisItProcessEngineCommand function.
* 3 : Console input was detected so read stdin and handle it.
* other : error out, stop calling VisItDetectInput.
*
* ****************************************************************************/
int VisItDetectInput(int blocking, int consoledesc);
int VisItDetectInputWithTimeout(int blocking, int timeout_usec, int consoledesc);
#ifndef _WIN32
/*******************************************************************************
* Function: VisItGetSockets
*
* Purpose:
* VisItDetectInput detects input from VisIt's listen socket, a client socket,
* and optionally, a console file descriptor. This function lets you obtain the
* file descriptors to which VisItDetectInput would have listened, allowing you
* to pass the socket descriptors to your own listening routines should you
* need to do so.
*
* Arguments:
* lSocket : Pass the address of an integer that will contain the listen socket
* file descriptor. When the function returns, the address will contain
* the listen file descriptor or -1 if you should not ignore the
* result.
*
* cSocket : Pass the address of an integer that will contain the client socket
* file descriptor. When the function returns, the address will contain
* the client file descriptor or -1 if you should not ignore the
* result.
*
* Returns: VISIT_OKAY on success, VISIT_ERROR on failure.
*
* Note: This function is not available on Windows because input is handled
* differently than on UNIX and VisItDetectInput should not be
* circumvented. In any case, only use this function if you REALLY
* know what you are doing. You should prefer using VisItDetectInput
* whenever possible.
*
*******************************************************************************/
int VisItGetSockets(int *lSocket, int *cSocket);
#endif
/******************************************************************************
* Function: VisItAttemptToCompleteConnection
*
* Purpose:
* Accept the inbound VisIt connection socket, verify security keys, get the
* connection parameters from the client, load the VisIt engine library,
* create the Engine and connect back to the VisIt viewer.
*
* Arguments: None
*
* Returns: 1 on success; 0 on failure
*
* Note: This function should be called when VisItDetectInput returns 1.
*
* ****************************************************************************/
int VisItAttemptToCompleteConnection(void);
/******************************************************************************
* Function: VisItReadConsole
*
* Purpose:
* Read characters from the console.
*
* Arguments:
* maxlen : The size of the buffer.
* buffer : the buffer into which the values will be read.
*
* Returns: VISIT_OKAY on success; VISIT_ERROR on failure
*
* Note: This function should be called when VisItDetectInput returns 3.
* Only the root processor should call this function.
*
* ****************************************************************************/
int VisItReadConsole(int maxlen, char *buffer);
/******************************************************************************
* Function: VisItSetSlaveProcessCallback
*
* Purpose:
* Set the callback function used to inform slave processes that they should
* call VisItfor ProcessEngineCommand. The provided callback function is used
* internally in libsim
*
*
* Arguments: A pointer to a function with prototype: void func(void);
*
* Returns: None
*
* Note: The slave process callback is required for a parallel simulation.
* This function should be called when VisItAttemptToCompleteConnection
* returns successfully.
*
* MPI simulations may define the callback like this:
* void slave_process_callback()
* {
* int command = 0;
* MPI_BCast(&command, 1, MPI_INT, 0, MPI_COMM_WORLD);
* }
*
* ****************************************************************************/
void VisItSetSlaveProcessCallback(void(*spcb)(void));
/******************************************************************************
* Function: VisItSetSlaveProcessCallback2
*
* Purpose:
* Set the callback function used to inform slave processes that they should
* call VisItProcessEngineCommand. The provided callback function is used
* internally in libsim
*
*
* Arguments: A pointer to a function with prototype: void func(void *);
* A pointer to some callback function data.
*
* Returns: None
*
* Note: The slave process callback is required for a parallel simulation.
* This function should be called when VisItAttemptToCompleteConnection
* returns successfully.
*
* MPI simulations may define the callback like this:
* void slave_process_callback(void *ptr)
* {
* int command = 0;
* simdata_t *sim = (simdata_t *)ptr;
* MPI_BCast(&command, 1, MPI_INT, 0, sim->communicator);
* }
*
* ****************************************************************************/
void VisItSetSlaveProcessCallback2(void(*cb)(void *), void *);
/******************************************************************************
* Function: VisItSetCommandCallback
*
* Purpose:
* Set the callback for processing control commands (these are set up in
* the simulation's metadata).
*
* Arguments: A pointer to a function with prototype:
* void func(const char*,const char*,void*);
*
* The callback function arguments are:
* cmd : The name of the command being called.
* sdata : string argument (reserved)
* void* : User callback data.
*
* Returns: None
*
* Note: This function must be called on all processors to install the
* callback function. This function should be called when
* VisItAttemptToCompleteConnection returns successfully.
*
* ****************************************************************************/
void VisItSetCommandCallback(void(*cb)(const char*,const char*,void*), void *cbdata1);
/******************************************************************************
* Function: VisItProcessEngineCommand
*
* Purpose:
* This function reads input from VisIt's viewer and executes the requests.
* The VisItProcessEngineCommand function needs to be called from the
* simulation's event loop when VisItDetectInput return 2, indicating that
* there is input to be processed.
*
* Arguments: None
*
* Returns: 1 on success; 0 on failure.
*
* Note: All processors must call this function.
*
* ****************************************************************************/
int VisItProcessEngineCommand(void);
/******************************************************************************
* Function: VisItTimeStepChanged
*
* Purpose:
* The simulation can use this function to tell VisIt that it has changed to
* a new time step. This causes the simulation to send new metadata to
* VisIt.
*
* Arguments: None
*
* Returns: None
*
* Note: All processors must call this function.
*
* ****************************************************************************/
void VisItTimeStepChanged(void);
/******************************************************************************
* Function: VisItUpdatePlots
*
* Purpose:
* The simulation can use this function to tell VisIt to update its plots
* using new data from the simulation. Calling this function only serves as
* a trigger to VisIt that it needs to update its plots. The simulation should
* take care to pause until VisIt has made all of its requests from the
* simulation or multiple plots may contain data from different time steps
* if the simulation has kept running.
*
* Arguments: None
*
* Returns: None
*
* Note: This function has no effect when called by non-master
* processes. When VisIt is connected to the simulation, calling
* this function on the master process will send commands to process
* to VisIt's viewer. The sim will then process VisIt commands in
* a synchronization loop if synchronization is enabled. In that case,
* ALL processors must call this function. During the synchronization
* loop, VisIt commands will be handled via the normal simulation
* callback functions. Once synchronization is complete, the function
* returns. If synchronization is not enabled then this function
* returns immediately and relies on the simulation's main loop
* for processing VisIt commands that result from the update.
*
* ****************************************************************************/
void VisItUpdatePlots(void);
/******************************************************************************
* Function: VisItExecuteCommand
*
* Purpose:
* This simulation can use this function to tell VisIt to execute VisIt CLI
* Python commands. The commands are sent to VisIt in a non-blocking fashion
* and VisIt later translates the commands into requests to the simulation.
*
* Arguments: A null-terminated character string containing the commands to
* be executed.
*
* Returns: None
*
* Note: And example call to this function could look like:
* VisItExecuteCommand("AddPlot(\"Pseudocolor\", \"zonal\")\n");
*
* This function has no effect when called by non-master
* processes. When VisIt is connected to the simulation, calling
* this function on the master process will send commands to process
* to VisIt's viewer. The sim will then process VisIt commands in
* a synchronization loop if synchronization is enabled. In that case,
* ALL processors must call this function. During the synchronization
* loop, VisIt commands will be handled via the normal simulation
* callback functions. Once synchronization is complete, the function
* returns. If synchronization is not enabled then this function
* returns immediately and relies on the simulation's main loop
* for processing VisIt commands that result from the command.
*
* ****************************************************************************/
void VisItExecuteCommand(const char *);
/******************************************************************************
* Function: VisItDisconnect
*
* Purpose:
* This function disconnects the simulation from VisIt. It should be called
* from the simulation's event loop when VisItProcessEngineCommand returns
* failure.
*
* Arguments: None
*
* Returns: None
*
* Note: All processors must call this function.
*
* ****************************************************************************/
void VisItDisconnect(void);
/******************************************************************************
* Function: VisItIsConnected
*
* Purpose:
* This function returns 1 if VisIt is connected; 0 otherwise.
*
* Arguments: None
*
* Returns: 1 if VisIt is connected; 0 otherwise.
*
* Note:
*
* ****************************************************************************/
int VisItIsConnected(void);
/******************************************************************************
* Function: VisItIsRuntimeLoaded
*
* Purpose:
* This function returns 1 if the VisIt runtime is loaded; 0 otherwise.
*
* Arguments: None
*
* Returns: 1 if VisIt runtime is loaded; 0 otherwise.
*
* Note:
*
* ****************************************************************************/
int VisItIsRuntimeLoaded(void);
/******************************************************************************
* Function: VisItGetLastError
*
* Purpose:
* This function returns a pointer to a character string that contains the
* last error that libsim encountered.
*
* Arguments: None
*
* Returns: A null-terminated character string that contains the last error.
*
* Note:
*
* ****************************************************************************/
char *VisItGetLastError(void);
/******************************************************************************
* Function: VisItSynchronize
*
* Purpose:
* This function blocks the simulation, creating a new event loop to handle
* requests from VisIt until VisIt returns a synchronize tag.
*
* Arguments: None
*
* Returns: None
*
* Note: Do not call recursively!
*
* ****************************************************************************/
int VisItSynchronize(void);
/******************************************************************************
* Function: VisItEnableSynchronize
*
* Purpose:
* This function sets whether synchronization is enabled for functions such as
* VisItUpdatePlots and VisItExecuteCommand.
*
* Arguments:
* sync : Non-zero values enable synchronization, zero disables it.
*
* Returns: None
*
* Note:
*
* ****************************************************************************/
void VisItEnableSynchronize(int);
/******************************************************************************
* Function: VisItDebug
*
* Purpose:
* These functions let you write a printf-style output to VisIt's debugging
* logs.
*
* Arguments:
* format : A format string.
*
* Returns: None
*
* Note: These functions have no effect until VisIt has connected.
*
* ****************************************************************************/
void VisItDebug1(const char *format, ...);
void VisItDebug2(const char *format, ...);
void VisItDebug3(const char *format, ...);
void VisItDebug4(const char *format, ...);
void VisItDebug5(const char *format, ...);
/******************************************************************************
* Function: VisItOpenTraceFile
*
* Purpose:
* This function opens a trace file that contains a trace of all of SimV2's
* function calls. The trace file is meant to aid in debugging.
*
* Arguments:
* filename : The name of the trace file.
*
* Returns: None
*
* Note:
*
* ****************************************************************************/
void VisItOpenTraceFile(const char *filename);
/******************************************************************************
* Function: VisItCloseTraceFile
*
* Purpose:
* This function closes the trace file.
*
* Arguments: None
*
* Returns: None
*
* Note:
*
* ****************************************************************************/
void VisItCloseTraceFile(void);
/******************************************************************************
* Function: VisItSaveWindow
*
* Purpose:
* This function saves the last plot to an image file.
*
* Arguments:
* filename : The name of the image file.
* width : The width of the saved image.
* height : The height of the saved image.
* format : The format in which to save the image. (e.g. VISIT_IMAGEFORMAT_JPEG)
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: A plot must have already been created. Call this function on all
* processors.
*
* ****************************************************************************/
int VisItSaveWindow(const char *filename, int width, int height, int format);
/******************************************************************************
* Function: VisItBeginCinema
*
* Purpose:
* This function saves parameters for a new Cinema database. This makes it
* so we don't pass contradictory parameters later on and we also allocate
* some internal storage for this Cinema database.
*
* Arguments:
* h : A pointer to the visit_handle that we'll allocate.
* file_cdb : The name of the .cdb directory that contains the Cinema data.
* dbspec : The database specification VISIT_CINEMA_SPEC_A, C, D.
* composite : 0 for images, 1 for composite images.
* imgformat: The format in which to save the image. (e.g. VISIT_IMAGEFORMAT_JPEG)
* width : The width of the saved image.
* height : The height of the saved image.
* cameratype: The camera type. VISIT_CINEMA_CAMERA_STATIC, VISIT_CINEMA_CAMERA_PHI_THETA.
* nphi : The number of divisions in phi (for VISIT_CINEMA_CAMERA_PHI_THETA).
* ntheta : The number of divisions in theta (for VISIT_CINEMA_CAMERA_PHI_THETA).
* varnames : A namelist object containing variable names. This parameter is
* optional. If you do not want to specify additional variable
* names, pass VISIT_INVALID_HANDLE.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: A plot must have already been created. Call this function on all
* processors.
*
* ****************************************************************************/
int VisItBeginCinema(visit_handle *h,
const char *file_cdb, int dbspec, int composite,
int imgformat, int width, int height,
int cameratype, int nphi, int ntheta,
visit_handle varnames);
/******************************************************************************
* Function: VisItSaveCinema
*
* Purpose:
* This function saves the current plots to the file_cdb Cinema database.
*
* Arguments:
* h : The handle returned from VisItBeginCinema.
* time : The time value for the current time step we're saving.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: A plot must have already been created. Call this function on all
* processors.
*
* ****************************************************************************/
int VisItSaveCinema(visit_handle h, double time);
/******************************************************************************
* Function: VisItEndCinema
*
* Purpose:
* This function ends a Cinema database.
*
* Arguments:
* h : The handle returned from VisItBeginCinema.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note:
*
* ****************************************************************************/
int VisItEndCinema(visit_handle h);
/******************************************************************************
* Function: VisItSetMPICommunicator
*
* Purpose:
* This function sets the communicator that VisIt should use for parallel
* operations. Note that you may want to temporarily install a communicator
* for vis operations and then revert to the default communicator for when
* VisIt needs to communicate commands to other processes.
*
* Arguments:
* mpicom : A pointer to the communicator that we should use.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: Passing NULL lets VisIt revert to its copy of MPI_COMM_WORLD.
*
* ****************************************************************************/
int VisItSetMPICommunicator(void *mpicom);
/******************************************************************************
* Function: VisItSetMPICommunicator_f
*
* Purpose:
* This function sets the communicator that VisIt should use for parallel
* operations from a Fortran handle. Note that you may want to temporarily
* install a communicator for vis operations and then revert to the default
* communicator for when VisIt needs to communicate commands to other
* processes.
*
* Arguments:
* mpicom : A pointer to the FORTRAN communicator that we should use.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: use VisItSetMPICommunicator to revert to its copy of MPI_COMM_WORLD.
*
* ****************************************************************************/
int VisItSetMPICommunicator_f(int *mpicom);
/******************************************************************************
* Function: VisItInitializeRuntime
*
* Purpose:
* Initialize the VisIt runtime without the client being connected.
*
* Arguments:
*
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: Call this function on all processors.
*
* ****************************************************************************/
int VisItInitializeRuntime(void);
/******************************************************************************
* Function: VisItGetMemory
*
* Purpose:
* Measure memory usage for the current processor.
*
* Arguments:
* m_size : The number of MiB in use.
* m_rss : The resident set size in MiB.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function can be called in individual processors.
*
* ****************************************************************************/
int VisItGetMemory(double *m_size, double *m_rss);
/******************************************************************************
* Function: VisItExportDatabase
*
* Purpose:
* Export the active plots to database files.
*
* Arguments:
* filename : The name of the file to save. If it does not have a path then
* the current working directory will be where files are saved.
* File format writers are free to append their own file extensions
* to this name.
* format : The name of a database plugin for the export. This can be either
* the plugin name or id (e.g. "Silo" or "Silo_1.0").
* variables: A name list containing the names of the variables to be exported.
* If an empty list or VISIT_INVALID_HANDLE are passed then the
* "default" variables will be exported.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: The active plots in the plot list are exported just like in
* typical export usage from VisIt.
*
* Call this function on all processors.
*
* ****************************************************************************/
int VisItExportDatabase(const char *filename, const char *format,
visit_handle variables);
/******************************************************************************
* Function: VisItExportDatabaseWithOptions
*
* Purpose:
* Export the active plots to database files.
*
* Arguments:
* filename : The name of the file to save. If it does not have a path then
* the current working directory will be where files are saved.
* File format writers are free to append their own file extensions
* to this name.
* format : The name of a database plugin for the export. This can be either
* the plugin name or id (e.g. "Silo" or "Silo_1.0").
* variables: A name list containing the names of the variables to be exported.
* If an empty list or VISIT_INVALID_HANDLE are passed then the
* "default" variables will be exported.
* options : A handle to an optional optionlist object (contaisn key/value
* pairs) or VISIT_INVALID_HANDLE if no options are to be passed.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: The active plots in the plot list are exported just like in
* typical export usage from VisIt.
*
* Call this function on all processors.
*
* ****************************************************************************/
int VisItExportDatabaseWithOptions(const char *filename, const char *format,
visit_handle variables, visit_handle options);
/******************************************************************************
* Function: VisItRestoreSession
*
* Purpose:
* Restores a session file to set up the visualization that will be saved
* from operations such as VisItSaveWindow and VisItExportDatabase.
*
* Arguments:
* filename : The path to the session file.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: Call this function on all processors.
*
* ****************************************************************************/
int VisItRestoreSession(const char *filename);
/******************************************************************************
*******************************************************************************
***
*** Functions to install data access callback functions
***
*******************************************************************************
******************************************************************************/
/******************************************************************************
* Function: VisItSetActivateTimestep
*
* Purpose:
* This function installs a callback function that does collective
* communication before other data access callback functions are called.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetActivateTimestep(int (*cb)(void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetMetaData
*
* Purpose:
* This function installs a callback function that gets simulation metadata.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetMetaData(visit_handle (*cb)(void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetMesh
*
* Purpose:
* This function installs a callback function that gets a mesh.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of mesh
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetMesh(visit_handle (*cb)(int, const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetMaterial
*
* Purpose:
* This function installs a callback function that gets a material.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of material
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetMaterial(visit_handle (*cb)(int, const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetSpecies
*
* Purpose:
* This function installs a callback function that gets species data.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of species
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetSpecies(visit_handle (*cb)(int, const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetVariable
*
* Purpose:
* This function installs a callback function that gets variable data.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of variable
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetVariable(visit_handle (*cb)(int, const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetMixedVariable
*
* Purpose:
* This function installs a callback function that gets mixed variable data.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of mixed variable
* void* : User-supplied callback data.
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetMixedVariable(visit_handle (*cb)(int, const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetCurve
*
* Purpose:
* This function installs a callback function that gets curve data.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of curve
* void* : User-supplied callback data.
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetCurve(visit_handle (*cb)(const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetDomainList
*
* Purpose:
* This function installs a callback function that gets a domain list.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of mesh for domain list (reserved)
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* The domain list callback function must be implemented in order
* for a parallel simulation to work.
*
* ****************************************************************************/
int VisItSetGetDomainList(visit_handle (*cb)(const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetDomainBoundaries
*
* Purpose:
* This function installs a callback function that gets domain boundaries.
* Implementing domain boundaries callback function allows VisIt to create
* ghost zones between domains.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of mesh for domain boundaries
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetDomainBoundaries(visit_handle (*cb)(const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetGetDomainNesting
*
* Purpose:
* This function installs a callback function that returns a domain nesting
* object, which is used to tell VisIt how AMR patches are nested.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* int : The domain number
* const char* : name of mesh for domain nesting
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetGetDomainNesting(visit_handle (*cb)(const char *, void *), void *cbdata1);
/* Functions that install data writer callback functions */
/******************************************************************************
* Function: VisItSetWriteBegin
*
* Purpose:
* This function installs a callback function that can be used to start
* exporting from VisIt back to the simulation.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of mesh
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetWriteBegin(int (*cb)(const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetWriteEnd
*
* Purpose:
* This function installs a callback function that can be called at the
* end of exporting from VisIt to the simulation.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of mesh
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetWriteEnd(int (*cb)(const char *, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetWriteMesh
*
* Purpose:
* This function installs a callback function that is called to export a
* chunk of mesh data from VisIt to the simulation.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of mesh
* int : The domain number
* int : The mesh type
* visit_handle : A handle to a mesh data object.
* visit_handle : A handle to mesh metadata
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetWriteMesh(int (*cb)(const char *, int, int, visit_handle, visit_handle, void *), void *cbdata1);
/******************************************************************************
* Function: VisItSetWriteVariable
*
* Purpose:
* This function installs a callback function that is called to export a chunk
* of variable data from VisIt to the simulation.
*
* Arguments:
* cb : The callback function
* cbdata1 : A pointer to data to pass to the callback function.
*
* The callback function arguments are:
* const char* : name of mesh
* const char* : name of variable
* int : The domain number
* visit_handle : A handle to variable data
* visit_handle : A handle to variable metadata.
* void* : User-supplied callback data.
*
* Returns: VISIT_OKAY on success; otherwise VISIT_ERROR
*
* Note: This function has no effect unless called after a successful
* call to VisItAttemptToCompleteConnection
*
* ****************************************************************************/
int VisItSetWriteVariable(int (*cb)(const char *, const char *, int, visit_handle, visit_handle, void *), void *cbdata1);
/* UI-related functions */
int VisItUI_clicked(const char *name, void (*cb)(void*), void *cbdata2);
int VisItUI_stateChanged(const char *name, void (*cb)(int,void*), void *cbdata2);
int VisItUI_valueChanged(const char *name, void (*cb)(int,void*), void *cbdata2);
int VisItUI_textChanged(const char *name, void (*cb)(char *,void*), void *cbdata2);
int VisItUI_cellChanged(const char *name, void (*cb)(char *,void*), void *cbdata2);
int VisItUI_setValueI(const char *name, int value, int enabled);
int VisItUI_setValueD(const char *name, double value, int enabled);
int VisItUI_setValueV(const char *name, double x, double y, double z, int enabled);
int VisItUI_setValueS(const char *name, const char *value, int enabled);
int VisItUI_setListValueI(const char *name,
int row, int value, int editable, int enabled);
int VisItUI_setListValueD(const char *name,
int row, double value, int editable, int enabled);
int VisItUI_setListValueV(const char *name,
int row, double x, double y, double z, int editable, int enabled);
int VisItUI_setListValueS(const char *name,
int row, const char *value, int editable, int enabled);
int VisItUI_setTableValueI(const char *name,
int row, int col, int value, int enabled);
int VisItUI_setTableValueD(const char *name,
int row, int col, double value, int enabled);
int VisItUI_setTableValueV(const char *name,
int row, int col, double x, double y, double z, int enabled);
int VisItUI_setTableValueS(const char *name,
int row, int col, const char *value, int enabled);
int VisItUI_addStripChartPoint(int chart, int curve, int cycle, double value);
int VisItUI_addStripChartPoints(int chart, int curve, int npts, int *cycles, double *values);
/* Include some experimental plotting functions */
#include <VisItControlInterface_V2_plotting.h>
#ifdef __cplusplus
}
#endif
#endif
|
f17746c1958e09a6794f0497d3e04ace572e546c
|
060bc5ba9a8f707bdac927f30842febf9a4676a1
|
/usr.bin/diff/diff/diff.c
|
e5f62a5f5747c4eebc0896fe0995d3b4797c4b17
|
[
"BSD-4-Clause-UC",
"LicenseRef-scancode-other-permissive"
] |
permissive
|
sergev/LiteBSD
|
14ae93caa709d4707c3b122c243641c8214583c3
|
6f89c18880065a83d3d18661c80f72fb3397a888
|
refs/heads/master
| 2023-01-10T02:20:05.357875
| 2022-07-19T16:41:32
| 2022-07-19T16:41:32
| 19,167,171
| 318
| 58
|
NOASSERTION
| 2022-12-28T16:23:01
| 2014-04-26T02:55:34
|
C
|
UTF-8
|
C
| false
| false
| 6,248
|
c
|
diff.c
|
/* $OpenBSD: diff.c,v 1.22 2003/07/04 17:52:35 millert Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
*
* 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 and documentation 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed or owned by Caldera
* International, Inc.
* 4. Neither the name of Caldera International, Inc. nor the names of other
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
* INTERNATIONAL, INC. 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 CALDERA INTERNATIONAL, INC. 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.
*/
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include "diff.h"
#include "pathnames.h"
#if 0
static char const sccsid[] = "@(#)diff.c 4.7 5/11/89";
#endif
/*
* diff - driver and subroutines
*/
int opt;
int aflag; /* treat all files as text */
int tflag; /* expand tabs on output */
/* Algorithm related options. */
int bflag; /* ignore blanks in comparisons */
int wflag; /* totally ignore blanks in comparisons */
int iflag; /* ignore case in comparisons */
/* Options on hierarchical diffs. */
int rflag; /* recursively trace directories */
int sflag; /* announce files which are same */
char *start; /* do file only if name >= this */
/* Variable for -D D_IFDEF option. */
char *ifdefname; /* What we will print for #ifdef/#endif */
/* Variables for -c and -u context option. */
int context; /* lines of context to be printed */
/* State for exit status. */
int status;
int anychange;
/* Variables for diffdir. */
char **diffargv; /* option list to pass to recursive diffs */
/*
* Input file names.
* With diffdir, file1 and file2 are allocated MAXPATHLEN space,
* and padded with a '/', and then efile1 and efile2 point after
* the '/'.
*/
char *file1, *file2, *efile1, *efile2;
struct stat stb1, stb2;
__dead void usage(void);
int
main(int argc, char **argv)
{
int ch;
status = 2;
diffargv = argv;
while ((ch = getopt(argc, argv, "abC:cD:efhinrS:stU:uw")) != -1) {
switch (ch) {
case 'a':
aflag++;
break;
case 'b':
bflag++;
break;
case 'C':
opt = D_CONTEXT;
if (!isdigit(*optarg))
usage();
context = atoi(optarg); /* XXX - use strtol */
break;
case 'c':
opt = D_CONTEXT;
context = 3;
break;
case 'D':
opt = D_IFDEF;
ifdefname = optarg;
break;
case 'e':
opt = D_EDIT;
break;
case 'f':
opt = D_REVERSE;
break;
case 'h':
/* silently ignore for backwards compatibility */
break;
case 'i':
iflag++;
break;
case 'n':
opt = D_NREVERSE;
break;
case 'r':
rflag++;
break;
case 'S':
start = optarg;
break;
case 's':
sflag++;
break;
case 't':
tflag++;
break;
case 'U':
opt = D_UNIFIED;
if (!isdigit(*optarg))
usage();
context = atoi(optarg); /* XXX - use strtol */
break;
case 'u':
opt = D_UNIFIED;
context = 3;
break;
case 'w':
wflag++;
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
if (argc != 2)
errorx("two filename arguments required");
file1 = argv[0];
file2 = argv[1];
if (!strcmp(file1, "-"))
stb1.st_mode = S_IFREG;
else if (stat(file1, &stb1) < 0)
error("%s", file1);
if (!strcmp(file2, "-"))
stb2.st_mode = S_IFREG;
else if (stat(file2, &stb2) < 0)
error("%s", file2);
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode))
diffdir(argv);
else
diffreg();
done(0);
/* We don't reach this, but needed to make GCC happy. */
return 0;
}
int
min(int a, int b)
{
return (a < b ? a : b);
}
int
max(int a, int b)
{
return (a > b ? a : b);
}
__dead void
done(int sig)
{
if (tempfiles[0] != NULL)
unlink(tempfiles[0]);
if (tempfiles[1] != NULL)
unlink(tempfiles[1]);
if (sig)
_exit(status);
exit(status);
}
void *
emalloc(size_t n)
{
void *p;
if ((p = malloc(n)) == NULL)
error(NULL);
return (p);
}
void *
erealloc(void *p, size_t n)
{
void *q;
if ((q = realloc(p, n)) == NULL)
error(NULL);
return (q);
}
__dead void
error(const char *fmt, ...)
{
va_list ap;
int sverrno = errno;
if (tempfiles[0] != NULL)
unlink(tempfiles[0]);
if (tempfiles[1] != NULL)
unlink(tempfiles[1]);
errno = sverrno;
va_start(ap, fmt);
verr(status, fmt, ap);
va_end(ap);
}
__dead void
errorx(const char *fmt, ...)
{
va_list ap;
if (tempfiles[0] != NULL)
unlink(tempfiles[0]);
if (tempfiles[1] != NULL)
unlink(tempfiles[1]);
va_start(ap, fmt);
verrx(status, fmt, ap);
va_end(ap);
}
__dead void
usage(void)
{
(void)fprintf(stderr,
"usage: diff [-bitw] [-c | -e | -f | -n | -u ] file1 file2\n"
" diff [-bitw] -C number file1 file2\n"
" diff [-bitw] -D string file1 file2\n"
" diff [-bitw] -U number file1 file2\n"
" diff [-biwt] [-c | -e | -f | -n | -u ] "
"[-r] [-s] [-S name]\n dir1 dir2\n");
exit(2);
}
|
c9a55997fafaa39aaec9b40c6e7367914643d633
|
4692f28f86ee84a76abfac8cc8a0dd41fcd402e4
|
/pkg/network/ebpf/c/protocols/postgres/helpers.h
|
973eefc6f82ea12b1bc401cfe3f4907e5cc66d8f
|
[
"CC0-1.0",
"BSD-3-Clause",
"Apache-2.0",
"GPL-1.0-or-later",
"MIT",
"0BSD",
"Unlicense",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"BSD-2-Clause-Views",
"MPL-2.0",
"GPL-2.0-only"
] |
permissive
|
DataDog/datadog-agent
|
cc4b89839d6031903bf23aa12eccc2a3f3c7f213
|
d960cdb7de8fa5d1c7138cfe58e754af80cb796a
|
refs/heads/main
| 2023-09-04T10:45:08.138748
| 2023-09-04T09:13:43
| 2023-09-04T09:13:43
| 49,970,739
| 2,388
| 1,288
|
Apache-2.0
| 2023-09-14T20:06:34
| 2016-01-19T17:40:41
|
Go
|
UTF-8
|
C
| false
| false
| 1,683
|
h
|
helpers.h
|
#ifndef __POSTGRES_HELPERS_H
#define __POSTGRES_HELPERS_H
#include "defs.h"
#include "protocols/sql/helpers.h"
// is_postgres_connect checks if the buffer is a Postgres startup message.
static __always_inline bool is_postgres_connect(const char *buf, __u32 buf_size) {
CHECK_PRELIMINARY_BUFFER_CONDITIONS(buf, buf_size, POSTGRES_STARTUP_MIN_LEN);
struct pg_startup_header *hdr = (struct pg_startup_header *)buf;
if (bpf_ntohl(hdr->version) != PG_STARTUP_VERSION) {
return false;
}
// Check if we can find the user param. Postgres uses C-style strings, so
// we also check for the terminating null byte.
return !bpf_memcmp(buf + sizeof(*hdr), PG_STARTUP_USER_PARAM, sizeof(PG_STARTUP_USER_PARAM));
}
// is_postgres_query checks if the buffer is a regular Postgres message.
static __always_inline bool is_postgres_query(const char *buf, __u32 buf_size) {
CHECK_PRELIMINARY_BUFFER_CONDITIONS(buf, buf_size, sizeof(struct pg_message_header));
struct pg_message_header *hdr = (struct pg_message_header *)buf;
// We only classify queries for now
if (hdr->message_tag != POSTGRES_QUERY_MAGIC_BYTE && hdr->message_tag != POSTGRES_COMMAND_COMPLETE_MAGIC_BYTE) {
return false;
}
__u32 message_len = bpf_ntohl(hdr->message_len);
if (message_len < POSTGRES_MIN_PAYLOAD_LEN || message_len > POSTGRES_MAX_PAYLOAD_LEN) {
return false;
}
return is_sql_command(buf + sizeof(*hdr), buf_size - sizeof(*hdr));
}
static __always_inline bool is_postgres(const char *buf, __u32 buf_size) {
return is_postgres_query(buf, buf_size) || is_postgres_connect(buf, buf_size);
}
#endif // __POSTGRES_HELPERS_H
|
ca75dd1978e5af2beb6e14954709be15d0113c7d
|
8838eb997879add5759b6dfb23f9a646464e53ca
|
/third-party/external_build/stage2/app2.c
|
1137f7c137cea121ec4dd9e8e1275f88be5b5253
|
[
"BSD-2-Clause"
] |
permissive
|
embox/embox
|
d6aacec876978522f01cdc4b8de37a668c6f4c80
|
98e3c06e33f3fdac10a29c069c20775568e0a6d1
|
refs/heads/master
| 2023-09-04T03:02:20.165042
| 2023-09-02T14:55:31
| 2023-09-02T14:55:31
| 33,078,138
| 1,087
| 325
|
BSD-2-Clause
| 2023-09-14T16:58:34
| 2015-03-29T15:27:48
|
C
|
UTF-8
|
C
| false
| false
| 188
|
c
|
app2.c
|
/**
* @file
* @brief
*
* @author Anton Kozlov
* @date 02.04.2014
*/
extern char external_build_lib_symbol;
static char *ptr __attribute__((used)) = &external_build_lib_symbol;
|
ec614dd4ebe94b1a948a8f59c0fcac3f155efba2
|
08d7a4631db5cde223283513f01f59121dab984f
|
/pluginsdk/include/teamspeak/public_errors_rare.h
|
8a5479260b64cfc3c9a61ebc2c9551b8d678a22b
|
[
"MIT"
] |
permissive
|
MGraefe/RP-Soundboard
|
982dc25ef18c226aa1f62838f314ce287cc3eecd
|
f597f1235365406fac46976421b00a8201cf4299
|
refs/heads/master
| 2023-08-01T03:48:09.963516
| 2023-07-19T15:22:19
| 2023-07-19T15:22:19
| 45,176,756
| 110
| 60
|
MIT
| 2023-07-18T20:16:38
| 2015-10-29T10:39:10
|
C++
|
UTF-8
|
C
| false
| false
| 4,113
|
h
|
public_errors_rare.h
|
#ifndef PUBLIC_ERRORS__RARE_H
#define PUBLIC_ERRORS__RARE_H
//The idea here is: the values are 2 bytes wide, the first byte identifies the group, the second the count within that group
enum Ts3RareErrorType {
//client
ERROR_client_invalid_password = 0x0208,
ERROR_client_too_many_clones_connected = 0x0209,
ERROR_client_is_online = 0x020b,
//channel
ERROR_channel_is_private_channel = 0x030e,
//note 0x030f is defined in public_errors;
//database
ERROR_database = 0x0500,
ERROR_database_empty_result = 0x0501,
ERROR_database_duplicate_entry = 0x0502,
ERROR_database_no_modifications = 0x0503,
ERROR_database_constraint = 0x0504,
ERROR_database_reinvoke = 0x0505,
//permissions
ERROR_permission_invalid_group_id = 0x0a00,
ERROR_permission_duplicate_entry = 0x0a01,
ERROR_permission_invalid_perm_id = 0x0a02,
ERROR_permission_empty_result = 0x0a03,
ERROR_permission_default_group_forbidden = 0x0a04,
ERROR_permission_invalid_size = 0x0a05,
ERROR_permission_invalid_value = 0x0a06,
ERROR_permissions_group_not_empty = 0x0a07,
ERROR_permissions_insufficient_group_power = 0x0a09,
ERROR_permissions_insufficient_permission_power = 0x0a0a,
ERROR_permission_template_group_is_used = 0x0a0b,
//0x0a0c is in public_errors.h
ERROR_permission_used_by_integration = 0x0a0d,
//server
ERROR_server_deployment_active = 0x0405,
ERROR_server_unable_to_stop_own_server = 0x0406,
ERROR_server_wrong_machineid = 0x0408,
ERROR_server_modal_quit = 0x040c,
ERROR_server_time_difference_too_large = 0x040f,
ERROR_server_blacklisted = 0x0410,
ERROR_server_shutdown = 0x0411,
//messages
ERROR_message_invalid_id = 0x0c00,
//ban
ERROR_ban_invalid_id = 0x0d00,
ERROR_connect_failed_banned = 0x0d01,
ERROR_rename_failed_banned = 0x0d02,
ERROR_ban_flooding = 0x0d03,
//tts
ERROR_tts_unable_to_initialize = 0x0e00,
//privilege key
ERROR_privilege_key_invalid = 0x0f00,
//voip
ERROR_voip_pjsua = 0x1000,
ERROR_voip_already_initialized = 0x1001,
ERROR_voip_too_many_accounts = 0x1002,
ERROR_voip_invalid_account = 0x1003,
ERROR_voip_internal_error = 0x1004,
ERROR_voip_invalid_connectionId = 0x1005,
ERROR_voip_cannot_answer_initiated_call = 0x1006,
ERROR_voip_not_initialized = 0x1007,
//ed25519
ERROR_ed25519_rng_fail = 0x1300,
ERROR_ed25519_signature_invalid = 0x1301,
ERROR_ed25519_invalid_key = 0x1302,
ERROR_ed25519_unable_to_create_valid_key = 0x1303,
ERROR_ed25519_out_of_memory = 0x1304,
ERROR_ed25519_exists = 0x1305,
ERROR_ed25519_read_beyond_eof = 0x1306,
ERROR_ed25519_write_beyond_eof = 0x1307,
ERROR_ed25519_version = 0x1308,
ERROR_ed25519_invalid = 0x1309,
ERROR_ed25519_invalid_date = 0x130A,
ERROR_ed25519_unauthorized = 0x130B,
ERROR_ed25519_invalid_type = 0x130C,
ERROR_ed25519_address_nomatch = 0x130D,
ERROR_ed25519_not_valid_yet = 0x130E,
ERROR_ed25519_expired = 0x130F,
ERROR_ed25519_index_out_of_range = 0x1310,
ERROR_ed25519_invalid_size = 0x1311,
//mytsid - client
ERROR_invalid_mytsid_data = 0x1200,
ERROR_invalid_integration = 0x1201,
};
#endif
|
299d759db90124bd2edfb95b39c1fc912c659f0c
|
e552c5408e825acc3a00ae8ab8e0697beddf7a0a
|
/projects/stm8l05x/STM8L15x-16x-05x-AL31-L_StdPeriph_Lib/Libraries/STM8L15x_StdPeriph_Driver/src/stm8l15x_beep.c
|
d4f700b205332d9af68a648907674b5c73dbcc15
|
[
"MIT",
"PostgreSQL",
"ISC",
"BSD-3-Clause",
"BSL-1.0",
"BSD-2-Clause"
] |
permissive
|
xhawk18/s_task
|
f81dda8252bbb0631b564eb8775c8008bc4f5583
|
d1e9a348a570433f0f5655f64c8dd3b94a6d1cbe
|
refs/heads/master
| 2023-08-13T08:11:27.712894
| 2023-04-11T12:29:43
| 2023-04-11T12:29:43
| 242,364,894
| 552
| 88
| null | null | null | null |
UTF-8
|
C
| false
| false
| 8,311
|
c
|
stm8l15x_beep.c
|
/**
******************************************************************************
* @file stm8l15x_beep.c
* @author MCD Application Team
* @version V1.6.1
* @date 30-September-2014
* @brief This file provides firmware functions to manage the following
* functionalities of the BEEPER (BEEP) peripheral:
* - Initialization and Configuration
* - Low Speed Internal Clock(LSI) Calibration
*
* @verbatim
* ===================================================================
* How to use this driver
* ===================================================================
* 1- Make sure that the LS RC clock calibration is performed by the following
* steps:
* - Connect internally the LS clock source to TIM2 channel 1 input
* capture for measurement using BEEP_LSClockToTIMConnectCmd() function
* - Update the BEEP_CSR register by the measured LSI frequency
* --> During this phase the BEEPER must be disabled to avoid
* unwanted interrupts
*
* 2- Configure the output beeper frequency using the BEEP_Init() function
*
* 3- Enable the beeper using the BEEP_Cmd() function
*
* @endverbatim
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x_beep.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @defgroup BEEP
* @brief BEEP driver modules
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup BEEP_Private_Functions
* @{
*/
/** @defgroup BEEP_Group1 Initialization and Configuration functions
* @brief Initialization and Configuration functions
*
@verbatim
===============================================================================
Initialization and Configuration functions
===============================================================================
This section provides functions allowing to:
- Initialize and configure the Beeper frequency
- Enable and Disable the Beeper output
@endverbatim
* @{
*/
/**
* @brief Deinitializes the BEEP peripheral registers to their default
* reset values.
* @param None
* @retval None
*/
void BEEP_DeInit(void)
{
BEEP->CSR1 = BEEP_CSR1_RESET_VALUE;
BEEP->CSR2 = BEEP_CSR2_RESET_VALUE;
}
/**
* @brief Initializes the BEEP function according to the specified parameters.
* @note The LS RC calibration must be performed before calling this function.
* @param BEEP_Frequency Frequency selection.
* This parameter can be one of the values of @ref BEEP_Frequency_TypeDef.
* @retval None
*/
void BEEP_Init(BEEP_Frequency_TypeDef BEEP_Frequency)
{
/* Check parameter */
assert_param(IS_BEEP_FREQUENCY(BEEP_Frequency));
/* Set a default calibration value if no calibration is done */
if ((BEEP->CSR2 & BEEP_CSR2_BEEPDIV) == BEEP_CSR2_BEEPDIV)
{
BEEP->CSR2 &= (uint8_t)(~BEEP_CSR2_BEEPDIV); /* Clear bits */
BEEP->CSR2 |= BEEP_CALIBRATION_DEFAULT;
}
/* Select the output frequency */
BEEP->CSR2 &= (uint8_t)(~BEEP_CSR2_BEEPSEL);
BEEP->CSR2 |= (uint8_t)(BEEP_Frequency);
}
/**
* @brief Enable or disable the BEEP function.
* @note Initialisation of BEEP and LS RC calibration must be done before.
* @param NewState Indicates the new state of the BEEP function.
* @retval None
*/
void BEEP_Cmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the BEEP peripheral */
BEEP->CSR2 |= BEEP_CSR2_BEEPEN;
}
else
{
/* Disable the BEEP peripheral */
BEEP->CSR2 &= (uint8_t)(~BEEP_CSR2_BEEPEN);
}
}
/**
* @}
*/
/** @defgroup BEEP_Group2 Low Speed Internal Clock(LSI) Calibration functions
* @brief Low Speed Internal Clock(LSI) Calibration functions
*
@verbatim
===============================================================================
Low Speed Internal Clock(LSI) Calibration functions
===============================================================================
This section provides functions allowing to measure and calibrate the internal
low speed clock source to ensure better BEEPER output frequency .
A typical configuration for LSI calibration is done following these steps :
1. Disable the Beeper to avoid any unwanted interrupt using BEEP_Cmd() function
2. Measure the LSI clock frequency by connecting it internally to TIM2 input capture
using BEEP_LSClockToTIMConnectCmd() function.
3. Calibrate the beeper frequency with the measured LSI clock frequency using
BEEP_LSICalibrationConfig() function.
@endverbatim
* @{
*/
/**
* @brief Enable or disable the LS clock source connection to TIM for measurement.
* @param NewState Indicates the new state of the LS clock to TIM connection
* @retval None
*/
void BEEP_LSClockToTIMConnectCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Connect LS clock to TIM for measurement */
BEEP->CSR1 |= BEEP_CSR1_MSR;
}
else
{
/* Disconnect LS clock to TIM */
BEEP->CSR1 &= (uint8_t)(~BEEP_CSR1_MSR);
}
}
/**
* @brief Update CSR register with the measured LSI frequency.
* @note BEEP must be disabled to avoid unwanted interrupts.
* @note Prescaler calculation:
* A is the integer part of LSIFreqkHz/4 and x the decimal part.
* x <= A/(1+2A) is equivalent to A >= x(1+2A)
* and also to 4A >= 4x(1+2A) [F1]
* but we know that A + x = LSIFreqkHz/4 ==> 4x = LSIFreqkHz-4A
* so [F1] can be written :
* 4A >= (LSIFreqkHz-4A)(1+2A)
* @param LSIFreqHz Low Speed RC frequency measured by timer (in Hz).
* @retval None
*/
void BEEP_LSICalibrationConfig(uint32_t LSIFreqHz)
{
uint16_t lsifreqkhz;
uint16_t A;
/* Check parameter */
assert_param(IS_LSI_FREQUENCY(LSIFreqHz));
lsifreqkhz = (uint16_t)(LSIFreqHz / 1000); /* Converts value in kHz */
/* Calculation of BEEPER calibration value */
BEEP->CSR2 &= (uint8_t)(~BEEP_CSR2_BEEPDIV); /* Clear bits */
A = (uint16_t)(lsifreqkhz >> 3U); /* Division by 8, keep integer part only */
if ((8U * A) >= ((lsifreqkhz - (8U * A)) * (1U + (2U * A))))
{
BEEP->CSR2 |= (uint8_t)(A - 2U);
}
else
{
BEEP->CSR2 |= (uint8_t)(A - 1U);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
9f674048460ea14ce35e83f7094034b1155ac56b
|
c8f7773f80acf75345af37c67f0d925cf0234118
|
/src/mac/mac_camera.h
|
80844d73d6bf94c736dad47eba2c6104ff7c3c56
|
[
"MIT"
] |
permissive
|
uglyDwarf/linuxtrack
|
14a8854b826d57fa28ca276ec6ba5c54a1ddaa31
|
fe9b98b51f6ee6521d38bd1f7edf84839227e588
|
refs/heads/master
| 2023-05-25T02:05:04.332165
| 2023-02-22T20:20:35
| 2023-02-22T20:20:35
| 39,029,490
| 156
| 35
|
MIT
| 2023-05-19T07:27:16
| 2015-07-13T18:21:31
|
C
|
UTF-8
|
C
| false
| false
| 93
|
h
|
mac_camera.h
|
#ifndef MAC_CAMERA__H
#define MAC_CAMERA__H
void enumerateCameras();
bool capture();
#endif
|
9f96925b72359e4f516413043ec8bf41ed4917a6
|
9bc18539a4cebb8f85d5e6399865849e00210a1c
|
/src/nginx_module/Configuration.h
|
774ae2067db57864672d2b0024f04e58089cd8f9
|
[
"MIT"
] |
permissive
|
phusion/passenger
|
6ada8099432e2ddee24385ecaac4a1a31b6f5944
|
b5b61d1a7096b07a976eb02ba9b063d21fe68e07
|
refs/heads/stable-6.0
| 2023-09-05T07:37:21.819164
| 2023-08-22T20:45:52
| 2023-08-22T21:02:09
| 5,625
| 2,903
| 364
|
MIT
| 2023-09-11T13:19:50
| 2008-03-27T23:40:48
|
C++
|
UTF-8
|
C
| false
| false
| 3,507
|
h
|
Configuration.h
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) 2007 Manlio Perillo (manlio.perillo@gmail.com)
* Copyright (c) 2010-2017 Phusion Holding B.V.
*
* 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 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 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.
*/
#ifndef _PASSENGER_NGINX_CONFIGURATION_H_
#define _PASSENGER_NGINX_CONFIGURATION_H_
#include <ngx_config.h>
#include <ngx_http.h>
#include "MainConfig/AutoGeneratedStruct.h"
#include "LocationConfig/AutoGeneratedStruct.h"
struct passenger_main_conf_s {
passenger_autogenerated_main_conf_t autogenerated;
ngx_str_t default_ruby;
PsgJsonValue *manifest;
};
struct passenger_loc_conf_s {
passenger_autogenerated_loc_conf_t autogenerated;
struct passenger_loc_conf_s *parent;
ngx_array_t children;
ngx_http_core_srv_conf_t *cscf;
ngx_http_core_loc_conf_t *clcf;
ngx_str_t context_source_file;
ngx_uint_t context_source_line;
ngx_http_upstream_conf_t upstream_config;
ngx_array_t *flushes;
ngx_array_t *headers_set_len;
ngx_array_t *headers_set;
ngx_hash_t headers_set_hash;
#if (NGX_HTTP_CACHE)
ngx_http_complex_value_t cache_key;
#endif
/** Raw HTTP header data for this location are cached here. */
ngx_str_t options_cache;
ngx_str_t env_vars_cache;
};
#ifndef _PASSENGER_NGINX_MODULE_CONF_STRUCT_TYPEDEFS_H_
#define _PASSENGER_NGINX_MODULE_CONF_STRUCT_TYPEDEFS_H_
struct passenger_main_conf_s;
struct passenger_loc_conf_s;
typedef struct passenger_main_conf_s passenger_main_conf_t;
typedef struct passenger_loc_conf_s passenger_loc_conf_t;
#endif /* _PASSENGER_NGINX_MODULE_CONF_STRUCT_TYPEDEFS_H_ */
extern const ngx_command_t passenger_commands[];
extern passenger_main_conf_t passenger_main_conf;
void *passenger_create_main_conf(ngx_conf_t *cf);
char *passenger_init_main_conf(ngx_conf_t *cf, void *conf_pointer);
void *passenger_create_loc_conf(ngx_conf_t *cf);
char *passenger_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
ngx_int_t passenger_postprocess_config(ngx_conf_t *cf);
PsgJsonValue *psg_json_value_set_str_array(PsgJsonValue *doc, const char *name, ngx_array_t *ary);
PsgJsonValue *psg_json_value_set_str_keyval(PsgJsonValue *doc, const char *name, ngx_array_t *ary);
#endif /* _PASSENGER_NGINX_CONFIGURATION_H_ */
|
bc310f080203c419e6896774564562154d4d9b75
|
3f017c2c3a55a2ac783045a23977765862ef4b20
|
/firmware/aica/codec/dac.h
|
ac05f18b03482d1b697196ea0c0d1cf08d221d31
|
[] |
no_license
|
DC-SWAT/DreamShell
|
8e4310087eb7f8e9bed285b8c66992e4df9c9143
|
f2551e18c06345fed0f5144245d6380203c20fa6
|
refs/heads/master
| 2023-07-09T16:50:05.291266
| 2023-06-23T05:32:37
| 2023-06-23T05:32:37
| 13,268,848
| 308
| 94
| null | 2023-06-23T05:04:53
| 2013-10-02T10:58:30
|
C
|
UTF-8
|
C
| false
| false
| 2,500
|
h
|
dac.h
|
/*
Copyright (C) 2006 Andreas Schwarz <andreas@andreas-s.net>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _DAC_H_
#define _DAC_H_
#define AIC_REG_LINVOL 0x00
#define AIC_REG_RINVOL 0x01
#define AIC_REG_LOUTVOL 0x02
#define AIC_REG_ROUTVOL 0x03
#define AIC_REG_AN_PATH 0x04
#define AIC_REG_DIG_PATH 0x05
#define AIC_REG_POWER 0x06
#define AIC_REG_DIG_FORMAT 0x07
#define AIC_REG_SRATE 0x08
#define AIC_REG_DIG_ACT 0x09
#define AIC_REG_RESET 0x0F
#define AIC_USB (1 << 0)
#define AIC_BOSR (1 << 1)
#define AIC_SR0 (1 << 2)
#define AIC_SR1 (1 << 3)
#define AIC_SR2 (1 << 4)
#define AIC_SR3 (1 << 5)
#define AIC_MICB (1 << 0)
#define AIC_MICM (1 << 1)
#define AIC_INSEL (1 << 2)
#define AIC_BYP (1 << 3)
#define AIC_DAC (1 << 4)
#define AIC_STE (1 << 5)
#define AIC_STA0 (1 << 6)
#define AIC_STA1 (1 << 7)
#define AIC_STA2 (1 << 8)
#define MAX_BUFFERS 3
#define DAC_BUFFER_MAX_SIZE 2400
extern short dac_buffer[MAX_BUFFERS][DAC_BUFFER_MAX_SIZE];
extern int dac_buffer_size[MAX_BUFFERS];
extern unsigned long current_srate;
extern unsigned int underruns;
void dac_reset();
int dac_get_writeable_buffer();
int dac_get_readable_buffer();
int dac_readable_buffers();
int dac_writeable_buffers();
int dac_busy_buffers();
int adc_busy_buffers();
int dac_fill_dma();
void dac_enable_dma();
void dac_disable_dma();
int dac_next_dma_empty();
int dac_first_dma_empty();
int adc_next_dma_empty();
int adc_first_dma_empty();
void dac_set_first_dma(short *buffer, int n);
void dac_set_next_dma(short *buffer, int n);
int dma_endtx(void);
void dac_write_reg(unsigned char reg, unsigned short value);
int dac_set_srate(unsigned long srate);
void dac_init(void);
#endif /* _DAC_H_ */
|
bcc28c080350e8065d252d614c2171fcee423b9d
|
d29d566560adedc004c8cf7d40e9695ccf830141
|
/kernel/boot/stage2.c
|
21dd63ffae7da0ef04759e6da392ab50d29696ef
|
[
"WTFPL",
"GPL-2.0-only",
"LGPL-2.1-only",
"ISC"
] |
permissive
|
cacalabs/libcaca
|
c6094af728e17721add9159b7ab779f1db1147d2
|
f42aa68fc798db63b7b2a789ae8cf5b90b57b752
|
refs/heads/main
| 2023-06-22T02:53:00.184744
| 2021-12-07T09:03:49
| 2021-12-07T09:03:53
| 29,090,568
| 512
| 86
|
WTFPL
| 2023-06-08T07:24:44
| 2015-01-11T12:13:56
|
C
|
UTF-8
|
C
| false
| false
| 1,092
|
c
|
stage2.c
|
/*
* libcaca Colour ASCII-Art library
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
* 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What the Fuck You Want
* to Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
#include "kernel.h"
#include "klibc.h"
extern int kmain(void);
/* Entry point bootsect.asm loaded this file at 0x0100:0x0, which is mapped
at 0x8:0x1000 (selector+8bytes, offset 1000 (0x100 + 0x0) */
/* 0x1000 */
void _start(void)
{
clearscreen();
init_gdt();
print("Loading IDT\n");
init_idt();
print("Loading PIC\n");
init_pic();
print("Running kmain()\n");
sti;
kmain(); /* Call kernel's kmain() */
while (1)
{ /* Never return */
print("hlt;\n");
}
}
|
f1856e44585fa1c5c45c6e017b50143e21b2978f
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/fs/nfsd/nfs2acl.c
|
95d76dc6c5da5bf313c4778eaa8220eb91ac1665
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 9,143
|
c
|
nfs2acl.c
|
/*
* Process version 2 NFSACL requests.
*
* Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
*/
#include "nfsd.h"
/* FIXME: nfsacl.h is a broken header */
#include <linux/nfsacl.h>
#include <linux/gfp.h>
#include "cache.h"
#include "xdr3.h"
#include "vfs.h"
#define NFSDDBG_FACILITY NFSDDBG_PROC
#define RETURN_STATUS(st) { resp->status = (st); return (st); }
/*
* NULL call.
*/
static __be32
nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
{
return nfs_ok;
}
/*
* Get the Access and/or Default ACL of a file.
*/
static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
{
svc_fh *fh;
struct posix_acl *acl;
__be32 nfserr = 0;
dprintk("nfsd: GETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
fh = fh_copy(&resp->fh, &argp->fh);
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
if (nfserr)
RETURN_STATUS(nfserr);
if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
RETURN_STATUS(nfserr_inval);
resp->mask = argp->mask;
nfserr = fh_getattr(fh, &resp->stat);
if (nfserr)
goto fail;
if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
if (IS_ERR(acl)) {
int err = PTR_ERR(acl);
if (err == -ENODATA || err == -EOPNOTSUPP)
acl = NULL;
else {
nfserr = nfserrno(err);
goto fail;
}
}
if (acl == NULL) {
/* Solaris returns the inode's minimum ACL. */
struct inode *inode = fh->fh_dentry->d_inode;
acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
}
resp->acl_access = acl;
}
if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
/* Check how Solaris handles requests for the Default ACL
of a non-directory! */
acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
if (IS_ERR(acl)) {
int err = PTR_ERR(acl);
if (err == -ENODATA || err == -EOPNOTSUPP)
acl = NULL;
else {
nfserr = nfserrno(err);
goto fail;
}
}
resp->acl_default = acl;
}
/* resp->acl_{access,default} are released in nfssvc_release_getacl. */
RETURN_STATUS(0);
fail:
posix_acl_release(resp->acl_access);
posix_acl_release(resp->acl_default);
RETURN_STATUS(nfserr);
}
/*
* Set the Access and/or Default ACL of a file.
*/
static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
struct nfsd3_setaclargs *argp,
struct nfsd_attrstat *resp)
{
svc_fh *fh;
__be32 nfserr = 0;
dprintk("nfsd: SETACL(2acl) %s\n", SVCFH_fmt(&argp->fh));
fh = fh_copy(&resp->fh, &argp->fh);
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
if (!nfserr) {
nfserr = nfserrno( nfsd_set_posix_acl(
fh, ACL_TYPE_ACCESS, argp->acl_access) );
}
if (!nfserr) {
nfserr = nfserrno( nfsd_set_posix_acl(
fh, ACL_TYPE_DEFAULT, argp->acl_default) );
}
if (!nfserr) {
nfserr = fh_getattr(fh, &resp->stat);
}
/* argp->acl_{access,default} may have been allocated in
nfssvc_decode_setaclargs. */
posix_acl_release(argp->acl_access);
posix_acl_release(argp->acl_default);
return nfserr;
}
/*
* Check file attributes
*/
static __be32 nfsacld_proc_getattr(struct svc_rqst * rqstp,
struct nfsd_fhandle *argp, struct nfsd_attrstat *resp)
{
__be32 nfserr;
dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
fh_copy(&resp->fh, &argp->fh);
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
if (nfserr)
return nfserr;
nfserr = fh_getattr(&resp->fh, &resp->stat);
return nfserr;
}
/*
* Check file access
*/
static __be32 nfsacld_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
struct nfsd3_accessres *resp)
{
__be32 nfserr;
dprintk("nfsd: ACCESS(2acl) %s 0x%x\n",
SVCFH_fmt(&argp->fh),
argp->access);
fh_copy(&resp->fh, &argp->fh);
resp->access = argp->access;
nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
if (nfserr)
return nfserr;
nfserr = fh_getattr(&resp->fh, &resp->stat);
return nfserr;
}
/*
* XDR decode functions
*/
static int nfsaclsvc_decode_getaclargs(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_getaclargs *argp)
{
if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
return 0;
argp->mask = ntohl(*p); p++;
return xdr_argsize_check(rqstp, p);
}
static int nfsaclsvc_decode_setaclargs(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_setaclargs *argp)
{
struct kvec *head = rqstp->rq_arg.head;
unsigned int base;
int n;
if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
return 0;
argp->mask = ntohl(*p++);
if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT) ||
!xdr_argsize_check(rqstp, p))
return 0;
base = (char *)p - (char *)head->iov_base;
n = nfsacl_decode(&rqstp->rq_arg, base, NULL,
(argp->mask & NFS_ACL) ?
&argp->acl_access : NULL);
if (n > 0)
n = nfsacl_decode(&rqstp->rq_arg, base + n, NULL,
(argp->mask & NFS_DFACL) ?
&argp->acl_default : NULL);
return (n > 0);
}
static int nfsaclsvc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p,
struct nfsd_fhandle *argp)
{
if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
return 0;
return xdr_argsize_check(rqstp, p);
}
static int nfsaclsvc_decode_accessargs(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_accessargs *argp)
{
if (!(p = nfs2svc_decode_fh(p, &argp->fh)))
return 0;
argp->access = ntohl(*p++);
return xdr_argsize_check(rqstp, p);
}
/*
* XDR encode functions
*/
/*
* There must be an encoding function for void results so svc_process
* will work properly.
*/
static int nfsaclsvc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
{
return xdr_ressize_check(rqstp, p);
}
/* GETACL */
static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_getaclres *resp)
{
struct dentry *dentry = resp->fh.fh_dentry;
struct inode *inode;
struct kvec *head = rqstp->rq_res.head;
unsigned int base;
int n;
int w;
/*
* Since this is version 2, the check for nfserr in
* nfsd_dispatch actually ensures the following cannot happen.
* However, it seems fragile to depend on that.
*/
if (dentry == NULL || dentry->d_inode == NULL)
return 0;
inode = dentry->d_inode;
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
*p++ = htonl(resp->mask);
if (!xdr_ressize_check(rqstp, p))
return 0;
base = (char *)p - (char *)head->iov_base;
rqstp->rq_res.page_len = w = nfsacl_size(
(resp->mask & NFS_ACL) ? resp->acl_access : NULL,
(resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
while (w > 0) {
if (!*(rqstp->rq_next_page++))
return 0;
w -= PAGE_SIZE;
}
n = nfsacl_encode(&rqstp->rq_res, base, inode,
resp->acl_access,
resp->mask & NFS_ACL, 0);
if (n > 0)
n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
resp->acl_default,
resp->mask & NFS_DFACL,
NFS_ACL_DEFAULT);
if (n <= 0)
return 0;
return 1;
}
static int nfsaclsvc_encode_attrstatres(struct svc_rqst *rqstp, __be32 *p,
struct nfsd_attrstat *resp)
{
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
return xdr_ressize_check(rqstp, p);
}
/* ACCESS */
static int nfsaclsvc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_accessres *resp)
{
p = nfs2svc_encode_fattr(rqstp, p, &resp->fh, &resp->stat);
*p++ = htonl(resp->access);
return xdr_ressize_check(rqstp, p);
}
/*
* XDR release functions
*/
static int nfsaclsvc_release_getacl(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_getaclres *resp)
{
fh_put(&resp->fh);
posix_acl_release(resp->acl_access);
posix_acl_release(resp->acl_default);
return 1;
}
static int nfsaclsvc_release_attrstat(struct svc_rqst *rqstp, __be32 *p,
struct nfsd_attrstat *resp)
{
fh_put(&resp->fh);
return 1;
}
static int nfsaclsvc_release_access(struct svc_rqst *rqstp, __be32 *p,
struct nfsd3_accessres *resp)
{
fh_put(&resp->fh);
return 1;
}
#define nfsaclsvc_decode_voidargs NULL
#define nfsaclsvc_release_void NULL
#define nfsd3_fhandleargs nfsd_fhandle
#define nfsd3_attrstatres nfsd_attrstat
#define nfsd3_voidres nfsd3_voidargs
struct nfsd3_voidargs { int dummy; };
#define PROC(name, argt, rest, relt, cache, respsize) \
{ (svc_procfunc) nfsacld_proc_##name, \
(kxdrproc_t) nfsaclsvc_decode_##argt##args, \
(kxdrproc_t) nfsaclsvc_encode_##rest##res, \
(kxdrproc_t) nfsaclsvc_release_##relt, \
sizeof(struct nfsd3_##argt##args), \
sizeof(struct nfsd3_##rest##res), \
0, \
cache, \
respsize, \
}
#define ST 1 /* status*/
#define AT 21 /* attributes */
#define pAT (1+AT) /* post attributes - conditional */
#define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
static struct svc_procedure nfsd_acl_procedures2[] = {
PROC(null, void, void, void, RC_NOCACHE, ST),
PROC(getacl, getacl, getacl, getacl, RC_NOCACHE, ST+1+2*(1+ACL)),
PROC(setacl, setacl, attrstat, attrstat, RC_NOCACHE, ST+AT),
PROC(getattr, fhandle, attrstat, attrstat, RC_NOCACHE, ST+AT),
PROC(access, access, access, access, RC_NOCACHE, ST+AT+1),
};
struct svc_version nfsd_acl_version2 = {
.vs_vers = 2,
.vs_nproc = 5,
.vs_proc = nfsd_acl_procedures2,
.vs_dispatch = nfsd_dispatch,
.vs_xdrsize = NFS3_SVC_XDRSIZE,
.vs_hidden = 0,
};
|
82c04e5f4be60843acf3035eee92ac858bff37a1
|
ffdc77394c5b5532b243cf3c33bd584cbdc65cb7
|
/mindspore/ccsrc/c_api/include/tensor.h
|
ad21bc12c3ce52bf56643333f89e8f1bc3fe96eb
|
[
"Apache-2.0",
"LicenseRef-scancode-proprietary-license",
"MPL-1.0",
"OpenSSL",
"LGPL-3.0-only",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause-Open-MPI",
"MIT",
"MPL-2.0-no-copyleft-exception",
"NTP",
"BSD-3-Clause",
"GPL-1.0-or-later",
"0BSD",
"MPL-2.0",
"LicenseRef-scancode-free-unknown",
"AGPL-3.0-only",
"Libpng",
"MPL-1.1",
"IJG",
"GPL-2.0-only",
"BSL-1.0",
"Zlib",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-python-cwi",
"BSD-2-Clause",
"LicenseRef-scancode-gary-s-brown",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"Python-2.0",
"LicenseRef-scancode-mit-nagy",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference",
"Unlicense"
] |
permissive
|
mindspore-ai/mindspore
|
ca7d5bb51a3451c2705ff2e583a740589d80393b
|
54acb15d435533c815ee1bd9f6dc0b56b4d4cf83
|
refs/heads/master
| 2023-07-29T09:17:11.051569
| 2023-07-17T13:14:15
| 2023-07-17T13:14:15
| 239,714,835
| 4,178
| 768
|
Apache-2.0
| 2023-07-26T22:31:11
| 2020-02-11T08:43:48
|
C++
|
UTF-8
|
C
| false
| false
| 7,103
|
h
|
tensor.h
|
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_C_API_INCLUDE_FUNC_TENSOR_H_
#define MINDSPORE_CCSRC_C_API_INCLUDE_FUNC_TENSOR_H_
#include <stdbool.h>
#include <stdlib.h>
#include "c_api/base/macros.h"
#include "c_api/base/status.h"
#include "c_api/base/types.h"
#include "c_api/base/handle_types.h"
#include "c_api/include/context.h"
#ifdef __cplusplus
extern "C" {
#endif
/// \brief Create a tensor with input data buffer.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] data The input data to be copied into tensor.
/// \param[in] type [TypeId] Data type of the tensor.
/// \param[in] shape The shape arary of the tensor.
/// \param[in] shape_size The size of shape array, i.e., the rank of the tensor.
/// \param[in] data_len The length of data in bytes.
///
/// \return The pointer of the created tensor instance.
MIND_C_API TensorHandle MSNewTensor(ResMgrHandle res_mgr, void *data, DataTypeC type, const int64_t shape[],
size_t shape_size, size_t data_len);
/// \brief Create a tensor with path to a space-sperated txt file.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] type [TypeId] Data type of the tensor.
/// \param[in] shape The shape arary of the tensor.
/// \param[in] shape_size The size of shape array, i.e., the rank of the tensor.
/// \param[in] path path to the file.
///
/// \return The pointer of the created tensor instance.
MIND_C_API TensorHandle MSNewTensorFromFile(ResMgrHandle res_mgr, DataTypeC type, const int64_t shape[],
size_t shape_size, const char *path);
/// \brief Create a tensor with input data buffer and given source data type.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] shape The shape arary of the tensor.
/// \param[in] shape_size The size of shape array, i.e., the rank of the tensor.
/// \param[in] data The input data to be copied into tensor.
/// \param[in] tensor_type [TypeId] Data type of the tensor.
/// \param[in] src_type [TypeId] The source data type.
///
/// \return The pointer of the created tensor instance.
MIND_C_API TensorHandle MSNewTensorWithSrcType(ResMgrHandle res_mgr, void *data, const int64_t shape[],
size_t shape_size, DataTypeC tensor_type, DataTypeC src_type);
/// \brief Create a tensor with float32 scalar value.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] value The input scalar value.
///
/// \return The pointer of the created tensor instance.
MIND_C_API TensorHandle MSNewScalarTensorFloat32(ResMgrHandle res_mgr, float value);
/// \brief Create a tensor with int32 scalar value.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] value The input scalar value.
///
/// \return The pointer of the created tensor instance.
MIND_C_API TensorHandle MSNewScalarTensorInt32(ResMgrHandle res_mgr, int value);
/// \brief Get the raw pointer of tensor data.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
///
/// \return The pointer to the tensor data
MIND_C_API void *MSTensorGetData(ResMgrHandle res_mgr, ConstTensorHandle tensor);
/// \brief Set tensor data type.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] type The data type to be set.
///
/// \return Error code that indicate whether the functions executed successfully.
MIND_C_API STATUS MSTensorSetDataType(ResMgrHandle res_mgr, TensorHandle tensor, DataTypeC type);
/// \brief Get tensor data type.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
///
/// \return The data type of tensor.
MIND_C_API DataTypeC MSTensorGetDataType(ResMgrHandle res_mgr, ConstTensorHandle tensor, STATUS *error);
/// \brief Get the byte size of tensor data.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] error Records error code that indicate whether the functions executed successfully.
///
/// \return The byte size of tensor data.
MIND_C_API size_t MSTensorGetDataSize(ResMgrHandle res_mgr, ConstTensorHandle tensor, STATUS *error);
/// \brief Get the element number of tensor array.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] error Records error code that indicate whether the functions executed successfully.
///
/// \return The element number of tensor array.
MIND_C_API size_t MSTensorGetElementNum(ResMgrHandle res_mgr, ConstTensorHandle tensor, STATUS *error);
/// \brief Get the dimension of tensor.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] error Records error code that indicate whether the functions executed successfully.
///
/// \return The dimension of tensor.
MIND_C_API size_t MSTensorGetDimension(ResMgrHandle res_mgr, ConstTensorHandle tensor, STATUS *error);
/// \brief Set the shape of tensor array.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] shape The shape array.
/// \param[in] dim The the dimension of tensor, i.e., size of shape array.
///
/// \return Error code indicates whether the function executed successfully.
MIND_C_API STATUS MSTensorSetShape(ResMgrHandle res_mgr, TensorHandle tensor, const int64_t shape[], size_t dim);
/// \brief Get the shape of tensor array.
///
/// \param[in] res_mgr Resource manager that saves allocated instance resources.
/// \param[in] tensor The pointer of the tensor instance.
/// \param[in] shape The shape array.
/// \param[in] dim The the dimension of tensor, i.e., size of shape array.
///
/// \return Error code indicates whether the function executed successfully.
MIND_C_API STATUS MSTensorGetShape(ResMgrHandle res_mgr, ConstTensorHandle tensor, int64_t shape[], size_t dim);
#ifdef __cplusplus
}
#endif
#endif // MINDSPORE_CCSRC_C_API_INCLUDE_FUNC_TENSOR_H_
|
78963e52027d290f1c994bed8d4e1baaef6f6189
|
76f9898ff7a555f4a729d725056a317af818375d
|
/assets/objects/object_hintnuts/object_hintnuts.c
|
d1d9133a1851fe0f2b26899093d22edeb7efd49a
|
[] |
no_license
|
z64proto/sw97
|
0b65837ab2f2a4073faca5670761d7fe0e74d29d
|
f571505ade2cefd4a5b5d19da06d33e7c6b02c60
|
refs/heads/master
| 2023-08-01T02:47:42.895871
| 2022-05-15T20:29:08
| 2022-05-15T20:29:08
| 430,216,978
| 208
| 29
| null | 2021-11-22T12:23:50
| 2021-11-20T21:52:59
|
C
|
UTF-8
|
C
| false
| false
| 48,039
|
c
|
object_hintnuts.c
|
#include "ultra64.h"
#include "z64.h"
#include "macros.h"
#include "object_hintnuts.h"
static s16 sHintNutsSpitAnimFrameData[150];
static JointIndex sHintNutsSpitAnimJointIndices[10];
static Vtx sHintNutsSkelVtx_000180[16];
static Vtx sHintNutsSkelVtx_000280[6];
static Vtx sHintNutsSkelVtx_0002E0[6];
static Vtx sHintNutsSkelVtx_000340[10];
static Vtx sHintNutsSkelVtx_0003E0[5];
static Vtx sHintNutsSkelVtx_000430[5];
static Vtx sHintNutsSkelVtx_000480[7];
static Vtx sHintNutsSkelVtx_0004F0[7];
static Vtx sHintNutsSkelVtx_000560[5];
static Vtx sHintNutsSkelVtx_0005B0[68];
static Vtx sHintNutsSkelVtx_0009F0[20];
static Vtx object_hintnutsVtx_0012C0[3];
static Vtx object_hintnutsVtx_001380[9];
static Vtx object_hintnutsVtx_001410[13];
static void* sHintNutsSkelLimbs[9];
static s16 sHintNutsBurrowAnimFrameData[96];
static JointIndex sHintNutsBurrowAnimJointIndices[10];
static s16 sHintNutsUnburrowAnimFrameData[212];
static JointIndex sHintNutsUnburrowAnimJointIndices[10];
static s16 sHintNutsLookAroundAnimFrameData[188];
static JointIndex sHintNutsLookAroundAnimJointIndices[10];
static s16 sHintNutsFreezeAnimFrameData[104];
static JointIndex sHintNutsFreezeAnimJointIndices[10];
static s16 sHintNutsUpAnimFrameData[194];
static JointIndex sHintNutsUpAnimJointIndices[10];
static s16 sHintNutsTalkAnimFrameData[340];
static JointIndex sHintNutsTalkAnimJointIndices[10];
static s16 sHintNutsStandAnimFrameData[80];
static JointIndex sHintNutsStandAnimJointIndices[10];
static s16 sHintNutsRunAnimFrameData[174];
static JointIndex sHintNutsRunAnimJointIndices[10];
static s16 sHintNutsSpitAnimFrameData[150] = {
0x0000, 0x02BC, 0x4000, 0x8000, 0xC000, 0x0000, 0xFFE4, 0xFFA1, 0xFF50, 0xFF0A, 0xFEE9, 0xFF06, 0x009F, 0x0222,
0x0221, 0x01F8, 0x01B2, 0x015A, 0x00FA, 0x009D, 0x004D, 0x0015, 0x0000, 0x0000, 0x01D4, 0x0644, 0x0BBF, 0x10B3,
0x138E, 0x12BE, 0xFC56, 0xE6AA, 0xE62F, 0xE7CC, 0xEAF6, 0xEF20, 0xF3C0, 0xF84C, 0xFC37, 0xFEF6, 0x0000, 0x0000,
0x024C, 0x07E4, 0x0ED1, 0x151F, 0x18D9, 0x180A, 0xFCB8, 0xE22B, 0xE177, 0xE34A, 0xE6FD, 0xEBE9, 0xF167, 0xF6CF,
0xFB7B, 0xFEC3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFB2, 0x0000, 0x03AB, 0xFC00,
0xFD8D, 0x0000, 0x005E, 0x0069, 0x0046, 0x0017, 0x0000, 0x0000, 0x003C, 0x00D1, 0x0194, 0x0256, 0x02EB, 0x0327,
0x0235, 0x0000, 0xFBE9, 0xF914, 0xF976, 0xFA73, 0xFBCD, 0xFD47, 0xFEA1, 0xFF9E, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xFF18, 0xFE30, 0x0000, 0x0BE7, 0x145F, 0x04BF, 0xF4D3, 0xF4A9, 0xF8B7, 0xFD9E, 0x0000,
0x0000, 0x0000, 0x0164, 0x0491, 0x0806, 0x0A43, 0x09C7, 0x03DF, 0xF9CB, 0xEFFF, 0xEAED, 0xECF7, 0xF359, 0xFAC9,
0x0000, 0x0157, 0x00AB, 0x0000, 0x0000, 0x5FC8, 0x5DC0, 0x5884, 0x515B, 0x498D, 0x4264, 0x3D26, 0x3DE7, 0x40F5,
0x40D9, 0x3FF8, 0x3FC2, 0x41A7, 0x46FA, 0x4EB9, 0x56D2, 0x5D32, 0x5FC8, 0x0000,
};
static JointIndex sHintNutsSpitAnimJointIndices[10] = {
{ 0x0000, 0x0001, 0x0005 },
{ 0x0002, 0x0017, 0x0002 },
{ 0x0000, 0x0000, 0x0029 },
{ 0x003B, 0x0000, 0x004D },
{ 0x005F, 0x0000, 0x0071 },
{ 0x0000, 0x0000, 0x0083 },
{ 0x0002, 0x0000, 0x0003 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0002, 0x0003, 0x0000 },
{ 0x0003, 0x0003, 0x0004 },
};
AnimationHeader gHintNutsSpitAnim = { { 18 }, sHintNutsSpitAnimFrameData, sHintNutsSpitAnimJointIndices, 5 };
static u8 unaccounted_000178[8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static Vtx sHintNutsSkelVtx_000180[16] = {
VTX(438, 555, -1041, 103, 166, 217, 44, 152, 255),
VTX(-389, 0, 0, 363, 691, 137, 2, 0, 255),
VTX(322, 1364, 0, 363, 231, 223, 115, 0, 255),
VTX(438, 555, 1041, 624, 145, 215, 45, 103, 255),
VTX(1669, -744, 0, 496, -707, 85, 172, 255, 255),
VTX(342, -825, -820, 608, 212, 217, 171, 181, 255),
VTX(1296, 0, -1068, 343, -428, 53, 237, 151, 255),
VTX(1309, 0, 1103, 342, -437, 53, 237, 106, 255),
VTX(342, -825, 820, 608, 212, 216, 171, 74, 255),
VTX(1669, 727, 564, 142, -667, 63, 75, 68, 255),
VTX(1669, 727, 564, 506, -648, 63, 75, 68, 255),
VTX(1669, 727, -564, 223, -636, 63, 74, 186, 255),
VTX(438, 555, -1041, 269, 183, 217, 44, 152, 255),
VTX(438, 555, 1041, 269, 183, 215, 45, 103, 255),
VTX(-389, 0, 0, 460, 742, 137, 2, 0, 255),
VTX(1669, 727, -564, 142, -667, 63, 74, 186, 255),
};
static Vtx sHintNutsSkelVtx_000280[6] = {
VTX(1286, 702, 702, 30, -136, 255, 255, 255, 255),
VTX(506, 1302, 188, 339, 203, 255, 255, 255, 255),
VTX(506, 522, 1194, -83, 309, 255, 255, 255, 255),
VTX(506, 522, -1194, -83, 309, 255, 255, 255, 255),
VTX(506, 1302, -188, 339, 203, 255, 255, 255, 255),
VTX(1286, 702, -702, 30, -136, 255, 255, 255, 255),
};
static Vtx sHintNutsSkelVtx_0002E0[6] = {
VTX(-627, 0, 0, 224, 219, 136, 0, 0, 255),
VTX(63, 0, -780, -65, 437, 244, 0, 137, 255),
VTX(63, -780, 0, 237, 437, 244, 137, 0, 255),
VTX(63, 780, 0, 237, 437, 244, 119, 0, 255),
VTX(993, 0, 0, 249, 655, 120, 0, 0, 255),
VTX(63, 0, 780, 538, 437, 244, 0, 119, 255),
};
static Vtx sHintNutsSkelVtx_000340[10] = {
VTX(-138, 334, -301, 289, 257, 214, 82, 180, 255),
VTX(-138, 334, 301, 289, 257, 208, 64, 89, 255),
VTX(852, 393, 300, -15, 280, 71, 89, 36, 255),
VTX(852, -191, -523, -18, 87, 88, 239, 177, 255),
VTX(-18, -328, -301, 248, 38, 209, 172, 185, 255),
VTX(852, -191, 523, -18, 87, 68, 236, 96, 255),
VTX(-18, -328, 301, 248, 38, 209, 172, 71, 255),
VTX(852, -542, 0, -20, -29, 32, 141, 0, 255),
VTX(-552, 3, 0, 414, 145, 137, 242, 0, 255),
VTX(852, 393, -300, -15, 280, 58, 86, 197, 255),
};
static Vtx sHintNutsSkelVtx_0003E0[5] = {
VTX(852, -191, -523, 1, 84, 88, 239, 177, 255),
VTX(852, 393, -300, 59, 255, 58, 86, 197, 255),
VTX(852, 393, 300, 204, 253, 71, 89, 36, 255),
VTX(852, -191, 523, 253, 80, 68, 236, 96, 255),
VTX(852, -542, 0, 124, -22, 32, 141, 0, 255),
};
static Vtx sHintNutsSkelVtx_000430[5] = {
VTX(912, 243, 227, 445, 236, 37, 55, 100, 255),
VTX(1212, 3, 0, 319, 152, 119, 2, 0, 255),
VTX(912, 243, -227, 445, 236, 37, 55, 156, 255),
VTX(-168, 3, 0, 343, 487, 145, 44, 0, 255),
VTX(912, -267, 0, 189, 235, 35, 142, 0, 255),
};
static Vtx sHintNutsSkelVtx_000480[7] = {
VTX(753, -252, -462, 696, 34, 11, 208, 147, 255),
VTX(1263, -252, 0, 953, 39, 117, 231, 0, 255),
VTX(753, -252, 462, 696, 34, 11, 208, 109, 255),
VTX(-87, -252, -270, 274, 26, 170, 198, 197, 255),
VTX(-87, -252, 270, 274, 26, 170, 198, 59, 255),
VTX(-27, 153, -15, 311, 153, 185, 96, 255, 255),
VTX(843, 468, 0, 756, 300, 51, 108, 0, 255),
};
static Vtx sHintNutsSkelVtx_0004F0[7] = {
VTX(753, -252, -462, 696, 34, 11, 208, 147, 255),
VTX(1263, -252, 0, 953, 39, 117, 231, 0, 255),
VTX(753, -252, 462, 696, 34, 11, 208, 109, 255),
VTX(-87, -252, 270, 274, 26, 170, 198, 59, 255),
VTX(-87, -252, -270, 274, 26, 170, 198, 197, 255),
VTX(843, 468, 0, 756, 300, 51, 108, 0, 255),
VTX(-27, 153, 15, 311, 153, 185, 96, 1, 255),
};
static Vtx sHintNutsSkelVtx_000560[5] = {
VTX(912, 243, 227, 445, 236, 37, 55, 100, 255),
VTX(1212, 3, 0, 319, 152, 119, 2, 0, 255),
VTX(912, 243, -227, 445, 236, 37, 55, 156, 255),
VTX(-168, 3, 0, 343, 487, 145, 44, 0, 255),
VTX(912, -267, 0, 189, 235, 35, 142, 0, 255),
};
static Vtx sHintNutsSkelVtx_0005B0[68] = {
VTX(0, 104, -1042, 199, -1024, 97, 248, 187, 255),
VTX(144, 907, 0, 470, -1122, 106, 56, 0, 255),
VTX(437, -222, 0, 465, -1323, 118, 236, 0, 255),
VTX(-2232, -2933, 0, 2069, 954, 63, 155, 0, 255),
VTX(-1167, -1126, -1354, 190, 285, 59, 187, 179, 255),
VTX(-249, -1191, 0, 575, -514, 91, 178, 0, 255),
VTX(-2285, -1061, -1803, -195, 1083, 31, 183, 167, 255),
VTX(0, 104, -1042, 1705, 11, 97, 248, 187, 255),
VTX(-1558, 211, -2432, 2276, 1024, 67, 232, 160, 255),
VTX(-893, 1809, -887, 386, 1024, 87, 67, 209, 255),
VTX(144, 907, 0, 1024, 138, 106, 56, 0, 255),
VTX(-893, 1809, -887, 362, 1062, 87, 67, 209, 255),
VTX(-893, 1809, 886, 1686, 1062, 87, 67, 47, 255),
VTX(0, 104, 1042, 1677, -132, 97, 248, 69, 255),
VTX(-893, 1809, 886, 450, 1067, 87, 67, 47, 255),
VTX(-1558, 211, 2431, 2339, 1067, 67, 232, 96, 255),
VTX(-1167, -1126, 1354, 190, 285, 59, 187, 77, 255),
VTX(-2285, -1061, 1802, -195, 1083, 32, 183, 89, 255),
VTX(144, 907, 0, 399, -120, 106, 56, 0, 255),
VTX(144, 907, 0, 432, -7, 106, 56, 0, 255),
VTX(-1308, 1497, -289, 164, 1024, 52, 106, 238, 255),
VTX(-71, 946, 0, 488, -10, 62, 102, 0, 255),
VTX(-568, 1027, -508, 12, 478, 61, 93, 211, 255),
VTX(-311, 439, -1104, -140, -69, 67, 253, 157, 255),
VTX(-1308, 1497, 288, 812, 1024, 51, 106, 18, 255),
VTX(-568, 1027, 509, 964, 478, 61, 93, 45, 255),
VTX(-311, 439, 1107, 1116, -69, 67, 253, 99, 255),
VTX(-2469, 187, 1743, 74, 996, 21, 208, 107, 255),
VTX(-1447, -614, 1185, 982, -74, 37, 195, 96, 255),
VTX(-311, 439, 1107, -310, -1008, 67, 253, 99, 255),
VTX(-425, -1215, 0, 1890, -1145, 68, 158, 0, 255),
VTX(-2469, 187, -1744, 74, 996, 21, 208, 149, 255),
VTX(-311, 439, -1104, -310, -1008, 67, 253, 157, 255),
VTX(-1447, -614, -1185, 982, -74, 37, 195, 160, 255),
VTX(-425, -1215, 0, 1890, -1145, 68, 158, 0, 255),
VTX(-3753, -2731, 0, 3205, 1032, 34, 142, 0, 255),
VTX(-1447, -614, 1185, 982, -74, 37, 195, 96, 255),
VTX(-2469, 187, 1743, 74, 996, 21, 208, 107, 255),
VTX(-71, 946, 0, 488, -10, 62, 102, 0, 255),
VTX(-1308, 1497, -289, 164, 1024, 52, 106, 238, 255),
VTX(-1308, 1497, 288, 812, 1024, 51, 106, 18, 255),
VTX(0, 104, -1042, 970, 1, 97, 248, 187, 255),
VTX(-249, -1191, 0, -148, -416, 91, 178, 0, 255),
VTX(-1167, -1126, -1354, 92, 521, 59, 187, 179, 255),
VTX(437, -222, 0, 465, -1323, 118, 236, 0, 255),
VTX(144, 907, 0, 470, -1122, 106, 56, 0, 255),
VTX(0, 104, 1042, 746, -1024, 97, 248, 69, 255),
VTX(-249, -1191, 0, 477, -854, 91, 178, 0, 255),
VTX(0, 104, -1042, 199, -1024, 97, 248, 187, 255),
VTX(200, 847, -175, 1100, 73, 111, 44, 8, 255),
VTX(100, -285, 39, 481, -486, 114, 221, 11, 255),
VTX(400, 449, -714, 490, -17, 116, 10, 228, 255),
VTX(50, 50, -1153, -90, 164, 101, 231, 198, 255),
VTX(-800, 1353, -1741, 534, 1473, 90, 52, 197, 255),
VTX(400, 449, 714, 490, -17, 116, 10, 28, 255),
VTX(200, 847, 175, 1100, 73, 111, 44, 248, 255),
VTX(-800, 1353, 1741, 534, 1473, 90, 52, 59, 255),
VTX(50, 50, 1153, -90, 164, 101, 231, 58, 255),
VTX(100, -285, -39, 481, -486, 114, 221, 245, 255),
VTX(-1167, -1126, -1354, 92, 521, 59, 187, 179, 255),
VTX(-1558, 211, -2432, 1065, 1106, 67, 232, 160, 255),
VTX(-2285, -1061, -1803, -34, 1021, 31, 183, 167, 255),
VTX(-1167, -1126, 1354, 92, 521, 59, 187, 77, 255),
VTX(-1558, 211, 2432, 1065, 1106, 67, 232, 96, 255),
VTX(-2285, -1061, 1803, -34, 1021, 32, 183, 89, 255),
VTX(-1167, -1126, 1354, 92, 521, 59, 187, 77, 255),
VTX(-249, -1191, 0, -148, -416, 91, 178, 0, 255),
VTX(0, 104, 1042, 970, 1, 97, 248, 69, 255),
};
static Vtx sHintNutsSkelVtx_0009F0[20] = {
VTX(546, -50, -667, 0, 124, 226, 86, 179, 255),
VTX(546, 550, 1, 533, 139, 217, 113, 0, 255),
VTX(2594, 370, 0, 467, 1666, 10, 119, 0, 255),
VTX(546, -50, 669, 1067, 154, 226, 86, 77, 255),
VTX(-505, -354, -6, 570, -832, 178, 91, 0, 255),
VTX(546, 550, 1, 533, 139, 217, 113, 0, 255),
VTX(612, -175, 650, 0, 124, 211, 72, 84, 255),
VTX(-435, -213, -235, 570, -832, 196, 78, 68, 255),
VTX(-22, -935, 965, 1067, 154, 211, 72, 84, 255),
VTX(1460, -1166, 1541, 467, 1666, 228, 64, 97, 255),
VTX(1460, -1166, -1541, 467, 1666, 228, 64, 159, 255),
VTX(-22, -935, -965, 1067, 154, 211, 72, 172, 255),
VTX(612, -175, -650, 0, 124, 211, 72, 172, 255),
VTX(-435, -213, 235, 570, -832, 196, 78, 188, 255),
VTX(395, -1420, 1, 533, 139, 112, 214, 0, 255),
VTX(55, -77, -35, 570, -832, 116, 29, 255, 255),
VTX(-305, -1120, 909, 1067, 154, 86, 225, 77, 255),
VTX(-305, -1120, -907, 0, 124, 86, 223, 179, 255),
VTX(395, -1420, 1, 533, 139, 112, 214, 0, 255),
VTX(-1837, -2936, 0, 467, 1666, 67, 157, 0, 255),
};
Gfx sHintNutsSkelLimbDL_000B30[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_000180[0], 16, 0),
gsSP2Triangles(0, 1, 2, 0, 1, 3, 2, 0),
gsSP2Triangles(4, 5, 6, 0, 7, 8, 4, 0),
gsSP2Triangles(9, 7, 4, 0, 2, 10, 11, 0),
gsSP2Triangles(0, 2, 11, 0, 6, 5, 12, 0),
gsSP2Triangles(7, 13, 8, 0, 14, 5, 8, 0),
gsSP2Triangles(8, 13, 14, 0, 4, 6, 15, 0),
gsSP2Triangles(12, 5, 14, 0, 13, 7, 9, 0),
gsSP2Triangles(8, 5, 4, 0, 10, 2, 3, 0),
gsSP1Triangle(15, 6, 12, 0),
gsDPPipeSync(),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001FA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 3, 0, 2, 3, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 63, 1024),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 2, 0, 0, 0, 2, 3, 0, 2, 3, 0),
gsDPSetTileSize(0, 0, 0, 28, 28),
gsDPSetCombineLERP(TEXEL0, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, TEXEL0,
K5, K5, 0, COMBINED, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_LIGHTING),
gsSPVertex(&sHintNutsSkelVtx_000280[0], 6, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 5, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_000C68[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_0002E0[0], 6, 0),
gsSP2Triangles(0, 1, 2, 0, 1, 0, 3, 0),
gsSP2Triangles(1, 4, 2, 0, 4, 1, 3, 0),
gsSP2Triangles(5, 0, 2, 0, 0, 5, 3, 0),
gsSP2Triangles(4, 5, 2, 0, 5, 4, 3, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_000D10[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_002028),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 3, 0, 2, 3, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 63, 1024),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 2, 0, 0, 0, 2, 3, 0, 2, 3, 0),
gsDPSetTileSize(0, 0, 0, 28, 28),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_000340[0], 10, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 0, 0),
gsSP2Triangles(5, 2, 1, 0, 6, 4, 7, 0),
gsSP2Triangles(7, 5, 6, 0, 8, 4, 6, 0),
gsSP2Triangles(8, 1, 0, 0, 6, 1, 8, 0),
gsSP2Triangles(4, 3, 7, 0, 2, 9, 0, 0),
gsSP2Triangles(0, 4, 8, 0, 1, 6, 5, 0),
gsSP1Triangle(0, 9, 3, 0),
gsDPPipeSync(),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_0020A8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 3, 0, 2, 3, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 63, 1024),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 2, 0, 0, 0, 2, 3, 0, 2, 3, 0),
gsDPSetTileSize(0, 0, 0, 28, 28),
gsSPVertex(&sHintNutsSkelVtx_0003E0[0], 5, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 0, 0),
gsSP1Triangle(2, 3, 0, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_000E28[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_000430[0], 5, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 0, 2, 0),
gsSP2Triangles(0, 4, 1, 0, 2, 1, 4, 0),
gsSP2Triangles(2, 4, 3, 0, 0, 3, 4, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_000EC8[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_000480[0], 7, 0),
gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
gsSP2Triangles(2, 4, 3, 0, 5, 6, 0, 0),
gsSP2Triangles(5, 4, 2, 0, 5, 3, 4, 0),
gsSP2Triangles(0, 3, 5, 0, 2, 6, 5, 0),
gsSP2Triangles(2, 1, 6, 0, 0, 6, 1, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_000F78[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_0004F0[0], 7, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 0, 2, 0),
gsSP2Triangles(3, 4, 0, 0, 2, 5, 6, 0),
gsSP2Triangles(0, 4, 6, 0, 4, 3, 6, 0),
gsSP2Triangles(6, 3, 2, 0, 6, 5, 0, 0),
gsSP2Triangles(5, 1, 0, 0, 1, 5, 2, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_001028[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_001DA8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 0, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 0, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, 1,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_000560[0], 5, 0),
gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0),
gsSP2Triangles(1, 4, 2, 0, 4, 1, 0, 0),
gsSP2Triangles(3, 4, 0, 0, 4, 3, 2, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_0010C8[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_0015A8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 5, 0, 0, 5, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 1023, 256),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, 0, 0, 2, 5, 0, 0, 5, 0),
gsDPSetTileSize(0, 0, 0, 124, 124),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, TEXEL0,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_0005B0[0], 32, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 5, 0),
gsSP2Triangles(3, 6, 4, 0, 7, 8, 9, 0),
gsSP2Triangles(10, 11, 12, 0, 13, 14, 15, 0),
gsSP2Triangles(5, 16, 3, 0, 16, 17, 3, 0),
gsSP2Triangles(14, 13, 18, 0, 9, 19, 7, 0),
gsSP2Triangles(20, 21, 22, 0, 21, 23, 22, 0),
gsSP2Triangles(24, 25, 21, 0, 25, 26, 21, 0),
gsSP2Triangles(27, 28, 29, 0, 28, 30, 29, 0),
gsSPVertex(&sHintNutsSkelVtx_0005B0[31], 32, 0),
gsSP2Triangles(0, 1, 2, 0, 1, 3, 2, 0),
gsSP2Triangles(4, 2, 3, 0, 4, 0, 2, 0),
gsSP2Triangles(3, 5, 4, 0, 5, 6, 4, 0),
gsSP2Triangles(7, 8, 9, 0, 10, 11, 12, 0),
gsSP2Triangles(13, 14, 15, 0, 15, 16, 13, 0),
gsSP2Triangles(13, 16, 17, 0, 18, 19, 20, 0),
gsSP2Triangles(19, 21, 20, 0, 22, 20, 21, 0),
gsSP2Triangles(22, 18, 20, 0, 23, 24, 25, 0),
gsSP2Triangles(26, 23, 25, 0, 23, 26, 27, 0),
gsSP2Triangles(23, 27, 24, 0, 28, 29, 10, 0),
gsSP1Triangle(30, 29, 28, 0),
gsSPVertex(&sHintNutsSkelVtx_0005B0[62], 6, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 5, 0),
gsSP1Triangle(5, 1, 0, 0),
gsSPEndDisplayList(),
};
Gfx sHintNutsSkelLimbDL_001208[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_0015A8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 5, 0, 0, 5, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 1023, 256),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, 0, 0, 2, 5, 0, 0, 5, 0),
gsDPSetTileSize(0, 0, 0, 124, 124),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, TEXEL0,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&sHintNutsSkelVtx_0009F0[0], 20, 0),
gsSP2Triangles(0, 1, 2, 0, 1, 3, 2, 0),
gsSP2Triangles(0, 4, 5, 0, 4, 3, 5, 0),
gsSP2Triangles(6, 7, 8, 0, 6, 8, 9, 0),
gsSP2Triangles(10, 11, 12, 0, 11, 13, 12, 0),
gsSP2Triangles(14, 15, 16, 0, 14, 17, 15, 0),
gsSP2Triangles(17, 18, 19, 0, 18, 16, 19, 0),
gsSPEndDisplayList(),
};
static Vtx object_hintnutsVtx_0012C0[3] = {
VTX(-1500, -800, 0, -293, 549, 255, 255, 255, 255),
VTX(1500, -800, 0, 805, 549, 255, 255, 255, 255),
VTX(0, 1500, 0, 256, -293, 255, 255, 255, 255),
};
Gfx gHintNutsNutDL[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, object_hintnutsTex_002128),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 4, 0, 2, 4, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 255, 512),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, 0, 0, 2, 4, 0, 2, 4, 0),
gsDPSetTileSize(0, 0, 0, 60, 60),
gsDPSetCombineLERP(TEXEL0, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, TEXEL0,
K5, K5, 0, COMBINED, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_FOG),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&object_hintnutsVtx_0012C0[0], 3, 0),
gsSP1Triangle(0, 1, 2, 0),
gsSPEndDisplayList(),
};
static Vtx object_hintnutsVtx_001380[9] = {
VTX(0, 25, 0, 4096, -421, 0, 120, 0, 255),
VTX(2178, 960, -2178, 3072, 1152, 231, 114, 25, 255),
VTX(-2178, 960, -2178, 5120, 1152, 25, 114, 25, 255),
VTX(-2178, 960, 2178, 5120, 1152, 25, 114, 231, 255),
VTX(2178, 960, 2178, 3072, 1152, 231, 114, 231, 255),
VTX(-2178, 960, -2178, 7168, 1152, 25, 114, 25, 255),
VTX(0, 25, 0, 6144, -421, 0, 120, 0, 255),
VTX(2178, 960, -2178, 1024, 1152, 231, 114, 25, 255),
VTX(0, 25, 0, 2048, -421, 0, 120, 0, 255),
};
static Vtx object_hintnutsVtx_001410[13] = {
VTX(-3118, 60, 1800, 10240, 1024, 241, 118, 8, 255),
VTX(0, 60, 3600, 12288, 1024, 0, 118, 17, 255),
VTX(0, 572, 0, 11264, -69, 0, 120, 0, 255),
VTX(0, 60, -3600, 6144, 1024, 0, 118, 239, 255),
VTX(-3118, 60, -1800, 8192, 1024, 241, 118, 248, 255),
VTX(0, 572, 0, 7168, -69, 0, 120, 0, 255),
VTX(0, 572, 0, 9216, -69, 0, 120, 0, 255),
VTX(0, 60, 3600, 0, 1024, 0, 118, 17, 255),
VTX(3118, 60, 1800, 2048, 1024, 15, 118, 8, 255),
VTX(0, 572, 0, 1024, -69, 0, 120, 0, 255),
VTX(3118, 60, -1800, 4096, 1024, 15, 118, 248, 255),
VTX(0, 572, 0, 3072, -69, 0, 120, 0, 255),
VTX(0, 572, 0, 5120, -69, 0, 120, 0, 255),
};
Gfx gHintNutsFlowerDL[] = {
gsDPPipeSync(),
gsDPSetTextureLUT(G_TT_NONE),
gsSPTexture(65535, 65535, 0, 0, G_ON),
gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, sHintNutsSkelTex_0015A8),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, 7, 0, 2, 5, 0, 0, 5, 0),
gsDPLoadSync(),
gsDPLoadBlock(7, 0, 0, 1023, 256),
gsDPPipeSync(),
gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, 0, 0, 2, 5, 0, 0, 5, 0),
gsDPSetTileSize(0, 0, 0, 124, 124),
gsDPSetCombineLERP(TEXEL0, K5, SHADE, COMBINED_ALPHA, 0, 0, 0, TEXEL0,
COMBINED, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2),
gsSPClearGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_FOG | G_LIGHTING),
gsDPSetPrimColor(0, 0, 255, 255, 255, 255),
gsSPVertex(&object_hintnutsVtx_001380[0], 9, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 0, 0),
gsSP2Triangles(5, 3, 6, 0, 4, 7, 8, 0),
gsDPPipeSync(),
gsSPSetGeometryMode(G_TEXTURE_ENABLE | G_CULL_BACK),
gsSPVertex(&object_hintnutsVtx_001410[0], 13, 0),
gsSP2Triangles(0, 1, 2, 0, 3, 4, 5, 0),
gsSP2Triangles(4, 0, 6, 0, 7, 8, 9, 0),
gsSP2Triangles(8, 10, 11, 0, 10, 3, 12, 0),
gsSPEndDisplayList(),
};
u64 sHintNutsSkelTex_0015A8[] = {
#include "assets/objects/object_hintnuts//sHintNutsSkelTex_0015A8.rgb5a1.inc.c"
};
u64 sHintNutsSkelTex_001DA8[] = {
#include "assets/objects/object_hintnuts//sHintNutsSkelTex_001DA8.rgb5a1.inc.c"
};
u64 sHintNutsSkelTex_001FA8[] = {
#include "assets/objects/object_hintnuts//sHintNutsSkelTex_001FA8.rgb5a1.inc.c"
};
u64 sHintNutsSkelTex_002028[] = {
#include "assets/objects/object_hintnuts//sHintNutsSkelTex_002028.rgb5a1.inc.c"
};
u64 sHintNutsSkelTex_0020A8[] = {
#include "assets/objects/object_hintnuts//sHintNutsSkelTex_0020A8.rgb5a1.inc.c"
};
u64 object_hintnutsTex_002128[] = {
#include "assets/objects/object_hintnuts//object_hintnutsTex_002128.rgb5a1.inc.c"
};
StandardLimb sHintNutsSkelLimb_002328 = { { 0, 700, 0 }, 1, 255, sHintNutsSkelLimbDL_000C68 };
StandardLimb sHintNutsSkelLimb_002334 = { { 480, 0, 0 }, 2, 5, sHintNutsSkelLimbDL_000B30 };
StandardLimb sHintNutsSkelLimb_002340 = { { 1848, -96, 0 }, 255, 3, sHintNutsSkelLimbDL_0010C8 };
StandardLimb sHintNutsSkelLimb_00234C = { { 1920, 0, 0 }, 255, 4, sHintNutsSkelLimbDL_001208 };
StandardLimb sHintNutsSkelLimb_002358 = { { 240, 816, 0 }, 255, 255, sHintNutsSkelLimbDL_000D10 };
StandardLimb sHintNutsSkelLimb_002364 = { { -144, 0, 168 }, 6, 7, sHintNutsSkelLimbDL_001028 };
StandardLimb sHintNutsSkelLimb_002370 = { { 912, 0, 0 }, 255, 255, sHintNutsSkelLimbDL_000F78 };
StandardLimb sHintNutsSkelLimb_00237C = { { -144, 0, -168 }, 8, 255, sHintNutsSkelLimbDL_000E28 };
StandardLimb sHintNutsSkelLimb_002388 = { { 912, 0, 0 }, 255, 255, sHintNutsSkelLimbDL_000EC8 };
static void* sHintNutsSkelLimbs[9] = {
&sHintNutsSkelLimb_002328,
&sHintNutsSkelLimb_002334,
&sHintNutsSkelLimb_002340,
&sHintNutsSkelLimb_00234C,
&sHintNutsSkelLimb_002358,
&sHintNutsSkelLimb_002364,
&sHintNutsSkelLimb_002370,
&sHintNutsSkelLimb_00237C,
&sHintNutsSkelLimb_002388,
};
SkeletonHeader gHintNutsSkel = { sHintNutsSkelLimbs, 9 };
static u8 unaccounted_0023C0[16] = {
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsBurrowAnimFrameData[96] = {
0x0000, 0x02BC, 0x4000, 0x8000, 0xC000, 0x02BC, 0x03E8, 0xFD72, 0xF7CC, 0xF6A9, 0xF6CA, 0xF76B, 0xF7CC, 0xF7CC,
0xF7CC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF01C, 0x0073, 0x1018, 0x090A, 0x0000, 0x0000, 0xEBA1, 0xF73B,
0x062C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0092, 0x014E, 0x00BC, 0xFA39, 0xF26E, 0xFCE6,
0x07F9, 0x04D6, 0x0000, 0x0000, 0xFFE2, 0xFFBA, 0xFFD9, 0x010F, 0x02D6, 0x028E, 0x01B0, 0x00AB, 0x0000, 0x0000,
0xFFA9, 0xFF39, 0xFF90, 0x0399, 0x0814, 0xFFC7, 0xF79C, 0xFB4D, 0x0000, 0x0000, 0x0514, 0x0EF5, 0x1768, 0x182B,
0x182B, 0x182B, 0x182B, 0x182B, 0x182B, 0x0000, 0x0183, 0xFEE3, 0xFC22, 0xFBDF, 0xFBDF, 0xFBDF, 0xFBDF, 0xFBDF,
0xFBDF, 0x4000, 0x3A3B, 0x59AC, 0x7878, 0x7B59, 0x7B59, 0x7B59, 0x7B59, 0x7B59, 0x7B59, 0x0000,
};
static JointIndex sHintNutsBurrowAnimJointIndices[10] = {
{ 0x0000, 0x0005, 0x0000 },
{ 0x0002, 0x0000, 0x0002 },
{ 0x000F, 0x0000, 0x0019 },
{ 0x0000, 0x0000, 0x0000 },
{ 0x0023, 0x002D, 0x0037 },
{ 0x0041, 0x004B, 0x0055 },
{ 0x0002, 0x0000, 0x0003 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0002, 0x0003, 0x0000 },
{ 0x0003, 0x0003, 0x0004 },
};
AnimationHeader gHintNutsBurrowAnim = { { 10 }, sHintNutsBurrowAnimFrameData, sHintNutsBurrowAnimJointIndices, 5 };
static u8 unaccounted_0024DC[4] = {
0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsUnburrowAnimFrameData[212] = {
0x0000, 0x02BC, 0x4000, 0x8000, 0x02BC, 0x0B06, 0x1085, 0x139E, 0x14B4, 0x1403, 0x11DB, 0x0EC0, 0x0B35, 0x07BF,
0x04E2, 0x04E2, 0x04E2, 0x04E2, 0x04E2, 0x04E2, 0x4000, 0x45A2, 0x552A, 0x6C8B, 0x89BA, 0xAAAB, 0xCD50, 0xEF9E,
0x0F88, 0x2B02, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0xF6D5, 0xEDAA, 0xEE41, 0xEFD8, 0xF22D,
0xF500, 0xF80D, 0xFB13, 0xFDCF, 0x0000, 0x0075, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xED0C, 0xDA28, 0xE324,
0xF497, 0x00A4, 0x034F, 0x02F1, 0x012E, 0xFFA7, 0x0000, 0x072E, 0x0D72, 0x09F6, 0x037C, 0x0000, 0x0000, 0x001D,
0x006B, 0x00D9, 0x0156, 0x01D3, 0x0240, 0x028C, 0x02A7, 0x0281, 0x020A, 0xFD17, 0xF842, 0xFA16, 0xFDE7, 0x0000,
0x0000, 0xFF71, 0xFDF5, 0xFBD0, 0xF94C, 0xF6AD, 0xF43B, 0xF23D, 0xF0FA, 0xF0B8, 0xF1BD, 0xFB80, 0x0C54, 0x16D1,
0x0C1F, 0x0000, 0x4826, 0x47E0, 0x4730, 0x464C, 0x4568, 0x44B8, 0x4472, 0x44CA, 0x45F4, 0x4826, 0x5717, 0x66B5,
0x67AD, 0x63B1, 0x5CD0, 0x4826, 0x4000, 0x4000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000,
0x4000, 0xC000, 0xC000, 0xC000, 0xC000, 0x4000, 0x0000, 0x0000, 0xBF27, 0xC727, 0xCA85, 0xC9E3, 0xC5E4, 0xBF27,
0xAD07, 0x9221, 0x0000, 0x7AF3, 0x7A51, 0x7C36, 0x7EBD, 0x0000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000, 0x0260, 0x041B, 0x0318,
0x00B9, 0xFEDB, 0xFF5D, 0x041B, 0x154C, 0x2ECF, 0x4000, 0x44CB, 0x4564, 0x4398, 0x4133, 0x4000, 0x8000, 0x8000,
0x4212, 0x3A3A, 0x36EC, 0x378B, 0x3B77, 0x4212, 0x53D9, 0x6E39, 0x8000, 0x84F4, 0x8593, 0x83B7, 0x813D, 0x8000,
0xC000, 0x81AD, 0x80D9, 0x7F7F, 0x7CF5, 0x7B19, 0x7BC6, 0x80D9, 0x92F9, 0xADDF, 0xC000, 0xC50D, 0xC5AF, 0xC3CA,
0xC143, 0xC000,
};
static JointIndex sHintNutsUnburrowAnimJointIndices[10] = {
{ 0x0000, 0x0004, 0x0000 },
{ 0x0014, 0x0000, 0x0002 },
{ 0x0000, 0x0024, 0x0034 },
{ 0x0000, 0x0000, 0x0044 },
{ 0x0000, 0x0000, 0x0054 },
{ 0x0000, 0x0000, 0x0064 },
{ 0x0074, 0x0084, 0x0094 },
{ 0x0000, 0x0000, 0x00A4 },
{ 0x0002, 0x00B4, 0x0000 },
{ 0x0003, 0x0003, 0x00C4 },
};
AnimationHeader gHintNutsUnburrowAnim = { { 16 }, sHintNutsUnburrowAnimFrameData, sHintNutsUnburrowAnimJointIndices, 4 };
static u8 unaccounted_0026D4[12] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsLookAroundAnimFrameData[188] = {
0x0000, 0x02BC, 0x4000, 0x8000, 0xC000, 0x02BC, 0x02C3, 0x02D6, 0x02EE, 0x0306, 0x0319, 0x0320, 0x031A, 0x030C,
0x02F9, 0x02E3, 0x02D0, 0x02C2, 0x02BC, 0x02C3, 0x02D6, 0x02EE, 0x0306, 0x0319, 0x0320, 0x0319, 0x0306, 0x02EE,
0x02D6, 0x02C3, 0x02BC, 0x012F, 0x0000, 0xF659, 0xE925, 0xE000, 0xE000, 0xE000, 0xE000, 0xE000, 0xE925, 0xF659,
0x0000, 0x012F, 0xFED1, 0x0000, 0x09A7, 0x16DB, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x16DB, 0x09A7, 0x0000,
0xFED1, 0x0000, 0x0090, 0x011F, 0x0000, 0xF90E, 0xF35F, 0xF50C, 0xF8E5, 0xFD23, 0x0000, 0x00DA, 0x00B1, 0x0030,
0x0000, 0xFF9D, 0xFF66, 0x0160, 0x0AFB, 0x12B6, 0x1081, 0x0B61, 0x0596, 0x0160, 0xFFD4, 0xFFC3, 0x0000, 0x0000,
0xFFFF, 0xFFFD, 0x0000, 0x0012, 0x0020, 0x001C, 0x0012, 0x0007, 0x0000, 0xFFFE, 0xFFFE, 0xFFFF, 0x0000, 0x0006,
0x000C, 0x0000, 0xFFB4, 0xFF75, 0xFF87, 0xFFB1, 0xFFDF, 0x0000, 0x0009, 0x0004, 0x0000, 0x0000, 0xFFFC, 0xFFF7,
0x0000, 0x0037, 0x0063, 0x0056, 0x0038, 0x0017, 0x0000, 0xFFF9, 0xFFFA, 0xFFFE, 0x0000, 0xFFF4, 0xFFE7, 0x0000,
0x009A, 0x0118, 0x00F4, 0x00A0, 0x0042, 0x0000, 0xFFEE, 0xFFF7, 0x0000, 0x0000, 0x00F3, 0x01E7, 0x0000, 0xF772,
0xEC09, 0xE655, 0xE768, 0xEA45, 0xEE5D, 0xF322, 0xF809, 0xFC82, 0x0000, 0x00CA, 0x0043, 0x0289, 0x0C06, 0x1850,
0x1E41, 0x1BD1, 0x1629, 0x0EEA, 0x07B8, 0x0234, 0x0000, 0x5739, 0x59F8, 0x5F12, 0x61D1, 0x5ED5, 0x597F, 0x5739,
0x5AA5, 0x60CA, 0x66AA, 0x6949, 0x64E1, 0x5C76, 0x5739, 0x59FA, 0x5FE9, 0x61D1, 0x59C5, 0x4DB1, 0x4826, 0x514B,
0x60F9, 0x6949, 0x62AF, 0x551D, 0x49ED, 0x0000,
};
static JointIndex sHintNutsLookAroundAnimJointIndices[10] = {
{ 0x0000, 0x0005, 0x0000 },
{ 0x0002, 0x0000, 0x0002 },
{ 0x001F, 0x0000, 0x0000 },
{ 0x0039, 0x0053, 0x006D },
{ 0x0087, 0x0000, 0x0000 },
{ 0x0000, 0x0000, 0x00A1 },
{ 0x0002, 0x0000, 0x0003 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0002, 0x0003, 0x0000 },
{ 0x0003, 0x0003, 0x0004 },
};
AnimationHeader gHintNutsLookAroundAnim = { { 26 }, sHintNutsLookAroundAnimFrameData, sHintNutsLookAroundAnimJointIndices, 5 };
static u8 unaccounted_0028A4[12] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsFreezeAnimFrameData[104] = {
0x0000, 0x07F0, 0x4000, 0xE78E, 0x3639, 0x0008, 0x8000, 0x8008, 0x4000, 0x2F4C, 0x5006, 0x40E3, 0x30FE, 0x3E26,
0x4C39, 0x46E5, 0x3BE9, 0x356B, 0x3946, 0x419E, 0x470E, 0x46CD, 0x4448, 0x4163, 0x0000, 0x10B4, 0xF328, 0xFFAD,
0x0D1F, 0x01DD, 0xF5CB, 0xFA01, 0x02F9, 0x0851, 0x0542, 0xFE93, 0xFA3A, 0xFA76, 0xFC85, 0xFEE0, 0x4000, 0xC000,
0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000,
0x0000, 0x938F, 0x701C, 0x7FBA, 0x904C, 0x8243, 0x735F, 0x7925, 0x84F2, 0x8BD1, 0x8759, 0x7DF2, 0x77DA, 0x782D,
0x7B15, 0x7E69, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x911D, 0x6DDB, 0x7E59, 0x8FD1, 0x827D, 0x73EC, 0x7954, 0x8482, 0x8B01,
0x86B7, 0x7DC0, 0x77F7, 0x7856, 0x7B32, 0x7E73,
};
static JointIndex sHintNutsFreezeAnimJointIndices[10] = {
{ 0x0000, 0x0001, 0x0000 },
{ 0x0002, 0x0000, 0x0008 },
{ 0x0000, 0x0018, 0x0003 },
{ 0x0000, 0x0000, 0x0000 },
{ 0x0000, 0x0000, 0x0000 },
{ 0x0000, 0x0000, 0x0004 },
{ 0x0028, 0x0038, 0x0048 },
{ 0x0000, 0x0000, 0x0005 },
{ 0x0002, 0x0058, 0x0000 },
{ 0x0006, 0x0006, 0x0007 },
};
AnimationHeader gHintNutsFreezeAnim = { { 16 }, sHintNutsFreezeAnimFrameData, sHintNutsFreezeAnimJointIndices, 8 };
static u8 unaccounted_0029CC[4] = {
0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsUpAnimFrameData[194] = {
0x0000, 0xF7CC, 0x4000, 0x8000, 0xC000, 0x0000, 0x0071, 0x00C8, 0xFFF3, 0xFF38, 0xFFF6, 0x00C8, 0x00AC, 0x0049,
0x0000, 0xFFF0, 0xFFF2, 0xFFFB, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF7CC, 0xF7CC,
0xF7CC, 0xF7CC, 0xF7CC, 0xF7CC, 0xF7CC, 0xF7CC, 0xF7CC, 0xF7CC, 0xFA88, 0xFD44, 0x0000, 0x02BC, 0x02BC, 0x02BC,
0x02BC, 0x02BC, 0x02BC, 0x02BC, 0x02BC, 0x0000, 0x0071, 0x00C8, 0xFFF3, 0xFF38, 0xFFF6, 0x00C8, 0x00AC, 0x0049,
0x0000, 0xFFF0, 0xFFF2, 0xFFFB, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFEF,
0xFFC5, 0xFF8E, 0xFF57, 0xFF2D, 0xFF1C, 0xFF31, 0xFF79, 0x0000, 0x0421, 0x0755, 0x048F, 0xFFEA, 0xFB5D, 0xF8DE,
0xF916, 0xFACB, 0xFD19, 0xFF21, 0x0000, 0x0000, 0xFFFD, 0xFFF6, 0xFFED, 0xFFE4, 0xFFDD, 0xFFDA, 0xFFDE, 0xFFEA,
0x0000, 0x0126, 0x0139, 0xFBFD, 0xF7DA, 0xFA4E, 0xFEEA, 0x020A, 0x0260, 0x019A, 0x0089, 0x0000, 0x0000, 0xFE0F,
0xFDFE, 0xFDF7, 0xFC91, 0xFBAD, 0xFD80, 0xFFA8, 0x0019, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x063A, 0xFDC0, 0xF70F, 0xFFA5, 0x0895, 0x0341, 0xFC35, 0xFD91,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF3A1,
0xFF9A, 0x0930, 0xFAE9, 0xECCD, 0xF6B3, 0x03AF, 0x030B, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0x4237, 0x4845, 0x5145, 0x5C53, 0x6889, 0x7503, 0x80DD, 0x8B32,
0x931E, 0x97DF, 0x96FD, 0x8D01, 0x7121, 0x4C28, 0x3500, 0x317B, 0x358B, 0x3D47, 0x44C8, 0x4826,
};
static JointIndex sHintNutsUpAnimJointIndices[10] = {
{ 0x0005, 0x001A, 0x002F },
{ 0x0002, 0x0000, 0x0002 },
{ 0x0000, 0x0000, 0x0044 },
{ 0x0000, 0x0000, 0x0059 },
{ 0x006E, 0x0083, 0x0098 },
{ 0x0000, 0x0000, 0x00AD },
{ 0x0002, 0x0000, 0x0003 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0002, 0x0003, 0x0000 },
{ 0x0003, 0x0003, 0x0004 },
};
AnimationHeader gHintNutsUpAnim = { { 21 }, sHintNutsUpAnimFrameData, sHintNutsUpAnimJointIndices, 5 };
static s16 sHintNutsTalkAnimFrameData[340] = {
0x0000, 0x04E2, 0x4000, 0xF9E3, 0xF8CE, 0xF603, 0xF231, 0xEE07, 0xEA35, 0xE76A, 0xE655, 0xE701, 0xE8CD, 0xEB67,
0xEE7D, 0xF1BC, 0xF4D1, 0xF76C, 0xF938, 0x0000, 0x06AB, 0x0AAB, 0x06AB, 0x0000, 0xF9E1, 0xF555, 0xF970, 0x0000,
0x06C5, 0x0AAB, 0x06AB, 0x0000, 0xF955, 0xF555, 0xF955, 0x0000, 0xFFEF, 0xFFC4, 0xFF88, 0xFF48, 0xFF0C, 0xFEE1,
0xFED0, 0xFEDA, 0xFEF6, 0xFF1F, 0xFF4F, 0xFF81, 0xFFB1, 0xFFDA, 0xFFF6, 0xED42, 0xEC3F, 0xE9A4, 0xE614, 0xE233,
0xDEA3, 0xDC08, 0xDB05, 0xDBA5, 0xDD52, 0xDFBF, 0xE2A0, 0xE5A7, 0xE888, 0xEAF5, 0xECA2, 0x0000, 0x0156, 0x0447,
0x0738, 0x088E, 0x078B, 0x0523, 0x024E, 0x0000, 0xFE39, 0xFC8B, 0xFB4B, 0xFACE, 0xFB9E, 0xFD67, 0xFF30, 0x0000,
0xFF2E, 0xFD3A, 0xFAEA, 0xF903, 0xF849, 0xF92E, 0xFB2E, 0xFD9F, 0xFFDA, 0x0136, 0x019C, 0x0185, 0x0122, 0x00A0,
0x0030, 0x0000, 0xF8E4, 0xF1C7, 0xF71C, 0x0000, 0x08E4, 0x0E39, 0x08E4, 0x0000, 0xF71C, 0xF1C7, 0xF71C, 0x0000,
0x08E4, 0x0E39, 0x071C, 0x0000, 0xFF2D, 0xFD25, 0xFA95, 0xF828, 0xF689, 0xF664, 0xF844, 0xFBBB, 0x0000, 0x044B,
0x07D4, 0x09D2, 0x08D4, 0x0564, 0x01B7, 0x4826, 0x3F98, 0x3709, 0x3F81, 0x4826, 0x4065, 0x3876, 0x404A, 0x4826,
0x4078, 0x38C0, 0x3FCF, 0x4826, 0x4998, 0x496F, 0x48A1, 0xBBEE, 0xBC3C, 0x3D13, 0x3E55, 0x3FD2, 0x4142, 0x4254,
0x42BF, 0x427D, 0x41CC, 0x40CE, 0x3FA7, 0x3E7E, 0x3D74, 0x3CA4, 0xBC1E, 0x8B8B, 0x8BB4, 0xF3F5, 0xF3A7, 0xF38D,
0xF3B2, 0xF3F3, 0xF415, 0xF3FF, 0xF3CE, 0xF3A0, 0xF38D, 0xF3A1, 0xF3D7, 0xF41E, 0x8BA5, 0xF9A8, 0xF85E, 0x7509,
0x7075, 0x6B75, 0x66E1, 0x638C, 0x6243, 0x630E, 0x6532, 0x684E, 0x6C02, 0x6FE9, 0x739C, 0x76B8, 0xF8DC, 0x0000,
0x003F, 0x00D8, 0x0196, 0x0240, 0x02E9, 0x03A3, 0x043A, 0x047C, 0x044A, 0x03C4, 0x0319, 0x0276, 0x01C3, 0x00F3,
0x0048, 0x05B4, 0x0619, 0x0708, 0x081D, 0x08F8, 0x0999, 0x0A2A, 0x0A8B, 0x0A9C, 0x0A39, 0x097C, 0x08A1, 0x07E2,
0x0733, 0x067D, 0x05EE, 0x328E, 0x3961, 0x4038, 0x3934, 0x32AB, 0x3BA8, 0x4428, 0x3BCB, 0x32B1, 0x3819, 0x3E3C,
0x38E8, 0x329D, 0x3182, 0x319C, 0x3233, 0x453E, 0x44C5, 0xC38B, 0xC1E5, 0xC054, 0xBED2, 0xBDBC, 0xBDC0, 0xBE6C,
0xBF60, 0xC080, 0xC1AF, 0xC2D1, 0xC3CD, 0x4492, 0x4510, 0x71D3, 0x719B, 0x0ED5, 0x0F29, 0x0F3E, 0x0F26, 0x0EF4,
0x0EE8, 0x0EFF, 0x0F20, 0x0F2F, 0x0F22, 0x0EF9, 0x0EBA, 0x7189, 0x71BE, 0xF997, 0xF806, 0x7436, 0x6F7C, 0x6B3C,
0x673D, 0x646C, 0x649C, 0x6672, 0x68E3, 0x6BD4, 0x6F02, 0x722B, 0x750E, 0xF76A, 0xF901, 0x7D28, 0x7CDE, 0x7C47,
0x7BCE, 0x7BDB, 0x7CD7, 0x7E6F, 0x7FFA, 0x80CF, 0x8094, 0x7FB2, 0x7EA3, 0x7DE0, 0x7D82, 0x7D4A, 0x7D2F, 0x595D,
0x59A6, 0x5A55, 0x5B2A, 0x5BE8, 0x5CA9, 0x5D81, 0x5E21, 0x5E3E, 0x5D8C, 0x5C46, 0x5AE9, 0x59F1, 0x5982, 0x5959,
0x5957, 0xAA94, 0xAA4D, 0xA9B5, 0xA920, 0xA8E6, 0xA937, 0xA9DC, 0xAA92, 0xAB14, 0xAB56, 0xAB79, 0xAB84, 0xAB7B,
0xAB4E, 0xAAFF, 0xAAB5, 0x0000,
};
static JointIndex sHintNutsTalkAnimJointIndices[10] = {
{ 0x0000, 0x0001, 0x0000 },
{ 0x0002, 0x0003, 0x0002 },
{ 0x0013, 0x0023, 0x0033 },
{ 0x0043, 0x0000, 0x0053 },
{ 0x0000, 0x0063, 0x0073 },
{ 0x0000, 0x0000, 0x0083 },
{ 0x0093, 0x00A3, 0x00B3 },
{ 0x00C3, 0x00D3, 0x00E3 },
{ 0x00F3, 0x0103, 0x0113 },
{ 0x0123, 0x0133, 0x0143 },
};
AnimationHeader gHintNutsTalkAnim = { { 16 }, sHintNutsTalkAnimFrameData, sHintNutsTalkAnimJointIndices, 3 };
static u8 unaccounted_002E94[12] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsStandAnimFrameData[80] = {
0x0000, 0x02BC, 0x4000, 0x8000, 0xC000, 0x0000, 0xFF41, 0xFD56, 0xFAB5, 0xF7D9, 0xF538, 0xF34D, 0xF28E, 0xF31A,
0xF48C, 0xF69B, 0xF8FC, 0xFB67, 0xFD90, 0xFF2E, 0xF5D0, 0xF4D8, 0xF257, 0xEEEB, 0xEB31, 0xE7C5, 0xE544, 0xE44B,
0xE50C, 0xE708, 0xE9D6, 0xED0E, 0xF045, 0xF314, 0xF510, 0x0000, 0x0044, 0x00E5, 0x01A3, 0x023D, 0x0272, 0x021B,
0x0164, 0x0087, 0xFFBE, 0xFF44, 0xFF30, 0xFF59, 0xFFA0, 0xFFE2, 0x0000, 0x00AC, 0x0235, 0x03E5, 0x0507, 0x04E4,
0x02C3, 0xFF1D, 0xFB09, 0xF79A, 0xF5E6, 0xF68D, 0xF8D4, 0xFBC8, 0xFE78, 0x5B4C, 0x5D73, 0x6229, 0x66CC, 0x68BE,
0x671C, 0x6387, 0x5F2D, 0x5B38, 0x58D3, 0x5829, 0x5861, 0x5925, 0x5A1D, 0x5AF2,
};
static JointIndex sHintNutsStandAnimJointIndices[10] = {
{ 0x0000, 0x0001, 0x0000 },
{ 0x0002, 0x0005, 0x0002 },
{ 0x0000, 0x0000, 0x0014 },
{ 0x0000, 0x0000, 0x0023 },
{ 0x0000, 0x0000, 0x0032 },
{ 0x0000, 0x0000, 0x0041 },
{ 0x0002, 0x0000, 0x0003 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0002, 0x0003, 0x0000 },
{ 0x0003, 0x0003, 0x0004 },
};
AnimationHeader gHintNutsStandAnim = { { 15 }, sHintNutsStandAnimFrameData, sHintNutsStandAnimJointIndices, 5 };
static u8 unaccounted_002F8C[4] = {
0x00, 0x00, 0x00, 0x00,
};
static s16 sHintNutsRunAnimFrameData[174] = {
0x0000, 0x04E2, 0x4826, 0x4000, 0x8000, 0x04E2, 0x094D, 0x0DB7, 0x0C56, 0x094D, 0x0643, 0x04E2, 0x094D, 0x0DB7,
0x0CCD, 0x0A8B, 0x07AA, 0x4000, 0x4042, 0x4109, 0x40CC, 0x405C, 0x4011, 0x4000, 0x3FC5, 0x3F2E, 0x3F6B, 0x3FCC,
0x3FFB, 0x0000, 0x03A8, 0x0743, 0x0632, 0x03CF, 0x0152, 0x0000, 0x02A3, 0x0564, 0x0490, 0x02B8, 0x00DA, 0x4000,
0x42DD, 0x45CC, 0x453E, 0x43DB, 0x4200, 0x4000, 0x3C72, 0x39D6, 0x3AD0, 0x3CF0, 0x3F0B, 0x0000, 0x0D0A, 0x1A13,
0x179D, 0x1156, 0x08E7, 0xFFF7, 0xF153, 0xE703, 0xEAEB, 0xF382, 0xFC19, 0x0000, 0xFC4F, 0xFC8F, 0xFD33, 0xFE17,
0xFF15, 0x000A, 0x018D, 0x029E, 0x0234, 0x014E, 0x0068, 0x0000, 0xFE85, 0xFAE1, 0xF62A, 0xF176, 0xEDD8, 0xEC65,
0xEDD9, 0xF17B, 0xF633, 0xFAEB, 0xFE8C, 0x0000, 0xF60F, 0xE399, 0xD9A8, 0xE399, 0xF60F, 0x0000, 0xF60F, 0xE399,
0xD9A8, 0xE399, 0xF60F, 0x4000, 0xC000, 0xC000, 0xC000, 0xC000, 0xC000, 0x4000, 0xC000, 0xC000, 0xC000, 0xC000,
0xC000, 0x0000, 0x9185, 0x8F62, 0x8A68, 0x84BF, 0x808F, 0x0000, 0x9040, 0x9F83, 0x9A96, 0x8FC1, 0x84EC, 0x8000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0xEEFF, 0x067D,
0x30E5, 0x5073, 0x53A3, 0x4000, 0xF818, 0x0E4B, 0x357D, 0x523C, 0x4CB7, 0x8000, 0x651C, 0x67C2, 0x6E23, 0x75E0,
0x7C9E, 0x8000, 0x7608, 0x6B9B, 0x6ECA, 0x75CD, 0x7CD0, 0xC000, 0x6B41, 0x8636, 0xB550, 0xD7A2, 0xD839, 0xC000,
0x7594, 0x88C3, 0xACF6, 0xC8A0, 0xC809, 0x0000,
};
static JointIndex sHintNutsRunAnimJointIndices[10] = {
{ 0x0000, 0x0005, 0x0000 },
{ 0x0011, 0x001D, 0x0029 },
{ 0x0035, 0x0041, 0x004D },
{ 0x0000, 0x0000, 0x0000 },
{ 0x0000, 0x0000, 0x0059 },
{ 0x0000, 0x0000, 0x0002 },
{ 0x0065, 0x0071, 0x007D },
{ 0x0000, 0x0000, 0x0089 },
{ 0x0003, 0x0095, 0x0000 },
{ 0x0004, 0x0004, 0x00A1 },
};
AnimationHeader gHintNutsRunAnim = { { 12 }, sHintNutsRunAnimFrameData, sHintNutsRunAnimJointIndices, 5 };
static u8 unaccounted_003138[8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
|
9ab117974e1af02fbf57fed74afaf5d4f5421ee8
|
bed3ac926beac0f4e0293303d7b2a6031ee476c9
|
/Modules/ThirdParty/VNL/src/vxl/v3p/netlib/eispack/tred2.c
|
aaffe351b0108877207db3ab954602672872f31f
|
[
"IJG",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"SMLNJ",
"BSD-3-Clause",
"BSD-4.3TAHOE",
"LicenseRef-scancode-free-unknown",
"Spencer-86",
"LicenseRef-scancode-llnl",
"FSFUL",
"Libpng",
"libtiff",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-hdf5",
"MIT",
"NTP",
"LicenseRef-scancode-mit-old-style",
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"MPL-2.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] |
permissive
|
InsightSoftwareConsortium/ITK
|
ed9dbbc5b8b3f7511f007c0fc0eebb3ad37b88eb
|
3eb8fd7cdfbc5ac2d0c2e5e776848a4cbab3d7e1
|
refs/heads/master
| 2023-08-31T17:21:47.754304
| 2023-08-31T00:58:51
| 2023-08-31T14:12:21
| 800,928
| 1,229
| 656
|
Apache-2.0
| 2023-09-14T17:54:00
| 2010-07-27T15:48:04
|
C++
|
UTF-8
|
C
| false
| false
| 9,979
|
c
|
tred2.c
|
/* eispack/tred2.f -- translated by f2c (version 20050501).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "v3p_netlib.h"
/*< subroutine tred2(nm,n,a,d,e,z) >*/
/* Subroutine */ int tred2_(integer *nm, integer *n, doublereal *a,
doublereal *d__, doublereal *e, doublereal *z__)
{
/* System generated locals */
integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2, i__3;
doublereal d__1;
/* Builtin functions */
double sqrt(doublereal), d_sign(doublereal *, doublereal *);
/* Local variables */
doublereal f, g, h__;
integer i__, j, k, l;
doublereal hh;
integer ii, jp1;
doublereal scale;
/*< integer i,j,k,l,n,ii,nm,jp1 >*/
/*< double precision a(nm,n),d(n),e(n),z(nm,n) >*/
/*< double precision f,g,h,hh,scale >*/
/* this subroutine is a translation of the algol procedure tred2, */
/* num. math. 11, 181-195(1968) by martin, reinsch, and wilkinson. */
/* handbook for auto. comp., vol.ii-linear algebra, 212-226(1971). */
/* this subroutine reduces a real symmetric matrix to a */
/* symmetric tridiagonal matrix using and accumulating */
/* orthogonal similarity transformations. */
/* on input */
/* nm must be set to the row dimension of two-dimensional */
/* array parameters as declared in the calling program */
/* dimension statement. */
/* n is the order of the matrix. */
/* a contains the real symmetric input matrix. only the */
/* lower triangle of the matrix need be supplied. */
/* on output */
/* d contains the diagonal elements of the tridiagonal matrix. */
/* e contains the subdiagonal elements of the tridiagonal */
/* matrix in its last n-1 positions. e(1) is set to zero. */
/* z contains the orthogonal transformation matrix */
/* produced in the reduction. */
/* a and z may coincide. if distinct, a is unaltered. */
/* questions and comments should be directed to burton s. garbow, */
/* mathematics and computer science div, argonne national laboratory */
/* this version dated august 1983. */
/* ------------------------------------------------------------------ */
/*< do 100 i = 1, n >*/
/* Parameter adjustments */
z_dim1 = *nm;
z_offset = 1 + z_dim1;
z__ -= z_offset;
--e;
--d__;
a_dim1 = *nm;
a_offset = 1 + a_dim1;
a -= a_offset;
/* Function Body */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/*< do 80 j = i, n >*/
i__2 = *n;
for (j = i__; j <= i__2; ++j) {
/*< 80 z(j,i) = a(j,i) >*/
/* L80: */
z__[j + i__ * z_dim1] = a[j + i__ * a_dim1];
}
/*< d(i) = a(n,i) >*/
d__[i__] = a[*n + i__ * a_dim1];
/*< 100 continue >*/
/* L100: */
}
/*< if (n .eq. 1) go to 510 >*/
if (*n == 1) {
goto L510;
}
/* .......... for i=n step -1 until 2 do -- .......... */
/*< do 300 ii = 2, n >*/
i__1 = *n;
for (ii = 2; ii <= i__1; ++ii) {
/*< i = n + 2 - ii >*/
i__ = *n + 2 - ii;
/*< l = i - 1 >*/
l = i__ - 1;
/*< h = 0.0d0 >*/
h__ = 0.;
/*< scale = 0.0d0 >*/
scale = 0.;
/*< if (l .lt. 2) go to 130 >*/
if (l < 2) {
goto L130;
}
/* .......... scale row (algol tol then not needed) .......... */
/*< do 120 k = 1, l >*/
i__2 = l;
for (k = 1; k <= i__2; ++k) {
/*< 120 scale = scale + dabs(d(k)) >*/
/* L120: */
scale += (d__1 = d__[k], abs(d__1));
}
/*< if (scale .ne. 0.0d0) go to 140 >*/
if (scale != 0.) {
goto L140;
}
/*< 130 e(i) = d(l) >*/
L130:
e[i__] = d__[l];
/*< do 135 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< d(j) = z(l,j) >*/
d__[j] = z__[l + j * z_dim1];
/*< z(i,j) = 0.0d0 >*/
z__[i__ + j * z_dim1] = 0.;
/*< z(j,i) = 0.0d0 >*/
z__[j + i__ * z_dim1] = 0.;
/*< 135 continue >*/
/* L135: */
}
/*< go to 290 >*/
goto L290;
/*< 140 do 150 k = 1, l >*/
L140:
i__2 = l;
for (k = 1; k <= i__2; ++k) {
/*< d(k) = d(k) / scale >*/
d__[k] /= scale;
/*< h = h + d(k) * d(k) >*/
h__ += d__[k] * d__[k];
/*< 150 continue >*/
/* L150: */
}
/*< f = d(l) >*/
f = d__[l];
/*< g = -dsign(dsqrt(h),f) >*/
d__1 = sqrt(h__);
g = -d_sign(&d__1, &f);
/*< e(i) = scale * g >*/
e[i__] = scale * g;
/*< h = h - f * g >*/
h__ -= f * g;
/*< d(l) = f - g >*/
d__[l] = f - g;
/* .......... form a*u .......... */
/*< do 170 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< 170 e(j) = 0.0d0 >*/
/* L170: */
e[j] = 0.;
}
/*< do 240 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< f = d(j) >*/
f = d__[j];
/*< z(j,i) = f >*/
z__[j + i__ * z_dim1] = f;
/*< g = e(j) + z(j,j) * f >*/
g = e[j] + z__[j + j * z_dim1] * f;
/*< jp1 = j + 1 >*/
jp1 = j + 1;
/*< if (l .lt. jp1) go to 220 >*/
if (l < jp1) {
goto L220;
}
/*< do 200 k = jp1, l >*/
i__3 = l;
for (k = jp1; k <= i__3; ++k) {
/*< g = g + z(k,j) * d(k) >*/
g += z__[k + j * z_dim1] * d__[k];
/*< e(k) = e(k) + z(k,j) * f >*/
e[k] += z__[k + j * z_dim1] * f;
/*< 200 continue >*/
/* L200: */
}
/*< 220 e(j) = g >*/
L220:
e[j] = g;
/*< 240 continue >*/
/* L240: */
}
/* .......... form p .......... */
/*< f = 0.0d0 >*/
f = 0.;
/*< do 245 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< e(j) = e(j) / h >*/
e[j] /= h__;
/*< f = f + e(j) * d(j) >*/
f += e[j] * d__[j];
/*< 245 continue >*/
/* L245: */
}
/*< hh = f / (h + h) >*/
hh = f / (h__ + h__);
/* .......... form q .......... */
/*< do 250 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< 250 e(j) = e(j) - hh * d(j) >*/
/* L250: */
e[j] -= hh * d__[j];
}
/* .......... form reduced a .......... */
/*< do 280 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< f = d(j) >*/
f = d__[j];
/*< g = e(j) >*/
g = e[j];
/*< do 260 k = j, l >*/
i__3 = l;
for (k = j; k <= i__3; ++k) {
/*< 260 z(k,j) = z(k,j) - f * e(k) - g * d(k) >*/
/* L260: */
z__[k + j * z_dim1] = z__[k + j * z_dim1] - f * e[k] - g *
d__[k];
}
/*< d(j) = z(l,j) >*/
d__[j] = z__[l + j * z_dim1];
/*< z(i,j) = 0.0d0 >*/
z__[i__ + j * z_dim1] = 0.;
/*< 280 continue >*/
/* L280: */
}
/*< 290 d(i) = h >*/
L290:
d__[i__] = h__;
/*< 300 continue >*/
/* L300: */
}
/* .......... accumulation of transformation matrices .......... */
/*< do 500 i = 2, n >*/
i__1 = *n;
for (i__ = 2; i__ <= i__1; ++i__) {
/*< l = i - 1 >*/
l = i__ - 1;
/*< z(n,l) = z(l,l) >*/
z__[*n + l * z_dim1] = z__[l + l * z_dim1];
/*< z(l,l) = 1.0d0 >*/
z__[l + l * z_dim1] = 1.;
/*< h = d(i) >*/
h__ = d__[i__];
/*< if (h .eq. 0.0d0) go to 380 >*/
if (h__ == 0.) {
goto L380;
}
/*< do 330 k = 1, l >*/
i__2 = l;
for (k = 1; k <= i__2; ++k) {
/*< 330 d(k) = z(k,i) / h >*/
/* L330: */
d__[k] = z__[k + i__ * z_dim1] / h__;
}
/*< do 360 j = 1, l >*/
i__2 = l;
for (j = 1; j <= i__2; ++j) {
/*< g = 0.0d0 >*/
g = 0.;
/*< do 340 k = 1, l >*/
i__3 = l;
for (k = 1; k <= i__3; ++k) {
/*< 340 g = g + z(k,i) * z(k,j) >*/
/* L340: */
g += z__[k + i__ * z_dim1] * z__[k + j * z_dim1];
}
/*< do 360 k = 1, l >*/
i__3 = l;
for (k = 1; k <= i__3; ++k) {
/*< z(k,j) = z(k,j) - g * d(k) >*/
z__[k + j * z_dim1] -= g * d__[k];
/*< 360 continue >*/
/* L360: */
}
}
/*< 380 do 400 k = 1, l >*/
L380:
i__3 = l;
for (k = 1; k <= i__3; ++k) {
/*< 400 z(k,i) = 0.0d0 >*/
/* L400: */
z__[k + i__ * z_dim1] = 0.;
}
/*< 500 continue >*/
/* L500: */
}
/*< 510 do 520 i = 1, n >*/
L510:
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/*< d(i) = z(n,i) >*/
d__[i__] = z__[*n + i__ * z_dim1];
/*< z(n,i) = 0.0d0 >*/
z__[*n + i__ * z_dim1] = 0.;
/*< 520 continue >*/
/* L520: */
}
/*< z(n,n) = 1.0d0 >*/
z__[*n + *n * z_dim1] = 1.;
/*< e(1) = 0.0d0 >*/
e[1] = 0.;
/*< return >*/
return 0;
/*< end >*/
} /* tred2_ */
#ifdef __cplusplus
}
#endif
|
dca9dcb2c58cf27e6e7cc05d7378c45ca99b89cc
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/u-boot_new/drivers/video/sunxi/disp2/disp/de/lowlevel_sun50iw1/de_enhance.h
|
0654fba384801c8e09e4e76bb1a5d8f1fc30996f
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"GPL-2.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 7,164
|
h
|
de_enhance.h
|
//*********************************************************************************************************************
// All Winner Tech, All Right Reserved. 2014-2015 Copyright (c)
//
// File name : de_enhance.h
//
// Description : display engine 2.0 enhance basic function declaration
//
// History : 2014/04/02 vito cheng v0.1 Initial version
// 2014/04/29 vito cheng v0.2 Add disp_enhance_config_data struct delcaration
// Add updata_regs and init for every module
//
//*********************************************************************************************************************
#ifndef __DE_ENHANCE_H__
#define __DE_ENHANCE_H__
#include "de_fce_type.h"
#include "de_peak_type.h"
#include "de_lti_type.h"
#include "de_ase_type.h"
#include "de_fcc_type.h"
#define MODE_NUM 4 //2
#define PARA_NUM 6
#define FORMAT_NUM 2
#define ENHANCE_MODE_NUM 3
#define ENAHNCE_MIN_WIDTH 32
#define ENAHNCE_MIN_HEIGHT 4
#define PEAK_OFST 0xA6000 //PEAKING offset based on RTMX
#define LTI_OFST 0xA4000 //LTI offset based on RTMX
#define FCE_OFST 0xA0000 //FCE offset based on RTMX
#define ASE_OFST 0xA8000 //ASE offset based on RTMX
#define FCC_OFST 0xAA000 //FCC offset based on RTMX
typedef struct
{
__fce_config_data fce_para;
__lti_config_data lti_para;
__peak_config_data peak_para;
__ase_config_data ase_para;
__fcc_config_data fcc_para;
}vep_config_data;
extern __hist_status_t *g_hist_status[DEVICE_NUM][CHN_NUM];
extern __ce_status_t *g_ce_status[DEVICE_NUM][CHN_NUM];
extern unsigned int *g_hist[DEVICE_NUM][CHN_NUM];
extern unsigned int g_sum[DEVICE_NUM][CHN_NUM];
extern unsigned int *g_hist_p[DEVICE_NUM][CHN_NUM];
extern unsigned int g_format[DEVICE_NUM];
extern unsigned int g_size_bypass[DEVICE_NUM]; //size too small to enable vep
//peak function declaration
int de_peak_set_reg_base(unsigned int sel, unsigned int chno, void *base);
int de_peak_update_regs(unsigned int sel, unsigned int chno);
int de_peak_init(unsigned int sel, unsigned int chno, uintptr_t reg_base);
int de_peak_enable(unsigned int sel, unsigned int chno, unsigned int en);
int de_peak_set_size(unsigned int sel, unsigned int chno, unsigned int width, unsigned int height);
int de_peak_set_window(unsigned int sel, unsigned int chno, unsigned int win_enable, de_rect window);
int de_peak_set_para(unsigned int sel, unsigned int chno, unsigned int gain, unsigned int hp_ratio,
unsigned int bp0_ratio);
int de_peak_info2para(unsigned int sharp, de_rect window, __peak_config_data *para);
//LTI function declaration
int de_lti_set_reg_base(unsigned int sel, unsigned int chno, void *base);
int de_lti_update_regs(unsigned int sel, unsigned int chno);
int de_lti_init(unsigned int sel, unsigned int chno, uintptr_t reg_base);
int de_lti_enable(unsigned int sel, unsigned int chno, unsigned int en);
int de_lti_set_size(unsigned int sel, unsigned int chno, unsigned int width, unsigned int height);
int de_lti_set_window(unsigned int sel, unsigned int chno, unsigned int win_enable, de_rect window);
int de_lti_set_para(unsigned int sel, unsigned int chno, unsigned int gain);
int de_lti_info2para(unsigned int gain, de_rect window, __lti_config_data *para);
//FCE function declaration
int de_fce_set_reg_base(unsigned int sel, unsigned int chno, void *base);
int de_fce_update_regs(unsigned int sel, unsigned int chno);
int de_fce_init(unsigned int sel, unsigned int chno, uintptr_t reg_base);
int de_fce_enable(unsigned int sel, unsigned int chno, unsigned int en);
int de_fce_set_size(unsigned int sel, unsigned int chno, unsigned int width, unsigned int height);
int de_fce_set_window(unsigned int sel, unsigned int chno, unsigned int win_enable, de_rect window);
int de_fce_set_para(unsigned int sel, unsigned int chno, __fce_config_data fce_para);
int de_fce_csc_en(unsigned int sel, unsigned int chno, unsigned int csc_enable);
int de_fce_info2para(unsigned int detail, unsigned int auto_contrast, unsigned int auto_color, de_rect window, __fce_config_data *para);
int de_fce_get_hist(unsigned int sel, unsigned int chno, unsigned int hist[256], unsigned int *sum);
int de_fce_set_ce(unsigned int sel, unsigned int chno, unsigned char ce_lut[256]);
int de_fce_info2para(unsigned int sharp, unsigned int auto_contrast, unsigned int auto_color, de_rect window, __fce_config_data *para);
int de_hist_apply(unsigned int screen_id, unsigned int chno, unsigned int hist_en, unsigned int auto_contrast_dirty);
int de_hist_tasklet(unsigned int screen_id, unsigned int chno, unsigned int frame_cnt);
int de_ce_apply(unsigned int screen_id, unsigned int chno, unsigned int ce_en, unsigned int b_automode,
unsigned int up_precent_thr, unsigned int down_precent_thr, unsigned int update_diff_thr,
unsigned int black_slope_lmt, unsigned int white_slope_lmt,
unsigned int auto_contrast_dirty);
int de_ce_tasklet(unsigned int screen_id, unsigned int chno, unsigned int frame_cnt);
//ASE function declaration
int de_ase_set_reg_base(unsigned int sel, unsigned int chno, void *base);
int de_ase_update_regs(unsigned int sel, unsigned int chno);
int de_ase_init(unsigned int sel, unsigned int chno, uintptr_t reg_base);
int de_ase_enable(unsigned int sel, unsigned int chno, unsigned int en);
int de_ase_set_size(unsigned int sel, unsigned int chno, unsigned int width, unsigned int height);
int de_ase_set_window(unsigned int sel, unsigned int chno, unsigned int win_enable, de_rect window);
int de_ase_set_para(unsigned int sel, unsigned int chno, unsigned int gain);
int de_ase_info2para(unsigned int auto_color, de_rect window, __ase_config_data *para);
//FCC function declaration
int de_fcc_set_reg_base(unsigned int sel, unsigned int chno, void *base);
int de_fcc_init(unsigned int sel, unsigned int chno, uintptr_t reg_base);
int de_fcc_enable(unsigned int sel, unsigned int chno, unsigned int en);
int de_fcc_set_size(unsigned int sel, unsigned int chno, unsigned int width, unsigned int height);
int de_fcc_set_window(unsigned int sel, unsigned int chno, unsigned int win_en, de_rect window);
int de_fcc_set_para(unsigned int sel, unsigned int chno, unsigned int sgain[6]);
int de_fcc_csc_set(unsigned int sel, unsigned int chno, unsigned int en, unsigned int mode);
int de_fcc_info2para(unsigned int sgain0, unsigned int sgain1, unsigned int sgain2, unsigned int sgain3, unsigned int sgain4, unsigned int sgain5, de_rect window, __fcc_config_data *para);
int de_fcc_update_regs(unsigned int sel, unsigned int chno);
int de_enhance_apply(unsigned int screen_id, struct disp_enhance_config *config);
int de_enhance_sync(unsigned int screen_id);
int de_enhance_tasklet(unsigned int screen_id);
int de_enhance_update_regs(unsigned int screen_id);
int de_enhance_init(disp_bsp_init_para *para);
int de_enhance_info2data(struct disp_enhance_config *config, vep_config_data *data, unsigned int bypass);
int de_enhance_set_mode(unsigned int format, struct disp_enhance_config *config);
int de_enhance_set_format(unsigned int screen_id, unsigned int format);
int de_enhance_set_size(unsigned int screen_id, struct disp_rect *size);
int de_enhance_demo_enable(unsigned int screen_id, unsigned int enable);
#endif
|
d9238e45d5535e6eb27c5ba4e7433bb235d92571
|
66df4873f0599b86e6baf66bb3a0c87329a71e61
|
/pushdown-stack/linked-list/STACK.h
|
e37e1049404575e6b2d5f1411fb10666907c8c2e
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
bartobri/data-structures-c
|
1aaaa0f9f36b173b2df6049d9677c70a0d2afbde
|
02d8e6b0aec7d38af5f5d5cab3383bdbc2288a61
|
refs/heads/master
| 2023-02-21T23:00:18.553695
| 2023-02-17T16:58:37
| 2023-02-17T16:58:37
| 82,822,619
| 102
| 48
|
MIT
| 2020-10-01T12:04:34
| 2017-02-22T15:48:12
|
C
|
UTF-8
|
C
| false
| false
| 149
|
h
|
STACK.h
|
#ifndef STACK_H
#define STACK_H 1
#include "Item.h"
void STACKinit(int);
int STACKcount(void);
void STACKpush(Item);
Item STACKpop(void);
#endif
|
188c428b8f89913a666693fa44625c06b7f835e7
|
dd90a566f56722a602207ceee39a4e1803915c5c
|
/src/nanopolish_phase_reads.h
|
78a394184714c58c94f40033a2986ee9b616334a
|
[
"MPL-1.1",
"LicenseRef-scancode-public-domain",
"MIT"
] |
permissive
|
jts/nanopolish
|
98b3a8996ab44283990fe707ffc44d45b2a61695
|
28e774088b4a780b86066571896348e790f4113c
|
refs/heads/master
| 2023-08-14T02:02:30.379708
| 2023-08-05T15:27:20
| 2023-08-05T15:27:20
| 28,145,157
| 524
| 202
|
MIT
| 2023-08-05T15:27:21
| 2014-12-17T16:23:00
|
C++
|
UTF-8
|
C
| false
| false
| 412
|
h
|
nanopolish_phase_reads.h
|
//---------------------------------------------------------
// Copyright 2017 Ontario Institute for Cancer Research
// Written by Jared Simpson (jared.simpson@oicr.on.ca)
//---------------------------------------------------------
//
// nanopolish_phase_reads -- phase variants onto reads
//
#ifndef NANOPOLISH_PHASE_READS_H
#define NANOPOLISH_PHASE_READS_H
int phase_reads_main(int argc, char** argv);
#endif
|
da64ab809815d4b6ee585ade7df74dc722c7d687
|
5fd011017b9a2ec48069ba470bc6344d8374cf30
|
/share/pegasus/examples/glite-mpi-hw/pegasus-mpi-hw.c
|
5ea43965ded603dcbd92f0b784c4646897f43b22
|
[
"Apache-2.0"
] |
permissive
|
pegasus-isi/pegasus
|
578c6d8f2df77a7d43c4b9e2d1edf6687db92040
|
6b7e41d7ebfacca23d853890937e593a248e6a6a
|
refs/heads/master
| 2023-08-02T08:20:18.871762
| 2023-07-20T23:00:08
| 2023-07-20T23:00:08
| 8,016,431
| 156
| 80
|
Apache-2.0
| 2023-06-15T18:55:18
| 2013-02-04T21:18:31
|
Java
|
UTF-8
|
C
| false
| false
| 5,235
|
c
|
pegasus-mpi-hw.c
|
/* MPI hello world */
/* Based on http://www.lam-mpi.org/tutorials/one-step/ezstart.php */
#include <mpi.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define MAXSTR 4096
#define WORKTAG 1
#define DIETAG 2
/* Local functions */
static void usage( char** );
static void master( int );
static void worker( int );
static char* outputFile = NULL;
int main(int argc, char **argv){
int rank;
char buffer[MAXSTR];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if( rank == 0 ){
/* rank 0 is master process */
/* parse command line arguments */
int c;
FILE *fin;
while ((c = getopt(argc, argv, "ho:")) != -1) {
switch (c) {
case 'o':
outputFile = optarg;
break;
default: //similar to h
usage( argv );
break;
}
}
if (optind < argc) {
fprintf( stderr, "[Master] non-option options passed on command line to %s", argv[0]);
while (optind < argc)
fprintf ( stderr, "%s ", argv[optind++]);
fprintf ( stderr, "\n");
return 1;
}
if( outputFile == NULL){
fprintf( stderr, "[Master] output file is a required option\n");
usage( argv );
return 1;
}
fprintf( stdout, "[Master] output file passed on command line %s ", outputFile );
master( rank );
}
else{
worker( rank );
}
//shutdown MPI
MPI_Finalize();
return 0;
}
static void usage( char** argv ){
fprintf( stderr, "Usage: %s [-h] [-o output-file]\n", argv[0]);
}
static void master(int myrank){
int nprocesses, rank;
char result[MAXSTR];
MPI_Status status;
char hostname[256];
char work[MAXSTR];
FILE *output;
gethostname(hostname,255);
/* Find out how many processes there are in the default
communicator */
MPI_Comm_size(MPI_COMM_WORLD, &nprocesses);
fprintf( stdout, "[Master] Total number of MPI processes %d\n", nprocesses);
fprintf( stdout, "[Master] Hello world! I am process number: %d on host %s\n", myrank, hostname);
sprintf( work,"Message from the master\n");
/* Seed the slaves; send one unit of work to each slave. */
for (rank = 1; rank < nprocesses; ++rank) {
/* Find the next item of work to do */
//not sending any work right now.
//just capturing the outputs
//work = get_next_work_item();
/* Send it to each rank */
MPI_Send(&work, /* message buffer */
strlen(work)+1, /* one data item */
MPI_CHAR, /* data item is a string */
rank, /* destination process rank */
WORKTAG, /* user chosen message tag */
MPI_COMM_WORLD); /* default communicator */
}
/* Loop over till we hear back from all the slaves */
output = fopen( outputFile,"w" );
fprintf( output, "[Master] Total number of MPI processes %d\n", nprocesses);
fprintf( output, "[Master] Hello world! I am process number: %d on host %s\n", myrank, hostname);
rank = 1;
while( rank < nprocesses ){
/* Receive results from a slave */
MPI_Recv(&result, /* message buffer */
MAXSTR, /* one data item */
MPI_CHAR, /* of type string */
MPI_ANY_SOURCE, /* receive from any sender */
MPI_ANY_TAG, /* any type of message */
MPI_COMM_WORLD, /* default communicator */
&status); /* info about the received message */
printf( "[Master %d] Received Message from worker\n", myrank);
printf( "[Master] %s\n", result);
/*write to output file*/
fputs ( result, output );
rank++;
}
/* close the output file*/
fclose ( output );
/* There's no more work to be done, so receive all the outstanding
results from the slaves. */
/*
for (rank = 1; rank < ntasks; ++rank) {
MPI_Recv(&result, 1, MPI_DOUBLE, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &status);
}
*/
/* Tell all the slaves to exit by sending an empty message with the
DIETAG. */
printf( "[Master] Sending DIE messages to workers \n");
for (rank = 1; rank < nprocesses; ++rank) {
MPI_Send(0, 0, MPI_CHAR, rank, DIETAG, MPI_COMM_WORLD);
}
}
static void worker(int myrank){
MPI_Status status;
char buffer[MAXSTR];
char work[MAXSTR];
char hostname[255];
gethostname(hostname,255);
//printf( "[Worker] Hello world! I am process number: %d on host %s\n", myrank, hostname);
while (1) {
/* Receive a message from the master */
MPI_Recv(&work, MAXSTR, MPI_CHAR, 0, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
printf( "[Worker %d] Received Message\n", myrank);
/* Check the tag of the received message. */
if (status.MPI_TAG == DIETAG) {
printf( "[Worker %d] Exiting\n", myrank);
return;
}
/* Do the work */
//printf( "[Worker] Hello world! I am process number: %d on host %s\n", myrank, hostname);
sprintf( buffer,"[Worker] Hello world! I am process number: %d on host %s\n", myrank, hostname);
/* Send the result back */
printf( "[Worker %d] Sending Message %s\n", myrank, buffer);
MPI_Send(&buffer, strlen(buffer)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
}
}
|
ef0effb90d669d8ba945727e0309d8148be2b68b
|
f79dec3c4033ca3cbb55d8a51a748cc7b8b6fbab
|
/graphics/kipi-plugins/patches/patch-removeredeyes_plugin_libopencv.h
|
9ae29a7bcf8ba20a00b098c10d01b91dbc87cabd
|
[] |
no_license
|
jsonn/pkgsrc
|
fb34c4a6a2d350e8e415f3c4955d4989fcd86881
|
c1514b5f4a3726d90e30aa16b0c209adbc276d17
|
refs/heads/trunk
| 2021-01-24T09:10:01.038867
| 2017-07-07T15:49:43
| 2017-07-07T15:49:43
| 2,095,004
| 106
| 47
| null | 2016-09-19T09:26:01
| 2011-07-23T23:49:04
|
Makefile
|
UTF-8
|
C
| false
| false
| 1,361
|
h
|
patch-removeredeyes_plugin_libopencv.h
|
$NetBSD: patch-removeredeyes_plugin_libopencv.h,v 1.1 2015/12/12 19:32:45 markd Exp $
opencv3 support. https://bugs.kde.org/show_bug.cgi?id=349601
--- removeredeyes/plugin/libopencv.h.orig 2015-09-03 21:22:45.000000000 +0000
+++ removeredeyes/plugin/libopencv.h
@@ -7,7 +7,7 @@
* @date 2010-06-16
* @brief Wrapper for OpenCV header files
*
- * @author Copyright (C) 2012-2014 by Gilles Caulier
+ * @author Copyright (C) 2012-2015 by Gilles Caulier
* <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
*
* This program is free software; you can redistribute it
@@ -53,12 +53,13 @@
#define OPENCV_MAKE_VERSION(major,minor,patch) (((major) << 16) | ((minor) << 8) | (patch))
#define OPENCV_VERSION OPENCV_MAKE_VERSION(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION)
-#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION >= OPENCV_MAKE_VERSION(major,minor,patch) )
+#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION < OPENCV_MAKE_VERSION(major,minor,patch) )
-#if OPENCV_TEST_VERSION(2,3,0)
+#include <opencv2/core/core_c.h>
+
+#if OPENCV_TEST_VERSION(2,5,0)
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui_c.h>
-#include <opencv2/core/core_c.h>
#include <opencv2/legacy/compat.hpp>
#include <opencv/cvaux.h>
#else
|
4d9018341dc3de4dc7b8d47fb85365a5c6ca917e
|
5fdaec353b93b273d117c5ef1ca7d2352f4bad4b
|
/test/test_libpluto.c
|
c9b7b55b4c332639d3c1a99f81f26f609bceb129
|
[
"MIT"
] |
permissive
|
bondhugula/pluto
|
1ddf0bf53dc8a9c50f895018b2810558441e85f3
|
eddc38537d61cd49d55e454831086848d51473d7
|
refs/heads/master
| 2023-07-21T19:53:05.377621
| 2023-06-21T09:22:57
| 2023-07-15T03:50:17
| 76,021,818
| 242
| 68
|
MIT
| 2023-07-15T03:50:18
| 2016-12-09T09:35:40
|
C
|
UTF-8
|
C
| false
| false
| 9,567
|
c
|
test_libpluto.c
|
/******************************************************************************
* libpluto - A library version of Pluto *
******************************************************************************
* *
* Copyright (C) 2012 Uday Bondhugula *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License version 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* A copy of the GNU Lesser General Public Licence can be found in the file
* `LICENSE.LGPL2' in the top-level directory of this distribution.
*
* This file is part of libpluto.
*
*/
#include "pluto/pluto.h"
#include "isl/union_map.h"
#include "isl/union_set.h"
void run_test_and_cleanup(const char *domains_str, const char *deps_str,
PlutoContext *context, __isl_take isl_ctx *ctx) {
isl_union_set *domains = isl_union_set_read_from_str(ctx, domains_str);
isl_union_map *deps = isl_union_map_read_from_str(ctx, deps_str);
isl_union_map *schedules =
pluto_transform(isl_union_set_copy(domains), deps, NULL, NULL, context);
if (schedules) {
isl_printer *printer = isl_printer_to_file(ctx, stdout);
printer = isl_printer_print_union_map(printer, schedules);
printf("\n");
isl_printer_free(printer);
// Check if the schedule can be applied to the domain.
domains = isl_union_set_apply(domains, schedules);
} else {
printf("No schedule found!\n");
isl_union_map_free(schedules);
}
isl_union_set_free(domains);
// Test remapping.
// TODO: test it properly instead of just checking it doesn't crash.
Remapping remapping;
pluto_get_remapping_str(domains_str, deps_str, context, &remapping);
pluto_remapping_free(remapping);
isl_ctx_free(ctx);
}
// Each test case should name statements S_0, S_1, ...
// CHECK-LABEL: *** TEST CASE 1 ***
// CHECK: T(S1): (i0, 0, 0)
// CHECK: T(S2): (i0, 1, i1)
// CHECK: T(S3): (i0, 2, 0)
void test1(PlutoContext *context) {
printf("\n\n*** TEST CASE 1 ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
"[n] -> {S_1[i0, i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= "
"99; S_0[i0] : i0 >= 0 and i0 <= 99; S_2[i0] : i0 >= 0 and i0 <= 99 "
"}";
const char *deps_str =
"[n] -> {S_1[i0, 99] -> S_0[1 + i0] : i0 >= 0 and i0 <= 98; S_1[i0, "
"i1] -> S_1[i0, 1 + i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 "
"<= 98; S_1[i0, 99] -> S_1[1 + i0, 0] : i0 >= 0 and i0 <= 98; "
"S_0[i0] -> S_1[i0, 0] : i0 >= 0 and i0 <= 99; S_2[i0] -> S_1[1 + "
"i0, 0] : i0 >= 0 and i0 <= 98; S_0[i0] -> S_2[i0] : i0 >= 0 and i0 "
"<= 99; S_1[i0, 99] -> S_2[i0] : i0 >= 0 and i0 <= 99 }";
run_test_and_cleanup(domains_str, deps_str, context, ctx);
}
// CHECK-LABEL: *** TEST CASE 2 ***
// CHECK: T(S1): (i0, 1024i0)
// CHECK: T(S2): (i0, 1024i0+i1)
void test2(PlutoContext *options) {
printf("\n\n*** TEST CASE 2 ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
"[p_0, p_1, p_2, p_3, p_4, p_5, p_7] -> { S_1[i0, i1] : i0 >= 0 and "
"i0 <= p_0 and i1 >= 0 and i1 <= p_3 and p_2 >= 0; S_0[i0] : i0 >= "
"0 and i0 <= p_0}";
const char *deps_str =
"[p_0, p_1, p_2, p_3, p_4, p_5, p_7] -> { S_0[i0] -> S_1[o0, o1] : "
"(exists (e0 = [(p_7)/8]: 8o1 = -p_5 + p_7 + 8192i0 - 8192o0 and "
"8e0 = p_7 and i0 >= 0 and o0 <= p_0 and 8192o0 >= -8p_3 - p_5 + "
"p_7 + 8192i0 and 8192o0 <= -p_5 + p_7 + 8192i0 and p_2 >= 0 and o0 "
">= 1 + i0)); S_1[i0, i1] -> S_0[o0] : (exists (e0 = [(p_1)/8], e1 "
"= [(p_4)/8], e2 = [(-p_1 + p_7)/8184]: 8192o0 = p_5 - p_7 + 8192i0 "
"+ 8i1 and 8e0 = p_1 and 8e1 = p_4 and 8184e2 = -p_1 + p_7 and i1 "
">= 0 and 8i1 <= 8192p_0 - p_5 + p_7 - 8192i0 and 8184i1 >= 1024 + "
"1024p_1 - 1023p_5 - p_7 - 8380416i0 and p_2 >= 0 and p_7 <= -1 + "
"p_5 and 8i1 >= 1 + 8p_3 + p_4 - p_5 - 8192i0 and i1 <= p_3 and i0 "
">= 0 and 8i1 >= 8192 - p_5 + p_7))}";
run_test_and_cleanup(domains_str, deps_str, options, ctx);
}
// CHECK-LABEL: *** TEST CASE 3 ***
// CHECK: T(S1): (i0-i1, i0+i1)
void test_diamond_tiling(PlutoContext *options) {
printf("\n\n*** TEST CASE 3 ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
" [R, T] -> { S_0[i0, i1] : 0 <= i0 <= T and 0 <= i1 <= R - 1; }";
// Dependences (1,-1) and (1,1).
const char *deps_str =
"[R, T] -> {"
"S_0[i0, i1] -> S_0[i0 + 1, i1 - 1] : 0 <= i0 <= T - 1 and 1 <= i1 "
"<= R - 2; "
"S_0[i0, i1] -> S_0[i0 + 1, i1 + 1] : 0 <= i0 <= T - 1 and 1 <= i1 "
"<= R - 2; }";
run_test_and_cleanup(domains_str, deps_str, options, ctx);
}
// CHECK-LABEL: *** TEST CASE 4 ***
// CHECK: T(S1): (i0+i1, i0)
void test4(PlutoContext *context) {
printf("\n\n*** TEST CASE 4 ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
" [R, T] -> { S_0[i0, i1] : 0 <= i0 <= T and 0 < i1 <= R - 1; }";
// Dependence (1, -1)
const char *deps_str = "[R, T] -> {"
"S_0[i0, i1] -> S_0[i0 + 1, i1 - 1] : 1 "
"<= i0 <= T and 1 <= i1 <= R - 2; }";
run_test_and_cleanup(domains_str, deps_str, context, ctx);
}
// CHECK-LABEL: *** TEST CASE 5 ***
// CHECK: T(S1): (i0, i1, 0)
// CHECK: T(S2): (i0+1, i1+1, 1)
void test5(PlutoContext *context) {
printf("\n\n*** TEST CASE 5 ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
" [R, T] -> { S_0[i0, i1] : 0 <= i0 <= T and 0 <= i1 <= R - 1; "
"S_1[i0, i1] : 0 <= i0 <= T and 0 <= i1 <= R - 1; }";
// Inter-statement deps; benefits from shifting.
const char *deps_str =
"[R, T] -> {"
"S_0[i0, i1] -> S_1[i0 - 1, i1 - 1] : 1 <= i0 <= T and 1 <= i1 <= R - 2; "
"}"
"S_0[i0, i1] -> S_1[i0 - 1, i1] : 1 <= i0 <= T and 1 <= i1 <= R - 2; }"
"S_0[i0, i1] -> S_1[i0 - 1, i1 + 1] : 1 <= i0 <= T and 1 <= i1 <= R - 2; "
"}";
run_test_and_cleanup(domains_str, deps_str, context, ctx);
}
// CHECK-LABEL: *** TEST CASE 6
// CHECK: T(S1): (i0, i1+i2, i1)
void test6_diamond_tiling_with_scalar_dimension(PlutoContext *context) {
printf("\n\n*** TEST CASE 6\n\n");
isl_ctx *ctx = isl_ctx_alloc();
const char *domains_str =
" [R, T] -> { S_0[2, i0, i1] : 0 <= i0 <= T and 0 <= i1 <= R - 1;}";
// Dependences (1,-1), (1,0), and (1,1)
const char *deps_str =
"[R, T] -> {"
"S_0[2, i0, i1] -> S_0[2, i0 + 1, i1 - 1] : 1 <= i0 <= T and 1 <= "
"i1 <= R - 2; }"
"S_0[2, i0, i1] -> S_0[2, i0 + 1, i1] : 1 <= i0 <= T and 1 <= i1 <= "
"R - 2; }"
"S_0[2, i0, i1] -> S_0[2, i0 + 1, i1 + 1] : 1 <= i0 <= T and 1 <= "
"i1 <= R - 2; }";
run_test_and_cleanup(domains_str, deps_str, context, ctx);
}
// CHECK-LABEL: *** TEST CASE test_lib_pluto_schedule ***
// CHECK: T(S1): (1, i0, i1, 0)
// CHECK: T(S2): (0, i0, i2, i1)
void test_lib_pluto_schedule(PlutoContext *context) {
printf("\n\n*** TEST CASE test_lib_pluto_schedule ***\n\n");
isl_ctx *ctx = isl_ctx_alloc();
isl_union_map *schedules = isl_union_map_read_from_str(
ctx,
"[p1, p2, p0] -> { S_0[i0, i1] -> [o0, o1, o2, o3] : o0 = 0 and o1 = "
"0 and o2 = i0 and o3 = 0 and i0 >= 0 and i0 < p0 and i1 >= 0 and "
"i1 < p1; S_1[i0, i1, i2] -> [o0, o1, o2, o3] : o0 = 1 and o1 = i0 "
"and o2 = i1 and o3 = i2 and i0 >= 0 and i0 < p1 and i1 >= 0 and i1 "
"< p2 and i2 >= 0 and i2 <= 100 }");
isl_union_map *reads = isl_union_map_read_from_str(
ctx,
"[p1, p2, p0] -> { S_0[i0, i1]->M0[o0, o1] : o0 = i0 and o1 = i1; "
" S_1[i0, i1, i2]->M0[o0, o1] : o0 = i0 and o1 = i2 }");
isl_union_map *writes = isl_union_map_read_from_str(
ctx,
"[p1, p2, p0] -> { S_1[i0, i1, i2]->M1[o0, o1] : o0 = i2 and o1 = i0}");
schedules = pluto_schedule(schedules, reads, writes, context);
if (schedules) {
isl_printer *printer = isl_printer_to_file(ctx, stdout);
printer = isl_printer_print_union_map(printer, schedules);
printf("\n");
isl_printer_free(printer);
}
isl_union_map_free(schedules);
isl_ctx_free(ctx);
}
int main() {
PlutoContext *context = pluto_context_alloc();
PlutoOptions *options = context->options;
options->tile = 1;
options->parallel = 1;
options->debug = 0;
options->moredebug = 0;
options->islsolve = 1;
options->diamondtile = 1;
options->fulldiamondtile = 0;
options->isldepaccesswise = 0;
test1(context);
test2(context);
test_diamond_tiling(context);
test4(context);
test5(context);
test6_diamond_tiling_with_scalar_dimension(context);
options->tile = 0;
options->diamondtile = 0;
options->fulldiamondtile = 0;
options->fuse = kNoFuse;
test_lib_pluto_schedule(context);
pluto_context_free(context);
}
|
3b0179a5305953e68a0460eefe102c2a0a9dfee4
|
0d64a706358a11f0a77716bbe72acce495297957
|
/src/DMXSerial_avr.h
|
73ac5f80ae8aa7899c17bc52619f85517016f2ca
|
[
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause"
] |
permissive
|
mathertel/DMXSerial
|
c6ba41902896dfeeab97b25425819bdba543c6f2
|
46745295694eda720361a18b21ac3d5cba6d872f
|
refs/heads/master
| 2022-12-12T18:29:59.515909
| 2022-12-08T19:12:35
| 2022-12-08T19:12:35
| 15,292,926
| 278
| 78
|
BSD-3-Clause
| 2022-10-25T06:38:27
| 2013-12-18T20:01:17
|
C++
|
UTF-8
|
C
| false
| false
| 8,029
|
h
|
DMXSerial_avr.h
|
// - - - - -
// DMXSerial - A Arduino library for sending and receiving DMX using the builtin serial hardware port.
// DMXSerial_avr.h: Hardware specific functions for AVR processors like ATmega168 and ATmega328 used in Aurduino UNO.
// Also supported boards are Leonardo and Mega2560.
//
// Copyright (c) 2011-2020 by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// - - - - -
// global variables and functions are prefixed with "_DMX_"
// ----- ATMega specific hardware related functions -----
#ifndef DMXSERIAL_AVR_H
#define DMXSERIAL_AVR_H
#if defined(DMXFORMAT) && defined(ARDUINO_ARCH_AVR)
#include "Arduino.h"
#include "DMXSerial.h"
#include "avr/io.h"
#include "avr/interrupt.h"
// ----- Constants -----
// Define port & bit values for Hardware Serial Port.
// The library works unchanged with the Arduino 2009, UNO, MEGA 2560 and Leonardo boards.
// The Arduino MEGA 2560 boards use the serial port 0 on pins 0 an 1.
// The Arduino Leonardo will use serial port 1, also on pins 0 an 1. (on the 32u4 boards the first USART is USART1)
// This is consistent to the Layout of the Arduino DMX Shield http://www.mathertel.de/Arduino/DMXShield.aspx.
// For using the serial port 1 on a Arduino MEGA 2560 board, enable the following DMX_USE_PORT1 definition.
// #define DMX_USE_PORT1
#if !defined(DMX_USE_PORT1) && defined(USART_RXC_vect)
// These definitions are used on ATmega8 boards
#define UCSRnA UCSRA // Control and Status Register A
#define TXCn TXC // Transmit buffer clear
#define RXCn RXC
#define UCSRnB UCSRB // USART Control and Status Register B
#define RXCIEn RXCIE // Enable Receive Complete Interrupt
#define TXCIEn TXCIE // Enable Transmission Complete Interrupt
#define UDRIEn UDRIE // Enable Data Register Empty Interrupt
#define RXENn RXEN // Enable Receiving
#define TXENn TXEN // Enable Sending
#define UCSRnC UCSRC // Control and Status Register C
#define USBSn USBS // Stop bit select 0=1bit, 1=2bits
#define UCSZn0 UCSZ0 // Character size 00=5, 01=6, 10=7, 11=8 bits
#define UPMn0 UPM0 // Parity setting 00=N, 10=E, 11=O
#define UBRRnH UBRRH // USART Baud Rate Register High
#define UBRRnL UBRRL // USART Baud Rate Register Low
#define UDRn UDR // USART Data Register
#define UDREn UDRE // USART Data Ready
#define FEn FE // Frame Error
#define USARTn_RX_vect USART_RXC_vect // Interrupt Data received
#define USARTn_TX_vect USART_TXC_vect // Interrupt Data sent
#define USARTn_UDRE_vect USART_UDRE_vect // Interrupt Data Register empty
#elif !defined(DMX_USE_PORT1) && defined(USART_RX_vect)
// These definitions are used on ATmega168p and ATmega328p boards
// like the Arduino Diecimila, Duemilanove, 2009, Uno
#define UCSRnA UCSR0A
#define RXCn RXC0
#define TXCn TXC0
#define UCSRnB UCSR0B
#define RXCIEn RXCIE0
#define TXCIEn TXCIE0
#define UDRIEn UDRIE0
#define RXENn RXEN0
#define TXENn TXEN0
#define UCSRnC UCSR0C
#define USBSn USBS0
#define UCSZn0 UCSZ00
#define UPMn0 UPM00
#define UBRRnH UBRR0H
#define UBRRnL UBRR0L
#define UDRn UDR0
#define UDREn UDRE0
#define FEn FE0
#define USARTn_RX_vect USART_RX_vect
#define USARTn_TX_vect USART_TX_vect
#define USARTn_UDRE_vect USART_UDRE_vect
#elif !defined(DMX_USE_PORT1) && defined(USART0_RX_vect)
// These definitions are used on ATmega1280 and ATmega2560 boards
// like the Arduino MEGA boards
#define UCSRnA UCSR0A
#define RXCn RXC0
#define TXCn TXC0
#define UCSRnB UCSR0B
#define RXCIEn RXCIE0
#define TXCIEn TXCIE0
#define UDRIEn UDRIE0
#define RXENn RXEN0
#define TXENn TXEN0
#define UCSRnC UCSR0C
#define USBSn USBS0
#define UCSZn0 UCSZ00
#define UPMn0 UPM00
#define UBRRnH UBRR0H
#define UBRRnL UBRR0L
#define UDRn UDR0
#define UDREn UDRE0
#define FEn FE0
#define USARTn_RX_vect USART0_RX_vect
#define USARTn_TX_vect USART0_TX_vect
#define USARTn_UDRE_vect USART0_UDRE_vect
#elif defined(DMX_USE_PORT1) || defined(USART1_RX_vect)
// These definitions are used for using serial port 1
// on ATmega32U4 boards like Arduino Leonardo, Esplora
// You can use it on other boards with USART1 by enabling the DMX_USE_PORT1 port definition
#define UCSRnA UCSR1A
#define RXCn RXC1
#define TXCn TXC1
#define UCSRnB UCSR1B
#define RXCIEn RXCIE1
#define TXCIEn TXCIE1
#define UDRIEn UDRIE1
#define RXENn RXEN1
#define TXENn TXEN1
#define UCSRnC UCSR1C
#define USBSn USBS1
#define UCSZn0 UCSZ10
#define UPMn0 UPM10
#define UBRRnH UBRR1H
#define UBRRnL UBRR1L
#define UDRn UDR1
#define UDREn UDRE1
#define FEn FE1
#define USARTn_RX_vect USART1_RX_vect
#define USARTn_TX_vect USART1_TX_vect
#define USARTn_UDRE_vect USART1_UDRE_vect
#endif
// ----- ATMega specific Hardware abstraction functions -----
// calculate prescaler from baud rate and cpu clock rate at compile time.
// This is a processor specific formula from the datasheet.
// It implements rounding of ((clock / 16) / baud) - 1.
#define CalcPreScale(B) (((((F_CPU) / 8) / (B)) - 1) / 2)
const int32_t _DMX_dmxPreScale = CalcPreScale(DMXSPEED); // BAUD prescale factor for DMX speed.
const int32_t _DMX_breakPreScale = CalcPreScale(BREAKSPEED); // BAUD prescale factor for BREAK speed.
// initialize mode independent registers.
void _DMX_init()
{
// 04.06.2012: use normal speed operation
UCSRnA = 0;
} // _DMX_init()
/// Initialize the Hardware UART serial port registers to the required mode.
void _DMX_setMode(DMXUARTMode mode)
{
if (mode == DMXUARTMode::OFF) {
UCSRnB = 0;
} else if (mode == DMXUARTMode::RONLY) {
// assign the baud_setting to the USART Baud Rate Register
UBRRnH = _DMX_dmxPreScale >> 8;
UBRRnL = _DMX_dmxPreScale;
// enable USART functions RX, TX, Interrupts
UCSRnB = (1 << RXENn);
// stop bits and character size
UCSRnC = DMXREADFORMAT; // accept data packets after first stop bit
} else if (mode == DMXUARTMode::RDATA) {
UBRRnH = _DMX_dmxPreScale >> 8;
UBRRnL = _DMX_dmxPreScale;
UCSRnB = (1 << RXENn) | (1 << RXCIEn);
UCSRnC = DMXREADFORMAT; // accept data packets after first stop bit
} else if (mode == DMXUARTMode::TBREAK) {
UBRRnH = _DMX_breakPreScale >> 8;
UBRRnL = _DMX_breakPreScale;
UCSRnB = ((1 << TXENn) | (1 << TXCIEn));
UCSRnC = BREAKFORMAT;
} else if (mode == DMXUARTMode::TDATA) {
UBRRnH = _DMX_dmxPreScale >> 8;
UBRRnL = _DMX_dmxPreScale;
UCSRnB = ((1 << TXENn) | (1 << UDRIEn));
UCSRnC = DMXFORMAT; // send with 2 stop bits for compatibility
} else if (mode == DMXUARTMode::TDONE) {
UBRRnH = _DMX_dmxPreScale >> 8;
UBRRnL = _DMX_dmxPreScale;
UCSRnB = ((1 << TXENn) | (1 << TXCIEn));
UCSRnC = DMXFORMAT; // send with 2 stop bits for compatibility
} // if
} // _DMX_setMode()
// flush all incoming data packets in the queue
void _DMX_flush()
{
uint8_t voiddata;
while (UCSRnA & (1 << RXCn)) {
voiddata = UDRn; // get data
}
}
// send the next byte after current byte was sent completely.
inline void _DMX_writeByte(uint8_t data)
{
// putting data into buffer sends the data
UDRn = data;
} // _DMX_writeByte
// This Interrupt Service Routine is called when a byte or frame error was received.
// In DMXController mode this interrupt is disabled and will not occur.
// In DMXReceiver mode when a byte or frame error was received
ISR(USARTn_RX_vect)
{
uint8_t rxferr = (UCSRnA & (1 << FEn)); // get state before data!
uint8_t rxdata = UDRn; // get data
_DMXReceived(rxdata, rxferr);
} // ISR(USARTn_RX_vect)
// Interrupt service routines that are called when the actual byte was sent.
ISR(USARTn_TX_vect)
{
_DMXTransmitted();
} // ISR(USARTn_TX_vect)
// this interrupt occurs after data register was emptied by handing it over to the shift register.
ISR(USARTn_UDRE_vect)
{
_DMXTransmitted();
} // ISR(USARTn_UDRE_vect)
#endif
#endif
|
0dcf22c78ac3889d4c4448610fcba97f80539667
|
321d11eaee885ceb3a74db0a062f9bbdf282148c
|
/crypto/pkcs12/p12_crpt.c
|
57d1caecfce7495a8fa6bfa10dc2c765e2658a2d
|
[
"Apache-2.0",
"OpenSSL",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
openssl/openssl
|
75691ebaae957793f2ff0673f77545277dfb3988
|
5318c012885a5382eadbf95aa9c1d35664bca819
|
refs/heads/master
| 2023-09-03T15:22:52.727123
| 2023-09-01T07:10:49
| 2023-09-02T14:30:01
| 7,634,677
| 24,148
| 11,569
|
Apache-2.0
| 2023-09-14T19:48:11
| 2013-01-15T22:34:48
|
C
|
UTF-8
|
C
| false
| false
| 2,793
|
c
|
p12_crpt.c
|
/*
* Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/core.h>
#include <openssl/core_names.h>
#include "crypto/evp.h"
#include <openssl/pkcs12.h>
/* PKCS#12 PBE algorithms now in static table */
void PKCS12_PBE_add(void)
{
}
int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
ASN1_TYPE *param, const EVP_CIPHER *cipher,
const EVP_MD *md, int en_de,
OSSL_LIB_CTX *libctx, const char *propq)
{
PBEPARAM *pbe;
int saltlen, iter, ret;
unsigned char *salt;
unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
unsigned char *piv = iv;
if (cipher == NULL)
return 0;
/* Extract useful info from parameter */
pbe = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBEPARAM), param);
if (pbe == NULL) {
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
return 0;
}
if (pbe->iter == NULL)
iter = 1;
else
iter = ASN1_INTEGER_get(pbe->iter);
salt = pbe->salt->data;
saltlen = pbe->salt->length;
if (!PKCS12_key_gen_utf8_ex(pass, passlen, salt, saltlen, PKCS12_KEY_ID,
iter, EVP_CIPHER_get_key_length(cipher),
key, md,
libctx, propq)) {
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_KEY_GEN_ERROR);
PBEPARAM_free(pbe);
return 0;
}
if (EVP_CIPHER_get_iv_length(cipher) > 0) {
if (!PKCS12_key_gen_utf8_ex(pass, passlen, salt, saltlen, PKCS12_IV_ID,
iter, EVP_CIPHER_get_iv_length(cipher),
iv, md,
libctx, propq)) {
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_IV_GEN_ERROR);
PBEPARAM_free(pbe);
return 0;
}
} else {
piv = NULL;
}
PBEPARAM_free(pbe);
ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, piv, en_de);
OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
return ret;
}
int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
ASN1_TYPE *param, const EVP_CIPHER *cipher,
const EVP_MD *md, int en_de)
{
return PKCS12_PBE_keyivgen_ex(ctx, pass, passlen, param, cipher, md, en_de,
NULL, NULL);
}
|
a74f4a0b17afab93bf9024ee8b44d68f9e2e8393
|
7ddfde60100403b1f1daeb4eb4235bed925f3f2e
|
/public/minmax.h
|
c302e4cd46201cdcf77a97093fcff43ef7a29ece
|
[] |
no_license
|
alliedmodders/hl2sdk
|
12de11a05a3a1cb459857eb918d55fce09e964e9
|
78dab58646d5983c77af44c45a877b89196eb82c
|
refs/heads/sdk2013
| 2023-08-13T10:27:55.916450
| 2022-10-15T13:53:52
| 2022-10-15T13:53:52
| 20,148,756
| 307
| 205
| null | 2023-08-15T08:09:50
| 2014-05-25T07:03:22
|
C++
|
UTF-8
|
C
| false
| false
| 403
|
h
|
minmax.h
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef MINMAX_H
#define MINMAX_H
#ifndef V_min
#define V_min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef V_max
#define V_max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#endif // MINMAX_H
|
4b5dc6f14dda82eef6b9c6e229f8d04da5640ba3
|
9977559fe42d71542876bbeffa829a8fe44a2d44
|
/Meiqia-SDK-files/MQChatViewController/Vendors/MLAudioRecorder/AMR_Debug.h
|
4c0826cc74a0e10ec95a8e07da7bd5af90fdc450
|
[
"MIT"
] |
permissive
|
Meiqia/MeiqiaSDK-iOS
|
5211df8c03e13a47185a4fffc5e4f2fb491ed8f8
|
a189c668ac6c3bad81f6144609d609c026d7f5f9
|
refs/heads/master
| 2023-06-07T19:07:38.392229
| 2023-06-06T06:12:15
| 2023-06-06T06:12:15
| 47,674,876
| 126
| 99
|
MIT
| 2023-03-21T06:21:14
| 2015-12-09T07:08:36
|
Objective-C
|
UTF-8
|
C
| false
| false
| 1,432
|
h
|
AMR_Debug.h
|
//
// Debug.h
// MolonFrame
//
// Created by Molon on 13-10-4.
// Copyright (c) 2013年 Molon. All rights reserved.
//
#ifndef MolonFrame_Debug_h
#define MolonFrame_Debug_h
#ifdef DEBUG
#define DLOG(format, ...) \
NSLog(@"\n%s:%d\n%@", \
__PRETTY_FUNCTION__, __LINE__, \
[NSString stringWithFormat:format, ## __VA_ARGS__])
#define _po(o) DLOG(@"%@", (o))
#define _pn(o) DLOG(@"%d", (o))
#define _pf(o) DLOG(@"%f", (o))
#define _ps(o) DLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height)
#define _pr(o) DLOG(@"NSRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.y, (o).size.width, (o).size.height)
#define DOBJ(obj) DLOG(@"%s: %@", #obj, [(obj) description])
#define MARK NSLog(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)
#define START_TIMER \
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) \
DLOG([NSString stringWithFormat:"%@ Time = %f", msg, \
[NSDate timeIntervalSinceReferenceDate]-start]);
#else
#define DLOG
#define _po
#define _pn
#define _pf
#define _ps
#define _pr
#define DOBJ
#define MARK
#define START_TIMER
#define END_TIMER
#endif
#ifdef DEBUG
#define LOG(...) NSLog(__VA_ARGS__)
#define LOG_METHOD \
NSLog(@"\nLine:%d\nFunction:%s\n", __LINE__, __FUNCTION__)
#else
#define LOG(...)
#define LOG_METHOD
#endif
#endif
|
ad8d00231b9d720a53751673df2ed6db80e9cdbf
|
f54021ed2b6bb09a18b2bd6331b01fdfacba4f08
|
/samples/theories.c
|
2649dcbaf611e67d4d5fb944db019e9cbcd3d41e
|
[
"MIT"
] |
permissive
|
Snaipe/Criterion
|
e13784611d4f024114759c81db7978a34158a571
|
9c01cbe75002ad8640e0f411f453fbcd0567ff79
|
refs/heads/bleeding
| 2023-09-01T14:38:14.824224
| 2023-05-13T15:44:26
| 2023-05-13T16:02:30
| 30,111,969
| 1,965
| 240
|
MIT
| 2023-04-29T11:26:11
| 2015-01-31T12:45:39
|
C
|
UTF-8
|
C
| false
| false
| 2,722
|
c
|
theories.c
|
#ifdef _MSC_VER
# pragma warning(disable : 4090)
#endif
#include <criterion/theories.h>
#include <limits.h>
#define INT_DATAPOINTS DataPoints(int, 0, 1, 2, -1, -2, INT_MAX, INT_MIN)
/* Let's test the multiplicative properties of 32-bit integers: */
int bad_mul(int a, int b)
{
return a * b;
}
int bad_div(int a, int b)
{
return a / b;
}
TheoryDataPoints(algebra, bad_divide_is_inverse_of_multiply) = {
INT_DATAPOINTS,
INT_DATAPOINTS,
};
Theory((int a, int b), algebra, bad_divide_is_inverse_of_multiply) {
cr_assume(b != 0);
cr_assume(a != INT_MIN || b != -1);
cr_assert_eq(a, bad_div(bad_mul(a, b), b));
}
/* The above implementation of mul & div fails the test because of overflows,
let's try again: */
long long good_mul(long long a, long long b)
{
return a * b;
}
long long good_div(long long a, long long b)
{
return a / b;
}
TheoryDataPoints(algebra, good_divide_is_inverse_of_multiply) = {
INT_DATAPOINTS,
INT_DATAPOINTS,
};
Theory((int a, int b), algebra, good_divide_is_inverse_of_multiply) {
cr_assume(b != 0);
cr_assume(a != INT_MIN || b != -1);
cr_assert_eq(a, good_div(good_mul(a, b), b));
}
/* For triangulation */
Test(algebra, multiplication_by_integer) {
cr_assert_eq(10, good_mul(5, 2));
}
/* Another property test */
TheoryDataPoints(algebra, zero_is_absorbing) = {
INT_DATAPOINTS,
INT_DATAPOINTS,
};
Theory((int a, int b), algebra, zero_is_absorbing) {
cr_assume(a == 0 || b == 0);
cr_assert_eq(0, good_mul(a, b));
}
/* Testing for various parameters */
struct my_object {
int foo;
};
TheoryDataPoints(theory, misc) = {
DataPoints(char, 'a'),
DataPoints(bool, true),
DataPoints(short, 1),
DataPoints(int, 1),
DataPoints(long, 1),
DataPoints(long long, 1),
DataPoints(float, 3.14f),
DataPoints(double, 3.14),
DataPoints(char *, "test"),
DataPoints(const char *, "other test"),
DataPoints(struct my_object *, & (struct my_object) { 42 }),
};
Theory((char c, bool b, short s, int i, long l, long long ll, float f, double d, char *str, const char *cstr, struct my_object *obj), theory, misc) {
float reff = 3.14f;
double refd = 3.14;
cr_assert(b);
cr_assert_eq(c, 'a');
cr_assert_eq(s, 1);
cr_assert_eq(i, 1);
cr_assert_eq(l, 1);
cr_assert_eq(ll, 1);
cr_assert_eq(f, reff);
cr_assert_eq(d, refd);
cr_assert_str_eq(str, "test");
cr_assert_str_eq(cstr, "other test");
cr_assert_eq(obj->foo, 42);
/* abort to see the formatted string of all parameters */
cr_assert_fail();
}
|
7f38e5d3f52b6a2c6bf77e00f48bd181c1463c4f
|
984bc4181baec6e5a4b05a657e666b0e9f89f3f3
|
/3rdparty/mongo-c-driver-1.21.2/src/libmongoc/tests/test-mongoc-retryable-reads.c
|
57c2d657208ea4a3bd689c95166e8e07165daa37
|
[
"BSD-3-Clause",
"Apache-2.0"
] |
permissive
|
treefrogframework/treefrog-framework
|
0173245ff92162d2107af79861505981980d1eca
|
a1df97793e8cc628779378e5adae9af6987460c1
|
refs/heads/master
| 2023-08-22T03:57:58.891846
| 2023-05-18T14:00:42
| 2023-05-18T14:00:42
| 7,067,532
| 1,152
| 263
|
BSD-3-Clause
| 2023-08-08T20:25:03
| 2012-12-08T13:17:01
|
C++
|
UTF-8
|
C
| false
| false
| 11,146
|
c
|
test-mongoc-retryable-reads.c
|
#include <mongoc/mongoc.h>
#include "mongoc/mongoc-collection-private.h"
#include "json-test.h"
#include "test-libmongoc.h"
#include "mock_server/mock-rs.h"
#include "mock_server/future.h"
#include "mock_server/future-functions.h"
#include "json-test-operations.h"
static bool
retryable_reads_test_run_operation (json_test_ctx_t *ctx,
const bson_t *test,
const bson_t *operation)
{
bool *explicit_session = (bool *) ctx->config->ctx;
bson_t reply;
bson_iter_t iter;
const char *op_name;
uint32_t op_len;
bool res;
bson_iter_init_find (&iter, operation, "name");
op_name = bson_iter_utf8 (&iter, &op_len);
if (strcmp (op_name, "estimatedDocumentCount") == 0 ||
strcmp (op_name, "count") == 0) {
/* CDRIVER-3612: mongoc_collection_estimated_document_count does not
* support explicit sessions */
*explicit_session = false;
}
res = json_test_operation (ctx,
test,
operation,
ctx->collection,
*explicit_session ? ctx->sessions[0] : NULL,
&reply);
bson_destroy (&reply);
return res;
}
/* Callback for JSON tests from Retryable Reads Spec */
static void
test_retryable_reads_cb (bson_t *scenario)
{
bool explicit_session;
json_test_config_t config = JSON_TEST_CONFIG_INIT;
/* use the context pointer to send "explicit_session" to the callback */
config.ctx = &explicit_session;
config.run_operation_cb = retryable_reads_test_run_operation;
config.scenario = scenario;
config.command_started_events_only = true;
explicit_session = true;
run_json_general_test (&config);
explicit_session = false;
run_json_general_test (&config);
}
static void
_set_failpoint (mongoc_client_t *client)
{
bson_error_t error;
bson_t *cmd =
tmp_bson ("{'configureFailPoint': 'failCommand',"
" 'mode': {'times': 1},"
" 'data': {'errorCode': 10107, 'failCommands': ['count']}}");
ASSERT_OR_PRINT (
mongoc_client_command_simple (client, "admin", cmd, NULL, NULL, &error),
error);
}
/* Test code paths for all command helpers */
static void
test_cmd_helpers (void *ctx)
{
mongoc_uri_t *uri;
mongoc_client_t *client;
uint32_t server_id;
mongoc_collection_t *collection;
bson_t *cmd;
bson_t reply;
bson_error_t error;
bson_iter_t iter;
mongoc_cursor_t *cursor;
mongoc_database_t *database;
const bson_t *doc;
uri = test_framework_get_uri ();
mongoc_uri_set_option_as_bool (uri, "retryReads", true);
client = test_framework_client_new_from_uri (uri, NULL);
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);
test_framework_set_ssl_opts (client);
mongoc_uri_destroy (uri);
/* clean up in case a previous test aborted */
server_id = mongoc_topology_select_server_id (
client->topology, MONGOC_SS_WRITE, NULL, NULL, &error);
ASSERT_OR_PRINT (server_id, error);
deactivate_fail_points (client, server_id);
collection = get_test_collection (client, "retryable_reads");
database = mongoc_client_get_database (client, "test");
if (!mongoc_collection_drop (collection, &error)) {
if (NULL == strstr (error.message, "ns not found")) {
/* an error besides ns not found */
ASSERT_OR_PRINT (false, error);
}
}
ASSERT_OR_PRINT (mongoc_collection_insert_one (
collection, tmp_bson ("{'_id': 0}"), NULL, NULL, &error),
error);
ASSERT_OR_PRINT (mongoc_collection_insert_one (
collection, tmp_bson ("{'_id': 1}"), NULL, NULL, &error),
error);
cmd = tmp_bson ("{'count': '%s'}", collection->collection);
/* read helpers must retry. */
_set_failpoint (client);
ASSERT_OR_PRINT (mongoc_client_read_command_with_opts (
client, "test", cmd, NULL, NULL, &reply, &error),
error);
bson_iter_init_find (&iter, &reply, "n");
ASSERT (bson_iter_as_int64 (&iter) == 2);
bson_destroy (&reply);
_set_failpoint (client);
ASSERT_OR_PRINT (mongoc_database_read_command_with_opts (
database, cmd, NULL, NULL, &reply, &error),
error);
bson_iter_init_find (&iter, &reply, "n");
ASSERT (bson_iter_as_int64 (&iter) == 2);
bson_destroy (&reply);
_set_failpoint (client);
ASSERT_OR_PRINT (mongoc_collection_read_command_with_opts (
collection, cmd, NULL, NULL, &reply, &error),
error);
bson_iter_init_find (&iter, &reply, "n");
ASSERT (bson_iter_as_int64 (&iter) == 2);
bson_destroy (&reply);
/* TODO: once CDRIVER-3314 is resolved, test the read+write helpers. */
/* read/write agnostic command_simple helpers must not retry. */
_set_failpoint (client);
ASSERT (
!mongoc_client_command_simple (client, "test", cmd, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
_set_failpoint (client);
ASSERT (!mongoc_database_command_simple (database, cmd, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
_set_failpoint (client);
ASSERT (
!mongoc_collection_command_simple (collection, cmd, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
/* read/write agnostic command_with_opts helpers must not retry. */
_set_failpoint (client);
ASSERT (!mongoc_client_command_with_opts (
client, "test", cmd, NULL, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
_set_failpoint (client);
ASSERT (!mongoc_database_command_with_opts (
database, cmd, NULL, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
_set_failpoint (client);
ASSERT (!mongoc_collection_command_with_opts (
collection, cmd, NULL, NULL, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
/* read/write agnostic command_simple_with_server_id helper must not retry.
*/
server_id = mongoc_topology_select_server_id (
client->topology, MONGOC_SS_WRITE, NULL, NULL, &error);
ASSERT_OR_PRINT (server_id, error);
_set_failpoint (client);
ASSERT (!mongoc_client_command_simple_with_server_id (
client, "test", cmd, NULL, server_id, NULL, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
/* deprecated command helpers (which goes through cursor logic) function must
* not retry. */
_set_failpoint (client);
cursor = mongoc_client_command (
client, "test", MONGOC_QUERY_NONE, 0, 1, 1, cmd, NULL, NULL);
ASSERT (!mongoc_cursor_next (cursor, &doc));
ASSERT (mongoc_cursor_error (cursor, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
mongoc_cursor_destroy (cursor);
_set_failpoint (client);
cursor = mongoc_database_command (
database, MONGOC_QUERY_NONE, 0, 1, 1, cmd, NULL, NULL);
ASSERT (!mongoc_cursor_next (cursor, &doc));
ASSERT (mongoc_cursor_error (cursor, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
mongoc_cursor_destroy (cursor);
_set_failpoint (client);
cursor = mongoc_collection_command (
collection, MONGOC_QUERY_NONE, 0, 1, 1, cmd, NULL, NULL);
ASSERT (!mongoc_cursor_next (cursor, &doc));
ASSERT (mongoc_cursor_error (cursor, &error));
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 10107, "Failing command");
mongoc_cursor_destroy (cursor);
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
deactivate_fail_points (client, server_id);
mongoc_collection_destroy (collection);
mongoc_database_destroy (database);
mongoc_client_destroy (client);
}
static void
test_retry_reads_off (void *ctx)
{
mongoc_uri_t *uri;
mongoc_client_t *client;
mongoc_collection_t *collection;
uint32_t server_id;
bson_t *cmd;
bson_error_t error;
bool res;
uri = test_framework_get_uri ();
mongoc_uri_set_option_as_bool (uri, "retryreads", false);
client = test_framework_client_new_from_uri (uri, NULL);
test_framework_set_ssl_opts (client);
/* clean up in case a previous test aborted */
server_id = mongoc_topology_select_server_id (
client->topology, MONGOC_SS_WRITE, NULL, NULL, &error);
ASSERT_OR_PRINT (server_id, error);
deactivate_fail_points (client, server_id);
collection = get_test_collection (client, "retryable_reads");
cmd = tmp_bson ("{'configureFailPoint': 'failCommand',"
" 'mode': {'times': 1},"
" 'data': {'errorCode': 10107, 'failCommands': ['count']}}");
ASSERT_OR_PRINT (mongoc_client_command_simple_with_server_id (
client, "admin", cmd, NULL, server_id, NULL, &error),
error);
cmd = tmp_bson ("{'count': 'coll'}", collection->collection);
res = mongoc_collection_read_command_with_opts (
collection, cmd, NULL, NULL, NULL, &error);
ASSERT (!res);
ASSERT_CONTAINS (error.message, "failpoint");
deactivate_fail_points (client, server_id);
mongoc_collection_destroy (collection);
mongoc_uri_destroy (uri);
mongoc_client_destroy (client);
}
/*
*-----------------------------------------------------------------------
*
* Runner for the JSON tests for retryable reads.
*
*-----------------------------------------------------------------------
*/
static void
test_all_spec_tests (TestSuite *suite)
{
install_json_test_suite_with_check (suite,
JSON_DIR,
"retryable_reads",
test_retryable_reads_cb,
TestSuite_CheckLive,
test_framework_skip_if_no_failpoint,
test_framework_skip_if_slow);
}
void
test_retryable_reads_install (TestSuite *suite)
{
test_all_spec_tests (suite);
/* Since we need failpoints, require wire version 7 */
TestSuite_AddFull (suite,
"/retryable_reads/cmd_helpers",
test_cmd_helpers,
NULL,
NULL,
test_framework_skip_if_max_wire_version_less_than_7,
test_framework_skip_if_mongos,
test_framework_skip_if_no_failpoint);
TestSuite_AddFull (suite,
"/retryable_reads/retry_off",
test_retry_reads_off,
NULL,
NULL,
test_framework_skip_if_max_wire_version_less_than_7,
test_framework_skip_if_mongos,
test_framework_skip_if_no_failpoint);
}
|
0ebe7f8adbfeec9e14f71e321d6497d5bfb37b5c
|
c9bc99866cfab223c777cfb741083be3e9439d81
|
/module/cmn650/src/cmn650_ccix.h
|
1d429ef912741789dcbdf3f00ff554b5c25bb682
|
[
"BSD-3-Clause"
] |
permissive
|
ARM-software/SCP-firmware
|
4738ca86ce42d82588ddafc2226a1f353ff2c797
|
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
|
refs/heads/master
| 2023-09-01T16:13:36.962036
| 2023-08-17T13:00:20
| 2023-08-31T07:43:37
| 134,399,880
| 211
| 165
|
NOASSERTION
| 2023-09-13T14:27:10
| 2018-05-22T10:35:56
|
C
|
UTF-8
|
C
| false
| false
| 3,823
|
h
|
cmn650_ccix.h
|
/*
* Arm SCP/MCP Software
* Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Description:
* CMN-650 CCIX Configuration Interface
*/
#ifndef CMN650_CCIX_H
#define CMN650_CCIX_H
#include <internal/cmn650_ctx.h>
#include <mod_cmn650.h>
int ccix_setup(
const unsigned int chip_id,
struct cmn650_device_ctx *ctx,
const struct mod_cmn650_ccix_config *ccix_config);
int ccix_exchange_protocol_credit(
struct cmn650_device_ctx *ctx,
const struct mod_cmn650_ccix_config *ccix_config);
int ccix_enter_system_coherency(
struct cmn650_device_ctx *ctx,
const struct mod_cmn650_ccix_config *ccix_config);
int ccix_enter_dvm_domain(
struct cmn650_device_ctx *ctx,
const struct mod_cmn650_ccix_config *ccix_config);
/*
* CCIX Link UP stages
*/
enum cxg_link_up_wait_cond {
CXG_LINK_CTRL_EN_BIT_SET,
CXG_LINK_CTRL_UP_BIT_CLR,
CXG_LINK_STATUS_DWN_BIT_SET,
CXG_LINK_STATUS_DWN_BIT_CLR,
CXG_LINK_STATUS_ACK_BIT_SET,
CXG_LINK_STATUS_ACK_BIT_CLR,
CXG_LINK_STATUS_HA_DVMDOMAIN_ACK_BIT_SET,
CXG_LINK_STATUS_RA_DVMDOMAIN_ACK_BIT_SET,
CXG_LINK_UP_SEQ_COUNT,
};
/*
* Structure defining data to be passed to timer API
*/
struct cxg_wait_condition_data {
struct cmn650_device_ctx *ctx;
uint8_t linkid;
enum cxg_link_up_wait_cond cond;
};
/* CCIX Gateway (CXG) Home Agent (HA) defines */
#define CXG_HA_RAID_TO_LDID_RNF_MASK (0x80)
#define CXLA_CCIX_PROP_MAX_PACK_SIZE_MASK UINT64_C(0x0000000000000380)
#define CXLA_CCIX_PROP_MAX_PACK_SIZE_SHIFT_VAL 7
#define CXLA_CCIX_PROP_MAX_PACK_SIZE_128 0
#define CXLA_CCIX_PROP_MAX_PACK_SIZE_256 1
#define CXLA_CCIX_PROP_MAX_PACK_SIZE_512 2
/* CCIX Gateway (CXG) link control & status defines */
#define CXG_LINK_CTRL_EN_MASK UINT64_C(0x0000000000000001)
#define CXG_LINK_CTRL_REQ_MASK UINT64_C(0x0000000000000002)
#define CXG_LINK_CTRL_UP_MASK UINT64_C(0x0000000000000004)
#define CXG_LINK_CTRL_DVMDOMAIN_REQ_MASK UINT64_C(0x0000000000000008)
#define CXG_LINK_STATUS_ACK_MASK UINT64_C(0x0000000000000001)
#define CXG_LINK_STATUS_DOWN_MASK UINT64_C(0x0000000000000002)
#define CXG_LINK_STATUS_DVMDOMAIN_ACK_MASK UINT64_C(0x0000000000000004)
#define CXG_PRTCL_LINK_CTRL_TIMEOUT UINT32_C(100)
#define CXG_PRTCL_LINK_DVMDOMAIN_TIMEOUT UINT32_C(100)
/* SMP Mode related defines */
#define CXG_RA_AUX_CTRL_SMP_MODE_EN_SHIFT_VAL 16
#define CXG_HA_AUX_CTRL_SMP_MODE_EN_SHIFT_VAL 16
#define CXLA_AUX_CTRL_SMP_MODE_EN_SHIFT_VAL 47
#define HNF_RN_PHYS_RN_ID_VALID_SHIFT_VAL 31
#define HNF_RN_PHYS_RN_LOCAL_REMOTE_SHIFT_VAL 16
#define NUM_BITS_RESERVED_FOR_RAID 8
#define NUM_BITS_RESERVED_FOR_LINKID 8
#define NUM_BITS_RESERVED_FOR_LDID 8
#define NUM_BITS_RESERVED_FOR_PHYS_ID 32
#define LOCAL_CCIX_NODE 0
#define REMOTE_CCIX_NODE 1
#define SAM_ADDR_TARGET_HAID_SHIFT (52)
#define SAM_ADDR_REG_VALID_MASK UINT64_C(0x8000000000000000)
/*
* Used by RNSAM and HNSAM CPA registers
*
* CPA - CCIX Port Aggregation
* PAG - Port Aggregation Group
* GRPID - Group ID
*/
#define HNF_RN_PHYS_CPA_GRP_RA_SHIFT_VAL 17
#define HNF_RN_PHYS_CPA_EN_RA_SHIFT_VAL 30
#define CML_PORT_AGGR_MODE_CTRL_REGIONS_PER_GROUP 9
#define CML_PORT_AGGR_MODE_CTRL_PAG_WIDTH_PER_REGION 6
#define CML_PORT_AGGR_MODE_CTRL_PAG_GRPID_OFFSET 1
#define CML_PORT_AGGR_CTRL_NUM_CXG_PAG_WIDTH 12
#define CMN_PORT_AGGR_GRP_PAG_TGTID_PER_GROUP 5
#define CMN_PORT_AGGR_GRP_PAG_TGTID_WIDTH 12
#define CMN_PORT_AGGR_GRP_PAG_TGTID_WIDTH_PER_GROUP 60
#define NUM_PORTS_PER_CPA_GROUP 2
#endif /* CMN650_CCIX_H */
|
0213697be9615394e7d19880dd6ccf578195e43e
|
fbe68d84e97262d6d26dd65c704a7b50af2b3943
|
/third_party/virtualbox/src/VBox/Devices/Graphics/shaderlib/libWineStub/include/wine/port.h
|
f0dab5816a8a7f53e9debbe42c3a202be99000ae
|
[
"GPL-2.0-only",
"LicenseRef-scancode-unknown-license-reference",
"CDDL-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-1.0-or-later",
"LGPL-2.1-or-later",
"GPL-2.0-or-later",
"MPL-1.0",
"LicenseRef-scancode-generic-exception",
"Apache-2.0",
"OpenSSL",
"MIT"
] |
permissive
|
thalium/icebox
|
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
|
6f78952d58da52ea4f0e55b2ab297f28e80c1160
|
refs/heads/master
| 2022-08-14T00:19:36.984579
| 2022-02-22T13:10:31
| 2022-02-22T13:10:31
| 190,019,914
| 585
| 109
|
MIT
| 2022-01-13T20:58:15
| 2019-06-03T14:18:12
|
C++
|
UTF-8
|
C
| false
| false
| 13,536
|
h
|
port.h
|
/*
* Wine porting definitions
*
* Copyright 1996 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#ifndef __WINE_WINE_PORT_H
#define __WINE_WINE_PORT_H
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif
#ifdef __WINE_BASETSD_H
# error You must include port.h before all other headers
#endif
#define _GNU_SOURCE /* for pread/pwrite */
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_DIRECT_H
# include <direct.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#ifdef HAVE_PROCESS_H
# include <process.h>
#endif
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
/* Can't use windef.h here, cause it'd cause problems with NONAMELESSUNION/STRUCT later */
#ifndef inline
#define inline
#endif
/****************************************************************
* Type definitions
*/
#if !defined(_MSC_VER) && !defined(__int64)
# if defined(__x86_64__) || defined(_WIN64)
# define __int64 long
# else
# define __int64 long long
# endif
#endif
#ifndef HAVE_MODE_T
typedef int mode_t;
#endif
#ifndef HAVE_OFF_T
typedef long off_t;
#endif
#ifndef HAVE_PID_T
typedef int pid_t;
#endif
#ifndef HAVE_SIZE_T
typedef unsigned int size_t;
#endif
#ifndef HAVE_SSIZE_T
typedef int ssize_t;
#endif
#ifndef HAVE_FSBLKCNT_T
typedef unsigned long fsblkcnt_t;
#endif
#ifndef HAVE_FSFILCNT_T
typedef unsigned long fsfilcnt_t;
#endif
#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
struct statvfs
{
unsigned long f_bsize;
unsigned long f_frsize;
fsblkcnt_t f_blocks;
fsblkcnt_t f_bfree;
fsblkcnt_t f_bavail;
fsfilcnt_t f_files;
fsfilcnt_t f_ffree;
fsfilcnt_t f_favail;
unsigned long f_fsid;
unsigned long f_flag;
unsigned long f_namemax;
};
#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
/****************************************************************
* Macro definitions
*/
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#define RTLD_LAZY 0x001
#define RTLD_NOW 0x002
#define RTLD_GLOBAL 0x100
#endif
#ifdef HAVE_ONE_ARG_MKDIR
#define mkdir(path,mode) mkdir(path)
#endif
#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
#define ftruncate chsize
#endif
#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
#define popen _popen
#endif
#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
#define pclose _pclose
#endif
#if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
#define strdup _strdup
#endif
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
#define snprintf _snprintf
#endif
#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
#define vsnprintf _vsnprintf
#endif
#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
#define strtoll _strtoi64
#endif
#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
#define strtoull _strtoui64
#endif
#ifndef S_ISLNK
# define S_ISLNK(mod) (0)
#endif
#ifndef S_ISSOCK
# define S_ISSOCK(mod) (0)
#endif
#ifndef S_ISDIR
# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
#endif
#ifndef S_ISCHR
# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
#endif
#ifndef S_ISFIFO
# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
#endif
#ifndef S_ISREG
# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
#endif
/* So we open files in 64 bit access mode on Linux */
#ifndef O_LARGEFILE
# define O_LARGEFILE 0
#endif
#ifndef O_NONBLOCK
# define O_NONBLOCK 0
#endif
#ifndef O_BINARY
# define O_BINARY 0
#endif
/****************************************************************
* Constants
*/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2
#define M_PI_2 1.570796326794896619
#endif
/****************************************************************
* Function definitions (only when using libwine_port)
*/
#ifndef NO_LIBWINE_PORT
#ifndef HAVE_FSTATVFS
int fstatvfs( int fd, struct statvfs *buf );
#endif
#ifndef HAVE_GETOPT_LONG
extern char *optarg;
extern int optind;
extern int opterr;
extern int optopt;
struct option;
#ifndef HAVE_STRUCT_OPTION_NAME
struct option
{
const char *name;
int has_arg;
int *flag;
int val;
};
#endif
extern int getopt_long (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
extern int getopt_long_only (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
#endif /* HAVE_GETOPT_LONG */
#ifndef HAVE_FFS
int ffs( int x );
#endif
#ifndef HAVE_FUTIMES
struct timeval;
int futimes(int fd, const struct timeval *tv);
#endif
#ifndef HAVE_GETPAGESIZE
size_t getpagesize(void);
#endif /* HAVE_GETPAGESIZE */
#ifndef HAVE_GETTID
pid_t gettid(void);
#endif /* HAVE_GETTID */
#ifndef HAVE_ISINF
# undef isinf /* VBox: _MSC_VER >= RT_MSC_VER_VC120 has complicated macro implementation in math.h */
int isinf(double x);
#endif
#ifndef HAVE_ISNAN
# undef isnan /* VBox: _MSC_VER >= RT_MSC_VER_VC120 has complicated macro implementation in math.h */
int isnan(double x);
#endif
#ifndef HAVE_LSTAT
int lstat(const char *file_name, struct stat *buf);
#endif /* HAVE_LSTAT */
#ifndef HAVE_MEMMOVE
void *memmove(void *dest, const void *src, size_t len);
#endif /* !defined(HAVE_MEMMOVE) */
#ifndef HAVE_POLL
struct pollfd
{
int fd;
short events;
short revents;
};
#define POLLIN 0x01
#define POLLPRI 0x02
#define POLLOUT 0x04
#define POLLERR 0x08
#define POLLHUP 0x10
#define POLLNVAL 0x20
int poll( struct pollfd *fds, unsigned int count, int timeout );
#endif /* HAVE_POLL */
#ifndef HAVE_PREAD
ssize_t pread( int fd, void *buf, size_t count, off_t offset );
#endif /* HAVE_PREAD */
#ifndef HAVE_PWRITE
ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
#endif /* HAVE_PWRITE */
#ifndef HAVE_READLINK
int readlink( const char *path, char *buf, size_t size );
#endif /* HAVE_READLINK */
#ifndef HAVE_STATVFS
int statvfs( const char *path, struct statvfs *buf );
#endif
#ifndef HAVE_STRNCASECMP
# ifndef HAVE__STRNICMP
int strncasecmp(const char *str1, const char *str2, size_t n);
# else
# define strncasecmp _strnicmp
# endif
#endif /* !defined(HAVE_STRNCASECMP) */
#ifndef HAVE_STRERROR
const char *strerror(int err);
#endif /* !defined(HAVE_STRERROR) */
#ifndef HAVE_STRCASECMP
# ifndef HAVE__STRICMP
int strcasecmp(const char *str1, const char *str2);
# else
# define strcasecmp _stricmp
# endif
#endif /* !defined(HAVE_STRCASECMP) */
#ifndef HAVE_SYMLINK
int symlink(const char *from, const char *to);
#endif
#ifndef HAVE_USLEEP
int usleep (unsigned int useconds);
#endif /* !defined(HAVE_USLEEP) */
#ifdef __i386__
static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
{
return memcpy( dst, src, size );
}
#else
extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
#endif /* __i386__ */
extern int mkstemps(char *template, int suffix_len);
/* Process creation flags */
#ifndef _P_WAIT
# define _P_WAIT 0
# define _P_NOWAIT 1
# define _P_OVERLAY 2
# define _P_NOWAITO 3
# define _P_DETACH 4
#endif
#ifndef HAVE_SPAWNVP
extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
#endif
/* Interlocked functions */
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
extern inline int interlocked_xchg( int *dest, int val );
extern inline void *interlocked_xchg_ptr( void **dest, void *val );
extern inline int interlocked_xchg_add( int *dest, int incr );
extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
{
int ret;
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
return ret;
}
extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
{
void *ret;
#ifdef __x86_64__
__asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
#else
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
#endif
return ret;
}
extern inline int interlocked_xchg( int *dest, int val )
{
int ret;
__asm__ __volatile__( "lock; xchgl %0,(%1)"
: "=r" (ret) : "r" (dest), "0" (val) : "memory" );
return ret;
}
extern inline void *interlocked_xchg_ptr( void **dest, void *val )
{
void *ret;
#ifdef __x86_64__
__asm__ __volatile__( "lock; xchgq %0,(%1)"
: "=r" (ret) :"r" (dest), "0" (val) : "memory" );
#else
__asm__ __volatile__( "lock; xchgl %0,(%1)"
: "=r" (ret) : "r" (dest), "0" (val) : "memory" );
#endif
return ret;
}
extern inline int interlocked_xchg_add( int *dest, int incr )
{
int ret;
__asm__ __volatile__( "lock; xaddl %0,(%1)"
: "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
return ret;
}
#ifdef __x86_64__
extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare );
extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare )
{
unsigned char ret;
__asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
: "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
"=a" (compare[0]), "=d" (compare[1])
: "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
"c" (xchg_high), "b" (xchg_low) );
return ret;
}
#endif
#else /* __GNUC__ */
extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
extern int interlocked_xchg( int *dest, int val );
extern void *interlocked_xchg_ptr( void **dest, void *val );
extern int interlocked_xchg_add( int *dest, int incr );
#ifdef _WIN64
extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare );
#endif
#endif /* __GNUC__ */
#else /* NO_LIBWINE_PORT */
#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
#define ffs __WINE_NOT_PORTABLE(ffs)
#define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
#define futimes __WINE_NOT_PORTABLE(futimes)
#define getopt_long __WINE_NOT_PORTABLE(getopt_long)
#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
#define getpagesize __WINE_NOT_PORTABLE(getpagesize)
#define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
#define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
#define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
#define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
#define lstat __WINE_NOT_PORTABLE(lstat)
#define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
#undef memmove
#define memmove __WINE_NOT_PORTABLE(memmove)
#define pread __WINE_NOT_PORTABLE(pread)
#define pwrite __WINE_NOT_PORTABLE(pwrite)
#define spawnvp __WINE_NOT_PORTABLE(spawnvp)
#define statvfs __WINE_NOT_PORTABLE(statvfs)
#define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
#define strerror __WINE_NOT_PORTABLE(strerror)
#define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
#define usleep __WINE_NOT_PORTABLE(usleep)
#endif /* NO_LIBWINE_PORT */
#endif /* !defined(__WINE_WINE_PORT_H) */
|
ab91d5112a168a8551b40ca92662a7e25fbe7776
|
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
|
/src/mono/mono/eglib/sort.frag.h
|
10ff451d4e6e8addf0dd19a17df7e929407475f5
|
[
"MIT"
] |
permissive
|
dotnet/runtime
|
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
|
47bb554d298e1e34c4e3895d7731e18ad1c47d02
|
refs/heads/main
| 2023-09-03T15:35:46.493337
| 2023-09-03T08:13:23
| 2023-09-03T08:13:23
| 210,716,005
| 13,765
| 5,179
|
MIT
| 2023-09-14T21:58:52
| 2019-09-24T23:36:39
|
C#
|
UTF-8
|
C
| false
| false
| 6,788
|
h
|
sort.frag.h
|
/*
* sort.frag.h: Common implementation of linked-list sorting
*
* Author:
* Raja R Harinath (rharinath@novell.com)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* (C) 2006 Novell, Inc.
*/
/*
* This code requires a typedef named 'list_node' for the list node. It
* is assumed that the list type is the type of a pointer to a list
* node, and that the node has a field named 'next' that implements to
* the linked list. No additional invariant is maintained (e.g. the
* 'prev' pointer of a doubly-linked list node is _not_ updated). Any
* invariant would require a post-processing pass to fix matters if
* necessary.
*/
typedef list_node *digit;
/*
* The maximum possible depth of the merge tree
* = ceiling (log2 (maximum number of list nodes))
* = ceiling (log2 (maximum possible memory size/size of each list node))
* = number of bits in 'size_t' - floor (log2 (sizeof digit))
* Also, each list in sort_info is at least 2 nodes long: we can reduce the depth by 1
*/
#define FLOOR_LOG2(x) (((x)>=2) + ((x)>=4) + ((x)>=8) + ((x)>=16) + ((x)>=32) + ((x)>=64) + ((x)>=128))
#define MAX_RANKS ((sizeof (size_t) * 8) - FLOOR_LOG2(sizeof (list_node)) - 1)
struct sort_info
{
int min_rank, n_ranks;
GCompareFunc func;
/* Invariant: ranks[i] == NULL || length(ranks[i]) >= 2**(i+1) */
list_node *ranks [MAX_RANKS]; /* ~ 128 bytes on 32bit, ~ 512 bytes on 64bit */
};
static inline void
init_sort_info (struct sort_info *si, GCompareFunc func)
{
si->min_rank = si->n_ranks = 0;
si->func = func;
/* we don't need to initialize si->ranks, since we never lookup past si->n_ranks. */
}
static inline list_node *
merge_lists (list_node *first, list_node *second, GCompareFunc func)
{
/* merge the two lists */
list_node *list = NULL;
list_node **pos = &list;
while (first && second) {
if (func (first->data, second->data) > 0) {
*pos = second;
second = second->next;
} else {
*pos = first;
first = first->next;
}
pos = &((*pos)->next);
}
*pos = first ? first : second;
return list;
}
/* Pre-condition: upto <= si->n_ranks, list == NULL || length(list) == 1 */
static inline list_node *
sweep_up (struct sort_info *si, list_node *list, int upto)
{
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
/*
* GCC incorrectly thinks we're writing below si->ranks array bounds.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
int i;
for (i = si->min_rank; i < upto; ++i) {
list = merge_lists (si->ranks [i], list, si->func);
si->ranks [i] = NULL;
}
return list;
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
#pragma GCC diagnostic pop
#endif
}
/*
* The 'ranks' array essentially captures the recursion stack of a mergesort.
* The merge tree is built in a bottom-up manner. The control loop for
* updating the 'ranks' array is analogous to incrementing a binary integer,
* and the O(n) time for counting upto n translates to O(n) merges when
* inserting rank-0 lists. When we plug in the sizes of the lists involved in
* those merges, we get the O(n log n) time for the sort.
*
* Inserting higher-ranked lists reduce the height of the merge tree, and also
* eliminate a lot of redundant comparisons when merging two lists that would've
* been part of the same run. Adding a rank-i list is analogous to incrementing
* a binary integer by 2**i in one operation, thus sharing a similar speedup.
*
* When inserting higher-ranked lists, we choose to clear out the lower ranks
* in the interests of keeping the sort stable, but this makes analysis harder.
* Note that clearing the lower-ranked lists is O(length(list))-- thus it
* shouldn't affect the O(n log n) behaviour. IOW, inserting one rank-i list
* is equivalent to inserting 2**i rank-0 lists, thus even if we do i additional
* merges in the clearing-out (taking at most 2**i time) we are still fine.
*/
#define stringify2(x) #x
#define stringify(x) stringify2(x)
/* Pre-condition: 2**(rank+1) <= length(list) < 2**(rank+2) (therefore: length(list) >= 2) */
static inline void
insert_list (struct sort_info *si, list_node* list, int rank)
{
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
/*
* GCC incorrectly thinks we're writing below si->ranks array bounds.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
int i;
if (rank > si->n_ranks) {
if (rank > MAX_RANKS) {
g_warning ("Rank '%d' should not exceed " stringify (MAX_RANKS), rank);
rank = MAX_RANKS;
}
list = merge_lists (sweep_up (si, NULL, si->n_ranks), list, si->func);
for (i = si->n_ranks; i < rank; ++i)
si->ranks [i] = NULL;
} else {
if (rank)
list = merge_lists (sweep_up (si, NULL, rank), list, si->func);
for (i = rank; i < si->n_ranks && si->ranks [i]; ++i) {
list = merge_lists (si->ranks [i], list, si->func);
si->ranks [i] = NULL;
}
}
if (i == MAX_RANKS) /* Will _never_ happen: so we can just devolve into quadratic ;-) */
--i;
if (i >= si->n_ranks)
si->n_ranks = i + 1;
si->min_rank = i;
si->ranks [i] = list;
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
#pragma GCC diagnostic pop
#endif
}
#undef stringify2
#undef stringify
#undef MAX_RANKS
#undef FLOOR_LOG2
/* A non-recursive mergesort */
static inline digit
do_sort (list_node* list, GCompareFunc func)
{
struct sort_info si;
init_sort_info (&si, func);
while (list && list->next) {
list_node* next = list->next;
list_node* tail = next->next;
if (func (list->data, next->data) > 0) {
next->next = list;
next = list;
list = list->next;
}
next->next = NULL;
insert_list (&si, list, 0);
list = tail;
}
return sweep_up (&si, list, si.n_ranks);
}
|
02cc37280f9070d98020bfe5918488c08d42ae2e
|
75196819c910f3fd523f1a4d28e5d0fe12570ab1
|
/src/bdb53/src/hash/hash.c
|
676d66c37192081e11d9365a2effa5ff3a6abba1
|
[
"MIT",
"BSD-3-Clause",
"Sleepycat"
] |
permissive
|
gridcoin-community/Gridcoin-Research
|
889967579b5b05bcc3ae836697a0f173b5ae91ea
|
21414dd0f63c9a34060f7f762f08d1a52aeb9e87
|
refs/heads/development
| 2023-09-04T09:21:55.006935
| 2023-09-03T17:45:20
| 2023-09-03T17:45:20
| 23,332,350
| 292
| 117
|
MIT
| 2023-09-11T10:22:10
| 2014-08-25T23:41:04
|
HTML
|
UTF-8
|
C
| false
| false
| 60,009
|
c
|
hash.c
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 2013 Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright (c) 1990, 1993, 1994
* Margo Seltzer. All rights reserved.
*/
/*
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Margo Seltzer.
*
* 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.
*
* $Id$
*/
#include "db_config.h"
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/btree.h"
#include "dbinc/hash.h"
#include "dbinc/lock.h"
#include "dbinc/mp.h"
#include "dbinc/partition.h"
static int __ham_bulk __P((DBC *, DBT *, u_int32_t));
static int __hamc_close __P((DBC *, db_pgno_t, int *));
static int __hamc_del __P((DBC *, u_int32_t));
static int __hamc_destroy __P((DBC *));
static int __hamc_get __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
static int __hamc_put __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
static int __hamc_writelock __P((DBC *));
static int __ham_dup_return __P((DBC *, DBT *, u_int32_t));
static int __ham_expand_table __P((DBC *));
static int __hamc_update_getorder
__P((DBC *, DBC *, u_int32_t *, db_pgno_t, u_int32_t, void *));
static int __hamc_update_setorder
__P((DBC *, DBC *, u_int32_t *, db_pgno_t, u_int32_t, void *));
static int __ham_get_clist_func
__P((DBC *, DBC *, u_int32_t *, db_pgno_t, u_int32_t, void *));
/*
* __ham_quick_delete --
* This function is called by __db_del when the appropriate conditions
* are met, and it performs the delete in the optimized way.
*
* PUBLIC: int __ham_quick_delete __P((DBC *));
*/
int
__ham_quick_delete(dbc)
DBC *dbc;
{
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
int ret, t_ret;
/*
* When performing a DB->del operation not involving secondary indices
* and not removing an off-page duplicate tree, we can speed things up
* substantially by removing the entire duplicate set, if any is
* present, in one operation, rather than by conjuring up and deleting
* each of the items individually. (All are stored in one big HKEYDATA
* structure.) We don't bother to distinguish on-page duplicate sets
* from single, non-dup items; they're deleted in exactly the same way.
*
* The cursor should be set to the first item in the duplicate set, or
* to the sole key/data pair when the key does not have a duplicate set,
* before the function is called.
*
* We do not need to call CDB_LOCKING_INIT, __db_del calls here with
* a write cursor.
*
* Assert we're initialized, but not to an off-page duplicate.
* Assert we're not using secondary indices.
*/
DB_ASSERT(dbc->env, IS_INITIALIZED(dbc));
DB_ASSERT(dbc->env, dbc->internal->opd == NULL);
DB_ASSERT(dbc->env, !F_ISSET(dbc->dbp, DB_AM_SECONDARY));
DB_ASSERT(dbc->env, !DB_IS_PRIMARY(dbc->dbp));
hcp = (HASH_CURSOR *)dbc->internal;
mpf = dbc->dbp->mpf;
if ((ret = __ham_get_meta(dbc)) != 0)
return (ret);
if ((ret = __hamc_writelock(dbc)) == 0) {
ret = __ham_del_pair(dbc, 0, NULL);
/*
* If a page was retrieved during the delete, put it now. We
* can't rely on the callers cursor close to do that, since bulk
* delete operations keep the cursor open across deletes.
*/
if (hcp->page != NULL) {
if ((t_ret = __memp_fput(mpf, dbc->thread_info,
hcp->page, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
hcp->page = NULL;
}
}
if ((t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
ret = t_ret;
return (ret);
}
/* ****************** CURSORS ********************************** */
/*
* __hamc_init --
* Initialize the hash-specific portion of a cursor.
*
* PUBLIC: int __hamc_init __P((DBC *));
*/
int
__hamc_init(dbc)
DBC *dbc;
{
ENV *env;
HASH_CURSOR *new_curs;
int ret;
env = dbc->env;
if ((ret = __os_calloc(env,
1, sizeof(struct cursor_t), &new_curs)) != 0)
return (ret);
if ((ret = __os_malloc(env,
dbc->dbp->pgsize, &new_curs->split_buf)) != 0) {
__os_free(env, new_curs);
return (ret);
}
dbc->internal = (DBC_INTERNAL *) new_curs;
dbc->close = dbc->c_close = __dbc_close_pp;
dbc->cmp = __dbc_cmp_pp;
dbc->count = dbc->c_count = __dbc_count_pp;
dbc->del = dbc->c_del = __dbc_del_pp;
dbc->dup = dbc->c_dup = __dbc_dup_pp;
dbc->get = dbc->c_get = __dbc_get_pp;
dbc->pget = dbc->c_pget = __dbc_pget_pp;
dbc->put = dbc->c_put = __dbc_put_pp;
dbc->am_bulk = __ham_bulk;
dbc->am_close = __hamc_close;
dbc->am_del = __hamc_del;
dbc->am_destroy = __hamc_destroy;
dbc->am_get = __hamc_get;
dbc->am_put = __hamc_put;
dbc->am_writelock = __hamc_writelock;
return (__ham_item_init(dbc));
}
/*
* __hamc_close --
* Close down the cursor from a single use.
*/
static int
__hamc_close(dbc, root_pgno, rmroot)
DBC *dbc;
db_pgno_t root_pgno;
int *rmroot;
{
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
HKEYDATA *dp;
db_lockmode_t lock_mode;
int doroot, gotmeta, ret, t_ret;
COMPQUIET(rmroot, 0);
mpf = dbc->dbp->mpf;
doroot = gotmeta = ret = 0;
hcp = (HASH_CURSOR *) dbc->internal;
/* Check for off page dups. */
if (dbc->internal->opd != NULL) {
if ((ret = __ham_get_meta(dbc)) != 0)
goto done;
gotmeta = 1;
lock_mode = DB_LOCK_READ;
/* To support dirty reads we must reget the write lock. */
if (F_ISSET(dbc->dbp, DB_AM_READ_UNCOMMITTED) &&
F_ISSET((BTREE_CURSOR *)
dbc->internal->opd->internal, C_DELETED))
lock_mode = DB_LOCK_WRITE;
if ((ret = __ham_get_cpage(dbc, lock_mode)) != 0)
goto out;
dp = (HKEYDATA *)H_PAIRDATA(dbc->dbp, hcp->page, hcp->indx);
/* If it's not a dup we aborted before we changed it. */
if (HPAGE_PTYPE(dp) == H_OFFDUP)
memcpy(&root_pgno,
HOFFPAGE_PGNO(dp), sizeof(db_pgno_t));
else
root_pgno = PGNO_INVALID;
if ((ret =
hcp->opd->am_close(hcp->opd, root_pgno, &doroot)) != 0)
goto out;
if (doroot != 0) {
if ((ret = __memp_dirty(mpf, &hcp->page,
dbc->thread_info, dbc->txn, dbc->priority, 0)) != 0)
goto out;
if ((ret = __ham_del_pair(dbc, 0, NULL)) != 0)
goto out;
}
}
out: if (ret != 0)
F_SET(dbc, DBC_ERROR);
if (hcp->page != NULL && (t_ret = __memp_fput(mpf,
dbc->thread_info, hcp->page, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
if (gotmeta != 0 && (t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
ret = t_ret;
done: if ((t_ret = __ham_item_init(dbc)) != 0 && ret == 0)
ret = t_ret;
return (ret);
}
/*
* __hamc_destroy --
* Cleanup the access method private part of a cursor.
*/
static int
__hamc_destroy(dbc)
DBC *dbc;
{
HASH_CURSOR *hcp;
hcp = (HASH_CURSOR *)dbc->internal;
if (hcp->split_buf != NULL)
__os_free(dbc->env, hcp->split_buf);
__os_free(dbc->env, hcp);
return (0);
}
/*
* __hamc_count --
* Return a count of on-page duplicates.
*
* PUBLIC: int __hamc_count __P((DBC *, db_recno_t *));
*/
int
__hamc_count(dbc, recnop)
DBC *dbc;
db_recno_t *recnop;
{
DB *dbp;
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
db_indx_t len;
db_recno_t recno;
int ret, t_ret;
u_int8_t *p, *pend;
dbp = dbc->dbp;
mpf = dbp->mpf;
hcp = (HASH_CURSOR *)dbc->internal;
recno = 0;
if ((ret = __ham_get_cpage(dbc, DB_LOCK_READ)) != 0)
return (ret);
if (hcp->indx >= NUM_ENT(hcp->page)) {
*recnop = 0;
goto err;
}
switch (HPAGE_PTYPE(H_PAIRDATA(dbp, hcp->page, hcp->indx))) {
case H_KEYDATA:
case H_OFFPAGE:
recno = 1;
break;
case H_DUPLICATE:
p = HKEYDATA_DATA(H_PAIRDATA(dbp, hcp->page, hcp->indx));
pend = p +
LEN_HDATA(dbp, hcp->page, dbp->pgsize, hcp->indx);
for (; p < pend; recno++) {
/* p may be odd, so copy rather than just dereffing */
memcpy(&len, p, sizeof(db_indx_t));
p += 2 * sizeof(db_indx_t) + len;
}
break;
default:
ret = __db_pgfmt(dbp->env, hcp->pgno);
goto err;
}
*recnop = recno;
err: if ((t_ret = __memp_fput(mpf,
dbc->thread_info, hcp->page, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
hcp->page = NULL;
return (ret);
}
/*
* __hamc_cmp --
* Compare two hash cursors for equality.
*
* This function is only called with two cursors that point to the same item.
* It distinguishes two cases:
* * Cursors pointing to different items in the same on-page duplicate set.
* * Cursors pointing to the same item, with different DELETED flags.
*
* PUBLIC: int __hamc_cmp __P((DBC *, DBC *, int *));
*/
int
__hamc_cmp(dbc, other_dbc, result)
DBC *dbc, *other_dbc;
int *result;
{
ENV *env;
HASH_CURSOR *hcp, *ohcp;
env = dbc->env;
hcp = (HASH_CURSOR *)dbc->internal;
ohcp = (HASH_CURSOR *)other_dbc->internal;
DB_ASSERT (env, hcp->pgno == ohcp->pgno);
DB_ASSERT (env, hcp->indx == ohcp->indx);
/* Only compare the duplicate offsets if this is a duplicate item. */
if ((F_ISSET(hcp, H_ISDUP) && hcp->dup_off != ohcp->dup_off) ||
F_ISSET(hcp, H_DELETED) != F_ISSET(ohcp, H_DELETED))
*result = 1;
else
*result = 0;
return (0);
}
static int
__hamc_del(dbc, flags)
DBC *dbc;
u_int32_t flags;
{
DB *dbp;
DBT repldbt;
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
int ret, t_ret;
COMPQUIET(flags, 0);
dbp = dbc->dbp;
mpf = dbp->mpf;
hcp = (HASH_CURSOR *)dbc->internal;
if (F_ISSET(hcp, H_DELETED))
return (DB_NOTFOUND);
if ((ret = __ham_get_meta(dbc)) != 0)
goto out;
if ((ret = __ham_get_cpage(dbc, DB_LOCK_WRITE)) != 0)
goto out;
/* Off-page duplicates. */
if (HPAGE_TYPE(dbp, hcp->page, H_DATAINDEX(hcp->indx)) == H_OFFDUP)
goto out;
DB_ASSERT(dbp->env, IS_DIRTY(hcp->page));
if (F_ISSET(hcp, H_ISDUP)) { /* On-page duplicate. */
if (hcp->dup_off == 0 &&
DUP_SIZE(hcp->dup_len) == LEN_HDATA(dbp, hcp->page,
hcp->hdr->dbmeta.pagesize, hcp->indx))
ret = __ham_del_pair(dbc, 0, NULL);
else {
repldbt.flags = 0;
F_SET(&repldbt, DB_DBT_PARTIAL);
repldbt.doff = hcp->dup_off;
repldbt.dlen = DUP_SIZE(hcp->dup_len);
repldbt.size = 0;
repldbt.data = HKEYDATA_DATA(H_PAIRDATA(dbp, hcp->page,
hcp->indx));
if ((ret =
__ham_replpair(dbc, &repldbt, H_DUPLICATE)) == 0) {
hcp->dup_tlen -= DUP_SIZE(hcp->dup_len);
F_SET(hcp, H_DELETED);
/*
* Clear any cached streaming information.
*/
hcp->stream_start_pgno = PGNO_INVALID;
ret = __hamc_update(dbc, DUP_SIZE(hcp->dup_len),
DB_HAM_CURADJ_DEL, 1);
}
}
} else /* Not a duplicate */
ret = __ham_del_pair(dbc, 0, NULL);
out: if (hcp->page != NULL) {
if ((t_ret = __memp_fput(mpf, dbc->thread_info,
hcp->page, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
hcp->page = NULL;
}
if ((t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
ret = t_ret;
return (ret);
}
/*
* __hamc_dup --
* Duplicate a hash cursor, such that the new one holds appropriate
* locks for the position of the original.
*
* PUBLIC: int __hamc_dup __P((DBC *, DBC *));
*/
int
__hamc_dup(orig_dbc, new_dbc)
DBC *orig_dbc, *new_dbc;
{
HASH_CURSOR *orig, *new;
orig = (HASH_CURSOR *)orig_dbc->internal;
new = (HASH_CURSOR *)new_dbc->internal;
new->bucket = orig->bucket;
new->lbucket = orig->lbucket;
new->dup_off = orig->dup_off;
new->dup_len = orig->dup_len;
new->dup_tlen = orig->dup_tlen;
if (F_ISSET(orig, H_DELETED))
F_SET(new, H_DELETED);
if (F_ISSET(orig, H_ISDUP))
F_SET(new, H_ISDUP);
return (0);
}
static int
__hamc_get(dbc, key, data, flags, pgnop)
DBC *dbc;
DBT *key;
DBT *data;
u_int32_t flags;
db_pgno_t *pgnop;
{
DB *dbp;
DB_MPOOLFILE *mpf;
ENV *env;
HASH_CURSOR *hcp;
db_lockmode_t lock_type;
int ret, t_ret;
hcp = (HASH_CURSOR *)dbc->internal;
dbp = dbc->dbp;
env = dbp->env;
mpf = dbp->mpf;
/* Clear OR'd in additional bits so we can check for flag equality. */
if (F_ISSET(dbc, DBC_RMW))
lock_type = DB_LOCK_WRITE;
else
lock_type = DB_LOCK_READ;
if ((ret = __ham_get_meta(dbc)) != 0)
return (ret);
hcp->seek_size = 0;
ret = 0;
switch (flags) {
case DB_PREV_DUP:
F_SET(hcp, H_DUPONLY);
goto prev;
case DB_PREV_NODUP:
F_SET(hcp, H_NEXT_NODUP);
/* FALLTHROUGH */
case DB_PREV:
if (IS_INITIALIZED(dbc)) {
prev: ret = __ham_item_prev(dbc, lock_type, pgnop);
break;
}
/* FALLTHROUGH */
case DB_LAST:
ret = __ham_item_last(dbc, lock_type, pgnop);
break;
case DB_NEXT_DUP:
case DB_GET_BOTHC:
/* cgetchk has already determined that the cursor is set. */
F_SET(hcp, H_DUPONLY);
goto next;
case DB_NEXT_NODUP:
F_SET(hcp, H_NEXT_NODUP);
/* FALLTHROUGH */
case DB_NEXT:
if (IS_INITIALIZED(dbc)) {
next: ret = __ham_item_next(dbc, lock_type, pgnop);
break;
}
/* FALLTHROUGH */
case DB_FIRST:
ret = __ham_item_first(dbc, lock_type, pgnop);
break;
case DB_SET:
case DB_SET_RANGE:
case DB_GET_BOTH:
case DB_GET_BOTH_RANGE:
ret = __ham_lookup(dbc, key, 0, lock_type, pgnop);
break;
case DB_CURRENT:
/* cgetchk has already determined that the cursor is set. */
if (F_ISSET(hcp, H_DELETED)) {
ret = DB_KEYEMPTY;
goto err;
}
ret = __ham_item(dbc, lock_type, pgnop);
break;
default:
ret = __db_unknown_flag(env, "__hamc_get", flags);
break;
}
/*
* Must always enter this loop to do error handling and
* check for big key/data pair.
*/
for (;;) {
if (ret != 0 && ret != DB_NOTFOUND)
goto err;
else if (F_ISSET(hcp, H_OK)) {
if (*pgnop == PGNO_INVALID)
ret = __ham_dup_return(dbc, data, flags);
break;
} else if (!F_ISSET(hcp, H_NOMORE)) {
__db_errx(env, DB_STR("1130",
"H_NOMORE returned to __hamc_get"));
ret = EINVAL;
break;
}
/*
* Ran out of entries in a bucket; change buckets.
*/
switch (flags) {
case DB_LAST:
case DB_PREV:
case DB_PREV_DUP:
case DB_PREV_NODUP:
ret = __memp_fput(mpf,
dbc->thread_info, hcp->page, dbc->priority);
hcp->page = NULL;
if (hcp->bucket == 0) {
ret = DB_NOTFOUND;
hcp->pgno = PGNO_INVALID;
goto err;
}
F_CLR(hcp, H_ISDUP);
hcp->bucket--;
hcp->indx = NDX_INVALID;
hcp->pgno = BUCKET_TO_PAGE(hcp, hcp->bucket);
if (ret == 0)
ret = __ham_item_prev(dbc, lock_type, pgnop);
break;
case DB_FIRST:
case DB_NEXT:
case DB_NEXT_NODUP:
ret = __memp_fput(mpf,
dbc->thread_info, hcp->page, dbc->priority);
hcp->page = NULL;
hcp->indx = NDX_INVALID;
hcp->bucket++;
F_CLR(hcp, H_ISDUP);
hcp->pgno = BUCKET_TO_PAGE(hcp, hcp->bucket);
if (hcp->bucket > hcp->hdr->max_bucket) {
ret = DB_NOTFOUND;
hcp->pgno = PGNO_INVALID;
goto err;
}
if (ret == 0)
ret = __ham_item_next(dbc, lock_type, pgnop);
break;
case DB_GET_BOTH:
case DB_GET_BOTHC:
case DB_GET_BOTH_RANGE:
case DB_NEXT_DUP:
case DB_SET:
case DB_SET_RANGE:
/* Key not found. */
ret = DB_NOTFOUND;
goto err;
case DB_CURRENT:
/*
* This should only happen if you are doing deletes and
* reading with concurrent threads and not doing proper
* locking. We return the same error code as we would
* if the cursor were deleted.
*/
ret = DB_KEYEMPTY;
goto err;
default:
DB_ASSERT(env, 0);
}
}
err: if ((t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
ret = t_ret;
F_CLR(hcp, H_DUPONLY);
F_CLR(hcp, H_NEXT_NODUP);
return (ret);
}
/*
* __ham_bulk -- Return bulk data from a hash table.
*/
static int
__ham_bulk(dbc, data, flags)
DBC *dbc;
DBT *data;
u_int32_t flags;
{
DB *dbp;
DB_MPOOLFILE *mpf;
HASH_CURSOR *cp;
PAGE *pg;
db_indx_t dup_len, dup_off, dup_tlen, indx, *inp;
db_lockmode_t lock_mode;
db_pgno_t pgno;
int32_t *endp, *offp, *saveoff;
u_int32_t key_off, key_size, pagesize, size, space;
u_int8_t *dbuf, *dp, *hk, *np, *tmp;
int is_dup, is_key;
int need_pg, next_key, no_dup, ret, t_ret;
ret = 0;
key_off = 0;
dup_len = dup_off = dup_tlen = 0;
size = 0;
dbp = dbc->dbp;
pagesize = dbp->pgsize;
mpf = dbp->mpf;
cp = (HASH_CURSOR *)dbc->internal;
is_key = LF_ISSET(DB_MULTIPLE_KEY) ? 1 : 0;
next_key = is_key && LF_ISSET(DB_OPFLAGS_MASK) != DB_NEXT_DUP;
no_dup = LF_ISSET(DB_OPFLAGS_MASK) == DB_NEXT_NODUP;
dbuf = data->data;
np = dp = dbuf;
/* Keep track of space that is left. There is an termination entry */
space = data->ulen;
space -= sizeof(*offp);
/* Build the offset/size table from the end up. */
endp = (int32_t *) ((u_int8_t *)dbuf + data->ulen);
endp--;
offp = endp;
key_size = 0;
lock_mode = F_ISSET(dbc, DBC_RMW) ? DB_LOCK_WRITE: DB_LOCK_READ;
next_pg:
need_pg = 1;
indx = cp->indx;
pg = cp->page;
inp = P_INP(dbp, pg);
do {
if (is_key) {
hk = H_PAIRKEY(dbp, pg, indx);
if (HPAGE_PTYPE(hk) == H_OFFPAGE) {
memcpy(&key_size,
HOFFPAGE_TLEN(hk), sizeof(u_int32_t));
memcpy(&pgno,
HOFFPAGE_PGNO(hk), sizeof(db_pgno_t));
size = key_size;
if (key_size > space)
goto get_key_space;
if ((ret = __bam_bulk_overflow(
dbc, key_size, pgno, np)) != 0)
return (ret);
space -= key_size;
key_off = (u_int32_t)(np - dbuf);
np += key_size;
} else {
if (need_pg) {
dp = np;
size = pagesize - HOFFSET(pg);
if (space < size) {
get_key_space:
if (offp == endp) {
data->size = (u_int32_t)
DB_ALIGN(size +
pagesize, 1024);
return
(DB_BUFFER_SMALL);
}
goto back_up;
}
memcpy(dp,
(u_int8_t *)pg + HOFFSET(pg), size);
need_pg = 0;
space -= size;
np += size;
}
key_size = LEN_HKEY(dbp, pg, pagesize, indx);
key_off = ((inp[indx] - HOFFSET(pg)) +
(u_int32_t)(dp - dbuf)) +
SSZA(HKEYDATA, data);
}
}
hk = H_PAIRDATA(dbp, pg, indx);
switch (HPAGE_PTYPE(hk)) {
case H_DUPLICATE:
case H_KEYDATA:
if (need_pg) {
dp = np;
size = pagesize - HOFFSET(pg);
if (space < size) {
back_up:
if (indx != 0) {
indx -= 2;
/* XXX
* It's not clear that this is
* the right way to fix this,
* but here goes.
* If we are backing up onto a
* duplicate, then we need to
* position ourselves at the
* end of the duplicate set.
* We probably need to make
* this work for H_OFFDUP too.
* It might be worth making a
* dummy cursor and calling
* __ham_item_prev.
*/
tmp = H_PAIRDATA(dbp, pg, indx);
if (HPAGE_PTYPE(tmp) ==
H_DUPLICATE) {
dup_off = dup_tlen =
LEN_HDATA(dbp, pg,
pagesize, indx + 1);
memcpy(&dup_len,
HKEYDATA_DATA(tmp),
sizeof(db_indx_t));
} else {
is_dup = 0;
dup_len = 0;
dup_off = 0;
dup_tlen = 0;
F_CLR(cp, H_ISDUP);
}
goto get_space;
}
/* indx == 0 */
cp->dup_len = dup_len;
cp->dup_off = dup_off;
cp->dup_tlen = dup_tlen;
if ((ret = __ham_item_prev(dbc,
lock_mode, &pgno)) != 0) {
if (ret != DB_NOTFOUND)
return (ret);
if ((ret = __memp_fput(mpf,
dbc->thread_info, cp->page,
dbc->priority)) != 0)
return (ret);
cp->page = NULL;
if (cp->bucket == 0) {
cp->indx = indx =
NDX_INVALID;
goto get_space;
}
if ((ret =
__ham_get_meta(dbc)) != 0)
return (ret);
cp->bucket--;
cp->pgno = BUCKET_TO_PAGE(cp,
cp->bucket);
cp->indx = NDX_INVALID;
if ((ret = __ham_release_meta(
dbc)) != 0)
return (ret);
/*
* Not an error to get
* DB_NOTFOUND, we're just at
* the beginning of the db.
*/
if ((ret = __ham_item_prev(dbc,
lock_mode, &pgno)) != 0) {
if (ret != DB_NOTFOUND)
return (ret);
else
ret = 0;
}
}
indx = cp->indx;
get_space:
/*
* See if we put any data in the buffer.
*/
if (offp >= endp ||
F_ISSET(dbc, DBC_TRANSIENT)) {
data->size = (u_int32_t)
DB_ALIGN(size +
data->ulen - space, 1024);
return (DB_BUFFER_SMALL);
}
/*
* Don't continue; we're all out
* of space, even though we're
* returning success.
*/
next_key = 0;
break;
}
memcpy(dp, (u_int8_t *)pg + HOFFSET(pg), size);
need_pg = 0;
space -= size;
np += size;
}
/*
* We're about to crack the offset(s) and length(s)
* out of an H_KEYDATA or H_DUPLICATE item.
* There are three cases:
* 1. We were moved into a duplicate set by
* the standard hash cursor code. Respect
* the dup_off and dup_tlen we were given.
* 2. We stumbled upon a duplicate set while
* walking the page on our own. We need to
* recognize it as a dup and set dup_off and
* dup_tlen.
* 3. The current item is not a dup.
*/
if (F_ISSET(cp, H_ISDUP)) {
/* Case 1 */
is_dup = 1;
dup_len = cp->dup_len;
dup_off = cp->dup_off;
dup_tlen = cp->dup_tlen;
} else if (HPAGE_PTYPE(hk) == H_DUPLICATE) {
/* Case 2 */
is_dup = 1;
/*
* If we run out of memory and bail,
* make sure the fact we're in a dup set
* isn't ignored later.
*/
F_SET(cp, H_ISDUP);
dup_off = 0;
memcpy(&dup_len,
HKEYDATA_DATA(hk), sizeof(db_indx_t));
dup_tlen = LEN_HDATA(dbp, pg, pagesize, indx);
} else {
/* Case 3 */
is_dup = 0;
dup_len = 0;
dup_off = 0;
dup_tlen = 0;
}
do {
space -= (is_key ? 4 : 2) * sizeof(*offp);
size += (is_key ? 4 : 2) * sizeof(*offp);
/*
* Since space is an unsigned, if we happen
* to wrap, then this comparison will turn out
* to be true. XXX Wouldn't it be better to
* simply check above that space is greater than
* the value we're about to subtract???
*/
if (space > data->ulen) {
if (!is_dup || dup_off == 0)
goto back_up;
dup_off -= (db_indx_t)
DUP_SIZE((u_int32_t)offp[1]);
goto get_space;
}
if (is_key) {
*offp-- = (int32_t)key_off;
*offp-- = (int32_t)key_size;
}
if (is_dup) {
*offp-- = (int32_t)(
((inp[indx + 1] - HOFFSET(pg)) +
dp - dbuf) + SSZA(HKEYDATA, data) +
dup_off + sizeof(db_indx_t));
memcpy(&dup_len,
HKEYDATA_DATA(hk) + dup_off,
sizeof(db_indx_t));
dup_off += DUP_SIZE(dup_len);
*offp-- = dup_len;
} else {
*offp-- = (int32_t)(
((inp[indx + 1] - HOFFSET(pg)) +
dp - dbuf) + SSZA(HKEYDATA, data));
*offp-- = LEN_HDATA(dbp, pg,
pagesize, indx);
}
} while (is_dup && dup_off < dup_tlen && no_dup == 0);
F_CLR(cp, H_ISDUP);
break;
case H_OFFDUP:
memcpy(&pgno, HOFFPAGE_PGNO(hk), sizeof(db_pgno_t));
space -= 2 * sizeof(*offp);
if (space > data->ulen)
goto back_up;
if (is_key) {
space -= 2 * sizeof(*offp);
if (space > data->ulen)
goto back_up;
*offp-- = (int32_t)key_off;
*offp-- = (int32_t)key_size;
}
saveoff = offp;
if ((ret = __bam_bulk_duplicates(dbc,
pgno, dbuf, is_key ? offp + 2 : NULL,
&offp, &np, &space, no_dup)) != 0) {
if (ret == DB_BUFFER_SMALL) {
size = space;
space = 0;
if (is_key && saveoff == offp) {
offp += 2;
goto back_up;
}
goto get_space;
}
return (ret);
}
break;
case H_OFFPAGE:
space -= (is_key ? 4 : 2) * sizeof(*offp);
if (space > data->ulen)
goto back_up;
memcpy(&size, HOFFPAGE_TLEN(hk), sizeof(u_int32_t));
memcpy(&pgno, HOFFPAGE_PGNO(hk), sizeof(db_pgno_t));
if (size > space)
goto back_up;
if ((ret =
__bam_bulk_overflow(dbc, size, pgno, np)) != 0)
return (ret);
if (is_key) {
*offp-- = (int32_t)key_off;
*offp-- = (int32_t)key_size;
}
*offp-- = (int32_t)(np - dbuf);
*offp-- = (int32_t)size;
np += size;
space -= size;
break;
default:
/* Do nothing. */
break;
}
} while (next_key && (indx += 2) < NUM_ENT(pg));
cp->indx = indx;
cp->dup_len = dup_len;
cp->dup_off = dup_off;
cp->dup_tlen = dup_tlen;
/* If we are off the page then try to the next page. */
if (ret == 0 && next_key && indx >= NUM_ENT(pg)) {
if ((ret = __ham_item_next(dbc, lock_mode, &pgno)) == 0)
goto next_pg;
if (ret != DB_NOTFOUND)
return (ret);
if ((ret = __memp_fput(dbc->dbp->mpf,
dbc->thread_info, cp->page, dbc->priority)) != 0)
return (ret);
cp->page = NULL;
if ((ret = __ham_get_meta(dbc)) != 0)
return (ret);
cp->bucket++;
if (cp->bucket > cp->hdr->max_bucket) {
/*
* Restore cursor to its previous state. We're past
* the last item in the last bucket, so the next
* DBC->get(DB_NEXT) will return DB_NOTFOUND.
*/
cp->bucket--;
ret = DB_NOTFOUND;
} else {
/*
* Start on the next bucket.
*
* Note that if this new bucket happens to be empty,
* but there's another non-empty bucket after it,
* we'll return early. This is a rare case, and we
* don't guarantee any particular number of keys
* returned on each call, so just let the next call
* to bulk get move forward by yet another bucket.
*/
cp->pgno = BUCKET_TO_PAGE(cp, cp->bucket);
cp->indx = NDX_INVALID;
F_CLR(cp, H_ISDUP);
ret = __ham_item_next(dbc, lock_mode, &pgno);
}
if ((t_ret = __ham_release_meta(dbc)) != 0)
return (t_ret);
if (ret == 0)
goto next_pg;
if (ret != DB_NOTFOUND)
return (ret);
}
*offp = -1;
return (0);
}
static int
__hamc_put(dbc, key, data, flags, pgnop)
DBC *dbc;
DBT *key;
DBT *data;
u_int32_t flags;
db_pgno_t *pgnop;
{
DB *dbp;
DBT tmp_val, *myval;
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
u_int32_t nbytes;
int ret, t_ret;
/*
* The compiler doesn't realize that we only use this when ret is
* equal to 0 and that if ret is equal to 0, that we must have set
* myval. So, we initialize it here to shut the compiler up.
*/
COMPQUIET(myval, NULL);
dbp = dbc->dbp;
mpf = dbp->mpf;
hcp = (HASH_CURSOR *)dbc->internal;
if (F_ISSET(hcp, H_DELETED) && flags != DB_KEYFIRST &&
flags != DB_KEYLAST && flags != DB_OVERWRITE_DUP)
return (DB_NOTFOUND);
if ((ret = __ham_get_meta(dbc)) != 0)
goto err1;
switch (flags) {
case DB_KEYLAST:
case DB_KEYFIRST:
case DB_NODUPDATA:
case DB_NOOVERWRITE:
case DB_OVERWRITE_DUP:
nbytes = (ISBIG(hcp, key->size) ? HOFFPAGE_PSIZE :
HKEYDATA_PSIZE(key->size)) +
(ISBIG(hcp, data->size) ? HOFFPAGE_PSIZE :
HKEYDATA_PSIZE(data->size));
if ((ret = __ham_lookup(dbc,
key, nbytes, DB_LOCK_WRITE, pgnop)) == DB_NOTFOUND) {
if (hcp->seek_found_page != PGNO_INVALID &&
hcp->seek_found_page != hcp->pgno) {
if ((ret = __memp_fput(mpf, dbc->thread_info,
hcp->page, dbc->priority)) != 0)
goto err2;
hcp->page = NULL;
hcp->pgno = hcp->seek_found_page;
hcp->indx = NDX_INVALID;
}
if (F_ISSET(data, DB_DBT_PARTIAL) && data->doff != 0) {
/*
* A partial put, but the key does not exist
* and we are not beginning the write at 0.
* We must create a data item padded up to doff
* and then write the new bytes represented by
* val.
*/
if ((ret = __ham_init_dbt(dbp->env, &tmp_val,
data->size + data->doff,
&dbc->my_rdata.data,
&dbc->my_rdata.ulen)) != 0)
goto err2;
memset(tmp_val.data, 0, data->doff);
memcpy((u_int8_t *)tmp_val.data +
data->doff, data->data, data->size);
myval = &tmp_val;
} else
myval = (DBT *)data;
ret = __ham_add_el(dbc, key, myval, H_KEYDATA);
goto done;
} else if (ret == 0 && flags == DB_NOOVERWRITE &&
!F_ISSET(hcp, H_DELETED)) {
if (*pgnop == PGNO_INVALID)
ret = DB_KEYEXIST;
else
ret = __bam_opd_exists(dbc, *pgnop);
if (ret != 0)
goto done;
}
break;
case DB_BEFORE:
case DB_AFTER:
case DB_CURRENT:
ret = __ham_item(dbc, DB_LOCK_WRITE, pgnop);
break;
default:
ret = __db_unknown_flag(dbp->env, "__hamc_put", flags);
break;
}
/*
* Invalidate any insert index found so they are not reused
* in future inserts.
*/
hcp->seek_found_page = PGNO_INVALID;
hcp->seek_found_indx = NDX_INVALID;
if (*pgnop == PGNO_INVALID && ret == 0) {
if ((ret = __memp_dirty(mpf, &hcp->page,
dbc->thread_info, dbc->txn, dbc->priority, 0)) != 0)
goto done;
if (flags == DB_CURRENT ||
(!(F_ISSET(dbp, DB_AM_DUP) || F_ISSET(key, DB_DBT_DUPOK)) &&
(flags == DB_KEYFIRST || flags == DB_KEYLAST ||
flags == DB_NODUPDATA || flags == DB_OVERWRITE_DUP)))
ret = __ham_overwrite(dbc, data, flags);
else
ret = __ham_add_dup(dbc, data, flags, pgnop);
}
done: if (hcp->page != NULL) {
if ((t_ret = __memp_fput(mpf, dbc->thread_info,
hcp->page, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
if (t_ret == 0)
hcp->page = NULL;
}
if (ret == 0 && F_ISSET(hcp, H_EXPAND)) {
ret = __ham_expand_table(dbc);
F_CLR(hcp, H_EXPAND);
/* If we are out of space, ignore the error. */
if (ret == ENOSPC && dbc->txn == NULL)
ret = 0;
} else if (ret == 0 && F_ISSET(hcp, H_CONTRACT)) {
if (!F_ISSET(dbp, DB_AM_REVSPLITOFF))
ret = __ham_contract_table(dbc, NULL);
F_CLR(hcp, H_CONTRACT);
}
err2: if ((t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
ret = t_ret;
err1: return (ret);
}
/********************************* UTILITIES ************************/
/*
* __ham_contract_table -- remove the last bucket.
* PUBLIC: int __ham_contract_table __P((DBC *, DB_COMPACT *));
*/
int
__ham_contract_table(dbc, c_data)
DBC *dbc;
DB_COMPACT *c_data;
{
DB *dbp;
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
HMETA *hdr;
PAGE *h;
db_pgno_t maxpgno, stoppgno;
int drop_segment, ret;
dbp = dbc->dbp;
mpf = dbp->mpf;
h = NULL;
if ((ret = __ham_dirty_meta(dbc, 0)) != 0)
return (ret);
hcp = (HASH_CURSOR *)dbc->internal;
hdr = hcp->hdr;
if ((ret = __ham_merge_pages(dbc,
hdr->max_bucket & hdr->low_mask, hdr->max_bucket, c_data)) != 0)
return (ret);
maxpgno = BUCKET_TO_PAGE(hcp, hdr->max_bucket);
drop_segment = hdr->max_bucket == (hdr->low_mask + 1);
if (DBC_LOGGING(dbc)) {
if ((ret = __ham_contract_log(dbp, dbc->txn, &LSN(hdr),
0, PGNO(hdr), &LSN(hdr), hdr->max_bucket, maxpgno)) != 0)
goto err;
} else
LSN_NOT_LOGGED(LSN(hdr));
hdr->max_bucket--;
/*
* If we are dropping a segment then adjust the spares table and masks
* and free the pages in that segment.
*/
if (drop_segment) {
LOCK_CHECK_OFF(dbc->thread_info);
hdr->spares[__db_log2(hdr->max_bucket + 1) + 1] = PGNO_INVALID;
hdr->high_mask = hdr->low_mask;
hdr->low_mask >>= 1;
stoppgno = maxpgno + hdr->max_bucket + 1;
do {
if ((ret = __memp_fget(mpf, &maxpgno,
dbc->thread_info, dbc->txn,
DB_MPOOL_CREATE | DB_MPOOL_DIRTY, &h)) != 0)
break;
if ((ret = __db_free(dbc, h, 0)) != 0)
break;
ret = 0;
} while (++maxpgno < stoppgno);
LOCK_CHECK_ON(dbc->thread_info);
}
err: return (ret);
}
/*
* __ham_expand_table --
*/
static int
__ham_expand_table(dbc)
DBC *dbc;
{
DB *dbp;
DBMETA *mmeta;
DB_LOCK metalock;
DB_LSN lsn;
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
PAGE *h;
db_pgno_t pgno, mpgno;
u_int32_t logn, newalloc, new_bucket, old_bucket;
int got_meta, new_double, ret, t_ret;
LOCK_CHECK_OFF(dbc->thread_info);
dbp = dbc->dbp;
mpf = dbp->mpf;
hcp = (HASH_CURSOR *)dbc->internal;
if ((ret = __ham_dirty_meta(dbc, 0)) != 0)
return (ret);
LOCK_INIT(metalock);
mmeta = (DBMETA *) hcp->hdr;
mpgno = mmeta->pgno;
h = NULL;
newalloc = 0;
got_meta = 0;
/*
* If the split point is about to increase, make sure that we
* have enough extra pages. The calculation here is weird.
* We'd like to do this after we've upped max_bucket, but it's
* too late then because we've logged the meta-data split. What
* we'll do between then and now is increment max bucket and then
* see what the log of one greater than that is; here we have to
* look at the log of max + 2. VERY NASTY STUFF.
*
* We figure out what we need to do, then we log it, then request
* the pages from mpool. We don't want to fail after extending
* the file.
*
* If the page we are about to split into has already been allocated,
* then we simply need to get it to get its LSN. If it hasn't yet
* been allocated, then we know it's LSN (0,0).
*/
new_bucket = hcp->hdr->max_bucket + 1;
old_bucket = new_bucket & hcp->hdr->low_mask;
new_double = hcp->hdr->max_bucket == hcp->hdr->high_mask;
logn = __db_log2(new_bucket);
if (!new_double || hcp->hdr->spares[logn + 1] != PGNO_INVALID) {
/* Page exists; get it so we can get its LSN */
pgno = BUCKET_TO_PAGE(hcp, new_bucket);
if ((ret = __memp_fget(mpf, &pgno, dbc->thread_info, dbc->txn,
DB_MPOOL_CREATE | DB_MPOOL_DIRTY, &h)) != 0)
goto err;
lsn = h->lsn;
} else {
/* Get the master meta-data page to do allocation. */
if (F_ISSET(dbp, DB_AM_SUBDB)) {
mpgno = PGNO_BASE_MD;
if ((ret = __db_lget(dbc,
0, mpgno, DB_LOCK_WRITE, 0, &metalock)) != 0)
goto err;
if ((ret = __memp_fget(mpf, &mpgno, dbc->thread_info,
dbc->txn, DB_MPOOL_DIRTY, &mmeta)) != 0)
goto err;
got_meta = 1;
}
pgno = mmeta->last_pgno + 1;
ZERO_LSN(lsn);
newalloc = 1;
}
/* Log the meta-data split first. */
if (DBC_LOGGING(dbc)) {
/*
* We always log the page number of the first page of
* the allocation group. However, the LSN that we log
* is either the LSN on the first page (if we did not
* do the actual allocation here) or the LSN on the last
* page of the unit (if we did do the allocation here).
*/
if ((ret = __ham_metagroup_log(dbp, dbc->txn,
&lsn, 0, hcp->hdr->max_bucket, mpgno, &mmeta->lsn,
hcp->hdr->dbmeta.pgno, &hcp->hdr->dbmeta.lsn,
pgno, &lsn, newalloc, mmeta->last_pgno)) != 0)
goto err;
} else
LSN_NOT_LOGGED(lsn);
hcp->hdr->dbmeta.lsn = lsn;
if (new_double && hcp->hdr->spares[logn + 1] == PGNO_INVALID) {
/*
* We need to begin a new doubling and we have not allocated
* any pages yet. Read the last page in and initialize it to
* make the allocation contiguous. The pgno we calculated
* above is the first page allocated. The entry in spares is
* that page number minus any buckets already allocated (it
* simplifies bucket to page transaction). After we've set
* that, we calculate the last pgno.
*/
pgno += hcp->hdr->max_bucket;
if ((ret = __memp_fget(mpf, &pgno, dbc->thread_info, dbc->txn,
DB_MPOOL_CREATE | DB_MPOOL_DIRTY, &h)) != 0)
goto err;
hcp->hdr->spares[logn + 1] =
(pgno - new_bucket) - hcp->hdr->max_bucket;
mmeta->last_pgno = pgno;
mmeta->lsn = lsn;
P_INIT(h, dbp->pgsize,
pgno, PGNO_INVALID, PGNO_INVALID, 0, P_HASH);
}
/* Write out whatever page we ended up modifying. */
h->lsn = lsn;
if ((ret = __memp_fput(mpf, dbc->thread_info, h, dbc->priority)) != 0)
goto err;
h = NULL;
/*
* Update the meta-data page of this hash database.
*/
hcp->hdr->max_bucket = new_bucket;
if (new_double) {
hcp->hdr->low_mask = hcp->hdr->high_mask;
hcp->hdr->high_mask = new_bucket | hcp->hdr->low_mask;
}
err: if (got_meta)
if ((t_ret = __memp_fput(mpf,
dbc->thread_info, mmeta, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
if ((t_ret = __TLPUT(dbc, metalock)) != 0 && ret == 0)
ret = t_ret;
if (h != NULL)
if ((t_ret = __memp_fput(mpf,
dbc->thread_info, h, dbc->priority)) != 0 && ret == 0)
ret = t_ret;
/* Relocate records to the new bucket -- after releasing metapage. */
if (ret == 0)
ret = __ham_split_page(dbc, old_bucket, new_bucket);
LOCK_CHECK_ON(dbc->thread_info);
return (ret);
}
/*
* PUBLIC: u_int32_t __ham_call_hash __P((DBC *, u_int8_t *, u_int32_t));
*/
u_int32_t
__ham_call_hash(dbc, k, len)
DBC *dbc;
u_int8_t *k;
u_int32_t len;
{
DB *dbp;
HASH *hashp;
HASH_CURSOR *hcp;
u_int32_t n, bucket;
dbp = dbc->dbp;
hcp = (HASH_CURSOR *)dbc->internal;
hashp = dbp->h_internal;
n = (u_int32_t)(hashp->h_hash(dbp, k, len));
bucket = n & hcp->hdr->high_mask;
if (bucket > hcp->hdr->max_bucket)
bucket = bucket & hcp->hdr->low_mask;
return (bucket);
}
/*
* Check for duplicates, and call __db_ret appropriately. Release
* everything held by the cursor.
*/
static int
__ham_dup_return(dbc, val, flags)
DBC *dbc;
DBT *val;
u_int32_t flags;
{
DB *dbp;
DBT *myval, tmp_val;
HASH_CURSOR *hcp;
PAGE *pp;
db_indx_t ndx;
db_pgno_t pgno;
u_int32_t off, tlen;
u_int8_t *hk, type;
int cmp, ret;
db_indx_t len;
/* Check for duplicate and return the first one. */
dbp = dbc->dbp;
hcp = (HASH_CURSOR *)dbc->internal;
ndx = H_DATAINDEX(hcp->indx);
type = HPAGE_TYPE(dbp, hcp->page, ndx);
pp = hcp->page;
myval = val;
/*
* There are 4 cases:
* 1. We are not in duplicate, simply return; the upper layer
* will do the right thing.
* 2. We are looking at keys and stumbled onto a duplicate.
* 3. We are in the middle of a duplicate set. (ISDUP set)
* 4. We need to check for particular data match.
*/
/* We should never get here with off-page dups. */
DB_ASSERT(dbp->env, type != H_OFFDUP);
/* Case 1 */
if (type != H_DUPLICATE && flags != DB_GET_BOTH &&
flags != DB_GET_BOTHC && flags != DB_GET_BOTH_RANGE)
return (0);
/*
* Here we check for the case where we just stumbled onto a
* duplicate. In this case, we do initialization and then
* let the normal duplicate code handle it. (Case 2)
*/
if (!F_ISSET(hcp, H_ISDUP) && type == H_DUPLICATE) {
F_SET(hcp, H_ISDUP);
hcp->dup_tlen = LEN_HDATA(dbp, hcp->page,
hcp->hdr->dbmeta.pagesize, hcp->indx);
hk = H_PAIRDATA(dbp, hcp->page, hcp->indx);
if (flags == DB_LAST ||
flags == DB_PREV || flags == DB_PREV_NODUP) {
hcp->dup_off = 0;
do {
memcpy(&len,
HKEYDATA_DATA(hk) + hcp->dup_off,
sizeof(db_indx_t));
hcp->dup_off += DUP_SIZE(len);
} while (hcp->dup_off < hcp->dup_tlen);
hcp->dup_off -= DUP_SIZE(len);
} else {
memcpy(&len,
HKEYDATA_DATA(hk), sizeof(db_indx_t));
hcp->dup_off = 0;
}
hcp->dup_len = len;
}
/*
* If we are retrieving a specific key/data pair, then we
* may need to adjust the cursor before returning data.
* Case 4
*/
if (flags == DB_GET_BOTH ||
flags == DB_GET_BOTHC || flags == DB_GET_BOTH_RANGE) {
if (F_ISSET(hcp, H_ISDUP)) {
/*
* If we're doing a join, search forward from the
* current position, not the beginning of the dup set.
*/
if (flags == DB_GET_BOTHC)
F_SET(hcp, H_CONTINUE);
__ham_dsearch(dbc, val, &off, &cmp, flags);
/*
* This flag is set nowhere else and is safe to
* clear unconditionally.
*/
F_CLR(hcp, H_CONTINUE);
hcp->dup_off = off;
} else {
hk = H_PAIRDATA(dbp, hcp->page, hcp->indx);
if (((HKEYDATA *)hk)->type == H_OFFPAGE) {
memcpy(&tlen,
HOFFPAGE_TLEN(hk), sizeof(u_int32_t));
memcpy(&pgno,
HOFFPAGE_PGNO(hk), sizeof(db_pgno_t));
if ((ret = __db_moff(dbc, val, pgno, tlen,
dbp->dup_compare, &cmp)) != 0)
return (ret);
cmp = -cmp;
} else {
/*
* We do not zero tmp_val since the comparison
* routines may only look at data and size.
*/
tmp_val.data = HKEYDATA_DATA(hk);
tmp_val.size = LEN_HDATA(dbp, hcp->page,
dbp->pgsize, hcp->indx);
cmp = dbp->dup_compare == NULL ?
__bam_defcmp(dbp, &tmp_val, val) :
dbp->dup_compare(dbp, &tmp_val, val);
}
if (cmp > 0 && flags == DB_GET_BOTH_RANGE &&
F_ISSET(dbp, DB_AM_DUPSORT))
cmp = 0;
}
if (cmp != 0)
return (DB_NOTFOUND);
}
/*
* If we've already got the data for this value, or we're doing a bulk
* get, we don't want to return the data.
*/
if (F_ISSET(dbc, DBC_MULTIPLE | DBC_MULTIPLE_KEY) ||
F_ISSET(val, DB_DBT_ISSET))
return (0);
/*
* Now, everything is initialized, grab a duplicate if
* necessary.
*/
if (F_ISSET(hcp, H_ISDUP)) { /* Case 3 */
/*
* Copy the DBT in case we are retrieving into user
* memory and we need the parameters for it. If the
* user requested a partial, then we need to adjust
* the user's parameters to get the partial of the
* duplicate which is itself a partial.
*/
memcpy(&tmp_val, val, sizeof(*val));
if (F_ISSET(&tmp_val, DB_DBT_PARTIAL)) {
/*
* Take the user's length unless it would go
* beyond the end of the duplicate.
*/
if (tmp_val.doff > hcp->dup_len)
tmp_val.dlen = 0;
else if (tmp_val.dlen + tmp_val.doff > hcp->dup_len)
tmp_val.dlen = hcp->dup_len - tmp_val.doff;
} else {
F_SET(&tmp_val, DB_DBT_PARTIAL);
tmp_val.dlen = hcp->dup_len;
tmp_val.doff = 0;
}
/*
* Set offset to the appropriate place within the
* current duplicate -- need to take into account
* both the dup_off and the current duplicate's
* length.
*/
tmp_val.doff += hcp->dup_off + sizeof(db_indx_t);
myval = &tmp_val;
}
/*
* Finally, if we had a duplicate, pp, ndx, and myval should be
* set appropriately.
*/
if ((ret = __db_ret(dbc, pp, ndx, myval,
&dbc->rdata->data, &dbc->rdata->ulen)) != 0) {
if (ret == DB_BUFFER_SMALL)
val->size = myval->size;
return (ret);
}
/*
* In case we sent a temporary off to db_ret, set the real
* return values.
*/
val->data = myval->data;
val->size = myval->size;
F_SET(val, DB_DBT_ISSET);
return (0);
}
/*
* Overwrite a record.
*
* PUBLIC: int __ham_overwrite __P((DBC *, DBT *, u_int32_t));
*/
int
__ham_overwrite(dbc, nval, flags)
DBC *dbc;
DBT *nval;
u_int32_t flags;
{
DB *dbp;
DBT *myval, tmp_val, tmp_val2;
ENV *env;
HASH_CURSOR *hcp;
void *newrec;
u_int8_t *hk, *p;
u_int32_t len, nondup_size;
db_indx_t newsize;
int ret;
dbp = dbc->dbp;
env = dbp->env;
hcp = (HASH_CURSOR *)dbc->internal;
if (F_ISSET(hcp, H_ISDUP)) {
/*
* This is an overwrite of a duplicate. We should never
* be off-page at this point.
*/
DB_ASSERT(env, hcp->opd == NULL);
/* On page dups */
if (F_ISSET(nval, DB_DBT_PARTIAL)) {
/*
* We're going to have to get the current item, then
* construct the record, do any padding and do a
* replace.
*/
memset(&tmp_val, 0, sizeof(tmp_val));
if ((ret =
__ham_dup_return(dbc, &tmp_val, DB_CURRENT)) != 0)
return (ret);
/* Figure out new size. */
nondup_size = tmp_val.size;
newsize = nondup_size;
/*
* Three cases:
* 1. strictly append (may need to allocate space
* for pad bytes; really gross).
* 2. overwrite some and append.
* 3. strictly overwrite.
*/
if (nval->doff > nondup_size)
newsize +=
((nval->doff - nondup_size) + nval->size);
else if (nval->doff + nval->dlen > nondup_size)
newsize += nval->size -
(nondup_size - nval->doff);
else
newsize += nval->size - nval->dlen;
/*
* Make sure that the new size doesn't put us over
* the onpage duplicate size in which case we need
* to convert to off-page duplicates.
*/
if (ISBIG(hcp,
(hcp->dup_tlen - nondup_size) + newsize)) {
if ((ret = __ham_dup_convert(dbc)) != 0)
return (ret);
return (hcp->opd->am_put(hcp->opd,
NULL, nval, flags, NULL));
}
if ((ret = __os_malloc(dbp->env,
DUP_SIZE(newsize), &newrec)) != 0)
return (ret);
memset(&tmp_val2, 0, sizeof(tmp_val2));
F_SET(&tmp_val2, DB_DBT_PARTIAL);
/* Construct the record. */
p = newrec;
/* Initial size. */
memcpy(p, &newsize, sizeof(db_indx_t));
p += sizeof(db_indx_t);
/* First part of original record. */
len = nval->doff > tmp_val.size
? tmp_val.size : nval->doff;
memcpy(p, tmp_val.data, len);
p += len;
if (nval->doff > tmp_val.size) {
/* Padding */
memset(p, 0, nval->doff - tmp_val.size);
p += nval->doff - tmp_val.size;
}
/* New bytes */
memcpy(p, nval->data, nval->size);
p += nval->size;
/* End of original record (if there is any) */
if (nval->doff + nval->dlen < tmp_val.size) {
len = (tmp_val.size - nval->doff) - nval->dlen;
memcpy(p, (u_int8_t *)tmp_val.data +
nval->doff + nval->dlen, len);
p += len;
}
/* Final size. */
memcpy(p, &newsize, sizeof(db_indx_t));
/*
* Make sure that the caller isn't corrupting
* the sort order.
*/
if (dbp->dup_compare != NULL) {
tmp_val2.data =
(u_int8_t *)newrec + sizeof(db_indx_t);
tmp_val2.size = newsize;
if (dbp->dup_compare(
dbp, &tmp_val, &tmp_val2) != 0) {
__os_free(env, newrec);
return (__db_duperr(dbp, flags));
}
}
tmp_val2.data = newrec;
tmp_val2.size = DUP_SIZE(newsize);
tmp_val2.doff = hcp->dup_off;
tmp_val2.dlen = DUP_SIZE(hcp->dup_len);
ret = __ham_replpair(dbc, &tmp_val2, H_DUPLICATE);
__os_free(env, newrec);
/* Update cursor */
if (ret != 0)
return (ret);
if (newsize > nondup_size) {
if ((ret = __hamc_update(dbc,
(newsize - nondup_size),
DB_HAM_CURADJ_ADDMOD, 1)) != 0)
return (ret);
hcp->dup_tlen += (newsize - nondup_size);
} else {
if ((ret = __hamc_update(dbc,
(nondup_size - newsize),
DB_HAM_CURADJ_DELMOD, 1)) != 0)
return (ret);
hcp->dup_tlen -= (nondup_size - newsize);
}
hcp->dup_len = newsize;
return (0);
} else {
/* Check whether we need to convert to off page. */
if (ISBIG(hcp,
(hcp->dup_tlen - hcp->dup_len) + nval->size)) {
if ((ret = __ham_dup_convert(dbc)) != 0)
return (ret);
return (hcp->opd->am_put(hcp->opd,
NULL, nval, flags, NULL));
}
/* Make sure we maintain sort order. */
if (dbp->dup_compare != NULL) {
tmp_val2.data =
HKEYDATA_DATA(H_PAIRDATA(dbp, hcp->page,
hcp->indx)) + hcp->dup_off +
sizeof(db_indx_t);
tmp_val2.size = hcp->dup_len;
if (dbp->dup_compare(
dbp, nval, &tmp_val2) != 0) {
__db_errx(env, DB_STR("1131",
"Existing data sorts differently from put data"));
return (EINVAL);
}
}
/* Overwriting a complete duplicate. */
if ((ret =
__ham_make_dup(dbp->env, nval, &tmp_val,
&dbc->my_rdata.data, &dbc->my_rdata.ulen)) != 0)
return (ret);
/* Now fix what we are replacing. */
tmp_val.doff = hcp->dup_off;
tmp_val.dlen = DUP_SIZE(hcp->dup_len);
/* Update cursor */
if (nval->size > hcp->dup_len) {
if ((ret = __hamc_update(dbc,
(nval->size - hcp->dup_len),
DB_HAM_CURADJ_ADDMOD, 1)) != 0)
return (ret);
hcp->dup_tlen += (nval->size - hcp->dup_len);
} else {
if ((ret = __hamc_update(dbc,
(hcp->dup_len - nval->size),
DB_HAM_CURADJ_DELMOD, 1)) != 0)
return (ret);
hcp->dup_tlen -= (hcp->dup_len - nval->size);
}
hcp->dup_len = (db_indx_t)nval->size;
}
myval = &tmp_val;
} else if (!F_ISSET(nval, DB_DBT_PARTIAL)) {
/* Put/overwrite */
memcpy(&tmp_val, nval, sizeof(*nval));
F_SET(&tmp_val, DB_DBT_PARTIAL);
tmp_val.doff = 0;
hk = H_PAIRDATA(dbp, hcp->page, hcp->indx);
if (HPAGE_PTYPE(hk) == H_OFFPAGE)
memcpy(&tmp_val.dlen,
HOFFPAGE_TLEN(hk), sizeof(u_int32_t));
else
tmp_val.dlen = LEN_HDATA(dbp, hcp->page,
hcp->hdr->dbmeta.pagesize, hcp->indx);
myval = &tmp_val;
} else
/* Regular partial put */
myval = nval;
return (__ham_replpair(dbc, myval,
F_ISSET(hcp, H_ISDUP) ? H_DUPLICATE : H_KEYDATA));
}
/*
* Given a key and a cursor, sets the cursor to the page/ndx on which
* the key resides. If the key is found, the cursor H_OK flag is set
* and the pagep, bndx, pgno (dpagep, dndx, dpgno) fields are set.
* If the key is not found, the H_OK flag is not set. If the sought
* field is non-0, the pagep, bndx, pgno (dpagep, dndx, dpgno) fields
* are set indicating where an add might take place. If it is 0,
* none of the cursor pointer field are valid.
* PUBLIC: int __ham_lookup __P((DBC *,
* PUBLIC: const DBT *, u_int32_t, db_lockmode_t, db_pgno_t *));
*/
int
__ham_lookup(dbc, key, sought, mode, pgnop)
DBC *dbc;
const DBT *key;
u_int32_t sought;
db_lockmode_t mode;
db_pgno_t *pgnop;
{
DB *dbp;
HASH_CURSOR *hcp;
db_pgno_t next_pgno;
int match, ret;
u_int8_t *dk;
dbp = dbc->dbp;
hcp = (HASH_CURSOR *)dbc->internal;
/*
* Set up cursor so that we're looking for space to add an item
* as we cycle through the pages looking for the key.
*/
if ((ret = __ham_item_reset(dbc)) != 0)
return (ret);
hcp->seek_size = sought;
hcp->bucket = __ham_call_hash(dbc, (u_int8_t *)key->data, key->size);
hcp->pgno = BUCKET_TO_PAGE(hcp, hcp->bucket);
/* look though all pages in the bucket for the key */
if ((ret = __ham_get_cpage(dbc, mode)) != 0)
return (ret);
*pgnop = PGNO_INVALID;
if (hcp->indx == NDX_INVALID) {
hcp->indx = 0;
F_CLR(hcp, H_ISDUP);
}
while (hcp->pgno != PGNO_INVALID) {
/* Are we looking for space to insert an item. */
if (hcp->seek_size != 0 &&
hcp->seek_found_page == PGNO_INVALID &&
hcp->seek_size < P_FREESPACE(dbp, hcp->page)) {
hcp->seek_found_page = hcp->pgno;
hcp->seek_found_indx = NDX_INVALID;
}
if ((ret = __ham_getindex(dbc, hcp->page, key,
H_KEYDATA, &match, &hcp->indx)) != 0)
return (ret);
/*
* If this is the first page in the bucket with space for
* inserting the requested item. Store the insert index to
* save having to look it up again later.
*/
if (hcp->seek_found_page == hcp->pgno)
hcp->seek_found_indx = hcp->indx;
if (match == 0) {
F_SET(hcp, H_OK);
dk = H_PAIRDATA(dbp, hcp->page, hcp->indx);
if (HPAGE_PTYPE(dk) == H_OFFDUP)
memcpy(pgnop, HOFFDUP_PGNO(dk),
sizeof(db_pgno_t));
return (0);
}
/* move the cursor to the next page. */
if (NEXT_PGNO(hcp->page) == PGNO_INVALID)
break;
next_pgno = NEXT_PGNO(hcp->page);
hcp->indx = 0;
if ((ret = __ham_next_cpage(dbc, next_pgno)) != 0)
return (ret);
}
F_SET(hcp, H_NOMORE);
return (DB_NOTFOUND);
}
/*
* __ham_init_dbt --
* Initialize a dbt using some possibly already allocated storage
* for items.
*
* PUBLIC: int __ham_init_dbt __P((ENV *,
* PUBLIC: DBT *, u_int32_t, void **, u_int32_t *));
*/
int
__ham_init_dbt(env, dbt, size, bufp, sizep)
ENV *env;
DBT *dbt;
u_int32_t size;
void **bufp;
u_int32_t *sizep;
{
int ret;
memset(dbt, 0, sizeof(*dbt));
if (*sizep < size) {
if ((ret = __os_realloc(env, size, bufp)) != 0) {
*sizep = 0;
return (ret);
}
*sizep = size;
}
dbt->data = *bufp;
dbt->size = size;
return (0);
}
/*
* Adjust the cursor after an insert or delete. The cursor passed is
* the one that was operated upon; we just need to check any of the
* others.
*
* len indicates the length of the item added/deleted
* add indicates if the item indicated by the cursor has just been
* added (add == 1) or deleted (add == 0).
* dup indicates if the addition occurred into a duplicate set.
*
* PUBLIC: int __hamc_update
* PUBLIC: __P((DBC *, u_int32_t, db_ham_curadj, int));
*/
static int
__hamc_update_getorder(cp, dbc, orderp, pgno, is_dup, args)
DBC *dbc, *cp;
u_int32_t *orderp;
db_pgno_t pgno;
u_int32_t is_dup;
void *args;
{
HASH_CURSOR *hcp, *lcp;
COMPQUIET(args, NULL);
COMPQUIET(pgno, 0);
hcp = (HASH_CURSOR *)dbc->internal;
if (cp == dbc || cp->dbtype != DB_HASH)
return (0);
lcp = (HASH_CURSOR *)cp->internal;
if (F_ISSET(lcp, H_DELETED) &&
hcp->pgno == lcp->pgno &&
hcp->indx == lcp->indx &&
*orderp < lcp->order &&
(!is_dup || hcp->dup_off == lcp->dup_off) &&
!MVCC_SKIP_CURADJ(cp, lcp->pgno))
*orderp = lcp->order;
return (0);
}
struct __hamc_update_setorder_args {
int was_mod, was_add;
u_int32_t len, order;
DB_TXN *my_txn;
};
static int
__hamc_update_setorder(cp, dbc, foundp, pgno, is_dup, vargs)
DBC *dbc, *cp;
u_int32_t *foundp;
db_pgno_t pgno;
u_int32_t is_dup;
void *vargs;
{
HASH_CURSOR *hcp, *lcp;
struct __hamc_update_setorder_args *args;
COMPQUIET(pgno, 0);
if (cp == dbc || cp->dbtype != DB_HASH)
return (0);
hcp = (HASH_CURSOR *)dbc->internal;
lcp = (HASH_CURSOR *)cp->internal;
if (lcp->pgno != hcp->pgno ||
lcp->indx == NDX_INVALID ||
MVCC_SKIP_CURADJ(cp, lcp->pgno))
return (0);
args = vargs;
/*
* We're about to move things out from under this
* cursor. Clear any cached streaming information.
*/
lcp->stream_start_pgno = PGNO_INVALID;
if (args->my_txn != NULL && cp->txn != args->my_txn)
*foundp = 1;
if (!is_dup) {
if (args->was_add == 1) {
/*
* This routine is not called to add
* non-dup records which are always put
* at the end. It is only called from
* recovery in this case and the
* cursor will be marked deleted.
* We are "undeleting" so unmark all
* cursors with the same order.
*/
if (lcp->indx == hcp->indx &&
F_ISSET(lcp, H_DELETED)) {
if (lcp->order == hcp->order)
F_CLR(lcp, H_DELETED);
else if (lcp->order >
hcp->order) {
/*
* If we've moved this cursor's
* index, split its order
* number--i.e., decrement it by
* enough so that the lowest
* cursor moved has order 1.
* cp_arg->order is the split
* point, so decrement by it.
*/
lcp->order -=
hcp->order;
lcp->indx += 2;
}
} else if (lcp->indx >= hcp->indx)
lcp->indx += 2;
} else {
if (lcp->indx > hcp->indx) {
lcp->indx -= 2;
if (lcp->indx == hcp->indx &&
F_ISSET(lcp, H_DELETED))
lcp->order += args->order;
} else if (lcp->indx == hcp->indx &&
!F_ISSET(lcp, H_DELETED)) {
F_SET(lcp, H_DELETED);
F_CLR(lcp, H_ISDUP);
lcp->order = args->order;
}
}
} else if (lcp->indx == hcp->indx) {
/*
* Handle duplicates. This routine is only
* called for on page dups. Off page dups are
* handled by btree/rtree code.
*/
if (args->was_add == 1) {
lcp->dup_tlen += args->len;
if (lcp->dup_off == hcp->dup_off &&
F_ISSET(hcp, H_DELETED) &&
F_ISSET(lcp, H_DELETED)) {
/* Abort of a delete. */
if (lcp->order == hcp->order)
F_CLR(lcp, H_DELETED);
else if (lcp->order >
hcp->order) {
lcp->order -=
(hcp->order -1);
lcp->dup_off += args->len;
}
} else if (lcp->dup_off >
hcp->dup_off || (!args->was_mod &&
lcp->dup_off == hcp->dup_off))
lcp->dup_off += args->len;
} else {
lcp->dup_tlen -= args->len;
if (lcp->dup_off > hcp->dup_off) {
lcp->dup_off -= args->len;
if (lcp->dup_off ==
hcp->dup_off &&
F_ISSET(lcp, H_DELETED))
lcp->order += args->order;
} else if (!args->was_mod &&
lcp->dup_off == hcp->dup_off &&
!F_ISSET(lcp, H_DELETED)) {
F_SET(lcp, H_DELETED);
lcp->order = args->order;
}
}
}
return (0);
}
int
__hamc_update(dbc, len, operation, is_dup)
DBC *dbc;
u_int32_t len;
db_ham_curadj operation;
int is_dup;
{
DB *dbp;
DB_LSN lsn;
HASH_CURSOR *hcp;
int ret;
u_int32_t found;
struct __hamc_update_setorder_args args;
dbp = dbc->dbp;
hcp = (HASH_CURSOR *)dbc->internal;
/*
* Adjustment will only be logged if this is a subtransaction.
* Only subtransactions can abort and effect their parent
* transactions cursors.
*/
args.my_txn = IS_SUBTRANSACTION(dbc->txn) ? dbc->txn : NULL;
args.len = len;
switch (operation) {
case DB_HAM_CURADJ_DEL:
args.was_mod = 0;
args.was_add = 0;
break;
case DB_HAM_CURADJ_ADD:
args.was_mod = 0;
args.was_add = 1;
break;
case DB_HAM_CURADJ_DELMOD:
args.was_mod = 1;
args.was_add = 0;
break;
case DB_HAM_CURADJ_ADDMOD:
args.was_mod = 1;
args.was_add = 1;
break;
default:
return (EINVAL);
}
/*
* Calculate the order of this deleted record.
* This will be one greater than any cursor that is pointing
* at this record and already marked as deleted.
*/
if (args.was_add == 0) {
if ((ret = __db_walk_cursors(dbp, dbc, __hamc_update_getorder,
&args.order, 0, (u_int32_t)is_dup, NULL)) != 0)
return (ret);
args.order++;
hcp->order = args.order;
}
if ((ret = __db_walk_cursors(dbp, dbc,
__hamc_update_setorder, &found, 0, (u_int32_t)is_dup, &args)) != 0)
return (ret);
if (found != 0 && DBC_LOGGING(dbc)) {
if ((ret = __ham_curadj_log(dbp, args.my_txn, &lsn, 0,
hcp->pgno, hcp->indx, len, hcp->dup_off,
(int)operation, is_dup, args.order)) != 0)
return (ret);
}
return (0);
}
struct __ham_get_clist_args {
u_int nalloc, nused;
DBC **listp;
};
static int
__ham_get_clist_func(dbc, my_dbc, countp, pgno, indx, vargs)
DBC *dbc, *my_dbc;
u_int32_t *countp;
db_pgno_t pgno;
u_int32_t indx;
void *vargs;
{
int ret;
struct __ham_get_clist_args *args;
COMPQUIET(my_dbc, NULL);
COMPQUIET(countp, NULL);
args = vargs;
/*
* We match if dbc->pgno matches the specified
* pgno, and if either the dbc->indx matches
* or we weren't given an index.
*/
if (dbc->internal->pgno == pgno &&
(indx == NDX_INVALID ||
dbc->internal->indx == indx) &&
!MVCC_SKIP_CURADJ(dbc, pgno)) {
if (args->nused >= args->nalloc) {
args->nalloc += 10;
if ((ret = __os_realloc(dbc->dbp->env,
args->nalloc * sizeof(HASH_CURSOR *),
&args->listp)) != 0)
return (ret);
}
args->listp[args->nused++] = dbc;
}
return (0);
}
/*
* __ham_get_clist --
*
* Get a list of cursors either on a particular bucket or on a particular
* page and index combination. The former is so that we can update
* cursors on a split. The latter is so we can update cursors when we
* move items off page.
*
* PUBLIC: int __ham_get_clist __P((DB *, db_pgno_t, u_int32_t, DBC ***));
*/
int
__ham_get_clist(dbp, pgno, indx, listp)
DB *dbp;
db_pgno_t pgno;
u_int32_t indx;
DBC ***listp;
{
ENV *env;
int ret;
u_int32_t count;
struct __ham_get_clist_args args;
env = dbp->env;
args.listp = NULL;
args.nalloc = args.nused = 0;
if ((ret = __db_walk_cursors(dbp, NULL,
__ham_get_clist_func, &count, pgno, indx, &args)) != 0)
return (ret);
if (args.listp != NULL) {
if (args.nused >= args.nalloc) {
args.nalloc++;
if ((ret = __os_realloc(env,
args.nalloc * sizeof(HASH_CURSOR *),
&args.listp)) != 0)
return (ret);
}
args.listp[args.nused] = NULL;
}
*listp = args.listp;
return (0);
}
static int
__hamc_writelock(dbc)
DBC *dbc;
{
DB_LOCK tmp_lock;
HASH_CURSOR *hcp;
int ret;
/*
* All we need do is acquire the lock and let the off-page
* dup tree do its thing.
*/
if (!STD_LOCKING(dbc))
return (0);
hcp = (HASH_CURSOR *)dbc->internal;
ret = 0;
if ((!LOCK_ISSET(hcp->lock) || hcp->lock_mode != DB_LOCK_WRITE)) {
tmp_lock = hcp->lock;
if ((ret = __ham_lock_bucket(dbc, DB_LOCK_WRITE)) == 0 &&
tmp_lock.mode != DB_LOCK_WWRITE)
ret = __LPUT(dbc, tmp_lock);
}
return (ret);
}
|
a8dc8d20c15e1cd148d30ae552fc74c37b8933c0
|
08a26f17a11f0aa2263001f9b1014a4b906f8bb3
|
/src/core/vector.c
|
b22603fe6e932a9d606c38c3f4adb96c8a901295
|
[
"MIT"
] |
permissive
|
janet-lang/janet
|
e4cbb3160e9fd8a0d406383e3d757e628ee4e736
|
a13aeaf9557250639018802baceeefb78b834846
|
refs/heads/master
| 2023-09-05T20:33:15.037901
| 2023-09-04T15:27:27
| 2023-09-04T15:27:27
| 84,521,458
| 3,233
| 270
|
MIT
| 2023-09-14T15:21:53
| 2017-03-10T05:08:35
|
C
|
UTF-8
|
C
| false
| false
| 2,067
|
c
|
vector.c
|
/*
* Copyright (c) 2023 Calvin Rose
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef JANET_AMALG
#include "features.h"
#include "vector.h"
#include "util.h"
#endif
/* Grow the buffer dynamically. Used for push operations. */
void *janet_v_grow(void *v, int32_t increment, int32_t itemsize) {
int32_t dbl_cur = (NULL != v) ? 2 * janet_v__cap(v) : 0;
int32_t min_needed = janet_v_count(v) + increment;
int32_t m = dbl_cur > min_needed ? dbl_cur : min_needed;
size_t newsize = ((size_t) itemsize) * m + sizeof(int32_t) * 2;
int32_t *p = (int32_t *) janet_srealloc(v ? janet_v__raw(v) : 0, newsize);
if (!v) p[1] = 0;
p[0] = m;
return p + 2;
}
/* Convert a buffer to normal allocated memory (forget capacity) */
void *janet_v_flattenmem(void *v, int32_t itemsize) {
char *p;
if (NULL == v) return NULL;
size_t size = (size_t) itemsize * janet_v__cnt(v);
p = janet_malloc(size);
if (NULL != p) {
safe_memcpy(p, v, size);
return p;
} else {
JANET_OUT_OF_MEMORY;
}
}
|
1d0b3185f9dac71bfd4b6d6a419150e8e5dd86e1
|
88aca3340574f733b9ecd6f76708ecd2d57cb07e
|
/vendor/bundle/ruby/2.6.0/gems/rb-fsevent-0.11.1/ext/fsevent_watch/FSEventsFix.c
|
60e3d37bd6073b41391bd8761a0be013a226d023
|
[
"MIT",
"Apache-2.0"
] |
permissive
|
collabnix/dockerlabs
|
65c63a8424d34120bddc0fc8d6fd54a688953491
|
0f2a6b906a8ca0ebc28561236d4d6516f93b184c
|
refs/heads/master
| 2023-09-05T07:30:30.601797
| 2023-09-05T07:25:53
| 2023-09-05T07:25:53
| 153,069,455
| 5,239
| 1,854
|
Apache-2.0
| 2023-09-03T05:51:41
| 2018-10-15T07:19:18
|
PHP
|
UTF-8
|
C
| false
| false
| 22,897
|
c
|
FSEventsFix.c
|
/*
* FSEventsFix
*
* Resolves a long-standing bug in realpath() that prevents FSEvents API from
* monitoring certain folders on a wide range of OS X released (10.6-10.10 at least).
*
* The underlying issue is that for some folders, realpath() call starts returning
* a path with incorrect casing (e.g. "/users/smt" instead of "/Users/smt").
* FSEvents is case-sensitive and calls realpath() on the paths you pass in, so
* an incorrect value returned by realpath() prevents FSEvents from seeing any
* change events.
*
* See the discussion at https://github.com/thibaudgg/rb-fsevent/issues/10 about
* the history of this bug and how this library came to exist.
*
* This library uses Facebook's fishhook to replace a custom implementation of
* realpath in place of the system realpath; FSEvents will then invoke our custom
* implementation (which does not screw up the names) and will thus work correctly.
*
* Our implementation of realpath is based on the open-source implementation from
* OS X 10.10, with a single change applied (enclosed in "BEGIN WORKAROUND FOR
* OS X BUG" ... "END WORKAROUND FOR OS X BUG").
*
* Include FSEventsFix.{h,c} into your project and call FSEventsFixInstall().
*
* It is recommended that you install FSEventsFix on demand, using FSEventsFixIsBroken
* to check if the folder you're about to pass to FSEventStreamCreate needs the fix.
* Note that the fix must be applied before calling FSEventStreamCreate.
*
* FSEventsFixIsBroken requires a path that uses the correct case for all folder names,
* i.e. a path provided by the system APIs or constructed from folder names provided
* by the directory enumeration APIs.
*
* Copyright (c) 2015 Andrey Tarantsov <andrey@tarantsov.com>
* Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Based on a realpath implementation from Apple libc 498.1.7, taken from
* http://www.opensource.apple.com/source/Libc/Libc-498.1.7/stdlib/FreeBSD/realpath.c
* and provided under the following license:
*
* Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
*
* 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. The names of the authors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* 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.
*/
#include "FSEventsFix.h"
#include <dispatch/dispatch.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <dlfcn.h>
const char *const FSEventsFixVersionString = "0.11.0";
#pragma mark - Forward declarations
static char *(*orig_realpath)(const char *restrict file_name, char resolved_name[PATH_MAX]);
static char *CFURL_realpath(const char *restrict file_name, char resolved_name[PATH_MAX]);
static char *FSEventsFix_realpath_wrapper(const char *restrict src, char *restrict dst);
static void _FSEventsFixHookInstall();
static void _FSEventsFixHookUninstall();
#pragma mark - Internal state
static dispatch_queue_t g_queue = NULL;
static int64_t g_enable_refcount = 0;
static bool g_in_self_test = false;
static bool g_hook_operational = false;
static void(^g_logging_block)(FSEventsFixMessageType type, const char *message);
static FSEventsFixDebugOptions g_debug_opt = 0;
typedef struct {
char *name;
void *replacement;
void *original;
uint hooked_symbols;
} rebinding_t;
static rebinding_t g_rebindings[] = {
{ "_realpath$DARWIN_EXTSN", (void *) &FSEventsFix_realpath_wrapper, (void *) &realpath, 0 }
};
static const uint g_rebindings_nel = sizeof(g_rebindings) / sizeof(g_rebindings[0]);
#pragma mark - Logging
static void _FSEventsFixLog(FSEventsFixMessageType type, const char *__restrict fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
static void _FSEventsFixLog(FSEventsFixMessageType type, const char *__restrict fmt, ...) {
if (g_logging_block) {
char *message = NULL;
va_list va;
va_start(va, fmt);
vasprintf(&message, fmt, va);
va_end(va);
if (message) {
if (!!(g_debug_opt & FSEventsFixDebugOptionLogToStderr)) {
fprintf(stderr, "FSEventsFix: %s\n", message);
}
if (g_logging_block) {
g_logging_block(type, message);
}
free(message);
}
}
}
#pragma mark - API
void _FSEventsFixInitialize() {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
g_queue = dispatch_queue_create("FSEventsFix", DISPATCH_QUEUE_SERIAL);
});
}
void FSEventsFixConfigure(FSEventsFixDebugOptions debugOptions, void(^loggingBlock)(FSEventsFixMessageType severity, const char *message)) {
_FSEventsFixInitialize();
loggingBlock = Block_copy(loggingBlock);
dispatch_sync(g_queue, ^{
g_debug_opt = debugOptions;
g_logging_block = loggingBlock;
});
}
// Must be called from the private serial queue.
void _FSEventsFixSelfTest() {
g_in_self_test = true;
g_hook_operational = false;
static char result[1024];
realpath("/Etc/__!FSEventsFixSelfTest!__", result);
g_in_self_test = false;
}
void FSEventsFixEnable() {
_FSEventsFixInitialize();
dispatch_sync(g_queue, ^{
if (++g_enable_refcount == 1) {
orig_realpath = dlsym(RTLD_DEFAULT, "realpath");
_FSEventsFixHookInstall();
_FSEventsFixSelfTest();
if (g_hook_operational) {
_FSEventsFixLog(FSEventsFixMessageTypeStatusChange, "Enabled");
} else {
_FSEventsFixLog(FSEventsFixMessageTypeFatalError, "Failed to enable (hook not called)");
}
}
});
}
void FSEventsFixDisable() {
_FSEventsFixInitialize();
dispatch_sync(g_queue, ^{
if (g_enable_refcount == 0) {
abort();
}
if (--g_enable_refcount == 0) {
_FSEventsFixHookUninstall();
_FSEventsFixSelfTest();
if (!g_hook_operational) {
_FSEventsFixLog(FSEventsFixMessageTypeStatusChange, "Disabled");
} else {
_FSEventsFixLog(FSEventsFixMessageTypeFatalError, "Failed to disable (hook still called)");
}
}
});
}
bool FSEventsFixIsOperational() {
_FSEventsFixInitialize();
__block bool result = false;
dispatch_sync(g_queue, ^{
result = g_hook_operational;
});
return result;
}
bool _FSEventsFixIsBroken_noresolve(const char *resolved) {
if (!!(g_debug_opt & FSEventsFixDebugOptionSimulateBroken)) {
if (strstr(resolved, FSEventsFixSimulatedBrokenFolderMarker)) {
return true;
}
}
char *reresolved = realpath(resolved, NULL);
if (reresolved) {
bool broken = (0 != strcmp(resolved, reresolved));
free(reresolved);
return broken;
} else {
return true;
}
}
bool FSEventsFixIsBroken(const char *path) {
char *resolved = CFURL_realpath(path, NULL);
if (!resolved) {
return true;
}
bool broken = _FSEventsFixIsBroken_noresolve(resolved);
free(resolved);
return broken;
}
char *FSEventsFixCopyRootBrokenFolderPath(const char *inpath) {
if (!FSEventsFixIsBroken(inpath)) {
return NULL;
}
// get a mutable copy of an absolute path
char *path = CFURL_realpath(inpath, NULL);
if (!path) {
return NULL;
}
for (;;) {
char *sep = strrchr(path, '/');
if ((sep == NULL) || (sep == path)) {
break;
}
*sep = 0;
if (!_FSEventsFixIsBroken_noresolve(path)) {
*sep = '/';
break;
}
}
return path;
}
static void _FSEventsFixAttemptRepair(const char *folder) {
int rv = rename(folder, folder);
if (!!(g_debug_opt & FSEventsFixDebugOptionSimulateRepair)) {
const char *pos = strstr(folder, FSEventsFixSimulatedBrokenFolderMarker);
if (pos) {
char *fixed = strdup(folder);
fixed[pos - folder] = 0;
strcat(fixed, pos + strlen(FSEventsFixSimulatedBrokenFolderMarker));
rv = rename(folder, fixed);
free(fixed);
}
}
if (rv != 0) {
if (errno == EPERM) {
_FSEventsFixLog(FSEventsFixMessageTypeResult, "Permission error when trying to repair '%s'", folder);
} else {
_FSEventsFixLog(FSEventsFixMessageTypeExpectedFailure, "Unknown error when trying to repair '%s': errno = %d", folder, errno);
}
}
}
FSEventsFixRepairStatus FSEventsFixRepairIfNeeded(const char *inpath) {
char *root = FSEventsFixCopyRootBrokenFolderPath(inpath);
if (root == NULL) {
return FSEventsFixRepairStatusNotBroken;
}
for (;;) {
_FSEventsFixAttemptRepair(root);
char *newRoot = FSEventsFixCopyRootBrokenFolderPath(inpath);
if (newRoot == NULL) {
_FSEventsFixLog(FSEventsFixMessageTypeResult, "Repaired '%s' in '%s'", root, inpath);
free(root);
return FSEventsFixRepairStatusRepaired;
}
if (0 == strcmp(root, newRoot)) {
_FSEventsFixLog(FSEventsFixMessageTypeResult, "Failed to repair '%s' in '%s'", root, inpath);
free(root);
free(newRoot);
return FSEventsFixRepairStatusFailed;
}
_FSEventsFixLog(FSEventsFixMessageTypeResult, "Partial success, repaired '%s' in '%s'", root, inpath);
free(root);
root = newRoot;
}
}
#pragma mark - FSEventsFix realpath wrapper
static char *FSEventsFix_realpath_wrapper(const char * __restrict src, char * __restrict dst) {
if (g_in_self_test) {
if (strstr(src, "__!FSEventsFixSelfTest!__")) {
g_hook_operational = true;
}
}
// CFURL_realpath doesn't support putting where resolution failed into the
// dst buffer, so we call the original realpath here first and if it gets a
// result, replace that with the output of CFURL_realpath. that way all the
// features of the original realpath are available.
char *rv = NULL;
char *orv = orig_realpath(src, dst);
if (orv != NULL) { rv = CFURL_realpath(src, dst); }
if (!!(g_debug_opt & FSEventsFixDebugOptionLogCalls)) {
char *result = rv ?: dst;
_FSEventsFixLog(FSEventsFixMessageTypeCall, "realpath(%s) => %s\n", src, result);
}
if (!!(g_debug_opt & FSEventsFixDebugOptionUppercaseReturn)) {
char *result = rv ?: dst;
if (result) {
for (char *pch = result; *pch; ++pch) {
*pch = (char)toupper(*pch);
}
}
}
return rv;
}
#pragma mark - realpath
// naive implementation of realpath on top of CFURL
// NOTE: doesn't quite support the full range of errno results one would
// expect here, in part because some of these functions just return a boolean,
// and in part because i'm not dealing with messy CFErrorRef objects and
// attempting to translate those to sane errno values.
// NOTE: the OSX realpath will return _where_ resolution failed in resolved_name
// if passed in and return NULL. we can't properly support that extension here
// since the resolution happens entirely behind the scenes to us in CFURL.
static char* CFURL_realpath(const char *file_name, char resolved_name[PATH_MAX])
{
char* resolved;
CFURLRef url1;
CFURLRef url2;
CFStringRef path;
if (file_name == NULL) {
errno = EINVAL;
return (NULL);
}
#if __DARWIN_UNIX03
if (*file_name == 0) {
errno = ENOENT;
return (NULL);
}
#endif
// create a buffer to store our result if we weren't passed one
if (!resolved_name) {
if ((resolved = malloc(PATH_MAX)) == NULL) return (NULL);
} else {
resolved = resolved_name;
}
url1 = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)file_name, (CFIndex)strlen(file_name), false);
if (url1 == NULL) { goto error_return; }
url2 = CFURLCopyAbsoluteURL(url1);
CFRelease(url1);
if (url2 == NULL) { goto error_return; }
url1 = CFURLCreateFileReferenceURL(NULL, url2, NULL);
CFRelease(url2);
if (url1 == NULL) { goto error_return; }
// if there are multiple hard links to the original path, this may end up
// being _completely_ different from what was intended
url2 = CFURLCreateFilePathURL(NULL, url1, NULL);
CFRelease(url1);
if (url2 == NULL) { goto error_return; }
path = CFURLCopyFileSystemPath(url2, kCFURLPOSIXPathStyle);
CFRelease(url2);
if (path == NULL) { goto error_return; }
bool success = CFStringGetCString(path, resolved, PATH_MAX, kCFStringEncodingUTF8);
CFRelease(path);
if (!success) { goto error_return; }
return resolved;
error_return:
if (!resolved_name) {
// we weren't passed in an output buffer and created our own. free it
int e = errno;
free(resolved);
errno = e;
}
return (NULL);
}
#pragma mark - fishhook
// Copyright (c) 2013, Facebook, Inc.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * 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.
// * Neither the name Facebook 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
#import <stdlib.h>
#import <string.h>
#import <sys/types.h>
#import <mach-o/dyld.h>
#import <mach-o/loader.h>
#import <mach-o/nlist.h>
#ifdef __LP64__
typedef struct mach_header_64 mach_header_t;
typedef struct segment_command_64 segment_command_t;
typedef struct section_64 section_t;
typedef struct nlist_64 nlist_t;
#define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT_64
#else
typedef struct mach_header mach_header_t;
typedef struct segment_command segment_command_t;
typedef struct section section_t;
typedef struct nlist nlist_t;
#define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT
#endif
static volatile bool g_hook_installed = false;
static void _FSEventsFixHookUpdateSection(section_t *section, intptr_t slide, nlist_t *symtab, char *strtab, uint32_t *indirect_symtab)
{
uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1;
void **indirect_symbol_bindings = (void **)((uintptr_t)slide + section->addr);
for (uint i = 0; i < section->size / sizeof(void *); i++) {
uint32_t symtab_index = indirect_symbol_indices[i];
if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL ||
symtab_index == (INDIRECT_SYMBOL_LOCAL | INDIRECT_SYMBOL_ABS)) {
continue;
}
uint32_t strtab_offset = symtab[symtab_index].n_un.n_strx;
char *symbol_name = strtab + strtab_offset;
for (rebinding_t *cur = g_rebindings, *end = g_rebindings + g_rebindings_nel; cur < end; ++cur) {
if (strcmp(symbol_name, cur->name) == 0) {
if (g_hook_installed) {
if (indirect_symbol_bindings[i] != cur->replacement) {
indirect_symbol_bindings[i] = cur->replacement;
++cur->hooked_symbols;
}
} else if (cur->original != NULL) {
if (indirect_symbol_bindings[i] == cur->replacement) {
indirect_symbol_bindings[i] = cur->original;
if (cur->hooked_symbols > 0) {
--cur->hooked_symbols;
}
}
}
goto symbol_loop;
}
}
symbol_loop:;
}
}
static void _FSEventsFixHookUpdateImage(const struct mach_header *header, intptr_t slide) {
Dl_info info;
if (dladdr(header, &info) == 0) {
return;
}
segment_command_t *cur_seg_cmd;
segment_command_t *linkedit_segment = NULL;
struct symtab_command* symtab_cmd = NULL;
struct dysymtab_command* dysymtab_cmd = NULL;
uintptr_t cur = (uintptr_t)header + sizeof(mach_header_t);
for (uint i = 0; i < header->ncmds; i++, cur += cur_seg_cmd->cmdsize) {
cur_seg_cmd = (segment_command_t *)cur;
if (cur_seg_cmd->cmd == LC_SEGMENT_ARCH_DEPENDENT) {
if (strcmp(cur_seg_cmd->segname, SEG_LINKEDIT) == 0) {
linkedit_segment = cur_seg_cmd;
}
} else if (cur_seg_cmd->cmd == LC_SYMTAB) {
symtab_cmd = (struct symtab_command*)cur_seg_cmd;
} else if (cur_seg_cmd->cmd == LC_DYSYMTAB) {
dysymtab_cmd = (struct dysymtab_command*)cur_seg_cmd;
}
}
if (!symtab_cmd || !dysymtab_cmd || !linkedit_segment ||
!dysymtab_cmd->nindirectsyms) {
return;
}
// Find base symbol/string table addresses
uintptr_t linkedit_base = (uintptr_t)slide + linkedit_segment->vmaddr - linkedit_segment->fileoff;
nlist_t *symtab = (nlist_t *)(linkedit_base + symtab_cmd->symoff);
char *strtab = (char *)(linkedit_base + symtab_cmd->stroff);
// Get indirect symbol table (array of uint32_t indices into symbol table)
uint32_t *indirect_symtab = (uint32_t *)(linkedit_base + dysymtab_cmd->indirectsymoff);
cur = (uintptr_t)header + sizeof(mach_header_t);
for (uint i = 0; i < header->ncmds; i++, cur += cur_seg_cmd->cmdsize) {
cur_seg_cmd = (segment_command_t *)cur;
if (cur_seg_cmd->cmd == LC_SEGMENT_ARCH_DEPENDENT) {
if (strcmp(cur_seg_cmd->segname, SEG_DATA) != 0) {
continue;
}
for (uint j = 0; j < cur_seg_cmd->nsects; j++) {
section_t *sect =
(section_t *)(cur + sizeof(segment_command_t)) + j;
if ((sect->flags & SECTION_TYPE) == S_LAZY_SYMBOL_POINTERS) {
_FSEventsFixHookUpdateSection(sect, slide, symtab, strtab, indirect_symtab);
}
if ((sect->flags & SECTION_TYPE) == S_NON_LAZY_SYMBOL_POINTERS) {
_FSEventsFixHookUpdateSection(sect, slide, symtab, strtab, indirect_symtab);
}
}
}
}
}
static void _FSEventsFixHookSaveOriginals() {
for (rebinding_t *cur = g_rebindings, *end = g_rebindings + g_rebindings_nel; cur < end; ++cur) {
void *original = cur->original = dlsym(RTLD_DEFAULT, cur->name+1);
if (!original) {
const char *error = dlerror();
_FSEventsFixLog(FSEventsFixMessageTypeFatalError, "Cannot find symbol %s, dlsym says: %s\n", cur->name, error);
}
}
}
static void _FSEventsFixHookUpdate() {
uint32_t c = _dyld_image_count();
for (uint32_t i = 0; i < c; i++) {
_FSEventsFixHookUpdateImage(_dyld_get_image_header(i), _dyld_get_image_vmaddr_slide(i));
}
}
static void _FSEventsFixHookInstall() {
static bool first_rebinding_done = false;
if (!g_hook_installed) {
g_hook_installed = true;
if (!first_rebinding_done) {
first_rebinding_done = true;
_FSEventsFixHookSaveOriginals();
_dyld_register_func_for_add_image(_FSEventsFixHookUpdateImage);
} else {
_FSEventsFixHookUpdate();
}
}
}
static void _FSEventsFixHookUninstall() {
if (g_hook_installed) {
g_hook_installed = false;
_FSEventsFixHookUpdate();
}
}
|
b0b68d37cfd077a5010077bbbe0e24b567cde5a3
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/mips/include/asm/mach-generic/kmalloc.h
|
a5d669086ed94a51a2fc03101dbe3e1be7b39f23
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 325
|
h
|
kmalloc.h
|
#ifndef __ASM_MACH_GENERIC_KMALLOC_H
#define __ASM_MACH_GENERIC_KMALLOC_H
#ifndef CONFIG_DMA_COHERENT
/*
* Total overkill for most systems but need as a safe default.
* Set this one if any device in the system might do non-coherent DMA.
*/
#define ARCH_DMA_MINALIGN 128
#endif
#endif /* __ASM_MACH_GENERIC_KMALLOC_H */
|
aa4026730dc83b87736fdca389b9806c97d8188f
|
f367e4b66a1ee42e85830b31df88f63723c36a47
|
/lib/monkey/examples/hello.c
|
d54c3dde71e849eb8e729d0a9a98aed6ba584d4f
|
[
"Apache-2.0"
] |
permissive
|
fluent/fluent-bit
|
06873e441162b92941024e9a7e9e8fc934150bf7
|
1a41f49dc2f3ae31a780caa9ffd6137b1d703065
|
refs/heads/master
| 2023-09-05T13:44:55.347372
| 2023-09-05T10:14:33
| 2023-09-05T10:14:33
| 29,933,948
| 4,907
| 1,565
|
Apache-2.0
| 2023-09-14T10:17:02
| 2015-01-27T20:41:52
|
C
|
UTF-8
|
C
| false
| false
| 1,858
|
c
|
hello.c
|
/* Monkey HTTP Daemon
* ------------------
* Copyright (C) 2012, Lauri Kasanen <cand@gmx.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <libmonkey.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
/*
* This example shows how to start the server, and point it to /tmp.
* It also creates /tmp/index.html.
*/
static void write_index() {
const char *path = "/tmp/index.html";
FILE *f = fopen(path, "w");
if (!f) exit(1);
fprintf(f, "<html><body><h2>Hello Monkey</h2></body></html>");
fclose(f);
}
int main() {
int ret;
write_index();
// All defaults. Bind to all interfaces, port 2001, default plugins, /tmp.
// No callbacks are used.
mklib_ctx ctx = mklib_init(NULL, 0, 0, "/tmp");
if (!ctx) return 1;
// The default has no index files, let's set index.html as one.
ret = mklib_config(ctx, MKC_INDEXFILE, "index.html", NULL);
if (!ret) return 1;
// Start the server.
mklib_start(ctx);
// I'm now free to do my own things. I'm just going to wait for a keypress.
printf("All set and running! Visit me, I default to localhost:2001.\n");
printf("Press a key to exit.\n");
getchar();
mklib_stop(ctx);
return 0;
}
|
4207aeacc885df0a6250ac9952f41aab48f1205c
|
e814383d36a10839104efaa4df277996ab220fa3
|
/ompi/mca/bml/r2/bml_r2_component.c
|
9420a2e0bc243c26d005e7c0d47b1f5e762dab32
|
[
"mpich2",
"BSD-3-Clause-Open-MPI"
] |
permissive
|
open-mpi/ompi
|
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
|
1edfdb025c4450f694600083ad871cf06c8d45cd
|
refs/heads/main
| 2023-09-01T01:30:02.040705
| 2023-08-29T17:32:18
| 2023-08-29T17:32:18
| 24,107,001
| 2,008
| 973
|
NOASSERTION
| 2023-09-14T20:59:26
| 2014-09-16T16:08:30
|
C
|
UTF-8
|
C
| false
| false
| 3,267
|
c
|
bml_r2_component.c
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2006 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2010-2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2020 Amazon.com, Inc. or its affiliates.
* All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "opal/util/event.h"
#include "opal/mca/btl/base/base.h"
#include "ompi/mca/bml/bml.h"
#include "bml_r2.h"
#include "mpi.h"
static int mca_bml_r2_component_register(void);
mca_bml_base_component_2_0_0_t mca_bml_r2_component = {
/* First, the mca_base_component_t struct containing meta
information about the component itself */
.bml_version = {
MCA_BML_BASE_VERSION_2_1_0,
.mca_component_name = "r2",
MCA_BASE_MAKE_VERSION(component, OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION,
OMPI_RELEASE_VERSION),
.mca_open_component = mca_bml_r2_component_open,
.mca_close_component = mca_bml_r2_component_close,
.mca_register_component_params = mca_bml_r2_component_register,
},
.bml_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
.bml_init = mca_bml_r2_component_init,
};
static int mca_bml_r2_component_register(void)
{
mca_bml_r2.show_unreach_errors = true;
(void) mca_base_component_var_register(&mca_bml_r2_component.bml_version,
"show_unreach_errors",
"Show error message when procs are unreachable",
MCA_BASE_VAR_TYPE_BOOL, NULL, 0,0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_bml_r2.show_unreach_errors);
return OMPI_SUCCESS;
}
int mca_bml_r2_component_open(void)
{
return OMPI_SUCCESS;
}
int mca_bml_r2_component_close(void)
{
return OMPI_SUCCESS;
}
mca_bml_base_module_t* mca_bml_r2_component_init( int* priority,
bool enable_progress_threads,
bool enable_mpi_threads )
{
/* initialize BTLs */
if(OMPI_SUCCESS != mca_btl_base_select(enable_progress_threads,enable_mpi_threads))
return NULL;
*priority = 100;
mca_bml_r2.btls_added = false;
return &mca_bml_r2.super;
}
|
650a955086186e70d457092f7c5503a3fe1f39a7
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/crypto/sunxi/sunxi_ss.c
|
9a050855bde42e124d3f6d64c652c822ffcc882d
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 22,829
|
c
|
sunxi_ss.c
|
/*
* The driver of SUNXI SecuritySystem controller.
*
* Copyright (C) 2013 Allwinner.
*
* Mintow <duanmintao@allwinnertech.com>
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/clk.h>
#include <linux/clk/sunxi.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <crypto/hash.h>
#include <crypto/md5.h>
#include <crypto/des.h>
#include <crypto/internal/hash.h>
#include <crypto/internal/rng.h>
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
#include <linux/dma/sunxi-dma.h>
#include "sunxi_ss.h"
#include "sunxi_ss_proc.h"
#include "sunxi_ss_reg.h"
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
static const struct of_device_id sunxi_ss_of_match[] = {
{.compatible = "allwinner,sunxi-ce",},
{},
};
MODULE_DEVICE_TABLE(of, sunxi_ss_of_match);
#endif
sunxi_ss_t *ss_dev = NULL;
static DEFINE_MUTEX(ss_lock);
void ss_dev_lock(void)
{
mutex_lock(&ss_lock);
}
void ss_dev_unlock(void)
{
mutex_unlock(&ss_lock);
}
void __iomem *ss_membase(void)
{
return ss_dev->base_addr;
}
void ss_reset(void)
{
SS_ENTER();
sunxi_periph_reset_assert(ss_dev->mclk);
sunxi_periph_reset_deassert(ss_dev->mclk);
}
void ss_clk_set(u32 rate)
{
#ifdef CONFIG_EVB_PLATFORM
int ret = 0;
ret = clk_get_rate(ss_dev->mclk);
if (ret == rate)
return;
SS_DBG("Change the SS clk to %d MHz. \n", rate/1000000);
ret = clk_set_rate(ss_dev->mclk, rate);
if (ret != 0)
SS_ERR("clk_set_rate(%d) failed! return %d\n", rate, ret);
#endif
}
static int ss_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
unsigned int keylen)
{
int ret = 0;
ss_aes_ctx_t *ctx = crypto_ablkcipher_ctx(tfm);
SS_DBG("keylen = %d\n", keylen);
if (ctx->comm.flags & SS_FLAG_NEW_KEY) {
SS_ERR("The key has already update.\n");
return -EBUSY;
}
ret = ss_aes_key_valid(tfm, keylen);
if (ret != 0)
return ret;
ctx->key_size = keylen;
memcpy(ctx->key, key, keylen);
if (keylen < AES_KEYSIZE_256)
memset(&ctx->key[keylen], 0, AES_KEYSIZE_256 - keylen);
ctx->comm.flags |= SS_FLAG_NEW_KEY;
return 0;
}
static int ss_aes_ecb_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_AES, SS_AES_MODE_ECB);
}
static int ss_aes_ecb_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_AES, SS_AES_MODE_ECB);
}
static int ss_aes_cbc_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_AES, SS_AES_MODE_CBC);
}
static int ss_aes_cbc_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_AES, SS_AES_MODE_CBC);
}
#ifdef SS_CTR_MODE_ENABLE
static int ss_aes_ctr_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_AES, SS_AES_MODE_CTR);
}
static int ss_aes_ctr_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_AES, SS_AES_MODE_CTR);
}
#endif
#ifdef SS_CTS_MODE_ENABLE
static int ss_aes_cts_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_AES, SS_AES_MODE_CTS);
}
static int ss_aes_cts_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_AES, SS_AES_MODE_CTS);
}
#endif
static int ss_des_ecb_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_DES, SS_AES_MODE_ECB);
}
static int ss_des_ecb_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_DES, SS_AES_MODE_ECB);
}
static int ss_des_cbc_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_DES, SS_AES_MODE_CBC);
}
static int ss_des_cbc_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_DES, SS_AES_MODE_CBC);
}
static int ss_des3_ecb_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_3DES, SS_AES_MODE_ECB);
}
static int ss_des3_ecb_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_3DES, SS_AES_MODE_ECB);
}
static int ss_des3_cbc_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_3DES, SS_AES_MODE_CBC);
}
static int ss_des3_cbc_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_3DES, SS_AES_MODE_CBC);
}
#ifdef SS_RSA_ENABLE
static int ss_rsa_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_RSA, SS_AES_MODE_CBC);
}
static int ss_rsa_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_RSA, SS_AES_MODE_CBC);
}
#endif
#ifdef SS_DH_ENABLE
static int ss_dh_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_DH, CE_RSA_OP_M_EXP);
}
static int ss_dh_decrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_DECRYPT, SS_METHOD_DH, CE_RSA_OP_M_EXP);
}
#endif
#ifdef SS_HMAC_SHA1_ENABLE
static int ss_hmac_sha1_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_HMAC_SHA1, SS_AES_MODE_ECB);
}
#endif
#ifdef SS_HMAC_SHA256_ENABLE
static int ss_hmac_sha256_encrypt(struct ablkcipher_request *req)
{
return ss_aes_crypt(req, SS_DIR_ENCRYPT, SS_METHOD_HMAC_SHA256, SS_AES_MODE_ECB);
}
#endif
int ss_rng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
{
int len = slen > SS_PRNG_SEED_LEN ? SS_PRNG_SEED_LEN : slen;
ss_aes_ctx_t *ctx = crypto_rng_ctx(tfm);
SS_DBG("Seed len: %d/%d, ctx->flags = %#x \n", len, slen, ctx->comm.flags);
ctx->key_size = len;
memset(ctx->key, 0, SS_PRNG_SEED_LEN);
memcpy(ctx->key, seed, len);
ctx->comm.flags |= SS_FLAG_NEW_KEY;
return 0;
}
static int ss_flow_request(ss_comm_ctx_t *comm)
{
int i;
unsigned long flags = 0;
spin_lock_irqsave(&ss_dev->lock, flags);
for (i=0; i<SS_FLOW_NUM; i++) {
if (ss_dev->flows[i].available == SS_FLOW_AVAILABLE) {
comm->flow = i;
ss_dev->flows[i].available = SS_FLOW_UNAVAILABLE;
SS_DBG("The flow %d is available. \n", i);
break;
}
}
spin_unlock_irqrestore(&ss_dev->lock, flags);
if (i == SS_FLOW_NUM) {
SS_ERR("Failed to get an available flow. \n");
i = -1;
}
return i;
}
static void ss_flow_release(ss_comm_ctx_t *comm)
{
unsigned long flags = 0;
spin_lock_irqsave(&ss_dev->lock, flags);
ss_dev->flows[comm->flow].available = SS_FLOW_AVAILABLE;
spin_unlock_irqrestore(&ss_dev->lock, flags);
}
static int sunxi_ss_cra_init(struct crypto_tfm *tfm)
{
if (ss_flow_request(crypto_tfm_ctx(tfm)) < 0)
return -1;
tfm->crt_ablkcipher.reqsize = sizeof(ss_aes_req_ctx_t);
SS_DBG("reqsize = %d \n", tfm->crt_u.ablkcipher.reqsize);
return 0;
}
static int sunxi_ss_cra_rng_init(struct crypto_tfm *tfm)
{
if (ss_flow_request(crypto_tfm_ctx(tfm)) < 0)
return -1;
return 0;
}
static int sunxi_ss_cra_hash_init(struct crypto_tfm *tfm)
{
if (ss_flow_request(crypto_tfm_ctx(tfm)) < 0)
return -1;
crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
sizeof(ss_aes_req_ctx_t));
SS_DBG("reqsize = %ld \n", sizeof(ss_aes_req_ctx_t));
return 0;
}
static void sunxi_ss_cra_exit(struct crypto_tfm *tfm)
{
SS_ENTER();
ss_flow_release(crypto_tfm_ctx(tfm));
}
static int ss_hash_init(struct ahash_request *req, int type, int size, char *iv)
{
ss_aes_req_ctx_t *req_ctx = ahash_request_ctx(req);
ss_hash_ctx_t *ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
SS_DBG("Method: %d \n", type);
memset(req_ctx, 0, sizeof(ss_aes_req_ctx_t));
req_ctx->type = type;
ctx->md_size = size;
memcpy(ctx->md, iv, size);
ctx->cnt = 0;
memset(ctx->pad, 0, SS_HASH_PAD_SIZE);
return 0;
}
static int ss_md5_init(struct ahash_request *req)
{
int iv[MD5_DIGEST_SIZE/4] = {SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3};
return ss_hash_init(req, SS_METHOD_MD5, MD5_DIGEST_SIZE, (char *)iv);
}
static int ss_sha1_init(struct ahash_request *req)
{
int iv[SHA1_DIGEST_SIZE/4] = {SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4};
#ifdef SS_SHA_SWAP_PRE_ENABLE
#ifdef SS_SHA_NO_SWAP_IV4
ss_hash_swap((char *)iv, SHA1_DIGEST_SIZE - 4);
#else
ss_hash_swap((char *)iv, SHA1_DIGEST_SIZE);
#endif
#endif
return ss_hash_init(req, SS_METHOD_SHA1, SHA1_DIGEST_SIZE, (char *)iv);
}
#ifdef SS_SHA224_ENABLE
static int ss_sha224_init(struct ahash_request *req)
{
int iv[SHA256_DIGEST_SIZE/4] = {SHA224_H0, SHA224_H1, SHA224_H2, SHA224_H3,
SHA224_H4, SHA224_H5, SHA224_H6, SHA224_H7};
#ifdef SS_SHA_SWAP_PRE_ENABLE
ss_hash_swap((char *)iv, SHA256_DIGEST_SIZE);
#endif
return ss_hash_init(req, SS_METHOD_SHA224, SHA256_DIGEST_SIZE, (char *)iv);
}
#endif
#ifdef SS_SHA256_ENABLE
static int ss_sha256_init(struct ahash_request *req)
{
int iv[SHA256_DIGEST_SIZE/4] = {SHA256_H0, SHA256_H1, SHA256_H2, SHA256_H3,
SHA256_H4, SHA256_H5, SHA256_H6, SHA256_H7};
#ifdef SS_SHA_SWAP_PRE_ENABLE
ss_hash_swap((char *)iv, SHA256_DIGEST_SIZE);
#endif
return ss_hash_init(req, SS_METHOD_SHA256, SHA256_DIGEST_SIZE, (char *)iv);
}
#endif
#define DES_MIN_KEY_SIZE DES_KEY_SIZE
#define DES_MAX_KEY_SIZE DES_KEY_SIZE
#define DES3_MIN_KEY_SIZE DES3_EDE_KEY_SIZE
#define DES3_MAX_KEY_SIZE DES3_EDE_KEY_SIZE
#define DECLARE_SS_AES_ALG(utype, ltype, lmode, block_size, iv_size) \
{ \
.cra_name = #lmode"("#ltype")", \
.cra_driver_name = "ss-"#lmode"-"#ltype, \
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, \
.cra_type = &crypto_ablkcipher_type, \
.cra_blocksize = block_size, \
.cra_alignmask = 3, \
.cra_u.ablkcipher = { \
.setkey = ss_aes_setkey, \
.encrypt = ss_##ltype##_##lmode##_encrypt, \
.decrypt = ss_##ltype##_##lmode##_decrypt, \
.min_keysize = utype##_MIN_KEY_SIZE, \
.max_keysize = utype##_MAX_KEY_SIZE, \
.ivsize = iv_size, \
} \
}
#define DECLARE_SS_ASYM_ALG(type, bitwidth, key_size, iv_size) \
{ \
.cra_name = #type"("#bitwidth")", \
.cra_driver_name = "ss-"#type"-"#bitwidth, \
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, \
.cra_type = &crypto_ablkcipher_type, \
.cra_blocksize = key_size%AES_BLOCK_SIZE == 0 ? AES_BLOCK_SIZE : 4, \
.cra_alignmask = key_size%AES_BLOCK_SIZE == 0 ? 31 : 3, \
.cra_u.ablkcipher = { \
.setkey = ss_aes_setkey, \
.encrypt = ss_##type##_encrypt, \
.decrypt = ss_##type##_decrypt, \
.min_keysize = key_size, \
.max_keysize = key_size, \
.ivsize = iv_size, \
}, \
}
#define DECLARE_SS_RSA_ALG(type, bitwidth) DECLARE_SS_ASYM_ALG(type, bitwidth, (bitwidth/8), (bitwidth/8))
#define DECLARE_SS_DH_ALG(type, bitwidth) DECLARE_SS_RSA_ALG(type, bitwidth)
#define DECLARE_SS_RNG_ALG(ltype) \
{ \
.cra_name = #ltype, \
.cra_driver_name = "ss-"#ltype, \
.cra_flags = CRYPTO_ALG_TYPE_RNG, \
.cra_type = &crypto_rng_type, \
.cra_u.rng = { \
.rng_make_random = ss_##ltype##_get_random, \
.rng_reset = ss_rng_reset, \
.seedsize = SS_SEED_SIZE, \
} \
}
static struct crypto_alg sunxi_ss_algs[] =
{
DECLARE_SS_AES_ALG(AES, aes, ecb, AES_BLOCK_SIZE, 0),
DECLARE_SS_AES_ALG(AES, aes, cbc, AES_BLOCK_SIZE, AES_MIN_KEY_SIZE),
#ifdef SS_CTR_MODE_ENABLE
DECLARE_SS_AES_ALG(AES, aes, ctr, 1, AES_MIN_KEY_SIZE),
#endif
#ifdef SS_CTS_MODE_ENABLE
DECLARE_SS_AES_ALG(AES, aes, cts, 1, AES_MIN_KEY_SIZE),
#endif
DECLARE_SS_AES_ALG(DES, des, ecb, DES_BLOCK_SIZE, 0),
DECLARE_SS_AES_ALG(DES, des, cbc, DES_BLOCK_SIZE, DES_KEY_SIZE),
DECLARE_SS_AES_ALG(DES3, des3, ecb, DES3_EDE_BLOCK_SIZE, 0),
DECLARE_SS_AES_ALG(DES3, des3, cbc, DES3_EDE_BLOCK_SIZE, DES_KEY_SIZE),
#ifdef SS_RSA512_ENABLE
DECLARE_SS_RSA_ALG(rsa, 512),
#endif
#ifdef SS_RSA1024_ENABLE
DECLARE_SS_RSA_ALG(rsa, 1024),
#endif
#ifdef SS_RSA2048_ENABLE
DECLARE_SS_RSA_ALG(rsa, 2048),
#endif
#ifdef SS_DH512_ENABLE
DECLARE_SS_DH_ALG(dh, 512),
#endif
#ifdef SS_DH1024_ENABLE
DECLARE_SS_DH_ALG(dh, 1024),
#endif
#ifdef SS_DH2048_ENABLE
DECLARE_SS_DH_ALG(dh, 2048),
#endif
#ifdef SS_TRNG_ENABLE
DECLARE_SS_RNG_ALG(trng),
#endif
DECLARE_SS_RNG_ALG(prng),
#ifdef SS_HMAC_SHA1_ENABLE
{
.cra_name = "hmac-sha1",
.cra_driver_name = "ss-hmac-sha1",
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
.cra_type = &crypto_ablkcipher_type,
.cra_blocksize = 4,
.cra_alignmask = 3,
.cra_u.ablkcipher = {
.setkey = ss_aes_setkey,
.encrypt = ss_hmac_sha1_encrypt,
.decrypt = NULL,
.min_keysize = SHA1_BLOCK_SIZE,
.max_keysize = SHA1_BLOCK_SIZE,
.ivsize = 0,
}
},
#endif
#ifdef SS_HMAC_SHA256_ENABLE
{
.cra_name = "hmac-sha256",
.cra_driver_name = "ss-hmac-sha256",
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
.cra_type = &crypto_ablkcipher_type,
.cra_blocksize = 4,
.cra_alignmask = 3,
.cra_u.ablkcipher = {
.setkey = ss_aes_setkey,
.encrypt = ss_hmac_sha256_encrypt,
.decrypt = NULL,
.min_keysize = SHA256_BLOCK_SIZE,
.max_keysize = SHA256_BLOCK_SIZE,
.ivsize = 0,
}
},
#endif
};
#define MD5_BLOCK_SIZE MD5_HMAC_BLOCK_SIZE
#define DECLARE_SS_AHASH_ALG(ltype, utype) \
{ \
.init = ss_##ltype##_init, \
.update = ss_hash_update, \
.final = ss_hash_final, \
.finup = ss_hash_finup, \
.halg.digestsize = utype##_DIGEST_SIZE, \
.halg.statesize = sizeof(struct ltype##_state), \
.halg.base = { \
.cra_name = #ltype, \
.cra_driver_name= "ss-"#ltype, \
.cra_flags = CRYPTO_ALG_TYPE_AHASH|CRYPTO_ALG_ASYNC, \
.cra_blocksize = utype##_BLOCK_SIZE, \
.cra_ctxsize = sizeof(ss_hash_ctx_t), \
.cra_alignmask = 3, \
.cra_module = THIS_MODULE, \
.cra_init = sunxi_ss_cra_hash_init, \
.cra_exit = sunxi_ss_cra_exit, \
} \
}
static struct ahash_alg sunxi_ss_algs_hash[] = {
DECLARE_SS_AHASH_ALG(md5, MD5),
DECLARE_SS_AHASH_ALG(sha1, SHA1),
#if 0
#ifdef SS_SHA224_ENABLE
DECLARE_SS_AHASH_ALG(sha224, SHA224),
#endif
#endif
#ifdef SS_SHA256_ENABLE
DECLARE_SS_AHASH_ALG(sha256, SHA256),
#endif
};
/* Requeset the resource: IRQ, mem */
static int sunxi_ss_res_request(struct platform_device *pdev)
{
int ret = 0;
struct device_node *pnode = pdev->dev.of_node;
sunxi_ss_t *sss = platform_get_drvdata(pdev);
sss->irq = irq_of_parse_and_map(pnode, SS_RES_INDEX);
if (sss->irq == 0) {
SS_ERR("Failed to get the SS IRQ.\n");
return -EINVAL;
}
ret = request_irq(sss->irq, sunxi_ss_irq_handler, IRQF_DISABLED, sss->dev_name, sss);
if (ret != 0) {
SS_ERR("Cannot request IRQ\n");
return ret;
}
#ifdef CONFIG_OF
sss->base_addr = of_iomap(pnode, SS_RES_INDEX);
if (sss->base_addr == NULL) {
SS_ERR("Unable to remap IO\n");
return -ENXIO;
}
#endif
return 0;
}
/* Release the resource: IRQ, mem */
static int sunxi_ss_res_release(sunxi_ss_t *sss)
{
iounmap(sss->base_addr);
free_irq(sss->irq, sss);
return 0;
}
static int sunxi_ss_hw_init(sunxi_ss_t *sss)
{
#ifdef CONFIG_EVB_PLATFORM
int ret = 0;
#endif
struct clk *pclk = NULL;
struct device_node *pnode = sss->pdev->dev.of_node;
pclk = of_clk_get(pnode, 1);
if (IS_ERR_OR_NULL(pclk)) {
SS_ERR("Unable to get pll clock, return %x\n", PTR_RET(pclk));
return PTR_RET(pclk);
}
sss->mclk = of_clk_get(pnode, 0);
if (IS_ERR_OR_NULL(sss->mclk)) {
SS_ERR("Unable to get module clock, return %x\n", PTR_RET(sss->mclk));
return PTR_RET(sss->mclk);
}
if (of_property_read_u32_array(pnode, "clock-frequency", &sss->gen_clkrate, 2)) {
SS_ERR("Unable to get clock-frequency.\n");
return -EINVAL;
}
SS_DBG("The clock frequency: %d, %d\n", sss->gen_clkrate, sss->rsa_clkrate);
#ifdef CONFIG_EVB_PLATFORM
ret = clk_set_parent(sss->mclk, pclk);
if (ret != 0) {
SS_ERR("clk_set_parent() failed! return %d\n", ret);
return ret;
}
ret = clk_set_rate(sss->mclk, sss->gen_clkrate);
if (ret != 0) {
SS_ERR("clk_set_rate(%d) failed! return %d\n", sss->gen_clkrate, ret);
return ret;
}
#endif
SS_DBG("SS mclk %luMHz, pclk %luMHz\n", clk_get_rate(sss->mclk)/1000000,
clk_get_rate(pclk)/1000000);
if (clk_prepare_enable(sss->mclk)) {
SS_ERR("Couldn't enable module clock\n");
return -EBUSY;
}
clk_put(pclk);
return 0;
}
static int sunxi_ss_hw_exit(sunxi_ss_t *sss)
{
clk_disable_unprepare(sss->mclk);
clk_put(sss->mclk);
sss->mclk = NULL;
return 0;
}
static int sunxi_ss_alg_register(void)
{
int i;
int ret = 0;
for (i=0; i<ARRAY_SIZE(sunxi_ss_algs); i++) {
INIT_LIST_HEAD(&sunxi_ss_algs[i].cra_list);
sunxi_ss_algs[i].cra_priority = SS_ALG_PRIORITY;
sunxi_ss_algs[i].cra_ctxsize = sizeof(ss_aes_ctx_t);
sunxi_ss_algs[i].cra_module = THIS_MODULE;
sunxi_ss_algs[i].cra_exit = sunxi_ss_cra_exit;
if (strncmp(sunxi_ss_algs[i].cra_name, "prng", 4) == 0)
sunxi_ss_algs[i].cra_init = sunxi_ss_cra_rng_init;
else
sunxi_ss_algs[i].cra_init = sunxi_ss_cra_init;
ret = crypto_register_alg(&sunxi_ss_algs[i]);
if (ret != 0) {
SS_ERR("crypto_register_alg(%s) failed! return %d \n",
sunxi_ss_algs[i].cra_name, ret);
return ret;
}
}
for (i=0; i<ARRAY_SIZE(sunxi_ss_algs_hash); i++) {
sunxi_ss_algs_hash[i].halg.base.cra_priority = SS_ALG_PRIORITY;
ret = crypto_register_ahash(&sunxi_ss_algs_hash[i]);
if (ret != 0) {
SS_ERR("crypto_register_ahash(%s) failed! return %d \n",
sunxi_ss_algs_hash[i].halg.base.cra_name, ret);
return ret;
}
}
return 0;
}
static void sunxi_ss_alg_unregister(void)
{
int i;
for (i=0; i<ARRAY_SIZE(sunxi_ss_algs); i++)
crypto_unregister_alg(&sunxi_ss_algs[i]);
for (i=0; i<ARRAY_SIZE(sunxi_ss_algs_hash); i++)
crypto_unregister_ahash(&sunxi_ss_algs_hash[i]);
}
static ssize_t sunxi_ss_info_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct platform_device *pdev = container_of(dev, struct platform_device, dev);
sunxi_ss_t *sss = platform_get_drvdata(pdev);
return snprintf(buf, PAGE_SIZE,
"pdev->id = %d \n"
"pdev->name = %s \n"
"pdev->num_resources = %u \n"
"pdev->resource.irq = %d \n"
"SS module clk rate = %ld Mhz \n"
"IO membase = 0x%p \n",
pdev->id, pdev->name, pdev->num_resources,
sss->irq,
(clk_get_rate(sss->mclk)/1000000), sss->base_addr);
}
static struct device_attribute sunxi_ss_info_attr =
__ATTR(info, S_IRUGO, sunxi_ss_info_show, NULL);
static ssize_t sunxi_ss_status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int i;
struct platform_device *pdev = container_of(dev, struct platform_device, dev);
sunxi_ss_t *sss = platform_get_drvdata(pdev);
char *avail[] = {"Available", "Unavailable"};
if (sss == NULL)
return snprintf(buf, PAGE_SIZE, "%s\n", "sunxi_ss_t is NULL!");
buf[0] = 0;
for (i=0; i<SS_FLOW_NUM; i++) {
snprintf(buf+strlen(buf), PAGE_SIZE-strlen(buf),
"The flow %d state: %s \n",
i, avail[sss->flows[i].available]
);
}
return strlen(buf) + ss_reg_print(buf + strlen(buf), PAGE_SIZE - strlen(buf));
}
static struct device_attribute sunxi_ss_status_attr =
__ATTR(status, S_IRUGO, sunxi_ss_status_show, NULL);
static void sunxi_ss_sysfs_create(struct platform_device *_pdev)
{
device_create_file(&_pdev->dev, &sunxi_ss_info_attr);
device_create_file(&_pdev->dev, &sunxi_ss_status_attr);
}
static void sunxi_ss_sysfs_remove(struct platform_device *_pdev)
{
device_remove_file(&_pdev->dev, &sunxi_ss_info_attr);
device_remove_file(&_pdev->dev, &sunxi_ss_status_attr);
}
static u64 sunxi_ss_dma_mask = DMA_BIT_MASK(32);
static int sunxi_ss_probe(struct platform_device *pdev)
{
int ret = 0;
sunxi_ss_t *sss = NULL;
sss = devm_kzalloc(&pdev->dev, sizeof(sunxi_ss_t), GFP_KERNEL);
if (sss == NULL) {
SS_ERR("Unable to allocate sunxi_ss_t\n");
return -ENOMEM;
}
#ifdef CONFIG_OF
pdev->dev.dma_mask = &sunxi_ss_dma_mask;
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
#endif
snprintf(sss->dev_name, sizeof(sss->dev_name), SUNXI_SS_DEV_NAME);
platform_set_drvdata(pdev, sss);
ret = sunxi_ss_res_request(pdev);
if (ret != 0) {
goto err0;
}
sss->pdev = pdev;
ret = sunxi_ss_hw_init(sss);
if (ret != 0) {
SS_ERR("SS hw init failed!\n");
goto err1;
}
ret = sunxi_ss_alg_register();
if (ret != 0) {
SS_ERR("sunxi_ss_alg_register() failed! return %d \n", ret);
goto err2;
}
sunxi_ss_sysfs_create(pdev);
ss_dev = sss;
SS_DBG("SS driver probe succeed, base 0x%p, irq %d!\n", sss->base_addr, sss->irq);
return 0;
err2:
sunxi_ss_hw_exit(sss);
err1:
sunxi_ss_res_release(sss);
err0:
platform_set_drvdata(pdev, NULL);
return ret;
}
static int sunxi_ss_remove(struct platform_device *pdev)
{
sunxi_ss_t *sss = platform_get_drvdata(pdev);
ss_wait_idle();
sunxi_ss_sysfs_remove(pdev);
sunxi_ss_alg_unregister();
sunxi_ss_hw_exit(sss);
sunxi_ss_res_release(sss);
platform_set_drvdata(pdev, NULL);
ss_dev = NULL;
return 0;
}
#ifdef CONFIG_PM
static int sunxi_ss_suspend(struct device *dev)
{
#ifdef CONFIG_EVB_PLATFORM
struct platform_device *pdev = to_platform_device(dev);
sunxi_ss_t *sss = platform_get_drvdata(pdev);
unsigned long flags = 0;
SS_ENTER();
/* Wait for the completion of SS operation. */
ss_dev_lock();
spin_lock_irqsave(&ss_dev->lock, flags);
sss->suspend = 1;
spin_unlock_irqrestore(&sss->lock, flags);
sunxi_ss_hw_exit(sss);
ss_dev_unlock();
#endif
return 0;
}
static int sunxi_ss_resume(struct device *dev)
{
int ret = 0;
#ifdef CONFIG_EVB_PLATFORM
struct platform_device *pdev = to_platform_device(dev);
sunxi_ss_t *sss = platform_get_drvdata(pdev);
unsigned long flags = 0;
SS_ENTER();
ret = sunxi_ss_hw_init(sss);
spin_lock_irqsave(&ss_dev->lock, flags);
sss->suspend = 0;
spin_unlock_irqrestore(&sss->lock, flags);
#endif
return ret;
}
static const struct dev_pm_ops sunxi_ss_dev_pm_ops = {
.suspend = sunxi_ss_suspend,
.resume = sunxi_ss_resume,
};
#define SUNXI_SS_DEV_PM_OPS (&sunxi_ss_dev_pm_ops)
#else
#define SUNXI_SS_DEV_PM_OPS NULL
#endif /* CONFIG_PM */
static struct platform_driver sunxi_ss_driver = {
.probe = sunxi_ss_probe,
.remove = sunxi_ss_remove,
.driver = {
.name = SUNXI_SS_DEV_NAME,
.owner = THIS_MODULE,
.pm = SUNXI_SS_DEV_PM_OPS,
.of_match_table = sunxi_ss_of_match,
},
};
static int __init sunxi_ss_init(void)
{
int ret = 0;
SS_DBG("[%s %s]Sunxi SS init ... \n", __DATE__, __TIME__);
ret = platform_driver_register(&sunxi_ss_driver);
if (ret < 0) {
SS_ERR("platform_driver_register() failed, return %d\n", ret);
return ret;
}
return ret;
}
static void __exit sunxi_ss_exit(void)
{
platform_driver_unregister(&sunxi_ss_driver);
}
module_init(sunxi_ss_init);
module_exit(sunxi_ss_exit);
MODULE_AUTHOR("mintow");
MODULE_DESCRIPTION("SUNXI SS Controller Driver");
MODULE_ALIAS("platform:"SUNXI_SS_DEV_NAME);
MODULE_LICENSE("GPL");
|
fde5463537a21b5ab1e896a00051350af080be83
|
4692f28f86ee84a76abfac8cc8a0dd41fcd402e4
|
/rtloader/common/builtins/_util.c
|
c552c441624e1279bd9a4ed5f4b066f92766812c
|
[
"CC0-1.0",
"BSD-3-Clause",
"Apache-2.0",
"GPL-1.0-or-later",
"MIT",
"0BSD",
"Unlicense",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"BSD-2-Clause-Views",
"MPL-2.0"
] |
permissive
|
DataDog/datadog-agent
|
cc4b89839d6031903bf23aa12eccc2a3f3c7f213
|
d960cdb7de8fa5d1c7138cfe58e754af80cb796a
|
refs/heads/main
| 2023-09-04T10:45:08.138748
| 2023-09-04T09:13:43
| 2023-09-04T09:13:43
| 49,970,739
| 2,388
| 1,288
|
Apache-2.0
| 2023-09-14T20:06:34
| 2016-01-19T17:40:41
|
Go
|
UTF-8
|
C
| false
| false
| 10,629
|
c
|
_util.c
|
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-present Datadog, Inc.
#include "_util.h"
#include "cgo_free.h"
#include "rtloader_mem.h"
#include "stringutils.h"
#include <stdio.h>
// must be set by the caller
static cb_get_subprocess_output_t cb_get_subprocess_output = NULL;
static PyObject *subprocess_output(PyObject *self, PyObject *args, PyObject *kw);
// Exceptions
/*! \fn void addSubprocessException(PyObject *m)
\brief Adds a custom SubprocessOutputEmptyError exception to the module passed as parameter.
\param m A PyObject* pointer to the module we wish to register the exception with.
*/
void addSubprocessException(PyObject *m)
{
PyObject *SubprocessOutputEmptyError = PyErr_NewException(_SUBPROCESS_OUTPUT_ERROR_NS_NAME, NULL, NULL);
PyModule_AddObject(m, _SUBPROCESS_OUTPUT_ERROR_NAME, SubprocessOutputEmptyError);
}
static PyMethodDef methods[] = {
{ "subprocess_output", (PyCFunction)subprocess_output, METH_VARARGS | METH_KEYWORDS,
"Exec a process and return the output." },
{ "get_subprocess_output", (PyCFunction)subprocess_output, METH_VARARGS | METH_KEYWORDS,
"Exec a process and return the output." },
{ NULL, NULL } // guards
};
#ifdef DATADOG_AGENT_THREE
static struct PyModuleDef module_def = { PyModuleDef_HEAD_INIT, _UTIL_MODULE_NAME, NULL, -1, methods };
PyMODINIT_FUNC PyInit__util(void)
{
PyObject *m = PyModule_Create(&module_def);
addSubprocessException(m);
return m;
}
#elif defined(DATADOG_AGENT_TWO)
// in Python2 keep the object alive for the program lifetime
static PyObject *module;
void Py2_init__util()
{
module = Py_InitModule(_UTIL_MODULE_NAME, methods);
addSubprocessException(module);
}
#endif
void _set_get_subprocess_output_cb(cb_get_subprocess_output_t cb)
{
cb_get_subprocess_output = cb;
}
/*! \fn void raiseEmptyOutputError()
\brief sets the SubprocessOutputEmptyError exception as the interpreter error.
If everything goes well the exception error will be set in the interpreter.
Otherwise, if the module or the exception class are not found, the relevant
error will be set in the interpreter instead.
*/
static void raiseEmptyOutputError()
{
PyObject *utilModule = PyImport_ImportModule(_UTIL_MODULE_NAME);
if (utilModule == NULL) {
PyErr_SetString(PyExc_TypeError, "error: no module '" _UTIL_MODULE_NAME "'");
return;
}
PyObject *excClass = PyObject_GetAttrString(utilModule, _SUBPROCESS_OUTPUT_ERROR_NAME);
if (excClass == NULL) {
Py_DecRef(utilModule);
PyErr_SetString(PyExc_TypeError, "no attribute '" _SUBPROCESS_OUTPUT_ERROR_NS_NAME "' found");
return;
}
PyErr_SetString(excClass, "get_subprocess_output expected output but had none.");
Py_DecRef(excClass);
Py_DecRef(utilModule);
}
/*! \fn PyObject *subprocess_output(PyObject *self, PyObject *args)
\brief This function implements the `_util.subprocess_output` _and_ `_util.get_subprocess_output`
python method, allowing to execute a subprocess and collect its output.
\param self A PyObject* pointer to the _util module.
\param args A PyObject* pointer to the args tuple with the desired subprocess commands, and
optionally a boolean raise_on_empty flag.
\param kw A PyObject* pointer to the kw dict with optionally an env dict.
\return a PyObject * pointer to a python tuple with the stdout, stderr output and the
command exit code.
This function is callable as the `_util.subprocess_output` or `_util.get_subprocess_output`
python methods. The command arguments list is fed to the CGO callback, where the command is
executed in go-land. The stdout, stderr and exit codes for the command are returned by the
callback; these are then converted into python strings and integer respectively and returned
in a tuple. If the optional `raise_on_empty` boolean flag is set, and the command output is
empty an exception will be raised: the error will be set in the interpreter and NULL will be
returned.
*/
PyObject *subprocess_output(PyObject *self, PyObject *args, PyObject *kw)
{
int i;
int raise = 0;
int ret_code = 0;
int subprocess_args_sz = 0;
int subprocess_env_sz = 0;
char **subprocess_args = NULL;
char **subprocess_env = NULL;
char *c_stdout = NULL;
char *c_stderr = NULL;
char *exception = NULL;
PyObject *cmd_args = NULL;
PyObject *cmd_raise_on_empty = NULL;
PyObject *cmd_env = NULL;
PyObject *pyResult = NULL;
if (!cb_get_subprocess_output) {
Py_RETURN_NONE;
}
PyGILState_STATE gstate = PyGILState_Ensure();
static char *keywords[] = { "command", "raise_on_empty", "env", NULL };
// `cmd_args` is mandatory and should be a list, `cmd_raise_on_empty` is an optional
// boolean. The string after the ':' is used as the function name in error messages.
if (!PyArg_ParseTupleAndKeywords(args, kw, "O|O" PY_ARG_PARSE_TUPLE_KEYWORD_ONLY "O:get_subprocess_output",
keywords, &cmd_args, &cmd_raise_on_empty, &cmd_env)) {
goto cleanup;
}
if (!PyList_Check(cmd_args)) {
PyErr_SetString(PyExc_TypeError, "command args is not a list");
goto cleanup;
}
// We already PyList_Check cmd_args, so PyList_Size won't fail and return -1
subprocess_args_sz = PyList_Size(cmd_args);
if (subprocess_args_sz == 0) {
PyErr_SetString(PyExc_TypeError, "invalid command: empty list");
goto cleanup;
}
if (!(subprocess_args = (char **)_malloc(sizeof(*subprocess_args) * (subprocess_args_sz + 1)))) {
PyErr_SetString(PyExc_MemoryError, "unable to allocate memory, bailing out");
goto cleanup;
}
// init to NULL for safety - could use memset, but this is safer.
for (i = 0; i <= subprocess_args_sz; i++) {
subprocess_args[i] = NULL;
}
for (i = 0; i < subprocess_args_sz; i++) {
char *subprocess_arg = as_string(PyList_GetItem(cmd_args, i));
if (subprocess_arg == NULL) {
PyErr_SetString(PyExc_TypeError, "command argument must be valid strings");
goto cleanup;
}
subprocess_args[i] = subprocess_arg;
}
if (cmd_env != NULL && cmd_env != Py_None) {
if (!PyDict_Check(cmd_env)) {
PyErr_SetString(PyExc_TypeError, "env is not a dict");
goto cleanup;
}
subprocess_env_sz = PyDict_Size(cmd_env);
if (subprocess_env_sz != 0) {
if (!(subprocess_env = (char **)_malloc(sizeof(*subprocess_env) * (subprocess_env_sz + 1)))) {
PyErr_SetString(PyExc_MemoryError, "unable to allocate memory, bailing out");
goto cleanup;
}
for (i = 0; i <= subprocess_env_sz; i++) {
subprocess_env[i] = NULL;
}
Py_ssize_t pos = 0;
PyObject *key = NULL, *value = NULL;
for (i = 0; i < subprocess_env_sz && PyDict_Next(cmd_env, &pos, &key, &value); i++) {
char *env_key = as_string(key);
if (env_key == NULL) {
PyErr_SetString(PyExc_TypeError, "env key is not a string");
goto cleanup;
}
char *env_value = as_string(value);
if (env_value == NULL) {
PyErr_SetString(PyExc_TypeError, "env value is not a string");
_free(env_key);
goto cleanup;
}
char *env = (char *)_malloc((strlen(env_key) + 1 + strlen(env_value) + 1) * sizeof(*env));
if (env == NULL) {
PyErr_SetString(PyExc_MemoryError, "unable to allocate memory, bailing out");
_free(env_key);
_free(env_value);
goto cleanup;
}
strcpy(env, env_key);
strcat(env, "=");
strcat(env, env_value);
_free(env_key);
_free(env_value);
subprocess_env[i] = env;
}
}
}
if (cmd_raise_on_empty != NULL && !PyBool_Check(cmd_raise_on_empty)) {
PyErr_SetString(PyExc_TypeError, "bad raise_on_empty argument: should be bool");
goto cleanup;
}
if (cmd_raise_on_empty == Py_True) {
raise = 1;
}
// Release the GIL so Python can execute other checks while Go runs the subprocess
PyGILState_Release(gstate);
PyThreadState *Tstate = PyEval_SaveThread();
cb_get_subprocess_output(subprocess_args, subprocess_env, &c_stdout, &c_stderr, &ret_code, &exception);
// Acquire the GIL now that Go is done
PyEval_RestoreThread(Tstate);
gstate = PyGILState_Ensure();
if (raise && strlen(c_stdout) == 0) {
raiseEmptyOutputError();
goto cleanup;
}
if (exception) {
PyErr_SetString(PyExc_Exception, exception);
goto cleanup;
}
PyObject *pyStdout = NULL;
if (c_stdout) {
pyStdout = PyStringFromCString(c_stdout);
} else {
Py_INCREF(Py_None);
pyStdout = Py_None;
}
PyObject *pyStderr = NULL;
if (c_stderr) {
pyStderr = PyStringFromCString(c_stderr);
} else {
Py_INCREF(Py_None);
pyStderr = Py_None;
}
pyResult = PyTuple_New(3);
PyTuple_SetItem(pyResult, 0, pyStdout);
PyTuple_SetItem(pyResult, 1, pyStderr);
#ifdef DATADOG_AGENT_THREE
PyTuple_SetItem(pyResult, 2, PyLong_FromLong(ret_code));
#else
PyTuple_SetItem(pyResult, 2, PyInt_FromLong(ret_code));
#endif
cleanup:
if (c_stdout) {
cgo_free(c_stdout);
}
if (c_stderr) {
cgo_free(c_stderr);
}
if (exception) {
cgo_free(exception);
}
if (subprocess_args) {
for (i = 0; i <= subprocess_args_sz && subprocess_args[i]; i++) {
_free(subprocess_args[i]);
}
_free(subprocess_args);
}
if (subprocess_env) {
for (i = 0; i <= subprocess_env_sz && subprocess_env[i]; i++) {
_free(subprocess_env[i]);
}
_free(subprocess_env);
}
// Please note that if we get here we have a matching PyGILState_Ensure above, so we're safe.
PyGILState_Release(gstate);
// pyResult will be NULL in the face of error to raise the exception set by PyErr_SetString
return pyResult;
}
|
6b7e082b7bf3c175dabbaa9882fd8f19bf6ef421
|
20e1c2f5cfac01f6b007124fa7792dd69751a6bb
|
/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c
|
4a3dc4ba22adf9eee5ab08f029ba98bb428be97c
|
[
"Apache-2.0"
] |
permissive
|
nasa/osal
|
71f159b767ba4a8c39df48f238b4f296cc571ac8
|
99e3b4007da51031b521d90390526e123ff740b4
|
refs/heads/main
| 2023-09-01T06:33:53.932829
| 2023-08-18T14:27:02
| 2023-08-18T14:27:02
| 4,814,601
| 493
| 229
|
Apache-2.0
| 2023-09-13T13:57:40
| 2012-06-27T23:10:37
|
C
|
UTF-8
|
C
| false
| false
| 7,969
|
c
|
bin-sem-timeout-test.c
|
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/*
** Binary semaphore Producer/Consumer test ( test the timeout feature )
*/
#include <stdio.h>
#include "common_types.h"
#include "osapi.h"
#include "utassert.h"
#include "uttest.h"
#include "utbsp.h"
/* Define setup and check functions for UT assert */
void BinSemTimeoutSetup(void);
void BinSemTimeoutCheck(void);
/* Task 1 */
#define TASK_1_STACK_SIZE 1024
#define TASK_1_PRIORITY 101
#define TASK_2_STACK_SIZE 1024
#define TASK_2_PRIORITY 50
uint32 task_1_stack[TASK_1_STACK_SIZE];
osal_id_t task_1_id;
uint32 task_1_timeouts;
uint32 task_1_work;
uint32 task_1_failures;
uint32 task_2_stack[TASK_2_STACK_SIZE];
osal_id_t task_2_id;
osal_id_t bin_sem_id;
uint32 timer_counter;
osal_id_t timer_id;
uint32 timer_start = 1000000;
uint32 timer_interval = 2000000; /* 2 second period */
uint32 timer_accuracy;
uint32 timer_function_failures;
int counter = 0;
/*
* Note that we should not call "printf" or anything
* like that during a timer callback routine (may be ISR context)
*
* On RTEMS even a call to BinSemGetInfo has very ill effects.
*/
void TimerFunction(osal_id_t local_timer_id)
{
int32 status;
OS_bin_sem_prop_t bin_sem_prop;
memset(&bin_sem_prop, 0, sizeof(bin_sem_prop));
timer_counter++;
status = OS_BinSemGive(bin_sem_id);
if (status != OS_SUCCESS)
{
++timer_function_failures;
}
{
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
if (status != OS_SUCCESS)
{
++timer_function_failures;
}
else if (bin_sem_prop.value > 1)
{
++timer_function_failures;
}
else if (bin_sem_prop.value < -1)
{
++timer_function_failures;
}
}
}
void task_1(void)
{
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;
memset(&bin_sem_prop, 0, sizeof(bin_sem_prop));
OS_printf("Starting task 1\n");
OS_printf("Delay for 1 second before starting\n");
OS_TaskDelay(1000);
while (1)
{
OS_printf("TASK 1: Waiting on the semaphore\n");
status = OS_BinSemTimedWait(bin_sem_id, 1000);
if (status == OS_SUCCESS)
{
OS_printf("TASK 1: Doing some work: %d\n", (int)counter++);
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
if (status != OS_SUCCESS)
{
OS_printf("Error: OS_BinSemGetInfo\n");
++task_1_failures;
}
else if (bin_sem_prop.value > 1)
{
OS_printf("Error: Binary sem value > 1 ( in task):%d !\n", (int)bin_sem_prop.value);
++task_1_failures;
}
else if (bin_sem_prop.value < -1)
{
OS_printf("Error: Binary sem value < -1 ( in task):%d !\n", (int)bin_sem_prop.value);
++task_1_failures;
}
}
else if (status == OS_SEM_TIMEOUT)
{
OS_printf("TASK 1:Timeout on OS_BinSemTimedWait\n");
++task_1_timeouts;
OS_TaskDelay(500);
}
else
{
++task_1_failures;
OS_printf("TASK 1:Error calling OS_BinSemTimedWait\n");
}
}
}
void BinSemTimeoutCheck(void)
{
int32 status;
uint32 limit;
status = OS_TimerDelete(timer_id);
UtAssert_True(status == OS_SUCCESS, "OS_TimerDelete Rc=%d", (int)status);
status = OS_TaskDelete(task_1_id);
UtAssert_True(status == OS_SUCCESS, "OS_TaskDelete Rc=%d", (int)status);
UtAssert_True(counter == timer_counter, "Task counter (%d) == timer counter (%d)", (int)counter,
(int)timer_counter);
UtAssert_True(task_1_failures == 0, "Task 1 failures = %u", (unsigned int)task_1_failures);
UtAssert_True(timer_function_failures == 0, "Timer function failures = %u", (unsigned int)timer_function_failures);
/*
* With the timers as configured, there should be approximately 1 task_1 timeout
* per real tick. Task 1 Sequence is:
* Sem Take (success after ??? ms) --> Sem Take (timeout after 1000ms) --> 500ms delay -->
* Sem Take (success after ~500ms) --> repeat
* And Repeat...
*/
limit = counter / 2;
UtAssert_True(task_1_timeouts >= limit, "Task 1 timeouts=%u >= %u", (unsigned int)task_1_timeouts,
(unsigned int)limit);
limit = counter * 2;
UtAssert_True(task_1_timeouts <= limit, "Task 1 timeouts=%u <= %u", (unsigned int)task_1_timeouts,
(unsigned int)limit);
}
void UtTest_Setup(void)
{
if (OS_API_Init() != OS_SUCCESS)
{
UtAssert_Abort("OS_API_Init() failed");
}
/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");
/*
* Register the test setup and check routines in UT assert
*/
UtTest_Add(BinSemTimeoutCheck, BinSemTimeoutSetup, NULL, "BinSemTimeoutTest");
}
void BinSemTimeoutSetup(void)
{
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;
uint32 accuracy = 0;
memset(&bin_sem_prop, 0, sizeof(bin_sem_prop));
task_1_timeouts = 0;
task_1_work = 0;
task_1_failures = 0;
timer_function_failures = 0;
/*
** Create the binary semaphore
*/
status = OS_BinSemCreate(&bin_sem_id, "BinSem1", 1, 0);
UtAssert_True(status == OS_SUCCESS, "BinSem1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(bin_sem_id), (int)status);
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
UtAssert_True(status == OS_SUCCESS, "BinSem1 value=%d Rc=%d", (int)bin_sem_prop.value, (int)status);
/*
** Take the semaphore so the value is 0 and the next SemTake call should block
*/
status = OS_BinSemTake(bin_sem_id);
UtAssert_True(status == OS_SUCCESS, "BinSem1 take Rc=%d", (int)status);
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
UtAssert_True(status == OS_SUCCESS, "BinSem1 value=%d Rc=%d", (int)bin_sem_prop.value, (int)status);
/*
** Create the "consumer" task.
*/
status = OS_TaskCreate(&task_1_id, "Task 1", task_1, OSAL_STACKPTR_C(task_1_stack), sizeof(task_1_stack),
OSAL_PRIORITY_C(TASK_1_PRIORITY), 0);
UtAssert_True(status == OS_SUCCESS, "Task 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(task_1_id), (int)status);
/*
** Create a timer
*/
status = OS_TimerCreate(&timer_id, "Timer 1", &accuracy, &(TimerFunction));
UtAssert_True(status == OS_SUCCESS, "Timer 1 create Id=%lx Rc=%d", OS_ObjectIdToInteger(timer_id), (int)status);
UtPrintf("Timer Accuracy = %u microseconds \n", (unsigned int)accuracy);
/*
** Start the timer
*/
status = OS_TimerSet(timer_id, timer_start, timer_interval);
UtAssert_True(status == OS_SUCCESS, "Timer 1 set Rc=%d", (int)status);
/*
* Give tasks time to run
*/
while (counter < 10)
{
OS_TaskDelay(100);
}
}
|
0910dde7d35c6a602592073893ba73a5d62c1785
|
badb70a0b235c98ac034cfe5b4bfafda36647831
|
/Library/OcDevicePathLib/OcDevicePathLib.c
|
3181b17f9dcea00cb997261874d04216e6992e1f
|
[
"BSD-3-Clause"
] |
permissive
|
acidanthera/OpenCorePkg
|
f34a7d67b22c74fb5ab559e48519e5f5855b6751
|
1d5b1736fe5a5ef7662b5c076c6d11aac96fd5d6
|
refs/heads/master
| 2023-08-30T21:03:02.993659
| 2023-08-28T23:30:43
| 2023-08-28T23:30:43
| 179,354,282
| 13,212
| 2,999
|
BSD-3-Clause
| 2023-09-10T18:29:53
| 2019-04-03T19:14:29
|
C
|
UTF-8
|
C
| false
| false
| 38,564
|
c
|
OcDevicePathLib.c
|
/** @file
Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.
All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/SimpleFileSystem.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcStringLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/OcDebugLogLib.h>
EFI_DEVICE_PATH_PROTOCOL *
AppendFileNameDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FileName
)
{
EFI_DEVICE_PATH_PROTOCOL *AppendedDevicePath;
FILEPATH_DEVICE_PATH *FilePathNode;
EFI_DEVICE_PATH_PROTOCOL *DevicePathEndNode;
UINTN FileNameSize;
UINTN FileDevicePathNodeSize;
AppendedDevicePath = NULL;
if ((DevicePath != NULL) && (FileName != NULL)) {
FileNameSize = StrSize (FileName);
FileDevicePathNodeSize = (FileNameSize + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
FilePathNode = AllocateZeroPool (FileDevicePathNodeSize);
if (FilePathNode != NULL) {
FilePathNode->Header.Type = MEDIA_DEVICE_PATH;
FilePathNode->Header.SubType = MEDIA_FILEPATH_DP;
SetDevicePathNodeLength (&FilePathNode->Header, FileNameSize + SIZE_OF_FILEPATH_DEVICE_PATH);
CopyMem (FilePathNode->PathName, FileName, FileNameSize);
DevicePathEndNode = NextDevicePathNode (&FilePathNode->Header);
SetDevicePathEndNode (DevicePathEndNode);
AppendedDevicePath = AppendDevicePath (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)FilePathNode);
FreePool (FilePathNode);
}
}
return AppendedDevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
FindDevicePathEndNode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
while (!IsDevicePathEnd (DevicePath)) {
DevicePath = NextDevicePathNode (DevicePath);
}
return DevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
FindDevicePathNodeWithType (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN UINT8 Type,
IN UINT8 SubType OPTIONAL
)
{
EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
DevicePathNode = NULL;
while (!IsDevicePathEnd (DevicePath)) {
if ( (DevicePathType (DevicePath) == Type)
&& ((SubType == 0) || (DevicePathSubType (DevicePath) == SubType)))
{
DevicePathNode = DevicePath;
break;
}
DevicePath = NextDevicePathNode (DevicePath);
}
return DevicePathNode;
}
EFI_DEVICE_PATH_PROTOCOL *
AbsoluteDevicePath (
IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RelativePath OPTIONAL
)
{
EFI_DEVICE_PATH_PROTOCOL *HandlePath;
EFI_DEVICE_PATH_PROTOCOL *NewPath;
HandlePath = DevicePathFromHandle (Handle);
if (HandlePath == NULL) {
return NULL;
}
if (RelativePath == NULL) {
return DuplicateDevicePath (HandlePath);
}
NewPath = AppendDevicePath (HandlePath, RelativePath);
if (NewPath == NULL) {
return DuplicateDevicePath (HandlePath);
}
return NewPath;
}
EFI_DEVICE_PATH_PROTOCOL *
TrailedBooterDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_DEVICE_PATH_PROTOCOL *DevicePathWalker;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
FILEPATH_DEVICE_PATH *FilePath;
FILEPATH_DEVICE_PATH *NewFilePath;
UINTN Length;
UINTN Size;
DevicePathWalker = DevicePath;
while (!IsDevicePathEnd (DevicePathWalker)) {
if ( (DevicePathType (DevicePathWalker) == MEDIA_DEVICE_PATH)
&& (DevicePathSubType (DevicePathWalker) == MEDIA_FILEPATH_DP)
&& IsDevicePathEnd (NextDevicePathNode (DevicePathWalker)))
{
FilePath = (FILEPATH_DEVICE_PATH *)DevicePathWalker;
Length = OcFileDevicePathNameLen (FilePath);
if (Length > 0) {
if (FilePath->PathName[Length - 1] == L'\\') {
//
// Already appended, good. It should never be true with Apple entries though.
//
return NULL;
}
if ((Length > 4) && ( (FilePath->PathName[Length - 4] != '.')
|| ((FilePath->PathName[Length - 3] != 'e') && (FilePath->PathName[Length - 3] != 'E'))
|| ((FilePath->PathName[Length - 2] != 'f') && (FilePath->PathName[Length - 2] != 'F'))
|| ((FilePath->PathName[Length - 1] != 'i') && (FilePath->PathName[Length - 1] != 'I'))))
{
//
// Found! We should have gotten something like:
// PciRoot(0x0)/Pci(...)/Pci(...)/Sata(...)/HD(...)/\com.apple.recovery.boot
//
Size = GetDevicePathSize (DevicePath);
NewDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (Size + sizeof (CHAR16));
if (NewDevicePath == NULL) {
//
// Allocation failure, just ignore.
//
return NULL;
}
//
// Strip the string termination and DP end node, which will get re-set
//
CopyMem (NewDevicePath, DevicePath, Size - sizeof (CHAR16) - END_DEVICE_PATH_LENGTH);
NewFilePath = (FILEPATH_DEVICE_PATH *)((UINT8 *)DevicePathWalker - (UINT8 *)DevicePath + (UINT8 *)NewDevicePath);
Size = DevicePathNodeLength (DevicePathWalker) + sizeof (CHAR16);
SetDevicePathNodeLength (NewFilePath, Size);
NewFilePath->PathName[Length] = L'\\';
NewFilePath->PathName[Length+1] = L'\0';
SetDevicePathEndNode ((UINT8 *)NewFilePath + Size);
return NewDevicePath;
}
}
}
DevicePathWalker = NextDevicePathNode (DevicePathWalker);
}
//
// Has .efi suffix or unsupported format.
//
return NULL;
}
VOID
OcFixAppleBootDevicePathNodeRestore (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,
IN CONST APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext
)
{
EFI_DEV_PATH_PTR Node;
UINT8 NodeType;
UINT8 NodeSubType;
//
// ATTENTION: This function must be carefully sync'd with changes to
// OcFixAppleBootDevicePathNode().
//
Node.DevPath = *DevicePathNode;
NodeType = DevicePathType (Node.DevPath);
NodeSubType = DevicePathSubType (Node.DevPath);
if (RestoreContext->OldPath != NULL) {
//
// Restore the previously stored Device Path prior to patching.
//
*DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL *)(
(UINTN)RestoreContext->OldPath +
((UINTN)*DevicePathNode - (UINTN)*DevicePath)
);
FreePool (*DevicePath);
*DevicePath = RestoreContext->OldPath;
return;
}
if (NodeType == MESSAGING_DEVICE_PATH) {
switch (NodeSubType) {
case MSG_SATA_DP:
Node.Sata->PortMultiplierPortNumber = RestoreContext->Types.Sata.PortMultiplierPortNumber;
break;
//
// The related patches in OcFixAppleBootDevicePathNode() are performed
// from MSG_SASEX_DP and MSG_NVME_NAMESPACE_DP but change the SubType.
// Please refer to the destination rather than the source SubType when
// matching the logic.
//
case MSG_NVME_NAMESPACE_DP:
case 0x22:
Node.NvmeNamespace->Header.SubType = RestoreContext->Types.SasExNvme.SubType;
break;
default:
break;
}
} else if (NodeType == ACPI_DEVICE_PATH) {
switch (NodeSubType) {
case ACPI_DP:
Node.Acpi->HID = RestoreContext->Types.Acpi.HID;
Node.Acpi->UID = RestoreContext->Types.Acpi.UID;
break;
case ACPI_EXTENDED_DP:
Node.ExtendedAcpi->HID = RestoreContext->Types.ExtendedAcpi.HID;
Node.ExtendedAcpi->CID = RestoreContext->Types.ExtendedAcpi.CID;
break;
default:
break;
}
}
}
VOID
OcFixAppleBootDevicePathNodeRestoreFree (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
IN OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext
)
{
//
// ATTENTION: This function must be carefully sync'd with changes to
// OcFixAppleBootDevicePathNode().
//
//
// Free the previously stored original Device Path for expansion patches.
//
if (RestoreContext->OldPath != NULL) {
FreePool (RestoreContext->OldPath);
}
}
/*
Constructs a new device path for an unrecognised device path with a hard drive
node.
@param[in,out] DevicePath A pointer to the device path to fix the node
of. It must be a pool memory buffer.
On success, may be updated with a reallocated
pool memory buffer.
@param[in,out] DevicePathNode A pointer to the device path node to fix. It
must be a node of *DevicePath.
On success, may be updated with the
corresponding node of *DevicePath.
@param[out] RestoreContext A pointer to a context that can be used to
restore DevicePathNode's original content in
the case of failure.
On success, data may need to be freed.
@retval -1 DevicePathNode could not be fixed.
@retval 1 DevicePathNode and is valid.
*/
STATIC
INTN
InternalExpandNewPath (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode
)
{
EFI_DEVICE_PATH_PROTOCOL *HdNode;
UINTN PrefixSize;
EFI_DEVICE_PATH_PROTOCOL *ExpandedPath;
EFI_DEVICE_PATH_PROTOCOL *ExpandedNode;
DebugPrintDevicePath (DEBUG_VERBOSE, "Expanding new DP from", *DevicePath);
DebugPrintDevicePath (DEBUG_VERBOSE, "at node", *DevicePathNode);
//
// Find HD node to locate a valid Device Path of. We require the prefix
// till the offending node (e.g. a SATA node, which should be
// preceeded by a PCI chain) as well as the suffix match (though latter
// may be expanded). For example SATA should be an arbitrary VendorBlockIo
// node.
//
HdNode = FindDevicePathNodeWithType (
*DevicePath,
MEDIA_DEVICE_PATH,
MEDIA_HARDDRIVE_DP
);
if (HdNode == NULL) {
DEBUG ((DEBUG_VERBOSE, "Failed to find HD node\n"));
//
// Expansion makes little sense when we don't have a HD node.
//
return -1;
}
PrefixSize = (UINTN)*DevicePathNode - (UINTN)*DevicePath;
//
// Expand the Device Path based of the HD node and sanity-check it
// likely describes the intended path.
//
for (
ExpandedPath = OcGetNextLoadOptionDevicePath (HdNode, NULL);
ExpandedPath != NULL;
ExpandedPath = OcGetNextLoadOptionDevicePath (HdNode, ExpandedPath)
)
{
DebugPrintDevicePath (DEBUG_VERBOSE, "DP candidate", ExpandedPath);
//
// Skip this expansion if the prefix does not match.
//
if ( (GetDevicePathSize (ExpandedPath) < PrefixSize)
|| (CompareMem (ExpandedPath, *DevicePath, PrefixSize) != 0))
{
DEBUG ((DEBUG_VERBOSE, "Prefix does not match\n"));
continue;
}
//
// The suffix is handled implicitly (by OcGetNextLoadOptionDevicePath).
// Keep in mind that with this logic our broken node may expand to an
// arbitrary number of nodes now.
//
ExpandedNode = (EFI_DEVICE_PATH_PROTOCOL *)(
(UINTN)ExpandedPath + PrefixSize
);
DebugPrintDevicePath (DEBUG_VERBOSE, "accepted DP", ExpandedPath);
DebugPrintDevicePath (DEBUG_VERBOSE, "fix starting at", ExpandedNode);
DEBUG_CODE (
EFI_DEVICE_PATH_PROTOCOL *RemDevPath = ExpandedPath;
EFI_HANDLE Dev;
EFI_STATUS Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemDevPath, &Dev);
if (EFI_ERROR (Status) || (RemDevPath->Type != END_DEVICE_PATH_TYPE) || (RemDevPath->SubType != END_ENTIRE_DEVICE_PATH_SUBTYPE)) {
DEBUG ((DEBUG_VERBOSE, "borked piece of crap\n"));
}
);
*DevicePath = ExpandedPath;
*DevicePathNode = ExpandedNode;
return 1;
}
//
// No adequate expansion could be found.
//
return -1;
}
INTN
OcFixAppleBootDevicePathNode (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,
OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext OPTIONAL
)
{
INTN Result;
EFI_DEVICE_PATH_PROTOCOL *OldPath;
EFI_DEV_PATH_PTR Node;
UINT8 NodeType;
UINT8 NodeSubType;
UINTN NodeSize;
ASSERT (DevicePathNode != NULL);
//
// ATTENTION: Changes to this function must be carefully sync'd with
// OcFixAppleBootDevicePathNodeRestore().
//
if (RestoreContext != NULL) {
RestoreContext->OldPath = NULL;
}
Node.DevPath = *DevicePathNode;
NodeType = DevicePathType (Node.DevPath);
NodeSubType = DevicePathSubType (Node.DevPath);
if (NodeType == MESSAGING_DEVICE_PATH) {
switch (NodeSubType) {
case MSG_SATA_DP:
if (Node.Sata->PortMultiplierPortNumber != 0xFFFF) {
if (RestoreContext != NULL) {
RestoreContext->Types.Sata.PortMultiplierPortNumber = Node.Sata->PortMultiplierPortNumber;
}
//
// Must be set to 0xFFFF if the device is directly connected to the
// HBA. This rule has been established by UEFI 2.5 via an Erratum
// and has not been followed by Apple thus far.
// Reference: AppleACPIPlatform.kext,
// appendSATADevicePathNodeForIOMedia
//
Node.Sata->PortMultiplierPortNumber = 0xFFFF;
return 1;
}
//
// Some vendors use proprietary node types over standardised ones. Find
// a new, valid DevicePath that matches in prefix and suffix to the
// given one but ignore the data of the node that matches the malformed
// one.
// REF: https://github.com/acidanthera/bugtracker/issues/991#issue-643248184
//
OldPath = *DevicePath;
Result = InternalExpandNewPath (
DevicePath,
DevicePathNode
);
if (Result > 0) {
//
// On success, handle restoring and resources.
//
if (RestoreContext != NULL) {
RestoreContext->OldPath = OldPath;
} else {
FreePool (OldPath);
}
}
return Result;
case MSG_SASEX_DP:
//
// Apple uses SubType 0x16 (SasEx) for NVMe, while the UEFI
// Specification defines it as SubType 0x17. The structures are
// identical.
// Reference: AppleACPIPlatform.kext,
// appendNVMeDevicePathNodeForIOMedia
//
if (RestoreContext != NULL) {
RestoreContext->Types.SasExNvme.SubType = Node.DevPath->SubType;
}
STATIC_ASSERT (
sizeof (SASEX_DEVICE_PATH) != sizeof (NVME_NAMESPACE_DEVICE_PATH),
"SasEx and NVMe DPs must differ in size for fixing to be accurate."
);
NodeSize = DevicePathNodeLength (Node.DevPath);
if (NodeSize == sizeof (NVME_NAMESPACE_DEVICE_PATH)) {
Node.SasEx->Header.SubType = MSG_NVME_NAMESPACE_DP;
return 1;
}
return -1;
case MSG_NVME_NAMESPACE_DP:
//
// Workaround for MacPro5,1 using custom NVMe type.
//
if (RestoreContext != NULL) {
RestoreContext->Types.SasExNvme.SubType = Node.DevPath->SubType;
}
Node.NvmeNamespace->Header.SubType = MSG_APPLE_NVME_NAMESPACE_DP;
return 1;
default:
break;
}
} else if (NodeType == ACPI_DEVICE_PATH) {
switch (NodeSubType) {
case ACPI_DP:
if (RestoreContext != NULL) {
RestoreContext->Types.Acpi.HID = Node.Acpi->HID;
RestoreContext->Types.Acpi.UID = Node.Acpi->UID;
}
if (EISA_ID_TO_NUM (Node.Acpi->HID) == 0x0A03) {
//
// In some types of firmware, UIDs for PciRoot do not match between ACPI tables and UEFI
// UEFI Device Paths. The former contain 0x00, 0x40, 0x80, 0xC0 values, while
// the latter have ascending numbers.
// Reference: https://github.com/acidanthera/bugtracker/issues/664.
// On other boards it is be even more erratic, refer to:
// https://github.com/acidanthera/bugtracker/issues/664#issuecomment-647526506
// On older boards there also is a PCI0/_UID1 issue, refer to:
// https://github.com/acidanthera/bugtracker/issues/664#issuecomment-663873846
//
switch (Node.Acpi->UID) {
case 0x1:
Node.Acpi->UID = 0;
return 1;
case 0x10:
case 0x40:
Node.Acpi->UID = 1;
return 1;
case 0x20:
case 0x80:
Node.Acpi->UID = 2;
return 1;
case 0x28:
case 0xC0:
Node.Acpi->UID = 3;
return 1;
case 0x30:
Node.Acpi->UID = 4;
return 1;
case 0x38:
Node.Acpi->UID = 5;
return 1;
default:
break;
}
//
// Apple uses PciRoot (EISA 0x0A03) nodes while some types of firmware might use
// PcieRoot (EISA 0x0A08).
//
Node.Acpi->HID = BitFieldWrite32 (
Node.Acpi->HID,
16,
31,
0x0A08
);
return 1;
}
return -1;
case ACPI_EXTENDED_DP:
if (RestoreContext != NULL) {
RestoreContext->Types.ExtendedAcpi.HID = Node.ExtendedAcpi->HID;
RestoreContext->Types.ExtendedAcpi.CID = Node.ExtendedAcpi->CID;
}
//
// Apple uses PciRoot (EISA 0x0A03) nodes while some types of firmware might use
// PcieRoot (EISA 0x0A08).
//
if (EISA_ID_TO_NUM (Node.ExtendedAcpi->HID) == 0x0A03) {
Node.ExtendedAcpi->HID = BitFieldWrite32 (
Node.ExtendedAcpi->HID,
16,
31,
0x0A08
);
return 1;
}
if ( (EISA_ID_TO_NUM (Node.ExtendedAcpi->CID) == 0x0A03)
&& (EISA_ID_TO_NUM (Node.ExtendedAcpi->HID) != 0x0A08))
{
Node.ExtendedAcpi->CID = BitFieldWrite32 (
Node.ExtendedAcpi->CID,
16,
31,
0x0A08
);
return 1;
}
return -1;
default:
break;
}
}
return 0;
}
INTN
OcFixAppleBootDevicePath (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **RemainingDevicePath
)
{
INTN Result;
INTN NodePatched;
UINTN DevicePathSize;
APPLE_BOOT_DP_PATCH_CONTEXT FirstNodeRestoreContext;
APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContextPtr;
EFI_HANDLE Device;
ASSERT (DevicePath != NULL);
ASSERT (*DevicePath != NULL);
ASSERT (IsDevicePathValid (*DevicePath, 0));
//
// Restoring is only required for the first Device Path node. Please refer
// to the loop for an explanation.
//
RestoreContextPtr = &FirstNodeRestoreContext;
NodePatched = 0;
do {
//
// Retrieve the first Device Path node that cannot be located.
//
*RemainingDevicePath = *DevicePath;
gBS->LocateDevicePath (
&gEfiDevicePathProtocolGuid,
RemainingDevicePath,
&Device
);
//
// Patch the potentially invalid node.
//
Result = OcFixAppleBootDevicePathNode (
DevicePath,
RemainingDevicePath,
RestoreContextPtr
);
//
// Save a restore context only for the first processing of the first node.
// The reason for this is when the first node cannot be located with any
// patch applied, the Device Path may be of a prefix short-form and may
// possibly be expanded successfully unmodified.
//
RestoreContextPtr = NULL;
//
// Continue as long as nodes are being patched. Remember patch status.
//
NodePatched |= Result > 0;
} while (Result > 0);
if (Result < 0) {
if (NodePatched != 0) {
if (*RemainingDevicePath == *DevicePath) {
//
// If the path could not be fixed, restore the first node if it's the
// one failing to be located. Please refer to the loop for an
// explanation.
// If advancing by at least one node happened, the Device Path cannot
// be of a prefix short-form and hence restoring is not beneficial (and
// most especially would require tracking every node individually).
//
OcFixAppleBootDevicePathNodeRestore (
DevicePath,
RemainingDevicePath,
&FirstNodeRestoreContext
);
} else {
//
// If patching was successful, explicitly free the used resources.
//
OcFixAppleBootDevicePathNodeRestoreFree (
*DevicePath,
&FirstNodeRestoreContext
);
}
}
return -1;
}
//
// Double-check that *RemainingDevicePath still points into *DevicePath.
//
DEBUG_CODE_BEGIN ();
DevicePathSize = GetDevicePathSize (*DevicePath);
ASSERT ((UINTN)*RemainingDevicePath >= (UINTN)*DevicePath);
ASSERT ((UINTN)*RemainingDevicePath < ((UINTN)*DevicePath) + DevicePathSize);
DEBUG_CODE_END ();
return NodePatched;
}
STATIC
BOOLEAN
InternalFileDevicePathsEqualClipBottom (
IN CONST FILEPATH_DEVICE_PATH *FilePath,
IN OUT UINTN *FilePathLength,
IN OUT UINTN *ClipIndex
)
{
UINTN Index;
ASSERT (FilePathLength != NULL);
ASSERT (*FilePathLength != 0);
ASSERT (FilePath != NULL);
ASSERT (ClipIndex != NULL);
Index = *ClipIndex;
if (FilePath->PathName[Index] == L'\\') {
*ClipIndex = Index + 1;
--(*FilePathLength);
return TRUE;
}
return FALSE;
}
STATIC
UINTN
InternalFileDevicePathsEqualClipNode (
IN FILEPATH_DEVICE_PATH **FilePath,
OUT UINTN *ClipIndex
)
{
EFI_DEV_PATH_PTR DevPath;
UINTN Index;
UINTN Length;
EFI_DEVICE_PATH_PROTOCOL *NextNode;
ASSERT (FilePath != NULL);
ASSERT (ClipIndex != NULL);
//
// It is unlikely to be encountered, but empty nodes are not forbidden.
//
for (
Length = 0, NextNode = &(*FilePath)->Header;
Length == 0;
NextNode = NextDevicePathNode (DevPath.DevPath)
)
{
DevPath.DevPath = NextNode;
if ( (DevicePathType (DevPath.DevPath) != MEDIA_DEVICE_PATH)
|| (DevicePathSubType (DevPath.DevPath) != MEDIA_FILEPATH_DP))
{
Length = 0;
break;
}
Length = OcFileDevicePathNameLen (DevPath.FilePath);
if (Length > 0) {
Index = 0;
InternalFileDevicePathsEqualClipBottom (DevPath.FilePath, &Length, &Index);
if ( (Length > 0)
&& (DevPath.FilePath->PathName[Index + Length - 1] == L'\\'))
{
--Length;
}
*ClipIndex = Index;
}
}
*FilePath = DevPath.FilePath;
return Length;
}
STATIC
UINTN
InternalFileDevicePathsEqualClipNextNode (
IN FILEPATH_DEVICE_PATH **FilePath,
OUT UINTN *ClipIndex
)
{
ASSERT (FilePath != NULL);
ASSERT (ClipIndex != NULL);
*FilePath = (FILEPATH_DEVICE_PATH *)NextDevicePathNode (*FilePath);
return InternalFileDevicePathsEqualClipNode (FilePath, ClipIndex);
}
BOOLEAN
InternalFileDevicePathsEqualWorker (
IN FILEPATH_DEVICE_PATH **FilePath1,
IN FILEPATH_DEVICE_PATH **FilePath2
)
{
UINTN Clip1Index;
UINTN Clip2Index;
UINTN Len1;
UINTN Len2;
UINTN CurrentLen;
UINTN Index;
CHAR16 Char1;
CHAR16 Char2;
BOOLEAN Result;
ASSERT (FilePath1 != NULL);
ASSERT (*FilePath1 != NULL);
ASSERT (FilePath2 != NULL);
ASSERT (*FilePath2 != NULL);
ASSERT (IsDevicePathValid (&(*FilePath1)->Header, 0));
ASSERT (IsDevicePathValid (&(*FilePath2)->Header, 0));
Len1 = InternalFileDevicePathsEqualClipNode (FilePath1, &Clip1Index);
Len2 = InternalFileDevicePathsEqualClipNode (FilePath2, &Clip2Index);
do {
if ((Len1 == 0) && (Len2 == 0)) {
return TRUE;
}
CurrentLen = MIN (Len1, Len2);
if (CurrentLen == 0) {
return FALSE;
}
//
// FIXME: Discuss case sensitivity. For UEFI FAT, case insensitivity is
// guaranteed.
//
for (Index = 0; Index < CurrentLen; ++Index) {
Char1 = CharToUpper ((*FilePath1)->PathName[Clip1Index + Index]);
Char2 = CharToUpper ((*FilePath2)->PathName[Clip2Index + Index]);
if (Char1 != Char2) {
return FALSE;
}
}
if (Len1 == Len2) {
Len1 = InternalFileDevicePathsEqualClipNextNode (FilePath1, &Clip1Index);
Len2 = InternalFileDevicePathsEqualClipNextNode (FilePath2, &Clip2Index);
} else if (Len1 < Len2) {
Len1 = InternalFileDevicePathsEqualClipNextNode (FilePath1, &Clip1Index);
if (Len1 == 0) {
return FALSE;
}
Len2 -= CurrentLen;
Clip2Index += CurrentLen;
//
// Switching to the next node for the other Device Path implies a path
// separator. Verify we hit such in the currently walked path too.
//
Result = InternalFileDevicePathsEqualClipBottom (*FilePath2, &Len2, &Clip2Index);
if (!Result) {
return FALSE;
}
} else {
Len2 = InternalFileDevicePathsEqualClipNextNode (FilePath2, &Clip2Index);
if (Len2 == 0) {
return FALSE;
}
Len1 -= CurrentLen;
Clip1Index += CurrentLen;
//
// Switching to the next node for the other Device Path implies a path
// separator. Verify we hit such in the currently walked path too.
//
Result = InternalFileDevicePathsEqualClipBottom (*FilePath1, &Len1, &Clip1Index);
if (!Result) {
return FALSE;
}
}
} while (TRUE);
}
/**
Check whether File Device Paths are equal.
@param[in] FilePath1 The first device path protocol to compare.
@param[in] FilePath2 The second device path protocol to compare.
@retval TRUE The device paths matched
@retval FALSE The device paths were different
**/
BOOLEAN
FileDevicePathsEqual (
IN FILEPATH_DEVICE_PATH *FilePath1,
IN FILEPATH_DEVICE_PATH *FilePath2
)
{
ASSERT (FilePath1 != NULL);
ASSERT (FilePath2 != NULL);
return InternalFileDevicePathsEqualWorker (&FilePath1, &FilePath2);
}
STATIC
BOOLEAN
InternalDevicePathCmpWorker (
IN EFI_DEVICE_PATH_PROTOCOL *ParentPath,
IN EFI_DEVICE_PATH_PROTOCOL *ChildPath,
IN BOOLEAN CheckChild
)
{
BOOLEAN Result;
INTN CmpResult;
EFI_DEV_PATH_PTR ChildPathPtr;
EFI_DEV_PATH_PTR ParentPathPtr;
UINT8 NodeType;
UINT8 NodeSubType;
UINTN NodeSize;
ASSERT (ParentPath != NULL);
ASSERT (IsDevicePathValid (ParentPath, 0));
ASSERT (ChildPath != NULL);
ASSERT (IsDevicePathValid (ChildPath, 0));
ParentPathPtr.DevPath = ParentPath;
ChildPathPtr.DevPath = ChildPath;
while (TRUE) {
NodeType = DevicePathType (ChildPathPtr.DevPath);
NodeSubType = DevicePathSubType (ChildPathPtr.DevPath);
if (NodeType == END_DEVICE_PATH_TYPE) {
//
// We only support single-instance Device Paths.
//
ASSERT (NodeSubType == END_ENTIRE_DEVICE_PATH_SUBTYPE);
return ( CheckChild
|| (DevicePathType (ParentPathPtr.DevPath) == END_DEVICE_PATH_TYPE));
}
if ( (DevicePathType (ParentPathPtr.DevPath) != NodeType)
|| (DevicePathSubType (ParentPathPtr.DevPath) != NodeSubType))
{
return FALSE;
}
if ( (NodeType == MEDIA_DEVICE_PATH)
&& (NodeSubType == MEDIA_FILEPATH_DP))
{
//
// File Paths need special consideration for prepended and appended
// terminators, as well as multiple nodes.
//
Result = InternalFileDevicePathsEqualWorker (
&ParentPathPtr.FilePath,
&ChildPathPtr.FilePath
);
if (!Result) {
return FALSE;
}
//
// InternalFileDevicePathsEqualWorker advances the nodes.
//
} else {
NodeSize = DevicePathNodeLength (ChildPathPtr.DevPath);
if (DevicePathNodeLength (ParentPathPtr.DevPath) != NodeSize) {
return FALSE;
}
STATIC_ASSERT (
(sizeof (*ChildPathPtr.DevPath) == 4),
"The Device Path comparison logic depends on the entire header being checked"
);
CmpResult = CompareMem (
(ChildPathPtr.DevPath + 1),
(ParentPathPtr.DevPath + 1),
(NodeSize - sizeof (*ChildPathPtr.DevPath))
);
if (CmpResult != 0) {
return FALSE;
}
ParentPathPtr.DevPath = NextDevicePathNode (ParentPathPtr.DevPath);
ChildPathPtr.DevPath = NextDevicePathNode (ChildPathPtr.DevPath);
}
}
}
BOOLEAN
EFIAPI
IsDevicePathEqual (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2
)
{
return InternalDevicePathCmpWorker (DevicePath1, DevicePath2, FALSE);
}
BOOLEAN
EFIAPI
IsDevicePathChild (
IN EFI_DEVICE_PATH_PROTOCOL *ParentPath,
IN EFI_DEVICE_PATH_PROTOCOL *ChildPath
)
{
return InternalDevicePathCmpWorker (ParentPath, ChildPath, TRUE);
}
UINTN
OcFileDevicePathNameSize (
IN CONST FILEPATH_DEVICE_PATH *FilePath
)
{
ASSERT (FilePath != NULL);
ASSERT (IsDevicePathValid (&FilePath->Header, 0));
return (OcFileDevicePathNameLen (FilePath) + 1) * sizeof (*FilePath->PathName);
}
UINTN
OcFileDevicePathNameLen (
IN CONST FILEPATH_DEVICE_PATH *FilePath
)
{
UINTN Size;
UINTN Len;
ASSERT (FilePath != NULL);
ASSERT (IsDevicePathValid (&FilePath->Header, 0));
Size = DevicePathNodeLength (FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;
//
// Account for more than one termination character.
//
Len = (Size / sizeof (*FilePath->PathName)) - 1;
while (Len > 0 && FilePath->PathName[Len - 1] == L'\0') {
--Len;
}
return Len;
}
/**
Retrieve the length of the full file path described by DevicePath.
@param[in] DevicePath The Device Path to inspect.
@returns The length of the full file path.
@retval 0 DevicePath does not start with a File Path node or contains
non-terminating nodes that are not File Path nodes.
**/
UINTN
OcFileDevicePathFullNameLen (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
UINTN PathLength;
CONST FILEPATH_DEVICE_PATH *FilePath;
ASSERT (DevicePath != NULL);
ASSERT (IsDevicePathValid (DevicePath, 0));
PathLength = 0;
do {
//
// On the first iteration, this ensures the path is not immediately
// terminated.
//
if ( (DevicePath->Type != MEDIA_DEVICE_PATH)
|| (DevicePath->SubType != MEDIA_FILEPATH_DP))
{
return 0;
}
FilePath = (FILEPATH_DEVICE_PATH *)DevicePath;
//
// Each node requires separator or CHAR_NULL
//
PathLength += OcFileDevicePathNameLen (FilePath) + 1;
DevicePath = NextDevicePathNode (DevicePath);
} while (!IsDevicePathEnd (DevicePath));
return PathLength - 1;
}
/**
Retrieve the size of the full file path described by DevicePath.
@param[in] DevicePath The Device Path to inspect.
@returns The size of the full file path.
@retval 0 DevicePath does not start with a File Path node or contains
non-terminating nodes that are not File Path nodes.
**/
UINTN
OcFileDevicePathFullNameSize (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
UINTN Len;
Len = OcFileDevicePathFullNameLen (DevicePath);
if (Len == 0) {
return 0;
}
return (Len + 1) * sizeof (CHAR16);
}
/**
Retrieve the full file path described by FilePath.
The caller is expected to call OcFileDevicePathFullNameSize() or ensure its
guarantees are met.
@param[out] PathName On output, the full file path of FilePath.
@param[in] FilePath The File Device Path to inspect.
@param[in] PathNameSize The size, in bytes, of PathName. Must equal the
actual full file path size.
**/
VOID
OcFileDevicePathFullName (
OUT CHAR16 *PathName,
IN CONST FILEPATH_DEVICE_PATH *FilePath,
IN UINTN PathNameSize
)
{
UINTN PathLen;
ASSERT (PathName != NULL);
ASSERT (FilePath != NULL);
ASSERT (IsDevicePathValid (&FilePath->Header, 0));
ASSERT (PathNameSize == OcFileDevicePathFullNameSize (&FilePath->Header));
//
// Note: The UEFI spec declares that a path separator may optionally be
// present at the beginning or end of any node's PathName. This is not
// currently supported here. Any fix would need to be applied here and
// in OcFileDevicePathNameLen.
//
do {
PathLen = OcFileDevicePathNameLen (FilePath);
CopyMem (
PathName,
FilePath->PathName,
PathLen * sizeof (*FilePath->PathName)
);
PathName += PathLen;
*PathName++ = L'\\';
FilePath = (CONST FILEPATH_DEVICE_PATH *)NextDevicePathNode (FilePath);
} while (!IsDevicePathEnd (FilePath));
*(PathName - 1) = CHAR_NULL;
}
CHAR16 *
OcCopyDevicePathFullName (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FileDevicePath OPTIONAL
)
{
CHAR16 *Path;
EFI_DEVICE_PATH_PROTOCOL *CurrNode;
UINTN PathSize;
Path = NULL;
if (FileDevicePath != NULL) {
*FileDevicePath = NULL;
}
for (CurrNode = DevicePath; !IsDevicePathEnd (CurrNode); CurrNode = NextDevicePathNode (CurrNode)) {
if ( (DevicePathType (CurrNode) == MEDIA_DEVICE_PATH)
&& (DevicePathSubType (CurrNode) == MEDIA_FILEPATH_DP))
{
if (FileDevicePath != NULL) {
*FileDevicePath = CurrNode;
}
//
// Perform copying of all the underlying nodes due to potential unaligned access.
//
PathSize = OcFileDevicePathFullNameSize (CurrNode);
if (PathSize == 0) {
return NULL;
}
Path = AllocatePool (PathSize);
if (Path == NULL) {
return NULL;
}
OcFileDevicePathFullName (Path, (FILEPATH_DEVICE_PATH *)CurrNode, PathSize);
break;
}
}
return Path;
}
EFI_DEVICE_PATH_PROTOCOL *
OcAppendDevicePathInstanceDedupe (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
)
{
INTN CmpResult;
EFI_DEVICE_PATH_PROTOCOL *DevPathWalker;
EFI_DEVICE_PATH_PROTOCOL *CurrentInstance;
UINTN AppendInstanceSize;
UINTN CurrentInstanceSize;
ASSERT (DevicePathInstance != NULL);
if (DevicePath != NULL) {
AppendInstanceSize = GetDevicePathSize (DevicePathInstance);
DevPathWalker = DevicePath;
while (TRUE) {
CurrentInstance = GetNextDevicePathInstance (
&DevPathWalker,
&CurrentInstanceSize
);
if (CurrentInstance == NULL) {
break;
}
if (CurrentInstanceSize != AppendInstanceSize) {
FreePool (CurrentInstance);
continue;
}
CmpResult = CompareMem (
CurrentInstance,
DevicePathInstance,
CurrentInstanceSize
);
FreePool (CurrentInstance);
if (CmpResult == 0) {
return DuplicateDevicePath (DevicePath);
}
}
}
return AppendDevicePathInstance (DevicePath, DevicePathInstance);
}
UINTN
OcGetNumDevicePathInstances (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
UINTN NumInstances;
NumInstances = 1;
while (!IsDevicePathEnd (DevicePath)) {
if (IsDevicePathEndInstance (DevicePath)) {
++NumInstances;
}
DevicePath = NextDevicePathNode (DevicePath);
}
return NumInstances;
}
BOOLEAN
OcDevicePathHasFilePathSuffix (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 *Suffix,
IN UINTN SuffixLen
)
{
FILEPATH_DEVICE_PATH *FilePath;
UINTN PathNameLen;
UINTN PathNameSize;
CHAR16 *PathName;
INTN Result;
//
// OcStrinCmp will be needed in case of a mismatch.
//
ASSERT (SuffixLen == StrLen (Suffix));
FilePath = (FILEPATH_DEVICE_PATH *)FindDevicePathNodeWithType (
DevicePath,
MEDIA_DEVICE_PATH,
MEDIA_FILEPATH_DP
);
if (FilePath == NULL) {
return FALSE;
}
PathNameLen = OcFileDevicePathFullNameLen (&FilePath->Header);
if (PathNameLen < SuffixLen) {
return FALSE;
}
PathNameSize = (PathNameLen + 1) * sizeof (CHAR16);
PathName = AllocatePool (PathNameSize);
if (PathName == NULL) {
return FALSE;
}
OcFileDevicePathFullName (PathName, FilePath, PathNameSize);
Result = OcStriCmp (
&PathName[PathNameLen - SuffixLen],
Suffix
);
FreePool (PathName);
return Result == 0;
}
|
409ba8eed39ea5f8619b610882d4bb8a33356e66
|
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
|
/AKWF-c/AKWF_snippets/AKWF_snippet_0038.h
|
9c617fa5f91b59bea1b1bbba795f6007a15c3f5e
|
[
"CC0-1.0"
] |
permissive
|
KristofferKarlAxelEkstrand/AKWF-FREE
|
b2defa1a2d389d309be6dd2e9f968923daf80d1b
|
cf8171df36e9fec25416b5f568b72a6e2cb69194
|
refs/heads/master
| 2023-07-23T18:22:36.939705
| 2023-07-10T17:14:40
| 2023-07-10T17:14:40
| 145,817,187
| 359
| 59
|
CC0-1.0
| 2023-07-10T17:14:41
| 2018-08-23T07:26:56
| null |
UTF-8
|
C
| false
| false
| 4,688
|
h
|
AKWF_snippet_0038.h
|
/* Adventure Kid Waveforms (AKWF) converted for use with Teensy Audio Library
*
* Adventure Kid Waveforms(AKWF) Open waveforms library
* https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/
*
* This code is in the public domain, CC0 1.0 Universal (CC0 1.0)
* https://creativecommons.org/publicdomain/zero/1.0/
*
* Converted by Brad Roy, https://github.com/prosper00
*/
/* AKWF_snippet_0038 256 samples
+-----------------------------------------------------------------------------------------------------------------+
| ****** ****** |
| * ** *** * |
| ** * * ******* ********* ** * |
| ************* ** **************** |
| ****** * * * * ****** |
| **** ****** |
|*** **** * |
|* **** **|
| **** **|
| ** ** |
| * * * ** * |
| ***** **** **** **** |
| ********* ********* |
| ****** * * ***** |
| ************** |
+-----------------------------------------------------------------------------------------------------------------+
*/
const uint16_t AKWF_snippet_0038 [] = {
33754, 31768, 31031, 35162, 37785, 38691, 38280, 38783, 39674, 38903, 38881, 41206, 40939, 42343, 42637, 43634,
44240, 43797, 44971, 45014, 46398, 47068, 46363, 46245, 48789, 49991, 48541, 50010, 49519, 45178, 46624, 49210,
48028, 48593, 49593, 46282, 46765, 47859, 49339, 49067, 46445, 48419, 50322, 48862, 48019, 50050, 50848, 53485,
52414, 48813, 49200, 48374, 50825, 52340, 50215, 53471, 53766, 55456, 57317, 57241, 58132, 58607, 58893, 59807,
61766, 61675, 62164, 61240, 59929, 61613, 62633, 61781, 62521, 61826, 60515, 60603, 62328, 61646, 61590, 60195,
59008, 58622, 57710, 56901, 57111, 56389, 53327, 53267, 50685, 52333, 50807, 48251, 49582, 47969, 50512, 53284,
51145, 49638, 47848, 48678, 49709, 48687, 45819, 48085, 49816, 46994, 47196, 45818, 48970, 48649, 47241, 48720,
46834, 44615, 48689, 50047, 48207, 48830, 48249, 46744, 45134, 46414, 45919, 44695, 44521, 42864, 43799, 43462,
41946, 42515, 40256, 39196, 36399, 37007, 39446, 38333, 37942, 37705, 37372, 35988, 32009, 29566, 32311, 32874,
30367, 28781, 29755, 28849, 24411, 21842, 24093, 21300, 18797, 17986, 16218, 16466, 16034, 20082, 18916, 15762,
14666, 12968, 13064, 12766, 12418, 12168, 11247, 12700, 13781, 12805, 13328, 14613, 12698, 13165, 14902, 12110,
10393, 9985, 11030, 8816, 7241, 8409, 7995, 7576, 7050, 3576, 6028, 7018, 5350, 3627, 4, 1495,
1719, 2984, 3036, 4018, 6216, 6495, 4570, 2390, 2907, 5071, 6650, 6247, 3394, 3120, 2303, 1522,
1489, 1572, 4423, 6024, 7520, 4633, 5468, 8007, 7478, 9166, 9096, 7531, 10228, 11223, 10671, 11235,
14418, 15090, 11982, 14110, 14273, 14178, 14132, 13913, 12067, 11341, 12884, 12600, 13636, 13725, 13833, 15867,
17010, 19974, 18829, 16178, 17196, 16783, 19402, 20071, 22890, 23754, 23131, 26638, 29991, 30347, 29708, 32074,
};
|
0bf9becaaeb87bbb27d3e7bbe017cdbbedfd4777
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/third_party/intel/popcntintrin.internal.h
|
18a9f9da1fd1704256f227e51a2d84da4f860a8f
|
[
"ISC"
] |
permissive
|
jart/cosmopolitan
|
fb11b5658939023977060a7c6c71a74093d9cb44
|
0d748ad58e1063dd1f8560f18a0c75293b9415b7
|
refs/heads/master
| 2023-09-06T09:17:29.303607
| 2023-09-02T03:49:13
| 2023-09-02T03:50:18
| 272,457,606
| 11,887
| 435
|
ISC
| 2023-09-14T17:47:58
| 2020-06-15T14:16:13
|
C
|
UTF-8
|
C
| false
| false
| 713
|
h
|
popcntintrin.internal.h
|
/* clang-format off */
#if defined(__x86_64__) && !(__ASSEMBLER__ + __LINKER__ + 0)
#ifndef _POPCNTINTRIN_H_INCLUDED
#define _POPCNTINTRIN_H_INCLUDED
#ifndef __POPCNT__
#pragma GCC push_options
#pragma GCC target("popcnt")
#define __DISABLE_POPCNT__
#endif
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_popcnt_u32 (unsigned int __X)
{
return __builtin_popcount (__X);
}
#ifdef __x86_64__
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_popcnt_u64 (unsigned long long __X)
{
return __builtin_popcountll (__X);
}
#endif
#ifdef __DISABLE_POPCNT__
#undef __DISABLE_POPCNT__
#pragma GCC pop_options
#endif
#endif
#endif
|
9a1f6857bb9c0ad48d69c15103e496608a9c14f8
|
76f9898ff7a555f4a729d725056a317af818375d
|
/assets/objects/object_gi_clothes/object_gi_clothes.h
|
4af1b61cd86314cabd3383db8956f6f778abe1f3
|
[] |
no_license
|
z64proto/sw97
|
0b65837ab2f2a4073faca5670761d7fe0e74d29d
|
f571505ade2cefd4a5b5d19da06d33e7c6b02c60
|
refs/heads/master
| 2023-08-01T02:47:42.895871
| 2022-05-15T20:29:08
| 2022-05-15T20:29:08
| 430,216,978
| 208
| 29
| null | 2021-11-22T12:23:50
| 2021-11-20T21:52:59
|
C
|
UTF-8
|
C
| false
| false
| 239
|
h
|
object_gi_clothes.h
|
extern u64 object_gi_clothesTex_000000[];
extern Gfx gGiGoronCollarColorDL[];
extern Gfx gGiZoraCollarColorDL[];
extern Gfx gGiGoronTunicColorDL[];
extern Gfx gGiZoraTunicColorDL[];
extern Gfx gGiTunicCollarDL[];
extern Gfx gGiTunicDL[];
|
b2b6c8e55cf51492cdc001094bd4b0e43375d753
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/lib/libcbor/src/cbor.h
|
f38601079476571942722fdfb61a7147a8710975
|
[
"MIT"
] |
permissive
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 1,703
|
h
|
cbor.h
|
/*
* Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
*
* libcbor is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIBCBOR_H_
#define LIBCBOR_H_
#include "cbor/common.h"
#include "cbor/data.h"
#include "cbor/arrays.h"
#include "cbor/bytestrings.h"
#include "cbor/floats_ctrls.h"
#include "cbor/ints.h"
#include "cbor/maps.h"
#include "cbor/strings.h"
#include "cbor/tags.h"
#include "cbor/callbacks.h"
#include "cbor/cbor_export.h"
#include "cbor/encoding.h"
#include "cbor/serialization.h"
#include "cbor/streaming.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* ============================================================================
* High level decoding
* ============================================================================
*/
/** Loads data item from a buffer
*
* @param source The buffer
* @param source_size
* @param result[out] Result indicator. #CBOR_ERR_NONE on success
* @return **new** CBOR item or `NULL` on failure. In that case, \p result
* contains location and description of the error.
*/
_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_load(
cbor_data source, size_t source_size, struct cbor_load_result* result);
/** Take a deep copy of an item
*
* All the reference counts in the new structure are set to one.
*
* @param item[borrow] item to copy
* @return **new** CBOR deep copy or `NULL` on failure.
*/
_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_copy(cbor_item_t* item);
#if CBOR_PRETTY_PRINTER
#include <stdio.h>
CBOR_EXPORT void cbor_describe(cbor_item_t* item, FILE* out);
#endif
#ifdef __cplusplus
}
#endif
#endif // LIBCBOR_H_
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.