repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
Microsoft/go-winio
pipe.go
CloseWrite
func (f *win32MessageBytePipe) CloseWrite() error { if f.writeClosed { return errPipeWriteClosed } err := f.win32File.Flush() if err != nil { return err } _, err = f.win32File.Write(nil) if err != nil { return err } f.writeClosed = true return nil }
go
func (f *win32MessageBytePipe) CloseWrite() error { if f.writeClosed { return errPipeWriteClosed } err := f.win32File.Flush() if err != nil { return err } _, err = f.win32File.Write(nil) if err != nil { return err } f.writeClosed = true return nil }
[ "func", "(", "f", "*", "win32MessageBytePipe", ")", "CloseWrite", "(", ")", "error", "{", "if", "f", ".", "writeClosed", "{", "return", "errPipeWriteClosed", "\n", "}", "\n", "err", ":=", "f", ".", "win32File", ".", "Flush", "(", ")", "\n", "if", "err"...
// CloseWrite closes the write side of a message pipe in byte mode.
[ "CloseWrite", "closes", "the", "write", "side", "of", "a", "message", "pipe", "in", "byte", "mode", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pipe.go#L125-L139
train
Microsoft/go-winio
pipe.go
Read
func (f *win32MessageBytePipe) Read(b []byte) (int, error) { if f.readEOF { return 0, io.EOF } n, err := f.win32File.Read(b) if err == io.EOF { // If this was the result of a zero-byte read, then // it is possible that the read was due to a zero-size // message. Since we are simulating CloseWrite with a // zero-byte message, ensure that all future Read() calls // also return EOF. f.readEOF = true } else if err == syscall.ERROR_MORE_DATA { // ERROR_MORE_DATA indicates that the pipe's read mode is message mode // and the message still has more bytes. Treat this as a success, since // this package presents all named pipes as byte streams. err = nil } return n, err }
go
func (f *win32MessageBytePipe) Read(b []byte) (int, error) { if f.readEOF { return 0, io.EOF } n, err := f.win32File.Read(b) if err == io.EOF { // If this was the result of a zero-byte read, then // it is possible that the read was due to a zero-size // message. Since we are simulating CloseWrite with a // zero-byte message, ensure that all future Read() calls // also return EOF. f.readEOF = true } else if err == syscall.ERROR_MORE_DATA { // ERROR_MORE_DATA indicates that the pipe's read mode is message mode // and the message still has more bytes. Treat this as a success, since // this package presents all named pipes as byte streams. err = nil } return n, err }
[ "func", "(", "f", "*", "win32MessageBytePipe", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "f", ".", "readEOF", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "\n", "n", ",", "err", ":=", "f"...
// Read reads bytes from a message pipe in byte mode. A read of a zero-byte message on a message // mode pipe will return io.EOF, as will all subsequent reads.
[ "Read", "reads", "bytes", "from", "a", "message", "pipe", "in", "byte", "mode", ".", "A", "read", "of", "a", "zero", "-", "byte", "message", "on", "a", "message", "mode", "pipe", "will", "return", "io", ".", "EOF", "as", "will", "all", "subsequent", ...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pipe.go#L155-L174
train
Microsoft/go-winio
pipe.go
tryDialPipe
func tryDialPipe(ctx context.Context, path *string) (syscall.Handle, error) { for { select { case <-ctx.Done(): return syscall.Handle(0), ctx.Err() default: h, err := createFile(*path, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_OVERLAPPED|cSECURITY_SQOS_PRESENT|cSECURITY_ANONYMOUS, 0) if err == nil { return h, nil } if err != cERROR_PIPE_BUSY { return h, &os.PathError{Err: err, Op: "open", Path: *path} } // Wait 10 msec and try again. This is a rather simplistic // view, as we always try each 10 milliseconds. time.Sleep(time.Millisecond * 10) } } }
go
func tryDialPipe(ctx context.Context, path *string) (syscall.Handle, error) { for { select { case <-ctx.Done(): return syscall.Handle(0), ctx.Err() default: h, err := createFile(*path, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_OVERLAPPED|cSECURITY_SQOS_PRESENT|cSECURITY_ANONYMOUS, 0) if err == nil { return h, nil } if err != cERROR_PIPE_BUSY { return h, &os.PathError{Err: err, Op: "open", Path: *path} } // Wait 10 msec and try again. This is a rather simplistic // view, as we always try each 10 milliseconds. time.Sleep(time.Millisecond * 10) } } }
[ "func", "tryDialPipe", "(", "ctx", "context", ".", "Context", ",", "path", "*", "string", ")", "(", "syscall", ".", "Handle", ",", "error", ")", "{", "for", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "syscall", "...
// tryDialPipe attempts to dial the pipe at `path` until `ctx` cancellation or timeout.
[ "tryDialPipe", "attempts", "to", "dial", "the", "pipe", "at", "path", "until", "ctx", "cancellation", "or", "timeout", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pipe.go#L185-L203
train
Microsoft/go-winio
pipe.go
DialPipeContext
func DialPipeContext(ctx context.Context, path string) (net.Conn, error) { var err error var h syscall.Handle h, err = tryDialPipe(ctx, &path) if err != nil { return nil, err } var flags uint32 err = getNamedPipeInfo(h, &flags, nil, nil, nil) if err != nil { return nil, err } f, err := makeWin32File(h) if err != nil { syscall.Close(h) return nil, err } // If the pipe is in message mode, return a message byte pipe, which // supports CloseWrite(). if flags&cPIPE_TYPE_MESSAGE != 0 { return &win32MessageBytePipe{ win32Pipe: win32Pipe{win32File: f, path: path}, }, nil } return &win32Pipe{win32File: f, path: path}, nil }
go
func DialPipeContext(ctx context.Context, path string) (net.Conn, error) { var err error var h syscall.Handle h, err = tryDialPipe(ctx, &path) if err != nil { return nil, err } var flags uint32 err = getNamedPipeInfo(h, &flags, nil, nil, nil) if err != nil { return nil, err } f, err := makeWin32File(h) if err != nil { syscall.Close(h) return nil, err } // If the pipe is in message mode, return a message byte pipe, which // supports CloseWrite(). if flags&cPIPE_TYPE_MESSAGE != 0 { return &win32MessageBytePipe{ win32Pipe: win32Pipe{win32File: f, path: path}, }, nil } return &win32Pipe{win32File: f, path: path}, nil }
[ "func", "DialPipeContext", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "h", "syscall", ".", "Handle", "\n", "h", ",", "err", "=", "tryDialPipe...
// DialPipeContext attempts to connect to a named pipe by `path` until `ctx` // cancellation or timeout.
[ "DialPipeContext", "attempts", "to", "connect", "to", "a", "named", "pipe", "by", "path", "until", "ctx", "cancellation", "or", "timeout", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pipe.go#L225-L253
train
Microsoft/go-winio
backup.go
Read
func (r *BackupStreamReader) Read(b []byte) (int, error) { if r.bytesLeft == 0 { return 0, io.EOF } if int64(len(b)) > r.bytesLeft { b = b[:r.bytesLeft] } n, err := r.r.Read(b) r.bytesLeft -= int64(n) if err == io.EOF { err = io.ErrUnexpectedEOF } else if r.bytesLeft == 0 && err == nil { err = io.EOF } return n, err }
go
func (r *BackupStreamReader) Read(b []byte) (int, error) { if r.bytesLeft == 0 { return 0, io.EOF } if int64(len(b)) > r.bytesLeft { b = b[:r.bytesLeft] } n, err := r.r.Read(b) r.bytesLeft -= int64(n) if err == io.EOF { err = io.ErrUnexpectedEOF } else if r.bytesLeft == 0 && err == nil { err = io.EOF } return n, err }
[ "func", "(", "r", "*", "BackupStreamReader", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "r", ".", "bytesLeft", "==", "0", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "\n", "if", "int64", ...
// Read reads from the current backup stream.
[ "Read", "reads", "from", "the", "current", "backup", "stream", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L116-L131
train
Microsoft/go-winio
backup.go
Write
func (w *BackupStreamWriter) Write(b []byte) (int, error) { if w.bytesLeft < int64(len(b)) { return 0, fmt.Errorf("too many bytes by %d", int64(len(b))-w.bytesLeft) } n, err := w.w.Write(b) w.bytesLeft -= int64(n) return n, err }
go
func (w *BackupStreamWriter) Write(b []byte) (int, error) { if w.bytesLeft < int64(len(b)) { return 0, fmt.Errorf("too many bytes by %d", int64(len(b))-w.bytesLeft) } n, err := w.w.Write(b) w.bytesLeft -= int64(n) return n, err }
[ "func", "(", "w", "*", "BackupStreamWriter", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "w", ".", "bytesLeft", "<", "int64", "(", "len", "(", "b", ")", ")", "{", "return", "0", ",", "fmt", ".", "E...
// Write writes to the current backup stream.
[ "Write", "writes", "to", "the", "current", "backup", "stream", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L178-L185
train
Microsoft/go-winio
backup.go
NewBackupFileReader
func NewBackupFileReader(f *os.File, includeSecurity bool) *BackupFileReader { r := &BackupFileReader{f, includeSecurity, 0} return r }
go
func NewBackupFileReader(f *os.File, includeSecurity bool) *BackupFileReader { r := &BackupFileReader{f, includeSecurity, 0} return r }
[ "func", "NewBackupFileReader", "(", "f", "*", "os", ".", "File", ",", "includeSecurity", "bool", ")", "*", "BackupFileReader", "{", "r", ":=", "&", "BackupFileReader", "{", "f", ",", "includeSecurity", ",", "0", "}", "\n", "return", "r", "\n", "}" ]
// NewBackupFileReader returns a new BackupFileReader from a file handle. If includeSecurity is true, // Read will attempt to read the security descriptor of the file.
[ "NewBackupFileReader", "returns", "a", "new", "BackupFileReader", "from", "a", "file", "handle", ".", "If", "includeSecurity", "is", "true", "Read", "will", "attempt", "to", "read", "the", "security", "descriptor", "of", "the", "file", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L196-L199
train
Microsoft/go-winio
backup.go
Close
func (r *BackupFileReader) Close() error { if r.ctx != 0 { backupRead(syscall.Handle(r.f.Fd()), nil, nil, true, false, &r.ctx) runtime.KeepAlive(r.f) r.ctx = 0 } return nil }
go
func (r *BackupFileReader) Close() error { if r.ctx != 0 { backupRead(syscall.Handle(r.f.Fd()), nil, nil, true, false, &r.ctx) runtime.KeepAlive(r.f) r.ctx = 0 } return nil }
[ "func", "(", "r", "*", "BackupFileReader", ")", "Close", "(", ")", "error", "{", "if", "r", ".", "ctx", "!=", "0", "{", "backupRead", "(", "syscall", ".", "Handle", "(", "r", ".", "f", ".", "Fd", "(", ")", ")", ",", "nil", ",", "nil", ",", "t...
// Close frees Win32 resources associated with the BackupFileReader. It does not close // the underlying file.
[ "Close", "frees", "Win32", "resources", "associated", "with", "the", "BackupFileReader", ".", "It", "does", "not", "close", "the", "underlying", "file", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L217-L224
train
Microsoft/go-winio
backup.go
Write
func (w *BackupFileWriter) Write(b []byte) (int, error) { var bytesWritten uint32 err := backupWrite(syscall.Handle(w.f.Fd()), b, &bytesWritten, false, w.includeSecurity, &w.ctx) if err != nil { return 0, &os.PathError{"BackupWrite", w.f.Name(), err} } runtime.KeepAlive(w.f) if int(bytesWritten) != len(b) { return int(bytesWritten), errors.New("not all bytes could be written") } return len(b), nil }
go
func (w *BackupFileWriter) Write(b []byte) (int, error) { var bytesWritten uint32 err := backupWrite(syscall.Handle(w.f.Fd()), b, &bytesWritten, false, w.includeSecurity, &w.ctx) if err != nil { return 0, &os.PathError{"BackupWrite", w.f.Name(), err} } runtime.KeepAlive(w.f) if int(bytesWritten) != len(b) { return int(bytesWritten), errors.New("not all bytes could be written") } return len(b), nil }
[ "func", "(", "w", "*", "BackupFileWriter", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "var", "bytesWritten", "uint32", "\n", "err", ":=", "backupWrite", "(", "syscall", ".", "Handle", "(", "w", ".", "f", ".",...
// Write restores a portion of the file using the provided backup stream.
[ "Write", "restores", "a", "portion", "of", "the", "file", "using", "the", "provided", "backup", "stream", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L241-L252
train
Microsoft/go-winio
backup.go
Close
func (w *BackupFileWriter) Close() error { if w.ctx != 0 { backupWrite(syscall.Handle(w.f.Fd()), nil, nil, true, false, &w.ctx) runtime.KeepAlive(w.f) w.ctx = 0 } return nil }
go
func (w *BackupFileWriter) Close() error { if w.ctx != 0 { backupWrite(syscall.Handle(w.f.Fd()), nil, nil, true, false, &w.ctx) runtime.KeepAlive(w.f) w.ctx = 0 } return nil }
[ "func", "(", "w", "*", "BackupFileWriter", ")", "Close", "(", ")", "error", "{", "if", "w", ".", "ctx", "!=", "0", "{", "backupWrite", "(", "syscall", ".", "Handle", "(", "w", ".", "f", ".", "Fd", "(", ")", ")", ",", "nil", ",", "nil", ",", "...
// Close frees Win32 resources associated with the BackupFileWriter. It does not // close the underlying file.
[ "Close", "frees", "Win32", "resources", "associated", "with", "the", "BackupFileWriter", ".", "It", "does", "not", "close", "the", "underlying", "file", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/backup.go#L256-L263
train
Microsoft/go-winio
vhd/vhd.go
CreateVhdx
func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error { var ( defaultType virtualStorageType handle syscall.Handle ) parameters := createVirtualDiskParameters{ Version: 2, Version2: createVersion2{ MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024, BlockSizeInBytes: blockSizeInMb * 1024 * 1024, }, } if err := createVirtualDisk( &defaultType, path, uint32(VirtualDiskAccessNone), nil, uint32(createVirtualDiskFlagNone), 0, &parameters, nil, &handle); err != nil { return err } if err := syscall.CloseHandle(handle); err != nil { return err } return nil }
go
func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error { var ( defaultType virtualStorageType handle syscall.Handle ) parameters := createVirtualDiskParameters{ Version: 2, Version2: createVersion2{ MaximumSize: uint64(maxSizeInGb) * 1024 * 1024 * 1024, BlockSizeInBytes: blockSizeInMb * 1024 * 1024, }, } if err := createVirtualDisk( &defaultType, path, uint32(VirtualDiskAccessNone), nil, uint32(createVirtualDiskFlagNone), 0, &parameters, nil, &handle); err != nil { return err } if err := syscall.CloseHandle(handle); err != nil { return err } return nil }
[ "func", "CreateVhdx", "(", "path", "string", ",", "maxSizeInGb", ",", "blockSizeInMb", "uint32", ")", "error", "{", "var", "(", "defaultType", "virtualStorageType", "\n", "handle", "syscall", ".", "Handle", "\n", ")", "\n\n", "parameters", ":=", "createVirtualDi...
// CreateVhdx will create a simple vhdx file at the given path using default values.
[ "CreateVhdx", "will", "create", "a", "simple", "vhdx", "file", "at", "the", "given", "path", "using", "default", "values", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/vhd/vhd.go#L86-L118
train
Microsoft/go-winio
vhd/vhd.go
DetachVhd
func DetachVhd(path string) error { handle, err := OpenVirtualDisk(path, VirtualDiskAccessDetach, OpenVirtualDiskFlagNone) if err != nil { return err } defer syscall.CloseHandle(handle) return detachVirtualDisk(handle, 0, 0) }
go
func DetachVhd(path string) error { handle, err := OpenVirtualDisk(path, VirtualDiskAccessDetach, OpenVirtualDiskFlagNone) if err != nil { return err } defer syscall.CloseHandle(handle) return detachVirtualDisk(handle, 0, 0) }
[ "func", "DetachVhd", "(", "path", "string", ")", "error", "{", "handle", ",", "err", ":=", "OpenVirtualDisk", "(", "path", ",", "VirtualDiskAccessDetach", ",", "OpenVirtualDiskFlagNone", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", ...
// DetachVhd detaches a VHD attached at the given path.
[ "DetachVhd", "detaches", "a", "VHD", "attached", "at", "the", "given", "path", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/vhd/vhd.go#L121-L128
train
Microsoft/go-winio
vhd/vhd.go
OpenVirtualDisk
func OpenVirtualDisk(path string, accessMask VirtualDiskAccessMask, flag VirtualDiskFlag) (syscall.Handle, error) { var ( defaultType virtualStorageType handle syscall.Handle ) parameters := openVirtualDiskParameters{Version: 2} if err := openVirtualDisk( &defaultType, path, uint32(accessMask), uint32(flag), &parameters, &handle); err != nil { return 0, err } return handle, nil }
go
func OpenVirtualDisk(path string, accessMask VirtualDiskAccessMask, flag VirtualDiskFlag) (syscall.Handle, error) { var ( defaultType virtualStorageType handle syscall.Handle ) parameters := openVirtualDiskParameters{Version: 2} if err := openVirtualDisk( &defaultType, path, uint32(accessMask), uint32(flag), &parameters, &handle); err != nil { return 0, err } return handle, nil }
[ "func", "OpenVirtualDisk", "(", "path", "string", ",", "accessMask", "VirtualDiskAccessMask", ",", "flag", "VirtualDiskFlag", ")", "(", "syscall", ".", "Handle", ",", "error", ")", "{", "var", "(", "defaultType", "virtualStorageType", "\n", "handle", "syscall", ...
// OpenVirtuaDisk obtains a handle to a VHD opened with supplied access mask and flags.
[ "OpenVirtuaDisk", "obtains", "a", "handle", "to", "a", "VHD", "opened", "with", "supplied", "access", "mask", "and", "flags", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/vhd/vhd.go#L131-L147
train
Microsoft/go-winio
pkg/etwlogrus/hook.go
NewHook
func NewHook(providerName string) (*Hook, error) { provider, err := etw.NewProvider(providerName, nil) if err != nil { return nil, err } return &Hook{provider, true}, nil }
go
func NewHook(providerName string) (*Hook, error) { provider, err := etw.NewProvider(providerName, nil) if err != nil { return nil, err } return &Hook{provider, true}, nil }
[ "func", "NewHook", "(", "providerName", "string", ")", "(", "*", "Hook", ",", "error", ")", "{", "provider", ",", "err", ":=", "etw", ".", "NewProvider", "(", "providerName", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",",...
// NewHook registers a new ETW provider and returns a hook to log from it. The // provider will be closed when the hook is closed.
[ "NewHook", "registers", "a", "new", "ETW", "provider", "and", "returns", "a", "hook", "to", "log", "from", "it", ".", "The", "provider", "will", "be", "closed", "when", "the", "hook", "is", "closed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etwlogrus/hook.go#L16-L23
train
Microsoft/go-winio
pkg/etwlogrus/hook.go
NewHookFromProvider
func NewHookFromProvider(provider *etw.Provider) (*Hook, error) { return &Hook{provider, false}, nil }
go
func NewHookFromProvider(provider *etw.Provider) (*Hook, error) { return &Hook{provider, false}, nil }
[ "func", "NewHookFromProvider", "(", "provider", "*", "etw", ".", "Provider", ")", "(", "*", "Hook", ",", "error", ")", "{", "return", "&", "Hook", "{", "provider", ",", "false", "}", ",", "nil", "\n", "}" ]
// NewHookFromProvider creates a new hook based on an existing ETW provider. The // provider will not be closed when the hook is closed.
[ "NewHookFromProvider", "creates", "a", "new", "hook", "based", "on", "an", "existing", "ETW", "provider", ".", "The", "provider", "will", "not", "be", "closed", "when", "the", "hook", "is", "closed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etwlogrus/hook.go#L27-L29
train
Microsoft/go-winio
pkg/etwlogrus/hook.go
Levels
func (h *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.TraceLevel, logrus.DebugLevel, logrus.InfoLevel, logrus.WarnLevel, logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel, } }
go
func (h *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.TraceLevel, logrus.DebugLevel, logrus.InfoLevel, logrus.WarnLevel, logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel, } }
[ "func", "(", "h", "*", "Hook", ")", "Levels", "(", ")", "[", "]", "logrus", ".", "Level", "{", "return", "[", "]", "logrus", ".", "Level", "{", "logrus", ".", "TraceLevel", ",", "logrus", ".", "DebugLevel", ",", "logrus", ".", "InfoLevel", ",", "lo...
// Levels returns the set of levels that this hook wants to receive log entries // for.
[ "Levels", "returns", "the", "set", "of", "levels", "that", "this", "hook", "wants", "to", "receive", "log", "entries", "for", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etwlogrus/hook.go#L33-L43
train
Microsoft/go-winio
pkg/etwlogrus/hook.go
Fire
func (h *Hook) Fire(e *logrus.Entry) error { // Logrus defines more levels than ETW typically uses, but analysis is // easiest when using a consistent set of levels across ETW providers, so we // map the Logrus levels to ETW levels. level := logrusToETWLevelMap[e.Level] if !h.provider.IsEnabledForLevel(level) { return nil } // Reserve extra space for the message field. fields := make([]etw.FieldOpt, 0, len(e.Data)+1) fields = append(fields, etw.StringField("Message", e.Message)) for k, v := range e.Data { fields = append(fields, etw.SmartField(k, v)) } return h.provider.WriteEvent( "LogrusEntry", etw.WithEventOpts(etw.WithLevel(level)), fields) }
go
func (h *Hook) Fire(e *logrus.Entry) error { // Logrus defines more levels than ETW typically uses, but analysis is // easiest when using a consistent set of levels across ETW providers, so we // map the Logrus levels to ETW levels. level := logrusToETWLevelMap[e.Level] if !h.provider.IsEnabledForLevel(level) { return nil } // Reserve extra space for the message field. fields := make([]etw.FieldOpt, 0, len(e.Data)+1) fields = append(fields, etw.StringField("Message", e.Message)) for k, v := range e.Data { fields = append(fields, etw.SmartField(k, v)) } return h.provider.WriteEvent( "LogrusEntry", etw.WithEventOpts(etw.WithLevel(level)), fields) }
[ "func", "(", "h", "*", "Hook", ")", "Fire", "(", "e", "*", "logrus", ".", "Entry", ")", "error", "{", "// Logrus defines more levels than ETW typically uses, but analysis is", "// easiest when using a consistent set of levels across ETW providers, so we", "// map the Logrus level...
// Fire receives each Logrus entry as it is logged, and logs it to ETW.
[ "Fire", "receives", "each", "Logrus", "entry", "as", "it", "is", "logged", "and", "logs", "it", "to", "ETW", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etwlogrus/hook.go#L56-L78
train
Microsoft/go-winio
pkg/etwlogrus/hook.go
Close
func (h *Hook) Close() error { if h.closeProvider { return h.provider.Close() } return nil }
go
func (h *Hook) Close() error { if h.closeProvider { return h.provider.Close() } return nil }
[ "func", "(", "h", "*", "Hook", ")", "Close", "(", ")", "error", "{", "if", "h", ".", "closeProvider", "{", "return", "h", ".", "provider", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close cleans up the hook and closes the ETW provider. If the provder was // registered by etwlogrus, it will be closed as part of `Close`. If the // provider was passed in, it will not be closed.
[ "Close", "cleans", "up", "the", "hook", "and", "closes", "the", "ETW", "provider", ".", "If", "the", "provder", "was", "registered", "by", "etwlogrus", "it", "will", "be", "closed", "as", "part", "of", "Close", ".", "If", "the", "provider", "was", "passe...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etwlogrus/hook.go#L83-L88
train
Microsoft/go-winio
privilege.go
RunWithPrivilege
func RunWithPrivilege(name string, fn func() error) error { return RunWithPrivileges([]string{name}, fn) }
go
func RunWithPrivilege(name string, fn func() error) error { return RunWithPrivileges([]string{name}, fn) }
[ "func", "RunWithPrivilege", "(", "name", "string", ",", "fn", "func", "(", ")", "error", ")", "error", "{", "return", "RunWithPrivileges", "(", "[", "]", "string", "{", "name", "}", ",", "fn", ")", "\n", "}" ]
// RunWithPrivilege enables a single privilege for a function call.
[ "RunWithPrivilege", "enables", "a", "single", "privilege", "for", "a", "function", "call", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/privilege.go#L71-L73
train
Microsoft/go-winio
privilege.go
RunWithPrivileges
func RunWithPrivileges(names []string, fn func() error) error { privileges, err := mapPrivileges(names) if err != nil { return err } runtime.LockOSThread() defer runtime.UnlockOSThread() token, err := newThreadToken() if err != nil { return err } defer releaseThreadToken(token) err = adjustPrivileges(token, privileges, SE_PRIVILEGE_ENABLED) if err != nil { return err } return fn() }
go
func RunWithPrivileges(names []string, fn func() error) error { privileges, err := mapPrivileges(names) if err != nil { return err } runtime.LockOSThread() defer runtime.UnlockOSThread() token, err := newThreadToken() if err != nil { return err } defer releaseThreadToken(token) err = adjustPrivileges(token, privileges, SE_PRIVILEGE_ENABLED) if err != nil { return err } return fn() }
[ "func", "RunWithPrivileges", "(", "names", "[", "]", "string", ",", "fn", "func", "(", ")", "error", ")", "error", "{", "privileges", ",", "err", ":=", "mapPrivileges", "(", "names", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}...
// RunWithPrivileges enables privileges for a function call.
[ "RunWithPrivileges", "enables", "privileges", "for", "a", "function", "call", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/privilege.go#L76-L93
train
Microsoft/go-winio
wim/wim.go
Time
func (ft *Filetime) Time() time.Time { // 100-nanosecond intervals since January 1, 1601 nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // change starting time to the Epoch (00:00:00 UTC, January 1, 1970) nsec -= 116444736000000000 // convert into nanoseconds nsec *= 100 return time.Unix(0, nsec) }
go
func (ft *Filetime) Time() time.Time { // 100-nanosecond intervals since January 1, 1601 nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // change starting time to the Epoch (00:00:00 UTC, January 1, 1970) nsec -= 116444736000000000 // convert into nanoseconds nsec *= 100 return time.Unix(0, nsec) }
[ "func", "(", "ft", "*", "Filetime", ")", "Time", "(", ")", "time", ".", "Time", "{", "// 100-nanosecond intervals since January 1, 1601", "nsec", ":=", "int64", "(", "ft", ".", "HighDateTime", ")", "<<", "32", "+", "int64", "(", "ft", ".", "LowDateTime", "...
// Time returns the time as time.Time.
[ "Time", "returns", "the", "time", "as", "time", ".", "Time", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L199-L207
train
Microsoft/go-winio
wim/wim.go
UnmarshalXML
func (ft *Filetime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { type time struct { Low string `xml:"LOWPART"` High string `xml:"HIGHPART"` } var t time err := d.DecodeElement(&t, &start) if err != nil { return err } low, err := strconv.ParseUint(t.Low, 0, 32) if err != nil { return err } high, err := strconv.ParseUint(t.High, 0, 32) if err != nil { return err } ft.LowDateTime = uint32(low) ft.HighDateTime = uint32(high) return nil }
go
func (ft *Filetime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { type time struct { Low string `xml:"LOWPART"` High string `xml:"HIGHPART"` } var t time err := d.DecodeElement(&t, &start) if err != nil { return err } low, err := strconv.ParseUint(t.Low, 0, 32) if err != nil { return err } high, err := strconv.ParseUint(t.High, 0, 32) if err != nil { return err } ft.LowDateTime = uint32(low) ft.HighDateTime = uint32(high) return nil }
[ "func", "(", "ft", "*", "Filetime", ")", "UnmarshalXML", "(", "d", "*", "xml", ".", "Decoder", ",", "start", "xml", ".", "StartElement", ")", "error", "{", "type", "time", "struct", "{", "Low", "string", "`xml:\"LOWPART\"`", "\n", "High", "string", "`xml...
// UnmarshalXML unmarshals the time from a WIM XML blob.
[ "UnmarshalXML", "unmarshals", "the", "time", "from", "a", "WIM", "XML", "blob", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L210-L233
train
Microsoft/go-winio
wim/wim.go
NewReader
func NewReader(f io.ReaderAt) (*Reader, error) { r := &Reader{r: f} section := io.NewSectionReader(f, 0, 0xffff) err := binary.Read(section, binary.LittleEndian, &r.hdr) if err != nil { return nil, err } if r.hdr.ImageTag != wimImageTag { return nil, &ParseError{Oper: "image tag", Err: errors.New("not a WIM file")} } if r.hdr.Flags&^supportedHdrFlags != 0 { return nil, fmt.Errorf("unsupported WIM flags %x", r.hdr.Flags&^supportedHdrFlags) } if r.hdr.CompressionSize != 0x8000 { return nil, fmt.Errorf("unsupported compression size %d", r.hdr.CompressionSize) } if r.hdr.TotalParts != 1 { return nil, errors.New("multi-part WIM not supported") } fileData, images, err := r.readOffsetTable(&r.hdr.OffsetTable) if err != nil { return nil, err } xmlinfo, err := r.readXML() if err != nil { return nil, err } var info info err = xml.Unmarshal([]byte(xmlinfo), &info) if err != nil { return nil, &ParseError{Oper: "XML info", Err: err} } for i, img := range images { for _, imgInfo := range info.Image { if imgInfo.Index == i+1 { img.ImageInfo = imgInfo break } } } r.fileData = fileData r.Image = images r.XMLInfo = xmlinfo return r, nil }
go
func NewReader(f io.ReaderAt) (*Reader, error) { r := &Reader{r: f} section := io.NewSectionReader(f, 0, 0xffff) err := binary.Read(section, binary.LittleEndian, &r.hdr) if err != nil { return nil, err } if r.hdr.ImageTag != wimImageTag { return nil, &ParseError{Oper: "image tag", Err: errors.New("not a WIM file")} } if r.hdr.Flags&^supportedHdrFlags != 0 { return nil, fmt.Errorf("unsupported WIM flags %x", r.hdr.Flags&^supportedHdrFlags) } if r.hdr.CompressionSize != 0x8000 { return nil, fmt.Errorf("unsupported compression size %d", r.hdr.CompressionSize) } if r.hdr.TotalParts != 1 { return nil, errors.New("multi-part WIM not supported") } fileData, images, err := r.readOffsetTable(&r.hdr.OffsetTable) if err != nil { return nil, err } xmlinfo, err := r.readXML() if err != nil { return nil, err } var info info err = xml.Unmarshal([]byte(xmlinfo), &info) if err != nil { return nil, &ParseError{Oper: "XML info", Err: err} } for i, img := range images { for _, imgInfo := range info.Image { if imgInfo.Index == i+1 { img.ImageInfo = imgInfo break } } } r.fileData = fileData r.Image = images r.XMLInfo = xmlinfo return r, nil }
[ "func", "NewReader", "(", "f", "io", ".", "ReaderAt", ")", "(", "*", "Reader", ",", "error", ")", "{", "r", ":=", "&", "Reader", "{", "r", ":", "f", "}", "\n", "section", ":=", "io", ".", "NewSectionReader", "(", "f", ",", "0", ",", "0xffff", "...
// NewReader returns a Reader that can be used to read WIM file data.
[ "NewReader", "returns", "a", "Reader", "that", "can", "be", "used", "to", "read", "WIM", "file", "data", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L347-L400
train
Microsoft/go-winio
wim/wim.go
Close
func (r *Reader) Close() error { for _, img := range r.Image { img.reset() } return nil }
go
func (r *Reader) Close() error { for _, img := range r.Image { img.reset() } return nil }
[ "func", "(", "r", "*", "Reader", ")", "Close", "(", ")", "error", "{", "for", "_", ",", "img", ":=", "range", "r", ".", "Image", "{", "img", ".", "reset", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close releases resources associated with the Reader.
[ "Close", "releases", "resources", "associated", "with", "the", "Reader", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L403-L408
train
Microsoft/go-winio
wim/wim.go
Open
func (img *Image) Open() (*File, error) { if img.sds == nil { rsrc, err := img.wim.resourceReaderWithOffset(&img.offset, img.rootOffset) if err != nil { return nil, err } sds, n, err := img.wim.readSecurityDescriptors(rsrc) if err != nil { rsrc.Close() return nil, err } img.sds = sds img.r = rsrc img.rootOffset = n img.curOffset = n } f, err := img.readdir(img.rootOffset) if err != nil { return nil, err } if len(f) != 1 { return nil, &ParseError{Oper: "root directory", Err: errors.New("expected exactly 1 root directory entry")} } return f[0], err }
go
func (img *Image) Open() (*File, error) { if img.sds == nil { rsrc, err := img.wim.resourceReaderWithOffset(&img.offset, img.rootOffset) if err != nil { return nil, err } sds, n, err := img.wim.readSecurityDescriptors(rsrc) if err != nil { rsrc.Close() return nil, err } img.sds = sds img.r = rsrc img.rootOffset = n img.curOffset = n } f, err := img.readdir(img.rootOffset) if err != nil { return nil, err } if len(f) != 1 { return nil, &ParseError{Oper: "root directory", Err: errors.New("expected exactly 1 root directory entry")} } return f[0], err }
[ "func", "(", "img", "*", "Image", ")", "Open", "(", ")", "(", "*", "File", ",", "error", ")", "{", "if", "img", ".", "sds", "==", "nil", "{", "rsrc", ",", "err", ":=", "img", ".", "wim", ".", "resourceReaderWithOffset", "(", "&", "img", ".", "o...
// Open parses the image and returns the root directory.
[ "Open", "parses", "the", "image", "and", "returns", "the", "root", "directory", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L570-L595
train
Microsoft/go-winio
wim/wim.go
Open
func (s *Stream) Open() (io.ReadCloser, error) { return s.wim.resourceReader(&s.offset) }
go
func (s *Stream) Open() (io.ReadCloser, error) { return s.wim.resourceReader(&s.offset) }
[ "func", "(", "s", "*", "Stream", ")", "Open", "(", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "s", ".", "wim", ".", "resourceReader", "(", "&", "s", ".", "offset", ")", "\n", "}" ]
// Open returns an io.ReadCloser that can be used to read the stream's contents.
[ "Open", "returns", "an", "io", ".", "ReadCloser", "that", "can", "be", "used", "to", "read", "the", "stream", "s", "contents", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L845-L847
train
Microsoft/go-winio
wim/wim.go
Open
func (f *File) Open() (io.ReadCloser, error) { return f.img.wim.resourceReader(&f.offset) }
go
func (f *File) Open() (io.ReadCloser, error) { return f.img.wim.resourceReader(&f.offset) }
[ "func", "(", "f", "*", "File", ")", "Open", "(", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "f", ".", "img", ".", "wim", ".", "resourceReader", "(", "&", "f", ".", "offset", ")", "\n", "}" ]
// Open returns an io.ReadCloser that can be used to read the file's contents.
[ "Open", "returns", "an", "io", ".", "ReadCloser", "that", "can", "be", "used", "to", "read", "the", "file", "s", "contents", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L850-L852
train
Microsoft/go-winio
wim/wim.go
Readdir
func (f *File) Readdir() ([]*File, error) { if !f.IsDir() { return nil, errors.New("not a directory") } return f.img.readdir(f.subdirOffset) }
go
func (f *File) Readdir() ([]*File, error) { if !f.IsDir() { return nil, errors.New("not a directory") } return f.img.readdir(f.subdirOffset) }
[ "func", "(", "f", "*", "File", ")", "Readdir", "(", ")", "(", "[", "]", "*", "File", ",", "error", ")", "{", "if", "!", "f", ".", "IsDir", "(", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "...
// Readdir reads the directory entries.
[ "Readdir", "reads", "the", "directory", "entries", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L855-L860
train
Microsoft/go-winio
wim/lzx/lzx.go
feed
func (f *decompressor) feed() bool { err := f.ensureAtLeast(2) if err != nil { if err == io.ErrUnexpectedEOF { return false } } f.c |= (uint32(f.b[f.bo+1])<<8 | uint32(f.b[f.bo])) << (16 - f.nbits) f.nbits += 16 f.bo += 2 return true }
go
func (f *decompressor) feed() bool { err := f.ensureAtLeast(2) if err != nil { if err == io.ErrUnexpectedEOF { return false } } f.c |= (uint32(f.b[f.bo+1])<<8 | uint32(f.b[f.bo])) << (16 - f.nbits) f.nbits += 16 f.bo += 2 return true }
[ "func", "(", "f", "*", "decompressor", ")", "feed", "(", ")", "bool", "{", "err", ":=", "f", ".", "ensureAtLeast", "(", "2", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "ErrUnexpectedEOF", "{", "return", "false", "\n", ...
// feed retrieves another 16-bit word from the stream and consumes // it into f.c. It returns false if there are no more bytes available. // Otherwise, on error, it sets f.err.
[ "feed", "retrieves", "another", "16", "-", "bit", "word", "from", "the", "stream", "and", "consumes", "it", "into", "f", ".", "c", ".", "It", "returns", "false", "if", "there", "are", "no", "more", "bytes", "available", ".", "Otherwise", "on", "error", ...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L118-L129
train
Microsoft/go-winio
wim/lzx/lzx.go
getBits
func (f *decompressor) getBits(n byte) uint16 { if f.nbits < n { if !f.feed() { f.fail(io.ErrUnexpectedEOF) } } c := uint16(f.c >> (32 - n)) f.c <<= n f.nbits -= n return c }
go
func (f *decompressor) getBits(n byte) uint16 { if f.nbits < n { if !f.feed() { f.fail(io.ErrUnexpectedEOF) } } c := uint16(f.c >> (32 - n)) f.c <<= n f.nbits -= n return c }
[ "func", "(", "f", "*", "decompressor", ")", "getBits", "(", "n", "byte", ")", "uint16", "{", "if", "f", ".", "nbits", "<", "n", "{", "if", "!", "f", ".", "feed", "(", ")", "{", "f", ".", "fail", "(", "io", ".", "ErrUnexpectedEOF", ")", "\n", ...
// getBits retrieves the next n bits from the byte stream. n // must be <= 16. It sets f.err on error.
[ "getBits", "retrieves", "the", "next", "n", "bits", "from", "the", "byte", "stream", ".", "n", "must", "be", "<", "=", "16", ".", "It", "sets", "f", ".", "err", "on", "error", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L133-L143
train
Microsoft/go-winio
wim/lzx/lzx.go
getCode
func (f *decompressor) getCode(h *huffman) uint16 { if h.maxbits > 0 { if f.nbits < maxTreePathLen { f.feed() } // For codes with length < tablebits, it doesn't matter // what the remainder of the bits used for table lookup // are, since entries with all possible suffixes were // added to the table. c := h.table[f.c>>(32-tablebits)] if c >= 1<<lenshift { // The code is already in c. } else { c = h.extra[c][f.c<<tablebits>>(32-(h.maxbits-tablebits))] } n := byte(c >> lenshift) if f.nbits >= n { // Only consume the length of the code, not the maximum // code length. f.c <<= n f.nbits -= n return c & codemask } f.fail(io.ErrUnexpectedEOF) return 0 } // This is an empty tree. It should not be used. f.fail(errCorrupt) return 0 }
go
func (f *decompressor) getCode(h *huffman) uint16 { if h.maxbits > 0 { if f.nbits < maxTreePathLen { f.feed() } // For codes with length < tablebits, it doesn't matter // what the remainder of the bits used for table lookup // are, since entries with all possible suffixes were // added to the table. c := h.table[f.c>>(32-tablebits)] if c >= 1<<lenshift { // The code is already in c. } else { c = h.extra[c][f.c<<tablebits>>(32-(h.maxbits-tablebits))] } n := byte(c >> lenshift) if f.nbits >= n { // Only consume the length of the code, not the maximum // code length. f.c <<= n f.nbits -= n return c & codemask } f.fail(io.ErrUnexpectedEOF) return 0 } // This is an empty tree. It should not be used. f.fail(errCorrupt) return 0 }
[ "func", "(", "f", "*", "decompressor", ")", "getCode", "(", "h", "*", "huffman", ")", "uint16", "{", "if", "h", ".", "maxbits", ">", "0", "{", "if", "f", ".", "nbits", "<", "maxTreePathLen", "{", "f", ".", "feed", "(", ")", "\n", "}", "\n\n", "...
// getCode retrieves the next code using the provided // huffman tree. It sets f.err on error.
[ "getCode", "retrieves", "the", "next", "code", "using", "the", "provided", "huffman", "tree", ".", "It", "sets", "f", ".", "err", "on", "error", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L224-L257
train
Microsoft/go-winio
wim/lzx/lzx.go
readTree
func (f *decompressor) readTree(lens []byte) error { // Get the pre-tree for the main tree. var pretreeLen [20]byte for i := range pretreeLen { pretreeLen[i] = byte(f.getBits(4)) } if f.err != nil { return f.err } h := buildTable(pretreeLen[:]) // The lengths are encoded as a series of huffman codes // encoded by the pre-tree. for i := 0; i < len(lens); { c := byte(f.getCode(h)) if f.err != nil { return f.err } switch { case c <= 16: // length is delta from previous length lens[i] = (lens[i] + 17 - c) % 17 i++ case c == 17: // next n + 4 lengths are zero zeroes := int(f.getBits(4)) + 4 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 18: // next n + 20 lengths are zero zeroes := int(f.getBits(5)) + 20 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 19: // next n + 4 lengths all have the same value same := int(f.getBits(1)) + 4 if i+same > len(lens) { return errCorrupt } c = byte(f.getCode(h)) if c > 16 { return errCorrupt } l := (lens[i] + 17 - c) % 17 for j := 0; j < same; j++ { lens[i+j] = l } i += same default: return errCorrupt } } if f.err != nil { return f.err } return nil }
go
func (f *decompressor) readTree(lens []byte) error { // Get the pre-tree for the main tree. var pretreeLen [20]byte for i := range pretreeLen { pretreeLen[i] = byte(f.getBits(4)) } if f.err != nil { return f.err } h := buildTable(pretreeLen[:]) // The lengths are encoded as a series of huffman codes // encoded by the pre-tree. for i := 0; i < len(lens); { c := byte(f.getCode(h)) if f.err != nil { return f.err } switch { case c <= 16: // length is delta from previous length lens[i] = (lens[i] + 17 - c) % 17 i++ case c == 17: // next n + 4 lengths are zero zeroes := int(f.getBits(4)) + 4 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 18: // next n + 20 lengths are zero zeroes := int(f.getBits(5)) + 20 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 19: // next n + 4 lengths all have the same value same := int(f.getBits(1)) + 4 if i+same > len(lens) { return errCorrupt } c = byte(f.getCode(h)) if c > 16 { return errCorrupt } l := (lens[i] + 17 - c) % 17 for j := 0; j < same; j++ { lens[i+j] = l } i += same default: return errCorrupt } } if f.err != nil { return f.err } return nil }
[ "func", "(", "f", "*", "decompressor", ")", "readTree", "(", "lens", "[", "]", "byte", ")", "error", "{", "// Get the pre-tree for the main tree.", "var", "pretreeLen", "[", "20", "]", "byte", "\n", "for", "i", ":=", "range", "pretreeLen", "{", "pretreeLen",...
// readTree updates the huffman tree path lengths in lens by // reading and decoding lengths from the byte stream. lens // should be prepopulated with the previous block's tree's path // lengths. For the first block, lens should be zero.
[ "readTree", "updates", "the", "huffman", "tree", "path", "lengths", "in", "lens", "by", "reading", "and", "decoding", "lengths", "from", "the", "byte", "stream", ".", "lens", "should", "be", "prepopulated", "with", "the", "previous", "block", "s", "tree", "s...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L263-L326
train
Microsoft/go-winio
wim/lzx/lzx.go
readTrees
func (f *decompressor) readTrees(readAligned bool) (main *huffman, length *huffman, aligned *huffman, err error) { // Aligned offset blocks start with a small aligned offset tree. if readAligned { var alignedLen [8]byte for i := range alignedLen { alignedLen[i] = byte(f.getBits(3)) } aligned = buildTable(alignedLen[:]) if aligned == nil { err = errors.New("corrupt") return } } // The main tree is encoded in two parts. err = f.readTree(f.mainlens[:maincodesplit]) if err != nil { return } err = f.readTree(f.mainlens[maincodesplit:]) if err != nil { return } main = buildTable(f.mainlens[:]) if main == nil { err = errors.New("corrupt") return } // The length tree is encoding in a single part. err = f.readTree(f.lenlens[:]) if err != nil { return } length = buildTable(f.lenlens[:]) if length == nil { err = errors.New("corrupt") return } err = f.err return }
go
func (f *decompressor) readTrees(readAligned bool) (main *huffman, length *huffman, aligned *huffman, err error) { // Aligned offset blocks start with a small aligned offset tree. if readAligned { var alignedLen [8]byte for i := range alignedLen { alignedLen[i] = byte(f.getBits(3)) } aligned = buildTable(alignedLen[:]) if aligned == nil { err = errors.New("corrupt") return } } // The main tree is encoded in two parts. err = f.readTree(f.mainlens[:maincodesplit]) if err != nil { return } err = f.readTree(f.mainlens[maincodesplit:]) if err != nil { return } main = buildTable(f.mainlens[:]) if main == nil { err = errors.New("corrupt") return } // The length tree is encoding in a single part. err = f.readTree(f.lenlens[:]) if err != nil { return } length = buildTable(f.lenlens[:]) if length == nil { err = errors.New("corrupt") return } err = f.err return }
[ "func", "(", "f", "*", "decompressor", ")", "readTrees", "(", "readAligned", "bool", ")", "(", "main", "*", "huffman", ",", "length", "*", "huffman", ",", "aligned", "*", "huffman", ",", "err", "error", ")", "{", "// Aligned offset blocks start with a small al...
// readTrees reads the two or three huffman trees for the current block. // readAligned specifies whether to read the aligned offset tree.
[ "readTrees", "reads", "the", "two", "or", "three", "huffman", "trees", "for", "the", "current", "block", ".", "readAligned", "specifies", "whether", "to", "read", "the", "aligned", "offset", "tree", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L393-L437
train
Microsoft/go-winio
wim/lzx/lzx.go
readCompressedBlock
func (f *decompressor) readCompressedBlock(start, end uint16, hmain, hlength, haligned *huffman) (int, error) { i := start for i < end { main := f.getCode(hmain) if f.err != nil { break } if main < 256 { // Literal byte. f.window[i] = byte(main) i++ continue } // This is a match backward in the window. Determine // the offset and dlength. matchlen := (main - 256) % 8 slot := (main - 256) / 8 // The length is either the low bits of the code, // or if this is 7, is encoded with the length tree. if matchlen == 7 { matchlen += f.getCode(hlength) } matchlen += 2 var matchoffset uint16 if slot < 3 { // The offset is one of the LRU values. matchoffset = f.lru[slot] f.lru[slot] = f.lru[0] f.lru[0] = matchoffset } else { // The offset is encoded as a combination of the // slot and more bits from the bit stream. offsetbits := footerBits[slot] var verbatimbits, alignedbits uint16 if offsetbits > 0 { if haligned != nil && offsetbits >= 3 { // This is an aligned offset block. Combine // the bits written verbatim with the aligned // offset tree code. verbatimbits = f.getBits(offsetbits-3) * 8 alignedbits = f.getCode(haligned) } else { // There are no aligned offset bits to read, // only verbatim bits. verbatimbits = f.getBits(offsetbits) alignedbits = 0 } } matchoffset = basePosition[slot] + verbatimbits + alignedbits - 2 // Update the LRU cache. f.lru[2] = f.lru[1] f.lru[1] = f.lru[0] f.lru[0] = matchoffset } if matchoffset <= i && matchlen <= end-i { copyend := i + matchlen for ; i < copyend; i++ { f.window[i] = f.window[i-matchoffset] } } else { f.fail(errCorrupt) break } } return int(i - start), f.err }
go
func (f *decompressor) readCompressedBlock(start, end uint16, hmain, hlength, haligned *huffman) (int, error) { i := start for i < end { main := f.getCode(hmain) if f.err != nil { break } if main < 256 { // Literal byte. f.window[i] = byte(main) i++ continue } // This is a match backward in the window. Determine // the offset and dlength. matchlen := (main - 256) % 8 slot := (main - 256) / 8 // The length is either the low bits of the code, // or if this is 7, is encoded with the length tree. if matchlen == 7 { matchlen += f.getCode(hlength) } matchlen += 2 var matchoffset uint16 if slot < 3 { // The offset is one of the LRU values. matchoffset = f.lru[slot] f.lru[slot] = f.lru[0] f.lru[0] = matchoffset } else { // The offset is encoded as a combination of the // slot and more bits from the bit stream. offsetbits := footerBits[slot] var verbatimbits, alignedbits uint16 if offsetbits > 0 { if haligned != nil && offsetbits >= 3 { // This is an aligned offset block. Combine // the bits written verbatim with the aligned // offset tree code. verbatimbits = f.getBits(offsetbits-3) * 8 alignedbits = f.getCode(haligned) } else { // There are no aligned offset bits to read, // only verbatim bits. verbatimbits = f.getBits(offsetbits) alignedbits = 0 } } matchoffset = basePosition[slot] + verbatimbits + alignedbits - 2 // Update the LRU cache. f.lru[2] = f.lru[1] f.lru[1] = f.lru[0] f.lru[0] = matchoffset } if matchoffset <= i && matchlen <= end-i { copyend := i + matchlen for ; i < copyend; i++ { f.window[i] = f.window[i-matchoffset] } } else { f.fail(errCorrupt) break } } return int(i - start), f.err }
[ "func", "(", "f", "*", "decompressor", ")", "readCompressedBlock", "(", "start", ",", "end", "uint16", ",", "hmain", ",", "hlength", ",", "haligned", "*", "huffman", ")", "(", "int", ",", "error", ")", "{", "i", ":=", "start", "\n", "for", "i", "<", ...
// readCompressedBlock decodes a compressed block, writing into the window // starting at start and ending at end, and using the provided huffman trees.
[ "readCompressedBlock", "decodes", "a", "compressed", "block", "writing", "into", "the", "window", "starting", "at", "start", "and", "ending", "at", "end", "and", "using", "the", "provided", "huffman", "trees", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L441-L510
train
Microsoft/go-winio
wim/lzx/lzx.go
readBlock
func (f *decompressor) readBlock(start uint16) (int, error) { blockType, size, err := f.readBlockHeader() if err != nil { return 0, err } if blockType == uncompressedBlock { if size%2 == 1 { // Remember to realign the byte stream at the next block. f.unaligned = true } copied := 0 if f.bo < f.bv { copied = int(size) s := int(start) if copied > f.bv-f.bo { copied = f.bv - f.bo } copy(f.window[s:s+copied], f.b[f.bo:f.bo+copied]) f.bo += copied } n, err := io.ReadFull(f.r, f.window[start+uint16(copied):start+size]) return copied + n, err } hmain, hlength, haligned, err := f.readTrees(blockType == alignedOffsetBlock) if err != nil { return 0, err } return f.readCompressedBlock(start, start+size, hmain, hlength, haligned) }
go
func (f *decompressor) readBlock(start uint16) (int, error) { blockType, size, err := f.readBlockHeader() if err != nil { return 0, err } if blockType == uncompressedBlock { if size%2 == 1 { // Remember to realign the byte stream at the next block. f.unaligned = true } copied := 0 if f.bo < f.bv { copied = int(size) s := int(start) if copied > f.bv-f.bo { copied = f.bv - f.bo } copy(f.window[s:s+copied], f.b[f.bo:f.bo+copied]) f.bo += copied } n, err := io.ReadFull(f.r, f.window[start+uint16(copied):start+size]) return copied + n, err } hmain, hlength, haligned, err := f.readTrees(blockType == alignedOffsetBlock) if err != nil { return 0, err } return f.readCompressedBlock(start, start+size, hmain, hlength, haligned) }
[ "func", "(", "f", "*", "decompressor", ")", "readBlock", "(", "start", "uint16", ")", "(", "int", ",", "error", ")", "{", "blockType", ",", "size", ",", "err", ":=", "f", ".", "readBlockHeader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "retur...
// readBlock decodes the current block and returns the number of uncompressed bytes.
[ "readBlock", "decodes", "the", "current", "block", "and", "returns", "the", "number", "of", "uncompressed", "bytes", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L513-L544
train
Microsoft/go-winio
wim/lzx/lzx.go
decodeE8
func decodeE8(b []byte, off int64) { if off > maxe8offset || len(b) < 10 { return } for i := 0; i < len(b)-10; i++ { if b[i] == 0xe8 { currentPtr := int32(off) + int32(i) abs := int32(binary.LittleEndian.Uint32(b[i+1 : i+5])) if abs >= -currentPtr && abs < e8filesize { var rel int32 if abs >= 0 { rel = abs - currentPtr } else { rel = abs + e8filesize } binary.LittleEndian.PutUint32(b[i+1:i+5], uint32(rel)) } i += 4 } } }
go
func decodeE8(b []byte, off int64) { if off > maxe8offset || len(b) < 10 { return } for i := 0; i < len(b)-10; i++ { if b[i] == 0xe8 { currentPtr := int32(off) + int32(i) abs := int32(binary.LittleEndian.Uint32(b[i+1 : i+5])) if abs >= -currentPtr && abs < e8filesize { var rel int32 if abs >= 0 { rel = abs - currentPtr } else { rel = abs + e8filesize } binary.LittleEndian.PutUint32(b[i+1:i+5], uint32(rel)) } i += 4 } } }
[ "func", "decodeE8", "(", "b", "[", "]", "byte", ",", "off", "int64", ")", "{", "if", "off", ">", "maxe8offset", "||", "len", "(", "b", ")", "<", "10", "{", "return", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "b", ")...
// decodeE8 reverses the 0xe8 x86 instruction encoding that was performed // to the uncompressed data before it was compressed.
[ "decodeE8", "reverses", "the", "0xe8", "x86", "instruction", "encoding", "that", "was", "performed", "to", "the", "uncompressed", "data", "before", "it", "was", "compressed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L548-L568
train
Microsoft/go-winio
wim/lzx/lzx.go
NewReader
func NewReader(r io.Reader, uncompressedSize int) (io.ReadCloser, error) { if uncompressedSize > windowSize { return nil, errors.New("uncompressed size is limited to 32KB") } f := &decompressor{ lru: [3]uint16{1, 1, 1}, uncompressed: uncompressedSize, b: make([]byte, 4096), r: r, } return f, nil }
go
func NewReader(r io.Reader, uncompressedSize int) (io.ReadCloser, error) { if uncompressedSize > windowSize { return nil, errors.New("uncompressed size is limited to 32KB") } f := &decompressor{ lru: [3]uint16{1, 1, 1}, uncompressed: uncompressedSize, b: make([]byte, 4096), r: r, } return f, nil }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ",", "uncompressedSize", "int", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "if", "uncompressedSize", ">", "windowSize", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\""...
// NewReader returns a new io.ReadCloser that decompresses a // WIM LZX stream until uncompressedSize bytes have been returned.
[ "NewReader", "returns", "a", "new", "io", ".", "ReadCloser", "that", "decompresses", "a", "WIM", "LZX", "stream", "until", "uncompressedSize", "bytes", "have", "been", "returned", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L595-L606
train
Microsoft/go-winio
pkg/guid/guid.go
FromString
func FromString(s string) (*GUID, error) { if len(s) != 36 { return nil, errors.New("invalid GUID format (length)") } if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { return nil, errors.New("invalid GUID format (dashes)") } var g GUID data1, err := strconv.ParseUint(s[0:8], 16, 32) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data1)") } g.Data1 = uint32(data1) data2, err := strconv.ParseUint(s[9:13], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data2)") } g.Data2 = uint16(data2) data3, err := strconv.ParseUint(s[14:18], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data3)") } g.Data3 = uint16(data3) for i, x := range []int{19, 21, 24, 26, 28, 30, 32, 34} { v, err := strconv.ParseUint(s[x:x+2], 16, 8) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data4)") } g.Data4[i] = uint8(v) } return &g, nil }
go
func FromString(s string) (*GUID, error) { if len(s) != 36 { return nil, errors.New("invalid GUID format (length)") } if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { return nil, errors.New("invalid GUID format (dashes)") } var g GUID data1, err := strconv.ParseUint(s[0:8], 16, 32) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data1)") } g.Data1 = uint32(data1) data2, err := strconv.ParseUint(s[9:13], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data2)") } g.Data2 = uint16(data2) data3, err := strconv.ParseUint(s[14:18], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data3)") } g.Data3 = uint16(data3) for i, x := range []int{19, 21, 24, 26, 28, 30, 32, 34} { v, err := strconv.ParseUint(s[x:x+2], 16, 8) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data4)") } g.Data4[i] = uint8(v) } return &g, nil }
[ "func", "FromString", "(", "s", "string", ")", "(", "*", "GUID", ",", "error", ")", "{", "if", "len", "(", "s", ")", "!=", "36", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "s", "[", "8", "]...
// FromString parses a string containing a GUID and returns the GUID. The only // format currently supported is the `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` // format.
[ "FromString", "parses", "a", "string", "containing", "a", "GUID", "and", "returns", "the", "GUID", ".", "The", "only", "format", "currently", "supported", "is", "the", "xxxxxxxx", "-", "xxxx", "-", "xxxx", "-", "xxxx", "-", "xxxxxxxxxxxx", "format", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/guid/guid.go#L56-L93
train
Microsoft/go-winio
pkg/guid/guid.go
UnmarshalJSON
func (g *GUID) UnmarshalJSON(data []byte) error { g2, err := FromString(strings.Trim(string(data), "\"")) if err != nil { return err } *g = *g2 return nil }
go
func (g *GUID) UnmarshalJSON(data []byte) error { g2, err := FromString(strings.Trim(string(data), "\"")) if err != nil { return err } *g = *g2 return nil }
[ "func", "(", "g", "*", "GUID", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "g2", ",", "err", ":=", "FromString", "(", "strings", ".", "Trim", "(", "string", "(", "data", ")", ",", "\"", "\\\"", "\"", ")", ")", "\n", ...
// UnmarshalJSON unmarshals a GUID from JSON representation and sets itself to // the unmarshaled GUID.
[ "UnmarshalJSON", "unmarshals", "a", "GUID", "from", "JSON", "representation", "and", "sets", "itself", "to", "the", "unmarshaled", "GUID", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/guid/guid.go#L103-L110
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
tmpVar
func (p *Param) tmpVar() string { if p.tmpVarIdx < 0 { p.tmpVarIdx = p.fn.curTmpVarIdx p.fn.curTmpVarIdx++ } return fmt.Sprintf("_p%d", p.tmpVarIdx) }
go
func (p *Param) tmpVar() string { if p.tmpVarIdx < 0 { p.tmpVarIdx = p.fn.curTmpVarIdx p.fn.curTmpVarIdx++ } return fmt.Sprintf("_p%d", p.tmpVarIdx) }
[ "func", "(", "p", "*", "Param", ")", "tmpVar", "(", ")", "string", "{", "if", "p", ".", "tmpVarIdx", "<", "0", "{", "p", ".", "tmpVarIdx", "=", "p", ".", "fn", ".", "curTmpVarIdx", "\n", "p", ".", "fn", ".", "curTmpVarIdx", "++", "\n", "}", "\n...
// tmpVar returns temp variable name that will be used to represent p during syscall.
[ "tmpVar", "returns", "temp", "variable", "name", "that", "will", "be", "used", "to", "represent", "p", "during", "syscall", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L100-L106
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
BoolTmpVarCode
func (p *Param) BoolTmpVarCode() string { const code = `var %s uint32 if %s { %s = 1 } else { %s = 0 }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Name, tmp, tmp) }
go
func (p *Param) BoolTmpVarCode() string { const code = `var %s uint32 if %s { %s = 1 } else { %s = 0 }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Name, tmp, tmp) }
[ "func", "(", "p", "*", "Param", ")", "BoolTmpVarCode", "(", ")", "string", "{", "const", "code", "=", "`var %s uint32\n\tif %s {\n\t\t%s = 1\n\t} else {\n\t\t%s = 0\n\t}`", "\n", "tmp", ":=", "p", ".", "tmpVar", "(", ")", "\n", "return", "fmt", ".", "Sprintf", ...
// BoolTmpVarCode returns source code for bool temp variable.
[ "BoolTmpVarCode", "returns", "source", "code", "for", "bool", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L109-L118
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SliceTmpVarCode
func (p *Param) SliceTmpVarCode() string { const code = `var %s *%s if len(%s) > 0 { %s = &%s[0] }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Type[2:], p.Name, tmp, p.Name) }
go
func (p *Param) SliceTmpVarCode() string { const code = `var %s *%s if len(%s) > 0 { %s = &%s[0] }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Type[2:], p.Name, tmp, p.Name) }
[ "func", "(", "p", "*", "Param", ")", "SliceTmpVarCode", "(", ")", "string", "{", "const", "code", "=", "`var %s *%s\n\tif len(%s) > 0 {\n\t\t%s = &%s[0]\n\t}`", "\n", "tmp", ":=", "p", ".", "tmpVar", "(", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "cod...
// SliceTmpVarCode returns source code for slice temp variable.
[ "SliceTmpVarCode", "returns", "source", "code", "for", "slice", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L121-L128
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
StringTmpVarCode
func (p *Param) StringTmpVarCode() string { errvar := p.fn.Rets.ErrorVarName() if errvar == "" { errvar = "_" } tmp := p.tmpVar() const code = `var %s %s %s, %s = %s(%s)` s := fmt.Sprintf(code, tmp, p.fn.StrconvType(), tmp, errvar, p.fn.StrconvFunc(), p.Name) if errvar == "-" { return s } const morecode = ` if %s != nil { return }` return s + fmt.Sprintf(morecode, errvar) }
go
func (p *Param) StringTmpVarCode() string { errvar := p.fn.Rets.ErrorVarName() if errvar == "" { errvar = "_" } tmp := p.tmpVar() const code = `var %s %s %s, %s = %s(%s)` s := fmt.Sprintf(code, tmp, p.fn.StrconvType(), tmp, errvar, p.fn.StrconvFunc(), p.Name) if errvar == "-" { return s } const morecode = ` if %s != nil { return }` return s + fmt.Sprintf(morecode, errvar) }
[ "func", "(", "p", "*", "Param", ")", "StringTmpVarCode", "(", ")", "string", "{", "errvar", ":=", "p", ".", "fn", ".", "Rets", ".", "ErrorVarName", "(", ")", "\n", "if", "errvar", "==", "\"", "\"", "{", "errvar", "=", "\"", "\"", "\n", "}", "\n",...
// StringTmpVarCode returns source code for string temp variable.
[ "StringTmpVarCode", "returns", "source", "code", "for", "string", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L131-L148
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
TmpVarCode
func (p *Param) TmpVarCode() string { switch { case p.Type == "bool": return p.BoolTmpVarCode() case strings.HasPrefix(p.Type, "[]"): return p.SliceTmpVarCode() default: return "" } }
go
func (p *Param) TmpVarCode() string { switch { case p.Type == "bool": return p.BoolTmpVarCode() case strings.HasPrefix(p.Type, "[]"): return p.SliceTmpVarCode() default: return "" } }
[ "func", "(", "p", "*", "Param", ")", "TmpVarCode", "(", ")", "string", "{", "switch", "{", "case", "p", ".", "Type", "==", "\"", "\"", ":", "return", "p", ".", "BoolTmpVarCode", "(", ")", "\n", "case", "strings", ".", "HasPrefix", "(", "p", ".", ...
// TmpVarCode returns source code for temp variable.
[ "TmpVarCode", "returns", "source", "code", "for", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L151-L160
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperType
func (p *Param) HelperType() string { if p.Type == "string" { return p.fn.StrconvType() } return p.Type }
go
func (p *Param) HelperType() string { if p.Type == "string" { return p.fn.StrconvType() } return p.Type }
[ "func", "(", "p", "*", "Param", ")", "HelperType", "(", ")", "string", "{", "if", "p", ".", "Type", "==", "\"", "\"", "{", "return", "p", ".", "fn", ".", "StrconvType", "(", ")", "\n", "}", "\n", "return", "p", ".", "Type", "\n", "}" ]
// HelperType returns type of parameter p used in helper function.
[ "HelperType", "returns", "type", "of", "parameter", "p", "used", "in", "helper", "function", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L198-L203
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
join
func join(ps []*Param, fn func(*Param) string, sep string) string { if len(ps) == 0 { return "" } a := make([]string, 0) for _, p := range ps { a = append(a, fn(p)) } return strings.Join(a, sep) }
go
func join(ps []*Param, fn func(*Param) string, sep string) string { if len(ps) == 0 { return "" } a := make([]string, 0) for _, p := range ps { a = append(a, fn(p)) } return strings.Join(a, sep) }
[ "func", "join", "(", "ps", "[", "]", "*", "Param", ",", "fn", "func", "(", "*", "Param", ")", "string", ",", "sep", "string", ")", "string", "{", "if", "len", "(", "ps", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "a", ":=", ...
// join concatenates parameters ps into a string with sep separator. // Each parameter is converted into string by applying fn to it // before conversion.
[ "join", "concatenates", "parameters", "ps", "into", "a", "string", "with", "sep", "separator", ".", "Each", "parameter", "is", "converted", "into", "string", "by", "applying", "fn", "to", "it", "before", "conversion", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L208-L217
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ErrorVarName
func (r *Rets) ErrorVarName() string { if r.ReturnsError { return "err" } if r.Type == "error" { return r.Name } return "" }
go
func (r *Rets) ErrorVarName() string { if r.ReturnsError { return "err" } if r.Type == "error" { return r.Name } return "" }
[ "func", "(", "r", "*", "Rets", ")", "ErrorVarName", "(", ")", "string", "{", "if", "r", ".", "ReturnsError", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "r", ".", "Type", "==", "\"", "\"", "{", "return", "r", ".", "Name", "\n", "}", "\n",...
// ErrorVarName returns error variable name for r.
[ "ErrorVarName", "returns", "error", "variable", "name", "for", "r", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L228-L236
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
List
func (r *Rets) List() string { s := join(r.ToParams(), func(p *Param) string { return p.Name + " " + p.Type }, ", ") if len(s) > 0 { s = "(" + s + ")" } return s }
go
func (r *Rets) List() string { s := join(r.ToParams(), func(p *Param) string { return p.Name + " " + p.Type }, ", ") if len(s) > 0 { s = "(" + s + ")" } return s }
[ "func", "(", "r", "*", "Rets", ")", "List", "(", ")", "string", "{", "s", ":=", "join", "(", "r", ".", "ToParams", "(", ")", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", "."...
// List returns source code of syscall return parameters.
[ "List", "returns", "source", "code", "of", "syscall", "return", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L251-L257
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
PrintList
func (r *Rets) PrintList() string { return join(r.ToParams(), func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
go
func (r *Rets) PrintList() string { return join(r.ToParams(), func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
[ "func", "(", "r", "*", "Rets", ")", "PrintList", "(", ")", "string", "{", "return", "join", "(", "r", ".", "ToParams", "(", ")", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "`\"%s=\", %s, `", ",", ...
// PrintList returns source code of trace printing part correspondent // to syscall return values.
[ "PrintList", "returns", "source", "code", "of", "trace", "printing", "part", "correspondent", "to", "syscall", "return", "values", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L261-L263
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SetReturnValuesCode
func (r *Rets) SetReturnValuesCode() string { if r.Name == "" && !r.ReturnsError { return "" } retvar := "r0" if r.Name == "" { retvar = "r1" } errvar := "_" if r.ReturnsError { errvar = "e1" } return fmt.Sprintf("%s, _, %s := ", retvar, errvar) }
go
func (r *Rets) SetReturnValuesCode() string { if r.Name == "" && !r.ReturnsError { return "" } retvar := "r0" if r.Name == "" { retvar = "r1" } errvar := "_" if r.ReturnsError { errvar = "e1" } return fmt.Sprintf("%s, _, %s := ", retvar, errvar) }
[ "func", "(", "r", "*", "Rets", ")", "SetReturnValuesCode", "(", ")", "string", "{", "if", "r", ".", "Name", "==", "\"", "\"", "&&", "!", "r", ".", "ReturnsError", "{", "return", "\"", "\"", "\n", "}", "\n", "retvar", ":=", "\"", "\"", "\n", "if",...
// SetReturnValuesCode returns source code that accepts syscall return values.
[ "SetReturnValuesCode", "returns", "source", "code", "that", "accepts", "syscall", "return", "values", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L266-L279
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SetErrorCode
func (r *Rets) SetErrorCode() string { const code = `if r0 != 0 { %s = %sErrno(r0) }` if r.Name == "" && !r.ReturnsError { return "" } if r.Name == "" { return r.useLongHandleErrorCode("r1") } if r.Type == "error" { return fmt.Sprintf(code, r.Name, syscalldot()) } s := "" switch { case r.Type[0] == '*': s = fmt.Sprintf("%s = (%s)(unsafe.Pointer(r0))", r.Name, r.Type) case r.Type == "bool": s = fmt.Sprintf("%s = r0 != 0", r.Name) default: s = fmt.Sprintf("%s = %s(r0)", r.Name, r.Type) } if !r.ReturnsError { return s } return s + "\n\t" + r.useLongHandleErrorCode(r.Name) }
go
func (r *Rets) SetErrorCode() string { const code = `if r0 != 0 { %s = %sErrno(r0) }` if r.Name == "" && !r.ReturnsError { return "" } if r.Name == "" { return r.useLongHandleErrorCode("r1") } if r.Type == "error" { return fmt.Sprintf(code, r.Name, syscalldot()) } s := "" switch { case r.Type[0] == '*': s = fmt.Sprintf("%s = (%s)(unsafe.Pointer(r0))", r.Name, r.Type) case r.Type == "bool": s = fmt.Sprintf("%s = r0 != 0", r.Name) default: s = fmt.Sprintf("%s = %s(r0)", r.Name, r.Type) } if !r.ReturnsError { return s } return s + "\n\t" + r.useLongHandleErrorCode(r.Name) }
[ "func", "(", "r", "*", "Rets", ")", "SetErrorCode", "(", ")", "string", "{", "const", "code", "=", "`if r0 != 0 {\n\t\t%s = %sErrno(r0)\n\t}`", "\n", "if", "r", ".", "Name", "==", "\"", "\"", "&&", "!", "r", ".", "ReturnsError", "{", "return", "\"", "\""...
// SetErrorCode returns source code that sets return parameters.
[ "SetErrorCode", "returns", "source", "code", "that", "sets", "return", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L297-L323
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
extractParams
func extractParams(s string, f *Fn) ([]*Param, error) { s = trim(s) if s == "" { return nil, nil } a := strings.Split(s, ",") ps := make([]*Param, len(a)) for i := range ps { s2 := trim(a[i]) b := strings.Split(s2, " ") if len(b) != 2 { b = strings.Split(s2, "\t") if len(b) != 2 { return nil, errors.New("Could not extract function parameter from \"" + s2 + "\"") } } ps[i] = &Param{ Name: trim(b[0]), Type: trim(b[1]), fn: f, tmpVarIdx: -1, } } return ps, nil }
go
func extractParams(s string, f *Fn) ([]*Param, error) { s = trim(s) if s == "" { return nil, nil } a := strings.Split(s, ",") ps := make([]*Param, len(a)) for i := range ps { s2 := trim(a[i]) b := strings.Split(s2, " ") if len(b) != 2 { b = strings.Split(s2, "\t") if len(b) != 2 { return nil, errors.New("Could not extract function parameter from \"" + s2 + "\"") } } ps[i] = &Param{ Name: trim(b[0]), Type: trim(b[1]), fn: f, tmpVarIdx: -1, } } return ps, nil }
[ "func", "extractParams", "(", "s", "string", ",", "f", "*", "Fn", ")", "(", "[", "]", "*", "Param", ",", "error", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "if", "s", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n...
// extractParams parses s to extract function parameters.
[ "extractParams", "parses", "s", "to", "extract", "function", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L339-L363
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
extractSection
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) { s = trim(s) if strings.HasPrefix(s, string(start)) { // no prefix body = s[1:] } else { a := strings.SplitN(s, string(start), 2) if len(a) != 2 { return "", "", s, false } prefix = a[0] body = a[1] } a := strings.SplitN(body, string(end), 2) if len(a) != 2 { return "", "", "", false } return prefix, a[0], a[1], true }
go
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) { s = trim(s) if strings.HasPrefix(s, string(start)) { // no prefix body = s[1:] } else { a := strings.SplitN(s, string(start), 2) if len(a) != 2 { return "", "", s, false } prefix = a[0] body = a[1] } a := strings.SplitN(body, string(end), 2) if len(a) != 2 { return "", "", "", false } return prefix, a[0], a[1], true }
[ "func", "extractSection", "(", "s", "string", ",", "start", ",", "end", "rune", ")", "(", "prefix", ",", "body", ",", "suffix", "string", ",", "found", "bool", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "if", "strings", ".", "HasPrefix", "(",...
// extractSection extracts text out of string s starting after start // and ending just before end. found return value will indicate success, // and prefix, body and suffix will contain correspondent parts of string s.
[ "extractSection", "extracts", "text", "out", "of", "string", "s", "starting", "after", "start", "and", "ending", "just", "before", "end", ".", "found", "return", "value", "will", "indicate", "success", "and", "prefix", "body", "and", "suffix", "will", "contain...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L368-L386
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
newFn
func newFn(s string) (*Fn, error) { s = trim(s) f := &Fn{ Rets: &Rets{}, src: s, PrintTrace: *printTraceFlag, } // function name and args prefix, body, s, found := extractSection(s, '(', ')') if !found || prefix == "" { return nil, errors.New("Could not extract function name and parameters from \"" + f.src + "\"") } f.Name = prefix var err error f.Params, err = extractParams(body, f) if err != nil { return nil, err } // return values _, body, s, found = extractSection(s, '(', ')') if found { r, err := extractParams(body, f) if err != nil { return nil, err } switch len(r) { case 0: case 1: if r[0].IsError() { f.Rets.ReturnsError = true } else { f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type } case 2: if !r[1].IsError() { return nil, errors.New("Only last windows error is allowed as second return value in \"" + f.src + "\"") } f.Rets.ReturnsError = true f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type default: return nil, errors.New("Too many return values in \"" + f.src + "\"") } } // fail condition _, body, s, found = extractSection(s, '[', ']') if found { f.Rets.FailCond = body } // dll and dll function names s = trim(s) if s == "" { return f, nil } if !strings.HasPrefix(s, "=") { return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } s = trim(s[1:]) a := strings.Split(s, ".") switch len(a) { case 1: f.dllfuncname = a[0] case 2: f.dllname = a[0] f.dllfuncname = a[1] default: return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } return f, nil }
go
func newFn(s string) (*Fn, error) { s = trim(s) f := &Fn{ Rets: &Rets{}, src: s, PrintTrace: *printTraceFlag, } // function name and args prefix, body, s, found := extractSection(s, '(', ')') if !found || prefix == "" { return nil, errors.New("Could not extract function name and parameters from \"" + f.src + "\"") } f.Name = prefix var err error f.Params, err = extractParams(body, f) if err != nil { return nil, err } // return values _, body, s, found = extractSection(s, '(', ')') if found { r, err := extractParams(body, f) if err != nil { return nil, err } switch len(r) { case 0: case 1: if r[0].IsError() { f.Rets.ReturnsError = true } else { f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type } case 2: if !r[1].IsError() { return nil, errors.New("Only last windows error is allowed as second return value in \"" + f.src + "\"") } f.Rets.ReturnsError = true f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type default: return nil, errors.New("Too many return values in \"" + f.src + "\"") } } // fail condition _, body, s, found = extractSection(s, '[', ']') if found { f.Rets.FailCond = body } // dll and dll function names s = trim(s) if s == "" { return f, nil } if !strings.HasPrefix(s, "=") { return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } s = trim(s[1:]) a := strings.Split(s, ".") switch len(a) { case 1: f.dllfuncname = a[0] case 2: f.dllname = a[0] f.dllfuncname = a[1] default: return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } return f, nil }
[ "func", "newFn", "(", "s", "string", ")", "(", "*", "Fn", ",", "error", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "f", ":=", "&", "Fn", "{", "Rets", ":", "&", "Rets", "{", "}", ",", "src", ":", "s", ",", "PrintTrace", ":", "*", "pr...
// newFn parses string s and return created function Fn.
[ "newFn", "parses", "string", "s", "and", "return", "created", "function", "Fn", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L389-L459
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
DLLFuncName
func (f *Fn) DLLFuncName() string { if f.dllfuncname == "" { return f.Name } return f.dllfuncname }
go
func (f *Fn) DLLFuncName() string { if f.dllfuncname == "" { return f.Name } return f.dllfuncname }
[ "func", "(", "f", "*", "Fn", ")", "DLLFuncName", "(", ")", "string", "{", "if", "f", ".", "dllfuncname", "==", "\"", "\"", "{", "return", "f", ".", "Name", "\n", "}", "\n", "return", "f", ".", "dllfuncname", "\n", "}" ]
// DLLName returns DLL function name for function f.
[ "DLLName", "returns", "DLL", "function", "name", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L470-L475
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamList
func (f *Fn) ParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.Type }, ", ") }
go
func (f *Fn) ParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.Type }, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "ParamList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", ".", "Type", "}...
// ParamList returns source code for function f parameters.
[ "ParamList", "returns", "source", "code", "for", "function", "f", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L478-L480
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperParamList
func (f *Fn) HelperParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.HelperType() }, ", ") }
go
func (f *Fn) HelperParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.HelperType() }, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "HelperParamList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", ".", "Helpe...
// HelperParamList returns source code for helper function f parameters.
[ "HelperParamList", "returns", "source", "code", "for", "helper", "function", "f", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L483-L485
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamPrintList
func (f *Fn) ParamPrintList() string { return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
go
func (f *Fn) ParamPrintList() string { return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
[ "func", "(", "f", "*", "Fn", ")", "ParamPrintList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "`\"%s=\", %s, `", ",", "p", ".",...
// ParamPrintList returns source code of trace printing part correspondent // to syscall input parameters.
[ "ParamPrintList", "returns", "source", "code", "of", "trace", "printing", "part", "correspondent", "to", "syscall", "input", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L489-L491
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamCount
func (f *Fn) ParamCount() int { n := 0 for _, p := range f.Params { n += len(p.SyscallArgList()) } return n }
go
func (f *Fn) ParamCount() int { n := 0 for _, p := range f.Params { n += len(p.SyscallArgList()) } return n }
[ "func", "(", "f", "*", "Fn", ")", "ParamCount", "(", ")", "int", "{", "n", ":=", "0", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "n", "+=", "len", "(", "p", ".", "SyscallArgList", "(", ")", ")", "\n", "}", "\n", "re...
// ParamCount return number of syscall parameters for function f.
[ "ParamCount", "return", "number", "of", "syscall", "parameters", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L494-L500
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
Syscall
func (f *Fn) Syscall() string { c := f.SyscallParamCount() if c == 3 { return syscalldot() + "Syscall" } return syscalldot() + "Syscall" + strconv.Itoa(c) }
go
func (f *Fn) Syscall() string { c := f.SyscallParamCount() if c == 3 { return syscalldot() + "Syscall" } return syscalldot() + "Syscall" + strconv.Itoa(c) }
[ "func", "(", "f", "*", "Fn", ")", "Syscall", "(", ")", "string", "{", "c", ":=", "f", ".", "SyscallParamCount", "(", ")", "\n", "if", "c", "==", "3", "{", "return", "syscalldot", "(", ")", "+", "\"", "\"", "\n", "}", "\n", "return", "syscalldot",...
// Syscall determines which SyscallX function to use for function f.
[ "Syscall", "determines", "which", "SyscallX", "function", "to", "use", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L523-L529
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SyscallParamList
func (f *Fn) SyscallParamList() string { a := make([]string, 0) for _, p := range f.Params { a = append(a, p.SyscallArgList()...) } for len(a) < f.SyscallParamCount() { a = append(a, "0") } return strings.Join(a, ", ") }
go
func (f *Fn) SyscallParamList() string { a := make([]string, 0) for _, p := range f.Params { a = append(a, p.SyscallArgList()...) } for len(a) < f.SyscallParamCount() { a = append(a, "0") } return strings.Join(a, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "SyscallParamList", "(", ")", "string", "{", "a", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "a", "=", "append", "(", "a", ",", ...
// SyscallParamList returns source code for SyscallX parameters for function f.
[ "SyscallParamList", "returns", "source", "code", "for", "SyscallX", "parameters", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L532-L541
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperCallParamList
func (f *Fn) HelperCallParamList() string { a := make([]string, 0, len(f.Params)) for _, p := range f.Params { s := p.Name if p.Type == "string" { s = p.tmpVar() } a = append(a, s) } return strings.Join(a, ", ") }
go
func (f *Fn) HelperCallParamList() string { a := make([]string, 0, len(f.Params)) for _, p := range f.Params { s := p.Name if p.Type == "string" { s = p.tmpVar() } a = append(a, s) } return strings.Join(a, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "HelperCallParamList", "(", ")", "string", "{", "a", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "f", ".", "Params", ")", ")", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Param...
// HelperCallParamList returns source code of call into function f helper.
[ "HelperCallParamList", "returns", "source", "code", "of", "call", "into", "function", "f", "helper", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L544-L554
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HasStringParam
func (f *Fn) HasStringParam() bool { for _, p := range f.Params { if p.Type == "string" { return true } } return false }
go
func (f *Fn) HasStringParam() bool { for _, p := range f.Params { if p.Type == "string" { return true } } return false }
[ "func", "(", "f", "*", "Fn", ")", "HasStringParam", "(", ")", "bool", "{", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "if", "p", ".", "Type", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "f...
// HasStringParam is true, if f has at least one string parameter. // Otherwise it is false.
[ "HasStringParam", "is", "true", "if", "f", "has", "at", "least", "one", "string", "parameter", ".", "Otherwise", "it", "is", "false", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L581-L588
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperName
func (f *Fn) HelperName() string { if !f.HasStringParam() { return f.Name } return "_" + f.Name }
go
func (f *Fn) HelperName() string { if !f.HasStringParam() { return f.Name } return "_" + f.Name }
[ "func", "(", "f", "*", "Fn", ")", "HelperName", "(", ")", "string", "{", "if", "!", "f", ".", "HasStringParam", "(", ")", "{", "return", "f", ".", "Name", "\n", "}", "\n", "return", "\"", "\"", "+", "f", ".", "Name", "\n", "}" ]
// HelperName returns name of function f helper.
[ "HelperName", "returns", "name", "of", "function", "f", "helper", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L591-L596
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
DLLs
func (src *Source) DLLs() []string { uniq := make(map[string]bool) r := make([]string, 0) for _, f := range src.Funcs { name := f.DLLName() if _, found := uniq[name]; !found { uniq[name] = true r = append(r, name) } } return r }
go
func (src *Source) DLLs() []string { uniq := make(map[string]bool) r := make([]string, 0) for _, f := range src.Funcs { name := f.DLLName() if _, found := uniq[name]; !found { uniq[name] = true r = append(r, name) } } return r }
[ "func", "(", "src", "*", "Source", ")", "DLLs", "(", ")", "[", "]", "string", "{", "uniq", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "r", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "f...
// DLLs return dll names for a source set src.
[ "DLLs", "return", "dll", "names", "for", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L650-L661
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParseFile
func (src *Source) ParseFile(path string) error { file, err := os.Open(path) if err != nil { return err } defer file.Close() s := bufio.NewScanner(file) for s.Scan() { t := trim(s.Text()) if len(t) < 7 { continue } if !strings.HasPrefix(t, "//sys") { continue } t = t[5:] if !(t[0] == ' ' || t[0] == '\t') { continue } f, err := newFn(t[1:]) if err != nil { return err } src.Funcs = append(src.Funcs, f) } if err := s.Err(); err != nil { return err } src.Files = append(src.Files, path) // get package name fset := token.NewFileSet() _, err = file.Seek(0, 0) if err != nil { return err } pkg, err := parser.ParseFile(fset, "", file, parser.PackageClauseOnly) if err != nil { return err } packageName = pkg.Name.Name return nil }
go
func (src *Source) ParseFile(path string) error { file, err := os.Open(path) if err != nil { return err } defer file.Close() s := bufio.NewScanner(file) for s.Scan() { t := trim(s.Text()) if len(t) < 7 { continue } if !strings.HasPrefix(t, "//sys") { continue } t = t[5:] if !(t[0] == ' ' || t[0] == '\t') { continue } f, err := newFn(t[1:]) if err != nil { return err } src.Funcs = append(src.Funcs, f) } if err := s.Err(); err != nil { return err } src.Files = append(src.Files, path) // get package name fset := token.NewFileSet() _, err = file.Seek(0, 0) if err != nil { return err } pkg, err := parser.ParseFile(fset, "", file, parser.PackageClauseOnly) if err != nil { return err } packageName = pkg.Name.Name return nil }
[ "func", "(", "src", "*", "Source", ")", "ParseFile", "(", "path", "string", ")", "error", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "file", ...
// ParseFile adds additional file path to a source set src.
[ "ParseFile", "adds", "additional", "file", "path", "to", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L664-L708
train
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
IsStdRepo
func (src *Source) IsStdRepo() (bool, error) { if len(src.Files) == 0 { return false, errors.New("no input files provided") } abspath, err := filepath.Abs(src.Files[0]) if err != nil { return false, err } goroot := runtime.GOROOT() if runtime.GOOS == "windows" { abspath = strings.ToLower(abspath) goroot = strings.ToLower(goroot) } sep := string(os.PathSeparator) if !strings.HasSuffix(goroot, sep) { goroot += sep } return strings.HasPrefix(abspath, goroot), nil }
go
func (src *Source) IsStdRepo() (bool, error) { if len(src.Files) == 0 { return false, errors.New("no input files provided") } abspath, err := filepath.Abs(src.Files[0]) if err != nil { return false, err } goroot := runtime.GOROOT() if runtime.GOOS == "windows" { abspath = strings.ToLower(abspath) goroot = strings.ToLower(goroot) } sep := string(os.PathSeparator) if !strings.HasSuffix(goroot, sep) { goroot += sep } return strings.HasPrefix(abspath, goroot), nil }
[ "func", "(", "src", "*", "Source", ")", "IsStdRepo", "(", ")", "(", "bool", ",", "error", ")", "{", "if", "len", "(", "src", ".", "Files", ")", "==", "0", "{", "return", "false", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n...
// IsStdRepo reports whether src is part of standard library.
[ "IsStdRepo", "reports", "whether", "src", "is", "part", "of", "standard", "library", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L711-L729
train
Microsoft/go-winio
file.go
makeWin32File
func makeWin32File(h syscall.Handle) (*win32File, error) { f := &win32File{handle: h} ioInitOnce.Do(initIo) _, err := createIoCompletionPort(h, ioCompletionPort, 0, 0xffffffff) if err != nil { return nil, err } err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) if err != nil { return nil, err } f.readDeadline.channel = make(timeoutChan) f.writeDeadline.channel = make(timeoutChan) return f, nil }
go
func makeWin32File(h syscall.Handle) (*win32File, error) { f := &win32File{handle: h} ioInitOnce.Do(initIo) _, err := createIoCompletionPort(h, ioCompletionPort, 0, 0xffffffff) if err != nil { return nil, err } err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) if err != nil { return nil, err } f.readDeadline.channel = make(timeoutChan) f.writeDeadline.channel = make(timeoutChan) return f, nil }
[ "func", "makeWin32File", "(", "h", "syscall", ".", "Handle", ")", "(", "*", "win32File", ",", "error", ")", "{", "f", ":=", "&", "win32File", "{", "handle", ":", "h", "}", "\n", "ioInitOnce", ".", "Do", "(", "initIo", ")", "\n", "_", ",", "err", ...
// makeWin32File makes a new win32File from an existing file handle
[ "makeWin32File", "makes", "a", "new", "win32File", "from", "an", "existing", "file", "handle" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L97-L111
train
Microsoft/go-winio
file.go
closeHandle
func (f *win32File) closeHandle() { f.wgLock.Lock() // Atomically set that we are closing, releasing the resources only once. if !f.closing.swap(true) { f.wgLock.Unlock() // cancel all IO and wait for it to complete cancelIoEx(f.handle, nil) f.wg.Wait() // at this point, no new IO can start syscall.Close(f.handle) f.handle = 0 } else { f.wgLock.Unlock() } }
go
func (f *win32File) closeHandle() { f.wgLock.Lock() // Atomically set that we are closing, releasing the resources only once. if !f.closing.swap(true) { f.wgLock.Unlock() // cancel all IO and wait for it to complete cancelIoEx(f.handle, nil) f.wg.Wait() // at this point, no new IO can start syscall.Close(f.handle) f.handle = 0 } else { f.wgLock.Unlock() } }
[ "func", "(", "f", "*", "win32File", ")", "closeHandle", "(", ")", "{", "f", ".", "wgLock", ".", "Lock", "(", ")", "\n", "// Atomically set that we are closing, releasing the resources only once.", "if", "!", "f", ".", "closing", ".", "swap", "(", "true", ")", ...
// closeHandle closes the resources associated with a Win32 handle
[ "closeHandle", "closes", "the", "resources", "associated", "with", "a", "Win32", "handle" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L118-L132
train
Microsoft/go-winio
file.go
ioCompletionProcessor
func ioCompletionProcessor(h syscall.Handle) { for { var bytes uint32 var key uintptr var op *ioOperation err := getQueuedCompletionStatus(h, &bytes, &key, &op, syscall.INFINITE) if op == nil { panic(err) } op.ch <- ioResult{bytes, err} } }
go
func ioCompletionProcessor(h syscall.Handle) { for { var bytes uint32 var key uintptr var op *ioOperation err := getQueuedCompletionStatus(h, &bytes, &key, &op, syscall.INFINITE) if op == nil { panic(err) } op.ch <- ioResult{bytes, err} } }
[ "func", "ioCompletionProcessor", "(", "h", "syscall", ".", "Handle", ")", "{", "for", "{", "var", "bytes", "uint32", "\n", "var", "key", "uintptr", "\n", "var", "op", "*", "ioOperation", "\n", "err", ":=", "getQueuedCompletionStatus", "(", "h", ",", "&", ...
// ioCompletionProcessor processes completed async IOs forever
[ "ioCompletionProcessor", "processes", "completed", "async", "IOs", "forever" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L156-L167
train
Microsoft/go-winio
file.go
asyncIo
func (f *win32File) asyncIo(c *ioOperation, d *deadlineHandler, bytes uint32, err error) (int, error) { if err != syscall.ERROR_IO_PENDING { return int(bytes), err } if f.closing.isSet() { cancelIoEx(f.handle, &c.o) } var timeout timeoutChan if d != nil { d.channelLock.Lock() timeout = d.channel d.channelLock.Unlock() } var r ioResult select { case r = <-c.ch: err = r.err if err == syscall.ERROR_OPERATION_ABORTED { if f.closing.isSet() { err = ErrFileClosed } } else if err != nil && f.socket { // err is from Win32. Query the overlapped structure to get the winsock error. var bytes, flags uint32 err = wsaGetOverlappedResult(f.handle, &c.o, &bytes, false, &flags) } case <-timeout: cancelIoEx(f.handle, &c.o) r = <-c.ch err = r.err if err == syscall.ERROR_OPERATION_ABORTED { err = ErrTimeout } } // runtime.KeepAlive is needed, as c is passed via native // code to ioCompletionProcessor, c must remain alive // until the channel read is complete. runtime.KeepAlive(c) return int(r.bytes), err }
go
func (f *win32File) asyncIo(c *ioOperation, d *deadlineHandler, bytes uint32, err error) (int, error) { if err != syscall.ERROR_IO_PENDING { return int(bytes), err } if f.closing.isSet() { cancelIoEx(f.handle, &c.o) } var timeout timeoutChan if d != nil { d.channelLock.Lock() timeout = d.channel d.channelLock.Unlock() } var r ioResult select { case r = <-c.ch: err = r.err if err == syscall.ERROR_OPERATION_ABORTED { if f.closing.isSet() { err = ErrFileClosed } } else if err != nil && f.socket { // err is from Win32. Query the overlapped structure to get the winsock error. var bytes, flags uint32 err = wsaGetOverlappedResult(f.handle, &c.o, &bytes, false, &flags) } case <-timeout: cancelIoEx(f.handle, &c.o) r = <-c.ch err = r.err if err == syscall.ERROR_OPERATION_ABORTED { err = ErrTimeout } } // runtime.KeepAlive is needed, as c is passed via native // code to ioCompletionProcessor, c must remain alive // until the channel read is complete. runtime.KeepAlive(c) return int(r.bytes), err }
[ "func", "(", "f", "*", "win32File", ")", "asyncIo", "(", "c", "*", "ioOperation", ",", "d", "*", "deadlineHandler", ",", "bytes", "uint32", ",", "err", "error", ")", "(", "int", ",", "error", ")", "{", "if", "err", "!=", "syscall", ".", "ERROR_IO_PEN...
// asyncIo processes the return value from ReadFile or WriteFile, blocking until // the operation has actually completed.
[ "asyncIo", "processes", "the", "return", "value", "from", "ReadFile", "or", "WriteFile", "blocking", "until", "the", "operation", "has", "actually", "completed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L171-L214
train
Microsoft/go-winio
file.go
Read
func (f *win32File) Read(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.readDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.ReadFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.readDeadline, bytes, err) runtime.KeepAlive(b) // Handle EOF conditions. if err == nil && n == 0 && len(b) != 0 { return 0, io.EOF } else if err == syscall.ERROR_BROKEN_PIPE { return 0, io.EOF } else { return n, err } }
go
func (f *win32File) Read(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.readDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.ReadFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.readDeadline, bytes, err) runtime.KeepAlive(b) // Handle EOF conditions. if err == nil && n == 0 && len(b) != 0 { return 0, io.EOF } else if err == syscall.ERROR_BROKEN_PIPE { return 0, io.EOF } else { return n, err } }
[ "func", "(", "f", "*", "win32File", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "f", ".", "prepareIo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\...
// Read reads from a file handle.
[ "Read", "reads", "from", "a", "file", "handle", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L217-L241
train
Microsoft/go-winio
file.go
Write
func (f *win32File) Write(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.writeDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.WriteFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.writeDeadline, bytes, err) runtime.KeepAlive(b) return n, err }
go
func (f *win32File) Write(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.writeDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.WriteFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.writeDeadline, bytes, err) runtime.KeepAlive(b) return n, err }
[ "func", "(", "f", "*", "win32File", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "f", ".", "prepareIo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "...
// Write writes to a file handle.
[ "Write", "writes", "to", "a", "file", "handle", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L244-L260
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeString
func (ed *eventData) writeString(data string) { ed.buffer.WriteString(data) ed.buffer.WriteByte(0) }
go
func (ed *eventData) writeString(data string) { ed.buffer.WriteString(data) ed.buffer.WriteByte(0) }
[ "func", "(", "ed", "*", "eventData", ")", "writeString", "(", "data", "string", ")", "{", "ed", ".", "buffer", ".", "WriteString", "(", "data", ")", "\n", "ed", ".", "buffer", ".", "WriteByte", "(", "0", ")", "\n", "}" ]
// writeString appends a string, including the null terminator, to the buffer.
[ "writeString", "appends", "a", "string", "including", "the", "null", "terminator", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L22-L25
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt8
func (ed *eventData) writeInt8(value int8) { ed.buffer.WriteByte(uint8(value)) }
go
func (ed *eventData) writeInt8(value int8) { ed.buffer.WriteByte(uint8(value)) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt8", "(", "value", "int8", ")", "{", "ed", ".", "buffer", ".", "WriteByte", "(", "uint8", "(", "value", ")", ")", "\n", "}" ]
// writeInt8 appends a int8 to the buffer.
[ "writeInt8", "appends", "a", "int8", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L28-L30
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt16
func (ed *eventData) writeInt16(value int16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt16(value int16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt16", "(", "value", "int16", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt16 appends a int16 to the buffer.
[ "writeInt16", "appends", "a", "int16", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L33-L35
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt32
func (ed *eventData) writeInt32(value int32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt32(value int32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt32", "(", "value", "int32", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt32 appends a int32 to the buffer.
[ "writeInt32", "appends", "a", "int32", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L38-L40
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt64
func (ed *eventData) writeInt64(value int64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt64(value int64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt64", "(", "value", "int64", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt64 appends a int64 to the buffer.
[ "writeInt64", "appends", "a", "int64", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L43-L45
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint16
func (ed *eventData) writeUint16(value uint16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint16(value uint16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint16", "(", "value", "uint16", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint16 appends a uint16 to the buffer.
[ "writeUint16", "appends", "a", "uint16", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L53-L55
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint32
func (ed *eventData) writeUint32(value uint32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint32(value uint32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint32", "(", "value", "uint32", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint32 appends a uint32 to the buffer.
[ "writeUint32", "appends", "a", "uint32", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L58-L60
train
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint64
func (ed *eventData) writeUint64(value uint64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint64(value uint64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint64", "(", "value", "uint64", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint64 appends a uint64 to the buffer.
[ "writeUint64", "appends", "a", "uint64", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L63-L65
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithLevel
func WithLevel(level Level) EventOpt { return func(options *eventOptions) { options.descriptor.level = level } }
go
func WithLevel(level Level) EventOpt { return func(options *eventOptions) { options.descriptor.level = level } }
[ "func", "WithLevel", "(", "level", "Level", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "level", "=", "level", "\n", "}", "\n", "}" ]
// WithLevel specifies the level of the event to be written.
[ "WithLevel", "specifies", "the", "level", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L25-L29
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithKeyword
func WithKeyword(keyword uint64) EventOpt { return func(options *eventOptions) { options.descriptor.keyword |= keyword } }
go
func WithKeyword(keyword uint64) EventOpt { return func(options *eventOptions) { options.descriptor.keyword |= keyword } }
[ "func", "WithKeyword", "(", "keyword", "uint64", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "keyword", "|=", "keyword", "\n", "}", "\n", "}" ]
// WithKeyword specifies the keywords of the event to be written. Multiple uses // of this option are OR'd together.
[ "WithKeyword", "specifies", "the", "keywords", "of", "the", "event", "to", "be", "written", ".", "Multiple", "uses", "of", "this", "option", "are", "OR", "d", "together", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L33-L37
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithChannel
func WithChannel(channel Channel) EventOpt { return func(options *eventOptions) { options.descriptor.channel = channel } }
go
func WithChannel(channel Channel) EventOpt { return func(options *eventOptions) { options.descriptor.channel = channel } }
[ "func", "WithChannel", "(", "channel", "Channel", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "channel", "=", "channel", "\n", "}", "\n", "}" ]
// WithChannel specifies the channel of the event to be written.
[ "WithChannel", "specifies", "the", "channel", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L40-L44
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithOpcode
func WithOpcode(opcode Opcode) EventOpt { return func(options *eventOptions) { options.descriptor.opcode = opcode } }
go
func WithOpcode(opcode Opcode) EventOpt { return func(options *eventOptions) { options.descriptor.opcode = opcode } }
[ "func", "WithOpcode", "(", "opcode", "Opcode", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "opcode", "=", "opcode", "\n", "}", "\n", "}" ]
// WithOpcode specifies the opcode of the event to be written.
[ "WithOpcode", "specifies", "the", "opcode", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L47-L51
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithActivityID
func WithActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.activityID = activityID } }
go
func WithActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.activityID = activityID } }
[ "func", "WithActivityID", "(", "activityID", "*", "guid", ".", "GUID", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "activityID", "=", "activityID", "\n", "}", "\n", "}" ]
// WithActivityID specifies the activity ID of the event to be written.
[ "WithActivityID", "specifies", "the", "activity", "ID", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L62-L66
train
Microsoft/go-winio
pkg/etw/eventopt.go
WithRelatedActivityID
func WithRelatedActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.relatedActivityID = activityID } }
go
func WithRelatedActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.relatedActivityID = activityID } }
[ "func", "WithRelatedActivityID", "(", "activityID", "*", "guid", ".", "GUID", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "relatedActivityID", "=", "activityID", "\n", "}", "\n", "}" ]
// WithRelatedActivityID specifies the parent activity ID of the event to be written.
[ "WithRelatedActivityID", "specifies", "the", "parent", "activity", "ID", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L69-L73
train
Microsoft/go-winio
pkg/etw/newprovider_unsupported.go
NewProviderWithID
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { return nil, nil }
go
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { return nil, nil }
[ "func", "NewProviderWithID", "(", "name", "string", ",", "id", "*", "guid", ".", "GUID", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// NewProviderWithID returns a nil provider on unsupported platforms.
[ "NewProviderWithID", "returns", "a", "nil", "provider", "on", "unsupported", "platforms", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/newprovider_unsupported.go#L10-L12
train
Microsoft/go-winio
pkg/security/grantvmgroupaccess.go
generateDACLWithAcesAdded
func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintptr, error) { // Generate pointers to the SIDs based on the string SIDs sid, err := syscall.StringToSid(sidVmGroup) if err != nil { return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup) } inheritance := inheritModeNoInheritance if isDir { inheritance = inheritModeSubContainersAndObjectsInherit } eaArray := []explicitAccess{ explicitAccess{ accessPermissions: accessMaskDesiredPermission, accessMode: accessModeGrant, inheritance: inheritance, trustee: trustee{ trusteeForm: trusteeFormIsSid, trusteeType: trusteeTypeWellKnownGroup, name: uintptr(unsafe.Pointer(sid)), }, }, } modifiedDACL := uintptr(0) if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil { return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name) } return modifiedDACL, nil }
go
func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintptr, error) { // Generate pointers to the SIDs based on the string SIDs sid, err := syscall.StringToSid(sidVmGroup) if err != nil { return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup) } inheritance := inheritModeNoInheritance if isDir { inheritance = inheritModeSubContainersAndObjectsInherit } eaArray := []explicitAccess{ explicitAccess{ accessPermissions: accessMaskDesiredPermission, accessMode: accessModeGrant, inheritance: inheritance, trustee: trustee{ trusteeForm: trusteeFormIsSid, trusteeType: trusteeTypeWellKnownGroup, name: uintptr(unsafe.Pointer(sid)), }, }, } modifiedDACL := uintptr(0) if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil { return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name) } return modifiedDACL, nil }
[ "func", "generateDACLWithAcesAdded", "(", "name", "string", ",", "isDir", "bool", ",", "origDACL", "uintptr", ")", "(", "uintptr", ",", "error", ")", "{", "// Generate pointers to the SIDs based on the string SIDs", "sid", ",", "err", ":=", "syscall", ".", "StringTo...
// generateDACLWithAcesAdded generates a new DACL with the two needed ACEs added. // The caller is responsible for LocalFree of the returned DACL on success.
[ "generateDACLWithAcesAdded", "generates", "a", "new", "DACL", "with", "the", "two", "needed", "ACEs", "added", ".", "The", "caller", "is", "responsible", "for", "LocalFree", "of", "the", "returned", "DACL", "on", "success", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/grantvmgroupaccess.go#L128-L159
train
Microsoft/go-winio
pkg/etw/newprovider.go
NewProviderWithID
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { providerCallbackOnce.Do(func() { globalProviderCallback = windows.NewCallback(providerCallbackAdapter) }) provider = providers.newProvider() defer func(provider *Provider) { if err != nil { providers.removeProvider(provider) } }(provider) provider.ID = id provider.callback = callback if err := eventRegister((*windows.GUID)(provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil { return nil, err } metadata := &bytes.Buffer{} binary.Write(metadata, binary.LittleEndian, uint16(0)) // Write empty size for buffer (to update later) metadata.WriteString(name) metadata.WriteByte(0) // Null terminator for name binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer provider.metadata = metadata.Bytes() if err := eventSetInformation( provider.handle, eventInfoClassProviderSetTraits, uintptr(unsafe.Pointer(&provider.metadata[0])), uint32(len(provider.metadata))); err != nil { return nil, err } return provider, nil }
go
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { providerCallbackOnce.Do(func() { globalProviderCallback = windows.NewCallback(providerCallbackAdapter) }) provider = providers.newProvider() defer func(provider *Provider) { if err != nil { providers.removeProvider(provider) } }(provider) provider.ID = id provider.callback = callback if err := eventRegister((*windows.GUID)(provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil { return nil, err } metadata := &bytes.Buffer{} binary.Write(metadata, binary.LittleEndian, uint16(0)) // Write empty size for buffer (to update later) metadata.WriteString(name) metadata.WriteByte(0) // Null terminator for name binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer provider.metadata = metadata.Bytes() if err := eventSetInformation( provider.handle, eventInfoClassProviderSetTraits, uintptr(unsafe.Pointer(&provider.metadata[0])), uint32(len(provider.metadata))); err != nil { return nil, err } return provider, nil }
[ "func", "NewProviderWithID", "(", "name", "string", ",", "id", "*", "guid", ".", "GUID", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "providerCallbackOnce", ".", "Do", "(", "func", "(", ")", "{...
// NewProviderWithID creates and registers a new ETW provider, allowing the // provider ID to be manually specified. This is most useful when there is an // existing provider ID that must be used to conform to existing diagnostic // infrastructure.
[ "NewProviderWithID", "creates", "and", "registers", "a", "new", "ETW", "provider", "allowing", "the", "provider", "ID", "to", "be", "manually", "specified", ".", "This", "is", "most", "useful", "when", "there", "is", "an", "existing", "provider", "ID", "that",...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/newprovider.go#L18-L53
train
Microsoft/go-winio
pkg/etw/provider.go
NewProvider
func NewProvider(name string, callback EnableCallback) (provider *Provider, err error) { return NewProviderWithID(name, providerIDFromName(name), callback) }
go
func NewProvider(name string, callback EnableCallback) (provider *Provider, err error) { return NewProviderWithID(name, providerIDFromName(name), callback) }
[ "func", "NewProvider", "(", "name", "string", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "return", "NewProviderWithID", "(", "name", ",", "providerIDFromName", "(", "name", ")", ",", "callback", "...
// NewProvider creates and registers a new ETW provider. The provider ID is // generated based on the provider name.
[ "NewProvider", "creates", "and", "registers", "a", "new", "ETW", "provider", ".", "The", "provider", "ID", "is", "generated", "based", "on", "the", "provider", "name", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L121-L123
train
Microsoft/go-winio
pkg/etw/provider.go
Close
func (provider *Provider) Close() error { if provider == nil { return nil } providers.removeProvider(provider) return eventUnregister(provider.handle) }
go
func (provider *Provider) Close() error { if provider == nil { return nil } providers.removeProvider(provider) return eventUnregister(provider.handle) }
[ "func", "(", "provider", "*", "Provider", ")", "Close", "(", ")", "error", "{", "if", "provider", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "providers", ".", "removeProvider", "(", "provider", ")", "\n", "return", "eventUnregister", "(", "pro...
// Close unregisters the provider.
[ "Close", "unregisters", "the", "provider", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L126-L133
train
Microsoft/go-winio
pkg/etw/provider.go
IsEnabledForLevel
func (provider *Provider) IsEnabledForLevel(level Level) bool { return provider.IsEnabledForLevelAndKeywords(level, ^uint64(0)) }
go
func (provider *Provider) IsEnabledForLevel(level Level) bool { return provider.IsEnabledForLevelAndKeywords(level, ^uint64(0)) }
[ "func", "(", "provider", "*", "Provider", ")", "IsEnabledForLevel", "(", "level", "Level", ")", "bool", "{", "return", "provider", ".", "IsEnabledForLevelAndKeywords", "(", "level", ",", "^", "uint64", "(", "0", ")", ")", "\n", "}" ]
// IsEnabledForLevel calls IsEnabledForLevelAndKeywords with the specified level // and all keywords set.
[ "IsEnabledForLevel", "calls", "IsEnabledForLevelAndKeywords", "with", "the", "specified", "level", "and", "all", "keywords", "set", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L143-L145
train
Microsoft/go-winio
pkg/etw/provider.go
IsEnabledForLevelAndKeywords
func (provider *Provider) IsEnabledForLevelAndKeywords(level Level, keywords uint64) bool { if provider == nil { return false } if !provider.enabled { return false } // ETW automatically sets the level to 255 if it is specified as 0, so we // don't need to worry about the level=0 (all events) case. if level > provider.level { return false } if keywords != 0 && (keywords&provider.keywordAny == 0 || keywords&provider.keywordAll != provider.keywordAll) { return false } return true }
go
func (provider *Provider) IsEnabledForLevelAndKeywords(level Level, keywords uint64) bool { if provider == nil { return false } if !provider.enabled { return false } // ETW automatically sets the level to 255 if it is specified as 0, so we // don't need to worry about the level=0 (all events) case. if level > provider.level { return false } if keywords != 0 && (keywords&provider.keywordAny == 0 || keywords&provider.keywordAll != provider.keywordAll) { return false } return true }
[ "func", "(", "provider", "*", "Provider", ")", "IsEnabledForLevelAndKeywords", "(", "level", "Level", ",", "keywords", "uint64", ")", "bool", "{", "if", "provider", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "if", "!", "provider", ".", "enable...
// IsEnabledForLevelAndKeywords allows event producer code to check if there are // any event sessions that are interested in an event, based on the event level // and keywords. Although this check happens automatically in the ETW // infrastructure, it can be useful to check if an event will actually be // consumed before doing expensive work to build the event data.
[ "IsEnabledForLevelAndKeywords", "allows", "event", "producer", "code", "to", "check", "if", "there", "are", "any", "event", "sessions", "that", "are", "interested", "in", "an", "event", "based", "on", "the", "event", "level", "and", "keywords", ".", "Although", ...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L152-L172
train
Microsoft/go-winio
pkg/etw/provider.go
WriteEvent
func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpts []FieldOpt) error { if provider == nil { return nil } options := eventOptions{descriptor: newEventDescriptor()} em := &eventMetadata{} ed := &eventData{} // We need to evaluate the EventOpts first since they might change tags, and // we write out the tags before evaluating FieldOpts. for _, opt := range eventOpts { opt(&options) } if !provider.IsEnabledForLevelAndKeywords(options.descriptor.level, options.descriptor.keyword) { return nil } em.writeEventHeader(name, options.tags) for _, opt := range fieldOpts { opt(em, ed) } // Don't pass a data blob if there is no event data. There will always be // event metadata (e.g. for the name) so we don't need to do this check for // the metadata. dataBlobs := [][]byte{} if len(ed.bytes()) > 0 { dataBlobs = [][]byte{ed.bytes()} } return provider.writeEventRaw(options.descriptor, options.activityID, options.relatedActivityID, [][]byte{em.bytes()}, dataBlobs) }
go
func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpts []FieldOpt) error { if provider == nil { return nil } options := eventOptions{descriptor: newEventDescriptor()} em := &eventMetadata{} ed := &eventData{} // We need to evaluate the EventOpts first since they might change tags, and // we write out the tags before evaluating FieldOpts. for _, opt := range eventOpts { opt(&options) } if !provider.IsEnabledForLevelAndKeywords(options.descriptor.level, options.descriptor.keyword) { return nil } em.writeEventHeader(name, options.tags) for _, opt := range fieldOpts { opt(em, ed) } // Don't pass a data blob if there is no event data. There will always be // event metadata (e.g. for the name) so we don't need to do this check for // the metadata. dataBlobs := [][]byte{} if len(ed.bytes()) > 0 { dataBlobs = [][]byte{ed.bytes()} } return provider.writeEventRaw(options.descriptor, options.activityID, options.relatedActivityID, [][]byte{em.bytes()}, dataBlobs) }
[ "func", "(", "provider", "*", "Provider", ")", "WriteEvent", "(", "name", "string", ",", "eventOpts", "[", "]", "EventOpt", ",", "fieldOpts", "[", "]", "FieldOpt", ")", "error", "{", "if", "provider", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n...
// WriteEvent writes a single ETW event from the provider. The event is // constructed based on the EventOpt and FieldOpt values that are passed as // opts.
[ "WriteEvent", "writes", "a", "single", "ETW", "event", "from", "the", "provider", ".", "The", "event", "is", "constructed", "based", "on", "the", "EventOpt", "and", "FieldOpt", "values", "that", "are", "passed", "as", "opts", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L177-L211
train
Microsoft/go-winio
pkg/etw/provider.go
writeEventRaw
func (provider *Provider) writeEventRaw( descriptor *eventDescriptor, activityID *guid.GUID, relatedActivityID *guid.GUID, metadataBlobs [][]byte, dataBlobs [][]byte) error { dataDescriptorCount := uint32(1 + len(metadataBlobs) + len(dataBlobs)) dataDescriptors := make([]eventDataDescriptor, 0, dataDescriptorCount) dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeProviderMetadata, provider.metadata)) for _, blob := range metadataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeEventMetadata, blob)) } for _, blob := range dataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob)) } return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(activityID), (*windows.GUID)(relatedActivityID), dataDescriptorCount, &dataDescriptors[0]) }
go
func (provider *Provider) writeEventRaw( descriptor *eventDescriptor, activityID *guid.GUID, relatedActivityID *guid.GUID, metadataBlobs [][]byte, dataBlobs [][]byte) error { dataDescriptorCount := uint32(1 + len(metadataBlobs) + len(dataBlobs)) dataDescriptors := make([]eventDataDescriptor, 0, dataDescriptorCount) dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeProviderMetadata, provider.metadata)) for _, blob := range metadataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeEventMetadata, blob)) } for _, blob := range dataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob)) } return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(activityID), (*windows.GUID)(relatedActivityID), dataDescriptorCount, &dataDescriptors[0]) }
[ "func", "(", "provider", "*", "Provider", ")", "writeEventRaw", "(", "descriptor", "*", "eventDescriptor", ",", "activityID", "*", "guid", ".", "GUID", ",", "relatedActivityID", "*", "guid", ".", "GUID", ",", "metadataBlobs", "[", "]", "[", "]", "byte", ",...
// writeEventRaw writes a single ETW event from the provider. This function is // less abstracted than WriteEvent, and presents a fairly direct interface to // the event writing functionality. It expects a series of event metadata and // event data blobs to be passed in, which must conform to the TraceLogging // schema. The functions on EventMetadata and EventData can help with creating // these blobs. The blobs of each type are effectively concatenated together by // the ETW infrastructure.
[ "writeEventRaw", "writes", "a", "single", "ETW", "event", "from", "the", "provider", ".", "This", "function", "is", "less", "abstracted", "than", "WriteEvent", "and", "presents", "a", "fairly", "direct", "interface", "to", "the", "event", "writing", "functionali...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L220-L239
train
Microsoft/go-winio
archive/tar/writer.go
formatString
func (f *formatter) formatString(b []byte, s string) { if len(s) > len(b) { f.err = ErrFieldTooLong return } ascii := toASCII(s) copy(b, ascii) if len(ascii) < len(b) { b[len(ascii)] = 0 } }
go
func (f *formatter) formatString(b []byte, s string) { if len(s) > len(b) { f.err = ErrFieldTooLong return } ascii := toASCII(s) copy(b, ascii) if len(ascii) < len(b) { b[len(ascii)] = 0 } }
[ "func", "(", "f", "*", "formatter", ")", "formatString", "(", "b", "[", "]", "byte", ",", "s", "string", ")", "{", "if", "len", "(", "s", ")", ">", "len", "(", "b", ")", "{", "f", ".", "err", "=", "ErrFieldTooLong", "\n", "return", "\n", "}", ...
// Write s into b, terminating it with a NUL if there is room.
[ "Write", "s", "into", "b", "terminating", "it", "with", "a", "NUL", "if", "there", "is", "room", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L75-L85
train
Microsoft/go-winio
archive/tar/writer.go
formatOctal
func (f *formatter) formatOctal(b []byte, x int64) { s := strconv.FormatInt(x, 8) // leading zeros, but leave room for a NUL. for len(s)+1 < len(b) { s = "0" + s } f.formatString(b, s) }
go
func (f *formatter) formatOctal(b []byte, x int64) { s := strconv.FormatInt(x, 8) // leading zeros, but leave room for a NUL. for len(s)+1 < len(b) { s = "0" + s } f.formatString(b, s) }
[ "func", "(", "f", "*", "formatter", ")", "formatOctal", "(", "b", "[", "]", "byte", ",", "x", "int64", ")", "{", "s", ":=", "strconv", ".", "FormatInt", "(", "x", ",", "8", ")", "\n", "// leading zeros, but leave room for a NUL.", "for", "len", "(", "s...
// Encode x as an octal ASCII string and write it into b with leading zeros.
[ "Encode", "x", "as", "an", "octal", "ASCII", "string", "and", "write", "it", "into", "b", "with", "leading", "zeros", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L88-L95
train
Microsoft/go-winio
archive/tar/writer.go
Write
func (tw *Writer) Write(b []byte) (n int, err error) { if tw.closed { err = ErrWriteAfterClose return } overwrite := false if int64(len(b)) > tw.nb { b = b[0:tw.nb] overwrite = true } n, err = tw.w.Write(b) tw.nb -= int64(n) if err == nil && overwrite { err = ErrWriteTooLong return } tw.err = err return }
go
func (tw *Writer) Write(b []byte) (n int, err error) { if tw.closed { err = ErrWriteAfterClose return } overwrite := false if int64(len(b)) > tw.nb { b = b[0:tw.nb] overwrite = true } n, err = tw.w.Write(b) tw.nb -= int64(n) if err == nil && overwrite { err = ErrWriteTooLong return } tw.err = err return }
[ "func", "(", "tw", "*", "Writer", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "tw", ".", "closed", "{", "err", "=", "ErrWriteAfterClose", "\n", "return", "\n", "}", "\n", "overwrite", ":=",...
// Write writes to the current entry in the tar archive. // Write returns the error ErrWriteTooLong if more than // hdr.Size bytes are written after WriteHeader.
[ "Write", "writes", "to", "the", "current", "entry", "in", "the", "tar", "archive", ".", "Write", "returns", "the", "error", "ErrWriteTooLong", "if", "more", "than", "hdr", ".", "Size", "bytes", "are", "written", "after", "WriteHeader", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L404-L422
train
Microsoft/go-winio
archive/tar/writer.go
Close
func (tw *Writer) Close() error { if tw.err != nil || tw.closed { return tw.err } tw.Flush() tw.closed = true if tw.err != nil { return tw.err } // trailer: two zero blocks for i := 0; i < 2; i++ { _, tw.err = tw.w.Write(zeroBlock) if tw.err != nil { break } } return tw.err }
go
func (tw *Writer) Close() error { if tw.err != nil || tw.closed { return tw.err } tw.Flush() tw.closed = true if tw.err != nil { return tw.err } // trailer: two zero blocks for i := 0; i < 2; i++ { _, tw.err = tw.w.Write(zeroBlock) if tw.err != nil { break } } return tw.err }
[ "func", "(", "tw", "*", "Writer", ")", "Close", "(", ")", "error", "{", "if", "tw", ".", "err", "!=", "nil", "||", "tw", ".", "closed", "{", "return", "tw", ".", "err", "\n", "}", "\n", "tw", ".", "Flush", "(", ")", "\n", "tw", ".", "closed",...
// Close closes the tar archive, flushing any unwritten // data to the underlying writer.
[ "Close", "closes", "the", "tar", "archive", "flushing", "any", "unwritten", "data", "to", "the", "underlying", "writer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L426-L444
train