Upload folder using huggingface_hub (part 9)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- pool/shard000/C/0008448_Timeout.c +138 -0
- pool/shard000/C/0008450_en_clock.c +308 -0
- pool/shard000/C/0008452_rpc_sign.c +109 -0
- pool/shard000/C/0008453_tcp_client.c +61 -0
- pool/shard000/C/0008478_gimpimage-pick-color.c +86 -0
- pool/shard000/C/0008496_display.c +315 -0
- pool/shard000/C/0008502_gnutls_global.c +341 -0
- pool/shard000/C/0008506_avic.c +222 -0
- pool/shard000/C/0008520_abspath.c +97 -0
- pool/shard000/C/0008521_msm7kv2-dai.c +121 -0
- pool/shard000/C/0008538_10903.c +82 -0
- pool/shard000/C/0008544_windir.c +80 -0
- pool/shard000/C/0008546_psychic.c +182 -0
- pool/shard000/C/0008549_wolfevent.c +283 -0
- pool/shard000/C/0008555_pkcs11-list.c +264 -0
- pool/shard000/C/0008576_aigMffc.c +297 -0
- pool/shard000/C/0008609_logging.c +211 -0
- pool/shard000/C/0008613_test-prioq.c +172 -0
- pool/shard000/C/0008639_lpc17xx_clkpwr.c +327 -0
- pool/shard000/C/0008652_init.c +98 -0
- pool/shard000/C/0008653_myrg_locking.c +51 -0
- pool/shard000/C/0008670_mips_features.c +125 -0
- pool/shard000/C/0008685_stdio_test.c +159 -0
- pool/shard000/C/0008695_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c +50 -0
- pool/shard000/C/0008696_end_of_solution_writer.c +59 -0
- pool/shard000/C/0008697_1.6-String_Compression.c +100 -0
- pool/shard000/C/0008698_nxeb500hmi.c +188 -0
- pool/shard000/C/0008717_heap-sort.c +218 -0
- pool/shard000/C/0008725_timecompare.c +191 -0
- pool/shard000/C/0008729_dot.c +245 -0
- pool/shard000/C/0008746_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c +63 -0
- pool/shard000/C/0008767_test.c +215 -0
- pool/shard000/C/0008783_ablk_helper.c +151 -0
- pool/shard000/C/0008799_aotrigger.c +94 -0
- pool/shard000/C/0008804_sz_string.c +62 -0
- pool/shard000/C/0008812_bigdict.c +128 -0
- pool/shard000/C/0008813_xsiget.c +60 -0
- pool/shard000/C/0008818_device.c +157 -0
- pool/shard000/C/0008825_autotools-notebook-tab.c +133 -0
- pool/shard000/C/0008837_discard.c +163 -0
- pool/shard000/C/0008848_demo.c +106 -0
- pool/shard000/C/0008854_mountpoints.c +121 -0
- pool/shard000/C/0008864_itob.c +130 -0
- pool/shard000/C/0008887_graphtest.c +61 -0
- pool/shard000/C/0008890_dvk_ebi.c +237 -0
- pool/shard000/C/0008902_comtest.c +312 -0
- pool/shard000/C/0008912_unix_misc.c +50 -0
- pool/shard000/C/0008917_PiCode.c +96 -0
- pool/shard000/C/0008927_channel_layout.c +231 -0
- pool/shard000/C/0008928_exoparg3.c +259 -0
pool/shard000/C/0008448_Timeout.c
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* vim: set expandtab ts=4 sw=4: */
|
| 2 |
+
/*
|
| 3 |
+
* You may redistribute this program and/or modify it under the terms of
|
| 4 |
+
* the GNU General Public License as published by the Free Software Foundation,
|
| 5 |
+
* either version 3 of the License, or (at your option) any later version.
|
| 6 |
+
*
|
| 7 |
+
* This program is distributed in the hope that it will be useful,
|
| 8 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
* GNU General Public License for more details.
|
| 11 |
+
*
|
| 12 |
+
* You should have received a copy of the GNU General Public License
|
| 13 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 14 |
+
*/
|
| 15 |
+
#include "util/events/libuv/UvWrapper.h"
|
| 16 |
+
#include "memory/Allocator.h"
|
| 17 |
+
#include "util/events/libuv/EventBase_pvt.h"
|
| 18 |
+
#include "util/events/Timeout.h"
|
| 19 |
+
#include "util/Identity.h"
|
| 20 |
+
|
| 21 |
+
struct Timeout
|
| 22 |
+
{
|
| 23 |
+
uv_timer_t timer;
|
| 24 |
+
|
| 25 |
+
void (* callback)(void* callbackContext);
|
| 26 |
+
|
| 27 |
+
void* callbackContext;
|
| 28 |
+
|
| 29 |
+
uint64_t milliseconds;
|
| 30 |
+
|
| 31 |
+
int isInterval;
|
| 32 |
+
|
| 33 |
+
struct Allocator* alloc;
|
| 34 |
+
|
| 35 |
+
Identity
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* The callback to be called by libuv.
|
| 40 |
+
*/
|
| 41 |
+
static void handleEvent(uv_timer_t* handle, int status)
|
| 42 |
+
{
|
| 43 |
+
struct Timeout* timeout = Identity_check((struct Timeout*) handle);
|
| 44 |
+
if (!timeout->isInterval) {
|
| 45 |
+
Timeout_clearTimeout(timeout);
|
| 46 |
+
}
|
| 47 |
+
timeout->callback(timeout->callbackContext);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
static void onFree2(uv_handle_t* timer)
|
| 51 |
+
{
|
| 52 |
+
Allocator_onFreeComplete(timer->data);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
static int onFree(struct Allocator_OnFreeJob* job)
|
| 56 |
+
{
|
| 57 |
+
struct Timeout* t = Identity_check((struct Timeout*) job->userData);
|
| 58 |
+
t->timer.data = job;
|
| 59 |
+
uv_close((uv_handle_t*) &t->timer, onFree2);
|
| 60 |
+
return Allocator_ONFREE_ASYNC;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* Create a timeout event.
|
| 65 |
+
* The timeout event will be triggered after the given number of milliseconds.
|
| 66 |
+
*
|
| 67 |
+
* @param callback the functiont to call.
|
| 68 |
+
* @param callbackContext a pointer to pass to the called function.
|
| 69 |
+
* @param milliseconds the number of milliseconds to wait before the event happens.
|
| 70 |
+
* @param interval if non-zero, this event will repeat instead of triggering once.
|
| 71 |
+
* @param eventBase the libevent event base.
|
| 72 |
+
* @param allocator the memory allocator to use for allocating the event.
|
| 73 |
+
* if this is freed, the event will be safely deleted.
|
| 74 |
+
* @return a timeout struct which can be used to clear the timeout.
|
| 75 |
+
*/
|
| 76 |
+
static struct Timeout* setTimeout(void (* const callback)(void* callbackContext),
|
| 77 |
+
void* const callbackContext,
|
| 78 |
+
const uint64_t milliseconds,
|
| 79 |
+
const uint32_t interval,
|
| 80 |
+
struct EventBase* eventBase,
|
| 81 |
+
struct Allocator* allocator)
|
| 82 |
+
{
|
| 83 |
+
struct EventBase_pvt* base = EventBase_privatize(eventBase);
|
| 84 |
+
struct Allocator* alloc = Allocator_child(allocator);
|
| 85 |
+
struct Timeout* timeout = Allocator_calloc(alloc, sizeof(struct Timeout), 1);
|
| 86 |
+
|
| 87 |
+
timeout->callback = callback;
|
| 88 |
+
timeout->callbackContext = callbackContext;
|
| 89 |
+
timeout->milliseconds = milliseconds;
|
| 90 |
+
timeout->alloc = alloc;
|
| 91 |
+
timeout->isInterval = interval;
|
| 92 |
+
Identity_set(timeout);
|
| 93 |
+
|
| 94 |
+
uv_timer_init(base->loop, &timeout->timer);
|
| 95 |
+
uv_timer_start(&timeout->timer, handleEvent, milliseconds, (interval) ? milliseconds : 0);
|
| 96 |
+
|
| 97 |
+
timeout->timer.data = timeout;
|
| 98 |
+
|
| 99 |
+
Allocator_onFree(alloc, onFree, timeout);
|
| 100 |
+
|
| 101 |
+
return timeout;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/** See: Timeout.h */
|
| 105 |
+
struct Timeout* Timeout_setTimeout(void (* const callback)(void* callbackContext),
|
| 106 |
+
void* const callbackContext,
|
| 107 |
+
const uint64_t milliseconds,
|
| 108 |
+
struct EventBase* eventBase,
|
| 109 |
+
struct Allocator* allocator)
|
| 110 |
+
{
|
| 111 |
+
return setTimeout(callback, callbackContext, milliseconds, 0, eventBase, allocator);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/** See: Timeout.h */
|
| 115 |
+
struct Timeout* Timeout_setInterval(void (* const callback)(void* callbackContext),
|
| 116 |
+
void* const callbackContext,
|
| 117 |
+
const uint64_t milliseconds,
|
| 118 |
+
struct EventBase* eventBase,
|
| 119 |
+
struct Allocator* allocator)
|
| 120 |
+
{
|
| 121 |
+
return setTimeout(callback, callbackContext, milliseconds, 1, eventBase, allocator);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/** See: Timeout.h */
|
| 125 |
+
void Timeout_resetTimeout(struct Timeout* timeout,
|
| 126 |
+
const uint64_t milliseconds)
|
| 127 |
+
{
|
| 128 |
+
Timeout_clearTimeout(timeout);
|
| 129 |
+
uv_timer_start(&timeout->timer, handleEvent, milliseconds, 0);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/** See: Timeout.h */
|
| 133 |
+
void Timeout_clearTimeout(struct Timeout* timeout)
|
| 134 |
+
{
|
| 135 |
+
if (!uv_is_closing((uv_handle_t*) &timeout->timer)) {
|
| 136 |
+
uv_timer_stop(&timeout->timer);
|
| 137 |
+
}
|
| 138 |
+
}
|
pool/shard000/C/0008450_en_clock.c
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2012 Mellanox Technologies. All rights reserved.
|
| 3 |
+
*
|
| 4 |
+
* This software is available to you under a choice of one of two
|
| 5 |
+
* licenses. You may choose to be licensed under the terms of the GNU
|
| 6 |
+
* General Public License (GPL) Version 2, available from the file
|
| 7 |
+
* COPYING in the main directory of this source tree, or the
|
| 8 |
+
* OpenIB.org BSD license below:
|
| 9 |
+
*
|
| 10 |
+
* Redistribution and use in source and binary forms, with or
|
| 11 |
+
* without modification, are permitted provided that the following
|
| 12 |
+
* conditions are met:
|
| 13 |
+
*
|
| 14 |
+
* - Redistributions of source code must retain the above
|
| 15 |
+
* copyright notice, this list of conditions and the following
|
| 16 |
+
* disclaimer.
|
| 17 |
+
*
|
| 18 |
+
* - Redistributions in binary form must reproduce the above
|
| 19 |
+
* copyright notice, this list of conditions and the following
|
| 20 |
+
* disclaimer in the documentation and/or other materials
|
| 21 |
+
* provided with the distribution.
|
| 22 |
+
*
|
| 23 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 24 |
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 25 |
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 26 |
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 27 |
+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 28 |
+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 29 |
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 30 |
+
* SOFTWARE.
|
| 31 |
+
*
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
#include <linux/mlx4/device.h>
|
| 35 |
+
#include <linux/clocksource.h>
|
| 36 |
+
|
| 37 |
+
#include "mlx4_en.h"
|
| 38 |
+
|
| 39 |
+
/* mlx4_en_read_clock - read raw cycle counter (to be used by time counter)
|
| 40 |
+
*/
|
| 41 |
+
static u64 mlx4_en_read_clock(const struct cyclecounter *tc)
|
| 42 |
+
{
|
| 43 |
+
struct mlx4_en_dev *mdev =
|
| 44 |
+
container_of(tc, struct mlx4_en_dev, cycles);
|
| 45 |
+
struct mlx4_dev *dev = mdev->dev;
|
| 46 |
+
|
| 47 |
+
return mlx4_read_clock(dev) & tc->mask;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe)
|
| 51 |
+
{
|
| 52 |
+
u64 hi, lo;
|
| 53 |
+
struct mlx4_ts_cqe *ts_cqe = (struct mlx4_ts_cqe *)cqe;
|
| 54 |
+
|
| 55 |
+
lo = (u64)be16_to_cpu(ts_cqe->timestamp_lo);
|
| 56 |
+
hi = ((u64)be32_to_cpu(ts_cqe->timestamp_hi) + !lo) << 16;
|
| 57 |
+
|
| 58 |
+
return hi | lo;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev,
|
| 62 |
+
struct skb_shared_hwtstamps *hwts,
|
| 63 |
+
u64 timestamp)
|
| 64 |
+
{
|
| 65 |
+
unsigned long flags;
|
| 66 |
+
u64 nsec;
|
| 67 |
+
|
| 68 |
+
read_lock_irqsave(&mdev->clock_lock, flags);
|
| 69 |
+
nsec = timecounter_cyc2time(&mdev->clock, timestamp);
|
| 70 |
+
read_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 71 |
+
|
| 72 |
+
memset(hwts, 0, sizeof(struct skb_shared_hwtstamps));
|
| 73 |
+
hwts->hwtstamp = ns_to_ktime(nsec);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* mlx4_en_remove_timestamp - disable PTP device
|
| 78 |
+
* @mdev: board private structure
|
| 79 |
+
*
|
| 80 |
+
* Stop the PTP support.
|
| 81 |
+
**/
|
| 82 |
+
void mlx4_en_remove_timestamp(struct mlx4_en_dev *mdev)
|
| 83 |
+
{
|
| 84 |
+
if (mdev->ptp_clock) {
|
| 85 |
+
ptp_clock_unregister(mdev->ptp_clock);
|
| 86 |
+
mdev->ptp_clock = NULL;
|
| 87 |
+
mlx4_info(mdev, "removed PHC\n");
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev)
|
| 92 |
+
{
|
| 93 |
+
bool timeout = time_is_before_jiffies(mdev->last_overflow_check +
|
| 94 |
+
mdev->overflow_period);
|
| 95 |
+
unsigned long flags;
|
| 96 |
+
|
| 97 |
+
if (timeout) {
|
| 98 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 99 |
+
timecounter_read(&mdev->clock);
|
| 100 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 101 |
+
mdev->last_overflow_check = jiffies;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* mlx4_en_phc_adjfreq - adjust the frequency of the hardware clock
|
| 107 |
+
* @ptp: ptp clock structure
|
| 108 |
+
* @delta: Desired frequency change in parts per billion
|
| 109 |
+
*
|
| 110 |
+
* Adjust the frequency of the PHC cycle counter by the indicated delta from
|
| 111 |
+
* the base frequency.
|
| 112 |
+
**/
|
| 113 |
+
static int mlx4_en_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
|
| 114 |
+
{
|
| 115 |
+
u64 adj;
|
| 116 |
+
u32 diff, mult;
|
| 117 |
+
int neg_adj = 0;
|
| 118 |
+
unsigned long flags;
|
| 119 |
+
struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
|
| 120 |
+
ptp_clock_info);
|
| 121 |
+
|
| 122 |
+
if (delta < 0) {
|
| 123 |
+
neg_adj = 1;
|
| 124 |
+
delta = -delta;
|
| 125 |
+
}
|
| 126 |
+
mult = mdev->nominal_c_mult;
|
| 127 |
+
adj = mult;
|
| 128 |
+
adj *= delta;
|
| 129 |
+
diff = div_u64(adj, 1000000000ULL);
|
| 130 |
+
|
| 131 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 132 |
+
timecounter_read(&mdev->clock);
|
| 133 |
+
mdev->cycles.mult = neg_adj ? mult - diff : mult + diff;
|
| 134 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 135 |
+
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* mlx4_en_phc_adjtime - Shift the time of the hardware clock
|
| 141 |
+
* @ptp: ptp clock structure
|
| 142 |
+
* @delta: Desired change in nanoseconds
|
| 143 |
+
*
|
| 144 |
+
* Adjust the timer by resetting the timecounter structure.
|
| 145 |
+
**/
|
| 146 |
+
static int mlx4_en_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
|
| 147 |
+
{
|
| 148 |
+
struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
|
| 149 |
+
ptp_clock_info);
|
| 150 |
+
unsigned long flags;
|
| 151 |
+
|
| 152 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 153 |
+
timecounter_adjtime(&mdev->clock, delta);
|
| 154 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 155 |
+
|
| 156 |
+
return 0;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* mlx4_en_phc_gettime - Reads the current time from the hardware clock
|
| 161 |
+
* @ptp: ptp clock structure
|
| 162 |
+
* @ts: timespec structure to hold the current time value
|
| 163 |
+
*
|
| 164 |
+
* Read the timecounter and return the correct value in ns after converting
|
| 165 |
+
* it into a struct timespec.
|
| 166 |
+
**/
|
| 167 |
+
static int mlx4_en_phc_gettime(struct ptp_clock_info *ptp,
|
| 168 |
+
struct timespec64 *ts)
|
| 169 |
+
{
|
| 170 |
+
struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
|
| 171 |
+
ptp_clock_info);
|
| 172 |
+
unsigned long flags;
|
| 173 |
+
u64 ns;
|
| 174 |
+
|
| 175 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 176 |
+
ns = timecounter_read(&mdev->clock);
|
| 177 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 178 |
+
|
| 179 |
+
*ts = ns_to_timespec64(ns);
|
| 180 |
+
|
| 181 |
+
return 0;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* mlx4_en_phc_settime - Set the current time on the hardware clock
|
| 186 |
+
* @ptp: ptp clock structure
|
| 187 |
+
* @ts: timespec containing the new time for the cycle counter
|
| 188 |
+
*
|
| 189 |
+
* Reset the timecounter to use a new base value instead of the kernel
|
| 190 |
+
* wall timer value.
|
| 191 |
+
**/
|
| 192 |
+
static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
|
| 193 |
+
const struct timespec64 *ts)
|
| 194 |
+
{
|
| 195 |
+
struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
|
| 196 |
+
ptp_clock_info);
|
| 197 |
+
u64 ns = timespec64_to_ns(ts);
|
| 198 |
+
unsigned long flags;
|
| 199 |
+
|
| 200 |
+
/* reset the timecounter */
|
| 201 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 202 |
+
timecounter_init(&mdev->clock, &mdev->cycles, ns);
|
| 203 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 204 |
+
|
| 205 |
+
return 0;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* mlx4_en_phc_enable - enable or disable an ancillary feature
|
| 210 |
+
* @ptp: ptp clock structure
|
| 211 |
+
* @request: Desired resource to enable or disable
|
| 212 |
+
* @on: Caller passes one to enable or zero to disable
|
| 213 |
+
*
|
| 214 |
+
* Enable (or disable) ancillary features of the PHC subsystem.
|
| 215 |
+
* Currently, no ancillary features are supported.
|
| 216 |
+
**/
|
| 217 |
+
static int mlx4_en_phc_enable(struct ptp_clock_info __always_unused *ptp,
|
| 218 |
+
struct ptp_clock_request __always_unused *request,
|
| 219 |
+
int __always_unused on)
|
| 220 |
+
{
|
| 221 |
+
return -EOPNOTSUPP;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
static const struct ptp_clock_info mlx4_en_ptp_clock_info = {
|
| 225 |
+
.owner = THIS_MODULE,
|
| 226 |
+
.max_adj = 100000000,
|
| 227 |
+
.n_alarm = 0,
|
| 228 |
+
.n_ext_ts = 0,
|
| 229 |
+
.n_per_out = 0,
|
| 230 |
+
.n_pins = 0,
|
| 231 |
+
.pps = 0,
|
| 232 |
+
.adjfreq = mlx4_en_phc_adjfreq,
|
| 233 |
+
.adjtime = mlx4_en_phc_adjtime,
|
| 234 |
+
.gettime64 = mlx4_en_phc_gettime,
|
| 235 |
+
.settime64 = mlx4_en_phc_settime,
|
| 236 |
+
.enable = mlx4_en_phc_enable,
|
| 237 |
+
};
|
| 238 |
+
|
| 239 |
+
#define MLX4_EN_WRAP_AROUND_SEC 10ULL
|
| 240 |
+
|
| 241 |
+
/* This function calculates the max shift that enables the user range
|
| 242 |
+
* of MLX4_EN_WRAP_AROUND_SEC values in the cycles register.
|
| 243 |
+
*/
|
| 244 |
+
static u32 freq_to_shift(u16 freq)
|
| 245 |
+
{
|
| 246 |
+
u32 freq_khz = freq * 1000;
|
| 247 |
+
u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
|
| 248 |
+
u64 tmp_rounded =
|
| 249 |
+
roundup_pow_of_two(max_val_cycles) > max_val_cycles ?
|
| 250 |
+
roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX;
|
| 251 |
+
u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
|
| 252 |
+
max_val_cycles : tmp_rounded;
|
| 253 |
+
/* calculate max possible multiplier in order to fit in 64bit */
|
| 254 |
+
u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded);
|
| 255 |
+
|
| 256 |
+
/* This comes from the reverse of clocksource_khz2mult */
|
| 257 |
+
return ilog2(div_u64(max_mul * freq_khz, 1000000));
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
|
| 261 |
+
{
|
| 262 |
+
struct mlx4_dev *dev = mdev->dev;
|
| 263 |
+
unsigned long flags;
|
| 264 |
+
u64 ns, zero = 0;
|
| 265 |
+
|
| 266 |
+
/* mlx4_en_init_timestamp is called for each netdev.
|
| 267 |
+
* mdev->ptp_clock is common for all ports, skip initialization if
|
| 268 |
+
* was done for other port.
|
| 269 |
+
*/
|
| 270 |
+
if (mdev->ptp_clock)
|
| 271 |
+
return;
|
| 272 |
+
|
| 273 |
+
rwlock_init(&mdev->clock_lock);
|
| 274 |
+
|
| 275 |
+
memset(&mdev->cycles, 0, sizeof(mdev->cycles));
|
| 276 |
+
mdev->cycles.read = mlx4_en_read_clock;
|
| 277 |
+
mdev->cycles.mask = CLOCKSOURCE_MASK(48);
|
| 278 |
+
mdev->cycles.shift = freq_to_shift(dev->caps.hca_core_clock);
|
| 279 |
+
mdev->cycles.mult =
|
| 280 |
+
clocksource_khz2mult(1000 * dev->caps.hca_core_clock, mdev->cycles.shift);
|
| 281 |
+
mdev->nominal_c_mult = mdev->cycles.mult;
|
| 282 |
+
|
| 283 |
+
write_lock_irqsave(&mdev->clock_lock, flags);
|
| 284 |
+
timecounter_init(&mdev->clock, &mdev->cycles,
|
| 285 |
+
ktime_to_ns(ktime_get_real()));
|
| 286 |
+
write_unlock_irqrestore(&mdev->clock_lock, flags);
|
| 287 |
+
|
| 288 |
+
/* Calculate period in seconds to call the overflow watchdog - to make
|
| 289 |
+
* sure counter is checked at least once every wrap around.
|
| 290 |
+
*/
|
| 291 |
+
ns = cyclecounter_cyc2ns(&mdev->cycles, mdev->cycles.mask, zero, &zero);
|
| 292 |
+
do_div(ns, NSEC_PER_SEC / 2 / HZ);
|
| 293 |
+
mdev->overflow_period = ns;
|
| 294 |
+
|
| 295 |
+
/* Configure the PHC */
|
| 296 |
+
mdev->ptp_clock_info = mlx4_en_ptp_clock_info;
|
| 297 |
+
snprintf(mdev->ptp_clock_info.name, 16, "mlx4 ptp");
|
| 298 |
+
|
| 299 |
+
mdev->ptp_clock = ptp_clock_register(&mdev->ptp_clock_info,
|
| 300 |
+
&mdev->pdev->dev);
|
| 301 |
+
if (IS_ERR(mdev->ptp_clock)) {
|
| 302 |
+
mdev->ptp_clock = NULL;
|
| 303 |
+
mlx4_err(mdev, "ptp_clock_register failed\n");
|
| 304 |
+
} else if (mdev->ptp_clock) {
|
| 305 |
+
mlx4_info(mdev, "registered PHC clock\n");
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
}
|
pool/shard000/C/0008452_rpc_sign.c
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/*
|
| 3 |
+
* Licensed Materials - Property of IBM
|
| 4 |
+
*
|
| 5 |
+
* trousers - An open source TCG Software Stack
|
| 6 |
+
*
|
| 7 |
+
* (C) Copyright International Business Machines Corp. 2004-2006
|
| 8 |
+
*
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <syslog.h>
|
| 14 |
+
#include <string.h>
|
| 15 |
+
#include <netdb.h>
|
| 16 |
+
|
| 17 |
+
#include "trousers/tss.h"
|
| 18 |
+
#include "trousers_types.h"
|
| 19 |
+
#include "tcs_tsp.h"
|
| 20 |
+
#include "tcs_utils.h"
|
| 21 |
+
#include "tcs_int_literals.h"
|
| 22 |
+
#include "capabilities.h"
|
| 23 |
+
#include "tcslog.h"
|
| 24 |
+
#include "tcsd_wrap.h"
|
| 25 |
+
#include "tcsd.h"
|
| 26 |
+
#include "tcs_utils.h"
|
| 27 |
+
#include "rpc_tcstp_tcs.h"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
TSS_RESULT
|
| 31 |
+
tcs_wrap_Sign(struct tcsd_thread_data *data)
|
| 32 |
+
{
|
| 33 |
+
TCS_CONTEXT_HANDLE hContext;
|
| 34 |
+
TCS_KEY_HANDLE hKey;
|
| 35 |
+
UINT32 areaToSignSize;
|
| 36 |
+
BYTE *areaToSign;
|
| 37 |
+
|
| 38 |
+
TPM_AUTH auth;
|
| 39 |
+
TPM_AUTH *pAuth;
|
| 40 |
+
|
| 41 |
+
UINT32 sigSize;
|
| 42 |
+
BYTE *sig;
|
| 43 |
+
TSS_RESULT result;
|
| 44 |
+
|
| 45 |
+
int i;
|
| 46 |
+
|
| 47 |
+
if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
|
| 48 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 49 |
+
|
| 50 |
+
if ((result = ctx_verify_context(hContext)))
|
| 51 |
+
goto done;
|
| 52 |
+
|
| 53 |
+
LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
|
| 54 |
+
|
| 55 |
+
if (getData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &data->comm))
|
| 56 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 57 |
+
if (getData(TCSD_PACKET_TYPE_UINT32, 2, &areaToSignSize, 0, &data->comm))
|
| 58 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 59 |
+
|
| 60 |
+
areaToSign = calloc(1, areaToSignSize);
|
| 61 |
+
if (areaToSign == NULL) {
|
| 62 |
+
LogError("malloc of %d bytes failed.", areaToSignSize);
|
| 63 |
+
return TCSERR(TSS_E_OUTOFMEMORY);
|
| 64 |
+
}
|
| 65 |
+
if (getData(TCSD_PACKET_TYPE_PBYTE, 3, areaToSign, areaToSignSize, &data->comm)) {
|
| 66 |
+
free(areaToSign);
|
| 67 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 68 |
+
}
|
| 69 |
+
result = getData(TCSD_PACKET_TYPE_AUTH, 4, &auth, 0, &data->comm);
|
| 70 |
+
if (result == TSS_TCP_RPC_BAD_PACKET_TYPE)
|
| 71 |
+
pAuth = NULL;
|
| 72 |
+
else if (result) {
|
| 73 |
+
free(areaToSign);
|
| 74 |
+
return result;
|
| 75 |
+
} else
|
| 76 |
+
pAuth = &auth;
|
| 77 |
+
|
| 78 |
+
MUTEX_LOCK(tcsp_lock);
|
| 79 |
+
|
| 80 |
+
result = TCSP_Sign_Internal(hContext, hKey, areaToSignSize, areaToSign, pAuth, &sigSize,
|
| 81 |
+
&sig);
|
| 82 |
+
|
| 83 |
+
MUTEX_UNLOCK(tcsp_lock);
|
| 84 |
+
free(areaToSign);
|
| 85 |
+
|
| 86 |
+
if (result == TSS_SUCCESS) {
|
| 87 |
+
i = 0;
|
| 88 |
+
initData(&data->comm, 3);
|
| 89 |
+
if (pAuth != NULL) {
|
| 90 |
+
if (setData(TCSD_PACKET_TYPE_AUTH, i++, &auth, 0, &data->comm)) {
|
| 91 |
+
free(sig);
|
| 92 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
if (setData(TCSD_PACKET_TYPE_UINT32, i++, &sigSize, 0, &data->comm)) {
|
| 96 |
+
free(sig);
|
| 97 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 98 |
+
}
|
| 99 |
+
if (setData(TCSD_PACKET_TYPE_PBYTE, i++, sig, sigSize, &data->comm)) {
|
| 100 |
+
free(sig);
|
| 101 |
+
return TCSERR(TSS_E_INTERNAL_ERROR);
|
| 102 |
+
}
|
| 103 |
+
free(sig);
|
| 104 |
+
} else
|
| 105 |
+
done: initData(&data->comm, 0);
|
| 106 |
+
|
| 107 |
+
data->comm.hdr.u.result = result;
|
| 108 |
+
return TSS_SUCCESS;
|
| 109 |
+
}
|
pool/shard000/C/0008453_tcp_client.c
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <stdlib.h>
|
| 4 |
+
#include <unistd.h>
|
| 5 |
+
#include <errno.h>
|
| 6 |
+
#include <string.h>
|
| 7 |
+
|
| 8 |
+
#include <arpa/inet.h>
|
| 9 |
+
#include <sys/socket.h>
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
int
|
| 13 |
+
main(int argc, char *argv[])
|
| 14 |
+
{
|
| 15 |
+
int sockfd;
|
| 16 |
+
struct sockaddr_in serv_addr;
|
| 17 |
+
int str_len, read_len, i;
|
| 18 |
+
char msg[128];
|
| 19 |
+
|
| 20 |
+
if (argc != 3) {
|
| 21 |
+
fprintf(stderr, "Usage: ./%s <ip> <port>\n", argv[0]);
|
| 22 |
+
exit(EXIT_FAILURE);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// same as: socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
| 26 |
+
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
| 27 |
+
perror("socket() failed");
|
| 28 |
+
exit(EXIT_FAILURE);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
memset(&serv_addr, 0, sizeof(serv_addr));
|
| 32 |
+
serv_addr.sin_family = AF_INET;
|
| 33 |
+
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
|
| 34 |
+
serv_addr.sin_port = htons(atoi(argv[2]));
|
| 35 |
+
|
| 36 |
+
if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
|
| 37 |
+
fprintf(stderr, "connect() failed: %s\n", strerror(errno));
|
| 38 |
+
exit(EXIT_FAILURE);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
i = 0;
|
| 43 |
+
while ((read_len = read(sockfd, &msg[i++], 1))) {
|
| 44 |
+
if (read_len == -1) {
|
| 45 |
+
perror("read() failed");
|
| 46 |
+
close(sockfd);
|
| 47 |
+
exit(EXIT_FAILURE);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
str_len += read_len;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
msg[str_len] = '\0';
|
| 54 |
+
printf("[recv %d bytes] %s\n", str_len, msg);
|
| 55 |
+
|
| 56 |
+
close(sockfd);
|
| 57 |
+
|
| 58 |
+
return 0;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
pool/shard000/C/0008478_gimpimage-pick-color.c
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* GIMP - The GNU Image Manipulation Program
|
| 2 |
+
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU General Public License as published by
|
| 6 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 7 |
+
* (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "config.h"
|
| 20 |
+
|
| 21 |
+
#include <glib-object.h>
|
| 22 |
+
|
| 23 |
+
#include "core-types.h"
|
| 24 |
+
|
| 25 |
+
#include "gimpdrawable.h"
|
| 26 |
+
#include "gimpimage.h"
|
| 27 |
+
#include "gimpimage-pick-color.h"
|
| 28 |
+
#include "gimppickable.h"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
gboolean
|
| 32 |
+
gimp_image_pick_color (GimpImage *image,
|
| 33 |
+
GimpDrawable *drawable,
|
| 34 |
+
gint x,
|
| 35 |
+
gint y,
|
| 36 |
+
gboolean sample_merged,
|
| 37 |
+
gboolean sample_average,
|
| 38 |
+
gdouble average_radius,
|
| 39 |
+
GimpImageType *sample_type,
|
| 40 |
+
GimpRGB *color,
|
| 41 |
+
gint *color_index)
|
| 42 |
+
{
|
| 43 |
+
GimpPickable *pickable;
|
| 44 |
+
|
| 45 |
+
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
| 46 |
+
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), FALSE);
|
| 47 |
+
g_return_val_if_fail (drawable == NULL ||
|
| 48 |
+
gimp_item_get_image (GIMP_ITEM (drawable)) == image,
|
| 49 |
+
FALSE);
|
| 50 |
+
|
| 51 |
+
if (! sample_merged)
|
| 52 |
+
{
|
| 53 |
+
if (! drawable)
|
| 54 |
+
drawable = gimp_image_get_active_drawable (image);
|
| 55 |
+
|
| 56 |
+
if (! drawable)
|
| 57 |
+
return FALSE;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (sample_merged)
|
| 61 |
+
{
|
| 62 |
+
pickable = GIMP_PICKABLE (image->projection);
|
| 63 |
+
}
|
| 64 |
+
else
|
| 65 |
+
{
|
| 66 |
+
gint off_x, off_y;
|
| 67 |
+
|
| 68 |
+
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
|
| 69 |
+
x -= off_x;
|
| 70 |
+
y -= off_y;
|
| 71 |
+
|
| 72 |
+
pickable = GIMP_PICKABLE (drawable);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/* Do *not* call gimp_pickable_flush() here because it's too expensive
|
| 76 |
+
* to call it unconditionally each time e.g. the cursor view is updated.
|
| 77 |
+
* Instead, call gimp_pickable_flush() in the callers if needed.
|
| 78 |
+
*/
|
| 79 |
+
|
| 80 |
+
if (sample_type)
|
| 81 |
+
*sample_type = gimp_pickable_get_image_type (pickable);
|
| 82 |
+
|
| 83 |
+
return gimp_pickable_pick_color (pickable, x, y,
|
| 84 |
+
sample_average, average_radius,
|
| 85 |
+
color, color_index);
|
| 86 |
+
}
|
pool/shard000/C/0008496_display.c
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2009 Arnaud "arnau" Fontaine <arnau@mini-dweeb.org>
|
| 3 |
+
*
|
| 4 |
+
* This program is free software: you can redistribute it and/or
|
| 5 |
+
* modify it under the terms of the GNU General Public License as
|
| 6 |
+
* published by the Free Software Foundation, either version 3 of the
|
| 7 |
+
* License, or (at your option) any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful, but
|
| 10 |
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 12 |
+
* General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program. If not, see
|
| 16 |
+
* <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/** \file
|
| 20 |
+
* \brief Display management run on startup
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <stdlib.h>
|
| 24 |
+
#include <string.h>
|
| 25 |
+
#include <assert.h>
|
| 26 |
+
|
| 27 |
+
#include <xcb/composite.h>
|
| 28 |
+
#include <xcb/xfixes.h>
|
| 29 |
+
#include <xcb/damage.h>
|
| 30 |
+
#include <xcb/xcb_ewmh.h>
|
| 31 |
+
#include <xcb/xcb_event.h>
|
| 32 |
+
#include <xcb/xcb_aux.h>
|
| 33 |
+
|
| 34 |
+
#include "structs.h"
|
| 35 |
+
#include "display.h"
|
| 36 |
+
#include "atoms.h"
|
| 37 |
+
#include "event.h"
|
| 38 |
+
#include "window.h"
|
| 39 |
+
#include "util.h"
|
| 40 |
+
|
| 41 |
+
/** Structure holding cookies for QueryVersion requests of
|
| 42 |
+
extensions */
|
| 43 |
+
typedef struct {
|
| 44 |
+
/** XFixes QueryVersion request cookie */
|
| 45 |
+
xcb_xfixes_query_version_cookie_t xfixes;
|
| 46 |
+
/** Damage QueryVersion request cookie */
|
| 47 |
+
xcb_damage_query_version_cookie_t damage;
|
| 48 |
+
/** Composite QueryVersion request cookie */
|
| 49 |
+
xcb_composite_query_version_cookie_t composite;
|
| 50 |
+
} init_extensions_cookies_t;
|
| 51 |
+
|
| 52 |
+
/** NOTICE: All above variables are not thread-safe, but well, we
|
| 53 |
+
don't care as they are only used during initialisation */
|
| 54 |
+
|
| 55 |
+
/** Initialise the QueryVersion extensions cookies with a 0 sequence
|
| 56 |
+
number, this is not thread-safe but we don't care here as it is
|
| 57 |
+
only used during initialisation */
|
| 58 |
+
static init_extensions_cookies_t _init_extensions_cookies = { { 0 }, { 0 }, { 0 } };
|
| 59 |
+
|
| 60 |
+
/** Cookie request used when acquiring ownership on _NET_WM_CM_Sn */
|
| 61 |
+
static xcb_get_selection_owner_cookie_t _get_wm_cm_owner_cookie = { 0 };
|
| 62 |
+
|
| 63 |
+
/** Cookie when querying the windows tree starting from the root
|
| 64 |
+
window */
|
| 65 |
+
static xcb_query_tree_cookie_t _query_tree_cookie = { 0 };
|
| 66 |
+
|
| 67 |
+
/** Check whether the needed X extensions are present on the
|
| 68 |
+
* server-side (all the data have been previously pre-fetched in the
|
| 69 |
+
* extension cache). Then send requests to check their version by
|
| 70 |
+
* sending QueryVersion requests which is compulsory because the
|
| 71 |
+
* client MUST negotiate the version of the extension before
|
| 72 |
+
* executing extension requests
|
| 73 |
+
*/
|
| 74 |
+
void
|
| 75 |
+
display_init_extensions(void)
|
| 76 |
+
{
|
| 77 |
+
globalconf.extensions.composite = xcb_get_extension_data(globalconf.connection,
|
| 78 |
+
&xcb_composite_id);
|
| 79 |
+
|
| 80 |
+
globalconf.extensions.xfixes = xcb_get_extension_data(globalconf.connection,
|
| 81 |
+
&xcb_xfixes_id);
|
| 82 |
+
|
| 83 |
+
globalconf.extensions.damage = xcb_get_extension_data(globalconf.connection,
|
| 84 |
+
&xcb_damage_id);
|
| 85 |
+
|
| 86 |
+
if(!globalconf.extensions.composite ||
|
| 87 |
+
!globalconf.extensions.composite->present)
|
| 88 |
+
fatal("No Composite extension");
|
| 89 |
+
|
| 90 |
+
debug("Composite: major_opcode=%ju",
|
| 91 |
+
(uintmax_t) globalconf.extensions.composite->major_opcode);
|
| 92 |
+
|
| 93 |
+
if(!globalconf.extensions.xfixes ||
|
| 94 |
+
!globalconf.extensions.xfixes->present)
|
| 95 |
+
fatal("No XFixes extension");
|
| 96 |
+
|
| 97 |
+
debug("XFixes: major_opcode=%ju",
|
| 98 |
+
(uintmax_t) globalconf.extensions.xfixes->major_opcode);
|
| 99 |
+
|
| 100 |
+
if(!globalconf.extensions.damage ||
|
| 101 |
+
!globalconf.extensions.damage->present)
|
| 102 |
+
fatal("No Damage extension");
|
| 103 |
+
|
| 104 |
+
debug("Damage: major_opcode=%ju",
|
| 105 |
+
(uintmax_t) globalconf.extensions.damage->major_opcode);
|
| 106 |
+
|
| 107 |
+
_init_extensions_cookies.composite =
|
| 108 |
+
xcb_composite_query_version_unchecked(globalconf.connection,
|
| 109 |
+
XCB_COMPOSITE_MAJOR_VERSION,
|
| 110 |
+
XCB_COMPOSITE_MINOR_VERSION);
|
| 111 |
+
|
| 112 |
+
_init_extensions_cookies.damage =
|
| 113 |
+
xcb_damage_query_version_unchecked(globalconf.connection,
|
| 114 |
+
XCB_DAMAGE_MAJOR_VERSION,
|
| 115 |
+
XCB_DAMAGE_MINOR_VERSION);
|
| 116 |
+
|
| 117 |
+
_init_extensions_cookies.xfixes =
|
| 118 |
+
xcb_xfixes_query_version_unchecked(globalconf.connection,
|
| 119 |
+
XCB_XFIXES_MAJOR_VERSION,
|
| 120 |
+
XCB_XFIXES_MINOR_VERSION);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
/** Get the replies of the QueryVersion requests previously sent and
|
| 124 |
+
* check if their version actually matched the versions needed
|
| 125 |
+
*
|
| 126 |
+
* \see display_init_extensions
|
| 127 |
+
*/
|
| 128 |
+
void
|
| 129 |
+
display_init_extensions_finalise(void)
|
| 130 |
+
{
|
| 131 |
+
assert(_init_extensions_cookies.composite.sequence);
|
| 132 |
+
|
| 133 |
+
xcb_composite_query_version_reply_t *composite_version_reply =
|
| 134 |
+
xcb_composite_query_version_reply(globalconf.connection,
|
| 135 |
+
_init_extensions_cookies.composite,
|
| 136 |
+
NULL);
|
| 137 |
+
|
| 138 |
+
/* Need NameWindowPixmap support introduced in version >= 0.2 */
|
| 139 |
+
if(!composite_version_reply || composite_version_reply->minor_version < 2)
|
| 140 |
+
{
|
| 141 |
+
free(composite_version_reply);
|
| 142 |
+
fatal("Need Composite extension 0.2 at least");
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
free(composite_version_reply);
|
| 146 |
+
|
| 147 |
+
assert(_init_extensions_cookies.damage.sequence);
|
| 148 |
+
|
| 149 |
+
xcb_damage_query_version_reply_t *damage_version_reply =
|
| 150 |
+
xcb_damage_query_version_reply(globalconf.connection,
|
| 151 |
+
_init_extensions_cookies.damage,
|
| 152 |
+
NULL);
|
| 153 |
+
|
| 154 |
+
if(!damage_version_reply)
|
| 155 |
+
fatal("Can't initialise Damage extension");
|
| 156 |
+
|
| 157 |
+
free(damage_version_reply);
|
| 158 |
+
|
| 159 |
+
assert(_init_extensions_cookies.xfixes.sequence);
|
| 160 |
+
|
| 161 |
+
xcb_xfixes_query_version_reply_t *xfixes_version_reply =
|
| 162 |
+
xcb_xfixes_query_version_reply(globalconf.connection,
|
| 163 |
+
_init_extensions_cookies.xfixes,
|
| 164 |
+
NULL);
|
| 165 |
+
|
| 166 |
+
/* Need Region objects support introduced in version >= 2.0 */
|
| 167 |
+
if(!xfixes_version_reply || xfixes_version_reply->major_version < 2)
|
| 168 |
+
{
|
| 169 |
+
free(xfixes_version_reply);
|
| 170 |
+
fatal("Need XFixes extension 2.0 at least");
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
free(xfixes_version_reply);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/** Handler for PropertyNotify event meaningful to set the timestamp
|
| 177 |
+
* (given in the PropertyNotify event field) when acquiring the
|
| 178 |
+
* ownership of _NET_WM_CM_Sn using SetOwner request (as specified in
|
| 179 |
+
* ICCCM and EWMH)
|
| 180 |
+
*
|
| 181 |
+
* \see display_register_cm
|
| 182 |
+
* \param event The X PropertyNotify event
|
| 183 |
+
*/
|
| 184 |
+
static int
|
| 185 |
+
display_event_set_owner_property(void *data __attribute__((unused)),
|
| 186 |
+
xcb_connection_t *c __attribute__((unused)),
|
| 187 |
+
xcb_property_notify_event_t *event)
|
| 188 |
+
{
|
| 189 |
+
debug("Set _NET_WM_CM_Sn ownership");
|
| 190 |
+
|
| 191 |
+
/* Set ownership on _NET_WM_CM_Sn giving the Compositing Manager window */
|
| 192 |
+
xcb_ewmh_set_wm_cm_owner(&globalconf.ewmh, globalconf.screen_nbr,
|
| 193 |
+
globalconf.cm_window, event->time, 0, 0);
|
| 194 |
+
|
| 195 |
+
/* Send request to check whether the ownership succeeded */
|
| 196 |
+
_get_wm_cm_owner_cookie = xcb_ewmh_get_wm_cm_owner_unchecked(&globalconf.ewmh,
|
| 197 |
+
globalconf.screen_nbr);
|
| 198 |
+
|
| 199 |
+
return 0;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/** Register Compositing Manager, e.g. set ownership on EMWH
|
| 203 |
+
* _NET_WM_CM_Sn atom used to politely stating that a Compositing
|
| 204 |
+
* Manager is currently running. Acquiring ownership is done in the
|
| 205 |
+
* following steps (ICCCM explains the principles of selection
|
| 206 |
+
* ownership):
|
| 207 |
+
*
|
| 208 |
+
* 0/ Check whether this selection is already owned by another
|
| 209 |
+
* program
|
| 210 |
+
*
|
| 211 |
+
* 1/ Create a Window whose identifier is set as the _NET_WM_CM_Sn
|
| 212 |
+
* value
|
| 213 |
+
*
|
| 214 |
+
* 2/ Change a Window property to generate a PropertyNotify event
|
| 215 |
+
* used as the timestamp to SetOwner request as multiple attempts
|
| 216 |
+
* may be sent at the same time
|
| 217 |
+
*
|
| 218 |
+
* 3/ Send SetOwner request
|
| 219 |
+
*
|
| 220 |
+
* 4/ Check whether the SetOwner request succeeds
|
| 221 |
+
*/
|
| 222 |
+
void
|
| 223 |
+
display_register_cm(void)
|
| 224 |
+
{
|
| 225 |
+
globalconf.cm_window = xcb_generate_id(globalconf.connection);
|
| 226 |
+
|
| 227 |
+
/* Create a dummy window meaningful to set the ownership on
|
| 228 |
+
_NET_WM_CM_Sn atom */
|
| 229 |
+
const uint32_t create_win_val[] = { true, XCB_EVENT_MASK_PROPERTY_CHANGE };
|
| 230 |
+
|
| 231 |
+
xcb_create_window(globalconf.connection, XCB_COPY_FROM_PARENT,
|
| 232 |
+
globalconf.cm_window, globalconf.screen->root, 0, 0, 1, 1, 0,
|
| 233 |
+
XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
|
| 234 |
+
XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
|
| 235 |
+
create_win_val);
|
| 236 |
+
|
| 237 |
+
xcb_event_set_property_notify_handler(&globalconf.evenths,
|
| 238 |
+
display_event_set_owner_property,
|
| 239 |
+
NULL);
|
| 240 |
+
|
| 241 |
+
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
| 242 |
+
globalconf.cm_window, globalconf.ewmh._NET_WM_NAME,
|
| 243 |
+
globalconf.ewmh.UTF8_STRING, 8,
|
| 244 |
+
sizeof(PACKAGE_NAME), PACKAGE_NAME);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
/** Finish acquiring ownership by checking whether the SetOwner
|
| 248 |
+
* request succeeded
|
| 249 |
+
*
|
| 250 |
+
* \see display_register_cm
|
| 251 |
+
* \return bool true if it succeeded, false otherwise
|
| 252 |
+
*/
|
| 253 |
+
bool
|
| 254 |
+
display_register_cm_finalise(void)
|
| 255 |
+
{
|
| 256 |
+
assert(_get_wm_cm_owner_cookie.sequence);
|
| 257 |
+
|
| 258 |
+
xcb_window_t wm_cm_owner_win;
|
| 259 |
+
|
| 260 |
+
/* Check whether the ownership of WM_CM_Sn succeeded */
|
| 261 |
+
return (xcb_ewmh_get_wm_cm_owner_reply(&globalconf.ewmh, _get_wm_cm_owner_cookie,
|
| 262 |
+
&wm_cm_owner_win, NULL) &&
|
| 263 |
+
wm_cm_owner_win == globalconf.cm_window);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/** Redirect all the windows to the off-screen buffer starting from
|
| 267 |
+
* the root window and change root window attributes to make the
|
| 268 |
+
* server reporting meaningful events
|
| 269 |
+
*/
|
| 270 |
+
void
|
| 271 |
+
display_init_redirect(void)
|
| 272 |
+
{
|
| 273 |
+
/* Manage all children windows from the root window */
|
| 274 |
+
_query_tree_cookie = xcb_query_tree_unchecked(globalconf.connection,
|
| 275 |
+
globalconf.screen->root);
|
| 276 |
+
|
| 277 |
+
xcb_composite_redirect_subwindows(globalconf.connection,
|
| 278 |
+
globalconf.screen->root,
|
| 279 |
+
XCB_COMPOSITE_REDIRECT_MANUAL);
|
| 280 |
+
|
| 281 |
+
/* Declare interest in meaningful events */
|
| 282 |
+
const uint32_t select_input_val =
|
| 283 |
+
XCB_EVENT_MASK_KEY_PRESS |
|
| 284 |
+
XCB_EVENT_MASK_KEY_RELEASE |
|
| 285 |
+
XCB_EVENT_MASK_BUTTON_RELEASE |
|
| 286 |
+
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
|
| 287 |
+
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
|
| 288 |
+
XCB_EVENT_MASK_PROPERTY_CHANGE;
|
| 289 |
+
|
| 290 |
+
xcb_change_window_attributes(globalconf.connection, globalconf.screen->root,
|
| 291 |
+
XCB_CW_EVENT_MASK, &select_input_val);
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/** Finish redirection by adding all the existing windows in the
|
| 295 |
+
* hierarchy
|
| 296 |
+
*/
|
| 297 |
+
void
|
| 298 |
+
display_init_redirect_finalise(void)
|
| 299 |
+
{
|
| 300 |
+
assert(_query_tree_cookie.sequence);
|
| 301 |
+
|
| 302 |
+
/* Get all the windows below the root window */
|
| 303 |
+
xcb_query_tree_reply_t *query_tree_reply =
|
| 304 |
+
xcb_query_tree_reply(globalconf.connection,
|
| 305 |
+
_query_tree_cookie,
|
| 306 |
+
NULL);
|
| 307 |
+
|
| 308 |
+
/* Add all these windows excluding the root window of course */
|
| 309 |
+
const int nwindows = xcb_query_tree_children_length(query_tree_reply);
|
| 310 |
+
if(nwindows)
|
| 311 |
+
window_manage_existing(nwindows,
|
| 312 |
+
xcb_query_tree_children(query_tree_reply));
|
| 313 |
+
|
| 314 |
+
free(query_tree_reply);
|
| 315 |
+
}
|
pool/shard000/C/0008502_gnutls_global.c
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2001-2012 Free Software Foundation, Inc.
|
| 3 |
+
*
|
| 4 |
+
* Author: Nikos Mavrogiannopoulos
|
| 5 |
+
*
|
| 6 |
+
* This file is part of GnuTLS.
|
| 7 |
+
*
|
| 8 |
+
* The GnuTLS is free software; you can redistribute it and/or
|
| 9 |
+
* modify it under the terms of the GNU Lesser General Public License
|
| 10 |
+
* as published by the Free Software Foundation; either version 2.1 of
|
| 11 |
+
* the License, or (at your option) any later version.
|
| 12 |
+
*
|
| 13 |
+
* This library is distributed in the hope that it will be useful, but
|
| 14 |
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
* Lesser General Public License for more details.
|
| 17 |
+
*
|
| 18 |
+
* You should have received a copy of the GNU Lesser General Public License
|
| 19 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
+
*
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
#include <gnutls_int.h>
|
| 24 |
+
#include <gnutls_errors.h>
|
| 25 |
+
#include <libtasn1.h>
|
| 26 |
+
#include <gnutls_dh.h>
|
| 27 |
+
#include <random.h>
|
| 28 |
+
#include <gnutls/pkcs11.h>
|
| 29 |
+
|
| 30 |
+
#include <gnutls_extensions.h> /* for _gnutls_ext_init */
|
| 31 |
+
#include <locks.h>
|
| 32 |
+
#include <system.h>
|
| 33 |
+
#include <accelerated/cryptodev.h>
|
| 34 |
+
#include <accelerated/accelerated.h>
|
| 35 |
+
|
| 36 |
+
#include "sockets.h"
|
| 37 |
+
#include "gettext.h"
|
| 38 |
+
|
| 39 |
+
/* Minimum library versions we accept. */
|
| 40 |
+
#define GNUTLS_MIN_LIBTASN1_VERSION "0.3.4"
|
| 41 |
+
|
| 42 |
+
/* created by asn1c */
|
| 43 |
+
extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[];
|
| 44 |
+
extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
|
| 45 |
+
void *_gnutls_file_mutex;
|
| 46 |
+
|
| 47 |
+
ASN1_TYPE _gnutls_pkix1_asn;
|
| 48 |
+
ASN1_TYPE _gnutls_gnutls_asn;
|
| 49 |
+
|
| 50 |
+
gnutls_log_func _gnutls_log_func = NULL;
|
| 51 |
+
gnutls_audit_log_func _gnutls_audit_log_func = NULL;
|
| 52 |
+
int _gnutls_log_level = 0; /* default log level */
|
| 53 |
+
|
| 54 |
+
static void default_log_func(int level, const char* str)
|
| 55 |
+
{
|
| 56 |
+
fprintf(stderr, "gnutls[%d]: %s\n", level, str);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* gnutls_global_set_log_function:
|
| 61 |
+
* @log_func: it's a log function
|
| 62 |
+
*
|
| 63 |
+
* This is the function where you set the logging function gnutls is
|
| 64 |
+
* going to use. This function only accepts a character array.
|
| 65 |
+
* Normally you may not use this function since it is only used for
|
| 66 |
+
* debugging purposes.
|
| 67 |
+
*
|
| 68 |
+
* @gnutls_log_func is of the form,
|
| 69 |
+
* void (*gnutls_log_func)( int level, const char*);
|
| 70 |
+
**/
|
| 71 |
+
void gnutls_global_set_log_function(gnutls_log_func log_func)
|
| 72 |
+
{
|
| 73 |
+
_gnutls_log_func = log_func;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* gnutls_global_set_audit_log_function:
|
| 78 |
+
* @log_func: it is the audit log function
|
| 79 |
+
*
|
| 80 |
+
* This is the function to set the audit logging function. This
|
| 81 |
+
* is a function to report important issues, such as possible
|
| 82 |
+
* attacks in the protocol. This is different from gnutls_global_set_log_function()
|
| 83 |
+
* because it will report also session-specific events. The session
|
| 84 |
+
* parameter will be null if there is no corresponding TLS session.
|
| 85 |
+
*
|
| 86 |
+
* @gnutls_audit_log_func is of the form,
|
| 87 |
+
* void (*gnutls_audit_log_func)( gnutls_session_t, const char*);
|
| 88 |
+
*
|
| 89 |
+
* Since: 3.0
|
| 90 |
+
**/
|
| 91 |
+
void gnutls_global_set_audit_log_function(gnutls_audit_log_func log_func)
|
| 92 |
+
{
|
| 93 |
+
_gnutls_audit_log_func = log_func;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* gnutls_global_set_time_function:
|
| 98 |
+
* @time_func: it's the system time function, a gnutls_time_func() callback.
|
| 99 |
+
*
|
| 100 |
+
* This is the function where you can override the default system time
|
| 101 |
+
* function. The application provided function should behave the same
|
| 102 |
+
* as the standard function.
|
| 103 |
+
*
|
| 104 |
+
* Since: 2.12.0
|
| 105 |
+
**/
|
| 106 |
+
void gnutls_global_set_time_function(gnutls_time_func time_func)
|
| 107 |
+
{
|
| 108 |
+
gnutls_time = time_func;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* gnutls_global_set_log_level:
|
| 113 |
+
* @level: it's an integer from 0 to 9.
|
| 114 |
+
*
|
| 115 |
+
* This is the function that allows you to set the log level. The
|
| 116 |
+
* level is an integer between 0 and 9. Higher values mean more
|
| 117 |
+
* verbosity. The default value is 0. Larger values should only be
|
| 118 |
+
* used with care, since they may reveal sensitive information.
|
| 119 |
+
*
|
| 120 |
+
* Use a log level over 10 to enable all debugging options.
|
| 121 |
+
**/
|
| 122 |
+
void gnutls_global_set_log_level(int level)
|
| 123 |
+
{
|
| 124 |
+
_gnutls_log_level = level;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* gnutls_global_set_mem_functions:
|
| 129 |
+
* @alloc_func: it's the default memory allocation function. Like malloc().
|
| 130 |
+
* @secure_alloc_func: This is the memory allocation function that will be used for sensitive data.
|
| 131 |
+
* @is_secure_func: a function that returns 0 if the memory given is not secure. May be NULL.
|
| 132 |
+
* @realloc_func: A realloc function
|
| 133 |
+
* @free_func: The function that frees allocated data. Must accept a NULL pointer.
|
| 134 |
+
*
|
| 135 |
+
* This is the function where you set the memory allocation functions
|
| 136 |
+
* gnutls is going to use. By default the libc's allocation functions
|
| 137 |
+
* (malloc(), free()), are used by gnutls, to allocate both sensitive
|
| 138 |
+
* and not sensitive data. This function is provided to set the
|
| 139 |
+
* memory allocation functions to something other than the defaults
|
| 140 |
+
*
|
| 141 |
+
* This function must be called before gnutls_global_init() is called.
|
| 142 |
+
* This function is not thread safe.
|
| 143 |
+
**/
|
| 144 |
+
void
|
| 145 |
+
gnutls_global_set_mem_functions(gnutls_alloc_function alloc_func,
|
| 146 |
+
gnutls_alloc_function secure_alloc_func,
|
| 147 |
+
gnutls_is_secure_function is_secure_func,
|
| 148 |
+
gnutls_realloc_function realloc_func,
|
| 149 |
+
gnutls_free_function free_func)
|
| 150 |
+
{
|
| 151 |
+
gnutls_secure_malloc = secure_alloc_func;
|
| 152 |
+
gnutls_malloc = alloc_func;
|
| 153 |
+
gnutls_realloc = realloc_func;
|
| 154 |
+
gnutls_free = free_func;
|
| 155 |
+
|
| 156 |
+
/* if using the libc's default malloc
|
| 157 |
+
* use libc's calloc as well.
|
| 158 |
+
*/
|
| 159 |
+
if (gnutls_malloc == malloc) {
|
| 160 |
+
gnutls_calloc = calloc;
|
| 161 |
+
} else { /* use the included ones */
|
| 162 |
+
gnutls_calloc = _gnutls_calloc;
|
| 163 |
+
}
|
| 164 |
+
gnutls_strdup = _gnutls_strdup;
|
| 165 |
+
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
static int _gnutls_init = 0;
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* gnutls_global_init:
|
| 172 |
+
*
|
| 173 |
+
* This function performs any required precalculations, detects
|
| 174 |
+
* the supported CPU capabilities and initializes the underlying
|
| 175 |
+
* cryptographic backend. In order to free any resources
|
| 176 |
+
* taken by this call you should gnutls_global_deinit()
|
| 177 |
+
* when gnutls usage is no longer needed.
|
| 178 |
+
*
|
| 179 |
+
* This function increments a global counter, so that
|
| 180 |
+
* gnutls_global_deinit() only releases resources when it has been
|
| 181 |
+
* called as many times as gnutls_global_init(). This is useful when
|
| 182 |
+
* GnuTLS is used by more than one library in an application. This
|
| 183 |
+
* function can be called many times, but will only do something the
|
| 184 |
+
* first time.
|
| 185 |
+
*
|
| 186 |
+
* Note! This function is not thread safe. If two threads call this
|
| 187 |
+
* function simultaneously, they can cause a race between checking
|
| 188 |
+
* the global counter and incrementing it, causing both threads to
|
| 189 |
+
* execute the library initialization code. That could lead to a
|
| 190 |
+
* memory leak or even a crash. To handle this, your application should
|
| 191 |
+
* invoke this function after aquiring a thread mutex.
|
| 192 |
+
*
|
| 193 |
+
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
|
| 194 |
+
* otherwise a negative error code is returned.
|
| 195 |
+
**/
|
| 196 |
+
int gnutls_global_init(void)
|
| 197 |
+
{
|
| 198 |
+
int result = 0;
|
| 199 |
+
int res, level;
|
| 200 |
+
const char* e;
|
| 201 |
+
|
| 202 |
+
if (_gnutls_init++)
|
| 203 |
+
goto out;
|
| 204 |
+
|
| 205 |
+
e = getenv("GNUTLS_DEBUG_LEVEL");
|
| 206 |
+
if (e != NULL) {
|
| 207 |
+
level = atoi(e);
|
| 208 |
+
gnutls_global_set_log_level(level);
|
| 209 |
+
if (_gnutls_log_func == NULL)
|
| 210 |
+
gnutls_global_set_log_function(default_log_func);
|
| 211 |
+
_gnutls_debug_log("Enabled GnuTLS logging...\n");
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
if (gl_sockets_startup(SOCKETS_1_1))
|
| 215 |
+
return gnutls_assert_val(GNUTLS_E_FILE_ERROR);
|
| 216 |
+
|
| 217 |
+
bindtextdomain(PACKAGE, LOCALEDIR);
|
| 218 |
+
|
| 219 |
+
res = gnutls_crypto_init();
|
| 220 |
+
if (res != 0) {
|
| 221 |
+
gnutls_assert();
|
| 222 |
+
return GNUTLS_E_CRYPTO_INIT_FAILED;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
_gnutls_register_accel_crypto();
|
| 226 |
+
|
| 227 |
+
/* initialize ASN.1 parser
|
| 228 |
+
* This should not deal with files in the final
|
| 229 |
+
* version.
|
| 230 |
+
*/
|
| 231 |
+
if (asn1_check_version(GNUTLS_MIN_LIBTASN1_VERSION) == NULL) {
|
| 232 |
+
gnutls_assert();
|
| 233 |
+
_gnutls_debug_log
|
| 234 |
+
("Checking for libtasn1 failed: %s < %s\n",
|
| 235 |
+
asn1_check_version(NULL),
|
| 236 |
+
GNUTLS_MIN_LIBTASN1_VERSION);
|
| 237 |
+
return GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
res = asn1_array2tree(pkix_asn1_tab, &_gnutls_pkix1_asn, NULL);
|
| 241 |
+
if (res != ASN1_SUCCESS) {
|
| 242 |
+
result = _gnutls_asn2err(res);
|
| 243 |
+
goto out;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
res = asn1_array2tree(gnutls_asn1_tab, &_gnutls_gnutls_asn, NULL);
|
| 247 |
+
if (res != ASN1_SUCCESS) {
|
| 248 |
+
result = _gnutls_asn2err(res);
|
| 249 |
+
goto out;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/* Initialize the random generator */
|
| 253 |
+
result = _gnutls_rnd_init();
|
| 254 |
+
if (result < 0) {
|
| 255 |
+
gnutls_assert();
|
| 256 |
+
goto out;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/* Initialize the default TLS extensions */
|
| 260 |
+
result = _gnutls_ext_init();
|
| 261 |
+
if (result < 0) {
|
| 262 |
+
gnutls_assert();
|
| 263 |
+
goto out;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
result = gnutls_mutex_init(&_gnutls_file_mutex);
|
| 267 |
+
if (result < 0) {
|
| 268 |
+
gnutls_assert();
|
| 269 |
+
goto out;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
result = gnutls_system_global_init();
|
| 273 |
+
if (result < 0) {
|
| 274 |
+
gnutls_assert();
|
| 275 |
+
goto out;
|
| 276 |
+
}
|
| 277 |
+
#ifdef ENABLE_PKCS11
|
| 278 |
+
gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_AUTO, NULL);
|
| 279 |
+
#endif
|
| 280 |
+
|
| 281 |
+
_gnutls_cryptodev_init();
|
| 282 |
+
|
| 283 |
+
out:
|
| 284 |
+
return result;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* gnutls_global_deinit:
|
| 289 |
+
*
|
| 290 |
+
* This function deinitializes the global data, that were initialized
|
| 291 |
+
* using gnutls_global_init().
|
| 292 |
+
*
|
| 293 |
+
* Note! This function is not thread safe. See the discussion for
|
| 294 |
+
* gnutls_global_init() for more information.
|
| 295 |
+
**/
|
| 296 |
+
void gnutls_global_deinit(void)
|
| 297 |
+
{
|
| 298 |
+
if (_gnutls_init == 1) {
|
| 299 |
+
gl_sockets_cleanup();
|
| 300 |
+
gnutls_crypto_deinit();
|
| 301 |
+
_gnutls_rnd_deinit();
|
| 302 |
+
_gnutls_ext_deinit();
|
| 303 |
+
asn1_delete_structure(&_gnutls_gnutls_asn);
|
| 304 |
+
asn1_delete_structure(&_gnutls_pkix1_asn);
|
| 305 |
+
_gnutls_crypto_deregister();
|
| 306 |
+
_gnutls_cryptodev_deinit();
|
| 307 |
+
gnutls_system_global_deinit();
|
| 308 |
+
#ifdef ENABLE_PKCS11
|
| 309 |
+
gnutls_pkcs11_deinit();
|
| 310 |
+
#endif
|
| 311 |
+
gnutls_mutex_deinit(&_gnutls_file_mutex);
|
| 312 |
+
}
|
| 313 |
+
_gnutls_init--;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/* These functions should be elsewere. Kept here for
|
| 317 |
+
* historical reasons.
|
| 318 |
+
*/
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
/**
|
| 322 |
+
* gnutls_check_version:
|
| 323 |
+
* @req_version: version string to compare with, or %NULL.
|
| 324 |
+
*
|
| 325 |
+
* Check GnuTLS Library version.
|
| 326 |
+
*
|
| 327 |
+
* See %GNUTLS_VERSION for a suitable @req_version string.
|
| 328 |
+
*
|
| 329 |
+
* Returns: Check that the version of the library is at
|
| 330 |
+
* minimum the one given as a string in @req_version and return the
|
| 331 |
+
* actual version string of the library; return %NULL if the
|
| 332 |
+
* condition is not met. If %NULL is passed to this function no
|
| 333 |
+
* check is done and only the version string is returned.
|
| 334 |
+
**/
|
| 335 |
+
const char *gnutls_check_version(const char *req_version)
|
| 336 |
+
{
|
| 337 |
+
if (!req_version || strverscmp(req_version, VERSION) <= 0)
|
| 338 |
+
return VERSION;
|
| 339 |
+
|
| 340 |
+
return NULL;
|
| 341 |
+
}
|
pool/shard000/C/0008506_avic.c
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
| 2 |
+
/*
|
| 3 |
+
* Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
|
| 4 |
+
* Copyright 2008 Juergen Beisert, kernel@pengutronix.de
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
#include <linux/module.h>
|
| 8 |
+
#include <linux/irq.h>
|
| 9 |
+
#include <linux/irqdomain.h>
|
| 10 |
+
#include <linux/io.h>
|
| 11 |
+
#include <linux/of.h>
|
| 12 |
+
#include <linux/of_address.h>
|
| 13 |
+
#include <asm/mach/irq.h>
|
| 14 |
+
#include <asm/exception.h>
|
| 15 |
+
|
| 16 |
+
#include "common.h"
|
| 17 |
+
#include "hardware.h"
|
| 18 |
+
#include "irq-common.h"
|
| 19 |
+
|
| 20 |
+
#define AVIC_INTCNTL 0x00 /* int control reg */
|
| 21 |
+
#define AVIC_NIMASK 0x04 /* int mask reg */
|
| 22 |
+
#define AVIC_INTENNUM 0x08 /* int enable number reg */
|
| 23 |
+
#define AVIC_INTDISNUM 0x0C /* int disable number reg */
|
| 24 |
+
#define AVIC_INTENABLEH 0x10 /* int enable reg high */
|
| 25 |
+
#define AVIC_INTENABLEL 0x14 /* int enable reg low */
|
| 26 |
+
#define AVIC_INTTYPEH 0x18 /* int type reg high */
|
| 27 |
+
#define AVIC_INTTYPEL 0x1C /* int type reg low */
|
| 28 |
+
#define AVIC_NIPRIORITY(x) (0x20 + 4 * (7 - (x))) /* int priority */
|
| 29 |
+
#define AVIC_NIVECSR 0x40 /* norm int vector/status */
|
| 30 |
+
#define AVIC_FIVECSR 0x44 /* fast int vector/status */
|
| 31 |
+
#define AVIC_INTSRCH 0x48 /* int source reg high */
|
| 32 |
+
#define AVIC_INTSRCL 0x4C /* int source reg low */
|
| 33 |
+
#define AVIC_INTFRCH 0x50 /* int force reg high */
|
| 34 |
+
#define AVIC_INTFRCL 0x54 /* int force reg low */
|
| 35 |
+
#define AVIC_NIPNDH 0x58 /* norm int pending high */
|
| 36 |
+
#define AVIC_NIPNDL 0x5C /* norm int pending low */
|
| 37 |
+
#define AVIC_FIPNDH 0x60 /* fast int pending high */
|
| 38 |
+
#define AVIC_FIPNDL 0x64 /* fast int pending low */
|
| 39 |
+
|
| 40 |
+
#define AVIC_NUM_IRQS 64
|
| 41 |
+
|
| 42 |
+
/* low power interrupt mask registers */
|
| 43 |
+
#define MX25_CCM_LPIMR0 0x68
|
| 44 |
+
#define MX25_CCM_LPIMR1 0x6C
|
| 45 |
+
|
| 46 |
+
static void __iomem *avic_base;
|
| 47 |
+
static void __iomem *mx25_ccm_base;
|
| 48 |
+
static struct irq_domain *domain;
|
| 49 |
+
|
| 50 |
+
#ifdef CONFIG_FIQ
|
| 51 |
+
static int avic_set_irq_fiq(unsigned int hwirq, unsigned int type)
|
| 52 |
+
{
|
| 53 |
+
unsigned int irqt;
|
| 54 |
+
|
| 55 |
+
if (hwirq >= AVIC_NUM_IRQS)
|
| 56 |
+
return -EINVAL;
|
| 57 |
+
|
| 58 |
+
if (hwirq < AVIC_NUM_IRQS / 2) {
|
| 59 |
+
irqt = imx_readl(avic_base + AVIC_INTTYPEL) & ~(1 << hwirq);
|
| 60 |
+
imx_writel(irqt | (!!type << hwirq), avic_base + AVIC_INTTYPEL);
|
| 61 |
+
} else {
|
| 62 |
+
hwirq -= AVIC_NUM_IRQS / 2;
|
| 63 |
+
irqt = imx_readl(avic_base + AVIC_INTTYPEH) & ~(1 << hwirq);
|
| 64 |
+
imx_writel(irqt | (!!type << hwirq), avic_base + AVIC_INTTYPEH);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return 0;
|
| 68 |
+
}
|
| 69 |
+
#endif /* CONFIG_FIQ */
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
static struct mxc_extra_irq avic_extra_irq = {
|
| 73 |
+
#ifdef CONFIG_FIQ
|
| 74 |
+
.set_irq_fiq = avic_set_irq_fiq,
|
| 75 |
+
#endif
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
#ifdef CONFIG_PM
|
| 79 |
+
static u32 avic_saved_mask_reg[2];
|
| 80 |
+
|
| 81 |
+
static void avic_irq_suspend(struct irq_data *d)
|
| 82 |
+
{
|
| 83 |
+
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
| 84 |
+
struct irq_chip_type *ct = gc->chip_types;
|
| 85 |
+
int idx = d->hwirq >> 5;
|
| 86 |
+
|
| 87 |
+
avic_saved_mask_reg[idx] = imx_readl(avic_base + ct->regs.mask);
|
| 88 |
+
imx_writel(gc->wake_active, avic_base + ct->regs.mask);
|
| 89 |
+
|
| 90 |
+
if (mx25_ccm_base) {
|
| 91 |
+
u8 offs = d->hwirq < AVIC_NUM_IRQS / 2 ?
|
| 92 |
+
MX25_CCM_LPIMR0 : MX25_CCM_LPIMR1;
|
| 93 |
+
/*
|
| 94 |
+
* The interrupts which are still enabled will be used as wakeup
|
| 95 |
+
* sources. Allow those interrupts in low-power mode.
|
| 96 |
+
* The LPIMR registers use 0 to allow an interrupt, the AVIC
|
| 97 |
+
* registers use 1.
|
| 98 |
+
*/
|
| 99 |
+
imx_writel(~gc->wake_active, mx25_ccm_base + offs);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
static void avic_irq_resume(struct irq_data *d)
|
| 104 |
+
{
|
| 105 |
+
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
| 106 |
+
struct irq_chip_type *ct = gc->chip_types;
|
| 107 |
+
int idx = d->hwirq >> 5;
|
| 108 |
+
|
| 109 |
+
imx_writel(avic_saved_mask_reg[idx], avic_base + ct->regs.mask);
|
| 110 |
+
|
| 111 |
+
if (mx25_ccm_base) {
|
| 112 |
+
u8 offs = d->hwirq < AVIC_NUM_IRQS / 2 ?
|
| 113 |
+
MX25_CCM_LPIMR0 : MX25_CCM_LPIMR1;
|
| 114 |
+
|
| 115 |
+
imx_writel(0xffffffff, mx25_ccm_base + offs);
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#else
|
| 120 |
+
#define avic_irq_suspend NULL
|
| 121 |
+
#define avic_irq_resume NULL
|
| 122 |
+
#endif
|
| 123 |
+
|
| 124 |
+
static __init void avic_init_gc(int idx, unsigned int irq_start)
|
| 125 |
+
{
|
| 126 |
+
struct irq_chip_generic *gc;
|
| 127 |
+
struct irq_chip_type *ct;
|
| 128 |
+
|
| 129 |
+
gc = irq_alloc_generic_chip("mxc-avic", 1, irq_start, avic_base,
|
| 130 |
+
handle_level_irq);
|
| 131 |
+
gc->private = &avic_extra_irq;
|
| 132 |
+
gc->wake_enabled = IRQ_MSK(32);
|
| 133 |
+
|
| 134 |
+
ct = gc->chip_types;
|
| 135 |
+
ct->chip.irq_mask = irq_gc_mask_clr_bit;
|
| 136 |
+
ct->chip.irq_unmask = irq_gc_mask_set_bit;
|
| 137 |
+
ct->chip.irq_ack = irq_gc_mask_clr_bit;
|
| 138 |
+
ct->chip.irq_set_wake = irq_gc_set_wake;
|
| 139 |
+
ct->chip.irq_suspend = avic_irq_suspend;
|
| 140 |
+
ct->chip.irq_resume = avic_irq_resume;
|
| 141 |
+
ct->regs.mask = !idx ? AVIC_INTENABLEL : AVIC_INTENABLEH;
|
| 142 |
+
ct->regs.ack = ct->regs.mask;
|
| 143 |
+
|
| 144 |
+
irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
static void __exception_irq_entry avic_handle_irq(struct pt_regs *regs)
|
| 148 |
+
{
|
| 149 |
+
u32 nivector;
|
| 150 |
+
|
| 151 |
+
do {
|
| 152 |
+
nivector = imx_readl(avic_base + AVIC_NIVECSR) >> 16;
|
| 153 |
+
if (nivector == 0xffff)
|
| 154 |
+
break;
|
| 155 |
+
|
| 156 |
+
handle_domain_irq(domain, nivector, regs);
|
| 157 |
+
} while (1);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/*
|
| 161 |
+
* This function initializes the AVIC hardware and disables all the
|
| 162 |
+
* interrupts. It registers the interrupt enable and disable functions
|
| 163 |
+
* to the kernel for each interrupt source.
|
| 164 |
+
*/
|
| 165 |
+
void __init mxc_init_irq(void __iomem *irqbase)
|
| 166 |
+
{
|
| 167 |
+
struct device_node *np;
|
| 168 |
+
int irq_base;
|
| 169 |
+
int i;
|
| 170 |
+
|
| 171 |
+
avic_base = irqbase;
|
| 172 |
+
|
| 173 |
+
np = of_find_compatible_node(NULL, NULL, "fsl,imx25-ccm");
|
| 174 |
+
mx25_ccm_base = of_iomap(np, 0);
|
| 175 |
+
|
| 176 |
+
if (mx25_ccm_base) {
|
| 177 |
+
/*
|
| 178 |
+
* By default, we mask all interrupts. We set the actual mask
|
| 179 |
+
* before we go into low-power mode.
|
| 180 |
+
*/
|
| 181 |
+
imx_writel(0xffffffff, mx25_ccm_base + MX25_CCM_LPIMR0);
|
| 182 |
+
imx_writel(0xffffffff, mx25_ccm_base + MX25_CCM_LPIMR1);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/* put the AVIC into the reset value with
|
| 186 |
+
* all interrupts disabled
|
| 187 |
+
*/
|
| 188 |
+
imx_writel(0, avic_base + AVIC_INTCNTL);
|
| 189 |
+
imx_writel(0x1f, avic_base + AVIC_NIMASK);
|
| 190 |
+
|
| 191 |
+
/* disable all interrupts */
|
| 192 |
+
imx_writel(0, avic_base + AVIC_INTENABLEH);
|
| 193 |
+
imx_writel(0, avic_base + AVIC_INTENABLEL);
|
| 194 |
+
|
| 195 |
+
/* all IRQ no FIQ */
|
| 196 |
+
imx_writel(0, avic_base + AVIC_INTTYPEH);
|
| 197 |
+
imx_writel(0, avic_base + AVIC_INTTYPEL);
|
| 198 |
+
|
| 199 |
+
irq_base = irq_alloc_descs(-1, 0, AVIC_NUM_IRQS, numa_node_id());
|
| 200 |
+
WARN_ON(irq_base < 0);
|
| 201 |
+
|
| 202 |
+
np = of_find_compatible_node(NULL, NULL, "fsl,avic");
|
| 203 |
+
domain = irq_domain_add_legacy(np, AVIC_NUM_IRQS, irq_base, 0,
|
| 204 |
+
&irq_domain_simple_ops, NULL);
|
| 205 |
+
WARN_ON(!domain);
|
| 206 |
+
|
| 207 |
+
for (i = 0; i < AVIC_NUM_IRQS / 32; i++, irq_base += 32)
|
| 208 |
+
avic_init_gc(i, irq_base);
|
| 209 |
+
|
| 210 |
+
/* Set default priority value (0) for all IRQ's */
|
| 211 |
+
for (i = 0; i < 8; i++)
|
| 212 |
+
imx_writel(0, avic_base + AVIC_NIPRIORITY(i));
|
| 213 |
+
|
| 214 |
+
set_handle_irq(avic_handle_irq);
|
| 215 |
+
|
| 216 |
+
#ifdef CONFIG_FIQ
|
| 217 |
+
/* Initialize FIQ */
|
| 218 |
+
init_FIQ(FIQ_START);
|
| 219 |
+
#endif
|
| 220 |
+
|
| 221 |
+
printk(KERN_INFO "MXC IRQ initialized\n");
|
| 222 |
+
}
|
pool/shard000/C/0008520_abspath.c
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */
|
| 2 |
+
|
| 3 |
+
#include "lib.h"
|
| 4 |
+
#include "str.h"
|
| 5 |
+
#include "abspath.h"
|
| 6 |
+
|
| 7 |
+
#include <stdlib.h>
|
| 8 |
+
#include <unistd.h>
|
| 9 |
+
|
| 10 |
+
const char *t_abspath(const char *path)
|
| 11 |
+
{
|
| 12 |
+
const char *dir;
|
| 13 |
+
|
| 14 |
+
if (*path == '/')
|
| 15 |
+
return path;
|
| 16 |
+
|
| 17 |
+
if (t_get_current_dir(&dir) < 0)
|
| 18 |
+
i_fatal("getcwd() failed: %m");
|
| 19 |
+
return t_strconcat(dir, "/", path, NULL);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const char *t_abspath_to(const char *path, const char *root)
|
| 23 |
+
{
|
| 24 |
+
if (*path == '/')
|
| 25 |
+
return path;
|
| 26 |
+
|
| 27 |
+
return t_strconcat(root, "/", path, NULL);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
int t_get_current_dir(const char **dir_r)
|
| 31 |
+
{
|
| 32 |
+
/* @UNSAFE */
|
| 33 |
+
char *dir;
|
| 34 |
+
size_t size = 128;
|
| 35 |
+
|
| 36 |
+
dir = t_buffer_get(size);
|
| 37 |
+
while (getcwd(dir, size) == NULL) {
|
| 38 |
+
if (errno != ERANGE)
|
| 39 |
+
return -1;
|
| 40 |
+
size = nearest_power(size+1);
|
| 41 |
+
dir = t_buffer_get(size);
|
| 42 |
+
}
|
| 43 |
+
t_buffer_alloc(strlen(dir) + 1);
|
| 44 |
+
*dir_r = dir;
|
| 45 |
+
return 0;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
int t_readlink(const char *path, const char **dest_r)
|
| 49 |
+
{
|
| 50 |
+
/* @UNSAFE */
|
| 51 |
+
ssize_t ret;
|
| 52 |
+
char *dest;
|
| 53 |
+
size_t size = 128;
|
| 54 |
+
|
| 55 |
+
dest = t_buffer_get(size);
|
| 56 |
+
while ((ret = readlink(path, dest, size)) >= (ssize_t)size) {
|
| 57 |
+
size = nearest_power(size+1);
|
| 58 |
+
dest = t_buffer_get(size);
|
| 59 |
+
}
|
| 60 |
+
if (ret < 0)
|
| 61 |
+
return -1;
|
| 62 |
+
|
| 63 |
+
dest[ret] = '\0';
|
| 64 |
+
t_buffer_alloc(ret + 1);
|
| 65 |
+
*dest_r = dest;
|
| 66 |
+
return 0;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
bool t_binary_abspath(const char **binpath)
|
| 70 |
+
{
|
| 71 |
+
const char *path_env, *const *paths;
|
| 72 |
+
string_t *path;
|
| 73 |
+
|
| 74 |
+
if (**binpath == '/') {
|
| 75 |
+
/* already have absolute path */
|
| 76 |
+
return TRUE;
|
| 77 |
+
} else if (strchr(*binpath, '/') != NULL) {
|
| 78 |
+
/* relative to current directory */
|
| 79 |
+
*binpath = t_abspath(*binpath);
|
| 80 |
+
return TRUE;
|
| 81 |
+
} else if ((path_env = getenv("PATH")) != NULL) {
|
| 82 |
+
/* we have to find our executable from path */
|
| 83 |
+
path = t_str_new(256);
|
| 84 |
+
paths = t_strsplit(path_env, ":");
|
| 85 |
+
for (; *paths != NULL; paths++) {
|
| 86 |
+
str_append(path, *paths);
|
| 87 |
+
str_append_c(path, '/');
|
| 88 |
+
str_append(path, *binpath);
|
| 89 |
+
if (access(str_c(path), X_OK) == 0) {
|
| 90 |
+
*binpath = str_c(path);
|
| 91 |
+
return TRUE;
|
| 92 |
+
}
|
| 93 |
+
str_truncate(path, 0);
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
return FALSE;
|
| 97 |
+
}
|
pool/shard000/C/0008521_msm7kv2-dai.c
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
#include <linux/init.h>
|
| 4 |
+
#include <linux/module.h>
|
| 5 |
+
#include <linux/device.h>
|
| 6 |
+
#include <linux/delay.h>
|
| 7 |
+
#include <linux/clk.h>
|
| 8 |
+
#include <linux/platform_device.h>
|
| 9 |
+
#include <sound/core.h>
|
| 10 |
+
#include <sound/pcm.h>
|
| 11 |
+
#include <sound/initval.h>
|
| 12 |
+
#include <sound/soc.h>
|
| 13 |
+
#include "msm7kv2-pcm.h"
|
| 14 |
+
|
| 15 |
+
struct snd_soc_dai msm_dais[] = {
|
| 16 |
+
{
|
| 17 |
+
.name = "CODEC_DAI",
|
| 18 |
+
.playback = {
|
| 19 |
+
.stream_name = "Playback",
|
| 20 |
+
.channels_min = USE_CHANNELS_MIN,
|
| 21 |
+
.channels_max = USE_CHANNELS_MAX,
|
| 22 |
+
.rates = USE_RATE,
|
| 23 |
+
.rate_min = USE_RATE_MIN,
|
| 24 |
+
.rate_max = USE_RATE_MAX,
|
| 25 |
+
.formats = USE_FORMATS,
|
| 26 |
+
},
|
| 27 |
+
.capture = {
|
| 28 |
+
.stream_name = "Capture",
|
| 29 |
+
.channels_min = USE_CHANNELS_MIN,
|
| 30 |
+
.channels_max = USE_CHANNELS_MAX,
|
| 31 |
+
.rate_min = USE_RATE_MIN,
|
| 32 |
+
.rates = USE_RATE,
|
| 33 |
+
.formats = USE_FORMATS,
|
| 34 |
+
},
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
.name = "CPU_DAI",
|
| 38 |
+
.id = 0,
|
| 39 |
+
.playback = {
|
| 40 |
+
.channels_min = USE_CHANNELS_MIN,
|
| 41 |
+
.channels_max = USE_CHANNELS_MAX,
|
| 42 |
+
.rates = USE_RATE,
|
| 43 |
+
.rate_min = USE_RATE_MIN,
|
| 44 |
+
.rate_max = USE_RATE_MAX,
|
| 45 |
+
.formats = USE_FORMATS,
|
| 46 |
+
},
|
| 47 |
+
.capture = {
|
| 48 |
+
.channels_min = USE_CHANNELS_MIN,
|
| 49 |
+
.channels_max = USE_CHANNELS_MAX,
|
| 50 |
+
.rate_min = USE_RATE_MIN,
|
| 51 |
+
.rates = USE_RATE,
|
| 52 |
+
.formats = USE_FORMATS,
|
| 53 |
+
},
|
| 54 |
+
},
|
| 55 |
+
};
|
| 56 |
+
EXPORT_SYMBOL_GPL(msm_dais);
|
| 57 |
+
|
| 58 |
+
int msm_pcm_probe(struct platform_device *devptr)
|
| 59 |
+
{
|
| 60 |
+
struct snd_soc_codec *codec;
|
| 61 |
+
int ret;
|
| 62 |
+
|
| 63 |
+
struct snd_soc_device *socdev = platform_get_drvdata(devptr);
|
| 64 |
+
|
| 65 |
+
printk(KERN_ERR "msm_soc: create pcms\n");
|
| 66 |
+
codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
|
| 67 |
+
if (codec == NULL)
|
| 68 |
+
return -ENOMEM;
|
| 69 |
+
|
| 70 |
+
codec->name = "MSM-CARD";
|
| 71 |
+
codec->owner = THIS_MODULE;
|
| 72 |
+
socdev->card->codec = codec;
|
| 73 |
+
mutex_init(&codec->mutex);
|
| 74 |
+
|
| 75 |
+
INIT_LIST_HEAD(&codec->dapm_widgets);
|
| 76 |
+
INIT_LIST_HEAD(&codec->dapm_paths);
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
|
| 80 |
+
if (ret < 0) {
|
| 81 |
+
printk(KERN_ERR "msm_soc: failed to create pcms\n");
|
| 82 |
+
goto __nopcm;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
ret = snd_soc_init_card(socdev);
|
| 86 |
+
if (ret < 0) {
|
| 87 |
+
printk(KERN_ERR "msm_soc: failed to register card\n");
|
| 88 |
+
goto __nodev;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return 0;
|
| 92 |
+
|
| 93 |
+
__nodev:
|
| 94 |
+
snd_soc_free_pcms(socdev);
|
| 95 |
+
__nopcm:
|
| 96 |
+
kfree(codec);
|
| 97 |
+
return ret;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
struct snd_soc_codec_device soc_codec_dev_msm = {
|
| 101 |
+
.probe = msm_pcm_probe,
|
| 102 |
+
};
|
| 103 |
+
EXPORT_SYMBOL_GPL(soc_codec_dev_msm);
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
static int __init msm_dai_init(void)
|
| 107 |
+
{
|
| 108 |
+
return snd_soc_register_dais(msm_dais, ARRAY_SIZE(msm_dais));
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
static void __exit msm_dai_exit(void)
|
| 112 |
+
{
|
| 113 |
+
snd_soc_unregister_dais(msm_dais, ARRAY_SIZE(msm_dais));
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
module_init(msm_dai_init);
|
| 117 |
+
module_exit(msm_dai_exit);
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
MODULE_DESCRIPTION("MSM Codec/Cpu Dai driver");
|
| 121 |
+
MODULE_LICENSE("GPL v2");
|
pool/shard000/C/0008538_10903.c
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// [ACM] #10903 - Rock-Paper-Scissors Tournament
|
| 2 |
+
// Problem Status CPU Date&Time(UTC) ID Best CPU
|
| 3 |
+
// 10903 Accepted 1.203 2006-11-07 11:24:36 5114450 0.148
|
| 4 |
+
|
| 5 |
+
#include<stdio.h>
|
| 6 |
+
|
| 7 |
+
int main(void)
|
| 8 |
+
{
|
| 9 |
+
int n, k, v , u, i = 0, pw[100], pl[100];
|
| 10 |
+
float w;
|
| 11 |
+
char vt[9], ut[9];
|
| 12 |
+
char type[3] = {'s', 'p', 'r'};
|
| 13 |
+
|
| 14 |
+
while(scanf("%d %d" , &n, &k) == 2)
|
| 15 |
+
{
|
| 16 |
+
if(i != 0)
|
| 17 |
+
printf("\n");
|
| 18 |
+
for(i = 0; i < 100; i ++)
|
| 19 |
+
{
|
| 20 |
+
pw[i] = 0;
|
| 21 |
+
pl[i] = 0;
|
| 22 |
+
}
|
| 23 |
+
for(i = 0; i < k * n * (n - 1) / 2 ;i ++)
|
| 24 |
+
{
|
| 25 |
+
scanf("%d %s %d %s" , &v, vt, &u, ut);
|
| 26 |
+
if(vt[0] == type[0] && ut[0] == type[0]);
|
| 27 |
+
else if(vt[0] == type[1] && ut[0] == type[1]);
|
| 28 |
+
else if(vt[0] == type[2] && ut[0] == type[2]);
|
| 29 |
+
else if(vt[0] == type[0])
|
| 30 |
+
{
|
| 31 |
+
if(ut[0] == type[1])
|
| 32 |
+
{
|
| 33 |
+
pw[v - 1] ++;
|
| 34 |
+
pl[u - 1] ++;
|
| 35 |
+
}
|
| 36 |
+
else
|
| 37 |
+
{
|
| 38 |
+
pw[u - 1] ++;
|
| 39 |
+
pl[v - 1] ++;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
else if(vt[0] == type[1])
|
| 43 |
+
{
|
| 44 |
+
if(ut[0] == type[0])
|
| 45 |
+
{
|
| 46 |
+
pw[u - 1] ++;
|
| 47 |
+
pl[v - 1] ++;
|
| 48 |
+
}
|
| 49 |
+
else
|
| 50 |
+
{
|
| 51 |
+
pw[v - 1] ++;
|
| 52 |
+
pl[u - 1] ++;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
else
|
| 56 |
+
{
|
| 57 |
+
if(ut[0] == type[0])
|
| 58 |
+
{
|
| 59 |
+
pw[v - 1] ++;
|
| 60 |
+
pl[u - 1] ++;
|
| 61 |
+
}
|
| 62 |
+
else
|
| 63 |
+
{
|
| 64 |
+
pw[u - 1] ++;
|
| 65 |
+
pl[v - 1] ++;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
for(i = 0; i < n; i ++)
|
| 70 |
+
{
|
| 71 |
+
w = pw[i] + pl[i];
|
| 72 |
+
if(w == 0)
|
| 73 |
+
printf("-\n");
|
| 74 |
+
else
|
| 75 |
+
{
|
| 76 |
+
w = pw[i] / w;
|
| 77 |
+
printf("%.3f\n" , w);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
return 0;
|
| 82 |
+
}
|
pool/shard000/C/0008544_windir.c
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***********************************************************************/
|
| 2 |
+
/* */
|
| 3 |
+
/* Objective Caml */
|
| 4 |
+
/* */
|
| 5 |
+
/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
| 6 |
+
/* */
|
| 7 |
+
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
| 8 |
+
/* en Automatique. All rights reserved. This file is distributed */
|
| 9 |
+
/* under the terms of the GNU Library General Public License, with */
|
| 10 |
+
/* the special exception on linking described in file ../../LICENSE. */
|
| 11 |
+
/* */
|
| 12 |
+
/***********************************************************************/
|
| 13 |
+
|
| 14 |
+
/* $Id: windir.c 5029 2002-07-23 14:12:03Z doligez $ */
|
| 15 |
+
|
| 16 |
+
#include <mlvalues.h>
|
| 17 |
+
#include <memory.h>
|
| 18 |
+
#include <errno.h>
|
| 19 |
+
#include <alloc.h>
|
| 20 |
+
#include <fail.h>
|
| 21 |
+
#include "unixsupport.h"
|
| 22 |
+
|
| 23 |
+
CAMLprim value win_findfirst(name)
|
| 24 |
+
value name;
|
| 25 |
+
{
|
| 26 |
+
HANDLE h;
|
| 27 |
+
value v;
|
| 28 |
+
WIN32_FIND_DATA fileinfo;
|
| 29 |
+
value valname = Val_unit;
|
| 30 |
+
value valh = Val_unit;
|
| 31 |
+
|
| 32 |
+
Begin_roots2 (valname,valh);
|
| 33 |
+
h = FindFirstFile(String_val(name),&fileinfo);
|
| 34 |
+
if (h == INVALID_HANDLE_VALUE) {
|
| 35 |
+
DWORD err = GetLastError();
|
| 36 |
+
if (err == ERROR_NO_MORE_FILES)
|
| 37 |
+
raise_end_of_file();
|
| 38 |
+
else {
|
| 39 |
+
win32_maperr(err);
|
| 40 |
+
uerror("opendir", Nothing);
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
valname = copy_string(fileinfo.cFileName);
|
| 44 |
+
valh = win_alloc_handle(h);
|
| 45 |
+
v = alloc_small(2, 0);
|
| 46 |
+
Field(v,0) = valname;
|
| 47 |
+
Field(v,1) = valh;
|
| 48 |
+
End_roots();
|
| 49 |
+
return v;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
CAMLprim value win_findnext(valh)
|
| 53 |
+
value valh;
|
| 54 |
+
{
|
| 55 |
+
WIN32_FIND_DATA fileinfo;
|
| 56 |
+
BOOL retcode;
|
| 57 |
+
|
| 58 |
+
retcode = FindNextFile(Handle_val(valh), &fileinfo);
|
| 59 |
+
if (!retcode) {
|
| 60 |
+
DWORD err = GetLastError();
|
| 61 |
+
if (err == ERROR_NO_MORE_FILES)
|
| 62 |
+
raise_end_of_file();
|
| 63 |
+
else {
|
| 64 |
+
win32_maperr(err);
|
| 65 |
+
uerror("readdir", Nothing);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
return copy_string(fileinfo.cFileName);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
CAMLprim value win_findclose(valh)
|
| 72 |
+
value valh;
|
| 73 |
+
{
|
| 74 |
+
if (! FindClose(Handle_val(valh))) {
|
| 75 |
+
win32_maperr(GetLastError());
|
| 76 |
+
uerror("closedir", Nothing);
|
| 77 |
+
}
|
| 78 |
+
return Val_unit;
|
| 79 |
+
}
|
| 80 |
+
|
pool/shard000/C/0008546_psychic.c
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
#include "internal.h"
|
| 4 |
+
|
| 5 |
+
#include "account.h"
|
| 6 |
+
#include "blist.h"
|
| 7 |
+
#include "conversation.h"
|
| 8 |
+
#include "debug.h"
|
| 9 |
+
#include "signals.h"
|
| 10 |
+
#include "status.h"
|
| 11 |
+
#include "version.h"
|
| 12 |
+
#include "privacy.h"
|
| 13 |
+
|
| 14 |
+
#include "plugin.h"
|
| 15 |
+
#include "pluginpref.h"
|
| 16 |
+
#include "prefs.h"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
#define PLUGIN_ID "core-psychic"
|
| 20 |
+
#define PLUGIN_NAME N_("Psychic Mode")
|
| 21 |
+
#define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation")
|
| 22 |
+
#define PLUGIN_DESC N_("Causes conversation windows to appear as other" \
|
| 23 |
+
" users begin to message you. This works for" \
|
| 24 |
+
" AIM, ICQ, XMPP, Sametime, and Yahoo!")
|
| 25 |
+
#define PLUGIN_AUTHOR "Christopher O'Brien <siege@preoccupied.net>"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
#define PREFS_BASE "/plugins/core/psychic"
|
| 29 |
+
#define PREF_BUDDIES PREFS_BASE "/buddies_only"
|
| 30 |
+
#define PREF_NOTICE PREFS_BASE "/show_notice"
|
| 31 |
+
#define PREF_STATUS PREFS_BASE "/activate_online"
|
| 32 |
+
#define PREF_RAISE PREFS_BASE "/raise_conv"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
static void
|
| 36 |
+
buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
|
| 37 |
+
PurpleConversation *gconv;
|
| 38 |
+
|
| 39 |
+
if(purple_prefs_get_bool(PREF_STATUS) &&
|
| 40 |
+
! purple_status_is_available(purple_account_get_active_status(acct))) {
|
| 41 |
+
purple_debug_info("psychic", "not available, doing nothing\n");
|
| 42 |
+
return;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if(purple_prefs_get_bool(PREF_BUDDIES) &&
|
| 46 |
+
! purple_find_buddy(acct, name)) {
|
| 47 |
+
purple_debug_info("psychic", "not in blist, doing nothing\n");
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if(FALSE == purple_privacy_check(acct, name)) {
|
| 52 |
+
purple_debug_info("psychic", "user %s is blocked\n", name);
|
| 53 |
+
return;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, acct);
|
| 57 |
+
if(! gconv) {
|
| 58 |
+
purple_debug_info("psychic", "no previous conversation exists\n");
|
| 59 |
+
gconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, name);
|
| 60 |
+
|
| 61 |
+
if(purple_prefs_get_bool(PREF_RAISE)) {
|
| 62 |
+
purple_conversation_present(gconv);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if(purple_prefs_get_bool(PREF_NOTICE)) {
|
| 66 |
+
|
| 67 |
+
/* This is a quote from Star Wars. You should probably not
|
| 68 |
+
translate it literally. If you can't find a fitting cultural
|
| 69 |
+
reference in your language, consider translating something
|
| 70 |
+
like this instead: "You feel a new message coming." */
|
| 71 |
+
purple_conversation_write(gconv, NULL,
|
| 72 |
+
_("You feel a disturbance in the force..."),
|
| 73 |
+
PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY,
|
| 74 |
+
time(NULL));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
purple_conv_im_set_typing_state(PURPLE_CONV_IM(gconv), PURPLE_TYPING);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
static PurplePluginPrefFrame *
|
| 83 |
+
get_plugin_pref_frame(PurplePlugin *plugin) {
|
| 84 |
+
|
| 85 |
+
PurplePluginPrefFrame *frame;
|
| 86 |
+
PurplePluginPref *pref;
|
| 87 |
+
|
| 88 |
+
frame = purple_plugin_pref_frame_new();
|
| 89 |
+
|
| 90 |
+
pref = purple_plugin_pref_new_with_name(PREF_BUDDIES);
|
| 91 |
+
purple_plugin_pref_set_label(pref, _("Only enable for users on"
|
| 92 |
+
" the buddy list"));
|
| 93 |
+
purple_plugin_pref_frame_add(frame, pref);
|
| 94 |
+
|
| 95 |
+
pref = purple_plugin_pref_new_with_name(PREF_STATUS);
|
| 96 |
+
purple_plugin_pref_set_label(pref, _("Disable when away"));
|
| 97 |
+
purple_plugin_pref_frame_add(frame, pref);
|
| 98 |
+
|
| 99 |
+
pref = purple_plugin_pref_new_with_name(PREF_NOTICE);
|
| 100 |
+
purple_plugin_pref_set_label(pref, _("Display notification message in"
|
| 101 |
+
" conversations"));
|
| 102 |
+
purple_plugin_pref_frame_add(frame, pref);
|
| 103 |
+
|
| 104 |
+
pref = purple_plugin_pref_new_with_name(PREF_RAISE);
|
| 105 |
+
purple_plugin_pref_set_label(pref, _("Raise psychic conversations"));
|
| 106 |
+
purple_plugin_pref_frame_add(frame, pref);
|
| 107 |
+
|
| 108 |
+
return frame;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
static gboolean
|
| 113 |
+
plugin_load(PurplePlugin *plugin) {
|
| 114 |
+
|
| 115 |
+
void *convs_handle;
|
| 116 |
+
convs_handle = purple_conversations_get_handle();
|
| 117 |
+
|
| 118 |
+
purple_signal_connect(convs_handle, "buddy-typing", plugin,
|
| 119 |
+
PURPLE_CALLBACK(buddy_typing_cb), NULL);
|
| 120 |
+
|
| 121 |
+
return TRUE;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
static PurplePluginUiInfo prefs_info = {
|
| 126 |
+
get_plugin_pref_frame,
|
| 127 |
+
0, /* page_num (Reserved) */
|
| 128 |
+
NULL, /* frame (Reserved) */
|
| 129 |
+
|
| 130 |
+
/* padding */
|
| 131 |
+
NULL,
|
| 132 |
+
NULL,
|
| 133 |
+
NULL,
|
| 134 |
+
NULL
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
static PurplePluginInfo info = {
|
| 139 |
+
PURPLE_PLUGIN_MAGIC,
|
| 140 |
+
PURPLE_MAJOR_VERSION,
|
| 141 |
+
PURPLE_MINOR_VERSION,
|
| 142 |
+
PURPLE_PLUGIN_STANDARD, /**< type */
|
| 143 |
+
NULL, /**< ui_requirement */
|
| 144 |
+
0, /**< flags */
|
| 145 |
+
NULL, /**< dependencies */
|
| 146 |
+
PURPLE_PRIORITY_DEFAULT, /**< priority */
|
| 147 |
+
|
| 148 |
+
PLUGIN_ID, /**< id */
|
| 149 |
+
PLUGIN_NAME, /**< name */
|
| 150 |
+
DISPLAY_VERSION, /**< version */
|
| 151 |
+
PLUGIN_SUMMARY, /**< summary */
|
| 152 |
+
PLUGIN_DESC, /**< description */
|
| 153 |
+
PLUGIN_AUTHOR, /**< author */
|
| 154 |
+
PURPLE_WEBSITE, /**< homepage */
|
| 155 |
+
|
| 156 |
+
plugin_load, /**< load */
|
| 157 |
+
NULL, /**< unload */
|
| 158 |
+
NULL, /**< destroy */
|
| 159 |
+
|
| 160 |
+
NULL, /**< ui_info */
|
| 161 |
+
NULL, /**< extra_info */
|
| 162 |
+
&prefs_info, /**< prefs_info */
|
| 163 |
+
NULL, /**< actions */
|
| 164 |
+
|
| 165 |
+
/* padding */
|
| 166 |
+
NULL,
|
| 167 |
+
NULL,
|
| 168 |
+
NULL,
|
| 169 |
+
NULL
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
static void
|
| 174 |
+
init_plugin(PurplePlugin *plugin) {
|
| 175 |
+
purple_prefs_add_none(PREFS_BASE);
|
| 176 |
+
purple_prefs_add_bool(PREF_BUDDIES, FALSE);
|
| 177 |
+
purple_prefs_add_bool(PREF_NOTICE, TRUE);
|
| 178 |
+
purple_prefs_add_bool(PREF_STATUS, TRUE);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
PURPLE_INIT_PLUGIN(psychic, init_plugin, info)
|
pool/shard000/C/0008549_wolfevent.c
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* wolfevent.c
|
| 2 |
+
*
|
| 3 |
+
* Copyright (C) 2006-2020 wolfSSL Inc.
|
| 4 |
+
*
|
| 5 |
+
* This file is part of wolfSSL.
|
| 6 |
+
*
|
| 7 |
+
* wolfSSL is free software; you can redistribute it and/or modify
|
| 8 |
+
* it under the terms of the GNU General Public License as published by
|
| 9 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 10 |
+
* (at your option) any later version.
|
| 11 |
+
*
|
| 12 |
+
* wolfSSL is distributed in the hope that it will be useful,
|
| 13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
+
* GNU General Public License for more details.
|
| 16 |
+
*
|
| 17 |
+
* You should have received a copy of the GNU General Public License
|
| 18 |
+
* along with this program; if not, write to the Free Software
|
| 19 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
| 20 |
+
*/
|
| 21 |
+
|
| 22 |
+
#ifdef HAVE_CONFIG_H
|
| 23 |
+
#include <config.h>
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
#include <wolfssl/wolfcrypt/settings.h>
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
#ifdef HAVE_WOLF_EVENT
|
| 30 |
+
|
| 31 |
+
#include <wolfssl/internal.h>
|
| 32 |
+
#include <wolfssl/error-ssl.h>
|
| 33 |
+
#include <wolfssl/wolfcrypt/error-crypt.h>
|
| 34 |
+
|
| 35 |
+
#include <wolfssl/wolfcrypt/wolfevent.h>
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context)
|
| 39 |
+
{
|
| 40 |
+
if (event == NULL) {
|
| 41 |
+
return BAD_FUNC_ARG;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
if (event->state == WOLF_EVENT_STATE_PENDING) {
|
| 45 |
+
WOLFSSL_MSG("Event already pending!");
|
| 46 |
+
return BAD_COND_E;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
XMEMSET(event, 0, sizeof(WOLF_EVENT));
|
| 50 |
+
event->type = type;
|
| 51 |
+
event->context = context;
|
| 52 |
+
|
| 53 |
+
return 0;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
int wolfEvent_Poll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags)
|
| 57 |
+
{
|
| 58 |
+
int ret = BAD_COND_E;
|
| 59 |
+
|
| 60 |
+
/* Check hardware */
|
| 61 |
+
#ifdef WOLFSSL_ASYNC_CRYPT
|
| 62 |
+
if (event->type >= WOLF_EVENT_TYPE_ASYNC_FIRST &&
|
| 63 |
+
event->type <= WOLF_EVENT_TYPE_ASYNC_LAST)
|
| 64 |
+
{
|
| 65 |
+
ret = wolfAsync_EventPoll(event, flags);
|
| 66 |
+
}
|
| 67 |
+
#endif /* WOLFSSL_ASYNC_CRYPT */
|
| 68 |
+
|
| 69 |
+
return ret;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
int wolfEventQueue_Init(WOLF_EVENT_QUEUE* queue)
|
| 73 |
+
{
|
| 74 |
+
int ret = 0;
|
| 75 |
+
|
| 76 |
+
if (queue == NULL) {
|
| 77 |
+
return BAD_FUNC_ARG;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
XMEMSET(queue, 0, sizeof(WOLF_EVENT_QUEUE));
|
| 81 |
+
#ifndef SINGLE_THREADED
|
| 82 |
+
ret = wc_InitMutex(&queue->lock);
|
| 83 |
+
#endif
|
| 84 |
+
return ret;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
|
| 89 |
+
{
|
| 90 |
+
int ret;
|
| 91 |
+
|
| 92 |
+
if (queue == NULL || event == NULL) {
|
| 93 |
+
return BAD_FUNC_ARG;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
#ifndef SINGLE_THREADED
|
| 97 |
+
if ((ret = wc_LockMutex(&queue->lock)) != 0) {
|
| 98 |
+
return ret;
|
| 99 |
+
}
|
| 100 |
+
#endif
|
| 101 |
+
|
| 102 |
+
ret = wolfEventQueue_Add(queue, event);
|
| 103 |
+
|
| 104 |
+
#ifndef SINGLE_THREADED
|
| 105 |
+
wc_UnLockMutex(&queue->lock);
|
| 106 |
+
#endif
|
| 107 |
+
|
| 108 |
+
return ret;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event)
|
| 112 |
+
{
|
| 113 |
+
int ret = 0;
|
| 114 |
+
|
| 115 |
+
if (queue == NULL || event == NULL) {
|
| 116 |
+
return BAD_FUNC_ARG;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#ifndef SINGLE_THREADED
|
| 120 |
+
/* In single threaded mode "event_queue.lock" doesn't exist */
|
| 121 |
+
if ((ret = wc_LockMutex(&queue->lock)) != 0) {
|
| 122 |
+
return ret;
|
| 123 |
+
}
|
| 124 |
+
#endif
|
| 125 |
+
|
| 126 |
+
/* Pop first item off queue */
|
| 127 |
+
*event = queue->head;
|
| 128 |
+
ret = wolfEventQueue_Remove(queue, *event);
|
| 129 |
+
|
| 130 |
+
#ifndef SINGLE_THREADED
|
| 131 |
+
wc_UnLockMutex(&queue->lock);
|
| 132 |
+
#endif
|
| 133 |
+
|
| 134 |
+
return ret;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* assumes queue is locked by caller */
|
| 138 |
+
int wolfEventQueue_Add(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
|
| 139 |
+
{
|
| 140 |
+
if (queue == NULL || event == NULL) {
|
| 141 |
+
return BAD_FUNC_ARG;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
event->next = NULL; /* added to end */
|
| 145 |
+
event->prev = NULL;
|
| 146 |
+
if (queue->tail == NULL) {
|
| 147 |
+
queue->head = event;
|
| 148 |
+
}
|
| 149 |
+
else {
|
| 150 |
+
queue->tail->next = event;
|
| 151 |
+
event->prev = queue->tail;
|
| 152 |
+
}
|
| 153 |
+
queue->tail = event; /* add to the end either way */
|
| 154 |
+
queue->count++;
|
| 155 |
+
|
| 156 |
+
return 0;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/* assumes queue is locked by caller */
|
| 160 |
+
int wolfEventQueue_Remove(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event)
|
| 161 |
+
{
|
| 162 |
+
int ret = 0;
|
| 163 |
+
|
| 164 |
+
if (queue == NULL || event == NULL) {
|
| 165 |
+
return BAD_FUNC_ARG;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
if (event == queue->head && event == queue->tail) {
|
| 169 |
+
queue->head = NULL;
|
| 170 |
+
queue->tail = NULL;
|
| 171 |
+
}
|
| 172 |
+
else if (event == queue->head) {
|
| 173 |
+
queue->head = event->next;
|
| 174 |
+
queue->head->prev = NULL;
|
| 175 |
+
}
|
| 176 |
+
else if (event == queue->tail) {
|
| 177 |
+
queue->tail = event->prev;
|
| 178 |
+
queue->tail->next = NULL;
|
| 179 |
+
}
|
| 180 |
+
else {
|
| 181 |
+
WOLF_EVENT* next = event->next;
|
| 182 |
+
WOLF_EVENT* prev = event->prev;
|
| 183 |
+
next->prev = prev;
|
| 184 |
+
prev->next = next;
|
| 185 |
+
}
|
| 186 |
+
queue->count--;
|
| 187 |
+
|
| 188 |
+
return ret;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
|
| 192 |
+
WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount)
|
| 193 |
+
{
|
| 194 |
+
WOLF_EVENT* event;
|
| 195 |
+
int ret = 0, count = 0;
|
| 196 |
+
|
| 197 |
+
if (queue == NULL) {
|
| 198 |
+
return BAD_FUNC_ARG;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
#ifndef SINGLE_THREADED
|
| 202 |
+
/* In single threaded mode "event_queue.lock" doesn't exist */
|
| 203 |
+
if ((ret = wc_LockMutex(&queue->lock)) != 0) {
|
| 204 |
+
return ret;
|
| 205 |
+
}
|
| 206 |
+
#endif
|
| 207 |
+
|
| 208 |
+
/* itterate event queue */
|
| 209 |
+
for (event = queue->head; event != NULL; event = event->next)
|
| 210 |
+
{
|
| 211 |
+
/* optional filter based on context */
|
| 212 |
+
if (context_filter == NULL || event->context == context_filter) {
|
| 213 |
+
|
| 214 |
+
/* poll event */
|
| 215 |
+
ret = wolfEvent_Poll(event, flags);
|
| 216 |
+
if (ret < 0) break; /* exit for */
|
| 217 |
+
|
| 218 |
+
/* If event is done then process */
|
| 219 |
+
if (event->state == WOLF_EVENT_STATE_DONE) {
|
| 220 |
+
/* remove from queue */
|
| 221 |
+
ret = wolfEventQueue_Remove(queue, event);
|
| 222 |
+
if (ret < 0) break; /* exit for */
|
| 223 |
+
|
| 224 |
+
/* return pointer in 'events' arg */
|
| 225 |
+
if (events) {
|
| 226 |
+
events[count] = event; /* return pointer */
|
| 227 |
+
}
|
| 228 |
+
count++;
|
| 229 |
+
|
| 230 |
+
/* check to make sure our event list isn't full */
|
| 231 |
+
if (events && count >= maxEvents) {
|
| 232 |
+
break; /* exit for */
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
#ifndef SINGLE_THREADED
|
| 239 |
+
wc_UnLockMutex(&queue->lock);
|
| 240 |
+
#endif
|
| 241 |
+
|
| 242 |
+
/* return number of properly populated events */
|
| 243 |
+
if (eventCount) {
|
| 244 |
+
*eventCount = count;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
return ret;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue)
|
| 251 |
+
{
|
| 252 |
+
int ret;
|
| 253 |
+
|
| 254 |
+
if (queue == NULL) {
|
| 255 |
+
return BAD_FUNC_ARG;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
#ifndef SINGLE_THREADED
|
| 259 |
+
/* In single threaded mode "event_queue.lock" doesn't exist */
|
| 260 |
+
if ((ret = wc_LockMutex(&queue->lock)) != 0) {
|
| 261 |
+
return ret;
|
| 262 |
+
}
|
| 263 |
+
#endif
|
| 264 |
+
|
| 265 |
+
ret = queue->count;
|
| 266 |
+
|
| 267 |
+
#ifndef SINGLE_THREADED
|
| 268 |
+
wc_UnLockMutex(&queue->lock);
|
| 269 |
+
#endif
|
| 270 |
+
|
| 271 |
+
return ret;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue)
|
| 275 |
+
{
|
| 276 |
+
if (queue) {
|
| 277 |
+
#ifndef SINGLE_THREADED
|
| 278 |
+
wc_FreeMutex(&queue->lock);
|
| 279 |
+
#endif
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
#endif /* HAVE_WOLF_EVENT */
|
pool/shard000/C/0008555_pkcs11-list.c
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2009, 2015 Internet Systems Consortium, Inc. ("ISC")
|
| 3 |
+
*
|
| 4 |
+
* Permission to use, copy, modify, and/or distribute this software for any
|
| 5 |
+
* purpose with or without fee is hereby granted, provided that the above
|
| 6 |
+
* copyright notice and this permission notice appear in all copies.
|
| 7 |
+
*
|
| 8 |
+
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
|
| 9 |
+
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
| 10 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
|
| 11 |
+
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 12 |
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 13 |
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
| 14 |
+
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
/*
|
| 18 |
+
* Portions copyright (c) 2008 Nominet UK. All rights reserved.
|
| 19 |
+
*
|
| 20 |
+
* Redistribution and use in source and binary forms, with or without
|
| 21 |
+
* modification, are permitted provided that the following conditions
|
| 22 |
+
* are met:
|
| 23 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 24 |
+
* notice, this list of conditions and the following disclaimer.
|
| 25 |
+
* 2. Redistributions in binary form must reproduce the above copyright
|
| 26 |
+
* notice, this list of conditions and the following disclaimer in the
|
| 27 |
+
* documentation and/or other materials provided with the distribution.
|
| 28 |
+
*
|
| 29 |
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
| 30 |
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
| 31 |
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
| 32 |
+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 33 |
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
| 34 |
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 35 |
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 36 |
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 37 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
| 38 |
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 39 |
+
*/
|
| 40 |
+
|
| 41 |
+
/* $Id: pkcs11-list.c,v 1.7 2009/10/26 23:36:53 each Exp $ */
|
| 42 |
+
|
| 43 |
+
/* pkcs11-list [-P] [-m module] [-s slot] [-i $id | -l $label] [-p $pin] */
|
| 44 |
+
|
| 45 |
+
/*! \file */
|
| 46 |
+
|
| 47 |
+
#include <config.h>
|
| 48 |
+
|
| 49 |
+
#include <stdio.h>
|
| 50 |
+
#include <stdlib.h>
|
| 51 |
+
#include <fcntl.h>
|
| 52 |
+
#include <errno.h>
|
| 53 |
+
#include <string.h>
|
| 54 |
+
#include <sys/types.h>
|
| 55 |
+
|
| 56 |
+
#include <isc/commandline.h>
|
| 57 |
+
#include <isc/print.h>
|
| 58 |
+
#include <isc/result.h>
|
| 59 |
+
#include <isc/types.h>
|
| 60 |
+
|
| 61 |
+
#include <pk11/pk11.h>
|
| 62 |
+
#include <pk11/result.h>
|
| 63 |
+
|
| 64 |
+
#if !(defined(HAVE_GETPASSPHRASE) || (defined (__SVR4) && defined (__sun)))
|
| 65 |
+
#define getpassphrase(x) getpass(x)
|
| 66 |
+
#endif
|
| 67 |
+
|
| 68 |
+
int
|
| 69 |
+
main(int argc, char *argv[]) {
|
| 70 |
+
isc_result_t result;
|
| 71 |
+
CK_RV rv;
|
| 72 |
+
CK_SLOT_ID slot = 0;
|
| 73 |
+
CK_SESSION_HANDLE hSession;
|
| 74 |
+
CK_BYTE attr_id[2];
|
| 75 |
+
CK_OBJECT_HANDLE akey[50];
|
| 76 |
+
pk11_context_t pctx;
|
| 77 |
+
char *lib_name = NULL;
|
| 78 |
+
char *label = NULL;
|
| 79 |
+
char *pin = NULL;
|
| 80 |
+
isc_boolean_t error = ISC_FALSE, logon = ISC_TRUE, all = ISC_FALSE;
|
| 81 |
+
unsigned int i = 0, id = 0;
|
| 82 |
+
int c, errflg = 0;
|
| 83 |
+
CK_ULONG ulObjectCount;
|
| 84 |
+
CK_ATTRIBUTE search_template[] = {
|
| 85 |
+
{CKA_ID, &attr_id, sizeof(attr_id)}
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
while ((c = isc_commandline_parse(argc, argv, ":m:s:i:l:p:P")) != -1) {
|
| 89 |
+
switch (c) {
|
| 90 |
+
case 'P':
|
| 91 |
+
logon = ISC_FALSE;
|
| 92 |
+
break;
|
| 93 |
+
case 'm':
|
| 94 |
+
lib_name = isc_commandline_argument;
|
| 95 |
+
break;
|
| 96 |
+
case 's':
|
| 97 |
+
slot = atoi(isc_commandline_argument);
|
| 98 |
+
break;
|
| 99 |
+
case 'i':
|
| 100 |
+
id = atoi(isc_commandline_argument);
|
| 101 |
+
id &= 0xffff;
|
| 102 |
+
break;
|
| 103 |
+
case 'l':
|
| 104 |
+
label = isc_commandline_argument;
|
| 105 |
+
break;
|
| 106 |
+
case 'p':
|
| 107 |
+
pin = isc_commandline_argument;
|
| 108 |
+
break;
|
| 109 |
+
case ':':
|
| 110 |
+
fprintf(stderr, "Option -%c requires an operand\n",
|
| 111 |
+
isc_commandline_option);
|
| 112 |
+
errflg++;
|
| 113 |
+
break;
|
| 114 |
+
case '?':
|
| 115 |
+
default:
|
| 116 |
+
fprintf(stderr, "Unrecognised option: -%c\n",
|
| 117 |
+
isc_commandline_option);
|
| 118 |
+
errflg++;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
if (errflg) {
|
| 123 |
+
fprintf(stderr, "Usage:\n");
|
| 124 |
+
fprintf(stderr, "\tpkcs11-list [-P] [-m module] [-s slot] "
|
| 125 |
+
"[-i id | -l label] [-p pin]\n");
|
| 126 |
+
exit(1);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (!id && (label == NULL))
|
| 130 |
+
all = ISC_TRUE;
|
| 131 |
+
|
| 132 |
+
if (slot)
|
| 133 |
+
printf("slot %lu\n", slot);
|
| 134 |
+
|
| 135 |
+
if (id) {
|
| 136 |
+
printf("id %i\n", id);
|
| 137 |
+
attr_id[0] = (id >> 8) & 0xff;
|
| 138 |
+
attr_id[1] = id & 0xff;
|
| 139 |
+
} else if (label != NULL) {
|
| 140 |
+
printf("label %s\n", label);
|
| 141 |
+
search_template[0].type = CKA_LABEL;
|
| 142 |
+
search_template[0].pValue = label;
|
| 143 |
+
search_template[0].ulValueLen = strlen(label);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
pk11_result_register();
|
| 147 |
+
|
| 148 |
+
/* Initialize the CRYPTOKI library */
|
| 149 |
+
if (lib_name != NULL)
|
| 150 |
+
pk11_set_lib_name(lib_name);
|
| 151 |
+
|
| 152 |
+
if (logon && pin == NULL)
|
| 153 |
+
pin = getpassphrase("Enter Pin: ");
|
| 154 |
+
|
| 155 |
+
result = pk11_get_session(&pctx, OP_ANY, ISC_FALSE, ISC_FALSE,
|
| 156 |
+
logon, pin, slot);
|
| 157 |
+
if (result == PK11_R_NORANDOMSERVICE ||
|
| 158 |
+
result == PK11_R_NODIGESTSERVICE ||
|
| 159 |
+
result == PK11_R_NOAESSERVICE) {
|
| 160 |
+
fprintf(stderr, "Warning: %s\n", isc_result_totext(result));
|
| 161 |
+
fprintf(stderr, "This HSM will not work with BIND 9 "
|
| 162 |
+
"using native PKCS#11.\n");
|
| 163 |
+
} else if (result != ISC_R_SUCCESS) {
|
| 164 |
+
fprintf(stderr, "Unrecoverable error initializing "
|
| 165 |
+
"PKCS#11: %s\n", isc_result_totext(result));
|
| 166 |
+
fprintf(stderr, "Unrecoverable error initializing "
|
| 167 |
+
"PKCS#11: %s\n", isc_result_totext(result));
|
| 168 |
+
exit(1);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (pin != NULL)
|
| 172 |
+
memset(pin, 0, strlen(pin));
|
| 173 |
+
|
| 174 |
+
hSession = pctx.session;
|
| 175 |
+
|
| 176 |
+
rv = pkcs_C_FindObjectsInit(hSession, search_template, all ? 0 : 1);
|
| 177 |
+
if (rv != CKR_OK) {
|
| 178 |
+
fprintf(stderr, "C_FindObjectsInit: Error = 0x%.8lX\n", rv);
|
| 179 |
+
error = 1;
|
| 180 |
+
goto exit_session;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
ulObjectCount = 1;
|
| 184 |
+
while (ulObjectCount) {
|
| 185 |
+
rv = pkcs_C_FindObjects(hSession, akey, 50, &ulObjectCount);
|
| 186 |
+
if (rv != CKR_OK) {
|
| 187 |
+
fprintf(stderr,
|
| 188 |
+
"C_FindObjects: Error = 0x%.8lX\n",
|
| 189 |
+
rv);
|
| 190 |
+
error = 1;
|
| 191 |
+
goto exit_search;
|
| 192 |
+
}
|
| 193 |
+
for (i = 0; i < ulObjectCount; i++) {
|
| 194 |
+
unsigned int j, len;
|
| 195 |
+
|
| 196 |
+
CK_OBJECT_CLASS oclass = 0;
|
| 197 |
+
CK_BYTE labelbuf[64 + 1];
|
| 198 |
+
CK_BYTE idbuf[64];
|
| 199 |
+
CK_ATTRIBUTE template[] = {
|
| 200 |
+
{CKA_CLASS, &oclass, sizeof(oclass)},
|
| 201 |
+
{CKA_LABEL, labelbuf, sizeof(labelbuf) - 1},
|
| 202 |
+
{CKA_ID, idbuf, sizeof(idbuf)}
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
memset(labelbuf, 0, sizeof(labelbuf));
|
| 206 |
+
memset(idbuf, 0, sizeof(idbuf));
|
| 207 |
+
|
| 208 |
+
rv = pkcs_C_GetAttributeValue(hSession, akey[i],
|
| 209 |
+
template, 3);
|
| 210 |
+
if (rv != CKR_OK) {
|
| 211 |
+
fprintf(stderr,
|
| 212 |
+
"C_GetAttributeValue[%u]: "
|
| 213 |
+
"rv = 0x%.8lX\n",
|
| 214 |
+
i, rv);
|
| 215 |
+
if (rv == CKR_BUFFER_TOO_SMALL)
|
| 216 |
+
fprintf(stderr,
|
| 217 |
+
"%u too small: %lu %lu %lu\n",
|
| 218 |
+
i,
|
| 219 |
+
template[0].ulValueLen,
|
| 220 |
+
template[1].ulValueLen,
|
| 221 |
+
template[2].ulValueLen);
|
| 222 |
+
error = 1;
|
| 223 |
+
continue;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
len = template[2].ulValueLen;
|
| 227 |
+
printf("object[%u]: handle %lu class %lu "
|
| 228 |
+
"label[%lu] '%s' id[%lu] ",
|
| 229 |
+
i, akey[i], oclass,
|
| 230 |
+
template[1].ulValueLen,
|
| 231 |
+
labelbuf,
|
| 232 |
+
template[2].ulValueLen);
|
| 233 |
+
if (len == 2) {
|
| 234 |
+
id = (idbuf[0] << 8) & 0xff00;
|
| 235 |
+
id |= idbuf[1] & 0xff;
|
| 236 |
+
printf("%u\n", id);
|
| 237 |
+
} else {
|
| 238 |
+
if (len > 8)
|
| 239 |
+
len = 8;
|
| 240 |
+
if (len > 0)
|
| 241 |
+
printf("0x");
|
| 242 |
+
for (j = 0; j < len; j++)
|
| 243 |
+
printf("%02x", idbuf[j]);
|
| 244 |
+
if (template[2].ulValueLen > len)
|
| 245 |
+
printf("...\n");
|
| 246 |
+
else
|
| 247 |
+
printf("\n");
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
exit_search:
|
| 253 |
+
rv = pkcs_C_FindObjectsFinal(hSession);
|
| 254 |
+
if (rv != CKR_OK) {
|
| 255 |
+
fprintf(stderr, "C_FindObjectsFinal: Error = 0x%.8lX\n", rv);
|
| 256 |
+
error = 1;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
exit_session:
|
| 260 |
+
pk11_return_session(&pctx);
|
| 261 |
+
(void) pk11_finalize();
|
| 262 |
+
|
| 263 |
+
exit(error);
|
| 264 |
+
}
|
pool/shard000/C/0008576_aigMffc.c
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**CFile****************************************************************
|
| 2 |
+
|
| 3 |
+
FileName [aigMffc.c]
|
| 4 |
+
|
| 5 |
+
SystemName [ABC: Logic synthesis and verification system.]
|
| 6 |
+
|
| 7 |
+
PackageName [AIG package.]
|
| 8 |
+
|
| 9 |
+
Synopsis [Computation of MFFCs.]
|
| 10 |
+
|
| 11 |
+
Author [Alan Mishchenko]
|
| 12 |
+
|
| 13 |
+
Affiliation [UC Berkeley]
|
| 14 |
+
|
| 15 |
+
Date [Ver. 1.0. Started - April 28, 2007.]
|
| 16 |
+
|
| 17 |
+
Revision [$Id: aigMffc.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
|
| 18 |
+
|
| 19 |
+
***********************************************************************/
|
| 20 |
+
|
| 21 |
+
#include "aig.h"
|
| 22 |
+
|
| 23 |
+
////////////////////////////////////////////////////////////////////////
|
| 24 |
+
/// DECLARATIONS ///
|
| 25 |
+
////////////////////////////////////////////////////////////////////////
|
| 26 |
+
|
| 27 |
+
////////////////////////////////////////////////////////////////////////
|
| 28 |
+
/// FUNCTION DEFINITIONS ///
|
| 29 |
+
////////////////////////////////////////////////////////////////////////
|
| 30 |
+
|
| 31 |
+
/**Function*************************************************************
|
| 32 |
+
|
| 33 |
+
Synopsis [Dereferences the node's MFFC.]
|
| 34 |
+
|
| 35 |
+
Description []
|
| 36 |
+
|
| 37 |
+
SideEffects []
|
| 38 |
+
|
| 39 |
+
SeeAlso []
|
| 40 |
+
|
| 41 |
+
***********************************************************************/
|
| 42 |
+
int Aig_NodeDeref_rec( Aig_Obj_t * pNode, unsigned LevelMin )
|
| 43 |
+
{
|
| 44 |
+
Aig_Obj_t * pFanin;
|
| 45 |
+
int Counter = 0;
|
| 46 |
+
if ( Aig_ObjIsPi(pNode) )
|
| 47 |
+
return 0;
|
| 48 |
+
// consider the first fanin
|
| 49 |
+
pFanin = Aig_ObjFanin0(pNode);
|
| 50 |
+
assert( pFanin->nRefs > 0 );
|
| 51 |
+
if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 52 |
+
Counter += Aig_NodeDeref_rec( pFanin, LevelMin );
|
| 53 |
+
// skip the buffer
|
| 54 |
+
if ( Aig_ObjIsBuf(pNode) )
|
| 55 |
+
return Counter;
|
| 56 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 57 |
+
// consider the second fanin
|
| 58 |
+
pFanin = Aig_ObjFanin1(pNode);
|
| 59 |
+
assert( pFanin->nRefs > 0 );
|
| 60 |
+
if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 61 |
+
Counter += Aig_NodeDeref_rec( pFanin, LevelMin );
|
| 62 |
+
return Counter + 1;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**Function*************************************************************
|
| 66 |
+
|
| 67 |
+
Synopsis [References the node's MFFC.]
|
| 68 |
+
|
| 69 |
+
Description []
|
| 70 |
+
|
| 71 |
+
SideEffects []
|
| 72 |
+
|
| 73 |
+
SeeAlso []
|
| 74 |
+
|
| 75 |
+
***********************************************************************/
|
| 76 |
+
int Aig_NodeRef_rec( Aig_Obj_t * pNode, unsigned LevelMin )
|
| 77 |
+
{
|
| 78 |
+
Aig_Obj_t * pFanin;
|
| 79 |
+
int Counter = 0;
|
| 80 |
+
if ( Aig_ObjIsPi(pNode) )
|
| 81 |
+
return 0;
|
| 82 |
+
// consider the first fanin
|
| 83 |
+
pFanin = Aig_ObjFanin0(pNode);
|
| 84 |
+
if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 85 |
+
Counter += Aig_NodeRef_rec( pFanin, LevelMin );
|
| 86 |
+
// skip the buffer
|
| 87 |
+
if ( Aig_ObjIsBuf(pNode) )
|
| 88 |
+
return Counter;
|
| 89 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 90 |
+
// consider the second fanin
|
| 91 |
+
pFanin = Aig_ObjFanin1(pNode);
|
| 92 |
+
if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 93 |
+
Counter += Aig_NodeRef_rec( pFanin, LevelMin );
|
| 94 |
+
return Counter + 1;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**Function*************************************************************
|
| 98 |
+
|
| 99 |
+
Synopsis [References the node's MFFC.]
|
| 100 |
+
|
| 101 |
+
Description []
|
| 102 |
+
|
| 103 |
+
SideEffects []
|
| 104 |
+
|
| 105 |
+
SeeAlso []
|
| 106 |
+
|
| 107 |
+
***********************************************************************/
|
| 108 |
+
int Aig_NodeRefLabel_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin )
|
| 109 |
+
{
|
| 110 |
+
Aig_Obj_t * pFanin;
|
| 111 |
+
int Counter = 0;
|
| 112 |
+
if ( Aig_ObjIsPi(pNode) )
|
| 113 |
+
return 0;
|
| 114 |
+
Aig_ObjSetTravIdCurrent( p, pNode );
|
| 115 |
+
// consider the first fanin
|
| 116 |
+
pFanin = Aig_ObjFanin0(pNode);
|
| 117 |
+
if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 118 |
+
Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin );
|
| 119 |
+
if ( Aig_ObjIsBuf(pNode) )
|
| 120 |
+
return Counter;
|
| 121 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 122 |
+
// consider the second fanin
|
| 123 |
+
pFanin = Aig_ObjFanin1(pNode);
|
| 124 |
+
if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) )
|
| 125 |
+
Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin );
|
| 126 |
+
return Counter + 1;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
/**Function*************************************************************
|
| 130 |
+
|
| 131 |
+
Synopsis [Collects the internal and boundary nodes in the derefed MFFC.]
|
| 132 |
+
|
| 133 |
+
Description []
|
| 134 |
+
|
| 135 |
+
SideEffects []
|
| 136 |
+
|
| 137 |
+
SeeAlso []
|
| 138 |
+
|
| 139 |
+
***********************************************************************/
|
| 140 |
+
void Aig_NodeMffsSupp_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin, Vec_Ptr_t * vSupp, int fTopmost, Aig_Obj_t * pObjSkip )
|
| 141 |
+
{
|
| 142 |
+
// skip visited nodes
|
| 143 |
+
if ( Aig_ObjIsTravIdCurrent(p, pNode) )
|
| 144 |
+
return;
|
| 145 |
+
Aig_ObjSetTravIdCurrent(p, pNode);
|
| 146 |
+
// add to the new support nodes
|
| 147 |
+
if ( !fTopmost && pNode != pObjSkip && (Aig_ObjIsPi(pNode) || pNode->nRefs > 0 || pNode->Level <= LevelMin) )
|
| 148 |
+
{
|
| 149 |
+
if ( vSupp ) Vec_PtrPush( vSupp, pNode );
|
| 150 |
+
return;
|
| 151 |
+
}
|
| 152 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 153 |
+
// recur on the children
|
| 154 |
+
Aig_NodeMffsSupp_rec( p, Aig_ObjFanin0(pNode), LevelMin, vSupp, 0, pObjSkip );
|
| 155 |
+
Aig_NodeMffsSupp_rec( p, Aig_ObjFanin1(pNode), LevelMin, vSupp, 0, pObjSkip );
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**Function*************************************************************
|
| 159 |
+
|
| 160 |
+
Synopsis [Collects the support of depth-limited MFFC.]
|
| 161 |
+
|
| 162 |
+
Description [Returns the number of internal nodes in the MFFC.]
|
| 163 |
+
|
| 164 |
+
SideEffects []
|
| 165 |
+
|
| 166 |
+
SeeAlso []
|
| 167 |
+
|
| 168 |
+
***********************************************************************/
|
| 169 |
+
int Aig_NodeMffsSupp( Aig_Man_t * p, Aig_Obj_t * pNode, int LevelMin, Vec_Ptr_t * vSupp )
|
| 170 |
+
{
|
| 171 |
+
int ConeSize1, ConeSize2;
|
| 172 |
+
assert( !Aig_IsComplement(pNode) );
|
| 173 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 174 |
+
if ( vSupp ) Vec_PtrClear( vSupp );
|
| 175 |
+
Aig_ManIncrementTravId( p );
|
| 176 |
+
ConeSize1 = Aig_NodeDeref_rec( pNode, LevelMin );
|
| 177 |
+
Aig_NodeMffsSupp_rec( p, pNode, LevelMin, vSupp, 1, NULL );
|
| 178 |
+
ConeSize2 = Aig_NodeRef_rec( pNode, LevelMin );
|
| 179 |
+
assert( ConeSize1 == ConeSize2 );
|
| 180 |
+
assert( ConeSize1 > 0 );
|
| 181 |
+
return ConeSize1;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/**Function*************************************************************
|
| 185 |
+
|
| 186 |
+
Synopsis [Labels the nodes in the MFFC.]
|
| 187 |
+
|
| 188 |
+
Description [Returns the number of internal nodes in the MFFC.]
|
| 189 |
+
|
| 190 |
+
SideEffects []
|
| 191 |
+
|
| 192 |
+
SeeAlso []
|
| 193 |
+
|
| 194 |
+
***********************************************************************/
|
| 195 |
+
int Aig_NodeMffsLabel( Aig_Man_t * p, Aig_Obj_t * pNode )
|
| 196 |
+
{
|
| 197 |
+
int ConeSize1, ConeSize2;
|
| 198 |
+
assert( !Aig_IsComplement(pNode) );
|
| 199 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 200 |
+
Aig_ManIncrementTravId( p );
|
| 201 |
+
ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
|
| 202 |
+
ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 );
|
| 203 |
+
assert( ConeSize1 == ConeSize2 );
|
| 204 |
+
assert( ConeSize1 > 0 );
|
| 205 |
+
return ConeSize1;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**Function*************************************************************
|
| 209 |
+
|
| 210 |
+
Synopsis [Labels the nodes in the MFFC.]
|
| 211 |
+
|
| 212 |
+
Description [Returns the number of internal nodes in the MFFC.]
|
| 213 |
+
|
| 214 |
+
SideEffects []
|
| 215 |
+
|
| 216 |
+
SeeAlso []
|
| 217 |
+
|
| 218 |
+
***********************************************************************/
|
| 219 |
+
int Aig_NodeMffsLabelCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves )
|
| 220 |
+
{
|
| 221 |
+
Aig_Obj_t * pObj;
|
| 222 |
+
int i, ConeSize1, ConeSize2;
|
| 223 |
+
assert( !Aig_IsComplement(pNode) );
|
| 224 |
+
assert( Aig_ObjIsNode(pNode) );
|
| 225 |
+
Aig_ManIncrementTravId( p );
|
| 226 |
+
Vec_PtrForEachEntry( vLeaves, pObj, i )
|
| 227 |
+
pObj->nRefs++;
|
| 228 |
+
ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
|
| 229 |
+
ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 );
|
| 230 |
+
Vec_PtrForEachEntry( vLeaves, pObj, i )
|
| 231 |
+
pObj->nRefs--;
|
| 232 |
+
assert( ConeSize1 == ConeSize2 );
|
| 233 |
+
assert( ConeSize1 > 0 );
|
| 234 |
+
return ConeSize1;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
/**Function*************************************************************
|
| 238 |
+
|
| 239 |
+
Synopsis [Expands the cut by adding the most closely related node.]
|
| 240 |
+
|
| 241 |
+
Description [Returns 1 if the cut exists.]
|
| 242 |
+
|
| 243 |
+
SideEffects []
|
| 244 |
+
|
| 245 |
+
SeeAlso []
|
| 246 |
+
|
| 247 |
+
***********************************************************************/
|
| 248 |
+
int Aig_NodeMffsExtendCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vResult )
|
| 249 |
+
{
|
| 250 |
+
Aig_Obj_t * pObj, * pLeafBest;
|
| 251 |
+
int i, LevelMax, ConeSize1, ConeSize2, ConeCur1, ConeCur2, ConeBest;
|
| 252 |
+
// dereference the current cut
|
| 253 |
+
LevelMax = 0;
|
| 254 |
+
Vec_PtrForEachEntry( vLeaves, pObj, i )
|
| 255 |
+
LevelMax = AIG_MAX( LevelMax, (int)pObj->Level );
|
| 256 |
+
if ( LevelMax == 0 )
|
| 257 |
+
return 0;
|
| 258 |
+
// dereference the cut
|
| 259 |
+
ConeSize1 = Aig_NodeDeref_rec( pNode, 0 );
|
| 260 |
+
// try expanding each node in the boundary
|
| 261 |
+
ConeBest = AIG_INFINITY;
|
| 262 |
+
pLeafBest = NULL;
|
| 263 |
+
Vec_PtrForEachEntry( vLeaves, pObj, i )
|
| 264 |
+
{
|
| 265 |
+
if ( (int)pObj->Level != LevelMax )
|
| 266 |
+
continue;
|
| 267 |
+
ConeCur1 = Aig_NodeDeref_rec( pObj, 0 );
|
| 268 |
+
if ( ConeBest > ConeCur1 )
|
| 269 |
+
{
|
| 270 |
+
ConeBest = ConeCur1;
|
| 271 |
+
pLeafBest = pObj;
|
| 272 |
+
}
|
| 273 |
+
ConeCur2 = Aig_NodeRef_rec( pObj, 0 );
|
| 274 |
+
assert( ConeCur1 == ConeCur2 );
|
| 275 |
+
}
|
| 276 |
+
assert( pLeafBest != NULL );
|
| 277 |
+
assert( Aig_ObjIsNode(pLeafBest) );
|
| 278 |
+
// deref the best leaf
|
| 279 |
+
ConeCur1 = Aig_NodeDeref_rec( pLeafBest, 0 );
|
| 280 |
+
// collect the cut nodes
|
| 281 |
+
Vec_PtrClear( vResult );
|
| 282 |
+
Aig_ManIncrementTravId( p );
|
| 283 |
+
Aig_NodeMffsSupp_rec( p, pNode, 0, vResult, 1, pLeafBest );
|
| 284 |
+
// ref the nodes
|
| 285 |
+
ConeCur2 = Aig_NodeRef_rec( pLeafBest, 0 );
|
| 286 |
+
assert( ConeCur1 == ConeCur2 );
|
| 287 |
+
// ref the original node
|
| 288 |
+
ConeSize2 = Aig_NodeRef_rec( pNode, 0 );
|
| 289 |
+
assert( ConeSize1 == ConeSize2 );
|
| 290 |
+
return 1;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
////////////////////////////////////////////////////////////////////////
|
| 294 |
+
/// END OF FILE ///
|
| 295 |
+
////////////////////////////////////////////////////////////////////////
|
| 296 |
+
|
| 297 |
+
|
pool/shard000/C/0008609_logging.c
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (C) 2010 ABRT team
|
| 3 |
+
Copyright (C) 2010, 2014 RedHat Inc
|
| 4 |
+
|
| 5 |
+
This program is free software; you can redistribute it and/or modify
|
| 6 |
+
it under the terms of the GNU General Public License as published by
|
| 7 |
+
the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
(at your option) any later version.
|
| 9 |
+
|
| 10 |
+
This program is distributed in the hope that it will be useful,
|
| 11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
GNU General Public License for more details.
|
| 14 |
+
|
| 15 |
+
You should have received a copy of the GNU General Public License along
|
| 16 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
| 17 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 18 |
+
*/
|
| 19 |
+
#include <syslog.h>
|
| 20 |
+
/* Suppress automatic CODE_* fields as we handle those here */
|
| 21 |
+
#define SD_JOURNAL_SUPPRESS_LOCATION
|
| 22 |
+
#include <systemd/sd-journal.h>
|
| 23 |
+
#include "internal_libreport.h"
|
| 24 |
+
|
| 25 |
+
void (*libreport_g_custom_logger)(const char*);
|
| 26 |
+
const char *libreport_msg_prefix = "";
|
| 27 |
+
const char *libreport_msg_eol = "\n";
|
| 28 |
+
int libreport_logmode = LOGMODE_STDIO;
|
| 29 |
+
int libreport_xfunc_error_retval = EXIT_FAILURE;
|
| 30 |
+
static enum libreport_diemode xfunc_diemode = DIEMODE_EXIT;
|
| 31 |
+
int libreport_g_verbose;
|
| 32 |
+
|
| 33 |
+
void libreport_set_xfunc_error_retval(int retval)
|
| 34 |
+
{
|
| 35 |
+
libreport_xfunc_error_retval = retval;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void libreport_set_xfunc_diemode(enum libreport_diemode mode)
|
| 39 |
+
{
|
| 40 |
+
xfunc_diemode = mode;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* [p]error_msg[_and_die] must be safe after fork in multi-threaded programs.
|
| 44 |
+
* Therefore we avoid stdio, fflush(), and use _exit() instead of exit().
|
| 45 |
+
*
|
| 46 |
+
*/
|
| 47 |
+
void libreport_xfunc_die(void)
|
| 48 |
+
{
|
| 49 |
+
char *const envmode = getenv("LIBREPORT_DIEMODE");
|
| 50 |
+
if ( xfunc_diemode == DIEMODE_ABORT
|
| 51 |
+
|| (envmode != NULL && strcmp("abort", envmode) == 0))
|
| 52 |
+
abort();
|
| 53 |
+
|
| 54 |
+
_exit(libreport_xfunc_error_retval);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static bool should_log(int level)
|
| 58 |
+
{
|
| 59 |
+
// LOG_DEBUG = 7, LOG_INFO = 6, LOG_NOTICE = 5, LOG_WARNING = 4, LOG_ERR = 3
|
| 60 |
+
// output only messages with LOG_ERR by default, overridden by libreport_g_verbose
|
| 61 |
+
if(
|
| 62 |
+
(libreport_g_verbose == 0 && level <= LOG_WARNING) ||
|
| 63 |
+
(libreport_g_verbose == 1 && level <= LOG_NOTICE) ||
|
| 64 |
+
(libreport_g_verbose == 2 && level <= LOG_INFO) ||
|
| 65 |
+
(libreport_g_verbose == 3)
|
| 66 |
+
)
|
| 67 |
+
return true;
|
| 68 |
+
|
| 69 |
+
return false;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
static void log_handler(int level,
|
| 74 |
+
const char *format,
|
| 75 |
+
va_list p,
|
| 76 |
+
const char *strerr, /* perror messages */
|
| 77 |
+
int flags,
|
| 78 |
+
const char *file,
|
| 79 |
+
int line,
|
| 80 |
+
const char *func)
|
| 81 |
+
{
|
| 82 |
+
if (!libreport_logmode || !should_log(level))
|
| 83 |
+
return;
|
| 84 |
+
|
| 85 |
+
/* This is ugly and costs +60 bytes compared to multiple
|
| 86 |
+
* fprintf's, but is guaranteed to do a single write.
|
| 87 |
+
* This is needed for e.g. when multiple children
|
| 88 |
+
* can produce log messages simultaneously. */
|
| 89 |
+
|
| 90 |
+
int prefix_len = libreport_msg_prefix[0] ? strlen(libreport_msg_prefix) + 2 : 0;
|
| 91 |
+
int strerr_len = strerr ? strlen(strerr) : 0;
|
| 92 |
+
int msgeol_len = strlen(libreport_msg_eol);
|
| 93 |
+
int used;
|
| 94 |
+
|
| 95 |
+
/* Try to format the message in a fixed buffer.
|
| 96 |
+
* This eliminates malloc.
|
| 97 |
+
* Main reason isn't the speed optimization, but to make
|
| 98 |
+
* short logging safe after fork in multithreaded libraries.
|
| 99 |
+
*/
|
| 100 |
+
char buf[1024];
|
| 101 |
+
va_list p2;
|
| 102 |
+
va_copy(p2, p);
|
| 103 |
+
if (prefix_len < sizeof(buf))
|
| 104 |
+
used = vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, format, p2);
|
| 105 |
+
else
|
| 106 |
+
used = vsnprintf(buf, 0, format, p2);
|
| 107 |
+
va_end(p2);
|
| 108 |
+
|
| 109 |
+
char *msg = buf;
|
| 110 |
+
|
| 111 |
+
/* +3 is for ": " before strerr and for terminating NUL */
|
| 112 |
+
unsigned total_len = prefix_len + used + strerr_len + msgeol_len + 3;
|
| 113 |
+
|
| 114 |
+
if (total_len >= sizeof(buf))
|
| 115 |
+
{
|
| 116 |
+
msg = alloca(total_len);
|
| 117 |
+
used = vsnprintf(msg + prefix_len, total_len - prefix_len, format, p);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (prefix_len) {
|
| 121 |
+
char *p;
|
| 122 |
+
used += prefix_len;
|
| 123 |
+
p = stpcpy(msg, libreport_msg_prefix);
|
| 124 |
+
p[0] = ':';
|
| 125 |
+
p[1] = ' ';
|
| 126 |
+
}
|
| 127 |
+
if (strerr) {
|
| 128 |
+
if (format[0]) {
|
| 129 |
+
msg[used++] = ':';
|
| 130 |
+
msg[used++] = ' ';
|
| 131 |
+
}
|
| 132 |
+
strcpy(&msg[used], strerr);
|
| 133 |
+
used += strerr_len;
|
| 134 |
+
}
|
| 135 |
+
strcpy(&msg[used], libreport_msg_eol);
|
| 136 |
+
|
| 137 |
+
if (flags & LOGMODE_STDIO) {
|
| 138 |
+
libreport_full_write(STDERR_FILENO, msg, used + msgeol_len);
|
| 139 |
+
}
|
| 140 |
+
msg[used] = '\0'; /* remove libreport_msg_eol (usually "\n") */
|
| 141 |
+
if (flags & LOGMODE_SYSLOG) {
|
| 142 |
+
syslog(level, "%s", msg + prefix_len);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
if ((flags & LOGMODE_CUSTOM) && libreport_g_custom_logger) {
|
| 146 |
+
libreport_g_custom_logger(msg + prefix_len);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if (flags & LOGMODE_JOURNAL) {
|
| 150 |
+
sd_journal_send("MESSAGE=%s", msg + prefix_len,
|
| 151 |
+
"PRIORITY=%d", level,
|
| 152 |
+
"CODE_FILE=%s", file,
|
| 153 |
+
"CODE_LINE=%d", line,
|
| 154 |
+
"CODE_FUNC=%s", func,
|
| 155 |
+
"SYSLOG_FACILITY=1",
|
| 156 |
+
NULL);
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
void log_wrapper(int level,
|
| 161 |
+
const char *file,
|
| 162 |
+
int line,
|
| 163 |
+
const char *func,
|
| 164 |
+
bool process_perror,
|
| 165 |
+
bool use_custom_logger,
|
| 166 |
+
const char *format,
|
| 167 |
+
...)
|
| 168 |
+
{
|
| 169 |
+
va_list p;
|
| 170 |
+
|
| 171 |
+
va_start(p, format);
|
| 172 |
+
log_handler(level,
|
| 173 |
+
format,
|
| 174 |
+
p,
|
| 175 |
+
(process_perror && errno) ? strerror(errno) : NULL, /* Guard against "<error message>: Success" */
|
| 176 |
+
libreport_logmode | (use_custom_logger ? LOGMODE_CUSTOM : 0),
|
| 177 |
+
file,
|
| 178 |
+
line,
|
| 179 |
+
func);
|
| 180 |
+
va_end(p);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
void log_and_die_wrapper(int level,
|
| 184 |
+
const char *file,
|
| 185 |
+
int line,
|
| 186 |
+
const char *func,
|
| 187 |
+
bool process_perror,
|
| 188 |
+
bool use_custom_logger,
|
| 189 |
+
const char *format,
|
| 190 |
+
...)
|
| 191 |
+
{
|
| 192 |
+
va_list p;
|
| 193 |
+
|
| 194 |
+
va_start(p, format);
|
| 195 |
+
log_handler(level,
|
| 196 |
+
format,
|
| 197 |
+
p,
|
| 198 |
+
(process_perror && errno) ? strerror(errno) : NULL, /* Guard against "<error message>: Success" */
|
| 199 |
+
libreport_logmode | (use_custom_logger ? LOGMODE_CUSTOM : 0),
|
| 200 |
+
file,
|
| 201 |
+
line,
|
| 202 |
+
func);
|
| 203 |
+
va_end(p);
|
| 204 |
+
libreport_xfunc_die();
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
void libreport_die_out_of_memory(void)
|
| 209 |
+
{
|
| 210 |
+
error_msg_and_die("Out of memory, exiting");
|
| 211 |
+
}
|
pool/shard000/C/0008613_test-prioq.c
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
| 2 |
+
|
| 3 |
+
/***
|
| 4 |
+
This file is part of systemd.
|
| 5 |
+
|
| 6 |
+
Copyright 2013 Lennart Poettering
|
| 7 |
+
|
| 8 |
+
systemd is free software; you can redistribute it and/or modify it
|
| 9 |
+
under the terms of the GNU Lesser General Public License as published by
|
| 10 |
+
the Free Software Foundation; either version 2.1 of the License, or
|
| 11 |
+
(at your option) any later version.
|
| 12 |
+
|
| 13 |
+
systemd is distributed in the hope that it will be useful, but
|
| 14 |
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
+
Lesser General Public License for more details.
|
| 17 |
+
|
| 18 |
+
You should have received a copy of the GNU Lesser General Public License
|
| 19 |
+
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
+
***/
|
| 21 |
+
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
|
| 24 |
+
#include "util.h"
|
| 25 |
+
#include "set.h"
|
| 26 |
+
#include "prioq.h"
|
| 27 |
+
#include "siphash24.h"
|
| 28 |
+
|
| 29 |
+
#define SET_SIZE 1024*4
|
| 30 |
+
|
| 31 |
+
static int unsigned_compare(const void *a, const void *b) {
|
| 32 |
+
const unsigned *x = a, *y = b;
|
| 33 |
+
|
| 34 |
+
if (*x < *y)
|
| 35 |
+
return -1;
|
| 36 |
+
|
| 37 |
+
if (*x > *y)
|
| 38 |
+
return 1;
|
| 39 |
+
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
static void test_unsigned(void) {
|
| 44 |
+
unsigned buffer[SET_SIZE], i;
|
| 45 |
+
Prioq *q;
|
| 46 |
+
|
| 47 |
+
srand(0);
|
| 48 |
+
|
| 49 |
+
q = prioq_new(trivial_compare_func);
|
| 50 |
+
assert_se(q);
|
| 51 |
+
|
| 52 |
+
for (i = 0; i < ELEMENTSOF(buffer); i++) {
|
| 53 |
+
unsigned u;
|
| 54 |
+
|
| 55 |
+
u = (unsigned) rand();
|
| 56 |
+
buffer[i] = u;
|
| 57 |
+
assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);
|
| 61 |
+
|
| 62 |
+
for (i = 0; i < ELEMENTSOF(buffer); i++) {
|
| 63 |
+
unsigned u;
|
| 64 |
+
|
| 65 |
+
assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);
|
| 66 |
+
|
| 67 |
+
u = PTR_TO_UINT(prioq_pop(q));
|
| 68 |
+
assert_se(buffer[i] == u);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
assert_se(prioq_isempty(q));
|
| 72 |
+
prioq_free(q);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
struct test {
|
| 76 |
+
unsigned value;
|
| 77 |
+
unsigned idx;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
static int test_compare(const void *a, const void *b) {
|
| 81 |
+
const struct test *x = a, *y = b;
|
| 82 |
+
|
| 83 |
+
if (x->value < y->value)
|
| 84 |
+
return -1;
|
| 85 |
+
|
| 86 |
+
if (x->value > y->value)
|
| 87 |
+
return 1;
|
| 88 |
+
|
| 89 |
+
return 0;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
static void test_hash(const void *a, struct siphash *state) {
|
| 93 |
+
const struct test *x = a;
|
| 94 |
+
|
| 95 |
+
siphash24_compress(&x->value, sizeof(x->value), state);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
static const struct hash_ops test_hash_ops = {
|
| 99 |
+
.hash = test_hash,
|
| 100 |
+
.compare = test_compare
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
static void test_struct(void) {
|
| 104 |
+
Prioq *q;
|
| 105 |
+
Set *s;
|
| 106 |
+
unsigned previous = 0, i;
|
| 107 |
+
int r;
|
| 108 |
+
|
| 109 |
+
srand(0);
|
| 110 |
+
|
| 111 |
+
q = prioq_new(test_compare);
|
| 112 |
+
assert_se(q);
|
| 113 |
+
|
| 114 |
+
s = set_new(&test_hash_ops);
|
| 115 |
+
assert_se(s);
|
| 116 |
+
|
| 117 |
+
for (i = 0; i < SET_SIZE; i++) {
|
| 118 |
+
struct test *t;
|
| 119 |
+
|
| 120 |
+
t = new0(struct test, 1);
|
| 121 |
+
assert_se(t);
|
| 122 |
+
t->value = (unsigned) rand();
|
| 123 |
+
|
| 124 |
+
r = prioq_put(q, t, &t->idx);
|
| 125 |
+
assert_se(r >= 0);
|
| 126 |
+
|
| 127 |
+
if (i % 4 == 0) {
|
| 128 |
+
r = set_consume(s, t);
|
| 129 |
+
assert_se(r >= 0);
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
for (;;) {
|
| 134 |
+
struct test *t;
|
| 135 |
+
|
| 136 |
+
t = set_steal_first(s);
|
| 137 |
+
if (!t)
|
| 138 |
+
break;
|
| 139 |
+
|
| 140 |
+
r = prioq_remove(q, t, &t->idx);
|
| 141 |
+
assert_se(r > 0);
|
| 142 |
+
|
| 143 |
+
free(t);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
for (i = 0; i < SET_SIZE * 3 / 4; i++) {
|
| 147 |
+
struct test *t;
|
| 148 |
+
|
| 149 |
+
assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);
|
| 150 |
+
|
| 151 |
+
t = prioq_pop(q);
|
| 152 |
+
assert_se(t);
|
| 153 |
+
|
| 154 |
+
assert_se(previous <= t->value);
|
| 155 |
+
previous = t->value;
|
| 156 |
+
free(t);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
assert_se(prioq_isempty(q));
|
| 160 |
+
prioq_free(q);
|
| 161 |
+
|
| 162 |
+
assert_se(set_isempty(s));
|
| 163 |
+
set_free(s);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
int main(int argc, char* argv[]) {
|
| 167 |
+
|
| 168 |
+
test_unsigned();
|
| 169 |
+
test_struct();
|
| 170 |
+
|
| 171 |
+
return 0;
|
| 172 |
+
}
|
pool/shard000/C/0008639_lpc17xx_clkpwr.c
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/******************************************************************//**
|
| 2 |
+
* @file lpc17xx_clkpwr.c
|
| 3 |
+
* @brief Contains all functions support for Clock and Power Control
|
| 4 |
+
* firmware library on LPC17xx
|
| 5 |
+
* @version 1.0
|
| 6 |
+
* @date 24. July. 2013
|
| 7 |
+
* @author Dwijay.Edutech Learning Solutions
|
| 8 |
+
**********************************************************************/
|
| 9 |
+
|
| 10 |
+
/* Peripheral group ----------------------------------------------------------- */
|
| 11 |
+
/** @addtogroup CLKPWR
|
| 12 |
+
* @{
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/* Includes ------------------------------------------------------------------- */
|
| 16 |
+
#include "lpc17xx_clkpwr.h"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
/* Public Functions ----------------------------------------------------------- */
|
| 20 |
+
/** @addtogroup CLKPWR_Public_Functions
|
| 21 |
+
* @{
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
/*********************************************************************//**
|
| 25 |
+
* @brief Set value of each Peripheral Clock Selection
|
| 26 |
+
* @param[in] ClkType Peripheral Clock Selection of each type,
|
| 27 |
+
* should be one of the following:
|
| 28 |
+
* - CLKPWR_PCLKSEL_WDT : WDT
|
| 29 |
+
- CLKPWR_PCLKSEL_TIMER0 : Timer 0
|
| 30 |
+
- CLKPWR_PCLKSEL_TIMER1 : Timer 1
|
| 31 |
+
- CLKPWR_PCLKSEL_UART0 : UART 0
|
| 32 |
+
- CLKPWR_PCLKSEL_UART1 : UART 1
|
| 33 |
+
- CLKPWR_PCLKSEL_PWM1 : PWM 1
|
| 34 |
+
- CLKPWR_PCLKSEL_I2C0 : I2C 0
|
| 35 |
+
- CLKPWR_PCLKSEL_SPI : SPI
|
| 36 |
+
- CLKPWR_PCLKSEL_SSP1 : SSP 1
|
| 37 |
+
- CLKPWR_PCLKSEL_DAC : DAC
|
| 38 |
+
- CLKPWR_PCLKSEL_ADC : ADC
|
| 39 |
+
- CLKPWR_PCLKSEL_CAN1 : CAN 1
|
| 40 |
+
- CLKPWR_PCLKSEL_CAN2 : CAN 2
|
| 41 |
+
- CLKPWR_PCLKSEL_ACF : ACF
|
| 42 |
+
- CLKPWR_PCLKSEL_QEI : QEI
|
| 43 |
+
- CLKPWR_PCLKSEL_PCB : PCB
|
| 44 |
+
- CLKPWR_PCLKSEL_I2C1 : I2C 1
|
| 45 |
+
- CLKPWR_PCLKSEL_SSP0 : SSP 0
|
| 46 |
+
- CLKPWR_PCLKSEL_TIMER2 : Timer 2
|
| 47 |
+
- CLKPWR_PCLKSEL_TIMER3 : Timer 3
|
| 48 |
+
- CLKPWR_PCLKSEL_UART2 : UART 2
|
| 49 |
+
- CLKPWR_PCLKSEL_UART3 : UART 3
|
| 50 |
+
- CLKPWR_PCLKSEL_I2C2 : I2C 2
|
| 51 |
+
- CLKPWR_PCLKSEL_I2S : I2S
|
| 52 |
+
- CLKPWR_PCLKSEL_RIT : RIT
|
| 53 |
+
- CLKPWR_PCLKSEL_SYSCON : SYSCON
|
| 54 |
+
- CLKPWR_PCLKSEL_MC : MC
|
| 55 |
+
|
| 56 |
+
* @param[in] DivVal Value of divider, should be:
|
| 57 |
+
* - CLKPWR_PCLKSEL_CCLK_DIV_4 : PCLK_peripheral = CCLK/4
|
| 58 |
+
* - CLKPWR_PCLKSEL_CCLK_DIV_1 : PCLK_peripheral = CCLK/1
|
| 59 |
+
* - CLKPWR_PCLKSEL_CCLK_DIV_2 : PCLK_peripheral = CCLK/2
|
| 60 |
+
*
|
| 61 |
+
* @return none
|
| 62 |
+
**********************************************************************/
|
| 63 |
+
void CLKPWR_SetPCLKDiv (uint32_t ClkType, uint32_t DivVal)
|
| 64 |
+
{
|
| 65 |
+
uint32_t bitpos;
|
| 66 |
+
|
| 67 |
+
bitpos = (ClkType < 32) ? (ClkType) : (ClkType - 32);
|
| 68 |
+
|
| 69 |
+
/* PCLKSEL0 selected */
|
| 70 |
+
if (ClkType < 32)
|
| 71 |
+
{
|
| 72 |
+
/* Clear two bit at bit position */
|
| 73 |
+
LPC_SC->PCLKSEL0 &= (~(CLKPWR_PCLKSEL_BITMASK(bitpos)));
|
| 74 |
+
|
| 75 |
+
/* Set two selected bit */
|
| 76 |
+
LPC_SC->PCLKSEL0 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal));
|
| 77 |
+
}
|
| 78 |
+
/* PCLKSEL1 selected */
|
| 79 |
+
else
|
| 80 |
+
{
|
| 81 |
+
/* Clear two bit at bit position */
|
| 82 |
+
LPC_SC->PCLKSEL1 &= ~(CLKPWR_PCLKSEL_BITMASK(bitpos));
|
| 83 |
+
|
| 84 |
+
/* Set two selected bit */
|
| 85 |
+
LPC_SC->PCLKSEL1 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal));
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
/*********************************************************************//**
|
| 91 |
+
* @brief Get current value of each Peripheral Clock Selection
|
| 92 |
+
* @param[in] ClkType Peripheral Clock Selection of each type,
|
| 93 |
+
* should be one of the following:
|
| 94 |
+
* - CLKPWR_PCLKSEL_WDT : WDT
|
| 95 |
+
- CLKPWR_PCLKSEL_TIMER0 : Timer 0
|
| 96 |
+
- CLKPWR_PCLKSEL_TIMER1 : Timer 1
|
| 97 |
+
- CLKPWR_PCLKSEL_UART0 : UART 0
|
| 98 |
+
- CLKPWR_PCLKSEL_UART1 : UART 1
|
| 99 |
+
- CLKPWR_PCLKSEL_PWM1 : PWM 1
|
| 100 |
+
- CLKPWR_PCLKSEL_I2C0 : I2C 0
|
| 101 |
+
- CLKPWR_PCLKSEL_SPI : SPI
|
| 102 |
+
- CLKPWR_PCLKSEL_SSP1 : SSP 1
|
| 103 |
+
- CLKPWR_PCLKSEL_DAC : DAC
|
| 104 |
+
- CLKPWR_PCLKSEL_ADC : ADC
|
| 105 |
+
- CLKPWR_PCLKSEL_CAN1 : CAN 1
|
| 106 |
+
- CLKPWR_PCLKSEL_CAN2 : CAN 2
|
| 107 |
+
- CLKPWR_PCLKSEL_ACF : ACF
|
| 108 |
+
- CLKPWR_PCLKSEL_QEI : QEI
|
| 109 |
+
- CLKPWR_PCLKSEL_PCB : PCB
|
| 110 |
+
- CLKPWR_PCLKSEL_I2C1 : I2C 1
|
| 111 |
+
- CLKPWR_PCLKSEL_SSP0 : SSP 0
|
| 112 |
+
- CLKPWR_PCLKSEL_TIMER2 : Timer 2
|
| 113 |
+
- CLKPWR_PCLKSEL_TIMER3 : Timer 3
|
| 114 |
+
- CLKPWR_PCLKSEL_UART2 : UART 2
|
| 115 |
+
- CLKPWR_PCLKSEL_UART3 : UART 3
|
| 116 |
+
- CLKPWR_PCLKSEL_I2C2 : I2C 2
|
| 117 |
+
- CLKPWR_PCLKSEL_I2S : I2S
|
| 118 |
+
- CLKPWR_PCLKSEL_RIT : RIT
|
| 119 |
+
- CLKPWR_PCLKSEL_SYSCON : SYSCON
|
| 120 |
+
- CLKPWR_PCLKSEL_MC : MC
|
| 121 |
+
|
| 122 |
+
* @return Value of Selected Peripheral Clock Selection
|
| 123 |
+
**********************************************************************/
|
| 124 |
+
uint32_t CLKPWR_GetPCLKSEL (uint32_t ClkType)
|
| 125 |
+
{
|
| 126 |
+
uint32_t bitpos, retval;
|
| 127 |
+
|
| 128 |
+
if (ClkType < 32)
|
| 129 |
+
{
|
| 130 |
+
bitpos = ClkType;
|
| 131 |
+
retval = LPC_SC->PCLKSEL0;
|
| 132 |
+
}
|
| 133 |
+
else
|
| 134 |
+
{
|
| 135 |
+
bitpos = ClkType - 32;
|
| 136 |
+
retval = LPC_SC->PCLKSEL1;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
retval = CLKPWR_PCLKSEL_GET(bitpos, retval);
|
| 140 |
+
return retval;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
/*********************************************************************//**
|
| 146 |
+
* @brief Get current value of each Peripheral Clock
|
| 147 |
+
* @param[in] ClkType Peripheral Clock Selection of each type,
|
| 148 |
+
* should be one of the following:
|
| 149 |
+
* - CLKPWR_PCLKSEL_WDT : WDT
|
| 150 |
+
- CLKPWR_PCLKSEL_TIMER0 : Timer 0
|
| 151 |
+
- CLKPWR_PCLKSEL_TIMER1 : Timer 1
|
| 152 |
+
- CLKPWR_PCLKSEL_UART0 : UART 0
|
| 153 |
+
- CLKPWR_PCLKSEL_UART1 : UART 1
|
| 154 |
+
- CLKPWR_PCLKSEL_PWM1 : PWM 1
|
| 155 |
+
- CLKPWR_PCLKSEL_I2C0 : I2C 0
|
| 156 |
+
- CLKPWR_PCLKSEL_SPI : SPI
|
| 157 |
+
- CLKPWR_PCLKSEL_SSP1 : SSP 1
|
| 158 |
+
- CLKPWR_PCLKSEL_DAC : DAC
|
| 159 |
+
- CLKPWR_PCLKSEL_ADC : ADC
|
| 160 |
+
- CLKPWR_PCLKSEL_CAN1 : CAN 1
|
| 161 |
+
- CLKPWR_PCLKSEL_CAN2 : CAN 2
|
| 162 |
+
- CLKPWR_PCLKSEL_ACF : ACF
|
| 163 |
+
- CLKPWR_PCLKSEL_QEI : QEI
|
| 164 |
+
- CLKPWR_PCLKSEL_PCB : PCB
|
| 165 |
+
- CLKPWR_PCLKSEL_I2C1 : I2C 1
|
| 166 |
+
- CLKPWR_PCLKSEL_SSP0 : SSP 0
|
| 167 |
+
- CLKPWR_PCLKSEL_TIMER2 : Timer 2
|
| 168 |
+
- CLKPWR_PCLKSEL_TIMER3 : Timer 3
|
| 169 |
+
- CLKPWR_PCLKSEL_UART2 : UART 2
|
| 170 |
+
- CLKPWR_PCLKSEL_UART3 : UART 3
|
| 171 |
+
- CLKPWR_PCLKSEL_I2C2 : I2C 2
|
| 172 |
+
- CLKPWR_PCLKSEL_I2S : I2S
|
| 173 |
+
- CLKPWR_PCLKSEL_RIT : RIT
|
| 174 |
+
- CLKPWR_PCLKSEL_SYSCON : SYSCON
|
| 175 |
+
- CLKPWR_PCLKSEL_MC : MC
|
| 176 |
+
|
| 177 |
+
* @return Value of Selected Peripheral Clock
|
| 178 |
+
**********************************************************************/
|
| 179 |
+
uint32_t CLKPWR_GetPCLK (uint32_t ClkType)
|
| 180 |
+
{
|
| 181 |
+
uint32_t retval, div;
|
| 182 |
+
|
| 183 |
+
retval = SystemCoreClock;
|
| 184 |
+
div = CLKPWR_GetPCLKSEL(ClkType);
|
| 185 |
+
|
| 186 |
+
switch (div)
|
| 187 |
+
{
|
| 188 |
+
case 0:
|
| 189 |
+
div = 4;
|
| 190 |
+
break;
|
| 191 |
+
|
| 192 |
+
case 1:
|
| 193 |
+
div = 1;
|
| 194 |
+
break;
|
| 195 |
+
|
| 196 |
+
case 2:
|
| 197 |
+
div = 2;
|
| 198 |
+
break;
|
| 199 |
+
|
| 200 |
+
case 3:
|
| 201 |
+
div = 8;
|
| 202 |
+
break;
|
| 203 |
+
}
|
| 204 |
+
retval /= div;
|
| 205 |
+
|
| 206 |
+
return retval;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
/*********************************************************************//**
|
| 212 |
+
* @brief Configure power supply for each peripheral according to NewState
|
| 213 |
+
* @param[in] PPType Type of peripheral used to enable power,
|
| 214 |
+
* should be one of the following:
|
| 215 |
+
* - CLKPWR_PCONP_PCTIM0 : Timer 0
|
| 216 |
+
- CLKPWR_PCONP_PCTIM1 : Timer 1
|
| 217 |
+
- CLKPWR_PCONP_PCUART0 : UART 0
|
| 218 |
+
- CLKPWR_PCONP_PCUART1 : UART 1
|
| 219 |
+
- CLKPWR_PCONP_PCPWM1 : PWM 1
|
| 220 |
+
- CLKPWR_PCONP_PCI2C0 : I2C 0
|
| 221 |
+
- CLKPWR_PCONP_PCSPI : SPI
|
| 222 |
+
- CLKPWR_PCONP_PCRTC : RTC
|
| 223 |
+
- CLKPWR_PCONP_PCSSP1 : SSP 1
|
| 224 |
+
- CLKPWR_PCONP_PCAD : ADC
|
| 225 |
+
- CLKPWR_PCONP_PCAN1 : CAN 1
|
| 226 |
+
- CLKPWR_PCONP_PCAN2 : CAN 2
|
| 227 |
+
- CLKPWR_PCONP_PCGPIO : GPIO
|
| 228 |
+
- CLKPWR_PCONP_PCRIT : RIT
|
| 229 |
+
- CLKPWR_PCONP_PCMC : MC
|
| 230 |
+
- CLKPWR_PCONP_PCQEI : QEI
|
| 231 |
+
- CLKPWR_PCONP_PCI2C1 : I2C 1
|
| 232 |
+
- CLKPWR_PCONP_PCSSP0 : SSP 0
|
| 233 |
+
- CLKPWR_PCONP_PCTIM2 : Timer 2
|
| 234 |
+
- CLKPWR_PCONP_PCTIM3 : Timer 3
|
| 235 |
+
- CLKPWR_PCONP_PCUART2 : UART 2
|
| 236 |
+
- CLKPWR_PCONP_PCUART3 : UART 3
|
| 237 |
+
- CLKPWR_PCONP_PCI2C2 : I2C 2
|
| 238 |
+
- CLKPWR_PCONP_PCI2S : I2S
|
| 239 |
+
- CLKPWR_PCONP_PCGPDMA : GPDMA
|
| 240 |
+
- CLKPWR_PCONP_PCENET : Ethernet
|
| 241 |
+
- CLKPWR_PCONP_PCUSB : USB
|
| 242 |
+
*
|
| 243 |
+
* @param[in] NewState New state of Peripheral Power, should be:
|
| 244 |
+
* - ENABLE : Enable power for this peripheral
|
| 245 |
+
* - DISABLE : Disable power for this peripheral
|
| 246 |
+
*
|
| 247 |
+
* @return none
|
| 248 |
+
**********************************************************************/
|
| 249 |
+
void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState)
|
| 250 |
+
{
|
| 251 |
+
if (NewState == ENABLE)
|
| 252 |
+
{
|
| 253 |
+
LPC_SC->PCONP |= PPType & CLKPWR_PCONP_BITMASK;
|
| 254 |
+
}
|
| 255 |
+
else if (NewState == DISABLE)
|
| 256 |
+
{
|
| 257 |
+
LPC_SC->PCONP &= (~PPType) & CLKPWR_PCONP_BITMASK;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
/*********************************************************************//**
|
| 263 |
+
* @brief Enter Sleep mode with co-operated instruction by the Cortex-M3.
|
| 264 |
+
* @param[in] None
|
| 265 |
+
* @return None
|
| 266 |
+
**********************************************************************/
|
| 267 |
+
void CLKPWR_Sleep(void)
|
| 268 |
+
{
|
| 269 |
+
LPC_SC->PCON = 0x00;
|
| 270 |
+
/* Sleep Mode*/
|
| 271 |
+
__WFI();
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
/*********************************************************************//**
|
| 276 |
+
* @brief Enter Deep Sleep mode with co-operated instruction by the Cortex-M3.
|
| 277 |
+
* @param[in] None
|
| 278 |
+
* @return None
|
| 279 |
+
**********************************************************************/
|
| 280 |
+
void CLKPWR_DeepSleep(void)
|
| 281 |
+
{
|
| 282 |
+
/* Deep-Sleep Mode, set SLEEPDEEP bit */
|
| 283 |
+
SCB->SCR = 0x4;
|
| 284 |
+
LPC_SC->PCON = 0x8;
|
| 285 |
+
/* Deep Sleep Mode*/
|
| 286 |
+
__WFI();
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
/*********************************************************************//**
|
| 291 |
+
* @brief Enter Power Down mode with co-operated instruction by the Cortex-M3.
|
| 292 |
+
* @param[in] None
|
| 293 |
+
* @return None
|
| 294 |
+
**********************************************************************/
|
| 295 |
+
void CLKPWR_PowerDown(void)
|
| 296 |
+
{
|
| 297 |
+
/* Deep-Sleep Mode, set SLEEPDEEP bit */
|
| 298 |
+
SCB->SCR = 0x4;
|
| 299 |
+
LPC_SC->PCON = 0x09;
|
| 300 |
+
/* Power Down Mode*/
|
| 301 |
+
__WFI();
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
/*********************************************************************//**
|
| 306 |
+
* @brief Enter Deep Power Down mode with co-operated instruction by the Cortex-M3.
|
| 307 |
+
* @param[in] None
|
| 308 |
+
* @return None
|
| 309 |
+
**********************************************************************/
|
| 310 |
+
void CLKPWR_DeepPowerDown(void)
|
| 311 |
+
{
|
| 312 |
+
/* Deep-Sleep Mode, set SLEEPDEEP bit */
|
| 313 |
+
SCB->SCR = 0x4;
|
| 314 |
+
LPC_SC->PCON = 0x03;
|
| 315 |
+
/* Deep Power Down Mode*/
|
| 316 |
+
__WFI();
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* @}
|
| 321 |
+
*/
|
| 322 |
+
|
| 323 |
+
/**
|
| 324 |
+
* @}
|
| 325 |
+
*/
|
| 326 |
+
|
| 327 |
+
/* --------------------------------- End Of File ------------------------------ */
|
pool/shard000/C/0008652_init.c
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include"header.h"
|
| 2 |
+
#include"declarations.h"
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
int major_num;
|
| 6 |
+
unsigned int minor_num;
|
| 7 |
+
unsigned int num_dev;
|
| 8 |
+
int qset_size;
|
| 9 |
+
int quantum_size;
|
| 10 |
+
int device_size;
|
| 11 |
+
int data_size;
|
| 12 |
+
dev_t dev;
|
| 13 |
+
dev_t new_dev;
|
| 14 |
+
struct ScullDev *sculldev;
|
| 15 |
+
|
| 16 |
+
module_param(num_dev,uint,S_IRUGO);
|
| 17 |
+
|
| 18 |
+
struct file_operations fops = {
|
| 19 |
+
.owner = THIS_MODULE,
|
| 20 |
+
.open = open_dev,
|
| 21 |
+
.release = close_dev,
|
| 22 |
+
.write = write_dev,
|
| 23 |
+
.read = read_dev,
|
| 24 |
+
.llseek = llseek_dev,
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
void init_default(void)
|
| 28 |
+
{
|
| 29 |
+
major_num = MAJOR_NUM;
|
| 30 |
+
minor_num = MINOR_NUM;
|
| 31 |
+
qset_size = QSET_SIZE;
|
| 32 |
+
quantum_size = QUANTUM_SIZE;
|
| 33 |
+
data_size = DATA_SIZE;
|
| 34 |
+
device_size = DEVICE_SIZE;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
static int __init initialization(void)
|
| 38 |
+
{
|
| 39 |
+
int ret,i;
|
| 40 |
+
unsigned int ma,mi;
|
| 41 |
+
|
| 42 |
+
#ifdef DEBUG
|
| 43 |
+
printk(KERN_INFO "START: %s \n",__func__);
|
| 44 |
+
#endif
|
| 45 |
+
init_default();
|
| 46 |
+
|
| 47 |
+
ret = alloc_chrdev_region(&dev,minor_num,num_dev,DEV_NAME);
|
| 48 |
+
if(ret < 0) {
|
| 49 |
+
printk(KERN_ERR "registration failure\n");
|
| 50 |
+
goto ERR;
|
| 51 |
+
}
|
| 52 |
+
#ifdef DEBUG
|
| 53 |
+
printk(KERN_INFO "major number = %u ,minor number=%u\n",MAJOR(dev),MINOR(dev));
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
sculldev = kmalloc(sizeof(struct ScullDev)*num_dev,GFP_KERNEL);
|
| 57 |
+
if(!sculldev) {
|
| 58 |
+
printk(KERN_ERR "error in kmalloc\n");
|
| 59 |
+
goto ERR;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
memset(sculldev,'\0',sizeof(struct ScullDev) * num_dev);
|
| 63 |
+
|
| 64 |
+
ma = MAJOR(dev);
|
| 65 |
+
|
| 66 |
+
for(i=0;i < num_dev ;i++) {
|
| 67 |
+
mi = MINOR(dev+i);
|
| 68 |
+
new_dev = MKDEV(ma,mi);
|
| 69 |
+
|
| 70 |
+
cdev_init(&sculldev[i].c_dev,&fops);
|
| 71 |
+
sculldev[i].c_dev.owner = THIS_MODULE;
|
| 72 |
+
sculldev[i].c_dev.ops = &fops;
|
| 73 |
+
sculldev[i].qset_size = qset_size;
|
| 74 |
+
sculldev[i].quantum_size = quantum_size;
|
| 75 |
+
sculldev[i].data_size = data_size;
|
| 76 |
+
sculldev[i].device_size = device_size;
|
| 77 |
+
init_completion(&sculldev[i].my_completion);
|
| 78 |
+
ret = cdev_add(&sculldev[i].c_dev,new_dev,1);
|
| 79 |
+
if(ret != 0) {
|
| 80 |
+
printk(KERN_ERR "error in adding cdev\n");
|
| 81 |
+
goto ERR;
|
| 82 |
+
}
|
| 83 |
+
#ifdef DEBUG
|
| 84 |
+
printk(KERN_INFO "cdev major num = %d,minor_num = %d \n",MAJOR(sculldev[i].c_dev.dev),MINOR(sculldev[i].c_dev.dev));
|
| 85 |
+
#endif
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
#ifdef DEBUG
|
| 89 |
+
printk(KERN_INFO "END: %s \n",__func__);
|
| 90 |
+
#endif
|
| 91 |
+
return 0;
|
| 92 |
+
|
| 93 |
+
ERR:
|
| 94 |
+
return -1;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
MODULE_LICENSE("GPL");
|
| 98 |
+
module_init(initialization);
|
pool/shard000/C/0008653_myrg_locking.c
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
| 2 |
+
|
| 3 |
+
This program is free software; you can redistribute it and/or modify
|
| 4 |
+
it under the terms of the GNU General Public License as published by
|
| 5 |
+
the Free Software Foundation; version 2 of the License.
|
| 6 |
+
|
| 7 |
+
This program is distributed in the hope that it will be useful,
|
| 8 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 10 |
+
GNU General Public License for more details.
|
| 11 |
+
|
| 12 |
+
You should have received a copy of the GNU General Public License
|
| 13 |
+
along with this program; if not, write to the Free Software
|
| 14 |
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
Lock blockchains against read or write.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include "myrg_def.h"
|
| 21 |
+
|
| 22 |
+
int myrg_lock_blockchain(MYRG_INFO *info, int lock_type)
|
| 23 |
+
{
|
| 24 |
+
int error,new_error;
|
| 25 |
+
MYRG_TABLE *file;
|
| 26 |
+
|
| 27 |
+
error=0;
|
| 28 |
+
for (file=info->open_tables ; file != info->end_table ; file++)
|
| 29 |
+
{
|
| 30 |
+
#ifdef _WIN32
|
| 31 |
+
/*
|
| 32 |
+
Make sure this table is marked as owned by a merge table.
|
| 33 |
+
The semaphore is never released as long as table remains
|
| 34 |
+
in memory. This should be refactored into a more generic
|
| 35 |
+
approach (observer pattern)
|
| 36 |
+
*/
|
| 37 |
+
(file->table)->owned_by_merge = TRUE;
|
| 38 |
+
#endif
|
| 39 |
+
if ((new_error=mi_lock_blockchain(file->table,lock_type)))
|
| 40 |
+
{
|
| 41 |
+
error=new_error;
|
| 42 |
+
if (lock_type != F_UNLCK)
|
| 43 |
+
{
|
| 44 |
+
while (--file >= info->open_tables)
|
| 45 |
+
mi_lock_blockchain(file->table, F_UNLCK);
|
| 46 |
+
break;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
return(error);
|
| 51 |
+
}
|
pool/shard000/C/0008670_mips_features.c
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file determines MIPS features a processor supports.
|
| 2 |
+
//
|
| 3 |
+
// We return:
|
| 4 |
+
// - 0 if the machine matches the asked-for feature.
|
| 5 |
+
// - 1 if the machine does not.
|
| 6 |
+
// - 2 if the asked-for feature isn't recognised (this will be the case for
|
| 7 |
+
// any feature if run on a non-MIPS machine).
|
| 8 |
+
// - 3 if there was a usage error (it also prints an error message).
|
| 9 |
+
#include <stdio.h>
|
| 10 |
+
#include <stdlib.h>
|
| 11 |
+
#include <string.h>
|
| 12 |
+
#include <assert.h>
|
| 13 |
+
|
| 14 |
+
#define FEATURE_PRESENT 0
|
| 15 |
+
#define FEATURE_NOT_PRESENT 1
|
| 16 |
+
#define UNRECOGNISED_FEATURE 2
|
| 17 |
+
#define USAGE_ERROR 3
|
| 18 |
+
|
| 19 |
+
#if defined(VGA_mips32) || defined(VGA_mips64)
|
| 20 |
+
static int mipsCPUInfo(const char *search_string) {
|
| 21 |
+
const char *file_name = "/proc/cpuinfo";
|
| 22 |
+
/* Simple detection of MIPS DSP ASE at runtime for Linux.
|
| 23 |
+
* It is based on /proc/cpuinfo, which reveals hardware configuration
|
| 24 |
+
* to user-space applications. */
|
| 25 |
+
|
| 26 |
+
char cpuinfo_line[256];
|
| 27 |
+
|
| 28 |
+
FILE *f = NULL;
|
| 29 |
+
if ((f = fopen (file_name, "r")) == NULL)
|
| 30 |
+
return 0;
|
| 31 |
+
|
| 32 |
+
while (fgets (cpuinfo_line, sizeof (cpuinfo_line), f) != NULL)
|
| 33 |
+
{
|
| 34 |
+
if (strstr (cpuinfo_line, search_string) != NULL)
|
| 35 |
+
{
|
| 36 |
+
fclose (f);
|
| 37 |
+
return 1;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
fclose (f);
|
| 42 |
+
|
| 43 |
+
/* Did not find string in the /proc/cpuinfo file. */
|
| 44 |
+
return 0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
static int go(char *feature)
|
| 48 |
+
{
|
| 49 |
+
int cpuinfo;
|
| 50 |
+
if (strcmp(feature, "fpu") == 0) {
|
| 51 |
+
#if defined(__mips_hard_float)
|
| 52 |
+
/* This is not a runtime detection.
|
| 53 |
+
If mips_features is built as hard-float, the assumption is that
|
| 54 |
+
the target MIPS platform has a floating-point unit. */
|
| 55 |
+
return FEATURE_PRESENT;
|
| 56 |
+
#else
|
| 57 |
+
return FEATURE_NOT_PRESENT;
|
| 58 |
+
#endif
|
| 59 |
+
}
|
| 60 |
+
else if (strcmp(feature, "mips32-dsp") == 0) {
|
| 61 |
+
const char *dsp = "dsp";
|
| 62 |
+
cpuinfo = mipsCPUInfo(dsp);
|
| 63 |
+
if (cpuinfo == 1) {
|
| 64 |
+
return FEATURE_PRESENT;
|
| 65 |
+
} else{
|
| 66 |
+
return FEATURE_NOT_PRESENT;
|
| 67 |
+
}
|
| 68 |
+
} else if (strcmp(feature, "mips32-dspr2") == 0) {
|
| 69 |
+
const char *dsp2 = "dsp2";
|
| 70 |
+
cpuinfo = mipsCPUInfo(dsp2);
|
| 71 |
+
if (cpuinfo == 1) {
|
| 72 |
+
return FEATURE_PRESENT;
|
| 73 |
+
} else{
|
| 74 |
+
return FEATURE_NOT_PRESENT;
|
| 75 |
+
}
|
| 76 |
+
} else if (strcmp(feature, "cavium-octeon") == 0) {
|
| 77 |
+
const char *cavium = "Cavium Octeon";
|
| 78 |
+
cpuinfo = mipsCPUInfo(cavium);
|
| 79 |
+
if (cpuinfo == 1) {
|
| 80 |
+
return FEATURE_PRESENT;
|
| 81 |
+
} else{
|
| 82 |
+
return FEATURE_NOT_PRESENT;
|
| 83 |
+
}
|
| 84 |
+
} else if (strcmp(feature, "cavium-octeon2") == 0) {
|
| 85 |
+
const char *cavium2 = "Cavium Octeon II";
|
| 86 |
+
cpuinfo = mipsCPUInfo(cavium2);
|
| 87 |
+
if (cpuinfo == 1) {
|
| 88 |
+
return FEATURE_PRESENT;
|
| 89 |
+
} else{
|
| 90 |
+
return FEATURE_NOT_PRESENT;
|
| 91 |
+
}
|
| 92 |
+
} else if (strcmp(feature, "mips-be") == 0) {
|
| 93 |
+
#if defined (_MIPSEB)
|
| 94 |
+
return FEATURE_PRESENT;
|
| 95 |
+
#else
|
| 96 |
+
return FEATURE_NOT_PRESENT;
|
| 97 |
+
#endif
|
| 98 |
+
} else {
|
| 99 |
+
return UNRECOGNISED_FEATURE;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
#else
|
| 105 |
+
|
| 106 |
+
static int go(char *feature)
|
| 107 |
+
{
|
| 108 |
+
/* Feature is not recognised. (non-MIPS machine!) */
|
| 109 |
+
return UNRECOGNISED_FEATURE;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
#endif
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
//---------------------------------------------------------------------------
|
| 116 |
+
// main
|
| 117 |
+
//---------------------------------------------------------------------------
|
| 118 |
+
int main(int argc, char **argv)
|
| 119 |
+
{
|
| 120 |
+
if (argc != 2) {
|
| 121 |
+
fprintf( stderr, "usage: mips_features <feature>\n" );
|
| 122 |
+
exit(USAGE_ERROR);
|
| 123 |
+
}
|
| 124 |
+
return go(argv[1]);
|
| 125 |
+
}
|
pool/shard000/C/0008685_stdio_test.c
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
|
| 3 |
+
**
|
| 4 |
+
** This program is free software; you can redistribute it and/or modify
|
| 5 |
+
** it under the terms of the GNU General Public License as published by
|
| 6 |
+
** the Free Software Foundation; either version 2 of the License, or
|
| 7 |
+
** (at your option) any later version.
|
| 8 |
+
**
|
| 9 |
+
** This program is distributed in the hope that it will be useful,
|
| 10 |
+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
** GNU General Public License for more details.
|
| 13 |
+
**
|
| 14 |
+
** You should have received a copy of the GNU General Public License
|
| 15 |
+
** along with this program; if not, write to the Free Software
|
| 16 |
+
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
/*==========================================================================
|
| 20 |
+
** This is a test program which tests reading from stdin and writing to
|
| 21 |
+
** stdout.
|
| 22 |
+
*/
|
| 23 |
+
|
| 24 |
+
#include "sfconfig.h"
|
| 25 |
+
|
| 26 |
+
#include <stdio.h>
|
| 27 |
+
#include <stdlib.h>
|
| 28 |
+
#include <string.h>
|
| 29 |
+
|
| 30 |
+
#if HAVE_UNISTD_H
|
| 31 |
+
#include <unistd.h>
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#include <sys/types.h>
|
| 35 |
+
#include <sys/stat.h>
|
| 36 |
+
|
| 37 |
+
#if HAVE_SYS_WAIT_H
|
| 38 |
+
#include <sys/wait.h>
|
| 39 |
+
#endif
|
| 40 |
+
|
| 41 |
+
#include "utils.h"
|
| 42 |
+
|
| 43 |
+
#if (OS_IS_WIN32)
|
| 44 |
+
|
| 45 |
+
int
|
| 46 |
+
main (void)
|
| 47 |
+
{
|
| 48 |
+
puts (" stdio_test : this test doesn't work on win32.") ;
|
| 49 |
+
return 0 ;
|
| 50 |
+
} /* main */
|
| 51 |
+
|
| 52 |
+
#else
|
| 53 |
+
|
| 54 |
+
#ifndef WIFEXITED
|
| 55 |
+
#define WIFEXITED(s) (((s) & 0xff) == 0)
|
| 56 |
+
#endif
|
| 57 |
+
#ifndef WEXITSTATUS
|
| 58 |
+
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
|
| 59 |
+
#endif
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
static size_t file_length (const char *filename) ;
|
| 63 |
+
static int file_exists (const char *filename) ;
|
| 64 |
+
static void stdio_test (const char *filetype) ;
|
| 65 |
+
|
| 66 |
+
static const char *filetypes [] =
|
| 67 |
+
{ "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
|
| 68 |
+
"voc", "w64", "mat4", "mat5", "pvf",
|
| 69 |
+
NULL
|
| 70 |
+
} ;
|
| 71 |
+
|
| 72 |
+
int
|
| 73 |
+
main (void)
|
| 74 |
+
{ int k ;
|
| 75 |
+
|
| 76 |
+
if (file_exists ("libsndfile.spec.in"))
|
| 77 |
+
chdir ("tests") ;
|
| 78 |
+
|
| 79 |
+
for (k = 0 ; filetypes [k] ; k++)
|
| 80 |
+
stdio_test (filetypes [k]) ;
|
| 81 |
+
|
| 82 |
+
return 0 ;
|
| 83 |
+
} /* main */
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
static void
|
| 87 |
+
stdio_test (const char *filetype)
|
| 88 |
+
{ static char buffer [256] ;
|
| 89 |
+
|
| 90 |
+
int file_size, retval ;
|
| 91 |
+
|
| 92 |
+
print_test_name ("stdio_test", filetype) ;
|
| 93 |
+
|
| 94 |
+
snprintf (buffer, sizeof (buffer), "./stdout_test %s > stdio.%s", filetype, filetype) ;
|
| 95 |
+
if ((retval = system (buffer)))
|
| 96 |
+
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
| 97 |
+
printf ("%s : %s", buffer, (strerror (retval))) ;
|
| 98 |
+
exit (1) ;
|
| 99 |
+
} ;
|
| 100 |
+
|
| 101 |
+
snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
|
| 102 |
+
if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
|
| 103 |
+
{ printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
|
| 104 |
+
exit (1) ;
|
| 105 |
+
} ;
|
| 106 |
+
|
| 107 |
+
snprintf (buffer, sizeof (buffer), "./stdin_test %s < stdio.%s", filetype, filetype) ;
|
| 108 |
+
if ((retval = system (buffer)))
|
| 109 |
+
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
| 110 |
+
printf ("%s : %s", buffer, (strerror (retval))) ;
|
| 111 |
+
exit (1) ;
|
| 112 |
+
} ;
|
| 113 |
+
|
| 114 |
+
snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
|
| 115 |
+
if ((retval = system (buffer)))
|
| 116 |
+
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
| 117 |
+
printf ("%s : %s", buffer, (strerror (retval))) ;
|
| 118 |
+
exit (1) ;
|
| 119 |
+
} ;
|
| 120 |
+
|
| 121 |
+
puts ("ok") ;
|
| 122 |
+
|
| 123 |
+
return ;
|
| 124 |
+
} /* stdio_test */
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
static size_t
|
| 130 |
+
file_length (const char *filename)
|
| 131 |
+
{ struct stat buf ;
|
| 132 |
+
|
| 133 |
+
if (stat (filename, &buf))
|
| 134 |
+
{ perror (filename) ;
|
| 135 |
+
exit (1) ;
|
| 136 |
+
} ;
|
| 137 |
+
|
| 138 |
+
return buf.st_size ;
|
| 139 |
+
} /* file_length */
|
| 140 |
+
|
| 141 |
+
static int
|
| 142 |
+
file_exists (const char *filename)
|
| 143 |
+
{ struct stat buf ;
|
| 144 |
+
|
| 145 |
+
if (stat (filename, &buf))
|
| 146 |
+
return 0 ;
|
| 147 |
+
|
| 148 |
+
return 1 ;
|
| 149 |
+
} /* file_exists */
|
| 150 |
+
|
| 151 |
+
#endif
|
| 152 |
+
|
| 153 |
+
/*
|
| 154 |
+
** Do not edit or modify anything in this comment block.
|
| 155 |
+
** The arch-tag line is a file identity tag for the GNU Arch
|
| 156 |
+
** revision control system.
|
| 157 |
+
**
|
| 158 |
+
** arch-tag: f46d84fd-d37b-4d08-b1ba-80f2f1e0cfb9
|
| 159 |
+
*/
|
pool/shard000/C/0008695_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b.c
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
|
| 4 |
+
Template File: sources-sink-51b.tmpl.c
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Allocate using malloc() and set data pointer to a small buffer
|
| 10 |
+
* GoodSource: Allocate using malloc() and set data pointer to a large buffer
|
| 11 |
+
* Sink: memcpy
|
| 12 |
+
* BadSink : Copy int array to data using memcpy
|
| 13 |
+
* Flow Variant: 51 Data flow: data passed as an argument from one function to another in different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
/* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
|
| 20 |
+
|
| 21 |
+
#ifndef OMITBAD
|
| 22 |
+
|
| 23 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b_badSink(int * data)
|
| 24 |
+
{
|
| 25 |
+
{
|
| 26 |
+
int source[100] = {0}; /* fill with 0's */
|
| 27 |
+
/* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
|
| 28 |
+
memcpy(data, source, 100*sizeof(int));
|
| 29 |
+
printIntLine(data[0]);
|
| 30 |
+
free(data);
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#endif /* OMITBAD */
|
| 35 |
+
|
| 36 |
+
#ifndef OMITGOOD
|
| 37 |
+
|
| 38 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 39 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_memcpy_51b_goodG2BSink(int * data)
|
| 40 |
+
{
|
| 41 |
+
{
|
| 42 |
+
int source[100] = {0}; /* fill with 0's */
|
| 43 |
+
/* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
|
| 44 |
+
memcpy(data, source, 100*sizeof(int));
|
| 45 |
+
printIntLine(data[0]);
|
| 46 |
+
free(data);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
#endif /* OMITGOOD */
|
pool/shard000/C/0008696_end_of_solution_writer.c
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "output/latex/tree/end_of_solution_writer.h"
|
| 2 |
+
#include "stipulation/stipulation.h"
|
| 3 |
+
#include "stipulation/pipe.h"
|
| 4 |
+
#include "solving/machinery/slack_length.h"
|
| 5 |
+
#include "solving/pipe.h"
|
| 6 |
+
#include "debugging/trace.h"
|
| 7 |
+
|
| 8 |
+
/* Allocate a STOutputLaTeXTreeEndOfSolutionWriter slice.
|
| 9 |
+
* @return index of allocated slice
|
| 10 |
+
*/
|
| 11 |
+
slice_index alloc_output_latex_tree_end_of_solution_writer_slice(FILE *file)
|
| 12 |
+
{
|
| 13 |
+
slice_index result;
|
| 14 |
+
|
| 15 |
+
TraceFunctionEntry(__func__);
|
| 16 |
+
TraceFunctionParamListEnd();
|
| 17 |
+
|
| 18 |
+
result = alloc_pipe(STOutputLaTeXTreeEndOfSolutionWriter);
|
| 19 |
+
SLICE_U(result).writer.file = file;
|
| 20 |
+
|
| 21 |
+
TraceFunctionExit(__func__);
|
| 22 |
+
TraceFunctionResult("%u",result);
|
| 23 |
+
TraceFunctionResultEnd();
|
| 24 |
+
return result;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/* Try to solve in solve_nr_remaining half-moves.
|
| 28 |
+
* @param si slice index
|
| 29 |
+
* @note assigns solve_result the length of solution found and written, i.e.:
|
| 30 |
+
* previous_move_is_illegal the move just played is illegal
|
| 31 |
+
* this_move_is_illegal the move being played is illegal
|
| 32 |
+
* immobility_on_next_move the moves just played led to an
|
| 33 |
+
* unintended immobility on the next move
|
| 34 |
+
* <=n+1 length of shortest solution found (n+1 only if in next
|
| 35 |
+
* branch)
|
| 36 |
+
* n+2 no solution found in this branch
|
| 37 |
+
* n+3 no solution found in next branch
|
| 38 |
+
* (with n denominating solve_nr_remaining)
|
| 39 |
+
*/
|
| 40 |
+
void output_latex_tree_end_of_solution_writer_solve(slice_index si)
|
| 41 |
+
{
|
| 42 |
+
TraceFunctionEntry(__func__);
|
| 43 |
+
TraceFunctionParam("%u",si);
|
| 44 |
+
TraceFunctionParamListEnd();
|
| 45 |
+
|
| 46 |
+
pipe_solve_delegate(si);
|
| 47 |
+
|
| 48 |
+
TraceValue("%u",slack_length);
|
| 49 |
+
TraceValue("%u",solve_result);
|
| 50 |
+
TraceValue("%u\n",MOVE_HAS_SOLVED_LENGTH());
|
| 51 |
+
if (move_has_solved())
|
| 52 |
+
{
|
| 53 |
+
TraceText("has solved\n");
|
| 54 |
+
fputs("\n",SLICE_U(si).writer.file);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
TraceFunctionExit(__func__);
|
| 58 |
+
TraceFunctionResultEnd();
|
| 59 |
+
}
|
pool/shard000/C/0008697_1.6-String_Compression.c
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*************************************************
|
| 2 |
+
* Solution to question 1.6 - String Compression
|
| 3 |
+
*
|
| 4 |
+
* Status: COMPLETE
|
| 5 |
+
*
|
| 6 |
+
* Assumptions:
|
| 7 |
+
* - Strings are ASCII
|
| 8 |
+
* - Strings are alphabetical only
|
| 9 |
+
* - Case insensitive
|
| 10 |
+
*************************************************/
|
| 11 |
+
|
| 12 |
+
#include <math.h>
|
| 13 |
+
#include <stdio.h>
|
| 14 |
+
#include <stdlib.h>
|
| 15 |
+
#include <string.h>
|
| 16 |
+
|
| 17 |
+
#include "common.h"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
static inline size_t ldigits(long number) {
|
| 21 |
+
return (size_t) (floor(log10(labs(number))) + 1);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
static long lreverse(long num) {
|
| 26 |
+
long rev = 0;
|
| 27 |
+
|
| 28 |
+
while (num > 0) {
|
| 29 |
+
rev = (rev * 10) + (num % 10);
|
| 30 |
+
num /= 10;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
return rev;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
int main(int argc, char *argv[]) {
|
| 38 |
+
if (argc < 2 || !isstring(argv[1])) {
|
| 39 |
+
fprintf(stderr, "Please enter a string on the command line\n");
|
| 40 |
+
return EXIT_FAILURE;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
fprintf(stdout, "Compressed string: ");
|
| 44 |
+
|
| 45 |
+
struct str s1 = {
|
| 46 |
+
.data = argv[1],
|
| 47 |
+
.length = strlen(argv[1])
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
// Determine how many chars pairs we'll need
|
| 51 |
+
size_t chars = 0, digits = 0, count = 1;
|
| 52 |
+
|
| 53 |
+
for (size_t i = 1; i <= s1.length; i++) {
|
| 54 |
+
if (s1.data[i] != s1.data[i-1]) {
|
| 55 |
+
chars++;
|
| 56 |
+
digits += ldigits(count);
|
| 57 |
+
count = 1;
|
| 58 |
+
} else {
|
| 59 |
+
count++;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// If new string is not smaller than original
|
| 64 |
+
if (chars + digits >= s1.length) {
|
| 65 |
+
fprintf(stdout, "%s\n", s1.data);
|
| 66 |
+
return EXIT_SUCCESS;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Allocate space for the pairs in a new string
|
| 70 |
+
struct str s2 = {
|
| 71 |
+
.data = calloc((chars + digits) + 1, sizeof(char)),
|
| 72 |
+
.length = chars + digits
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
size_t s = 0;
|
| 76 |
+
|
| 77 |
+
// Create new string
|
| 78 |
+
for (size_t i = 1; i <= s1.length; i++) {
|
| 79 |
+
if (s1.data[i] != s1.data[i-1]) {
|
| 80 |
+
s2.data[s] = s1.data[i-1]; // Add the character
|
| 81 |
+
size_t reverse = lreverse(count);
|
| 82 |
+
|
| 83 |
+
// Save each digit
|
| 84 |
+
for (size_t j = 0; j < ldigits(count); j++) {
|
| 85 |
+
s++;
|
| 86 |
+
s2.data[s] = (reverse % 10) + '0';
|
| 87 |
+
reverse /= 10;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
count = 1;
|
| 91 |
+
s++;
|
| 92 |
+
} else {
|
| 93 |
+
count++;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
fprintf(stdout, "%s\n", s2.data);
|
| 98 |
+
free(s2.data);
|
| 99 |
+
return EXIT_SUCCESS;
|
| 100 |
+
}
|
pool/shard000/C/0008698_nxeb500hmi.c
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* arch/arm/mach-netx/nxeb500hmi.c
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
| 5 |
+
*
|
| 6 |
+
* This program is free software; you can redistribute it and/or modify
|
| 7 |
+
* it under the terms of the GNU General Public License version 2
|
| 8 |
+
* as published by the Free Software Foundation.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <linux/dma-mapping.h>
|
| 21 |
+
#include <linux/init.h>
|
| 22 |
+
#include <linux/interrupt.h>
|
| 23 |
+
#include <linux/mtd/plat-ram.h>
|
| 24 |
+
#include <linux/platform_device.h>
|
| 25 |
+
#include <linux/amba/bus.h>
|
| 26 |
+
#include <linux/amba/clcd.h>
|
| 27 |
+
|
| 28 |
+
#include <mach/hardware.h>
|
| 29 |
+
#include <asm/mach-types.h>
|
| 30 |
+
#include <asm/mach/arch.h>
|
| 31 |
+
#include <asm/hardware/vic.h>
|
| 32 |
+
#include <mach/netx-regs.h>
|
| 33 |
+
#include <mach/eth.h>
|
| 34 |
+
|
| 35 |
+
#include "generic.h"
|
| 36 |
+
#include "fb.h"
|
| 37 |
+
|
| 38 |
+
static struct clcd_panel qvga = {
|
| 39 |
+
.mode = {
|
| 40 |
+
.name = "QVGA",
|
| 41 |
+
.refresh = 60,
|
| 42 |
+
.xres = 240,
|
| 43 |
+
.yres = 320,
|
| 44 |
+
.pixclock = 187617,
|
| 45 |
+
.left_margin = 6,
|
| 46 |
+
.right_margin = 26,
|
| 47 |
+
.upper_margin = 0,
|
| 48 |
+
.lower_margin = 6,
|
| 49 |
+
.hsync_len = 6,
|
| 50 |
+
.vsync_len = 1,
|
| 51 |
+
.sync = 0,
|
| 52 |
+
.vmode = FB_VMODE_NONINTERLACED,
|
| 53 |
+
},
|
| 54 |
+
.width = -1,
|
| 55 |
+
.height = -1,
|
| 56 |
+
.tim2 = 16,
|
| 57 |
+
.cntl = CNTL_LCDTFT | CNTL_BGR,
|
| 58 |
+
.bpp = 16,
|
| 59 |
+
.grayscale = 0,
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
static inline int nxeb500hmi_check(struct clcd_fb *fb, struct fb_var_screeninfo *var)
|
| 63 |
+
{
|
| 64 |
+
var->green.length = 5;
|
| 65 |
+
var->green.msb_right = 0;
|
| 66 |
+
|
| 67 |
+
return clcdfb_check(fb, var);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
static int nxeb500hmi_clcd_setup(struct clcd_fb *fb)
|
| 71 |
+
{
|
| 72 |
+
unsigned int val;
|
| 73 |
+
|
| 74 |
+
fb->fb.var.green.length = 5;
|
| 75 |
+
fb->fb.var.green.msb_right = 0;
|
| 76 |
+
|
| 77 |
+
/* */
|
| 78 |
+
val = readl(NETX_SYSTEM_IOC_ACCESS_KEY);
|
| 79 |
+
writel(val, NETX_SYSTEM_IOC_ACCESS_KEY);
|
| 80 |
+
|
| 81 |
+
writel(3, NETX_SYSTEM_IOC_CR);
|
| 82 |
+
|
| 83 |
+
/* */
|
| 84 |
+
writel(9, NETX_GPIO_CFG(14));
|
| 85 |
+
|
| 86 |
+
val = readl(NETX_PIO_OUTPIO);
|
| 87 |
+
writel(val | 1, NETX_PIO_OUTPIO);
|
| 88 |
+
|
| 89 |
+
val = readl(NETX_PIO_OEPIO);
|
| 90 |
+
writel(val | 1, NETX_PIO_OEPIO);
|
| 91 |
+
return netx_clcd_setup(fb);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
static struct clcd_board clcd_data = {
|
| 95 |
+
.name = "netX",
|
| 96 |
+
.check = nxeb500hmi_check,
|
| 97 |
+
.decode = clcdfb_decode,
|
| 98 |
+
.enable = netx_clcd_enable,
|
| 99 |
+
.setup = nxeb500hmi_clcd_setup,
|
| 100 |
+
.mmap = netx_clcd_mmap,
|
| 101 |
+
.remove = netx_clcd_remove,
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
static struct netxeth_platform_data eth0_platform_data = {
|
| 105 |
+
.xcno = 0,
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
static struct platform_device netx_eth0_device = {
|
| 109 |
+
.name = "netx-eth",
|
| 110 |
+
.id = 0,
|
| 111 |
+
.num_resources = 0,
|
| 112 |
+
.resource = NULL,
|
| 113 |
+
.dev = {
|
| 114 |
+
.platform_data = ð0_platform_data,
|
| 115 |
+
}
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
static struct netxeth_platform_data eth1_platform_data = {
|
| 119 |
+
.xcno = 1,
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
static struct platform_device netx_eth1_device = {
|
| 123 |
+
.name = "netx-eth",
|
| 124 |
+
.id = 1,
|
| 125 |
+
.num_resources = 0,
|
| 126 |
+
.resource = NULL,
|
| 127 |
+
.dev = {
|
| 128 |
+
.platform_data = ð1_platform_data,
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
static struct resource netx_cf_resources[] = {
|
| 133 |
+
[0] = {
|
| 134 |
+
.start = 0x20000000,
|
| 135 |
+
.end = 0x25ffffff,
|
| 136 |
+
.flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
|
| 137 |
+
},
|
| 138 |
+
};
|
| 139 |
+
|
| 140 |
+
static struct platform_device netx_cf_device = {
|
| 141 |
+
.name = "netx-cf",
|
| 142 |
+
.id = 0,
|
| 143 |
+
.resource = netx_cf_resources,
|
| 144 |
+
.num_resources = ARRAY_SIZE(netx_cf_resources),
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
static struct resource netx_uart0_resources[] = {
|
| 148 |
+
[0] = {
|
| 149 |
+
.start = 0x00100A00,
|
| 150 |
+
.end = 0x00100A3F,
|
| 151 |
+
.flags = IORESOURCE_MEM,
|
| 152 |
+
},
|
| 153 |
+
[1] = {
|
| 154 |
+
.start = (NETX_IRQ_UART0),
|
| 155 |
+
.end = (NETX_IRQ_UART0),
|
| 156 |
+
.flags = IORESOURCE_IRQ,
|
| 157 |
+
},
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
static struct platform_device netx_uart0_device = {
|
| 161 |
+
.name = "netx-uart",
|
| 162 |
+
.id = 0,
|
| 163 |
+
.num_resources = ARRAY_SIZE(netx_uart0_resources),
|
| 164 |
+
.resource = netx_uart0_resources,
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
static struct platform_device *devices[] __initdata = {
|
| 168 |
+
&netx_eth0_device,
|
| 169 |
+
&netx_eth1_device,
|
| 170 |
+
&netx_cf_device,
|
| 171 |
+
&netx_uart0_device,
|
| 172 |
+
};
|
| 173 |
+
|
| 174 |
+
static void __init nxeb500hmi_init(void)
|
| 175 |
+
{
|
| 176 |
+
netx_fb_init(&clcd_data, &qvga);
|
| 177 |
+
platform_add_devices(devices, ARRAY_SIZE(devices));
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
MACHINE_START(NXEB500HMI, "Hilscher nxeb500hmi")
|
| 181 |
+
.atag_offset = 0x100,
|
| 182 |
+
.map_io = netx_map_io,
|
| 183 |
+
.init_irq = netx_init_irq,
|
| 184 |
+
.handle_irq = vic_handle_irq,
|
| 185 |
+
.timer = &netx_timer,
|
| 186 |
+
.init_machine = nxeb500hmi_init,
|
| 187 |
+
.restart = netx_restart,
|
| 188 |
+
MACHINE_END
|
pool/shard000/C/0008717_heap-sort.c
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* =====================================================================================
|
| 3 |
+
*
|
| 4 |
+
* Filename: heap-sort.c
|
| 5 |
+
*
|
| 6 |
+
* Description:
|
| 7 |
+
*
|
| 8 |
+
* Version: 1.0
|
| 9 |
+
* Created: 12/22/2016 07:35:56 PM
|
| 10 |
+
* Revision: none
|
| 11 |
+
* Compiler: gcc
|
| 12 |
+
*
|
| 13 |
+
* Author: YOUR NAME (),
|
| 14 |
+
* Organization:
|
| 15 |
+
*
|
| 16 |
+
* =====================================================================================
|
| 17 |
+
*/
|
| 18 |
+
#include <stdio.h>
|
| 19 |
+
#include <string.h>
|
| 20 |
+
#include <strings.h>
|
| 21 |
+
#include <stdlib.h>
|
| 22 |
+
#include <math.h>
|
| 23 |
+
|
| 24 |
+
struct st_list {
|
| 25 |
+
int *pList;
|
| 26 |
+
int iLen;
|
| 27 |
+
int iCmpCount;
|
| 28 |
+
int iSwapCount;
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
void get_list(struct st_list * pstList, int len) {
|
| 32 |
+
if(NULL == pstList) {
|
| 33 |
+
return ;
|
| 34 |
+
}
|
| 35 |
+
bzero(pstList, sizeof(struct st_list));
|
| 36 |
+
pstList -> pList = (int *)malloc(sizeof(int) * len);
|
| 37 |
+
if(NULL == pstList -> pList) {
|
| 38 |
+
printf("get mamory faild\n");
|
| 39 |
+
return ;
|
| 40 |
+
}
|
| 41 |
+
pstList -> iLen = len;
|
| 42 |
+
srand(374677);
|
| 43 |
+
int i = 0;
|
| 44 |
+
for(i = 0; i < len; i++) {
|
| 45 |
+
pstList -> pList[i] = rand() % (len * 10);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
void delete_list(struct st_list * pstList) {
|
| 50 |
+
if(NULL == pstList) {
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
if(NULL != pstList -> pList) {
|
| 54 |
+
free(pstList -> pList);
|
| 55 |
+
pstList -> pList = NULL;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
int check_list(struct st_list * pstList, int(*cmp)(void*, void*)) {
|
| 60 |
+
int *list = pstList -> pList;
|
| 61 |
+
int len = pstList -> iLen;
|
| 62 |
+
int i = 0;
|
| 63 |
+
int iRet = 0;
|
| 64 |
+
for(i = 0; i < len - 1; i++) {
|
| 65 |
+
if(!cmp(&list[i], &list[i + 1])) {
|
| 66 |
+
printf("\033[0;31mcompare faild on : [%d] and [%d] as : [%d] and [%d]\033[0m\n",
|
| 67 |
+
i, i + 1, list[i], list[i + 1]);
|
| 68 |
+
iRet ++;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return iRet;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/* **************************** */
|
| 76 |
+
|
| 77 |
+
int cmp_fun(void *a, void *b) {
|
| 78 |
+
return *(int*)a <= *(int*)b;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
int swap(void *a, void *b, int isize, void *t) {
|
| 82 |
+
if(NULL == a || NULL == b || NULL == t || isize <= 0) {
|
| 83 |
+
return 0;
|
| 84 |
+
}
|
| 85 |
+
memcpy(t, a, isize);
|
| 86 |
+
memcpy(a, b, isize);
|
| 87 |
+
memcpy(b, t, isize);
|
| 88 |
+
|
| 89 |
+
return 3;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
int adjust_sort(struct st_list * pstList, int iLen, int (*cmp)(void *, void *)) {
|
| 93 |
+
if( NULL == pstList ||
|
| 94 |
+
NULL == pstList -> pList ||
|
| 95 |
+
NULL == cmp) {
|
| 96 |
+
printf("argu is empty\n");
|
| 97 |
+
return -1;
|
| 98 |
+
}
|
| 99 |
+
int *list = pstList -> pList;
|
| 100 |
+
int len = iLen;
|
| 101 |
+
int iChild = 0;
|
| 102 |
+
int tmp = 0;
|
| 103 |
+
int i = 0;
|
| 104 |
+
for(i = len / 2; i >= 0; ) {
|
| 105 |
+
if((i * 2) < len && cmp(&list[i], &list[i * 2])) {
|
| 106 |
+
pstList -> iCmpCount += swap(&list[i], &list[i * 2], sizeof(int), &tmp);
|
| 107 |
+
}
|
| 108 |
+
if((i * 2 + 1) < len && cmp(&list[i], &list[i * 2 + 1])) {
|
| 109 |
+
pstList -> iCmpCount += swap(&list[i], &list[i * 2 + 1], sizeof(int), &tmp);
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
return 0;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
int heap_sort(struct st_list *pstList, int (*cmp)(void *, void *)) {
|
| 117 |
+
int i = 0;
|
| 118 |
+
for(i = 0; i < pstList -> iLen / 2; i++) {
|
| 119 |
+
adjust_sort(pstList, pstList -> iLen - i, cmp);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
return 0;
|
| 123 |
+
}
|
| 124 |
+
/* ********************************* */
|
| 125 |
+
//typedef int ElemType;
|
| 126 |
+
#define ElemType int
|
| 127 |
+
|
| 128 |
+
void HeapAdjust(ElemType H[], int start, int end)
|
| 129 |
+
{
|
| 130 |
+
|
| 131 |
+
ElemType temp = H[start];
|
| 132 |
+
|
| 133 |
+
int i = 0;
|
| 134 |
+
for(i = 2 * start + 1; i <= end; i *= 2)
|
| 135 |
+
{
|
| 136 |
+
//因为假设根结点的序号为0而不是1,所以i结点左孩子和右孩子分别为2i+1和2i+2
|
| 137 |
+
if(i < end && H[i] < H[i+1])//左右孩子的比较
|
| 138 |
+
{
|
| 139 |
+
++i;//i为较大的记录的下标
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
if(temp > H[i])//左右孩子中获胜者与父亲的比较
|
| 143 |
+
{
|
| 144 |
+
break;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
//将孩子结点上位,则以孩子结点的位置进行下一轮的筛选
|
| 148 |
+
H[start]= H[i];
|
| 149 |
+
start = i;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
H[start]= temp; //插入最开始不和谐的元素
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
void HeapSort(ElemType A[], int n)
|
| 156 |
+
{
|
| 157 |
+
int i = 0;
|
| 158 |
+
//先建立大顶堆
|
| 159 |
+
for(i = n/2; i >= 0; --i)
|
| 160 |
+
{
|
| 161 |
+
HeapAdjust(A,i,n);
|
| 162 |
+
}
|
| 163 |
+
ElemType temp;
|
| 164 |
+
//进行排序
|
| 165 |
+
for(i = n-1; i > 0; --i)
|
| 166 |
+
{
|
| 167 |
+
//最后一个元素和第一元素进行交换
|
| 168 |
+
swap(&A[0], &A[i], sizeof(ElemType), &temp);
|
| 169 |
+
//ElemType temp = A[i];
|
| 170 |
+
//A[i] = A[0];
|
| 171 |
+
//A[0] = temp;
|
| 172 |
+
|
| 173 |
+
//然后将剩下的无序元素继续调整为大顶堆
|
| 174 |
+
HeapAdjust(A,0,i-1);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
int test_heap_sort(int n) {
|
| 179 |
+
struct st_list alist;
|
| 180 |
+
get_list(&alist, n);
|
| 181 |
+
//for(i = 0; i < n; i++) {
|
| 182 |
+
// printf("%2d ", list[i]);
|
| 183 |
+
//}
|
| 184 |
+
//printf("\n");
|
| 185 |
+
#if 0
|
| 186 |
+
HeapSort(alist.pList, alist.iLen);
|
| 187 |
+
#else
|
| 188 |
+
heap_sort(&alist, cmp_fun);
|
| 189 |
+
#endif
|
| 190 |
+
if(check_list(&alist, cmp_fun)) {
|
| 191 |
+
printf("\033[0;31msort faild\033[0m\n");
|
| 192 |
+
}
|
| 193 |
+
//int i = 0;
|
| 194 |
+
//for(i = 0; i < n; i++) {
|
| 195 |
+
// printf("%2d ", alist.pList[i]);
|
| 196 |
+
//}
|
| 197 |
+
//printf("\n");
|
| 198 |
+
double dThro = n * log(n) / log(2);
|
| 199 |
+
printf("compare times : [%d], theoretical times [%d], degree = [%lf]\n",
|
| 200 |
+
alist.iCmpCount, (int)dThro, alist.iCmpCount / dThro);
|
| 201 |
+
printf("sweap times : [%d], theoretical times [%d], degree = [%f]\n",
|
| 202 |
+
alist.iSwapCount, (int)dThro, alist.iSwapCount / dThro);
|
| 203 |
+
delete_list(&alist);
|
| 204 |
+
printf("\n");
|
| 205 |
+
|
| 206 |
+
return 0;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/* ********************************* */
|
| 210 |
+
int main() {
|
| 211 |
+
int i = 0;
|
| 212 |
+
for(i = 16; i <= 1024 * 1024; i *= 2) {
|
| 213 |
+
test_heap_sort(i);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
return 0;
|
| 217 |
+
}
|
| 218 |
+
|
pool/shard000/C/0008725_timecompare.c
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2009 Intel Corporation.
|
| 3 |
+
* Author: Patrick Ohly <patrick.ohly@intel.com>
|
| 4 |
+
*
|
| 5 |
+
* This program is free software; you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This program is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with this program; if not, write to the Free Software
|
| 17 |
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#include <linux/timecompare.h>
|
| 21 |
+
#include <linux/module.h>
|
| 22 |
+
#include <linux/math64.h>
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
* fixed point arithmetic scale factor for skew
|
| 26 |
+
*
|
| 27 |
+
* Usually one would measure skew in ppb (parts per billion, 1e9), but
|
| 28 |
+
* using a factor of 2 simplifies the math.
|
| 29 |
+
*/
|
| 30 |
+
#define TIMECOMPARE_SKEW_RESOLUTION (((s64)1)<<30)
|
| 31 |
+
|
| 32 |
+
ktime_t timecompare_transform(struct timecompare *sync,
|
| 33 |
+
u64 source_tstamp)
|
| 34 |
+
{
|
| 35 |
+
u64 nsec;
|
| 36 |
+
|
| 37 |
+
nsec = source_tstamp + sync->offset;
|
| 38 |
+
nsec += (s64)(source_tstamp - sync->last_update) * sync->skew /
|
| 39 |
+
TIMECOMPARE_SKEW_RESOLUTION;
|
| 40 |
+
|
| 41 |
+
return ns_to_ktime(nsec);
|
| 42 |
+
}
|
| 43 |
+
EXPORT_SYMBOL_GPL(timecompare_transform);
|
| 44 |
+
|
| 45 |
+
int timecompare_offset(struct timecompare *sync,
|
| 46 |
+
s64 *offset,
|
| 47 |
+
u64 *source_tstamp)
|
| 48 |
+
{
|
| 49 |
+
u64 start_source = 0, end_source = 0;
|
| 50 |
+
struct {
|
| 51 |
+
s64 offset;
|
| 52 |
+
s64 duration_target;
|
| 53 |
+
} buffer[10], sample, *samples;
|
| 54 |
+
int counter = 0, i;
|
| 55 |
+
int used;
|
| 56 |
+
int index;
|
| 57 |
+
int num_samples = sync->num_samples;
|
| 58 |
+
|
| 59 |
+
if (num_samples > sizeof(buffer)/sizeof(buffer[0])) {
|
| 60 |
+
samples = kmalloc(sizeof(*samples) * num_samples, GFP_ATOMIC);
|
| 61 |
+
if (!samples) {
|
| 62 |
+
samples = buffer;
|
| 63 |
+
num_samples = sizeof(buffer)/sizeof(buffer[0]);
|
| 64 |
+
}
|
| 65 |
+
} else {
|
| 66 |
+
samples = buffer;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* run until we have enough valid samples, but do not try forever */
|
| 70 |
+
i = 0;
|
| 71 |
+
counter = 0;
|
| 72 |
+
while (1) {
|
| 73 |
+
u64 ts;
|
| 74 |
+
ktime_t start, end;
|
| 75 |
+
|
| 76 |
+
start = sync->target();
|
| 77 |
+
ts = timecounter_read(sync->source);
|
| 78 |
+
end = sync->target();
|
| 79 |
+
|
| 80 |
+
if (!i)
|
| 81 |
+
start_source = ts;
|
| 82 |
+
|
| 83 |
+
/* ignore negative durations */
|
| 84 |
+
sample.duration_target = ktime_to_ns(ktime_sub(end, start));
|
| 85 |
+
if (sample.duration_target >= 0) {
|
| 86 |
+
/*
|
| 87 |
+
* assume symetric delay to and from source:
|
| 88 |
+
* average target time corresponds to measured
|
| 89 |
+
* source time
|
| 90 |
+
*/
|
| 91 |
+
sample.offset =
|
| 92 |
+
ktime_to_ns(ktime_add(end, start)) / 2 -
|
| 93 |
+
ts;
|
| 94 |
+
|
| 95 |
+
/* simple insertion sort based on duration */
|
| 96 |
+
index = counter - 1;
|
| 97 |
+
while (index >= 0) {
|
| 98 |
+
if (samples[index].duration_target <
|
| 99 |
+
sample.duration_target)
|
| 100 |
+
break;
|
| 101 |
+
samples[index + 1] = samples[index];
|
| 102 |
+
index--;
|
| 103 |
+
}
|
| 104 |
+
samples[index + 1] = sample;
|
| 105 |
+
counter++;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
i++;
|
| 109 |
+
if (counter >= num_samples || i >= 100000) {
|
| 110 |
+
end_source = ts;
|
| 111 |
+
break;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
*source_tstamp = (end_source + start_source) / 2;
|
| 116 |
+
|
| 117 |
+
/* remove outliers by only using 75% of the samples */
|
| 118 |
+
used = counter * 3 / 4;
|
| 119 |
+
if (!used)
|
| 120 |
+
used = counter;
|
| 121 |
+
if (used) {
|
| 122 |
+
/* calculate average */
|
| 123 |
+
s64 off = 0;
|
| 124 |
+
for (index = 0; index < used; index++)
|
| 125 |
+
off += samples[index].offset;
|
| 126 |
+
*offset = div_s64(off, used);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (samples && samples != buffer)
|
| 130 |
+
kfree(samples);
|
| 131 |
+
|
| 132 |
+
return used;
|
| 133 |
+
}
|
| 134 |
+
EXPORT_SYMBOL_GPL(timecompare_offset);
|
| 135 |
+
|
| 136 |
+
void __timecompare_update(struct timecompare *sync,
|
| 137 |
+
u64 source_tstamp)
|
| 138 |
+
{
|
| 139 |
+
s64 offset;
|
| 140 |
+
u64 average_time;
|
| 141 |
+
|
| 142 |
+
if (!timecompare_offset(sync, &offset, &average_time))
|
| 143 |
+
return;
|
| 144 |
+
|
| 145 |
+
if (!sync->last_update) {
|
| 146 |
+
sync->last_update = average_time;
|
| 147 |
+
sync->offset = offset;
|
| 148 |
+
sync->skew = 0;
|
| 149 |
+
} else {
|
| 150 |
+
s64 delta_nsec = average_time - sync->last_update;
|
| 151 |
+
|
| 152 |
+
/* avoid division by negative or small deltas */
|
| 153 |
+
if (delta_nsec >= 10000) {
|
| 154 |
+
s64 delta_offset_nsec = offset - sync->offset;
|
| 155 |
+
s64 skew; /* delta_offset_nsec *
|
| 156 |
+
TIMECOMPARE_SKEW_RESOLUTION /
|
| 157 |
+
delta_nsec */
|
| 158 |
+
u64 divisor;
|
| 159 |
+
|
| 160 |
+
/* div_s64() is limited to 32 bit divisor */
|
| 161 |
+
skew = delta_offset_nsec * TIMECOMPARE_SKEW_RESOLUTION;
|
| 162 |
+
divisor = delta_nsec;
|
| 163 |
+
while (unlikely(divisor >= ((s64)1) << 32)) {
|
| 164 |
+
/* divide both by 2; beware, right shift
|
| 165 |
+
of negative value has undefined
|
| 166 |
+
behavior and can only be used for
|
| 167 |
+
the positive divisor */
|
| 168 |
+
skew = div_s64(skew, 2);
|
| 169 |
+
divisor >>= 1;
|
| 170 |
+
}
|
| 171 |
+
skew = div_s64(skew, divisor);
|
| 172 |
+
|
| 173 |
+
/*
|
| 174 |
+
* Calculate new overall skew as 4/16 the
|
| 175 |
+
* old value and 12/16 the new one. This is
|
| 176 |
+
* a rather arbitrary tradeoff between
|
| 177 |
+
* only using the latest measurement (0/16 and
|
| 178 |
+
* 16/16) and even more weight on past measurements.
|
| 179 |
+
*/
|
| 180 |
+
#define TIMECOMPARE_NEW_SKEW_PER_16 12
|
| 181 |
+
sync->skew =
|
| 182 |
+
div_s64((16 - TIMECOMPARE_NEW_SKEW_PER_16) *
|
| 183 |
+
sync->skew +
|
| 184 |
+
TIMECOMPARE_NEW_SKEW_PER_16 * skew,
|
| 185 |
+
16);
|
| 186 |
+
sync->last_update = average_time;
|
| 187 |
+
sync->offset = offset;
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
EXPORT_SYMBOL_GPL(__timecompare_update);
|
pool/shard000/C/0008729_dot.c
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 3 |
+
% %
|
| 4 |
+
% %
|
| 5 |
+
% %
|
| 6 |
+
% DDDD OOO TTTTT %
|
| 7 |
+
% D D O O T %
|
| 8 |
+
% D D O O T %
|
| 9 |
+
% D D O O T %
|
| 10 |
+
% DDDD OOO T %
|
| 11 |
+
% %
|
| 12 |
+
% %
|
| 13 |
+
% Read/Write Graphviz DOT Format %
|
| 14 |
+
% %
|
| 15 |
+
% Software Design %
|
| 16 |
+
% Cristy %
|
| 17 |
+
% July 1992 %
|
| 18 |
+
% %
|
| 19 |
+
% %
|
| 20 |
+
% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
|
| 21 |
+
% dedicated to making software imaging solutions freely available. %
|
| 22 |
+
% %
|
| 23 |
+
% You may not use this file except in compliance with the License. You may %
|
| 24 |
+
% obtain a copy of the License at %
|
| 25 |
+
% %
|
| 26 |
+
% http://www.imagemagick.org/script/license.php %
|
| 27 |
+
% %
|
| 28 |
+
% Unless required by applicable law or agreed to in writing, software %
|
| 29 |
+
% distributed under the License is distributed on an "AS IS" BASIS, %
|
| 30 |
+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
|
| 31 |
+
% See the License for the specific language governing permissions and %
|
| 32 |
+
% limitations under the License. %
|
| 33 |
+
% %
|
| 34 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 35 |
+
%
|
| 36 |
+
%
|
| 37 |
+
*/
|
| 38 |
+
|
| 39 |
+
/*
|
| 40 |
+
Include declarations.
|
| 41 |
+
*/
|
| 42 |
+
#include "magick/studio.h"
|
| 43 |
+
#include "magick/blob.h"
|
| 44 |
+
#include "magick/blob-private.h"
|
| 45 |
+
#include "magick/client.h"
|
| 46 |
+
#include "magick/constitute.h"
|
| 47 |
+
#include "magick/exception.h"
|
| 48 |
+
#include "magick/exception-private.h"
|
| 49 |
+
#include "magick/image.h"
|
| 50 |
+
#include "magick/image-private.h"
|
| 51 |
+
#include "magick/list.h"
|
| 52 |
+
#include "magick/magick.h"
|
| 53 |
+
#include "magick/memory_.h"
|
| 54 |
+
#include "magick/monitor.h"
|
| 55 |
+
#include "magick/monitor-private.h"
|
| 56 |
+
#include "magick/option.h"
|
| 57 |
+
#include "magick/pixel-accessor.h"
|
| 58 |
+
#include "magick/quantum-private.h"
|
| 59 |
+
#include "magick/resource_.h"
|
| 60 |
+
#include "magick/static.h"
|
| 61 |
+
#include "magick/string_.h"
|
| 62 |
+
#include "magick/module.h"
|
| 63 |
+
#include "magick/utility.h"
|
| 64 |
+
#include "magick/xwindow-private.h"
|
| 65 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 66 |
+
#undef HAVE_CONFIG_H
|
| 67 |
+
#include <gvc.h>
|
| 68 |
+
static GVC_t
|
| 69 |
+
*graphic_context;
|
| 70 |
+
#endif
|
| 71 |
+
|
| 72 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 73 |
+
/*
|
| 74 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 75 |
+
% %
|
| 76 |
+
% %
|
| 77 |
+
% %
|
| 78 |
+
% R e a d D O T I m a g e %
|
| 79 |
+
% %
|
| 80 |
+
% %
|
| 81 |
+
% %
|
| 82 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 83 |
+
%
|
| 84 |
+
% ReadDOTImage() reads a Graphviz image file and returns it. It allocates
|
| 85 |
+
% the memory necessary for the new Image structure and returns a pointer to
|
| 86 |
+
% the new image.
|
| 87 |
+
%
|
| 88 |
+
% The format of the ReadDOTImage method is:
|
| 89 |
+
%
|
| 90 |
+
% Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
|
| 91 |
+
%
|
| 92 |
+
% A description of each parameter follows:
|
| 93 |
+
%
|
| 94 |
+
% o image_info: the image info.
|
| 95 |
+
%
|
| 96 |
+
% o exception: return any errors or warnings in this structure.
|
| 97 |
+
%
|
| 98 |
+
*/
|
| 99 |
+
static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
|
| 100 |
+
{
|
| 101 |
+
char
|
| 102 |
+
command[MaxTextExtent];
|
| 103 |
+
|
| 104 |
+
const char
|
| 105 |
+
*option;
|
| 106 |
+
|
| 107 |
+
graph_t
|
| 108 |
+
*graph;
|
| 109 |
+
|
| 110 |
+
Image
|
| 111 |
+
*image;
|
| 112 |
+
|
| 113 |
+
ImageInfo
|
| 114 |
+
*read_info;
|
| 115 |
+
|
| 116 |
+
MagickBooleanType
|
| 117 |
+
status;
|
| 118 |
+
|
| 119 |
+
/*
|
| 120 |
+
Open image file.
|
| 121 |
+
*/
|
| 122 |
+
assert(image_info != (const ImageInfo *) NULL);
|
| 123 |
+
assert(image_info->signature == MagickSignature);
|
| 124 |
+
if (image_info->debug != MagickFalse)
|
| 125 |
+
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
|
| 126 |
+
image_info->filename);
|
| 127 |
+
assert(exception != (ExceptionInfo *) NULL);
|
| 128 |
+
assert(exception->signature == MagickSignature);
|
| 129 |
+
image=AcquireImage(image_info);
|
| 130 |
+
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
|
| 131 |
+
if (status == MagickFalse)
|
| 132 |
+
return((Image *) NULL);
|
| 133 |
+
read_info=CloneImageInfo(image_info);
|
| 134 |
+
SetImageInfoBlob(read_info,(void *) NULL,0);
|
| 135 |
+
(void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
|
| 136 |
+
(void) AcquireUniqueFilename(read_info->filename);
|
| 137 |
+
(void) FormatLocaleString(command,MaxTextExtent,"-Tsvg -o%s %s",
|
| 138 |
+
read_info->filename,image_info->filename);
|
| 139 |
+
#if !defined(WITH_CGRAPH)
|
| 140 |
+
graph=agread(GetBlobFileHandle(image));
|
| 141 |
+
#else
|
| 142 |
+
graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
|
| 143 |
+
#endif
|
| 144 |
+
if (graph == (graph_t *) NULL)
|
| 145 |
+
{
|
| 146 |
+
(void) RelinquishUniqueFileResource(read_info->filename);
|
| 147 |
+
return ((Image *) NULL);
|
| 148 |
+
}
|
| 149 |
+
option=GetImageOption(image_info,"dot:layout-engine");
|
| 150 |
+
if (option == (const char *) NULL)
|
| 151 |
+
gvLayout(graphic_context,graph,(char *) "dot");
|
| 152 |
+
else
|
| 153 |
+
gvLayout(graphic_context,graph,(char *) option);
|
| 154 |
+
gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
|
| 155 |
+
gvFreeLayout(graphic_context,graph);
|
| 156 |
+
agclose(graph);
|
| 157 |
+
/*
|
| 158 |
+
Read SVG graph.
|
| 159 |
+
*/
|
| 160 |
+
image=ReadImage(read_info,exception);
|
| 161 |
+
(void) RelinquishUniqueFileResource(read_info->filename);
|
| 162 |
+
read_info=DestroyImageInfo(read_info);
|
| 163 |
+
if (image == (Image *) NULL)
|
| 164 |
+
return((Image *) NULL);
|
| 165 |
+
return(GetFirstImageInList(image));
|
| 166 |
+
}
|
| 167 |
+
#endif
|
| 168 |
+
|
| 169 |
+
/*
|
| 170 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 171 |
+
% %
|
| 172 |
+
% %
|
| 173 |
+
% %
|
| 174 |
+
% R e g i s t e r D O T I m a g e %
|
| 175 |
+
% %
|
| 176 |
+
% %
|
| 177 |
+
% %
|
| 178 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 179 |
+
%
|
| 180 |
+
% RegisterDOTImage() adds attributes for the Display Postscript image
|
| 181 |
+
% format to the list of supported formats. The attributes include the image
|
| 182 |
+
% format tag, a method to read and/or write the format, whether the format
|
| 183 |
+
% supports the saving of more than one frame to the same file or blob,
|
| 184 |
+
% whether the format supports native in-memory I/O, and a brief
|
| 185 |
+
% description of the format.
|
| 186 |
+
%
|
| 187 |
+
% The format of the RegisterDOTImage method is:
|
| 188 |
+
%
|
| 189 |
+
% size_t RegisterDOTImage(void)
|
| 190 |
+
%
|
| 191 |
+
*/
|
| 192 |
+
ModuleExport size_t RegisterDOTImage(void)
|
| 193 |
+
{
|
| 194 |
+
MagickInfo
|
| 195 |
+
*entry;
|
| 196 |
+
|
| 197 |
+
entry=SetMagickInfo("DOT");
|
| 198 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 199 |
+
entry->decoder=(DecodeImageHandler *) ReadDOTImage;
|
| 200 |
+
#endif
|
| 201 |
+
entry->blob_support=MagickFalse;
|
| 202 |
+
entry->description=ConstantString("Graphviz");
|
| 203 |
+
entry->module=ConstantString("DOT");
|
| 204 |
+
(void) RegisterMagickInfo(entry);
|
| 205 |
+
entry=SetMagickInfo("GV");
|
| 206 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 207 |
+
entry->decoder=(DecodeImageHandler *) ReadDOTImage;
|
| 208 |
+
#endif
|
| 209 |
+
entry->blob_support=MagickFalse;
|
| 210 |
+
entry->description=ConstantString("Graphviz");
|
| 211 |
+
entry->module=ConstantString("DOT");
|
| 212 |
+
(void) RegisterMagickInfo(entry);
|
| 213 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 214 |
+
graphic_context=gvContext();
|
| 215 |
+
#endif
|
| 216 |
+
return(MagickImageCoderSignature);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/*
|
| 220 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 221 |
+
% %
|
| 222 |
+
% %
|
| 223 |
+
% %
|
| 224 |
+
% U n r e g i s t e r D O T I m a g e %
|
| 225 |
+
% %
|
| 226 |
+
% %
|
| 227 |
+
% %
|
| 228 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 229 |
+
%
|
| 230 |
+
% UnregisterDOTImage() removes format registrations made by the
|
| 231 |
+
% DOT module from the list of supported formats.
|
| 232 |
+
%
|
| 233 |
+
% The format of the UnregisterDOTImage method is:
|
| 234 |
+
%
|
| 235 |
+
% UnregisterDOTImage(void)
|
| 236 |
+
%
|
| 237 |
+
*/
|
| 238 |
+
ModuleExport void UnregisterDOTImage(void)
|
| 239 |
+
{
|
| 240 |
+
(void) UnregisterMagickInfo("GV");
|
| 241 |
+
(void) UnregisterMagickInfo("DOT");
|
| 242 |
+
#if defined(MAGICKCORE_GVC_DELEGATE)
|
| 243 |
+
gvFreeContext(graphic_context);
|
| 244 |
+
#endif
|
| 245 |
+
}
|
pool/shard000/C/0008746_CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* TEMPLATE GENERATED TESTCASE FILE
|
| 2 |
+
Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b.c
|
| 3 |
+
Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
|
| 4 |
+
Template File: sources-sink-66b.tmpl.c
|
| 5 |
+
*/
|
| 6 |
+
/*
|
| 7 |
+
* @description
|
| 8 |
+
* CWE: 122 Heap Based Buffer Overflow
|
| 9 |
+
* BadSource: Allocate using malloc() and set data pointer to a small buffer
|
| 10 |
+
* GoodSource: Allocate using malloc() and set data pointer to a large buffer
|
| 11 |
+
* Sinks: loop
|
| 12 |
+
* BadSink : Copy int64_t array to data using a loop
|
| 13 |
+
* Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
|
| 14 |
+
*
|
| 15 |
+
* */
|
| 16 |
+
|
| 17 |
+
#include "std_testcase.h"
|
| 18 |
+
|
| 19 |
+
#ifndef OMITBAD
|
| 20 |
+
|
| 21 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b_badSink(int64_t * dataArray[])
|
| 22 |
+
{
|
| 23 |
+
/* copy data out of dataArray */
|
| 24 |
+
int64_t * data = dataArray[2];
|
| 25 |
+
{
|
| 26 |
+
int64_t source[100] = {0}; /* fill with 0's */
|
| 27 |
+
{
|
| 28 |
+
size_t i;
|
| 29 |
+
/* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
|
| 30 |
+
for (i = 0; i < 100; i++)
|
| 31 |
+
{
|
| 32 |
+
data[i] = source[i];
|
| 33 |
+
}
|
| 34 |
+
printLongLongLine(data[0]);
|
| 35 |
+
free(data);
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#endif /* OMITBAD */
|
| 41 |
+
|
| 42 |
+
#ifndef OMITGOOD
|
| 43 |
+
|
| 44 |
+
/* goodG2B uses the GoodSource with the BadSink */
|
| 45 |
+
void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_loop_66b_goodG2BSink(int64_t * dataArray[])
|
| 46 |
+
{
|
| 47 |
+
int64_t * data = dataArray[2];
|
| 48 |
+
{
|
| 49 |
+
int64_t source[100] = {0}; /* fill with 0's */
|
| 50 |
+
{
|
| 51 |
+
size_t i;
|
| 52 |
+
/* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
|
| 53 |
+
for (i = 0; i < 100; i++)
|
| 54 |
+
{
|
| 55 |
+
data[i] = source[i];
|
| 56 |
+
}
|
| 57 |
+
printLongLongLine(data[0]);
|
| 58 |
+
free(data);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
#endif /* OMITGOOD */
|
pool/shard000/C/0008767_test.c
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// $Id: test.c 1682 2009-02-05 01:07:09Z shodan $
|
| 3 |
+
//
|
| 4 |
+
|
| 5 |
+
//
|
| 6 |
+
// Copyright (c) 2008, Andrew Aksyonoff. All rights reserved.
|
| 7 |
+
//
|
| 8 |
+
// This program is free software; you can redistribute it and/or modify
|
| 9 |
+
// it under the terms of the GNU Library General Public License. You should
|
| 10 |
+
// have received a copy of the LGPL license along with this program; if you
|
| 11 |
+
// did not, you can find it at http://www.gnu.org/
|
| 12 |
+
//
|
| 13 |
+
|
| 14 |
+
#include <stdarg.h>
|
| 15 |
+
#include <stdio.h>
|
| 16 |
+
#include <stdlib.h>
|
| 17 |
+
|
| 18 |
+
#if _WIN32
|
| 19 |
+
#include <winsock2.h>
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#include "sphinxclient.h"
|
| 23 |
+
|
| 24 |
+
void die ( const char * template, ... )
|
| 25 |
+
{
|
| 26 |
+
va_list ap;
|
| 27 |
+
va_start ( ap, template );
|
| 28 |
+
printf ( "FATAL: " );
|
| 29 |
+
vprintf ( template, ap );
|
| 30 |
+
printf ( "\n" );
|
| 31 |
+
va_end ( ap );
|
| 32 |
+
exit ( 1 );
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
void net_init ()
|
| 37 |
+
{
|
| 38 |
+
#if _WIN32
|
| 39 |
+
// init WSA on Windows
|
| 40 |
+
WSADATA wsa_data;
|
| 41 |
+
int wsa_startup_err;
|
| 42 |
+
|
| 43 |
+
wsa_startup_err = WSAStartup ( WINSOCK_VERSION, &wsa_data );
|
| 44 |
+
if ( wsa_startup_err )
|
| 45 |
+
die ( "failed to initialize WinSock2: error %d", wsa_startup_err );
|
| 46 |
+
#endif
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
void test_query ( sphinx_client * client, sphinx_bool test_extras )
|
| 51 |
+
{
|
| 52 |
+
sphinx_result * res;
|
| 53 |
+
const char *query, *index;
|
| 54 |
+
int i, j, k;
|
| 55 |
+
unsigned int * mva;
|
| 56 |
+
const char * field_names[2];
|
| 57 |
+
int field_weights[2];
|
| 58 |
+
|
| 59 |
+
sphinx_uint64_t override_docid = 4;
|
| 60 |
+
unsigned int override_value = 456;
|
| 61 |
+
|
| 62 |
+
query = "test";
|
| 63 |
+
index = "test1";
|
| 64 |
+
|
| 65 |
+
field_names[0] = "title";
|
| 66 |
+
field_names[1] = "content";
|
| 67 |
+
field_weights[0] = 100;
|
| 68 |
+
field_weights[1] = 1;
|
| 69 |
+
sphinx_set_field_weights ( client, 2, field_names, field_weights );
|
| 70 |
+
field_weights[0] = 1;
|
| 71 |
+
field_weights[1] = 1;
|
| 72 |
+
|
| 73 |
+
if ( test_extras )
|
| 74 |
+
{
|
| 75 |
+
sphinx_add_override ( client, "group_id", &override_docid, 1, &override_value );
|
| 76 |
+
sphinx_set_select ( client, "*, group_id*1000+@id*10 AS q" );
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
res = sphinx_query ( client, query, index, NULL );
|
| 80 |
+
if ( !res )
|
| 81 |
+
die ( "query failed: %s", sphinx_error(client) );
|
| 82 |
+
|
| 83 |
+
printf ( "Query '%s' retrieved %d of %d matches in %d.%03d sec.\n",
|
| 84 |
+
query, res->total, res->total_found, res->time_msec/1000, res->time_msec%1000 );
|
| 85 |
+
printf ( "Query stats:\n" );
|
| 86 |
+
for ( i=0; i<res->num_words; i++ )
|
| 87 |
+
printf ( "\t'%s' found %d times in %d documents\n",
|
| 88 |
+
res->words[i].word, res->words[i].hits, res->words[i].docs );
|
| 89 |
+
|
| 90 |
+
printf ( "\nMatches:\n" );
|
| 91 |
+
for ( i=0; i<res->num_matches; i++ )
|
| 92 |
+
{
|
| 93 |
+
printf ( "%d. doc_id=%d, weight=%d", 1+i,
|
| 94 |
+
(int)sphinx_get_id ( res, i ), sphinx_get_weight ( res, i ) );
|
| 95 |
+
|
| 96 |
+
for ( j=0; j<res->num_attrs; j++ )
|
| 97 |
+
{
|
| 98 |
+
printf ( ", %s=", res->attr_names[j] );
|
| 99 |
+
switch ( res->attr_types[j] )
|
| 100 |
+
{
|
| 101 |
+
case SPH_ATTR_MULTI | SPH_ATTR_INTEGER:
|
| 102 |
+
mva = sphinx_get_mva ( res, i, j );
|
| 103 |
+
printf ( "(" );
|
| 104 |
+
for ( k=0; k<(int)mva[0]; k++ )
|
| 105 |
+
printf ( k ? ",%u" : "%u", mva[1+k] );
|
| 106 |
+
printf ( ")" );
|
| 107 |
+
break;
|
| 108 |
+
|
| 109 |
+
case SPH_ATTR_FLOAT: printf ( "%f", sphinx_get_float ( res, i, j ) ); break;
|
| 110 |
+
default: printf ( "%u", (unsigned int)sphinx_get_int ( res, i, j ) ); break;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
printf ( "\n" );
|
| 115 |
+
}
|
| 116 |
+
printf ( "\n" );
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
void test_excerpt ( sphinx_client * client )
|
| 121 |
+
{
|
| 122 |
+
const char * docs[] =
|
| 123 |
+
{
|
| 124 |
+
"this is my test text to be highlighted, and for the sake of the testing we need to pump its length somewhat",
|
| 125 |
+
"another test text to be highlighted, below limit",
|
| 126 |
+
"test number three, without phrase match",
|
| 127 |
+
"final test, not only without phrase match, but also above limit and with swapped phrase text test as well"
|
| 128 |
+
};
|
| 129 |
+
const int ndocs = sizeof(docs)/sizeof(docs[0]);
|
| 130 |
+
const char * words = "test text";
|
| 131 |
+
const char * index = "test1";
|
| 132 |
+
sphinx_excerpt_options opts;
|
| 133 |
+
char ** res;
|
| 134 |
+
int i, j;
|
| 135 |
+
|
| 136 |
+
sphinx_init_excerpt_options ( &opts );
|
| 137 |
+
opts.limit = 60;
|
| 138 |
+
opts.around = 3;
|
| 139 |
+
|
| 140 |
+
for ( j=0; j<2; j++ )
|
| 141 |
+
{
|
| 142 |
+
opts.exact_phrase = j;
|
| 143 |
+
printf ( "exact_phrase=%d\n", j );
|
| 144 |
+
|
| 145 |
+
res = sphinx_build_excerpts ( client, ndocs, docs, index, words, &opts );
|
| 146 |
+
if ( !res )
|
| 147 |
+
die ( "query failed: %s", sphinx_error(client) );
|
| 148 |
+
|
| 149 |
+
for ( i=0; i<ndocs; i++ )
|
| 150 |
+
printf ( "n=%d, res=%s\n", 1+i, res[i] );
|
| 151 |
+
printf ( "\n" );
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
void test_update ( sphinx_client * client )
|
| 157 |
+
{
|
| 158 |
+
const char * attr = "group_id";
|
| 159 |
+
const sphinx_uint64_t id = 2;
|
| 160 |
+
const sphinx_int64_t val = 123;
|
| 161 |
+
int res;
|
| 162 |
+
|
| 163 |
+
res = sphinx_update_attributes ( client, "test1", 1, &attr, 1, &id, &val );
|
| 164 |
+
if ( res<0 )
|
| 165 |
+
printf ( "update failed: %s\n\n", sphinx_error(client) );
|
| 166 |
+
else
|
| 167 |
+
printf ( "update success, %d rows updated\n\n", res );
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
void test_keywords ( sphinx_client * client )
|
| 172 |
+
{
|
| 173 |
+
int i, nwords;
|
| 174 |
+
sphinx_keyword_info * words;
|
| 175 |
+
|
| 176 |
+
words = sphinx_build_keywords ( client, "hello test one", "test1", SPH_TRUE, &nwords );
|
| 177 |
+
if ( !words )
|
| 178 |
+
{
|
| 179 |
+
printf ( "build_keywords failed: %s\n\n", sphinx_error(client) );
|
| 180 |
+
} else
|
| 181 |
+
{
|
| 182 |
+
printf ( "build_keywords result:\n" );
|
| 183 |
+
for ( i=0; i<nwords; i++ )
|
| 184 |
+
printf ( "%d. tokenized=%s, normalized=%s, docs=%d, hits=%d\n", 1+i,
|
| 185 |
+
words[i].tokenized, words[i].normalized,
|
| 186 |
+
words[i].num_docs, words[i].num_hits );
|
| 187 |
+
printf ( "\n" );
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
int main ()
|
| 193 |
+
{
|
| 194 |
+
sphinx_client * client;
|
| 195 |
+
|
| 196 |
+
net_init ();
|
| 197 |
+
|
| 198 |
+
client = sphinx_create ( SPH_TRUE );
|
| 199 |
+
if ( !client )
|
| 200 |
+
die ( "failed to create client" );
|
| 201 |
+
|
| 202 |
+
test_query ( client, SPH_FALSE );
|
| 203 |
+
test_excerpt ( client );
|
| 204 |
+
test_update ( client );
|
| 205 |
+
test_query ( client, SPH_FALSE );
|
| 206 |
+
test_keywords ( client );
|
| 207 |
+
test_query ( client, SPH_TRUE );
|
| 208 |
+
|
| 209 |
+
sphinx_destroy ( client );
|
| 210 |
+
return 0;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
//
|
| 214 |
+
// $Id: test.c 1682 2009-02-05 01:07:09Z shodan $
|
| 215 |
+
//
|
pool/shard000/C/0008783_ablk_helper.c
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Shared async block cipher helpers
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2012 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
|
| 5 |
+
*
|
| 6 |
+
* Based on aesni-intel_glue.c by:
|
| 7 |
+
* Copyright (C) 2008, Intel Corp.
|
| 8 |
+
* Author: Huang Ying <ying.huang@intel.com>
|
| 9 |
+
*
|
| 10 |
+
* This program is free software; you can redistribute it and/or modify
|
| 11 |
+
* it under the terms of the GNU General Public License as published by
|
| 12 |
+
* the Free Software Foundation; either version 2 of the License, or
|
| 13 |
+
* (at your option) any later version.
|
| 14 |
+
*
|
| 15 |
+
* This program is distributed in the hope that it will be useful,
|
| 16 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 18 |
+
* GNU General Public License for more details.
|
| 19 |
+
*
|
| 20 |
+
* You should have received a copy of the GNU General Public License
|
| 21 |
+
* along with this program; if not, write to the Free Software
|
| 22 |
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
| 23 |
+
* USA
|
| 24 |
+
*
|
| 25 |
+
*/
|
| 26 |
+
|
| 27 |
+
#include <linux/kernel.h>
|
| 28 |
+
#include <linux/crypto.h>
|
| 29 |
+
#include <linux/err.h>
|
| 30 |
+
#include <linux/init.h>
|
| 31 |
+
#include <linux/module.h>
|
| 32 |
+
#include <linux/hardirq.h>
|
| 33 |
+
#include <crypto/algapi.h>
|
| 34 |
+
#include <crypto/cryptd.h>
|
| 35 |
+
#include <crypto/ablk_helper.h>
|
| 36 |
+
#include <asm-generic/simd.h>
|
| 37 |
+
|
| 38 |
+
int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
|
| 39 |
+
unsigned int key_len)
|
| 40 |
+
{
|
| 41 |
+
struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
|
| 42 |
+
struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
|
| 43 |
+
int err;
|
| 44 |
+
|
| 45 |
+
crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
|
| 46 |
+
crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
|
| 47 |
+
& CRYPTO_TFM_REQ_MASK);
|
| 48 |
+
err = crypto_ablkcipher_setkey(child, key, key_len);
|
| 49 |
+
crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
|
| 50 |
+
& CRYPTO_TFM_RES_MASK);
|
| 51 |
+
return err;
|
| 52 |
+
}
|
| 53 |
+
EXPORT_SYMBOL_GPL(ablk_set_key);
|
| 54 |
+
|
| 55 |
+
int __ablk_encrypt(struct ablkcipher_request *req)
|
| 56 |
+
{
|
| 57 |
+
struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
|
| 58 |
+
struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
|
| 59 |
+
struct blkcipher_desc desc;
|
| 60 |
+
|
| 61 |
+
desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
|
| 62 |
+
desc.info = req->info;
|
| 63 |
+
desc.flags = 0;
|
| 64 |
+
|
| 65 |
+
return crypto_blkcipher_crt(desc.tfm)->encrypt(
|
| 66 |
+
&desc, req->dst, req->src, req->nbytes);
|
| 67 |
+
}
|
| 68 |
+
EXPORT_SYMBOL_GPL(__ablk_encrypt);
|
| 69 |
+
|
| 70 |
+
int ablk_encrypt(struct ablkcipher_request *req)
|
| 71 |
+
{
|
| 72 |
+
struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
|
| 73 |
+
struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
|
| 74 |
+
|
| 75 |
+
if (!may_use_simd()) {
|
| 76 |
+
struct ablkcipher_request *cryptd_req =
|
| 77 |
+
ablkcipher_request_ctx(req);
|
| 78 |
+
|
| 79 |
+
memcpy(cryptd_req, req, sizeof(*req));
|
| 80 |
+
ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
|
| 81 |
+
|
| 82 |
+
return crypto_ablkcipher_encrypt(cryptd_req);
|
| 83 |
+
} else {
|
| 84 |
+
return __ablk_encrypt(req);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
EXPORT_SYMBOL_GPL(ablk_encrypt);
|
| 88 |
+
|
| 89 |
+
int ablk_decrypt(struct ablkcipher_request *req)
|
| 90 |
+
{
|
| 91 |
+
struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
|
| 92 |
+
struct async_helper_ctx *ctx = crypto_ablkcipher_ctx(tfm);
|
| 93 |
+
|
| 94 |
+
if (!may_use_simd()) {
|
| 95 |
+
struct ablkcipher_request *cryptd_req =
|
| 96 |
+
ablkcipher_request_ctx(req);
|
| 97 |
+
|
| 98 |
+
memcpy(cryptd_req, req, sizeof(*req));
|
| 99 |
+
ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
|
| 100 |
+
|
| 101 |
+
return crypto_ablkcipher_decrypt(cryptd_req);
|
| 102 |
+
} else {
|
| 103 |
+
struct blkcipher_desc desc;
|
| 104 |
+
|
| 105 |
+
desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
|
| 106 |
+
desc.info = req->info;
|
| 107 |
+
desc.flags = 0;
|
| 108 |
+
|
| 109 |
+
return crypto_blkcipher_crt(desc.tfm)->decrypt(
|
| 110 |
+
&desc, req->dst, req->src, req->nbytes);
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
EXPORT_SYMBOL_GPL(ablk_decrypt);
|
| 114 |
+
|
| 115 |
+
void ablk_exit(struct crypto_tfm *tfm)
|
| 116 |
+
{
|
| 117 |
+
struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm);
|
| 118 |
+
|
| 119 |
+
cryptd_free_ablkcipher(ctx->cryptd_tfm);
|
| 120 |
+
}
|
| 121 |
+
EXPORT_SYMBOL_GPL(ablk_exit);
|
| 122 |
+
|
| 123 |
+
int ablk_init_common(struct crypto_tfm *tfm, const char *drv_name)
|
| 124 |
+
{
|
| 125 |
+
struct async_helper_ctx *ctx = crypto_tfm_ctx(tfm);
|
| 126 |
+
struct cryptd_ablkcipher *cryptd_tfm;
|
| 127 |
+
|
| 128 |
+
cryptd_tfm = cryptd_alloc_ablkcipher(drv_name, 0, 0);
|
| 129 |
+
if (IS_ERR(cryptd_tfm))
|
| 130 |
+
return PTR_ERR(cryptd_tfm);
|
| 131 |
+
|
| 132 |
+
ctx->cryptd_tfm = cryptd_tfm;
|
| 133 |
+
tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) +
|
| 134 |
+
crypto_ablkcipher_reqsize(&cryptd_tfm->base);
|
| 135 |
+
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
EXPORT_SYMBOL_GPL(ablk_init_common);
|
| 139 |
+
|
| 140 |
+
int ablk_init(struct crypto_tfm *tfm)
|
| 141 |
+
{
|
| 142 |
+
char drv_name[CRYPTO_MAX_ALG_NAME];
|
| 143 |
+
|
| 144 |
+
snprintf(drv_name, sizeof(drv_name), "__driver-%s",
|
| 145 |
+
crypto_tfm_alg_driver_name(tfm));
|
| 146 |
+
|
| 147 |
+
return ablk_init_common(tfm, drv_name);
|
| 148 |
+
}
|
| 149 |
+
EXPORT_SYMBOL_GPL(ablk_init);
|
| 150 |
+
|
| 151 |
+
MODULE_LICENSE("GPL");
|
pool/shard000/C/0008799_aotrigger.c
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
gcc -DNIDAQ_MAJOR=254 -o aotrigger aotrigger.c -lm
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
#include <stdio.h>
|
| 6 |
+
#include <stdlib.h>
|
| 7 |
+
#include <unistd.h>
|
| 8 |
+
#include <sys/types.h>
|
| 9 |
+
#include <sys/stat.h>
|
| 10 |
+
#include <sys/ioctl.h>
|
| 11 |
+
#include <fcntl.h>
|
| 12 |
+
#include <math.h>
|
| 13 |
+
#include "nidaq.h"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
#define MAXPOINTS 600
|
| 17 |
+
#define MAXBUFFERS 40
|
| 18 |
+
#define UPDATERATE 100000
|
| 19 |
+
#define PERIOD 200
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
void AO_add_channel( int fd, int channel, int bipolar,
|
| 23 |
+
int reglitch, int extref, int groundref )
|
| 24 |
+
{
|
| 25 |
+
unsigned int u = 0;
|
| 26 |
+
|
| 27 |
+
if ( bipolar )
|
| 28 |
+
u |= 0x0001;
|
| 29 |
+
|
| 30 |
+
if ( reglitch )
|
| 31 |
+
u |= 0x0002;
|
| 32 |
+
|
| 33 |
+
if ( extref )
|
| 34 |
+
u |= 0x0004;
|
| 35 |
+
|
| 36 |
+
if ( groundref )
|
| 37 |
+
u |= 0x0008;
|
| 38 |
+
|
| 39 |
+
channel &= 0x1;
|
| 40 |
+
u |= channel << 8;
|
| 41 |
+
|
| 42 |
+
fprintf( stderr, "added channel %d\n", channel );
|
| 43 |
+
|
| 44 |
+
ioctl( fd, NIDAQAOADDCHANNEL, u );
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
void init_sine( signed short buf[], int n )
|
| 49 |
+
{
|
| 50 |
+
int k;
|
| 51 |
+
|
| 52 |
+
for ( k=0; k<MAXPOINTS; k++ )
|
| 53 |
+
buf[k] = 2047*sin( 2.0*M_PI*(k+1)/PERIOD );
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
int main( int argc, char *argv[] )
|
| 58 |
+
{
|
| 59 |
+
int ao;
|
| 60 |
+
signed short *buf;
|
| 61 |
+
|
| 62 |
+
buf = malloc( 4*MAXPOINTS);
|
| 63 |
+
if ( buf == NULL ) {
|
| 64 |
+
fprintf( stderr, "out of memory\n" );
|
| 65 |
+
exit( 0 );
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
ao = open( "/dev/niao0", O_WRONLY );
|
| 69 |
+
|
| 70 |
+
AO_add_channel( ao, 0, 1, 0, 0, 0 );
|
| 71 |
+
|
| 72 |
+
ioctl( ao, NIDAQAOSTART, 1 );
|
| 73 |
+
ioctl( ao, NIDAQAORATE, UPDATERATE );
|
| 74 |
+
ioctl( ao, NIDAQAOBUFFERS, MAXBUFFERS );
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
ioctl( ao, NIDAQLOWVALUE, 0 );
|
| 78 |
+
ioctl( ao, NIDAQHIGHVALUE, 0 );
|
| 79 |
+
ioctl( ao, NIDAQTRIGGERMODE, 1 );
|
| 80 |
+
ioctl( ao, NIDAQTRIGGERSOURCE, 0 );
|
| 81 |
+
ioctl( ao, NIDAQAOANALOGTRIGGER );
|
| 82 |
+
*/
|
| 83 |
+
|
| 84 |
+
ioctl( ao, NIDAQAOSTART1SOURCE, 2 );
|
| 85 |
+
|
| 86 |
+
init_sine( buf, MAXPOINTS );
|
| 87 |
+
write( ao, buf, 2*MAXPOINTS );
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
close( ao );
|
| 91 |
+
free( buf );
|
| 92 |
+
|
| 93 |
+
return 0;
|
| 94 |
+
}
|
pool/shard000/C/0008804_sz_string.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* $Id$ */
|
| 2 |
+
#include "softbot.h"
|
| 3 |
+
#include "sz_string.h"
|
| 4 |
+
|
| 5 |
+
char *sz_strncat(char *dest, const char *src, size_t n)
|
| 6 |
+
{
|
| 7 |
+
char *buf=NULL;
|
| 8 |
+
|
| 9 |
+
if (n < 0) {
|
| 10 |
+
warn("n is %d. setting it 0", (int)n);
|
| 11 |
+
n = 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
if (strlen(src) >= n) {
|
| 15 |
+
int orig_len = strlen(dest);
|
| 16 |
+
int n2=0;
|
| 17 |
+
|
| 18 |
+
n2 = n-1;
|
| 19 |
+
buf = strncat(dest, src, n2);
|
| 20 |
+
dest[orig_len+n-1] = '\0';
|
| 21 |
+
}
|
| 22 |
+
else {
|
| 23 |
+
buf = strncat(dest, src, n);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
return buf;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
char *sz_strncpy(char *dest, const char *src, size_t n)
|
| 31 |
+
{
|
| 32 |
+
char *buf=NULL;
|
| 33 |
+
|
| 34 |
+
if (n < 0) {
|
| 35 |
+
warn("n is %d. setting it 0", (int)n);
|
| 36 |
+
n = 0;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
buf = strncpy(dest, src, n);
|
| 40 |
+
dest[n-1] = '\0';
|
| 41 |
+
|
| 42 |
+
return buf;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
int sz_snprintf(char *str, size_t size, const char *format, ...)
|
| 46 |
+
{
|
| 47 |
+
int rv=0;
|
| 48 |
+
va_list args;
|
| 49 |
+
|
| 50 |
+
if (size < 0) {
|
| 51 |
+
warn("size is %d. setting it 0", (int)size);
|
| 52 |
+
size = 0;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
va_start(args, format);
|
| 56 |
+
rv = vsnprintf(str, size, format, args);
|
| 57 |
+
va_end(args);
|
| 58 |
+
|
| 59 |
+
str[size-1] = '\0';
|
| 60 |
+
|
| 61 |
+
return rv;
|
| 62 |
+
}
|
pool/shard000/C/0008812_bigdict.c
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
| 3 |
+
* All rights reserved.
|
| 4 |
+
*
|
| 5 |
+
* This source code is licensed under both the BSD-style license (found in the
|
| 6 |
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
| 7 |
+
* in the COPYING file in the root directory of this source tree).
|
| 8 |
+
* You may select, at your option, one of the above-listed licenses.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <assert.h>
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stddef.h>
|
| 14 |
+
#include <stdlib.h>
|
| 15 |
+
#include <stdint.h>
|
| 16 |
+
#include "datagen.h"
|
| 17 |
+
#include "mem.h"
|
| 18 |
+
#define ZSTD_STATIC_LINKING_ONLY
|
| 19 |
+
#include "zstd.h"
|
| 20 |
+
|
| 21 |
+
static int
|
| 22 |
+
compress(ZSTD_CCtx* cctx, ZSTD_DCtx* dctx,
|
| 23 |
+
void* dst, size_t dstCapacity,
|
| 24 |
+
void const* src, size_t srcSize,
|
| 25 |
+
void* roundtrip, ZSTD_EndDirective end)
|
| 26 |
+
{
|
| 27 |
+
ZSTD_inBuffer in = {src, srcSize, 0};
|
| 28 |
+
ZSTD_outBuffer out = {dst, dstCapacity, 0};
|
| 29 |
+
int ended = 0;
|
| 30 |
+
|
| 31 |
+
while (!ended && (in.pos < in.size || out.pos > 0)) {
|
| 32 |
+
size_t rc;
|
| 33 |
+
out.pos = 0;
|
| 34 |
+
rc = ZSTD_compressStream2(cctx, &out, &in, end);
|
| 35 |
+
if (ZSTD_isError(rc))
|
| 36 |
+
return 1;
|
| 37 |
+
if (end == ZSTD_e_end && rc == 0)
|
| 38 |
+
ended = 1;
|
| 39 |
+
{
|
| 40 |
+
ZSTD_inBuffer rtIn = {dst, out.pos, 0};
|
| 41 |
+
ZSTD_outBuffer rtOut = {roundtrip, srcSize, 0};
|
| 42 |
+
rc = 1;
|
| 43 |
+
while (rtIn.pos < rtIn.size || rtOut.pos > 0) {
|
| 44 |
+
rtOut.pos = 0;
|
| 45 |
+
rc = ZSTD_decompressStream(dctx, &rtOut, &rtIn);
|
| 46 |
+
if (ZSTD_isError(rc)) {
|
| 47 |
+
fprintf(stderr, "Decompression error: %s\n", ZSTD_getErrorName(rc));
|
| 48 |
+
return 1;
|
| 49 |
+
}
|
| 50 |
+
if (rc == 0)
|
| 51 |
+
break;
|
| 52 |
+
}
|
| 53 |
+
if (ended && rc != 0) {
|
| 54 |
+
fprintf(stderr, "Frame not finished!\n");
|
| 55 |
+
return 1;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return 0;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
int main(int argc, const char** argv)
|
| 64 |
+
{
|
| 65 |
+
ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
| 66 |
+
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
| 67 |
+
const size_t dataSize = (size_t)1 << 30;
|
| 68 |
+
const size_t outSize = ZSTD_compressBound(dataSize);
|
| 69 |
+
const size_t bufferSize = (size_t)1 << 31;
|
| 70 |
+
char* buffer = (char*)malloc(bufferSize);
|
| 71 |
+
void* out = malloc(outSize);
|
| 72 |
+
void* roundtrip = malloc(dataSize);
|
| 73 |
+
(void)argc;
|
| 74 |
+
(void)argv;
|
| 75 |
+
|
| 76 |
+
if (!buffer || !out || !roundtrip || !cctx || !dctx) {
|
| 77 |
+
fprintf(stderr, "Allocation failure\n");
|
| 78 |
+
return 1;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
|
| 82 |
+
return 1;
|
| 83 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1)))
|
| 84 |
+
return 1;
|
| 85 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9)))
|
| 86 |
+
return 1;
|
| 87 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1)))
|
| 88 |
+
return 1;
|
| 89 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt)))
|
| 90 |
+
return 1;
|
| 91 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7)))
|
| 92 |
+
return 1;
|
| 93 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7)))
|
| 94 |
+
return 1;
|
| 95 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1)))
|
| 96 |
+
return 1;
|
| 97 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10)))
|
| 98 |
+
return 1;
|
| 99 |
+
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10)))
|
| 100 |
+
return 1;
|
| 101 |
+
|
| 102 |
+
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31)))
|
| 103 |
+
return 1;
|
| 104 |
+
|
| 105 |
+
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
|
| 106 |
+
|
| 107 |
+
/* Compress 30 GB */
|
| 108 |
+
{
|
| 109 |
+
int i;
|
| 110 |
+
for (i = 0; i < 10; ++i) {
|
| 111 |
+
fprintf(stderr, "Compressing 1 GB\n");
|
| 112 |
+
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue))
|
| 113 |
+
return 1;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
fprintf(stderr, "Compressing 1 GB\n");
|
| 117 |
+
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end))
|
| 118 |
+
return 1;
|
| 119 |
+
|
| 120 |
+
fprintf(stderr, "Success!\n");
|
| 121 |
+
|
| 122 |
+
free(roundtrip);
|
| 123 |
+
free(out);
|
| 124 |
+
free(buffer);
|
| 125 |
+
ZSTD_freeDCtx(dctx);
|
| 126 |
+
ZSTD_freeCCtx(cctx);
|
| 127 |
+
return 0;
|
| 128 |
+
}
|
pool/shard000/C/0008813_xsiget.c
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "../apue.h"
|
| 2 |
+
|
| 3 |
+
#define USE_EXCL
|
| 4 |
+
#define USE_FTOK
|
| 5 |
+
|
| 6 |
+
#include <sys/msg.h>
|
| 7 |
+
#include <sys/sem.h>
|
| 8 |
+
#include <sys/shm.h>
|
| 9 |
+
|
| 10 |
+
int main (int argc, char *argv[])
|
| 11 |
+
{
|
| 12 |
+
if (argc < 3)
|
| 13 |
+
{
|
| 14 |
+
printf ("Usage: xsiget type <msg|sem|shm> projid\n");
|
| 15 |
+
return -1;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
char const* type = argv[1];
|
| 19 |
+
int id = atoi (argv[2]);
|
| 20 |
+
|
| 21 |
+
key_t key = IPC_PRIVATE;
|
| 22 |
+
#ifdef USE_FTOK
|
| 23 |
+
key = ftok ("./xsiget.c", id);
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
int flag = IPC_CREAT;
|
| 27 |
+
#ifdef USE_EXCL
|
| 28 |
+
flag |= IPC_EXCL;
|
| 29 |
+
#endif
|
| 30 |
+
|
| 31 |
+
if (strcasecmp (type, "msg") == 0)
|
| 32 |
+
{
|
| 33 |
+
int ret = msgget (key, flag);
|
| 34 |
+
if (ret < 0)
|
| 35 |
+
err_sys ("msgget failed");
|
| 36 |
+
|
| 37 |
+
printf ("create msgqueue %d with key 0x%08x ok\n", ret, key);
|
| 38 |
+
}
|
| 39 |
+
else if (strcasecmp (type, "sem") == 0)
|
| 40 |
+
{
|
| 41 |
+
int ret = semget (key, 1, flag);
|
| 42 |
+
if (ret < 0)
|
| 43 |
+
err_sys ("semget failed");
|
| 44 |
+
|
| 45 |
+
printf ("create semphore %d with key 0x%08x ok\n", ret, key);
|
| 46 |
+
}
|
| 47 |
+
else if (strcasecmp (type, "shm") == 0)
|
| 48 |
+
{
|
| 49 |
+
int ret = shmget (key, 1024, flag);
|
| 50 |
+
if (ret < 0)
|
| 51 |
+
err_sys ("shmget failed");
|
| 52 |
+
|
| 53 |
+
printf ("create share memory %d with key 0x%08x ok\n", ret, key);
|
| 54 |
+
}
|
| 55 |
+
else
|
| 56 |
+
printf ("unknown type %s\n", type);
|
| 57 |
+
|
| 58 |
+
//sleep (60);
|
| 59 |
+
return 0;
|
| 60 |
+
}
|
pool/shard000/C/0008818_device.c
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
#include <linux/kernel.h>
|
| 4 |
+
#include <linux/gpio.h>
|
| 5 |
+
#include <linux/init.h>
|
| 6 |
+
#include <linux/irq.h>
|
| 7 |
+
#include <linux/phy.h>
|
| 8 |
+
#include <linux/platform_device.h>
|
| 9 |
+
#include <linux/serial.h>
|
| 10 |
+
#include <linux/serial_8250.h>
|
| 11 |
+
|
| 12 |
+
#include <variant/hardware.h>
|
| 13 |
+
#include <variant/dmac.h>
|
| 14 |
+
|
| 15 |
+
#include <platform/gpio.h>
|
| 16 |
+
|
| 17 |
+
#define GPIO3_INTNUM 3
|
| 18 |
+
#define UART_INTNUM 4
|
| 19 |
+
#define GMAC_INTNUM 5
|
| 20 |
+
|
| 21 |
+
static const signed char gpio3_irq_mappings[] = {
|
| 22 |
+
S6_INTC_GPIO(3),
|
| 23 |
+
-1
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
static const signed char uart_irq_mappings[] = {
|
| 27 |
+
S6_INTC_UART(0),
|
| 28 |
+
S6_INTC_UART(1),
|
| 29 |
+
-1,
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
static const signed char gmac_irq_mappings[] = {
|
| 33 |
+
S6_INTC_GMAC_STAT,
|
| 34 |
+
S6_INTC_GMAC_ERR,
|
| 35 |
+
S6_INTC_DMA_HOSTTERMCNT(0),
|
| 36 |
+
S6_INTC_DMA_HOSTTERMCNT(1),
|
| 37 |
+
-1
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
const signed char *platform_irq_mappings[NR_IRQS] = {
|
| 41 |
+
[GPIO3_INTNUM] = gpio3_irq_mappings,
|
| 42 |
+
[UART_INTNUM] = uart_irq_mappings,
|
| 43 |
+
[GMAC_INTNUM] = gmac_irq_mappings,
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
static struct plat_serial8250_port serial_platform_data[] = {
|
| 47 |
+
{
|
| 48 |
+
.membase = (void *)S6_REG_UART + 0x0000,
|
| 49 |
+
.mapbase = S6_REG_UART + 0x0000,
|
| 50 |
+
.irq = UART_INTNUM,
|
| 51 |
+
.uartclk = S6_SCLK,
|
| 52 |
+
.regshift = 2,
|
| 53 |
+
.iotype = SERIAL_IO_MEM,
|
| 54 |
+
.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST,
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
.membase = (void *)S6_REG_UART + 0x1000,
|
| 58 |
+
.mapbase = S6_REG_UART + 0x1000,
|
| 59 |
+
.irq = UART_INTNUM,
|
| 60 |
+
.uartclk = S6_SCLK,
|
| 61 |
+
.regshift = 2,
|
| 62 |
+
.iotype = SERIAL_IO_MEM,
|
| 63 |
+
.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST,
|
| 64 |
+
},
|
| 65 |
+
{ },
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
static struct resource s6_gmac_resource[] = {
|
| 69 |
+
{
|
| 70 |
+
.name = "mem",
|
| 71 |
+
.start = (resource_size_t)S6_REG_GMAC,
|
| 72 |
+
.end = (resource_size_t)S6_REG_GMAC + 0x10000 - 1,
|
| 73 |
+
.flags = IORESOURCE_MEM,
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
.name = "dma",
|
| 77 |
+
.start = (resource_size_t)
|
| 78 |
+
DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACTX),
|
| 79 |
+
.end = (resource_size_t)
|
| 80 |
+
DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACTX) + 0x100 - 1,
|
| 81 |
+
.flags = IORESOURCE_DMA,
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
.name = "dma",
|
| 85 |
+
.start = (resource_size_t)
|
| 86 |
+
DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACRX),
|
| 87 |
+
.end = (resource_size_t)
|
| 88 |
+
DMA_CHNL(S6_REG_HIFDMA, S6_HIFDMA_GMACRX) + 0x100 - 1,
|
| 89 |
+
.flags = IORESOURCE_DMA,
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
.name = "io",
|
| 93 |
+
.start = (resource_size_t)S6_MEM_GMAC,
|
| 94 |
+
.end = (resource_size_t)S6_MEM_GMAC + 0x2000000 - 1,
|
| 95 |
+
.flags = IORESOURCE_IO,
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
.name = "irq",
|
| 99 |
+
.start = (resource_size_t)GMAC_INTNUM,
|
| 100 |
+
.flags = IORESOURCE_IRQ,
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
.name = "irq",
|
| 104 |
+
.start = (resource_size_t)PHY_POLL,
|
| 105 |
+
.flags = IORESOURCE_IRQ,
|
| 106 |
+
},
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
static int __init prepare_phy_irq(int pin)
|
| 110 |
+
{
|
| 111 |
+
int irq;
|
| 112 |
+
if (gpio_request(pin, "s6gmac_phy") < 0)
|
| 113 |
+
goto fail;
|
| 114 |
+
if (gpio_direction_input(pin) < 0)
|
| 115 |
+
goto free;
|
| 116 |
+
irq = gpio_to_irq(pin);
|
| 117 |
+
if (irq < 0)
|
| 118 |
+
goto free;
|
| 119 |
+
if (set_irq_type(irq, IRQ_TYPE_LEVEL_LOW) < 0)
|
| 120 |
+
goto free;
|
| 121 |
+
return irq;
|
| 122 |
+
free:
|
| 123 |
+
gpio_free(pin);
|
| 124 |
+
fail:
|
| 125 |
+
return PHY_POLL;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
static struct platform_device platform_devices[] = {
|
| 129 |
+
{
|
| 130 |
+
.name = "serial8250",
|
| 131 |
+
.id = PLAT8250_DEV_PLATFORM,
|
| 132 |
+
.dev = {
|
| 133 |
+
.platform_data = serial_platform_data,
|
| 134 |
+
},
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
.name = "s6gmac",
|
| 138 |
+
.id = 0,
|
| 139 |
+
.resource = s6_gmac_resource,
|
| 140 |
+
.num_resources = ARRAY_SIZE(s6_gmac_resource),
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
I2C_BOARD_INFO("m41t62", S6I2C_ADDR_M41T62),
|
| 144 |
+
},
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
static int __init device_init(void)
|
| 148 |
+
{
|
| 149 |
+
int i;
|
| 150 |
+
|
| 151 |
+
s6_gmac_resource[5].start = prepare_phy_irq(GPIO_PHY_IRQ);
|
| 152 |
+
|
| 153 |
+
for (i = 0; i < ARRAY_SIZE(platform_devices); i++)
|
| 154 |
+
platform_device_register(&platform_devices[i]);
|
| 155 |
+
return 0;
|
| 156 |
+
}
|
| 157 |
+
arch_initcall_sync(device_init);
|
pool/shard000/C/0008825_autotools-notebook-tab.c
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (C) 2010 - Jeff Johnston
|
| 3 |
+
*
|
| 4 |
+
* This program is free software; you can redistribute it and/or modify
|
| 5 |
+
* it under the terms of the GNU General Public License as published by
|
| 6 |
+
* the Free Software Foundation; either version 2, or (at your option)
|
| 7 |
+
* any later version.
|
| 8 |
+
*
|
| 9 |
+
* This program is distributed in the hope that it will be useful,
|
| 10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
+
* GNU General Public License for more details.
|
| 13 |
+
*
|
| 14 |
+
* You should have received a copy of the GNU General Public License
|
| 15 |
+
* along with this program; if not, write to the Free Software
|
| 16 |
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
#include "autotools-notebook-tab.h"
|
| 20 |
+
#include <codeslayer/codeslayer-utils.h>
|
| 21 |
+
|
| 22 |
+
static void autotools_notebook_tab_class_init (AutotoolsNotebookTabClass *klass);
|
| 23 |
+
static void autotools_notebook_tab_init (AutotoolsNotebookTab *notebook_tab);
|
| 24 |
+
static void autotools_notebook_tab_finalize (AutotoolsNotebookTab *notebook_tab);
|
| 25 |
+
|
| 26 |
+
static void close_action (AutotoolsNotebookTab *notebook_tab);
|
| 27 |
+
|
| 28 |
+
#define AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE(obj) \
|
| 29 |
+
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), AUTOTOOLS_NOTEBOOK_TAB_TYPE, AutotoolsNotebookTabPrivate))
|
| 30 |
+
|
| 31 |
+
typedef struct _AutotoolsNotebookTabPrivate AutotoolsNotebookTabPrivate;
|
| 32 |
+
|
| 33 |
+
struct _AutotoolsNotebookTabPrivate
|
| 34 |
+
{
|
| 35 |
+
GtkWidget *notebook_page;
|
| 36 |
+
GtkWidget *notebook;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
enum
|
| 40 |
+
{
|
| 41 |
+
CLOSE,
|
| 42 |
+
LAST_SIGNAL
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
static guint autotools_notebook_tab_signals[LAST_SIGNAL] = { 0 };
|
| 46 |
+
|
| 47 |
+
G_DEFINE_TYPE (AutotoolsNotebookTab, autotools_notebook_tab, GTK_TYPE_HBOX)
|
| 48 |
+
|
| 49 |
+
static void
|
| 50 |
+
autotools_notebook_tab_class_init (AutotoolsNotebookTabClass *klass)
|
| 51 |
+
{
|
| 52 |
+
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
| 53 |
+
|
| 54 |
+
autotools_notebook_tab_signals[CLOSE] =
|
| 55 |
+
g_signal_new ("close",
|
| 56 |
+
G_TYPE_FROM_CLASS (klass),
|
| 57 |
+
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
|
| 58 |
+
G_STRUCT_OFFSET (AutotoolsNotebookTabClass, close),
|
| 59 |
+
NULL, NULL,
|
| 60 |
+
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
| 61 |
+
|
| 62 |
+
gobject_class->finalize = (GObjectFinalizeFunc) autotools_notebook_tab_finalize;
|
| 63 |
+
|
| 64 |
+
g_type_class_add_private (klass, sizeof (AutotoolsNotebookTabPrivate));
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
static void
|
| 68 |
+
autotools_notebook_tab_init (AutotoolsNotebookTab *notebook_tab)
|
| 69 |
+
{
|
| 70 |
+
gtk_box_set_homogeneous (GTK_BOX (notebook_tab), FALSE);
|
| 71 |
+
gtk_box_set_spacing (GTK_BOX (notebook_tab), 0);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
static void
|
| 75 |
+
autotools_notebook_tab_finalize (AutotoolsNotebookTab *notebook_tab)
|
| 76 |
+
{
|
| 77 |
+
G_OBJECT_CLASS (autotools_notebook_tab_parent_class)->finalize ( G_OBJECT (notebook_tab));
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
GtkWidget*
|
| 81 |
+
autotools_notebook_tab_new (GtkWidget *notebook,
|
| 82 |
+
const gchar *label)
|
| 83 |
+
{
|
| 84 |
+
AutotoolsNotebookTabPrivate *priv;
|
| 85 |
+
GtkWidget *notebook_tab;
|
| 86 |
+
GtkWidget *text;
|
| 87 |
+
GtkWidget *button;
|
| 88 |
+
GtkWidget *image;
|
| 89 |
+
|
| 90 |
+
notebook_tab = g_object_new (autotools_notebook_tab_get_type (), NULL);
|
| 91 |
+
priv = AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab);
|
| 92 |
+
priv->notebook = notebook;
|
| 93 |
+
|
| 94 |
+
text = gtk_label_new (label);
|
| 95 |
+
|
| 96 |
+
button = gtk_button_new ();
|
| 97 |
+
|
| 98 |
+
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
|
| 99 |
+
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
|
| 100 |
+
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
|
| 101 |
+
gtk_container_add (GTK_CONTAINER (button), image);
|
| 102 |
+
codeslayer_utils_style_close_button (button);
|
| 103 |
+
|
| 104 |
+
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
| 105 |
+
G_CALLBACK (close_action), notebook_tab);
|
| 106 |
+
|
| 107 |
+
gtk_box_pack_start (GTK_BOX (notebook_tab), text, TRUE, TRUE, 1);
|
| 108 |
+
|
| 109 |
+
gtk_box_pack_start (GTK_BOX (notebook_tab), button, FALSE, FALSE, 1);
|
| 110 |
+
|
| 111 |
+
return notebook_tab;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
static void
|
| 115 |
+
close_action (AutotoolsNotebookTab *notebook_tab)
|
| 116 |
+
{
|
| 117 |
+
g_signal_emit_by_name ((gpointer) notebook_tab, "close");
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
GtkWidget*
|
| 121 |
+
autotools_notebook_tab_get_notebook_page (AutotoolsNotebookTab *notebook_tab)
|
| 122 |
+
{
|
| 123 |
+
return AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab)->notebook_page;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
void
|
| 127 |
+
autotools_notebook_tab_set_notebook_page (AutotoolsNotebookTab *notebook_tab,
|
| 128 |
+
GtkWidget *notebook_page)
|
| 129 |
+
{
|
| 130 |
+
AutotoolsNotebookTabPrivate *priv;
|
| 131 |
+
priv = AUTOTOOLS_NOTEBOOK_TAB_GET_PRIVATE (notebook_tab);
|
| 132 |
+
priv->notebook_page = notebook_page;
|
| 133 |
+
}
|
pool/shard000/C/0008837_discard.c
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <kernel.h>
|
| 2 |
+
#include <timer.h>
|
| 3 |
+
#include <kdata.h>
|
| 4 |
+
#include <printf.h>
|
| 5 |
+
#include <device.h>
|
| 6 |
+
#include <devtty.h>
|
| 7 |
+
#include <blkdev.h>
|
| 8 |
+
#include <carts.h>
|
| 9 |
+
|
| 10 |
+
/*
|
| 11 |
+
* Map handling: We have flexible paging. Each map table consists of a set of pages
|
| 12 |
+
* with the last page repeated to fill any holes.
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
extern uint8_t internal32k;
|
| 16 |
+
|
| 17 |
+
void pagemap_init(void)
|
| 18 |
+
{
|
| 19 |
+
int i;
|
| 20 |
+
|
| 21 |
+
/* kernel uses 4 5 6 7 0 1 2 3F */
|
| 22 |
+
for (i = 0x3e; i > 7; i--)
|
| 23 |
+
pagemap_add(i);
|
| 24 |
+
pagemap_add(3); /* was used while loading, replaced by 3F */
|
| 25 |
+
|
| 26 |
+
#ifdef SWAPDEV
|
| 27 |
+
for (i = 0; i < MAX_SWAPS; i++)
|
| 28 |
+
swapmap_init(i);
|
| 29 |
+
#endif
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
uint8_t platform_param(char *p)
|
| 33 |
+
{
|
| 34 |
+
return 0;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
static const char *sysname[] = {"Dragon", "COCO", "COCO3", "Unknown"};
|
| 38 |
+
|
| 39 |
+
struct cart_rom_id {
|
| 40 |
+
uint16_t hash;
|
| 41 |
+
uint8_t id;
|
| 42 |
+
const char *name;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
static const char empty[] = "(empty)";
|
| 46 |
+
|
| 47 |
+
struct cart_rom_id carts[] = {
|
| 48 |
+
{ 0x72B0, CART_DRAGONDOS, "DragonDOS" },
|
| 49 |
+
{ 0x9063, CART_DELTADOS, "DeltaDOS" },
|
| 50 |
+
{ 0xB400, 0, empty },
|
| 51 |
+
{ 0xC248, CART_RSDOS, "RS-DOS" },
|
| 52 |
+
/* This one is an oddity - we need to do more to know what it drives
|
| 53 |
+
The great thing is we can extract the MMIO addresses from it */
|
| 54 |
+
{ 0xB61B, CART_HDBDOS, "HDBDOS" },
|
| 55 |
+
{ 0xCF55, CART_HDBDOS, "HDBDOS" },
|
| 56 |
+
{ 0xE1BA, CART_ORCH90, "Orchestra-90 CC" },
|
| 57 |
+
{ 0x933E, CART_SDBOOT, "SDBOOT" },
|
| 58 |
+
{ 0x0000, 0, "No ROM" }
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
struct hdb_rom_id {
|
| 62 |
+
char key[2];
|
| 63 |
+
uint8_t id;
|
| 64 |
+
const char *name;
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
static struct hdb_rom_id hdb[] = {
|
| 68 |
+
{ "ID", CART_IDE, "IDE-CHS" },
|
| 69 |
+
{ "LB", CART_IDE, "IDE-LBA" },
|
| 70 |
+
{ "TC", CART_TC3, "TC^3" },
|
| 71 |
+
{ "KE", CART_KENTON, "KENTON" },
|
| 72 |
+
{ "LR", CART_LRTECH, "LRTECH" },
|
| 73 |
+
{ "HD", CART_HDII, "HD-II" },
|
| 74 |
+
{ "4-", CART_4N1, "4-N-1" },
|
| 75 |
+
{ "DW", CART_DRIVEWIRE, "Drivewire" },
|
| 76 |
+
{ "BE", CART_BECKER, "Becker" },
|
| 77 |
+
{ "J&", CART_JMCP, "J&M CP" },
|
| 78 |
+
{}
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
/* Find a cartridge or it's slot */
|
| 82 |
+
int cart_find(int id)
|
| 83 |
+
{
|
| 84 |
+
int i;
|
| 85 |
+
for (i = 0; i < id; i++) {
|
| 86 |
+
if (carttype[i] == id)
|
| 87 |
+
return i;
|
| 88 |
+
}
|
| 89 |
+
return -1;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
static struct cart_rom_id *cart_lookup(uint16_t hash)
|
| 93 |
+
{
|
| 94 |
+
struct cart_rom_id *cart = carts;
|
| 95 |
+
do {
|
| 96 |
+
if (cart->hash == hash)
|
| 97 |
+
return cart;
|
| 98 |
+
} while(cart++->hash);
|
| 99 |
+
return NULL;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
static inline int keycmp(uint16_t *k1, uint16_t *k2)
|
| 103 |
+
{
|
| 104 |
+
return (*k1 == *k2);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
static struct hdb_rom_id *hdb_lookup(uint16_t key)
|
| 108 |
+
{
|
| 109 |
+
struct hdb_rom_id *id = hdb;
|
| 110 |
+
do {
|
| 111 |
+
if (keycmp(&key, (uint16_t *)id->key))
|
| 112 |
+
return id;
|
| 113 |
+
} while(id++->id);
|
| 114 |
+
return NULL;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
void map_init(void)
|
| 118 |
+
{
|
| 119 |
+
uint8_t i;
|
| 120 |
+
uint8_t bslot = 0;
|
| 121 |
+
uint16_t hash;
|
| 122 |
+
struct cart_rom_id *rom;
|
| 123 |
+
|
| 124 |
+
kprintf("%s system.\n", sysname[system_id]);
|
| 125 |
+
if (mpi_present()) {
|
| 126 |
+
kputs("MPI cartridge detected.\n");
|
| 127 |
+
cartslots = 4;
|
| 128 |
+
bootslot = mpi_set_slot(0);
|
| 129 |
+
bslot = bootslot & 3;
|
| 130 |
+
}
|
| 131 |
+
for (i = 0; i < cartslots; i++) {
|
| 132 |
+
mpi_set_slot((i << 4) | i);
|
| 133 |
+
hash = cart_hash();
|
| 134 |
+
rom = cart_lookup(hash);
|
| 135 |
+
if (rom) {
|
| 136 |
+
kprintf("%d:%c%s",
|
| 137 |
+
i, i == bslot ? '*':' ',
|
| 138 |
+
rom->name);
|
| 139 |
+
carttype[i] = rom->id;
|
| 140 |
+
}
|
| 141 |
+
else
|
| 142 |
+
kprintf("%d:%cUnknown(%x)",
|
| 143 |
+
i, i == bslot ? '*':' ', hash);
|
| 144 |
+
|
| 145 |
+
/* The analysis needs to be in asm as we need to page in
|
| 146 |
+
the ROM to peer at it */
|
| 147 |
+
if (rom->id == CART_HDBDOS) {
|
| 148 |
+
uint16_t t = cart_analyze_hdb();
|
| 149 |
+
struct hdb_rom_id *hdb = hdb_lookup(t);
|
| 150 |
+
if (hdb) {
|
| 151 |
+
kprintf(" %s ID %d",
|
| 152 |
+
hdb->name, hdb_id);
|
| 153 |
+
if (hdb->id == CART_IDE)
|
| 154 |
+
kprintf(" MMIO %x", hdb_port);
|
| 155 |
+
carttype[i] = hdb->id;
|
| 156 |
+
cartaddr[i] = hdb_port;
|
| 157 |
+
} else
|
| 158 |
+
kprintf("??%x\n", t);
|
| 159 |
+
}
|
| 160 |
+
kputchar('\n');
|
| 161 |
+
}
|
| 162 |
+
mpi_set_slot(bootslot);
|
| 163 |
+
}
|
pool/shard000/C/0008848_demo.c
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Õâ·ÝdemoÓÃÓÚÑÝʾ»·Ðλº³åÇø
|
| 3 |
+
*/
|
| 4 |
+
#include <rtthread.h>
|
| 5 |
+
#include "rtdevice.h" //for rt_ringbuffer
|
| 6 |
+
#ifdef RT_USING_FINSH
|
| 7 |
+
#include <finsh.h>
|
| 8 |
+
#include <shell.h>
|
| 9 |
+
#endif
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
static rt_sem_t sem = RT_NULL;
|
| 14 |
+
|
| 15 |
+
static rt_uint8_t working_buffer[256];
|
| 16 |
+
struct rt_ringbuffer rb;
|
| 17 |
+
|
| 18 |
+
/* Ö¸ÏòÏ߳̿ØÖÆ¿éµÄÖ¸Õë */
|
| 19 |
+
static rt_thread_t tid1 = RT_NULL;
|
| 20 |
+
static rt_thread_t tid2 = RT_NULL;
|
| 21 |
+
|
| 22 |
+
/* Ïß³Ì1Èë¿Ú */
|
| 23 |
+
static void thread1_entry(void* parameter)
|
| 24 |
+
{
|
| 25 |
+
rt_bool_t result=RT_FALSE;
|
| 26 |
+
rt_uint8_t data_buffer[33];
|
| 27 |
+
rt_uint32_t i = 1;
|
| 28 |
+
|
| 29 |
+
while(1)
|
| 30 |
+
{
|
| 31 |
+
rt_sem_take (sem,RT_WAITING_FOREVER);
|
| 32 |
+
rt_kprintf("th1 take sem\n");
|
| 33 |
+
result = rt_ringbuffer_get(&rb,&data_buffer[0],33);
|
| 34 |
+
rt_kprintf("th1 release sem\n");
|
| 35 |
+
rt_sem_release(sem);
|
| 36 |
+
//if(RT_TRUE==result)
|
| 37 |
+
if(RT_FALSE!=result)
|
| 38 |
+
{
|
| 39 |
+
rt_kprintf(" th1 read data buffer: %s\n",data_buffer);
|
| 40 |
+
}
|
| 41 |
+
rt_thread_delay(5);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Ïß³Ì2Èë¿Ú£¬Ïß³Ì2µÄÓÅÏȼ¶±ÈÏß³Ì1µÍ£¬Ó¦¸ÃÏß³Ì1ÏÈ»ñµÃÖ´ÐС£*/
|
| 47 |
+
static void thread2_entry(void *parameter)
|
| 48 |
+
{
|
| 49 |
+
rt_bool_t result=RT_FALSE;
|
| 50 |
+
rt_uint32_t index,setchar,i = 1;
|
| 51 |
+
rt_uint8_t data_buffer[33];
|
| 52 |
+
|
| 53 |
+
setchar = 0x21;
|
| 54 |
+
while(1)
|
| 55 |
+
{
|
| 56 |
+
for (index = 0; index < 32; index++)
|
| 57 |
+
{
|
| 58 |
+
data_buffer[index] = setchar;
|
| 59 |
+
if (++setchar == 0x7f)
|
| 60 |
+
{
|
| 61 |
+
setchar = 0x21;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
data_buffer[32] = '\0';
|
| 65 |
+
|
| 66 |
+
rt_sem_take(sem,RT_WAITING_FOREVER);
|
| 67 |
+
rt_kprintf("th2 take sem\n");
|
| 68 |
+
result = rt_ringbuffer_put(&rb,&data_buffer[0],33);
|
| 69 |
+
// if(RT_TRUE==result)
|
| 70 |
+
if(RT_FALSE!=result)
|
| 71 |
+
{
|
| 72 |
+
rt_kprintf("th2 write buffer success!\n");
|
| 73 |
+
}
|
| 74 |
+
rt_kprintf("th2 realease sem\n");
|
| 75 |
+
rt_sem_release(sem);
|
| 76 |
+
|
| 77 |
+
rt_thread_delay(10);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
int demo_init(void)
|
| 82 |
+
{
|
| 83 |
+
rt_ringbuffer_init(&rb,working_buffer,256);
|
| 84 |
+
|
| 85 |
+
sem = rt_sem_create("sem",1,RT_IPC_FLAG_FIFO);
|
| 86 |
+
if (sem == RT_NULL)
|
| 87 |
+
{
|
| 88 |
+
return 0;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* ´´½¨Ïß³Ì1 */
|
| 92 |
+
tid1 = rt_thread_create("t1",
|
| 93 |
+
thread1_entry, RT_NULL, /* Ïß³ÌÈë¿ÚÊÇthread1_entry, Èë¿Ú²ÎÊýÊÇRT_NULL */
|
| 94 |
+
512, 8, 10);
|
| 95 |
+
if (tid1 != RT_NULL)
|
| 96 |
+
rt_thread_startup(tid1);
|
| 97 |
+
|
| 98 |
+
/* ´´½¨Ïß³Ì2 */
|
| 99 |
+
tid2 = rt_thread_create("t2",
|
| 100 |
+
thread2_entry, RT_NULL, /* Ïß³ÌÈë¿ÚÊÇthread2_entry, Èë¿Ú²ÎÊýÊÇRT_NULL */
|
| 101 |
+
512, 7, 10);
|
| 102 |
+
if (tid2 != RT_NULL)
|
| 103 |
+
rt_thread_startup(tid2);
|
| 104 |
+
|
| 105 |
+
return 0;
|
| 106 |
+
}
|
pool/shard000/C/0008854_mountpoints.c
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <string.h>
|
| 2 |
+
#include <fcntl.h>
|
| 3 |
+
#include <unistd.h>
|
| 4 |
+
#include <sys/mount.h>
|
| 5 |
+
#include <sys/stat.h>
|
| 6 |
+
|
| 7 |
+
#include "zdtmtst.h"
|
| 8 |
+
|
| 9 |
+
const char *test_doc = "Check that mountpoints (in mount namespace) are supported";
|
| 10 |
+
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";
|
| 11 |
+
|
| 12 |
+
#define MPTS_ROOT "/zdtm_mpts/"
|
| 13 |
+
|
| 14 |
+
static char buf[1024];
|
| 15 |
+
|
| 16 |
+
static int test_fn(int argc, char **argv)
|
| 17 |
+
{
|
| 18 |
+
FILE *f;
|
| 19 |
+
int fd, tmpfs_fd;
|
| 20 |
+
unsigned fs_cnt, fs_cnt_last = 0;
|
| 21 |
+
|
| 22 |
+
again:
|
| 23 |
+
fs_cnt = 0;
|
| 24 |
+
f = fopen("/proc/self/mountinfo", "r");
|
| 25 |
+
if (!f) {
|
| 26 |
+
fail("Can't open mountinfo");
|
| 27 |
+
return -1;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
while (fgets(buf, sizeof(buf), f) != NULL) {
|
| 31 |
+
char *mp = buf, *end;
|
| 32 |
+
|
| 33 |
+
mp = strchr(mp, ' ') + 1;
|
| 34 |
+
mp = strchr(mp, ' ') + 1;
|
| 35 |
+
mp = strchr(mp, ' ') + 1;
|
| 36 |
+
mp = strchr(mp, ' ') + 1;
|
| 37 |
+
end = strchr(mp, ' ');
|
| 38 |
+
*end = '\0';
|
| 39 |
+
|
| 40 |
+
if (!strcmp(mp, "/"))
|
| 41 |
+
continue;
|
| 42 |
+
if (!strcmp(mp, "/proc"))
|
| 43 |
+
continue;
|
| 44 |
+
|
| 45 |
+
umount(mp);
|
| 46 |
+
fs_cnt++;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
fclose(f);
|
| 50 |
+
|
| 51 |
+
if (fs_cnt == 0)
|
| 52 |
+
goto done;
|
| 53 |
+
|
| 54 |
+
if (fs_cnt != fs_cnt_last) {
|
| 55 |
+
fs_cnt_last = fs_cnt;
|
| 56 |
+
goto again;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
fail("Can't umount all the filesystems");
|
| 60 |
+
return -1;
|
| 61 |
+
|
| 62 |
+
done:
|
| 63 |
+
rmdir(MPTS_ROOT);
|
| 64 |
+
if (mkdir(MPTS_ROOT, 0600) < 0) {
|
| 65 |
+
fail("Can't make zdtm_sys");
|
| 66 |
+
return 1;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (mount("none", MPTS_ROOT, "sysfs", 0, "") < 0) {
|
| 70 |
+
fail("Can't mount sysfs");
|
| 71 |
+
return 1;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (mount("none", MPTS_ROOT"/dev", "tmpfs", 0, "") < 0) {
|
| 75 |
+
fail("Can't mount tmpfs");
|
| 76 |
+
return 1;
|
| 77 |
+
}
|
| 78 |
+
tmpfs_fd = open(MPTS_ROOT"/dev/test", O_WRONLY | O_CREAT);
|
| 79 |
+
if (write(tmpfs_fd, "hello", 5) <= 0) {
|
| 80 |
+
err("write() failed");
|
| 81 |
+
return 1;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (mount("none", MPTS_ROOT"/kernel", "proc", 0, "") < 0) {
|
| 85 |
+
fail("Can't mount proc");
|
| 86 |
+
return 1;
|
| 87 |
+
}
|
| 88 |
+
if (mount("none", MPTS_ROOT"/kernel/sys/fs/binfmt_misc",
|
| 89 |
+
"binfmt_misc", 0, "") < 0) {
|
| 90 |
+
fail("Can't mount proc");
|
| 91 |
+
return 1;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3));
|
| 95 |
+
|
| 96 |
+
setup_outfile();
|
| 97 |
+
|
| 98 |
+
fd = open(MPTS_ROOT"/kernel/meminfo", O_RDONLY);
|
| 99 |
+
if (fd == -1)
|
| 100 |
+
return 1;
|
| 101 |
+
|
| 102 |
+
test_daemon();
|
| 103 |
+
test_waitsig();
|
| 104 |
+
|
| 105 |
+
/* this checks both -- sys and proc presence */
|
| 106 |
+
if (access(MPTS_ROOT"/kernel/meminfo", F_OK)) {
|
| 107 |
+
fail("No proc after restore");
|
| 108 |
+
return 1;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
pass();
|
| 112 |
+
return 0;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
#define CLONE_NEWNS 0x00020000
|
| 116 |
+
|
| 117 |
+
int main(int argc, char **argv)
|
| 118 |
+
{
|
| 119 |
+
test_init_ns(argc, argv, CLONE_NEWNS, test_fn);
|
| 120 |
+
return 0;
|
| 121 |
+
}
|
pool/shard000/C/0008864_itob.c
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* itob: converts an integer to a variable base character string representation
|
| 3 |
+
*
|
| 4 |
+
* "Portions of this work are derived from The Standard C Library, copyright (c) 1992
|
| 5 |
+
* by P.J. Plauger, published by Prentice-Hall, and are used with permission."
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
// Includes
|
| 9 |
+
|
| 10 |
+
#include <limits.h>
|
| 11 |
+
#include <stdio.h>
|
| 12 |
+
#include <stdlib.h>
|
| 13 |
+
#include <string.h>
|
| 14 |
+
|
| 15 |
+
// Definitions
|
| 16 |
+
|
| 17 |
+
#define MAXSTRING 256
|
| 18 |
+
|
| 19 |
+
/*
|
| 20 |
+
* reverse(): reverse string 's' in place
|
| 21 |
+
*/
|
| 22 |
+
|
| 23 |
+
static void reverse(char s[]) {
|
| 24 |
+
|
| 25 |
+
size_t i;
|
| 26 |
+
size_t j;
|
| 27 |
+
|
| 28 |
+
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
|
| 29 |
+
int c;
|
| 30 |
+
c = s[i];
|
| 31 |
+
s[i] = s[j];
|
| 32 |
+
s[j] = c;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/*
|
| 38 |
+
* iotb(): converts integer 'n' into a base 'b' string 's[]'
|
| 39 |
+
*/
|
| 40 |
+
|
| 41 |
+
static void itob(int n, char s[], int b) {
|
| 42 |
+
|
| 43 |
+
size_t i = 0;
|
| 44 |
+
int sign = n; // Save the sign and make it positive if its negative
|
| 45 |
+
|
| 46 |
+
// generate digits in reverse order
|
| 47 |
+
do {
|
| 48 |
+
int d = abs(n % b); // gets the next digit
|
| 49 |
+
s[i++] = (d <= 9) ? (char)d + '0' : (char)d + 'A' - 10; // save it as a char--letters if num > 9
|
| 50 |
+
} while ((n /= b) != 0); // and deletes it from the number
|
| 51 |
+
|
| 52 |
+
// set the sign of the string (again in reverse)
|
| 53 |
+
if (sign < 0)
|
| 54 |
+
s[i++] = '-';
|
| 55 |
+
|
| 56 |
+
// termerate the string
|
| 57 |
+
s[i] = '\0';
|
| 58 |
+
|
| 59 |
+
// and reverse the string back
|
| 60 |
+
reverse(s);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* Main */
|
| 64 |
+
|
| 65 |
+
int main(void) {
|
| 66 |
+
int n;
|
| 67 |
+
int b;
|
| 68 |
+
char s[MAXSTRING] = "";
|
| 69 |
+
|
| 70 |
+
n = -255;
|
| 71 |
+
b = 10;
|
| 72 |
+
itob(n, s, b);
|
| 73 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 74 |
+
b = 2;
|
| 75 |
+
itob(n, s, b);
|
| 76 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 77 |
+
b = 8;
|
| 78 |
+
itob(n, s, b);
|
| 79 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 80 |
+
b = 16;
|
| 81 |
+
itob(n, s, b);
|
| 82 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 83 |
+
(void)putchar('\n');
|
| 84 |
+
|
| 85 |
+
n = 255;
|
| 86 |
+
b = 10;
|
| 87 |
+
itob(n, s, b);
|
| 88 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 89 |
+
b = 2;
|
| 90 |
+
itob(n, s, b);
|
| 91 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 92 |
+
b = 8;
|
| 93 |
+
itob(n, s, b);
|
| 94 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 95 |
+
b = 16;
|
| 96 |
+
itob(n, s, b);
|
| 97 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 98 |
+
(void)putchar('\n');
|
| 99 |
+
|
| 100 |
+
n = 1043;
|
| 101 |
+
b = 10;
|
| 102 |
+
itob(n, s, b);
|
| 103 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 104 |
+
b = 2;
|
| 105 |
+
itob(n, s, b);
|
| 106 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 107 |
+
b = 8;
|
| 108 |
+
itob(n, s, b);
|
| 109 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 110 |
+
b = 16;
|
| 111 |
+
itob(n, s, b);
|
| 112 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 113 |
+
(void)putchar('\n');
|
| 114 |
+
|
| 115 |
+
n = INT_MIN;
|
| 116 |
+
b = 10;
|
| 117 |
+
itob(n, s, b);
|
| 118 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 119 |
+
b = 2;
|
| 120 |
+
itob(n, s, b);
|
| 121 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 122 |
+
b = 8;
|
| 123 |
+
itob(n, s, b);
|
| 124 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 125 |
+
b = 16;
|
| 126 |
+
itob(n, s, b);
|
| 127 |
+
printf("Number %d converted to a string in base %d is: \"%s\"\n", n, b, s);
|
| 128 |
+
|
| 129 |
+
return 0;
|
| 130 |
+
}
|
pool/shard000/C/0008887_graphtest.c
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <libchaos/io.h>
|
| 2 |
+
#include <libchaos/mem.h>
|
| 3 |
+
#include <libchaos/timer.h>
|
| 4 |
+
#include <libchaos/log.h>
|
| 5 |
+
#include <libchaos/gif.h>
|
| 6 |
+
#include <libchaos/image.h>
|
| 7 |
+
#include <libchaos/graph.h>
|
| 8 |
+
|
| 9 |
+
uint32_t bytes_in = 666;
|
| 10 |
+
uint32_t bytes_out = 666;
|
| 11 |
+
|
| 12 |
+
void graphtest_write(void)
|
| 13 |
+
{
|
| 14 |
+
struct graph *graph;
|
| 15 |
+
|
| 16 |
+
graph = graph_new("traffic", 400, 160, GRAPH_TYPE_LINE);
|
| 17 |
+
|
| 18 |
+
/* graph_colorize(graph, GRAPH_COLOR_DARK);
|
| 19 |
+
|
| 20 |
+
graph_source_add(graph, GRAPH_MEASURE_DIFFTIME,
|
| 21 |
+
GRAPH_SOURCE_UINT, &bytes_in, "in");
|
| 22 |
+
|
| 23 |
+
graph_source_add(graph, GRAPH_MEASURE_DIFFTIME,
|
| 24 |
+
GRAPH_SOURCE_UINT, &bytes_out, "out");
|
| 25 |
+
|
| 26 |
+
graph_drain_add(graph, GRAPH_DATA_HOURLY);
|
| 27 |
+
graph_drain_add(graph, GRAPH_DATA_DAILY);
|
| 28 |
+
graph_drain_add(graph, GRAPH_DATA_WEEKLY);
|
| 29 |
+
graph_drain_add(graph, GRAPH_DATA_MONTHLY);
|
| 30 |
+
|
| 31 |
+
graph_drain_render(graph, GRAPH_DATA_HOURLY);
|
| 32 |
+
graph_drain_save(graph, GRAPH_DATA_HOURLY);
|
| 33 |
+
*/
|
| 34 |
+
graph_delete(graph);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
int main()
|
| 38 |
+
{
|
| 39 |
+
log_init(STDOUT_FILENO, LOG_ALL, L_status);
|
| 40 |
+
io_init_except(STDOUT_FILENO, STDOUT_FILENO, STDOUT_FILENO);
|
| 41 |
+
mem_init();
|
| 42 |
+
dlink_init();
|
| 43 |
+
gif_init();
|
| 44 |
+
image_init();
|
| 45 |
+
timer_init();
|
| 46 |
+
graph_init();
|
| 47 |
+
|
| 48 |
+
graphtest_write();
|
| 49 |
+
|
| 50 |
+
graph_shutdown();
|
| 51 |
+
timer_shutdown();
|
| 52 |
+
image_shutdown();
|
| 53 |
+
gif_shutdown();
|
| 54 |
+
dlink_shutdown();
|
| 55 |
+
mem_shutdown();
|
| 56 |
+
log_shutdown();
|
| 57 |
+
io_shutdown();
|
| 58 |
+
|
| 59 |
+
return 0;
|
| 60 |
+
}
|
| 61 |
+
|
pool/shard000/C/0008890_dvk_ebi.c
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**************************************************************************//**
|
| 2 |
+
* @file
|
| 3 |
+
* @brief EBI implementation of Board Control interface
|
| 4 |
+
* This implementation works for devices w/o LCD display on the
|
| 5 |
+
* MCU module, specifically the EFM32_G2xx_DK development board
|
| 6 |
+
* @author Energy Micro AS
|
| 7 |
+
* @version 1.6.0
|
| 8 |
+
******************************************************************************
|
| 9 |
+
* @section License
|
| 10 |
+
* <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
|
| 11 |
+
******************************************************************************
|
| 12 |
+
*
|
| 13 |
+
* This source code is the property of Energy Micro AS. The source and compiled
|
| 14 |
+
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
| 15 |
+
*
|
| 16 |
+
* This copyright notice may not be removed from the source code nor changed.
|
| 17 |
+
*
|
| 18 |
+
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
| 19 |
+
* obligation to support this Software. Energy Micro AS is providing the
|
| 20 |
+
* Software "AS IS", with no express or implied warranties of any kind,
|
| 21 |
+
* including, but not limited to, any implied warranties of merchantability
|
| 22 |
+
* or fitness for any particular purpose or warranties against infringement
|
| 23 |
+
* of any proprietary rights of a third party.
|
| 24 |
+
*
|
| 25 |
+
* Energy Micro AS will not be liable for any consequential, incidental, or
|
| 26 |
+
* special damages, or any other relief, or for any claim by any third party,
|
| 27 |
+
* arising from your use of this Software.
|
| 28 |
+
*
|
| 29 |
+
*****************************************************************************/
|
| 30 |
+
#include "efm32.h"
|
| 31 |
+
#include "efm32_ebi.h"
|
| 32 |
+
#include "efm32_cmu.h"
|
| 33 |
+
#include "efm32_gpio.h"
|
| 34 |
+
#include "dvk.h"
|
| 35 |
+
#include "dvk_bcregisters.h"
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
/**************************************************************************//**
|
| 39 |
+
* @brief Configure EBI (external bus interface) for Board Control register
|
| 40 |
+
* access
|
| 41 |
+
*****************************************************************************/
|
| 42 |
+
void DVK_EBI_configure(void)
|
| 43 |
+
{
|
| 44 |
+
EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;
|
| 45 |
+
|
| 46 |
+
/* Run time check if we have EBI on-chip capability on this device */
|
| 47 |
+
switch ((DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK) >>
|
| 48 |
+
_DEVINFO_PART_DEVICE_NUMBER_SHIFT)
|
| 49 |
+
{
|
| 50 |
+
/* Only device types EFM32G 280/290/880 and 890 have EBI capability */
|
| 51 |
+
case 280:
|
| 52 |
+
case 290:
|
| 53 |
+
case 880:
|
| 54 |
+
case 890:
|
| 55 |
+
break;
|
| 56 |
+
default:
|
| 57 |
+
/* This device do not have EBI capability - use SPI to interface DVK */
|
| 58 |
+
/* With high probability your project has been configured for an */
|
| 59 |
+
/* incorrect part number. */
|
| 60 |
+
while (1) ;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/* Enable clocks */
|
| 64 |
+
CMU_ClockEnable(cmuClock_EBI, true);
|
| 65 |
+
CMU_ClockEnable(cmuClock_GPIO, true);
|
| 66 |
+
|
| 67 |
+
/* Configure bus connect PC bit 12 active low */
|
| 68 |
+
GPIO_PinModeSet(gpioPortC, 12, gpioModePushPull, 0);
|
| 69 |
+
|
| 70 |
+
/* Configure GPIO pins as push pull */
|
| 71 |
+
/* EBI AD9..15 */
|
| 72 |
+
GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
|
| 73 |
+
GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
|
| 74 |
+
GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 0);
|
| 75 |
+
GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
|
| 76 |
+
GPIO_PinModeSet(gpioPortA, 4, gpioModePushPull, 0);
|
| 77 |
+
GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 0);
|
| 78 |
+
GPIO_PinModeSet(gpioPortA, 6, gpioModePushPull, 0);
|
| 79 |
+
|
| 80 |
+
/* EBI AD8 */
|
| 81 |
+
GPIO_PinModeSet(gpioPortA, 15, gpioModePushPull, 0);
|
| 82 |
+
|
| 83 |
+
/* EBI CS0-CS3 */
|
| 84 |
+
GPIO_PinModeSet(gpioPortD, 9, gpioModePushPull, 0);
|
| 85 |
+
GPIO_PinModeSet(gpioPortD, 10, gpioModePushPull, 0);
|
| 86 |
+
GPIO_PinModeSet(gpioPortD, 11, gpioModePushPull, 0);
|
| 87 |
+
GPIO_PinModeSet(gpioPortD, 12, gpioModePushPull, 0);
|
| 88 |
+
|
| 89 |
+
/* EBI AD0..7 */
|
| 90 |
+
GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
|
| 91 |
+
GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
|
| 92 |
+
GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
|
| 93 |
+
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
|
| 94 |
+
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
|
| 95 |
+
GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
|
| 96 |
+
GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
|
| 97 |
+
GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
|
| 98 |
+
|
| 99 |
+
/* EBI ARDY/ALEN/Wen/Ren */
|
| 100 |
+
GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 0);
|
| 101 |
+
GPIO_PinModeSet(gpioPortF, 3, gpioModePushPull, 0);
|
| 102 |
+
GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 0);
|
| 103 |
+
GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 0);
|
| 104 |
+
|
| 105 |
+
/* Configure EBI controller, changing default values */
|
| 106 |
+
ebiConfig.mode = ebiModeD16A16ALE;
|
| 107 |
+
/* Enable bank 0 address map 0x80000000, FPGA Flash */
|
| 108 |
+
/* Enable bank 1 address map 0x84000000, FPGA SRAM */
|
| 109 |
+
/* Enable bank 2 address map 0x88000000, FPGA TFT Display (SSD2119) */
|
| 110 |
+
/* Enable bank 3 address map 0x8c000000, FPGA Board Control Registers */
|
| 111 |
+
ebiConfig.banks = EBI_BANK0|EBI_BANK1|EBI_BANK2|EBI_BANK3;
|
| 112 |
+
ebiConfig.csLines = EBI_CS0|EBI_CS1|EBI_CS2|EBI_CS3;
|
| 113 |
+
|
| 114 |
+
/* Address Setup and hold time */
|
| 115 |
+
ebiConfig.addrHoldCycles = 3;
|
| 116 |
+
ebiConfig.addrSetupCycles = 3;
|
| 117 |
+
|
| 118 |
+
/* Read cycle times */
|
| 119 |
+
ebiConfig.readStrobeCycles = 7;
|
| 120 |
+
ebiConfig.readHoldCycles = 3;
|
| 121 |
+
ebiConfig.readSetupCycles = 3;
|
| 122 |
+
|
| 123 |
+
/* Write cycle times */
|
| 124 |
+
ebiConfig.writeStrobeCycles = 7;
|
| 125 |
+
ebiConfig.writeHoldCycles = 3;
|
| 126 |
+
ebiConfig.writeSetupCycles = 3;
|
| 127 |
+
|
| 128 |
+
/* Polarity values are default */
|
| 129 |
+
|
| 130 |
+
/* Configure EBI */
|
| 131 |
+
EBI_Init(&ebiConfig);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
/**************************************************************************//**
|
| 136 |
+
* @brief Initialize EBI
|
| 137 |
+
* access
|
| 138 |
+
*****************************************************************************/
|
| 139 |
+
void DVK_EBI_init(void)
|
| 140 |
+
{
|
| 141 |
+
uint16_t ebiMagic;
|
| 142 |
+
int ctr;
|
| 143 |
+
|
| 144 |
+
/* Disable all GPIO pins and register */
|
| 145 |
+
DVK_EBI_disable();
|
| 146 |
+
/* Configure EBI */
|
| 147 |
+
DVK_EBI_configure();
|
| 148 |
+
/* Verify that EBI access is working, if not kit is in SPI mode and needs to
|
| 149 |
+
* be configured for EBI access */
|
| 150 |
+
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
| 151 |
+
if (ebiMagic != BC_MAGIC_VALUE)
|
| 152 |
+
{
|
| 153 |
+
/* Disable EBI */
|
| 154 |
+
DVK_EBI_disable();
|
| 155 |
+
/* Enable SPI interface */
|
| 156 |
+
DVK_SPI_init();
|
| 157 |
+
/* Set EBI mode - after this SPI access will no longer be available */
|
| 158 |
+
DVK_SPI_writeRegister(BC_CFG, BC_CFG_EBI);
|
| 159 |
+
/* Disable SPI */
|
| 160 |
+
DVK_SPI_disable();
|
| 161 |
+
/* Now setup EBI again */
|
| 162 |
+
DVK_EBI_configure();
|
| 163 |
+
/* Wait until ready */
|
| 164 |
+
ctr = 0;
|
| 165 |
+
do
|
| 166 |
+
{
|
| 167 |
+
/* Check if FPGA responds */
|
| 168 |
+
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
| 169 |
+
ctr++;
|
| 170 |
+
DVK_EBI_writeRegister(BC_LED, ctr);
|
| 171 |
+
} while (ebiMagic != BC_MAGIC_VALUE);
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/**************************************************************************//**
|
| 176 |
+
* @brief Disable EBI interface, free all GPIO pins
|
| 177 |
+
*****************************************************************************/
|
| 178 |
+
void DVK_EBI_disable(void)
|
| 179 |
+
{
|
| 180 |
+
/* Disable EBI controller */
|
| 181 |
+
EBI_Disable();
|
| 182 |
+
|
| 183 |
+
/* Disable EBI clock in CMU */
|
| 184 |
+
CMU_ClockEnable(cmuClock_EBI, false);
|
| 185 |
+
|
| 186 |
+
/* Disable EBI _BC_BUS_CONNECT */
|
| 187 |
+
GPIO_PinModeSet(gpioPortC, 12, gpioModeDisabled, 0);
|
| 188 |
+
|
| 189 |
+
/* Configure GPIO pins as disabled */
|
| 190 |
+
GPIO_PinModeSet(gpioPortA, 0, gpioModeDisabled, 0);
|
| 191 |
+
GPIO_PinModeSet(gpioPortA, 1, gpioModeDisabled, 0);
|
| 192 |
+
GPIO_PinModeSet(gpioPortA, 2, gpioModeDisabled, 0);
|
| 193 |
+
GPIO_PinModeSet(gpioPortA, 3, gpioModeDisabled, 0);
|
| 194 |
+
GPIO_PinModeSet(gpioPortA, 4, gpioModeDisabled, 0);
|
| 195 |
+
GPIO_PinModeSet(gpioPortA, 5, gpioModeDisabled, 0);
|
| 196 |
+
GPIO_PinModeSet(gpioPortA, 6, gpioModeDisabled, 0);
|
| 197 |
+
|
| 198 |
+
GPIO_PinModeSet(gpioPortA, 15, gpioModeDisabled, 0);
|
| 199 |
+
|
| 200 |
+
GPIO_PinModeSet(gpioPortD, 9, gpioModeDisabled, 0);
|
| 201 |
+
GPIO_PinModeSet(gpioPortD, 10, gpioModeDisabled, 0);
|
| 202 |
+
GPIO_PinModeSet(gpioPortD, 11, gpioModeDisabled, 0);
|
| 203 |
+
GPIO_PinModeSet(gpioPortD, 12, gpioModeDisabled, 0);
|
| 204 |
+
|
| 205 |
+
GPIO_PinModeSet(gpioPortE, 8, gpioModeDisabled, 0);
|
| 206 |
+
GPIO_PinModeSet(gpioPortE, 9, gpioModeDisabled, 0);
|
| 207 |
+
GPIO_PinModeSet(gpioPortE, 10, gpioModeDisabled, 0);
|
| 208 |
+
GPIO_PinModeSet(gpioPortE, 11, gpioModeDisabled, 0);
|
| 209 |
+
GPIO_PinModeSet(gpioPortE, 12, gpioModeDisabled, 0);
|
| 210 |
+
GPIO_PinModeSet(gpioPortE, 13, gpioModeDisabled, 0);
|
| 211 |
+
GPIO_PinModeSet(gpioPortE, 14, gpioModeDisabled, 0);
|
| 212 |
+
GPIO_PinModeSet(gpioPortE, 15, gpioModeDisabled, 0);
|
| 213 |
+
|
| 214 |
+
GPIO_PinModeSet(gpioPortF, 2, gpioModeDisabled, 0);
|
| 215 |
+
GPIO_PinModeSet(gpioPortF, 3, gpioModeDisabled, 0);
|
| 216 |
+
GPIO_PinModeSet(gpioPortF, 4, gpioModeDisabled, 0);
|
| 217 |
+
GPIO_PinModeSet(gpioPortF, 5, gpioModeDisabled, 0);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/**************************************************************************//**
|
| 221 |
+
* @brief Write data into 16-bit board control register
|
| 222 |
+
* @param addr Address to board control register
|
| 223 |
+
* @param data Data to write into register
|
| 224 |
+
*****************************************************************************/
|
| 225 |
+
void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
|
| 226 |
+
{
|
| 227 |
+
*addr = data;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/**************************************************************************//**
|
| 231 |
+
* @brief Write data into 16-bit board control register
|
| 232 |
+
* @param addr Register to read from
|
| 233 |
+
*****************************************************************************/
|
| 234 |
+
uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
|
| 235 |
+
{
|
| 236 |
+
return *addr;
|
| 237 |
+
}
|
pool/shard000/C/0008902_comtest.c
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
|
| 3 |
+
|
| 4 |
+
FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
|
| 5 |
+
http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
| 6 |
+
|
| 7 |
+
***************************************************************************
|
| 8 |
+
* *
|
| 9 |
+
* FreeRTOS tutorial books are available in pdf and paperback. *
|
| 10 |
+
* Complete, revised, and edited pdf reference manuals are also *
|
| 11 |
+
* available. *
|
| 12 |
+
* *
|
| 13 |
+
* Purchasing FreeRTOS documentation will not only help you, by *
|
| 14 |
+
* ensuring you get running as quickly as possible and with an *
|
| 15 |
+
* in-depth knowledge of how to use FreeRTOS, it will also help *
|
| 16 |
+
* the FreeRTOS project to continue with its mission of providing *
|
| 17 |
+
* professional grade, cross platform, de facto standard solutions *
|
| 18 |
+
* for microcontrollers - completely free of charge! *
|
| 19 |
+
* *
|
| 20 |
+
* >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
|
| 21 |
+
* *
|
| 22 |
+
* Thank you for using FreeRTOS, and thank you for your support! *
|
| 23 |
+
* *
|
| 24 |
+
***************************************************************************
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
This file is part of the FreeRTOS distribution.
|
| 28 |
+
|
| 29 |
+
FreeRTOS is free software; you can redistribute it and/or modify it under
|
| 30 |
+
the terms of the GNU General Public License (version 2) as published by the
|
| 31 |
+
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
| 32 |
+
|
| 33 |
+
>>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
|
| 34 |
+
distribute a combined work that includes FreeRTOS without being obliged to
|
| 35 |
+
provide the source code for proprietary components outside of the FreeRTOS
|
| 36 |
+
kernel.
|
| 37 |
+
|
| 38 |
+
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
| 39 |
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
| 40 |
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
| 41 |
+
details. You should have received a copy of the GNU General Public License
|
| 42 |
+
and the FreeRTOS license exception along with FreeRTOS; if not itcan be
|
| 43 |
+
viewed here: http://www.freertos.org/a00114.html and also obtained by
|
| 44 |
+
writing to Real Time Engineers Ltd., contact details for whom are available
|
| 45 |
+
on the FreeRTOS WEB site.
|
| 46 |
+
|
| 47 |
+
1 tab == 4 spaces!
|
| 48 |
+
|
| 49 |
+
***************************************************************************
|
| 50 |
+
* *
|
| 51 |
+
* Having a problem? Start by reading the FAQ "My application does *
|
| 52 |
+
* not run, what could be wrong?" *
|
| 53 |
+
* *
|
| 54 |
+
* http://www.FreeRTOS.org/FAQHelp.html *
|
| 55 |
+
* *
|
| 56 |
+
***************************************************************************
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
| 60 |
+
license and Real Time Engineers Ltd. contact details.
|
| 61 |
+
|
| 62 |
+
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
| 63 |
+
including FreeRTOS+Trace - an indispensable productivity tool, and our new
|
| 64 |
+
fully thread aware and reentrant UDP/IP stack.
|
| 65 |
+
|
| 66 |
+
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
| 67 |
+
Integrity Systems, who sell the code with commercial support,
|
| 68 |
+
indemnification and middleware, under the OpenRTOS brand.
|
| 69 |
+
|
| 70 |
+
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
| 71 |
+
engineered and independently SIL3 certified version for use in safety and
|
| 72 |
+
mission critical applications that require provable dependability.
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
* This version of comtest. c is for use on systems that have limited stack
|
| 78 |
+
* space and no display facilities. The complete version can be found in
|
| 79 |
+
* the Demo/Common/Full directory.
|
| 80 |
+
*
|
| 81 |
+
* Creates two tasks that operate on an interrupt driven serial port. A
|
| 82 |
+
* loopback connector should be used so that everything that is transmitted is
|
| 83 |
+
* also received. The serial port does not use any flow control. On a
|
| 84 |
+
* standard 9way 'D' connector pins two and three should be connected together.
|
| 85 |
+
*
|
| 86 |
+
* The first task posts a sequence of characters to the Tx queue, toggling an
|
| 87 |
+
* LED on each successful post. At the end of the sequence it sleeps for a
|
| 88 |
+
* pseudo-random period before resending the same sequence.
|
| 89 |
+
*
|
| 90 |
+
* The UART Tx end interrupt is enabled whenever data is available in the Tx
|
| 91 |
+
* queue. The Tx end ISR removes a single character from the Tx queue and
|
| 92 |
+
* passes it to the UART for transmission.
|
| 93 |
+
*
|
| 94 |
+
* The second task blocks on the Rx queue waiting for a character to become
|
| 95 |
+
* available. When the UART Rx end interrupt receives a character it places
|
| 96 |
+
* it in the Rx queue, waking the second task. The second task checks that the
|
| 97 |
+
* characters removed from the Rx queue form the same sequence as those posted
|
| 98 |
+
* to the Tx queue, and toggles an LED for each correct character.
|
| 99 |
+
*
|
| 100 |
+
* The receiving task is spawned with a higher priority than the transmitting
|
| 101 |
+
* task. The receiver will therefore wake every time a character is
|
| 102 |
+
* transmitted so neither the Tx or Rx queue should ever hold more than a few
|
| 103 |
+
* characters.
|
| 104 |
+
*
|
| 105 |
+
*/
|
| 106 |
+
|
| 107 |
+
/* Scheduler include files. */
|
| 108 |
+
#include <stdlib.h>
|
| 109 |
+
#include "FreeRTOS.h"
|
| 110 |
+
#include "task.h"
|
| 111 |
+
|
| 112 |
+
/* Demo program include files. */
|
| 113 |
+
#include "serial.h"
|
| 114 |
+
#include "comtest.h"
|
| 115 |
+
#include "partest.h"
|
| 116 |
+
|
| 117 |
+
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
|
| 118 |
+
#define comTX_LED_OFFSET ( 0 )
|
| 119 |
+
#define comRX_LED_OFFSET ( 1 )
|
| 120 |
+
#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
|
| 121 |
+
|
| 122 |
+
/* The Tx task will transmit the sequence of characters at a pseudo random
|
| 123 |
+
interval. This is the maximum and minimum block time between sends. */
|
| 124 |
+
#define comTX_MAX_BLOCK_TIME ( ( portTickType ) 0x96 )
|
| 125 |
+
#define comTX_MIN_BLOCK_TIME ( ( portTickType ) 0x32 )
|
| 126 |
+
#define comOFFSET_TIME ( ( portTickType ) 3 )
|
| 127 |
+
|
| 128 |
+
/* We should find that each character can be queued for Tx immediately and we
|
| 129 |
+
don't have to block to send. */
|
| 130 |
+
#define comNO_BLOCK ( ( portTickType ) 0 )
|
| 131 |
+
|
| 132 |
+
/* The Rx task will block on the Rx queue for a long period. */
|
| 133 |
+
#define comRX_BLOCK_TIME ( ( portTickType ) 0xffff )
|
| 134 |
+
|
| 135 |
+
/* The sequence transmitted is from comFIRST_BYTE to and including comLAST_BYTE. */
|
| 136 |
+
#define comFIRST_BYTE ( 'A' )
|
| 137 |
+
#define comLAST_BYTE ( 'X' )
|
| 138 |
+
|
| 139 |
+
#define comBUFFER_LEN ( ( unsigned portBASE_TYPE ) ( comLAST_BYTE - comFIRST_BYTE ) + ( unsigned portBASE_TYPE ) 1 )
|
| 140 |
+
#define comINITIAL_RX_COUNT_VALUE ( 0 )
|
| 141 |
+
|
| 142 |
+
/* Handle to the com port used by both tasks. */
|
| 143 |
+
static xComPortHandle xPort = NULL;
|
| 144 |
+
|
| 145 |
+
/* The transmit task as described at the top of the file. */
|
| 146 |
+
static portTASK_FUNCTION_PROTO( vComTxTask, pvParameters );
|
| 147 |
+
|
| 148 |
+
/* The receive task as described at the top of the file. */
|
| 149 |
+
static portTASK_FUNCTION_PROTO( vComRxTask, pvParameters );
|
| 150 |
+
|
| 151 |
+
/* The LED that should be toggled by the Rx and Tx tasks. The Rx task will
|
| 152 |
+
toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
|
| 153 |
+
( uxBaseLED + comTX_LED_OFFSET ). */
|
| 154 |
+
static unsigned portBASE_TYPE uxBaseLED = 0;
|
| 155 |
+
|
| 156 |
+
/* Check variable used to ensure no error have occurred. The Rx task will
|
| 157 |
+
increment this variable after every successfully received sequence. If at any
|
| 158 |
+
time the sequence is incorrect the the variable will stop being incremented. */
|
| 159 |
+
static volatile unsigned portBASE_TYPE uxRxLoops = comINITIAL_RX_COUNT_VALUE;
|
| 160 |
+
|
| 161 |
+
/*-----------------------------------------------------------*/
|
| 162 |
+
|
| 163 |
+
void vAltStartComTestTasks( unsigned portBASE_TYPE uxPriority, unsigned long ulBaudRate, unsigned portBASE_TYPE uxLED )
|
| 164 |
+
{
|
| 165 |
+
/* Initialise the com port then spawn the Rx and Tx tasks. */
|
| 166 |
+
uxBaseLED = uxLED;
|
| 167 |
+
xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
|
| 168 |
+
|
| 169 |
+
/* The Tx task is spawned with a lower priority than the Rx task. */
|
| 170 |
+
xTaskCreate( vComTxTask, ( signed char * ) "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( xTaskHandle * ) NULL );
|
| 171 |
+
xTaskCreate( vComRxTask, ( signed char * ) "COMRx", comSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
|
| 172 |
+
}
|
| 173 |
+
/*-----------------------------------------------------------*/
|
| 174 |
+
|
| 175 |
+
static portTASK_FUNCTION( vComTxTask, pvParameters )
|
| 176 |
+
{
|
| 177 |
+
signed char cByteToSend;
|
| 178 |
+
portTickType xTimeToWait;
|
| 179 |
+
|
| 180 |
+
/* Just to stop compiler warnings. */
|
| 181 |
+
( void ) pvParameters;
|
| 182 |
+
|
| 183 |
+
for( ;; )
|
| 184 |
+
{
|
| 185 |
+
/* Simply transmit a sequence of characters from comFIRST_BYTE to
|
| 186 |
+
comLAST_BYTE. */
|
| 187 |
+
for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
|
| 188 |
+
{
|
| 189 |
+
if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
|
| 190 |
+
{
|
| 191 |
+
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/* Turn the LED off while we are not doing anything. */
|
| 196 |
+
vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
|
| 197 |
+
|
| 198 |
+
/* We have posted all the characters in the string - wait before
|
| 199 |
+
re-sending. Wait a pseudo-random time as this will provide a better
|
| 200 |
+
test. */
|
| 201 |
+
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
|
| 202 |
+
|
| 203 |
+
/* Make sure we don't wait too long... */
|
| 204 |
+
xTimeToWait %= comTX_MAX_BLOCK_TIME;
|
| 205 |
+
|
| 206 |
+
/* ...but we do want to wait. */
|
| 207 |
+
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
|
| 208 |
+
{
|
| 209 |
+
xTimeToWait = comTX_MIN_BLOCK_TIME;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
vTaskDelay( xTimeToWait );
|
| 213 |
+
}
|
| 214 |
+
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
|
| 215 |
+
/*-----------------------------------------------------------*/
|
| 216 |
+
|
| 217 |
+
static portTASK_FUNCTION( vComRxTask, pvParameters )
|
| 218 |
+
{
|
| 219 |
+
signed char cExpectedByte, cByteRxed;
|
| 220 |
+
portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
|
| 221 |
+
|
| 222 |
+
/* Just to stop compiler warnings. */
|
| 223 |
+
( void ) pvParameters;
|
| 224 |
+
|
| 225 |
+
for( ;; )
|
| 226 |
+
{
|
| 227 |
+
/* We expect to receive the characters from comFIRST_BYTE to
|
| 228 |
+
comLAST_BYTE in an incrementing order. Loop to receive each byte. */
|
| 229 |
+
for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
|
| 230 |
+
{
|
| 231 |
+
/* Block on the queue that contains received bytes until a byte is
|
| 232 |
+
available. */
|
| 233 |
+
if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
|
| 234 |
+
{
|
| 235 |
+
/* Was this the byte we were expecting? If so, toggle the LED,
|
| 236 |
+
otherwise we are out on sync and should break out of the loop
|
| 237 |
+
until the expected character sequence is about to restart. */
|
| 238 |
+
if( cByteRxed == cExpectedByte )
|
| 239 |
+
{
|
| 240 |
+
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
|
| 241 |
+
}
|
| 242 |
+
else
|
| 243 |
+
{
|
| 244 |
+
xResyncRequired = pdTRUE;
|
| 245 |
+
break; /*lint !e960 Non-switch break allowed. */
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/* Turn the LED off while we are not doing anything. */
|
| 251 |
+
vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
|
| 252 |
+
|
| 253 |
+
/* Did we break out of the loop because the characters were received in
|
| 254 |
+
an unexpected order? If so wait here until the character sequence is
|
| 255 |
+
about to restart. */
|
| 256 |
+
if( xResyncRequired == pdTRUE )
|
| 257 |
+
{
|
| 258 |
+
while( cByteRxed != comLAST_BYTE )
|
| 259 |
+
{
|
| 260 |
+
/* Block until the next char is available. */
|
| 261 |
+
xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
/* Note that an error occurred which caused us to have to resync.
|
| 265 |
+
We use this to stop incrementing the loop counter so
|
| 266 |
+
sAreComTestTasksStillRunning() will return false - indicating an
|
| 267 |
+
error. */
|
| 268 |
+
xErrorOccurred++;
|
| 269 |
+
|
| 270 |
+
/* We have now resynced with the Tx task and can continue. */
|
| 271 |
+
xResyncRequired = pdFALSE;
|
| 272 |
+
}
|
| 273 |
+
else
|
| 274 |
+
{
|
| 275 |
+
if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
|
| 276 |
+
{
|
| 277 |
+
/* Increment the count of successful loops. As error
|
| 278 |
+
occurring (i.e. an unexpected character being received) will
|
| 279 |
+
prevent this counter being incremented for the rest of the
|
| 280 |
+
execution. Don't worry about mutual exclusion on this
|
| 281 |
+
variable - it doesn't really matter as we just want it
|
| 282 |
+
to change. */
|
| 283 |
+
uxRxLoops++;
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
|
| 288 |
+
/*-----------------------------------------------------------*/
|
| 289 |
+
|
| 290 |
+
portBASE_TYPE xAreComTestTasksStillRunning( void )
|
| 291 |
+
{
|
| 292 |
+
portBASE_TYPE xReturn;
|
| 293 |
+
|
| 294 |
+
/* If the count of successful reception loops has not changed than at
|
| 295 |
+
some time an error occurred (i.e. a character was received out of sequence)
|
| 296 |
+
and we will return false. */
|
| 297 |
+
if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
|
| 298 |
+
{
|
| 299 |
+
xReturn = pdFALSE;
|
| 300 |
+
}
|
| 301 |
+
else
|
| 302 |
+
{
|
| 303 |
+
xReturn = pdTRUE;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/* Reset the count of successful Rx loops. When this function is called
|
| 307 |
+
again we expect this to have been incremented. */
|
| 308 |
+
uxRxLoops = comINITIAL_RX_COUNT_VALUE;
|
| 309 |
+
|
| 310 |
+
return xReturn;
|
| 311 |
+
}
|
| 312 |
+
|
pool/shard000/C/0008912_unix_misc.c
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <stdlib.h>
|
| 3 |
+
#include <unistd.h>
|
| 4 |
+
#include <errno.h>
|
| 5 |
+
#include <signal.h>
|
| 6 |
+
#include <sys/stat.h>
|
| 7 |
+
#include <sys/wait.h>
|
| 8 |
+
#include <sys/types.h>
|
| 9 |
+
#include <string.h>
|
| 10 |
+
#include <pty.h>
|
| 11 |
+
#include <utmp.h>
|
| 12 |
+
#include "process.h"
|
| 13 |
+
#include "io.h"
|
| 14 |
+
#include "prog.h"
|
| 15 |
+
#include "ntcomm.h"
|
| 16 |
+
|
| 17 |
+
#define unixfd(hc) FileHandle_fromCommHandle(ComGetHandle(hc))
|
| 18 |
+
|
| 19 |
+
/* Record locking code */
|
| 20 |
+
|
| 21 |
+
int lock(int fd, long offset, long len)
|
| 22 |
+
{
|
| 23 |
+
struct flock lck;
|
| 24 |
+
|
| 25 |
+
lck.l_type = F_WRLCK; /* setting a write lock */
|
| 26 |
+
lck.l_whence = SEEK_SET; /* offset l_start from beginning of file */
|
| 27 |
+
lck.l_start = (off_t)offset;
|
| 28 |
+
lck.l_len = len;
|
| 29 |
+
|
| 30 |
+
return fcntl(fd, F_SETLK, &lck);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
int unlock(int fd, long offset, long len)
|
| 34 |
+
{
|
| 35 |
+
struct flock lck;
|
| 36 |
+
|
| 37 |
+
lck.l_type = F_UNLCK; /* setting not locked */
|
| 38 |
+
lck.l_whence = SEEK_SET; /* offset l_start from beginning of file */
|
| 39 |
+
lck.l_start = (off_t)offset;
|
| 40 |
+
lck.l_len = len;
|
| 41 |
+
|
| 42 |
+
return fcntl(fd, F_SETLK, &lck);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
void NoMem() __attribute__((weak));
|
| 46 |
+
void NoMem()
|
| 47 |
+
{
|
| 48 |
+
fprintf(stderr, "Out of memory!\n");
|
| 49 |
+
_exit(1);
|
| 50 |
+
}
|
pool/shard000/C/0008917_PiCode.c
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* PiCode.c
|
| 3 |
+
*
|
| 4 |
+
* Created on: May 25, 2016
|
| 5 |
+
* Author: Barrett
|
| 6 |
+
* Uses the Monte Carlo method of pi calculation and pthreads
|
| 7 |
+
* to accurately and consistently approximate pi, getting more
|
| 8 |
+
* accurate as the number of threads increase
|
| 9 |
+
*/
|
| 10 |
+
#include <stdio.h>
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
#include <pthread.h>
|
| 13 |
+
#include <math.h>
|
| 14 |
+
|
| 15 |
+
//GLOBAL VARIABLE
|
| 16 |
+
int threadcount = 100000;//number of threads created 250000
|
| 17 |
+
|
| 18 |
+
//STRUCTURES
|
| 19 |
+
struct randoms{//used to pass the two random numbers
|
| 20 |
+
double rand1;
|
| 21 |
+
double rand2;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
void *piseries(void *arg){
|
| 25 |
+
//*NOTE* DON'T SEED RANDOM NUMBERS (srand()) IN THE THREAD FUNCTION,
|
| 26 |
+
//you must seed the random function once in the main method so its only seeded once as a constant
|
| 27 |
+
//addornot has dynamically allocated data
|
| 28 |
+
int *addornot = malloc(sizeof(*addornot));//add or not is returned as 0 or 1, a boolean for C
|
| 29 |
+
|
| 30 |
+
struct randoms *nums = (struct randoms*)arg;
|
| 31 |
+
//gets random numbers created in main()
|
| 32 |
+
double x = nums->rand1;
|
| 33 |
+
double y = nums->rand2;
|
| 34 |
+
//THE MATH, REFER TO MONTE CARLO PI CALCULATION
|
| 35 |
+
double answ = (x*x)+(y*y);
|
| 36 |
+
//DEBUGGINGprintf("\n\n------------\n| %f...%f |\n------------\n\n", x, y);
|
| 37 |
+
*addornot = 0;//initially false
|
| 38 |
+
if (answ < 1){
|
| 39 |
+
*addornot = 1;//TRUE
|
| 40 |
+
pthread_exit(addornot);//return addornot to pthread_join()
|
| 41 |
+
}
|
| 42 |
+
else{//FALSE
|
| 43 |
+
pthread_exit(addornot);//return addornot to pthread_join
|
| 44 |
+
}
|
| 45 |
+
return NULL;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
int main(){
|
| 49 |
+
void *incircle;//recieve the addornot variable when pthread_exit() is called
|
| 50 |
+
int pointsinside = 0;//if addornot is true(1) add one
|
| 51 |
+
double pi;//store actual finished value of pi
|
| 52 |
+
struct randoms randm;//random numbers for pthreads
|
| 53 |
+
|
| 54 |
+
//INITIALIZING THE THREADS
|
| 55 |
+
pthread_t threads[threadcount];//array of threads with custom size of global variabel threadcount
|
| 56 |
+
srand(3645783);//seed the rand function ONLY DO ONCE AND NOT IN ANY THREADS, THE NUMBERS WILL BECOME NOT RANDOM IF YOU DO AND IT WILL SKEW RESULTS
|
| 57 |
+
|
| 58 |
+
for (int i = 0; i < threadcount; i++){//create random numbers, threads and joins the threads while printing out status of the process
|
| 59 |
+
//assign random numbers to structure, DIVIDE BY RAND_MAX NOT ESTIMATED MAX OR ELSE RESULTS WILL BE SKEWED
|
| 60 |
+
randm.rand1 = (double)rand()/RAND_MAX;
|
| 61 |
+
randm.rand2 = (double)rand()/RAND_MAX;
|
| 62 |
+
//create and join threads
|
| 63 |
+
pthread_create(&threads[i], NULL, piseries, (void *)&randm);
|
| 64 |
+
pthread_join(threads[i], &incircle);
|
| 65 |
+
if(*(int*)incircle == 1){//incircle is returned by pthread_exit in the piseries function
|
| 66 |
+
pointsinside++;
|
| 67 |
+
//DEBUGGINGprintf("YES");
|
| 68 |
+
//DEBUGGINGfflush(stdout);
|
| 69 |
+
}
|
| 70 |
+
//printing benchmark points
|
| 71 |
+
if((double)i/threadcount == .25){
|
| 72 |
+
printf(" 25%% ");
|
| 73 |
+
fflush(stdout);
|
| 74 |
+
}
|
| 75 |
+
else if((double)i/threadcount == .5){
|
| 76 |
+
printf(" 50%% ");
|
| 77 |
+
fflush(stdout);
|
| 78 |
+
}
|
| 79 |
+
else if((double)i/threadcount == .75){
|
| 80 |
+
printf(" 75%% ");
|
| 81 |
+
fflush(stdout);
|
| 82 |
+
}
|
| 83 |
+
}//end for
|
| 84 |
+
//MATH, SEE MONTE CARLO PI CALCULATION
|
| 85 |
+
pi = 4 * ((double)pointsinside/threadcount);//4*(number of points inside/total number of threads)
|
| 86 |
+
printf("\n\nPi is estimated to: %f\n\n%d", pi, pointsinside);
|
| 87 |
+
fflush(stdout);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
pool/shard000/C/0008927_channel_layout.c
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
| 3 |
+
*
|
| 4 |
+
* This file is part of Libav.
|
| 5 |
+
*
|
| 6 |
+
* Libav is free software; you can redistribute it and/or
|
| 7 |
+
* modify it under the terms of the GNU Lesser General Public
|
| 8 |
+
* License as published by the Free Software Foundation; either
|
| 9 |
+
* version 2.1 of the License, or (at your option) any later version.
|
| 10 |
+
*
|
| 11 |
+
* Libav is distributed in the hope that it will be useful,
|
| 12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
+
* Lesser General Public License for more details.
|
| 15 |
+
*
|
| 16 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 17 |
+
* License along with Libav; if not, write to the Free Software
|
| 18 |
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @file
|
| 23 |
+
* audio channel layout utility functions
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
#include "avstring.h"
|
| 27 |
+
#include "avutil.h"
|
| 28 |
+
#include "channel_layout.h"
|
| 29 |
+
#include "common.h"
|
| 30 |
+
|
| 31 |
+
static const char * const channel_names[] = {
|
| 32 |
+
[0] = "FL", /* front left */
|
| 33 |
+
[1] = "FR", /* front right */
|
| 34 |
+
[2] = "FC", /* front center */
|
| 35 |
+
[3] = "LFE", /* low frequency */
|
| 36 |
+
[4] = "BL", /* back left */
|
| 37 |
+
[5] = "BR", /* back right */
|
| 38 |
+
[6] = "FLC", /* front left-of-center */
|
| 39 |
+
[7] = "FRC", /* front right-of-center */
|
| 40 |
+
[8] = "BC", /* back-center */
|
| 41 |
+
[9] = "SL", /* side left */
|
| 42 |
+
[10] = "SR", /* side right */
|
| 43 |
+
[11] = "TC", /* top center */
|
| 44 |
+
[12] = "TFL", /* top front left */
|
| 45 |
+
[13] = "TFC", /* top front center */
|
| 46 |
+
[14] = "TFR", /* top front right */
|
| 47 |
+
[15] = "TBL", /* top back left */
|
| 48 |
+
[16] = "TBC", /* top back center */
|
| 49 |
+
[17] = "TBR", /* top back right */
|
| 50 |
+
[29] = "DL", /* downmix left */
|
| 51 |
+
[30] = "DR", /* downmix right */
|
| 52 |
+
[31] = "WL", /* wide left */
|
| 53 |
+
[32] = "WR", /* wide right */
|
| 54 |
+
[33] = "SDL", /* surround direct left */
|
| 55 |
+
[34] = "SDR", /* surround direct right */
|
| 56 |
+
[35] = "LFE2", /* low frequency 2 */
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
static const char *get_channel_name(int channel_id)
|
| 60 |
+
{
|
| 61 |
+
if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
|
| 62 |
+
return NULL;
|
| 63 |
+
return channel_names[channel_id];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
static const struct {
|
| 67 |
+
const char *name;
|
| 68 |
+
int nb_channels;
|
| 69 |
+
uint64_t layout;
|
| 70 |
+
} channel_layout_map[] = {
|
| 71 |
+
{ "mono", 1, AV_CH_LAYOUT_MONO },
|
| 72 |
+
{ "stereo", 2, AV_CH_LAYOUT_STEREO },
|
| 73 |
+
{ "stereo", 2, AV_CH_LAYOUT_STEREO_DOWNMIX },
|
| 74 |
+
{ "2.1", 3, AV_CH_LAYOUT_2POINT1 },
|
| 75 |
+
{ "3.0", 3, AV_CH_LAYOUT_SURROUND },
|
| 76 |
+
{ "3.0(back)", 3, AV_CH_LAYOUT_2_1 },
|
| 77 |
+
{ "3.1", 4, AV_CH_LAYOUT_3POINT1 },
|
| 78 |
+
{ "4.0", 4, AV_CH_LAYOUT_4POINT0 },
|
| 79 |
+
{ "quad", 4, AV_CH_LAYOUT_QUAD },
|
| 80 |
+
{ "quad(side)", 4, AV_CH_LAYOUT_2_2 },
|
| 81 |
+
{ "4.1", 5, AV_CH_LAYOUT_4POINT1 },
|
| 82 |
+
{ "5.0", 5, AV_CH_LAYOUT_5POINT0 },
|
| 83 |
+
{ "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK },
|
| 84 |
+
{ "5.1", 6, AV_CH_LAYOUT_5POINT1 },
|
| 85 |
+
{ "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK },
|
| 86 |
+
{ "6.0", 6, AV_CH_LAYOUT_6POINT0 },
|
| 87 |
+
{ "6.0(front)", 6, AV_CH_LAYOUT_6POINT0_FRONT },
|
| 88 |
+
{ "hexagonal", 6, AV_CH_LAYOUT_HEXAGONAL },
|
| 89 |
+
{ "6.1", 7, AV_CH_LAYOUT_6POINT1 },
|
| 90 |
+
{ "6.1", 7, AV_CH_LAYOUT_6POINT1_BACK },
|
| 91 |
+
{ "6.1(front)", 7, AV_CH_LAYOUT_6POINT1_FRONT },
|
| 92 |
+
{ "7.0", 7, AV_CH_LAYOUT_7POINT0 },
|
| 93 |
+
{ "7.0(front)", 7, AV_CH_LAYOUT_7POINT0_FRONT },
|
| 94 |
+
{ "7.1", 8, AV_CH_LAYOUT_7POINT1 },
|
| 95 |
+
{ "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE },
|
| 96 |
+
{ "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE_BACK },
|
| 97 |
+
{ "octagonal", 8, AV_CH_LAYOUT_OCTAGONAL },
|
| 98 |
+
{ "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
|
| 99 |
+
{ 0 }
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
static uint64_t get_channel_layout_single(const char *name, int name_len)
|
| 103 |
+
{
|
| 104 |
+
int i;
|
| 105 |
+
char *end;
|
| 106 |
+
int64_t layout;
|
| 107 |
+
|
| 108 |
+
for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map) - 1; i++) {
|
| 109 |
+
if (strlen(channel_layout_map[i].name) == name_len &&
|
| 110 |
+
!memcmp(channel_layout_map[i].name, name, name_len))
|
| 111 |
+
return channel_layout_map[i].layout;
|
| 112 |
+
}
|
| 113 |
+
for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
|
| 114 |
+
if (channel_names[i] &&
|
| 115 |
+
strlen(channel_names[i]) == name_len &&
|
| 116 |
+
!memcmp(channel_names[i], name, name_len))
|
| 117 |
+
return (int64_t)1 << i;
|
| 118 |
+
i = strtol(name, &end, 10);
|
| 119 |
+
if (end - name == name_len ||
|
| 120 |
+
(end + 1 - name == name_len && *end == 'c'))
|
| 121 |
+
return av_get_default_channel_layout(i);
|
| 122 |
+
layout = strtoll(name, &end, 0);
|
| 123 |
+
if (end - name == name_len)
|
| 124 |
+
return FFMAX(layout, 0);
|
| 125 |
+
return 0;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
uint64_t av_get_channel_layout(const char *name)
|
| 129 |
+
{
|
| 130 |
+
const char *n, *e;
|
| 131 |
+
const char *name_end = name + strlen(name);
|
| 132 |
+
int64_t layout = 0, layout_single;
|
| 133 |
+
|
| 134 |
+
for (n = name; n < name_end; n = e + 1) {
|
| 135 |
+
for (e = n; e < name_end && *e != '+' && *e != '|'; e++);
|
| 136 |
+
layout_single = get_channel_layout_single(n, e - n);
|
| 137 |
+
if (!layout_single)
|
| 138 |
+
return 0;
|
| 139 |
+
layout |= layout_single;
|
| 140 |
+
}
|
| 141 |
+
return layout;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void av_get_channel_layout_string(char *buf, int buf_size,
|
| 145 |
+
int nb_channels, uint64_t channel_layout)
|
| 146 |
+
{
|
| 147 |
+
int i;
|
| 148 |
+
|
| 149 |
+
if (nb_channels <= 0)
|
| 150 |
+
nb_channels = av_get_channel_layout_nb_channels(channel_layout);
|
| 151 |
+
|
| 152 |
+
for (i = 0; channel_layout_map[i].name; i++)
|
| 153 |
+
if (nb_channels == channel_layout_map[i].nb_channels &&
|
| 154 |
+
channel_layout == channel_layout_map[i].layout) {
|
| 155 |
+
av_strlcpy(buf, channel_layout_map[i].name, buf_size);
|
| 156 |
+
return;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
snprintf(buf, buf_size, "%d channels", nb_channels);
|
| 160 |
+
if (channel_layout) {
|
| 161 |
+
int i, ch;
|
| 162 |
+
av_strlcat(buf, " (", buf_size);
|
| 163 |
+
for (i = 0, ch = 0; i < 64; i++) {
|
| 164 |
+
if ((channel_layout & (UINT64_C(1) << i))) {
|
| 165 |
+
const char *name = get_channel_name(i);
|
| 166 |
+
if (name) {
|
| 167 |
+
if (ch > 0)
|
| 168 |
+
av_strlcat(buf, "|", buf_size);
|
| 169 |
+
av_strlcat(buf, name, buf_size);
|
| 170 |
+
}
|
| 171 |
+
ch++;
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
av_strlcat(buf, ")", buf_size);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
|
| 179 |
+
{
|
| 180 |
+
return av_popcount64(channel_layout);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
uint64_t av_get_default_channel_layout(int nb_channels)
|
| 184 |
+
{
|
| 185 |
+
switch(nb_channels) {
|
| 186 |
+
case 1: return AV_CH_LAYOUT_MONO;
|
| 187 |
+
case 2: return AV_CH_LAYOUT_STEREO;
|
| 188 |
+
case 3: return AV_CH_LAYOUT_SURROUND;
|
| 189 |
+
case 4: return AV_CH_LAYOUT_QUAD;
|
| 190 |
+
case 5: return AV_CH_LAYOUT_5POINT0;
|
| 191 |
+
case 6: return AV_CH_LAYOUT_5POINT1;
|
| 192 |
+
case 7: return AV_CH_LAYOUT_6POINT1;
|
| 193 |
+
case 8: return AV_CH_LAYOUT_7POINT1;
|
| 194 |
+
default: return 0;
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
int av_get_channel_layout_channel_index(uint64_t channel_layout,
|
| 199 |
+
uint64_t channel)
|
| 200 |
+
{
|
| 201 |
+
if (!(channel_layout & channel) ||
|
| 202 |
+
av_get_channel_layout_nb_channels(channel) != 1)
|
| 203 |
+
return AVERROR(EINVAL);
|
| 204 |
+
channel_layout &= channel - 1;
|
| 205 |
+
return av_get_channel_layout_nb_channels(channel_layout);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
const char *av_get_channel_name(uint64_t channel)
|
| 209 |
+
{
|
| 210 |
+
int i;
|
| 211 |
+
if (av_get_channel_layout_nb_channels(channel) != 1)
|
| 212 |
+
return NULL;
|
| 213 |
+
for (i = 0; i < 64; i++)
|
| 214 |
+
if ((1ULL<<i) & channel)
|
| 215 |
+
return get_channel_name(i);
|
| 216 |
+
return NULL;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
|
| 220 |
+
{
|
| 221 |
+
int i;
|
| 222 |
+
|
| 223 |
+
if (av_get_channel_layout_nb_channels(channel_layout) <= index)
|
| 224 |
+
return 0;
|
| 225 |
+
|
| 226 |
+
for (i = 0; i < 64; i++) {
|
| 227 |
+
if ((1ULL << i) & channel_layout && !index--)
|
| 228 |
+
return 1ULL << i;
|
| 229 |
+
}
|
| 230 |
+
return 0;
|
| 231 |
+
}
|
pool/shard000/C/0008928_exoparg3.c
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/******************************************************************************
|
| 3 |
+
*
|
| 4 |
+
* Module Name: exoparg3 - AML execution - opcodes with 3 arguments
|
| 5 |
+
*
|
| 6 |
+
*****************************************************************************/
|
| 7 |
+
|
| 8 |
+
/*
|
| 9 |
+
* Copyright (C) 2000 - 2005, R. Byron Moore
|
| 10 |
+
* All rights reserved.
|
| 11 |
+
*
|
| 12 |
+
* Redistribution and use in source and binary forms, with or without
|
| 13 |
+
* modification, are permitted provided that the following conditions
|
| 14 |
+
* are met:
|
| 15 |
+
* 1. Redistributions of source code must retain the above copyright
|
| 16 |
+
* notice, this list of conditions, and the following disclaimer,
|
| 17 |
+
* without modification.
|
| 18 |
+
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
| 19 |
+
* substantially similar to the "NO WARRANTY" disclaimer below
|
| 20 |
+
* ("Disclaimer") and any redistribution must be conditioned upon
|
| 21 |
+
* including a substantially similar Disclaimer requirement for further
|
| 22 |
+
* binary redistribution.
|
| 23 |
+
* 3. Neither the names of the above-listed copyright holders nor the names
|
| 24 |
+
* of any contributors may be used to endorse or promote products derived
|
| 25 |
+
* from this software without specific prior written permission.
|
| 26 |
+
*
|
| 27 |
+
* Alternatively, this software may be distributed under the terms of the
|
| 28 |
+
* GNU General Public License ("GPL") version 2 as published by the Free
|
| 29 |
+
* Software Foundation.
|
| 30 |
+
*
|
| 31 |
+
* NO WARRANTY
|
| 32 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 33 |
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 34 |
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
|
| 35 |
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 36 |
+
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 37 |
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 38 |
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 39 |
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 40 |
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 41 |
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 42 |
+
* POSSIBILITY OF SUCH DAMAGES.
|
| 43 |
+
*/
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
#include <acpi/acpi.h>
|
| 47 |
+
#include <acpi/acinterp.h>
|
| 48 |
+
#include <acpi/acparser.h>
|
| 49 |
+
#include <acpi/amlcode.h>
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
#define _COMPONENT ACPI_EXECUTER
|
| 53 |
+
ACPI_MODULE_NAME ("exoparg3")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
/*!
|
| 57 |
+
* Naming convention for AML interpreter execution routines.
|
| 58 |
+
*
|
| 59 |
+
* The routines that begin execution of AML opcodes are named with a common
|
| 60 |
+
* convention based upon the number of arguments, the number of target operands,
|
| 61 |
+
* and whether or not a value is returned:
|
| 62 |
+
*
|
| 63 |
+
* AcpiExOpcode_xA_yT_zR
|
| 64 |
+
*
|
| 65 |
+
* Where:
|
| 66 |
+
*
|
| 67 |
+
* xA - ARGUMENTS: The number of arguments (input operands) that are
|
| 68 |
+
* required for this opcode type (1 through 6 args).
|
| 69 |
+
* yT - TARGETS: The number of targets (output operands) that are required
|
| 70 |
+
* for this opcode type (0, 1, or 2 targets).
|
| 71 |
+
* zR - RETURN VALUE: Indicates whether this opcode type returns a value
|
| 72 |
+
* as the function return (0 or 1).
|
| 73 |
+
*
|
| 74 |
+
* The AcpiExOpcode* functions are called via the Dispatcher component with
|
| 75 |
+
* fully resolved operands.
|
| 76 |
+
!*/
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
/*******************************************************************************
|
| 80 |
+
*
|
| 81 |
+
* FUNCTION: acpi_ex_opcode_3A_0T_0R
|
| 82 |
+
*
|
| 83 |
+
* PARAMETERS: walk_state - Current walk state
|
| 84 |
+
*
|
| 85 |
+
* RETURN: Status
|
| 86 |
+
*
|
| 87 |
+
* DESCRIPTION: Execute Triadic operator (3 operands)
|
| 88 |
+
*
|
| 89 |
+
******************************************************************************/
|
| 90 |
+
|
| 91 |
+
acpi_status
|
| 92 |
+
acpi_ex_opcode_3A_0T_0R (
|
| 93 |
+
struct acpi_walk_state *walk_state)
|
| 94 |
+
{
|
| 95 |
+
union acpi_operand_object **operand = &walk_state->operands[0];
|
| 96 |
+
struct acpi_signal_fatal_info *fatal;
|
| 97 |
+
acpi_status status = AE_OK;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R",
|
| 101 |
+
acpi_ps_get_opcode_name (walk_state->opcode));
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
switch (walk_state->opcode) {
|
| 105 |
+
case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
|
| 106 |
+
|
| 107 |
+
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
|
| 108 |
+
"fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
|
| 109 |
+
(u32) operand[0]->integer.value,
|
| 110 |
+
(u32) operand[1]->integer.value,
|
| 111 |
+
(u32) operand[2]->integer.value));
|
| 112 |
+
|
| 113 |
+
fatal = ACPI_MEM_ALLOCATE (sizeof (struct acpi_signal_fatal_info));
|
| 114 |
+
if (fatal) {
|
| 115 |
+
fatal->type = (u32) operand[0]->integer.value;
|
| 116 |
+
fatal->code = (u32) operand[1]->integer.value;
|
| 117 |
+
fatal->argument = (u32) operand[2]->integer.value;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/* Always signal the OS! */
|
| 121 |
+
|
| 122 |
+
status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal);
|
| 123 |
+
|
| 124 |
+
/* Might return while OS is shutting down, just continue */
|
| 125 |
+
|
| 126 |
+
ACPI_MEM_FREE (fatal);
|
| 127 |
+
break;
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
default:
|
| 131 |
+
|
| 132 |
+
ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
|
| 133 |
+
walk_state->opcode));
|
| 134 |
+
status = AE_AML_BAD_OPCODE;
|
| 135 |
+
goto cleanup;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
cleanup:
|
| 140 |
+
|
| 141 |
+
return_ACPI_STATUS (status);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
/*******************************************************************************
|
| 146 |
+
*
|
| 147 |
+
* FUNCTION: acpi_ex_opcode_3A_1T_1R
|
| 148 |
+
*
|
| 149 |
+
* PARAMETERS: walk_state - Current walk state
|
| 150 |
+
*
|
| 151 |
+
* RETURN: Status
|
| 152 |
+
*
|
| 153 |
+
* DESCRIPTION: Execute Triadic operator (3 operands)
|
| 154 |
+
*
|
| 155 |
+
******************************************************************************/
|
| 156 |
+
|
| 157 |
+
acpi_status
|
| 158 |
+
acpi_ex_opcode_3A_1T_1R (
|
| 159 |
+
struct acpi_walk_state *walk_state)
|
| 160 |
+
{
|
| 161 |
+
union acpi_operand_object **operand = &walk_state->operands[0];
|
| 162 |
+
union acpi_operand_object *return_desc = NULL;
|
| 163 |
+
char *buffer;
|
| 164 |
+
acpi_status status = AE_OK;
|
| 165 |
+
acpi_integer index;
|
| 166 |
+
acpi_size length;
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R",
|
| 170 |
+
acpi_ps_get_opcode_name (walk_state->opcode));
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
switch (walk_state->opcode) {
|
| 174 |
+
case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
|
| 175 |
+
|
| 176 |
+
/*
|
| 177 |
+
* Create the return object. The Source operand is guaranteed to be
|
| 178 |
+
* either a String or a Buffer, so just use its type.
|
| 179 |
+
*/
|
| 180 |
+
return_desc = acpi_ut_create_internal_object (
|
| 181 |
+
ACPI_GET_OBJECT_TYPE (operand[0]));
|
| 182 |
+
if (!return_desc) {
|
| 183 |
+
status = AE_NO_MEMORY;
|
| 184 |
+
goto cleanup;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/* Get the Integer values from the objects */
|
| 188 |
+
|
| 189 |
+
index = operand[1]->integer.value;
|
| 190 |
+
length = (acpi_size) operand[2]->integer.value;
|
| 191 |
+
|
| 192 |
+
/*
|
| 193 |
+
* If the index is beyond the length of the String/Buffer, or if the
|
| 194 |
+
* requested length is zero, return a zero-length String/Buffer
|
| 195 |
+
*/
|
| 196 |
+
if ((index < operand[0]->string.length) &&
|
| 197 |
+
(length > 0)) {
|
| 198 |
+
/* Truncate request if larger than the actual String/Buffer */
|
| 199 |
+
|
| 200 |
+
if ((index + length) >
|
| 201 |
+
operand[0]->string.length) {
|
| 202 |
+
length = (acpi_size) operand[0]->string.length -
|
| 203 |
+
(acpi_size) index;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* Allocate a new buffer for the String/Buffer */
|
| 207 |
+
|
| 208 |
+
buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1);
|
| 209 |
+
if (!buffer) {
|
| 210 |
+
status = AE_NO_MEMORY;
|
| 211 |
+
goto cleanup;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/* Copy the portion requested */
|
| 215 |
+
|
| 216 |
+
ACPI_MEMCPY (buffer, operand[0]->string.pointer + index,
|
| 217 |
+
length);
|
| 218 |
+
|
| 219 |
+
/* Set the length of the new String/Buffer */
|
| 220 |
+
|
| 221 |
+
return_desc->string.pointer = buffer;
|
| 222 |
+
return_desc->string.length = (u32) length;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/* Mark buffer initialized */
|
| 226 |
+
|
| 227 |
+
return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
|
| 228 |
+
break;
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
default:
|
| 232 |
+
|
| 233 |
+
ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
|
| 234 |
+
walk_state->opcode));
|
| 235 |
+
status = AE_AML_BAD_OPCODE;
|
| 236 |
+
goto cleanup;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/* Store the result in the target */
|
| 240 |
+
|
| 241 |
+
status = acpi_ex_store (return_desc, operand[3], walk_state);
|
| 242 |
+
|
| 243 |
+
cleanup:
|
| 244 |
+
|
| 245 |
+
/* Delete return object on error */
|
| 246 |
+
|
| 247 |
+
if (ACPI_FAILURE (status)) {
|
| 248 |
+
acpi_ut_remove_reference (return_desc);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
/* Set the return object and exit */
|
| 252 |
+
|
| 253 |
+
if (!walk_state->result_obj) {
|
| 254 |
+
walk_state->result_obj = return_desc;
|
| 255 |
+
}
|
| 256 |
+
return_ACPI_STATUS (status);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
|