file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/875047.c
#include<stdio.h> #define N 100005 int v[N]; int main() { int n,k; scanf("%d",&n); while(n--) { int a; scanf("%d",&a); v[a]++; } scanf("%d",&k); for(int i=N-1; i>=0; i--) { k -= (v[i] > 0); if(k<=0) { printf("%d %d",i,v[i]); return 0; } } return 0; }
the_stack_data/852701.c
#include <stdio.h> #include <time.h> // clang -Wall greet03_time.c -o greetings int main(int argc, char *argv[]) { time_t now; struct tm *clock; // man localtime int hour; time(&now); // man time.2 clock = localtime(&now); hour = clock->tm_hour; printf("Good "); if (hour < 12) { printf("morning"); } else if (hour < 17) { printf("afternoon"); } else { printf("evening"); } if (argc > 1) { printf(", %s", argv[1]); } putchar('\n'); printf("It's %s", ctime(&now)); return(0); }
the_stack_data/111078123.c
#include <stdio.h> void stats(int resource, int doom) { } int main(void) { int i; int j; int resource = 10; int doom = 0; int end = 0; int unit[10][10]; char* number; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { unit[j][i] = 0; //this would work if x++ was done here because j is gompleting to the end here, it alkl works out don't worry //printf("%d", unit[j][i]); } } /*number ranges 0 = Undiscovered space 1 = Discovered space 2 -> 5 = trash, wood, puddles, odd but seemingly useless items, the lower the number, the more rare the item 6 -> 12 = Places to restock, every time you are in a space of this number range, the doom meter decreased by 1 and you have the option of spending doom on resources, you want to have a low amount of doom, but you need doom for resources 13 -> 26 = Enemy Places ... (Add more) 346 = End, if you manage to get here you win the game, but there may be a price that you have to pay inorder to pass, strenuous, or mind numbingly hard */ printf("You have mastered the wraths of hell and now you must do what you can to exit the intermediate world.\nStrange things occur in this world.\n"); while (end == 0) { //for some reason the shit below breaks out of the loop so this opne above catches it and then the one below is regained while (end == 0) { printf(""); } } return 0; }
the_stack_data/146455.c
// code: 0 int main() { return !1.0; }
the_stack_data/237642328.c
/* pnggccrd.c was removed from libpng-1.2.20. */ /* This code snippet is for use by configure's compilation test. */ #if (!defined _MSC_VER) && \ defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ defined(PNG_MMX_CODE_SUPPORTED) int PNGAPI _png_dummy_mmx_support(void); static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested int PNGAPI _png_dummy_mmx_support(void) __attribute__((noinline)); int PNGAPI _png_dummy_mmx_support(void) { int result; #ifdef PNG_MMX_CODE_SUPPORTED // superfluous, but what the heck __asm__ __volatile__ ( #ifdef __x86_64__ "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction "pushq %%rcx \n\t" // so does rcx... "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) "pushfq \n\t" // save Eflag to stack "popq %%rax \n\t" // get Eflag from stack into rax "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) "pushq %%rax \n\t" // save modified Eflag back to stack "popfq \n\t" // restore modified value to Eflag reg "pushfq \n\t" // save Eflag to stack "popq %%rax \n\t" // get Eflag from stack "pushq %%rcx \n\t" // save original Eflag to stack "popfq \n\t" // restore original Eflag #else "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction "pushl %%ecx \n\t" // so does ecx... "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) "pushfl \n\t" // save Eflag to stack "popl %%eax \n\t" // get Eflag from stack into eax "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) "pushl %%eax \n\t" // save modified Eflag back to stack "popfl \n\t" // restore modified value to Eflag reg "pushfl \n\t" // save Eflag to stack "popl %%eax \n\t" // get Eflag from stack "pushl %%ecx \n\t" // save original Eflag to stack "popfl \n\t" // restore original Eflag #endif "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag "jz 0f \n\t" // if same, CPUID instr. is not supported "xorl %%eax, %%eax \n\t" // set eax to zero // ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) "cpuid \n\t" // get the CPU identification info "cmpl $1, %%eax \n\t" // make sure eax return non-zero value "jl 0f \n\t" // if eax is zero, MMX is not supported "xorl %%eax, %%eax \n\t" // set eax to zero and... "incl %%eax \n\t" // ...increment eax to 1. This pair is // faster than the instruction "mov eax, 1" "cpuid \n\t" // get the CPU identification info again "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) "cmpl $0, %%edx \n\t" // 0 = MMX not supported "jz 0f \n\t" // non-zero = yes, MMX IS supported "movl $1, %%eax \n\t" // set return value to 1 "jmp 1f \n\t" // DONE: have MMX support "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions "movl $0, %%eax \n\t" // set return value to 0 "1: \n\t" // .RETURN: target label for jump instructions #ifdef __x86_64__ "popq %%rdx \n\t" // restore rdx "popq %%rcx \n\t" // restore rcx "popq %%rbx \n\t" // restore rbx #else "popl %%edx \n\t" // restore edx "popl %%ecx \n\t" // restore ecx "popl %%ebx \n\t" // restore ebx #endif // "ret \n\t" // DONE: no MMX support // (fall through to standard C "ret") : "=a" (result) // output list : // any variables used on input (none) // no clobber list // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually // , "memory" // if write to a variable gcc thought was in a reg // , "cc" // "condition codes" (flag bits) ); _mmx_supported = result; #else _mmx_supported = 0; #endif /* PNG_MMX_CODE_SUPPORTED */ return _mmx_supported; } #endif
the_stack_data/20451450.c
/**************************************************************************** * arch/sim/src/sim/up_x11framebuffer.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <syslog.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <sys/ipc.h> #ifndef CONFIG_SIM_X11NOSHM # include <sys/shm.h> # include <X11/extensions/XShm.h> #endif /**************************************************************************** * Public Data ****************************************************************************/ /* Also used in up_x11eventloop */ Display *g_display; /**************************************************************************** * Private Data ****************************************************************************/ static int g_screen; static Window g_window; static GC g_gc; #ifndef CONFIG_SIM_X11NOSHM static XShmSegmentInfo g_xshminfo; static int g_xerror; #endif static XImage *g_image; static unsigned char *g_framebuffer; static unsigned short g_fbpixelwidth; static unsigned short g_fbpixelheight; static int g_shmcheckpoint = 0; static int b_useshm; /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** * Name: up_x11createframe ****************************************************************************/ static inline int up_x11createframe(void) { XGCValues gcval; char *argv[2] = { "nuttx", NULL }; char *winName = "NuttX"; char *iconName = "NX"; XTextProperty winprop; XTextProperty iconprop; XSizeHints hints; g_display = XOpenDisplay(NULL); if (g_display == NULL) { syslog(LOG_ERR, "Unable to open display.\n"); return -1; } g_screen = DefaultScreen(g_display); g_window = XCreateSimpleWindow(g_display, DefaultRootWindow(g_display), 0, 0, g_fbpixelwidth, g_fbpixelheight, 2, BlackPixel(g_display, g_screen), BlackPixel(g_display, g_screen)); XStringListToTextProperty(&winName, 1, &winprop); XStringListToTextProperty(&iconName, 1, &iconprop); hints.flags = PSize | PMinSize | PMaxSize; hints.width = hints.min_width = hints.max_width = g_fbpixelwidth; hints.height = hints.min_height = hints.max_height = g_fbpixelheight; XSetWMProperties(g_display, g_window, &winprop, &iconprop, argv, 1, &hints, NULL, NULL); XMapWindow(g_display, g_window); /* Select window input events */ #if defined(CONFIG_SIM_AJOYSTICK) XSelectInput(g_display, g_window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask); #else XSelectInput(g_display, g_window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask); #endif /* Release queued events on the display */ #if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) XAllowEvents(g_display, AsyncBoth, CurrentTime); /* Grab mouse button 1, enabling mouse-related events */ XGrabButton(g_display, Button1, AnyModifier, g_window, 1, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None); #endif gcval.graphics_exposures = 0; g_gc = XCreateGC(g_display, g_window, GCGraphicsExposures, &gcval); return 0; } /**************************************************************************** * Name: up_x11errorhandler ****************************************************************************/ #ifndef CONFIG_SIM_X11NOSHM static int up_x11errorhandler(Display *display, XErrorEvent *event) { g_xerror = 1; return 0; } #endif /**************************************************************************** * Name: up_x11traperrors ****************************************************************************/ #ifndef CONFIG_SIM_X11NOSHM static void up_x11traperrors(void) { g_xerror = 0; XSetErrorHandler(up_x11errorhandler); } #endif /**************************************************************************** * Name: up_x11untraperrors ****************************************************************************/ #ifndef CONFIG_SIM_X11NOSHM static int up_x11untraperrors(void) { XSync(g_display, 0); XSetErrorHandler(NULL); return g_xerror; } #endif /**************************************************************************** * Name: up_x11uninitX ****************************************************************************/ static void up_x11uninitX(void) { #ifndef CONFIG_SIM_X11NOSHM if (g_shmcheckpoint > 4) { XShmDetach(g_display, &g_xshminfo); } if (g_shmcheckpoint > 3) { shmdt(g_xshminfo.shmaddr); } if (g_shmcheckpoint > 2) { shmctl(g_xshminfo.shmid, IPC_RMID, 0); } #endif if (g_shmcheckpoint > 1) { XDestroyImage(g_image); } /* Un-grab the mouse buttons */ #if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) XUngrabButton(g_display, Button1, AnyModifier, g_window); #endif XCloseDisplay(g_display); } /**************************************************************************** * Name: up_x11uninitialize ****************************************************************************/ #ifndef CONFIG_SIM_X11NOSHM static void up_x11uninitialize(void) { if (g_shmcheckpoint > 1) { if (!b_useshm && g_framebuffer) { free(g_framebuffer); g_framebuffer = 0; } } if (g_shmcheckpoint > 0) { g_shmcheckpoint = 1; } } #endif /**************************************************************************** * Name: up_x11mapsharedmem ****************************************************************************/ static inline int up_x11mapsharedmem(int depth, unsigned int fblen) { #ifndef CONFIG_SIM_X11NOSHM Status result; #endif atexit(up_x11uninitX); g_shmcheckpoint = 1; b_useshm = 0; #ifndef CONFIG_SIM_X11NOSHM if (XShmQueryExtension(g_display)) { b_useshm = 1; up_x11traperrors(); g_image = XShmCreateImage(g_display, DefaultVisual(g_display, g_screen), depth, ZPixmap, NULL, &g_xshminfo, g_fbpixelwidth, g_fbpixelheight); if (up_x11untraperrors()) { up_x11uninitialize(); goto shmerror; } if (!g_image) { syslog(LOG_ERR, "Unable to create g_image.\n"); return -1; } g_shmcheckpoint++; g_xshminfo.shmid = shmget(IPC_PRIVATE, g_image->bytes_per_line * g_image->height, IPC_CREAT | 0777); if (g_xshminfo.shmid < 0) { up_x11uninitialize(); goto shmerror; } g_shmcheckpoint++; g_image->data = (char *) shmat(g_xshminfo.shmid, 0, 0); if (g_image->data == ((char *) -1)) { up_x11uninitialize(); goto shmerror; } g_shmcheckpoint++; g_xshminfo.shmaddr = g_image->data; g_xshminfo.readOnly = 0; up_x11traperrors(); result = XShmAttach(g_display, &g_xshminfo); if (up_x11untraperrors() || !result) { up_x11uninitialize(); goto shmerror; } g_framebuffer = (unsigned char *)g_image->data; g_shmcheckpoint++; } else #endif if (!b_useshm) { #ifndef CONFIG_SIM_X11NOSHM shmerror: #endif b_useshm = 0; g_framebuffer = (unsigned char *)malloc(fblen); g_image = XCreateImage(g_display, DefaultVisual(g_display, g_screen), depth, ZPixmap, 0, (char *)g_framebuffer, g_fbpixelwidth, g_fbpixelheight, 8, 0); if (g_image == NULL) { syslog(LOG_ERR, "Unable to create g_image\n"); return -1; } g_shmcheckpoint++; } return 0; } /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: up_x11initialize * * Description: * Make an X11 window look like a frame buffer. * ****************************************************************************/ int up_x11initialize(unsigned short width, unsigned short height, void **fbmem, size_t *fblen, unsigned char *bpp, unsigned short *stride) { XWindowAttributes windowAttributes; int depth; int ret; /* Save inputs */ g_fbpixelwidth = width; g_fbpixelheight = height; /* Create the X11 window */ ret = up_x11createframe(); if (ret < 0) { return ret; } /* Determine the supported pixel bpp of the current window */ XGetWindowAttributes(g_display, DefaultRootWindow(g_display), &windowAttributes); /* Get the pixel depth. If the depth is 24-bits, use 32 because X expects * 32-bit alignment anyway. */ depth = windowAttributes.depth; if (depth == 24) { depth = 32; } *bpp = depth; *stride = (depth * width / 8); *fblen = (*stride * height); /* Map the window to shared memory */ up_x11mapsharedmem(windowAttributes.depth, *fblen); *fbmem = (void *)g_framebuffer; return 0; } /**************************************************************************** * Name: up_x11cmap ****************************************************************************/ int up_x11cmap(unsigned short first, unsigned short len, unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *transp) { Colormap cMap; int ndx; /* Convert each color to X11 scaling */ cMap = DefaultColormap(g_display, g_screen); for (ndx = first; ndx < first + len; ndx++) { XColor color; /* Convert to RGB. In the NuttX cmap, each component * ranges from 0-255; for X11 the range is 0-65536 */ color.red = (short)(*red++) << 8; color.green = (short)(*green++) << 8; color.blue = (short)(*blue++) << 8; color.flags = DoRed | DoGreen | DoBlue; /* Then allocate a color for this selection */ if (!XAllocColor(g_display, cMap, &color)) { syslog(LOG_ERR, "Failed to allocate color%d\n", ndx); return -1; } } return 0; } /**************************************************************************** * Name: up_x11update ****************************************************************************/ void up_x11update(void) { #ifndef CONFIG_SIM_X11NOSHM if (b_useshm) { XShmPutImage(g_display, g_window, g_gc, g_image, 0, 0, 0, 0, g_fbpixelwidth, g_fbpixelheight, 0); } else #endif { XPutImage(g_display, g_window, g_gc, g_image, 0, 0, 0, 0, g_fbpixelwidth, g_fbpixelheight); } XSync(g_display, 0); }
the_stack_data/165768954.c
// Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // // // Copyright (c) 2019-2020 checkra1n team // This file is part of pongoOS. // #ifdef AUTOBOOT #define LL_KTRW_INTERNAL 1 #include <pongo.h> void pongo_autoboot() { uint64_t* autoboot_block = (uint64_t*)0x429000000; if (autoboot_block[0] == 0x746F6F626F747561) { memcpy(loader_xfer_recv_data, &autoboot_block[2], (uint32_t)autoboot_block[1]); loader_xfer_recv_count = (uint32_t)autoboot_block[1]; autoboot_count = loader_xfer_recv_count; queue_rx_string("modload\nautoboot\n"); } } #endif
the_stack_data/89199057.c
/* * C Program to Implement Stooge Sort */ #include <stdio.h> // Function Prototype void stoogesort(int [], int, int); void main() { int b[7], i; printf("Enter the values you want to sort using STOOGE SORT!!!:\n"); for (i = 0;i < 7;i++) scanf(" %d", &b[i]); stoogesort(b, 0, 6); printf("sorted by stooge sort \n"); for (i = 0;i < 7;i++) { printf("%d ", b[i]); } printf("\n"); } // Function to implement STOOGE SORT void stoogesort(int a[], int i, int j) { int temp, k; if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } if ((i + 1) >= j) return; k = (int)((j - i + 1) / 3); stoogesort(a, i, j - k); stoogesort(a, i + k, j); stoogesort(a, i, j - k); }
the_stack_data/86076475.c
/*- * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. * * %sccs.include.redist.c% */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1988 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)fp.c 5.2 (Berkeley) 05/13/91"; #endif /* not lint */ #include <stdio.h> main() { fputs("fp: fp has not been ported to the tahoe.\n", stderr); }
the_stack_data/1195295.c
#include<stdio.h> int main(void) { // this program demonstrates all the different ways of getting and outputting different data types int anInteger = 2147483647; float aFloat = 3.3; double aDouble = 4.4; long aLong = 1234567890L; char aChar = 'x'; // note the SINGLE quotes! char aNotherChar = 'Y'; char aListofChars[50] = ""; // note that this is an array of characters char aString[50] = ""; // note that a string is just an array of characters - don't let the names confuse you // boolean? printf("Please enter an integer, float, double, long, char, char2, and a string:\n\t"); printf("Integer __SIZEOF_INT__ is %d and __INT_MAX__ is %d\n", __SIZEOF_INT__, __INT_MAX__); //scanf("", anInteger, aFloat, aDouble, aLong, aChar, aNotherChar, aString); char string[25]; printf("Enter the name:"); scanf("%[^\n]*c",string); printf("My name is %s",string); }
the_stack_data/178264758.c
int binaryGap(int N) { int gap = 0; int i = 0; int met = 0; while (N) { if (N & 1) { if (met) { if (i > gap) { gap = i; } } else { met = 1; } i = 0; } i++; N = N >> 1; } return gap; }
the_stack_data/838010.c
/* Write a program to remove traililing blanks and tabs from each line of input, * and to delete entirely blank lines. */ #include <stdio.h> #define SIZE 1000 /* maximum input line size */ int get_line_size(char buffer[], int size); int trim_line(char buffer[]); int main() { int size; /* current line size */ char line[SIZE]; /* current input line */ while ((size = get_line_size(line, SIZE)) > 0) { if (trim_line(line) > 0) { printf("%s", line); } } return 0; } /* get_line_size: read a line into buffer, return size */ int get_line_size(char buffer[], int size) { int input, index; for (index = 0; index < size - 1 && (input = getchar()) != EOF && input != '\n'; index++) { buffer[index] = input; } if (input == '\n') { buffer[index++] = input; } buffer[index] = '\0'; return index; } /* trim_line: read a line into buffer, trim the line */ int trim_line(char buffer[]) { int index = 0; while ((buffer[index] != '\n') && (buffer[index] != '\0')) { index++; } index--; while ((buffer[index] == ' ') || (buffer[index] == '\t')) { index--; } if (index >= 0) { buffer[++index] = '\n'; buffer[++index] = '\0'; } return index; }
the_stack_data/462595.c
/* * Copyright (C) 2013 Red Hat * Author: Rob Clark <[email protected]> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ /* For debugging crashes, userspace can: * * tail -f /sys/kernel/debug/dri/<minor>/rd > logfile.rd * * To log the cmdstream in a format that is understood by freedreno/cffdump * utility. By comparing the last successfully completed fence #, to the * cmdstream for the next fence, you can narrow down which process and submit * caused the gpu crash/lockup. * * This bypasses drm_debugfs_create_files() mainly because we need to use * our own fops for a bit more control. In particular, we don't want to * do anything if userspace doesn't have the debugfs file open. * * The module-param "rd_full", which defaults to false, enables snapshotting * all (non-written) buffers in the submit, rather than just cmdstream bo's. * This is useful to capture the contents of (for example) vbo's or textures, * or shader programs (if not emitted inline in cmdstream). */ #ifdef CONFIG_DEBUG_FS #include <linux/kfifo.h> #include <linux/debugfs.h> #include <linux/circ_buf.h> #include <linux/wait.h> #include "msm_drv.h" #include "msm_gpu.h" #include "msm_gem.h" static bool rd_full = false; MODULE_PARM_DESC(rd_full, "If true, $debugfs/.../rd will snapshot all buffer contents"); module_param_named(rd_full, rd_full, bool, 0600); enum rd_sect_type { RD_NONE, RD_TEST, /* ascii text */ RD_CMD, /* ascii text */ RD_GPUADDR, /* u32 gpuaddr, u32 size */ RD_CONTEXT, /* raw dump */ RD_CMDSTREAM, /* raw dump */ RD_CMDSTREAM_ADDR, /* gpu addr of cmdstream */ RD_PARAM, /* u32 param_type, u32 param_val, u32 bitlen */ RD_FLUSH, /* empty, clear previous params */ RD_PROGRAM, /* shader program, raw dump */ RD_VERT_SHADER, RD_FRAG_SHADER, RD_BUFFER_CONTENTS, RD_GPU_ID, }; #define BUF_SZ 512 /* should be power of 2 */ /* space used: */ #define circ_count(circ) \ (CIRC_CNT((circ)->head, (circ)->tail, BUF_SZ)) #define circ_count_to_end(circ) \ (CIRC_CNT_TO_END((circ)->head, (circ)->tail, BUF_SZ)) /* space available: */ #define circ_space(circ) \ (CIRC_SPACE((circ)->head, (circ)->tail, BUF_SZ)) #define circ_space_to_end(circ) \ (CIRC_SPACE_TO_END((circ)->head, (circ)->tail, BUF_SZ)) struct msm_rd_state { struct drm_device *dev; bool open; struct dentry *ent; struct drm_info_node *node; /* current submit to read out: */ struct msm_gem_submit *submit; /* fifo access is synchronized on the producer side by * struct_mutex held by submit code (otherwise we could * end up w/ cmds logged in different order than they * were executed). And read_lock synchronizes the reads */ struct mutex read_lock; wait_queue_head_t fifo_event; struct circ_buf fifo; char buf[BUF_SZ]; }; static void rd_write(struct msm_rd_state *rd, const void *buf, int sz) { struct circ_buf *fifo = &rd->fifo; const char *ptr = buf; while (sz > 0) { char *fptr = &fifo->buf[fifo->head]; int n; wait_event(rd->fifo_event, circ_space(&rd->fifo) > 0); n = min(sz, circ_space_to_end(&rd->fifo)); memcpy(fptr, ptr, n); fifo->head = (fifo->head + n) & (BUF_SZ - 1); sz -= n; ptr += n; wake_up_all(&rd->fifo_event); } } static void rd_write_section(struct msm_rd_state *rd, enum rd_sect_type type, const void *buf, int sz) { rd_write(rd, &type, 4); rd_write(rd, &sz, 4); rd_write(rd, buf, sz); } static ssize_t rd_read(struct file *file, char __user *buf, size_t sz, loff_t *ppos) { struct msm_rd_state *rd = file->private_data; struct circ_buf *fifo = &rd->fifo; const char *fptr = &fifo->buf[fifo->tail]; int n = 0, ret = 0; mutex_lock(&rd->read_lock); ret = wait_event_interruptible(rd->fifo_event, circ_count(&rd->fifo) > 0); if (ret) goto out; n = min_t(int, sz, circ_count_to_end(&rd->fifo)); if (copy_to_user(buf, fptr, n)) { ret = -EFAULT; goto out; } fifo->tail = (fifo->tail + n) & (BUF_SZ - 1); *ppos += n; wake_up_all(&rd->fifo_event); out: mutex_unlock(&rd->read_lock); if (ret) return ret; return n; } static int rd_open(struct inode *inode, struct file *file) { struct msm_rd_state *rd = inode->i_private; struct drm_device *dev = rd->dev; struct msm_drm_private *priv = dev->dev_private; struct msm_gpu *gpu = priv->gpu; uint64_t val; uint32_t gpu_id; int ret = 0; mutex_lock(&dev->struct_mutex); if (rd->open || !gpu) { ret = -EBUSY; goto out; } file->private_data = rd; rd->open = true; /* the parsing tools need to know gpu-id to know which * register database to load. */ gpu->funcs->get_param(gpu, MSM_PARAM_GPU_ID, &val); gpu_id = val; rd_write_section(rd, RD_GPU_ID, &gpu_id, sizeof(gpu_id)); out: mutex_unlock(&dev->struct_mutex); return ret; } static int rd_release(struct inode *inode, struct file *file) { struct msm_rd_state *rd = inode->i_private; rd->open = false; return 0; } static const struct file_operations rd_debugfs_fops = { .owner = THIS_MODULE, .open = rd_open, .read = rd_read, .llseek = no_llseek, .release = rd_release, }; int msm_rd_debugfs_init(struct drm_minor *minor) { struct msm_drm_private *priv = minor->dev->dev_private; struct msm_rd_state *rd; /* only create on first minor: */ if (priv->rd) return 0; rd = kzalloc(sizeof(*rd), GFP_KERNEL); if (!rd) return -ENOMEM; rd->dev = minor->dev; rd->fifo.buf = rd->buf; mutex_init(&rd->read_lock); priv->rd = rd; init_waitqueue_head(&rd->fifo_event); rd->node = kzalloc(sizeof(*rd->node), GFP_KERNEL); if (!rd->node) goto fail; rd->ent = debugfs_create_file("rd", S_IFREG | S_IRUGO, minor->debugfs_root, rd, &rd_debugfs_fops); if (!rd->ent) { DRM_ERROR("Cannot create /sys/kernel/debug/dri/%pd/rd\n", minor->debugfs_root); goto fail; } rd->node->minor = minor; rd->node->dent = rd->ent; rd->node->info_ent = NULL; mutex_lock(&minor->debugfs_lock); list_add(&rd->node->list, &minor->debugfs_list); mutex_unlock(&minor->debugfs_lock); return 0; fail: msm_rd_debugfs_cleanup(minor); return -1; } void msm_rd_debugfs_cleanup(struct drm_minor *minor) { struct msm_drm_private *priv = minor->dev->dev_private; struct msm_rd_state *rd = priv->rd; if (!rd) return; priv->rd = NULL; debugfs_remove(rd->ent); if (rd->node) { mutex_lock(&minor->debugfs_lock); list_del(&rd->node->list); mutex_unlock(&minor->debugfs_lock); kfree(rd->node); } mutex_destroy(&rd->read_lock); kfree(rd); } static void snapshot_buf(struct msm_rd_state *rd, struct msm_gem_submit *submit, int idx, uint32_t iova, uint32_t size) { struct msm_gem_object *obj = submit->bos[idx].obj; const char *buf; buf = msm_gem_get_vaddr_locked(&obj->base); if (IS_ERR(buf)) return; if (iova) { buf += iova - submit->bos[idx].iova; } else { iova = submit->bos[idx].iova; size = obj->base.size; } rd_write_section(rd, RD_GPUADDR, (uint32_t[2]){ iova, size }, 8); rd_write_section(rd, RD_BUFFER_CONTENTS, buf, size); msm_gem_put_vaddr_locked(&obj->base); } /* called under struct_mutex */ void msm_rd_dump_submit(struct msm_gem_submit *submit) { struct drm_device *dev = submit->dev; struct msm_drm_private *priv = dev->dev_private; struct msm_rd_state *rd = priv->rd; char msg[128]; int i, n; if (!rd->open) return; /* writing into fifo is serialized by caller, and * rd->read_lock is used to serialize the reads */ WARN_ON(!mutex_is_locked(&dev->struct_mutex)); n = snprintf(msg, sizeof(msg), "%.*s/%d: fence=%u", TASK_COMM_LEN, current->comm, task_pid_nr(current), submit->fence->seqno); rd_write_section(rd, RD_CMD, msg, ALIGN(n, 4)); if (rd_full) { for (i = 0; i < submit->nr_bos; i++) { /* buffers that are written to probably don't start out * with anything interesting: */ if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE) continue; snapshot_buf(rd, submit, i, 0, 0); } } for (i = 0; i < submit->nr_cmds; i++) { uint32_t iova = submit->cmd[i].iova; uint32_t szd = submit->cmd[i].size; /* in dwords */ /* snapshot cmdstream bo's (if we haven't already): */ if (!rd_full) { snapshot_buf(rd, submit, submit->cmd[i].idx, submit->cmd[i].iova, szd * 4); } switch (submit->cmd[i].type) { case MSM_SUBMIT_CMD_IB_TARGET_BUF: /* ignore IB-targets, we've logged the buffer, the * parser tool will follow the IB based on the logged * buffer/gpuaddr, so nothing more to do. */ break; case MSM_SUBMIT_CMD_CTX_RESTORE_BUF: case MSM_SUBMIT_CMD_BUF: rd_write_section(rd, RD_CMDSTREAM_ADDR, (uint32_t[2]){ iova, szd }, 8); break; } } } #endif
the_stack_data/144906.c
int foo (void) { return 34; }
the_stack_data/181394271.c
int volume(int a[256][256]) { int v=0; int i,j; volume: for(i=0;i<256;i++) { v=v+1; for(j=0;j<256;j++) v=v+a[i][j]; } return v; } main() { int a [256][256]; int n = volume(a); printf("%d",n); return 0; }
the_stack_data/64200452.c
#include <stdio.h> #include <stdlib.h> #include <string.h> void factLU(double *A, int size) { int i, j, k; for (k = 0; k < size - 1; k++) { for (i = k + 1; i < size; i++) { A[i * size + k] = A[i * size + k] / A[k * size + k]; } for (i = k + 1; i < size; i++) { for (j = k + 1; j < size; j++) { A[i * size + j] = A[i * size + j] - A[i * size + k] * A[k * size + j]; } } } } double *genSingleMat(char *filePath, int bsize) { FILE *f; f = fopen(filePath, "r"); double *mat; mat = (double *)malloc(bsize * bsize * sizeof(double)); int i, j, nbRow, nbCol, indI, indJ; double tmp; for (i = 0; i < bsize; i++) { // row for (j = 0; j < bsize; j++) { // col fscanf(f, "%d %d %lf", &indI, &indJ, &tmp); mat[indI * bsize + indJ] = tmp; // printf("i-%d j-%d indi-%d indj-%d %lf \n",i,j,indI,indJ,tmp); } // printf("\n"); } fclose(f); return mat; } void printU(double *mat, int bsize) { printf("u\n"); int i, j; for (i = 0; i < bsize; i++) { // row for (j = 0; j < bsize; j++) { // col if (i <= j) printf("%lf\t", mat[i * bsize + j]); else printf("%lf\t", 0.0); } printf("\n"); } } void printL(double *mat, int bsize) { printf("l\n"); int i, j; for (i = 0; i < bsize; i++) { // row for (j = 0; j < bsize; j++) { // col if (i > j) printf("%lf\t", mat[i * bsize + j]); else if (i == j) printf("%lf\t", 1.0); else printf("%lf\t", 0.0); } printf("\n"); } } void printMatrix(double *mat, int bsize) { int i, j; for (i = 0; i < bsize; i++) { // row for (j = 0; j < bsize; j++) { // col printf("%lf\t", mat[i * bsize + j]); } printf("\n"); } } int main(int argc, char **argv) { if (argc != 3) { printf("Wrong number of argument\n"); exit(1); } int n = atoi(argv[2]); double *m; m = genSingleMat(argv[1], n); factLU(m, n); printMatrix(m, n); // printU(m, n); // printL(m, n); free(m); }
the_stack_data/1045224.c
extern char * malloc(int); char * h() { char * a = malloc(20); return a; } char * g() { char * a = malloc(10); return a; } char * f(int flag) { if (flag == 1) return h(); else return g(); } int main (){ char a[20]; int flag = a[0]; char * pa, * pb; pa = 0; pb = 0; if (flag == 1) { pa = f(flag); } else { pb = f(flag); } * pa = 0; * pb = 1; }
the_stack_data/132953531.c
// RUN: touch %t.o // RUN: %clang -target x86_64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=0 -### %t.o 2>&1 \ // RUN: | FileCheck %s // RUN: env SDKROOT=%S/Inputs/MacOSX10.14.sdk %clang -target x86_64-apple-macos10.13.0.1 -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck %s // CHECK: "-platform_version" "macos" "10.13.0" "10.14" // RUN: %clang -target arm64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW %s // RUN: %clang -target arm64-apple-darwin19 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW %s // RUN: %clang -target arm64-apple-macos11.1 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW_1 %s // RUN: %clang -target arm64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_OLD %s // RUN: %clang -target arm64e-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW %s // LINKER-OLD: "-macosx_version_min" "10.13.0" // LINKER-NEW: "-platform_version" "macos" "10.13.0" "10.14" // ARM64_NEW: "-platform_version" "macos" "11.0.0" "10.14" // ARM64_NEW_1: "-platform_version" "macos" "11.1.0" "10.14" // ARM64_OLD: "-macosx_version_min" "11.0.0"
the_stack_data/40761771.c
#include <errno.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "error.h" void __die(const char *file, unsigned int line, const char *func, const char *fmt, ...) { va_list ap; int saved_errno = errno; va_start(ap, fmt); fprintf(stderr, "%s:%d:%s: ", file, line, func); vfprintf(stderr, fmt, ap); if (saved_errno) fprintf(stderr, ": %d %s", errno, strerror(errno)); fprintf(stderr, "\n"); va_end(ap); abort(); }
the_stack_data/200144157.c
#include "stdio.h" int main(int argc, char const *argv[]) { /* code */ printf("Trigger EOF on Unix is ctrl+d"); printf("Trigger EOF on Windows is ctrl+z"); printf("the the value of getchar() is %d", getchar() != EOF); return 0; }
the_stack_data/87637054.c
// Programa que mostra como fazer entrada de dados via teclado // // Moacir A Ponti 2019 #include <stdio.h> int main(void) { int num1 = 0; double num2 = 0.0; // funcao da stdio que permite obter valores de entrada // scanf ("formatacao", endereco) scanf("%d", &num1); printf("Valor digitado (num1) = %d\n", num1); // permitir que o usuario digite o valor de num2 scanf("%lf", &num2); printf("Valor digitado (num2) = %lf\n", num2); return 0; }
the_stack_data/133208.c
#include <stdio.h> int main(){ int i; scanf("%d",&i); printf("%d %d %d\n",++i,i,i++); printf("%d ",++i); printf("%d ",i); printf("%d ",i++); return 0; }
the_stack_data/392694.c
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * ************************************************************************* */ #ifdef DOT11_N_SUPPORT #include "rt_config.h" #define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) //1 // inital sequence number of BA session #define ORI_SESSION_MAX_RETRY 8 #define ORI_BA_SESSION_TIMEOUT (2000) // ms #define REC_BA_SESSION_IDLE_TIMEOUT (1000) // ms #define REORDERING_PACKET_TIMEOUT ((100 * OS_HZ)/1000) // system ticks -- 100 ms #define MAX_REORDERING_PACKET_TIMEOUT ((3000 * OS_HZ)/1000) // system ticks -- 100 ms #define RESET_RCV_SEQ (0xFFFF) static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk); BA_ORI_ENTRY *BATableAllocOriEntry( IN PRTMP_ADAPTER pAd, OUT USHORT *Idx); BA_REC_ENTRY *BATableAllocRecEntry( IN PRTMP_ADAPTER pAd, OUT USHORT *Idx); VOID BAOriSessionSetupTimeout( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3); VOID BARecSessionIdleTimeout( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3); BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout); BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout); #define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \ Announce_Reordering_Packet(_pAd, _mpdu_blk); VOID BA_MaxWinSizeReasign( IN PRTMP_ADAPTER pAd, IN MAC_TABLE_ENTRY *pEntryPeer, OUT UCHAR *pWinSize) { UCHAR MaxSize; UCHAR MaxPeerRxSize; MaxPeerRxSize = (((1 << (pEntryPeer->MaxRAmpduFactor + 3)) * 10) / 16) -1; if (pAd->MACVersion >= RALINK_2883_VERSION) { if (pAd->MACVersion >= RALINK_3070_VERSION) { if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled) MaxSize = 7; // for non-open mode else MaxSize = 13; } else MaxSize = 31; } else if (pAd->MACVersion >= RALINK_2880E_VERSION) // 2880 e { if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled) MaxSize = 7; // for non-open mode else MaxSize = 13; } else MaxSize = 7; DBGPRINT(RT_DEBUG_TRACE, ("ba>WinSize=%d, MaxSize=%d, MaxPeerRxSize=%d\n", *pWinSize, MaxSize, MaxPeerRxSize)); MaxSize = min(MaxPeerRxSize, MaxSize); if ((*pWinSize) > MaxSize) { DBGPRINT(RT_DEBUG_TRACE, ("ba> reassign max win size from %d to %d\n", *pWinSize, MaxSize)); *pWinSize = MaxSize; } } void Announce_Reordering_Packet(IN PRTMP_ADAPTER pAd, IN struct reordering_mpdu *mpdu) { PNDIS_PACKET pPacket; pPacket = mpdu->pPacket; if (mpdu->bAMSDU) { //ASSERT(0); BA_Reorder_AMSDU_Annnounce(pAd, pPacket); } else { // // pass this 802.3 packet to upper layer or forward this packet to WM directly // #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket, RTMP_GET_PACKET_IF(pPacket)); #endif // CONFIG_STA_SUPPORT // } } /* * Insert a reordering mpdu into sorted linked list by sequence no. */ BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list, struct reordering_mpdu *mpdu) { struct reordering_mpdu **ppScan = &list->next; while (*ppScan != NULL) { if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ)) { ppScan = &(*ppScan)->next; } else if ((*ppScan)->Sequence == mpdu->Sequence) { /* give up this duplicated frame */ return(FALSE); } else { /* find position */ break; } } mpdu->next = *ppScan; *ppScan = mpdu; list->qlen++; return TRUE; } /* * caller lock critical section if necessary */ static inline void ba_enqueue(struct reordering_list *list, struct reordering_mpdu *mpdu_blk) { list->qlen++; mpdu_blk->next = list->next; list->next = mpdu_blk; } /* * caller lock critical section if necessary */ static inline struct reordering_mpdu * ba_dequeue(struct reordering_list *list) { struct reordering_mpdu *mpdu_blk = NULL; ASSERT(list); if (list->qlen) { list->qlen--; mpdu_blk = list->next; if (mpdu_blk) { list->next = mpdu_blk->next; mpdu_blk->next = NULL; } } return mpdu_blk; } static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct reordering_list *list) { return(ba_dequeue(list)); } static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct reordering_list *list) { ASSERT(list); return(list->next); } /* * free all resource for reordering mechanism */ void ba_reordering_resource_release(PRTMP_ADAPTER pAd) { BA_TABLE *Tab; PBA_REC_ENTRY pBAEntry; struct reordering_mpdu *mpdu_blk; int i; Tab = &pAd->BATable; /* I. release all pending reordering packet */ NdisAcquireSpinLock(&pAd->BATabLock); for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) { pBAEntry = &Tab->BARecEntry[i]; if (pBAEntry->REC_BA_Status != Recipient_NONE) { while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) { ASSERT(mpdu_blk->pPacket); RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket, NDIS_STATUS_FAILURE); ba_mpdu_blk_free(pAd, mpdu_blk); } } } NdisReleaseSpinLock(&pAd->BATabLock); ASSERT(pBAEntry->list.qlen == 0); /* II. free memory of reordering mpdu table */ NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); os_free_mem(pAd, pAd->mpdu_blk_pool.mem); NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); } /* * Allocate all resource for reordering mechanism */ BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num) { int i; PUCHAR mem; struct reordering_mpdu *mpdu_blk; struct reordering_list *freelist; /* allocate spinlock */ NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock); /* initialize freelist */ freelist = &pAd->mpdu_blk_pool.freelist; freelist->next = NULL; freelist->qlen = 0; DBGPRINT(RT_DEBUG_TRACE, ("Allocate %d memory for BA reordering\n", (UINT32)(num*sizeof(struct reordering_mpdu)))); /* allocate number of mpdu_blk memory */ os_alloc_mem(pAd, (PUCHAR *)&mem, (num*sizeof(struct reordering_mpdu))); pAd->mpdu_blk_pool.mem = mem; if (mem == NULL) { DBGPRINT(RT_DEBUG_ERROR, ("Can't Allocate Memory for BA Reordering\n")); return(FALSE); } /* build mpdu_blk free list */ for (i=0; i<num; i++) { /* get mpdu_blk */ mpdu_blk = (struct reordering_mpdu *) mem; /* initial mpdu_blk */ NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); /* next mpdu_blk */ mem += sizeof(struct reordering_mpdu); /* insert mpdu_blk into freelist */ ba_enqueue(freelist, mpdu_blk); } return(TRUE); } //static int blk_count=0; // sample take off, no use static struct reordering_mpdu *ba_mpdu_blk_alloc(PRTMP_ADAPTER pAd) { struct reordering_mpdu *mpdu_blk; NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist); if (mpdu_blk) { // blk_count++; /* reset mpdu_blk */ NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); } NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); return mpdu_blk; } static void ba_mpdu_blk_free(PRTMP_ADAPTER pAd, struct reordering_mpdu *mpdu_blk) { ASSERT(mpdu_blk); NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); // blk_count--; ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk); NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); } static USHORT ba_indicate_reordering_mpdus_in_order( IN PRTMP_ADAPTER pAd, IN PBA_REC_ENTRY pBAEntry, IN USHORT StartSeq) { struct reordering_mpdu *mpdu_blk; USHORT LastIndSeq = RESET_RCV_SEQ; NdisAcquireSpinLock(&pBAEntry->RxReRingLock); while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) { /* find in-order frame */ if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ)) { break; } /* dequeue in-order frame from reodering list */ mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); /* pass this frame up */ ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); /* move to next sequence */ StartSeq = mpdu_blk->Sequence; LastIndSeq = StartSeq; /* free mpdu_blk */ ba_mpdu_blk_free(pAd, mpdu_blk); } NdisReleaseSpinLock(&pBAEntry->RxReRingLock); /* update last indicated sequence */ return LastIndSeq; } static void ba_indicate_reordering_mpdus_le_seq( IN PRTMP_ADAPTER pAd, IN PBA_REC_ENTRY pBAEntry, IN USHORT Sequence) { struct reordering_mpdu *mpdu_blk; NdisAcquireSpinLock(&pBAEntry->RxReRingLock); while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) { /* find in-order frame */ if ((mpdu_blk->Sequence == Sequence) || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ)) { /* dequeue in-order frame from reodering list */ mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); /* pass this frame up */ ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); /* free mpdu_blk */ ba_mpdu_blk_free(pAd, mpdu_blk); } else { break; } } NdisReleaseSpinLock(&pBAEntry->RxReRingLock); } static void ba_refresh_reordering_mpdus( IN PRTMP_ADAPTER pAd, PBA_REC_ENTRY pBAEntry) { struct reordering_mpdu *mpdu_blk; NdisAcquireSpinLock(&pBAEntry->RxReRingLock); /* dequeue in-order frame from reodering list */ while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) { /* pass this frame up */ ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); pBAEntry->LastIndSeq = mpdu_blk->Sequence; ba_mpdu_blk_free(pAd, mpdu_blk); /* update last indicated sequence */ } ASSERT(pBAEntry->list.qlen == 0); pBAEntry->LastIndSeq = RESET_RCV_SEQ; NdisReleaseSpinLock(&pBAEntry->RxReRingLock); } //static void ba_flush_reordering_timeout_mpdus( IN PRTMP_ADAPTER pAd, IN PBA_REC_ENTRY pBAEntry, IN ULONG Now32) { USHORT Sequence; // if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) && // (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //|| // (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) && // (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8))) if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(MAX_REORDERING_PACKET_TIMEOUT/6))) &&(pBAEntry->list.qlen > 1) ) { DBGPRINT(RT_DEBUG_TRACE,("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer), (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), MAX_REORDERING_PACKET_TIMEOUT, pBAEntry->LastIndSeq)); ba_refresh_reordering_mpdus(pAd, pBAEntry); pBAEntry->LastIndSeqAtTimer = Now32; } else if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(REORDERING_PACKET_TIMEOUT))) && (pBAEntry->list.qlen > 0) ) { // DBGPRINT(RT_DEBUG_OFF, ("timeout[%d] (%lx-%lx = %d > %d): %x, ", pBAEntry->list.qlen, Now32, (pBAEntry->LastIndSeqAtTimer), // (int)((long) Now32 - (long)(pBAEntry->LastIndSeqAtTimer)), REORDERING_PACKET_TIMEOUT, // pBAEntry->LastIndSeq)); // // force LastIndSeq to shift to LastIndSeq+1 // Sequence = (pBAEntry->LastIndSeq+1) & MAXSEQ; ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); pBAEntry->LastIndSeqAtTimer = Now32; pBAEntry->LastIndSeq = Sequence; // // indicate in-order mpdus // Sequence = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, Sequence); if (Sequence != RESET_RCV_SEQ) { pBAEntry->LastIndSeq = Sequence; } DBGPRINT(RT_DEBUG_OFF, ("%x, flush one!\n", pBAEntry->LastIndSeq)); } } /* * generate ADDBA request to * set up BA agreement */ VOID BAOriSessionSetUp( IN PRTMP_ADAPTER pAd, IN MAC_TABLE_ENTRY *pEntry, IN UCHAR TID, IN USHORT TimeOut, IN ULONG DelayTime, IN BOOLEAN isForced) { //MLME_ADDBA_REQ_STRUCT AddbaReq; BA_ORI_ENTRY *pBAEntry = NULL; USHORT Idx; BOOLEAN Cancelled; ASSERT(TID < NUM_OF_TID); if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE) && (isForced == FALSE)) return; // if this entry is limited to use legacy tx mode, it doesn't generate BA. if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT) return; if ((pEntry->BADeclineBitmap & (1<<TID)) && (isForced == FALSE)) { // try again after 3 secs DelayTime = 3000; // DBGPRINT(RT_DEBUG_TRACE, ("DeCline BA from Peer\n")); // return; } Idx = pEntry->BAOriWcidArray[TID]; if (Idx == 0) { // allocate a BA session pBAEntry = BATableAllocOriEntry(pAd, &Idx); if (pBAEntry == NULL) { DBGPRINT(RT_DEBUG_TRACE,("ADDBA - MlmeADDBAAction() allocate BA session failed \n")); return; } } else { pBAEntry =&pAd->BATable.BAOriEntry[Idx]; } if (pBAEntry->ORI_BA_Status >= Originator_WaitRes) { return; } pEntry->BAOriWcidArray[TID] = Idx; // Initialize BA session pBAEntry->ORI_BA_Status = Originator_WaitRes; pBAEntry->Wcid = pEntry->Aid; pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit; pBAEntry->Sequence = BA_ORI_INIT_SEQ; pBAEntry->Token = 1; // (2008-01-21) Jan Lee recommends it - this token can't be 0 pBAEntry->TID = TID; pBAEntry->TimeOutValue = TimeOut; pBAEntry->pAdapter = pAd; if (!(pEntry->TXBAbitmap & (1<<TID))) { RTMPInitTimer(pAd, &pBAEntry->ORIBATimer, GET_TIMER_FUNCTION(BAOriSessionSetupTimeout), pBAEntry, FALSE); } else RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); // set timer to send ADDBA request RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime); } VOID BAOriSessionAdd( IN PRTMP_ADAPTER pAd, IN MAC_TABLE_ENTRY *pEntry, IN PFRAME_ADDBA_RSP pFrame) { BA_ORI_ENTRY *pBAEntry = NULL; BOOLEAN Cancelled; UCHAR TID; USHORT Idx; PUCHAR pOutBuffer2 = NULL; NDIS_STATUS NStatus; ULONG FrameLen; FRAME_BAR FrameBar; TID = pFrame->BaParm.TID; Idx = pEntry->BAOriWcidArray[TID]; pBAEntry =&pAd->BATable.BAOriEntry[Idx]; // Start fill in parameters. if ((Idx !=0) && (pBAEntry->TID == TID) && (pBAEntry->ORI_BA_Status == Originator_WaitRes)) { pBAEntry->BAWinSize = min(pBAEntry->BAWinSize, ((UCHAR)pFrame->BaParm.BufSize)); BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize); pBAEntry->TimeOutValue = pFrame->TimeOutValue; pBAEntry->ORI_BA_Status = Originator_Done; pAd->BATable.numDoneOriginator ++; // reset sequence number pBAEntry->Sequence = BA_ORI_INIT_SEQ; // Set Bitmap flag. pEntry->TXBAbitmap |= (1<<TID); RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); pBAEntry->ORIBATimer.TimerValue = 0; //pFrame->TimeOutValue; DBGPRINT(RT_DEBUG_TRACE,("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n", __FUNCTION__, pEntry->TXBAbitmap, pBAEntry->BAWinSize, pBAEntry->ORIBATimer.TimerValue)); // SEND BAR ; NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE,("BA - BAOriSessionAdd() allocate memory failed \n")); return; } #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) BarHeaderInit(pAd, &FrameBar, pAd->MacTab.Content[pBAEntry->Wcid].Addr, pAd->CurrentAddress); #endif // CONFIG_STA_SUPPORT // FrameBar.StartingSeq.field.FragNum = 0; // make sure sequence not clear in DEL function. FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; // make sure sequence not clear in DEL funciton. FrameBar.BarControl.TID = pBAEntry->TID; // make sure sequence not clear in DEL funciton. MakeOutgoingFrame(pOutBuffer2, &FrameLen, sizeof(FRAME_BAR), &FrameBar, END_OF_ARGS); MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen); MlmeFreeMemory(pAd, pOutBuffer2); if (pBAEntry->ORIBATimer.TimerValue) RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); // in mSec } } BOOLEAN BARecSessionAdd( IN PRTMP_ADAPTER pAd, IN MAC_TABLE_ENTRY *pEntry, IN PFRAME_ADDBA_REQ pFrame) { BA_REC_ENTRY *pBAEntry = NULL; BOOLEAN Status = TRUE; BOOLEAN Cancelled; USHORT Idx; UCHAR TID; UCHAR BAWinSize; //UINT32 Value; //UINT offset; ASSERT(pEntry); // find TID TID = pFrame->BaParm.TID; BAWinSize = min(((UCHAR)pFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit); // Intel patch if (BAWinSize == 0) { BAWinSize = 64; } // get software BA rec array index, Idx Idx = pEntry->BARecWcidArray[TID]; if (Idx == 0) { // allocate new array entry for the new session pBAEntry = BATableAllocRecEntry(pAd, &Idx); } else { pBAEntry = &pAd->BATable.BARecEntry[Idx]; // flush all pending reordering mpdus ba_refresh_reordering_mpdus(pAd, pBAEntry); } DBGPRINT(RT_DEBUG_TRACE,("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __FUNCTION__, pAd->BATable.numAsRecipient, Idx, pFrame->BaParm.BufSize, BAWinSize)); // Start fill in parameters. if (pBAEntry != NULL) { ASSERT(pBAEntry->list.qlen == 0); pBAEntry->REC_BA_Status = Recipient_HandleRes; pBAEntry->BAWinSize = BAWinSize; pBAEntry->Wcid = pEntry->Aid; pBAEntry->TID = TID; pBAEntry->TimeOutValue = pFrame->TimeOutValue; pBAEntry->REC_BA_Status = Recipient_Accept; // initial sequence number pBAEntry->LastIndSeq = RESET_RCV_SEQ; //pFrame->BaStartSeq.field.StartSeq; DBGPRINT(RT_DEBUG_OFF, ("Start Seq = %08x\n", pFrame->BaStartSeq.field.StartSeq)); if (pEntry->RXBAbitmap & (1<<TID)) { RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); } else { RTMPInitTimer(pAd, &pBAEntry->RECBATimer, GET_TIMER_FUNCTION(BARecSessionIdleTimeout), pBAEntry, TRUE); } // Set Bitmap flag. pEntry->RXBAbitmap |= (1<<TID); pEntry->BARecWcidArray[TID] = Idx; pEntry->BADeclineBitmap &= ~(1<<TID); // Set BA session mask in WCID table. RTMP_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID); DBGPRINT(RT_DEBUG_TRACE,("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n", pEntry->Aid, pEntry->RXBAbitmap, pEntry->BARecWcidArray[TID])); } else { Status = FALSE; DBGPRINT(RT_DEBUG_TRACE,("Can't Accept ADDBA for %02x:%02x:%02x:%02x:%02x:%02x TID = %d\n", PRINT_MAC(pEntry->Addr), TID)); } return(Status); } BA_REC_ENTRY *BATableAllocRecEntry( IN PRTMP_ADAPTER pAd, OUT USHORT *Idx) { int i; BA_REC_ENTRY *pBAEntry = NULL; NdisAcquireSpinLock(&pAd->BATabLock); if (pAd->BATable.numAsRecipient >= (MAX_LEN_OF_BA_REC_TABLE - 1)) { DBGPRINT(RT_DEBUG_OFF, ("BA Recipeint Session (%ld) > %d\n", pAd->BATable.numAsRecipient, (MAX_LEN_OF_BA_REC_TABLE - 1))); goto done; } // reserve idx 0 to identify BAWcidArray[TID] as empty for (i=1; i < MAX_LEN_OF_BA_REC_TABLE; i++) { pBAEntry =&pAd->BATable.BARecEntry[i]; if ((pBAEntry->REC_BA_Status == Recipient_NONE)) { // get one pAd->BATable.numAsRecipient++; pBAEntry->REC_BA_Status = Recipient_USED; *Idx = i; break; } } done: NdisReleaseSpinLock(&pAd->BATabLock); return pBAEntry; } BA_ORI_ENTRY *BATableAllocOriEntry( IN PRTMP_ADAPTER pAd, OUT USHORT *Idx) { int i; BA_ORI_ENTRY *pBAEntry = NULL; NdisAcquireSpinLock(&pAd->BATabLock); if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE - 1)) { goto done; } // reserve idx 0 to identify BAWcidArray[TID] as empty for (i=1; i<MAX_LEN_OF_BA_ORI_TABLE; i++) { pBAEntry =&pAd->BATable.BAOriEntry[i]; if ((pBAEntry->ORI_BA_Status == Originator_NONE)) { // get one pAd->BATable.numAsOriginator++; pBAEntry->ORI_BA_Status = Originator_USED; pBAEntry->pAdapter = pAd; *Idx = i; break; } } done: NdisReleaseSpinLock(&pAd->BATabLock); return pBAEntry; } VOID BATableFreeOriEntry( IN PRTMP_ADAPTER pAd, IN ULONG Idx) { BA_ORI_ENTRY *pBAEntry = NULL; MAC_TABLE_ENTRY *pEntry; if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) return; pBAEntry =&pAd->BATable.BAOriEntry[Idx]; if (pBAEntry->ORI_BA_Status != Originator_NONE) { pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; pEntry->BAOriWcidArray[pBAEntry->TID] = 0; NdisAcquireSpinLock(&pAd->BATabLock); if (pBAEntry->ORI_BA_Status == Originator_Done) { pAd->BATable.numDoneOriginator -= 1; pEntry->TXBAbitmap &= (~(1<<(pBAEntry->TID) )); DBGPRINT(RT_DEBUG_TRACE, ("BATableFreeOriEntry numAsOriginator= %ld\n", pAd->BATable.numAsRecipient)); // Erase Bitmap flag. } ASSERT(pAd->BATable.numAsOriginator != 0); pAd->BATable.numAsOriginator -= 1; pBAEntry->ORI_BA_Status = Originator_NONE; pBAEntry->Token = 0; NdisReleaseSpinLock(&pAd->BATabLock); } } VOID BATableFreeRecEntry( IN PRTMP_ADAPTER pAd, IN ULONG Idx) { BA_REC_ENTRY *pBAEntry = NULL; MAC_TABLE_ENTRY *pEntry; if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE)) return; pBAEntry =&pAd->BATable.BARecEntry[Idx]; if (pBAEntry->REC_BA_Status != Recipient_NONE) { pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; pEntry->BARecWcidArray[pBAEntry->TID] = 0; NdisAcquireSpinLock(&pAd->BATabLock); ASSERT(pAd->BATable.numAsRecipient != 0); pAd->BATable.numAsRecipient -= 1; pBAEntry->REC_BA_Status = Recipient_NONE; NdisReleaseSpinLock(&pAd->BATabLock); } } VOID BAOriSessionTearDown( IN OUT PRTMP_ADAPTER pAd, IN UCHAR Wcid, IN UCHAR TID, IN BOOLEAN bPassive, IN BOOLEAN bForceSend) { ULONG Idx = 0; BA_ORI_ENTRY *pBAEntry; BOOLEAN Cancelled; if (Wcid >= MAX_LEN_OF_MAC_TABLE) { return; } // // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). // Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID]; if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) { if (bForceSend == TRUE) { // force send specified TID DelBA MLME_DELBA_REQ_STRUCT DelbaReq; MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); if (Elem != NULL) { NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); DelbaReq.Wcid = Wcid; DelbaReq.TID = TID; DelbaReq.Initiator = ORIGINATOR; Elem->MsgLen = sizeof(DelbaReq); NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); MlmeDELBAAction(pAd, Elem); kfree(Elem); } else { DBGPRINT(RT_DEBUG_ERROR, ("%s(bForceSend):alloc memory failed!\n", __FUNCTION__)); } } return; } DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID)); pBAEntry = &pAd->BATable.BAOriEntry[Idx]; DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->ORI_BA_Status)); // // Prepare DelBA action frame and send to the peer. // if ((bPassive == FALSE) && (TID == pBAEntry->TID) && (pBAEntry->ORI_BA_Status == Originator_Done)) { MLME_DELBA_REQ_STRUCT DelbaReq; MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); if (Elem != NULL) { NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); DelbaReq.Wcid = Wcid; DelbaReq.TID = pBAEntry->TID; DelbaReq.Initiator = ORIGINATOR; Elem->MsgLen = sizeof(DelbaReq); NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); MlmeDELBAAction(pAd, Elem); kfree(Elem); } else { DBGPRINT(RT_DEBUG_ERROR, ("%s():alloc memory failed!\n", __FUNCTION__)); return; } } RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); BATableFreeOriEntry(pAd, Idx); if (bPassive) { //BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE); } } VOID BARecSessionTearDown( IN OUT PRTMP_ADAPTER pAd, IN UCHAR Wcid, IN UCHAR TID, IN BOOLEAN bPassive) { ULONG Idx = 0; BA_REC_ENTRY *pBAEntry; if (Wcid >= MAX_LEN_OF_MAC_TABLE) { return; } // // Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). // Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; if (Idx == 0) return; DBGPRINT(RT_DEBUG_TRACE,("%s===>Wcid=%d.TID=%d \n", __FUNCTION__, Wcid, TID)); pBAEntry = &pAd->BATable.BARecEntry[Idx]; DBGPRINT(RT_DEBUG_TRACE,("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx, Wcid, TID, pBAEntry->REC_BA_Status)); // // Prepare DelBA action frame and send to the peer. // if ((TID == pBAEntry->TID) && (pBAEntry->REC_BA_Status == Recipient_Accept)) { MLME_DELBA_REQ_STRUCT DelbaReq; BOOLEAN Cancelled; //ULONG offset; //UINT32 VALUE; RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); // // 1. Send DELBA Action Frame // if (bPassive == FALSE) { MLME_QUEUE_ELEM *Elem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG); if (Elem != NULL) { NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); NdisZeroMemory(Elem, sizeof(MLME_QUEUE_ELEM)); COPY_MAC_ADDR(DelbaReq.Addr, pAd->MacTab.Content[Wcid].Addr); DelbaReq.Wcid = Wcid; DelbaReq.TID = TID; DelbaReq.Initiator = RECIPIENT; Elem->MsgLen = sizeof(DelbaReq); NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); MlmeDELBAAction(pAd, Elem); kfree(Elem); } else { DBGPRINT(RT_DEBUG_ERROR, ("%s():alloc memory failed!\n", __FUNCTION__)); return; } } // // 2. Free resource of BA session // // flush all pending reordering mpdus ba_refresh_reordering_mpdus(pAd, pBAEntry); NdisAcquireSpinLock(&pAd->BATabLock); // Erase Bitmap flag. pBAEntry->LastIndSeq = RESET_RCV_SEQ; pBAEntry->BAWinSize = 0; // Erase Bitmap flag at software mactable pAd->MacTab.Content[Wcid].RXBAbitmap &= (~(1<<(pBAEntry->TID))); pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0; RTMP_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID); NdisReleaseSpinLock(&pAd->BATabLock); } BATableFreeRecEntry(pAd, Idx); } VOID BASessionTearDownALL( IN OUT PRTMP_ADAPTER pAd, IN UCHAR Wcid) { int i; for (i=0; i<NUM_OF_TID; i++) { BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE); BARecSessionTearDown(pAd, Wcid, i, FALSE); } } /* ========================================================================== Description: Retry sending ADDBA Reqest. IRQL = DISPATCH_LEVEL Parametrs: p8023Header: if this is already 802.3 format, p8023Header is NULL Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. FALSE , then continue indicaterx at this moment. ========================================================================== */ VOID BAOriSessionSetupTimeout( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3) { BA_ORI_ENTRY *pBAEntry = (BA_ORI_ENTRY *)FunctionContext; MAC_TABLE_ENTRY *pEntry; PRTMP_ADAPTER pAd; if (pBAEntry == NULL) return; pAd = pBAEntry->pAdapter; #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // Do nothing if monitor mode is on if (MONITOR_ON(pAd)) return; } #endif // CONFIG_STA_SUPPORT // #ifdef RALINK_ATE // Nothing to do in ATE mode. if (ATE_ON(pAd)) return; #endif // RALINK_ATE // pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; if ((pBAEntry->ORI_BA_Status == Originator_WaitRes) && (pBAEntry->Token < ORI_SESSION_MAX_RETRY)) { MLME_ADDBA_REQ_STRUCT AddbaReq; #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { if (INFRA_ON(pAd) && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))) { /* In scan progress and have no chance to send out, just re-schedule to another time period */ RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT); return; } } #endif // CONFIG_STA_SUPPORT // NdisZeroMemory(&AddbaReq, sizeof(AddbaReq)); COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr); AddbaReq.Wcid = (UCHAR)(pEntry->Aid); AddbaReq.TID = pBAEntry->TID; AddbaReq.BaBufSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit; AddbaReq.TimeOutValue = 0; AddbaReq.Token = pBAEntry->Token; MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE, sizeof(MLME_ADDBA_REQ_STRUCT), (PVOID)&AddbaReq, 0); RTMP_MLME_HANDLER(pAd); DBGPRINT(RT_DEBUG_TRACE,("BA Ori Session Timeout(%d) : Send ADD BA again\n", pBAEntry->Token)); pBAEntry->Token++; RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT); } else { BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]); } } /* ========================================================================== Description: Retry sending ADDBA Reqest. IRQL = DISPATCH_LEVEL Parametrs: p8023Header: if this is already 802.3 format, p8023Header is NULL Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. FALSE , then continue indicaterx at this moment. ========================================================================== */ VOID BARecSessionIdleTimeout( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3) { BA_REC_ENTRY *pBAEntry = (BA_REC_ENTRY *)FunctionContext; PRTMP_ADAPTER pAd; ULONG Now32; if (pBAEntry == NULL) return; if ((pBAEntry->REC_BA_Status == Recipient_Accept)) { NdisGetSystemUpTime(&Now32); if (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer + REC_BA_SESSION_IDLE_TIMEOUT))) { pAd = pBAEntry->pAdapter; // flush all pending reordering mpdus ba_refresh_reordering_mpdus(pAd, pBAEntry); DBGPRINT(RT_DEBUG_OFF, ("%ld: REC BA session Timeout\n", Now32)); } } } VOID PeerAddBAReqAction( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { // 7.4.4.1 //ULONG Idx; UCHAR Status = 1; UCHAR pAddr[6]; FRAME_ADDBA_RSP ADDframe; PUCHAR pOutBuffer = NULL; NDIS_STATUS NStatus; PFRAME_ADDBA_REQ pAddreqFrame = NULL; //UCHAR BufSize; ULONG FrameLen; PULONG ptemp; PMAC_TABLE_ENTRY pMacEntry; DBGPRINT(RT_DEBUG_TRACE, ("%s ==> (Wcid = %d)\n", __FUNCTION__, Elem->Wcid)); //hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen); //ADDBA Request from unknown peer, ignore this. if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) return; pMacEntry = &pAd->MacTab.Content[Elem->Wcid]; DBGPRINT(RT_DEBUG_TRACE,("BA - PeerAddBAReqAction----> \n")); ptemp = (PULONG)Elem->Msg; //DBGPRINT_RAW(RT_DEBUG_EMU, ("%08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x\n", *(ptemp), *(ptemp+1), *(ptemp+2), *(ptemp+3), *(ptemp+4), *(ptemp+5), *(ptemp+6), *(ptemp+7), *(ptemp+8))); if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr)) { if ((pAd->CommonCfg.bBADecline == FALSE) && IS_HT_STA(pMacEntry)) { pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]); DBGPRINT(RT_DEBUG_OFF, ("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid)); if (BARecSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pAddreqFrame)) Status = 0; else Status = 38; // more parameters have invalid values } else { Status = 37; // the request has been declined. } } if (IS_ENTRY_CLIENT(&pAd->MacTab.Content[Elem->Wcid])) ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC); pAddreqFrame = (PFRAME_ADDBA_REQ)(&Elem->Msg[0]); // 2. Always send back ADDBA Response NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE,("ACTION - PeerBAAction() allocate memory failed \n")); return; } NdisZeroMemory(&ADDframe, sizeof(FRAME_ADDBA_RSP)); // 2-1. Prepare ADDBA Response frame. #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { if (ADHOC_ON(pAd) #ifdef QOS_DLS_SUPPORT || (IS_ENTRY_DLS(&pAd->MacTab.Content[Elem->Wcid])) #endif // QOS_DLS_SUPPORT // ) ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, pAd->CurrentAddress, pAd->CommonCfg.Bssid); else ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAddr); } #endif // CONFIG_STA_SUPPORT // ADDframe.Category = CATEGORY_BA; ADDframe.Action = ADDBA_RESP; ADDframe.Token = pAddreqFrame->Token; // What is the Status code?? need to check. ADDframe.StatusCode = Status; ADDframe.BaParm.BAPolicy = IMMED_BA; ADDframe.BaParm.AMSDUSupported = 0; ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID; ADDframe.BaParm.BufSize = min(((UCHAR)pAddreqFrame->BaParm.BufSize), (UCHAR)pAd->CommonCfg.BACapability.field.RxBAWinLimit); if (ADDframe.BaParm.BufSize == 0) { ADDframe.BaParm.BufSize = 64; } ADDframe.TimeOutValue = 0; //pAddreqFrame->TimeOutValue; *(USHORT *)(&ADDframe.BaParm) = cpu2le16(*(USHORT *)(&ADDframe.BaParm)); ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode); ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue); MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(FRAME_ADDBA_RSP), &ADDframe, END_OF_ARGS); MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); MlmeFreeMemory(pAd, pOutBuffer); DBGPRINT(RT_DEBUG_TRACE, ("%s(%d): TID(%d), BufSize(%d) <== \n", __FUNCTION__, Elem->Wcid, ADDframe.BaParm.TID, ADDframe.BaParm.BufSize)); } VOID PeerAddBARspAction( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { //UCHAR Idx, i; //PUCHAR pOutBuffer = NULL; PFRAME_ADDBA_RSP pFrame = NULL; //PBA_ORI_ENTRY pBAEntry; //ADDBA Response from unknown peer, ignore this. if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) return; DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __FUNCTION__, Elem->Wcid)); //hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen); if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen)) { pFrame = (PFRAME_ADDBA_RSP)(&Elem->Msg[0]); DBGPRINT(RT_DEBUG_TRACE, ("\t\t StatusCode = %d\n", pFrame->StatusCode)); switch (pFrame->StatusCode) { case 0: // I want a BAsession with this peer as an originator. BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], pFrame); break; default: // check status == USED ??? BAOriSessionTearDown(pAd, Elem->Wcid, pFrame->BaParm.TID, TRUE, FALSE); break; } // Rcv Decline StatusCode if ((pFrame->StatusCode == 37) #ifdef CONFIG_STA_SUPPORT || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd) && (pFrame->StatusCode != 0)) #endif // CONFIG_STA_SUPPORT // ) { pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |= 1<<pFrame->BaParm.TID; } } } VOID PeerDelBAAction( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { //UCHAR Idx; //PUCHAR pOutBuffer = NULL; PFRAME_DELBA_REQ pDelFrame = NULL; DBGPRINT(RT_DEBUG_TRACE,("%s ==>\n", __FUNCTION__)); //DELBA Request from unknown peer, ignore this. if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen)) { pDelFrame = (PFRAME_DELBA_REQ)(&Elem->Msg[0]); if (pDelFrame->DelbaParm.Initiator == ORIGINATOR) { DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> ORIGINATOR\n")); BARecSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE); } else { DBGPRINT(RT_DEBUG_TRACE,("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n", pDelFrame->ReasonCode)); //hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen); BAOriSessionTearDown(pAd, Elem->Wcid, pDelFrame->DelbaParm.TID, TRUE, FALSE); } } } BOOLEAN CntlEnqueueForRecv( IN PRTMP_ADAPTER pAd, IN ULONG Wcid, IN ULONG MsgLen, IN PFRAME_BA_REQ pMsg) { PFRAME_BA_REQ pFrame = pMsg; //PRTMP_REORDERBUF pBuffer; //PRTMP_REORDERBUF pDmaBuf; PBA_REC_ENTRY pBAEntry; //BOOLEAN Result; ULONG Idx; //UCHAR NumRxPkt; UCHAR TID;//, i; TID = (UCHAR)pFrame->BARControl.TID; DBGPRINT(RT_DEBUG_TRACE, ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __FUNCTION__, Wcid, TID)); //hex_dump("BAR", (PCHAR) pFrame, MsgLen); // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) return FALSE; // First check the size, it MUST not exceed the mlme queue size if (MsgLen > MGMT_DMA_BUFFER_SIZE) { DBGPRINT_ERR(("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen)); return FALSE; } else if (MsgLen != sizeof(FRAME_BA_REQ)) { DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); return FALSE; } else if (MsgLen != sizeof(FRAME_BA_REQ)) { DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); return FALSE; } if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8)) { // if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search. Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; pBAEntry = &pAd->BATable.BARecEntry[Idx]; } else { return FALSE; } DBGPRINT(RT_DEBUG_TRACE, ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID, pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq )); if (SEQ_SMALLER(pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq, MAXSEQ)) { //DBGPRINT(RT_DEBUG_TRACE, ("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq)); ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, pFrame->BAStartingSeq.field.StartSeq); pBAEntry->LastIndSeq = (pFrame->BAStartingSeq.field.StartSeq == 0) ? MAXSEQ :(pFrame->BAStartingSeq.field.StartSeq -1); } //ba_refresh_reordering_mpdus(pAd, pBAEntry); return TRUE; } /* Description : Send PSMP Action frame If PSMP mode switches. */ VOID SendPSMPAction( IN PRTMP_ADAPTER pAd, IN UCHAR Wcid, IN UCHAR Psmp) { PUCHAR pOutBuffer = NULL; NDIS_STATUS NStatus; //ULONG Idx; FRAME_PSMP_ACTION Frame; ULONG FrameLen; NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_ERROR,("BA - MlmeADDBAAction() allocate memory failed \n")); return; } #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr); #endif // CONFIG_STA_SUPPORT // Frame.Category = CATEGORY_HT; Frame.Action = SMPS_ACTION; switch (Psmp) { case MMPS_ENABLE: Frame.Psmp = 0; break; case MMPS_DYNAMIC: Frame.Psmp = 3; break; case MMPS_STATIC: Frame.Psmp = 1; break; } MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(FRAME_PSMP_ACTION), &Frame, END_OF_ARGS); MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); MlmeFreeMemory(pAd, pOutBuffer); DBGPRINT(RT_DEBUG_ERROR,("HT - SendPSMPAction( %d ) \n", Frame.Psmp)); } #define RADIO_MEASUREMENT_REQUEST_ACTION 0 typedef struct GNU_PACKED { UCHAR RegulatoryClass; UCHAR ChannelNumber; USHORT RandomInterval; USHORT MeasurementDuration; UCHAR MeasurementMode; UCHAR BSSID[MAC_ADDR_LEN]; UCHAR ReportingCondition; UCHAR Threshold; UCHAR SSIDIE[2]; // 2 byte } BEACON_REQUEST; typedef struct GNU_PACKED { UCHAR ID; UCHAR Length; UCHAR Token; UCHAR RequestMode; UCHAR Type; } MEASUREMENT_REQ; void convert_reordering_packet_to_preAMSDU_or_802_3_packet( IN PRTMP_ADAPTER pAd, IN RX_BLK *pRxBlk, IN UCHAR FromWhichBSSID) { PNDIS_PACKET pRxPkt; UCHAR Header802_3[LENGTH_802_3]; // 1. get 802.3 Header // 2. remove LLC // a. pointer pRxBlk->pData to payload // b. modify pRxBlk->DataSize #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); #endif // CONFIG_STA_SUPPORT // ASSERT(pRxBlk->pRxPacket); pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); SET_OS_PKT_NETDEV(pRxPkt, get_netdev_from_bssid(pAd, FromWhichBSSID)); SET_OS_PKT_DATAPTR(pRxPkt, pRxBlk->pData); SET_OS_PKT_LEN(pRxPkt, pRxBlk->DataSize); SET_OS_PKT_DATATAIL(pRxPkt, pRxBlk->pData, pRxBlk->DataSize); // // copy 802.3 header, if necessary // if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) { #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { #ifdef LINUX NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3), Header802_3, LENGTH_802_3); #endif } #endif // CONFIG_STA_SUPPORT // } } #define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \ do \ { \ if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \ { \ Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ } \ else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \ { \ Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ } \ else \ { \ Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ } \ } while (0); static VOID ba_enqueue_reordering_packet( IN PRTMP_ADAPTER pAd, IN PBA_REC_ENTRY pBAEntry, IN RX_BLK *pRxBlk, IN UCHAR FromWhichBSSID) { struct reordering_mpdu *mpdu_blk; UINT16 Sequence = (UINT16) pRxBlk->pHeader->Sequence; mpdu_blk = ba_mpdu_blk_alloc(pAd); if ((mpdu_blk != NULL) && (!RX_BLK_TEST_FLAG(pRxBlk, fRX_EAP))) { // Write RxD buffer address & allocated buffer length NdisAcquireSpinLock(&pBAEntry->RxReRingLock); mpdu_blk->Sequence = Sequence; mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU); convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd, pRxBlk, FromWhichBSSID); STATS_INC_RX_PACKETS(pAd, FromWhichBSSID); // // it is necessary for reordering packet to record // which BSS it come from // RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID); mpdu_blk->pPacket = pRxBlk->pRxPacket; if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk) == FALSE) { // had been already within reordering list // don't indicate RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_SUCCESS); ba_mpdu_blk_free(pAd, mpdu_blk); } ASSERT((0<= pBAEntry->list.qlen) && (pBAEntry->list.qlen <= pBAEntry->BAWinSize)); NdisReleaseSpinLock(&pBAEntry->RxReRingLock); } else { DBGPRINT(RT_DEBUG_ERROR, ("!!! (%d) Can't allocate reordering mpdu blk\n", pBAEntry->list.qlen)); /* * flush all pending reordering mpdus * and receving mpdu to upper layer * make tcp/ip to take care reordering mechanism */ //ba_refresh_reordering_mpdus(pAd, pBAEntry); ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); pBAEntry->LastIndSeq = Sequence; INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); } } /* ========================================================================== Description: Indicate this packet to upper layer or put it into reordering buffer Parametrs: pRxBlk : carry necessary packet info 802.11 format FromWhichBSSID : the packet received from which BSS Return : none Note : the packet queued into reordering buffer need to cover to 802.3 format or pre_AMSDU format ========================================================================== */ VOID Indicate_AMPDU_Packet( IN PRTMP_ADAPTER pAd, IN RX_BLK *pRxBlk, IN UCHAR FromWhichBSSID) { USHORT Idx; PBA_REC_ENTRY pBAEntry = NULL; UINT16 Sequence = pRxBlk->pHeader->Sequence; ULONG Now32; UCHAR Wcid = pRxBlk->pRxWI->WirelessCliID; UCHAR TID = pRxBlk->pRxWI->TID; if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU) && (pRxBlk->DataSize > MAX_RX_PKT_LEN)) { static int err_size; err_size++; if (err_size > 20) { DBGPRINT(RT_DEBUG_TRACE, ("AMPDU DataSize = %d\n", pRxBlk->DataSize)); hex_dump("802.11 Header", (UCHAR *)pRxBlk->pHeader, 24); hex_dump("Payload", pRxBlk->pData, 64); err_size = 0; } // release packet RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); return; } if (Wcid < MAX_LEN_OF_MAC_TABLE) { Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; if (Idx == 0) { /* Rec BA Session had been torn down */ INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); return; } pBAEntry = &pAd->BATable.BARecEntry[Idx]; } else { // impossible !!! ASSERT(0); // release packet RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); return; } ASSERT(pBAEntry); // update last rx time NdisGetSystemUpTime(&Now32); pBAEntry->rcvSeq = Sequence; ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32); pBAEntry->LastIndSeqAtTimer = Now32; // // Reset Last Indicate Sequence // if (pBAEntry->LastIndSeq == RESET_RCV_SEQ) { ASSERT((pBAEntry->list.qlen == 0) && (pBAEntry->list.next == NULL)); // reset rcv sequence of BA session pBAEntry->LastIndSeq = Sequence; pBAEntry->LastIndSeqAtTimer = Now32; INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); return; } // // I. Check if in order. // if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) { USHORT LastIndSeq; pBAEntry->LastIndSeq = Sequence; INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); LastIndSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq); if (LastIndSeq != RESET_RCV_SEQ) { pBAEntry->LastIndSeq = LastIndSeq; } pBAEntry->LastIndSeqAtTimer = Now32; } // // II. Drop Duplicated Packet // else if (Sequence == pBAEntry->LastIndSeq) { // drop and release packet pBAEntry->nDropPacket++; RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); } // // III. Drop Old Received Packet // else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) { // drop and release packet pBAEntry->nDropPacket++; RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); } // // IV. Receive Sequence within Window Size // else if (SEQ_SMALLER(Sequence, (((pBAEntry->LastIndSeq+pBAEntry->BAWinSize+1)) & MAXSEQ), MAXSEQ)) { ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID); } // // V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer // else { LONG WinStartSeq, TmpSeq; TmpSeq = Sequence - (pBAEntry->BAWinSize) -1; if (TmpSeq < 0) { TmpSeq = (MAXSEQ+1) + TmpSeq; } WinStartSeq = (TmpSeq+1) & MAXSEQ; ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq); pBAEntry->LastIndSeq = WinStartSeq; //TmpSeq; pBAEntry->LastIndSeqAtTimer = Now32; ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, FromWhichBSSID); TmpSeq = ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, pBAEntry->LastIndSeq); if (TmpSeq != RESET_RCV_SEQ) { pBAEntry->LastIndSeq = TmpSeq; } } } #endif // DOT11_N_SUPPORT //
the_stack_data/179831870.c
#include <assert.h> #include <setjmp.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> // Regression test for bug 91162: if a client had a SEGV signal handler, // and jumped to a bogus address, Valgrind would abort. With the fix, // the following test runs to completion correctly. static jmp_buf myjmpbuf; static void SIGSEGV_handler(int signum) { longjmp(myjmpbuf, 1); } int main(void) { struct sigaction sigsegv_new, sigsegv_saved; int res; /* Install own SIGSEGV handler */ sigsegv_new.sa_handler = SIGSEGV_handler; sigsegv_new.sa_flags = 0; #if !defined(__APPLE__) && !defined(__sun) sigsegv_new.sa_restorer = NULL; #endif res = sigemptyset( &sigsegv_new.sa_mask ); assert(res == 0); res = sigaction( SIGSEGV, &sigsegv_new, &sigsegv_saved ); assert(res == 0); if (setjmp(myjmpbuf) == 0) { // Jump to zero; will cause seg fault #if defined(__powerpc64__) && (_CALL_ELF != 2) unsigned long int fn[3]; fn[0] = 0; fn[1] = 0; fn[2] = 0; #else void (*fn)(void) = 0; #endif ((void(*)(void)) fn) (); fprintf(stderr, "Got here??\n"); } else { fprintf(stderr, "Signal caught, as expected\n"); } return 0; }
the_stack_data/170451996.c
/** * @file 2-18.c * * stdarg.hを使って、printfを単純化したtiny_printfを定義する * - stdarg.hを使って可変長引数を扱えるようにする * - 書式に指定できる変換は%dのみ * - 第2引数移行には0-9だけを指定できる 文字コードはASCIIを仮定する * - 出力のためにはputcharだけを使う */ #include <stdio.h> #include <stdlib.h> // exit #include <string.h> #include <stdarg.h> /** * format文の中から、intのプレースホルダ(%d)の数を集計する * * "%d, %d, %d, %d" の場合 4 */ int get_int_var_count(char format[]) { // formatから%dの個数のチェックをする int sum_of_arg = 0; int i = 0; while (i < strlen(format)) { char c = format[i]; if (c == '%' && format[i + 1] == 'd') { sum_of_arg++; i+=2; continue; } i++; } return sum_of_arg; } int get_number_of_digits(int x) { int res = 1; // printf("x: %d\n", x); int target = x; while (1) { target = target / 10; // printf("a: %d\n", target); if (target == 0) { break; } res++; } return res; } /** * 自作 tiny_printf improve版 * 桁数とか諸々自前で計算した * * 問題文だと、数字は1桁前提になっているが、2桁以上の整数でも表示できるようになっている。 */ void improve_tiny_printf(char format[], ...) { // formatから%dの個数のチェックをする int sum_of_arg = get_int_var_count(format); int i = 0; int format_len = (int)strlen(format); va_list pvar; va_start(pvar, format); while (i <= format_len) { // printf("----\n"); if (format[i] == '%' && format[i + 1] == 'd') { int tmp = va_arg(pvar, int); // printf("------tmp: %d", tmp); // 入力値の整数の桁数を入力 int number_of_digits = get_number_of_digits(tmp); // printf("--number of digits:%d\n", number_of_digits); char converted[number_of_digits + 1]; sprintf(converted, "%d", tmp); // 整数値の桁数分ループして文字出力 for (int j = 0; j < number_of_digits; j++) { int res = putchar(converted[j]); if (res == EOF) { exit(1); } } i+=2; continue; } putchar(format[i]); i++; } va_end(pvar); } int tiny_printf(const char *fmt, ...) { va_list pvar; va_start(pvar, fmt); // 終端までループ while (*fmt != '\0') { if (*fmt != '%') { // %d以外はそのまま出力 putchar(*fmt); } else if (*++fmt == 'd') { // 1桁の整数を文字に変換して出力 putchar('0' + va_arg(pvar, int)); } else { return -1; } fmt++; } va_end(pvar); return 0; } int main(void) { // original 1桁のみ対応版 tiny_printf("hello: \n"); tiny_printf("hello: %d\n", 1); tiny_printf("hello: %d %d\n", 1, 2); // 複数桁対応版 improve_tiny_printf("test:%d, %d, %d aaa %d", 1100, 23001, 3, 4); }
the_stack_data/75935.c
// Variant of nested.c with a counter. void main() { int z = 0; for (int i=0; i<10 ; i++) { z = z+1; for (int j = 0; j < 10 ; j++) ; z = z+1; } return ; }
the_stack_data/6388224.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2015-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> #include <assert.h> pthread_barrier_t barrier; #define NUM_THREADS 2 void * thread_function (void *arg) { /* This ensures that the breakpoint is only hit after both threads are created, so the test can always switch to the non-event thread when the breakpoint triggers. */ pthread_barrier_wait (&barrier); while (1); /* break here */ } int main (void) { int i; pthread_barrier_init (&barrier, NULL, NUM_THREADS); for (i = 0; i < NUM_THREADS; i++) { pthread_t thread; int res; res = pthread_create (&thread, NULL, thread_function, NULL); assert (res == 0); } sleep (300); return 0; }
the_stack_data/198579530.c
//Enache Anca-Mihaela 314CD #include <stdio.h> #include <string.h> #include <stdlib.h> void wrap(int max_line_length, char original[1000][1000], int i, int original_line_count) { char *cuvant, aux_matrix[1000][1000], rand[1000]; int length = 0, L = 0, k; aux_matrix[0][0] = '\0'; i = 0; k = 0; strcpy(rand, original[i]); cuvant = strtok(rand, " \n"); while (cuvant != NULL && i < original_line_count) { L = strlen(cuvant); if (L > max_line_length) { printf("Cannot wrap!\n"); break; } length = length + L; if (length <= max_line_length) { strcat(aux_matrix[k], cuvant); strcat(aux_matrix[k], " "); length++; } else { if (length > max_line_length) { L = strlen(aux_matrix[k]); aux_matrix[k][L - 1] = '\n'; length = 0; strcat(aux_matrix[k], cuvant); strcat(aux_matrix[k], " "); L = strlen(cuvant); if (L > max_line_length) { printf("Cannot wrap!\n"); break; } length = length + L; length++; } } cuvant = strtok(NULL, " \n"); if (cuvant == NULL) { i++; L = strlen(aux_matrix[k]); aux_matrix[k][L - 1] = '\n'; k++; strcpy(rand, original[i]); if (rand[0] == '\n') { length = 0; strcat(aux_matrix[k], "\n"); k++; i++; strcpy(rand, original[i]); } cuvant = strtok(rand, " \n"); } } for (i = 0; i < k; i++) { strcpy(original[i], aux_matrix[i]); } } void center(int start, int end, char original[1000][1000], int i, int original_line_count) { int max_length = 0, nr = 0, j = 0, k; char spaces[1000], rand[1000]; for (i = 0; i <= original_line_count; i++) { strcpy(rand, original[i]); j = strlen(rand); if (j > max_length) { max_length = j; } } for (i = start; i <= end; i++) { nr = 0; strcpy(rand, original[i]); if (rand[0] != '\n') { j = strlen(rand); nr = (max_length - j +1)/ 2; for (k = 0; k < nr; k++) { spaces[k]=' '; } strcpy(spaces + nr, rand); strcpy(original[i], spaces); } } } void align_left(int start, int end, char original[1000][1000], int i, int original_line_count) { int nr = 0, j = 0; char rand[1000]; for (i = start; i <= end; i++) { j = 0; nr = 0; strcpy(rand, original[i]); if (rand[0] != '\n') { while (original[i][j] == ' ') { nr++; j++; } strcpy(rand, original[i] + nr); strcpy(original[i], rand); } } } void align_right(int start, int end, char original[1000][1000], int i, int original_line_count) { int max_length = 0, nr = 0, j = 0, k; char spaces[1000], rand[1000]; for (i = 0; i <= original_line_count; i++) { strcpy(rand, original[i]); j = strlen(rand); if (j > max_length) { max_length = j; } } for (i = start; i <= end; i++) { nr = 0; strcpy(rand, original[i]); if (rand[0] != '\n') { j = strlen(rand); nr = max_length - j; for (k = 0; k < nr; k++) { spaces[k]=' '; } strcpy(spaces + nr, rand); strcpy(original[i], spaces); } } } /*void justify() { }*/ void paragraphs(int indent_length, int start, int end, int i, char original[1000][1000], int original_line_count) { int k; char rand[1000]; rand[0] = '\0'; for (i = start - 1; i <= end; i++) { if (i == 0) { for (k = 0; k < indent_length; k++) { rand[k] = 32; } strcpy(rand + indent_length, original[i]); strcpy(original[i], rand); } else { if (strcmp(original[i], "\n") == 0) { i++; for (k = 0; k < indent_length; k++) { rand[k] = 32; } strcpy(rand + indent_length, original[i]); strcpy(original[i], rand); } } } } void lists(int start, int end, char *list_type, char *special_character, int i, char original[1000][1000], int original_line_count) { char rand[1000], bullet[1010]; int nr = 0; if (*list_type == 'n')//lista numerotata { int number = 1; for (i = start; i <= end; i++) { bullet[0] = '\0'; strcpy(rand, original[i]); if (rand[0] != '\n') { sprintf(bullet, "%d%s ", number, special_character); if (number < 10) { strcpy(bullet + 3, rand); } else { strcpy(bullet + 4, rand); } strcpy(original[i], bullet); number++; } } } if (*list_type == 'a')//lista alfabetica cu lit. mici { char litera = 'a'; for (i = start; i <= end; i++) { bullet[0] = '\0'; strcpy(rand, original[i]); if (rand[0] != '\n') { strcpy(rand, original[i] + nr); bullet[0] = litera; litera = litera + 1; strcpy(bullet + 1, special_character); strcpy(bullet + 2," "); strcpy(bullet + 3, rand); strcpy(original[i], bullet); } } } if (*list_type == 'A')//lista alfabetica cu lit. mari { char litera = 'A'; for (i = start; i <= end; i++) { bullet[0] = '\0'; strcpy(rand, original[i]); if (rand[0] != '\n') { strcpy(rand, original[i] + nr); bullet[0] = litera; litera = litera + 1; strcpy(bullet + 1, special_character); strcpy(bullet + 2," "); strcpy(bullet + 3, rand); strcpy(original[i], bullet); } } } if (*list_type == 'b')//bullet list { for ( i = start; i <= end; i++) { bullet[0] = '\0'; strcpy(rand, original[i]); if (rand[0] != '\n') { strcpy(rand, original[i] + nr); strcat(bullet, special_character); strcat(bullet," "); strcpy(bullet + 2, rand); strcpy(original[i], bullet); } } } } int main (int argc, char *argv[]) { char buf[1000], // buffer used for reading from the file original[1000][1000], // original text, line by line result[1000][1000]; // text obtained after applying operations int original_line_count = 0, // number of lines in the input file result_line_count = 0, // number of lines in the output file i; if (argc != 4) { // invalid number of arguments fprintf(stderr, "Usage: %s operations_string input_file output_file\n", argv[0]); return -1; } // Open input file for reading FILE *input_file = fopen(argv[2], "r"); if (input_file == NULL) { fprintf(stderr, "File \"%s\" not found\n", argv[2]); return -2; } // Read data in file line by line while (fgets(buf, 1000, input_file)) { strcpy(original[original_line_count], buf); original_line_count++; } fclose(input_file); char operations[100], ARGS[100][100]; char *p, *litera, *aux; int j, start, end, n = 0, k; strcpy( operations, argv[1]); i = 0; p = strtok(operations,","); while(p != NULL) { strcpy(ARGS[i], p); i++; p = strtok(NULL,","); } n = i; for(k = 0; k < n; k++) { strcpy(operations, ARGS[k]); p = strtok(operations," \n"); litera = p; //retin operatia ce urmeaza sa fie realizata if (*litera == 'W' || *litera == 'w')//WRAP { int max_line_length = 0; p = strtok(NULL," \n"); if ( p != NULL) { aux = p; max_line_length = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } wrap(max_line_length, original, i, original_line_count); } if (*litera == 'C' || *litera == 'c')//CENTER { start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if(start < 0) { printf("Invalid operation!\n"); break; } center(start, end, original, i, original_line_count); } if (*litera == 'L' || *litera == 'l')//ALIGN LEFT { start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if(start < 0) { printf("Invalid operation!\n"); break; } align_left(start, end, original, i, original_line_count); } if (*litera == 'R' || *litera == 'r')//ALIGN RIGHT { start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if(start < 0) { printf("Invalid operation!\n"); break; } align_right(start, end, original, i, original_line_count); } if (*litera == 'J' || *litera == 'j' )//JUSTIFY { int start = 0, end = 0; start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if(start < 0) { printf("Invalid operation!\n"); break; } } if (*litera == 'P' || *litera == 'p' )//PARAGRAPHS { int start = 0, end = 0, indent_length = 0; p = strtok(NULL," \n"); if (p != NULL) { aux = p; indent_length = atoi(aux); } else { printf("Invalid operation!\n"); break; } start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if (start < 0) { printf("Invalid operation!\n"); break; } paragraphs(indent_length, start, end, i, original, original_line_count); } if (*litera == 'I' || *litera == 'i' )//LISTS { int start = 0, end = 0; char *list_type, *special_character; p = strtok(NULL," \n"); if (p != NULL) { list_type = p; } p = strtok(NULL," \n"); if (p != NULL) { special_character = p; } else { printf("Invalid operation!\n"); break; } start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); break; } if(start > end) { printf("Invalid operation!\n"); break; } if(start < 0) { printf("Invalid operation!\n"); break; } align_left(start, end, original, i, original_line_count); lists(start, end, list_type, special_character, i, original, original_line_count); } if (*litera == 'O' || *litera == 'o' )//ORDERED LISTS { int start = 0, end = 0; char *list_type, *special_character, *ordering; p = strtok(NULL," \n"); if (p != NULL) { list_type = p; } p = strtok(NULL," \n"); if (p != NULL) { special_character = p; } p = strtok(NULL," \n"); if (p != NULL) { ordering = p; } else { printf("Invalid operation!\n"); break; } start = 0; end = original_line_count; p = strtok(NULL," \n"); if (p != NULL) { aux = p; start = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { aux = p; end = atoi(aux); } p = strtok(NULL," \n"); if (p != NULL) { printf("Invalid operation!\n"); } if(start > end) { printf("Invalid operation!\n"); } if(start < 0) { printf("Invalid operation!\n"); break; } char aux[1000]; if (*ordering == 'a')//sortare alfabetica { if ( start == 0 && end == original_line_count) { for (i = 0; i < original_line_count - 1; i++) { for (j = i + 1; j < original_line_count; j++) { if(strcmp(original[i],original[j]) > 0) { strcpy(aux, original[i]); strcpy(original[i], original[j]); strcpy(original[j], aux); } } } } else { aux[0] = '\0'; for (i = start; i <= end; i++) { for (j = i + 1; j <= end; j++) { if(strcmp(original[i],original[j]) > 0) { strcpy(aux, original[i]); strcpy(original[i], original[j]); strcpy(original[j], aux); } } } } } else { if (*ordering == 'z')//sortare invers alfabetica { if ( start == 0 && end == original_line_count) { for (i = 0; i < original_line_count - 1; i++) { for (j = i + 1; j < original_line_count; j++) { if(strcmp(original[i],original[j]) > 0) { strcpy(aux, original[i]); strcpy(original[i], original[j]); strcpy(original[j], aux); } } } } else { aux[0] = '\0'; for (i = start; i <= end; i++) { for (j = i + 1; j <= end; j++) { if(strcmp(original[i],original[j]) < 0) { strcpy(aux, original[i]); strcpy(original[i], original[j]); strcpy(original[j], aux); } } } } } } align_left(start, end, original, i, original_line_count); lists(start, end, list_type, special_character, i, original, original_line_count); } } for (i = 0; i < original_line_count; i++) { strcpy(result[i], original[i]); } result_line_count = original_line_count; // Open output file for writing FILE *output_file = fopen(argv[3], "w"); if (output_file == NULL) { fprintf(stderr, "Could not open or create file \"%s\"\n", argv[3]); return -2; } // Write result in output file for (i = 0; i < result_line_count; i++) { fputs(result[i], output_file); } fclose(output_file); }
the_stack_data/59512650.c
/* example from http://barnyard.syr.edu/quickies/hanoi.c */ /* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */ /* By Terry R. McConnell (12/2/97) */ /* Compile: cc -o hanoi hanoi.c */ /* This program does no error checking. But then, if it's right, it's right ... right ? */ /* The original towers of hanoi problem seems to have been originally posed by one M. Claus in 1883. There is a popular legend that goes along with it that has been often repeated and paraphrased. It goes something like this: In the great temple at Benares there are 3 golden spikes. On one of them, God placed 64 disks increasing in size from bottom to top, at the beginning of time. Since then, and to this day, the priest on duty constantly transfers disks, one at a time, in such a way that no larger disk is ever put on top of a smaller one. When the disks have been transferred entirely to another spike the Universe will come to an end in a large thunderclap. This paraphrases the original legend due to DeParville, La Nature, Paris 1884, Part I, 285-286. For this and further information see: Mathematical Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967, 303-305. * * */ #include <stdio.h> #include <stdlib.h> #define N 4 /* This is the number of "disks" on tower A initially. */ /* Taken to be 64 in the legend. The number of moves required, in general, is 2^N - 1. For N = 64, this is 18,446,744,073,709,551,615 */ int A[N], B[N], C[N]; /* These are the three towers. For example if the state of A is 0,1,3,4, that means that there are three discs on A of sizes 1, 3, and 4. (Think of right as being the "down" direction.) */ void Hanoi(int,int*,int*,int*); /* Print the current configuration of A, B, and C to the screen */ void PrintAll() { int i; printf("A: "); for(i=0;i<N;i++)printf(" %d ",A[i]); printf("\n"); printf("B: "); for(i=0;i<N;i++)printf(" %d ",B[i]); printf("\n"); printf("C: "); for(i=0;i<N;i++)printf(" %d ",C[i]); printf("\n"); printf("------------------------------------------\n"); return; } /* Move the leftmost nonzero element of source to dest, leave behind 0. */ /* Returns the value moved (not used.) */ int Move(int *source, int *dest) { int i = 0,j = 0; while (i<N && (source[i])==0) i++; while (j<N && (dest[j])==0) j++; dest[j-1] = source[i]; source[i] = 0; PrintAll(); /* Print configuration after each move. */ return dest[j-1]; } /* Moves first n nonzero numbers from source to dest using the rules of Hanoi. Calls itself recursively. */ void Hanoi(int n,int *source, int *dest, int *spare) { int i; if(n==1){ Move(source,dest); return; } Hanoi(n-1,source,spare,dest); Move(source,dest); Hanoi(n-1,spare,dest,source); return; } int main() { int i; /* initialize the towers */ for(i=0;i<N;i++)A[i]=i+1; for(i=0;i<N;i++)B[i]=0; for(i=0;i<N;i++)C[i]=0; printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N); /* Print the starting state */ printf("Starting state:\n"); PrintAll(); printf("\n\nSubsequent states:\n\n"); /* Do it! Use A = Source, B = Destination, C = Spare */ Hanoi(N,A,B,C); return 0; }
the_stack_data/68888977.c
#include <stdio.h> struct person{ int age; int gender; //1 - female, 0 - men(bcs women are always true(right)!!!) int accepts_LGBT; // 1 - yes, 0 -no }; void what_are_they(struct person person1,struct person person2); void should_we_date(struct person person1,struct person person2); void sexuality(struct person person1,struct person person2); int parade_or_not(struct person person); int make_the_num_positive(int num); int main() { struct person women; struct person men; //hard coded values for testing women.age = 22; men.age = 23; women.gender = 1; men.gender = 0; women.accepts_LGBT = 1; men.accepts_LGBT = 0; what_are_they(women, men); should_we_date(women,men); sexuality(women,men); if(parade_or_not(men)==1) printf("Yessss\n"); else printf("Nooo\n"); return 0; } void what_are_they(struct person person1,struct person person2){ //should print if they are both men, women, or man and women int count_male = 0,count_female = 0; if(person1.gender==1) count_female++; else count_male++; if(person2.gender==1) count_female++; else count_male++; if(count_male == 2) printf("Both are male\n"); else if(count_female == 2) printf("Both are female\n"); else printf("One is female, one is male\n"); } void should_we_date(struct person person1,struct person person2){ if((person1.age<=18 && person2.age>=18)||(person1.age>=18 && person2.age<=18)){ //pedophiles printf("Warning! Not a safe relationship. One is underage!\n"); } else if (person1.age<18 && person2.age<18){ printf("Both are underage.\n"); } else{ int age_difference = person1.age - person2.age; make_the_num_positive(age_difference); //make it possitive if (age_difference<11){ printf("This relationship is all right.\n"); }else{ printf("Warning, there is a big age difference.\n"); } } } void sexuality(struct person person1,struct person person2){ if(person1.gender == 1){ //person 1 - woman if (person2.gender == 1){ //both are women printf("Lesbians\n"); }else{ //one men,one women printf("Homo\n"); } }else{ //one is male if (person2.gender == 0){ //both male printf("Gays\n"); }else{ //one men,one women printf("Homo\n"); } } } int parade_or_not(struct person person){ if(person.accepts_LGBT == 1) { return 1; // should }else return 0; // not really } int make_the_num_positive(int num){ if(num>0); else num *= -1; return num; }
the_stack_data/150140293.c
#include<stdio.h> #include<string.h> int main() { char str[1000]; int i,j,sum; scanf("%s",str); sum=0; for(i=0;i<strlen(str);i++) { if(str[i]=='['||str[i]==']'||str[i]=='('||str[i]==')') sum++; } for(i=0;i<strlen(str);i++) { if(str[i]=='(') { for(j=i;j<strlen(str);j++) { if(str[j]==')') { str[i]='0'; str[j]='0'; sum-=2; break; } } } if(str[i]=='[') { for(j=i;j<strlen(str);j++) { if(str[j]==']') { str[i]='0'; str[j]='0'; sum-=2; break; } } } } if(sum==0) printf("YES"); else printf("NO"); return 0; }
the_stack_data/161080831.c
#include <stdio.h> int main() { int x = 1; int y = 2; int *p1 = NULL; printf("%u\n", p1); int *p2 = NULL; p2 = &y; *p1 = 170; // Dangerous?? *p2 = 4; printf("%i\n", x+y); return 0; }
the_stack_data/132180.c
#include <string.h> int ibmgfx(int ch) { const char *vt100 = "lmkjnqxtuvwah~-"; const char *cp437 = "\xDA\xC0\xBF\xD9\xC5\xC4\xB3" "\xC3\xB4\xC1\xC2\xB1\xB0\xFA\x18"; char *p; if (ch & 0x100) { ch ^= 0x100; p = strchr(vt100, ch); if (p) return cp437[p-vt100]; } return ch; }
the_stack_data/1124813.c
#include <stdio.h> #include <unistd.h> // gcc -Wall tick.c -o tick int main() { int i; for (i = 0; i < 10; i++) { printf("tick\n"); fflush(stdout); sleep(1); } printf("BOOM!\n"); return 0; }
the_stack_data/140766625.c
/* * i386 signal handling routines * * Copyright 1999 Alexandre Julliard * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef __i386__ #include <errno.h> #include <signal.h> #include <stdlib.h> #include <stdarg.h> #include <stdio.h> #include <sys/types.h> #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" #include "ntdll_misc.h" #include "wine/exception.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(seh); struct x86_thread_data { DWORD fs; /* 1d4 TEB selector */ DWORD gs; /* 1d8 libc selector; update winebuild if you move this! */ DWORD dr0; /* 1dc debug registers */ DWORD dr1; /* 1e0 */ DWORD dr2; /* 1e4 */ DWORD dr3; /* 1e8 */ DWORD dr6; /* 1ec */ DWORD dr7; /* 1f0 */ void *exit_frame; /* 1f4 exit frame pointer */ }; C_ASSERT( sizeof(struct x86_thread_data) <= 16 * sizeof(void *) ); C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, gs ) == 0x1d8 ); C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, exit_frame ) == 0x1f4 ); static inline struct x86_thread_data *x86_thread_data(void) { return (struct x86_thread_data *)&NtCurrentTeb()->GdiTebBatch; } struct ldt_copy *__wine_ldt_copy = NULL; /* Exception record for handling exceptions happening inside exception handlers */ typedef struct { EXCEPTION_REGISTRATION_RECORD frame; EXCEPTION_REGISTRATION_RECORD *prevFrame; } EXC_NESTED_FRAME; extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame, CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher, PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler ); /******************************************************************* * is_valid_frame */ static inline BOOL is_valid_frame( void *frame ) { if ((ULONG_PTR)frame & 3) return FALSE; return (frame >= NtCurrentTeb()->Tib.StackLimit && (void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1); } /******************************************************************* * raise_handler * * Handler for exceptions happening inside a handler. */ static DWORD raise_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame, CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher ) { if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) return ExceptionContinueSearch; /* We shouldn't get here so we store faulty frame in dispatcher */ *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame; return ExceptionNestedException; } /******************************************************************* * unwind_handler * * Handler for exceptions happening inside an unwind handler. */ static DWORD unwind_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame, CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher ) { if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))) return ExceptionContinueSearch; /* We shouldn't get here so we store faulty frame in dispatcher */ *dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame; return ExceptionCollidedUnwind; } /********************************************************************** * call_stack_handlers * * Call the stack handlers chain. */ static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) { EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame; DWORD res; frame = NtCurrentTeb()->Tib.ExceptionList; nested_frame = NULL; while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) { /* Check frame address */ if (!is_valid_frame( frame )) { rec->ExceptionFlags |= EH_STACK_INVALID; break; } /* Call handler */ TRACE( "calling handler at %p code=%x flags=%x\n", frame->Handler, rec->ExceptionCode, rec->ExceptionFlags ); res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, raise_handler ); TRACE( "handler at %p returned %x\n", frame->Handler, res ); if (frame == nested_frame) { /* no longer nested */ nested_frame = NULL; rec->ExceptionFlags &= ~EH_NESTED_CALL; } switch(res) { case ExceptionContinueExecution: if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS; return STATUS_NONCONTINUABLE_EXCEPTION; case ExceptionContinueSearch: break; case ExceptionNestedException: if (nested_frame < dispatch) nested_frame = dispatch; rec->ExceptionFlags |= EH_NESTED_CALL; break; default: return STATUS_INVALID_DISPOSITION; } frame = frame->Prev; } return STATUS_UNHANDLED_EXCEPTION; } /******************************************************************* * KiUserExceptionDispatcher (NTDLL.@) */ NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context ) { NTSTATUS status; DWORD c; TRACE( "code=%x flags=%x addr=%p ip=%08x tid=%04x\n", rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, context->Eip, GetCurrentThreadId() ); for (c = 0; c < rec->NumberParameters; c++) TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] ); if (rec->ExceptionCode == EXCEPTION_WINE_STUB) { if (rec->ExceptionInformation[1] >> 16) MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n", rec->ExceptionAddress, (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] ); else MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n", rec->ExceptionAddress, (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] ); } else { TRACE(" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n", context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi ); TRACE(" ebp=%08x esp=%08x cs=%04x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n", context->Ebp, context->Esp, context->SegCs, context->SegDs, context->SegEs, context->SegFs, context->SegGs, context->EFlags ); } if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) NtContinue( context, FALSE ); if ((status = call_stack_handlers( rec, context )) == STATUS_SUCCESS) NtContinue( context, FALSE ); if (status != STATUS_UNHANDLED_EXCEPTION) RtlRaiseStatus( status ); return NtRaiseException( rec, context, FALSE ); } __ASM_STDCALL_FUNC( KiUserExceptionDispatcher, 8, "pushl 4(%esp)\n\t" "pushl 4(%esp)\n\t" "call " __ASM_STDCALL("dispatch_exception", 8) "\n\t" "int3" ) /******************************************************************* * KiUserApcDispatcher (NTDLL.@) */ void WINAPI KiUserApcDispatcher( CONTEXT *context, ULONG_PTR ctx, ULONG_PTR arg1, ULONG_PTR arg2, PNTAPCFUNC func ) { func( ctx, arg1, arg2 ); NtContinue( context, TRUE ); } /*********************************************************************** * save_fpu * * Save the thread FPU context. */ static inline void save_fpu( CONTEXT *context ) { #ifdef __GNUC__ struct { DWORD ControlWord; DWORD StatusWord; DWORD TagWord; DWORD ErrorOffset; DWORD ErrorSelector; DWORD DataOffset; DWORD DataSelector; } float_status; context->ContextFlags |= CONTEXT_FLOATING_POINT; __asm__ __volatile__( "fnsave %0; fwait" : "=m" (context->FloatSave) ); /* Reset unmasked exceptions status to avoid firing an exception. */ memcpy(&float_status, &context->FloatSave, sizeof(float_status)); float_status.StatusWord &= float_status.ControlWord | 0xffffff80; __asm__ __volatile__( "fldenv %0" : : "m" (float_status) ); #endif } /*********************************************************************** * save_fpux * * Save the thread FPU extended context. */ static inline void save_fpux( CONTEXT *context ) { #ifdef __GNUC__ /* we have to enforce alignment by hand */ char buffer[sizeof(XSAVE_FORMAT) + 16]; XSAVE_FORMAT *state = (XSAVE_FORMAT *)(((ULONG_PTR)buffer + 15) & ~15); context->ContextFlags |= CONTEXT_EXTENDED_REGISTERS; __asm__ __volatile__( "fxsave %0" : "=m" (*state) ); memcpy( context->ExtendedRegisters, state, sizeof(*state) ); #endif } /*********************************************************************** * RtlCaptureContext (NTDLL.@) */ __ASM_STDCALL_FUNC( RtlCaptureContext, 4, "pushl %eax\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") "movl 8(%esp),%eax\n\t" /* context */ "movl $0x10007,(%eax)\n\t" /* context->ContextFlags */ "movw %gs,0x8c(%eax)\n\t" /* context->SegGs */ "movw %fs,0x90(%eax)\n\t" /* context->SegFs */ "movw %es,0x94(%eax)\n\t" /* context->SegEs */ "movw %ds,0x98(%eax)\n\t" /* context->SegDs */ "movl %edi,0x9c(%eax)\n\t" /* context->Edi */ "movl %esi,0xa0(%eax)\n\t" /* context->Esi */ "movl %ebx,0xa4(%eax)\n\t" /* context->Ebx */ "movl %edx,0xa8(%eax)\n\t" /* context->Edx */ "movl %ecx,0xac(%eax)\n\t" /* context->Ecx */ "movl 0(%ebp),%edx\n\t" "movl %edx,0xb4(%eax)\n\t" /* context->Ebp */ "movl 4(%ebp),%edx\n\t" "movl %edx,0xb8(%eax)\n\t" /* context->Eip */ "movw %cs,0xbc(%eax)\n\t" /* context->SegCs */ "pushfl\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") "popl 0xc0(%eax)\n\t" /* context->EFlags */ __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") "leal 8(%ebp),%edx\n\t" "movl %edx,0xc4(%eax)\n\t" /* context->Esp */ "movw %ss,0xc8(%eax)\n\t" /* context->SegSs */ "popl 0xb0(%eax)\n\t" /* context->Eax */ __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") "ret $4" ) /******************************************************************* * RtlUnwind (NTDLL.@) */ void WINAPI DECLSPEC_HIDDEN __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID targetIp, PEXCEPTION_RECORD pRecord, PVOID retval, CONTEXT *context ) { EXCEPTION_RECORD record; EXCEPTION_REGISTRATION_RECORD *frame, *dispatch; DWORD res; context->Eax = (DWORD)retval; /* build an exception record, if we do not have one */ if (!pRecord) { record.ExceptionCode = STATUS_UNWIND; record.ExceptionFlags = 0; record.ExceptionRecord = NULL; record.ExceptionAddress = (void *)context->Eip; record.NumberParameters = 0; pRecord = &record; } pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND); TRACE( "code=%x flags=%x\n", pRecord->ExceptionCode, pRecord->ExceptionFlags ); TRACE( "eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n", context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi ); TRACE( "ebp=%08x esp=%08x eip=%08x cs=%04x ds=%04x fs=%04x gs=%04x flags=%08x\n", context->Ebp, context->Esp, context->Eip, LOWORD(context->SegCs), LOWORD(context->SegDs), LOWORD(context->SegFs), LOWORD(context->SegGs), context->EFlags ); /* get chain of exception frames */ frame = NtCurrentTeb()->Tib.ExceptionList; while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame)) { /* Check frame address */ if (pEndFrame && (frame > pEndFrame)) raise_status( STATUS_INVALID_UNWIND_TARGET, pRecord ); if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, pRecord ); /* Call handler */ TRACE( "calling handler at %p code=%x flags=%x\n", frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags ); res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, unwind_handler ); TRACE( "handler at %p returned %x\n", frame->Handler, res ); switch(res) { case ExceptionContinueSearch: break; case ExceptionCollidedUnwind: frame = dispatch; break; default: raise_status( STATUS_INVALID_DISPOSITION, pRecord ); break; } frame = __wine_pop_frame( frame ); } NtContinue( context, FALSE ); } __ASM_STDCALL_FUNC( RtlUnwind, 16, "pushl %ebp\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") "movl %esp,%ebp\n\t" __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") "leal -(0x2cc+8)(%esp),%esp\n\t" /* sizeof(CONTEXT) + alignment */ "pushl %eax\n\t" "leal 4(%esp),%eax\n\t" /* context */ "xchgl %eax,(%esp)\n\t" "call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t" "leal 24(%ebp),%eax\n\t" "movl %eax,0xc4(%esp)\n\t" /* context->Esp */ "pushl %esp\n\t" "pushl 20(%ebp)\n\t" "pushl 16(%ebp)\n\t" "pushl 12(%ebp)\n\t" "pushl 8(%ebp)\n\t" "call " __ASM_STDCALL("__regs_RtlUnwind",20) "\n\t" "leave\n\t" __ASM_CFI(".cfi_def_cfa %esp,4\n\t") __ASM_CFI(".cfi_same_value %ebp\n\t") "ret $16" ) /* actually never returns */ /******************************************************************* * raise_exception_full_context * * Raise an exception with the full CPU context. */ void raise_exception_full_context( EXCEPTION_RECORD *rec, CONTEXT *context ) { save_fpu( context ); save_fpux( context ); /* FIXME: xstate */ context->Dr0 = x86_thread_data()->dr0; context->Dr1 = x86_thread_data()->dr1; context->Dr2 = x86_thread_data()->dr2; context->Dr3 = x86_thread_data()->dr3; context->Dr6 = x86_thread_data()->dr6; context->Dr7 = x86_thread_data()->dr7; context->ContextFlags |= CONTEXT_DEBUG_REGISTERS; RtlRaiseStatus( NtRaiseException( rec, context, TRUE )); } /*********************************************************************** * RtlRaiseException (NTDLL.@) */ __ASM_STDCALL_FUNC( RtlRaiseException, 4, "pushl %ebp\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") "movl %esp,%ebp\n\t" __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") "leal -0x2cc(%esp),%esp\n\t" /* sizeof(CONTEXT) */ "pushl %esp\n\t" /* context */ "call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t" "movl 4(%ebp),%eax\n\t" /* return address */ "movl 8(%ebp),%ecx\n\t" /* rec */ "movl %eax,12(%ecx)\n\t" /* rec->ExceptionAddress */ "leal 12(%ebp),%eax\n\t" "movl %eax,0xc4(%esp)\n\t" /* context->Esp */ "movl %esp,%eax\n\t" "pushl %eax\n\t" "pushl %ecx\n\t" "call " __ASM_NAME("raise_exception_full_context") "\n\t" "leave\n\t" __ASM_CFI(".cfi_def_cfa %esp,4\n\t") __ASM_CFI(".cfi_same_value %ebp\n\t") "ret $4" ) /* actually never returns */ /************************************************************************* * RtlCaptureStackBackTrace (NTDLL.@) */ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash ) { CONTEXT context; ULONG i; ULONG *frame; RtlCaptureContext( &context ); if (hash) *hash = 0; frame = (ULONG *)context.Ebp; while (skip--) { if (!is_valid_frame( frame )) return 0; frame = (ULONG *)*frame; } for (i = 0; i < count; i++) { if (!is_valid_frame( frame )) break; buffer[i] = (void *)frame[1]; if (hash) *hash += frame[1]; frame = (ULONG *)*frame; } return i; } /*********************************************************************** * signal_start_thread */ __ASM_GLOBAL_FUNC( signal_start_thread, "movl 4(%esp),%esi\n\t" /* context */ "leal -12(%esi),%ecx\n\t" /* clear the thread stack */ "andl $~0xfff,%ecx\n\t" /* round down to page size */ "movl %fs:8,%edi\n\t" /* NtCurrentTeb()->Tib.StackLimit */ "addl $0x1000,%edi\n\t" "movl %edi,%esp\n\t" "subl %edi,%ecx\n\t" "xorl %eax,%eax\n\t" "shrl $2,%ecx\n\t" "rep; stosl\n\t" /* switch to the initial context */ "leal -12(%esi),%esp\n\t" "movl $1,4(%esp)\n\t" "movl %esi,(%esp)\n\t" "call " __ASM_STDCALL("NtContinue", 8) ) /********************************************************************** * DbgBreakPoint (NTDLL.@) */ __ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret" "\n\tnop; nop; nop; nop; nop; nop; nop; nop" "\n\tnop; nop; nop; nop; nop; nop" ); /********************************************************************** * DbgUserBreakPoint (NTDLL.@) */ __ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret" "\n\tnop; nop; nop; nop; nop; nop; nop; nop" "\n\tnop; nop; nop; nop; nop; nop" ); /********************************************************************** * NtCurrentTeb (NTDLL.@) */ __ASM_STDCALL_FUNC( NtCurrentTeb, 0, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" ) /************************************************************************** * _chkstk (NTDLL.@) */ __ASM_GLOBAL_FUNC( _chkstk, "negl %eax\n\t" "addl %esp,%eax\n\t" "xchgl %esp,%eax\n\t" "movl 0(%eax),%eax\n\t" /* copy return address from old location */ "movl %eax,0(%esp)\n\t" "ret" ) /************************************************************************** * _alloca_probe (NTDLL.@) */ __ASM_GLOBAL_FUNC( _alloca_probe, "negl %eax\n\t" "addl %esp,%eax\n\t" "xchgl %esp,%eax\n\t" "movl 0(%eax),%eax\n\t" /* copy return address from old location */ "movl %eax,0(%esp)\n\t" "ret" ) /********************************************************************** * EXC_CallHandler (internal) * * Some exception handlers depend on EBP to have a fixed position relative to * the exception frame. * Shrinker depends on (*1) doing what it does, * (*2) being the exact instruction it is and (*3) beginning with 0x64 * (i.e. the %fs prefix to the movl instruction). It also depends on the * function calling the handler having only 5 parameters (*4). */ __ASM_GLOBAL_FUNC( EXC_CallHandler, "pushl %ebp\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") "movl %esp,%ebp\n\t" __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") "pushl %ebx\n\t" __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t") "movl 28(%ebp), %edx\n\t" /* ugly hack to pass the 6th param needed because of Shrinker */ "pushl 24(%ebp)\n\t" "pushl 20(%ebp)\n\t" "pushl 16(%ebp)\n\t" "pushl 12(%ebp)\n\t" "pushl 8(%ebp)\n\t" "call " __ASM_NAME("call_exception_handler") "\n\t" "popl %ebx\n\t" __ASM_CFI(".cfi_same_value %ebx\n\t") "leave\n" __ASM_CFI(".cfi_def_cfa %esp,4\n\t") __ASM_CFI(".cfi_same_value %ebp\n\t") "ret" ) __ASM_GLOBAL_FUNC(call_exception_handler, "pushl %ebp\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") "movl %esp,%ebp\n\t" __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") "subl $12,%esp\n\t" "pushl 12(%ebp)\n\t" /* make any exceptions in this... */ "pushl %edx\n\t" /* handler be handled by... */ ".byte 0x64\n\t" "pushl (0)\n\t" /* nested_handler (passed in edx). */ ".byte 0x64\n\t" "movl %esp,(0)\n\t" /* push the new exception frame onto the exception stack. */ "pushl 20(%ebp)\n\t" "pushl 16(%ebp)\n\t" "pushl 12(%ebp)\n\t" "pushl 8(%ebp)\n\t" "movl 24(%ebp), %ecx\n\t" /* (*1) */ "call *%ecx\n\t" /* call handler. (*2) */ ".byte 0x64\n\t" "movl (0), %esp\n\t" /* restore previous... (*3) */ ".byte 0x64\n\t" "popl (0)\n\t" /* exception frame. */ "movl %ebp, %esp\n\t" /* restore saved stack, in case it was corrupted */ "popl %ebp\n\t" __ASM_CFI(".cfi_def_cfa %esp,4\n\t") __ASM_CFI(".cfi_same_value %ebp\n\t") "ret $20" ) /* (*4) */ #endif /* __i386__ */
the_stack_data/1022870.c
#include <stdio.h> int main () { /* local variable definition */ int i, j; for(i = 2; i<100; i++) { for(j = 2; j <= (i/j); j++) if(!(i%j)) break; // if factor found, not prime if(j > (i/j)) printf("%d is prime\n", i); } return 0; }
the_stack_data/68887961.c
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <stdio.h> int main( int argc, char **argv ) { const char *file_name = "prueba"; if(open(file_name, O_CREAT, 00645) == -1) { perror("¡! Error en la función open"); return -1; } printf("=> Fichero %s creado con éxito\n", file_name); return 0; }
the_stack_data/12361.c
#if bios == 1 #include <lib/print.h> #include <lib/real.h> #include <pxe/pxe.h> #include <lib/libc.h> #include <lib/blib.h> #include <mm/pmm.h> void set_pxe_fp(uint32_t fp); struct volume *pxe_bind_volume(void) { struct volume *volume = ext_mem_alloc(sizeof(struct volume)); volume->pxe = true; return volume; } void pxe_init(void) { //pxe installation check struct rm_regs r = { 0 }; r.ebx = 0; r.ecx = 0; r.eax = 0x5650; r.es = 0; rm_int(0x1a, &r, &r); if ((r.eax & 0xffff) != 0x564e) { panic("PXE installation check failed"); } struct pxenv* pxenv = { 0 }; pxenv = (struct pxenv*)((r.es << 4) + (r.ebx & 0xffff)); if (memcmp(pxenv->signature, PXE_SIGNATURE, sizeof(pxenv->signature)) != 0) { panic("PXENV structure signature corrupted"); } if (pxenv->version < 0x201) { //we won't support pxe < 2.1, grub does this too and it seems to work fine panic("pxe version too old"); } struct bangpxe* bangpxe = (struct bangpxe*)((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4) + (pxenv->pxe_ptr & 0xffff)); if (memcmp(bangpxe->signature, PXE_BANGPXE_SIGNATURE, sizeof(bangpxe->signature)) != 0) { panic("!pxe signature corrupted"); } set_pxe_fp(bangpxe->rm_entry); printv("pxe: Successfully initialized\n"); } #endif
the_stack_data/35427.c
#include <math.h> #ifdef CONFIG_ESP_FOC_CUSTOM_MATH const float ESP_FOC_FAST_PI = 3.14159265358f; const float ESP_FOC_FAST_2PI = ESP_FOC_FAST_PI * 2.0f; const float ESP_FOC_SIN_COS_APPROX_B = 4.0f / ESP_FOC_FAST_PI; const float ESP_FOC_SIN_COS_APPROX_C = -4.0f / (ESP_FOC_FAST_PI * ESP_FOC_FAST_PI); const float ESP_FOC_SIN_COS_APPROX_P = 0.225f; const float ESP_FOC_SIN_COS_APPROX_D = ESP_FOC_FAST_PI/2.0f; #endif const float ESP_FOC_CLARKE_K1 = 2.0/3.0f; const float ESP_FOC_CLARKE_K2 = 1.0/3.0f; const float ESP_FOC_CLARKE_PARK_SQRT3 = 1.73205080757f; const float ESP_FOC_CLARKE_K3 = 2.0f / ESP_FOC_CLARKE_PARK_SQRT3;
the_stack_data/455389.c
#include <stdio.h> #include <stdlib.h> typedef struct var_s { int coeff; int power; struct var_s *next; } Var; typedef Var *Polynomial; void push(Polynomial *p, const int coeff, const int power) { Var *new = malloc(sizeof(Var)); new->coeff = coeff; new->power = power; new->next = NULL; if (!(*p)) { *p = new; return; } while ((*p)->next) p = &(*p)->next; (*p)->next = new; } void input(Polynomial *p) { int i, count = 0, buf[20] = {0}; char ch = 0; while (ch != EOF && ch != '\n') { scanf("%d", &buf[count]); ch = getchar(); count++; } for (i = 0; i < count; i++) if (buf[i]) push(p, buf[i], count - i - 1); printf("\n"); } void output(const Polynomial *p) { int is_first = 1, has_non_zero = 0; while (*p) { if ((*p)->coeff) { if ((*p)->coeff > 0 && !is_first) printf("+"); if ((*p)->coeff == -1 && (*p)->power > 0) printf("-"); else if ((*p)->coeff != 1 || (*p)->power == 0) printf("%d", (*p)->coeff); if ((*p)->power > 1) printf("x^%d", (*p)->power); else if ((*p)->power == 1) printf("x"); is_first = 0; has_non_zero = 1; } p = &(*p)->next; } if (!has_non_zero) printf("0"); printf("\n"); } void output_raw(const Polynomial *p) { while (*p) { printf("%2dx^%d\n", (*p)->coeff, (*p)->power); p = &(*p)->next; } } void delete_all(Polynomial *p) { Var *tmp; while (*p) { tmp = *p; *p = (*p)->next; free(tmp); } } void copy(Polynomial *dest, Polynomial *src) { delete_all(dest); while (*src) { push(dest, (*src)->coeff, (*src)->power); src = &(*src)->next; } } void add(const Polynomial *p1, const Polynomial *p2, Polynomial *ans) { Polynomial tmp = NULL; while (*p1 || *p2) { if (!(*p1)) { push(&tmp, (*p2)->coeff, (*p2)->power); p2 = &(*p2)->next; continue; } if (!(*p2)) { push(&tmp, (*p1)->coeff, (*p1)->power); p1 = &(*p1)->next; continue; } if ((*p1)->power > (*p2)->power) { push(&tmp, (*p1)->coeff, (*p1)->power); p1 = &(*p1)->next; continue; } if ((*p1)->power < (*p2)->power) { push(&tmp, (*p2)->coeff, (*p2)->power); p2 = &(*p2)->next; continue; } push(&tmp, (*p1)->coeff + (*p2)->coeff, (*p1)->power); p1 = &(*p1)->next; p2 = &(*p2)->next; } copy(ans, &tmp); delete_all(&tmp); } void sub(const Polynomial *p1, const Polynomial *p2, Polynomial *ans) { Polynomial tmp = NULL; while (*p1 || *p2) { if (!(*p1)) { push(&tmp, -(*p2)->coeff, (*p2)->power); p2 = &(*p2)->next; continue; } if (!(*p2)) { push(&tmp, (*p1)->coeff, (*p1)->power); p1 = &(*p1)->next; continue; } if ((*p1)->power > (*p2)->power) { push(&tmp, (*p1)->coeff, (*p1)->power); p1 = &(*p1)->next; continue; } if ((*p1)->power < (*p2)->power) { push(&tmp, -(*p2)->coeff, (*p2)->power); p2 = &(*p2)->next; continue; } push(&tmp, (*p1)->coeff - (*p2)->coeff, (*p1)->power); p1 = &(*p1)->next; p2 = &(*p2)->next; } copy(ans, &tmp); delete_all(&tmp); } void mul(const Polynomial *p1, const Polynomial *p2, Polynomial *ans) { Polynomial product = NULL, _p1 = NULL; while (*p2) { _p1 = *p1; while (_p1) { push(&product, (_p1)->coeff * (*p2)->coeff, (_p1)->power + (*p2)->power); _p1 = (_p1)->next; } add(&product, ans, ans); delete_all(&product); p2 = &(*p2)->next; } } int main() { Polynomial p1 = NULL, p2 = NULL, ans = NULL; input(&p1); input(&p2); add(&p1, &p2, &ans); output(&ans); delete_all(&ans); sub(&p1, &p2, &ans); output(&ans); delete_all(&ans); mul(&p1, &p2, &ans); output(&ans); delete_all(&ans); delete_all(&p1); delete_all(&p2); return 0; }
the_stack_data/242332006.c
#include <stdio.h> #include <stdlib.h> int main() { int array[2][2][3]={0,1,2,3,4,5,6,7,8,9,10,11}; printf("%d", array[1][0][2]); return 0; system("PAUSE"); }
the_stack_data/159515704.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int n; scanf("%d", &n); struct Time_Pos { int t, p; }; struct Time_Pos *collection = (struct Time_Pos*)malloc(sizeof(struct Time_Pos) * n); float greatest_speed = 0.0f; for(int i = 0; i < n; i++) { int t, p; scanf("%d %d", &t, &p); collection[i].t = t; collection[i].p = p; for(int k = i-1; k >= 0; k--) { if(collection[k].t > t) { collection[k+1].t = collection[k].t; collection[k+1].p = collection[k].p; collection[k].t = t; collection[k].p = p; continue; } break; } } for(int i = 0; i < n-1; i++) { float speed = fabs((float)(collection[i].p - collection[i+1].p) / (float)(collection[i].t - collection[i+1].t)); if(speed > greatest_speed) { greatest_speed = speed; } } printf("%f\n", greatest_speed); return 0; }
the_stack_data/6387232.c
#include<stdio.h> #include<stdlib.h> struct vector{ int size; int capacity; char *arr; }; void resize(struct vector *X); int strLen(char *Y); void output(struct vector *X); void initString(struct vector *X, char *Y); void concatenate(struct vector *combined, struct vector *a, struct vector *b); void slice(struct vector *sliced, struct vector *source, int start, int end); int main(){ //Asks the user for their choices int input; printf("What do you want to do?\n[1]Concatenate\n[2]Slice\n"); scanf("%i", &input); if(input == 1){ //Initializing values struct vector one = { 0 }; struct vector two = { 0 }; struct vector combined = { 0 }; char textOne[50]; char textTwo[50]; //Using functions printf("Enter text: "); scanf_s("%s", textOne, 50); initString(&one, textOne); printf("\nEnter text: "); scanf_s("%s", textTwo, 50); initString(&two, textTwo); concatenate(&combined, &one, &two); output(&combined); }else if(input == 2){ //Initializing values struct vector source = { 0 }; struct vector sliced = { 0 }; int start = 0, end = 0; char text[50]; //Using functions printf("Enter text: "); scanf_s("%s", text, 50); initString(&source, text); //Looping in cas user does not place correct values do{ printf("Enter start index: "); scanf("%i", &start); }while(start < 0 || start > 9); do{ printf("Enter end index: "); scanf("%i", &end); }while(end < 0 || end > 9); slice(&sliced, &source, start, end); output(&sliced); }else{ printf("Invalid input."); } return 0; } //Expands the maximum threshold to twice the original value void resize(struct vector *X){ //Doubling the max threshold int newCapacity = 2*X->size; char *newArr = (char*)malloc(sizeof(char)*newCapacity); //Moving all the characters from the old array into the new bigger one for(int i = 0; i< X->size; i++){ newArr[i] = X->arr[i]; } //Updating variables with their new values X->capacity = newCapacity; free(X->arr); X->arr = newArr; } //Counts the length of the string int strLen (char *Y){ int i = 0; while(Y[i] != '\0'){ i++; } return i; } //Prints out the vector string void output(struct vector *X){ printf("\n"); for(int i = 0; i < X->size; i++){ printf("%c", X->arr[i]); } } //Accepts a string and inserts all the character array's characters in the vector void initString(struct vector *X, char *Y){ //Initializing X->size = strLen(Y); X->capacity = 10; X->arr = (char*)malloc(sizeof(char)*X->capacity); //When the max threshold is not enough, we update it by resizing the whole vector while(X->capacity < X->size){ resize(X); } //Transferring the inputted values from the user to the vector for(int i = 0; i < X->size; i++) { X->arr[i] = Y[i]; } } void concatenate(struct vector *combined, struct vector *a, struct vector *b){ //Initializing //Combining the sizes of the a.vector and b.vector int finalSize = a->size + b->size; combined->size = finalSize; combined->capacity = 10; combined->arr =(char*)malloc(sizeof(char)*combined->capacity); //Expand the max threshold if necessary while(combined->capacity < finalSize){ resize(combined); } int i = 0, index = 0; //Going through the first vector and placing all of a.vectors value inside the combined vector for(i = 0; i < a->size; i++){ combined->arr[i] = a->arr[i]; } //retaining the last digit while going though the loop so we do not replace the already placed characters and start going through the next vector from the last position index = i; //Going through the second vector and placing all its values to the combined vector for(int i = 0; i < b->size; i++){ combined->arr[index + i] = b->arr[i]; } } //Takes a portion of the vector array from a starting index to the end index - 1 void slice(struct vector *sliced, struct vector *source, int start, int end){ //Initializing sliced->size = (end - start); sliced->capacity = 10; sliced->arr = (char*)malloc(sizeof(char)*sliced->capacity); while(sliced->capacity < sliced->size){ resize(sliced); } //Using start and end as reference for which part of the source array should be placed in the sliced array int i = 0; for(start, end, i; start <= end - 1; start++, i++){ //Using i for the sliced array //Incrementing start until it reaches end-1 sliced->arr[i] = source->arr[start]; } }
the_stack_data/87638042.c
#include <stdio.h> int main(){ float a, b; float somme; printf("Donnez la valeur de a\n"); scanf("%f", &a); printf("Donnez la valeur de b\n"); scanf("%f", &b); somme = a+b; printf("La somme de a et b vaut\n"); printf("%f", somme); return 0; }
the_stack_data/898844.c
/* * Copyright (c) 2014-2016 Alibaba Group. All rights reserved. * License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #ifdef CM_SUPPORT_LOCAL_CONN #include "iot_import.h" #include "lite-utils.h" #include "lite-system.h" #include "iot_export.h" #include "iotx_cm_common.h" #include "iotx_cm_local_conn.h" #include "iotx_cm_connection.h" #include "iotx_local_conn_alcs.h" typedef struct iotx_cm_local_device_list_st { iotx_cm_local_device_t* node; void* next; int is_used; } iotx_cm_local_device_list_t; static iotx_cm_local_device_list_t* g_local_device = NULL; #if 0 static iotx_cm_local_device_list_t iotx_cm_local_device_list[CM_SUPPORT_MAX_MAPPING_SIZE]; static int iotx_cm_local_conn_add_device(iotx_cm_local_device_t* device) { iotx_cm_local_device_list_t* device_list = NULL; iotx_cm_local_device_list_t* temp = NULL; int i = 0; if (NULL == device) { log_info("parameter error"); return FAIL_RETURN; } for (i = 0; i < CM_SUPPORT_MAX_MAPPING_SIZE; i++) { if (iotx_cm_local_device_list[i].is_used == 0) { iotx_cm_local_device_list[i].is_used = 1; device_list = &iotx_cm_local_device_list[i]; } } if (NULL == device_list) { return FAIL_RETURN; } device_list->node = device; if (NULL == g_local_device) { g_local_device = device_list; return SUCCESS_RETURN; } temp = g_local_device; while (temp->next) { temp = temp->next; } temp->next = device_list; return SUCCESS_RETURN; } /* remove */ static int iotx_cm_local_conn_remove_device(iotx_cm_local_device_t* device) { iotx_cm_local_device_list_t* temp = NULL; iotx_cm_local_device_list_t* pre_temp = NULL; if (NULL == g_local_device) { log_info("parameter error"); return FAIL_RETURN; } if (g_local_device->node == device) { temp = g_local_device; g_local_device = g_local_device->next; /* free */ LITE_free(temp->node->device_info); LITE_free(temp->node); temp->is_used = 0; memset(temp, 0x0, sizeof(iotx_cm_local_device_list_t)); return SUCCESS_RETURN; } pre_temp = g_local_device; temp = g_local_device->next; while (temp) { if (device == temp->node) { pre_temp->next = temp->next; /* free */ LITE_free(temp->node->device_info); LITE_free(temp->node); temp->is_used = 0; memset(temp, 0x0, sizeof(iotx_cm_local_device_list_t)); return SUCCESS_RETURN; } pre_temp = temp; temp = temp->next; } return FAIL_RETURN; } /* remove all */ static int iotx_cm_local_conn_remove_device_all() { int i = 0; for (i = 0; i < CM_SUPPORT_MAX_MAPPING_SIZE; i++) { if (iotx_cm_local_device_list[i].is_used == 1) { LITE_free(iotx_cm_local_device_list[i].node->device_info); LITE_free(iotx_cm_local_device_list[i].node); } } return SUCCESS_RETURN; } static int iotx_cm_local_compare_device(iotx_cm_send_peer_t* device_info_1, iotx_cm_send_peer_t* device_info_2) { if (NULL == device_info_1 || NULL == device_info_2) return -1; if (0 == strncmp(device_info_1->product_key, device_info_2->product_key, strlen(device_info_1->product_key)) && 0 == strncmp(device_info_1->device_name, device_info_2->device_name, strlen(device_info_1->device_name))) { return 0; } return -1; } /* find */ static iotx_cm_local_device_t* iotx_cm_local_conn_find_device(iotx_cm_send_peer_t* device_info) { iotx_cm_local_device_list_t* temp = NULL; if (NULL == g_local_device) { log_info("parameter error"); return NULL; } if (0 == iotx_cm_local_compare_device(g_local_device->node->device_info, device_info)) { return g_local_device->node; } temp = g_local_device->next; while (temp) { if (0 == iotx_cm_local_compare_device(temp->node->device_info, device_info)) { return temp->node; } temp = temp->next; } return NULL; } #endif static void iotx_local_conn_event_callback(void *pcontext, iotx_connection_event_msg_t* event_msg) { iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)pcontext; if (NULL == cm_ctx || NULL == event_msg) { CM_ERR(cm_log_error_parameter); return; } switch (event_msg->event_id) { case IOTX_CONNECTION_EVENT_DISCONNECT: #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL); if (NULL == node) return; node->type = IOTX_CM_PROCESS_LOCAL_DISCONNECT; node->msg = NULL; if (FAIL_RETURN == (ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node))) iotx_cm_free_list_node(cm_ctx, node); } #else iotx_cm_local_conn_disconnect_handler(cm_ctx); #endif /* CM_SUPPORT_MULTI_THREAD */ break; case IOTX_CONNECTION_EVENT_RECONNECT:{ #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL); if (NULL == node) return; node->type = IOTX_CM_PROCESS_LOCAL_RECONNECT; node->msg = NULL; if (FAIL_RETURN == (ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node))) iotx_cm_free_list_node(cm_ctx, node); } #else iotx_cm_local_conn_reconnect_handler(cm_ctx); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; #if 0 case IOTX_LOCAL_CONN_EVENT_ADD_DEVICE: { iotx_local_conn_device_event_t* msg = (iotx_local_conn_device_event_t*)event_msg->msg; iotx_cm_send_peer_t* device_info = NULL; iotx_cm_local_device_t* device = NULL; if (NULL == msg) return; CM_INFO(cm_log_info_add_device); device_info = LITE_malloc(sizeof(iotx_cm_event_device_t)); if (NULL == device_info) return; device = LITE_malloc(sizeof(iotx_cm_local_device_t)); if (NULL == device) { LITE_free(device_info); return; } memset(device_info, 0x0, sizeof(iotx_cm_event_device_t)); stretpy(device_info->product_key, msg->product_key); stretpy(device_info->device_name, msg->device_name); device->device_info = device_info; device->addr = msg->addr; #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL); if (NULL == node) return; node->type = IOTX_CM_PROCESS_LOCAL_ADD_DEVICE; node->msg = device; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) iotx_cm_free_list_node(cm_ctx, node); } #else iotx_cm_local_conn_found_device_handler(cm_ctx, device); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; case IOTX_LOCAL_CONN_EVENT_REMOVE_DEVICE: { iotx_local_conn_device_event_t* msg = (iotx_local_conn_device_event_t*)event_msg->msg; iotx_cm_send_peer_t* device_info = NULL; iotx_cm_local_device_t* device = NULL; if (NULL == msg) return; CM_INFO(cm_log_info_remove_device); device = LITE_malloc(sizeof(iotx_cm_local_device_t)); if (NULL == device) { LITE_free(device_info); return; } device->device_info = device_info; device->addr = msg->addr; #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL); if (NULL == node) return; node->type = IOTX_CM_PROCESS_LOCAL_REMOVE_DEVICE; node->msg = device; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) iotx_cm_free_list_node(cm_ctx, node); } #else iotx_cm_local_conn_remove_device_handler(cm_ctx, device); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; #endif default: break; } } static int iotx_cm_local_conn_response_callback(void* pcontext, iotx_connection_msg_rsp_t* msg) { iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)pcontext; if (NULL == cm_ctx || NULL == msg) { CM_ERR(cm_log_error_fail); return FAIL_RETURN; } CM_INFO(cm_log_info_rsp_type, msg->rsp_type); switch (msg->rsp_type) { case IOTX_CONNECTION_RESPONSE_ADD_SERVICE_SUCCESS: { #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_process_service_result_pt result_msg = NULL; if (NULL == (node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_CLOUD))) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_ADD_SERVICE_RESULT; node->msg = LITE_malloc(sizeof(iotx_cm_process_service_result_t)); if (NULL == node) { CM_ERR(cm_log_error_memory); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } result_msg = node->msg; result_msg->URI = LITE_malloc(strlen(msg->URI) + 1); if (NULL == result_msg->URI) { LITE_free(node->msg); LITE_free(node); return FAIL_RETURN; } memset(result_msg->URI, 0x0, strlen(msg->URI) + 1); strncpy(result_msg->URI, (msg->URI), strlen(msg->URI) + 1); result_msg->result = 0; result_msg->is_add = 1; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { LITE_free(result_msg->URI); LITE_free(node->msg); LITE_free(node); return FAIL_RETURN; } } #else return iotx_cm_local_conn_service_handler(cm_ctx, msg->URI, 0, 1); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; case IOTX_CONNECTION_RESPONSE_ADD_SERVICE_FAIL: { #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_process_service_result_pt result_msg = NULL; if (NULL == (node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL))) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_ADD_SERVICE_RESULT; node->msg = LITE_malloc(sizeof(iotx_cm_process_service_result_t)); if (NULL == node) { CM_ERR(cm_log_error_memory); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } result_msg = node->msg; result_msg->URI = LITE_malloc(strlen(msg->URI) + 1); if (NULL == result_msg->URI) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } memset(result_msg->URI, 0x0, strlen(msg->URI) + 1); strncpy(result_msg->URI, (msg->URI), strlen(msg->URI) + 1); result_msg->result = -1; result_msg->is_add = 1; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } } #else return iotx_cm_local_conn_service_handler(cm_ctx, msg->URI, -1, 1); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; case IOTX_CONNECTION_RESPONSE_REMOVE_SERVICE_SUCCESS: { #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_process_service_result_pt result_msg = NULL; if (NULL == (node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL))) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_REMOVE_SERVICE_RESULT; node->msg = LITE_malloc(sizeof(iotx_cm_process_service_result_t)); if (NULL == node) { CM_ERR(cm_log_error_memory); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } result_msg = node->msg; result_msg->URI = LITE_malloc(strlen(msg->URI) + 1); if (NULL == result_msg->URI) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } memset(result_msg->URI, 0x0, strlen(msg->URI) + 1); strncpy(result_msg->URI, (msg->URI), strlen(msg->URI) + 1); result_msg->result = 0; result_msg->is_add = 0; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } } #else return iotx_cm_local_conn_service_handler(cm_ctx, msg->URI, 0, 0); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; case IOTX_CONNECTION_RESPONSE_REMOVE_SERVICE_FAIL: { #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_process_service_result_pt result_msg = NULL; if (NULL == (node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL))) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_REMOVE_SERVICE_RESULT; node->msg = LITE_malloc(sizeof(iotx_cm_process_service_result_t)); if (NULL == node) { CM_ERR(cm_log_error_memory); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } result_msg = node->msg; result_msg->URI = LITE_malloc(strlen(msg->URI) + 1); if (NULL == result_msg->URI) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } memset(result_msg->URI, 0x0, strlen(msg->URI) + 1); strncpy(result_msg->URI, (msg->URI), strlen(msg->URI) + 1); result_msg->result = -1; result_msg->is_add = 0; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); } } #else return iotx_cm_local_conn_service_handler(cm_ctx, msg->URI, -1, 0); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; case IOTX_CONNECTION_RESPONSE_SEND_SUCCESS: case IOTX_CONNECTION_RESPONSE_SEND_FAIL: case IOTX_CONNECTION_RESPONSE_NEW_DATA: { #ifdef CM_SUPPORT_MULTI_THREAD { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_message_info_t* msg_info = NULL; #ifdef CM_SUPPORT_TOPIC_DISPATCH iotx_cm_mapping_t* mapping = NULL; #endif /* CM_SUPPORT_TOPIC_DISPATCH */ if (NULL == (node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL))) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_NEW_DATA; node->msg = LITE_malloc(sizeof(iotx_cm_message_info_t)); if (NULL == node->msg) { CM_ERR(cm_log_error_memory); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } msg_info = node->msg; msg_info->URI = LITE_malloc(msg->URI_length + 1); #if 0 if (NULL == msg_info->URI) { CM_ERR(cm_log_error_memory); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } if (FAIL_RETURN == iotx_cm_parse_URI((char*)msg->URI, msg->URI_length, msg_info->URI, &msg_info->URI_type)) { CM_ERR(cm_log_error_parse_URI); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } #endif if (msg_info->URI) { strncpy(msg_info->URI, msg->URI, msg->URI_length); } else { CM_ERR(cm_log_error_parse_URI); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } #ifdef CM_SUPPORT_TOPIC_DISPATCH /* find mapping */ mapping = iotx_cm_find_mapping(cm_ctx, (char*)msg->URI, msg->URI_length); if (NULL == mapping) { CM_WARNING(cm_log_warning_not_mapping); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } msg_info->message_type = mapping->type; #endif /* CM_SUPPORT_TOPIC_DISPATCH */ if (FAIL_RETURN == iotx_cm_parse_payload((char*)msg->payload, msg->payload_length, msg_info)) { CM_ERR(cm_log_error_parse_URI); iotx_cm_free_message_info(msg_info); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { iotx_cm_free_message_info(msg_info); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); break; } } #else iotx_cm_message_info_t message_info; #ifdef CM_SUPPORT_TOPIC_DISPATCH iotx_cm_mapping_t* mapping = NULL; #endif /* CM_SUPPORT_TOPIC_DISPATCH */ memset(&message_info, 0x0, sizeof(iotx_cm_message_info_t)); message_info.URI = LITE_malloc(msg->URI_length + 1); #if 0 if (NULL == message_info.URI) { CM_ERR(cm_log_error_memory); return FAIL_RETURN; } memset(message_info.URI, 0x0, msg->URI_length + 1); if (FAIL_RETURN == iotx_cm_parse_URI((char*)msg->URI, msg->URI_length, message_info.URI, &message_info.URI_type)) { CM_ERR(cm_log_error_parse_URI); iotx_cm_free_message_info(&message_info); return FAIL_RETURN; } #endif if (message_info.URI) { strncpy(message_info.URI, msg->URI, msg->URI_length); } else { iotx_cm_free_message_info(&message_info); return FAIL_RETURN; } #ifdef CM_SUPPORT_TOPIC_DISPATCH /* find mapping */ mapping = iotx_cm_find_mapping(cm_ctx, (char*)msg->URI, msg->URI_length); if (NULL == mapping) { CM_WARNING(cm_log_warning_not_mapping); iotx_cm_free_message_info(&message_info); return FAIL_RETURN; } message_info.message_type = mapping->type; #endif /* CM_SUPPORT_TOPIC_DISPATCH */ if (FAIL_RETURN == iotx_cm_parse_payload((char*)msg->payload, msg->payload_length, &message_info)) { CM_ERR(cm_log_error_parse_payload); iotx_cm_free_message_info(&message_info); return FAIL_RETURN; } message_info.conn_ctx = msg->conn_ctx; return iotx_cm_local_conn_response_handler(cm_ctx, &message_info); #endif /* CM_SUPPORT_MULTI_THREAD */ } break; default: CM_INFO(cm_log_warning_not_arrived); break; } return FAIL_RETURN; } int iotx_cm_local_conn_service_handler(iotx_cm_conntext_t* cm_ctx, char* URI, int result, int is_add) { iotx_cm_event_msg_t event; iotx_cm_event_result_t event_result = {0}; if (NULL == cm_ctx || NULL == URI) { CM_ERR(cm_log_error_parameter); return FAIL_RETURN; } event_result.result = result; event_result.URI = LITE_malloc(CM_TOPIC_LEN_MAX); #if 0 if (NULL == event_result.URI) { CM_ERR(cm_log_error_memory); return FAIL_RETURN; } memset(event_result.URI, 0x0, CM_TOPIC_LEN_MAX); if (FAIL_RETURN == iotx_cm_parse_URI((char*)URI, strlen(event_result.URI), event_result.URI, &event_result.URI_type)) { CM_ERR(cm_log_error_parse_URI); LITE_free(event_result.URI); return FAIL_RETURN; } #endif if (event_result.URI) { strncpy(event_result.URI, URI, CM_TOPIC_LEN_MAX); } else { return FAIL_RETURN; } event.event_id = is_add ? IOTX_CM_EVENT_ADD_SERVICE_RESULT : IOTX_CM_EVENT_REMOVE_SERVICE_RESULT; event.msg = (void*)&event_result; iotx_cm_trigger_event_callback(cm_ctx, &event); LITE_free(event_result.URI); return SUCCESS_RETURN; } int iotx_cm_local_conn_disconnect_handler(iotx_cm_conntext_t* cm_ctx) { iotx_cm_event_msg_t event; if (NULL == cm_ctx) { CM_ERR(cm_log_error_parameter); return FAIL_RETURN; } event.event_id = IOTX_CM_EVENT_LOCAL_DISCONNECT; event.msg = NULL; CM_INFO(cm_log_info_local_disconnect); iotx_cm_trigger_event_callback(cm_ctx, &event); return SUCCESS_RETURN; } int iotx_cm_local_conn_reconnect_handler(iotx_cm_conntext_t* cm_ctx) { iotx_cm_event_msg_t event; if (NULL == cm_ctx) { CM_ERR(cm_log_error_parameter); return FAIL_RETURN; } event.event_id = IOTX_CM_EVENT_LOCAL_RECONNECT; event.msg = NULL; CM_INFO(cm_log_info_local_reconnect); iotx_cm_trigger_event_callback(cm_ctx, &event); return SUCCESS_RETURN; } int iotx_cm_local_conn_found_device_handler(iotx_cm_conntext_t* cm_ctx, iotx_cm_local_device_t* device) { #if 0 iotx_cm_event_msg_t event; if (FAIL_RETURN == iotx_cm_local_conn_add_device(device)) { return FAIL_RETURN; } event.event_id = IOTX_CM_EVENT_FOUND_DEVICE; event.msg = device->device_info; CM_INFO(cm_log_info_found_device); iotx_cm_trigger_event_callback(cm_ctx, &event); #endif return SUCCESS_RETURN; } int iotx_cm_local_conn_remove_device_handler(iotx_cm_conntext_t* cm_ctx, iotx_cm_local_device_t* device) { #if 0 iotx_cm_event_msg_t event; if (FAIL_RETURN == iotx_cm_local_conn_remove_device(device)) { return FAIL_RETURN; } event.event_id = IOTX_CM_EVENT_REMOVE_DEVICE; event.msg = device->device_info; CM_INFO(cm_log_info_remove_device); iotx_cm_trigger_event_callback(cm_ctx, &event); #endif return SUCCESS_RETURN; } int iotx_cm_local_conn_response_handler(iotx_cm_conntext_t* cm_ctx, iotx_cm_message_info_t* message_info) { if (NULL == cm_ctx || NULL == message_info) { CM_ERR(cm_log_error_parameter); return FAIL_RETURN; } CM_INFO(cm_log_info_URI, (char*)message_info->URI); if (cm_ctx->response_func) cm_ctx->response_func(cm_ctx, message_info); return SUCCESS_RETURN; } int iotx_cm_local_conn_connect(void* handler, void* _connectivity) { iotx_cm_connectivity_t *connectivity = NULL; iotx_connection_t* connection = NULL; connectivity = (iotx_cm_connectivity_t *)_connectivity; connection = (iotx_connection_t*)connectivity->context; connection->context = connection->init_func(connection); if (connection->context) { connectivity->is_connected = 1; return SUCCESS_RETURN; } return FAIL_RETURN; } static void* _alcs_init(void* handler) { iotx_connection_t* connection = NULL; connection = CM_malloc(sizeof(iotx_connection_t)); if (NULL == connection) return NULL; connection->init_func = iotx_local_conn_alcs_init; connection->deinit_func = iotx_local_conn_alcs_deinit; connection->send_func = iotx_local_conn_alcs_send; connection->sub_func = NULL; connection->unsub_func = NULL; connection->add_service_func = iotx_local_conn_alcs_add_service; connection->remove_service_func = iotx_local_conn_alcs_remove_service; connection->yield_func = iotx_local_conn_alcs_yield; connection->protocol_type = IOTX_CONNECTION_PROTOCOL_TYPE_ALCS; connection->event_handler = iotx_local_conn_event_callback; connection->event_pcontext = handler; connection->response_handler = iotx_cm_local_conn_response_callback; g_local_device = CM_malloc(sizeof(iotx_cm_local_device_list_t)); memset(g_local_device, 0x0, sizeof(iotx_cm_local_device_list_t)); g_local_device->node = CM_malloc(sizeof(iotx_cm_local_device_t)); memset(g_local_device->node, 0x0, sizeof(iotx_cm_local_device_t)); g_local_device->node->device_info = CM_malloc(sizeof(iotx_cm_send_peer_t)); memset(g_local_device->node->device_info, 0x0, sizeof(iotx_cm_send_peer_t)); strcpy(g_local_device->node->device_info->device_name, "device_name"); strcpy(g_local_device->node->device_info->product_key, "product_key"); return connection; } void* iotx_cm_local_conn_init(void* handler, iotx_cm_init_param_t* pparam) { iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)handler; iotx_cm_connectivity_t* connectivity = NULL; iotx_connection_t* connection = NULL; if (NULL == cm_ctx || NULL == pparam) { CM_ERR(cm_log_error_parameter); return NULL; } connection = _alcs_init(cm_ctx); if (connection == NULL) return NULL; connectivity = LITE_malloc(sizeof(iotx_cm_connectivity_t)); if (NULL == connectivity) { CM_ERR(cm_log_error_memory); iotx_cm_local_conn_deinit(connectivity); return NULL; } connectivity->context = connection; #ifdef CM_SUPPORT_MULTI_THREAD #ifdef CM_SUPPORT_MULTI_THREAD_VIA_HAL HAL_ThreadCreate(&connectivity->pthread_process, iotx_cm_local_conn_process, cm_ctx, NULL, NULL); #else pthread_create(&connectivity->pthread_process, NULL, iotx_cm_local_conn_process, (void*)cm_ctx); #endif connectivity->process_lock = HAL_MutexCreate(); #endif /* CM_SUPPORT_MULTI_THREAD */ connectivity->init_func = iotx_cm_local_conn_init; connectivity->connect_func = iotx_cm_local_conn_connect; connectivity->register_func = iotx_cm_local_conn_register; connectivity->trigger_connected_func = iotx_cm_local_conn_trigger_connected; connectivity->unregister_func = iotx_cm_local_conn_unregister; connectivity->add_service_func = iotx_cm_local_conn_add_service; connectivity->remove_service_func = iotx_cm_local_conn_remove_service; connectivity->send_func = iotx_cm_local_conn_send; connectivity->send_sync_func = iotx_cm_local_conn_send_sync; connectivity->yield_func = iotx_cm_local_conn_yield; connectivity->deinit_func = iotx_cm_local_conn_deinit; connectivity->get_target_func = iotx_cm_local_conn_get_target; #ifdef CM_SUPPORT_MULTI_THREAD connectivity->add_send_func = iotx_cm_local_conn_add_send; connectivity->thread_process_func = iotx_cm_local_conn_process; #endif /* CM_SUPPORT_MULTI_THREAD */ connectivity->id = iotx_cm_get_connectivity_id(); connectivity->type = IOTX_CM_CONNECTIVITY_TYPE_LOCAL; return connectivity; } int iotx_cm_local_conn_trigger_connected(void* handler, void* _connectivity, iotx_cm_event_handle_fp_t event_fp, void* user_data) { iotx_cm_connectivity_t *connectivity = (iotx_cm_connectivity_t *)_connectivity; iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)handler; if (NULL == connectivity || NULL == cm_ctx) return FAIL_RETURN; if (0 == connectivity->is_connected && connectivity->connect_func) connectivity->connect_func(cm_ctx, connectivity); if (1 == connectivity->is_connected) { iotx_cm_event_msg_t event_msg = {0}; event_msg.event_id = IOTX_CM_EVENT_LOCAL_CONNECTED; event_msg.msg = (void*)connectivity->id; event_fp ? event_fp(cm_ctx, &event_msg, user_data) : iotx_cm_trigger_event_callback(cm_ctx, &event_msg); return SUCCESS_RETURN; } return FAIL_RETURN; } int iotx_cm_local_conn_register(void* handler, void* _connectivity, const char* topic_filter) { return SUCCESS_RETURN; } int iotx_cm_local_conn_unregister(void* handler, void* _connectivity, const char* topic_filter) { return SUCCESS_RETURN; } int iotx_cm_local_conn_add_service(void* handler, void* _connectivity, const char* topic_filter, iotx_cm_message_auth_types_t auth_type) { iotx_cm_connectivity_t *connectivity = (iotx_cm_connectivity_t *)_connectivity; iotx_connection_t* connection = NULL; connection = (iotx_connection_t*)connectivity->context; return connection->add_service_func(connection, topic_filter, IOTX_CM_MESSAGE_NEED_ACK, auth_type); } int iotx_cm_local_conn_remove_service(void* handler, void* _connectivity, const char* topic_filter) { iotx_cm_connectivity_t *connectivity = (iotx_cm_connectivity_t *)_connectivity; iotx_connection_t* connection = NULL; connection = (iotx_connection_t*)connectivity->context; return connection->remove_service_func(connection, topic_filter); } int iotx_cm_local_conn_send(void* handler, void* _connectivity, iotx_cm_send_peer_t* target, const char* topic_filter, iotx_cm_message_ack_types_t ack_type, const void* payload, int payload_length, void* context) { iotx_cm_connectivity_t* connectivity = (iotx_cm_connectivity_t*)_connectivity; iotx_connection_t* connection = NULL; iotx_connection_msg_t msg = {0}; connection = (iotx_connection_t*)connectivity->context; msg.type = IOTX_CONNECTION_MESSAGE_TYPE_SEND; msg.ack_type = ack_type; msg.URI = (char*)topic_filter; msg.URI_length = strlen(topic_filter); msg.payload = (char*)payload; msg.payload_length = payload_length; msg.response_handler = iotx_cm_local_conn_response_callback; msg.response_pcontext = handler; return connection->send_func(connection, context, &msg); } int iotx_cm_local_conn_send_sync(void* handler, void* _connectivity, iotx_cm_send_peer_t* target, const char* topic_filter, iotx_cm_message_ack_types_t ack_type, const void* payload, int payload_length, void* context) { return SUCCESS_RETURN; } int iotx_cm_local_conn_yield(void* _connectivity, int timeout_ms) { iotx_cm_connectivity_t *connectivity = (iotx_cm_connectivity_t *)_connectivity; iotx_connection_t* connection = NULL; connection = (iotx_connection_t*)connectivity->context; return connection->yield_func(connection, timeout_ms); } int iotx_cm_local_conn_deinit(void* _connectivity) { int ret; iotx_cm_connectivity_t *connectivity = (iotx_cm_connectivity_t *)_connectivity; iotx_connection_t* connection = NULL; connection = (iotx_connection_t*)connectivity->context; if(g_local_device->node->device_info) LITE_free(g_local_device->node->device_info); if(g_local_device->node) LITE_free(g_local_device->node); if(g_local_device) LITE_free(g_local_device); ret = connection->deinit_func(connection); LITE_free(connection); connectivity->context = NULL; return ret; } iotx_cm_send_peer_t* iotx_cm_local_conn_get_target() { if (g_local_device == NULL) return NULL; return g_local_device->node->device_info; } #ifdef CM_SUPPORT_MULTI_THREAD int iotx_cm_local_conn_add_send(void* handler, iotx_cm_send_peer_t* target, iotx_cm_message_info_t* message_info) { /* send message to itself thread */ int ret = 0; iotx_cm_process_list_node_t* node = NULL; iotx_cm_process_send_pt msg = NULL; char* URI; void* payload; int payload_length = 0; iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)handler; node = iotx_cm_get_list_node(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL); if (NULL == node) return FAIL_RETURN; node->type = IOTX_CM_PROCESS_LOCAL_SEND; node->msg = LITE_malloc(sizeof(iotx_cm_process_send_t)); if (NULL == node->msg) { CM_INFO(cm_log_error_parameter); iotx_cm_free_list_node(cm_ctx, node); return FAIL_RETURN; } msg = node->msg; if (target) { msg->target = LITE_malloc(sizeof(iotx_cm_send_peer_t)); memset(msg->target, 0x0, sizeof(iotx_cm_send_peer_t)); strncpy(msg->target->device_name, target->device_name, strlen(target->device_name)); strncpy(msg->target->product_key, target->product_key, strlen(target->product_key)); } else { msg->target = NULL; } if (FAIL_RETURN == iotx_cm_parse_message(cm_ctx, message_info, &URI, &payload, &payload_length)) { CM_INFO(cm_log_error_parameter); iotx_cm_free_list_node(cm_ctx, node); if (msg->target) LITE_free(msg->target); return FAIL_RETURN; } msg->URI = URI; msg->ack_type = message_info->ack_type; msg->payload = payload; msg->payload_length = payload_length; msg->conn_ctx = message_info->conn_ctx; ret = iotx_cm_process_list_push(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL, node); if (FAIL_RETURN == ret) { if (msg->target) LITE_free(msg->target); LITE_free(msg->URI); LITE_free(msg->payload); LITE_free(node->msg); iotx_cm_free_list_node(cm_ctx, node); } return ret; } void* iotx_cm_local_conn_process(void *pclient) { iotx_cm_conntext_t* cm_ctx = (iotx_cm_conntext_t*)pclient; iotx_cm_connectivity_t* connectivity = iotx_cm_find_connectivity(cm_ctx, iotx_cm_local_conn_get_target(), NULL); if (NULL == cm_ctx) { CM_INFO(cm_log_error_parameter); return NULL; } log_info("enter cloud process"); while (!cm_ctx->thread_stop) { if (NULL == connectivity) { HAL_SleepMs(1000); connectivity = iotx_cm_find_connectivity(cm_ctx, iotx_cm_local_conn_get_target(), NULL); continue; } if (0 == connectivity->is_connected) { connectivity->trigger_connected_func(cm_ctx, connectivity, NULL, NULL); continue; } if (iotx_cm_process_list_get_size(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL) > 0) { iotx_cm_process_list_node_t* node = NULL; if (NULL != (node = iotx_cm_process_list_pop(cm_ctx, IOTX_CM_CONNECTIVITY_TYPE_LOCAL))) { log_info("process %d", node->type); switch(node->type) { case IOTX_CM_PROCESS_LOCAL_ADD_DEVICE: { iotx_cm_local_device_t* device = (iotx_cm_local_device_t*)node->msg; iotx_cm_local_conn_found_device_handler(cm_ctx, device); } break; case IOTX_CM_PROCESS_LOCAL_REMOVE_DEVICE: { iotx_cm_local_device_t* device = (iotx_cm_local_device_t*)node->msg; iotx_cm_local_conn_remove_device_handler(cm_ctx, device); } break; case IOTX_CM_PROCESS_LOCAL_SEND: { iotx_cm_process_send_pt send_pt = (iotx_cm_process_send_pt)node->msg; if (FAIL_RETURN == iotx_cm_send_data(cm_ctx, send_pt->target, iotx_cm_find_connectivity(cm_ctx, iotx_cm_local_conn_get_target(), send_pt->conn_ctx), send_pt->URI, send_pt->ack_type, send_pt->payload, send_pt->payload_length, send_pt->conn_ctx)) { log_info("send fail"); } if (send_pt->target) LITE_free(send_pt->target); LITE_free(send_pt); } break; case IOTX_CM_PROCESS_LOCAL_DISCONNECT: { iotx_cm_local_conn_disconnect_handler(cm_ctx); } break; case IOTX_CM_PROCESS_LOCAL_RECONNECT: { iotx_cm_local_conn_reconnect_handler(cm_ctx); } break; case IOTX_CM_PROCESS_LOCAL_ADD_SERVICE: { iotx_cm_process_service_t* service_pt = (iotx_cm_process_service_t*)node->msg; if (FAIL_RETURN == iotx_cm_add_service(cm_ctx, service_pt->URI, service_pt->type, service_pt->auth_type, service_pt->register_func, service_pt->user_data, service_pt->mail_box)) { log_info("add service fail"); } LITE_free(service_pt->URI); LITE_free(service_pt); } break; case IOTX_CM_PROCESS_LOCAL_REMOVE_SERVICE: { char* URI = (char*)node->msg; if (FAIL_RETURN == iotx_cm_remove_service(cm_ctx, URI)) { log_info("unregister fail"); } LITE_free(URI); } break; case IOTX_CM_PROCESS_LOCAL_ADD_SERVICE_RESULT: case IOTX_CM_PROCESS_LOCAL_REMOVE_SERVICE_RESULT: { iotx_cm_process_service_result_pt service_pt = (iotx_cm_process_service_result_pt)node->msg; iotx_cm_local_conn_service_handler(cm_ctx, service_pt->URI, service_pt->result, service_pt->is_add); LITE_free(service_pt->URI); LITE_free(service_pt); } break; case IOTX_CM_PROCESS_LOCAL_NEW_DATA: { iotx_cm_message_info_t* message_info = (iotx_cm_message_info_t*)node->msg; iotx_cm_local_conn_response_handler(cm_ctx, message_info); LITE_free(node->msg); break; } default: break; } iotx_cm_free_list_node(cm_ctx, node); } /* local yield */ connectivity->yield_func(connectivity, 200); } else { /* local yield */ connectivity->yield_func(connectivity, 200); } } return NULL; } #endif /* CM_SUPPORT_MULTI_THREAD */ #endif /* CM_SUPPORT_LOCAL_CONN */
the_stack_data/991831.c
#include <stdio.h> int main (void) { double A, B, MAX; scanf("%lf", &A); scanf("%lf", &B); MAX = ((A*0.35) + (B*0.75))/11 *10; printf("MEDIA = %.5lf\n", MAX); return 0; }
the_stack_data/165767942.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_lowercase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: llima-ce <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/07/19 16:03:31 by llima-ce #+# #+# */ /* Updated: 2021/07/21 00:52:38 by llima-ce ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> int ft_str_is_lowercase(char *str) { while (*str != '\0') { if (!('z' >= *str && *str >= 'a')) { return (0); } str++; } return (1); }
the_stack_data/231393604.c
// Test strict_string_checks option in strtoll function // RUN: %clang_asan %s -o %t // RUN: %run %t test1 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1 // RUN: %run %t test2 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2 // RUN: %run %t test3 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 // RUN: %run %t test4 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test4 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4 // RUN: %run %t test5 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test5 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5 // RUN: %run %t test6 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test6 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6 // RUN: %run %t test7 2>&1 // RUN: %env_asan_opts=strict_string_checks=false %run %t test7 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7 // FIXME: Enable strtoll interceptor. // REQUIRES: shadow-scale-3 // XFAIL: windows-msvc #include <assert.h> #include <stdlib.h> #include <string.h> #include <sanitizer/asan_interface.h> void test1(char *array, char *endptr) { // Buffer overflow if there is no terminating null (depends on base) long long r = strtoll(array, &endptr, 3); assert(array + 2 == endptr); assert(r == 5); } void test2(char *array, char *endptr) { // Buffer overflow if there is no terminating null (depends on base) array[2] = 'z'; long long r = strtoll(array, &endptr, 35); assert(array + 2 == endptr); assert(r == 37); } void test3(char *array, char *endptr) { // Buffer overflow if base is invalid. memset(array, 0, 8); ASAN_POISON_MEMORY_REGION(array, 8); long long r = strtoll(array + 1, NULL, -1); assert(r == 0); ASAN_UNPOISON_MEMORY_REGION(array, 8); } void test4(char *array, char *endptr) { // Buffer overflow if base is invalid. long long r = strtoll(array + 3, NULL, 1); assert(r == 0); } void test5(char *array, char *endptr) { // Overflow if no digits are found. array[0] = ' '; array[1] = '+'; array[2] = '-'; long long r = strtoll(array, NULL, 0); assert(r == 0); } void test6(char *array, char *endptr) { // Overflow if no digits are found. array[0] = ' '; array[1] = array[2] = 'z'; long long r = strtoll(array, &endptr, 0); assert(array == endptr); assert(r == 0); } void test7(char *array, char *endptr) { // Overflow if no digits are found. array[2] = 'z'; long long r = strtoll(array + 2, NULL, 0); assert(r == 0); } int main(int argc, char **argv) { char *array0 = (char*)malloc(11); char* array = array0 + 8; char *endptr = NULL; array[0] = '1'; array[1] = '2'; array[2] = '3'; if (argc != 2) return 1; if (!strcmp(argv[1], "test1")) test1(array, endptr); // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK1: READ of size 4 if (!strcmp(argv[1], "test2")) test2(array, endptr); // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK2: READ of size 4 if (!strcmp(argv[1], "test3")) test3(array0, endptr); // CHECK3: {{.*ERROR: AddressSanitizer: use-after-poison on address}} // CHECK3: READ of size 1 if (!strcmp(argv[1], "test4")) test4(array, endptr); // CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK4: READ of size 1 if (!strcmp(argv[1], "test5")) test5(array, endptr); // CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK5: READ of size 4 if (!strcmp(argv[1], "test6")) test6(array, endptr); // CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK6: READ of size 4 if (!strcmp(argv[1], "test7")) test7(array, endptr); // CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK7: READ of size 2 free(array0); return 0; }
the_stack_data/104414.c
#include <stdio.h> #define NPERLINE 10 main() { short line[2][NPERLINE]; register int n, i, j; register int curline = 0; int currently_printing = 1; for(i = 0; (n = fread(line[curline], sizeof(short), NPERLINE, stdin)) > 0; i += n, curline = 1-curline) { if(i != 0 && n == NPERLINE && sameline(line[0], line[1])) { if(currently_printing) { printf("*\n"); currently_printing = 0; } continue; } currently_printing = 1; printf("%7d ", i); for(j = 0; j < n; j++) printf("%6d ", line[curline][j]); printf("\n"); } printf("%4d\n", i); } sameline(l1, l2) register short *l1, *l2; { register n = NPERLINE; while(--n >= 0) if(*l1++ != *l2++) return 0; return 1; }
the_stack_data/123352.c
// // Created by 吴超 on 2020/7/11. // #include <stdlib.h> struct ListNode { int val; struct ListNode *next; }; struct ListNode *removeElements(struct ListNode *head, int val) { struct ListNode* prev = malloc(sizeof(struct ListNode)); prev->val = -1; prev->next = head; struct ListNode* current = head; struct ListNode* newHead = head; while(current!=NULL){ if(current->val == val){ if(current == newHead){ newHead = newHead->next; } prev->next = current->next; }else{ prev = prev->next; } current = current->next; } return newHead; }
the_stack_data/646348.c
// Replace this file with the Solution for Project Euler Problem #089 // Project Euler Problem: #089 // Repository Maintainer: https://www.github.com/theSwapnilSaste // File Creation Date : 14th March 2020 // Solution Author : **** Insert Your Name/Github Handle Here *** // Solution added on : **** Insert Date here **** // Problem Status : Complete/Incomplete/Need Improvement etc. // Space for Notes // . // .
the_stack_data/149443.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2013-2019 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ void pendfunc1 (int x) { int y = x + 4; } void pendfunc (int x) { pendfunc1 (x); }
the_stack_data/9512746.c
#include <stdlib.h> char *mx_strnew(const int size) { char *str = NULL; str = (char*) malloc(sizeof(char) * (size + 1)); if(!str) return NULL; for (int i = 0; i < size + 1; i++) str[i] = '\0'; return str; }
the_stack_data/76699837.c
#include <stdio.h> int main(void) { char ch[1024]; int count = 0; int i; while ((ch[count++] = getchar()) != '#') ; for (i = 0; i < count; i++) { printf("%d ", ch[i]); if (!(i % 8)) putchar('\n'); } return 0; }
the_stack_data/28838.c
void kernel_start() { char * video_memory = (char *) 0xb8000; *video_memory = 'X'; }
the_stack_data/111077135.c
/* * Copyright 2016-2017, Intel Corporation * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * check-license.c -- check the license in the file */ #include <assert.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <ctype.h> #define LICENSE_MAX_LEN 2048 #define COPYRIGHT "Copyright " #define COPYRIGHT_LEN 10 #define COPYRIGHT_SYMBOL "(c) " #define COPYRIGHT_SYMBOL_LEN 4 #define YEAR_MIN 1900 #define YEAR_MAX 9999 #define YEAR_INIT_MIN 9999 #define YEAR_INIT_MAX 0 #define YEAR_LEN 4 #define LICENSE_BEG "Redistribution and use" #define LICENSE_END "THE POSSIBILITY OF SUCH DAMAGE." #define DIFF_LEN 50 #define COMMENT_STR_LEN 5 #define STR_MODE_CREATE "create" #define STR_MODE_PATTERN "check-pattern" #define STR_MODE_LICENSE "check-license" #define ERROR(fmt, ...) fprintf(stderr, "error: " fmt "\n", __VA_ARGS__) #define ERROR2(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__) /* * help_str -- string for the help message */ static const char *help_str = "Usage: %s <mode> <file_1> <file_2> [filename]\n" "\n" "Modes:\n" " create <file_license> <file_pattern>\n" " - create a license pattern file <file_pattern>\n" " from the license text file <file_license>\n" "\n" " check-pattern <file_pattern> <file_to_check>\n" " - check if a license in <file_to_check>\n" " matches the license pattern in <file_pattern>,\n" " if it does, copyright dates are printed out (see below)\n" "\n" " check-license <file_license> <file_to_check>\n" " - check if a license in <file_to_check>\n" " matches the license text in <file_license>,\n" " if it does, copyright dates are printed out (see below)\n" "\n" "In case of 'check_pattern' and 'check_license' modes,\n" "if the license is correct, it prints out copyright dates\n" "in the following format: OLDEST_YEAR-NEWEST_YEAR\n" "\n" "Return value: returns 0 on success and -1 on error.\n" "\n"; /* * read_pattern -- read the pattern from the 'path_pattern' file to 'pattern' */ static int read_pattern(const char *path_pattern, char *pattern) { int file_pattern; ssize_t ret; if ((file_pattern = open(path_pattern, O_RDONLY)) == -1) { ERROR("open(): %s: %s", strerror(errno), path_pattern); return -1; } ret = read(file_pattern, pattern, LICENSE_MAX_LEN); close(file_pattern); if (ret == -1) { ERROR("read(): %s: %s", strerror(errno), path_pattern); return -1; } else if (ret != LICENSE_MAX_LEN) { ERROR( "read(): incorrect format of the license pattern file (%s)", path_pattern); return -1; } return 0; } /* * write_pattern -- write 'pattern' to the 'path_pattern' file */ static int write_pattern(const char *path_pattern, char *pattern) { int file_pattern; ssize_t ret; if ((file_pattern = open(path_pattern, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IRGRP | S_IROTH)) == -1) { ERROR("open(): %s: %s", strerror(errno), path_pattern); return -1; } ret = write(file_pattern, pattern, LICENSE_MAX_LEN); close(file_pattern); if (ret < LICENSE_MAX_LEN) { ERROR("write(): %s: %s", strerror(errno), path_pattern); return -1; } return 0; } /* * strstr2 -- locate two substrings in the string */ static int strstr2(const char *str, const char *sub1, const char *sub2, char **pos1, char **pos2) { *pos1 = strstr(str, sub1); *pos2 = strstr(str, sub2); if (*pos1 == NULL || *pos2 == NULL) return -1; return 0; } /* * format_license -- remove comments and redundant whitespaces from the license */ static void format_license(char *license, size_t length) { char comment_str[COMMENT_STR_LEN]; char *comment = license; size_t comment_len; int was_space; size_t w, r; /* detect a comment string */ while (*comment != '\n') comment--; /* is there any comment? */ if (comment + 1 != license) { /* separate out a comment */ strncpy(comment_str, comment, COMMENT_STR_LEN); comment = comment_str + 1; while (isspace(*comment)) comment++; while (!isspace(*comment)) comment++; *comment = '\0'; comment_len = strlen(comment_str); /* replace comments with spaces */ if (comment_len > 2) { while ((comment = strstr(license, comment_str)) != NULL) for (w = 1; w < comment_len; w++) comment[w] = ' '; } else { while ((comment = strstr(license, comment_str)) != NULL) comment[1] = ' '; } } /* replace multiple spaces with one space */ was_space = 0; for (r = w = 0; r < length; r++) { if (!isspace(license[r])) { if (was_space) { license[w++] = ' '; was_space = 0; } if (w < r) license[w] = license[r]; w++; } else { if (!was_space) was_space = 1; } } license[w] = '\0'; } /* * analyze_license -- check correctness of the license */ static int analyze_license(const char *path_to_check, char *buffer, char **license) { char *_license; size_t _length; char *beg_str, *end_str; if (strstr2(buffer, LICENSE_BEG, LICENSE_END, &beg_str, &end_str)) { if (!beg_str) ERROR2( "%s:1: error: incorrect license (license should start with the string '%s')", path_to_check, LICENSE_BEG); else ERROR2( "%s:1: error: incorrect license (license should end with the string '%s')", path_to_check, LICENSE_END); return -1; } _license = beg_str; assert((uintptr_t)end_str > (uintptr_t)beg_str); _length = (size_t)(end_str - beg_str) + strlen(LICENSE_END); _license[_length] = '\0'; format_license(_license, _length); *license = _license; return 0; } /* * create_pattern -- create 'pattern' from the 'path_license' file */ static int create_pattern(const char *path_license, char *pattern) { char buffer[LICENSE_MAX_LEN]; char *license; ssize_t ret; int file_license; if ((file_license = open(path_license, O_RDONLY)) == -1) { ERROR("open(): %s: %s", strerror(errno), path_license); return -1; } memset(buffer, 0, sizeof(buffer)); ret = read(file_license, buffer, LICENSE_MAX_LEN); close(file_license); if (ret == -1) { ERROR("read(): %s: %s", strerror(errno), path_license); return -1; } if (analyze_license(path_license, buffer, &license) == -1) return -1; memset(pattern, 0, LICENSE_MAX_LEN); strncpy(pattern, license, strlen(license) + 1); return 0; } /* * print_diff -- print the first difference between 'license' and 'pattern' */ static void print_diff(char *license, char *pattern, size_t len) { size_t i = 0; while (i < len && license[i] == pattern[i]) i++; license[i + 1] = '\0'; pattern[i + 1] = '\0'; i = (i - DIFF_LEN > 0) ? (i - DIFF_LEN) : 0; while (i > 0 && license[i] != ' ') i--; fprintf(stderr, " The first difference is at the end of the line:\n"); fprintf(stderr, " * License: %s\n", license + i); fprintf(stderr, " * Pattern: %s\n", pattern + i); } /* * verify_license -- compare 'license' with 'pattern' and check correctness * of the copyright line */ static int verify_license(const char *path_to_check, char *pattern, const char *filename) { char buffer[LICENSE_MAX_LEN]; char *license, *copyright; int file_to_check; ssize_t ret; int year_first, year_last; int min_year_first = YEAR_INIT_MIN; int max_year_last = YEAR_INIT_MAX; char *err_str = NULL; const char *name_to_print = filename ? filename : path_to_check; if ((file_to_check = open(path_to_check, O_RDONLY)) == -1) { ERROR("open(): %s: %s", strerror(errno), path_to_check); return -1; } memset(buffer, 0, sizeof(buffer)); ret = read(file_to_check, buffer, LICENSE_MAX_LEN); close(file_to_check); if (ret == -1) { ERROR("read(): %s: %s", strerror(errno), name_to_print); return -1; } if (analyze_license(path_to_check, buffer, &license) == -1) return -1; /* check the copyright notice */ copyright = buffer; while ((copyright = strstr(copyright, COPYRIGHT)) != NULL) { copyright += COPYRIGHT_LEN; /* skip the copyright symbol '(c)' if any */ if (strncmp(copyright, COPYRIGHT_SYMBOL, COPYRIGHT_SYMBOL_LEN) == 0) copyright += COPYRIGHT_SYMBOL_LEN; /* look for the first year */ if (!isdigit(*copyright)) { err_str = "no digit just after the 'Copyright ' string"; break; } year_first = atoi(copyright); if (year_first < YEAR_MIN || year_first > YEAR_MAX) { err_str = "the first year is wrong"; break; } copyright += YEAR_LEN; if (year_first < min_year_first) min_year_first = year_first; if (year_first > max_year_last) max_year_last = year_first; /* check if there is the second year */ if (*copyright == ',') continue; else if (*copyright != '-') { err_str = "'-' or ',' expected after the first year"; break; } copyright++; /* look for the second year */ if (!isdigit(*copyright)) { err_str = "no digit after '-'"; break; } year_last = atoi(copyright); if (year_last < YEAR_MIN || year_last > YEAR_MAX) { err_str = "the second year is wrong"; break; } copyright += YEAR_LEN; if (year_last > max_year_last) max_year_last = year_last; if (*copyright != ',') { err_str = "',' expected after the second year"; break; } } if (!err_str && min_year_first == YEAR_INIT_MIN) err_str = "no 'Copyright ' string found"; if (err_str) /* found an error in the copyright notice */ ERROR2("%s:1: error: incorrect copyright notice: %s", name_to_print, err_str); /* now check the license */ if (memcmp(license, pattern, strlen(pattern)) != 0) { ERROR2("%s:1: error: incorrect license", name_to_print); print_diff(license, pattern, strlen(pattern)); return -1; } if (err_str) return -1; /* all checks passed */ if (min_year_first != max_year_last && max_year_last != YEAR_INIT_MAX) { printf("%i-%i\n", min_year_first, max_year_last); } else { printf("%i\n", min_year_first); } return 0; } /* * mode_create_pattern_file -- 'create' mode function */ static int mode_create_pattern_file(const char *path_license, const char *path_pattern) { char pattern[LICENSE_MAX_LEN]; if (create_pattern(path_license, pattern) == -1) return -1; return write_pattern(path_pattern, pattern); } /* * mode_check_pattern -- 'check_pattern' mode function */ static int mode_check_pattern(const char *path_license, const char *path_to_check) { char pattern[LICENSE_MAX_LEN]; if (create_pattern(path_license, pattern) == -1) return -1; return verify_license(path_to_check, pattern, NULL); } /* * mode_check_license -- 'check_license' mode function */ static int mode_check_license(const char *path_pattern, const char *path_to_check, const char *filename) { char pattern[LICENSE_MAX_LEN]; if (read_pattern(path_pattern, pattern) == -1) return -1; return verify_license(path_to_check, pattern, filename); } int main(int argc, char *argv[]) { if (strcmp(argv[1], STR_MODE_CREATE) == 0) { if (argc != 4) goto invalid_args; return mode_create_pattern_file(argv[2], argv[3]); } else if (strcmp(argv[1], STR_MODE_PATTERN) == 0) { if (argc != 5) goto invalid_args; return mode_check_license(argv[2], argv[3], argv[4]); } else if (strcmp(argv[1], STR_MODE_LICENSE) == 0) { if (argc != 4) goto invalid_args; return mode_check_pattern(argv[2], argv[3]); } else { ERROR("wrong mode: %s\n", argv[1]); } invalid_args: printf(help_str, argv[0]); return -1; }
the_stack_data/165764799.c
/* $Id: mkspans.c,v 1.4 2010-03-10 18:56:48 bfriesen Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler * Copyright (c) 1991-1997 Silicon Graphics, Inc. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation for any purpose is hereby granted without fee, provided * that (i) the above copyright notices and this permission notice appear in * all copies of the software and related documentation, and (ii) the names of * Sam Leffler and Silicon Graphics may not be used in any advertising or * publicity relating to the software without the specific, prior written * permission of Sam Leffler and Silicon Graphics. * * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. */ #include <string.h> #include <stdio.h> /* * Hack program to construct tables used to find * runs of zeros and ones in Group 3 Fax encoding. */ dumparray(name, runs) char *name; unsigned char runs[256]; { int i; char *sep; printf("static unsigned char %s[256] = {\n", name); sep = " "; for (i = 0; i < 256; i++) { printf("%s%d", sep, runs[i]); if (((i + 1) % 16) == 0) { printf(", /* 0x%02x - 0x%02x */\n", i-15, i); sep = " "; } else sep = ", "; } printf("\n};\n"); } main() { unsigned char runs[2][256]; memset(runs[0], 0, 256*sizeof (char)); memset(runs[1], 0, 256*sizeof (char)); { register int run, runlen, i; runlen = 1; for (run = 0x80; run != 0xff; run = (run>>1)|0x80) { for (i = run-1; i >= 0; i--) { runs[1][run|i] = runlen; runs[0][(~(run|i)) & 0xff] = runlen; } runlen++; } runs[1][0xff] = runs[0][0] = 8; } dumparray("bruns", runs[0]); dumparray("wruns", runs[1]); } /* vim: set ts=8 sts=8 sw=8 noet: */ /* * Local Variables: * mode: c * c-basic-offset: 8 * fill-column: 78 * End: */
the_stack_data/308599.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern float strtof(char const *str , char const *endptr ) ; extern void signal(int sig , void *func ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned long input[1] , unsigned long output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; int main(int argc , char *argv[] ) { unsigned long input[1] ; unsigned long output[1] ; int randomFuns_i5 ; unsigned long randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 4242424242UL) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%lu\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned long input[1] , unsigned long output[1] ) { unsigned long state[1] ; unsigned long local1 ; { state[0UL] = (input[0UL] & 914778474UL) << 7UL; local1 = 0UL; while (local1 < 1UL) { state[0UL] &= state[local1]; local1 ++; } output[0UL] = state[0UL] & 690137161UL; } } void megaInit(void) { { } }
the_stack_data/106947.c
#include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <unistd.h> int main() { pid_t pid; /* 새로운 자식을 fork 한다. */ pid = fork(); if (pid < 0) { /* 에러가 발생한 경우 */ fprintf(stderr, "Fork failed"); return 1; }else if(pid == 0) { /* 자식 프로세스 */ printf("================================\n"); printf("CHILD: ls command\n"); execlp("/bin/ls","ls",NULL); printf("/'execlp/' call was unsuccessful\n"); /* 해당 줄의 코드는 출력되지 않는다. 왜? */ }else { /* 부모 프로세스 */ /* parent will wait for the child to complete */ wait(NULL); printf("--------------------------------\n"); printf("PARENT: Child Complete\n"); printf("--------------------------------\n"); } return 0; }
the_stack_data/1137792.c
#include <wchar.h> int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) { for (; n && *l==*r; n--, l++, r++); return n ? *l-*r : 0; }
the_stack_data/14199837.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlenw.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mburson <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 22:33:35 by mburson #+# #+# */ /* Updated: 2017/01/11 22:33:37 by mburson ### ########.fr */ /* */ /* ************************************************************************** */ #include <wchar.h> #include <string.h> /* ** finds the number of characters in a wide character string */ size_t ft_strlenw(const wchar_t *str) { size_t length; length = 0; while (*str) { str++; length++; } return (length); }
the_stack_data/165765411.c
// general protection fault in ebitmap_destroy // https://syzkaller.appspot.com/bug?id=72040bb854581b881b69be2e9dac5ddc8eaa8256 // status:open // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <dirent.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <pthread.h> #include <sched.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/futex.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); if (pthread_create(&th, &attr, fn, arg)) exit(1); pthread_attr_destroy(&attr); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static struct { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; } nlmsg; static void netlink_init(int typ, int flags, const void* data, int size) { memset(&nlmsg, 0, sizeof(nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg.pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(int typ) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_type = typ; nlmsg.pos += sizeof(*attr); nlmsg.nested[nlmsg.nesting++] = attr; } static void netlink_done(void) { struct nlattr* attr = nlmsg.nested[--nlmsg.nesting]; attr->nla_len = nlmsg.pos - (char*)attr; } static int netlink_send(int sock) { if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_len = nlmsg.pos - nlmsg.buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0); if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static void netlink_add_device_impl(const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(IFLA_IFNAME, name, strlen(name)); netlink_nest(IFLA_LINKINFO); netlink_attr(IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(int sock, const char* type, const char* name) { netlink_add_device_impl(type, name); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_veth(int sock, const char* name, const char* peer) { netlink_add_device_impl("veth", name); netlink_nest(IFLA_INFO_DATA); netlink_nest(VETH_INFO_PEER); nlmsg.pos += sizeof(struct ifinfomsg); netlink_attr(IFLA_IFNAME, peer, strlen(peer)); netlink_done(); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_hsr(int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl("hsr", name); netlink_nest(IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_device_change(int sock, const char* name, bool up, const char* master, const void* mac, int macsize) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr)); netlink_attr(IFLA_IFNAME, name, strlen(name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(IFLA_ADDRESS, mac, macsize); int err = netlink_send(sock); (void)err; } static int netlink_add_addr(int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(IFA_LOCAL, addr, addrsize); netlink_attr(IFA_ADDRESS, addr, addrsize); return netlink_send(sock); } static void netlink_add_addr4(int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC 0x00aaaaaaaaaa static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, }; const char* devmasters[] = {"bridge", "bond", "team"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(sock, slave0, false, master, 0, 0); netlink_device_change(sock, slave1, false, master, 0, 0); } netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0); netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0); netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0); netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(sock, devices[i].name, true, 0, &macaddr, devices[i].macsize); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02hx:%02hx", i, (int)procid + 1); netlink_add_addr6(sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize); } close(sock); } #define XT_TABLE_SIZE 1536 #define XT_MAX_ENTRIES 10 struct xt_counters { uint64_t pcnt, bcnt; }; struct ipt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_entries; unsigned int size; }; struct ipt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct ipt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct ipt_table_desc { const char* name; struct ipt_getinfo info; struct ipt_replace replace; }; static struct ipt_table_desc ipv4_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; static struct ipt_table_desc ipv6_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; #define IPT_BASE_CTL 64 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) #define IPT_SO_GET_INFO (IPT_BASE_CTL) #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) struct arpt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_entries; unsigned int size; }; struct arpt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct arpt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct arpt_table_desc { const char* name; struct arpt_getinfo info; struct arpt_replace replace; }; static struct arpt_table_desc arpt_tables[] = { {.name = "filter"}, }; #define ARPT_BASE_CTL 96 #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL) #define ARPT_SO_GET_INFO (ARPT_BASE_CTL) #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1) static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct ipt_get_entries entries; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct xt_counters counters[XT_MAX_ENTRIES]; struct ipt_get_entries entries; struct ipt_getinfo info; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_arptables(void) { struct arpt_get_entries entries; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_arptables() { struct xt_counters counters[XT_MAX_ENTRIES]; struct arpt_get_entries entries; struct arpt_getinfo info; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } else { } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } #define NF_BR_NUMHOOKS 6 #define EBT_TABLE_MAXNAMELEN 32 #define EBT_CHAIN_MAXNAMELEN 32 #define EBT_BASE_CTL 128 #define EBT_SO_SET_ENTRIES (EBT_BASE_CTL) #define EBT_SO_GET_INFO (EBT_BASE_CTL) #define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1) #define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1) #define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1) struct ebt_replace { char name[EBT_TABLE_MAXNAMELEN]; unsigned int valid_hooks; unsigned int nentries; unsigned int entries_size; struct ebt_entries* hook_entry[NF_BR_NUMHOOKS]; unsigned int num_counters; struct ebt_counter* counters; char* entries; }; struct ebt_entries { unsigned int distinguisher; char name[EBT_CHAIN_MAXNAMELEN]; unsigned int counter_offset; int policy; unsigned int nentries; char data[0] __attribute__((aligned(__alignof__(struct ebt_replace)))); }; struct ebt_table_desc { const char* name; struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; }; static struct ebt_table_desc ebt_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "broute"}, }; static void checkpoint_ebtables(void) { socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; strcpy(table->replace.name, table->name); optlen = sizeof(table->replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->replace.entries_size > sizeof(table->entrytable)) exit(1); table->replace.num_counters = 0; table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace, &optlen)) exit(1); } close(fd); } static void reset_ebtables() { struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; socklen_t optlen; unsigned i, j, h; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; if (table->replace.valid_hooks == 0) continue; memset(&replace, 0, sizeof(replace)); strcpy(replace.name, table->name); optlen = sizeof(replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen)) exit(1); replace.num_counters = 0; table->replace.entries = 0; for (h = 0; h < NF_BR_NUMHOOKS; h++) table->replace.hook_entry[h] = 0; if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) { memset(&entrytable, 0, sizeof(entrytable)); replace.entries = entrytable; optlen = sizeof(replace) + replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen)) exit(1); if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0) continue; } for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) { if (table->replace.valid_hooks & (1 << h)) { table->replace.hook_entry[h] = (struct ebt_entries*)table->entrytable + j; j++; } } table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_net_namespace(void) { checkpoint_ebtables(); checkpoint_arptables(); checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void reset_net_namespace(void) { reset_ebtables(); reset_arptables(); reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void setup_cgroups() { if (mkdir("/syzcgroup", 0777)) { } if (mkdir("/syzcgroup/unified", 0777)) { } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { } if (chmod("/syzcgroup/unified", 0777)) { } write_file("/syzcgroup/unified/cgroup.subtree_control", "+cpu +memory +io +pids +rdma"); if (mkdir("/syzcgroup/cpu", 0777)) { } if (mount("none", "/syzcgroup/cpu", "cgroup", 0, "cpuset,cpuacct,perf_event,hugetlb")) { } write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); if (chmod("/syzcgroup/cpu", 0777)) { } if (mkdir("/syzcgroup/net", 0777)) { } if (mount("none", "/syzcgroup/net", "cgroup", 0, "net_cls,net_prio,devices,freezer")) { } if (chmod("/syzcgroup/net", 0777)) { } } static void setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) { } write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:"); write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC"); } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } setup_cgroups(); setup_binfmt_misc(); } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 200 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_netdevices(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } #define SYZ_HAVE_SETUP_LOOP 1 static void setup_loop() { int pid = getpid(); char cgroupdir[64]; char file[128]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); write_file(file, "32"); snprintf(file, sizeof(file), "%s/memory.low", cgroupdir); write_file(file, "%d", 298 << 20); snprintf(file, sizeof(file), "%s/memory.high", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.max", cgroupdir); write_file(file, "%d", 300 << 20); snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); checkpoint_net_namespace(); } #define SYZ_HAVE_RESET_LOOP 1 static void reset_loop() { reset_net_namespace(); } #define SYZ_HAVE_SETUP_TEST 1 static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } write_file("/proc/self/oom_score_adj", "1000"); } #define SYZ_HAVE_RESET_TEST 1 static void reset_test() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 3; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); reset_test(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20000080, "/selinux/load\x00", 14); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000080, 2, 0); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000000, "\x8c\xff\x7c\xf9\x08\x00\x00\x00\x53\x45\x20\x4c\x69\x6e\x75\x78" "\x15\x00\x00\x00\x00\xf6\x00\x00\x08\x00\x00\x00\x07\x00\x00\x00" "\x40\x2c\x11\x00\x00\x00\x00\x00\x09\x00\x00\x07\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x38\x58\x58\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6d\xbd\x00\x60\x15\xd8\x00" "\xcc\xbf\x8e\xf1\x70\x25\xb5\x4f\x36\xaf\xa1\x82", 92); syscall(__NR_write, r[0], 0x20000000, 0x5c); break; case 2: *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0; *(uint64_t*)0x20000190 = 0x20000040; *(uint64_t*)0x20000040 = 0; *(uint64_t*)0x20000048 = 1; *(uint64_t*)0x20000198 = 1; *(uint64_t*)0x200001a0 = 0; *(uint64_t*)0x200001a8 = 0; *(uint32_t*)0x200001b0 = 0; syscall(__NR_sendmsg, -1, 0x20000180, 0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }
the_stack_data/98136.c
// this example shows how to use the ptrace API to // determine which system calls are being made by the child // process. Note, this example, only catches the first system // call. #include <errno.h> #include <fcntl.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ptrace.h> #include <sys/reg.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #define NUM_SYSCALLS 512 // just to be safe int main(int argc, char **argv) { pid_t child = fork(); if (child == 0) { // do something childish ptrace(PTRACE_TRACEME); // printf("Hello. I'm the child process.\n"); // stop myself --allow the parent to get ready to trace me kill(getpid(), SIGSTOP); system(argv[1]); } else { int status, syscall_num; uint64_t syscall_table[NUM_SYSCALLS] = {0}; FILE *out = fopen(argv[2], "w"); // I'm the parent...keep tabs on that child process // wait for the child to stop itself waitpid(child, &status, 0); // this option makes it easier to distinguish normal traps from // system calls ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD); while (1) { do { // Request: I want to wait for a system call ptrace(PTRACE_SYSCALL, child, 0, 0); // actually wait for child status to change waitpid(child, &status, 0); // there are differented reasons that a child's // status might change. Check to see if the child // exited if (WIFEXITED(status)) { // the child exited...let's exit too for (int i = 0; i < NUM_SYSCALLS; i++) { if (syscall_table[i] == 0) continue; fprintf(out, "%d\t%lu\n", i, syscall_table[i]); } fclose(out); exit(1); } // wait until the process is stopped or bit 7 is set in // the status (see man page comment on // PTRACE_O_TRACESYSGOOD) } while (!(WIFSTOPPED(status) && WSTOPSIG(status) & 0x80)); // read out the saved value of the RAX register, // which contains the system call number // For 32-bit machines, you would use EAX. syscall_num = ptrace(PTRACE_PEEKUSER, child, sizeof(long) * ORIG_RAX, NULL); syscall_table[syscall_num]++; ptrace(PTRACE_SYSCALL, child, 0, 0); waitpid(child, &status, 0); } } }
the_stack_data/37974.c
#include<stdio.h> void sub(int x, int y){ printf("Addition result = %d\n", x-y); }
the_stack_data/1260771.c
#include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { setlocale(LC_ALL,"portuguese"); int n=0; float e=0; printf("\t- 1/1 ... + 1/N -\n\n"); printf("Digite o valor de N: "); scanf("%i",&n); printf("\nE ="); for(int i=1;i<=n;i++){ printf(" 1/%i",i); if(i!=n) printf(" +"); e+=1/i; } printf("\nE = %.2f\n\n",e); return 0; }
the_stack_data/777537.c
int prime(int index) { if (index <= 0) return 2; static int primes[100]; int nprimes = 0; primes[nprimes++] = 2; for (int i = 3;; i++) { int j = 0; while (j < nprimes && i % primes[j] != 0) j++; if (j != nprimes) continue; // i is a prime. if (nprimes == index) return i; primes[nprimes++] = i; } } int main() { return prime(99); }
the_stack_data/7231.c
#include <stdio.h> #include <stdlib.h> #include <math.h> float converteTemperatura(float); main () { float temperatura, resultado; printf("Digite a temperatura em Celsius: "); scanf("%f", &temperatura); resultado = converteTemperatura(temperatura); printf("Temperatura em fahrenheit: %f", resultado); } float converteTemperatura(float temperatura) { return 1.8 * temperatura + 32; }
the_stack_data/3263721.c
#include <stdio.h> int binary_search(int arr[], int n, int find) { int low = 0; int high = n - 1; int mid; while (low <= high) { mid = (low + high) / 2; if (find < arr[mid]) { high = mid - 1; } else if (find > arr[mid]) { low = mid + 1; } else { return mid; } } return -1; } int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 25, 30, 100}; printf("%d\n", binary_search(arr, sizeof(arr)/sizeof(int), 30)); printf("%d\n", binary_search(arr, sizeof(arr)/sizeof(int), 2)); printf("%d\n", binary_search(arr, sizeof(arr)/sizeof(int), 1)); printf("%d\n", binary_search(arr, sizeof(arr)/sizeof(int), 1000)); return 0; }
the_stack_data/78470.c
/* $Id: genstring.c,v 1.1.1.1 2012/03/29 17:20:58 uid42307 Exp $ * * Generate array-of-const-string from text file. * * Copyright (C) 2006-2007 Peter Johnson * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLINE 1024 int main(int argc, char *argv[]) { FILE *in, *out; int i; char *str; char *strp; size_t len; if (argc < 4) { fprintf(stderr, "Usage: %s <string> <outfile> <file> [<file> ...]\n", argv[0]); return EXIT_FAILURE; } out = fopen(argv[2], "wt"); if (!out) { fprintf(stderr, "Could not open `%s'.\n", argv[2]); return EXIT_FAILURE; } str = malloc(MAXLINE); fprintf(out, "/* This file auto-generated from %s by genstring.c" " - don't edit it */\n\n" "static const char *%s[] = {\n", argv[3], argv[1]); for (i=3; i<argc; i++) { in = fopen(argv[i], "rt"); if (!in) { fprintf(stderr, "Could not open `%s'.\n", argv[i]); fclose(out); remove(argv[2]); return EXIT_FAILURE; } while (fgets(str, MAXLINE, in)) { strp = str; /* strip off trailing whitespace */ len = strlen(strp); while (len > 0 && (strp[len-1] == ' ' || strp[len-1] == '\t' || strp[len-1] == '\n')) { strp[len-1] = '\0'; len--; } /* output as string to output file */ fprintf(out, " \""); while (*strp != '\0') { if (*strp == '\\' || *strp == '"') fputc('\\', out); fputc(*strp, out); strp++; } fprintf(out, "\",\n"); } fclose(in); } fprintf(out, "};\n"); fclose(out); free(str); return EXIT_SUCCESS; }
the_stack_data/243893602.c
//C program to find hcf and lcm using recursion #include <stdio.h> long gcd(long, long); int main() { long x, y, hcf, lcm; printf("Enter two integers\n"); scanf("%ld%ld", &x, &y); hcf = gcd(x, y); lcm = (x*y)/hcf; printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf); printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm); return 0; } long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } }
the_stack_data/43888807.c
int d = 72; void MAIN() { d &= 70; print("d 64"); printid(d); }
the_stack_data/6387379.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <CL/cl.h> unsigned char *read_buffer(char *file_name, size_t *size_ptr) { FILE *f; unsigned char *buf; size_t size; /* Open file */ f = fopen(file_name, "rb"); if (!f) return NULL; /* Obtain file size */ fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); /* Allocate and read buffer */ buf = malloc(size + 1); fread(buf, 1, size, f); buf[size] = '\0'; /* Return size of buffer */ if (size_ptr) *size_ptr = size; /* Return buffer */ return buf; } void write_buffer(char *file_name, const char *buffer, size_t buffer_size) { FILE *f; /* Open file */ f = fopen(file_name, "w+"); /* Write buffer */ if(buffer) fwrite(buffer, 1, buffer_size, f); /* Close file */ fclose(f); } int main(int argc, char const *argv[]) { /* Get platform */ cl_platform_id platform; cl_uint num_platforms; cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformIDs' failed\n"); exit(1); } printf("Number of platforms: %d\n", num_platforms); printf("platform=%p\n", platform); /* Get platform name */ char platform_name[100]; ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformInfo' failed\n"); exit(1); } printf("platform.name='%s'\n\n", platform_name); /* Get device */ cl_device_id device; cl_uint num_devices; ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceIDs' failed\n"); exit(1); } printf("Number of devices: %d\n", num_devices); printf("device=%p\n", device); /* Get device name */ char device_name[100]; ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceInfo' failed\n"); exit(1); } printf("device.name='%s'\n", device_name); printf("\n"); /* Create a Context Object */ cl_context context; context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateContext' failed\n"); exit(1); } printf("context=%p\n", context); /* Create a Command Queue Object*/ cl_command_queue command_queue; command_queue = clCreateCommandQueue(context, device, 0, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateCommandQueue' failed\n"); exit(1); } printf("command_queue=%p\n", command_queue); printf("\n"); /* Program source */ unsigned char *source_code; size_t source_length; /* Read program from 'relational_less_than_or_equal_to_uchar2uchar2.cl' */ source_code = read_buffer("relational_less_than_or_equal_to_uchar2uchar2.cl", &source_length); /* Create a program */ cl_program program; program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateProgramWithSource' failed\n"); exit(1); } printf("program=%p\n", program); /* Build program */ ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (ret != CL_SUCCESS ) { size_t size; char *log; /* Get log size */ clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size); /* Allocate log and print */ log = malloc(size); clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL); printf("error: call to 'clBuildProgram' failed:\n%s\n", log); /* Free log and exit */ free(log); exit(1); } printf("program built\n"); printf("\n"); /* Create a Kernel Object */ cl_kernel kernel; kernel = clCreateKernel(program, "relational_less_than_or_equal_to_uchar2uchar2", &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateKernel' failed\n"); exit(1); } /* Create and allocate host buffers */ size_t num_elem = 10; /* Create and init host side src buffer 0 */ cl_uchar2 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_uchar2)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_uchar2){{2, 2}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uchar2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_uchar2), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create and init host side src buffer 1 */ cl_uchar2 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_uchar2)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_uchar2){{2, 2}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uchar2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_uchar2), src_1_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_int2 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_int2)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int2)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create dst buffer\n"); exit(1); } /* Set kernel arguments */ ret = CL_SUCCESS; ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer); ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer); ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clSetKernelArg' failed\n"); exit(1); } /* Launch the kernel */ size_t global_work_size = num_elem; size_t local_work_size = num_elem; ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueNDRangeKernel' failed\n"); exit(1); } /* Wait for it to finish */ clFinish(command_queue); /* Read results from GPU */ ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int2), dst_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueReadBuffer' failed\n"); exit(1); } /* Dump dst buffer to file */ char dump_file[100]; sprintf((char *)&dump_file, "%s.result", argv[0]); write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int2)); printf("Result dumped to %s\n", dump_file); /* Free host dst buffer */ free(dst_host_buffer); /* Free device dst buffer */ ret = clReleaseMemObject(dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 0 */ free(src_0_host_buffer); /* Free device side src buffer 0 */ ret = clReleaseMemObject(src_0_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 1 */ free(src_1_host_buffer); /* Free device side src buffer 1 */ ret = clReleaseMemObject(src_1_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Release kernel */ ret = clReleaseKernel(kernel); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseKernel' failed\n"); exit(1); } /* Release program */ ret = clReleaseProgram(program); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseProgram' failed\n"); exit(1); } /* Release command queue */ ret = clReleaseCommandQueue(command_queue); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseCommandQueue' failed\n"); exit(1); } /* Release context */ ret = clReleaseContext(context); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseContext' failed\n"); exit(1); } return 0; }
the_stack_data/87638109.c
/* ************************************************ username : smmehrab fullname : s.m.mehrabul islam email : [email protected] institute : university of dhaka, bangladesh session : 2017-2018 ************************************************ */ #include<stdio.h> int main() { int m,n,i,j,m1[100][100],m2[100][100]; scanf("%d %d",&m,&n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&m1[i][j]); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&m2[i][j]); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d",(m1[i][j]+m2[i][j])); if(j!=n-1) printf(" "); } printf("\n"); } return 0; }
the_stack_data/275172.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int contador, limite, continua1; float parcial, media; int total = 0; char nome[20]; char continua; printf("============================================\n"); printf(" Cálculo de notas 1.0 \n"); printf("============================================\n\n"); continua = 'S'; /* CHAR é definido por aspas simples */ while (continua == 'S') { total = 0; printf("Digite o nome do aluno:\n"); scanf("%s", &nome); printf("Digite o número total de provas realizadas: \n"); scanf("%d", &limite); for (contador = 1; contador <= limite; contador++) { printf("Digite a %dª nota:\n", contador); scanf("%f", &parcial); total = parcial + total; } media = total/limite; printf("A média das %d provas do aluno %s foi %.2f.\n", limite, nome, media); printf("Deseja prosseguir para o próximo? (S/N)\n"); scanf(" %c", &continua); /* O espaço para o %c é necessário quando é caractere */ } return 0; }
the_stack_data/154917.c
//***************************************************************************** // crp.c // // Source file to create CRP word expected by LPCXpresso IDE linker //***************************************************************************** // // Copyright(C) NXP Semiconductors, 2013 // All rights reserved. // // Software that is described herein is for illustrative purposes only // which provides customers with programming information regarding the // LPC products. This software is supplied "AS IS" without any warranties of // any kind, and NXP Semiconductors and its licensor disclaim any and // all warranties, express or implied, including all implied warranties of // merchantability, fitness for a particular purpose and non-infringement of // intellectual property rights. NXP Semiconductors assumes no responsibility // or liability for the use of the software, conveys no license or rights under any // patent, copyright, mask work right, or any other intellectual property rights in // or to any products. NXP Semiconductors reserves the right to make changes // in the software without notification. NXP Semiconductors also makes no // representation or warranty that such application will be suitable for the // specified use without further testing or modification. // // Permission to use, copy, modify, and distribute this software and its // documentation is hereby granted, under NXP Semiconductors' and its // licensor's relevant copyrights in the software, without fee, provided that it // is used in conjunction with NXP Semiconductors microcontrollers. This // copyright, permission, and disclaimer notice must appear in all copies of // this code. //***************************************************************************** #if defined (__CODE_RED) #include <NXP/crp.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; #endif
the_stack_data/65924.c
/* gcc -std=c17 -lc -lm -pthread -o ../_build/c/language__Noreturn.exe ./c/language__Noreturn.c && (cd ../_build/c/;./language__Noreturn.exe) || true https://en.cppreference.com/w/c/language/_Noreturn */ #include <stdlib.h> #include <stdio.h> #include <stdnoreturn.h> // causes undefined behavior if i <= 0 // exits if i > 0 noreturn void stop_now(int i) // or _Noreturn void stop_now(int i) { if (i > 0) exit(i); } int main(void) { puts("Preparing to stop..."); stop_now(2); puts("This code is never executed."); }
the_stack_data/123219.c
/* examples on assignments*/ #include<stdio.h> main() { float x,p; double y,q; unsigned k; int m=54321; long int n=1234567890; x=1.234567890000; y=9.87654321; k=54321; p=q=1.0; printf("m=%d\n",m); printf("n=%ld\n",n); printf("x=%.12lf\n",x); printf("x=%f\n",x); printf("y=%.12lf\n",y); printf("y=%lf\n",y); printf("k=%u p = %f q=%.12lf\n",k,p,q); }
the_stack_data/48574404.c
#include <stdio.h> //09_3_Pointer(String)_File.hwp look for it char *str_ncat(char *s1, const char *s2, int n) { char *tmp = s1; while (*s1) { s1++; } while (n--) { if (!(*s1++ = *s2++)) { break; } } *s1 = '\0'; return tmp; } void main() { char str1[] = "asdf1234"; char str2[] = "qwer5678qwer5678"; char *p; p = str_ncat(str1, str2, 10); printf("%s", p); }
the_stack_data/90764707.c
#include <stdio.h> #include <string.h> #include <stdlib.h> void printMat(float *a, uint m, uint n) { for (uint i = 0; i < m; ++i) { printf("{"); for (uint j = 0; j < n;) { printf("%.0f", a[i * n + j]); if (++j != n) { printf(", "); } } printf("}\n"); } } void transpose(float *a, float *b, uint n) { for (uint i = 0; i < n; ++i) { for (uint j = 0; j < n; ++j) { b[j * n + i] = a[i * n + j]; } } } float * transposeOut(float *a, uint n) { float *b = (float *) malloc(n * n * sizeof(float)); transpose(a, b, n); return b; } void matMul(float *a, float *b, float *c, uint m, uint n, uint p) { printf("multiplying\n"); printMat(a, m, n); printf("by\n"); printMat(b, n, p); printf("into\n"); printMat(c, m, p); for (uint i = 0; i < m; ++i) { for (uint j = 0; j < p; ++j) { float val = 0; for (uint k = 0; k < n; ++k) { val += a[i * n + k] * b[k * p + j]; } c[i * p +j] = val; } } printf("result\n"); printMat(c, m, p); } float * matMulOut(float *a, float *b, uint m, uint n, uint p) { float *c = (float *) malloc(m * p * sizeof(float)); matMul(a, b, c, m, n, p); return c; } int main() { const uint n = 3; size_t size = n * n * sizeof(float); float *a = malloc(size); float *b = malloc(size); for (uint i = 0; i < n * n; ++i) { a[i] = i + 1; b[i] = a[i] * 2; } float *c = matMulOut(a, b, n, n, n); }
the_stack_data/192329339.c
int main() { int a = 6, i; if (a == 2) if (a == 3) printf("3"); else printf("None"); while (a > 3) { for (i=1; i<7; i++) { a--; } } return 0; }
the_stack_data/165767809.c
#include <stdlib.h> void * _realloc_r (struct _reent *ptr, void *old, size_t newlen) { return realloc (old, newlen); }
the_stack_data/162644191.c
#include <stdint.h> const uint8_t ASCII[] = { 0x00, 0x00, 0x00, 0x00, 0x00, // 0 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, // 1 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, // 2 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, // 3 0x18, 0x3C, 0x7E, 0x3C, 0x18, // 4 0x1C, 0x57, 0x7D, 0x57, 0x1C, // 5 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, // 6 0x00, 0x18, 0x3C, 0x18, 0x00, // 7 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, // 8 0x00, 0x18, 0x24, 0x18, 0x00, // 9 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, // 10 0x30, 0x48, 0x3A, 0x06, 0x0E, // 11 0x26, 0x29, 0x79, 0x29, 0x26, // 12 0x40, 0x7F, 0x05, 0x05, 0x07, // 13 0x40, 0x7F, 0x05, 0x25, 0x3F, // 14 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, // 15 0x7F, 0x3E, 0x1C, 0x1C, 0x08, // 16 0x08, 0x1C, 0x1C, 0x3E, 0x7F, // 17 0x14, 0x22, 0x7F, 0x22, 0x14, // 18 0x5F, 0x5F, 0x00, 0x5F, 0x5F, // 19 0x06, 0x09, 0x7F, 0x01, 0x7F, // 20 0x00, 0x66, 0x89, 0x95, 0x6A, // 21 0x60, 0x60, 0x60, 0x60, 0x60, // 22 0x94, 0xA2, 0xFF, 0xA2, 0x94, // 23 0x08, 0x04, 0x7E, 0x04, 0x08, // 24 0x10, 0x20, 0x7E, 0x20, 0x10, // 25 0x08, 0x08, 0x2A, 0x1C, 0x08, // 26 0x08, 0x1C, 0x2A, 0x08, 0x08, // 27 0x1E, 0x10, 0x10, 0x10, 0x10, // 28 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, // 29 0x30, 0x38, 0x3E, 0x38, 0x30, // 30 0x06, 0x0E, 0x3E, 0x0E, 0x06, // 31 0x00, 0x00, 0x00, 0x00, 0x00, // 32 space 0x00, 0x00, 0x5F, 0x00, 0x00, // 33 ! 0x00, 0x07, 0x00, 0x07, 0x00, // 34 " 0x14, 0x7F, 0x14, 0x7F, 0x14, // 35 # 0x24, 0x2A, 0x7F, 0x2A, 0x12, // 36 $ 0x23, 0x13, 0x08, 0x64, 0x62, // 37 % 0x36, 0x49, 0x56, 0x20, 0x50, // 38 & 0x00, 0x08, 0x07, 0x03, 0x00, // 39 ' 0x00, 0x1C, 0x22, 0x41, 0x00, // 40 ( 0x00, 0x41, 0x22, 0x1C, 0x00, // 41 ) 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // 42 * 0x08, 0x08, 0x3E, 0x08, 0x08, // 43 + 0x00, 0x80, 0x70, 0x30, 0x00, // 44 , 0x08, 0x08, 0x08, 0x08, 0x08, // 45 - 0x00, 0x00, 0x60, 0x60, 0x00, // 46 . 0x20, 0x10, 0x08, 0x04, 0x02, // 47 / 0x3E, 0x51, 0x49, 0x45, 0x3E, // 48 0 0x00, 0x42, 0x7F, 0x40, 0x00, // 49 1 0x72, 0x49, 0x49, 0x49, 0x46, // 50 2 0x21, 0x41, 0x49, 0x4D, 0x33, // 51 3 0x18, 0x14, 0x12, 0x7F, 0x10, // 52 4 0x27, 0x45, 0x45, 0x45, 0x39, // 53 5 0x3C, 0x4A, 0x49, 0x49, 0x31, // 54 6 0x41, 0x21, 0x11, 0x09, 0x07, // 55 7 0x36, 0x49, 0x49, 0x49, 0x36, // 56 8 0x46, 0x49, 0x49, 0x29, 0x1E, // 57 9 0x00, 0x00, 0x14, 0x00, 0x00, // 58 : 0x00, 0x40, 0x34, 0x00, 0x00, // 59 ; 0x00, 0x08, 0x14, 0x22, 0x41, // 60 < 0x14, 0x14, 0x14, 0x14, 0x14, // 61 = 0x00, 0x41, 0x22, 0x14, 0x08, // 62 > 0x02, 0x01, 0x59, 0x09, 0x06, // 63 ? 0x3E, 0x41, 0x5D, 0x59, 0x4E, // 64 @ 0x7C, 0x12, 0x11, 0x12, 0x7C, // 65 A 0x7F, 0x49, 0x49, 0x49, 0x36, // 66 B 0x3E, 0x41, 0x41, 0x41, 0x22, // 67 C 0x7F, 0x41, 0x41, 0x41, 0x3E, // 68 D 0x7F, 0x49, 0x49, 0x49, 0x41, // 69 E 0x7F, 0x09, 0x09, 0x09, 0x01, // 70 F 0x3E, 0x41, 0x41, 0x51, 0x73, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x26, 0x49, 0x49, 0x49, 0x32, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x63, 0x14, 0x08, 0x14, 0x63, 0x03, 0x04, 0x78, 0x04, 0x03, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x04, 0x02, 0x01, 0x02, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x03, 0x07, 0x08, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x38, 0x44, 0x44, 0x44, 0x28, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x38, 0x44, 0x44, 0x44, 0x38, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x48, 0x54, 0x54, 0x54, 0x24, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x44, 0x28, 0x10, 0x28, 0x44, 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x1E, 0xA1, 0xA1, 0x61, 0x12, 0x3A, 0x40, 0x40, 0x20, 0x7A, 0x38, 0x54, 0x54, 0x55, 0x59, 0x21, 0x55, 0x55, 0x79, 0x41, 0x21, 0x54, 0x54, 0x78, 0x41, 0x21, 0x55, 0x54, 0x78, 0x40, 0x20, 0x54, 0x55, 0x79, 0x40, 0x0C, 0x1E, 0x52, 0x72, 0x12, 0x39, 0x55, 0x55, 0x55, 0x59, 0x39, 0x54, 0x54, 0x54, 0x59, 0x39, 0x55, 0x54, 0x54, 0x58, 0x00, 0x00, 0x45, 0x7C, 0x41, 0x00, 0x02, 0x45, 0x7D, 0x42, 0x00, 0x01, 0x45, 0x7C, 0x40, 0xF0, 0x29, 0x24, 0x29, 0xF0, 0xF0, 0x28, 0x25, 0x28, 0xF0, 0x7C, 0x54, 0x55, 0x45, 0x00, 0x20, 0x54, 0x54, 0x7C, 0x54, 0x7C, 0x0A, 0x09, 0x7F, 0x49, 0x32, 0x49, 0x49, 0x49, 0x32, 0x32, 0x48, 0x48, 0x48, 0x32, 0x32, 0x4A, 0x48, 0x48, 0x30, 0x3A, 0x41, 0x41, 0x21, 0x7A, 0x3A, 0x42, 0x40, 0x20, 0x78, 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 0x39, 0x44, 0x44, 0x44, 0x39, 0x3D, 0x40, 0x40, 0x40, 0x3D, 0x3C, 0x24, 0xFF, 0x24, 0x24, 0x48, 0x7E, 0x49, 0x43, 0x66, 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 0xFF, 0x09, 0x29, 0xF6, 0x20, 0xC0, 0x88, 0x7E, 0x09, 0x03, 0x20, 0x54, 0x54, 0x79, 0x41, 0x00, 0x00, 0x44, 0x7D, 0x41, 0x30, 0x48, 0x48, 0x4A, 0x32, 0x38, 0x40, 0x40, 0x22, 0x7A, 0x00, 0x7A, 0x0A, 0x0A, 0x72, 0x7D, 0x0D, 0x19, 0x31, 0x7D, 0x26, 0x29, 0x29, 0x2F, 0x28, 0x26, 0x29, 0x29, 0x29, 0x26, 0x30, 0x48, 0x4D, 0x40, 0x20, 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 0x2F, 0x10, 0x28, 0x34, 0xFA, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, 0xAA, 0x00, 0x55, 0x00, 0xAA, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, 0x10, 0x10, 0xFF, 0x00, 0xFF, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x14, 0x14, 0x14, 0xFC, 0x00, 0x14, 0x14, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x14, 0x14, 0xF4, 0x04, 0xFC, 0x14, 0x14, 0x17, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0x1F, 0x00, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0x14, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x1F, 0x10, 0x17, 0x00, 0x00, 0xFC, 0x04, 0xF4, 0x14, 0x14, 0x17, 0x10, 0x17, 0x14, 0x14, 0xF4, 0x04, 0xF4, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0xF7, 0x00, 0xF7, 0x14, 0x14, 0x14, 0x17, 0x14, 0x10, 0x10, 0x1F, 0x10, 0x1F, 0x14, 0x14, 0x14, 0xF4, 0x14, 0x10, 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x1F, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x14, 0x00, 0x00, 0x00, 0xFC, 0x14, 0x00, 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xFF, 0x10, 0xFF, 0x14, 0x14, 0x14, 0xFF, 0x14, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x38, 0x44, 0x44, 0x38, 0x44, 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 0x7E, 0x02, 0x02, 0x06, 0x06, 0x02, 0x7E, 0x02, 0x7E, 0x02, 0x63, 0x55, 0x49, 0x41, 0x63, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x40, 0x7E, 0x20, 0x1E, 0x20, 0x06, 0x02, 0x7E, 0x02, 0x02, 0x99, 0xA5, 0xE7, 0xA5, 0x99, 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 0x4C, 0x72, 0x01, 0x72, 0x4C, 0x30, 0x4A, 0x4D, 0x4D, 0x30, 0x30, 0x48, 0x78, 0x48, 0x30, 0xBC, 0x62, 0x5A, 0x46, 0x3D, 0x3E, 0x49, 0x49, 0x49, 0x00, 0x7E, 0x01, 0x01, 0x01, 0x7E, 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 0x44, 0x44, 0x5F, 0x44, 0x44, 0x40, 0x51, 0x4A, 0x44, 0x40, 0x40, 0x44, 0x4A, 0x51, 0x40, 0x00, 0x00, 0xFF, 0x01, 0x03, 0xE0, 0x80, 0xFF, 0x00, 0x00, 0x08, 0x08, 0x6B, 0x6B, 0x08, 0x36, 0x12, 0x36, 0x24, 0x36, 0x06, 0x0F, 0x09, 0x0F, 0x06, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x30, 0x40, 0xFF, 0x01, 0x01, 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, };
the_stack_data/1134802.c
#include <termios.h> #include <sys/ioctl.h> int tcflow(int fd, int action) { return ioctl(fd, TCXONC, action); }
the_stack_data/122191.c
/** https://projecteuler.net/problem=1 */ #include <assert.h> int solution1(int n) { int sum = 0; for (int i = 1; i < n; ++i) { if (i % 3 == 0 || i % 5 == 0) { sum += i; } } return sum; } void test() { assert(0 == solution1(-100)); assert(0 == solution1(3)); assert(3 == solution1(4)); assert(23 == solution1(10)); assert(233168 == solution1(1000)); } int main() { test(); return 0; }
the_stack_data/663816.c
#include<stdio.h> #include<malloc.h> #include<limits.h> struct arrayStack { int top ; int capacity ; int *array ; }; struct arrayStack *createStack(int size) { struct arrayStack *S = malloc(sizeof(struct arrayStack)) ; S -> top = -1 ; S -> capacity = size ; S -> array = malloc(sizeof(int)*S->capacity) ; return S ; } int isStackEmpty(struct arrayStack *S) { return (S -> top == -1) ; } int isStackFull(struct arrayStack *S) { return (S -> top == (S -> capacity)-1) ; } int pop(struct arrayStack *S) { if(isEmpty(S)) { printf("Array is Empty\n"); return 0; } else { int data = S->array[S->top] ; S-> top-- ; return data ; } } void push(struct arrayStack *S, int data) { if(isFull(S)) { printf("StackOverflow\n"); return ; } else { S->array[++S->top] = data ; printf("Inserted Successfully\n"); } } struct queue { int front , rear ; int capacity ; int *array ; }; struct queue *createQueue(int size) { struct queue *Q = malloc(sizeof(struct queue)) ; if(!Q) { printf("creation of queue is not possible\n"); return NULL ; } Q -> front = -1 ; Q -> rear = -1 ; Q -> capacity = size ; Q -> array = malloc(Q -> capacity * sizeof(int)) ; if(!Q -> array) { printf("creation of array of queue is not possible\n"); return NULL ; } return Q ; } int isEmpty(struct queue *Q) { return Q -> front == -1 ; } int isFull(struct queue *Q) { return ((Q -> rear + 1) % Q -> capacity == Q -> front) ; } int getQSize(struct queue *Q) { return (Q -> capacity - Q -> front + Q -> rear + 1) % Q -> capacity ; } void EnQueue(struct queue *Q , int data) { if(isFull(Q)) { printf("Queue Overflow\n") ; return ; } Q -> rear = (Q -> rear + 1)%Q->capacity ; Q -> array[Q -> rear] = data ; if(Q -> front == -1) { Q -> front = Q -> rear ; } } int DeQueue(struct queue *Q) { if(isEmpty(Q)) { return INT_MIN ; } else { int d = Q -> array[Q -> front] ; if(Q -> front == Q -> rear) // one element in the queue Q -> front = Q -> rear = -1 ; else Q -> front = (Q -> front + 1) % Q -> capacity ; return d ; } } int main() { struct queue *Q = createQueue(11) ; int i , k; for(i = 0 ; i < 10 ; i++) EnQueue(Q , (i+1)*10) ; printf("Enter the value till the elements of queue is reversed : "); scanf("%d" , &k) ; struct arrayStack *S = createStack(k) ; for(i = 0 ; i < k ; i++) { push(S , DeQueue(Q)) ; } while(!isStackEmpty(S)) { EnQueue(Q , pop(S)) ; } int size = getQSize(Q) ; for (i = 0; i < size - k; i++) { int t = DeQueue(Q) ; EnQueue(Q , t) ; } while(!isEmpty(Q)) { int d = DeQueue(Q) ; printf(" %d ", d); } }
the_stack_data/585273.c
//Classification: n/DAM/NP/sS/D(v)/lc/ln //Written by: Sergey Pomelov //Reviewed by: Igor Eremeev //Comment: #include <stdio.h> int main(void) { int *p = NULL; static int a; a = *p; printf("%d",a); return 0; }
the_stack_data/788076.c
typedef enum {false,true} bool; extern int __VERIFIER_nondet_int(void); int main() { int i; int j; int k; int t; i = __VERIFIER_nondet_int(); j = __VERIFIER_nondet_int(); k = __VERIFIER_nondet_int(); while (i <= 100 && j < k) { i = j; j = i + 1; k = k - 1; } return 0; }
the_stack_data/168892577.c
int main(void){ float x; x; return 0; }
the_stack_data/9513585.c
// https://issues.dlang.org/show_bug.cgi?id=22877 int array[3]; _Static_assert(sizeof(array) == 3 * sizeof(int), "array"); _Static_assert(sizeof("ab") == 3, "string"); _Static_assert((sizeof(L"ab") == 3 * sizeof(short)) || (sizeof(L"ab") == 3 * sizeof(int)), "wstring"); _Static_assert(sizeof(u8"ab") == 3, "UTF-8 string"); _Static_assert(sizeof(u"ab") == 3 * sizeof(short), "UTF-16 string"); _Static_assert(sizeof(U"ab") == 3 * sizeof(int), "UTF-32 string"); _Static_assert(sizeof(&"ab") == sizeof(void*), "pointer"); _Static_assert(sizeof(*&"ab") == 3, "pointer deref");
the_stack_data/31388801.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 150 int main ( ) { int a[N]; int i = 0; while ( i < N ) { a[i] = 42; i = i + 1; } i = 0; while ( i < N ) { a[i] = 43; i = i + 1; } int x; for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a[x] == 43 ); } return 0; }
the_stack_data/148680.c
#include <stdio.h> #include <stdlib.h> int main(void) { puts("Basic Test Cases."); return EXIT_SUCCESS; }// end of function main
the_stack_data/67477.c
/*** TMS34010: Portable TMS34010 emulator *********************************** Copyright (C) Alex Pasadyn/Zsolt Vasvari 1998 Opcode Table *****************************************************************************/ static void unimpl(void); /* Graphics Instructions */ static void pixblt_l_l(void); /* 0f00 */ static void pixblt_l_xy(void); /* 0f20 */ static void pixblt_xy_l(void); /* 0f40 */ static void pixblt_xy_xy(void); /* 0f60 */ static void pixblt_b_l(void); /* 0f80 */ static void pixblt_b_xy(void); /* 0fa0 */ static void fill_l(void); /* 0fc0 */ static void fill_xy(void); /* 0fe0 */ static void line(void); /* df10/df90 */ static void add_xy_a(void); /* e000/e100 */ static void add_xy_b(void); /* e000/e100 */ static void sub_xy_a(void); /* e200/e300 */ static void sub_xy_b(void); /* e200/e300 */ static void cmp_xy_a(void); /* e400/e500 */ static void cmp_xy_b(void); /* e400/e500 */ static void cpw_a(void); /* e600/e700 */ static void cpw_b(void); /* e600/e700 */ static void cvxyl_a(void); /* e800/e900 */ static void cvxyl_b(void); /* e800/e900 */ static void movx_a(void); /* ec00/ed00 */ static void movx_b(void); /* ec00/ed00 */ static void movy_a(void); /* ee00/ef00 */ static void movy_b(void); /* ee00/ef00 */ static void pixt_ri_a(void); /* f800/f900 */ static void pixt_ri_b(void); /* f800/f900 */ static void pixt_rixy_a(void); /* f000/f100 */ static void pixt_rixy_b(void); /* f000/f100 */ static void pixt_ir_a(void); /* fa00/fb00 */ static void pixt_ir_b(void); /* fa00/fb00 */ static void pixt_ii_a(void); /* fc00/fd00 */ static void pixt_ii_b(void); /* fc00/fd00 */ static void pixt_ixyr_a(void); /* f200/f300 */ static void pixt_ixyr_b(void); /* f200/f300 */ static void pixt_ixyixy_a(void); /* f400/f500 */ static void pixt_ixyixy_b(void); /* f400/f500 */ static void drav_a(void); /* f600/f700 */ static void drav_b(void); /* f600/f700 */ /* General Instructions */ static void abs_a(void); /* 0380 */ static void abs_b(void); /* 0390 */ static void add_a(void); /* 4000/4100 */ static void add_b(void); /* 4000/4100 */ static void addc_a(void); /* 4200/4200 */ static void addc_b(void); /* 4200/4200 */ static void addi_w_a(void); /* 0b00 */ static void addi_w_b(void); /* 0b10 */ static void addi_l_a(void); /* 0b20 */ static void addi_l_b(void); /* 0b30 */ static void addk_a(void); /* 1000-1300 */ static void addk_b(void); /* 1000-1300 */ static void and_a(void); /* 5000/5100 */ static void and_b(void); /* 5000/5100 */ static void andi_a(void); /* 0b80 */ static void andi_b(void); /* 0b90 */ static void andn_a(void); /* 5200-5300 */ static void andn_b(void); /* 5200-5300 */ static void btst_k_a(void); /* 1c00-1f00 */ static void btst_k_b(void); /* 1c00-1f00 */ static void btst_r_a(void); /* 4a00-4b00 */ static void btst_r_b(void); /* 4a00-4b00 */ static void clrc(void); /* 0320 */ static void cmp_a(void); /* 4800/4900 */ static void cmp_b(void); /* 4800/4900 */ static void cmpi_w_a(void); /* 0b40 */ static void cmpi_w_b(void); /* 0b50 */ static void cmpi_l_a(void); /* 0b60 */ static void cmpi_l_b(void); /* 0b70 */ static void dint(void); static void divs_a(void); /* 5800/5900 */ static void divs_b(void); /* 5800/5900 */ static void divu_a(void); /* 5a00/5b00 */ static void divu_b(void); /* 5a00/5b00 */ static void eint(void); static void exgf0_a(void); /* d500 */ static void exgf0_b(void); /* d510 */ static void exgf1_a(void); /* d700 */ static void exgf1_b(void); /* d710 */ static void lmo_a(void); /* 6a00/6b00 */ static void lmo_b(void); /* 6a00/6b00 */ static void mmfm_a(void); /* 09a0 */ static void mmfm_b(void); /* 09b0 */ static void mmtm_a(void); /* 0980 */ static void mmtm_b(void); /* 0990 */ static void mods_a(void); /* 6c00/6d00 */ static void mods_b(void); /* 6c00/6d00 */ static void modu_a(void); /* 6e00/6f00 */ static void modu_b(void); /* 6e00/6f00 */ static void mpys_a(void); /* 5c00/5d00 */ static void mpys_b(void); /* 5c00/5d00 */ static void mpyu_a(void); /* 5e00/5e00 */ static void mpyu_b(void); /* 5e00/5f00 */ static void neg_a(void); /* 03a0 */ static void neg_b(void); /* 03b0 */ static void negb_a(void); /* 03c0 */ static void negb_b(void); /* 03d0 */ static void nop(void); /* 0300 */ static void not_a(void); /* 03e0 */ static void not_b(void); /* 03f0 */ static void or_a(void); /* 5400-5500 */ static void or_b(void); /* 5400-5500 */ static void ori_a(void); /* 0ba0 */ static void ori_b(void); /* 0bb0 */ static void rl_k_a(void); /* 3000-3300 */ static void rl_k_b(void); /* 3000-3300 */ static void rl_r_a(void); /* 6800/6900 */ static void rl_r_b(void); /* 6800/6900 */ static void setc(void); /* 0de0 */ static void setf0(void); static void setf1(void); static void sext0_a(void); /* 0500 */ static void sext0_b(void); /* 0510 */ static void sext1_a(void); /* 0700 */ static void sext1_b(void); /* 0710 */ static void sla_k_a(void); /* 2000-2300 */ static void sla_k_b(void); /* 2000-2300 */ static void sla_r_a(void); /* 6000/6100 */ static void sla_r_b(void); /* 6000/6100 */ static void sll_k_a(void); /* 2400-2700 */ static void sll_k_b(void); /* 2400-2700 */ static void sll_r_a(void); /* 6200/6300 */ static void sll_r_b(void); /* 6200/6300 */ static void sra_k_a(void); /* 2800-2b00 */ static void sra_k_b(void); /* 2800-2b00 */ static void sra_r_a(void); /* 6400/6500 */ static void sra_r_b(void); /* 6400/6500 */ static void srl_k_a(void); /* 2c00-2f00 */ static void srl_k_b(void); /* 2c00-2f00 */ static void srl_r_a(void); /* 6600/6700 */ static void srl_r_b(void); /* 6600/6700 */ static void sub_a(void); /* 4400/4500 */ static void sub_b(void); /* 4400/4500 */ static void subb_a(void); /* 4600/4700 */ static void subb_b(void); /* 4600/4700 */ static void subi_w_a(void); /* 0be0 */ static void subi_w_b(void); /* 0bf0 */ static void subi_l_a(void); /* 0d00 */ static void subi_l_b(void); /* 0d10 */ static void subk_a(void); /* 1400-1700 */ static void subk_b(void); /* 1400-1700 */ static void xor_a(void); /* 5600-5700 */ static void xor_b(void); /* 5600-5700 */ static void xori_a(void); /* 0bc0 */ static void xori_b(void); /* 0bd0 */ static void zext0_a(void); /* 0520 */ static void zext0_b(void); /* 0530 */ static void zext1_a(void); /* 0720 */ static void zext1_b(void); /* 0720 */ /* Move Instructions */ static void movi_w_a(void); static void movi_w_b(void); static void movi_l_a(void); static void movi_l_b(void); static void movk_a(void); static void movk_b(void); static void movb_rn_a(void); /* 8c00-8d00 */ static void movb_rn_b(void); /* 8c00-8d00 */ static void movb_nr_a(void); /* 8e00-8f00 */ static void movb_nr_b(void); /* 8e00-8f00 */ static void movb_nn_a(void); /* 9c00-9d00 */ static void movb_nn_b(void); /* 9c00-9d00 */ static void movb_r_no_a(void); /* ac00-ad00 */ static void movb_r_no_b(void); /* ac00-ad00 */ static void movb_no_r_a(void); /* ae00-af00 */ static void movb_no_r_b(void); /* ae00-af00 */ static void movb_no_no_a(void); /* bc00-bd00 */ static void movb_no_no_b(void); /* bc00-bd00 */ static void movb_ra_a(void); static void movb_ra_b(void); static void movb_ar_a(void); static void movb_ar_b(void); static void movb_aa(void); static void move_rr_a(void); /* 4c00/d00 */ static void move_rr_b(void); /* 4c00/d00 */ static void move_rr_ax(void); /* 4e00/f00 */ static void move_rr_bx(void); /* 4e00/f00 */ static void move0_rn_a(void); /* 8000 */ static void move0_rn_b(void); static void move1_rn_a(void); static void move1_rn_b(void); static void move0_r_dn_a(void); /* a000 */ static void move0_r_dn_b(void); static void move1_r_dn_a(void); static void move1_r_dn_b(void); static void move0_r_ni_a(void); /* 9000 */ static void move0_r_ni_b(void); static void move1_r_ni_a(void); static void move1_r_ni_b(void); static void move0_nr_a(void); /* 8400-500 */ static void move0_nr_b(void); /* 8400-500 */ static void move1_nr_a(void); /* 8600-700 */ static void move1_nr_b(void); /* 8600-700 */ static void move0_dn_r_a(void); /* A400-500 */ static void move0_dn_r_b(void); /* A400-500 */ static void move1_dn_r_a(void); /* A600-700 */ static void move1_dn_r_b(void); /* A600-700 */ static void move0_ni_r_a(void); /* 9400-500 */ static void move0_ni_r_b(void); /* 9400-500 */ static void move1_ni_r_a(void); /* 9600-700 */ static void move1_ni_r_b(void); /* 9600-700 */ static void move0_nn_a(void); /* 8800 */ static void move0_nn_b(void); static void move1_nn_a(void); static void move1_nn_b(void); static void move0_dn_dn_a(void); /* a800 */ static void move0_dn_dn_b(void); static void move1_dn_dn_a(void); static void move1_dn_dn_b(void); static void move0_ni_ni_a(void); /* 9800 */ static void move0_ni_ni_b(void); static void move1_ni_ni_a(void); static void move1_ni_ni_b(void); static void move0_r_no_a(void); /* b000 */ static void move0_r_no_b(void); static void move1_r_no_a(void); static void move1_r_no_b(void); static void move0_no_r_a(void); /* b400 */ static void move0_no_r_b(void); static void move1_no_r_a(void); static void move1_no_r_b(void); static void move0_no_ni_a(void); /* d000 */ static void move0_no_ni_b(void); static void move1_no_ni_a(void); static void move1_no_ni_b(void); static void move0_no_no_a(void); /* b800 */ static void move0_no_no_b(void); static void move1_no_no_a(void); static void move1_no_no_b(void); static void move0_ra_a(void); static void move0_ra_b(void); static void move1_ra_a(void); static void move1_ra_b(void); static void move0_ar_a(void); static void move0_ar_b(void); static void move1_ar_a(void); static void move1_ar_b(void); static void move0_a_ni_a(void); /* d400 */ static void move0_a_ni_b(void); /* d410 */ static void move1_a_ni_a(void); /* d600 */ static void move1_a_ni_b(void); /* d610 */ static void move0_aa(void); /* 05c0 */ static void move1_aa(void); /* 07c0 */ /* Program Control and Context Switching */ static void call_a(void); /* 0920 */ static void call_b(void); /* 0930 */ static void callr(void); /* 0d3f */ static void calla(void); /* 0d5f */ static void dsj_a(void); /* 0d80 */ static void dsj_b(void); /* 0d90 */ static void dsjeq_a(void); /* 0da0 */ static void dsjeq_b(void); /* 0db0 */ static void dsjne_a(void); /* 0dc0 */ static void dsjne_b(void); /* 0dd0 */ static void dsjs_a(void); static void dsjs_b(void); static void emu(void); /* 0100 */ static void exgpc_a(void); /* 0120 */ static void exgpc_b(void); /* 0130 */ static void getpc_a(void); /* 0140 */ static void getpc_b(void); /* 0150 */ static void getst_a(void); /* 0180 */ static void getst_b(void); /* 0190 */ static void j_UC_0(void); static void j_UC_8(void); static void j_UC_x(void); static void j_P_0(void); static void j_P_8(void); static void j_P_x(void); static void j_LS_0(void); static void j_LS_8(void); static void j_LS_x(void); static void j_HI_0(void); static void j_HI_8(void); static void j_HI_x(void); static void j_LT_0(void); static void j_LT_8(void); static void j_LT_x(void); static void j_GE_0(void); static void j_GE_8(void); static void j_GE_x(void); static void j_LE_0(void); static void j_LE_8(void); static void j_LE_x(void); static void j_GT_0(void); static void j_GT_8(void); static void j_GT_x(void); static void j_C_0(void); static void j_C_8(void); static void j_C_x(void); static void j_NC_0(void); static void j_NC_8(void); static void j_NC_x(void); static void j_EQ_0(void); static void j_EQ_8(void); static void j_EQ_x(void); static void j_NE_0(void); static void j_NE_8(void); static void j_NE_x(void); static void j_V_0(void); static void j_V_8(void); static void j_V_x(void); static void j_NV_0(void); static void j_NV_8(void); static void j_NV_x(void); static void j_N_0(void); static void j_N_8(void); static void j_N_x(void); static void j_NN_0(void); static void j_NN_8(void); static void j_NN_x(void); static void jump_a(void); /* 0160 */ static void jump_b(void); /* 0170 */ static void popst(void); /* 01c0 */ static void pushst(void); /* 01e0 */ static void putst_a(void); /* 01a0 */ static void putst_b(void); /* 01b0 */ static void reti(void); /* 0940 */ static void rets(void); /* 0960/70 */ static void rev_a(void); /* 0020 */ static void rev_b(void); /* 0030 */ static void trap(void); /* 0900/10 */ /* 34020 instructions */ static void addxyi_a(void); static void addxyi_b(void); static void blmove(void); static void cexec_l(void); static void cexec_s(void); static void clip(void); static void cmovcg_a(void); static void cmovcg_b(void); static void cmovcm_f(void); static void cmovcm_b(void); static void cmovgc_a(void); static void cmovgc_b(void); static void cmovgc_a_s(void); static void cmovgc_b_s(void); static void cmovmc_f(void); static void cmovmc_f_va(void); static void cmovmc_f_vb(void); static void cmovmc_b(void); static void cmp_k_a(void); static void cmp_k_b(void); static void cvdxyl_a(void); static void cvdxyl_b(void); static void cvmxyl_a(void); static void cvmxyl_b(void); static void cvsxyl_a(void); static void cvsxyl_b(void); static void exgps_a(void); static void exgps_b(void); static void fline(void); static void fpixeq(void); static void fpixne(void); static void getps_a(void); static void getps_b(void); static void idle(void); static void linit(void); static void mwait(void); static void pfill_xy(void); static void pixblt_l_m_l(void); static void retm(void); static void rmo_a(void); static void rmo_b(void); static void rpix_a(void); static void rpix_b(void); static void setcdp(void); static void setcmp(void); static void setcsp(void); static void swapf_a(void); static void swapf_b(void); static void tfill_xy(void); static void trapl(void); static void vblt_b_l(void); static void vfill_l(void); static void vlcol(void); /* Opcode Table */ static void (*opcode_table[65536 >> 4])(void) = { /* 0x0000 0x0010 0x0020 0x0030 ... 0x00f0 */ unimpl, unimpl, rev_a, rev_b, idle, unimpl, unimpl, unimpl, mwait, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, blmove, /* 0x0100 */ emu, unimpl, exgpc_a, exgpc_b, getpc_a, getpc_b, jump_a, jump_b, getst_a, getst_b, putst_a, putst_b, popst, unimpl, pushst, unimpl, /* 0x0200 */ unimpl, unimpl, unimpl, unimpl, unimpl, setcsp, unimpl, setcdp, rpix_a, rpix_b, exgps_a, exgps_b, getps_a, getps_b, unimpl, setcmp, /* 0x0300 */ nop, unimpl, clrc, unimpl, movb_aa, unimpl, dint, unimpl, abs_a, abs_b, neg_a, neg_b, negb_a, negb_b, not_a, not_b, /* 0x0400 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x0500 */ sext0_a, sext0_b, zext0_a, zext0_b, setf0, setf0, setf0, setf0, move0_ra_a, move0_ra_b, move0_ar_a, move0_ar_b, move0_aa, unimpl, movb_ra_a, movb_ra_b, /* 0x0600 */ cexec_l, unimpl, cmovgc_a, cmovgc_b, cmovgc_a_s, cmovgc_b_s, cmovcg_a, cmovcg_b, cmovmc_f, cmovmc_f, cmovcm_f, cmovcm_f, cmovcm_b, cmovcm_b, cmovmc_f_va,cmovmc_f_vb, /* 0x0700 */ sext1_a, sext1_b, zext1_a, zext1_b, setf1, setf1, setf1, setf1, move1_ra_a, move1_ra_b, move1_ar_a, move1_ar_b, move1_aa, unimpl, movb_ar_a, movb_ar_b, /* 0x0800 */ trapl, unimpl, cmovmc_b, cmovmc_b, unimpl, vblt_b_l, retm, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, clip, /* 0x0900 */ trap, trap, call_a, call_b, reti, unimpl, rets, rets, mmtm_a, mmtm_b, mmfm_a, mmfm_b, movi_w_a, movi_w_b, movi_l_a, movi_l_b, /* 0x0a00 */ vlcol, unimpl, unimpl, pfill_xy, unimpl, vfill_l, cvmxyl_a, cvmxyl_b, cvdxyl_a, cvdxyl_b, unimpl, fpixeq, unimpl, fpixne, unimpl, unimpl, /* 0x0b00 */ addi_w_a, addi_w_b, addi_l_a, addi_l_b, cmpi_w_a, cmpi_w_b, cmpi_l_a, cmpi_l_b, andi_a, andi_b, ori_a, ori_b, xori_a, xori_b, subi_w_a, subi_w_b, /* 0x0c00 */ addxyi_a, addxyi_b, unimpl, unimpl, unimpl, linit, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x0d00 */ subi_l_a, subi_l_b, unimpl, callr, unimpl, calla, eint, unimpl, dsj_a, dsj_b, dsjeq_a, dsjeq_b, dsjne_a, dsjne_b, setc, unimpl, /* 0x0e00 */ unimpl, pixblt_l_m_l,unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, tfill_xy, /* 0x0f00 */ pixblt_l_l, unimpl, pixblt_l_xy,unimpl, pixblt_xy_l,unimpl, pixblt_xy_xy,unimpl, pixblt_b_l, unimpl, pixblt_b_xy,unimpl, fill_l, unimpl, fill_xy, unimpl, /* 0x1000 */ addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, /* 0x1100 */ addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, /* 0x1200 */ addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, /* 0x1300 */ addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, addk_a, addk_b, /* 0x1400 */ subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, /* 0x1500 */ subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, /* 0x1600 */ subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, /* 0x1700 */ subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, subk_a, subk_b, /* 0x1800 */ movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, /* 0x1900 */ movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, /* 0x1a00 */ movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, /* 0x1b00 */ movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, movk_a, movk_b, /* 0x1c00 */ btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, /* 0x1d00 */ btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, /* 0x1e00 */ btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, /* 0x1f00 */ btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, btst_k_a, btst_k_b, /* 0x2000 */ sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, /* 0x2100 */ sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, /* 0x2200 */ sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, /* 0x2300 */ sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, sla_k_a, sla_k_b, /* 0x2400 */ sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, /* 0x2500 */ sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, /* 0x2600 */ sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, /* 0x2700 */ sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, sll_k_a, sll_k_b, /* 0x2800 */ sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, /* 0x2900 */ sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, /* 0x2a00 */ sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, /* 0x2b00 */ sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, sra_k_a, sra_k_b, /* 0x2c00 */ srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, /* 0x2d00 */ srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, /* 0x2e00 */ srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, /* 0x2f00 */ srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, srl_k_a, srl_k_b, /* 0x3000 */ rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, /* 0x3100 */ rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, /* 0x3200 */ rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, /* 0x3300 */ rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, rl_k_a, rl_k_b, /* 0x3400 */ cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, /* 0x3500 */ cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, /* 0x3600 */ cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, /* 0x3700 */ cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, cmp_k_a, cmp_k_b, /* 0x3800 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3900 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3a00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3b00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3c00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3d00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3e00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x3f00 */ dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, dsjs_a, dsjs_b, /* 0x4000 */ add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, /* 0x4100 */ add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, add_a, add_b, /* 0x4200 */ addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, /* 0x4300 */ addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, addc_a, addc_b, /* 0x4400 */ sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, /* 0x4500 */ sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, sub_a, sub_b, /* 0x4600 */ subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, /* 0x4700 */ subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, subb_a, subb_b, /* 0x4800 */ cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, /* 0x4900 */ cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, cmp_a, cmp_b, /* 0x4a00 */ btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, /* 0x4b00 */ btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, btst_r_a, btst_r_b, /* 0x4c00 */ move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, /* 0x4d00 */ move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, move_rr_a, move_rr_b, /* 0x4e00 */ move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, /* 0x4f00 */ move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, move_rr_ax, move_rr_bx, /* 0x5000 */ and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, /* 0x5100 */ and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, and_a, and_b, /* 0x5200 */ andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, /* 0x5300 */ andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, andn_a, andn_b, /* 0x5400 */ or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, /* 0x5500 */ or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, or_a, or_b, /* 0x5600 */ xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, /* 0x5700 */ xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, xor_a, xor_b, /* 0x5800 */ divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, /* 0x5900 */ divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, divs_a, divs_b, /* 0x5a00 */ divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, /* 0x5b00 */ divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, divu_a, divu_b, /* 0x5c00 */ mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, /* 0x5d00 */ mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, mpys_a, mpys_b, /* 0x5e00 */ mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, /* 0x5f00 */ mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, mpyu_a, mpyu_b, /* 0x6000 */ sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, /* 0x6100 */ sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, sla_r_a, sla_r_b, /* 0x6200 */ sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, /* 0x6300 */ sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, sll_r_a, sll_r_b, /* 0x6400 */ sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, /* 0x6500 */ sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, sra_r_a, sra_r_b, /* 0x6600 */ srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, /* 0x6700 */ srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, srl_r_a, srl_r_b, /* 0x6800 */ rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, /* 0x6900 */ rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, rl_r_a, rl_r_b, /* 0x6a00 */ lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, /* 0x6b00 */ lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, lmo_a, lmo_b, /* 0x6c00 */ mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, /* 0x6d00 */ mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, mods_a, mods_b, /* 0x6e00 */ modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, /* 0x6f00 */ modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, modu_a, modu_b, /* 0x7000 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7100 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7200 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7300 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7400 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7500 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7600 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7700 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7800 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7900 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7a00 */ rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, /* 0x7b00 */ rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, rmo_a, rmo_b, /* 0x7c00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7d00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x7e00 */ swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, /* 0x7f00 */ swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, swapf_a, swapf_b, /* 0x8000 */ move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, /* 0x8100 */ move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, move0_rn_a, move0_rn_b, /* 0x8200 */ move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, /* 0x8300 */ move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, move1_rn_a, move1_rn_b, /* 0x8400 */ move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, /* 0x8500 */ move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, move0_nr_a, move0_nr_b, /* 0x8600 */ move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, /* 0x8700 */ move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, move1_nr_a, move1_nr_b, /* 0x8800 */ move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, /* 0x8900 */ move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, move0_nn_a, move0_nn_b, /* 0x8a00 */ move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, /* 0x8b00 */ move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, move1_nn_a, move1_nn_b, /* 0x8c00 */ movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, /* 0x8d00 */ movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, movb_rn_a, movb_rn_b, /* 0x8e00 */ movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, /* 0x8f00 */ movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, movb_nr_a, movb_nr_b, /* 0x9000 */ move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, /* 0x9100 */ move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, move0_r_ni_a, move0_r_ni_b, /* 0x9200 */ move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, /* 0x9300 */ move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, move1_r_ni_a, move1_r_ni_b, /* 0x9400 */ move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, /* 0x9500 */ move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, move0_ni_r_a, move0_ni_r_b, /* 0x9600 */ move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, /* 0x9700 */ move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, move1_ni_r_a, move1_ni_r_b, /* 0x9800 */ move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, /* 0x9900 */ move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, move0_ni_ni_a, move0_ni_ni_b, /* 0x9a00 */ move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, /* 0x9b00 */ move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, move1_ni_ni_a, move1_ni_ni_b, /* 0x9c00 */ movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, /* 0x9d00 */ movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, movb_nn_a, movb_nn_b, /* 0x9e00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0x9f00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xa000 */ move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, /* 0xa100 */ move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, move0_r_dn_a, move0_r_dn_b, /* 0xa200 */ move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, /* 0xa300 */ move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, move1_r_dn_a, move1_r_dn_b, /* 0xa400 */ move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, /* 0xa500 */ move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, move0_dn_r_a, move0_dn_r_b, /* 0xa600 */ move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, /* 0xa700 */ move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, move1_dn_r_a, move1_dn_r_b, /* 0xa800 */ move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, /* 0xa900 */ move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, move0_dn_dn_a, move0_dn_dn_b, /* 0xaa00 */ move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, /* 0xab00 */ move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, move1_dn_dn_a, move1_dn_dn_b, /* 0xac00 */ movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, /* 0xad00 */ movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, movb_r_no_a, movb_r_no_b, /* 0xae00 */ movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, /* 0xaf00 */ movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, movb_no_r_a, movb_no_r_b, /* 0xb000 */ move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, /* 0xb100 */ move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, move0_r_no_a, move0_r_no_b, /* 0xb200 */ move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, /* 0xb300 */ move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, move1_r_no_a, move1_r_no_b, /* 0xb400 */ move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, /* 0xb500 */ move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, move0_no_r_a, move0_no_r_b, /* 0xb600 */ move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, /* 0xb700 */ move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, move1_no_r_a, move1_no_r_b, /* 0xb800 */ move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, /* 0xb900 */ move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, move0_no_no_a, move0_no_no_b, /* 0xba00 */ move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, /* 0xbb00 */ move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, move1_no_no_a, move1_no_no_b, /* 0xbc00 */ movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, /* 0xbd00 */ movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, movb_no_no_a, movb_no_no_b, /* 0xbe00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xbf00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xc000 */ j_UC_0, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_8, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, j_UC_x, /* 0xc100 */ j_P_0, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, j_P_8, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, j_P_x, /* 0xc200 */ j_LS_0, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_8, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, j_LS_x, /* 0xc300 */ j_HI_0, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_8, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, j_HI_x, /* 0xc400 */ j_LT_0, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_8, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, j_LT_x, /* 0xc500 */ j_GE_0, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_8, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, j_GE_x, /* 0xc600 */ j_LE_0, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_8, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, j_LE_x, /* 0xc700 */ j_GT_0, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_8, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, j_GT_x, /* 0xc800 */ j_C_0, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, j_C_8, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, j_C_x, /* 0xc900 */ j_NC_0, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_8, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, j_NC_x, /* 0xca00 */ j_EQ_0, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_8, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, j_EQ_x, /* 0xcb00 */ j_NE_0, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_8, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, j_NE_x, /* 0xcc00 */ j_V_0, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, j_V_8, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, j_V_x, /* 0xcd00 */ j_NV_0, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_8, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, j_NV_x, /* 0xce00 */ j_N_0, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, j_N_8, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, j_N_x, /* 0xcf00 */ j_NN_0, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_8, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, j_NN_x, /* 0xd000 */ move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, /* 0xd100 */ move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, move0_no_ni_a, move0_no_ni_b, /* 0xd200 */ move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, /* 0xd300 */ move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, move1_no_ni_a, move1_no_ni_b, /* 0xd400 */ move0_a_ni_a,move0_a_ni_b,unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xd500 */ exgf0_a, exgf0_b, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xd600 */ move1_a_ni_a,move1_a_ni_b,unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xd700 */ exgf1_a, exgf1_b, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xd800 */ cexec_s, cexec_s, cexec_s, cexec_s, cexec_s, cexec_s, cexec_s, cexec_s, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xd900 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xda00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xdb00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xdc00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xdd00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xde00 */ unimpl, fline, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, fline, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xdf00 */ unimpl, line, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, line, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xe000 */ add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, /* 0xe100 */ add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, add_xy_a, add_xy_b, /* 0xe200 */ sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, /* 0xe300 */ sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, sub_xy_a, sub_xy_b, /* 0xe400 */ cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, /* 0xe500 */ cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, cmp_xy_a, cmp_xy_b, /* 0xe600 */ cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, /* 0xe700 */ cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, cpw_a, cpw_b, /* 0xe800 */ cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, /* 0xe900 */ cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, cvxyl_a, cvxyl_b, /* 0xea00 */ cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, /* 0xeb00 */ cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, cvsxyl_a, cvsxyl_b, /* 0xec00 */ movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, /* 0xed00 */ movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, movx_a, movx_b, /* 0xee00 */ movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, /* 0xef00 */ movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, movy_a, movy_b, /* 0xf000 */ pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, /* 0xf100 */ pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, pixt_rixy_a, pixt_rixy_b, /* 0xf200 */ pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, /* 0xf300 */ pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, pixt_ixyr_a, pixt_ixyr_b, /* 0xf400 */ pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, /* 0xf500 */ pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, pixt_ixyixy_a, pixt_ixyixy_b, /* 0xf600 */ drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, /* 0xf700 */ drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, drav_a, drav_b, /* 0xf800 */ pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, /* 0xf900 */ pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, pixt_ri_a, pixt_ri_b, /* 0xfa00 */ pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, /* 0xfb00 */ pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, pixt_ir_a, pixt_ir_b, /* 0xfc00 */ pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, /* 0xfd00 */ pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, pixt_ii_a, pixt_ii_b, /* 0xfe00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, /* 0xff00 */ unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl, unimpl };
the_stack_data/40331.c
#include <stdio.h> void scilab_rt_champ_i2d2i2d2i0d2_(int in00, int in01, int matrixin0[in00][in01], int in10, int in11, double matrixin1[in10][in11], int in20, int in21, int matrixin2[in20][in21], int in30, int in31, double matrixin3[in30][in31], int scalarin0, int in40, int in41, double matrixin4[in40][in41]) { int i; int j; int val0 = 0; double val1 = 0; int val2 = 0; double val3 = 0; double val4 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%d", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%f", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%d", val2); for (i = 0; i < in30; ++i) { for (j = 0; j < in31; ++j) { val3 += matrixin3[i][j]; } } printf("%f", val3); printf("%d", scalarin0); for (i = 0; i < in40; ++i) { for (j = 0; j < in41; ++j) { val4 += matrixin4[i][j]; } } printf("%f", val4); }
the_stack_data/1018262.c
/* * Program to copy between two files * usage cp file1 file2 * * Author: NagaChaitanya Vellanki * */ #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #ifndef BUF_SISZE #define BUF_SIZE 1024 #endif int main(int argc, char *argv[]) { int inputFd, outputFd, openFlags; mode_t filePerms; ssize_t numRead; char buf[BUF_SIZE]; if((argc != 3) || (strcmp(argv[1], "--help") == 0)) { printf("%s old-file new-file\n", argv[0]); exit(EXIT_FAILURE); } /* Open input and output files */ inputFd = open(argv[1], O_RDONLY); if(inputFd == -1) { printf("error opening file %s\n", argv[1]); exit(EXIT_FAILURE); } openFlags = O_CREAT | O_WRONLY | O_TRUNC; filePerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; outputFd = open(argv[2], openFlags, filePerms); if(outputFd == -1) { printf("error opening file %s\n", argv[2]); exit(EXIT_FAILURE); } while((numRead = read(inputFd, buf, BUF_SIZE)) > 0) { if(write(outputFd, buf, numRead) != numRead) { printf("could not write the whole buffer\n"); exit(EXIT_FAILURE); } } if(numRead == -1) { printf("error while reading\n"); } if(close(inputFd)) { printf("could not close input file descriptor\n"); exit(EXIT_FAILURE); } if(close(outputFd)) { printf("could not close output file descriptor\n"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
the_stack_data/32949931.c
#include <math.h> double trunc(double d) { return d > 0 ? floor(d) : ceil(d); }
the_stack_data/149508.c
#include <stdlib.h> int *majorityElement(int *nums, int numsSize, int *returnSize) { int i, e1, e2, c1, c2; int e1vld, e2vld; int *res; /* * tell if e1 or e2 is validate */ e1vld = e2vld = 0; c1 = c2 = 0; for (i = 0; i < numsSize; i++) { if (e1vld && e1 == nums[i]) { c1++; } else if (e2vld && e2 == nums[i]) { c2++; } else if (c1 == 0) { e1vld = 1; e1 = nums[i]; c1 = 1; } else if (c2 == 0) { e2vld = 1; e2 = nums[i]; c2 = 1; } else { c1--; c2--; } } c1 = c2 = 0; for (i = 0; i < numsSize; i++) { if (e1vld && e1 == nums[i]) c1++; else if (e2vld && e2 == nums[i]) c2++; } res = malloc(2 * sizeof(int)); i = 0; if (e1vld && c1 > numsSize / 3) res[i++] = e1; if (e2vld && c2 > numsSize / 3) res[i++] = e2; *returnSize = i; return(res); } int main(void) { }
the_stack_data/28973.c
#include <stdio.h> int main() { int a, b; while (EOF != scanf("%d%d", &a, &b) && !(a == 0 && b == 0)) { printf("%d\n", a+b); } return 0; }
the_stack_data/1111217.c
// Copyright (c) 2017, Herman Bergwerf. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. #include <curses.h> #include <stdio.h> #include <string.h> /// All editor data. typedef struct { WINDOW *window; /// File path specified at startup. char *filePath; /// Array of NULL-terminated text strings containing each line. /// Note: this should probably be a linked list. char **textBuffer; /// Total number of lines. int lineCount; /// Current scrolling offset. int rowOffset; int colOffset; } EditorData; int getLineLength(EditorData *data, int row) { return strlen(data->textBuffer[row]); } /// Not the most efficent, but for now the easiest approach. void redrawEditor(EditorData *data) { // Get dimensions and erase. int w = 0, h = 0; getmaxyx(data->window, h, w); // Note: this is an ugly dirty macro. erase(); // Draw each line. int offset = data->colOffset; for (int i = 0; i < h && i + data->rowOffset < data->lineCount; i++) { char *lineText = data->textBuffer[i + data->rowOffset]; int lineLength = strlen(lineText); int relLength = lineLength - offset; if (relLength > 0) { mvaddnstr(i, 0, lineText + offset, relLength > w ? w : relLength); } } // Refresh screen. refresh(); } /// Insert newline after the given row in the buffer. Returns true on error. bool insertLine(EditorData *data, int row) { if (data->lineCount <= row || row < -1) return true; // Reallocate array of line pointers. int newLineCount = data->lineCount + 1; char **textBuffer = (char **)malloc(newLineCount * sizeof(char *)); // Move over all old pointers. int offset = 0; for (int i = 0; i < newLineCount; i++) { if (i == row + 1) { char *emptyLine = (char *)malloc(1); emptyLine[0] = 0; textBuffer[i] = emptyLine; offset = 1; } else { textBuffer[i] = data->textBuffer[i - offset]; } } // Swap and free. free(data->textBuffer); data->textBuffer = textBuffer; data->lineCount = newLineCount; return false; } /// Insert the given fragment of length n at the given position in the text /// buffer in the given editor. Returns true on error. bool insertText(EditorData *data, int row, int col, char *fragment, int n) { if (data->lineCount <= row) return true; char *oldLine = data->textBuffer[row]; int oldLineLength = strlen(oldLine); if (oldLineLength < col) return true; // Reallocate the given line and copy the old line while inserting fragment. char *newLine = (char *)malloc(oldLineLength + n + 1); strncpy(newLine, oldLine, col); strncpy(newLine + col, fragment, n); strncpy(newLine + col + n, oldLine + col, oldLineLength - col); // Ensure the string is NULL-terminated. newLine[oldLineLength + n] = 0; // Swap and free. data->textBuffer[row] = newLine; free(oldLine); return false; } /// Delete n characters from the given position in the text buffer going /// backward. Returns true on error. bool removeText(EditorData *data, int row, int col, int n) { if (data->lineCount <= row) return true; if (col < n) return true; char *oldLine = data->textBuffer[row]; int oldLineLength = strlen(oldLine); if (oldLineLength < col) return true; // Reallocate the given line and copy parts of the old line. char *newLine = (char *)malloc(oldLineLength - n + 1); strncpy(newLine, oldLine, col - n); strncpy(newLine + col - n, oldLine + col, oldLineLength - col); // Ensure the string is NULL-terminated. newLine[oldLineLength - n] = 0; // Swap and free. data->textBuffer[row] = newLine; free(oldLine); return false; } /// Save editor text to given file. bool saveAsFile(EditorData *data) { FILE *file; if (file = fopen(data->filePath, "w")) { for (int i = 0; i < data->lineCount; i++) { char *lineText = data->textBuffer[i]; fwrite(lineText, 1, strlen(lineText), file); fputc('\n', file); } fclose(file); return false; } else { return true; } } /// Restore editor text from file. bool restoreFromFile(EditorData *data) { FILE *file; if (file = fopen(data->filePath, "r")) { // Obtain file size. fseek(file, 0, SEEK_END); int fileSize = ftell(file); rewind(file); // Allocate memory to contain the whole file. char *buffer = (char *)malloc(fileSize); // Copy the file into the buffer. int result = fread(buffer, 1, fileSize, file); fclose(file); // Split into lines. if (result != fileSize) { free(buffer); return true; } else { // Count lines. int lineCount = 0; for (int i = 0; i < fileSize; i++) { // TODO: This is not very nice, the buffer cannot contain NULLs. if (buffer[i] == '\n') { lineCount++; } } // Allocate line array. data->lineCount = lineCount; data->textBuffer = (char **)malloc(lineCount * sizeof(char *)); // Copy data to lines. // It is neccesary to allocate new buffers or else they cannot be freed // seperately. int lineIndex = 0, lineLength = 0; for (int i = 0; i < fileSize; i++) { if (buffer[i] == '\n') { // Clone string. char *line = (char *)malloc(lineLength + 1); strncpy(line, (char *)(buffer + i - lineLength), lineLength); line[lineLength] = 0; // Store in buffer and move on. data->textBuffer[lineIndex] = line; lineIndex++; lineLength = 0; } else { lineLength++; } } free(buffer); return false; } } else { return true; } }
the_stack_data/87131.c
// WARNING in hsr_dev_finalize // https://syzkaller.appspot.com/bug?id=7f1c020f68dab95aab59 // status:6 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <errno.h> #include <fcntl.h> #include <sched.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <linux/capability.h> #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } #define MAX_FDS 30 static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } loop(); exit(1); } static void close_fds() { int fd; for (fd = 3; fd < MAX_FDS; fd++) close(fd); } uint64_t r[6] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0}; void loop(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[0] = res; res = syscall(__NR_socket, 0x10ul, 0x803ul, 0); if (res != -1) r[1] = res; *(uint64_t*)0x200001c0 = 0; *(uint32_t*)0x200001c8 = 0; *(uint64_t*)0x200001d0 = 0x20000180; *(uint64_t*)0x20000180 = 0; *(uint64_t*)0x20000188 = 0; *(uint64_t*)0x200001d8 = 1; *(uint64_t*)0x200001e0 = 0; *(uint64_t*)0x200001e8 = 0; *(uint32_t*)0x200001f0 = 0; syscall(__NR_sendmsg, r[1], 0x200001c0ul, 0ul); res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[2] = res; res = syscall(__NR_socket, 0x10ul, 0x803ul, 0); if (res != -1) r[3] = res; syscall(__NR_sendto, r[3], 0ul, 0ul, 0ul, 0ul, 0ul); *(uint32_t*)0x20000200 = 0x14; res = syscall(__NR_getsockname, r[3], 0x20000100ul, 0x20000200ul); if (res != -1) r[4] = *(uint32_t*)0x20000104; *(uint64_t*)0x20000040 = 0; *(uint32_t*)0x20000048 = 0; *(uint64_t*)0x20000050 = 0x20000000; *(uint64_t*)0x20000000 = 0x20000080; memcpy((void*)0x20000080, "\x48\x00\x00\x00\x10\x00\x05\x07\x00\x00\x00\x66" "\x08\x00\x0b\x75\x31\xef\x8e\x55", 20); *(uint32_t*)0x20000094 = r[4]; memcpy((void*)0x20000098, "\x00\x00\x00\x00\x00\x00\x00\x00\x28\x00\x12\x00" "\x09\x00\x01\x00\x76\x65\x74\x68", 20); *(uint64_t*)0x20000008 = 0x48; *(uint64_t*)0x20000058 = 1; *(uint64_t*)0x20000060 = 0; *(uint64_t*)0x20000068 = 0; *(uint32_t*)0x20000070 = 0; syscall(__NR_sendmsg, r[2], 0x20000040ul, 0ul); *(uint32_t*)0x20000200 = 0x14; res = syscall(__NR_getsockname, r[1], 0x20000100ul, 0x20000200ul); if (res != -1) r[5] = *(uint32_t*)0x20000104; *(uint64_t*)0x20000240 = 0; *(uint32_t*)0x20000248 = 3; *(uint64_t*)0x20000250 = 0x20000140; *(uint64_t*)0x20000140 = 0x20000000; *(uint32_t*)0x20000000 = 0x48; *(uint16_t*)0x20000004 = 0x10; *(uint16_t*)0x20000006 = 0x401; *(uint32_t*)0x20000008 = 0; *(uint32_t*)0x2000000c = 0; *(uint8_t*)0x20000010 = 0; *(uint8_t*)0x20000011 = 0; *(uint16_t*)0x20000012 = 0; *(uint32_t*)0x20000014 = 0; *(uint32_t*)0x20000018 = 0; *(uint32_t*)0x2000001c = 0; *(uint16_t*)0x20000020 = 0x20; STORE_BY_BITMASK(uint16_t, , 0x20000022, 0x12, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000023, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000023, 1, 7, 1); *(uint16_t*)0x20000024 = 8; *(uint16_t*)0x20000026 = 1; memcpy((void*)0x20000028, "hsr\000", 4); *(uint16_t*)0x2000002c = 0x14; STORE_BY_BITMASK(uint16_t, , 0x2000002e, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000002f, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000002f, 1, 7, 1); *(uint16_t*)0x20000030 = 8; *(uint16_t*)0x20000032 = 1; *(uint32_t*)0x20000034 = r[4]; *(uint16_t*)0x20000038 = 8; *(uint16_t*)0x2000003a = 2; *(uint32_t*)0x2000003c = r[5]; *(uint16_t*)0x20000040 = 8; *(uint16_t*)0x20000042 = 0xa; *(uint32_t*)0x20000044 = 0; *(uint64_t*)0x20000148 = 0x48; *(uint64_t*)0x20000258 = 1; *(uint64_t*)0x20000260 = 0; *(uint64_t*)0x20000268 = 0; *(uint32_t*)0x20000270 = 0; syscall(__NR_sendmsg, r[0], 0x20000240ul, 0ul); close_fds(); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); do_sandbox_none(); return 0; }
the_stack_data/243893749.c
/* sizeof_packed.c */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdint.h> /* per la definizione dei tipi interi */ int main(void) { typedef struct struttura { uint32_t i; uint8_t c; } __attribute__ (( packed )) STRUTTURA; STRUTTURA s; STRUTTURA vet[10]; printf( "dimensione variabile struttura packed s %ld \n" , sizeof(s) ); printf( "dimensione vettore di strutture packed vet %ld \n" , sizeof(vet) ); return(0); }