Welcome, Guest. Please login or register.

Author Topic: Fake seglist in C...  (Read 7191 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Fake seglist in C...
« on: August 08, 2007, 03:50:31 PM »
http://www.iki.fi/sintonen/src/ipc/ has some small IPC example. It's rather easy to mess up subprocessing stuff, say for example have race conditions or cases where resources are not released. This IPC example shows one way of handling such things in a reliable way.

Note: This code is OS2++, but it could easily be 1.3 compatible.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Fake seglist in C...
« Reply #1 on: August 08, 2007, 03:53:51 PM »
@Thomas

Your code has a bug, it doesn't clear instruction cache for the jmp instruction. Add
CacheClearE(&segl->jump, 6, CACRF_ClearI); after the jmp has been poked.
[EDIT] Ahh, but this is KS 1.x example... Ok, that won't work. Forget that one.. :-) [/EDIT]

[EDIT2] Here's a KS 1.x compatible cache clear routine:
Code: [Select]

        include "exec/execbase.i"
        include "lvo/exec.i"

MyCacheClearU
        movem.l d0-d1/a0-a1/a6,-(sp)
        pea     (.cleanexit,pc)
        move.l  (4).w,a6
        cmp.w   #37,(LIB_VERSION,a6)
        blo.b   .manualclear
        jmp     (_LVOCacheClearU,a6)
.cleanexit
        movem.l (sp)+,d0-d1/a0-a1/a6
        rts
.manualclear
        move.l  a5,-(sp)
        lea     (.cacheclrsv,pc),a5
        jsr     (_LVOSupervisor,a6)
        move.l  (sp)+,a5
        rts
.cacheclrsv
        btst    #AFB_68020,(AttnFlags+1,a6)
        beq.b   .nocache
        btst    #AFB_68040,(AttnFlags+1,a6)
        beq.b   .is020or030
        ; 040/060
        cpusha  bc
        cinva   bc
        nop
        rte
.is020or030
        movec   cacr,d0
        or.w    #CACRF_ClearI!CACRF_ClearD,d0
        movec   d0,cacr
.nocache
        rte

[/EDIT2]

Also, Wait()ing for signal clears it. Thus it's possible that the subprocess never sees the SIGBREAKF_CTRL_C.

Relying on some Delay() + subprocessing cleaning up in the meanwhile is a bit bad coding style, especially if it ends up doing RemTask() which can potentially lock the system.

Quote
An important note when working with multiple threads is that ANSI runtime routines, especially buffered I/O (printf etc.) are not thread-safe and can give various strange results. You should use the AmigaDOS equivalents (e.g. Printf with a capital "P") instead.

Actually, many AmigaDOS functions aren't thread safe either, especially buffered I/O ones.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Fake seglist in C...
« Reply #2 on: August 08, 2007, 04:02:37 PM »
Quote
BTW, doesn't the main process port need to be in the public list for the subtask to be able to find it with FindPort ?

It does, and it is. amiga.lib CreatePort() routine does it, if you give it the port name.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Fake seglist in C...
« Reply #3 on: August 09, 2007, 08:37:21 PM »
@Jose
Quote
Why does it need to clear the cache ? It's not using selfmodified code and the code is already in memory so the cache data should be valid. (?)

It's building code to memory. Since it's impossible to know if this particular memory area might already be in instruction cache - containing some other, earlier instructions - it is necessary to clear the cache at least for this area.

From exec.doc:
Quote
Code: [Select]
Some examples of when the cache needs clearing:
   Self modifying code
   Building Jump tables
   Run-time code patches
   Relocating code for use at different addresses.
   Loading code from disk

Note that loading code from disk with LoadSeg() doesn't require separate cache clearing, it handles caches already.