CreateNewProc _start()

This forum is for general developer support questions.
Post Reply
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

CreateNewProc _start()

Post by JosDuchIt »

i do read this in the autodoc about the NP_Entry tag

This entry() function has the same prototype as the _start()

Where do i find this prototype?
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: CreateNewProc _start()

Post by salass00 »

JosDuchIt wrote:i do read this in the autodoc about the NP_Entry tag

This entry() function has the same prototype as the _start()

Where do i find this prototype?
In <dos/startup.h>:

Code: Select all

/* Native AmigaDOS program _start() entry function definition. */


int32  _start( STRPTR argstring, int32 arglen, struct ExecBase *sysbase );
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: CreateNewProc _start()

Post by JosDuchIt »

@salass00

thanks, now if i don't need any args what should my call look like ?

Second question: what should the called function do with the last argument provuded? (sysbase) ?
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: CreateNewProc _start()

Post by salass00 »

JosDuchIt wrote:thanks, now if i don't need any args what should my call look like ?
Just do like you would do with main() if you don't need argc & argv:

Code: Select all

int32 _start(void) {
    return 0;
}
Second question: what should the called function do with the last argument provuded? (sysbase) ?
Common usage is to obtain IExec pointer without needing to read from AbsExecBase:

Code: Select all

struct ExecIFace *IExec = (struct ExecIFace *)sysbase->MainInterface;
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: CreateNewProc _start()

Post by colinw »

JosDuchIt wrote: thanks, now if i don't need any args what should my call look like ?
Second question: what should the called function do with the last argument provuded? (sysbase) ?
You must have an old SDK because the include/dos/startup.h file not only provides the correct prototype
info but also has example code and a list of mandatory caveats when starting new processes.

What is in the one you have ?
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: CreateNewProc _start()

Post by JosDuchIt »

@colinw

I think i have a recent one & i guess the caveats you mention are these;
* For this stand-alone DOS startup code example;
* 1) Only dos.library is opened and closed.
* 2) Any workbench startup message is simply fetched and replied to.
* 3) No global library bases or interfaces are initialised.
* 4) No parameters are used from the workbench message or cli.

The example opens the dos.library
May i conclude
-that in a CreateNewProc addressed child entry function this opening & closing of dos.library is not needed ?

- hat any other library used in the child process should be opened in the child's entry function?
Last edited by JosDuchIt on Sun Jan 18, 2015 8:07 pm, edited 1 time in total.
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: CreateNewProc _start()

Post by colinw »

After that you should have the following;

===========================================================================
*
* Mandatory Caveats;
* 1) It is never permissable to open libraries or call any dos.library
* functions or perform any i/o whatsoever, directly or indirectly
* from this process context, before a workbench startup message
* has been fetched from the process structure message port.
*
* 2) After replying to a workench startup message on exit, with the
* IExec->ReplyMsg() function, assume that all process locks and
* streams have gone away instantly, in other words, do nothing after
* the IExec->ReplyMsg() except releasing the exec interface and
* returning back to dos.library.
*
* 3) The _start() function is never to be declared as a void function.
*
* 4) Regardless of how a program is started, via workbench, via shell,
* a dos handler, or anything else, the only acceptable return codes
* are those from the include/dos/dos.h file. eg;
* RETURN_OK = 0 ( No problems, program exited successfully )
* RETURN_WARN = 5 ( Warning only, ie; for 'IF' shell command )
* RETURN_ERROR = 10 ( Something failed normally )
* RETURN_FAIL = 20 ( Severe failure, ie; missing system component )
*
* 5) A meaningfull secondary error code from dos/errors.h must always be
* returning when exiting with a primary code other than RETURN_OK.
*
===========================================================================

Then there is the basic startup example code folllowing....

As this kind of code is started in several ways in DOS, the RunCommand() documentation will explain
how this all works and what functions call what.

Just remember, if your new process code is running in the shared code space that was loaded by another process,
then NP_Child should be set to prevent disaster. Also remember that you must end all dependant child processes
before the parent can exit. There is extensive arbitration code examples at the bottom of the CreateNewProc() autodoc

Of couse, the easiest way to stay out of trouble is to not share resources, library interfaces and such like,
but open and close them from within the child process, same goes for files and locks, loadable code and such like.
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: CreateNewProc _start()

Post by JosDuchIt »

@coln thanks for additional info
@all
How come i have an old page?

Is not Amiupdate taking care of this?
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: CreateNewProc _start()

Post by xenic »

JosDuchIt wrote:@coln thanks for additional info
@all
How come i have an old page?

Is not Amiupdate taking care of this?
My SDK has the information in startup.h that Colin referred to above. If you are using the latest SDK (v53.24) from the Hyperion WEB site you should have the same files too.
AmigaOne X1000 with 2GB memory - OS4.1 FE
Belxjander
Posts: 314
Joined: Mon May 14, 2012 10:26 pm
Location: 日本千葉県松戸市 / Matsudo City, Chiba, Japan
Contact:

Re: CreateNewProc _start()

Post by Belxjander »

I have a similar "solution" to the above with a major point of difference in that...

There is no parent "process" as I have embedded my own dynamic process within a shared library and have it launched as a child of ramlib.

I've done this for Perception-IME and Polymorph-VMM core management processes as they are both designed for long-running client support.

I'm also setting up the library to forward MessageEvent handling through to the central process followed by some kind of sync option for a means of using a "return code".

Hopefully http://github.com/Belxjander/Perception-IME and http://github.com/Belxjander/Polymorph-VMM are useful
Post Reply