Fresh IDE . Check-in [f828bb2bc5]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work on the new Exec2 function for Linux that allows changing of the std i/o handles. It is implemented in _process_posix.asm, but uses only system calls and the same implementation will be OK for the _process_native.asm;
Timelines: family | ancestors | descendants | both | FreshLibDev
Files: files | file ages | folders
SHA1:f828bb2bc5f6d2dc98373e5ea3c70f32a857515d
User & Date: johnfound 2018-10-17 12:03:58
Context
2018-10-18
13:31
The Exec2 function is now the main. The old Exec is a wrapper of Exec2. Implemented for Win32 and Linux. check-in: 17ffd16cb7 user: johnfound tags: FreshLibDev
2018-10-17
12:03
Work on the new Exec2 function for Linux that allows changing of the std i/o handles. It is implemented in _process_posix.asm, but uses only system calls and the same implementation will be OK for the _process_native.asm; check-in: f828bb2bc5 user: johnfound tags: FreshLibDev
12:01
Work on the test project for the bbcode parser. check-in: 30f1444ddb user: johnfound tags: FreshLibDev
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/system/Linux/_process_posix.asm.

38
39
40
41
42
43
44





45


46

47









48
















































49
50
51
52
53
54
55

body FreeThreadID
begin
        return
endp










body Exec

begin









;sys_forkd
















































        return
endp



; MUTEX functions
;_________________________________________________________________________________________







>
>
>
>
>

>
>
|
>

>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

body FreeThreadID
begin
        return
endp


body Exec
begin
        stdcall Exec2, .hCommand, [STDIN], [STDOUT], [STDERR]
        return
endp



body Exec2
.pArgs dd ?
begin
        pushad

        DebugMsg "Exec2 procedure!!!"

; first handle the .hCommand

        stdcall StrSplitArg, [.hCommand]
        mov     [.pArgs], eax

        mov     eax, sys_fork
        int     $80

        OutputValue "Fork returns: ", eax, -1, 10

        test    eax, eax
        jnz     .parent         ; this is the parent process

; here is the child.

        mov     eax, sys_dup2
        mov     ebx, [.hStdIn]
        mov     ecx, [STDIN]
        int     $80

        OutputValue "Dup2 returns: ", eax, -1, 10

        mov     ebx, [.hStdOut]
        mov     ecx, [STDOUT]
        int     $80

        OutputValue "Dup2 returns: ", eax, -1, 10

        mov     ebx, [.hStdErr]
        mov     ecx, [STDERR]
        int     $80

        OutputValue "Dup2 returns: ", eax, -1, 10

        mov     ecx, [.pArgs]
        mov     ebx, [ecx]                      ; the first argument is the executable name.

        mov     edx, [_ptrEnvironment]
        mov     eax, [edx]                      ; argument count
        lea     edx, [edx + 4*eax + 8]          ; +4 for argc and +4 for the termination 0; edx points to the env table here.

        mov     eax, sys_execve
        int     $80

        stc
        mov     [esp+4*regEAX], eax
        popad
        return

.parent:
        stdcall FreeMem, [.pArgs]
        bt      eax, 31
        mov     [esp+4*regEAX], eax
        popad
        return
endp



; MUTEX functions
;_________________________________________________________________________________________

Changes to freshlib/system/process.asm.

28
29
30
31
32
33
34

35
36
37
38
39
40
41
..
43
44
45
46
47
48
49
50







































































































51
52
53
54
55
56
57
58
59
60
61

interface ThreadCreate, .ptrFunction, .ptrArguments

interface FreeThreadID, .ThreadID


interface Exec, .hCommand


interface FreeProcessID, .ProcessID

interface WaitProcessExit, .ProcessID, .timeout



................................................................................

interface WaitForMutex, .ptrMutex, .timeout

interface MutexRelease, .ptrMutex

interface MutexDestroy, .ptrMutex









































































































include '%TargetOS%/process.asm'


if used ThreadCreate
  options.Threads = 1
else
  options.Threads = 0
end if


endmodule







>







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









<

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

164

interface ThreadCreate, .ptrFunction, .ptrArguments

interface FreeThreadID, .ThreadID


interface Exec, .hCommand
interface Exec2, .hCommand, .hStdIn, .hStdOut, .hStdErr

interface FreeProcessID, .ProcessID

interface WaitProcessExit, .ProcessID, .timeout



................................................................................

interface WaitForMutex, .ptrMutex, .timeout

interface MutexRelease, .ptrMutex

interface MutexDestroy, .ptrMutex




proc StrSplitArg, .hString
.pRes dd ?
.strlen dd ?
begin
        pushad

        stdcall StrLen, [.hString]
        mov     [.strlen], eax

        stdcall StrPtr, [.hString]
        mov     esi, eax
        mov     edi, eax
        xor     edx, edx

.loop1:
        lodsb
        test    al, al
        jz      .endstr1
        cmp     al, ' '
        jne     .loop1
        inc     edx
        jmp     .loop1

.endstr1:
        mov     esi, edi
        mov     ecx, [.strlen]

        add     edx, 3
        lea     edx, [4*edx + ecx]
        add     edx, 3
        and     edx, $fffffffc

        stdcall GetMem, edx
        mov     [.pRes], eax

        sub     edx, ecx
        sub     edx, 4
        and     edx, $fffffffc

        lea     edi, [eax+edx]
        rep movsb

        mov     edi, [.pRes]
        lea     esi, [edi+edx]  ; start of the string.

.search_loop:
        mov     [edi], esi
        add     edi, 4

.loop_to_space:
        lodsb
        test    al, al
        jz      .end_of_string

        cmp     al, '"'
        je      .skip_quoted

        cmp     al, "'"
        je      .skip_quoted

        cmp     al, ' '
        jne     .next

        cmp     ah, ' '
        je      .loop_to_space

        mov     byte [esi-1], 0
        jmp     .search_loop

.next:
        mov     ah, al
        jmp     .loop_to_space


.skip_quoted:
        mov     ah, al

.loop_quote:
        lodsb
        test    al, al
        jz      .end_of_string

        cmp     al, ah
        jne     .loop_quote
        jmp     .loop_to_space


.end_of_string:

        mov     eax, [.pRes]
        mov     [esp+4*regEAX], eax
        popad
        return
endp







include '%TargetOS%/process.asm'


if used ThreadCreate
  options.Threads = 1
else
  options.Threads = 0
end if


endmodule

Changes to freshlib/test_code/TestPThreads.asm.

11
12
13
14
15
16
17
18


19

20
21
22
23
24
25
26
27
28




29
30
31
32
33
34
35
36


37
38
39
40
41
42
43
..
49
50
51
52
53
54
55
56
57
58
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console



include "%lib%/freshlib.asm"


; include your includes here.

iglobal
  Stop dd 0
endg

start:
        InitializeAll





        stdcall ThreadCreate, TestThread, 0

.wait:
        stdcall Sleep, 100
        cmp     [Stop], 0
        je      .wait



        FinalizeAll
        stdcall TerminateAll, 0


proc TestThread, .arg
begin
        mov     esi, esp
................................................................................
        loop    .touch

        mov     [Stop], 1
        mov     esp, esi
        cret
endp


@AllImportEmbeded       ; or @AllImportSection
@AllDataEmbeded         ; or @AllDataSection








>
>

>









>
>
>
>








>
>







 







<
<
<
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
58
59
60
61
62
63
64



;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console

options.DebugMode = 1

include "%lib%/freshlib.asm"


; include your includes here.

iglobal
  Stop dd 0
endg

start:
        InitializeAll

        stdcall Exec2, "/usr/bin/ls --color=auto --group-directories-first", 0, 1, 2

        jmp     .finish

        stdcall ThreadCreate, TestThread, 0

.wait:
        stdcall Sleep, 100
        cmp     [Stop], 0
        je      .wait


.finish:
        FinalizeAll
        stdcall TerminateAll, 0


proc TestThread, .arg
begin
        mov     esi, esp
................................................................................
        loop    .touch

        mov     [Stop], 1
        mov     esp, esi
        cret
endp




Changes to freshlib/test_code/TestPThreads.fpr.

cannot compute difference between binary files