Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
support ./src/env/*.c
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Aug 5, 2022
1 parent a87fd91 commit 9e003b7
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 72 deletions.
7 changes: 5 additions & 2 deletions c2go.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"__pthread_self"
],
"files": [
"./src/env/__init_tls.c",
"./src/env/__libc_start_main.c",
"./src/env/__reset_tls.c",
"./src/env/__stack_chk_fail.c",
"./src/crypt/crypt_blowfish.c",
"./src/unistd/dup3.c",
"./src/unistd/faccessat.c",
Expand Down Expand Up @@ -74,6 +78,7 @@
]
},
"dirs": [
"./src/env",
"./src/crypt",
"./src/unistd",
"./src/misc",
Expand All @@ -95,8 +100,6 @@
"./src/fenv/fesetround.c",
"./src/stdlib/strtod.c",
"./src/stdlib/qsort.c",
"./src/env/__environ.c",
"./src/env/getenv.c",
"./src/mman/mmap.c",
"./src/mman/munmap.c",
"./src/time/__map_file.c",
Expand Down
140 changes: 70 additions & 70 deletions c2go_header.i.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,61 @@ type Pthread_t = *Struct___pthread
type Pthread_once_t = int32
type Pthread_key_t = uint32
type Pthread_spinlock_t = int32
type _cgoa_1_crypt struct {
type _cgoa_1___environ struct {
X__attr uint32
}
type Pthread_mutexattr_t = _cgoa_1_crypt
type _cgoa_2_crypt struct {
type Pthread_mutexattr_t = _cgoa_1___environ
type _cgoa_2___environ struct {
X__attr uint32
}
type Pthread_condattr_t = _cgoa_2_crypt
type _cgoa_3_crypt struct {
type Pthread_condattr_t = _cgoa_2___environ
type _cgoa_3___environ struct {
X__attr uint32
}
type Pthread_barrierattr_t = _cgoa_3_crypt
type _cgoa_4_crypt struct {
type Pthread_barrierattr_t = _cgoa_3___environ
type _cgoa_4___environ struct {
X__attr [2]uint32
}
type Pthread_rwlockattr_t = _cgoa_4_crypt
type Pthread_rwlockattr_t = _cgoa_4___environ
type Struct___sigset_t struct {
X__bits [16]uint64
}
type Sigset_t = Struct___sigset_t
type _cgoa_6_crypt struct {
type _cgoa_6___environ struct {
X__i [14]int32
}
type _cgoa_5_crypt struct {
X__u _cgoa_6_crypt
type _cgoa_5___environ struct {
X__u _cgoa_6___environ
}
type Pthread_attr_t = _cgoa_5_crypt
type _cgoa_8_crypt struct {
type Pthread_attr_t = _cgoa_5___environ
type _cgoa_8___environ struct {
X__i [10]int32
}
type _cgoa_7_crypt struct {
X__u _cgoa_8_crypt
type _cgoa_7___environ struct {
X__u _cgoa_8___environ
}
type Pthread_mutex_t = _cgoa_7_crypt
type _cgoa_10_crypt struct {
type Pthread_mutex_t = _cgoa_7___environ
type _cgoa_10___environ struct {
X__i [12]int32
}
type _cgoa_9_crypt struct {
X__u _cgoa_10_crypt
type _cgoa_9___environ struct {
X__u _cgoa_10___environ
}
type Pthread_cond_t = _cgoa_9_crypt
type _cgoa_12_crypt struct {
type Pthread_cond_t = _cgoa_9___environ
type _cgoa_12___environ struct {
X__i [14]int32
}
type _cgoa_11_crypt struct {
X__u _cgoa_12_crypt
type _cgoa_11___environ struct {
X__u _cgoa_12___environ
}
type Pthread_rwlock_t = _cgoa_11_crypt
type _cgoa_14_crypt struct {
type Pthread_rwlock_t = _cgoa_11___environ
type _cgoa_14___environ struct {
X__i [8]int32
}
type _cgoa_13_crypt struct {
X__u _cgoa_14_crypt
type _cgoa_13___environ struct {
X__u _cgoa_14___environ
}
type Pthread_barrier_t = _cgoa_13_crypt
type Pthread_barrier_t = _cgoa_13___environ
type Pid_t = int32
type struct_sched_param struct {
sched_priority int32
Expand Down Expand Up @@ -103,21 +103,21 @@ type struct___ptcb struct {
__next *struct___ptcb
}
type Wchar_t = uint32
type _cgoa_15_crypt struct {
type _cgoa_15___environ struct {
Quot int32
Rem int32
}
type Div_t = _cgoa_15_crypt
type _cgoa_16_crypt struct {
type Div_t = _cgoa_15___environ
type _cgoa_16___environ struct {
Quot int64
Rem int64
}
type Ldiv_t = _cgoa_16_crypt
type _cgoa_17_crypt struct {
type Ldiv_t = _cgoa_16___environ
type _cgoa_17___environ struct {
Quot int64
Rem int64
}
type Lldiv_t = _cgoa_17_crypt
type Lldiv_t = _cgoa_17___environ
type Ssize_t = int64
type Off_t = int64
type FILE = Struct__IO_FILE
Expand Down Expand Up @@ -164,6 +164,41 @@ type Intptr_t = int64
type Uid_t = uint32
type Gid_t = uint32
type Useconds_t = uint32
type struct_cpu_set_t struct {
__bits [16]uint64
}
type cpu_set_t = struct_cpu_set_t

func __CPU_AND_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) & *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}
func __CPU_OR_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) | *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}
func __CPU_XOR_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) ^ *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}

type Cookie_read_function_t = func(unsafe.Pointer, *int8, uint64) int64
type Cookie_write_function_t = func(unsafe.Pointer, *int8, uint64) int64
type Cookie_seek_function_t = func(unsafe.Pointer, *int64, int32) int32
type Cookie_close_function_t = func(unsafe.Pointer) int32
type Struct__IO_cookie_io_functions_t struct {
Read func(unsafe.Pointer, *int8, uint64) int64
Write func(unsafe.Pointer, *int8, uint64) int64
Seek func(unsafe.Pointer, *int64, int32) int32
Close func(unsafe.Pointer) int32
}
type Cookie_io_functions_t = Struct__IO_cookie_io_functions_t
type struct_crypt_data struct {
initialized int32
__buf [256]int8
Expand Down Expand Up @@ -233,41 +268,6 @@ func __alt_socketcall(sys int32, sock int32, cp int32, a int64, b int64, c int64
return r
}

type struct_cpu_set_t struct {
__bits [16]uint64
}
type cpu_set_t = struct_cpu_set_t

func __CPU_AND_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) & *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}
func __CPU_OR_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) | *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}
func __CPU_XOR_S(__size uint64, __dest *struct_cpu_set_t, __src1 *struct_cpu_set_t, __src2 *struct_cpu_set_t) {
var __i uint64
for __i = uint64(0); __i < __size/8; __i++ {
*(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__dest)))) + uintptr(__i)*8)) = *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src1)))) + uintptr(__i)*8)) ^ *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint64)(unsafe.Pointer(__src2)))) + uintptr(__i)*8))
}
}

type Cookie_read_function_t = func(unsafe.Pointer, *int8, uint64) int64
type Cookie_write_function_t = func(unsafe.Pointer, *int8, uint64) int64
type Cookie_seek_function_t = func(unsafe.Pointer, *int64, int32) int32
type Cookie_close_function_t = func(unsafe.Pointer) int32
type Struct__IO_cookie_io_functions_t struct {
Read func(unsafe.Pointer, *int8, uint64) int64
Write func(unsafe.Pointer, *int8, uint64) int64
Seek func(unsafe.Pointer, *int64, int32) int32
Close func(unsafe.Pointer) int32
}
type Cookie_io_functions_t = Struct__IO_cookie_io_functions_t
type Suseconds_t = int64
type Struct_timeval struct {
Tv_sec int64
Expand Down Expand Up @@ -438,7 +438,7 @@ type struct_sigaction struct {
}
type _cgoa_33_setxid struct {
sigev_notify_function func(union_sigval)
sigev_notify_attributes *_cgoa_5_crypt
sigev_notify_attributes *_cgoa_5___environ
}
type _cgoa_32_setxid struct {
__pad [48]int8
Expand Down
21 changes: 21 additions & 0 deletions clearenv.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package libc

import unsafe "unsafe"

func _cgos_dummy_clearenv(old *int8, new *int8) {
}
func Clearenv() int32 {
var e **int8 = X__environ
X__environ = (**int8)(nil)
if e != nil {
for *e != nil {
__env_rm_add(*func() (_cgo_ret **int8) {
_cgo_addr := &e
_cgo_ret = *_cgo_addr
*(*uintptr)(unsafe.Pointer(_cgo_addr)) += 8
return
}(), nil)
}
}
return int32(0)
}
67 changes: 67 additions & 0 deletions putenv.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package libc

import unsafe "unsafe"

func _cgos_dummy_putenv(old *int8, new *int8) {
}
func __putenv(s *int8, l uint64, r *int8) int32 {
var i uint64 = uint64(0)
if X__environ != nil {
for e := (**int8)(X__environ); *e != nil; func() uint64 {
*(*uintptr)(unsafe.Pointer(&e)) += 8
return func() (_cgo_ret uint64) {
_cgo_addr := &i
_cgo_ret = *_cgo_addr
*_cgo_addr++
return
}()
}() {
if !(Strncmp(s, *e, l+uint64(1)) != 0) {
var tmp *int8 = *e
*e = s
__env_rm_add(tmp, r)
return int32(0)
}
}
}
var newenv **int8
if uintptr(unsafe.Pointer(X__environ)) == uintptr(unsafe.Pointer(_cgos_oldenv_putenv)) {
newenv = (**int8)(Realloc(unsafe.Pointer(_cgos_oldenv_putenv), 8*(i+uint64(2))))
if !(newenv != nil) {
goto oom
}
} else {
newenv = (**int8)(Malloc(8 * (i + uint64(2))))
if !(newenv != nil) {
goto oom
}
if i != 0 {
Memcpy(unsafe.Pointer(newenv), unsafe.Pointer(X__environ), 8*i)
}
Free(unsafe.Pointer(_cgos_oldenv_putenv))
}
*(**int8)(unsafe.Pointer(uintptr(unsafe.Pointer(newenv)) + uintptr(i)*8)) = s
*(**int8)(unsafe.Pointer(uintptr(unsafe.Pointer(newenv)) + uintptr(i+uint64(1))*8)) = (*int8)(nil)
X__environ = func() (_cgo_ret **int8) {
_cgo_addr := &_cgos_oldenv_putenv
*_cgo_addr = newenv
return *_cgo_addr
}()
if r != nil {
__env_rm_add(nil, r)
}
return int32(0)
oom:
Free(unsafe.Pointer(r))
return -1
}

var _cgos_oldenv_putenv **int8

func Putenv(s *int8) int32 {
var l uint64 = uint64(uintptr(unsafe.Pointer(__strchrnul(s, '='))) - uintptr(unsafe.Pointer(s)))
if !(l != 0) || !(*(*int8)(unsafe.Pointer(uintptr(unsafe.Pointer(s)) + uintptr(l))) != 0) {
return Unsetenv(s)
}
return __putenv(s, l, nil)
}
11 changes: 11 additions & 0 deletions secure_getenv.c.i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package libc

func Secure_getenv(name *int8) *int8 {
return func() *int8 {
if int32(__libc.secure) != 0 {
return nil
} else {
return Getenv(name)
}
}()
}
Loading

0 comments on commit 9e003b7

Please sign in to comment.