28 #include <oc_stdlib.h> 38 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 48 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 56 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 58 void ProgramThread(
void * UserPointer );
59 bool CloseProcess(
oC_Thread_t Thread,
void * Process, uint32_t Parameter );
61 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 69 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 77 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 84 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 93 if(oC_Program_IsCorrect(Program) && oC_User_IsCorrect(User))
95 oC_Stream_t _stdin = oC_StreamMan_GetStream(Program->StdInName);
96 oC_Stream_t _stdout = oC_StreamMan_GetStream(Program->StdOutName);
97 oC_Stream_t _stderr = oC_StreamMan_GetStream(Program->StdErrName);
98 process = oC_Process_New(Program->Priority,Program->Name,User,Program->HeapMapSize,_stdin,_stdout,_stderr);
102 oC_SaveIfFalse(
"Program::NewProcess - cannot set memory limit " , oC_Process_SetAllocationLimit (process, Program->AllocationLimit ) , oC_ErrorCode_ObjectNotCorrect);
103 oC_SaveIfFalse(
"Program::NewProcess - cannot set memory tracking " , oC_Process_SetAllocationTracking(process, Program->TrackAllocations) , oC_ErrorCode_ObjectNotCorrect);
112 oC_Program_t oC_Program_New( oC_Program_Priority_t Priority ,
char * Name , oC_Program_MainFunction_t MainFunction ,
char * StdInName ,
char * StdOutName ,
char * StdErrName , oC_UInt_t HeapMapSize )
117 isaddresscorrect(Name) &&
118 isaddresscorrect(MainFunction) &&
119 isaddresscorrect(StdInName) &&
120 isaddresscorrect(StdOutName) &&
121 isaddresscorrect(StdOutName)
128 program->Priority = Priority;
129 program->MainFunction = MainFunction;
130 program->HeapMapSize = HeapMapSize;
131 program->ThreadStackSize= 0;
135 program->Name = Name;
139 program->Name = ksmartalloc(strlen(Name)+1 , &Allocator , AllocationFlags_NoWait);
140 strcpy(program->Name,Name);
145 program->StdInName = StdInName;
149 program->StdInName = ksmartalloc(strlen(StdInName)+1 , &Allocator , AllocationFlags_NoWait);
150 strcpy(program->StdInName,StdInName);
152 if(isrom(StdOutName))
154 program->StdOutName = StdOutName;
158 program->StdOutName = ksmartalloc(strlen(StdOutName)+1 , &Allocator , AllocationFlags_NoWait);
159 strcpy(program->StdOutName,StdOutName);
162 if(isrom(StdErrName))
164 program->StdErrName = StdErrName;
168 program->StdErrName = ksmartalloc(strlen(StdErrName)+1 , &Allocator , AllocationFlags_NoWait);
169 strcpy(program->StdErrName,StdErrName);
182 bool deleted =
false;
189 if(!ksmartfree((*Program)->Name,strlen((*Program)->Name)+1,AllocationFlags_CanWaitForever))
197 if(!ksmartfree((*Program)->StdInName,strlen((*Program)->StdInName)+1,AllocationFlags_CanWaitForever))
205 if(!ksmartfree((*Program)->StdOutName,strlen((*Program)->StdOutName)+1,AllocationFlags_CanWaitForever))
213 if(!ksmartfree((*Program)->StdErrName,strlen((*Program)->StdErrName)+1,AllocationFlags_CanWaitForever))
231 return isaddresscorrect(Program);
237 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
240 oC_AssignErrorCodeIfFalse(&errorCode, oC_Program_IsCorrect(Program) , oC_ErrorCode_ObjectNotCorrect ) &&
241 oC_AssignErrorCodeIfFalse(&errorCode, isaddresscorrect(Argv) , oC_ErrorCode_WrongAddress ) &&
242 oC_AssignErrorCodeIfFalse(&errorCode, oC_Process_IsCorrect(Process) , oC_ErrorCode_ObjectNotCorrect ) &&
243 oC_AssignErrorCodeIfFalse(&errorCode, outMainThread ==
NULL || isram(outMainThread) , oC_ErrorCode_OutputAddressNotInRAM )
247 Allocator_t allocator = oC_Process_GetAllocator(Process);
251 programContext->Process = Process;
252 programContext->Program = Program;
253 programContext->Argv = kmalloc(Argc *
sizeof(
char*),allocator,AllocationFlags_CanWait1Second);
254 programContext->Argc = Argc;
261 errorCode = oC_ErrorCode_None;
263 if(isram(programContext->Argv)==
false)
265 errorCode = oC_ErrorCode_AllocationError;
269 for(
int argumentIndex = 0; argumentIndex < Argc && !oC_ErrorOccur(errorCode) ; argumentIndex++ )
271 if(isaddresscorrect(Argv[argumentIndex]))
273 programContext->Argv[argumentIndex] = kmalloc(strlen(Argv[argumentIndex])+1,allocator,AllocationFlags_CanWait500Msecond);
275 if(isram(programContext->Argv[argumentIndex]))
277 strcpy(programContext->Argv[argumentIndex],Argv[argumentIndex]);
281 errorCode = oC_ErrorCode_AllocationError;
286 errorCode = oC_ErrorCode_WrongAddress;
290 if(oC_ErrorOccur(errorCode))
295 oC_Thread_t thread = oC_Thread_New( oC_Process_GetPriority(Process) ,Program->ThreadStackSize,Process,Program->Name,ProgramThread,programContext);
299 kfree(programContext,AllocationFlags_CanWaitForever);
300 errorCode = oC_ErrorCode_AllocationError;
304 if(oC_ProcessMan_ContainsProcess(Process) ==
false)
306 errorCode = oC_ProcessMan_AddProcess(Process);
309 if(oC_ProcessMan_ContainsProcess(Process))
311 if(oC_Thread_Run(thread))
313 if(outMainThread !=
NULL)
315 *outMainThread = thread;
317 oC_SaveIfFalse(
"Cannot save CloseProcess to revert", oC_Thread_SaveToRevert(thread,CloseProcess,Process,0), oC_ErrorCode_InternalDataAreDamaged);
318 errorCode = oC_ErrorCode_None;
322 errorCode = oC_ErrorCode_ImplementError;
327 oC_SaveIfFalse(
"Thread", oC_Thread_Delete(&thread) , oC_ErrorCode_ReleaseError);
333 errorCode = oC_ErrorCode_AllocationError;
343 const char * name =
"program not correct";
345 if(oC_Program_IsCorrect(Program))
347 name = Program->Name;
354 const char * oC_Program_GetStdInName(
oC_Program_t Program )
356 const char * name =
"program not correct";
358 if(oC_Program_IsCorrect(Program))
360 name = Program->StdInName;
367 const char * oC_Program_GetStdOutName(
oC_Program_t Program )
369 const char * name =
"program not correct";
371 if(oC_Program_IsCorrect(Program))
373 name = Program->StdOutName;
380 const char * oC_Program_GetStdErrName(
oC_Program_t Program )
382 const char * name =
"program not correct";
384 if(oC_Program_IsCorrect(Program))
386 name = Program->StdErrName;
393 oC_Program_Priority_t oC_Program_GetPriority(
oC_Program_t Program )
395 oC_Program_Priority_t priority = 0;
397 if(oC_Program_IsCorrect(Program))
399 priority = Program->Priority;
405 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 412 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 416 void ProgramThread(
void * UserPointer )
420 if(isaddresscorrect(programContext) && isaddresscorrect(programContext->Program) && isaddresscorrect(programContext->Program->MainFunction))
422 int ret = programContext->Program->MainFunction(programContext->Argc,(
const char **)programContext->Argv);
426 oC_SaveError(programContext->Program->Name,(oC_ErrorCode_t)ret);
429 if(oC_Process_Kill(programContext->Process)==
false)
431 oC_SaveError(
"Cannot kill process " , oC_ErrorCode_ReleaseError);
438 bool CloseProcess(
oC_Thread_t Thread,
void * Process, uint32_t Parameter )
440 return oC_Process_Kill(Process);
443 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
The file with interface for programs.
identifier for allocations
The file with interface for process manager.
bool oC_MemMan_IsDynamicAllocatedAddress(const void *Address)
checks if address is in dynamic allocated section
The file with interface for stream manager.
#define NULL
pointer to a zero