/* Fill a preallocated vector arguments, doing expansion and all. * Assumes Tcl will * not tamper with our strings * make copies if strings are "persistent" */ int fill_args (char **argv, int where, value v) { value l; switch (Tag_val(v)) { case 0: argv[where] = caml_string_to_tcl(Field(v,0)); /* must free by stat_free */ return (where + 1); case 1: for (l=Field(v,0); Is_block(l); l=Field(l,1)) where = fill_args(argv,where,Field(l,0)); return where; case 2: { char **tmpargv; char *merged; int i; int size = argv_size(Field(v,0)); tmpargv = (char **)stat_alloc((size + 1) * sizeof(char *)); fill_args(tmpargv,0,Field(v,0)); tmpargv[size] = NULL; merged = Tcl_Merge(size,tmpargv); for(i = 0; i<size; i++){ stat_free(tmpargv[i]); } stat_free((char *)tmpargv); /* must be freed by stat_free */ argv[where] = (char*)stat_alloc(strlen(merged)+1); strcpy(argv[where], merged); Tcl_Free(merged); return (where + 1); } default: tk_error("fill_args: illegal tag"); } }
static int check_fill_args(const char *input, int len, int addspace, const char *expect, char **resultp) { if (!fill_args(input, len, addspace)) return -1; *resultp = sudoerslval.command.args; return !strcmp(sudoerslval.command.args, expect); }
static int check_fill_args(const char *input, int len, int addspace, const char *expect, char **resultp) { /* Must not free old sudoerslval.command.args as gets appended to. */ if (!fill_args(input, len, addspace)) return -1; *resultp = sudoerslval.command.args; return !strcmp(sudoerslval.command.args, expect); }
int get_args(char *src_str, char ***dest_args) { int nb_args; int nb_allocated_args; nb_args = count_args(src_str); if (nb_args < 0) return (-1); if ((*dest_args = malloc(sizeof(char *) * nb_args + 1)) == NULL) return (-1); (*dest_args)[nb_args] = NULL; if ((nb_allocated_args = fill_args(*dest_args, src_str)) != nb_args) { free_args(dest_args, nb_allocated_args); return (-1); } return (nb_args); }
/* v is an array of TkArg */ CAMLprim value camltk_tcl_direct_eval(value v) { int i; int size; /* size of argv */ char **argv, **allocated; int result; Tcl_CmdInfo info; CheckInit(); /* walk the array to compute final size for Tcl */ for(i=0, size=0; i<Wosize_val(v); i++) size += argv_size(Field(v,i)); /* +2: one slot for NULL one slot for "unknown" if command not found */ argv = (char **)stat_alloc((size + 2) * sizeof(char *)); allocated = (char **)stat_alloc(size * sizeof(char *)); /* Copy -- argv[i] must be freed by stat_free */ { int where; for(i=0, where=0; i<Wosize_val(v); i++){ where = fill_args(argv,where,Field(v,i)); } if( size != where ){ tk_error("fill_args error!!! Call the CamlTk maintainer!"); } for(i=0; i<where; i++){ allocated[i] = argv[i]; } argv[size] = NULL; argv[size + 1] = NULL; } /* Eval */ Tcl_ResetResult(cltclinterp); if (Tcl_GetCommandInfo(cltclinterp,argv[0],&info)) { /* command found */ #if (TCL_MAJOR_VERSION >= 8) /* info.proc might be a NULL pointer * We should probably attempt an Obj invocation, but the following quick * hack is easier. */ if (info.proc == NULL) { Tcl_DString buf; Tcl_DStringInit(&buf); Tcl_DStringAppend(&buf, argv[0], -1); for (i=1; i<size; i++) { Tcl_DStringAppend(&buf, " ", -1); Tcl_DStringAppend(&buf, argv[i], -1); } result = Tcl_Eval(cltclinterp, Tcl_DStringValue(&buf)); Tcl_DStringFree(&buf); } else { result = (*info.proc)(info.clientData,cltclinterp,size,argv); } #else result = (*info.proc)(info.clientData,cltclinterp,size,argv); #endif } else { /* implement the autoload stuff */ if (Tcl_GetCommandInfo(cltclinterp,"unknown",&info)) { /* unknown found */ for (i = size; i >= 0; i--) argv[i+1] = argv[i]; argv[0] = "unknown"; result = (*info.proc)(info.clientData,cltclinterp,size+1,argv); } else { /* ah, it isn't there at all */ result = TCL_ERROR; Tcl_AppendResult(cltclinterp, "Unknown command \"", argv[0], "\"", NULL); } } /* Free the various things we allocated */ for(i=0; i< size; i ++){ stat_free((char *) allocated[i]); } stat_free((char *)argv); stat_free((char *)allocated); switch (result) { case TCL_OK: return tcl_string_to_caml (Tcl_GetStringResult(cltclinterp)); case TCL_ERROR: tk_error(Tcl_GetStringResult(cltclinterp)); default: /* TCL_BREAK, TCL_CONTINUE, TCL_RETURN */ tk_error("bad tcl result"); } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LLMemType mt1(LLMemType::MTYPE_STARTUP); // *FIX: global gIconResource = MAKEINTRESOURCE(IDI_LL_ICON); // In Win32, we need to generate argc and argv ourselves... // Note: GetCommandLine() returns a potentially return a LPTSTR // which can resolve to a LPWSTR (unicode string). // (That's why it's different from lpCmdLine which is a LPSTR.) // We don't currently do unicode, so call the non-unicode version // directly. LPSTR cmd_line_including_exe_name = GetCommandLineA(); const S32 MAX_ARGS = 100; int argc = 0; char* argv[MAX_ARGS]; /* Flawfinder: ignore */ fill_args(argc, argv, MAX_ARGS, cmd_line_including_exe_name); LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(); // *FIX:Mani This method is poorly named, since the exception // is now handled by LLApp. bool ok = LLWinDebug::setupExceptionHandler(); // Actually here's the exception setup. LPTOP_LEVEL_EXCEPTION_FILTER prev_filter; prev_filter = SetUnhandledExceptionFilter(viewer_windows_exception_handler); if (!prev_filter) { llwarns << "Our exception handler (" << (void *)LLWinDebug::handleException << ") replaced with NULL!" << llendl; ok = FALSE; } if (prev_filter != LLWinDebug::handleException) { llwarns << "Our exception handler (" << (void *)LLWinDebug::handleException << ") replaced with " << prev_filter << "!" << llendl; ok = FALSE; } viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); ok = viewer_app_ptr->tempStoreCommandOptions(argc, argv); if(!ok) { llwarns << "Unable to parse command line." << llendl; return -1; } ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // viewer_app_ptr->cleanup(); } delete viewer_app_ptr; viewer_app_ptr = NULL; return 0; }
static void syscall_handler (struct intr_frame *f) { // Validate call number test_bad_address(f->esp); //Arguments passed to syscall, can only have 3 at most int funcArgs[3]; int* syscall_id = (int*)f->esp; switch (*syscall_id) { case SYS_EXIT: { fill_args(f, &funcArgs[0], 1); exit(funcArgs[0]); break; } case SYS_WAIT: { fill_args(f, &funcArgs[0], 1); f->eax = wait(funcArgs[0]); break; } case SYS_HALT: { halt(); break; } case SYS_WRITE: { fill_args(f, &funcArgs[0], 3); void* kp = kptr((const void*)funcArgs[1]); f->eax = write(funcArgs[0], (const char*)kp, (unsigned)funcArgs[2]); break; } case SYS_READ: { fill_args(f, &funcArgs[0], 3); void* kp = kptr((const void*)funcArgs[1]); f->eax = read(funcArgs[0], kp, (unsigned)funcArgs[2]); break; } case SYS_EXEC: { fill_args(f, &funcArgs[0], 1); void* kp = kptr((const void*)funcArgs[0]); f->eax = exec((const char*)kp); break; } case SYS_CREATE: { fill_args(f, &funcArgs[0], 2); void* kp = kptr((const void*)funcArgs[0]); f->eax = create((const char*)kp, (unsigned)funcArgs[1]); break; } case SYS_REMOVE: { fill_args(f, &funcArgs[0], 1); void* kp = kptr((const void*)funcArgs[0]); f->eax = remove((const char*)kp); break; } case SYS_OPEN: { fill_args(f, &funcArgs[0], 1); void* kp = kptr((const void*)funcArgs[0]); f->eax = open((const char*)kp); break; } case SYS_FILESIZE: { fill_args(f, &funcArgs[0], 1); f->eax = filesize(funcArgs[0]); break; } case SYS_SEEK: { fill_args(f, &funcArgs[0], 2); seek(funcArgs[0], (unsigned)funcArgs[1]); break; } case SYS_TELL: { fill_args(f, &funcArgs[0], 1); f->eax = tell(funcArgs[0]); } default: break; } }