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
bafbee8cb173007e436fb28931708f03d7218a40
3225f903ab65e9e242f250a02b3b74fc7e34b098
/third_party/libuip/net/rime/mesh.c
25ea280dd257e750386ca059b9f186352b78f115
[ "MIT", "BSD-2-Clause" ]
permissive
timvideos/litex-buildenv
6f7657a0d2836f66bbc8ad29f89f1f975eda7832
fafb0f1c645a0d36ff4947686b4d2d8e3433f686
refs/heads/master
2022-06-04T18:02:22.567089
2022-05-21T15:21:25
2022-05-21T15:21:25
115,785,208
217
88
BSD-2-Clause
2022-05-21T15:21:26
2017-12-30T08:50:22
Python
UTF-8
C
false
false
6,266
c
mesh.c
/* * Copyright (c) 2007, Swedish Institute of Computer Science. * 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. * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. * * This file is part of the Contiki operating system. * */ /** * \file * A mesh routing protocol * \author * Adam Dunkels <adam@sics.se> */ /** * \addtogroup rimemesh * @{ */ #include "contiki.h" #include "net/rime/rime.h" #include "net/rime/route.h" #include "net/rime/mesh.h" #include <stddef.h> /* For offsetof */ #define PACKET_TIMEOUT (CLOCK_SECOND * 10) #define DEBUG 0 #if DEBUG #include <stdio.h> #define PRINTF(...) printf(__VA_ARGS__) #else #define PRINTF(...) #endif /*---------------------------------------------------------------------------*/ static void data_packet_received(struct multihop_conn *multihop, const linkaddr_t *from, const linkaddr_t *prevhop, uint8_t hops) { struct mesh_conn *c = (struct mesh_conn *) ((char *)multihop - offsetof(struct mesh_conn, multihop)); struct route_entry *rt; /* Refresh the route when we hear a packet from a neighbor. */ rt = route_lookup(from); if(rt != NULL) { route_refresh(rt); } if(c->cb->recv) { c->cb->recv(c, from, hops); } } /*---------------------------------------------------------------------------*/ static linkaddr_t * data_packet_forward(struct multihop_conn *multihop, const linkaddr_t *originator, const linkaddr_t *dest, const linkaddr_t *prevhop, uint8_t hops) { struct route_entry *rt; struct mesh_conn *c = (struct mesh_conn *) ((char *)multihop - offsetof(struct mesh_conn, multihop)); rt = route_lookup(dest); if(rt == NULL) { if(c->queued_data != NULL) { queuebuf_free(c->queued_data); } PRINTF("data_packet_forward: queueing data, sending rreq\n"); c->queued_data = queuebuf_new_from_packetbuf(); linkaddr_copy(&c->queued_data_dest, dest); route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT); return NULL; } else { route_refresh(rt); } return &rt->nexthop; } /*---------------------------------------------------------------------------*/ static void found_route(struct route_discovery_conn *rdc, const linkaddr_t *dest) { struct route_entry *rt; struct mesh_conn *c = (struct mesh_conn *) ((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn)); PRINTF("found_route\n"); if(c->queued_data != NULL && linkaddr_cmp(dest, &c->queued_data_dest)) { queuebuf_to_packetbuf(c->queued_data); queuebuf_free(c->queued_data); c->queued_data = NULL; rt = route_lookup(dest); if(rt != NULL) { multihop_resend(&c->multihop, &rt->nexthop); if(c->cb->sent != NULL) { c->cb->sent(c); } } else { if(c->cb->timedout != NULL) { c->cb->timedout(c); } } } } /*---------------------------------------------------------------------------*/ static void route_timed_out(struct route_discovery_conn *rdc) { struct mesh_conn *c = (struct mesh_conn *) ((char *)rdc - offsetof(struct mesh_conn, route_discovery_conn)); if(c->queued_data != NULL) { queuebuf_free(c->queued_data); c->queued_data = NULL; } if(c->cb->timedout) { c->cb->timedout(c); } } /*---------------------------------------------------------------------------*/ static const struct multihop_callbacks data_callbacks = { data_packet_received, data_packet_forward }; static const struct route_discovery_callbacks route_discovery_callbacks = { found_route, route_timed_out }; /*---------------------------------------------------------------------------*/ void mesh_open(struct mesh_conn *c, uint16_t channels, const struct mesh_callbacks *callbacks) { route_init(); multihop_open(&c->multihop, channels, &data_callbacks); route_discovery_open(&c->route_discovery_conn, CLOCK_SECOND * 2, channels + 1, &route_discovery_callbacks); c->cb = callbacks; } /*---------------------------------------------------------------------------*/ void mesh_close(struct mesh_conn *c) { multihop_close(&c->multihop); route_discovery_close(&c->route_discovery_conn); } /*---------------------------------------------------------------------------*/ int mesh_send(struct mesh_conn *c, const linkaddr_t *to) { int could_send; PRINTF("%d.%d: mesh_send to %d.%d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], to->u8[0], to->u8[1]); could_send = multihop_send(&c->multihop, to); if(!could_send) { PRINTF("mesh_send: could not send\n"); return 0; } if(c->cb->sent != NULL) { c->cb->sent(c); } return 1; } /*---------------------------------------------------------------------------*/ int mesh_ready(struct mesh_conn *c) { return (c->queued_data == NULL); } /** @} */
fc837bee5cdaf0017d1f8488bc3e0a2c1ae9b47c
526b17ad25eec622b8f266034df3506ca1580ce6
/ppdc/ppdc-private.h
1f2e60617bd132493aa33243c98b96492a8db000
[ "LLVM-exception", "Apache-2.0", "LicenseRef-scancode-warranty-disclaimer", "EPL-1.0", "GPL-2.0-only", "LGPL-2.0-only" ]
permissive
apple/cups
906903c936f9ec702e50dcd9971ec71af90a56fb
ec055da6794984133d48cc376f04e10af62b64dc
refs/heads/master
2023-08-24T17:53:09.249969
2022-06-27T16:22:46
2022-06-27T16:22:46
44,137,852
1,875
570
Apache-2.0
2023-01-19T21:23:20
2015-10-12T22:33:18
C
UTF-8
C
false
false
865
h
ppdc-private.h
// // Private definitions for the CUPS PPD Compiler. // // Copyright 2009-2010 by Apple Inc. // // Licensed under Apache License v2.0. See the file "LICENSE" for more information. // #ifndef _PPDC_PRIVATE_H_ # define _PPDC_PRIVATE_H_ // // Include necessary headers... // # include "ppdc.h" # include <cups/cups-private.h> // // Macros... // # ifdef PPDC_DEBUG # define PPDC_NEW DEBUG_printf(("%s: %p new", class_name(), this)) # define PPDC_NEWVAL(s) DEBUG_printf(("%s(\"%s\"): %p new", class_name(), s, this)) # define PPDC_DELETE DEBUG_printf(("%s: %p delete", class_name(), this)) # define PPDC_DELETEVAL(s) DEBUG_printf(("%s(\"%s\"): %p delete", class_name(), s, this)) # else # define PPDC_NEW # define PPDC_NEWVAL(s) # define PPDC_DELETE # define PPDC_DELETEVAL(s) # endif /* PPDC_DEBUG */ #endif // !_PPDC_PRIVATE_H_
852df0843b4a888f9fda9cf217a947722986be72
3f017c2c3a55a2ac783045a23977765862ef4b20
/firmware/isoldr/loader/kos/src/printf.c
2466a2ed0513e57a4fe93cc181eb3f3b9047812a
[]
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
9,279
c
printf.c
/* printf.c $Id: printf.c,v 1.3 2002/06/29 12:57:04 quad Exp $ DESCRIPTION An implementation of printf. CREDIT I stole it from somewhere. I can't remember where though. Sorry! TODO Cleanup the printf implementation. See if it's possible to compress its size - remove textualization modes we don't need. */ #include <arch/types.h> #include <string.h> #include <stdio.h> #define do_div(n, base) ({ int32 __res; __res = ((unsigned long) n) % (unsigned) base; n = ((unsigned long) n) / (unsigned) base; __res; }) static int32 skip_atoi (const char **s) { int32 i; i = 0; while (check_digit (**s)) i = i*10 + *((*s)++) - '0'; return i; } char* printf_number (char *str, long num, int32 base, int32 size, int32 precision, int32 type) { int32 i; char c; char sign; char tmp[66]; const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; if (type & N_LARGE) digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (type & N_LEFT) type &= ~N_ZEROPAD; if (base < 2 || base > 36) return 0; c = (type & N_ZEROPAD) ? '0' : ' '; sign = 0; if (type & N_SIGN) { if (num < 0) { sign = '-'; num = -num; size--; } else if (type & N_PLUS) { sign = '+'; size--; } else if (type & N_SPACE) { sign = ' '; size--; } } if (type & N_SPECIAL) { if (base == 16) size -= 2; else if (base == 8) size--; } i = 0; if (num == 0) tmp[i++] = '0'; else while (num != 0) tmp[i++] = digits[do_div (num,base)]; if (i > precision) precision = i; size -= precision; if (!(type & (N_ZEROPAD + N_LEFT))) { while (size-- > 0) *str++ = ' '; } if (sign) *str++ = sign; if (type & N_SPECIAL) { if (base == 8) { *str++ = '0'; } else if (base == 16) { *str++ = '0'; *str++ = digits[33]; } } if (!(type & N_LEFT)) { while (size-- > 0) *str++ = c; } while (i < precision--) *str++ = '0'; while (i-- > 0) *str++ = tmp[i]; while (size-- > 0) *str++ = ' '; return str; } int vsnprintf (char *buf, int size, const char *fmt, va_list args) { int len; unsigned long num; int i; int base; char *str; const char *s; int flags; /* NOTE: Flags to printf_number (). */ int field_width; /* NOTE: Width of output field. */ int precision; /* NOTE: min. # of digits for integers; max number of chars for from string. */ int qualifier; /* NOTE: 'h', 'l', or 'L' for integer fields. */ for (str = buf; *fmt && ((str - buf) < (size - 1)); ++fmt) { /* STAGE: If it's not specifying an option, just pass it on through. */ if (*fmt != '%') { *str++ = *fmt; continue; } /* STAGE: Process the flags. */ flags = 0; repeat: ++fmt; /* NOTE: This also skips first '%' */ switch (*fmt) { case '-' : flags |= N_LEFT; goto repeat; case '+' : flags |= N_PLUS; goto repeat; case ' ' : flags |= N_SPACE; goto repeat; case '#' : flags |= N_SPECIAL; goto repeat; case '0' : flags |= N_ZEROPAD; goto repeat; } /* STAGE: Get field width. */ field_width = -1; if (check_digit (*fmt)) { field_width = skip_atoi (&fmt); } else if (*fmt == '*') { ++fmt; /* STAGE: Specified on the next argument. */ field_width = va_arg (args, int); if (field_width < 0) { field_width = -field_width; flags |= N_LEFT; } } /* STAGE: Get the precision. */ precision = -1; if (*fmt == '.') { ++fmt; if (check_digit (*fmt)) { precision = skip_atoi (&fmt); } else if (*fmt == '*') { ++fmt; /* STAGE: Specified on the next argument */ precision = va_arg (args, int); } /* STAGE: Paranoia on the precision value. */ if (precision < 0) precision = 0; } /* STAGE: Get the conversion qualifier. */ qualifier = -1; if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { qualifier = *fmt; ++fmt; } /* NOTE: The default base. */ base = 10; /* STAGE: Handle all the other formatting types. */ switch (*fmt) { /* STAGE: Character type. */ case 'c' : { if (!(flags & N_LEFT)) { while (--field_width > 0) *str++ = ' '; } *str++ = (unsigned char) va_arg (args, int); while (--field_width > 0) *str++ = ' '; continue; } /* STAGE: String type. */ case 's' : { s = va_arg (args, char *); if (!s) s = "<NULL>"; len = strnlen (s, precision); if (!(flags & N_LEFT)) { while (len < field_width--) *str++ = ' '; } for (i = 0; i < len; ++i) *str++ = *s++; while (len < field_width--) *str++ = ' '; continue; } case 'p' : { if (field_width == -1) { field_width = 2 * sizeof (void *); flags |= N_ZEROPAD; } str = printf_number (str, (unsigned long) va_arg (args, void *), 16, field_width, precision, flags); continue; } case 'n' : { if (qualifier == 'l') { long *ip; ip = va_arg (args, long *); *ip = (str - buf); } else { int *ip; ip = va_arg (args, int *); *ip = (str - buf); } continue; } /* NOTE: Integer number formats - set up the flags and "break". */ /* STAGE: Octal. */ case 'o' : base = 8; break; /* STAGE: Uppercase hexidecimal. */ case 'X' : flags |= N_LARGE; base = 16; break; /* STAGE: Lowercase hexidecimal. */ case 'x' : base = 16; break; /* STAGE: Signed decimal/integer. */ case 'd' : case 'i' : flags |= N_SIGN; /* STAGE: Unsigned decimal/integer. */ case 'u' : break; default : { if (*fmt != '%') *str++ = '%'; if (*fmt) *str++ = *fmt; else --fmt; continue; } } /* STAGE: Handle number formats with the various modifying qualifiers. */ if (qualifier == 'l') { num = va_arg (args, unsigned long); } else if (qualifier == 'h') { /* NOTE: The int16 should work, but the compiler promotes the datatype and complains if I don't handle it directly. */ if (flags & N_SIGN) { // num = va_arg (args, int16); num = va_arg (args, int32); } else { // num = va_arg (args, uint16); num = va_arg (args, uint32); } } else if (flags & N_SIGN) { num = va_arg (args, int); } else { num = va_arg (args, unsigned int); } /* STAGE: And after all that work, actually convert the integer into text. */ str = printf_number (str, num, base, field_width, precision, flags); } *str = '\0'; return str - buf; } /* int snprintf (char *buf, int size, const char *fmt, ...) { va_list args; int i; va_start (args, fmt); i = vsnprintf (buf,size,fmt,args); va_end (args); return i; } */
676cc0547f3c6104bdfb07faedfb92937a6d2bd7
04e5b6df2ee3bcfb7005d8ec91aab8e380333ac4
/Extensions/clib/include/python3.10/pycore_code.h
8ff1863dc0015f6c1bf0fb66d427b678a09affee
[ "MIT" ]
permissive
ColdGrub1384/Pyto
64e2a593957fd640907f0e4698d430ea7754a73e
7557485a733dd7e17ba0366b92794931bdb39975
refs/heads/main
2023-08-01T03:48:35.694832
2022-07-20T14:38:45
2022-07-20T14:38:45
148,944,721
884
157
MIT
2023-02-26T21:34:04
2018-09-15T22:29:07
C
UTF-8
C
false
false
696
h
pycore_code.h
#ifndef Py_INTERNAL_CODE_H #define Py_INTERNAL_CODE_H #ifdef __cplusplus extern "C" { #endif typedef struct { PyObject *ptr; /* Cached pointer (borrowed reference) */ uint64_t globals_ver; /* ma_version of global dict */ uint64_t builtins_ver; /* ma_version of builtin dict */ } _PyOpcache_LoadGlobal; typedef struct { PyTypeObject *type; Py_ssize_t hint; unsigned int tp_version_tag; } _PyOpCodeOpt_LoadAttr; struct _PyOpcache { union { _PyOpcache_LoadGlobal lg; _PyOpCodeOpt_LoadAttr la; } u; char optimized; }; /* Private API */ int _PyCode_InitOpcache(PyCodeObject *co); #ifdef __cplusplus } #endif #endif /* !Py_INTERNAL_CODE_H */
218f8390e495fc44a94fb933f2717525a61f3eb2
cf56b5fcf51fddb219c47f5f006d8595a4483c57
/src/components/tl/mlx5/tl_mlx5.c
bab4808ece0a70d967b9cac378cee657b36f4dff
[ "BSD-3-Clause" ]
permissive
openucx/ucc
3b39fbd849a7850c559b60eaec7882292f8a5eca
f89cd7557e6ebb19b4c6ebd529647d8b42c30657
refs/heads/master
2023-08-18T03:18:54.072899
2023-08-17T18:05:44
2023-08-17T18:05:44
282,490,868
150
57
BSD-3-Clause
2023-09-12T09:49:18
2020-07-25T17:18:51
C
UTF-8
C
false
false
4,407
c
tl_mlx5.c
/** * Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * See file LICENSE for terms. */ #include "tl_mlx5.h" ucc_status_t ucc_tl_mlx5_get_lib_attr(const ucc_base_lib_t *lib, ucc_base_lib_attr_t * base_attr); ucc_status_t ucc_tl_mlx5_get_context_attr(const ucc_base_context_t *context, ucc_base_ctx_attr_t * base_attr); ucc_status_t ucc_tl_mlx5_get_lib_properties(ucc_base_lib_properties_t *prop); static ucc_config_field_t ucc_tl_mlx5_lib_config_table[] = { {"", "", NULL, ucc_offsetof(ucc_tl_mlx5_lib_config_t, super), UCC_CONFIG_TYPE_TABLE(ucc_tl_lib_config_table)}, {"ASR_BARRIER", "0", "Boolean - use service barrier or p2p sync of ASRs", ucc_offsetof(ucc_tl_mlx5_lib_config_t, asr_barrier), UCC_CONFIG_TYPE_BOOL}, {"DM_BUF_SIZE", "8k", "Size of the pre-allocated DeviceMemory buffer", ucc_offsetof(ucc_tl_mlx5_lib_config_t, dm_buf_size), UCC_CONFIG_TYPE_MEMUNITS}, {"DM_BUF_NUM", "auto", "Number of DM buffers to alloc", ucc_offsetof(ucc_tl_mlx5_lib_config_t, dm_buf_num), UCC_CONFIG_TYPE_ULUNITS}, {"BLOCK_SIZE", "0", "Size of the blocks that are sent using blocked AlltoAll Algorithm", ucc_offsetof(ucc_tl_mlx5_lib_config_t, block_size), UCC_CONFIG_TYPE_UINT}, {"NUM_DCI_QPS", "16", "Number of parallel DCI QPs that will be used per team", ucc_offsetof(ucc_tl_mlx5_lib_config_t, num_dci_qps), UCC_CONFIG_TYPE_UINT}, {"DC_THRESHOLD", "128", "If number of nodes >= DC_THRESHOLD then DC QPs " "are used instead of RC", ucc_offsetof(ucc_tl_mlx5_lib_config_t, dc_threshold), UCC_CONFIG_TYPE_UINT}, {"DM_HOST", "n", "Use host registered memory instead of DM for " "transpose staging", ucc_offsetof(ucc_tl_mlx5_lib_config_t, dm_host), UCC_CONFIG_TYPE_BOOL}, {"QP_RNR_RETRY", "7", "IB QP rnr retry count", ucc_offsetof(ucc_tl_mlx5_lib_config_t, qp_conf.qp_rnr_retry), UCC_CONFIG_TYPE_UINT}, {"QP_RNR_TIMER", "20", "IB QP rnr timer", ucc_offsetof(ucc_tl_mlx5_lib_config_t, qp_conf.qp_rnr_timer), UCC_CONFIG_TYPE_UINT}, {"QP_RETRY_COUNT", "7", "IB QP retry count", ucc_offsetof(ucc_tl_mlx5_lib_config_t, qp_conf.qp_retry_cnt), UCC_CONFIG_TYPE_UINT}, {"QP_TIMEOUT", "18", "IB QP timeout", ucc_offsetof(ucc_tl_mlx5_lib_config_t, qp_conf.qp_timeout), UCC_CONFIG_TYPE_UINT}, {"QP_MAX_ATOMIC", "1", "max num of outstanding atomics in IB QP", ucc_offsetof(ucc_tl_mlx5_lib_config_t, qp_conf.qp_max_atomic), UCC_CONFIG_TYPE_UINT}, {NULL}}; static ucc_config_field_t ucc_tl_mlx5_context_config_table[] = { {"", "", NULL, ucc_offsetof(ucc_tl_mlx5_context_config_t, super), UCC_CONFIG_TYPE_TABLE(ucc_tl_context_config_table)}, {"NET_DEVICES", "", "Specifies which network device(s) to use", ucc_offsetof(ucc_tl_mlx5_context_config_t, devices), UCC_CONFIG_TYPE_STRING_ARRAY}, {NULL}}; UCC_CLASS_DEFINE_NEW_FUNC(ucc_tl_mlx5_lib_t, ucc_base_lib_t, const ucc_base_lib_params_t *, const ucc_base_config_t *); UCC_CLASS_DEFINE_DELETE_FUNC(ucc_tl_mlx5_lib_t, ucc_base_lib_t); UCC_CLASS_DEFINE_NEW_FUNC(ucc_tl_mlx5_context_t, ucc_base_context_t, const ucc_base_context_params_t *, const ucc_base_config_t *); UCC_CLASS_DEFINE_DELETE_FUNC(ucc_tl_mlx5_context_t, ucc_base_context_t); UCC_CLASS_DEFINE_NEW_FUNC(ucc_tl_mlx5_team_t, ucc_base_team_t, ucc_base_context_t *, const ucc_base_team_params_t *); ucc_status_t ucc_tl_mlx5_team_create_test(ucc_base_team_t *tl_team); ucc_status_t ucc_tl_mlx5_team_destroy(ucc_base_team_t *tl_team); ucc_status_t ucc_tl_mlx5_coll_init(ucc_base_coll_args_t *coll_args, ucc_base_team_t * team, ucc_coll_task_t ** task); ucc_status_t ucc_tl_mlx5_team_get_scores(ucc_base_team_t * tl_team, ucc_coll_score_t **score); UCC_TL_IFACE_DECLARE(mlx5, MLX5); ucc_status_t ucc_tl_mlx5_context_create_epilog(ucc_base_context_t *context); __attribute__((constructor)) static void tl_mlx5_iface_init(void) { ucc_tl_mlx5.super.context.create_epilog = ucc_tl_mlx5_context_create_epilog; }
30fe5cda53aaf29bef81fb2eacd1d689a413d585
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/include/sparcv9-linux-gnu/fpu_control.h
4dd8dc0c987e1581e96be24e5f4c67b342cf03c6
[ "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
2,323
h
fpu_control.h
/* FPU control word bits. SPARC version. Copyright (C) 1997-2021 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Miguel de Icaza The GNU C 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. The GNU C 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 the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ #ifndef _FPU_CONTROL_H #define _FPU_CONTROL_H 1 #include <features.h> #include <bits/wordsize.h> /* masking of interrupts */ #define _FPU_MASK_IM 0x08000000 #define _FPU_MASK_OM 0x04000000 #define _FPU_MASK_UM 0x02000000 #define _FPU_MASK_ZM 0x01000000 #define _FPU_MASK_PM 0x00800000 /* precision control */ #define _FPU_EXTENDED 0x00000000 /* RECOMMENDED */ #define _FPU_DOUBLE 0x20000000 #define _FPU_80BIT 0x30000000 #define _FPU_SINGLE 0x10000000 /* DO NOT USE */ /* rounding control / Sparc */ #define _FPU_RC_DOWN 0xc0000000 #define _FPU_RC_UP 0x80000000 #define _FPU_RC_ZERO 0x40000000 #define _FPU_RC_NEAREST 0x0 /* RECOMMENDED */ #define _FPU_RESERVED 0x30300000 /* Reserved bits in cw */ /* Now two recommended cw */ /* Linux and IEEE default: - extended precision - rounding to nearest - no exceptions */ #define _FPU_DEFAULT 0x0 #define _FPU_IEEE 0x0 /* Type of the control word. */ typedef unsigned long int fpu_control_t; #if __WORDSIZE == 64 # define _FPU_GETCW(cw) __asm__ __volatile__ ("stx %%fsr,%0" : "=m" (*&cw)) # define _FPU_SETCW(cw) __asm__ __volatile__ ("ldx %0,%%fsr" : : "m" (*&cw)) #else # define _FPU_GETCW(cw) __asm__ __volatile__ ("st %%fsr,%0" : "=m" (*&cw)) # define _FPU_SETCW(cw) __asm__ __volatile__ ("ld %0,%%fsr" : : "m" (*&cw)) #endif /* Default control word set at startup. */ extern fpu_control_t __fpu_control; #endif /* fpu_control.h */
2063b80c97bbbfd906c4e0d0a6c38f67587f8a48
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/m68k/include/asm/bvme6000hw.h
f40d2f8510ee9c536f0a49efc03c22bac1a50028
[ "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
3,490
h
bvme6000hw.h
#ifndef _M68K_BVME6000HW_H_ #define _M68K_BVME6000HW_H_ #include <asm/irq.h> /* * PIT structure */ #define BVME_PIT_BASE 0xffa00000 typedef struct { unsigned char pad_a[3], pgcr, pad_b[3], psrr, pad_c[3], paddr, pad_d[3], pbddr, pad_e[3], pcddr, pad_f[3], pivr, pad_g[3], pacr, pad_h[3], pbcr, pad_i[3], padr, pad_j[3], pbdr, pad_k[3], paar, pad_l[3], pbar, pad_m[3], pcdr, pad_n[3], psr, pad_o[3], res1, pad_p[3], res2, pad_q[3], tcr, pad_r[3], tivr, pad_s[3], res3, pad_t[3], cprh, pad_u[3], cprm, pad_v[3], cprl, pad_w[3], res4, pad_x[3], crh, pad_y[3], crm, pad_z[3], crl, pad_A[3], tsr, pad_B[3], res5; } PitRegs_t, *PitRegsPtr; #define bvmepit ((*(volatile PitRegsPtr)(BVME_PIT_BASE))) #define BVME_RTC_BASE 0xff900000 typedef struct { unsigned char pad_a[3], msr, pad_b[3], t0cr_rtmr, pad_c[3], t1cr_omr, pad_d[3], pfr_icr0, pad_e[3], irr_icr1, pad_f[3], bcd_tenms, pad_g[3], bcd_sec, pad_h[3], bcd_min, pad_i[3], bcd_hr, pad_j[3], bcd_dom, pad_k[3], bcd_mth, pad_l[3], bcd_year, pad_m[3], bcd_ujcc, pad_n[3], bcd_hjcc, pad_o[3], bcd_dow, pad_p[3], t0lsb, pad_q[3], t0msb, pad_r[3], t1lsb, pad_s[3], t1msb, pad_t[3], cmp_sec, pad_u[3], cmp_min, pad_v[3], cmp_hr, pad_w[3], cmp_dom, pad_x[3], cmp_mth, pad_y[3], cmp_dow, pad_z[3], sav_sec, pad_A[3], sav_min, pad_B[3], sav_hr, pad_C[3], sav_dom, pad_D[3], sav_mth, pad_E[3], ram, pad_F[3], test; } RtcRegs_t, *RtcPtr_t; #define BVME_I596_BASE 0xff100000 #define BVME_ETHIRQ_REG 0xff20000b #define BVME_LOCAL_IRQ_STAT 0xff20000f #define BVME_ETHERR 0x02 #define BVME_ABORT_STATUS 0x08 #define BVME_NCR53C710_BASE 0xff000000 #define BVME_SCC_A_ADDR 0xffb0000b #define BVME_SCC_B_ADDR 0xffb00003 #define BVME_SCC_RTxC 7372800 #define BVME_CONFIG_REG 0xff500003 #define config_reg_ptr (volatile unsigned char *)BVME_CONFIG_REG #define BVME_CONFIG_SW1 0x08 #define BVME_CONFIG_SW2 0x04 #define BVME_CONFIG_SW3 0x02 #define BVME_CONFIG_SW4 0x01 #define BVME_IRQ_TYPE_PRIO 0 #define BVME_IRQ_PRN (IRQ_USER+20) #define BVME_IRQ_TIMER (IRQ_USER+25) #define BVME_IRQ_I596 IRQ_AUTO_2 #define BVME_IRQ_SCSI IRQ_AUTO_3 #define BVME_IRQ_RTC IRQ_AUTO_6 #define BVME_IRQ_ABORT IRQ_AUTO_7 /* SCC interrupts */ #define BVME_IRQ_SCC_BASE IRQ_USER #define BVME_IRQ_SCCB_TX IRQ_USER #define BVME_IRQ_SCCB_STAT (IRQ_USER+2) #define BVME_IRQ_SCCB_RX (IRQ_USER+4) #define BVME_IRQ_SCCB_SPCOND (IRQ_USER+6) #define BVME_IRQ_SCCA_TX (IRQ_USER+8) #define BVME_IRQ_SCCA_STAT (IRQ_USER+10) #define BVME_IRQ_SCCA_RX (IRQ_USER+12) #define BVME_IRQ_SCCA_SPCOND (IRQ_USER+14) /* Address control registers */ #define BVME_ACR_A32VBA 0xff400003 #define BVME_ACR_A32MSK 0xff410003 #define BVME_ACR_A24VBA 0xff420003 #define BVME_ACR_A24MSK 0xff430003 #define BVME_ACR_A16VBA 0xff440003 #define BVME_ACR_A32LBA 0xff450003 #define BVME_ACR_A24LBA 0xff460003 #define BVME_ACR_ADDRCTL 0xff470003 #define bvme_acr_a32vba *(volatile unsigned char *)BVME_ACR_A32VBA #define bvme_acr_a32msk *(volatile unsigned char *)BVME_ACR_A32MSK #define bvme_acr_a24vba *(volatile unsigned char *)BVME_ACR_A24VBA #define bvme_acr_a24msk *(volatile unsigned char *)BVME_ACR_A24MSK #define bvme_acr_a16vba *(volatile unsigned char *)BVME_ACR_A16VBA #define bvme_acr_a32lba *(volatile unsigned char *)BVME_ACR_A32LBA #define bvme_acr_a24lba *(volatile unsigned char *)BVME_ACR_A24LBA #define bvme_acr_addrctl *(volatile unsigned char *)BVME_ACR_ADDRCTL #endif
2a1e92ac61f7ae872b5f867a2bd0b86959ab8056
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h
bbad164f6fc98b1597517215c515230c61952ffa
[ "BSD-2-Clause", "MIT", "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" ]
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
3,904
h
VirtioPciDevice.h
/** @file Internal definitions for the VirtIo PCI Device driver Copyright (C) 2013, ARM Ltd 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. **/ #ifndef _VIRTIO_PCI_DEVICE_DXE_H_ #define _VIRTIO_PCI_DEVICE_DXE_H_ #include <Protocol/ComponentName.h> #include <Protocol/DriverBinding.h> #include <Protocol/PciIo.h> #include <Protocol/VirtioDevice.h> #include <IndustryStandard/Virtio.h> #define VIRTIO_PCI_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'P', 'C', 'I') typedef struct { UINT32 Signature; VIRTIO_DEVICE_PROTOCOL VirtioDevice; EFI_PCI_IO_PROTOCOL *PciIo; UINT64 OriginalPciAttributes; UINT32 DeviceSpecificConfigurationOffset; } VIRTIO_PCI_DEVICE; #define VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE(Device) \ CR (Device, VIRTIO_PCI_DEVICE, VirtioDevice, VIRTIO_PCI_DEVICE_SIGNATURE) EFI_STATUS EFIAPI VirtioPciIoRead ( IN VIRTIO_PCI_DEVICE *Dev, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINTN BufferSize, OUT VOID *Buffer ); EFI_STATUS EFIAPI VirtioPciIoWrite ( IN VIRTIO_PCI_DEVICE *Dev, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINT64 Value ); /******************************************** * PCI Functions for VIRTIO_DEVICE_PROTOCOL *******************************************/ EFI_STATUS EFIAPI VirtioPciDeviceRead ( IN VIRTIO_DEVICE_PROTOCOL *This, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINTN BufferSize, OUT VOID *Buffer ); EFI_STATUS EFIAPI VirtioPciDeviceWrite ( IN VIRTIO_DEVICE_PROTOCOL *This, IN UINTN FieldOffset, IN UINTN FieldSize, IN UINT64 Value ); EFI_STATUS EFIAPI VirtioPciGetDeviceFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, OUT UINT32 *DeviceFeatures ); EFI_STATUS EFIAPI VirtioPciGetQueueAddress ( IN VIRTIO_DEVICE_PROTOCOL *This, OUT UINT32 *QueueAddress ); EFI_STATUS EFIAPI VirtioPciGetQueueSize ( IN VIRTIO_DEVICE_PROTOCOL *This, OUT UINT16 *QueueNumMax ); EFI_STATUS EFIAPI VirtioPciSetQueueAlignment ( VIRTIO_DEVICE_PROTOCOL *This, UINT32 Alignment ); EFI_STATUS EFIAPI VirtioPciSetPageSize ( VIRTIO_DEVICE_PROTOCOL *This, UINT32 PageSize ); EFI_STATUS EFIAPI VirtioPciGetDeviceStatus ( IN VIRTIO_DEVICE_PROTOCOL *This, OUT UINT8 *DeviceStatus ); EFI_STATUS EFIAPI VirtioPciSetGuestFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, IN UINT32 Features ); EFI_STATUS EFIAPI VirtioPciSetQueueAddress ( VIRTIO_DEVICE_PROTOCOL *This, UINT32 Address ); EFI_STATUS EFIAPI VirtioPciSetQueueSel ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Sel ); EFI_STATUS EFIAPI VirtioPciSetQueueNotify ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Index ); EFI_STATUS EFIAPI VirtioPciSetQueueSize ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Size ); EFI_STATUS EFIAPI VirtioPciSetDeviceStatus ( VIRTIO_DEVICE_PROTOCOL *This, UINT8 DeviceStatus ); #endif // _VIRTIO_PCI_DEVICE_DXE_H_
d99c7b0b5d19dff2770eb36fcf8488e51c6b7935
78dc9f153549b281be709227bc9897931b06260d
/generation/WinSDK/RecompiledIdlHeaders/um/threadpoolapiset.h
c0e871bb5e177960fd95654b068886bbe9e52d38
[ "MIT" ]
permissive
microsoft/win32metadata
dff35b4fe904d556162cee5133294c4498f1a79a
5bf233f04d45f7a697e112e9639722551103eb07
refs/heads/main
2023-09-01T19:51:22.972899
2023-08-30T21:39:44
2023-08-30T21:39:44
270,838,404
1,240
107
NOASSERTION
2023-09-14T18:49:44
2020-06-08T21:52:10
C++
UTF-8
C
false
false
6,774
h
threadpoolapiset.h
/******************************************************************************** * * * threadpoolapi.h -- ApiSet Contract for api-ms-win-core-threadpool-l1 * * * * Copyright (c) Microsoft Corporation. All rights reserved. * * * ********************************************************************************/ #ifdef _MSC_VER #pragma once #endif // _MSC_VER #ifndef _THREADPOOLAPISET_H_ #define _THREADPOOLAPISET_H_ #include <apiset.h> #include <apisetcconv.h> #include <minwindef.h> #include <minwinbase.h> #ifdef __cplusplus extern "C" { #endif // // Thread pool API's // #pragma region Application Family or OneCore Family or Games Family #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) typedef VOID (WINAPI *PTP_WIN32_IO_CALLBACK)( _Inout_ PTP_CALLBACK_INSTANCE Instance, _Inout_opt_ PVOID Context, _Inout_opt_ PVOID Overlapped, _In_ ULONG IoResult, _In_ ULONG_PTR NumberOfBytesTransferred, _Inout_ PTP_IO Io ); #if (_WIN32_WINNT >= 0x0600) WINBASEAPI _Must_inspect_result_ PTP_POOL WINAPI CreateThreadpool( _Reserved_ PVOID reserved ); WINBASEAPI VOID WINAPI SetThreadpoolThreadMaximum( _Inout_ PTP_POOL ptpp, _In_ DWORD cthrdMost ); WINBASEAPI BOOL WINAPI SetThreadpoolThreadMinimum( _Inout_ PTP_POOL ptpp, _In_ DWORD cthrdMic ); WINBASEAPI BOOL WINAPI SetThreadpoolStackInformation( _Inout_ PTP_POOL ptpp, _In_ PTP_POOL_STACK_INFORMATION ptpsi ); WINBASEAPI BOOL WINAPI QueryThreadpoolStackInformation( _In_ PTP_POOL ptpp, _Out_ PTP_POOL_STACK_INFORMATION ptpsi ); WINBASEAPI VOID WINAPI CloseThreadpool( _Inout_ PTP_POOL ptpp ); WINBASEAPI _Must_inspect_result_ PTP_CLEANUP_GROUP WINAPI CreateThreadpoolCleanupGroup( VOID ); WINBASEAPI VOID WINAPI CloseThreadpoolCleanupGroupMembers( _Inout_ PTP_CLEANUP_GROUP ptpcg, _In_ BOOL fCancelPendingCallbacks, _Inout_opt_ PVOID pvCleanupContext ); WINBASEAPI VOID WINAPI CloseThreadpoolCleanupGroup( _Inout_ PTP_CLEANUP_GROUP ptpcg ); WINBASEAPI VOID WINAPI SetEventWhenCallbackReturns( _Inout_ PTP_CALLBACK_INSTANCE pci, _In_ HANDLE evt ); WINBASEAPI VOID WINAPI ReleaseSemaphoreWhenCallbackReturns( _Inout_ PTP_CALLBACK_INSTANCE pci, _In_ HANDLE sem, _In_ DWORD crel ); WINBASEAPI VOID WINAPI ReleaseMutexWhenCallbackReturns( _Inout_ PTP_CALLBACK_INSTANCE pci, _In_ HANDLE mut ); WINBASEAPI VOID WINAPI LeaveCriticalSectionWhenCallbackReturns( _Inout_ PTP_CALLBACK_INSTANCE pci, _Inout_ PCRITICAL_SECTION pcs ); WINBASEAPI VOID WINAPI FreeLibraryWhenCallbackReturns( _Inout_ PTP_CALLBACK_INSTANCE pci, _In_ HMODULE mod ); WINBASEAPI BOOL WINAPI CallbackMayRunLong( _Inout_ PTP_CALLBACK_INSTANCE pci ); WINBASEAPI VOID WINAPI DisassociateCurrentThreadFromCallback( _Inout_ PTP_CALLBACK_INSTANCE pci ); WINBASEAPI _Must_inspect_result_ BOOL WINAPI TrySubmitThreadpoolCallback( _In_ PTP_SIMPLE_CALLBACK pfns, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe ); WINBASEAPI _Must_inspect_result_ PTP_WORK WINAPI CreateThreadpoolWork( _In_ PTP_WORK_CALLBACK pfnwk, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe ); WINBASEAPI VOID WINAPI SubmitThreadpoolWork( _Inout_ PTP_WORK pwk ); WINBASEAPI VOID WINAPI WaitForThreadpoolWorkCallbacks( _Inout_ PTP_WORK pwk, _In_ BOOL fCancelPendingCallbacks ); WINBASEAPI VOID WINAPI CloseThreadpoolWork( _Inout_ PTP_WORK pwk ); WINBASEAPI _Must_inspect_result_ PTP_TIMER WINAPI CreateThreadpoolTimer( _In_ PTP_TIMER_CALLBACK pfnti, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe ); WINBASEAPI VOID WINAPI SetThreadpoolTimer( _Inout_ PTP_TIMER pti, _In_opt_ PFILETIME pftDueTime, _In_ DWORD msPeriod, _In_opt_ DWORD msWindowLength ); WINBASEAPI BOOL WINAPI IsThreadpoolTimerSet( _Inout_ PTP_TIMER pti ); WINBASEAPI VOID WINAPI WaitForThreadpoolTimerCallbacks( _Inout_ PTP_TIMER pti, _In_ BOOL fCancelPendingCallbacks ); WINBASEAPI VOID WINAPI CloseThreadpoolTimer( _Inout_ PTP_TIMER pti ); WINBASEAPI _Must_inspect_result_ PTP_WAIT WINAPI CreateThreadpoolWait( _In_ PTP_WAIT_CALLBACK pfnwa, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe ); WINBASEAPI VOID WINAPI SetThreadpoolWait( _Inout_ PTP_WAIT pwa, _In_opt_ HANDLE h, _In_opt_ PFILETIME pftTimeout ); WINBASEAPI VOID WINAPI WaitForThreadpoolWaitCallbacks( _Inout_ PTP_WAIT pwa, _In_ BOOL fCancelPendingCallbacks ); WINBASEAPI VOID WINAPI CloseThreadpoolWait( _Inout_ PTP_WAIT pwa ); WINBASEAPI _Must_inspect_result_ PTP_IO WINAPI CreateThreadpoolIo( _In_ HANDLE fl, _In_ PTP_WIN32_IO_CALLBACK pfnio, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe ); WINBASEAPI VOID WINAPI StartThreadpoolIo( _Inout_ PTP_IO pio ); WINBASEAPI VOID WINAPI CancelThreadpoolIo( _Inout_ PTP_IO pio ); WINBASEAPI VOID WINAPI WaitForThreadpoolIoCallbacks( _Inout_ PTP_IO pio, _In_ BOOL fCancelPendingCallbacks ); WINBASEAPI VOID WINAPI CloseThreadpoolIo( _Inout_ PTP_IO pio ); #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) */ #pragma endregion #pragma region Application Family or OneCore Family #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) WINBASEAPI BOOL WINAPI SetThreadpoolTimerEx( _Inout_ PTP_TIMER pti, _In_opt_ PFILETIME pftDueTime, _In_ DWORD msPeriod, _In_opt_ DWORD msWindowLength ); WINBASEAPI BOOL WINAPI SetThreadpoolWaitEx( _Inout_ PTP_WAIT pwa, _In_opt_ HANDLE h, _In_opt_ PFILETIME pftTimeout, _Reserved_ PVOID Reserved ); #endif // _WIN32_WINNT >= 0x0600 #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */ #pragma endregion #pragma region Desktop Family or OneCore Family or Games Family #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) #if (_WIN32_WINNT >= 0x0600) #endif // _WIN32_WINNT >= 0x0600 #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */ #pragma endregion #ifdef __cplusplus } #endif #endif // _THREADPOOLAPISET_H_
1ac49c74eb0e5636332888f16b0f754c4a9ac09c
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/graphics/blender/patches/patch-extern_glog_src_config.h
dcaceeed0b72e4fb5a99c140dba04da1e5d4c14d
[]
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
430
h
patch-extern_glog_src_config.h
$NetBSD: patch-extern_glog_src_config.h,v 1.2 2019/09/18 23:40:17 nia Exp $ Support NetBSD. --- extern/glog/src/config.h.orig 2016-03-23 08:49:49.000000000 +0000 +++ extern/glog/src/config.h @@ -10,6 +10,8 @@ #include "windows/config.h" #elif defined(__linux__) #include "config_linux.h" +#elif defined(__NetBSD__) + #include "config_netbsd.h" #elif defined(_MSC_VER) #include "windows/config.h" #elif defined(__GNU__)
77185f9812f070ff3c3e8ee86c79dece4a9ce880
50dd46b8ece33f3cdd174284b15d1d51f89669d4
/third_party/tomcrypt/src/pk/asn1/der/sequence/der_sequence_shrink.c
660fcaf0c329d5141d47c0a1b14ab302acf16ada
[ "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,294
c
der_sequence_shrink.c
/* LibTomCrypt, modular cryptographic library -- Tom St Denis * * LibTomCrypt is a library that provides various cryptographic * algorithms in a highly modular and flexible manner. * * The library is free for all purposes without any express * guarantee it works. */ #include "tomcrypt_private.h" /** @file der_sequence_shrink.c Free memory allocated for CONSTRUCTED, SET or SEQUENCE elements by der_decode_sequence_flexi(), Steffen Jaeckel */ #ifdef LTC_DER /** Free memory allocated for CONSTRUCTED, SET or SEQUENCE elements by der_decode_sequence_flexi() @param in The list to shrink */ void der_sequence_shrink(ltc_asn1_list *in) { if (!in) return; /* now walk the list and free stuff */ while (in != NULL) { /* is there a child? */ if (in->child) { der_sequence_shrink(in->child); } switch (in->type) { case LTC_ASN1_CUSTOM_TYPE: case LTC_ASN1_SET: case LTC_ASN1_SEQUENCE : if (in->data != NULL) { XFREE(in->data); in->data = NULL; } break; default: break; } /* move to next and free current */ in = in->next; } } #endif /* ref: HEAD -> develop */ /* git commit: 9c0d7085234bd6baba2ab8fd9eee62254599341c */ /* commit time: 2018-10-15 10:51:17 +0200 */
1aa843ef388fc0b53d5b4c2980b18f8b72d06ea0
d5fa3a8417ef72029ebe1a714204b4d80afa07b0
/apue/apue.3e/figlinks/fig17.30
6174b892aa2394065ba5758fbf12da45ddd24da2
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
wuzhouhui/misc
e9eeaa16ce21341db0e075a369edc45af4a89aae
465c679b10b9766985a510df26d3e6a549cfa421
refs/heads/master
2023-01-07T00:45:02.721093
2022-12-30T07:27:37
2022-12-30T07:27:37
48,721,582
1,287
494
null
null
null
null
UTF-8
C
false
false
25
30
fig17.30
../ipc2/opend/loop.poll.c
ddc60b636e74c51d2cddb766c6e2f9202115b33b
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/arch/amiga/include/pmap.h
a160d400b39c50f0ef5e04d2f3b030d21961ed06
[]
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
96
h
pmap.h
/* $NetBSD: pmap.h,v 1.45 2007/10/17 19:53:26 garbled Exp $ */ #include <m68k/pmap_motorola.h>
ad4b9b7d2060e5bd217ec164f6b1f483e11d9c4d
975b756612322df89d14559f21ca740d6f448bd8
/linux/gif_1_bus_2_oleds/main.c
8dfe040f8e7885a2503442b1370626c93c4c8bdc
[ "Apache-2.0" ]
permissive
bitbank2/OneBitDisplay
0127f09cb88332de321ab7b6df027b7c3eb2dd8d
fcc9ae1d9226abd670f6cf05ee041ae86bd0ed15
refs/heads/master
2023-08-18T03:37:22.011102
2023-08-11T11:32:48
2023-08-11T11:32:48
249,551,623
157
17
Apache-2.0
2023-01-09T00:04:17
2020-03-23T21:48:48
C
UTF-8
C
false
false
3,674
c
main.c
// // main.c // OneBitDisplay library test program // #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <math.h> #include "../../../AnimatedGIF/src/AnimatedGIF.h" #include "../../../AnimatedGIF/src/gif.inl" #include "../../src/OneBitDisplay.cpp" #include "running_256_64.h" #define OLED_TYPE OLED_132x64 #define OLED_ADDR 0x3c #define FLIP180 0 #define INVERT 0 #define HW_I2C 1 // On Linux this is the I2C bus number (SDA_PIN) for HW I2C #define SDA_PIN 1 // On Linux this is the I2C device address #define SCL_PIN 0x3c #define RESET_PIN -1 // This is not controlled on Linux through the API // On the Raspberry PI, see /boot/config.txt #define SPEED 0 #define DISPLAY_WIDTH 256 #define DISPLAY_HEIGHT 64 static uint8_t ucOLED_0[1024], ucOLED_1[1024]; static OBDISP obd[2]; // // This doesn't have to be super efficient // void DrawPixel(int x, int y, uint8_t ucColor) { uint8_t *d, ucMask; ucMask = 1 << (y & 7); if (x >= 128) // right display d = &ucOLED_1[(x-128)+((y>>3) << 7)]; else d = &ucOLED_0[x + ((y>>3) << 7)]; if (ucColor) *d |= ucMask; else *d &= ~ucMask; } // Draw a line of image into our 1-bpp virtual display buffers void GIFDraw(GIFDRAW *pDraw) { uint8_t *s; int x, y, iWidth; static uint8_t ucPalette[256]; // thresholded palette if (pDraw->y == 0) // first line, convert palette to 0/1 { for (x = 0; x < 256; x++) { uint16_t usColor = pDraw->pPalette[x]; int gray = (usColor & 0xf800) >> 8; // red gray += ((usColor & 0x7e0) >> 2); // plus green*2 gray += ((usColor & 0x1f) << 3); // plus blue ucPalette[x] = (gray >> 9); // 0->511 = 0, 512->1023 = 1 } } y = pDraw->iY + pDraw->y; // current line iWidth = pDraw->iWidth; if (iWidth > DISPLAY_WIDTH) iWidth = DISPLAY_WIDTH; s = pDraw->pPixels; if (pDraw->ucDisposalMethod == 2) // restore to background color { for (x=0; x<iWidth; x++) { if (s[x] == pDraw->ucTransparent) s[x] = pDraw->ucBackground; } pDraw->ucHasTransparency = 0; } // Apply the new pixels to the main image if (pDraw->ucHasTransparency) // if transparency used { uint8_t c, ucTransparent = pDraw->ucTransparent; int x; for(x=0; x < iWidth; x++) { c = *s++; if (c != ucTransparent) DrawPixel(pDraw->iX + x, y, ucPalette[c]); } } else { s = pDraw->pPixels; // Translate the 8-bit pixels through the RGB565 palette (already byte reversed) for (x=0; x<pDraw->iWidth; x++) DrawPixel(pDraw->iX + x, y, ucPalette[*s++]); } if (pDraw->y == pDraw->iHeight-1) { // last line, render it to the display(s) obdDumpBuffer(&obd[0], NULL); obdDumpBuffer(&obd[1], NULL); } } /* GIFDraw() */ int main(int argc, const char * argv[]) { GIFIMAGE gif; int rc; int iDelay; obdI2CInit(&obd[0], OLED_TYPE, -1, FLIP180, INVERT, HW_I2C, 1, 0x3C, RESET_PIN, SPEED); obdSetBackBuffer(&obd[0], ucOLED_0); obdFill(&obd[0], 0, 1); obdI2CInit(&obd[1], OLED_TYPE, -1, FLIP180, INVERT, HW_I2C, 1, 0x3D, RESET_PIN, SPEED); obdSetBackBuffer(&obd[1], ucOLED_1); obdFill(&obd[1], 0, 1); GIF_begin(&gif, GIF_PALETTE_RGB565_LE); while (1) { rc = GIF_openRAM(&gif, (uint8_t *)running_256_64, sizeof(running_256_64), GIFDraw); if (rc) { while (GIF_playFrame(&gif, &iDelay, NULL)) { // usleep(iDelay * 1000); } } } // while (1) return 0; } /* main() */
1c4334e59ebdd1607267090c150202fe28234059
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/blackfin/mach-bf538/boards/ezkit.c
755f0dc120100a7f359d1137059c3f094cb10d75
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "BSD-3-Clause-Clear", "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
23,529
c
ezkit.c
/* * Copyright 2004-2009 Analog Devices Inc. * 2005 National ICT Australia (NICTA) * Aidan Williams <aidan@nicta.com.au> * * Licensed under the GPL-2 */ #include <linux/device.h> #include <linux/platform_device.h> #include <linux/mtd/mtd.h> #include <linux/mtd/physmap.h> #include <linux/mtd/partitions.h> #include <linux/spi/spi.h> #include <linux/spi/flash.h> #include <linux/irq.h> #include <linux/interrupt.h> #include <asm/bfin5xx_spi.h> #include <asm/dma.h> #include <asm/gpio.h> #include <asm/nand.h> #include <asm/portmux.h> #include <asm/dpmc.h> #include <linux/input.h> /* * Name the Board for the /proc/cpuinfo */ const char bfin_board_name[] = "ADI BF538-EZKIT"; /* * Driver needs to know address, irq and flag pin. */ #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) static struct platform_device rtc_device = { .name = "rtc-bfin", .id = -1, }; #endif /* CONFIG_RTC_DRV_BFIN */ #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) #ifdef CONFIG_SERIAL_BFIN_UART0 static struct resource bfin_uart0_resources[] = { { .start = UART0_THR, .end = UART0_GCTL+2, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART0_TX, .end = IRQ_UART0_TX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART0_RX, .end = IRQ_UART0_RX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART0_ERROR, .end = IRQ_UART0_ERROR, .flags = IORESOURCE_IRQ, }, { .start = CH_UART0_TX, .end = CH_UART0_TX, .flags = IORESOURCE_DMA, }, { .start = CH_UART0_RX, .end = CH_UART0_RX, .flags = IORESOURCE_DMA, }, #ifdef CONFIG_BFIN_UART0_CTSRTS { /* CTS pin */ .start = GPIO_PG7, .end = GPIO_PG7, .flags = IORESOURCE_IO, }, { /* RTS pin */ .start = GPIO_PG6, .end = GPIO_PG6, .flags = IORESOURCE_IO, }, #endif }; static unsigned short bfin_uart0_peripherals[] = { P_UART0_TX, P_UART0_RX, 0 }; static struct platform_device bfin_uart0_device = { .name = "bfin-uart", .id = 0, .num_resources = ARRAY_SIZE(bfin_uart0_resources), .resource = bfin_uart0_resources, .dev = { .platform_data = &bfin_uart0_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_UART0 */ #ifdef CONFIG_SERIAL_BFIN_UART1 static struct resource bfin_uart1_resources[] = { { .start = UART1_THR, .end = UART1_GCTL+2, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART1_TX, .end = IRQ_UART1_TX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART1_RX, .end = IRQ_UART1_RX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART1_ERROR, .end = IRQ_UART1_ERROR, .flags = IORESOURCE_IRQ, }, { .start = CH_UART1_TX, .end = CH_UART1_TX, .flags = IORESOURCE_DMA, }, { .start = CH_UART1_RX, .end = CH_UART1_RX, .flags = IORESOURCE_DMA, }, }; static unsigned short bfin_uart1_peripherals[] = { P_UART1_TX, P_UART1_RX, 0 }; static struct platform_device bfin_uart1_device = { .name = "bfin-uart", .id = 1, .num_resources = ARRAY_SIZE(bfin_uart1_resources), .resource = bfin_uart1_resources, .dev = { .platform_data = &bfin_uart1_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_UART1 */ #ifdef CONFIG_SERIAL_BFIN_UART2 static struct resource bfin_uart2_resources[] = { { .start = UART2_THR, .end = UART2_GCTL+2, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART2_TX, .end = IRQ_UART2_TX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART2_RX, .end = IRQ_UART2_RX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_UART2_ERROR, .end = IRQ_UART2_ERROR, .flags = IORESOURCE_IRQ, }, { .start = CH_UART2_TX, .end = CH_UART2_TX, .flags = IORESOURCE_DMA, }, { .start = CH_UART2_RX, .end = CH_UART2_RX, .flags = IORESOURCE_DMA, }, }; static unsigned short bfin_uart2_peripherals[] = { P_UART2_TX, P_UART2_RX, 0 }; static struct platform_device bfin_uart2_device = { .name = "bfin-uart", .id = 2, .num_resources = ARRAY_SIZE(bfin_uart2_resources), .resource = bfin_uart2_resources, .dev = { .platform_data = &bfin_uart2_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_UART2 */ #endif /* CONFIG_SERIAL_BFIN */ #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE) #ifdef CONFIG_BFIN_SIR0 static struct resource bfin_sir0_resources[] = { { .start = 0xFFC00400, .end = 0xFFC004FF, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART0_RX, .end = IRQ_UART0_RX+1, .flags = IORESOURCE_IRQ, }, { .start = CH_UART0_RX, .end = CH_UART0_RX+1, .flags = IORESOURCE_DMA, }, }; static struct platform_device bfin_sir0_device = { .name = "bfin_sir", .id = 0, .num_resources = ARRAY_SIZE(bfin_sir0_resources), .resource = bfin_sir0_resources, }; #endif /* CONFIG_BFIN_SIR0 */ #ifdef CONFIG_BFIN_SIR1 static struct resource bfin_sir1_resources[] = { { .start = 0xFFC02000, .end = 0xFFC020FF, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART1_RX, .end = IRQ_UART1_RX+1, .flags = IORESOURCE_IRQ, }, { .start = CH_UART1_RX, .end = CH_UART1_RX+1, .flags = IORESOURCE_DMA, }, }; static struct platform_device bfin_sir1_device = { .name = "bfin_sir", .id = 1, .num_resources = ARRAY_SIZE(bfin_sir1_resources), .resource = bfin_sir1_resources, }; #endif /* CONFIG_BFIN_SIR1 */ #ifdef CONFIG_BFIN_SIR2 static struct resource bfin_sir2_resources[] = { { .start = 0xFFC02100, .end = 0xFFC021FF, .flags = IORESOURCE_MEM, }, { .start = IRQ_UART2_RX, .end = IRQ_UART2_RX+1, .flags = IORESOURCE_IRQ, }, { .start = CH_UART2_RX, .end = CH_UART2_RX+1, .flags = IORESOURCE_DMA, }, }; static struct platform_device bfin_sir2_device = { .name = "bfin_sir", .id = 2, .num_resources = ARRAY_SIZE(bfin_sir2_resources), .resource = bfin_sir2_resources, }; #endif /* CONFIG_BFIN_SIR2 */ #endif /* CONFIG_BFIN_SIR */ #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART static struct resource bfin_sport0_uart_resources[] = { { .start = SPORT0_TCR1, .end = SPORT0_MRCS3+4, .flags = IORESOURCE_MEM, }, { .start = IRQ_SPORT0_RX, .end = IRQ_SPORT0_RX+1, .flags = IORESOURCE_IRQ, }, { .start = IRQ_SPORT0_ERROR, .end = IRQ_SPORT0_ERROR, .flags = IORESOURCE_IRQ, }, }; static unsigned short bfin_sport0_peripherals[] = { P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0 }; static struct platform_device bfin_sport0_uart_device = { .name = "bfin-sport-uart", .id = 0, .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources), .resource = bfin_sport0_uart_resources, .dev = { .platform_data = &bfin_sport0_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_SPORT0_UART */ #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART static struct resource bfin_sport1_uart_resources[] = { { .start = SPORT1_TCR1, .end = SPORT1_MRCS3+4, .flags = IORESOURCE_MEM, }, { .start = IRQ_SPORT1_RX, .end = IRQ_SPORT1_RX+1, .flags = IORESOURCE_IRQ, }, { .start = IRQ_SPORT1_ERROR, .end = IRQ_SPORT1_ERROR, .flags = IORESOURCE_IRQ, }, }; static unsigned short bfin_sport1_peripherals[] = { P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS, P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0 }; static struct platform_device bfin_sport1_uart_device = { .name = "bfin-sport-uart", .id = 1, .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources), .resource = bfin_sport1_uart_resources, .dev = { .platform_data = &bfin_sport1_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_SPORT1_UART */ #ifdef CONFIG_SERIAL_BFIN_SPORT2_UART static struct resource bfin_sport2_uart_resources[] = { { .start = SPORT2_TCR1, .end = SPORT2_MRCS3+4, .flags = IORESOURCE_MEM, }, { .start = IRQ_SPORT2_RX, .end = IRQ_SPORT2_RX+1, .flags = IORESOURCE_IRQ, }, { .start = IRQ_SPORT2_ERROR, .end = IRQ_SPORT2_ERROR, .flags = IORESOURCE_IRQ, }, }; static unsigned short bfin_sport2_peripherals[] = { P_SPORT2_TFS, P_SPORT2_DTPRI, P_SPORT2_TSCLK, P_SPORT2_RFS, P_SPORT2_DRPRI, P_SPORT2_RSCLK, P_SPORT2_DRSEC, P_SPORT2_DTSEC, 0 }; static struct platform_device bfin_sport2_uart_device = { .name = "bfin-sport-uart", .id = 2, .num_resources = ARRAY_SIZE(bfin_sport2_uart_resources), .resource = bfin_sport2_uart_resources, .dev = { .platform_data = &bfin_sport2_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_SPORT2_UART */ #ifdef CONFIG_SERIAL_BFIN_SPORT3_UART static struct resource bfin_sport3_uart_resources[] = { { .start = SPORT3_TCR1, .end = SPORT3_MRCS3+4, .flags = IORESOURCE_MEM, }, { .start = IRQ_SPORT3_RX, .end = IRQ_SPORT3_RX+1, .flags = IORESOURCE_IRQ, }, { .start = IRQ_SPORT3_ERROR, .end = IRQ_SPORT3_ERROR, .flags = IORESOURCE_IRQ, }, }; static unsigned short bfin_sport3_peripherals[] = { P_SPORT3_TFS, P_SPORT3_DTPRI, P_SPORT3_TSCLK, P_SPORT3_RFS, P_SPORT3_DRPRI, P_SPORT3_RSCLK, P_SPORT3_DRSEC, P_SPORT3_DTSEC, 0 }; static struct platform_device bfin_sport3_uart_device = { .name = "bfin-sport-uart", .id = 3, .num_resources = ARRAY_SIZE(bfin_sport3_uart_resources), .resource = bfin_sport3_uart_resources, .dev = { .platform_data = &bfin_sport3_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_SERIAL_BFIN_SPORT3_UART */ #endif /* CONFIG_SERIAL_BFIN_SPORT */ #if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE) static unsigned short bfin_can_peripherals[] = { P_CAN0_RX, P_CAN0_TX, 0 }; static struct resource bfin_can_resources[] = { { .start = 0xFFC02A00, .end = 0xFFC02FFF, .flags = IORESOURCE_MEM, }, { .start = IRQ_CAN_RX, .end = IRQ_CAN_RX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_CAN_TX, .end = IRQ_CAN_TX, .flags = IORESOURCE_IRQ, }, { .start = IRQ_CAN_ERROR, .end = IRQ_CAN_ERROR, .flags = IORESOURCE_IRQ, }, }; static struct platform_device bfin_can_device = { .name = "bfin_can", .num_resources = ARRAY_SIZE(bfin_can_resources), .resource = bfin_can_resources, .dev = { .platform_data = &bfin_can_peripherals, /* Passed to driver */ }, }; #endif /* CONFIG_CAN_BFIN */ /* * USB-LAN EzExtender board * Driver needs to know address, irq and flag pin. */ #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE) #include <linux/smc91x.h> static struct smc91x_platdata smc91x_info = { .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT, .leda = RPC_LED_100_10, .ledb = RPC_LED_TX_RX, }; static struct resource smc91x_resources[] = { { .name = "smc91x-regs", .start = 0x20310300, .end = 0x20310300 + 16, .flags = IORESOURCE_MEM, }, { .start = IRQ_PF0, .end = IRQ_PF0, .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, }, }; static struct platform_device smc91x_device = { .name = "smc91x", .id = 0, .num_resources = ARRAY_SIZE(smc91x_resources), .resource = smc91x_resources, .dev = { .platform_data = &smc91x_info, }, }; #endif /* CONFIG_SMC91X */ #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE) /* all SPI peripherals info goes here */ #if defined(CONFIG_MTD_M25P80) \ || defined(CONFIG_MTD_M25P80_MODULE) /* SPI flash chip (m25p16) */ static struct mtd_partition bfin_spi_flash_partitions[] = { { .name = "bootloader(spi)", .size = 0x00040000, .offset = 0, .mask_flags = MTD_CAP_ROM }, { .name = "linux kernel(spi)", .size = 0x1c0000, .offset = 0x40000 } }; static struct flash_platform_data bfin_spi_flash_data = { .name = "m25p80", .parts = bfin_spi_flash_partitions, .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions), .type = "m25p16", }; static struct bfin5xx_spi_chip spi_flash_chip_info = { .enable_dma = 0, /* use dma transfer with this chip*/ }; #endif /* CONFIG_MTD_M25P80 */ #endif /* CONFIG_SPI_BFIN5XX */ #if defined(CONFIG_TOUCHSCREEN_AD7879) || defined(CONFIG_TOUCHSCREEN_AD7879_MODULE) #include <linux/spi/ad7879.h> static const struct ad7879_platform_data bfin_ad7879_ts_info = { .model = 7879, /* Model = AD7879 */ .x_plate_ohms = 620, /* 620 Ohm from the touch datasheet */ .pressure_max = 10000, .pressure_min = 0, .first_conversion_delay = 3, /* wait 512us before do a first conversion */ .acquisition_time = 1, /* 4us acquisition time per sample */ .median = 2, /* do 8 measurements */ .averaging = 1, /* take the average of 4 middle samples */ .pen_down_acc_interval = 255, /* 9.4 ms */ .gpio_export = 1, /* Export GPIO to gpiolib */ .gpio_base = -1, /* Dynamic allocation */ }; #endif /* CONFIG_TOUCHSCREEN_AD7879 */ #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE) #include <asm/bfin-lq035q1.h> static struct bfin_lq035q1fb_disp_info bfin_lq035q1_data = { .mode = LQ035_NORM | LQ035_RGB | LQ035_RL | LQ035_TB, .ppi_mode = USE_RGB565_16_BIT_PPI, .use_bl = 0, /* let something else control the LCD Blacklight */ .gpio_bl = GPIO_PF7, }; static struct resource bfin_lq035q1_resources[] = { { .start = IRQ_PPI_ERROR, .end = IRQ_PPI_ERROR, .flags = IORESOURCE_IRQ, }, }; static struct platform_device bfin_lq035q1_device = { .name = "bfin-lq035q1", .id = -1, .num_resources = ARRAY_SIZE(bfin_lq035q1_resources), .resource = bfin_lq035q1_resources, .dev = { .platform_data = &bfin_lq035q1_data, }, }; #endif /* CONFIG_FB_BFIN_LQ035Q1 */ static struct spi_board_info bf538_spi_board_info[] __initdata = { #if defined(CONFIG_MTD_M25P80) \ || defined(CONFIG_MTD_M25P80_MODULE) { /* the modalias must be the same as spi device driver name */ .modalias = "m25p80", /* Name of spi_driver for this device */ .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, /* Framework bus number */ .chip_select = 1, /* SPI_SSEL1*/ .platform_data = &bfin_spi_flash_data, .controller_data = &spi_flash_chip_info, .mode = SPI_MODE_3, }, #endif /* CONFIG_MTD_M25P80 */ #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) { .modalias = "ad7879", .platform_data = &bfin_ad7879_ts_info, .irq = IRQ_PF3, .max_speed_hz = 5000000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 1, .mode = SPI_CPHA | SPI_CPOL, }, #endif /* CONFIG_TOUCHSCREEN_AD7879_SPI */ #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE) { .modalias = "bfin-lq035q1-spi", .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 2, .mode = SPI_CPHA | SPI_CPOL, }, #endif /* CONFIG_FB_BFIN_LQ035Q1 */ #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE) { .modalias = "spidev", .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 1, }, #endif /* CONFIG_SPI_SPIDEV */ }; /* SPI (0) */ static struct resource bfin_spi0_resource[] = { [0] = { .start = SPI0_REGBASE, .end = SPI0_REGBASE + 0xFF, .flags = IORESOURCE_MEM, }, [1] = { .start = CH_SPI0, .end = CH_SPI0, .flags = IORESOURCE_DMA, }, [2] = { .start = IRQ_SPI0, .end = IRQ_SPI0, .flags = IORESOURCE_IRQ, } }; /* SPI (1) */ static struct resource bfin_spi1_resource[] = { [0] = { .start = SPI1_REGBASE, .end = SPI1_REGBASE + 0xFF, .flags = IORESOURCE_MEM, }, [1] = { .start = CH_SPI1, .end = CH_SPI1, .flags = IORESOURCE_DMA, }, [2] = { .start = IRQ_SPI1, .end = IRQ_SPI1, .flags = IORESOURCE_IRQ, } }; /* SPI (2) */ static struct resource bfin_spi2_resource[] = { [0] = { .start = SPI2_REGBASE, .end = SPI2_REGBASE + 0xFF, .flags = IORESOURCE_MEM, }, [1] = { .start = CH_SPI2, .end = CH_SPI2, .flags = IORESOURCE_DMA, }, [2] = { .start = IRQ_SPI2, .end = IRQ_SPI2, .flags = IORESOURCE_IRQ, } }; /* SPI controller data */ static struct bfin5xx_spi_master bf538_spi_master_info0 = { .num_chipselect = 8, .enable_dma = 1, /* master has the ability to do dma transfer */ .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0}, }; static struct platform_device bf538_spi_master0 = { .name = "bfin-spi", .id = 0, /* Bus number */ .num_resources = ARRAY_SIZE(bfin_spi0_resource), .resource = bfin_spi0_resource, .dev = { .platform_data = &bf538_spi_master_info0, /* Passed to driver */ }, }; static struct bfin5xx_spi_master bf538_spi_master_info1 = { .num_chipselect = 2, .enable_dma = 1, /* master has the ability to do dma transfer */ .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0}, }; static struct platform_device bf538_spi_master1 = { .name = "bfin-spi", .id = 1, /* Bus number */ .num_resources = ARRAY_SIZE(bfin_spi1_resource), .resource = bfin_spi1_resource, .dev = { .platform_data = &bf538_spi_master_info1, /* Passed to driver */ }, }; static struct bfin5xx_spi_master bf538_spi_master_info2 = { .num_chipselect = 2, .enable_dma = 1, /* master has the ability to do dma transfer */ .pin_req = {P_SPI2_SCK, P_SPI2_MISO, P_SPI2_MOSI, 0}, }; static struct platform_device bf538_spi_master2 = { .name = "bfin-spi", .id = 2, /* Bus number */ .num_resources = ARRAY_SIZE(bfin_spi2_resource), .resource = bfin_spi2_resource, .dev = { .platform_data = &bf538_spi_master_info2, /* Passed to driver */ }, }; #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) static const u16 bfin_twi0_pins[] = {P_TWI0_SCL, P_TWI0_SDA, 0}; static struct resource bfin_twi0_resource[] = { [0] = { .start = TWI0_REGBASE, .end = TWI0_REGBASE + 0xFF, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_TWI0, .end = IRQ_TWI0, .flags = IORESOURCE_IRQ, }, }; static struct platform_device i2c_bfin_twi0_device = { .name = "i2c-bfin-twi", .id = 0, .num_resources = ARRAY_SIZE(bfin_twi0_resource), .resource = bfin_twi0_resource, .dev = { .platform_data = &bfin_twi0_pins, }, }; static const u16 bfin_twi1_pins[] = {P_TWI1_SCL, P_TWI1_SDA, 0}; static struct resource bfin_twi1_resource[] = { [0] = { .start = TWI1_REGBASE, .end = TWI1_REGBASE + 0xFF, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_TWI1, .end = IRQ_TWI1, .flags = IORESOURCE_IRQ, }, }; static struct platform_device i2c_bfin_twi1_device = { .name = "i2c-bfin-twi", .id = 1, .num_resources = ARRAY_SIZE(bfin_twi1_resource), .resource = bfin_twi1_resource, }; #endif /* CONFIG_I2C_BLACKFIN_TWI */ #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) #include <linux/gpio_keys.h> static struct gpio_keys_button bfin_gpio_keys_table[] = { {BTN_0, GPIO_PC7, 1, "gpio-keys: BTN0"}, }; static struct gpio_keys_platform_data bfin_gpio_keys_data = { .buttons = bfin_gpio_keys_table, .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table), }; static struct platform_device bfin_device_gpiokeys = { .name = "gpio-keys", .dev = { .platform_data = &bfin_gpio_keys_data, }, }; #endif static const unsigned int cclk_vlev_datasheet[] = { /* * Internal VLEV BF538SBBC1533 ****temporarily using these values until data sheet is updated */ VRPAIR(VLEV_100, 150000000), VRPAIR(VLEV_100, 250000000), VRPAIR(VLEV_110, 276000000), VRPAIR(VLEV_115, 301000000), VRPAIR(VLEV_120, 525000000), VRPAIR(VLEV_125, 550000000), VRPAIR(VLEV_130, 600000000), }; static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = { .tuple_tab = cclk_vlev_datasheet, .tabsize = ARRAY_SIZE(cclk_vlev_datasheet), .vr_settling_time = 25 /* us */, }; static struct platform_device bfin_dpmc = { .name = "bfin dpmc", .dev = { .platform_data = &bfin_dmpc_vreg_data, }, }; #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) static struct mtd_partition ezkit_partitions[] = { { .name = "bootloader(nor)", .size = 0x40000, .offset = 0, }, { .name = "linux kernel(nor)", .size = 0x180000, .offset = MTDPART_OFS_APPEND, }, { .name = "file system(nor)", .size = MTDPART_SIZ_FULL, .offset = MTDPART_OFS_APPEND, } }; static struct physmap_flash_data ezkit_flash_data = { .width = 2, .parts = ezkit_partitions, .nr_parts = ARRAY_SIZE(ezkit_partitions), }; static struct resource ezkit_flash_resource = { .start = 0x20000000, #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE) .end = 0x202fffff, #else .end = 0x203fffff, #endif .flags = IORESOURCE_MEM, }; static struct platform_device ezkit_flash_device = { .name = "physmap-flash", .id = 0, .dev = { .platform_data = &ezkit_flash_data, }, .num_resources = 1, .resource = &ezkit_flash_resource, }; #endif static struct platform_device *cm_bf538_devices[] __initdata = { &bfin_dpmc, #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) &rtc_device, #endif #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) #ifdef CONFIG_SERIAL_BFIN_UART0 &bfin_uart0_device, #endif #ifdef CONFIG_SERIAL_BFIN_UART1 &bfin_uart1_device, #endif #ifdef CONFIG_SERIAL_BFIN_UART2 &bfin_uart2_device, #endif #endif #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE) &bf538_spi_master0, &bf538_spi_master1, &bf538_spi_master2, #endif #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) &i2c_bfin_twi0_device, &i2c_bfin_twi1_device, #endif #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE) #ifdef CONFIG_BFIN_SIR0 &bfin_sir0_device, #endif #ifdef CONFIG_BFIN_SIR1 &bfin_sir1_device, #endif #ifdef CONFIG_BFIN_SIR2 &bfin_sir2_device, #endif #endif #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART &bfin_sport0_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART &bfin_sport1_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT2_UART &bfin_sport2_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT3_UART &bfin_sport3_uart_device, #endif #endif #if defined(CONFIG_CAN_BFIN) || defined(CONFIG_CAN_BFIN_MODULE) &bfin_can_device, #endif #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE) &smc91x_device, #endif #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE) &bfin_lq035q1_device, #endif #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) &bfin_device_gpiokeys, #endif #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE) &ezkit_flash_device, #endif }; static int __init ezkit_init(void) { printk(KERN_INFO "%s(): registering device resources\n", __func__); platform_add_devices(cm_bf538_devices, ARRAY_SIZE(cm_bf538_devices)); #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE) spi_register_board_info(bf538_spi_board_info, ARRAY_SIZE(bf538_spi_board_info)); #endif return 0; } arch_initcall(ezkit_init); static struct platform_device *ezkit_early_devices[] __initdata = { #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK) #ifdef CONFIG_SERIAL_BFIN_UART0 &bfin_uart0_device, #endif #ifdef CONFIG_SERIAL_BFIN_UART1 &bfin_uart1_device, #endif #ifdef CONFIG_SERIAL_BFIN_UART2 &bfin_uart2_device, #endif #endif #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE) #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART &bfin_sport0_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART &bfin_sport1_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT2_UART &bfin_sport2_uart_device, #endif #ifdef CONFIG_SERIAL_BFIN_SPORT3_UART &bfin_sport3_uart_device, #endif #endif }; void __init native_machine_early_platform_add_devices(void) { printk(KERN_INFO "register early platform devices\n"); early_platform_add_devices(ezkit_early_devices, ARRAY_SIZE(ezkit_early_devices)); }
5727d6fa6abaa063a03c3b813fc7b6ac7d5f96c5
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/devel/imake/files/patch-imake.c
ed6c3a3570b11f1b5b9bdb56ae0f4c005e616725
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
1,213
c
patch-imake.c
--- imake.c.orig 2019-03-16 23:26:24 UTC +++ imake.c @@ -531,6 +531,14 @@ init(void) AddCppArg(p); } } + if ((p = getenv("IMAKECPPFLAGS"))) { + AddCppArg(p); + for (; *p; p++) + if (*p == ' ') { + *p++ = '\0'; + AddCppArg(p); + } + } if ((p = getenv("IMAKECPP"))) cpp = p; if ((p = getenv("IMAKEMAKE"))) @@ -1139,34 +1147,7 @@ get_ld_version(FILE *inFile) static void get_binary_format(FILE *inFile) { - int mib[2]; - size_t len; - int osrel = 0; - FILE *objprog = NULL; - int iself = 0; - char buf[10]; - char cmd[PATH_MAX]; - - mib[0] = CTL_KERN; - mib[1] = KERN_OSRELDATE; - len = sizeof(osrel); - sysctl(mib, 2, &osrel, &len, NULL, 0); - if (CrossCompiling) { - strcpy (cmd, CrossCompileDir); - strcat (cmd, "/"); - strcat (cmd,"objformat"); - } else - strcpy (cmd, "objformat"); - - if (osrel >= 300004 && - (objprog = popen(cmd, "r")) != NULL && - fgets(buf, sizeof(buf), objprog) != NULL && - strncmp(buf, "elf", 3) == 0) - iself = 1; - if (objprog) - pclose(objprog); - - fprintf(inFile, "#define DefaultToElfFormat %s\n", iself ? "YES" : "NO"); + fprintf(inFile, "#define DefaultToElfFormat YES\n"); } #endif
cba498130416ca3794fbc3245b0d2dd56e8554d9
c26d7b0ed875357278e61627da2da0650da77986
/src/libc/gen/isnan.c
b1d0a447147d7aadbe2939c81ed1d19ccd805832
[ "BSD-3-Clause" ]
permissive
RetroBSD/retrobsd
5343d9e3c424637fc3ad5b03fe720b2744490025
486f81f6abff01c7dcc207235cd2979b226a95ff
refs/heads/master
2023-09-02T23:12:05.110883
2023-07-07T18:41:40
2023-07-07T18:41:40
18,598,087
282
59
BSD-3-Clause
2023-07-18T07:35:36
2014-04-09T13:25:46
C
UTF-8
C
false
false
612
c
isnan.c
/* * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. */ #include <math.h> /* * isnan(x) returns 1 is x is nan, else 0; * no branching! */ int isnan (double x) { long hx, lx; lx = *(unsigned long long*) &x; hx = (*(unsigned long long*) &x) >> 32; hx &= 0x7fffffff; hx |= (unsigned long) (lx | (-lx)) >> 31; hx = 0x7ff00000 - hx; return (int) (((unsigned long) hx) >> 31); }
b05957cc1f220a457e4800a65a97eea9d4ffc2c3
9ceacf33fd96913cac7ef15492c126d96cae6911
/sys/arch/hppa/include/psl.h
e58327b02576b090e3b6e9b7bae3b3aea70b00b9
[]
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
4,351
h
psl.h
/* $OpenBSD: psl.h,v 1.11 2021/03/11 11:16:57 jsg Exp $ */ /* * Copyright (c) 1999-2004 Michael Shalayeff * 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 OR HIS RELATIVES 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 MIND, 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 _MACHINE_PSL_H_ #define _MACHINE_PSL_H_ /* * Reference: * 1. PA-RISC 1.1 Architecture and Instruction Set Manual * Hewlett Packard, 3rd Edition, February 1994; Part Number 09740-90039 */ /* * Processor Status Word Bit Positions (in PA-RISC bit order) */ #define PSL_Y_POS (0) #define PSL_Z_POS (1) #define PSL_SS_POS (3) /* Reserved, Software-defined */ #define PSL_W_POS (4) #define PSL_E_POS (5) #define PSL_S_POS (6) #define PSL_T_POS (7) #define PSL_H_POS (8) #define PSL_L_POS (9) #define PSL_N_POS (10) #define PSL_X_POS (11) #define PSL_B_POS (12) #define PSL_C_POS (13) #define PSL_V_POS (14) #define PSL_M_POS (15) #define PSL_CB_POS (16) #define PSL_O_POS (24) #define PSL_G_POS (25) #define PSL_F_POS (26) #define PSL_R_POS (27) #define PSL_Q_POS (28) #define PSL_P_POS (29) #define PSL_D_POS (30) #define PSL_I_POS (31) #define PSL_BITS "\020\001I\002D\003P\004Q\005R\006F\007G\010O" \ "\021M\022V\023C\024B\025X\026N\027L\030H" \ "\031T\032S\033E\034W\037Z\040Y" /* * Processor Status Word Bit Values */ #define PSL_Y (1 << (31-PSL_Y_POS)) /* Data Debug Trap Disable */ #define PSL_Z (1 << (31-PSL_Z_POS)) /* Instruction Debug Trap Disable */ #define PSL_SS (1 << (31-PSL_SS_POS)) /* Reserved; Software Single-Step */ #define PSL_W (1 << (31-PSL_W_POS)) /* 64bit address decode enable */ #define PSL_E (1 << (31-PSL_E_POS)) /* Little Endian Memory Access Enable */ #define PSL_S (1 << (31-PSL_S_POS)) /* Secure Interval Timer */ #define PSL_T (1 << (31-PSL_T_POS)) /* Taken Branch Trap Enable */ #define PSL_H (1 << (31-PSL_H_POS)) /* Higher-privilege Transfer Trap Enable */ #define PSL_L (1 << (31-PSL_L_POS)) /* Lower-privilege Transfer Trap Enable */ #define PSL_N (1 << (31-PSL_N_POS)) /* Nullify */ #define PSL_X (1 << (31-PSL_X_POS)) /* Data Memory Break Disable */ #define PSL_B (1 << (31-PSL_B_POS)) /* Taken Branch */ #define PSL_C (1 << (31-PSL_C_POS)) /* Instruction Address Translation Enable */ #define PSL_V (1 << (31-PSL_V_POS)) /* Divide Step Correction */ #define PSL_M (1 << (31-PSL_M_POS)) /* High-priority Machine Check Mask */ #define PSL_CB (1 << (31-PSL_CB_POS)) /* Carry/Borrow Bits */ #define PSL_O (1 << (31-PSL_O_POS)) /* Force strong ordering (2.0) */ #define PSL_G (1 << (31-PSL_G_POS)) /* Debug Trap Enable */ #define PSL_F (1 << (31-PSL_F_POS)) /* Performance Monitor Interrupt Unmask */ #define PSL_R (1 << (31-PSL_R_POS)) /* Recover Counter Enable */ #define PSL_Q (1 << (31-PSL_Q_POS)) /* Interrupt State Collection Enable */ #define PSL_P (1 << (31-PSL_P_POS)) /* Protection Identifier Validation Enable */ #define PSL_D (1 << (31-PSL_D_POS)) /* Data Address Translation Enable */ #define PSL_I (1 << (31-PSL_I_POS)) /* External Interrupt, Power Failure Interrupt, and Low-Priority Machine Check Interrupt unmask */ /* * Frequently Used PSW Values */ #define RESET_PSL (PSL_R | PSL_Q | PSL_P | PSL_D | PSL_I) #endif /* _MACHINE_PSL_H_ */
62b6c02ac2f3d9b5e55f7c4d8a8b8f86049aa100
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/include/any-macos-any/xlocale/__wctype.h
d377bf5a7613c31ca7aecfc8ad28396580c065a8
[ "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
3,513
h
__wctype.h
/* * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #ifndef _XLOCALE___WCTYPE_H_ #define _XLOCALE___WCTYPE_H_ #include <__wctype.h> #include <xlocale/_ctype.h> #if !defined(_DONT_USE_CTYPE_INLINE_) && \ (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) __DARWIN_WCTYPE_TOP_inline int iswalnum_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_A|_CTYPE_D, _l)); } __DARWIN_WCTYPE_TOP_inline int iswalpha_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_A, _l)); } __DARWIN_WCTYPE_TOP_inline int iswcntrl_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_C, _l)); } __DARWIN_WCTYPE_TOP_inline int iswctype_l(wint_t _wc, wctype_t _charclass, locale_t _l) { return (__istype_l(_wc, _charclass, _l)); } __DARWIN_WCTYPE_TOP_inline int iswdigit_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_D, _l)); } __DARWIN_WCTYPE_TOP_inline int iswgraph_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_G, _l)); } __DARWIN_WCTYPE_TOP_inline int iswlower_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_L, _l)); } __DARWIN_WCTYPE_TOP_inline int iswprint_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_R, _l)); } __DARWIN_WCTYPE_TOP_inline int iswpunct_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_P, _l)); } __DARWIN_WCTYPE_TOP_inline int iswspace_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_S, _l)); } __DARWIN_WCTYPE_TOP_inline int iswupper_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_U, _l)); } __DARWIN_WCTYPE_TOP_inline int iswxdigit_l(wint_t _wc, locale_t _l) { return (__istype_l(_wc, _CTYPE_X, _l)); } __DARWIN_WCTYPE_TOP_inline wint_t towlower_l(wint_t _wc, locale_t _l) { return (__tolower_l(_wc, _l)); } __DARWIN_WCTYPE_TOP_inline wint_t towupper_l(wint_t _wc, locale_t _l) { return (__toupper_l(_wc, _l)); } #else /* not using inlines */ __BEGIN_DECLS int iswalnum_l(wint_t, locale_t); int iswalpha_l(wint_t, locale_t); int iswcntrl_l(wint_t, locale_t); int iswctype_l(wint_t, wctype_t, locale_t); int iswdigit_l(wint_t, locale_t); int iswgraph_l(wint_t, locale_t); int iswlower_l(wint_t, locale_t); int iswprint_l(wint_t, locale_t); int iswpunct_l(wint_t, locale_t); int iswspace_l(wint_t, locale_t); int iswupper_l(wint_t, locale_t); int iswxdigit_l(wint_t, locale_t); wint_t towlower_l(wint_t, locale_t); wint_t towupper_l(wint_t, locale_t); __END_DECLS #endif /* using inlines */ __BEGIN_DECLS wctype_t wctype_l(const char *, locale_t); __END_DECLS #endif /* _XLOCALE___WCTYPE_H_ */
551eca41d40a627c901e503c8ea1057b00bf30e5
a85c048a4ae820beb2bc265d1845e23842fc8c2a
/data_collection/common/sql_dump_v2.c
fe702b6ed1796bb45679603154224c7ff159b74c
[ "MIT" ]
permissive
ithemal/Ithemal
e549856538c7b1f2c50d0f40b51b9bb97baf6379
b3c39a8942b8b3d92c0fa81815b34fa9b6cbe683
refs/heads/master
2021-12-10T11:50:00.058462
2021-11-30T16:18:30
2021-11-30T16:18:30
151,625,735
124
33
MIT
2020-06-26T15:11:01
2018-10-04T19:33:52
Python
UTF-8
C
false
false
2,376
c
sql_dump_v2.c
#include <string.h> #include <stdio.h> #include "sql_dump_v2.h" // dropping support for sqlite and solely focused on MYSQL syntax // reason why we do not directly insert into the database is because // if you use DR to collect executed BBs, rather than as a decoding library // it will not work since MYSQL library requires pthread support. char * code_types[3] = {"code_token", "code_intel", "code_att"}; int insert_architecture(query_t * query, config_t * config){ int pos = 0; pos += sprintf(query, "INSERT INTO cpu_desc (name, vendor) VALUES ('%s', '%s');\n", config->name, config->vendor); pos += sprintf(query + pos, "SET @arch_id = (SELECT arch_id from cpu_desc WHERE name = '%s' AND vendor ='%s');\n", config->name, config->vendor); return pos; } int insert_config(query_t * query, config_t * config){ int pos = 0; pos += sprintf(query, "INSERT INTO config (compiler, flags, arch_id) VALUES ('%s','%s', @arch_id);\n", config->compiler, config->flags); pos += sprintf(query + pos,"SET @config_id = (SELECT config_id FROM config WHERE compiler = '%s' AND flags = '%s' AND arch_id = @arch_id);\n", config->compiler, config->flags); return pos; } int insert_code(query_t * query, code_info_t * cinfo){ int pos = 0; pos += sprintf(query, "INSERT INTO code (code_raw) VALUES ('"); int i = 0; for(i = 0; i < cinfo->code_size; i++){ pos += sprintf(query + pos, "%02x", cinfo->code[i], i); } //pos += sprintf(query + pos, "-%d", cinfo->code_size); pos += sprintf(query + pos, "');\n"); return pos; } int insert_disassembly(query_t * query, code_info_t * cinfo, uint32_t type){ int pos = 0; pos += sprintf(query, "UPDATE code_metadata SET %s='",code_types[type]); int i = 0; for(i = 0; i < cinfo->code_size; i++){ query[pos + i] = cinfo->code[i]; } pos += cinfo->code_size; pos += sprintf(query + pos, "' WHERE metadata_id=LAST_INSERT_ID();\n"); return pos; } int insert_code_metadata(query_t * query, code_info_t * cinfo){ int pos; pos = sprintf(query, "INSERT INTO code_metadata (config_id, code_id, module, rel_addr) VALUES (@config_id, LAST_INSERT_ID(), '%s',%llu);\n",cinfo->module, cinfo->rel_addr); if(strlen(cinfo->function) > 0){ pos += sprintf(query + pos, "UPDATE code_metadata SET function='%s' WHERE metadata_id=LAST_INSERT_ID();\n", cinfo->function); } return pos; }
a7736f3b51cb447cddb1c57655a10e55c53eb366
08a26f17a11f0aa2263001f9b1014a4b906f8bb3
/src/boot/table_test.c
4b941ca2c68c8f47633ffe09096e7b3c25c80fa2
[ "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
3,131
c
table_test.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. */ #include <janet.h> #include <assert.h> #include "tests.h" int table_test() { JanetTable *t1, *t2; t1 = janet_table(10); t2 = janet_table(0); janet_table_put(t1, janet_cstringv("hello"), janet_wrap_integer(2)); janet_table_put(t1, janet_cstringv("akey"), janet_wrap_integer(5)); janet_table_put(t1, janet_cstringv("box"), janet_wrap_boolean(0)); janet_table_put(t1, janet_cstringv("square"), janet_cstringv("avalue")); assert(t1->count == 4); assert(t1->capacity >= t1->count); assert(janet_equals(janet_table_get(t1, janet_cstringv("hello")), janet_wrap_integer(2))); assert(janet_equals(janet_table_get(t1, janet_cstringv("akey")), janet_wrap_integer(5))); assert(janet_equals(janet_table_get(t1, janet_cstringv("box")), janet_wrap_boolean(0))); assert(janet_equals(janet_table_get(t1, janet_cstringv("square")), janet_cstringv("avalue"))); janet_table_remove(t1, janet_cstringv("hello")); janet_table_put(t1, janet_cstringv("box"), janet_wrap_nil()); assert(t1->count == 2); assert(janet_equals(janet_table_get(t1, janet_cstringv("hello")), janet_wrap_nil())); assert(janet_equals(janet_table_get(t1, janet_cstringv("box")), janet_wrap_nil())); janet_table_put(t2, janet_csymbolv("t2key1"), janet_wrap_integer(10)); janet_table_put(t2, janet_csymbolv("t2key2"), janet_wrap_integer(100)); janet_table_put(t2, janet_csymbolv("some key "), janet_wrap_integer(-2)); janet_table_put(t2, janet_csymbolv("a thing"), janet_wrap_integer(10)); assert(janet_equals(janet_table_get(t2, janet_csymbolv("t2key1")), janet_wrap_integer(10))); assert(janet_equals(janet_table_get(t2, janet_csymbolv("t2key2")), janet_wrap_integer(100))); assert(t2->count == 4); assert(janet_equals(janet_table_remove(t2, janet_csymbolv("t2key1")), janet_wrap_integer(10))); assert(t2->count == 3); assert(janet_equals(janet_table_remove(t2, janet_csymbolv("t2key2")), janet_wrap_integer(100))); assert(t2->count == 2); return 0; }
be272602b0780d49dccd658dcaff34074b3abcf9
50dd46b8ece33f3cdd174284b15d1d51f89669d4
/third_party/edk2/StdLib/LibC/Stdio/local.h
262deb36116c32386cef59eba1c774d12c5d787e
[ "LicenseRef-scancode-generic-cla", "Apache-2.0", "BSD-2-Clause", "OpenSSL" ]
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
4,872
h
local.h
/** @file Information local to this implementation of stdio, in particular, function declarations and macros. Copyright (c) 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License that 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. Copyright (c) 1990, 1993 The Regents of the University of California. All rights reserved. This code is derived from software contributed to Berkeley by Chris Torek. 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 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 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 HOLDERS 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. NetBSD: local.h,v 1.20 2005/05/14 23:51:02 christos Exp local.h 8.3 (Berkeley) 7/3/94 **/ #include "wcio.h" #include "fileext.h" extern int __sflush(FILE *); extern FILE *__sfp(void); extern int __srefill(FILE *); extern int __sread(void *, char *, int); extern int __swrite(void *, char const *, int); extern fpos_t __sseek(void *, fpos_t, int); extern int __sclose(void *); extern void __sinit(void); extern void _cleanup(void); //extern void (*__cleanup)(void); // Now in MainData.h. Ref. as gMD->cleanup extern void __smakebuf(FILE *); extern int __swhatbuf(FILE *, size_t *, int *); extern int _fwalk(int (*)(FILE *)); extern char *_mktemp(char *); extern int __swsetup(FILE *); extern int __sflags(const char *, int *); extern int __svfscanf(FILE * __restrict, const char * __restrict, va_list) __attribute__((__format__(__scanf__, 2, 0))); extern int __svfscanf_unlocked(FILE * __restrict, const char * __restrict, va_list) __attribute__((__format__(__scanf__, 2, 0))); extern int __vfprintf_unlocked(FILE * __restrict, const char * __restrict, va_list); extern int __sdidinit; extern int __gettemp(char *, int *, int); extern wint_t __fgetwc_unlock(FILE *); extern wint_t __fputwc_unlock(wchar_t, FILE *); extern char *__fgetstr(FILE * __restrict, size_t * __restrict, int); extern int __slbexpand(FILE *, size_t); extern int __vfwprintf_unlocked(FILE *, const wchar_t *, va_list); extern int __vfwscanf_unlocked(FILE * __restrict, const wchar_t * __restrict, va_list); /* * Return true iff the given FILE cannot be written now. */ #define cantwrite(fp) \ ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && __swsetup(fp)) /* * Test whether the given stdio file has an active ungetc buffer; * release such a buffer, without restoring ordinary unread data. */ #define HASUB(fp) (_UB(fp)._base != NULL) #define FREEUB(fp) { \ if (_UB(fp)._base != (fp)->_ubuf) \ free((char *)_UB(fp)._base); \ _UB(fp)._base = NULL; \ } /* * test for an fgetln() buffer. */ #define HASLB(fp) ((fp)->_lb._base != NULL) #define FREELB(fp) { \ free((char *)(fp)->_lb._base); \ (fp)->_lb._base = NULL; \ } extern void __flockfile_internal (FILE *, int); extern void __funlockfile_internal(FILE *, int);
be5e42f631d4acc3a82e505c1f353f86fadb7fcb
abe704eb3b53944cdd6505f922f58558e334c589
/components/motor/servo/include/iot_servo.h
b5659e90b08e8a070ee22a1c1bf087962fdeaa35
[ "Apache-2.0" ]
permissive
espressif/esp-iot-solution
c25079eb26a8f54ddacd23689a7288533c721916
2227f0ca21ab37df9cf9d74182fa84c52dffc76f
refs/heads/master
2023-09-01T15:06:17.000154
2023-08-31T10:26:21
2023-08-31T10:26:21
99,690,601
1,612
758
Apache-2.0
2023-09-08T08:43:59
2017-08-08T12:32:16
C
UTF-8
C
false
false
2,694
h
iot_servo.h
/* * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #ifndef _IOT_SERVO_H_ #define _IOT_SERVO_H_ #include "esp_err.h" #include "driver/ledc.h" #include "driver/gpio.h" /** * @brief Configuration of servo motor channel * */ typedef struct { gpio_num_t servo_pin[LEDC_CHANNEL_MAX]; /**< Pin number of pwm output */ ledc_channel_t ch[LEDC_CHANNEL_MAX]; /**< The ledc channel which used */ } servo_channel_t; /** * @brief Configuration of servo motor * */ typedef struct { uint16_t max_angle; /**< Servo max angle */ uint16_t min_width_us; /**< Pulse width corresponding to minimum angle, which is usually 500us */ uint16_t max_width_us; /**< Pulse width corresponding to maximum angle, which is usually 2500us */ uint32_t freq; /**< PWM frequency */ ledc_timer_t timer_number; /**< Timer number of ledc */ servo_channel_t channels; /**< Channels to use */ uint8_t channel_number; /**< Total channel number */ } servo_config_t; #ifdef __cplusplus extern "C" { #endif /** * @brief Initialize ledc to control the servo * * @param speed_mode Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. * @param config Pointer of servo configure struct * * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG Parameter error * - ESP_FAIL Configure ledc failed */ esp_err_t iot_servo_init(ledc_mode_t speed_mode, const servo_config_t *config); /** * @brief Deinitialize ledc for servo * * @param speed_mode Select the LEDC channel group with specified speed mode. * * @return * - ESP_OK Success */ esp_err_t iot_servo_deinit(ledc_mode_t speed_mode); /** * @brief Set the servo motor to a certain angle * * @note This API is not thread-safe * * @param speed_mode Select the LEDC channel group with specified speed mode. * @param channel LEDC channel, select from ledc_channel_t * @param angle The angle to go * * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG Parameter error */ esp_err_t iot_servo_write_angle(ledc_mode_t speed_mode, uint8_t channel, float angle); /** * @brief Read current angle of one channel * * @param speed_mode Select the LEDC channel group with specified speed mode. * @param channel LEDC channel, select from ledc_channel_t * @param angle Current angle of the channel * * @return * - ESP_OK Success * - ESP_ERR_INVALID_ARG Parameter error */ esp_err_t iot_servo_read_angle(ledc_mode_t speed_mode, uint8_t channel, float *angle); #ifdef __cplusplus } #endif #endif /* _IOT_SERVO_H_ */
45a91ad4d0dfa4d2bfc1d6a2dd293708094c0f0d
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/ftp/quftp/files/patch-ftp.c
cbffb8b61e444056ed0b87fee1d5da4e1bbb530c
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
335
c
patch-ftp.c
--- ftp.c.orig Mon Mar 10 19:28:11 2003 +++ ftp.c Wed Dec 10 20:33:55 2003 @@ -7,12 +7,10 @@ #define _XOPEN_SOURCE 500 #include <stdlib.h> -#include <features.h> #include <stdio.h> #include <errno.h> #include <fcntl.h> #include <ctype.h> -#include <malloc.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h>
07090bbb5bcf5982facf14f19703c6a5f0cc8df8
1901bdbaf57584e7c5ec21643db340f9d98d6807
/compute/tensor/src/cpu/arm/fp32/mvm_nkn32.h
e3dbc50e64c29d0bd3d2b1f8c5c45bfad964e447
[ "MIT" ]
permissive
huawei-noah/bolt
2a4febe5f5cce64e3589c2782c489d59975eb6a3
cf4ca8f8646a8e30ddf91c29a18743d75ac1c172
refs/heads/master
2023-08-28T13:36:34.815244
2023-06-12T01:24:41
2023-06-12T01:24:41
225,365,905
889
168
MIT
2023-06-12T01:24:42
2019-12-02T12:06:12
C++
UTF-8
C
false
false
17,279
h
mvm_nkn32.h
// Copyright (C) 2019. Huawei Technologies Co., Ltd. All rights reserved. // 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 _H_MVM_NKN32 #define _H_MVM_NKN32 #include "tensor_desc.h" #include "thread_affinity.h" inline void mvm_nkn32(U32 fn, U32 fk, const F32 *filterArray, F32 *input, F32 *output) { #ifdef _USE_OPENMP #pragma omp parallel for num_threads(OMP_NUM_THREADS) #endif for (U32 n = 0; n < fn; n++) { F32 *in = input; const F32 *f = filterArray + n * fk * 32; F32 *out = output + n * 32; #ifdef __aarch64__ __asm__ __volatile__("ldr d0, [%[in]]\n" "ldr q1, [%[out]]\n" "ldr q2, [%[out], #16]\n" "ldr q3, [%[out], #32]\n" "ldr q4, [%[out], #48]\n" "ldr q13, [%[out], #64]\n" "ldr q14, [%[out], #80]\n" "ldr q15, [%[out], #96]\n" "ldr q16, [%[out], #112]\n" "mov x0, %[k]\n" "ldr q5, [%[f]]\n" "ldr q6, [%[f], #16]\n" "ldr q7, [%[f], #32]\n" "ldr q8, [%[f], #48]\n" "ldr q17, [%[f], #64]\n" "ldr q18, [%[f], #80]\n" "ldr q19, [%[f], #96]\n" "ldr q20, [%[f], #112]\n" "0:\n" "prfm pldl2strm, [%[f], #4096]\n" "prfm pldl1strm, [%[f], #1024]\n" "ldr d9, [%[f], #128]\n" "fmla v1.4s, v5.4s, v0.s[0]\n" "ldr x9, [%[f], #136]\n" "ins v9.d[1], x9\n" "ldr d10, [%[f], #144]\n" "fmla v2.4s, v6.4s, v0.s[0]\n" "ldr x10, [%[f], #152]\n" "ins v10.d[1], x10\n" "ldr d11, [%[f], #160]\n" "fmla v3.4s, v7.4s, v0.s[0]\n" "ldr x11, [%[f], #168]\n" "ins v11.d[1], x11\n" "ldr d12, [%[f], #176]\n" "fmla v4.4s, v8.4s, v0.s[0]\n" "ldr x12, [%[f], #184]\n" "ins v12.d[1], x12\n" "ldr d21, [%[f], #192]\n" "fmla v13.4s, v17.4s, v0.s[0]\n" "ldr x9, [%[f], #200]\n" "ins v21.d[1], x9\n" "ldr d22, [%[f], #208]\n" "fmla v14.4s, v18.4s, v0.s[0]\n" "ldr x10, [%[f], #216]\n" "ins v22.d[1], x10\n" "ldr d23, [%[f], #224]\n" "fmla v15.4s, v19.4s, v0.s[0]\n" "ldr x11, [%[f], #232]\n" "ins v23.d[1], x11\n" "ldr d24, [%[f], #240]\n" "fmla v16.4s, v20.4s, v0.s[0]\n" "ldr x12, [%[f], #248]\n" "ins v24.d[1], x12\n" "add %[f], %[f], #256\n" "ldr d5, [%[f]]\n" "fmla v1.4s, v9.4s, v0.s[1]\n" "ldr x5, [%[f], #8]\n" "ins v5.d[1], x5\n" "ldr d6, [%[f], #16]\n" "fmla v2.4s, v10.4s, v0.s[1]\n" "ldr x6, [%[f], #24]\n" "ins v6.d[1], x6\n" "ldr d7, [%[f], #32]\n" "fmla v3.4s, v11.4s, v0.s[1]\n" "ldr x7, [%[f], #40]\n" "ins v7.d[1], x7\n" "ldr d8, [%[f], #48]\n" "fmla v4.4s, v12.4s, v0.s[1]\n" "ldr x8, [%[f], #56]\n" "ins v8.d[1], x8\n" "ldr d17, [%[f], #64]\n" "fmla v13.4s, v21.4s, v0.s[1]\n" "ldr x5, [%[f], #72]\n" "ins v17.d[1], x5\n" "ldr d18, [%[f], #80]\n" "fmla v14.4s, v22.4s, v0.s[1]\n" "ldr x6, [%[f], #88]\n" "ins v18.d[1], x6\n" "ldr d19, [%[f], #96]\n" "fmla v15.4s, v23.4s, v0.s[1]\n" "ldr x7, [%[f], #104]\n" "ins v19.d[1], x7\n" "ldr d20, [%[f], #112]\n" "fmla v16.4s, v24.4s, v0.s[1]\n" "ldr x8, [%[f], #120]\n" "add %[in], %[in], #8\n" "ins v20.d[1], x8\n" "ldr d0, [%[in]]\n" "sub x0, x0, #2\n" "cmp x0, #3\n" "bgt 0b\n" "ldr q9, [%[f], #128]\n" "ldr q10, [%[f], #144]\n" "ldr q11, [%[f], #160]\n" "ldr q12, [%[f], #176]\n" "ldr q21, [%[f], #192]\n" "ldr q22, [%[f], #208]\n" "ldr q23, [%[f], #224]\n" "ldr q24, [%[f], #240]\n" "fmla v1.4s, v5.4s, v0.s[0]\n" "fmla v2.4s, v6.4s, v0.s[0]\n" "fmla v3.4s, v7.4s, v0.s[0]\n" "fmla v4.4s, v8.4s, v0.s[0]\n" "fmla v13.4s, v17.4s, v0.s[0]\n" "fmla v14.4s, v18.4s, v0.s[0]\n" "fmla v15.4s, v19.4s, v0.s[0]\n" "fmla v16.4s, v20.4s, v0.s[0]\n" "fmla v1.4s, v9.4s, v0.s[1]\n" "fmla v2.4s, v10.4s, v0.s[1]\n" "fmla v3.4s, v11.4s, v0.s[1]\n" "fmla v4.4s, v12.4s, v0.s[1]\n" "fmla v13.4s, v21.4s, v0.s[1]\n" "fmla v14.4s, v22.4s, v0.s[1]\n" "fmla v15.4s, v23.4s, v0.s[1]\n" "fmla v16.4s, v24.4s, v0.s[1]\n" "cmp x0, #3\n" "bne 1f\n" "add %[f], %[f], #256\n" "ldr s0, [%[in], #8]\n" "ldr q5, [%[f]]\n" "ldr q6, [%[f], #16]\n" "ldr q7, [%[f], #32]\n" "ldr q8, [%[f], #48]\n" "ldr q17, [%[f], #64]\n" "ldr q18, [%[f], #80]\n" "ldr q19, [%[f], #96]\n" "ldr q20, [%[f], #112]\n" "fmla v1.4s, v5.4s, v0.s[0]\n" "fmla v2.4s, v6.4s, v0.s[0]\n" "fmla v3.4s, v7.4s, v0.s[0]\n" "fmla v4.4s, v8.4s, v0.s[0]\n" "fmla v13.4s, v17.4s, v0.s[0]\n" "fmla v14.4s, v18.4s, v0.s[0]\n" "fmla v15.4s, v19.4s, v0.s[0]\n" "fmla v16.4s, v20.4s, v0.s[0]\n" "1:\n" "str q1, [%[out]]\n" "str q2, [%[out], #16]\n" "str q3, [%[out], #32]\n" "str q4, [%[out], #48]\n" "str q13, [%[out], #64]\n" "str q14, [%[out], #80]\n" "str q15, [%[out], #96]\n" "str q16, [%[out], #112]\n" : [out] "+r"(out), [f] "+r"(f), [in] "+r"(in) : [k] "r"((I64)fk) : "memory", "cc", "x0", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24"); #else __asm__ __volatile__("vld1.f32 {d0[0]}, [%[in]]!\n" "mov r2, %[out]\n" "mov r3, %[out]\n" "vld1.f32 {d2-d3}, [r2]!\n" "vld1.f32 {d4-d5}, [r2]!\n" "vld1.f32 {d6-d7}, [r2]!\n" "vld1.f32 {d8-d9}, [r2]!\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "mov r4, %[k]\n" "vld1.f32 {d10-d11}, [r2]!\n" "vld1.f32 {d12-d13}, [r2]!\n" "vld1.f32 {d14-d15}, [r2]!\n" "vld1.f32 {d16-d17}, [r2]\n" "vld1.f32 {d26-d27}, [%[f]]!\n" "vld1.f32 {d28-d29}, [%[f]]!\n" "0:\n" "cmp r4, #3\n" "ble 3f\n" "pld [%[f], #374]\n" "vld1.f32 {d30[0]}, [%[in]]!\n" "vmla.f32 q1, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q2, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vmla.f32 q3, q11, d0[0]\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vmla.f32 q4, q12, d0[0]\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "vmla.f32 q5, q13, d0[0]\n" "vld1.f32 {d26-d27}, [%[f]]!\n" "vmla.f32 q6, q14, d0[0]\n" "vld1.f32 {d28-d29}, [%[f]]!\n" "vmla.f32 q7, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q8, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "pld [%[f], #374]\n" "vmov.f32 q0, q15\n" "vld1.f32 {d30[0]}, [%[in]]!\n" "vmla.f32 q1, q11, d0[0]\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vmla.f32 q2, q12, d0[0]\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "vmla.f32 q3, q13, d0[0]\n" "vld1.f32 {d26-d27}, [%[f]]!\n" "vmla.f32 q4, q14, d0[0]\n" "vld1.f32 {d28-d29}, [%[f]]!\n" "vmla.f32 q5, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q6, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vmla.f32 q7, q11, d0[0]\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vmla.f32 q8, q12, d0[0]\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "sub r4, r4, #3\n" "pld [%[f], #374]\n" "vmov.f32 q0, q15\n" "vld1.f32 {d30[0]}, [%[in]]!\n" "vmla.f32 q1, q13, d0[0]\n" "vld1.f32 {d26-d27}, [%[f]]!\n" "vmla.f32 q2, q14, d0[0]\n" "vld1.f32 {d28-d29}, [%[f]]!\n" "vmla.f32 q3, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q4, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vmla.f32 q5, q11, d0[0]\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vmla.f32 q6, q12, d0[0]\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "vmla.f32 q7, q13, d0[0]\n" "vld1.f32 {d26-d27}, [%[f]]!\n" "vmla.f32 q8, q14, d0[0]\n" "vld1.f32 {d28-d29}, [%[f]]!\n" "vmov.f32 q0, q15\n" "b 0b\n" "3:\n" "sub r4, r4, #1\n" "vmla.f32 q1, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q2, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vmla.f32 q3, q11, d0[0]\n" "vmla.f32 q4, q12, d0[0]\n" "vmla.f32 q5, q13, d0[0]\n" "vmla.f32 q6, q14, d0[0]\n" "vmla.f32 q7, q9, d0[0]\n" "vmla.f32 q8, q10, d0[0]\n" "1:\n" "cmp r4, #0\n" "beq 2f\n" "sub r4, r4, #1\n" "vld1.f32 {d0[0]}, [%[in]]!\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "vmla.f32 q1, q9, d0[0]\n" "vld1.f32 {d18-d19}, [%[f]]!\n" "vmla.f32 q2, q10, d0[0]\n" "vld1.f32 {d20-d21}, [%[f]]!\n" "vmla.f32 q3, q11, d0[0]\n" "vld1.f32 {d22-d23}, [%[f]]!\n" "vmla.f32 q4, q12, d0[0]\n" "vld1.f32 {d24-d25}, [%[f]]!\n" "vmla.f32 q5, q9, d0[0]\n" "vmla.f32 q6, q10, d0[0]\n" "vmla.f32 q7, q11, d0[0]\n" "vmla.f32 q8, q12, d0[0]\n" "b 1b\n" "2:\n" "vst1.f32 {d2-d3}, [r3]!\n" "vst1.f32 {d4-d5}, [r3]!\n" "vst1.f32 {d6-d7}, [r3]!\n" "vst1.f32 {d8-d9}, [r3]!\n" "vst1.f32 {d10-d11}, [r3]!\n" "vst1.f32 {d12-d13}, [r3]!\n" "vst1.f32 {d14-d15}, [r3]!\n" "vst1.f32 {d16-d17}, [r3]\n" : [f] "+r"(f), [in] "+r"(in) : [k] "r"(fk), [out] "r"(out) : "memory", "cc", "r2", "r3", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"); #endif } } #endif
4d2ce27c0b7875ba2b4cadb31cd520ec1c70fc31
035660e8cc10571ebbd0d4393fef063bb7eb98f6
/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c
c7dbd8888229681c7f126b72e4021dd33125f7a8
[]
no_license
zeldaret/mm
f163a5e7c4314105777369fa7671ce9c2a99922a
4ae00e909e74044f05155683b49d2561f91de7ba
refs/heads/master
2023-08-06T07:22:04.912966
2023-08-04T20:36:03
2023-08-04T20:36:03
247,875,852
915
328
null
2023-09-14T11:48:59
2020-03-17T04:03:07
C
UTF-8
C
false
false
9,299
c
z_en_dnb.c
/* * File: z_en_dnb.c * Overlay: ovl_En_Dnb * Description: Unused invisible snowy mountain that explodes? */ #include "z_en_dnb.h" #include "objects/object_hanareyama_obj/object_hanareyama_obj.h" #include "objects/gameplay_keep/gameplay_keep.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20 | ACTOR_FLAG_REACT_TO_LENS) #define THIS ((EnDnb*)thisx) void EnDnb_Init(Actor* thisx, PlayState* play); void EnDnb_Destroy(Actor* thisx, PlayState* play); void EnDnb_Update(Actor* thisx, PlayState* play); void EnDnb_Draw(Actor* thisx, PlayState* play); s32 func_80A507C0(EnDnbUnkStruct* arg0, Vec3f arg1, Vec3f arg2, u8 arg3, f32 arg4, f32 arg5); s32 func_80A5086C(EnDnbUnkStruct* arg0); s32 func_80A50950(EnDnbUnkStruct* arg0, PlayState* play2); ActorInit En_Dnb_InitVars = { ACTOR_EN_DNB, ACTORCAT_BG, FLAGS, OBJECT_HANAREYAMA_OBJ, sizeof(EnDnb), (ActorFunc)EnDnb_Init, (ActorFunc)EnDnb_Destroy, (ActorFunc)EnDnb_Update, (ActorFunc)EnDnb_Draw, }; void func_80A4FDD0(EnDnbEffect* effect, EnDnb* this, s16* alloc, s32 idx) { Vec3f sp1C; s32 idx2 = idx * 3; sp1C.x = alloc[idx2 + 0] + this->dyna.actor.world.pos.x; sp1C.y = alloc[idx2 + 1] + this->dyna.actor.world.pos.y; sp1C.z = alloc[idx2 + 2] + this->dyna.actor.world.pos.z; effect->unk_00 = sp1C; effect->unk_0C = sp1C; effect->unk_24 = Math_Vec3f_Yaw(&this->dyna.actor.world.pos, &sp1C); effect->unk_18 = gZeroVec3s; } s32 func_80A4FEBC(EnDnbEffect* effect, f32 arg1) { s32 ret = false; if ((DECR(effect->unk_26) == 0) && (arg1 < effect->unk_0C.y)) { Math_ApproachF(&effect->unk_30, 1.0f, 0.4f, 1.0f); effect->unk_2C += effect->unk_34; effect->unk_0C.x += effect->unk_30 * Math_SinS(effect->unk_24); effect->unk_0C.z += effect->unk_30 * Math_CosS(effect->unk_24); effect->unk_0C.y += effect->unk_2C; if (effect->unk_0C.y <= arg1) { effect->unk_0C.y = arg1; } effect->unk_18.x += effect->unk_1E.x; effect->unk_18.y += effect->unk_1E.y; effect->unk_18.z += effect->unk_1E.z; ret = true; } return ret; } void func_80A4FFE8(EnDnbEffect* effect, s16 arg1) { effect->unk_0C = effect->unk_00; effect->unk_1E.x = (Rand_ZeroOne() - 0.5f) * 400.0f; effect->unk_1E.y = (Rand_ZeroOne() - 0.5f) * 400.0f; effect->unk_1E.z = (Rand_ZeroOne() - 0.5f) * 400.0f; effect->unk_18 = gZeroVec3s; effect->unk_30 = 40.0f; effect->unk_2C = 0.0f; effect->unk_26 = arg1; effect->unk_34 = (Rand_ZeroOne() * -2.0f) - 2.0f; } s32 func_80A500F8(EnDnb* this) { static Vec3f D_80A50CB0 = { 0.0f, 0.0f, 1000.0f }; Actor* actor = &this->dyna.actor; Vec3f spA8 = gZeroVec3f; Vec3f sp9C; s32 i; f32 temp_f20; for (i = 0; i < 16; i++) { Lib_Vec3f_TranslateAndRotateY(&actor->world.pos, i * 4096, &D_80A50CB0, &spA8); temp_f20 = Rand_ZeroOne() * 240.0f; sp9C.x = Math_SinS(i * 4096) * temp_f20; sp9C.z = Math_CosS(i * 4096) * temp_f20; sp9C.y = Rand_ZeroOne() * 180.0f; func_80A507C0(this->unk_0D38, spA8, sp9C, 16, 50.0f, 30.0f); } return i; } void EnDnb_Init(Actor* thisx, PlayState* play) { EnDnb* this = THIS; s32 i; s16* alloc; DynaPolyActor_Init(&this->dyna, DYNA_TRANSFORM_POS); DynaPolyActor_LoadMesh(play, &this->dyna, &object_hanareyama_obj_Colheader_004D8C); alloc = Lib_SegmentedToVirtual(object_hanareyama_obj_Vec_004710); for (i = 0; i < ARRAY_COUNT(this->effects); i++) { func_80A4FDD0(&this->effects[i], this, alloc, i); } Actor_SetScale(&this->dyna.actor, 1.0f); } void EnDnb_Destroy(Actor* thisx, PlayState* play) { EnDnb* this = THIS; DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); } void EnDnb_Update(Actor* thisx, PlayState* play) { EnDnb* this = THIS; s32 i; if (this->unk_0D30 == 0) { for (i = 0; i < ARRAY_COUNT(this->effects); i++) { func_80A4FFE8(&this->effects[i], ((53 - i) / 18) * 4); } for (i = 0; i < ARRAY_COUNT(this->unk_0D38); i++) { this->unk_0D38[i].isEnabled = false; } this->unk_0D32 = 20; this->unk_0D30 = 100; } else if (DECR(this->unk_0D32) == 0) { if ((DECR(this->unk_0D34) == 0) && (this->unk_0D30 >= 21)) { this->unk_0D34 = 5; func_80A500F8(this); } for (i = 0; i < ARRAY_COUNT(this->effects); i++) { func_80A4FEBC(&this->effects[i], this->dyna.actor.world.pos.y); } this->unk_0D30--; } func_80A5086C(this->unk_0D38); } void func_80A50510(EnDnb* this, PlayState* play) { s32 i; Gfx** gfx = Lib_SegmentedToVirtual(object_hanareyama_obj_DLArray_004638); OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Xlu(play->state.gfxCtx); for (i = 0; i < ARRAY_COUNT(this->effects); i++) { Matrix_Push(); Matrix_Translate(this->effects[i].unk_0C.x, this->effects[i].unk_0C.y, this->effects[i].unk_0C.z, MTXMODE_NEW); Matrix_RotateXS(this->effects[i].unk_18.x, MTXMODE_APPLY); Matrix_RotateYS(this->effects[i].unk_18.y, MTXMODE_APPLY); Matrix_RotateZS(this->effects[i].unk_18.z, MTXMODE_APPLY); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gfx[i]); Matrix_Pop(); } CLOSE_DISPS(play->state.gfxCtx); } void func_80A5063C(EnDnb* this, PlayState* play) { s32 i; Gfx** gfx = Lib_SegmentedToVirtual(object_hanareyama_obj_DLArray_004638); OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Opa(play->state.gfxCtx); for (i = 0; i < ARRAY_COUNT(this->effects); i++) { Matrix_Push(); Matrix_Translate(this->effects[i].unk_0C.x, this->effects[i].unk_0C.y, this->effects[i].unk_0C.z, MTXMODE_NEW); Matrix_RotateXS(this->effects[i].unk_18.x, MTXMODE_APPLY); Matrix_RotateYS(this->effects[i].unk_18.y, MTXMODE_APPLY); Matrix_RotateZS(this->effects[i].unk_18.z, MTXMODE_APPLY); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_OPA_DISP++, gfx[i]); Matrix_Pop(); } CLOSE_DISPS(play->state.gfxCtx); } void EnDnb_Draw(Actor* thisx, PlayState* play) { EnDnb* this = THIS; if (play->actorCtx.lensMaskSize != 0) { func_80A50510(this, play); } else { func_80A5063C(this, play); } func_80A50950(this->unk_0D38, play); } s32 func_80A507C0(EnDnbUnkStruct* arg0, Vec3f arg1, Vec3f arg2, u8 arg3, f32 arg4, f32 arg5) { s32 i; s32 ret = 0; for (i = 0; i < 256; i++, arg0++) { if (arg0->isEnabled == false) { arg0->isEnabled = true; arg0->unk_01 = arg3; arg0->unk_02 = arg3; arg0->unk_0C = arg1; arg0->unk_18 = arg2; arg0->unk_04 = arg4; arg0->unk_08 = arg5; arg0->unk_24 = 255.0f; ret = 1; break; } } return ret; } s32 func_80A5086C(EnDnbUnkStruct* arg0) { s32 count = 0; s32 i; for (i = 0; i < 256; i++, arg0++) { if (arg0->isEnabled == true) { count++; if (arg0->unk_01 != 0) { arg0->unk_0C.x += arg0->unk_18.x; arg0->unk_0C.y += arg0->unk_18.y; arg0->unk_0C.z += arg0->unk_18.z; arg0->unk_01 -= 1; } else { arg0->isEnabled = false; } } } return count; } s32 func_80A50950(EnDnbUnkStruct* arg0, PlayState* play2) { static TexturePtr sDustTextures[] = { gEffDust8Tex, gEffDust7Tex, gEffDust6Tex, gEffDust5Tex, gEffDust4Tex, gEffDust3Tex, gEffDust2Tex, gEffDust1Tex, }; PlayState* play = play2; s32 isGfxSetup = false; s32 sp5C = 0; s32 idx; s32 i; OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Xlu(play->state.gfxCtx); for (i = 0; i < 256; i++, arg0++) { if (arg0->isEnabled != 1) { continue; } if (!isGfxSetup) { POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_0); gSPDisplayList(POLY_XLU_DISP++, object_hanareyama_obj_DL_000000); gDPSetEnvColor(POLY_XLU_DISP++, 255, 255, 255, 0); isGfxSetup = true; } Matrix_Push(); arg0->unk_24 = (arg0->unk_01 / (f32)arg0->unk_02) * 255.0f; gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 255, 255, (u8)arg0->unk_24); Matrix_Translate(arg0->unk_0C.x, arg0->unk_0C.y, arg0->unk_0C.z, MTXMODE_NEW); Matrix_Scale(arg0->unk_04, arg0->unk_04, 1.0f, MTXMODE_APPLY); Matrix_ReplaceRotation(&play->billboardMtxF); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); idx = (arg0->unk_01 / (f32)arg0->unk_02) * 8.0f; gSPSegment(POLY_XLU_DISP++, 0x08, Lib_SegmentedToVirtual(sDustTextures[idx])); gSPDisplayList(POLY_XLU_DISP++, object_hanareyama_obj_DL_000020); Matrix_Pop(); sp5C += 1; } CLOSE_DISPS(play->state.gfxCtx); return sp5C; }
1e4ab2e1f0f06ecd8c67f399a53002de624f46e8
7c857119fe1505b1d80d6e62969661c06dc1a2f4
/MdePkg/Include/Protocol/LegacySpiSmmFlash.h
1babbc09ca03c69ab95b63ff99db306e5cdb2a11
[ "BSD-2-Clause" ]
permissive
CloverHackyColor/CloverBootloader
7042ca7dd6b513d22be591a295e49071ae1482ee
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
refs/heads/master
2023-08-30T22:14:34.590134
2023-08-27T19:14:02
2023-08-27T19:14:02
205,810,121
4,734
770
BSD-2-Clause
2023-09-03T12:41:33
2019-09-02T08:22:14
C
UTF-8
C
false
false
823
h
LegacySpiSmmFlash.h
/** @file This file defines the Legacy SPI SMM Flash Protocol. Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @par Revision Reference: This Protocol was introduced in UEFI PI Specification 1.6. **/ #ifndef __LEGACY_SPI_SMM_FLASH_PROTOCOL_H__ #define __LEGACY_SPI_SMM_FLASH_PROTOCOL_H__ #include <Protocol/LegacySpiFlash.h> /// /// Global ID for the Legacy SPI SMM Flash Protocol /// #define EFI_LEGACY_SPI_SMM_FLASH_PROTOCOL_GUID \ { 0x5e3848d4, 0x0db5, 0x4fc0, \ { 0x97, 0x29, 0x3f, 0x35, 0x3d, 0x4f, 0x87, 0x9f }} typedef struct _EFI_LEGACY_SPI_FLASH_PROTOCOL EFI_LEGACY_SPI_SMM_FLASH_PROTOCOL; extern EFI_GUID gEfiLegacySpiSmmFlashProtocolGuid; #endif // __SPI_SMM_FLASH_PROTOCOL_H__
ab65c07545c93b75c74e63ab56f5652eee779d49
1577e1cf4e89584a125cffb855ca50a9654c6d55
/file_cmds/dd/dd.h
6fefbb01c709c1ddc0ac6696e5e41771c0383479
[]
no_license
apple-open-source/macos
a4188b5c2ef113d90281d03cd1b14e5ee52ebffb
2d2b15f13487673de33297e49f00ef94af743a9a
refs/heads/master
2023-08-01T11:03:26.870408
2023-03-27T00:00:00
2023-03-27T00:00:00
180,595,052
124
24
null
2022-12-27T14:54:09
2019-04-10T14:06:23
null
UTF-8
C
false
false
4,805
h
dd.h
/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Keith Muller of the University of California, San Diego and Lance * Visser of Convex Computer Corporation. * * 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. * * @(#)dd.h 8.3 (Berkeley) 4/2/94 * $FreeBSD$ */ #ifndef _DD_H_ #define _DD_H_ /* Input/output stream state. */ typedef struct { u_char *db; /* buffer address */ u_char *dbp; /* current buffer I/O address */ ssize_t dbcnt; /* current buffer byte count */ ssize_t dbrcnt; /* last read byte count */ ssize_t dbsz; /* block size */ #define ISCHR 0x01 /* character device (warn on short) */ #define ISPIPE 0x02 /* pipe-like (see position.c) */ #define ISTAPE 0x04 /* tape */ #define ISSEEK 0x08 /* valid to seek on */ #define NOREAD 0x10 /* not readable */ #define ISTRUNC 0x20 /* valid to ftruncate() */ u_int flags; const char *name; /* name */ int fd; /* file descriptor */ off_t offset; /* # of blocks to skip */ off_t seek_offset; /* offset of last seek past output hole */ } IO; typedef struct { uintmax_t in_full; /* # of full input blocks */ uintmax_t in_part; /* # of partial input blocks */ uintmax_t out_full; /* # of full output blocks */ uintmax_t out_part; /* # of partial output blocks */ uintmax_t trunc; /* # of truncated records */ uintmax_t swab; /* # of odd-length swab blocks */ uintmax_t bytes; /* # of bytes written */ struct timespec start; /* start time of dd */ } STAT; /* Flags (in ddflags). */ #define C_ASCII 0x0000000000000001ULL #define C_BLOCK 0x0000000000000002ULL #define C_BS 0x0000000000000004ULL #define C_CBS 0x0000000000000008ULL #define C_COUNT 0x0000000000000010ULL #define C_EBCDIC 0x0000000000000020ULL #define C_FILES 0x0000000000000040ULL #define C_IBS 0x0000000000000080ULL #define C_IF 0x0000000000000100ULL #define C_LCASE 0x0000000000000200ULL #define C_NOERROR 0x0000000000000400ULL #define C_NOTRUNC 0x0000000000000800ULL #define C_OBS 0x0000000000001000ULL #define C_OF 0x0000000000002000ULL #define C_OSYNC 0x0000000000004000ULL #define C_PAREVEN 0x0000000000008000ULL #define C_PARNONE 0x0000000000010000ULL #define C_PARODD 0x0000000000020000ULL #define C_PARSET 0x0000000000040000ULL #define C_SEEK 0x0000000000080000ULL #define C_SKIP 0x0000000000100000ULL #define C_SPARSE 0x0000000000200000ULL #define C_SWAB 0x0000000000400000ULL #define C_SYNC 0x0000000000800000ULL #define C_UCASE 0x0000000001000000ULL #define C_UNBLOCK 0x0000000002000000ULL #define C_FILL 0x0000000004000000ULL #define C_STATUS 0x0000000008000000ULL #define C_NOXFER 0x0000000010000000ULL #define C_NOINFO 0x0000000020000000ULL #define C_PROGRESS 0x0000000040000000ULL #define C_FSYNC 0x0000000080000000ULL #ifndef __APPLE__ #define C_FDATASYNC 0x0000000100000000ULL #endif #define C_OFSYNC 0x0000000200000000ULL #define C_IFULLBLOCK 0x0000000400000000ULL #define C_IDIRECT 0x0000000800000000ULL #define C_ODIRECT 0x0000001000000000ULL #define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET) #define BISZERO(p, s) ((s) > 0 && *((const char *)p) == 0 && !memcmp( \ (const void *)(p), (const void *) \ ((const char *)p + 1), (s) - 1)) #endif /* _DD_H_ */
262d77b3a1913162993c1dbe2aeb341df8b7570e
8838eb997879add5759b6dfb23f9a646464e53ca
/src/compat/posix/util/swab.c
07864b725d3d1aab765b6ec740607f5fbb82a7ec
[ "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
354
c
swab.c
/** * @file * * @data 18.11.2015 * @author: Anton Bondarev */ #include <unistd.h> void swab(const void *bfrom, void *bto, ssize_t n) { const char *from = (const char *) bfrom; char *to = (char *) bto; n &= ~((ssize_t) 1); while (n > 1) { const char b0 = from[--n], b1 = from[--n]; to[n] = b0; to[n + 1] = b1; } }
0225ee63d99eab132acbdd0c5d7a27e8479ba9e7
f34c3cc5ee087643bf6492afea1503b8f8440869
/drivers/windows/pandaJ2534DLL/constants_ISO15765.h
86928f1436c99663a8c741fa436b54b68624047b
[ "MIT" ]
permissive
commaai/panda
24334163d7c2ee49b5baa854fe355681fd5ceaba
72f1603a89c7fecb6746d0154232f2d8187ebe70
refs/heads/master
2023-09-04T12:48:22.461254
2023-09-01T23:32:08
2023-09-01T23:32:08
87,490,037
1,493
781
MIT
2023-09-14T21:34:19
2017-04-07T01:11:08
C
UTF-8
C
false
false
755
h
constants_ISO15765.h
#pragma once #define msg_is_extaddr(msg) check_bmask(msg->TxFlags, ISO15765_ADDR_TYPE) #define msg_is_padded(msg) check_bmask(msg->TxFlags, ISO15765_FRAME_PAD) #define FRAME_SINGLE 0x00 #define FRAME_FIRST 0x10 #define FRAME_CONSEC 0x20 #define FRAME_FLOWCTRL 0x30 #define FLOWCTRL_CONTINUE 0 #define FLOWCTRL_WAIT 1 #define FLOWCTRL_ABORT 2 #define msg_get_type(msg, addrlen) ((msg).Data[addrlen] & 0xF0) #define is_single(msg, addrlen) (msg_get_type(msg, addrlen) == FRAME_SINGLE) #define is_first(msg, addrlen) (msg_get_type(msg, addrlen) == FRAME_FIRST) #define is_consecutive(msg, addrlen) (msg_get_type(msg, addrlen) == FRAME_CONSEC) #define is_flowctrl(msg, addrlen) (msg_get_type(msg, addrlen) == FRAME_FLOWCTRL)
c54341e709002b38ea3ec3aefc325d088f8287b2
0744dcc5394cebf57ebcba343747af6871b67017
/os/board/rtl8720e/src/component/soc/amebalite/fwlib/include/sysreg_sec.h
e9781ab2fe6819ff07c2abfa84f9c8d4d86774ad
[ "GPL-1.0-or-later", "BSD-3-Clause", "ISC", "MIT", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-other-permissive", "Apache-2.0" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
24,063
h
sysreg_sec.h
#ifndef _AMEBAD2_SEC_H_ #define _AMEBAD2_SEC_H_ /* AUTO_GEN_START */ /** @addtogroup Ameba_Periph_Driver * @{ */ /** @defgroup SEC * @{ */ /* Registers Definitions --------------------------------------------------------*/ /** @defgroup SEC_Register_Definitions SEC Register Definitions * @{ *****************************************************************************/ /** @defgroup SEC_OTP_SYSCFG0 * @brief * @{ **/ #define SEC_MASK_SW_RSVD_1 ((u32)0x00000003 << 30) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD_1(x) ((u32)(((x) & 0x00000003) << 30)) #define SEC_GET_SW_RSVD_1(x) ((u32)(((x >> 30) & 0x00000003))) #define SEC_BIT_BOOT_RAND_DELAY_EN ((u32)0x00000001 << 29) /*!<R/W 0 Enable random boot delay 0: disable 1: enable */ #define SEC_BIT_LOGIC_RDP_EN ((u32)0x00000001 << 28) /*!<R/W 0 RDP enable */ #define SEC_BIT_LOGIC_RSIP_EN ((u32)0x00000001 << 27) /*!<R/W 0 RSIP enable */ #define SEC_BIT_LOGIC_SECURE_BOOT_EN ((u32)0x00000001 << 26) /*!<R/W 0 Secure boot enable */ #define SEC_BIT_LOW_BAUD_LOG_EN ((u32)0x00000001 << 25) /*!<R/W 0 Loguart Baudrate selection 1: 115200bps 0: 1.5Mbps */ #define SEC_BIT_DIS_BOOT_LOG_EN ((u32)0x00000001 << 24) /*!<R/W 0 Boot log disable */ #define SEC_MASK_SW_RSVD_0 ((u32)0x0000000F << 20) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD_0(x) ((u32)(((x) & 0x0000000F) << 20)) #define SEC_GET_SW_RSVD_0(x) ((u32)(((x >> 20) & 0x0000000F))) #define SEC_BIT_BOOT_FLASH_BAUD_SEL ((u32)0x00000001 << 19) /*!<R/W 0 Boot Flash clock selection. Baudrate = 40/(2*(1+x)) 0: 20M 1: 10M */ #define SEC_BIT_SPIC_BOOT_SPEEDUP_DIS ((u32)0x00000001 << 18) /*!<R/W 0 SPIC boot speed up disable */ #define SEC_BIT_SPIC_ADDR_4BYTE_EN ((u32)0x00000001 << 17) /*!<R/W 0 SPIC address 4-byte enable */ #define SEC_BIT_FLASH_DEEP_SLEEP_EN ((u32)0x00000001 << 16) /*!<R/W 0 Flash deepsleep enable */ #define SEC_MASK_OTP_CHIPID1 ((u32)0x000000FF << 8) /*!<R/W 0 OTP autuload data reserved for SW */ #define SEC_OTP_CHIPID1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_OTP_CHIPID1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_OTP_CHIPID0 ((u32)0x000000FF << 0) /*!<R/W 0 OTP autuload data reserved for SW */ #define SEC_OTP_CHIPID0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_OTP_CHIPID0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_OTP_SYSCFG1 * @brief * @{ **/ #define SEC_MASK_SW_RSVD3 ((u32)0x000000FF << 24) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD3(x) ((u32)(((x) & 0x000000FF) << 24)) #define SEC_GET_SW_RSVD3(x) ((u32)(((x >> 24) & 0x000000FF))) #define SEC_MASK_SW_RSVD2 ((u32)0x000000FF << 16) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD2(x) ((u32)(((x) & 0x000000FF) << 16)) #define SEC_GET_SW_RSVD2(x) ((u32)(((x >> 16) & 0x000000FF))) #define SEC_MASK_SW_RSVD1 ((u32)0x000000FF << 8) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_SW_RSVD1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_SW_RSVD0 ((u32)0x000000FF << 0) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_SW_RSVD0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_OTP_SYSCFG2 * @brief * @{ **/ #define SEC_MASK_SW_RSVD4 ((u32)0xFFFFFFFF << 0) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD4(x) ((u32)(((x) & 0xFFFFFFFF) << 0)) #define SEC_GET_SW_RSVD4(x) ((u32)(((x >> 0) & 0xFFFFFFFF))) /** @} */ /** @defgroup SEC_OTP_SYSCFG3 * @brief * @{ **/ #define SEC_MASK_SW_RSVD5 ((u32)0xFFFFFFFF << 0) /*!<R/W 0 RSVD for SW usage */ #define SEC_SW_RSVD5(x) ((u32)(((x) & 0xFFFFFFFF) << 0)) #define SEC_GET_SW_RSVD5(x) ((u32)(((x >> 0) & 0xFFFFFFFF))) /** @} */ /** @defgroup SEC_NEWKEY_HUK_0 * @brief * @{ **/ #define SEC_MASK_HUK_0_3 ((u32)0x000000FF << 24) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_0_3(x) ((u32)(((x) & 0x000000FF) << 24)) #define SEC_GET_HUK_0_3(x) ((u32)(((x >> 24) & 0x000000FF))) #define SEC_MASK_HUK_0_2 ((u32)0x000000FF << 16) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_0_2(x) ((u32)(((x) & 0x000000FF) << 16)) #define SEC_GET_HUK_0_2(x) ((u32)(((x >> 16) & 0x000000FF))) #define SEC_MASK_HUK_0_1 ((u32)0x000000FF << 8) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_0_1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_HUK_0_1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_HUK_0_0 ((u32)0x000000FF << 0) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_0_0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_HUK_0_0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_NEWKEY_HUK_1 * @brief * @{ **/ #define SEC_MASK_HUK_1_3 ((u32)0x000000FF << 24) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_1_3(x) ((u32)(((x) & 0x000000FF) << 24)) #define SEC_GET_HUK_1_3(x) ((u32)(((x >> 24) & 0x000000FF))) #define SEC_MASK_HUK_1_2 ((u32)0x000000FF << 16) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_1_2(x) ((u32)(((x) & 0x000000FF) << 16)) #define SEC_GET_HUK_1_2(x) ((u32)(((x >> 16) & 0x000000FF))) #define SEC_MASK_HUK_1_1 ((u32)0x000000FF << 8) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_1_1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_HUK_1_1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_HUK_1_0 ((u32)0x000000FF << 0) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_1_0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_HUK_1_0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_NEWKEY_HUK_2 * @brief * @{ **/ #define SEC_MASK_HUK_2_3 ((u32)0x000000FF << 24) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_2_3(x) ((u32)(((x) & 0x000000FF) << 24)) #define SEC_GET_HUK_2_3(x) ((u32)(((x >> 24) & 0x000000FF))) #define SEC_MASK_HUK_2_2 ((u32)0x000000FF << 16) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_2_2(x) ((u32)(((x) & 0x000000FF) << 16)) #define SEC_GET_HUK_2_2(x) ((u32)(((x >> 16) & 0x000000FF))) #define SEC_MASK_HUK_2_1 ((u32)0x000000FF << 8) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_2_1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_HUK_2_1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_HUK_2_0 ((u32)0x000000FF << 0) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_2_0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_HUK_2_0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_NEWKEY_HUK_3 * @brief * @{ **/ #define SEC_MASK_HUK_3_3 ((u32)0x000000FF << 24) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_3_3(x) ((u32)(((x) & 0x000000FF) << 24)) #define SEC_GET_HUK_3_3(x) ((u32)(((x >> 24) & 0x000000FF))) #define SEC_MASK_HUK_3_2 ((u32)0x000000FF << 16) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_3_2(x) ((u32)(((x) & 0x000000FF) << 16)) #define SEC_GET_HUK_3_2(x) ((u32)(((x >> 16) & 0x000000FF))) #define SEC_MASK_HUK_3_1 ((u32)0x000000FF << 8) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_3_1(x) ((u32)(((x) & 0x000000FF) << 8)) #define SEC_GET_HUK_3_1(x) ((u32)(((x >> 8) & 0x000000FF))) #define SEC_MASK_HUK_3_0 ((u32)0x000000FF << 0) /*!<PROT/RMSK1 8'hff */ #define SEC_HUK_3_0(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_HUK_3_0(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_CFG1 * @brief * @{ **/ #define SEC_BIT_SWD_PWD_EN ((u32)0x00000001 << 0) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_DBGEN ((u32)0x00000001 << 1) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_NIDEN ((u32)0x00000001 << 2) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_SPIDEN ((u32)0x00000001 << 3) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_SPNIDEN ((u32)0x00000001 << 4) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_PWD_R_PROTECTION_EN ((u32)0x00000001 << 5) /*!<PROT 1'b1 */ #define SEC_BIT_SWD_PWD_W_FORBIDDEN_EN ((u32)0x00000001 << 6) /*!<PROT 1'b1 */ #define SEC_BIT_HUK_W_FORBIDDEN_EN ((u32)0x00000001 << 7) /*!<PROT 1'b1 */ #define SEC_BIT_PK1_W_FORBIDDEN_EN ((u32)0x00000001 << 9) /*!<PROT 1'b1 */ #define SEC_BIT_PK2_W_FORBIDDEN_EN ((u32)0x00000001 << 10) /*!<PROT 1'b1 */ #define SEC_BIT_S_IPSEC_KEY1_R_PROTECTION_EN ((u32)0x00000001 << 11) /*!<PROT 1'b1 */ #define SEC_BIT_S_IPSEC_KEY1_W_FORBIDDEN_EN ((u32)0x00000001 << 12) /*!<PROT 1'b1 */ #define SEC_BIT_S_IPSEC_KEY2_R_PROTECTION_EN ((u32)0x00000001 << 13) /*!<PROT 1'b1 */ #define SEC_BIT_S_IPSEC_KEY2_W_FORBIDDEN_EN ((u32)0x00000001 << 14) /*!<PROT 1'b1 */ #define SEC_BIT_NS_IPSEC_KEY1_R_PROTECTION_EN ((u32)0x00000001 << 15) /*!<PROT 1'b1 */ #define SEC_BIT_NS_IPSEC_KEY1_W_FORBIDDEN_EN ((u32)0x00000001 << 16) /*!<PROT 1'b1 */ #define SEC_BIT_NS_IPSEC_KEY2_R_PROTECTION_EN ((u32)0x00000001 << 17) /*!<PROT 1'b1 */ #define SEC_BIT_NS_IPSEC_KEY2_W_FORBIDDEN_EN ((u32)0x00000001 << 18) /*!<PROT 1'b1 */ #define SEC_BIT_ECDSA_PRI_KEY1_R_PROTECTION_EN ((u32)0x00000001 << 19) /*!<PROT 1'b1 */ #define SEC_BIT_ECDSA_PRI_KEY1_W_FORBIDDEN_EN ((u32)0x00000001 << 20) /*!<PROT 1'b1 */ #define SEC_BIT_ECDSA_PRI_KEY2_R_PROTECTION_EN ((u32)0x00000001 << 21) /*!<PROT 1'b1 */ #define SEC_BIT_ECDSA_PRI_KEY2_W_FORBIDDEN_EN ((u32)0x00000001 << 22) /*!<PROT 1'b1 */ #define SEC_BIT_RSIP_KEY1_R_PROTECTION_EN ((u32)0x00000001 << 23) /*!<PROT 1'b1 */ #define SEC_BIT_RSIP_KEY1_W_FORBIDDEN_EN ((u32)0x00000001 << 24) /*!<PROT 1'b1 */ #define SEC_BIT_RSIP_KEY2_R_PROTECTION_EN ((u32)0x00000001 << 25) /*!<PROT 1'b1 */ #define SEC_BIT_RSIP_KEY2_W_FORBIDDEN_EN ((u32)0x00000001 << 26) /*!<PROT 1'b1 */ #define SEC_BIT_RSIP_MODE_W_FORBIDDEN_EN ((u32)0x00000001 << 27) /*!<PROT 1'b1 */ #define SEC_BIT_SIC_SECURE_EN ((u32)0x00000001 << 28) /*!<PROT 1'b1 */ #define SEC_BIT_CPU_PC_DBG_EN ((u32)0x00000001 << 29) /*!<PROT 1'b1 */ #define SEC_BIT_UDF1_TRUSTZONE_EN ((u32)0x00000001 << 30) /*!<PROT 1'b1 */ #define SEC_BIT_UDF2_TRUSTZONE_EN ((u32)0x00000001 << 31) /*!<PROT 1'b1 */ /** @} */ /** @defgroup SEC_CFG2 * @brief * @{ **/ #define SEC_BIT_UART_DOWNLOAD_DISABLE ((u32)0x00000001 << 0) /*!<PROT/R 1'b1 */ #define SEC_BIT_RSIP_EN ((u32)0x00000001 << 2) /*!<PROT/R 1'b1 */ #define SEC_BIT_SECURE_BOOT_EN ((u32)0x00000001 << 3) /*!<PROT/R 1'b1 */ #define SEC_BIT_SECURE_BOOT_HW_DIS ((u32)0x00000001 << 4) /*!<PROT/R 1'b1 */ #define SEC_BIT_RDP_EN ((u32)0x00000001 << 5) /*!<PROT/R 1'b1 */ #define SEC_BIT_ANTI_ROLLBACK_EN ((u32)0x00000001 << 6) /*!<PROT/R 1'b1 */ #define SEC_BIT_FAULT_LOG_PRINT_DIS ((u32)0x00000001 << 7) /*!<PROT/R 1'b1 */ #define SEC_MASK_RSIP_MODE ((u32)0x00000003 << 8) /*!<PROT/R 2'b11 */ #define SEC_RSIP_MODE(x) ((u32)(((x) & 0x00000003) << 8)) #define SEC_GET_RSIP_MODE(x) ((u32)(((x >> 8) & 0x00000003))) #define SEC_BIT_HUK_DERIV_EN ((u32)0x00000001 << 10) /*!<PROT/R 1'b1 */ #define SEC_MASK_CFG_RSVD1 ((u32)0x0000001F << 11) /*!<PROT/R 5'h1f */ #define SEC_CFG_RSVD1(x) ((u32)(((x) & 0x0000001F) << 11)) #define SEC_GET_CFG_RSVD1(x) ((u32)(((x >> 11) & 0x0000001F))) #define SEC_MASK_BOOTLOADER_VERSION ((u32)0x0000FFFF << 16) /*!<PROT/R 16'hff */ #define SEC_BOOTLOADER_VERSION(x) ((u32)(((x) & 0x0000FFFF) << 16)) #define SEC_GET_BOOTLOADER_VERSION(x) ((u32)(((x >> 16) & 0x0000FFFF))) /** @} */ /** @defgroup SEC_RMA * @brief * @{ **/ #define SEC_MASK_RMA_DATA ((u32)0x000000FF << 0) /*!<PROT/R 8'hff If the number of 1 is odd, it will goto RMA state. */ #define SEC_RMA_DATA(x) ((u32)(((x) & 0x000000FF) << 0)) #define SEC_GET_RMA_DATA(x) ((u32)(((x >> 0) & 0x000000FF))) /** @} */ /** @defgroup SEC_ROM_PATCH * @brief * @{ **/ #define SEC_MASK_ROM_PATCH_PG ((u32)0x00000003 << 0) /*!<PROT/R 2'b11 ROM patch enable.This Bit will programed by FT if ROM patch do not needed */ #define SEC_ROM_PATCH_PG(x) ((u32)(((x) & 0x00000003) << 0)) #define SEC_GET_ROM_PATCH_PG(x) ((u32)(((x >> 0) & 0x00000003))) #define SEC_BIT_ROM_PATCH_LWE ((u32)0x00000001 << 2) /*!<PROT/R 1'b1 ROM patch write protection (protect Low 2Kbits) */ #define SEC_BIT_ROM_PATCH_HWE ((u32)0x00000001 << 3) /*!<PROT/R 1'b1 ROM patch write protection (protect High 2Kbits) */ #define SEC_MASK_OTP_RSVD ((u32)0x0000000F << 4) /*!<PROT/R 4'hf RSVD for further use */ #define SEC_OTP_RSVD(x) ((u32)(((x) & 0x0000000F) << 4)) #define SEC_GET_OTP_RSVD(x) ((u32)(((x >> 4) & 0x0000000F))) /** @} */ /** @defgroup SEC_CFG3 * @brief * @{ **/ #define SEC_BIT_RMA_SWD_PWD_R_PROTECTION_EN ((u32)0x00000001 << 0) /*!<PROT 1'b1 */ #define SEC_BIT_RMA_SWD_PWD_W_FORBIDDEN_EN ((u32)0x00000001 << 1) /*!<PROT 1'b1 */ #define SEC_BIT_RMA_PK_W_FORBIDDEN_EN ((u32)0x00000001 << 2) /*!<PROT 1'b1 */ #define SEC_MASK_OTP_RSVD0 ((u32)0x0000001F << 3) /*!<PROT 5'h1f */ #define SEC_OTP_RSVD0(x) ((u32)(((x) & 0x0000001F) << 3)) #define SEC_GET_OTP_RSVD0(x) ((u32)(((x >> 3) & 0x0000001F))) /** @} */ /*==========SEC Register Address Definition==========*/ #define SEC_OTP_SYSCFG0 0x0100 #define SEC_OTP_SYSCFG1 0x0104 #define SEC_OTP_SYSCFG2 0x0108 #define SEC_OTP_SYSCFG3 0x010C #define SEC_KEY_S_IPSEC1_0 0x0200 #define SEC_KEY_S_IPSEC1_1 0x0204 #define SEC_KEY_S_IPSEC1_2 0x0208 #define SEC_KEY_S_IPSEC1_3 0x020C #define SEC_KEY_S_IPSEC1_4 0x0210 #define SEC_KEY_S_IPSEC1_5 0x0214 #define SEC_KEY_S_IPSEC1_6 0x0218 #define SEC_KEY_S_IPSEC1_7 0x021C #define SEC_KEY_S_IPSEC2_0 0x0220 #define SEC_KEY_S_IPSEC2_1 0x0224 #define SEC_KEY_S_IPSEC2_2 0x0228 #define SEC_KEY_S_IPSEC2_3 0x022C #define SEC_KEY_S_IPSEC2_4 0x0230 #define SEC_KEY_S_IPSEC2_5 0x0234 #define SEC_KEY_S_IPSEC2_6 0x0238 #define SEC_KEY_S_IPSEC2_7 0x023C #define SEC_KEY_NS_IPSEC1_0 0x0240 #define SEC_KEY_NS_IPSEC1_1 0x0244 #define SEC_KEY_NS_IPSEC1_2 0x0248 #define SEC_KEY_NS_IPSEC1_3 0x024C #define SEC_KEY_NS_IPSEC1_4 0x0250 #define SEC_KEY_NS_IPSEC1_5 0x0254 #define SEC_KEY_NS_IPSEC1_6 0x0258 #define SEC_KEY_NS_IPSEC1_7 0x025C #define SEC_KEY_NS_IPSEC2_0 0x0260 #define SEC_KEY_NS_IPSEC2_1 0x0264 #define SEC_KEY_NS_IPSEC2_2 0x0268 #define SEC_KEY_NS_IPSEC2_3 0x026C #define SEC_KEY_NS_IPSEC2_4 0x0270 #define SEC_KEY_NS_IPSEC2_5 0x0274 #define SEC_KEY_NS_IPSEC2_6 0x0278 #define SEC_KEY_NS_IPSEC2_7 0x027C #define SEC_KEY_ECDSA_PRI1_0 0x0280 #define SEC_KEY_ECDSA_PRI1_1 0x0284 #define SEC_KEY_ECDSA_PRI1_2 0x0288 #define SEC_KEY_ECDSA_PRI1_3 0x028C #define SEC_KEY_ECDSA_PRI1_4 0x0290 #define SEC_KEY_ECDSA_PRI1_5 0x0294 #define SEC_KEY_ECDSA_PRI1_6 0x0298 #define SEC_KEY_ECDSA_PRI1_7 0x029C #define SEC_KEY_ECDSA_PRI2_0 0x02A0 #define SEC_KEY_ECDSA_PRI2_1 0x02A4 #define SEC_KEY_ECDSA_PRI2_2 0x02A8 #define SEC_KEY_ECDSA_PRI2_3 0x02AC #define SEC_KEY_ECDSA_PRI2_4 0x02B0 #define SEC_KEY_ECDSA_PRI2_5 0x02B4 #define SEC_KEY_ECDSA_PRI2_6 0x02B8 #define SEC_KEY_ECDSA_PRI2_7 0x02BC #define SEC_KEY_RSIP_ECB_0 0x02C0 #define SEC_KEY_RSIP_ECB_1 0x02C4 #define SEC_KEY_RSIP_ECB_2 0x02C8 #define SEC_KEY_RSIP_ECB_3 0x02CC #define SEC_KEY_RSIP_ECB_4 0x02D0 #define SEC_KEY_RSIP_ECB_5 0x02D4 #define SEC_KEY_RSIP_ECB_6 0x02D8 #define SEC_KEY_RSIP_ECB_7 0x02DC #define SEC_KEY_RSIP_CTR_0 0x02E0 #define SEC_KEY_RSIP_CTR_1 0x02E4 #define SEC_KEY_RSIP_CTR_2 0x02E8 #define SEC_KEY_RSIP_CTR_3 0x02EC #define SEC_KEY_RSIP_CTR_4 0x02F0 #define SEC_KEY_RSIP_CTR_5 0x02F4 #define SEC_KEY_RSIP_CTR_6 0x02F8 #define SEC_KEY_RSIP_CTR_7 0x02FC #define SEC_KEY_SWD_PWD_0 0x0300 #define SEC_KEY_SWD_PWD_1 0x0304 #define SEC_KEY_SWD_PWD_2 0x0308 #define SEC_KEY_SWD_PWD_3 0x030C #define SEC_NEWKEY_HUK_0 0x0310 #define SEC_NEWKEY_HUK_1 0x0314 #define SEC_NEWKEY_HUK_2 0x0318 #define SEC_NEWKEY_HUK_3 0x031C #define SEC_PKKEY_PK1_0 0x0320 #define SEC_PKKEY_PK1_1 0x0324 #define SEC_PKKEY_PK1_2 0x0328 #define SEC_PKKEY_PK1_3 0x032C #define SEC_PKKEY_PK1_4 0x0330 #define SEC_PKKEY_PK1_5 0x0334 #define SEC_PKKEY_PK1_6 0x0338 #define SEC_PKKEY_PK1_7 0x033C #define SEC_PKKEY_PK2_0 0x0340 #define SEC_PKKEY_PK2_1 0x0344 #define SEC_PKKEY_PK2_2 0x0348 #define SEC_PKKEY_PK2_3 0x034C #define SEC_PKKEY_PK2_4 0x0350 #define SEC_PKKEY_PK2_5 0x0354 #define SEC_PKKEY_PK2_6 0x0358 #define SEC_PKKEY_PK2_7 0x035C #define SEC_CFG0 0x0360 #define SEC_CFG1 0x0364 #define SEC_CFG2 0x0368 #define SEC_OTA_ADDR 0x036C #define SEC_CRC0 0x0370 #define SEC_CRC1 0x0374 #define SEC_CRC2 0x0378 #define SEC_CRC3 0x037C #define SEC_RMA 0x0700 #define SEC_ROM_PATCH 0x0701 #define SEC_CFG3 0x0702 #define SEC_SWD_RMA_PWD_0 0x0710 #define SEC_SWD_RMA_PWD_1 0x0714 #define SEC_SWD_RMA_PWD_2 0x0718 #define SEC_SWD_RMA_PWD_3 0x071C #define SEC_PKKEY_RMA_PK_0 0x0720 #define SEC_PKKEY_RMA_PK_1 0x0724 #define SEC_PKKEY_RMA_PK_2 0x0728 #define SEC_PKKEY_RMA_PK_3 0x072C #define SEC_PKKEY_RMA_PK_4 0x0730 #define SEC_PKKEY_RMA_PK_5 0x0734 #define SEC_PKKEY_RMA_PK_6 0x0738 #define SEC_PKKEY_RMA_PK_7 0x073C #define SEC_OTP_DUMMY 0x0740 /** @} */ /* AUTO_GEN_END */ /* MANUAL_GEN_START */ //Please add your defination here /*==========SWR Calibration Register Address Definition==========*/ #define SEC_VOL_AUDIO_VREF_1V8_F 0x7DE #define SEC_VOL_AUDIO_VREF_1V8_S 0x7DF #define SEC_VOL_SWR_PFM_125 0x7E0 #define SEC_VOL_SWR_PWM_135 0x7E1 #define SEC_VOL_SWR_PFM_09 0x7E2 #define SEC_VOL_SWR_PWM_10 0x7E3 #define SEC_VOL_AON_LDO_09 0x7E4 #define SEC_VOL_CORE_LDO_10 0x7E5 #define SEC_VOL_ANA_LDO_180 0x7E6 /** @} */ #define SEC_BOOT_ALG (SEC_CFG2 + 3) #define SEC_GET_AUTH_ALG(x) ((u8)((x) & 0x0F)) #define SEC_GET_HASH_ALG(x) ((u8)((x >> 4) & 0x0F)) #define SEC_BOOT_IMGVER0 (SEC_OTA_ADDR + 2) #define SEC_ROM_PATCH_DIS 0 #define SEC_ROM_PATCH_EMPTY 3 #define SEC_BIT_SWTRIG_UART_DOWNLOAD_DISABLE ((u32)0x00000001 << 11) /* MANUAL_GEN_END */ #endif /** @} */ /** @} */
25f90341281abc280e6765347393f70f27043729
3f2489ba277fb3e414884eb5f0051175e9702edf
/asf/http/asf_http_requestinterface.c
1608e2f805c9dc374e1048ea5242c8fdcb779979
[ "PHP-3.01" ]
permissive
yulonghu/asf
1790ddbc170960d2e03999835970de60f074f855
5542977fa5bd973b79c8750cd8e862bc02ec0ea9
refs/heads/master
2022-09-04T21:54:29.766735
2021-12-21T15:02:23
2021-12-21T15:02:23
132,080,229
291
14
NOASSERTION
2020-04-10T23:17:09
2018-05-04T03:18:55
C
UTF-8
C
false
false
4,282
c
asf_http_requestinterface.c
/* +----------------------------------------------------------------------+ | API Services Framework | +----------------------------------------------------------------------+ | Copyright (c) 1997-2018 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Jiapeng Fan <fanjiapeng@126.com> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_asf.h" #include "kernel/asf_namespace.h" #include "asf_exception.h" #include "http/asf_http_requestinterface.h" zend_class_entry *asf_http_requestinterface_ce; /* {{{ asf_http_requestinterface_methods */ zend_function_entry asf_http_requestinterface_methods[] = { /* The prefix is the has method for HTTP REQUEST */ PHP_ABSTRACT_ME(asf_http_requestinterface, isGet, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isPost, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isPut, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isDelete, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isPatch, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isHead, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isOptions, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isCli, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isXmlHttpRequest,NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isTrace, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isConnect, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isFlashRequest, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, isPropFind, NULL) /* HTTP REQUEST */ PHP_ABSTRACT_ME(asf_http_requestinterface, getParam, asf_http_requestinterface_get_param_arginfo) PHP_ABSTRACT_ME(asf_http_requestinterface, getParams, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getModuleName, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getServiceName, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getActionName, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getMethod, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getBaseUri, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getRequestUri, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getQuery, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getPost, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getRequest, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getFiles, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getCookie, NULL) PHP_ABSTRACT_ME(asf_http_requestinterface, getServer, asf_http_requestinterface_getserver_arginfo) PHP_ABSTRACT_ME(asf_http_requestinterface, getEnv, asf_http_requestinterface_getenv_arginfo) /* The prefix is the has method for $_REQUEST */ PHP_ABSTRACT_ME(asf_http_requestinterface, hasPost, asf_http_requestinterface_hasname_arginfo) PHP_ABSTRACT_ME(asf_http_requestinterface, hasQuery, asf_http_requestinterface_hasname_arginfo) PHP_ABSTRACT_ME(asf_http_requestinterface, hasServer, asf_http_requestinterface_hasname_arginfo) PHP_ABSTRACT_ME(asf_http_requestinterface, hasFiles, asf_http_requestinterface_hasname_arginfo) PHP_FE_END }; /* }}} */ ASF_INIT_CLASS(http_requestinterface) /* {{{ */ { ASF_REGISTER_CLASS_INTERFACE(asf_http_requestinterface, asf_Http_RequestInterface, Asf\\Http\\RequestInterface); return SUCCESS; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */
61943781ea5dc1f2175b2102801cbfbff0b05d51
1db673907c7946c2ea857cc9aa8b6f7f4060e36a
/Chapter/14_DLL/Test/SkyTest.h
a133c132801918c2439ad2d33702bd69e19b27da
[ "BSD-3-Clause" ]
permissive
pdpdds/SkyOS
a973cd9f1b4e541ae4ac26d19df29aa3f4110db3
db2ce044c581fc2dfe068723fb0be2336c7f18d9
refs/heads/master
2023-07-21T15:24:46.457637
2023-07-17T16:32:04
2023-07-17T16:32:04
97,029,119
160
49
null
2023-04-30T15:33:47
2017-07-12T16:23:01
C
WINDOWS-1252
C
false
false
376
h
SkyTest.h
#pragma once void TestInterrupt(); void TestCPlusPlus(); void TestMap(); void Testlist(); void TestCommonLibrary(); void TestString(); //ÀúÀåÀåÄ¡ void TestStorage(const char* filename, char driveLetter); void TestFPU(); void TestTryCatch(); void TestNullPointer(); void TestLua(); void TestEasyZLib(); bool TestMemoryModule(const char* moduleName);
b7f8b66eabe1543ed6f239ed8a1cba9d3be9dae6
37a907f462060ac992a822fd2ec74713411ea7bc
/examples/boolops/ex7.c
ff7840724ed2571d361113e5e81560e0687f657d
[ "MIT" ]
permissive
nlsandler/nqcc
b5c8f8318f09d68c6cc3900adf892b74c8f90255
c95ad9ecaf83c18c904c7010de35adeff0622d75
refs/heads/master
2023-08-16T16:03:19.687040
2022-07-14T17:07:16
2022-07-14T17:07:16
107,458,133
265
30
MIT
2018-09-09T15:52:34
2017-10-18T20:16:06
OCaml
UTF-8
C
false
false
31
c
ex7.c
int main() { return 2==2; }
087b5f7d2c13c697abf66c4f4ac536cd3043779e
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/Additions/common/crOpenGL/wgl.c
dcc38ba73daa48bf9d11cead86cf90ca0b0ce9ba
[ "MIT", "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" ]
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
29,690
c
wgl.c
/* Copyright (c) 2001, Stanford University * All rights reserved * * See the file LICENSE.txt for information on redistributing this software. */ #include "cr_error.h" #include "cr_spu.h" #include "cr_mem.h" #include "stub.h" /* I *know* most of the parameters are unused, dammit. */ #pragma warning( disable: 4100 ) #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <stdio.h> #include <iprt/cdefs.h> #include <iprt/env.h> /* Currently host part will misbehave re-creating context with proper visual bits * if contexts with alternative visual bits is requested. * For now we just report a superset of all visual bits to avoid that. * Better to it on the host side as well? * We could also implement properly multiple pixel formats, * which should be done by implementing offscreen rendering or multiple host contexts. * */ #define VBOX_CROGL_USE_VBITS_SUPERSET #ifdef VBOX_CROGL_USE_VBITS_SUPERSET static GLuint desiredVisual = CR_RGB_BIT | CR_ALPHA_BIT | CR_DEPTH_BIT | CR_STENCIL_BIT | CR_ACCUM_BIT | CR_DOUBLE_BIT; #else static GLuint desiredVisual = CR_RGB_BIT; #endif #ifndef VBOX_CROGL_USE_VBITS_SUPERSET /** * Compute a mask of CR_*_BIT flags which reflects the attributes of * the pixel format of the given hdc. */ static GLuint ComputeVisBits( HDC hdc ) { PIXELFORMATDESCRIPTOR pfd; int iPixelFormat; GLuint b = 0; iPixelFormat = GetPixelFormat( hdc ); DescribePixelFormat( hdc, iPixelFormat, sizeof(pfd), &pfd ); if (pfd.cDepthBits > 0) b |= CR_DEPTH_BIT; if (pfd.cAccumBits > 0) b |= CR_ACCUM_BIT; if (pfd.cColorBits > 8) b |= CR_RGB_BIT; if (pfd.cStencilBits > 0) b |= CR_STENCIL_BIT; if (pfd.cAlphaBits > 0) b |= CR_ALPHA_BIT; if (pfd.dwFlags & PFD_DOUBLEBUFFER) b |= CR_DOUBLE_BIT; if (pfd.dwFlags & PFD_STEREO) b |= CR_STEREO_BIT; return b; } #endif DECLEXPORT(int) WINAPI wglChoosePixelFormat_prox( HDC hdc, CONST PIXELFORMATDESCRIPTOR *pfd ) { DWORD okayFlags; CR_DDI_PROLOGUE(); stubInit(); /* * NOTE!!! * Here we're telling the renderspu not to use the GDI * equivalent's of ChoosePixelFormat/DescribePixelFormat etc * There are subtle differences in the use of these calls. */ RTEnvSet("CR_WGL_DO_NOT_USE_GDI", "yes"); if ( pfd->nSize != sizeof(*pfd) || pfd->nVersion != 1 ) { crError( "wglChoosePixelFormat: bad pfd\n" ); return 0; } okayFlags = ( PFD_DRAW_TO_WINDOW | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DOUBLEBUFFER_DONTCARE | PFD_SWAP_EXCHANGE | PFD_SWAP_COPY | /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ // PFD_STEREO | PFD_STEREO_DONTCARE | PFD_DEPTH_DONTCARE ); if ( pfd->dwFlags & ~okayFlags ) { crWarning( "wglChoosePixelFormat: only support flags=0x%x, but you gave me flags=0x%x", okayFlags, pfd->dwFlags ); return 0; } if ( pfd->iPixelType != PFD_TYPE_RGBA ) { crError( "wglChoosePixelFormat: only support RGBA\n" ); } if ( pfd->cColorBits > 32 || pfd->cRedBits > 8 || pfd->cGreenBits > 8 || pfd->cBlueBits > 8 || pfd->cAlphaBits > 8 ) { crWarning( "wglChoosePixelFormat: too much color precision requested\n" ); } if ( pfd->dwFlags & PFD_DOUBLEBUFFER ) desiredVisual |= CR_DOUBLE_BIT; if ( pfd->dwFlags & PFD_STEREO ) desiredVisual |= CR_STEREO_BIT; if ( pfd->cColorBits > 8) desiredVisual |= CR_RGB_BIT; if ( pfd->cAccumBits > 0 || pfd->cAccumRedBits > 0 || pfd->cAccumGreenBits > 0 || pfd->cAccumBlueBits > 0 || pfd->cAccumAlphaBits > 0 ) { crWarning( "wglChoosePixelFormat: asked for accumulation buffer, ignoring\n" ); } if ( pfd->cAccumBits > 0 ) desiredVisual |= CR_ACCUM_BIT; if ( pfd->cDepthBits > 32 ) { crError( "wglChoosePixelFormat; asked for too many depth bits\n" ); } if ( pfd->cDepthBits > 0 ) desiredVisual |= CR_DEPTH_BIT; if ( pfd->cStencilBits > 8 ) { crError( "wglChoosePixelFormat: asked for too many stencil bits\n" ); } if ( pfd->cStencilBits > 0 ) desiredVisual |= CR_STENCIL_BIT; if ( pfd->cAuxBuffers > 0 ) { crError( "wglChoosePixelFormat: asked for aux buffers\n" ); } if ( pfd->iLayerType != PFD_MAIN_PLANE ) { crError( "wglChoosePixelFormat: asked for a strange layer\n" ); } return 1; } DECLEXPORT(BOOL) WINAPI wglSetPixelFormat_prox( HDC hdc, int pixelFormat, CONST PIXELFORMATDESCRIPTOR *pdf ) { CR_DDI_PROLOGUE(); if ( pixelFormat != 1 ) { crError( "wglSetPixelFormat: pixelFormat=%d?\n", pixelFormat ); } return 1; } DECLEXPORT(BOOL) WINAPI wglDeleteContext_prox( HGLRC hglrc ) { CR_DDI_PROLOGUE(); stubDestroyContext( (unsigned long) hglrc ); return 1; } DECLEXPORT(BOOL) WINAPI wglMakeCurrent_prox( HDC hdc, HGLRC hglrc ) { ContextInfo *context; WindowInfo *window; BOOL ret; CR_DDI_PROLOGUE(); crHashtableLock(stub.windowTable); crHashtableLock(stub.contextTable); context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc); window = stubGetWindowInfo(hdc); if (hglrc!=0 && !context) { crWarning("wglMakeCurrent got unexpected hglrc 0x%x", hglrc); } ret = stubMakeCurrent( window, context ); crHashtableUnlock(stub.contextTable); crHashtableUnlock(stub.windowTable); return ret; } DECLEXPORT(HGLRC) WINAPI wglGetCurrentContext_prox( void ) { ContextInfo *context = stubGetCurrentContext(); CR_DDI_PROLOGUE(); return (HGLRC) (context ? context->id : 0); } DECLEXPORT(HDC) WINAPI wglGetCurrentDC_prox( void ) { ContextInfo *context = stubGetCurrentContext(); CR_DDI_PROLOGUE(); if (context && context->currentDrawable) return (HDC) context->currentDrawable->drawable; else return (HDC) NULL; } DECLEXPORT(int) WINAPI wglGetPixelFormat_prox( HDC hdc ) { CR_DDI_PROLOGUE(); /* this is what we call our generic pixelformat, regardless of the HDC */ return 1; } DECLEXPORT(int) WINAPI wglDescribePixelFormat_prox( HDC hdc, int pixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR pfd ) { CR_DDI_PROLOGUE(); /* if ( pixelFormat != 1 ) { * crError( "wglDescribePixelFormat: pixelFormat=%d?\n", pixelFormat ); * return 0; * } */ if ( !pfd ) { crWarning( "wglDescribePixelFormat: pfd=NULL\n" ); return 1; /* There's only one, baby */ } if ( nBytes != sizeof(*pfd) ) { crWarning( "wglDescribePixelFormat: nBytes=%u?\n", nBytes ); return 1; /* There's only one, baby */ } pfd->nSize = sizeof(*pfd); pfd->nVersion = 1; pfd->dwFlags = ( PFD_DRAW_TO_WINDOW | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER ); pfd->iPixelType = PFD_TYPE_RGBA; pfd->cColorBits = 32; pfd->cRedBits = 8; pfd->cRedShift = 24; pfd->cGreenBits = 8; pfd->cGreenShift = 16; pfd->cBlueBits = 8; pfd->cBlueShift = 8; pfd->cAlphaBits = 8; pfd->cAlphaShift = 0; pfd->cAccumBits = 0; pfd->cAccumRedBits = 0; pfd->cAccumGreenBits = 0; pfd->cAccumBlueBits = 0; pfd->cAccumAlphaBits = 0; pfd->cDepthBits = 32; pfd->cStencilBits = 8; pfd->cAuxBuffers = 0; pfd->iLayerType = PFD_MAIN_PLANE; pfd->bReserved = 0; pfd->dwLayerMask = 0; pfd->dwVisibleMask = 0; pfd->dwDamageMask = 0; /* the max PFD index */ return 1; } DECLEXPORT(void) WINAPI VBoxCtxChromiumParameteriCR(HGLRC hglrc, GLenum param, GLint value) { ContextInfo *context; CR_DDI_PROLOGUE(); // crHashtableLock(stub.windowTable); crHashtableLock(stub.contextTable); context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc); if (context) { stubCtxCheckCreate(context); stubConChromiumParameteriCR(CR_CTX_CON(context), param, value); } else crWarning("invalid context %#x", hglrc); crHashtableUnlock(stub.contextTable); // crHashtableUnlock(stub.windowTable); } DECLEXPORT(BOOL) WINAPI wglShareLists_prox( HGLRC hglrc1, HGLRC hglrc2 ) { ContextInfo *context1, *context2; GLint aSpuContexts[2]; CR_DDI_PROLOGUE(); // crHashtableLock(stub.windowTable); crHashtableLock(stub.contextTable); context1 = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc1); if (!context1) { WARN(("invalid hglrc1")); return FALSE; } stubCtxCheckCreate(context1); context2 = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc2); if (!context2) { WARN(("invalid hglrc2")); return FALSE; } stubCtxCheckCreate(context2); aSpuContexts[0] = context1->spuContext; aSpuContexts[1] = context2->spuContext; stubConChromiumParametervCR(CR_CTX_CON(context2), GL_SHARE_LISTS_CR, GL_INT, 2, aSpuContexts); crHashtableUnlock(stub.contextTable); return TRUE; } DECLEXPORT(HGLRC) WINAPI VBoxCreateContext( HDC hdc, struct VBOXUHGSMI *pHgsmi ) { char *dpyName; ContextInfo *context; CR_DDI_PROLOGUE(); stubInit(); CRASSERT(stub.contextTable); dpyName = crCalloc(MAX_DPY_NAME); if (dpyName) { crMemset(dpyName, 0, MAX_DPY_NAME); sprintf(dpyName, "%p", hdc); } #ifndef VBOX_CROGL_USE_VBITS_SUPERSET if (stub.haveNativeOpenGL) desiredVisual |= ComputeVisBits( hdc ); #endif context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , pHgsmi #else , NULL #endif ); /* Not needed any more. */ crFree(dpyName); if (!context) return 0; return (HGLRC) context->id; } DECLEXPORT(GLint) WINAPI VBoxGetWindowId( HDC hdc ) { WindowInfo *window; GLint winid = 0; CR_DDI_PROLOGUE(); crHashtableLock(stub.windowTable); window = stubGetWindowInfo(hdc); if (!window) { crWarning("stubGetWindowInfo: window not found!"); goto end; } if (!window->spuWindow) { crWarning("stubGetWindowInfo: window is null!"); goto end; } winid = window->spuWindow; end: crHashtableUnlock(stub.windowTable); return winid; } DECLEXPORT(GLint) WINAPI VBoxGetContextId( HGLRC hglrc ) { ContextInfo *context; GLint ctxid = 0; CR_DDI_PROLOGUE(); // crHashtableLock(stub.windowTable); crHashtableLock(stub.contextTable); context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc); if (!context) { crWarning("crHashtableSearch: context not found!"); goto end; } if (context->type != CHROMIUM) { crWarning("unexpected context type %d", context->type); goto end; } if (context->spuContext <= 0) { crWarning("no spuSontext defined"); goto end; } ctxid = context->spuContext; end: crHashtableUnlock(stub.contextTable); return ctxid; } DECLEXPORT(HGLRC) WINAPI wglCreateContext_prox( HDC hdc ) { return VBoxCreateContext(hdc, NULL); } DECLEXPORT(void) WINAPI VBoxFlushToHost ( HGLRC hglrc ) { ContextInfo *context; CR_DDI_PROLOGUE(); // crHashtableLock(stub.windowTable); crHashtableLock(stub.contextTable); context = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) hglrc); if (context) stubConFlush(CR_CTX_CON(context)); else crWarning("invalid context %#x", hglrc); crHashtableUnlock(stub.contextTable); // crHashtableUnlock(stub.windowTable); } DECLEXPORT(BOOL) WINAPI wglSwapBuffers_prox( HDC hdc ) { WindowInfo *window = stubGetWindowInfo(hdc); CR_DDI_PROLOGUE(); stubSwapBuffers( window, 0 ); return 1; } DECLEXPORT(BOOL) WINAPI wglCopyContext_prox( HGLRC src, HGLRC dst, UINT mask ) { CR_DDI_PROLOGUE(); crWarning( "wglCopyContext: unsupported" ); return 0; } DECLEXPORT(HGLRC) WINAPI wglCreateLayerContext_prox( HDC hdc, int layerPlane ) { CR_DDI_PROLOGUE(); stubInit(); crWarning( "wglCreateLayerContext: unsupported" ); return 0; } DECLEXPORT(PROC) WINAPI wglGetProcAddress_prox( LPCSTR name ) { CR_DDI_PROLOGUE(); return (PROC) crGetProcAddress( name ); } DECLEXPORT(BOOL) WINAPI wglUseFontBitmapsA_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase ) { CR_DDI_PROLOGUE(); crWarning( "wglUseFontBitmapsA: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglUseFontBitmapsW_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase ) { CR_DDI_PROLOGUE(); crWarning( "wglUseFontBitmapsW: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglDescribeLayerPlane_prox( HDC hdc, int pixelFormat, int layerPlane, UINT nBytes, LPLAYERPLANEDESCRIPTOR lpd ) { CR_DDI_PROLOGUE(); crWarning( "wglDescribeLayerPlane: unimplemented" ); return 0; } DECLEXPORT(int) WINAPI wglSetLayerPaletteEntries_prox( HDC hdc, int layerPlane, int start, int entries, CONST COLORREF *cr ) { CR_DDI_PROLOGUE(); crWarning( "wglSetLayerPaletteEntries: unsupported" ); return 0; } DECLEXPORT(int) WINAPI wglGetLayerPaletteEntries_prox( HDC hdc, int layerPlane, int start, int entries, COLORREF *cr ) { CR_DDI_PROLOGUE(); crWarning( "wglGetLayerPaletteEntries: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglRealizeLayerPalette_prox( HDC hdc, int layerPlane, BOOL realize ) { CR_DDI_PROLOGUE(); crWarning( "wglRealizeLayerPalette: unsupported" ); return 0; } DECLEXPORT(DWORD) WINAPI wglSwapMultipleBuffers_prox( UINT a, CONST void *b ) { CR_DDI_PROLOGUE(); crWarning( "wglSwapMultipleBuffer: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglUseFontOutlinesA_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT gmf ) { CR_DDI_PROLOGUE(); crWarning( "wglUseFontOutlinesA: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglUseFontOutlinesW_prox( HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT gmf ) { CR_DDI_PROLOGUE(); crWarning( "wglUseFontOutlinesW: unsupported" ); return 0; } DECLEXPORT(BOOL) WINAPI wglSwapLayerBuffers_prox( HDC hdc, UINT planes ) { CR_DDI_PROLOGUE(); if (planes == WGL_SWAP_MAIN_PLANE) { return wglSwapBuffers_prox(hdc); } else { crWarning( "wglSwapLayerBuffers: unsupported" ); return 0; } } DECLEXPORT(BOOL) WINAPI wglChoosePixelFormatEXT_prox (HDC hdc, const int *piAttributes, const FLOAT *pfAttributes, UINT nMaxFormats, int *piFormats, UINT *nNumFormats) { int *pi; int wants_rgb = 0; CR_DDI_PROLOGUE(); stubInit(); /** @todo : Need to check pfAttributes too ! */ for ( pi = (int *)piAttributes; *pi != 0; pi++ ) { switch ( *pi ) { case WGL_COLOR_BITS_EXT: if (pi[1] > 8) wants_rgb = 1; pi++; break; case WGL_RED_BITS_EXT: case WGL_GREEN_BITS_EXT: case WGL_BLUE_BITS_EXT: if (pi[1] > 3) wants_rgb = 1; pi++; break; case WGL_ACCUM_ALPHA_BITS_EXT: case WGL_ALPHA_BITS_EXT: if (pi[1] > 0) desiredVisual |= CR_ALPHA_BIT; pi++; break; case WGL_DOUBLE_BUFFER_EXT: if (pi[1] > 0) desiredVisual |= CR_DOUBLE_BIT; pi++; break; case WGL_STEREO_EXT: if (pi[1] > 0) { /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ crWarning("WGL_STEREO_EXT not supporteed!"); return 0; // desiredVisual |= CR_STEREO_BIT; } pi++; break; case WGL_DEPTH_BITS_EXT: if (pi[1] > 0) desiredVisual |= CR_DEPTH_BIT; pi++; break; case WGL_STENCIL_BITS_EXT: if (pi[1] > 0) desiredVisual |= CR_STENCIL_BIT; pi++; break; case WGL_ACCUM_RED_BITS_EXT: case WGL_ACCUM_GREEN_BITS_EXT: case WGL_ACCUM_BLUE_BITS_EXT: if (pi[1] > 0) desiredVisual |= CR_ACCUM_BIT; pi++; break; case WGL_SAMPLE_BUFFERS_EXT: case WGL_SAMPLES_EXT: if (pi[1] > 0) { /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ crWarning("WGL_SAMPLE_BUFFERS_EXT & WGL_SAMPLES_EXT not supporteed!"); return 0; // desiredVisual |= CR_MULTISAMPLE_BIT; } pi++; break; case WGL_SUPPORT_OPENGL_ARB: case WGL_DRAW_TO_WINDOW_ARB: case WGL_ACCELERATION_ARB: pi++; break; case WGL_PIXEL_TYPE_ARB: if(pi[1]!=WGL_TYPE_RGBA_ARB) { crWarning("WGL_PIXEL_TYPE 0x%x not supported!", pi[1]); return 0; } pi++; break; default: crWarning( "wglChoosePixelFormatEXT: bad pi=0x%x", *pi ); return 0; } } if (nNumFormats) *nNumFormats = 1; if (nMaxFormats>0 && piFormats) { piFormats[0] = 1; } return 1; } DECLEXPORT(BOOL) WINAPI wglGetPixelFormatAttribivEXT_prox (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *pValues) { UINT i; CR_DDI_PROLOGUE(); if (!pValues || !piAttributes) return 0; if ((nAttributes!=1) || (piAttributes && piAttributes[0]!=WGL_NUMBER_PIXEL_FORMATS_ARB)) { if (iPixelFormat!=1) { crDebug("wglGetPixelFormatAttribivARB: bad pf:%i", iPixelFormat); return 0; } } for (i=0; i<nAttributes; ++i) { switch (piAttributes[i]) { case WGL_NUMBER_PIXEL_FORMATS_ARB: pValues[i] = 1; break; case WGL_DRAW_TO_WINDOW_ARB: case WGL_SUPPORT_OPENGL_ARB: case WGL_DOUBLE_BUFFER_ARB: pValues[i] = 1; break; case WGL_STEREO_ARB: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0; break; case WGL_DRAW_TO_BITMAP_ARB: case WGL_NEED_PALETTE_ARB: case WGL_NEED_SYSTEM_PALETTE_ARB: case WGL_SWAP_LAYER_BUFFERS_ARB: case WGL_NUMBER_OVERLAYS_ARB: case WGL_NUMBER_UNDERLAYS_ARB: case WGL_TRANSPARENT_ARB: case WGL_TRANSPARENT_RED_VALUE_ARB: case WGL_TRANSPARENT_GREEN_VALUE_ARB: case WGL_TRANSPARENT_BLUE_VALUE_ARB: case WGL_TRANSPARENT_ALPHA_VALUE_ARB: case WGL_TRANSPARENT_INDEX_VALUE_ARB: case WGL_SHARE_DEPTH_ARB: case WGL_SHARE_STENCIL_ARB: case WGL_SHARE_ACCUM_ARB: case WGL_SUPPORT_GDI_ARB: pValues[i] = 0; break; case WGL_ACCELERATION_ARB: pValues[i] = WGL_FULL_ACCELERATION_ARB; break; case WGL_SWAP_METHOD_ARB: pValues[i] = WGL_SWAP_UNDEFINED_ARB; break; case WGL_PIXEL_TYPE_ARB: pValues[i] = WGL_TYPE_RGBA_ARB; break; case WGL_COLOR_BITS_ARB: pValues[i] = 32; break; case WGL_RED_BITS_ARB: case WGL_GREEN_BITS_ARB: case WGL_BLUE_BITS_ARB: case WGL_ALPHA_BITS_ARB: pValues[i] = 8; break; case WGL_RED_SHIFT_ARB: pValues[i] = 24; break; case WGL_GREEN_SHIFT_ARB: pValues[i] = 16; break; case WGL_BLUE_SHIFT_ARB: pValues[i] = 8; break; case WGL_ALPHA_SHIFT_ARB: pValues[i] = 0; break; case WGL_ACCUM_BITS_ARB: pValues[i] = 0; break; case WGL_ACCUM_RED_BITS_ARB: pValues[i] = 0; break; case WGL_ACCUM_GREEN_BITS_ARB: pValues[i] = 0; break; case WGL_ACCUM_BLUE_BITS_ARB: pValues[i] = 0; break; case WGL_ACCUM_ALPHA_BITS_ARB: pValues[i] = 0; break; case WGL_DEPTH_BITS_ARB: pValues[i] = 32; break; case WGL_STENCIL_BITS_ARB: pValues[i] = 8; break; case WGL_AUX_BUFFERS_ARB: pValues[i] = 0; break; case WGL_SAMPLE_BUFFERS_EXT: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0; break; case WGL_SAMPLES_EXT: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0; break; case 0x202d: /* <- WGL_DRAW_TO_PBUFFER_ARB this is to make VSG Open Inventor happy */ pValues[i] = 0; break; default: crWarning("wglGetPixelFormatAttribivARB: bad attrib=0x%x", piAttributes[i]); return 0; } } return 1; } DECLEXPORT(BOOL) WINAPI wglGetPixelFormatAttribfvEXT_prox (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, float *pValues) { UINT i; CR_DDI_PROLOGUE(); if (!pValues || !piAttributes) return 0; if ((nAttributes!=1) || (piAttributes && piAttributes[0]!=WGL_NUMBER_PIXEL_FORMATS_ARB)) { if (iPixelFormat!=1) { crDebug("wglGetPixelFormatAttribivARB: bad pf:%i", iPixelFormat); return 0; } } for (i=0; i<nAttributes; ++i) { switch (piAttributes[i]) { case WGL_NUMBER_PIXEL_FORMATS_ARB: pValues[i] = 1.f; break; case WGL_DRAW_TO_WINDOW_ARB: case WGL_SUPPORT_OPENGL_ARB: case WGL_DOUBLE_BUFFER_ARB: pValues[i] = 1.f; break; case WGL_STEREO_ARB: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0.f; break; case WGL_DRAW_TO_BITMAP_ARB: case WGL_NEED_PALETTE_ARB: case WGL_NEED_SYSTEM_PALETTE_ARB: case WGL_SWAP_LAYER_BUFFERS_ARB: case WGL_NUMBER_OVERLAYS_ARB: case WGL_NUMBER_UNDERLAYS_ARB: case WGL_TRANSPARENT_ARB: case WGL_TRANSPARENT_RED_VALUE_ARB: case WGL_TRANSPARENT_GREEN_VALUE_ARB: case WGL_TRANSPARENT_BLUE_VALUE_ARB: case WGL_TRANSPARENT_ALPHA_VALUE_ARB: case WGL_TRANSPARENT_INDEX_VALUE_ARB: case WGL_SHARE_DEPTH_ARB: case WGL_SHARE_STENCIL_ARB: case WGL_SHARE_ACCUM_ARB: case WGL_SUPPORT_GDI_ARB: pValues[i] = 0.f; break; case WGL_ACCELERATION_ARB: pValues[i] = WGL_FULL_ACCELERATION_ARB; break; case WGL_SWAP_METHOD_ARB: pValues[i] = WGL_SWAP_UNDEFINED_ARB; break; case WGL_PIXEL_TYPE_ARB: pValues[i] = WGL_TYPE_RGBA_ARB; break; case WGL_COLOR_BITS_ARB: pValues[i] = 32.f; break; case WGL_RED_BITS_ARB: case WGL_GREEN_BITS_ARB: case WGL_BLUE_BITS_ARB: case WGL_ALPHA_BITS_ARB: pValues[i] = 8.f; break; case WGL_RED_SHIFT_ARB: pValues[i] = 24.f; break; case WGL_GREEN_SHIFT_ARB: pValues[i] = 16.f; break; case WGL_BLUE_SHIFT_ARB: pValues[i] = 8.f; break; case WGL_ALPHA_SHIFT_ARB: pValues[i] = 0.f; break; case WGL_ACCUM_BITS_ARB: pValues[i] = 0.f; break; case WGL_ACCUM_RED_BITS_ARB: pValues[i] = 0.f; break; case WGL_ACCUM_GREEN_BITS_ARB: pValues[i] = 0.f; break; case WGL_ACCUM_BLUE_BITS_ARB: pValues[i] = 0.f; break; case WGL_ACCUM_ALPHA_BITS_ARB: pValues[i] = 0.f; break; case WGL_DEPTH_BITS_ARB: pValues[i] = 32.f; break; case WGL_STENCIL_BITS_ARB: pValues[i] = 8.f; break; case WGL_AUX_BUFFERS_ARB: pValues[i] = 0.f; break; case WGL_SAMPLE_BUFFERS_EXT: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0.f; break; case WGL_SAMPLES_EXT: /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ pValues[i] = 0.f; break; case 0x202d: /* <- WGL_DRAW_TO_PBUFFER_ARB this is to make VSG Open Inventor happy */ pValues[i] = 0.f; break; default: crWarning("wglGetPixelFormatAttribivARB: bad attrib=0x%x", piAttributes[i]); return 0; } } return 1; } DECLEXPORT(BOOL) WINAPI wglSwapIntervalEXT_prox(int interval) { CR_DDI_PROLOGUE(); return TRUE; } DECLEXPORT(int) WINAPI wglGetSwapIntervalEXT_prox() { CR_DDI_PROLOGUE(); return 1; } static GLubyte *gsz_wgl_extensions = "WGL_EXT_pixel_format WGL_ARB_pixel_format WGL_ARB_multisample"; DECLEXPORT(const GLubyte *) WINAPI wglGetExtensionsStringEXT_prox() { CR_DDI_PROLOGUE(); return gsz_wgl_extensions; } DECLEXPORT(const GLubyte *) WINAPI wglGetExtensionsStringARB_prox(HDC hdc) { CR_DDI_PROLOGUE(); (void) hdc; return gsz_wgl_extensions; }
d0c858726bf7fc6cacf6e2f02f4e6743acf44c41
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/area_jan/jan_05/jan_05_3_log.c
fda49f8e3f397693f5247afec65e1235beb6b8e8
[]
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
5,288
c
jan_05_3_log.c
#include "jan_05.h" #include "effects.h" #include "sprite/player.h" EvtScript N(EVS_SetupLogObjects) = { EVT_IF_EQ(GF_JAN05_CreateLogBridge, FALSE) EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_o21, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(EnableModel, MODEL_o147, FALSE) EVT_CALL(EnableModel, MODEL_o148, FALSE) EVT_CALL(TranslateGroup, MODEL_g31, 0, -240, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, -240, 0) EVT_ELSE EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_o94, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_o92, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_CLEAR_BITS, COLLIDER_o21, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(EnableModel, MODEL_o147, TRUE) EVT_CALL(EnableModel, MODEL_o148, TRUE) EVT_CALL(TranslateGroup, MODEL_g31, 0, 10, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, 10, 0) EVT_CALL(RotateGroup, MODEL_g31, -90, 0, 0, 1) EVT_CALL(RotateGroup, MODEL_g32, -90, 0, 0, 1) EVT_CALL(RotateGroup, MODEL_g31, 90, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_g32, -90, 0, 1, 0) EVT_END_IF EVT_RETURN EVT_END }; EvtScript N(EVS_LogAnim_RiseUp) = { EVT_CALL(PlaySoundAtCollider, COLLIDER_o94, SOUND_SMACK_TREE, 0) EVT_CALL(MakeLerp, -240, -259, 5, EASING_QUARTIC_OUT) EVT_LOOP(0) EVT_CALL(UpdateLerp) EVT_CALL(TranslateGroup, MODEL_g31, 0, LVar0, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, LVar0, 0) EVT_WAIT(1) EVT_IF_EQ(LVar1, 0) EVT_BREAK_LOOP EVT_END_IF EVT_END_LOOP EVT_RETURN EVT_END }; #include "world/common/todo/UpdateLogShadow.inc.c" EvtScript N(EVS_LogAnim_FallDown) = { EVT_THREAD EVT_WAIT(17) EVT_CALL(SetPlayerAnimation, ANIM_Mario1_LookUp) EVT_CALL(N(UpdateLogShadow), MODEL_o147, MF_KillLogShadow) EVT_END_THREAD EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_o94, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(MakeLerp, -259, 60, 30, EASING_QUADRATIC_OUT) EVT_LOOP(0) EVT_CALL(UpdateLerp) EVT_CALL(TranslateGroup, MODEL_g31, 0, LVar0, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, LVar0, 0) EVT_WAIT(1) EVT_IF_EQ(LVar1, 0) EVT_BREAK_LOOP EVT_END_IF EVT_END_LOOP EVT_WAIT(1) EVT_CALL(MakeLerp, 60, 0, 30, EASING_CUBIC_IN) EVT_LOOP(0) EVT_CALL(UpdateLerp) EVT_CALL(TranslateGroup, MODEL_g31, 0, LVar0, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, LVar0, 0) EVT_WAIT(1) EVT_IF_EQ(LVar1, 0) EVT_BREAK_LOOP EVT_END_IF EVT_END_LOOP EVT_CALL(SetPlayerAnimation, ANIM_Mario1_Idle) EVT_CALL(PlaySoundAtCollider, COLLIDER_o94, SOUND_JAN_LOG_LAND, 0) EVT_PLAY_EFFECT(EFFECT_LANDING_DUST, 4, -185, 0, 320, 0) EVT_CALL(ShakeCam, CAM_DEFAULT, 2, 3, 1) EVT_RETURN EVT_END }; EvtScript N(EVS_LogAnim_FallOver) = { EVT_THREAD EVT_WAIT(50) EVT_SET(MF_KillLogShadow, TRUE) EVT_END_THREAD EVT_CALL(MakeLerp, 0, -90, 60, EASING_CUBIC_IN) EVT_LOOP(0) EVT_CALL(UpdateLerp) EVT_CALL(TranslateGroup, MODEL_g31, 0, 0, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, 0, 0) EVT_CALL(RotateGroup, MODEL_g31, LVar0, 0, 0, 1) EVT_CALL(RotateGroup, MODEL_g32, LVar0, 0, 0, 1) EVT_WAIT(1) EVT_IF_EQ(LVar1, 0) EVT_BREAK_LOOP EVT_END_IF EVT_END_LOOP EVT_THREAD EVT_CALL(ShakeCam, CAM_DEFAULT, 2, 3, 1) EVT_END_THREAD EVT_RETURN EVT_END }; EvtScript N(EVS_LogAnim_Split) = { EVT_CALL(PlaySoundAtCollider, COLLIDER_o94, SOUND_JAN_LOG_SPLIT, 0) EVT_CALL(EnableModel, MODEL_o147, TRUE) EVT_CALL(EnableModel, MODEL_o148, TRUE) EVT_CALL(MakeLerp, 0, 90, 30, EASING_COS_FAST_OVERSHOOT) EVT_LOOP(0) EVT_CALL(UpdateLerp) EVT_SET(LVar2, LVar0) EVT_DIVF(LVar2, 9) EVT_CALL(TranslateGroup, MODEL_g31, 0, LVar2, 0) EVT_CALL(TranslateGroup, MODEL_g32, 0, LVar2, 0) EVT_CALL(RotateGroup, MODEL_g31, -90, 0, 0, 1) EVT_CALL(RotateGroup, MODEL_g32, -90, 0, 0, 1) EVT_CALL(RotateGroup, MODEL_g31, LVar0, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_g32, LVar0, 0, -1, 0) EVT_WAIT(1) EVT_IF_EQ(LVar1, 0) EVT_BREAK_LOOP EVT_END_IF EVT_END_LOOP EVT_RETURN EVT_END }; EvtScript N(EVS_Smash_BuriedLog) = { EVT_SET(GF_JAN05_CreateLogBridge, TRUE) EVT_CALL(DisablePlayerInput, TRUE) EVT_EXEC_WAIT(N(EVS_LogAnim_RiseUp)) EVT_WAIT(1) EVT_EXEC_WAIT(N(EVS_LogAnim_FallDown)) EVT_WAIT(1) EVT_EXEC_WAIT(N(EVS_LogAnim_FallOver)) EVT_WAIT(1) EVT_EXEC_WAIT(N(EVS_LogAnim_Split)) EVT_WAIT(1) EVT_CALL(DisablePlayerInput, FALSE) EVT_EXEC(N(EVS_SetupLogObjects)) EVT_RETURN EVT_END }; EvtScript N(EVS_SetupLogs) = { EVT_IF_EQ(GF_JAN05_CreateLogBridge, FALSE) EVT_BIND_TRIGGER(EVT_PTR(N(EVS_Smash_BuriedLog)), TRIGGER_WALL_HAMMER, COLLIDER_o94, 1, 0) EVT_END_IF EVT_EXEC(N(EVS_SetupLogObjects)) EVT_RETURN EVT_END };
c645ad0dafe66a24c45595b0e84d23ca7b4368a1
270937d32c2bc8e33622d96c045b43b8a23bc086
/third_party/iculehb/src/src/LEScripts.h
b665142228669688cddbb29d96e372dbce3e31de
[ "Apache-2.0", "ICU" ]
permissive
google/ion
32491fc26a0a2a5fd602e4008296ccba5017d689
514ce797458d02e7cd3a1b2d0b5c7ff8ccb5f5d1
refs/heads/master
2023-09-04T18:10:40.343013
2022-06-09T07:56:18
2022-06-09T07:56:18
50,387,855
1,651
132
Apache-2.0
2018-05-12T02:16:47
2016-01-25T23:13:46
C++
UTF-8
C
false
false
6,452
h
LEScripts.h
/** Copyright 2017 Google Inc. 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. */ /* * * (C) Copyright IBM Corp. 1998-2014. All Rights Reserved. * * WARNING: THIS FILE IS MACHINE GENERATED. DO NOT HAND EDIT IT UNLESS * YOU REALLY KNOW WHAT YOU'RE DOING. * * Generated on: 04/08/2014 03:20:04 PM PDT */ #ifndef __LESCRIPTS_H #define __LESCRIPTS_H #include "LETypes.h" /** * \file * \brief C++ API: Constants for Unicode script values */ U_NAMESPACE_BEGIN /** * Constants for Unicode script values, generated using * ICU4J's <code>UScript</code> class. * * @deprecated ICU 54. See {@link icu::LayoutEngine} */ enum ScriptCodes { zyyyScriptCode = 0, zinhScriptCode = 1, qaaiScriptCode = zinhScriptCode, /* manually added alias, for API stability */ arabScriptCode = 2, armnScriptCode = 3, bengScriptCode = 4, bopoScriptCode = 5, cherScriptCode = 6, coptScriptCode = 7, cyrlScriptCode = 8, dsrtScriptCode = 9, devaScriptCode = 10, ethiScriptCode = 11, georScriptCode = 12, gothScriptCode = 13, grekScriptCode = 14, gujrScriptCode = 15, guruScriptCode = 16, haniScriptCode = 17, hangScriptCode = 18, hebrScriptCode = 19, hiraScriptCode = 20, kndaScriptCode = 21, kanaScriptCode = 22, khmrScriptCode = 23, laooScriptCode = 24, latnScriptCode = 25, mlymScriptCode = 26, mongScriptCode = 27, mymrScriptCode = 28, ogamScriptCode = 29, italScriptCode = 30, oryaScriptCode = 31, runrScriptCode = 32, sinhScriptCode = 33, syrcScriptCode = 34, tamlScriptCode = 35, teluScriptCode = 36, thaaScriptCode = 37, thaiScriptCode = 38, tibtScriptCode = 39, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ cansScriptCode = 40, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ yiiiScriptCode = 41, tglgScriptCode = 42, hanoScriptCode = 43, buhdScriptCode = 44, tagbScriptCode = 45, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ braiScriptCode = 46, cprtScriptCode = 47, limbScriptCode = 48, linbScriptCode = 49, osmaScriptCode = 50, shawScriptCode = 51, taleScriptCode = 52, ugarScriptCode = 53, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ hrktScriptCode = 54, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ bugiScriptCode = 55, glagScriptCode = 56, kharScriptCode = 57, syloScriptCode = 58, taluScriptCode = 59, tfngScriptCode = 60, xpeoScriptCode = 61, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ baliScriptCode = 62, batkScriptCode = 63, blisScriptCode = 64, brahScriptCode = 65, chamScriptCode = 66, cirtScriptCode = 67, cyrsScriptCode = 68, egydScriptCode = 69, egyhScriptCode = 70, egypScriptCode = 71, geokScriptCode = 72, hansScriptCode = 73, hantScriptCode = 74, hmngScriptCode = 75, hungScriptCode = 76, indsScriptCode = 77, javaScriptCode = 78, kaliScriptCode = 79, latfScriptCode = 80, latgScriptCode = 81, lepcScriptCode = 82, linaScriptCode = 83, mandScriptCode = 84, mayaScriptCode = 85, meroScriptCode = 86, nkooScriptCode = 87, orkhScriptCode = 88, permScriptCode = 89, phagScriptCode = 90, phnxScriptCode = 91, plrdScriptCode = 92, roroScriptCode = 93, saraScriptCode = 94, syreScriptCode = 95, syrjScriptCode = 96, syrnScriptCode = 97, tengScriptCode = 98, vaiiScriptCode = 99, vispScriptCode = 100, xsuxScriptCode = 101, zxxxScriptCode = 102, zzzzScriptCode = 103, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ cariScriptCode = 104, jpanScriptCode = 105, lanaScriptCode = 106, lyciScriptCode = 107, lydiScriptCode = 108, olckScriptCode = 109, rjngScriptCode = 110, saurScriptCode = 111, sgnwScriptCode = 112, sundScriptCode = 113, moonScriptCode = 114, mteiScriptCode = 115, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ armiScriptCode = 116, avstScriptCode = 117, cakmScriptCode = 118, koreScriptCode = 119, kthiScriptCode = 120, maniScriptCode = 121, phliScriptCode = 122, phlpScriptCode = 123, phlvScriptCode = 124, prtiScriptCode = 125, samrScriptCode = 126, tavtScriptCode = 127, zmthScriptCode = 128, zsymScriptCode = 129, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ bamuScriptCode = 130, lisuScriptCode = 131, nkgbScriptCode = 132, sarbScriptCode = 133, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ bassScriptCode = 134, duplScriptCode = 135, elbaScriptCode = 136, granScriptCode = 137, kpelScriptCode = 138, lomaScriptCode = 139, mendScriptCode = 140, mercScriptCode = 141, narbScriptCode = 142, nbatScriptCode = 143, palmScriptCode = 144, sindScriptCode = 145, waraScriptCode = 146, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ afakScriptCode = 147, jurcScriptCode = 148, mrooScriptCode = 149, nshuScriptCode = 150, shrdScriptCode = 151, soraScriptCode = 152, takrScriptCode = 153, tangScriptCode = 154, woleScriptCode = 155, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ hluwScriptCode = 156, khojScriptCode = 157, tirhScriptCode = 158, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ aghbScriptCode = 159, mahjScriptCode = 160, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ ahomScriptCode = 161, hatrScriptCode = 162, modiScriptCode = 163, multScriptCode = 164, paucScriptCode = 165, siddScriptCode = 166, /** * @deprecated ICU 54. See {@link icu::LayoutEngine} */ scriptCodeCount }; U_NAMESPACE_END #endif
fdd61a46b10e882410837de74f3a00e06f2d48de
b732361d6b3405c3e79ac0a7d8361cf5b329b015
/ext/phalcon/encryption/security/jwt/validator.zep.c
1f5693da30185c83d060d69988d6780bee053cde
[ "BSD-3-Clause" ]
permissive
phalcon/cphalcon
4a5b26f47b5c2a4107541d7fd73c595c0d90ed73
fc183e11e8b96c43daf7d893244846206dc2aa73
refs/heads/master
2023-03-07T22:09:48.814291
2023-02-28T16:45:15
2023-02-28T16:45:15
2,854,337
8,135
2,343
BSD-3-Clause
2023-09-12T12:41:13
2011-11-26T05:52:50
PHP
UTF-8
C
false
true
20,191
c
validator.zep.c
#ifdef HAVE_CONFIG_H #include "../../../../ext_config.h" #endif #include <php.h> #include "../../../../php_ext.h" #include "../../../../ext.h" #include <Zend/zend_operators.h> #include <Zend/zend_exceptions.h> #include <Zend/zend_interfaces.h> #include "kernel/main.h" #include "kernel/time.h" #include "kernel/memory.h" #include "kernel/object.h" #include "kernel/array.h" #include "kernel/operators.h" #include "kernel/exception.h" #include "kernel/fcall.h" #include "ext/spl/spl_exceptions.h" /** * This file is part of the Phalcon Framework. * * (c) Phalcon Team <team@phalcon.io> * * For the full copyright and license information, please view the LICENSE.txt * file that was distributed with this source code. */ /** * Class Validator */ ZEPHIR_INIT_CLASS(Phalcon_Encryption_Security_JWT_Validator) { ZEPHIR_REGISTER_CLASS(Phalcon\\Encryption\\Security\\JWT, Validator, phalcon, encryption_security_jwt_validator, phalcon_encryption_security_jwt_validator_method_entry, 0); /** * @var array */ zend_declare_property_null(phalcon_encryption_security_jwt_validator_ce, SL("claims"), ZEND_ACC_PRIVATE); /** * @var array */ zend_declare_property_null(phalcon_encryption_security_jwt_validator_ce, SL("errors"), ZEND_ACC_PRIVATE); /** * @var int */ zend_declare_property_long(phalcon_encryption_security_jwt_validator_ce, SL("timeShift"), 0, ZEND_ACC_PRIVATE); /** * @var Token */ zend_declare_property_null(phalcon_encryption_security_jwt_validator_ce, SL("token"), ZEND_ACC_PRIVATE); phalcon_encryption_security_jwt_validator_ce->create_object = zephir_init_properties_Phalcon_Encryption_Security_JWT_Validator; return SUCCESS; } /** * Validator constructor. * * @param Token $token * @param int $timeShift */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, __construct) { zval _1; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long timeShift; zval *token, token_sub, *timeShift_param = NULL, __$null, now, _0; zval *this_ptr = getThis(); ZVAL_UNDEF(&token_sub); ZVAL_NULL(&__$null); ZVAL_UNDEF(&now); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_OBJECT_OF_CLASS(token, phalcon_encryption_security_jwt_token_token_ce) Z_PARAM_OPTIONAL Z_PARAM_LONG(timeShift) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &token, &timeShift_param); if (!timeShift_param) { timeShift = 0; } else { timeShift = zephir_get_intval(timeShift_param); } ZEPHIR_INIT_VAR(&now); zephir_time(&now); zephir_update_property_zval(this_ptr, ZEND_STRL("token"), token); ZEPHIR_INIT_ZVAL_NREF(_0); ZVAL_LONG(&_0, timeShift); zephir_update_property_zval(this_ptr, ZEND_STRL("timeShift"), &_0); ZEPHIR_INIT_VAR(&_1); zephir_create_array(&_1, 7, 0); zephir_array_update_string(&_1, SL("aud"), &__$null, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("exp"), &now, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("jti"), &__$null, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("iat"), &now, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("iss"), &__$null, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("nbf"), &now, PH_COPY | PH_SEPARATE); zephir_array_update_string(&_1, SL("sub"), &__$null, PH_COPY | PH_SEPARATE); zephir_update_property_zval(this_ptr, ZEND_STRL("claims"), &_1); ZEPHIR_MM_RESTORE(); } PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, getErrors) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "errors"); } PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, get) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *claim_param = NULL, _0, _1$$3, _2$$3; zval claim; zval *this_ptr = getThis(); ZVAL_UNDEF(&claim); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(claim) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &claim_param); zephir_get_strval(&claim, claim_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("claims"), PH_NOISY_CC | PH_READONLY); if (zephir_array_isset(&_0, &claim)) { zephir_read_property(&_1$$3, this_ptr, ZEND_STRL("claims"), PH_NOISY_CC | PH_READONLY); zephir_array_fetch(&_2$$3, &_1$$3, &claim, PH_NOISY | PH_READONLY, "phalcon/Encryption/Security/JWT/Validator.zep", 75); RETURN_CTOR(&_2$$3); } RETURN_MM_NULL(); } PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, set) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *claim_param = NULL, *value, value_sub; zval claim; zval *this_ptr = getThis(); ZVAL_UNDEF(&claim); ZVAL_UNDEF(&value_sub); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(claim) Z_PARAM_ZVAL(value) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &claim_param, &value); zephir_get_strval(&claim, claim_param); zephir_update_property_array(this_ptr, SL("claims"), &claim, value); RETURN_THIS(); } /** * @param Token $token * * @return Validator */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, setToken) { zval *token, token_sub; zval *this_ptr = getThis(); ZVAL_UNDEF(&token_sub); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(token, phalcon_encryption_security_jwt_token_token_ce) ZEND_PARSE_PARAMETERS_END(); #endif zephir_fetch_params_without_memory_grow(1, 0, &token); zephir_update_property_zval(this_ptr, ZEND_STRL("token"), token); RETURN_THISW(); } /** * @param string|array $audience * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateAudience) { zend_bool _0; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *audience = NULL, audience_sub, item, tokenAudience, _2, _3, _4, _5, *_6, _7, _1$$4, _8$$6, _9$$8; zval *this_ptr = getThis(); ZVAL_UNDEF(&audience_sub); ZVAL_UNDEF(&item); ZVAL_UNDEF(&tokenAudience); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_7); ZVAL_UNDEF(&_1$$4); ZVAL_UNDEF(&_8$$6); ZVAL_UNDEF(&_9$$8); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(audience) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &audience); ZEPHIR_SEPARATE_PARAM(audience); _0 = Z_TYPE_P(audience) != IS_STRING; if (_0) { _0 = Z_TYPE_P(audience) != IS_ARRAY; } if (_0) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_encryption_security_jwt_exceptions_validatorexception_ce, "Audience must be a string or an array", "phalcon/Encryption/Security/JWT/Validator.zep", 113); return; } if (Z_TYPE_P(audience) == IS_STRING) { ZEPHIR_INIT_VAR(&_1$$4); zephir_create_array(&_1$$4, 1, 0); zephir_array_fast_append(&_1$$4, audience); ZEPHIR_CPY_WRT(audience, &_1$$4); } zephir_read_property(&_2, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_3, &_2, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_4); array_init(&_4); ZEPHIR_INIT_VAR(&_5); ZVAL_STRING(&_5, "aud"); ZEPHIR_CALL_METHOD(&tokenAudience, &_3, "get", NULL, 0, &_5, &_4); zephir_check_call_status(); zephir_is_iterable(audience, 0, "phalcon/Encryption/Security/JWT/Validator.zep", 128); if (Z_TYPE_P(audience) == IS_ARRAY) { ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(audience), _6) { ZEPHIR_INIT_NVAR(&item); ZVAL_COPY(&item, _6); if (1 != zephir_fast_in_array(&item, &tokenAudience)) { ZEPHIR_INIT_ZVAL_NREF(_8$$6); ZEPHIR_INIT_NVAR(&_8$$6); ZVAL_STRING(&_8$$6, "Validation: audience not allowed"); zephir_update_property_array_append(this_ptr, SL("errors"), &_8$$6); } } ZEND_HASH_FOREACH_END(); } else { ZEPHIR_CALL_METHOD(NULL, audience, "rewind", NULL, 0); zephir_check_call_status(); while (1) { ZEPHIR_CALL_METHOD(&_7, audience, "valid", NULL, 0); zephir_check_call_status(); if (!zend_is_true(&_7)) { break; } ZEPHIR_CALL_METHOD(&item, audience, "current", NULL, 0); zephir_check_call_status(); if (1 != zephir_fast_in_array(&item, &tokenAudience)) { ZEPHIR_INIT_ZVAL_NREF(_9$$8); ZEPHIR_INIT_NVAR(&_9$$8); ZVAL_STRING(&_9$$8, "Validation: audience not allowed"); zephir_update_property_array_append(this_ptr, SL("errors"), &_9$$8); } ZEPHIR_CALL_METHOD(NULL, audience, "next", NULL, 0); zephir_check_call_status(); } } ZEPHIR_INIT_NVAR(&item); RETURN_THIS(); } /** * @param int $timestamp * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateExpiration) { zend_bool _7; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *timestamp_param = NULL, _0, _1, _2, _3, _4, _5, _6, _8, _9, _10$$3; zend_long timestamp, ZEPHIR_LAST_CALL_STATUS, tokenExpirationTime = 0; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6); ZVAL_UNDEF(&_8); ZVAL_UNDEF(&_9); ZVAL_UNDEF(&_10$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(timestamp) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &timestamp_param); timestamp = zephir_get_intval(timestamp_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_1, &_0, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3); ZVAL_STRING(&_3, "exp"); ZEPHIR_CALL_METHOD(&_2, &_1, "get", NULL, 0, &_3); zephir_check_call_status(); tokenExpirationTime = zephir_get_intval(&_2); zephir_read_property(&_4, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_5, &_4, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_3); ZVAL_STRING(&_3, "exp"); ZEPHIR_CALL_METHOD(&_6, &_5, "has", NULL, 0, &_3); zephir_check_call_status(); _7 = zephir_is_true(&_6); if (_7) { ZVAL_LONG(&_9, timestamp); ZEPHIR_CALL_METHOD(&_8, this_ptr, "gettimestamp", NULL, 266, &_9); zephir_check_call_status(); _7 = ZEPHIR_GT_LONG(&_8, tokenExpirationTime); } if (_7) { ZEPHIR_INIT_ZVAL_NREF(_10$$3); ZEPHIR_INIT_VAR(&_10$$3); ZVAL_STRING(&_10$$3, "Validation: the token has expired"); zephir_update_property_array_append(this_ptr, SL("errors"), &_10$$3); } RETURN_THIS(); } /** * @param string $id * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateId) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *id_param = NULL, tokenId, _0, _1, _2, _3, _5$$3; zval id, _4; zval *this_ptr = getThis(); ZVAL_UNDEF(&id); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&tokenId); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_5$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(id) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &id_param); zephir_get_strval(&id, id_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_1, &_0, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3); ZVAL_STRING(&_3, "jti"); ZEPHIR_CALL_METHOD(&_2, &_1, "get", NULL, 0, &_3); zephir_check_call_status(); zephir_cast_to_string(&_4, &_2); ZEPHIR_CPY_WRT(&tokenId, &_4); if (!ZEPHIR_IS_IDENTICAL(&id, &tokenId)) { ZEPHIR_INIT_ZVAL_NREF(_5$$3); ZEPHIR_INIT_VAR(&_5$$3); ZVAL_STRING(&_5$$3, "Validation: incorrect Id"); zephir_update_property_array_append(this_ptr, SL("errors"), &_5$$3); } RETURN_THIS(); } /** * @param int $timestamp * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateIssuedAt) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *timestamp_param = NULL, _0, _1, _2, _3, _4, _5, _6$$3; zend_long timestamp, ZEPHIR_LAST_CALL_STATUS, tokenIssuedAt = 0; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(timestamp) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &timestamp_param); timestamp = zephir_get_intval(timestamp_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_1, &_0, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3); ZVAL_STRING(&_3, "iat"); ZEPHIR_CALL_METHOD(&_2, &_1, "get", NULL, 0, &_3); zephir_check_call_status(); tokenIssuedAt = zephir_get_intval(&_2); ZVAL_LONG(&_5, timestamp); ZEPHIR_CALL_METHOD(&_4, this_ptr, "gettimestamp", NULL, 266, &_5); zephir_check_call_status(); if (ZEPHIR_LE_LONG(&_4, tokenIssuedAt)) { ZEPHIR_INIT_ZVAL_NREF(_6$$3); ZEPHIR_INIT_VAR(&_6$$3); ZVAL_STRING(&_6$$3, "Validation: the token cannot be used yet (future)"); zephir_update_property_array_append(this_ptr, SL("errors"), &_6$$3); } RETURN_THIS(); } /** * @param string $issuer * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateIssuer) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval *issuer_param = NULL, tokenIssuer, _0, _1, _2, _3, _5$$3; zval issuer, _4; zval *this_ptr = getThis(); ZVAL_UNDEF(&issuer); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&tokenIssuer); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_5$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(issuer) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &issuer_param); if (UNEXPECTED(Z_TYPE_P(issuer_param) != IS_STRING && Z_TYPE_P(issuer_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'issuer' must be of the type string")); RETURN_MM_NULL(); } if (EXPECTED(Z_TYPE_P(issuer_param) == IS_STRING)) { zephir_get_strval(&issuer, issuer_param); } else { ZEPHIR_INIT_VAR(&issuer); } zephir_read_property(&_0, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_1, &_0, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3); ZVAL_STRING(&_3, "iss"); ZEPHIR_CALL_METHOD(&_2, &_1, "get", NULL, 0, &_3); zephir_check_call_status(); zephir_cast_to_string(&_4, &_2); ZEPHIR_CPY_WRT(&tokenIssuer, &_4); if (!ZEPHIR_IS_IDENTICAL(&issuer, &tokenIssuer)) { ZEPHIR_INIT_ZVAL_NREF(_5$$3); ZEPHIR_INIT_VAR(&_5$$3); ZVAL_STRING(&_5$$3, "Validation: incorrect issuer"); zephir_update_property_array_append(this_ptr, SL("errors"), &_5$$3); } RETURN_THIS(); } /** * @param int $timestamp * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateNotBefore) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *timestamp_param = NULL, _0, _1, _2, _3, _4, _5, _6$$3; zend_long timestamp, ZEPHIR_LAST_CALL_STATUS, tokenNotBefore = 0; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(timestamp) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &timestamp_param); timestamp = zephir_get_intval(timestamp_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_1, &_0, "getclaims", NULL, 0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_3); ZVAL_STRING(&_3, "nbf"); ZEPHIR_CALL_METHOD(&_2, &_1, "get", NULL, 0, &_3); zephir_check_call_status(); tokenNotBefore = zephir_get_intval(&_2); ZVAL_LONG(&_5, timestamp); ZEPHIR_CALL_METHOD(&_4, this_ptr, "gettimestamp", NULL, 266, &_5); zephir_check_call_status(); if (ZEPHIR_LE_LONG(&_4, tokenNotBefore)) { ZEPHIR_INIT_ZVAL_NREF(_6$$3); ZEPHIR_INIT_VAR(&_6$$3); ZVAL_STRING(&_6$$3, "Validation: the token cannot be used yet (not before)"); zephir_update_property_array_append(this_ptr, SL("errors"), &_6$$3); } RETURN_THIS(); } /** * @param SignerInterface $signer * @param string $passphrase * * @return Validator * @throws ValidatorException */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, validateSignature) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zval passphrase; zval *signer, signer_sub, *passphrase_param = NULL, _0, _1, _2, _3, _4, _5, _6$$3; zval *this_ptr = getThis(); ZVAL_UNDEF(&signer_sub); ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_1); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_3); ZVAL_UNDEF(&_4); ZVAL_UNDEF(&_5); ZVAL_UNDEF(&_6$$3); ZVAL_UNDEF(&passphrase); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_OBJECT_OF_CLASS(signer, phalcon_encryption_security_jwt_signer_signerinterface_ce) Z_PARAM_STR(passphrase) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &signer, &passphrase_param); zephir_get_strval(&passphrase, passphrase_param); zephir_read_property(&_1, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_2, &_1, "getsignature", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_3, &_2, "gethash", NULL, 0); zephir_check_call_status(); zephir_read_property(&_4, this_ptr, ZEND_STRL("token"), PH_NOISY_CC | PH_READONLY); ZEPHIR_CALL_METHOD(&_5, &_4, "getpayload", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_0, signer, "verify", NULL, 0, &_3, &_5, &passphrase); zephir_check_call_status(); if (!ZEPHIR_IS_TRUE_IDENTICAL(&_0)) { ZEPHIR_INIT_ZVAL_NREF(_6$$3); ZEPHIR_INIT_VAR(&_6$$3); ZVAL_STRING(&_6$$3, "Validation: the signature does not match"); zephir_update_property_array_append(this_ptr, SL("errors"), &_6$$3); } RETURN_THIS(); } /** * @param int $timestamp * * @return int */ PHP_METHOD(Phalcon_Encryption_Security_JWT_Validator, getTimestamp) { zval *timestamp_param = NULL, _0; zend_long timestamp; zval *this_ptr = getThis(); ZVAL_UNDEF(&_0); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(timestamp) ZEND_PARSE_PARAMETERS_END(); #endif zephir_fetch_params_without_memory_grow(1, 0, &timestamp_param); timestamp = zephir_get_intval(timestamp_param); zephir_read_property(&_0, this_ptr, ZEND_STRL("timeShift"), PH_NOISY_CC | PH_READONLY); RETURN_LONG((timestamp + zephir_get_numberval(&_0))); } zend_object *zephir_init_properties_Phalcon_Encryption_Security_JWT_Validator(zend_class_entry *class_type) { zval _0, _2, _1$$3, _3$$4; zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; ZVAL_UNDEF(&_0); ZVAL_UNDEF(&_2); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_3$$4); ZEPHIR_MM_GROW(); { zval local_this_ptr, *this_ptr = &local_this_ptr; ZEPHIR_CREATE_OBJECT(this_ptr, class_type); zephir_read_property_ex(&_0, this_ptr, ZEND_STRL("errors"), PH_NOISY_CC | PH_READONLY); if (Z_TYPE_P(&_0) == IS_NULL) { ZEPHIR_INIT_VAR(&_1$$3); array_init(&_1$$3); zephir_update_property_zval_ex(this_ptr, ZEND_STRL("errors"), &_1$$3); } zephir_read_property_ex(&_2, this_ptr, ZEND_STRL("claims"), PH_NOISY_CC | PH_READONLY); if (Z_TYPE_P(&_2) == IS_NULL) { ZEPHIR_INIT_VAR(&_3$$4); array_init(&_3$$4); zephir_update_property_zval_ex(this_ptr, ZEND_STRL("claims"), &_3$$4); } ZEPHIR_MM_RESTORE(); return Z_OBJ_P(this_ptr); } }
1e6ec2839af476a37561e48a4e9e8f0fb04b5e09
8b98cd47f934d2a4a8d0b2842d3277b01f3fb7fa
/applications/obsolete/asterix/inc/adiarray.h
9c86bcf72be716c0f85012b530c20e04cc50378f
[]
no_license
Starlink/starlink
1cc03b85eb78330a3622003b26b69c1733df50fe
2c374b3e97c9cebcc8f3bd2f8b4bb326eefe061a
refs/heads/master
2023-07-26T09:32:27.987319
2023-07-05T23:56:27
2023-07-05T23:56:27
5,169,323
139
45
null
2022-11-18T13:29:32
2012-07-24T18:15:25
Fortran
UTF-8
C
false
false
1,293
h
adiarray.h
#if !defined(_ADI_ARRAY_H_) #define _ADI_ARRAY_H_ typedef struct { ADIobj data; /* First data item */ ADIobj parent; /* Parent array if slice */ int dims[ADI__MXDIM]; short ndim; /* Number of dimensions */ } ADIarray; #define KT_DEFN_ary ADI_G_tdef_ary #define _ary_data(_x) ((ADIarray *) _ID_DATA(_x)) #define _ary_q(_x) (_ID_BLOCK(_x)->cdef==&KT_DEFN_ary) extern ADIclassDef KT_DEFN_ary; /* * Cater for C++ */ #ifdef __cplusplus extern "C" { #endif void ADIaryAlter( ADIobj id, char *name, int nlen, int ndim, int dims[], ADIstatus status ); void ADIaryBaseInfo( ADIarray *ary, int indices[], int orig[], int **bdims, ADIobj *bdata, ADIstatus status ); ADIobj ADIaryCell( ADIarray *ary, int index[], ADIstatus status ); int ADIaryCountNelm( int ndim, int dims[] ); void ADIaryIndices( int ndim, int dims[], int offset, int index[], ADIstatus status ); void ADIaryInit( ADIstatus status ); ADIobj ADIaryNew( int ndim, int dims[], ADIobj dataobjs, ADIobj parent, ADIstatus status ); int ADIaryOffset( int ndim, int dims[], int index[] ); void ADIaryPrint( ADIobj stream, ADIarray *ary, ADIstatus status ); #ifdef __cplusplus } #endif #endif
919a1335fd112255b27a155582d22bf7d666c4f9
d690a7f7fe2329f08274e50d6b9f6c1e048c5e57
/src/core/gfx/fonts/ati8x8.h
508e8eb64f6c2e325ec781725ea824e809a4a204
[ "freertos-exception-2.0", "MIT", "GPL-2.0-or-later" ]
permissive
westlicht/performer
5fde2bbb74db2eb9b855cc08c11fb99f3cb8746a
dac9d12621b4683fc0e98303a422b34ac6f3d23a
refs/heads/master
2022-10-03T00:02:48.422071
2022-06-07T12:16:45
2022-06-07T20:46:39
98,348,867
219
69
MIT
2022-09-21T13:31:29
2017-07-25T20:51:01
C
UTF-8
C
false
false
7,311
h
ati8x8.h
#ifndef __ATI8X8_H__ #define __ATI8X8_H__ #include "BitmapFont.h" static uint8_t ati8x8_bitmap[] = { 0x61, 0xbc, 0xff, 0x46, 0x00, 0x10, 0xfb, 0xef, 0x31, 0x04, 0x8c, 0xf7, 0x33, 0xbf, 0xc7, 0x00, 0xf3, 0x3c, 0xcf, 0x33, 0x30, 0x03, 0xfe, 0xdb, 0xde, 0xdc, 0xd8, 0xd8, 0xd8, 0x3c, 0x33, 0xc7, 0x66, 0xe3, 0xcc, 0x3c, 0xff, 0xff, 0x1f, 0x8c, 0xf7, 0x33, 0xbf, 0xc7, 0xfc, 0x8c, 0xf7, 0x33, 0x0c, 0xc3, 0x00, 0x0c, 0xc3, 0x30, 0xbf, 0xc7, 0x00, 0x18, 0xdc, 0x1f, 0x87, 0x01, 0x0c, 0xc7, 0xdf, 0xc1, 0x00, 0x83, 0xc1, 0xe0, 0x0f, 0x24, 0x66, 0xff, 0x66, 0x24, 0x08, 0x8e, 0xcf, 0xf7, 0x07, 0x7f, 0x9f, 0x8f, 0x83, 0x00, 0xf6, 0x6f, 0x06, 0x06, 0x7b, 0x6f, 0x36, 0xdb, 0xdf, 0xf6, 0xb7, 0xd9, 0x00, 0x18, 0xff, 0xc0, 0x07, 0xfe, 0x61, 0x00, 0x63, 0x18, 0x86, 0x61, 0x18, 0x03, 0x1c, 0x1b, 0xc7, 0x3d, 0x9b, 0xb9, 0x01, 0xf6, 0x00, 0x6c, 0x33, 0x63, 0x0c, 0x63, 0xcc, 0x6c, 0x03, 0x77, 0xdf, 0xdf, 0x77, 0x07, 0x0c, 0xf3, 0x33, 0x0c, 0xf6, 0x00, 0x7f, 0x3f, 0x60, 0x18, 0x86, 0x61, 0x18, 0x04, 0x00, 0xbe, 0xf1, 0x7c, 0xff, 0x3e, 0xfb, 0x00, 0xcc, 0xc3, 0x30, 0x0c, 0xf3, 0x03, 0xbe, 0x31, 0x0c, 0xc3, 0x30, 0xff, 0x01, 0xbe, 0x31, 0x98, 0x07, 0x1e, 0xfb, 0x00, 0x30, 0x1c, 0xcf, 0xf6, 0x87, 0xc1, 0x00, 0xff, 0xc1, 0x0f, 0x0c, 0x1e, 0xfb, 0x00, 0xbe, 0xf1, 0xe0, 0x37, 0x1e, 0xfb, 0x00, 0xff, 0x31, 0x18, 0x86, 0xc1, 0x60, 0x00, 0xbe, 0xf1, 0xd8, 0x37, 0x1e, 0xfb, 0x00, 0xbe, 0xf1, 0xd8, 0x0f, 0x1e, 0xfb, 0x00, 0x3f, 0xf0, 0x03, 0x36, 0x60, 0x0f, 0x98, 0x99, 0x61, 0x18, 0x06, 0x7f, 0x00, 0xe0, 0x0f, 0xc3, 0x30, 0xcc, 0xcc, 0x00, 0xbe, 0x31, 0x18, 0x86, 0x01, 0x60, 0x00, 0xbe, 0xf1, 0x78, 0xbf, 0x1b, 0xf8, 0x01, 0x1c, 0xdb, 0x78, 0xfc, 0x1f, 0x8f, 0x01, 0x3f, 0xb3, 0xd9, 0x67, 0x36, 0xff, 0x00, 0x3c, 0xf3, 0x60, 0x30, 0x30, 0xf3, 0x00, 0x1f, 0x9b, 0xd9, 0x6c, 0xb6, 0x7d, 0x00, 0xff, 0xe1, 0xe0, 0x33, 0x18, 0xfe, 0x01, 0x7f, 0xa3, 0xc1, 0x67, 0x30, 0x3c, 0x00, 0xbe, 0xf1, 0x60, 0xb0, 0x1f, 0xfb, 0x00, 0xe3, 0xf1, 0xf8, 0x3f, 0x1e, 0x8f, 0x01, 0x6f, 0x66, 0x66, 0x0f, 0x3c, 0x86, 0x61, 0xdb, 0xe6, 0x00, 0xe3, 0xd9, 0xe6, 0xb1, 0x99, 0x8d, 0x01, 0x0f, 0x83, 0xc1, 0x60, 0x30, 0xfe, 0x01, 0xe3, 0xfb, 0x7f, 0xbd, 0x1e, 0x8f, 0x01, 0xe3, 0xf3, 0xf9, 0xbd, 0x9f, 0x8f, 0x01, 0xbe, 0xf1, 0x78, 0x3c, 0x1e, 0xfb, 0x00, 0x3f, 0xb3, 0xd9, 0x67, 0x30, 0x3c, 0x00, 0xbe, 0xf1, 0x78, 0x3c, 0x5e, 0xfb, 0xc0, 0xbf, 0xf1, 0xf8, 0xb7, 0x99, 0x8d, 0x01, 0xbe, 0xf1, 0xc0, 0x07, 0x1e, 0xfb, 0x00, 0x7f, 0xcb, 0x30, 0x0c, 0xe3, 0x01, 0xe3, 0xf1, 0x78, 0x3c, 0x1e, 0xfb, 0x00, 0xe3, 0xf1, 0x78, 0x6c, 0xe3, 0x20, 0x00, 0xe3, 0xf1, 0x7a, 0xfd, 0xbf, 0x8f, 0x01, 0x63, 0x1b, 0x87, 0xc3, 0xb1, 0x8d, 0x01, 0xf3, 0x3c, 0x7b, 0x0c, 0xe3, 0x01, 0xff, 0x30, 0x0c, 0xc3, 0x30, 0xfe, 0x01, 0x7f, 0x8c, 0x31, 0xc6, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x1f, 0x63, 0x8c, 0xf1, 0x07, 0x08, 0x8e, 0x6d, 0x0c, 0xff, 0x9b, 0x01, 0x1e, 0x98, 0x6f, 0xe6, 0x07, 0x07, 0x83, 0xcf, 0x6c, 0x36, 0xff, 0x00, 0xbe, 0xf1, 0x60, 0xec, 0x03, 0x38, 0x98, 0x6f, 0x36, 0x9b, 0xf9, 0x01, 0xbe, 0xf1, 0x7f, 0xe0, 0x03, 0x38, 0x36, 0xe3, 0xc7, 0x60, 0x78, 0x00, 0xee, 0xf9, 0xd8, 0x0f, 0xf6, 0x01, 0x07, 0x83, 0xcf, 0x6c, 0x36, 0x9f, 0x01, 0x06, 0x67, 0x66, 0x0f, 0x30, 0x80, 0xc3, 0x30, 0x3c, 0x7b, 0x07, 0x83, 0xd9, 0xe6, 0xb1, 0x9d, 0x01, 0xdb, 0xb6, 0x1d, 0xb6, 0xff, 0x7a, 0x3d, 0x06, 0x3b, 0xb3, 0xd9, 0x6c, 0x06, 0xbe, 0xf1, 0x78, 0xec, 0x03, 0x3b, 0xb3, 0xd9, 0x67, 0x78, 0x00, 0xee, 0xd9, 0xcc, 0x07, 0xc3, 0x03, 0x3b, 0xb3, 0xc1, 0xf0, 0x00, 0xbe, 0x81, 0x0f, 0xec, 0x03, 0x0c, 0xc6, 0x8f, 0xc1, 0x60, 0xe3, 0x00, 0xb3, 0xd9, 0x6c, 0xe6, 0x06, 0xe3, 0xb1, 0x8d, 0x83, 0x00, 0xe3, 0xf1, 0xfa, 0x6f, 0x03, 0x63, 0x1b, 0xc7, 0x36, 0x06, 0xe3, 0xf1, 0xdc, 0x0d, 0xf6, 0x01, 0x7f, 0xc6, 0x98, 0x3f, 0x38, 0xc3, 0x1c, 0x0c, 0x83, 0x03, 0x3f, 0x3f, 0x07, 0xc3, 0xe0, 0x0c, 0x73, 0x00, 0xee, 0x1d }; static BitmapFontGlyph ati8x8_glyphs[] = { { 0, 5, 7, 8, 0, -6 }, { 5, 5, 7, 8, 2, -6 }, { 10, 6, 7, 8, 1, -6 }, { 16, 6, 7, 8, 1, -6 }, { 22, 8, 7, 8, 0, -6 }, { 29, 7, 8, 8, 0, -6 }, { 36, 7, 3, 8, 0, -2 }, { 39, 6, 8, 8, 1, -6 }, { 45, 6, 7, 8, 1, -6 }, { 51, 6, 7, 8, 1, -6 }, { 57, 7, 5, 8, 0, -5 }, { 62, 7, 5, 8, 0, -5 }, { 67, 7, 4, 8, 0, -4 }, { 71, 8, 5, 8, 0, -5 }, { 76, 7, 5, 8, 0, -5 }, { 81, 7, 5, 8, 0, -5 }, { 86, 0, 0, 8, 0, 1 }, { 86, 4, 7, 8, 2, -6 }, { 90, 5, 3, 8, 1, -6 }, { 92, 7, 7, 8, 0, -6 }, { 99, 7, 7, 8, 0, -6 }, { 106, 7, 6, 8, 0, -5 }, { 112, 7, 7, 8, 0, -6 }, { 119, 3, 3, 8, 2, -6 }, { 121, 4, 7, 8, 1, -6 }, { 125, 4, 7, 8, 1, -6 }, { 129, 7, 5, 8, 0, -5 }, { 134, 6, 5, 8, 1, -5 }, { 138, 3, 3, 8, 2, -2 }, { 140, 7, 1, 8, 0, -3 }, { 141, 3, 2, 8, 2, -1 }, { 142, 7, 7, 8, 0, -6 }, { 149, 7, 7, 8, 0, -6 }, { 156, 6, 7, 8, 1, -6 }, { 162, 7, 7, 8, 0, -6 }, { 169, 7, 7, 8, 0, -6 }, { 176, 7, 7, 8, 0, -6 }, { 183, 7, 7, 8, 0, -6 }, { 190, 7, 7, 8, 0, -6 }, { 197, 7, 7, 8, 0, -6 }, { 204, 7, 7, 8, 0, -6 }, { 211, 7, 7, 8, 0, -6 }, { 218, 3, 6, 8, 3, -5 }, { 221, 3, 7, 8, 2, -5 }, { 224, 5, 7, 8, 1, -6 }, { 229, 7, 4, 8, 0, -4 }, { 233, 5, 7, 8, 1, -6 }, { 238, 7, 7, 8, 0, -6 }, { 245, 7, 7, 8, 0, -6 }, { 252, 7, 7, 8, 0, -6 }, { 259, 7, 7, 8, 0, -6 }, { 266, 7, 7, 8, 0, -6 }, { 273, 7, 7, 8, 0, -6 }, { 280, 7, 7, 8, 0, -6 }, { 287, 7, 7, 8, 0, -6 }, { 294, 7, 7, 8, 0, -6 }, { 301, 7, 7, 8, 0, -6 }, { 308, 4, 7, 8, 2, -6 }, { 312, 6, 7, 8, 0, -6 }, { 318, 7, 7, 8, 0, -6 }, { 325, 7, 7, 8, 0, -6 }, { 332, 7, 7, 8, 0, -6 }, { 339, 7, 7, 8, 0, -6 }, { 346, 7, 7, 8, 0, -6 }, { 353, 7, 7, 8, 0, -6 }, { 360, 7, 8, 8, 0, -6 }, { 367, 7, 7, 8, 0, -6 }, { 374, 7, 7, 8, 0, -6 }, { 381, 6, 7, 8, 1, -6 }, { 387, 7, 7, 8, 0, -6 }, { 394, 7, 7, 8, 0, -6 }, { 401, 7, 7, 8, 0, -6 }, { 408, 7, 7, 8, 0, -6 }, { 415, 6, 7, 8, 1, -6 }, { 421, 7, 7, 8, 0, -6 }, { 428, 5, 7, 8, 1, -6 }, { 433, 7, 7, 8, 0, -6 }, { 440, 5, 7, 8, 1, -6 }, { 445, 7, 4, 8, 0, -6 }, { 449, 8, 1, 8, 0, 1 }, { 450, 3, 3, 8, 2, -6 }, { 452, 7, 5, 8, 0, -4 }, { 457, 7, 7, 8, 0, -6 }, { 464, 7, 5, 8, 0, -4 }, { 469, 7, 7, 8, 0, -6 }, { 476, 7, 5, 8, 0, -4 }, { 481, 7, 7, 8, 0, -6 }, { 488, 7, 6, 8, 0, -4 }, { 494, 7, 7, 8, 0, -6 }, { 501, 4, 7, 8, 2, -6 }, { 505, 6, 8, 8, 0, -6 }, { 511, 7, 7, 8, 0, -6 }, { 518, 3, 7, 8, 3, -6 }, { 521, 7, 5, 8, 0, -4 }, { 526, 7, 5, 8, 0, -4 }, { 531, 7, 5, 8, 0, -4 }, { 536, 7, 6, 8, 0, -4 }, { 542, 7, 6, 8, 0, -4 }, { 548, 7, 5, 8, 0, -4 }, { 553, 7, 5, 8, 0, -4 }, { 558, 7, 7, 8, 0, -6 }, { 565, 7, 5, 8, 0, -4 }, { 570, 7, 5, 8, 0, -4 }, { 575, 7, 5, 8, 0, -4 }, { 580, 7, 5, 8, 0, -4 }, { 585, 7, 6, 8, 0, -4 }, { 591, 6, 5, 8, 0, -4 }, { 595, 6, 7, 8, 1, -6 }, { 601, 2, 7, 8, 3, -6 }, { 603, 6, 7, 8, 1, -6 }, { 609, 7, 2, 8, 0, -6 }, }; static BitmapFont ati8x8 = { 1, ati8x8_bitmap, ati8x8_glyphs, 16, 126, 8 }; #endif // __ATI8X8_H__
3a723f1ea5442acda7b6af34e8c5e5c59108e5a4
9ceacf33fd96913cac7ef15492c126d96cae6911
/usr.bin/calendar/calendar.c
ad82a94707cbb7cd99b4604f4fbade70f9787747
[]
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
7,349
c
calendar.c
/* $OpenBSD: calendar.c,v 1.37 2019/02/01 16:22:53 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. 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. * 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. */ #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <err.h> #include <errno.h> #include <locale.h> #include <login_cap.h> #include <pwd.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <time.h> #include <unistd.h> #include "pathnames.h" #include "calendar.h" char *calendarFile = "calendar"; /* default calendar file */ char *calendarHome = ".calendar"; /* HOME */ char *calendarNoMail = "nomail"; /* don't sent mail if this file exists */ struct passwd *pw; int doall = 0; int daynames = 0; time_t f_time = 0; int bodun_always = 0; int f_dayAfter = 0; /* days after current date */ int f_dayBefore = 0; /* days before current date */ int f_Setday = 0; /* calendar invoked with -A or -B */ struct specialev spev[NUMEV]; void childsig(int); int main(int argc, char *argv[]) { int ch; const char *errstr; char *caldir; (void)setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "abwf:t:A:B:-")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': if (getuid()) errx(1, "%s", strerror(EPERM)); doall = 1; break; case 'b': bodun_always = 1; break; case 'f': /* other calendar file */ calendarFile = optarg; break; case 't': /* other date, undocumented, for tests */ if ((f_time = Mktime(optarg)) <= 0) errx(1, "specified date is outside allowed range"); break; case 'A': /* days after current date */ f_dayAfter = strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) errx(1, "-A %s: %s", optarg, errstr); f_Setday = 1; break; case 'B': /* days before current date */ f_dayBefore = strtonum(optarg, 0, INT_MAX, &errstr); if (errstr) errx(1, "-B %s: %s", optarg, errstr); if (f_dayBefore != 0) f_Setday = 1; break; case 'w': daynames = 1; break; default: usage(); } argc -= optind; argv += optind; if (argc) usage(); if (doall) { if (pledge("stdio rpath tmppath fattr getpw id proc exec", NULL) == -1) err(1, "pledge"); } else { if (pledge("stdio rpath proc exec", NULL) == -1) err(1, "pledge"); } /* use current time */ if (f_time <= 0) (void)time(&f_time); if (f_dayBefore) { /* Move back in time and only look forwards */ f_dayAfter += f_dayBefore; f_time -= SECSPERDAY * f_dayBefore; f_dayBefore = 0; } settime(&f_time); if (doall) { pid_t kid, deadkid; int kidstat, kidreaped, runningkids; int acstat; struct stat sbuf; time_t t; unsigned int sleeptime; signal(SIGCHLD, childsig); runningkids = 0; t = time(NULL); while ((pw = getpwent()) != NULL) { acstat = 0; /* Avoid unnecessary forks. The calendar file is only * opened as the user later; if it can't be opened, * it's no big deal. Also, get to correct directory. * Note that in an NFS environment root may get EACCES * on a chdir(), in which case we have to fork. As long as * we can chdir() we can stat(), unless the user is * modifying permissions while this is running. */ if (chdir(pw->pw_dir)) { if (errno == EACCES) acstat = 1; else continue; } if (stat(calendarFile, &sbuf) != 0) { if (chdir(calendarHome)) { if (errno == EACCES) acstat = 1; else continue; } if (stat(calendarNoMail, &sbuf) == 0 || stat(calendarFile, &sbuf) != 0) continue; } sleeptime = USERTIMEOUT; switch ((kid = fork())) { case -1: /* error */ warn("fork"); continue; case 0: /* child */ (void)setpgid(getpid(), getpid()); (void)setlocale(LC_ALL, ""); if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL ^ LOGIN_SETLOGIN)) err(1, "unable to set user context (uid %u)", pw->pw_uid); if (acstat) { if (chdir(pw->pw_dir) || stat(calendarFile, &sbuf) != 0 || chdir(calendarHome) || stat(calendarNoMail, &sbuf) == 0 || stat(calendarFile, &sbuf) != 0) exit(0); } cal(); exit(0); } /* parent: wait a reasonable time, then kill child if * necessary. */ runningkids++; kidreaped = 0; do { sleeptime = sleep(sleeptime); /* Note that there is the possibility, if the sleep * stops early due to some other signal, of the child * terminating and not getting detected during the next * sleep. In that unlikely worst case, we just sleep * too long for that user. */ for (;;) { deadkid = waitpid(-1, &kidstat, WNOHANG); if (deadkid <= 0) break; runningkids--; if (deadkid == kid) { kidreaped = 1; sleeptime = 0; } } } while (sleeptime); if (!kidreaped) { /* It doesn't _really_ matter if the kill fails, e.g. * if there's only a zombie now. */ if (getpgid(kid) != getpgrp()) (void)killpg(getpgid(kid), SIGTERM); else (void)kill(kid, SIGTERM); warnx("uid %u did not finish in time", pw->pw_uid); } if (time(NULL) - t >= SECSPERDAY) errx(2, "'calendar -a' took more than a day; " "stopped at uid %u", pw->pw_uid); } for (;;) { deadkid = waitpid(-1, &kidstat, WNOHANG); if (deadkid <= 0) break; runningkids--; } if (runningkids) warnx("%d child processes still running when " "'calendar -a' finished", runningkids); } else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { if(!chdir(caldir)) cal(); } else cal(); exit(0); } void usage(void) { (void)fprintf(stderr, "usage: calendar [-abw] [-A num] [-B num] [-f calendarfile] " "[-t [[[cc]yy]mm]dd]\n"); exit(1); } void childsig(int signo) { }
e5c1a846c299dc1777df5a3c34c7c89c68908a8d
af901bc01d668ecd411549625208b07024df3ffd
/src/internal/nse-inject.h
ff091cee43275b515f9d6d86070d2c71929bf58a
[ "MIT", "BSD-2-Clause" ]
permissive
r-lib/rlang
2784186a4dafb2fde7357c79514b3761803d0e66
c55f6027928d3104ed449e591e8a225fcaf55e13
refs/heads/main
2023-09-06T03:23:47.522921
2023-06-07T17:01:51
2023-06-07T17:01:51
73,098,312
355
128
NOASSERTION
2023-08-31T13:11:13
2016-11-07T16:28:57
R
UTF-8
C
false
false
2,005
h
nse-inject.h
#ifndef RLANG_INTERNAL_NSE_INJECT_H #define RLANG_INTERNAL_NSE_INJECT_H #include <rlang.h> #include "quo.h" #include "utils.h" #define UQ_N 2 #define UQS_N 2 static const char* uqs_names[UQS_N] = { "UQS", "!!!"}; static inline bool is_maybe_rlang_call(r_obj* x, const char* name) { return r_is_call(x, name) || r_is_namespaced_call(x, "rlang", name); } static inline bool is_maybe_rlang_call_any(r_obj* x, const char** names, int n) { return r_is_call_any(x, names, n) || r_is_namespaced_call_any(x, "rlang", names, n); } static inline bool is_splice_call(r_obj* node) { return is_maybe_rlang_call_any(node, uqs_names, UQS_N); } enum injection_op { INJECTION_OP_none, INJECTION_OP_uq, INJECTION_OP_uqs, INJECTION_OP_uqn, INJECTION_OP_fixup, INJECTION_OP_dot_data, INJECTION_OP_curly }; #define INJECTION_OP_MAX 7 struct injection_info { enum injection_op op; r_obj* operand; // Expression being unquoted r_obj* parent; // Node pointing to the future unquoted value r_obj* root; // Expression wrapping the unquoted value (optional) }; static inline struct injection_info init_expansion_info(void) { struct injection_info info; info.op = INJECTION_OP_none; info.operand = r_null; info.parent = r_null; info.root = r_null; return info; } struct injection_info which_uq_op(r_obj* x); struct injection_info which_expansion_op(r_obj* x, bool unquote_names); struct injection_info is_big_bang_op(r_obj* x); r_obj* big_bang_coerce(r_obj* expr); r_obj* ffi_interp(r_obj* x, r_obj* env); r_obj* call_interp(r_obj* x, r_obj* env); r_obj* call_interp_impl(r_obj* x, r_obj* env, struct injection_info info); static inline r_obj* forward_quosure(r_obj* x, r_obj* env) { switch (r_typeof(x)) { case R_TYPE_call: if (is_quosure(x)) { return x; } // else fallthrough case R_TYPE_symbol: case R_TYPE_closure: return ffi_new_quosure(x, env); default: return ffi_new_quosure(x, r_envs.empty); } } #endif
36a9f4644e7dce0f33ffd9481931d95459f7a0ed
b4c2b8dc89417e966a67a433267ebb9c156dbff4
/src/vehicles/sounds/Saurer2DMidle.h
3ef8b59d605d7e739bd18d74df0d719a8f57c230
[]
no_license
TheDIYGuy999/Rc_Engine_Sound_ESP32
92134030dbc047627310d54ccf1fd34fb3cad791
eeeb47964861b66f8e1db34bffe35657846d8b20
refs/heads/master
2023-08-31T00:17:03.698027
2023-05-04T19:46:51
2023-05-04T19:46:51
225,658,413
230
105
null
2023-08-26T14:38:39
2019-12-03T15:51:13
C
UTF-8
C
false
false
18,654
h
Saurer2DMidle.h
const unsigned int sampleRate = 22050; const unsigned int sampleCount = 3748; const signed char samples[] = {//0 0, 0, 1, 1, 1, 0, 2, 4, 7, 5, 11, 15, 13, 7, 8, 9, //16 12, 11, 17, 20, 22, 23, 18, 25, 30, 35, 32, 26, 32, 43, 38, 37, //32 47, 48, 52, 58, 64, 64, 58, 60, 55, 49, 40, 41, 41, 38, 34, 38, //48 42, 40, 32, 28, 32, 29, 29, 37, 42, 50, 53, 58, 61, 61, 57, 54, //64 49, 45, 42, 41, 44, 39, 38, 40, 40, 37, 28, 33, 34, 32, 32, 40, //80 50, 43, 41, 43, 47, 46, 50, 47, 49, 50, 41, 43, 42, 41, 34, 34, //96 46, 53, 56, 61, 72, 74, 59, 60, 59, 58, 53, 50, 51, 49, 49, 48, //112 46, 49, 52, 50, 52, 57, 62, 54, 50, 56, 61, 58, 60, 77, 84, 79, //128 78, 90, 91, 89, 85, 84, 94, 98, 98, 101, 104, 109, 99, 97, 93, 83, //144 80, 86, 88, 84, 88, 96, 100, 96, 95, 95, 93, 86, 81, 75, 69, 76, //160 74, 70, 73, 78, 79, 85, 92, 90, 94, 92, 96, 96, 97, 104, 106, 110, //176 104, 107, 103, 93, 93, 95, 92, 84, 77, 80, 89, 91, 83, 85, 91, 90, //192 84, 85, 92, 97, 91, 87, 93, 91, 84, 78, 77, 79, 80, 83, 82, 78, //208 78, 78, 81, 79, 81, 85, 85, 93, 93, 93, 92, 91, 87, 86, 83, 81, //224 79, 72, 73, 60, 56, 54, 51, 48, 47, 47, 42, 46, 48, 49, 49, 49, //240 46, 45, 43, 37, 44, 44, 44, 47, 47, 46, 41, 38, 38, 36, 29, 26, //256 25, 26, 25, 24, 24, 27, 30, 29, 35, 34, 34, 36, 35, 34, 26, 22, //272 17, 12, 7, 4, 6, 7, 5, 6, 1, -6, 0, 1, -1, -3, 0, 8, //288 10, 12, 14, 17, 15, 11, 8, 4, 2, -5, -9, -8, -2, -6, -10, -5, //304 -5, -6, -7, -7, -6, -14, -22, -24, -21, -19, -23, -22, -18, -16, -19, -25, //320 -26, -29, -37, -37, -33, -31, -33, -34, -34, -39, -42, -41, -40, -47, -45, -41, //336 -41, -43, -43, -39, -37, -47, -49, -49, -53, -54, -54, -51, -54, -62, -68, -66, //352 -63, -63, -68, -66, -67, -70, -69, -72, -72, -69, -74, -71, -68, -67, -65, -68, //368 -73, -71, -68, -74, -73, -70, -65, -65, -63, -54, -45, -45, -45, -42, -37, -36, //384 -37, -35, -36, -41, -43, -42, -43, -51, -55, -58, -61, -69, -68, -59, -60, -62, //400 -61, -57, -59, -63, -60, -63, -65, -68, -70, -66, -70, -74, -78, -80, -83, -84, //416 -81, -79, -77, -78, -77, -71, -68, -69, -61, -55, -56, -56, -57, -52, -58, -61, //432 -65, -70, -75, -78, -78, -78, -81, -80, -77, -79, -78, -77, -71, -67, -65, -62, //448 -55, -49, -47, -44, -44, -44, -45, -49, -50, -52, -60, -62, -61, -59, -57, -60, //464 -49, -44, -45, -44, -44, -44, -41, -42, -41, -36, -37, -37, -35, -36, -42, -46, //480 -42, -47, -53, -60, -56, -50, -55, -56, -54, -53, -56, -56, -44, -44, -43, -40, //496 -34, -33, -40, -34, -33, -42, -45, -49, -48, -48, -57, -56, -58, -61, -65, -67, //512 -59, -60, -70, -75, -77, -75, -77, -76, -67, -67, -65, -65, -70, -68, -73, -77, //528 -74, -77, -69, -66, -66, -60, -65, -61, -62, -67, -60, -60, -60, -57, -56, -49, //544 -47, -50, -57, -59, -58, -58, -60, -62, -63, -62, -67, -72, -68, -68, -73, -78, //560 -74, -69, -69, -62, -55, -52, -51, -47, -48, -49, -49, -46, -44, -48, -47, -41, //576 -36, -37, -37, -43, -40, -37, -34, -35, -37, -27, -23, -28, -26, -23, -19, -24, //592 -29, -24, -25, -24, -22, -17, -13, -16, -21, -23, -21, -20, -21, -11, -11, -14, //608 -7, -5, -11, -17, -13, -11, -18, -16, -8, -4, -6, -2, 11, 12, 3, 5, //624 7, 2, -6, -5, 6, 11, 8, 9, 18, 12, 17, 22, 22, 27, 22, 32, //640 31, 23, 19, 20, 23, 21, 25, 31, 33, 26, 26, 38, 40, 36, 40, 43, //656 34, 29, 32, 43, 40, 41, 49, 48, 44, 35, 38, 39, 28, 32, 34, 37, //672 37, 42, 47, 48, 41, 47, 47, 47, 50, 52, 58, 60, 58, 62, 56, 52, //688 47, 48, 45, 41, 50, 52, 51, 55, 60, 62, 52, 48, 48, 41, 43, 47, //704 57, 56, 53, 58, 52, 42, 35, 43, 47, 43, 48, 56, 67, 60, 60, 69, //720 62, 53, 50, 55, 58, 61, 65, 64, 60, 50, 47, 52, 52, 56, 68, 85, //736 90, 91, 95, 92, 85, 78, 74, 78, 83, 78, 76, 77, 78, 76, 70, 76, //752 75, 73, 80, 84, 86, 83, 80, 83, 80, 79, 75, 76, 88, 87, 81, 86, //768 98, 109, 101, 104, 112, 116, 116, 111, 112, 114, 109, 105, 104, 105, 104, 97, //784 99, 104, 99, 95, 90, 88, 88, 80, 74, 69, 72, 75, 80, 87, 82, 90, //800 86, 76, 75, 81, 81, 76, 74, 69, 75, 77, 77, 82, 87, 97, 102, 98, //816 103, 98, 85, 73, 70, 74, 71, 65, 65, 65, 67, 55, 56, 59, 60, 57, //832 57, 60, 57, 52, 42, 49, 46, 41, 49, 51, 56, 52, 61, 70, 69, 62, //848 58, 69, 69, 66, 68, 77, 76, 65, 55, 56, 51, 35, 29, 31, 35, 25, //864 16, 17, 13, 2, -5, -2, 1, 0, -4, 6, 14, 12, 14, 14, 21, 18, //880 9, 8, 7, 8, 1, -2, 5, 8, -6, -15, -14, -5, -9, -11, -12, -7, //896 -4, -10, -7, -9, -2, -3, -5, -5, -7, -8, -18, -17, -14, -12, -10, -8, //912 -2, -3, -4, 0, -4, -8, -11, -1, 2, 0, 12, 20, 22, 16, 15, 15, //928 9, 1, -4, 4, 3, -2, 3, 9, 14, 7, 11, 18, 7, 2, 0, 1, //944 -8, -25, -19, -19, -25, -26, -18, -14, -21, -23, -22, -19, -20, -18, -15, -12, //960 -13, -18, -14, -16, -16, -15, -19, -8, -10, -13, -19, -12, -3, -20, -24, -28, //976 -30, -34, -44, -48, -48, -47, -50, -51, -43, -47, -52, -60, -70, -67, -72, -73, //992 -71, -65, -57, -59, -58, -54, -52, -56, -57, -51, -46, -49, -54, -55, -55, -54, //1008 -58, -60, -59, -65, -67, -71, -68, -62, -59, -53, -49, -44, -43, -42, -41, -50, //1024 -56, -61, -62, -67, -66, -55, -56, -53, -52, -54, -55, -65, -67, -71, -74, -69, //1040 -67, -63, -65, -68, -65, -68, -74, -71, -75, -76, -82, -85, -81, -82, -83, -85, //1056 -86, -84, -86, -79, -78, -78, -77, -76, -74, -78, -81, -82, -85, -81, -80, -86, //1072 -88, -88, -87, -83, -84, -77, -73, -76, -65, -65, -62, -65, -68, -61, -62, -65, //1088 -63, -59, -54, -56, -63, -62, -60, -69, -72, -69, -67, -62, -61, -58, -50, -44, //1104 -45, -46, -45, -44, -45, -44, -42, -39, -37, -33, -32, -26, -22, -25, -27, -27, //1120 -25, -29, -34, -36, -37, -35, -39, -36, -41, -38, -36, -44, -51, -58, -60, -54, //1136 -57, -60, -57, -54, -48, -47, -52, -49, -44, -44, -44, -42, -46, -44, -44, -45, //1152 -44, -43, -35, -40, -50, -52, -49, -45, -54, -55, -55, -56, -56, -49, -45, -49, //1168 -55, -59, -66, -66, -62, -66, -70, -69, -59, -58, -66, -60, -50, -50, -55, -55, //1184 -49, -42, -45, -51, -47, -45, -48, -55, -45, -48, -49, -42, -41, -37, -42, -42, //1200 -37, -40, -40, -40, -38, -39, -36, -31, -36, -40, -35, -35, -38, -45, -41, -37, //1216 -41, -36, -34, -34, -31, -31, -25, -25, -26, -29, -28, -20, -14, -10, -8, -8, //1232 -6, -16, -18, -13, -12, -14, -10, -8, -5, -9, -8, -2, -7, -7, -12, -10, //1248 -16, -14, -4, -11, -5, 0, 8, 12, 8, 8, 12, 7, 6, 7, 1, 8, //1264 6, -1, 7, 12, 9, 11, 11, 18, 26, 25, 33, 33, 33, 35, 35, 35, //1280 38, 42, 41, 40, 41, 43, 35, 29, 34, 36, 37, 42, 49, 56, 55, 52, //1296 49, 50, 47, 43, 50, 51, 60, 62, 65, 60, 54, 51, 41, 38, 43, 44, //1312 48, 44, 49, 58, 57, 55, 60, 58, 59, 57, 54, 65, 62, 60, 65, 62, //1328 55, 59, 56, 53, 52, 53, 61, 61, 58, 55, 51, 47, 45, 48, 45, 49, //1344 58, 58, 54, 54, 57, 56, 46, 52, 61, 67, 64, 61, 60, 70, 71, 65, //1360 67, 73, 76, 78, 75, 75, 74, 70, 72, 65, 68, 71, 74, 77, 75, 77, //1376 81, 71, 67, 74, 77, 75, 75, 80, 88, 82, 77, 76, 73, 74, 78, 81, //1392 88, 92, 94, 106, 103, 91, 89, 86, 91, 91, 83, 82, 88, 88, 85, 85, //1408 88, 94, 89, 85, 83, 91, 96, 83, 82, 94, 95, 86, 83, 94, 93, 88, //1424 83, 87, 76, 72, 66, 59, 59, 66, 71, 69, 70, 75, 75, 60, 61, 64, //1440 53, 45, 42, 42, 44, 41, 41, 44, 48, 49, 44, 43, 44, 35, 34, 34, //1456 32, 35, 34, 45, 41, 36, 44, 39, 36, 33, 34, 35, 31, 31, 34, 31, //1472 29, 27, 29, 30, 37, 32, 30, 39, 39, 39, 38, 41, 46, 46, 45, 43, //1488 42, 42, 48, 48, 38, 41, 42, 35, 33, 35, 37, 27, 20, 26, 30, 29, //1504 18, 19, 30, 27, 23, 22, 22, 26, 26, 29, 31, 30, 27, 25, 34, 37, //1520 33, 33, 33, 30, 26, 24, 26, 28, 25, 26, 30, 29, 25, 10, 12, 7, //1536 -1, -1, -6, -3, -2, -7, -8, -4, -2, 2, -9, -8, 0, -5, -5, -3, //1552 2, 8, 6, 8, 15, 16, 14, 9, 7, 7, 7, 5, -4, 1, 8, 6, //1568 5, 4, 5, 2, -10, -8, -7, -8, -10, -7, -3, -3, -6, -9, -6, -12, //1584 -16, -17, -17, -19, -22, -16, -12, -9, -18, -25, -21, -26, -31, -37, -41, -38, //1600 -38, -41, -42, -44, -42, -40, -48, -44, -41, -43, -48, -52, -45, -48, -54, -55, //1616 -54, -53, -66, -68, -66, -63, -67, -72, -70, -74, -77, -81, -84, -83, -84, -78, //1632 -77, -78, -78, -79, -80, -84, -87, -84, -90, -86, -84, -82, -84, -86, -79, -78, //1648 -77, -76, -78, -76, -74, -70, -70, -69, -67, -72, -67, -68, -71, -72, -76, -77, //1664 -81, -85, -81, -86, -81, -80, -78, -78, -76, -69, -68, -68, -66, -63, -67, -69, //1680 -59, -53, -52, -57, -53, -49, -49, -45, -40, -32, -27, -35, -35, -37, -40, -41, //1696 -41, -38, -36, -38, -35, -35, -47, -49, -55, -52, -58, -58, -51, -53, -53, -56, //1712 -56, -55, -63, -67, -63, -54, -66, -60, -48, -41, -40, -51, -53, -42, -44, -47, //1728 -46, -44, -46, -46, -42, -38, -42, -45, -47, -53, -54, -51, -55, -61, -63, -59, //1744 -59, -66, -63, -54, -59, -58, -62, -63, -58, -60, -60, -59, -60, -55, -48, -46, //1760 -44, -49, -54, -51, -49, -45, -39, -39, -36, -32, -27, -32, -41, -34, -34, -41, //1776 -48, -45, -43, -49, -50, -45, -45, -51, -54, -52, -51, -57, -58, -49, -45, -49, //1792 -52, -43, -42, -49, -52, -47, -46, -48, -54, -59, -56, -56, -65, -71, -58, -45, //1808 -49, -52, -45, -37, -40, -49, -55, -59, -59, -60, -57, -54, -52, -52, -56, -53, //1824 -48, -48, -61, -61, -54, -58, -61, -56, -46, -46, -47, -48, -51, -50, -44, -42, //1840 -39, -38, -36, -31, -24, -20, -24, -22, -23, -24, -20, -14, -13, -16, -18, -15, //1856 -10, -12, -13, -9, -4, 1, 0, -1, -8, -5, -6, -4, -2, 5, 8, 3, //1872 12, 12, 10, 14, 14, 15, 10, 7, 8, 6, 6, 20, 17, 22, 28, 32, //1888 35, 42, 44, 36, 30, 29, 32, 36, 35, 40, 38, 39, 41, 38, 47, 51, //1904 47, 37, 29, 33, 30, 32, 36, 38, 40, 40, 39, 40, 43, 42, 41, 41, //1920 31, 31, 37, 26, 26, 27, 33, 41, 47, 55, 56, 51, 48, 40, 39, 41, //1936 46, 51, 50, 54, 60, 67, 69, 70, 73, 51, 47, 44, 46, 48, 54, 66, //1952 58, 60, 66, 61, 55, 52, 57, 58, 61, 64, 65, 68, 67, 71, 73, 72, //1968 72, 70, 72, 68, 59, 61, 72, 67, 62, 60, 62, 67, 58, 59, 61, 62, //1984 60, 54, 58, 58, 50, 48, 60, 74, 81, 77, 75, 87, 75, 67, 66, 67, //2000 67, 65, 68, 68, 65, 67, 75, 84, 83, 85, 84, 74, 77, 79, 82, 81, //2016 81, 89, 92, 93, 92, 86, 85, 83, 75, 73, 73, 73, 75, 69, 67, 71, //2032 66, 69, 73, 75, 75, 73, 77, 75, 76, 82, 85, 84, 82, 90, 97, 83, //2048 79, 77, 69, 61, 60, 67, 71, 71, 71, 69, 70, 73, 77, 67, 64, 66, //2064 69, 67, 66, 69, 71, 69, 74, 71, 59, 60, 68, 62, 62, 58, 60, 61, //2080 52, 44, 54, 57, 54, 56, 62, 64, 49, 44, 53, 51, 43, 49, 56, 55, //2096 52, 56, 70, 66, 53, 52, 53, 51, 41, 38, 42, 36, 29, 30, 32, 30, //2112 21, 20, 21, 22, 22, 17, 19, 26, 24, 26, 24, 31, 37, 35, 41, 40, //2128 42, 36, 31, 26, 24, 25, 30, 32, 33, 35, 37, 32, 32, 27, 25, 26, //2144 22, 20, 16, 15, 10, 7, 5, 1, -4, -10, -12, -12, -11, -8, -8, -5, //2160 -7, -4, -3, 0, -6, -11, -6, -10, -10, -13, -11, -1, 5, 7, -1, 2, //2176 10, 4, 10, 10, 7, 2, -1, -7, -8, -9, -11, -21, -26, -30, -34, -37, //2192 -42, -38, -34, -39, -37, -35, -31, -30, -35, -33, -36, -42, -43, -34, -32, -32, //2208 -36, -38, -34, -37, -40, -43, -40, -38, -36, -35, -30, -24, -25, -28, -30, -30, //2224 -31, -39, -41, -42, -47, -47, -44, -43, -49, -50, -55, -58, -58, -59, -56, -59, //2240 -66, -62, -57, -61, -63, -59, -56, -58, -60, -54, -51, -50, -50, -47, -39, -46, //2256 -51, -54, -56, -53, -56, -53, -59, -65, -61, -63, -68, -70, -68, -66, -65, -63, //2272 -65, -75, -79, -76, -79, -73, -61, -68, -69, -74, -79, -80, -85, -90, -88, -84, //2288 -78, -72, -65, -63, -71, -73, -72, -70, -70, -74, -72, -71, -72, -75, -86, -85, //2304 -82, -77, -70, -73, -74, -77, -83, -78, -71, -70, -74, -70, -61, -56, -57, -59, //2320 -48, -51, -62, -66, -63, -60, -68, -62, -48, -50, -57, -54, -53, -51, -51, -53, //2336 -48, -44, -44, -44, -43, -41, -46, -46, -41, -42, -47, -44, -40, -41, -46, -41, //2352 -36, -39, -40, -37, -35, -36, -31, -30, -33, -37, -34, -28, -33, -32, -34, -34, //2368 -30, -30, -29, -30, -38, -47, -48, -38, -41, -45, -42, -34, -32, -41, -43, -45, //2384 -52, -54, -52, -47, -47, -51, -51, -53, -54, -56, -55, -62, -67, -53, -59, -62, //2400 -56, -55, -55, -62, -62, -55, -48, -45, -42, -33, -31, -32, -40, -43, -43, -42, //2416 -46, -47, -47, -43, -49, -57, -55, -58, -66, -68, -58, -57, -56, -48, -44, -47, //2432 -45, -47, -43, -45, -53, -49, -40, -43, -48, -49, -47, -42, -44, -43, -40, -47, //2448 -51, -47, -36, -34, -40, -42, -40, -31, -23, -15, -14, -15, -18, -20, -17, -23, //2464 -26, -28, -28, -26, -31, -27, -27, -31, -18, -15, -19, -23, -27, -23, -17, -13, //2480 -12, -22, -19, -13, -19, -11, -19, -17, -5, -9, -7, -17, -16, -14, -10, 1, //2496 -3, -5, -11, -1, 6, 6, 8, 11, 17, 16, 21, 23, 13, 11, 10, 16, //2512 10, 12, 21, 24, 25, 28, 21, 18, 16, 20, 21, 22, 30, 26, 32, 36, //2528 26, 41, 41, 36, 37, 39, 36, 31, 30, 34, 36, 39, 46, 48, 44, 34, //2544 30, 45, 47, 44, 38, 37, 35, 37, 42, 46, 44, 43, 44, 32, 31, 26, //2560 28, 45, 40, 44, 41, 50, 69, 67, 72, 54, 44, 44, 36, 35, 26, 34, //2576 47, 54, 60, 48, 44, 54, 53, 53, 56, 49, 48, 38, 41, 58, 49, 52, //2592 57, 65, 69, 59, 69, 73, 71, 64, 60, 73, 70, 65, 72, 77, 77, 68, //2608 61, 67, 72, 67, 71, 76, 86, 87, 73, 78, 88, 93, 100, 93, 85, 82, //2624 86, 89, 89, 84, 80, 87, 100, 100, 97, 99, 97, 97, 98, 90, 91, 91, //2640 90, 96, 99, 98, 93, 87, 88, 92, 89, 84, 88, 84, 85, 91, 89, 92, //2656 92, 86, 88, 89, 93, 93, 87, 85, 87, 93, 92, 86, 89, 78, 81, 86, //2672 89, 91, 85, 87, 90, 89, 84, 77, 76, 77, 62, 57, 61, 56, 60, 56, //2688 54, 52, 46, 46, 48, 53, 58, 57, 56, 57, 55, 59, 59, 54, 55, 50, //2704 53, 58, 54, 51, 47, 51, 55, 56, 61, 56, 50, 47, 46, 46, 43, 46, //2720 55, 53, 47, 50, 55, 59, 50, 43, 44, 45, 47, 48, 44, 36, 42, 50, //2736 53, 47, 43, 45, 42, 43, 40, 38, 38, 32, 33, 34, 36, 32, 32, 33, //2752 34, 33, 28, 22, 27, 29, 25, 20, 20, 21, 20, 19, 22, 15, 9, 8, //2768 11, 12, 20, 25, 21, 15, 12, 13, 21, 1, -3, 5, 10, 9, 1, 10, //2784 11, 1, -4, 2, 4, 0, 7, 17, 22, 13, 17, 15, 8, -1, -3, 1, //2800 -12, -12, -11, -10, -3, -4, -9, -14, -8, -14, -14, -17, -23, -28, -34, -28, //2816 -21, -28, -24, -23, -22, -25, -29, -33, -43, -41, -38, -28, -31, -35, -30, -30, //2832 -28, -42, -40, -32, -27, -27, -34, -38, -45, -42, -44, -43, -41, -49, -45, -48, //2848 -58, -62, -71, -73, -75, -73, -73, -67, -62, -59, -55, -56, -60, -66, -63, -58, //2864 -57, -57, -66, -66, -67, -65, -65, -72, -70, -69, -65, -68, -78, -74, -83, -75, //2880 -73, -75, -72, -74, -76, -76, -71, -68, -69, -72, -79, -81, -77, -71, -66, -68, //2896 -70, -62, -66, -74, -72, -56, -55, -51, -52, -55, -57, -68, -60, -58, -63, -74, //2912 -69, -72, -72, -72, -73, -74, -79, -81, -82, -75, -77, -83, -75, -76, -71, -66, //2928 -62, -66, -65, -62, -62, -66, -72, -76, -75, -76, -77, -73, -73, -72, -74, -74, //2944 -71, -70, -70, -71, -62, -67, -70, -72, -73, -74, -75, -71, -72, -75, -68, -58, //2960 -54, -60, -70, -70, -70, -77, -75, -69, -67, -67, -65, -57, -58, -56, -59, -48, //2976 -42, -47, -48, -52, -49, -48, -53, -49, -44, -42, -52, -52, -52, -49, -48, -56, //2992 -47, -38, -35, -37, -37, -22, -31, -35, -43, -46, -41, -47, -43, -41, -43, -43, //3008 -36, -41, -46, -45, -41, -42, -48, -44, -49, -50, -46, -54, -55, -53, -58, -65, //3024 -50, -41, -40, -47, -47, -45, -46, -55, -56, -43, -43, -48, -45, -44, -45, -48, //3040 -51, -54, -50, -45, -40, -42, -45, -45, -36, -40, -43, -37, -40, -47, -61, -52, //3056 -50, -52, -54, -57, -47, -46, -49, -55, -61, -55, -58, -52, -49, -55, -54, -48, //3072 -41, -43, -54, -55, -43, -46, -46, -38, -41, -45, -46, -44, -48, -48, -46, -46, //3088 -35, -26, -23, -17, -20, -43, -38, -22, -21, -23, -31, -10, -14, -18, -19, -17, //3104 -6, -18, -17, -15, -19, -21, -17, -11, -14, -17, -18, -16, -13, -8, -5, -9, //3120 -9, -11, -4, 7, 12, 11, 9, 19, 15, 14, 17, 10, 5, 12, 12, 14, //3136 12, 6, 15, 8, 0, 8, 18, 18, 22, 26, 21, 16, 22, 32, 32, 19, //3152 12, 14, 16, 16, 31, 34, 36, 35, 34, 35, 34, 38, 35, 36, 41, 34, //3168 44, 51, 42, 35, 27, 27, 21, 24, 32, 38, 51, 50, 49, 46, 33, 31, //3184 43, 40, 40, 47, 54, 51, 61, 70, 71, 68, 68, 66, 58, 57, 59, 59, //3200 66, 59, 62, 64, 67, 62, 60, 58, 56, 64, 58, 56, 61, 62, 67, 67, //3216 69, 73, 71, 72, 72, 73, 75, 67, 59, 57, 71, 77, 66, 79, 92, 92, //3232 86, 78, 99, 101, 89, 91, 100, 96, 66, 80, 97, 95, 91, 93, 98, 101, //3248 99, 97, 98, 90, 88, 94, 89, 83, 77, 75, 89, 96, 93, 88, 84, 80, //3264 85, 94, 96, 95, 94, 97, 99, 86, 81, 88, 103, 106, 106, 117, 124, 127, //3280 124, 122, 115, 103, 99, 95, 93, 97, 101, 110, 110, 104, 105, 104, 95, 87, //3296 90, 90, 74, 77, 86, 83, 79, 82, 86, 75, 67, 69, 65, 57, 52, 62, //3312 66, 53, 48, 55, 55, 60, 67, 71, 70, 62, 64, 59, 50, 36, 36, 40, //3328 36, 36, 35, 32, 44, 51, 45, 39, 28, 33, 30, 25, 28, 29, 23, 16, //3344 17, 25, 19, 25, 29, 27, 27, 26, 21, 23, 26, 25, 31, 30, 34, 43, //3360 47, 44, 41, 43, 39, 38, 39, 32, 33, 36, 32, 25, 19, 26, 24, 22, //3376 26, 22, 20, 19, 26, 31, 21, 28, 21, 14, 11, 18, 20, 10, 20, 29, //3392 26, 17, 17, 23, 17, 15, 23, 14, 11, 18, 20, 20, 18, 8, 7, 7, //3408 6, 6, -3, -3, -4, -1, 1, 1, -1, -7, -8, -6, -11, -11, -15, -13, //3424 -13, -21, -19, -15, -11, -7, -11, -16, -13, -15, -20, -19, -22, -21, -15, -17, //3440 -13, -12, -17, -20, -23, -19, -24, -28, -16, -23, -24, -19, -15, -13, -17, -19, //3456 -16, -21, -25, -21, -18, -24, -29, -26, -22, -22, -28, -33, -33, -28, -27, -27, //3472 -15, -15, -21, -24, -31, -30, -35, -38, -38, -36, -38, -41, -44, -48, -45, -40, //3488 -40, -54, -57, -50, -53, -61, -65, -68, -63, -65, -66, -63, -61, -67, -66, -69, //3504 -69, -73, -71, -70, -72, -67, -59, -61, -58, -55, -67, -70, -63, -60, -50, -54, //3520 -60, -63, -67, -62, -61, -55, -55, -62, -60, -66, -76, -78, -80, -86, -86, -83, //3536 -82, -87, -86, -79, -73, -80, -81, -75, -73, -77, -65, -56, -62, -67, -62, -62, //3552 -66, -70, -63, -59, -62, -63, -61, -60, -58, -59, -59, -57, -57, -56, -55, -54, //3568 -47, -41, -42, -45, -48, -51, -50, -45, -39, -38, -37, -45, -47, -46, -48, -45, //3584 -46, -47, -42, -44, -47, -53, -52, -49, -45, -41, -43, -47, -42, -34, -32, -34, //3600 -37, -39, -42, -43, -47, -48, -46, -53, -53, -45, -45, -49, -52, -45, -45, -49, //3616 -48, -48, -46, -43, -42, -33, -36, -39, -41, -52, -54, -56, -51, -43, -51, -49, //3632 -50, -49, -43, -47, -46, -52, -52, -48, -47, -43, -40, -34, -35, -43, -43, -50, //3648 -53, -55, -55, -51, -50, -53, -46, -45, -46, -48, -54, -51, -54, -58, -55, -55, //3664 -49, -52, -47, -43, -47, -49, -58, -54, -51, -57, -54, -66, -61, -59, -58, -57, //3680 -66, -59, -58, -61, -63, -69, -59, -61, -63, -59, -63, -59, -54, -46, -45, -47, //3696 -46, -48, -50, -45, -46, -45, -47, -48, -45, -40, -37, -33, -37, -36, -39, -33, //3712 -34, -38, -38, -39, -34, -33, -33, -31, -32, -34, -33, -30, -28, -27, -27, -24, //3728 -23, -19, -17, -16, -19, -12, -11, -10, -9, -6, -4, -4, -4, -1, -1, 0, //3744 3, 2, 0, 0, };
d2dca808f7d27984897c411840e2325fb0eea24f
1230e0eecf094c565eee44b683fb2bf24537b75b
/STM32HAL/BMP085/BMP085.c
2019384257ea0097e2e32081ca9d4a85981c6e94
[ "MIT" ]
permissive
jrowberg/i2cdevlib
c8f9ebc2c954b51a901bc24dc0d8e9db1ff8c82c
605a7401b05baebef146dc5caa3d0e8e15841e49
refs/heads/master
2023-08-25T02:58:46.489760
2023-05-28T19:23:01
2023-05-28T19:23:01
2,105,143
3,548
7,325
null
2023-05-28T19:23:02
2011-07-26T04:58:39
C++
UTF-8
C
false
false
9,442
c
BMP085.c
// I2Cdev library collection - BMP085 I2C device class // Based on register information stored in the I2Cdevlib internal database // 2012-06-28 by Jeff Rowberg <jeff@rowberg.net> // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib // 2015-06-06 by Andrey Voloshin <voloshin@think.in.ua> // // Changelog: // 2015-06-06 - ported to STM32 HAL library from Arduino code /* ============================================ I2Cdev device library code is placed under the MIT license Copyright (c) 2012 Jeff Rowberg 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 "BMP085.h" static uint8_t devAddr = BMP085_DEFAULT_ADDRESS; static uint8_t buffer[3]; static bool calibrationLoaded; static int16_t ac1, ac2, ac3, b1, b2, mb, mc, md; static uint16_t ac4, ac5, ac6; static int32_t b5; static uint8_t measureMode; /** * Specific address constructor. * @param address Specific device address * @see BMP085_DEFAULT_ADDRESS */ void BMP085_setAddress(uint8_t address) { devAddr = address; } /** * Prepare device for normal usage. */ void BMP085_initialize() { if (devAddr==0) devAddr = BMP085_DEFAULT_ADDRESS; // load sensor's calibration constants BMP085_loadCalibration(); } /** * Verify the device is connected and available. */ bool BMP085_testConnection() { // test for a response, though this is very basic return I2Cdev_readByte(devAddr, BMP085_RA_AC1_H, buffer, 100) == 1; } /* calibration register methods */ void BMP085_loadCalibration() { uint8_t buf2[22]; I2Cdev_readBytes(devAddr, BMP085_RA_AC1_H, 22, buf2, 1000); ac1 = ((int16_t)buf2[0] << 8) + buf2[1]; ac2 = ((int16_t)buf2[2] << 8) + buf2[3]; ac3 = ((int16_t)buf2[4] << 8) + buf2[5]; ac4 = ((uint16_t)buf2[6] << 8) + buf2[7]; ac5 = ((uint16_t)buf2[8] << 8) + buf2[9]; ac6 = ((uint16_t)buf2[10] << 8) + buf2[11]; b1 = ((int16_t)buf2[12] << 8) + buf2[13]; b2 = ((int16_t)buf2[14] << 8) + buf2[15]; mb = ((int16_t)buf2[16] << 8) + buf2[17]; mc = ((int16_t)buf2[18] << 8) + buf2[19]; md = ((int16_t)buf2[20] << 8) + buf2[21]; calibrationLoaded = true; } #ifdef BMP085_INCLUDE_INDIVIDUAL_CALIBRATION_ACCESS int16_t BMP085_getAC1() { if (calibrationLoaded) return ac1; I2Cdev_readBytes(devAddr, BMP085_RA_AC1_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getAC2() { if (calibrationLoaded) return ac2; I2Cdev_readBytes(devAddr, BMP085_RA_AC2_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getAC3() { if (calibrationLoaded) return ac3; I2Cdev_readBytes(devAddr, BMP085_RA_AC3_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } uint16_t BMP085_getAC4() { if (calibrationLoaded) return ac4; I2Cdev_readBytes(devAddr, BMP085_RA_AC4_H, 2, buffer); return ((uint16_t)buffer[1] << 8) + buffer[0]; } uint16_t BMP085_getAC5() { if (calibrationLoaded) return ac5; I2Cdev_readBytes(devAddr, BMP085_RA_AC5_H, 2, buffer); return ((uint16_t)buffer[1] << 8) + buffer[0]; } uint16_t BMP085_getAC6() { if (calibrationLoaded) return ac6; I2Cdev_readBytes(devAddr, BMP085_RA_AC6_H, 2, buffer); return ((uint16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getB1() { if (calibrationLoaded) return b1; I2Cdev_readBytes(devAddr, BMP085_RA_B1_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getB2() { if (calibrationLoaded) return b2; I2Cdev_readBytes(devAddr, BMP085_RA_B2_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getMB() { if (calibrationLoaded) return mb; I2Cdev_readBytes(devAddr, BMP085_RA_MB_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getMC() { if (calibrationLoaded) return mc; I2Cdev_readBytes(devAddr, BMP085_RA_MC_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } int16_t BMP085_getMD() { if (calibrationLoaded) return md; I2Cdev_readBytes(devAddr, BMP085_RA_MD_H, 2, buffer); return ((int16_t)buffer[1] << 8) + buffer[0]; } #endif /* control register methods */ uint8_t BMP085_getControl() { I2Cdev_readByte(devAddr, BMP085_RA_CONTROL, buffer, 1000); return buffer[0]; } void BMP085_setControl(uint8_t value) { I2Cdev_writeByte(devAddr, BMP085_RA_CONTROL, value); measureMode = value; } /* measurement register methods */ uint16_t BMP085_getMeasurement2() { I2Cdev_readBytes(devAddr, BMP085_RA_MSB, 2, buffer, 1000); return ((uint16_t) buffer[0] << 8) + buffer[1]; } uint32_t BMP085_getMeasurement3() { I2Cdev_readBytes(devAddr, BMP085_RA_MSB, 3, buffer, 1000); return ((uint32_t)buffer[0] << 16) + ((uint16_t)buffer[1] << 8) + buffer[2]; } uint8_t BMP085_getMeasureDelayMilliseconds(uint8_t mode) { if (mode == 0) mode = measureMode; if (measureMode == 0x2E) return 5; else if (measureMode == 0x34) return 5; else if (measureMode == 0x74) return 8; else if (measureMode == 0xB4) return 14; else if (measureMode == 0xF4) return 26; return 0; // invalid mode } uint16_t BMP085_getMeasureDelayMicroseconds(uint8_t mode) { if (mode == 0) mode = measureMode; if (measureMode == 0x2E) return 4500; else if (measureMode == 0x34) return 4500; else if (measureMode == 0x74) return 7500; else if (measureMode == 0xB4) return 13500; else if (measureMode == 0xF4) return 25500; return 0; // invalid mode } uint16_t BMP085_getRawTemperature() { if (measureMode == 0x2E) return BMP085_getMeasurement2(); return 0; // wrong measurement mode for temperature request } float BMP085_getTemperatureC() { /* Datasheet formula: UT = raw temperature X1 = (UT - AC6) * AC5 / 2^15 X2 = MC * 2^11 / (X1 + MD) B5 = X1 + X2 T = (B5 + 8) / 2^4 */ int32_t ut = BMP085_getRawTemperature(); int32_t x1 = ((ut - (int32_t)ac6) * (int32_t)ac5) >> 15; int32_t x2 = ((int32_t)mc << 11) / (x1 + md); b5 = x1 + x2; return (float)((b5 + 8) >> 4) / 10.0f; } float BMP085_getTemperatureF() { return BMP085_getTemperatureC() * 9.0f / 5.0f + 32; } uint32_t BMP085_getRawPressure() { if (measureMode & 0x34) return BMP085_getMeasurement3() >> (8 - ((measureMode & 0xC0) >> 6)); return 0; // wrong measurement mode for pressure request } float BMP085_getPressure() { /* Datasheet forumla UP = raw pressure B6 = B5 - 4000 X1 = (B2 * (B6 * B6 / 2^12)) / 2^11 X2 = AC2 * B6 / 2^11 X3 = X1 + X2 B3 = ((AC1 * 4 + X3) << oss + 2) / 4 X1 = AC3 * B6 / 2^13 X2 = (B1 * (B6 * B6 / 2^12)) / 2^16 X3 = ((X1 + X2) + 2) / 2^2 B4 = AC4 * (unsigned long)(X3 + 32768) / 2^15 B7 = ((unsigned long)UP - B3) * (50000 >> oss) if (B7 < 0x80000000) { p = (B7 * 2) / B4 } else { p = (B7 / B4) * 2 } X1 = (p / 2^8) * (p / 2^8) X1 = (X1 * 3038) / 2^16 X2 = (-7357 * p) / 2^16 p = p + (X1 + X2 + 3791) / 2^4 */ uint32_t up = BMP085_getRawPressure(); uint8_t oss = (measureMode & 0xC0) >> 6; int32_t p; int32_t b6 = b5 - 4000; int32_t x1 = ((int32_t)b2 * ((b6 * b6) >> 12)) >> 11; int32_t x2 = ((int32_t)ac2 * b6) >> 11; int32_t x3 = x1 + x2; int32_t b3 = ((((int32_t)ac1 * 4 + x3) << oss) + 2) >> 2; x1 = ((int32_t)ac3 * b6) >> 13; x2 = ((int32_t)b1 * ((b6 * b6) >> 12)) >> 16; x3 = ((x1 + x2) + 2) >> 2; uint32_t b4 = ((uint32_t)ac4 * (uint32_t)(x3 + 32768)) >> 15; uint32_t b7 = ((uint32_t)up - b3) * (uint32_t)(50000UL >> oss); if (b7 < 0x80000000) { p = (b7 << 1) / b4; } else { p = (b7 / b4) << 1; } x1 = (p >> 8) * (p >> 8); x1 = (x1 * 3038) >> 16; x2 = (-7357 * p) >> 16; return p + ((x1 + x2 + (int32_t)3791) >> 4); } float BMP085_getAltitude(float pressure, float seaLevelPressure) { if (seaLevelPressure == 0) seaLevelPressure = 101325; return 44330 * (1.0 - pow(pressure / seaLevelPressure, 0.1903)); }
6f4bf04a5c6ad3c5af4baf00e1929529ff168998
83372fce92c9088ee5c1e1c13bc67385a3b02a36
/src/sim65/paravirt.c
2e52d6e7e0ceb261c793bec29152b2a6b9684275
[ "Zlib" ]
permissive
cc65/cc65
2cd1b20b61ddd0691cd4601b4da37a9200a50afb
16e90187e8e80c6e2fcfcc04f068ac865d2290e5
refs/heads/master
2023-09-03T17:16:46.027934
2023-09-02T22:30:44
2023-09-02T22:30:44
8,932,489
2,103
526
Zlib
2023-09-13T06:19:01
2013-03-21T15:56:48
C
UTF-8
C
false
false
8,638
c
paravirt.c
/*****************************************************************************/ /* */ /* paravirt.c */ /* */ /* Paravirtualization for the sim65 6502 simulator */ /* */ /* */ /* */ /* (C) 2013-2013 Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed 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. */ /* */ /*****************************************************************************/ #include <string.h> #include <stdlib.h> #include <fcntl.h> #include <sys/stat.h> #if defined(_WIN32) # define O_INITIAL O_BINARY #else # define O_INITIAL 0 #endif #if defined(_MSC_VER) /* Microsoft compiler */ # include <io.h> #else /* Anyone else */ # include <unistd.h> #endif #ifndef S_IREAD # define S_IREAD S_IRUSR #endif #ifndef S_IWRITE # define S_IWRITE S_IWUSR #endif /* common */ #include "cmdline.h" #include "print.h" #include "xmalloc.h" /* sim65 */ #include "6502.h" #include "error.h" #include "memory.h" #include "paravirt.h" /*****************************************************************************/ /* Data */ /*****************************************************************************/ typedef void (*PVFunc) (CPURegs* Regs); static unsigned ArgStart; static unsigned char SPAddr; /*****************************************************************************/ /* Code */ /*****************************************************************************/ static unsigned GetAX (CPURegs* Regs) { return Regs->AC + (Regs->XR << 8); } static void SetAX (CPURegs* Regs, unsigned Val) { Regs->AC = Val & 0xFF; Val >>= 8; Regs->XR = Val; } static unsigned char Pop (CPURegs* Regs) { return MemReadByte (0x0100 + (++Regs->SP & 0xFF)); } static unsigned PopParam (unsigned char Incr) { unsigned SP = MemReadZPWord (SPAddr); unsigned Val = MemReadWord (SP); MemWriteWord (SPAddr, SP + Incr); return Val; } static void PVExit (CPURegs* Regs) { Print (stderr, 1, "PVExit ($%02X)\n", Regs->AC); SimExit (Regs->AC); /* Error code in range 0-255. */ } static void PVArgs (CPURegs* Regs) { unsigned ArgC = ArgCount - ArgStart; unsigned ArgV = GetAX (Regs); unsigned SP = MemReadZPWord (SPAddr); unsigned Args = SP - (ArgC + 1) * 2; Print (stderr, 2, "PVArgs ($%04X)\n", ArgV); MemWriteWord (ArgV, Args); SP = Args; while (ArgStart < ArgCount) { unsigned I = 0; const char* Arg = ArgVec[ArgStart++]; SP -= strlen (Arg) + 1; do { MemWriteByte (SP + I, Arg[I]); } while (Arg[I++]); MemWriteWord (Args, SP); Args += 2; } MemWriteWord (Args, SPAddr); MemWriteWord (SPAddr, SP); SetAX (Regs, ArgC); } static void PVOpen (CPURegs* Regs) { char Path[PVOPEN_PATH_SIZE]; int OFlag = O_INITIAL; int OMode = 0; unsigned RetVal, I = 0; unsigned Mode = PopParam (Regs->YR - 4); unsigned Flags = PopParam (2); unsigned Name = PopParam (2); if (Regs->YR - 4 < 2) { /* If the caller didn't supply the mode ** argument, use a reasonable default. */ Mode = 0x01 | 0x02; } do { if (!(Path[I] = MemReadByte ((Name + I) & 0xFFFF))) { break; } ++I; if (I >= PVOPEN_PATH_SIZE) { Error("PVOpen path too long at address $%04X",Name); } } while (1); Print (stderr, 2, "PVOpen (\"%s\", $%04X)\n", Path, Flags); switch (Flags & 0x03) { case 0x01: OFlag |= O_RDONLY; break; case 0x02: OFlag |= O_WRONLY; break; case 0x03: OFlag |= O_RDWR; break; } if (Flags & 0x10) { OFlag |= O_CREAT; } if (Flags & 0x20) { OFlag |= O_TRUNC; } if (Flags & 0x40) { OFlag |= O_APPEND; } if (Flags & 0x80) { OFlag |= O_EXCL; } if (Mode & 0x01) { OMode |= S_IREAD; } if (Mode & 0x02) { OMode |= S_IWRITE; } RetVal = open (Path, OFlag, OMode); SetAX (Regs, RetVal); } static void PVClose (CPURegs* Regs) { unsigned RetVal; unsigned FD = GetAX (Regs); Print (stderr, 2, "PVClose ($%04X)\n", FD); if (FD != 0xFFFF) { RetVal = close (FD); } else { /* test/val/constexpr.c "abuses" close, expecting close(-1) to return -1. ** This behaviour is not the same on all target platforms. ** MSVC's close treats it as a fatal error instead and terminates. */ RetVal = 0xFFFF; } SetAX (Regs, RetVal); } static void PVRead (CPURegs* Regs) { unsigned char* Data; unsigned RetVal, I = 0; unsigned Count = GetAX (Regs); unsigned Buf = PopParam (2); unsigned FD = PopParam (2); Print (stderr, 2, "PVRead ($%04X, $%04X, $%04X)\n", FD, Buf, Count); Data = xmalloc (Count); RetVal = read (FD, Data, Count); if (RetVal != (unsigned) -1) { while (I < RetVal) { MemWriteByte (Buf++, Data[I++]); } } xfree (Data); SetAX (Regs, RetVal); } static void PVWrite (CPURegs* Regs) { unsigned char* Data; unsigned RetVal, I = 0; unsigned Count = GetAX (Regs); unsigned Buf = PopParam (2); unsigned FD = PopParam (2); Print (stderr, 2, "PVWrite ($%04X, $%04X, $%04X)\n", FD, Buf, Count); Data = xmalloc (Count); while (I < Count) { Data[I++] = MemReadByte (Buf++); } RetVal = write (FD, Data, Count); xfree (Data); SetAX (Regs, RetVal); } static const PVFunc Hooks[] = { PVOpen, PVClose, PVRead, PVWrite, PVArgs, PVExit, }; void ParaVirtInit (unsigned aArgStart, unsigned char aSPAddr) /* Initialize the paravirtualization subsystem */ { ArgStart = aArgStart; SPAddr = aSPAddr; }; void ParaVirtHooks (CPURegs* Regs) /* Potentially execute paravirtualization hooks */ { unsigned lo; /* Check for paravirtualization address range */ if (Regs->PC < PARAVIRT_BASE || Regs->PC >= PARAVIRT_BASE + sizeof (Hooks) / sizeof (Hooks[0])) { return; } /* Call paravirtualization hook */ Hooks[Regs->PC - PARAVIRT_BASE] (Regs); /* Simulate RTS */ lo = Pop (Regs); Regs->PC = lo + (Pop (Regs) << 8) + 1; }
f72542be19eb4f232d9fef78fa7be59ac24bd2eb
b8906afecca06f48f2cd289a9997f670b26c4721
/platform/shared/shttpd/src/rdispatcher.c
e2d3d6d482babd1fd181f845a645fc7c8cc9a911
[ "MIT", "Beerware" ]
permissive
rhomobile/rhodes
51bd88921c51bd618948f9a557de17fc297e7cc2
fc8409c9c281684a49d7ff6805ddc565de09a6d5
refs/heads/master
2023-09-01T17:45:36.149868
2023-08-31T20:56:06
2023-08-31T20:56:06
54,084
504
155
MIT
2023-09-12T00:14:29
2008-09-18T21:55:16
C
UTF-8
C
false
false
13,989
c
rdispatcher.c
#include <string.h> #include "defs.h" #include "llist.h" #include "ruby/ext/rho/rhoruby.h" #include "logging/RhoLog.h" #include "common/RhoMutexLock.h" #undef DEFAULT_LOGCATEGORY #define DEFAULT_LOGCATEGORY "RDispatcher" #if defined(__SYMBIAN32__) || defined(WINDOWS_PLATFORM) extern char* get_home_url(); #else /*static char* localhost = "http://localhost:8080";*/ #endif #ifdef __SYMBIAN32__ extern int g_need_launch_gc; char* g_current_url = NULL; RHO_INIT_LOCK(change_url); //forward declaration void webview_set_current_location(char* url); #endif typedef struct __Route { char* _url; char* _application; char* _model; char* _id; char* _action; } Route, * RouteRef; struct data_chunk { struct llhead link; size_t size; void *data; }; static char *trim(char *str) { char *ibuf = str, *obuf = str; int i; if (str) { // Remove leading spaces for(ibuf = str; *ibuf && isspace(*ibuf); ++ibuf); if (str != ibuf) memmove(str, ibuf, ibuf - str); // Remove trailing spaces i = strlen(str); while (--i >= 0) { if (!(isspace(obuf[i])||obuf[i]==':')) break; } obuf[++i] = 0; } return str; } static int _isid(char* str) { if (str!=NULL) { int l = strlen(str); if ( (l>2) && (str[0]=='{') && (str[l-1]=='}') ) return 1; } return 0; } static char* _tok(char* t) { char* s = NULL; if (t) { s = strchr(t,'/'); if ( s != NULL ) { s[0] = '\0'; s++; } } return s; } static int _parse_route(RouteRef route) { char *actionorid,*next; char* url = route->_url; if (url[0]=='/') url++; route->_application = url; if ((route->_model = _tok(url)) == NULL) return 0; if ((actionorid = _tok(route->_model)) == NULL) return 1; next = _tok(actionorid); if (_isid(actionorid)) { route->_id = actionorid; route->_action = next; } else { route->_id = next; route->_action = actionorid; } _tok(next); return 1; } static RouteRef _alloc_route(char* uri) { RouteRef route; char *url; if ( (route = malloc(sizeof(Route))) != NULL) { if ((url = _shttpd_strdup(uri)) != NULL) { memset(route, 0, sizeof(route[0])); route->_url = url; return route; } free(route); } return NULL; } static void _free_route(RouteRef route) { if (route) { if (route->_url) free(route->_url); free(route); } } static VALUE _create_request_hash(struct conn *c, RouteRef route, const char* body, int bodylen) { const char *method, *uri, *query; VALUE hash_headers; struct parsed_header* h; int i; VALUE hash = createHash(); addStrToHash(hash, "application", route->_application, strlen(route->_application)); addStrToHash(hash, "model", route->_model, strlen(route->_model)); if (route->_action!=NULL) { const char* actionName = route->_action; addStrToHash(hash, "action", actionName, strlen(actionName)); } if (route->_id!=NULL) { const char* _id = route->_id; addStrToHash(hash, "id", _id, strlen(_id)); } method = _shttpd_known_http_methods[c->method].ptr; addStrToHash(hash, "request-method", method, strlen(method)); uri = c->uri; addStrToHash(hash, "request-uri", uri, strlen(uri)); query = c->query == NULL ? "" : c->query; addStrToHash(hash, "request-query", query, strlen(query)); hash_headers = createHash(); h = &c->ch.cl; for (i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) { if (h->_name) { char* name = trim(_shttpd_strdup(h->_name)); if (h->_type == HDR_STRING) { addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len); } else if (h->_type == HDR_INT) { addIntToHash(hash_headers, name, h->_v.v_big_int); } else if (h->_type == HDR_DATE) { addTimeToHash(hash_headers, name, h->_v.v_time); } free(name); } h++; } addHashToHash(hash,"headers",hash_headers); if (bodylen > 0) { addStrToHash(hash, "request-body", body, bodylen); } return hash; } /* static char* _rho_resolve_index(char* url,char* path,const char *index_names) { char file[FILENAME_MAX]; char indexfile[128]; struct stat st; char* resolved_url; const char* slash = path[strlen(path)-1] == '/' ? "" : "/"; int full_len,url_len,len; FOR_EACH_WORD_IN_LIST(index_names, len) { strncpy(indexfile,index_names,len); _shttpd_snprintf(file, sizeof(file), "%s%s%s", path, slash, indexfile); if ( (_shttpd_stat(file, &st) == 0) && (!S_ISDIR(st.st_mode)) ) { //if ( i == 0 ) {// there is a controller in this folder // return url; //} url_len = strlen(url); slash = url[strlen(url)-1] == '/' ? "" : "/"; full_len = url_len + strlen(slash)+len+1; resolved_url = malloc(full_len); _shttpd_snprintf(resolved_url, full_len, "%s%s%s", url, slash, indexfile); free(url); return resolved_url; } } return url; } */ /* static char* _rho_resolve_index(char* url,char* path,const char *index_names) { char filename[FILENAME_MAX]; struct stat st; //check if there is controller.rb int len = strlen(path); char* slash = path[len-1] == '\\' || path[len-1] == '/' ? "" : "/"; _shttpd_snprintf(filename,sizeof(filename),"%s%s%s",path,slash,"controller.iseq"); if ((_shttpd_stat(filename, &st) == 0)&&(!S_ISDIR(st.st_mode))) { return url; } len = strlen(url); if (url[len-1]!='/') { char* tmp_url = malloc(len+2); _shttpd_snprintf(tmp_url,len+2,"%s/",url); free(url); return tmp_url; } return url; }*/ /* char* rho_resolve_url(char* url, const char* root,const char *index_names) { char path[URI_MAX]; struct stat st; char* tmp_url; char* ret; int full_len; char* full_path = strstr(url,"http://"); if (full_path) { return full_path; } if (strlen(url) + strlen(root) >= sizeof(path)) { tmp_url = url; } else { _shttpd_snprintf(path, sizeof(path), "%s%s", root, url); if ( _shttpd_stat(path, &st) == -1 ) { tmp_url = url; } else if ( S_ISDIR(st.st_mode) ) { tmp_url = _rho_resolve_index(url,path,index_names); } else { tmp_url = url; } } #if defined(__SYMBIAN32__) || defined(WINDOWS_PLATFORM) full_len = strlen(get_home_url())+strlen(tmp_url)+1; ret = malloc(full_len); _shttpd_snprintf(ret, full_len, "%s%s", get_home_url(), tmp_url); #else full_len = strlen(localhost)+strlen(tmp_url)+1; ret = malloc(full_len); _shttpd_snprintf(ret, full_len, "%s%s", localhost, tmp_url); #endif free(tmp_url); return ret; }*/ extern void rho_sync_addobjectnotify_bysrcname(const char* szSrcName, const char* szObject); //extern void rho_rhodesapp_keeplastvisitedurl(const char* szUrl); void* rho_dispatch(struct conn *c, const char* path) { RouteRef route; if ( _shttpd_match_extension(c->uri,"css,js,html,htm,png,bmp,jpg,jpeg,gif") ) return NULL; /*#ifdef __SYMBIAN32__ if ( strstr(_shttpd_known_http_methods[c->method].ptr, "GET" ) ) webview_set_current_location(c->uri); #endif*/ if ((route = _alloc_route(c->uri)) != NULL) { if (_parse_route(route)) { struct stat st; //is this an actual file or folder if (_shttpd_stat(path, &st) != 0) return route; //is this a folder if (S_ISDIR(st.st_mode)) { //check if there is controller.rb to run char filename[FILENAME_MAX]; int len = strlen(path); char* slash = path[len-1] == '\\' || path[len-1] == '/' ? "" : "/"; _shttpd_snprintf(filename,sizeof(filename),"%s%s%s",path,slash,"controller.iseq"); if ((_shttpd_stat(filename, &st) == 0)&&(!S_ISDIR(st.st_mode))) { RAWLOG_INFO1("Run controller on this url: %s", c->uri); return route; } } } _free_route(route); } return NULL; } int collect_data(struct llhead *plist, const void* data, size_t len) { struct data_chunk *chunk; if ((chunk = malloc(sizeof(*chunk))) != NULL) { if ((chunk->data = malloc(len)) != NULL) { memcpy(chunk->data,data,len); chunk->size = len; LL_TAIL(plist, &chunk->link); return len; } free(chunk); } return -1; } static void collected_data_destructor(struct llhead *lp) { struct data_chunk *chunk = LL_ENTRY(lp, struct data_chunk, link); free(chunk->data); free(chunk); } static void* get_collected_data(struct llhead *head, int nchunks, size_t datasize) { struct data_chunk *chunk; struct llhead *lp, *tmp; char* data = NULL; if (nchunks == 1) { chunk = LL_ENTRY(head->next, struct data_chunk, link); data = chunk->data; free(chunk); } else if (nchunks > 1) { char *p = data = malloc(datasize); LL_FOREACH_SAFE(head, lp, tmp) { LL_DEL(lp); chunk = (struct data_chunk *)lp; memcpy(p, chunk->data, chunk->size); p += chunk->size; collected_data_destructor(lp); } } return data; } struct rho_write_state { VALUE data; size_t nDataLen; /* Content-Length */ size_t nRead; /* Number of bytes read */ }; void rho_write_data(struct shttpd_arg *arg) { struct rho_write_state* state = arg->state; if ( state->nRead < state->nDataLen ) state->nRead += shttpd_printf(arg, "%s", getStringFromValue(state->data) + state->nRead); if ( state->nRead >= state->nDataLen ) { arg->flags |= SHTTPD_END_OF_OUTPUT; releaseValue(state->data); free(arg->state); arg->state = NULL; } } void rho_create_write_state(struct shttpd_arg *arg, VALUE data) { struct rho_write_state* state = 0; arg->state = state = calloc(1, sizeof(struct rho_write_state)); state->data = data; state->nDataLen = getStringLenFromValue(data); #if defined(OS_WINDOWS_DESKTOP) { char* reply = getStringFromValue(state->data); RAWTRACE1("Reply: [%s]",reply); } #endif } void rho_serve(struct shttpd_arg *arg) { //const char *s; struct rho_read_state { size_t cl; /* Content-Length */ size_t nread; /* Number of bytes read */ int nchunks; /* Number of chunks in the list */ struct llhead post_data; } *state; /* If the connection was broken prematurely, cleanup */ if (arg->flags & SHTTPD_CONNECTION_ERROR) { if (arg->state) { if (arg->user_data){ //Read request state = arg->state; free_list(&state->post_data, collected_data_destructor); }else releaseValue( ((struct rho_write_state*)arg->state)->data); free(arg->state); } if (arg->user_data) _free_route(arg->user_data); arg->user_data = NULL; arg->state = NULL; return; } if ( !arg->user_data ) {//Request read. Return response rho_write_data(arg); return; } if (arg->state == NULL) { /* New request. Allocate a state structure. */ arg->state = state = calloc(1, sizeof(*state)); state->cl = ((struct conn *)(arg->priv))->ch.cl._v.v_big_int; state->nchunks = 0; LL_INIT(&state->post_data); } state = arg->state; /* Collect the POST data */ if (arg->in.len > 0) { if ( collect_data(&state->post_data,arg->in.buf, arg->in.len) == -1 ) { shttpd_printf(arg, "HTTP/1.0 500 Out of memory\n\n"); arg->flags |= SHTTPD_END_OF_OUTPUT; return; } state->nchunks++; state->nread += arg->in.len; /* Tell SHTTPD we have processed all data */ arg->in.num_bytes = arg->in.len; } /* Read all input? Call ruby framework with collected data (if any) */ if (state->nread >= state->cl) { void* data = get_collected_data(&state->post_data, state->nchunks, state->nread); VALUE req = _create_request_hash( arg->priv, (RouteRef) arg->user_data, data, state->nread ); #ifdef __SYMBIAN32__ g_need_launch_gc = 1; #endif //shttpd_printf(arg, "%s", callFramework(req)); // _free_route(arg->user_data); // arg->user_data = NULL; // free(state); //arg->flags |= SHTTPD_END_OF_OUTPUT; rho_create_write_state(arg,callFramework(req)); { RouteRef route = arg->user_data; if ( _isid(route->_id) ) { rho_sync_addobjectnotify_bysrcname(route->_model, route->_id); } } _free_route(arg->user_data); arg->user_data = NULL; free(state); rho_write_data(arg); } } int isindex(struct conn *c, char* path) { int pathlen = strlen(path); const char *s = c->ctx->options[OPT_INDEX_FILES]; int len; FOR_EACH_WORD_IN_LIST(s, len) { if ( len > pathlen ) continue; if( strncmp(path+pathlen-len,s,len) == 0 ) return 1; } return 0; } void rho_serve_index(struct shttpd_arg *arg) { if (arg->flags & SHTTPD_CONNECTION_ERROR) { if (arg->state){ releaseValue( ((struct rho_write_state*)arg->state)->data); free(arg->state); } if ( arg->user_data ) free(arg->user_data); arg->state = NULL; arg->user_data = NULL; return; } if (arg->state == NULL) { rho_create_write_state(arg,callServeIndex(arg->user_data)); free(arg->user_data); arg->user_data = NULL; } rho_write_data(arg); //shttpd_printf(arg, "%s", callServeIndex(arg->user_data)); //free(arg->user_data); //arg->flags |= SHTTPD_END_OF_OUTPUT; } #ifdef __SYMBIAN32__ //this is platform specific function extern void webview_navigate(char* url); char* webview_current_location() { char* retval = NULL; RHO_LOCK(change_url); retval = strdup(g_current_url); RHO_UNLOCK(change_url); return retval; } void webview_set_current_location(char* url) { RHO_LOCK(change_url); if ( g_current_url ) free(g_current_url); g_current_url = strdup(url); RHO_UNLOCK(change_url); } void webview_refresh() { char* url = webview_current_location(); if ( url ) { webview_navigate(url); free(url); } } #endif
b31fc67e88caa0029da7f6cbeba2561d86e85b10
e1b53f2bff297f9d640c7f1f5eec43ceff77122e
/pluginsdk/_dbgfunctions.h
dda3ea5824a61c40b49ac7c26909f1bd8f522275
[ "MIT" ]
permissive
x64dbg/x64dbgpy
33b248ce77fd53519cf45480aea24b3bea4853ce
8c0538a0b608f0344b2308328c1fd4c6b68bfa98
refs/heads/v25
2023-04-12T15:41:04.420363
2023-04-05T08:12:57
2023-04-05T08:26:18
39,038,863
1,344
79
MIT
2020-07-14T13:58:25
2015-07-13T21:40:37
C
UTF-8
C
false
false
9,583
h
_dbgfunctions.h
#ifndef _DBGFUNCTIONS_H #define _DBGFUNCTIONS_H #ifndef __cplusplus #include <stdbool.h> #endif typedef struct { char mod[MAX_MODULE_SIZE]; duint addr; unsigned char oldbyte; unsigned char newbyte; } DBGPATCHINFO; typedef struct { duint addr; duint from; duint to; char comment[MAX_COMMENT_SIZE]; } DBGCALLSTACKENTRY; typedef struct { int total; DBGCALLSTACKENTRY* entries; } DBGCALLSTACK; typedef struct { duint addr; duint handler; } DBGSEHRECORD; typedef struct { duint total; DBGSEHRECORD* records; } DBGSEHCHAIN; typedef struct { DWORD dwProcessId; char szExeFile[MAX_PATH]; char szExeMainWindowTitle[MAX_PATH]; char szExeArgs[MAX_COMMAND_LINE_SIZE]; } DBGPROCESSINFO; typedef struct { DWORD rva; BYTE type; WORD size; } DBGRELOCATIONINFO; typedef enum { InstructionBody = 0, InstructionHeading = 1, InstructionTailing = 2, InstructionOverlapped = 3, // The byte was executed with differing instruction base addresses DataByte, // This and the following is not implemented yet. DataWord, DataDWord, DataQWord, DataFloat, DataDouble, DataLongDouble, DataXMM, DataYMM, DataMMX, DataMixed, //the byte is accessed in multiple ways InstructionDataMixed //the byte is both executed and written } TRACERECORDBYTETYPE; typedef enum { TraceRecordNone, TraceRecordBitExec, TraceRecordByteWithExecTypeAndCounter, TraceRecordWordWithExecTypeAndCounter } TRACERECORDTYPE; typedef struct { duint Handle; unsigned char TypeNumber; unsigned int GrantedAccess; } HANDLEINFO; // The longest ip address is 1234:6789:1234:6789:1234:6789:123.567.901.345 (46 bytes) #define TCP_ADDR_SIZE 50 typedef struct { char RemoteAddress[TCP_ADDR_SIZE]; unsigned short RemotePort; char LocalAddress[TCP_ADDR_SIZE]; unsigned short LocalPort; char StateText[TCP_ADDR_SIZE]; unsigned int State; } TCPCONNECTIONINFO; typedef struct { duint handle; duint parent; DWORD threadId; DWORD style; DWORD styleEx; duint wndProc; bool enabled; RECT position; char windowTitle[MAX_COMMENT_SIZE]; char windowClass[MAX_COMMENT_SIZE]; } WINDOW_INFO; typedef struct { duint addr; duint size; duint flags; } HEAPINFO; typedef struct { const char* name; duint value; } CONSTANTINFO; typedef bool (*ASSEMBLEATEX)(duint addr, const char* instruction, char* error, bool fillnop); typedef bool (*SECTIONFROMADDR)(duint addr, char* section); typedef bool (*MODNAMEFROMADDR)(duint addr, char* modname, bool extension); typedef duint(*MODBASEFROMADDR)(duint addr); typedef duint(*MODBASEFROMNAME)(const char* modname); typedef duint(*MODSIZEFROMADDR)(duint addr); typedef bool (*ASSEMBLE)(duint addr, unsigned char* dest, int* size, const char* instruction, char* error); typedef bool (*PATCHGET)(duint addr); typedef bool (*PATCHINRANGE)(duint start, duint end); typedef bool (*MEMPATCH)(duint va, const unsigned char* src, duint size); typedef void (*PATCHRESTORERANGE)(duint start, duint end); typedef bool (*PATCHENUM)(DBGPATCHINFO* patchlist, size_t* cbsize); typedef bool (*PATCHRESTORE)(duint addr); typedef int (*PATCHFILE)(DBGPATCHINFO* patchlist, int count, const char* szFileName, char* error); typedef int (*MODPATHFROMADDR)(duint addr, char* path, int size); typedef int (*MODPATHFROMNAME)(const char* modname, char* path, int size); typedef bool (*DISASMFAST)(const unsigned char* data, duint addr, BASIC_INSTRUCTION_INFO* basicinfo); typedef void (*MEMUPDATEMAP)(); typedef void (*GETCALLSTACK)(DBGCALLSTACK* callstack); typedef void (*GETSEHCHAIN)(DBGSEHCHAIN* sehchain); typedef void (*SYMBOLDOWNLOADALLSYMBOLS)(const char* szSymbolStore); typedef bool (*GETJIT)(char* jit, bool x64); typedef bool (*GETJITAUTO)(bool* jitauto); typedef bool (*GETDEFJIT)(char* defjit); typedef bool (*GETPROCESSLIST)(DBGPROCESSINFO** entries, int* count); typedef bool (*GETPAGERIGHTS)(duint addr, char* rights); typedef bool (*SETPAGERIGHTS)(duint addr, const char* rights); typedef bool (*PAGERIGHTSTOSTRING)(DWORD protect, char* rights); typedef bool (*ISPROCESSELEVATED)(); typedef bool (*GETCMDLINE)(char* cmdline, size_t* cbsize); typedef bool (*SETCMDLINE)(const char* cmdline); typedef duint(*FILEOFFSETTOVA)(const char* modname, duint offset); typedef duint(*VATOFILEOFFSET)(duint va); typedef duint(*GETADDRFROMLINE)(const char* szSourceFile, int line, duint* displacement); typedef bool (*GETSOURCEFROMADDR)(duint addr, char* szSourceFile, int* line); typedef bool (*VALFROMSTRING)(const char* string, duint* value); typedef bool (*PATCHGETEX)(duint addr, DBGPATCHINFO* info); typedef bool (*GETBRIDGEBP)(BPXTYPE type, duint addr, BRIDGEBP* bp); typedef bool (*STRINGFORMATINLINE)(const char* format, size_t resultSize, char* result); typedef void (*GETMNEMONICBRIEF)(const char* mnem, size_t resultSize, char* result); typedef unsigned int (*GETTRACERECORDHITCOUNT)(duint address); typedef TRACERECORDBYTETYPE(*GETTRACERECORDBYTETYPE)(duint address); typedef bool (*SETTRACERECORDTYPE)(duint pageAddress, TRACERECORDTYPE type); typedef TRACERECORDTYPE(*GETTRACERECORDTYPE)(duint pageAddress); typedef bool (*ENUMHANDLES)(ListOf(HANDLEINFO) handles); typedef bool (*GETHANDLENAME)(duint handle, char* name, size_t nameSize, char* typeName, size_t typeNameSize); typedef bool (*ENUMTCPCONNECTIONS)(ListOf(TCPCONNECTIONINFO) connections); typedef duint(*GETDBGEVENTS)(); typedef int (*MODGETPARTY)(duint base); typedef void (*MODSETPARTY)(duint base, int party); typedef bool(*WATCHISWATCHDOGTRIGGERED)(unsigned int id); typedef bool(*MEMISCODEPAGE)(duint addr, bool refresh); typedef bool(*ANIMATECOMMAND)(const char* command); typedef void(*DBGSETDEBUGGEEINITSCRIPT)(const char* fileName); typedef const char* (*DBGGETDEBUGGEEINITSCRIPT)(); typedef bool(*HANDLESENUMWINDOWS)(ListOf(WINDOW_INFO) windows); typedef bool(*HANDLESENUMHEAPS)(ListOf(HEAPINFO) heaps); typedef bool(*THREADGETNAME)(DWORD tid, char* name); typedef bool(*ISDEPENABLED)(); typedef void(*GETCALLSTACKEX)(DBGCALLSTACK* callstack, bool cache); typedef bool(*GETUSERCOMMENT)(duint addr, char* comment); typedef void(*ENUMCONSTANTS)(ListOf(CONSTANTINFO) constants); typedef duint(*MEMBPSIZE)(duint addr); typedef bool(*MODRELOCATIONSFROMADDR)(duint addr, ListOf(DBGRELOCATIONINFO) relocations); typedef bool(*MODRELOCATIONATADDR)(duint addr, DBGRELOCATIONINFO* relocation); typedef bool(*MODRELOCATIONSINRANGE)(duint addr, duint size, ListOf(DBGRELOCATIONINFO) relocations); //The list of all the DbgFunctions() return value. //WARNING: This list is append only. Do not insert things in the middle or plugins would break. typedef struct DBGFUNCTIONS_ { ASSEMBLEATEX AssembleAtEx; SECTIONFROMADDR SectionFromAddr; MODNAMEFROMADDR ModNameFromAddr; MODBASEFROMADDR ModBaseFromAddr; MODBASEFROMNAME ModBaseFromName; MODSIZEFROMADDR ModSizeFromAddr; ASSEMBLE Assemble; PATCHGET PatchGet; PATCHINRANGE PatchInRange; MEMPATCH MemPatch; PATCHRESTORERANGE PatchRestoreRange; PATCHENUM PatchEnum; PATCHRESTORE PatchRestore; PATCHFILE PatchFile; MODPATHFROMADDR ModPathFromAddr; MODPATHFROMNAME ModPathFromName; DISASMFAST DisasmFast; MEMUPDATEMAP MemUpdateMap; GETCALLSTACK GetCallStack; GETSEHCHAIN GetSEHChain; SYMBOLDOWNLOADALLSYMBOLS SymbolDownloadAllSymbols; GETJITAUTO GetJitAuto; GETJIT GetJit; GETDEFJIT GetDefJit; GETPROCESSLIST GetProcessList; GETPAGERIGHTS GetPageRights; SETPAGERIGHTS SetPageRights; PAGERIGHTSTOSTRING PageRightsToString; ISPROCESSELEVATED IsProcessElevated; GETCMDLINE GetCmdline; SETCMDLINE SetCmdline; FILEOFFSETTOVA FileOffsetToVa; VATOFILEOFFSET VaToFileOffset; GETADDRFROMLINE GetAddrFromLine; GETSOURCEFROMADDR GetSourceFromAddr; VALFROMSTRING ValFromString; PATCHGETEX PatchGetEx; GETBRIDGEBP GetBridgeBp; STRINGFORMATINLINE StringFormatInline; GETMNEMONICBRIEF GetMnemonicBrief; GETTRACERECORDHITCOUNT GetTraceRecordHitCount; GETTRACERECORDBYTETYPE GetTraceRecordByteType; SETTRACERECORDTYPE SetTraceRecordType; GETTRACERECORDTYPE GetTraceRecordType; ENUMHANDLES EnumHandles; GETHANDLENAME GetHandleName; ENUMTCPCONNECTIONS EnumTcpConnections; GETDBGEVENTS GetDbgEvents; MODGETPARTY ModGetParty; MODSETPARTY ModSetParty; WATCHISWATCHDOGTRIGGERED WatchIsWatchdogTriggered; MEMISCODEPAGE MemIsCodePage; ANIMATECOMMAND AnimateCommand; DBGSETDEBUGGEEINITSCRIPT DbgSetDebuggeeInitScript; DBGGETDEBUGGEEINITSCRIPT DbgGetDebuggeeInitScript; HANDLESENUMWINDOWS EnumWindows; HANDLESENUMHEAPS EnumHeaps; THREADGETNAME ThreadGetName; ISDEPENABLED IsDepEnabled; GETCALLSTACKEX GetCallStackEx; GETUSERCOMMENT GetUserComment; ENUMCONSTANTS EnumConstants; ENUMCONSTANTS EnumErrorCodes; ENUMCONSTANTS EnumExceptions; MEMBPSIZE MemBpSize; MODRELOCATIONSFROMADDR ModRelocationsFromAddr; MODRELOCATIONATADDR ModRelocationAtAddr; MODRELOCATIONSINRANGE ModRelocationsInRange; } DBGFUNCTIONS; #ifdef BUILD_DBG const DBGFUNCTIONS* dbgfunctionsget(); void dbgfunctionsinit(); #endif //BUILD_DBG #endif //_DBGFUNCTIONS_H
4e7159ac27bc2d1cd5749375dcc57749348db599
e4eb547141929d5c61b3335c09904f258a65f5ea
/minijvm/c/utils/hashset.h
8b1d1c3ed1eda89ca5911b34a61a65d13786201e
[ "MIT" ]
permissive
digitalgust/miniJVM
14e11fa518e965ebe6c6b8172b2cacffde7a46d7
aa504d6c3c17a365a8f8f2ea91eb580d6ec94711
refs/heads/master
2023-08-22T12:55:31.981267
2023-08-10T07:09:28
2023-08-10T07:09:28
101,243,754
269
78
null
2023-03-08T06:50:54
2017-08-24T02:10:21
C
UTF-8
C
false
false
4,843
h
hashset.h
// // Created by gust on 2017/8/30. // #ifndef MINI_JVM_hashset_H #define MINI_JVM_hashset_H #include "arraylist.h" #ifdef __cplusplus extern "C" { #endif /** * A hash table structure. */ typedef struct _Hashset Hashset; /** * Structure used to iterate over a hash table. */ typedef struct _HashsetIterator HashsetIterator; /** * Internal structure representing an entry in a hash table. */ typedef struct _HashsetEntry HashsetEntry; /** * A key to look up a value in a @ref Hashset. */ typedef void *HashsetKey; /** * Definition of a @ref HashsetIterator. */ struct _HashsetIterator { Hashset *set; // HashsetEntry *prev_entry; HashsetEntry *curr_entry; HashsetEntry *next_entry; u64 curr_chain; u64 next_chain; }; /** * A null @ref HashsetValue. */ #ifndef HASH_NULL #define HASH_NULL ((void *) 0) #endif struct _HashsetEntry { HashsetKey key; HashsetEntry *next; }; struct _Hashset { HashsetEntry **table; u64 table_size; u64 entries; spinlock_t lock; ArrayList *entry_pool; }; /** * Create a new hash table. * * @return A new hash table structure, or NULL if it * was not possible to allocate the new hash * table. */ Hashset *hashset_create(void); // //Hashset *hashset_create(HashtableHashFunc hash_func, // HashtableEqualFunc equal_func); /** * Destroy a hash table. * * @param hash_table The hash table to destroy. */ void hashset_destory(Hashset *hash_table); void hashset_clear(Hashset *hash_table); /** * Register functions used to free the key and value when an entry is * removed from a hash table. * * @param hash_table The hash table. * @param key_free_func Function used to free keys. * @param value_free_func Function used to free values. */ //void hashset_register_free_functions(Hashset *hash_table, // HashtableKeyFreeFunc key_free_func); /** * Insert a value into a hash table, overwriting any existing entry * using the same key. * * @param hash_table The hash table. * @param key The key for the new value. * @return Non-zero if the value was added successfully, * or zero if it was not possible to allocate * memory for the new entry. */ int hashset_put(Hashset *hash_table, HashsetKey key); int hashset_put_unsafe(Hashset *set, HashsetKey key); /** * Look up a value in a hash table by key. * * @param hash_table The hash table. * @param key The key of the value to look up. * @return The value, or @ref HASH_TABLE_NULL if there * is no value with that key in the hash table. */ HashsetKey hashset_get(Hashset *hash_table, HashsetKey key); HashsetKey hashset_get_unsafe(Hashset *set, HashsetKey key); /** * Remove a value from a hash table. * * @param hash_table The hash table. * @param key The key of the value to remove. * @return Non-zero if a key was removed, or zero if the * specified key was not found in the hash table. */ int hashset_remove(Hashset *hash_table, HashsetKey key, int resize); /** * Retrieve the number of entries in a hash table. * * @param hash_table The hash table. * @return The number of entries in the hash table. */ u64 hashset_num_entries(Hashset *hash_table); /** * Initialise a @ref HashsetIterator to iterate over a hash table. * * @param hash_table The hash table. * @param iter Pointer to an iterator structure to * initialise. */ void hashset_iterate(Hashset *hash_table, HashsetIterator *iter); /** * Determine if there are more keys in the hash table to iterate * over. * * @param iterator The hash table iterator. * @return Zero if there are no more values to iterate * over, non-zero if there are more values to * iterate over. */ int hashset_iter_has_more(HashsetIterator *iterator); /** * (EXTENSION!) * * Using a hash table iterator, retrieve the next key. * * @param iterator The hash table iterator. * @return The next key from the hash table, or * @ref HASH_TABLE_NULL if there are no more * keys to iterate over. */ HashsetKey hashset_iter_next_key(HashsetIterator *iterator); HashsetKey hashset_iter_remove(HashsetIterator *iterator); u64 hashset_count(Hashset *set); #ifdef __cplusplus } #endif #endif //MINI_JVM_hashset_H
7f7f59092fbeca7d97807fbb6d3e3c70abadfded
8301e9607481f19635c9ab5bfa0b879c5d6234f8
/libogc/depackrnc1.c
e9bb782e5e9e1f0230474b4cf86f2d2b5d160dae
[ "Zlib" ]
permissive
devkitPro/libogc
ba6af8f0e848cccb3054662edb98127c9616144a
0a35583f638c3705be220ae5b65bd7ec20db234d
refs/heads/master
2023-06-23T08:05:17.433798
2023-06-16T15:47:02
2023-06-16T15:47:02
28,180,403
249
163
NOASSERTION
2023-06-16T15:47:03
2014-12-18T11:13:41
C
UTF-8
C
false
false
7,105
c
depackrnc1.c
#include <gccore.h> #define RNC_SIGNATURE 0x524E4301 /* "RNC\001" */ typedef struct { unsigned long bitbuf; /* holds between 16 and 32 bits */ int bitcount; /* how many bits does bitbuf hold? */ } bit_stream; typedef struct { int num; /* number of nodes in the tree */ struct { unsigned long code; int codelen; int value; } table[32]; } huf_table; static long rnc_crc (void *data, long len); static void read_huftable (huf_table *h, bit_stream *bs, unsigned char **p); static unsigned long huf_read (huf_table *h, bit_stream *bs,unsigned char **p); static void bitread_init (bit_stream *bs, unsigned char **p); static void bitread_fix (bit_stream *bs, unsigned char **p); static unsigned long bit_peek (bit_stream *bs, unsigned long mask); static void bit_advance (bit_stream *bs, int n, unsigned char **p); static unsigned long bit_read (bit_stream *bs, unsigned long mask,int n, unsigned char **p); static unsigned long blong (unsigned char *p); static unsigned long bword (unsigned char *p); static unsigned long lword (unsigned char *p); static unsigned long mirror (unsigned long x, int n); s32 depackrnc1_ulen(void *packed) { unsigned char *p = packed; if (blong (p) != RNC_SIGNATURE) return RNC_FILE_IS_NOT_RNC; return blong (p+4); } s32 depackrnc1(void *packed,void *unpacked) { unsigned char *input = packed; unsigned char *output = unpacked; unsigned char *inputend, *outputend; bit_stream bs; huf_table raw, dist, len; unsigned long ch_count; unsigned long ret_len; unsigned out_crc; if (blong(input) != RNC_SIGNATURE) return RNC_FILE_IS_NOT_RNC; ret_len = blong (input+4); outputend = output + ret_len; inputend = input + 18 + blong(input+8); input += 18; /* skip header */ /* * Check the packed-data CRC. Also save the unpacked-data CRC * for later. */ if (rnc_crc(input, inputend-input) != bword(input-4)) return RNC_PACKED_CRC_ERROR; out_crc = bword(input-6); bitread_init (&bs, &input); bit_advance (&bs, 2, &input); /* discard first two bits */ /* * Process chunks. */ while (output < outputend) { read_huftable (&raw, &bs, &input); read_huftable (&dist, &bs, &input); read_huftable (&len, &bs, &input); ch_count = bit_read (&bs, 0xFFFF, 16, &input); while (1) { long length, posn; length = huf_read (&raw, &bs, &input); if (length == -1) return RNC_HUF_DECODE_ERROR; if (length) { while (length--) *output++ = *input++; bitread_fix (&bs, &input); } if (--ch_count <= 0) break; posn = huf_read (&dist, &bs, &input); if (posn == -1) return RNC_HUF_DECODE_ERROR; length = huf_read (&len, &bs, &input); if (length == -1) return RNC_HUF_DECODE_ERROR; posn += 1; length += 2; while (length--) { *output = output[-posn]; output++; } } } if (outputend != output) return RNC_FILE_SIZE_MISMATCH; if (rnc_crc(outputend-ret_len, ret_len) != out_crc) return RNC_UNPACKED_CRC_ERROR; return ret_len; } /* * Read a Huffman table out of the bit stream and data stream given. */ static void read_huftable (huf_table *h, bit_stream *bs, unsigned char **p) { int i, j, k, num; int leaflen[32]; int leafmax; unsigned long codeb; /* big-endian form of code */ num = bit_read (bs, 0x1F, 5, p); if (!num) return; leafmax = 1; for (i=0; i<num; i++) { leaflen[i] = bit_read (bs, 0x0F, 4, p); if (leafmax < leaflen[i]) leafmax = leaflen[i]; } codeb = 0L; k = 0; for (i=1; i<=leafmax; i++) { for (j=0; j<num; j++) if (leaflen[j] == i) { h->table[k].code = mirror (codeb, i); h->table[k].codelen = i; h->table[k].value = j; codeb++; k++; } codeb <<= 1; } h->num = k; } /* * Read a value out of the bit stream using the given Huffman table. */ static unsigned long huf_read (huf_table *h, bit_stream *bs, unsigned char **p) { int i; unsigned long val; for (i=0; i<h->num; i++) { unsigned long mask = (1 << h->table[i].codelen) - 1; if (bit_peek(bs, mask) == h->table[i].code) break; } if (i == h->num) return -1; bit_advance (bs, h->table[i].codelen, p); val = h->table[i].value; if (val >= 2) { val = 1 << (val-1); val |= bit_read (bs, val-1, h->table[i].value - 1, p); } return val; } /* * Initialises a bit stream with the first two bytes of the packed * data. */ static void bitread_init (bit_stream *bs, unsigned char **p) { bs->bitbuf = lword (*p); bs->bitcount = 16; } /* * Fixes up a bit stream after literals have been read out of the * data stream. */ static void bitread_fix (bit_stream *bs, unsigned char **p) { bs->bitcount -= 16; bs->bitbuf &= (1<<bs->bitcount)-1; /* remove the top 16 bits */ bs->bitbuf |= (lword(*p)<<bs->bitcount);/* replace with what's at *p */ bs->bitcount += 16; } /* * Returns some bits. */ static unsigned long bit_peek (bit_stream *bs, unsigned long mask) { return bs->bitbuf & mask; } /* * Advances the bit stream. */ static void bit_advance (bit_stream *bs, int n, unsigned char **p) { bs->bitbuf >>= n; bs->bitcount -= n; if (bs->bitcount < 16) { (*p) += 2; bs->bitbuf |= (lword(*p)<<bs->bitcount); bs->bitcount += 16; } } /* * Reads some bits in one go (ie the above two routines combined). */ static unsigned long bit_read (bit_stream *bs, unsigned long mask, int n, unsigned char **p) { unsigned long result = bit_peek (bs, mask); bit_advance (bs, n, p); return result; } /* * Return the big-endian longword at p. */ static unsigned long blong (unsigned char *p) { unsigned long n; n = p[0]; n = (n << 8) + p[1]; n = (n << 8) + p[2]; n = (n << 8) + p[3]; return n; } /* * Return the big-endian word at p. */ static unsigned long bword (unsigned char *p) { unsigned long n; n = p[0]; n = (n << 8) + p[1]; return n; } /* * Return the little-endian word at p. */ static unsigned long lword (unsigned char *p) { unsigned long n; n = p[1]; n = (n << 8) + p[0]; return n; } /* * Mirror the bottom n bits of x. */ static unsigned long mirror (unsigned long x, int n) { unsigned long top = 1 << (n-1), bottom = 1; while (top > bottom) { unsigned long mask = top | bottom; unsigned long masked = x & mask; if (masked != 0 && masked != mask) x ^= mask; top >>= 1; bottom <<= 1; } return x; } /* * Calculate a CRC, the RNC way. It re-computes its CRC table every * time it's run, but who cares? ;-) */ static long rnc_crc (void *data, long len) { unsigned short crctab[256]; unsigned short val; int i, j; unsigned char *p = data; for (i=0; i<256; i++) { val = i; for (j=0; j<8; j++) { if (val & 1) val = (val >> 1) ^ 0xA001; else val = (val >> 1); } crctab[i] = val; } val = 0; while (len--) { val ^= *p++; val = (val >> 8) ^ crctab[val & 0xFF]; } return val; }
f4905a750df0a788dda07fc482a15b1d5b6c7ef1
9e50ffd3ec7300e541a2e985193916badd8c07f2
/Example_osx/Pods/Headers/Public/Yoga/YGEnums.h
43ed0bbdb6a93d60e1602f3a56b6907a9deb5824
[ "MIT" ]
permissive
zhenglibao/FlexLib
cbc03d6e20933ee94a81e64ace2fa36c0b91e064
ca67797970aed6a41817f643741a0f62e57da34b
refs/heads/master
2023-05-02T03:30:13.829384
2023-04-13T07:34:05
2023-04-13T07:34:05
113,294,355
1,732
288
MIT
2021-05-06T06:14:56
2017-12-06T09:13:46
Objective-C
UTF-8
C
false
false
28
h
YGEnums.h
../../../Yoga/yoga/YGEnums.h
4c5436a13bd84ca7e4ed3a7f50d41535d3ef1e03
549270020f6c8724e2ef1b12e38d11b025579f8d
/recipes/libiberty/all/test_package/test_package.c
0d3850d960d09596099c7dddfa77f00fb3eea998
[ "MIT" ]
permissive
conan-io/conan-center-index
1bcec065ccd65aa38b1fed93fbd94d9d5fe6bc43
3b17e69bb4e5601a850b6e006e44775e690bac33
refs/heads/master
2023-08-31T11:34:45.403978
2023-08-31T11:13:23
2023-08-31T11:13:23
204,671,232
844
1,820
MIT
2023-09-14T21:22:42
2019-08-27T09:43:58
Python
UTF-8
C
false
false
223
c
test_package.c
#include <stdio.h> #include <stdlib.h> #include "libiberty/libiberty.h" int main(void) { printf("GETPWD: %s\n", getpwd()); printf("CONCAT (FOO + BAR): %s\n", concat("FOO", "BAR", NULL)); return EXIT_SUCCESS; }
fde22fd2ca9506a48ba8209317a0dd38d4d1a11f
748626778e870ce6cdfd0c1f3b46d7f8a096b5a8
/src/condor_filetransfer_plugins/data_plugin.c
e24592bad62e8428e7dae7d2c0fd218414f547d4
[ "Apache-2.0" ]
permissive
htcondor/htcondor
1c8bab33379299f64e5274a7d525f3c64c64c47f
3b67625b2f4d97bcc28f534340a6fd7ac518dc75
refs/heads/main
2023-08-31T03:17:53.070364
2023-08-31T00:18:04
2023-08-31T00:18:04
5,808,515
249
165
Apache-2.0
2023-09-14T18:44:26
2012-09-14T11:35:15
C++
UTF-8
C
false
false
3,243
c
data_plugin.c
#include <stdio.h> #include <stdlib.h> #include <string.h> /* * in: base64 encoded string with * out: 3 uncoded bytes * returns number of chars passed over (4 or more) */ int decode_block(unsigned char *in, unsigned char *out) { unsigned char *c = in; int i = 0, j = 0; char temp[4] = { 0, 0, 0, 0}; // convert char to corresponding base64 value(0-63) while(i < 4 && c && *c) { if(*c != ' ') { // skip over whitespace if(*c == '+') { temp[i] = 62; } else if(*c == '/') { temp[i] = 63; } else if(*c == '=') { temp[i] = 0; // padding } else if(*c >= '0' && *c <= '9') { temp[i] = *c + 4; } else if(*c >= 'A' && *c <= 'Z') { temp[i] = *c - 65; } else if(*c >= 'a' && *c <= 'z') { temp[i] = *c - 71; } else if(*c == ' ') { j++; } else { break; //invalid char } i++; } j++; c++; } // Convert base64 values into bytes out[0] = (temp[0] << 2) + (temp[1] >> 4); out[1] = (temp[1] << 4) + (temp[2] >> 2); out[2] = (temp[2] << 6) + (temp[3] >> 0); return j; // Number of chars passed over } // decode ASCII hex characters int decode_hex(const char * p, int len, int * pvalid) { int valid = 1; int value = 0; int ii; for (ii = 0; ii < len; ++ii) { int ch = p[ii]; if (ch >= '0' && ch <= '9') { ch -= '0'; // ch is now a hex digit between 0x00 and 0x09 } else { ch &= ~20; // force uppercase if ascii if (ch < 'A' || ch > 'F') { // digit was not a valid hex digit... valid = 0; break; } ch = ch - 'A' + 0x0A; // ch is now a hex digit between 0x0A and 0x0F } value = (value << 4) + ch; } if (pvalid) *pvalid = valid; return value; } int main(int argc, char **argv) { char *c = NULL, *d = NULL, *data = NULL, *dest = NULL, *lastslash = NULL; unsigned char out[4]; FILE *file = NULL; int base64 = 0, rval = -1; if(argc == 2 && strcmp(argv[1], "-classad") == 0) { printf("%s", "PluginVersion = \"0.1\"\n" "PluginType = \"FileTransfer\"\n" "SupportedMethods = \"data\"\n" ); return 0; } if(argc != 3) { return -1; } data = strchr(argv[1], ','); lastslash = strrchr(argv[1], '/'); dest = argv[2]; if(data && lastslash && (file = fopen(dest, "w"))) { rval = 4; // Check for base64 encoding c = argv[1]; d = NULL; do { d = strchr(c, ';'); if(d && d < data) { base64 = !strncmp(d, ";base64,", 7); c = d+1; } else { break; } } while(!base64); c = data+1; if(base64) { // base64 encoding out[3] = '\0'; while(c && *c && c+3 < lastslash && rval >= 4) { rval = decode_block((unsigned char*)c, out); fputs((char*)out, file); c+=rval; } // invalid base64 data (not 4 char aligned) if(c < lastslash) { rval = -1; } } else { // ASCII encoding while(c && *c && *c != '/') { if(*c == '%') { // %XX two hex digits must follow a % int valid = 0, ch; c++; ch = decode_hex(c, 2, &valid); if ( ! valid) { rval = -1; break; } fputc(ch, file); c++; } else { fputc(*c, file); } c++; } } fclose(file); if(rval < 4) { remove(dest); // Remove file if we failed } else { rval = 0; } } return rval; // >= 0 on success, -1 on failure }
43d37b8c9f220e04d06e720ad86a7b0394069645
0744dcc5394cebf57ebcba343747af6871b67017
/os/board/rtl8730e/src/component/ui/LVGL/lvgl/src/extra/libs/gif/lv_gif.h
bed3a522187b81a977435e5be2dd2af740de431e
[ "GPL-1.0-or-later", "BSD-3-Clause", "ISC", "MIT", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-other-permissive", "Apache-2.0" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
888
h
lv_gif.h
/** * @file lv_gif.h * */ #ifndef LV_GIF_H #define LV_GIF_H #ifdef __cplusplus extern "C" { #endif /********************* * INCLUDES *********************/ #include "../../../lvgl.h" #if LV_USE_GIF #include "gifdec.h" /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ typedef struct { lv_img_t img; gd_GIF *gif; lv_timer_t *timer; lv_img_dsc_t imgdsc; uint32_t last_call; } lv_gif_t; extern const lv_obj_class_t lv_gif_class; /********************** * GLOBAL PROTOTYPES **********************/ lv_obj_t *lv_gif_create(lv_obj_t *parent); void lv_gif_set_src(lv_obj_t *obj, const void *src); void lv_gif_restart(lv_obj_t *gif); /********************** * MACROS **********************/ #endif /*LV_USE_GIF*/ #ifdef __cplusplus } /* extern "C" */ #endif #endif /*LV_GIF_H*/
36b32ce68cee4d46b1b379bffc968064f8bbd263
a12b448f44beb4d521cb7e31677281f41df35f0b
/3rdParty/isl/isl_sample.c
058d689cef5f475b6ca7282f5ca72cb24ac2b023
[ "MIT", "LGPL-2.0-or-later" ]
permissive
Tiramisu-Compiler/tiramisu
d45f65dd9c35f643b3531ec79df1203c7ea3371d
f13e480f0ddb142cec371b7d7431a41d8ca885ec
refs/heads/master
2023-08-25T12:21:26.889736
2023-05-09T18:40:52
2023-05-09T18:40:52
58,378,976
906
168
MIT
2023-09-08T11:47:06
2016-05-09T13:33:51
C++
UTF-8
C
false
false
37,248
c
isl_sample.c
/* * Copyright 2008-2009 Katholieke Universiteit Leuven * * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ #include <isl_ctx_private.h> #include <isl_map_private.h> #include "isl_sample.h" #include <isl/vec.h> #include <isl/mat.h> #include <isl_seq.h> #include "isl_equalities.h" #include "isl_tab.h" #include "isl_basis_reduction.h" #include <isl_factorization.h> #include <isl_point_private.h> #include <isl_options_private.h> #include <isl_vec_private.h> #include <bset_from_bmap.c> #include <set_to_map.c> static __isl_give isl_vec *empty_sample(__isl_take isl_basic_set *bset) { struct isl_vec *vec; vec = isl_vec_alloc(bset->ctx, 0); isl_basic_set_free(bset); return vec; } /* Construct a zero sample of the same dimension as bset. * As a special case, if bset is zero-dimensional, this * function creates a zero-dimensional sample point. */ static __isl_give isl_vec *zero_sample(__isl_take isl_basic_set *bset) { unsigned dim; struct isl_vec *sample; dim = isl_basic_set_total_dim(bset); sample = isl_vec_alloc(bset->ctx, 1 + dim); if (sample) { isl_int_set_si(sample->el[0], 1); isl_seq_clr(sample->el + 1, dim); } isl_basic_set_free(bset); return sample; } static __isl_give isl_vec *interval_sample(__isl_take isl_basic_set *bset) { int i; isl_int t; struct isl_vec *sample; bset = isl_basic_set_simplify(bset); if (!bset) return NULL; if (isl_basic_set_plain_is_empty(bset)) return empty_sample(bset); if (bset->n_eq == 0 && bset->n_ineq == 0) return zero_sample(bset); sample = isl_vec_alloc(bset->ctx, 2); if (!sample) goto error; if (!bset) return NULL; isl_int_set_si(sample->block.data[0], 1); if (bset->n_eq > 0) { isl_assert(bset->ctx, bset->n_eq == 1, goto error); isl_assert(bset->ctx, bset->n_ineq == 0, goto error); if (isl_int_is_one(bset->eq[0][1])) isl_int_neg(sample->el[1], bset->eq[0][0]); else { isl_assert(bset->ctx, isl_int_is_negone(bset->eq[0][1]), goto error); isl_int_set(sample->el[1], bset->eq[0][0]); } isl_basic_set_free(bset); return sample; } isl_int_init(t); if (isl_int_is_one(bset->ineq[0][1])) isl_int_neg(sample->block.data[1], bset->ineq[0][0]); else isl_int_set(sample->block.data[1], bset->ineq[0][0]); for (i = 1; i < bset->n_ineq; ++i) { isl_seq_inner_product(sample->block.data, bset->ineq[i], 2, &t); if (isl_int_is_neg(t)) break; } isl_int_clear(t); if (i < bset->n_ineq) { isl_vec_free(sample); return empty_sample(bset); } isl_basic_set_free(bset); return sample; error: isl_basic_set_free(bset); isl_vec_free(sample); return NULL; } /* Find a sample integer point, if any, in bset, which is known * to have equalities. If bset contains no integer points, then * return a zero-length vector. * We simply remove the known equalities, compute a sample * in the resulting bset, using the specified recurse function, * and then transform the sample back to the original space. */ static __isl_give isl_vec *sample_eq(__isl_take isl_basic_set *bset, __isl_give isl_vec *(*recurse)(__isl_take isl_basic_set *)) { struct isl_mat *T; struct isl_vec *sample; if (!bset) return NULL; bset = isl_basic_set_remove_equalities(bset, &T, NULL); sample = recurse(bset); if (!sample || sample->size == 0) isl_mat_free(T); else sample = isl_mat_vec_product(T, sample); return sample; } /* Return a matrix containing the equalities of the tableau * in constraint form. The tableau is assumed to have * an associated bset that has been kept up-to-date. */ static struct isl_mat *tab_equalities(struct isl_tab *tab) { int i, j; int n_eq; struct isl_mat *eq; struct isl_basic_set *bset; if (!tab) return NULL; bset = isl_tab_peek_bset(tab); isl_assert(tab->mat->ctx, bset, return NULL); n_eq = tab->n_var - tab->n_col + tab->n_dead; if (tab->empty || n_eq == 0) return isl_mat_alloc(tab->mat->ctx, 0, tab->n_var); if (n_eq == tab->n_var) return isl_mat_identity(tab->mat->ctx, tab->n_var); eq = isl_mat_alloc(tab->mat->ctx, n_eq, tab->n_var); if (!eq) return NULL; for (i = 0, j = 0; i < tab->n_con; ++i) { if (tab->con[i].is_row) continue; if (tab->con[i].index >= 0 && tab->con[i].index >= tab->n_dead) continue; if (i < bset->n_eq) isl_seq_cpy(eq->row[j], bset->eq[i] + 1, tab->n_var); else isl_seq_cpy(eq->row[j], bset->ineq[i - bset->n_eq] + 1, tab->n_var); ++j; } isl_assert(bset->ctx, j == n_eq, goto error); return eq; error: isl_mat_free(eq); return NULL; } /* Compute and return an initial basis for the bounded tableau "tab". * * If the tableau is either full-dimensional or zero-dimensional, * the we simply return an identity matrix. * Otherwise, we construct a basis whose first directions correspond * to equalities. */ static struct isl_mat *initial_basis(struct isl_tab *tab) { int n_eq; struct isl_mat *eq; struct isl_mat *Q; tab->n_unbounded = 0; tab->n_zero = n_eq = tab->n_var - tab->n_col + tab->n_dead; if (tab->empty || n_eq == 0 || n_eq == tab->n_var) return isl_mat_identity(tab->mat->ctx, 1 + tab->n_var); eq = tab_equalities(tab); eq = isl_mat_left_hermite(eq, 0, NULL, &Q); if (!eq) return NULL; isl_mat_free(eq); Q = isl_mat_lin_to_aff(Q); return Q; } /* Compute the minimum of the current ("level") basis row over "tab" * and store the result in position "level" of "min". * * This function assumes that at least one more row and at least * one more element in the constraint array are available in the tableau. */ static enum isl_lp_result compute_min(isl_ctx *ctx, struct isl_tab *tab, __isl_keep isl_vec *min, int level) { return isl_tab_min(tab, tab->basis->row[1 + level], ctx->one, &min->el[level], NULL, 0); } /* Compute the maximum of the current ("level") basis row over "tab" * and store the result in position "level" of "max". * * This function assumes that at least one more row and at least * one more element in the constraint array are available in the tableau. */ static enum isl_lp_result compute_max(isl_ctx *ctx, struct isl_tab *tab, __isl_keep isl_vec *max, int level) { enum isl_lp_result res; unsigned dim = tab->n_var; isl_seq_neg(tab->basis->row[1 + level] + 1, tab->basis->row[1 + level] + 1, dim); res = isl_tab_min(tab, tab->basis->row[1 + level], ctx->one, &max->el[level], NULL, 0); isl_seq_neg(tab->basis->row[1 + level] + 1, tab->basis->row[1 + level] + 1, dim); isl_int_neg(max->el[level], max->el[level]); return res; } /* Perform a greedy search for an integer point in the set represented * by "tab", given that the minimal rational value (rounded up to the * nearest integer) at "level" is smaller than the maximal rational * value (rounded down to the nearest integer). * * Return 1 if we have found an integer point (if tab->n_unbounded > 0 * then we may have only found integer values for the bounded dimensions * and it is the responsibility of the caller to extend this solution * to the unbounded dimensions). * Return 0 if greedy search did not result in a solution. * Return -1 if some error occurred. * * We assign a value half-way between the minimum and the maximum * to the current dimension and check if the minimal value of the * next dimension is still smaller than (or equal) to the maximal value. * We continue this process until either * - the minimal value (rounded up) is greater than the maximal value * (rounded down). In this case, greedy search has failed. * - we have exhausted all bounded dimensions, meaning that we have * found a solution. * - the sample value of the tableau is integral. * - some error has occurred. */ static int greedy_search(isl_ctx *ctx, struct isl_tab *tab, __isl_keep isl_vec *min, __isl_keep isl_vec *max, int level) { struct isl_tab_undo *snap; enum isl_lp_result res; snap = isl_tab_snap(tab); do { isl_int_add(tab->basis->row[1 + level][0], min->el[level], max->el[level]); isl_int_fdiv_q_ui(tab->basis->row[1 + level][0], tab->basis->row[1 + level][0], 2); isl_int_neg(tab->basis->row[1 + level][0], tab->basis->row[1 + level][0]); if (isl_tab_add_valid_eq(tab, tab->basis->row[1 + level]) < 0) return -1; isl_int_set_si(tab->basis->row[1 + level][0], 0); if (++level >= tab->n_var - tab->n_unbounded) return 1; if (isl_tab_sample_is_integer(tab)) return 1; res = compute_min(ctx, tab, min, level); if (res == isl_lp_error) return -1; if (res != isl_lp_ok) isl_die(ctx, isl_error_internal, "expecting bounded rational solution", return -1); res = compute_max(ctx, tab, max, level); if (res == isl_lp_error) return -1; if (res != isl_lp_ok) isl_die(ctx, isl_error_internal, "expecting bounded rational solution", return -1); } while (isl_int_le(min->el[level], max->el[level])); if (isl_tab_rollback(tab, snap) < 0) return -1; return 0; } /* Given a tableau representing a set, find and return * an integer point in the set, if there is any. * * We perform a depth first search * for an integer point, by scanning all possible values in the range * attained by a basis vector, where an initial basis may have been set * by the calling function. Otherwise an initial basis that exploits * the equalities in the tableau is created. * tab->n_zero is currently ignored and is clobbered by this function. * * The tableau is allowed to have unbounded direction, but then * the calling function needs to set an initial basis, with the * unbounded directions last and with tab->n_unbounded set * to the number of unbounded directions. * Furthermore, the calling functions needs to add shifted copies * of all constraints involving unbounded directions to ensure * that any feasible rational value in these directions can be rounded * up to yield a feasible integer value. * In particular, let B define the given basis x' = B x * and let T be the inverse of B, i.e., X = T x'. * Let a x + c >= 0 be a constraint of the set represented by the tableau, * or a T x' + c >= 0 in terms of the given basis. Assume that * the bounded directions have an integer value, then we can safely * round up the values for the unbounded directions if we make sure * that x' not only satisfies the original constraint, but also * the constraint "a T x' + c + s >= 0" with s the sum of all * negative values in the last n_unbounded entries of "a T". * The calling function therefore needs to add the constraint * a x + c + s >= 0. The current function then scans the first * directions for an integer value and once those have been found, * it can compute "T ceil(B x)" to yield an integer point in the set. * Note that during the search, the first rows of B may be changed * by a basis reduction, but the last n_unbounded rows of B remain * unaltered and are also not mixed into the first rows. * * The search is implemented iteratively. "level" identifies the current * basis vector. "init" is true if we want the first value at the current * level and false if we want the next value. * * At the start of each level, we first check if we can find a solution * using greedy search. If not, we continue with the exhaustive search. * * The initial basis is the identity matrix. If the range in some direction * contains more than one integer value, we perform basis reduction based * on the value of ctx->opt->gbr * - ISL_GBR_NEVER: never perform basis reduction * - ISL_GBR_ONCE: only perform basis reduction the first * time such a range is encountered * - ISL_GBR_ALWAYS: always perform basis reduction when * such a range is encountered * * When ctx->opt->gbr is set to ISL_GBR_ALWAYS, then we allow the basis * reduction computation to return early. That is, as soon as it * finds a reasonable first direction. */ struct isl_vec *isl_tab_sample(struct isl_tab *tab) { unsigned dim; unsigned gbr; struct isl_ctx *ctx; struct isl_vec *sample; struct isl_vec *min; struct isl_vec *max; enum isl_lp_result res; int level; int init; int reduced; struct isl_tab_undo **snap; if (!tab) return NULL; if (tab->empty) return isl_vec_alloc(tab->mat->ctx, 0); if (!tab->basis) tab->basis = initial_basis(tab); if (!tab->basis) return NULL; isl_assert(tab->mat->ctx, tab->basis->n_row == tab->n_var + 1, return NULL); isl_assert(tab->mat->ctx, tab->basis->n_col == tab->n_var + 1, return NULL); ctx = tab->mat->ctx; dim = tab->n_var; gbr = ctx->opt->gbr; if (tab->n_unbounded == tab->n_var) { sample = isl_tab_get_sample_value(tab); sample = isl_mat_vec_product(isl_mat_copy(tab->basis), sample); sample = isl_vec_ceil(sample); sample = isl_mat_vec_inverse_product(isl_mat_copy(tab->basis), sample); return sample; } if (isl_tab_extend_cons(tab, dim + 1) < 0) return NULL; min = isl_vec_alloc(ctx, dim); max = isl_vec_alloc(ctx, dim); snap = isl_alloc_array(ctx, struct isl_tab_undo *, dim); if (!min || !max || !snap) goto error; level = 0; init = 1; reduced = 0; while (level >= 0) { if (init) { int choice; res = compute_min(ctx, tab, min, level); if (res == isl_lp_error) goto error; if (res != isl_lp_ok) isl_die(ctx, isl_error_internal, "expecting bounded rational solution", goto error); if (isl_tab_sample_is_integer(tab)) break; res = compute_max(ctx, tab, max, level); if (res == isl_lp_error) goto error; if (res != isl_lp_ok) isl_die(ctx, isl_error_internal, "expecting bounded rational solution", goto error); if (isl_tab_sample_is_integer(tab)) break; choice = isl_int_lt(min->el[level], max->el[level]); if (choice) { int g; g = greedy_search(ctx, tab, min, max, level); if (g < 0) goto error; if (g) break; } if (!reduced && choice && ctx->opt->gbr != ISL_GBR_NEVER) { unsigned gbr_only_first; if (ctx->opt->gbr == ISL_GBR_ONCE) ctx->opt->gbr = ISL_GBR_NEVER; tab->n_zero = level; gbr_only_first = ctx->opt->gbr_only_first; ctx->opt->gbr_only_first = ctx->opt->gbr == ISL_GBR_ALWAYS; tab = isl_tab_compute_reduced_basis(tab); ctx->opt->gbr_only_first = gbr_only_first; if (!tab || !tab->basis) goto error; reduced = 1; continue; } reduced = 0; snap[level] = isl_tab_snap(tab); } else isl_int_add_ui(min->el[level], min->el[level], 1); if (isl_int_gt(min->el[level], max->el[level])) { level--; init = 0; if (level >= 0) if (isl_tab_rollback(tab, snap[level]) < 0) goto error; continue; } isl_int_neg(tab->basis->row[1 + level][0], min->el[level]); if (isl_tab_add_valid_eq(tab, tab->basis->row[1 + level]) < 0) goto error; isl_int_set_si(tab->basis->row[1 + level][0], 0); if (level + tab->n_unbounded < dim - 1) { ++level; init = 1; continue; } break; } if (level >= 0) { sample = isl_tab_get_sample_value(tab); if (!sample) goto error; if (tab->n_unbounded && !isl_int_is_one(sample->el[0])) { sample = isl_mat_vec_product(isl_mat_copy(tab->basis), sample); sample = isl_vec_ceil(sample); sample = isl_mat_vec_inverse_product( isl_mat_copy(tab->basis), sample); } } else sample = isl_vec_alloc(ctx, 0); ctx->opt->gbr = gbr; isl_vec_free(min); isl_vec_free(max); free(snap); return sample; error: ctx->opt->gbr = gbr; isl_vec_free(min); isl_vec_free(max); free(snap); return NULL; } static __isl_give isl_vec *sample_bounded(__isl_take isl_basic_set *bset); /* Compute a sample point of the given basic set, based on the given, * non-trivial factorization. */ static __isl_give isl_vec *factored_sample(__isl_take isl_basic_set *bset, __isl_take isl_factorizer *f) { int i, n; isl_vec *sample = NULL; isl_ctx *ctx; unsigned nparam; unsigned nvar; ctx = isl_basic_set_get_ctx(bset); if (!ctx) goto error; nparam = isl_basic_set_dim(bset, isl_dim_param); nvar = isl_basic_set_dim(bset, isl_dim_set); sample = isl_vec_alloc(ctx, 1 + isl_basic_set_total_dim(bset)); if (!sample) goto error; isl_int_set_si(sample->el[0], 1); bset = isl_morph_basic_set(isl_morph_copy(f->morph), bset); for (i = 0, n = 0; i < f->n_group; ++i) { isl_basic_set *bset_i; isl_vec *sample_i; bset_i = isl_basic_set_copy(bset); bset_i = isl_basic_set_drop_constraints_involving(bset_i, nparam + n + f->len[i], nvar - n - f->len[i]); bset_i = isl_basic_set_drop_constraints_involving(bset_i, nparam, n); bset_i = isl_basic_set_drop(bset_i, isl_dim_set, n + f->len[i], nvar - n - f->len[i]); bset_i = isl_basic_set_drop(bset_i, isl_dim_set, 0, n); sample_i = sample_bounded(bset_i); if (!sample_i) goto error; if (sample_i->size == 0) { isl_basic_set_free(bset); isl_factorizer_free(f); isl_vec_free(sample); return sample_i; } isl_seq_cpy(sample->el + 1 + nparam + n, sample_i->el + 1, f->len[i]); isl_vec_free(sample_i); n += f->len[i]; } f->morph = isl_morph_inverse(f->morph); sample = isl_morph_vec(isl_morph_copy(f->morph), sample); isl_basic_set_free(bset); isl_factorizer_free(f); return sample; error: isl_basic_set_free(bset); isl_factorizer_free(f); isl_vec_free(sample); return NULL; } /* Given a basic set that is known to be bounded, find and return * an integer point in the basic set, if there is any. * * After handling some trivial cases, we construct a tableau * and then use isl_tab_sample to find a sample, passing it * the identity matrix as initial basis. */ static __isl_give isl_vec *sample_bounded(__isl_take isl_basic_set *bset) { unsigned dim; struct isl_vec *sample; struct isl_tab *tab = NULL; isl_factorizer *f; if (!bset) return NULL; if (isl_basic_set_plain_is_empty(bset)) return empty_sample(bset); dim = isl_basic_set_total_dim(bset); if (dim == 0) return zero_sample(bset); if (dim == 1) return interval_sample(bset); if (bset->n_eq > 0) return sample_eq(bset, sample_bounded); f = isl_basic_set_factorizer(bset); if (!f) goto error; if (f->n_group != 0) return factored_sample(bset, f); isl_factorizer_free(f); tab = isl_tab_from_basic_set(bset, 1); if (tab && tab->empty) { isl_tab_free(tab); ISL_F_SET(bset, ISL_BASIC_SET_EMPTY); sample = isl_vec_alloc(isl_basic_set_get_ctx(bset), 0); isl_basic_set_free(bset); return sample; } if (!ISL_F_ISSET(bset, ISL_BASIC_SET_NO_IMPLICIT)) if (isl_tab_detect_implicit_equalities(tab) < 0) goto error; sample = isl_tab_sample(tab); if (!sample) goto error; if (sample->size > 0) { isl_vec_free(bset->sample); bset->sample = isl_vec_copy(sample); } isl_basic_set_free(bset); isl_tab_free(tab); return sample; error: isl_basic_set_free(bset); isl_tab_free(tab); return NULL; } /* Given a basic set "bset" and a value "sample" for the first coordinates * of bset, plug in these values and drop the corresponding coordinates. * * We do this by computing the preimage of the transformation * * [ 1 0 ] * x = [ s 0 ] x' * [ 0 I ] * * where [1 s] is the sample value and I is the identity matrix of the * appropriate dimension. */ static __isl_give isl_basic_set *plug_in(__isl_take isl_basic_set *bset, __isl_take isl_vec *sample) { int i; unsigned total; struct isl_mat *T; if (!bset || !sample) goto error; total = isl_basic_set_total_dim(bset); T = isl_mat_alloc(bset->ctx, 1 + total, 1 + total - (sample->size - 1)); if (!T) goto error; for (i = 0; i < sample->size; ++i) { isl_int_set(T->row[i][0], sample->el[i]); isl_seq_clr(T->row[i] + 1, T->n_col - 1); } for (i = 0; i < T->n_col - 1; ++i) { isl_seq_clr(T->row[sample->size + i], T->n_col); isl_int_set_si(T->row[sample->size + i][1 + i], 1); } isl_vec_free(sample); bset = isl_basic_set_preimage(bset, T); return bset; error: isl_basic_set_free(bset); isl_vec_free(sample); return NULL; } /* Given a basic set "bset", return any (possibly non-integer) point * in the basic set. */ static __isl_give isl_vec *rational_sample(__isl_take isl_basic_set *bset) { struct isl_tab *tab; struct isl_vec *sample; if (!bset) return NULL; tab = isl_tab_from_basic_set(bset, 0); sample = isl_tab_get_sample_value(tab); isl_tab_free(tab); isl_basic_set_free(bset); return sample; } /* Given a linear cone "cone" and a rational point "vec", * construct a polyhedron with shifted copies of the constraints in "cone", * i.e., a polyhedron with "cone" as its recession cone, such that each * point x in this polyhedron is such that the unit box positioned at x * lies entirely inside the affine cone 'vec + cone'. * Any rational point in this polyhedron may therefore be rounded up * to yield an integer point that lies inside said affine cone. * * Denote the constraints of cone by "<a_i, x> >= 0" and the rational * point "vec" by v/d. * Let b_i = <a_i, v>. Then the affine cone 'vec + cone' is given * by <a_i, x> - b/d >= 0. * The polyhedron <a_i, x> - ceil{b/d} >= 0 is a subset of this affine cone. * We prefer this polyhedron over the actual affine cone because it doesn't * require a scaling of the constraints. * If each of the vertices of the unit cube positioned at x lies inside * this polyhedron, then the whole unit cube at x lies inside the affine cone. * We therefore impose that x' = x + \sum e_i, for any selection of unit * vectors lies inside the polyhedron, i.e., * * <a_i, x'> - ceil{b/d} = <a_i, x> + sum a_i - ceil{b/d} >= 0 * * The most stringent of these constraints is the one that selects * all negative a_i, so the polyhedron we are looking for has constraints * * <a_i, x> + sum_{a_i < 0} a_i - ceil{b/d} >= 0 * * Note that if cone were known to have only non-negative rays * (which can be accomplished by a unimodular transformation), * then we would only have to check the points x' = x + e_i * and we only have to add the smallest negative a_i (if any) * instead of the sum of all negative a_i. */ static __isl_give isl_basic_set *shift_cone(__isl_take isl_basic_set *cone, __isl_take isl_vec *vec) { int i, j, k; unsigned total; struct isl_basic_set *shift = NULL; if (!cone || !vec) goto error; isl_assert(cone->ctx, cone->n_eq == 0, goto error); total = isl_basic_set_total_dim(cone); shift = isl_basic_set_alloc_space(isl_basic_set_get_space(cone), 0, 0, cone->n_ineq); for (i = 0; i < cone->n_ineq; ++i) { k = isl_basic_set_alloc_inequality(shift); if (k < 0) goto error; isl_seq_cpy(shift->ineq[k] + 1, cone->ineq[i] + 1, total); isl_seq_inner_product(shift->ineq[k] + 1, vec->el + 1, total, &shift->ineq[k][0]); isl_int_cdiv_q(shift->ineq[k][0], shift->ineq[k][0], vec->el[0]); isl_int_neg(shift->ineq[k][0], shift->ineq[k][0]); for (j = 0; j < total; ++j) { if (isl_int_is_nonneg(shift->ineq[k][1 + j])) continue; isl_int_add(shift->ineq[k][0], shift->ineq[k][0], shift->ineq[k][1 + j]); } } isl_basic_set_free(cone); isl_vec_free(vec); return isl_basic_set_finalize(shift); error: isl_basic_set_free(shift); isl_basic_set_free(cone); isl_vec_free(vec); return NULL; } /* Given a rational point vec in a (transformed) basic set, * such that cone is the recession cone of the original basic set, * "round up" the rational point to an integer point. * * We first check if the rational point just happens to be integer. * If not, we transform the cone in the same way as the basic set, * pick a point x in this cone shifted to the rational point such that * the whole unit cube at x is also inside this affine cone. * Then we simply round up the coordinates of x and return the * resulting integer point. */ static __isl_give isl_vec *round_up_in_cone(__isl_take isl_vec *vec, __isl_take isl_basic_set *cone, __isl_take isl_mat *U) { unsigned total; if (!vec || !cone || !U) goto error; isl_assert(vec->ctx, vec->size != 0, goto error); if (isl_int_is_one(vec->el[0])) { isl_mat_free(U); isl_basic_set_free(cone); return vec; } total = isl_basic_set_total_dim(cone); cone = isl_basic_set_preimage(cone, U); cone = isl_basic_set_remove_dims(cone, isl_dim_set, 0, total - (vec->size - 1)); cone = shift_cone(cone, vec); vec = rational_sample(cone); vec = isl_vec_ceil(vec); return vec; error: isl_mat_free(U); isl_vec_free(vec); isl_basic_set_free(cone); return NULL; } /* Concatenate two integer vectors, i.e., two vectors with denominator * (stored in element 0) equal to 1. */ static __isl_give isl_vec *vec_concat(__isl_take isl_vec *vec1, __isl_take isl_vec *vec2) { struct isl_vec *vec; if (!vec1 || !vec2) goto error; isl_assert(vec1->ctx, vec1->size > 0, goto error); isl_assert(vec2->ctx, vec2->size > 0, goto error); isl_assert(vec1->ctx, isl_int_is_one(vec1->el[0]), goto error); isl_assert(vec2->ctx, isl_int_is_one(vec2->el[0]), goto error); vec = isl_vec_alloc(vec1->ctx, vec1->size + vec2->size - 1); if (!vec) goto error; isl_seq_cpy(vec->el, vec1->el, vec1->size); isl_seq_cpy(vec->el + vec1->size, vec2->el + 1, vec2->size - 1); isl_vec_free(vec1); isl_vec_free(vec2); return vec; error: isl_vec_free(vec1); isl_vec_free(vec2); return NULL; } /* Give a basic set "bset" with recession cone "cone", compute and * return an integer point in bset, if any. * * If the recession cone is full-dimensional, then we know that * bset contains an infinite number of integer points and it is * fairly easy to pick one of them. * If the recession cone is not full-dimensional, then we first * transform bset such that the bounded directions appear as * the first dimensions of the transformed basic set. * We do this by using a unimodular transformation that transforms * the equalities in the recession cone to equalities on the first * dimensions. * * The transformed set is then projected onto its bounded dimensions. * Note that to compute this projection, we can simply drop all constraints * involving any of the unbounded dimensions since these constraints * cannot be combined to produce a constraint on the bounded dimensions. * To see this, assume that there is such a combination of constraints * that produces a constraint on the bounded dimensions. This means * that some combination of the unbounded dimensions has both an upper * bound and a lower bound in terms of the bounded dimensions, but then * this combination would be a bounded direction too and would have been * transformed into a bounded dimensions. * * We then compute a sample value in the bounded dimensions. * If no such value can be found, then the original set did not contain * any integer points and we are done. * Otherwise, we plug in the value we found in the bounded dimensions, * project out these bounded dimensions and end up with a set with * a full-dimensional recession cone. * A sample point in this set is computed by "rounding up" any * rational point in the set. * * The sample points in the bounded and unbounded dimensions are * then combined into a single sample point and transformed back * to the original space. */ __isl_give isl_vec *isl_basic_set_sample_with_cone( __isl_take isl_basic_set *bset, __isl_take isl_basic_set *cone) { unsigned total; unsigned cone_dim; struct isl_mat *M, *U; struct isl_vec *sample; struct isl_vec *cone_sample; struct isl_ctx *ctx; struct isl_basic_set *bounded; if (!bset || !cone) goto error; ctx = isl_basic_set_get_ctx(bset); total = isl_basic_set_total_dim(cone); cone_dim = total - cone->n_eq; M = isl_mat_sub_alloc6(ctx, cone->eq, 0, cone->n_eq, 1, total); M = isl_mat_left_hermite(M, 0, &U, NULL); if (!M) goto error; isl_mat_free(M); U = isl_mat_lin_to_aff(U); bset = isl_basic_set_preimage(bset, isl_mat_copy(U)); bounded = isl_basic_set_copy(bset); bounded = isl_basic_set_drop_constraints_involving(bounded, total - cone_dim, cone_dim); bounded = isl_basic_set_drop_dims(bounded, total - cone_dim, cone_dim); sample = sample_bounded(bounded); if (!sample || sample->size == 0) { isl_basic_set_free(bset); isl_basic_set_free(cone); isl_mat_free(U); return sample; } bset = plug_in(bset, isl_vec_copy(sample)); cone_sample = rational_sample(bset); cone_sample = round_up_in_cone(cone_sample, cone, isl_mat_copy(U)); sample = vec_concat(sample, cone_sample); sample = isl_mat_vec_product(U, sample); return sample; error: isl_basic_set_free(cone); isl_basic_set_free(bset); return NULL; } static void vec_sum_of_neg(struct isl_vec *v, isl_int *s) { int i; isl_int_set_si(*s, 0); for (i = 0; i < v->size; ++i) if (isl_int_is_neg(v->el[i])) isl_int_add(*s, *s, v->el[i]); } /* Given a tableau "tab", a tableau "tab_cone" that corresponds * to the recession cone and the inverse of a new basis U = inv(B), * with the unbounded directions in B last, * add constraints to "tab" that ensure any rational value * in the unbounded directions can be rounded up to an integer value. * * The new basis is given by x' = B x, i.e., x = U x'. * For any rational value of the last tab->n_unbounded coordinates * in the update tableau, the value that is obtained by rounding * up this value should be contained in the original tableau. * For any constraint "a x + c >= 0", we therefore need to add * a constraint "a x + c + s >= 0", with s the sum of all negative * entries in the last elements of "a U". * * Since we are not interested in the first entries of any of the "a U", * we first drop the columns of U that correpond to bounded directions. */ static int tab_shift_cone(struct isl_tab *tab, struct isl_tab *tab_cone, struct isl_mat *U) { int i; isl_int v; struct isl_basic_set *bset = NULL; if (tab && tab->n_unbounded == 0) { isl_mat_free(U); return 0; } isl_int_init(v); if (!tab || !tab_cone || !U) goto error; bset = isl_tab_peek_bset(tab_cone); U = isl_mat_drop_cols(U, 0, tab->n_var - tab->n_unbounded); for (i = 0; i < bset->n_ineq; ++i) { int ok; struct isl_vec *row = NULL; if (isl_tab_is_equality(tab_cone, tab_cone->n_eq + i)) continue; row = isl_vec_alloc(bset->ctx, tab_cone->n_var); if (!row) goto error; isl_seq_cpy(row->el, bset->ineq[i] + 1, tab_cone->n_var); row = isl_vec_mat_product(row, isl_mat_copy(U)); if (!row) goto error; vec_sum_of_neg(row, &v); isl_vec_free(row); if (isl_int_is_zero(v)) continue; if (isl_tab_extend_cons(tab, 1) < 0) goto error; isl_int_add(bset->ineq[i][0], bset->ineq[i][0], v); ok = isl_tab_add_ineq(tab, bset->ineq[i]) >= 0; isl_int_sub(bset->ineq[i][0], bset->ineq[i][0], v); if (!ok) goto error; } isl_mat_free(U); isl_int_clear(v); return 0; error: isl_mat_free(U); isl_int_clear(v); return -1; } /* Compute and return an initial basis for the possibly * unbounded tableau "tab". "tab_cone" is a tableau * for the corresponding recession cone. * Additionally, add constraints to "tab" that ensure * that any rational value for the unbounded directions * can be rounded up to an integer value. * * If the tableau is bounded, i.e., if the recession cone * is zero-dimensional, then we just use inital_basis. * Otherwise, we construct a basis whose first directions * correspond to equalities, followed by bounded directions, * i.e., equalities in the recession cone. * The remaining directions are then unbounded. */ int isl_tab_set_initial_basis_with_cone(struct isl_tab *tab, struct isl_tab *tab_cone) { struct isl_mat *eq; struct isl_mat *cone_eq; struct isl_mat *U, *Q; if (!tab || !tab_cone) return -1; if (tab_cone->n_col == tab_cone->n_dead) { tab->basis = initial_basis(tab); return tab->basis ? 0 : -1; } eq = tab_equalities(tab); if (!eq) return -1; tab->n_zero = eq->n_row; cone_eq = tab_equalities(tab_cone); eq = isl_mat_concat(eq, cone_eq); if (!eq) return -1; tab->n_unbounded = tab->n_var - (eq->n_row - tab->n_zero); eq = isl_mat_left_hermite(eq, 0, &U, &Q); if (!eq) return -1; isl_mat_free(eq); tab->basis = isl_mat_lin_to_aff(Q); if (tab_shift_cone(tab, tab_cone, U) < 0) return -1; if (!tab->basis) return -1; return 0; } /* Compute and return a sample point in bset using generalized basis * reduction. We first check if the input set has a non-trivial * recession cone. If so, we perform some extra preprocessing in * sample_with_cone. Otherwise, we directly perform generalized basis * reduction. */ static __isl_give isl_vec *gbr_sample(__isl_take isl_basic_set *bset) { unsigned dim; struct isl_basic_set *cone; dim = isl_basic_set_total_dim(bset); cone = isl_basic_set_recession_cone(isl_basic_set_copy(bset)); if (!cone) goto error; if (cone->n_eq < dim) return isl_basic_set_sample_with_cone(bset, cone); isl_basic_set_free(cone); return sample_bounded(bset); error: isl_basic_set_free(bset); return NULL; } static __isl_give isl_vec *basic_set_sample(__isl_take isl_basic_set *bset, int bounded) { struct isl_ctx *ctx; unsigned dim; if (!bset) return NULL; ctx = bset->ctx; if (isl_basic_set_plain_is_empty(bset)) return empty_sample(bset); dim = isl_basic_set_n_dim(bset); isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error); isl_assert(ctx, bset->n_div == 0, goto error); if (bset->sample && bset->sample->size == 1 + dim) { int contains = isl_basic_set_contains(bset, bset->sample); if (contains < 0) goto error; if (contains) { struct isl_vec *sample = isl_vec_copy(bset->sample); isl_basic_set_free(bset); return sample; } } isl_vec_free(bset->sample); bset->sample = NULL; if (bset->n_eq > 0) return sample_eq(bset, bounded ? isl_basic_set_sample_bounded : isl_basic_set_sample_vec); if (dim == 0) return zero_sample(bset); if (dim == 1) return interval_sample(bset); return bounded ? sample_bounded(bset) : gbr_sample(bset); error: isl_basic_set_free(bset); return NULL; } __isl_give isl_vec *isl_basic_set_sample_vec(__isl_take isl_basic_set *bset) { return basic_set_sample(bset, 0); } /* Compute an integer sample in "bset", where the caller guarantees * that "bset" is bounded. */ __isl_give isl_vec *isl_basic_set_sample_bounded(__isl_take isl_basic_set *bset) { return basic_set_sample(bset, 1); } __isl_give isl_basic_set *isl_basic_set_from_vec(__isl_take isl_vec *vec) { int i; int k; struct isl_basic_set *bset = NULL; struct isl_ctx *ctx; unsigned dim; if (!vec) return NULL; ctx = vec->ctx; isl_assert(ctx, vec->size != 0, goto error); bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0); if (!bset) goto error; dim = isl_basic_set_n_dim(bset); for (i = dim - 1; i >= 0; --i) { k = isl_basic_set_alloc_equality(bset); if (k < 0) goto error; isl_seq_clr(bset->eq[k], 1 + dim); isl_int_neg(bset->eq[k][0], vec->el[1 + i]); isl_int_set(bset->eq[k][1 + i], vec->el[0]); } bset->sample = vec; return bset; error: isl_basic_set_free(bset); isl_vec_free(vec); return NULL; } __isl_give isl_basic_map *isl_basic_map_sample(__isl_take isl_basic_map *bmap) { struct isl_basic_set *bset; struct isl_vec *sample_vec; bset = isl_basic_map_underlying_set(isl_basic_map_copy(bmap)); sample_vec = isl_basic_set_sample_vec(bset); if (!sample_vec) goto error; if (sample_vec->size == 0) { isl_vec_free(sample_vec); return isl_basic_map_set_to_empty(bmap); } isl_vec_free(bmap->sample); bmap->sample = isl_vec_copy(sample_vec); bset = isl_basic_set_from_vec(sample_vec); return isl_basic_map_overlying_set(bset, bmap); error: isl_basic_map_free(bmap); return NULL; } __isl_give isl_basic_set *isl_basic_set_sample(__isl_take isl_basic_set *bset) { return isl_basic_map_sample(bset); } __isl_give isl_basic_map *isl_map_sample(__isl_take isl_map *map) { int i; isl_basic_map *sample = NULL; if (!map) goto error; for (i = 0; i < map->n; ++i) { sample = isl_basic_map_sample(isl_basic_map_copy(map->p[i])); if (!sample) goto error; if (!ISL_F_ISSET(sample, ISL_BASIC_MAP_EMPTY)) break; isl_basic_map_free(sample); } if (i == map->n) sample = isl_basic_map_empty(isl_map_get_space(map)); isl_map_free(map); return sample; error: isl_map_free(map); return NULL; } __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set) { return bset_from_bmap(isl_map_sample(set_to_map(set))); } __isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset) { isl_vec *vec; isl_space *dim; dim = isl_basic_set_get_space(bset); bset = isl_basic_set_underlying_set(bset); vec = isl_basic_set_sample_vec(bset); return isl_point_alloc(dim, vec); } __isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set) { int i; isl_point *pnt; if (!set) return NULL; for (i = 0; i < set->n; ++i) { pnt = isl_basic_set_sample_point(isl_basic_set_copy(set->p[i])); if (!pnt) goto error; if (!isl_point_is_void(pnt)) break; isl_point_free(pnt); } if (i == set->n) pnt = isl_point_void(isl_set_get_space(set)); isl_set_free(set); return pnt; error: isl_set_free(set); return NULL; }
954742b087296e5fe34ad58f22d6a586bf4b59a3
edccfef24a84712873938e24e138d2ce79834181
/third-party/zstd/contrib/seekable_format/examples/parallel_compression.c
4e06fae324125e518264614fc2657a27d66f84be
[ "BSD-3-Clause", "GPL-2.0-only", "MIT", "Zlib", "Apache-2.0", "BSD-2-Clause" ]
permissive
rui314/mold
aa746e60ee491af54b7753d35bef3d2b821ae0c6
f76d3e0d0c285fab4d770d4b57035d57690fade7
refs/heads/main
2023-08-31T22:14:27.427281
2023-08-31T09:16:26
2023-08-31T09:16:32
299,510,783
12,149
503
MIT
2023-09-14T03:54:12
2020-09-29T05:12:48
C++
UTF-8
C
false
false
6,029
c
parallel_compression.c
/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). */ #include <stdlib.h> // malloc, free, exit, atoi #include <stdio.h> // fprintf, perror, feof, fopen, etc. #include <string.h> // strlen, memset, strcat #define ZSTD_STATIC_LINKING_ONLY #include <zstd.h> // presumes zstd library is installed #include <zstd_errors.h> #if defined(WIN32) || defined(_WIN32) # include <windows.h> # define SLEEP(x) Sleep(x) #else # include <unistd.h> # define SLEEP(x) usleep(x * 1000) #endif #include "xxhash.h" #include "pool.h" // use zstd thread pool for demo #include "../zstd_seekable.h" static void* malloc_orDie(size_t size) { void* const buff = malloc(size); if (buff) return buff; /* error */ perror("malloc:"); exit(1); } static FILE* fopen_orDie(const char *filename, const char *instruction) { FILE* const inFile = fopen(filename, instruction); if (inFile) return inFile; /* error */ perror(filename); exit(3); } static size_t fread_orDie(void* buffer, size_t sizeToRead, FILE* file) { size_t const readSize = fread(buffer, 1, sizeToRead, file); if (readSize == sizeToRead) return readSize; /* good */ if (feof(file)) return readSize; /* good, reached end of file */ /* error */ perror("fread"); exit(4); } static size_t fwrite_orDie(const void* buffer, size_t sizeToWrite, FILE* file) { size_t const writtenSize = fwrite(buffer, 1, sizeToWrite, file); if (writtenSize == sizeToWrite) return sizeToWrite; /* good */ /* error */ perror("fwrite"); exit(5); } static size_t fclose_orDie(FILE* file) { if (!fclose(file)) return 0; /* error */ perror("fclose"); exit(6); } static void fseek_orDie(FILE* file, long int offset, int origin) { if (!fseek(file, offset, origin)) { if (!fflush(file)) return; } /* error */ perror("fseek"); exit(7); } static long int ftell_orDie(FILE* file) { long int off = ftell(file); if (off != -1) return off; /* error */ perror("ftell"); exit(8); } struct job { const void* src; size_t srcSize; void* dst; size_t dstSize; unsigned checksum; int compressionLevel; int done; }; static void compressFrame(void* opaque) { struct job* job = opaque; job->checksum = XXH64(job->src, job->srcSize, 0); size_t ret = ZSTD_compress(job->dst, job->dstSize, job->src, job->srcSize, job->compressionLevel); if (ZSTD_isError(ret)) { fprintf(stderr, "ZSTD_compress() error : %s \n", ZSTD_getErrorName(ret)); exit(20); } job->dstSize = ret; job->done = 1; } static void compressFile_orDie(const char* fname, const char* outName, int cLevel, unsigned frameSize, int nbThreads) { POOL_ctx* pool = POOL_create(nbThreads, nbThreads); if (pool == NULL) { fprintf(stderr, "POOL_create() error \n"); exit(9); } FILE* const fin = fopen_orDie(fname, "rb"); FILE* const fout = fopen_orDie(outName, "wb"); if (ZSTD_compressBound(frameSize) > 0xFFFFFFFFU) { fprintf(stderr, "Frame size too large \n"); exit(10); } unsigned dstSize = ZSTD_compressBound(frameSize); fseek_orDie(fin, 0, SEEK_END); long int length = ftell_orDie(fin); fseek_orDie(fin, 0, SEEK_SET); size_t numFrames = (length + frameSize - 1) / frameSize; struct job* jobs = malloc_orDie(sizeof(struct job) * numFrames); size_t i; for(i = 0; i < numFrames; i++) { void* in = malloc_orDie(frameSize); void* out = malloc_orDie(dstSize); size_t inSize = fread_orDie(in, frameSize, fin); jobs[i].src = in; jobs[i].srcSize = inSize; jobs[i].dst = out; jobs[i].dstSize = dstSize; jobs[i].compressionLevel = cLevel; jobs[i].done = 0; POOL_add(pool, compressFrame, &jobs[i]); } ZSTD_frameLog* fl = ZSTD_seekable_createFrameLog(1); if (fl == NULL) { fprintf(stderr, "ZSTD_seekable_createFrameLog() failed \n"); exit(11); } for (i = 0; i < numFrames; i++) { while (!jobs[i].done) SLEEP(5); /* wake up every 5 milliseconds to check */ fwrite_orDie(jobs[i].dst, jobs[i].dstSize, fout); free((void*)jobs[i].src); free(jobs[i].dst); size_t ret = ZSTD_seekable_logFrame(fl, jobs[i].dstSize, jobs[i].srcSize, jobs[i].checksum); if (ZSTD_isError(ret)) { fprintf(stderr, "ZSTD_seekable_logFrame() error : %s \n", ZSTD_getErrorName(ret)); } } { unsigned char seekTableBuff[1024]; ZSTD_outBuffer out = {seekTableBuff, 1024, 0}; while (ZSTD_seekable_writeSeekTable(fl, &out) != 0) { fwrite_orDie(seekTableBuff, out.pos, fout); out.pos = 0; } fwrite_orDie(seekTableBuff, out.pos, fout); } ZSTD_seekable_freeFrameLog(fl); free(jobs); fclose_orDie(fout); fclose_orDie(fin); } static const char* createOutFilename_orDie(const char* filename) { size_t const inL = strlen(filename); size_t const outL = inL + 5; void* outSpace = malloc_orDie(outL); memset(outSpace, 0, outL); strcat(outSpace, filename); strcat(outSpace, ".zst"); return (const char*)outSpace; } int main(int argc, const char** argv) { const char* const exeName = argv[0]; if (argc!=4) { printf("wrong arguments\n"); printf("usage:\n"); printf("%s FILE FRAME_SIZE NB_THREADS\n", exeName); return 1; } { const char* const inFileName = argv[1]; unsigned const frameSize = (unsigned)atoi(argv[2]); int const nbThreads = atoi(argv[3]); const char* const outFileName = createOutFilename_orDie(inFileName); compressFile_orDie(inFileName, outFileName, 5, frameSize, nbThreads); } return 0; }
b08c4859e3051cdd4d3e9095570f4c7788d64e56
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/gpu/drm/i915/i915_trace.h
3db4a681771320f1d42f8fb023c83d73e4426fb6
[ "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
11,304
h
i915_trace.h
#if !defined(_I915_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) #define _I915_TRACE_H_ #include <linux/stringify.h> #include <linux/types.h> #include <linux/tracepoint.h> #include <drm/drmP.h> #include "i915_drv.h" #include "intel_ringbuffer.h" #undef TRACE_SYSTEM #define TRACE_SYSTEM i915 #define TRACE_SYSTEM_STRING __stringify(TRACE_SYSTEM) #define TRACE_INCLUDE_FILE i915_trace /* object tracking */ TRACE_EVENT(i915_gem_object_create, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, size) ), TP_fast_assign( __entry->obj = obj; __entry->size = obj->base.size; ), TP_printk("obj=%p, size=%u", __entry->obj, __entry->size) ); TRACE_EVENT(i915_gem_object_bind, TP_PROTO(struct drm_i915_gem_object *obj, bool mappable), TP_ARGS(obj, mappable), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, offset) __field(u32, size) __field(bool, mappable) ), TP_fast_assign( __entry->obj = obj; __entry->offset = obj->gtt_space->start; __entry->size = obj->gtt_space->size; __entry->mappable = mappable; ), TP_printk("obj=%p, offset=%08x size=%x%s", __entry->obj, __entry->offset, __entry->size, __entry->mappable ? ", mappable" : "") ); TRACE_EVENT(i915_gem_object_unbind, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, offset) __field(u32, size) ), TP_fast_assign( __entry->obj = obj; __entry->offset = obj->gtt_space->start; __entry->size = obj->gtt_space->size; ), TP_printk("obj=%p, offset=%08x size=%x", __entry->obj, __entry->offset, __entry->size) ); TRACE_EVENT(i915_gem_object_change_domain, TP_PROTO(struct drm_i915_gem_object *obj, u32 old_read, u32 old_write), TP_ARGS(obj, old_read, old_write), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, read_domains) __field(u32, write_domain) ), TP_fast_assign( __entry->obj = obj; __entry->read_domains = obj->base.read_domains | (old_read << 16); __entry->write_domain = obj->base.write_domain | (old_write << 16); ), TP_printk("obj=%p, read=%02x=>%02x, write=%02x=>%02x", __entry->obj, __entry->read_domains >> 16, __entry->read_domains & 0xffff, __entry->write_domain >> 16, __entry->write_domain & 0xffff) ); TRACE_EVENT(i915_gem_object_pwrite, TP_PROTO(struct drm_i915_gem_object *obj, u32 offset, u32 len), TP_ARGS(obj, offset, len), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, offset) __field(u32, len) ), TP_fast_assign( __entry->obj = obj; __entry->offset = offset; __entry->len = len; ), TP_printk("obj=%p, offset=%u, len=%u", __entry->obj, __entry->offset, __entry->len) ); TRACE_EVENT(i915_gem_object_pread, TP_PROTO(struct drm_i915_gem_object *obj, u32 offset, u32 len), TP_ARGS(obj, offset, len), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, offset) __field(u32, len) ), TP_fast_assign( __entry->obj = obj; __entry->offset = offset; __entry->len = len; ), TP_printk("obj=%p, offset=%u, len=%u", __entry->obj, __entry->offset, __entry->len) ); TRACE_EVENT(i915_gem_object_fault, TP_PROTO(struct drm_i915_gem_object *obj, u32 index, bool gtt, bool write), TP_ARGS(obj, index, gtt, write), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) __field(u32, index) __field(bool, gtt) __field(bool, write) ), TP_fast_assign( __entry->obj = obj; __entry->index = index; __entry->gtt = gtt; __entry->write = write; ), TP_printk("obj=%p, %s index=%u %s", __entry->obj, __entry->gtt ? "GTT" : "CPU", __entry->index, __entry->write ? ", writable" : "") ); DECLARE_EVENT_CLASS(i915_gem_object, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj), TP_STRUCT__entry( __field(struct drm_i915_gem_object *, obj) ), TP_fast_assign( __entry->obj = obj; ), TP_printk("obj=%p", __entry->obj) ); DEFINE_EVENT(i915_gem_object, i915_gem_object_clflush, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj) ); DEFINE_EVENT(i915_gem_object, i915_gem_object_destroy, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj) ); TRACE_EVENT(i915_gem_evict, TP_PROTO(struct drm_device *dev, u32 size, u32 align, bool mappable), TP_ARGS(dev, size, align, mappable), TP_STRUCT__entry( __field(u32, dev) __field(u32, size) __field(u32, align) __field(bool, mappable) ), TP_fast_assign( __entry->dev = dev->primary->index; __entry->size = size; __entry->align = align; __entry->mappable = mappable; ), TP_printk("dev=%d, size=%d, align=%d %s", __entry->dev, __entry->size, __entry->align, __entry->mappable ? ", mappable" : "") ); TRACE_EVENT(i915_gem_evict_everything, TP_PROTO(struct drm_device *dev), TP_ARGS(dev), TP_STRUCT__entry( __field(u32, dev) ), TP_fast_assign( __entry->dev = dev->primary->index; ), TP_printk("dev=%d", __entry->dev) ); TRACE_EVENT(i915_gem_ring_dispatch, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno, u32 flags), TP_ARGS(ring, seqno, flags), TP_STRUCT__entry( __field(u32, dev) __field(u32, ring) __field(u32, seqno) __field(u32, flags) ), TP_fast_assign( __entry->dev = ring->dev->primary->index; __entry->ring = ring->id; __entry->seqno = seqno; __entry->flags = flags; i915_trace_irq_get(ring, seqno); ), TP_printk("dev=%u, ring=%u, seqno=%u, flags=%x", __entry->dev, __entry->ring, __entry->seqno, __entry->flags) ); TRACE_EVENT(i915_gem_ring_flush, TP_PROTO(struct intel_ring_buffer *ring, u32 invalidate, u32 flush), TP_ARGS(ring, invalidate, flush), TP_STRUCT__entry( __field(u32, dev) __field(u32, ring) __field(u32, invalidate) __field(u32, flush) ), TP_fast_assign( __entry->dev = ring->dev->primary->index; __entry->ring = ring->id; __entry->invalidate = invalidate; __entry->flush = flush; ), TP_printk("dev=%u, ring=%x, invalidate=%04x, flush=%04x", __entry->dev, __entry->ring, __entry->invalidate, __entry->flush) ); DECLARE_EVENT_CLASS(i915_gem_request, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno), TP_STRUCT__entry( __field(u32, dev) __field(u32, ring) __field(u32, seqno) ), TP_fast_assign( __entry->dev = ring->dev->primary->index; __entry->ring = ring->id; __entry->seqno = seqno; ), TP_printk("dev=%u, ring=%u, seqno=%u", __entry->dev, __entry->ring, __entry->seqno) ); DEFINE_EVENT(i915_gem_request, i915_gem_request_add, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno) ); DEFINE_EVENT(i915_gem_request, i915_gem_request_complete, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno) ); DEFINE_EVENT(i915_gem_request, i915_gem_request_retire, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno) ); TRACE_EVENT(i915_gem_request_wait_begin, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno), TP_STRUCT__entry( __field(u32, dev) __field(u32, ring) __field(u32, seqno) __field(bool, blocking) ), /* NB: the blocking information is racy since mutex_is_locked * doesn't check that the current thread holds the lock. The only * other option would be to pass the boolean information of whether * or not the class was blocking down through the stack which is * less desirable. */ TP_fast_assign( __entry->dev = ring->dev->primary->index; __entry->ring = ring->id; __entry->seqno = seqno; __entry->blocking = mutex_is_locked(&ring->dev->struct_mutex); ), TP_printk("dev=%u, ring=%u, seqno=%u, blocking=%s", __entry->dev, __entry->ring, __entry->seqno, __entry->blocking ? "yes (NB)" : "no") ); DEFINE_EVENT(i915_gem_request, i915_gem_request_wait_end, TP_PROTO(struct intel_ring_buffer *ring, u32 seqno), TP_ARGS(ring, seqno) ); DECLARE_EVENT_CLASS(i915_ring, TP_PROTO(struct intel_ring_buffer *ring), TP_ARGS(ring), TP_STRUCT__entry( __field(u32, dev) __field(u32, ring) ), TP_fast_assign( __entry->dev = ring->dev->primary->index; __entry->ring = ring->id; ), TP_printk("dev=%u, ring=%u", __entry->dev, __entry->ring) ); DEFINE_EVENT(i915_ring, i915_ring_wait_begin, TP_PROTO(struct intel_ring_buffer *ring), TP_ARGS(ring) ); DEFINE_EVENT(i915_ring, i915_ring_wait_end, TP_PROTO(struct intel_ring_buffer *ring), TP_ARGS(ring) ); TRACE_EVENT(i915_flip_request, TP_PROTO(int plane, struct drm_i915_gem_object *obj), TP_ARGS(plane, obj), TP_STRUCT__entry( __field(int, plane) __field(struct drm_i915_gem_object *, obj) ), TP_fast_assign( __entry->plane = plane; __entry->obj = obj; ), TP_printk("plane=%d, obj=%p", __entry->plane, __entry->obj) ); TRACE_EVENT(i915_flip_complete, TP_PROTO(int plane, struct drm_i915_gem_object *obj), TP_ARGS(plane, obj), TP_STRUCT__entry( __field(int, plane) __field(struct drm_i915_gem_object *, obj) ), TP_fast_assign( __entry->plane = plane; __entry->obj = obj; ), TP_printk("plane=%d, obj=%p", __entry->plane, __entry->obj) ); TRACE_EVENT(i915_reg_rw, TP_PROTO(bool write, u32 reg, u64 val, int len), TP_ARGS(write, reg, val, len), TP_STRUCT__entry( __field(u64, val) __field(u32, reg) __field(u16, write) __field(u16, len) ), TP_fast_assign( __entry->val = (u64)val; __entry->reg = reg; __entry->write = write; __entry->len = len; ), TP_printk("%s reg=0x%x, len=%d, val=(0x%x, 0x%x)", __entry->write ? "write" : "read", __entry->reg, __entry->len, (u32)(__entry->val & 0xffffffff), (u32)(__entry->val >> 32)) ); TRACE_EVENT(intel_gpu_freq_change, TP_PROTO(u32 freq), TP_ARGS(freq), TP_STRUCT__entry( __field(u32, freq) ), TP_fast_assign( __entry->freq = freq; ), TP_printk("new_freq=%u", __entry->freq) ); #endif /* _I915_TRACE_H_ */ /* This part must be outside protection */ #undef TRACE_INCLUDE_PATH #define TRACE_INCLUDE_PATH . #include <trace/define_trace.h>
040e94a52ae0eec4dc2a2995f0bcef975428323c
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
/AKWF-c/AKWF_violin/AKWF_violin_0006.h
c018cd755323d03fee67fa2159c158b9de68978a
[ "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,686
h
AKWF_violin_0006.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_violin_0006 256 samples +-----------------------------------------------------------------------------------------------------------------+ | ** ** | | ** ** ********* | | ** **** ** ** | | * ** ** **** | | * ** **** *** | | * ** *** ** | |* ** ** ** | |* ** ** ** | | *** ***** ** ** | | **** ** * ** *| | ** * ** **** ***| | ** ** ** ** ******* | | ** ** ** ***** | | ** * ** **** | | *** ** ******** | +-----------------------------------------------------------------------------------------------------------------+ */ const uint16_t AKWF_violin_0006 [] = { 33197, 35217, 37954, 40839, 43711, 46561, 49314, 51954, 54473, 56908, 59232, 61211, 62819, 64065, 64938, 65404, 65535, 65482, 65131, 64406, 63335, 62157, 60989, 59603, 58285, 57047, 55876, 54959, 54247, 53698, 53164, 52487, 51540, 50501, 49375, 47942, 46201, 44297, 42333, 40345, 38545, 37080, 35879, 34761, 33632, 32562, 31570, 30635, 29907, 29470, 29359, 29514, 29812, 30246, 30890, 31723, 32488, 33036, 33292, 33277, 33061, 32679, 32033, 30992, 29579, 27907, 26190, 24554, 22979, 21464, 19970, 18481, 17051, 15642, 14322, 13194, 12228, 11412, 10631, 9855, 9121, 8542, 8040, 7673, 7725, 7830, 7909, 7971, 7784, 7585, 7277, 6978, 7104, 7384, 7720, 8160, 8734, 9521, 10468, 11551, 12833, 14519, 16495, 18636, 20945, 23403, 25820, 28087, 30264, 32209, 33944, 35554, 37117, 38695, 40193, 41509, 42663, 43748, 44642, 45321, 45881, 46234, 46598, 47007, 47416, 48091, 49011, 50150, 51464, 52849, 54207, 55464, 56524, 57309, 57729, 57906, 57964, 57783, 57662, 57575, 57419, 57402, 57474, 57626, 57813, 57977, 58058, 58051, 57905, 57510, 57031, 56427, 55648, 54798, 53887, 52920, 51967, 51164, 50525, 49955, 49401, 48883, 48326, 47653, 46827, 45829, 44627, 43283, 41829, 40258, 38685, 37117, 35561, 34137, 32953, 31901, 30784, 29516, 28202, 26894, 25596, 24334, 22950, 21676, 20634, 19748, 18912, 18136, 17322, 16380, 15375, 14361, 13263, 12065, 11000, 10209, 9661, 9308, 9482, 9779, 10208, 10818, 11315, 11573, 11747, 11873, 11748, 11602, 11824, 12426, 12962, 13751, 14666, 15356, 15778, 16230, 16683, 16933, 17042, 17257, 17246, 16850, 16717, 16968, 17795, 18961, 20157, 21443, 22866, 24251, 25352, 26126, 26492, 26327, 25625, 24573, 23366, 22361, 21927, 21676, 21673, 21940, 22321, 22613, 22838, 22901, 22732, 22804, 23105, 23491, 23885, 24778, 25881, 27244, 28954, 31271, };
e863d2db45de918159f67b1beb755f5d91859977
1efd2de8bf77ec00eb2fcaf5749278495946d920
/src/include/daos/drpc_modules.h
69aaf568673c273e0b14bbc5bb738d868c4e510f
[ "BSD-2-Clause", "BSD-2-Clause-Patent" ]
permissive
daos-stack/daos
6f55bf3061fd830d5b8d28506e1295e2d3a27c38
ed5eed5df43a68571afe123132a743824c02637a
refs/heads/master
2023-08-31T21:43:37.606145
2023-08-31T16:38:00
2023-08-31T16:38:00
69,390,670
631
300
NOASSERTION
2023-09-14T18:55:15
2016-09-27T19:21:29
C
UTF-8
C
false
false
2,728
h
drpc_modules.h
/* * (C) Copyright 2019-2022 Intel Corporation. * * SPDX-License-Identifier: BSD-2-Clause-Patent */ #ifndef __DAOS_DRPC_MODULES_H__ #define __DAOS_DRPC_MODULES_H__ /** * DAOS dRPC Modules * * dRPC modules are used to multiplex communications over the Unix Domain Socket * to appropriate handlers. They are populated in the Drpc__Call structure. * * dRPC module IDs must be unique. This is a list of all DAOS dRPC modules. */ enum drpc_module { DRPC_MODULE_TEST = 0, /* Reserved for testing */ DRPC_MODULE_SEC_AGENT = 1, /* daos_agent security */ DRPC_MODULE_MGMT = 2, /* daos_server mgmt */ DRPC_MODULE_SRV = 3, /* daos_server */ DRPC_MODULE_SEC = 4, /* daos_server security */ NUM_DRPC_MODULES /* Must be last */ }; enum drpc_sec_agent_method { DRPC_METHOD_SEC_AGENT_REQUEST_CREDS = 101, NUM_DRPC_SEC_AGENT_METHODS /* Must be last */ }; enum drpc_mgmt_method { DRPC_METHOD_MGMT_KILL_RANK = 201, DRPC_METHOD_MGMT_SET_RANK = 202, DRPC_METHOD_MGMT_GET_ATTACH_INFO = 206, DRPC_METHOD_MGMT_POOL_CREATE = 207, DRPC_METHOD_MGMT_POOL_DESTROY = 208, DRPC_METHOD_MGMT_SET_UP = 209, DRPC_METHOD_MGMT_BIO_HEALTH_QUERY = 210, DRPC_METHOD_MGMT_SMD_LIST_DEVS = 211, DRPC_METHOD_MGMT_SMD_LIST_POOLS = 212, DRPC_METHOD_MGMT_POOL_GET_ACL = 213, DRPC_METHOD_MGMT_POOL_OVERWRITE_ACL = 215, DRPC_METHOD_MGMT_POOL_UPDATE_ACL = 216, DRPC_METHOD_MGMT_POOL_DELETE_ACL = 217, DRPC_METHOD_MGMT_PREP_SHUTDOWN = 218, DRPC_METHOD_MGMT_DEV_SET_FAULTY = 220, DRPC_METHOD_MGMT_DEV_REPLACE = 221, DRPC_METHOD_MGMT_LIST_CONTAINERS = 222, DRPC_METHOD_MGMT_POOL_QUERY = 223, DRPC_METHOD_MGMT_POOL_SET_PROP = 224, DRPC_METHOD_MGMT_PING_RANK = 225, DRPC_METHOD_MGMT_REINTEGRATE = 226, DRPC_METHOD_MGMT_CONT_SET_OWNER = 227, DRPC_METHOD_MGMT_EXCLUDE = 228, DRPC_METHOD_MGMT_EXTEND = 229, DRPC_METHOD_MGMT_POOL_EVICT = 230, DRPC_METHOD_MGMT_DRAIN = 231, DRPC_METHOD_MGMT_GROUP_UPDATE = 232, DRPC_METHOD_MGMT_NOTIFY_EXIT = 233, DRPC_METHOD_MGMT_NOTIFY_POOL_CONNECT = 235, DRPC_METHOD_MGMT_NOTIFY_POOL_DISCONNECT = 236, DRPC_METHOD_MGMT_POOL_GET_PROP = 237, DRPC_METHOD_MGMT_SET_LOG_MASKS = 238, DRPC_METHOD_MGMT_POOL_UPGRADE = 239, DRPC_METHOD_MGMT_POOL_QUERY_TARGETS = 240, DRPC_METHOD_MGMT_LED_MANAGE = 241, NUM_DRPC_MGMT_METHODS /* Must be last */ }; enum drpc_srv_method { DRPC_METHOD_SRV_NOTIFY_READY = 301, DRPC_METHOD_SRV_BIO_ERR = 302, DRPC_METHOD_SRV_GET_POOL_SVC = 303, DRPC_METHOD_SRV_CLUSTER_EVENT = 304, DRPC_METHOD_SRV_POOL_FIND_BYLABEL = 305, NUM_DRPC_SRV_METHODS /* Must be last */ }; enum drpc_sec_method { DRPC_METHOD_SEC_VALIDATE_CREDS = 401, NUM_DRPC_SEC_METHODS /* Must be last */ }; #endif /* __DAOS_DRPC_MODULES_H__ */
3ea8359824e7b9778deb9917c1e7988cec5ebe33
b61818b74d0f10c0580ddec16d085aa5e9171fb2
/src/pipe/modules/o-pfm/main.c
f7c5d5355e1fafd6eec0272891c530f8b4ba1224
[ "LGPL-2.0-only", "BSD-2-Clause" ]
permissive
hanatos/vkdt
8d52444b40d3e0478bbaf0100b66e21f8bf05561
04ef97d5a7e091661b66dbee1fb71994bfbb6ffb
refs/heads/master
2023-08-03T16:12:49.335070
2023-08-01T13:25:47
2023-08-01T13:26:13
196,389,968
249
28
BSD-2-Clause
2023-09-08T19:09:54
2019-07-11T12:27:14
C
UTF-8
C
false
false
1,146
c
main.c
#include "modules/api.h" #include <stdio.h> #include <string.h> // called after pipeline finished up to here. // our input buffer will come in memory mapped. void write_sink( dt_module_t *module, void *buf) { const char *basename = dt_module_param_string(module, 0); fprintf(stderr, "[o-pfm] writing '%s'\n", basename); float *pf = buf; const int width = module->connector[0].roi.wd; const int height = module->connector[0].roi.ht; char filename[512]; snprintf(filename, sizeof(filename), "%s.pfm", basename); FILE* f = fopen(filename, "wb"); if(f) { // align pfm header to sse, assuming the file will // be mmapped to page boundaries. char header[1024]; snprintf(header, 1024, "PF\n%d %d\n-1.0", width, height); size_t len = strlen(header); fprintf(f, "PF\n%d %d\n-1.0", width, height); ssize_t off = 0; while((len + 1 + off) & 0xf) off++; while(off-- > 0) fprintf(f, "0"); fprintf(f, "\n"); for(size_t k=0;k<width*(uint64_t)height;k++) { float p32[3] = {pf[4*k+0], pf[4*k+1], pf[4*k+2]}; fwrite(p32, sizeof(float), 3ul, f); } fclose(f); } }
b164ea8df14e6adc64e4972f2ca8a629fa9e7326
35c04ea32351dc95bc18d46e5c70dda9c1e08668
/Examples/MCUXpresso/LPC55S69-EVK/LPC55S69_McuLib_Blinky/source/platform.h
3df3fb6820c50cb9630efebfe0ddc88af062d2bb
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
ErichStyger/mcuoneclipse
0f8e7a2056a26ed79d9d4a0afd64777ff0b2b2fe
04ad311b11860ae5f8285316010961a87fa06d0c
refs/heads/master
2023-08-28T22:54:08.501719
2023-08-25T15:11:44
2023-08-25T15:11:44
7,446,094
620
1,191
NOASSERTION
2020-10-16T03:13:28
2013-01-04T19:38:12
Batchfile
UTF-8
C
false
false
618
h
platform.h
/* * Copyright (c) 2021, Erich Styger * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef PLATFORM_H_ #define PLATFORM_H_ #ifndef PL_CONFIG_USE_LORA_SHIELD #error "PL_CONFIG_USE_LORA_SHIELD needs be set in IncludeMcuLibConfig.h!" #endif #define PL_CONFIG_USE_SHELL (0) #define PL_CONFIG_USE_USB_CDC (0) #define PL_CONFIG_USE_I2C (0) /* if I2C peripheral is used */ #define PL_CONFIG_USE_HW_I2C (USE_HW_I2C && PL_CONFIG_USE_I2C) /* USE_HW_I2C defined in IncludeMcuLibConfig.h */ #define PL_CONFIG_USE_OLED (1 && PL_CONFIG_USE_I2C) void PL_Init(void); #endif /* PLATFORM_H_ */
a81e8f4bbd0835fe4b889df36db39c9d802e086b
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/xnnpack/src/src/f16-f32-vcvt/gen/f16-f32-vcvt-neon-int16-x16.c
19e730dbea5524e5c06344b9b056a52adcdfbfc7
[ "BSD-3-Clause", "LicenseRef-scancode-generic-cla", "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
7,452
c
f16-f32-vcvt-neon-int16-x16.c
// Auto-generated file. Do not edit! // Template: src/f16-f32-vcvt/neon-int16.c.in // Generator: tools/xngen // // Copyright 2021 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/vcvt.h> void xnn_f16_f32_vcvt_ukernel__neon_int16_x16( size_t batch, const void* input, float* output, const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(batch != 0); assert(batch % sizeof(uint16_t) == 0); assert(input != NULL); assert(output != NULL); const uint16x8_t vsign_mask = vmovq_n_u16(0x8000); const uint16x8_t vexp_offset = vmovq_n_u16(0x7000); const float32x4_t vexp_scale = vld1q_dup_f32(&params->neon.exp_scale); const uint32x4_t vmagic_bias = vmovq_n_u32(0x3F000000); const uint16x8_t vdenorm_cutoff = vmovq_n_u16(0x0400); const uint16_t* i = (const uint16_t*) input; for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) { const uint16x8_t vh0 = vld1q_u16(i); i += 8; const uint16x8_t vh1 = vld1q_u16(i); i += 8; const uint16x8_t vsign0 = vandq_u16(vh0, vsign_mask); const uint16x8_t vsign1 = vandq_u16(vh1, vsign_mask); const uint16x8_t vnonsign0 = veorq_u16(vh0, vsign0); const uint16x8_t vnonsign1 = veorq_u16(vh1, vsign1); const uint16x8x2_t vprenorm0 = vzipq_u16(vshlq_n_u16(vnonsign0, 13), vsraq_n_u16(vexp_offset, vnonsign0, 3)); const uint16x8x2_t vprenorm1 = vzipq_u16(vshlq_n_u16(vnonsign1, 13), vsraq_n_u16(vexp_offset, vnonsign1, 3)); const float32x4_t vnorm0 = vmulq_f32(vreinterpretq_f32_u16(vprenorm0.val[0]), vexp_scale); const float32x4_t vnorm1 = vmulq_f32(vreinterpretq_f32_u16(vprenorm0.val[1]), vexp_scale); const float32x4_t vnorm2 = vmulq_f32(vreinterpretq_f32_u16(vprenorm1.val[0]), vexp_scale); const float32x4_t vnorm3 = vmulq_f32(vreinterpretq_f32_u16(vprenorm1.val[1]), vexp_scale); const float32x4_t vdenorm0 = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_low_u16(vnonsign0))), vreinterpretq_f32_u32(vmagic_bias)); const float32x4_t vdenorm1 = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_high_u16(vnonsign0))), vreinterpretq_f32_u32(vmagic_bias)); const float32x4_t vdenorm2 = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_low_u16(vnonsign1))), vreinterpretq_f32_u32(vmagic_bias)); const float32x4_t vdenorm3 = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_high_u16(vnonsign1))), vreinterpretq_f32_u32(vmagic_bias)); const uint16x8_t vmask0 = vcgtq_u16(vnonsign0, vdenorm_cutoff); const uint16x8_t vmask1 = vcgtq_u16(vnonsign1, vdenorm_cutoff); const uint32x4_t vxmask0 = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_low_u16(vmask0)))); const uint32x4_t vf0 = vorrq_u32(vshll_n_u16(vget_low_u16(vsign0), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask0, vnorm0, vdenorm0))); const uint32x4_t vxmask2 = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_low_u16(vmask1)))); const uint32x4_t vf2 = vorrq_u32(vshll_n_u16(vget_low_u16(vsign1), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask2, vnorm2, vdenorm2))); const uint32x4_t vxmask1 = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_high_u16(vmask0)))); const uint32x4_t vf1 = vorrq_u32(vshll_n_u16(vget_high_u16(vsign0), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask1, vnorm1, vdenorm1))); const uint32x4_t vxmask3 = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_high_u16(vmask1)))); const uint32x4_t vf3 = vorrq_u32(vshll_n_u16(vget_high_u16(vsign1), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask3, vnorm3, vdenorm3))); vst1q_f32(output, vreinterpretq_f32_u32(vf0)); output += 4; vst1q_f32(output, vreinterpretq_f32_u32(vf1)); output += 4; vst1q_f32(output, vreinterpretq_f32_u32(vf2)); output += 4; vst1q_f32(output, vreinterpretq_f32_u32(vf3)); output += 4; } for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) { const uint16x8_t vh = vld1q_u16(i); i += 8; const uint16x8_t vsign = vandq_u16(vh, vsign_mask); const uint16x8_t vnonsign = veorq_u16(vh, vsign); const uint16x8x2_t vprenorm = vzipq_u16(vshlq_n_u16(vnonsign, 13), vsraq_n_u16(vexp_offset, vnonsign, 3)); const float32x4_t vnorm_lo = vmulq_f32(vreinterpretq_f32_u16(vprenorm.val[0]), vexp_scale); const float32x4_t vnorm_hi = vmulq_f32(vreinterpretq_f32_u16(vprenorm.val[1]), vexp_scale); const float32x4_t vdenorm_lo = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_low_u16(vnonsign))), vreinterpretq_f32_u32(vmagic_bias)); const float32x4_t vdenorm_hi = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_high_u16(vnonsign))), vreinterpretq_f32_u32(vmagic_bias)); const uint16x8_t vmask = vcgtq_u16(vnonsign, vdenorm_cutoff); const uint32x4_t vxmask_lo = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_low_u16(vmask)))); const uint32x4_t vf_lo = vorrq_u32(vshll_n_u16(vget_low_u16(vsign), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask_lo, vnorm_lo, vdenorm_lo))); const uint32x4_t vxmask_hi = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_high_u16(vmask)))); const uint32x4_t vf_hi = vorrq_u32(vshll_n_u16(vget_high_u16(vsign), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask_hi, vnorm_hi, vdenorm_hi))); vst1q_f32(output, vreinterpretq_f32_u32(vf_lo)); output += 4; vst1q_f32(output, vreinterpretq_f32_u32(vf_hi)); output += 4; } if XNN_UNPREDICTABLE(batch != 0) { const uint16x8_t vh = vld1q_u16(i); i += 8; const uint16x8_t vsign = vandq_u16(vh, vsign_mask); const uint16x8_t vnonsign = veorq_u16(vh, vsign); const uint16x8x2_t vprenorm = vzipq_u16(vshlq_n_u16(vnonsign, 13), vsraq_n_u16(vexp_offset, vnonsign, 3)); const float32x4_t vnorm_lo = vmulq_f32(vreinterpretq_f32_u16(vprenorm.val[0]), vexp_scale); const float32x4_t vnorm_hi = vmulq_f32(vreinterpretq_f32_u16(vprenorm.val[1]), vexp_scale); const float32x4_t vdenorm_lo = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_low_u16(vnonsign))), vreinterpretq_f32_u32(vmagic_bias)); const float32x4_t vdenorm_hi = vsubq_f32(vreinterpretq_f32_u32(vaddw_u16(vmagic_bias, vget_high_u16(vnonsign))), vreinterpretq_f32_u32(vmagic_bias)); const uint16x8_t vmask = vcgtq_u16(vnonsign, vdenorm_cutoff); const uint32x4_t vxmask_lo = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_low_u16(vmask)))); uint32x4_t vf = vorrq_u32(vshll_n_u16(vget_low_u16(vsign), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask_lo, vnorm_lo, vdenorm_lo))); if (batch & (4 * sizeof(uint16_t))) { vst1q_f32(output, vreinterpretq_f32_u32(vf)); output += 4; const uint32x4_t vxmask_hi = vreinterpretq_u32_s32(vmovl_s16(vreinterpret_s16_u16(vget_high_u16(vmask)))); vf = vorrq_u32(vshll_n_u16(vget_high_u16(vsign), 16), vreinterpretq_u32_f32(vbslq_f32(vxmask_hi, vnorm_hi, vdenorm_hi))); } uint32x2_t vf_lo = vget_low_u32(vf); if (batch & (2 * sizeof(uint16_t))) { vst1_f32(output, vreinterpret_f32_u32(vf_lo)); output += 2; vf_lo = vget_high_u32(vf); } if (batch & (1 * sizeof(uint16_t))) { vst1_lane_f32(output, vreinterpret_f32_u32(vf_lo), 0); } } }
a914076271de065c8f3f91499e8f3c830eae3c63
45874c847c5a2fc4e89e05a7fc8ad9b63d8c4860
/libclc/generic/include/spirv/atomic/atomic_cmpxchg.h
5f7683ec4e55fbe2a0e541bcd2559b4df17ea374
[ "NCSA", "Apache-2.0", "LLVM-exception", "MIT", "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
intel/llvm
2f023cefec793a248d8a237267410f5e288116c5
a3d10cf63ddbdcc23712c45afd1b6b0a2ff5b190
refs/heads/sycl
2023-08-24T18:53:49.800759
2023-08-24T17:38:35
2023-08-24T17:38:35
166,008,577
1,050
735
NOASSERTION
2023-09-14T20:35:07
2019-01-16T09:05:33
null
UTF-8
C
false
false
2,329
h
atomic_cmpxchg.h
//===----------------------------------------------------------------------===// // // Part of the LLVM Project, 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 // //===----------------------------------------------------------------------===// // TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling. _CLC_DECL int _Z29__spirv_AtomicCompareExchangePU3AS3iN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_ii( volatile local int *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, int, int); _CLC_DECL int _Z29__spirv_AtomicCompareExchangePU3AS1iN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_ii( volatile global int *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, int, int); _CLC_DECL uint _Z29__spirv_AtomicCompareExchangePU3AS3jN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_jj( volatile local uint *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, uint, uint); _CLC_DECL uint _Z29__spirv_AtomicCompareExchangePU3AS1jN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_jj( volatile global uint *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, uint, uint); #ifdef cl_khr_int64_base_atomics _CLC_DECL long _Z29__spirv_AtomicCompareExchangePU3AS3lN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_ll( volatile local long *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, long, long); _CLC_DECL long _Z29__spirv_AtomicCompareExchangePU3AS1lN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_ll( volatile global long *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, long, long); _CLC_DECL unsigned long _Z29__spirv_AtomicCompareExchangePU3AS3mN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_mm( volatile local unsigned long *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, unsigned long, unsigned long); _CLC_DECL unsigned long _Z29__spirv_AtomicCompareExchangePU3AS1mN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagES5_mm( volatile global unsigned long *, enum Scope, enum MemorySemanticsMask, enum MemorySemanticsMask, unsigned long, unsigned long); #endif
803a069fb412e151751972cc736c58ba957dfba2
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/arm/mach-imx/cpu-imx31.c
fde1860a25216ed9763fb7ba8256ed0b16757e70
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "Linux-syscall-note", "GPL-2.0-only", "GPL-1.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
1,832
c
cpu-imx31.c
/* * MX31 CPU type detection * * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> * * 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. */ #include <linux/module.h> #include <linux/io.h> #include "common.h" #include "hardware.h" #include "iim.h" static int mx31_cpu_rev = -1; static struct { u8 srev; const char *name; unsigned int rev; } mx31_cpu_type[] = { { .srev = 0x00, .name = "i.MX31(L)", .rev = IMX_CHIP_REVISION_1_0 }, { .srev = 0x10, .name = "i.MX31", .rev = IMX_CHIP_REVISION_1_1 }, { .srev = 0x11, .name = "i.MX31L", .rev = IMX_CHIP_REVISION_1_1 }, { .srev = 0x12, .name = "i.MX31", .rev = IMX_CHIP_REVISION_1_1 }, { .srev = 0x13, .name = "i.MX31L", .rev = IMX_CHIP_REVISION_1_1 }, { .srev = 0x14, .name = "i.MX31", .rev = IMX_CHIP_REVISION_1_2 }, { .srev = 0x15, .name = "i.MX31L", .rev = IMX_CHIP_REVISION_1_2 }, { .srev = 0x28, .name = "i.MX31", .rev = IMX_CHIP_REVISION_2_0 }, { .srev = 0x29, .name = "i.MX31L", .rev = IMX_CHIP_REVISION_2_0 }, }; static int mx31_read_cpu_rev(void) { u32 i, srev; /* read SREV register from IIM module */ srev = __raw_readl(MX31_IO_ADDRESS(MX31_IIM_BASE_ADDR + MXC_IIMSREV)); srev &= 0xff; for (i = 0; i < ARRAY_SIZE(mx31_cpu_type); i++) if (srev == mx31_cpu_type[i].srev) { imx_print_silicon_rev(mx31_cpu_type[i].name, mx31_cpu_type[i].rev); return mx31_cpu_type[i].rev; } imx_print_silicon_rev("i.MX31", IMX_CHIP_REVISION_UNKNOWN); return IMX_CHIP_REVISION_UNKNOWN; } int mx31_revision(void) { if (mx31_cpu_rev == -1) mx31_cpu_rev = mx31_read_cpu_rev(); return mx31_cpu_rev; } EXPORT_SYMBOL(mx31_revision);
6207c091d5ec55afe34b124705da597265fdcf08
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
/AKWF-c/AKWF_0020/AKWF_1941.h
d36327a7c8402e50e2d29de3c5201c169805fee5
[ "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,672
h
AKWF_1941.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_1941 256 samples +-----------------------------------------------------------------------------------------------------------------+ | *** *** | | ** ** *** | | ** ** ** *** | | ** ** ***** ** ** | | * ** *** *** ** ** | |** *** *** ** ** * | |* ****** ** ** ** | | ** ** ** | | * ** ** ******* *| | * * ** *** ** **| | ** * *** *** ** * | | ** ** ** *** ** ** | | *** *** ******* ** ** | | *** ** ** | | *** ** | +-----------------------------------------------------------------------------------------------------------------+ */ const uint16_t AKWF_1941 [] = { 33038, 35437, 38161, 40743, 43345, 45811, 48245, 50518, 52720, 54740, 56652, 58363, 59939, 61301, 62505, 63490, 64299, 64892, 65301, 65502, 65520, 65343, 64990, 64463, 63775, 62939, 61964, 60869, 59663, 58369, 56994, 55566, 54092, 52599, 51092, 49601, 48131, 46708, 45337, 44041, 42825, 41708, 40693, 39795, 39015, 38364, 37843, 37455, 37200, 37076, 37082, 37213, 37460, 37817, 38276, 38826, 39453, 40148, 40896, 41682, 42492, 43312, 44124, 44917, 45672, 46376, 47016, 47577, 48048, 48415, 48671, 48806, 48811, 48681, 48412, 48001, 47446, 46747, 45907, 44929, 43820, 42588, 41238, 39782, 38231, 36596, 34893, 33137, 31342, 29523, 27697, 25879, 24089, 22342, 20656, 19044, 17524, 16108, 14813, 13651, 12631, 11766, 11065, 10534, 10179, 10007, 10018, 10213, 10591, 11153, 11891, 12802, 13876, 15109, 16487, 17999, 19633, 21377, 23214, 25131, 27109, 29135, 31190, 33257, 35319, 37361, 39362, 41310, 43189, 44981, 46672, 48252, 49706, 51022, 52192, 53207, 54059, 54743, 55253, 55587, 55743, 55721, 55523, 55150, 54608, 53901, 53037, 52023, 50867, 49582, 48176, 46662, 45053, 43361, 41600, 39785, 37929, 36046, 34152, 32260, 30383, 28536, 26733, 24986, 23306, 21706, 20195, 18783, 17479, 16291, 15226, 14288, 13482, 12810, 12275, 11877, 11617, 11493, 11500, 11636, 11894, 12269, 12754, 13341, 14021, 14783, 15619, 16514, 17460, 18444, 19453, 20476, 21500, 22509, 23496, 24446, 25348, 26189, 26960, 27649, 28250, 28752, 29146, 29429, 29593, 29635, 29549, 29339, 29000, 28534, 27944, 27230, 26401, 25460, 24416, 23275, 22051, 20748, 19386, 17968, 16517, 15038, 13552, 12069, 10611, 9183, 7812, 6502, 5281, 4149, 3132, 2233, 1475, 859, 406, 118, 3, 74, 323, 771, 1399, 2235, 3240, 4457, 5829, 7408, 9119, 11027, 13041, 15235, 17498, 19926, 22382, 24981, 27549, 30288, };
c0611886ce03a5a276978d56634e1c66ff3bd468
f7f043523dcacb348f7a387430ae5b7b2932b56a
/vendor/github.com/coreswitch/openconfigd/cli/lib/sh/strchrnul.c
00cb88c4e5e90f0751d9069669ba10e6b942e9f9
[ "Apache-2.0", "FSFAP", "GPL-3.0-or-later", "GPL-3.0-only", "LGPL-2.0-or-later" ]
permissive
coreswitch/zebra
2f3dcbb0f1aa0350fe63d664e5533d6895030e85
1931dde592c81398707a07d90d00f90321dc9b46
refs/heads/master
2021-12-15T02:26:03.510038
2019-05-19T12:00:34
2019-05-19T12:00:34
107,520,729
105
22
Apache-2.0
2019-05-17T01:23:34
2017-10-19T08:42:40
Go
UTF-8
C
false
false
1,057
c
strchrnul.c
/* Searching in a string. Copyright (C) 2012 Free Software Foundation, Inc. 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 3 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, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> /* Specification. */ #include <string.h> /* Find the first occurrence of C in S or the final NUL byte. */ char * strchrnul (s, c_in) const char *s; int c_in; { char c; register char *s1; for (c = c_in, s1 = (char *)s; s1 && *s1 && *s1 != c; s1++) ; return (s1); }
40a7396950fcc966be4e68bfd872840d4c3cbf3e
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/x11/xf86-input-keyboard/patches/patch-src_bsd__KbdMap.c
3305fb26db582e035242a595aac67af9ed94e679
[]
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
2,015
c
patch-src_bsd__KbdMap.c
$NetBSD: patch-src_bsd__KbdMap.c,v 1.2 2020/09/19 13:52:14 taca Exp $ PR191459: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191459 Fix a segmentation fault due to the use of Unicode codepoints in vt(4) which is the default console driver from FreeBSD 11. xsrc/54784: Cannot input some keys in JP keyboard on Xorg server when specify wskbd Protocol. --- src/bsd_KbdMap.c.orig 2015-08-07 03:16:08.000000000 +0000 +++ src/bsd_KbdMap.c @@ -28,6 +28,7 @@ #include "bsd_kbd.h" #if (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)) && defined(GIO_KEYMAP) +#if !(defined(__FreeBSD__) && __FreeBSD__ >= 11) #define KD_GET_ENTRY(i,n) \ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]] @@ -188,6 +189,7 @@ static KeySym eascii_to_x[512] = { NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol, NoSymbol }; +#endif /* !(defined(__FreeBSD__) && __FreeBSD__ >= 11) */ #ifdef SYSCONS_SUPPORT static @@ -581,20 +583,20 @@ static CARD8 wsXtMap[] = { /* 109 */ KEY_NOTUSED, /* 110 */ KEY_NOTUSED, /* 111 */ KEY_NOTUSED, - /* 112 */ KEY_NOTUSED, + /* 112 */ KEY_HKTG, /* 113 */ KEY_NOTUSED, /* 114 */ KEY_NOTUSED, - /* 115 */ KEY_NOTUSED, + /* 115 */ KEY_BSlash2, /* 116 */ KEY_NOTUSED, /* 117 */ KEY_NOTUSED, /* 118 */ KEY_NOTUSED, /* 119 */ KEY_NOTUSED, /* 120 */ KEY_NOTUSED, - /* 121 */ KEY_NOTUSED, + /* 121 */ KEY_XFER, /* 122 */ KEY_NOTUSED, - /* 123 */ KEY_NOTUSED, + /* 123 */ KEY_NFER, /* 124 */ KEY_NOTUSED, - /* 125 */ KEY_NOTUSED, + /* 125 */ KEY_Yen, /* 126 */ KEY_NOTUSED, /* 127 */ KEY_Pause, /* 128 */ KEY_NOTUSED, @@ -1261,6 +1263,7 @@ KbdGetMapping (InputInfoPtr pInfo, KeySy KeySym *k; int i; +#if !(defined(__FreeBSD__) && __FreeBSD__ >= 11) #ifndef __bsdi__ switch (pKbd->consType) { @@ -1294,6 +1297,7 @@ KbdGetMapping (InputInfoPtr pInfo, KeySy } #endif /* !bsdi */ +#endif /* !(defined(__FreeBSD__) && __FreeBSD__ >= 11) */ /* * compute the modifier map
f9d6954ec5ed8e228abc558d271b681793b54354
fbef550c1f0206aac0582a58f7e3db945f442a9a
/Pods/MIKMIDI/Source/MIKMIDIPrivate.h
afdc52f96ac2f469a501b610acb2d9f589263e77
[ "MIT" ]
permissive
Hammerspoon/hammerspoon
0f03b4dd2ef3b44ea4c0a1cd0b94fcb513b5f2b7
0ccc9d07641a660140d1d2f05b76f682b501a0e8
refs/heads/master
2023-08-19T01:26:41.898873
2023-06-20T22:52:50
2023-06-20T22:52:50
24,956,772
11,379
676
MIT
2023-06-09T02:51:33
2014-10-08T19:24:44
Objective-C
UTF-8
C
false
false
670
h
MIKMIDIPrivate.h
// // MIKMIDIPrivate.h // MIKMIDI // // Created by Andrew Madsen on 10/29/13. // Copyright (c) 2013 Mixed In Key. All rights reserved. // #if OS_OBJECT_HAVE_OBJC_SUPPORT && __has_feature(objc_arc) #define MIKMIDI_GCD_RELEASE(x) #define MIKMIDI_GCD_RETAIN(x) #else #define MIKMIDI_GCD_RELEASE(x) if (x) { dispatch_release(x); } #define MIKMIDI_GCD_RETAIN(x) if (x) { dispatch_retain(x); } #endif #define SHOW_STANDARD_DEPRECATION_WARNING static dispatch_once_t onceToken; \ dispatch_once(&onceToken, ^{ \ NSLog(@"-[%@ %@] is deprecated and will be removed in a future release of MIKMIDI.", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); \ }); \
81c50d5ce8a1a55912c946a99d4a5cc44fee1990
e73547787354afd9b717ea57fe8dd0695d161821
/include/mapfs/pra_05_hit.h
6070b2e46397cac320891f77263cf9229682e61a
[]
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
670
h
pra_05_hit.h
#define COLLIDER_Root 0xD #define COLLIDER_g253 0xC #define COLLIDER_o903 0xB #define COLLIDER_deilittsw 0xA #define COLLIDER_deilitsw 0x9 #define COLLIDER_deilisw 0x8 #define COLLIDER_g229 0x7 #define COLLIDER_o1017 0x6 #define COLLIDER_o1016 0x5 #define COLLIDER_o688 0x4 #define COLLIDER_o957 0x3 #define COLLIDER_o954 0x2 #define COLLIDER_o953 0x1 #define COLLIDER_o662 0x0 #define ZONE_Root 0x3 #define ZONE_g144 0x2 #define ZONE_o1024 0x1 #define ZONE_o1023 0x0
9ed3d2596c6c6c8ba24284284d9be2ad52469e95
a0594b88e0b4cdd233364b3d0189e651e05f4b1e
/aircast/src/cast_parse.h
576f12ce9967e7c9d0cca91106611e415cb50f7f
[ "MIT" ]
permissive
philippe44/AirConnect
e8e183d10b37422c59b746e56d85adeae4c11888
2cb3a01d4a946fb5b11a97d776828ba560c92a0a
refs/heads/master
2023-08-24T18:03:19.570052
2023-08-23T00:04:36
2023-08-23T00:04:36
99,628,750
3,142
240
NOASSERTION
2022-11-29T07:33:49
2017-08-07T23:17:20
C
UTF-8
C
false
false
547
h
cast_parse.h
/* * Chromecast parse utils * * (c) Philippe 2016-2017, philippe_44@outlook.com * * See LICENSE * */ #pragma once #include <stdbool.h> #include "jansson.h" int GetMediaItem_I(json_t *root, int n, char *item); double GetMediaItem_F(json_t *root, int n, char *item); const char* GetMediaItem_S(json_t *root, int n, char *item); const char* GetAppIdItem(json_t *root, char* appId, char *item); const char* GetMediaInfoItem_S(json_t *root, int n, char *item); bool GetMediaVolume(json_t *root, int n, double *volume, bool *muted);
a2b3d87b24b4a9622ca4dcec84f0387e14598331
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/libaom/source/libaom/aom_dsp/sse.c
16f6b58bd4da6770d5b20b5a6b6b01b2e3fa6755
[ "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later", "BSD-3-Clause", "BSD-2-Clause" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
1,573
c
sse.c
/* * Copyright (c) 2018, Alliance for Open Media. All rights reserved * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent. */ /* Sum the difference between every corresponding element of the buffers. */ #include "config/aom_config.h" #include "config/aom_dsp_rtcd.h" #include "aom/aom_integer.h" int64_t aom_sse_c(const uint8_t *a, int a_stride, const uint8_t *b, int b_stride, int width, int height) { int y, x; int64_t sse = 0; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { const int32_t diff = abs(a[x] - b[x]); sse += diff * diff; } a += a_stride; b += b_stride; } return sse; } #if CONFIG_AV1_HIGHBITDEPTH int64_t aom_highbd_sse_c(const uint8_t *a8, int a_stride, const uint8_t *b8, int b_stride, int width, int height) { int y, x; int64_t sse = 0; uint16_t *a = CONVERT_TO_SHORTPTR(a8); uint16_t *b = CONVERT_TO_SHORTPTR(b8); for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { const int32_t diff = (int32_t)(a[x]) - (int32_t)(b[x]); sse += diff * diff; } a += a_stride; b += b_stride; } return sse; } #endif
5e6825badc506825f65cd6d1d231417aaec331ef
30b736259b38c916e96f8e1517f92231070f5464
/nimble/controller/include/controller/ble_hw.h
394c3a173c2883d4f5ba3f1ef95d5cd76913c67d
[ "Apache-2.0", "LicenseRef-scancode-gary-s-brown", "BSD-3-Clause" ]
permissive
apache/mynewt-nimble
5bcc87df4482705c5a6542467bab028c8fd4e5fe
b5e107e9c55f32d18b16e5afc0a7e1720b901b68
refs/heads/master
2023-09-01T19:28:57.874159
2023-08-31T09:07:59
2023-08-31T14:46:07
113,086,218
606
354
Apache-2.0
2023-09-14T12:14:19
2017-12-04T19:34:47
C
UTF-8
C
false
false
2,868
h
ble_hw.h
/* * 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. */ #ifndef H_BLE_HW_ #define H_BLE_HW_ #ifdef __cplusplus extern "C" { #endif #include "syscfg/syscfg.h" #if defined(ARCH_sim) #define BLE_USES_HW_WHITELIST (0) #else #define BLE_USES_HW_WHITELIST MYNEWT_VAL(BLE_HW_WHITELIST_ENABLE) #endif /* Returns the number of hw whitelist elements */ uint8_t ble_hw_whitelist_size(void); /* Clear the whitelist */ void ble_hw_whitelist_clear(void); /* Remove a device from the hw whitelist */ void ble_hw_whitelist_rmv(const uint8_t *addr, uint8_t addr_type); /* Add a device to the hw whitelist */ int ble_hw_whitelist_add(const uint8_t *addr, uint8_t addr_type); /* Enable hw whitelisting */ void ble_hw_whitelist_enable(void); /* Enable hw whitelisting */ void ble_hw_whitelist_disable(void); /* Boolean function returning true if address matches a whitelist entry */ int ble_hw_whitelist_match(void); /* Encrypt data */ struct ble_encryption_block; int ble_hw_encrypt_block(struct ble_encryption_block *ecb); /* Random number generation */ typedef void (*ble_rng_isr_cb_t)(uint8_t rnum); int ble_hw_rng_init(ble_rng_isr_cb_t cb, int bias); /** * Start the random number generator * * @return int */ int ble_hw_rng_start(void); /** * Stop the random generator * * @return int */ int ble_hw_rng_stop(void); /** * Read the random number generator. * * @return uint8_t */ uint8_t ble_hw_rng_read(void); /* Clear the resolving list*/ void ble_hw_resolv_list_clear(void); /* Add a device to the hw resolving list */ int ble_hw_resolv_list_add(uint8_t *irk); /* Remove a device from the hw resolving list */ void ble_hw_resolv_list_rmv(int index); /* Returns the size of the whitelist in HW */ uint8_t ble_hw_resolv_list_size(void); /* Returns index of resolved address; -1 if not resolved */ int ble_hw_resolv_list_match(void); /* Returns public device address or -1 if not present */ int ble_hw_get_public_addr(ble_addr_t *addr); /* Returns random static address or -1 if not present */ int ble_hw_get_static_addr(ble_addr_t *addr); #ifdef __cplusplus } #endif #endif /* H_BLE_HW_ */
c1764cbe563d021a5ca20defadde06c29b9c881a
de3521f03ac554b25e91015eb2f0d7e434a92519
/Libraries/3rd/curl/source/lib/http_aws_sigv4.c
8c6d1c9dc8f1fa302653086cd61be0dd2b7efe87
[ "curl" ]
permissive
MiKTeX/miktex
5336dca6bbc09b121b5bd42e484e5b5ef1488017
60a5fd73f8a5e0654f1bbf9c68d9c1b8e777c6cd
refs/heads/next
2023-09-04T02:20:14.229772
2023-08-07T15:16:13
2023-08-07T15:16:13
61,892,189
727
107
NOASSERTION
2023-08-07T05:30:11
2016-06-24T15:00:19
C
UTF-8
C
false
false
16,013
c
http_aws_sigv4.c
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH) #include "urldata.h" #include "strcase.h" #include "strdup.h" #include "http_aws_sigv4.h" #include "curl_sha256.h" #include "transfer.h" #include "parsedate.h" #include "sendf.h" #include <time.h> /* The last 3 #include files should be in this order */ #include "curl_printf.h" #include "curl_memory.h" #include "memdebug.h" #include "slist.h" #define HMAC_SHA256(k, kl, d, dl, o) \ do { \ ret = Curl_hmacit(Curl_HMAC_SHA256, \ (unsigned char *)k, \ (unsigned int)kl, \ (unsigned char *)d, \ (unsigned int)dl, o); \ if(ret) { \ goto fail; \ } \ } while(0) #define TIMESTAMP_SIZE 17 static void sha256_to_hex(char *dst, unsigned char *sha, size_t dst_l) { int i; DEBUGASSERT(dst_l >= 65); for(i = 0; i < 32; ++i) { msnprintf(dst + (i * 2), dst_l - (i * 2), "%02x", sha[i]); } } static char *find_date_hdr(struct Curl_easy *data, const char *sig_hdr) { char *tmp = Curl_checkheaders(data, sig_hdr, strlen(sig_hdr)); if(tmp) return tmp; return Curl_checkheaders(data, STRCONST("Date")); } /* remove whitespace, and lowercase all headers */ static void trim_headers(struct curl_slist *head) { struct curl_slist *l; for(l = head; l; l = l->next) { char *value; /* to read from */ char *store; size_t colon = strcspn(l->data, ":"); Curl_strntolower(l->data, l->data, colon); value = &l->data[colon]; if(!*value) continue; ++value; store = value; /* skip leading whitespace */ while(*value && ISBLANK(*value)) value++; while(*value) { int space = 0; while(*value && ISBLANK(*value)) { value++; space++; } if(space) { /* replace any number of consecutive whitespace with a single space, unless at the end of the string, then nothing */ if(*value) *store++ = ' '; } else *store++ = *value++; } *store = 0; /* null terminate */ } } /* maximum length for the aws sivg4 parts */ #define MAX_SIGV4_LEN 64 #define MAX_SIGV4_LEN_TXT "64" #define DATE_HDR_KEY_LEN (MAX_SIGV4_LEN + sizeof("X--Date")) #define MAX_HOST_LEN 255 /* FQDN + host: */ #define FULL_HOST_LEN (MAX_HOST_LEN + sizeof("host:")) /* string been x-PROVIDER-date:TIMESTAMP, I need +1 for ':' */ #define DATE_FULL_HDR_LEN (DATE_HDR_KEY_LEN + TIMESTAMP_SIZE + 1) /* timestamp should point to a buffer of at last TIMESTAMP_SIZE bytes */ static CURLcode make_headers(struct Curl_easy *data, const char *hostname, char *timestamp, char *provider1, char **date_header, struct dynbuf *canonical_headers, struct dynbuf *signed_headers) { char date_hdr_key[DATE_HDR_KEY_LEN]; char date_full_hdr[DATE_FULL_HDR_LEN]; struct curl_slist *head = NULL; struct curl_slist *tmp_head = NULL; CURLcode ret = CURLE_OUT_OF_MEMORY; struct curl_slist *l; int again = 1; /* provider1 mid */ Curl_strntolower(provider1, provider1, strlen(provider1)); provider1[0] = Curl_raw_toupper(provider1[0]); msnprintf(date_hdr_key, DATE_HDR_KEY_LEN, "X-%s-Date", provider1); /* provider1 lowercase */ Curl_strntolower(provider1, provider1, 1); /* first byte only */ msnprintf(date_full_hdr, DATE_FULL_HDR_LEN, "x-%s-date:%s", provider1, timestamp); if(Curl_checkheaders(data, STRCONST("Host"))) { head = NULL; } else { char full_host[FULL_HOST_LEN + 1]; if(data->state.aptr.host) { size_t pos; if(strlen(data->state.aptr.host) > FULL_HOST_LEN) { ret = CURLE_URL_MALFORMAT; goto fail; } strcpy(full_host, data->state.aptr.host); /* remove /r/n as the separator for canonical request must be '\n' */ pos = strcspn(full_host, "\n\r"); full_host[pos] = 0; } else { if(strlen(hostname) > MAX_HOST_LEN) { ret = CURLE_URL_MALFORMAT; goto fail; } msnprintf(full_host, FULL_HOST_LEN, "host:%s", hostname); } head = curl_slist_append(NULL, full_host); if(!head) goto fail; } for(l = data->set.headers; l; l = l->next) { tmp_head = curl_slist_append(head, l->data); if(!tmp_head) goto fail; head = tmp_head; } trim_headers(head); *date_header = find_date_hdr(data, date_hdr_key); if(!*date_header) { tmp_head = curl_slist_append(head, date_full_hdr); if(!tmp_head) goto fail; head = tmp_head; *date_header = curl_maprintf("%s: %s", date_hdr_key, timestamp); } else { char *value; *date_header = strdup(*date_header); if(!*date_header) goto fail; value = strchr(*date_header, ':'); if(!value) goto fail; ++value; while(ISBLANK(*value)) ++value; strncpy(timestamp, value, TIMESTAMP_SIZE - 1); timestamp[TIMESTAMP_SIZE - 1] = 0; } /* alpha-sort in a case sensitive manner */ do { again = 0; for(l = head; l; l = l->next) { struct curl_slist *next = l->next; if(next && strcmp(l->data, next->data) > 0) { char *tmp = l->data; l->data = next->data; next->data = tmp; again = 1; } } } while(again); for(l = head; l; l = l->next) { char *tmp; if(Curl_dyn_add(canonical_headers, l->data)) goto fail; if(Curl_dyn_add(canonical_headers, "\n")) goto fail; tmp = strchr(l->data, ':'); if(tmp) *tmp = 0; if(l != head) { if(Curl_dyn_add(signed_headers, ";")) goto fail; } if(Curl_dyn_add(signed_headers, l->data)) goto fail; } ret = CURLE_OK; fail: curl_slist_free_all(head); return ret; } #define CONTENT_SHA256_KEY_LEN (MAX_SIGV4_LEN + sizeof("X--Content-Sha256")) /* try to parse a payload hash from the content-sha256 header */ static char *parse_content_sha_hdr(struct Curl_easy *data, const char *provider1, size_t *value_len) { char key[CONTENT_SHA256_KEY_LEN]; size_t key_len; char *value; size_t len; key_len = msnprintf(key, sizeof(key), "x-%s-content-sha256", provider1); value = Curl_checkheaders(data, key, key_len); if(!value) return NULL; value = strchr(value, ':'); if(!value) return NULL; ++value; while(*value && ISBLANK(*value)) ++value; len = strlen(value); while(len > 0 && ISBLANK(value[len-1])) --len; *value_len = len; return value; } CURLcode Curl_output_aws_sigv4(struct Curl_easy *data, bool proxy) { CURLcode ret = CURLE_OUT_OF_MEMORY; struct connectdata *conn = data->conn; size_t len; const char *arg; char provider0[MAX_SIGV4_LEN + 1]=""; char provider1[MAX_SIGV4_LEN + 1]=""; char region[MAX_SIGV4_LEN + 1]=""; char service[MAX_SIGV4_LEN + 1]=""; const char *hostname = conn->host.name; time_t clock; struct tm tm; char timestamp[TIMESTAMP_SIZE]; char date[9]; struct dynbuf canonical_headers; struct dynbuf signed_headers; char *date_header = NULL; char *payload_hash = NULL; size_t payload_hash_len = 0; const char *post_data = data->set.postfields; size_t post_data_len = 0; unsigned char sha_hash[32]; char sha_hex[65]; char *canonical_request = NULL; char *request_type = NULL; char *credential_scope = NULL; char *str_to_sign = NULL; const char *user = data->state.aptr.user ? data->state.aptr.user : ""; char *secret = NULL; unsigned char sign0[32] = {0}; unsigned char sign1[32] = {0}; char *auth_headers = NULL; DEBUGASSERT(!proxy); (void)proxy; if(Curl_checkheaders(data, STRCONST("Authorization"))) { /* Authorization already present, Bailing out */ return CURLE_OK; } /* we init those buffers here, so goto fail will free initialized dynbuf */ Curl_dyn_init(&canonical_headers, CURL_MAX_HTTP_HEADER); Curl_dyn_init(&signed_headers, CURL_MAX_HTTP_HEADER); /* * Parameters parsing * Google and Outscale use the same OSC or GOOG, * but Amazon uses AWS and AMZ for header arguments. * AWS is the default because most of non-amazon providers * are still using aws:amz as a prefix. */ arg = data->set.str[STRING_AWS_SIGV4] ? data->set.str[STRING_AWS_SIGV4] : "aws:amz"; /* provider1[:provider2[:region[:service]]] No string can be longer than N bytes of non-whitespace */ (void)sscanf(arg, "%" MAX_SIGV4_LEN_TXT "[^:]" ":%" MAX_SIGV4_LEN_TXT "[^:]" ":%" MAX_SIGV4_LEN_TXT "[^:]" ":%" MAX_SIGV4_LEN_TXT "s", provider0, provider1, region, service); if(!provider0[0]) { failf(data, "first provider can't be empty"); ret = CURLE_BAD_FUNCTION_ARGUMENT; goto fail; } else if(!provider1[0]) strcpy(provider1, provider0); if(!service[0]) { char *hostdot = strchr(hostname, '.'); if(!hostdot) { failf(data, "service missing in parameters and hostname"); ret = CURLE_URL_MALFORMAT; goto fail; } len = hostdot - hostname; if(len > MAX_SIGV4_LEN) { failf(data, "service too long in hostname"); ret = CURLE_URL_MALFORMAT; goto fail; } strncpy(service, hostname, len); service[len] = '\0'; if(!region[0]) { const char *reg = hostdot + 1; const char *hostreg = strchr(reg, '.'); if(!hostreg) { failf(data, "region missing in parameters and hostname"); ret = CURLE_URL_MALFORMAT; goto fail; } len = hostreg - reg; if(len > MAX_SIGV4_LEN) { failf(data, "region too long in hostname"); ret = CURLE_URL_MALFORMAT; goto fail; } strncpy(region, reg, len); region[len] = '\0'; } } #ifdef DEBUGBUILD { char *force_timestamp = getenv("CURL_FORCETIME"); if(force_timestamp) clock = 0; else time(&clock); } #else time(&clock); #endif ret = Curl_gmtime(clock, &tm); if(ret) { goto fail; } if(!strftime(timestamp, sizeof(timestamp), "%Y%m%dT%H%M%SZ", &tm)) { ret = CURLE_OUT_OF_MEMORY; goto fail; } ret = make_headers(data, hostname, timestamp, provider1, &date_header, &canonical_headers, &signed_headers); if(ret) goto fail; ret = CURLE_OUT_OF_MEMORY; memcpy(date, timestamp, sizeof(date)); date[sizeof(date) - 1] = 0; payload_hash = parse_content_sha_hdr(data, provider1, &payload_hash_len); if(!payload_hash) { if(post_data) { if(data->set.postfieldsize < 0) post_data_len = strlen(post_data); else post_data_len = (size_t)data->set.postfieldsize; } if(Curl_sha256it(sha_hash, (const unsigned char *) post_data, post_data_len)) goto fail; sha256_to_hex(sha_hex, sha_hash, sizeof(sha_hex)); payload_hash = sha_hex; payload_hash_len = strlen(sha_hex); } { Curl_HttpReq httpreq; const char *method; Curl_http_method(data, conn, &method, &httpreq); canonical_request = curl_maprintf("%s\n" /* HTTPRequestMethod */ "%s\n" /* CanonicalURI */ "%s\n" /* CanonicalQueryString */ "%s\n" /* CanonicalHeaders */ "%s\n" /* SignedHeaders */ "%.*s", /* HashedRequestPayload in hex */ method, data->state.up.path, data->state.up.query ? data->state.up.query : "", Curl_dyn_ptr(&canonical_headers), Curl_dyn_ptr(&signed_headers), (int)payload_hash_len, payload_hash); if(!canonical_request) goto fail; } /* provider 0 lowercase */ Curl_strntolower(provider0, provider0, strlen(provider0)); request_type = curl_maprintf("%s4_request", provider0); if(!request_type) goto fail; credential_scope = curl_maprintf("%s/%s/%s/%s", date, region, service, request_type); if(!credential_scope) goto fail; if(Curl_sha256it(sha_hash, (unsigned char *) canonical_request, strlen(canonical_request))) goto fail; sha256_to_hex(sha_hex, sha_hash, sizeof(sha_hex)); /* provider 0 uppercase */ Curl_strntoupper(provider0, provider0, strlen(provider0)); /* * Google allows using RSA key instead of HMAC, so this code might change * in the future. For now we only support HMAC. */ str_to_sign = curl_maprintf("%s4-HMAC-SHA256\n" /* Algorithm */ "%s\n" /* RequestDateTime */ "%s\n" /* CredentialScope */ "%s", /* HashedCanonicalRequest in hex */ provider0, timestamp, credential_scope, sha_hex); if(!str_to_sign) { goto fail; } /* provider 0 uppercase */ secret = curl_maprintf("%s4%s", provider0, data->state.aptr.passwd ? data->state.aptr.passwd : ""); if(!secret) goto fail; HMAC_SHA256(secret, strlen(secret), date, strlen(date), sign0); HMAC_SHA256(sign0, sizeof(sign0), region, strlen(region), sign1); HMAC_SHA256(sign1, sizeof(sign1), service, strlen(service), sign0); HMAC_SHA256(sign0, sizeof(sign0), request_type, strlen(request_type), sign1); HMAC_SHA256(sign1, sizeof(sign1), str_to_sign, strlen(str_to_sign), sign0); sha256_to_hex(sha_hex, sign0, sizeof(sha_hex)); /* provider 0 uppercase */ auth_headers = curl_maprintf("Authorization: %s4-HMAC-SHA256 " "Credential=%s/%s, " "SignedHeaders=%s, " "Signature=%s\r\n" "%s\r\n", provider0, user, credential_scope, Curl_dyn_ptr(&signed_headers), sha_hex, date_header); if(!auth_headers) { goto fail; } Curl_safefree(data->state.aptr.userpwd); data->state.aptr.userpwd = auth_headers; data->state.authhost.done = TRUE; ret = CURLE_OK; fail: Curl_dyn_free(&canonical_headers); Curl_dyn_free(&signed_headers); free(canonical_request); free(request_type); free(credential_scope); free(str_to_sign); free(secret); free(date_header); return ret; } #endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH) */
4f77791d337acdcd9a84844282f01ed4f6142a85
010279e2ba272d09e9d2c4e903722e5faba2cf7a
/contrib/python/scipy/py3/scipy/optimize/_highs/src/ipm/basiclu/src/lu_solve_sparse.c
b982d58bd68e5e02f2c2dfe22b859294ca68dc15
[ "MIT", "Apache-2.0", "Python-2.0", "LicenseRef-scancode-unknown-license-reference", "Qhull", "BSD-3-Clause", "BSL-1.0", "BSD-2-Clause" ]
permissive
catboost/catboost
854c1a1f439a96f1ae6b48e16644be20aa04dba2
f5042e35b945aded77b23470ead62d7eacefde92
refs/heads/master
2023-09-01T12:14:14.174108
2023-09-01T10:01:01
2023-09-01T10:22:12
97,556,265
8,012
1,425
Apache-2.0
2023-09-11T03:32:32
2017-07-18T05:29:04
Python
UTF-8
C
false
false
9,340
c
lu_solve_sparse.c
/* * lu_solve_sparse.c * * Copyright (C) 2016-2018 ERGO-Code * */ #include "lu_internal.h" void lu_solve_sparse( struct lu *this, const lu_int nrhs, const lu_int *irhs, const double *xrhs, lu_int *p_nlhs, lu_int *ilhs, double *xlhs, char trans) { const lu_int m = this->m; const lu_int nforrest = this->nforrest; const lu_int pivotlen = this->pivotlen; const lu_int nz_sparse = this->sparse_thres * m; const double droptol = this->droptol; const lu_int *p = this->p; const lu_int *pmap = this->pmap; const lu_int *qmap = this->qmap; const lu_int *eta_row = this->eta_row; const lu_int *pivotcol = this->pivotcol; const lu_int *pivotrow = this->pivotrow; const lu_int *Lbegin = this->Lbegin; const lu_int *Ltbegin = this->Ltbegin; const lu_int *Ltbegin_p = this->Ltbegin_p; const lu_int *Ubegin = this->Ubegin; const lu_int *Rbegin = this->Rbegin; const lu_int *Wbegin = this->Wbegin; const lu_int *Wend = this->Wend; const double *col_pivot = this->col_pivot; const double *row_pivot = this->row_pivot; const lu_int *Lindex = this->Lindex; const double *Lvalue = this->Lvalue; const lu_int *Uindex = this->Uindex; const double *Uvalue = this->Uvalue; const lu_int *Windex = this->Windex; const double *Wvalue = this->Wvalue; lu_int *marked = this->marked; lu_int i, j, k, n, t, top, pos, ipivot, jpivot, nz, nz_symb, M; double x; lu_int Lflops = 0, Uflops = 0, Rflops = 0; double tic[2], elapsed; if (trans == 't' || trans == 'T') { /* ----------------------- */ /* Solve transposed system */ /* ----------------------- */ lu_int *pattern_symb = this->iwork1; lu_int *pattern = this->iwork1 + m; double *work = this->work0; lu_int *pstack = (void *) this->work1; assert(sizeof(lu_int) <= sizeof(double)); /* * Sparse triangular solve with U'. * Solution scattered into work, indices in pattern[0..nz-1]. */ M = ++this->marker; top = lu_solve_symbolic(m, Wbegin, Wend, Windex, nrhs, irhs, pattern_symb, pstack, marked, M); nz_symb = m-top; for (n = 0; n < nrhs; n++) work[irhs[n]] = xrhs[n]; nz = lu_solve_triangular(nz_symb, pattern_symb+top, Wbegin, Wend, Windex, Wvalue, col_pivot, droptol, work, pattern, &Uflops); /* * Permute solution into xlhs. * Map pattern from column indices to row indices. */ M = ++this->marker; for (n = 0; n < nz; n++) { j = pattern[n]; i = pmap[j]; pattern[n] = i; xlhs[i] = work[j]; work[j] = 0; marked[i] = M; } /* * Solve with update etas. * Append fill-in to pattern. */ for (t = nforrest-1; t >= 0; t--) { ipivot = eta_row[t]; if (xlhs[ipivot]) { x = xlhs[ipivot]; for (pos = Rbegin[t]; pos < Rbegin[t+1]; pos++) { i = Lindex[pos]; if (marked[i] != M) { marked[i] = M; pattern[nz++] = i; } xlhs[i] -= x * Lvalue[pos]; Rflops++; } } } if (nz <= nz_sparse) { /* * Sparse triangular solve with L'. * Solution scattered into xlhs, indices in ilhs[0..nz-1]. */ M = ++this->marker; top = lu_solve_symbolic(m, Ltbegin, NULL, Lindex, nz, pattern, pattern_symb, pstack, marked, M); nz_symb = m-top; nz = lu_solve_triangular(nz_symb, pattern_symb+top, Ltbegin, NULL, Lindex, Lvalue, NULL, droptol, xlhs, ilhs, &Lflops); *p_nlhs = nz; } else { /* * Sequential triangular solve with L'. * Solution scattered into xlhs, indices in ilhs[0..nz-1]. */ nz = 0; for (k = m-1; k >= 0; k--) { ipivot = p[k]; if (xlhs[ipivot]) { x = xlhs[ipivot]; for (pos = Ltbegin_p[k]; (i = Lindex[pos]) >= 0; pos++) { xlhs[i] -= x * Lvalue[pos]; Lflops++; } if (fabs(x) > droptol) ilhs[nz++] = ipivot; else xlhs[ipivot] = 0.0; } } *p_nlhs = nz; } } else { /* -------------------- */ /* Solve forward system */ /* -------------------- */ lu_int *pattern_symb = this->iwork1; lu_int *pattern = this->iwork1 + m; double *work = this->work0; lu_int *pstack = (void *) this->work1; assert(sizeof(lu_int) <= sizeof(double)); /* * Sparse triangular solve with L. * Solution scattered into work, indices in pattern[0..nz-1]. */ M = ++this->marker; top = lu_solve_symbolic(m, Lbegin, NULL, Lindex, nrhs, irhs, pattern_symb, pstack, marked, M); nz_symb = m-top; for (n = 0; n < nrhs; n++) work[irhs[n]] = xrhs[n]; nz = lu_solve_triangular(nz_symb, pattern_symb+top, Lbegin, NULL, Lindex, Lvalue, NULL, droptol, work, pattern, &Lflops); /* unmark cancellation */ if (nz < nz_symb) { for (t = top, n = 0; n < nz; t++) { i = pattern_symb[t]; if (i == pattern[n]) n++; else marked[i]--; } for ( ; t < m; t++) marked[pattern_symb[t]]--; } /* * Solve with update etas. * Append fill-in to pattern. */ pos = Rbegin[0]; for (t = 0; t < nforrest; t++) { ipivot = eta_row[t]; x = 0.0; for ( ; pos < Rbegin[t+1]; pos++) { x += work[Lindex[pos]] * Lvalue[pos]; } work[ipivot] -= x; if (x && marked[ipivot] != M) { marked[ipivot] = M; pattern[nz++] = ipivot; } } Rflops += Rbegin[nforrest] - Rbegin[0]; if (nz <= nz_sparse) { /* * Sparse triangular solve with U. * Solution scattered into work, indices in ilhs[0..nz-1]. */ M = ++this->marker; top = lu_solve_symbolic(m, Ubegin, NULL, Uindex, nz, pattern, pattern_symb, pstack, marked, M); nz_symb = m-top; nz = lu_solve_triangular(nz_symb, pattern_symb+top, Ubegin, NULL, Uindex, Uvalue, row_pivot, droptol, work, ilhs, &Uflops); /* * Permute solution into xlhs. * Map pattern from row indices to column indices. */ for (n = 0; n < nz; n++) { i = ilhs[n]; j = qmap[i]; ilhs[n] = j; xlhs[j] = work[i]; work[i] = 0; } } else { /* * Sequential triangular solve with U. * Solution computed in work and permuted into xlhs. * Pattern (in column indices) stored in ilhs[0..nz-1]. */ nz = 0; for (k = pivotlen-1; k >= 0; k--) { ipivot = pivotrow[k]; jpivot = pivotcol[k]; if (work[ipivot]) { x = work[ipivot] / row_pivot[ipivot]; work[ipivot] = 0.0; for (pos = Ubegin[ipivot]; (i = Uindex[pos]) >= 0; pos++) { work[i] -= x * Uvalue[pos]; Uflops++; } if (fabs(x) > droptol) { ilhs[nz++] = jpivot; xlhs[jpivot] = x; } } } } *p_nlhs = nz; } this->Lflops += Lflops; this->Uflops += Uflops; this->Rflops += Rflops; this->update_cost_numer += Rflops; }
b32ba732dbb6c5083f28624549bdf2152621a583
ca4c4631f3d47a90b8415bbe70dbc7cae18c071e
/src/property_evaluator/ConstantPropertyEvaluator.C
124faeca290d1225310ae4fe69c66ef996575502
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
Exawind/nalu-wind
5765078c445d379ea952d2b25a01f5ff490837a6
722cd7757a412c9306645963808047824c312a17
refs/heads/master
2023-08-16T17:44:54.744168
2023-08-15T18:05:23
2023-08-15T18:05:23
132,016,365
111
87
NOASSERTION
2023-09-14T04:02:07
2018-05-03T15:39:32
C
UTF-8
C
false
false
1,833
c
ConstantPropertyEvaluator.C
// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC // (NTESS), National Renewable Energy Laboratory, University of Texas Austin, // Northwest Research Associates. Under the terms of Contract DE-NA0003525 // with NTESS, the U.S. Government retains certain rights in this software. // // This software is released under the BSD 3-clause license. See LICENSE file // for more details. // #include <property_evaluator/ConstantPropertyEvaluator.h> namespace sierra { namespace nalu { //========================================================================== // Class Definition //========================================================================== // ConstantPropertyEvaluator //========================================================================== //-------------------------------------------------------------------------- //-------- constructor ----------------------------------------------------- //-------------------------------------------------------------------------- ConstantPropertyEvaluator::ConstantPropertyEvaluator(const double& value) : value_(value) { // nothing else } //-------------------------------------------------------------------------- //-------- destructor ------------------------------------------------------ //-------------------------------------------------------------------------- ConstantPropertyEvaluator::~ConstantPropertyEvaluator() { // nothing } //-------------------------------------------------------------------------- //-------- execute --------------------------------------------------------- //-------------------------------------------------------------------------- double ConstantPropertyEvaluator::execute( double* /* indVarList */, stk::mesh::Entity /*node*/) { return value_; } } // namespace nalu } // namespace sierra
cc0dfbd3e6e86d1aa21ce1d5263480c3e96af623
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/mn10300/include/asm/highmem.h
7c137cd8aa37490e07e2e9b7e917785e63236f5b
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "Linux-syscall-note", "GPL-2.0-only", "GPL-1.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
3,022
h
highmem.h
/* MN10300 Virtual kernel memory mappings for high memory * * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * - Derived from include/asm-i386/highmem.h * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. */ #ifndef _ASM_HIGHMEM_H #define _ASM_HIGHMEM_H #ifdef __KERNEL__ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/highmem.h> #include <asm/kmap_types.h> #include <asm/pgtable.h> /* undef for production */ #undef HIGHMEM_DEBUG /* declarations for highmem.c */ extern unsigned long highstart_pfn, highend_pfn; extern pte_t *kmap_pte; extern pgprot_t kmap_prot; extern pte_t *pkmap_page_table; extern void __init kmap_init(void); /* * Right now we initialize only a single pte table. It can be extended * easily, subsequent pte tables have to be allocated in one physical * chunk of RAM. */ #define PKMAP_BASE 0xfe000000UL #define LAST_PKMAP 1024 #define LAST_PKMAP_MASK (LAST_PKMAP - 1) #define PKMAP_NR(virt) ((virt - PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) extern unsigned long kmap_high(struct page *page); extern void kunmap_high(struct page *page); static inline unsigned long kmap(struct page *page) { if (in_interrupt()) BUG(); if (page < highmem_start_page) return page_address(page); return kmap_high(page); } static inline void kunmap(struct page *page) { if (in_interrupt()) BUG(); if (page < highmem_start_page) return; kunmap_high(page); } /* * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap * gives a more generic (and caching) interface. But kmap_atomic can * be used in IRQ contexts, so in some (very limited) cases we need * it. */ static inline unsigned long kmap_atomic(struct page *page) { unsigned long vaddr; int idx, type; pagefault_disable(); if (page < highmem_start_page) return page_address(page); type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR * smp_processor_id(); vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); #if HIGHMEM_DEBUG if (!pte_none(*(kmap_pte - idx))) BUG(); #endif set_pte(kmap_pte - idx, mk_pte(page, kmap_prot)); local_flush_tlb_one(vaddr); return vaddr; } static inline void __kunmap_atomic(unsigned long vaddr) { int type; if (vaddr < FIXADDR_START) { /* FIXME */ pagefault_enable(); return; } type = kmap_atomic_idx(); #if HIGHMEM_DEBUG { unsigned int idx; idx = type + KM_TYPE_NR * smp_processor_id(); if (vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx)) BUG(); /* * force other mappings to Oops if they'll try to access * this pte without first remap it */ pte_clear(kmap_pte - idx); local_flush_tlb_one(vaddr); } #endif kmap_atomic_idx_pop(); pagefault_enable(); } #endif /* __KERNEL__ */ #endif /* _ASM_HIGHMEM_H */
785e2cd575b7833f4e7418af029fc931e0714108
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/arch/arm/gemini/gemini_gmacvar.h
d3024cc10daf2b9ccd11b41e25f4aa8ee65a2e96
[]
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
5,529
h
gemini_gmacvar.h
/* $NetBSD: gemini_gmacvar.h,v 1.3 2008/12/23 02:15:10 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Matt Thomas <matt@3am-software.com> * * 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 _ARM_GEMINI_GEMINI_GMACVAR_H #define _ARM_GEMINI_GEMINI_GMACVAR_H #include <sys/device.h> #include <sys/queue.h> #include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> #include <dev/mii/miivar.h> #include <arm/gemini/gemini_gmacreg.h> typedef struct gmac_hwqueue gmac_hwqueue_t; typedef struct gmac_hwqmem gmac_hwqmem_t; typedef struct gmac_mapcache gmac_mapcache_t; #define MAX_TXMAPS 256 #define MIN_TXMAPS 16 #define MAX_RXMAPS 128 #define MIN_RXMAPS 8 #define RXQ_NDESCS 256 #define TXQ_NDESCS 128 struct gmac_mapcache { bus_dma_tag_t mc_dmat; bus_size_t mc_mapsize; size_t mc_nsegs; size_t mc_free; size_t mc_used; size_t mc_max; bus_dmamap_t mc_maps[0]; }; struct gmac_softc { device_t sc_dev; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; bus_dma_tag_t sc_dmat; /* * MDIO state */ kmutex_t sc_mdiolock; uint32_t sc_mdiobits; device_t sc_gpio_dev; uint8_t sc_gpio_mdclk; uint8_t sc_gpio_mdin; uint8_t sc_gpio_mdout; /* * What GMAC ports have attached? */ uint8_t sc_ports; uint8_t sc_running; /* * The hardware free queue and software free queue are shared * resources. As are the dmamap caches. */ gmac_hwqueue_t *sc_swfreeq; gmac_hwqueue_t *sc_hwfreeq; gmac_mapcache_t *sc_rxmaps; gmac_mapcache_t *sc_txmaps; size_t sc_swfree_min; /* min mbufs to keep on swfreeq */ size_t sc_rxpkts_per_sec; /* * What interrupts are enabled for both ports? */ uint32_t sc_int_enabled[5]; uint32_t sc_int_select[5]; }; struct gmac_attach_args { bus_space_tag_t gma_iot; bus_space_handle_t gma_ioh; bus_dma_tag_t gma_dmat; int gma_port; int gma_phy; int gma_intr; mii_readreg_t gma_mii_readreg; mii_writereg_t gma_mii_writereg; }; struct gmac_hwqmem { bus_dma_tag_t hqm_dmat; bus_dmamap_t hqm_dmamap; gmac_mapcache_t *hqm_mc; gmac_desc_t *hqm_base; bus_size_t hqm_memsize; bus_dma_segment_t hqm_segs[1]; size_t hqm_ndesc; size_t hqm_nqueue; int hqm_nsegs; uint8_t hqm_refs; uint8_t hqm_flags; #define HQM_TX 0x0001 #define HQM_RX 0x0000 #define HQM_PRODUCER 0x0002 #define HQM_CONSUMER 0x0000 }; struct gmac_hwqueue { gmac_desc_t *hwq_base; gmac_hwqmem_t *hwq_hqm; union { SLIST_ENTRY(gmac_hwqueue) qun_link; SLIST_HEAD(,gmac_hwqueue) qun_producers; struct gmac_hwqueue *qun_producer; } hwq_qun; #define hwq_link hwq_qun.qun_link #define hwq_producers hwq_qun.qun_producers #define hwq_producer hwq_qun.qun_producer struct ifnet *hwq_ifp; struct ifqueue hwq_ifq; struct mbuf *hwq_rxmbuf; struct mbuf **hwq_mp; bus_space_tag_t hwq_iot; bus_space_handle_t hwq_qrwptr_ioh; /* * These are in units of gmac_desc_t, not bytes. */ size_t hwq_qoff; /* offset in descriptors to start */ uint16_t hwq_wptr; /* next descriptor to write */ uint16_t hwq_rptr; /* next descriptor to read */ uint16_t hwq_free; /* descriptors can be produced */ uint16_t hwq_size; /* total number of descriptors */ uint8_t hwq_ref; }; #ifdef _KERNEL gmac_hwqmem_t * gmac_hwqmem_create(gmac_mapcache_t *, size_t, size_t, int); void gmac_hwqmem_destroy(gmac_hwqmem_t *); void gmac_hwqueue_destroy(gmac_hwqueue_t *); gmac_hwqueue_t * gmac_hwqueue_create(gmac_hwqmem_t *, bus_space_tag_t, bus_space_handle_t, bus_size_t, bus_size_t, size_t); gmac_desc_t * gmac_hwqueue_desc(gmac_hwqueue_t *, size_t); void gmac_hwqueue_sync(gmac_hwqueue_t *); size_t gmac_hwqueue_consume(gmac_hwqueue_t *, size_t); void gmac_hwqueue_produce(gmac_hwqueue_t *, size_t); gmac_mapcache_t * gmac_mapcache_create(bus_dma_tag_t, size_t, bus_size_t, int); void gmac_mapcache_destroy(gmac_mapcache_t **); int gmac_mapcache_fill(gmac_mapcache_t *, size_t); bus_dmamap_t gmac_mapcache_get(gmac_mapcache_t *); void gmac_mapcache_put(gmac_mapcache_t *, bus_dmamap_t); size_t gmac_rxproduce(gmac_hwqueue_t *, size_t); void gmac_swfree_min_update(struct gmac_softc *); void gmac_intr_update(struct gmac_softc *); #endif #endif /* _ARM_GEMINI_GEMINI_GMACVAR_H */
6010d5f67a1bf3fe0aa4d66a7e697db69127249a
3c6e1e35f38421273f92dd25055dccc6f632fd93
/app/lua/lmem.c
ae244a9ff4f934bddefd54f15527a80d10d041a5
[ "MIT" ]
permissive
nodemcu/nodemcu-firmware
fd907ddf01bf17fdc55dd352d6987ee91d8b95e3
f25dc56d3c6213b8ac7ce46d1293466137746eae
refs/heads/release
2023-08-22T21:46:10.995686
2021-12-30T07:46:20
2021-12-30T07:46:20
26,917,568
8,077
3,888
MIT
2023-07-25T09:20:45
2014-11-20T15:06:45
C
UTF-8
C
false
false
2,151
c
lmem.c
/* ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ #define lmem_c #define LUA_CORE #include "lua.h" #include "ldebug.h" #include "ldo.h" #include "lmem.h" #include "lobject.h" #include "lstate.h" /* ** About the realloc function: ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); ** (`osize' is the old size, `nsize' is the new size) ** ** Lua ensures that (ptr == NULL) iff (osize == 0). ** ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' ** ** * frealloc(ud, p, x, 0) frees the block `p' ** (in this specific case, frealloc must return NULL). ** particularly, frealloc(ud, NULL, 0, 0) does nothing ** (which is equivalent to free(NULL) in ANSI C) ** ** frealloc returns NULL if it cannot create or reallocate the area ** (any reallocation to an equal or smaller size cannot fail!) */ #define MINSIZEARRAY 4 void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, int limit, const char *errormsg) { void *newblock; int newsize; if (*size >= limit/2) { /* cannot double it? */ if (*size >= limit) /* cannot grow even a little? */ luaG_runerror(L, errormsg); newsize = limit; /* still have at least one free place */ } else { newsize = (*size)*2; if (newsize < MINSIZEARRAY) newsize = MINSIZEARRAY; /* minimum size */ } newblock = luaM_reallocv(L, block, *size, newsize, size_elems); *size = newsize; /* update only when everything else is OK */ return newblock; } void *luaM_toobig (lua_State *L) { luaG_runerror(L, "memory allocation error: block too big"); return NULL; /* to avoid warnings */ } /* ** generic allocation routine. */ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { global_State *g = G(L); lua_assert((osize == 0) == (block == NULL)); block = (*g->frealloc)(g->ud, block, osize, nsize); if (block == NULL && nsize > 0) luaD_throw(L, LUA_ERRMEM); lua_assert((nsize == 0) == (block == NULL)); g->totalbytes = (g->totalbytes - osize) + nsize; return block; }
9f693bdf2041f19bb847be3f1748897eb1bd5a2d
97aa8d02224c045c320a539b8e274e5370a953a2
/include/util.h
d3d2211e0de3660a2866872a69cbb1ec9cea66c2
[ "MIT" ]
permissive
caesar0301/http-sniffer
3dc883d505189fb1f34493cf20c089433c2e27d8
1f237d9e7d0eaf6b5b096920265be043772912f8
refs/heads/master
2021-01-22T03:13:50.221717
2018-12-22T02:49:55
2018-12-22T02:49:55
6,952,546
192
51
null
2015-09-19T01:54:25
2012-12-01T09:58:46
C
UTF-8
C
false
false
543
h
util.h
/* util.h */ #ifndef __UTIL_H__ #define __UTIL_H__ #include <sys/types.h> /************************Macros*****************************/ #define MALLOC(type, num) (type *) check_malloc((num) * sizeof(type)) #ifndef BOOL #define BOOL int #endif /* BOOL */ #ifndef TRUE #define TRUE 1 #endif /* TRUE */ #ifndef FALSE #define FALSE 0 #endif /* FALSE */ /**********************Functions*****************************/ void *check_malloc(unsigned long size); char *ip_ntos(u_int32_t n); u_int32_t ip_ston(char *s); #endif /* __UTIL_H__ */
5a8c29d3b2ea6a0a1d4d56a22b36998a7d485e51
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/imx6sx/iMX6_Platform_SDK/board/mx6dq/evb/iomux/i2c1_iomux_config.c
e464f458837926472417f5ceb47635a11fea0a73
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
9,702
c
i2c1_iomux_config.c
/* * Copyright (c) 2012, Freescale Semiconductor, Inc. * All rights reserved. * * 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. */ // File: i2c1_iomux_config.c /* ------------------------------------------------------------------------------ * <auto-generated> * This code was generated by a tool. * Runtime Version:3.4.0.0 * * Changes to this file may cause incorrect behavior and will be lost if * the code is regenerated. * </auto-generated> * ------------------------------------------------------------------------------ */ #include "iomux_config.h" #include "registers/regsiomuxc.h" // Function to configure IOMUXC for i2c1 module. void i2c1_iomux_config(void) { // Config i2c1.I2C1_SCL to pad CSI0_DATA09(N5) // HW_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA09_WR(0x00000014); // HW_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_WR(0x0001B0B0); // HW_IOMUXC_I2C1_SCL_IN_SELECT_INPUT_WR(0x00000001); // Mux Register: // IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA09(0x020E027C) // SION [4] - Software Input On Field Reset: DISABLED // Force the selected mux mode Input path no matter of MUX_MODE functionality. // DISABLED (0) - Input Path is determined by functionality of the selected mux mode (regular). // ENABLED (1) - Force input path of pad. // MUX_MODE [2:0] - MUX Mode Select Field Reset: ALT5 // Select iomux modes to be used for pad. // ALT0 (0) - Select instance: ipu1 signal: IPU1_CSI0_DATA09 // ALT1 (1) - Select instance: eim signal: EIM_DATA07 // ALT2 (2) - Select instance: ecspi2 signal: ECSPI2_MOSI // ALT3 (3) - Select instance: kpp signal: KEY_ROW7 // ALT4 (4) - Select instance: i2c1 signal: I2C1_SCL // ALT5 (5) - Select instance: gpio5 signal: GPIO5_IO27 // ALT7 (7) - Select instance: arm signal: ARM_TRACE06 HW_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA09_WR( BF_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA09_SION_V(ENABLED) | BF_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA09_MUX_MODE_V(ALT4)); // Pad Control Register: // IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09(0x020E064C) // HYS [16] - Hysteresis Enable Field Reset: ENABLED // DISABLED (0) - CMOS input // ENABLED (1) - Schmitt trigger input // PUS [15:14] - Pull Up / Down Config. Field Reset: 100K_OHM_PU // 100K_OHM_PD (0) - 100K Ohm Pull Down // 47K_OHM_PU (1) - 47K Ohm Pull Up // 100K_OHM_PU (2) - 100K Ohm Pull Up // 22K_OHM_PU (3) - 22K Ohm Pull Up // PUE [13] - Pull / Keep Select Field Reset: PULL // KEEP (0) - Keeper Enabled // PULL (1) - Pull Enabled // PKE [12] - Pull / Keep Enable Field Reset: ENABLED // DISABLED (0) - Pull/Keeper Disabled // ENABLED (1) - Pull/Keeper Enabled // ODE [11] - Open Drain Enable Field Reset: DISABLED // Enables open drain of the pin. // DISABLED (0) - Output is CMOS. // ENABLED (1) - Output is Open Drain. // SPEED [7:6] - Speed Field Reset: 100MHZ // TBD (0) - TBD // 50MHZ (1) - Low (50 MHz) // 100MHZ (2) - Medium (100 MHz) // 200MHZ (3) - Maximum (200 MHz) // DSE [5:3] - Drive Strength Field Reset: 40_OHM // HIZ (0) - HI-Z // 240_OHM (1) - 240 Ohm // 120_OHM (2) - 120 Ohm // 80_OHM (3) - 80 Ohm // 60_OHM (4) - 60 Ohm // 48_OHM (5) - 48 Ohm // 40_OHM (6) - 40 Ohm // 34_OHM (7) - 34 Ohm // SRE [0] - Slew Rate Field Reset: SLOW // Slew rate control. // SLOW (0) - Slow Slew Rate // FAST (1) - Fast Slew Rate HW_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_WR( BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_HYS_V(ENABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_PUS_V(100K_OHM_PU) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_PUE_V(PULL) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_PKE_V(ENABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_ODE_V(DISABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_SPEED_V(100MHZ) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_DSE_V(40_OHM) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA09_SRE_V(SLOW)); // Pad CSI0_DATA09 is involved in Daisy Chain. // Input Select Register: // IOMUXC_I2C1_SCL_IN_SELECT_INPUT(0x020E0898) // DAISY [0] - MUX Mode Select Field Reset: EIM_DATA21_ALT6 // Selecting Pads Involved in Daisy Chain. // EIM_DATA21_ALT6 (0) - Select signal i2c1 I2C1_SCL as input from pad EIM_DATA21(ALT6). // CSI0_DATA09_ALT4 (1) - Select signal i2c1 I2C1_SCL as input from pad CSI0_DATA09(ALT4). HW_IOMUXC_I2C1_SCL_IN_SELECT_INPUT_WR( BF_IOMUXC_I2C1_SCL_IN_SELECT_INPUT_DAISY_V(CSI0_DATA09_ALT4)); // Config i2c1.I2C1_SDA to pad CSI0_DATA08(N6) // HW_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA08_WR(0x00000014); // HW_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_WR(0x0001B0B0); // HW_IOMUXC_I2C1_SDA_IN_SELECT_INPUT_WR(0x00000001); // Mux Register: // IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA08(0x020E0278) // SION [4] - Software Input On Field Reset: DISABLED // Force the selected mux mode Input path no matter of MUX_MODE functionality. // DISABLED (0) - Input Path is determined by functionality of the selected mux mode (regular). // ENABLED (1) - Force input path of pad. // MUX_MODE [2:0] - MUX Mode Select Field Reset: ALT5 // Select iomux modes to be used for pad. // ALT0 (0) - Select instance: ipu1 signal: IPU1_CSI0_DATA08 // ALT1 (1) - Select instance: eim signal: EIM_DATA06 // ALT2 (2) - Select instance: ecspi2 signal: ECSPI2_SCLK // ALT3 (3) - Select instance: kpp signal: KEY_COL7 // ALT4 (4) - Select instance: i2c1 signal: I2C1_SDA // ALT5 (5) - Select instance: gpio5 signal: GPIO5_IO26 // ALT7 (7) - Select instance: arm signal: ARM_TRACE05 HW_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA08_WR( BF_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA08_SION_V(ENABLED) | BF_IOMUXC_SW_MUX_CTL_PAD_CSI0_DATA08_MUX_MODE_V(ALT4)); // Pad Control Register: // IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08(0x020E0648) // HYS [16] - Hysteresis Enable Field Reset: ENABLED // DISABLED (0) - CMOS input // ENABLED (1) - Schmitt trigger input // PUS [15:14] - Pull Up / Down Config. Field Reset: 100K_OHM_PU // 100K_OHM_PD (0) - 100K Ohm Pull Down // 47K_OHM_PU (1) - 47K Ohm Pull Up // 100K_OHM_PU (2) - 100K Ohm Pull Up // 22K_OHM_PU (3) - 22K Ohm Pull Up // PUE [13] - Pull / Keep Select Field Reset: PULL // KEEP (0) - Keeper Enabled // PULL (1) - Pull Enabled // PKE [12] - Pull / Keep Enable Field Reset: ENABLED // DISABLED (0) - Pull/Keeper Disabled // ENABLED (1) - Pull/Keeper Enabled // ODE [11] - Open Drain Enable Field Reset: DISABLED // Enables open drain of the pin. // DISABLED (0) - Output is CMOS. // ENABLED (1) - Output is Open Drain. // SPEED [7:6] - Speed Field Reset: 100MHZ // TBD (0) - TBD // 50MHZ (1) - Low (50 MHz) // 100MHZ (2) - Medium (100 MHz) // 200MHZ (3) - Maximum (200 MHz) // DSE [5:3] - Drive Strength Field Reset: 40_OHM // HIZ (0) - HI-Z // 240_OHM (1) - 240 Ohm // 120_OHM (2) - 120 Ohm // 80_OHM (3) - 80 Ohm // 60_OHM (4) - 60 Ohm // 48_OHM (5) - 48 Ohm // 40_OHM (6) - 40 Ohm // 34_OHM (7) - 34 Ohm // SRE [0] - Slew Rate Field Reset: SLOW // Slew rate control. // SLOW (0) - Slow Slew Rate // FAST (1) - Fast Slew Rate HW_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_WR( BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_HYS_V(ENABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_PUS_V(100K_OHM_PU) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_PUE_V(PULL) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_PKE_V(ENABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_ODE_V(DISABLED) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_SPEED_V(100MHZ) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_DSE_V(40_OHM) | BF_IOMUXC_SW_PAD_CTL_PAD_CSI0_DATA08_SRE_V(SLOW)); // Pad CSI0_DATA08 is involved in Daisy Chain. // Input Select Register: // IOMUXC_I2C1_SDA_IN_SELECT_INPUT(0x020E089C) // DAISY [0] - MUX Mode Select Field Reset: EIM_DATA28_ALT1 // Selecting Pads Involved in Daisy Chain. // EIM_DATA28_ALT1 (0) - Select signal i2c1 I2C1_SDA as input from pad EIM_DATA28(ALT1). // CSI0_DATA08_ALT4 (1) - Select signal i2c1 I2C1_SDA as input from pad CSI0_DATA08(ALT4). HW_IOMUXC_I2C1_SDA_IN_SELECT_INPUT_WR( BF_IOMUXC_I2C1_SDA_IN_SELECT_INPUT_DAISY_V(CSI0_DATA08_ALT4)); }
e961f84244116eea53ccfbf1610ea976e15f81f8
0853493263443e3493d5d359576f71fc7b1d509c
/contrib/curl/lib/share.c
5b3957fcfb16c000fa92d749ce27e4768285425e
[ "BSD-3-Clause" ]
permissive
premake/premake-core
2480471ed07868913533b045b7d7db7d9630e8ba
7b309649ce08cb40f4947d6952fb554c94f8cff6
refs/heads/master
2023-09-01T07:23:53.970594
2023-08-30T19:06:18
2023-08-30T19:06:18
32,634,405
3,160
944
BSD-3-Clause
2023-09-09T23:25:44
2015-03-21T14:08:15
C
UTF-8
C
false
false
5,970
c
share.c
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ #include "curl_setup.h" #include <curl/curl.h> #include "urldata.h" #include "share.h" #include "vtls/vtls.h" #include "curl_memory.h" /* The last #include file should be: */ #include "memdebug.h" struct Curl_share * curl_share_init(void) { struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); if(share) { share->specifier |= (1<<CURL_LOCK_DATA_SHARE); if(Curl_mk_dnscache(&share->hostcache)) { free(share); return NULL; } } return share; } #undef curl_share_setopt CURLSHcode curl_share_setopt(struct Curl_share *share, CURLSHoption option, ...) { va_list param; int type; curl_lock_function lockfunc; curl_unlock_function unlockfunc; void *ptr; CURLSHcode res = CURLSHE_OK; if(share->dirty) /* don't allow setting options while one or more handles are already using this share */ return CURLSHE_IN_USE; va_start(param, option); switch(option) { case CURLSHOPT_SHARE: /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<<type); switch(type) { case CURL_LOCK_DATA_DNS: break; case CURL_LOCK_DATA_COOKIE: #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(!share->cookies) { share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE); if(!share->cookies) res = CURLSHE_NOMEM; } #else /* CURL_DISABLE_HTTP */ res = CURLSHE_NOT_BUILT_IN; #endif break; case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL if(!share->sslsession) { share->max_ssl_sessions = 8; share->sslsession = calloc(share->max_ssl_sessions, sizeof(struct curl_ssl_session)); share->sessionage = 0; if(!share->sslsession) res = CURLSHE_NOMEM; } #else res = CURLSHE_NOT_BUILT_IN; #endif break; case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */ break; default: res = CURLSHE_BAD_OPTION; } break; case CURLSHOPT_UNSHARE: /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<<type); switch(type) { case CURL_LOCK_DATA_DNS: break; case CURL_LOCK_DATA_COOKIE: #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(share->cookies) { Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } #else /* CURL_DISABLE_HTTP */ res = CURLSHE_NOT_BUILT_IN; #endif break; case CURL_LOCK_DATA_SSL_SESSION: #ifdef USE_SSL Curl_safefree(share->sslsession); #else res = CURLSHE_NOT_BUILT_IN; #endif break; case CURL_LOCK_DATA_CONNECT: break; default: res = CURLSHE_BAD_OPTION; break; } break; case CURLSHOPT_LOCKFUNC: lockfunc = va_arg(param, curl_lock_function); share->lockfunc = lockfunc; break; case CURLSHOPT_UNLOCKFUNC: unlockfunc = va_arg(param, curl_unlock_function); share->unlockfunc = unlockfunc; break; case CURLSHOPT_USERDATA: ptr = va_arg(param, void *); share->clientdata = ptr; break; default: res = CURLSHE_BAD_OPTION; break; } va_end(param); return res; } CURLSHcode curl_share_cleanup(struct Curl_share *share) { if(share == NULL) return CURLSHE_INVALID; if(share->lockfunc) share->lockfunc(NULL, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE, share->clientdata); if(share->dirty) { if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); return CURLSHE_IN_USE; } Curl_hash_destroy(&share->hostcache); #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) Curl_cookie_cleanup(share->cookies); #endif #ifdef USE_SSL if(share->sslsession) { size_t i; for(i = 0; i < share->max_ssl_sessions; i++) Curl_ssl_kill_session(&(share->sslsession[i])); free(share->sslsession); } #endif if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); free(share); return CURLSHE_OK; } CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type, curl_lock_access accesstype) { struct Curl_share *share = data->share; if(share == NULL) return CURLSHE_INVALID; if(share->specifier & (1<<type)) { if(share->lockfunc) /* only call this if set! */ share->lockfunc(data, type, accesstype, share->clientdata); } /* else if we don't share this, pretend successful lock */ return CURLSHE_OK; } CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type) { struct Curl_share *share = data->share; if(share == NULL) return CURLSHE_INVALID; if(share->specifier & (1<<type)) { if(share->unlockfunc) /* only call this if set! */ share->unlockfunc (data, type, share->clientdata); } return CURLSHE_OK; }
fbf73a13ca26ed44031559f7a8c65a6f7d84a1f6
b33394c69589d95e38530fa80c74cf796ba6a5af
/felix/bpf-gpl/tc_preamble.c
5ec06c081e22260196a180970254ef951505422d
[ "GPL-1.0-or-later", "GPL-2.0-only", "Apache-2.0", "GPL-2.0-or-later", "LicenseRef-scancode-unknown-license-reference" ]
permissive
projectcalico/calico
3212e99d951dd17a50d95ec585676d525eae26ec
b494be8fc7d135034a482322119d6d9f1bbf9c0f
refs/heads/master
2023-08-29T21:50:21.982251
2023-08-29T09:31:32
2023-08-29T09:31:32
63,882,194
5,115
1,407
Apache-2.0
2023-09-14T18:55:43
2016-07-21T15:45:54
Go
UTF-8
C
false
false
2,907
c
tc_preamble.c
// Project Calico BPF dataplane programs. // Copyright (c) 2023 Tigera, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later // stdbool.h has no deps so it's OK to include; stdint.h pulls in parts // of the std lib that aren't compatible with BPF. #include <stdbool.h> #include "bpf.h" #include "types.h" #include "globals.h" #include "jump.h" #include "log.h" const volatile struct cali_tc_globals __globals; #ifdef IPVER6 #define IPV " v6" #define JUMP_IDX(idx) (idx ## _V6) #define JUMP_IDX_DEBUG(idx) (idx ## _V6_DEBUG) #else #define IPV " v4" #define JUMP_IDX(idx) (idx) #define JUMP_IDX_DEBUG(idx) (idx ## _DEBUG) #endif #define JUMP(idx) globals->jumps[JUMP_IDX(idx)] #define JUMP_DEBUG(idx) globals->jumps[JUMP_IDX_DEBUG(idx)] SEC("tc") int cali_tc_preamble(struct __sk_buff *skb) { volatile struct cali_tc_globals *globals = state_get_globals_tc(); if (!globals) { return TC_ACT_SHOT; } /* Set the globals for the rest of the prog chain. */ *globals = __globals; #if EMIT_LOGS CALI_LOG("tc_preamble" IPV " iface %s\n", globals->iface_name); #endif /* If we have log filter installed, tell the filter where to jump next * and jump to the filter. */ if (globals->log_filter_jmp != (__u32)-1) { skb->cb[0] = JUMP(PROG_INDEX_MAIN); skb->cb[1] = JUMP_DEBUG(PROG_INDEX_MAIN); bpf_tail_call(skb, &cali_jump_prog_map, globals->log_filter_jmp); CALI_LOG("tc_preamble" IPV " iface %s failed to call log filter %d\n", globals->iface_name, globals->log_filter_jmp); /* try to jump to the regular path */ } /* Jump to the start of the prog chain. */ #if EMIT_LOGS CALI_LOG("tc_preamble" IPV " iface %s jump to %d\n", globals->iface_name, JUMP(PROG_INDEX_MAIN)); #endif bpf_tail_call(skb, &cali_jump_map, JUMP(PROG_INDEX_MAIN)); CALI_LOG("tc_preamble" IPV " iface %s failed to call main %d\n", globals->iface_name, JUMP(PROG_INDEX_MAIN)); /* Try debug path in the unexpected case of not being able to make the jump. */ CALI_LOG("tc_preamble" IPV " iface %s jump to %d\n", globals->iface_name, JUMP_DEBUG(PROG_INDEX_MAIN)); bpf_tail_call(skb, &cali_jump_map, JUMP_DEBUG(PROG_INDEX_MAIN)); CALI_LOG("tc_preamble" IPV " iface %s failed to call debug main %d\n", globals->iface_name, JUMP_DEBUG(PROG_INDEX_MAIN)); /* Drop the packet in the unexpected case of not being able to make the jump. */ CALI_LOG("tc_preamble" IPV " iface %s failed to call main %d\n", globals->iface_name, JUMP(PROG_INDEX_MAIN)); return TC_ACT_SHOT; } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-local-typedef" #pragma clang diagnostic ignored "-Wunused" static CALI_BPF_INLINE void __compile_tc_asserts(void) { /* We store globals in the state map to pass them between programs, they must fit! */ COMPILE_TIME_ASSERT(sizeof(struct cali_tc_globals) < sizeof(struct cali_tc_state)) } #pragma clang diagnostic pop
704a6b02afb1b48bf38f20a8ff4d5fb7e5d40217
fbef550c1f0206aac0582a58f7e3db945f442a9a
/Pods/Headers/Private/MIKMIDI/MIKMIDIMetaEvent_SubclassMethods.h
0c42dfa7462ceab00f43f89d91007298ba82e00d
[ "MIT" ]
permissive
Hammerspoon/hammerspoon
0f03b4dd2ef3b44ea4c0a1cd0b94fcb513b5f2b7
0ccc9d07641a660140d1d2f05b76f682b501a0e8
refs/heads/master
2023-08-19T01:26:41.898873
2023-06-20T22:52:50
2023-06-20T22:52:50
24,956,772
11,379
676
MIT
2023-06-09T02:51:33
2014-10-08T19:24:44
Objective-C
UTF-8
C
false
false
58
h
MIKMIDIMetaEvent_SubclassMethods.h
../../../MIKMIDI/Source/MIKMIDIMetaEvent_SubclassMethods.h
803bfa1da42538cdfcf10b16715abf059ff25bbc
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/lpc408x/Libraries/Drivers/source/lpc_rtc.c
9dd34b72285109425cd1789cde22f3e1273315dd
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
36,784
c
lpc_rtc.c
/********************************************************************** * $Id$ lpc_rtc.c 2011-06-02 *//** * @file lpc_rtc.c * @brief Contains all functions support for RTC firmware library * on LPC * @version 1.0 * @date 02. June. 2011 * @author NXP MCU SW Application Team * * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * *********************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. * Permission to use, copy, modify, and distribute this software and its * documentation is hereby granted, under NXP Semiconductors' * relevant copyright in the software, without fee, provided that it * is used in conjunction with NXP Semiconductors microcontrollers. This * copyright, permission, and disclaimer notice must appear in all copies of * this code. **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ /** @addtogroup RTC * @{ */ #ifdef __BUILD_WITH_EXAMPLE__ #include "lpc_libcfg.h" #else #include "lpc_libcfg_default.h" #endif /* __BUILD_WITH_EXAMPLE__ */ #ifdef _RTC /* Includes ------------------------------------------------------------------- */ #include "lpc_rtc.h" #include "lpc_clkpwr.h" /* Public Functions ----------------------------------------------------------- */ /** @addtogroup RTC_Public_Functions * @{ */ /********************************************************************//** * @brief Initializes the RTC peripheral. * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @return None *********************************************************************/ void RTC_Init (LPC_RTC_TypeDef *RTCx) { /* Set up clock and power for RTC module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE); // Clear all register to be default RTCx->ILR = 0x00; RTCx->CCR = 0x00; RTCx->CIIR = 0x00; RTCx->AMR = 0xFF; RTCx->CALIBRATION = 0x00; } /*********************************************************************//** * @brief De-initializes the RTC peripheral registers to their * default reset values. * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @return None **********************************************************************/ void RTC_DeInit(LPC_RTC_TypeDef *RTCx) { RTCx->CCR = 0x00; // Disable power and clock for RTC module CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, DISABLE); } /*********************************************************************//** * @brief Reset clock tick counter in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @return None **********************************************************************/ void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx) { RTCx->CCR |= RTC_CCR_CTCRST; RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK; } /*********************************************************************//** * @brief Start/Stop RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] NewState New State of this function, should be: * - ENABLE: The time counters are enabled * - DISABLE: The time counters are disabled * @return None **********************************************************************/ void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState) { if (NewState == ENABLE) { RTCx->CCR |= RTC_CCR_CLKEN; } else { RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK; } } /*********************************************************************//** * @brief Enable/Disable Counter increment interrupt for each time type * in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] CntIncrIntType: Counter Increment Interrupt type, * an increment of this type value below will generates * an interrupt, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @param[in] NewState New State of this function, should be: * - ENABLE: Counter Increment interrupt for this * time type are enabled * - DISABLE: Counter Increment interrupt for this * time type are disabled * @return None **********************************************************************/ void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \ FunctionalState NewState) { if (NewState == ENABLE) { switch (CntIncrIntType) { case RTC_TIMETYPE_SECOND: RTCx->CIIR |= RTC_CIIR_IMSEC; break; case RTC_TIMETYPE_MINUTE: RTCx->CIIR |= RTC_CIIR_IMMIN; break; case RTC_TIMETYPE_HOUR: RTCx->CIIR |= RTC_CIIR_IMHOUR; break; case RTC_TIMETYPE_DAYOFWEEK: RTCx->CIIR |= RTC_CIIR_IMDOW; break; case RTC_TIMETYPE_DAYOFMONTH: RTCx->CIIR |= RTC_CIIR_IMDOM; break; case RTC_TIMETYPE_DAYOFYEAR: RTCx->CIIR |= RTC_CIIR_IMDOY; break; case RTC_TIMETYPE_MONTH: RTCx->CIIR |= RTC_CIIR_IMMON; break; case RTC_TIMETYPE_YEAR: RTCx->CIIR |= RTC_CIIR_IMYEAR; break; } } else { switch (CntIncrIntType) { case RTC_TIMETYPE_SECOND: RTCx->CIIR &= (~RTC_CIIR_IMSEC) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_MINUTE: RTCx->CIIR &= (~RTC_CIIR_IMMIN) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_HOUR: RTCx->CIIR &= (~RTC_CIIR_IMHOUR) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_DAYOFWEEK: RTCx->CIIR &= (~RTC_CIIR_IMDOW) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_DAYOFMONTH: RTCx->CIIR &= (~RTC_CIIR_IMDOM) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_DAYOFYEAR: RTCx->CIIR &= (~RTC_CIIR_IMDOY) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_MONTH: RTCx->CIIR &= (~RTC_CIIR_IMMON) & RTC_CIIR_BITMASK; break; case RTC_TIMETYPE_YEAR: RTCx->CIIR &= (~RTC_CIIR_IMYEAR) & RTC_CIIR_BITMASK; break; } } } /*********************************************************************//** * @brief Enable/Disable Alarm interrupt for each time type * in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] AlarmTimeType: Alarm Time Interrupt type, * an matching of this type value below with current time * in RTC will generates an interrupt, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @param[in] NewState New State of this function, should be: * - ENABLE: Alarm interrupt for this * time type are enabled * - DISABLE: Alarm interrupt for this * time type are disabled * @return None **********************************************************************/ void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \ FunctionalState NewState) { if (NewState == ENABLE) { switch (AlarmTimeType) { case RTC_TIMETYPE_SECOND: RTCx->AMR &= (~RTC_AMR_AMRSEC) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_MINUTE: RTCx->AMR &= (~RTC_AMR_AMRMIN) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_HOUR: RTCx->AMR &= (~RTC_AMR_AMRHOUR) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_DAYOFWEEK: RTCx->AMR &= (~RTC_AMR_AMRDOW) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_DAYOFMONTH: RTCx->AMR &= (~RTC_AMR_AMRDOM) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_DAYOFYEAR: RTCx->AMR &= (~RTC_AMR_AMRDOY) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_MONTH: RTCx->AMR &= (~RTC_AMR_AMRMON) & RTC_AMR_BITMASK; break; case RTC_TIMETYPE_YEAR: RTCx->AMR &= (~RTC_AMR_AMRYEAR) & RTC_AMR_BITMASK; break; } } else { switch (AlarmTimeType) { case RTC_TIMETYPE_SECOND: RTCx->AMR |= (RTC_AMR_AMRSEC); break; case RTC_TIMETYPE_MINUTE: RTCx->AMR |= (RTC_AMR_AMRMIN); break; case RTC_TIMETYPE_HOUR: RTCx->AMR |= (RTC_AMR_AMRHOUR); break; case RTC_TIMETYPE_DAYOFWEEK: RTCx->AMR |= (RTC_AMR_AMRDOW); break; case RTC_TIMETYPE_DAYOFMONTH: RTCx->AMR |= (RTC_AMR_AMRDOM); break; case RTC_TIMETYPE_DAYOFYEAR: RTCx->AMR |= (RTC_AMR_AMRDOY); break; case RTC_TIMETYPE_MONTH: RTCx->AMR |= (RTC_AMR_AMRMON); break; case RTC_TIMETYPE_YEAR: RTCx->AMR |= (RTC_AMR_AMRYEAR); break; } } } /*********************************************************************//** * @brief Set current time value for each time type in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Timetype: Time Type, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @param[in] TimeValue Time value to set * @return None **********************************************************************/ void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue) { switch ( Timetype) { case RTC_TIMETYPE_SECOND: if(TimeValue <= RTC_SECOND_MAX) RTCx->SEC = TimeValue & RTC_SEC_MASK; break; case RTC_TIMETYPE_MINUTE: if(TimeValue <= RTC_MINUTE_MAX) RTCx->MIN = TimeValue & RTC_MIN_MASK; break; case RTC_TIMETYPE_HOUR: if(TimeValue <= RTC_HOUR_MAX) RTCx->HOUR = TimeValue & RTC_HOUR_MASK; break; case RTC_TIMETYPE_DAYOFWEEK: if(TimeValue <= RTC_DAYOFWEEK_MAX) RTCx->DOW = TimeValue & RTC_DOW_MASK; break; case RTC_TIMETYPE_DAYOFMONTH: if((TimeValue >= RTC_DAYOFMONTH_MIN)&&(TimeValue <= RTC_DAYOFMONTH_MAX)) RTCx->DOM = TimeValue & RTC_DOM_MASK; break; case RTC_TIMETYPE_DAYOFYEAR: if((TimeValue >= RTC_DAYOFYEAR_MIN)&&(TimeValue <= RTC_DAYOFYEAR_MAX)) RTCx->DOY = TimeValue & RTC_DOY_MASK; break; case RTC_TIMETYPE_MONTH: if((TimeValue >= RTC_MONTH_MIN)&&(TimeValue <= RTC_MONTH_MAX)) RTCx->MONTH = TimeValue & RTC_MONTH_MASK; break; case RTC_TIMETYPE_YEAR: if(TimeValue <= RTC_YEAR_MAX) RTCx->YEAR = TimeValue & RTC_YEAR_MASK; break; } } /*********************************************************************//** * @brief Get current time value for each type time type * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Timetype: Time Type, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @return Value of time according to specified time type **********************************************************************/ uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype) { switch (Timetype) { case RTC_TIMETYPE_SECOND: return (RTCx->SEC & RTC_SEC_MASK); case RTC_TIMETYPE_MINUTE: return (RTCx->MIN & RTC_MIN_MASK); case RTC_TIMETYPE_HOUR: return (RTCx->HOUR & RTC_HOUR_MASK); case RTC_TIMETYPE_DAYOFWEEK: return (RTCx->DOW & RTC_DOW_MASK); case RTC_TIMETYPE_DAYOFMONTH: return (RTCx->DOM & RTC_DOM_MASK); case RTC_TIMETYPE_DAYOFYEAR: return (RTCx->DOY & RTC_DOY_MASK); case RTC_TIMETYPE_MONTH: return (RTCx->MONTH & RTC_MONTH_MASK); case RTC_TIMETYPE_YEAR: return (RTCx->YEAR & RTC_YEAR_MASK); default: return (0); } } /*********************************************************************//** * @brief Set full of time in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that * contains time value in full. * @return None **********************************************************************/ void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) { RTCx->DOM = pFullTime->DOM & RTC_DOM_MASK; RTCx->DOW = pFullTime->DOW & RTC_DOW_MASK; RTCx->DOY = pFullTime->DOY & RTC_DOY_MASK; RTCx->HOUR = pFullTime->HOUR & RTC_HOUR_MASK; RTCx->MIN = pFullTime->MIN & RTC_MIN_MASK; RTCx->SEC = pFullTime->SEC & RTC_SEC_MASK; RTCx->MONTH = pFullTime->MONTH & RTC_MONTH_MASK; RTCx->YEAR = pFullTime->YEAR & RTC_YEAR_MASK; } /*********************************************************************//** * @brief Get full of time in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that * will be stored time in full. * @return None **********************************************************************/ void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) { pFullTime->DOM = RTCx->DOM & RTC_DOM_MASK; pFullTime->DOW = RTCx->DOW & RTC_DOW_MASK; pFullTime->DOY = RTCx->DOY & RTC_DOY_MASK; pFullTime->HOUR = RTCx->HOUR & RTC_HOUR_MASK; pFullTime->MIN = RTCx->MIN & RTC_MIN_MASK; pFullTime->SEC = RTCx->SEC & RTC_SEC_MASK; pFullTime->MONTH = RTCx->MONTH & RTC_MONTH_MASK; pFullTime->YEAR = RTCx->YEAR & RTC_YEAR_MASK; } /*********************************************************************//** * @brief Set alarm time value for each time type * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Timetype: Time Type, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @param[in] ALValue Alarm time value to set * @return None **********************************************************************/ void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue) { switch (Timetype) { case RTC_TIMETYPE_SECOND: if(ALValue <= RTC_SECOND_MAX) RTCx->ALSEC = ALValue & RTC_SEC_MASK; break; case RTC_TIMETYPE_MINUTE: if(ALValue <= RTC_MINUTE_MAX) RTCx->ALMIN = ALValue & RTC_MIN_MASK; break; case RTC_TIMETYPE_HOUR: if(ALValue <= RTC_HOUR_MAX) RTCx->ALHOUR = ALValue & RTC_HOUR_MASK; break; case RTC_TIMETYPE_DAYOFWEEK: if(ALValue <= RTC_DAYOFWEEK_MAX) RTCx->ALDOW = ALValue & RTC_DOW_MASK; break; case RTC_TIMETYPE_DAYOFMONTH: if((ALValue >= RTC_DAYOFMONTH_MIN)&&(ALValue <= RTC_DAYOFMONTH_MAX)) RTCx->ALDOM = ALValue & RTC_DOM_MASK; break; case RTC_TIMETYPE_DAYOFYEAR: if((ALValue >= RTC_DAYOFYEAR_MIN)&&(ALValue <= RTC_DAYOFYEAR_MAX)) RTCx->ALDOY = ALValue & RTC_DOY_MASK; break; case RTC_TIMETYPE_MONTH: if((ALValue >= RTC_MONTH_MIN)&&(ALValue <= RTC_MONTH_MAX)) RTCx->ALMON = ALValue & RTC_MONTH_MASK; break; case RTC_TIMETYPE_YEAR: if(ALValue <= RTC_YEAR_MAX) RTCx->ALYEAR = ALValue & RTC_YEAR_MASK; break; } } /*********************************************************************//** * @brief Get alarm time value for each time type * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Timetype: Time Type, should be: * - RTC_TIMETYPE_SECOND * - RTC_TIMETYPE_MINUTE * - RTC_TIMETYPE_HOUR * - RTC_TIMETYPE_DAYOFWEEK * - RTC_TIMETYPE_DAYOFMONTH * - RTC_TIMETYPE_DAYOFYEAR * - RTC_TIMETYPE_MONTH * - RTC_TIMETYPE_YEAR * @return Value of Alarm time according to specified time type **********************************************************************/ uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype) { switch (Timetype) { case RTC_TIMETYPE_SECOND: return (RTCx->ALSEC & RTC_SEC_MASK); case RTC_TIMETYPE_MINUTE: return (RTCx->ALMIN & RTC_MIN_MASK); case RTC_TIMETYPE_HOUR: return (RTCx->ALHOUR & RTC_HOUR_MASK); case RTC_TIMETYPE_DAYOFWEEK: return (RTCx->ALDOW & RTC_DOW_MASK); case RTC_TIMETYPE_DAYOFMONTH: return (RTCx->ALDOM & RTC_DOM_MASK); case RTC_TIMETYPE_DAYOFYEAR: return (RTCx->ALDOY & RTC_DOY_MASK); case RTC_TIMETYPE_MONTH: return (RTCx->ALMON & RTC_MONTH_MASK); case RTC_TIMETYPE_YEAR: return (RTCx->ALYEAR & RTC_YEAR_MASK); default: return (0); } } /*********************************************************************//** * @brief Set full of alarm time in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that * contains alarm time value in full. * @return None **********************************************************************/ void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) { RTCx->ALDOM = pFullTime->DOM & RTC_DOM_MASK; RTCx->ALDOW = pFullTime->DOW & RTC_DOW_MASK; RTCx->ALDOY = pFullTime->DOY & RTC_DOY_MASK; RTCx->ALHOUR = pFullTime->HOUR & RTC_HOUR_MASK; RTCx->ALMIN = pFullTime->MIN & RTC_MIN_MASK; RTCx->ALSEC = pFullTime->SEC & RTC_SEC_MASK; RTCx->ALMON = pFullTime->MONTH & RTC_MONTH_MASK; RTCx->ALYEAR = pFullTime->YEAR & RTC_YEAR_MASK; } /*********************************************************************//** * @brief Get full of alarm time in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that * will be stored alarm time in full. * @return None **********************************************************************/ void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime) { pFullTime->DOM = RTCx->ALDOM & RTC_DOM_MASK; pFullTime->DOW = RTCx->ALDOW & RTC_DOW_MASK; pFullTime->DOY = RTCx->ALDOY & RTC_DOY_MASK; pFullTime->HOUR = RTCx->ALHOUR & RTC_HOUR_MASK; pFullTime->MIN = RTCx->ALMIN & RTC_MIN_MASK; pFullTime->SEC = RTCx->ALSEC & RTC_SEC_MASK; pFullTime->MONTH = RTCx->ALMON & RTC_MONTH_MASK; pFullTime->YEAR = RTCx->ALYEAR & RTC_YEAR_MASK; } /*********************************************************************//** * @brief Check whether if specified Location interrupt in * RTC peripheral is set or not * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] IntType Interrupt location type, should be: * - RTC_INT_COUNTER_INCREASE: Counter Increment Interrupt * block generated an interrupt. * - RTC_INT_ALARM: Alarm generated an * interrupt. * @return New state of specified Location interrupt in RTC peripheral * (SET or RESET) **********************************************************************/ IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) { return ((RTCx->ILR & IntType) ? SET : RESET); } /*********************************************************************//** * @brief Clear specified Location interrupt pending in * RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] IntType Interrupt location type, should be: * - RTC_INT_COUNTER_INCREASE: Clear Counter Increment * Interrupt pending. * - RTC_INT_ALARM: Clear alarm interrupt pending * @return None **********************************************************************/ void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType) { RTCx->ILR |= IntType; } /*********************************************************************//** * @brief Enable/Disable calibration counter in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] NewState New State of this function, should be: * - ENABLE: The calibration counter is enabled and counting * - DISABLE: The calibration counter is disabled and reset to zero * @return None **********************************************************************/ void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState) { if (NewState == ENABLE) { RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK; } else { RTCx->CCR |= RTC_CCR_CCALEN; } } /*********************************************************************//** * @brief Configures Calibration in RTC peripheral * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] CalibValue Calibration value, should be in range from * 0 to 131,072 * @param[in] CalibDir Calibration Direction, should be: * - RTC_CALIB_DIR_FORWARD: Forward calibration * - RTC_CALIB_DIR_BACKWARD: Backward calibration * @return None **********************************************************************/ void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir) { RTCx->CALIBRATION = ((CalibValue) & RTC_CALIBRATION_CALVAL_MASK) \ | ((CalibDir == RTC_CALIB_DIR_BACKWARD) ? RTC_CALIBRATION_LIBDIR : 0); } /*********************************************************************//** * @brief Write value to General purpose registers * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Channel General purpose registers Channel number, * should be in range from 0 to 4. * @param[in] Value Value to write * @return None * Note: These General purpose registers can be used to store important * information when the main power supply is off. The value in these * registers is not affected by chip reset. **********************************************************************/ void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value) { uint32_t *preg; preg = (uint32_t *)&RTCx->GPREG0; preg += Channel; *preg = Value; } /*********************************************************************//** * @brief Read value from General purpose registers * @param[in] RTCx RTC peripheral selected, should be LPC_RTC * @param[in] Channel General purpose registers Channel number, * should be in range from 0 to 4. * @return Read Value * Note: These General purpose registers can be used to store important * information when the main power supply is off. The value in these * registers is not affected by chip reset. **********************************************************************/ uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel) { uint32_t *preg; uint32_t value; preg = (uint32_t *)&RTCx->GPREG0; preg += Channel; value = *preg; return (value); } /*********************************************************************//** * @brief Initialize an variable of type RTC_ER_CONFIG_Type. * @param[in] pConfig The address of input variable. * @return None **********************************************************************/ void RTC_ER_InitConfigStruct(RTC_ER_CONFIG_Type* pConfig) { uint32_t tmp; if(pConfig == NULL) return; for(tmp = 0; tmp < RTC_ER_INPUT_CHANNEL_NUM; tmp++) { pConfig->InputChannel[tmp].EventOnPosEdge = FALSE; pConfig->InputChannel[tmp].GPClear= FALSE; pConfig->InputChannel[tmp].IntWake= FALSE; } pConfig->Clk = 64; } /*********************************************************************//** * @brief Initialize Event Monitor/Recorder * @param[in] pConfig Configuration * @return SUCCESS/ERROR * Note: The RTC Module must be intialized before initializing this module. **********************************************************************/ Status RTC_ER_Init(RTC_ER_CONFIG_Type* pConfig) { if(pConfig == NULL) return ERROR; if((LPC_RTC->CCR & RTC_CCR_CLKEN) == 0) return ERROR; /* EV0 */ if(pConfig->InputChannel[0].EventOnPosEdge) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_POS_EDGE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_POS_EDGE; if(pConfig->InputChannel[0].IntWake) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_INTWAKE_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_INTWAKE_ENABLE; if(pConfig->InputChannel[0].GPClear) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_GPCLEAR_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_GPCLEAR_ENABLE; /* EV1 */ if(pConfig->InputChannel[1].EventOnPosEdge) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_POS_EDGE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_POS_EDGE; if(pConfig->InputChannel[1].IntWake) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_INTWAKE_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_INTWAKE_ENABLE; if(pConfig->InputChannel[1].GPClear) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_GPCLEAR_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_GPCLEAR_ENABLE; /* EV2 */ if(pConfig->InputChannel[2].EventOnPosEdge) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_POS_EDGE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_POS_EDGE; if(pConfig->InputChannel[2].IntWake) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_INTWAKE_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_INTWAKE_ENABLE; if(pConfig->InputChannel[2].GPClear) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_GPCLEAR_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_GPCLEAR_ENABLE; /* Sample Clock */ LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_MODE_MASK; switch(pConfig->Clk) { case 0: LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_CLK_DISABLE; break; case 16: LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_16HZ; break; case 64: LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_64HZ; break; case 1000: LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_1KHZ; break; default: return ERROR; } return SUCCESS; } /*********************************************************************//** * @brief Enable/Disable a input channel for Event Monitor/Recorder * @param[in] channel Channel Number. It should be 0~2 * @param[in]state ENABLE/DISABLE * @return SUCCESS/ERROR **********************************************************************/ Status RTC_ER_Cmd(uint8_t channel, FunctionalState state) { switch(channel) { case 0: if(state) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_INPUT_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_INPUT_ENABLE; break; case 1: if(state) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_INPUT_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_INPUT_ENABLE; break; case 2: if(state) LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_INPUT_ENABLE; else LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_INPUT_ENABLE; break; default: return ERROR; } return SUCCESS; } /*********************************************************************//** * @brief Get event count on a given channel. * @param[in] channel Channel Number. It should be 0~2 * @return counter **********************************************************************/ uint8_t RTC_ER_GetEventCount(uint8_t channel) { uint8_t count = 0; switch(channel) { case 0: count = RTC_ER_EV0_COUNTER(LPC_RTC->ERCOUNTERS); break; case 1: count = RTC_ER_EV1_COUNTER(LPC_RTC->ERCOUNTERS); break; case 2: count = RTC_ER_EV2_COUNTER(LPC_RTC->ERCOUNTERS); break; default: break; } return count; } /*********************************************************************//** * @brief Get Event Monirot/Recorder Status. * @param[in] None * @return Status. It can includes: * RTC_ER_EVENTS_ON_EV0_FLG * RTC_ER_EVENTS_ON_EV1_FLG * RTC_ER_EVENTS_ON_EV2_FLG * RTC_ER_STATUS_GP_CLEARED_FLG * RTC_ER_STATUS_WAKEUP_REQ_PENDING **********************************************************************/ uint32_t RTC_ER_GetStatus(void) { return LPC_RTC->ERSTATUS; } /*********************************************************************//** * @brief Clear Event Monitor/recoder status register. * @param[in] status Status Flag. It should be: * RTC_ER_EVENTS_ON_EV0_FLG * RTC_ER_EVENTS_ON_EV1_FLG * RTC_ER_EVENTS_ON_EV2_FLG * RTC_ER_STATUS_GP_CLEARED_FLG * RTC_ER_STATUS_WAKEUP_REQ_PENDING * @return None **********************************************************************/ void RTC_ER_ClearStatus(uint32_t status) { LPC_RTC->ERSTATUS |= status; } /*********************************************************************//** * @brief Check whether a Wakup request is pending or not. * @param[in] None * @return TRUE/FALSE **********************************************************************/ Bool RTC_ER_WakupReqPending(void) { if(LPC_RTC->ERSTATUS & RTC_ER_STATUS_WAKEUP_REQ_PENDING) return TRUE; else return FALSE; } /*********************************************************************//** * @brief Check whether RTC General Purpose registed has been cleared or not. * @param[in] None * @return TRUE/FALSE **********************************************************************/ Bool RTC_ER_GPCleared(void) { if(LPC_RTC->ERSTATUS & RTC_ER_STATUS_GP_CLEARED_FLG) return TRUE; else return FALSE; } /*********************************************************************//** * @brief Get the timestamp of the fist event on a given channel. * @param[in] channel Channel number (It should be 0~2) * @param[in] pTimeStamp point to the buffer * @return SUCCESS/ERROR **********************************************************************/ Status RTC_ER_GetFirstTimeStamp(uint8_t channel, RTC_ER_TIMESTAMP_Type* pTimeStamp) { if(pTimeStamp == NULL) return ERROR; switch(channel) { case 0: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV0_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP0); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP0); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP0); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP0); break; case 1: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV1_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP1); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP1); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP1); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP1); break; case 2: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV2_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP2); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP2); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP2); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP2); break; default: break; } return SUCCESS; } /*********************************************************************//** * @brief Get the timestamp of the last event on a given channel. * @param[in] channel Channel number (It should be 0~2) * @param[in] pTimeStamp point to the buffer * @return SUCCESS/ERROR **********************************************************************/ Status RTC_ER_GetLastTimeStamp(uint8_t channel, RTC_ER_TIMESTAMP_Type* pTimeStamp) { if(pTimeStamp == NULL) return ERROR; switch(channel) { case 0: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV0_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP0); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP0); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP0); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP0); break; case 1: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV1_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP1); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP1); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP1); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP1); break; case 2: if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV2_BIT)) == 0) return ERROR; pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP2); pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP2); pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP2); pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP2); break; default: break; } return SUCCESS; } /** * @} */ #endif /*_RTC*/ /** * @} */ /* --------------------------------- End Of File ------------------------------ */
724d7fb9834d22a64b12836e0699aa9de22b292e
d05e1ee9d0ac33a0a4b4116dedda7a40609973ef
/CorradeStlMath.h
ce0d2aec5af5910171cb1c4dd28eb8a2b55e37e2
[ "MIT" ]
permissive
mosra/magnum-singles
5a13583292280f2c1c3b033ded0243c27368552b
a97ad80251a0614973d947ca5dd040c62adbf240
refs/heads/master
2022-10-25T20:25:08.036346
2022-10-18T08:00:11
2022-10-18T08:07:36
166,048,095
106
10
null
null
null
null
UTF-8
C
false
false
2,284
h
CorradeStlMath.h
/* Corrade's optimized <cmath>, without the heavy C++17 additions https://doc.magnum.graphics/corrade/StlMath_8h.html This is a single-header library generated from the Corrade project. With the goal being easy integration, it's deliberately free of all comments to keep the file size small. More info, detailed changelogs and docs here: - Project homepage — https://magnum.graphics/corrade/ - Documentation — https://doc.magnum.graphics/corrade/ - GitHub project page — https://github.com/mosra/corrade - GitHub Singles repository — https://github.com/mosra/magnum-singles v2019.01-186-gdd93f1f1 (2019-06-06) - Initial release Generated from Corrade v2020.06-0-g61d1b58c (2020-06-27), 57 / 3015 LoC */ /* This file is part of Corrade. Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Vladimír Vondruš <mosra@centrum.cz> 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 <ciso646> #ifndef Corrade_Utility_StlMath_h #define Corrade_Utility_StlMath_h #ifdef _GLIBCXX_USE_STD_SPEC_FUNCS #undef _GLIBCXX_USE_STD_SPEC_FUNCS #define _GLIBCXX_USE_STD_SPEC_FUNCS 0 #endif #include <cmath> #endif
bf0950574165732b9b0f50c453846775e07ee93c
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
/AKWF-c/AKWF_0012/AKWF_1163.h
3d575b31e8fb4913234425edf31bbb0aa3a2c140
[ "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,672
h
AKWF_1163.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_1163 256 samples +-----------------------------------------------------------------------------------------------------------------+ | *** *** | | ** * *********** | | ** ** *** * | | * * ** *** | |** * ** *** | |* ** ** **** | |* *** ** ** | |* ********** * ** | | * ** *** | | ** * * *| | ** ** * *| | ** * * * | | ***** *********** ** * | | ********* **** * * | | ************* *** | +-----------------------------------------------------------------------------------------------------------------+ */ const uint16_t AKWF_1163 [] = { 33801, 35667, 41588, 46439, 49332, 52466, 54647, 56872, 58467, 60025, 61141, 62211, 62988, 63691, 64210, 64637, 64963, 65188, 65371, 65455, 65531, 65470, 65334, 65175, 64971, 64794, 64524, 64368, 64023, 63928, 63477, 63518, 62839, 63361, 59907, 53971, 51646, 48763, 46739, 44678, 43087, 41619, 40407, 39374, 38447, 37734, 37034, 36562, 36042, 35746, 35371, 35194, 34935, 34836, 34674, 34619, 34540, 34495, 34499, 34436, 34529, 34407, 34630, 34339, 34949, 32150, 27890, 26279, 24165, 22770, 21276, 20192, 19128, 18311, 17570, 16965, 16467, 16028, 15711, 15397, 15214, 14997, 14910, 14763, 14745, 14651, 14677, 14626, 14680, 14660, 14726, 14734, 14803, 14833, 14897, 14945, 14997, 15063, 15099, 15185, 15200, 15302, 15298, 15414, 15388, 15520, 15476, 15617, 15558, 15702, 15637, 15778, 15714, 15841, 15794, 15889, 15878, 15918, 15981, 15901, 16154, 15717, 22219, 27944, 30586, 33981, 36206, 38650, 40379, 40706, 42586, 44608, 45498, 47472, 48633, 49828, 50593, 52477, 53869, 54865, 55773, 56492, 57128, 57616, 58052, 58369, 58643, 58824, 58972, 59057, 59115, 59133, 59128, 59099, 59050, 58986, 58917, 58822, 58750, 58624, 58574, 58396, 58416, 58139, 58393, 55819, 53136, 51905, 50407, 49340, 48279, 47426, 46681, 46007, 45504, 44969, 44653, 44223, 44052, 43695, 43665, 43122, 39829, 37912, 36571, 35238, 34198, 33281, 32407, 31998, 28237, 24461, 22709, 20445, 19027, 17396, 16337, 15165, 14394, 13571, 13019, 12466, 12076, 11724, 11455, 11254, 11069, 10978, 10854, 10841, 10761, 10799, 10752, 10821, 10800, 10883, 10885, 10968, 10991, 11061, 11106, 11154, 11229, 11240, 11356, 11299, 11537, 10557, 9374, 8861, 8278, 7820, 7435, 7062, 6811, 6523, 6385, 6173, 6107, 5962, 5896, 5915, 6341, 6542, 6816, 7104, 7306, 7706, 7756, 8406, 7920, 15024, 22201, 25023, 27596, 29556, };
29b081c98dc6036a3b2646fe3f65270db7335832
995c73cc45a35afe22229aac5e707c2406ef44a7
/sherlock.c
1d7477e0dbc7e048f87a01d3327fa54287a7953a
[ "Unlicense" ]
permissive
diogocabral/sherlock
2646991f310f0c0f0f85260537bedb76290aaddf
2299e4b123e986ce8d54121631e49b006e52af74
refs/heads/master
2022-05-28T12:20:15.326333
2022-05-13T02:19:02
2022-05-13T02:19:02
58,764,117
129
41
Unlicense
2022-05-13T02:19:03
2016-05-13T18:38:51
C
UTF-8
C
false
false
11,618
c
sherlock.c
/* * sherlock.c - written by Loki from Rob Pike's sig and comp programs. * * This program takes filenames given on the command line, * and reads those files into memory, then compares them * all pairwise to find those which are most similar. * * It uses a digital signature generation scheme to randomly * discard information, thus allowing a better match. * Essentially it hashes up N adjacent 'words' of input, * and semi-randomly throws away many of the hashed values * so that it become hard to hide the plagiarised text. */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <dirent.h> char* Progname = "sherlock"; int Ntoken = 3; int Zerobits = 4; unsigned long zeromask; int ntoken = 0; char** token; FILE* Outfile; int Thresh = 0; int Recursive = 0; char* fileextension = "c"; int nfiles = 0; char** filePath; /* characters to ignore at start and end of each word */ char* Ignore = " \t\n"; /* characters to treat as word-separators or words on their own */ char* Punct_full = ",.<>/?;:'\"`~[]{}\\|!@#$%^&*()-+_="; char* Punct = ""; typedef struct Sig Sig; struct Sig { int nval; unsigned long* val; }; void init_token_array(void); Sig* signature(FILE*); int compare(Sig*, Sig*); int endsWith(char*, char*); void usage(void) { fprintf(stderr, "%s: find similar files\n", Progname); fprintf(stderr, "usage: %s", Progname); fprintf(stderr, " [options] directory1 directory2 ...\n"); fprintf(stderr, "options:"); fprintf(stderr, " [-t threshold%%]"); fprintf(stderr, " [-z zerobits]"); fprintf(stderr, " [-n chainlength]"); fprintf(stderr, " [-e fileextension]"); fprintf(stderr, " [-r recursive]"); fprintf(stderr, " [-o outfile]"); fprintf(stderr, "\n"); fprintf(stderr, "defaults:"); fprintf(stderr, " threshold=0%%"); fprintf(stderr, " zerobits=3"); fprintf(stderr, " chainlength=4"); fprintf(stderr, " fileextension=c"); fprintf(stderr, " outfile=the screen"); fprintf(stderr, "\n"); exit(2); } int endsWith(char* word, char* suffix) { size_t wordLength = strlen(word); size_t suffixLength = strlen(suffix); if (wordLength < suffixLength) return 0; return strncmp(word + wordLength - suffixLength, suffix, suffixLength); } void listFiles(const char* name) { DIR* dir; struct dirent* entry; if (!(dir = opendir(name))) return; while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_DIR) { if (Recursive == 1) { int len; char* path; if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; len = strlen(name) + 2 + strlen(entry->d_name); path = malloc(len * sizeof(char)); sprintf(path, "%s/%s", name, entry->d_name); listFiles(path); free(path); } } else if (entry->d_type == DT_REG) { if (endsWith(entry->d_name, fileextension) != 0) continue; filePath[nfiles] = malloc((strlen(name) + 2 + strlen(entry->d_name)) * sizeof(char)); strcpy(filePath[nfiles], name); strcat(filePath[nfiles], "/"); strcat(filePath[nfiles], entry->d_name); nfiles++; if (nfiles % 1000 == 0) filePath = realloc(filePath, (nfiles + 1000) * sizeof(char*)); } } closedir(dir); } int main(int argc, char* argv[]) { FILE* f; int i, j, start, percent; char *s, *outname; Sig** sig; Outfile = stdout; outname = NULL; /* handle options */ for (start = 1; start < argc; start++) { if (argv[start][0] != '-') break; switch (argv[start][1]) { case 't': s = argv[++start]; if (s == NULL) usage(); Thresh = atoi(s); if (Thresh < 0 || Thresh > 100) usage(); break; case 'z': s = argv[++start]; if (s == NULL) usage(); Zerobits = atoi(s); if (Zerobits < 0 || Zerobits > 31) usage(); break; case 'n': s = argv[++start]; if (s == NULL) usage(); Ntoken = atoi(s); if (Ntoken <= 0) usage(); break; case 'e': s = argv[++start]; if (s == NULL) usage(); fileextension = s; break; case 'r': Recursive = 1; break; case 'o': s = argv[++start]; if (s == NULL) usage(); outname = s; break; default: usage(); } } nfiles = argc - start; if (nfiles < 1) usage(); /* initialise */ if (outname != NULL) Outfile = fopen(outname, "w"); init_token_array(); zeromask = (1 << Zerobits) - 1; nfiles = 0; filePath = malloc(1000 * sizeof(char*)); while (start < argc) listFiles(argv[start++]); /* shrink to smallest required space */ filePath = realloc(filePath, nfiles * sizeof(char*)); sig = malloc(nfiles * sizeof(Sig*)); /* generate signatures for each file */ for (i = 0; i < nfiles; i++) { f = fopen(filePath[i], "r"); if (f == NULL) { fprintf(stderr, "%s: can't open %s:", Progname, filePath[i]); perror(NULL); continue; } sig[i] = signature(f); fclose(f); } /* compare each signature pair-wise */ for (i = 0; i < nfiles; i++) for (j = i + 1; j < nfiles; j++) { percent = compare(sig[i], sig[j]); if (percent >= Thresh) fprintf(Outfile, "%s;%s;%d%%\n", filePath[i], filePath[j], percent); } for (i = 0; i < nfiles; i++) { free(filePath[i]); } free(filePath); return 0; } /* read_word: read a 'word' from the input, ignoring leading characters which are inside the 'ignore' string, and stopping if one of the 'ignore' or 'punct' characters is found. Uses memory allocation to avoid buffer overflow problems. */ char* read_word(FILE* f, int* length, char* ignore, char* punct) { long max; char* word; long pos; char* c; int ch, is_ignore, is_punct; /* check for EOF first */ if (feof(f)) { length = 0; return NULL; } /* allocate a buffer to hold the string */ pos = 0; max = 128; word = malloc(sizeof(char) * max); c = &word[pos]; /* initialise some defaults */ if (ignore == NULL) ignore = ""; if (punct == NULL) punct = ""; /* read characters into the buffer, resizing it if necessary */ while ((ch = getc(f)) != EOF) { is_ignore = (strchr(ignore, ch) != NULL); if (pos == 0) { if (is_ignore) /* ignorable char found at start, skip it */ continue; } if (is_ignore) /* ignorable char found after start, stop */ break; is_punct = (strchr(punct, ch) != NULL); if (is_punct && (pos > 0)) { ungetc(ch, f); break; } *c = ch; c++; pos++; if (is_punct) break; if (pos == max) { /* realloc buffer twice the size */ max += max; word = realloc(word, max); c = &word[pos]; } } /* set length and check for EOF condition */ *length = pos; if (pos == 0) { free(word); return NULL; } /* terminate the string and shrink to smallest required space */ *c = '\0'; word = realloc(word, pos + 1); return word; } /* ulcmp: compare *p1 and *p2 */ int ulcmp(const void* p1, const void* p2) { unsigned long v1, v2; v1 = *(unsigned long*)p1; v2 = *(unsigned long*)p2; if (v1 < v2) return -1; else if (v1 == v2) return 0; else return 1; } /* hash: hash an array of char* into an unsigned long hash code */ unsigned long hash(char* tok[]) { unsigned long h; unsigned char* s; int i; h = 0; for (i = 0; i < Ntoken; i++) for (s = (unsigned char*)tok[i]; *s; s++) h = h * 31 + *s; return h; } void init_token_array(void) { int i; /* create global array of char* and initialise all to NULL */ token = malloc(Ntoken * sizeof(char*)); for (i = 0; i < Ntoken; i++) token[i] = NULL; } Sig* signature(FILE* f) { int nv, na; unsigned long *v, h; char* str; int i, ntoken; Sig* sig; /* start loading hash values, after we have Ntoken of them */ v = NULL; na = 0; nv = 0; ntoken = 0; while ((str = read_word(f, &i, Ignore, Punct)) != NULL) { /* step words down by one */ free(token[0]); for (i = 0; i < Ntoken - 1; i++) token[i] = token[i + 1]; /* add new word into array */ token[Ntoken - 1] = str; /* if we don't yet have enough words in the array continue */ ntoken++; if (ntoken < Ntoken) continue; /* hash the array of words */ h = hash(token); if ((h & zeromask) != 0) continue; /* discard zeros from end of hash value */ h = h >> Zerobits; /* add value into the signature array, resizing if needed */ if (nv == na) { na += 100; v = realloc(v, na * sizeof(unsigned long)); } v[nv++] = h; } /* sort the array of hash values for speed */ qsort(v, nv, sizeof(v[0]), ulcmp); /* allocate and return the Sig structure for this file */ sig = malloc(sizeof(Sig)); sig->nval = nv; sig->val = v; return sig; } int compare(Sig* s0, Sig* s1) { int i0, i1, nboth, nsimilar; unsigned long v; i0 = 0; i1 = 0; nboth = 0; while (i0 < s0->nval && i1 < s1->nval) { if (s0->val[i0] == s1->val[i1]) { v = s0->val[i0]; while (i0 < s0->nval && v == s0->val[i0]) { i0++; nboth++; } while (i1 < s1->nval && v == s1->val[i1]) { i1++; nboth++; } continue; } if (s0->val[i0] < s1->val[i1]) i0++; else i1++; } if (s0->nval + s1->nval == 0) return 0; /* ignore if both are empty files */ if (s0->nval + s1->nval == nboth) return 100; /* perfect match if all hash codes match */ nsimilar = nboth / 2; return 100 * nsimilar / (s0->nval + s1->nval - nsimilar); } /* * Let f1 == filesize(file1) == A+B * and f2 == filesize(file2) == A+C * where A is the similar section and B or C are dissimilar * * Similarity = 100 * A / (f1 + f2 - A) * = 100 * A / (A+B + A+C - A) * = 100 * A / (A+B+C) * * Thus if A==B==C==n the similarity will be 33% (one third) * This is desireable since we are finding the ratio of similarities * as a fraction of (similarities+dissimilarities). * * The other way of doing things would be to find the ratio of * the sum of similarities as a fraction of total file size: * Similarity = 100 * (A+A) / (A+B + A+C) * This produces higher percentages and more false matches. */
254582ee60cf8b2c64e42f47e81f86be4d908bf0
4f61a7c9be8cd7a88ad8be13815d6ade244e7a5a
/llvm-hs/src/LLVM/Internal/FFI/Value.h
e494f401635df0f60b1e0c823726935a4dc9c593
[]
no_license
llvm-hs/llvm-hs
0386e5a6f599b449a6b8a1762011a4b01ae120a8
423220bffac4990d019fc088c46c5f25310d5a33
refs/heads/llvm-12
2023-08-16T13:42:14.414573
2022-10-11T13:29:07
2022-10-11T13:35:32
78,232,564
526
125
null
2023-07-30T07:59:58
2017-01-06T19:25:26
LLVM
UTF-8
C
false
false
768
h
Value.h
#ifndef __LLVM_INTERNAL_FFI__VALUE__H__ #define __LLVM_INTERNAL_FFI__VALUE__H__ #define LLVM_HS_FOR_EACH_VALUE_SUBCLASS(macro) \ macro(Argument) \ macro(BasicBlock) \ macro(Function) \ macro(GlobalAlias) \ macro(GlobalVariable) \ macro(UndefValue) \ macro(BlockAddress) \ macro(ConstantExpr) \ macro(ConstantAggregateZero) \ macro(ConstantDataArray) \ macro(ConstantDataVector) \ macro(ConstantInt) \ macro(ConstantFP) \ macro(ConstantArray) \ macro(ConstantStruct) \ macro(ConstantTokenNone) \ macro(ConstantVector) \ macro(ConstantPointerNull) \ macro(InlineAsm) \ macro(Instruction) typedef enum { #define ENUM_CASE(class) LLVM ## class ## SubclassId, LLVM_HS_FOR_EACH_VALUE_SUBCLASS(ENUM_CASE) #undef ENUM_CASE } LLVMValueSubclassId; #endif
6dbe0fe5e87cfd77427142695939a6d500a067bb
7df190df28da7e4ff166e55dc8ce780f11236a9f
/src/router/rtpproxy/src/rtpp_command.c
fdcc0676e7a772bb84d73916735060e8e37e3ece
[ "BSD-2-Clause" ]
permissive
mirror/dd-wrt
25416946e6132aa54b35809de61834a1825a9a36
8f2934a5a2adfbb59b471375aa3a38de5d036531
refs/heads/master
2023-08-31T14:54:47.496685
2023-08-30T17:40:54
2023-08-30T17:40:54
7,470,282
520
281
null
2023-05-29T20:56:24
2013-01-06T17:21:29
null
UTF-8
C
false
false
23,217
c
rtpp_command.c
/* * Copyright (c) 2004-2006 Maxim Sobolev <sobomax@FreeBSD.org> * Copyright (c) 2006-2014 Sippy Software, Inc., http://www.sippysoft.com * 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 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. * */ #if defined(HAVE_CONFIG_H) #include "config.h" #endif #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <assert.h> #include <errno.h> #include <fcntl.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "rtp.h" #include "rtpp_log.h" #include "rtpp_cfg_stable.h" #include "rtpp_defines.h" #include "rtpp_command.h" #include "rtpp_command_async.h" #include "rtpp_command_copy.h" #include "rtpp_command_parse.h" #include "rtpp_command_private.h" #include "rtpp_command_stats.h" #include "rtpp_command_ul.h" #include "rtpp_netio_async.h" #include "rtpp_network.h" #include "rtpp_notify.h" #include "rtpp_session.h" #include "rtp_server.h" #include "rtpp_util.h" #include "rtpp_types.h" #include "rtpp_stats.h" struct proto_cap proto_caps[] = { /* * The first entry must be basic protocol version and isn't shown * as extension on -v. */ { "20040107", "Basic RTP proxy functionality" }, { "20050322", "Support for multiple RTP streams and MOH" }, { "20060704", "Support for extra parameter in the V command" }, { "20071116", "Support for RTP re-packetization" }, { "20071218", "Support for forking (copying) RTP stream" }, { "20080403", "Support for RTP statistics querying" }, { "20081102", "Support for setting codecs in the update/lookup command" }, { "20081224", "Support for session timeout notifications" }, { "20090810", "Support for automatic bridging" }, { "20140323", "Support for tracking/reporting load" }, { "20140617", "Support for anchoring session connect time" }, { "20141004", "Support for extendable performance counters" }, { NULL, NULL } }; struct d_opts; static int create_twinlistener(struct rtpp_cfg_stable *, struct sockaddr *, int, int *); static int handle_delete(struct cfg *, struct common_cmd_args *, int); static void handle_noplay(struct cfg *, struct rtpp_session *, int, struct rtpp_command *); static int handle_play(struct cfg *, struct rtpp_session *, int, char *, char *, int, struct rtpp_command *); static int handle_record(struct cfg *, struct common_cmd_args *, int); static void handle_query(struct cfg *, struct rtpp_command *, struct rtpp_session *, int); static void handle_info(struct cfg *, struct rtpp_command *, const char *); static void handle_ver_feature(struct cfg *cf, struct rtpp_command *cmd); static int create_twinlistener(struct rtpp_cfg_stable *cf, struct sockaddr *ia, int port, int *fds) { struct sockaddr_storage iac; int rval, i, flags, so_rcvbuf; fds[0] = fds[1] = -1; rval = -1; for (i = 0; i < 2; i++) { fds[i] = socket(ia->sa_family, SOCK_DGRAM, 0); if (fds[i] == -1) { rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "can't create %s socket", (ia->sa_family == AF_INET) ? "IPv4" : "IPv6"); goto failure; } memcpy(&iac, ia, SA_LEN(ia)); satosin(&iac)->sin_port = htons(port); if (bind(fds[i], sstosa(&iac), SA_LEN(ia)) != 0) { if (errno != EADDRINUSE && errno != EACCES) { rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "can't bind to the %s port %d", (ia->sa_family == AF_INET) ? "IPv4" : "IPv6", port); } else { rval = -2; } goto failure; } port++; if ((ia->sa_family == AF_INET) && (cf->tos >= 0) && (setsockopt(fds[i], IPPROTO_IP, IP_TOS, &cf->tos, sizeof(cf->tos)) == -1)) rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "unable to set TOS to %d", cf->tos); so_rcvbuf = 256 * 1024; if (setsockopt(fds[i], SOL_SOCKET, SO_RCVBUF, &so_rcvbuf, sizeof(so_rcvbuf)) == -1) rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "unable to set 256K receive buffer size"); flags = fcntl(fds[i], F_GETFL); fcntl(fds[i], F_SETFL, flags | O_NONBLOCK); } return 0; failure: for (i = 0; i < 2; i++) if (fds[i] != -1) { close(fds[i]); fds[i] = -1; } return rval; } int rtpp_create_listener(struct cfg *cf, struct sockaddr *ia, int *port, int *fds) { int i, idx, rval; for (i = 0; i < 2; i++) fds[i] = -1; for (i = 1; i < cf->stable->port_table_len; i++) { idx = (cf->port_table_idx + i) % cf->stable->port_table_len; *port = cf->stable->port_table[idx]; if (*port == cf->stable->port_ctl || *port == (cf->stable->port_ctl - 1)) continue; rval = create_twinlistener(cf->stable, ia, *port, fds); if (rval == 0) { cf->port_table_idx = idx; return 0; } if (rval == -1) break; } return -1; } void rtpc_doreply(struct cfg *cf, char *buf, int len, struct rtpp_command *cmd, int errd) { buf[len] = '\0'; rtpp_log_write(RTPP_LOG_DBUG, cf->stable->glog, "sending reply \"%s\"", buf); if (cmd->umode == 0) { write(cmd->controlfd, buf, len); } else { if (cmd->cookie != NULL) { len = snprintf(cmd->buf_r, sizeof(cmd->buf_r), "%s %s", cmd->cookie, buf); buf = cmd->buf_r; } rtpp_anetio_sendto(cf->stable->rtpp_netio_cf, cmd->controlfd, buf, len, 0, sstosa(&cmd->raddr), cmd->rlen); } cmd->csp->ncmds_repld.cnt++; if (errd == 0) { cmd->csp->ncmds_succd.cnt++; } else { cmd->csp->ncmds_errs.cnt++; } } static void reply_number(struct cfg *cf, struct rtpp_command *cmd, int number) { int len; len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d\n", number); rtpc_doreply(cf, cmd->buf_t, len, cmd, 0); } static void reply_ok(struct cfg *cf, struct rtpp_command *cmd) { reply_number(cf, cmd, 0); } void reply_error(struct cfg *cf, struct rtpp_command *cmd, int ecode) { int len; len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "E%d\n", ecode); rtpc_doreply(cf, cmd->buf_t, len, cmd, 1); } void free_command(struct rtpp_command *cmd) { free(cmd); } struct rtpp_command * get_command(struct cfg *cf, int controlfd, int *rval, double dtime, struct rtpp_command_stats *csp, int umode) { char **ap; char *cp; int len, i; struct rtpp_command *cmd; cmd = malloc(sizeof(struct rtpp_command)); if (cmd == NULL) { *rval = ENOMEM; return (NULL); } memset(cmd, 0, sizeof(struct rtpp_command)); cmd->controlfd = controlfd; cmd->dtime = dtime; cmd->csp = csp; cmd->umode = umode; if (umode == 0) { for (;;) { len = read(controlfd, cmd->buf, sizeof(cmd->buf) - 1); if (len != -1 || (errno != EAGAIN && errno != EINTR)) break; } } else { cmd->rlen = sizeof(cmd->raddr); len = recvfrom(controlfd, cmd->buf, sizeof(cmd->buf) - 1, 0, sstosa(&cmd->raddr), &cmd->rlen); } if (len == -1) { if (errno != EAGAIN && errno != EINTR) rtpp_log_ewrite(RTPP_LOG_ERR, cf->stable->glog, "can't read from control socket"); free(cmd); *rval = -1; return (NULL); } cmd->buf[len] = '\0'; rtpp_log_write(RTPP_LOG_DBUG, cf->stable->glog, "received command \"%s\"", cmd->buf); csp->ncmds_rcvd.cnt++; cp = cmd->buf; for (ap = cmd->argv; (*ap = rtpp_strsep(&cp, "\r\n\t ")) != NULL;) { if (**ap != '\0') { cmd->argc++; if (++ap >= &cmd->argv[RTPC_MAX_ARGC]) break; } } if (cmd->argc < 1 || (umode != 0 && cmd->argc < 2)) { rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error"); reply_error(cf, cmd, ECODE_PARSE_1); *rval = 0; free(cmd); return (NULL); } /* Stream communication mode doesn't use cookie */ if (umode != 0) { cmd->cookie = cmd->argv[0]; for (i = 1; i < cmd->argc; i++) cmd->argv[i - 1] = cmd->argv[i]; cmd->argc--; cmd->argv[cmd->argc] = NULL; } /* Step I: parse parameters that are common to all ops */ if (rtpp_command_pre_parse(cf, cmd) != 0) { /* Error reply is handled by the rtpp_command_pre_parse() */ *rval = 0; free(cmd); return (NULL); } return (cmd); } struct d_opts { int weak; }; int handle_command(struct cfg *cf, struct rtpp_command *cmd) { int i, verbose; int playcount; char *cp, *tcp; char *pname, *codecs, *recording_name; struct rtpp_session *spa; int record_single_file; struct ul_opts *ulop; struct d_opts dopt; spa = NULL; recording_name = NULL; codecs = NULL; /* Step II: parse parameters that are specific to a particular op and run simple ops */ switch (cmd->cca.op) { case VER_FEATURE: handle_ver_feature(cf, cmd); return 0; case GET_VER: /* This returns base version. */ reply_number(cf, cmd, CPROTOVER); return 0; case DELETE_ALL: /* Delete all active sessions */ rtpp_log_write(RTPP_LOG_INFO, cf->stable->glog, "deleting all active sessions"); pthread_mutex_lock(&cf->sessinfo.lock); for (i = 0; i < cf->sessinfo.nsessions; i++) { spa = cf->sessinfo.sessions[i]; if (spa == NULL || spa->sidx[0] != i) continue; remove_session(cf, spa); } pthread_mutex_unlock(&cf->sessinfo.lock); reply_ok(cf, cmd); return 0; case INFO: handle_info(cf, cmd, &cmd->argv[0][1]); return 0; case PLAY: /* * P callid pname codecs from_tag to_tag * * <codecs> could be either comma-separated list of supported * payload types or word "session" (without quotes), in which * case list saved on last session update will be used instead. */ playcount = 1; pname = cmd->argv[2]; codecs = cmd->argv[3]; tcp = &(cmd->argv[0][1]); if (*tcp != '\0') { playcount = strtol(tcp, &cp, 10); if (cp == tcp || *cp != '\0') { rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error"); reply_error(cf, cmd, ECODE_PARSE_6); return 0; } } break; case COPY: recording_name = cmd->argv[2]; /* Fallthrough */ case RECORD: if (cmd->argv[0][1] == 'S' || cmd->argv[0][1] == 's') { if (cmd->argv[0][2] != '\0') { rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error"); reply_error(cf, cmd, ECODE_PARSE_2); return 0; } record_single_file = (cf->stable->record_pcap == 0) ? 0 : 1; } else { if (cmd->argv[0][1] != '\0') { rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error"); reply_error(cf, cmd, ECODE_PARSE_3); return 0; } record_single_file = 0; } break; case DELETE: /* D[w] call_id from_tag [to_tag] */ dopt.weak = 0; for (cp = cmd->argv[0] + 1; *cp != '\0'; cp++) { switch (*cp) { case 'w': case 'W': dopt.weak = 1; break; default: rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "DELETE: unknown command modifier `%c'", *cp); reply_error(cf, cmd, ECODE_PARSE_4); return 0; } } break; case UPDATE: case LOOKUP: ulop = rtpp_command_ul_opts_parse(cf, cmd); if (ulop == NULL) { return 0; } break; case GET_STATS: verbose = 0; for (cp = cmd->argv[0] + 1; *cp != '\0'; cp++) { switch (*cp) { case 'v': case 'V': verbose = 1; break; default: rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "STATS: unknown command modifier `%c'", *cp); reply_error(cf, cmd, ECODE_PARSE_5); return 0; } } i = handle_get_stats(cf, cmd, verbose); if (i != 0) { reply_error(cf, cmd, i); } return 0; default: break; } /* * Record and delete need special handling since they apply to all * streams in the session. */ switch (cmd->cca.op) { case DELETE: i = handle_delete(cf, &cmd->cca, dopt.weak); break; case RECORD: i = handle_record(cf, &cmd->cca, record_single_file); break; default: i = find_stream(cf, cmd->cca.call_id, cmd->cca.from_tag, cmd->cca.to_tag, &spa); if (i != -1 && cmd->cca.op != UPDATE) i = NOT(i); break; } if (i == -1 && cmd->cca.op != UPDATE) { rtpp_log_write(RTPP_LOG_INFO, cf->stable->glog, "%s request failed: session %s, tags %s/%s not found", cmd->cca.rname, cmd->cca.call_id, cmd->cca.from_tag, cmd->cca.to_tag != NULL ? cmd->cca.to_tag : "NONE"); if (cmd->cca.op == LOOKUP) { rtpp_command_ul_opts_free(ulop); ul_reply_port(cf, cmd, NULL); return 0; } reply_error(cf, cmd, ECODE_SESUNKN); return 0; } switch (cmd->cca.op) { case DELETE: case RECORD: reply_ok(cf, cmd); break; case NOPLAY: handle_noplay(cf, spa, i, cmd); reply_ok(cf, cmd); break; case PLAY: handle_noplay(cf, spa, i, cmd); if (strcmp(codecs, "session") == 0) { if (spa->codecs[i] == NULL) { reply_error(cf, cmd, ECODE_INVLARG_5); return 0; } codecs = spa->codecs[i]; } if (playcount != 0 && handle_play(cf, spa, i, codecs, pname, playcount, cmd) != 0) { reply_error(cf, cmd, ECODE_PLRFAIL); return 0; } reply_ok(cf, cmd); break; case COPY: if (handle_copy(cf, spa, i, recording_name, record_single_file) != 0) { reply_error(cf, cmd, ECODE_CPYFAIL); return 0; } reply_ok(cf, cmd); break; case QUERY: handle_query(cf, cmd, spa, i); break; case LOOKUP: case UPDATE: rtpp_command_ul_handle(cf, cmd, ulop, spa, i); break; default: /* Programmatic error, should not happen */ abort(); } return 0; } static int handle_delete(struct cfg *cf, struct common_cmd_args *ccap, int weak) { int ndeleted; unsigned int medianum; struct rtpp_session *spa, *spb; int cmpr, cmpr1, idx; ndeleted = 0; for (spa = session_findfirst(cf, ccap->call_id); spa != NULL;) { medianum = 0; if ((cmpr1 = compare_session_tags(spa->tag, ccap->from_tag, &medianum)) != 0) { idx = 1; cmpr = cmpr1; } else if (ccap->to_tag != NULL && (cmpr1 = compare_session_tags(spa->tag, ccap->to_tag, &medianum)) != 0) { idx = 0; cmpr = cmpr1; } else { spa = session_findnext(cf, spa); continue; } if (weak) spa->weak[idx] = 0; else spa->strong = 0; /* * This seems to be stable from reiterations, the only side * effect is less efficient work. */ if (spa->strong || spa->weak[0] || spa->weak[1]) { rtpp_log_write(RTPP_LOG_INFO, spa->log, "delete: medianum=%u: removing %s flag, seeing flags to" " continue session (strong=%d, weak=%d/%d)", medianum, weak ? ( idx ? "weak[1]" : "weak[0]" ) : "strong", spa->strong, spa->weak[0], spa->weak[1]); /* Skipping to next possible stream for this call */ ++ndeleted; spa = session_findnext(cf, spa); continue; } rtpp_log_write(RTPP_LOG_INFO, spa->log, "forcefully deleting session %u on ports %d/%d", medianum, spa->ports[0], spa->ports[1]); /* Search forward before we do removal */ spb = spa; spa = session_findnext(cf, spa); pthread_mutex_lock(&cf->sessinfo.lock); remove_session(cf, spb); pthread_mutex_unlock(&cf->sessinfo.lock); ++ndeleted; if (cmpr != 2) { break; } } if (ndeleted == 0) { return -1; } return 0; } static void handle_noplay(struct cfg *cf, struct rtpp_session *spa, int idx, struct rtpp_command *cmd) { if (spa->rtps[idx] != NULL) { rtp_server_free(spa->rtps[idx]); cmd->csp->nplrs_destroyed.cnt++; spa->rtps[idx] = NULL; rtpp_log_write(RTPP_LOG_INFO, spa->log, "stopping player at port %d", spa->ports[idx]); if (spa->rtps[0] == NULL && spa->rtps[1] == NULL) { assert(cf->rtp_servers[spa->sridx] == spa); cf->rtp_servers[spa->sridx] = NULL; spa->sridx = -1; } } } static int handle_play(struct cfg *cf, struct rtpp_session *spa, int idx, char *codecs, char *pname, int playcount, struct rtpp_command *cmd) { int n; char *cp; while (*codecs != '\0') { n = strtol(codecs, &cp, 10); if (cp == codecs) break; codecs = cp; if (*codecs != '\0') codecs++; spa->rtps[idx] = rtp_server_new(pname, n, playcount); if (spa->rtps[idx] == NULL) continue; cmd->csp->nplrs_created.cnt++; rtpp_log_write(RTPP_LOG_INFO, spa->log, "%d times playing prompt %s codec %d", playcount, pname, n); if (spa->sridx == -1) append_server(cf, spa); return 0; } rtpp_log_write(RTPP_LOG_ERR, spa->log, "can't create player"); return -1; } static int handle_record(struct cfg *cf, struct common_cmd_args *ccap, int record_single_file) { int nrecorded, idx; struct rtpp_session *spa; nrecorded = 0; for (spa = session_findfirst(cf, ccap->call_id); spa != NULL; spa = session_findnext(cf, spa)) { if (compare_session_tags(spa->tag, ccap->from_tag, NULL) != 0) { idx = 1; } else if (ccap->to_tag != NULL && (compare_session_tags(spa->tag, ccap->to_tag, NULL)) != 0) { idx = 0; } else { continue; } if (handle_copy(cf, spa, idx, NULL, record_single_file) == 0) { nrecorded++; } } return (nrecorded == 0 ? -1 : 0); } static void handle_query(struct cfg *cf, struct rtpp_command *cmd, struct rtpp_session *spa, int idx) { int len; len = snprintf(cmd->buf_t, sizeof(cmd->buf_t), "%d %lu %lu %lu %lu\n", get_ttl(spa), spa->pcount[idx], spa->pcount[NOT(idx)], spa->pcount[2], spa->pcount[3]); rtpc_doreply(cf, cmd->buf_t, len, cmd, 0); } static void handle_info(struct cfg *cf, struct rtpp_command *cmd, const char *opts) { #if 0 struct rtpp_session *spa, *spb; char addrs[4][256]; #endif int len, i, brief, load; char buf[1024 * 8]; unsigned long long packets_in, packets_out; brief = 0; load = 0; for (i = 0; opts[i] != '\0'; i++) { switch (opts[i]) { case 'b': case 'B': brief = 1; break; case 'l': case 'L': load = 1; break; default: rtpp_log_write(RTPP_LOG_ERR, cf->stable->glog, "command syntax error"); reply_error(cf, cmd, ECODE_PARSE_7); return; } } packets_in = CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_rcvd"); packets_out = CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_relayed") + CALL_METHOD(cf->stable->rtpp_stats, getlvalbyname, "npkts_played"); pthread_mutex_lock(&cf->sessinfo.lock); len = snprintf(buf, sizeof(buf), "sessions created: %llu\nactive sessions: %d\n" "active streams: %d\npackets received: %llu\npackets transmitted: %llu\n", cf->sessions_created, cf->sessions_active, cf->sessinfo.nsessions, packets_in, packets_out); if (load != 0) { len += snprintf(buf + len, sizeof(buf) - len, "average load: %f\n", rtpp_command_async_get_aload(cf->stable->rtpp_cmd_cf)); } #if 0 XXX this needs work to fix it after rtp/rtcp split for (i = 0; i < cf->sessinfo.nsessions && brief == 0; i++) { spa = cf->sessinfo.sessions[i]; if (spa == NULL || spa->sidx[0] != i) continue; /* RTCP twin session */ if (spa->rtcp == NULL) { spb = spa->rtp; buf[len++] = '\t'; } else { spb = spa->rtcp; buf[len++] = '\t'; buf[len++] = 'C'; buf[len++] = ' '; } addr2char_r(spb->laddr[1], addrs[0], sizeof(addrs[0])); if (spb->addr[1] == NULL) { strcpy(addrs[1], "NONE"); } else { sprintf(addrs[1], "%s:%d", addr2char(spb->addr[1]), addr2port(spb->addr[1])); } addr2char_r(spb->laddr[0], addrs[2], sizeof(addrs[2])); if (spb->addr[0] == NULL) { strcpy(addrs[3], "NONE"); } else { sprintf(addrs[3], "%s:%d", addr2char(spb->addr[0]), addr2port(spb->addr[0])); } len += snprintf(buf + len, sizeof(buf) - len, "%s/%s: caller = %s:%d/%s, callee = %s:%d/%s, " "stats = %lu/%lu/%lu/%lu, ttl = %d/%d\n", spb->call_id, spb->tag, addrs[0], spb->ports[1], addrs[1], addrs[2], spb->ports[0], addrs[3], spa->pcount[0], spa->pcount[1], spa->pcount[2], spa->pcount[3], spb->ttl[0], spb->ttl[1]); if (len + 512 > sizeof(buf)) { rtpc_doreply(cf, buf, len, cmd); len = 0; } } #endif pthread_mutex_unlock(&cf->sessinfo.lock); if (len > 0) { rtpc_doreply(cf, buf, len, cmd, 0); } } static void handle_ver_feature(struct cfg *cf, struct rtpp_command *cmd) { int i, known; /* * Wait for protocol version datestamp and check whether we * know it. */ /* * Only list 20081224 protocol mod as supported if * user actually enabled notification with -n */ if (strcmp(cmd->argv[1], "20081224") == 0 && rtpp_th_get_sn(cf->timeout_handler) == NULL) { reply_number(cf, cmd, 0); return; } for (known = i = 0; proto_caps[i].pc_id != NULL; ++i) { if (!strcmp(cmd->argv[1], proto_caps[i].pc_id)) { known = 1; break; } } reply_number(cf, cmd, known); }
46324c414ef4c2261e3c1eadbac19ce22ecedc40
eb9f655206c43c12b497c667ba56a0d358b6bc3a
/plugins/hg4idea/testData/bin/mercurial/compat.h
1f3e442fb3b291f08d53d1d99b49ec3e270c3d8a
[ "Apache-2.0" ]
permissive
JetBrains/intellij-community
2ed226e200ecc17c037dcddd4a006de56cd43941
05dbd4575d01a213f3f4d69aa4968473f2536142
refs/heads/master
2023-09-03T17:06:37.560889
2023-09-03T11:51:00
2023-09-03T12:12:27
2,489,216
16,288
6,635
Apache-2.0
2023-09-12T07:41:58
2011-09-30T13:33:05
null
UTF-8
C
false
false
1,034
h
compat.h
#ifndef _HG_COMPAT_H_ #define _HG_COMPAT_H_ #ifdef _WIN32 #ifdef _MSC_VER #if _MSC_VER < 1900 /* msvc 6.0 has problems */ #define inline __inline #if defined(_WIN64) typedef __int64 ssize_t; typedef unsigned __int64 uintptr_t; #else typedef int ssize_t; typedef unsigned int uintptr_t; #endif typedef signed char int8_t; typedef short int16_t; typedef long int32_t; typedef __int64 int64_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned long uint32_t; typedef unsigned __int64 uint64_t; #else /* VC++ 14 */ #include <stdint.h> #if defined(_WIN64) typedef __int64 ssize_t; #else typedef int ssize_t; #endif #endif /* _MSC_VER < 1900 */ #else /* not msvc */ #include <stdint.h> #endif #else /* not windows */ #include <sys/types.h> #if defined __BEOS__ && !defined __HAIKU__ #include <ByteOrder.h> #else #include <arpa/inet.h> #endif #include <inttypes.h> #endif #if defined __hpux || defined __SUNPRO_C || defined _AIX #define inline #endif #ifdef __linux #define inline __inline #endif #endif
de8b6a853fa2534ecd6edbc6b04894543f6e4305
b732361d6b3405c3e79ac0a7d8361cf5b329b015
/ext/phalcon/events/event.zep.c
bc8273cb6975df2145a3fd67af66b28d0b2dd98f
[ "BSD-3-Clause" ]
permissive
phalcon/cphalcon
4a5b26f47b5c2a4107541d7fd73c595c0d90ed73
fc183e11e8b96c43daf7d893244846206dc2aa73
refs/heads/master
2023-03-07T22:09:48.814291
2023-02-28T16:45:15
2023-02-28T16:45:15
2,854,337
8,135
2,343
BSD-3-Clause
2023-09-12T12:41:13
2011-11-26T05:52:50
PHP
UTF-8
C
false
true
7,492
c
event.zep.c
#ifdef HAVE_CONFIG_H #include "../../ext_config.h" #endif #include <php.h> #include "../../php_ext.h" #include "../../ext.h" #include <Zend/zend_operators.h> #include <Zend/zend_exceptions.h> #include <Zend/zend_interfaces.h> #include "kernel/main.h" #include "kernel/operators.h" #include "kernel/exception.h" #include "kernel/memory.h" #include "kernel/fcall.h" #include "kernel/concat.h" #include "kernel/object.h" #include "ext/spl/spl_exceptions.h" /** * This file is part of the Phalcon Framework. * * (c) Phalcon Team <team@phalcon.io> * * For the full copyright and license information, please view the LICENSE.txt * file that was distributed with this source code. */ /** * This class offers contextual information of a fired event in the * EventsManager * *```php * Phalcon\Events\Event; * * $event = new Event("db:afterQuery", $this, ["data" => "mydata"], true); * if ($event->isCancelable()) { * $event->stop(); * } * ``` */ ZEPHIR_INIT_CLASS(Phalcon_Events_Event) { ZEPHIR_REGISTER_CLASS(Phalcon\\Events, Event, phalcon, events_event, phalcon_events_event_method_entry, 0); /** * Is event cancelable? * * @var bool */ zend_declare_property_null(phalcon_events_event_ce, SL("cancelable"), ZEND_ACC_PROTECTED); /** * Event data * * @var mixed */ zend_declare_property_null(phalcon_events_event_ce, SL("data"), ZEND_ACC_PROTECTED); /** * Event source * * @var object|null */ zend_declare_property_null(phalcon_events_event_ce, SL("source"), ZEND_ACC_PROTECTED); /** * Is event propagation stopped? * * @var bool */ zend_declare_property_bool(phalcon_events_event_ce, SL("stopped"), 0, ZEND_ACC_PROTECTED); /** * Event type * * @var string */ zend_declare_property_null(phalcon_events_event_ce, SL("type"), ZEND_ACC_PROTECTED); zend_class_implements(phalcon_events_event_ce, 1, phalcon_events_eventinterface_ce); return SUCCESS; } /** * Phalcon\Events\Event constructor * * @param object source */ PHP_METHOD(Phalcon_Events_Event, __construct) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zend_long ZEPHIR_LAST_CALL_STATUS; zend_bool cancelable, _0; zval *type_param = NULL, *source = NULL, source_sub, *data = NULL, data_sub, *cancelable_param = NULL, __$true, __$false, __$null, _1$$3, _2$$3, _3$$3; zval type; zval *this_ptr = getThis(); ZVAL_UNDEF(&type); ZVAL_UNDEF(&source_sub); ZVAL_UNDEF(&data_sub); ZVAL_BOOL(&__$true, 1); ZVAL_BOOL(&__$false, 0); ZVAL_NULL(&__$null); ZVAL_UNDEF(&_1$$3); ZVAL_UNDEF(&_2$$3); ZVAL_UNDEF(&_3$$3); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 4) Z_PARAM_STR(type) Z_PARAM_OPTIONAL Z_PARAM_ZVAL_OR_NULL(source) Z_PARAM_ZVAL_OR_NULL(data) Z_PARAM_BOOL(cancelable) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 3, &type_param, &source, &data, &cancelable_param); if (UNEXPECTED(Z_TYPE_P(type_param) != IS_STRING && Z_TYPE_P(type_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'type' must be of the type string")); RETURN_MM_NULL(); } if (EXPECTED(Z_TYPE_P(type_param) == IS_STRING)) { zephir_get_strval(&type, type_param); } else { ZEPHIR_INIT_VAR(&type); } if (!source) { source = &source_sub; source = &__$null; } if (!data) { data = &data_sub; data = &__$null; } if (!cancelable_param) { cancelable = 1; } else { cancelable = zephir_get_boolval(cancelable_param); } _0 = Z_TYPE_P(source) != IS_NULL; if (_0) { _0 = Z_TYPE_P(source) != IS_OBJECT; } if (UNEXPECTED(_0)) { ZEPHIR_INIT_VAR(&_1$$3); object_init_ex(&_1$$3, phalcon_events_exception_ce); ZEPHIR_INIT_VAR(&_2$$3); zephir_gettype(&_2$$3, source); ZEPHIR_INIT_VAR(&_3$$3); ZEPHIR_CONCAT_SVSV(&_3$$3, "The source of ", &type, " event must be an object, got ", &_2$$3); ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 29, &_3$$3); zephir_check_call_status(); zephir_throw_exception_debug(&_1$$3, "phalcon/Events/Event.zep", 73); ZEPHIR_MM_RESTORE(); return; } zephir_update_property_zval(this_ptr, ZEND_STRL("type"), &type); zephir_update_property_zval(this_ptr, ZEND_STRL("source"), source); zephir_update_property_zval(this_ptr, ZEND_STRL("data"), data); if (cancelable) { zephir_update_property_zval(this_ptr, ZEND_STRL("cancelable"), &__$true); } else { zephir_update_property_zval(this_ptr, ZEND_STRL("cancelable"), &__$false); } ZEPHIR_MM_RESTORE(); } PHP_METHOD(Phalcon_Events_Event, getData) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "data"); } PHP_METHOD(Phalcon_Events_Event, getSource) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "source"); } PHP_METHOD(Phalcon_Events_Event, getType) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "type"); } /** * Check whether the event is cancelable. * * ```php * if ($event->isCancelable()) { * $event->stop(); * } * ``` */ PHP_METHOD(Phalcon_Events_Event, isCancelable) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "cancelable"); } /** * Check whether the event is currently stopped. */ PHP_METHOD(Phalcon_Events_Event, isStopped) { zval *this_ptr = getThis(); RETURN_MEMBER(getThis(), "stopped"); } /** * Sets event data. */ PHP_METHOD(Phalcon_Events_Event, setData) { zval *data = NULL, data_sub, __$null; zval *this_ptr = getThis(); ZVAL_UNDEF(&data_sub); ZVAL_NULL(&__$null); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_ZVAL_OR_NULL(data) ZEND_PARSE_PARAMETERS_END(); #endif zephir_fetch_params_without_memory_grow(0, 1, &data); if (!data) { data = &data_sub; data = &__$null; } zephir_update_property_zval(this_ptr, ZEND_STRL("data"), data); RETURN_THISW(); } /** * Sets event type. */ PHP_METHOD(Phalcon_Events_Event, setType) { zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL; zval *type_param = NULL; zval type; zval *this_ptr = getThis(); ZVAL_UNDEF(&type); #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(type) ZEND_PARSE_PARAMETERS_END(); #endif ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &type_param); if (UNEXPECTED(Z_TYPE_P(type_param) != IS_STRING && Z_TYPE_P(type_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'type' must be of the type string")); RETURN_MM_NULL(); } if (EXPECTED(Z_TYPE_P(type_param) == IS_STRING)) { zephir_get_strval(&type, type_param); } else { ZEPHIR_INIT_VAR(&type); } zephir_update_property_zval(this_ptr, ZEND_STRL("type"), &type); RETURN_THIS(); } /** * Stops the event preventing propagation. * * ```php * if ($event->isCancelable()) { * $event->stop(); * } * ``` */ PHP_METHOD(Phalcon_Events_Event, stop) { zval __$true, __$false, _0; zval *this_ptr = getThis(); ZVAL_BOOL(&__$true, 1); ZVAL_BOOL(&__$false, 0); ZVAL_UNDEF(&_0); zephir_read_property(&_0, this_ptr, ZEND_STRL("cancelable"), PH_NOISY_CC | PH_READONLY); if (UNEXPECTED(!zephir_is_true(&_0))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STRW(phalcon_events_exception_ce, "Trying to cancel a non-cancelable event", "phalcon/Events/Event.zep", 150); return; } if (1) { zephir_update_property_zval(this_ptr, ZEND_STRL("stopped"), &__$true); } else { zephir_update_property_zval(this_ptr, ZEND_STRL("stopped"), &__$false); } RETURN_THISW(); }
f3ee4e6703b3925ec883835f7e9fe0f567158af2
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/tile/include/uapi/arch/sim.h
e54b7b0527f368523b64e957eddaa28e4549b29e
[ "LicenseRef-scancode-free-unknown", "Apache-2.0", "Linux-syscall-note", "GPL-2.0-only", "GPL-1.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
17,271
h
sim.h
/* * Copyright 2010 Tilera Corporation. All Rights Reserved. * * 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, version 2. * * 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, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for * more details. */ /** * @file * * Provides an API for controlling the simulator at runtime. */ /** * @addtogroup arch_sim * @{ * * An API for controlling the simulator at runtime. * * The simulator's behavior can be modified while it is running. * For example, human-readable trace output can be enabled and disabled * around code of interest. * * There are two ways to modify simulator behavior: * programmatically, by calling various sim_* functions, and * interactively, by entering commands like "sim set functional true" * at the tile-monitor prompt. Typing "sim help" at that prompt provides * a list of interactive commands. * * All interactive commands can also be executed programmatically by * passing a string to the sim_command function. */ #ifndef __ARCH_SIM_H__ #define __ARCH_SIM_H__ #include <arch/sim_def.h> #include <arch/abi.h> #ifndef __ASSEMBLER__ #include <arch/spr_def.h> /** * Return true if the current program is running under a simulator, * rather than on real hardware. If running on hardware, other "sim_xxx()" * calls have no useful effect. */ static inline int sim_is_simulator(void) { return __insn_mfspr(SPR_SIM_CONTROL) != 0; } /** * Checkpoint the simulator state to a checkpoint file. * * The checkpoint file name is either the default or the name specified * on the command line with "--checkpoint-file". */ static __inline void sim_checkpoint(void) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_CHECKPOINT); } /** * Report whether or not various kinds of simulator tracing are enabled. * * @return The bitwise OR of these values: * * SIM_TRACE_CYCLES (--trace-cycles), * SIM_TRACE_ROUTER (--trace-router), * SIM_TRACE_REGISTER_WRITES (--trace-register-writes), * SIM_TRACE_DISASM (--trace-disasm), * SIM_TRACE_STALL_INFO (--trace-stall-info) * SIM_TRACE_MEMORY_CONTROLLER (--trace-memory-controller) * SIM_TRACE_L2_CACHE (--trace-l2) * SIM_TRACE_LINES (--trace-lines) */ static __inline unsigned int sim_get_tracing(void) { return __insn_mfspr(SPR_SIM_CONTROL) & SIM_TRACE_FLAG_MASK; } /** * Turn on or off different kinds of simulator tracing. * * @param mask Either one of these special values: * * SIM_TRACE_NONE (turns off tracing), * SIM_TRACE_ALL (turns on all possible tracing). * * or the bitwise OR of these values: * * SIM_TRACE_CYCLES (--trace-cycles), * SIM_TRACE_ROUTER (--trace-router), * SIM_TRACE_REGISTER_WRITES (--trace-register-writes), * SIM_TRACE_DISASM (--trace-disasm), * SIM_TRACE_STALL_INFO (--trace-stall-info) * SIM_TRACE_MEMORY_CONTROLLER (--trace-memory-controller) * SIM_TRACE_L2_CACHE (--trace-l2) * SIM_TRACE_LINES (--trace-lines) */ static __inline void sim_set_tracing(unsigned int mask) { __insn_mtspr(SPR_SIM_CONTROL, SIM_TRACE_SPR_ARG(mask)); } /** * Request dumping of different kinds of simulator state. * * @param mask Either this special value: * * SIM_DUMP_ALL (dump all known state) * * or the bitwise OR of these values: * * SIM_DUMP_REGS (the register file), * SIM_DUMP_SPRS (the SPRs), * SIM_DUMP_ITLB (the iTLB), * SIM_DUMP_DTLB (the dTLB), * SIM_DUMP_L1I (the L1 I-cache), * SIM_DUMP_L1D (the L1 D-cache), * SIM_DUMP_L2 (the L2 cache), * SIM_DUMP_SNREGS (the switch register file), * SIM_DUMP_SNITLB (the switch iTLB), * SIM_DUMP_SNL1I (the switch L1 I-cache), * SIM_DUMP_BACKTRACE (the current backtrace) */ static __inline void sim_dump(unsigned int mask) { __insn_mtspr(SPR_SIM_CONTROL, SIM_DUMP_SPR_ARG(mask)); } /** * Print a string to the simulator stdout. * * @param str The string to be written. */ static __inline void sim_print(const char* str) { for ( ; *str != '\0'; str++) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC | (*str << _SIM_CONTROL_OPERATOR_BITS)); } __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC | (SIM_PUTC_FLUSH_BINARY << _SIM_CONTROL_OPERATOR_BITS)); } /** * Print a string to the simulator stdout. * * @param str The string to be written (a newline is automatically added). */ static __inline void sim_print_string(const char* str) { for ( ; *str != '\0'; str++) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC | (*str << _SIM_CONTROL_OPERATOR_BITS)); } __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC | (SIM_PUTC_FLUSH_STRING << _SIM_CONTROL_OPERATOR_BITS)); } /** * Execute a simulator command string. * * Type 'sim help' at the tile-monitor prompt to learn what commands * are available. Note the use of the tile-monitor "sim" command to * pass commands to the simulator. * * The argument to sim_command() does not include the leading "sim" * prefix used at the tile-monitor prompt; for example, you might call * sim_command("trace disasm"). */ static __inline void sim_command(const char* str) { int c; do { c = *str++; __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_COMMAND | (c << _SIM_CONTROL_OPERATOR_BITS)); } while (c); } #ifndef __DOXYGEN__ /** * The underlying implementation of "_sim_syscall()". * * We use extra "and" instructions to ensure that all the values * we are passing to the simulator are actually valid in the registers * (i.e. returned from memory) prior to the SIM_CONTROL spr. */ static __inline long _sim_syscall0(int val) { long result; __asm__ __volatile__ ("mtspr SIM_CONTROL, r0" : "=R00" (result) : "R00" (val)); return result; } static __inline long _sim_syscall1(int val, long arg1) { long result; __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }" : "=R00" (result) : "R00" (val), "R01" (arg1)); return result; } static __inline long _sim_syscall2(int val, long arg1, long arg2) { long result; __asm__ __volatile__ ("{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }" : "=R00" (result) : "R00" (val), "R01" (arg1), "R02" (arg2)); return result; } /* Note that _sim_syscall3() and higher are technically at risk of receiving an interrupt right before the mtspr bundle, in which case the register values for arguments 3 and up may still be in flight to the core from a stack frame reload. */ static __inline long _sim_syscall3(int val, long arg1, long arg2, long arg3) { long result; __asm__ __volatile__ ("{ and zero, r3, r3 };" "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }" : "=R00" (result) : "R00" (val), "R01" (arg1), "R02" (arg2), "R03" (arg3)); return result; } static __inline long _sim_syscall4(int val, long arg1, long arg2, long arg3, long arg4) { long result; __asm__ __volatile__ ("{ and zero, r3, r4 };" "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }" : "=R00" (result) : "R00" (val), "R01" (arg1), "R02" (arg2), "R03" (arg3), "R04" (arg4)); return result; } static __inline long _sim_syscall5(int val, long arg1, long arg2, long arg3, long arg4, long arg5) { long result; __asm__ __volatile__ ("{ and zero, r3, r4; and zero, r5, r5 };" "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }" : "=R00" (result) : "R00" (val), "R01" (arg1), "R02" (arg2), "R03" (arg3), "R04" (arg4), "R05" (arg5)); return result; } /** * Make a special syscall to the simulator itself, if running under * simulation. This is used as the implementation of other functions * and should not be used outside this file. * * @param syscall_num The simulator syscall number. * @param nr The number of additional arguments provided. * * @return Varies by syscall. */ #define _sim_syscall(syscall_num, nr, args...) \ _sim_syscall##nr( \ ((syscall_num) << _SIM_CONTROL_OPERATOR_BITS) | SIM_CONTROL_SYSCALL, \ ##args) /* Values for the "access_mask" parameters below. */ #define SIM_WATCHPOINT_READ 1 #define SIM_WATCHPOINT_WRITE 2 #define SIM_WATCHPOINT_EXECUTE 4 static __inline int sim_add_watchpoint(unsigned int process_id, unsigned long address, unsigned long size, unsigned int access_mask, unsigned long user_data) { return _sim_syscall(SIM_SYSCALL_ADD_WATCHPOINT, 5, process_id, address, size, access_mask, user_data); } static __inline int sim_remove_watchpoint(unsigned int process_id, unsigned long address, unsigned long size, unsigned int access_mask, unsigned long user_data) { return _sim_syscall(SIM_SYSCALL_REMOVE_WATCHPOINT, 5, process_id, address, size, access_mask, user_data); } /** * Return value from sim_query_watchpoint. */ struct SimQueryWatchpointStatus { /** * 0 if a watchpoint fired, 1 if no watchpoint fired, or -1 for * error (meaning a bad process_id). */ int syscall_status; /** * The address of the watchpoint that fired (this is the address * passed to sim_add_watchpoint, not an address within that range * that actually triggered the watchpoint). */ unsigned long address; /** The arbitrary user_data installed by sim_add_watchpoint. */ unsigned long user_data; }; static __inline struct SimQueryWatchpointStatus sim_query_watchpoint(unsigned int process_id) { struct SimQueryWatchpointStatus status; long val = SIM_CONTROL_SYSCALL | (SIM_SYSCALL_QUERY_WATCHPOINT << _SIM_CONTROL_OPERATOR_BITS); __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }" : "=R00" (status.syscall_status), "=R01" (status.address), "=R02" (status.user_data) : "R00" (val), "R01" (process_id)); return status; } /* On the simulator, confirm lines have been evicted everywhere. */ static __inline void sim_validate_lines_evicted(unsigned long long pa, unsigned long length) { #ifdef __LP64__ _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 2, pa, length); #else _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 4, 0 /* dummy */, (long)(pa), (long)(pa >> 32), length); #endif } /* Return the current CPU speed in cycles per second. */ static __inline long sim_query_cpu_speed(void) { return _sim_syscall(SIM_SYSCALL_QUERY_CPU_SPEED, 0); } #endif /* !__DOXYGEN__ */ /** * Modify the shaping parameters of a shim. * * @param shim The shim to modify. One of: * SIM_CONTROL_SHAPING_GBE_0 * SIM_CONTROL_SHAPING_GBE_1 * SIM_CONTROL_SHAPING_GBE_2 * SIM_CONTROL_SHAPING_GBE_3 * SIM_CONTROL_SHAPING_XGBE_0 * SIM_CONTROL_SHAPING_XGBE_1 * * @param type The type of shaping. This should be the same type of * shaping that is already in place on the shim. One of: * SIM_CONTROL_SHAPING_MULTIPLIER * SIM_CONTROL_SHAPING_PPS * SIM_CONTROL_SHAPING_BPS * * @param units The magnitude of the rate. One of: * SIM_CONTROL_SHAPING_UNITS_SINGLE * SIM_CONTROL_SHAPING_UNITS_KILO * SIM_CONTROL_SHAPING_UNITS_MEGA * SIM_CONTROL_SHAPING_UNITS_GIGA * * @param rate The rate to which to change it. This must fit in * SIM_CONTROL_SHAPING_RATE_BITS bits or a warning is issued and * the shaping is not changed. * * @return 0 if no problems were detected in the arguments to sim_set_shaping * or 1 if problems were detected (for example, rate does not fit in 17 bits). */ static __inline int sim_set_shaping(unsigned shim, unsigned type, unsigned units, unsigned rate) { if ((rate & ~((1 << SIM_CONTROL_SHAPING_RATE_BITS) - 1)) != 0) return 1; __insn_mtspr(SPR_SIM_CONTROL, SIM_SHAPING_SPR_ARG(shim, type, units, rate)); return 0; } #ifdef __tilegx__ /** Enable a set of mPIPE links. Pass a -1 link_mask to enable all links. */ static __inline void sim_enable_mpipe_links(unsigned mpipe, unsigned long link_mask) { __insn_mtspr(SPR_SIM_CONTROL, (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE | (mpipe << 8) | (1 << 16) | ((uint_reg_t)link_mask << 32))); } /** Disable a set of mPIPE links. Pass a -1 link_mask to disable all links. */ static __inline void sim_disable_mpipe_links(unsigned mpipe, unsigned long link_mask) { __insn_mtspr(SPR_SIM_CONTROL, (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE | (mpipe << 8) | (0 << 16) | ((uint_reg_t)link_mask << 32))); } #endif /* __tilegx__ */ /* * An API for changing "functional" mode. */ #ifndef __DOXYGEN__ #define sim_enable_functional() \ __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_ENABLE_FUNCTIONAL) #define sim_disable_functional() \ __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_DISABLE_FUNCTIONAL) #endif /* __DOXYGEN__ */ /* * Profiler support. */ /** * Turn profiling on for the current task. * * Note that this has no effect if run in an environment without * profiling support (thus, the proper flags to the simulator must * be supplied). */ static __inline void sim_profiler_enable(void) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_ENABLE); } /** Turn profiling off for the current task. */ static __inline void sim_profiler_disable(void) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_DISABLE); } /** * Turn profiling on or off for the current task. * * @param enabled If true, turns on profiling. If false, turns it off. * * Note that this has no effect if run in an environment without * profiling support (thus, the proper flags to the simulator must * be supplied). */ static __inline void sim_profiler_set_enabled(int enabled) { int val = enabled ? SIM_CONTROL_PROFILER_ENABLE : SIM_CONTROL_PROFILER_DISABLE; __insn_mtspr(SPR_SIM_CONTROL, val); } /** * Return true if and only if profiling is currently enabled * for the current task. * * This returns false even if sim_profiler_enable() was called * if the current execution environment does not support profiling. */ static __inline int sim_profiler_is_enabled(void) { return ((__insn_mfspr(SPR_SIM_CONTROL) & SIM_PROFILER_ENABLED_MASK) != 0); } /** * Reset profiling counters to zero for the current task. * * Resetting can be done while profiling is enabled. It does not affect * the chip-wide profiling counters. */ static __inline void sim_profiler_clear(void) { __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_CLEAR); } /** * Enable specified chip-level profiling counters. * * Does not affect the per-task profiling counters. * * @param mask Either this special value: * * SIM_CHIP_ALL (enables all chip-level components). * * or the bitwise OR of these values: * * SIM_CHIP_MEMCTL (enable all memory controllers) * SIM_CHIP_XAUI (enable all XAUI controllers) * SIM_CHIP_MPIPE (enable all MPIPE controllers) */ static __inline void sim_profiler_chip_enable(unsigned int mask) { __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask)); } /** * Disable specified chip-level profiling counters. * * Does not affect the per-task profiling counters. * * @param mask Either this special value: * * SIM_CHIP_ALL (disables all chip-level components). * * or the bitwise OR of these values: * * SIM_CHIP_MEMCTL (disable all memory controllers) * SIM_CHIP_XAUI (disable all XAUI controllers) * SIM_CHIP_MPIPE (disable all MPIPE controllers) */ static __inline void sim_profiler_chip_disable(unsigned int mask) { __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask)); } /** * Reset specified chip-level profiling counters to zero. * * Does not affect the per-task profiling counters. * * @param mask Either this special value: * * SIM_CHIP_ALL (clears all chip-level components). * * or the bitwise OR of these values: * * SIM_CHIP_MEMCTL (clear all memory controllers) * SIM_CHIP_XAUI (clear all XAUI controllers) * SIM_CHIP_MPIPE (clear all MPIPE controllers) */ static __inline void sim_profiler_chip_clear(unsigned int mask) { __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask)); } /* * Event support. */ #ifndef __DOXYGEN__ static __inline void sim_event_begin(unsigned int x) { #if defined(__tile__) && !defined(__NO_EVENT_SPR__) __insn_mtspr(SPR_EVENT_BEGIN, x); #endif } static __inline void sim_event_end(unsigned int x) { #if defined(__tile__) && !defined(__NO_EVENT_SPR__) __insn_mtspr(SPR_EVENT_END, x); #endif } #endif /* !__DOXYGEN__ */ #endif /* !__ASSEMBLER__ */ #endif /* !__ARCH_SIM_H__ */ /** @} */
ace8781e406d613a0d57d3a54f65fe341b03cea7
5eff7a36d9a9917dce9111f0c3074375fe6f7656
/app/xlockmore/modes/roll.c
d0129ceb4c9b486b5fb035a1b631571bbd08e13c
[]
no_license
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
8,713
c
roll.c
/* -*- Mode: C; tab-width: 4 -*- */ /* roll --- rolling ball of points */ #if !defined( lint ) && !defined( SABER ) static const char sccsid[] = "@(#)roll.c 5.00 2000/11/01 xlockmore"; #endif /*- * Copyright (c) 1995 by Charles Vidal <cvidal@ivsweb.com> * http://www.chez.com/vidalc * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. * * This file is provided AS IS with no warranties of any kind. The author * shall have no liability with respect to the infringement of copyrights, * trade secrets or any patents by this file or any part thereof. In no * event will the author be liable for any lost revenue or profits or * other special, indirect and consequential damages. * * Revision History: * 01-Nov-2000: Allocation checks * 10-May-1997: Compatible with xscreensaver * 1995: Written. */ #ifdef STANDALONE #define MODE_roll #define PROGCLASS "Roll" #define HACK_INIT init_roll #define HACK_DRAW draw_roll #define roll_opts xlockmore_opts #define DEFAULTS "*delay: 100000 \n" \ "*count: 25 \n" \ "*size: -64 \n" \ "*ncolors: 200 \n" #define BRIGHT_COLORS #define SMOOTH_COLORS #include "xlockmore.h" /* in xscreensaver distribution */ #else /* STANDALONE */ #include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ #ifdef MODE_roll ModeSpecOpt roll_opts = {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; #ifdef USE_MODULES ModStruct roll_description = {"roll", "init_roll", "draw_roll", "release_roll", "refresh_roll", "init_roll", (char *) NULL, &roll_opts, 100000, 25, 1, -64, 64, 0.6, "", "Shows a rolling ball", 0, NULL}; #endif #define MINPTS 1 #define MINSIZE 8 #define FACTOR 8.0 #define SPEED 25.0 typedef struct { float t, u, v; float t1, u1, v1; } ptsstruct; typedef struct { ptsstruct *pts; XPoint *p; int maxpts, npts; float alpha, theta, phi, r; XPoint sphere, direction; int color; int width, height; } rollstruct; static rollstruct *rolls = (rollstruct *) NULL; static void createsphere(rollstruct * rp, int n1, int n2) { double i, j; int n = 0; for (i = 0.0; i < FACTOR * M_PI; i += (FACTOR * M_PI) / n1) for (j = 0.0; j < FACTOR * M_PI; j += (FACTOR * M_PI) / n2) { rp->pts[n].t1 = rp->r * COSF(i) * COSF(j); rp->pts[n].u1 = rp->r * COSF(i) * SINF(j); rp->pts[n].v1 = rp->r * SINF(i); n++; } } static void rotation3d(rollstruct * rp) { float c1, c2, c3, c4, c5, c6, c7, c8, c9, x, y, z; float sintheta, costheta; float sinphi, cosphi; float sinalpha, cosalpha; int i; sintheta = SINF(rp->theta); costheta = COSF(rp->theta); sinphi = SINF(rp->phi); cosphi = COSF(rp->phi); sinalpha = SINF(rp->alpha); cosalpha = COSF(rp->alpha); c1 = cosphi * costheta; c2 = sinphi * costheta; c3 = -sintheta; c4 = cosphi * sintheta * sinalpha - sinphi * cosalpha; c5 = sinphi * sintheta * sinalpha + cosphi * cosalpha; c6 = costheta * sinalpha; c7 = cosphi * sintheta * cosalpha + sinphi * sinalpha; c8 = sinphi * sintheta * cosalpha - cosphi * sinalpha; c9 = costheta * cosalpha; for (i = 0; i < rp->maxpts; i++) { x = rp->pts[i].t; y = rp->pts[i].u; z = rp->pts[i].v; rp->pts[i].t = c1 * x + c2 * y + c3 * z; rp->pts[i].u = c4 * x + c5 * y + c6 * z; rp->pts[i].v = c7 * x + c8 * y + c9 * z; } } static void project(rollstruct * rp) { int i; for (i = 0; i < rp->maxpts; i++) { rp->p[i].x = (short) (2 * rp->pts[i].t); rp->p[i].y = (short) (2 * rp->pts[i].u); } } static void free_roll(rollstruct *rp) { if (rp->pts != NULL) { free(rp->pts); rp->pts = (ptsstruct *) NULL; } if (rp->p != NULL) { free(rp->p); rp->p = (XPoint *) NULL; } } void init_roll(ModeInfo * mi) { int i; int size = MI_SIZE(mi); double ang; rollstruct *rp; if (rolls == NULL) { if ((rolls = (rollstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (rollstruct))) == NULL) return; } rp = &rolls[MI_SCREEN(mi)]; ang = (double) NRAND(75) + 7.5; rp->direction.x = (short) ((2 * (LRAND() & 1)) - 1) * (int) (SPEED * SINF(ang * M_PI / 180.0)); rp->direction.y = (short) ((2 * (LRAND() & 1)) - 1) * (int) (SPEED * COSF(ang * M_PI / 180.0)); rp->width = MI_WIDTH(mi); rp->height = MI_HEIGHT(mi); if (size < -MINSIZE) rp->r = NRAND(MIN(-size, MAX(MINSIZE, MIN(rp->width, rp->height) / 4)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) rp->r = MAX(MINSIZE, MIN(rp->width, rp->height) / 4); else rp->r = MINSIZE; } else rp->r = MIN(size, MAX(MINSIZE, MIN(rp->width, rp->height) / 4)); rp->sphere.x = NRAND(MAX(1, rp->width - 4 * (int) rp->r)) + 2 * (int) rp->r; rp->sphere.y = NRAND(MAX(1, rp->height - 4 * (int) rp->r)) + 2 * (int) rp->r; rp->alpha = 0; rp->theta = 0; rp->phi = 0; rp->maxpts = MI_COUNT(mi); if (rp->maxpts < -MINPTS) { /* if rp->maxpts is random ... the size can change */ if (rp->pts != NULL) { free(rp->pts); rp->pts = (ptsstruct *) NULL; } rp->maxpts = NRAND(-rp->maxpts - MINPTS + 1) + MINPTS; } else if (rp->maxpts < MINPTS) rp->maxpts = MINPTS; i = rp->maxpts; rp->maxpts *= rp->maxpts; rp->npts = 0; if (rp->pts == NULL) if ((rp->pts = (ptsstruct *) malloc(rp->maxpts * sizeof (ptsstruct))) ==NULL) { free_roll(rp); return; } if (rp->p != NULL) { free(rp->p); rp->p = (XPoint *) NULL; } if (MI_NPIXELS(mi) > 2) rp->color = NRAND(MI_NPIXELS(mi)); createsphere(rp, i, i); MI_CLEARWINDOW(mi); } void draw_roll(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int i; rollstruct *rp; if (rolls == NULL) return; rp = &rolls[MI_SCREEN(mi)]; if (rp->pts == NULL) return; MI_IS_DRAWN(mi) = True; for (i = 0; i < rp->maxpts; i++) { rp->pts[i].t = rp->pts[i].t1; rp->pts[i].u = rp->pts[i].u1; rp->pts[i].v = rp->pts[i].v1; } rp->alpha += ((FACTOR * M_PI) / 200.0); rp->theta += ((FACTOR * M_PI) / 200.0); rp->phi += ((FACTOR * M_PI) / 200.0); if (rp->alpha > (FACTOR * M_PI)) rp->alpha -= (FACTOR * M_PI); if (rp->theta > (FACTOR * M_PI)) rp->theta -= (FACTOR * M_PI); if (rp->phi > (FACTOR * M_PI)) rp->phi -= (FACTOR * M_PI); if (rp->npts) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XDrawPoints(display, window, gc, rp->p, rp->npts, CoordModeOrigin); } else { if (rp->p) free(rp->p); if ((rp->p = (XPoint *) malloc(rp->maxpts * sizeof (XPoint))) == NULL) { free_roll(rp); return; } } rotation3d(rp); project(rp); rp->npts = 0; for (i = 0; i < rp->maxpts; i++) { if (rp->pts[i].v > 0.0) { rp->p[rp->npts].x += rp->sphere.x; rp->p[rp->npts].y += rp->sphere.y; rp->npts++; } } if (MI_NPIXELS(mi) <= 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); else { rp->color = (rp->color + 1) % MI_NPIXELS(mi); XSetForeground(display, gc, MI_PIXEL(mi, rp->color)); } XDrawPoints(display, window, gc, rp->p, rp->npts, CoordModeOrigin); if (rp->sphere.x >= rp->width - (int) rp->r && rp->direction.x > 0) rp->direction.x = -rp->direction.x; else if (rp->sphere.x <= (int) rp->r && rp->direction.x < 0) rp->direction.x = -rp->direction.x; else if (rp->sphere.x < rp->width - 2 * (int) rp->r || rp->sphere.x > 2 * (int) rp->r) { if (rp->sphere.x >= rp->width - 2 * (int) rp->r && rp->direction.x > 0) rp->direction.x = -rp->direction.x; else if (rp->sphere.x <= 2 * (int) rp->r && rp->direction.x < 0) rp->direction.x = -rp->direction.x; } if (rp->sphere.y >= rp->height - (int) rp->r && rp->direction.y > 0) rp->direction.y = -rp->direction.y; else if (rp->sphere.y <= (int) rp->r && rp->direction.y < 0) rp->direction.y = -rp->direction.y; else if (rp->sphere.y < rp->height - 2 * (int) rp->r || rp->sphere.y > 2 * (int) rp->r) { if (rp->sphere.y >= rp->height - 2 * (int) rp->r && rp->direction.y > 0) rp->direction.y = -rp->direction.y; else if (rp->sphere.y <= 2 * (int) rp->r && rp->direction.y < 0) rp->direction.y = -rp->direction.y; } rp->sphere.x += rp->direction.x; rp->sphere.y += rp->direction.y; } void release_roll(ModeInfo * mi) { if (rolls != NULL) { int screen; for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) free_roll(&rolls[screen]); free(rolls); rolls = (rollstruct *) NULL; } } void refresh_roll(ModeInfo * mi) { MI_CLEARWINDOW(mi); } #endif /* MODE_roll */
afbdf7a6ebd9484be363567963763629701143b1
aa3befea459382dc5c01c925653d54f435b3fb0f
/arch/x86_64/src/intel64/intel64_restore_auxstate.c
27929aaf8c41fa9649d4e30953eeb1749b56ff74
[ "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
1,992
c
intel64_restore_auxstate.c
/**************************************************************************** * arch/x86_64/src/intel64/intel64_restore_auxstate.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 <debug.h> #include <nuttx/arch.h> #include <nuttx/sched.h> #include <arch/arch.h> #include <arch/irq.h> #include <arch/io.h> #include "x86_64_internal.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: x86_64_restore_auxstate * * Description: * This function performs some additional action required to complete the * CTX on intel64 processor. * ****************************************************************************/ void x86_64_restore_auxstate(struct tcb_s *rtcb) { /* Set PCID, avoid TLB flush */ set_pcid(rtcb->pid); }
c727cec317864cb622a19fbbb667a1fed565e285
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/arch/vax/vax/ka680.c
36372cf417c2203c38b4c4f9145feffa61a3e04d
[]
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
7,220
c
ka680.c
/* $NetBSD: ka680.c,v 1.18 2017/05/22 16:46:15 ragge Exp $ */ /* * Copyright (c) 2002 Hugh Graham. * Copyright (c) 2000 Ludd, University of Lule}, Sweden. * 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. * 3. The name of the author 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 ``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. */ /* Done by Michael Kukat (michael@unixiron.org) */ /* minor modifications for KA690 cache support by isildur@vaxpower.org */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: ka680.c,v 1.18 2017/05/22 16:46:15 ragge Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/cpu.h> #include <sys/device.h> #include <sys/kernel.h> #include <machine/sid.h> #include <machine/nexus.h> #include <machine/ka680.h> #include <machine/clock.h> #include <machine/scb.h> static void ka680_conf(void); static void ka680_attach_cpu(device_t); static void ka680_cache_enable(void); static void ka680_softmem(void *); static void ka680_hardmem(void *); static void ka680_steal_pages(void); static void ka680_memerr(void); static int ka680_mchk(void *); /* * KA680-specific IPRs. KA680 has the funny habit to control all caches * via IPRs. */ #define PR_CCTL 0xa0 #define CCTL_ENABLE 0x00000001 #define CCTL_SW_ETM 0x40000000 #define CCTL_HW_ETM 0x80000000 #define PR_BCETSTS 0xa3 #define PR_BCEDSTS 0xa6 #define PR_NESTS 0xae #define PR_VMAR 0xd0 #define PR_VTAG 0xd1 #define PR_ICSR 0xd3 #define ICSR_ENABLE 0x01 #define PR_PCCTL 0xf8 #define PCCTL_P_EN 0x10 #define PCCTL_I_EN 0x02 #define PCCTL_D_EN 0x01 static const char * const ka680_devs[] = { "cpu", "sgec", "shac", "uba", NULL }; /* * Declaration of KA680-specific calls. */ const struct cpu_dep ka680_calls = { .cpu_steal_pages = ka680_steal_pages, .cpu_mchk = ka680_mchk, .cpu_memerr = ka680_memerr, .cpu_conf = ka680_conf, .cpu_gettime = generic_gettime, .cpu_settime = generic_settime, .cpu_vups = 24, /* ~VUPS */ .cpu_scbsz = 2, /* SCB pages */ .cpu_halt = generic_halt, .cpu_reboot = generic_reboot, .cpu_flags = CPU_RAISEIPL, .cpu_devs = ka680_devs, .cpu_attach_cpu = ka680_attach_cpu, }; void ka680_conf(void) { /* Don't ask why, but we seem to need this... */ volatile int *hej = (void *)mfpr(PR_ISP); *hej = *hej; hej[-1] = hej[-1]; cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1); } void ka680_attach_cpu(device_t self) { const char *cpuname; switch (vax_boardtype) { case VAX_BTYP_680: switch((vax_siedata & 0xff00) >> 8) { case VAX_STYP_675: cpuname = "KA675"; break; case VAX_STYP_680: cpuname = "KA680"; break; case VAX_STYP_690: cpuname = "KA690"; break; default: cpuname = "unknown KA680-class"; } break; case VAX_BTYP_681: switch ((vax_siedata & 0xff00) >> 8) { case VAX_STYP_681: cpuname = "KA681"; break; case VAX_STYP_691: cpuname = "KA691"; break; case VAX_STYP_694: cpuname = (vax_cpudata & 0x1000) ? "KA694" : "KA692"; break; default: cpuname = "unknown KA681-class"; } break; default: cpuname = "unknown class"; break; } aprint_normal("%s, NVAX (ucode rev %d)\n", cpuname, vax_cpudata & 0xff); } void ka680_cache_enable(void) { int start, pslut, fslut, cslut, havevic; /* * Turn caches off. */ mtpr(0, PR_ICSR); mtpr(0, PR_PCCTL); mtpr(mfpr(PR_CCTL) | CCTL_SW_ETM, PR_CCTL); /* * Invalidate caches. */ mtpr(mfpr(PR_CCTL) | 6, PR_CCTL); /* Set cache size and speed */ mtpr(mfpr(PR_BCETSTS), PR_BCETSTS); /* Clear error bits */ mtpr(mfpr(PR_BCEDSTS), PR_BCEDSTS); /* Clear error bits */ mtpr(mfpr(PR_NESTS), PR_NESTS); /* Clear error bits */ start = 0x01400000; /* fallback, use smallest known cache on unknown models */ fslut = 0x01420000; cslut = 0x01020000; havevic = 0; switch(vax_boardtype) { case VAX_BTYP_680: switch((vax_siedata & 0xff00) >> 8) { case VAX_STYP_675: fslut = 0x01420000; cslut = 0x01020000; havevic = 0; break; case VAX_STYP_680: fslut = 0x01420000; cslut = 0x01020000; havevic = 1; break; case VAX_STYP_690: fslut = 0x01440000; cslut = 0x01040000; havevic = 1; break; } case VAX_BTYP_681: switch((vax_siedata & 0xff00) >> 8) { case VAX_STYP_681: fslut = 0x01420000; cslut = 0x01020000; havevic = 1; break; case VAX_STYP_691: fslut = 0x01420000; cslut = 0x01020000; havevic = 1; break; case VAX_STYP_694: fslut = 0x01440000; cslut = 0x01040000; havevic = 1; break; } } /* Flush cache lines */ for (; start < fslut; start += 0x20) mtpr(0, start); mtpr((mfpr(PR_CCTL) & ~(CCTL_SW_ETM|CCTL_ENABLE)) | CCTL_HW_ETM, PR_CCTL); start = 0x01000000; /* clear tag and valid */ for (; start < cslut; start += 0x20) mtpr(0, start); mtpr(mfpr(PR_CCTL) | 6 | CCTL_ENABLE, PR_CCTL); /* enab. bcache */ start = 0x01800000; pslut = 0x01802000; /* Clear primary cache */ for (; start < pslut; start += 0x20) mtpr(0, start); /* Flush the pipes (via REI) */ __asm("movpsl -(%sp); movab 1f,-(%sp); rei; 1:;"); /* Enable primary cache */ mtpr(PCCTL_P_EN|PCCTL_I_EN|PCCTL_D_EN, PR_PCCTL); /* Enable the VIC */ if (havevic) { int slut; start = 0; slut = 0x800; for (; start < slut; start += 0x20) { mtpr(start, PR_VMAR); mtpr(0, PR_VTAG); } mtpr(ICSR_ENABLE, PR_ICSR); } } /* * Why may we get memory errors during startup??? */ void ka680_hardmem(void *arg) { if (cold == 0) printf("Hard memory error\n"); splhigh(); } void ka680_softmem(void *arg) { if (cold == 0) printf("Soft memory error\n"); splhigh(); } void ka680_steal_pages(void) { /* * Get the soft and hard memory error vectors now. */ scb_vecalloc(0x54, ka680_softmem, NULL, 0, NULL); scb_vecalloc(0x60, ka680_hardmem, NULL, 0, NULL); /* Turn on caches (to speed up execution a bit) */ ka680_cache_enable(); } void ka680_memerr(void) { printf("Memory err!\n"); } int ka680_mchk(void *addr) { panic("Machine check"); return 0; }
5a01554b59ae80089dad9c05e845cb6914681192
75732426f13d523ab1c7be7bee23c2152eb9a77c
/libs/framework/src/manifest_parser.c
af31137417f987b223942a5e4f7f01a6ebf3676d
[ "Apache-2.0", "BSD-3-Clause", "MIT" ]
permissive
apache/celix
841da4d364432bff49c796f908d64090cec1d759
28118976b802f421f4789ece0c15e791f542712f
refs/heads/master
2023-09-04T22:17:43.815664
2023-09-04T01:22:00
2023-09-04T01:22:00
22,781,134
158
114
Apache-2.0
2023-09-12T01:22:30
2014-08-09T07:00:07
C
UTF-8
C
false
false
3,890
c
manifest_parser.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. */ /** * manifest_parser.c * * \date Jul 12, 2010 * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a> * \copyright Apache License, Version 2.0 */ #include <stdlib.h> #include <string.h> #include "utils.h" #include "celix_utils.h" #include "celix_constants.h" #include "manifest_parser.h" #include "capability.h" #include "requirement.h" #include "hash_map.h" #include "celix_errno.h" #include "linked_list_iterator.h" #include "celix_log.h" struct manifestParser { module_pt owner; manifest_pt manifest; version_pt bundleVersion; //TODO: Implement Requirement-Capability-Model using RCM library }; celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { celix_status_t status; manifest_parser_pt parser; status = CELIX_SUCCESS; parser = (manifest_parser_pt) malloc(sizeof(*parser)); if (parser) { const char * bundleVersion = NULL; parser->manifest = manifest; parser->owner = owner; bundleVersion = manifest_getValue(manifest, OSGI_FRAMEWORK_BUNDLE_VERSION); if (bundleVersion != NULL) { parser->bundleVersion = NULL; version_createVersionFromString(bundleVersion, &parser->bundleVersion); } else { parser->bundleVersion = NULL; version_createEmptyVersion(&parser->bundleVersion); } *manifest_parser = parser; status = CELIX_SUCCESS; } else { status = CELIX_ENOMEM; } framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create manifest parser"); return status; } celix_status_t manifestParser_destroy(manifest_parser_pt mp) { version_destroy(mp->bundleVersion); mp->bundleVersion = NULL; mp->manifest = NULL; mp->owner = NULL; free(mp); return CELIX_SUCCESS; } static celix_status_t manifestParser_getDuplicateEntry(manifest_parser_pt parser, const char* entryName, char **result) { const char *val = manifest_getValue(parser->manifest, entryName); if (result != NULL && val == NULL) { *result = NULL; } else if (result != NULL) { *result = celix_utils_strdup(val); } return CELIX_SUCCESS; } celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group) { return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_GROUP, group); } celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName) { return manifestParser_getDuplicateEntry(parser, OSGI_FRAMEWORK_BUNDLE_SYMBOLICNAME, symbolicName); } celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name) { return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_NAME, name); } celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description) { return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_DESCRIPTION, description); } celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version) { return version_clone(parser->bundleVersion, version); }
c489e947d4ad31f3a9b062794546bec32430b731
64dca62dd18660e93f14b5f173df16b8ef9ab80e
/src/deark-dbuf.c
b0ce6daec067ff9bf53ae26f898a53edca85834c
[ "MIT" ]
permissive
jsummers/deark
44086f9772a6e8a5ab70b3ed00c55dedf1f9637d
0ef4d1a13b6658206135cda3f07fd062d296911d
refs/heads/master
2023-09-03T16:53:22.581091
2023-08-28T15:49:31
2023-08-28T15:49:54
18,972,953
139
17
NOASSERTION
2023-07-18T14:03:53
2014-04-20T20:14:04
C
UTF-8
C
false
false
65,764
c
deark-dbuf.c
// This file is part of Deark. // Copyright (C) 2016 Jason Summers // See the file COPYING for terms of use. // deark-dbuf.c // // Functions related to the dbuf object. #define DE_NOT_IN_MODULE #include "deark-config.h" #include "deark-private.h" #define DE_DUMMY_MAX_FILE_SIZE (1LL<<56) #define DE_MAX_MEMBUF_SIZE 2000000000 #define DE_RCACHE_SIZE 262144 #define DE_WBUFFER_SIZE 512 // Support at least this many virtual bytes before or after the actual file. #define DE_ALLOWED_VIRTUAL_BYTES 16384 // Fill the cache that remembers the first part of the file. // TODO: We should probably use memory-mapped files instead when possible, // but this is simple and portable, and does most of what we need. static void populate_rcache(dbuf *f) { i64 bytes_to_read; i64 bytes_read; if(f->btype!=DBUF_TYPE_IFILE) return; bytes_to_read = DE_RCACHE_SIZE; if(f->len < bytes_to_read) { bytes_to_read = f->len; } f->rcache = de_malloc(f->c, DE_RCACHE_SIZE); de_fseek(f->fp, 0, SEEK_SET); bytes_read = fread(f->rcache, 1, (size_t)bytes_to_read, f->fp); f->rcache_bytes_used = bytes_read; f->file_pos_known = 0; } // Read all data from stdin (or a named pipe) into memory. static void populate_rcache_from_pipe(dbuf *f) { FILE *fp; i64 cache_bytes_alloc = 0; if(f->btype==DBUF_TYPE_STDIN) { fp = stdin; } else if(f->btype==DBUF_TYPE_FIFO) { fp = f->fp; } else { return; } f->rcache_bytes_used = 0; while(1) { i64 bytes_to_read, bytes_read; if(f->rcache_bytes_used >= cache_bytes_alloc) { i64 old_cache_size, new_cache_size; // Cache is full. Increase its size. old_cache_size = cache_bytes_alloc; new_cache_size = old_cache_size*2; if(new_cache_size<DE_RCACHE_SIZE) new_cache_size = DE_RCACHE_SIZE; f->rcache = de_realloc(f->c, f->rcache, old_cache_size, new_cache_size); cache_bytes_alloc = new_cache_size; } // Try to read as many bytes as it would take to fill the cache. bytes_to_read = cache_bytes_alloc - f->rcache_bytes_used; if(bytes_to_read<1) break; // Shouldn't happen bytes_read = fread(&f->rcache[f->rcache_bytes_used], 1, (size_t)bytes_to_read, fp); if(bytes_read<1 || bytes_read>bytes_to_read) break; f->rcache_bytes_used += bytes_read; if(feof(fp) || ferror(fp)) break; } f->len = f->rcache_bytes_used; } // Use if we read a 'offset' field representing an absolute file position. // Returns 0 if we changed *plen. int dbuf_constrain_offset(dbuf *f, i64 *ppos) { return de_constrain_int(ppos, 0, f->len); } // Use if we read a 'length' field associated with a segment with a known offset. // pos should be a valid position for this dbuf: // 0 to f->len inclusive. If not, sets *plen to 0, and returns 0. // Returns 0 if we changed *plen. int dbuf_constrain_length(dbuf *f, i64 pos, i64 *plen) { i64 maxlen; if(*plen < 0 || pos < 0 || pos > f->len ) { *plen = 0; return 0; } maxlen = f->len - pos; if(*plen > maxlen) { *plen = maxlen; return 0; } return 1; } // Read len bytes, starting at file position pos, into buf. // Unread bytes will be set to 0. void dbuf_read(dbuf *f, u8 *buf, i64 pos, i64 len) { i64 bytes_read = 0; i64 bytes_to_read; deark *c; c = f->c; if(len <= 0) goto done_read; if(len > DE_MAX_MALLOC) { de_fatalerror(c); return; } if(pos < 0) { if(pos <= (-len)) { // All requested bytes are before the beginning of the file de_zeromem(buf, (size_t)len); return; } // Some requested bytes are before the beginning of the file. // Zero out the ones that are: de_zeromem(buf, (size_t)(-pos)); // And adjust the parameters: buf += (-pos); len -= (-pos); pos = 0; } bytes_to_read = len; if(pos >= f->len) { bytes_to_read = 0; } else if(pos + bytes_to_read > f->len) { bytes_to_read = f->len - pos; } if(bytes_to_read<1) { goto done_read; } // If the data we need is all cached, get it from cache. if(f->rcache && pos >= 0 && pos + bytes_to_read <= f->rcache_bytes_used) { de_memcpy(buf, &f->rcache[pos], (size_t)bytes_to_read); bytes_read = bytes_to_read; goto done_read; } switch(f->btype) { case DBUF_TYPE_IFILE: if(!f->fp) { de_internal_err_fatal(c, "File not open"); goto done_read; } // For performance reasons, don't call fseek if we're already at the // right position. if(!f->file_pos_known || f->file_pos!=pos) { de_fseek(f->fp, pos, SEEK_SET); } bytes_read = fread(buf, 1, (size_t)bytes_to_read, f->fp); f->file_pos = pos + bytes_read; f->file_pos_known = 1; break; case DBUF_TYPE_IDBUF: // Recursive call to the parent dbuf. dbuf_read(f->parent_dbuf, buf, f->offset_into_parent_dbuf+pos, bytes_to_read); // The parent dbuf always writes 'bytes_to_read' bytes. bytes_read = bytes_to_read; break; case DBUF_TYPE_MEMBUF: de_memcpy(buf, &f->membuf_buf[pos], (size_t)bytes_to_read); bytes_read = bytes_to_read; break; default: de_internal_err_fatal(c, "getbytes from this I/O type not implemented"); goto done_read; } done_read: // Zero out any requested bytes that were not read. if(bytes_read < len) { de_zeromem(buf+bytes_read, (size_t)(len - bytes_read)); } } // A function that works a little more like a standard read/fread function than // does dbuf_read. It returns the number of bytes read, won't read past end of // file, and helps track the file position. i64 dbuf_standard_read(dbuf *f, u8 *buf, i64 n, i64 *fpos) { i64 amt_to_read; if(*fpos < 0 || *fpos >= f->len) return 0; amt_to_read = n; if(*fpos + amt_to_read > f->len) amt_to_read = f->len - *fpos; dbuf_read(f, buf, *fpos, amt_to_read); *fpos += amt_to_read; return amt_to_read; } u8 dbuf_getbyte(dbuf *f, i64 pos) { u8 b; if(pos<0 || pos>=f->len) return 0x00; if(pos<f->rcache_bytes_used) { return f->rcache[pos]; } if(f->btype==DBUF_TYPE_MEMBUF) { return f->membuf_buf[pos]; } dbuf_read(f, &b, pos, 1); return b; } i64 de_geti8_direct(const u8 *m) { u8 b = m[0]; if(b<=127) return (i64)b; return ((i64)b)-256; } i64 dbuf_geti8(dbuf *f, i64 pos) { u8 b; b = dbuf_getbyte(f, pos); return de_geti8_direct(&b); } u8 dbuf_getbyte_p(dbuf *f, i64 *ppos) { u8 b; b = dbuf_getbyte(f, *ppos); (*ppos)++; return b; } static i64 dbuf_getuint_ext_be_direct(const u8 *m, unsigned int nbytes) { unsigned int k; u64 val = 0; for(k=0; k<nbytes; k++) { if(val>0x00ffffffffffffffULL) return 0; val = (val<<8) | (u64)m[k]; } return (i64)val; } static i64 dbuf_getint_ext_be_direct(const u8 *m, unsigned int nbytes) { unsigned int k; u64 val = 0; // We can handle up to 8 arbitrary bytes. Any more have to be 0xff. if(nbytes>8) { for(k=0; k<nbytes-8; k++) { if(m[k]!=0xff) return 0; // underflow } } // Process bytes in order of increasing significance for(k=0; k<8; k++) { u8 byteval; if(k<nbytes) { byteval = m[nbytes-1-k]; } else { byteval = 0xff; } val |= ((u64)byteval) << (k*8); } return (i64)val; } static i64 dbuf_getuint_ext_le_direct(const u8 *m, unsigned int nbytes) { unsigned int k; u64 val = 0; for(k=0; k<nbytes; k++) { if(m[k]!=0) { if(k>7) return 0; val |= ((u64)m[k])<<(k*8); } } return (i64)val; } static i64 dbuf_getuint_ext_x(dbuf *f, i64 pos, unsigned int nbytes, int is_le) { u8 m[24]; if(nbytes>(unsigned int)sizeof(m)) return 0; dbuf_read(f, m, pos, (i64)nbytes); if(is_le) { return dbuf_getuint_ext_le_direct(m, nbytes); } return dbuf_getuint_ext_be_direct(m, nbytes); } static i64 dbuf_getint_ext_x(dbuf *f, i64 pos, unsigned int nbytes, int is_le) { u8 m[24]; if(nbytes>(unsigned int)sizeof(m)) return 0; dbuf_read(f, m, pos, (i64)nbytes); if(is_le) { return 0; // TODO } return dbuf_getint_ext_be_direct(m, nbytes); } i64 de_getu16be_direct(const u8 *m) { return (i64)(((u32)m[1]) | (((u32)m[0])<<8)); } i64 dbuf_getu16be(dbuf *f, i64 pos) { u8 m[2]; dbuf_read(f, m, pos, 2); return de_getu16be_direct(m); } i64 dbuf_getu16be_p(dbuf *f, i64 *ppos) { u8 m[2]; dbuf_read(f, m, *ppos, 2); (*ppos) += 2; return de_getu16be_direct(m); } i64 de_getu16le_direct(const u8 *m) { return (i64)(((u32)m[0]) | (((u32)m[1])<<8)); } i64 dbuf_getu16le(dbuf *f, i64 pos) { u8 m[2]; dbuf_read(f, m, pos, 2); return de_getu16le_direct(m); } i64 dbuf_getu16le_p(dbuf *f, i64 *ppos) { u8 m[2]; dbuf_read(f, m, *ppos, 2); (*ppos) += 2; return de_getu16le_direct(m); } i64 dbuf_geti16be(dbuf *f, i64 pos) { i64 n; n = dbuf_getu16be(f, pos); if(n>=32768) n -= 65536; return n; } i64 dbuf_geti16le(dbuf *f, i64 pos) { i64 n; n = dbuf_getu16le(f, pos); if(n>=32768) n -= 65536; return n; } i64 dbuf_geti16be_p(dbuf *f, i64 *ppos) { i64 n; n = dbuf_geti16be(f, *ppos); (*ppos) += 2; return n; } i64 dbuf_geti16le_p(dbuf *f, i64 *ppos) { i64 n; n = dbuf_geti16le(f, *ppos); (*ppos) += 2; return n; } i64 de_getu32be_direct(const u8 *m) { return (i64)(((u32)m[3]) | (((u32)m[2])<<8) | (((u32)m[1])<<16) | (((u32)m[0])<<24)); } i64 dbuf_getu32be(dbuf *f, i64 pos) { u8 m[4]; dbuf_read(f, m, pos, 4); return de_getu32be_direct(m); } i64 dbuf_getu32be_p(dbuf *f, i64 *ppos) { u8 m[4]; dbuf_read(f, m, *ppos, 4); (*ppos) += 4; return de_getu32be_direct(m); } i64 de_getu32le_direct(const u8 *m) { return (i64)(((u32)m[0]) | (((u32)m[1])<<8) | (((u32)m[2])<<16) | (((u32)m[3])<<24)); } i64 dbuf_getu32le(dbuf *f, i64 pos) { u8 m[4]; dbuf_read(f, m, pos, 4); return de_getu32le_direct(m); } i64 dbuf_getu32le_p(dbuf *f, i64 *ppos) { u8 m[4]; dbuf_read(f, m, *ppos, 4); (*ppos) += 4; return de_getu32le_direct(m); } i64 dbuf_geti32be(dbuf *f, i64 pos) { i64 n; n = dbuf_getu32be(f, pos); return (i64)(i32)(u32)n; } i64 dbuf_geti32le(dbuf *f, i64 pos) { i64 n; n = dbuf_getu32le(f, pos); return (i64)(i32)(u32)n; } i64 dbuf_geti32be_p(dbuf *f, i64 *ppos) { i64 n; n = dbuf_geti32be(f, *ppos); (*ppos) += 4; return n; } i64 dbuf_geti32le_p(dbuf *f, i64 *ppos) { i64 n; n = dbuf_geti32le(f, *ppos); (*ppos) += 4; return n; } u64 de_getu64be_direct(const u8 *m) { unsigned int i; u64 val = 0; for(i=0; i<8; i++) { val |= ((u64)m[i])<<((7-i)*8); } return val; } i64 de_geti64be_direct(const u8 *m) { return (i64)de_getu64be_direct(m); } i64 dbuf_geti64be(dbuf *f, i64 pos) { u8 m[8]; dbuf_read(f, m, pos, 8); return de_geti64be_direct(m); } u64 de_getu64le_direct(const u8 *m) { unsigned int i; u64 val = 0; for(i=0; i<8; i++) { val |= ((u64)m[i])<<(i*8); } return val; } i64 de_geti64le_direct(const u8 *m) { return (i64)de_getu64le_direct(m); } i64 dbuf_geti64le(dbuf *f, i64 pos) { u8 m[8]; dbuf_read(f, m, pos, 8); return de_geti64le_direct(m); } i64 dbuf_getu16x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_getu16le(f, pos); return dbuf_getu16be(f, pos); } i64 dbuf_geti16x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_geti16le(f, pos); return dbuf_geti16be(f, pos); } i64 dbuf_getu32x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_getu32le(f, pos); return dbuf_getu32be(f, pos); } i64 dbuf_geti32x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_geti32le(f, pos); return dbuf_geti32be(f, pos); } i64 dbuf_geti64x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_geti64le(f, pos); return dbuf_geti64be(f, pos); } u64 dbuf_getu64be(dbuf *f, i64 pos) { u8 m[8]; dbuf_read(f, m, pos, 8); return de_getu64be_direct(m); } u64 dbuf_getu64le(dbuf *f, i64 pos) { u8 m[8]; dbuf_read(f, m, pos, 8); return de_getu64le_direct(m); } u64 dbuf_getu64x(dbuf *f, i64 pos, int is_le) { if(is_le) return dbuf_getu64le(f, pos); return dbuf_getu64be(f, pos); } i64 dbuf_getint_ext(dbuf *f, i64 pos, unsigned int nbytes, int is_le, int is_signed) { if(is_signed) { // TODO: Extend this to any number of bytes, 1-8. switch(nbytes) { case 1: return (i64)(signed char)dbuf_getbyte(f, pos); break; case 2: return dbuf_geti16x(f, pos, is_le); break; case 4: return dbuf_geti32x(f, pos, is_le); break; case 8: return dbuf_geti64x(f, pos, is_le); break; default: return dbuf_getint_ext_x(f, pos, nbytes, is_le); } } else { switch(nbytes) { case 1: return (i64)dbuf_getbyte(f, pos); break; case 2: return dbuf_getu16x(f, pos, is_le); break; case 4: return dbuf_getu32x(f, pos, is_le); break; case 8: return dbuf_geti64x(f, pos, is_le); break; default: return dbuf_getuint_ext_x(f, pos, nbytes, is_le); } } return 0; } static void init_fltpt_decoder(deark *c) { unsigned int x = 1; char b = 0; c->can_decode_fltpt = 0; if(sizeof(float)!=4) return; if(sizeof(double)!=8) return; c->can_decode_fltpt = 1; de_memcpy(&b, &x, 1); if(b==0) c->host_is_le = 0; else c->host_is_le = 1; } double de_getfloat32x_direct(deark *c, const u8 *m, int is_le) { char buf[4]; float val = 0.0; if(c->can_decode_fltpt<0) { init_fltpt_decoder(c); } if(!c->can_decode_fltpt) return 0.0; // FIXME: This assumes that the native floating point format is // IEEE 754, but that does not have to be the case. de_memcpy(buf, m, 4); if(is_le != c->host_is_le) { int i; char tmpc; // Reverse order of bytes for(i=0; i<2; i++) { tmpc = buf[i]; buf[i] = buf[3-i]; buf[3-i] = tmpc; } } de_memcpy(&val, buf, 4); return (double)val; } double dbuf_getfloat32x(dbuf *f, i64 pos, int is_le) { u8 buf[4]; dbuf_read(f, buf, pos, 4); return de_getfloat32x_direct(f->c, buf, is_le); } double de_getfloat64x_direct(deark *c, const u8 *m, int is_le) { char buf[8]; double val = 0.0; if(c->can_decode_fltpt<0) { init_fltpt_decoder(c); } if(!c->can_decode_fltpt) return 0.0; de_memcpy(buf, m, 8); if(is_le != c->host_is_le) { int i; char tmpc; // Reverse order of bytes for(i=0; i<4; i++) { tmpc = buf[i]; buf[i] = buf[7-i]; buf[7-i] = tmpc; } } de_memcpy(&val, buf, 8); return (double)val; } double dbuf_getfloat64x(dbuf *f, i64 pos, int is_le) { u8 buf[8]; dbuf_read(f, buf, pos, 8); return de_getfloat64x_direct(f->c, buf, is_le); } int dbuf_read_ascii_number(dbuf *f, i64 pos, i64 fieldsize, int base, i64 *value) { char buf[32]; *value = 0; if(fieldsize>(i64)(sizeof(buf)-1)) return 0; dbuf_read(f, (u8*)buf, pos, fieldsize); buf[fieldsize] = '\0'; *value = de_strtoll(buf, NULL, base); return 1; } de_color dbuf_getRGB(dbuf *f, i64 pos, unsigned int flags) { u8 buf[3]; dbuf_read(f, buf, pos, 3); if(flags&DE_GETRGBFLAG_BGR) return DE_MAKE_RGB(buf[2], buf[1], buf[0]); return DE_MAKE_RGB(buf[0], buf[1], buf[2]); } static int copy_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { dbuf *outf = (dbuf*)brctx->userdata; dbuf_write(outf, buf, buf_len); return 1; } void dbuf_copy(dbuf *inf, i64 input_offset, i64 input_len, dbuf *outf) { u8 tmpbuf[256]; // Fast paths, if the data to copy is all in memory if(inf->rcache && (input_offset>=0) && (input_offset+input_len<=inf->rcache_bytes_used)) { dbuf_write(outf, &inf->rcache[input_offset], input_len); return; } if(inf->btype==DBUF_TYPE_MEMBUF && (input_offset>=0) && (input_offset+input_len<=inf->len)) { dbuf_write(outf, &inf->membuf_buf[input_offset], input_len); return; } if(input_len<=(i64)sizeof(tmpbuf)) { // Fast path for small sizes dbuf_read(inf, tmpbuf, input_offset, input_len); dbuf_write(outf, tmpbuf, input_len); return; } dbuf_buffered_read(inf, input_offset, input_len, copy_cbfn, (void*)outf); } struct copy_at_ctx { dbuf *outf; i64 outpos; }; static int copy_at_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { struct copy_at_ctx *ctx = (struct copy_at_ctx*)brctx->userdata; dbuf_write_at(ctx->outf, ctx->outpos, buf, buf_len); ctx->outpos += buf_len; return 1; } void dbuf_copy_at(dbuf *inf, i64 input_offset, i64 input_len, dbuf *outf, i64 output_offset) { struct copy_at_ctx ctx; ctx.outf = outf; ctx.outpos = output_offset; dbuf_buffered_read(inf, input_offset, input_len, copy_at_cbfn, (void*)&ctx); } // An advanced function for reading a string from a file. // The issue is that some strings are both human-readable and machine-readable. // In such a case, we'd like to read some data from a file into a nice printable // ucstring, while also making some or all of the raw bytes available, say for // byte-for-byte string comparisons. // Plus (for NUL-terminated/padded strings), we may need to know the actual length // of the string in the file, so that it can be skipped over, even if we don't // care about the whole string. // Caller is responsible for calling destroy_stringreader() on the returned value. // max_bytes_to_scan: The maximum number of bytes to read from the file. // max_bytes_to_keep: The maximum (or in some cases the exact) number of bytes, // not counting any NUL terminator, to return in ->sz. // The ->str field is a Unicode version of ->sz, so this also affects ->str. // If DE_CONVFLAG_STOP_AT_NUL is not set, it is assumed we are reading a string // of known length, that may have internal NUL bytes. The caller must set // max_bytes_to_scan and max_bytes_to_keep to the same value. The ->sz field will // always be allocated with this many bytes, plus one more for an artificial NUL // terminator. // If DE_CONVFLAG_WANT_UTF8 is set, then the ->sz_utf8 field will be set to a // UTF-8 version of ->str. This is mainly useful if the original string was // UTF-16. sz_utf8 is not "printable" -- use ucstring_get_printable_sz_n(str) for // that. // ->sz_strlen will equal strlen(->sz) if DE_CONVFLAG_STOP_AT_NUL is set, or // the supplied value of max_bytes_to_(scan|keep) if not. // Recognized flags: // - DE_CONVFLAG_STOP_AT_NUL // - DE_CONVFLAG_WANT_UTF8 struct de_stringreaderdata *dbuf_read_string(dbuf *f, i64 pos, i64 max_bytes_to_scan, i64 max_bytes_to_keep, unsigned int flags, de_ext_encoding ee) { deark *c = f->c; struct de_stringreaderdata *srd; i64 foundpos = 0; int ret; i64 bytes_avail_to_read; i64 bytes_to_malloc; i64 x_strlen = 0; srd = de_malloc(c, sizeof(struct de_stringreaderdata)); srd->str = ucstring_create(c); if(max_bytes_to_scan<0) max_bytes_to_scan = 0; if(max_bytes_to_keep<0) max_bytes_to_keep = 0; bytes_avail_to_read = max_bytes_to_scan; if(bytes_avail_to_read > f->len-pos) { bytes_avail_to_read = f->len-pos; } if(bytes_avail_to_read<0) bytes_avail_to_read = 0; srd->bytes_consumed = bytes_avail_to_read; // default // From here on, we can safely bail out ("goto done"). The // de_stringreaderdata struct is sufficiently valid. if(!(flags&DE_CONVFLAG_STOP_AT_NUL) && (max_bytes_to_scan != max_bytes_to_keep)) { // To reduce possible confusion, we require that // max_bytes_to_scan==max_bytes_to_keep in this case. srd->sz = de_malloc(c, max_bytes_to_keep+1); goto done; } if(flags&DE_CONVFLAG_STOP_AT_NUL) { ret = dbuf_search_byte(f, 0x00, pos, bytes_avail_to_read, &foundpos); if(ret) { srd->found_nul = 1; } else { // No NUL byte found. Could be an error in some formats, but in // others NUL is used as separator or as padding, not a terminator. foundpos = pos+bytes_avail_to_read; } x_strlen = foundpos-pos; srd->bytes_consumed = x_strlen+1; } else { x_strlen = max_bytes_to_keep; srd->bytes_consumed = x_strlen; } bytes_to_malloc = x_strlen+1; if(bytes_to_malloc>(max_bytes_to_keep+1)) { bytes_to_malloc = max_bytes_to_keep+1; srd->was_truncated = 1; } srd->sz = de_malloc(c, bytes_to_malloc); dbuf_read(f, (u8*)srd->sz, pos, bytes_to_malloc-1); // The last byte remains NUL ucstring_append_bytes(srd->str, (const u8*)srd->sz, bytes_to_malloc-1, 0, ee); if(flags&DE_CONVFLAG_WANT_UTF8) { srd->sz_utf8_strlen = (size_t)ucstring_count_utf8_bytes(srd->str); srd->sz_utf8 = de_malloc(c, (i64)srd->sz_utf8_strlen + 1); ucstring_to_sz(srd->str, srd->sz_utf8, srd->sz_utf8_strlen + 1, 0, DE_ENCODING_UTF8); } done: if(!srd->sz) { // Always return a valid sz, even on failure. srd->sz = de_malloc(c, 1); } if((flags&DE_CONVFLAG_WANT_UTF8) && !srd->sz_utf8) { // Always return a valid sz_utf8 if it was requested, even on failure. srd->sz_utf8 = de_malloc(c, 1); srd->sz_utf8_strlen = 0; } srd->sz_strlen = (size_t)x_strlen; return srd; } void de_destroy_stringreaderdata(deark *c, struct de_stringreaderdata *srd) { if(!srd) return; de_free(c, srd->sz); de_free(c, srd->sz_utf8); ucstring_destroy(srd->str); de_free(c, srd); } void dbuf_read_to_ucstring_ex(dbuf *f, i64 pos1, i64 len, de_ucstring *s, unsigned int conv_flags, struct de_encconv_state *es) { i64 nbytes_remaining; i64 pos = pos1; int stop_at_nul = 0; #define READTOUCSTRING_BUFLEN 256 u8 buf[READTOUCSTRING_BUFLEN]; if(conv_flags & DE_CONVFLAG_STOP_AT_NUL) { stop_at_nul = 1; // We handle STOP_AT_NUL ourselves, so don't pass it on. conv_flags -= DE_CONVFLAG_STOP_AT_NUL; } // Note: It might be sensible to use dbuf_buffered_read() here, but I've // decided against it for now. nbytes_remaining = len; do { i64 nbytes_to_read; i64 nbytes_in_buf; unsigned int conv_flags_to_use_this_time; // Lack of DE_CONVFLAG_PARTIAL_DATA flag signals end of data, which // isn't necessarily a no-op even with len=0. // That's why we always do this loop at least once. nbytes_to_read = de_min_int(nbytes_remaining, READTOUCSTRING_BUFLEN); dbuf_read(f, buf, pos, nbytes_to_read); pos += nbytes_to_read; nbytes_in_buf = nbytes_to_read; nbytes_remaining -= nbytes_to_read; if(stop_at_nul) { char *tmpp; tmpp = de_memchr(buf, 0x00, (size_t)nbytes_in_buf); if(tmpp) { nbytes_in_buf = (const u8*)tmpp - buf; nbytes_remaining = 0; } } conv_flags_to_use_this_time = conv_flags; if(nbytes_remaining>0) { // The caller may have already set this flag, in which case we will use // it every time. // If not, we still use it for all but the final call to ucstring_append_bytes_ex(). conv_flags_to_use_this_time |= DE_CONVFLAG_PARTIAL_DATA; } ucstring_append_bytes_ex(s, buf, nbytes_in_buf, conv_flags_to_use_this_time, es); } while(nbytes_remaining>0); } // Read (up to) len bytes from f, translate them to characters, and append // them to s. void dbuf_read_to_ucstring(dbuf *f, i64 pos, i64 len, de_ucstring *s, unsigned int conv_flags, de_ext_encoding ee) { struct de_encconv_state es; de_encconv_init(&es, ee); dbuf_read_to_ucstring_ex(f, pos, len, s, conv_flags, &es); } void dbuf_read_to_ucstring_n(dbuf *f, i64 pos, i64 len, i64 max_len, de_ucstring *s, unsigned int conv_flags, de_ext_encoding ee) { struct de_encconv_state es; if(len>max_len) len = max_len; de_encconv_init(&es, ee); dbuf_read_to_ucstring_ex(f, pos, len, s, conv_flags, &es); } static int dbufmemcmp_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { // Return 0 if there is a mismatch. return !de_memcmp(buf, &(((const u8*)brctx->userdata)[brctx->offset]), (size_t)buf_len); } int dbuf_memcmp(dbuf *f, i64 pos, const void *s, size_t n) { u8 buf1[128]; if(f->rcache && pos >= 0 && pos + (i64)n <= f->rcache_bytes_used) { // Fastest path: Compare directly to cache. return de_memcmp(s, &f->rcache[pos], n); } if(n<=sizeof(buf1)) { // Use a stack buffer if small enough. dbuf_read(f, buf1, pos, n); return de_memcmp(buf1, s, n); } // Fallback method. return !dbuf_buffered_read(f, pos, n, dbufmemcmp_cbfn, (void*)s); } int dbuf_create_file_from_slice(dbuf *inf, i64 pos, i64 data_size, const char *ext, de_finfo *fi, unsigned int createflags) { dbuf *f; f = dbuf_create_output_file(inf->c, ext, fi, createflags); if(!f) return 0; dbuf_copy(inf, pos, data_size, f); dbuf_close(f); return 1; } static void finfo_shallow_copy(deark *c, de_finfo *src, de_finfo *dst) { UI k; dst->is_directory = src->is_directory; dst->is_volume_label = src->is_volume_label; dst->has_riscos_data = src->has_riscos_data; dst->riscos_appended_type = src->riscos_appended_type; dst->riscos_attribs = src->riscos_attribs; dst->mode_flags = src->mode_flags; for(k=0; k<DE_TIMESTAMPIDX_COUNT; k++) { dst->timestamp[k] = src->timestamp[k]; } dst->internal_mod_time = src->internal_mod_time; dst->density = src->density; dst->has_hotspot = src->has_hotspot; dst->hotspot_x = src->hotspot_x; dst->hotspot_y = src->hotspot_y; dst->load_addr = src->load_addr; dst->exec_addr = src->exec_addr; } static dbuf *create_dbuf_lowlevel(deark *c) { dbuf *f; f = de_malloc(c, sizeof(dbuf)); f->c = c; f->file_id = -1; return f; } // Create or open a file for writing, that is *not* one of the usual // "output.000.ext" files we extract from the input file. // // overwrite_mode, flags: Same as for de_fopen_for_write(). // // On failure, prints an error message, and sets f->btype to DBUF_TYPE_NULL. dbuf *dbuf_create_unmanaged_file(deark *c, const char *fname, int overwrite_mode, unsigned int flags) { dbuf *f; char msgbuf[200]; f = create_dbuf_lowlevel(c); f->is_managed = 0; f->name = de_strdup(c, fname); f->btype = DBUF_TYPE_OFILE; f->max_len_hard = c->max_output_file_size; f->fp = de_fopen_for_write(c, f->name, msgbuf, sizeof(msgbuf), c->overwrite_mode, flags); if(!f->fp) { de_err(c, "Failed to write %s: %s", f->name, msgbuf); f->btype = DBUF_TYPE_NULL; c->serious_error_flag = 1; } return f; } dbuf *dbuf_create_unmanaged_file_stdout(deark *c, const char *name) { dbuf *f; f = create_dbuf_lowlevel(c); f->is_managed = 0; f->name = de_strdup(c, name); f->btype = DBUF_TYPE_STDOUT; f->max_len_hard = c->max_output_file_size; f->fp = stdout; return f; } static void sanitize_ext(const char *ext1, char *ext, size_t extlen) { size_t k; de_strlcpy(ext, ext1, extlen); // This part of the filename should come from Deark, and should only // use a limited set of characters. Just to be sure: for(k=0; ext[k]; k++) { if((ext[k]>='0' && ext[k]<='9') || (ext[k]>='A' && ext[k]<='Z') || (ext[k]>='a' && ext[k]<='z') || ext[k]=='.' || ext[k]=='_' || ext[k]=='-' || ext[k]=='+') { ; } else { ext[k] = '_'; } } } // Allow small writes to be coalesced, for more efficient callbacks, etc. // This may make writes less efficient in general, though, since FILE* I/O is // already buffered, and our membufs don't need caching. // // Warning - Do not use unless the this file is going to be written // strictly sequentially (no write_at()...), and you call // dbuf_flush() when needed. void dbuf_enable_wbuffer(dbuf *f) { if(f->c->disable_wbuffer) return; // Feature is disabled globally if(f->wbuffer) return; f->wbuffer = de_malloc(f->c, DE_WBUFFER_SIZE); } void dbuf_disable_wbuffer(dbuf *f) { if(!f->wbuffer) return; dbuf_flush(f); de_free(f->c, f->wbuffer); f->wbuffer = NULL; } dbuf *dbuf_create_output_file(deark *c, const char *ext1, de_finfo *fi, unsigned int createflags) { char nbuf[500]; char msgbuf[200]; char ext[128]; int have_ext; dbuf *f; const char *basefn; u8 is_directory = 0; char *name_from_finfo = NULL; i64 name_from_finfo_len = 0; if(ext1) { have_ext = 1; sanitize_ext(ext1, ext, sizeof(ext)); } else { have_ext = 0; ext[0] = '\0'; } if(have_ext && fi && fi->original_filename_flag) { de_dbg(c, "[internal warning: Incorrect use of create_output_file]"); } f = create_dbuf_lowlevel(c); f->max_len_hard = c->max_output_file_size; f->is_managed = 1; if(fi && fi->is_volume_label) { if(c->output_style!=DE_OUTPUTSTYLE_ARCHIVE || c->archive_fmt!=DE_ARCHIVEFMT_ZIP) { de_dbg(c, "skipping volume label"); f->btype = DBUF_TYPE_NULL; goto done; } } if(fi && fi->is_directory) { is_directory = 1; } if(is_directory && !c->keep_dir_entries) { de_dbg(c, "skipping 'directory' file"); f->btype = DBUF_TYPE_NULL; goto done; } if(c->extract_policy==DE_EXTRACTPOLICY_MAINONLY) { if(createflags&DE_CREATEFLAG_IS_AUX) { de_dbg(c, "skipping 'auxiliary' file"); f->btype = DBUF_TYPE_NULL; goto done; } } else if(c->extract_policy==DE_EXTRACTPOLICY_AUXONLY) { if(!(createflags&DE_CREATEFLAG_IS_AUX)) { de_dbg(c, "skipping 'main' file"); f->btype = DBUF_TYPE_NULL; goto done; } } f->file_id = c->file_count; c->file_count++; basefn = c->base_output_filename ? c->base_output_filename : "output"; if(fi && ucstring_isnonempty(fi->file_name_internal)) { name_from_finfo_len = 1 + ucstring_count_utf8_bytes(fi->file_name_internal); name_from_finfo = de_malloc(c, name_from_finfo_len); ucstring_to_sz(fi->file_name_internal, name_from_finfo, (size_t)name_from_finfo_len, 0, DE_ENCODING_UTF8); } if(c->output_style==DE_OUTPUTSTYLE_ARCHIVE && !c->base_output_filename && fi && fi->is_directory && (fi->is_root_dir || (fi->detect_root_dot_dir && fi->orig_name_was_dot))) { de_strlcpy(nbuf, ".", sizeof(nbuf)); } else if(c->special_1st_filename && (f->file_id==c->first_output_file) && !is_directory) { de_strlcpy(nbuf, c->special_1st_filename, sizeof(nbuf)); } else if(c->output_style==DE_OUTPUTSTYLE_ARCHIVE && !c->base_output_filename && fi && fi->original_filename_flag && name_from_finfo) { // TODO: This is a "temporary" hack to allow us to, when both reading from // and writing to an archive format, use some semblance of the correct // filename (instead of "output.xxx.yyy"). // There are some things that we don't handle optimally, such as // subdirectories. // A major redesign of the file naming logic would be good. de_strlcpy(nbuf, name_from_finfo, sizeof(nbuf)); } else { char fn_suffix[256]; if(have_ext && name_from_finfo) { de_snprintf(fn_suffix, sizeof(fn_suffix), "%s.%s", name_from_finfo, ext); } else if(have_ext) { de_strlcpy(fn_suffix, ext, sizeof(fn_suffix)); } else if(is_directory && name_from_finfo) { de_snprintf(fn_suffix, sizeof(fn_suffix), "%s.dir", name_from_finfo); } else if(name_from_finfo) { de_strlcpy(fn_suffix, name_from_finfo, sizeof(fn_suffix)); } else if(is_directory) { de_strlcpy(fn_suffix, "dir", sizeof(fn_suffix)); } else { de_strlcpy(fn_suffix, "bin", sizeof(fn_suffix)); } de_snprintf(nbuf, sizeof(nbuf), "%s.%03d.%s", basefn, f->file_id, fn_suffix); } f->name = de_strdup(c, nbuf); if(fi) { // The finfo object passed to us at file creation is not required to // remain valid, so make a copy of anything in it that we might need // later. f->fi_copy = de_finfo_create(c); finfo_shallow_copy(c, fi, f->fi_copy); fi->riscos_appended_type = 0; // Here's where we respect the -intz option, by using it to convert to // UTC in some cases. if(f->fi_copy->timestamp[DE_TIMESTAMPIDX_MODIFY].is_valid && f->fi_copy->timestamp[DE_TIMESTAMPIDX_MODIFY].tzcode==DE_TZCODE_LOCAL && c->input_tz_offs_seconds!=0) { de_timestamp_cvt_to_utc(&f->fi_copy->timestamp[DE_TIMESTAMPIDX_MODIFY], -c->input_tz_offs_seconds); } if(f->fi_copy->internal_mod_time.is_valid && f->fi_copy->internal_mod_time.tzcode==DE_TZCODE_LOCAL && c->input_tz_offs_seconds!=0) { de_timestamp_cvt_to_utc(&f->fi_copy->internal_mod_time, -c->input_tz_offs_seconds); } } if(f->file_id < c->first_output_file) { f->btype = DBUF_TYPE_NULL; goto done; } if(f->file_id >= c->first_output_file + c->max_output_files) { f->btype = DBUF_TYPE_NULL; if(f->file_id == c->first_output_file + c->max_output_files) { if(!c->user_set_max_output_files) { de_err(c, "Limit of %d output files exceeded", c->max_output_files); } } goto done; } c->num_files_extracted++; if(c->extrlist_dbuf) { dbuf_printf(c->extrlist_dbuf, "%s\n", f->name); dbuf_flush_lowlevel(c->extrlist_dbuf); } if(c->enable_wbuffer_test && !(createflags & DE_CREATEFLAG_NO_WBUFFER)) { dbuf_enable_wbuffer(f); } if(c->enable_oinfo) { f->crco_for_oinfo = de_crcobj_create(c, DE_CRCOBJ_CRC32_IEEE); } if(c->list_mode) { f->btype = DBUF_TYPE_NULL; if(c->list_mode_include_file_id) { de_msg(c, "%d:%s", f->file_id, f->name); } else { de_msg(c, "%s", f->name); } goto done; } if(c->output_style==DE_OUTPUTSTYLE_ARCHIVE && c->archive_fmt==DE_ARCHIVEFMT_TAR) { de_info(c, "Adding %s to TAR file", f->name); f->btype = DBUF_TYPE_ODBUF; // A dummy max_len_hard value. The parent will do the checking. f->max_len_hard = DE_DUMMY_MAX_FILE_SIZE; f->writing_to_tar_archive = 1; de_tar_start_member_file(c, f); } else if(c->output_style==DE_OUTPUTSTYLE_ARCHIVE) { // ZIP i64 initial_alloc; de_info(c, "Adding %s to ZIP file", f->name); f->btype = DBUF_TYPE_MEMBUF; f->max_len_hard = DE_MAX_MEMBUF_SIZE; if(is_directory) { // A directory entry is not expected to have any data associated // with it (besides the files it contains). initial_alloc = 16; } else { initial_alloc = 65536; } f->membuf_buf = de_malloc(c, initial_alloc); f->membuf_alloc = initial_alloc; f->write_memfile_to_zip_archive = 1; } else if(c->output_style==DE_OUTPUTSTYLE_STDOUT) { de_info(c, "Writing %s to [stdout]", f->name); f->btype = DBUF_TYPE_STDOUT; // TODO: Should we increase f->max_len_hard? f->fp = stdout; } else { de_info(c, "Writing %s", f->name); f->btype = DBUF_TYPE_OFILE; f->fp = de_fopen_for_write(c, f->name, msgbuf, sizeof(msgbuf), c->overwrite_mode, 0); if(!f->fp) { de_err(c, "Failed to write %s: %s", f->name, msgbuf); f->btype = DBUF_TYPE_NULL; c->serious_error_flag = 1; } } done: de_free(c, name_from_finfo); return f; } static void do_on_dbuf_size_exceeded(dbuf *f) { de_err(f->c, "Maximum %s size of %"I64_FMT" bytes exceeded", (f->btype==DBUF_TYPE_MEMBUF)?"membuf":"output file", f->max_len_hard); de_fatalerror(f->c); } dbuf *dbuf_create_membuf(deark *c, i64 initialsize, unsigned int flags) { dbuf *f; f = create_dbuf_lowlevel(c); f->btype = DBUF_TYPE_MEMBUF; f->max_len_hard = DE_MAX_MEMBUF_SIZE; if(initialsize>0) { if(initialsize > f->max_len_hard) { do_on_dbuf_size_exceeded(f); } f->membuf_buf = de_malloc(c, initialsize); f->membuf_alloc = initialsize; } if(flags&0x01) { dbuf_set_length_limit(f, initialsize); } return f; } static void membuf_append(dbuf *f, const u8 *m, i64 mlen) { i64 new_alloc_size; if(f->has_len_limit) { if(f->len + mlen > f->len_limit) { mlen = f->len_limit - f->len; } } if(mlen<=0) return; if(mlen > f->membuf_alloc - f->len) { // Need to allocate more space new_alloc_size = (f->membuf_alloc + mlen)*2; if(new_alloc_size<1024) new_alloc_size=1024; if(new_alloc_size > f->max_len_hard) new_alloc_size = f->max_len_hard; if(f->c->debug_level>=4) { de_dbgx(f->c, 4, "increasing membuf size %"I64_FMT" -> %"I64_FMT, f->membuf_alloc, new_alloc_size); } if(f->len + mlen > f->max_len_hard) { do_on_dbuf_size_exceeded(f); } f->membuf_buf = de_realloc(f->c, f->membuf_buf, f->membuf_alloc, new_alloc_size); f->membuf_alloc = new_alloc_size; } de_memcpy(&f->membuf_buf[f->len], m, (size_t)mlen); f->len += mlen; } // Not to be called directly. Used only by dbuf_write/dbuf_flush. static void dbuf_write_unbuffered(dbuf *f, const u8 *m, i64 len) { if(len<=0) return; if(f->len + len > f->max_len_hard) { do_on_dbuf_size_exceeded(f); } if(f->crco_for_oinfo) { de_crcobj_addbuf(f->crco_for_oinfo, m, len); } if(f->writelistener_cb) { f->writelistener_cb(f, f->userdata_for_writelistener, m, len); } switch(f->btype) { case DBUF_TYPE_OFILE: case DBUF_TYPE_STDOUT: if(!f->fp) return; if(f->c->debug_level>=4) { de_dbgx(f->c, 4, "writing %"I64_FMT" bytes to %s", len, f->name); } fwrite(m, 1, (size_t)len, f->fp); f->len += len; return; case DBUF_TYPE_MEMBUF: if(f->c->debug_level>=4 && f->name) { de_dbgx(f->c, 4, "appending %"I64_FMT" bytes to membuf %s", len, f->name); } membuf_append(f, m, len); return; case DBUF_TYPE_ODBUF: dbuf_write(f->parent_dbuf, m, len); f->len += len; return; case DBUF_TYPE_CUSTOM: if(f->customwrite_fn) { f->customwrite_fn(f, f->userdata_for_customwrite, m, len); } f->len += len; return; case DBUF_TYPE_NULL: f->len += len; return; } de_internal_err_fatal(f->c, "Invalid output file type (%d)", f->btype); } // High-level flush. Updates fields in f, calls the writelistener function, etc. // (Use dbuf_flush_lowlevel to flush to the actual disk file.) void dbuf_flush(dbuf *f) { if(f->wbuffer_bytes_used==0) return; dbuf_write_unbuffered(f, f->wbuffer, f->wbuffer_bytes_used); f->wbuffer_bytes_used = 0; } void dbuf_write(dbuf *f, const u8 *m, i64 len) { if(!f->wbuffer) { dbuf_write_unbuffered(f, m, len); return; } if(len<=0) return; if(len > DE_WBUFFER_SIZE/2) { // This item doesn't fit in the buffer, even by itself, or we // consider it "large". // Flush the buffer, write the item, done. // TODO: Decide what the "large" threshold should be, or if there should // even be one. if(f->wbuffer_bytes_used!=0) dbuf_flush(f); dbuf_write_unbuffered(f, m, len); return; } if(f->wbuffer_bytes_used + len > DE_WBUFFER_SIZE) { // This item fits in the buffer by itself, but currently the buffer // is too full. // Flush the buffer, copy the item to the buffer, done. dbuf_flush(f); de_memcpy(f->wbuffer, m, (size_t)len); f->wbuffer_bytes_used = len; return; } // There is room for this item in the buffer, even without flushing it first. de_memcpy(&f->wbuffer[f->wbuffer_bytes_used], m, (size_t)len); f->wbuffer_bytes_used += len; } void dbuf_writebyte(dbuf *f, u8 n) { // Optimization if(f->wbuffer && f->wbuffer_bytes_used<DE_WBUFFER_SIZE) { f->wbuffer[f->wbuffer_bytes_used++] = n; return; } dbuf_write(f, &n, 1); } // Allowed only for membufs, and unmanaged output files. // For unmanaged output files, must be used with care, and should not be // mixed with dbuf_write(). void dbuf_write_at(dbuf *f, i64 pos, const u8 *m, i64 len) { if(len<1 || pos<0) return; if(pos + len > f->max_len_hard) { do_on_dbuf_size_exceeded(f); } if(f->btype==DBUF_TYPE_MEMBUF) { i64 amt_overwrite, amt_newzeroes, amt_append; if(pos+len <= f->len) { // entirely within the current file amt_overwrite = len; amt_newzeroes = 0; amt_append = 0; } else if(pos >= f->len) { // starts after the end of the current file amt_overwrite = 0; amt_newzeroes = pos - f->len; amt_append = len; } else { // overlaps the end of the current file amt_overwrite = f->len - pos; amt_newzeroes = 0; amt_append = len - amt_overwrite; } if(amt_overwrite>0) { de_memcpy(&f->membuf_buf[pos], m, (size_t)amt_overwrite); } if(amt_newzeroes>0) { dbuf_write_zeroes(f, amt_newzeroes); } if(amt_append>0) { membuf_append(f, &m[amt_overwrite], amt_append); } } else if(f->btype==DBUF_TYPE_OFILE && !f->is_managed) { i64 curpos = de_ftell(f->fp); if(pos != curpos) { de_fseek(f->fp, pos, SEEK_SET); } fwrite(m, 1, (size_t)len, f->fp); if(pos+len > f->len) { f->len = pos+len; } } else if(f->btype==DBUF_TYPE_NULL) { if(pos+len > f->len) { f->len = pos+len; } } else { de_internal_err_fatal(f->c, "Attempt to seek on non-seekable stream"); } } void dbuf_writebyte_at(dbuf *f, i64 pos, u8 n) { if(f->btype==DBUF_TYPE_MEMBUF && pos>=0 && pos<f->len) { // Fast path when overwriting a byte in a membuf f->membuf_buf[pos] = n; return; } dbuf_write_at(f, pos, &n, 1); } void dbuf_write_run(dbuf *f, u8 n, i64 len) { u8 buf[1024]; i64 amt_left; i64 amt_to_write; if(len<=0) return; de_memset(buf, n, (size_t)len<sizeof(buf) ? (size_t)len : sizeof(buf)); amt_left = len; while(amt_left > 0) { if(amt_left < (i64)sizeof(buf)) amt_to_write = amt_left; else amt_to_write = (i64)sizeof(buf); dbuf_write(f, buf, amt_to_write); amt_left -= amt_to_write; } } void dbuf_write_zeroes(dbuf *f, i64 len) { dbuf_write_run(f, 0, len); } // Make the membuf have exactly len bytes of content. void dbuf_truncate(dbuf *f, i64 desired_len) { dbuf_flush(f); if(desired_len<0) desired_len=0; if(desired_len>f->len) { dbuf_write_zeroes(f, desired_len - f->len); } else if(desired_len<f->len) { if(f->btype==DBUF_TYPE_MEMBUF || f->btype==DBUF_TYPE_CUSTOM) { f->len = desired_len; } } } void de_writeu16le_direct(u8 *m, i64 n) { m[0] = (u8)(n & 0x00ff); m[1] = (u8)((n & 0xff00)>>8); } void de_writeu16be_direct(u8 *m, i64 n) { m[0] = (u8)((n & 0xff00)>>8); m[1] = (u8)(n & 0x00ff); } void dbuf_writeu16le(dbuf *f, i64 n) { u8 buf[2]; de_writeu16le_direct(buf, n); dbuf_write(f, buf, 2); } void dbuf_writeu16be(dbuf *f, i64 n) { u8 buf[2]; de_writeu16be_direct(buf, n); dbuf_write(f, buf, 2); } void dbuf_writei16le(dbuf *f, i64 n) { if(n<0) { dbuf_writeu16le(f, n+65536); } else { dbuf_writeu16le(f, n); } } void dbuf_writei16be(dbuf *f, i64 n) { if(n<0) { dbuf_writeu16be(f, n+65536); } else { dbuf_writeu16be(f, n); } } void de_writeu32be_direct(u8 *m, i64 n) { m[0] = (u8)((n & 0xff000000)>>24); m[1] = (u8)((n & 0x00ff0000)>>16); m[2] = (u8)((n & 0x0000ff00)>>8); m[3] = (u8)(n & 0x000000ff); } void dbuf_writeu32be(dbuf *f, i64 n) { u8 buf[4]; de_writeu32be_direct(buf, n); dbuf_write(f, buf, 4); } void de_writeu32le_direct(u8 *m, i64 n) { m[0] = (u8)(n & 0x000000ff); m[1] = (u8)((n & 0x0000ff00)>>8); m[2] = (u8)((n & 0x00ff0000)>>16); m[3] = (u8)((n & 0xff000000)>>24); } void dbuf_writeu32le(dbuf *f, i64 n) { u8 buf[4]; de_writeu32le_direct(buf, n); dbuf_write(f, buf, 4); } void dbuf_writei32le(dbuf *f, i64 n) { if(n<0) { dbuf_writeu32le(f, n+0x100000000LL); } else { dbuf_writeu32le(f, n); }} void dbuf_writei32be(dbuf *f, i64 n) { if(n<0) { dbuf_writeu32be(f, n+0x100000000LL); } else { dbuf_writeu32be(f, n); } } void de_writeu64le_direct(u8 *m, u64 n) { de_writeu32le_direct(&m[0], (i64)(u32)(n&0xffffffffULL)); de_writeu32le_direct(&m[4], (i64)(u32)(n>>32)); } void dbuf_writeu64le(dbuf *f, u64 n) { u8 buf[8]; de_writeu64le_direct(buf, n); dbuf_write(f, buf, 8); } void dbuf_puts(dbuf *f, const char *sz) { dbuf_write(f, (const u8*)sz, (i64)de_strlen(sz)); } // TODO: Remove the buffer size limitation? void dbuf_printf(dbuf *f, const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); de_vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); dbuf_puts(f, buf); } void dbuf_flush_lowlevel(dbuf *f) { dbuf_flush(f); if(f->btype==DBUF_TYPE_OFILE) { fflush(f->fp); } } dbuf *dbuf_open_input_file(deark *c, const char *fn) { dbuf *f; unsigned int returned_flags = 0; char msgbuf[200]; if(!fn) { c->serious_error_flag = 1; return NULL; } f = create_dbuf_lowlevel(c); f->btype = DBUF_TYPE_IFILE; f->rcache_policy = DE_RCACHE_POLICY_ENABLED; f->fp = de_fopen_for_read(c, fn, &f->len, msgbuf, sizeof(msgbuf), &returned_flags); if(!f->fp) { de_err(c, "Can't read %s: %s", fn, msgbuf); de_free(c, f); c->serious_error_flag = 1; return NULL; } if(returned_flags & 0x1) { // This "file" is actually a pipe. f->btype = DBUF_TYPE_FIFO; f->rcache_policy = DE_RCACHE_POLICY_NONE; populate_rcache_from_pipe(f); } if(!f->rcache && f->rcache_policy==DE_RCACHE_POLICY_ENABLED) { populate_rcache(f); } return f; } dbuf *dbuf_open_input_stdin(deark *c) { dbuf *f; f = create_dbuf_lowlevel(c); f->btype = DBUF_TYPE_STDIN; // Set to NONE, to make sure we don't try to auto-populate the cache later. f->rcache_policy = DE_RCACHE_POLICY_NONE; populate_rcache_from_pipe(f); return f; } dbuf *dbuf_open_input_subfile(dbuf *parent, i64 offset, i64 size) { dbuf *f; deark *c; c = parent->c; f = create_dbuf_lowlevel(c); f->btype = DBUF_TYPE_IDBUF; f->parent_dbuf = parent; f->offset_into_parent_dbuf = offset; f->len = size; return f; } dbuf *dbuf_create_custom_dbuf(deark *c, i64 apparent_size, unsigned int flags) { dbuf *f; f = create_dbuf_lowlevel(c); f->btype = DBUF_TYPE_CUSTOM; f->len = apparent_size; f->max_len_hard = DE_DUMMY_MAX_FILE_SIZE; return f; } void dbuf_set_writelistener(dbuf *f, de_writelistener_cb_type fn, void *userdata) { dbuf_flush(f); f->userdata_for_writelistener = userdata; f->writelistener_cb = fn; } // A shared writelister callback function that just calculates the CRC. // To use, set userdata to your 'struct de_crcobj *' object. void de_writelistener_for_crc(dbuf *f, void *userdata, const u8 *buf, i64 buf_len) { struct de_crcobj *crco = (struct de_crcobj*)userdata; de_crcobj_addbuf(crco, buf, buf_len); } void dbuf_close(dbuf *f) { deark *c; if(!f) return; c = f->c; if(f->wbuffer_bytes_used!=0) dbuf_flush(f); if(c->enable_oinfo && f->is_managed) { u32 crc = 0; if(f->crco_for_oinfo) { crc = de_crcobj_getval(f->crco_for_oinfo); } de_msg(c, "Output file info: ID=%d CRC=%08x size=%"I64_FMT, f->file_id, crc, f->len); } if(f->btype==DBUF_TYPE_OFILE || f->btype==DBUF_TYPE_STDOUT) { c->total_output_size += f->len; } if(f->btype==DBUF_TYPE_MEMBUF && f->write_memfile_to_zip_archive) { de_zip_add_file_to_archive(c, f); if(f->name) { de_dbg3(c, "closing memfile %s", f->name); } } else if(f->writing_to_tar_archive) { de_tar_end_member_file(c, f); } switch(f->btype) { case DBUF_TYPE_IFILE: case DBUF_TYPE_OFILE: if(f->name) { de_dbg3(c, "closing file %s", f->name); } de_fclose(f->fp); f->fp = NULL; if(f->btype==DBUF_TYPE_OFILE && f->is_managed) { de_update_file_attribs(f, c->preserve_file_times); } break; case DBUF_TYPE_FIFO: de_fclose(f->fp); f->fp = NULL; break; case DBUF_TYPE_STDOUT: if(f->name && f->is_managed) { de_dbg3(c, "finished writing %s to stdout", f->name); } else if(!f->is_managed) { de_dbg3(c, "finished writing %s", f->name); } f->fp = NULL; break; case DBUF_TYPE_MEMBUF: case DBUF_TYPE_IDBUF: case DBUF_TYPE_ODBUF: case DBUF_TYPE_STDIN: case DBUF_TYPE_CUSTOM: case DBUF_TYPE_NULL: break; default: de_internal_err_nonfatal(c, "Don't know how to close this type of file (%d)", f->btype); } de_free(c, f->membuf_buf); de_free(c, f->name); de_free(c, f->rcache); de_free(c, f->wbuffer); if(f->crco_for_oinfo) de_crcobj_destroy(f->crco_for_oinfo); if(f->fi_copy) de_finfo_destroy(c, f->fi_copy); de_free(c, f); if(c->total_output_size > c->max_total_output_size) { // FIXME: Since we only do this check when a file is closed, it can // potentially be subverted in the (rare) case that Deark has multiple // output files open simultaneously. de_err(c, "Maximum total output size of %"I64_FMT" bytes exceeded", c->max_total_output_size); de_fatalerror(c); } } void dbuf_empty(dbuf *f) { if(f->btype == DBUF_TYPE_MEMBUF) { dbuf_flush(f); f->len = 0; } } // Provides direct (presumably read-only) access to the memory in a membuf. // Use with care: The memory is still owned by the dbuf. // Note: Another, arguably safer, way to do this is to use dbuf_buffered_read(). const u8 *dbuf_get_membuf_direct_ptr(dbuf *f) { if(f->btype != DBUF_TYPE_MEMBUF) return NULL; return f->membuf_buf; } // Search a section of a dbuf for a given byte. // 'haystack_len' is the number of bytes to search. // Returns 0 if not found. // If found, sets *foundpos to the position in the file where it was found // (not relative to startpos). int dbuf_search_byte(dbuf *f, const u8 b, i64 startpos, i64 haystack_len, i64 *foundpos) { i64 i; for(i=0; i<haystack_len; i++) { if(b == dbuf_getbyte(f, startpos+i)) { *foundpos = startpos+i; return 1; } } return 0; } struct search_ctx { const u8 *needle; i64 needle_len; int foundflag; i64 foundpos_rel; }; static int search_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { struct search_ctx *sctx = (struct search_ctx*)brctx->userdata; i64 i; i64 num_starting_positions_to_check; if(buf_len < sctx->needle_len) return 0; num_starting_positions_to_check = buf_len + 1 - sctx->needle_len; for(i=0; i<num_starting_positions_to_check; i++) { if(sctx->needle[0]==buf[i] && !de_memcmp(sctx->needle, &buf[i], (size_t)sctx->needle_len)) { sctx->foundpos_rel = brctx->offset+i; sctx->foundflag = 1; return 0; } } if(brctx->eof_flag) return 0; brctx->bytes_consumed = num_starting_positions_to_check; return 1; } // Search a section of a dbuf for a given byte sequence. // // This function is inefficient, but it's good enough for Deark's needs. // Maximum 'needle_len' is DE_BUFFERED_READ_MIN_BLKSIZE bytes, but it's expected to // be quite short. If it gets close to the maximum, the search could get very // inefficient. // // 'haystack_len' is the number of bytes to search in (the sequence must be completely // within that range, not just start there). // Returns 0 if not found. // If found, sets *foundpos to the position in the file where it was found // (not relative to startpos). int dbuf_search(dbuf *f, const u8 *needle, i64 needle_len, i64 startpos, i64 haystack_len, i64 *foundpos) { int retval = 0; struct search_ctx sctx; *foundpos = 0; if(startpos < 0) { haystack_len += startpos; if(haystack_len < 0) { goto done; } startpos = 0; } if(startpos > f->len) { goto done; } if(haystack_len > f->len - startpos) { haystack_len = f->len - startpos; } if(needle_len > haystack_len) { goto done; } if(needle_len > DE_BUFFERED_READ_MIN_BLKSIZE) { goto done; } if(needle_len<1) { retval = 1; *foundpos = startpos; goto done; } de_zeromem(&sctx, sizeof(struct search_ctx)); sctx.needle = needle; sctx.needle_len = needle_len; (void)dbuf_buffered_read(f, startpos, haystack_len, search_cbfn, (void*)&sctx); if(sctx.foundflag) { *foundpos = startpos + sctx.foundpos_rel; retval = 1; } done: return retval; } // Search for the aligned pair of 0x00 bytes that marks the end of a UTF-16 string. // Endianness doesn't matter, because we're only looking for 0x00 0x00. // The returned 'bytes_consumed' is in bytes, and includes the 2 bytes for the NUL // terminator. // Returns 0 if the NUL is not found, in which case *bytes_consumed is not // meaningful. int dbuf_get_utf16_NULterm_len(dbuf *f, i64 pos1, i64 bytes_avail, i64 *bytes_consumed) { i64 x; i64 pos = pos1; *bytes_consumed = bytes_avail; while(1) { if(pos1+bytes_avail-pos < 2) { break; } x = dbuf_getu16le(f, pos); pos += 2; if(x==0) { *bytes_consumed = pos - pos1; return 1; } } return 0; } int dbuf_find_line(dbuf *f, i64 pos1, i64 *pcontent_len, i64 *ptotal_len) { u8 b0, b1; i64 pos; i64 eol_pos = 0; i64 eol_size = 0; *pcontent_len = 0; *ptotal_len = 0; if(pos1<0 || pos1>=f->len) { return 0; } pos = pos1; while(1) { if(pos>=f->len) { // No EOL. eol_pos = pos; eol_size = 0; break; } b0 = dbuf_getbyte(f, pos); if(b0==0x0d) { eol_pos = pos; // Look ahead at the next byte. b1 = dbuf_getbyte(f, pos+1); if(b1==0x0a) { // CR+LF eol_size = 2; break; } // LF eol_pos = pos; eol_size = 1; break; } else if(b0==0x0a) { eol_pos = pos; eol_size = 1; break; } pos++; } *pcontent_len = eol_pos - pos1; *ptotal_len = *pcontent_len + eol_size; return (*ptotal_len > 0); } // Returns the length of the dbuf's data, including bytes that have been written // but not flushed. // Unless wbuffer is enabled, it is also okay to access f->len directly. i64 dbuf_get_length(dbuf *f) { return f->len + f->wbuffer_bytes_used; } // Enforce a maximum size when writing to a dbuf. // Attempting to write more than this is a silent no-op. // May be valid only for memory buffers. void dbuf_set_length_limit(dbuf *f, i64 max_len) { f->has_len_limit = 1; f->len_limit = max_len; } int dbuf_has_utf8_bom(dbuf *f, i64 pos) { return !dbuf_memcmp(f, pos, "\xef\xbb\xbf", 3); } // Write the contents of a dbuf to a file. // This function intended for use in development/debugging. int dbuf_dump_to_file(dbuf *inf, const char *fn) { dbuf *outf; deark *c = inf->c; outf = dbuf_create_unmanaged_file(c, fn, DE_OVERWRITEMODE_STANDARD, 0); dbuf_copy(inf, 0, inf->len, outf); dbuf_close(outf); return 1; } static void reverse_fourcc(u8 *buf, int nbytes) { size_t k; for(k=0; k<((size_t)nbytes)/2; k++) { u8 tmpc; tmpc = buf[k]; buf[k] = buf[(size_t)nbytes-1-k]; buf[(size_t)nbytes-1-k] = tmpc; } } // Though we call it a "fourcc", we support 'nbytes' from 1 to 4. void dbuf_read_fourcc(dbuf *f, i64 pos, struct de_fourcc *fcc, int nbytes, unsigned int flags) { if(nbytes<1 || nbytes>4) return; de_zeromem(fcc->bytes, 4); dbuf_read(f, fcc->bytes, pos, (i64)nbytes); if(flags&DE_4CCFLAG_REVERSED) { reverse_fourcc(fcc->bytes, nbytes); } fcc->id = (u32)de_getu32be_direct(fcc->bytes); if(nbytes<4) { fcc->id >>= (4-(unsigned int)nbytes)*8; } de_bytes_to_printable_sz(fcc->bytes, (i64)nbytes, fcc->id_sanitized_sz, sizeof(fcc->id_sanitized_sz), 0, DE_ENCODING_ASCII); de_bytes_to_printable_sz(fcc->bytes, (i64)nbytes, fcc->id_dbgstr, sizeof(fcc->id_dbgstr), DE_CONVFLAG_ALLOW_HL, DE_ENCODING_ASCII); } static int buffered_read_internal(struct de_bufferedreadctx *brctx, dbuf *f, i64 pos1, i64 len, de_buffered_read_cbfn cbfn) { int retval = 0; i64 pos = pos1; // Absolute pos of next byte to read from f i64 offs_of_first_byte_in_buf; // Relative to pos1, where in f is buf[0]? i64 num_unconsumed_bytes_in_buf; #define BRBUFLEN 4096 // Must be >= DE_BUFFERED_READ_MIN_BLKSIZE u8 buf[BRBUFLEN]; num_unconsumed_bytes_in_buf = 0; offs_of_first_byte_in_buf = 0; while(1) { i64 nbytes_avail_to_read; i64 bytestoread; int ret; nbytes_avail_to_read = pos1+len-pos; if(nbytes_avail_to_read<1 && num_unconsumed_bytes_in_buf<1) { break; } // max bytes that will fit in buf: bytestoread = BRBUFLEN-num_unconsumed_bytes_in_buf; // max bytes available to read: if(bytestoread >= nbytes_avail_to_read) { bytestoread = nbytes_avail_to_read; brctx->eof_flag = 1; } else { brctx->eof_flag = 0; } dbuf_read(f, &buf[num_unconsumed_bytes_in_buf], pos, bytestoread); pos += bytestoread; num_unconsumed_bytes_in_buf += bytestoread; brctx->offset = offs_of_first_byte_in_buf; brctx->bytes_consumed = num_unconsumed_bytes_in_buf; ret = cbfn(brctx, buf, num_unconsumed_bytes_in_buf); if(!ret) goto done; if(brctx->bytes_consumed<1 || brctx->bytes_consumed>num_unconsumed_bytes_in_buf) { goto done; } if(brctx->bytes_consumed < num_unconsumed_bytes_in_buf) { // cbfn didn't consume all bytes // TODO: For better efficiency, we could leave the buffer as it is until // the unconsumed byte count drops below DE_BUFFERED_READ_MIN_BLKSIZE. // But that's only useful if some consumers consume only a small number of bytes. de_memmove(buf, &buf[brctx->bytes_consumed], (size_t)(num_unconsumed_bytes_in_buf-brctx->bytes_consumed)); num_unconsumed_bytes_in_buf -= brctx->bytes_consumed; } else { num_unconsumed_bytes_in_buf = 0; } offs_of_first_byte_in_buf += brctx->bytes_consumed; } retval = 1; done: return retval; } // Special case where all bytes are already in memory static int buffered_read_from_mem(struct de_bufferedreadctx *brctx, dbuf *f, const u8 *mem, i64 pos1, i64 len, de_buffered_read_cbfn cbfn) { int retval = 0; i64 total_nbytes_consumed = 0; while(1) { int ret; i64 nbytes_to_send; nbytes_to_send = len - total_nbytes_consumed; if(nbytes_to_send<1) break; brctx->bytes_consumed = nbytes_to_send; brctx->offset = total_nbytes_consumed; brctx->eof_flag = 1; ret = cbfn(brctx, &mem[pos1+total_nbytes_consumed], nbytes_to_send); if(!ret) goto done; if(brctx->bytes_consumed<1 || brctx->bytes_consumed>nbytes_to_send) { goto done; } total_nbytes_consumed += brctx->bytes_consumed; } retval = 1; done: return retval; } static int buffered_read_zero_len(struct de_bufferedreadctx *brctx, de_buffered_read_cbfn cbfn) { const u8 dummybuf[1] = { 0 }; int ret; brctx->offset = 0; brctx->eof_flag = 1; brctx->bytes_consumed = 0; ret = cbfn(brctx, dummybuf, 0); return ret?1:0; } // dbuf_buffered_read: // Read a slice of a dbuf, and pass its data to a callback function, one // segment at a time. // cbfn: Caller-implemented callback function. // - It must be prepared for an arbitrarily large number of bytes to be passed // to it at once (though it does not have to consume them all). // - It must consume at least 1 byte, unless 0 bytes were passed to it. // - If it does not consume all the bytes passed to it, it must set // brctx->bytes_consumed. // - It must return nonzero normally, 0 to abort. // We guarantee that: // - brctx->eof_flag will be nonzero if and only if there is no data after this. // - If eof_flag is not set, at least DE_BUFFERED_READ_MIN_BLKSIZE bytes will // be provided. // - If the caller supplies 0 bytes of input data, the callback function will be // called exactly once. This is the only case where the callback will be // called with buf_len==0. // - If the source dbuf is a MEMBUF, and the requested bytes are all in range, // then all requested bytes will be provided in the first call to the callback // function. // As is normal for Deark, a slice may extend slightly before or after the file, // with nonexistent bytes getting the value 0. // Return value: 1 normally, 0 if the callback function ever returned 0. int dbuf_buffered_read(dbuf *f, i64 pos1, i64 len, de_buffered_read_cbfn cbfn, void *userdata) { struct de_bufferedreadctx brctx; brctx.c = f->c; brctx.userdata = userdata; if((pos1 < -DE_ALLOWED_VIRTUAL_BYTES) || (pos1 > f->len+DE_ALLOWED_VIRTUAL_BYTES) || (len > f->len+DE_ALLOWED_VIRTUAL_BYTES) || (pos1+len > f->len+DE_ALLOWED_VIRTUAL_BYTES)) { len = 0; } if(len<=0) { // Get this special case out of the way. return buffered_read_zero_len(&brctx, cbfn); } // Use an optimized routine if all the data we need to read is already in memory. if(f->rcache && (pos1>=0) && (pos1+len<=f->rcache_bytes_used)) { return buffered_read_from_mem(&brctx, f, f->rcache, pos1, len, cbfn); } // Not an "optimization", since we promise this behavior for MEMBUFs. if(f->btype==DBUF_TYPE_MEMBUF && (pos1>=0) && (pos1+len<=f->len)) { return buffered_read_from_mem(&brctx, f, f->membuf_buf, pos1, len, cbfn); } // The general case: return buffered_read_internal(&brctx, f, pos1, len, cbfn); } int de_is_all_zeroes(const u8 *b, i64 n) { i64 k; for(k=0; k<n; k++) { if(b[k]!=0) return 0; } return 1; } static int is_all_zeroes_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { return de_is_all_zeroes(buf, buf_len); } // Returns 1 if the given slice has only bytes with value 0. int dbuf_is_all_zeroes(dbuf *f, i64 pos, i64 len) { return dbuf_buffered_read(f, pos, len, is_all_zeroes_cbfn, NULL); } // A struct sometimes used with dbuf_buffered_read(). struct textconvctx_struct { dbuf *outf; de_ucstring *tmpstr; struct de_encconv_state es; }; static int slice_is_ascii_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { struct textconvctx_struct *tcctx = (struct textconvctx_struct*)brctx->userdata; UI conv_flags; brctx->bytes_consumed = de_min_int(buf_len, 4096); if(brctx->eof_flag && brctx->bytes_consumed==buf_len) conv_flags = 0; else conv_flags = DE_CONVFLAG_PARTIAL_DATA; ucstring_empty(tcctx->tmpstr); ucstring_append_bytes_ex(tcctx->tmpstr, buf, brctx->bytes_consumed, conv_flags, &tcctx->es); if(!ucstring_is_ascii(tcctx->tmpstr)) { return 0; } return 1; } static int slice_is_ascii_compatible(dbuf *inf, i64 pos1, i64 len, de_ext_encoding input_ee) { deark *c = inf->c; struct textconvctx_struct tcctx; int retval = 1; de_zeromem(&tcctx, sizeof(struct textconvctx_struct)); tcctx.outf = NULL; de_encconv_init(&tcctx.es, input_ee); tcctx.tmpstr = ucstring_create(c); retval = dbuf_buffered_read(inf, pos1, len, slice_is_ascii_cbfn, (void*)&tcctx); ucstring_destroy(tcctx.tmpstr); return retval; } static int text2utf8_cbfn(struct de_bufferedreadctx *brctx, const u8 *buf, i64 buf_len) { struct textconvctx_struct *tcctx = (struct textconvctx_struct*)brctx->userdata; UI conv_flags; // There's no limit to how much data dbuf_buffered_read() could send us // at once, so we won't try to put it all in a ucstring at once. brctx->bytes_consumed = de_min_int(buf_len, 4096); // For best results, ucstring_append_bytes_ex() needs to be told whether there will // be any more bytes after this. if(brctx->eof_flag && brctx->bytes_consumed==buf_len) conv_flags = 0; else conv_flags = DE_CONVFLAG_PARTIAL_DATA; ucstring_empty(tcctx->tmpstr); ucstring_append_bytes_ex(tcctx->tmpstr, buf, brctx->bytes_consumed, conv_flags, &tcctx->es); ucstring_write_as_utf8(brctx->c, tcctx->tmpstr, tcctx->outf, 0); return 1; } static int slice_has_BOM(dbuf *inf, i64 pos, i64 len, de_encoding enc) { i64 len_to_read; u8 buf[3] = {0, 0, 0}; switch(enc) { case DE_ENCODING_UTF8: len_to_read = 3; break; case DE_ENCODING_UTF16BE: case DE_ENCODING_UTF16LE: len_to_read = 2; break; default: return 0; } if(len < len_to_read) return 0; dbuf_read(inf, buf, pos, len_to_read); switch(enc) { case DE_ENCODING_UTF16BE: if(buf[0]==0xfe && buf[1]==0xff) { return 1; } break; case DE_ENCODING_UTF16LE: if(buf[0]==0xff && buf[1]==0xfe) { return 1; } break; default: // UTF8 if(buf[0]==0xef && buf[1]==0xbb && buf[2]==0xbf) { return 1; } } return 0; } // Write a slice with a known encoding, to an output file, generally as UTF-8. // // This is a messy function intended to be used when extracting a text segment // to its own file. // // flags 0x1: Add BOM unless BOM is already present. // flags 0x2: Add BOM only if needed, and slice has non-ASCII characters // (can be slow). // flags 0x4: If input encoding is UNKNOWN or ASCII, just copy the bytes unchanged. // // Except: A BOM will never be added if the -nobom option was used, or if // outf has already been written to. // A pre-existing BOM will never be removed. // (See also ucstring_write_as_utf8().) void dbuf_copy_slice_convert_to_utf8(dbuf *inf, i64 pos, i64 len, de_ext_encoding input_ee, dbuf *outf, UI flags) { deark *c = inf->c; de_encoding enc = DE_EXTENC_GET_BASE(input_ee); int prepend_BOM = 0; int already_has_BOM = 0; struct textconvctx_struct tcctx; de_zeromem(&tcctx, sizeof(struct textconvctx_struct)); dbuf_constrain_length(inf, pos, &len); if((flags & 0x4) && (enc==DE_ENCODING_UNKNOWN || enc==DE_ENCODING_ASCII)) { dbuf_copy(inf, pos, len, outf); goto done; } tcctx.outf = outf; de_encconv_init(&tcctx.es, input_ee); tcctx.tmpstr = ucstring_create(c); if(c->write_bom && outf->len==0) { if((flags & 0x3)!=0) { already_has_BOM = slice_has_BOM(inf, pos, len, enc); } if(flags & 0x1) { prepend_BOM = !already_has_BOM; } else if(flags & 0x2) { if(!already_has_BOM) { prepend_BOM = !slice_is_ascii_compatible(inf, pos, len, input_ee); } } } if(prepend_BOM) { dbuf_write_uchar_as_utf8(outf, 0xfeff); } dbuf_buffered_read(inf, pos, len, text2utf8_cbfn, (void*)&tcctx); done: ucstring_destroy(tcctx.tmpstr); } // Unused bits in n are required to be 0. void de_bitbuf_lowlevel_add_bits(struct de_bitbuf_lowlevel *bbll, u64 n, UI nbits) { if(bbll->nbits_in_bitbuf+nbits>64) return; if(bbll->is_lsb==0) { bbll->bit_buf = (bbll->bit_buf<<nbits) | n; } else { bbll->bit_buf |= (u64)n << bbll->nbits_in_bitbuf; } bbll->nbits_in_bitbuf += nbits; } void de_bitbuf_lowlevel_add_byte(struct de_bitbuf_lowlevel *bbll, u8 n) { if(bbll->nbits_in_bitbuf>56) return; if(bbll->is_lsb==0) { bbll->bit_buf = (bbll->bit_buf<<8) | n; } else { bbll->bit_buf |= (u64)n << bbll->nbits_in_bitbuf; } bbll->nbits_in_bitbuf += 8; } u64 de_bitbuf_lowlevel_get_bits(struct de_bitbuf_lowlevel *bbll, UI nbits) { u64 n; u64 mask; if(nbits > bbll->nbits_in_bitbuf) return 0; mask = ((u64)1 << nbits)-1; if(bbll->is_lsb==0) { bbll->nbits_in_bitbuf -= nbits; n = (bbll->bit_buf >> bbll->nbits_in_bitbuf) & mask; } else { n = bbll->bit_buf & mask; bbll->bit_buf >>= nbits; bbll->nbits_in_bitbuf -= nbits; } return n; } void de_bitbuf_lowlevel_empty(struct de_bitbuf_lowlevel *bbll) { bbll->bit_buf = 0; bbll->nbits_in_bitbuf = 0; } u64 de_bitreader_getbits(struct de_bitreader *bitrd, UI nbits) { if(bitrd->eof_flag) return 0; if(nbits==0) { // TODO: Decide if we always want to do this. Could risk infinite loops // with this successful no-op. return 0; } if(nbits > 57) { bitrd->eof_flag = 1; return 0; } while(bitrd->bbll.nbits_in_bitbuf < nbits) { u8 b; if(bitrd->curpos >= bitrd->endpos) { bitrd->eof_flag = 1; return 0; } b = dbuf_getbyte_p(bitrd->f, &bitrd->curpos); de_bitbuf_lowlevel_add_byte(&bitrd->bbll, b); } return de_bitbuf_lowlevel_get_bits(&bitrd->bbll, nbits); } // Empty the bitbuffer, and set ->curpos to the position of the next byte with // entirely unprocessed bits. // In other words, make it okay for the caller to read or change the ->curpos // field. void de_bitreader_skip_to_byte_boundary(struct de_bitreader *bitrd) { // This is unlikely to change anything, since the current bitreader // implementation reads no more bytes than needed. bitrd->curpos -= (i64)(bitrd->bbll.nbits_in_bitbuf/8); de_bitbuf_lowlevel_empty(&bitrd->bbll); } // pos is the offset of the next whole byte that may be added to the bitbuf. char *de_bitbuf_describe_curpos(struct de_bitbuf_lowlevel *bbll, i64 pos1, char *buf, size_t buf_len) { i64 curpos; UI nwholebytes; UI nbits; nwholebytes = (i64)(bbll->nbits_in_bitbuf / 8); nbits = bbll->nbits_in_bitbuf % 8; curpos = pos1 - (i64)nwholebytes; if(nbits==0) { de_snprintf(buf, buf_len, "%"I64_FMT, curpos); } else { de_snprintf(buf, buf_len, "%"I64_FMT"+%ubits", curpos-1, (UI)(8-nbits)); } return buf; } char *de_bitreader_describe_curpos(struct de_bitreader *bitrd, char *buf, size_t buf_len) { return de_bitbuf_describe_curpos(&bitrd->bbll, bitrd->curpos, buf, buf_len); }
19f8c7c43b4a97cce02e5c90a2925ae5eebc80f0
321d11eaee885ceb3a74db0a062f9bbdf282148c
/crypto/bn/bn_shift.c
8fcb04324e6d593296f8a3e8b0e5888d35a5eeb4
[ "OpenSSL", "Apache-2.0", "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
4,826
c
bn_shift.c
/* * Copyright 1995-2020 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 <assert.h> #include "internal/cryptlib.h" #include "bn_local.h" int BN_lshift1(BIGNUM *r, const BIGNUM *a) { register BN_ULONG *ap, *rp, t, c; int i; bn_check_top(r); bn_check_top(a); if (r != a) { r->neg = a->neg; if (bn_wexpand(r, a->top + 1) == NULL) return 0; r->top = a->top; } else { if (bn_wexpand(r, a->top + 1) == NULL) return 0; } ap = a->d; rp = r->d; c = 0; for (i = 0; i < a->top; i++) { t = *(ap++); *(rp++) = ((t << 1) | c) & BN_MASK2; c = t >> (BN_BITS2 - 1); } *rp = c; r->top += c; bn_check_top(r); return 1; } int BN_rshift1(BIGNUM *r, const BIGNUM *a) { BN_ULONG *ap, *rp, t, c; int i; bn_check_top(r); bn_check_top(a); if (BN_is_zero(a)) { BN_zero(r); return 1; } i = a->top; ap = a->d; if (a != r) { if (bn_wexpand(r, i) == NULL) return 0; r->neg = a->neg; } rp = r->d; r->top = i; t = ap[--i]; rp[i] = t >> 1; c = t << (BN_BITS2 - 1); r->top -= (t == 1); while (i > 0) { t = ap[--i]; rp[i] = ((t >> 1) & BN_MASK2) | c; c = t << (BN_BITS2 - 1); } if (!r->top) r->neg = 0; /* don't allow negative zero */ bn_check_top(r); return 1; } int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int ret; if (n < 0) { ERR_raise(ERR_LIB_BN, BN_R_INVALID_SHIFT); return 0; } ret = bn_lshift_fixed_top(r, a, n); bn_correct_top(r); bn_check_top(r); return ret; } /* * In respect to shift factor the execution time is invariant of * |n % BN_BITS2|, but not |n / BN_BITS2|. Or in other words pre-condition * for constant-time-ness is |n < BN_BITS2| or |n / BN_BITS2| being * non-secret. */ int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n) { int i, nw; unsigned int lb, rb; BN_ULONG *t, *f; BN_ULONG l, m, rmask = 0; assert(n >= 0); bn_check_top(r); bn_check_top(a); nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return 0; if (a->top != 0) { lb = (unsigned int)n % BN_BITS2; rb = BN_BITS2 - lb; rb %= BN_BITS2; /* say no to undefined behaviour */ rmask = (BN_ULONG)0 - rb; /* rmask = 0 - (rb != 0) */ rmask |= rmask >> 8; f = &(a->d[0]); t = &(r->d[nw]); l = f[a->top - 1]; t[a->top] = (l >> rb) & rmask; for (i = a->top - 1; i > 0; i--) { m = l << lb; l = f[i - 1]; t[i] = (m | ((l >> rb) & rmask)) & BN_MASK2; } t[0] = (l << lb) & BN_MASK2; } else { /* shouldn't happen, but formally required */ r->d[nw] = 0; } if (nw != 0) memset(r->d, 0, sizeof(*t) * nw); r->neg = a->neg; r->top = a->top + nw + 1; r->flags |= BN_FLG_FIXED_TOP; return 1; } int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) { int ret = 0; if (n < 0) { ERR_raise(ERR_LIB_BN, BN_R_INVALID_SHIFT); return 0; } ret = bn_rshift_fixed_top(r, a, n); bn_correct_top(r); bn_check_top(r); return ret; } /* * In respect to shift factor the execution time is invariant of * |n % BN_BITS2|, but not |n / BN_BITS2|. Or in other words pre-condition * for constant-time-ness for sufficiently[!] zero-padded inputs is * |n < BN_BITS2| or |n / BN_BITS2| being non-secret. */ int bn_rshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n) { int i, top, nw; unsigned int lb, rb; BN_ULONG *t, *f; BN_ULONG l, m, mask; bn_check_top(r); bn_check_top(a); assert(n >= 0); nw = n / BN_BITS2; if (nw >= a->top) { /* shouldn't happen, but formally required */ BN_zero(r); return 1; } rb = (unsigned int)n % BN_BITS2; lb = BN_BITS2 - rb; lb %= BN_BITS2; /* say no to undefined behaviour */ mask = (BN_ULONG)0 - lb; /* mask = 0 - (lb != 0) */ mask |= mask >> 8; top = a->top - nw; if (r != a && bn_wexpand(r, top) == NULL) return 0; t = &(r->d[0]); f = &(a->d[nw]); l = f[0]; for (i = 0; i < top - 1; i++) { m = f[i + 1]; t[i] = (l >> rb) | ((m << lb) & mask); l = m; } t[i] = l >> rb; r->neg = a->neg; r->top = top; r->flags |= BN_FLG_FIXED_TOP; return 1; }
44de60600558b0a14a7ad7eef1bb311d8b521fbc
950a8f43e5ad8696b71a322ad6c92a7710d736ff
/player/bladeplayer.c
e202428e7ee4ec6b0ccb3b74ba529d5e6eed49f1
[ "MIT" ]
permissive
gym487/gps-sdr-sim-realtime
b3b9c9dc5c5dfc7714a12188517116027693231d
759dd3b9658e5317634a4398bbfadfcb620a4924
refs/heads/master
2022-08-09T19:41:13.459937
2022-07-12T00:47:24
2022-07-12T00:47:24
89,053,550
127
45
MIT
2022-04-15T07:34:29
2017-04-22T07:51:06
C
UTF-8
C
false
false
8,945
c
bladeplayer.c
#define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> #include <string.h> #include <libbladeRF.h> #ifdef _WIN32 #include "getopt.h" #else #include <getopt.h> #include <unistd.h> #include <errno.h> #endif #define TX_FREQUENCY 1575420000 #define TX_SAMPLERATE 2600000 #define TX_BANDWIDTH 2500000 #define TX_VGA1 -25 #define TX_VGA2 0 #define NUM_BUFFERS 32 #define SAMPLES_PER_BUFFER (32 * 1024) #define NUM_TRANSFERS 16 #define TIMEOUT_MS 1000 #define AMPLITUDE (1000) // Default amplitude for 12-bit I/Q void usage(void) { fprintf(stderr, "Usage: bladeplayer [options]\n" " -f <tx_file> I/Q sampling data file (required)\n" " -b <iq_bits> I/Q data format [1/16] (default: 16)\n" " -g <tx_vga1> TX VGA1 gain (default: %d)\n", TX_VGA1); return; } int main(int argc, char *argv[]) { int status; char *devstr = NULL; struct bladerf *dev = NULL; FILE *fp; int16_t *tx_buffer; enum state {INIT, READ_FILE, PAD_TRAILING, DONE}; enum state state = INIT; int compressed = 0; uint8_t *read_buffer; size_t samples_read; int16_t lut[256][8]; int16_t amp = AMPLITUDE; uint32_t i,k; int gain = TX_VGA1; int result; int data_format; char txfile[128]; // Empty TX file name txfile[0] = 0; if (argc<3) { usage(); exit(1); } while ((result=getopt(argc,argv,"g:b:f:"))!=-1) { switch (result) { case 'g': gain = atoi(optarg); if (gain>-4 || gain<-35) { printf("ERROR: Invalid TX VGA1 gain.\n"); exit(1); } break; case 'b': data_format = atoi(optarg); if (data_format!=1 && data_format!=16) { printf("ERROR: Invalid I/Q data format.\n"); exit(1); } else if (data_format==1) compressed = 1; break; case 'f': strcpy(txfile, optarg); break; case ':': case '?': usage(); exit(1); default: break; } } // Open TX file. if (txfile[0]==0) { printf("ERROR: I/Q sampling data file is not specified.\n"); exit(1); } fp = fopen(txfile, "rb"); if (fp==NULL) { fprintf(stderr, "ERROR: Failed to open TX file: %s\n", argv[1]); exit(1); } // Initializing device. printf("Opening and initializing device...\n"); status = bladerf_open(&dev, devstr); if (status != 0) { fprintf(stderr, "Failed to open device: %s\n", bladerf_strerror(status)); goto out; } status = bladerf_set_frequency(dev, BLADERF_MODULE_TX, TX_FREQUENCY); if (status != 0) { fprintf(stderr, "Faield to set TX frequency: %s\n", bladerf_strerror(status)); goto out; } else { printf("TX frequency: %u Hz\n", TX_FREQUENCY); } status = bladerf_set_sample_rate(dev, BLADERF_MODULE_TX, TX_SAMPLERATE, NULL); if (status != 0) { fprintf(stderr, "Failed to set TX sample rate: %s\n", bladerf_strerror(status)); goto out; } else { printf("TX sample rate: %u sps\n", TX_SAMPLERATE); } status = bladerf_set_bandwidth(dev, BLADERF_MODULE_TX, TX_BANDWIDTH, NULL); if (status != 0) { fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status)); goto out; } else { printf("TX bandwidth: %u Hz\n", TX_BANDWIDTH); } status = bladerf_set_txvga1(dev, gain); if (status != 0) { fprintf(stderr, "Failed to set TX VGA1 gain: %s\n", bladerf_strerror(status)); goto out; } else { printf("TX VGA1 gain: %d dB\n", gain); } status = bladerf_set_txvga2(dev, TX_VGA2); if (status != 0) { fprintf(stderr, "Failed to set TX VGA2 gain: %s\n", bladerf_strerror(status)); goto out; } else { printf("TX VGA2 gain: %d dB\n", TX_VGA2); } // Application code goes here. printf("Running...\n"); // Allocate a buffer to hold each block of samples to transmit. tx_buffer = (int16_t*)malloc(SAMPLES_PER_BUFFER * 2 * sizeof(int16_t)); if (tx_buffer == NULL) { fprintf(stderr, "Failed to allocate TX buffer.\n"); goto out; } // if compressed read_buffer = (uint8_t*)malloc(SAMPLES_PER_BUFFER / 4); if (read_buffer == NULL) { fprintf(stderr, "Failed to allocate read buffer.\n"); goto out; } for (i=0; i<256; i++) { for (k=0; k<8; k++) lut[i][k] = ((i>>(7-k))&0x1)?amp:-amp; } // Configure the TX module for use with the synchronous interface. status = bladerf_sync_config(dev, BLADERF_MODULE_TX, BLADERF_FORMAT_SC16_Q11, NUM_BUFFERS, SAMPLES_PER_BUFFER, NUM_TRANSFERS, TIMEOUT_MS); if (status != 0) { fprintf(stderr, "Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); goto out; } // We must always enable the modules *after* calling bladerf_sync_config(). status = bladerf_enable_module(dev, BLADERF_MODULE_TX, true); if (status != 0) { fprintf(stderr, "Failed to enable TX module: %s\n", bladerf_strerror(status)); goto out; } // Keep writing samples while there is more data to send and no failures have occurred. while (state != DONE && status == 0) { int16_t *tx_buffer_current = tx_buffer; unsigned int buffer_samples_remaining = SAMPLES_PER_BUFFER; // if compressed unsigned int read_samples_remaining = SAMPLES_PER_BUFFER / 4; // Keep adding to the buffer until it is full or a failure occurs while (buffer_samples_remaining > 0 && status == 0 && state != DONE) { size_t samples_populated = 0; switch(state) { case INIT: case READ_FILE: // Read from the input file if (compressed) { int16_t *write_buffer_current = tx_buffer; samples_read = fread(read_buffer, sizeof(uint8_t), read_samples_remaining, fp); samples_populated = samples_read * 4; buffer_samples_remaining = read_samples_remaining * 4; // Expand compressed data into TX buffer for (i=0; i<samples_read; i++) { memcpy(write_buffer_current, lut[read_buffer[i]], 8); // Advance the write buffer pointer write_buffer_current += 8; } } else { samples_populated = fread(tx_buffer_current, 2 * sizeof(int16_t), buffer_samples_remaining, fp); } // If the end of the file was reached, pad the rest of the buffer and finish. if (feof(fp)) { state = PAD_TRAILING; } // Check for errors else if (ferror(fp)) { status = errno; } break; case PAD_TRAILING: // Populate the remainder of the buffer with zeros. memset(tx_buffer_current, 0, buffer_samples_remaining * 2 * sizeof(uint16_t)); state = DONE; break; case DONE: default: break; } // Advance the buffer pointer. buffer_samples_remaining -= (unsigned int)samples_populated; tx_buffer_current += (2 * samples_populated); } // If there were no errors, transmit the data buffer. if (status == 0) { bladerf_sync_tx(dev, tx_buffer, SAMPLES_PER_BUFFER, NULL, TIMEOUT_MS); } } // Disable TX module, shutting down our underlying TX stream. status = bladerf_enable_module(dev, BLADERF_MODULE_TX, false); if (status != 0) { fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(status)); } // Free up our resources free(tx_buffer); // if compressed free(read_buffer); // Close TX file fclose(fp); out: printf("Closing device...\n"); bladerf_close(dev); return(0); }
e8b0af0a0af3fe8b38eae6f6e67f0dba601154a4
83e7dc1281874779c46dfadcc15b2bb66d8e599c
/examples/event/lv_example_event_4.c
ac4670aab87aef53796a75aae2d37dd69aecf569
[ "MIT" ]
permissive
lvgl/lvgl
7d51d6774d6ac71df7101fc7ded56fea4b70be01
5c984b4a5364b6455966eb3a860153806c51626f
refs/heads/master
2023-08-30T22:39:20.283922
2023-08-30T19:55:29
2023-08-30T19:55:29
60,667,730
9,296
2,218
MIT
2023-09-14T17:59:34
2016-06-08T04:14:34
C
UTF-8
C
false
false
1,554
c
lv_example_event_4.c
#include "../lv_examples.h" #if LV_BUILD_EXAMPLES static uint32_t size = 0; static bool size_dec = false; static void timer_cb(lv_timer_t * timer) { lv_obj_invalidate(timer->user_data); if(size_dec) size--; else size++; if(size == 50) size_dec = true; else if(size == 0) size_dec = false; } static void event_cb(lv_event_t * e) { lv_obj_t * obj = lv_event_get_target(e); lv_draw_task_t * draw_task = lv_event_get_draw_task(e); lv_draw_dsc_base_t * base_dsc = draw_task->draw_dsc; if(base_dsc->part == LV_PART_MAIN) { lv_draw_rect_dsc_t draw_dsc; lv_draw_rect_dsc_init(&draw_dsc); draw_dsc.bg_color = lv_color_hex(0xffaaaa); draw_dsc.radius = LV_RADIUS_CIRCLE; draw_dsc.border_color = lv_color_hex(0xff5555); draw_dsc.border_width = 2; draw_dsc.outline_color = lv_color_hex(0xff0000); draw_dsc.outline_pad = 3; draw_dsc.outline_width = 2; lv_area_t a; a.x1 = 0; a.y1 = 0; a.x2 = size; a.y2 = size; lv_area_align(&obj->coords, &a, LV_ALIGN_CENTER, 0, 0); lv_draw_rect(base_dsc->layer, &draw_dsc, &a); } } /** * Demonstrate the usage of draw event */ void lv_example_event_4(void) { lv_obj_t * cont = lv_obj_create(lv_scr_act()); lv_obj_set_size(cont, 200, 200); lv_obj_center(cont); lv_obj_add_event(cont, event_cb, LV_EVENT_DRAW_TASK_ADDED, NULL); lv_obj_add_flag(cont, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS); lv_timer_create(timer_cb, 30, cont); } #endif
babf2a6d71d81a3c7216341111ae3ea7b9ea7179
d9b749e8a4982b8bcd66a19d4ee189fc607ab79e
/iterator/iter_hints.c
a60d9a6b1cf2587c8d14c99077821a9e520bc6cb
[ "LicenseRef-scancode-free-unknown", "GPL-3.0-or-later", "LicenseRef-scancode-autoconf-simple-exception", "BSD-3-Clause" ]
permissive
NLnetLabs/unbound
26312ae0b3b963f2ab700c4be3d9c45587bcf45e
10843805ac37002f1d9293c9835a3e68e41d392d
refs/heads/master
2023-08-31T23:34:52.610625
2023-08-31T11:54:03
2023-08-31T11:54:03
94,195,301
2,526
395
BSD-3-Clause
2023-09-07T14:37:56
2017-06-13T09:27:49
C
UTF-8
C
false
false
15,946
c
iter_hints.c
/* * iterator/iter_hints.c - iterative resolver module stub and root hints. * * Copyright (c) 2007, NLnet Labs. All rights reserved. * * This software is open source. * * 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 NLNET LABS 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. */ /** * \file * * This file contains functions to assist the iterator module. * Keep track of stub and root hints, and read those from config. */ #include "config.h" #include "iterator/iter_hints.h" #include "iterator/iter_delegpt.h" #include "util/log.h" #include "util/config_file.h" #include "util/net_help.h" #include "util/data/dname.h" #include "sldns/rrdef.h" #include "sldns/str2wire.h" #include "sldns/wire2str.h" struct iter_hints* hints_create(void) { struct iter_hints* hints = (struct iter_hints*)calloc(1, sizeof(struct iter_hints)); if(!hints) return NULL; return hints; } static void hints_stub_free(struct iter_hints_stub* s) { if(!s) return; delegpt_free_mlc(s->dp); free(s); } static void delhintnode(rbnode_type* n, void* ATTR_UNUSED(arg)) { struct iter_hints_stub* node = (struct iter_hints_stub*)n; hints_stub_free(node); } static void hints_del_tree(struct iter_hints* hints) { traverse_postorder(&hints->tree, &delhintnode, NULL); } void hints_delete(struct iter_hints* hints) { if(!hints) return; hints_del_tree(hints); free(hints); } /** add hint to delegation hints */ static int ah(struct delegpt* dp, const char* sv, const char* ip) { struct sockaddr_storage addr; socklen_t addrlen; size_t dname_len; uint8_t* dname = sldns_str2wire_dname(sv, &dname_len); if(!dname) { log_err("could not parse %s", sv); return 0; } if(!delegpt_add_ns_mlc(dp, dname, 0, NULL, UNBOUND_DNS_PORT) || !extstrtoaddr(ip, &addr, &addrlen, UNBOUND_DNS_PORT) || !delegpt_add_target_mlc(dp, dname, dname_len, &addr, addrlen, 0, 0)) { free(dname); return 0; } free(dname); return 1; } /** obtain compiletime provided root hints */ static struct delegpt* compile_time_root_prime(int do_ip4, int do_ip6) { /* from: ; This file is made available by InterNIC ; under anonymous FTP as ; file /domain/named.cache ; on server FTP.INTERNIC.NET ; -OR- RS.INTERNIC.NET ; ; related version of root zone: changes-on-20120103 */ struct delegpt* dp = delegpt_create_mlc((uint8_t*)"\000"); if(!dp) return NULL; dp->has_parent_side_NS = 1; if(do_ip4) { if(!ah(dp, "A.ROOT-SERVERS.NET.", "198.41.0.4")) goto failed; if(!ah(dp, "B.ROOT-SERVERS.NET.", "199.9.14.201")) goto failed; if(!ah(dp, "C.ROOT-SERVERS.NET.", "192.33.4.12")) goto failed; if(!ah(dp, "D.ROOT-SERVERS.NET.", "199.7.91.13")) goto failed; if(!ah(dp, "E.ROOT-SERVERS.NET.", "192.203.230.10")) goto failed; if(!ah(dp, "F.ROOT-SERVERS.NET.", "192.5.5.241")) goto failed; if(!ah(dp, "G.ROOT-SERVERS.NET.", "192.112.36.4")) goto failed; if(!ah(dp, "H.ROOT-SERVERS.NET.", "198.97.190.53")) goto failed; if(!ah(dp, "I.ROOT-SERVERS.NET.", "192.36.148.17")) goto failed; if(!ah(dp, "J.ROOT-SERVERS.NET.", "192.58.128.30")) goto failed; if(!ah(dp, "K.ROOT-SERVERS.NET.", "193.0.14.129")) goto failed; if(!ah(dp, "L.ROOT-SERVERS.NET.", "199.7.83.42")) goto failed; if(!ah(dp, "M.ROOT-SERVERS.NET.", "202.12.27.33")) goto failed; } if(do_ip6) { if(!ah(dp, "A.ROOT-SERVERS.NET.", "2001:503:ba3e::2:30")) goto failed; if(!ah(dp, "B.ROOT-SERVERS.NET.", "2001:500:200::b")) goto failed; if(!ah(dp, "C.ROOT-SERVERS.NET.", "2001:500:2::c")) goto failed; if(!ah(dp, "D.ROOT-SERVERS.NET.", "2001:500:2d::d")) goto failed; if(!ah(dp, "E.ROOT-SERVERS.NET.", "2001:500:a8::e")) goto failed; if(!ah(dp, "F.ROOT-SERVERS.NET.", "2001:500:2f::f")) goto failed; if(!ah(dp, "G.ROOT-SERVERS.NET.", "2001:500:12::d0d")) goto failed; if(!ah(dp, "H.ROOT-SERVERS.NET.", "2001:500:1::53")) goto failed; if(!ah(dp, "I.ROOT-SERVERS.NET.", "2001:7fe::53")) goto failed; if(!ah(dp, "J.ROOT-SERVERS.NET.", "2001:503:c27::2:30")) goto failed; if(!ah(dp, "K.ROOT-SERVERS.NET.", "2001:7fd::1")) goto failed; if(!ah(dp, "L.ROOT-SERVERS.NET.", "2001:500:9f::42")) goto failed; if(!ah(dp, "M.ROOT-SERVERS.NET.", "2001:dc3::35")) goto failed; } return dp; failed: delegpt_free_mlc(dp); return 0; } /** insert new hint info into hint structure */ static int hints_insert(struct iter_hints* hints, uint16_t c, struct delegpt* dp, int noprime) { struct iter_hints_stub* node = (struct iter_hints_stub*)malloc( sizeof(struct iter_hints_stub)); if(!node) { delegpt_free_mlc(dp); return 0; } node->dp = dp; node->noprime = (uint8_t)noprime; if(!name_tree_insert(&hints->tree, &node->node, dp->name, dp->namelen, dp->namelabs, c)) { char buf[257]; dname_str(dp->name, buf); log_err("second hints for zone %s ignored.", buf); delegpt_free_mlc(dp); free(node); } return 1; } /** set stub name */ static struct delegpt* read_stubs_name(struct config_stub* s) { struct delegpt* dp; size_t dname_len; uint8_t* dname; if(!s->name) { log_err("stub zone without a name"); return NULL; } dname = sldns_str2wire_dname(s->name, &dname_len); if(!dname) { log_err("cannot parse stub zone name %s", s->name); return NULL; } if(!(dp=delegpt_create_mlc(dname))) { free(dname); log_err("out of memory"); return NULL; } free(dname); return dp; } /** set stub host names */ static int read_stubs_host(struct config_stub* s, struct delegpt* dp) { struct config_strlist* p; uint8_t* dname; char* tls_auth_name; int port; for(p = s->hosts; p; p = p->next) { log_assert(p->str); dname = authextstrtodname(p->str, &port, &tls_auth_name); if(!dname) { log_err("cannot parse stub %s nameserver name: '%s'", s->name, p->str); return 0; } #if ! defined(HAVE_SSL_SET1_HOST) && ! defined(HAVE_X509_VERIFY_PARAM_SET1_HOST) if(tls_auth_name) log_err("no name verification functionality in " "ssl library, ignored name for %s", p->str); #endif if(!delegpt_add_ns_mlc(dp, dname, 0, tls_auth_name, port)) { free(dname); log_err("out of memory"); return 0; } free(dname); } return 1; } /** set stub server addresses */ static int read_stubs_addr(struct config_stub* s, struct delegpt* dp) { struct config_strlist* p; struct sockaddr_storage addr; socklen_t addrlen; char* auth_name; for(p = s->addrs; p; p = p->next) { log_assert(p->str); if(!authextstrtoaddr(p->str, &addr, &addrlen, &auth_name)) { log_err("cannot parse stub %s ip address: '%s'", s->name, p->str); return 0; } #if ! defined(HAVE_SSL_SET1_HOST) && ! defined(HAVE_X509_VERIFY_PARAM_SET1_HOST) if(auth_name) log_err("no name verification functionality in " "ssl library, ignored name for %s", p->str); #endif if(!delegpt_add_addr_mlc(dp, &addr, addrlen, 0, 0, auth_name, -1)) { log_err("out of memory"); return 0; } } return 1; } /** read stubs config */ static int read_stubs(struct iter_hints* hints, struct config_file* cfg) { struct config_stub* s; struct delegpt* dp; for(s = cfg->stubs; s; s = s->next) { if(!(dp=read_stubs_name(s))) return 0; if(!read_stubs_host(s, dp) || !read_stubs_addr(s, dp)) { delegpt_free_mlc(dp); return 0; } /* the flag is turned off for 'stub-first' so that the * last resort will ask for parent-side NS record and thus * fallback to the internet name servers on a failure */ dp->has_parent_side_NS = (uint8_t)!s->isfirst; /* Do not cache if set. */ dp->no_cache = s->no_cache; /* ssl_upstream */ dp->ssl_upstream = (uint8_t)s->ssl_upstream; /* tcp_upstream */ dp->tcp_upstream = (uint8_t)s->tcp_upstream; delegpt_log(VERB_QUERY, dp); if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp, !s->isprime)) return 0; } return 1; } /** read root hints from file */ static int read_root_hints(struct iter_hints* hints, char* fname) { struct sldns_file_parse_state pstate; struct delegpt* dp; uint8_t rr[LDNS_RR_BUF_SIZE]; size_t rr_len, dname_len; int status; uint16_t c = LDNS_RR_CLASS_IN; FILE* f = fopen(fname, "r"); if(!f) { log_err("could not read root hints %s: %s", fname, strerror(errno)); return 0; } dp = delegpt_create_mlc(NULL); if(!dp) { log_err("out of memory reading root hints"); fclose(f); return 0; } verbose(VERB_QUERY, "Reading root hints from %s", fname); memset(&pstate, 0, sizeof(pstate)); pstate.lineno = 1; dp->has_parent_side_NS = 1; while(!feof(f)) { rr_len = sizeof(rr); dname_len = 0; status = sldns_fp2wire_rr_buf(f, rr, &rr_len, &dname_len, &pstate); if(status != 0) { log_err("reading root hints %s %d:%d: %s", fname, pstate.lineno, LDNS_WIREPARSE_OFFSET(status), sldns_get_errorstr_parse(status)); goto stop_read; } if(rr_len == 0) continue; /* EMPTY line, TTL or ORIGIN */ if(sldns_wirerr_get_type(rr, rr_len, dname_len) == LDNS_RR_TYPE_NS) { if(!delegpt_add_ns_mlc(dp, sldns_wirerr_get_rdata(rr, rr_len, dname_len), 0, NULL, UNBOUND_DNS_PORT)) { log_err("out of memory reading root hints"); goto stop_read; } c = sldns_wirerr_get_class(rr, rr_len, dname_len); if(!dp->name) { if(!delegpt_set_name_mlc(dp, rr)) { log_err("out of memory."); goto stop_read; } } } else if(sldns_wirerr_get_type(rr, rr_len, dname_len) == LDNS_RR_TYPE_A && sldns_wirerr_get_rdatalen(rr, rr_len, dname_len) == INET_SIZE) { struct sockaddr_in sa; socklen_t len = (socklen_t)sizeof(sa); memset(&sa, 0, len); sa.sin_family = AF_INET; sa.sin_port = (in_port_t)htons(UNBOUND_DNS_PORT); memmove(&sa.sin_addr, sldns_wirerr_get_rdata(rr, rr_len, dname_len), INET_SIZE); if(!delegpt_add_target_mlc(dp, rr, dname_len, (struct sockaddr_storage*)&sa, len, 0, 0)) { log_err("out of memory reading root hints"); goto stop_read; } } else if(sldns_wirerr_get_type(rr, rr_len, dname_len) == LDNS_RR_TYPE_AAAA && sldns_wirerr_get_rdatalen(rr, rr_len, dname_len) == INET6_SIZE) { struct sockaddr_in6 sa; socklen_t len = (socklen_t)sizeof(sa); memset(&sa, 0, len); sa.sin6_family = AF_INET6; sa.sin6_port = (in_port_t)htons(UNBOUND_DNS_PORT); memmove(&sa.sin6_addr, sldns_wirerr_get_rdata(rr, rr_len, dname_len), INET6_SIZE); if(!delegpt_add_target_mlc(dp, rr, dname_len, (struct sockaddr_storage*)&sa, len, 0, 0)) { log_err("out of memory reading root hints"); goto stop_read; } } else { char buf[17]; sldns_wire2str_type_buf(sldns_wirerr_get_type(rr, rr_len, dname_len), buf, sizeof(buf)); log_warn("root hints %s:%d skipping type %s", fname, pstate.lineno, buf); } } fclose(f); if(!dp->name) { log_warn("root hints %s: no NS content", fname); delegpt_free_mlc(dp); return 1; } delegpt_log(VERB_QUERY, dp); if(!hints_insert(hints, c, dp, 0)) { return 0; } return 1; stop_read: delegpt_free_mlc(dp); fclose(f); return 0; } /** read root hints list */ static int read_root_hints_list(struct iter_hints* hints, struct config_file* cfg) { struct config_strlist* p; for(p = cfg->root_hints; p; p = p->next) { log_assert(p->str); if(p->str && p->str[0]) { char* f = p->str; if(cfg->chrootdir && cfg->chrootdir[0] && strncmp(p->str, cfg->chrootdir, strlen(cfg->chrootdir)) == 0) f += strlen(cfg->chrootdir); if(!read_root_hints(hints, f)) return 0; } } return 1; } int hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg) { hints_del_tree(hints); name_tree_init(&hints->tree); /* read root hints */ if(!read_root_hints_list(hints, cfg)) return 0; /* read stub hints */ if(!read_stubs(hints, cfg)) return 0; /* use fallback compiletime root hints */ if(!hints_lookup_root(hints, LDNS_RR_CLASS_IN)) { struct delegpt* dp = compile_time_root_prime(cfg->do_ip4, cfg->do_ip6); verbose(VERB_ALGO, "no config, using builtin root hints."); if(!dp) return 0; if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp, 0)) return 0; } name_tree_init_parents(&hints->tree); return 1; } struct delegpt* hints_lookup_root(struct iter_hints* hints, uint16_t qclass) { uint8_t rootlab = 0; struct iter_hints_stub *stub; stub = (struct iter_hints_stub*)name_tree_find(&hints->tree, &rootlab, 1, 1, qclass); if(!stub) return NULL; return stub->dp; } struct iter_hints_stub* hints_lookup_stub(struct iter_hints* hints, uint8_t* qname, uint16_t qclass, struct delegpt* cache_dp) { size_t len; int labs; struct iter_hints_stub *r; /* first lookup the stub */ labs = dname_count_size_labels(qname, &len); r = (struct iter_hints_stub*)name_tree_lookup(&hints->tree, qname, len, labs, qclass); if(!r) return NULL; /* If there is no cache (root prime situation) */ if(cache_dp == NULL) { if(r->dp->namelabs != 1) return r; /* no cache dp, use any non-root stub */ return NULL; } /* * If the stub is same as the delegation we got * And has noprime set, we need to 'prime' to use this stub instead. */ if(r->noprime && query_dname_compare(cache_dp->name, r->dp->name)==0) return r; /* use this stub instead of cached dp */ /* * If our cached delegation point is above the hint, we need to prime. */ if(dname_strict_subdomain(r->dp->name, r->dp->namelabs, cache_dp->name, cache_dp->namelabs)) return r; /* need to prime this stub */ return NULL; } int hints_next_root(struct iter_hints* hints, uint16_t* qclass) { return name_tree_next_root(&hints->tree, qclass); } size_t hints_get_mem(struct iter_hints* hints) { size_t s; struct iter_hints_stub* p; if(!hints) return 0; s = sizeof(*hints); RBTREE_FOR(p, struct iter_hints_stub*, &hints->tree) { s += sizeof(*p) + delegpt_get_mem(p->dp); } return s; } int hints_add_stub(struct iter_hints* hints, uint16_t c, struct delegpt* dp, int noprime) { struct iter_hints_stub *z; if((z=(struct iter_hints_stub*)name_tree_find(&hints->tree, dp->name, dp->namelen, dp->namelabs, c)) != NULL) { (void)rbtree_delete(&hints->tree, &z->node); hints_stub_free(z); } if(!hints_insert(hints, c, dp, noprime)) return 0; name_tree_init_parents(&hints->tree); return 1; } void hints_delete_stub(struct iter_hints* hints, uint16_t c, uint8_t* nm) { struct iter_hints_stub *z; size_t len; int labs = dname_count_size_labels(nm, &len); if(!(z=(struct iter_hints_stub*)name_tree_find(&hints->tree, nm, len, labs, c))) return; /* nothing to do */ (void)rbtree_delete(&hints->tree, &z->node); hints_stub_free(z); name_tree_init_parents(&hints->tree); }